dia r3941 - in trunk: . lib



Author: hans
Date: Sun Apr 13 16:36:04 2008
New Revision: 3941
URL: http://svn.gnome.org/viewvc/dia?rev=3941&view=rev

Log:
	[currently unused: first step for property editor with GtkTreeView]
	* lib/diamarshal.list : add marshaler
	* lib/diacellrendererproperty.[hc] : boilerplate for CellRenderers
	* lib/makefile.msc lib/Makefile.am : build new files
	* lib/prop_sdarray.c : prepare to make the list editable
	


Added:
   trunk/lib/diacellrendererproperty.c   (contents, props changed)
   trunk/lib/diacellrendererproperty.h   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/lib/Makefile.am
   trunk/lib/diamarshal.list
   trunk/lib/makefile.msc
   trunk/lib/prop_sdarray.c

Modified: trunk/lib/Makefile.am
==============================================================================
--- trunk/lib/Makefile.am	(original)
+++ trunk/lib/Makefile.am	Sun Apr 13 16:36:04 2008
@@ -166,6 +166,10 @@
 		prefs.h \
 	        newgroup.c \
 	        newgroup.h \
+		\
+		diacellrendererproperty.c \
+		diacellrendererproperty.h \
+		\
 		dia-lib-icons.h
 
 #		charconv.c \

