summaryrefslogtreecommitdiff
path: root/riscos/menus.c
blob: a287dadbae38eba714c3ac96ad55ec577ba4f401 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
/*
 * This file is part of NetSurf, http://netsurf.sourceforge.net/
 * Licensed under the GNU General Public License,
 *                http://www.opensource.org/licenses/gpl-license
 * Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
 * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
 * Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
 * Copyright 2004 Richard Wilson <not_ginger_matt@users.sourceforge.net>
 */

/** \file
 * Menu creation and handling (implementation).
 */

#include <stdlib.h>
#include <string.h>
#include "oslib/wimp.h"
#include "netsurf/desktop/gui.h"
#include "netsurf/riscos/constdata.h"
#include "netsurf/riscos/gui.h"
#include "netsurf/riscos/theme.h"
#include "netsurf/riscos/options.h"
#include "netsurf/utils/log.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/url.h"
#include "netsurf/utils/utils.h"


/*	Menu index definitions used by menu decoding code so that entries can
	be quickly commented out. Use -ve numbers below -1 to hide an entry.
*/
#define MENU_PAGE	0
#define MENU_OBJECT	-2
#define MENU_SELECTION	-2
#define MENU_NAVIGATE	1
#define MENU_VIEW	2
#define MENU_UTILITIES	-2
#define MENU_HELP	3

static void translate_menu(wimp_menu *menu);
static void ro_gui_menu_prepare_images(void);
static void ro_gui_menu_prepare_toolbars(void);
static void ro_gui_menu_pageinfo(wimp_message_menu_warning *warning);


static wimp_menu *current_menu;
static int current_menu_x, current_menu_y;
gui_window *current_gui;


/*	Default menu item flags
*/
#define DEFAULT_FLAGS (wimp_ICON_TEXT | wimp_ICON_FILLED | \
		(wimp_COLOUR_BLACK << wimp_ICON_FG_COLOUR_SHIFT) | \
		(wimp_COLOUR_WHITE << wimp_ICON_BG_COLOUR_SHIFT))


/*	Iconbar menu
*/
wimp_menu *iconbar_menu = (wimp_menu *)&(wimp_MENU(4)) {
  { "NetSurf" }, 7,2,7,0, 200, 44, 0,
  {
    { 0,              wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Info" } },
    { 0,              wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "AppHelp" } },
    { 0,              wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Choices" } },
    { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Quit" } }
  }
};
int iconbar_menu_height = 4 * 44;


/*	Export submenu
*/
static wimp_MENU(2) export_menu = {
  { "ExportAs" }, 7,2,7,0, 200, 44, 0,
  {
    { wimp_MENU_GIVE_WARNING,                  (wimp_menu *)1, DEFAULT_FLAGS, { "Draw" } },
    { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Text" } }
  }
};


/*	Page submenu
*/
static wimp_MENU(7) page_menu = {
  { "Page" }, 7,2,7,0, 200, 44, 0,
  {
    { wimp_MENU_GIVE_WARNING, (wimp_menu *)1,            DEFAULT_FLAGS,                    { "PageInfo" } },
    { wimp_MENU_GIVE_WARNING, (wimp_menu *)1,            DEFAULT_FLAGS,                    { "Save" } },
    { wimp_MENU_GIVE_WARNING, (wimp_menu *)1,            DEFAULT_FLAGS,                    { "SaveComp" } },
    { 0,                      (wimp_menu *)&export_menu, DEFAULT_FLAGS,                    { "Export" } },
    { wimp_MENU_GIVE_WARNING, (wimp_menu *)1,            DEFAULT_FLAGS,                    { "SaveURL" } },
    { wimp_MENU_SEPARATE,     wimp_NO_SUB_MENU,          DEFAULT_FLAGS | wimp_ICON_SHADED, { "Print" } },
    { wimp_MENU_LAST,         wimp_NO_SUB_MENU,          DEFAULT_FLAGS,                    { "ViewSrc" } }
  }
};


/*	Object export submenu
*/
static wimp_MENU(2) object_export_menu = {
  { "ExportAs" }, 7,2,7,0, 200, 44, 0,
  {
    { wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, (wimp_menu *)1, DEFAULT_FLAGS, { "Sprite" } }
  }
};


/*	Object submenu
*/
static wimp_MENU(5) object_menu = {
  { "Object" }, 7,2,7,0, 300, 44, 0,
  {
    { wimp_MENU_GIVE_WARNING, (wimp_menu *)1,                   DEFAULT_FLAGS, { "ObjInfo" } },
    { wimp_MENU_GIVE_WARNING, (wimp_menu *)1,                   DEFAULT_FLAGS, { "ObjSave" } },
    { 0,                      (wimp_menu *)&object_export_menu, DEFAULT_FLAGS, { "Export" } },
    { wimp_MENU_GIVE_WARNING | wimp_MENU_SEPARATE, (wimp_menu *)1,                   DEFAULT_FLAGS, { "SaveURL" } },
    { wimp_MENU_LAST,         wimp_NO_SUB_MENU,                 DEFAULT_FLAGS, { "ObjReload" } }
  }
};


/*	Selection submenu
*/
static wimp_MENU(3) selection_menu = {
  { "Selection" }, 7,2,7,0, 300, 44, 0,
  {
    { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Copy" } },
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "SelectAll" } },
    { wimp_MENU_LAST,     wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Clear" } }
  }
};


/*	Navigate submenu
*/
static wimp_MENU(5) navigate_menu = {
  { "Navigate" }, 7,2,7,0, 300, 44, 0,
  {
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS,                    { "Home" } },
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS,                    { "Back" } },
    { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS,                    { "Forward" } },
    { wimp_MENU_LAST,     wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "Reload" } }
  }
};


