]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfontbutton.c
Deprecate widget flag: GTK_WIDGET_VISIBLE
[~andy/gtk] / gtk / gtkfontbutton.c
index b26b8af383e9b08b4a8fbc939428c3b54dee145f..694c61874a545fe3346987f75398640f37a7f98c 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 
-#include "gtkalias.h"
 #include "gtkfontbutton.h"
 
-#include "gtksignal.h"
 #include "gtkmain.h"
 #include "gtkalignment.h"
 #include "gtkhbox.h"
@@ -40,7 +38,9 @@
 #include "gtkfontsel.h"
 #include "gtkimage.h"
 #include "gtkmarshalers.h"
+#include "gtkprivate.h"
 #include "gtkintl.h"
+#include "gtkalias.h"
 
 #include <string.h>
 #include <stdio.h>
@@ -83,8 +83,6 @@ enum
 };
 
 /* Prototypes */
-static void gtk_font_button_init                   (GtkFontButton      *font_button);
-static void gtk_font_button_class_init             (GtkFontButtonClass *klass);
 static void gtk_font_button_finalize               (GObject            *object);
 static void gtk_font_button_get_property           (GObject            *object,
                                                     guint               param_id,
@@ -110,51 +108,19 @@ static GtkWidget *gtk_font_button_create_inside     (GtkFontButton     *gfs);
 static void gtk_font_button_label_use_font          (GtkFontButton     *gfs);
 static void gtk_font_button_update_font_info        (GtkFontButton     *gfs);
 
-static gpointer parent_class = NULL;
 static guint font_button_signals[LAST_SIGNAL] = { 0 };
 
-GType
-gtk_font_button_get_type (void)
-{
-  static GType font_button_type = 0;
-  
-  if (!font_button_type)
-    {
-      static const GTypeInfo font_button_info =
-      {
-        sizeof (GtkFontButtonClass),
-        NULL,           /* base_init */
-        NULL,           /* base_finalize */
-        (GClassInitFunc) gtk_font_button_class_init,
-        NULL,           /* class_finalize */
-        NULL,           /* class_data */
-        sizeof (GtkFontButton),
-        0,              /* n_preallocs */
-        (GInstanceInitFunc) gtk_font_button_init,
-      };
-      
-      font_button_type =
-        g_type_register_static (GTK_TYPE_BUTTON, "GtkFontButton",
-                                &font_button_info, 0);
-    }
-  
-  return font_button_type;
-}
-
+G_DEFINE_TYPE (GtkFontButton, gtk_font_button, GTK_TYPE_BUTTON)
 
 static void
 gtk_font_button_class_init (GtkFontButtonClass *klass)
 {
-  GtkObjectClass *object_class;
   GObjectClass *gobject_class;
   GtkButtonClass *button_class;
   
-  object_class = (GtkObjectClass *) klass;
   gobject_class = (GObjectClass *) klass;
   button_class = (GtkButtonClass *) klass;
 
-  parent_class = g_type_class_peek_parent (klass);
-
   gobject_class->finalize = gtk_font_button_finalize;
   gobject_class->set_property = gtk_font_button_set_property;
   gobject_class->get_property = gtk_font_button_get_property;
@@ -176,8 +142,8 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
                                                         P_("Title"),
                                                         P_("The title of the font selection dialog"),
                                                         _("Pick a Font"),
-                                                        (G_PARAM_READABLE |
-                                                         G_PARAM_WRITABLE)));
+                                                        (GTK_PARAM_READABLE |
+                                                         GTK_PARAM_WRITABLE)));
 
   /**
    * GtkFontButton:font-name:
@@ -188,88 +154,93 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
    */
   g_object_class_install_property (gobject_class,
                                    PROP_FONT_NAME,
-                                   g_param_spec_string ("font_name",
+                                   g_param_spec_string ("font-name",
                                                         P_("Font name"),
                                                         P_("The name of the selected font"),
                                                         P_("Sans 12"),
-                                                        (G_PARAM_READABLE |
-                                                         G_PARAM_WRITABLE)));
+                                                        (GTK_PARAM_READABLE |
+                                                         GTK_PARAM_WRITABLE)));
 
   /**
    * GtkFontButton:use-font:
    * 
-   * If this property is set to %TRUE, the label will be drawn in the selected font.
+   * If this property is set to %TRUE, the label will be drawn 
+   * in the selected font.
    *
    * Since: 2.4
    */
   g_object_class_install_property (gobject_class,
                                    PROP_USE_FONT,
-                                   g_param_spec_boolean ("use_font",
+                                   g_param_spec_boolean ("use-font",
                                                          P_("Use font in label"),
                                                          P_("Whether the label is drawn in the selected font"),
                                                          FALSE,
-                                                         (G_PARAM_READABLE |
-                                                          G_PARAM_WRITABLE)));
+                                                         GTK_PARAM_READWRITE));
 
   /**
    * GtkFontButton:use-size:
    * 
-   * If this property is set to %TRUE, the label will be drawn with the selected font size.
+   * If this property is set to %TRUE, the label will be drawn 
+   * with the selected font size.
    *
    * Since: 2.4
    */
   g_object_class_install_property (gobject_class,
                                    PROP_USE_SIZE,
-                                   g_param_spec_boolean ("use_size",
+                                   g_param_spec_boolean ("use-size",
                                                          P_("Use size in label"),
                                                          P_("Whether the label is drawn with the selected font size"),
                                                          FALSE,
-                                                         (G_PARAM_READABLE |
-                                                          G_PARAM_WRITABLE)));
+                                                         GTK_PARAM_READWRITE));
 
   /**
    * GtkFontButton:show-style:
    * 
-   * If this property is set to %TRUE, the name of the selected font style will be shown in the label. For
-   * a more WYSIWIG way to show the selected style, see the ::use-font property. 
+   * If this property is set to %TRUE, the name of the selected font style 
+   * will be shown in the label. For a more WYSIWYG way to show the selected 
+   * style, see the ::use-font property. 
    *
    * Since: 2.4
    */
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_STYLE,
-                                   g_param_spec_boolean ("show_style",
+                                   g_param_spec_boolean ("show-style",
                                                          P_("Show style"),
                                                          P_("Whether the selected font style is shown in the label"),
                                                          TRUE,
-                                                         (G_PARAM_READABLE |
-                                                          G_PARAM_WRITABLE)));
+                                                         GTK_PARAM_READWRITE));
   /**
    * GtkFontButton:show-size:
    * 
-   * If this property is set to %TRUE, the selected font size will be shown in the label. For
-   * a more WYSIWIG way to show the selected size, see the ::use-size property. 
+   * If this property is set to %TRUE, the selected font size will be shown 
+   * in the label. For a more WYSIWYG way to show the selected size, see the 
+   * ::use-size property. 
    *
    * Since: 2.4
    */
   g_object_class_install_property (gobject_class,
                                    PROP_SHOW_SIZE,
-                                   g_param_spec_boolean ("show_size",
+                                   g_param_spec_boolean ("show-size",
                                                          P_("Show size"),
                                                          P_("Whether selected font size is shown in the label"),
                                                          TRUE,
-                                                         (G_PARAM_READABLE |
-                                                          G_PARAM_WRITABLE)));
+                                                         GTK_PARAM_READWRITE));
 
   /**
    * GtkFontButton::font-set:
    * @widget: the object which received the signal.
    * 
-   * The ::font-set signal is emitted when the user selects a font. When handling this signal,
-   * use gtk_font_button_get_font_name() to find out which font was just selected.
+   * The ::font-set signal is emitted when the user selects a font. 
+   * When handling this signal, use gtk_font_button_get_font_name() 
+   * to find out which font was just selected.
+   *
+   * Note that this signal is only emitted when the <emphasis>user</emphasis>
+   * changes the font. If you need to react to programmatic font changes
+   * as well, use the notify::font-name signal.
    *
    * Since: 2.4
    */
