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:
@@ -449,6 +449,7 @@ All (GUI):
|
|||||||
GTK:
|
GTK:
|
||||||
|
|
||||||
- wxRadioBox constructor uses default consistent with other ports now.
|
- wxRadioBox constructor uses default consistent with other ports now.
|
||||||
|
- Partially implemented wxTextCtrl::GetStyle() (Igor Romanov).
|
||||||
- Corrected themed border display.
|
- Corrected themed border display.
|
||||||
|
|
||||||
Mac:
|
Mac:
|
||||||
|
@@ -63,6 +63,7 @@ public:
|
|||||||
virtual void DiscardEdits();
|
virtual void DiscardEdits();
|
||||||
|
|
||||||
virtual bool SetStyle(long start, long end, const wxTextAttr& style);
|
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
|
// 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
|
// considering all its contents as a single strings) and (x, y) coordinates
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "wx/math.h"
|
#include "wx/math.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "wx/scopeguard.h"
|
||||||
#include "wx/strconv.h"
|
#include "wx/strconv.h"
|
||||||
#include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
|
#include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
|
||||||
|
|
||||||
@@ -1685,6 +1686,43 @@ bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
|
|||||||
return false;
|
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)
|
void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style)
|
||||||
{
|
{
|
||||||
gtk_widget_modify_style(m_text, style);
|
gtk_widget_modify_style(m_text, style);
|
||||||
|
Reference in New Issue
Block a user