#include "wx/math.h"
#endif
+#include "wx/scopeguard.h"
#include "wx/strconv.h"
#include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
static void
au_check_word( GtkTextIter *s, GtkTextIter *e )
{
- static const char *URIPrefixes[] =
+ static const char *const URIPrefixes[] =
{
"http://",
"ftp://",
// wxTextCtrl
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase)
-
BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
EVT_CHAR(wxTextCtrl::OnChar)
m_text = NULL;
m_showPositionOnThaw = NULL;
- m_gdkHandCursor = NULL;
- m_gdkXTermCursor = NULL;
}
wxTextCtrl::~wxTextCtrl()
{
- if(m_gdkHandCursor)
- gdk_cursor_unref(m_gdkHandCursor);
- if(m_gdkXTermCursor)
- gdk_cursor_unref(m_gdkXTermCursor);
}
wxTextCtrl::wxTextCtrl( wxWindow *parent,
// a single-line text control: no need for scrollbars
m_widget =
m_text = gtk_entry_new();
+ // work around probable bug in GTK+ 2.18 when calling WriteText on a
+ // new, empty control, see http://trac.wxwidgets.org/ticket/11409
+ gtk_entry_get_text((GtkEntry*)m_text);
if (style & wxNO_BORDER)
g_object_set (m_text, "has-frame", FALSE, NULL);
if (style & wxTE_AUTO_URL)
{
GtkTextIter start, end;
- m_gdkHandCursor = gdk_cursor_new(GDK_HAND2);
- m_gdkXTermCursor = gdk_cursor_new(GDK_XTERM);
// We create our wxUrl tag here for slight efficiency gain - we
// don't have to check for the tag existance in callbacks,
{
wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
- if (from == -1 && to == -1)
- {
- from = 0;
- to = GetValue().length();
- }
-
if ( IsMultiLine() )
{
+ if (from == -1 && to == -1)
+ {
+ from = 0;
+ to = GetValue().length();
+ }
+
GtkTextIter fromi, toi;
gtk_text_buffer_get_iter_at_offset( m_buffer, &fromi, from );
gtk_text_buffer_get_iter_at_offset( m_buffer, &toi, to );
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,
+ wxT("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);
+
+ const wxGtkString
+ pangoFontString(pango_font_description_to_string(pattr->font));
+
+ wxFont font;
+ if ( font.SetNativeFontInfo(wxString(pangoFontString)) )
+ style.SetFont(font);
+
+ // TODO: set alignment, tabs and indents
+ }
+
+ return true;
+}
+
void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style)
{
gtk_widget_modify_style(m_text, style);
gtk_text_view_get_iter_at_location(GTK_TEXT_VIEW(m_text), &end, x, y);
if (!gtk_text_iter_has_tag(&end, tag))
{
- gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text),
- GTK_TEXT_WINDOW_TEXT), m_gdkXTermCursor);
+ SetCursor(wxCursor(wxCURSOR_IBEAM));
return;
}
- gdk_window_set_cursor(gtk_text_view_get_window(GTK_TEXT_VIEW(m_text),
- GTK_TEXT_WINDOW_TEXT), m_gdkHandCursor);
+ SetCursor(wxCursor(wxCURSOR_HAND));
start = end;
if(!gtk_text_iter_begins_tag(&start, tag))