]> git.saurik.com Git - wxWidgets.git/commitdiff
Partially implement wxTextCtrl::GetStyle() in wxGTK.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 5 Oct 2009 22:53:26 +0000 (22:53 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 5 Oct 2009 22:53:26 +0000 (22:53 +0000)
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

docs/changes.txt
include/wx/gtk/textctrl.h
src/gtk/textctrl.cpp

index dc440605b0585f2889f37e5ef7f39a5336495193..355904376a4a45106855e5c8c475115fa6862307 100644 (file)
@@ -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:
index 3da5188a2d5b4e17834c56469e274d9837098a80..cdecf127e888f61616b1a999f511933c631dd82a 100644 (file)
@@ -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
index 167cfcb38a8dc2003323ca3f7ce389a83b2b900f..a29fc541833eabf1600c7d79d07dbb6b5ab27db2 100644 (file)
@@ -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);