[glade3/glade-3-8] Revert " * gladeui/Makefile.am, gladeui/glade-custom.[ch]: Removed support for old"



commit 2245d7778c3d4493263a84b059f81ac98b3dea62
Author: Tristan Van Berkom <tristan van berkom gmail com>
Date:   Tue Dec 14 16:30:22 2010 +0900

    Revert "	* gladeui/Makefile.am, gladeui/glade-custom.[ch]: Removed support for old"
    
    This reverts commit b6dd2b5baac587473c7a929f968c314c28a9242f.
    
    Conflicts:
    
    	plugins/gtk+/gtk+.xml.in

 ChangeLog                  |    7 +-
 gladeui/Makefile.am        |    2 +
 gladeui/glade-custom.c     |  281 ++++++++++++++++++++++++++++++++++++++++++++
 gladeui/glade-custom.h     |   62 ++++++++++
 plugins/gtk+/gtk+.xml.in   |    1 +
 plugins/python/Makefile.am |    2 +-
 6 files changed, 349 insertions(+), 6 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1f490f9..ac864e2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,8 @@
 
 	* Reverted 3.0 commit, now targetting this branch to the final GTK+ 2.x chapter
 
+	* Reverted the commit that removes the old fashioned "Custom Widget" handling.
+
 2010-11-12  Johannes Schmid <jhs gnome org>
 
 	* gladeui/glade-project.c:
@@ -90,11 +92,6 @@
 	* plugins/gtk/gtk+.xml.in, plugins/gtk/glade-gtk.c: Removed all reference to
 	  deprecated GTK+ widgets (anything removed in 3.0).
 
-	* gladeui/Makefile.am, gladeui/glade-custom.[ch]: Removed support for old
-	  fashioned custom widgets from glade-2.
-
-	* plugins/python/Makefile.am: Fixed to link with new core library (libgladeui-2).
-
 2010-06-10  Javier Jardón <jjardon gnome org>
 
 	* m4/python.m4: quote the definition of AM_CHECK_PYMOD
diff --git a/gladeui/Makefile.am b/gladeui/Makefile.am
index b0e29e8..4558d51 100644
--- a/gladeui/Makefile.am
+++ b/gladeui/Makefile.am
@@ -58,6 +58,7 @@ libgladeui_1_la_SOURCES = \
 	glade-project.c \
 	glade-parameter.c \
 	glade-placeholder.c \
+	glade-custom.c \
 	glade-inspector.c \
 	glade-xml-utils.c \
 	glade-palette.c \
@@ -122,6 +123,7 @@ libgladeuiinclude_HEADERS = \
 	glade-inspector.h \
 	glade-parameter.h \
 	glade-placeholder.h \
+	glade-custom.h \
 	glade-editor.h \
 	glade-editor-property.h \
 	glade-signal-editor.h \
