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
);
292 tmp
= wxString(text
,*wxConv_current
);
300 tmp
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
305 void wxTextCtrl::SetValue( const wxString
&value
)
307 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
309 wxString tmp
= _T("");
310 if (!value
.IsNull()) tmp
= value
;
311 if (m_windowStyle
& wxTE_MULTILINE
)
313 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
314 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
317 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
318 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
320 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
325 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
329 void wxTextCtrl::WriteText( const wxString
&text
)
331 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
333 if (text
.IsNull()) return;
335 if (m_windowStyle
& wxTE_MULTILINE
)
337 /* this moves the cursor pos to behind the inserted text */
338 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
341 wxWX2MBbuf buf
= text
.mbc_str();
342 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
344 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
347 /* bring editable's cursor uptodate. bug in GTK. */
348 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
352 /* this moves the cursor pos to behind the inserted text */
353 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
355 wxWX2MBbuf buf
= text
.mbc_str();
356 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
358 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
361 /* bring editable's cursor uptodate. bug in GTK. */
362 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
364 /* bring entry's cursor uptodate. bug in GTK. */
365 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
369 void wxTextCtrl::AppendText( const wxString
&text
)
371 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
373 if (m_windowStyle
& wxTE_MULTILINE
)
375 /* we'll insert at the last position */
376 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
378 wxWX2MBbuf buf
= text
.mbc_str();
379 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
381 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
384 /* bring editable's cursor uptodate. bug in GTK. */
385 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
389 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
393 bool wxTextCtrl::LoadFile( const wxString
&file
)
395 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
397 if (!wxFileExists(file
)) return FALSE
;
401 FILE *fp
= (FILE*) NULL
;
404 if ((stat (FNSTRINGCAST file
.fn_str(), &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
405 !(fp
= fopen (FNSTRINGCAST file
.fn_str(), "r")))
411 gint len
= statb
.st_size
;
413 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
418 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
425 if (m_windowStyle
& wxTE_MULTILINE
)
428 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
432 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
442 bool wxTextCtrl::SaveFile( const wxString
&file
)
444 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
446 if (file
== _T("")) return FALSE
;
450 if (!(fp
= fopen (FNSTRINGCAST file
.fn_str(), "w")))
456 char *text
= (char*) NULL
;
459 if (m_windowStyle
& wxTE_MULTILINE
)
461 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
462 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
466 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
469 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
471 // Did not write whole file
474 // Make sure newline terminates the file
475 if (text
[len
- 1] != '\n')
480 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
489 wxString
wxTextCtrl::GetLineText( long lineNo
) const
491 if (m_windowStyle
& wxTE_MULTILINE
)
493 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
494 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
498 wxString
buf(_T(""));
501 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
506 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
513 return wxEmptyString
;
517 if (lineNo
== 0) return GetValue();
518 return wxEmptyString
;
522 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
524 /* If you implement this, don't forget to update the documentation!
525 * (file docs/latex/wx/text.tex) */
526 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
529 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
531 if ( m_windowStyle
& wxTE_MULTILINE
)
533 wxString text
= GetValue();
535 // cast to prevent warning. But pos really should've been unsigned.
536 if( (unsigned long)pos
> text
.Len() )
542 const wxChar
* stop
= text
.c_str() + pos
;
543 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
554 else // single line control
556 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
563 // index out of bounds
571 long wxTextCtrl::XYToPosition(long x
, long y
) const
573 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
576 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
582 int wxTextCtrl::GetLineLength(long lineNo
) const
584 wxString str
= GetLineText (lineNo
);
585 return (int) str
.Length();
588 int wxTextCtrl::GetNumberOfLines() const
590 if (m_windowStyle
& wxTE_MULTILINE
)
592 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
593 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
598 for (int i
= 0; i
< len
; i
++ )
605 // currentLine is 0 based, add 1 to get number of lines
606 return currentLine
+ 1;
619 void wxTextCtrl::SetInsertionPoint( long pos
)
621 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
623 if (m_windowStyle
& wxTE_MULTILINE
)
625 /* seems to be broken in GTK 1.0.X:
626 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
628 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
629 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
631 /* we fake a set_point by inserting and deleting. as the user
632 isn't supposed to get to know about thos non-sense, we
633 disconnect so that no events are sent to the user program. */
635 gint tmp
= (gint
)pos
;
636 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
637 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
639 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
640 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
642 /* bring editable's cursor uptodate. another bug in GTK. */
644 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
648 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
650 /* bring editable's cursor uptodate. bug in GTK. */
652 GTK_EDITABLE(m_text
)->current_pos
= pos
;
656 void wxTextCtrl::SetInsertionPointEnd()
658 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
660 if (m_windowStyle
& wxTE_MULTILINE
)
661 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
663 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
666 void wxTextCtrl::SetEditable( bool editable
)
668 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
670 if (m_windowStyle
& wxTE_MULTILINE
)
671 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
673 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
676 void wxTextCtrl::SetSelection( long from
, long to
)
678 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
680 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
683 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
685 wxFAIL_MSG( _T("wxTextCtrl::ShowPosition not implemented") );
688 long wxTextCtrl::GetInsertionPoint() const
690 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
692 return (long) GTK_EDITABLE(m_text
)->current_pos
;
695 long wxTextCtrl::GetLastPosition() const
697 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
700 if (m_windowStyle
& wxTE_MULTILINE
)
701 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
703 pos
= GTK_ENTRY(m_text
)->text_length
;
708 void wxTextCtrl::Remove( long from
, long to
)
710 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
712 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
715 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
717 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
719 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
720 if (value
.IsNull()) return;
721 gint pos
= (gint
)from
;
723 wxWX2MBbuf buf
= value
.mbc_str();
724 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
726 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
730 void wxTextCtrl::Cut()
732 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
734 #if (GTK_MINOR_VERSION > 0)
735 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
737 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
741 void wxTextCtrl::Copy()
743 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
745 #if (GTK_MINOR_VERSION > 0)
746 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
748 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
752 void wxTextCtrl::Paste()
754 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
756 #if (GTK_MINOR_VERSION > 0)
757 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
759 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
763 bool wxTextCtrl::CanCopy() const
765 // Can copy if there's a selection
767 GetSelection(& from
, & to
);
768 return (from
!= to
) ;
771 bool wxTextCtrl::CanCut() const
773 // Can cut if there's a selection
775 GetSelection(& from
, & to
);
776 return (from
!= to
) ;
779 bool wxTextCtrl::CanPaste() const
781 return IsEditable() ;
785 void wxTextCtrl::Undo()
788 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
791 void wxTextCtrl::Redo()
794 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
797 bool wxTextCtrl::CanUndo() const
800 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
804 bool wxTextCtrl::CanRedo() const
807 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
811 // If the return values from and to are the same, there is no
813 void wxTextCtrl::GetSelection(long* from
, long* to
) const
818 wxFAIL_MSG( _T("wxTextCtrl::GetSelection not implemented") );
821 bool wxTextCtrl::IsEditable() const
824 wxFAIL_MSG( _T("wxTextCtrl::IsEditable not implemented") );
828 void wxTextCtrl::Clear()
833 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
835 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
837 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
839 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
840 event
.SetEventObject(this);
841 if (GetEventHandler()->ProcessEvent(event
)) return;
847 #ifndef NO_TEXT_WINDOW_STREAM
848 int wxTextCtrl::overflow( int WXUNUSED(c
) )
850 int len
= pptr() - pbase();
851 char *txt
= new char[len
+1];
852 strncpy(txt
, pbase(), len
);
855 setp(pbase(), epptr());
860 int wxTextCtrl::sync()
862 int len
= pptr() - pbase();
863 char *txt
= new char[len
+1];
864 strncpy(txt
, pbase(), len
);
867 setp(pbase(), epptr());
872 int wxTextCtrl::underflow()
877 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
883 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
885 static char buf
[100];
886 sprintf(buf
, "%.2f", f
);
891 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
893 static char buf
[100];
894 sprintf(buf
, "%.2f", d
);
899 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
901 static char buf
[100];
902 sprintf(buf
, "%i", i
);
907 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
909 static char buf
[100];
910 sprintf(buf
, "%ld", i
);
915 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
926 GtkWidget
* wxTextCtrl::GetConnectWidget()
928 return GTK_WIDGET(m_text
);
931 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
933 if (m_windowStyle
& wxTE_MULTILINE
)
934 return (window
== GTK_TEXT(m_text
)->text_area
);
936 return (window
== GTK_ENTRY(m_text
)->text_area
);
939 void wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
941 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
946 void wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
948 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
953 void wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
955 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
957 wxControl::SetBackgroundColour( colour
);
959 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
960 if (sysbg
.Red() == colour
.Red() &&
961 sysbg
.Green() == colour
.Green() &&
962 sysbg
.Blue() == colour
.Blue())
967 if (!m_backgroundColour
.Ok()) return;
969 if (m_windowStyle
& wxTE_MULTILINE
)
971 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
972 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
973 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
974 gdk_window_clear( window
);
978 void wxTextCtrl::ApplyWidgetStyle()
980 if (m_windowStyle
& wxTE_MULTILINE
)
987 gtk_widget_set_style( m_text
, m_widgetStyle
);
991 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
996 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1001 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1006 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1011 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1016 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1018 event
.Enable( CanCut() );
1021 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1023 event
.Enable( CanCopy() );
1026 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1028 event
.Enable( CanPaste() );
1031 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1033 event
.Enable( CanUndo() );
1036 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1038 event
.Enable( CanRedo() );