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
->GetId() );
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
);
155 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
156 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
157 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
160 /* always wrap words */
161 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
162 /* put the horizontal scrollbar in the lower left hand corner */
165 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
166 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
167 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
168 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
),
171 gtk_widget_show(hscrollbar
);
173 #if (GTK_MINOR_VERSION > 0)
174 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
175 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
178 /* finally, put the vertical scrollbar in the upper right corner */
179 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
180 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
181 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
183 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
188 /* a single-line text control: no need for scrollbars */
190 m_text
= gtk_entry_new();
193 wxSize newSize
= size
;
194 if (newSize
.x
== -1) newSize
.x
= 80;
195 if (newSize
.y
== -1) newSize
.y
= 26;
196 SetSize( newSize
.x
, newSize
.y
);
198 m_parent
->DoAddChild( this );
203 gtk_widget_show(m_text
);
205 /* we want to be notified about text changes */
206 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
207 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
211 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
212 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
215 if (!value
.IsEmpty())
219 #if GTK_MINOR_VERSION == 0
220 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
221 // gtk_editable_insert_text()
222 gtk_widget_realize(m_text
);
226 wxWX2MBbuf val
= value
.mbc_str();
227 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
229 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
230 #endif // Unicode/!Unicode
234 /* bring editable's cursor uptodate. bug in GTK. */
236 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
240 if (style
& wxTE_PASSWORD
)
243 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
246 if (style
& wxTE_READONLY
)
249 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
254 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
257 SetBackgroundColour( parent
->GetBackgroundColour() );
258 SetForegroundColour( parent
->GetForegroundColour() );
265 void wxTextCtrl::CalculateScrollbar()
267 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
269 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
271 if (adj
->upper
- adj
->page_size
< 0.8)
273 if (m_vScrollbarVisible
)
275 gtk_widget_hide( m_vScrollbar
);
277 m_vScrollbarVisible
= FALSE
;
282 if (!m_vScrollbarVisible
)
284 gtk_widget_show( m_vScrollbar
);
286 m_vScrollbarVisible
= TRUE
;
291 wxString
wxTextCtrl::GetValue() const
293 wxCHECK_MSG( m_text
!= NULL
, _T(""), _T("invalid text ctrl") );
296 if (m_windowStyle
& wxTE_MULTILINE
)
298 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
299 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
300 tmp
= wxString(text
,*wxConv_current
);
305 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConv_current
);
310 void wxTextCtrl::SetValue( const wxString
&value
)
312 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
314 wxString tmp
= _T("");
315 if (!value
.IsNull()) tmp
= value
;
316 if (m_windowStyle
& wxTE_MULTILINE
)
318 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
319 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
322 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
323 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
325 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
330 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
334 void wxTextCtrl::WriteText( const wxString
&text
)
336 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
338 if (text
.IsNull()) return;
340 if (m_windowStyle
& wxTE_MULTILINE
)
342 /* this moves the cursor pos to behind the inserted text */
343 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
346 wxWX2MBbuf buf
= text
.mbc_str();
347 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
349 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
352 /* bring editable's cursor uptodate. bug in GTK. */
353 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
357 /* this moves the cursor pos to behind the inserted text */
358 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
360 wxWX2MBbuf buf
= text
.mbc_str();
361 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
363 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
366 /* bring editable's cursor uptodate. bug in GTK. */
367 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
369 /* bring entry's cursor uptodate. bug in GTK. */
370 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
374 void wxTextCtrl::AppendText( const wxString
&text
)
376 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
378 if (m_windowStyle
& wxTE_MULTILINE
)
380 /* we'll insert at the last position */
381 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
383 wxWX2MBbuf buf
= text
.mbc_str();
384 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
386 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
389 /* bring editable's cursor uptodate. bug in GTK. */
390 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
394 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
398 bool wxTextCtrl::LoadFile( const wxString
&file
)
400 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
402 if (!wxFileExists(file
)) return FALSE
;
406 FILE *fp
= (FILE*) NULL
;
409 if ((stat (FNSTRINGCAST file
.fn_str(), &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
410 !(fp
= fopen (FNSTRINGCAST file
.fn_str(), "r")))
416 gint len
= statb
.st_size
;
418 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
423 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
430 if (m_windowStyle
& wxTE_MULTILINE
)
433 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
437 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
447 bool wxTextCtrl::SaveFile( const wxString
&file
)
449 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
451 if (file
== _T("")) return FALSE
;
455 if (!(fp
= fopen (FNSTRINGCAST file
.fn_str(), "w")))
461 char *text
= (char*) NULL
;
464 if (m_windowStyle
& wxTE_MULTILINE
)
466 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
467 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
471 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
474 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
476 // Did not write whole file
479 // Make sure newline terminates the file
480 if (text
[len
- 1] != '\n')
485 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
494 wxString
wxTextCtrl::GetLineText( long lineNo
) const
496 if (m_windowStyle
& wxTE_MULTILINE
)
498 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
499 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
503 wxString
buf(_T(""));
506 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
511 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
518 return wxEmptyString
;
522 if (lineNo
== 0) return GetValue();
523 return wxEmptyString
;
527 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
529 /* If you implement this, don't forget to update the documentation!
530 * (file docs/latex/wx/text.tex) */
531 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
534 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
536 if ( m_windowStyle
& wxTE_MULTILINE
)
538 wxString text
= GetValue();
540 // cast to prevent warning. But pos really should've been unsigned.
541 if( (unsigned long)pos
> text
.Len() )
547 const wxChar
* stop
= text
.c_str() + pos
;
548 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
559 else // single line control
561 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
568 // index out of bounds
576 long wxTextCtrl::XYToPosition(long x
, long y
) const
578 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
581 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
587 int wxTextCtrl::GetLineLength(long lineNo
) const
589 wxString str
= GetLineText (lineNo
);
590 return (int) str
.Length();
593 int wxTextCtrl::GetNumberOfLines() const
595 if (m_windowStyle
& wxTE_MULTILINE
)
597 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
598 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
603 for (int i
= 0; i
< len
; i
++ )
610 // currentLine is 0 based, add 1 to get number of lines
611 return currentLine
+ 1;
624 void wxTextCtrl::SetInsertionPoint( long pos
)
626 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
628 if (m_windowStyle
& wxTE_MULTILINE
)
630 /* seems to be broken in GTK 1.0.X:
631 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
633 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
634 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
636 /* we fake a set_point by inserting and deleting. as the user
637 isn't supposed to get to know about thos non-sense, we
638 disconnect so that no events are sent to the user program. */
640 gint tmp
= (gint
)pos
;
641 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
642 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
644 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
645 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
647 /* bring editable's cursor uptodate. another bug in GTK. */
649 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
653 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
655 /* bring editable's cursor uptodate. bug in GTK. */
657 GTK_EDITABLE(m_text
)->current_pos
= pos
;
661 void wxTextCtrl::SetInsertionPointEnd()
663 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
665 if (m_windowStyle
& wxTE_MULTILINE
)
666 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
668 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
671 void wxTextCtrl::SetEditable( bool editable
)
673 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
675 if (m_windowStyle
& wxTE_MULTILINE
)
676 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
678 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
681 void wxTextCtrl::SetSelection( long from
, long to
)
683 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
685 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
688 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
690 wxFAIL_MSG( _T("wxTextCtrl::ShowPosition not implemented") );
693 long wxTextCtrl::GetInsertionPoint() const
695 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
697 return (long) GTK_EDITABLE(m_text
)->current_pos
;
700 long wxTextCtrl::GetLastPosition() const
702 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
705 if (m_windowStyle
& wxTE_MULTILINE
)
706 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
708 pos
= GTK_ENTRY(m_text
)->text_length
;
713 void wxTextCtrl::Remove( long from
, long to
)
715 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
717 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
720 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
722 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
724 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
725 if (value
.IsNull()) return;
726 gint pos
= (gint
)from
;
728 wxWX2MBbuf buf
= value
.mbc_str();
729 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
731 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
735 void wxTextCtrl::Cut()
737 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
739 #if (GTK_MINOR_VERSION > 0)
740 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
742 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
746 void wxTextCtrl::Copy()
748 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
750 #if (GTK_MINOR_VERSION > 0)
751 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
753 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
757 void wxTextCtrl::Paste()
759 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
761 #if (GTK_MINOR_VERSION > 0)
762 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
764 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
768 bool wxTextCtrl::CanCopy() const
770 // Can copy if there's a selection
772 GetSelection(& from
, & to
);
773 return (from
!= to
) ;
776 bool wxTextCtrl::CanCut() const
778 // Can cut if there's a selection
780 GetSelection(& from
, & to
);
781 return (from
!= to
) ;
784 bool wxTextCtrl::CanPaste() const
786 return IsEditable() ;
790 void wxTextCtrl::Undo()
793 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
796 void wxTextCtrl::Redo()
799 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
802 bool wxTextCtrl::CanUndo() const
805 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
809 bool wxTextCtrl::CanRedo() const
812 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
816 // If the return values from and to are the same, there is no
818 void wxTextCtrl::GetSelection(long* from
, long* to
) const
823 wxFAIL_MSG( _T("wxTextCtrl::GetSelection not implemented") );
826 bool wxTextCtrl::IsEditable() const
829 wxFAIL_MSG( _T("wxTextCtrl::IsEditable not implemented") );
833 void wxTextCtrl::Clear()
838 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
840 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
842 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
844 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
845 event
.SetEventObject(this);
846 if (GetEventHandler()->ProcessEvent(event
)) return;
852 #ifndef NO_TEXT_WINDOW_STREAM
853 int wxTextCtrl::overflow( int WXUNUSED(c
) )
855 int len
= pptr() - pbase();
856 char *txt
= new char[len
+1];
857 strncpy(txt
, pbase(), len
);
860 setp(pbase(), epptr());
865 int wxTextCtrl::sync()
867 int len
= pptr() - pbase();
868 char *txt
= new char[len
+1];
869 strncpy(txt
, pbase(), len
);
872 setp(pbase(), epptr());
877 int wxTextCtrl::underflow()
882 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
888 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
890 static char buf
[100];
891 sprintf(buf
, "%.2f", f
);
896 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
898 static char buf
[100];
899 sprintf(buf
, "%.2f", d
);
904 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
906 static char buf
[100];
907 sprintf(buf
, "%i", i
);
912 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
914 static char buf
[100];
915 sprintf(buf
, "%ld", i
);
920 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
931 GtkWidget
* wxTextCtrl::GetConnectWidget()
933 return GTK_WIDGET(m_text
);
936 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
938 if (m_windowStyle
& wxTE_MULTILINE
)
939 return (window
== GTK_TEXT(m_text
)->text_area
);
941 return (window
== GTK_ENTRY(m_text
)->text_area
);
944 bool wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
946 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
952 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
954 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
960 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
962 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
964 wxControl::SetBackgroundColour( colour
);
966 if (!m_widget
->window
)
969 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
970 if (sysbg
.Red() == colour
.Red() &&
971 sysbg
.Green() == colour
.Green() &&
972 sysbg
.Blue() == colour
.Blue())
974 return FALSE
; // FIXME or TRUE?
977 if (!m_backgroundColour
.Ok())
980 if (m_windowStyle
& wxTE_MULTILINE
)
982 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
985 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
986 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
987 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() );