aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Bradford <rob@linux.intel.com>2007-04-03 18:55:54 +0000
committerRob Bradford <rob@linux.intel.com>2007-04-03 18:55:54 +0000
commit6831b92ab427f8feb93ea0010b2032149d4c8c89 (patch)
tree818e6af009e1c1ef358720c2f6993ceab9e21892
parent38d2c268a79362550b2680326d41325b016fda0f (diff)
downloadlibowl-6831b92ab427f8feb93ea0010b2032149d4c8c89.tar.gz
libowl-6831b92ab427f8feb93ea0010b2032149d4c8c89.tar.bz2
libowl-6831b92ab427f8feb93ea0010b2032149d4c8c89.zip
2007-04-03 Rob Bradford <rob@openedhand.com>
* libowl/owlcolourselectordialog.c: (owl_colour_selector_dialog_orientation_get_type), (owl_colour_selector_dialog_get_property), (owl_colour_selector_dialog_set_property), (owl_colour_selector_dialog_constructor), (owl_colour_selector_dialog_class_init), (owl_colour_selector_dialog_init), (owl_colour_selector_dialog_new_with_orientation), (owl_colour_selector_dialog_new): * libowl/owlcolourselectordialog.h: Add support for vertical or horizontally orientated colour selector. If the orientation is set to OWL_COLOUR_SELECTOR_AUTOMATIC (default) then it will detect it based on the width & height on the screen. It can also be manually specified with a construction time property.
-rw-r--r--ChangeLog17
-rw-r--r--libowl/owlcolourselectordialog.c169
-rw-r--r--libowl/owlcolourselectordialog.h9
3 files changed, 160 insertions, 35 deletions
diff --git a/ChangeLog b/ChangeLog
index 70b1e7d..82fdb3d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-04-03 Rob Bradford <rob@openedhand.com>
+
+ * libowl/owlcolourselectordialog.c:
+ (owl_colour_selector_dialog_orientation_get_type),
+ (owl_colour_selector_dialog_get_property),
+ (owl_colour_selector_dialog_set_property),
+ (owl_colour_selector_dialog_constructor),
+ (owl_colour_selector_dialog_class_init),
+ (owl_colour_selector_dialog_init),
+ (owl_colour_selector_dialog_new_with_orientation),
+ (owl_colour_selector_dialog_new):
+ * libowl/owlcolourselectordialog.h:
+ Add support for vertical or horizontally orientated colour selector.
+ If the orientation is set to OWL_COLOUR_SELECTOR_AUTOMATIC (default)
+ then it will detect it based on the width & height on the screen.
+ It can also be manually specified with a construction time property.
+
2007-03-19 Rob Bradford <rob@openedhand.com>
* libowl/Makefile.am:
diff --git a/libowl/owlcolourselectordialog.c b/libowl/owlcolourselectordialog.c
index c2571b9..4f722b0 100644
--- a/libowl/owlcolourselectordialog.c
+++ b/libowl/owlcolourselectordialog.c
@@ -37,16 +37,60 @@ typedef struct _OwlColourSelectorDialogPrivate OwlColourSelectorDialogPrivate;
struct _OwlColourSelectorDialogPrivate
{
GtkWidget *frame;
- GtkWidget *vbox;
+ GtkWidget *main_box;
GtkWidget *palette;
GtkWidget *swatch;
+ GtkWidget *swatch_box;
+ GtkWidget *alignment;
+
+ gint orientation;
+};
+
+enum {
+ PROP_ORIENTATION = 1
};
+GType
+owl_colour_selector_dialog_orientation_get_type (void)
+{
+ static GType etype = 0;
+ if (etype == 0) {
+ static const GEnumValue values[] = {
+ { OWL_COLOUR_SELECTOR_DIALOG_HORIZONTAL, "OWL_COLOUR_SELECTOR_DIALOG_HORIZONTAL", "horizontal" },
+ { OWL_COLOUR_SELECTOR_DIALOG_VERTICAL, "OWL_COLOUR_SELECTOR_DIALOG_VERTICAL", "vertical" },
+ { OWL_COLOUR_SELECTOR_DIALOG_AUTOMATIC, "OWL_COLOUR_SELECTOR_DIALOG_AUTOMATIC", "automatic" },
+ { 0, NULL, NULL }
+ };
+ etype = g_enum_register_static (g_intern_static_string ("OwlColourSelectorDialogOrientation"), values);
+ }
+ return etype;
+}
+
+#define OWL_TYPE_COLOUR_SELECTOR_DIALOG_ORIENTATION owl_colour_selector_dialog_orientation_get_type ()
+
+static const guint32 colours[] =
+ {0xfce94f00, 0xedd40000, 0xc4a00000,
+ 0xfcaf3e00, 0xf5790000, 0xce5c0000,
+ 0xe9b96e00, 0xc17d1100, 0x8f590200,
+ 0x8ae23400, 0x73d21600, 0x4e9a0600,
+ 0x729fcf00, 0x3465a400, 0x204a8700,
+ 0xad7fa800, 0x75507b00, 0x5c356600,
+ 0xef292900, 0xcc000000, 0xa4000000,
+ 0xffffffff, 0xbabdb600, 0x00000000};
+
+static void colour_selected_cb (GtkWidget *widget, OwlColourSwatch *swatch, gpointer user_data);
+
+
static void
owl_colour_selector_dialog_get_property (GObject *object, guint property_id,
GValue *value, GParamSpec *pspec)
{
+ OwlColourSelectorDialogPrivate *priv = COLOUR_SELECTOR_DIALOG_PRIVATE (object);
+
switch (property_id) {
+ case PROP_ORIENTATION:
+ g_value_set_enum (value, priv->orientation);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -56,7 +100,12 @@ static void
owl_colour_selector_dialog_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
+ OwlColourSelectorDialogPrivate *priv = COLOUR_SELECTOR_DIALOG_PRIVATE (object);
+
switch (property_id) {
+ case PROP_ORIENTATION:
+ priv->orientation = g_value_get_enum (value);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
}
@@ -75,10 +124,74 @@ owl_colour_selector_dialog_finalize (GObject *object)
G_OBJECT_CLASS (owl_colour_selector_dialog_parent_class)->finalize (object);
}
+static GObject *
+owl_colour_selector_dialog_constructor (GType type,
+ guint n_construct_properties, GObjectConstructParam *construct_properties)
+{
+ GObject *obj;
+ OwlColourSelectorDialogPrivate *priv;
+
+ GtkWidget *main_box = NULL;
+ GtkWidget *swatch_box = NULL;
+ GtkWidget *alignment = NULL;
+ GtkWidget *frame = NULL;
+ GtkWidget *palette = NULL;
+ OwlColourSelectorDialogOrientation orientation;
+
+ {
+ /* Invoke parent constructor. */
+ OwlColourSelectorDialogClass *klass;
+ GObjectClass *parent_class;
+ klass = OWL_COLOUR_SELECTOR_DIALOG_CLASS (
+ g_type_class_peek (OWL_TYPE_COLOUR_SELECTOR_DIALOG));
+
+ parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
+
+ obj = parent_class->constructor (type, n_construct_properties,
+ construct_properties);
+ }
+
+ priv = COLOUR_SELECTOR_DIALOG_PRIVATE (obj);
+
+ alignment = priv->alignment;
+ frame = priv->frame;
+ palette = priv->palette;
+
+ if (priv->orientation == OWL_COLOUR_SELECTOR_DIALOG_AUTOMATIC)
+ {
+ if (gdk_screen_width () > gdk_screen_height ())
+ orientation = OWL_COLOUR_SELECTOR_DIALOG_HORIZONTAL;
+ else
+ orientation = OWL_COLOUR_SELECTOR_DIALOG_VERTICAL;
+
+ } else {
+ orientation = priv->orientation;
+ }
+
+ if (orientation == OWL_COLOUR_SELECTOR_DIALOG_VERTICAL)
+ {
+ main_box = gtk_vbox_new (FALSE, 6);
+ swatch_box = gtk_hbox_new (FALSE, 0);
+ } else {
+ main_box = gtk_hbox_new (FALSE, 6);
+ swatch_box = gtk_vbox_new (FALSE, 0);
+ }
+
+ gtk_box_pack_start (GTK_BOX (swatch_box), alignment, TRUE, FALSE, 6);
+ gtk_container_add (GTK_CONTAINER (frame), main_box);
+ gtk_box_pack_start (GTK_BOX (main_box), palette, TRUE, TRUE, 6);
+ gtk_box_pack_start (GTK_BOX (main_box), swatch_box, FALSE, FALSE, 6);
+ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (obj)->vbox), frame);
+ gtk_widget_show_all (frame);
+
+ return obj;
+}
+
static void
owl_colour_selector_dialog_class_init (OwlColourSelectorDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GParamSpec *pspec;
g_type_class_add_private (klass, sizeof (OwlColourSelectorDialogPrivate));
@@ -86,6 +199,18 @@ owl_colour_selector_dialog_class_init (OwlColourSelectorDialogClass *klass)
object_class->set_property = owl_colour_selector_dialog_set_property;
object_class->dispose = owl_colour_selector_dialog_dispose;
object_class->finalize = owl_colour_selector_dialog_finalize;
+ object_class->constructor = owl_colour_selector_dialog_constructor;
+
+ pspec = g_param_spec_enum ("orientation",
+ "The orientation of the dialog",
+ "Set orientation of the dialog",
+ OWL_TYPE_COLOUR_SELECTOR_DIALOG_ORIENTATION,
+ OWL_COLOUR_SELECTOR_DIALOG_AUTOMATIC,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+
+ g_object_class_install_property (object_class,
+ PROP_ORIENTATION,
+ pspec);
}
static void
@@ -117,50 +242,24 @@ static void
owl_colour_selector_dialog_init (OwlColourSelectorDialog *self)
{
GtkWidget *frame;
- GtkWidget *vbox;
- GtkWidget *palette;
GtkWidget *swatch;
- GtkWidget *hbox;
GtkWidget *alignment;
-
- guint32 colours[] = {0xfce94f00, 0xedd40000, 0xc4a00000,
- 0xfcaf3e00, 0xf5790000, 0xce5c0000,
- 0xe9b96e00, 0xc17d1100, 0x8f590200,
- 0x8ae23400, 0x73d21600, 0x4e9a0600,
- 0x729fcf00, 0x3465a400, 0x204a8700,
- 0xad7fa800, 0x75507b00, 0x5c356600,
- 0xef292900, 0xcc000000, 0xa4000000,
- 0xffffffff, 0xbabdb600, 0x00000000};
+ GtkWidget *palette;
OwlColourSelectorDialogPrivate *priv = COLOUR_SELECTOR_DIALOG_PRIVATE (self);
- frame = gtk_frame_new (NULL);
- vbox = gtk_vbox_new (FALSE, 6);
-
- gtk_container_add (GTK_CONTAINER(frame), vbox);
-
palette = owl_colour_palette_new (6, 4);
- gtk_box_pack_start (GTK_BOX (vbox), palette, TRUE, TRUE, 6);
-
owl_colour_palette_set_colours (OWL_COLOUR_PALETTE (palette), colours, 24);
-
g_signal_connect (palette, "colour-selected", (GCallback)colour_selected_cb, self);
+ frame = gtk_frame_new (NULL);
swatch = owl_colour_swatch_new ();
- hbox = gtk_hbox_new (FALSE, 0);
alignment = gtk_alignment_new (0.5, 0.5, 1, 1);
gtk_container_add (GTK_CONTAINER (alignment), swatch);
- gtk_box_pack_start (GTK_BOX (hbox), alignment, TRUE, FALSE, 6);
- gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 6);
-
gtk_widget_set_size_request (swatch, 64, 64);
- gtk_container_add (GTK_CONTAINER (GTK_DIALOG (self)->vbox), frame);
-
- gtk_widget_show_all (frame);
-
gtk_dialog_add_buttons (GTK_DIALOG (self),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL,
@@ -168,14 +267,19 @@ owl_colour_selector_dialog_init (OwlColourSelectorDialog *self)
GTK_RESPONSE_OK,
NULL);
-
gtk_window_set_resizable (GTK_WINDOW (self), FALSE);
gtk_window_set_title (GTK_WINDOW (self), "Pick a colour");
- priv->palette = palette;
priv->swatch = swatch;
- priv->vbox = vbox;
priv->frame = frame;
+ priv->alignment = alignment;
+ priv->palette = palette;
+}
+
+GtkWidget*
+owl_colour_selector_dialog_new_with_orientation (OwlColourSelectorDialogOrientation orientation)
+{
+ return GTK_WIDGET(g_object_new (OWL_TYPE_COLOUR_SELECTOR_DIALOG, "orientation", orientation, NULL));
}
GtkWidget*
@@ -183,4 +287,3 @@ owl_colour_selector_dialog_new (void)
{
return GTK_WIDGET(g_object_new (OWL_TYPE_COLOUR_SELECTOR_DIALOG, NULL));
}
-
diff --git a/libowl/owlcolourselectordialog.h b/libowl/owlcolourselectordialog.h
index 8607299..6254d2b 100644
--- a/libowl/owlcolourselectordialog.h
+++ b/libowl/owlcolourselectordialog.h
@@ -59,11 +59,16 @@ typedef struct {
GtkDialogClass parent_class;
} OwlColourSelectorDialogClass;
+typedef enum {
+ OWL_COLOUR_SELECTOR_DIALOG_HORIZONTAL,
+ OWL_COLOUR_SELECTOR_DIALOG_VERTICAL,
+ OWL_COLOUR_SELECTOR_DIALOG_AUTOMATIC
+} OwlColourSelectorDialogOrientation;
+
GType owl_colour_selector_dialog_get_type (void);
+GtkWidget* owl_colour_selector_dialog_new_with_orientation (OwlColourSelectorDialogOrientation orientation);
GtkWidget* owl_colour_selector_dialog_new (void);
-
-
guint32 owl_colour_selector_dialog_get_colour (OwlColourSelectorDialog *self);
void owl_colour_selector_dialog_set_colour (OwlColourSelectorDialog *self, guint32 colour);