]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkfontbutton.c
Use gtk_box_new() instead gtk_[v|h]box_new()
[~andy/gtk] / gtk / gtkfontbutton.c
index 91f05d23f141a08fd1b39f6048442f352eca8a09..e3458ff3cb59dff33b6279b2eee2aba863766f9d 100644 (file)
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 
 #include "gtkfontbutton.h"
 
-#include "gtksignal.h"
 #include "gtkmain.h"
 #include "gtkalignment.h"
 #include "gtkhbox.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
-#include "gtkalias.h"
 
 #include <string.h>
 #include <stdio.h>
 
-#define GTK_FONT_BUTTON_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_FONT_BUTTON, GtkFontButtonPrivate))
 
 struct _GtkFontButtonPrivate 
 {
@@ -84,8 +81,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,
@@ -111,37 +106,9 @@ 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, I_("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)
@@ -152,8 +119,6 @@ gtk_font_button_class_init (GtkFontButtonClass *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;
@@ -263,9 +228,13 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
    * 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
    */
@@ -283,7 +252,9 @@ gtk_font_button_class_init (GtkFontButtonClass *klass)
 static void
 gtk_font_button_init (GtkFontButton *font_button)
 {
-  font_button->priv = GTK_FONT_BUTTON_GET_PRIVATE (font_button);
+  font_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (font_button,
+                                                   GTK_TYPE_FONT_BUTTON,
+                                                   GtkFontButtonPrivate);
 
   /* Initialize fields */
   font_button->priv->fontname = g_strdup (_("Sans 12"));
@@ -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);
 } 
 
 /**
@@ -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.
  *
@@ -729,22 +705,24 @@ 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);
-
-      g_signal_connect (font_dialog->ok_button, "clicked",
+      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 (gtk_font_selection_dialog_get_ok_button (font_dialog), "clicked",
                         G_CALLBACK (dialog_ok_clicked), font_button);
-      g_signal_connect (font_dialog->cancel_button, "clicked",
+      g_signal_connect (gtk_font_selection_dialog_get_cancel_button (font_dialog), "clicked",
                        G_CALLBACK (dialog_cancel_clicked), font_button);
       g_signal_connect (font_dialog, "destroy",
                         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);
       
@@ -802,7 +780,7 @@ gtk_font_button_create_inside (GtkFontButton *font_button)
   
   gtk_widget_push_composite_child ();
 
-  widget = gtk_hbox_new (FALSE, 0);
+  widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 0);
   
   font_button->priv->font_label = gtk_label_new (_("Font"));
   
@@ -811,7 +789,7 @@ gtk_font_button_create_inside (GtkFontButton *font_button)
 
   if (font_button->priv->show_size) 
     {
-      gtk_box_pack_start (GTK_BOX (widget), gtk_vseparator_new (), FALSE, FALSE, 0);
+      gtk_box_pack_start (GTK_BOX (widget), gtk_separator_new (GTK_ORIENTATION_VERTICAL), FALSE, FALSE, 0);
       font_button->priv->size_label = gtk_label_new ("14");
       gtk_box_pack_start (GTK_BOX (widget), font_button->priv->size_label, FALSE, FALSE, 5);
     }
@@ -879,6 +857,7 @@ gtk_font_button_update_font_info (GtkFontButton *font_button)
       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;
@@ -935,6 +914,3 @@ gtk_font_button_update_font_info (GtkFontButton *font_button)
   
   pango_font_description_free (desc);
 } 
-
-#define __GTK_FONT_BUTTON_C__
-#include "gtkaliasdef.c"