From 66324470f1b90146c8c6d96b1b07bb6e90640b3f Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 7 Nov 2017 15:40:29 +0100 Subject: [PATCH] Fix wxTextCtrl::GetStyle() with GTK+ 3 The text and background colours are now stored in the rgba array instead of fg_color and bg_color as with GTK+ 2 (the latter ones seem to have been repurposed for the underline and strike-through colours!). Also make the unit test for this method more robust. --- docs/changes.txt | 1 + src/gtk/textctrl.cpp | 5 +++++ tests/controls/textctrltest.cpp | 21 +++++++++++---------- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 0f5d8fd377..7b4b32ef2d 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -171,6 +171,7 @@ wxGTK: - Make wxUIActionSimulator work with GTK+ 3 (Scott Talbert). - Make wxBORDER_NONE work for wxTextCtrl with GTK+ 3 (Adrien Tétar). - Apply wxTextCtrl::SetDefaultStyle() to user-entered text (Andreas Falkenhahn). +- Fix wxTextCtrl::GetStyle() with GTK+ 3. - Support background colour in wxDataViewCtrl attributes. - Improve wxSpinCtrl best size calculation. - Implement support for icon locations in wxMimeTypesManager (Hanmac). diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 2495c498df..4aa72d774f 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1777,8 +1777,13 @@ bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) } else // have custom attributes { +#ifdef __WXGTK3__ + style.SetBackgroundColour(*pattr->appearance.rgba[0]); + style.SetTextColour(*pattr->appearance.rgba[1]); +#else style.SetBackgroundColour(pattr->appearance.bg_color); style.SetTextColour(pattr->appearance.fg_color); +#endif const wxGtkString pangoFontString(pango_font_description_to_string(pattr->font)); diff --git a/tests/controls/textctrltest.cpp b/tests/controls/textctrltest.cpp index f7877d3b0a..3abcbfe868 100644 --- a/tests/controls/textctrltest.cpp +++ b/tests/controls/textctrltest.cpp @@ -397,7 +397,7 @@ void TextCtrlTestCase::Style() #ifndef __WXOSX__ delete m_text; // We need wxTE_RICH under windows for style support - CreateText(wxTE_RICH); + CreateText(wxTE_MULTILINE|wxTE_RICH); // Red text on a white background m_text->SetDefaultStyle(wxTextAttr(*wxRED, *wxWHITE)); @@ -431,20 +431,21 @@ void TextCtrlTestCase::Style() wxTextAttr style; // We have to check that styles are supported - if(m_text->GetStyle(3, style)) + if ( !m_text->GetStyle(3, style) ) { - CPPUNIT_ASSERT_EQUAL(style.GetTextColour(), *wxRED); - CPPUNIT_ASSERT_EQUAL(style.GetBackgroundColour(), *wxWHITE); + WARN("Retrieving text style not supported, skipping test."); + return; } + CHECK( style.GetTextColour() == *wxRED ); + CHECK( style.GetBackgroundColour() == *wxWHITE ); + // And then setting the style - if(m_text->SetStyle(15, 18, style)) - { - m_text->GetStyle(17, style); + REQUIRE( m_text->SetStyle(15, 18, style) ); - CPPUNIT_ASSERT_EQUAL(style.GetTextColour(), *wxRED); - CPPUNIT_ASSERT_EQUAL(style.GetBackgroundColour(), *wxWHITE); - } + REQUIRE( m_text->GetStyle(17, style) ); + CHECK( style.GetTextColour() == *wxRED ); + CHECK( style.GetBackgroundColour() == *wxWHITE ); #endif }