diff --git a/src/gtk/control.cpp b/src/gtk/control.cpp index 3352965683..f11b6e80ed 100644 --- a/src/gtk/control.cpp +++ b/src/gtk/control.cpp @@ -251,6 +251,7 @@ wxControl::GetDefaultAttributesFromGTKWidget(GtkWidget* widget, } GtkStyleContext* sc = gtk_widget_get_style_context(widget); GdkRGBA c; + gtk_style_context_set_state(sc, stateFlag); gtk_style_context_get_color(sc, stateFlag, &c); attr.colFg = wxColour(c); gtk_style_context_get_background_color(sc, stateFlag, &c); @@ -319,7 +320,11 @@ wxSize wxControl::GTKGetPreferredSize(GtkWidget* widget) const { GtkRequisition req; #ifdef __WXGTK3__ + int w, h; + gtk_widget_get_size_request(widget, &w, &h); + gtk_widget_set_size_request(widget, -1, -1); gtk_widget_get_preferred_size(widget, NULL, &req); + gtk_widget_set_size_request(widget, w, h); #else GTK_WIDGET_GET_CLASS(widget)->size_request(widget, &req); #endif diff --git a/src/gtk/settings.cpp b/src/gtk/settings.cpp index 0f5f4de5fe..33b0a07752 100644 --- a/src/gtk/settings.cpp +++ b/src/gtk/settings.cpp @@ -155,33 +155,39 @@ static GtkWidget* ToolTipWidget() static void bg(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA) { GtkStyleContext* sc = gtk_widget_get_style_context(widget); + gtk_style_context_set_state(sc, state); gtk_style_context_get_background_color(sc, state, &gdkRGBA); if (gdkRGBA.alpha <= 0) { widget = gtk_widget_get_parent(GTK_WIDGET(ContainerWidget())); sc = gtk_widget_get_style_context(widget); + gtk_style_context_set_state(sc, state); gtk_style_context_get_background_color(sc, state, &gdkRGBA); } } static void fg(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA) { GtkStyleContext* sc = gtk_widget_get_style_context(widget); + gtk_style_context_set_state(sc, state); gtk_style_context_get_color(sc, state, &gdkRGBA); if (gdkRGBA.alpha <= 0) { widget = gtk_widget_get_parent(GTK_WIDGET(ContainerWidget())); sc = gtk_widget_get_style_context(widget); + gtk_style_context_set_state(sc, state); gtk_style_context_get_color(sc, state, &gdkRGBA); } } static void border(GtkWidget* widget, GtkStateFlags state, GdkRGBA& gdkRGBA) { GtkStyleContext* sc = gtk_widget_get_style_context(widget); + gtk_style_context_set_state(sc, state); gtk_style_context_get_border_color(sc, state, &gdkRGBA); if (gdkRGBA.alpha <= 0) { widget = gtk_widget_get_parent(GTK_WIDGET(ContainerWidget())); sc = gtk_widget_get_style_context(widget); + gtk_style_context_set_state(sc, state); gtk_style_context_get_border_color(sc, state, &gdkRGBA); } } @@ -453,6 +459,7 @@ wxFont wxSystemSettingsNative::GetFont( wxSystemFont index ) wxNativeFontInfo info; #ifdef __WXGTK3__ GtkStyleContext* sc = gtk_widget_get_style_context(ButtonWidget()); + gtk_style_context_set_state(sc, GTK_STATE_FLAG_NORMAL); gtk_style_context_get(sc, GTK_STATE_FLAG_NORMAL, GTK_STYLE_PROPERTY_FONT, &info.description, NULL); #else diff --git a/src/gtk/spinbutt.cpp b/src/gtk/spinbutt.cpp index a2285fbce3..97f3461af3 100644 --- a/src/gtk/spinbutt.cpp +++ b/src/gtk/spinbutt.cpp @@ -196,7 +196,7 @@ wxSize wxSpinButton::DoGetBestSize() const #ifdef __WXGTK3__ GtkStyleContext* sc = gtk_widget_get_style_context(m_widget); GtkBorder pad = { 0, 0, 0, 0 }; - gtk_style_context_get_padding(sc, GtkStateFlags(0), &pad); + gtk_style_context_get_padding(sc, gtk_style_context_get_state(sc), &pad); best.x -= pad.left + pad.right; #else gtk_widget_ensure_style(m_widget); diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 5f4f134da5..8ef85e6f84 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1828,6 +1828,7 @@ void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style) gtk_style_context_save(context); gtk_style_context_add_class(context, GTK_STYLE_CLASS_VIEW); } + gtk_style_context_set_state(context, selectedFocused); gtk_style_context_get_color(context, selectedFocused, &fg_orig); gtk_style_context_get_background_color(context, selectedFocused, &bg_orig); if (IsMultiLine()) diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index c3d42e8f29..a52dad0461 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -1194,6 +1194,14 @@ void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int si } } +extern "C" { +static gboolean reset_size_request(void* data) +{ + gtk_widget_set_size_request(GTK_WIDGET(data), -1, -1); + return false; +} +} + void wxTopLevelWindowGTK::DoSetClientSize(int width, int height) { base_type::DoSetClientSize(width, height); @@ -1202,6 +1210,25 @@ void wxTopLevelWindowGTK::DoSetClientSize(int width, int height) // Has to be done after calling base because it calls SetSize, // which sets this true m_deferShowAllowed = false; + + if (m_wxwindow) + { + // If window is not resizable or not yet shown, set size request on + // client widget, to make it more likely window will get correct size + // even if our decorations size cache is incorrect (as it will be before + // showing first TLW). + if (!gtk_window_get_resizable(GTK_WINDOW(m_widget))) + { + gtk_widget_set_size_request(m_widget, -1, -1); + gtk_widget_set_size_request(m_wxwindow, m_clientWidth, m_clientHeight); + } + else if (!IsShown()) + { + gtk_widget_set_size_request(m_wxwindow, m_clientWidth, m_clientHeight); + // Cancel size request at next idle to allow resizing + g_idle_add_full(G_PRIORITY_LOW, reset_size_request, m_wxwindow, NULL); + } + } } void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const diff --git a/src/gtk/win_gtk.cpp b/src/gtk/win_gtk.cpp index 90ff180ec1..b0f7721f36 100644 --- a/src/gtk/win_gtk.cpp +++ b/src/gtk/win_gtk.cpp @@ -192,8 +192,24 @@ static void pizza_remove(GtkContainer* container, GtkWidget* widget) } #ifdef __WXGTK3__ +// Get preferred size of children, to avoid GTK+ warnings complaining +// that they were size-allocated without asking their preferred size +static void children_get_preferred_size(const GList* p) +{ + for (; p; p = p->next) + { + const wxPizzaChild* child = static_cast(p->data); + if (gtk_widget_get_visible(child->widget)) + { + GtkRequisition req; + gtk_widget_get_preferred_size(child->widget, &req, NULL); + } + } +} + static void pizza_get_preferred_width(GtkWidget* widget, int* minimum, int* natural) { + children_get_preferred_size(WX_PIZZA(widget)->m_children); *minimum = 0; gtk_widget_get_size_request(widget, natural, NULL); if (*natural < 0) @@ -202,6 +218,7 @@ static void pizza_get_preferred_width(GtkWidget* widget, int* minimum, int* natu static void pizza_get_preferred_height(GtkWidget* widget, int* minimum, int* natural) { + children_get_preferred_size(WX_PIZZA(widget)->m_children); *minimum = 0; gtk_widget_get_size_request(widget, NULL, natural); if (*natural < 0) @@ -452,6 +469,7 @@ void wxPizza::get_border(GtkBorder& border) else sc = gtk_widget_get_style_context(wxGTKPrivate::GetEntryWidget()); + gtk_style_context_set_state(sc, GTK_STATE_FLAG_NORMAL); gtk_style_context_get_border(sc, GTK_STATE_FLAG_NORMAL, &border); #else // !__WXGTK3__ GtkStyle* style; diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index a1619c5d0e..8920d55a22 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -304,6 +304,7 @@ draw_border(GtkWidget* widget, GdkEventExpose* gdk_event, wxWindow* win) #ifdef __WXGTK3__ GtkStyleContext* sc = gtk_widget_get_style_context(win->m_wxwindow); GdkRGBA c; + gtk_style_context_set_state(sc, GTK_STATE_FLAG_NORMAL); gtk_style_context_get_border_color(sc, GTK_STATE_FLAG_NORMAL, &c); gdk_cairo_set_source_rgba(cr, &c); cairo_set_line_width(cr, 1); @@ -4443,6 +4444,7 @@ void wxWindowGTK::GTKApplyStyle(GtkWidget* widget, GtkRcStyle* WXUNUSED_IN_GTK3( cairo_pattern_t* pattern = NULL; if (m_backgroundColour.IsOk()) { + gtk_style_context_set_state(context, GTK_STATE_FLAG_NORMAL); gtk_style_context_get(context, GTK_STATE_FLAG_NORMAL, "background-image", &pattern, NULL); } diff --git a/src/propgrid/property.cpp b/src/propgrid/property.cpp index 5067b8d2e7..72a7a51530 100644 --- a/src/propgrid/property.cpp +++ b/src/propgrid/property.cpp @@ -477,13 +477,13 @@ void wxPGProperty::Init() void wxPGProperty::Init( const wxString& label, const wxString& name ) { - // We really need to check if &label and &name are NULL pointers - // (this can if we are called before property grid has been initalized) + // wxPG_LABEL reference can be NULL if we are called before property + // grid has been initialized - if ( (&label) != NULL && label != wxPG_LABEL ) + if ( sm_wxPG_LABEL && label != wxPG_LABEL ) m_label = label; - if ( (&name) != NULL && name != wxPG_LABEL ) + if ( sm_wxPG_LABEL && name != wxPG_LABEL ) DoSetName( name ); else DoSetName( m_label );