X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/cbe6a493b66ad18b6a1f490589f2706f0f841b01..2a45803fc3877afd0ae3ce356dfe216505165882:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 66e9818fa3..3805f1ba5a 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1910,10 +1910,11 @@ size_allocate(GtkWidget*, GtkAllocation* alloc, wxWindow* win) if (w < 0) w = 0; if (h < 0) h = 0; } - if (win->m_oldClientWidth != w || win->m_oldClientHeight != h) + win->m_useCachedClientSize = true; + if (win->m_clientWidth != w || win->m_clientHeight != h) { - win->m_oldClientWidth = w; - win->m_oldClientHeight = h; + win->m_clientWidth = w; + win->m_clientHeight = h; // this callback can be connected to m_wxwindow, // so always get size from m_widget->allocation GtkAllocation a; @@ -1960,18 +1961,9 @@ static void style_updated(GtkWidget*, wxWindow* win) static void style_updated(GtkWidget*, GtkStyle*, wxWindow* win) #endif { - if (win->IsTopLevel()) - { - wxSysColourChangedEvent event; - event.SetEventObject(win); - win->GTKProcessEvent(event); - } - else - { - // Border width could change, which will change client size. - // Make sure size event occurs for this - win->m_oldClientWidth = 0; - } + wxSysColourChangedEvent event; + event.SetEventObject(win); + win->GTKProcessEvent(event); } //----------------------------------------------------------------------------- @@ -1990,12 +1982,14 @@ void wxWindowGTK::GTKHandleRealized() if (IsFrozen()) DoFreeze(); + GdkWindow* const window = GTKGetDrawingWindow(); + if (m_imData) { gtk_im_context_set_client_window ( m_imData->context, - m_wxwindow ? GTKGetDrawingWindow() + window ? window : gtk_widget_get_window(m_widget) ); } @@ -2006,7 +2000,6 @@ void wxWindowGTK::GTKHandleRealized() #if wxGTK_HAS_COMPOSITING_SUPPORT if (IsTransparentBackgroundSupported()) { - GdkWindow* const window = GTKGetDrawingWindow(); if (window) gdk_window_set_composited(window, true); } @@ -2018,16 +2011,14 @@ void wxWindowGTK::GTKHandleRealized() } } - - // We cannot set colours and fonts before the widget - // been realized, so we do this directly after realization - // or otherwise in idle time - - if (m_needsStyleChange) +#ifndef __WXGTK3__ + if (window && ( + m_backgroundStyle == wxBG_STYLE_PAINT || + m_backgroundStyle == wxBG_STYLE_TRANSPARENT)) { - SetBackgroundStyle(GetBackgroundStyle()); - m_needsStyleChange = false; + gdk_window_set_back_pixmap(window, NULL, false); } +#endif wxWindowCreateEvent event(static_cast(this)); event.SetEventObject( this ); @@ -2035,8 +2026,7 @@ void wxWindowGTK::GTKHandleRealized() GTKUpdateCursor(true, false); - if (m_wxwindow && - (IsTopLevel() || HasFlag(wxBORDER_RAISED | wxBORDER_SUNKEN | wxBORDER_THEME))) + if (m_wxwindow && IsTopLevel()) { // attaching to style changed signal after realization avoids initial // changes we don't care about @@ -2064,8 +2054,11 @@ void wxWindowGTK::GTKHandleUnrealize() if (m_imData) gtk_im_context_set_client_window(m_imData->context, NULL); - g_signal_handlers_disconnect_by_func( - m_wxwindow, (void*)style_updated, this); + if (IsTopLevel()) + { + g_signal_handlers_disconnect_by_func( + m_wxwindow, (void*)style_updated, this); + } } } @@ -2214,13 +2207,12 @@ void wxWindowGTK::Init() m_scrollPos[dir] = 0; } - m_oldClientWidth = - m_oldClientHeight = 0; + m_clientWidth = + m_clientHeight = 0; + m_useCachedClientSize = false; m_clipPaintRegion = false; - m_needsStyleChange = false; - m_cursor = *wxSTANDARD_CURSOR; m_imData = NULL; @@ -2588,6 +2580,9 @@ void wxWindowGTK::PostCreation() if (!WX_IS_PIZZA(gtk_widget_get_parent(m_widget)) && !GTK_IS_WINDOW(m_widget)) gtk_widget_set_size_request(m_widget, m_width, m_height); + // apply any font or color changes made before creation + GTKApplyWidgetStyle(); + InheritAttributes(); SetLayoutDirection(wxLayout_Default); @@ -2731,6 +2726,10 @@ void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags height = m_height; const bool sizeChange = m_width != width || m_height != height; + + if (sizeChange) + m_useCachedClientSize = false; + if (sizeChange || m_x != x || m_y != y) { m_x = x; @@ -2760,7 +2759,7 @@ void wxWindowGTK::DoSetSize( int x, int y, int width, int height, int sizeFlags { // update these variables to keep size_allocate handler // from sending another size event for this change - GetClientSize( &m_oldClientWidth, &m_oldClientHeight ); + DoGetClientSize(&m_clientWidth, &m_clientHeight); wxSizeEvent event( wxSize(m_width,m_height), GetId() ); event.SetEventObject( this ); @@ -2825,6 +2824,13 @@ void wxWindowGTK::DoGetClientSize( int *width, int *height ) const { wxCHECK_RET( (m_widget != NULL), wxT("invalid window") ); + if (m_useCachedClientSize) + { + if (width) *width = m_clientWidth; + if (height) *height = m_clientHeight; + return; + } + int w = m_width; int h = m_height; @@ -4006,46 +4012,46 @@ void wxWindowGTK::GTKApplyToolTip(const char* tip) bool wxWindowGTK::SetBackgroundColour( const wxColour &colour ) { - wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") ); - if (!wxWindowBase::SetBackgroundColour(colour)) return false; -#ifndef __WXGTK3__ - if (colour.IsOk()) + if (m_widget) { - // We need the pixel value e.g. for background clearing. - m_backgroundColour.CalcPixel(gtk_widget_get_colormap(m_widget)); - } +#ifndef __WXGTK3__ + if (colour.IsOk()) + { + // We need the pixel value e.g. for background clearing. + m_backgroundColour.CalcPixel(gtk_widget_get_colormap(m_widget)); + } #endif - // apply style change (forceStyle=true so that new style is applied - // even if the bg colour changed from valid to wxNullColour) - GTKApplyWidgetStyle(true); + // apply style change (forceStyle=true so that new style is applied + // even if the bg colour changed from valid to wxNullColour) + GTKApplyWidgetStyle(true); + } return true; } bool wxWindowGTK::SetForegroundColour( const wxColour &colour ) { - wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") ); - if (!wxWindowBase::SetForegroundColour(colour)) - { return false; - } -#ifndef __WXGTK3__ - if (colour.IsOk()) + if (m_widget) { - // We need the pixel value e.g. for background clearing. - m_foregroundColour.CalcPixel(gtk_widget_get_colormap(m_widget)); - } +#ifndef __WXGTK3__ + if (colour.IsOk()) + { + // We need the pixel value e.g. for background clearing. + m_foregroundColour.CalcPixel(gtk_widget_get_colormap(m_widget)); + } #endif - // apply style change (forceStyle=true so that new style is applied - // even if the bg colour changed from valid to wxNullColour): - GTKApplyWidgetStyle(true); + // apply style change (forceStyle=true so that new style is applied + // even if the bg colour changed from valid to wxNullColour): + GTKApplyWidgetStyle(true); + } return true; } @@ -4215,40 +4221,10 @@ bool wxWindowGTK::SetBackgroundStyle(wxBackgroundStyle style) #ifndef __WXGTK3__ GdkWindow *window; - if ( m_wxwindow ) - { - window = GTKGetDrawingWindow(); - } - else + if ((style == wxBG_STYLE_PAINT || style == wxBG_STYLE_TRANSPARENT) && + (window = GTKGetDrawingWindow())) { - GtkWidget * const w = GetConnectWidget(); - window = w ? gtk_widget_get_window(w) : NULL; - } - - bool wantNoBackPixmap = style == wxBG_STYLE_PAINT || style == wxBG_STYLE_TRANSPARENT; - - if ( wantNoBackPixmap ) - { - if (window) - { - // Make sure GDK/X11 doesn't refresh the window - // automatically. - gdk_window_set_back_pixmap( window, NULL, FALSE ); - m_needsStyleChange = false; - } - else // window not realized yet - { - // Do when window is realized - m_needsStyleChange = true; - } - - // Don't apply widget style, or we get a grey background - } - else - { - // apply style change (forceStyle=true so that new style is applied - // even if the bg colour changed from valid to wxNullColour): - GTKApplyWidgetStyle(true); + gdk_window_set_back_pixmap(window, NULL, false); } #endif // !__WXGTK3__ @@ -4417,14 +4393,15 @@ GdkWindow *wxWindowGTK::GTKGetWindow(wxArrayGdkWindows& WXUNUSED(windows)) const bool wxWindowGTK::SetFont( const wxFont &font ) { - wxCHECK_MSG( m_widget != NULL, false, wxT("invalid window") ); - if (!wxWindowBase::SetFont(font)) return false; - // apply style change (forceStyle=true so that new style is applied - // even if the font changed from valid to wxNullFont): - GTKApplyWidgetStyle(true); + if (m_widget) + { + // apply style change (forceStyle=true so that new style is applied + // even if the font changed from valid to wxNullFont): + GTKApplyWidgetStyle(true); + } return true; }