[evince/wip/gpoo/gtk4-preparation: 14/16] shell: Use composite template for the Fonts property tab




commit 318a304cfd8aeab748a97fa247932f061f0e3edd
Author: Germán Poo-Caamaño <gpoo gnome org>
Date:   Sat Mar 5 00:25:27 2022 -0300

    shell: Use composite template for the Fonts property tab
    
    Co-authored-by: Qiu Wenbo <qiuwenbo kylinos com cn>

 shell/ev-properties-fonts.c      | 92 +++++++++++++---------------------------
 shell/evince-properties-fonts.ui | 70 ++++++++++++++++++++++++++++++
 shell/evince.gresource.xml       |  1 +
 shell/meson.build                |  1 +
 4 files changed, 102 insertions(+), 62 deletions(-)
---
diff --git a/shell/ev-properties-fonts.c b/shell/ev-properties-fonts.c
index 42059929b..8a7586dab 100644
--- a/shell/ev-properties-fonts.c
+++ b/shell/ev-properties-fonts.c
@@ -33,9 +33,11 @@
 struct _EvPropertiesFonts {
        GtkBox base_instance;
 
-       GtkWidget *fonts_treeview;
+       GtkTreeView *fonts_treeview;
        GtkWidget *fonts_progress_label;
        GtkWidget *fonts_summary;
+       GtkTreeViewColumn *column;
+       GtkCellRenderer *renderer;
        EvJob     *fonts_job;
 
        EvDocument *document;
@@ -72,8 +74,20 @@ static void
 ev_properties_fonts_class_init (EvPropertiesFontsClass *properties_class)
 {
        GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (properties_class);
 
        g_object_class->dispose = ev_properties_fonts_dispose;
+
+       gtk_widget_class_set_template_from_resource (widget_class,
+                               "/org/gnome/evince/ui/properties-fonts.ui");
+       gtk_widget_class_bind_template_child (widget_class, EvPropertiesFonts, column);
+       gtk_widget_class_bind_template_child (widget_class, EvPropertiesFonts, renderer);
+       gtk_widget_class_bind_template_child (widget_class,
+                                             EvPropertiesFonts, fonts_treeview);
+       gtk_widget_class_bind_template_child (widget_class,
+                                             EvPropertiesFonts, fonts_progress_label);
+       gtk_widget_class_bind_template_child (widget_class,
+                                             EvPropertiesFonts, fonts_summary);
 }
 
 static void
@@ -87,17 +101,17 @@ font_cell_data_func (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
        gtk_tree_model_get (model, iter,
                            EV_DOCUMENT_FONTS_COLUMN_NAME, &name,
                            EV_DOCUMENT_FONTS_COLUMN_DETAILS, &details,
-                           -1);        
+                           -1);
 
        if (details) {
-               markup = g_strdup_printf ("<b><big>%s</big></b>\n<small>%s</small>",
+               markup = g_strdup_printf ("<b><big>Font: %s</big></b>\n<small>%s</small>",
                                          name, details);
        } else {
                markup = g_strdup_printf ("<b><big>%s</big></b>", name);
        }
 
-       g_object_set (renderer, "markup", markup, NULL);
-       
+       g_object_set (renderer, "markup", markup, NULL, NULL);
+
        g_free (markup);
        g_free (details);
        g_free (name);
@@ -106,59 +120,13 @@ font_cell_data_func (GtkTreeViewColumn *col, GtkCellRenderer *renderer,
 static void
 ev_properties_fonts_init (EvPropertiesFonts *properties)
 {
-       GtkWidget         *swindow;
-       GtkCellRenderer   *renderer;
-       GtkTreeViewColumn *column;
+       GtkWidget *widget = GTK_WIDGET (properties);
 
-       gtk_container_set_border_width (GTK_CONTAINER (properties), 12);
-       gtk_box_set_spacing (GTK_BOX (properties), 6);
-       
-       properties->fonts_summary = gtk_label_new (NULL);
-       g_object_set (G_OBJECT (properties->fonts_summary),
-                     "xalign", 0.0,
-                     NULL);
-       gtk_label_set_line_wrap (GTK_LABEL (properties->fonts_summary), TRUE);
-       gtk_box_pack_start (GTK_BOX (properties),
-                           properties->fonts_summary,
-                           FALSE, FALSE, 0);
-
-       swindow = gtk_scrolled_window_new (NULL, NULL);
-       gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (swindow),
-                                            GTK_SHADOW_IN);
-
-       properties->fonts_treeview = gtk_tree_view_new ();
-       gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (properties->fonts_treeview),
-                                          FALSE);
-       column = gtk_tree_view_column_new ();
-       gtk_tree_view_column_set_expand (GTK_TREE_VIEW_COLUMN (column), TRUE);
-       gtk_tree_view_append_column (GTK_TREE_VIEW (properties->fonts_treeview),
-                                    column);
-
-       renderer = GTK_CELL_RENDERER (g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
-                                                   "ypad", 6, NULL));
-       gtk_tree_view_column_pack_start (GTK_TREE_VIEW_COLUMN (column),
-                                        renderer, FALSE);
-       gtk_tree_view_column_set_title (GTK_TREE_VIEW_COLUMN (column),
-                                       _("Font"));
-       gtk_tree_view_column_set_cell_data_func (column, renderer,
+       gtk_widget_init_template (widget);
+       gtk_tree_view_column_set_cell_data_func (properties->column,
+                                                properties->renderer,
                                                 font_cell_data_func,
                                                 NULL, NULL);
-
-       gtk_container_add (GTK_CONTAINER (swindow), properties->fonts_treeview);
-       gtk_widget_show (properties->fonts_treeview);
-
-       gtk_box_pack_start (GTK_BOX (properties), swindow, 
-                           TRUE, TRUE, 0);
-       gtk_widget_show (swindow);
-
-       properties->fonts_progress_label = gtk_label_new (NULL);
-       g_object_set (G_OBJECT (properties->fonts_progress_label),
-                     "xalign", 0.0,
-                     NULL);
-       gtk_box_pack_start (GTK_BOX (properties),
-                           properties->fonts_progress_label,
-                           FALSE, FALSE, 0);
-       gtk_widget_show (properties->fonts_progress_label);
 }
 
 static void
@@ -204,7 +172,7 @@ job_fonts_updated_cb (EvJobFonts *job, gdouble progress, EvPropertiesFonts *prop
 
        update_progress_label (properties->fonts_progress_label, progress);
 
-       model = gtk_tree_view_get_model (GTK_TREE_VIEW (properties->fonts_treeview));
+       model = gtk_tree_view_get_model (properties->fonts_treeview);
        /* Document lock is already held by the jop */
        ev_document_fonts_fill_model (document_fonts, model);
 }
@@ -213,7 +181,7 @@ void
 ev_properties_fonts_set_document (EvPropertiesFonts *properties,
                                  EvDocument        *document)
 {
-       GtkTreeView *tree_view = GTK_TREE_VIEW (properties->fonts_treeview);
+       GtkTreeView *tree_view = properties->fonts_treeview;
        GtkListStore *list_store;
 
        properties->document = document;
@@ -235,11 +203,11 @@ ev_properties_fonts_set_document (EvPropertiesFonts *properties,
 GtkWidget *
 ev_properties_fonts_new (void)
 {
-       EvPropertiesFonts *properties;
+       GtkWidget *retval;
+
+       retval = GTK_WIDGET (g_object_new (EV_TYPE_PROPERTIES_FONTS, NULL));
 
-       properties = g_object_new (EV_TYPE_PROPERTIES_FONTS,
-                                  "orientation", GTK_ORIENTATION_VERTICAL,
-                                  NULL);
+       gtk_widget_show_all (retval);
 
-       return GTK_WIDGET (properties);
+       return retval;
 }
diff --git a/shell/evince-properties-fonts.ui b/shell/evince-properties-fonts.ui
new file mode 100644
index 000000000..02e23d130
--- /dev/null
+++ b/shell/evince-properties-fonts.ui
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.38.2 -->
+<interface>
+  <requires lib="gtk+" version="3.16"/>
+  <template class="EvPropertiesFonts" parent="GtkBox">
+    <property name="can-focus">False</property>
+    <property name="margin-start">12</property>
+    <property name="margin-end">12</property>
+    <property name="margin-top">12</property>
+    <property name="margin-bottom">12</property>
+    <property name="orientation">vertical</property>
+    <property name="spacing">6</property>
+    <child>
+      <object class="GtkLabel" id="fonts_summary">
+        <property name="can-focus">False</property>
+        <property name="wrap">True</property>
+        <property name="xalign">0.0</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">False</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow">
+        <property name="can-focus">False</property>
+        <property name="shadow-type">in</property>
+        <child>
+          <object class="GtkTreeView" id="fonts_treeview">
+            <property name="can-focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="vexpand">True</property>
+            <property name="headers-visible">False</property>
+            <child internal-child="selection">
+              <object class="GtkTreeSelection"/>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn" id="column">
+                <property name="title" translatable="yes">Font</property>
+                <property name="expand">True</property>
+                <child>
+                  <object class="GtkCellRendererText" id="renderer">
+                    <property name="ypad">6</property>
+                  </object>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkLabel" id="fonts_progress_label">
+        <property name="can-focus">False</property>
+        <property name="xalign">0</property>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">2</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/shell/evince.gresource.xml b/shell/evince.gresource.xml
index 3e98fe3cb..37302a567 100644
--- a/shell/evince.gresource.xml
+++ b/shell/evince.gresource.xml
@@ -22,6 +22,7 @@
     <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/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>
   </gresource>
 </gresources>
diff --git a/shell/meson.build b/shell/meson.build
index bfcbe807c..725394cb9 100644
--- a/shell/meson.build
+++ b/shell/meson.build
@@ -37,6 +37,7 @@ resource_data = files(
   '../data/thumbnail-frame.png',
   'evince-menus.ui',
   'evince-password-view.ui',
+  'evince-properties-fonts.ui',
   'evince-zoom-action.ui',
   'help-overlay.ui',
 )


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