+GtkWidget* wxTextCtrl::GetConnectWidget()
+{
+ return GTK_WIDGET(m_text);
+}
+
+bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
+{
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ return (window == GTK_TEXT(m_text)->text_area);
+ }
+ else
+ {
+ return (window == GTK_ENTRY(m_text)->text_area);
+ }
+}
+
+// the font will change for subsequent text insertiongs
+bool wxTextCtrl::SetFont( const wxFont &font )
+{
+ wxCHECK_MSG( m_text != NULL, false, wxT("invalid text ctrl") );
+
+ if ( !wxTextCtrlBase::SetFont(font) )
+ {
+ // font didn't change, nothing to do
+ return false;
+ }
+
+ if ( m_windowStyle & wxTE_MULTILINE )
+ {
+ SetUpdateFont(true);
+
+ m_defaultStyle.SetFont(font);
+
+ ChangeFontGlobally();
+ }
+
+ return true;
+}
+
+void wxTextCtrl::ChangeFontGlobally()
+{
+ // this method is very inefficient and hence should be called as rarely as
+ // possible!
+ wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont,
+
+ _T("shouldn't be called for single line controls") );
+
+ wxString value = GetValue();
+ if ( !value.empty() )
+ {
+ SetUpdateFont(false);
+
+ Clear();
+ AppendText(value);
+ }
+}
+
+void wxTextCtrl::UpdateFontIfNeeded()
+{
+ if ( m_updateFont )
+ ChangeFontGlobally();
+}
+
+bool wxTextCtrl::SetForegroundColour(const wxColour& colour)
+{
+ if ( !wxControl::SetForegroundColour(colour) )
+ return false;
+
+ // update default fg colour too
+ m_defaultStyle.SetTextColour(colour);
+
+ return true;
+}
+
+bool wxTextCtrl::SetBackgroundColour( const wxColour &colour )
+{
+ wxCHECK_MSG( m_text != NULL, false, wxT("invalid text ctrl") );
+
+ if ( !wxControl::SetBackgroundColour( colour ) )
+ return false;
+
+ if (!m_widget->window)
+ return false;
+
+ if (!m_backgroundColour.Ok())
+ return false;
+
+ if (m_windowStyle & wxTE_MULTILINE)
+ {
+ GdkWindow *window = GTK_TEXT(m_text)->text_area;
+ if (!window)
+ return false;
+ m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
+ gdk_window_set_background( window, m_backgroundColour.GetColor() );
+ gdk_window_clear( window );
+ }
+
+ // change active background color too
+ m_defaultStyle.SetBackgroundColour( colour );
+
+ return true;
+}
+
+bool wxTextCtrl::SetStyle( long start, long end, const wxTextAttr& style )
+{
+ if ( m_windowStyle & wxTE_MULTILINE )
+ {
+ if ( style.IsDefault() )
+ {
+ // nothing to do
+ return true;
+ }
+
+ // VERY dirty way to do that - removes the required text and re-adds it
+ // with styling (FIXME)
+
+ gint l = gtk_text_get_length( GTK_TEXT(m_text) );
+
+ wxCHECK_MSG( start >= 0 && end <= l, false,
+ _T("invalid range in wxTextCtrl::SetStyle") );
+
+ gint old_pos = gtk_editable_get_position( GTK_EDITABLE(m_text) );
+ char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), start, end );
+ wxString tmp(text,*wxConvCurrent);
+ g_free( text );
+
+ gtk_editable_delete_text( GTK_EDITABLE(m_text), start, end );
+ gtk_editable_set_position( GTK_EDITABLE(m_text), start );
+
+ #if wxUSE_UNICODE
+ wxWX2MBbuf buf = tmp.mbc_str();
+ const char *txt = buf;
+ size_t txtlen = strlen(buf);
+ #else
+ const char *txt = tmp;
+ size_t txtlen = tmp.length();
+ #endif
+
+ // use the attributes from style which are set in it and fall back
+ // first to the default style and then to the text control default
+ // colours for the others
+ wxGtkTextInsert(m_text,
+ wxTextAttr::Combine(style, m_defaultStyle, this),
+ txt,
+ txtlen);
+
+ /* does not seem to help under GTK+ 1.2 !!!
+ gtk_editable_set_position( GTK_EDITABLE(m_text), old_pos ); */
+ SetInsertionPoint( old_pos );
+
+ return true;
+ }
+
+ // else single line
+ // cannot do this for GTK+'s Entry widget
+ return false;
+}
+
+void wxTextCtrl::DoApplyWidgetStyle(GtkRcStyle *style)
+{
+ gtk_widget_modify_style(m_text, style);
+}
+
+void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
+{
+ Cut();
+}
+
+void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
+{
+ Copy();
+}
+
+void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
+{
+ Paste();
+}
+
+void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
+{
+ Undo();
+}
+
+void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
+{
+ Redo();
+}
+
+void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
+{
+ event.Enable( CanCut() );
+}
+
+void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
+{
+ event.Enable( CanCopy() );
+}
+
+void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
+{
+ event.Enable( CanPaste() );
+}
+
+void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
+{
+ event.Enable( CanUndo() );
+}
+
+void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
+{
+ event.Enable( CanRedo() );
+}
+
+void wxTextCtrl::OnInternalIdle()
+{
+ wxCursor cursor = m_cursor;
+ if (g_globalCursor.Ok()) cursor = g_globalCursor;
+
+ if (cursor.Ok())
+ {
+ GdkWindow *window = NULL;
+ if (HasFlag(wxTE_MULTILINE))
+ window = GTK_TEXT(m_text)->text_area;
+ else
+ window = GTK_ENTRY(m_text)->text_area;
+
+ if (window)
+ gdk_window_set_cursor( window, cursor.GetCursor() );
+
+ if (!g_globalCursor.Ok())
+ cursor = *wxSTANDARD_CURSOR;
+
+ window = m_widget->window;
+ if ((window) && !(GTK_WIDGET_NO_WINDOW(m_widget)))
+ gdk_window_set_cursor( window, cursor.GetCursor() );
+ }
+
+ if (g_delayedFocus == this)
+ {
+ if (GTK_WIDGET_REALIZED(m_widget))
+ {
+ gtk_widget_grab_focus( m_widget );
+ g_delayedFocus = NULL;
+ }
+ }
+
+ if (wxUpdateUIEvent::CanUpdate(this))
+ UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
+}
+
+wxSize wxTextCtrl::DoGetBestSize() const
+{
+ // FIXME should be different for multi-line controls...
+ wxSize ret( wxControl::DoGetBestSize() );
+ wxSize best(80, ret.y);
+ CacheBestSize(best);
+ return best;
+}
+
+// ----------------------------------------------------------------------------
+// freeze/thaw
+// ----------------------------------------------------------------------------
+
+void wxTextCtrl::DoFreeze()
+{
+ if ( HasFlag(wxTE_MULTILINE) )
+ {
+ gtk_text_freeze(GTK_TEXT(m_text));
+ }
+}
+
+void wxTextCtrl::DoThaw()
+{
+ if ( HasFlag(wxTE_MULTILINE) )
+ {
+ GTK_TEXT(m_text)->vadj->value = 0.0;
+
+ gtk_text_thaw(GTK_TEXT(m_text));
+ }
+}
+
+// ----------------------------------------------------------------------------
+// scrolling
+// ----------------------------------------------------------------------------
+
+GtkAdjustment *wxTextCtrl::GetVAdj() const
+{
+ if ( !IsMultiLine() )
+ return NULL;
+
+ return GTK_TEXT(m_text)->vadj;
+}
+
+bool wxTextCtrl::DoScroll(GtkAdjustment *adj, int diff)
+{
+ float value = adj->value + diff;
+
+ if ( value < 0 )
+ value = 0;
+
+ float upper = adj->upper - adj->page_size;
+ if ( value > upper )
+ value = upper;
+
+ // did we noticeably change the scroll position?
+ if ( fabs(adj->value - value) < 0.2 )
+ {
+ // well, this is what Robert does in wxScrollBar, so it must be good...
+ return false;
+ }
+
+ adj->value = value;
+ gtk_signal_emit_by_name(GTK_OBJECT(adj), "value_changed");
+
+ return true;
+}
+
+bool wxTextCtrl::ScrollLines(int lines)
+{
+ GtkAdjustment *adj = GetVAdj();
+ if ( !adj )
+ return false;
+
+ // this is hardcoded to 10 in GTK+ 1.2 (great idea)
+ int diff = 10*lines;
+
+ return DoScroll(adj, diff);
+}
+
+bool wxTextCtrl::ScrollPages(int pages)
+{
+ GtkAdjustment *adj = GetVAdj();
+ if ( !adj )
+ return false;
+
+ return DoScroll(adj, (int)ceil(pages*adj->page_increment));
+}
+
+
+// static
+wxVisualAttributes
+wxTextCtrl::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant))
+{
+ return GetDefaultAttributesFromGTKWidget(gtk_entry_new, true);
+}