Merge branch 'child-properties-be-gone' into 'master'

Child properties be gone

See merge request GNOME/gtk!715
This commit is contained in:
Matthias Clasen 2019-04-05 12:27:24 +00:00
commit d89df8a980
22 changed files with 112 additions and 1761 deletions

View File

@ -27,10 +27,16 @@ toggle_resize (GtkWidget *widget,
is_child1 = (child == gtk_paned_get_child1 (paned));
gtk_container_child_get (GTK_CONTAINER (paned), child,
"resize", &resize,
"shrink", &shrink,
NULL);
if (is_child1)
g_object_get (paned,
"resize-child1", &resize,
"shrink-child1", &shrink,
NULL);
else
g_object_get (paned,
"resize-child2", &resize,
"shrink-child2", &shrink,
NULL);
g_object_ref (child);
gtk_container_remove (GTK_CONTAINER (parent), child);
@ -55,10 +61,16 @@ toggle_shrink (GtkWidget *widget,
is_child1 = (child == gtk_paned_get_child1 (paned));
gtk_container_child_get (GTK_CONTAINER (paned), child,
"resize", &resize,
"shrink", &shrink,
NULL);
if (is_child1)
g_object_get (paned,
"resize-child1", &resize,
"shrink-child1", &shrink,
NULL);
else
g_object_get (paned,
"resize-child2", &resize,
"shrink-child2", &shrink,
NULL);
g_object_ref (child);
gtk_container_remove (GTK_CONTAINER (parent), child);

View File

@ -236,10 +236,7 @@ puzzle_button_pressed (GtkGestureMultiPress *gesture,
return;
}
gtk_container_child_get (GTK_CONTAINER (grid), child,
"left-attach", &l,
"top-attach", &t,
NULL);
gtk_grid_query_child (GTK_GRID (grid), child, &l, &t, NULL, NULL);
if (l == pos_x && t == pos_y)
{

View File

@ -744,10 +744,8 @@ gtk_combo_box_text_get_type
<TITLE>GtkContainer</TITLE>
GtkContainer
GtkContainerClass
GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID
gtk_container_add
gtk_container_remove
gtk_container_add_with_properties
gtk_container_foreach
gtk_container_get_children
gtk_container_get_path_for_child
@ -756,19 +754,7 @@ gtk_container_set_focus_vadjustment
gtk_container_get_focus_hadjustment
gtk_container_set_focus_hadjustment
gtk_container_child_type
gtk_container_child_get
gtk_container_child_set
gtk_container_child_get_property
gtk_container_child_set_property
gtk_container_child_get_valist
gtk_container_child_set_valist
gtk_container_child_notify
gtk_container_child_notify_by_pspec
gtk_container_forall
gtk_container_class_find_child_property
gtk_container_class_install_child_property
gtk_container_class_install_child_properties
gtk_container_class_list_child_properties
<SUBSECTION Standard>
GTK_CONTAINER
@ -4485,8 +4471,6 @@ gtk_widget_class_set_accessible_type
gtk_widget_class_set_accessible_role
gtk_widget_get_accessible
gtk_widget_child_focus
gtk_widget_child_notify
gtk_widget_freeze_child_notify
gtk_widget_get_child_visible
gtk_widget_get_parent
gtk_widget_get_settings
@ -4496,7 +4480,6 @@ gtk_widget_get_display
gtk_widget_get_size_request
gtk_widget_set_child_visible
gtk_widget_set_size_request
gtk_widget_thaw_child_notify
gtk_widget_list_mnemonic_labels
gtk_widget_add_mnemonic_label
gtk_widget_remove_mnemonic_label

File diff suppressed because it is too large Load Diff

View File

@ -83,16 +83,6 @@ struct _GtkContainerClass
void (*set_focus_child) (GtkContainer *container,
GtkWidget *child);
GType (*child_type) (GtkContainer *container);
void (*set_child_property) (GtkContainer *container,
GtkWidget *child,
guint property_id,
const GValue *value,
GParamSpec *pspec);
void (*get_child_property) (GtkContainer *container,
GtkWidget *child,
guint property_id,
GValue *value,
GParamSpec *pspec);
GtkWidgetPath * (*get_path_for_child) (GtkContainer *container,
GtkWidget *child);
@ -145,81 +135,6 @@ GtkAdjustment *gtk_container_get_focus_hadjustment (GtkContainer *container);
GDK_AVAILABLE_IN_ALL
GType gtk_container_child_type (GtkContainer *container);
GDK_AVAILABLE_IN_ALL
void gtk_container_class_install_child_property (GtkContainerClass *cclass,
guint property_id,
GParamSpec *pspec);
GDK_AVAILABLE_IN_ALL
void gtk_container_class_install_child_properties (GtkContainerClass *cclass,
guint n_pspecs,
GParamSpec **pspecs);
GDK_AVAILABLE_IN_ALL
GParamSpec* gtk_container_class_find_child_property (GObjectClass *cclass,
const gchar *property_name);
GDK_AVAILABLE_IN_ALL
GParamSpec** gtk_container_class_list_child_properties (GObjectClass *cclass,
guint *n_properties);
GDK_AVAILABLE_IN_ALL
void gtk_container_add_with_properties (GtkContainer *container,
GtkWidget *widget,
const gchar *first_prop_name,
...) G_GNUC_NULL_TERMINATED;
GDK_AVAILABLE_IN_ALL
void gtk_container_child_set (GtkContainer *container,
GtkWidget *child,
const gchar *first_prop_name,
...) G_GNUC_NULL_TERMINATED;
GDK_AVAILABLE_IN_ALL
void gtk_container_child_get (GtkContainer *container,
GtkWidget *child,
const gchar *first_prop_name,
...) G_GNUC_NULL_TERMINATED;
GDK_AVAILABLE_IN_ALL
void gtk_container_child_set_valist (GtkContainer *container,
GtkWidget *child,
const gchar *first_property_name,
va_list var_args);
GDK_AVAILABLE_IN_ALL
void gtk_container_child_get_valist (GtkContainer *container,
GtkWidget *child,
const gchar *first_property_name,
va_list var_args);
GDK_AVAILABLE_IN_ALL
void gtk_container_child_set_property (GtkContainer *container,
GtkWidget *child,
const gchar *property_name,
const GValue *value);
GDK_AVAILABLE_IN_ALL
void gtk_container_child_get_property (GtkContainer *container,
GtkWidget *child,
const gchar *property_name,
GValue *value);
GDK_AVAILABLE_IN_ALL
void gtk_container_child_notify (GtkContainer *container,
GtkWidget *child,
const gchar *child_property);
GDK_AVAILABLE_IN_ALL
void gtk_container_child_notify_by_pspec (GtkContainer *container,
GtkWidget *child,
GParamSpec *pspec);
/**
* GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID:
* @object: the #GObject on which set_child_property() or get_child_property()
* was called
* @property_id: the numeric id of the property
* @pspec: the #GParamSpec of the property
*
* This macro should be used to emit a standard warning about unexpected
* properties in set_child_property() and get_child_property() implementations.
*/
#define GTK_CONTAINER_WARN_INVALID_CHILD_PROPERTY_ID(object, property_id, pspec) \
G_OBJECT_WARN_INVALID_PSPEC ((object), "child property", (property_id), (pspec))
GDK_AVAILABLE_IN_ALL
void gtk_container_forall (GtkContainer *container,
GtkCallback callback,

View File

@ -1080,10 +1080,10 @@ gtk_grid_get_baseline_row (GtkGrid *grid)
* gtk_grid_query_child:
* @grid: a #GtkGrid
* @child: a #GtkWidget child of @grid
* @left: (out): the column used to attach the left side of @child
* @top: (out): the row used to attach the top side of @child
* @width: (out): the number of columns @child spans
* @height: (out): the number of rows @child spans
* @left: (out) (optional): the column used to attach the left side of @child
* @top: (out) (optional): the row used to attach the top side of @child
* @width: (out) (optional): the number of columns @child spans
* @height: (out) (optiona): the number of rows @child spans
*
* Queries the attach points and spans of @child inside the given #GtkGrid.
*/

View File

@ -3378,6 +3378,7 @@ do_detach_tab (GtkNotebook *from,
gboolean tab_expand, tab_fill, reorderable, detachable;
GList *element;
gint page_num;
GtkNotebookPage *page;
menu_label = gtk_notebook_get_menu_label (from, child);
@ -3391,13 +3392,13 @@ do_detach_tab (GtkNotebook *from,
g_object_ref (child);
gtk_container_child_get (GTK_CONTAINER (from),
child,
"tab-expand", &tab_expand,
"tab-fill", &tab_fill,
"reorderable", &reorderable,
"detachable", &detachable,
NULL);
page = gtk_notebook_get_page (from, child);
g_object_get (page,
"tab-expand", &tab_expand,
"tab-fill", &tab_fill,
"reorderable", &reorderable,
"detachable", &detachable,
NULL);
gtk_notebook_detach_tab (from, child);
@ -3405,12 +3406,14 @@ do_detach_tab (GtkNotebook *from,
page_num = g_list_position (to_priv->children, element);
gtk_notebook_insert_page_menu (to, child, tab_label, menu_label, page_num);
gtk_container_child_set (GTK_CONTAINER (to), child,
"tab-expand", tab_expand,
"tab-fill", tab_fill,
"reorderable", reorderable,
"detachable", detachable,
NULL);
page = gtk_notebook_get_page (to, child);
g_object_set (page,
"tab-expand", tab_expand,
"tab-fill", tab_fill,
"reorderable", reorderable,
"detachable", detachable,
NULL);
if (child)
g_object_unref (child);

View File

@ -174,12 +174,6 @@ enum {
PROP_ORIENTATION,
};
enum {
CHILD_PROP_0,
CHILD_PROP_RESIZE,
CHILD_PROP_SHRINK
};
enum {
CYCLE_CHILD_FOCUS,
TOGGLE_HANDLE_FOCUS,

View File

@ -1359,17 +1359,14 @@ add_option_to_extension_point (GtkPrinterOption *option,
static gint
grid_rows (GtkGrid *table)
{
gint t0, t1, t, h;
gint t0, t1, l, t, w, h;
GList *children, *c;
children = gtk_container_get_children (GTK_CONTAINER (table));
t0 = t1 = 0;
for (c = children; c; c = c->next)
{
gtk_container_child_get (GTK_CONTAINER (table), c->data,
"top-attach", &t,
"height", &h,
NULL);
gtk_grid_query_child (table, c->data, &l, &t, &w, &h);
if (c == children)
{
t0 = t;

View File

@ -627,9 +627,6 @@ static gboolean gtk_widget_real_query_tooltip (GtkWidget *widget,
GtkTooltip *tooltip);
static void gtk_widget_real_style_updated (GtkWidget *widget);
static void gtk_widget_dispatch_child_properties_changed (GtkWidget *object,
guint n_pspecs,
GParamSpec **pspecs);
static gboolean gtk_widget_real_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_widget_real_move_focus (GtkWidget *widget,
@ -689,6 +686,11 @@ static gboolean gtk_widget_buildable_custom_tag_start (GtkBuildable
const gchar *tagname,
GMarkupParser *parser,
gpointer *data);
static void gtk_widget_buildable_custom_tag_end (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const gchar *tagname,
gpointer data);
static void gtk_widget_buildable_custom_finished (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
@ -804,14 +806,6 @@ gtk_widget_base_class_init (gpointer g_class)
klass->priv->template = NULL;
}
static void
child_property_notify_dispatcher (GObject *object,
guint n_pspecs,
GParamSpec **pspecs)
{
GTK_WIDGET_GET_CLASS (object)->dispatch_child_properties_changed (GTK_WIDGET (object), n_pspecs, pspecs);
}
static void
gtk_widget_real_snapshot (GtkWidget *widget,
GtkSnapshot *snapshot)
@ -924,7 +918,6 @@ gtk_widget_real_unroot (GtkWidget *widget)
static void
gtk_widget_class_init (GtkWidgetClass *klass)
{
static GObjectNotifyContext cpn_context = { 0, NULL, NULL };
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkBindingSet *binding_set;
@ -946,11 +939,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
quark_font_options = g_quark_from_static_string ("gtk-widget-font-options");
quark_font_map = g_quark_from_static_string ("gtk-widget-font-map");
_gtk_widget_child_property_pool = g_param_spec_pool_new (TRUE);
cpn_context.quark_notify_queue = g_quark_from_static_string ("GtkWidget-child-property-notify-queue");
cpn_context.dispatcher = child_property_notify_dispatcher;
_gtk_widget_child_property_notify_context = &cpn_context;
gobject_class->constructed = gtk_widget_constructed;
gobject_class->dispose = gtk_widget_dispose;
gobject_class->finalize = gtk_widget_finalize;
@ -960,7 +948,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->destroy = gtk_widget_real_destroy;
klass->activate_signal = 0;
klass->dispatch_child_properties_changed = gtk_widget_dispatch_child_properties_changed;
klass->show = gtk_widget_real_show;
klass->hide = gtk_widget_real_hide;
klass->map = gtk_widget_real_map;
@ -975,7 +962,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->state_flags_changed = gtk_widget_real_state_flags_changed;
klass->direction_changed = gtk_widget_real_direction_changed;
klass->grab_notify = gtk_widget_real_grab_notify;
klass->child_notify = NULL;
klass->snapshot = gtk_widget_real_snapshot;
klass->mnemonic_activate = gtk_widget_real_mnemonic_activate;
klass->grab_focus = gtk_widget_real_grab_focus;
@ -1673,25 +1659,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
G_TYPE_NONE, 1,
G_TYPE_BOOLEAN);
/**
* GtkWidget::child-notify:
* @widget: the object which received the signal
* @child_property: the #GParamSpec of the changed child property
*
* The ::child-notify signal is emitted for each
* [child property][child-properties] that has
* changed on an object. The signal's detail holds the property name.
*/
widget_signals[CHILD_NOTIFY] =
g_signal_new (I_("child-notify"),
G_TYPE_FROM_CLASS (gobject_class),
G_SIGNAL_RUN_FIRST | G_SIGNAL_NO_RECURSE | G_SIGNAL_DETAILED | G_SIGNAL_NO_HOOKS,
G_STRUCT_OFFSET (GtkWidgetClass, child_notify),
NULL, NULL,
g_cclosure_marshal_VOID__PARAM,
G_TYPE_NONE, 1,
G_TYPE_PARAM);
/**
* GtkWidget::mnemonic-activate:
* @widget: the object which received the signal.
@ -2940,98 +2907,6 @@ gtk_widget_init (GTypeInstance *instance, gpointer g_class)
priv->root = (GtkRoot *) widget;
}
static void
gtk_widget_dispatch_child_properties_changed (GtkWidget *widget,
guint n_pspecs,
GParamSpec **pspecs)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GtkWidget *container = priv->parent;
guint i;
for (i = 0; widget->priv->parent == container && i < n_pspecs; i++)
g_signal_emit (widget, widget_signals[CHILD_NOTIFY], g_param_spec_get_name_quark (pspecs[i]), pspecs[i]);
}
/**
* gtk_widget_freeze_child_notify:
* @widget: a #GtkWidget
*
* Stops emission of #GtkWidget::child-notify signals on @widget. The
* signals are queued until gtk_widget_thaw_child_notify() is called
* on @widget.
*
* This is the analogue of g_object_freeze_notify() for child properties.
**/
void
gtk_widget_freeze_child_notify (GtkWidget *widget)
{
g_return_if_fail (GTK_IS_WIDGET (widget));
if (!G_OBJECT (widget)->ref_count)
return;
g_object_ref (widget);
g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
g_object_unref (widget);
}
/**
* gtk_widget_child_notify:
* @widget: a #GtkWidget
* @child_property: the name of a child property installed on the
* class of @widgets parent
*
* Emits a #GtkWidget::child-notify signal for the
* [child property][child-properties] @child_property
* on @widget.
*
* This is the analogue of g_object_notify() for child properties.
*
* Also see gtk_container_child_notify().
*/
void
gtk_widget_child_notify (GtkWidget *widget,
const gchar *child_property)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
if (priv->parent == NULL)
return;
gtk_container_child_notify (GTK_CONTAINER (priv->parent), widget, child_property);
}
/**
* gtk_widget_thaw_child_notify:
* @widget: a #GtkWidget
*
* Reverts the effect of a previous call to gtk_widget_freeze_child_notify().
* This causes all queued #GtkWidget::child-notify signals on @widget to be
* emitted.
*/
void
gtk_widget_thaw_child_notify (GtkWidget *widget)
{
GObjectNotifyQueue *nqueue;
g_return_if_fail (GTK_IS_WIDGET (widget));
if (!G_OBJECT (widget)->ref_count)
return;
g_object_ref (widget);
nqueue = g_object_notify_queue_from_object (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
if (!nqueue || !nqueue->freeze_count)
g_warning (G_STRLOC ": child-property-changed notification for %s(%p) is not frozen",
G_OBJECT_TYPE_NAME (widget), widget);
else
g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
g_object_unref (widget);
}
/**
* gtk_widget_new:
* @type: type ID of the widget to create
@ -3117,7 +2992,6 @@ void
gtk_widget_unparent (GtkWidget *widget)
{
GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
GObjectNotifyQueue *nqueue;
GtkWidget *old_parent;
GtkWidget *old_prev_sibling;
GtkWidget *toplevel;
@ -3132,7 +3006,6 @@ gtk_widget_unparent (GtkWidget *widget)
gtk_widget_push_verify_invariants (widget);
g_object_freeze_notify (G_OBJECT (widget));
nqueue = g_object_notify_queue_freeze (G_OBJECT (widget), _gtk_widget_child_property_notify_context);
toplevel = _gtk_widget_get_toplevel (widget);
if (_gtk_widget_is_toplevel (toplevel))
@ -3221,9 +3094,6 @@ gtk_widget_unparent (GtkWidget *widget)
g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_PARENT]);
g_object_thaw_notify (G_OBJECT (widget));
if (!priv->parent)
g_object_notify_queue_clear (G_OBJECT (widget), nqueue);
g_object_notify_queue_thaw (G_OBJECT (widget), nqueue);
gtk_widget_pop_verify_invariants (widget);
g_object_unref (widget);
@ -9599,6 +9469,7 @@ gtk_widget_buildable_interface_init (GtkBuildableIface *iface)
iface->set_buildable_property = gtk_widget_buildable_set_buildable_property;
iface->parser_finished = gtk_widget_buildable_parser_finished;
iface->custom_tag_start = gtk_widget_buildable_custom_tag_start;
iface->custom_tag_end = gtk_widget_buildable_custom_tag_end;
iface->custom_finished = gtk_widget_buildable_custom_finished;
iface->add_child = gtk_widget_buildable_add_child;
}
@ -10267,6 +10138,15 @@ gtk_widget_buildable_custom_tag_start (GtkBuildable *buildable,
return FALSE;
}
static void
gtk_widget_buildable_custom_tag_end (GtkBuildable *buildable,
GtkBuilder *builder,
GObject *child,
const gchar *tagname,
gpointer data)
{
}
void
_gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
GtkWidget *toplevel,

View File

@ -133,7 +133,6 @@ struct _GtkWidget
* @activate_signal: The signal to emit when a widget of this class is
* activated, gtk_widget_activate() handles the emission.
* Implementation of this signal is optional.
* @dispatch_child_properties_changed: Seldomly overidden.
* @destroy: Signals that all holders of a reference to the widget
* should release the reference that they hold.
* @show: Signal emitted when widget is shown
@ -234,11 +233,6 @@ struct _GtkWidgetClass
guint activate_signal;
/* seldomly overidden */
void (*dispatch_child_properties_changed) (GtkWidget *widget,
guint n_pspecs,
GParamSpec **pspecs);
/* basics */
void (* destroy) (GtkWidget *widget);
void (* show) (GtkWidget *widget);
@ -259,8 +253,6 @@ struct _GtkWidgetClass
GtkTextDirection previous_direction);
void (* grab_notify) (GtkWidget *widget,
gboolean was_grabbed);
void (* child_notify) (GtkWidget *widget,
GParamSpec *child_property);
/* size requests */
GtkSizeRequestMode (* get_request_mode) (GtkWidget *widget);
@ -461,14 +453,6 @@ gboolean gtk_widget_event (GtkWidget *widget,
GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_activate (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
void gtk_widget_freeze_child_notify (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
void gtk_widget_child_notify (GtkWidget *widget,
const gchar *child_property);
GDK_AVAILABLE_IN_ALL
void gtk_widget_thaw_child_notify (GtkWidget *widget);
GDK_AVAILABLE_IN_ALL
void gtk_widget_set_can_focus (GtkWidget *widget,
gboolean can_focus);

View File

@ -331,7 +331,7 @@ get_property_pspec (MyParserData *data,
pspec = g_object_class_find_property (class, canonical_name);
break;
case PROP_KIND_PACKING:
pspec = gtk_container_class_find_child_property (class, canonical_name);
pspec = NULL;
break;
case PROP_KIND_CELL_PACKING:
{

View File

@ -108,11 +108,9 @@ gtk_tests = [
['teststack'],
['testrevealer'],
['testrevealer2'],
['testtitlebar'],
['testtreelistmodel'],
['testsplitheaders'],
['teststackedheaders'],
['testactionbar'],
['testwindowsize'],
['testpopover'],
['gdkgears', ['gtkgears.c']],

View File

@ -1,169 +0,0 @@
#include <gtk/gtk.h>
static void
toggle_center (GtkCheckButton *button,
GParamSpec *pspec,
GtkActionBar *bar)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
{
GtkWidget *button;
button = gtk_button_new_with_label ("Center");
gtk_widget_show (button);
gtk_action_bar_set_center_widget (bar, button);
}
else
{
gtk_action_bar_set_center_widget (bar, NULL);
}
}
static void
toggle_visibility (GtkCheckButton *button,
GParamSpec *pspec,
GtkActionBar *bar)
{
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
gtk_action_bar_set_revealed (bar, TRUE);
else
gtk_action_bar_set_revealed (bar, FALSE);
}
static void
create_widgets (GtkActionBar *bar,
GtkPackType pack_type,
gint n)
{
GList *children, *l;
GtkWidget *child;
gint i;
gchar *label;
children = gtk_container_get_children (GTK_CONTAINER (bar));
for (l = children; l; l = l->next)
{
GtkPackType type;
child = l->data;
if (child == gtk_action_bar_get_center_widget (bar))
continue;
gtk_container_child_get (GTK_CONTAINER (bar), child, "pack-type", &type, NULL);
if (type == pack_type)
gtk_container_remove (GTK_CONTAINER (bar), child);
}
g_list_free (children);
for (i = 0; i < n; i++)
{
label = g_strdup_printf ("%d", i);
child = gtk_button_new_with_label (label);
g_free (label);
gtk_widget_show (child);
if (pack_type == GTK_PACK_START)
gtk_action_bar_pack_start (bar, child);
else
gtk_action_bar_pack_end (bar, child);
}
}
static void
change_start (GtkSpinButton *button,
GParamSpec *pspec,
GtkActionBar *bar)
{
create_widgets (bar,
GTK_PACK_START,
gtk_spin_button_get_value_as_int (button));
}
static void
change_end (GtkSpinButton *button,
GParamSpec *pspec,
GtkActionBar *bar)
{
create_widgets (bar,
GTK_PACK_END,
gtk_spin_button_get_value_as_int (button));
}
static void
activate (GApplication *gapp)
{
GtkApplication *app = GTK_APPLICATION (gapp);
GtkWidget *window;
GtkWidget *box;
GtkWidget *grid;
GtkWidget *label;
GtkWidget *spin;
GtkWidget *check;
GtkWidget *bar;
window = gtk_application_window_new (app);
gtk_application_add_window (app, GTK_WINDOW (window));
bar = gtk_action_bar_new ();
gtk_action_bar_set_revealed (GTK_ACTION_BAR (bar), FALSE);
box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
grid = gtk_grid_new ();
g_object_set (grid,
"halign", GTK_ALIGN_CENTER,
"margin", 20,
"row-spacing", 12,
"column-spacing", 12,
"vexpand", TRUE,
NULL);
gtk_container_add (GTK_CONTAINER (box), grid);
label = gtk_label_new ("Start");
gtk_widget_set_halign (label, GTK_ALIGN_END);
spin = gtk_spin_button_new_with_range (0, 10, 1);
g_signal_connect (spin, "notify::value",
G_CALLBACK (change_start), bar);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), spin, 1, 0, 1, 1);
label = gtk_label_new ("Center");
gtk_widget_set_halign (label, GTK_ALIGN_END);
check = gtk_check_button_new ();
g_signal_connect (check, "notify::active",
G_CALLBACK (toggle_center), bar);
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), check, 1, 1, 1, 1);
label = gtk_label_new ("End");
gtk_widget_set_halign (label, GTK_ALIGN_END);
spin = gtk_spin_button_new_with_range (0, 10, 1);
g_signal_connect (spin, "notify::value",
G_CALLBACK (change_end), bar);
gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
gtk_grid_attach (GTK_GRID (grid), spin, 1, 2, 1, 1);
label = gtk_label_new ("Visible");
gtk_widget_set_halign (label, GTK_ALIGN_END);
check = gtk_check_button_new ();
g_signal_connect (check, "notify::active",
G_CALLBACK (toggle_visibility), bar);
gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
gtk_grid_attach (GTK_GRID (grid), check, 1, 3, 1, 1);
gtk_container_add (GTK_CONTAINER (box), bar);
gtk_container_add (GTK_CONTAINER (window), box);
gtk_widget_show (window);
}
int
main (int argc, char *argv[])
{
GtkApplication *app;
app = gtk_application_new ("org.gtk.Test.ActionBar", 0);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
return g_application_run (G_APPLICATION (app), argc, argv);
}

View File

@ -4025,17 +4025,15 @@ page_switch (GtkWidget *widget, gpointer *page, gint page_num)
static void
tab_fill (GtkToggleButton *button, GtkWidget *child)
{
gtk_container_child_set (GTK_CONTAINER (sample_notebook), child,
"tab-fill", gtk_toggle_button_get_active (button),
NULL);
GtkNotebookPage *page = gtk_notebook_get_page (GTK_NOTEBOOK (sample_notebook), child);
g_object_set (page, "tab-fill", gtk_toggle_button_get_active (button), NULL);
}
static void
tab_expand (GtkToggleButton *button, GtkWidget *child)
{
gtk_container_child_set (GTK_CONTAINER (sample_notebook), child,
"tab-expand", gtk_toggle_button_get_active (button),
NULL);
GtkNotebookPage *page = gtk_notebook_get_page (GTK_NOTEBOOK (sample_notebook), child);
g_object_set (page, "tab-expand", gtk_toggle_button_get_active (button), NULL);
}
static void
@ -4322,23 +4320,29 @@ create_notebook (GtkWidget *widget)
void
toggle_resize (GtkWidget *widget, GtkWidget *child)
{
GtkContainer *container = GTK_CONTAINER (gtk_widget_get_parent (child));
GValue value = G_VALUE_INIT;
g_value_init (&value, G_TYPE_BOOLEAN);
gtk_container_child_get_property (container, child, "resize", &value);
g_value_set_boolean (&value, !g_value_get_boolean (&value));
gtk_container_child_set_property (container, child, "resize", &value);
GtkPaned *paned = GTK_PANED (gtk_widget_get_parent (child));
gboolean is_child1;
gboolean resize;
const char *prop;
is_child1 = (child == gtk_paned_get_child1 (paned));
prop = is_child1 ? "resize-child1" : "resize-child2";
g_object_get (paned, prop, &resize, NULL);
g_object_set (paned, prop, !resize, NULL);
}
void
toggle_shrink (GtkWidget *widget, GtkWidget *child)
{
GtkContainer *container = GTK_CONTAINER (gtk_widget_get_parent (child));
GValue value = G_VALUE_INIT;
g_value_init (&value, G_TYPE_BOOLEAN);
gtk_container_child_get_property (container, child, "shrink", &value);
g_value_set_boolean (&value, !g_value_get_boolean (&value));
gtk_container_child_set_property (container, child, "shrink", &value);
GtkPaned *paned = GTK_PANED (gtk_widget_get_parent (child));
gboolean is_child1;
gboolean resize;
const char *prop;
is_child1 = (child == gtk_paned_get_child1 (paned));
prop = is_child1 ? "shrink-child1" : "shrink-child2";
g_object_get (paned, prop, &resize, NULL);
g_object_set (paned, prop, !resize, NULL);
}
GtkWidget *

View File

@ -1,200 +0,0 @@
#include <gtk/gtk.h>
static void
on_text_changed (GtkEntry *entry,
GParamSpec *pspec,
GtkHeaderBar *bar)
{
const gchar *layout;
layout = gtk_editable_get_text (GTK_EDITABLE (entry));
gtk_header_bar_set_decoration_layout (bar, layout);
}
static void
create_widgets (GtkHeaderBar *bar,
GtkPackType pack_type,
gint n)
{
GList *children, *l;
GtkWidget *child;
gint i;
gchar *label;
children = gtk_container_get_children (GTK_CONTAINER (bar));
for (l = children; l; l = l->next)
{
GtkPackType type;
child = l->data;
gtk_container_child_get (GTK_CONTAINER (bar), child, "pack-type", &type, NULL);
if (type == pack_type)
gtk_container_remove (GTK_CONTAINER (bar), child);
}
g_list_free (children);
for (i = 0; i < n; i++)
{
label = g_strdup_printf ("%d", i);
child = gtk_button_new_with_label (label);
g_free (label);
gtk_widget_show (child);
if (pack_type == GTK_PACK_START)
gtk_header_bar_pack_start (bar, child);
else
gtk_header_bar_pack_end (bar, child);
}
}
static void
change_start (GtkSpinButton *button,
GParamSpec *pspec,
GtkHeaderBar *bar)
{
create_widgets (bar,
GTK_PACK_START,
gtk_spin_button_get_value_as_int (button));
}
static void
change_end (GtkSpinButton *button,
GParamSpec *pspec,
GtkHeaderBar *bar)
{
create_widgets (bar,
GTK_PACK_END,
gtk_spin_button_get_value_as_int (button));
}
static void
activate (GApplication *gapp)
{
GtkApplication *app = GTK_APPLICATION (gapp);
GtkWidget *window;
GtkWidget *header;
GtkWidget *grid;
GtkWidget *label;
GtkWidget *entry;
GtkWidget *check;
GtkWidget *spin;
GtkBuilder *builder;
GMenuModel *menu;
gchar *layout;
g_action_map_add_action (G_ACTION_MAP (gapp), G_ACTION (g_simple_action_new ("test", NULL)));
builder = gtk_builder_new ();
gtk_builder_add_from_string (builder,
"<interface>"
" <menu id='app-menu'>"
" <section>"
" <item>"
" <attribute name='label'>Test item</attribute>"
" <attribute name='action'>app.test</attribute>"
" </item>"
" </section>"
" </menu>"
"</interface>", -1, NULL);
window = gtk_application_window_new (app);
gtk_window_set_icon_name (GTK_WINDOW (window), "preferences-desktop-font");
menu = (GMenuModel*)gtk_builder_get_object (builder, "app-menu");
gtk_application_add_window (app, GTK_WINDOW (window));
gtk_application_set_app_menu (app, menu);
header = gtk_header_bar_new ();
gtk_window_set_titlebar (GTK_WINDOW (window), header);
grid = gtk_grid_new ();
g_object_set (grid,
"halign", GTK_ALIGN_CENTER,
"margin", 20,
"row-spacing", 12,
"column-spacing", 12,
NULL);
label = gtk_label_new ("Title");
gtk_widget_set_halign (label, GTK_ALIGN_END);
entry = gtk_entry_new ();
g_object_bind_property (header, "title",
entry, "text",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), entry, 1, 0, 1, 1);
label = gtk_label_new ("Subtitle");
gtk_widget_set_halign (label, GTK_ALIGN_END);
entry = gtk_entry_new ();
g_object_bind_property (header, "subtitle",
entry, "text",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), entry, 1, 1, 1, 1);
label = gtk_label_new ("Layout");
gtk_widget_set_halign (label, GTK_ALIGN_END);
entry = gtk_entry_new ();
g_object_get (gtk_widget_get_settings (window), "gtk-decoration-layout", &layout, NULL);
gtk_editable_set_text (GTK_EDITABLE (entry), layout);
g_free (layout);
g_signal_connect (entry, "notify::text",
G_CALLBACK (on_text_changed), header);
gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
gtk_grid_attach (GTK_GRID (grid), entry, 1, 2, 1, 1);
label = gtk_label_new ("Decorations");
gtk_widget_set_halign (label, GTK_ALIGN_END);
check = gtk_check_button_new ();
g_object_bind_property (header, "show-title-buttons",
check, "active",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
gtk_grid_attach (GTK_GRID (grid), label, 2, 0, 1, 1);
gtk_grid_attach (GTK_GRID (grid), check, 3, 0, 1, 1);
label = gtk_label_new ("Has Subtitle");
gtk_widget_set_halign (label, GTK_ALIGN_END);
check = gtk_check_button_new ();
g_object_bind_property (header, "has-subtitle",
check, "active",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
gtk_grid_attach (GTK_GRID (grid), label, 2, 1, 1, 1);
gtk_grid_attach (GTK_GRID (grid), check, 3, 1, 1, 1);
label = gtk_label_new ("Shell Shows Menu");
gtk_widget_set_halign (label, GTK_ALIGN_END);
check = gtk_check_button_new ();
g_object_bind_property (gtk_settings_get_default (), "gtk-shell-shows-app-menu",
check, "active",
G_BINDING_BIDIRECTIONAL|G_BINDING_SYNC_CREATE);
gtk_grid_attach (GTK_GRID (grid), label, 2, 2, 1, 1);
gtk_grid_attach (GTK_GRID (grid), check, 3, 2, 1, 1);
label = gtk_label_new ("Custom");
gtk_widget_set_halign (label, GTK_ALIGN_END);
spin = gtk_spin_button_new_with_range (0, 10, 1);
g_signal_connect (spin, "notify::value",
G_CALLBACK (change_start), header);
gtk_grid_attach (GTK_GRID (grid), label, 0, 3, 1, 1);
gtk_grid_attach (GTK_GRID (grid), spin, 1, 3, 1, 1);
spin = gtk_spin_button_new_with_range (0, 10, 1);
g_signal_connect (spin, "notify::value",
G_CALLBACK (change_end), header);
gtk_grid_attach (GTK_GRID (grid), spin, 2, 3, 2, 1);
gtk_container_add (GTK_CONTAINER (window), grid);
gtk_widget_show (window);
}
int
main (int argc, char *argv[])
{
GtkApplication *app;
app = gtk_application_new ("org.gtk.Test.titlebar", 0);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
return g_application_run (G_APPLICATION (app), argc, argv);
}

View File

@ -1,2 +0,0 @@
ERROR: g-markup-error-quark 6
.:7:32 element 'property' requires attribute 'name'

View File

@ -1,11 +0,0 @@
<!-- invalid child property attribute -->
<interface>
<object class="GtkBox">
<child>
<object class="GtkLabel" id="widget1"/>
<packing>
<property food="good"/>
</packing>
</child>
</object>
</interface>

View File

@ -1,2 +0,0 @@
ERROR: gtk-builder-error-quark 1
.:7:17 Unsupported tag for GtkContainer: <warbl>

View File

@ -1,11 +0,0 @@
<!-- invalid packing element -->
<interface>
<object class="GtkBox">
<child>
<object class="GtkLabel" id="widget1"/>
<packing>
<warbl/>
</packing>
</child>
</object>
</interface>

View File

@ -1,2 +0,0 @@
ERROR: g-markup-error-quark 4
.:7:1 attribute 'try' invalid for element 'packing'

View File

@ -1,10 +0,0 @@
<!-- invalid container packing attribute -->
<interface>
<object class="GtkBox">
<child>
<object class="GtkLabel" id="widget1"/>
<packing try="this">
</packing>
</child>
</object>
</interface>