Commit 04d9d5bd authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann
Browse files

libgimpwidgets/gimpcolorarea.c more object properties.

2005-05-20  Sven Neumann  <sven@gimp.org>

	* libgimpwidgets/gimpcolorarea.c
	* libgimpwidgets/gimpcolorbutton.c: more object properties.
parent 6bd6a444
2005-05-20 Sven Neumann <sven@gimp.org>
* libgimpwidgets/gimpcolorarea.c
* libgimpwidgets/gimpcolorbutton.c: more object properties.
2005-05-20 Sven Neumann <sven@gimp.org> 2005-05-20 Sven Neumann <sven@gimp.org>
* libgimpwidgets/Makefile.am * libgimpwidgets/Makefile.am
......
...@@ -45,28 +45,30 @@ enum ...@@ -45,28 +45,30 @@ enum
enum enum
{ {
PROP_0, PROP_0,
PROP_TYPE PROP_COLOR,
PROP_TYPE,
PROP_DRAG_MASK
}; };
static void gimp_color_area_class_init (GimpColorAreaClass *klass); static void gimp_color_area_class_init (GimpColorAreaClass *klass);
static void gimp_color_area_init (GimpColorArea *area); static void gimp_color_area_init (GimpColorArea *area);
static void gimp_color_area_get_property (GObject *object, static void gimp_color_area_get_property (GObject *object,
guint property_id, guint property_id,
GValue *value, GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_color_area_set_property (GObject *object, static void gimp_color_area_set_property (GObject *object,
guint property_id, guint property_id,
const GValue *value, const GValue *value,
GParamSpec *pspec); GParamSpec *pspec);
static void gimp_color_area_finalize (GObject *object); static void gimp_color_area_finalize (GObject *object);
static void gimp_color_area_size_allocate (GtkWidget *widget, static void gimp_color_area_size_allocate (GtkWidget *widget,
GtkAllocation *allocation); GtkAllocation *allocation);
static gboolean gimp_color_area_expose (GtkWidget *widget, static gboolean gimp_color_area_expose (GtkWidget *widget,
GdkEventExpose *event); GdkEventExpose *event);
static void gimp_color_area_render (GimpColorArea *area); static void gimp_color_area_render (GimpColorArea *area);
static void gimp_color_area_drag_begin (GtkWidget *widget, static void gimp_color_area_drag_begin (GtkWidget *widget,
GdkDragContext *context); GdkDragContext *context);
...@@ -126,6 +128,7 @@ gimp_color_area_class_init (GimpColorAreaClass *klass) ...@@ -126,6 +128,7 @@ gimp_color_area_class_init (GimpColorAreaClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GimpRGB color;
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
...@@ -152,6 +155,20 @@ gimp_color_area_class_init (GimpColorAreaClass *klass) ...@@ -152,6 +155,20 @@ gimp_color_area_class_init (GimpColorAreaClass *klass)
klass->color_changed = NULL; klass->color_changed = NULL;
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
/**
* GimpColorArea:color:
*
* The color displayed in the color area.
*
* Since: GIMP 2.4
*/
g_object_class_install_property (object_class, PROP_COLOR,
gimp_param_spec_rgb ("color", NULL, NULL,
&color,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
/** /**
* GimpColorArea:type: * GimpColorArea:type:
* *
...@@ -165,6 +182,19 @@ gimp_color_area_class_init (GimpColorAreaClass *klass) ...@@ -165,6 +182,19 @@ gimp_color_area_class_init (GimpColorAreaClass *klass)
GIMP_COLOR_AREA_FLAT, GIMP_COLOR_AREA_FLAT,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT)); G_PARAM_CONSTRUCT));
/**
* GimpColorArea:drag-type:
*
* The event_mask that should trigger drags.
*
* Since: GIMP 2.4
*/
g_object_class_install_property (object_class, PROP_DRAG_MASK,
g_param_spec_flags ("drag-mask", NULL, NULL,
GDK_TYPE_MODIFIER_TYPE,
0,
G_PARAM_WRITABLE |
G_PARAM_CONSTRUCT_ONLY));
} }
static void static void
...@@ -176,7 +206,12 @@ gimp_color_area_init (GimpColorArea *area) ...@@ -176,7 +206,12 @@ gimp_color_area_init (GimpColorArea *area)
area->rowstride = 0; area->rowstride = 0;
area->draw_border = FALSE; area->draw_border = FALSE;
gimp_rgba_set (&area->color, 0.0, 0.0, 0.0, 1.0); gtk_drag_dest_set (GTK_WIDGET (area),
GTK_DEST_DEFAULT_HIGHLIGHT |
GTK_DEST_DEFAULT_MOTION |
GTK_DEST_DEFAULT_DROP,
&target, 1,
GDK_ACTION_COPY);
} }
static void static void
...@@ -203,6 +238,10 @@ gimp_color_area_get_property (GObject *object, ...@@ -203,6 +238,10 @@ gimp_color_area_get_property (GObject *object,
switch (property_id) switch (property_id)
{ {
case PROP_COLOR:
g_value_set_boxed (value, &area->color);
break;
case PROP_TYPE: case PROP_TYPE:
g_value_set_enum (value, area->type); g_value_set_enum (value, area->type);
break; break;
...@@ -219,14 +258,30 @@ gimp_color_area_set_property (GObject *object, ...@@ -219,14 +258,30 @@ gimp_color_area_set_property (GObject *object,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GimpColorArea *area = GIMP_COLOR_AREA (object); GimpColorArea *area = GIMP_COLOR_AREA (object);
GdkModifierType drag_mask;
switch (property_id) switch (property_id)
{ {
case PROP_COLOR:
gimp_color_area_set_color (area, g_value_get_boxed (value));
break;
case PROP_TYPE: case PROP_TYPE:
gimp_color_area_set_type (area, g_value_get_enum (value)); gimp_color_area_set_type (area, g_value_get_enum (value));
break; break;
case PROP_DRAG_MASK:
drag_mask = g_value_get_flags (value) & (GDK_BUTTON1_MASK |
GDK_BUTTON2_MASK |
GDK_BUTTON3_MASK);
if (drag_mask)
gtk_drag_source_set (GTK_WIDGET (area),
drag_mask,
&target, 1,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
...@@ -312,32 +367,11 @@ gimp_color_area_new (const GimpRGB *color, ...@@ -312,32 +367,11 @@ gimp_color_area_new (const GimpRGB *color,
GimpColorAreaType type, GimpColorAreaType type,
GdkModifierType drag_mask) GdkModifierType drag_mask)
{ {
GimpColorArea *area; return g_object_new (GIMP_TYPE_COLOR_AREA,
"color", color,
g_return_val_if_fail (color != NULL, NULL); "type", type,
"drag-mask", drag_mask,
area = g_object_new (GIMP_TYPE_COLOR_AREA,
"type", type,
NULL); NULL);
area->color = *color;
gtk_drag_dest_set (GTK_WIDGET (area),
GTK_DEST_DEFAULT_HIGHLIGHT |
GTK_DEST_DEFAULT_MOTION |
GTK_DEST_DEFAULT_DROP,
&target, 1,
GDK_ACTION_COPY);
drag_mask &= (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK);
if (drag_mask)
gtk_drag_source_set (GTK_WIDGET (area),
drag_mask,
&target, 1,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
return GTK_WIDGET (area);
} }
/** /**
...@@ -370,6 +404,8 @@ gimp_color_area_set_color (GimpColorArea *area, ...@@ -370,6 +404,8 @@ gimp_color_area_set_color (GimpColorArea *area,
area->needs_render = TRUE; area->needs_render = TRUE;
gtk_widget_queue_draw (GTK_WIDGET (area)); gtk_widget_queue_draw (GTK_WIDGET (area));
g_object_notify (G_OBJECT (area), "color");
g_signal_emit (area, gimp_color_area_signals[COLOR_CHANGED], 0); g_signal_emit (area, gimp_color_area_signals[COLOR_CHANGED], 0);
} }
......
...@@ -64,7 +64,10 @@ enum ...@@ -64,7 +64,10 @@ enum
enum enum
{ {
PROP_0, PROP_0,
PROP_TITLE PROP_TITLE,
PROP_COLOR,
PROP_TYPE,
PROP_UPDATE
}; };
...@@ -104,7 +107,7 @@ static void gimp_color_button_help_func (const gchar *help_id, ...@@ -104,7 +107,7 @@ static void gimp_color_button_help_func (const gchar *help_id,
gpointer help_data); gpointer help_data);
static GtkActionEntry actions[] = static const GtkActionEntry actions[] =
{ {
{ "color-button-popup", NULL, { "color-button-popup", NULL,
"Color Button Menu", NULL, NULL, "Color Button Menu", NULL, NULL,
...@@ -169,6 +172,7 @@ gimp_color_button_class_init (GimpColorButtonClass *klass) ...@@ -169,6 +172,7 @@ gimp_color_button_class_init (GimpColorButtonClass *klass)
GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass); GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass); GtkButtonClass *button_class = GTK_BUTTON_CLASS (klass);
GimpRGB color;
parent_class = g_type_class_peek_parent (klass); parent_class = g_type_class_peek_parent (klass);
...@@ -195,6 +199,8 @@ gimp_color_button_class_init (GimpColorButtonClass *klass) ...@@ -195,6 +199,8 @@ gimp_color_button_class_init (GimpColorButtonClass *klass)
klass->color_changed = NULL; klass->color_changed = NULL;
klass->get_action_type = gimp_color_button_get_action_type; klass->get_action_type = gimp_color_button_get_action_type;
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
/** /**
* GimpColorButton:title: * GimpColorButton:title:
* *
...@@ -207,6 +213,44 @@ gimp_color_button_class_init (GimpColorButtonClass *klass) ...@@ -207,6 +213,44 @@ gimp_color_button_class_init (GimpColorButtonClass *klass)
NULL, NULL,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT_ONLY)); G_PARAM_CONSTRUCT_ONLY));
/**
* GimpColorButton:color:
*
* The color displayed in the button's color area.
*
* Since: GIMP 2.4
*/
g_object_class_install_property (object_class, PROP_COLOR,
gimp_param_spec_rgb ("color", NULL, NULL,
&color,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
/**
* GimpColorButton:type:
*
* The type of the button's color area.
*
* Since: GIMP 2.4
*/
g_object_class_install_property (object_class, PROP_TYPE,
g_param_spec_enum ("type", NULL, NULL,
GIMP_TYPE_COLOR_AREA_TYPE,
GIMP_COLOR_AREA_FLAT,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
/**
* GimpColorButton:continuous-update:
*
* The update policy of the color button.
*
* Since: GIMP 2.4
*/
g_object_class_install_property (object_class, PROP_UPDATE,
g_param_spec_boolean ("continuous-update",
NULL, NULL,
FALSE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT));
} }
static void static void
...@@ -215,15 +259,15 @@ gimp_color_button_init (GimpColorButton *button, ...@@ -215,15 +259,15 @@ gimp_color_button_init (GimpColorButton *button,
{ {
GtkActionGroup *group; GtkActionGroup *group;
GtkUIManager *ui_manager; GtkUIManager *ui_manager;
GimpRGB color;
gint i; gint i;
button->continuous_update = FALSE; button->title = NULL;
button->title = NULL; button->dialog = NULL;
button->dialog = NULL;
button->color_area = g_object_new (GIMP_TYPE_COLOR_AREA,
"drag-mask", GDK_BUTTON2_MASK,
NULL);
gimp_rgba_set (&color, 0.0, 0.0, 0.0, 1.0);
button->color_area = gimp_color_area_new (&color, FALSE, GDK_BUTTON2_MASK);
g_signal_connect (button->color_area, "color_changed", g_signal_connect (button->color_area, "color_changed",
G_CALLBACK (gimp_color_button_area_changed), G_CALLBACK (gimp_color_button_area_changed),
button); button);
...@@ -305,6 +349,18 @@ gimp_color_button_get_property (GObject *object, ...@@ -305,6 +349,18 @@ gimp_color_button_get_property (GObject *object,
g_value_set_string (value, button->title); g_value_set_string (value, button->title);
break; break;
case PROP_COLOR:
g_object_get_property (G_OBJECT (button->color_area), "color", value);
break;
case PROP_TYPE:
g_object_get_property (G_OBJECT (button->color_area), "type", value);
break;
case PROP_UPDATE:
g_value_set_boolean (value, button->continuous_update);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
...@@ -326,6 +382,18 @@ gimp_color_button_set_property (GObject *object, ...@@ -326,6 +382,18 @@ gimp_color_button_set_property (GObject *object,
button->title = g_value_dup_string (value); button->title = g_value_dup_string (value);
break; break;
case PROP_COLOR:
g_object_set_property (G_OBJECT (button->color_area), "color", value);
break;
case PROP_TYPE:
g_object_set_property (G_OBJECT (button->color_area), "type", value);
break;
case PROP_UPDATE:
gimp_color_button_set_update (button, g_value_get_boolean (value));
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break; break;
...@@ -493,13 +561,12 @@ gimp_color_button_new (const gchar *title, ...@@ -493,13 +561,12 @@ gimp_color_button_new (const gchar *title,
button = g_object_new (GIMP_TYPE_COLOR_BUTTON, button = g_object_new (GIMP_TYPE_COLOR_BUTTON,
"title", title, "title", title,
"type", type,
"color", color,
NULL); NULL);
gtk_widget_set_size_request (GTK_WIDGET (button->color_area), width, height); gtk_widget_set_size_request (GTK_WIDGET (button->color_area), width, height);
gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color);
return GTK_WIDGET (button); return GTK_WIDGET (button);
} }
...@@ -518,6 +585,8 @@ gimp_color_button_set_color (GimpColorButton *button, ...@@ -518,6 +585,8 @@ gimp_color_button_set_color (GimpColorButton *button,
g_return_if_fail (color != NULL); g_return_if_fail (color != NULL);
gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color); gimp_color_area_set_color (GIMP_COLOR_AREA (button->color_area), color);
g_object_notify (G_OBJECT (button), "color");
} }
/** /**
...@@ -568,6 +637,8 @@ gimp_color_button_set_type (GimpColorButton *button, ...@@ -568,6 +637,8 @@ gimp_color_button_set_type (GimpColorButton *button,
g_return_if_fail (GIMP_IS_COLOR_BUTTON (button)); g_return_if_fail (GIMP_IS_COLOR_BUTTON (button));
gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type); gimp_color_area_set_type (GIMP_COLOR_AREA (button->color_area), type);
g_object_notify (G_OBJECT (button), "type");
} }
/** /**
...@@ -624,6 +695,8 @@ gimp_color_button_set_update (GimpColorButton *button, ...@@ -624,6 +695,8 @@ gimp_color_button_set_update (GimpColorButton *button,
gimp_color_button_set_color (button, &color); gimp_color_button_set_color (button, &color);
} }
} }
g_object_notify (G_OBJECT (button), "continuous-update");
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment