Move create_form_select_menu to window gui table.

This commit is contained in:
Michael Drake 2014-10-24 20:45:21 +01:00
parent 69e82a8966
commit 94f32b8369
13 changed files with 75 additions and 74 deletions

View File

@ -5082,6 +5082,7 @@ static struct gui_window_table amiga_window_table = {
.remove_caret = gui_window_remove_caret,
.drag_start = gui_window_drag_start,
.new_content = gui_window_new_content,
.create_form_select_menu = gui_create_form_select_menu,
.file_gadget_open = gui_file_gadget_open,
.drag_save_object = gui_drag_save_object,
.drag_save_selection =gui_drag_save_selection,
@ -5112,7 +5113,6 @@ static struct gui_browser_table amiga_browser_table = {
.quit = gui_quit,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.login = gui_401login_open,
};

View File

@ -984,7 +984,6 @@ static struct gui_browser_table beos_browser_table = {
beos_schedule,
gui_quit,
gui_launch_url,
NULL, //create_form_select_menu
NULL, //cert_verify
gui_401login_open
};

View File

@ -1362,6 +1362,7 @@ static struct gui_window_table window_table = {
NULL, //scroll_visible
NULL, //scroll_start
gui_window_new_content,
NULL, //create_form_select_menu
NULL, //file_gadget_open
NULL, //drag_save_object
NULL, //drag_save_selection

View File

@ -292,6 +292,7 @@ static struct gui_window_table window_table = {
.new_content = gui_window_new_content,
.start_throbber = gui_window_start_throbber,
.stop_throbber = gui_window_stop_throbber,
.create_form_select_menu = gui_create_form_select_menu,
};
struct gui_window_table *cocoa_window_table = &window_table;
@ -301,7 +302,6 @@ static struct gui_browser_table browser_table = {
.schedule = cocoa_schedule,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
};

View File

@ -1604,7 +1604,7 @@ static nserror browser_window_callback(hlcache_handle *c,
if (event->data.select_menu.gadget->type == GADGET_SELECT) {
struct browser_window *root =
browser_window_get_root(bw);
guit->browser->create_form_select_menu(root->window,
guit->window->create_form_select_menu(root->window,
event->data.select_menu.gadget);
}

View File

@ -108,6 +108,11 @@ static void gui_default_window_remove_caret(struct gui_window *g)
{
}
static void gui_default_window_create_form_select_menu(struct gui_window *g,
struct form_control *control)
{
}
static void gui_default_window_file_gadget_open(struct gui_window *g,
hlcache_handle *hl,
struct form_control *gadget)
@ -211,6 +216,10 @@ static nserror verify_window_register(struct gui_window_table *gwt)
if (gwt->scroll_start == NULL) {
gwt->scroll_start = gui_default_window_scroll_start;
}
if (gwt->create_form_select_menu == NULL) {
gwt->create_form_select_menu =
gui_default_window_create_form_select_menu;
}
if (gwt->file_gadget_open == NULL) {
gwt->file_gadget_open = gui_default_window_file_gadget_open;
}
@ -541,11 +550,6 @@ static nserror gui_default_launch_url(struct nsurl *url)
return NSERROR_NO_FETCH_HANDLER;
}
static void gui_default_create_form_select_menu(struct gui_window *g,
struct form_control *control)
{
}
static void gui_default_cert_verify(nsurl *url,
const struct ssl_cert_info *certs,
@ -589,9 +593,6 @@ static nserror verify_browser_register(struct gui_browser_table *gbt)
if (gbt->launch_url == NULL) {
gbt->launch_url = gui_default_launch_url;
}
if (gbt->create_form_select_menu == NULL) {
gbt->create_form_select_menu = gui_default_create_form_select_menu;
}
if (gbt->cert_verify == NULL) {
gbt->cert_verify = gui_default_cert_verify;
}

View File

@ -69,11 +69,6 @@ struct gui_browser_table {
*/
nserror (*launch_url)(struct nsurl *url);
/**
* create a form select menu
*/
void (*create_form_select_menu)(struct gui_window *gw, struct form_control *control);
/**
* verify certificate
*/

View File

@ -266,6 +266,11 @@ struct gui_window_table {
*/
void (*new_content)(struct gui_window *g);
/**
* create a form select menu
*/
void (*create_form_select_menu)(struct gui_window *gw, struct form_control *control);
/**
* Called when file chooser gadget is activated
*/

View File

@ -52,7 +52,6 @@
#include "content/hlcache.h"
#include "content/urldb.h"
#include "content/backing_store.h"
#include "render/form.h"
#include "desktop/browser.h"
#include "desktop/save_complete.h"
#include "desktop/save_pdf/pdf_plotters.h"
@ -94,15 +93,10 @@ struct glade_file_location_s *glade_file_location;
static GtkWindow *nsgtk_warning_window;
GtkWidget *widWarning;
static GtkWidget *select_menu;
static struct form_control *select_menu_control;
static void nsgtk_ssl_accept(GtkButton *w, gpointer data);
static void nsgtk_ssl_reject(GtkWidget *w, gpointer data);
static gboolean nsgtk_ssl_delete_event(GtkWidget *w, GdkEvent *event,
gpointer data);
static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem,
gpointer user_data);
#ifdef WITH_PDF_EXPORT
static void nsgtk_PDF_set_pass(GtkButton *w, gpointer data);
static void nsgtk_PDF_no_pass(GtkButton *w, gpointer data);
@ -557,53 +551,6 @@ static void gui_quit(void)
gtk_fetch_filetype_fin();
}
static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem,
gpointer user_data)
{
form_select_process_selection(select_menu_control,
(intptr_t)user_data);
}
static void gui_create_form_select_menu(struct gui_window *g,
struct form_control *control)
{
intptr_t i;
struct form_option *option;
GtkWidget *menu_item;
/* control->data.select.multiple is true if multiple selections
* are allowable. We ignore this, as the core handles it for us.
* Yay. \o/
*/
if (select_menu != NULL)
gtk_widget_destroy(select_menu);
select_menu = gtk_menu_new();
select_menu_control = control;
for (i = 0, option = control->data.select.items; option;
i++, option = option->next) {
menu_item = gtk_check_menu_item_new_with_label(option->text);
if (option->selected)
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(menu_item), TRUE);
g_signal_connect(menu_item, "toggled",
G_CALLBACK(nsgtk_select_menu_clicked), (gpointer)i);
gtk_menu_shell_append(GTK_MENU_SHELL(select_menu), menu_item);
}
gtk_widget_show_all(select_menu);
gtk_menu_popup(GTK_MENU(select_menu), NULL, NULL, NULL,
NULL /* data */, 0, gtk_get_current_event_time());
}
static nserror gui_launch_url(struct nsurl *url)
{
gboolean ok;
@ -1240,7 +1187,6 @@ static struct gui_browser_table nsgtk_browser_table = {
.quit = gui_quit,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.login = gui_401login_open,
};

View File

@ -38,6 +38,7 @@
#include "desktop/searchweb.h"
#include "desktop/textinput.h"
#include "desktop/gui_window.h"
#include "render/form.h"
#include "gtk/compat.h"
#include "gtk/gui.h"
@ -54,6 +55,12 @@
extern const GdkPixdata menu_cursor_pixdata;
static GtkWidget *select_menu;
static struct form_control *select_menu_control;
static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem,
gpointer user_data);
struct gui_window {
/** The gtk scaffold object containing menu, buttons, url bar, [tabs],
* drawing area, etc that may contain one or more gui_windows.
@ -162,6 +169,13 @@ float nsgtk_get_scale_for_gui(struct gui_window *g)
return browser_window_get_scale(g->bw);
}
static void nsgtk_select_menu_clicked(GtkCheckMenuItem *checkmenuitem,
gpointer user_data)
{
form_select_process_selection(select_menu_control,
(intptr_t)user_data);
}
#if GTK_CHECK_VERSION(3,0,0)
static gboolean
@ -1199,6 +1213,46 @@ static void gui_window_start_selection(struct gui_window *g)
gtk_widget_grab_focus(GTK_WIDGET(g->layout));
}
static void gui_window_create_form_select_menu(struct gui_window *g,
struct form_control *control)
{
intptr_t i;
struct form_option *option;
GtkWidget *menu_item;
/* control->data.select.multiple is true if multiple selections
* are allowable. We ignore this, as the core handles it for us.
* Yay. \o/
*/
if (select_menu != NULL)
gtk_widget_destroy(select_menu);
select_menu = gtk_menu_new();
select_menu_control = control;
for (i = 0, option = control->data.select.items; option;
i++, option = option->next) {
menu_item = gtk_check_menu_item_new_with_label(option->text);
if (option->selected)
gtk_check_menu_item_set_active(
GTK_CHECK_MENU_ITEM(menu_item), TRUE);
g_signal_connect(menu_item, "toggled",
G_CALLBACK(nsgtk_select_menu_clicked), (gpointer)i);
gtk_menu_shell_append(GTK_MENU_SHELL(select_menu), menu_item);
}
gtk_widget_show_all(select_menu);
gtk_menu_popup(GTK_MENU(select_menu), NULL, NULL, NULL,
NULL /* data */, 0, gtk_get_current_event_time());
}
static void
gui_window_file_gadget_open(struct gui_window *g,
hlcache_handle *hl,
@ -1247,6 +1301,7 @@ static struct gui_window_table window_table = {
.set_pointer = gui_window_set_pointer,
.place_caret = gui_window_place_caret,
.remove_caret = gui_window_remove_caret,
.create_form_select_menu = gui_window_create_form_select_menu,
.file_gadget_open = gui_window_file_gadget_open,
.start_selection = gui_window_start_selection,

View File

@ -2408,7 +2408,6 @@ static struct gui_browser_table riscos_browser_table = {
.quit = gui_quit,
.launch_url = gui_launch_url,
.create_form_select_menu = gui_create_form_select_menu,
.cert_verify = gui_cert_verify,
.login = gui_401login_open,
};

View File

@ -159,7 +159,6 @@ bool ro_gui_shift_pressed(void);
bool ro_gui_ctrl_pressed(void);
bool ro_gui_alt_pressed(void);
void gui_window_set_pointer(struct gui_window *g, enum gui_pointer_shape shape);
void gui_create_form_select_menu(struct gui_window *g, struct form_control *control);
/* in history.c */
void ro_gui_history_init(void);

View File

@ -1358,7 +1358,7 @@ void gui_window_set_extent(struct gui_window *g, int width, int height)
* \param control form control of type GADGET_SELECT
*/
void gui_create_form_select_menu(struct gui_window *g,
static void gui_window_create_form_select_menu(struct gui_window *g,
struct form_control *control)
{
os_error *error;
@ -5044,6 +5044,7 @@ static struct gui_window_table window_table = {
.new_content = gui_window_new_content,
.start_throbber = gui_window_start_throbber,
.stop_throbber = gui_window_stop_throbber,
.create_form_select_menu = gui_window_create_form_select_menu,
/* from save */
.drag_save_object = gui_drag_save_object,