Merge branch 'seal-popover-menu' into 'master'

Privatize popover menu pieces

See merge request GNOME/gtk!925
This commit is contained in:
Matthias Clasen 2019-11-18 01:57:55 +00:00
commit d4180931f8
22 changed files with 140 additions and 133 deletions

View File

@ -149,7 +149,6 @@
<xi:include href="xml/gtkscalebutton.xml" />
<xi:include href="xml/gtkvolumebutton.xml" />
<xi:include href="xml/gtklockbutton.xml" />
<xi:include href="xml/gtkmodelbutton.xml" />
</chapter>
<chapter id="NumericEntry">

View File

@ -6546,18 +6546,14 @@ gtk_popover_get_type
<FILE>gtkpopovermenu</FILE>
<TITLE>GtkPopoverMenu</TITLE>
GtkPopoverMenu
gtk_popover_menu_new
gtk_popover_menu_new_from_model
gtk_popover_menu_add_submenu
gtk_popover_menu_open_submenu
gtk_popover_menu_set_menu_model
gtk_popover_menu_get_menu_model
<SUBSECTION Standard>
GTK_TYPE_POPOVER_MENU
GTK_IS_POPOVER_MENU
GTK_IS_POPOVER_MENU_CLASS
GTK_POPOVER_MENU
GTK_POPOVER_MENU_CLASS
GTK_POPOVER_MENU_GET_CLASS
<SUBSECTION Private>
gtk_popover_menu_get_type
@ -6580,20 +6576,6 @@ GTK_POPOVER_MENU_BAR
gtk_popover_menu_bar_get_type
</SECTION>
<SECTION>
<FILE>gtkmodelbutton</FILE>
<TITLE>GtkModelButton</TITLE>
GtkModelButton
GtkButtonRole
gtk_model_button_new
<SUBSECTION Standard>
GTK_TYPE_MODEL_BUTTON
GTK_MODEL_BUTTON
GTK_IS_MODEL_BUTTON
<SUBSECTION Private>
gtk_model_button_get_type
</SECTION>
<SECTION>
<FILE>gtkeventcontroller</FILE>
<TITLE>GtkEventController</TITLE>

View File

@ -121,7 +121,6 @@ gtk_menu_item_get_type
gtk_menu_shell_get_type
gtk_menu_tool_button_get_type
gtk_message_dialog_get_type
gtk_model_button_get_type
gtk_mount_operation_get_type
gtk_native_get_type
gtk_notebook_get_type

View File

@ -162,7 +162,6 @@
#include <gtk/gtkmenushell.h>
#include <gtk/gtkmenutoolbutton.h>
#include <gtk/gtkmessagedialog.h>
#include <gtk/gtkmodelbutton.h>
#include <gtk/gtkmountoperation.h>
#include <gtk/gtknative.h>
#include <gtk/gtknativedialog.h>

View File

@ -22,8 +22,8 @@
#include "gtkwidgetprivate.h"
#include "gtkdebug.h"
#include "gtkmodelbutton.h"
#include "gtktypebuiltins.h"
#include "gtkmodelbuttonprivate.h"
#include <string.h>

View File

@ -32,7 +32,7 @@
#include "gtkimage.h"
#include "gtkintl.h"
#include "gtkmain.h"
#include "gtkmodelbutton.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkpopovermenu.h"
#include "gtkprivate.h"
#include "gtksnapshot.h"

View File

@ -76,7 +76,7 @@
#include "gtkrevealer.h"
#include "gtkspinner.h"
#include "gtkseparator.h"
#include "gtkmodelbutton.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkgesturelongpress.h"
#include "gtkgestureclick.h"
#include "gtkeventcontrollerkey.h"

View File

@ -25,12 +25,12 @@
#include "gtkwidgetprivate.h"
#include "gtklabel.h"
#include "gtkmenutrackerprivate.h"
#include "gtkmodelbutton.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkseparator.h"
#include "gtksizegroup.h"
#include "gtkstack.h"
#include "gtkstylecontext.h"
#include "gtkpopovermenu.h"
#include "gtkpopovermenuprivate.h"
#include "gtkorientable.h"
#include "gtkiconprivate.h"

View File

