]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/window.cpp
Committing in .
[wxWidgets.git] / src / gtk / window.cpp
index efc124ac8dd7ad236dd2da336a9ebc5d3b121681..bad1ac7648dc2979e3853ff25e6360699017729e 100644 (file)
@@ -270,43 +270,6 @@ extern bool g_mainThreadLocked;
 #else
 #   define DEBUG_MAIN_THREAD
 #endif
 #else
 #   define DEBUG_MAIN_THREAD
 #endif
-
-static gint gtk_debug_focus_in_callback( GtkWidget *WXUNUSED(widget),
-                                         GdkEvent *WXUNUSED(event),
-                                         const wxChar *WXUNUSED(name) )
-{
-/*
-    static bool s_done = FALSE;
-    if ( !s_done )
-    {
-        wxLog::AddTraceMask("focus");
-        s_done = TRUE;
-    }
-    wxLogTrace(wxT("FOCUS NOW AT: %s"), name);
-*/
-
-    return FALSE;
-}
-
-void debug_focus_in( GtkWidget* widget, const wxChar* name, const wxChar *window )
-{
-    // suppress warnings about gtk_debug_focus_in_callback being unused with
-    // this "if ( 0 )"
-    if ( 0 )
-    {
-        wxString tmp = name;
-        tmp += wxT(" FROM ");
-        tmp += window;
-
-        wxChar *s = new wxChar[tmp.Length()+1];
-
-        wxStrcpy( s, tmp );
-
-        gtk_signal_connect( GTK_OBJECT(widget), "focus_in_event",
-          GTK_SIGNAL_FUNC(gtk_debug_focus_in_callback), (gpointer)s );
-    }
-}
-
 #else
 #define DEBUG_MAIN_THREAD
 #endif // Debug
 #else
 #define DEBUG_MAIN_THREAD
 #endif // Debug
@@ -385,15 +348,6 @@ wxWindow *wxFindFocusedChild(wxWindowGTK *win)
     return (wxWindow *)NULL;
 }
 
     return (wxWindow *)NULL;
 }
 
