mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-14 20:51:07 +00:00
Drop GtkModelButton:has-submenu
Replace the has-submenu property with checking menu-name != NULL.
This commit is contained in:
parent
4da281d20b
commit
ef22be9bb7
@ -56,13 +56,14 @@ typedef struct
|
||||
|
||||
G_DEFINE_TYPE (GtkMenuSectionBox, gtk_menu_section_box, GTK_TYPE_BOX)
|
||||
|
||||
void gtk_menu_section_box_sync_separators (GtkMenuSectionBox *box,
|
||||
MenuData *data);
|
||||
void gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
|
||||
GtkMenuSectionBox *toplevel,
|
||||
GtkWidget *focus);
|
||||
GtkWidget * gtk_menu_section_box_new_section (GtkMenuTrackerItem *item,
|
||||
GtkMenuSectionBox *parent);
|
||||
static void gtk_menu_section_box_sync_separators (GtkMenuSectionBox *box,
|
||||
MenuData *data);
|
||||
static void gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
|
||||
GtkMenuSectionBox *toplevel,
|
||||
GtkWidget *focus,
|
||||
const gchar *name);
|
||||
static GtkWidget * gtk_menu_section_box_new_section (GtkMenuTrackerItem *item,
|
||||
GtkMenuSectionBox *parent);
|
||||
|
||||
static void
|
||||
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 6: these rules don't apply exactly the same way for subsections)
|
||||
*/
|
||||
void
|
||||
static void
|
||||
gtk_menu_section_box_sync_separators (GtkMenuSectionBox *box,
|
||||
MenuData *data)
|
||||
{
|
||||
@ -234,16 +235,12 @@ close_submenu (GtkWidget *button,
|
||||
gpointer data)
|
||||
{
|
||||
GtkMenuTrackerItem *item = data;
|
||||
GtkWidget *stack;
|
||||
GtkWidget *parent;
|
||||
GtkWidget *focus;
|
||||
|
||||
if (gtk_menu_tracker_item_get_should_request_show (item))
|
||||
gtk_menu_tracker_item_request_submenu_shown (item, FALSE);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -252,16 +249,12 @@ open_submenu (GtkWidget *button,
|
||||
gpointer data)
|
||||
{
|
||||
GtkMenuTrackerItem *item = data;
|
||||
GtkWidget *stack;
|
||||
GtkWidget *child;
|
||||
GtkWidget *focus;
|
||||
|
||||
if (gtk_menu_tracker_item_get_should_request_show (item))
|
||||
gtk_menu_tracker_item_request_submenu_shown (item, TRUE);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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))
|
||||
{
|
||||
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, "icon", widget, "icon", 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
|
||||
{
|
||||
widget = gtk_model_button_new ();
|
||||
|
||||
g_object_bind_property (item, "label", widget, "text", G_BINDING_SYNC_CREATE);
|
||||
|
||||
if (box->iconic)
|
||||
@ -388,10 +389,11 @@ gtk_menu_section_box_new_toplevel (GtkStack *stack,
|
||||
gtk_widget_show (GTK_WIDGET (box));
|
||||
}
|
||||
|
||||
void
|
||||
static void
|
||||
gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
|
||||
GtkMenuSectionBox *toplevel,
|
||||
GtkWidget *focus)
|
||||
GtkWidget *focus,
|
||||
const gchar *name)
|
||||
{
|
||||
GtkMenuSectionBox *box;
|
||||
GtkWidget *button;
|
||||
@ -399,10 +401,11 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
|
||||
box = g_object_new (GTK_TYPE_MENU_SECTION_BOX, "margin", 10, NULL);
|
||||
|
||||
button = g_object_new (GTK_TYPE_MODEL_BUTTON,
|
||||
"has-submenu", TRUE,
|
||||
"menu-name", name,
|
||||
"inverted", TRUE,
|
||||
"centered", TRUE,
|
||||
NULL);
|
||||
|
||||
g_object_bind_property (item, "label", button, "text", 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,
|
||||
box);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
static GtkWidget *
|
||||
gtk_menu_section_box_new_section (GtkMenuTrackerItem *item,
|
||||
GtkMenuSectionBox *parent)
|
||||
{
|
||||
|
@ -41,7 +41,6 @@ struct _GtkModelButton
|
||||
GtkWidget *image;
|
||||
GtkWidget *label;
|
||||
gboolean active;
|
||||
gboolean has_submenu;
|
||||
gboolean centered;
|
||||
gboolean inverted;
|
||||
gboolean iconic;
|
||||
@ -61,7 +60,6 @@ enum
|
||||
PROP_TEXT,
|
||||
PROP_ACTIVE,
|
||||
PROP_ACCEL,
|
||||
PROP_HAS_SUBMENU,
|
||||
PROP_MENU_NAME,
|
||||
PROP_INVERTED,
|
||||
PROP_CENTERED,
|
||||
@ -151,7 +149,7 @@ gtk_model_button_update_state (GtkModelButton *button)
|
||||
|
||||
state &= ~GTK_STATE_FLAG_CHECKED;
|
||||
|
||||
if (button->active && !button->has_submenu)
|
||||
if (button->active && !button->menu_name)
|
||||
state |= GTK_STATE_FLAG_CHECKED;
|
||||
|
||||
gtk_widget_set_state_flags (GTK_WIDGET (button), state, TRUE);
|
||||
@ -167,15 +165,6 @@ gtk_model_button_set_active (GtkModelButton *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
|
||||
gtk_model_button_set_menu_name (GtkModelButton *button,
|
||||
const gchar *menu_name)
|
||||
@ -282,10 +271,6 @@ gtk_model_button_set_property (GObject *object,
|
||||
gtk_model_button_set_accel (button, g_value_get_string (value));
|
||||
break;
|
||||
|
||||
case PROP_HAS_SUBMENU:
|
||||
gtk_model_button_set_has_submenu (button, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
case PROP_MENU_NAME:
|
||||
gtk_model_button_set_menu_name (button, g_value_get_string (value));
|
||||
break;
|
||||
@ -355,7 +340,7 @@ has_sibling_with_indicator (GtkWidget *button)
|
||||
continue;
|
||||
|
||||
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;
|
||||
break;
|
||||
@ -647,7 +632,7 @@ gtk_model_button_draw (GtkWidget *widget,
|
||||
width - 2 * border_width,
|
||||
height - 2 * border_width);
|
||||
|
||||
if (model_button->has_submenu)
|
||||
if (model_button->menu_name)
|
||||
{
|
||||
GtkStateFlags state;
|
||||
|
||||
@ -758,9 +743,6 @@ gtk_model_button_class_init (GtkModelButtonClass *class)
|
||||
g_object_class_install_property (object_class, PROP_ACCEL,
|
||||
g_param_spec_string ("accel", "", "", NULL,
|
||||
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_param_spec_string ("menu-name", "", "", NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
|
Loading…
Reference in New Issue
Block a user