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 (!win
->m_hasVMT
) return;
50 wxapp_install_idle_handler();
54 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->GetId() );
55 event
.SetString( win
->GetValue() );
56 event
.SetEventObject( win
);
57 win
->GetEventHandler()->ProcessEvent( event
);
60 //-----------------------------------------------------------------------------
61 // "changed" from vertical scrollbar
62 //-----------------------------------------------------------------------------
65 gtk_scrollbar_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
67 if (!win
->m_hasVMT
) return;
70 wxapp_install_idle_handler();
72 win
->CalculateScrollbar();
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
79 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
81 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
82 EVT_CHAR(wxTextCtrl::OnChar
)
84 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
85 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
86 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
87 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
88 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
90 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
91 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
92 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
93 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
94 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
97 #ifndef NO_TEXT_WINDOW_STREAM
98 wxTextCtrl::wxTextCtrl() : streambuf()
100 if (allocate()) setp(base(),ebuf());
105 wxTextCtrl::wxTextCtrl()
111 #ifndef NO_TEXT_WINDOW_STREAM
112 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
113 const wxPoint
&pos
, const wxSize
&size
,
114 int style
, const wxValidator
& validator
, const wxString
&name
) : streambuf()
116 if (allocate()) setp(base(),ebuf());
119 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
122 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
123 const wxPoint
&pos
, const wxSize
&size
,
124 int style
, const wxValidator
& validator
, const wxString
&name
)
127 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
131 bool wxTextCtrl::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
132 const wxPoint
&pos
, const wxSize
&size
,
133 int style
, const wxValidator
& validator
, const wxString
&name
)
136 m_acceptsFocus
= TRUE
;
138 PreCreation( parent
, id
, pos
, size
, style
, name
);
140 SetValidator( validator
);
142 m_vScrollbarVisible
= FALSE
;
144 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
147 /* a multi-line edit control: create a vertical scrollbar by default and
148 horizontal if requested */
149 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
151 /* create our control ... */
152 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
154 /* ... and put into the upper left hand corner of the table */
155 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
156 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
157 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
158 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
159 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
162 /* always wrap words */
163 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
);
169 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
170 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
),
173 gtk_widget_show(hscrollbar
);
175 #if (GTK_MINOR_VERSION > 0)
176 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
177 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
180 /* finally, put the vertical scrollbar in the upper right corner */
181 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
182 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
183 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
185 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
190 /* a single-line text control: no need for scrollbars */
192 m_text
= gtk_entry_new();
195 wxSize newSize
= size
;
196 if (newSize
.x
== -1) newSize
.x
= 80;
197 if (newSize
.y
== -1) newSize
.y
= 26;
198 SetSize( newSize
.x
, newSize
.y
);
200 m_parent
->DoAddChild( this );
205 gtk_widget_show(m_text
);
207 /* we want to be notified about text changes */
208 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
209 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
213 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
214 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
217 if (!value
.IsEmpty())
221 #if GTK_MINOR_VERSION == 0
222 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
223 // gtk_editable_insert_text()
224 gtk_widget_realize(m_text
);
228 wxWX2MBbuf val
= value
.mbc_str();
229 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
231 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
232 #endif // Unicode/!Unicode
236 /* bring editable's cursor uptodate. bug in GTK. */
238 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
242 if (style
& wxTE_PASSWORD
)
245 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
248 if (style
& wxTE_READONLY
)
251 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
256 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
259 SetBackgroundColour( parent
->GetBackgroundColour() );
260 SetForegroundColour( parent
->GetForegroundColour() );
267 void wxTextCtrl::CalculateScrollbar()
269 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
271 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
273 if (adj
->upper
- adj
->page_size
< 0.8)
275 if (m_vScrollbarVisible
)
277 gtk_widget_hide( m_vScrollbar
);
278 m_vScrollbarVisible
= FALSE
;
283 if (!m_vScrollbarVisible
)
285 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 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
315 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
317 wxString tmp
= _T("");
318 if (!value
.IsNull()) tmp
= value
;
319 if (m_windowStyle
& wxTE_MULTILINE
)
321 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
322 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
325 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
326 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
328 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
333 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
336 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
337 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
340 void wxTextCtrl::WriteText( const wxString
&text
)
342 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
344 if (text
.IsNull()) return;
346 if (m_windowStyle
& wxTE_MULTILINE
)
348 /* this moves the cursor pos to behind the inserted text */
349 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
352 wxWX2MBbuf buf
= text
.mbc_str();
353 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
355 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
358 /* bring editable's cursor uptodate. bug in GTK. */
359 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
363 /* this moves the cursor pos to behind the inserted text */
364 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
366 wxWX2MBbuf buf
= text
.mbc_str();
367 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
369 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
372 /* bring editable's cursor uptodate. bug in GTK. */
373 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
375 /* bring entry's cursor uptodate. bug in GTK. */
376 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
380 void wxTextCtrl::AppendText( const wxString
&text
)
382 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
384 if (m_windowStyle
& wxTE_MULTILINE
)
386 /* we'll insert at the last position */
387 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
389 wxWX2MBbuf buf
= text
.mbc_str();
390 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
392 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
395 /* bring editable's cursor uptodate. bug in GTK. */
396 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
400 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
404 bool wxTextCtrl::LoadFile( const wxString
&file
)
406 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
408 if (!wxFileExists(file
)) return FALSE
;
412 FILE *fp
= (FILE*) NULL
;
415 if ((stat (FNSTRINGCAST file
.fn_str(), &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
416 !(fp
= fopen (FNSTRINGCAST file
.fn_str(), "r")))
422 gint len
= statb
.st_size
;
424 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
429 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
436 if (m_windowStyle
& wxTE_MULTILINE
)
439 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
443 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
453 bool wxTextCtrl::SaveFile( const wxString
&file
)
455 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
457 if (file
== _T("")) return FALSE
;
461 if (!(fp
= fopen (FNSTRINGCAST file
.fn_str(), "w")))
467 char *text
= (char*) NULL
;
470 if (m_windowStyle
& wxTE_MULTILINE
)
472 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
473 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
477 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
480 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
482 // Did not write whole file
485 // Make sure newline terminates the file
486 if (text
[len
- 1] != '\n')
491 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
500 wxString
wxTextCtrl::GetLineText( long lineNo
) const
502 if (m_windowStyle
& wxTE_MULTILINE
)
504 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
505 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
509 wxString
buf(_T(""));
512 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
517 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
524 return wxEmptyString
;
528 if (lineNo
== 0) return GetValue();
529 return wxEmptyString
;
533 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
535 /* If you implement this, don't forget to update the documentation!
536 * (file docs/latex/wx/text.tex) */
537 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
540 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
542 if ( m_windowStyle
& wxTE_MULTILINE
)
544 wxString text
= GetValue();
546 // cast to prevent warning. But pos really should've been unsigned.
547 if( (unsigned long)pos
> text
.Len() )
553 const wxChar
* stop
= text
.c_str() + pos
;
554 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
565 else // single line control
567 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
574 // index out of bounds
582 long wxTextCtrl::XYToPosition(long x
, long y
) const
584 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
587 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
593 int wxTextCtrl::GetLineLength(long lineNo
) const
595 wxString str
= GetLineText (lineNo
);
596 return (int) str
.Length();
599 int wxTextCtrl::GetNumberOfLines() const
601 if (m_windowStyle
& wxTE_MULTILINE
)
603 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
604 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
609 for (int i
= 0; i
< len
; i
++ )
616 // currentLine is 0 based, add 1 to get number of lines
617 return currentLine
+ 1;
630 void wxTextCtrl::SetInsertionPoint( long pos
)
632 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
634 if (m_windowStyle
& wxTE_MULTILINE
)
636 /* seems to be broken in GTK 1.0.X:
637 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
639 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
640 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
642 /* we fake a set_point by inserting and deleting. as the user
643 isn't supposed to get to know about thos non-sense, we
644 disconnect so that no events are sent to the user program. */
646 gint tmp
= (gint
)pos
;
647 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
648 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
650 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
651 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
653 /* bring editable's cursor uptodate. another bug in GTK. */
655 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
659 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
661 /* bring editable's cursor uptodate. bug in GTK. */
663 GTK_EDITABLE(m_text
)->current_pos
= pos
;
667 void wxTextCtrl::SetInsertionPointEnd()
669 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
671 if (m_windowStyle
& wxTE_MULTILINE
)
672 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
674 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
677 void wxTextCtrl::SetEditable( bool editable
)
679 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
681 if (m_windowStyle
& wxTE_MULTILINE
)
682 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
684 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
687 void wxTextCtrl::SetSelection( long from
, long to
)
689 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
691 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
694 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
696 wxFAIL_MSG( _T("wxTextCtrl::ShowPosition not implemented") );
699 long wxTextCtrl::GetInsertionPoint() const
701 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
703 return (long) GTK_EDITABLE(m_text
)->current_pos
;
706 long wxTextCtrl::GetLastPosition() const
708 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
711 if (m_windowStyle
& wxTE_MULTILINE
)
712 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
714 pos
= GTK_ENTRY(m_text
)->text_length
;
719 void wxTextCtrl::Remove( long from
, long to
)
721 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
723 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
726 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
728 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
730 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
731 if (value
.IsNull()) return;
732 gint pos
= (gint
)from
;
734 wxWX2MBbuf buf
= value
.mbc_str();
735 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
737 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
741 void wxTextCtrl::Cut()
743 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
745 #if (GTK_MINOR_VERSION > 0)
746 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
748 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
752 void wxTextCtrl::Copy()
754 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
756 #if (GTK_MINOR_VERSION > 0)
757 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
759 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
763 void wxTextCtrl::Paste()
765 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
767 #if (GTK_MINOR_VERSION > 0)
768 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
770 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
774 bool wxTextCtrl::CanCopy() const
776 // Can copy if there's a selection
778 GetSelection(& from
, & to
);
779 return (from
!= to
) ;
782 bool wxTextCtrl::CanCut() const
784 // Can cut if there's a selection
786 GetSelection(& from
, & to
);
787 return (from
!= to
) ;
790 bool wxTextCtrl::CanPaste() const
792 return IsEditable() ;
796 void wxTextCtrl::Undo()
799 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
802 void wxTextCtrl::Redo()
805 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
808 bool wxTextCtrl::CanUndo() const
811 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
815 bool wxTextCtrl::CanRedo() const
818 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
822 // If the return values from and to are the same, there is no
824 void wxTextCtrl::GetSelection(long* from
, long* to
) const
829 wxFAIL_MSG( _T("wxTextCtrl::GetSelection not implemented") );
832 bool wxTextCtrl::IsEditable() const
835 wxFAIL_MSG( _T("wxTextCtrl::IsEditable not implemented") );
839 void wxTextCtrl::Clear()
844 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
846 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
848 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
850 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
851 event
.SetEventObject(this);
852 if (GetEventHandler()->ProcessEvent(event
)) return;
858 #ifndef NO_TEXT_WINDOW_STREAM
859 int wxTextCtrl::overflow( int WXUNUSED(c
) )
861 int len
= pptr() - pbase();
862 char *txt
= new char[len
+1];
863 strncpy(txt
, pbase(), len
);
866 setp(pbase(), epptr());
871 int wxTextCtrl::sync()
873 int len
= pptr() - pbase();
874 char *txt
= new char[len
+1];
875 strncpy(txt
, pbase(), len
);
878 setp(pbase(), epptr());
883 int wxTextCtrl::underflow()
888 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
894 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
896 static char buf
[100];
897 sprintf(buf
, "%.2f", f
);
902 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
904 static char buf
[100];
905 sprintf(buf
, "%.2f", d
);
910 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
912 static char buf
[100];
913 sprintf(buf
, "%i", i
);
918 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
920 static char buf
[100];
921 sprintf(buf
, "%ld", i
);
926 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
937 GtkWidget
* wxTextCtrl::GetConnectWidget()
939 return GTK_WIDGET(m_text
);
942 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
944 if (m_windowStyle
& wxTE_MULTILINE
)
945 return (window
== GTK_TEXT(m_text
)->text_area
);
947 return (window
== GTK_ENTRY(m_text
)->text_area
);
950 bool wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
952 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
958 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
960 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
966 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
968 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
970 wxControl::SetBackgroundColour( colour
);
972 if (!m_widget
->window
)
975 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
976 if (sysbg
.Red() == colour
.Red() &&
977 sysbg
.Green() == colour
.Green() &&
978 sysbg
.Blue() == colour
.Blue())
980 return FALSE
; // FIXME or TRUE?
983 if (!m_backgroundColour
.Ok())
986 if (m_windowStyle
& wxTE_MULTILINE
)
988 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
991 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
992 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
993 gdk_window_clear( window
);
999 void wxTextCtrl::ApplyWidgetStyle()
1001 if (m_windowStyle
& wxTE_MULTILINE
)
1008 gtk_widget_set_style( m_text
, m_widgetStyle
);
1012 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1017 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1022 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1027 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1032 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1037 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1039 event
.Enable( CanCut() );
1042 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1044 event
.Enable( CanCopy() );
1047 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1049 event
.Enable( CanPaste() );
1052 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1054 event
.Enable( CanUndo() );
1057 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1059 event
.Enable( CanRedo() );