Added: trunk/lib/diacellrendererproperty.c
==============================================================================
--- (empty file)
+++ trunk/lib/diacellrendererproperty.c	Sun Apr 13 16:36:04 2008
@@ -0,0 +1,356 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * diacellrendererproperty.c - a cell renderer for Dia's StdProps system, to be used in GtkTreeView
+ * Copyright (C) 2008 Hans Breuer
+ *
+ * based on :
+ * diacellrendererproperty.c
+ * Copyright (C) 2003 Michael Natterer <mitch dia org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include <gtk/gtk.h>
+
+#include "diacellrendererproperty.h"
+
+#include "diarenderer.h"
+#include "diamarshal.h"
+#include "message.h"
+
+enum
+{
+  CLICKED,
+  LAST_SIGNAL
+};
+
+enum
+{
+  PROP_0,
+  PROP_RENDERER,
+  PROP_PROPERTY
+};
+
+static void dia_cell_renderer_property_finalize     (GObject         *object);
+static void dia_cell_renderer_property_get_property (GObject         *object,
+                                                     guint            param_id,
+                                                     GValue          *value,
+                                                     GParamSpec      *pspec);
+static void dia_cell_renderer_property_set_property (GObject         *object,
+                                                     guint            param_id,
+                                                     const GValue    *value,
+                                                     GParamSpec      *pspec);
+static void dia_cell_renderer_property_get_size     (GtkCellRenderer *cell,
+                                                     GtkWidget       *widget,
+                                                     GdkRectangle    *rectangle,
+                                                     gint            *x_offset,
+                                                     gint            *y_offset,
+                                                     gint            *width,
+                                                     gint            *height);
+static void dia_cell_renderer_property_render       (GtkCellRenderer *cell,
+                                                     GdkWindow       *window,
+                                                     GtkWidget       *widget,
+                                                     GdkRectangle    *background_area,
+                                                     GdkRectangle    *cell_area,
+                                                     GdkRectangle    *expose_area,
+                                                     GtkCellRendererState flags);
+static gboolean dia_cell_renderer_property_activate (GtkCellRenderer *cell,
+                                                     GdkEvent        *event,
+                                                     GtkWidget       *widget,
+                                                     const gchar     *path,
+                                                     GdkRectangle    *background_area,
+                                                     GdkRectangle    *cell_area,
+                                                     GtkCellRendererState flags);
+
+
+G_DEFINE_TYPE (DiaCellRendererProperty, dia_cell_renderer_property, GTK_TYPE_CELL_RENDERER)
+
+#define parent_class dia_cell_renderer_property_parent_class
+
+static guint property_cell_signals[LAST_SIGNAL] = { 0 };
+
+
+static void
+dia_cell_renderer_property_class_init (DiaCellRendererPropertyClass *klass)
+{
+  GObjectClass         *object_class = G_OBJECT_CLASS (klass);
+  GtkCellRendererClass *cell_class   = GTK_CELL_RENDERER_CLASS (klass);
+
+  property_cell_signals[CLICKED] =
+    g_signal_new ("clicked",
+                  G_OBJECT_CLASS_TYPE (object_class),
+                  G_SIGNAL_RUN_LAST,
+                  G_STRUCT_OFFSET (DiaCellRendererPropertyClass, clicked),
+                  NULL, NULL,
+                  dia_marshal_VOID__STRING_FLAGS,
+                  G_TYPE_NONE, 2,
+                  G_TYPE_STRING,
+                  GDK_TYPE_MODIFIER_TYPE);
+
+  object_class->finalize     = dia_cell_renderer_property_finalize;
+  object_class->get_property = dia_cell_renderer_property_get_property;
+  object_class->set_property = dia_cell_renderer_property_set_property;
+
+  cell_class->get_size       = dia_cell_renderer_property_get_size;
+  cell_class->render         = dia_cell_renderer_property_render;
+  cell_class->activate       = dia_cell_renderer_property_activate;
+
+  klass->clicked             = NULL;
+
+  g_object_class_install_property (object_class, PROP_RENDERER,
+                                   g_param_spec_object ("renderer",
+                                                        NULL, NULL,
+                                                        DIA_TYPE_RENDERER,
+                                                        G_PARAM_READWRITE));
+  g_object_class_install_property (object_class, PROP_PROPERTY,
+                                   g_param_spec_object ("property",
+                                                        NULL, NULL,
+                                                        DIA_TYPE_RENDERER,
+                                                        G_PARAM_READWRITE));
+}
+
+static void
+dia_cell_renderer_property_init (DiaCellRendererProperty *cellproperty)
+{
+  GTK_CELL_RENDERER (cellproperty)->mode = GTK_CELL_RENDERER_MODE_ACTIVATABLE;
+}
+
+static void
+dia_cell_renderer_property_finalize (GObject *object)
+{
+  DiaCellRendererProperty *cell = DIA_CELL_RENDERER_PROPERTY (object);
+
+  if (cell->renderer)
+    {
+      g_object_unref (cell->renderer);
+      cell->renderer = NULL;
+    }
+
+  G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+dia_cell_renderer_property_get_property (GObject    *object,
+                                          guint       param_id,
+                                          GValue     *value,
+                                          GParamSpec *pspec)
+{
+  DiaCellRendererProperty *cell = DIA_CELL_RENDERER_PROPERTY (object);
+
+  switch (param_id)
+    {
+    case PROP_RENDERER:
+      g_value_set_object (value, cell->renderer);
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+      break;
+    }
+}
+
+static void
+dia_cell_renderer_property_set_property (GObject      *object,
+                                          guint         param_id,
+                                          const GValue *value,
+                                          GParamSpec   *pspec)
+{
+  DiaCellRendererProperty *cell = DIA_CELL_RENDERER_PROPERTY (object);
+
+  switch (param_id)
+    {
+    case PROP_RENDERER:
+      {
+        DiaRenderer *renderer;
+
+        renderer = (DiaRenderer *) g_value_dup_object (value);
+        if (cell->renderer)
+          g_object_unref (cell->renderer);
+        cell->renderer = renderer;
+      }
+      break;
+
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
+      break;
+    }
+}
+
+static void
+dia_cell_renderer_property_get_size (GtkCellRenderer *cell,
+                                      GtkWidget       *widget,
+                                      GdkRectangle    *cell_area,
+                                      gint            *x_offset,
+                                      gint            *y_offset,
+                                      gint            *width,
+                                      gint            *height)
+{
+  DiaCellRendererProperty *cellproperty;
+  gint                      view_width  = 0;
+  gint                      view_height = 0;
+  gint                      calc_width;
+  gint                      calc_height;
+
+#if 0
+  cellproperty = DIA_CELL_RENDERER_PROPERTY (cell);
+
+  if (cellproperty->renderer)
+    {
+      view_width  = (cellproperty->renderer->width  +
+                     2 * cellproperty->renderer->border_width);
+      view_height = (cellproperty->renderer->height +
+                     2 * cellproperty->renderer->border_width);
+    }
+#else
+  /* not sure how to translate, most props could have a fixed size for drawing */
+  view_width = 120;
+  view_height = 30;
+#endif
+
+  calc_width  = (gint) cell->xpad * 2 + view_width;
+  calc_height = (gint) cell->ypad * 2 + view_height;
+
+  if (x_offset) *x_offset = 0;
+  if (y_offset) *y_offset = 0;
+
+  if (cell_area && view_width > 0 && view_height > 0)
+    {
+      if (x_offset)
+        {
+          *x_offset = (((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
+                        1.0 - cell->xalign : cell->xalign) *
+                       (cell_area->width - calc_width - 2 * cell->xpad));
+          *x_offset = (MAX (*x_offset, 0) + cell->xpad);
+        }
+      if (y_offset)
+        {
+          *y_offset = (cell->yalign *
+                       (cell_area->height - calc_height - 2 * cell->ypad));
+          *y_offset = (MAX (*y_offset, 0) + cell->ypad);
+        }
+    }
+
+  if (width)  *width  = calc_width;
+  if (height) *height = calc_height;
+}
+
+static void
+dia_cell_renderer_property_render (GtkCellRenderer      *cell,
+                                    GdkWindow            *window,
+                                    GtkWidget            *widget,
+                                    GdkRectangle         *background_area,
+                                    GdkRectangle         *cell_area,
+                                    GdkRectangle         *expose_area,
+                                    GtkCellRendererState  flags)
+{
+  DiaCellRendererProperty *cellproperty;
+
+  cellproperty = DIA_CELL_RENDERER_PROPERTY (cell);
+
+  if (cellproperty->renderer)
+    {
+      if (! (flags & GTK_CELL_RENDERER_SELECTED))
+        {
+#if 0
+          dia_view_renderer_remove_idle (cellproperty->renderer);
+#endif
+        }
+#if 0
+      dia_view_renderer_draw (cellproperty->renderer, window, widget,
+                               cell_area, expose_area);
+#endif
+    }
+}
+
+static gboolean
+dia_cell_renderer_property_activate (GtkCellRenderer      *cell,
+                                      GdkEvent             *event,
+                                      GtkWidget            *widget,
+                                      const gchar          *path,
+                                      GdkRectangle         *background_area,
+                                      GdkRectangle         *cell_area,
+                                      GtkCellRendererState  flags)
+{
+  DiaCellRendererProperty *cellproperty;
+
+  cellproperty = DIA_CELL_RENDERER_PROPERTY (cell);
+
+  if (cellproperty->renderer)
+    {
+      GdkModifierType state = 0;
+
+      if (event && ((GdkEventAny *) event)->type == GDK_BUTTON_PRESS)
+        state = ((GdkEventButton *) event)->state;
+
+      if (! event ||
+          (((GdkEventAny *) event)->type == GDK_BUTTON_PRESS &&
+           ((GdkEventButton *) event)->button == 1))
+        {
+          dia_cell_renderer_property_clicked (cellproperty, path, state);
+
+          return TRUE;
+        }
+    }
+
+  return FALSE;
+}
+
+GtkCellRenderer *
+dia_cell_renderer_property_new (void)
+{
+  return g_object_new (DIA_TYPE_CELL_RENDERER_PROPERTY, NULL);
+}
+
+void
+dia_cell_renderer_property_clicked (DiaCellRendererProperty *cell,
+                                     const gchar              *path,
+                                     GdkModifierType           state)
+{
+  GdkEvent *event;
+
+  g_return_if_fail (DIA_IS_CELL_RENDERER_PROPERTY (cell));
+  g_return_if_fail (path != NULL);
+
+  g_signal_emit (cell, property_cell_signals[CLICKED], 0, path, state);
+
+  event = gtk_get_current_event ();
+
+  if (event)
+    {
+      GdkEventButton *bevent = (GdkEventButton *) event;
+
+      if (bevent->type == GDK_BUTTON_PRESS &&
+          (bevent->button == 1 || bevent->button == 2))
+        {
+#if 0
+          dia_view_popup_show (gtk_get_event_widget (event),
+                                bevent,
+                                cell->renderer->context,
+                                cell->renderer->property,
+                                cell->renderer->width,
+                                cell->renderer->height,
+                                cell->renderer->dot_for_dot);
+#else
+          /* either edit the property itself _or_ if it is a list open another property list */
+          message_warning ("Clicked!");
+#endif
+        }
+
+      gdk_event_free (event);
+    }
+}

Added: trunk/lib/diacellrendererproperty.h
==============================================================================
--- (empty file)
+++ trunk/lib/diacellrendererproperty.h	Sun Apr 13 16:36:04 2008
@@ -0,0 +1,68 @@
+/* Dia -- an diagram creation/manipulation program
+ * Copyright (C) 1998 Alexander Larsson
+ *
+ * diacellrendererproperty.h
+ * Copyright (C) 2008 Hans Breuer <hans breuer org>
+ *
+ * gimpcellrendererviewable.h
+ * Copyright (C) 2003 Michael Natterer <mitch gimp org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __DIA_CELL_RENDERER_PROPERTY_H__
+#define __DIA_CELL_RENDERER_PROPERTY_H__
+
+
+#include <gtk/gtkcellrenderer.h>
+#include "diatypes.h"
+
+#define DIA_TYPE_CELL_RENDERER_PROPERTY            (dia_cell_renderer_property_get_type ())
+#define DIA_CELL_RENDERER_PROPERTY(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CELL_RENDERER_PROPERTY, DiaCellRendererProperty))
+#define DIA_CELL_RENDERER_PROPERTY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CELL_RENDERER_PROPERTY, DiaCellRendererPropertyClass))
+#define DIA_IS_CELL_RENDERER_PROPERTY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CELL_RENDERER_PROPERTY))
+#define DIA_IS_CELL_RENDERER_PROPERTY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DIA_TYPE_CELL_RENDERER_PROPERTY))
+#define DIA_CELL_RENDERER_PROPERTY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_TYPE_CELL_RENDERER_PROPERTY, DiaCellRendererPropertyClass))
+
+
+typedef struct _DiaCellRendererPropertyClass DiaCellRendererPropertyClass;
+
+struct _DiaCellRendererProperty
+{
+  GtkCellRenderer   parent_instance;
+  
+  /*< private >*/
+  DiaRenderer      *renderer;
+};
+
+struct _DiaCellRendererPropertyClass
+{
+  GtkCellRendererClass  parent_class;
+
+  void (* clicked) (DiaCellRendererProperty *cell,
+                    const gchar              *path,
+                    GdkModifierType           state);
+};
+
+
+GType             dia_cell_renderer_property_get_type (void) G_GNUC_CONST;
+
+GtkCellRenderer * dia_cell_renderer_property_new      (void);
+
+void   dia_cell_renderer_property_clicked (DiaCellRendererProperty *cell,
+                                            const gchar              *path,
+                                            GdkModifierType           state);
+
+#endif /* __DIA_CELL_RENDERER_PROPERTY_H__ */

Modified: trunk/lib/diamarshal.list
==============================================================================
--- trunk/lib/diamarshal.list	(original)
+++ trunk/lib/diamarshal.list	Sun Apr 13 16:36:04 2008
@@ -26,3 +26,4 @@
 VOID: OBJECT
 VOID: INT
 VOID: POINTER,POINTER
+VOID: STRING, FLAGS

Modified: trunk/lib/makefile.msc
==============================================================================
--- trunk/lib/makefile.msc	(original)
+++ trunk/lib/makefile.msc	Sun Apr 13 16:36:04 2008
@@ -111,6 +111,9 @@
 	units.obj \
 	utils.obj \
 	widgets.obj \
+	\
+	diacellrendererproperty.obj \
+	\
 	diamarshal.obj \
 
 #

Modified: trunk/lib/prop_sdarray.c
==============================================================================
--- trunk/lib/prop_sdarray.c	(original)
+++ trunk/lib/prop_sdarray.c	Sun Apr 13 16:36:04 2008
@@ -238,6 +238,36 @@
   }
 }
 
