#include "wx/math.h"
#endif
+#include "wx/scopeguard.h"
#include "wx/strconv.h"
#include "wx/fontutil.h" // for wxNativeFontInfo (GetNativeFontInfo())
gtk_text_iter_get_line(start) );
gtk_text_iter_forward_line(¶_end);
- wxGtkTextRemoveTagsWithPrefix(text_buffer, "WXALIGNMENT", start, end);
+ wxGtkTextRemoveTagsWithPrefix(text_buffer, "WXALIGNMENT", ¶_start, ¶_end);
GtkJustification align;
switch (attr.GetAlignment())
gtk_text_iter_get_line(start) );
gtk_text_iter_forward_line(¶_end);
- wxGtkTextRemoveTagsWithPrefix(text_buffer, "WXINDENT", start, end);
+ wxGtkTextRemoveTagsWithPrefix(text_buffer, "WXINDENT", ¶_start, ¶_end);
// Convert indent from 1/10th of a mm into pixels
float factor =
gtk_text_iter_get_line(start) );
gtk_text_iter_forward_line(¶_end);
- wxGtkTextRemoveTagsWithPrefix(text_buffer, "WXTABS", start, end);
+ wxGtkTextRemoveTagsWithPrefix(text_buffer, "WXTABS", ¶_start, ¶_end);
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://",
}
}
+//-----------------------------------------------------------------------------
+// "populate_popup" from text control and "unmap" from its poup menu
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static void
+gtk_textctrl_popup_unmap( GtkMenu *WXUNUSED(menu), wxTextCtrl* win )
+{
+ win->GTKEnableFocusOutEvent();
+}
+}
+
+extern "C" {
+static void
+gtk_textctrl_populate_popup( GtkEntry *WXUNUSED(entry), GtkMenu *menu, wxTextCtrl *win )
+{
+ win->GTKDisableFocusOutEvent();
+
+ g_signal_connect (menu, "unmap", G_CALLBACK (gtk_textctrl_popup_unmap), win );
+}
+}
//-----------------------------------------------------------------------------
// "changed"
extern "C" {
static void
-gtk_text_changed_callback( GtkWidget * WXUNUSED(widget), wxTextCtrl *win )
+gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
{
if ( win->IgnoreTextUpdate() )
return;
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);
-
+
}
+ g_object_ref(m_widget);
m_parent->DoAddChild( this );
G_CALLBACK (gtk_text_changed_callback), this);
}
+ // Catch to disable focus out handling
+ g_signal_connect (m_text, "populate_popup",
+ G_CALLBACK (gtk_textctrl_populate_popup),
+ this);
+
if (!value.empty())
{
SetValue( value );
return GTK_EDITABLE(m_text);
}
+GtkEntry *wxTextCtrl::GetEntry() const
+{
+ return GTK_ENTRY(m_text);
+}
+
// ----------------------------------------------------------------------------
// flags handling
// ----------------------------------------------------------------------------
return;
}
+ if (value.IsEmpty())
+ {
+ if ( !(flags & SetValue_SendEvent) )
+ EnableTextChangedEvents(false);
+
+ gtk_text_buffer_set_text( m_buffer, "", 0 );
+
+ if ( !(flags & SetValue_SendEvent) )
+ EnableTextChangedEvents(true);
+
+ return;
+ }
+
+#if wxUSE_UNICODE
+ const wxCharBuffer buffer(value.utf8_str());
+#else
wxFontEncoding enc = m_defaultStyle.HasFont()
? m_defaultStyle.GetFont().GetEncoding()
: wxFONTENCODING_SYSTEM;
wxLogWarning(_("Failed to set text in the text control."));
return;
}
+#endif
if ( !(flags & SetValue_SendEvent) )
{
{
EnableTextChangedEvents(true);
}
-
- // This was added after discussion on the list
- SetInsertionPoint(0);
}
void wxTextCtrl::WriteText( const wxString &text )
return;
}
+#if wxUSE_UNICODE
+ const wxCharBuffer buffer(text.utf8_str());
+#else
// check if we have a specific style for the current position
wxFontEncoding enc = wxFONTENCODING_SYSTEM;
wxTextAttr style;
wxLogWarning(_("Failed to insert text in the control."));
return;
}
+#endif
// First remove the selection if there is one
// TODO: Is there an easier GTK specific way to do this?
}
gtk_widget_set_sensitive( m_text, enable );
+ SetCursor(enable ? wxCursor(wxCURSOR_IBEAM) : wxCursor());
return true;
}
gtk_text_buffer_get_iter_at_offset( m_buffer, &fromi, from );
gtk_text_buffer_get_iter_at_offset( m_buffer, &toi, to );
- gtk_text_buffer_place_cursor( m_buffer, &toi );
- gtk_text_buffer_move_mark_by_name( m_buffer, "selection_bound", &fromi );
+ gtk_text_buffer_select_range( m_buffer, &fromi, &toi );
}
else // single line
{
//
// 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,
+ _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);
+
+ 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);