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
This commit is contained in:
Vadim Zeitlin
2009-10-05 22:53:26 +00:00
parent d9a35b5406
commit e9ee227022
3 changed files with 40 additions and 0 deletions

View 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);