]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/window.cpp
fixed all the other ports broken by controls labels in wxToolBar patch commit
[wxWidgets.git] / src / gtk / window.cpp
index de71af2416030ed5a1696935d192bfd86af2c668..724b780866709218f4a4e673052b8f1cd98ed478 100644 (file)
@@ -210,6 +210,11 @@ wxWindowGTK *g_focusWindowLast = (wxWindowGTK*) NULL;
 // yet, defer setting the focus to idle time.
 wxWindowGTK *g_delayedFocus = (wxWindowGTK*) NULL;
 
+// global variables because GTK+ DnD want to have the
+// mouse event that caused it
+GdkEvent    *g_lastMouseEvent = (GdkEvent*) NULL;
+int          g_lastButtonNumber = 0;
+
 extern bool g_mainThreadLocked;
 
 //-----------------------------------------------------------------------------
@@ -326,13 +331,13 @@ static void draw_frame( GtkWidget *widget, wxWindowGTK *win )
 
     int x = dx;
     int y = dy;
-    
+
     int dw = 0;
     int dh = 0;
     if (win->m_hasScrolling)
     {
         GetScrollbarWidth(widget, dw, dh);
-        
+
         if (win->GetLayoutDirection() == wxLayout_RightToLeft)
         {
             // This is actually wrong for old GTK+ version
@@ -446,7 +451,7 @@ void wxgtk_combo_size_request_callback(GtkWidget *widget,
     button_req.height = 2;
     (* GTK_WIDGET_CLASS( GTK_OBJECT_GET_CLASS(gcombo->button) )->size_request )
         (gcombo->button, &button_req );
-        
+
     requisition->width = w - button_req.width;
     requisition->height = entry_req.height;
 }
@@ -1153,7 +1158,7 @@ gtk_wxwindow_commit_cb (GtkIMContext *context,
                                   window, window->m_imData->lastKeyEvent);
     }
 
-    const wxWxCharBuffer data(wxGTK_CONV_BACK(str));
+    const wxWxCharBuffer data(wxGTK_CONV_BACK_SYS(str));
     if( !data )
         return;
 
@@ -1272,7 +1277,7 @@ template<typename T> void InitMouseEvent(wxWindowGTK *win,
     wxPoint pt = win->GetClientAreaOrigin();
     event.m_x = (wxCoord)gdk_event->x - pt.x;
     event.m_y = (wxCoord)gdk_event->y - pt.y;
-    
+
     if ((win->m_wxwindow) && (win->GetLayoutDirection() == wxLayout_RightToLeft))
     {
         // origin in the upper right corner
@@ -1462,6 +1467,8 @@ gtk_window_button_press_callback( GtkWidget *widget,
 {
     wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win);
 
+    g_lastButtonNumber = gdk_event->button;
+
     if (win->m_wxwindow && (g_focusWindow != win) && win->AcceptsFocus())
     {
         gtk_widget_grab_focus( win->m_wxwindow );
@@ -1578,6 +1585,8 @@ gtk_window_button_press_callback( GtkWidget *widget,
         return FALSE;
     }
 
+    g_lastMouseEvent = (GdkEvent*) gdk_event;
+
     wxMouseEvent event( event_type );
     InitMouseEvent( win, event, gdk_event );
 
@@ -1597,10 +1606,10 @@ gtk_window_button_press_callback( GtkWidget *widget,
     event.SetEventObject( win );
     event.SetId( win->GetId() );
 
-    if (win->GTKProcessEvent( event ))
-    {
+    bool ret = win->GTKProcessEvent( event );
+    g_lastMouseEvent = NULL;
+    if ( ret )
         return TRUE;
-    }
 
     if (event_type == wxEVT_RIGHT_DOWN)
     {
@@ -1633,6 +1642,8 @@ gtk_window_button_release_callback( GtkWidget *widget,
 {
     wxCOMMON_CALLBACK_PROLOGUE(gdk_event, win);
 
+    g_lastButtonNumber = 0;
+
     wxEventType event_type = wxEVT_NULL;
 
     switch (gdk_event->button)
@@ -1654,6 +1665,8 @@ gtk_window_button_release_callback( GtkWidget *widget,
             return FALSE;
     }
 
+    g_lastMouseEvent = (GdkEvent*) gdk_event;
+
     wxMouseEvent event( event_type );
     InitMouseEvent( win, event, gdk_event );
 
@@ -1669,7 +1682,11 @@ gtk_window_button_release_callback( GtkWidget *widget,
     event.SetEventObject( win );
     event.SetId( win->GetId() );
 
-    return win->GTKProcessEvent(event);
+    bool ret = win->GTKProcessEvent(event);
+
+    g_lastMouseEvent = NULL;
+
+    return ret;
 }
 
 //-----------------------------------------------------------------------------
@@ -1693,6 +1710,8 @@ gtk_window_motion_notify_callback( GtkWidget *widget,
         gdk_event->y = y;
     }
 
+    g_lastMouseEvent = (GdkEvent*) gdk_event;
+
     wxMouseEvent event( wxEVT_MOTION );
     InitMouseEvent(win, event, gdk_event);
 
@@ -1735,7 +1754,11 @@ gtk_window_motion_notify_callback( GtkWidget *widget,
         }
     }
 
-    return win->GTKProcessEvent(event);
+    bool ret = win->GTKProcessEvent(event);
+
+    g_lastMouseEvent = NULL;
+
+    return ret;
 }
 
 //-----------------------------------------------------------------------------
@@ -2114,17 +2137,12 @@ void gtk_window_size_callback( GtkWidget *WXUNUSED(widget),
     if ((client_width == win->m_oldClientWidth) && (client_height == win->m_oldClientHeight))
         return;
 
-#if 0
-        wxPrintf( wxT("size_allocate ") );
-        if (win->GetClassInfo() && win->GetClassInfo()->GetClassName())
-            wxPrintf( win->GetClassInfo()->GetClassName() );
-        wxPrintf( wxT(" %d %d %d %d\n"),
-                alloc->x,
-                alloc->y,
-                alloc->width,
-                alloc->height );
-#endif
-                
+    if ( !client_width && !client_height )
+    {
+        // the window is currently unmapped, don't generate size events
+        return;
+    }
+
     win->m_oldClientWidth = client_width;
     win->m_oldClientHeight = client_height;
 
@@ -2319,7 +2337,17 @@ bool wxWindowGTK::Create( wxWindow *parent,
     GtkScrolledWindowClass *scroll_class = GTK_SCROLLED_WINDOW_CLASS( GTK_OBJECT_GET_CLASS(m_widget) );
     scroll_class->scrollbar_spacing = 0;
 
-    gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
+    if (HasFlag(wxALWAYS_SHOW_SB))
+    {
+        gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS );
+
+        scrolledWindow->hscrollbar_visible = TRUE;
+        scrolledWindow->vscrollbar_visible = TRUE;
+    }
+    else
+    {
+        gtk_scrolled_window_set_policy( scrolledWindow, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
+    }
 
     m_scrollBar[ScrollDir_Horz] = GTK_RANGE(scrolledWindow->hscrollbar);
     m_scrollBar[ScrollDir_Vert] = GTK_RANGE(scrolledWindow->vscrollbar);
@@ -2523,7 +2551,7 @@ void wxWindowGTK::PostCreation()
         // FIXME: what should be done here ?
     }
 #endif
-    else
+    else if ( !IsTopLevel() ) // top level windows use their own callback
     {
         // This is needed if we want to add our windows into native
         // GTK controls, such as the toolbar. With this callback, the
@@ -2581,7 +2609,7 @@ void wxWindowGTK::DoMoveWindow(int x, int y, int width, int height)
 {
     // inform the parent to perform the move
     gtk_pizza_set_size( GTK_PIZZA(m_parent->m_wxwindow), m_widget, x, y, width, height );
-    
+
 }
 
 void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags )
@@ -2920,10 +2948,10 @@ void wxWindowGTK::DoClientToScreen( int *x, int *y ) const
     {
         if (GetLayoutDirection() == wxLayout_RightToLeft)
             *x = (GetClientSize().x - *x) + org_x;
-        else 
+        else
             *x += org_x;
     }
-    
+
     if (y) *y += org_y;
 }
 
@@ -2956,7 +2984,7 @@ void wxWindowGTK::DoScreenToClient( int *x, int *y ) const
     {
         if (GetLayoutDirection() == wxLayout_RightToLeft)
             *x = (GetClientSize().x - *x) - org_x;
-        else 
+        else
             *x -= org_x;
     }
     if (y) *y -= org_y;
@@ -3181,7 +3209,7 @@ void wxWindowGTK::SetFocus()
                 gtk_widget_grab_focus (m_widget);
                 return;
             }
-        
+
             gtk_widget_child_focus( m_widget, GTK_DIR_TAB_FORWARD );
         }
         else
@@ -3340,7 +3368,7 @@ void wxWindowGTK::SetLayoutDirection(wxLayoutDirection dir)
         return;
 
     GTKSetLayout(m_widget, dir);
-    
+
     if (m_wxwindow)
         GTKSetLayout(m_wxwindow, dir);
 }
@@ -3589,7 +3617,7 @@ void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect )
         {
             p = NULL;
         }
-        
+
         gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow)->bin_window, p, TRUE );
     }
 }
