[gtk+/composite-templates-new: 32/32] GtkVolumeButton: Define children with a GtkBuilder template



commit 19bfb621e175575d0e22abbeaa9af2bb8f7e8641
Author: Tristan Van Berkom <tristanvb openismus com>
Date:   Sat Mar 30 18:51:58 2013 +0900

    GtkVolumeButton: Define children with a GtkBuilder template

 gtk/Makefile.am        |    3 +-
 gtk/gtk.gresource.xml  |    1 +
 gtk/gtkvolumebutton.c  |   54 +++++++++++-------------------------------
 gtk/gtkvolumebutton.ui |   61 ++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/tests/templates.c  |   11 ++++++++
 po/POTFILES.in         |    1 +
 6 files changed, 90 insertions(+), 41 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index fbf5e7b..a819b69 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1116,7 +1116,8 @@ COMPOSITE_TEMPLATES =                     \
        gtkprintunixdialog.ui           \
        gtkrecentchooserdefault.ui      \
        gtkscalebutton.ui               \
-       gtkstatusbar.ui
+       gtkstatusbar.ui                 \
+       gtkvolumebutton.ui
 
 #
 # rules to generate built sources
diff --git a/gtk/gtk.gresource.xml b/gtk/gtk.gresource.xml
index 7def35d..b93d837 100644
--- a/gtk/gtk.gresource.xml
+++ b/gtk/gtk.gresource.xml
@@ -33,5 +33,6 @@
     <file compressed="true">gtkrecentchooserdefault.ui</file>
     <file compressed="true">gtkscalebutton.ui</file>
     <file compressed="true">gtkstatusbar.ui</file>
+    <file compressed="true">gtkvolumebutton.ui</file>
   </gresource>
 </gresources>
diff --git a/gtk/gtkvolumebutton.c b/gtk/gtkvolumebutton.c
index ceb6472..f05aa54 100644
--- a/gtk/gtkvolumebutton.c
+++ b/gtk/gtkvolumebutton.c
@@ -135,6 +135,7 @@ static void
 gtk_volume_button_class_init (GtkVolumeButtonClass *klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   gobject_class->set_property = gtk_volume_button_set_property;
   gobject_class->get_property = gtk_volume_button_get_property;
@@ -156,51 +157,24 @@ gtk_volume_button_class_init (GtkVolumeButtonClass *klass)
                                                          P_("Whether to use symbolic icons"),
                                                          FALSE,
                                                          G_PARAM_READWRITE));
