#include "wx/textctrl.h"
#ifndef WX_PRECOMP
- #include "wx/app.h"
#include "wx/intl.h"
#include "wx/log.h"
#include "wx/utils.h"
#include "wx/math.h"
#endif
+#include "wx/scopeguard.h"
#include "wx/strconv.h"
#include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
const wxArrayInt& tabs = attr.GetTabs();
- wxString tagname = _T("WXTABS");
+ wxString tagname = wxT("WXTABS");
g_snprintf(buf, sizeof(buf), "WXTABS");
for (size_t i = 0; i < tabs.GetCount(); i++)
- tagname += wxString::Format(_T(" %d"), tabs[i]);
+ tagname += wxString::Format(wxT(" %d"), tabs[i]);
const wxWX2MBbuf buftag = tagname.utf8_str();
static void
au_check_word( GtkTextIter *s, GtkTextIter *e )
{
- static const char *URIPrefixes[] =
+ static const char *const URIPrefixes[] =
{
"http://",
"ftp://",
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,
GTKSetWrapMode();
- GtkScrolledWindowSetBorder(m_widget, style);
+ GTKScrolledWindowSetBorder(m_widget, style);
gtk_widget_add_events( GTK_WIDGET(m_text), GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK );
// 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,
return GTK_EDITABLE(m_text);
}
+GtkEntry *wxTextCtrl::GetEntry() const
+{
+ return GTK_ENTRY(m_text);
+}
+
// ----------------------------------------------------------------------------
// flags handling
// ----------------------------------------------------------------------------
}
gtk_widget_set_sensitive( m_text, enable );
+ SetCursor(enable ? wxCursor(wxCURSOR_IBEAM) : wxCursor());
return true;
}
{
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 );
//
// TODO: it can be implemented much more efficiently for GTK2
wxASSERT_MSG( IsMultiLine(),
- _T("shouldn't be called for single line controls") );
+ wxT("shouldn't be called for single line controls") );
wxString value = GetValue();
if ( !value.empty() )
gint l = gtk_text_buffer_get_char_count( m_buffer );
wxCHECK_MSG( start >= 0 && end <= l, false,
- _T("invalid range in wxTextCtrl::SetStyle") );
+ wxT("invalid range in wxTextCtrl::SetStyle") );
GtkTextIter starti, endi;
gtk_text_buffer_get_iter_at_offset( m_buffer, &starti, start );
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))