-  font_button_signals[FONT_SET] = g_signal_new ("font_set",
+  font_button_signals[FONT_SET] = g_signal_new (I_("font-set"),
                                                 G_TYPE_FROM_CLASS (gobject_class),
                                                 G_SIGNAL_RUN_FIRST,
                                                 G_STRUCT_OFFSET (GtkFontButtonClass, font_set),
@@ -316,7 +287,7 @@ gtk_font_button_finalize (GObject *object)
   g_free (font_button->priv->title);
   font_button->priv->title = NULL;
   
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_font_button_parent_class)->finalize (object);
 }
 
 static void
@@ -416,7 +387,7 @@ gtk_font_button_new (void)
 GtkWidget *
 gtk_font_button_new_with_font (const gchar *fontname)
 {
-  return g_object_new (GTK_TYPE_FONT_BUTTON, "font_name", fontname, NULL);
+  return g_object_new (GTK_TYPE_FONT_BUTTON, "font-name", fontname, NULL);
 } 
 
 /**
@@ -508,7 +479,7 @@ gtk_font_button_set_use_font (GtkFontButton *font_button,
       else
        gtk_widget_set_style (font_button->priv->font_label, NULL);
  
-     g_object_notify (G_OBJECT (font_button), "use_font");
+     g_object_notify (G_OBJECT (font_button), "use-font");
     }
 } 
 
@@ -554,7 +525,7 @@ gtk_font_button_set_use_size (GtkFontButton *font_button,
       if (font_button->priv->use_font)
         gtk_font_button_label_use_font (font_button);
 
-      g_object_notify (G_OBJECT (font_button), "use_size");
+      g_object_notify (G_OBJECT (font_button), "use-size");
     }
 } 
 
@@ -598,7 +569,7 @@ gtk_font_button_set_show_style (GtkFontButton *font_button,
       
       gtk_font_button_update_font_info (font_button);
   
-      g_object_notify (G_OBJECT (font_button), "show_style");
+      g_object_notify (G_OBJECT (font_button), "show-style");
     }
 } 
 
@@ -648,7 +619,7 @@ gtk_font_button_set_show_size (GtkFontButton *font_button,
       
       gtk_font_button_update_font_info (font_button);
 
-      g_object_notify (G_OBJECT (font_button), "show_size");
+      g_object_notify (G_OBJECT (font_button), "show-size");
     }
 } 
 
@@ -657,7 +628,12 @@ gtk_font_button_set_show_size (GtkFontButton *font_button,
  * gtk_font_button_get_font_name:
  * @font_button: a #GtkFontButton
  *
- * Retrieves the name of the currently selected font.
+ * Retrieves the name of the currently selected font. This name includes
+ * style and size information as well. If you want to render something
+ * with the font, use this string with pango_font_description_from_string() .
+ * If you're interested in peeking certain values (family name,
+ * style, size, weight) just query these properties from the
+ * #PangoFontDescription object.
  *
  * Returns: an internal copy of the font name which must not be freed.
  *
@@ -708,7 +684,7 @@ gtk_font_button_set_font_name (GtkFontButton *font_button,
   else
     result = FALSE;
 
-  g_object_notify (G_OBJECT (font_button), "font_name");
+  g_object_notify (G_OBJECT (font_button), "font-name");
 
   return result;
 }
@@ -729,12 +705,14 @@ gtk_font_button_clicked (GtkButton *button)
       
       font_dialog = GTK_FONT_SELECTION_DIALOG (font_button->priv->font_dialog);
       
-      if (parent)
-        gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent));
-      
-      /* If there is a grabbed window, set new dialog as modal */
-      if (gtk_grab_get_current ())
-        gtk_window_set_modal (GTK_WINDOW (font_dialog), TRUE);
+      if (gtk_widget_is_toplevel (parent) && GTK_IS_WINDOW (parent))
+        {
+          if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (font_dialog)))
+           gtk_window_set_transient_for (GTK_WINDOW (font_dialog), GTK_WINDOW (parent));
+              
+         gtk_window_set_modal (GTK_WINDOW (font_dialog),
+                               gtk_window_get_modal (GTK_WINDOW (parent)));
+       }
 
       g_signal_connect (font_dialog->ok_button, "clicked",
                         G_CALLBACK (dialog_ok_clicked), font_button);