+
+  /* Bind class to template
+   */
+  gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/gtkvolumebutton.ui");
+  gtk_widget_class_bind_callback (widget_class, cb_query_tooltip);
+  gtk_widget_class_bind_callback (widget_class, cb_value_changed);
 }
 
 static void
 gtk_volume_button_init (GtkVolumeButton *button)
 {
-  GtkScaleButton *sbutton = GTK_SCALE_BUTTON (button);
-  GtkAdjustment *adj;
-  GtkWidget *minus_button, *plus_button;
-
-  atk_object_set_name (gtk_widget_get_accessible (GTK_WIDGET (button)),
-                      _("Volume"));
-  atk_object_set_description (gtk_widget_get_accessible (GTK_WIDGET (button)),
-                      _("Turns volume down or up"));
-  atk_action_set_description (ATK_ACTION (gtk_widget_get_accessible (GTK_WIDGET (button))),
-                             1,
-                             _("Adjusts the volume"));
-
-  minus_button = gtk_scale_button_get_minus_button (sbutton);
-  plus_button = gtk_scale_button_get_plus_button (sbutton);
-
-  atk_object_set_name (gtk_widget_get_accessible (minus_button),
-                      _("Volume Down"));
-  atk_object_set_description (gtk_widget_get_accessible (minus_button),
-                      _("Decreases the volume"));
-  gtk_widget_set_tooltip_text (minus_button, _("Volume Down"));
-
-  atk_object_set_name (gtk_widget_get_accessible (plus_button),
-                      _("Volume Up"));
-  atk_object_set_description (gtk_widget_get_accessible (plus_button),
-                      _("Increases the volume"));
-  gtk_widget_set_tooltip_text (plus_button, _("Volume Up"));
-
-  gtk_scale_button_set_icons (sbutton, (const char **) icons);
-
-  adj = gtk_adjustment_new (0., 0., 1., 0.02, 0.2, 0.);
-  g_object_set (G_OBJECT (button),
-               "adjustment", adj,
-               "size", GTK_ICON_SIZE_SMALL_TOOLBAR,
-               "has-tooltip", TRUE,
-               NULL);
-
-  g_signal_connect (G_OBJECT (button), "query-tooltip",
-                   G_CALLBACK (cb_query_tooltip), NULL);
-  g_signal_connect (G_OBJECT (button), "value-changed",
-                   G_CALLBACK (cb_value_changed), NULL);
+  GtkWidget *widget = GTK_WIDGET (button);
+
+  gtk_widget_init_template (widget);
+
+  /* The atk action description is not supported by GtkBuilder */
+  atk_action_set_description (ATK_ACTION (gtk_widget_get_accessible (GTK_WIDGET (widget))),
+                             1, _("Adjusts the volume"));
 }
 
 /**
diff --git a/gtk/gtkvolumebutton.ui b/gtk/gtkvolumebutton.ui
new file mode 100644
index 0000000..4c253a3
--- /dev/null
+++ b/gtk/gtkvolumebutton.ui
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface domain="gtk30">
+  <!-- interface-requires gtk+ 3.6 -->
+  <object class="GtkAdjustment" id="adjustment">
+    <property name="upper">1</property>
+    <property name="step_increment">0.02</property>
+    <property name="page_increment">0.20000000000000001</property>
+  </object>
+  <template class="GtkVolumeButton" parent="GtkScaleButton">
+    <property name="visible">True</property>
+    <property name="can_focus">True</property>
+    <property name="receives_default">True</property>
+    <property name="has_tooltip">True</property>
+    <property name="relief">none</property>
+    <property name="focus_on_click">False</property>
+    <property name="orientation">vertical</property>
+    <property name="adjustment">adjustment</property>
+    <property name="icons">audio-volume-muted
+audio-volume-high
+audio-volume-low
+audio-volume-medium</property>
+    <child internal-child="accessible">
+      <object class="AtkObject" id="GtkVolumeButton-atkobject">
+        <property name="AtkObject::accessible-name" translatable="yes">Volume</property>
+        <property name="AtkObject::accessible-description" translatable="yes">Turns volume up or 
down</property>
+      </object>
+    </child>
+    <signal name="query-tooltip" handler="cb_query_tooltip" swapped="no"/>
+    <signal name="value-changed" handler="cb_value_changed" swapped="no"/>
+    <child internal-child="plus_button">
+      <object class="GtkButton" id="scalebutton-plus_button1">
+        <property name="label" translatable="yes">+</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="tooltip_text" translatable="yes">Volume Up</property>
+        <property name="relief">none</property>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="scalebutton-plus_button1-atkobject">
+            <property name="AtkObject::accessible-name" translatable="yes">Volume Up</property>
+            <property name="AtkObject::accessible-description" translatable="yes">Increases the 
volume</property>
+          </object>
+        </child>
+      </object>
+    </child>
+    <child internal-child="minus_button">
+      <object class="GtkButton" id="scalebutton-minus_button1">
+        <property name="label" translatable="yes">-</property>
+        <property name="can_focus">True</property>
+        <property name="receives_default">True</property>
+        <property name="tooltip_text" translatable="yes">Volume Down</property>
+        <property name="relief">none</property>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="scalebutton-minus_button1-atkobject">
+            <property name="AtkObject::accessible-name" translatable="yes">Volume Down</property>
+            <property name="AtkObject::accessible-description" translatable="yes">Decreases the 
volume</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/gtk/tests/templates.c b/gtk/tests/templates.c
index e666c1c..32c1e68 100644
--- a/gtk/tests/templates.c
+++ b/gtk/tests/templates.c
@@ -125,6 +125,16 @@ test_scale_button_basic (void)
 }
 
 static void
+test_volume_button_basic (void)
+{
+  GtkWidget *widget;
+
+  widget = gtk_volume_button_new ();
+  g_assert (GTK_IS_VOLUME_BUTTON (widget));
+  gtk_widget_destroy (widget);
+}
+
+static void
 test_statusbar_basic (void)
 {
   GtkWidget *widget;
@@ -327,6 +337,7 @@ main (int argc, char **argv)
   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/GtkScaleButton/Basic", test_scale_button_basic);
+  g_test_add_func ("/Template/GtkVolumeButton/Basic", test_volume_button_basic);
   g_test_add_func ("/Template/GtkStatusBar/Basic", test_statusbar_basic);
   g_test_add_func ("/Template/GtkAppChooserWidget/Basic", test_app_chooser_widget_basic);
   g_test_add_func ("/Template/GtkAppChooserDialog/Basic", test_app_chooser_dialog_basic);
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ea4d669..a307b2e 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -296,3 +296,4 @@ modules/printbackends/test/gtkprintbackendtest.c
 [type: gettext/glade]gtk/gtkrecentchooserdefault.ui
 [type: gettext/glade]gtk/gtkscalebutton.ui
 [type: gettext/glade]gtk/gtkstatusbar.ui
+[type: gettext/glade]gtk/gtkvolumebutton.ui


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]