/*	Image submenu
*/
static wimp_MENU(5) image_menu = {
  { "Images" }, 7,2,7,0, 300, 44, 0,
  {
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "ForeImg" } },
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "BackImg" } },
    { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS,                    { "AnimImg" } },
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS,                    { "DitherImg" } },
    { wimp_MENU_LAST,     wimp_NO_SUB_MENU, DEFAULT_FLAGS,                    { "FilterImg" } }
  }
};


/*	Toolbar submenu
*/
static wimp_MENU(4) toolbar_menu = {
  { "Toolbars" }, 7,2,7,0, 300, 44, 0,
  {
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ToolButtons" } },
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ToolAddress" } },
    { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ToolThrob" } },
    { wimp_MENU_LAST,     wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "ToolStatus" } }
  }
};


/*	View submenu
*/
static wimp_MENU(4) view_menu = {
  { "View" }, 7,2,7,0, 300, 44, 0,
  {
    { wimp_MENU_GIVE_WARNING,                      (wimp_menu *)1,             DEFAULT_FLAGS, { "ScaleView" } },
    { wimp_MENU_GIVE_WARNING,                      (wimp_menu *)&image_menu,   DEFAULT_FLAGS, { "Images" } },
    { wimp_MENU_SEPARATE | wimp_MENU_GIVE_WARNING, (wimp_menu *)&toolbar_menu, DEFAULT_FLAGS, { "Toolbars" } },
    { wimp_MENU_LAST,                              wimp_NO_SUB_MENU,           DEFAULT_FLAGS, { "OptDefault" } }
  }
};


/*	Hotlist submenu
*/
static wimp_MENU(2) hotlist_menu = {
  { "Hotlist" }, 7,2,7,0, 300, 44, 0,
  {
    { 0,              wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HotlistAdd" } },
    { wimp_MENU_LAST, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "HotlistShow" } }
  }
};


/*	Utilities submenu
*/
static wimp_MENU(4) utilities_menu = {
  { "Utilities" }, 7,2,7,0, 300, 44, 0,
  {
    { wimp_MENU_SEPARATE, (wimp_menu *)&hotlist_menu, DEFAULT_FLAGS, { "Hotlist" } },
    { 0,                  wimp_NO_SUB_MENU,           DEFAULT_FLAGS, { "FindText" } },
    { 0,                  wimp_NO_SUB_MENU,           DEFAULT_FLAGS, { "HistLocal" } },
    { wimp_MENU_LAST,     wimp_NO_SUB_MENU,           DEFAULT_FLAGS, { "HistGlobal" } }
  }
};


/*	Help submenu
*/
static wimp_MENU(4) help_menu = {
  { "Help" }, 7,2,7,0, 300, 44, 0,
  {
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS,                    { "HelpContent" } },
    { 0,                  wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "HelpGuide" } },
    { wimp_MENU_SEPARATE, wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "HelpInfo" } },
    { wimp_MENU_LAST,     wimp_NO_SUB_MENU, DEFAULT_FLAGS | wimp_ICON_SHADED, { "HelpInter" } }
  }
};


