fontchooser: Add a way to set a GtkFilter
authorMatthias Clasen <mclasen@redhat.com>
Sat, 29 Oct 2022 03:58:50 +0000 (23:58 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sat, 29 Oct 2022 14:18:37 +0000 (10:18 -0400)
We keep this private, since the chooser apis
are going away. This will be used in GtkFontDialog.

gtk/gtkfontchooserdialog.c
gtk/gtkfontchooserdialogprivate.h [new file with mode: 0644]
gtk/gtkfontchooserwidget.c
gtk/gtkfontchooserwidgetprivate.h
gtk/ui/gtkfontchooserwidget.ui

index 147cff8bca6aa140d8b40f6c7b4f4895b5f6acbe..c10c214bb2ffbb375ba84d91297bb7ac21289e74 100644 (file)
@@ -21,7 +21,7 @@
 #include <glib/gprintf.h>
 #include <string.h>
 
-#include "gtkfontchooserdialog.h"
+#include "gtkfontchooserdialogprivate.h"
 #include "gtkfontchooser.h"
 #include "gtkfontchooserwidget.h"
 #include "gtkfontchooserwidgetprivate.h"
@@ -324,3 +324,10 @@ gtk_font_chooser_dialog_buildable_get_internal_child (GtkBuildable *buildable,
 
   return parent_buildable_iface->get_internal_child (buildable, builder, childname);
 }
+
+void
+gtk_font_chooser_dialog_set_filter (GtkFontChooserDialog *dialog,
+                                    GtkFilter            *filter)
+{
+  gtk_font_chooser_widget_set_filter (GTK_FONT_CHOOSER_WIDGET (dialog->fontchooser), filter);
+}
diff --git a/gtk/gtkfontchooserdialogprivate.h b/gtk/gtkfontchooserdialogprivate.h
new file mode 100644 (file)
index 0000000..e57685e
--- /dev/null
@@ -0,0 +1,31 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2017 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GTK_FONT_CHOOSER_DIALOG_PRIVATE_H__
+#define __GTK_FONT_CHOOSER_DIALOG_PRIVATE_H__
+
+#include "gtkfontchooserdialog.h"
+#include "gtkfilter.h"
+
+G_BEGIN_DECLS
+
+void gtk_font_chooser_dialog_set_filter (GtkFontChooserDialog *dialog,
+                                         GtkFilter            *filter);
+
+G_END_DECLS
+
+#endif /* __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__ */
index c645739644b82f374e440b6f34904f7e9ba8cf3c..dcacae2e10d25966315c83055948e0c0a62e4155 100644 (file)
@@ -63,6 +63,7 @@
 #include "gtksortlistmodel.h"
 #include "gtkstringsorter.h"
 #include "gtkdropdown.h"
+#include "gtkmultifilter.h"
 
 #include <hb-ot.h>
 
@@ -105,6 +106,7 @@ struct _GtkFontChooserWidget
   GtkSingleSelection *selection;
   GtkCustomFilter      *custom_filter;
   GtkCustomFilter      *user_filter;
+  GtkCustomFilter      *multi_filter;
   GtkFilterListModel   *filter_model;
 
   GtkWidget       *preview;
@@ -144,6 +146,8 @@ struct _GtkFontChooserWidget
   gpointer          filter_data;
   GDestroyNotify    filter_data_destroy;
 
+  GtkFilter *filter;
+
   guint last_fontconfig_timestamp;
 
   GtkFontChooserLevel level;
@@ -1325,6 +1329,8 @@ gtk_font_chooser_widget_finalize (GObject *object)
 
   g_free (fontchooser->font_features);
 
+  g_clear_object (&fontchooser->filter);
+
   G_OBJECT_CLASS (gtk_font_chooser_widget_parent_class)->finalize (object);
 }
 
@@ -2976,3 +2982,14 @@ gtk_font_chooser_widget_get_tweak_action (GtkWidget *widget)
 
   return fontchooser->tweak_action;
 }
+
+void
+gtk_font_chooser_widget_set_filter (GtkFontChooserWidget *widget,
+                                    GtkFilter            *filter)
+{
+  if (widget->filter)
+    gtk_multi_filter_remove (GTK_MULTI_FILTER (widget->multi_filter), 3);
+  g_set_object (&widget->filter, filter);
+  if (widget->filter)
+    gtk_multi_filter_append (GTK_MULTI_FILTER (widget->multi_filter), g_object_ref (filter));
+}
index 1a7dd743ec5eb935b9487ff2c31cca6fe9d0a9ae..ac8e7dc7c07a049fb4fabdaa34b274a1cdabef80 100644 (file)
 #define __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__
 
 #include "gtkfontchooserwidget.h"
+#include "gtkfilter.h"
 
 G_BEGIN_DECLS
 
 GAction *gtk_font_chooser_widget_get_tweak_action (GtkWidget *fontchooser);
 
+void     gtk_font_chooser_widget_set_filter (GtkFontChooserWidget *widget,
+                                             GtkFilter            *filter);
+
 G_END_DECLS
 
 #endif /* __GTK_FONT_CHOOSER_WIDGET_PRIVATE_H__ */
index ffd3ae68e4b6e240581ce451a39ce47a3faafe85..9b0fc903135fff0bb4806d698ea13a0b92f63333 100644 (file)
@@ -8,7 +8,7 @@
         <signal name="notify::pending" handler="rows_changed_cb" object="GtkFontChooserWidget" swapped="1"/>
         <property name="incremental">1</property>
         <property name="filter">
-          <object class="GtkEveryFilter">
+          <object class="GtkEveryFilter" id="multi_filter">
             <child>
               <object class="GtkStringFilter">
                 <binding name="search">