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"
17 #include "wx/settings.h"
19 #include <sys/types.h>
25 #include "gdk/gdkkeysyms.h"
27 //-----------------------------------------------------------------------------
29 //-----------------------------------------------------------------------------
31 extern void wxapp_install_idle_handler();
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 extern bool g_blockEventsOnDrag
;
40 //-----------------------------------------------------------------------------
42 //-----------------------------------------------------------------------------
45 gtk_text_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
47 if (g_isIdle
) wxapp_install_idle_handler();
49 if (!win
->m_hasVMT
) return;
53 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->m_windowId
);
54 event
.SetString( win
->GetValue() );
55 event
.SetEventObject( win
);
56 win
->GetEventHandler()->ProcessEvent( event
);
59 //-----------------------------------------------------------------------------
60 // "changed" from vertical scrollbar
61 //-----------------------------------------------------------------------------
64 gtk_scrollbar_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
66 if (g_isIdle
) wxapp_install_idle_handler();
68 win
->CalculateScrollbar();
70 if (!win
->m_hasVMT
) return;
73 //-----------------------------------------------------------------------------
75 //-----------------------------------------------------------------------------
77 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
79 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
80 EVT_CHAR(wxTextCtrl::OnChar
)
82 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
83 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
84 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
85 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
86 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
88 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
89 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
90 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
91 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
92 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
95 #ifndef NO_TEXT_WINDOW_STREAM
96 wxTextCtrl::wxTextCtrl() : streambuf()
98 if (allocate()) setp(base(),ebuf());
103 wxTextCtrl::wxTextCtrl()
109 #ifndef NO_TEXT_WINDOW_STREAM
110 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
111 const wxPoint
&pos
, const wxSize
&size
,
112 int style
, const wxValidator
& validator
, const wxString
&name
) : streambuf()
114 if (allocate()) setp(base(),ebuf());
117 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
120 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
121 const wxPoint
&pos
, const wxSize
&size
,
122 int style
, const wxValidator
& validator
, const wxString
&name
)
125 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
129 bool wxTextCtrl::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
130 const wxPoint
&pos
, const wxSize
&size
,
131 int style
, const wxValidator
& validator
, const wxString
&name
)
134 m_acceptsFocus
= TRUE
;
136 PreCreation( parent
, id
, pos
, size
, style
, name
);
138 SetValidator( validator
);
140 m_vScrollbarVisible
= FALSE
;
142 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
145 /* a multi-line edit control: create a vertical scrollbar by default and
146 horizontal if requested */
147 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
149 /* create our control ... */
150 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
152 /* ... and put into the upper left hand corner of the table */
153 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
154 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
156 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
157 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
158 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
161 /* always wrap words */
162 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
164 /* put the horizontal scrollbar in the lower left hand corner */
167 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
168 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
170 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
171 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
),
174 gtk_widget_show(hscrollbar
);
176 #if (GTK_MINOR_VERSION > 0)
177 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
178 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
182 /* finally, put the vertical scrollbar in the upper right corner */
183 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
184 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
186 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
188 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
193 /* a single-line text control: no need for scrollbars */
195 m_text
= gtk_entry_new();
198 wxSize newSize
= size
;
199 if (newSize
.x
== -1) newSize
.x
= 80;
200 if (newSize
.y
== -1) newSize
.y
= 26;
201 SetSize( newSize
.x
, newSize
.y
);
203 m_parent
->AddChild( this );
205 (m_parent
->m_insertCallback
)( m_parent
, this );
210 gtk_widget_show(m_text
);
212 /* we want to be notified about text changes */
213 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
214 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
218 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
219 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
222 if (!value
.IsEmpty())
226 #if GTK_MINOR_VERSION == 0
227 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
228 // gtk_editable_insert_text()
229 gtk_widget_realize(m_text
);
233 wxWX2MBbuf val
= value
.mbc_str();
234 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
236 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
237 #endif // Unicode/!Unicode
241 /* bring editable's cursor uptodate. bug in GTK. */
243 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
247 if (style
& wxTE_PASSWORD
)
250 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
253 if (style
& wxTE_READONLY
)
256 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
261 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
264 SetBackgroundColour( parent
->GetBackgroundColour() );
265 SetForegroundColour( parent
->GetForegroundColour() );
272 void wxTextCtrl::CalculateScrollbar()
274 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
276 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
278 if (adj
->upper
- adj
->page_size
< 0.8)
280 if (m_vScrollbarVisible
)
282 gtk_widget_hide( m_vScrollbar
);
284 m_vScrollbarVisible
= FALSE
;
289 if (!m_vScrollbarVisible
)
291 gtk_widget_show( m_vScrollbar
);
293 m_vScrollbarVisible
= TRUE
;
298 wxString
wxTextCtrl::GetValue() const
300 wxCHECK_MSG( m_text
!= NULL
, _T(""), _T("invalid text ctrl") );
303 if (m_windowStyle
& wxTE_MULTILINE
)
305 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
306 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
307 tmp
= wxString(text
,*wxConv_current
);
312 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConv_current
);
317 void wxTextCtrl::SetValue( const wxString
&value
)
319 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
321 wxString tmp
= _T("");
322 if (!value
.IsNull()) tmp
= value
;
323 if (m_windowStyle
& wxTE_MULTILINE
)
325 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
326 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
329 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
330 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
332 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
337 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
341 void wxTextCtrl::WriteText( const wxString
&text
)
343 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
345 if (text
.IsNull()) return;
347 if (m_windowStyle
& wxTE_MULTILINE
)
349 /* this moves the cursor pos to behind the inserted text */
350 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
353 wxWX2MBbuf buf
= text
.mbc_str();
354 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
356 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
359 /* bring editable's cursor uptodate. bug in GTK. */
360 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
364 /* this moves the cursor pos to behind the inserted text */
365 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
367 wxWX2MBbuf buf
= text
.mbc_str();
368 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
370 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
373 /* bring editable's cursor uptodate. bug in GTK. */
374 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
376 /* bring entry's cursor uptodate. bug in GTK. */
377 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
381 void wxTextCtrl::AppendText( const wxString
&text
)
383 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
385 if (m_windowStyle
& wxTE_MULTILINE
)
387 /* we'll insert at the last position */
388 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
390 wxWX2MBbuf buf
= text
.mbc_str();
391 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
393 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
396 /* bring editable's cursor uptodate. bug in GTK. */
397 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
401 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
405 bool wxTextCtrl::LoadFile( const wxString
&file
)
407 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
409 if (!wxFileExists(file
)) return FALSE
;
413 FILE *fp
= (FILE*) NULL
;
416 if ((stat (FNSTRINGCAST file
.fn_str(), &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
417 !(fp
= fopen (FNSTRINGCAST file
.fn_str(), "r")))
423 gint len
= statb
.st_size
;
425 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
430 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
437 if (m_windowStyle
& wxTE_MULTILINE
)
440 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
444 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
454 bool wxTextCtrl::SaveFile( const wxString
&file
)
456 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
458 if (file
== _T("")) return FALSE
;
462 if (!(fp
= fopen (FNSTRINGCAST file
.fn_str(), "w")))
468 char *text
= (char*) NULL
;
471 if (m_windowStyle
& wxTE_MULTILINE
)
473 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
474 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
478 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
481 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
483 // Did not write whole file
486 // Make sure newline terminates the file
487 if (text
[len
- 1] != '\n')
492 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
501 wxString
wxTextCtrl::GetLineText( long lineNo
) const
503 if (m_windowStyle
& wxTE_MULTILINE
)
505 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
506 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
510 wxString
buf(_T(""));
513 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
518 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
525 return wxEmptyString
;
529 if (lineNo
== 0) return GetValue();
530 return wxEmptyString
;
534 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
536 /* If you implement this, don't forget to update the documentation!
537 * (file docs/latex/wx/text.tex) */
538 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
541 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
543 if ( m_windowStyle
& wxTE_MULTILINE
)
545 wxString text
= GetValue();
547 // cast to prevent warning. But pos really should've been unsigned.
548 if( (unsigned long)pos
> text
.Len() )
554 const wxChar
* stop
= text
.c_str() + pos
;
555 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
566 else // single line control
568 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
575 // index out of bounds
583 long wxTextCtrl::XYToPosition(long x
, long y
) const
585 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
588 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
594 int wxTextCtrl::GetLineLength(long lineNo
) const
596 wxString str
= GetLineText (lineNo
);
597 return (int) str
.Length();
600 int wxTextCtrl::GetNumberOfLines() const
602 if (m_windowStyle
& wxTE_MULTILINE
)
604 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
605 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
610 for (int i
= 0; i
< len
; i
++ )
617 // currentLine is 0 based, add 1 to get number of lines
618 return currentLine
+ 1;
631 void wxTextCtrl::SetInsertionPoint( long pos
)
633 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
635 if (m_windowStyle
& wxTE_MULTILINE
)
637 /* seems to be broken in GTK 1.0.X:
638 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
640 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
641 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
643 /* we fake a set_point by inserting and deleting. as the user
644 isn't supposed to get to know about thos non-sense, we
645 disconnect so that no events are sent to the user program. */
647 gint tmp
= (gint
)pos
;
648 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
649 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
651 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
652 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
654 /* bring editable's cursor uptodate. another bug in GTK. */
656 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
660 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
662 /* bring editable's cursor uptodate. bug in GTK. */
664 GTK_EDITABLE(m_text
)->current_pos
= pos
;
668 void wxTextCtrl::SetInsertionPointEnd()
670 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
672 if (m_windowStyle
& wxTE_MULTILINE
)
673 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
675 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
678 void wxTextCtrl::SetEditable( bool editable
)
680 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
682 if (m_windowStyle
& wxTE_MULTILINE
)
683 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
685 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
688 void wxTextCtrl::SetSelection( long from
, long to
)
690 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
692 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
695 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
697 wxFAIL_MSG( _T("wxTextCtrl::ShowPosition not implemented") );
700 long wxTextCtrl::GetInsertionPoint() const
702 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
704 return (long) GTK_EDITABLE(m_text
)->current_pos
;
707 long wxTextCtrl::GetLastPosition() const
709 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
712 if (m_windowStyle
& wxTE_MULTILINE
)
713 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
715 pos
= GTK_ENTRY(m_text
)->text_length
;
720 void wxTextCtrl::Remove( long from
, long to
)
722 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
724 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
727 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
729 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
731 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
732 if (value
.IsNull()) return;
733 gint pos
= (gint
)from
;
735 wxWX2MBbuf buf
= value
.mbc_str();
736 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
738 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
742 void wxTextCtrl::Cut()
744 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
746 #if (GTK_MINOR_VERSION > 0)
747 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
749 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
753 void wxTextCtrl::Copy()
755 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
757 #if (GTK_MINOR_VERSION > 0)
758 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
760 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
764 void wxTextCtrl::Paste()
766 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
768 #if (GTK_MINOR_VERSION > 0)
769 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
771 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
775 bool wxTextCtrl::CanCopy() const
777 // Can copy if there's a selection
779 GetSelection(& from
, & to
);
780 return (from
!= to
) ;
783 bool wxTextCtrl::CanCut() const
785 // Can cut if there's a selection
787 GetSelection(& from
, & to
);
788 return (from
!= to
) ;
791 bool wxTextCtrl::CanPaste() const
793 return IsEditable() ;
797 void wxTextCtrl::Undo()
800 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
803 void wxTextCtrl::Redo()
806 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
809 bool wxTextCtrl::CanUndo() const
812 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
816 bool wxTextCtrl::CanRedo() const
819 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
823 // If the return values from and to are the same, there is no
825 void wxTextCtrl::GetSelection(long* from
, long* to
) const
830 wxFAIL_MSG( _T("wxTextCtrl::GetSelection not implemented") );
833 bool wxTextCtrl::IsEditable() const
836 wxFAIL_MSG( _T("wxTextCtrl::IsEditable not implemented") );
840 void wxTextCtrl::Clear()
845 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
847 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
849 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
851 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
852 event
.SetEventObject(this);
853 if (GetEventHandler()->ProcessEvent(event
)) return;
859 #ifndef NO_TEXT_WINDOW_STREAM
860 int wxTextCtrl::overflow( int WXUNUSED(c
) )
862 int len
= pptr() - pbase();
863 char *txt
= new char[len
+1];
864 strncpy(txt
, pbase(), len
);
867 setp(pbase(), epptr());
872 int wxTextCtrl::sync()
874 int len
= pptr() - pbase();
875 char *txt
= new char[len
+1];
876 strncpy(txt
, pbase(), len
);
879 setp(pbase(), epptr());
884 int wxTextCtrl::underflow()
889 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
895 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
897 static char buf
[100];
898 sprintf(buf
, "%.2f", f
);
903 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
905 static char buf
[100];
906 sprintf(buf
, "%.2f", d
);
911 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
913 static char buf
[100];
914 sprintf(buf
, "%i", i
);
919 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
921 static char buf
[100];
922 sprintf(buf
, "%ld", i
);
927 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
938 GtkWidget
* wxTextCtrl::GetConnectWidget()
940 return GTK_WIDGET(m_text
);
943 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
945 if (m_windowStyle
& wxTE_MULTILINE
)
946 return (window
== GTK_TEXT(m_text
)->text_area
);
948 return (window
== GTK_ENTRY(m_text
)->text_area
);
951 void wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
953 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
958 void wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
960 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
965 void wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
967 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
969 wxControl::SetBackgroundColour( colour
);
971 if (!m_widget
->window
) return;
973 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
974 if (sysbg
.Red() == colour
.Red() &&
975 sysbg
.Green() == colour
.Green() &&
976 sysbg
.Blue() == colour
.Blue())
981 if (!m_backgroundColour
.Ok()) return;
983 if (m_windowStyle
& wxTE_MULTILINE
)
985 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
987 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
988 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
989 gdk_window_clear( window
);
993 void wxTextCtrl::ApplyWidgetStyle()
995 if (m_windowStyle
& wxTE_MULTILINE
)
1002 gtk_widget_set_style( m_text
, m_widgetStyle
);
1006 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1011 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1016 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1021 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1026 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1031 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1033 event
.Enable( CanCut() );
1036 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1038 event
.Enable( CanCopy() );
1041 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1043 event
.Enable( CanPaste() );
1046 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1048 event
.Enable( CanUndo() );
1051 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1053 event
.Enable( CanRedo() );