/*	Main browser menu
*/
static wimp_MENU(5) menu = {
  { "NetSurf" }, 7,2,7,0, 200, 44, 0,
  {
    { 0,              (wimp_menu *)&page_menu,      DEFAULT_FLAGS, { "Page" } },
//    { 0,              (wimp_menu *)&object_menu,    DEFAULT_FLAGS, { "Object" } },
//    { 0,              (wimp_menu *)&selection_menu, DEFAULT_FLAGS, { "Selection" } },
    { 0,              (wimp_menu *)&navigate_menu,  DEFAULT_FLAGS, { "Navigate" } },
    { 0,              (wimp_menu *)&view_menu,      DEFAULT_FLAGS, { "View" } },
//    { 0,              (wimp_menu *)&utilities_menu, DEFAULT_FLAGS, { "Utilities" } },
    { wimp_MENU_LAST, (wimp_menu *)&help_menu,      DEFAULT_FLAGS, { "Help" } }
  }
};
wimp_menu *browser_menu = (wimp_menu *) &menu;


static wimp_menu *browser_page_menu = (wimp_menu *)&page_menu;
static wimp_menu *browser_export_menu = (wimp_menu *)&export_menu;
static wimp_menu *browser_object_menu = (wimp_menu *)&object_menu;
static wimp_menu *browser_object_export_menu = (wimp_menu *)&object_export_menu;
static wimp_menu *browser_selection_menu = (wimp_menu *)&selection_menu;
static wimp_menu *browser_navigate_menu = (wimp_menu *)&navigate_menu;
static wimp_menu *browser_view_menu = (wimp_menu *)&view_menu;
static wimp_menu *browser_image_menu = (wimp_menu *)&image_menu;
static wimp_menu *browser_toolbar_menu = (wimp_menu *)&toolbar_menu;
static wimp_menu *browser_utilities_menu = (wimp_menu *)&utilities_menu;
static wimp_menu *browser_hotlist_menu = (wimp_menu *)&hotlist_menu;
static wimp_menu *browser_help_menu = (wimp_menu *)&help_menu;


/**
 * Create menu structures.
 */

void ro_gui_menus_init(void)
{
	translate_menu(iconbar_menu);
	translate_menu(browser_menu);
	translate_menu(browser_page_menu);
	translate_menu(browser_export_menu);
	translate_menu(browser_object_menu);
	translate_menu(browser_object_export_menu);
	translate_menu(browser_selection_menu);
	translate_menu(browser_navigate_menu);
	translate_menu(browser_view_menu);
	translate_menu(browser_image_menu);
	translate_menu(browser_toolbar_menu);
	translate_menu(browser_utilities_menu);
	translate_menu(browser_hotlist_menu);
	translate_menu(browser_help_menu);

	iconbar_menu->entries[0].sub_menu = (wimp_menu *) dialog_info;
	browser_page_menu->entries[0].sub_menu = (wimp_menu*) dialog_pageinfo;
//	browser_page_menu->entries[1].sub_menu = (wimp_menu *) dialog_saveas;
//	browser_page_menu->entries[2].sub_menu = (wimp_menu *) dialog_saveas;
//	browser_export_menu->entries[0].sub_menu = (wimp_menu *) dialog_saveas;
//	browser_export_menu->entries[1].sub_menu = (wimp_menu *) dialog_saveas;
//	browser_view_menu->entries[0].sub_menu = (wimp_menu *) dialog_zoom;
}


/**
 * Replace text in a menu with message values.
 */

void translate_menu(wimp_menu *menu)
{
	unsigned int i = 0;
	char *indirected_text;

	/*	We can't just blindly set something as indirected as if we use
		the fallback messages text (ie the pointer we gave), we overwrite
		this data when setting the pointer to the indirected text we
		already had.
	*/
	indirected_text = (char *)messages_get(menu->title_data.text);
	if (indirected_text != menu->title_data.text) {
		menu->title_data.indirected_text.text = indirected_text;
		menu->entries[0].menu_flags |= wimp_MENU_TITLE_INDIRECTED;

        }

	/* items */
	do {
	  	indirected_text = (char *)messages_get(menu->entries[i].data.text);
	  	if (indirected_text != menu->entries[i].data.text) {
			menu->entries[i].icon_flags |= wimp_ICON_INDIRECTED;
			menu->entries[i].data.indirected_text.text = indirected_text;
			menu->entries[i].data.indirected_text.validation = 0;
			menu->entries[i].data.indirected_text.size = strlen(indirected_text) + 1;
		}
		i++;
	} while ((menu->entries[i - 1].menu_flags & wimp_MENU_LAST) == 0);
}