@@ -3654,11 +3682,11 @@ void wxWindowGTK::GtkSendPaintEvents()
     {
         // Transform m_updateRegion under RTL
         m_updateRegion.Clear();
-        
+
         gint width;
         gdk_window_get_geometry( GTK_PIZZA(m_wxwindow)->bin_window,
                                  NULL, NULL, &width, NULL, NULL );
-        
+
         wxRegionIterator upd( m_nativeUpdateRegion );
         while (upd)
         {
@@ -3667,14 +3695,14 @@ void wxWindowGTK::GtkSendPaintEvents()
             rect.y = upd.GetY();
             rect.width = upd.GetWidth();
             rect.height = upd.GetHeight();
-            
+
             rect.x = width - rect.x - rect.width;
             m_updateRegion.Union( rect );
-            
+
             ++upd;
         }
     }
-    
+
     // widget to draw on
     GtkPizza *pizza = GTK_PIZZA (m_wxwindow);
 
@@ -3763,8 +3791,15 @@ void wxWindowGTK::DoSetToolTip( wxToolTip *tip )
 
 void wxWindowGTK::ApplyToolTip( GtkTooltips *tips, const wxChar *tip )
 {
-    wxString tmp( tip );
-    gtk_tooltips_set_tip( tips, GetConnectWidget(), wxGTK_CONV(tmp), (gchar*) NULL );
+    if (tip)
+    {
+        wxString tmp( tip );
+        gtk_tooltips_set_tip( tips, GetConnectWidget(), wxGTK_CONV(tmp), (gchar*) NULL );
+    }
+    else
+    {
+        gtk_tooltips_set_tip( tips, GetConnectWidget(), NULL, NULL);
+    }
 }
 #endif // wxUSE_TOOLTIPS
 
