--- embedaddon/mtr/ui/gtk.c 2019/10/21 14:25:31 1.1 +++ embedaddon/mtr/ui/gtk.c 2021/03/17 00:07:30 1.1.1.2 @@ -12,9 +12,9 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include "config.h" @@ -198,7 +198,7 @@ static gint About_clicked( gtk_show_about_dialog(GTK_WINDOW(main_window) , "version", PACKAGE_VERSION, "copyright", "Copyright \xc2\xa9 1997,1998 Matt Kimball", - "website", "http://www.bitwizard.nl/mtr/", + "website", "https://www.bitwizard.nl/mtr/", "authors", authors, "comments", "The 'traceroute' and 'ping' programs in a single network diagnostic tool.", "license", @@ -272,46 +272,45 @@ static void Toolbar_fill( GtkWidget *Label; GtkAdjustment *Adjustment; - Button = gtk_button_new_from_stock(GTK_STOCK_QUIT); + Button = gtk_button_new_with_label("Quit"); gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0); - g_signal_connect(GTK_OBJECT(Button), "clicked", - GTK_SIGNAL_FUNC(Window_destroy), NULL); + g_signal_connect(G_OBJECT(Button), "clicked", + G_CALLBACK(Window_destroy), NULL); - Button = gtk_button_new_from_stock(GTK_STOCK_ABOUT); + Button = gtk_button_new_with_label("About"); gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0); - g_signal_connect(GTK_OBJECT(Button), "clicked", - GTK_SIGNAL_FUNC(About_clicked), NULL); + g_signal_connect(G_OBJECT(Button), "clicked", + G_CALLBACK(About_clicked), NULL); Button = gtk_button_new_with_mnemonic("_Restart"); gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0); - g_signal_connect(GTK_OBJECT(Button), "clicked", - GTK_SIGNAL_FUNC(Restart_clicked), ctl); + g_signal_connect(G_OBJECT(Button), "clicked", + G_CALLBACK(Restart_clicked), ctl); Pause_Button = gtk_toggle_button_new_with_mnemonic("_Pause"); gtk_box_pack_end(GTK_BOX(Toolbar), Pause_Button, FALSE, FALSE, 0); - g_signal_connect(GTK_OBJECT(Pause_Button), "clicked", - GTK_SIGNAL_FUNC(Pause_clicked), ctl); + g_signal_connect(G_OBJECT(Pause_Button), "clicked", + G_CALLBACK(Pause_clicked), ctl); /* allow root only to set zero delay */ Adjustment = (GtkAdjustment *) gtk_adjustment_new(ctl->WaitTime, - getuid() == - 0 ? 0.01 : 1.00, + running_as_root() ? 0.01 : 1.00, 999.99, 1.0, 10.0, 0.0); Button = gtk_spin_button_new(Adjustment, 0.5, 2); gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(Button), TRUE); gtk_box_pack_end(GTK_BOX(Toolbar), Button, FALSE, FALSE, 0); ctl->gtk_data = Button; - g_signal_connect(GTK_OBJECT(Adjustment), "value_changed", - GTK_SIGNAL_FUNC(WaitTime_changed), ctl); + g_signal_connect(G_OBJECT(Adjustment), "value_changed", + G_CALLBACK(WaitTime_changed), ctl); Label = gtk_label_new_with_mnemonic("_Hostname:"); gtk_box_pack_start(GTK_BOX(Toolbar), Label, FALSE, FALSE, 0); Entry = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(Entry), ctl->Hostname); - g_signal_connect(GTK_OBJECT(Entry), "activate", - GTK_SIGNAL_FUNC(Host_activate), ctl); + g_signal_connect(G_OBJECT(Entry), "activate", + G_CALLBACK(Host_activate), ctl); gtk_box_pack_start(GTK_BOX(Toolbar), Entry, TRUE, TRUE, 0); gtk_label_set_mnemonic_widget(GTK_LABEL(Label), Entry); @@ -395,7 +394,7 @@ static void TreeViewCreate( ReportTreeView = gtk_tree_view_new_with_model(GTK_TREE_MODEL(ReportStore)); - g_signal_connect(GTK_OBJECT(ReportTreeView), "button_press_event", + g_signal_connect(G_OBJECT(ReportTreeView), "button_press_event", G_CALLBACK(ReportTreeView_clicked), ctl); #ifdef HAVE_IPINFO @@ -508,7 +507,7 @@ static void update_tree_row( char str[256] = "???", *name = str; addr = net_addr(row); - if (addrcmp((void *) addr, (void *) &ctl->unspec_addr, ctl->af)) { + if (addrcmp(addr, &ctl->unspec_addr, ctl->af)) { if ((name = dns_lookup(ctl, addr))) { if (ctl->show_ips) { snprintf(str, sizeof(str), "%s (%s)", name, @@ -565,6 +564,15 @@ void gtk_redraw( } } +// GTK 3 has changed the interface a bit. Here a few defines so that we can +// work with GTK2 or GTK3 as required. +#ifdef HAVE_GTK3 +#define gtk_vbox_new_(orientation,sz) gtk_box_new(orientation, sz) +#define gtk_hbox_new_(orientation,sz) gtk_box_new(orientation, sz) +#else +#define gtk_vbox_new_(orientation,sz) gtk_vbox_new(FALSE, sz) +#define gtk_hbox_new_(orientation,sz) gtk_hbox_new(FALSE, sz) +#endif static void Window_fill( struct mtr_ctl *ctl, @@ -577,9 +585,10 @@ static void Window_fill( gtk_window_set_title(GTK_WINDOW(Window), "My traceroute"); gtk_window_set_default_size(GTK_WINDOW(Window), 650, 400); gtk_container_set_border_width(GTK_CONTAINER(Window), 10); - VBox = gtk_vbox_new(FALSE, 10); - Toolbar = gtk_hbox_new(FALSE, 10); + VBox = gtk_vbox_new_(GTK_ORIENTATION_VERTICAL, 10); + Toolbar = gtk_hbox_new_(GTK_ORIENTATION_HORIZONTAL, 10); + Toolbar_fill(ctl, Toolbar); gtk_box_pack_start(GTK_BOX(VBox), Toolbar, FALSE, FALSE, 0); @@ -620,10 +629,10 @@ void gtk_open( Window_fill(ctl, main_window); - g_signal_connect(GTK_OBJECT(main_window), "delete_event", - GTK_SIGNAL_FUNC(Window_destroy), NULL); - g_signal_connect(GTK_OBJECT(main_window), "destroy", - GTK_SIGNAL_FUNC(Window_destroy), NULL); + g_signal_connect(G_OBJECT(main_window), "delete_event", + G_CALLBACK(Window_destroy), NULL); + g_signal_connect(G_OBJECT(main_window), "destroy", + G_CALLBACK(Window_destroy), NULL); gtk_widget_show_all(main_window); } @@ -802,20 +811,24 @@ static gboolean ReportTreeView_clicked( newdestination_item = gtk_menu_item_new_with_label("Set as new destination"); - gtk_menu_append(GTK_MENU(popup_menu), copy_item); - gtk_menu_append(GTK_MENU(popup_menu), newdestination_item); + gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), copy_item); + gtk_menu_shell_append(GTK_MENU_SHELL(popup_menu), newdestination_item); - g_signal_connect(GTK_OBJECT(copy_item), "activate", - GTK_SIGNAL_FUNC(Copy_activate), path); + g_signal_connect(G_OBJECT(copy_item), "activate", + G_CALLBACK(Copy_activate), path); ctl->gtk_data = path; - g_signal_connect(GTK_OBJECT(newdestination_item), "activate", - GTK_SIGNAL_FUNC(NewDestination_activate), ctl); + g_signal_connect(G_OBJECT(newdestination_item), "activate", + G_CALLBACK(NewDestination_activate), ctl); gtk_widget_show(copy_item); gtk_widget_show(newdestination_item); +#ifdef HAVE_GTK3 + gtk_menu_popup_at_pointer(GTK_MENU(popup_menu), NULL); +#else gtk_menu_popup(GTK_MENU(popup_menu), NULL, NULL, NULL, NULL, 0, event->time); +#endif return TRUE; }