/**
 * Display a menu.
 */

void ro_gui_create_menu(wimp_menu *menu, int x, int y, gui_window *g)
{
	current_menu = menu;
	current_menu_x = x;
	current_menu_y = y;
	current_gui = g;
	wimp_create_menu(menu, x, y);
}


/**
 * Display a pop-up menu next to the specified icon.
 */

void ro_gui_popup_menu(wimp_menu *menu, wimp_w w, wimp_i i)
{
	wimp_window_state state;
	wimp_icon_state icon_state;
	state.w = w;
	icon_state.w = w;
	icon_state.i = i;
	wimp_get_window_state(&state);
	wimp_get_icon_state(&icon_state);
	ro_gui_create_menu(menu, state.visible.x0 + icon_state.icon.extent.x1,
			state.visible.y1 + icon_state.icon.extent.y1, 0);
}


/**
 * Handle menu selection.
 */

void ro_gui_menu_selection(wimp_selection *selection)
{
	struct browser_action msg;
	wimp_pointer pointer;

	wimp_get_pointer_info(&pointer);

	if (current_menu == combo_menu && selection->items[0] >= 0) {
		msg.type = act_GADGET_SELECT;
		msg.data.gadget_select.g = current_gadget;
		msg.data.gadget_select.item = selection->items[0];
		browser_window_action(current_gui->data.browser.bw, &msg);

	} else if (current_menu == iconbar_menu) {
		switch (selection->items[0]) {
			case 0: /* Info */
				ro_gui_create_menu((wimp_menu *) dialog_info,
						pointer.pos.x, pointer.pos.y, 0);
				break;
			case 1: /* Help */
			        ro_gui_open_help_page();
			        break;
			case 2: /* Choices */
				ro_gui_dialog_open(dialog_config);
				break;
			case 3: /* Quit */
				netsurf_quit = true;
				break;
		}

	} else if (current_menu == browser_menu) {
		struct content *c = current_gui->data.browser.bw->current_content;
		switch (selection->items[0]) {
			case MENU_PAGE:
				switch (selection->items[1]) {
					case 0: /* Info */
						break;
					case 1: /* Save */
						break;
					case 2: /* Full save */
						break;
					case 3: /* Export */
						break;
					case 4: /* Save location */
						break;
					case 5: /* Print */
						break;
					case 6: /* Page source */
						ro_gui_view_source(c);
						break;
				}
				break;
			case MENU_SELECTION:
				switch (selection->items[1]) {
					case 0: /* Copy to clipboard */
						ro_gui_copy_selection(current_gui);
						break;
					case 1: /* Select all */
						break;
					case 2: /* Clear */
						msg.type = act_CLEAR_SELECTION;
						browser_window_action(current_gui->data.browser.bw, &msg);
						break;
				}
				break;
			case MENU_NAVIGATE:
				switch (selection->items[1]) {
					case 0: /* Home */
						break;
					case 1: /* Back */
						history_back(current_gui->data.browser.bw,
								current_gui->data.browser.bw->history);
						break;
					case 2: /* Forward */
						history_forward(current_gui->data.browser.bw,
								current_gui->data.browser.bw->history);
						break;
					case 3: /* Reload */
						break;
				}
				break;
			case MENU_VIEW:
				switch (selection->items[1]) {
					case 0: /* Scale view */
						break;
					case 1: /* Images -> */
						if (selection->items[2] == 2) current_gui->option_animate_images =
								!current_gui->option_animate_images;
						if (selection->items[2] == 3) current_gui->option_dither_sprites =
								!current_gui->option_dither_sprites;
						if (selection->items[2] == 4) current_gui->option_filter_sprites =
								!current_gui->option_filter_sprites;
						if (selection->items[2] >= 2) {
							ro_gui_menu_prepare_images();
							gui_window_redraw_window(current_gui);
//							content_broadcast(c, CONTENT_MSG_REDRAW, 0);
						}
						break;
					case 2: /* Toolbars -> */
						switch (selection->items[2]) {
							case 0:
								current_gui->data.browser.toolbar->standard_buttons =
										!current_gui->data.browser.toolbar->standard_buttons;
								break;
							case 1:
								current_gui->data.browser.toolbar->url_bar =
										!current_gui->data.browser.toolbar->url_bar;
								break;
							case 2:
								current_gui->data.browser.toolbar->throbber =
										!current_gui->data.browser.toolbar->throbber;
								break;
							case 3:
								current_gui->data.browser.toolbar->status_window =
										!current_gui->data.browser.toolbar->status_window;
						}
						if (ro_theme_update_toolbar(current_gui) || true) {
							wimp_window_state state;
							state.w = current_gui->window;
							wimp_get_window_state(&state);
							current_gui->data.browser.old_height = 0xffffffff;
							ro_gui_window_open(current_gui, (wimp_open *)&state);
						}
						ro_gui_menu_prepare_toolbars();
						break;
					case 3: /* Make default */
						gui_window_default_options(current_gui->data.browser.bw);
						break;
				}
				break;
			case MENU_HELP:
				switch (selection->items[1]) {
				  	case -1: /* No sub-item */
					case 0: /* Contents */
					        ro_gui_open_help_page();
					        break;
					case 1: /* User guide -> */
						break;
					case 2: /* User information */
						break;
					case 3: /* Interactive help */
						break;
				}
				break;
		}

	} else if (current_menu == theme_menu && theme_menu != NULL) {
		ro_gui_theme_menu_selection(theme_menu->entries[selection->items[0]].data.indirected_text.text);
	}

	if (pointer.buttons == wimp_CLICK_ADJUST) {
		if (current_menu == combo_menu)
			gui_gadget_combo(current_gui->data.browser.bw, current_gadget, (unsigned int)current_menu_x, (unsigned int)current_menu_y);
		else
			ro_gui_create_menu(current_menu, current_menu_x, current_menu_y, current_gui);
	}
}


