]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcolorbutton.c
Updated Slovenian translation
[~andy/gtk] / gtk / gtkcolorbutton.c
index c41f708ad47599a39fb46905b0763ce36a9f4569..081e687cbaed1411eed71f1682968d6b3f09fd3f 100644 (file)
@@ -28,7 +28,7 @@
  * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
  */
 
-#include <config.h>
+#include "config.h"
 
 #include "gtkcolorbutton.h"
 #include "gdk/gdkkeysyms.h"
@@ -41,7 +41,6 @@
 #include "gtkdnd.h"
 #include "gtkdrawingarea.h"
 #include "gtkframe.h"
-#include "gtksignal.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
 #include "gtkintl.h"
@@ -87,9 +86,6 @@ enum
   LAST_SIGNAL
 };
 
-static void gtk_color_button_class_init    (GtkColorButtonClass *klass);
-static void gtk_color_button_init          (GtkColorButton      *color_button);
-
 /* gobject signals */
 static void gtk_color_button_finalize      (GObject             *object);
 static void gtk_color_button_set_property  (GObject        *object,
@@ -103,6 +99,7 @@ static void gtk_color_button_get_property  (GObject        *object,
 
 /* gtkwidget signals */
 static void gtk_color_button_realize       (GtkWidget *widget);
+static void gtk_color_button_unrealize     (GtkWidget *widget);
 static void gtk_color_button_state_changed (GtkWidget           *widget, 
                                            GtkStateType         previous_state);
 static void gtk_color_button_style_set     (GtkWidget *widget, 
@@ -133,38 +130,11 @@ static void gtk_color_button_drag_data_received (GtkWidget        *widget,
                                                 GtkColorButton   *color_button);
 
 
-static gpointer parent_class = NULL;
 static guint color_button_signals[LAST_SIGNAL] = { 0 };
 
 static const GtkTargetEntry drop_types[] = { { "application/x-color", 0, 0 } };
 
-GType
-gtk_color_button_get_type (void)
-{
-  static GType color_button_type = 0;
-  
-  if (!color_button_type)
-    {
-      static const GTypeInfo color_button_info =
-      {
-        sizeof (GtkColorButtonClass),
-        NULL,           /* base_init */
-        NULL,           /* base_finalize */
-        (GClassInitFunc) gtk_color_button_class_init,
-        NULL,           /* class_finalize */
-        NULL,           /* class_data */
-        sizeof (GtkColorButton),
-        0,              /* n_preallocs */
-        (GInstanceInitFunc) gtk_color_button_init,
-      };
-      
-      color_button_type =
-        g_type_register_static (GTK_TYPE_BUTTON, I_("GtkColorButton"),
-                                &color_button_info, 0);
-    }
-  
-  return color_button_type;
-}
+G_DEFINE_TYPE (GtkColorButton, gtk_color_button, GTK_TYPE_BUTTON)
 
 static void
 gtk_color_button_class_init (GtkColorButtonClass *klass)
@@ -177,13 +147,12 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
   widget_class = GTK_WIDGET_CLASS (klass);
   button_class = GTK_BUTTON_CLASS (klass);
 
-  parent_class = g_type_class_peek_parent (klass);
-
   gobject_class->get_property = gtk_color_button_get_property;
   gobject_class->set_property = gtk_color_button_set_property;
   gobject_class->finalize = gtk_color_button_finalize;
   widget_class->state_changed = gtk_color_button_state_changed;
   widget_class->realize = gtk_color_button_realize;
+  widget_class->unrealize = gtk_color_button_unrealize;
   widget_class->style_set = gtk_color_button_style_set;
   button_class->clicked = gtk_color_button_clicked;
   klass->color_set = NULL;
@@ -253,13 +222,17 @@ gtk_color_button_class_init (GtkColorButtonClass *klass)
    * GtkColorButton::color-set:
    * @widget: the object which received the signal.
    * 
-   * The ::color-set signal is emitted when the user selects a color. When handling this signal,
-   * use gtk_color_button_get_color() and gtk_color_button_get_alpha() to find out which color 
-   * was just selected.
+   * The ::color-set signal is emitted when the user selects a color. 
+   * When handling this signal, use gtk_color_button_get_color() and 
+   * gtk_color_button_get_alpha() to find out which color was just selected.
+   *
+   * Note that this signal is only emitted when the <emphasis>user</emphasis>
+   * changes the color. If you need to react to programmatic color changes
+   * as well, use the notify::color signal.
    *
    * Since: 2.4
    */
-  color_button_signals[COLOR_SET] = g_signal_new (I_("color_set"),
+  color_button_signals[COLOR_SET] = g_signal_new (I_("color-set"),
                                                  G_TYPE_FROM_CLASS (gobject_class),
                                                  G_SIGNAL_RUN_FIRST,
                                                  G_STRUCT_OFFSET (GtkColorButtonClass, color_set),
@@ -346,7 +319,7 @@ render (GtkColorButton *color_button)
       
     for (i = 0; i < width; i++) 
       {
-        if (!GTK_WIDGET_SENSITIVE (GTK_WIDGET (color_button)) && (i+j)%2) 
+        if (!GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (color_button)) && (i+j)%2) 
           {
             *(pixels + j * rowstride + i * 3) = insensitive_r;
             *(pixels + j * rowstride + i * 3 + 1) = insensitive_g;
@@ -404,21 +377,31 @@ gtk_color_button_realize (GtkWidget *widget)
 {
   GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
 
-  GTK_WIDGET_CLASS (parent_class)->realize (widget);
+  GTK_WIDGET_CLASS (gtk_color_button_parent_class)->realize (widget);
 
-  if (color_button->priv->gc == NULL)
-    color_button->priv->gc = gdk_gc_new (widget->window);
+  color_button->priv->gc = gdk_gc_new (widget->window);
 
   render (color_button);
 }
 
+static void
+gtk_color_button_unrealize (GtkWidget *widget)
+{
+  GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
+
+  g_object_unref (color_button->priv->gc);
+  color_button->priv->gc = NULL;
+
+  GTK_WIDGET_CLASS (gtk_color_button_parent_class)->unrealize (widget);
+}
+
 static void
 gtk_color_button_style_set (GtkWidget *widget, 
                            GtkStyle  *previous_style)
 {
   GtkColorButton *color_button = GTK_COLOR_BUTTON (widget);
 
-  GTK_WIDGET_CLASS (parent_class)->style_set (widget, previous_style);
+  GTK_WIDGET_CLASS (gtk_color_button_parent_class)->style_set (widget, previous_style);
 
   if (GTK_WIDGET_REALIZED (widget)) 
     {
@@ -565,6 +548,8 @@ gtk_color_button_init (GtkColorButton *color_button)
 
   layout = gtk_widget_create_pango_layout (GTK_WIDGET (color_button), "Black");
   pango_layout_get_pixel_extents (layout, NULL, &rect);
+  g_object_unref (layout);
+
   gtk_widget_set_size_request (color_button->priv->draw_area, rect.width - 2, rect.height - 2);
   g_signal_connect (color_button->priv->draw_area, "expose-event",
                     G_CALLBACK (expose_event), color_button);
@@ -597,11 +582,11 @@ gtk_color_button_init (GtkColorButton *color_button)
                        GDK_BUTTON1_MASK|GDK_BUTTON3_MASK,
                        drop_types, 1,
                        GDK_ACTION_COPY);
-  g_signal_connect (color_button, "drag_begin",
+  g_signal_connect (color_button, "drag-begin",
                    G_CALLBACK (gtk_color_button_drag_begin), color_button);
-  g_signal_connect (color_button, "drag_data_received",
+  g_signal_connect (color_button, "drag-data-received",
                     G_CALLBACK (gtk_color_button_drag_data_received), color_button);
-  g_signal_connect (color_button, "drag_data_get",
+  g_signal_connect (color_button, "drag-data-get",
                     G_CALLBACK (gtk_color_button_drag_data_get), color_button);
 
   gtk_widget_pop_composite_child ();
@@ -612,10 +597,6 @@ gtk_color_button_finalize (GObject *object)
 {
   GtkColorButton *color_button = GTK_COLOR_BUTTON (object);
 
-  if (color_button->priv->gc != NULL)
-    g_object_unref (color_button->priv->gc);
-  color_button->priv->gc = NULL;
-
   if (color_button->priv->cs_dialog != NULL)
     gtk_widget_destroy (color_button->priv->cs_dialog);
   color_button->priv->cs_dialog = NULL;
@@ -627,7 +608,7 @@ gtk_color_button_finalize (GObject *object)
   g_free (color_button->priv->title);
   color_button->priv->title = NULL;
 
-  G_OBJECT_CLASS (parent_class)->finalize (object);
+  G_OBJECT_CLASS (gtk_color_button_parent_class)->finalize (object);
 }
 
 
@@ -732,9 +713,14 @@ gtk_color_button_clicked (GtkButton *button)
       
       color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);
 
-      if (parent)
-        gtk_window_set_transient_for (GTK_WINDOW (color_dialog),
-                                      GTK_WINDOW (parent));
+      if (GTK_WIDGET_TOPLEVEL (parent) && GTK_IS_WINDOW (parent))
+        {
+          if (GTK_WINDOW (parent) != gtk_window_get_transient_for (GTK_WINDOW (color_dialog)))
+           gtk_window_set_transient_for (GTK_WINDOW (color_dialog), GTK_WINDOW (parent));
+              
+         gtk_window_set_modal (GTK_WINDOW (color_dialog),
+                               gtk_window_get_modal (GTK_WINDOW (parent)));
+       }
       
       g_signal_connect (color_dialog->ok_button, "clicked",
                         G_CALLBACK (dialog_ok_clicked), color_button);
@@ -742,10 +728,6 @@ gtk_color_button_clicked (GtkButton *button)
                        G_CALLBACK (dialog_cancel_clicked), color_button);
       g_signal_connect (color_dialog, "destroy",
                         G_CALLBACK (dialog_destroy), color_button);
-      
-      /* If there is a grabbed window, set new dialog as modal */
-      if (gtk_grab_get_current ())
-        gtk_window_set_modal (GTK_WINDOW (color_button->priv->cs_dialog),TRUE);
     }
 
   color_dialog = GTK_COLOR_SELECTION_DIALOG (color_button->priv->cs_dialog);