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
)
42 win
->CalculateScrollbar();
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 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
55 gtk_text_size_callback( GtkWidget
*WXUNUSED(widget
), GtkAllocation
* WXUNUSED(alloc
), wxTextCtrl
*win
)
57 win
->CalculateScrollbar();
60 //-----------------------------------------------------------------------------
62 //-----------------------------------------------------------------------------
64 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
66 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
67 EVT_CHAR(wxTextCtrl::OnChar
)
69 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
70 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
71 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
72 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
73 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
75 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
76 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
77 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
78 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
79 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
82 #ifndef NO_TEXT_WINDOW_STREAM
83 wxTextCtrl::wxTextCtrl() : streambuf()
85 if (allocate()) setp(base(),ebuf());
90 wxTextCtrl::wxTextCtrl()
96 #ifndef NO_TEXT_WINDOW_STREAM
97 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
98 const wxPoint
&pos
, const wxSize
&size
,
99 int style
, const wxValidator
& validator
, const wxString
&name
) : streambuf()
101 if (allocate()) setp(base(),ebuf());
104 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
107 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
108 const wxPoint
&pos
, const wxSize
&size
,
109 int style
, const wxValidator
& validator
, const wxString
&name
)
112 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
116 bool wxTextCtrl::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
117 const wxPoint
&pos
, const wxSize
&size
,
118 int style
, const wxValidator
& validator
, const wxString
&name
)
121 m_acceptsFocus
= TRUE
;
123 PreCreation( parent
, id
, pos
, size
, style
, name
);
125 SetValidator( validator
);
127 m_vScrollbarVisible
= TRUE
;
129 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
132 // a multi-line edit control: create a vertical scrollbar by default and
133 // horizontal if requested
134 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
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
);
143 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
144 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
145 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
148 // put the horizontal scrollbar in the lower left hand corner
151 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
152 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
154 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
155 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
),
158 gtk_widget_show(hscrollbar
);
161 // finally, put the vertical scrollbar in the upper right corner
162 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
163 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
165 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
167 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
169 gtk_widget_show( m_vScrollbar
);
171 gtk_signal_connect( GTK_OBJECT(m_widget
), "size_allocate",
172 GTK_SIGNAL_FUNC(gtk_text_size_callback
), (gpointer
)this );
176 // a single-line text control: no need for scrollbars
178 m_text
= gtk_entry_new();
181 wxSize newSize
= size
;
182 if (newSize
.x
== -1) newSize
.x
= 80;
183 if (newSize
.y
== -1) newSize
.y
= 26;
184 SetSize( newSize
.x
, newSize
.y
);
186 m_parent
->AddChild( this );
188 (m_parent
->m_insertCallback
)( m_parent
, this );
194 gtk_widget_realize(m_text
);
195 gtk_widget_show(m_text
);
198 // we want to be notified about text changes
199 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
200 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
202 if (!value
.IsEmpty())
205 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
209 /* bring editable's cursor uptodate. bug in GTK. */
211 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
215 if (style
& wxTE_PASSWORD
)
218 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
221 if (style
& wxTE_READONLY
)
224 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
229 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
234 SetBackgroundColour( parent
->GetBackgroundColour() );
235 SetForegroundColour( parent
->GetForegroundColour() );
240 void wxTextCtrl::CalculateScrollbar()
242 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
244 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
246 if (adj
->upper
- adj
->page_size
< 0.8)
248 if (m_vScrollbarVisible
)
250 gtk_widget_hide( m_vScrollbar
);
252 m_vScrollbarVisible
= FALSE
;
257 if (!m_vScrollbarVisible
)
259 gtk_widget_show( m_vScrollbar
);
261 m_vScrollbarVisible
= TRUE
;
266 wxString
wxTextCtrl::GetValue() const
268 wxCHECK_MSG( m_text
!= NULL
, "", "invalid text ctrl" );
271 if (m_windowStyle
& wxTE_MULTILINE
)
273 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
274 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
280 tmp
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
285 void wxTextCtrl::SetValue( const wxString
&value
)
287 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
290 if (!value
.IsNull()) tmp
= value
;
291 if (m_windowStyle
& wxTE_MULTILINE
)
293 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
294 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
296 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
, tmp
.Length(), &len
);
300 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
);
304 void wxTextCtrl::WriteText( const wxString
&text
)
306 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
308 if (text
.IsNull()) return;
310 if (m_windowStyle
& wxTE_MULTILINE
)
312 /* this moves the cursor pos to behind the inserted text */
313 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
315 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
317 /* bring editable's cursor uptodate. bug in GTK. */
318 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
322 /* this moves the cursor pos to behind the inserted text */
323 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
324 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
326 /* bring editable's cursor uptodate. bug in GTK. */
327 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
329 /* bring entry's cursor uptodate. bug in GTK. */
330 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
334 void wxTextCtrl::AppendText( const wxString
&text
)
336 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
338 if (m_windowStyle
& wxTE_MULTILINE
)
340 /* we'll insert at the last position */
341 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
342 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
344 /* bring editable's cursor uptodate. bug in GTK. */
345 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
349 gtk_entry_append_text( GTK_ENTRY(m_text
), text
);
353 bool wxTextCtrl::LoadFile( const wxString
&file
)
355 wxCHECK_MSG( m_text
!= NULL
, FALSE
, "invalid text ctrl" );
357 if (!wxFileExists(file
)) return FALSE
;
361 FILE *fp
= (FILE*) NULL
;
364 if ((stat ((char*) (const char*) file
, &statb
) == -1) || (statb
.st_mode
& S_IFMT
) != S_IFREG
||
365 !(fp
= fopen ((char*) (const char*) file
, "r")))
371 gint len
= statb
.st_size
;
373 if (!(text
= (char*)malloc ((unsigned) (len
+ 1))))
378 if (fread (text
, sizeof (char), len
, fp
) != (size_t) len
)
385 if (m_windowStyle
& wxTE_MULTILINE
)
388 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, len
, &pos
);
392 gtk_entry_set_text( GTK_ENTRY(m_text
), text
);
402 bool wxTextCtrl::SaveFile( const wxString
&file
)
404 wxCHECK_MSG( m_text
!= NULL
, FALSE
, "invalid text ctrl" );
406 if (file
== "") return FALSE
;
410 if (!(fp
= fopen ((char*) (const char*) file
, "w")))
416 char *text
= (char*) NULL
;
419 if (m_windowStyle
& wxTE_MULTILINE
)
421 len
= gtk_text_get_length( GTK_TEXT(m_text
) );
422 text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
426 text
= gtk_entry_get_text( GTK_ENTRY(m_text
) );
429 if (fwrite (text
, sizeof (char), len
, fp
) != (size_t) len
)
431 // Did not write whole file
434 // Make sure newline terminates the file
435 if (text
[len
- 1] != '\n')
440 if (m_windowStyle
& wxTE_MULTILINE
) g_free( text
);
449 wxString
wxTextCtrl::GetLineText( long lineNo
) const
451 if (m_windowStyle
& wxTE_MULTILINE
)
453 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
454 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
461 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
466 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
473 return wxEmptyString
;
477 if (lineNo
== 0) return GetValue();
478 return wxEmptyString
;
482 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
484 /* If you implement this, don't forget to update the documentation!
485 * (file docs/latex/wx/text.tex) */
486 wxFAIL_MSG( "wxTextCtrl::OnDropFiles not implemented" );
489 long wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
491 if ( m_windowStyle
& wxTE_MULTILINE
)
493 wxString text
= GetValue();
495 // cast to prevent warning. But pos really should've been unsigned.
496 if( (unsigned long)pos
> text
.Len() )
502 const char* stop
= text
.c_str() + pos
;
503 for ( const char *p
= text
.c_str(); p
< stop
; p
++ )
514 else // single line control
516 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
523 // index out of bounds
531 long wxTextCtrl::XYToPosition(long x
, long y
) const
533 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
536 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
542 int wxTextCtrl::GetLineLength(long lineNo
) const
544 wxString str
= GetLineText (lineNo
);
545 return (int) str
.Length();
548 int wxTextCtrl::GetNumberOfLines() const
550 if (m_windowStyle
& wxTE_MULTILINE
)
552 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
553 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
558 for (int i
= 0; i
< len
; i
++ )
565 // currentLine is 0 based, add 1 to get number of lines
566 return currentLine
+ 1;
579 void wxTextCtrl::SetInsertionPoint( long pos
)
581 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
583 if (m_windowStyle
& wxTE_MULTILINE
)
585 /* seems to be broken in GTK 1.0.X:
586 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
588 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
589 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
591 /* we fake a set_point by inserting and deleting. as the user
592 isn't supposed to get to know about thos non-sense, we
593 disconnect so that no events are sent to the user program. */
595 gint tmp
= (gint
)pos
;
596 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
597 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
599 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
600 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
602 /* bring editable's cursor uptodate. another bug in GTK. */
604 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
608 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
610 /* bring editable's cursor uptodate. bug in GTK. */
612 GTK_EDITABLE(m_text
)->current_pos
= pos
;
616 void wxTextCtrl::SetInsertionPointEnd()
618 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
620 if (m_windowStyle
& wxTE_MULTILINE
)
621 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
623 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
626 void wxTextCtrl::SetEditable( bool editable
)
628 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
630 if (m_windowStyle
& wxTE_MULTILINE
)
631 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
633 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
636 void wxTextCtrl::SetSelection( long from
, long to
)
638 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
640 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
643 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
645 wxFAIL_MSG( "wxTextCtrl::ShowPosition not implemented" );
648 long wxTextCtrl::GetInsertionPoint() const
650 wxCHECK_MSG( m_text
!= NULL
, 0, "invalid text ctrl" );
652 return (long) GTK_EDITABLE(m_text
)->current_pos
;
655 long wxTextCtrl::GetLastPosition() const
657 wxCHECK_MSG( m_text
!= NULL
, 0, "invalid text ctrl" );
660 if (m_windowStyle
& wxTE_MULTILINE
)
661 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
663 pos
= GTK_ENTRY(m_text
)->text_length
;
668 void wxTextCtrl::Remove( long from
, long to
)
670 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
672 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
675 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
677 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
679 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
680 if (value
.IsNull()) return;
681 gint pos
= (gint
)from
;
682 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
685 void wxTextCtrl::Cut()
687 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
689 #if (GTK_MINOR_VERSION > 0)
690 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
692 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
696 void wxTextCtrl::Copy()
698 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
700 #if (GTK_MINOR_VERSION > 0)
701 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
703 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
707 void wxTextCtrl::Paste()
709 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
711 #if (GTK_MINOR_VERSION > 0)
712 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
714 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
718 bool wxTextCtrl::CanCopy() const
720 // Can copy if there's a selection
722 GetSelection(& from
, & to
);
723 return (from
!= to
) ;
726 bool wxTextCtrl::CanCut() const
728 // Can cut if there's a selection
730 GetSelection(& from
, & to
);
731 return (from
!= to
) ;
734 bool wxTextCtrl::CanPaste() const
736 return IsEditable() ;
740 void wxTextCtrl::Undo()
743 wxFAIL_MSG( "wxTextCtrl::Undo not implemented" );
746 void wxTextCtrl::Redo()
749 wxFAIL_MSG( "wxTextCtrl::Redo not implemented" );
752 bool wxTextCtrl::CanUndo() const
755 wxFAIL_MSG( "wxTextCtrl::CanUndo not implemented" );
759 bool wxTextCtrl::CanRedo() const
762 wxFAIL_MSG( "wxTextCtrl::CanRedo not implemented" );
766 // If the return values from and to are the same, there is no
768 void wxTextCtrl::GetSelection(long* from
, long* to
) const
773 wxFAIL_MSG( "wxTextCtrl::GetSelection not implemented" );
776 bool wxTextCtrl::IsEditable() const
779 wxFAIL_MSG( "wxTextCtrl::IsEditable not implemented" );
783 void wxTextCtrl::Clear()
788 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
790 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
792 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
794 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
795 event
.SetEventObject(this);
796 if (GetEventHandler()->ProcessEvent(event
)) return;
802 #ifndef NO_TEXT_WINDOW_STREAM
803 int wxTextCtrl::overflow( int WXUNUSED(c
) )
805 int len
= pptr() - pbase();
806 char *txt
= new char[len
+1];
807 strncpy(txt
, pbase(), len
);
810 setp(pbase(), epptr());
815 int wxTextCtrl::sync()
817 int len
= pptr() - pbase();
818 char *txt
= new char[len
+1];
819 strncpy(txt
, pbase(), len
);
822 setp(pbase(), epptr());
827 int wxTextCtrl::underflow()
832 wxTextCtrl
& wxTextCtrl::operator<<(const wxString
& s
)
838 wxTextCtrl
& wxTextCtrl::operator<<(float f
)
840 static char buf
[100];
841 sprintf(buf
, "%.2f", f
);
846 wxTextCtrl
& wxTextCtrl::operator<<(double d
)
848 static char buf
[100];
849 sprintf(buf
, "%.2f", d
);
854 wxTextCtrl
& wxTextCtrl::operator<<(int i
)
856 static char buf
[100];
857 sprintf(buf
, "%i", i
);
862 wxTextCtrl
& wxTextCtrl::operator<<(long i
)
864 static char buf
[100];
865 sprintf(buf
, "%ld", i
);
870 wxTextCtrl
& wxTextCtrl::operator<<(const char c
)
881 GtkWidget
* wxTextCtrl::GetConnectWidget()
883 return GTK_WIDGET(m_text
);
886 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
888 if (m_windowStyle
& wxTE_MULTILINE
)
889 return (window
== GTK_TEXT(m_text
)->text_area
);
891 return (window
== GTK_ENTRY(m_text
)->text_area
);
894 void wxTextCtrl::SetFont( const wxFont
&WXUNUSED(font
) )
896 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
901 void wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
903 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
908 void wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
910 wxCHECK_RET( m_text
!= NULL
, "invalid text ctrl" );
912 wxControl::SetBackgroundColour( colour
);
914 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
915 if (sysbg
.Red() == colour
.Red() &&
916 sysbg
.Green() == colour
.Green() &&
917 sysbg
.Blue() == colour
.Blue())
922 if (!m_backgroundColour
.Ok()) return;
924 if (m_windowStyle
& wxTE_MULTILINE
)
926 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
927 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
928 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
929 gdk_window_clear( window
);
933 void wxTextCtrl::ApplyWidgetStyle()
935 if (m_windowStyle
& wxTE_MULTILINE
)
942 gtk_widget_set_style( m_text
, m_widgetStyle
);
946 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
951 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
956 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
961 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
966 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
971 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
973 event
.Enable( CanCut() );
976 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
978 event
.Enable( CanCopy() );
981 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
983 event
.Enable( CanPaste() );
986 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
988 event
.Enable( CanUndo() );
991 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
993 event
.Enable( CanRedo() );