/**
 * Handle Message_MenuWarning by opening the save dialog.
 */

void ro_gui_menu_warning(wimp_message_menu_warning *warning)
{
	struct content *c = current_gui->data.browser.bw->current_content;
	os_error *error = NULL; // No warnings

	switch (warning->selection.items[0]) {
		case MENU_PAGE: /* Page -> */
			switch (warning->selection.items[1]) {
				case 3: /* Export as -> */
					switch (warning->selection.items[2]) {
						case 0: /* Draw */
							gui_current_save_type = GUI_SAVE_DRAW;
							break;

				                case 1: /* Text */
							gui_current_save_type = GUI_SAVE_TEXT;
							break;
					}
					break;

				case 2: /* Save complete */
					gui_current_save_type = GUI_SAVE_COMPLETE;
					break;


       	         		case 0: /* Page info */
       	                 		ro_gui_menu_pageinfo(warning);
	                        	return;

				case 1:
				default: /* Save */
					gui_current_save_type = GUI_SAVE_SOURCE;
					break;
			}
			ro_gui_menu_prepare_save(c);
			error = xwimp_create_sub_menu((wimp_menu *) dialog_saveas,
					warning->pos.x, warning->pos.y);
			break;
		case MENU_VIEW: /* View -> */
			switch (warning->selection.items[1]) {
				case 0: /* Scale view -> */
					ro_gui_menu_prepare_scale();
					error = xwimp_create_sub_menu((wimp_menu *) dialog_zoom,
							warning->pos.x, warning->pos.y);
					break;
				case 1: /* Images -> */
					ro_gui_menu_prepare_images();
					error = xwimp_create_sub_menu(browser_image_menu,
							warning->pos.x, warning->pos.y);
					break;
				case 2: /* Toolbars -> */
					ro_gui_menu_prepare_toolbars();
					error = xwimp_create_sub_menu(browser_toolbar_menu,
							warning->pos.x, warning->pos.y);
					break;
			}
			break;
	}


	if (error) {
		LOG(("0x%x: %s\n", error->errnum, error->errmess));
		warn_user(error->errmess);
	}
}


/**
 * Prepares the save box to reflect gui_current_save_type and a content.
 *
 * \param  c  content to save
 */

