diff options
author | Elliot Lee <sopwith@src.gnome.org> | 1997-12-19 19:17:45 +0000 |
---|---|---|
committer | Elliot Lee <sopwith@src.gnome.org> | 1997-12-19 19:17:45 +0000 |
commit | 61124945c03460d8f0fc891c65f0c41dc1436e78 (patch) | |
tree | 0759761593157c274af81398f8e4409f1c29a476 | |
parent | e9f322e2f020e977c1fe6b0fb93807d978da16a2 (diff) | |
download | gtk+-61124945c03460d8f0fc891c65f0c41dc1436e78.tar.gz |
more gtkhandlebox work..
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | glib/glibconfig.h.in | 1 | ||||
-rw-r--r-- | gtk/Makefile.am | 2 | ||||
-rw-r--r-- | gtk/gtkhandlebox.c | 77 | ||||
-rw-r--r-- | gtk/gtkhandlebox.h | 3 | ||||
-rw-r--r-- | gtk/testgtk.c | 47 | ||||
-rw-r--r-- | tests/testgtk.c | 47 |
7 files changed, 152 insertions, 27 deletions
diff --git a/configure.in b/configure.in index 4858d9078a..bbde83a1e2 100644 --- a/configure.in +++ b/configure.in @@ -14,7 +14,7 @@ VERSION=$GTK_VERSION PACKAGE=gtk+ # Configure glib -AC_CONFIG_SUBDIRS(glib) +#AC_CONFIG_SUBDIRS(glib) # Save this value here, since automake will set cflags later cflags_set=${CFLAGS+set} diff --git a/glib/glibconfig.h.in b/glib/glibconfig.h.in index 7ce63bbcaa..1d1c6f218b 100644 --- a/glib/glibconfig.h.in +++ b/glib/glibconfig.h.in @@ -31,6 +31,7 @@ #undef NO_SYS_SIGLIST #undef HAVE_WCHAR_H +#undef HAVE_WCSTR_H #undef HAVE_WCTYPE_H /* #undef PACKAGE */ diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 86064404a9..4791609247 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -29,7 +29,7 @@ libgtk_la_SOURCES = \ gtkframe.c \ gtkgamma.c \ gtkgc.c \ -# gtkhandlebox.c \ + gtkhandlebox.c \ gtkhbbox.c \ gtkhbox.c \ gtkhpaned.c \ diff --git a/gtk/gtkhandlebox.c b/gtk/gtkhandlebox.c index 3de889e519..d8e2f34a6d 100644 --- a/gtk/gtkhandlebox.c +++ b/gtk/gtkhandlebox.c @@ -17,7 +17,9 @@ */ #include "gtksignal.h" #include "gtkhandlebox.h" +#include <gdk/gdkx.h> +#define DRAG_HANDLE_SIZE 10 static void gtk_handle_box_class_init (GtkHandleBoxClass *klass); static void gtk_handle_box_init (GtkHandleBox *handle_box); @@ -26,6 +28,8 @@ static void gtk_handle_box_size_request (GtkWidget *widget, GtkRequisition *requisition); static void gtk_handle_box_size_allocate (GtkWidget *widget, GtkAllocation *allocation); +static void gtk_handle_box_paint (GtkWidget *widget, + GdkRectangle *area); static void gtk_handle_box_draw (GtkWidget *widget, GdkRectangle *area); static gint gtk_handle_box_expose (GtkWidget *widget, @@ -41,7 +45,7 @@ gtk_handle_box_get_type () { static guint handle_box_type = 0; - if (!event_box_type) + if (!handle_box_type) { GtkTypeInfo handle_box_info = { @@ -65,14 +69,13 @@ gtk_handle_box_class_init (GtkHandleBoxClass *class) GtkWidgetClass *widget_class; widget_class = (GtkWidgetClass*) class; - widget_class->realize = gtk_handle_box_realize; widget_class->size_request = gtk_handle_box_size_request; widget_class->size_allocate = gtk_handle_box_size_allocate; widget_class->draw = gtk_handle_box_draw; widget_class->expose_event = gtk_handle_box_expose; - widget_class->button_press_event = gtk_handle_box_button_change; - widget_class->button_release_event = gtk_handle_box_button_change; + widget_class->button_press_event = gtk_handle_box_button_changed; + widget_class->button_release_event = gtk_handle_box_button_changed; widget_class->motion_notify_event = gtk_handle_box_motion; } @@ -129,7 +132,7 @@ gtk_handle_box_realize (GtkWidget *widget) static void gtk_handle_box_size_request (GtkWidget *widget, - GtkRequisition *requisition) + GtkRequisition *requisition) { GtkBin *bin; @@ -139,15 +142,16 @@ gtk_handle_box_size_request (GtkWidget *widget, bin = GTK_BIN (widget); - requisition->width = GTK_CONTAINER (widget)->border_width * 2; - requisition->height = GTK_CONTAINER (widget)->border_width * 2; + requisition->width = DRAG_HANDLE_SIZE; + requisition->height = DRAG_HANDLE_SIZE; if (bin->child && GTK_WIDGET_VISIBLE (bin->child)) { gtk_widget_size_request (bin->child, &bin->child->requisition); requisition->width += bin->child->requisition.width; - requisition->height += bin->child->requisition.height; + if(bin->child->requisition.height > requisition->height) + requisition->height = bin->child->requisition.height; } } @@ -167,14 +171,14 @@ gtk_handle_box_size_allocate (GtkWidget *widget, child_allocation.x = 0; child_allocation.y = 0; - child_allocation.width = allocation->width - GTK_CONTAINER (widget)->border_width * 2; - child_allocation.height = allocation->height - GTK_CONTAINER (widget)->border_width * 2; + child_allocation.width = allocation->width - DRAG_HANDLE_SIZE; + child_allocation.height = allocation->height; if (GTK_WIDGET_REALIZED (widget)) { gdk_window_move_resize (widget->window, - allocation->x + GTK_CONTAINER (widget)->border_width, - allocation->y + GTK_CONTAINER (widget)->border_width, + allocation->x + DRAG_HANDLE_SIZE, + allocation->y, child_allocation.width, child_allocation.height); } @@ -185,6 +189,19 @@ gtk_handle_box_size_allocate (GtkWidget *widget, } } +static void gtk_handle_box_paint(GtkWidget *widget, + GdkRectangle *area) +{ + g_print("painting %dx%d+%d+%d\n", + area->x, area->y, area->width, area->height); + gtk_draw_diamond(widget->style, widget->window, + GTK_STATE_NORMAL, + GTK_SHADOW_ETCHED_IN, + 1, 1, + DRAG_HANDLE_SIZE, + DRAG_HANDLE_SIZE); +} + static void gtk_handle_box_draw (GtkWidget *widget, GdkRectangle *area) @@ -199,7 +216,8 @@ gtk_handle_box_draw (GtkWidget *widget, if (GTK_WIDGET_DRAWABLE (widget)) { bin = GTK_BIN (widget); - + + gtk_handle_box_paint(widget, area); if (bin->child) { if (gtk_widget_intersect (bin->child, area, &child_area)) @@ -210,7 +228,7 @@ gtk_handle_box_draw (GtkWidget *widget, static gint gtk_handle_box_expose (GtkWidget *widget, - GdkEventExpose *event) + GdkEventExpose *event) { GtkBin *bin; GdkEventExpose child_event; @@ -222,6 +240,7 @@ gtk_handle_box_expose (GtkWidget *widget, if (GTK_WIDGET_DRAWABLE (widget)) { bin = GTK_BIN (widget); + gtk_handle_box_paint(widget, &event->area); child_event = *event; if (bin->child && @@ -242,35 +261,49 @@ static gint gtk_handle_box_button_changed(GtkWidget *widget, g_return_val_if_fail(event != NULL, FALSE); hb = GTK_HANDLE_BOX(widget); - - if(event->button == 0) + if(event->button == 1) { if(event->type == GDK_BUTTON_PRESS) { hb->is_being_dragged = TRUE; - real_parent = widget->parent; - gdk_window_set_override_redirect(hb->window, TRUE); - gdk_window_reparent(hb->window, GDK_ROOT_PARENT(), - event->x, event->y); + if(!hb->real_parent) { + hb->real_parent = widget->parent; + gdk_window_set_override_redirect(widget->window, TRUE); + gdk_window_reparent(widget->window, GDK_ROOT_PARENT(), + event->x_root - event->x, + event->y_root - event->y); + g_print("Reparenting with event %f (%f) x %f (%f)\n", + event->x_root, event->x, + event->y_root, event->y); + } else + gdk_window_raise(widget->window); } else if(event->type == GDK_BUTTON_RELEASE) { hb->is_being_dragged = FALSE; } } + return TRUE; } static gint gtk_handle_box_motion (GtkWidget *widget, GdkEventMotion *event) { GtkHandleBox *hb; + gint newx, newy; + g_return_val_if_fail(widget != NULL, FALSE); g_return_val_if_fail(GTK_IS_HANDLE_BOX(widget), FALSE); g_return_val_if_fail(event != NULL, FALSE); hb = GTK_HANDLE_BOX(widget); if(hb->is_being_dragged) { - gdk_window_move(widget->window, event->x_root - event->x, - event->y_root - event->y); + newx = event->x_root - DRAG_HANDLE_SIZE; + newy = event->y_root - DRAG_HANDLE_SIZE; + if(newx < 0) newx = 0; + if(newy < 0) newy = 0; + gdk_window_move(widget->window, newx, + newy); } + return TRUE; } diff --git a/gtk/gtkhandlebox.h b/gtk/gtkhandlebox.h index 7e69bb642c..106f1aa742 100644 --- a/gtk/gtkhandlebox.h +++ b/gtk/gtkhandlebox.h @@ -15,7 +15,8 @@ * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* The GtkHandleBox is to allow +/* The GtkHandleBox is to allow widgets to be dragged in and out of + their parents */ #ifndef __GTK_HANDLE_BOX_H__ #define __GTK_HANDLE_BOX_H__ diff --git a/gtk/testgtk.c b/gtk/testgtk.c index a1d5545dfe..dfb7958c34 100644 --- a/gtk/testgtk.c +++ b/gtk/testgtk.c @@ -20,7 +20,7 @@ #include "gtk.h" #include "../gdk/gdk.h" #include "../gdk/gdkx.h" - +#include "gtkhandlebox.h" void destroy_window (GtkWidget *widget, @@ -548,6 +548,50 @@ create_button_box () gtk_widget_destroy (window); } +void +create_handle_box () +{ + static GtkWidget* window = NULL; + GtkWidget* hbox; + GtkWidget* button; + + if (!window) + { + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), + "Handle Box Test"); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(destroy_window), &window); + gtk_signal_connect (GTK_OBJECT (window), "delete_event", + GTK_SIGNAL_FUNC(destroy_window), &window); + + gtk_container_border_width (GTK_CONTAINER (window), 20); + + /* + *these 15 lines are a nice and easy example for GtkHButtonBox + */ + hbox = gtk_handle_box_new (); + gtk_container_add (GTK_CONTAINER (window), hbox); + gtk_widget_set_usize(hbox, 300, 40); + gtk_widget_show (hbox); + +#if 0 + button = gtk_toggle_button_new_with_label ("Let's try this"); +#else + button = gtk_label_new ("Let's try this"); +#endif + gtk_container_add (GTK_CONTAINER (hbox), button); + gtk_widget_set_usize(button, 250, 40); + gtk_widget_show (button); + } + + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show (window); + else + gtk_widget_destroy (window); +} + void reparent_label (GtkWidget *widget, @@ -3234,6 +3278,7 @@ create_main_window () { "check buttons", create_check_buttons }, { "radio buttons", create_radio_buttons }, { "button box", create_button_box }, + { "handle box", create_handle_box }, { "reparent", create_reparent }, { "pixmap", create_pixmap }, { "tooltips", create_tooltips }, diff --git a/tests/testgtk.c b/tests/testgtk.c index a1d5545dfe..dfb7958c34 100644 --- a/tests/testgtk.c +++ b/tests/testgtk.c @@ -20,7 +20,7 @@ #include "gtk.h" #include "../gdk/gdk.h" #include "../gdk/gdkx.h" - +#include "gtkhandlebox.h" void destroy_window (GtkWidget *widget, @@ -548,6 +548,50 @@ create_button_box () gtk_widget_destroy (window); } +void +create_handle_box () +{ + static GtkWidget* window = NULL; + GtkWidget* hbox; + GtkWidget* button; + + if (!window) + { + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), + "Handle Box Test"); + + gtk_signal_connect (GTK_OBJECT (window), "destroy", + GTK_SIGNAL_FUNC(destroy_window), &window); + gtk_signal_connect (GTK_OBJECT (window), "delete_event", + GTK_SIGNAL_FUNC(destroy_window), &window); + + gtk_container_border_width (GTK_CONTAINER (window), 20); + + /* + *these 15 lines are a nice and easy example for GtkHButtonBox + */ + hbox = gtk_handle_box_new (); + gtk_container_add (GTK_CONTAINER (window), hbox); + gtk_widget_set_usize(hbox, 300, 40); + gtk_widget_show (hbox); + +#if 0 + button = gtk_toggle_button_new_with_label ("Let's try this"); +#else + button = gtk_label_new ("Let's try this"); +#endif + gtk_container_add (GTK_CONTAINER (hbox), button); + gtk_widget_set_usize(button, 250, 40); + gtk_widget_show (button); + } + + if (!GTK_WIDGET_VISIBLE (window)) + gtk_widget_show (window); + else + gtk_widget_destroy (window); +} + void reparent_label (GtkWidget *widget, @@ -3234,6 +3278,7 @@ create_main_window () { "check buttons", create_check_buttons }, { "radio buttons", create_radio_buttons }, { "button box", create_button_box }, + { "handle box", create_handle_box }, { "reparent", create_reparent }, { "pixmap", create_pixmap }, { "tooltips", create_tooltips }, |