]> Pileus Git - ~andy/gtk/blob - tests/testfontchooserdialog.c
Add GtkFontChooser:font-desc property
[~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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <gtk/gtk.h>
21 #include "prop-editor.h"
22
23 static void
24 notify_font_cb (GtkFontChooser *fontchooser, GParamSpec *pspec, gpointer data)
25 {
26   PangoFontFamily *family;
27   PangoFontFace *face;
28
29   g_debug ("Changed font name %s", gtk_font_chooser_get_font (fontchooser));
30
31   family = gtk_font_chooser_get_family (fontchooser);
32   face = gtk_font_chooser_get_face (fontchooser);
33   if (family)
34     {
35        g_debug ("  Family: %s is-monospace:%s",
36                 pango_font_family_get_name (family),
37                 pango_font_family_is_monospace (family) ? "true" : "false");
38     }
39   else
40     g_debug ("  No font family!");
41
42   if (face)
43     g_debug ("  Face description: %s", pango_font_face_get_face_name (face));
44   else
45     g_debug ("  No font face!");
46 }
47
48 static void
49 notify_preview_text_cb (GObject *fontchooser, GParamSpec *pspec, gpointer data)
50 {
51   g_debug ("Changed preview text %s", gtk_font_chooser_get_preview_text (GTK_FONT_CHOOSER (fontchooser)));
52 }
53
54 static void
55 font_activated_cb (GtkFontChooser *chooser, const gchar *font_name, gpointer data)
56 {
57   g_debug ("font-activated: %s", font_name);
58 }
59
60 int
61 main (int argc, char *argv[])
62 {
63   GtkWidget *window;
64   GtkWidget *font_button;
65
66   gtk_init (&argc, &argv);
67
68   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
69   font_button = gtk_font_button_new ();
70   gtk_container_add (GTK_CONTAINER (window), font_button);
71   gtk_widget_show_all (window);
72
73   g_signal_connect (font_button, "notify::font",
74                     G_CALLBACK (notify_font_cb), NULL);
75   g_signal_connect (font_button, "notify::preview-text",
76                     G_CALLBACK (notify_preview_text_cb), NULL);
77   g_signal_connect (font_button, "font-activated",
78                     G_CALLBACK (font_activated_cb), NULL);
79
80   g_signal_connect (window, "delete-event",
81                     G_CALLBACK (gtk_main_quit), NULL);
82
83   create_prop_editor (G_OBJECT (font_button), 0);
84
85   gtk_main ();
86
87   return 0;
88 }