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 if (!PreCreation( parent
, pos
, size
) ||
118 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
120 wxFAIL_MSG( _T("wxTextCtrl creation failed") );
125 m_vScrollbarVisible
= FALSE
;
127 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
130 #if (GTK_MINOR_VERSION > 2)
131 /* a multi-line edit control: create a vertical scrollbar by default and
132 horizontal if requested */
133 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
135 bool bHasHScrollbar
= FALSE
;
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
);
144 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
145 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
146 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
149 /* always wrap words */
150 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
152 #if (GTK_MINOR_VERSION > 2)
153 /* put the horizontal scrollbar in the lower left hand corner */
156 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
157 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
158 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
159 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
162 gtk_widget_show(hscrollbar
);
164 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
165 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
169 /* finally, put the vertical scrollbar in the upper right corner */
170 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
171 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
172 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
174 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
179 /* a single-line text control: no need for scrollbars */
181 m_text
= gtk_entry_new();
184 wxSize newSize
= size
;
185 if (newSize
.x
== -1) newSize
.x
= 80;
186 if (newSize
.y
== -1) newSize
.y
= 26;
187 SetSize( newSize
.x
, newSize
.y
);
189 m_parent
->DoAddChild( this );
194 gtk_widget_show(m_text
);
196 /* we want to be notified about text changes */
197 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
198 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
202 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
203 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
206 if (!value
.IsEmpty())
210 #if GTK_MINOR_VERSION == 0
211 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
212 // gtk_editable_insert_text()
213 gtk_widget_realize(m_text
);
217 wxWX2MBbuf val
= value
.mbc_str();
218 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
220 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
221 #endif // Unicode/!Unicode
225 /* bring editable's cursor uptodate. bug in GTK. */
227 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
231 if (style
& wxTE_PASSWORD
)
234 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
237 if (style
& wxTE_READONLY
)
240 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
245 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
248 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) );
249 SetForegroundColour( parent
->GetForegroundColour() );
256 void wxTextCtrl::CalculateScrollbar()
258 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
260 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
262 if (adj
->upper
- adj
->page_size
< 0.8)
264 if (m_vScrollbarVisible
)
266 gtk_widget_hide( m_vScrollbar
);
267 m_vScrollbarVisible
= FALSE
;
272 if (!m_vScrollbarVisible
)
274 gtk_widget_show( m_vScrollbar
);
275 m_vScrollbarVisible
= TRUE
;
280 wxString
wxTextCtrl::GetValue() const
282 wxCHECK_MSG( m_text
!= NULL
, _T(""), _T("invalid text ctrl") );
285 if (m_windowStyle
& wxTE_MULTILINE
)
287 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
288 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
289 tmp
= wxString(text
,*wxConvCurrent
);
294 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConvCurrent
);
299 void wxTextCtrl::SetValue( const wxString
&value
)
301 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
303 wxString tmp
= _T("");
304 if (!value
.IsNull()) tmp
= value
;
305 if (m_windowStyle
& wxTE_MULTILINE
)
307 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
308 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
311 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
312 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
314 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
319 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
323 void wxTextCtrl::WriteText( const wxString
&text
)
325 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
327 if (text
.IsEmpty()) return;
329 if (m_windowStyle
& wxTE_MULTILINE
)
331 /* this moves the cursor pos to behind the inserted text */
332 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
335 wxWX2MBbuf buf
= text
.mbc_str();
336 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
338 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
341 /* bring editable's cursor uptodate. bug in GTK. */
342 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
346 /* this moves the cursor pos to behind the inserted text */
347 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
349 wxWX2MBbuf buf
= text
.mbc_str();
350 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
352 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
355 /* bring editable's cursor uptodate. bug in GTK. */
356 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
358 /* bring entry's cursor uptodate. bug in GTK. */
359 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
363 void wxTextCtrl::AppendText( const wxString
&text
)
365 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
367 if (text
.IsEmpty()) return;
369 if (m_windowStyle
& wxTE_MULTILINE
)
371 bool hasSpecialAttributes
= m_font
.Ok() ||
372 m_foregroundColour
.Ok() ||
373 m_backgroundColour
.Ok();
374 if ( hasSpecialAttributes
)
376 gtk_text_insert( GTK_TEXT(m_text
),
377 m_font
.GetInternalFont(),
378 m_foregroundColour
.GetColor(),
379 m_backgroundColour
.GetColor(),
380 text
.mbc_str(), text
.length());
385 /* we'll insert at the last position */
386 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
388 wxWX2MBbuf buf
= text
.mbc_str();
389 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
391 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
395 /* bring editable's cursor uptodate. bug in GTK. */
396 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
400 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
404 wxString
wxTextCtrl::GetLineText( long lineNo
) const
406 if (m_windowStyle
& wxTE_MULTILINE
)
408 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
409 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
413 wxString
buf(_T(""));
416 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
421 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
428 return wxEmptyString
;
432 if (lineNo
== 0) return GetValue();
433 return wxEmptyString
;
437 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
439 /* If you implement this, don't forget to update the documentation!
440 * (file docs/latex/wx/text.tex) */
441 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
444 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
446 if ( m_windowStyle
& wxTE_MULTILINE
)
448 wxString text
= GetValue();
450 // cast to prevent warning. But pos really should've been unsigned.
451 if( (unsigned long)pos
> text
.Len() )
457 const wxChar
* stop
= text
.c_str() + pos
;
458 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
469 else // single line control
471 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
478 // index out of bounds
486 long wxTextCtrl::XYToPosition(long x
, long y
) const
488 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
491 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
497 int wxTextCtrl::GetLineLength(long lineNo
) const
499 wxString str
= GetLineText (lineNo
);
500 return (int) str
.Length();
503 int wxTextCtrl::GetNumberOfLines() const
505 if (m_windowStyle
& wxTE_MULTILINE
)
507 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
508 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
513 for (int i
= 0; i
< len
; i
++ )
520 // currentLine is 0 based, add 1 to get number of lines
521 return currentLine
+ 1;
534 void wxTextCtrl::SetInsertionPoint( long pos
)
536 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
538 if (m_windowStyle
& wxTE_MULTILINE
)
540 /* seems to be broken in GTK 1.0.X:
541 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
543 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
544 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
546 /* we fake a set_point by inserting and deleting. as the user
547 isn't supposed to get to know about thos non-sense, we
548 disconnect so that no events are sent to the user program. */
550 gint tmp
= (gint
)pos
;
551 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
552 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
554 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
555 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
557 /* bring editable's cursor uptodate. another bug in GTK. */
559 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
563 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
565 /* bring editable's cursor uptodate. bug in GTK. */
567 GTK_EDITABLE(m_text
)->current_pos
= pos
;
571 void wxTextCtrl::SetInsertionPointEnd()
573 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
575 if (m_windowStyle
& wxTE_MULTILINE
)
576 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
578 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
581 void wxTextCtrl::SetEditable( bool editable
)
583 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
585 if (m_windowStyle
& wxTE_MULTILINE
)
586 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
588 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
591 void wxTextCtrl::DiscardEdits()
596 void wxTextCtrl::SetSelection( long from
, long to
)
598 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
600 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
603 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
605 // SetInsertionPoint( pos );
608 long wxTextCtrl::GetInsertionPoint() const
610 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
612 return (long) GTK_EDITABLE(m_text
)->current_pos
;
615 long wxTextCtrl::GetLastPosition() const
617 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
620 if (m_windowStyle
& wxTE_MULTILINE
)
621 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
623 pos
= GTK_ENTRY(m_text
)->text_length
;
628 void wxTextCtrl::Remove( long from
, long to
)
630 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
632 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
635 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
637 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
639 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
641 if (!value
.IsEmpty())
643 gint pos
= (gint
)from
;
645 wxWX2MBbuf buf
= value
.mbc_str();
646 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
648 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
653 void wxTextCtrl::Cut()
655 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
657 #if (GTK_MINOR_VERSION > 0)
658 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
660 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
664 void wxTextCtrl::Copy()
666 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
668 #if (GTK_MINOR_VERSION > 0)
669 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
671 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
675 void wxTextCtrl::Paste()
677 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
679 #if (GTK_MINOR_VERSION > 0)
680 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
682 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
686 bool wxTextCtrl::CanCopy() const
688 // Can copy if there's a selection
690 GetSelection(& from
, & to
);
691 return (from
!= to
) ;
694 bool wxTextCtrl::CanCut() const
696 // Can cut if there's a selection
698 GetSelection(& from
, & to
);
699 return (from
!= to
) ;
702 bool wxTextCtrl::CanPaste() const
704 return IsEditable() ;
708 void wxTextCtrl::Undo()
711 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
714 void wxTextCtrl::Redo()
717 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
720 bool wxTextCtrl::CanUndo() const
723 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
727 bool wxTextCtrl::CanRedo() const
730 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
734 // If the return values from and to are the same, there is no
736 void wxTextCtrl::GetSelection(long* from
, long* to
) const
738 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
740 if (!(GTK_EDITABLE(m_text
)->has_selection
))
747 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
748 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
751 bool wxTextCtrl::IsEditable() const
753 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
755 return GTK_EDITABLE(m_text
)->editable
;
758 bool wxTextCtrl::IsModified() const
763 void wxTextCtrl::Clear()
768 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
770 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
772 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
774 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
775 event
.SetEventObject(this);
776 if (GetEventHandler()->ProcessEvent(event
)) return;
782 GtkWidget
* wxTextCtrl::GetConnectWidget()
784 return GTK_WIDGET(m_text
);
787 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
789 if (m_windowStyle
& wxTE_MULTILINE
)
790 return (window
== GTK_TEXT(m_text
)->text_area
);
792 return (window
== GTK_ENTRY(m_text
)->text_area
);
795 // the font will change for subsequent text insertiongs
796 bool wxTextCtrl::SetFont( const wxFont
&font
)
798 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
800 if ( !wxWindowBase::SetFont(font
) )
802 // font didn't change, nothing to do
806 if ( m_windowStyle
& wxTE_MULTILINE
)
808 // for compatibility with other ports: the font is a global controls
809 // characteristic, so change the font globally
810 wxString value
= GetValue();
811 if ( !value
.IsEmpty() )
822 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
824 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
830 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
832 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
834 wxControl::SetBackgroundColour( colour
);
836 if (!m_widget
->window
)
839 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
840 if (sysbg
.Red() == colour
.Red() &&
841 sysbg
.Green() == colour
.Green() &&
842 sysbg
.Blue() == colour
.Blue())
844 return FALSE
; // FIXME or TRUE?
847 if (!m_backgroundColour
.Ok())
850 if (m_windowStyle
& wxTE_MULTILINE
)
852 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
855 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
856 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
857 gdk_window_clear( window
);
863 void wxTextCtrl::ApplyWidgetStyle()
865 if (m_windowStyle
& wxTE_MULTILINE
)
872 gtk_widget_set_style( m_text
, m_widgetStyle
);
876 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
881 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
886 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
891 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
896 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
901 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
903 event
.Enable( CanCut() );
906 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
908 event
.Enable( CanCopy() );
911 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
913 event
.Enable( CanPaste() );
916 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
918 event
.Enable( CanUndo() );
921 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
923 event
.Enable( CanRedo() );