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
);
165 /* put the horizontal scrollbar in the lower left hand corner */
168 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
169 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
170 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
171 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
174 gtk_widget_show(hscrollbar
);
176 #if (GTK_MINOR_VERSION > 0)
177 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
178 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
182 /* finally, put the vertical scrollbar in the upper right corner */
183 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
184 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
185 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
187 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
192 /* a single-line text control: no need for scrollbars */
194 m_text
= gtk_entry_new();
197 wxSize newSize
= size
;
198 if (newSize
.x
== -1) newSize
.x
= 80;
199 if (newSize
.y
== -1) newSize
.y
= 26;
200 SetSize( newSize
.x
, newSize
.y
);
202 m_parent
->DoAddChild( this );
207 gtk_widget_show(m_text
);
209 /* we want to be notified about text changes */
210 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
211 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
215 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
216 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
219 if (!value
.IsEmpty())
223 #if GTK_MINOR_VERSION == 0
224 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
225 // gtk_editable_insert_text()
226 gtk_widget_realize(m_text
);
230 wxWX2MBbuf val
= value
.mbc_str();
231 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
233 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
234 #endif // Unicode/!Unicode
238 /* bring editable's cursor uptodate. bug in GTK. */
240 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
244 if (style
& wxTE_PASSWORD
)
247 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
250 if (style
& wxTE_READONLY
)
253 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
258 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
261 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) );
262 SetForegroundColour( parent
->GetForegroundColour() );
269 void wxTextCtrl::CalculateScrollbar()
271 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
273 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
275 if (adj
->upper
- adj
->page_size
< 0.8)
277 if (m_vScrollbarVisible
)
279 gtk_widget_hide( m_vScrollbar
);
280 m_vScrollbarVisible
= FALSE
;
285 if (!m_vScrollbarVisible
)
287 gtk_widget_show( m_vScrollbar
);
288 m_vScrollbarVisible
= TRUE
;
293 wxString
wxTextCtrl::GetValue() const
295 wxCHECK_MSG( m_text
!= NULL
, _T(""), _T("invalid text ctrl") );
298 if (m_windowStyle
& wxTE_MULTILINE
)
300 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
301 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
302 tmp
= wxString(text
,*wxConv_current
);
307 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConv_current
);
312 void wxTextCtrl::SetValue( const wxString
&value
)
314 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
316 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
317 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
319 wxString tmp
= _T("");
320 if (!value
.IsNull()) tmp
= value
;
321 if (m_windowStyle
& wxTE_MULTILINE
)
323 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
324 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
327 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
328 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
330 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
335 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
338 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
339 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
342 void wxTextCtrl::WriteText( const wxString
&text
)
344 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
346 if (text
.IsNull()) return;
348 if (m_windowStyle
& wxTE_MULTILINE
)
350 /* this moves the cursor pos to behind the inserted text */
351 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
354 wxWX2MBbuf buf
= text
.mbc_str();
355 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
357 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
360 /* bring editable's cursor uptodate. bug in GTK. */
361 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
365 /* this moves the cursor pos to behind the inserted text */
366 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
368 wxWX2MBbuf buf
= text
.mbc_str();
369 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
371 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
374 /* bring editable's cursor uptodate. bug in GTK. */
375 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
377 /* bring entry's cursor uptodate. bug in GTK. */
378 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
382 void wxTextCtrl::AppendText( const wxString
&text
)
384 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
386 if (m_windowStyle
& wxTE_MULTILINE
)
388 /* we'll insert at the last position */
389 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
391 wxWX2MBbuf buf
= text
.mbc_str();
392 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
394 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
397 /* bring editable's cursor uptodate. bug in GTK. */
398 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
402 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
406 bool wxTextCtrl::LoadFile( const wxString
&file
)
408 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
410 if (!wxFileExists(file
)) return FALSE
;
414 FILE *fp
= (FILE*) NULL
;
417 if ((stat (FNSTRINGCAST file
.fn_str(), &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
418 !(fp
= fopen (FNSTRINGCAST file
.fn_str(), "r")))
424 gint len
= statb
.st_size
;
426 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
431 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
438 if (m_windowStyle
& wxTE_MULTILINE
)
441 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
445 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
455 bool wxTextCtrl::SaveFile( const wxString
&file
)
457 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
459 if (file
== _T("")) return FALSE
;
463 if (!(fp
= fopen (FNSTRINGCAST file
.fn_str(), "w")))
469 char *text
= (char*) NULL
;
472 if (m_windowStyle
& wxTE_MULTILINE
)
474 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
475 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
479 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
482 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
484 // Did not write whole file
487 // Make sure newline terminates the file
488 if (text
[len
- 1] != '\n')
493 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
502 wxString
wxTextCtrl::GetLineText( long lineNo
) const
504 if (m_windowStyle
& wxTE_MULTILINE
)
506 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
507 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
511 wxString
buf(_T(""));
514 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
519 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
526 return wxEmptyString
;
530 if (lineNo
== 0) return GetValue();
531 return wxEmptyString
;
535 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
537 /* If you implement this, don't forget to update the documentation!
538 * (file docs/latex/wx/text.tex) */
539 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
542 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
544 if ( m_windowStyle
& wxTE_MULTILINE
)
546 wxString text
= GetValue();
548 // cast to prevent warning. But pos really should've been unsigned.
549 if( (unsigned long)pos
> text
.Len() )
555 const wxChar
* stop
= text
.c_str() + pos
;
556 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
567 else // single line control
569 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
576 // index out of bounds
584 long wxTextCtrl::XYToPosition(long x
, long y
) const
586 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
589 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
595 int wxTextCtrl::GetLineLength(long lineNo
) const
597 wxString str
= GetLineText (lineNo
);
598 return (int) str
.Length();
601 int wxTextCtrl::GetNumberOfLines() const
603 if (m_windowStyle
& wxTE_MULTILINE
)
605 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
606 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
611 for (int i
= 0; i
< len
; i
++ )
618 // currentLine is 0 based, add 1 to get number of lines
619 return currentLine
+ 1;
632 void wxTextCtrl::SetInsertionPoint( long pos
)
634 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
636 if (m_windowStyle
& wxTE_MULTILINE
)
638 /* seems to be broken in GTK 1.0.X:
639 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
641 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
642 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
644 /* we fake a set_point by inserting and deleting. as the user
645 isn't supposed to get to know about thos non-sense, we
646 disconnect so that no events are sent to the user program. */
648 gint tmp
= (gint
)pos
;
649 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
650 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
652 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
653 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
655 /* bring editable's cursor uptodate. another bug in GTK. */
657 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
661 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
663 /* bring editable's cursor uptodate. bug in GTK. */
665 GTK_EDITABLE(m_text
)->current_pos
= pos
;
669 void wxTextCtrl::SetInsertionPointEnd()
671 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
673 if (m_windowStyle
& wxTE_MULTILINE
)
674 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
676 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
679 void wxTextCtrl::SetEditable( bool editable
)
681 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
683 if (m_windowStyle
& wxTE_MULTILINE
)
684 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
686 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
689 void wxTextCtrl::SetSelection( long from
, long to
)
691 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
693 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
696 void wxTextCtrl::ShowPosition( long pos
)
698 SetInsertionPoint( pos
);
701 long wxTextCtrl::GetInsertionPoint() const
703 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
705 return (long) GTK_EDITABLE(m_text
)->current_pos
;
708 long wxTextCtrl::GetLastPosition() const
710 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
713 if (m_windowStyle
& wxTE_MULTILINE
)
714 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
716 pos
= GTK_ENTRY(m_text
)->text_length
;
721 void wxTextCtrl::Remove( long from
, long to
)
723 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
725 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
728 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
730 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
732 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
733 if (value
.IsNull()) return;
734 gint pos
= (gint
)from
;
736 wxWX2MBbuf buf
= value
.mbc_str();
737 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
739 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
743 void wxTextCtrl::Cut()
745 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
747 #if (GTK_MINOR_VERSION > 0)
748 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
750 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
754 void wxTextCtrl::Copy()
756 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
758 #if (GTK_MINOR_VERSION > 0)
759 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
761 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
765 void wxTextCtrl::Paste()
767 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
769 #if (GTK_MINOR_VERSION > 0)
770 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
772 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
776 bool wxTextCtrl::CanCopy() const
778 // Can copy if there's a selection
780 GetSelection(& from
, & to
);
781 return (from
!= to
) ;
784 bool wxTextCtrl::CanCut() const
786 // Can cut if there's a selection
788 GetSelection(& from
, & to
);
789 return (from
!= to
) ;
792 bool wxTextCtrl::CanPaste() const
794 return IsEditable() ;
798 void wxTextCtrl::Undo()
801 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
804 void wxTextCtrl::Redo()
807 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
810 bool wxTextCtrl::CanUndo() const
813 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
817 bool wxTextCtrl::CanRedo() const
820 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
824 // If the return values from and to are the same, there is no
826 void wxTextCtrl::GetSelection(long* from
, long* to
) const
828 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
830 if (!(GTK_EDITABLE(m_text
)->has_selection
))
837 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
838 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
841 bool wxTextCtrl::IsEditable() const
843 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
845 return GTK_EDITABLE(m_text
)->editable
;
848 void wxTextCtrl::Clear()
853 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
855 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
857 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
859 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
860 event
.SetEventObject(this);
861 if (GetEventHandler()->ProcessEvent(event
)) return;
867 #ifndef NO_TEXT_WINDOW_STREAM
868 int wxTextCtrl::overflow( int WXUNUSED(c
) )
870 int len
= pptr() - pbase();
871 char *txt
= new char[len
+1];
872 strncpy(txt
, pbase(), len
);
875 setp(pbase(), epptr());
880 int wxTextCtrl::sync()
882 int len
= pptr() - pbase();
883 char *txt
= new char[len
+1];
884 strncpy(txt
, pbase(), len
);
887 setp(pbase(), epptr());
892 int wxTextCtrl::underflow()
897 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
903 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
905 static char buf
[100];
906 sprintf(buf
, "%.2f", f
);
911 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
913 static char buf
[100];
914 sprintf(buf
, "%.2f", d
);
919 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
921 static char buf
[100];
922 sprintf(buf
, "%i", i
);
927 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
929 static char buf
[100];
930 sprintf(buf
, "%ld", i
);
935 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
946 GtkWidget
* wxTextCtrl::GetConnectWidget()
948 return GTK_WIDGET(m_text
);
951 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
953 if (m_windowStyle
& wxTE_MULTILINE
)
954 return (window
== GTK_TEXT(m_text
)->text_area
);
956 return (window
== GTK_ENTRY(m_text
)->text_area
);
959 bool wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
961 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
967 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
969 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
975 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
977 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
979 wxControl::SetBackgroundColour( colour
);
981 if (!m_widget
->window
)
984 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
985 if (sysbg
.Red() == colour
.Red() &&
986 sysbg
.Green() == colour
.Green() &&
987 sysbg
.Blue() == colour
.Blue())
989 return FALSE
; // FIXME or TRUE?
992 if (!m_backgroundColour
.Ok())
995 if (m_windowStyle
& wxTE_MULTILINE
)
997 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
1000 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
1001 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
1002 gdk_window_clear( window
);
1008 void wxTextCtrl::ApplyWidgetStyle()
1010 if (m_windowStyle
& wxTE_MULTILINE
)
1017 gtk_widget_set_style( m_text
, m_widgetStyle
);
1021 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
1026 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1031 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
1036 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
1041 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
1046 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
1048 event
.Enable( CanCut() );
1051 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
1053 event
.Enable( CanCopy() );
1056 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
1058 event
.Enable( CanPaste() );
1061 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1063 event
.Enable( CanUndo() );
1066 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1068 event
.Enable( CanRedo() );