]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk1/window.cpp
wxMotif: wxWindow/Client/PaintDC starting to work.
[wxWidgets.git] / src / gtk1 / window.cpp
index ada44904e66c8d8988ac494c34bbaacd81681472..e382126ada827bfda65d54f342bce2ae9e0d543c 100644 (file)
 #include "wx/menu.h"
 #include "wx/notebook.h"
 #include "wx/statusbr.h"
-#include <wx/intl.h>
-#include "gdk/gdkkeysyms.h"
-#include <math.h>
+#include "wx/intl.h"
 #include "wx/gtk/win_gtk.h"
 #include "gdk/gdkprivate.h"
+#include "gdk/gdkkeysyms.h"
+
+#include <math.h>
+
+//-----------------------------------------------------------------------------
+// documentation on internals
+//-----------------------------------------------------------------------------
+
+/*
+   I have been asked several times about writing some documentation about
+   the GTK port of wxWindows, especially its internal structures. Obviously,
+   you cannot understand wxGTK without knowing a little about the GTK, but
+   some more information about what the wxWindow, which is the base class 
+   for all other window classes, does seems required as well.
+   
+   What does wxWindow do? It contains the common interface for the following
+   jobs of its descentants:
+   
+   1) Define the rudimentary behaviour common to all window classes, such as
+   resizing, intercepting user input so as to make it possible to use these
+   events for special purposes in a derived class, window names etc.
+
+   2) Provide the possibility to contain and manage children, if the derived
+   class is allowed to contain children, which holds true for those window
+   classes, which do not display a native GTK widget. To name them, these
+   classes are wxPanel, wxScrolledWindow, wxDialog, wxFrame. The MDI frame-
+   work classes are a special case and are handled a bit differently from 
+   the rest.
+   
+   3) Provide the possibility to draw into a client area of a window. This,
+   too, only holds true for classes that do not display a native GTK widget
+   as above.
+   
+   4) Provide the entire mechanism for scrolling widgets. This actaul inter-
+   face for this is usually in wxScrolledWidget, but the GTK implementation
+   is in this class.
+   
+   5) A multitude of helper or extra methods for special purposes, such as
+   Drag'n'Drop, managing validators etc.
+   
+   Normally one might expect, that one wxWindows class would always contain
+   one GTK widget. Under GTK, there is no such allround widget that has all
+   the functionality. Moreover, the GTK defines a client area as a different
+   widget from the actual widget you are handling. Last but not least some
+   special classes (e.g. wxFrame) handle different categories of widgets and
+   still have the possibility to draw something in the client area.
+   It was therefore required to write a special purpose GTK widget, that would
+   represent a client area in the sense of wxWindows capable to do the jobs
+   2), 3) and 4). I have written this class and it resides in win_gtk.c of
+   this directory.
+   
+   All windows must have a widget, with which they interact with other under-
+   lying GTK widget. It is this widget, e.g. that has to be resized etc and
+   thw wxWindow class has a member variable called m_widget which holds a
+   pointer to this widget. When the window class displays a GTK native widget,
+   this is the only GTK widget the class manages. When the class has a client
+   area for drawing into and for containing children it must have at least
+   one more GTK widget to handle (of the type GtkMyFixed, defined in win_gtk.c),
+   but there can be any number of widgets, handled by a class (e.g. the frame
+   class handles three). The common rule for all windows is only, that the
+   widget that interacts with the rest of GTK must be referenced in m_widget
+   and all other widgets must be children of this widget on the GTK level.
+   The top-most widget, which also represents the client area, must be in
+   the m_wxwindow field and must be of the type GtkMyFixed.
+   
+   As I said, the window classes that display a GTK native widget only have
+   one widget, so in the case of e.g. the wxButton class m_widget holds a
+   pointer to a GtkButton widget. But windows with client areas (for drawing
+   and children) have a m_widget field that is a pointer to a GtkScrolled-
+   Window and a m_wxwindow field that is pointer to a GtkMyFixed and this
+   one is (in the GTK sense) a child of the GtkScrolledWindow.
+   
+   If the m_wxwindow field is set, then all input to this widget is inter-
+   cepted and sent to the wxWindows class. If not, all input to the widget
+   that gets pointed to by m_widget gets intercepted and sent to the class.
+
+*/
 
 //-----------------------------------------------------------------------------
 // data
 extern wxList wxPendingDelete;
 extern wxList wxTopLevelWindows;
 extern bool   g_blockEventsOnDrag;
+       bool   g_capturing = FALSE;
 
 //-----------------------------------------------------------------------------
 // "expose_event" (of m_wxwindow, not of m_widget)
