GtkStatusbar: Define children with a GtkBuilder template
This commit is contained in:
@ -1102,7 +1102,8 @@ COMPOSITE_TEMPLATES = \
|
|||||||
gtkinfobar.ui \
|
gtkinfobar.ui \
|
||||||
gtklockbutton.ui \
|
gtklockbutton.ui \
|
||||||
gtkmessagedialog.ui \
|
gtkmessagedialog.ui \
|
||||||
gtkscalebutton.ui
|
gtkscalebutton.ui \
|
||||||
|
gtkstatusbar.ui
|
||||||
|
|
||||||
#
|
#
|
||||||
# rules to generate built sources
|
# rules to generate built sources
|
||||||
|
@ -18,5 +18,6 @@
|
|||||||
<file compressed="true">gtklockbutton.ui</file>
|
<file compressed="true">gtklockbutton.ui</file>
|
||||||
<file compressed="true">gtkmessagedialog.ui</file>
|
<file compressed="true">gtkmessagedialog.ui</file>
|
||||||
<file compressed="true">gtkscalebutton.ui</file>
|
<file compressed="true">gtkscalebutton.ui</file>
|
||||||
|
<file compressed="true">gtkstatusbar.ui</file>
|
||||||
</gresource>
|
</gresource>
|
||||||
</gresources>
|
</gresources>
|
||||||
|
@ -34,7 +34,6 @@
|
|||||||
#include "gtkwindow.h"
|
#include "gtkwindow.h"
|
||||||
#include "gtkprivate.h"
|
#include "gtkprivate.h"
|
||||||
#include "gtkintl.h"
|
#include "gtkintl.h"
|
||||||
#include "gtkbuildable.h"
|
|
||||||
#include "gtkorientable.h"
|
#include "gtkorientable.h"
|
||||||
#include "gtktypebuiltins.h"
|
#include "gtktypebuiltins.h"
|
||||||
#include "a11y/gtkstatusbaraccessible.h"
|
#include "a11y/gtkstatusbaraccessible.h"
|
||||||
@ -80,6 +79,7 @@ struct _GtkStatusbarPrivate
|
|||||||
{
|
{
|
||||||
GtkWidget *frame;
|
GtkWidget *frame;
|
||||||
GtkWidget *label;
|
GtkWidget *label;
|
||||||
|
GtkWidget *message_area;
|
||||||
|
|
||||||
GSList *messages;
|
GSList *messages;
|
||||||
GSList *keys;
|
GSList *keys;
|
||||||
@ -103,10 +103,6 @@ enum
|
|||||||
SIGNAL_LAST
|
SIGNAL_LAST
|
||||||
};
|
};
|
||||||
|
|
||||||
static void gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface);
|
|
||||||
static GObject *gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
|
|
||||||
GtkBuilder *builder,
|
|
||||||
const gchar *childname);
|
|
||||||
static void gtk_statusbar_update (GtkStatusbar *statusbar,
|
static void gtk_statusbar_update (GtkStatusbar *statusbar,
|
||||||
guint context_id,
|
guint context_id,
|
||||||
const gchar *text);
|
const gchar *text);
|
||||||
@ -120,16 +116,12 @@ static void gtk_statusbar_hierarchy_changed (GtkWidget *widget,
|
|||||||
|
|
||||||
static guint statusbar_signals[SIGNAL_LAST] = { 0 };
|
static guint statusbar_signals[SIGNAL_LAST] = { 0 };
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (GtkStatusbar, gtk_statusbar, GTK_TYPE_BOX,
|
G_DEFINE_TYPE (GtkStatusbar, gtk_statusbar, GTK_TYPE_BOX);
|
||||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE,
|
|
||||||
gtk_statusbar_buildable_interface_init));
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_statusbar_class_init (GtkStatusbarClass *class)
|
gtk_statusbar_class_init (GtkStatusbarClass *class)
|
||||||
{
|
{
|
||||||
GtkWidgetClass *widget_class;
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
||||||
|
|
||||||
widget_class = (GtkWidgetClass *) class;
|
|
||||||
|
|
||||||
widget_class->realize = gtk_statusbar_realize;
|
widget_class->realize = gtk_statusbar_realize;
|
||||||
widget_class->destroy = gtk_statusbar_destroy;
|
widget_class->destroy = gtk_statusbar_destroy;
|
||||||
@ -185,17 +177,22 @@ gtk_statusbar_class_init (GtkStatusbarClass *class)
|
|||||||
GTK_SHADOW_IN,
|
GTK_SHADOW_IN,
|
||||||
GTK_PARAM_READABLE));
|
GTK_PARAM_READABLE));
|
||||||
|
|
||||||
g_type_class_add_private (class, sizeof (GtkStatusbarPrivate));
|
/* Bind class to template
|
||||||
|
*/
|
||||||
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkstatusbar.ui");
|
||||||
|
gtk_widget_class_bind_child_internal (widget_class, GtkStatusbarPrivate, message_area);
|
||||||
|
gtk_widget_class_bind_child (widget_class, GtkStatusbarPrivate, frame);
|
||||||
|
gtk_widget_class_bind_child (widget_class, GtkStatusbarPrivate, label);
|
||||||
|
|
||||||
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_STATUSBAR_ACCESSIBLE);
|
g_type_class_add_private (class, sizeof (GtkStatusbarPrivate));
|
||||||
|
|
||||||
|
gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_STATUSBAR_ACCESSIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_statusbar_init (GtkStatusbar *statusbar)
|
gtk_statusbar_init (GtkStatusbar *statusbar)
|
||||||
{
|
{
|
||||||
GtkStatusbarPrivate *priv;
|
GtkStatusbarPrivate *priv;
|
||||||
GtkBox *box = GTK_BOX (statusbar);
|
|
||||||
GtkWidget *message_area;
|
|
||||||
GtkShadowType shadow_type;
|
GtkShadowType shadow_type;
|
||||||
|
|
||||||
statusbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (statusbar,
|
statusbar->priv = G_TYPE_INSTANCE_GET_PRIVATE (statusbar,
|
||||||
@ -203,59 +200,16 @@ gtk_statusbar_init (GtkStatusbar *statusbar)
|
|||||||
GtkStatusbarPrivate);
|
GtkStatusbarPrivate);
|
||||||
priv = statusbar->priv;
|
priv = statusbar->priv;
|
||||||
|
|
||||||
gtk_widget_set_redraw_on_allocate (GTK_WIDGET (box), TRUE);
|
|
||||||
|
|
||||||
gtk_box_set_spacing (box, 2);
|
|
||||||
gtk_box_set_homogeneous (box, FALSE);
|
|
||||||
|
|
||||||
gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
|
|
||||||
|
|
||||||
priv->frame = gtk_frame_new (NULL);
|
|
||||||
gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), shadow_type);
|
|
||||||
gtk_box_pack_start (box, priv->frame, TRUE, TRUE, 0);
|
|
||||||
gtk_widget_show (priv->frame);
|
|
||||||
|
|
||||||
message_area = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
|
||||||
gtk_container_add (GTK_CONTAINER (priv->frame), message_area);
|
|
||||||
gtk_widget_show (message_area);
|
|
||||||
|
|
||||||
priv->label = gtk_label_new ("");
|
|
||||||
gtk_label_set_single_line_mode (GTK_LABEL (priv->label), TRUE);
|
|
||||||
gtk_widget_set_halign (priv->label, GTK_ALIGN_START);
|
|
||||||
gtk_widget_set_valign (priv->label, GTK_ALIGN_CENTER);
|
|
||||||
gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_END);
|
|
||||||
gtk_container_add (GTK_CONTAINER (message_area), priv->label);
|
|
||||||
gtk_widget_show (priv->label);
|
|
||||||
|
|
||||||
priv->seq_context_id = 1;
|
priv->seq_context_id = 1;
|
||||||
priv->seq_message_id = 1;
|
priv->seq_message_id = 1;
|
||||||
priv->messages = NULL;
|
priv->messages = NULL;
|
||||||
priv->keys = NULL;
|
priv->keys = NULL;
|
||||||
}
|
|
||||||
|
|
||||||
static GtkBuildableIface *parent_buildable_iface;
|
gtk_widget_init_template (GTK_WIDGET (statusbar));
|
||||||
|
|
||||||
static void
|
gtk_widget_set_redraw_on_allocate (GTK_WIDGET (statusbar), TRUE);
|
||||||
gtk_statusbar_buildable_interface_init (GtkBuildableIface *iface)
|
gtk_widget_style_get (GTK_WIDGET (statusbar), "shadow-type", &shadow_type, NULL);
|
||||||
{
|
gtk_frame_set_shadow_type (GTK_FRAME (priv->frame), shadow_type);
|
||||||
parent_buildable_iface = g_type_interface_peek_parent (iface);
|
|
||||||
iface->get_internal_child = gtk_statusbar_buildable_get_internal_child;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GObject *
|
|
||||||
gtk_statusbar_buildable_get_internal_child (GtkBuildable *buildable,
|
|
||||||
GtkBuilder *builder,
|
|
||||||
const gchar *childname)
|
|
||||||
{
|
|
||||||
GtkStatusbar *statusbar = GTK_STATUSBAR (buildable);
|
|
||||||
GtkStatusbarPrivate *priv = statusbar->priv;
|
|
||||||
|
|
||||||
if (strcmp (childname, "message_area") == 0)
|
|
||||||
return G_OBJECT (gtk_bin_get_child (GTK_BIN (priv->frame)));
|
|
||||||
|
|
||||||
return parent_buildable_iface->get_internal_child (buildable,
|
|
||||||
builder,
|
|
||||||
childname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -580,7 +534,7 @@ gtk_statusbar_get_message_area (GtkStatusbar *statusbar)
|
|||||||
|
|
||||||
priv = statusbar->priv;
|
priv = statusbar->priv;
|
||||||
|
|
||||||
return gtk_bin_get_child (GTK_BIN (priv->frame));
|
return priv->message_area;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
50
gtk/gtkstatusbar.ui
Normal file
50
gtk/gtkstatusbar.ui
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<interface domain="gtk30">
|
||||||
|
<!-- interface-requires gtk+ 3.10 -->
|
||||||
|
<template class="GtkStatusbar" parent="GtkBox">
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="vexpand">False</property>
|
||||||
|
<property name="spacing">2</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkFrame" id="frame">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="label_xalign">0</property>
|
||||||
|
<property name="shadow_type">none</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkBox" id="message_area">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="spacing">4</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkLabel" id="label">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">False</property>
|
||||||
|
<property name="halign">start</property>
|
||||||
|
<property name="valign">center</property>
|
||||||
|
<property name="ellipsize">end</property>
|
||||||
|
<property name="single_line_mode">True</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
</child>
|
||||||
|
<child type="label_item">
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
|
</template>
|
||||||
|
</interface>
|
@ -109,6 +109,16 @@ test_scale_button_basic (void)
|
|||||||
gtk_widget_destroy (widget);
|
gtk_widget_destroy (widget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_statusbar_basic (void)
|
||||||
|
{
|
||||||
|
GtkWidget *widget;
|
||||||
|
|
||||||
|
widget = gtk_statusbar_new ();
|
||||||
|
g_assert (GTK_IS_STATUSBAR (widget));
|
||||||
|
gtk_widget_destroy (widget);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -129,6 +139,7 @@ main (int argc, char **argv)
|
|||||||
g_test_add_func ("/Template/GtkLockButton/Basic", test_lock_button_basic);
|
g_test_add_func ("/Template/GtkLockButton/Basic", test_lock_button_basic);
|
||||||
g_test_add_func ("/Template/GtkAssistant/Basic", test_assistant_basic);
|
g_test_add_func ("/Template/GtkAssistant/Basic", test_assistant_basic);
|
||||||
g_test_add_func ("/Template/GtkScaleButton/Basic", test_scale_button_basic);
|
g_test_add_func ("/Template/GtkScaleButton/Basic", test_scale_button_basic);
|
||||||
|
g_test_add_func ("/Template/GtkStatusBar/Basic", test_statusbar_basic);
|
||||||
|
|
||||||
return g_test_run();
|
return g_test_run();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user