1 /*
2  * Copyright 2005 Richard Wilson <info@tinct.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 <stdbool.h>
20 #include <stdlib.h>
21 
22 #include "utils/messages.h"
23 #include "utils/nsoption.h"
24 
25 #include "riscos/gui.h"
26 #include "riscos/menus.h"
27 #include "riscos/url_suggest.h"
28 #include "riscos/wimp.h"
29 #include "riscos/wimp_event.h"
30 #include "riscos/configure.h"
31 #include "riscos/configure/configure.h"
32 #include "riscos/dialog.h"
33 
34 #define HOME_URL_FIELD 3
35 #define HOME_URL_GRIGHT 4
36 #define HOME_OPEN_STARTUP 5
37 #define HOME_DEFAULT_BUTTON 6
38 #define HOME_CANCEL_BUTTON 7
39 #define HOME_OK_BUTTON 8
40 
41 static void ro_gui_options_home_default(wimp_pointer *pointer);
42 static bool ro_gui_options_home_ok(wimp_w w);
43 static bool ro_gui_options_home_menu_prepare(wimp_w w, wimp_i i,
44 		wimp_menu *menu, wimp_pointer *pointer);
45 
ro_gui_options_home_initialise(wimp_w w)46 bool ro_gui_options_home_initialise(wimp_w w)
47 {
48 	/* set the current values */
49 	ro_gui_set_icon_string(w, HOME_URL_FIELD,
50                                nsoption_charp(homepage_url) ?
51                                nsoption_charp(homepage_url) : "", true);
52 
53 	ro_gui_set_icon_selected_state(w, HOME_OPEN_STARTUP,
54                                        nsoption_bool(open_browser_at_startup));
55 
56 	ro_gui_set_icon_shaded_state(w,
57 			HOME_URL_GRIGHT, !ro_gui_url_suggest_prepare_menu());
58 
59 	/* initialise all functions for a newly created window */
60 	ro_gui_wimp_event_register_menu_gright(w, HOME_URL_FIELD,
61 			HOME_URL_GRIGHT, ro_gui_url_suggest_menu);
62 	ro_gui_wimp_event_register_checkbox(w, HOME_OPEN_STARTUP);
63 	ro_gui_wimp_event_register_button(w, HOME_DEFAULT_BUTTON,
64 			ro_gui_options_home_default);
65 	ro_gui_wimp_event_register_cancel(w, HOME_CANCEL_BUTTON);
66 	ro_gui_wimp_event_register_ok(w, HOME_OK_BUTTON,
67 			ro_gui_options_home_ok);
68 	ro_gui_wimp_event_register_menu_prepare(w,
69 			ro_gui_options_home_menu_prepare);
70 	ro_gui_wimp_event_set_help_prefix(w, "HelpHomeConfig");
71 	ro_gui_wimp_event_memorise(w);
72 	return true;
73 
74 }
75 
ro_gui_options_home_default(wimp_pointer * pointer)76 void ro_gui_options_home_default(wimp_pointer *pointer)
77 {
78 	/* set the default values */
79 	ro_gui_set_icon_string(pointer->w, HOME_URL_FIELD, "", true);
80 	ro_gui_set_icon_selected_state(pointer->w, HOME_OPEN_STARTUP, false);
81 }
82 
ro_gui_options_home_ok(wimp_w w)83 bool ro_gui_options_home_ok(wimp_w w)
84 {
85 	nsoption_set_charp(homepage_url,
86 		       strdup(ro_gui_get_icon_string(w, HOME_URL_FIELD)));
87 
88 	nsoption_set_bool(open_browser_at_startup,
89 			  ro_gui_get_icon_selected_state(w, HOME_OPEN_STARTUP));
90 
91 	ro_gui_save_options();
92   	return true;
93 }
94 
95 
96 /**
97  * Callback to prepare menus in the Configure Home dialog.  At present, this
98  * only has to handle the URL Suggestion pop-up.
99  *
100  * \param w		The window handle owning the menu.
101  * \param i		The icon handle owning the menu.
102  * \param *menu		The menu to be prepared.
103  * \param *pointer	The associated mouse click event block, or NULL
104  *			on an Adjust-click re-opening.
105  * \return		true if the event was handled; false if not.
106  */
107 
ro_gui_options_home_menu_prepare(wimp_w w,wimp_i i,wimp_menu * menu,wimp_pointer * pointer)108 bool ro_gui_options_home_menu_prepare(wimp_w w, wimp_i i, wimp_menu *menu,
109 		wimp_pointer *pointer)
110 {
111 	if (menu != ro_gui_url_suggest_menu || i != HOME_URL_GRIGHT)
112 		return false;
113 
114 	if (pointer != NULL)
115 		ro_gui_url_suggest_prepare_menu();
116 
117 	return true;
118 }
119