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 wxTextCtrl::wxTextCtrl()
102 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
103 const wxPoint
&pos
, const wxSize
&size
,
104 int style
, const wxValidator
& validator
, const wxString
&name
)
107 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
110 bool wxTextCtrl::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
111 const wxPoint
&pos
, const wxSize
&size
,
112 int style
, const wxValidator
& validator
, const wxString
&name
)
115 m_acceptsFocus
= TRUE
;
117 PreCreation( parent
, id
, pos
, size
, style
, name
);
120 SetValidator( validator
);
121 #endif // wxUSE_VALIDATORS
123 m_vScrollbarVisible
= FALSE
;
125 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
128 #if (GTK_MINOR_VERSION > 2)
129 /* a multi-line edit control: create a vertical scrollbar by default and
130 horizontal if requested */
131 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
133 bool bHasHScrollbar
= FALSE
;
136 /* create our control ... */
137 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
139 /* ... and put into the upper left hand corner of the table */
140 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
141 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
142 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
143 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
144 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
147 /* always wrap words */
148 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
150 #if (GTK_MINOR_VERSION > 2)
151 /* put the horizontal scrollbar in the lower left hand corner */
154 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
155 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
| GTK_SHRINK
),
160 gtk_widget_show(hscrollbar
);
162 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
163 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
167 /* finally, put the vertical scrollbar in the upper right corner */
168 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
169 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
170 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
172 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
177 /* a single-line text control: no need for scrollbars */
179 m_text
= gtk_entry_new();
182 wxSize newSize
= size
;
183 if (newSize
.x
== -1) newSize
.x
= 80;
184 if (newSize
.y
== -1) newSize
.y
= 26;
185 SetSize( newSize
.x
, newSize
.y
);
187 m_parent
->DoAddChild( this );
192 gtk_widget_show(m_text
);
194 /* we want to be notified about text changes */
195 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
196 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
200 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
201 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
204 if (!value
.IsEmpty())
208 #if GTK_MINOR_VERSION == 0
209 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
210 // gtk_editable_insert_text()
211 gtk_widget_realize(m_text
);
215 wxWX2MBbuf val
= value
.mbc_str();
216 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
218 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
219 #endif // Unicode/!Unicode
223 /* bring editable's cursor uptodate. bug in GTK. */
225 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
229 if (style
& wxTE_PASSWORD
)
232 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
235 if (style
& wxTE_READONLY
)
238 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
243 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
246 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) );
247 SetForegroundColour( parent
->GetForegroundColour() );
254 void wxTextCtrl::CalculateScrollbar()
256 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
258 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
260 if (adj
->upper
- adj
->page_size
< 0.8)
262 if (m_vScrollbarVisible
)
264 gtk_widget_hide( m_vScrollbar
);
265 m_vScrollbarVisible
= FALSE
;
270 if (!m_vScrollbarVisible
)
272 gtk_widget_show( m_vScrollbar
);
273 m_vScrollbarVisible
= TRUE
;
278 wxString
wxTextCtrl::GetValue() const
280 wxCHECK_MSG( m_text
!= NULL
, _T(""), _T("invalid text ctrl") );
283 if (m_windowStyle
& wxTE_MULTILINE
)
285 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
286 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
287 tmp
= wxString(text
,*wxConvCurrent
);
292 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConvCurrent
);
297 void wxTextCtrl::SetValue( const wxString
&value
)
299 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
301 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
302 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
304 wxString tmp
= _T("");
305 if (!value
.IsNull()) tmp
= value
;
306 if (m_windowStyle
& wxTE_MULTILINE
)
308 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
309 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
312 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
313 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
315 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
320 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
323 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
324 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
327 void wxTextCtrl::WriteText( const wxString
&text
)
329 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
331 if (text
.IsEmpty()) return;
333 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
334 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
336 if (m_windowStyle
& wxTE_MULTILINE
)
338 /* this moves the cursor pos to behind the inserted text */
339 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
342 wxWX2MBbuf buf
= text
.mbc_str();
343 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
345 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
348 /* bring editable's cursor uptodate. bug in GTK. */
349 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
353 /* this moves the cursor pos to behind the inserted text */
354 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
356 wxWX2MBbuf buf
= text
.mbc_str();
357 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
359 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
362 /* bring editable's cursor uptodate. bug in GTK. */
363 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
365 /* bring entry's cursor uptodate. bug in GTK. */
366 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
369 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
370 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
373 void wxTextCtrl::AppendText( const wxString
&text
)
375 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
377 if (text
.IsEmpty()) return;
379 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
380 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
382 if (m_windowStyle
& wxTE_MULTILINE
)
384 bool hasSpecialAttributes
= m_font
.Ok() ||
385 m_foregroundColour
.Ok() ||
386 m_backgroundColour
.Ok();
387 if ( hasSpecialAttributes
)
389 gtk_text_insert( GTK_TEXT(m_text
),
390 m_font
.GetInternalFont(),
391 m_foregroundColour
.GetColor(),
392 m_backgroundColour
.GetColor(),
393 text
.mbc_str(), text
.length());
398 /* we'll insert at the last position */
399 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
401 wxWX2MBbuf buf
= text
.mbc_str();
402 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
404 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
408 /* bring editable's cursor uptodate. bug in GTK. */
409 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
413 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
416 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
417 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
420 wxString
wxTextCtrl::GetLineText( long lineNo
) const
422 if (m_windowStyle
& wxTE_MULTILINE
)
424 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
425 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
429 wxString
buf(_T(""));
432 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
437 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
444 return wxEmptyString
;
448 if (lineNo
== 0) return GetValue();
449 return wxEmptyString
;
453 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
455 /* If you implement this, don't forget to update the documentation!
456 * (file docs/latex/wx/text.tex) */
457 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
460 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
462 if ( m_windowStyle
& wxTE_MULTILINE
)
464 wxString text
= GetValue();
466 // cast to prevent warning. But pos really should've been unsigned.
467 if( (unsigned long)pos
> text
.Len() )
473 const wxChar
* stop
= text
.c_str() + pos
;
474 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
485 else // single line control
487 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
494 // index out of bounds
502 long wxTextCtrl::XYToPosition(long x
, long y
) const
504 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
507 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
513 int wxTextCtrl::GetLineLength(long lineNo
) const
515 wxString str
= GetLineText (lineNo
);
516 return (int) str
.Length();
519 int wxTextCtrl::GetNumberOfLines() const
521 if (m_windowStyle
& wxTE_MULTILINE
)
523 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
524 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
529 for (int i
= 0; i
< len
; i
++ )
536 // currentLine is 0 based, add 1 to get number of lines
537 return currentLine
+ 1;
550 void wxTextCtrl::SetInsertionPoint( long pos
)
552 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
554 if (m_windowStyle
& wxTE_MULTILINE
)
556 /* seems to be broken in GTK 1.0.X:
557 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
559 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
560 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
562 /* we fake a set_point by inserting and deleting. as the user
563 isn't supposed to get to know about thos non-sense, we
564 disconnect so that no events are sent to the user program. */
566 gint tmp
= (gint
)pos
;
567 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
568 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
570 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
571 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
573 /* bring editable's cursor uptodate. another bug in GTK. */
575 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
579 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
581 /* bring editable's cursor uptodate. bug in GTK. */
583 GTK_EDITABLE(m_text
)->current_pos
= pos
;
587 void wxTextCtrl::SetInsertionPointEnd()
589 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
591 if (m_windowStyle
& wxTE_MULTILINE
)
592 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
594 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
597 void wxTextCtrl::SetEditable( bool editable
)
599 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
601 if (m_windowStyle
& wxTE_MULTILINE
)
602 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
604 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
607 void wxTextCtrl::DiscardEdits()
612 void wxTextCtrl::SetSelection( long from
, long to
)
614 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
616 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
619 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
621 // SetInsertionPoint( pos );
624 long wxTextCtrl::GetInsertionPoint() const
626 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
628 return (long) GTK_EDITABLE(m_text
)->current_pos
;
631 long wxTextCtrl::GetLastPosition() const
633 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
636 if (m_windowStyle
& wxTE_MULTILINE
)
637 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
639 pos
= GTK_ENTRY(m_text
)->text_length
;
644 void wxTextCtrl::Remove( long from
, long to
)
646 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
648 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
649 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
651 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
653 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
654 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
657 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
659 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
661 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
662 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
664 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
666 if (!value
.IsEmpty())
668 gint pos
= (gint
)from
;
670 wxWX2MBbuf buf
= value
.mbc_str();
671 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
673 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
677 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
678 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
681 void wxTextCtrl::Cut()
683 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
685 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
686 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
688 #if (GTK_MINOR_VERSION > 0)
689 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
691 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
694 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
695 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
698 void wxTextCtrl::Copy()
700 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
702 #if (GTK_MINOR_VERSION > 0)
703 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
705 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
709 void wxTextCtrl::Paste()
711 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
713 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
714 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
716 #if (GTK_MINOR_VERSION > 0)
717 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
719 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
722 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
723 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
726 bool wxTextCtrl::CanCopy() const
728 // Can copy if there's a selection
730 GetSelection(& from
, & to
);
731 return (from
!= to
) ;
734 bool wxTextCtrl::CanCut() const
736 // Can cut if there's a selection
738 GetSelection(& from
, & to
);
739 return (from
!= to
) ;
742 bool wxTextCtrl::CanPaste() const
744 return IsEditable() ;
748 void wxTextCtrl::Undo()
751 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
754 void wxTextCtrl::Redo()
757 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
760 bool wxTextCtrl::CanUndo() const
763 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
767 bool wxTextCtrl::CanRedo() const
770 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
774 // If the return values from and to are the same, there is no
776 void wxTextCtrl::GetSelection(long* from
, long* to
) const
778 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
780 if (!(GTK_EDITABLE(m_text
)->has_selection
))
787 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
788 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
791 bool wxTextCtrl::IsEditable() const
793 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
795 return GTK_EDITABLE(m_text
)->editable
;
798 bool wxTextCtrl::IsModified() const
803 void wxTextCtrl::Clear()
808 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
810 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
812 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
814 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
815 event
.SetEventObject(this);
816 if (GetEventHandler()->ProcessEvent(event
)) return;
822 GtkWidget
* wxTextCtrl::GetConnectWidget()
824 return GTK_WIDGET(m_text
);
827 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
829 if (m_windowStyle
& wxTE_MULTILINE
)
830 return (window
== GTK_TEXT(m_text
)->text_area
);
832 return (window
== GTK_ENTRY(m_text
)->text_area
);
835 // the font will change for subsequent text insertiongs
836 bool wxTextCtrl::SetFont( const wxFont
&font
)
838 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
840 if ( !wxWindowBase::SetFont(font
) )
842 // font didn't change, nothing to do
846 if ( m_windowStyle
& wxTE_MULTILINE
)
848 // for compatibility with other ports: the font is a global controls
849 // characteristic, so change the font globally
850 wxString value
= GetValue();
851 if ( !value
.IsEmpty() )
862 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
864 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
870 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
872 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
874 wxControl::SetBackgroundColour( colour
);
876 if (!m_widget
->window
)
879 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
880 if (sysbg
.Red() == colour
.Red() &&
881 sysbg
.Green() == colour
.Green() &&
882 sysbg
.Blue() == colour
.Blue())
884 return FALSE
; // FIXME or TRUE?
887 if (!m_backgroundColour
.Ok())
890 if (m_windowStyle
& wxTE_MULTILINE
)
892 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
895 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
896 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
897 gdk_window_clear( window
);
903 void wxTextCtrl::ApplyWidgetStyle()
905 if (m_windowStyle
& wxTE_MULTILINE
)
912 gtk_widget_set_style( m_text
, m_widgetStyle
);
916 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
921 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
926 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
931 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
936 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
941 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
943 event
.Enable( CanCut() );
946 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
948 event
.Enable( CanCopy() );
951 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
953 event
.Enable( CanPaste() );
956 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
958 event
.Enable( CanUndo() );
961 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
963 event
.Enable( CanRedo() );