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 bool g_blockEventsOnDrag
;
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
38 gtk_text_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
40 if (!win
->m_hasVMT
) return;
44 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->m_windowId
);
45 event
.SetString( win
->GetValue() );
46 event
.SetEventObject( win
);
47 win
->GetEventHandler()->ProcessEvent( event
);
50 //-----------------------------------------------------------------------------
51 // "changed" from vertical scrollbar
52 //-----------------------------------------------------------------------------
55 gtk_scrollbar_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
57 if (!win
->m_hasVMT
) return;
59 win
->CalculateScrollbar();
62 //-----------------------------------------------------------------------------
64 //-----------------------------------------------------------------------------
66 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
68 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
69 EVT_CHAR(wxTextCtrl::OnChar
)
71 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
72 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
73 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
74 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
75 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
77 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
78 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
79 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
80 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
81 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
84 #ifndef NO_TEXT_WINDOW_STREAM
85 wxTextCtrl::wxTextCtrl() : streambuf()
87 if (allocate()) setp(base(),ebuf());
92 wxTextCtrl::wxTextCtrl()
98 #ifndef NO_TEXT_WINDOW_STREAM
99 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
100 const wxPoint
&pos
, const wxSize
&size
,
101 int style
, const wxValidator
& validator
, const wxString
&name
) : streambuf()
103 if (allocate()) setp(base(),ebuf());
106 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
109 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
110 const wxPoint
&pos
, const wxSize
&size
,
111 int style
, const wxValidator
& validator
, const wxString
&name
)
114 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
118 bool wxTextCtrl::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
119 const wxPoint
&pos
, const wxSize
&size
,
120 int style
, const wxValidator
& validator
, const wxString
&name
)
123 m_acceptsFocus
= TRUE
;
125 PreCreation( parent
, id
, pos
, size
, style
, name
);
127 SetValidator( validator
);
129 m_vScrollbarVisible
= FALSE
;
131 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
134 /* a multi-line edit control: create a vertical scrollbar by default and
135 horizontal if requested */
136 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
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
);
145 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
146 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
147 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
150 /* put the horizontal scrollbar in the lower left hand corner */
153 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
154 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
),
160 gtk_widget_show(hscrollbar
);
163 /* we create the vertical scrollbar on demand */
164 m_vScrollbar
= (GtkWidget
*) NULL
;
169 /* a single-line text control: no need for scrollbars */
171 m_text
= gtk_entry_new();
174 wxSize newSize
= size
;
175 if (newSize
.x
== -1) newSize
.x
= 80;
176 if (newSize
.y
== -1) newSize
.y
= 26;
177 SetSize( newSize
.x
, newSize
.y
);
179 m_parent
->AddChild( this );
181 (m_parent
->m_insertCallback
)( m_parent
, this );
187 gtk_widget_realize(m_text
);
188 gtk_widget_show(m_text
);
191 /* we want to be notified about text changes */
192 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
193 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
195 if (!value
.IsEmpty())
198 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
202 /* bring editable's cursor uptodate. bug in GTK. */
204 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
208 if (style
& wxTE_PASSWORD
)
211 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
214 if (style
& wxTE_READONLY
)
217 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
222 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
225 SetBackgroundColour( parent
->GetBackgroundColour() );
226 SetForegroundColour( parent
->GetForegroundColour() );
232 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
233 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
239 void wxTextCtrl::CalculateScrollbar()
241 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
243 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
245 if (adj
->upper
- adj
->page_size
< 0.8)
247 if (m_vScrollbarVisible
)
249 gtk_widget_hide( m_vScrollbar
);
251 m_vScrollbarVisible
= FALSE
;
256 if (!m_vScrollbarVisible
)
260 /* finally, put the vertical scrollbar in the upper right corner */
261 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
262 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
264 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
266 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
270 gtk_widget_show( m_vScrollbar
);
272 m_vScrollbarVisible
= TRUE
;
277 wxString
wxTextCtrl::GetValue() const
279 wxCHECK_MSG( m_text
!= NULL
, "", "invalid text ctrl" );
282 if (m_windowStyle
& wxTE_MULTILINE
)
284 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
285 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
291 tmp
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
296 void wxTextCtrl::SetValue( const wxString
&value
)
298 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
301 if (!value
.IsNull()) tmp
= value
;
302 if (m_windowStyle
& wxTE_MULTILINE
)
304 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
305 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
307 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
, tmp
.Length(), &len
);
311 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
);
315 void wxTextCtrl::WriteText( const wxString
&text
)
317 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
319 if (text
.IsNull()) return;
321 if (m_windowStyle
& wxTE_MULTILINE
)
323 /* this moves the cursor pos to behind the inserted text */
324 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
326 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
328 /* bring editable's cursor uptodate. bug in GTK. */
329 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
333 /* this moves the cursor pos to behind the inserted text */
334 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
335 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
337 /* bring editable's cursor uptodate. bug in GTK. */
338 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
340 /* bring entry's cursor uptodate. bug in GTK. */
341 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
345 void wxTextCtrl::AppendText( const wxString
&text
)
347 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
349 if (m_windowStyle
& wxTE_MULTILINE
)
351 /* we'll insert at the last position */
352 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
353 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
= gtk_text_get_point( GTK_TEXT(m_text
) );
360 gtk_entry_append_text( GTK_ENTRY(m_text
), text
);
364 bool wxTextCtrl::LoadFile( const wxString
&file
)
366 wxCHECK_MSG( m_text
!= NULL
, FALSE
, "invalid text ctrl" );
368 if (!wxFileExists(file
)) return FALSE
;
372 FILE *fp
= (FILE*) NULL
;
375 if ((stat ((char*) (const char*) file
, &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
376 !(fp
= fopen ((char*) (const char*) file
, "r")))
382 gint len
= statb
.st_size
;
384 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
389 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
396 if (m_windowStyle
& wxTE_MULTILINE
)
399 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
403 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
413 bool wxTextCtrl::SaveFile( const wxString
&file
)
415 wxCHECK_MSG( m_text
!= NULL
, FALSE
, "invalid text ctrl" );
417 if (file
== "") return FALSE
;
421 if (!(fp
= fopen ((char*) (const char*) file
, "w")))
427 char *text
= (char*) NULL
;
430 if (m_windowStyle
& wxTE_MULTILINE
)
432 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
433 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
437 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
440 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
442 // Did not write whole file
445 // Make sure newline terminates the file
446 if (text
[len
- 1] != '\n')
451 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
460 wxString
wxTextCtrl::GetLineText( long lineNo
) const
462 if (m_windowStyle
& wxTE_MULTILINE
)
464 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
465 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
472 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
477 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
484 return wxEmptyString
;
488 if (lineNo
== 0) return GetValue();
489 return wxEmptyString
;
493 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
495 /* If you implement this, don't forget to update the documentation!
496 * (file docs/latex/wx/text.tex) */
497 wxFAIL_MSG( "wxTextCtrl::OnDropFiles not implemented" );
500 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
502 if ( m_windowStyle
& wxTE_MULTILINE
)
504 wxString text
= GetValue();
506 // cast to prevent warning. But pos really should've been unsigned.
507 if( (unsigned long)pos
> text
.Len() )
513 const char* stop
= text
.c_str() + pos
;
514 for ( const char *p
= text
.c_str(); p
< stop
; p
++ )
525 else // single line control
527 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
534 // index out of bounds
542 long wxTextCtrl::XYToPosition(long x
, long y
) const
544 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
547 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
553 int wxTextCtrl::GetLineLength(long lineNo
) const
555 wxString str
= GetLineText (lineNo
);
556 return (int) str
.Length();
559 int wxTextCtrl::GetNumberOfLines() const
561 if (m_windowStyle
& wxTE_MULTILINE
)
563 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
564 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
569 for (int i
= 0; i
< len
; i
++ )
576 // currentLine is 0 based, add 1 to get number of lines
577 return currentLine
+ 1;
590 void wxTextCtrl::SetInsertionPoint( long pos
)
592 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
594 if (m_windowStyle
& wxTE_MULTILINE
)
596 /* seems to be broken in GTK 1.0.X:
597 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
599 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
600 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
602 /* we fake a set_point by inserting and deleting. as the user
603 isn't supposed to get to know about thos non-sense, we
604 disconnect so that no events are sent to the user program. */
606 gint tmp
= (gint
)pos
;
607 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
608 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
610 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
611 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
613 /* bring editable's cursor uptodate. another bug in GTK. */
615 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
619 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
621 /* bring editable's cursor uptodate. bug in GTK. */
623 GTK_EDITABLE(m_text
)->current_pos
= pos
;
627 void wxTextCtrl::SetInsertionPointEnd()
629 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
631 if (m_windowStyle
& wxTE_MULTILINE
)
632 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
634 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
637 void wxTextCtrl::SetEditable( bool editable
)
639 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
641 if (m_windowStyle
& wxTE_MULTILINE
)
642 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
644 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
647 void wxTextCtrl::SetSelection( long from
, long to
)
649 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
651 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
654 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
656 wxFAIL_MSG( "wxTextCtrl::ShowPosition not implemented" );
659 long wxTextCtrl::GetInsertionPoint() const
661 wxCHECK_MSG( m_text
!= NULL
, 0, "invalid text ctrl" );
663 return (long) GTK_EDITABLE(m_text
)->current_pos
;
666 long wxTextCtrl::GetLastPosition() const
668 wxCHECK_MSG( m_text
!= NULL
, 0, "invalid text ctrl" );
671 if (m_windowStyle
& wxTE_MULTILINE
)
672 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
674 pos
= GTK_ENTRY(m_text
)->text_length
;
679 void wxTextCtrl::Remove( long from
, long to
)
681 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
683 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
686 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
688 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
690 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
691 if (value
.IsNull()) return;
692 gint pos
= (gint
)from
;
693 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
696 void wxTextCtrl::Cut()
698 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
700 #if (GTK_MINOR_VERSION > 0)
701 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
703 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
707 void wxTextCtrl::Copy()
709 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
711 #if (GTK_MINOR_VERSION > 0)
712 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
714 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
718 void wxTextCtrl::Paste()
720 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
722 #if (GTK_MINOR_VERSION > 0)
723 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
725 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
729 bool wxTextCtrl::CanCopy() const
731 // Can copy if there's a selection
733 GetSelection(& from
, & to
);
734 return (from
!= to
) ;
737 bool wxTextCtrl::CanCut() const
739 // Can cut if there's a selection
741 GetSelection(& from
, & to
);
742 return (from
!= to
) ;
745 bool wxTextCtrl::CanPaste() const
747 return IsEditable() ;
751 void wxTextCtrl::Undo()
754 wxFAIL_MSG( "wxTextCtrl::Undo not implemented" );
757 void wxTextCtrl::Redo()
760 wxFAIL_MSG( "wxTextCtrl::Redo not implemented" );
763 bool wxTextCtrl::CanUndo() const
766 wxFAIL_MSG( "wxTextCtrl::CanUndo not implemented" );
770 bool wxTextCtrl::CanRedo() const
773 wxFAIL_MSG( "wxTextCtrl::CanRedo not implemented" );
777 // If the return values from and to are the same, there is no
779 void wxTextCtrl::GetSelection(long* from
, long* to
) const
784 wxFAIL_MSG( "wxTextCtrl::GetSelection not implemented" );
787 bool wxTextCtrl::IsEditable() const
790 wxFAIL_MSG( "wxTextCtrl::IsEditable not implemented" );
794 void wxTextCtrl::Clear()
799 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
801 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
803 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
805 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
806 event
.SetEventObject(this);
807 if (GetEventHandler()->ProcessEvent(event
)) return;
813 #ifndef NO_TEXT_WINDOW_STREAM
814 int wxTextCtrl::overflow( int WXUNUSED(c
) )
816 int len
= pptr() - pbase();
817 char *txt
= new char[len
+1];
818 strncpy(txt
, pbase(), len
);
821 setp(pbase(), epptr());
826 int wxTextCtrl::sync()
828 int len
= pptr() - pbase();
829 char *txt
= new char[len
+1];
830 strncpy(txt
, pbase(), len
);
833 setp(pbase(), epptr());
838 int wxTextCtrl::underflow()
843 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
849 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
851 static char buf
[100];
852 sprintf(buf
, "%.2f", f
);
857 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
859 static char buf
[100];
860 sprintf(buf
, "%.2f", d
);
865 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
867 static char buf
[100];
868 sprintf(buf
, "%i", i
);
873 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
875 static char buf
[100];
876 sprintf(buf
, "%ld", i
);
881 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
892 GtkWidget
* wxTextCtrl::GetConnectWidget()
894 return GTK_WIDGET(m_text
);
897 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
899 if (m_windowStyle
& wxTE_MULTILINE
)
900 return (window
== GTK_TEXT(m_text
)->text_area
);
902 return (window
== GTK_ENTRY(m_text
)->text_area
);
905 void wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
907 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
912 void wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
914 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
919 void wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
921 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
923 wxControl::SetBackgroundColour( colour
);
925 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
926 if (sysbg
.Red() == colour
.Red() &&
927 sysbg
.Green() == colour
.Green() &&
928 sysbg
.Blue() == colour
.Blue())
933 if (!m_backgroundColour
.Ok()) return;
935 if (m_windowStyle
& wxTE_MULTILINE
)
937 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
938 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
939 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
940 gdk_window_clear( window
);
944 void wxTextCtrl::ApplyWidgetStyle()
946 if (m_windowStyle
& wxTE_MULTILINE
)
953 gtk_widget_set_style( m_text
, m_widgetStyle
);
957 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
962 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
967 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
972 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
977 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
982 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
984 event
.Enable( CanCut() );
987 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
989 event
.Enable( CanCopy() );
992 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
994 event
.Enable( CanPaste() );
997 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
999 event
.Enable( CanUndo() );
1002 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1004 event
.Enable( CanRedo() );