forked from AuroraMiddleware/gtk
GtkFontButton: Define children with a GtkBuilder template
This commit is contained in:
parent
4c81151a20
commit
36bacc4674
@ -1106,6 +1106,7 @@ COMPOSITE_TEMPLATES = \
|
||||
gtkfilechooserbutton.ui \
|
||||
gtkfilechooserdefault.ui \
|
||||
gtkfilechooserdialog.ui \
|
||||
gtkfontbutton.ui \
|
||||
gtkfontchooserdialog.ui \
|
||||
gtkfontchooserwidget.ui \
|
||||
gtkinfobar.ui \
|
||||
|
@ -21,6 +21,7 @@
|
||||
<file compressed="true">gtkfilechooserbutton.ui</file>
|
||||
<file compressed="true">gtkfilechooserdefault.ui</file>
|
||||
<file compressed="true">gtkfilechooserdialog.ui</file>
|
||||
<file compressed="true">gtkfontbutton.ui</file>
|
||||
<file compressed="true">gtkfontchooserdialog.ui</file>
|
||||
<file compressed="true">gtkfontchooserwidget.ui</file>
|
||||
<file compressed="true">gtkinfobar.ui</file>
|
||||
|
@ -70,9 +70,9 @@ struct _GtkFontButtonPrivate
|
||||
guint show_preview_entry : 1;
|
||||
|
||||
GtkWidget *font_dialog;
|
||||
GtkWidget *inside;
|
||||
GtkWidget *font_label;
|
||||
GtkWidget *size_label;
|
||||
GtkWidget *font_size_box;
|
||||
|
||||
PangoFontDescription *font_desc;
|
||||
PangoFontFamily *font_family;
|
||||
@ -123,7 +123,6 @@ static void dialog_destroy (GtkWidget *widget,
|
||||
gpointer data);
|
||||
|
||||
/* Auxiliary functions */
|
||||
static GtkWidget *gtk_font_button_create_inside (GtkFontButton *gfs);
|
||||
static void gtk_font_button_label_use_font (GtkFontButton *gfs);
|
||||
static void gtk_font_button_update_font_info (GtkFontButton *gfs);
|
||||
|
||||
@ -406,9 +405,11 @@ static void
|
||||
gtk_font_button_class_init (GtkFontButtonClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
GtkWidgetClass *widget_class;
|
||||
GtkButtonClass *button_class;
|
||||
|
||||
gobject_class = (GObjectClass *) klass;
|
||||
widget_class = (GtkWidgetClass *) klass;
|
||||
button_class = (GtkButtonClass *) klass;
|
||||
|
||||
gobject_class->finalize = gtk_font_button_finalize;
|
||||
@ -539,6 +540,13 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
|
||||
NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
/* Bind class to template
|
||||
*/
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkfontbutton.ui");
|
||||
gtk_widget_class_bind_child (widget_class, GtkFontButtonPrivate, font_label);
|
||||
gtk_widget_class_bind_child (widget_class, GtkFontButtonPrivate, size_label);
|
||||
gtk_widget_class_bind_child (widget_class, GtkFontButtonPrivate, font_size_box);
|
||||
|
||||
g_type_class_add_private (gobject_class, sizeof (GtkFontButtonPrivate));
|
||||
}
|
||||
@ -562,8 +570,7 @@ gtk_font_button_init (GtkFontButton *font_button)
|
||||
font_button->priv->font_size = -1;
|
||||
font_button->priv->title = g_strdup (_("Pick a Font"));
|
||||
|
||||
font_button->priv->inside = gtk_font_button_create_inside (font_button);
|
||||
gtk_container_add (GTK_CONTAINER (font_button), font_button->priv->inside);
|
||||
gtk_widget_init_template (GTK_WIDGET (font_button));
|
||||
|
||||
gtk_font_button_take_font_desc (font_button, NULL);
|
||||
}
|
||||
@ -928,9 +935,10 @@ gtk_font_button_set_show_size (GtkFontButton *font_button,
|
||||
{
|
||||
font_button->priv->show_size = show_size;
|
||||
|
||||
gtk_container_remove (GTK_CONTAINER (font_button), font_button->priv->inside);
|
||||
font_button->priv->inside = gtk_font_button_create_inside (font_button);
|
||||
gtk_container_add (GTK_CONTAINER (font_button), font_button->priv->inside);
|
||||
if (font_button->priv->show_size)
|
||||
gtk_widget_show (font_button->priv->font_size_box);
|
||||
else
|
||||
gtk_widget_hide (font_button->priv->font_size_box);
|
||||
|
||||
gtk_font_button_update_font_info (font_button);
|
||||
|
||||
@ -1109,31 +1117,6 @@ dialog_destroy (GtkWidget *widget,
|
||||
font_button->priv->font_dialog = NULL;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
gtk_font_button_create_inside (GtkFontButton *font_button)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
|
||||
widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
||||
|
||||
font_button->priv->font_label = gtk_label_new (_("Font"));
|
||||
|
||||
gtk_label_set_justify (GTK_LABEL (font_button->priv->font_label), GTK_JUSTIFY_LEFT);
|
||||
gtk_box_pack_start (GTK_BOX (widget), font_button->priv->font_label, TRUE, TRUE, 5);
|
||||
|
||||
if (font_button->priv->show_size)
|
||||
{
|
||||
gtk_box_pack_start (GTK_BOX (widget), gtk_separator_new (GTK_ORIENTATION_VERTICAL), FALSE, FALSE, 0);
|
||||
font_button->priv->size_label = gtk_label_new ("14");
|
||||
gtk_box_pack_start (GTK_BOX (widget), font_button->priv->size_label, FALSE, FALSE, 5);
|
||||
}
|
||||
|
||||
gtk_widget_show_all (widget);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_font_button_label_use_font (GtkFontButton *font_button)
|
||||
{
|
||||
|
64
gtk/gtkfontbutton.ui
Normal file
64
gtk/gtkfontbutton.ui
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface domain="gtk30">
|
||||
<!-- interface-requires gtk+ 3.10 -->
|
||||
<template class="GtkFontButton" parent="GtkButton">
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<child>
|
||||
<object class="GtkBox" id="box1">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="font_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">Font</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox" id="font_size_box">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="no_show_all">True</property>
|
||||
<child>
|
||||
<object class="GtkSeparator" id="separator">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel" id="size_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label">14</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</template>
|
||||
</interface>
|
@ -245,6 +245,16 @@ test_file_chooser_button_basic (void)
|
||||
gtk_widget_destroy (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
test_font_button_basic (void)
|
||||
{
|
||||
GtkWidget *widget;
|
||||
|
||||
widget = gtk_font_button_new ();
|
||||
g_assert (GTK_IS_FONT_BUTTON (widget));
|
||||
gtk_widget_destroy (widget);
|
||||
}
|
||||
|
||||
static void
|
||||
test_font_chooser_widget_basic (void)
|
||||
{
|
||||
@ -324,6 +334,7 @@ main (int argc, char **argv)
|
||||
g_test_add_func ("/Template/GtkFileChooserWidget/Basic", test_file_chooser_widget_basic);
|
||||
g_test_add_func ("/Template/GtkFileChooserDialog/Basic", test_file_chooser_dialog_basic);
|
||||
g_test_add_func ("/Template/GtkFileChooserButton/Basic", test_file_chooser_button_basic);
|
||||
g_test_add_func ("/Template/GtkFontButton/Basic", test_font_button_basic);
|
||||
g_test_add_func ("/Template/GtkFontChooserWidget/Basic", test_font_chooser_widget_basic);
|
||||
g_test_add_func ("/Template/GtkFontChooserDialog/Basic", test_font_chooser_dialog_basic);
|
||||
g_test_add_func ("/Template/GtkRecentChooserWidget/Basic", test_recent_chooser_widget_basic);
|
||||
|
Loading…
Reference in New Issue
Block a user