NetSurf
toolbar.c
Go to the documentation of this file.
1/*
2 * Copyright 2012 Ole Loots <ole@monochrom.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#include <sys/types.h>
20#include <sys/stat.h>
21#include <fcntl.h>
22#include <limits.h>
23#include <unistd.h>
24#include <string.h>
25#include <stdlib.h>
26#include <stdbool.h>
27#include <assert.h>
28#include <math.h>
29
30#include "utils/log.h"
31#include "utils/nsoption.h"
32#include "utils/nsurl.h"
33#include "utils/utf8.h"
35#include "netsurf/mouse.h"
36#include "netsurf/plotters.h"
37#include "netsurf/keypress.h"
39#include "desktop/hotlist.h"
40#include "desktop/textarea.h"
41
42#include "atari/clipboard.h"
43#include "atari/gui.h"
44#include "atari/search.h"
45#include "atari/toolbar.h"
46#include "atari/rootwin.h"
47#include "atari/clipboard.h"
48#include "atari/misc.h"
49#include "atari/plot/plot.h"
50#include "cflib.h"
51#include "atari/res/netsurf.rsh"
52#include "atari/encoding.h"
53
54
55#define TB_BUTTON_WIDTH 32
56#define THROBBER_WIDTH 32
57#define THROBBER_MIN_INDEX 1
58#define THROBBER_MAX_INDEX 12
59#define THROBBER_INACTIVE_INDEX 13
60
63 button_off = 1
64};
65#define TOOLBAR_BUTTON_NUM_STATES 2
66
67struct s_toolbar;
68
70 short rsc_id;
71 void (*cb_click)(struct s_toolbar *tb);
75 short index;
76 GRECT area;
77};
78
79
80extern char * option_homepage_url;
81extern void * h_gem_rsrc;
82extern struct gui_window * input_window;
83extern long atari_plot_flags;
84extern int atari_plot_vdi_handle;
85extern EVMULT_OUT aes_event_out;
86
87static OBJECT * aes_toolbar = NULL;
88static OBJECT * throbber_form = NULL;
89static bool init = false;
91static int area_search_height = 0;
92static int area_full_height = 0;
93static float toolbar_url_scale = 1.0;
94
97 .size = 14*PLOT_STYLE_SCALE,
98 .weight = 400,
99 .flags = FONTF_NONE,
100 .background = 0xffffff,
101 .foreground = 0x0
102};
103
104
105/* prototypes & order for button widgets: */
106
107static struct s_tb_button tb_buttons[] = {
108 {
109 TOOLBAR_BT_BACK,
111 {0,0},
112 0, 0, 0, {0,0,0,0}
113 },
114 {
115 TOOLBAR_BT_HOME,
117 {0,0},
118 0, 0, 0, {0,0,0,0}
119 },
120 {
121 TOOLBAR_BT_FORWARD,
123 {0,0},
124 0, 0, 0, {0,0,0,0}
125 },
126 {
127 TOOLBAR_BT_STOP,
129 {0,0},
130 0, 0, 0, {0,0,0,0}
131 },
132 {
133 TOOLBAR_BT_RELOAD,
135 {0,0},
136 0, 0, 0, {0,0,0,0}
137 },
138 { 0, 0, {0,0}, 0, -1, 0, {0,0,0,0}}
139};
140
143};
144
146 /* small (18 px height) */
147 {9},
148 /* medium (default - 26 px height) */
149 {14},
150 /* large ( 49 px height ) */
151 {18},
152 /* custom style: */
153 {18}
154};
155
156static const struct redraw_context toolbar_rdrw_ctx = {
157 .interactive = true,
158 .background_images = true,
159 .plot = &atari_plotters
160};
161
162static void tb_txt_request_redraw(void *data, int x, int y, int w, int h );
163
164/**
165 * Find a button for a specific resource ID
166 */
167static struct s_tb_button *find_button(struct s_toolbar *tb, int rsc_id)
168{
169 int i = 0;
170 while (i < tb->btcnt) {
171 if (tb->buttons[i].rsc_id == rsc_id) {
172 return(&tb->buttons[i]);
173 }
174 i++;
175 }
176 return(NULL);
177}
178
179/**
180 * Callback for textarea redraw
181 */
182static void tb_txt_request_redraw(void *data, int x, int y, int w, int h)
183{
184
185 GRECT area;
186 struct s_toolbar * tb = (struct s_toolbar *)data;
187
188 if (tb->attached == false) {
189 return;
190 }
191
192 toolbar_get_grect(tb, TOOLBAR_AREA_URL, &area);
193 area.g_x += x;
194 area.g_y += y;
195 area.g_w = w;
196 area.g_h = h;
197 /* dbg_grect("tb_txt_request_redraw", &area); */
199 return;
200}
201
202static void tb_txt_callback(void *data, struct textarea_msg *msg)
203{
204 switch (msg->type) {
205
207 break;
208
211 msg->data.redraw.x0, msg->data.redraw.y0,
212 msg->data.redraw.x1 - msg->data.redraw.x0,
213 msg->data.redraw.y1 - msg->data.redraw.y0);
214 break;
215
216 default:
217 break;
218 }
219}
220
221static struct s_tb_button *button_init(struct s_toolbar *tb, OBJECT * tree, int index,
222 struct s_tb_button * instance)
223{
224 *instance = tb_buttons[index];
225 instance->owner = tb;
226
227 return(instance);
228}
229
230
231static short __CDECL toolbar_url_userdraw(PARMBLK *parmblock)
232{
233 return(0);
234}
235
236void toolbar_init( void )
237{
238 static USERBLK userblk;
239
240 aes_toolbar = gemtk_obj_get_tree(TOOLBAR);
241 throbber_form = gemtk_obj_get_tree(THROBBER);
242
243 userblk.ub_code = toolbar_url_userdraw;
244 userblk.ub_parm = (long) aes_toolbar[TOOLBAR_AREA_URL].ob_spec.userblk;
245 aes_toolbar[TOOLBAR_AREA_URL].ob_spec.userblk = &userblk;
246
247 aes_toolbar[TOOLBAR_CB_SHOWALL].ob_state &= ~OS_SELECTED;
248 aes_toolbar[TOOLBAR_CB_CASESENSE].ob_state &= ~OS_SELECTED;
249
250 /* init default values: */
251 gemtk_obj_set_str_safe(aes_toolbar, TOOLBAR_TB_SRCH, (char*)"");
252
253 area_full_height = aes_toolbar->ob_height;
254 area_search_height = aes_toolbar[TOOLBAR_AREA_SEARCH].ob_height;
255 area_navigation_height = aes_toolbar[TOOLBAR_AREA_NAVIGATION].ob_height;
256
257 init = true;
258}
259
260
261void toolbar_exit(void)
262{
263
264}
265
266
268{
269 int i;
270 struct s_toolbar *t;
271
272 NSLOG(netsurf, INFO, "owner %p", owner);
273
274 assert(init == true);
275
276 t = calloc(1, sizeof(struct s_toolbar));
277
278 assert(t);
279
280 /* initialize the toolbar values: */
281 t->owner = owner;
282 t->style = 1;
283 t->search_visible = false;
284 t->visible = true;
285 t->reflow = true;
286
287 /* dublicate the form template: */
288 t->form = gemtk_obj_tree_copy(aes_toolbar);
289
290
291 /* count buttons and add them as components: */
292 i = 0;
293 while(tb_buttons[i].rsc_id > 0) {
294 i++;
295 }
296 t->btcnt = i;
297 t->buttons = malloc(t->btcnt * sizeof(struct s_tb_button));
298 memset(t->buttons, 0, t->btcnt * sizeof(struct s_tb_button));
299 for (i=0; i < t->btcnt; i++) {
300 button_init(t, aes_toolbar, i, &t->buttons[i]);
301 }
302
303 /* create the url widget: */
306
308 textarea_setup ta_setup;
309 ta_setup.width = 300;
310 ta_setup.height = t->form[TOOLBAR_AREA_URL].ob_height;
311 ta_setup.pad_top = 0;
312 ta_setup.pad_right = 4;
313 ta_setup.pad_bottom = 0;
314 ta_setup.pad_left = 4;
315 ta_setup.border_width = 1;
316 ta_setup.border_col = 0x000000;
317 ta_setup.selected_text = 0xffffff;
318 ta_setup.selected_bg = 0x000000;
319 ta_setup.text = font_style_url;
320 ta_setup.text.foreground = 0x000000;
321 ta_setup.text.background = 0xffffff;
322 t->url.textarea = textarea_create(ta_flags, &ta_setup,
323 tb_txt_callback, t);
324
325 /* create the throbber widget: */
328 t->throbber.running = false;
329
330 NSLOG(netsurf, INFO,
331 "created toolbar: %p, root: %p, textarea: %p, throbber: %p", t,
332 owner, t->url.textarea, &t->throbber);
333 return( t );
334}
335
336
338{
339 free(tb->buttons);
340 free(tb->form);
341
343
344 free(tb);
345}
346
348{
349 int r = 0;
350
351 if (tb->visible == false) {
352 return(0);
353 }
354
356
357 if (tb->search_visible) {
359 }
360
361 return(r);
362}
363
364static void toolbar_reflow(struct s_toolbar *tb)
365{
366 int i;
367 short offx, offy;
368
369 // position toolbar areas:
370 tb->form->ob_x = tb->area.g_x;
371 tb->form->ob_y = tb->area.g_y;
372 tb->form->ob_width = tb->area.g_w;
373 tb->form->ob_height = toolbar_calculate_height(tb);
374
375 // expand the "main" areas to the current width:
376 tb->form[TOOLBAR_AREA_NAVIGATION].ob_width = tb->area.g_w;
377 tb->form[TOOLBAR_AREA_SEARCH].ob_width = tb->area.g_w;
378
379 if (tb->search_visible) {
380 tb->form[TOOLBAR_AREA_SEARCH].ob_state &= ~OF_HIDETREE;
381 } else {
382 tb->form[TOOLBAR_AREA_SEARCH].ob_state |= OF_HIDETREE;
383
384 }
385
386 // align TOOLBAR_AREA_RIGHT IBOX at right edge:
387 tb->form[TOOLBAR_AREA_RIGHT].ob_x = tb->area.g_w
388 - tb->form[TOOLBAR_AREA_RIGHT].ob_width;
389
390 // center the URL area:
391 tb->form[TOOLBAR_AREA_URL].ob_width = tb->area.g_w
392 - (tb->form[TOOLBAR_AREA_LEFT].ob_width
393 + tb->form[TOOLBAR_AREA_RIGHT].ob_width);
394
395 // position throbber image above IBOX:
396 objc_offset(tb->form, TOOLBAR_THROBBER_AREA, &offx, &offy);
397 throbber_form[tb->throbber.index].ob_x = offx;
398 throbber_form[tb->throbber.index].ob_y = offy;
399
400 // align the search button:
401 tb->form[TOOLBAR_SEARCH_ALIGN_RIGHT].ob_x = tb->area.g_w
402 - tb->form[TOOLBAR_SEARCH_ALIGN_RIGHT].ob_width;
403
404 // set button states:
405 for (i=0; i < tb->btcnt; i++ ) {
406 if (tb->buttons[i].state == button_off) {
407 tb->form[tb->buttons[i].rsc_id].ob_state |= OS_DISABLED;
408 } else if (tb->buttons[i].state == button_on) {
409 tb->form[tb->buttons[i].rsc_id].ob_state &= ~OS_DISABLED;
410 }
411 }
412 tb->reflow = false;
413 // TODO: iterate through all other toolbars and set reflow = true
414}
415
416void toolbar_redraw(struct s_toolbar *tb, GRECT *clip)
417{
418 GRECT area, area_ro;
419
420 if (tb->attached == false) {
421 return;
422 }
423
424 if(tb->reflow == true)
425 toolbar_reflow(tb);
426
427 //dbg_grect("toolbar redraw clip", clip);
428
429 /* Redraw the AES objects: */
430 objc_draw_grect(tb->form,0,8,clip);
431 objc_draw_grect(&throbber_form[tb->throbber.index], 0, 1, clip);
432
433 toolbar_get_grect(tb, TOOLBAR_AREA_URL, &area_ro);
434 area = area_ro;
435
436 if (rc_intersect(clip, &area)) {
437 float old_scale;
438
439 plot_set_dimensions(&toolbar_rdrw_ctx, area_ro.g_x, area_ro.g_y, area_ro.g_w, area_ro.g_h);
440 struct rect r = {
441 .x0 = MAX(0,area.g_x - area_ro.g_x),
442 .y0 = MAX(0,area.g_y - area_ro.g_y),
443 .x1 = MAX(0,area.g_x - area_ro.g_x) + area.g_w,
444 .y1 = MAX(0,area.g_y - area_ro.g_y) + area.g_h
445 };
446 //dbg_rect("tb textarea clip: ", &r);
447 // TODO: let this be handled by an userdef object redraw function:
448 /* Redraw the url input: */
450 textarea_redraw(tb->url.textarea, 0, 0, 0xffffff, 1.0, &r,
452 plot_set_scale(old_scale);
453 }
454}
455
456
457void
459 struct browser_window *bw,
460 short button)
461{
462 NSLOG(netsurf, INFO, "tb %p", tb);
463
464 struct s_tb_button * bt;
465 bool enable = false;
466 GRECT area;
467
468 assert(bw != NULL);
469
470 if (button == TOOLBAR_BT_BACK || button <= 0 ) {
471 bt = find_button(tb, TOOLBAR_BT_BACK);
473 if (enable) {
474 bt->state = button_on;
475 } else {
476 bt->state = button_off;
477 }
478 }
479
480 if (button == TOOLBAR_BT_HOME || button <= 0 ) {
481
482 }
483
484 if (button == TOOLBAR_BT_FORWARD || button <= 0 ) {
485 bt = find_button(tb, TOOLBAR_BT_FORWARD);
487 if (enable) {
488 bt->state = button_on;
489 } else {
490 bt->state = button_off;
491 }
492 }
493
494 if (button == TOOLBAR_BT_RELOAD || button <= 0 ) {
495 bt = find_button(tb, TOOLBAR_BT_RELOAD);
497 if (enable) {
498 bt->state = button_on;
499 } else {
500 bt->state = button_off;
501 }
502 }
503
504 if (button == TOOLBAR_BT_STOP || button <= 0) {
505 bt = find_button(tb, TOOLBAR_BT_STOP);
507 if (enable) {
508 bt->state = button_on;
509 } else {
510 bt->state = button_off;
511 }
512 }
513
514 if (tb->attached) {
515 if (button > 0) {
516 toolbar_get_grect(tb, button, &area);
518 } else {
519 toolbar_get_grect(tb, TOOLBAR_AREA_LEFT, &area);
521
522 toolbar_get_grect(tb, TOOLBAR_AREA_RIGHT, &area);
524 }
525 }
526}
527
528void toolbar_set_width(struct s_toolbar *tb, short w)
529{
530 GRECT cur;
531
532 toolbar_get_grect(tb, 0, &cur);
533
534 if (w != cur.g_w) {
535
536 tb->area.g_w = w;
537
538 /* reflow now, just for url input calucation: */
539 toolbar_reflow(tb);
540 /* this will request an textarea redraw: */
542 tb->form[TOOLBAR_AREA_URL].ob_width,
543 tb->form[TOOLBAR_AREA_URL].ob_height);
544 tb->reflow = true;
545 }
546}
547
548void toolbar_set_origin(struct s_toolbar *tb, short x, short y)
549{
550 GRECT cur;
551
552 toolbar_get_grect(tb, 0, &cur);
553
554 if (x != cur.g_x || y != cur.g_y) {
555 tb->area.g_x = x;
556 tb->area.g_y = y;
557 tb->reflow = true;
558 }
559}
560
561void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area)
562{
563 if (area->g_w != tb->area.g_w) {
564
565 tb->area = *area;
566
567 /* reflow now, just for url input calucation: */
568 toolbar_reflow(tb);
569 /* this will request an textarea redraw: */
571 tb->form[TOOLBAR_AREA_URL].ob_width,
572 tb->form[TOOLBAR_AREA_URL].ob_height-1);
573 }
574 else {
575 tb->area = *area;
576 }
577 /* reflow for next redraw: */
578 /* TODO: that's only required because we do not reset others toolbars reflow
579 state on reflow */
580 tb->reflow = true;
581}
582
583
584void toolbar_set_url(struct s_toolbar *tb, const char *text)
585{
586 NSLOG(netsurf, INFO, "tb %p", tb);
587
589
590 if (tb->attached && tb->visible) {
591 GRECT area;
592 toolbar_get_grect(tb, TOOLBAR_AREA_URL, &area);
595 assert(gw != NULL);
596 toolbar_update_buttons(tb, gw->browser->bw , 0);
597 }
598}
599
601{
602 GRECT throbber_area;
603
604 tb->throbber.running = active;
605 if (active) {
607 } else {
609 }
610
611 tb->reflow = true;
612 toolbar_get_grect(tb, TOOLBAR_THROBBER_AREA, &throbber_area);
613 window_schedule_redraw_grect(tb->owner, &throbber_area);
614}
615
616void toolbar_set_visible(struct s_toolbar *tb, short area, bool visible)
617{
618 if (area == 0) {
619 if ((visible == false) && (tb->visible == true)) {
620 tb->visible = false;
621 tb->reflow = true;
622 } else if((visible == true) && (tb->visible == false)) {
623 tb->visible = false;
624 tb->reflow = true;
625 }
626 } else if (area == TOOLBAR_AREA_SEARCH) {
627 tb->search_visible = visible;
628 tb->reflow = true;
629 OBJECT *frm = toolbar_get_form(tb);
630 if(visible == false){
631 frm[TOOLBAR_AREA_SEARCH].ob_flags |= OF_HIDETREE;
632 } else {
633 frm[TOOLBAR_AREA_SEARCH].ob_flags &= ~OF_HIDETREE;
634 }
635 }
636}
637
638void toolbar_set_reflow(struct s_toolbar *tb, bool do_reflow)
639{
640 tb->reflow = do_reflow;
641}
642
643void toolbar_set_attached(struct s_toolbar *tb, bool attached)
644{
645 tb->attached = attached;
646
647}
648
650{
651 GRECT throbber_area;
652
653 assert(tb->throbber.running == true);
654
655 if(tb->throbber.running == false)
656 return;
657
658 tb->throbber.index++;
661 }
662
663 tb->reflow = true;
664 toolbar_get_grect(tb, TOOLBAR_THROBBER_AREA, &throbber_area);
665 window_schedule_redraw_grect(tb->owner, &throbber_area);
666}
667
668bool toolbar_text_input(struct s_toolbar *tb, char *text)
669{
670 bool handled = true;
671
672 NSLOG(netsurf, INFO, "tb %p", tb);
673
674 return(handled);
675}
676
677bool toolbar_key_input(struct s_toolbar *tb, short nkc)
678{
679
680 assert(tb!=NULL);
681 bool ret = false;
683
684 assert( gw != NULL );
685
686 long ucs4;
687 long ik = nkc_to_input_key(nkc, &ucs4);
688
689 if (ik == 0) {
690 if ((nkc&0xFF) >= 9) {
691 ret = textarea_keypress(tb->url.textarea, ucs4);
692 }
693
694 } else if (ik == NS_KEY_CR || ik == NS_KEY_NL) {
695 nsurl *url;
696 char tmp_url[PATH_MAX];
697 if ( textarea_get_text( tb->url.textarea, tmp_url, PATH_MAX) > 0 ) {
699 if (nsurl_create((const char*)&tmp_url, &url) != NSERROR_OK) {
700 atari_warn_user("NoMemory", 0);
701 } else {
704 NULL, NULL, NULL);
706 }
707
708 ret = true;
709 }
710
711 } else if (ik == NS_KEY_COPY_SELECTION) {
712 // copy whole text
713 char * text;
714 int len;
715 len = textarea_get_text( tb->url.textarea, NULL, 0 );
716 text = malloc( len+1 );
717 if (text){
718 textarea_get_text( tb->url.textarea, text, len+1 );
720 free( text );
721 }
722
723 } else if ( ik == NS_KEY_PASTE) {
724 char * clip = scrap_txt_read();
725 if ( clip != NULL ){
726 int clip_length = strlen( clip );
727 if ( clip_length > 0 ) {
728 char *utf8;
729 nserror res;
730 /* Clipboard is in local encoding so
731 * convert to UTF8 */
733 if ( res == NSERROR_OK ) {
734 toolbar_set_url(tb, utf8);
735 free(utf8);
736 ret = true;
737 }
738 }
739 free( clip );
740 }
741
742 } else if (ik == NS_KEY_ESCAPE) {
745
746 } else {
747 ret = textarea_keypress( tb->url.textarea, ik );
748
749 }
750
751 return( ret );
752}
753
754
755void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button)
756{
757 GRECT work;
758 short mx, my, mb, kstat;
759 struct gui_window * gw;
760
761 NSLOG(netsurf, INFO, "tb %p", tb);
762
763
764 if (obj==TOOLBAR_AREA_URL) {
765 graf_mkstate(&mx, &my, &mb, &kstat);
766 toolbar_get_grect(tb, TOOLBAR_AREA_URL, &work);
767 mx -= work.g_x;
768 my -= work.g_y;
769
770 /* TODO: reset mouse state of browser window? */
771 /* select whole text when newly focused, otherwise set caret to
772 end of text */
774 window_set_focus(tb->owner, URL_WIDGET, (void*)&tb->url);
775
776 } else if (mb & 1) {
777 /* url widget has focus and mouse button is still pressed... */
778
780 mx, my );
781 short prev_x = mx;
782 short prev_y = my;
783 do {
784 if (abs(prev_x-mx) > 5 || abs(prev_y-my) > 5) {
786 BROWSER_MOUSE_HOLDING_1, mx, my );
787 prev_x = mx;
788 prev_y = my;
791 }
792 graf_mkstate( &mx, &my, &mb, &kstat );
793 mx = mx - (work.g_x);
794 my = my - (work.g_y);
795 } while (mb & 1);
796
798 my);
799
800 } else if (button & 2) {
801 // TODO: open a context popup
802
803 } else {
804 /* when execution reaches here, mouse input is a click or dclick */
805 /* TODO: recognize click + shitoolbar_update_buttonsft key */
806 if (aes_event_out.emo_mclicks == 2 ) {
809 my);
810 toolbar_get_grect(tb, TOOLBAR_AREA_URL, &work);
812 } else {
814 BROWSER_MOUSE_PRESS_1, mx, my );
815 }
816 }
817
818 } else if(obj==TOOLBAR_TB_SRCH) {
820
821 } else if (obj==TOOLBAR_BT_SEARCH_FWD) {
822 gw = tb->owner->active_gui_window;
823 assert(gw->search);
825
826 } else if (obj==TOOLBAR_BT_SEARCH_BACK) {
827 gw = tb->owner->active_gui_window;
828 assert(gw->search);
830
831 } else if (obj==TOOLBAR_BT_CLOSE_SEARCH) {
832 tb->form[TOOLBAR_BT_CLOSE_SEARCH].ob_state &= ~OS_SELECTED;
834 } else {
835 struct s_tb_button *bt = find_button(tb, obj);
836 if (bt != NULL && bt->state != button_off) {
837 bt->cb_click(tb);
839 toolbar_update_buttons(tb, gw->browser->bw, 0);
840 }
841 }
842}
843
844
845/**
846 * Receive a specific region of the toolbar.
847 * @param tb - the toolbar pointer
848 * @param which - the area to retrieve: 0 to receive the workarea,
849 all other values must be
850 an resource ID of the TOOLBAR tree.
851 * @param dst - GRECT pointer receiving the area.
852 */
853
854void toolbar_get_grect(struct s_toolbar *tb, short which, GRECT *dst)
855{
856#define LAST_TOOLBAR_AREA TOOLBAR_AREA_SEARCH
857
858 if (tb->reflow == true) {
859 toolbar_reflow(tb);
860 }
861
862 objc_offset(tb->form, which, &dst->g_x, &dst->g_y);
863
864 dst->g_w = tb->form[which].ob_width;
865 dst->g_h = tb->form[which].ob_height;
866 //tb->form[which].ob_height;
867
868 //printf("Toolbar get grect (%d): ", which);
869 //dbg_grect("", dst);
870
871#undef LAST_TOOLBAR_AREA
872}
873
874
876 enum toolbar_textarea which)
877{
878 return(tb->url.textarea);
879}
880
881char *toolbar_get_url(struct s_toolbar *tb)
882{
883 char * c_url = NULL;
884 int c_url_len = 0;
885
886 c_url_len = textarea_get_text(tb->url.textarea, NULL, 0);
887
888 if (c_url_len > -1) {
889 c_url = malloc(c_url_len+1);
890 textarea_get_text(tb->url.textarea, c_url, c_url_len+1);
891 }
892
893 return(c_url);
894}
895
897{
898 nsurl * ns_url = NULL;
899 char * c_url;
900
901 c_url = toolbar_get_url(tb);
902 if (c_url) {
903 nsurl_create(c_url, &ns_url);
904 }
905
906 return(ns_url);
907}
908
909
910OBJECT *toolbar_get_form(struct s_toolbar *tb)
911{
912 return(tb->form);
913}
914
915
916/* public event handler */
918{
919 struct browser_window * bw;
920 struct gui_window * gw;
921
923 assert(gw != NULL);
924 bw = gw->browser->bw;
925 assert(bw != NULL);
926
929 }
930}
931
933{
934 struct browser_window * bw;
935 struct gui_window * gw;
936
938 assert(gw != NULL);
939 bw = gw->browser->bw;
940 assert(bw != NULL);
941
943}
944
946{
947 struct browser_window * bw;
948 struct gui_window * gw;
949
951 assert(gw != NULL);
952 bw = gw->browser->bw;
953 assert(bw != NULL);
954
957 }
958}
959
961{
962 struct browser_window * bw;
963 struct gui_window * gw;
964 nsurl *url;
965 char * use_url = NULL;
966
968 assert(gw != NULL);
969 bw = gw->browser->bw;
970 assert(bw != NULL);
971
972 use_url = nsoption_charp(homepage_url);
973 if (use_url == NULL || strlen(use_url) == 0){
974 use_url = (char*)"about:welcome";
975 }
976
977 if (nsurl_create(use_url, &url) != NSERROR_OK) {
978 atari_warn_user("NoMemory", 0);
979 } else {
981 url,
982 NULL,
984 NULL,
985 NULL,
986 NULL);
988 }
989}
990
991
993{
994 struct browser_window * bw;
995 struct gui_window * gw;
996
998
999 assert(gw != NULL);
1000
1001 bw = gw->browser->bw;
1002
1003 assert(bw != NULL);
1004
1006}
1007
1009{
1010 nsurl * ns_url = NULL;
1011 char * c_url;
1012 int c_url_len = 0;
1013
1014 c_url = toolbar_get_url(tb);
1015 c_url_len = strlen(c_url);
1016
1017 nsurl_create(c_url, &ns_url);
1018
1019 if (hotlist_has_url(ns_url)) {
1020 char msg[c_url_len+100];
1021 snprintf(msg, c_url_len+100, "Really delete from favorites: \"%s\"",
1022 c_url);
1023 if (gemtk_msg_box_show(GEMTK_MSG_BOX_CONFIRM, msg)) {
1024 hotlist_remove_url(ns_url);
1025 }
1026
1027 } else {
1028 hotlist_add_url(ns_url);
1029
1030 }
1031
1032 nsurl_unref(ns_url);
1033 free(c_url);
1034}
1035
1037{
1038
1039}
int scrap_txt_write(char *str)
Definition: clipboard.c:50
char * scrap_txt_read(void)
Definition: clipboard.c:62
@ URL_WIDGET
Definition: gui.h:82
@ BROWSER
Definition: gui.h:84
@ SEARCH_INPUT
Definition: gui.h:83
#define PATH_MAX
Definition: gui.h:31
nserror atari_warn_user(const char *warning, const char *detail)
Warn the user of an event.
Definition: misc.c:56
long nkc_to_input_key(short nkc, long *ucs4_out)
Convert NKC to netsurf input key code and/or to ucs4 (depends on keycode).
Definition: misc.c:213
const struct plotter_table atari_plotters
atari plottr operation table
Definition: plot.c:2507
float plot_set_scale(float scale)
set scale of plotter.
Definition: plot.c:1854
bool plot_set_dimensions(const struct redraw_context *ctx, int x, int y, int w, int h)
Set plot origin and canvas size.
Definition: plot.c:1806
#define THROBBER_MAX_INDEX
Definition: toolbar.c:58
EVMULT_OUT aes_event_out
Definition: gui.c:104
static void tb_txt_request_redraw(void *data, int x, int y, int w, int h)
Callback for textarea redraw.
Definition: toolbar.c:182
void toolbar_init(void)
Definition: toolbar.c:236
static struct s_tb_button * button_init(struct s_toolbar *tb, OBJECT *tree, int index, struct s_tb_button *instance)
Definition: toolbar.c:221
void toolbar_set_url(struct s_toolbar *tb, const char *text)
Definition: toolbar.c:584
char * toolbar_get_url(struct s_toolbar *tb)
Definition: toolbar.c:881
nsurl * toolbar_get_nsurl(struct s_toolbar *tb)
Definition: toolbar.c:896
static short __CDECL toolbar_url_userdraw(PARMBLK *parmblock)
Definition: toolbar.c:231
char * option_homepage_url
Definition: gui.c:87
#define TOOLBAR_BUTTON_NUM_STATES
Definition: toolbar.c:65
static float toolbar_url_scale
Definition: toolbar.c:93
void toolbar_set_throbber_state(struct s_toolbar *tb, bool active)
Definition: toolbar.c:600
static void toolbar_reflow(struct s_toolbar *tb)
Definition: toolbar.c:364
static int toolbar_calculate_height(struct s_toolbar *tb)
Definition: toolbar.c:347
static OBJECT * aes_toolbar
Definition: toolbar.c:87
void * h_gem_rsrc
Definition: gui.c:75
static int area_full_height
Definition: toolbar.c:92
OBJECT * toolbar_get_form(struct s_toolbar *tb)
Definition: toolbar.c:910
long atari_plot_flags
Definition: plot.c:209
void toolbar_set_reflow(struct s_toolbar *tb, bool do_reflow)
Definition: toolbar.c:638
static int area_search_height
Definition: toolbar.c:91
void toolbar_redraw(struct s_toolbar *tb, GRECT *clip)
Definition: toolbar.c:416
int atari_plot_vdi_handle
Definition: plot.c:208
struct s_toolbar * toolbar_create(struct s_gui_win_root *owner)
Definition: toolbar.c:267
static bool init
Definition: toolbar.c:89
static OBJECT * throbber_form
Definition: toolbar.c:88
struct gui_window * input_window
Definition: gui.c:73
e_toolbar_button_states
Definition: toolbar.c:61
@ button_off
Definition: toolbar.c:63
@ button_on
Definition: toolbar.c:62
void toolbar_favorite_click(struct s_toolbar *tb)
Definition: toolbar.c:1008
void toolbar_set_attached(struct s_toolbar *tb, bool attached)
Definition: toolbar.c:643
void toolbar_back_click(struct s_toolbar *tb)
Definition: toolbar.c:917
static plot_font_style_t font_style_url
Definition: toolbar.c:95
void toolbar_get_grect(struct s_toolbar *tb, short which, GRECT *dst)
Receive a specific region of the toolbar.
Definition: toolbar.c:854
void toolbar_stop_click(struct s_toolbar *tb)
Definition: toolbar.c:992
struct textarea * toolbar_get_textarea(struct s_toolbar *tb, enum toolbar_textarea which)
Definition: toolbar.c:875
bool toolbar_text_input(struct s_toolbar *tb, char *text)
Definition: toolbar.c:668
void toolbar_set_visible(struct s_toolbar *tb, short area, bool visible)
Definition: toolbar.c:616
void toolbar_set_width(struct s_toolbar *tb, short w)
Definition: toolbar.c:528
void toolbar_reload_click(struct s_toolbar *tb)
Definition: toolbar.c:932
void toolbar_destroy(struct s_toolbar *tb)
Definition: toolbar.c:337
void toolbar_throbber_progress(struct s_toolbar *tb)
Definition: toolbar.c:649
#define THROBBER_MIN_INDEX
Definition: toolbar.c:57
void toolbar_update_buttons(struct s_toolbar *tb, struct browser_window *bw, short button)
Definition: toolbar.c:458
static int area_navigation_height
Definition: toolbar.c:90
void toolbar_forward_click(struct s_toolbar *tb)
Definition: toolbar.c:945
static struct s_tb_button tb_buttons[]
Definition: toolbar.c:107
static void tb_txt_callback(void *data, struct textarea_msg *msg)
Definition: toolbar.c:202
void toolbar_set_dimensions(struct s_toolbar *tb, GRECT *area)
Definition: toolbar.c:561
bool toolbar_key_input(struct s_toolbar *tb, short nkc)
Definition: toolbar.c:677
#define THROBBER_INACTIVE_INDEX
Definition: toolbar.c:59
void toolbar_home_click(struct s_toolbar *tb)
Definition: toolbar.c:960
static struct s_toolbar_style toolbar_styles[]
Definition: toolbar.c:145
void toolbar_crypto_click(struct s_toolbar *tb)
Definition: toolbar.c:1036
void toolbar_mouse_input(struct s_toolbar *tb, short obj, short button)
Definition: toolbar.c:755
static struct s_tb_button * find_button(struct s_toolbar *tb, int rsc_id)
Find a button for a specific resource ID.
Definition: toolbar.c:167
void toolbar_set_origin(struct s_toolbar *tb, short x, short y)
Definition: toolbar.c:548
static const struct redraw_context toolbar_rdrw_ctx
Definition: toolbar.c:156
void toolbar_exit(void)
Definition: toolbar.c:261
toolbar_textarea
Definition: toolbar.h:28
nserror browser_window_history_forward(struct browser_window *bw, bool new_window)
Go forward in the history.
nserror browser_window_history_back(struct browser_window *bw, bool new_window)
Go back in the history.
Interface to browser history operations.
Browser window creation and manipulation interface.
nserror browser_window_navigate(struct browser_window *bw, struct nsurl *url, struct nsurl *referrer, enum browser_window_nav_flags flags, char *post_urlenc, struct fetch_multipart_data *post_multipart, struct hlcache_handle *parent)
Start fetching a page in a browser window.
bool browser_window_back_available(struct browser_window *bw)
Check availability of Back action for a given browser window.
nserror browser_window_reload(struct browser_window *bw, bool all)
Reload the page in a browser window.
bool browser_window_reload_available(struct browser_window *bw)
Check availability of Reload action for a given browser window.
bool browser_window_forward_available(struct browser_window *bw)
Check availability of Forward action for a given browser window.
void browser_window_stop(struct browser_window *bw)
Stop all fetching activity in a browser window.
bool browser_window_stop_available(struct browser_window *bw)
Check availability of Stop action for a given browser window.
@ BW_NAVIGATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
nserror hotlist_add_url(nsurl *url)
Add an entry to the hotlist for given URL.
Definition: hotlist.c:1431
bool hotlist_has_url(nsurl *url)
Check whether given URL is present in hotlist.
Definition: hotlist.c:1494
void hotlist_remove_url(nsurl *url)
Remove any entries matching the given URL from the hotlist.
Definition: hotlist.c:1536
@ SEARCH_FLAG_FORWARDS
Definition: search.h:32
void textarea_redraw(struct textarea *ta, int x, int y, colour bg, float scale, const struct rect *clip, const struct redraw_context *ctx)
Handle redraw requests for text areas.
Definition: textarea.c:2131
void textarea_set_dimensions(struct textarea *ta, int width, int height)
Set the dimensions of a textarea.
Definition: textarea.c:3318
struct textarea * textarea_create(const textarea_flags flags, const textarea_setup *setup, textarea_client_callback callback, void *data)
Create a text area.
Definition: textarea.c:1852
void textarea_destroy(struct textarea *ta)
Destroy a text area.
Definition: textarea.c:1975
bool textarea_set_text(struct textarea *ta, const char *text)
Set the text in a text area, discarding any current text.
Definition: textarea.c:1995
int textarea_get_text(struct textarea *ta, char *buf, unsigned int len)
Extract the text from a text area.
Definition: textarea.c:2078
textarea_mouse_status textarea_mouse_action(struct textarea *ta, browser_mouse_state mouse, int x, int y)
Handles all kinds of mouse action.
Definition: textarea.c:3069
bool textarea_keypress(struct textarea *ta, uint32_t key)
Key press handling for text areas.
Definition: textarea.c:2450
Single/Multi-line UTF-8 text area interface.
textarea_flags
Text area flags.
Definition: textarea.h:40
@ TEXTAREA_INTERNAL_CARET
Render own caret.
Definition: textarea.h:44
@ TEXTAREA_MSG_DRAG_REPORT
Textarea drag start/end report.
Definition: textarea.h:63
@ TEXTAREA_MSG_REDRAW_REQUEST
Textarea redraw request.
Definition: textarea.h:65
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
nserror utf8_from_local_encoding(const char *string, size_t len, char **result)
Definition: utf8.c:80
void nsatari_search_perform(struct s_search_form_session *s, OBJECT *obj, search_flags_t f)
Definition: search.c:262
static size_t clip_length
Definition: textselection.c:69
Core mouse and pointer states.
@ BROWSER_MOUSE_PRESS_1
button 1 pressed
Definition: mouse.h:50
@ BROWSER_MOUSE_HOVER
No mouse buttons pressed, May be used to indicate hover or end of drag.
Definition: mouse.h:47
@ BROWSER_MOUSE_CLICK_1
button 1 clicked.
Definition: mouse.h:55
@ BROWSER_MOUSE_DOUBLE_CLICK
button double clicked
Definition: mouse.h:60
@ BROWSER_MOUSE_DRAG_1
start of button 1 drag
Definition: mouse.h:65
@ BROWSER_MOUSE_HOLDING_1
during button 1 drag
Definition: mouse.h:73
Target independent plotting interface.
Interface to key press operations.
@ NS_KEY_CR
Definition: keypress.h:40
@ NS_KEY_SELECT_ALL
Definition: keypress.h:32
@ NS_KEY_PASTE
Definition: keypress.h:43
@ NS_KEY_COPY_SELECTION
Definition: keypress.h:33
@ NS_KEY_NL
Definition: keypress.h:38
@ NS_KEY_DELETE_LEFT
Definition: keypress.h:35
@ NS_KEY_ESCAPE
Definition: keypress.h:47
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
NetSurf URL handling (interface).
nserror nsurl_create(const char *const url_s, nsurl **url)
Create a NetSurf URL object from a URL string.
void nsurl_unref(nsurl *url)
Drop a reference to a NetSurf URL object.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
@ FONTF_NONE
Definition: plot_style.h:102
@ PLOT_FONT_FAMILY_SANS_SERIF
Definition: plot_style.h:89
#define PLOT_STYLE_SCALE
Scaling factor for plot styles.
Definition: plot_style.h:45
struct gui_window * window_get_active_gui_window(ROOTWIN *rootwin)
Definition: rootwin.c:586
void window_set_focus(struct s_gui_win_root *rootwin, enum focus_element_type type, void *element)
Definition: rootwin.c:498
void window_schedule_redraw_grect(ROOTWIN *rootwin, GRECT *area)
Definition: rootwin.c:807
void window_close_search(ROOTWIN *rootwin)
Definition: rootwin.c:680
bool window_url_widget_has_focus(struct s_gui_win_root *rootwin)
Definition: rootwin.c:531
void window_process_redraws(ROOTWIN *rootwin)
Definition: rootwin.c:1015
Interface to utility string handling.
Browser window data.
struct browser_window * bw
first entry in window list
Definition: gui.c:296
bool active
Whether the throbber should be active.
Definition: gui.h:89
char * url
Definition: gui.h:154
struct s_search_form_session * search
Definition: gui.h:158
struct s_browser * browser
Definition: gui.h:149
struct browser_window * bw
The 'content' window that is rendered in the gui_window.
Definition: gui.c:314
High-level cache handle.
Definition: hlcache.c:66
Font style for plotting.
Definition: plot_style.h:111
plot_font_generic_family_t family
Generic family to plot with.
Definition: plot_style.h:118
colour foreground
Colour of text.
Definition: plot_style.h:123
plot_style_fixed size
Font size, in pt.
Definition: plot_style.h:119
colour background
Background colour to blend to, if appropriate.
Definition: plot_style.h:122
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
Redraw context.
Definition: plotters.h:51
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59
struct browser_window * bw
Definition: gui.h:137
struct gui_window * active_gui_window
Definition: gui.h:127
short index
Definition: toolbar.c:75
enum e_toolbar_button_states state
Definition: toolbar.c:74
GRECT area
Definition: toolbar.c:76
struct s_toolbar * owner
Definition: toolbar.c:73
short rsc_id
Definition: toolbar.c:70
void(* cb_click)(struct s_toolbar *tb)
Definition: toolbar.c:71
struct hlcache_handle * icon[TOOLBAR_BUTTON_NUM_STATES]
Definition: toolbar.c:72
short max_index
Definition: toolbar.h:39
int font_height_pt
Definition: toolbar.c:142
int style
Definition: toolbar.h:53
bool search_visible
Definition: toolbar.h:57
struct s_tb_button * buttons
Definition: toolbar.h:51
GRECT area
Definition: toolbar.h:48
struct s_gui_win_root * owner
Definition: toolbar.h:44
int btcnt
Definition: toolbar.h:52
struct s_url_widget url
Definition: toolbar.h:45
struct s_throbber_widget throbber
Definition: toolbar.h:46
bool visible
Definition: toolbar.h:56
bool reflow
Definition: toolbar.h:55
bool attached
Definition: toolbar.h:54
OBJECT * form
Definition: toolbar.h:47
struct textarea * textarea
Definition: toolbar.h:33
textarea message
Definition: textarea.h:74
textarea_msg_type type
Indicates message data type.
Definition: textarea.h:77
struct rect redraw
With _REDRAW_REQUEST.
Definition: textarea.h:84
union textarea_msg::@79 data
Depends on msg type.
textarea setup parameters
Definition: textarea.h:108
int pad_top
Textarea top padding.
Definition: textarea.h:112
colour border_col
Textarea border colour.
Definition: textarea.h:118
int height
Textarea height.
Definition: textarea.h:110
int width
Textarea width.
Definition: textarea.h:109
int border_width
Textarea border width.
Definition: textarea.h:117
int pad_right
Textarea right padding.
Definition: textarea.h:113
int pad_left
Textarea left padding.
Definition: textarea.h:115
plot_font_style_t text
Textarea background colour and font.
Definition: textarea.h:122
int pad_bottom
Textarea bottom padding.
Definition: textarea.h:114
colour selected_text
Textarea selected text colour.
Definition: textarea.h:120
colour selected_bg
Textarea selection background colour.
Definition: textarea.h:121
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:297
UTF-8 manipulation functions (interface).
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357