+/*!
+ * Create a dialog containing the list of array properties
+ */
+static void
+darray_prop_edit (GtkWidget *widget, gpointer data)
+{
+  ArrayProperty *prop = data;
+  
+}
+
+static WIDGET *
+arrayprop_get_widget(ArrayProperty *prop, PropDialog *dialog) 
+{ 
+  GtkWidget *ret = gtk_button_new_with_label (prop->common.descr->tooltip);
+  gtk_signal_connect (GTK_OBJECT (ret), "clicked",
+                      (GtkSignalFunc) darray_prop_edit, prop);
+  
+  return ret;  
+}
+
+void 
+arrayprop_reset_widget(NoopProperty *prop, WIDGET *widget)
+{
+}
+
+void 
+arrayprop_set_from_widget(NoopProperty *prop, WIDGET *widget) 
+{
+}
+
 static gboolean 
 arrayprop_can_merge(const PropDescription *pd1, const PropDescription *pd2) 
 {
@@ -252,9 +282,9 @@
   (PropertyType_Load) arrayprop_load,
   (PropertyType_Save) arrayprop_save,
 
-  (PropertyType_GetWidget) unimplementedprop_get_widget,
-  (PropertyType_ResetWidget) unimplementedprop_reset_widget,
-  (PropertyType_SetFromWidget) unimplementedprop_set_from_widget,
+  (PropertyType_GetWidget) arrayprop_get_widget,
+  (PropertyType_ResetWidget) arrayprop_reset_widget,
+  (PropertyType_SetFromWidget) arrayprop_set_from_widget,
 
   (PropertyType_CanMerge) arrayprop_can_merge, 
   (PropertyType_GetFromOffset) sarrayprop_get_from_offset,
@@ -268,9 +298,9 @@
   (PropertyType_Load) arrayprop_load,
   (PropertyType_Save) arrayprop_save,
 
-  (PropertyType_GetWidget) unimplementedprop_get_widget,
-  (PropertyType_ResetWidget) unimplementedprop_reset_widget,
-  (PropertyType_SetFromWidget) unimplementedprop_set_from_widget,
+  (PropertyType_GetWidget) arrayprop_get_widget,
+  (PropertyType_ResetWidget) arrayprop_reset_widget,
+  (PropertyType_SetFromWidget) arrayprop_set_from_widget,
 
   (PropertyType_CanMerge) noopprop_can_merge, 
   (PropertyType_GetFromOffset) darrayprop_get_from_offset,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]