forked from AuroraMiddleware/gtk
model button: Add a role for titles
This gets us out of using direct presentational markup like 'inverted' and 'centered' and will make it easier to play with different layout. Use the new role when creating popover menus from models.
This commit is contained in:
parent
0d59ece4a4
commit
fc6010be37
@ -454,8 +454,7 @@ gtk_menu_section_box_new_submenu (GtkMenuTrackerItem *item,
|
||||
|
||||
button = g_object_new (GTK_TYPE_MODEL_BUTTON,
|
||||
"menu-name", name,
|
||||
"inverted", TRUE,
|
||||
"centered", TRUE,
|
||||
"role", GTK_BUTTON_ROLE_TITLE,
|
||||
NULL);
|
||||
|
||||
g_object_bind_property (item, "label", button, "text", G_BINDING_SYNC_CREATE);
|
||||
|
@ -196,13 +196,15 @@ gtk_model_button_update_state (GtkModelButton *button)
|
||||
{
|
||||
GtkStateFlags state;
|
||||
GtkStateFlags indicator_state;
|
||||
GtkCssImageBuiltinType image_type = GTK_CSS_IMAGE_BUILTIN_NONE;
|
||||
GtkCssImageBuiltinType image_type;
|
||||
|
||||
state = gtk_widget_get_state_flags (GTK_WIDGET (button));
|
||||
indicator_state = state;
|
||||
image_type = GTK_CSS_IMAGE_BUILTIN_NONE;
|
||||
|
||||
if (button->role == GTK_BUTTON_ROLE_CHECK)
|
||||
switch (button->role)
|
||||
{
|
||||
case GTK_BUTTON_ROLE_CHECK:
|
||||
if (button->active && !button->menu_name)
|
||||
{
|
||||
indicator_state |= GTK_STATE_FLAG_CHECKED;
|
||||
@ -212,9 +214,9 @@ gtk_model_button_update_state (GtkModelButton *button)
|
||||
{
|
||||
indicator_state &= ~GTK_STATE_FLAG_CHECKED;
|
||||
}
|
||||
}
|
||||
if (button->role == GTK_BUTTON_ROLE_RADIO)
|
||||
{
|
||||
break;
|
||||
|
||||
case GTK_BUTTON_ROLE_RADIO:
|
||||
if (button->active && !button->menu_name)
|
||||
{
|
||||
indicator_state |= GTK_STATE_FLAG_CHECKED;
|
||||
@ -224,14 +226,28 @@ gtk_model_button_update_state (GtkModelButton *button)
|
||||
{
|
||||
indicator_state &= ~GTK_STATE_FLAG_CHECKED;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
if (button->menu_name)
|
||||
{
|
||||
if (indicator_is_left (GTK_WIDGET (button)))
|
||||
image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT;
|
||||
else
|
||||
image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT;
|
||||
case GTK_BUTTON_ROLE_TITLE:
|
||||
g_object_set (button,
|
||||
"inverted", TRUE,
|
||||
"centered", TRUE,
|
||||
NULL);
|
||||
/* fall through */
|
||||
|
||||
case GTK_BUTTON_ROLE_NORMAL:
|
||||
if (button->menu_name != NULL)
|
||||
{
|
||||
if (indicator_is_left (GTK_WIDGET (button)))
|
||||
image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_LEFT;
|
||||
else
|
||||
image_type = GTK_CSS_IMAGE_BUILTIN_ARROW_RIGHT;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
gtk_icon_set_image (GTK_ICON (button->indicator_widget), image_type);
|
||||
@ -305,6 +321,7 @@ update_node_name (GtkModelButton *button)
|
||||
switch (button->role)
|
||||
{
|
||||
case GTK_BUTTON_ROLE_NORMAL:
|
||||
case GTK_BUTTON_ROLE_TITLE:
|
||||
a11y_role = ATK_ROLE_PUSH_BUTTON;
|
||||
if (button->menu_name)
|
||||
{
|
||||
@ -353,8 +370,8 @@ gtk_model_button_set_role (GtkModelButton *button,
|
||||
button->role = role;
|
||||
|
||||
update_node_name (button);
|
||||
|
||||
gtk_model_button_update_state (button);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (button));
|
||||
g_object_notify_by_pspec (G_OBJECT (button), properties[PROP_ROLE]);
|
||||
}
|
||||
|
@ -41,13 +41,15 @@ typedef struct _GtkModelButton GtkModelButton;
|
||||
* @GTK_BUTTON_ROLE_NORMAL: A plain button
|
||||
* @GTK_BUTTON_ROLE_CHECK: A check button
|
||||
* @GTK_BUTTON_ROLE_RADIO: A radio button
|
||||
* @GTK_BUTTON_ROLE_TITLE: The title for a submenu
|
||||
*
|
||||
* The role specifies the desired appearance of a #GtkModelButton.
|
||||
*/
|
||||
typedef enum {
|
||||
GTK_BUTTON_ROLE_NORMAL,
|
||||
GTK_BUTTON_ROLE_CHECK,
|
||||
GTK_BUTTON_ROLE_RADIO
|
||||
GTK_BUTTON_ROLE_RADIO,
|
||||
GTK_BUTTON_ROLE_TITLE
|
||||
} GtkButtonRole;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
Loading…
Reference in New Issue
Block a user