cvs: php-gtk /ext/spaned .cvsignore Makefile.in README config.m4 gtkshpaned.c gtkshpaned.h gtkspaned.c gtkspaned.h gtksvpaned.c gtksvpaned.h
php_spaned.c php_spaned.h spaned.defs spaned.overrides /test spaned.php
| From: | Markus Fischer | Date: | Fri, 07 Dec 2001 00:07:16 +0000 |
| Subject: | cvs: php-gtk /ext/spaned .cvsignore Makefile.in README config.m4 gtkshpaned.c gtkshpaned.h gtkspaned.c gtkspaned.h gtksvpaned.c gtksvpaned.h php_spaned.c php_spaned.h spaned.defs spaned.overrides /test spaned.php |
||
| Groups: | php.gtk.cvs | ||
| Request: | Send a blank email to php-gtk-cvs+get-377@lists.php.net to get a copy of this message | ||
mfischer Thu Dec 6 19:07:16 2001 EDT
Added files:
/php-gtk/ext/spaned .cvsignore Makefile.in README config.m4
gtkshpaned.c gtkshpaned.h gtkspaned.c
gtkspaned.h gtksvpaned.c gtksvpaned.h
php_spaned.c php_spaned.h spaned.defs
spaned.overrides
/php-gtk/test spaned.php
Log:
- Initial commit of GtkSPaned widget.
Index: php-gtk/ext/spaned/.cvsignore +++ php-gtk/ext/spaned/.cvsignore deps Makefile *.lo *.slo *.la libs libs.mk gen_* *.cache Index: php-gtk/ext/spaned/Makefile.in +++ php-gtk/ext/spaned/Makefile.in LTLIBRARY_NAME = libspaned.la LTLIBRARY_SOURCES = php_spaned.c gen_spaned.c gtkspaned.c gtkshpaned.c gtksvpaned.c LTLIBRARY_LIBADD = $(SPANED_SHARED_LIBADD) LTLIBRARY_SHARED_NAME = php_gtk_spaned.la LTLIBRARY_SHARED_LIBADD = $(SPANED_SHARED_LIBADD) include $(top_srcdir)/build/dynlib.mk php_spaned.o php_spaned.lo php_spaned.slo: gen_ce_spaned.h gen_spaned.c: spaned.defs spaned.overrides $(PHP) -q $(top_srcdir)/generator/generator.php -o $(srcdir)/spaned.overrides -p SPaned -r $(top_srcdir)/ext/gtk%2b/gtk.defs $(srcdir)/spaned.defs > gen_spaned.c gen_ce_spaned.h: gen_spaned.c grep -h "^PHP_GTK_EXPORT_CE" gen_spaned.c | sed -e "s!^!extern !" > gen_ce_spaned.h Index: php-gtk/ext/spaned/config.m4 +++ php-gtk/ext/spaned/config.m4 dnl $Id: config.m4,v 1.1 2001/12/07 00:07:15 mfischer Exp $ dnl config.m4 for spaned module PHP_GTK_ARG_ENABLE(spaned,for GtkSPaned support, [ --disable-spaned Disable GtkSPaned support], yes) if test "$PHP_GTK_SPANED" != "no"; then AC_DEFINE(HAVE_SPANED,1,[spaned support]) PHP_GTK_EXTENSION(spaned, $php_gtk_ext_shared) fi Index: php-gtk/ext/spaned/gtkshpaned.c +++ php-gtk/ext/spaned/gtkshpaned.c /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "gtkshpaned.h" static void gtk_shpaned_class_init (GtkSHPanedClass *klass); static void gtk_shpaned_init (GtkSHPaned *shpaned); static void gtk_shpaned_realize (GtkWidget *widget); static void gtk_shpaned_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_shpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static void gtk_shpaned_draw (GtkWidget *widget, GdkRectangle *area); static void gtk_shpaned_xor_line (GtkSPaned *shpaned); static gint gtk_shpaned_button_press (GtkWidget *widget, GdkEventButton *event); static gint gtk_shpaned_button_release (GtkWidget *widget, GdkEventButton *event); static gint gtk_shpaned_motion (GtkWidget *widget, GdkEventMotion *event); GtkType gtk_shpaned_get_type (void) { static GtkType shpaned_type = 0; if (!shpaned_type) { static const GtkTypeInfo shpaned_info = { "GtkSHPaned", sizeof (GtkSHPaned), sizeof (GtkSHPanedClass), (GtkClassInitFunc) gtk_shpaned_class_init, (GtkObjectInitFunc) gtk_shpaned_init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; shpaned_type = gtk_type_unique (gtk_spaned_get_type (), &shpaned_info); } return shpaned_type; } static void gtk_shpaned_class_init (GtkSHPanedClass *class) { GtkWidgetClass *widget_class; widget_class = (GtkWidgetClass*) class; widget_class->size_request = gtk_shpaned_size_request; widget_class->size_allocate = gtk_shpaned_size_allocate; widget_class->draw = gtk_shpaned_draw; widget_class->button_press_event = gtk_shpaned_button_press; widget_class->button_release_event = gtk_shpaned_button_release; widget_class->motion_notify_event = gtk_shpaned_motion; widget_class->realize = gtk_shpaned_realize; } static void gtk_shpaned_init (GtkSHPaned *shpaned) { } GtkWidget* gtk_shpaned_new (void) { GtkSHPaned *shpaned; shpaned = gtk_type_new (gtk_shpaned_get_type ()); return GTK_WIDGET (shpaned); } static void gtk_shpaned_realize (GtkWidget *widget) { GtkSPaned *spaned; GdkWindowAttr attributes; gint attributes_mask; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); spaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (spaned)->border_width; attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.window_type = GDK_WINDOW_CHILD; 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; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (widget->window, spaned); attributes.x = spaned->handle_xpos; attributes.y = spaned->handle_ypos; attributes.width = spaned->handle_width; attributes.height = spaned->handle_height; attributes.cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); attributes_mask |= GDK_WA_CURSOR; spaned->handle = gdk_window_new (widget->window, &attributes, attributes_mask); gdk_window_set_user_data (spaned->handle, spaned); gdk_cursor_destroy (attributes.cursor); widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, spaned->handle, GTK_STATE_NORMAL); gdk_window_set_back_pixmap (widget->window, NULL, TRUE); gdk_window_show (spaned->handle); } static void gtk_shpaned_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkSPaned *shpaned; GtkRequisition child_requisition; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SHPANED (widget)); g_return_if_fail (requisition != NULL); shpaned = GTK_SPANED (widget); requisition->width = 0; requisition->height = 0; if (shpaned->child1 && GTK_WIDGET_VISIBLE (shpaned->child1)) { gtk_widget_size_request (shpaned->child1, &child_requisition); requisition->height = child_requisition.height; requisition->width = child_requisition.width; } if (shpaned->child2 && GTK_WIDGET_VISIBLE (shpaned->child2)) { gtk_widget_size_request (shpaned->child2, &child_requisition); requisition->height = MAX(requisition->height, child_requisition.height); requisition->width += child_requisition.width; } requisition->width += GTK_CONTAINER (shpaned)->border_width * 2 + shpaned->handle_size; requisition->height += GTK_CONTAINER (shpaned)->border_width * 2; } static void gtk_shpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkSPaned *shpaned; GtkRequisition child1_requisition; GtkRequisition child2_requisition; GtkAllocation child1_allocation; GtkAllocation child2_allocation; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SHPANED (widget)); g_return_if_fail (allocation != NULL); widget->allocation = *allocation; shpaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (shpaned)->border_width; if (shpaned->child1) gtk_widget_size_request(shpaned->child1, &child1_requisition); else child1_requisition.width = 0; if (shpaned->child2) gtk_widget_size_request(shpaned->child2, &child2_requisition); else child2_requisition.width = 0; gtk_spaned_compute_position (shpaned, widget->allocation.width - shpaned->handle_size - 2 * border_width, child1_requisition.width, child2_requisition.width); /* Move the handle before the children so we don't get extra expose events */ shpaned->handle_xpos = shpaned->child1_size + border_width; shpaned->handle_ypos = border_width; shpaned->handle_width = shpaned->handle_size; shpaned->handle_height = allocation->height; if (GTK_WIDGET_REALIZED (widget)) { gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height); gdk_window_move_resize (shpaned->handle, shpaned->handle_xpos, shpaned->handle_ypos, shpaned->handle_width, shpaned->handle_height); } child1_allocation.height = child2_allocation.height = MAX (1, (gint)allocation->height - border_width * 2); child1_allocation.width = shpaned->child1_size; child1_allocation.x = border_width; child1_allocation.y = child2_allocation.y = border_width; child2_allocation.x = child1_allocation.x + child1_allocation.width + shpaned->handle_size; child2_allocation.width = MAX (1, (gint)allocation->width - child2_allocation.x - border_width); /* Now allocate the childen, making sure, when resizing not to * overlap the windows */ if (GTK_WIDGET_MAPPED(widget) && shpaned->child1 && GTK_WIDGET_VISIBLE (shpaned->child1) && shpaned->child1->allocation.width < child1_allocation.width) { if (shpaned->child2 && GTK_WIDGET_VISIBLE (shpaned->child2)) gtk_widget_size_allocate (shpaned->child2, &child2_allocation); gtk_widget_size_allocate (shpaned->child1, &child1_allocation); } else { if (shpaned->child1 && GTK_WIDGET_VISIBLE (shpaned->child1)) gtk_widget_size_allocate (shpaned->child1, &child1_allocation); if (shpaned->child2 && GTK_WIDGET_VISIBLE (shpaned->child2)) gtk_widget_size_allocate (shpaned->child2, &child2_allocation); } } static void gtk_shpaned_draw (GtkWidget *widget, GdkRectangle *area) { GtkSPaned *shpaned; GdkRectangle handle_area, child_area; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SHPANED (widget)); if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) { gint width, height; shpaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (shpaned)->border_width; gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height); if (shpaned->child1 && gtk_widget_intersect (shpaned->child1, area, &child_area)) gtk_widget_draw (shpaned->child1, &child_area); if (shpaned->child2 && gtk_widget_intersect (shpaned->child2, area, &child_area)) gtk_widget_draw (shpaned->child2, &child_area); } } static void gtk_shpaned_xor_line (GtkSPaned *shpaned) { GtkWidget *widget; GdkGCValues values; guint16 xpos; widget = GTK_WIDGET(shpaned); if (!shpaned->xor_gc) { values.function = GDK_INVERT; values.subwindow_mode = GDK_INCLUDE_INFERIORS; shpaned->xor_gc = gdk_gc_new_with_values (widget->window, &values, GDK_GC_FUNCTION | GDK_GC_SUBWINDOW); } xpos = shpaned->child1_size + GTK_CONTAINER (shpaned)->border_width + shpaned->handle_size / 2; gdk_draw_line (widget->window, shpaned->xor_gc, xpos, 0, xpos, widget->allocation.height - 1); } static gint gtk_shpaned_button_press (GtkWidget *widget, GdkEventButton *event) { GtkSPaned *shpaned; g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (GTK_IS_SHPANED (widget),FALSE); shpaned = GTK_SPANED (widget); if (!shpaned->in_drag && (event->window == shpaned->handle) && (event->button == 1)) { shpaned->in_drag = TRUE; /* We need a server grab here, not gtk_grab_add(), since * we don't want to pass events on to the widget's children */ gdk_pointer_grab (shpaned->handle, FALSE, GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time); shpaned->child1_size += event->x - shpaned->handle_size / 2; shpaned->child1_size = CLAMP (shpaned->child1_size, 0, widget->allocation.width - shpaned->handle_size - 2 * GTK_CONTAINER (shpaned)->border_width); gtk_shpaned_xor_line (shpaned); } return TRUE; } static gint gtk_shpaned_button_release (GtkWidget *widget, GdkEventButton *event) { GtkSPaned *shpaned; g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (GTK_IS_SHPANED (widget),FALSE); shpaned = GTK_SPANED (widget); if (shpaned->in_drag && (event->button == 1)) { gtk_shpaned_xor_line (shpaned); shpaned->in_drag = FALSE; shpaned->position_set = TRUE; gdk_pointer_ungrab (event->time); gtk_widget_queue_resize (GTK_WIDGET (shpaned)); } return TRUE; } static gint gtk_shpaned_motion (GtkWidget *widget, GdkEventMotion *event) { GtkSPaned *shpaned; gint x; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_SHPANED (widget), FALSE); shpaned = GTK_SPANED (widget); if (event->is_hint || event->window != widget->window) gtk_widget_get_pointer(widget, &x, NULL); else x = event->x; if (shpaned->in_drag) { gint size = x - GTK_CONTAINER (shpaned)->border_width - shpaned->handle_size/2; gtk_shpaned_xor_line (shpaned); shpaned->child1_size = CLAMP (size, shpaned->min_position, shpaned->max_position); gtk_shpaned_xor_line (shpaned); } return TRUE; } Index: php-gtk/ext/spaned/gtkshpaned.h +++ php-gtk/ext/spaned/gtkshpaned.h /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #ifndef __GTK_SHPANED_H__ #define __GTK_SHPANED_H__ #include <gdk/gdk.h> #include "gtkspaned.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #define GTK_SHPANED(obj) GTK_CHECK_CAST (obj, gtk_shpaned_get_type (), GtkSHPaned) #define GTK_SHPANED_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_shpaned_get_type (), GtkSHPanedClass) #define GTK_IS_SHPANED(obj) GTK_CHECK_TYPE (obj, gtk_shpaned_get_type ()) typedef struct _GtkSHPaned GtkSHPaned; typedef struct _GtkSHPanedClass GtkSHPanedClass; struct _GtkSHPaned { GtkSPaned spaned; }; struct _GtkSHPanedClass { GtkSPanedClass parent_class; }; GtkType gtk_shpaned_get_type (void); GtkWidget* gtk_shpaned_new (void); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __GTK_SHPANED_H__ */ Index: php-gtk/ext/spaned/gtkspaned.c +++ php-gtk/ext/spaned/gtkspaned.c /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "gtkspaned.h" enum { ARG_0, ARG_HANDLE_SIZE, ARG_FIXED, }; static void gtk_spaned_class_init (GtkSPanedClass *klass); static void gtk_spaned_init (GtkSPaned *spaned); static void gtk_spaned_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); static void gtk_spaned_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); static void gtk_spaned_map (GtkWidget *widget); static void gtk_spaned_unmap (GtkWidget *widget); static void gtk_spaned_unrealize (GtkWidget *widget); static gint gtk_spaned_expose (GtkWidget *widget, GdkEventExpose *event); static void gtk_spaned_add (GtkContainer *container, GtkWidget *widget); static void gtk_spaned_remove (GtkContainer *container, GtkWidget *widget); static void gtk_spaned_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); static GtkType gtk_spaned_child_type (GtkContainer *container); static GtkContainerClass *parent_class = NULL; GtkType gtk_spaned_get_type (void) { static GtkType spaned_type = 0; if (!spaned_type) { static const GtkTypeInfo spaned_info = { "GtkSPaned", sizeof (GtkSPaned), sizeof (GtkSPanedClass), (GtkClassInitFunc) gtk_spaned_class_init, (GtkObjectInitFunc) gtk_spaned_init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; spaned_type = gtk_type_unique (GTK_TYPE_CONTAINER, &spaned_info); } return spaned_type; } static void gtk_spaned_class_init (GtkSPanedClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkContainerClass *container_class; object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; container_class = (GtkContainerClass*) class; parent_class = gtk_type_class (GTK_TYPE_CONTAINER); object_class->set_arg = gtk_spaned_set_arg; object_class->get_arg = gtk_spaned_get_arg; widget_class->map = gtk_spaned_map; widget_class->unmap = gtk_spaned_unmap; widget_class->unrealize = gtk_spaned_unrealize; widget_class->expose_event = gtk_spaned_expose; container_class->add = gtk_spaned_add; container_class->remove = gtk_spaned_remove; container_class->forall = gtk_spaned_forall; container_class->child_type = gtk_spaned_child_type; gtk_object_add_arg_type ("GtkSPaned::handle_size", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_HANDLE_SIZE); gtk_object_add_arg_type ("GtkSPaned::fixed", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_FIXED); } static GtkType gtk_spaned_child_type (GtkContainer *container) { if (!GTK_SPANED (container)->child1 || !GTK_SPANED (container)->child2) return GTK_TYPE_WIDGET; else return GTK_TYPE_NONE; } static void gtk_spaned_init (GtkSPaned *spaned) { GTK_WIDGET_UNSET_FLAGS (spaned, GTK_NO_WINDOW); spaned->child1 = NULL; spaned->child2 = NULL; spaned->handle = NULL; spaned->xor_gc = NULL; spaned->handle_size = 6; spaned->fixed = TRUE; spaned->position_set = FALSE; spaned->last_allocation = -1; spaned->in_drag = FALSE; spaned->handle_xpos = -1; spaned->handle_ypos = -1; spaned->handle_width = 6; spaned->handle_height = 6; } static void gtk_spaned_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) { GtkSPaned *spaned = GTK_SPANED (object); switch (arg_id) { case ARG_HANDLE_SIZE: gtk_spaned_set_handle_size (spaned, GTK_VALUE_UINT (*arg)); break; case ARG_FIXED: gtk_spaned_set_fixed (spaned, GTK_VALUE_BOOL (*arg)); break; } } static void gtk_spaned_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) { GtkSPaned *spaned = GTK_SPANED (object); switch (arg_id) { case ARG_HANDLE_SIZE: GTK_VALUE_UINT (*arg) = spaned->handle_size; break; case ARG_FIXED: GTK_VALUE_BOOL (*arg) = spaned->fixed; break; default: arg->type = GTK_TYPE_INVALID; break; } } static void gtk_spaned_map (GtkWidget *widget) { GtkSPaned *spaned; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); spaned = GTK_SPANED (widget); if (spaned->child1 && GTK_WIDGET_VISIBLE (spaned->child1) && !GTK_WIDGET_MAPPED (spaned->child1)) gtk_widget_map (spaned->child1); if (spaned->child2 && GTK_WIDGET_VISIBLE (spaned->child2) && !GTK_WIDGET_MAPPED (spaned->child2)) gtk_widget_map (spaned->child2); gdk_window_show (widget->window); } static void gtk_spaned_unmap (GtkWidget *widget) { g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); gdk_window_hide (widget->window); } static void gtk_spaned_unrealize (GtkWidget *widget) { GtkSPaned *spaned; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); spaned = GTK_SPANED (widget); if (spaned->xor_gc) { gdk_gc_destroy (spaned->xor_gc); spaned->xor_gc = NULL; } if (spaned->handle) { gdk_window_set_user_data (spaned->handle, NULL); gdk_window_destroy (spaned->handle); spaned->handle = NULL; } if (GTK_WIDGET_CLASS (parent_class)->unrealize) (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); } static gint gtk_spaned_expose (GtkWidget *widget, GdkEventExpose *event) { GtkSPaned *spaned; GdkEventExpose child_event; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_SPANED (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (GTK_WIDGET_DRAWABLE (widget)) { spaned = GTK_SPANED (widget); /* An expose event for the handle */ if (event->window == spaned->handle) { /*gtk_paint_box (widget->style, spaned->handle, GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT, &event->area, widget, "spaned", 0, 0, spaned->handle_size, spaned->handle_size);*/ } else { child_event = *event; if (spaned->child1 && GTK_WIDGET_NO_WINDOW (spaned->child1) && gtk_widget_intersect (spaned->child1, &event->area, &child_event.area)) gtk_widget_event (spaned->child1, (GdkEvent*) &child_event); if (spaned->child2 && GTK_WIDGET_NO_WINDOW (spaned->child2) && gtk_widget_intersect (spaned->child2, &event->area, &child_event.area)) gtk_widget_event (spaned->child2, (GdkEvent*) &child_event); /* redraw the groove if necessary */ /*if (gdk_rectangle_intersect (&spaned->groove_rectangle, &event->area, &child_event.area)) gtk_widget_draw (widget, &child_event.area);*/ } } return FALSE; } void gtk_spaned_add1 (GtkSPaned *spaned, GtkWidget *widget) { gtk_spaned_pack1 (spaned, widget, TRUE, TRUE);//FALSE, TRUE); } void gtk_spaned_add2 (GtkSPaned *spaned, GtkWidget *widget) { gtk_spaned_pack2 (spaned, widget, TRUE, TRUE); } void gtk_spaned_pack1 (GtkSPaned *spaned, GtkWidget *child, gboolean resize, gboolean shrink) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); g_return_if_fail (GTK_IS_WIDGET (child)); if (!spaned->child1) { spaned->child1 = child; gtk_widget_set_parent (child, GTK_WIDGET (spaned)); if (GTK_WIDGET_REALIZED (child->parent)) gtk_widget_realize (child); if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) { if (GTK_WIDGET_MAPPED (child->parent)) gtk_widget_map (child); gtk_widget_queue_resize (child); } } } void gtk_spaned_pack2 (GtkSPaned *spaned, GtkWidget *child, gboolean resize, gboolean shrink) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); g_return_if_fail (GTK_IS_WIDGET (child)); if (!spaned->child2) { spaned->child2 = child; gtk_widget_set_parent (child, GTK_WIDGET (spaned)); if (GTK_WIDGET_REALIZED (child->parent)) gtk_widget_realize (child); if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) { if (GTK_WIDGET_MAPPED (child->parent)) gtk_widget_map (child); gtk_widget_queue_resize (child); } } } static void gtk_spaned_add (GtkContainer *container, GtkWidget *widget) { GtkSPaned *spaned; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_SPANED (container)); g_return_if_fail (widget != NULL); spaned = GTK_SPANED (container); if (!spaned->child1) gtk_spaned_add1 (GTK_SPANED (container),widget); else if (!spaned->child2) gtk_spaned_add2 (GTK_SPANED (container),widget); } static void gtk_spaned_remove (GtkContainer *container, GtkWidget *widget) { GtkSPaned *spaned; gboolean was_visible; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_SPANED (container)); g_return_if_fail (widget != NULL); spaned = GTK_SPANED (container); was_visible = GTK_WIDGET_VISIBLE (widget); if (spaned->child1 == widget) { gtk_widget_unparent (widget); spaned->child1 = NULL; if (was_visible && GTK_WIDGET_VISIBLE (container)) gtk_widget_queue_resize (GTK_WIDGET (container)); } else if (spaned->child2 == widget) { gtk_widget_unparent (widget); spaned->child2 = NULL; if (was_visible && GTK_WIDGET_VISIBLE (container)) gtk_widget_queue_resize (GTK_WIDGET (container)); } } static void gtk_spaned_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data) { GtkSPaned *spaned; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_SPANED (container)); g_return_if_fail (callback != NULL); spaned = GTK_SPANED (container); if (spaned->child1) (* callback) (spaned->child1, callback_data); if (spaned->child2) (* callback) (spaned->child2, callback_data); } void gtk_spaned_set_position (GtkSPaned *spaned, gint position) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); if (position >= 0) { /* We don't clamp here - the assumption is that * if the total allocation changes at the same time * as the position, the position set is with reference * to the new total size. If only the position changes, * then clamping will occur in gtk_spaned_compute_position() */ spaned->child1_size = position; spaned->position_set = TRUE; } else spaned->position_set = FALSE; gtk_widget_queue_resize (GTK_WIDGET (spaned)); } void gtk_spaned_set_handle_size (GtkSPaned *spaned, guint16 size) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); spaned->handle_size = size; if (GTK_WIDGET_VISIBLE (GTK_WIDGET (spaned))) gtk_widget_queue_resize (GTK_WIDGET (spaned)); } void gtk_spaned_set_fixed (GtkSPaned *spaned, gboolean fixed) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); spaned->fixed = fixed; } void gtk_spaned_compute_position (GtkSPaned *spaned, gint allocation, gint child1_req, gint child2_req) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); spaned->min_position = 0; spaned->max_position = allocation; if (!spaned->position_set) { spaned->child1_size = child1_req;//allocation /2; spaned->position_set = TRUE; } else { if (spaned->last_allocation>0) { if(spaned->fixed) spaned->child1_size = spaned->child1_size;//* ((gdouble)child1_req / (child1_req + child2_req)); else spaned->child1_size = spaned->child1_size * allocation / spaned->last_allocation;//* ((gdouble)child1_req / (child1_req + child2_req)); } } spaned->child1_size = CLAMP (spaned->child1_size, spaned->min_position, spaned->max_position); spaned->last_allocation = allocation; } Index: php-gtk/ext/spaned/gtkspaned.h +++ php-gtk/ext/spaned/gtkspaned.h /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #ifndef __GTK_SPANED_H__ #define __GTK_SPANED_H__ #include <gdk/gdk.h> #include <gtk/gtkcontainer.h> #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #define GTK_TYPE_SPANED (gtk_spaned_get_type ()) #define GTK_SPANED(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_SPANED, GtkSPaned)) #define GTK_SPANED_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_SPANED, GtkSPanedClass)) #define GTK_IS_SPANED(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_SPANED)) #define GTK_IS_SPANED_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SPANED)) typedef struct _GtkSPaned GtkSPaned; typedef struct _GtkSPanedClass GtkSPanedClass; struct _GtkSPaned { GtkContainer container; GtkWidget *child1; GtkWidget *child2; GdkWindow *handle; GdkGC *xor_gc; /*< public >*/ guint16 handle_size; gboolean fixed; /*< private >*/ gint child1_size; gint last_allocation; gint min_position; gint max_position; guint position_set : 1; guint in_drag : 1; gint16 handle_xpos; gint16 handle_ypos; gint16 handle_width; gint16 handle_height; }; struct _GtkSPanedClass { GtkContainerClass parent_class; }; GtkType gtk_spaned_get_type (void); void gtk_spaned_add1 (GtkSPaned *shpaned, GtkWidget *child); void gtk_spaned_add2 (GtkSPaned *shpaned, GtkWidget *child); void gtk_spaned_pack1 (GtkSPaned *shpaned, GtkWidget *child, gboolean resize, gboolean shrink); void gtk_spaned_pack2 (GtkSPaned *shpaned, GtkWidget *child, gboolean resize, gboolean shrink); void gtk_spaned_set_position (GtkSPaned *shpaned, gint position); void gtk_spaned_set_handle_size (GtkSPaned *shpaned, guint16 size); void gtk_spaned_set_fixed (GtkSPaned *shpaned, gboolean fixed); /* Internal function */ void gtk_spaned_compute_position (GtkSPaned *shpaned, gint allocation, gint child1_req, gint child2_req); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __GTK_SPANED_H__ */ Index: php-gtk/ext/spaned/gtksvpaned.c +++ php-gtk/ext/spaned/gtksvpaned.c /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "gtksvpaned.h" static void gtk_svpaned_class_init (GtkSVPanedClass *klass); static void gtk_svpaned_init (GtkSVPaned *svpaned); static void gtk_svpaned_realize (GtkWidget *widget); static void gtk_svpaned_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_svpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static void gtk_svpaned_draw (GtkWidget *widget, GdkRectangle *area); static void gtk_svpaned_xor_line (GtkSPaned *svpaned); static gint gtk_svpaned_button_press (GtkWidget *widget, GdkEventButton *event); static gint gtk_svpaned_button_release (GtkWidget *widget, GdkEventButton *event); static gint gtk_svpaned_motion (GtkWidget *widget, GdkEventMotion *event); GtkType gtk_svpaned_get_type (void) { static GtkType svpaned_type = 0; if (!svpaned_type) { static const GtkTypeInfo svpaned_info = { "GtkSVPaned", sizeof (GtkSVPaned), sizeof (GtkSVPanedClass), (GtkClassInitFunc) gtk_svpaned_class_init, (GtkObjectInitFunc) gtk_svpaned_init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; svpaned_type = gtk_type_unique (gtk_spaned_get_type (), &svpaned_info); } return svpaned_type; } static void gtk_svpaned_class_init (GtkSVPanedClass *class) { GtkWidgetClass *widget_class; widget_class = (GtkWidgetClass*) class; widget_class->size_request = gtk_svpaned_size_request; widget_class->size_allocate = gtk_svpaned_size_allocate; widget_class->draw = gtk_svpaned_draw; widget_class->button_press_event = gtk_svpaned_button_press; widget_class->button_release_event = gtk_svpaned_button_release; widget_class->motion_notify_event = gtk_svpaned_motion; widget_class->realize = gtk_svpaned_realize; } static void gtk_svpaned_init (GtkSVPaned *svpaned) { } GtkWidget* gtk_svpaned_new (void) { GtkSVPaned *svpaned; svpaned = gtk_type_new (gtk_svpaned_get_type ()); return GTK_WIDGET (svpaned); } static void gtk_svpaned_realize (GtkWidget *widget) { GtkSPaned *spaned; GdkWindowAttr attributes; gint attributes_mask; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); spaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (spaned)->border_width; attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.window_type = GDK_WINDOW_CHILD; 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; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (widget->window, spaned); attributes.x = spaned->handle_xpos; attributes.y = spaned->handle_ypos; attributes.width = spaned->handle_width; attributes.height = spaned->handle_height; attributes.cursor = gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW); attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); attributes_mask |= GDK_WA_CURSOR; spaned->handle = gdk_window_new (widget->window, &attributes, attributes_mask); gdk_window_set_user_data (spaned->handle, spaned); gdk_cursor_destroy (attributes.cursor); widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, spaned->handle, GTK_STATE_NORMAL); gdk_window_set_back_pixmap (widget->window, NULL, TRUE); gdk_window_show (spaned->handle); } static void gtk_svpaned_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkSPaned *svpaned; GtkRequisition child_requisition; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SVPANED (widget)); g_return_if_fail (requisition != NULL); svpaned = GTK_SPANED (widget); requisition->width = 0; requisition->height = 0; if (svpaned->child1 && GTK_WIDGET_VISIBLE (svpaned->child1)) { gtk_widget_size_request (svpaned->child1, &child_requisition); requisition->height = child_requisition.height; requisition->width = child_requisition.width; } if (svpaned->child2 && GTK_WIDGET_VISIBLE (svpaned->child2)) { gtk_widget_size_request (svpaned->child2, &child_requisition); requisition->height += child_requisition.height; requisition->width = MAX(requisition->width, child_requisition.width); } requisition->width += GTK_CONTAINER (svpaned)->border_width * 2; requisition->height += GTK_CONTAINER (svpaned)->border_width * 2 + svpaned->handle_size; } static void gtk_svpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkSPaned *svpaned; GtkRequisition child1_requisition; GtkRequisition child2_requisition; GtkAllocation child1_allocation; GtkAllocation child2_allocation; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SVPANED (widget)); g_return_if_fail (allocation != NULL); widget->allocation = *allocation; svpaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (svpaned)->border_width; if (svpaned->child1) gtk_widget_size_request(svpaned->child1, &child1_requisition); else child1_requisition.height = 0; if (svpaned->child2) gtk_widget_size_request(svpaned->child1, &child1_requisition); else child2_requisition.height = 0; gtk_spaned_compute_position (svpaned, widget->allocation.height - svpaned->handle_size - 2 * border_width, child1_requisition.height, child2_requisition.height); /* Move the handle before the children so we don't get extra expose events */ svpaned->handle_xpos = border_width; svpaned->handle_ypos = svpaned->child1_size + border_width; svpaned->handle_width = allocation->width; svpaned->handle_height = svpaned->handle_size; if (GTK_WIDGET_REALIZED (widget)) { gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height); gdk_window_move_resize (svpaned->handle, svpaned->handle_xpos, svpaned->handle_ypos, svpaned->handle_width, svpaned->handle_height); } child1_allocation.width = child2_allocation.width = MAX (1, (gint)allocation->width - border_width * 2); child1_allocation.height = svpaned->child1_size; child1_allocation.x = child2_allocation.x = border_width; child1_allocation.y = border_width; child2_allocation.y = child1_allocation.y + child1_allocation.height + svpaned->handle_size; child2_allocation.height = MAX (1, (gint)allocation->height - child2_allocation.y - border_width); /* Now allocate the childen, making sure, when resizing not to * overlap the windows */ if (GTK_WIDGET_MAPPED(widget) && svpaned->child1 && GTK_WIDGET_VISIBLE (svpaned->child1) && svpaned->child1->allocation.height < child1_allocation.height) { if (svpaned->child2 && GTK_WIDGET_VISIBLE (svpaned->child2)) gtk_widget_size_allocate (svpaned->child2, &child2_allocation); gtk_widget_size_allocate (svpaned->child1, &child1_allocation); } else { if (svpaned->child1 && GTK_WIDGET_VISIBLE (svpaned->child1)) gtk_widget_size_allocate (svpaned->child1, &child1_allocation); if (svpaned->child2 && GTK_WIDGET_VISIBLE (svpaned->child2)) gtk_widget_size_allocate (svpaned->child2, &child2_allocation); } } static void gtk_svpaned_draw (GtkWidget *widget, GdkRectangle *area) { GtkSPaned *svpaned; GdkRectangle handle_area, child_area; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SVPANED (widget)); if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) { gint width, height; svpaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (svpaned)->border_width; gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height); if (svpaned->child1 && gtk_widget_intersect (svpaned->child1, area, &child_area)) gtk_widget_draw (svpaned->child1, &child_area); if (svpaned->child2 && gtk_widget_intersect (svpaned->child2, area, &child_area)) gtk_widget_draw (svpaned->child2, &child_area); } } static void gtk_svpaned_xor_line (GtkSPaned *svpaned) { GtkWidget *widget; GdkGCValues values; guint16 ypos; widget = GTK_WIDGET(svpaned); if (!svpaned->xor_gc) { values.function = GDK_INVERT; values.subwindow_mode = GDK_INCLUDE_INFERIORS; svpaned->xor_gc = gdk_gc_new_with_values (widget->window, &values, GDK_GC_FUNCTION | GDK_GC_SUBWINDOW); } ypos = svpaned->child1_size + GTK_CONTAINER (svpaned)->border_width + svpaned->handle_size / 2; gdk_draw_line (widget->window, svpaned->xor_gc, 0, ypos, widget->allocation.width - 1, ypos); } static gint gtk_svpaned_button_press (GtkWidget *widget, GdkEventButton *event) { GtkSPaned *svpaned; g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (GTK_IS_SVPANED (widget),FALSE); svpaned = GTK_SPANED (widget); if (!svpaned->in_drag && (event->window == svpaned->handle) && (event->button == 1)) { svpaned->in_drag = TRUE; /* We need a server grab here, not gtk_grab_add(), since * we don't want to pass events on to the widget's children */ gdk_pointer_grab (svpaned->handle, FALSE, GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time); svpaned->child1_size += event->y - svpaned->handle_size / 2; svpaned->child1_size = CLAMP (svpaned->child1_size, 0, widget->allocation.height - svpaned->handle_size - 2 * GTK_CONTAINER (svpaned)->border_width); gtk_svpaned_xor_line (svpaned); } return TRUE; } static gint gtk_svpaned_button_release (GtkWidget *widget, GdkEventButton *event) { GtkSPaned *svpaned; g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (GTK_IS_SVPANED (widget),FALSE); svpaned = GTK_SPANED (widget); if (svpaned->in_drag && (event->button == 1)) { gtk_svpaned_xor_line (svpaned); svpaned->in_drag = FALSE; svpaned->position_set = TRUE; gdk_pointer_ungrab (event->time); gtk_widget_queue_resize (GTK_WIDGET (svpaned)); } return TRUE; } static gint gtk_svpaned_motion (GtkWidget *widget, GdkEventMotion *event) { GtkSPaned *svpaned; gint y; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_SVPANED (widget), FALSE); svpaned = GTK_SPANED (widget); if (event->is_hint || event->window != widget->window) gtk_widget_get_pointer(widget, NULL, &y); else y = event->y; if (svpaned->in_drag) { gint size = y - GTK_CONTAINER (svpaned)->border_width - svpaned->handle_size/2; gtk_svpaned_xor_line (svpaned); svpaned->child1_size = CLAMP (size, svpaned->min_position, svpaned->max_position); gtk_svpaned_xor_line (svpaned); } return TRUE; } Index: php-gtk/ext/spaned/gtksvpaned.h +++ php-gtk/ext/spaned/gtksvpaned.h /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #ifndef __GTK_SVPANED_H__ #define __GTK_SVPANED_H__ #include <gdk/gdk.h> #include "gtkspaned.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #define GTK_SVPANED(obj) GTK_CHECK_CAST (obj, gtk_svpaned_get_type (), GtkSVPaned) #define GTK_SVPANED_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_svpaned_get_type (), GtkSVPanedClass) #define GTK_IS_SVPANED(obj) GTK_CHECK_TYPE (obj, gtk_svpaned_get_type ()) typedef struct _GtkSVPaned GtkSVPaned; typedef struct _GtkSVPanedClass GtkSVPanedClass; struct _GtkSVPaned { GtkSPaned spaned; }; struct _GtkSVPanedClass { GtkSPanedClass parent_class; }; GtkType gtk_svpaned_get_type (void); GtkWidget* gtk_svpaned_new (void); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __GTK_SVPANED_H__ */ Index: php-gtk/ext/spaned/php_spaned.c +++ php-gtk/ext/spaned/php_spaned.c /* * PHP-GTK - The PHP language bindings for GTK+ * * Copyright (C) 2001 Andrei Zmievski <andrei@php.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 */ /* $Id: php_spaned.c,v 1.1 2001/12/07 00:07:15 mfischer Exp $ */ #include "php_spaned.h" #if HAVE_SPANED #ifdef PHP_GTK_COMPILE_DL_SPANED PHP_GTK_GET_EXTENSION(spaned) #endif PHP_GTK_XINIT_FUNCTION(spaned) { php_spaned_register_constants(module_number TSRMLS_CC); php_spaned_register_classes(); return SUCCESS; } php_gtk_ext_entry spaned_ext_entry = { "spaned", PHP_GTK_XINIT(spaned), NULL, }; #endif /* HAVE_SPANED */ Index: php-gtk/ext/spaned/php_spaned.h +++ php-gtk/ext/spaned/php_spaned.h /* * PHP-GTK - The PHP language bindings for GTK+ * * Copyright (C) 2001 Andrei Zmievski <andrei@php.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 */ /* $Id: php_spaned.h,v 1.1 2001/12/07 00:07:15 mfischer Exp $ */ #ifndef PHP_SPANED_H #define PHP_SPANED_H #include "php_gtk.h" #if HAVE_SPANED extern php_gtk_ext_entry spaned_ext_entry; #define spaned_ext_ptr &spaned_ext_entry void php_spaned_register_constants(int module_number TSRMLS_DC); void php_spaned_register_classes(); #else #define spaned_ext_ptr NULL #endif /* HAVE_SPANED */ #define php_gtk_ext_spaned_ptr spaned_ext_ptr #endif /* PHP_SPANED_H */ Index: php-gtk/ext/spaned/spaned.defs +++ php-gtk/ext/spaned/spaned.defs ;; -*- scheme -*- ; object definitions ... (object SPaned (in-module Gtk) (parent Container (Gtk)) (c-name GtkSPaned) ) (object SHPaned (in-module Gtk) (parent SPaned (Gtk)) (c-name GtkSHPaned) ) (object SVPaned (in-module Gtk) (parent SPaned (Gtk)) (c-name GtkSVPaned) ) ;; Enumerations and flags ... ;; From gtkspaned.h (function gtk_spaned_get_type (c-name gtk_spaned_get_type) (return-type GtkType) ) (method add1 (of-object SPaned (Gtk)) (c-name gtk_spaned_add1) (return-type none) (parameter (type-and-name GtkWidget* child)) ) (method add2 (of-object SPaned (Gtk)) (c-name gtk_spaned_add2) (return-type none) (parameter (type-and-name GtkWidget* child)) ) (method pack1 (of-object SPaned (Gtk)) (c-name gtk_spaned_pack1) (return-type none) (parameter (type-and-name GtkWidget* child)) (parameter (type-and-name gboolean resize) (default "TRUE")) (parameter (type-and-name gboolean shrink) (default "TRUE")) ) (method pack2 (of-object SPaned (Gtk)) (c-name gtk_spaned_pack2) (return-type none) (parameter (type-and-name GtkWidget* child)) (parameter (type-and-name gboolean resize) (default "TRUE")) (parameter (type-and-name gboolean shrink) (default "TRUE")) ) (method set_position (of-object SPaned (Gtk)) (c-name gtk_spaned_set_position) (return-type none) (parameter (type-and-name gint position)) ) (method set_handle_size (of-object SPaned (Gtk)) (c-name gtk_spaned_set_handle_size) (return-type none) (parameter (type-and-name guint16 size)) ) (method set_fixed (of-object SPaned (Gtk)) (c-name gtk_spaned_set_fixed) (return-type none) (parameter (type-and-name gboolean fixed)) ) (method compute_position (of-object SPaned (Gtk)) (c-name gtk_spaned_compute_position) (return-type none) (parameter (type-and-name gint allocation)) (parameter (type-and-name gint child1_req)) (parameter (type-and-name gint child2_req)) ) ;; From gtkshpaned.h (function gtk_shpaned_get_type (c-name gtk_shpaned_get_type) (return-type GtkType) ) (function gtk_shpaned_new (c-name gtk_shpaned_new) (is-constructor-of GtkSHPaned) (return-type GtkWidget*) ) ;; From gtksvpaned.h (function gtk_svpaned_get_type (c-name gtk_svpaned_get_type) (return-type GtkType) ) (function gtk_svpaned_new (c-name gtk_svpaned_new) (is-constructor-of GtkSVPaned) (return-type GtkWidget*) ) Index: php-gtk/ext/spaned/spaned.overrides +++ php-gtk/ext/spaned/spaned.overrides /* vim: set ft=cpp: */ %% headers #include "gtkspaned.h" #include "gtkshpaned.h" #include "gtksvpaned.h" #include "ext/gtk+/php_gtk+.h" %% constants %% ignore-glob *_get_type Index: php-gtk/test/spaned.php +++ php-gtk/test/spaned.php <?php if (!extension_loaded('gtk')) dl( 'php_gtk.' . (strstr( PHP_OS, 'WIN') ? 'dll' : 'so')); $w = &new GtkWindow; $w->set_title('Comparing GtkPaned and GtkSPaned'); $w->set_border_width(10); $w->set_usize(600,300); $w->connect('destroy', create_function('','Gtk::main_quit();')); $hbox = &new GtkHBox; $w->add($hbox); $frameleft = &new GtkFrame('GtkHPaned'); $hbox->pack_start($frameleft); $frameright = &new GtkFrame('GtkSHPaned'); $hbox->pack_start($frameright); $vpaned = &new GtkVPaned; $frameleft->add($vpaned); $tleft = &new GtkText; $tleft->insert_text('They behave the same', 0); $vpaned->pack1($tleft); $vpaned->pack2(new GtkText()); $svpaned = &new GtkSVPaned; $frameright->add($svpaned); $tright = &new GtkText; $tright->insert_text('But the handle is much easier to grab', 0); $svpaned->pack1($tright); $svpaned->pack2(new GtkText()); $w->show_all(); Gtk::main(); ?>
Index: php-gtk/ext/spaned/.cvsignore +++ php-gtk/ext/spaned/.cvsignore deps Makefile *.lo *.slo *.la libs libs.mk gen_* *.cache Index: php-gtk/ext/spaned/Makefile.in +++ php-gtk/ext/spaned/Makefile.in LTLIBRARY_NAME = libspaned.la LTLIBRARY_SOURCES = php_spaned.c gen_spaned.c gtkspaned.c gtkshpaned.c gtksvpaned.c LTLIBRARY_LIBADD = $(SPANED_SHARED_LIBADD) LTLIBRARY_SHARED_NAME = php_gtk_spaned.la LTLIBRARY_SHARED_LIBADD = $(SPANED_SHARED_LIBADD) include $(top_srcdir)/build/dynlib.mk php_spaned.o php_spaned.lo php_spaned.slo: gen_ce_spaned.h gen_spaned.c: spaned.defs spaned.overrides $(PHP) -q $(top_srcdir)/generator/generator.php -o $(srcdir)/spaned.overrides -p SPaned -r $(top_srcdir)/ext/gtk%2b/gtk.defs $(srcdir)/spaned.defs > gen_spaned.c gen_ce_spaned.h: gen_spaned.c grep -h "^PHP_GTK_EXPORT_CE" gen_spaned.c | sed -e "s!^!extern !" > gen_ce_spaned.h Index: php-gtk/ext/spaned/config.m4 +++ php-gtk/ext/spaned/config.m4 dnl $Id: config.m4,v 1.1 2001/12/07 00:07:15 mfischer Exp $ dnl config.m4 for spaned module PHP_GTK_ARG_ENABLE(spaned,for GtkSPaned support, [ --disable-spaned Disable GtkSPaned support], yes) if test "$PHP_GTK_SPANED" != "no"; then AC_DEFINE(HAVE_SPANED,1,[spaned support]) PHP_GTK_EXTENSION(spaned, $php_gtk_ext_shared) fi Index: php-gtk/ext/spaned/gtkshpaned.c +++ php-gtk/ext/spaned/gtkshpaned.c /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "gtkshpaned.h" static void gtk_shpaned_class_init (GtkSHPanedClass *klass); static void gtk_shpaned_init (GtkSHPaned *shpaned); static void gtk_shpaned_realize (GtkWidget *widget); static void gtk_shpaned_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_shpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static void gtk_shpaned_draw (GtkWidget *widget, GdkRectangle *area); static void gtk_shpaned_xor_line (GtkSPaned *shpaned); static gint gtk_shpaned_button_press (GtkWidget *widget, GdkEventButton *event); static gint gtk_shpaned_button_release (GtkWidget *widget, GdkEventButton *event); static gint gtk_shpaned_motion (GtkWidget *widget, GdkEventMotion *event); GtkType gtk_shpaned_get_type (void) { static GtkType shpaned_type = 0; if (!shpaned_type) { static const GtkTypeInfo shpaned_info = { "GtkSHPaned", sizeof (GtkSHPaned), sizeof (GtkSHPanedClass), (GtkClassInitFunc) gtk_shpaned_class_init, (GtkObjectInitFunc) gtk_shpaned_init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; shpaned_type = gtk_type_unique (gtk_spaned_get_type (), &shpaned_info); } return shpaned_type; } static void gtk_shpaned_class_init (GtkSHPanedClass *class) { GtkWidgetClass *widget_class; widget_class = (GtkWidgetClass*) class; widget_class->size_request = gtk_shpaned_size_request; widget_class->size_allocate = gtk_shpaned_size_allocate; widget_class->draw = gtk_shpaned_draw; widget_class->button_press_event = gtk_shpaned_button_press; widget_class->button_release_event = gtk_shpaned_button_release; widget_class->motion_notify_event = gtk_shpaned_motion; widget_class->realize = gtk_shpaned_realize; } static void gtk_shpaned_init (GtkSHPaned *shpaned) { } GtkWidget* gtk_shpaned_new (void) { GtkSHPaned *shpaned; shpaned = gtk_type_new (gtk_shpaned_get_type ()); return GTK_WIDGET (shpaned); } static void gtk_shpaned_realize (GtkWidget *widget) { GtkSPaned *spaned; GdkWindowAttr attributes; gint attributes_mask; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); spaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (spaned)->border_width; attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.window_type = GDK_WINDOW_CHILD; 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; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (widget->window, spaned); attributes.x = spaned->handle_xpos; attributes.y = spaned->handle_ypos; attributes.width = spaned->handle_width; attributes.height = spaned->handle_height; attributes.cursor = gdk_cursor_new (GDK_SB_H_DOUBLE_ARROW); attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); attributes_mask |= GDK_WA_CURSOR; spaned->handle = gdk_window_new (widget->window, &attributes, attributes_mask); gdk_window_set_user_data (spaned->handle, spaned); gdk_cursor_destroy (attributes.cursor); widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, spaned->handle, GTK_STATE_NORMAL); gdk_window_set_back_pixmap (widget->window, NULL, TRUE); gdk_window_show (spaned->handle); } static void gtk_shpaned_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkSPaned *shpaned; GtkRequisition child_requisition; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SHPANED (widget)); g_return_if_fail (requisition != NULL); shpaned = GTK_SPANED (widget); requisition->width = 0; requisition->height = 0; if (shpaned->child1 && GTK_WIDGET_VISIBLE (shpaned->child1)) { gtk_widget_size_request (shpaned->child1, &child_requisition); requisition->height = child_requisition.height; requisition->width = child_requisition.width; } if (shpaned->child2 && GTK_WIDGET_VISIBLE (shpaned->child2)) { gtk_widget_size_request (shpaned->child2, &child_requisition); requisition->height = MAX(requisition->height, child_requisition.height); requisition->width += child_requisition.width; } requisition->width += GTK_CONTAINER (shpaned)->border_width * 2 + shpaned->handle_size; requisition->height += GTK_CONTAINER (shpaned)->border_width * 2; } static void gtk_shpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkSPaned *shpaned; GtkRequisition child1_requisition; GtkRequisition child2_requisition; GtkAllocation child1_allocation; GtkAllocation child2_allocation; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SHPANED (widget)); g_return_if_fail (allocation != NULL); widget->allocation = *allocation; shpaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (shpaned)->border_width; if (shpaned->child1) gtk_widget_size_request(shpaned->child1, &child1_requisition); else child1_requisition.width = 0; if (shpaned->child2) gtk_widget_size_request(shpaned->child2, &child2_requisition); else child2_requisition.width = 0; gtk_spaned_compute_position (shpaned, widget->allocation.width - shpaned->handle_size - 2 * border_width, child1_requisition.width, child2_requisition.width); /* Move the handle before the children so we don't get extra expose events */ shpaned->handle_xpos = shpaned->child1_size + border_width; shpaned->handle_ypos = border_width; shpaned->handle_width = shpaned->handle_size; shpaned->handle_height = allocation->height; if (GTK_WIDGET_REALIZED (widget)) { gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height); gdk_window_move_resize (shpaned->handle, shpaned->handle_xpos, shpaned->handle_ypos, shpaned->handle_width, shpaned->handle_height); } child1_allocation.height = child2_allocation.height = MAX (1, (gint)allocation->height - border_width * 2); child1_allocation.width = shpaned->child1_size; child1_allocation.x = border_width; child1_allocation.y = child2_allocation.y = border_width; child2_allocation.x = child1_allocation.x + child1_allocation.width + shpaned->handle_size; child2_allocation.width = MAX (1, (gint)allocation->width - child2_allocation.x - border_width); /* Now allocate the childen, making sure, when resizing not to * overlap the windows */ if (GTK_WIDGET_MAPPED(widget) && shpaned->child1 && GTK_WIDGET_VISIBLE (shpaned->child1) && shpaned->child1->allocation.width < child1_allocation.width) { if (shpaned->child2 && GTK_WIDGET_VISIBLE (shpaned->child2)) gtk_widget_size_allocate (shpaned->child2, &child2_allocation); gtk_widget_size_allocate (shpaned->child1, &child1_allocation); } else { if (shpaned->child1 && GTK_WIDGET_VISIBLE (shpaned->child1)) gtk_widget_size_allocate (shpaned->child1, &child1_allocation); if (shpaned->child2 && GTK_WIDGET_VISIBLE (shpaned->child2)) gtk_widget_size_allocate (shpaned->child2, &child2_allocation); } } static void gtk_shpaned_draw (GtkWidget *widget, GdkRectangle *area) { GtkSPaned *shpaned; GdkRectangle handle_area, child_area; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SHPANED (widget)); if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) { gint width, height; shpaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (shpaned)->border_width; gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height); if (shpaned->child1 && gtk_widget_intersect (shpaned->child1, area, &child_area)) gtk_widget_draw (shpaned->child1, &child_area); if (shpaned->child2 && gtk_widget_intersect (shpaned->child2, area, &child_area)) gtk_widget_draw (shpaned->child2, &child_area); } } static void gtk_shpaned_xor_line (GtkSPaned *shpaned) { GtkWidget *widget; GdkGCValues values; guint16 xpos; widget = GTK_WIDGET(shpaned); if (!shpaned->xor_gc) { values.function = GDK_INVERT; values.subwindow_mode = GDK_INCLUDE_INFERIORS; shpaned->xor_gc = gdk_gc_new_with_values (widget->window, &values, GDK_GC_FUNCTION | GDK_GC_SUBWINDOW); } xpos = shpaned->child1_size + GTK_CONTAINER (shpaned)->border_width + shpaned->handle_size / 2; gdk_draw_line (widget->window, shpaned->xor_gc, xpos, 0, xpos, widget->allocation.height - 1); } static gint gtk_shpaned_button_press (GtkWidget *widget, GdkEventButton *event) { GtkSPaned *shpaned; g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (GTK_IS_SHPANED (widget),FALSE); shpaned = GTK_SPANED (widget); if (!shpaned->in_drag && (event->window == shpaned->handle) && (event->button == 1)) { shpaned->in_drag = TRUE; /* We need a server grab here, not gtk_grab_add(), since * we don't want to pass events on to the widget's children */ gdk_pointer_grab (shpaned->handle, FALSE, GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time); shpaned->child1_size += event->x - shpaned->handle_size / 2; shpaned->child1_size = CLAMP (shpaned->child1_size, 0, widget->allocation.width - shpaned->handle_size - 2 * GTK_CONTAINER (shpaned)->border_width); gtk_shpaned_xor_line (shpaned); } return TRUE; } static gint gtk_shpaned_button_release (GtkWidget *widget, GdkEventButton *event) { GtkSPaned *shpaned; g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (GTK_IS_SHPANED (widget),FALSE); shpaned = GTK_SPANED (widget); if (shpaned->in_drag && (event->button == 1)) { gtk_shpaned_xor_line (shpaned); shpaned->in_drag = FALSE; shpaned->position_set = TRUE; gdk_pointer_ungrab (event->time); gtk_widget_queue_resize (GTK_WIDGET (shpaned)); } return TRUE; } static gint gtk_shpaned_motion (GtkWidget *widget, GdkEventMotion *event) { GtkSPaned *shpaned; gint x; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_SHPANED (widget), FALSE); shpaned = GTK_SPANED (widget); if (event->is_hint || event->window != widget->window) gtk_widget_get_pointer(widget, &x, NULL); else x = event->x; if (shpaned->in_drag) { gint size = x - GTK_CONTAINER (shpaned)->border_width - shpaned->handle_size/2; gtk_shpaned_xor_line (shpaned); shpaned->child1_size = CLAMP (size, shpaned->min_position, shpaned->max_position); gtk_shpaned_xor_line (shpaned); } return TRUE; } Index: php-gtk/ext/spaned/gtkshpaned.h +++ php-gtk/ext/spaned/gtkshpaned.h /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #ifndef __GTK_SHPANED_H__ #define __GTK_SHPANED_H__ #include <gdk/gdk.h> #include "gtkspaned.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #define GTK_SHPANED(obj) GTK_CHECK_CAST (obj, gtk_shpaned_get_type (), GtkSHPaned) #define GTK_SHPANED_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_shpaned_get_type (), GtkSHPanedClass) #define GTK_IS_SHPANED(obj) GTK_CHECK_TYPE (obj, gtk_shpaned_get_type ()) typedef struct _GtkSHPaned GtkSHPaned; typedef struct _GtkSHPanedClass GtkSHPanedClass; struct _GtkSHPaned { GtkSPaned spaned; }; struct _GtkSHPanedClass { GtkSPanedClass parent_class; }; GtkType gtk_shpaned_get_type (void); GtkWidget* gtk_shpaned_new (void); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __GTK_SHPANED_H__ */ Index: php-gtk/ext/spaned/gtkspaned.c +++ php-gtk/ext/spaned/gtkspaned.c /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "gtkspaned.h" enum { ARG_0, ARG_HANDLE_SIZE, ARG_FIXED, }; static void gtk_spaned_class_init (GtkSPanedClass *klass); static void gtk_spaned_init (GtkSPaned *spaned); static void gtk_spaned_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); static void gtk_spaned_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); static void gtk_spaned_map (GtkWidget *widget); static void gtk_spaned_unmap (GtkWidget *widget); static void gtk_spaned_unrealize (GtkWidget *widget); static gint gtk_spaned_expose (GtkWidget *widget, GdkEventExpose *event); static void gtk_spaned_add (GtkContainer *container, GtkWidget *widget); static void gtk_spaned_remove (GtkContainer *container, GtkWidget *widget); static void gtk_spaned_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data); static GtkType gtk_spaned_child_type (GtkContainer *container); static GtkContainerClass *parent_class = NULL; GtkType gtk_spaned_get_type (void) { static GtkType spaned_type = 0; if (!spaned_type) { static const GtkTypeInfo spaned_info = { "GtkSPaned", sizeof (GtkSPaned), sizeof (GtkSPanedClass), (GtkClassInitFunc) gtk_spaned_class_init, (GtkObjectInitFunc) gtk_spaned_init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; spaned_type = gtk_type_unique (GTK_TYPE_CONTAINER, &spaned_info); } return spaned_type; } static void gtk_spaned_class_init (GtkSPanedClass *class) { GtkObjectClass *object_class; GtkWidgetClass *widget_class; GtkContainerClass *container_class; object_class = (GtkObjectClass*) class; widget_class = (GtkWidgetClass*) class; container_class = (GtkContainerClass*) class; parent_class = gtk_type_class (GTK_TYPE_CONTAINER); object_class->set_arg = gtk_spaned_set_arg; object_class->get_arg = gtk_spaned_get_arg; widget_class->map = gtk_spaned_map; widget_class->unmap = gtk_spaned_unmap; widget_class->unrealize = gtk_spaned_unrealize; widget_class->expose_event = gtk_spaned_expose; container_class->add = gtk_spaned_add; container_class->remove = gtk_spaned_remove; container_class->forall = gtk_spaned_forall; container_class->child_type = gtk_spaned_child_type; gtk_object_add_arg_type ("GtkSPaned::handle_size", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_HANDLE_SIZE); gtk_object_add_arg_type ("GtkSPaned::fixed", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_FIXED); } static GtkType gtk_spaned_child_type (GtkContainer *container) { if (!GTK_SPANED (container)->child1 || !GTK_SPANED (container)->child2) return GTK_TYPE_WIDGET; else return GTK_TYPE_NONE; } static void gtk_spaned_init (GtkSPaned *spaned) { GTK_WIDGET_UNSET_FLAGS (spaned, GTK_NO_WINDOW); spaned->child1 = NULL; spaned->child2 = NULL; spaned->handle = NULL; spaned->xor_gc = NULL; spaned->handle_size = 6; spaned->fixed = TRUE; spaned->position_set = FALSE; spaned->last_allocation = -1; spaned->in_drag = FALSE; spaned->handle_xpos = -1; spaned->handle_ypos = -1; spaned->handle_width = 6; spaned->handle_height = 6; } static void gtk_spaned_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) { GtkSPaned *spaned = GTK_SPANED (object); switch (arg_id) { case ARG_HANDLE_SIZE: gtk_spaned_set_handle_size (spaned, GTK_VALUE_UINT (*arg)); break; case ARG_FIXED: gtk_spaned_set_fixed (spaned, GTK_VALUE_BOOL (*arg)); break; } } static void gtk_spaned_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) { GtkSPaned *spaned = GTK_SPANED (object); switch (arg_id) { case ARG_HANDLE_SIZE: GTK_VALUE_UINT (*arg) = spaned->handle_size; break; case ARG_FIXED: GTK_VALUE_BOOL (*arg) = spaned->fixed; break; default: arg->type = GTK_TYPE_INVALID; break; } } static void gtk_spaned_map (GtkWidget *widget) { GtkSPaned *spaned; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); spaned = GTK_SPANED (widget); if (spaned->child1 && GTK_WIDGET_VISIBLE (spaned->child1) && !GTK_WIDGET_MAPPED (spaned->child1)) gtk_widget_map (spaned->child1); if (spaned->child2 && GTK_WIDGET_VISIBLE (spaned->child2) && !GTK_WIDGET_MAPPED (spaned->child2)) gtk_widget_map (spaned->child2); gdk_window_show (widget->window); } static void gtk_spaned_unmap (GtkWidget *widget) { g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); gdk_window_hide (widget->window); } static void gtk_spaned_unrealize (GtkWidget *widget) { GtkSPaned *spaned; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); spaned = GTK_SPANED (widget); if (spaned->xor_gc) { gdk_gc_destroy (spaned->xor_gc); spaned->xor_gc = NULL; } if (spaned->handle) { gdk_window_set_user_data (spaned->handle, NULL); gdk_window_destroy (spaned->handle); spaned->handle = NULL; } if (GTK_WIDGET_CLASS (parent_class)->unrealize) (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); } static gint gtk_spaned_expose (GtkWidget *widget, GdkEventExpose *event) { GtkSPaned *spaned; GdkEventExpose child_event; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_SPANED (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); if (GTK_WIDGET_DRAWABLE (widget)) { spaned = GTK_SPANED (widget); /* An expose event for the handle */ if (event->window == spaned->handle) { /*gtk_paint_box (widget->style, spaned->handle, GTK_WIDGET_STATE(widget), GTK_SHADOW_OUT, &event->area, widget, "spaned", 0, 0, spaned->handle_size, spaned->handle_size);*/ } else { child_event = *event; if (spaned->child1 && GTK_WIDGET_NO_WINDOW (spaned->child1) && gtk_widget_intersect (spaned->child1, &event->area, &child_event.area)) gtk_widget_event (spaned->child1, (GdkEvent*) &child_event); if (spaned->child2 && GTK_WIDGET_NO_WINDOW (spaned->child2) && gtk_widget_intersect (spaned->child2, &event->area, &child_event.area)) gtk_widget_event (spaned->child2, (GdkEvent*) &child_event); /* redraw the groove if necessary */ /*if (gdk_rectangle_intersect (&spaned->groove_rectangle, &event->area, &child_event.area)) gtk_widget_draw (widget, &child_event.area);*/ } } return FALSE; } void gtk_spaned_add1 (GtkSPaned *spaned, GtkWidget *widget) { gtk_spaned_pack1 (spaned, widget, TRUE, TRUE);//FALSE, TRUE); } void gtk_spaned_add2 (GtkSPaned *spaned, GtkWidget *widget) { gtk_spaned_pack2 (spaned, widget, TRUE, TRUE); } void gtk_spaned_pack1 (GtkSPaned *spaned, GtkWidget *child, gboolean resize, gboolean shrink) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); g_return_if_fail (GTK_IS_WIDGET (child)); if (!spaned->child1) { spaned->child1 = child; gtk_widget_set_parent (child, GTK_WIDGET (spaned)); if (GTK_WIDGET_REALIZED (child->parent)) gtk_widget_realize (child); if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) { if (GTK_WIDGET_MAPPED (child->parent)) gtk_widget_map (child); gtk_widget_queue_resize (child); } } } void gtk_spaned_pack2 (GtkSPaned *spaned, GtkWidget *child, gboolean resize, gboolean shrink) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); g_return_if_fail (GTK_IS_WIDGET (child)); if (!spaned->child2) { spaned->child2 = child; gtk_widget_set_parent (child, GTK_WIDGET (spaned)); if (GTK_WIDGET_REALIZED (child->parent)) gtk_widget_realize (child); if (GTK_WIDGET_VISIBLE (child->parent) && GTK_WIDGET_VISIBLE (child)) { if (GTK_WIDGET_MAPPED (child->parent)) gtk_widget_map (child); gtk_widget_queue_resize (child); } } } static void gtk_spaned_add (GtkContainer *container, GtkWidget *widget) { GtkSPaned *spaned; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_SPANED (container)); g_return_if_fail (widget != NULL); spaned = GTK_SPANED (container); if (!spaned->child1) gtk_spaned_add1 (GTK_SPANED (container),widget); else if (!spaned->child2) gtk_spaned_add2 (GTK_SPANED (container),widget); } static void gtk_spaned_remove (GtkContainer *container, GtkWidget *widget) { GtkSPaned *spaned; gboolean was_visible; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_SPANED (container)); g_return_if_fail (widget != NULL); spaned = GTK_SPANED (container); was_visible = GTK_WIDGET_VISIBLE (widget); if (spaned->child1 == widget) { gtk_widget_unparent (widget); spaned->child1 = NULL; if (was_visible && GTK_WIDGET_VISIBLE (container)) gtk_widget_queue_resize (GTK_WIDGET (container)); } else if (spaned->child2 == widget) { gtk_widget_unparent (widget); spaned->child2 = NULL; if (was_visible && GTK_WIDGET_VISIBLE (container)) gtk_widget_queue_resize (GTK_WIDGET (container)); } } static void gtk_spaned_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data) { GtkSPaned *spaned; g_return_if_fail (container != NULL); g_return_if_fail (GTK_IS_SPANED (container)); g_return_if_fail (callback != NULL); spaned = GTK_SPANED (container); if (spaned->child1) (* callback) (spaned->child1, callback_data); if (spaned->child2) (* callback) (spaned->child2, callback_data); } void gtk_spaned_set_position (GtkSPaned *spaned, gint position) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); if (position >= 0) { /* We don't clamp here - the assumption is that * if the total allocation changes at the same time * as the position, the position set is with reference * to the new total size. If only the position changes, * then clamping will occur in gtk_spaned_compute_position() */ spaned->child1_size = position; spaned->position_set = TRUE; } else spaned->position_set = FALSE; gtk_widget_queue_resize (GTK_WIDGET (spaned)); } void gtk_spaned_set_handle_size (GtkSPaned *spaned, guint16 size) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); spaned->handle_size = size; if (GTK_WIDGET_VISIBLE (GTK_WIDGET (spaned))) gtk_widget_queue_resize (GTK_WIDGET (spaned)); } void gtk_spaned_set_fixed (GtkSPaned *spaned, gboolean fixed) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); spaned->fixed = fixed; } void gtk_spaned_compute_position (GtkSPaned *spaned, gint allocation, gint child1_req, gint child2_req) { g_return_if_fail (spaned != NULL); g_return_if_fail (GTK_IS_SPANED (spaned)); spaned->min_position = 0; spaned->max_position = allocation; if (!spaned->position_set) { spaned->child1_size = child1_req;//allocation /2; spaned->position_set = TRUE; } else { if (spaned->last_allocation>0) { if(spaned->fixed) spaned->child1_size = spaned->child1_size;//* ((gdouble)child1_req / (child1_req + child2_req)); else spaned->child1_size = spaned->child1_size * allocation / spaned->last_allocation;//* ((gdouble)child1_req / (child1_req + child2_req)); } } spaned->child1_size = CLAMP (spaned->child1_size, spaned->min_position, spaned->max_position); spaned->last_allocation = allocation; } Index: php-gtk/ext/spaned/gtkspaned.h +++ php-gtk/ext/spaned/gtkspaned.h /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #ifndef __GTK_SPANED_H__ #define __GTK_SPANED_H__ #include <gdk/gdk.h> #include <gtk/gtkcontainer.h> #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #define GTK_TYPE_SPANED (gtk_spaned_get_type ()) #define GTK_SPANED(obj) (GTK_CHECK_CAST ((obj), GTK_TYPE_SPANED, GtkSPaned)) #define GTK_SPANED_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_SPANED, GtkSPanedClass)) #define GTK_IS_SPANED(obj) (GTK_CHECK_TYPE ((obj), GTK_TYPE_SPANED)) #define GTK_IS_SPANED_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_SPANED)) typedef struct _GtkSPaned GtkSPaned; typedef struct _GtkSPanedClass GtkSPanedClass; struct _GtkSPaned { GtkContainer container; GtkWidget *child1; GtkWidget *child2; GdkWindow *handle; GdkGC *xor_gc; /*< public >*/ guint16 handle_size; gboolean fixed; /*< private >*/ gint child1_size; gint last_allocation; gint min_position; gint max_position; guint position_set : 1; guint in_drag : 1; gint16 handle_xpos; gint16 handle_ypos; gint16 handle_width; gint16 handle_height; }; struct _GtkSPanedClass { GtkContainerClass parent_class; }; GtkType gtk_spaned_get_type (void); void gtk_spaned_add1 (GtkSPaned *shpaned, GtkWidget *child); void gtk_spaned_add2 (GtkSPaned *shpaned, GtkWidget *child); void gtk_spaned_pack1 (GtkSPaned *shpaned, GtkWidget *child, gboolean resize, gboolean shrink); void gtk_spaned_pack2 (GtkSPaned *shpaned, GtkWidget *child, gboolean resize, gboolean shrink); void gtk_spaned_set_position (GtkSPaned *shpaned, gint position); void gtk_spaned_set_handle_size (GtkSPaned *shpaned, guint16 size); void gtk_spaned_set_fixed (GtkSPaned *shpaned, gboolean fixed); /* Internal function */ void gtk_spaned_compute_position (GtkSPaned *shpaned, gint allocation, gint child1_req, gint child2_req); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __GTK_SPANED_H__ */ Index: php-gtk/ext/spaned/gtksvpaned.c +++ php-gtk/ext/spaned/gtksvpaned.c /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #include "gtksvpaned.h" static void gtk_svpaned_class_init (GtkSVPanedClass *klass); static void gtk_svpaned_init (GtkSVPaned *svpaned); static void gtk_svpaned_realize (GtkWidget *widget); static void gtk_svpaned_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_svpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation); static void gtk_svpaned_draw (GtkWidget *widget, GdkRectangle *area); static void gtk_svpaned_xor_line (GtkSPaned *svpaned); static gint gtk_svpaned_button_press (GtkWidget *widget, GdkEventButton *event); static gint gtk_svpaned_button_release (GtkWidget *widget, GdkEventButton *event); static gint gtk_svpaned_motion (GtkWidget *widget, GdkEventMotion *event); GtkType gtk_svpaned_get_type (void) { static GtkType svpaned_type = 0; if (!svpaned_type) { static const GtkTypeInfo svpaned_info = { "GtkSVPaned", sizeof (GtkSVPaned), sizeof (GtkSVPanedClass), (GtkClassInitFunc) gtk_svpaned_class_init, (GtkObjectInitFunc) gtk_svpaned_init, /* reserved_1 */ NULL, /* reserved_2 */ NULL, (GtkClassInitFunc) NULL, }; svpaned_type = gtk_type_unique (gtk_spaned_get_type (), &svpaned_info); } return svpaned_type; } static void gtk_svpaned_class_init (GtkSVPanedClass *class) { GtkWidgetClass *widget_class; widget_class = (GtkWidgetClass*) class; widget_class->size_request = gtk_svpaned_size_request; widget_class->size_allocate = gtk_svpaned_size_allocate; widget_class->draw = gtk_svpaned_draw; widget_class->button_press_event = gtk_svpaned_button_press; widget_class->button_release_event = gtk_svpaned_button_release; widget_class->motion_notify_event = gtk_svpaned_motion; widget_class->realize = gtk_svpaned_realize; } static void gtk_svpaned_init (GtkSVPaned *svpaned) { } GtkWidget* gtk_svpaned_new (void) { GtkSVPaned *svpaned; svpaned = gtk_type_new (gtk_svpaned_get_type ()); return GTK_WIDGET (svpaned); } static void gtk_svpaned_realize (GtkWidget *widget) { GtkSPaned *spaned; GdkWindowAttr attributes; gint attributes_mask; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SPANED (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); spaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (spaned)->border_width; attributes.x = widget->allocation.x; attributes.y = widget->allocation.y; attributes.width = widget->allocation.width; attributes.height = widget->allocation.height; attributes.window_type = GDK_WINDOW_CHILD; 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; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); gdk_window_set_user_data (widget->window, spaned); attributes.x = spaned->handle_xpos; attributes.y = spaned->handle_ypos; attributes.width = spaned->handle_width; attributes.height = spaned->handle_height; attributes.cursor = gdk_cursor_new (GDK_SB_V_DOUBLE_ARROW); attributes.event_mask |= (GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); attributes_mask |= GDK_WA_CURSOR; spaned->handle = gdk_window_new (widget->window, &attributes, attributes_mask); gdk_window_set_user_data (spaned->handle, spaned); gdk_cursor_destroy (attributes.cursor); widget->style = gtk_style_attach (widget->style, widget->window); gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL); gtk_style_set_background (widget->style, spaned->handle, GTK_STATE_NORMAL); gdk_window_set_back_pixmap (widget->window, NULL, TRUE); gdk_window_show (spaned->handle); } static void gtk_svpaned_size_request (GtkWidget *widget, GtkRequisition *requisition) { GtkSPaned *svpaned; GtkRequisition child_requisition; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SVPANED (widget)); g_return_if_fail (requisition != NULL); svpaned = GTK_SPANED (widget); requisition->width = 0; requisition->height = 0; if (svpaned->child1 && GTK_WIDGET_VISIBLE (svpaned->child1)) { gtk_widget_size_request (svpaned->child1, &child_requisition); requisition->height = child_requisition.height; requisition->width = child_requisition.width; } if (svpaned->child2 && GTK_WIDGET_VISIBLE (svpaned->child2)) { gtk_widget_size_request (svpaned->child2, &child_requisition); requisition->height += child_requisition.height; requisition->width = MAX(requisition->width, child_requisition.width); } requisition->width += GTK_CONTAINER (svpaned)->border_width * 2; requisition->height += GTK_CONTAINER (svpaned)->border_width * 2 + svpaned->handle_size; } static void gtk_svpaned_size_allocate (GtkWidget *widget, GtkAllocation *allocation) { GtkSPaned *svpaned; GtkRequisition child1_requisition; GtkRequisition child2_requisition; GtkAllocation child1_allocation; GtkAllocation child2_allocation; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SVPANED (widget)); g_return_if_fail (allocation != NULL); widget->allocation = *allocation; svpaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (svpaned)->border_width; if (svpaned->child1) gtk_widget_size_request(svpaned->child1, &child1_requisition); else child1_requisition.height = 0; if (svpaned->child2) gtk_widget_size_request(svpaned->child1, &child1_requisition); else child2_requisition.height = 0; gtk_spaned_compute_position (svpaned, widget->allocation.height - svpaned->handle_size - 2 * border_width, child1_requisition.height, child2_requisition.height); /* Move the handle before the children so we don't get extra expose events */ svpaned->handle_xpos = border_width; svpaned->handle_ypos = svpaned->child1_size + border_width; svpaned->handle_width = allocation->width; svpaned->handle_height = svpaned->handle_size; if (GTK_WIDGET_REALIZED (widget)) { gdk_window_move_resize (widget->window, allocation->x, allocation->y, allocation->width, allocation->height); gdk_window_move_resize (svpaned->handle, svpaned->handle_xpos, svpaned->handle_ypos, svpaned->handle_width, svpaned->handle_height); } child1_allocation.width = child2_allocation.width = MAX (1, (gint)allocation->width - border_width * 2); child1_allocation.height = svpaned->child1_size; child1_allocation.x = child2_allocation.x = border_width; child1_allocation.y = border_width; child2_allocation.y = child1_allocation.y + child1_allocation.height + svpaned->handle_size; child2_allocation.height = MAX (1, (gint)allocation->height - child2_allocation.y - border_width); /* Now allocate the childen, making sure, when resizing not to * overlap the windows */ if (GTK_WIDGET_MAPPED(widget) && svpaned->child1 && GTK_WIDGET_VISIBLE (svpaned->child1) && svpaned->child1->allocation.height < child1_allocation.height) { if (svpaned->child2 && GTK_WIDGET_VISIBLE (svpaned->child2)) gtk_widget_size_allocate (svpaned->child2, &child2_allocation); gtk_widget_size_allocate (svpaned->child1, &child1_allocation); } else { if (svpaned->child1 && GTK_WIDGET_VISIBLE (svpaned->child1)) gtk_widget_size_allocate (svpaned->child1, &child1_allocation); if (svpaned->child2 && GTK_WIDGET_VISIBLE (svpaned->child2)) gtk_widget_size_allocate (svpaned->child2, &child2_allocation); } } static void gtk_svpaned_draw (GtkWidget *widget, GdkRectangle *area) { GtkSPaned *svpaned; GdkRectangle handle_area, child_area; guint16 border_width; g_return_if_fail (widget != NULL); g_return_if_fail (GTK_IS_SVPANED (widget)); if (GTK_WIDGET_VISIBLE (widget) && GTK_WIDGET_MAPPED (widget)) { gint width, height; svpaned = GTK_SPANED (widget); border_width = GTK_CONTAINER (svpaned)->border_width; gdk_window_clear_area (widget->window, area->x, area->y, area->width, area->height); if (svpaned->child1 && gtk_widget_intersect (svpaned->child1, area, &child_area)) gtk_widget_draw (svpaned->child1, &child_area); if (svpaned->child2 && gtk_widget_intersect (svpaned->child2, area, &child_area)) gtk_widget_draw (svpaned->child2, &child_area); } } static void gtk_svpaned_xor_line (GtkSPaned *svpaned) { GtkWidget *widget; GdkGCValues values; guint16 ypos; widget = GTK_WIDGET(svpaned); if (!svpaned->xor_gc) { values.function = GDK_INVERT; values.subwindow_mode = GDK_INCLUDE_INFERIORS; svpaned->xor_gc = gdk_gc_new_with_values (widget->window, &values, GDK_GC_FUNCTION | GDK_GC_SUBWINDOW); } ypos = svpaned->child1_size + GTK_CONTAINER (svpaned)->border_width + svpaned->handle_size / 2; gdk_draw_line (widget->window, svpaned->xor_gc, 0, ypos, widget->allocation.width - 1, ypos); } static gint gtk_svpaned_button_press (GtkWidget *widget, GdkEventButton *event) { GtkSPaned *svpaned; g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (GTK_IS_SVPANED (widget),FALSE); svpaned = GTK_SPANED (widget); if (!svpaned->in_drag && (event->window == svpaned->handle) && (event->button == 1)) { svpaned->in_drag = TRUE; /* We need a server grab here, not gtk_grab_add(), since * we don't want to pass events on to the widget's children */ gdk_pointer_grab (svpaned->handle, FALSE, GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK | GDK_BUTTON_RELEASE_MASK, NULL, NULL, event->time); svpaned->child1_size += event->y - svpaned->handle_size / 2; svpaned->child1_size = CLAMP (svpaned->child1_size, 0, widget->allocation.height - svpaned->handle_size - 2 * GTK_CONTAINER (svpaned)->border_width); gtk_svpaned_xor_line (svpaned); } return TRUE; } static gint gtk_svpaned_button_release (GtkWidget *widget, GdkEventButton *event) { GtkSPaned *svpaned; g_return_val_if_fail (widget != NULL,FALSE); g_return_val_if_fail (GTK_IS_SVPANED (widget),FALSE); svpaned = GTK_SPANED (widget); if (svpaned->in_drag && (event->button == 1)) { gtk_svpaned_xor_line (svpaned); svpaned->in_drag = FALSE; svpaned->position_set = TRUE; gdk_pointer_ungrab (event->time); gtk_widget_queue_resize (GTK_WIDGET (svpaned)); } return TRUE; } static gint gtk_svpaned_motion (GtkWidget *widget, GdkEventMotion *event) { GtkSPaned *svpaned; gint y; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_SVPANED (widget), FALSE); svpaned = GTK_SPANED (widget); if (event->is_hint || event->window != widget->window) gtk_widget_get_pointer(widget, NULL, &y); else y = event->y; if (svpaned->in_drag) { gint size = y - GTK_CONTAINER (svpaned)->border_width - svpaned->handle_size/2; gtk_svpaned_xor_line (svpaned); svpaned->child1_size = CLAMP (size, svpaned->min_position, svpaned->max_position); gtk_svpaned_xor_line (svpaned); } return TRUE; } Index: php-gtk/ext/spaned/gtksvpaned.h +++ php-gtk/ext/spaned/gtksvpaned.h /* GTK - The GIMP Toolkit * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald * * 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. */ /* * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS * file for a list of people on the GTK+ Team. See the ChangeLog * files for a list of changes. These files are distributed with * GTK+ at ftp://ftp.gtk.org/pub/gtk/. */ #ifndef __GTK_SVPANED_H__ #define __GTK_SVPANED_H__ #include <gdk/gdk.h> #include "gtkspaned.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #define GTK_SVPANED(obj) GTK_CHECK_CAST (obj, gtk_svpaned_get_type (), GtkSVPaned) #define GTK_SVPANED_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gtk_svpaned_get_type (), GtkSVPanedClass) #define GTK_IS_SVPANED(obj) GTK_CHECK_TYPE (obj, gtk_svpaned_get_type ()) typedef struct _GtkSVPaned GtkSVPaned; typedef struct _GtkSVPanedClass GtkSVPanedClass; struct _GtkSVPaned { GtkSPaned spaned; }; struct _GtkSVPanedClass { GtkSPanedClass parent_class; }; GtkType gtk_svpaned_get_type (void); GtkWidget* gtk_svpaned_new (void); #ifdef __cplusplus } #endif /* __cplusplus */ #endif /* __GTK_SVPANED_H__ */ Index: php-gtk/ext/spaned/php_spaned.c +++ php-gtk/ext/spaned/php_spaned.c /* * PHP-GTK - The PHP language bindings for GTK+ * * Copyright (C) 2001 Andrei Zmievski <andrei@php.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 */ /* $Id: php_spaned.c,v 1.1 2001/12/07 00:07:15 mfischer Exp $ */ #include "php_spaned.h" #if HAVE_SPANED #ifdef PHP_GTK_COMPILE_DL_SPANED PHP_GTK_GET_EXTENSION(spaned) #endif PHP_GTK_XINIT_FUNCTION(spaned) { php_spaned_register_constants(module_number TSRMLS_CC); php_spaned_register_classes(); return SUCCESS; } php_gtk_ext_entry spaned_ext_entry = { "spaned", PHP_GTK_XINIT(spaned), NULL, }; #endif /* HAVE_SPANED */ Index: php-gtk/ext/spaned/php_spaned.h +++ php-gtk/ext/spaned/php_spaned.h /* * PHP-GTK - The PHP language bindings for GTK+ * * Copyright (C) 2001 Andrei Zmievski <andrei@php.net> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser 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 */ /* $Id: php_spaned.h,v 1.1 2001/12/07 00:07:15 mfischer Exp $ */ #ifndef PHP_SPANED_H #define PHP_SPANED_H #include "php_gtk.h" #if HAVE_SPANED extern php_gtk_ext_entry spaned_ext_entry; #define spaned_ext_ptr &spaned_ext_entry void php_spaned_register_constants(int module_number TSRMLS_DC); void php_spaned_register_classes(); #else #define spaned_ext_ptr NULL #endif /* HAVE_SPANED */ #define php_gtk_ext_spaned_ptr spaned_ext_ptr #endif /* PHP_SPANED_H */ Index: php-gtk/ext/spaned/spaned.defs +++ php-gtk/ext/spaned/spaned.defs ;; -*- scheme -*- ; object definitions ... (object SPaned (in-module Gtk) (parent Container (Gtk)) (c-name GtkSPaned) ) (object SHPaned (in-module Gtk) (parent SPaned (Gtk)) (c-name GtkSHPaned) ) (object SVPaned (in-module Gtk) (parent SPaned (Gtk)) (c-name GtkSVPaned) ) ;; Enumerations and flags ... ;; From gtkspaned.h (function gtk_spaned_get_type (c-name gtk_spaned_get_type) (return-type GtkType) ) (method add1 (of-object SPaned (Gtk)) (c-name gtk_spaned_add1) (return-type none) (parameter (type-and-name GtkWidget* child)) ) (method add2 (of-object SPaned (Gtk)) (c-name gtk_spaned_add2) (return-type none) (parameter (type-and-name GtkWidget* child)) ) (method pack1 (of-object SPaned (Gtk)) (c-name gtk_spaned_pack1) (return-type none) (parameter (type-and-name GtkWidget* child)) (parameter (type-and-name gboolean resize) (default "TRUE")) (parameter (type-and-name gboolean shrink) (default "TRUE")) ) (method pack2 (of-object SPaned (Gtk)) (c-name gtk_spaned_pack2) (return-type none) (parameter (type-and-name GtkWidget* child)) (parameter (type-and-name gboolean resize) (default "TRUE")) (parameter (type-and-name gboolean shrink) (default "TRUE")) ) (method set_position (of-object SPaned (Gtk)) (c-name gtk_spaned_set_position) (return-type none) (parameter (type-and-name gint position)) ) (method set_handle_size (of-object SPaned (Gtk)) (c-name gtk_spaned_set_handle_size) (return-type none) (parameter (type-and-name guint16 size)) ) (method set_fixed (of-object SPaned (Gtk)) (c-name gtk_spaned_set_fixed) (return-type none) (parameter (type-and-name gboolean fixed)) ) (method compute_position (of-object SPaned (Gtk)) (c-name gtk_spaned_compute_position) (return-type none) (parameter (type-and-name gint allocation)) (parameter (type-and-name gint child1_req)) (parameter (type-and-name gint child2_req)) ) ;; From gtkshpaned.h (function gtk_shpaned_get_type (c-name gtk_shpaned_get_type) (return-type GtkType) ) (function gtk_shpaned_new (c-name gtk_shpaned_new) (is-constructor-of GtkSHPaned) (return-type GtkWidget*) ) ;; From gtksvpaned.h (function gtk_svpaned_get_type (c-name gtk_svpaned_get_type) (return-type GtkType) ) (function gtk_svpaned_new (c-name gtk_svpaned_new) (is-constructor-of GtkSVPaned) (return-type GtkWidget*) ) Index: php-gtk/ext/spaned/spaned.overrides +++ php-gtk/ext/spaned/spaned.overrides /* vim: set ft=cpp: */ %% headers #include "gtkspaned.h" #include "gtkshpaned.h" #include "gtksvpaned.h" #include "ext/gtk+/php_gtk+.h" %% constants %% ignore-glob *_get_type Index: php-gtk/test/spaned.php +++ php-gtk/test/spaned.php <?php if (!extension_loaded('gtk')) dl( 'php_gtk.' . (strstr( PHP_OS, 'WIN') ? 'dll' : 'so')); $w = &new GtkWindow; $w->set_title('Comparing GtkPaned and GtkSPaned'); $w->set_border_width(10); $w->set_usize(600,300); $w->connect('destroy', create_function('','Gtk::main_quit();')); $hbox = &new GtkHBox; $w->add($hbox); $frameleft = &new GtkFrame('GtkHPaned'); $hbox->pack_start($frameleft); $frameright = &new GtkFrame('GtkSHPaned'); $hbox->pack_start($frameright); $vpaned = &new GtkVPaned; $frameleft->add($vpaned); $tleft = &new GtkText; $tleft->insert_text('They behave the same', 0); $vpaned->pack1($tleft); $vpaned->pack2(new GtkText()); $svpaned = &new GtkSVPaned; $frameright->add($svpaned); $tright = &new GtkText; $tright->insert_text('But the handle is much easier to grab', 0); $svpaned->pack1($tright); $svpaned->pack2(new GtkText()); $w->show_all(); Gtk::main(); ?>