X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5540f0ba6ce6d2a1dfb41f192865290ff15f392d..e637208a3210dfae3ee044cc5b7179fd76082769:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index a6544f8fe6..9f639a3586 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -33,10 +33,9 @@ #include "wx/layout.h" #include "wx/statusbr.h" #include "wx/math.h" + #include "wx/module.h" #endif -#include "wx/module.h" - #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" #endif @@ -487,6 +486,7 @@ gtk_window_expose_callback( GtkWidget *widget, GtkPizza *pizza = GTK_PIZZA( widget ); if (gdk_event->window != pizza->bin_window) return FALSE; + #if 0 if (win->GetName()) { @@ -516,7 +516,6 @@ gtk_window_expose_callback( GtkWidget *widget, win->GtkSendPaintEvents(); - // Let parent window draw window-less widgets (* GTK_WIDGET_CLASS (pizza_parent_class)->expose_event) (widget, gdk_event); @@ -1245,7 +1244,7 @@ gtk_window_key_release_callback( GtkWidget *widget, return FALSE; } - return win->GetEventHandler()->ProcessEvent(event); + return win->GTKProcessEvent(event); } } @@ -1283,6 +1282,13 @@ template 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 + int window_width = gtk_pizza_get_rtl_offset( GTK_PIZZA(win->m_wxwindow) ); + event.m_x = window_width - event.m_x; + } event.SetEventObject( win ); event.SetId( win->GetId() ); @@ -1331,8 +1337,8 @@ wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y) if (win->m_wxwindow) { GtkPizza *pizza = GTK_PIZZA(win->m_wxwindow); - xx += pizza->xoffset; - yy += pizza->yoffset; + xx += gtk_pizza_get_xoffset( pizza ); + yy += gtk_pizza_get_yoffset( pizza ); } wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst(); @@ -1391,6 +1397,12 @@ wxWindowGTK *FindWindowForMouseEvent(wxWindowGTK *win, wxCoord& x, wxCoord& y) // common event handlers helpers // ---------------------------------------------------------------------------- +bool wxWindowGTK::GTKProcessEvent(wxEvent& event) const +{ + // nothing special at this level + return GetEventHandler()->ProcessEvent(event); +} + int wxWindowGTK::GTKCallbackCommonPrologue(GdkEventAny *event) const { DEBUG_MAIN_THREAD @@ -1595,7 +1607,7 @@ gtk_window_button_press_callback( GtkWidget *widget, event.SetEventObject( win ); event.SetId( win->GetId() ); - if (win->GetEventHandler()->ProcessEvent( event )) + if (win->GTKProcessEvent( event )) { return TRUE; } @@ -1614,7 +1626,7 @@ gtk_window_button_press_callback( GtkWidget *widget, win->GetId(), win->ClientToScreen(event.GetPosition())); evtCtx.SetEventObject(win); - return win->GetEventHandler()->ProcessEvent(evtCtx); + return win->GTKProcessEvent(evtCtx); } return FALSE; @@ -1667,7 +1679,7 @@ gtk_window_button_release_callback( GtkWidget *widget, event.SetEventObject( win ); event.SetId( win->GetId() ); - return win->GetEventHandler()->ProcessEvent(event); + return win->GTKProcessEvent(event); } //----------------------------------------------------------------------------- @@ -1712,7 +1724,7 @@ gtk_window_motion_notify_callback( GtkWidget *widget, : wxEVT_LEAVE_WINDOW); InitMouseEvent(win, eventM, gdk_event); eventM.SetEventObject(win); - win->GetEventHandler()->ProcessEvent(eventM); + win->GTKProcessEvent(eventM); } } else // no capture @@ -1727,13 +1739,13 @@ gtk_window_motion_notify_callback( GtkWidget *widget, if ( !g_captureWindow ) { wxSetCursorEvent cevent( event.m_x, event.m_y ); - if (win->GetEventHandler()->ProcessEvent( cevent )) + if (win->GTKProcessEvent( cevent )) { - // Rewrite cursor handling here (away from idle). + win->SetCursor( cevent.GetCursor() ); } } - return win->GetEventHandler()->ProcessEvent(event); + return win->GTKProcessEvent(event); } //----------------------------------------------------------------------------- @@ -1778,7 +1790,7 @@ window_scroll_event(GtkWidget*, GdkEventScroll* gdk_event, wxWindow* win) event.SetId( win->GetId() ); event.SetTimestamp( gdk_event->time ); - return win->GetEventHandler()->ProcessEvent(event); + return win->GTKProcessEvent(event); } //----------------------------------------------------------------------------- @@ -1789,7 +1801,7 @@ static gboolean wxgtk_window_popup_menu_callback(GtkWidget*, wxWindowGTK* win) { wxContextMenuEvent event(wxEVT_CONTEXT_MENU, win->GetId(), wxPoint(-1, -1)); event.SetEventObject(win); - return win->GetEventHandler()->ProcessEvent(event); + return win->GTKProcessEvent(event); } //----------------------------------------------------------------------------- @@ -1900,7 +1912,7 @@ gtk_window_focus_out_callback( GtkWidget *widget, wxFocusEvent event( wxEVT_KILL_FOCUS, win->GetId() ); event.SetEventObject( win ); - (void)win->GetEventHandler()->ProcessEvent( event ); + (void)win->GTKProcessEvent( event ); ret = TRUE; } @@ -1942,13 +1954,13 @@ gtk_window_enter_callback( GtkWidget *widget, if ( !g_captureWindow ) { wxSetCursorEvent cevent( event.m_x, event.m_y ); - if (win->GetEventHandler()->ProcessEvent( cevent )) + if (win->GTKProcessEvent( cevent )) { - // Rewrite cursor handling here (away from idle). + win->SetCursor( cevent.GetCursor() ); } } - return win->GetEventHandler()->ProcessEvent(event); + return win->GTKProcessEvent(event); } //----------------------------------------------------------------------------- @@ -1987,7 +1999,7 @@ gtk_window_leave_callback( GtkWidget *widget, event.m_x = x + pt.x; event.m_y = y + pt.y; - return win->GetEventHandler()->ProcessEvent(event); + return win->GTKProcessEvent(event); } //----------------------------------------------------------------------------- @@ -2012,7 +2024,7 @@ gtk_scrollbar_value_changed(GtkRange* range, wxWindow* win) event.SetEventObject(win); win->m_blockValueChanged[dir] = true; - win->GetEventHandler()->ProcessEvent(event); + win->GTKProcessEvent(event); win->m_blockValueChanged[dir] = false; } } @@ -2049,7 +2061,7 @@ gtk_scrollbar_event_after(GtkRange* range, GdkEvent* event, wxWindow* win) win->ScrollDirFromRange(range)); wxScrollWinEvent event(wxEVT_SCROLLWIN_THUMBRELEASE, win->GetScrollPos(orient), orient); event.SetEventObject(win); - win->GetEventHandler()->ProcessEvent(event); + win->GTKProcessEvent(event); } } @@ -2101,7 +2113,7 @@ gtk_window_realized_callback( GtkWidget *m_widget, wxWindow *win ) wxWindowCreateEvent event( win ); event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( event ); + win->GTKProcessEvent( event ); } //----------------------------------------------------------------------------- @@ -2110,7 +2122,7 @@ gtk_window_realized_callback( GtkWidget *m_widget, wxWindow *win ) static void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), - GtkAllocation *WXUNUSED(alloc), + GtkAllocation *alloc, wxWindow *win ) { if (g_isIdle) @@ -2122,6 +2134,19 @@ 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 + + GTK_PIZZA(win->m_wxwindow)->m_width = alloc->width; + win->m_oldClientWidth = client_width; win->m_oldClientHeight = client_height; @@ -2129,7 +2154,7 @@ void gtk_window_size_callback( GtkWidget *WXUNUSED(widget), { wxSizeEvent event( win->GetSize(), win->GetId() ); event.SetEventObject( win ); - win->GetEventHandler()->ProcessEvent( event ); + win->GTKProcessEvent( event ); } } @@ -2285,8 +2310,8 @@ static void wxInsertChildInWindow( wxWindowGTK* parent, wxWindowGTK* child ) /* the window might have been scrolled already, do we have to adapt the position */ GtkPizza *pizza = GTK_PIZZA(parent->m_wxwindow); - child->m_x += pizza->xoffset; - child->m_y += pizza->yoffset; + child->m_x += gtk_pizza_get_xoffset( pizza ); + child->m_y += gtk_pizza_get_yoffset( pizza ); gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow), GTK_WIDGET(child->m_widget), @@ -2359,7 +2384,7 @@ void wxWindowGTK::Init() m_hasVMT = false; m_needParent = true; m_isBeingDeleted = false; - + m_showOnIdle= false; m_noExpose = false; @@ -2588,7 +2613,8 @@ void wxWindowGTK::PostCreation() g_signal_connect (m_wxwindow, "expose_event", G_CALLBACK (gtk_window_expose_callback), this); - gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), HasFlag( wxFULL_REPAINT_ON_RESIZE ) ); + if (GetLayoutDirection() == wxLayout_LeftToRight) + gtk_widget_set_redraw_on_allocate( GTK_WIDGET(m_wxwindow), HasFlag( wxFULL_REPAINT_ON_RESIZE ) ); } // Create input method handler @@ -2663,7 +2689,7 @@ void wxWindowGTK::PostCreation() this); } #ifdef GTK_IS_FILE_CHOOSER_BUTTON - else if (GTK_IS_FILE_CHOOSER_BUTTON(m_widget)) + else if (!gtk_check_version(2,6,0) && GTK_IS_FILE_CHOOSER_BUTTON(m_widget)) { // If we connect to the "size_request" signal of a GtkFileChooserButton // then that control won't be sized properly when placed inside sizers @@ -2686,6 +2712,8 @@ void wxWindowGTK::PostCreation() m_hasVMT = true; + SetLayoutDirection(wxLayout_Default); + // unless the window was created initially hidden (i.e. Hide() had been // called before Create()), we should show it at GTK+ level as well if ( IsShown() ) @@ -2725,7 +2753,9 @@ bool wxWindowGTK::Destroy() 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 ) @@ -2780,8 +2810,6 @@ void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags // don't take the x,y values, they're wrong because toolbar sets them GtkWidget *widget = GTK_WIDGET(m_widget); gtk_widget_set_size_request (widget, m_width, m_height); - if (GTK_WIDGET_VISIBLE (widget)) - gtk_widget_queue_resize (widget); } else #endif @@ -2798,13 +2826,13 @@ void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags GtkPizza *pizza = GTK_PIZZA(m_parent->m_wxwindow); if ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0) { - if (x != -1) m_x = x + pizza->xoffset; - if (y != -1) m_y = y + pizza->yoffset; + if (x != -1) m_x = x + gtk_pizza_get_xoffset( pizza ); + if (y != -1) m_y = y + gtk_pizza_get_yoffset( pizza ); } else { - m_x = x + pizza->xoffset; - m_y = y + pizza->yoffset; + m_x = x + gtk_pizza_get_xoffset( pizza ); + m_y = y + gtk_pizza_get_yoffset( pizza ); } int left_border = 0; @@ -2878,7 +2906,7 @@ bool wxWindowGTK::GtkShowFromOnIdle() m_showOnIdle = false; return true; } - + return false; } @@ -2900,7 +2928,7 @@ void wxWindowGTK::OnInternalIdle() SetBackgroundStyle(GetBackgroundStyle()); m_needsStyleChange = false; } - + wxCursor cursor = m_cursor; if (g_globalCursor.Ok()) cursor = g_globalCursor; @@ -3015,6 +3043,10 @@ void wxWindowGTK::DoGetClientSize( int *width, int *height ) const w -= dw; h -= dh; + if (w < 0) + w = 0; + if (h < 0) + h = 0; } if (width) *width = w; @@ -3030,8 +3062,8 @@ void wxWindowGTK::DoGetPosition( int *x, int *y ) const if (m_parent && m_parent->m_wxwindow) { GtkPizza *pizza = GTK_PIZZA(m_parent->m_wxwindow); - dx = pizza->xoffset; - dy = pizza->yoffset; + dx = gtk_pizza_get_xoffset( pizza ); + dy = gtk_pizza_get_yoffset( pizza ); } if (x) (*x) = m_x - dx; @@ -3381,7 +3413,7 @@ bool wxWindowGTK::Reparent( wxWindowBase *newParentBase ) m_showOnIdle = true; gtk_widget_hide( m_widget ); } - + /* insert GTK representation */ (*(newParent->m_insertCallback))(newParent, this); } @@ -3389,6 +3421,8 @@ bool wxWindowGTK::Reparent( wxWindowBase *newParentBase ) /* reverse: prevent GTK from deleting the widget arbitrarily */ gtk_widget_unref( m_widget ); + SetLayoutDirection(wxLayout_Default); + return true; } @@ -3423,6 +3457,63 @@ void wxWindowGTK::RemoveChild(wxWindowBase *child) wxapp_install_idle_handler(); } +/* static */ +wxLayoutDirection wxWindowGTK::GTKGetLayout(GtkWidget *widget) +{ + return gtk_widget_get_direction(GTK_WIDGET(widget)) == GTK_TEXT_DIR_RTL + ? wxLayout_RightToLeft + : wxLayout_LeftToRight; +} + +/* static */ +void wxWindowGTK::GTKSetLayout(GtkWidget *widget, wxLayoutDirection dir) +{ + wxASSERT_MSG( dir != wxLayout_Default, _T("invalid layout direction") ); + + gtk_widget_set_direction(GTK_WIDGET(widget), + dir == wxLayout_RightToLeft ? GTK_TEXT_DIR_RTL + : GTK_TEXT_DIR_LTR); +} + +wxLayoutDirection wxWindowGTK::GetLayoutDirection() const +{ + return GTKGetLayout(m_widget); +} + +void wxWindowGTK::SetLayoutDirection(wxLayoutDirection dir) +{ + if ( dir == wxLayout_Default ) + { + const wxWindow *const parent = GetParent(); + if ( parent ) + { + // inherit layout from parent. + dir = parent->GetLayoutDirection(); + } + else // no parent, use global default layout + { + dir = wxTheApp->GetLayoutDirection(); + } + } + + if ( dir == wxLayout_Default ) + return; + + GTKSetLayout(m_widget, dir); + + if (m_wxwindow) + GTKSetLayout(m_wxwindow, dir); +} + +wxCoord +wxWindowGTK::AdjustForLayoutDirection(wxCoord x, + wxCoord WXUNUSED(width), + wxCoord WXUNUSED(widthTotal)) const +{ + // We now mirrors the coordinates of RTL windows in GtkPizza + return x; +} + void wxWindowGTK::DoMoveInTabOrder(wxWindow *win, MoveKind move) { wxWindowBase::DoMoveInTabOrder(win, move); @@ -3533,15 +3624,12 @@ void wxWindowGTK::Lower() bool wxWindowGTK::SetCursor( const wxCursor &cursor ) { - wxCHECK_MSG( (m_widget != NULL), false, wxT("invalid window") ); + if ( !wxWindowBase::SetCursor(cursor.Ok() ? cursor : *wxSTANDARD_CURSOR) ) + return false; - if (cursor == m_cursor) - return false; + GTKUpdateCursor(); - if (g_isIdle) - wxapp_install_idle_handler(); - - return wxWindowBase::SetCursor( cursor.Ok() ? cursor : *wxSTANDARD_CURSOR ); + return true; } void wxWindowGTK::GTKUpdateCursor() @@ -3643,7 +3731,7 @@ void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect ) if (m_wxwindow) { if (!GTK_PIZZA(m_wxwindow)->bin_window) return; - + GdkRectangle gdk_rect, *p; if (rect) @@ -3658,6 +3746,8 @@ void wxWindowGTK::Refresh( bool eraseBackground, const wxRect *rect ) { p = NULL; } + + p = NULL; gdk_window_invalidate_rect( GTK_PIZZA(m_wxwindow)->bin_window, p, TRUE ); } @@ -3692,6 +3782,20 @@ void wxWindowGTK::GtkUpdate() } } +bool wxWindowGTK::DoIsExposed( int x, int y ) const +{ + return m_updateRegion.Contains(x, y) != wxOutRegion; +} + + +bool wxWindowGTK::DoIsExposed( int x, int y, int w, int h ) const +{ + if (GetLayoutDirection() == wxLayout_RightToLeft) + return m_updateRegion.Contains(x-w, y, w, h) != wxOutRegion; + else + return m_updateRegion.Contains(x, y, w, h) != wxOutRegion; +} + void wxWindowGTK::GtkSendPaintEvents() { if (!m_wxwindow) @@ -3703,6 +3807,34 @@ void wxWindowGTK::GtkSendPaintEvents() // Clip to paint region in wxClientDC m_clipPaintRegion = true; + wxRegion maybe_rtl_region = m_updateRegion; + +#if 0 + if (GetLayoutDirection() == wxLayout_RightToLeft) + { + maybe_rtl_region.Clear(); + + gint width; + gdk_window_get_geometry( GTK_PIZZA(m_wxwindow)->bin_window, + NULL, NULL, &width, NULL, NULL ); + + wxRegionIterator upd( m_updateRegion ); + while (upd) + { + wxRect rect; + rect.x = upd.GetX(); + rect.y = upd.GetY(); + rect.width = upd.GetWidth(); + rect.height = upd.GetHeight(); + + rect.x = width - rect.x - rect.width; + maybe_rtl_region.Union( rect ); + + ++upd; + } + } +#endif + // widget to draw on GtkPizza *pizza = GTK_PIZZA (m_wxwindow); @@ -3738,8 +3870,9 @@ void wxWindowGTK::GtkSendPaintEvents() } } else - { + m_updateRegion = maybe_rtl_region; + wxWindowDC dc( (wxWindow*)this ); dc.SetClippingRegion( m_updateRegion ); @@ -3749,6 +3882,8 @@ void wxWindowGTK::GtkSendPaintEvents() GetEventHandler()->ProcessEvent(erase_event); } + m_updateRegion = maybe_rtl_region; + wxNcPaintEvent nc_paint_event( GetId() ); nc_paint_event.SetEventObject( this ); GetEventHandler()->ProcessEvent( nc_paint_event ); @@ -4316,4 +4451,3 @@ void wxRemoveGrab(wxWindow* window) { gtk_grab_remove( (GtkWidget*) window->GetHandle() ); } -