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 wxString tmp
= _T("");
302 if (!value
.IsNull()) tmp
= value
;
303 if (m_windowStyle
& wxTE_MULTILINE
)
305 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
306 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
309 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
310 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
312 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
317 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
321 void wxTextCtrl::WriteText( const wxString
&text
)
323 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
325 if (text
.IsEmpty()) return;
327 if (m_windowStyle
& wxTE_MULTILINE
)
329 /* this moves the cursor pos to behind the inserted text */
330 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
333 wxWX2MBbuf buf
= text
.mbc_str();
334 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
336 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
339 /* bring editable's cursor uptodate. bug in GTK. */
340 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
344 /* this moves the cursor pos to behind the inserted text */
345 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
347 wxWX2MBbuf buf
= text
.mbc_str();
348 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
350 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
353 /* bring editable's cursor uptodate. bug in GTK. */
354 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
356 /* bring entry's cursor uptodate. bug in GTK. */
357 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
361 void wxTextCtrl::AppendText( const wxString
&text
)
363 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
365 if (text
.IsEmpty()) return;
367 if (m_windowStyle
& wxTE_MULTILINE
)
369 bool hasSpecialAttributes
= m_font
.Ok() ||
370 m_foregroundColour
.Ok() ||
371 m_backgroundColour
.Ok();
372 if ( hasSpecialAttributes
)
374 gtk_text_insert( GTK_TEXT(m_text
),
375 m_font
.GetInternalFont(),
376 m_foregroundColour
.GetColor(),
377 m_backgroundColour
.GetColor(),
378 text
.mbc_str(), text
.length());
383 /* we'll insert at the last position */
384 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
386 wxWX2MBbuf buf
= text
.mbc_str();
387 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
389 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
393 /* bring editable's cursor uptodate. bug in GTK. */
394 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
398 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
402 wxString
wxTextCtrl::GetLineText( long lineNo
) const
404 if (m_windowStyle
& wxTE_MULTILINE
)
406 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
407 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
411 wxString
buf(_T(""));
414 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
419 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
426 return wxEmptyString
;
430 if (lineNo
== 0) return GetValue();
431 return wxEmptyString
;
435 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
437 /* If you implement this, don't forget to update the documentation!
438 * (file docs/latex/wx/text.tex) */
439 wxFAIL_MSG( _T("wxTextCtrl::OnDropFiles not implemented") );
442 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
444 if ( m_windowStyle
& wxTE_MULTILINE
)
446 wxString text
= GetValue();
448 // cast to prevent warning. But pos really should've been unsigned.
449 if( (unsigned long)pos
> text
.Len() )
455 const wxChar
* stop
= text
.c_str() + pos
;
456 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
467 else // single line control
469 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
476 // index out of bounds
484 long wxTextCtrl::XYToPosition(long x
, long y
) const
486 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
489 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
495 int wxTextCtrl::GetLineLength(long lineNo
) const
497 wxString str
= GetLineText (lineNo
);
498 return (int) str
.Length();
501 int wxTextCtrl::GetNumberOfLines() const
503 if (m_windowStyle
& wxTE_MULTILINE
)
505 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
506 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
511 for (int i
= 0; i
< len
; i
++ )
518 // currentLine is 0 based, add 1 to get number of lines
519 return currentLine
+ 1;
532 void wxTextCtrl::SetInsertionPoint( long pos
)
534 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
536 if (m_windowStyle
& wxTE_MULTILINE
)
538 /* seems to be broken in GTK 1.0.X:
539 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
541 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
542 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
544 /* we fake a set_point by inserting and deleting. as the user
545 isn't supposed to get to know about thos non-sense, we
546 disconnect so that no events are sent to the user program. */
548 gint tmp
= (gint
)pos
;
549 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
550 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
552 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
553 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
555 /* bring editable's cursor uptodate. another bug in GTK. */
557 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
561 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
563 /* bring editable's cursor uptodate. bug in GTK. */
565 GTK_EDITABLE(m_text
)->current_pos
= pos
;
569 void wxTextCtrl::SetInsertionPointEnd()
571 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
573 if (m_windowStyle
& wxTE_MULTILINE
)
574 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
576 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
579 void wxTextCtrl::SetEditable( bool editable
)
581 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
583 if (m_windowStyle
& wxTE_MULTILINE
)
584 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
586 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
589 void wxTextCtrl::DiscardEdits()
594 void wxTextCtrl::SetSelection( long from
, long to
)
596 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
598 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
601 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
603 // SetInsertionPoint( pos );
606 long wxTextCtrl::GetInsertionPoint() const
608 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
610 return (long) GTK_EDITABLE(m_text
)->current_pos
;
613 long wxTextCtrl::GetLastPosition() const
615 wxCHECK_MSG( m_text
!= NULL
, 0, _T("invalid text ctrl") );
618 if (m_windowStyle
& wxTE_MULTILINE
)
619 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
621 pos
= GTK_ENTRY(m_text
)->text_length
;
626 void wxTextCtrl::Remove( long from
, long to
)
628 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
630 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
633 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
635 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
637 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
639 if (!value
.IsEmpty())
641 gint pos
= (gint
)from
;
643 wxWX2MBbuf buf
= value
.mbc_str();
644 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
646 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
651 void wxTextCtrl::Cut()
653 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
655 #if (GTK_MINOR_VERSION > 0)
656 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
658 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
662 void wxTextCtrl::Copy()
664 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
666 #if (GTK_MINOR_VERSION > 0)
667 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
669 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
673 void wxTextCtrl::Paste()
675 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
677 #if (GTK_MINOR_VERSION > 0)
678 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
680 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
684 bool wxTextCtrl::CanCopy() const
686 // Can copy if there's a selection
688 GetSelection(& from
, & to
);
689 return (from
!= to
) ;
692 bool wxTextCtrl::CanCut() const
694 // Can cut if there's a selection
696 GetSelection(& from
, & to
);
697 return (from
!= to
) ;
700 bool wxTextCtrl::CanPaste() const
702 return IsEditable() ;
706 void wxTextCtrl::Undo()
709 wxFAIL_MSG( _T("wxTextCtrl::Undo not implemented") );
712 void wxTextCtrl::Redo()
715 wxFAIL_MSG( _T("wxTextCtrl::Redo not implemented") );
718 bool wxTextCtrl::CanUndo() const
721 wxFAIL_MSG( _T("wxTextCtrl::CanUndo not implemented") );
725 bool wxTextCtrl::CanRedo() const
728 wxFAIL_MSG( _T("wxTextCtrl::CanRedo not implemented") );
732 // If the return values from and to are the same, there is no
734 void wxTextCtrl::GetSelection(long* from
, long* to
) const
736 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
738 if (!(GTK_EDITABLE(m_text
)->has_selection
))
745 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
746 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
749 bool wxTextCtrl::IsEditable() const
751 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
753 return GTK_EDITABLE(m_text
)->editable
;
756 bool wxTextCtrl::IsModified() const
761 void wxTextCtrl::Clear()
766 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
768 wxCHECK_RET( m_text
!= NULL
, _T("invalid text ctrl") );
770 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
772 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
773 event
.SetEventObject(this);
774 if (GetEventHandler()->ProcessEvent(event
)) return;
780 GtkWidget
* wxTextCtrl::GetConnectWidget()
782 return GTK_WIDGET(m_text
);
785 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
787 if (m_windowStyle
& wxTE_MULTILINE
)
788 return (window
== GTK_TEXT(m_text
)->text_area
);
790 return (window
== GTK_ENTRY(m_text
)->text_area
);
793 // the font will change for subsequent text insertiongs
794 bool wxTextCtrl::SetFont( const wxFont
&font
)
796 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
798 if ( !wxWindowBase::SetFont(font
) )
800 // font didn't change, nothing to do
804 if ( m_windowStyle
& wxTE_MULTILINE
)
806 // for compatibility with other ports: the font is a global controls
807 // characteristic, so change the font globally
808 wxString value
= GetValue();
809 if ( !value
.IsEmpty() )
820 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
822 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
828 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
830 wxCHECK_MSG( m_text
!= NULL
, FALSE
, _T("invalid text ctrl") );
832 wxControl::SetBackgroundColour( colour
);
834 if (!m_widget
->window
)
837 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
838 if (sysbg
.Red() == colour
.Red() &&
839 sysbg
.Green() == colour
.Green() &&
840 sysbg
.Blue() == colour
.Blue())
842 return FALSE
; // FIXME or TRUE?
845 if (!m_backgroundColour
.Ok())
848 if (m_windowStyle
& wxTE_MULTILINE
)
850 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
853 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
854 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
855 gdk_window_clear( window
);
861 void wxTextCtrl::ApplyWidgetStyle()
863 if (m_windowStyle
& wxTE_MULTILINE
)
870 gtk_widget_set_style( m_text
, m_widgetStyle
);
874 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
879 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
884 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
889 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
894 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
899 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
901 event
.Enable( CanCut() );
904 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
906 event
.Enable( CanCopy() );
909 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
911 event
.Enable( CanPaste() );
914 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
916 event
.Enable( CanUndo() );
919 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
921 event
.Enable( CanRedo() );