void ro_gui_menu_prepare_save(struct content *c)
{
	char icon_buf[20] = "file_xxx";
	const char *icon = icon_buf;
	const char *name = "";
	const char *nice;

	switch (gui_current_save_type) {
		case GUI_SAVE_SOURCE:
			if (c)
				sprintf(icon_buf, "file_%x",
						ro_content_filetype(c));
			name = messages_get("SaveSource");
			break;

		case GUI_SAVE_DRAW:
			icon = "file_aff";
			name = messages_get("SaveDraw");
			break;

                case GUI_SAVE_TEXT:
			icon = "file_fff";
			name = messages_get("SaveText");
			break;

		case GUI_SAVE_COMPLETE:
			icon = "file_faf";
			name = messages_get("SaveComplete");
			break;
        }

	if (c)
		if ((nice = url_nice(c->url)))
			name = nice;

	ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_ICON, icon);
	ro_gui_set_icon_string(dialog_saveas, ICON_SAVE_PATH, name);
}


/**
 * Update image menu status
 */
static void ro_gui_menu_prepare_images(void) {
	if (current_menu != browser_menu) return;

	/*	We don't currently have any local options so we update from the global ones
	*/
	browser_image_menu->entries[2].menu_flags &= ~wimp_MENU_TICKED;
	if (current_gui->option_animate_images) browser_image_menu->entries[2].menu_flags |= wimp_MENU_TICKED;
	browser_image_menu->entries[3].menu_flags &= ~wimp_MENU_TICKED;
	if (current_gui->option_dither_sprites) browser_image_menu->entries[3].menu_flags |= wimp_MENU_TICKED;
	browser_image_menu->entries[4].menu_flags &= ~wimp_MENU_TICKED;
	if (current_gui->option_filter_sprites) browser_image_menu->entries[4].menu_flags |= wimp_MENU_TICKED;
}


/**
 * Update toolbar menu status
 */
static void ro_gui_menu_prepare_toolbars(void) {
  	int index;
  	struct toolbar *toolbar;
	if (current_menu != browser_menu) return;

	/*	Check we have a toolbar
	*/
	toolbar = current_gui->data.browser.toolbar;

	/*	Set our ticks, or shade everything if there's no toolbar
	*/
	if (toolbar) {
		for (index = 0; index < 4; index++) {
			browser_toolbar_menu->entries[index].icon_flags &= ~wimp_ICON_SHADED;
			browser_toolbar_menu->entries[index].menu_flags &= ~wimp_MENU_TICKED;
		}
		if (toolbar->standard_buttons) browser_toolbar_menu->entries[0].menu_flags |= wimp_MENU_TICKED;
		if (toolbar->url_bar) browser_toolbar_menu->entries[1].menu_flags |= wimp_MENU_TICKED;
		if (toolbar->throbber) browser_toolbar_menu->entries[2].menu_flags |= wimp_MENU_TICKED;
		if (toolbar->status_window) browser_toolbar_menu->entries[3].menu_flags |= wimp_MENU_TICKED;
	} else {
		for (index = 0; index < 4; index++) {
			browser_toolbar_menu->entries[index].icon_flags |= wimp_ICON_SHADED;
			browser_toolbar_menu->entries[index].menu_flags &= ~wimp_MENU_TICKED;
		}
	}
}


/**
 * Update scale to current document value
 */
void ro_gui_menu_prepare_scale(void) {
  	char scale_buffer[8];
	if (current_menu != browser_menu) return;
	sprintf(scale_buffer, "%.0f", current_gui->scale * 100);
	ro_gui_set_icon_string(dialog_zoom, ICON_ZOOM_VALUE, scale_buffer);
}

void ro_gui_menu_pageinfo(wimp_message_menu_warning *warning)
{
        struct content *c = current_gui->data.browser.bw->current_content;
        os_error *error;
        char icon_buf[20] = "file_xxx";
        const char *icon = icon_buf;
        const char *title = "-";
        const char *url = "-";
        const char *enc = "-";
        const char *mime = "-";

        if (c->title != 0)     title = c->title;
        if (c->url != 0)       url = c->url;
        if (c->mime_type != 0) mime = c->mime_type;

        sprintf(icon_buf, "file_%x", ro_content_filetype(c));

        if (c->type == CONTENT_HTML) {
                enc = xmlGetCharEncodingName(c->data.html.encoding);
        }

        ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_ICON, icon);
	ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_TITLE, title);
	ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_URL, url);
	ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_ENC, enc);
	ro_gui_set_icon_string(dialog_pageinfo, ICON_PAGEINFO_TYPE, mime);

        error = xwimp_create_sub_menu((wimp_menu *) dialog_pageinfo,
			warning->pos.x, warning->pos.y);
	if (error) {
		LOG(("0x%x: %s\n", error->errnum, error->errmess));
		warn_user(error->errmess);
	}
}