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 bool g_blockEventsOnDrag
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
38 gtk_text_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
40 if (!win
->m_hasVMT
) return;
44 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->m_windowId
);
45 event
.SetString( win
->GetValue() );
46 event
.SetEventObject( win
);
47 win
->GetEventHandler()->ProcessEvent( event
);
50 //-----------------------------------------------------------------------------
51 // "changed" from vertical scrollbar
52 //-----------------------------------------------------------------------------
55 gtk_scrollbar_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
57 if (!win
->m_hasVMT
) return;
59 win
->CalculateScrollbar();
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
66 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
68 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
69 EVT_CHAR(wxTextCtrl::OnChar
)
71 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
72 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
73 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
74 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
75 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
77 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
78 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
79 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
80 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
81 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
84 #ifndef NO_TEXT_WINDOW_STREAM
85 wxTextCtrl::wxTextCtrl() : streambuf()
87 if (allocate()) setp(base(),ebuf());
92 wxTextCtrl::wxTextCtrl()
98 #ifndef NO_TEXT_WINDOW_STREAM
99 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
100 const wxPoint
&pos
, const wxSize
&size
,
101 int style
, const wxValidator
& validator
, const wxString
&name
) : streambuf()
103 if (allocate()) setp(base(),ebuf());
106 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
109 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
110 const wxPoint
&pos
, const wxSize
&size
,
111 int style
, const wxValidator
& validator
, const wxString
&name
)
114 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
118 bool wxTextCtrl::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
119 const wxPoint
&pos
, const wxSize
&size
,
120 int style
, const wxValidator
& validator
, const wxString
&name
)
123 m_acceptsFocus
= TRUE
;
125 PreCreation( parent
, id
, pos
, size
, style
, name
);
127 SetValidator( validator
);
129 m_vScrollbarVisible
= FALSE
;
131 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
134 /* a multi-line edit control: create a vertical scrollbar by default and
135 horizontal if requested */
136 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
138 /* create our control ... */
139 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
141 /* ... and put into the upper left hand corner of the table */
142 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
143 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
145 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
146 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
147 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
150 /* put the horizontal scrollbar in the lower left hand corner */
153 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
154 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
156 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
157 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
),
160 gtk_widget_show(hscrollbar
);
163 /* we create the vertical scrollbar on demand */
164 m_vScrollbar
= (GtkWidget
*) NULL
;
169 /* a single-line text control: no need for scrollbars */
171 m_text
= gtk_entry_new();
174 wxSize newSize
= size
;
175 if (newSize
.x
== -1) newSize
.x
= 80;
176 if (newSize
.y
== -1) newSize
.y
= 26;
177 SetSize( newSize
.x
, newSize
.y
);
179 m_parent
->AddChild( this );
181 (m_parent
->m_insertCallback
)( m_parent
, this );
187 gtk_widget_realize(m_text
);
188 gtk_widget_show(m_text
);
191 /* we want to be notified about text changes */
192 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
193 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
195 if (!value
.IsEmpty())
199 wxWX2MBbuf val
= value
.mbc_str();
200 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
202 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
207 /* bring editable's cursor uptodate. bug in GTK. */
209 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
213 if (style
& wxTE_PASSWORD
)
216 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
219 if (style
& wxTE_READONLY
)
222 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
227 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
230 SetBackgroundColour( parent
->GetBackgroundColour() );
231 SetForegroundColour( parent
->GetForegroundColour() );
237 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
238 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
244 void wxTextCtrl::CalculateScrollbar()
246 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
248 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
250 if (adj
->upper
- adj
->page_size
< 0.8)
252 if (m_vScrollbarVisible
)
254 gtk_widget_hide( m_vScrollbar
);
256 m_vScrollbarVisible
= FALSE
;
261 if (!m_vScrollbarVisible
)
265 /* finally, put the vertical scrollbar in the upper right corner */
266 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
267 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
269 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
271 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
275 gtk_widget_show( m_vScrollbar
);
277 m_vScrollbarVisible
= TRUE
;
282 wxString
wxTextCtrl::GetValue() const
284 wxCHECK_MSG( m_text
!= NULL
, _T(""), _T("invalid text ctrl") );
287 if (m_windowStyle
& wxTE_MULTILINE
)
289 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
290 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
291 tmp
= wxString(text
,*wxConv_current
);
296 tmp
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
301 void wxTextCtrl::SetValue( const wxString
&value
)
303 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
305 wxString tmp
= _T("");
306 if (!value
.IsNull()) tmp
= value
;
307 if (m_windowStyle
& wxTE_MULTILINE
)
309 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
310 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
313 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
314 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
316 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
321 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
325 void wxTextCtrl::WriteText( const wxString
&text
)
327 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
329 if (text
.IsNull()) return;
331 if (m_windowStyle
& wxTE_MULTILINE
)
333 /* this moves the cursor pos to behind the inserted text */
334 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
337 wxWX2MBbuf buf
= text
.mbc_str();
338 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
340 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
343 /* bring editable's cursor uptodate. bug in GTK. */
344 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
348 /* this moves the cursor pos to behind the inserted text */
349 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
351 wxWX2MBbuf buf
= text
.mbc_str();
352 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
354 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
357 /* bring editable's cursor uptodate. bug in GTK. */
358 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
360 /* bring entry's cursor uptodate. bug in GTK. */
361 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
365 void wxTextCtrl::AppendText( const wxString
&text
)
367 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
369 if (m_windowStyle
& wxTE_MULTILINE
)
371 /* we'll insert at the last position */
372 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
374 wxWX2MBbuf buf
= text
.mbc_str();
375 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
377 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
380 /* bring editable's cursor uptodate. bug in GTK. */
381 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
385 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
389 bool wxTextCtrl::LoadFile( const wxString
&file
)
391 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
393 if (!wxFileExists(file
)) return FALSE
;
397 FILE *fp
= (FILE*) NULL
;
400 if ((stat (FNSTRINGCAST file
.fn_str(), &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
401 !(fp
= fopen (FNSTRINGCAST file
.fn_str(), "r")))
407 gint len
= statb
.st_size
;
409 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
414 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
421 if (m_windowStyle
& wxTE_MULTILINE
)
424 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
428 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
438 bool wxTextCtrl::SaveFile( const wxString
&file
)
440 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
442 if (file
== _T("")) return FALSE
;
446 if (!(fp
= fopen (FNSTRINGCAST file
.fn_str(), "w")))
452 char *text
= (char*) NULL
;
455 if (m_windowStyle
& wxTE_MULTILINE
)
457 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
458 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
462 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
465 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
467 // Did not write whole file
470 // Make sure newline terminates the file
471 if (text
[len
- 1] != '\n')
476 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
485 wxString
wxTextCtrl::GetLineText( long lineNo
) const
487 if (m_windowStyle
& wxTE_MULTILINE
)
489 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
490 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
494 wxString
buf(_T(""));
497 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
502 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
509 return wxEmptyString
;
513 if (lineNo
== 0) return GetValue();
514 return wxEmptyString
;
518 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
520 /* If you implement this, don't forget to update the documentation!
521 * (file docs/latex/wx/text.tex) */
522 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
525 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
527 if ( m_windowStyle
& wxTE_MULTILINE
)
529 wxString text
= GetValue();
531 // cast to prevent warning. But pos really should've been unsigned.
532 if( (unsigned long)pos
> text
.Len() )
538 const wxChar
* stop
= text
.c_str() + pos
;
539 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
550 else // single line control
552 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
559 // index out of bounds
567 long wxTextCtrl::XYToPosition(long x
, long y
) const
569 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
572 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
578 int wxTextCtrl::GetLineLength(long lineNo
) const
580 wxString str
= GetLineText (lineNo
);
581 return (int) str
.Length();
584 int wxTextCtrl::GetNumberOfLines() const
586 if (m_windowStyle
& wxTE_MULTILINE
)
588 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
589 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
594 for (int i
= 0; i
< len
; i
++ )
601 // currentLine is 0 based, add 1 to get number of lines
602 return currentLine
+ 1;
615 void wxTextCtrl::SetInsertionPoint( long pos
)
617 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
619 if (m_windowStyle
& wxTE_MULTILINE
)
621 /* seems to be broken in GTK 1.0.X:
622 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
624 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
625 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
627 /* we fake a set_point by inserting and deleting. as the user
628 isn't supposed to get to know about thos non-sense, we
629 disconnect so that no events are sent to the user program. */
631 gint tmp
= (gint
)pos
;
632 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
633 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
635 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
636 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
638 /* bring editable's cursor uptodate. another bug in GTK. */
640 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
644 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
646 /* bring editable's cursor uptodate. bug in GTK. */
648 GTK_EDITABLE(m_text
)->current_pos
= pos
;
652 void wxTextCtrl::SetInsertionPointEnd()
654 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
656 if (m_windowStyle
& wxTE_MULTILINE
)
657 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
659 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
662 void wxTextCtrl::SetEditable( bool editable
)
664 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
666 if (m_windowStyle
& wxTE_MULTILINE
)
667 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
669 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
672 void wxTextCtrl::SetSelection( long from
, long to
)
674 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
676 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
679 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
681 wxFAIL_MSG( _T("wxTextCtrl::ShowPosition not implemented") );
684 long wxTextCtrl::GetInsertionPoint() const
686 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
688 return (long) GTK_EDITABLE(m_text
)->current_pos
;
691 long wxTextCtrl::GetLastPosition() const
693 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
696 if (m_windowStyle
& wxTE_MULTILINE
)
697 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
699 pos
= GTK_ENTRY(m_text
)->text_length
;
704 void wxTextCtrl::Remove( long from
, long to
)
706 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
708 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
711 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
713 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
715 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
716 if (value
.IsNull()) return;
717 gint pos
= (gint
)from
;
719 wxWX2MBbuf buf
= value
.mbc_str();
720 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
722 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
726 void wxTextCtrl::Cut()
728 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
730 #if (GTK_MINOR_VERSION > 0)
731 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
733 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
737 void wxTextCtrl::Copy()
739 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
741 #if (GTK_MINOR_VERSION > 0)
742 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
744 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
748 void wxTextCtrl::Paste()
750 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
752 #if (GTK_MINOR_VERSION > 0)
753 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
755 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
759 bool wxTextCtrl::CanCopy() const
761 // Can copy if there's a selection
763 GetSelection(& from
, & to
);
764 return (from
!= to
) ;
767 bool wxTextCtrl::CanCut() const
769 // Can cut if there's a selection
771 GetSelection(& from
, & to
);
772 return (from
!= to
) ;
775 bool wxTextCtrl::CanPaste() const
777 return IsEditable() ;
781 void wxTextCtrl::Undo()
784 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
787 void wxTextCtrl::Redo()
790 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
793 bool wxTextCtrl::CanUndo() const
796 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
800 bool wxTextCtrl::CanRedo() const
803 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
807 // If the return values from and to are the same, there is no
809 void wxTextCtrl::GetSelection(long* from
, long* to
) const
814 wxFAIL_MSG( _T("wxTextCtrl::GetSelection not implemented") );
817 bool wxTextCtrl::IsEditable() const
820 wxFAIL_MSG( _T("wxTextCtrl::IsEditable not implemented") );
824 void wxTextCtrl::Clear()
829 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
831 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
833 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
835 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
836 event
.SetEventObject(this);
837 if (GetEventHandler()->ProcessEvent(event
)) return;
843 #ifndef NO_TEXT_WINDOW_STREAM
844 int wxTextCtrl::overflow( int WXUNUSED(c
) )
846 int len
= pptr() - pbase();
847 char *txt
= new char[len
+1];
848 strncpy(txt
, pbase(), len
);
851 setp(pbase(), epptr());
856 int wxTextCtrl::sync()
858 int len
= pptr() - pbase();
859 char *txt
= new char[len
+1];
860 strncpy(txt
, pbase(), len
);
863 setp(pbase(), epptr());
868 int wxTextCtrl::underflow()
873 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
879 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
881 static char buf
[100];
882 sprintf(buf
, "%.2f", f
);
887 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
889 static char buf
[100];
890 sprintf(buf
, "%.2f", d
);
895 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
897 static char buf
[100];
898 sprintf(buf
, "%i", i
);
903 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
905 static char buf
[100];
906 sprintf(buf
, "%ld", i
);
911 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
922 GtkWidget
* wxTextCtrl::GetConnectWidget()
924 return GTK_WIDGET(m_text
);
927 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
929 if (m_windowStyle
& wxTE_MULTILINE
)
930 return (window
== GTK_TEXT(m_text
)->text_area
);
932 return (window
== GTK_ENTRY(m_text
)->text_area
);
935 void wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
937 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
942 void wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
944 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
949 void wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
951 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
953 wxControl::SetBackgroundColour( colour
);
955 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
956 if (sysbg
.Red() == colour
.Red() &&
957 sysbg
.Green() == colour
.Green() &&
958 sysbg
.Blue() == colour
.Blue())
963 if (!m_backgroundColour
.Ok()) return;
965 if (m_windowStyle
& wxTE_MULTILINE
)
967 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
968 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
969 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
970 gdk_window_clear( window
);
974 void wxTextCtrl::ApplyWidgetStyle()
976 if (m_windowStyle
& wxTE_MULTILINE
)
983 gtk_widget_set_style( m_text
, m_widgetStyle
);
987 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
992 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
997 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1002 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1007 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1012 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1014 event
.Enable( CanCut() );
1017 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1019 event
.Enable( CanCopy() );
1022 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1024 event
.Enable( CanPaste() );
1027 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1029 event
.Enable( CanUndo() );
1032 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1034 event
.Enable( CanRedo() );