2007-01-03 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+ * plugins:
+ * plugins/Makefile.am:
+ * plugins/hildon-color-chooser-dialog-hsv.c:
+ * plugins/hildon-color-chooser-hsv.c:
+ * src/Makefile.am:
+ * src/hildon-plugin-widget.c:
+ * src/hildon-plugin-widget.h: Removing old plugin bits.
+
+2007-01-03 Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+
* src/Makefile.am:
* src/hildon-color-button-private.h:
* src/hildon-color-button.c:
+++ /dev/null
-MAINTAINERCLEANFILES = Makefile.in
-
-INCLUDES = $(GTK_CFLAGS) $(GCONF_CFLAGS) -DLOCALEDIR=\"$(localedir)\" \
- -I$(srcdir)/..
-
-#LDFLAGS = -module -avoid-version
-#LIBADD = -L$(srcdir)/../hildon-widgets/.libs -lhildonwidgets $(GTK_LIBS)
-
-pluginwidgetdir = $(libdir)/hildon-widgets
-pluginwidget_LTLIBRARIES = hildoncolorchooser_hsv.la \
- hildoncolorchooserdialog_hsv.la
-
-hildoncolorchooser_hsv_la_SOURCES = hildon-color-chooser-hsv.c
-
-hildoncolorchooserdialog_hsv_la_SOURCES = hildon-color-chooser-dialog-hsv.c
-hildoncolorchooserdialog_hsv_la_LIBADD = $(GCONF_LIBS)
-
-install-exec-local: installdirs
- @echo "Creating default symlink for color chooser..."
- @ln -f -s 'hildoncolorchooser_hsv.so' '$(DESTDIR)/$(libdir)/hildon-widgets/hildoncolorchooser_default.so'
- @echo "Creating default symlink for color chooser dialog..."
- @ln -f -s 'hildoncolorchooserdialog_hsv.so' '$(DESTDIR)/$(libdir)/hildon-widgets/hildoncolorchooserdialog_default.so'
-
-
-
-
-
+++ /dev/null
-/*
- * This file is part of hildon-libs
- *
- * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
- *
- * Author: Kuisma Salonen <kuisma.salonen@nokia.com>
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; version 2.1 of
- * the License.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-
-#include <memory.h>
-#include <string.h>
-
-#include <libintl.h>
-
-#include <gdk/gdk.h>
-#include <gdk/gdkkeysyms.h>
-
-#include <gtk/gtk.h>
-
-#include <gconf/gconf-client.h>
-
-
-#include <hildon-widgets/hildon-color-chooser-dialog.h>
-#include <hildon-widgets/hildon-color-chooser.h>
-
-#include <hildon-widgets/hildon-plugin-widget.h>
-
-#include <hildon-widgets/hildon-defines.h>
-
-#include <hildon-widgets/hildon-banner.h>
-
-
-#define _(String) dgettext("hildon-libs", String)
-
-
-const char *parent_name = "HildonColorChooserDialog";
-const char *plugin_name = "HSV color chooser dialog";
-
-GType export_type(void);
-
-
-static HildonPluginWidgetInfo *chooser_plugin = NULL;
-
-static HildonColorChooserDialogClass *parent_klass = NULL;
-
-
-/* darkened EGA palette to be used as predefined colors if style doesn't
- define anything else (darker colors are darkened 0x8000 -> 0x6666) */
-static GdkColor hardcoded_colors[16] = {{0, 0x0000, 0x0000, 0x0000},
- {0, 0x6666, 0x6666, 0x6666},
- {0, 0x6666, 0x0000, 0x0000},
- {0, 0x0000, 0x6666, 0x0000},
- {0, 0x0000, 0x0000, 0x6666},
- {0, 0x6666, 0x6666, 0x0000},
- {0, 0x6666, 0x0000, 0x6666},
- {0, 0x0000, 0x6666, 0x6666},
- {0, 0xffff, 0xffff, 0xffff},
- {0, 0xc000, 0xc000, 0xc000},
- {0, 0xffff, 0x0000, 0x0000},
- {0, 0x0000, 0xffff, 0x0000},
- {0, 0x0000, 0x0000, 0xffff},
- {0, 0xffff, 0xffff, 0x0000},
- {0, 0xffff, 0x0000, 0xffff},
- {0, 0x0000, 0xffff, 0xffff}};
-
-
-typedef struct {
- GtkBorder radio_sizes;
- GtkBorder cont_sizes;
- GtkBorder num_buttons;
- GtkBorder last_num_buttons;
-
- GdkColor default_color;
-} HildonColorChooserStyleInfo;
-
-
-typedef struct _HildonColorChooserDialogHSV HildonColorChooserDialogHSV;
-typedef struct _HildonColorChooserDialogHSVClass HildonColorChooserDialogHSVClass;
-
-
-struct _HildonColorChooserDialogHSV {
- HildonColorChooserDialog parent;
-
- GtkWidget *hbox;
- GtkWidget *vbox;
-
- GtkWidget *align_custom, *align_defined;
- GtkWidget *area_custom, *area_defined;
- GtkWidget *separator;
-
- GtkWidget *chooser;
-
- GdkColor *colors_custom, *colors_defined;
- GdkGC **gc_array;
-
- gint selected;
-
- HildonColorChooserStyleInfo style_info;
-
-
- gint has_style;
-
- GdkColor pending_color;
-
-
- struct {
- GConfClient *client;
- } gconf_data;
-};
-
-struct _HildonColorChooserDialogHSVClass {
- HildonColorChooserDialogClass parent_klass;
-};
-
-
-#define HILDON_COLOR_CHOOSER_DIALOG_HSV(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), export_type(), HildonColorChooserDialogHSV))
-#define HILDON_COLOR_CHOOSER_DIALOG_HSV_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), export_type(), HildonColorChooserDialogHSVClass))
-
-
-GtkType export_type(void);
-
-
-static void hildon_color_chooser_dialog_hsv_init(HildonColorChooserDialogHSV *object);
-static void hildon_color_chooser_dialog_hsv_class_init(HildonColorChooserDialogHSVClass *klass);
-
-static void hildon_color_chooser_dialog_hsv_size_request(GtkWidget *widget, GtkRequisition *req);
-static void hildon_color_chooser_dialog_hsv_size_allocate(GtkWidget *widget, GtkAllocation *alloc);
-
-static void hildon_color_chooser_dialog_hsv_realize(GtkWidget *widget);
-static void hildon_color_chooser_dialog_hsv_unrealize(GtkWidget *widget);
-
-static void hildon_color_chooser_dialog_hsv_style_set(GtkWidget *widget, GtkStyle *previous_style);
-
-static void hildon_color_chooser_dialog_hsv_show(GtkWidget *widget);
-static void hildon_color_chooser_dialog_hsv_show_all(GtkWidget *widget);
-
-static gboolean hildon_color_chooser_dialog_hsv_key_press_event(GtkWidget *widget, GdkEventKey *event);
-static gboolean hildon_color_chooser_dialog_hsv_key_release_event(GtkWidget *widget, GdkEventKey *event);
-
-
-static void hildon_color_chooser_dialog_hsv_destroy(GtkObject *object);
-
-
-static void hildon_color_chooser_dialog_hsv_set_color(HildonColorChooserDialog *dialog, GdkColor *color);
-
-
-static gboolean hildon_color_chooser_dialog_hsv_area_expose(GtkWidget *widget, GdkEventExpose *event, gpointer data);
-
-static gboolean hildon_color_chooser_dialog_hsv_area_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data);
-
-
-static void hildon_color_chooser_dialog_hsv_chooser_color_changed(HildonColorChooser *chooser, GdkColor *color, gpointer data);
-
-static void hildon_color_chooser_dialog_hsv_chooser_insensitive_press(GtkWidget *widget, gpointer data);
-
-
-static void hildon_color_chooser_dialog_hsv_refresh_style_info(HildonColorChooserDialogHSV *dialog);
-
-static void hildon_color_chooser_dialog_hsv_set_color_num(HildonColorChooserDialogHSV *dialog, gint num);
-
-static void hildon_color_chooser_dialog_hsv_ascii_hex_to_color(gchar *s, GdkColor *color);
-static void hildon_color_chooser_dialog_hsv_color_to_ascii_hex(gchar *s, GdkColor *color);
-
-
-GType export_type()
-{
- static GType dialog_type = 0;
-
- if (!dialog_type) {
- static const GTypeInfo dialog_info =
- {
- sizeof (HildonColorChooserDialogHSVClass),
- NULL,
- NULL,
- (GClassInitFunc) hildon_color_chooser_dialog_hsv_class_init,
- NULL,
- NULL,
- sizeof (HildonColorChooserDialogHSV),
- 0,
- (GInstanceInitFunc) hildon_color_chooser_dialog_hsv_init,
- NULL
- };
-
- dialog_type = g_type_register_static (HILDON_TYPE_COLOR_CHOOSER_DIALOG, "HildonColorChooserDialogHSV", &dialog_info, 0);
- }
-
- return dialog_type;
-}
-
-
-static void hildon_color_chooser_dialog_hsv_init(HildonColorChooserDialogHSV *object)
-{
- if(!chooser_plugin) {
- chooser_plugin = hildon_plugin_info_initialize(HILDON_TYPE_COLOR_CHOOSER, "hsv");
- }
-
-
- gtk_dialog_set_has_separator(GTK_DIALOG(object), FALSE);
-
- gtk_window_set_title(GTK_WINDOW(object), _("ecdg_ti_colour_selector"));
-
-
- object->chooser = hildon_plugin_info_construct_widget(chooser_plugin);
-
- object->hbox = gtk_hbox_new(FALSE, 0);
- object->vbox = gtk_vbox_new(FALSE, 0);
-
- gtk_box_pack_start(GTK_BOX(object->hbox), object->chooser, TRUE, TRUE, 0);
- gtk_box_pack_end(GTK_BOX(object->hbox), object->vbox, FALSE, FALSE, 0);
-
-
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(object)->vbox), object->hbox, TRUE, TRUE, 0);
-
-
- object->align_custom = gtk_alignment_new(0.5, 1.0, 0.0, 0.0);
- object->align_defined = gtk_alignment_new(0.5, 1.0, 0.0, 0.0);
-
- object->area_custom = gtk_drawing_area_new();
- object->area_defined = gtk_drawing_area_new();
-
-
- gtk_container_add(GTK_CONTAINER(object->align_custom), object->area_custom);
- gtk_container_add(GTK_CONTAINER(object->align_defined), object->area_defined);
-
-
- object->separator = gtk_hseparator_new();
-
-
- gtk_box_pack_start(GTK_BOX(object->vbox), object->align_defined, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(object->vbox), object->separator, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(object->vbox), object->align_custom, FALSE, FALSE, 0);
-
-
- gtk_dialog_add_button(GTK_DIALOG(object), _("ecdg_bd_colour_selector_ok"), GTK_RESPONSE_OK);
- gtk_dialog_add_button(GTK_DIALOG(object), _("ecdg_bd_colour_selector_cancel"), GTK_RESPONSE_CANCEL);
- gtk_dialog_set_default_response (GTK_DIALOG (object), GTK_RESPONSE_OK);
-
-
- g_signal_connect(G_OBJECT(object->chooser), "insensitive-press", G_CALLBACK(hildon_color_chooser_dialog_hsv_chooser_insensitive_press), object);
-
-
- g_signal_connect(G_OBJECT(object->area_custom), "expose-event", G_CALLBACK(hildon_color_chooser_dialog_hsv_area_expose), object);
- g_signal_connect(G_OBJECT(object->area_defined), "expose-event", G_CALLBACK(hildon_color_chooser_dialog_hsv_area_expose), object);
-
- g_signal_connect(G_OBJECT(object->area_custom), "button-press-event", G_CALLBACK(hildon_color_chooser_dialog_hsv_area_button_press), object);
- g_signal_connect(G_OBJECT(object->area_defined), "button-press-event", G_CALLBACK(hildon_color_chooser_dialog_hsv_area_button_press), object);
-
- gtk_widget_add_events(object->area_custom, GDK_BUTTON_PRESS_MASK);
- gtk_widget_add_events(object->area_defined, GDK_BUTTON_PRESS_MASK);
-
-
- object->selected = 0;
-
-
- g_signal_connect(G_OBJECT(object->chooser), "color-changed", G_CALLBACK(hildon_color_chooser_dialog_hsv_chooser_color_changed), object);
-
-
- object->gconf_data.client = gconf_client_get_default();
-
-
- memset(&object->style_info, 0, sizeof(HildonColorChooserStyleInfo));
-
-
- object->colors_custom = NULL;
- object->colors_defined = NULL;
-
- object->gc_array = NULL;
-
-
- object->has_style = 0;
-}
-
-static void hildon_color_chooser_dialog_hsv_class_init(HildonColorChooserDialogHSVClass *klass)
-{
- GtkWidgetClass *widget_klass = GTK_WIDGET_CLASS(klass);
- GtkObjectClass *object_klass = GTK_OBJECT_CLASS(klass);
- HildonColorChooserDialogClass *dialog_klass = HILDON_COLOR_CHOOSER_DIALOG_CLASS(klass);
- gchar tmp[32];
- gint i;
-
-
- widget_klass->size_request = hildon_color_chooser_dialog_hsv_size_request;
- widget_klass->size_allocate = hildon_color_chooser_dialog_hsv_size_allocate;
-
- widget_klass->realize = hildon_color_chooser_dialog_hsv_realize;
- widget_klass->unrealize = hildon_color_chooser_dialog_hsv_unrealize;
-
- widget_klass->style_set = hildon_color_chooser_dialog_hsv_style_set;
-
- widget_klass->show = hildon_color_chooser_dialog_hsv_show;
- widget_klass->show_all = hildon_color_chooser_dialog_hsv_show_all;
-
- widget_klass->key_press_event = hildon_color_chooser_dialog_hsv_key_press_event;
- widget_klass->key_release_event = hildon_color_chooser_dialog_hsv_key_release_event;
-
-
- object_klass->destroy = hildon_color_chooser_dialog_hsv_destroy;
-
-
- dialog_klass->set_color = hildon_color_chooser_dialog_hsv_set_color;
-
-
- parent_klass = g_type_class_peek_parent(klass);
-
-
- gtk_widget_class_install_style_property(widget_klass,
- g_param_spec_boxed("container_sizes",
- "Container sizes",
- "Container specific sizes",
- GTK_TYPE_BORDER,
- G_PARAM_READABLE));
-
- gtk_widget_class_install_style_property(widget_klass,
- g_param_spec_boxed("radio_sizes",
- "Color radio sizes",
- "Color radio specific sizes",
- GTK_TYPE_BORDER,
- G_PARAM_READABLE));
-
- gtk_widget_class_install_style_property(widget_klass,
- g_param_spec_boxed("num_buttons",
- "Number of buttons",
- "Number of color store buttons",
- GTK_TYPE_BORDER,
- G_PARAM_READABLE));
-
-
- gtk_widget_class_install_style_property(widget_klass,
- g_param_spec_boxed("default_color", "Default color",
- "Default color for nonpainted custom colors",
- GDK_TYPE_COLOR,
- G_PARAM_READABLE));
-
-
- for(i = 0; i < 32; i++) {
- memset(tmp, 0, 32);
- g_snprintf(tmp, 32, "defined_color%d", i);
-
- gtk_widget_class_install_style_property(widget_klass,
- g_param_spec_boxed(tmp, "Defined color",
- "Pre-defined colors for the dialog",
- GDK_TYPE_COLOR,
- G_PARAM_READABLE));
- }
-}
-
-
-static void hildon_color_chooser_dialog_hsv_size_request(GtkWidget *widget, GtkRequisition *req)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(widget);
-
-
- gtk_container_set_border_width(GTK_CONTAINER(dialog->hbox), dialog->style_info.cont_sizes.left);
-
- gtk_box_set_spacing(GTK_BOX(dialog->hbox), dialog->style_info.cont_sizes.right);
- gtk_box_set_spacing(GTK_BOX(dialog->vbox), dialog->style_info.cont_sizes.top);
- gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(widget)->vbox), dialog->style_info.cont_sizes.bottom);
-
-
- gtk_widget_set_size_request(dialog->area_custom,
- (dialog->style_info.radio_sizes.left + 2*dialog->style_info.radio_sizes.bottom)*(dialog->style_info.num_buttons.top) +
- (dialog->style_info.num_buttons.top-1)*dialog->style_info.radio_sizes.top,
- (dialog->style_info.radio_sizes.right + 2*dialog->style_info.radio_sizes.bottom)*(dialog->style_info.num_buttons.bottom) +
- (dialog->style_info.num_buttons.bottom-1)*dialog->style_info.radio_sizes.top);
- gtk_widget_set_size_request(dialog->area_defined,
- (dialog->style_info.radio_sizes.left + 2*dialog->style_info.radio_sizes.bottom)*(dialog->style_info.num_buttons.left) +
- (dialog->style_info.num_buttons.left-1)*dialog->style_info.radio_sizes.top,
- (dialog->style_info.radio_sizes.right + 2*dialog->style_info.radio_sizes.bottom)*(dialog->style_info.num_buttons.right) +
- (dialog->style_info.num_buttons.right-1)*dialog->style_info.radio_sizes.top);
-
-
- GTK_WIDGET_CLASS(parent_klass)->size_request(widget, req);
-}
-
-static void hildon_color_chooser_dialog_hsv_size_allocate(GtkWidget *widget, GtkAllocation *alloc)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(widget);
- GdkRectangle rect;
- int i, tmp, tmp2;
-
-
- GTK_WIDGET_CLASS(parent_klass)->size_allocate(widget, alloc);
-
-
- if(GTK_WIDGET_REALIZED(widget)) {
- tmp = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right);
- tmp2 = (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
-
- for(i = 0; i < tmp; i++) {
- rect.x = ((i % dialog->style_info.num_buttons.left) * (dialog->style_info.radio_sizes.left + dialog->style_info.radio_sizes.top +
- 2*dialog->style_info.radio_sizes.bottom)) + dialog->style_info.radio_sizes.bottom;
- rect.y = ((i / dialog->style_info.num_buttons.left) * (dialog->style_info.radio_sizes.right + dialog->style_info.radio_sizes.top +
- 2*dialog->style_info.radio_sizes.bottom)) + dialog->style_info.radio_sizes.bottom;
- rect.width = dialog->style_info.radio_sizes.left;
- rect.height = dialog->style_info.radio_sizes.right;
-
- gdk_gc_set_clip_rectangle(dialog->gc_array[i], &rect);
- }
-
- for(i = 0; i < tmp2; i++) {
- rect.x = ((i % dialog->style_info.num_buttons.top) * (dialog->style_info.radio_sizes.left + dialog->style_info.radio_sizes.top +
- 2*dialog->style_info.radio_sizes.bottom)) + dialog->style_info.radio_sizes.bottom;
- rect.y = ((i / dialog->style_info.num_buttons.top) * (dialog->style_info.radio_sizes.right + dialog->style_info.radio_sizes.top +
- 2*dialog->style_info.radio_sizes.bottom)) + dialog->style_info.radio_sizes.bottom;
- rect.width = dialog->style_info.radio_sizes.left;
- rect.height = dialog->style_info.radio_sizes.right;
-
- gdk_gc_set_clip_rectangle(dialog->gc_array[i + tmp], &rect);
- }
- }
-}
-
-
-static void hildon_color_chooser_dialog_hsv_realize(GtkWidget *widget)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(widget);
- GdkRectangle rect;
- int i, tmp, tmp2;
-
-
- GTK_WIDGET_CLASS(parent_klass)->realize(widget);
-
-
- tmp = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right) +
- (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
-
- for(i = 0; i < tmp; i++) {
- dialog->gc_array[i] = gdk_gc_new(widget->window);
- }
-
-
-
- tmp = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right);
- tmp2 = (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
-
- for(i = 0; i < tmp; i++) {
- gdk_gc_set_rgb_fg_color(dialog->gc_array[i], &dialog->colors_defined[i]);
-
- rect.x = ((i % dialog->style_info.num_buttons.left) * (dialog->style_info.radio_sizes.left + dialog->style_info.radio_sizes.top +
- 2*dialog->style_info.radio_sizes.bottom)) + dialog->style_info.radio_sizes.bottom;
- rect.y = ((i / dialog->style_info.num_buttons.left) * (dialog->style_info.radio_sizes.right + dialog->style_info.radio_sizes.top +
- 2*dialog->style_info.radio_sizes.bottom)) + dialog->style_info.radio_sizes.bottom;
- rect.width = dialog->style_info.radio_sizes.left;
- rect.height = dialog->style_info.radio_sizes.right;
-
- gdk_gc_set_clip_rectangle(dialog->gc_array[i], &rect);
- }
-
- for(i = 0; i < tmp2; i++) {
- gdk_gc_set_rgb_fg_color(dialog->gc_array[i + tmp], &dialog->colors_custom[i]);
-
- rect.x = ((i % dialog->style_info.num_buttons.top) * (dialog->style_info.radio_sizes.left + dialog->style_info.radio_sizes.top +
- 2*dialog->style_info.radio_sizes.bottom)) + dialog->style_info.radio_sizes.bottom;
- rect.y = ((i / dialog->style_info.num_buttons.top) * (dialog->style_info.radio_sizes.right + dialog->style_info.radio_sizes.top +
- 2*dialog->style_info.radio_sizes.bottom)) + dialog->style_info.radio_sizes.bottom;
- rect.width = dialog->style_info.radio_sizes.left;
- rect.height = dialog->style_info.radio_sizes.right;
-
- gdk_gc_set_clip_rectangle(dialog->gc_array[i + tmp], &rect);
- }
-}
-
-static void hildon_color_chooser_dialog_hsv_unrealize(GtkWidget *widget)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(widget);
- int i, tmp;
-
-
- tmp = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right) +
- (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
-
- for(i = 0; i < tmp; i++) {
- g_object_unref(dialog->gc_array[i]);
- }
-
-
- GTK_WIDGET_CLASS(parent_klass)->unrealize(widget);
-}
-
-
-static void hildon_color_chooser_dialog_hsv_style_set(GtkWidget *widget, GtkStyle *previous_style)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(widget);
- GdkColor *tmpcolor;
- gchar tmp[32], key[128], *val;
- int i, tmpn, setcolor = 0;
-
-
- if(!dialog->has_style)
- setcolor = 1;
-
- dialog->has_style = 1;
-
-
- gtk_widget_style_get(widget, "default_color", &tmpcolor, NULL);
- if(tmpcolor) {
- dialog->style_info.default_color = *tmpcolor;
- } else {
- dialog->style_info.default_color.red = 0x0000;
- dialog->style_info.default_color.green = 0x0000;
- dialog->style_info.default_color.blue = 0x0000;
- dialog->style_info.default_color.pixel = 0x00000000;
- }
-
-
- hildon_color_chooser_dialog_hsv_refresh_style_info(dialog);
-
-
- if(memcmp(&dialog->style_info.num_buttons, &dialog->style_info.last_num_buttons, sizeof(GtkBorder))) {
- if(dialog->colors_custom) {
- g_free(dialog->colors_custom);
- } if(dialog->colors_defined) {
- g_free(dialog->colors_defined);
- } if(dialog->gc_array) {
- if(GTK_WIDGET_REALIZED(widget)) {
- tmpn = (dialog->style_info.last_num_buttons.left * dialog->style_info.last_num_buttons.right) +
- (dialog->style_info.last_num_buttons.top * dialog->style_info.last_num_buttons.bottom);
-
- for(i = 0; i < tmpn; i++) {
- g_object_unref(dialog->gc_array[i]);
- }
- }
-
- g_free(dialog->gc_array);
- }
-
- dialog->colors_custom = (GdkColor *)g_malloc0(sizeof(GdkColor) * (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom));
- dialog->colors_defined = (GdkColor *)g_malloc0(sizeof(GdkColor) * (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right));
-
-
- tmpn = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right) +
- (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
- dialog->gc_array = (GdkGC **)g_malloc0(sizeof(GdkGC *) * tmpn);
-
-
- if(dialog->gconf_data.client) {
- for(i = 0; i < (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom); i++) {
- memset(key, 0, 128);
- g_snprintf(key, 128, "/system/osso/af/color_chooser/custom_color%d", i);
- val = gconf_client_get_string(dialog->gconf_data.client, key, NULL);
- if(val) {
- hildon_color_chooser_dialog_hsv_ascii_hex_to_color(val, &dialog->colors_custom[i]);
- g_free(val);
- } else {
- dialog->colors_custom[i] = dialog->style_info.default_color;
- }
- }
- } else {
- for(i = 0; i < (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom); i++) {
- dialog->colors_custom[i] = dialog->style_info.default_color;
- }
- }
- }
-
-
- tmpn = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right);
-
- hildon_color_chooser_set_color(HILDON_COLOR_CHOOSER(dialog->chooser),
- (dialog->selected < tmpn) ? &dialog->colors_defined[dialog->selected] : &dialog->colors_custom[dialog->selected - tmpn]);
-
-
- for(i = 0; i < (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right); i++) {
- memset(tmp, 0, 32);
- g_snprintf(tmp, 32, "defined_color%d", i);
-
- gtk_widget_style_get(widget, tmp, &tmpcolor, NULL);
-
- if(tmpcolor) {
- dialog->colors_defined[i] = *tmpcolor;
- } else {
- if(i < 16) {
- dialog->colors_defined[i] = hardcoded_colors[i];
- } else { /* fallback to prevent segfault */
- dialog->colors_defined[i].red = 0x0000;
- dialog->colors_defined[i].green = 0x0000;
- dialog->colors_defined[i].blue = 0x0000;
- dialog->colors_defined[i].pixel = 0x00000000;
- }
- }
- }
-
-
- if(GTK_WIDGET_REALIZED(widget)) {
- for(i = 0; i < (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right); i++) {
- gdk_gc_set_rgb_fg_color(dialog->gc_array[i], &dialog->colors_defined[i]);
- }
- }
-
-
- if(setcolor)
- hildon_color_chooser_dialog_hsv_set_color(HILDON_COLOR_CHOOSER_DIALOG(dialog), &dialog->pending_color);
-
-
- gtk_widget_queue_resize(widget);
-
-
- GTK_WIDGET_CLASS(parent_klass)->style_set(widget, previous_style);
-}
-
-
-static void hildon_color_chooser_dialog_hsv_show(GtkWidget *widget)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(widget);
-
-
- gtk_widget_show(dialog->hbox);
- gtk_widget_show(dialog->vbox);
-
- gtk_widget_show(dialog->chooser);
-
- gtk_widget_show(dialog->align_custom);
- gtk_widget_show(dialog->align_defined);
-
- gtk_widget_show(dialog->separator);
-
- gtk_widget_show(dialog->area_custom);
- gtk_widget_show(dialog->area_defined);
-
-
- GTK_WIDGET_CLASS(parent_klass)->show(widget);
-}
-
-static void hildon_color_chooser_dialog_hsv_show_all(GtkWidget *widget)
-{
- hildon_color_chooser_dialog_hsv_show(widget);
-}
-
-
-static gboolean hildon_color_chooser_dialog_hsv_key_press_event(GtkWidget *widget, GdkEventKey *event)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(widget);
- int tmp, tot, sel;
-
-
- if(event->keyval == HILDON_HARDKEY_UP || event->keyval == HILDON_HARDKEY_DOWN ||
- event->keyval == HILDON_HARDKEY_LEFT || event->keyval == HILDON_HARDKEY_RIGHT) {
- tmp = (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
- tot = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right) + tmp;
-
- switch(event->keyval) {
- case HILDON_HARDKEY_UP:
- if(dialog->selected >= dialog->style_info.num_buttons.top) {
- if(dialog->selected - dialog->style_info.num_buttons.left >= tmp) {
- sel = dialog->selected - dialog->style_info.num_buttons.left;
- } else {
- sel = dialog->selected - dialog->style_info.num_buttons.top;
- }
-
- hildon_color_chooser_dialog_hsv_set_color_num(dialog, sel);
- }
- break;
- case HILDON_HARDKEY_DOWN:
- if(dialog->selected < tot - dialog->style_info.num_buttons.left) {
- if(dialog->selected < tmp) {
- sel = dialog->selected + dialog->style_info.num_buttons.top;
- } else {
- sel = dialog->selected + dialog->style_info.num_buttons.left;
- }
-
- hildon_color_chooser_dialog_hsv_set_color_num(dialog, sel);
- }
- break;
- case HILDON_HARDKEY_LEFT:
- if((dialog->selected < tmp ? (dialog->selected % dialog->style_info.num_buttons.top) : ((dialog->selected - tmp) % dialog->style_info.num_buttons.left)) > 0) {
- sel = dialog->selected - 1;
-
- hildon_color_chooser_dialog_hsv_set_color_num(dialog, sel);
- }
- break;
- case HILDON_HARDKEY_RIGHT:
- if((dialog->selected < tmp) ? (dialog->selected % dialog->style_info.num_buttons.top < dialog->style_info.num_buttons.top - 1) :
- ((dialog->selected - tmp) % dialog->style_info.num_buttons.left < dialog->style_info.num_buttons.left - 1)) {
- sel = dialog->selected + 1;
-
- hildon_color_chooser_dialog_hsv_set_color_num(dialog, sel);
- }
- break;
- default:
- break;
- }
-
- return FALSE;
- }
-
- return GTK_WIDGET_CLASS(parent_klass)->key_press_event(widget, event);
-}
-
-static gboolean hildon_color_chooser_dialog_hsv_key_release_event(GtkWidget *widget, GdkEventKey *event)
-{
- if(event->keyval == HILDON_HARDKEY_UP || event->keyval == HILDON_HARDKEY_DOWN ||
- event->keyval == HILDON_HARDKEY_LEFT || event->keyval == HILDON_HARDKEY_RIGHT) {
- return FALSE;
- }
-
- return GTK_WIDGET_CLASS(parent_klass)->key_press_event(widget, event);
-}
-
-
-static void hildon_color_chooser_dialog_hsv_destroy(GtkObject *object)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(object);
- gchar key[128], color[13];
- int i, tmp;
-
-
- if(dialog->gconf_data.client) {
- memset(color, 0, 13);
-
- tmp = (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
-
- for(i = 0; i < tmp; i++) {
- memset(key, 0, 128);
- g_snprintf(key, 128, "/system/osso/af/color_chooser/custom_color%d", i);
- hildon_color_chooser_dialog_hsv_color_to_ascii_hex(color, &dialog->colors_custom[i]);
- gconf_client_set_string(dialog->gconf_data.client, key, color, NULL);
- }
-
- g_object_unref(dialog->gconf_data.client);
- dialog->gconf_data.client = NULL;
- }
-
-
- if(dialog->gc_array) {
- g_free(dialog->gc_array);
- dialog->gc_array = NULL;
- } if(dialog->colors_defined) {
- g_free(dialog->colors_defined);
- dialog->colors_defined = NULL;
- } if(dialog->colors_custom) {
- g_free(dialog->colors_custom);
- dialog->colors_custom = NULL;
- }
-
-
- GTK_OBJECT_CLASS(parent_klass)->destroy(object);
-}
-
-
-static void hildon_color_chooser_dialog_hsv_set_color(HildonColorChooserDialog *dialog, GdkColor *color)
-{
- HildonColorChooserDialogHSV *dialog_hsv = HILDON_COLOR_CHOOSER_DIALOG_HSV(dialog);
- int i, found = -1, tmp, tmp2;
-
-
- if(!dialog_hsv->has_style) {
- dialog_hsv->pending_color = *color;
- return;
- }
-
-
- tmp = (dialog_hsv->style_info.num_buttons.left * dialog_hsv->style_info.num_buttons.right);
- tmp2 = (dialog_hsv->style_info.num_buttons.top * dialog_hsv->style_info.num_buttons.bottom);
-
- for(i = 0; i < tmp; i++) {
- if(dialog_hsv->colors_defined[i].red == color->red &&
- dialog_hsv->colors_defined[i].green == color->green &&
- dialog_hsv->colors_defined[i].blue == color->blue) {
- found = i;
- break;
- }
- }
-
- if(found == -1) {
- for(i = 0; i < tmp2; i++) {
- if(dialog_hsv->colors_custom[i].red == color->red &&
- dialog_hsv->colors_custom[i].green == color->green &&
- dialog_hsv->colors_custom[i].blue == color->blue) {
- found = i + tmp;
- break;
- }
- }
- }
-
-
- if(found == -1) {
- dialog_hsv->colors_custom[tmp2-1] = *color;
- if(GTK_WIDGET_REALIZED(GTK_WIDGET(dialog))) {
- gdk_gc_set_rgb_fg_color(dialog_hsv->gc_array[tmp2-1], color);
- }
- hildon_color_chooser_dialog_hsv_set_color_num(dialog_hsv, tmp2-1);
- } else {
- hildon_color_chooser_dialog_hsv_set_color_num(dialog_hsv, found);
- }
-}
-
-
-static gboolean hildon_color_chooser_dialog_hsv_area_expose(GtkWidget *widget, GdkEventExpose *event, gpointer data)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(data);
- int i, num_selected, tot_w, tot_h, spacing, brd, x, y;
- GdkGC **start_gc;
- int tmp, w, h;
-
-
- tmp = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right);
-
- if(widget == dialog->area_custom) {
- num_selected = dialog->selected - tmp;
- start_gc = dialog->gc_array + tmp;
- tmp = (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
- w = dialog->style_info.num_buttons.top; h = dialog->style_info.num_buttons.bottom;
- } else { /* widget == dialog->area_defined */
- num_selected = dialog->selected;
- start_gc = dialog->gc_array;
- w = dialog->style_info.num_buttons.left; h = dialog->style_info.num_buttons.right;
- }
-
- spacing = dialog->style_info.radio_sizes.top;
- brd = dialog->style_info.radio_sizes.bottom;
- tot_w = dialog->style_info.radio_sizes.left + 2*brd;
- tot_h = dialog->style_info.radio_sizes.right + 2*brd;
-
-
- for(i = 0; i < tmp; i++) {
- x = ((i % w) * (tot_w + spacing));
- y = ((i / w) * (tot_h + spacing));
-
- gdk_draw_rectangle(widget->window,
- widget->style->black_gc,
- TRUE,
- (i == num_selected) ? x : x + 2,
- (i == num_selected) ? y : y + 2,
- (i == num_selected) ? tot_w : tot_w - 4,
- (i == num_selected) ? tot_h : tot_h - 4);
-
- gdk_draw_rectangle(widget->window,
- widget->style->white_gc,
- TRUE,
- x + 3,
- y + 3,
- tot_w - 6,
- tot_h - 6);
-
- gdk_draw_rectangle(widget->window,
- start_gc [i],
- TRUE,
- x + 3 + 1,
- y + 3 + 1,
- tot_w - 6 - 2,
- tot_h - 6 - 2);
-
-// gtk_paint_box(gtk_widget_get_style(GTK_WIDGET(dialog)), widget->window, (i == num_selected) ? GTK_STATE_SELECTED : GTK_STATE_NORMAL,
-// (i == num_selected) ? GTK_SHADOW_IN : GTK_SHADOW_OUT, &event->area, GTK_WIDGET(dialog), "color-radio", x, y, tot_w, tot_h);
- //}
-
- //gdk_draw_rectangle(widget->window, start_gc[i], TRUE, event->area.x, event->area.y, event->area.width, event->area.height);
- }
-
-
- return FALSE;
-}
-
-
-static gboolean hildon_color_chooser_dialog_hsv_area_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(data);
- int i, hskip, vskip, brd, selection = -1;
- int x, y, tmp, tmp2, w;
-
-
- x = event->x;
- y = event->y;
-
-
- brd = dialog->style_info.radio_sizes.bottom;
- hskip = dialog->style_info.radio_sizes.left + dialog->style_info.radio_sizes.top + 2*brd;
- vskip = dialog->style_info.radio_sizes.right + dialog->style_info.radio_sizes.top + 2*brd;
-
-
- tmp = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right);
- tmp2 = (dialog->style_info.num_buttons.top * dialog->style_info.num_buttons.bottom);
-
-
- if(widget == dialog->area_defined) {
- w = dialog->style_info.num_buttons.left;
-
- for(i = 0; i < tmp; i++) {
- if(x >= hskip*(i % w) + brd && x < hskip*(i % w) + brd + dialog->style_info.radio_sizes.left &&
- y >= vskip*(i / w) + brd && y < hskip*(i / w) + brd + dialog->style_info.radio_sizes.right) {
- selection = i;
- break;
- }
- }
- } else {
- w = dialog->style_info.num_buttons.top;
- for(i = 0; i < tmp2; i++) {
- if(x >= hskip*(i % w) + brd && x < hskip*(i % w) + brd + dialog->style_info.radio_sizes.left &&
- y >= vskip*(i / w) + brd && y < hskip*(i / w) + brd + dialog->style_info.radio_sizes.right) {
- selection = i + tmp;
- break;
- }
- }
- }
-
-
- if(selection != -1) {
- hildon_color_chooser_dialog_hsv_set_color_num(dialog, selection);
- }
-
-
- return FALSE;
-}
-
-
-static void hildon_color_chooser_dialog_hsv_chooser_color_changed(HildonColorChooser *chooser, GdkColor *color, gpointer data)
-{
- HildonColorChooserDialogHSV *dialog = HILDON_COLOR_CHOOSER_DIALOG_HSV(data);
- HildonColorChooserDialog *dia = HILDON_COLOR_CHOOSER_DIALOG(data);
- char key[128], color_str[13];
- int tmp;
-
-
- dia->color = *color;
-
-
- tmp = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right);
-
-
- if(dialog->selected >= tmp) {
- dialog->colors_custom[dialog->selected - tmp] = *color;
-
- gdk_gc_set_rgb_fg_color(dialog->gc_array[dialog->selected], &dialog->colors_custom[dialog->selected - tmp]);
-
- gtk_widget_queue_draw(dialog->area_custom);
-
-
- if(dialog->gconf_data.client) {
- memset(key, 0, 128);
- memset(color_str, 0, 13);
- g_snprintf(key, 128, "/system/osso/af/color_chooser/custom_color%d", dialog->selected - tmp);
- hildon_color_chooser_dialog_hsv_color_to_ascii_hex(color_str, &dialog->colors_custom[dialog->selected - tmp]);
- gconf_client_set_string(dialog->gconf_data.client, key, color_str, NULL);
- }
- }
-}
-
-
-static void hildon_color_chooser_dialog_hsv_chooser_insensitive_press(GtkWidget *widget, gpointer data)
-{
- hildon_banner_show_information(widget, NULL, _("ecdg_ib_colour_selector_predefined"));
-}
-
- /* function has size defaults */
-static void hildon_color_chooser_dialog_hsv_refresh_style_info(HildonColorChooserDialogHSV *dialog)
-{
- GtkBorder *tmp1, *tmp2, *tmp3;
-
-
- gtk_widget_style_get(GTK_WIDGET(dialog), "container_sizes", &tmp1,
- "radio_sizes", &tmp2, "num_buttons", &tmp3, NULL);
-
-
- dialog->style_info.last_num_buttons = dialog->style_info.num_buttons;
-
-
- if(tmp1) {
- dialog->style_info.cont_sizes = *tmp1;
- g_free(tmp1);
- } else {
- dialog->style_info.cont_sizes.left = 0;
- dialog->style_info.cont_sizes.right = 8;
- dialog->style_info.cont_sizes.top = 4;
- dialog->style_info.cont_sizes.bottom = 0;
- }
-
- if(tmp2) {
- dialog->style_info.radio_sizes = *tmp2;
- g_free(tmp2);
- } else {
- dialog->style_info.radio_sizes.left = 16;
- dialog->style_info.radio_sizes.right = 16;
- dialog->style_info.radio_sizes.top = 4;
- dialog->style_info.radio_sizes.bottom = 2;
- }
-
- if(tmp3) {
- dialog->style_info.num_buttons = *tmp3;
- g_free(tmp3);
- } else {
- dialog->style_info.num_buttons.left = 8;
- dialog->style_info.num_buttons.right = 2;
- dialog->style_info.num_buttons.top = 8;
- dialog->style_info.num_buttons.bottom = 2;
- }
-}
-
-
-static void hildon_color_chooser_dialog_hsv_set_color_num(HildonColorChooserDialogHSV *dialog, gint num)
-{
- HildonColorChooserDialog *dia = HILDON_COLOR_CHOOSER_DIALOG(dialog);
- int tmp;
-
-
- tmp = (dialog->style_info.num_buttons.left * dialog->style_info.num_buttons.right);
-
-
- if(num < tmp) {
- gtk_widget_set_sensitive(dialog->chooser, FALSE);
- } else {
- gtk_widget_set_sensitive(dialog->chooser, TRUE);
- }
-
-
- dialog->selected = num;
-
- gtk_widget_queue_draw(dialog->area_custom);
- gtk_widget_queue_draw(dialog->area_defined);
-
- dia->color = (num < tmp) ? dialog->colors_defined[num] : dialog->colors_custom[num - tmp];
-
- hildon_color_chooser_set_color(HILDON_COLOR_CHOOSER(dialog->chooser), (num < tmp) ? &dialog->colors_defined[num] : &dialog->colors_custom[num - tmp]);
-}
-
-
-static void hildon_color_chooser_dialog_hsv_ascii_hex_to_color(gchar *s, GdkColor *color)
-{
- int vals[12], i;
-
-
- for(i = 0; i < 12; i++) {
- if(s[i] >= '0' && s[i] <= '9') {
- vals[i] = s[i] - 0x30;
- } else if(s[i] >= 'a' && s[i] <= 'f') {
- vals[i] = s[i] - 0x57;
- } else {
- vals[i] = 0;
- }
- }
-
-
- color->red = (vals[0] << 12) | (vals[1] << 8) | (vals[2 ] << 4) | (vals[3 ] );
- color->green = (vals[4] << 12) | (vals[5] << 8) | (vals[6 ] << 4) | (vals[7 ] );
- color->blue = (vals[8] << 12) | (vals[9] << 8) | (vals[10] << 4) | (vals[11] );
-}
-
-static void hildon_color_chooser_dialog_hsv_color_to_ascii_hex(gchar *s, GdkColor *color)
-{
- g_snprintf(s, 13, "%x%x%x%x%x%x%x%x%x%x%x%x",
- (color->red >> 12) & 0xf, (color->red >> 8) & 0xf,
- (color->red >> 4) & 0xf, (color->red ) & 0xf,
- (color->green >> 12) & 0xf, (color->green >> 8) & 0xf,
- (color->green >> 4) & 0xf, (color->green ) & 0xf,
- (color->blue >> 12) & 0xf, (color->blue >> 8) & 0xf,
- (color->blue >> 4) & 0xf, (color->blue ) & 0xf);
-}
+++ /dev/null
-/*
- * This file is part of hildon-libs
- *
- * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
- *
- * Author: Kuisma Salonen <kuisma.salonen@nokia.com>
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; version 2.1 of
- * the License.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-#include <gtk/gtk.h>
-
-#include <hildon-widgets/hildon-color-chooser.h>
-
-
-const char *parent_name = "HildonColorChooser";
-const char *plugin_name = "HSV color chooser";
-
-GType export_type(void);
-
-
-typedef struct {
- HildonColorChooser parent;
-
- GtkAllocation hba;
- GtkAllocation spa;
-
- unsigned short currhue;
- unsigned short currsat;
- unsigned short currval;
-
- int mousestate;
- gboolean mousein;
-
-
- GdkWindow *event_window;
-
- GdkPixbuf *dimmed_plane;
- GdkPixbuf *dimmed_bar;
-
- struct {
- unsigned short last_expose_hue;
-
- GTimeVal last_expose_time;
-
- int expose_queued;
- } expose_info;
-} HildonColorChooserHSV;
-
-typedef struct {
- HildonColorChooserClass parent;
-} HildonColorChooserHSVClass;
-
-
-#define HILDON_COLOR_CHOOSER_HSV(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), export_type(), HildonColorChooserHSV))
-#define HILDON_COLOR_CHOOSER_HSV_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), export_type(), HildonColorChooserHSVClass))
-
-
-static HildonColorChooserClass *parent_class = NULL;
-
-
- /* "crosshair" is hardcoded for now */
-static gchar crosshair[64] = { 0, 0, 0, 2, 2, 0, 0, 0,
- 0, 2, 2, 3, 3, 2, 2, 0,
- 0, 2, 3, 0, 0, 3, 2, 0,
- 2, 3, 0, 0, 0, 0, 3, 2,
- 2, 3, 0, 0, 0, 0, 3, 2,
- 0, 2, 3, 0, 0, 3, 2, 0,
- 0, 2, 2, 3, 3, 2, 2, 0,
- 0, 0, 0, 2, 2, 0, 0, 0};
-
-
-static void hildon_color_chooser_hsv_init(HildonColorChooserHSV *sel);
-static void hildon_color_chooser_hsv_class_init(HildonColorChooserHSVClass *klass);
-
-static void hildon_color_chooser_hsv_dispose(HildonColorChooserHSV *sel);
-
-static void hildon_color_chooser_hsv_size_request(GtkWidget *widget, GtkRequisition *req);
-static void hildon_color_chooser_hsv_size_allocate(GtkWidget *widget, GtkAllocation *alloc);
-
-static void hildon_color_chooser_hsv_realize(GtkWidget *widget);
-
-static void hildon_color_chooser_hsv_map(GtkWidget *widget);
-static void hildon_color_chooser_hsv_unmap(GtkWidget *widget);
-
-static gboolean hildon_color_chooser_hsv_expose(GtkWidget *widget, GdkEventExpose *event);
-
-static gboolean hildon_color_chooser_button_press(GtkWidget *widget, GdkEventButton *event);
-static gboolean hildon_color_chooser_button_release(GtkWidget *widget, GdkEventButton *event);
-static gboolean hildon_color_chooser_pointer_motion(GtkWidget *widget, GdkEventMotion *event);
-
-static void hildon_color_chooser_hsv_set_color(HildonColorChooser *sel, GdkColor *color);
-
-
-static void internal_get_border(GtkWidget *w, char *name, GtkBorder *b);
-static void _internal_init_borders(GtkWidget *w, GtkBorder *inner, GtkBorder *outer);
-
-static void internal_invoke_color_changed(HildonColorChooserHSV *sel);
-
-
-inline void inline_clip_to_alloc(void *s, GtkAllocation *a);
-
-inline void inline_sub_times(GTimeVal *result, GTimeVal *greater, GTimeVal *lesser);
-
-inline void inline_limited_expose(HildonColorChooserHSV *sel);
-
-inline void inline_draw_hue_bar(GtkWidget *widget, int x, int y, int w, int h, int sy, int sh);
-inline void inline_draw_hue_bar_dimmed(GtkWidget *widget, int x, int y, int w, int h, int sy, int sh);
-
-inline void inline_draw_sv_plane(HildonColorChooserHSV *sel, int x, int y, int w, int h);
-inline void inline_draw_sv_plane_dimmed(HildonColorChooserHSV *sel, int x, int y, int w, int h);
-
-inline void inline_draw_crosshair(unsigned char *buf, int x, int y, int w, int h);
-
-
-inline void inline_h2rgb(unsigned short hue, unsigned long *rgb);
-
-
-static gboolean hildon_color_chooser_hsv_expose_timer(gpointer data);
-
-
-GType export_type()
-{
- static GType chooser_type = 0;
-
- if (!chooser_type) {
- static const GTypeInfo chooser_info =
- {
- sizeof (HildonColorChooserHSVClass),
- NULL,
- NULL,
- (GClassInitFunc) hildon_color_chooser_hsv_class_init,
- NULL,
- NULL,
- sizeof (HildonColorChooserHSV),
- 0,
- (GInstanceInitFunc) hildon_color_chooser_hsv_init,
- NULL
- };
-
- chooser_type = g_type_register_static (HILDON_TYPE_COLOR_CHOOSER,
- "HildonColorChooserHSV",
- &chooser_info, 0);
- }
-
- return chooser_type;
-}
-
-static void hildon_color_chooser_hsv_init(HildonColorChooserHSV *sel)
-{
- GTK_WIDGET_SET_FLAGS (sel, GTK_NO_WINDOW);
-
-
- sel->currhue = 0;
- sel->currsat = 0;
- sel->currval = 0;
-
- sel->mousestate = 0;
- sel->mousein = FALSE;
-
-
- g_get_current_time(&sel->expose_info.last_expose_time);
-
- sel->expose_info.last_expose_hue = sel->currhue;
- sel->expose_info.expose_queued = 0;
-
- sel->dimmed_plane = NULL;
- sel->dimmed_bar = NULL;
-}
-
-static void hildon_color_chooser_hsv_class_init(HildonColorChooserHSVClass *klass)
-{
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- HildonColorChooserClass *selection_class = HILDON_COLOR_CHOOSER_CLASS(klass);
-
-
- parent_class = g_type_class_peek_parent(klass);
-
-
- object_class->dispose = (gpointer) hildon_color_chooser_hsv_dispose;
-
- widget_class->size_request = hildon_color_chooser_hsv_size_request;
- widget_class->size_allocate = hildon_color_chooser_hsv_size_allocate;
-
- widget_class->realize = hildon_color_chooser_hsv_realize;
-
- widget_class->map = hildon_color_chooser_hsv_map;
- widget_class->unmap = hildon_color_chooser_hsv_unmap;
-
- widget_class->expose_event = hildon_color_chooser_hsv_expose;
-
- widget_class->button_press_event = hildon_color_chooser_button_press;
- widget_class->button_release_event = hildon_color_chooser_button_release;
- widget_class->motion_notify_event = hildon_color_chooser_pointer_motion;
-
-
- selection_class->set_color = hildon_color_chooser_hsv_set_color;
-
-
- gtk_widget_class_install_style_property(widget_class,
- g_param_spec_boxed("inner_size",
- "Inner sizes",
- "Sizes of SV plane, H bar and spacing",
- GTK_TYPE_BORDER,
- G_PARAM_READABLE));
- gtk_widget_class_install_style_property(widget_class,
- g_param_spec_boxed("graphic_border",
- "Graphical borders",
- "Size of graphical border",
- GTK_TYPE_BORDER,
- G_PARAM_READABLE));
-}
-
-
-static void hildon_color_chooser_hsv_dispose(HildonColorChooserHSV *sel)
-{
- if (sel->dimmed_bar != NULL) {
- g_object_unref (sel->dimmed_bar);
- sel->dimmed_bar = NULL;
- }
-
- if (sel->dimmed_plane != NULL) {
- g_object_unref (sel->dimmed_plane);
- sel->dimmed_plane = NULL;
- }
-
- G_OBJECT_CLASS(parent_class)->dispose(sel);
-}
-
-static void hildon_color_chooser_hsv_size_request(GtkWidget *widget, GtkRequisition *req)
-{
- GtkBorder inner, outer;
-
-
- _internal_init_borders(widget, &inner, &outer);
-
-
- req->width = inner.left + inner.top + inner.bottom + outer.left + outer.right;
- req->height = inner.right + outer.top + outer.bottom;
-}
-
-static void hildon_color_chooser_hsv_size_allocate(GtkWidget *widget, GtkAllocation *alloc)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
- GtkBorder outer, inner;
-
-
- widget->allocation = *alloc;
-
-
- _internal_init_borders(widget, &inner, &outer);
-
-
- sel->hba.height = alloc->height - outer.top - outer.bottom;
- sel->hba.y = alloc->y + outer.top;
- sel->hba.width = inner.top;
- sel->hba.x = alloc->x + alloc->width - outer.right - inner.top;
-
- sel->spa.x = alloc->x + outer.left;
- sel->spa.y = alloc->y + outer.top;
- sel->spa.height = alloc->height - outer.top - outer.bottom;
- sel->spa.width = alloc->width - outer.left - outer.right - inner.top - inner.bottom;
-
- if(GTK_WIDGET_REALIZED(widget)) {
- gdk_window_move_resize(sel->event_window, widget->allocation.x, widget->allocation.y, widget->allocation.width, widget->allocation.height);
- }
-}
-
-
-static void hildon_color_chooser_hsv_realize(GtkWidget *widget)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
- GdkWindowAttr attributes;
- gint attributes_mask;
-
- attributes.x = widget->allocation.x;
- attributes.y = widget->allocation.y;
- attributes.width = widget->allocation.width;
- attributes.height = widget->allocation.height;
- attributes.wclass = GDK_INPUT_ONLY;
- attributes.window_type = GDK_WINDOW_CHILD;
- attributes.event_mask = gtk_widget_get_events(widget) | GDK_BUTTON_PRESS_MASK |
- GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK |
- GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_MOTION_MASK |
- GDK_BUTTON1_MOTION_MASK;
- attributes.visual = gtk_widget_get_visual(widget);
- attributes.colormap = gtk_widget_get_colormap(widget);
-
- attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_WMCLASS;
- sel->event_window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
-
-
- gdk_window_set_user_data(sel->event_window, widget);
-
-
- widget->window = gtk_widget_get_parent_window(widget);
-
-
- widget->style = gtk_style_attach(widget->style, widget->window);
-
-
- GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
-}
-
-
-static void hildon_color_chooser_hsv_map(GtkWidget *widget)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
-
-
- GTK_WIDGET_CLASS(parent_class)->map(widget);
-
- if(sel->event_window) {
- gdk_window_show(sel->event_window);
- }
-}
-
-static void hildon_color_chooser_hsv_unmap(GtkWidget *widget)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
-
-
- if(sel->event_window) {
- gdk_window_hide(sel->event_window);
- }
-
- GTK_WIDGET_CLASS(parent_class)->unmap(widget);
-}
-
-
-inline void inline_clip_to_alloc(void *s, GtkAllocation *a)
-{
- struct {
- int x, y, w, h;
- } *area = s;
-
-
- if(area->x < a->x) {
- area->w -= a->x - area->x;
- area->x = a->x;
- } if(area->y < a->y) {
- area->h -= a->y - area->y;
- area->y = a->y;
- }
- if(area->x + area->w > a->x + a->width) area->w = a->width - (area->x - a->x);
- if(area->y + area->h > a->y + a->height) area->h = a->height - (area->y - a->y);
-}
-
-static gboolean hildon_color_chooser_hsv_expose(GtkWidget *widget, GdkEventExpose *event)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
- GtkBorder graphical_border;
- struct {
- int x, y, w, h;
- } area;
-
-
- if(!GTK_WIDGET_REALIZED(widget)) {
- return FALSE;
- }
-
-
- internal_get_border(widget, "graphic_border", &graphical_border);
-
-
- if(event->area.width || event->area.height) {
- gdk_draw_rectangle(widget->window,
- widget->style->black_gc,
- FALSE,
- sel->hba.x - 2,
- sel->hba.y - 2,
- sel->hba.width + 3,
- sel->hba.height + 3);
-
- gdk_draw_rectangle(widget->window,
- widget->style->black_gc,
- FALSE,
- sel->spa.x - 2,
- sel->spa.y - 2,
- sel->spa.width + 3,
- sel->spa.height + 3);
- }
-
- if(sel->expose_info.expose_queued) {
- if(GTK_WIDGET_SENSITIVE(widget)) {
- inline_draw_hue_bar(widget, sel->hba.x, sel->hba.y, sel->hba.width, sel->hba.height, sel->hba.y, sel->hba.height);
-
- inline_draw_sv_plane(sel, sel->spa.x, sel->spa.y, sel->spa.width, sel->spa.height);
- } else {
- inline_draw_hue_bar_dimmed(widget, sel->hba.x, sel->hba.y, sel->hba.width, sel->hba.height, sel->hba.y, sel->hba.height);
-
- inline_draw_sv_plane_dimmed(sel, sel->spa.x, sel->spa.y, sel->spa.width, sel->spa.height);
- }
-
-
- sel->expose_info.expose_queued = 0;
-
- g_get_current_time(&sel->expose_info.last_expose_time);
- } else {
- /* clip hue bar region */
- area.x = event->area.x;
- area.y = event->area.y;
- area.w = event->area.width;
- area.h = event->area.height;
-
- inline_clip_to_alloc(&area, &sel->hba);
-
- if(GTK_WIDGET_SENSITIVE(widget)) {
- inline_draw_hue_bar(widget, area.x, area.y, area.w, area.h, sel->hba.y, sel->hba.height);
- } else {
- inline_draw_hue_bar_dimmed(widget, area.x, area.y, area.w, area.h, sel->hba.y, sel->hba.height);
- }
-
-
- area.x = event->area.x;
- area.y = event->area.y;
- area.w = event->area.width;
- area.h = event->area.height;
-
- inline_clip_to_alloc(&area, &sel->spa);
-
- if(GTK_WIDGET_SENSITIVE(widget)) {
- inline_draw_sv_plane(sel, area.x, area.y, area.w, area.h);
- } else {
- inline_draw_sv_plane_dimmed(sel, area.x, area.y, area.w, area.h);
- }
- }
-
-
- return FALSE;
-}
-
-
-inline void inline_sub_times(GTimeVal *result, GTimeVal *greater, GTimeVal *lesser)
-{
- result->tv_sec = greater->tv_sec - lesser->tv_sec;
- result->tv_usec = greater->tv_usec - lesser->tv_usec;
-
- if(result->tv_usec < 0) {
- result->tv_sec--;
- result->tv_usec += 1000000;
- }
-}
-
-#define EXPOSE_INTERVAL 50000
-inline void inline_limited_expose(HildonColorChooserHSV *sel)
-{
- GTimeVal curr_time, result;
- GdkEventExpose event;
-
-
- if(!GTK_WIDGET_REALIZED(GTK_WIDGET(sel))) {
- return;
- }
-
-
- if(sel->currhue == sel->expose_info.last_expose_hue) {
- return; /* no need to redraw */
- }
-
-
- sel->expose_info.last_expose_hue = sel->currhue;
-
-
- g_get_current_time(&curr_time);
-
- inline_sub_times(&result, &curr_time, &sel->expose_info.last_expose_time);
-
- if(result.tv_sec != 0 || result.tv_usec >= EXPOSE_INTERVAL) {
- sel->expose_info.expose_queued = 1;
-
-#if 1
- event.type = GDK_EXPOSE;
- event.area.width = 0;
- event.area.height = 0;
- event.window = GTK_WIDGET(sel)->window;
-
- gtk_widget_send_expose(GTK_WIDGET(sel), (GdkEvent *)&event);
-#else
- gtk_widget_queue_draw(GTK_WIDGET(sel));
-#endif
- } else if(!sel->expose_info.expose_queued) {
- sel->expose_info.expose_queued = 1;
-
-
- g_timeout_add((EXPOSE_INTERVAL - result.tv_usec)/1000, hildon_color_chooser_hsv_expose_timer, sel);
- }
-}
-
-static gboolean hildon_color_chooser_button_press(GtkWidget *widget, GdkEventButton *event)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
- int x, y, tmp;
-
-
- x = (int)event->x + widget->allocation.x;
- y = (int)event->y + widget->allocation.y;
-
-
- if(x >= sel->spa.x && x <= sel->spa.x + sel->spa.width &&
- y >= sel->spa.y && y <= sel->spa.y + sel->spa.height) {
- tmp = y - sel->spa.y;
- sel->currsat = tmp * 0xffff / sel->spa.height;
- tmp = x - sel->spa.x;
- sel->currval = tmp * 0xffff / sel->spa.width;
-
- internal_invoke_color_changed(sel);
- gtk_widget_queue_draw(widget);
-
- sel->mousestate = 1;
- sel->mousein = TRUE;
-
- gtk_grab_add(widget);
- } else if(x >= sel->hba.x && x <= sel->hba.x + sel->hba.width &&
- y >= sel->hba.y && y <= sel->hba.y + sel->hba.height) {
- tmp = y - sel->hba.y;
- sel->currhue = tmp * 0xffff / sel->hba.height;
-
- internal_invoke_color_changed(sel);
- inline_limited_expose(sel);
-
- sel->mousestate = 2;
- sel->mousein = TRUE;
-
- gtk_grab_add(widget);
- }
-
-
- return FALSE;
-}
-
-static gboolean hildon_color_chooser_button_release(GtkWidget *widget, GdkEventButton *event)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
-
-
- if(sel->mousestate) {
- gtk_grab_remove(widget);
- }
-
-
- sel->mousestate = 0;
- sel->mousein = FALSE;
-
-
- return FALSE;
-}
-
-static gboolean hildon_color_chooser_pointer_motion(GtkWidget *widget, GdkEventMotion *event)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
- GdkModifierType mods;
- gint x, y, tmp;
-
-
- if (event->is_hint || (event->window != widget->window))
- gdk_window_get_pointer (widget->window, &x, &y, &mods);
-
-
- if(sel->mousestate == 1) {
- if(x >= sel->spa.x && x <= sel->spa.x + sel->spa.width &&
- y >= sel->spa.y && y <= sel->spa.y + sel->spa.height) {
- sel->currsat = (((long)(y - sel->spa.y)) * 0xffff)/sel->spa.height;
- sel->currval = (((long)(x - sel->spa.x)) * 0xffff)/sel->spa.width;
-
- internal_invoke_color_changed(sel);
- gtk_widget_queue_draw(widget);
- } else if(sel->mousein == TRUE) {
- }
- } else if(sel->mousestate == 2) {
- if(x >= sel->hba.x && x <= sel->hba.x + sel->hba.width &&
- y >= sel->hba.y && y <= sel->hba.y + sel->hba.height) {
- tmp = y - sel->hba.y;
- tmp *= 0xffff;
- tmp /= sel->hba.height;
-
- if(tmp != sel->currhue) {
- sel->currhue = tmp;
-
- internal_invoke_color_changed(sel);
- inline_limited_expose(sel);
- }
- } else if(sel->mousein == TRUE) {
- }
- }
-
- return FALSE;
-}
-
-
-static void internal_get_border(GtkWidget *w, char *name, GtkBorder *b)
-{
- GtkBorder *tb;
-
- gtk_widget_style_get(w, name, &tb, NULL);
-
- if(tb) {
- *b = *tb;
- g_free(tb);
- } else {
- b->left = 0;
- b->right = 0;
- b->top = 0;
- b->bottom = 0;
- }
-}
-
-
-static void _internal_init_borders(GtkWidget *w, GtkBorder *inner, GtkBorder *outer)
-{
- GtkBorder *tb;
-
-
- internal_get_border(w, "outer_border", outer);
-
-
- gtk_widget_style_get(w, "inner_size", &tb, NULL);
-
- if(tb) {
- *inner = *tb;
- g_free(tb);
- } else {
- inner->left = 64;
- inner->right = 64;
- inner->top = 12;
- inner->bottom = 2;
- }
-
- if(inner->left < 2) inner->left = 2;
- if(inner->right < 2) inner->right = 2;
- if(inner->top < 2) inner->top = 2;
-}
-
- /* calculate RGB color & emit signal */
-static void internal_invoke_color_changed(HildonColorChooserHSV *sel)
-{
- HildonColorChooser *parent_sel = HILDON_COLOR_CHOOSER(sel);
- GdkVisual *system_visual = gdk_visual_get_system();
- unsigned long rgb[3], rgb2[3];
-
-
- inline_h2rgb(sel->currhue, rgb);
-
- rgb2[0] = 0xffffff - rgb[0];
- rgb2[1] = 0xffffff - rgb[1];
- rgb2[2] = 0xffffff - rgb[2];
-
-
- parent_sel->color.red = ((rgb[0] >> 8) + ((rgb2[0] >> 8) * (0xffff - sel->currsat) / 0xffff)) * sel->currval / 0xffff;
- parent_sel->color.green = ((rgb[1] >> 8) + ((rgb2[1] >> 8) * (0xffff - sel->currsat) / 0xffff)) * sel->currval / 0xffff;
- parent_sel->color.blue = ((rgb[2] >> 8) + ((rgb2[2] >> 8) * (0xffff - sel->currsat) / 0xffff)) * sel->currval / 0xffff;
-
- parent_sel->color.pixel = ((parent_sel->color.red >> (16 - system_visual->red_prec)) << system_visual->red_shift) |
- ((parent_sel->color.green >> (16 - system_visual->green_prec)) << system_visual->green_shift) |
- ((parent_sel->color.blue >> (16 - system_visual->blue_prec)) << system_visual->blue_shift);
-
-
- hildon_color_chooser_emit_color_changed(HILDON_COLOR_CHOOSER(sel));
-}
-
- /* do the RGB -> HSV conversion here, not so time critical */
-static void hildon_color_chooser_hsv_set_color(HildonColorChooser *sel, GdkColor *color)
-{
- HildonColorChooserHSV *sel_hsv = HILDON_COLOR_CHOOSER_HSV(sel);
- unsigned short hue, sat, val;
- unsigned long min, max;
- signed long tmp, diff;
-
- /* ugly nesting */
- min = MIN(MIN(color->red, color->green), color->blue);
- max = MAX(MAX(color->red, color->green), color->blue);
- diff = max - min;
-
-
- val = max;
-
- if(val > 0 && diff != 0) {
- sat = (diff * 0x0000ffff) / max;
-
- if(color->red == max) {
- tmp = (signed)color->green - (signed)color->blue;
- tmp *= 10922;
- tmp /= diff;
- if(tmp < 0) {
- tmp += 65532;
- }
- hue = tmp;
- } else if(color->green == max) {
- hue = (((signed long)color->blue - (signed long)color->red)*10922 / diff) + 21844;
- } else {
- hue = (((signed long)color->red - (signed long)color->green)*10922 / diff) + 43688;
- }
- } else {
- hue = 0;
- sat = 0;
- }
-
-
- sel_hsv->currhue = hue;
- sel_hsv->currsat = sat;
- sel_hsv->currval = val;
-
-
- inline_limited_expose(sel_hsv);
-}
-
-
-#define FULL_COLOR 0x00ffffff
-inline void inline_h2rgb(unsigned short hue, unsigned long *rgb)
-{
- unsigned short hue_rotation, hue_value;
-
- hue_rotation = hue / 10922;
- hue_value = hue % 10922;
-
-
- switch(hue_rotation) {
- case 0:
- case 6:
- rgb[0] = FULL_COLOR;
- rgb[1] = hue_value * 6*256;
- rgb[2] = 0;
- break;
- case 1:
- rgb[0] = FULL_COLOR - (hue_value * 6*256);
- rgb[1] = FULL_COLOR;
- rgb[2] = 0;
- break;
- case 2:
- rgb[0] = 0;
- rgb[1] = FULL_COLOR;
- rgb[2] = hue_value * 6*256;
- break;
- case 3:
- rgb[0] = 0;
- rgb[1] = FULL_COLOR - (hue_value * 6*256);
- rgb[2] = FULL_COLOR;
- break;
- case 4:
- rgb[0] = hue_value * 6*256;
- rgb[1] = 0;
- rgb[2] = FULL_COLOR;
- break;
- case 5:
- rgb[0] = FULL_COLOR;
- rgb[1] = 0;
- rgb[2] = FULL_COLOR - (hue_value * 6*256);
- break;
- default:
- rgb[0] = 0;
- rgb[1] = 0;
- rgb[2] = 0;
- break;
- }
-}
-
-#define FULL_COLOR8 0xff
-static void intern_h2rgb8(unsigned short hue, unsigned char *rgb)
-{
- unsigned short hue_rotation, hue_value;
-
- hue >>= 8;
- hue_rotation = hue / 42;
- hue_value = hue % 42;
-
-
- switch(hue_rotation) {
- case 0:
- case 6:
- rgb[0] = FULL_COLOR8;
- rgb[1] = hue_value * 6;
- rgb[2] = 0;
- break;
- case 1:
- rgb[0] = FULL_COLOR8 - (hue_value * 6);
- rgb[1] = FULL_COLOR8;
- rgb[2] = 0;
- break;
- case 2:
- rgb[0] = 0;
- rgb[1] = FULL_COLOR8;
- rgb[2] = hue_value * 6;
- break;
- case 3:
- rgb[0] = 0;
- rgb[1] = FULL_COLOR8 - (hue_value * 6);
- rgb[2] = FULL_COLOR8;
- break;
- case 4:
- rgb[0] = hue_value * 6;
- rgb[1] = 0;
- rgb[2] = FULL_COLOR8;
- break;
- case 5:
- rgb[0] = FULL_COLOR8;
- rgb[1] = 0;
- rgb[2] = FULL_COLOR8 - (hue_value * 6);
- break;
- default:
- rgb[0] = 0;
- rgb[1] = 0;
- rgb[2] = 0;
- break;
- }
-}
-
-
- /* optimization: do not ask hue for each round but have bilinear vectors */
- /* rethink: benefits from handling data 8 bit? (no shift round) */
-inline void inline_draw_hue_bar(GtkWidget *widget, int x, int y, int w, int h, int sy, int sh)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
- unsigned short hvec, hcurr;
- unsigned char *buf, *ptr, tmp[3];
- int i, j, tmpy;
-
-
- if(w <= 0 || h <= 0) {
- return;
- }
-
- buf = (unsigned char *)g_malloc(w*h*3);
-
- hvec = 65535/sh;
- hcurr = hvec * (y - sy);
-
- ptr = buf;
-
-
- for(i = 0; i < h; i++) {
- intern_h2rgb8(hcurr, tmp);
-
- for(j = 0; j < w; j++) {
- ptr[0] = tmp[0];
- ptr[1] = tmp[1];
- ptr[2] = tmp[2];
- ptr += 3;
- }
-
- hcurr += hvec;
- }
-
-
- gdk_draw_rgb_image(widget->parent->window, widget->style->fg_gc[0], x, y, w, h, GDK_RGB_DITHER_NONE, buf, w*3);
-
- tmpy = sel->hba.y + (sel->currhue * sel->hba.height / 0xffff);
- gdk_draw_line(widget->parent->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], sel->hba.x, tmpy, sel->hba.x + sel->hba.width - 1, tmpy);
-
- if((((sel->currhue * sel->hba.height) & 0xffff) > 0x8000) && (tmpy < (sel->hba.y + sel->hba.height))) {
- gdk_draw_line(widget->parent->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], sel->hba.x, tmpy+1, sel->hba.x + sel->hba.width - 1, tmpy+1);
- } else if(tmpy > sel->hba.y) {
- gdk_draw_line(widget->parent->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], sel->hba.x, tmpy-1, sel->hba.x + sel->hba.width - 1, tmpy-1);
- }
-
-
- g_free(buf);
-}
-
-inline void inline_draw_hue_bar_dimmed(GtkWidget *widget, int x, int y, int w, int h, int sy, int sh)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(widget);
-
-
- if(w <= 0 || h <= 0) {
- return;
- }
-
- /* We need to create (and cache) the pixbuf if we don't
- * have it yet */
- if (sel->dimmed_bar == NULL) {
- int i, j;
- unsigned short hvec, hcurr, avg;
- unsigned char *buf, *ptr, tmp[3];
- buf = (unsigned char *)g_malloc(w*h*3);
-
- hvec = 65535/sh;
- hcurr = hvec * (y - sy);
-
- ptr = buf;
-
-
- for(i = 0; i < h; i++) {
- intern_h2rgb8(hcurr, tmp);
-
- for(j = 0; j < w; j++) {
- avg = ((unsigned short)tmp[0]*3 + (unsigned short)tmp[1]*2 + (unsigned short)tmp[2])/6;
- ptr[0] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255);
- ptr[1] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255);
- ptr[2] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255);
- ptr += 3;
- }
-
- hcurr += hvec;
- }
-
- sel->dimmed_bar = gdk_pixbuf_new_from_data (buf, GDK_COLORSPACE_RGB, FALSE, 8, w, h, w * 3, g_free, buf);
- }
-
- gdk_draw_pixbuf (widget->parent->window, widget->style->fg_gc [0], sel->dimmed_bar, 0, 0, x, y, w, h, GDK_RGB_DITHER_NONE, 0, 0);
-}
-
-
-inline void inline_draw_crosshair(unsigned char *buf, int x, int y, int w, int h)
-{
- int i, j, sx, sy;
-
- /* bad "clipping", clip the loop to save cpu */
- for(i = 0; i < 8; i++) {
- for(j = 0; j < 8; j++) {
- sx = j + x; sy = i + y;
-
- if(sx >= 0 && sx < w && sy >= 0 && sy < h) {
- if(crosshair[j + 8*i]) {
- if(crosshair[j + 8*i] & 0x1) {
- buf[(sx)*3+(sy)*w*3+0] = 255;
- buf[(sx)*3+(sy)*w*3+1] = 255;
- buf[(sx)*3+(sy)*w*3+2] = 255;
- } else {
- buf[(sx)*3+(sy)*w*3+0] = 0;
- buf[(sx)*3+(sy)*w*3+1] = 0;
- buf[(sx)*3+(sy)*w*3+2] = 0;
- }
- }
- }
- }
- }
-}
-
-
-inline void inline_draw_sv_plane(HildonColorChooserHSV *sel, int x, int y, int w, int h)
-{
- GtkWidget *widget = GTK_WIDGET(sel);
- unsigned char *buf, *ptr;
- unsigned long rgbx[3] = { 0x00ffffff, 0x00ffffff, 0x00ffffff }, rgbtmp[3];
- signed long rgby[3];
- int tmp = sel->spa.width*sel->spa.height, i, j;
-
-
- if(w <= 0 || h <= 0) {
- return;
- }
-
-
- buf = (unsigned char *)g_malloc(w*h*3);
-
- ptr = buf;
-
-
- inline_h2rgb(sel->currhue, rgbtmp);
-
- rgby[0] = rgbtmp[0] - rgbx[0];
- rgby[1] = rgbtmp[1] - rgbx[1];
- rgby[2] = rgbtmp[2] - rgbx[2];
-
- rgbx[0] /= sel->spa.width;
- rgbx[1] /= sel->spa.width;
- rgbx[2] /= sel->spa.width;
-
- rgby[0] /= tmp;
- rgby[1] /= tmp;
- rgby[2] /= tmp;
-
-
- rgbx[0] += (y - sel->spa.y)*rgby[0];
- rgbx[1] += (y - sel->spa.y)*rgby[1];
- rgbx[2] += (y - sel->spa.y)*rgby[2];
-
-
- for(i = 0; i < h; i++) {
- rgbtmp[0] = rgbx[0] * (x - sel->spa.x);
- rgbtmp[1] = rgbx[1] * (x - sel->spa.x);
- rgbtmp[2] = rgbx[2] * (x - sel->spa.x);
-
- for(j = 0; j < w; j++) {
- ptr[0] = rgbtmp[0] >> 16;
- ptr[1] = rgbtmp[1] >> 16;
- ptr[2] = rgbtmp[2] >> 16;
- rgbtmp[0] += rgbx[0];
- rgbtmp[1] += rgbx[1];
- rgbtmp[2] += rgbx[2];
- ptr += 3;
- }
-
- rgbx[0] += rgby[0];
- rgbx[1] += rgby[1];
- rgbx[2] += rgby[2];
- }
-
-
- inline_draw_crosshair(buf, (sel->spa.width * sel->currval / 0xffff) - x + sel->spa.x - 4, (sel->spa.height * sel->currsat / 0xffff) - y + sel->spa.y - 4, w, h);
-
-
- gdk_draw_rgb_image(widget->parent->window, widget->style->fg_gc[0], x, y, w, h, GDK_RGB_DITHER_NONE, buf, w*3);
-
-
- g_free(buf);
-}
-
-inline void inline_draw_sv_plane_dimmed(HildonColorChooserHSV *sel, int x, int y, int w, int h)
-{
- GtkWidget *widget = GTK_WIDGET(sel);
-
- if(w <= 0 || h <= 0) {
- return;
- }
-
- /* We need to create (and cache) the pixbuf if we don't
- * have it yet */
- if (sel->dimmed_plane == NULL) {
- unsigned char *buf, *ptr;
- unsigned long rgbx[3] = { 0x00ffffff, 0x00ffffff, 0x00ffffff }, rgbtmp[3];
- unsigned long avg;
- signed long rgby[3];
- int tmp = sel->spa.width*sel->spa.height, i, j;
-
- buf = (unsigned char *)g_malloc(w*h*3);
-
- ptr = buf;
-
- /* possibe optimization: as we are drawing grayscale plane, there might
- be some simpler algorithm to do this*/
- rgbtmp[0] = 0x00ffffff;
- rgbtmp[1] = 0x00000000;
- rgbtmp[2] = 0x00000000;
-
- rgby[0] = rgbtmp[0] - rgbx[0];
- rgby[1] = rgbtmp[1] - rgbx[1];
- rgby[2] = rgbtmp[2] - rgbx[2];
-
- rgbx[0] /= sel->spa.width;
- rgbx[1] /= sel->spa.width;
- rgbx[2] /= sel->spa.width;
-
- rgby[0] /= tmp;
- rgby[1] /= tmp;
- rgby[2] /= tmp;
-
- rgbx[0] += (y - sel->spa.y)*rgby[0];
- rgbx[1] += (y - sel->spa.y)*rgby[1];
- rgbx[2] += (y - sel->spa.y)*rgby[2];
-
- for(i = 0; i < h; i++) {
- rgbtmp[0] = rgbx[0] * (x - sel->spa.x);
- rgbtmp[1] = rgbx[1] * (x - sel->spa.x);
- rgbtmp[2] = rgbx[2] * (x - sel->spa.x);
-
- for(j = 0; j < w; j++) {
- avg = (rgbtmp[0] + rgbtmp[1] + rgbtmp[2])/3;
- avg >>= 16;
- ptr[0] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255);
- ptr[1] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255);
- ptr[2] = ((((i % 2) + j) % 2) == 0) ? MIN ((avg * 0.7) + 180, 255) : MIN ((avg * 0.7) + 120, 255);
- rgbtmp[0] += rgbx[0];
- rgbtmp[1] += rgbx[1];
- rgbtmp[2] += rgbx[2];
- ptr += 3;
- }
-
- rgbx[0] += rgby[0];
- rgbx[1] += rgby[1];
- rgbx[2] += rgby[2];
- }
-
- sel->dimmed_plane = gdk_pixbuf_new_from_data (buf, GDK_COLORSPACE_RGB, FALSE, 8, w, h, w * 3, g_free, buf);
- }
-
- gdk_draw_pixbuf (widget->parent->window, widget->style->fg_gc [0], sel->dimmed_plane, 0, 0, x, y, w, h, GDK_RGB_DITHER_NONE, 0, 0);
-}
-
-
-static gboolean hildon_color_chooser_hsv_expose_timer(gpointer data)
-{
- HildonColorChooserHSV *sel = HILDON_COLOR_CHOOSER_HSV(data);
-
-
- if(sel->expose_info.expose_queued) {
- gtk_widget_queue_draw(GTK_WIDGET(data));
- }
-
-
- return FALSE;
-}
hildon-window.c \
hildon-program.c \
hildon-code-dialog.c \
- hildon-plugin-widget.c \
hildon-enum-types.c \
hildon-marshalers.c
hildon-program.h \
hildon-window-private.h \
hildon-code-dialog.h \
- hildon-plugin-widget.h \
hildon-enum-types.h \
hildon-marshalers.h
+++ /dev/null
-/*
- * This file is part of hildon-libs
- *
- * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
- *
- * Author: Kuisma Salonen <kuisma.salonen@nokia.com>
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; version 2.1 of
- * the License.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-/**
- * SECTION:hildon-plugin-widget
- * @short_description: A simple interface to load plugin based widgets. Not
- * compatible with GObject.
- *
- * #HildonPluginWidgetInfo is a struct containing information about loaded
- * module which contains code for a widget.
- */
-
-#include <config.h>
-#include "hildon-plugin-widget.h"
-#include <stdio.h>
-#include <memory.h>
-#include <string.h>
-#include <gtk/gtk.h>
-
-#ifndef PLUGIN_DIR
-#define PLUGIN_DIR "/usr/lib/hildon-widgets"
-#endif
-
-struct HildonPluginWidgetInfo_ {
- GType base_type;
-
- gchar *filename;
-
- GModule *module;
- int refcount;
-
- GType (*get_type) ();
-};
-
-
-static gchar *hildon_plugin_filename(GType base_type, const gchar *name);
-
- /* WARNING: works properly only with ASCII */
-static gchar *ascii_decapitalize_without_dashes(gchar *source);
-
-static gchar *hildon_plugin_default_name(gchar *typename);
-
-/**
- * hildon_plugin_info_initialize:
- * @base_type: a #GType representing parent type of object that will be
- * loaded.
- * @name: Name of child. To load default (or #GtkSettings defined), NULL
- * should be passed as name. To load specific child type, decapitalized name
- * should be passed here.
- *
- * Creates a new #HildonPluginWidgetInfo structure and opens a module.
- *
- * The naming of child widgets (or objects) doesn't matter, but for plugins
- * the file names should be type
- * <decapitalized-parent-type-name-with-dashes>-<pluginname>.so where the
- * decapitalized type name would be for example for #GtkWidget gtk-widget.
- *
- * The name comes from name argument or from #GtkSettings where the variable
- * storing it is with name <ParentTypeName>-plugin, for #GtkWidget this would
- * be "GtkWidget-plugin". If nothing is defined in #GtkSettings, name
- * "default" is assumed. For this case there should be symlink to some child
- * type plugin named <parent-type-name>-default.so
- *
- * Returns: a #HildonPluginWidgetInfo struct pointer upon success, NULL if
- * failed.
- */
-HildonPluginWidgetInfo *hildon_plugin_info_initialize(GType base_type, const gchar *name)
-{
- HildonPluginWidgetInfo *ret;
- GModule *module;
- gchar *filename;
-
-
- if(!base_type) {
- return NULL;
- }
-
-
- filename = hildon_plugin_filename(base_type, name);
- g_return_val_if_fail (filename != NULL, NULL);
-
-
- module = g_module_open(filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
- if(!module) {
- g_warning ("Failed to load plugin for '%s' (filename: '%s')", name, filename);
- g_free(filename);
- return NULL;
- }
-
-
- ret = (HildonPluginWidgetInfo *)g_malloc0(sizeof(HildonPluginWidgetInfo) + strlen(filename) + 1);
- ret->filename = (gchar *)ret + sizeof(HildonPluginWidgetInfo);
-
- ret->base_type = base_type;
-
- ret->module = module;
-
- g_module_symbol(module, "export_type", (void **)&ret->get_type);
-
- memcpy(ret->filename, filename, strlen(filename));
-
-
- g_free(filename);
-
-
- return ret;
-}
-
-/**
- * hildon_plugin_info_construct_widget:
- * @info: pointer to a #HildonPluginWidgetInfo struct.
- *
- * Creates instance of loaded type from module stored in
- * #HildonPluginWidgetInfo struct. Designed for loading types inherited from
- * GtkWidget, but could be basically any GTK+ type.
- *
- * Returns: a GtkWidget pointer to instance of loaded type.
- */
-GtkWidget *hildon_plugin_info_construct_widget(HildonPluginWidgetInfo *info)
-{
- g_return_val_if_fail (info != NULL, NULL);
- info->refcount++;
-
-
- return GTK_WIDGET(g_type_create_instance(info->get_type()));
-}
-
-/**
- * hildon_plugin_info_kill:
- * @info: a pointer to a #HildonPluginWidgetInfo struct that should be
- * destroyed.
- *
- * Frees the plugin information structure and unloads the module.
- */
-void hildon_plugin_info_kill(HildonPluginWidgetInfo *info)
-{
- if(!info) {
- return;
- }
-
-
- g_module_close(info->module);
-
-
- g_free(info);
-}
-
-
-static gchar *hildon_plugin_filename(GType base_type, const gchar *name)
-{
- gchar *ret, *name2, *plgbuf;
- gchar *typename = (gchar *)g_type_name(base_type);
- int retsize;
-
-
- plgbuf = ascii_decapitalize_without_dashes(typename);
-
-
- if(name) {
- name2 = g_strdup(name);
- } else {
- name2 = hildon_plugin_default_name(typename);
- }
-
-
- retsize = strlen(PLUGIN_DIR) + strlen(plgbuf) + strlen(name2) + 6;
- ret = (gchar *)g_malloc0(retsize);
- g_snprintf(ret, retsize, "%s/%s_%s.so", PLUGIN_DIR, plgbuf, name2);
-
-
- g_free(name2);
- g_free(plgbuf);
-
-
- return ret;
-}
-
- /* possible speedup: pre-allocate more memory and ditch the first loop */
-static gchar *ascii_decapitalize_without_dashes(gchar *source)
-{
- gchar *ptr, *ret = g_strdup (source);
-
-
- for(ptr = ret; *ptr; ptr++) {
- if(*ptr >= 'A' && *ptr <= 'Z') {
- *ptr += 0x20;
- }
- }
-
-
- return ret;
-}
-
-
-static gchar *hildon_plugin_default_name(gchar *typename)
-{
- GtkSettings *settings;
- gchar *ret, *val, *tmp;
- int tmplen;
-
-
- tmplen = strlen(typename) + strlen("-plugin") + 1;
- tmp = (gchar *)g_malloc0(tmplen);
- g_snprintf(tmp, tmplen, "%s-plugin", typename);
-
-
- gtk_settings_install_property(g_param_spec_string(tmp,
- tmp,
- "Plugin for this pecific widget",
- NULL,
- G_PARAM_READWRITE));
-
- settings = gtk_settings_get_default();
-
- g_object_get(G_OBJECT(settings), tmp, &val, NULL);
-
- g_free(tmp);
-
-
- if(val) {
- ret = (gchar *)g_malloc0(strlen(val)+1);
- memcpy(ret, val, strlen(val));
- g_free(val);
- } else {
- ret = (gchar *)g_malloc0(strlen("default")+1);
-
-
- g_snprintf(ret, strlen("default")+1, "default");
- }
-
-
- return ret;
-}
+++ /dev/null
-/*
- * This file is part of hildon-libs
- *
- * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
- *
- * Author: Kuisma Salonen <kuisma.salonen@nokia.com>
- * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; version 2.1 of
- * the License.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA
- *
- */
-
-
-#ifndef __HILDON_PLUGIN_WIDGET_H__
-#define __HILDON_PLUGIN_WIDGET_H__
-
-#include <glib-object.h>
-#include <gtk/gtkwidget.h>
-
-/**
- * HildonPluginWidgetInfo:
- *
- * Contains information about the loaded module which has some widget
- * inherited from some non-plugin widget. The struct should be considered
- * private and should not be used directly.
- */
-typedef struct HildonPluginWidgetInfo_ HildonPluginWidgetInfo;
-
-
-HildonPluginWidgetInfo *hildon_plugin_info_initialize(GType base_type, const gchar *name);
-
-
-GtkWidget *hildon_plugin_info_construct_widget(HildonPluginWidgetInfo *info);
-
-
-void hildon_plugin_info_kill(HildonPluginWidgetInfo *info);
-
-
-
-#endif /* __HILDON_PLUGIN_WIDGET_H__ */