1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling, Vadim Zeitlin
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "textctrl.h"
14 #include "wx/textctrl.h"
18 #include "wx/settings.h"
20 #include <sys/types.h>
26 #include "gdk/gdkkeysyms.h"
28 //-----------------------------------------------------------------------------
30 //-----------------------------------------------------------------------------
32 extern void wxapp_install_idle_handler();
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 extern bool g_blockEventsOnDrag;
40 extern wxCursor g_globalCursor;
42 //-----------------------------------------------------------------------------
44 //-----------------------------------------------------------------------------
47 gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
49 if (!win->m_hasVMT) return;
52 wxapp_install_idle_handler();
55 win->UpdateFontIfNeeded();
57 wxCommandEvent event( wxEVT_COMMAND_TEXT_UPDATED, win->GetId() );
58 event.SetString( win->GetValue() );
59 event.SetEventObject( win );
60 win->GetEventHandler()->ProcessEvent( event );
63 //-----------------------------------------------------------------------------
64 // "changed" from vertical scrollbar
65 //-----------------------------------------------------------------------------
68 gtk_scrollbar_changed_callback( GtkWidget *WXUNUSED(widget), wxTextCtrl *win )
70 if (!win->m_hasVMT) return;
73 wxapp_install_idle_handler();
75 win->CalculateScrollbar();
78 //-----------------------------------------------------------------------------
80 //-----------------------------------------------------------------------------
82 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl,wxControl)
84 BEGIN_EVENT_TABLE(wxTextCtrl, wxControl)
85 EVT_CHAR(wxTextCtrl::OnChar)
87 EVT_MENU(wxID_CUT, wxTextCtrl::OnCut)
88 EVT_MENU(wxID_COPY, wxTextCtrl::OnCopy)
89 EVT_MENU(wxID_PASTE, wxTextCtrl::OnPaste)
90 EVT_MENU(wxID_UNDO, wxTextCtrl::OnUndo)
91 EVT_MENU(wxID_REDO, wxTextCtrl::OnRedo)
93 EVT_UPDATE_UI(wxID_CUT, wxTextCtrl::OnUpdateCut)
94 EVT_UPDATE_UI(wxID_COPY, wxTextCtrl::OnUpdateCopy)
95 EVT_UPDATE_UI(wxID_PASTE, wxTextCtrl::OnUpdatePaste)
96 EVT_UPDATE_UI(wxID_UNDO, wxTextCtrl::OnUpdateUndo)
97 EVT_UPDATE_UI(wxID_REDO, wxTextCtrl::OnUpdateRedo)
100 void wxTextCtrl::Init()
103 m_updateFont = FALSE;
105 m_vScrollbar = (GtkWidget *)NULL;
108 wxTextCtrl::wxTextCtrl( wxWindow *parent,
110 const wxString &value,
114 const wxValidator& validator,
115 const wxString &name )
119 Create( parent, id, value, pos, size, style, validator, name );
122 bool wxTextCtrl::Create( wxWindow *parent,
124 const wxString &value,
128 const wxValidator& validator,
129 const wxString &name )
132 m_acceptsFocus = TRUE;
134 if (!PreCreation( parent, pos, size ) ||
135 !CreateBase( parent, id, pos, size, style, validator, name ))
137 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
142 m_vScrollbarVisible = FALSE;
144 bool multi_line = (style & wxTE_MULTILINE) != 0;
147 #if (GTK_MINOR_VERSION > 2)
148 /* a multi-line edit control: create a vertical scrollbar by default and
149 horizontal if requested */
150 bool bHasHScrollbar = (style & wxHSCROLL) != 0;
152 bool bHasHScrollbar = FALSE;
155 /* create our control ... */
156 m_text = gtk_text_new( (GtkAdjustment *) NULL, (GtkAdjustment *) NULL );
158 /* ... and put into the upper left hand corner of the table */
159 m_widget = gtk_table_new(bHasHScrollbar ? 2 : 1, 2, FALSE);
160 GTK_WIDGET_UNSET_FLAGS( m_widget, GTK_CAN_FOCUS );
161 gtk_table_attach( GTK_TABLE(m_widget), m_text, 0, 1, 0, 1,
162 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
163 (GtkAttachOptions)(GTK_FILL | GTK_EXPAND | GTK_SHRINK),
166 /* always wrap words */
167 gtk_text_set_word_wrap( GTK_TEXT(m_text), TRUE );
169 #if (GTK_MINOR_VERSION > 2)
170 /* put the horizontal scrollbar in the lower left hand corner */
173 GtkWidget *hscrollbar = gtk_hscrollbar_new(GTK_TEXT(m_text)->hadj);
174 GTK_WIDGET_UNSET_FLAGS( hscrollbar, GTK_CAN_FOCUS );
175 gtk_table_attach(GTK_TABLE(m_widget), hscrollbar, 0, 1, 1, 2,
176 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK),
179 gtk_widget_show(hscrollbar);
181 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
182 gtk_text_set_line_wrap( GTK_TEXT(m_text), FALSE );
186 /* finally, put the vertical scrollbar in the upper right corner */
187 m_vScrollbar = gtk_vscrollbar_new( GTK_TEXT(m_text)->vadj );
188 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar, GTK_CAN_FOCUS );
189 gtk_table_attach(GTK_TABLE(m_widget), m_vScrollbar, 1, 2, 0, 1,
191 (GtkAttachOptions)(GTK_EXPAND | GTK_FILL | GTK_SHRINK),
196 /* a single-line text control: no need for scrollbars */
198 m_text = gtk_entry_new();
201 m_parent->DoAddChild( this );
205 SetFont( parent->GetFont() );
207 wxSize size_best( DoGetBestSize() );
208 wxSize new_size( size );
209 if (new_size.x == -1)
210 new_size.x = size_best.x;
211 if (new_size.y == -1)
212 new_size.y = size_best.y;
213 if ((new_size.x != size.x) || (new_size.y != size.y))
214 SetSize( new_size.x, new_size.y );
217 gtk_widget_show(m_text);
219 /* we want to be notified about text changes */
220 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
221 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
225 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text)->vadj), "changed",
226 (GtkSignalFunc) gtk_scrollbar_changed_callback, (gpointer) this );
229 if (!value.IsEmpty())
233 #if GTK_MINOR_VERSION == 0
234 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
235 // gtk_editable_insert_text()
236 gtk_widget_realize(m_text);
240 wxWX2MBbuf val = value.mbc_str();
241 gtk_editable_insert_text( GTK_EDITABLE(m_text), val, strlen(val), &tmp );
243 gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &tmp );
244 #endif // Unicode/!Unicode
248 /* bring editable's cursor uptodate. bug in GTK. */
250 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
254 if (style & wxTE_PASSWORD)
257 gtk_entry_set_visibility( GTK_ENTRY(m_text), FALSE );
260 if (style & wxTE_READONLY)
263 gtk_entry_set_editable( GTK_ENTRY(m_text), FALSE );
268 gtk_text_set_editable( GTK_TEXT(m_text), 1 );
271 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW) );
272 SetForegroundColour( parent->GetForegroundColour() );
274 m_cursor = wxCursor( wxCURSOR_IBEAM );
281 void wxTextCtrl::CalculateScrollbar()
283 if ((m_windowStyle & wxTE_MULTILINE) == 0) return;
285 GtkAdjustment *adj = GTK_TEXT(m_text)->vadj;
287 if (adj->upper - adj->page_size < 0.8)
289 if (m_vScrollbarVisible)
291 gtk_widget_hide( m_vScrollbar );
292 m_vScrollbarVisible = FALSE;
297 if (!m_vScrollbarVisible)
299 gtk_widget_show( m_vScrollbar );
300 m_vScrollbarVisible = TRUE;
305 wxString wxTextCtrl::GetValue() const
307 wxCHECK_MSG( m_text != NULL, wxT(""), wxT("invalid text ctrl") );
310 if (m_windowStyle & wxTE_MULTILINE)
312 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
313 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
314 tmp = wxString(text,*wxConvCurrent);
319 tmp = wxString(gtk_entry_get_text( GTK_ENTRY(m_text) ),*wxConvCurrent);
324 void wxTextCtrl::SetValue( const wxString &value )
326 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
328 if (m_windowStyle & wxTE_MULTILINE)
330 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
331 gtk_editable_delete_text( GTK_EDITABLE(m_text), 0, len );
334 wxWX2MBbuf tmpbuf = value.mbc_str();
335 gtk_editable_insert_text( GTK_EDITABLE(m_text), tmpbuf, strlen(tmpbuf), &len );
337 gtk_editable_insert_text( GTK_EDITABLE(m_text), value.mbc_str(), value.Length(), &len );
342 gtk_entry_set_text( GTK_ENTRY(m_text), value.mbc_str() );
345 // GRG, Jun/2000: Changed this after a lot of discussion in
346 // the lists. wxWindows 2.2 will have a set of flags to
347 // customize this behaviour.
348 SetInsertionPoint(0);
353 void wxTextCtrl::WriteText( const wxString &text )
355 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
357 if (text.IsEmpty()) return;
359 if (m_windowStyle & wxTE_MULTILINE)
361 /* this moves the cursor pos to behind the inserted text */
362 gint len = GTK_EDITABLE(m_text)->current_pos;
365 wxWX2MBbuf buf = text.mbc_str();
366 gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
368 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
371 /* bring editable's cursor uptodate. bug in GTK. */
372 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
376 /* this moves the cursor pos to behind the inserted text */
377 gint len = GTK_EDITABLE(m_text)->current_pos;
379 wxWX2MBbuf buf = text.mbc_str();
380 gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
382 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
385 /* bring editable's cursor uptodate. bug in GTK. */
386 GTK_EDITABLE(m_text)->current_pos += text.Len();
388 /* bring entry's cursor uptodate. bug in GTK. */
389 gtk_entry_set_position( GTK_ENTRY(m_text), GTK_EDITABLE(m_text)->current_pos );
393 void wxTextCtrl::AppendText( const wxString &text )
395 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
397 if (text.IsEmpty()) return;
399 if (m_windowStyle & wxTE_MULTILINE)
401 bool hasSpecialAttributes = m_font.Ok() ||
402 m_foregroundColour.Ok() ||
403 m_backgroundColour.Ok();
404 if ( hasSpecialAttributes )
406 gtk_text_insert( GTK_TEXT(m_text),
407 m_font.GetInternalFont(),
408 m_foregroundColour.GetColor(),
409 m_backgroundColour.GetColor(),
410 text.mbc_str(), text.length());
415 /* we'll insert at the last position */
416 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
418 wxWX2MBbuf buf = text.mbc_str();
419 gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &len );
421 gtk_editable_insert_text( GTK_EDITABLE(m_text), text, text.Length(), &len );
425 /* bring editable's cursor uptodate. bug in GTK. */
426 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
430 gtk_entry_append_text( GTK_ENTRY(m_text), text.mbc_str() );
434 wxString wxTextCtrl::GetLineText( long lineNo ) const
436 if (m_windowStyle & wxTE_MULTILINE)
438 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
439 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
443 wxString buf(wxT(""));
446 for (i = 0; currentLine != lineNo && text[i]; i++ )
451 for (j = 0; text[i] && text[i] != '\n'; i++, j++ )
458 return wxEmptyString;
462 if (lineNo == 0) return GetValue();
463 return wxEmptyString;
467 void wxTextCtrl::OnDropFiles( wxDropFilesEvent &WXUNUSED(event) )
469 /* If you implement this, don't forget to update the documentation!
470 * (file docs/latex/wx/text.tex) */
471 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
474 bool wxTextCtrl::PositionToXY(long pos, long *x, long *y ) const
476 if ( m_windowStyle & wxTE_MULTILINE )
478 wxString text = GetValue();
480 // cast to prevent warning. But pos really should've been unsigned.
481 if( (unsigned long)pos > text.Len() )
487 const wxChar* stop = text.c_str() + pos;
488 for ( const wxChar *p = text.c_str(); p < stop; p++ )
499 else // single line control
501 if ( pos <= GTK_ENTRY(m_text)->text_length )
508 // index out of bounds
516 long wxTextCtrl::XYToPosition(long x, long y ) const
518 if (!(m_windowStyle & wxTE_MULTILINE)) return 0;
521 for( int i=0; i<y; i++ ) pos += GetLineLength(i) + 1; // one for '\n'
527 int wxTextCtrl::GetLineLength(long lineNo) const
529 wxString str = GetLineText (lineNo);
530 return (int) str.Length();
533 int wxTextCtrl::GetNumberOfLines() const
535 if (m_windowStyle & wxTE_MULTILINE)
537 gint len = gtk_text_get_length( GTK_TEXT(m_text) );
538 char *text = gtk_editable_get_chars( GTK_EDITABLE(m_text), 0, len );
543 for (int i = 0; i < len; i++ )
550 // currentLine is 0 based, add 1 to get number of lines
551 return currentLine + 1;
564 void wxTextCtrl::SetInsertionPoint( long pos )
566 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
568 if (m_windowStyle & wxTE_MULTILINE)
570 /* seems to be broken in GTK 1.0.X:
571 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
573 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text),
574 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
576 /* we fake a set_point by inserting and deleting. as the user
577 isn't supposed to get to know about thos non-sense, we
578 disconnect so that no events are sent to the user program. */
580 gint tmp = (gint)pos;
581 gtk_editable_insert_text( GTK_EDITABLE(m_text), " ", 1, &tmp );
582 gtk_editable_delete_text( GTK_EDITABLE(m_text), tmp-1, tmp );
584 gtk_signal_connect( GTK_OBJECT(m_text), "changed",
585 GTK_SIGNAL_FUNC(gtk_text_changed_callback), (gpointer)this);
587 /* bring editable's cursor uptodate. another bug in GTK. */
589 GTK_EDITABLE(m_text)->current_pos = gtk_text_get_point( GTK_TEXT(m_text) );
593 gtk_entry_set_position( GTK_ENTRY(m_text), (int)pos );
595 /* bring editable's cursor uptodate. bug in GTK. */
597 GTK_EDITABLE(m_text)->current_pos = (guint32)pos;
601 void wxTextCtrl::SetInsertionPointEnd()
603 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
605 if (m_windowStyle & wxTE_MULTILINE)
606 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text)));
608 gtk_entry_set_position( GTK_ENTRY(m_text), -1 );
611 void wxTextCtrl::SetEditable( bool editable )
613 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
615 if (m_windowStyle & wxTE_MULTILINE)
616 gtk_text_set_editable( GTK_TEXT(m_text), editable );
618 gtk_entry_set_editable( GTK_ENTRY(m_text), editable );
621 bool wxTextCtrl::Enable( bool enable )
623 if (!wxWindowBase::Enable(enable))
629 if (m_windowStyle & wxTE_MULTILINE)
631 gtk_text_set_editable( GTK_TEXT(m_text), enable );
635 gtk_widget_set_sensitive( m_text, enable );
641 void wxTextCtrl::DiscardEdits()
646 void wxTextCtrl::SetSelection( long from, long to )
648 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
650 if ( (m_windowStyle & wxTE_MULTILINE) &&
651 !GTK_TEXT(m_text)->line_start_cache )
653 // tell the programmer that it didn't work
654 wxLogDebug(_T("Can't call SetSelection() before realizing the control"));
658 gtk_editable_select_region( GTK_EDITABLE(m_text), (gint)from, (gint)to );
661 void wxTextCtrl::ShowPosition( long WXUNUSED(pos) )
663 // SetInsertionPoint( pos );
666 long wxTextCtrl::GetInsertionPoint() const
668 wxCHECK_MSG( m_text != NULL, 0, wxT("invalid text ctrl") );
670 return (long) GTK_EDITABLE(m_text)->current_pos;
673 long wxTextCtrl::GetLastPosition() const
675 wxCHECK_MSG( m_text != NULL, 0, wxT("invalid text ctrl") );
678 if (m_windowStyle & wxTE_MULTILINE)
679 pos = gtk_text_get_length( GTK_TEXT(m_text) );
681 pos = GTK_ENTRY(m_text)->text_length;
686 void wxTextCtrl::Remove( long from, long to )
688 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
690 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
693 void wxTextCtrl::Replace( long from, long to, const wxString &value )
695 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
697 gtk_editable_delete_text( GTK_EDITABLE(m_text), (gint)from, (gint)to );
699 if (!value.IsEmpty())
701 gint pos = (gint)from;
703 wxWX2MBbuf buf = value.mbc_str();
704 gtk_editable_insert_text( GTK_EDITABLE(m_text), buf, strlen(buf), &pos );
706 gtk_editable_insert_text( GTK_EDITABLE(m_text), value, value.Length(), &pos );
711 void wxTextCtrl::Cut()
713 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
715 #if (GTK_MINOR_VERSION > 0)
716 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text) );
718 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text), 0 );
722 void wxTextCtrl::Copy()
724 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
726 #if (GTK_MINOR_VERSION > 0)
727 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text) );
729 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text), 0 );
733 void wxTextCtrl::Paste()
735 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
737 #if (GTK_MINOR_VERSION > 0)
738 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text) );
740 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text), 0 );
744 bool wxTextCtrl::CanCopy() const
746 // Can copy if there's a selection
748 GetSelection(& from, & to);
749 return (from != to) ;
752 bool wxTextCtrl::CanCut() const
754 // Can cut if there's a selection
756 GetSelection(& from, & to);
757 return (from != to) && (IsEditable());
760 bool wxTextCtrl::CanPaste() const
762 return IsEditable() ;
766 void wxTextCtrl::Undo()
769 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
772 void wxTextCtrl::Redo()
775 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
778 bool wxTextCtrl::CanUndo() const
781 wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
785 bool wxTextCtrl::CanRedo() const
788 wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
792 // If the return values from and to are the same, there is no
794 void wxTextCtrl::GetSelection(long* from, long* to) const
796 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
798 if (!(GTK_EDITABLE(m_text)->has_selection))
800 long i = GetInsertionPoint();
806 if (from) *from = (long) GTK_EDITABLE(m_text)->selection_start_pos;
807 if (to) *to = (long) GTK_EDITABLE(m_text)->selection_end_pos;
810 bool wxTextCtrl::IsEditable() const
812 wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
814 return GTK_EDITABLE(m_text)->editable;
817 bool wxTextCtrl::IsModified() const
822 void wxTextCtrl::Clear()
827 void wxTextCtrl::OnChar( wxKeyEvent &key_event )
829 wxCHECK_RET( m_text != NULL, wxT("invalid text ctrl") );
831 if ((key_event.KeyCode() == WXK_RETURN) && (m_windowStyle & wxPROCESS_ENTER))
833 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId);
834 event.SetEventObject(this);
835 event.SetString(GetValue());
836 if (GetEventHandler()->ProcessEvent(event)) return;
839 if ((key_event.KeyCode() == WXK_RETURN) && !(m_windowStyle & wxTE_MULTILINE))
841 wxWindow *top_frame = m_parent;
842 while (top_frame->GetParent() && !(top_frame->IsTopLevel()))
843 top_frame = top_frame->GetParent();
844 GtkWindow *window = GTK_WINDOW(top_frame->m_widget);
846 if (window->default_widget)
848 gtk_widget_activate (window->default_widget);
856 GtkWidget* wxTextCtrl::GetConnectWidget()
858 return GTK_WIDGET(m_text);
861 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow *window )
863 if (m_windowStyle & wxTE_MULTILINE)
864 return (window == GTK_TEXT(m_text)->text_area);
866 return (window == GTK_ENTRY(m_text)->text_area);
869 // the font will change for subsequent text insertiongs
870 bool wxTextCtrl::SetFont( const wxFont &font )
872 wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
874 if ( !wxWindowBase::SetFont(font) )
876 // font didn't change, nothing to do
880 if ( m_windowStyle & wxTE_MULTILINE )
884 ChangeFontGlobally();
890 void wxTextCtrl::ChangeFontGlobally()
892 // this method is very inefficient and hence should be called as rarely as
894 wxASSERT_MSG( (m_windowStyle & wxTE_MULTILINE) && m_updateFont,
895 _T("shouldn't be called for single line controls") );
897 wxString value = GetValue();
898 if ( !value.IsEmpty() )
903 m_updateFont = FALSE;
907 void wxTextCtrl::UpdateFontIfNeeded()
910 ChangeFontGlobally();
913 bool wxTextCtrl::SetForegroundColour( const wxColour &WXUNUSED(colour) )
915 wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
921 bool wxTextCtrl::SetBackgroundColour( const wxColour &colour )
923 wxCHECK_MSG( m_text != NULL, FALSE, wxT("invalid text ctrl") );
925 wxControl::SetBackgroundColour( colour );
927 if (!m_widget->window)
930 wxColour sysbg = wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE );
931 if (sysbg.Red() == colour.Red() &&
932 sysbg.Green() == colour.Green() &&
933 sysbg.Blue() == colour.Blue())
935 return FALSE; // FIXME or TRUE?
938 if (!m_backgroundColour.Ok())
941 if (m_windowStyle & wxTE_MULTILINE)
943 GdkWindow *window = GTK_TEXT(m_text)->text_area;
946 m_backgroundColour.CalcPixel( gdk_window_get_colormap( window ) );
947 gdk_window_set_background( window, m_backgroundColour.GetColor() );
948 gdk_window_clear( window );
954 void wxTextCtrl::ApplyWidgetStyle()
956 if (m_windowStyle & wxTE_MULTILINE)
963 gtk_widget_set_style( m_text, m_widgetStyle );
967 void wxTextCtrl::OnCut(wxCommandEvent& WXUNUSED(event))
972 void wxTextCtrl::OnCopy(wxCommandEvent& WXUNUSED(event))
977 void wxTextCtrl::OnPaste(wxCommandEvent& WXUNUSED(event))
982 void wxTextCtrl::OnUndo(wxCommandEvent& WXUNUSED(event))
987 void wxTextCtrl::OnRedo(wxCommandEvent& WXUNUSED(event))
992 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent& event)
994 event.Enable( CanCut() );
997 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent& event)
999 event.Enable( CanCopy() );
1002 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent& event)
1004 event.Enable( CanPaste() );
1007 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent& event)
1009 event.Enable( CanUndo() );
1012 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent& event)
1014 event.Enable( CanRedo() );
1017 void wxTextCtrl::OnInternalIdle()
1019 wxCursor cursor = m_cursor;
1020 if (g_globalCursor.Ok()) cursor = g_globalCursor;
1024 GdkWindow *window = (GdkWindow*) NULL;
1025 if (HasFlag(wxTE_MULTILINE))
1026 window = GTK_TEXT(m_text)->text_area;
1028 window = GTK_ENTRY(m_text)->text_area;
1031 gdk_window_set_cursor( window, cursor.GetCursor() );
1033 if (!g_globalCursor.Ok())
1034 cursor = *wxSTANDARD_CURSOR;
1036 window = m_widget->window;
1037 if ((window) && !(GTK_WIDGET_NO_WINDOW(m_widget)))
1038 gdk_window_set_cursor( window, cursor.GetCursor() );
1044 wxSize wxTextCtrl::DoGetBestSize() const
1046 // FIXME should be different for multi-line controls...
1047 wxSize ret( wxControl::DoGetBestSize() );
1048 return wxSize(80, ret.y);