]> Pileus Git - ~andy/gtk/blob - tests/testfontchooser.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testfontchooser.c
1 /* testfontchooser.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 <gtk/gtk.h>
19 #include "prop-editor.h"
20
21 static void
22 notify_font_cb (GtkFontChooser *fontchooser, GParamSpec *pspec, gpointer data)
23 {
24   PangoFontFamily *family;
25   PangoFontFace *face;
26
27   g_debug ("Changed font name %s", gtk_font_chooser_get_font (fontchooser));
28
29   family = gtk_font_chooser_get_font_family (fontchooser);
30   face = gtk_font_chooser_get_font_face (fontchooser);
31   if (family)
32     {
33        g_debug ("  Family: %s is-monospace:%s",
34                 pango_font_family_get_name (family),
35                 pango_font_family_is_monospace (family) ? "true" : "false");
36     }
37   else
38     g_debug ("  No font family!");
39
40   if (face)
41     g_debug ("  Face description: %s", pango_font_face_get_face_name (face));
42   else
43     g_debug ("  No font face!");
44 }
45
46 static void
47 notify_preview_text_cb (GObject *fontchooser, GParamSpec *pspec, gpointer data)
48 {
49   g_debug ("Changed preview text %s", gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (fontchooser)));
50 }
51
52 static void
53 font_activated_cb (GtkFontChooser *chooser, const gchar *font_name, gpointer data)
54 {
55   g_debug ("font-activated: %s", font_name);
56 }
57
58 int
59 main (int argc, char *argv[])
60 {
61   GtkWidget *window;
62   GtkWidget *box;
63   GtkWidget *fontchooser;
64
65   gtk_init (NULL, NULL);
66
67   fontchooser = gtk_font_chooser_widget_new ();
68
69   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
70   gtk_widget_set_size_request (window, 600, 600);
71   box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
72   gtk_container_add (GTK_CONTAINER (window), box);
73   gtk_container_add (GTK_CONTAINER (box), fontchooser);
74
75   gtk_widget_show_all (window);
76
77   g_signal_connect (window, "delete-event",
78                     G_CALLBACK (gtk_main_quit), NULL);
79   g_signal_connect (fontchooser, "notify::font",
80                     G_CALLBACK (notify_font_cb), NULL);
81   g_signal_connect (fontchooser, "notify::preview-text",
82                     G_CALLBACK (notify_preview_text_cb), NULL);
83   g_signal_connect (fontchooser, "font-activated",
84                     G_CALLBACK (font_activated_cb), NULL);
85
86   gtk_font_chooser_set_font (GTK_FONT_CHOOSER (fontchooser), "Bitstream Vera Sans 45");
87   gtk_font_chooser_set_preview_text (GTK_FONT_CHOOSER (fontchooser), "[user@host ~]$ &>>");
88   gtk_font_chooser_set_show_preview_entry (GTK_FONT_CHOOSER (fontchooser), FALSE);
89
90   create_prop_editor (G_OBJECT (fontchooser), GTK_TYPE_FONT_CHOOSER);
91
92   gtk_main ();
93
94   return 0;
95 }