NetSurf
deskmenu.c
Go to the documentation of this file.
1/*
2 * Copyright 2010 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 <stdlib.h>
20#include <cflib.h>
21
22#include "utils/log.h"
23#include "utils/nsurl.h"
24#include "utils/messages.h"
25#include "utils/nsoption.h"
26#include "utils/utils.h"
28#include "netsurf/keypress.h"
30
31#include "atari/res/netsurf.rsh"
32#include "atari/gemtk/gemtk.h"
33#include "atari/deskmenu.h"
34#include "atari/hotlist.h"
35#include "atari/history.h"
36#include "atari/cookies.h"
37#include "atari/toolbar.h"
38#include "atari/settings.h"
39#include "atari/misc.h"
40#include "atari/gui.h"
41#include "atari/findfile.h"
42#include "atari/about.h"
43#include "atari/plot/plot.h"
44#include "atari/rootwin.h"
45
46typedef void __CDECL (*menu_evnt_func)(short item, short title, void * data);
47
49{
50 char ascii; /* either ascii or */
51 long keycode; /* normalised keycode is valid */
52 short mod; /* shift / ctrl etc */
53};
54
56 short title; /* to which menu this item belongs */
57 short rid; /* resource ID */
58 menu_evnt_func menu_func; /* click handler */
59 struct s_accelerator accel; /* accelerator info */
60 char * menustr;
61};
62
63static void register_menu_str(struct s_menu_item_evnt * mi);
64//static void __CDECL evnt_menu(WINDOW * win, short buff[8]);
65
66extern void *h_gem_rsrc;
67extern bool html_redraw_debug;
68extern struct gui_window * input_window;
69extern char options[PATH_MAX];
70extern const char * option_homepage_url;
71extern int option_window_width;
72extern int option_window_height;
73extern int option_window_x;
74extern int option_window_y;
75
76static OBJECT * h_gem_menu;
77
78
79/* Zero based resource tree ids: */
80#define T_ABOUT 0
81#define T_FILE MAINMENU_T_FILE - MAINMENU_T_FILE + 1
82#define T_EDIT MAINMENU_T_EDIT - MAINMENU_T_FILE + 1
83#define T_VIEW MAINMENU_T_VIEW - MAINMENU_T_FILE + 1
84#define T_NAV MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1
85#define T_UTIL MAINMENU_T_UTIL - MAINMENU_T_FILE + 1
86#define T_HELP MAINMENU_T_NAVIGATE - MAINMENU_T_FILE + 1
87/* Count of the above defines: */
88#define NUM_MENU_TITLES 7
89
90
91static void __CDECL menu_about(short item, short title, void *data);
92static void __CDECL menu_new_win(short item, short title, void *data);
93static void __CDECL menu_open_url(short item, short title, void *data);
94static void __CDECL menu_open_file(short item, short title, void *data);
95static void __CDECL menu_close_win(short item, short title, void *data);
96static void __CDECL menu_save_page(short item, short title, void *data);
97static void __CDECL menu_quit(short item, short title, void *data);
98static void __CDECL menu_cut(short item, short title, void *data);
99static void __CDECL menu_copy(short item, short title, void *data);
100static void __CDECL menu_paste(short item, short title, void *data);
101static void __CDECL menu_find(short item, short title, void *data);
102static void __CDECL menu_choices(short item, short title, void *data);
103static void __CDECL menu_stop(short item, short title, void *data);
104static void __CDECL menu_reload(short item, short title, void *data);
105static void __CDECL menu_dec_scale(short item, short title, void *data);
106static void __CDECL menu_inc_scale(short item, short title, void *data);
107static void __CDECL menu_toolbars(short item, short title, void *data);
108static void __CDECL menu_savewin(short item, short title, void *data);
109static void __CDECL menu_debug_render(short item, short title, void *data);
110static void __CDECL menu_fg_images(short item, short title, void *data);
111static void __CDECL menu_bg_images(short item, short title, void *data);
112static void __CDECL menu_back(short item, short title, void *data);
113static void __CDECL menu_forward(short item, short title, void *data);
114static void __CDECL menu_home(short item, short title, void *data);
115static void __CDECL menu_lhistory(short item, short title, void *data);
116static void __CDECL menu_ghistory(short item, short title, void *data);
117static void __CDECL menu_add_bookmark(short item, short title, void *data);
118static void __CDECL menu_bookmarks(short item, short title, void *data);
119static void __CDECL menu_cookies(short item, short title, void *data);
120static void __CDECL menu_vlog(short item, short title, void *data);
121static void __CDECL menu_help_content(short item, short title, void *data);
122
124{
125 {T_ABOUT,MAINMENU_M_ABOUT, menu_about, {0,0,0}, NULL },
126 {T_FILE, MAINMENU_M_NEWWIN, menu_new_win, {0,0,0}, NULL},
127 {T_FILE, MAINMENU_M_OPENURL, menu_open_url, {'G',0,K_CTRL}, NULL},
128 {T_FILE, MAINMENU_M_OPENFILE, menu_open_file, {'O',0,K_CTRL}, NULL},
129 {T_FILE, MAINMENU_M_CLOSEWIN, menu_close_win, {0,0,0}, NULL},
130 {T_FILE, MAINMENU_M_SAVEPAGE, menu_save_page, {0,NK_F3,0}, NULL},
131 {T_FILE, MAINMENU_M_QUIT, menu_quit, {'Q',0,K_CTRL}, NULL},
132 {T_EDIT, MAINMENU_M_CUT, menu_cut, {'X',0,K_CTRL}, NULL},
133 {T_EDIT, MAINMENU_M_COPY, menu_copy, {'C',0,K_CTRL}, NULL},
134 {T_EDIT, MAINMENU_M_PASTE, menu_paste, {'V',0,K_CTRL}, NULL},
135 {T_EDIT, MAINMENU_M_FIND, menu_find, {0,NK_F4,0}, NULL},
136 {T_VIEW, MAINMENU_M_RELOAD, menu_reload, {0,NK_F5,0}, NULL},
137 {T_VIEW, MAINMENU_INC_SCALE, menu_inc_scale, {'+',0,K_CTRL}, NULL},
138 {T_VIEW, MAINMENU_DEC_SCALE, menu_dec_scale, {'-',0,K_CTRL}, NULL},
139 {T_VIEW, MAINMENU_M_TOOLBARS, menu_toolbars, {0,NK_F1,K_CTRL}, NULL},
140 {T_VIEW, MAINMENU_M_SAVEWIN, menu_savewin, {0,0,0}, NULL},
141 {T_VIEW, MAINMENU_M_DEBUG_RENDER, menu_debug_render, {0,0,0}, NULL},
142 {T_VIEW, MAINMENU_M_FG_IMAGES, menu_fg_images, {0,0,0}, NULL},
143 {T_VIEW, MAINMENU_M_BG_IMAGES, menu_bg_images, {0,0,0}, NULL},
144 {T_VIEW, MAINMENU_M_STOP, menu_stop, {0,NK_ESC,K_ALT}, NULL},
145 {T_NAV, MAINMENU_M_BACK, menu_back, {0,NK_LEFT,K_ALT}, NULL},
146 {T_NAV, MAINMENU_M_FORWARD, menu_forward, {0,NK_RIGHT,K_ALT}, NULL},
147 {T_NAV, MAINMENU_M_HOME, menu_home, {0,0,0}, NULL},
148 {T_UTIL, MAINMENU_M_LHISTORY,menu_lhistory, {0,NK_F7,0}, NULL},
149 {T_UTIL, MAINMENU_M_GHISTORY, menu_ghistory, {0,NK_F7,K_CTRL}, NULL},
150 {T_UTIL, MAINMENU_M_ADD_BOOKMARK, menu_add_bookmark, {'D',0,K_CTRL}, NULL},
151 {T_UTIL, MAINMENU_M_BOOKMARKS, menu_bookmarks, {0,NK_F6,0}, NULL},
152 {T_UTIL, MAINMENU_M_COOKIES, menu_cookies, {0,0,0}, NULL},
153 {T_UTIL, MAINMENU_M_CHOICES, menu_choices, {0,0,0}, NULL},
154 {T_UTIL, MAINMENU_M_VLOG, menu_vlog, {'V',0,K_ALT}, NULL},
155 {T_HELP, MAINMENU_M_HELP_CONTENT, menu_help_content, {0,NK_F1,0}, NULL},
156 {-1, -1, NULL,{0,0,0}, NULL }
157};
158
159
160/*
161 static void __CDECL evnt_menu(WINDOW * win, short buff[8])
162 {
163 int title = buff[3];
164 INT16 x,y;
165 char *str;
166 struct gui_window * gw = window_list;
167 int i=0;
168
169 deskmenu_dispatch_item(buff[3], buff[4]);
170 }
171*/
172
173/*
174 Menu item event handlers:
175*/
176
177static void __CDECL menu_about(short item, short title, void *data)
178{
179 /*
180 nsurl *url;
181 nserror error;
182 char buf[PATH_MAX];
183
184 NSLOG(netsurf, INFO, "abort menu");
185 strcpy((char*)&buf, "file://");
186 strncat((char*)&buf, (char*)"./doc/README.TXT",
187 PATH_MAX - (strlen("file://")+1) );
188
189 error = nsurl_create(buf, &url);
190 if (error == NSERROR_OK) {
191 error = browser_window_create(BW_CREATE_HISTORY,
192 url,
193 NULL,
194 NULL,
195 NULL);
196 nsurl_unref(url);
197 }
198 if (error != NSERROR_OK) {
199 atari_warn_user(messages_get_errorcode(error), 0);
200 }
201 */
203}
204
205static void __CDECL menu_new_win(short item, short title, void *data)
206{
207 nsurl *url;
208 nserror error;
209 const char *addr;
210
211 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
212
213 if (nsoption_charp(homepage_url) != NULL) {
214 addr = nsoption_charp(homepage_url);
215 } else {
216 addr = NETSURF_HOMEPAGE;
217 }
218
219 /* create an initial browser window */
220 error = nsurl_create(addr, &url);
221 if (error == NSERROR_OK) {
223 url,
224 NULL,
225 NULL,
226 NULL);
227 nsurl_unref(url);
228
229 }
230 if (error != NSERROR_OK) {
232 }
233}
234
235static void __CDECL menu_open_url(short item, short title, void *data)
236{
237 struct gui_window * gw;
238 struct browser_window * bw ;
239 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
240
241 gw = input_window;
242 if( gw == NULL ) {
244 NULL,
245 NULL,
246 NULL,
247 &bw);
248 }
249}
250
251static void __CDECL menu_open_file(short item, short title, void *data)
252{
253
254 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
255
256 const char * filename = file_select(messages_get("OpenFile"), "");
257 if( filename != NULL ){
258 char * urltxt = local_file_to_url( filename );
259 if( urltxt ){
260 nsurl *url;
261 nserror error;
262
263 error = nsurl_create(urltxt, &url);
264 if (error == NSERROR_OK) {
266 url,
267 NULL,
268 NULL,
269 NULL);
270 nsurl_unref(url);
271
272 }
273 if (error != NSERROR_OK) {
275 }
276 free( urltxt );
277 }
278 }
279}
280
281static void __CDECL menu_close_win(short item, short title, void *data)
282{
283 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
284 if( input_window == NULL )
285 return;
287}
288
289static void __CDECL menu_save_page(short item, short title, void *data)
290{
291 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
292 static bool init = true;
293 bool is_folder=false;
294 const char * path;
295
296 if( !input_window )
297 return;
298
299 if( init ){
300 init = false;
302 }
303
304 do {
305 // TODO: localize string
306 path = file_select("Select folder", "");
307 if (path)
308 is_folder = is_dir(path);
309 } while ((is_folder == false) && (path != NULL));
310
311 if( path != NULL ){
313 input_window->browser->bw), path, NULL);
314 }
315
316}
317
318static void __CDECL menu_quit(short item, short title, void *data)
319{
320 short buff[8];
321 memset( &buff, 0, sizeof(short)*8 );
322 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
323 gemtk_wm_send_msg(NULL, AP_TERM, 0, 0, 0, 0);
324}
325
326static void __CDECL menu_cut(short item, short title, void *data)
327{
328 if( input_window != NULL )
330}
331
332static void __CDECL menu_copy(short item, short title, void *data)
333{
334 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
335 if( input_window != NULL )
337}
338
339static void __CDECL menu_paste(short item, short title, void *data)
340{
341 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
342 if( input_window != NULL )
344}
345
346static void __CDECL menu_find(short item, short title, void *data)
347{
348 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
349 if (input_window != NULL) {
350 if (input_window->search) {
352 }
353 else {
355 }
356 }
357}
358
359static void __CDECL menu_choices(short item, short title, void *data)
360{
361 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
363}
364
365static void __CDECL menu_stop(short item, short title, void *data)
366{
367 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
368 if( input_window == NULL )
369 return;
370
371 assert(input_window && input_window->root);
373
374}
375
376static void __CDECL menu_reload(short item, short title, void *data)
377{
378 if(input_window == NULL)
379 return;
381 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
382}
383
384
385static void __CDECL menu_inc_scale(short item, short title, void *data)
386{
387 if(input_window == NULL)
388 return;
389
391}
392
393
394static void __CDECL menu_dec_scale(short item, short title, void *data)
395{
396 if(input_window == NULL)
397 return;
398
400}
401
402
403
404static void __CDECL menu_toolbars(short item, short title, void *data)
405{
406 static int state = 0;
407 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
408 if( input_window != null && input_window->root->toolbar != null ){
409 state = !state;
410 // TODO: implement toolbar hide
411 //toolbar_hide(input_window->root->toolbar, state );
412 }
413}
414
415static void __CDECL menu_savewin(short item, short title, void *data)
416{
417 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
419 GRECT rect;
420 wind_get_grect(gemtk_wm_get_handle(input_window->root->win), WF_CURRXYWH,
421 &rect);
424 option_window_x = rect.g_x;
425 option_window_y = rect.g_y;
426 nsoption_set_int(window_width, rect.g_w);
427 nsoption_set_int(window_height, rect.g_h);
428 nsoption_set_int(window_x, rect.g_x);
429 nsoption_set_int(window_y, rect.g_y);
430 nsoption_write((const char*)&options, NULL, NULL);
431 }
432
433}
434
435static void __CDECL menu_debug_render(short item, short title, void *data)
436{
437 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
439 if( input_window != NULL ) {
440 if ( input_window->browser != NULL
441 && input_window->browser->bw != NULL) {
442 GRECT rect;
445 rect.g_w, rect.g_h );
446 menu_icheck(h_gem_menu, MAINMENU_M_DEBUG_RENDER,
447 (html_redraw_debug) ? 1 : 0);
448 }
449 }
450}
451
452static void __CDECL menu_fg_images(short item, short title, void *data)
453{
454 nsoption_set_bool(foreground_images, !nsoption_bool(foreground_images));
455 menu_icheck(h_gem_menu, MAINMENU_M_FG_IMAGES,
456 (nsoption_bool(foreground_images)) ? 1 : 0);
457}
458
459static void __CDECL menu_bg_images(short item, short title, void *data)
460{
461 nsoption_set_bool(background_images, !nsoption_bool(background_images));
462 menu_icheck(h_gem_menu, MAINMENU_M_BG_IMAGES,
463 (nsoption_bool(background_images)) ? 1 : 0);
464}
465
466static void __CDECL menu_back(short item, short title, void *data)
467{
468 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
469 if( input_window == NULL )
470 return;
472}
473
474static void __CDECL menu_forward(short item, short title, void *data)
475{
476 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
477 if( input_window == NULL )
478 return;
480}
481
482static void __CDECL menu_home(short item, short title, void *data)
483{
484 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
485 if( input_window == NULL )
486 return;
488}
489
490static void __CDECL menu_lhistory(short item, short title, void *data)
491{
492 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
493 if( input_window == NULL )
494 return;
495}
496
497static void __CDECL menu_ghistory(short item, short title, void *data)
498{
499 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
501}
502
503static void __CDECL menu_add_bookmark(short item, short title, void *data)
504{
505 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
506 if (input_window) {
510 NULL
511 );
512 }
513 }
514}
515
516static void __CDECL menu_bookmarks(short item, short title, void *data)
517{
518 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
520}
521
522static void __CDECL menu_cookies(short item, short title, void *data)
523{
524 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
526}
527
528static void __CDECL menu_vlog(short item, short title, void *data)
529{
530 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
532 menu_icheck(h_gem_menu, MAINMENU_M_VLOG, (verbose_log) ? 1 : 0);
533}
534
535static void __CDECL menu_help_content(short item, short title, void *data)
536{
537 NSLOG(netsurf, INFO, "%s", __FUNCTION__);
538}
539
540/*
541 Public deskmenu interface:
542*/
543
544
545/*
546 Parse encoded menu key shortcut
547
548 The format is:
549
550 "[" - marks start of the shortcut
551 "@,^,<" - If the keyshortcut is only valid
552 with modifier keys, one of these characters must directly
553 follow the start mark.
554 Meaning:
555 @ -> Alternate
556 ^ -> Control
557 "#" - keycode or ascii character.
558 The value is handled as keycode if the character value
559 is <= 28 ( Atari chracter table )
560 or if it is interpreted as function key string.
561 (strings: F1 - F10)
562
563*/
564static void register_menu_str( struct s_menu_item_evnt * mi )
565{
566 assert(h_gem_menu != NULL);
567
568 struct s_accelerator * accel = &mi->accel;
569 int i, l=0, x=-1;
570 char str[255];
571 bool is_std_shortcut = false;
572
573 get_string(h_gem_menu, mi->rid, str);
574
575 i = l = strlen(str);
576 while (i > 2) {
577 if ((strncmp(" ", &str[i], 2) == 0) && (strlen(&str[i]) > 2)) {
578 // "Standard" Keyboard Shortcut Element found:
579 NSLOG(netsurf, INFO,
580 "Standard Keyboard Shortcut: \"%s\"\n", &str[i]);
581 x = i+2;
582 is_std_shortcut = true;
583 break;
584 }
585
586 if( str[i] == '['){
587 NSLOG(netsurf, INFO, "Keyboard Shortcut: \"%s\"\n",
588 &str[i]);
589 // "Custom" Keyboard Shortcut Element found (identified by [):
590 x = i;
591 break;
592 }
593 i--;
594 }
595
596 // Parse keyboard shortcut value:
597 if( x > -1 ){
598
599 if (is_std_shortcut == false) {
600 // create a new menu string to hide the "[" mark:
601 mi->menustr = malloc( l+1 );
602 strcpy(mi->menustr, str);
603 mi->menustr[x]=' ';
604 x++;
605 }
606
607 // find & register modifiers:
608 if (str[x] == '@') {
609 accel->mod = K_ALT;
610 if (is_std_shortcut == false) {
611 // only modify menu items when it is malloc'd:
612 mi->menustr[x] = 0x07;
613 }
614 x++;
615 }
616 else if (str[x] == '^') {
617 accel->mod = K_CTRL;
618 x++;
619 }
620 else if (str[x] == 0x01) { // the arrow up chracter (atari-st encoding)
621 accel->mod = K_LSHIFT;
622 x++;
623 }
624
625 // find keycodes / chracters:
626 if( str[x] <= 28 ){
627 // parse symbol
628 switch( str[x] ){
629 case 0x03:
630 accel->keycode = NK_RIGHT;
631 break;
632 case 0x04:
633 accel->keycode = NK_LEFT;
634 break;
635 case 0x1B:
636 accel->keycode = NK_ESC;
637 break;
638 default:
639 break;
640 }
641 } else {
642 if(str[x] == 'F' && ( str[x+1] >= '1' && str[x+1] <= '9') ){
643 // parse function key
644 short fkey = atoi( &str[x+1] );
645 if( (fkey >= 0) && (fkey <= 10) ){
646 accel->keycode = NK_F1 - 1 + fkey;
647 }
648 }
649 else if (strncmp(&str[x], "Home", 4) == 0) {
650 accel->keycode = NK_CLRHOME;
651 }
652 else if (strncmp(&str[x], "Undo", 4) == 0) {
653 accel->keycode = NK_UNDO;
654 }
655 else if (strncmp(&str[x], "Help", 4) == 0) {
656 accel->keycode = NK_HELP;
657 }
658 else {
659 accel->ascii = str[x];
660 }
661 }
662
663 NSLOG(netsurf, INFO,
664 "Registered keyboard shortcut for \"%s\" => mod: %d, ""keycode: %ld, ascii: %c\n",
665 str,
666 accel->mod,
667 accel->keycode,
668 accel->ascii);
669 }
670}
671
672/**
673 * Setup & display an desktop menu.
674 */
675
677{
678 int i;
679
680 h_gem_menu = gemtk_obj_get_tree(MAINMENU);
681
682
683 /* Install menu: */
684 menu_bar(h_gem_menu, MENU_INSTALL);
685
686 /* parse and update menu items: */
687 i = 0;
688 while (menu_evnt_tbl[i].rid != -1) {
689 if(menu_evnt_tbl[i].rid > 0 && menu_evnt_tbl[i].title > 0){
691 /* Update menu string if not null: */
692 if( menu_evnt_tbl[i].menustr != NULL ){
693 menu_text(h_gem_menu, menu_evnt_tbl[i].rid,
694 menu_evnt_tbl[i].menustr);
695 }
696 }
697 i++;
698 }
700 /* Redraw menu: */
701 menu_bar(h_gem_menu, MENU_UPDATE);
702}
703
704/**
705 * Uninstall the desktop menu
706 */
708{
709 int i;
710
711 /* Remove menu from desktop: */
712 menu_bar(h_gem_menu, MENU_REMOVE);
713
714 /* Free modified menu titles: */
715 i=0;
716 while(menu_evnt_tbl[i].rid != -1) {
717 if( menu_evnt_tbl[i].menustr != NULL )
718 free(menu_evnt_tbl[i].menustr);
719 i++;
720 }
721}
722
723/**
724 * Return the deskmenu AES OBJECT tree
725 */
727{
728 return(h_gem_menu);
729}
730
731/**
732 * Handle an menu item event
733 */
734int deskmenu_dispatch_item(short title, short item)
735{
736 int i=0;
737 int retval = 0;
738 OBJECT * menu_root = deskmenu_get_obj_tree();
739
740 menu_tnormal(menu_root, item, 1);
741 menu_tnormal(menu_root, title, 1);
742 menu_bar(menu_root, 1);
743
744 // legacy code, is this sensible?:
745 /*
746 while( gw ) {
747 window_set_focus( gw, WIDGET_NONE, NULL );
748 gw = gw->next;
749 }
750 */
751
752
753 while (menu_evnt_tbl[i].rid != -1) {
754 if (menu_evnt_tbl[i].rid == item) {
755 if (menu_evnt_tbl[i].menu_func != NULL) {
756 menu_evnt_tbl[i].menu_func(item, title, NULL);
757 }
758 break;
759 }
760 i++;
761 }
762
763 return(retval);
764}
765
766/**
767 * Handle an keypress (check for accelerator)
768 */
769int deskmenu_dispatch_keypress(unsigned short kcode, unsigned short kstate,
770 unsigned short nkc)
771{
772 char sascii;
773 bool done = 0;
774 int i = 0;
775
776 sascii = gemtk_keybd2ascii(kcode, 0);
777 if(sascii >= 'a' && sascii <= 'z'){
778 sascii = gemtk_keybd2ascii(kcode, K_LSHIFT);
779 }
780
781 /* Iterate through the menu function table: */
782 while( menu_evnt_tbl[i].rid != -1 && done == false) {
783 if( kstate == menu_evnt_tbl[i].accel.mod
784 && menu_evnt_tbl[i].accel.ascii != 0) {
785 if( menu_evnt_tbl[i].accel.ascii == sascii) {
786 if (menu_evnt_tbl[i].title > 0 && menu_evnt_tbl[i].rid > 0) {
788 menu_evnt_tbl[i].rid);
789 }
790 else {
791 /* Keyboard shortcut not displayed within menu: */
792 menu_evnt_tbl[i].menu_func(0, 0, NULL);
793 }
794 done = true;
795 break;
796 }
797 } else {
798 /* the accel code hides in the keycode: */
799 if( menu_evnt_tbl[i].accel.keycode != 0) {
800 if( menu_evnt_tbl[i].accel.keycode == (nkc & 0xFF) &&
801 kstate == menu_evnt_tbl[i].accel.mod) {
802 if (menu_evnt_tbl[i].title > 0 && menu_evnt_tbl[i].rid > 0) {
804 menu_evnt_tbl[i].rid);
805 }
806 else {
807 /* Keyboard shortcut not displayed within menu: */
808 menu_evnt_tbl[i].menu_func(0, 0, NULL);
809 }
810 done = true;
811 break;
812 }
813 }
814 }
815 i++;
816 }
817 return((done==true) ? 1 : 0);
818}
819
820/**
821 * Refresh the desk menu, reflecting netsurf current state.
822 */
824{
825 menu_icheck(h_gem_menu, MAINMENU_M_DEBUG_RENDER, (html_redraw_debug) ? 1 : 0);
826 menu_icheck(h_gem_menu, MAINMENU_M_FG_IMAGES,
827 (nsoption_bool(foreground_images)) ? 1 : 0);
828 menu_icheck(h_gem_menu, MAINMENU_M_BG_IMAGES,
829 (nsoption_bool(background_images)) ? 1 : 0);
830 menu_icheck(h_gem_menu, MAINMENU_M_VLOG, ((verbose_log == true) ? 1 : 0));
831}
static void gui_window_destroy(struct gui_window *g)
Definition: gui.c:5499
void atari_about_show(void)
Definition: about.c:116
void atari_cookie_manager_open(void)
Definition: cookies.c:171
char * local_file_to_url(const char *filename)
Definition: findfile.c:29
#define PATH_MAX
Definition: gui.h:31
void atari_global_history_open(void)
Definition: history.c:145
const char * file_select(const char *title, const char *name)
Show default file selector.
Definition: misc.c:363
nserror atari_warn_user(const char *warning, const char *detail)
Warn the user of an event.
Definition: misc.c:56
static bool init
Definition: toolbar.c:89
void toolbar_back_click(struct s_toolbar *tb)
Definition: toolbar.c:917
void toolbar_stop_click(struct s_toolbar *tb)
Definition: toolbar.c:992
void toolbar_reload_click(struct s_toolbar *tb)
Definition: toolbar.c:932
void toolbar_forward_click(struct s_toolbar *tb)
Definition: toolbar.c:945
void toolbar_home_click(struct s_toolbar *tb)
Definition: toolbar.c:960
Browser window creation and manipulation interface.
bool browser_window_has_content(struct browser_window *bw)
Find out if a browser window is currently showing a content.
struct nsurl * browser_window_access_url(const struct browser_window *bw)
Access a browser window's URL.
nserror browser_window_create(enum browser_window_create_flags flags, struct nsurl *url, struct nsurl *referrer, struct browser_window *existing, struct browser_window **bw)
Create and open a new root browser window with the given page.
nserror browser_window_set_scale(struct browser_window *bw, float scale, bool absolute)
Sets the scale of a browser window.
void browser_window_reformat(struct browser_window *bw, bool background, int width, int height)
Reformat a browser window contents to a new width or height.
struct hlcache_handle * browser_window_get_content(struct browser_window *bw)
Get a cache handle for the content within a browser window.
@ BW_CREATE_HISTORY
this will form a new history node (don't set for back/reload/etc)
static void __CDECL menu_toolbars(short item, short title, void *data)
Definition: deskmenu.c:404
#define T_HELP
Definition: deskmenu.c:86
#define T_FILE
Definition: deskmenu.c:81
int deskmenu_dispatch_keypress(unsigned short kcode, unsigned short kstate, unsigned short nkc)
Handle an keypress (check for accelerator)
Definition: deskmenu.c:769
static void __CDECL menu_fg_images(short item, short title, void *data)
Definition: deskmenu.c:452
static void __CDECL menu_cut(short item, short title, void *data)
Definition: deskmenu.c:326
static void __CDECL menu_help_content(short item, short title, void *data)
Definition: deskmenu.c:535
static void __CDECL menu_new_win(short item, short title, void *data)
Definition: deskmenu.c:205
#define T_ABOUT
Definition: deskmenu.c:80
static void __CDECL menu_savewin(short item, short title, void *data)
Definition: deskmenu.c:415
static void __CDECL menu_add_bookmark(short item, short title, void *data)
Definition: deskmenu.c:503
static void __CDECL menu_open_file(short item, short title, void *data)
Definition: deskmenu.c:251
int option_window_height
Definition: gui.c:83
void deskmenu_update(void)
Refresh the desk menu, reflecting netsurf current state.
Definition: deskmenu.c:823
#define T_EDIT
Definition: deskmenu.c:82
static void __CDECL menu_reload(short item, short title, void *data)
Definition: deskmenu.c:376
static void __CDECL menu_inc_scale(short item, short title, void *data)
Definition: deskmenu.c:385
const char * option_homepage_url
Definition: gui.c:88
static void __CDECL menu_debug_render(short item, short title, void *data)
Definition: deskmenu.c:435
int option_window_width
Definition: gui.c:82
void * h_gem_rsrc
Definition: gui.c:76
static void __CDECL menu_copy(short item, short title, void *data)
Definition: deskmenu.c:332
static void __CDECL menu_find(short item, short title, void *data)
Definition: deskmenu.c:346
static void __CDECL menu_dec_scale(short item, short title, void *data)
Definition: deskmenu.c:394
char options[PATH_MAX]
Definition: gui.c:91
static void __CDECL menu_about(short item, short title, void *data)
Definition: deskmenu.c:177
#define T_NAV
Definition: deskmenu.c:84
struct gui_window * input_window
Definition: gui.c:74
static void __CDECL menu_home(short item, short title, void *data)
Definition: deskmenu.c:482
static void __CDECL menu_paste(short item, short title, void *data)
Definition: deskmenu.c:339
static void __CDECL menu_ghistory(short item, short title, void *data)
Definition: deskmenu.c:497
static void __CDECL menu_choices(short item, short title, void *data)
Definition: deskmenu.c:359
static void __CDECL menu_bookmarks(short item, short title, void *data)
Definition: deskmenu.c:516
static void __CDECL menu_quit(short item, short title, void *data)
Definition: deskmenu.c:318
struct s_menu_item_evnt menu_evnt_tbl[]
Definition: deskmenu.c:123
static void __CDECL menu_open_url(short item, short title, void *data)
Definition: deskmenu.c:235
int option_window_x
Definition: gui.c:84
#define T_VIEW
Definition: deskmenu.c:83
void deskmenu_destroy(void)
Uninstall the desktop menu.
Definition: deskmenu.c:707
bool html_redraw_debug
Definition: redraw.c:68
static void __CDECL menu_lhistory(short item, short title, void *data)
Definition: deskmenu.c:490
OBJECT * deskmenu_get_obj_tree(void)
Return the deskmenu AES OBJECT tree.
Definition: deskmenu.c:726
static void __CDECL menu_stop(short item, short title, void *data)
Definition: deskmenu.c:365
void __CDECL(* menu_evnt_func)(short item, short title, void *data)
Definition: deskmenu.c:46
static OBJECT * h_gem_menu
Definition: deskmenu.c:76
#define T_UTIL
Definition: deskmenu.c:85
static void __CDECL menu_cookies(short item, short title, void *data)
Definition: deskmenu.c:522
static void __CDECL menu_close_win(short item, short title, void *data)
Definition: deskmenu.c:281
static void __CDECL menu_forward(short item, short title, void *data)
Definition: deskmenu.c:474
static void register_menu_str(struct s_menu_item_evnt *mi)
Definition: deskmenu.c:564
static void __CDECL menu_vlog(short item, short title, void *data)
Definition: deskmenu.c:528
void deskmenu_init(void)
Setup & display an desktop menu.
Definition: deskmenu.c:676
int deskmenu_dispatch_item(short title, short item)
Handle an menu item event.
Definition: deskmenu.c:734
int option_window_y
Definition: gui.c:85
static void __CDECL menu_save_page(short item, short title, void *data)
Definition: deskmenu.c:289
static void __CDECL menu_bg_images(short item, short title, void *data)
Definition: deskmenu.c:459
static void __CDECL menu_back(short item, short title, void *data)
Definition: deskmenu.c:466
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
void atari_hotlist_open(void)
Definition: hotlist.c:237
void atari_hotlist_add_page(const char *url, const char *title)
Definition: hotlist.c:288
Interface to key press operations.
@ NS_KEY_PASTE
Definition: keypress.h:43
@ NS_KEY_COPY_SELECTION
Definition: keypress.h:33
@ NS_KEY_CUT_SELECTION
Definition: keypress.h:44
bool browser_window_key_press(struct browser_window *bw, uint32_t key)
Handle key presses in a browser window.
Definition: textinput.c:107
bool verbose_log
flag to enable verbose logging
Definition: log.c:31
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * messages_get_errorcode(nserror code)
lookup of a message by errorcode from the standard Messages hash.
Definition: messages.c:248
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
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.
const char * nsurl_access(const nsurl *url)
Access a NetSurf URL object as a string.
struct nsurl nsurl
NetSurf URL object.
Definition: nsurl.h:31
void window_open_search(ROOTWIN *rootwin, bool reformat)
Definition: rootwin.c:649
void window_close_search(ROOTWIN *rootwin)
Definition: rootwin.c:680
void window_get_grect(ROOTWIN *rootwin, enum browser_area_e which, GRECT *d)
Definition: rootwin.c:601
@ BROWSER_AREA_CONTENT
Definition: rootwin.h:34
void save_complete_init(void)
Initialise save complete module.
nserror save_complete(hlcache_handle *c, const char *path, save_complete_set_type_cb set_type)
Save an HTML page with all dependencies.
Save HTML document with dependencies (interface).
void open_settings(void)
Definition: settings.c:904
Browser window data.
struct browser_window * bw
first entry in window list
Definition: gui.c:298
struct s_search_form_session * search
Definition: gui.h:158
struct s_gui_win_root * root
Definition: gui.h:148
char * title
Definition: gui.h:153
struct s_browser * browser
Definition: gui.h:149
Rectangle coordinates.
Definition: types.h:40
char ascii
Definition: deskmenu.c:50
short mod
Definition: deskmenu.c:52
long keycode
Definition: deskmenu.c:51
struct browser_window * bw
Definition: gui.h:137
CMP_TOOLBAR toolbar
Definition: gui.h:122
GUIWIN * win
Definition: gui.h:121
struct s_accelerator accel
Definition: deskmenu.c:59
char * menustr
Definition: deskmenu.c:60
menu_evnt_func menu_func
Definition: deskmenu.c:58
struct rect rect
Rectangle coordinates.
nserror nsoption_write(const char *path, struct nsoption_s *opts, struct nsoption_s *defs)
Write options that have changed from the defaults to a file.
Definition: nsoption.c:786
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:331
#define nsoption_set_int(OPTION, VALUE)
set an integer option in the default table
Definition: nsoption.h:348
#define nsoption_set_bool(OPTION, VALUE)
set a boolean option in the default table
Definition: nsoption.h:344
#define nsoption_bool(OPTION)
Get the value of a boolean option.
Definition: nsoption.h:304
Interface to a number of general purpose functionality.
bool is_dir(const char *path)
Check if a directory exists.
Definition: utils.c:94
static nserror path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plot.c:821