@@ -3834,45 +3869,54 @@ GtkRcStyle *wxWindowGTK::CreateWidgetStyle(bool forceStyle)
             pango_font_description_copy( m_font.GetNativeFontInfo()->description );
     }
 
+    int flagsNormal = 0,
+        flagsPrelight = 0,
+        flagsActive = 0,
+        flagsInsensitive = 0;
+
     if ( m_foregroundColour.Ok() )
     {
         const GdkColor *fg = m_foregroundColour.GetColor();
 
-        style->fg[GTK_STATE_NORMAL] = *fg;
-        style->color_flags[GTK_STATE_NORMAL] = GTK_RC_FG;
+        style->fg[GTK_STATE_NORMAL] =
+        style->text[GTK_STATE_NORMAL] = *fg;
+        flagsNormal |= GTK_RC_FG | GTK_RC_TEXT;
 
-        style->fg[GTK_STATE_PRELIGHT] = *fg;
-        style->color_flags[GTK_STATE_PRELIGHT] = GTK_RC_FG;
+        style->fg[GTK_STATE_PRELIGHT] =
+        style->text[GTK_STATE_PRELIGHT] = *fg;
+        flagsPrelight |= GTK_RC_FG | GTK_RC_TEXT;
 
-        style->fg[GTK_STATE_ACTIVE] = *fg;
-        style->color_flags[GTK_STATE_ACTIVE] = GTK_RC_FG;
+        style->fg[GTK_STATE_ACTIVE] =
+        style->text[GTK_STATE_ACTIVE] = *fg;
+        flagsActive |= GTK_RC_FG | GTK_RC_TEXT;
     }
 
     if ( m_backgroundColour.Ok() )
     {
         const GdkColor *bg = m_backgroundColour.GetColor();
 
-        style->bg[GTK_STATE_NORMAL] = *bg;
+        style->bg[GTK_STATE_NORMAL] =
         style->base[GTK_STATE_NORMAL] = *bg;
-        style->color_flags[GTK_STATE_NORMAL] = (GtkRcFlags)
-            (style->color_flags[GTK_STATE_NORMAL] | GTK_RC_BG | GTK_RC_BASE);
+        flagsNormal |= GTK_RC_BG | GTK_RC_BASE;
 
-        style->bg[GTK_STATE_PRELIGHT] = *bg;
+        style->bg[GTK_STATE_PRELIGHT] =
         style->base[GTK_STATE_PRELIGHT] = *bg;
-        style->color_flags[GTK_STATE_PRELIGHT] = (GtkRcFlags)
-            (style->color_flags[GTK_STATE_PRELIGHT] | GTK_RC_BG | GTK_RC_BASE);
+        flagsPrelight |= GTK_RC_BG | GTK_RC_BASE;
 
-        style->bg[GTK_STATE_ACTIVE] = *bg;
+        style->bg[GTK_STATE_ACTIVE] =
         style->base[GTK_STATE_ACTIVE] = *bg;
-        style->color_flags[GTK_STATE_ACTIVE] = (GtkRcFlags)
-            (style->color_flags[GTK_STATE_ACTIVE] | GTK_RC_BG | GTK_RC_BASE);
+        flagsActive |= GTK_RC_BG | GTK_RC_BASE;
 
-        style->bg[GTK_STATE_INSENSITIVE] = *bg;
+        style->bg[GTK_STATE_INSENSITIVE] =
         style->base[GTK_STATE_INSENSITIVE] = *bg;
-        style->color_flags[GTK_STATE_INSENSITIVE] = (GtkRcFlags)
-            (style->color_flags[GTK_STATE_INSENSITIVE] | GTK_RC_BG | GTK_RC_BASE);
+        flagsInsensitive |= GTK_RC_BG | GTK_RC_BASE;
     }
 