-// Returns toplevel grandparent of given window:
-static wxWindowGTK* wxGetTopLevelParent(wxWindowGTK *win)
-{
-    wxWindowGTK *p = win;
-    while (p && !p->IsTopLevel())
-         p = p->GetParent();
-    return p;
-}
-
 static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
 {
     // wxUniversal widgets draw the borders and scrollbars themselves
 static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
 {
     // wxUniversal widgets draw the borders and scrollbars themselves
@@ -551,35 +505,13 @@ static int gtk_window_expose_callback( GtkWidget *widget,
     }
 #endif
 
     }
 #endif
 
-#ifndef __WXUNIVERSAL__
-    GtkPizza *pizza = GTK_PIZZA (widget);
-
-    if (win->GetThemeEnabled())
-    {
-        wxWindow *parent = win->GetParent();
-        while (parent && !parent->IsTopLevel())
-            parent = parent->GetParent();
-        if (!parent)
-            parent = win;
-
-        gtk_paint_flat_box (parent->m_widget->style,
-                            pizza->bin_window,
-                            GTK_STATE_NORMAL,
-                            GTK_SHADOW_NONE,
-                            &gdk_event->area,
-                            parent->m_widget,
-                            (char *)"base",
-                            0, 0, -1, -1);
-    }
-#endif
-
     win->GetUpdateRegion().Union( gdk_event->area.x,
                                   gdk_event->area.y,
                                   gdk_event->area.width,
                                   gdk_event->area.height );
 
     // Actual redrawing takes place in idle time.
     win->GetUpdateRegion().Union( gdk_event->area.x,
                                   gdk_event->area.y,
                                   gdk_event->area.width,
                                   gdk_event->area.height );
 
     // Actual redrawing takes place in idle time.
-    win->Update();
+    win->GtkUpdate();
 
 #ifdef __WXGTK20__
 
 
 #ifdef __WXGTK20__
 
@@ -686,7 +618,7 @@ static void gtk_window_draw_callback( GtkWidget *widget,
 
     // Actual redrawing takes place in idle time.
 
 
     // Actual redrawing takes place in idle time.
 
-    win->Update();
+    win->GtkUpdate();
 
 #ifndef __WXUNIVERSAL__
     // Redraw child widgets
 
 #ifndef __WXUNIVERSAL__
     // Redraw child widgets
@@ -1771,6 +1703,21 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget,
 // "focus_in_event"
 //-----------------------------------------------------------------------------
 
 // "focus_in_event"
 //-----------------------------------------------------------------------------
 
+// send the wxChildFocusEvent and wxFocusEvent, common code of
+// gtk_window_focus_in_callback() and SetFocus()
+static bool DoSendFocusEvents(wxWindow *win)
+{
+    // Notify the parent keeping track of focus for the kbd navigation
+    // purposes that we got it.
+    wxChildFocusEvent eventChildFocus(win);
+    (void)win->GetEventHandler()->ProcessEvent(eventChildFocus);
+
+    wxFocusEvent eventFocus(wxEVT_SET_FOCUS, win->GetId());
+    eventFocus.SetEventObject(win);
+
+    return win->GetEventHandler()->ProcessEvent(eventFocus);
+}
+
 static gint gtk_window_focus_in_callback( GtkWidget *widget,
                                           GdkEvent *WXUNUSED(event),
                                           wxWindow *win )
 static gint gtk_window_focus_in_callback( GtkWidget *widget,
                                           GdkEvent *WXUNUSED(event),
                                           wxWindow *win )
@@ -1804,11 +1751,6 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
     printf( "OnSetFocus 2 from %s\n", win->GetName().c_str() );
 #endif
 
     printf( "OnSetFocus 2 from %s\n", win->GetName().c_str() );
 #endif
 
-    // Notify the parent keeping track of focus for the kbd navigation
-    // purposes that we got it.
-    wxChildFocusEvent eventFocus(win);
-    (void)win->GetEventHandler()->ProcessEvent(eventFocus);
-
 #ifdef HAVE_XIM
     if (win->m_ic)
         gdk_im_begin(win->m_ic, win->m_wxwindow->window);
 #ifdef HAVE_XIM
     if (win->m_ic)
         gdk_im_begin(win->m_ic, win->m_wxwindow->window);
@@ -1847,11 +1789,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget,
         //    return TRUE;
     }
 
         //    return TRUE;
     }
 
-
-    wxFocusEvent event( wxEVT_SET_FOCUS, win->GetId() );
-    event.SetEventObject( win );
-
-    if (win->GetEventHandler()->ProcessEvent( event ))
+    if ( DoSendFocusEvents(win) )
     {
        gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" );
        return TRUE;
     {
        gtk_signal_emit_stop_by_name( GTK_OBJECT(widget), "focus_in_event" );
        return TRUE;
@@ -2037,7 +1975,8 @@ static void gtk_window_vscroll_callback( GtkAdjustment *adjust,
 
     win->m_oldVerticalPos = adjust->value;
 
 
     win->m_oldVerticalPos = adjust->value;
 
-    wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(win->m_widget));
+    GtkScrolledWindow   *sw = GTK_SCROLLED_WINDOW(win->m_widget);
+    wxEventType         command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw->vscrollbar));
 
     int value = (int)(adjust->value+0.5);
 
 
     int value = (int)(adjust->value+0.5);
 
@@ -2065,7 +2004,8 @@ static void gtk_window_hscroll_callback( GtkAdjustment *adjust,
     float diff = adjust->value - win->m_oldHorizontalPos;
     if (fabs(diff) < 0.2) return;
 
     float diff = adjust->value - win->m_oldHorizontalPos;
     if (fabs(diff) < 0.2) return;
 
-    wxEventType command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(win->m_widget));
+    GtkScrolledWindow   *sw = GTK_SCROLLED_WINDOW(win->m_widget);
+    wxEventType         command = GtkScrollWinTypeToWx(GET_SCROLL_TYPE(sw->hscrollbar));
 
     win->m_oldHorizontalPos = adjust->value;
 
 
     win->m_oldHorizontalPos = adjust->value;
 
@@ -2586,6 +2526,9 @@ wxWindowGTK::~wxWindowGTK()
     if (g_activeFrame == this)
         g_activeFrame = NULL;
 
     if (g_activeFrame == this)
         g_activeFrame = NULL;
 
