[gtkmm] FontChooser: Add set_filter().
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtkmm] FontChooser: Add set_filter().
- Date: Thu, 15 Mar 2012 07:54:35 +0000 (UTC)
commit 4f449263c21173c7e76cc385a230e671e5521716
Author: Murray Cumming <murrayc murrayc com>
Date: Thu Mar 15 08:53:02 2012 +0100
FontChooser: Add set_filter().
* gtk/src/fontchooser.[hg|ccg]: Wrap gtk_font_chooser_set_filter_func()
and its callback function (as a slot).
ChangeLog | 7 +++++++
gtk/src/fontchooser.ccg | 42 ++++++++++++++++++++++++++++++++++++++++++
gtk/src/fontchooser.hg | 31 +++++++++++++++++++++++++------
3 files changed, 74 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 04bff47..b0f83e7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2012-03-15 Murray Cumming <murrayc murrayc com>
+
+ FontChooser: Add set_filter().
+
+ * gtk/src/fontchooser.[hg|ccg]: Wrap gtk_font_chooser_set_filter_func()
+ and its callback function (as a slot).
+
2012-03-14 Murray Cumming <murrayc murrayc com>
PaperSize: Correct the PaperSizeTraits pre-declaration.
diff --git a/gtk/src/fontchooser.ccg b/gtk/src/fontchooser.ccg
index 5d7dafa..633cbc0 100644
--- a/gtk/src/fontchooser.ccg
+++ b/gtk/src/fontchooser.ccg
@@ -17,3 +17,45 @@
#include <gtk/gtk.h>
+
+namespace
+{
+extern "C"
+{
+static gboolean SignalProxy_Filter_gtk_callback(const PangoFontFamily* family, const PangoFontFace* face, gpointer user_data)
+{
+ Gtk::FontChooser::SlotFontFilter* the_slot = static_cast<Gtk::FontChooser::SlotFontFilter*>(user_data);
+
+ try
+ {
+ // Create suitable C++ instances to pass to the C++ method:
+ const Glib::RefPtr<const Pango::FontFamily> cppFamily = Glib::wrap(const_cast<PangoFontFamily*>(family), true);
+ const Glib::RefPtr<const Pango::FontFace> cppFace = Glib::wrap(const_cast<PangoFontFace*>(face), true);
+ return (*the_slot)(cppFamily, cppFace);
+ }
+ catch(...)
+ {
+ Glib::exception_handlers_invoke();
+ }
+
+ return false; // arbitrary value
+}
+
+static void SignalProxy_Filter_gtk_callback_destroy(void* data)
+{
+ delete static_cast<Gtk::FontChooser::SlotFontFilter*>(data);
+}
+
+} // extern "C"
+} // anonymous namespace
+
+namespace Gtk
+{
+
+void FontChooser::set_filter_func(const SlotFontFilter& slot)
+{
+ SlotFontFilter* slot_copy = new SlotFontFilter(slot);
+ gtk_font_chooser_set_filter_func(gobj(), &SignalProxy_Filter_gtk_callback, slot_copy, &SignalProxy_Filter_gtk_callback_destroy);
+}
+
+} //namespace Gtk
diff --git a/gtk/src/fontchooser.hg b/gtk/src/fontchooser.hg
index 5830318..6b02162 100644
--- a/gtk/src/fontchooser.hg
+++ b/gtk/src/fontchooser.hg
@@ -72,12 +72,31 @@ public:
_WRAP_METHOD(bool get_show_preview_entry() const, gtk_font_chooser_get_show_preview_entry)
_WRAP_METHOD(void set_show_preview_entry(bool show_preview_entry = true), gtk_font_chooser_set_show_preview_entry)
-/* TODO:
-void gtk_font_chooser_set_filter_func (GtkFontChooser *fontchooser,
- GtkFontFilterFunc filter,
- gpointer user_data,
- GDestroyNotify destroy);
-*/
+ /** Font filter callback.
+ * For instance,
+ * @code
+ * bool on_font_fitler(const Glib::RefPtr<const Pango::FontFamily>& font_family, const Glib::RefPtr<const Pango::FontFace>& font_face);
+ * @endcode
+ *
+ * @param font_family A Pango FontFamily.
+ * @param font_face A Font Face belonging to the @a font_family.
+ * @result true if the font should be displayed.
+ *
+ * This is used for deciding what fonts should be shown in a FontChooser.
+ * See set_filter_func().
+ *
+ * @newin{3,4}
+ */
+ typedef sigc::slot<bool, const Glib::RefPtr<const Pango::FontFamily>&, const Glib::RefPtr<const Pango::FontFace>&> SlotFontFilter;
+
+ /** Adds a filter function that decides which fonts to display in the font chooser.
+ *
+ * @param slot A callback, to be called for each font.
+ *
+ * @newin{3,4}
+ */
+ void set_filter_func(const SlotFontFilter& slot);
+ _IGNORE(gtk_font_chooser_set_filter_func)
//TODO: Remove no_default_handler when we can break ABI.
_WRAP_SIGNAL(void font_activated(const Glib::ustring& fontname), "font-activated", no_default_handler)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]