+ // If we have a custom background colour, we use this colour in both
+ // disabled and enabled mode, or we end up with a different colour under the
+ // text.
+ wxColour oldColour = GetBackgroundColour();
+ if (oldColour.Ok())
+ {
+ // Need to set twice or it'll optimize the useful stuff out
+ if (oldColour == * wxWHITE)
+ SetBackgroundColour(*wxBLACK);
+ else
+ SetBackgroundColour(*wxWHITE);
+ SetBackgroundColour(oldColour);
+ }
+}
+
+void wxTextCtrl::DiscardEdits()
+{
+ m_modified = FALSE;
+}
+
+// ----------------------------------------------------------------------------
+// max text length support
+// ----------------------------------------------------------------------------
+
+void wxTextCtrl::IgnoreNextTextUpdate()
+{
+ m_ignoreNextUpdate = TRUE;
+}
+
+bool wxTextCtrl::IgnoreTextUpdate()
+{
+ if ( m_ignoreNextUpdate )
+ {
+ m_ignoreNextUpdate = FALSE;
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void wxTextCtrl::SetMaxLength(unsigned long len)
+{
+ if ( !HasFlag(wxTE_MULTILINE) )
+ {
+ gtk_entry_set_max_length(GTK_ENTRY(m_text), len);
+
+ // there is a bug in GTK+ 1.2.x: "changed" signal is emitted even if
+ // we had tried to enter more text than allowed by max text length and
+ // the text wasn't really changed
+ //
+ // to detect this and generate TEXT_MAXLEN event instead of
+ // TEXT_CHANGED one in this case we also catch "insert_text" signal
+ //
+ // when max len is set to 0 we disconnect our handler as it means that
+ // we shouldn't check anything any more
+ if ( len )
+ {
+ gtk_signal_connect( GTK_OBJECT(m_text),
+ "insert_text",
+ GTK_SIGNAL_FUNC(gtk_insert_text_callback),
+ (gpointer)this);
+ }
+ else // no checking
+ {
+ gtk_signal_disconnect_by_func
+ (
+ GTK_OBJECT(m_text),
+ GTK_SIGNAL_FUNC(gtk_insert_text_callback),
+ (gpointer)this
+ );
+ }
+ }
+}
+
+void wxTextCtrl::SetSelection( long from, long to )
+{
+ wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
+
+ if ( (m_windowStyle & wxTE_MULTILINE) &&
+ !GTK_TEXT(m_text)->line_start_cache )
+ {
+ // tell the programmer that it didn't work
+ wxLogDebug(_T("Can't call SetSelection() before realizing the control"));
+ return;
+ }
+
+ gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to );
+}
+
+void wxTextCtrl::ShowPosition( long WXUNUSED(pos) )
+{
+// SetInsertionPoint( pos );
+}
+
+long wxTextCtrl::GetInsertionPoint() const
+{
+ wxCHECK_MSG( m_text != NULL, 0, wxT("invalid text ctrl") );
+
+ return (long) GTK_EDITABLE(m_text)->current_pos;
+}
+
+long wxTextCtrl::GetLastPosition() const
+{
+ wxCHECK_MSG( m_text != NULL, 0, wxT("invalid text ctrl") );
+
+ int pos = 0;
+ if (m_windowStyle & wxTE_MULTILINE)
+ pos = gtk_text_get_length( GTK_TEXT(m_text) );
+ else
+ pos = GTK_ENTRY(m_text)->text_length;
+
+ return (long)pos;
+}
+
+void wxTextCtrl::Remove( long from, long to )
+{
+ wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
+
+ gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
+}
+
+void wxTextCtrl::Replace( long from, long to, const wxString &value )
+{
+ wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
+
+ gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
+
+ if (!value.IsEmpty())
+ {
+ gint pos = (gint)from;
+#if wxUSE_UNICODE
+ wxWX2MBbuf buf = value.mbc_str();
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos );
+#else
+ gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos );
+#endif
+ }
+}
+
+void wxTextCtrl::Cut()
+{
+ wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
+
+#if (GTK_MINOR_VERSION > 0)
+ gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) );
+#else
+ gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 );
+#endif
+}
+
+void wxTextCtrl::Copy()
+{
+ wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
+
+#if (GTK_MINOR_VERSION > 0)
+ gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) );
+#else
+ gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 );
+#endif
+}
+
+void wxTextCtrl::Paste()
+{
+ wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );