[evince/wip/gpoo/gtk4-preparation-ev-message-area: 1/2] shell: Use composite template for the message area




commit df3661af7bd40ee4b6b3ea9e1afa9c3d251b9c3e
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Thu Mar 24 23:53:16 2022 -0300

    shell: Use composite template for the message area
    
    Co-authored-by: Qiu Wenbo <qiuwenbo kylinos com cn>

 shell/ev-message-area.c      | 62 ++++++++++++++------------------------------
 shell/evince-message-area.ui | 58 +++++++++++++++++++++++++++++++++++++++++
 shell/evince.gresource.xml   |  1 +
 shell/meson.build            |  1 +
 4 files changed, 79 insertions(+), 43 deletions(-)
---
diff --git a/shell/ev-message-area.c b/shell/ev-message-area.c
index 1b1126cc2..dd43c70ef 100644
--- a/shell/ev-message-area.c
+++ b/shell/ev-message-area.c
@@ -52,14 +52,32 @@ G_DEFINE_TYPE_WITH_PRIVATE (EvMessageArea, ev_message_area, GTK_TYPE_INFO_BAR)
 
 #define GET_PRIVATE(o) ev_message_area_get_instance_private (o);
 
+static void
+ev_message_area_constructed (GObject *object)
+{
+       EvMessageArea *ev_message_area = EV_MESSAGE_AREA (object);
+
+       G_OBJECT_CLASS (ev_message_area_parent_class)->constructed (object);
+
+       gtk_widget_show_all (GTK_WIDGET (ev_message_area));
+}
+
 static void
 ev_message_area_class_init (EvMessageAreaClass *class)
 {
        GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
 
+       gobject_class->constructed = ev_message_area_constructed;
        gobject_class->set_property = ev_message_area_set_property;
        gobject_class->get_property = ev_message_area_get_property;
 
+       gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/evince/ui/message-area.ui");
+       gtk_widget_class_bind_template_child_private (widget_class, EvMessageArea, main_box);
+       gtk_widget_class_bind_template_child_private (widget_class, EvMessageArea, image);
+       gtk_widget_class_bind_template_child_private (widget_class, EvMessageArea, label);
+       gtk_widget_class_bind_template_child_private (widget_class, EvMessageArea, secondary_label);
+
        g_object_class_install_property (gobject_class,
                                         PROP_TEXT,
                                         g_param_spec_string ("text",
@@ -89,49 +107,7 @@ ev_message_area_class_init (EvMessageAreaClass *class)
 static void
 ev_message_area_init (EvMessageArea *area)
 {
-       GtkWidget *hbox, *vbox;
-       GtkWidget *content_area;
-       EvMessageAreaPrivate *priv;
-
-       priv = ev_message_area_get_instance_private (area);
-
-       priv->main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
-       gtk_container_set_border_width (GTK_CONTAINER (priv->main_box), 6);
-
-       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-       vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
-
-       priv->label = gtk_label_new (NULL);
-       gtk_label_set_use_markup (GTK_LABEL (priv->label), TRUE);
-       gtk_label_set_line_wrap (GTK_LABEL (priv->label), TRUE);
-       gtk_label_set_selectable (GTK_LABEL (priv->label), TRUE);
-       g_object_set (G_OBJECT (priv->label), "xalign", 0., "yalign", 0.5, NULL);
-       gtk_widget_set_can_focus (priv->label, TRUE);
-       gtk_box_pack_start (GTK_BOX (vbox), priv->label, TRUE, TRUE, 0);
-       gtk_widget_show (priv->label);
-
-       priv->secondary_label = gtk_label_new (NULL);
-       gtk_label_set_use_markup (GTK_LABEL (priv->secondary_label), TRUE);
-       gtk_label_set_line_wrap (GTK_LABEL (priv->secondary_label), TRUE);
-       gtk_label_set_selectable (GTK_LABEL (priv->secondary_label), TRUE);
-       g_object_set (G_OBJECT (priv->secondary_label), "xalign", 0., "yalign", 0.5, NULL);
-       gtk_widget_set_can_focus (priv->secondary_label, TRUE);
-       gtk_box_pack_start (GTK_BOX (vbox), priv->secondary_label, TRUE, TRUE, 0);
-
-       priv->image = gtk_image_new_from_icon_name (NULL, GTK_ICON_SIZE_DIALOG);
-       g_object_set (G_OBJECT (priv->image), "xalign", 0.5, "yalign", 0., NULL);
-       gtk_box_pack_start (GTK_BOX (hbox), priv->image, FALSE, FALSE, 0);
-       gtk_widget_show (priv->image);
-
-       gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
-       gtk_widget_show (vbox);
-
-       gtk_box_pack_start (GTK_BOX (priv->main_box), hbox, TRUE, TRUE, 0);
-       gtk_widget_show (hbox);
-
-       content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (area));
-       gtk_container_add (GTK_CONTAINER (content_area), priv->main_box);
-       gtk_widget_show (priv->main_box);
+       gtk_widget_init_template (GTK_WIDGET (area));
 }
 
 static void
diff --git a/shell/evince-message-area.ui b/shell/evince-message-area.ui
new file mode 100644
index 000000000..8cec2bd17
--- /dev/null
+++ b/shell/evince-message-area.ui
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <template class="EvMessageArea" parent="GtkInfoBar">
+    <property name="visible">True</property>
+    <property name="show-close-button">True</property>
+    <child internal-child="content_area">
+      <object class="GtkBox" id="main_box">
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <property name="border-width">12</property>
+        <child>
+          <object class="GtkBox" id="hbox">
+            <property name="orientation">horizontal</property>
+            <property name="spacing">12</property>
+            <child>
+              <object class="GtkImage" id="image">
+                <property name="icon-size">6</property>
+                <property name="xalign">0.5</property>
+                <property name="yalign">0.0</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkBox" id="vbox">
+                <property name="orientation">vertical</property>
+                <property name="spacing">12</property>
+                <property name="hexpand">True</property>
+                <property name="vexpand">False</property>
+                <property name="halign">fill</property>
+                <child>
+                  <object class="GtkLabel" id="label">
+                    <property name="use-markup">True</property>
+                    <property name="wrap">True</property>
+                    <property name="selectable">True</property>
+                    <property name="xalign">0.0</property>
+                    <property name="yalign">0.5</property>
+                    <property name="can-focus">True</property>
+                    <property name="vexpand">True</property>
+                  </object>
+                </child>
+                <child>
+                  <object class="GtkLabel" id="secondary_label">
+                    <property name="use-markup">True</property>
+                    <property name="wrap">True</property>
+                    <property name="selectable">True</property>
+                    <property name="xalign">0.0</property>
+                    <property name="yalign">0.5</property>
+                    <property name="can-focus">True</property>
+                    <property name="visible">False</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index 37302a567..d8eb58deb 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -21,6 +21,7 @@
     <file alias="ui/evince.css" compressed="true">evince.css</file>
     <file alias="ui/thumbnail-frame.png" compressed="true">thumbnail-frame.png</file>
     <file alias="gtk/menus.ui" compressed="true" preprocess="xml-stripblanks">evince-menus.ui</file>
+    <file alias="ui/message-area.ui" compressed="true" 
preprocess="xml-stripblanks">evince-message-area.ui</file>
     <file alias="ui/password-view.ui" compressed="true" 
preprocess="xml-stripblanks">evince-password-view.ui</file>
     <file alias="ui/properties-fonts.ui" compressed="true" 
preprocess="xml-stripblanks">evince-properties-fonts.ui</file>
     <file alias="ui/zoom-action.ui" compressed="true" 
preprocess="xml-stripblanks">evince-zoom-action.ui</file>
diff --git a/shell/meson.build b/shell/meson.build
index 725394cb9..f25793f1d 100644
--- a/shell/meson.build
+++ b/shell/meson.build
@@ -36,6 +36,7 @@ resource_data = files(
   'evince.css',
   '../data/thumbnail-frame.png',
   'evince-menus.ui',
+  'evince-message-area.ui',
   'evince-password-view.ui',
   'evince-properties-fonts.ui',
   'evince-zoom-action.ui',


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