@ -19,7 +19,7 @@
#include "config.h"
#include "gtkmodelbutton.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkactionhelperprivate.h"
#include "gtkboxlayout.h"
@ -182,6 +182,30 @@ static void gtk_model_button_actionable_iface_init (GtkActionableInterface *ifac
G_DEFINE_TYPE_WITH_CODE (GtkModelButton, gtk_model_button, GTK_TYPE_WIDGET,
G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIONABLE, gtk_model_button_actionable_iface_init))
GType
gtk_button_role_get_type (void)
{
static gsize gtk_button_role_type;
if (g_once_init_enter (&gtk_button_role_type))
{
static const GEnumValue values[] = {
{ GTK_BUTTON_ROLE_NORMAL, "GTK_BUTTON_ROLE_NORMAL", "normal" },
{ GTK_BUTTON_ROLE_CHECK, "GTK_BUTTON_ROLE_CHECK", "check" },
{ GTK_BUTTON_ROLE_RADIO, "GTK_BUTTON_ROLE_RADIO", "radio" },
{ GTK_BUTTON_ROLE_TITLE, "GTK_BUTTON_ROLE_RADIO", "title" },
{ 0, NULL, NULL }
};
GType type;
type = g_enum_register_static (I_("GtkButtonRole"), values);
g_once_init_leave (&gtk_button_role_type, type);
}
return gtk_button_role_type;
}
enum
{
PROP_0,

View File

@ -17,12 +17,8 @@
* Author: Matthias Clasen
*/
#ifndef __GTK_MODEL_BUTTON_H__
#define __GTK_MODEL_BUTTON_H__
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
#error "Only <gtk/gtk.h> can be included directly."
#endif
#ifndef __GTK_MODEL_BUTTON_PRIVATE_H__
#define __GTK_MODEL_BUTTON_PRIVATE_H__
#include <gtk/gtkwidget.h>
@ -52,12 +48,13 @@ typedef enum {
GTK_BUTTON_ROLE_TITLE
} GtkButtonRole;
GDK_AVAILABLE_IN_ALL
#define GTK_TYPE_BUTTON_ROLE (gtk_button_role_get_type ())
GType gtk_button_role_get_type (void) G_GNUC_CONST;
GType gtk_model_button_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_model_button_new (void);
G_END_DECLS
#endif /* __GTK_MODEL_BUTTON_H__ */
#endif /* __GTK_MODEL_BUTTON_PRIVATE_H__ */

View File

@ -43,7 +43,7 @@
#include "gtklabel.h"
#include "gtkmain.h"
#include "gtkmarshalers.h"
#include "gtkpopovermenu.h"
#include "gtkpopovermenuprivate.h"
#include "gtkorientable.h"
#include "gtksizerequest.h"
#include "gtkstylecontextprivate.h"

View File

@ -59,7 +59,7 @@
#include "gtkentry.h"
#include "gtkgesturelongpress.h"
#include "gtkbox.h"
#include "gtkmodelbutton.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkprivate.h"
#include "gtkeventcontrollerkey.h"
#include "gtkgestureclick.h"

View File

@ -33,7 +33,7 @@
#include "gtkmain.h"
#include "gtktypebuiltins.h"
#include "gtkbindings.h"
#include "gtkmodelbutton.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkpopovermenubar.h"
@ -129,6 +129,8 @@ struct _GtkPopoverMenu
GtkWidget *active_item;
GtkWidget *open_submenu;
GtkWidget *parent_menu;
GMenuModel *model;
GtkPopoverMenuFlags flags;
};
struct _GtkPopoverMenuClass
@ -137,7 +139,8 @@ struct _GtkPopoverMenuClass
};
enum {
PROP_VISIBLE_SUBMENU = 1
PROP_VISIBLE_SUBMENU = 1,
PROP_MENU_MODEL
};
G_DEFINE_TYPE (GtkPopoverMenu, gtk_popover_menu, GTK_TYPE_POPOVER)
@ -276,6 +279,16 @@ gtk_popover_menu_init (GtkPopoverMenu *popover)
}
static void
gtk_popover_menu_dispose (GObject *object)
{
GtkPopoverMenu *popover = GTK_POPOVER_MENU (object);
g_clear_object (&popover->model);
G_OBJECT_CLASS (gtk_popover_menu_parent_class)->dispose (object);
}
static void
gtk_popover_menu_map (GtkWidget *widget)
{
@ -290,47 +303,6 @@ gtk_popover_menu_unmap (GtkWidget *widget)
gtk_popover_menu_open_submenu (GTK_POPOVER_MENU (widget), "main");
}
static void
gtk_popover_menu_add (GtkContainer *container,
GtkWidget *child)
{
GtkWidget *stack;
stack = gtk_bin_get_child (GTK_BIN (container));
if (stack == NULL)
{
GTK_CONTAINER_CLASS (gtk_popover_menu_parent_class)->add (container, child);
}
else
{
const char *name;
if (gtk_widget_get_name (child))
name = gtk_widget_get_name (child);
else if (gtk_stack_get_child_by_name (GTK_STACK (stack), "main"))
name = "submenu";
else
name = "main";
gtk_popover_menu_add_submenu (GTK_POPOVER_MENU (container), child, name);
}
}
static void
gtk_popover_menu_remove (GtkContainer *container,
GtkWidget *child)
{
GtkWidget *stack;
stack = gtk_bin_get_child (GTK_BIN (container));
if (child == stack)
GTK_CONTAINER_CLASS (gtk_popover_menu_parent_class)->remove (container, child);
else
gtk_container_remove (GTK_CONTAINER (stack), child);
}
static void
gtk_popover_menu_get_property (GObject *object,
guint property_id,
@ -347,6 +319,10 @@ gtk_popover_menu_get_property (GObject *object,
g_value_set_string (value, gtk_stack_get_visible_child_name (GTK_STACK (stack)));
break;
case PROP_MENU_MODEL:
g_value_set_object (value, gtk_popover_menu_get_menu_model (GTK_POPOVER_MENU (object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -369,6 +345,10 @@ gtk_popover_menu_set_property (GObject *object,
gtk_stack_set_visible_child_name (GTK_STACK (stack), g_value_get_string (value));
break;
case PROP_MENU_MODEL:
gtk_popover_menu_set_menu_model (GTK_POPOVER_MENU (object), g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@ -470,11 +450,11 @@ add_arrow_bindings (GtkBindingSet *binding_set,
static void
gtk_popover_menu_class_init (GtkPopoverMenuClass *klass)
{
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkBindingSet *binding_set;
object_class->dispose = gtk_popover_menu_dispose;
object_class->set_property = gtk_popover_menu_set_property;
object_class->get_property = gtk_popover_menu_get_property;
@ -482,9 +462,6 @@ gtk_popover_menu_class_init (GtkPopoverMenuClass *klass)
widget_class->unmap = gtk_popover_menu_unmap;
widget_class->focus = gtk_popover_menu_focus;
container_class->add = gtk_popover_menu_add;
container_class->remove = gtk_popover_menu_remove;
g_object_class_install_property (object_class,
PROP_VISIBLE_SUBMENU,
g_param_spec_string ("visible-submenu",
@ -493,6 +470,14 @@ gtk_popover_menu_class_init (GtkPopoverMenuClass *klass)
NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
PROP_MENU_MODEL,
g_param_spec_object ("menu-model",
P_("Menu model"),
P_("The model from which the menu is made."),
G_TYPE_MENU_MODEL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
binding_set = gtk_binding_set_by_class (klass);
add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP);
@ -567,14 +552,6 @@ gtk_popover_menu_open_submenu (GtkPopoverMenu *popover,
gtk_stack_set_visible_child_name (GTK_STACK (stack), name);
}
/**
* gtk_popover_menu_add_submenu:
* @popover: a #GtkPopoverMenu
* @submenu: a widget to add as submenu
* @name: the name for the submenu
*
* Adds a submenu to the popover menu.
*/
void
gtk_popover_menu_add_submenu (GtkPopoverMenu *popover,
GtkWidget *submenu,
@ -583,14 +560,13 @@ gtk_popover_menu_add_submenu (GtkPopoverMenu *popover,
GtkWidget *stack;
stack = gtk_bin_get_child (GTK_BIN (popover));
gtk_stack_add_named (GTK_STACK (stack), submenu, name);
}
/**
* gtk_popover_menu_new_from_model:
* @relative_to: (allow-none): #GtkWidget the popover is related to
* @model: a #GMenuModel
* @model: (allow-none): a #GMenuModel, or %NULL
*
* Creates a #GtkPopoverMenu and populates it according to
* @model. The popover is pointed to the @relative_to widget.
@ -638,7 +614,7 @@ gtk_popover_menu_new_from_model (GtkWidget *relative_to,
* #GTK_POPOVER_MENU_NESTED, which makes GTK create traditional,
* nested submenus instead of the default sliding submenus.
*
* Returns: the new #GtkPopoverMenu
* Returns: (transfer full): the new #GtkPopoverMenu
*/
GtkWidget *
gtk_popover_menu_new_from_model_full (GtkWidget *relative_to,
@ -648,11 +624,42 @@ gtk_popover_menu_new_from_model_full (GtkWidget *relative_to,
GtkWidget *popover;
g_return_val_if_fail (relative_to == NULL || GTK_IS_WIDGET (relative_to), NULL);
g_return_val_if_fail (G_IS_MENU_MODEL (model), NULL);
g_return_val_if_fail (model == NULL || G_IS_MENU_MODEL (model), NULL);
popover = gtk_popover_menu_new (relative_to);
gtk_menu_section_box_new_toplevel (GTK_POPOVER_MENU (popover), model, flags);
GTK_POPOVER_MENU (popover)->flags = flags;
gtk_popover_menu_set_menu_model (GTK_POPOVER_MENU (popover), model);
return popover;
}
void
gtk_popover_menu_set_menu_model (GtkPopoverMenu *popover,
GMenuModel *model)
{
g_return_if_fail (GTK_IS_POPOVER_MENU (popover));
g_return_if_fail (model == NULL || G_IS_MENU_MODEL (model));
if (g_set_object (&popover->model, model))
{
GtkWidget *stack;
GtkWidget *child;
stack = gtk_bin_get_child (GTK_BIN (popover));
while ((child = gtk_widget_get_first_child (stack)))
gtk_widget_destroy (child);
if (model)
gtk_menu_section_box_new_toplevel (popover, model, popover->flags);
g_object_notify (G_OBJECT (popover), "menu-model");
}
}
GMenuModel *
gtk_popover_menu_get_menu_model (GtkPopoverMenu *popover)
{
g_return_val_if_fail (GTK_IS_POPOVER_MENU (popover), NULL);
return popover->model;
}

View File

@ -35,9 +35,6 @@ typedef struct _GtkPopoverMenu GtkPopoverMenu;
GDK_AVAILABLE_IN_ALL
GType gtk_popover_menu_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_popover_menu_new (GtkWidget *relative_to);
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_popover_menu_new_from_model (GtkWidget *relative_to,
GMenuModel *model);
@ -61,12 +58,10 @@ GtkWidget * gtk_popover_menu_new_from_model_full (GtkWidget *relative_
GtkPopoverMenuFlags flags);
GDK_AVAILABLE_IN_ALL
void gtk_popover_menu_add_submenu (GtkPopoverMenu *popover,
GtkWidget *submenu,
const char *name);
void gtk_popover_menu_set_menu_model (GtkPopoverMenu *popover,
GMenuModel *model);
GDK_AVAILABLE_IN_ALL
void gtk_popover_menu_open_submenu (GtkPopoverMenu *popover,
const char *name);
GMenuModel *gtk_popover_menu_get_menu_model (GtkPopoverMenu *popover);
G_END_DECLS

View File

@ -533,7 +533,7 @@ gtk_popover_menu_bar_init (GtkPopoverMenuBar *bar)
/**
* gtk_popover_menu_bar_new_from_model:
* @model: a #GMenuModel
* @model: (allow-none): a #GMenuModel, or %NULL
*
* Creates a #GtkPopoverMenuBar from a #GMenuModel.
*
@ -550,7 +550,7 @@ gtk_popover_menu_bar_new_from_model (GMenuModel *model)
/**
* gtk_popover_menu_bar_set_menu_model:
* @bar: a #GtkPopoverMenuBar
* @model: a #GMenuModel
* @model: (allow-none): a #GMenuModel, or %NULL
*
* Sets a menu model from which @bar should take
* its contents.
@ -572,16 +572,19 @@ gtk_popover_menu_bar_set_menu_model (GtkPopoverMenuBar *bar,
g_clear_pointer (&bar->tracker, gtk_menu_tracker_free);
muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (bar), TRUE);
bar->tracker = gtk_menu_tracker_new (GTK_ACTION_OBSERVABLE (muxer),
model,
FALSE,
TRUE,
FALSE,
NULL,
tracker_insert,
tracker_remove,
bar);
if (model)
{
muxer = _gtk_widget_get_action_muxer (GTK_WIDGET (bar), TRUE);
bar->tracker = gtk_menu_tracker_new (GTK_ACTION_OBSERVABLE (muxer),
model,
FALSE,
TRUE,
FALSE,
NULL,
tracker_insert,
tracker_remove,
bar);
}
g_object_notify_by_pspec (G_OBJECT (bar), bar_props[PROP_MENU_MODEL]);
}

View File

@ -32,6 +32,14 @@ GtkWidget *gtk_popover_menu_get_parent_menu (GtkPopoverMenu *menu);
void gtk_popover_menu_set_parent_menu (GtkPopoverMenu *menu,
GtkWidget *parent);
GtkWidget * gtk_popover_menu_new (GtkWidget *relative_to);
void gtk_popover_menu_add_submenu (GtkPopoverMenu *popover,
GtkWidget *submenu,
const char *name);
void gtk_popover_menu_open_submenu (GtkPopoverMenu *popover,
const gchar *name);
G_END_DECLS
#endif /* __GTK_POPOVER_PRIVATE_H__ */
#endif /* __GTK_POPOVER_MENU_PRIVATE_H__ */

View File

@ -48,8 +48,8 @@
#include "gtkorientable.h"
#include "gtkorientableprivate.h"
#include "gtkprivate.h"
#include "gtkpopovermenu.h"
#include "gtkmodelbutton.h"
#include "gtkpopovermenuprivate.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkseparator.h"
#include "gtkradiomenuitem.h"
#include "gtkcheckmenuitem.h"

View File

@ -59,9 +59,8 @@
#include "gtkmenubarprivate.h"
#include "gtkmenushellprivate.h"
#include "gtkpointerfocusprivate.h"
#include "gtkpopoverprivate.h"
#include "gtkpopovermenu.h"
#include "gtkmodelbutton.h"
#include "gtkpopovermenuprivate.h"
#include "gtkmodelbuttonprivate.h"
#include "gtkseparator.h"
#include "gtkprivate.h"
#include "gtkroot.h"

View File

@ -40,7 +40,6 @@
#include "gtktreeview.h"
#include "gtktreeselection.h"
#include "gtktypebuiltins.h"
#include "gtkmodelbutton.h"
#include "gtkstack.h"
#include <glib/gi18n-lib.h>

View File

@ -552,7 +552,6 @@ gtk_public_headers = files([
'gtkmenushell.h',
'gtkmenutoolbutton.h',
'gtkmessagedialog.h',
'gtkmodelbutton.h',
'gtkmountoperation.h',
'gtknative.h',
'gtknativedialog.h',

View File

@ -1,4 +1,5 @@
#include <gtk/gtk.h>
#include "gtk/gtkmodelbuttonprivate.h"
static void
on_action_beep (GSimpleAction *action,
@ -46,7 +47,7 @@ on_application_activate (GApplication *gapplication,
gicon = g_themed_icon_new ("face-smile");
model_button = g_object_new (GTK_TYPE_MODEL_BUTTON,
model_button = g_object_new (g_type_from_name ("GtkModelButton"),
"action-name", "app.beep",
"text", "Its-a-me! ModelButton",
"icon", gicon,

View File

@ -592,10 +592,6 @@ test_type (gconstpointer data)
g_str_equal (pspec->name, "use-header-bar"))
continue;
if (type == GTK_TYPE_MODEL_BUTTON &&
pspec->owner_type == GTK_TYPE_BUTTON)
continue;
if (g_type_is_a (type, GTK_TYPE_SHORTCUTS_SHORTCUT) &&
g_str_equal (pspec->name, "accelerator"))
continue;