@@ -58,6 +134,13 @@ static void gtk_window_expose_callback( GtkWidget *WXUNUSED(widget), GdkEventExp
            
   if (gdk_event->count > 0) return;
 
+/*
+  printf( "OnExpose from " );
+  if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+    printf( win->GetClassInfo()->GetClassName() );
+  printf( ".\n" );
+*/
+
   wxPaintEvent event( win->GetId() );
   event.SetEventObject( win );
   win->GetEventHandler()->ProcessEvent( event );
@@ -191,6 +274,22 @@ static gint gtk_window_key_press_callback( GtkWidget *widget, GdkEventKey *gdk_e
   
   bool ret = win->GetEventHandler()->ProcessEvent( event );
   
+  if (!ret)
+  {
+    wxWindow *ancestor = win;
+    while (ancestor)
+    {    
+      int command = ancestor->GetAcceleratorTable()->GetCommand( event );
+      if (command != -1)
+      {
+        wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
+        ret = ancestor->GetEventHandler()->ProcessEvent( command_event );
+       break;
+      }
+      ancestor = ancestor->GetParent();
+    }
+  }
+  
   if (ret)
   {
     if ((gdk_event->keyval >= 0x20) && (gdk_event->keyval <= 0xFF)) 
@@ -227,11 +326,13 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
   }
     
   if (!win->HasVMT()) return TRUE;
-    
+
+/*
   printf( "OnButtonPress from " );
   if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
     printf( win->GetClassInfo()->GetClassName() );
   printf( ".\n" );
+*/
 
   wxEventType event_type = wxEVT_LEFT_DOWN;
   
@@ -278,21 +379,24 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
   // Some control don't have their own X window and thus cannot get
   // any events. 
   
-  wxNode *node = win->GetChildren()->First();
-  while (node)
+  if (!g_capturing)
   {
-    wxWindow *child = (wxWindow*)node->Data();
-    if ((child->m_x <= event.m_x) &&
-        (child->m_y <= event.m_y) &&
-       (child->m_x+child->m_width  >= event.m_x) &&
-       (child->m_y+child->m_height >= event.m_y))
+    wxNode *node = win->GetChildren()->First();
+    while (node)
     {
-      win = child;
-      event.m_x -= child->m_x;
-      event.m_y -= child->m_y;
-      break;
+      wxWindow *child = (wxWindow*)node->Data();
+      if ((child->m_x <= event.m_x) &&
+          (child->m_y <= event.m_y) &&
+         (child->m_x+child->m_width  >= event.m_x) &&
+         (child->m_y+child->m_height >= event.m_y))
+      {
+        win = child;
+        event.m_x -= child->m_x;
+        event.m_y -= child->m_y;
+        break;
+      }
+      node = node->Next();
     }
-    node = node->Next();
   }
   
   event.SetEventObject( win );
@@ -304,12 +408,13 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
 }
 
 //-----------------------------------------------------------------------------
-// "button_release"
+// "button_release_event"
 //-----------------------------------------------------------------------------
 
 static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButton *gdk_event, wxWindow *win )
 { 
   if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
+  
   if (g_blockEventsOnDrag) return TRUE;
 
   if (!win->HasVMT()) return TRUE;
@@ -344,21 +449,24 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto
   // Some control don't have their own X window and thus cannot get
   // any events. 
   
-  wxNode *node = win->GetChildren()->First();
-  while (node)
+  if (!g_capturing)
   {
-    wxWindow *child = (wxWindow*)node->Data();
-    if ((child->m_x <= event.m_x) &&
-        (child->m_y <= event.m_y) &&
-       (child->m_x+child->m_width  >= event.m_x) &&
-       (child->m_y+child->m_height >= event.m_y))
+    wxNode *node = win->GetChildren()->First();
+    while (node)
     {
-      win = child;
-      event.m_x -= child->m_x;
-      event.m_y -= child->m_y;
-      break;
+      wxWindow *child = (wxWindow*)node->Data();
+      if ((child->m_x <= event.m_x) &&
+          (child->m_y <= event.m_y) &&
+         (child->m_x+child->m_width  >= event.m_x) &&
+         (child->m_y+child->m_height >= event.m_y))
+      {
+        win = child;
+        event.m_x -= child->m_x;
+        event.m_y -= child->m_y;
+        break;
+      }
+      node = node->Next();
     }
-    node = node->Next();
   }
   
   event.SetEventObject( win );
@@ -376,6 +484,7 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto
 static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion *gdk_event, wxWindow *win )
 { 
   if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
+  
   if (g_blockEventsOnDrag) return TRUE;
 
   if (!win->HasVMT()) return TRUE;
@@ -402,21 +511,24 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion
   // Some control don't have their own X window and thus cannot get
   // any events. 
   
-  wxNode *node = win->GetChildren()->First();
-  while (node)
+  if (!g_capturing)
   {
-    wxWindow *child = (wxWindow*)node->Data();
-    if ((child->m_x <= event.m_x) &&
-        (child->m_y <= event.m_y) &&
-       (child->m_x+child->m_width  >= event.m_x) &&
-       (child->m_y+child->m_height >= event.m_y))
+    wxNode *node = win->GetChildren()->First();
+    while (node)
     {
-      win = child;
-      event.m_x -= child->m_x;
-      event.m_y -= child->m_y;
-      break;
+      wxWindow *child = (wxWindow*)node->Data();
+      if ((child->m_x <= event.m_x) &&
+          (child->m_y <= event.m_y) &&
+         (child->m_x+child->m_width  >= event.m_x) &&
+         (child->m_y+child->m_height >= event.m_y))
+      {
+        win = child;
+        event.m_x -= child->m_x;
+        event.m_y -= child->m_y;
+        break;
+      }
+      node = node->Next();
     }
-    node = node->Next();
   }
   
   event.SetEventObject( win );
@@ -499,6 +611,68 @@ static gint gtk_window_focus_out_callback( GtkWidget *widget, GdkEvent *WXUNUSED
   return TRUE;
 }
 
+//-----------------------------------------------------------------------------
+// "enter_notify_event"
+//-----------------------------------------------------------------------------
+
+static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
+{
+  if (widget->window != gdk_event->window) return TRUE;
+  
+  if (g_blockEventsOnDrag) return TRUE;
+  
+  if (!win->HasVMT()) return TRUE;
+  
+/*
+  printf( "OnEnter from " );
+  if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+    printf( win->GetClassInfo()->GetClassName() );
+  printf( ".\n" );
+*/
+  
+  if ((widget->window) && (win->m_cursor))
+    gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() );
+    
+  wxMouseEvent event( wxEVT_ENTER_WINDOW );
+  event.SetEventObject( win );
+  
+  if (win->GetEventHandler()->ProcessEvent( event ))
+    gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "enter_notify_event" );
+  
+  return TRUE;
+}
+    
+//-----------------------------------------------------------------------------
+// "leave_notify_event"
+//-----------------------------------------------------------------------------
+
+static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
+{
+  if (widget->window != gdk_event->window) return TRUE;
+  
+  if (g_blockEventsOnDrag) return TRUE;
+  
+  if (!win->HasVMT()) return TRUE;
+  
+/*
+  printf( "OnLeave from " );
+  if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
+    printf( win->GetClassInfo()->GetClassName() );
+  printf( ".\n" );
+*/
+  
+  if ((widget->window) && (win->m_cursor))
+    gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
+    
+  wxMouseEvent event( wxEVT_LEAVE_WINDOW );
+  event.SetEventObject( win );
+  
+  if (win->GetEventHandler()->ProcessEvent( event ))
+    gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "leave_notify_event" );
+  
+  return TRUE;
+}
+    
 //-----------------------------------------------------------------------------
 // "value_changed" from m_vAdjust
 //-----------------------------------------------------------------------------
@@ -625,6 +799,39 @@ static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW
   win->GetEventHandler()->ProcessEvent( event );
 }
 
+//-----------------------------------------------------------------------------
+// "button_press_event" from scrollbar
+//-----------------------------------------------------------------------------
+
+static gint gtk_scrollbar_button_press_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win )
+{
+  if (gdk_event->window != widget->slider) return FALSE;
+
+  win->m_isScrolling = TRUE;
+  
+  return FALSE;
+}
+
+//-----------------------------------------------------------------------------
+// "button_release_event" from scrollbar
+//-----------------------------------------------------------------------------
+
+static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win )
+{
+  if (gdk_event->window != widget->slider) return FALSE;
+
+  GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(win->m_widget);
+  if (widget == GTK_RANGE(s_window->vscrollbar))
+    gtk_signal_emit_by_name( GTK_OBJECT(win->m_hAdjust), "value_changed" );
+  else  
+    gtk_signal_emit_by_name( GTK_OBJECT(win->m_vAdjust), "value_changed" );
+      
+  win->m_isScrolling = FALSE;
+  
+  return FALSE;
+}
+
 //-----------------------------------------------------------------------------
 // "drop_data_available_event"
 //-----------------------------------------------------------------------------
@@ -647,42 +854,6 @@ static void gtk_window_drop_callback( GtkWidget *widget, GdkEvent *event, wxWind
 */
 }
 
-//-----------------------------------------------------------------------------
-// "enter_notify_event"
-//-----------------------------------------------------------------------------
-
-static gint gtk_window_enter_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
-{
-  if (widget->window != gdk_event->window) return TRUE;
-  if (g_blockEventsOnDrag) return TRUE;
-  if (!win->HasVMT()) return TRUE;
-  
-  if (widget->window)
-    gdk_window_set_cursor( widget->window, win->m_cursor->GetCursor() );
-    
-  wxMouseEvent event( wxEVT_ENTER_WINDOW );
-  event.SetEventObject( win );
-  return win->GetEventHandler()->ProcessEvent( event );
-}
-    
-//-----------------------------------------------------------------------------
-// "leave_notify_event"
-//-----------------------------------------------------------------------------
-
-static gint gtk_window_leave_callback( GtkWidget *widget, GdkEventCrossing *gdk_event, wxWindow *win )
-{
-  if (widget->window != gdk_event->window) return TRUE;
-  if (!win->HasVMT()) return TRUE;
-  if (g_blockEventsOnDrag) return TRUE;
-  
-  if (widget->window)
-    gdk_window_set_cursor( widget->window, wxSTANDARD_CURSOR->GetCursor() );
-    
-  wxMouseEvent event( wxEVT_LEAVE_WINDOW );
-  event.SetEventObject( win );
-  return win->GetEventHandler()->ProcessEvent( event );
-}
-    
 //-----------------------------------------------------------------------------
 // wxWindow
 //-----------------------------------------------------------------------------
@@ -714,7 +885,7 @@ wxWindow::wxWindow()
   m_eventHandler = this;
   m_windowValidator = (wxValidator *) NULL;
   m_windowId = -1;
-  m_cursor = new wxCursor( wxCURSOR_ARROW );
+  m_cursor = (wxCursor *) NULL;
   m_font = *wxSWISS_FONT;
   m_windowStyle = 0;
   m_windowName = "noname";
@@ -727,6 +898,7 @@ wxWindow::wxWindow()
   m_hasVMT = FALSE;
   m_needParent = TRUE;
   m_hasScrolling = FALSE;
+  m_isScrolling = FALSE;
   m_hAdjust = (GtkAdjustment *) NULL;
   m_vAdjust = (GtkAdjustment *) NULL;
   m_oldHorizontalPos = 0.0;
@@ -735,6 +907,7 @@ wxWindow::wxWindow()
   m_isEnabled = TRUE;
   m_pDropTarget = (wxDropTarget *) NULL;
   m_resizing = FALSE;