+    if ( g_delayedFocus == this )
+        g_delayedFocus = NULL;
+
     m_isBeingDeleted = TRUE;
     m_hasVMT = FALSE;
 
     m_isBeingDeleted = TRUE;
     m_hasVMT = FALSE;
 
@@ -2902,7 +2845,7 @@ void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags
 void wxWindowGTK::OnInternalIdle()
 {
     // Update invalidated regions.
 void wxWindowGTK::OnInternalIdle()
 {
     // Update invalidated regions.
-    Update();
+    GtkUpdate();
 
     // Synthetize activate events.
     if ( g_sendActivateEvent != -1 )
 
     // Synthetize activate events.
     if ( g_sendActivateEvent != -1 )
@@ -2928,15 +2871,6 @@ void wxWindowGTK::OnInternalIdle()
         g_activeFrameLostFocus = FALSE;
     }
     
         g_activeFrameLostFocus = FALSE;
     }
     
-    if (g_delayedFocus == this)
-    {
-        if (GTK_WIDGET_REALIZED(m_widget))
-        {
-            gtk_widget_grab_focus( m_widget );
-            g_delayedFocus = NULL;
-        }
-    }
-
     wxCursor cursor = m_cursor;
     if (g_globalCursor.Ok()) cursor = g_globalCursor;
 
     wxCursor cursor = m_cursor;
     if (g_globalCursor.Ok()) cursor = g_globalCursor;
 
@@ -3303,9 +3237,21 @@ void wxWindowGTK::SetFocus()
         if (GTK_WIDGET_CAN_FOCUS(m_widget) && !GTK_WIDGET_HAS_FOCUS (m_widget) )
         {
             if (!GTK_WIDGET_REALIZED(m_widget))
         if (GTK_WIDGET_CAN_FOCUS(m_widget) && !GTK_WIDGET_HAS_FOCUS (m_widget) )
         {
             if (!GTK_WIDGET_REALIZED(m_widget))
+            {
+                wxLogTrace(_T("focus"),
+                           _T("Delaying setting focus to %s(%s)\n"),
+                           GetClassInfo()->GetClassName(), GetLabel().c_str());
+
                 g_delayedFocus = this;
                 g_delayedFocus = this;
+            }
             else
             else
+            {
+                wxLogTrace(_T("focus"),
+                           _T("Setting focus to %s(%s)\n"),
+                           GetClassInfo()->GetClassName(), GetLabel().c_str());
+
                 gtk_widget_grab_focus (m_widget);
                 gtk_widget_grab_focus (m_widget);
+            }
         }
         else if (GTK_IS_CONTAINER(m_widget))
         {
         }
         else if (GTK_IS_CONTAINER(m_widget))
         {
@@ -3316,6 +3262,8 @@ void wxWindowGTK::SetFocus()
            // ?
         }
     }
            // ?
         }
     }
+
+    (void)DoSendFocusEvents((wxWindow*)this);
 }
 
 bool wxWindowGTK::AcceptsFocus() const
 }
 
 bool wxWindowGTK::AcceptsFocus() const
@@ -3500,6 +3448,11 @@ void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect )
 }
 
 void wxWindowGTK::Update()
 }
 
 void wxWindowGTK::Update()
+{
+    GtkUpdate();
+}
+
+void wxWindowGTK::GtkUpdate()
 {
 #ifdef __WXGTK20__
     if (m_wxwindow && GTK_PIZZA(m_wxwindow)->bin_window)
 {
 #ifdef __WXGTK20__
     if (m_wxwindow && GTK_PIZZA(m_wxwindow)->bin_window)
@@ -3519,8 +3472,43 @@ void wxWindowGTK::GtkSendPaintEvents()
         return;
     }
 
         return;
     }
 
+    // widget to draw on
+    GtkPizza *pizza = GTK_PIZZA (m_wxwindow);
+            
+    // Clip to paint region in wxClientDC
     m_clipPaintRegion = TRUE;
     
     m_clipPaintRegion = TRUE;
     
