[libgda/LIBGDA_5.0] GdauiBasicForm better shows invalid values
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_5.0] GdauiBasicForm better shows invalid values
- Date: Tue, 24 Jan 2012 17:52:03 +0000 (UTC)
commit 8108cfb05b4480dd8daa0c9539c354a3506eea92
Author: Vivien Malerba <malerba gnome-db org>
Date: Tue Jan 24 18:41:11 2012 +0100
GdauiBasicForm better shows invalid values
doc/C/libgda-ui-sections.txt | 3 ++
libgda-ui/data-entries/gdaui-entry-combo.c | 10 +++++
libgda-ui/data-entries/gdaui-entry-shell.c | 23 ++++++++++++-
libgda-ui/data-entries/gdaui-entry-shell.h | 3 ++
libgda-ui/data-entries/gdaui-entry-wrapper.c | 10 +++++
libgda-ui/data-entries/widget-embedder.c | 31 +++++++++++++++--
libgda-ui/data-entries/widget-embedder.h | 14 ++++++--
libgda-ui/gdaui-basic-form.c | 47 ++++++++++++++++++++++++++
libgda-ui/gdaui-basic-form.h | 3 ++
libgda-ui/gdaui-data-entry.c | 23 ++++++++++++
libgda-ui/gdaui-data-entry.h | 9 ++++-
libgda-ui/gdaui-raw-form.c | 3 ++
libgda-ui/libgda-ui.symbols | 5 +++
testing/gdaui-test-errors.c | 19 ++++++++++
14 files changed, 194 insertions(+), 9 deletions(-)
---
diff --git a/doc/C/libgda-ui-sections.txt b/doc/C/libgda-ui-sections.txt
index 13656e3..cef8f8e 100644
--- a/doc/C/libgda-ui-sections.txt
+++ b/doc/C/libgda-ui-sections.txt
@@ -46,6 +46,8 @@ gdaui_basic_form_get_place_holder
GdauiBasicFormPart
gdaui_basic_form_add_to_size_group
gdaui_basic_form_remove_from_size_group
+<SUBSECTION>
+gdaui_basic_form_set_unknown_color
<SUBSECTION Standard>
GDAUI_BASIC_FORM
GDAUI_BASIC_FORM_CLASS
@@ -93,6 +95,7 @@ gdaui_data_entry_can_expand
gdaui_data_entry_set_editable
gdaui_data_entry_get_editable
gdaui_data_entry_grab_focus
+gdaui_data_entry_set_unknown_color
<SUBSECTION Standard>
GDAUI_DATA_ENTRY
GDAUI_IS_DATA_ENTRY
diff --git a/libgda-ui/data-entries/gdaui-entry-combo.c b/libgda-ui/data-entries/gdaui-entry-combo.c
index ff23a36..e69b63b 100644
--- a/libgda-ui/data-entries/gdaui-entry-combo.c
+++ b/libgda-ui/data-entries/gdaui-entry-combo.c
@@ -54,6 +54,8 @@ static void gdaui_entry_combo_set_attributes (GdauiDataEntry *de,
static GdaValueAttribute gdaui_entry_combo_get_attributes (GdauiDataEntry *de);
static gboolean gdaui_entry_combo_can_expand (GdauiDataEntry *de, gboolean horiz);
static void gdaui_entry_combo_grab_focus (GdauiDataEntry *de);
+static void gdaui_entry_combo_set_unknown_color (GdauiDataEntry *de, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha);
static void _gdaui_entry_combo_construct(GdauiEntryCombo* combo,
GdauiSet *paramlist, GdauiSetSource *source);
@@ -142,6 +144,7 @@ gdaui_entry_combo_data_entry_init (GdauiDataEntryIface *iface)
iface->get_handler = NULL;
iface->can_expand = gdaui_entry_combo_can_expand;
iface->grab_focus = gdaui_entry_combo_grab_focus;
+ iface->set_unknown_color = gdaui_entry_combo_set_unknown_color;
}
@@ -1040,3 +1043,10 @@ gdaui_entry_combo_grab_focus (GdauiDataEntry *iface)
if (combo->priv->combo_entry)
gtk_widget_grab_focus (combo->priv->combo_entry);
}
+
+static void
+gdaui_entry_combo_set_unknown_color (GdauiDataEntry *de, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha)
+{
+ gdaui_entry_shell_set_ucolor (GDAUI_ENTRY_SHELL (de), red, green, blue, alpha);
+}
diff --git a/libgda-ui/data-entries/gdaui-entry-shell.c b/libgda-ui/data-entries/gdaui-entry-shell.c
index cf26813..6a07d24 100644
--- a/libgda-ui/data-entries/gdaui-entry-shell.c
+++ b/libgda-ui/data-entries/gdaui-entry-shell.c
@@ -476,7 +476,7 @@ gdaui_entry_shell_refresh (GdauiEntryShell *shell)
/**
* gdaui_entry_shell_set_unknown:
- * @shell: the GdauiEntryShell widget to refresh
+ * @shell: the #GdauiEntryShell widget to refresh
* @unknown: set to %TRUE if @shell's contents is unavailable and should not be modified
*
* Defines if @shell's contents is in an undefined state (shows or hides @shell's contents)
@@ -488,3 +488,24 @@ gdaui_entry_shell_set_unknown (GdauiEntryShell *shell, gboolean unknown)
widget_embedder_set_valid ((WidgetEmbedder*) shell->priv->embedder, !unknown);
}
+
+/**
+ * gdaui_entry_shell_set_ucolor:
+ * @shell: a #GdauiEntryShell
+ * @red: the red component of a color
+ * @green: the green component of a color
+ * @blue: the blue component of a color
+ * @alpha: the alpha component of a color
+ *
+ * Defines the color to be used when @de displays an invalid value. Any value not
+ * between 0. and 1. will result in the default hard coded values to be used (grayish).
+ *
+ * Since: 4.2.13
+ */
+void
+gdaui_entry_shell_set_ucolor (GdauiEntryShell *shell, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha)
+{
+ g_return_if_fail (GDAUI_IS_ENTRY_SHELL (shell));
+ widget_embedder_set_ucolor ((WidgetEmbedder*) shell->priv->embedder, red, green, blue, alpha);
+}
diff --git a/libgda-ui/data-entries/gdaui-entry-shell.h b/libgda-ui/data-entries/gdaui-entry-shell.h
index 5c83659..dfa22b7 100644
--- a/libgda-ui/data-entries/gdaui-entry-shell.h
+++ b/libgda-ui/data-entries/gdaui-entry-shell.h
@@ -58,6 +58,9 @@ GType gdaui_entry_shell_get_type (void) G_GNUC_CONST;
void gdaui_entry_shell_pack_entry (GdauiEntryShell *shell, GtkWidget *main_widget);
void gdaui_entry_shell_refresh (GdauiEntryShell *shell);
void gdaui_entry_shell_set_unknown (GdauiEntryShell *shell, gboolean unknown);
+void gdaui_entry_shell_set_ucolor (GdauiEntryShell *shell, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha);
+
G_END_DECLS
diff --git a/libgda-ui/data-entries/gdaui-entry-wrapper.c b/libgda-ui/data-entries/gdaui-entry-wrapper.c
index 3847d12..b04fbb1 100644
--- a/libgda-ui/data-entries/gdaui-entry-wrapper.c
+++ b/libgda-ui/data-entries/gdaui-entry-wrapper.c
@@ -57,6 +57,8 @@ static gboolean gdaui_entry_wrapper_can_expand (GdauiDataEntry *de
static void gdaui_entry_wrapper_set_editable (GdauiDataEntry *de, gboolean editable);
static gboolean gdaui_entry_wrapper_get_editable (GdauiDataEntry *de);
static void gdaui_entry_wrapper_grab_focus (GdauiDataEntry *de);
+static void gdaui_entry_wrapper_set_unknown_color (GdauiDataEntry *de, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha);
/* properties */
enum {
@@ -138,6 +140,7 @@ gdaui_entry_wrapper_data_entry_init (GdauiDataEntryIface *iface)
iface->set_editable = gdaui_entry_wrapper_set_editable;
iface->get_editable = gdaui_entry_wrapper_get_editable;
iface->grab_focus = gdaui_entry_wrapper_grab_focus;
+ iface->set_unknown_color = gdaui_entry_wrapper_set_unknown_color;
}
@@ -881,3 +884,10 @@ gdaui_entry_wrapper_grab_focus (GdauiDataEntry *iface)
gtk_widget_grab_focus (mgwrap->priv->entry);
}
}
+
+static void
+gdaui_entry_wrapper_set_unknown_color (GdauiDataEntry *de, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha)
+{
+ gdaui_entry_shell_set_ucolor (GDAUI_ENTRY_SHELL (de), red, green, blue, alpha);
+}
diff --git a/libgda-ui/data-entries/widget-embedder.c b/libgda-ui/data-entries/widget-embedder.c
index 7ede546..173f1b1 100644
--- a/libgda-ui/data-entries/widget-embedder.c
+++ b/libgda-ui/data-entries/widget-embedder.c
@@ -97,6 +97,10 @@ widget_embedder_init (WidgetEmbedder *bin)
{
gtk_widget_set_has_window (GTK_WIDGET (bin), TRUE);
bin->valid = TRUE;
+ bin->red = -1.;
+ bin->green = -1.;
+ bin->blue = -1.;
+ bin->alpha = -1.;
}
GtkWidget *
@@ -381,10 +385,23 @@ widget_embedder_damage (GtkWidget *widget,
return TRUE;
}
+void
+widget_embedder_set_ucolor (WidgetEmbedder *bin, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha)
+{
+ bin->red = red;
+ bin->green = green;
+ bin->blue = blue;
+ bin->alpha = alpha;
+ gtk_widget_queue_draw (GTK_WIDGET (bin));
+}
+
+
static gboolean
widget_embedder_draw (GtkWidget *widget, cairo_t *cr)
{
WidgetEmbedder *bin = WIDGET_EMBEDDER (widget);
+#define MARGIN 1.5
GdkWindow *window;
window = gtk_widget_get_window (widget);
@@ -399,9 +416,17 @@ widget_embedder_draw (GtkWidget *widget, cairo_t *cr)
cairo_paint (cr);
if (! bin->valid) {
- cairo_set_source_rgba (cr, GDAUI_COLOR_UNKNOWN_MASK);
- cairo_rectangle (cr, child_area.x, child_area.y,
- child_area.width, child_area.height);
+ if ((bin->red >= 0.) && (bin->red <= 1.) &&
+ (bin->green >= 0.) && (bin->green <= 1.) &&
+ (bin->blue >= 0.) && (bin->blue <= 1.) &&
+ (bin->alpha >= 0.) && (bin->alpha <= 1.))
+ cairo_set_source_rgba (cr, bin->red, bin->green,
+ bin->blue, bin->alpha);
+ else
+ cairo_set_source_rgba (cr, GDAUI_COLOR_UNKNOWN_MASK);
+ cairo_rectangle (cr, child_area.x + MARGIN, child_area.y + MARGIN,
+ child_area.width - 2. * MARGIN,
+ child_area.height - 2. * MARGIN);
cairo_fill (cr);
}
}
diff --git a/libgda-ui/data-entries/widget-embedder.h b/libgda-ui/data-entries/widget-embedder.h
index 9fdb72c..366a9d1 100644
--- a/libgda-ui/data-entries/widget-embedder.h
+++ b/libgda-ui/data-entries/widget-embedder.h
@@ -35,6 +35,12 @@ struct _WidgetEmbedder
GtkWidget *child;
GdkWindow *offscreen_window;
gboolean valid;
+
+ /* unknown colors */
+ gdouble red;
+ gdouble green;
+ gdouble blue;
+ gdouble alpha;
};
struct _WidgetEmbedderClass
@@ -42,7 +48,9 @@ struct _WidgetEmbedderClass
GtkContainerClass parent_class;
};
-GType widget_embedder_get_type (void) G_GNUC_CONST;
-GtkWidget* widget_embedder_new (void);
-void widget_embedder_set_valid (WidgetEmbedder *bin, gboolean valid);
+GType widget_embedder_get_type (void) G_GNUC_CONST;
+GtkWidget* widget_embedder_new (void);
+void widget_embedder_set_valid (WidgetEmbedder *bin, gboolean valid);
+void widget_embedder_set_ucolor (WidgetEmbedder *bin, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha);
diff --git a/libgda-ui/gdaui-basic-form.c b/libgda-ui/gdaui-basic-form.c
index 2bda83c..ece40b8 100644
--- a/libgda-ui/gdaui-basic-form.c
+++ b/libgda-ui/gdaui-basic-form.c
@@ -169,6 +169,12 @@ struct _GdauiBasicFormPriv
GSList *size_groups; /* list of SizeGroup pointers */
GtkWidget *mainbox;
+
+ /* unknown value color */
+ gdouble red;
+ gdouble green;
+ gdouble blue;
+ gdouble alpha;
};
@@ -416,6 +422,11 @@ gdaui_basic_form_init (GdauiBasicForm *wid)
G_CALLBACK (popup_menu_cb), wid);
g_signal_connect (evbox, "button-press-event",
G_CALLBACK (button_press_event_cb), wid);
+
+ wid->priv->red = .98;
+ wid->priv->green = .93;
+ wid->priv->blue = .25;
+ wid->priv->alpha = .50;
}
/**
@@ -1060,6 +1071,9 @@ create_entry_widget (SingleEntry *sentry)
sentry->entry = GDAUI_DATA_ENTRY (entry);
g_object_ref_sink (sentry->entry);
gdaui_data_entry_set_editable (sentry->entry, editable);
+ gdaui_data_entry_set_unknown_color (sentry->entry, sentry->form->priv->red,
+ sentry->form->priv->green, sentry->form->priv->blue,
+ sentry->form->priv->alpha);
GSList *list;
for (list = sentry->form->priv->size_groups; list; list = list->next) {
@@ -2403,3 +2417,36 @@ gdaui_basic_form_remove_from_size_group (GdauiBasicForm *form, GtkSizeGroup *siz
}
}
}
+
+/**
+ * gdaui_basic_form_set_unknown_color:
+ * @form: a #GdauiBasicForm widget
+ * @red: the red component of a color
+ * @green: the green component of a color
+ * @blue: the blue component of a color
+ * @alpha: the alpha component of a color
+ *
+ * Defines the color to be used when @form displays an invalid value. Any value not
+ * between 0. and 1. will result in the default hard coded values to be used (grayish).
+ *
+ * Since: 4.2.13
+ */
+void
+gdaui_basic_form_set_unknown_color (GdauiBasicForm *form, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha)
+{
+ g_return_if_fail (GDAUI_IS_BASIC_FORM (form));
+ form->priv->red = red;
+ form->priv->green = green;
+ form->priv->blue = blue;
+ form->priv->alpha = alpha;
+
+ GSList *list;
+ for (list = form->priv->s_entries; list; list = list->next) {
+ SingleEntry *se;
+ se = (SingleEntry *) list->data;
+ gdaui_data_entry_set_unknown_color (se->entry, form->priv->red,
+ form->priv->green, form->priv->blue,
+ form->priv->alpha);
+ }
+}
diff --git a/libgda-ui/gdaui-basic-form.h b/libgda-ui/gdaui-basic-form.h
index 5b05eb4..3e303dd 100644
--- a/libgda-ui/gdaui-basic-form.h
+++ b/libgda-ui/gdaui-basic-form.h
@@ -183,6 +183,9 @@ void gdaui_basic_form_add_to_size_group (GdauiBasicForm *for
void gdaui_basic_form_remove_from_size_group (GdauiBasicForm *form, GtkSizeGroup *size_group,
GdauiBasicFormPart part);
+void gdaui_basic_form_set_unknown_color (GdauiBasicForm *form, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha);
+
G_END_DECLS
#endif
diff --git a/libgda-ui/gdaui-data-entry.c b/libgda-ui/gdaui-data-entry.c
index 690f714..f30e60d 100644
--- a/libgda-ui/gdaui-data-entry.c
+++ b/libgda-ui/gdaui-data-entry.c
@@ -487,3 +487,26 @@ gdaui_data_entry_grab_focus (GdauiDataEntry *de)
if (GDAUI_DATA_ENTRY_GET_IFACE (de)->grab_focus)
(GDAUI_DATA_ENTRY_GET_IFACE (de)->grab_focus) (de);
}
+
+/**
+ * gdaui_data_entry_set_unknown_color:
+ * @de: a #GtkWidget object which implements the #GdauiDataEntry interface
+ * @red: the red component of a color
+ * @green: the green component of a color
+ * @blue: the blue component of a color
+ * @alpha: the alpha component of a color
+ *
+ * Defines the color to be used when @de displays an invalid value. Any value not
+ * between 0. and 1. will result in the default hard coded values to be used (grayish).
+ *
+ * Since: 4.2.13
+ */
+void
+gdaui_data_entry_set_unknown_color (GdauiDataEntry *de, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha)
+{
+ g_return_if_fail (GDAUI_IS_DATA_ENTRY (de));
+
+ if (GDAUI_DATA_ENTRY_GET_IFACE (de)->set_unknown_color)
+ (GDAUI_DATA_ENTRY_GET_IFACE (de)->set_unknown_color) (de, red, green, blue, alpha);
+}
diff --git a/libgda-ui/gdaui-data-entry.h b/libgda-ui/gdaui-data-entry.h
index ac0157d..97f0e3f 100644
--- a/libgda-ui/gdaui-data-entry.h
+++ b/libgda-ui/gdaui-data-entry.h
@@ -73,11 +73,13 @@ struct _GdauiDataEntryIface
void (*grab_focus) (GdauiDataEntry *de);
/* another signal */
- void (* expand_changed) (GdauiDataEntry *de);
+ void (*expand_changed) (GdauiDataEntry *de);
+
+ void (*set_unknown_color) (GdauiDataEntry *de, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha);
/*< private >*/
/* Padding for future expansion */
- void (*_gdaui_reserved1) (void);
void (*_gdaui_reserved2) (void);
void (*_gdaui_reserved3) (void);
void (*_gdaui_reserved4) (void);
@@ -135,6 +137,9 @@ void gdaui_data_entry_set_editable (GdauiDataEntry *de, gbo
gboolean gdaui_data_entry_get_editable (GdauiDataEntry *de);
void gdaui_data_entry_grab_focus (GdauiDataEntry *de);
+void gdaui_data_entry_set_unknown_color (GdauiDataEntry *de, gdouble red, gdouble green,
+ gdouble blue, gdouble alpha);
+
G_END_DECLS
#endif
diff --git a/libgda-ui/gdaui-raw-form.c b/libgda-ui/gdaui-raw-form.c
index 7089731..a456d57 100644
--- a/libgda-ui/gdaui-raw-form.c
+++ b/libgda-ui/gdaui-raw-form.c
@@ -292,6 +292,9 @@ gdaui_raw_form_init (GdauiRawForm *wid)
wid->priv->filter = NULL;
wid->priv->filter_window = NULL;
+
+ /* raw forms' default unknown color */
+ gdaui_basic_form_set_unknown_color ((GdauiBasicForm*) wid, -1., -1., -1., -1.);
}
/**
diff --git a/libgda-ui/libgda-ui.symbols b/libgda-ui/libgda-ui.symbols
index a247e2a..b7c30cc 100644
--- a/libgda-ui/libgda-ui.symbols
+++ b/libgda-ui/libgda-ui.symbols
@@ -18,6 +18,7 @@
gdaui_basic_form_set_as_reference
gdaui_basic_form_set_entries_to_default
gdaui_basic_form_set_layout_from_file
+ gdaui_basic_form_set_unknown_color
gdaui_cloud_create_filter_widget
gdaui_cloud_filter
gdaui_cloud_get_type
@@ -58,6 +59,7 @@
gdaui_data_entry_set_reference_value
gdaui_data_entry_set_value
gdaui_data_entry_set_value_type
+ gdaui_data_entry_set_unknown_color
gdaui_data_filter_get_type
gdaui_data_filter_new
gdaui_data_proxy_column_set_editable
@@ -101,6 +103,7 @@
gdaui_entry_combo_set_default_values
gdaui_entry_combo_set_values
gdaui_entry_combo_set_reference_values
+ gdaui_entry_combo_set_unknown_color
gdaui_entry_common_time_get_type
gdaui_entry_common_time_new
gdaui_entry_date_get_type
@@ -121,6 +124,7 @@
gdaui_entry_shell_get_type
gdaui_entry_shell_pack_entry
gdaui_entry_shell_refresh
+ gdaui_entry_shell_set_ucolor
gdaui_entry_string_get_type
gdaui_entry_string_new
gdaui_entry_time_get_type
@@ -130,6 +134,7 @@
gdaui_entry_wrapper_contents_activated
gdaui_entry_wrapper_contents_changed
gdaui_entry_wrapper_get_type
+ gdaui_entry_wrapper_set_unknown_color
gdaui_formatted_entry_get_text
gdaui_formatted_entry_get_type
gdaui_formatted_entry_new
diff --git a/testing/gdaui-test-errors.c b/testing/gdaui-test-errors.c
index e5120db..0f4b6ae 100644
--- a/testing/gdaui-test-errors.c
+++ b/testing/gdaui-test-errors.c
@@ -24,6 +24,20 @@ static void destroy (G_GNUC_UNUSED GtkWidget *widget, G_GNUC_UNUSED gpointer dat
gtk_main_quit ();
}
+static gboolean change_unknow_color (GdauiBasicForm *form)
+{
+ static gdouble red = .3;
+ static gdouble green = .1;
+ static gdouble blue = .1;
+ static gdouble alpha = .5;
+
+ red += .075;
+ if (red >= 1.)
+ red = .3;
+ gdaui_basic_form_set_unknown_color (form, red, green, blue, alpha);
+ return TRUE; /* keep timer */
+}
+
int
main (int argc, char *argv[])
{
@@ -51,6 +65,11 @@ main (int argc, char *argv[])
form = gdaui_form_new (model);
gtk_box_pack_start (GTK_BOX (vbox), form, FALSE, FALSE, 0);
+ GtkWidget *raw;
+ g_object_get (form, "raw-form", &raw, NULL);
+ g_timeout_add (80, (GSourceFunc) change_unknow_color, raw);
+ g_object_unref (raw);
+
g_object_set (G_OBJECT (form),
"info-flags",
GDAUI_DATA_PROXY_INFO_CURRENT_ROW |
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]