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 /* put the horizontal scrollbar in the lower left hand corner */
164 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
165 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
);
174 /* finally, put the vertical scrollbar in the upper right corner */
175 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
176 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
178 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
180 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
185 /* a single-line text control: no need for scrollbars */
187 m_text
= gtk_entry_new();
190 wxSize newSize
= size
;
191 if (newSize
.x
== -1) newSize
.x
= 80;
192 if (newSize
.y
== -1) newSize
.y
= 26;
193 SetSize( newSize
.x
, newSize
.y
);
195 m_parent
->AddChild( this );
197 (m_parent
->m_insertCallback
)( m_parent
, this );
202 gtk_widget_show(m_text
);
204 /* we want to be notified about text changes */
205 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
206 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
210 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
211 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
214 if (!value
.IsEmpty())
218 wxWX2MBbuf val
= value
.mbc_str();
219 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
221 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
226 /* bring editable's cursor uptodate. bug in GTK. */
228 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
232 if (style
& wxTE_PASSWORD
)
235 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
238 if (style
& wxTE_READONLY
)
241 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
246 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
249 SetBackgroundColour( parent
->GetBackgroundColour() );
250 SetForegroundColour( parent
->GetForegroundColour() );
257 void wxTextCtrl::CalculateScrollbar()
259 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
261 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
263 if (adj
->upper
- adj
->page_size
< 0.8)
265 if (m_vScrollbarVisible
)
267 gtk_widget_hide( m_vScrollbar
);
269 m_vScrollbarVisible
= FALSE
;
274 if (!m_vScrollbarVisible
)
276 gtk_widget_show( m_vScrollbar
);
278 m_vScrollbarVisible
= TRUE
;
283 wxString
wxTextCtrl::GetValue() const
285 wxCHECK_MSG( m_text
!= NULL
, _T(""), _T("invalid text ctrl") );
288 if (m_windowStyle
& wxTE_MULTILINE
)
290 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
291 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
292 tmp
= wxString(text
,*wxConv_current
);
297 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConv_current
);
302 void wxTextCtrl::SetValue( const wxString
&value
)
304 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
306 wxString tmp
= _T("");
307 if (!value
.IsNull()) tmp
= value
;
308 if (m_windowStyle
& wxTE_MULTILINE
)
310 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
311 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
314 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
315 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
317 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
322 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
326 void wxTextCtrl::WriteText( const wxString
&text
)
328 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
330 if (text
.IsNull()) return;
332 if (m_windowStyle
& wxTE_MULTILINE
)
334 /* this moves the cursor pos to behind the inserted text */
335 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
338 wxWX2MBbuf buf
= text
.mbc_str();
339 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
341 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
344 /* bring editable's cursor uptodate. bug in GTK. */
345 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
349 /* this moves the cursor pos to behind the inserted text */
350 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
+= text
.Len();
361 /* bring entry's cursor uptodate. bug in GTK. */
362 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
366 void wxTextCtrl::AppendText( const wxString
&text
)
368 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
370 if (m_windowStyle
& wxTE_MULTILINE
)
372 /* we'll insert at the last position */
373 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
375 wxWX2MBbuf buf
= text
.mbc_str();
376 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
378 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
381 /* bring editable's cursor uptodate. bug in GTK. */
382 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
386 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
390 bool wxTextCtrl::LoadFile( const wxString
&file
)
392 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
394 if (!wxFileExists(file
)) return FALSE
;
398 FILE *fp
= (FILE*) NULL
;
401 if ((stat (FNSTRINGCAST file
.fn_str(), &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
402 !(fp
= fopen (FNSTRINGCAST file
.fn_str(), "r")))
408 gint len
= statb
.st_size
;
410 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
415 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
422 if (m_windowStyle
& wxTE_MULTILINE
)
425 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
429 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
439 bool wxTextCtrl::SaveFile( const wxString
&file
)
441 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
443 if (file
== _T("")) return FALSE
;
447 if (!(fp
= fopen (FNSTRINGCAST file
.fn_str(), "w")))
453 char *text
= (char*) NULL
;
456 if (m_windowStyle
& wxTE_MULTILINE
)
458 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
459 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
463 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
466 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
468 // Did not write whole file
471 // Make sure newline terminates the file
472 if (text
[len
- 1] != '\n')
477 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
486 wxString
wxTextCtrl::GetLineText( long lineNo
) const
488 if (m_windowStyle
& wxTE_MULTILINE
)
490 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
491 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
495 wxString
buf(_T(""));
498 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
503 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
510 return wxEmptyString
;
514 if (lineNo
== 0) return GetValue();
515 return wxEmptyString
;
519 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
521 /* If you implement this, don't forget to update the documentation!
522 * (file docs/latex/wx/text.tex) */
523 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
526 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
528 if ( m_windowStyle
& wxTE_MULTILINE
)
530 wxString text
= GetValue();
532 // cast to prevent warning. But pos really should've been unsigned.
533 if( (unsigned long)pos
> text
.Len() )
539 const wxChar
* stop
= text
.c_str() + pos
;
540 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
551 else // single line control
553 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
560 // index out of bounds
568 long wxTextCtrl::XYToPosition(long x
, long y
) const
570 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
573 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
579 int wxTextCtrl::GetLineLength(long lineNo
) const
581 wxString str
= GetLineText (lineNo
);
582 return (int) str
.Length();
585 int wxTextCtrl::GetNumberOfLines() const
587 if (m_windowStyle
& wxTE_MULTILINE
)
589 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
590 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
595 for (int i
= 0; i
< len
; i
++ )
602 // currentLine is 0 based, add 1 to get number of lines
603 return currentLine
+ 1;
616 void wxTextCtrl::SetInsertionPoint( long pos
)
618 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
620 if (m_windowStyle
& wxTE_MULTILINE
)
622 /* seems to be broken in GTK 1.0.X:
623 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
625 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
626 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
628 /* we fake a set_point by inserting and deleting. as the user
629 isn't supposed to get to know about thos non-sense, we
630 disconnect so that no events are sent to the user program. */
632 gint tmp
= (gint
)pos
;
633 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
634 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
636 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
637 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
639 /* bring editable's cursor uptodate. another bug in GTK. */
641 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
645 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
647 /* bring editable's cursor uptodate. bug in GTK. */
649 GTK_EDITABLE(m_text
)->current_pos
= pos
;
653 void wxTextCtrl::SetInsertionPointEnd()
655 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
657 if (m_windowStyle
& wxTE_MULTILINE
)
658 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
660 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
663 void wxTextCtrl::SetEditable( bool editable
)
665 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
667 if (m_windowStyle
& wxTE_MULTILINE
)
668 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
670 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
673 void wxTextCtrl::SetSelection( long from
, long to
)
675 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
677 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
680 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
682 wxFAIL_MSG( _T("wxTextCtrl::ShowPosition not implemented") );
685 long wxTextCtrl::GetInsertionPoint() const
687 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
689 return (long) GTK_EDITABLE(m_text
)->current_pos
;
692 long wxTextCtrl::GetLastPosition() const
694 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
697 if (m_windowStyle
& wxTE_MULTILINE
)
698 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
700 pos
= GTK_ENTRY(m_text
)->text_length
;
705 void wxTextCtrl::Remove( long from
, long to
)
707 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
709 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
712 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
714 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
716 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
717 if (value
.IsNull()) return;
718 gint pos
= (gint
)from
;
720 wxWX2MBbuf buf
= value
.mbc_str();
721 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
723 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
727 void wxTextCtrl::Cut()
729 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
731 #if (GTK_MINOR_VERSION > 0)
732 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
734 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
738 void wxTextCtrl::Copy()
740 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
742 #if (GTK_MINOR_VERSION > 0)
743 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
745 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
749 void wxTextCtrl::Paste()
751 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
753 #if (GTK_MINOR_VERSION > 0)
754 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
756 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
760 bool wxTextCtrl::CanCopy() const
762 // Can copy if there's a selection
764 GetSelection(& from
, & to
);
765 return (from
!= to
) ;
768 bool wxTextCtrl::CanCut() const
770 // Can cut if there's a selection
772 GetSelection(& from
, & to
);
773 return (from
!= to
) ;
776 bool wxTextCtrl::CanPaste() const
778 return IsEditable() ;
782 void wxTextCtrl::Undo()
785 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
788 void wxTextCtrl::Redo()
791 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
794 bool wxTextCtrl::CanUndo() const
797 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
801 bool wxTextCtrl::CanRedo() const
804 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
808 // If the return values from and to are the same, there is no
810 void wxTextCtrl::GetSelection(long* from
, long* to
) const
815 wxFAIL_MSG( _T("wxTextCtrl::GetSelection not implemented") );
818 bool wxTextCtrl::IsEditable() const
821 wxFAIL_MSG( _T("wxTextCtrl::IsEditable not implemented") );
825 void wxTextCtrl::Clear()
830 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
832 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
834 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
836 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
837 event
.SetEventObject(this);
838 if (GetEventHandler()->ProcessEvent(event
)) return;
844 #ifndef NO_TEXT_WINDOW_STREAM
845 int wxTextCtrl::overflow( int WXUNUSED(c
) )
847 int len
= pptr() - pbase();
848 char *txt
= new char[len
+1];
849 strncpy(txt
, pbase(), len
);
852 setp(pbase(), epptr());
857 int wxTextCtrl::sync()
859 int len
= pptr() - pbase();
860 char *txt
= new char[len
+1];
861 strncpy(txt
, pbase(), len
);
864 setp(pbase(), epptr());
869 int wxTextCtrl::underflow()
874 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
880 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
882 static char buf
[100];
883 sprintf(buf
, "%.2f", f
);
888 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
890 static char buf
[100];
891 sprintf(buf
, "%.2f", d
);
896 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
898 static char buf
[100];
899 sprintf(buf
, "%i", i
);
904 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
906 static char buf
[100];
907 sprintf(buf
, "%ld", i
);
912 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
923 GtkWidget
* wxTextCtrl::GetConnectWidget()
925 return GTK_WIDGET(m_text
);
928 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
930 if (m_windowStyle
& wxTE_MULTILINE
)
931 return (window
== GTK_TEXT(m_text
)->text_area
);
933 return (window
== GTK_ENTRY(m_text
)->text_area
);
936 void wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
938 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
943 void wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
945 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
950 void wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
952 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
954 wxControl::SetBackgroundColour( colour
);
956 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
957 if (sysbg
.Red() == colour
.Red() &&
958 sysbg
.Green() == colour
.Green() &&
959 sysbg
.Blue() == colour
.Blue())
964 if (!m_backgroundColour
.Ok()) return;
966 if (m_windowStyle
& wxTE_MULTILINE
)
968 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
969 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
970 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
971 gdk_window_clear( window
);
975 void wxTextCtrl::ApplyWidgetStyle()
977 if (m_windowStyle
& wxTE_MULTILINE
)
984 gtk_widget_set_style( m_text
, m_widgetStyle
);
988 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
993 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
998 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1003 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1008 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1013 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1015 event
.Enable( CanCut() );
1018 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1020 event
.Enable( CanCopy() );
1023 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1025 event
.Enable( CanPaste() );
1028 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1030 event
.Enable( CanUndo() );
1033 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1035 event
.Enable( CanRedo() );