diff --git a/gladeui/glade-custom.c b/gladeui/glade-custom.c
new file mode 100644
index 0000000..ffafa2f
--- /dev/null
+++ b/gladeui/glade-custom.c
@@ -0,0 +1,281 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * glade-custom.c - An emulation of a custom widget used to
+ *                  support the glade-2 style custom widget.
+ *
+ * Copyright (C) 2005 The GNOME Foundation.
+ *
+ * Author(s):
+ *      Tristan Van Berkom <tvb gnome 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <glib/gi18n-lib.h>
+
+#include "glade-custom.h"
+
+enum
+{
+	PROP_0,
+	PROP_CREATION,
+	PROP_STR1,
+	PROP_STR2,
+	PROP_INT1,
+	PROP_INT2
+};
+
+static GtkWidgetClass *parent_class = NULL;
+
+/* Ignore properties.
+ */
+static void
+glade_custom_set_property (GObject      *object,
+			   guint         prop_id,
+			   const GValue *value,
+			   GParamSpec   *pspec)
+{
+}
+
+static void
+glade_custom_get_property (GObject    *object,
+			   guint       prop_id,
+			   GValue     *value,
+			   GParamSpec *pspec)
+{
+}
+
+
+static void
+glade_custom_finalize (GObject *object)
+{
+	GladeCustom *custom;
+
+	g_return_if_fail (GLADE_IS_CUSTOM (object));
+	custom = GLADE_CUSTOM (object);
+
+	/* custom->custom_pixmap can be NULL if the custom
+	 * widget is destroyed before it's realized */
+	if (custom->custom_pixmap)
+		g_object_unref (custom->custom_pixmap);
+
+	G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+static void
+glade_custom_send_configure (GladeCustom *custom)
+{
+	GtkWidget *widget;
+	GtkAllocation allocation;
+	GdkEvent *event = gdk_event_new (GDK_CONFIGURE);
+
+	widget = GTK_WIDGET (custom);
+
+	event->configure.window = g_object_ref (gtk_widget_get_window (widget));
+	event->configure.send_event = TRUE;
+	gtk_widget_get_allocation (widget, &allocation);
+	event->configure.x = allocation.x;
+	event->configure.y = allocation.y;
+	event->configure.width = allocation.width;
+	event->configure.height = allocation.height;
+
+	gtk_widget_event (widget, event);
+	gdk_event_free (event);
+}
+
+static void
+glade_custom_realize (GtkWidget *widget)
+{
+	GladeCustom *custom;
+	GtkAllocation allocation;
+	GdkWindow *window;
+	GdkWindowAttr attributes;
+	gint attributes_mask;
+
+	g_return_if_fail (GLADE_IS_CUSTOM (widget));
+
+	custom = GLADE_CUSTOM (widget);
+
+	gtk_widget_set_realized (widget, TRUE);
+
+	attributes.window_type = GDK_WINDOW_CHILD;
+	gtk_widget_get_allocation (widget, &allocation);
+	attributes.x = allocation.x;
+	attributes.y = allocation.y;
+	attributes.width = allocation.width;
+	attributes.height = allocation.height;
+	attributes.wclass = GDK_INPUT_OUTPUT;
+	attributes.visual = gtk_widget_get_visual (widget);
+	attributes.colormap = gtk_widget_get_colormap (widget);
+	attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
+
+	attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+
+	window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
+	gtk_widget_set_window (widget, window);
+	gdk_window_set_user_data (window, custom);
+
+	gtk_widget_style_attach (widget);
+
+	glade_custom_send_configure (custom);
+
+	if (!custom->custom_pixmap)
+	{
+		custom->custom_pixmap = 
+			gdk_pixmap_colormap_create_from_xpm_d 
+			(NULL, gtk_widget_get_colormap (GTK_WIDGET (custom)),
+			 NULL, NULL, custom_xpm);
+
+		g_assert(G_IS_OBJECT(custom->custom_pixmap));
+	}
+	gdk_window_set_back_pixmap (gtk_widget_get_window (GTK_WIDGET (custom)), custom->custom_pixmap, FALSE);
+}
+
+static void
+glade_custom_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+{
+	g_return_if_fail (GLADE_IS_CUSTOM (widget));
+	g_return_if_fail (allocation != NULL);
+
+	gtk_widget_set_allocation (widget, allocation);
+
+	if (gtk_widget_get_realized (widget))
+	{
+		gdk_window_move_resize (gtk_widget_get_window (widget),
+					allocation->x, allocation->y,
+					allocation->width, allocation->height);
+
+		glade_custom_send_configure (GLADE_CUSTOM (widget));
+	}
+}
+
+static gboolean
+glade_custom_expose (GtkWidget *widget, GdkEventExpose *event)
+{
+	GtkStyle *style;
+	GdkGC *light_gc;
+	GdkGC *dark_gc;
+	gint w, h;
+
+	g_return_val_if_fail (GLADE_IS_CUSTOM (widget), FALSE);
+
+	style = gtk_widget_get_style (widget);
+	light_gc = style->light_gc[GTK_STATE_NORMAL];
+	dark_gc  = style->dark_gc[GTK_STATE_NORMAL];
+	gdk_drawable_get_size (event->window, &w, &h);
+
+	gdk_draw_line (event->window, light_gc, 0, 0, w - 1, 0);
+	gdk_draw_line (event->window, light_gc, 0, 0, 0, h - 1);
+	gdk_draw_line (event->window, dark_gc, 0, h - 1, w - 1, h - 1);
+	gdk_draw_line (event->window, dark_gc, w - 1, 0, w - 1, h - 1);
+
+	return FALSE;
+}
+
+static void
+glade_custom_init (GladeCustom *custom)
+{
+	custom->custom_pixmap = NULL;
+
+	gtk_widget_set_size_request (GTK_WIDGET (custom),
+				     GLADE_CUSTOM_WIDTH_REQ,
+				     GLADE_CUSTOM_HEIGHT_REQ);
+
+	gtk_widget_show (GTK_WIDGET (custom));
+}
+
+static void
+glade_custom_class_init (GladeCustomClass *klass)
+{
+	GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+	GObjectClass   *object_class = G_OBJECT_CLASS (klass);
+
+	parent_class = g_type_class_peek_parent (klass);
+
+	object_class->finalize     = glade_custom_finalize;
+	object_class->set_property = glade_custom_set_property;
+	object_class->get_property = glade_custom_get_property;
+
+	widget_class->realize       = glade_custom_realize;
+	widget_class->size_allocate = glade_custom_size_allocate;
+	widget_class->expose_event  = glade_custom_expose;
+
+	g_object_class_install_property 
+		(object_class, PROP_CREATION,
+		 g_param_spec_string 
+		 ("creation-function", _("Creation Function"), 
+		  _("The function which creates this widget"),
+		  NULL, G_PARAM_READWRITE));
+
+	g_object_class_install_property 
+		(object_class, PROP_STR1,
+		 g_param_spec_string 
+		 ("string1", _("String 1"), 
+		  _("The first string argument to pass to the function"),
+		  NULL, G_PARAM_READWRITE));
+
+	g_object_class_install_property 
+		(object_class, PROP_STR2,
+		 g_param_spec_string 
+		 ("string2", _("String 2"), 
+		  _("The second string argument to pass to the function"),
+		  NULL, G_PARAM_READWRITE));
+
+	g_object_class_install_property 
+		(object_class, PROP_INT1,
+		 g_param_spec_int 
+		 ("int1", _("Integer 1"), 
+		  _("The first integer argument to pass to the function"),
+		  G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
+
+	g_object_class_install_property 
+		(object_class, PROP_INT2,
+		 g_param_spec_int 
+		 ("int2", _("Integer 2"), 
+		  _("The second integer argument to pass to the function"),
+		  G_MININT, G_MAXINT, 0, G_PARAM_READWRITE));
+}
+
+GType
+custom_get_type (void)
+{
+	static GType custom_type = 0;
+
+	if (!custom_type)
+	{
+		static const GTypeInfo custom_info = 
+		{
+			sizeof (GladeCustomClass),
+			(GBaseInitFunc) NULL,
+			(GBaseFinalizeFunc) NULL,
+			(GClassInitFunc) glade_custom_class_init,
+			(GClassFinalizeFunc) NULL,
+			NULL,           /* class_data */
+			sizeof (GladeCustom),
+			0,              /* n_preallocs */
+			(GInstanceInitFunc) glade_custom_init,
+		};
+		custom_type = 
+			g_type_register_static (GTK_TYPE_WIDGET,
+						"Custom",
+						&custom_info, 0);
+	}
+	return custom_type;
+}
diff --git a/gladeui/glade-custom.h b/gladeui/glade-custom.h
new file mode 100644
index 0000000..c804627
--- /dev/null
+++ b/gladeui/glade-custom.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+#ifndef __GLADE_CUSTOM_H__
+#define __GLADE_CUSTOM_H__
+
+#include <gladeui/glade.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GLADE_TYPE_CUSTOM            (custom_get_type ())
+#define GLADE_CUSTOM(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLADE_TYPE_CUSTOM, GladeCustom))
+#define GLADE_CUSTOM_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GLADE_TYPE_CUSTOM, GladeCustomClass))
+#define GLADE_IS_CUSTOM(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLADE_TYPE_CUSTOM))
+#define GLADE_IS_CUSTOM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GLADE_TYPE_CUSTOM))
+#define GLADE_CUSTOM_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GLADE_TYPE_CUSTOM, GladeCustomClass))
+
+#define GLADE_CUSTOM_WIDTH_REQ    20
+#define GLADE_CUSTOM_HEIGHT_REQ   20
+
+/* taken from glade 2 */
+static char * custom_xpm[] = {
+"8 8 4 1",
+"       c None",
+".      c #BBBBBB",
+"+      c #D6D6D6",
+"@      c #6B5EFF",
+".+..+...",
+"+..@@@..",
+"      ++",
+"      ++",
+"+    +  ",
+".++@@@..",
+"..++....",
+"..++...."};
+
+
+typedef struct _GladeCustom      GladeCustom;
+typedef struct _GladeCustomClass GladeCustomClass;
+
+struct _GladeCustom
+{
+	GtkWidget widget;
+
+	GdkPixmap *custom_pixmap;
+	
+	
+};
+
+struct _GladeCustomClass
+{
+	GtkWidgetClass parent_class;
+};
+
+/* Since the class is called Custom and not GladeCustom, 
+ * glade-widget-class will search for custom_get_type() instead
+ * if glade_custom_get_type()
+ */ 
+GType  custom_get_type  (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* __GLADE_CUSTOM_H__ */
diff --git a/plugins/gtk+/gtk+.xml.in b/plugins/gtk+/gtk+.xml.in
index ef412ec..103248d 100644
--- a/plugins/gtk+/gtk+.xml.in
+++ b/plugins/gtk+/gtk+.xml.in
@@ -3534,6 +3534,7 @@ embedded in another object</_tooltip>
     <glade-widget-class-ref name="GtkVRuler"/>
     <glade-widget-class-ref name="GtkCurve"/>
     <glade-widget-class-ref name="GtkGammaCurve"/>
+    <glade-widget-class-ref name="Custom"/>
   </glade-widget-group>
 
   <glade-widget-group name="gtk-obsolete" _title="Gtk+ Obsolete">
diff --git a/plugins/python/Makefile.am b/plugins/python/Makefile.am
index 8abc73a..0c21542 100644
--- a/plugins/python/Makefile.am
+++ b/plugins/python/Makefile.am
@@ -1,6 +1,6 @@
 ## Process this file with automake to produce Makefile.in
 
-libgladeui = $(top_builddir)/gladeui/libgladeui-2.la
+libgladeui = $(top_builddir)/gladeui/libgladeui-1.la
 
 
 # libgladepython



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