Commit ef22be9b authored by Matthias Clasen's avatar Matthias Clasen

Drop GtkModelButton:has-submenu

Replace the has-submenu property with checking menu-name != NULL.
parent 4da281d2
...@@ -56,13 +56,14 @@ typedef struct ...@@ -56,13 +56,14 @@ typedef struct
G_DEFINE_TYPE (GtkMenuSectionBox, gtk_menu_section_box, GTK_TYPE_BOX) G_DEFINE_TYPE (GtkMenuSectionBox, gtk_menu_section_box, GTK_TYPE_BOX)
void gtk_menu_section_box_sync_separators (GtkMenuSectionBox *box, static void gtk_menu_section_box_sync_separators (GtkMenuSectionBox *box,
MenuData *data); MenuData *data);
void gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item, static void gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
GtkMenuSectionBox *toplevel, GtkMenuSectionBox *toplevel,
GtkWidget *focus); GtkWidget *focus,
GtkWidget * gtk_menu_section_box_new_section (GtkMenuTrackerItem *item, const gchar *name);
GtkMenuSectionBox *parent); static GtkWidget * gtk_menu_section_box_new_section (GtkMenuTrackerItem *item,
GtkMenuSectionBox *parent);
static void static void
gtk_menu_section_box_sync_item (GtkWidget *widget, gtk_menu_section_box_sync_item (GtkWidget *widget,
...@@ -86,7 +87,7 @@ gtk_menu_section_box_sync_item (GtkWidget *widget, ...@@ -86,7 +87,7 @@ gtk_menu_section_box_sync_item (GtkWidget *widget,
* rule 5: never show separators directly above or below an iconic box * rule 5: never show separators directly above or below an iconic box
* (rule 6: these rules don't apply exactly the same way for subsections) * (rule 6: these rules don't apply exactly the same way for subsections)
*/ */
void static void
gtk_menu_section_box_sync_separators (GtkMenuSectionBox *box, gtk_menu_section_box_sync_separators (GtkMenuSectionBox *box,
MenuData *data) MenuData *data)
{ {
...@@ -234,16 +235,12 @@ close_submenu (GtkWidget *button, ...@@ -234,16 +235,12 @@ close_submenu (GtkWidget *button,
gpointer data) gpointer data)
{ {
GtkMenuTrackerItem *item = data; GtkMenuTrackerItem *item = data;
GtkWidget *stack;
GtkWidget *parent;
GtkWidget *focus; GtkWidget *focus;
if (gtk_menu_tracker_item_get_should_request_show (item)) if (gtk_menu_tracker_item_get_should_request_show (item))
gtk_menu_tracker_item_request_submenu_shown (item, FALSE); gtk_menu_tracker_item_request_submenu_shown (item, FALSE);
focus = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "focus")); focus = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "focus"));
get_ancestors (focus, GTK_TYPE_STACK, &stack, &parent);
gtk_stack_set_visible_child (GTK_STACK (stack), parent);
gtk_widget_grab_focus (focus); gtk_widget_grab_focus (focus);
} }
...@@ -252,16 +249,12 @@ open_submenu (GtkWidget *button, ...@@ -252,16 +249,12 @@ open_submenu (GtkWidget *button,
gpointer data) gpointer data)
{ {
GtkMenuTrackerItem *item = data; GtkMenuTrackerItem *item = data;
GtkWidget *stack;
GtkWidget *child;
GtkWidget *focus; GtkWidget *focus;
if (gtk_menu_tracker_item_get_should_request_show (item)) if (gtk_menu_tracker_item_get_should_request_show (item))
gtk_menu_tracker_item_request_submenu_shown (item, TRUE); gtk_menu_tracker_item_request_submenu_shown (item, TRUE);
focus = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "focus")); focus = GTK_WIDGET (g_object_get_data (G_OBJECT (button), "focus"));
get_ancestors (focus, GTK_TYPE_STACK, &stack, &child);
gtk_stack_set_visible_child (GTK_STACK (stack), child);
gtk_widget_grab_focus (focus); gtk_widget_grab_focus (focus);
} }
...@@ -279,17 +272,25 @@ gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item, ...@@ -279,17 +272,25 @@ gtk_menu_section_box_insert_func (GtkMenuTrackerItem *item,
} }
else if (gtk_menu_tracker_item_get_has_link (item, G_MENU_LINK_SUBMENU)) else if (gtk_menu_tracker_item_get_has_link (item, G_MENU_LINK_SUBMENU))
{ {
widget = g_object_new (GTK_TYPE_MODEL_BUTTON, "has-submenu", TRUE, NULL); GtkWidget *stack = NULL;
GtkWidget *parent = NULL;
gchar *name;
widget = g_object_new (GTK_TYPE_MODEL_BUTTON,
"menu-name", gtk_menu_tracker_item_get_label (item),
NULL);
g_object_bind_property (item, "label", widget, "text", G_BINDING_SYNC_CREATE); g_object_bind_property (item, "label", widget, "text", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "icon", widget, "icon", G_BINDING_SYNC_CREATE); g_object_bind_property (item, "icon", widget, "icon", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "sensitive", widget, "sensitive", G_BINDING_SYNC_CREATE); g_object_bind_property (item, "sensitive", widget, "sensitive", G_BINDING_SYNC_CREATE);
gtk_menu_section_box_new_submenu (item, box->toplevel, widget);
gtk_widget_show (widget); get_ancestors (GTK_WIDGET (box->toplevel), GTK_TYPE_STACK, &stack, &parent);
gtk_container_child_get (GTK_CONTAINER (stack), parent, "name", &name, NULL);
gtk_menu_section_box_new_submenu (item, box->toplevel, widget, name);
g_free (name);
} }
else else
{ {
widget = gtk_model_button_new (); widget = gtk_model_button_new ();
g_object_bind_property (item, "label", widget, "text", G_BINDING_SYNC_CREATE); g_object_bind_property (item, "label", widget, "text", G_BINDING_SYNC_CREATE);
if (box->iconic) if (box->iconic)
...@@ -388,10 +389,11 @@ gtk_menu_section_box_new_toplevel (GtkStack *stack, ...@@ -388,10 +389,11 @@ gtk_menu_section_box_new_toplevel (GtkStack *stack,
gtk_widget_show (GTK_WIDGET (box)); gtk_widget_show (GTK_WIDGET (box));
} }
void static void
gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item, gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
GtkMenuSectionBox *toplevel, GtkMenuSectionBox *toplevel,
GtkWidget *focus) GtkWidget *focus,
const gchar *name)
{ {
GtkMenuSectionBox *box; GtkMenuSectionBox *box;
GtkWidget *button; GtkWidget *button;
...@@ -399,10 +401,11 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item, ...@@ -399,10 +401,11 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
box = g_object_new (GTK_TYPE_MENU_SECTION_BOX, "margin", 10, NULL); box = g_object_new (GTK_TYPE_MENU_SECTION_BOX, "margin", 10, NULL);
button = g_object_new (GTK_TYPE_MODEL_BUTTON, button = g_object_new (GTK_TYPE_MODEL_BUTTON,
"has-submenu", TRUE, "menu-name", name,
"inverted", TRUE, "inverted", TRUE,
"centered", TRUE, "centered", TRUE,
NULL); NULL);
g_object_bind_property (item, "label", button, "text", G_BINDING_SYNC_CREATE); g_object_bind_property (item, "label", button, "text", G_BINDING_SYNC_CREATE);
g_object_bind_property (item, "icon", button, "icon", G_BINDING_SYNC_CREATE); g_object_bind_property (item, "icon", button, "icon", G_BINDING_SYNC_CREATE);
...@@ -425,7 +428,7 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item, ...@@ -425,7 +428,7 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
box); box);
} }
GtkWidget * static GtkWidget *
gtk_menu_section_box_new_section (GtkMenuTrackerItem *item, gtk_menu_section_box_new_section (GtkMenuTrackerItem *item,
GtkMenuSectionBox *parent) GtkMenuSectionBox *parent)
{ {
......
...@@ -41,7 +41,6 @@ struct _GtkModelButton ...@@ -41,7 +41,6 @@ struct _GtkModelButton
GtkWidget *image; GtkWidget *image;
GtkWidget *label; GtkWidget *label;
gboolean active; gboolean active;
gboolean has_submenu;
gboolean centered; gboolean centered;
gboolean inverted; gboolean inverted;
gboolean iconic; gboolean iconic;
...@@ -61,7 +60,6 @@ enum ...@@ -61,7 +60,6 @@ enum
PROP_TEXT, PROP_TEXT,
PROP_ACTIVE, PROP_ACTIVE,
PROP_ACCEL, PROP_ACCEL,
PROP_HAS_SUBMENU,
PROP_MENU_NAME, PROP_MENU_NAME,
PROP_INVERTED, PROP_INVERTED,
PROP_CENTERED, PROP_CENTERED,
...@@ -151,7 +149,7 @@ gtk_model_button_update_state (GtkModelButton *button) ...@@ -151,7 +149,7 @@ gtk_model_button_update_state (GtkModelButton *button)
state &= ~GTK_STATE_FLAG_CHECKED; state &= ~GTK_STATE_FLAG_CHECKED;
if (button->active && !button->has_submenu) if (button->active && !button->menu_name)
state |= GTK_STATE_FLAG_CHECKED; state |= GTK_STATE_FLAG_CHECKED;
gtk_widget_set_state_flags (GTK_WIDGET (button), state, TRUE); gtk_widget_set_state_flags (GTK_WIDGET (button), state, TRUE);
...@@ -167,15 +165,6 @@ gtk_model_button_set_active (GtkModelButton *button, ...@@ -167,15 +165,6 @@ gtk_model_button_set_active (GtkModelButton *button,
gtk_widget_queue_draw (GTK_WIDGET (button)); gtk_widget_queue_draw (GTK_WIDGET (button));
} }
static void
gtk_model_button_set_has_submenu (GtkModelButton *button,
gboolean has_submenu)
{
button->has_submenu = has_submenu;
gtk_model_button_update_state (button);
gtk_widget_queue_resize (GTK_WIDGET (button));
}
static void static void
gtk_model_button_set_menu_name (GtkModelButton *button, gtk_model_button_set_menu_name (GtkModelButton *button,
const gchar *menu_name) const gchar *menu_name)
...@@ -282,10 +271,6 @@ gtk_model_button_set_property (GObject *object, ...@@ -282,10 +271,6 @@ gtk_model_button_set_property (GObject *object,
gtk_model_button_set_accel (button, g_value_get_string (value)); gtk_model_button_set_accel (button, g_value_get_string (value));
break; break;
case PROP_HAS_SUBMENU:
gtk_model_button_set_has_submenu (button, g_value_get_boolean (value));
break;
case PROP_MENU_NAME: case PROP_MENU_NAME:
gtk_model_button_set_menu_name (button, g_value_get_string (value)); gtk_model_button_set_menu_name (button, g_value_get_string (value));
break; break;
...@@ -355,7 +340,7 @@ has_sibling_with_indicator (GtkWidget *button) ...@@ -355,7 +340,7 @@ has_sibling_with_indicator (GtkWidget *button)
continue; continue;
if (!sibling->centered && if (!sibling->centered &&
(sibling->has_submenu || sibling->role != GTK_MENU_TRACKER_ITEM_ROLE_NORMAL)) (sibling->menu_name || sibling->role != GTK_MENU_TRACKER_ITEM_ROLE_NORMAL))
{ {
has_indicator = TRUE; has_indicator = TRUE;
break; break;
...@@ -647,7 +632,7 @@ gtk_model_button_draw (GtkWidget *widget, ...@@ -647,7 +632,7 @@ gtk_model_button_draw (GtkWidget *widget,
width - 2 * border_width, width - 2 * border_width,
height - 2 * border_width); height - 2 * border_width);
if (model_button->has_submenu) if (model_button->menu_name)
{ {
GtkStateFlags state; GtkStateFlags state;
...@@ -758,9 +743,6 @@ gtk_model_button_class_init (GtkModelButtonClass *class) ...@@ -758,9 +743,6 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
g_object_class_install_property (object_class, PROP_ACCEL, g_object_class_install_property (object_class, PROP_ACCEL,
g_param_spec_string ("accel", "", "", NULL, g_param_spec_string ("accel", "", "", NULL,
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS)); G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_HAS_SUBMENU,
g_param_spec_boolean ("has-submenu", "", "", FALSE,
G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_MENU_NAME, g_object_class_install_property (object_class, PROP_MENU_NAME,
g_param_spec_string ("menu-name", "", "", NULL, g_param_spec_string ("menu-name", "", "", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment