]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/window.cpp
wxSize/wxPoint/wxRect versions of functions added to wxMSW, wxMotif;
[wxWidgets.git] / src / gtk / window.cpp
index 95aa2af173630ab7c5c609deea4e4c25ff71242b..e452bbd119c19260d305a4d1beb658c582712504 100644 (file)
 
 */
 
+//-------------------------------------------------------------------------
+// conditional compilation
+//-------------------------------------------------------------------------
+
+#if (GTK_MINOR_VERSION == 1)
+#if (GTK_MICRO_VERSION >= 5)
+#define NEW_GTK_SCROLL_CODE
+#endif
+#endif
+
 //-----------------------------------------------------------------------------
 // data
 //-----------------------------------------------------------------------------
 extern wxList wxPendingDelete;
 extern wxList wxTopLevelWindows;
 extern bool   g_blockEventsOnDrag;
+extern bool   g_blockEventsOnScroll;
 static bool   g_capturing = FALSE;
 
 // hack: we need something to pass to gtk_menu_popup, so we store the time of
@@ -312,6 +323,7 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton
     if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
 
     if (g_blockEventsOnDrag) return TRUE;
+    if (g_blockEventsOnScroll) return TRUE;
 
     if (win->m_wxwindow)
     {
@@ -422,6 +434,7 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto
     if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
 
     if (g_blockEventsOnDrag) return TRUE;
+    if (g_blockEventsOnScroll) return TRUE;
 
     if (!win->HasVMT()) return TRUE;
 
@@ -492,7 +505,8 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion
     if (!win->IsOwnGtkWindow( gdk_event->window )) return TRUE;
 
     if (g_blockEventsOnDrag) return TRUE;
-
+    if (g_blockEventsOnScroll) return TRUE;
+    
     if (!win->HasVMT()) return TRUE;
 
 /*
@@ -704,13 +718,20 @@ static void gtk_window_vscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *
     float line_step = win->m_vAdjust->step_increment;
     float page_step = win->m_vAdjust->page_increment;
 
-    if (fabs(win->m_vAdjust->value-win->m_vAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM;
-    else if (fabs(win->m_vAdjust->value-win->m_vAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP;
-    else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
-    else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
-    else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
-    else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
-    else command = wxEVT_SCROLL_THUMBTRACK;
+    if (win->m_isScrolling)
+    {
+        command = wxEVT_SCROLL_THUMBTRACK;
+    }
+    else
+    {
+        if (fabs(win->m_vAdjust->value-win->m_vAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM;
+        else if (fabs(win->m_vAdjust->value-win->m_vAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP;
+        else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
+        else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
+        else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
+        else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
+        else command = wxEVT_SCROLL_THUMBTRACK;
+    }
 
     int value = (int)(win->m_vAdjust->value+0.5);
 
@@ -744,13 +765,20 @@ static void gtk_window_hscroll_callback( GtkWidget *WXUNUSED(widget), wxWindow *
     float line_step = win->m_hAdjust->step_increment;
     float page_step = win->m_hAdjust->page_increment;
     
-    if (fabs(win->m_hAdjust->value-win->m_hAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM;
-    else if (fabs(win->m_hAdjust->value-win->m_hAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP;
-    else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
-    else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
-    else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
-    else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
-    else command = wxEVT_SCROLL_THUMBTRACK;
+    if (win->m_isScrolling)
+    {
+        command = wxEVT_SCROLL_THUMBTRACK;
+    }
+    else
+    {
+        if (fabs(win->m_hAdjust->value-win->m_hAdjust->lower) < 0.2) command = wxEVT_SCROLL_BOTTOM;
+        else if (fabs(win->m_hAdjust->value-win->m_hAdjust->upper) < 0.2) command = wxEVT_SCROLL_TOP;
+        else if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
+        else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
+        else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
+        else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
+        else command = wxEVT_SCROLL_THUMBTRACK;
+    }
 
     int value = (int)(win->m_hAdjust->value+0.5);
 
@@ -813,11 +841,14 @@ static void gtk_window_hscroll_change_callback( GtkWidget *WXUNUSED(widget), wxW
 // "button_press_event" from scrollbar
 //-----------------------------------------------------------------------------
 
-static gint gtk_scrollbar_button_press_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win )
+static gint gtk_scrollbar_button_press_callback( GtkRange *WXUNUSED(widget), 
+                                                 GdkEventButton *WXUNUSED(gdk_event), 
+                                                wxWindow *win )
 {
-    if (gdk_event->window != widget->slider) return FALSE;
-
+//    if (gdk_event->window != widget->slider) return FALSE;
+    
     win->m_isScrolling = TRUE;
+    g_blockEventsOnScroll = TRUE;
 
     return FALSE;
 }
@@ -826,9 +857,15 @@ static gint gtk_scrollbar_button_press_callback( GtkRange *widget, GdkEventButto
 // "button_release_event" from scrollbar
 //-----------------------------------------------------------------------------
 
-static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventButton *gdk_event, wxWindow *win )
+static gint gtk_scrollbar_button_release_callback( GtkRange *widget, 
+                                                   GdkEventButton *WXUNUSED(gdk_event), 
+                                                  wxWindow *win )
 {
-    if (gdk_event->window != widget->slider) return FALSE;
+
+//  don't test here as we can reelase the mouse while being over
+//  a different window then the slider
+//
+//    if (gdk_event->window != widget->slider) return FALSE;
 
     GtkScrolledWindow *s_window = GTK_SCROLLED_WINDOW(win->m_widget);
 
@@ -838,6 +875,7 @@ static gint gtk_scrollbar_button_release_callback( GtkRange *widget, GdkEventBut
         gtk_signal_emit_by_name( GTK_OBJECT(win->m_vAdjust), "value_changed" );
 
     win->m_isScrolling = FALSE;
+    g_blockEventsOnScroll = FALSE;
 
     return FALSE;
 }
@@ -956,21 +994,10 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
     PreCreation( parent, id, pos, size, style, name );
 
     m_widget = gtk_scrolled_window_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
+    GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
 
     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;
 
@@ -982,17 +1009,15 @@ 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",
-          (GtkSignalFunc) gtk_window_hscroll_callback, (gpointer) this );
-    gtk_signal_connect( GTK_OBJECT(m_vAdjust), "value_changed",
-          (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
-
-    gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed",
-          (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this );
-    gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed",
-          (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this );
+    m_wxwindow = gtk_myfixed_new();
 
+#ifdef NEW_GTK_SCROLL_CODE
+    gtk_scrolled_window_add_with_viewport( GTK_SCROLLED_WINDOW(m_widget), m_wxwindow );
+    GtkViewport *viewport = GTK_VIEWPORT(s_window->child);
+#else
+    gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
     GtkViewport *viewport = GTK_VIEWPORT(s_window->viewport);
+#endif
 
     if (m_windowStyle & wxRAISED_BORDER)
     {
@@ -1007,17 +1032,11 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
         gtk_viewport_set_shadow_type( viewport, GTK_SHADOW_NONE );
     }
 
-    m_wxwindow = gtk_myfixed_new();
-
-    GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
-
     if (m_windowStyle & wxTAB_TRAVERSAL == wxTAB_TRAVERSAL)
         GTK_WIDGET_UNSET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
     else
         GTK_WIDGET_SET_FLAGS( m_wxwindow, GTK_CAN_FOCUS );
 
-    gtk_container_add( GTK_CONTAINER(m_widget), m_wxwindow );
-
     // shut the viewport up
     gtk_viewport_set_hadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
     gtk_viewport_set_vadjustment( viewport, (GtkAdjustment*) gtk_adjustment_new( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0) );
@@ -1038,6 +1057,36 @@ bool wxWindow::Create( wxWindow *parent, wxWindowID id,
     m_hAdjust->page_size = 5.0;
     gtk_signal_emit_by_name( GTK_OBJECT(m_hAdjust), "changed" );
 
+    // these handlers block mouse events to any window during scrolling
+    // such as motion events and prevent GTK and wxWindows from fighting
+    // over where the slider should be
+    
+    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 );
+         
+    // these handers het notified when screen updates are required either when
+    // scrolling or when the window size (and therefore scrollbar configuration)
+    // has 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",
+          (GtkSignalFunc) gtk_window_vscroll_callback, (gpointer) this );
+
+    gtk_signal_connect( GTK_OBJECT(m_hAdjust), "changed",
+          (GtkSignalFunc) gtk_window_hscroll_change_callback, (gpointer) this );
+    gtk_signal_connect(GTK_OBJECT(m_vAdjust), "changed",
+          (GtkSignalFunc) gtk_window_vscroll_change_callback, (gpointer) this );
+
     gtk_widget_show( m_wxwindow );
   
     if (m_parent) m_parent->AddChild( this );
@@ -1069,7 +1118,7 @@ wxWindow::~wxWindow()
     if (m_wxwindow) gtk_widget_destroy( m_wxwindow );
 
     if (m_widget) gtk_widget_destroy( m_widget );
-
+    
     if (m_cursor) delete m_cursor;
 
     DeleteRelatedConstraints();
@@ -1302,56 +1351,64 @@ void wxWindow::SetSize( int x, int y, int width, int height, int sizeFlags )
     wxASSERT_MSG( (m_widget != NULL), "invalid window" );
     wxASSERT_MSG( (m_parent != NULL), "wxWindow::SetSize requires parent.\n" );
   
-    // Don't do anything for children of wxNotebook
-    if (m_parent->m_wxwindow == NULL) return;
-
     if (m_resizing) return; // I don't like recursions
     m_resizing = TRUE;
 
-    int old_width = m_width;
-    int old_height = m_height;
-  
-    if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING)
-    {
-        if (x != -1) m_x = x;
-        if (y != -1) m_y = y;
-        if (width != -1) m_width = width;
-        if (height != -1) m_height = height;
-    }
-    else
+    if (m_parent->m_wxwindow == NULL) // i.e. wxNotebook
     {
+        // don't set the size for children of wxNotebook, just take the values.
         m_x = x;
         m_y = y;
         m_width = width;
-       m_height = height;
+        m_height = height;
     }
-
-    if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
+    else
     {
-        if (width == -1) m_width = 80;
-    }
+        int old_width = m_width;
+        int old_height = m_height;
+  
+        if ((sizeFlags & wxSIZE_USE_EXISTING) == wxSIZE_USE_EXISTING)
+        {
+            if (x != -1) m_x = x;
+            if (y != -1) m_y = y;
+            if (width != -1) m_width = width;
+            if (height != -1) m_height = height;
+        }
+        else
+        {
+            m_x = x;
+            m_y = y;
+            m_width = width;
+            m_height = height;
+        }
 
-    if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
-    {
-        if (height == -1) m_height = 26;
-    }
+        if ((sizeFlags & wxSIZE_AUTO_WIDTH) == wxSIZE_AUTO_WIDTH)
+        {
+             if (width == -1) m_width = 80;
+        }
+
+        if ((sizeFlags & wxSIZE_AUTO_HEIGHT) == wxSIZE_AUTO_HEIGHT)
+        {
+             if (height == -1) m_height = 26;
+        }
   
-    if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
-    if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
-    if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth;
-    if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight;
+        if ((m_minWidth != -1) && (m_width < m_minWidth)) m_width = m_minWidth;
+        if ((m_minHeight != -1) && (m_height < m_minHeight)) m_height = m_minHeight;
+        if ((m_maxWidth != -1) && (m_width > m_maxWidth)) m_width = m_minWidth;
+        if ((m_maxHeight != -1) && (m_height > m_maxHeight)) m_height = m_minHeight;
 
-    wxPoint pt( m_parent->GetClientAreaOrigin() );
-    gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x+pt.x, m_y+pt.y );
+        wxPoint pt( m_parent->GetClientAreaOrigin() );
+        gtk_myfixed_move( GTK_MYFIXED(m_parent->m_wxwindow), m_widget, m_x+pt.x, m_y+pt.y );
   
-    if ((old_width != m_width) || (old_height != m_height))
-        gtk_widget_set_usize( m_widget, m_width, m_height );
+        if ((old_width != m_width) || (old_height != m_height))
+             gtk_widget_set_usize( m_widget, m_width, m_height );
+    }
   
     m_sizeSet = TRUE;
 
     wxSizeEvent event( wxSize(m_width,m_height), GetId() );
     event.SetEventObject( this );
-    ProcessEvent( event );
+    GetEventHandler()->ProcessEvent( event );
 
     m_resizing = FALSE;
 }
@@ -1403,7 +1460,12 @@ void wxWindow::SetClientSize( int width, int height )
       GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
       GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
 
+#ifdef NEW_GTK_SCROLL_CODE
+      GtkWidget *viewport = scroll_window->child;
+#else      
       GtkWidget *viewport = scroll_window->viewport;
+#endif
+
       GtkStyleClass *viewport_class = viewport->style->klass;
 
       GtkWidget *hscrollbar = scroll_window->hscrollbar;
@@ -1463,7 +1525,12 @@ void wxWindow::GetClientSize( int *width, int *height ) const
       GtkScrolledWindow *scroll_window = GTK_SCROLLED_WINDOW(m_widget);
       GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT(m_widget)->klass );
 
+#ifdef NEW_GTK_SCROLL_CODE
+      GtkWidget *viewport = scroll_window->child;
+#else      
       GtkWidget *viewport = scroll_window->viewport;
+#endif
+
       GtkStyleClass *viewport_class = viewport->style->klass;
 
       GtkWidget *hscrollbar = scroll_window->hscrollbar;