From 90c5886333d77e714e757c3098767fddf895a9b4 Mon Sep 17 00:00:00 2001 From: "pavlov%pavlov.net" Date: Sat, 9 Jan 1999 17:41:20 +0000 Subject: [PATCH] Resizing works.... somewhat. More to come --- widget/src/gtk/nsGtkEventHandler.cpp | 48 +++++++++++++++++++++ widget/src/gtk/nsGtkEventHandler.h | 1 + widget/src/gtk/nsWidget.cpp | 62 +++++++++++++++------------- widget/src/gtk/nsWindow.cpp | 14 +++---- 4 files changed, 88 insertions(+), 37 deletions(-) diff --git a/widget/src/gtk/nsGtkEventHandler.cpp b/widget/src/gtk/nsGtkEventHandler.cpp index 3930fd830039..b3b6a542d16d 100644 --- a/widget/src/gtk/nsGtkEventHandler.cpp +++ b/widget/src/gtk/nsGtkEventHandler.cpp @@ -160,6 +160,30 @@ void InitAllocationEvent(GtkAllocation *aAlloc, anEvent.time = 0; } +//============================================================== +void InitConfigureEvent(GdkEventConfigure *aConf, + gpointer p, + nsSizeEvent &anEvent, + PRUint32 aEventType) +{ + anEvent.message = aEventType; + anEvent.widget = (nsWidget *) p; + NS_ADDREF(anEvent.widget); + + anEvent.eventStructType = NS_SIZE_EVENT; + + if (aConf != NULL) { + nsRect *foo = new nsRect(aConf->x, aConf->y, aConf->width, aConf->height); + anEvent.windowSize = foo; + anEvent.point.x = aConf->x; + anEvent.point.y = aConf->y; + anEvent.mWinWidth = aConf->width; + anEvent.mWinHeight = aConf->height; + } +// this usually returns 0 + anEvent.time = 0; +} + //============================================================== void InitMouseEvent(GdkEventButton *aGEB, gpointer p, @@ -282,14 +306,38 @@ void InitKeyEvent(GdkEventKey *aGEK, void handle_size_allocate(GtkWidget *w, GtkAllocation *alloc, gpointer p) { + g_print("size_allocate: %p, {x=%i, y=%i, w=%i, h=%i}\n", w, alloc->x, + alloc->y, + alloc->width, + alloc->height); + nsSizeEvent sevent; InitAllocationEvent(alloc, p, sevent, NS_SIZE); + sevent.mWinWidth = gtk_widget_get_toplevel(w)->allocation.width; + sevent.mWinHeight = gtk_widget_get_toplevel(w)->allocation.height; nsWindow *win = (nsWindow *)p; win->OnResize(sevent); } +gint handle_configure_event(GtkWidget *w, GdkEventConfigure *conf, gpointer p) +{ + g_print("configure_event: {x=%i, y=%i, w=%i, h=%i}\n", conf->x, + conf->y, + conf->width, + conf->height); + + nsSizeEvent sevent; + InitConfigureEvent(conf, p, sevent, NS_SIZE); + + nsWindow *win = (nsWindow *)p; + + win->OnResize(sevent); + + return PR_FALSE; +} + gint handle_expose_event(GtkWidget *w, GdkEventExpose *event, gpointer p) { if (event->type == GDK_NO_EXPOSE) diff --git a/widget/src/gtk/nsGtkEventHandler.h b/widget/src/gtk/nsGtkEventHandler.h index e1b6e3ebf2a7..939c55874f00 100644 --- a/widget/src/gtk/nsGtkEventHandler.h +++ b/widget/src/gtk/nsGtkEventHandler.h @@ -24,6 +24,7 @@ class nsIWidget; class nsIMenuItem; +gint handle_configure_event(GtkWidget *w, GdkEventConfigure *conf, gpointer p); void handle_size_allocate(GtkWidget *w, GtkAllocation *alloc, gpointer p); gint handle_expose_event(GtkWidget *w, GdkEventExpose *event, gpointer p); gint handle_button_press_event(GtkWidget *w, GdkEventButton * event, gpointer p); diff --git a/widget/src/gtk/nsWidget.cpp b/widget/src/gtk/nsWidget.cpp index b6dbcfe8e863..a96005f87eb8 100644 --- a/widget/src/gtk/nsWidget.cpp +++ b/widget/src/gtk/nsWidget.cpp @@ -158,33 +158,31 @@ NS_METHOD nsWidget::IsVisible(PRBool &aState) NS_METHOD nsWidget::Move(PRUint32 aX, PRUint32 aY) { -#ifdef DBG - g_print("nsWidget::Move(%3d,%3d) - %s %p\n", aX, aY, mWidget->name, this); -#endif + if (mBounds.x == aX && mBounds.y == aY) + return NS_ERROR_FAILURE; + mBounds.x = aX; mBounds.y = aY; + gtk_layout_move(GTK_LAYOUT(mWidget->parent), mWidget, aX, aY); + return NS_OK; } NS_METHOD nsWidget::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) { -//#ifdef DBG - g_print("nsWidget::Resize(%3d,%3d) - %s %p %s\n", aWidth, aHeight, mWidget->name, this, aRepaint ? "paint" : "no paint"); -//#endif - if (aWidth > 2000) - { - g_print("we have problems! aWidth == %d, setting to 0\n", aWidth); - aWidth = -1; - } - if (aHeight > 2000) - { - g_print("we have problems! aHeight == %d, setting to 0\n", aHeight); - aHeight = -1; - } + if (mBounds.width == aWidth && mBounds.height == aHeight) + return NS_ERROR_FAILURE; + mBounds.width = aWidth; mBounds.height = aHeight; gtk_widget_set_usize(mWidget, aWidth, aHeight); + +/* + if (aRepaint) + gtk_widget_queue_resize(mWidget); +*/ + if (aRepaint && GTK_IS_WIDGET (mWidget) && GTK_WIDGET_REALIZED (GTK_WIDGET(mWidget))) { @@ -204,15 +202,30 @@ NS_METHOD nsWidget::Resize(PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) gtk_widget_event (GTK_WIDGET(mWidget), (GdkEvent*) &event); gdk_window_unref (event.window); } + return NS_OK; } NS_METHOD nsWidget::Resize(PRUint32 aX, PRUint32 aY, PRUint32 aWidth, PRUint32 aHeight, PRBool aRepaint) { - Resize(aWidth, aHeight, aRepaint); - Move(aX, aY); - return NS_OK; + GtkAllocation alloc; + alloc.x = aX; + alloc.y = aY; + alloc.width = aWidth; + alloc.height = aHeight; + + mBounds.x = aX; + mBounds.y = aY; + mBounds.width = aWidth; + mBounds.height = aHeight; + + gtk_widget_size_allocate (mWidget, &alloc); + + if (aRepaint) + gtk_widget_queue_draw(mWidget); + + return NS_OK; } //------------------------------------------------------------------------- @@ -492,21 +505,13 @@ nsresult nsWidget::StandardWindowCreate(nsIWidget *aParent, parentWidget = GTK_WIDGET(shellWidget); } -#ifdef DBG - g_print("--\n"); -#endif - CreateNative (parentWidget); - Resize(mBounds.width, mBounds.height, PR_TRUE); - if (parentWidget) { gtk_layout_put(GTK_LAYOUT(parentWidget), mWidget, mBounds.x, mBounds.y); -#ifdef DBG - g_print("nsWidget::SWC(%3d,%3d) - %s %p\n", mBounds.x, mBounds.y, mWidget->name, this); -#endif } + Resize(mBounds.width, mBounds.height, PR_FALSE); InitCallbacks(); CreateGC(); @@ -514,7 +519,6 @@ nsresult nsWidget::StandardWindowCreate(nsIWidget *aParent, gtk_widget_pop_colormap(); gtk_widget_pop_visual(); - DispatchStandardEvent(NS_CREATE); return NS_OK; } diff --git a/widget/src/gtk/nsWindow.cpp b/widget/src/gtk/nsWindow.cpp index a9c807012651..dcac439a1d82 100644 --- a/widget/src/gtk/nsWindow.cpp +++ b/widget/src/gtk/nsWindow.cpp @@ -58,7 +58,6 @@ nsWindow::nsWindow() strcpy(gInstanceClassName, "nsWindow"); mFontMetrics = nsnull; mVBox = nsnull; - mIgnoreResize = PR_FALSE; mResized = PR_FALSE; mVisible = PR_FALSE; mDisplayed = PR_FALSE; @@ -202,7 +201,6 @@ NS_METHOD nsWindow::CreateNative(GtkWidget *parentWidget) mWidget = gtk_layout_new(PR_FALSE, PR_FALSE); gtk_widget_set_events (mWidget, - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | @@ -221,18 +219,12 @@ NS_METHOD nsWindow::CreateNative(GtkWidget *parentWidget) GTK_SIGNAL_FUNC(window_realize_callback), NULL); - gtk_signal_connect(GTK_OBJECT(mainWindow), - "size_allocate", - GTK_SIGNAL_FUNC(handle_size_allocate), - this); - // VBox for the menu, etc. mVBox = gtk_vbox_new(PR_FALSE, 0); gtk_widget_show (mVBox); gtk_container_add(GTK_CONTAINER(mainWindow), mVBox); gtk_box_pack_start(GTK_BOX(mVBox), mWidget, PR_TRUE, PR_TRUE, 0); } - gtk_widget_show(mWidget); // Force cursor to default setting gtk_widget_set_name(mWidget, "nsWindow"); mCursor = eCursor_select; @@ -248,6 +240,12 @@ NS_METHOD nsWindow::CreateNative(GtkWidget *parentWidget) //------------------------------------------------------------------------- void nsWindow::InitCallbacks(char * aName) { + + gtk_signal_connect_after(GTK_OBJECT(mWidget), + "size_allocate", + GTK_SIGNAL_FUNC(handle_size_allocate), + this); + gtk_signal_connect(GTK_OBJECT(mWidget), "button_press_event", GTK_SIGNAL_FUNC(handle_button_press_event),