* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
+#include "config.h"
#include "gtkcolorbutton.h"
#include "gdk/gdkkeysyms.h"
#include "gtkdnd.h"
#include "gtkdrawingarea.h"
#include "gtkframe.h"
-#include "gtksignal.h"
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkintl.h"
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,
/* 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,
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)
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;
* 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),
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;
{
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))
{
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);
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 ();
{
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;
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);
}
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);
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);