2 * This file is part of hildon-libs
4 * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
6 * Author: Kuisma Salonen <kuisma.salonen@nokia.com>
7 * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; version 2.1 of
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * SECTION:hildon-color-chooser
29 * @short_description: A widget to choose a color.
30 * @see_also: #HildonColorChooserDialog, #HildonColorButton
32 * HildonColorChooser is a widget to choose a color.
37 #include "hildon-color-chooser.h"
39 #include "hildon-plugin-widget.h"
48 static HildonPluginWidgetInfo *global_plugin = NULL;
51 static guint color_chooser_signals[LAST_SIGNAL] = { 0 };
54 static void hildon_color_chooser_init(HildonColorChooser *sel);
55 static void hildon_color_chooser_class_init(HildonColorChooserClass *klass);
58 GtkType hildon_color_chooser_get_type ()
60 static GtkType chooser_type = 0;
64 static const GtkTypeInfo chooser_info =
67 sizeof (HildonColorChooser),
68 sizeof (HildonColorChooserClass),
69 (GtkClassInitFunc) hildon_color_chooser_class_init,
70 (GtkObjectInitFunc) hildon_color_chooser_init,
71 /* reserved_1 */ NULL,
72 /* reserved_1 */ NULL,
73 (GtkClassInitFunc) NULL
76 chooser_type = gtk_type_unique (GTK_TYPE_WIDGET, &chooser_info);
83 static void hildon_color_chooser_init(HildonColorChooser *sel)
85 sel->color.red = 0x0000;
86 sel->color.green = 0x0000;
87 sel->color.blue = 0x0000;
88 sel->color.pixel = 0x00000000;
91 static void hildon_color_chooser_class_init(HildonColorChooserClass *klass)
93 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
94 GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass);
96 klass->set_color = NULL;
99 gtk_widget_class_install_style_property(widget_class,
100 g_param_spec_boxed("outer_border",
102 "Size of outer border",
106 color_chooser_signals[COLOR_CHANGED] = g_signal_new("color-changed", G_OBJECT_CLASS_TYPE (object_class),
107 G_SIGNAL_RUN_FIRST, G_STRUCT_OFFSET (HildonColorChooserClass, color_changed),
108 NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GDK_TYPE_COLOR);
112 * hildon_color_chooser_new:
114 * Creates a new color chooser widget. The dialog is created through
115 * HildonPluginWidget API and is loaded from plugin. The initially selected
116 * color can be anything, so it's recommended to call
117 * hildon_color_chooser_dialog_set_color () after creating the widget.
119 * Returns: a new color chooser widget
121 GtkWidget *hildon_color_chooser_new()
124 global_plugin = hildon_plugin_info_initialize(HILDON_TYPE_COLOR_CHOOSER, NULL);
128 return hildon_plugin_info_construct_widget(global_plugin);
132 * hildon_color_chooser_set_color:
133 * @chooser: a #HildonColorChooser
134 * @color: a color to be set
136 * Sets the color selected in the widget.
138 void hildon_color_chooser_set_color(HildonColorChooser *chooser, GdkColor *color)
140 HildonColorChooserClass *klass = HILDON_COLOR_CHOOSER_CLASS(G_OBJECT_GET_CLASS(chooser));
143 chooser->color = *color;
145 if(klass->set_color) {
146 klass->set_color(chooser, color);
151 * hildon_color_chooser_get_color:
152 * @chooser: a #HildonColorChooser
153 * @color: a pointer to #GdkColor to be filled by the function
155 * Gets the color selected in the widget.
157 void hildon_color_chooser_get_color(HildonColorChooser *chooser, GdkColor *color)
159 *color = chooser->color;
163 void hildon_color_chooser_emit_color_changed(HildonColorChooser *chooser)
165 g_signal_emit(chooser, color_chooser_signals[COLOR_CHANGED], 0, &chooser->color);