[libgda] Identify invalid data in grid
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda] Identify invalid data in grid
- Date: Fri, 25 Jun 2010 19:21:48 +0000 (UTC)
commit 7fc674124ad31be393ab03aec74764e94d9134fb
Author: Vivien Malerba <malerba gnome-db org>
Date: Fri Jun 25 20:35:27 2010 +0200
Identify invalid data in grid
as has been done for forms, not yet done for all
cell renderers
libgda-ui/data-entries/Makefile.am | 4 +-
libgda-ui/data-entries/drawing.c | 42 ++++++++++++++++++++
libgda-ui/data-entries/drawing.h | 27 +++++++++++++
.../data-entries/gdaui-data-cell-renderer-bin.c | 22 +++++++---
.../gdaui-data-cell-renderer-textual.c | 20 +++++++--
testing/gdaui-test-errors.c | 15 ++++++-
6 files changed, 117 insertions(+), 13 deletions(-)
---
diff --git a/libgda-ui/data-entries/Makefile.am b/libgda-ui/data-entries/Makefile.am
index 1def51e..6cc9cce 100644
--- a/libgda-ui/data-entries/Makefile.am
+++ b/libgda-ui/data-entries/Makefile.am
@@ -60,7 +60,9 @@ libgda_ui_data_entries_la_SOURCES = \
gdaui-entry-wrapper.c \
gdaui-entry.c \
gdaui-formatted-entry.c \
- gdaui-numeric-entry.c
+ gdaui-numeric-entry.c \
+ drawing.h \
+ drawing.c
xmldir = $(datadir)/libgda-4.0/ui
xml_in_files = \
diff --git a/libgda-ui/data-entries/drawing.c b/libgda-ui/data-entries/drawing.c
new file mode 100644
index 0000000..bea41a1
--- /dev/null
+++ b/libgda-ui/data-entries/drawing.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2010 Vivien Malerba <malerba gnome-db org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "drawing.h"
+
+void
+draw_invalid_area (GdkWindow *window, GdkRectangle *cell_area)
+{
+ cairo_t *cr;
+ cr = gdk_cairo_create (window);
+ cairo_set_source_rgba (cr, .5, .5, .5, .4);
+ cairo_rectangle (cr, cell_area->x, cell_area->y, cell_area->width, cell_area->height);
+ cairo_clip (cr);
+
+ gint i;
+ for (i = 0; ; i++) {
+ gint x = 10 * i;
+ if (x > cell_area->width + cell_area->height)
+ break;
+ cairo_move_to (cr, x + cell_area->x, cell_area->y);
+ cairo_line_to (cr, x + cell_area->x - cell_area->height,
+ cell_area->y + cell_area->height);
+ cairo_stroke (cr);
+ }
+ cairo_destroy (cr);
+}
diff --git a/libgda-ui/data-entries/drawing.h b/libgda-ui/data-entries/drawing.h
new file mode 100644
index 0000000..ad9cf10
--- /dev/null
+++ b/libgda-ui/data-entries/drawing.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010 Vivien Malerba <malerba gnome-db org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __DRAWING_H__
+#define __DRAWING_H__
+
+#include <gtk/gtk.h>
+
+void draw_invalid_area (GdkWindow *window, GdkRectangle *cell_area);
+
+#endif
diff --git a/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c b/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
index 3e469e8..b5e4f54 100644
--- a/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
+++ b/libgda-ui/data-entries/gdaui-data-cell-renderer-bin.c
@@ -1,6 +1,6 @@
/* gdaui-data-cell-renderer-bin.c
*
- * Copyright (C) 2009 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2009 - 2010 Vivien Malerba <malerba gnome-db org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -26,7 +26,7 @@
#include "gdaui-data-cell-renderer-bin.h"
#include "marshallers/gdaui-custom-marshal.h"
#include "common-bin.h"
-
+#include "drawing.h"
static void gdaui_data_cell_renderer_bin_get_property (GObject *object,
guint param_id,
@@ -78,6 +78,7 @@ struct _GdauiDataCellRendererBinPrivate
gboolean editable;
gboolean active;
gboolean null;
+ gboolean invalid;
};
enum {
@@ -271,15 +272,22 @@ gdaui_data_cell_renderer_bin_set_property (GObject *object,
switch (param_id) {
case PROP_VALUE:
/* Because we don't have a copy of the value, we MUST NOT free it! */
+ cell->priv->invalid = FALSE;
if (value) {
GValue *gval = g_value_get_boxed (value);
if (gval && (G_VALUE_TYPE (gval) != GDA_TYPE_NULL))
g_object_set (object, "pixbuf", attach_pixbuf, NULL);
- else
+ else if (gval)
+ g_object_set (object, "pixbuf", NULL, NULL);
+ else {
+ cell->priv->invalid = TRUE;
g_object_set (object, "pixbuf", NULL, NULL);
+ }
}
- else
+ else {
+ cell->priv->invalid = TRUE;
g_object_set (object, "pixbuf", NULL, NULL);
+ }
break;
case PROP_VALUE_ATTRIBUTES:
break;
@@ -357,11 +365,12 @@ gdaui_data_cell_renderer_bin_render (GtkCellRenderer *cell,
GdkRectangle *expose_area,
GtkCellRendererState flags)
{
+ GdauiDataCellRendererBin *datacell = (GdauiDataCellRendererBin*) cell;
GtkCellRendererClass *pixbuf_class = g_type_class_peek (GTK_TYPE_CELL_RENDERER_PIXBUF);
(pixbuf_class->render) (cell, window, widget, background_area, cell_area, expose_area, flags);
- if (GDAUI_DATA_CELL_RENDERER_BIN (cell)->priv->to_be_deleted) {
+ if (datacell->priv->to_be_deleted) {
GtkStyle *style;
guint xpad;
@@ -377,7 +386,8 @@ gdaui_data_cell_renderer_bin_render (GtkCellRenderer *cell,
cell_area->y + cell_area->height / 2.);
g_object_unref (style);
}
-
+ if (datacell->priv->invalid)
+ draw_invalid_area (window, cell_area);
}
static void
diff --git a/libgda-ui/data-entries/gdaui-data-cell-renderer-textual.c b/libgda-ui/data-entries/gdaui-data-cell-renderer-textual.c
index b80e9d9..5030c67 100644
--- a/libgda-ui/data-entries/gdaui-data-cell-renderer-textual.c
+++ b/libgda-ui/data-entries/gdaui-data-cell-renderer-textual.c
@@ -1,7 +1,7 @@
/* gdaui-data-cell-renderer-textual.c
*
* Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb redhat com>
- * Copyright (C) 2003 - 2009 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2003 - 2010 Vivien Malerba <malerba gnome-db org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -35,6 +35,7 @@
#include "gdaui-entry-timestamp.h"
#include <libgda/gda-enum-types.h>
#include "marshallers/gdaui-custom-marshal.h"
+#include "drawing.h"
#define MAX_ACCEPTED_STRING_LENGTH 500
@@ -96,6 +97,7 @@ struct _GdauiDataCellRendererTextualPrivate
gboolean type_forced; /* TRUE if ->type has been forced by a value and changed from what was specified */
GValue *value;
gboolean to_be_deleted;
+ gboolean invalid;
gchar *options;
gchar *currency;
@@ -418,6 +420,7 @@ gdaui_data_cell_renderer_textual_set_property (GObject *object,
}
}
+ datacell->priv->invalid = FALSE;
if (value) {
GValue *gval = g_value_get_pointer (value);
if (gval && !gda_value_is_null (gval)) {
@@ -488,11 +491,17 @@ gdaui_data_cell_renderer_textual_set_property (GObject *object,
g_object_set (G_OBJECT (object), "text", _("<non-printable>"),
"xalign", xalign, NULL);
}
- else
+ else if (gval)
g_object_set (G_OBJECT (object), "text", "", "xalign", xalign, NULL);
+ else {
+ datacell->priv->invalid = TRUE;
+ g_object_set (G_OBJECT (object), "text", "", "xalign", xalign, NULL);
+ }
}
- else
+ else {
+ datacell->priv->invalid = TRUE;
g_object_set (G_OBJECT (object), "text", "", "xalign", xalign, NULL);
+ }
g_object_notify (object, "value");
break;
@@ -601,10 +610,11 @@ gdaui_data_cell_renderer_textual_render (GtkCellRenderer *cell,
GtkCellRendererState flags)
{
+ GdauiDataCellRendererTextual *datacell = (GdauiDataCellRendererTextual*) cell;
GtkCellRendererClass *text_class = g_type_class_peek (GTK_TYPE_CELL_RENDERER_TEXT);
(text_class->render) (cell, window, widget, background_area, cell_area, expose_area, flags);
- if (GDAUI_DATA_CELL_RENDERER_TEXTUAL (cell)->priv->to_be_deleted) {
+ if (datacell->priv->to_be_deleted) {
GtkStyle *style;
guint xpad;
@@ -620,6 +630,8 @@ gdaui_data_cell_renderer_textual_render (GtkCellRenderer *cell,
cell_area->y + cell_area->height / 2.);
g_object_unref (style);
}
+ if (datacell->priv->invalid)
+ draw_invalid_area (window, cell_area);
}
static void
diff --git a/testing/gdaui-test-errors.c b/testing/gdaui-test-errors.c
index 68d97a0..65939eb 100644
--- a/testing/gdaui-test-errors.c
+++ b/testing/gdaui-test-errors.c
@@ -18,7 +18,7 @@ main (int argc, char *argv[])
gda_data_model_dump (model, NULL);
/* create UI */
- GtkWidget *window, *vbox, *button, *form;
+ GtkWidget *window, *vbox, *button, *form, *grid;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW(window), 400, 200);
g_signal_connect_swapped (window, "destroy",
@@ -31,7 +31,6 @@ main (int argc, char *argv[])
/* main form to list customers */
form = gdaui_form_new (model);
- g_object_unref (model);
gtk_box_pack_start (GTK_BOX (vbox), form, TRUE, TRUE, 0);
g_object_set (G_OBJECT (form),
@@ -42,6 +41,18 @@ main (int argc, char *argv[])
NULL
);
+ /* main grid to list customers */
+ grid = gdaui_grid_new (model);
+ g_object_unref (model);
+ gtk_box_pack_start (GTK_BOX (vbox), grid, TRUE, TRUE, 0);
+
+ g_object_set (G_OBJECT (grid),
+ "info-flags",
+ GDAUI_DATA_PROXY_INFO_CURRENT_ROW |
+ GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS,
+ NULL
+ );
+
/* button to quit */
button = gtk_button_new_with_label ("Quit");
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]