GtkFontChooserDialog: Define children with a GtkBuilder template

This commit is contained in:
Tristan Van Berkom 2013-03-26 19:13:12 +09:00
parent 21391027c4
commit 6f8162a2e1
5 changed files with 116 additions and 49 deletions

View File

@ -1104,6 +1104,7 @@ COMPOSITE_TEMPLATES = \
gtkdialog.ui \
gtkfilechooserdefault.ui \
gtkfilechooserdialog.ui \
gtkfontchooserdialog.ui \
gtkfontchooserwidget.ui \
gtkinfobar.ui \
gtklockbutton.ui \

View File

@ -19,6 +19,7 @@
<file compressed="true">gtkdialog.ui</file>
<file compressed="true">gtkfilechooserdefault.ui</file>
<file compressed="true">gtkfilechooserdialog.ui</file>
<file compressed="true">gtkfontchooserdialog.ui</file>
<file compressed="true">gtkfontchooserwidget.ui</file>
<file compressed="true">gtkinfobar.ui</file>
<file compressed="true">gtklockbutton.ui</file>

View File

@ -109,19 +109,6 @@ gtk_font_chooser_dialog_get_property (GObject *object,
}
}
static void
gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
gobject_class->get_property = gtk_font_chooser_dialog_get_property;
gobject_class->set_property = gtk_font_chooser_dialog_set_property;
_gtk_font_chooser_install_properties (gobject_class);
g_type_class_add_private (klass, sizeof (GtkFontChooserDialogPrivate));
}
static void
font_activated_cb (GtkFontChooser *fontchooser,
const gchar *fontname,
@ -132,58 +119,47 @@ font_activated_cb (GtkFontChooser *fontchooser,
gtk_dialog_response (dialog, GTK_RESPONSE_OK);
}
static void
gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gobject_class->get_property = gtk_font_chooser_dialog_get_property;
gobject_class->set_property = gtk_font_chooser_dialog_set_property;
_gtk_font_chooser_install_properties (gobject_class);
/* Bind class to template
*/
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gtk/libgtk/gtkfontchooserdialog.ui");
gtk_widget_class_bind_child (widget_class, GtkFontChooserDialogPrivate, fontchooser);
gtk_widget_class_bind_child (widget_class, GtkFontChooserDialogPrivate, select_button);
gtk_widget_class_bind_child (widget_class, GtkFontChooserDialogPrivate, cancel_button);
gtk_widget_class_bind_callback (widget_class, font_activated_cb);
g_type_class_add_private (klass, sizeof (GtkFontChooserDialogPrivate));
}
static void
gtk_font_chooser_dialog_init (GtkFontChooserDialog *fontchooserdiag)
{
GtkFontChooserDialogPrivate *priv;
GtkDialog *dialog = GTK_DIALOG (fontchooserdiag);
GtkWidget *action_area, *content_area;
fontchooserdiag->priv = G_TYPE_INSTANCE_GET_PRIVATE (fontchooserdiag,
GTK_TYPE_FONT_CHOOSER_DIALOG,
GtkFontChooserDialogPrivate);
priv = fontchooserdiag->priv;
content_area = gtk_dialog_get_content_area (dialog);
action_area = gtk_dialog_get_action_area (dialog);
gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
gtk_box_set_spacing (GTK_BOX (content_area), 2); /* 2 * 5 + 2 = 12 */
gtk_container_set_border_width (GTK_CONTAINER (action_area), 5);
gtk_box_set_spacing (GTK_BOX (action_area), 6);
gtk_widget_push_composite_child ();
gtk_window_set_resizable (GTK_WINDOW (fontchooserdiag), TRUE);
/* Create the content area */
priv->fontchooser = gtk_font_chooser_widget_new ();
gtk_container_set_border_width (GTK_CONTAINER (priv->fontchooser), 5);
gtk_widget_show (priv->fontchooser);
gtk_box_pack_start (GTK_BOX (content_area),
priv->fontchooser, TRUE, TRUE, 0);
g_signal_connect (priv->fontchooser, "font-activated",
G_CALLBACK (font_activated_cb), dialog);
/* Create the action area */
priv->cancel_button = gtk_dialog_add_button (dialog,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
priv->select_button = gtk_dialog_add_button (dialog,
_("_Select"),
GTK_RESPONSE_OK);
gtk_widget_grab_default (priv->select_button);
gtk_widget_init_template (GTK_WIDGET (fontchooserdiag));
gtk_dialog_set_alternative_button_order (GTK_DIALOG (fontchooserdiag),
GTK_RESPONSE_OK,
GTK_RESPONSE_CANCEL,
-1);
gtk_window_set_title (GTK_WINDOW (fontchooserdiag), _("Font Selection"));
gtk_widget_pop_composite_child ();
_gtk_font_chooser_set_delegate (GTK_FONT_CHOOSER (fontchooserdiag),
GTK_FONT_CHOOSER (priv->fontchooser));
}

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface domain="gtk30">
<!-- interface-requires gtk+ 3.10 -->
<template class="GtkFontChooserDialog" parent="GtkDialog">
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="title" translatable="yes">Font Selection</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox" id="dialog-action_area1">
<property name="can_focus">False</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label">gtk-cancel</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="select_button">
<property name="label" translatable="yes">_Select</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">True</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFontChooserWidget" id="fontchooser">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<signal name="font-activated" handler="font_activated_cb" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="-6">cancel_button</action-widget>
<action-widget response="-5">select_button</action-widget>
</action-widgets>
</template>
</interface>

View File

@ -234,6 +234,16 @@ test_font_chooser_widget_basic (void)
gtk_widget_destroy (widget);
}
static void
test_font_chooser_dialog_basic (void)
{
GtkWidget *widget;
widget = gtk_font_chooser_dialog_new ("Choose a font !", NULL);
g_assert (GTK_IS_FONT_CHOOSER_DIALOG (widget));
gtk_widget_destroy (widget);
}
int
main (int argc, char **argv)
{
@ -261,6 +271,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/GtkFontChooserWidget/Basic", test_font_chooser_widget_basic);
g_test_add_func ("/Template/GtkFontChooserDialog/Basic", test_font_chooser_dialog_basic);
return g_test_run();
}