From: Vadim Zeitlin Date: Mon, 5 Oct 2009 22:53:26 +0000 (+0000) Subject: Partially implement wxTextCtrl::GetStyle() in wxGTK. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e9ee227022d56afbe21612425c7f93e5ea8d713b Partially implement wxTextCtrl::GetStyle() in wxGTK. Support retrieving the (both foreground and background) colours for the given position. Closes #11281. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62262 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index dc440605b0..355904376a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -449,6 +449,7 @@ All (GUI): GTK: - wxRadioBox constructor uses default consistent with other ports now. +- Partially implemented wxTextCtrl::GetStyle() (Igor Romanov). - Corrected themed border display. Mac: diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 3da5188a2d..cdecf127e8 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -63,6 +63,7 @@ public: virtual void DiscardEdits(); virtual bool SetStyle(long start, long end, const wxTextAttr& style); + virtual bool GetStyle(long position, wxTextAttr& style); // translate between the position (which is just an index in the text ctrl // considering all its contents as a single strings) and (x, y) coordinates diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 167cfcb38a..a29fc54183 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -22,6 +22,7 @@ #include "wx/math.h" #endif +#include "wx/scopeguard.h" #include "wx/strconv.h" #include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo()) @@ -1685,6 +1686,43 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style ) return false; } +bool wxTextCtrl::GetStyle(long position, wxTextAttr& style) +{ + if ( !IsMultiLine() ) + { + // no styles for GtkEntry + return false; + } + + gint l = gtk_text_buffer_get_char_count( m_buffer ); + + wxCHECK_MSG( position >= 0 && position <= l, false, + _T("invalid range in wxTextCtrl::GetStyle") ); + + GtkTextIter positioni; + gtk_text_buffer_get_iter_at_offset(m_buffer, &positioni, position); + + // Obtain a copy of the default attributes + GtkTextAttributes * const + pattr = gtk_text_view_get_default_attributes(GTK_TEXT_VIEW(m_text)); + wxON_BLOCK_EXIT1( g_free, pattr ); + + // And query GTK for the attributes at the given position using it as base + if ( !gtk_text_iter_get_attributes(&positioni, pattr) ) + { + style = m_defaultStyle; + } + else // have custom attributes + { + style.SetBackgroundColour(pattr->appearance.bg_color); + style.SetTextColour(pattr->appearance.fg_color); + + // TODO: set font, alignment, tabs and indents + } + + return true; +} + void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style) { gtk_widget_modify_style(m_text, style);