From: Hugo Villeneuve Date: Thu, 10 Oct 2013 00:54:05 +0000 (-0400) Subject: Replace GTK deprecated functions X-Git-Tag: v2.0.0~140 X-Git-Url: http://gitweb.hugovil.com/?a=commitdiff_plain;h=6c53f8ff0267ae104d1b60efb3b8285df338e473;p=emu8051.git Replace GTK deprecated functions gtk_signal_connect_object -> g_signal_connect gtk_menu_bar_append -> gtk_menu_shell_append Also simplified ShowMessage function. --- diff --git a/src/emugtk.c b/src/emugtk.c index 328fd42..7cd5a2a 100644 --- a/src/emugtk.c +++ b/src/emugtk.c @@ -49,7 +49,8 @@ static int running; static int running_function_tag; -static GtkWidget *mainwin; + +GtkWidget *mainwin; extern struct app_config_t *cfg; diff --git a/src/filemenu.c b/src/filemenu.c index ce13368..7e9e3dd 100644 --- a/src/filemenu.c +++ b/src/filemenu.c @@ -133,20 +133,18 @@ FileAddMenu(GtkWidget *menu_bar) item = gtk_menu_item_new_with_label(FILENAME_DESCRIPTION); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object(GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(FileOpenEvent), NULL); + g_signal_connect(item, "activate", G_CALLBACK(FileOpenEvent), NULL); AddMenuSeparator(menu); item = gtk_menu_item_new_with_label("Exit"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* We can attach the Quit menu item to our exit function */ - gtk_signal_connect_object(GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(FileQuitEvent), - (gpointer) "file.quit"); + g_signal_connect(item, "activate", G_CALLBACK(FileQuitEvent), + (gpointer) "file.quit"); /* Adding submenu title. */ item = gtk_menu_item_new_with_label("File"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); - gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), item); + gtk_menu_shell_append((GtkMenuShell *) menu_bar, item); } diff --git a/src/helpmenu.c b/src/helpmenu.c index bb9f9d5..3bde4ce 100644 --- a/src/helpmenu.c +++ b/src/helpmenu.c @@ -63,9 +63,7 @@ HelpAddMenu(GtkWidget *menu_bar) item = gtk_menu_item_new_with_label("Command Line Options"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object(GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(HelpCommandsEvent), - NULL); + g_signal_connect(item, "activate", G_CALLBACK(HelpCommandsEvent), NULL); AddMenuSeparator(menu); @@ -73,12 +71,10 @@ HelpAddMenu(GtkWidget *menu_bar) item = gtk_menu_item_new_with_label("About " PACKAGE); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object(GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(HelpAboutEvent), - NULL); + g_signal_connect(item, "activate", G_CALLBACK(HelpAboutEvent), NULL); /* Adding submenu title. */ item = gtk_menu_item_new_with_label("Help"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); - gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), item); + gtk_menu_shell_append((GtkMenuShell *) menu_bar, item); } diff --git a/src/messagebox.c b/src/messagebox.c index 15019a7..c4d3723 100644 --- a/src/messagebox.c +++ b/src/messagebox.c @@ -32,72 +32,20 @@ #define BUTTON_TEXT_BORDER 3 -/* This function is used to adjust the border around the text in a button. */ -static GtkWidget * -AddTextButton(gchar *button_text) -{ - GtkWidget *button; - GtkWidget *label; - GtkWidget *label_window; - - /* - * The GtkLabel widget is one of a few GTK+ widgets that don't create - * their own window to render themselves into. Instead, they draw - * themselves directly onto their parents window. This means that in - * order to set a property for a GtkLabel widget, you need to change the - * property of its parent, i.e. the object that you pack it into. - * Another solution (short term workaround) is to put the label widget - * inside another widget that does get its own window, like the - * 'ViewPort' or 'EventBox' widget. - */ - - /* - * Using workaround described above to set the border width of 'label' - * widget. - */ - label_window = gtk_event_box_new(); - - /* Creating our label. */ - label = gtk_label_new(button_text); - - /* Adding label widget to label_window widget. */ - gtk_container_add(GTK_CONTAINER(label_window), label); - - /* - * Changing border width of the label widget by way of label_window - * widget. - */ - gtk_container_set_border_width(GTK_CONTAINER(label_window), - BUTTON_TEXT_BORDER); - - /* Create the button. */ - button = gtk_button_new(); - - /* Adding label to button. */ - gtk_container_add(GTK_CONTAINER(button), label_window); - - return button; -} +extern GtkWidget *mainwin; void ShowMessage(gchar *title, gchar *message, int justification, int font_style) { GtkWidget *dialog; GtkWidget *label; - GtkWidget *okay_button; GtkWidget *label_window; - GtkWidget *center; - - /* Set-up a dialog window, centered on the screen. */ - dialog = gtk_dialog_new(); - gtk_window_set_title(GTK_WINDOW(dialog), title); - gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER); - /* - * To have the main window of our application being unusable while using - * the dialog. - */ - gtk_window_set_modal(GTK_WINDOW(dialog), TRUE); + /* Keep the dialog on top of the main window, and centered. */ + dialog = gtk_dialog_new_with_buttons( + title, GTK_WINDOW(mainwin), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, + GTK_RESPONSE_NONE, NULL); /* * The GtkLabel widget is one of a few GTK+ widgets that don't create @@ -137,22 +85,9 @@ ShowMessage(gchar *title, gchar *message, int justification, int font_style) gtk_container_set_border_width(GTK_CONTAINER(label_window), MESSAGE_DIALOG_BORDER); - /* xalign, yalign, xscale, yscale */ - center = gtk_alignment_new(0.5, 0.5, 0.0, 0.0); - - /* Create the OK button. */ - okay_button = AddTextButton("OK"); - - /* Ensure that the dialog box is destroyed when the user clicks ok. */ - gtk_signal_connect_object(GTK_OBJECT(okay_button), "clicked", - GTK_SIGNAL_FUNC(gtk_widget_destroy), - (gpointer) dialog); - - /* Add the OK button to the alignment widget. */ - gtk_container_add(GTK_CONTAINER(center), okay_button); - /* Add the alignment widget to the dialog window. */ - gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->action_area), - center); + /* Ensure that the dialog box is destroyed when the user responds */ + g_signal_connect_swapped(dialog, "response", + G_CALLBACK(gtk_widget_destroy), dialog); /* Add the label_window to the dialog window. */ gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), diff --git a/src/viewmenu.c b/src/viewmenu.c index 4ac24c2..b167274 100644 --- a/src/viewmenu.c +++ b/src/viewmenu.c @@ -56,9 +56,8 @@ ViewAddMenu(GtkWidget *menu_bar) item = gtk_menu_item_new_with_label("External Memory Dump"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object(GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(ViewMenuExternalDump), - NULL); + g_signal_connect(item, "activate", G_CALLBACK(ViewMenuExternalDump), + NULL); AddMenuSeparator(menu); @@ -66,12 +65,11 @@ ViewAddMenu(GtkWidget *menu_bar) item = gtk_menu_item_new_with_label("Internal Memory Dump"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), item); /* Attach the callback functions to the activate signal. */ - gtk_signal_connect_object(GTK_OBJECT(item), "activate", - GTK_SIGNAL_FUNC(ViewMenuInternalDump), - NULL); + g_signal_connect(item, "activate", G_CALLBACK(ViewMenuInternalDump), + NULL); /* Adding submenu title. */ item = gtk_menu_item_new_with_label("View"); gtk_menu_item_set_submenu(GTK_MENU_ITEM(item), menu); - gtk_menu_bar_append(GTK_MENU_BAR(menu_bar), item); + gtk_menu_shell_append((GtkMenuShell *) menu_bar, item); }