+    style->color_flags[GTK_STATE_NORMAL] = (GtkRcFlags)flagsNormal;
+    style->color_flags[GTK_STATE_PRELIGHT] = (GtkRcFlags)flagsPrelight;
+    style->color_flags[GTK_STATE_ACTIVE] = (GtkRcFlags)flagsActive;
+    style->color_flags[GTK_STATE_INSENSITIVE] = (GtkRcFlags)flagsInsensitive;
+
     return style;
 }
 
@@ -4111,7 +4155,7 @@ void wxWindowGTK::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
         if (pos < 0)
             pos = 0;
         m_scrollPos[dir] = adj->value = pos;
-        
+
         // If a "value_changed" signal emission is not already in progress
         if (!m_blockValueChanged[dir])
         {
@@ -4164,9 +4208,9 @@ wxEventType wxWindowGTK::GetScrollEventType(GtkRange* range)
 
     const int barIndex = range == m_scrollBar[1];
     GtkAdjustment* adj = range->adjustment;
-    
+
     const int value = int(adj->value + 0.5);
-    
+
     // save previous position
     const double oldPos = m_scrollPos[barIndex];
     // update current position
@@ -4218,6 +4262,28 @@ void wxWindowGTK::ScrollWindow( int dx, int dy, const wxRect* WXUNUSED(rect) )
         gtk_pizza_scroll( GTK_PIZZA(m_wxwindow), -dx, -dy );
 
     m_clipPaintRegion = false;
+
+#if wxUSE_CARET
+    bool restoreCaret = (GetCaret() != NULL && GetCaret()->IsVisible());
+    if (restoreCaret)
+    {
+        wxRect caretRect(GetCaret()->GetPosition(), GetCaret()->GetSize());
+        if (dx > 0)
+            caretRect.width += dx;
+        else
+        {
+            caretRect.x += dx; caretRect.width -= dx;
+        }
+        if (dy > 0)
+            caretRect.height += dy;
+        else
+        {
+            caretRect.y += dy; caretRect.height -= dy;
+        }
+
+        RefreshRect(caretRect);
+    }
+#endif // wxUSE_CARET
 }
 
 void wxWindowGTK::GtkScrolledWindowSetBorder(GtkWidget* w, int wxstyle)