+    if (GetThemeEnabled())
+    {
+        // find ancestor from which to steal background
+        wxWindow *parent = GetParent();
+        while (parent && !parent->IsTopLevel())
+            parent = parent->GetParent();
+        if (!parent)
+            parent = (wxWindow*)this;
+    
+        wxRegionIterator upd( m_updateRegion );
+        while (upd)
+        {
+            GdkRectangle rect;
+            rect.x = upd.GetX();
+            rect.y = upd.GetY();
+            rect.width = upd.GetWidth();
+            rect.height = upd.GetHeight();
+                    
+            gtk_paint_flat_box( parent->m_widget->style,
+                        pizza->bin_window,
+                        GTK_STATE_NORMAL,
+                        GTK_SHADOW_NONE,
+                        &rect,
+                        parent->m_widget,
+                        (char *)"base",
+                        0, 0, -1, -1 );
+                        
+            upd ++;
+        }
+    }
+    else
     // if (!m_clearRegion.IsEmpty())   // always send an erase event
     {
         wxWindowDC dc( (wxWindow*)this );
     // if (!m_clearRegion.IsEmpty())   // always send an erase event
     {
         wxWindowDC dc( (wxWindow*)this );
@@ -3533,7 +3521,7 @@ void wxWindowGTK::GtkSendPaintEvents()
         {
             if (!g_eraseGC)
             {
         {
             if (!g_eraseGC)
             {
-                g_eraseGC = gdk_gc_new( GTK_PIZZA(m_wxwindow)->bin_window );
+                g_eraseGC = gdk_gc_new( pizza->bin_window );
                 gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
             }
             gdk_gc_set_foreground( g_eraseGC, m_backgroundColour.GetColor() );
                 gdk_gc_set_fill( g_eraseGC, GDK_SOLID );
             }
             gdk_gc_set_foreground( g_eraseGC, m_backgroundColour.GetColor() );
@@ -3541,8 +3529,8 @@ void wxWindowGTK::GtkSendPaintEvents()
             wxRegionIterator upd( m_clearRegion );
             while (upd)
             {
             wxRegionIterator upd( m_clearRegion );
             while (upd)
             {
-                gdk_draw_rectangle( GTK_PIZZA(m_wxwindow)->bin_window, g_eraseGC, 1,
-                                       upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
+                gdk_draw_rectangle( pizza->bin_window, g_eraseGC, 1,
+                                    upd.GetX(), upd.GetY(), upd.GetWidth(), upd.GetHeight() );
                 upd ++;
             }
         }
                 upd ++;
             }
         }
@@ -3565,8 +3553,6 @@ void wxWindowGTK::GtkSendPaintEvents()
     // being redrawn because the wxWindows class is allowed to
     // paint over the window-less widgets.
 
     // being redrawn because the wxWindows class is allowed to
     // paint over the window-less widgets.
 
-    GtkPizza *pizza = GTK_PIZZA(m_wxwindow);
-
     GList *children = pizza->children;
     while (children)
     {
     GList *children = pizza->children;
     while (children)
     {
@@ -3619,7 +3605,7 @@ void wxWindowGTK::Clear()
         m_clearRegion.Union( 0,0,size.x,size.y );
         
         // Better do this in idle?
         m_clearRegion.Union( 0,0,size.x,size.y );
         
         // Better do this in idle?
-        Update();
+        GtkUpdate();
     }
 }
 
     }
 }
 
@@ -3651,12 +3637,9 @@ void wxWindowGTK::GtkSetBackgroundColour( const wxColour &colour )
     // We need the pixel value e.g. for background clearing.
     m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
     
     // We need the pixel value e.g. for background clearing.
     m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
     
-    if ((m_wxwindow) &&
-        (m_backgroundColour != wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)))
+    if (m_wxwindow)
     {
     {
-        /* wxMSW doesn't clear the window here. I don't do that either to
-          provide compatibility. call Clear() to do the job. */
-
+        // wxMSW doesn't clear the window here, either.
         gdk_window_set_background( window, m_backgroundColour.GetColor() );
     }
 
         gdk_window_set_background( window, m_backgroundColour.GetColor() );
     }
 
@@ -4347,3 +4330,4 @@ void wxWinModule::OnExit()
         gdk_gc_unref( g_eraseGC );
 }
 
         gdk_gc_unref( g_eraseGC );
 }
 
+// vi:sts=4:sw=4:et