mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-10 07:50:19 +00:00
Updated GTK3 menu item label/state handling and join dialog accessors while preserving GTK2 field access under !HAVE_GTK3 guards.
Switched GTK3 menu child list usage and menu reordering calculations to container-based APIs with list cleanup in GTK3 paths.
This commit is contained in:
@@ -330,9 +330,20 @@ menu_quick_item (char *cmd, char *label, GtkWidget * menu, int flags,
|
||||
{
|
||||
item = gtk_menu_item_new_with_label ("");
|
||||
if (flags & XCMENU_MNEMONIC)
|
||||
{
|
||||
#if HAVE_GTK3
|
||||
gtk_label_set_markup_with_mnemonic (GTK_LABEL (gtk_bin_get_child (GTK_BIN (item))), label);
|
||||
#else
|
||||
gtk_label_set_markup_with_mnemonic (GTK_LABEL (GTK_BIN (item)->child), label);
|
||||
else
|
||||
#endif
|
||||
} else
|
||||
{
|
||||
#if HAVE_GTK3
|
||||
gtk_label_set_markup (GTK_LABEL (gtk_bin_get_child (GTK_BIN (item))), label);
|
||||
#else
|
||||
gtk_label_set_markup (GTK_LABEL (GTK_BIN (item)->child), label);
|
||||
#endif
|
||||
}
|
||||
} else
|
||||
{
|
||||
if (flags & XCMENU_MNEMONIC)
|
||||
@@ -381,7 +392,11 @@ menu_quick_sub (char *name, GtkWidget *menu, GtkWidget **sub_item_ret, int flags
|
||||
if (flags & XCMENU_MARKUP)
|
||||
{
|
||||
sub_item = gtk_menu_item_new_with_label ("");
|
||||
#if HAVE_GTK3
|
||||
gtk_label_set_markup (GTK_LABEL (gtk_bin_get_child (GTK_BIN (sub_item))), name);
|
||||
#else
|
||||
gtk_label_set_markup (GTK_LABEL (GTK_BIN (sub_item)->child), name);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -421,7 +436,11 @@ toggle_cb (GtkWidget *item, char *pref_name)
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
#if HAVE_GTK3
|
||||
if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)))
|
||||
#else
|
||||
if (GTK_CHECK_MENU_ITEM (item)->active)
|
||||
#endif
|
||||
g_snprintf (buf, sizeof (buf), "set %s 1", pref_name);
|
||||
else
|
||||
g_snprintf (buf, sizeof (buf), "set %s 0", pref_name);
|
||||
@@ -742,6 +761,9 @@ void
|
||||
fe_userlist_update (session *sess, struct User *user)
|
||||
{
|
||||
GList *items, *next;
|
||||
#if HAVE_GTK3
|
||||
GList *iter;
|
||||
#endif
|
||||
|
||||
if (!nick_submenu || !str_copy)
|
||||
return;
|
||||
@@ -754,6 +776,17 @@ fe_userlist_update (session *sess, struct User *user)
|
||||
g_signal_handlers_disconnect_by_func (nick_submenu, menu_nickinfo_cb, sess);
|
||||
|
||||
/* destroy all the old items */
|
||||
#if HAVE_GTK3
|
||||
items = gtk_container_get_children (GTK_CONTAINER (nick_submenu));
|
||||
iter = items;
|
||||
while (iter)
|
||||
{
|
||||
next = iter->next;
|
||||
gtk_widget_destroy (iter->data);
|
||||
iter = next;
|
||||
}
|
||||
g_list_free (items);
|
||||
#else
|
||||
items = ((GtkMenuShell *) nick_submenu)->children;
|
||||
while (items)
|
||||
{
|
||||
@@ -761,6 +794,7 @@ fe_userlist_update (session *sess, struct User *user)
|
||||
gtk_widget_destroy (items->data);
|
||||
items = next;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* and re-create them with new info */
|
||||
menu_create_nickinfo_menu (user, nick_submenu);
|
||||
@@ -885,7 +919,11 @@ menu_setting_foreach (void (*callback) (session *), int id, guint state)
|
||||
if (sess->gui->is_tab)
|
||||
maindone = TRUE;
|
||||
if (id != -1)
|
||||
#if HAVE_GTK3
|
||||
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (sess->gui->menu_item[id]), state);
|
||||
#else
|
||||
GTK_CHECK_MENU_ITEM (sess->gui->menu_item[id])->active = state;
|
||||
#endif
|
||||
if (callback)
|
||||
callback (sess);
|
||||
}
|
||||
@@ -1215,8 +1253,22 @@ usermenu_create (GtkWidget *menu)
|
||||
static void
|
||||
usermenu_destroy (GtkWidget * menu)
|
||||
{
|
||||
GList *items = ((GtkMenuShell *) menu)->children;
|
||||
GList *items;
|
||||
GList *next;
|
||||
#if HAVE_GTK3
|
||||
GList *iter;
|
||||
|
||||
items = gtk_container_get_children (GTK_CONTAINER (menu));
|
||||
iter = items;
|
||||
while (iter)
|
||||
{
|
||||
next = iter->next;
|
||||
gtk_widget_destroy (iter->data);
|
||||
iter = next;
|
||||
}
|
||||
g_list_free (items);
|
||||
#else
|
||||
items = ((GtkMenuShell *) menu)->children;
|
||||
|
||||
while (items)
|
||||
{
|
||||
@@ -1224,6 +1276,7 @@ usermenu_destroy (GtkWidget * menu)
|
||||
gtk_widget_destroy (items->data);
|
||||
items = next;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
@@ -1434,7 +1487,11 @@ menu_join_cb (GtkWidget *dialog, gint response, GtkEntry *entry)
|
||||
switch (response)
|
||||
{
|
||||
case GTK_RESPONSE_ACCEPT:
|
||||
#if HAVE_GTK3
|
||||
menu_chan_join (NULL, (char *)gtk_entry_get_text (GTK_ENTRY (entry)));
|
||||
#else
|
||||
menu_chan_join (NULL, entry->text);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case GTK_RESPONSE_HELP:
|
||||
@@ -1455,6 +1512,9 @@ static void
|
||||
menu_join (GtkWidget * wid, gpointer none)
|
||||
{
|
||||
GtkWidget *hbox, *dialog, *entry, *label;
|
||||
#if HAVE_GTK3
|
||||
GtkWidget *content_area;
|
||||
#endif
|
||||
|
||||
#if HAVE_GTK3
|
||||
dialog = gtk_dialog_new_with_buttons (_("Join Channel"),
|
||||
@@ -1490,7 +1550,12 @@ menu_join (GtkWidget * wid, gpointer none)
|
||||
GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
|
||||
NULL);
|
||||
#endif
|
||||
#if HAVE_GTK3
|
||||
content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
|
||||
gtk_box_set_homogeneous (GTK_BOX (content_area), TRUE);
|
||||
#else
|
||||
gtk_box_set_homogeneous (GTK_BOX (GTK_DIALOG (dialog)->vbox), TRUE);
|
||||
#endif
|
||||
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
|
||||
#if HAVE_GTK3
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
@@ -1500,7 +1565,11 @@ menu_join (GtkWidget * wid, gpointer none)
|
||||
#endif
|
||||
|
||||
entry = gtk_entry_new ();
|
||||
#if HAVE_GTK3
|
||||
gtk_editable_set_editable (GTK_EDITABLE (entry), FALSE); /* avoid auto-selection */
|
||||
#else
|
||||
GTK_ENTRY (entry)->editable = 0; /* avoid auto-selection */
|
||||
#endif
|
||||
gtk_entry_set_text (GTK_ENTRY (entry), "#");
|
||||
g_signal_connect (G_OBJECT (entry), "activate",
|
||||
G_CALLBACK (menu_join_entry_cb), dialog);
|
||||
@@ -1512,7 +1581,11 @@ menu_join (GtkWidget * wid, gpointer none)
|
||||
g_signal_connect (G_OBJECT (dialog), "response",
|
||||
G_CALLBACK (menu_join_cb), entry);
|
||||
|
||||
#if HAVE_GTK3
|
||||
gtk_container_add (GTK_CONTAINER (content_area), hbox);
|
||||
#else
|
||||
gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), hbox);
|
||||
#endif
|
||||
|
||||
gtk_widget_show_all (dialog);
|
||||
|
||||
@@ -1735,7 +1808,11 @@ static void
|
||||
menu_layout_cb (GtkWidget *item, gpointer none)
|
||||
{
|
||||
prefs.hex_gui_tab_layout = 2;
|
||||
#if HAVE_GTK3
|
||||
if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)))
|
||||
#else
|
||||
if (GTK_CHECK_MENU_ITEM (item)->active)
|
||||
#endif
|
||||
prefs.hex_gui_tab_layout = 0;
|
||||
|
||||
menu_change_layout ();
|
||||
@@ -1750,7 +1827,11 @@ menu_apply_metres_cb (session *sess)
|
||||
static void
|
||||
menu_metres_off (GtkWidget *item, gpointer none)
|
||||
{
|
||||
#if HAVE_GTK3
|
||||
if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)))
|
||||
#else
|
||||
if (GTK_CHECK_MENU_ITEM (item)->active)
|
||||
#endif
|
||||
{
|
||||
prefs.hex_gui_lagometer = 0;
|
||||
prefs.hex_gui_throttlemeter = 0;
|
||||
@@ -1762,7 +1843,11 @@ menu_metres_off (GtkWidget *item, gpointer none)
|
||||
static void
|
||||
menu_metres_text (GtkWidget *item, gpointer none)
|
||||
{
|
||||
#if HAVE_GTK3
|
||||
if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)))
|
||||
#else
|
||||
if (GTK_CHECK_MENU_ITEM (item)->active)
|
||||
#endif
|
||||
{
|
||||
prefs.hex_gui_lagometer = 2;
|
||||
prefs.hex_gui_throttlemeter = 2;
|
||||
@@ -1774,7 +1859,11 @@ menu_metres_text (GtkWidget *item, gpointer none)
|
||||
static void
|
||||
menu_metres_graph (GtkWidget *item, gpointer none)
|
||||
{
|
||||
#if HAVE_GTK3
|
||||
if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)))
|
||||
#else
|
||||
if (GTK_CHECK_MENU_ITEM (item)->active)
|
||||
#endif
|
||||
{
|
||||
prefs.hex_gui_lagometer = 1;
|
||||
prefs.hex_gui_throttlemeter = 1;
|
||||
@@ -1786,7 +1875,11 @@ menu_metres_graph (GtkWidget *item, gpointer none)
|
||||
static void
|
||||
menu_metres_both (GtkWidget *item, gpointer none)
|
||||
{
|
||||
#if HAVE_GTK3
|
||||
if (gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (item)))
|
||||
#else
|
||||
if (GTK_CHECK_MENU_ITEM (item)->active)
|
||||
#endif
|
||||
{
|
||||
prefs.hex_gui_lagometer = 3;
|
||||
prefs.hex_gui_throttlemeter = 3;
|
||||
@@ -2074,30 +2167,51 @@ menu_canacaccel (GtkWidget *widget, guint signal_id, gpointer user_data)
|
||||
static GtkMenuItem *
|
||||
menu_find_item (GtkWidget *menu, char *name)
|
||||
{
|
||||
GList *items = ((GtkMenuShell *) menu)->children;
|
||||
GList *items;
|
||||
#if HAVE_GTK3
|
||||
GList *items_head;
|
||||
#endif
|
||||
GtkMenuItem *item;
|
||||
GtkWidget *child;
|
||||
const char *labeltext;
|
||||
GtkMenuItem *found = NULL;
|
||||
|
||||
#if HAVE_GTK3
|
||||
items_head = gtk_container_get_children (GTK_CONTAINER (menu));
|
||||
items = items_head;
|
||||
#else
|
||||
items = ((GtkMenuShell *) menu)->children;
|
||||
#endif
|
||||
while (items)
|
||||
{
|
||||
item = items->data;
|
||||
#if HAVE_GTK3
|
||||
child = gtk_bin_get_child (GTK_BIN (item));
|
||||
#else
|
||||
child = GTK_BIN (item)->child;
|
||||
#endif
|
||||
if (child) /* separators arn't labels, skip them */
|
||||
{
|
||||
labeltext = g_object_get_data (G_OBJECT (item), "name");
|
||||
if (!labeltext)
|
||||
labeltext = gtk_label_get_text (GTK_LABEL (child));
|
||||
if (!menu_streq (labeltext, name, 1))
|
||||
return item;
|
||||
{
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
} else if (name == NULL)
|
||||
{
|
||||
return item;
|
||||
found = item;
|
||||
break;
|
||||
}
|
||||
items = items->next;
|
||||
}
|
||||
#if HAVE_GTK3
|
||||
g_list_free (items_head);
|
||||
#endif
|
||||
|
||||
return NULL;
|
||||
return found;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
@@ -2179,7 +2293,11 @@ menu_update_cb (GtkWidget *menu, menu_entry *me, char *target)
|
||||
gtk_widget_set_sensitive (item, me->enable);
|
||||
/* must do it without triggering the callback */
|
||||
if (GTK_IS_CHECK_MENU_ITEM (item))
|
||||
#if HAVE_GTK3
|
||||
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), me->state);
|
||||
#else
|
||||
GTK_CHECK_MENU_ITEM (item)->active = me->state;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2188,7 +2306,11 @@ static void
|
||||
menu_radio_cb (GtkCheckMenuItem *item, menu_entry *me)
|
||||
{
|
||||
me->state = 0;
|
||||
#if HAVE_GTK3
|
||||
if (gtk_check_menu_item_get_active (item))
|
||||
#else
|
||||
if (item->active)
|
||||
#endif
|
||||
me->state = 1;
|
||||
|
||||
/* update the state, incase this was changed via right-click. */
|
||||
@@ -2204,7 +2326,11 @@ static void
|
||||
menu_toggle_cb (GtkCheckMenuItem *item, menu_entry *me)
|
||||
{
|
||||
me->state = 0;
|
||||
#if HAVE_GTK3
|
||||
if (gtk_check_menu_item_get_active (item))
|
||||
#else
|
||||
if (item->active)
|
||||
#endif
|
||||
me->state = 1;
|
||||
|
||||
/* update the state, incase this was changed via right-click. */
|
||||
@@ -2246,7 +2372,17 @@ menu_reorder (GtkMenu *menu, GtkWidget *item, int pos)
|
||||
return;
|
||||
|
||||
if (pos < 0) /* position offset from end/bottom */
|
||||
#if HAVE_GTK3
|
||||
{
|
||||
GList *children = gtk_container_get_children (GTK_CONTAINER (menu));
|
||||
int length = g_list_length (children);
|
||||
|
||||
g_list_free (children);
|
||||
gtk_menu_reorder_child (menu, item, (length + pos) - 1);
|
||||
}
|
||||
#else
|
||||
gtk_menu_reorder_child (menu, item, (g_list_length (GTK_MENU_SHELL (menu)->children) + pos) - 1);
|
||||
#endif
|
||||
else
|
||||
gtk_menu_reorder_child (menu, item, pos);
|
||||
}
|
||||
@@ -2312,7 +2448,17 @@ menu_add_sub (GtkWidget *menu, menu_entry *me)
|
||||
{
|
||||
pos = me->pos;
|
||||
if (pos < 0) /* position offset from end/bottom */
|
||||
#if HAVE_GTK3
|
||||
{
|
||||
GList *children = gtk_container_get_children (GTK_CONTAINER (menu));
|
||||
int length = g_list_length (children);
|
||||
|
||||
g_list_free (children);
|
||||
pos = length + pos;
|
||||
}
|
||||
#else
|
||||
pos = g_list_length (GTK_MENU_SHELL (menu)->children) + pos;
|
||||
#endif
|
||||
menu_quick_sub (me->label, menu, &item, me->markup ? XCMENU_MARKUP|XCMENU_MNEMONIC : XCMENU_MNEMONIC, pos);
|
||||
}
|
||||
return item;
|
||||
@@ -2590,7 +2736,11 @@ normalitem:
|
||||
item = gtk_check_menu_item_new_with_mnemonic (_(mymenu[i].text));
|
||||
togitem:
|
||||
/* must avoid callback for Radio buttons */
|
||||
#if HAVE_GTK3
|
||||
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), mymenu[i].state);
|
||||
#else
|
||||
GTK_CHECK_MENU_ITEM (item)->active = mymenu[i].state;
|
||||
#endif
|
||||
/*gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
|
||||
mymenu[i].state);*/
|
||||
if (mymenu[i].key != 0)
|
||||
|
||||
Reference in New Issue
Block a user