X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/0847e36eff0512bf3c50c01e8d9dcff5e693ada5..aa3e374197e99d6362468dd821935050e5074065:/src/gtk/textctrl.cpp diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 167cfcb38a..e88d1e2aed 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()) @@ -350,7 +351,7 @@ extern "C" { static void au_check_word( GtkTextIter *s, GtkTextIter *e ) { - static const char *URIPrefixes[] = + static const char *const URIPrefixes[] = { "http://", "ftp://", @@ -582,8 +583,6 @@ gtk_paste_clipboard_callback( GtkWidget *widget, wxTextCtrl *win ) // wxTextCtrl //----------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase) - BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase) EVT_CHAR(wxTextCtrl::OnChar) @@ -621,16 +620,10 @@ void wxTextCtrl::Init() 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, @@ -703,6 +696,9 @@ bool wxTextCtrl::Create( 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); @@ -759,8 +755,6 @@ bool wxTextCtrl::Create( wxWindow *parent, 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, @@ -1338,14 +1332,14 @@ void wxTextCtrl::SetSelection( long from, long to ) { 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 ); @@ -1685,6 +1679,50 @@ 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, + 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); @@ -1825,13 +1863,11 @@ void wxTextCtrl::OnUrlMouseEvent(wxMouseEvent& event) 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))