+  m_hasOwnStyle = FALSE;
 }
 
 bool wxWindow::Create( wxWindow *parent, wxWindowID id,
@@ -752,9 +925,20 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
   m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
   m_hasScrolling = TRUE;
   
-  GtkScrolledWindow *s_window;
-  s_window = GTK_SCROLLED_WINDOW(m_widget);
-  
+  GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(m_widget);
+  gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_press_event",
+          (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
+
+  gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_press_event",
+          (GtkSignalFunc)gtk_scrollbar_button_press_callback, (gpointer) this );
+
+  gtk_signal_connect( GTK_OBJECT(s_window->vscrollbar), "button_release_event",
+          (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
+
+  gtk_signal_connect( GTK_OBJECT(s_window->hscrollbar), "button_release_event",
+          (GtkSignalFunc)gtk_scrollbar_button_release_callback, (gpointer) this );
+
   GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
   scroll_class->scrollbar_spacing = 0;
   
@@ -766,18 +950,17 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
   m_hAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->hscrollbar) );
   m_vAdjust = gtk_range_get_adjustment( GTK_RANGE(s_window->vscrollbar) );
   
-  gtk_signal_connect (GTK_OBJECT (m_hAdjust), "value_changed",
+  gtk_signal_connect( GTK_OBJECT(m_hAdjust), "value_changed",
           (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
-  gtk_signal_connect (GTK_OBJECT (m_vAdjust), "value_changed",
+  gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
           (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
           
-  gtk_signal_connect (GTK_OBJECT (m_hAdjust), "changed",
+  gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed",
           (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this );
-  gtk_signal_connect (GTK_OBJECT (m_vAdjust), "changed",
+  gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed",
           (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this );
   
-  GtkViewport *viewport;
-  viewport = GTK_VIEWPORT(s_window->viewport);
+  GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport);
   
   if (m_windowStyle & wxRAISED_BORDER)
   {
@@ -916,20 +1099,18 @@ void wxWindow::PreCreation( wxWindow *parent, wxWindowID id,
   m_windowSizer = (wxSizer *) NULL;
   m_sizerParent = (wxWindow *) NULL;
   m_autoLayout = FALSE;
+  m_hasScrolling = FALSE;
+  m_isScrolling = FALSE;
   m_pDropTarget = (wxDropTarget *) NULL;
   m_resizing = FALSE;
   m_windowValidator = (wxValidator *) NULL;
+  m_hasOwnStyle = FALSE;
 }
 
 void wxWindow::PostCreation(void)
 {
   if (m_parent) m_parent->AddChild( this );
   
-//  GtkStyle *style = m_widget->style;
-//  style->font = m_font.GetInternalFont( 1.0 );          // destroy old font ?
-  
-  GtkWidget *connect_widget = GetConnectWidget();
   if (m_wxwindow)
   {
     gtk_signal_connect( GTK_OBJECT(m_wxwindow), "expose_event", 
@@ -939,52 +1120,46 @@ void wxWindow::PostCreation(void)
       GTK_SIGNAL_FUNC(gtk_window_draw_callback), (gpointer)this );
   }
   
-  gtk_signal_connect( GTK_OBJECT(connect_widget), "key_press_event",
+  ConnectWidget( GetConnectWidget() );
+  
+  if (m_widget && m_parent) gtk_widget_realize( m_widget );
+  
+  if (m_wxwindow)
+  {
+    gtk_widget_realize( m_wxwindow );
+    gdk_gc_set_exposures( m_wxwindow->style->fg_gc[0], TRUE );
+  }
+  
+  SetCursor( *wxSTANDARD_CURSOR );
+  
+  m_hasVMT = TRUE;
+}
+
+void wxWindow::ConnectWidget( GtkWidget *widget )
+{
+  gtk_signal_connect( GTK_OBJECT(widget), "key_press_event",
     GTK_SIGNAL_FUNC(gtk_window_key_press_callback), (gpointer)this );
 
-  gtk_signal_connect( GTK_OBJECT(connect_widget), "button_press_event",
+  gtk_signal_connect( GTK_OBJECT(widget), "button_press_event",
     GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this );
     
-  gtk_signal_connect( GTK_OBJECT(connect_widget), "button_release_event",
+  gtk_signal_connect( GTK_OBJECT(widget), "button_release_event",
     GTK_SIGNAL_FUNC(gtk_window_button_release_callback), (gpointer)this );
     
-  gtk_signal_connect( GTK_OBJECT(connect_widget), "motion_notify_event",
+  gtk_signal_connect( GTK_OBJECT(widget), "motion_notify_event",
     GTK_SIGNAL_FUNC(gtk_window_motion_notify_callback), (gpointer)this );
     
-  gtk_signal_connect( GTK_OBJECT(connect_widget), "focus_in_event", 
+  gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event", 
     GTK_SIGNAL_FUNC(gtk_window_focus_in_callback), (gpointer)this );
 
-  gtk_signal_connect( GTK_OBJECT(connect_widget), "focus_out_event", 
+  gtk_signal_connect( GTK_OBJECT(widget), "focus_out_event", 
     GTK_SIGNAL_FUNC(gtk_window_focus_out_callback), (gpointer)this );
 
-  // Only for cursor handling
-    
-  gtk_signal_connect( GTK_OBJECT(m_widget), "enter_notify_event", 
+  gtk_signal_connect( GTK_OBJECT(widget), "enter_notify_event", 
     GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this );
     
-  gtk_signal_connect( GTK_OBJECT(m_widget), "leave_notify_event", 
+  gtk_signal_connect( GTK_OBJECT(widget), "leave_notify_event", 
     GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this );
-    
-  if (m_wxwindow)
-  {
-    gtk_signal_connect( GTK_OBJECT(m_wxwindow), "enter_notify_event", 
-      GTK_SIGNAL_FUNC(gtk_window_enter_callback), (gpointer)this );
-      
-    gtk_signal_connect( GTK_OBJECT(m_wxwindow), "leave_notify_event", 
-      GTK_SIGNAL_FUNC(gtk_window_leave_callback), (gpointer)this );
-  }
-  
-  if (m_widget && m_parent) gtk_widget_realize( m_widget );
-  
-  if (m_wxwindow)
-  {
-    gtk_widget_realize( m_wxwindow );
-    gdk_gc_set_exposures( m_wxwindow->style->fg_gc[0], TRUE );
-  }
-  
-  SetCursor( wxSTANDARD_CURSOR );
-  
-  m_hasVMT = TRUE;
 }
 
 bool wxWindow::HasVMT(void)
@@ -994,6 +1169,8 @@ bool wxWindow::HasVMT(void)
 
 bool wxWindow::Close( bool force )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   wxCloseEvent event(wxEVT_CLOSE_WINDOW, m_windowId);
   event.SetEventObject(this);
   event.SetForce(force);
@@ -1003,6 +1180,8 @@ bool wxWindow::Close( bool force )
 
 bool wxWindow::Destroy(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   m_hasVMT = FALSE;
   delete this;
   return TRUE;
@@ -1063,6 +1242,8 @@ void wxWindow::ImplementSetPosition(void)
 
 void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (m_resizing) return; // I don't like recursions
   m_resizing = TRUE;
   
@@ -1122,12 +1303,16 @@ void wxWindow::Move( int x, int y )
 
 void wxWindow::GetSize( int *width, int *height ) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (width) (*width) = m_width;
   if (height) (*height) = m_height;
 }
 
 void wxWindow::SetClientSize( int width, int height )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (!m_wxwindow)
   {
     SetSize( width, height );
@@ -1185,6 +1370,8 @@ void wxWindow::SetClientSize( int width, int height )
 
 void wxWindow::GetClientSize( int *width, int *height ) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (!m_wxwindow)
   {
     if (width) (*width) = m_width;
@@ -1246,12 +1433,16 @@ void wxWindow::GetClientSize( int *width, int *height ) const
 
 void wxWindow::GetPosition( int *x, int *y ) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (x) (*x) = m_x;
   if (y) (*y) = m_y;
 }
 
 void wxWindow::ClientToScreen( int *x, int *y )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   GdkWindow *source = (GdkWindow *) NULL;
   if (m_wxwindow)
     source = m_wxwindow->window;
@@ -1277,6 +1468,8 @@ void wxWindow::ClientToScreen( int *x, int *y )
 
 void wxWindow::ScreenToClient( int *x, int *y )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   GdkWindow *source = (GdkWindow *) NULL;
   if (m_wxwindow)
     source = m_wxwindow->window;
@@ -1302,6 +1495,8 @@ void wxWindow::ScreenToClient( int *x, int *y )
 
 void wxWindow::Centre( int direction )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (IS_KIND_OF(this,wxDialog) || IS_KIND_OF(this,wxFrame))
   {
     if (direction & wxHORIZONTAL == wxHORIZONTAL) m_x = (gdk_screen_width () - m_width) / 2;
@@ -1324,6 +1519,8 @@ void wxWindow::Centre( int direction )
 
 void wxWindow::Fit(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   int maxX = 0;
   int maxY = 0;
   wxNode *node = GetChildren()->First();
@@ -1345,6 +1542,8 @@ void wxWindow::Fit(void)
 
 void wxWindow::SetSizeHints( int minW, int minH, int maxW, int maxH, int WXUNUSED(incW), int WXUNUSED(incH) )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   m_minWidth = minW;
   m_minHeight = minH;
   m_maxWidth = maxW;
@@ -1358,6 +1557,8 @@ void wxWindow::OnSize( wxSizeEvent &WXUNUSED(event) )
 
 bool wxWindow::Show( bool show )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (show)
     gtk_widget_show( m_widget );
   else
@@ -1368,6 +1569,8 @@ bool wxWindow::Show( bool show )
 
 void wxWindow::Enable( bool enable )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   m_isEnabled = enable;
   gtk_widget_set_sensitive( m_widget, enable );
   if (m_wxwindow) gtk_widget_set_sensitive( m_wxwindow, enable );
@@ -1375,12 +1578,28 @@ void wxWindow::Enable( bool enable )
 
 int wxWindow::GetCharHeight(void) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  if (!m_font.Ok())
+  {
+    wxFAIL_MSG( "invalid font" );
+    return -1;
+  }
+  
   GdkFont *font = m_font.GetInternalFont( 1.0 );
   return font->ascent + font->descent;
 }
 
 int wxWindow::GetCharWidth(void) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  if (!m_font.Ok())
+  {
+    wxFAIL_MSG( "invalid font" );
+    return -1;
+  }
+  
   GdkFont *font = m_font.GetInternalFont( 1.0 );
   return gdk_string_width( font, "H" );
 }
@@ -1388,11 +1607,20 @@ int wxWindow::GetCharWidth(void) const
 void wxWindow::GetTextExtent( const wxString& string, int *x, int *y,
   int *descent, int *externalLeading, const wxFont *theFont, bool WXUNUSED(use16) ) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   wxFont fontToUse = m_font;
   if (theFont) fontToUse = *theFont;
   
+  if (!fontToUse.Ok())
+  {
+    wxFAIL_MSG( "invalid font" );
+    return;
+  }
+  wxASSERT_MSG( (m_font.Ok()), "invalid font" );
+  
   GdkFont *font = fontToUse.GetInternalFont( 1.0 );
-  if (x) (*y) = gdk_string_width( font, string );
+  if (x) (*x) = gdk_string_width( font, string );
   if (y) (*y) = font->ascent + font->descent;
   if (descent) (*descent) = font->descent;
   if (externalLeading) (*externalLeading) = 0;  // ??
@@ -1418,6 +1646,8 @@ void wxWindow::MakeModal( bool modal )
 
 void wxWindow::SetFocus(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   GtkWidget *connect_widget = GetConnectWidget();
   if (connect_widget)
   {
@@ -1435,6 +1665,11 @@ bool wxWindow::OnClose(void)
 
 void wxWindow::AddChild( wxWindow *child )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  wxASSERT_MSG( (m_wxwindow != NULL), "window need client area" );
+  wxASSERT_MSG( (child != NULL), "invalid child" );
+  wxASSERT_MSG( (child->m_widget != NULL), "invalid child" );
+  
   // Addchild is (often) called before the program
   // has left the parents constructor so that no
   // virtual tables work yet. The approach below
@@ -1507,7 +1742,7 @@ wxList *wxWindow::GetChildren(void)
 void wxWindow::RemoveChild( wxWindow *child )
 {
   if (GetChildren())
- GetChildren()->DeleteObject( child );
 GetChildren()->DeleteObject( child );
   child->m_parent = (wxWindow *) NULL;
 }
 
@@ -1523,11 +1758,15 @@ int wxWindow::GetReturnCode(void)
 
 void wxWindow::Raise(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (m_widget) gdk_window_raise( m_widget->window );
 }
 
 void wxWindow::Lower(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (m_widget) gdk_window_lower( m_widget->window );
 }
 
@@ -1543,28 +1782,28 @@ void wxWindow::SetEventHandler( wxEvtHandler *handler )
 
 void wxWindow::PushEventHandler(wxEvtHandler *handler)
 {
-       handler->SetNextHandler(GetEventHandler());
-       SetEventHandler(handler);
+  handler->SetNextHandler(GetEventHandler());
+  SetEventHandler(handler);
 }
 
 wxEvtHandler *wxWindow::PopEventHandler(bool deleteHandler)
 {
-       if ( GetEventHandler() )
-       {
-               wxEvtHandler *handlerA = GetEventHandler();
-               wxEvtHandler *handlerB = handlerA->GetNextHandler();
-               handlerA->SetNextHandler((wxEvtHandler *) NULL);
-               SetEventHandler(handlerB);
-               if ( deleteHandler )
-               {
-                       delete handlerA;
-                       return (wxEvtHandler *) NULL;
-               }
-               else
-                       return handlerA;
-       }
-       else
-               return (wxEvtHandler *) NULL;
+  if (GetEventHandler())
+  {
+    wxEvtHandler *handlerA = GetEventHandler();
+    wxEvtHandler *handlerB = handlerA->GetNextHandler();
+    handlerA->SetNextHandler((wxEvtHandler *) NULL);
+    SetEventHandler(handlerB);
+    if (deleteHandler)
+    {
+      delete handlerA;
+      return (wxEvtHandler*) NULL;
+    }
+    else
+      return handlerA;
+  }
+  else
+   return (wxEvtHandler *) NULL;
 }
 
 wxValidator *wxWindow::GetValidator(void)
@@ -1596,20 +1835,35 @@ wxWindowID wxWindow::GetId(void)
 
 void wxWindow::SetCursor( const wxCursor &cursor )
 {
-  wxASSERT(m_cursor != NULL);
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  if (m_cursor == NULL)
+  {
+    wxFAIL_MSG( "wxWindow::SetCursor m_cursor == NULL" );
+    m_cursor = new wxCursor( wxCURSOR_ARROW );
+  }
+    
+  if (cursor.Ok())
+  {
+    if (*((wxCursor*)&cursor) == m_cursor) return;
+    *m_cursor = cursor;
+  }
+  else
+  {
+    *m_cursor = *wxSTANDARD_CURSOR;
+  }
 
-  if (m_cursor != NULL)
-    if (*m_cursor == cursor)
-      return;
-  (*m_cursor) = cursor;
-  if (m_widget->window)
+  if ((m_widget) && (m_widget->window))
     gdk_window_set_cursor( m_widget->window, m_cursor->GetCursor() );
-  if (m_wxwindow && m_wxwindow->window)
+    
+  if ((m_wxwindow) && (m_wxwindow->window))
     gdk_window_set_cursor( m_wxwindow->window, m_cursor->GetCursor() );
 }
 
 void wxWindow::Refresh( bool eraseBackground, const wxRect *rect )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (eraseBackground && m_wxwindow && m_wxwindow->window)
   {
     if (rect)
@@ -1652,18 +1906,35 @@ void wxWindow::Refresh( bool eraseBackground, const wxRect *rect )
   }
 }
 
-bool wxWindow::IsExposed( long x, long y )
+wxRegion wxWindow::GetUpdateRegion() const
+{
+  return m_updateRegion;
+}
+
+bool wxWindow::IsExposed( int x, int y) const
 {
   return (m_updateRegion.Contains( x, y ) != wxOutRegion );
 }
 
-bool wxWindow::IsExposed( long x, long y, long width, long height )
+bool wxWindow::IsExposed( int x, int y, int w, int h ) const
 {
-  return (m_updateRegion.Contains( x, y, width, height ) != wxOutRegion );
+  return (m_updateRegion.Contains( x, y, w, h ) != wxOutRegion );
+}
+
+bool wxWindow::IsExposed( const wxPoint& pt ) const
+{
+  return (m_updateRegion.Contains( pt.x, pt.y ) != wxOutRegion );
+}
+
+bool wxWindow::IsExposed( const wxRect& rect ) const
+{
+  return (m_updateRegion.Contains( rect.x, rect.y, rect.width, rect.height ) != wxOutRegion );
 }
 
 void wxWindow::Clear(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   if (m_wxwindow && m_wxwindow->window) gdk_window_clear( m_wxwindow->window );
 }
 
@@ -1674,6 +1945,8 @@ wxColour wxWindow::GetBackgroundColour(void) const
 
 void wxWindow::SetBackgroundColour( const wxColour &colour )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   m_backgroundColour = colour;
   if (m_wxwindow)
   {
@@ -1696,6 +1969,8 @@ void wxWindow::SetForegroundColour( const wxColour &colour )
 
 bool wxWindow::Validate(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   wxNode *node = GetChildren()->First();
   while (node)
   {
@@ -1709,6 +1984,8 @@ bool wxWindow::Validate(void)
 
 bool wxWindow::TransferDataToWindow(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   wxNode *node = GetChildren()->First();
   while (node)
   {
@@ -1726,6 +2003,8 @@ bool wxWindow::TransferDataToWindow(void)
 
 bool wxWindow::TransferDataFromWindow(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   wxNode *node = GetChildren()->First();
   while (node)
   {
@@ -1737,6 +2016,11 @@ bool wxWindow::TransferDataFromWindow(void)
   return TRUE;
 }
 
+void wxWindow::SetAcceleratorTable( const wxAcceleratorTable& accel )
+{
+  m_acceleratorTable = accel;
+}
+
 void wxWindow::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
 {
   TransferDataToWindow();
@@ -1744,6 +2028,8 @@ void wxWindow::OnInitDialog( wxInitDialogEvent &WXUNUSED(event) )
 
 void wxWindow::InitDialog(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   wxInitDialogEvent event(GetId());
   event.SetEventObject( this );
   GetEventHandler()->ProcessEvent(event);
@@ -1764,6 +2050,8 @@ static void SetInvokingWindow( wxMenu *menu, wxWindow *win )
 
 bool wxWindow::PopupMenu( wxMenu *menu, int WXUNUSED(x), int WXUNUSED(y) )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   SetInvokingWindow( menu, this );
   gtk_menu_popup( GTK_MENU(menu->m_menu), (GtkWidget *) NULL, (GtkWidget *) NULL, (GtkMenuPositionFunc) NULL, NULL, 0, 0 );
   return TRUE;
@@ -1771,24 +2059,16 @@ bool wxWindow::PopupMenu( wxMenu *menu, int WXUNUSED(x), int WXUNUSED(y) )
 
 void wxWindow::SetDropTarget( wxDropTarget *dropTarget )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
   GtkWidget *dnd_widget = GetConnectWidget();
   
-  if (m_pDropTarget)
-  {
-    gtk_signal_disconnect_by_func( GTK_OBJECT(dnd_widget),
-      GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this );
+  DisconnectDnDWidget( dnd_widget );
   
-    m_pDropTarget->UnregisterWidget( dnd_widget );
-    delete m_pDropTarget;
-  }
+  if (m_pDropTarget) delete m_pDropTarget;
   m_pDropTarget = dropTarget;
-  if (m_pDropTarget)
-  {
-    m_pDropTarget->RegisterWidget( dnd_widget );
-    
-    gtk_signal_connect( GTK_OBJECT(dnd_widget), "drop_data_available_event",
-      GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this );
-  }
+  
+  ConnectDnDWidget( dnd_widget );
 }
 
 wxDropTarget *wxWindow::GetDropTarget() const
@@ -1796,6 +2076,26 @@ wxDropTarget *wxWindow::GetDropTarget() const
   return m_pDropTarget;
 }
 
+void wxWindow::ConnectDnDWidget( GtkWidget *widget )
+{
+  if (!m_pDropTarget) return;
+  
+  m_pDropTarget->RegisterWidget( widget );
+    
+  gtk_signal_connect( GTK_OBJECT(widget), "drop_data_available_event",
+    GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this );
+}
+
+void wxWindow::DisconnectDnDWidget( GtkWidget *widget )
+{
+  if (!m_pDropTarget) return;
+  
+  gtk_signal_disconnect_by_func( GTK_OBJECT(widget),
+    GTK_SIGNAL_FUNC(gtk_window_drop_callback), (gpointer)this );
+  
+  m_pDropTarget->UnregisterWidget( widget );
+}
+
 GtkWidget* wxWindow::GetConnectWidget(void)
 {
   GtkWidget *connect_widget = m_widget;
@@ -1812,16 +2112,28 @@ bool wxWindow::IsOwnGtkWindow( GdkWindow *window )
 
 void wxWindow::SetFont( const wxFont &font )
 {
-  m_font = font;
-/*
-  create new style
-  copy old style values to new one
-  set font in new style
-  -> takes to many resources
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
   
-  GtkStyle *style = gtk_style_new();
-  ...
-*/
+  if (((wxFont*)&font)->Ok())
+    m_font = font;
+  else
+    m_font = *wxSWISS_FONT;
+
+  GtkStyle *style = (GtkStyle*) NULL;
+  if (!m_hasOwnStyle)
+  {
+    m_hasOwnStyle = TRUE;
+    style = gtk_style_copy( gtk_widget_get_style( m_widget ) );
+  }
+  else
+  {
+    style = gtk_widget_get_style( m_widget );
+  }
+  
+  gdk_font_unref( style->font );
+  style->font = gdk_font_ref( m_font.GetInternalFont( 1.0 ) );
+  
+  gtk_widget_set_style( m_widget, style );
 }
 
 wxFont *wxWindow::GetFont(void)
@@ -1841,6 +2153,10 @@ long wxWindow::GetWindowStyleFlag(void) const
 
 void wxWindow::CaptureMouse(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  wxASSERT_MSG( (g_capturing == FALSE), "CaptureMouse called twice" );
+  
   GtkWidget *connect_widget = GetConnectWidget();
   gtk_grab_add( connect_widget );
   gdk_pointer_grab ( connect_widget->window, FALSE,
@@ -1849,13 +2165,19 @@ void wxWindow::CaptureMouse(void)
         GDK_BUTTON_RELEASE_MASK |
         GDK_POINTER_MOTION_MASK), 
         (GdkWindow *) NULL, (GdkCursor *) NULL, GDK_CURRENT_TIME );
+  g_capturing = TRUE;
 }
 
 void wxWindow::ReleaseMouse(void)
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  wxASSERT_MSG( (g_capturing == TRUE), "ReleaseMouse called twice" );
+  
   GtkWidget *connect_widget = GetConnectWidget();
   gtk_grab_remove( connect_widget );
   gdk_pointer_ungrab ( GDK_CURRENT_TIME );
+  g_capturing = FALSE;
 }
 
 void wxWindow::SetTitle( const wxString &WXUNUSED(title) )
@@ -1921,46 +2243,56 @@ wxWindow *wxWindow::FindWindow( const wxString& name )
 }
 
 void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible,
-      int range, bool WXUNUSED(refresh) )
+      int range, bool refresh )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" );
+  
   if (!m_wxwindow) return;
 
   if (orient == wxHORIZONTAL)
   {
     float fpos = (float)pos;
-    m_oldHorizontalPos = fpos;
     float frange = (float)range;
     float fthumb = (float)thumbVisible;
     
-    if ((fabs(fpos-m_hAdjust->value) < 0.2) &&
-        (fabs(frange-m_hAdjust->upper) < 0.2) &&
-  (fabs(fthumb-m_hAdjust->page_size) < 0.2))
+    if ((fabs(frange-m_hAdjust->upper) < 0.2) &&
+        (fabs(fthumb-m_hAdjust->page_size) < 0.2))
+    {
+      SetScrollPos( orient, pos, refresh );
       return;
+    }
       
+    m_oldHorizontalPos = fpos;
+    
     m_hAdjust->lower = 0.0;
     m_hAdjust->upper = frange;
     m_hAdjust->value = fpos;
     m_hAdjust->step_increment = 1.0;
-    m_hAdjust->page_increment = (float)(wxMax(fthumb-2,0));
+    m_hAdjust->page_increment = (float)(wxMax(fthumb,0));
     m_hAdjust->page_size = fthumb;
   }
   else
   {
     float fpos = (float)pos;
-    m_oldVerticalPos = fpos;
     float frange = (float)range;
     float fthumb = (float)thumbVisible;
     
-    if ((fabs(fpos-m_vAdjust->value) < 0.2) &&
-        (fabs(frange-m_vAdjust->upper) < 0.2) &&
-  (fabs(fthumb-m_vAdjust->page_size) < 0.2))
+    if ((fabs(frange-m_vAdjust->upper) < 0.2) &&
+        (fabs(fthumb-m_vAdjust->page_size) < 0.2))
+    {
+      SetScrollPos( orient, pos, refresh );
       return;
+    }
+    
+    m_oldVerticalPos = fpos;
       
     m_vAdjust->lower = 0.0;
     m_vAdjust->upper = frange;
     m_vAdjust->value = fpos;
     m_vAdjust->step_increment = 1.0;
-    m_vAdjust->page_increment = (float)(wxMax(fthumb-2,0));
+    m_vAdjust->page_increment = (float)(wxMax(fthumb,0));
     m_vAdjust->page_size = fthumb;
   }
   
@@ -1977,6 +2309,10 @@ void wxWindow::SetScrollbar( int orient, int pos, int thumbVisible,
 
 void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" );
+  
   if (!m_wxwindow) return;
   
   if (orient == wxHORIZONTAL)
@@ -1995,17 +2331,24 @@ void wxWindow::SetScrollPos( int orient, int pos, bool WXUNUSED(refresh) )
     m_vAdjust->value = fpos;
   }
   
-  if (m_wxwindow->window)
-  {  
-    if (orient == wxHORIZONTAL)
-      gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
-    else  
-      gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
+  if (!m_isScrolling)
+  {
+    if (m_wxwindow->window)
+    {  
+      if (orient == wxHORIZONTAL)
+        gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "value_changed" );
+      else  
+        gtk_signal_emit_by_name( GTK_OBJECT(m_vAdjust), "value_changed" );
+    }
   }
 }
 
 int wxWindow::GetScrollThumb( int orient ) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" );
+  
   if (!m_wxwindow) return 0;
 
   if (orient == wxHORIZONTAL)
@@ -2016,6 +2359,10 @@ int wxWindow::GetScrollThumb( int orient ) const
 
 int wxWindow::GetScrollPos( int orient ) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" );
+  
   if (!m_wxwindow) return 0;
 
   if (orient == wxHORIZONTAL)
@@ -2026,6 +2373,10 @@ int wxWindow::GetScrollPos( int orient ) const
 
 int wxWindow::GetScrollRange( int orient ) const
 {
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
+  
+  wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" );
+  
   if (!m_wxwindow) return 0;
 
   if (orient == wxHORIZONTAL)
@@ -2036,32 +2387,11 @@ int wxWindow::GetScrollRange( int orient ) const
 
 void wxWindow::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) )
 {
-  if (!m_wxwindow) return;
+  wxASSERT_MSG( (m_widget != NULL), "invalid window" );
   
-/*
-  bool refresh = FALSE;
-    
-  if ((m_drawingOffsetX == 0) && (m_drawingOffsetY == 0))
-  {
-    m_drawingOffsetX = -16000;
-    m_drawingOffsetY = -16000;
-    refresh = TRUE;
-  }
-  else
-  {
-    m_drawingOffsetX += dx;
-    m_drawingOffsetY += dy;
-  }
+  wxASSERT_MSG( (m_wxwindow != NULL), "window needs client area" );
   
-//  printf( "X: %d  Y: %d  \n", (int)m_drawingOffsetX, (int)m_drawingOffsetY );
-  
-  gtk_myfixed_set_offset( GTK_MYFIXED(m_wxwindow), m_drawingOffsetX, m_drawingOffsetY );
-  
-  if (refresh) Refresh();
-  
-    The code here is very nifty, but it doesn't work with
-    overlapping windows...
-*/
+  if (!m_wxwindow) return;
 
     int cw = 0;
     int ch = 0;