more gtkhandlebox work..

This commit is contained in:
Elliot Lee 1997-12-19 19:17:45 +00:00
parent e9f322e2f0
commit 61124945c0
7 changed files with 152 additions and 27 deletions

View File

@ -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}

View File

@ -31,6 +31,7 @@
#undef NO_SYS_SIGLIST
#undef HAVE_WCHAR_H
#undef HAVE_WCSTR_H
#undef HAVE_WCTYPE_H
/* #undef PACKAGE */

View File

@ -29,7 +29,7 @@ libgtk_la_SOURCES = \
gtkframe.c \
gtkgamma.c \
gtkgc.c \
# gtkhandlebox.c \
gtkhandlebox.c \
gtkhbbox.c \
gtkhbox.c \
gtkhpaned.c \

View File

@ -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;
}
@ -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)
@ -200,6 +217,7 @@ gtk_handle_box_draw (GtkWidget *widget,
{
bin = GTK_BIN (widget);
gtk_handle_box_paint(widget, area);
if (bin->child)
{
if (gtk_widget_intersect (bin->child, area, &child_area))
@ -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;
}

View File

@ -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__

View File

@ -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 },

View File

@ -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 },