]> Pileus Git - ~andy/gtk/blob - tests/testfontchooserdialog.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testfontchooserdialog.c
1 /* testfontchooserdialog.c
2  * Copyright (C) 2011 Alberto Ruiz <aruiz@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include <string.h>
19 #include <gtk/gtk.h>
20 #include "prop-editor.h"
21
22 static gboolean
23 monospace_filter (const PangoFontFamily *family,
24                   const PangoFontFace   *face,
25                   gpointer               data)
26 {
27   return pango_font_family_is_monospace ((PangoFontFamily *) family);
28 }
29
30 static void
31 notify_font_cb (GtkFontChooser *fontchooser, GParamSpec *pspec, gpointer data)
32 {
33   PangoFontFamily *family;
34   PangoFontFace *face;
35
36   g_debug ("Changed font name %s", gtk_font_chooser_get_font (fontchooser));
37
38   family = gtk_font_chooser_get_font_family (fontchooser);
39   face = gtk_font_chooser_get_font_face (fontchooser);
40   if (family)
41     {
42        g_debug ("  Family: %s is-monospace:%s",
43                 pango_font_family_get_name (family),
44                 pango_font_family_is_monospace (family) ? "true" : "false");
45     }
46   else
47     g_debug ("  No font family!");
48
49   if (face)
50     g_debug ("  Face description: %s", pango_font_face_get_face_name (face));
51   else
52     g_debug ("  No font face!");
53 }
54
55 static void
56 notify_preview_text_cb (GObject *fontchooser, GParamSpec *pspec, gpointer data)
57 {
58   g_debug ("Changed preview text %s", gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (fontchooser)));
59 }
60
61 static void
62 font_activated_cb (GtkFontChooser *chooser, const gchar *font_name, gpointer data)
63 {
64   g_debug ("font-activated: %s", font_name);
65 }
66
67 int
68 main (int argc, char *argv[])
69 {
70   GtkWidget *window;
71   GtkWidget *font_button;
72
73   gtk_init (&argc, &argv);
74
75   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
76   font_button = gtk_font_button_new ();
77   gtk_container_add (GTK_CONTAINER (window), font_button);
78   gtk_widget_show_all (window);
79
80   g_signal_connect (font_button, "notify::font",
81                     G_CALLBACK (notify_font_cb), NULL);
82   g_signal_connect (font_button, "notify::preview-text",
83                     G_CALLBACK (notify_preview_text_cb), NULL);
84   g_signal_connect (font_button, "font-activated",
85                     G_CALLBACK (font_activated_cb), NULL);
86
87   if (argc >= 2 && strcmp (argv[1], "--monospace") == 0)
88     {
89       gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (font_button),
90                                         monospace_filter, NULL, NULL);
91     }
92
93   g_signal_connect (window, "delete-event",
94                     G_CALLBACK (gtk_main_quit), NULL);
95
96   create_prop_editor (G_OBJECT (font_button), 0);
97
98   gtk_main ();
99
100   return 0;
101 }