@@ -744,7 +722,7 @@ gtk_font_button_clicked (GtkButton *button)
                         G_CALLBACK (dialog_destroy), font_button);
     }
   
-  if (!GTK_WIDGET_VISIBLE (font_button->priv->font_dialog)) 
+  if (!gtk_widget_get_visible (font_button->priv->font_dialog))
     {
       font_dialog = GTK_FONT_SELECTION_DIALOG (font_button->priv->font_dialog);
       
@@ -769,7 +747,7 @@ dialog_ok_clicked (GtkWidget *widget,
   /* Set label font */
   gtk_font_button_update_font_info (font_button);
 
-  g_object_notify (G_OBJECT (font_button), "font_name");
+  g_object_notify (G_OBJECT (font_button), "font-name");
   
   /* Emit font_set signal */
   g_signal_emit (font_button, font_button_signals[FONT_SET], 0);
@@ -872,13 +850,14 @@ gtk_font_button_update_font_info (GtkFontButton *font_button)
 #endif
 
   style = NULL;
-  if (font_button->priv->show_style) 
+  if (font_button->priv->show_style && family
     {
       PangoFontFamily **families;
       PangoFontFace **faces;
       gint n_families, n_faces, i;
 
       n_families = 0;
+      families = NULL;
       pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (font_button)),
                                    &families, &n_families);
       n_faces = 0;
@@ -923,8 +902,8 @@ gtk_font_button_update_font_info (GtkFontButton *font_button)
 
   if (font_button->priv->show_size) 
     {
-      gchar *size = g_strdup_printf ("%d", 
-                                     pango_font_description_get_size (desc) / PANGO_SCALE);
+      gchar *size = g_strdup_printf ("%g",
+                                     pango_font_description_get_size (desc) / (double)PANGO_SCALE);
       
       gtk_label_set_text (GTK_LABEL (font_button->priv->size_label), size);
       
@@ -936,10 +915,5 @@ gtk_font_button_update_font_info (GtkFontButton *font_button)
   pango_font_description_free (desc);
 } 
 
-
-
-
-
-
-
-
+#define __GTK_FONT_BUTTON_C__
+#include "gtkaliasdef.c"