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
;
39 extern wxCursor g_globalCursor
;
41 //-----------------------------------------------------------------------------
43 //-----------------------------------------------------------------------------
46 gtk_text_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
48 if (!win
->m_hasVMT
) return;
51 wxapp_install_idle_handler();
55 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->GetId() );
56 event
.SetString( win
->GetValue() );
57 event
.SetEventObject( win
);
58 win
->GetEventHandler()->ProcessEvent( event
);
61 //-----------------------------------------------------------------------------
62 // "changed" from vertical scrollbar
63 //-----------------------------------------------------------------------------
66 gtk_scrollbar_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
68 if (!win
->m_hasVMT
) return;
71 wxapp_install_idle_handler();
73 win
->CalculateScrollbar();
76 //-----------------------------------------------------------------------------
78 //-----------------------------------------------------------------------------
80 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
82 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
83 EVT_CHAR(wxTextCtrl::OnChar
)
85 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
86 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
87 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
88 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
89 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
91 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
92 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
93 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
94 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
95 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
98 wxTextCtrl::wxTextCtrl()
103 wxTextCtrl::wxTextCtrl( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
104 const wxPoint
&pos
, const wxSize
&size
,
105 int style
, const wxValidator
& validator
, const wxString
&name
)
108 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
111 bool wxTextCtrl::Create( wxWindow
*parent
, wxWindowID id
, const wxString
&value
,
112 const wxPoint
&pos
, const wxSize
&size
,
113 int style
, const wxValidator
& validator
, const wxString
&name
)
116 m_acceptsFocus
= TRUE
;
118 if (!PreCreation( parent
, pos
, size
) ||
119 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
121 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
126 m_vScrollbarVisible
= FALSE
;
128 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
131 #if (GTK_MINOR_VERSION > 2)
132 /* a multi-line edit control: create a vertical scrollbar by default and
133 horizontal if requested */
134 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
136 bool bHasHScrollbar
= FALSE
;
139 /* create our control ... */
140 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
142 /* ... and put into the upper left hand corner of the table */
143 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
144 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 /* always wrap words */
151 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
153 #if (GTK_MINOR_VERSION > 2)
154 /* put the horizontal scrollbar in the lower left hand corner */
157 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
158 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
159 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
160 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
163 gtk_widget_show(hscrollbar
);
165 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
166 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
170 /* finally, put the vertical scrollbar in the upper right corner */
171 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
172 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
173 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
175 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
180 /* a single-line text control: no need for scrollbars */
182 m_text
= gtk_entry_new();
185 wxSize newSize
= size
;
186 if (newSize
.x
== -1) newSize
.x
= 80;
187 if (newSize
.y
== -1) newSize
.y
= 26;
188 SetSize( newSize
.x
, newSize
.y
);
190 m_parent
->DoAddChild( this );
195 gtk_widget_show(m_text
);
197 /* we want to be notified about text changes */
198 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
199 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
203 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
204 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
207 if (!value
.IsEmpty())
211 #if GTK_MINOR_VERSION == 0
212 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
213 // gtk_editable_insert_text()
214 gtk_widget_realize(m_text
);
218 wxWX2MBbuf val
= value
.mbc_str();
219 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
221 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
222 #endif // Unicode/!Unicode
226 /* bring editable's cursor uptodate. bug in GTK. */
228 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
232 if (style
& wxTE_PASSWORD
)
235 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
238 if (style
& wxTE_READONLY
)
241 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
246 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
249 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) );
250 SetForegroundColour( parent
->GetForegroundColour() );
252 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
259 void wxTextCtrl::CalculateScrollbar()
261 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
263 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
265 if (adj
->upper
- adj
->page_size
< 0.8)
267 if (m_vScrollbarVisible
)
269 gtk_widget_hide( m_vScrollbar
);
270 m_vScrollbarVisible
= FALSE
;
275 if (!m_vScrollbarVisible
)
277 gtk_widget_show( m_vScrollbar
);
278 m_vScrollbarVisible
= TRUE
;
283 wxString
wxTextCtrl::GetValue() const
285 wxCHECK_MSG( m_text
!= NULL
, wxT(""), wxT("invalid text ctrl") );
288 if (m_windowStyle
& wxTE_MULTILINE
)
290 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
291 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
292 tmp
= wxString(text
,*wxConvCurrent
);
297 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConvCurrent
);
302 void wxTextCtrl::SetValue( const wxString
&value
)
304 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
306 wxString tmp
= wxT("");
307 if (!value
.IsNull()) tmp
= value
;
308 if (m_windowStyle
& wxTE_MULTILINE
)
310 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
311 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
314 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
315 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
317 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
322 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
326 void wxTextCtrl::WriteText( const wxString
&text
)
328 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
330 if (text
.IsEmpty()) return;
332 if (m_windowStyle
& wxTE_MULTILINE
)
334 /* this moves the cursor pos to behind the inserted text */
335 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
338 wxWX2MBbuf buf
= text
.mbc_str();
339 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
341 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 /* this moves the cursor pos to behind the inserted text */
350 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
352 wxWX2MBbuf buf
= text
.mbc_str();
353 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
355 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
358 /* bring editable's cursor uptodate. bug in GTK. */
359 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
361 /* bring entry's cursor uptodate. bug in GTK. */
362 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
366 void wxTextCtrl::AppendText( const wxString
&text
)
368 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
370 if (text
.IsEmpty()) return;
372 if (m_windowStyle
& wxTE_MULTILINE
)
374 bool hasSpecialAttributes
= m_font
.Ok() ||
375 m_foregroundColour
.Ok() ||
376 m_backgroundColour
.Ok();
377 if ( hasSpecialAttributes
)
379 gtk_text_insert( GTK_TEXT(m_text
),
380 m_font
.GetInternalFont(),
381 m_foregroundColour
.GetColor(),
382 m_backgroundColour
.GetColor(),
383 text
.mbc_str(), text
.length());
388 /* we'll insert at the last position */
389 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
391 wxWX2MBbuf buf
= text
.mbc_str();
392 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
394 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
398 /* bring editable's cursor uptodate. bug in GTK. */
399 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
403 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
407 wxString
wxTextCtrl::GetLineText( long lineNo
) const
409 if (m_windowStyle
& wxTE_MULTILINE
)
411 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
412 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
416 wxString
buf(wxT(""));
419 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
424 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
431 return wxEmptyString
;
435 if (lineNo
== 0) return GetValue();
436 return wxEmptyString
;
440 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
442 /* If you implement this, don't forget to update the documentation!
443 * (file docs/latex/wx/text.tex) */
444 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
447 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
449 if ( m_windowStyle
& wxTE_MULTILINE
)
451 wxString text
= GetValue();
453 // cast to prevent warning. But pos really should've been unsigned.
454 if( (unsigned long)pos
> text
.Len() )
460 const wxChar
* stop
= text
.c_str() + pos
;
461 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
472 else // single line control
474 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
481 // index out of bounds
489 long wxTextCtrl::XYToPosition(long x
, long y
) const
491 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
494 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
500 int wxTextCtrl::GetLineLength(long lineNo
) const
502 wxString str
= GetLineText (lineNo
);
503 return (int) str
.Length();
506 int wxTextCtrl::GetNumberOfLines() const
508 if (m_windowStyle
& wxTE_MULTILINE
)
510 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
511 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
516 for (int i
= 0; i
< len
; i
++ )
523 // currentLine is 0 based, add 1 to get number of lines
524 return currentLine
+ 1;
537 void wxTextCtrl::SetInsertionPoint( long pos
)
539 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
541 if (m_windowStyle
& wxTE_MULTILINE
)
543 /* seems to be broken in GTK 1.0.X:
544 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
546 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
547 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
549 /* we fake a set_point by inserting and deleting. as the user
550 isn't supposed to get to know about thos non-sense, we
551 disconnect so that no events are sent to the user program. */
553 gint tmp
= (gint
)pos
;
554 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
555 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
557 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
558 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
560 /* bring editable's cursor uptodate. another bug in GTK. */
562 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
566 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
568 /* bring editable's cursor uptodate. bug in GTK. */
570 GTK_EDITABLE(m_text
)->current_pos
= pos
;
574 void wxTextCtrl::SetInsertionPointEnd()
576 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
578 if (m_windowStyle
& wxTE_MULTILINE
)
579 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
581 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
584 void wxTextCtrl::SetEditable( bool editable
)
586 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
588 if (m_windowStyle
& wxTE_MULTILINE
)
589 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
591 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
594 void wxTextCtrl::DiscardEdits()
599 void wxTextCtrl::SetSelection( long from
, long to
)
601 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
603 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
606 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
608 // SetInsertionPoint( pos );
611 long wxTextCtrl::GetInsertionPoint() const
613 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
615 return (long) GTK_EDITABLE(m_text
)->current_pos
;
618 long wxTextCtrl::GetLastPosition() const
620 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
623 if (m_windowStyle
& wxTE_MULTILINE
)
624 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
626 pos
= GTK_ENTRY(m_text
)->text_length
;
631 void wxTextCtrl::Remove( long from
, long to
)
633 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
635 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
638 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
640 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
642 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
644 if (!value
.IsEmpty())
646 gint pos
= (gint
)from
;
648 wxWX2MBbuf buf
= value
.mbc_str();
649 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
651 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
656 void wxTextCtrl::Cut()
658 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
660 #if (GTK_MINOR_VERSION > 0)
661 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
663 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
667 void wxTextCtrl::Copy()
669 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
671 #if (GTK_MINOR_VERSION > 0)
672 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
674 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
678 void wxTextCtrl::Paste()
680 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
682 #if (GTK_MINOR_VERSION > 0)
683 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
685 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
689 bool wxTextCtrl::CanCopy() const
691 // Can copy if there's a selection
693 GetSelection(& from
, & to
);
694 return (from
!= to
) ;
697 bool wxTextCtrl::CanCut() const
699 // Can cut if there's a selection
701 GetSelection(& from
, & to
);
702 return (from
!= to
) ;
705 bool wxTextCtrl::CanPaste() const
707 return IsEditable() ;
711 void wxTextCtrl::Undo()
714 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
717 void wxTextCtrl::Redo()
720 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
723 bool wxTextCtrl::CanUndo() const
726 wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
730 bool wxTextCtrl::CanRedo() const
733 wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
737 // If the return values from and to are the same, there is no
739 void wxTextCtrl::GetSelection(long* from
, long* to
) const
741 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
743 if (!(GTK_EDITABLE(m_text
)->has_selection
))
750 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
751 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
754 bool wxTextCtrl::IsEditable() const
756 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
758 return GTK_EDITABLE(m_text
)->editable
;
761 bool wxTextCtrl::IsModified() const
766 void wxTextCtrl::Clear()
771 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
773 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
775 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
777 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
778 event
.SetEventObject(this);
779 if (GetEventHandler()->ProcessEvent(event
)) return;
785 GtkWidget
* wxTextCtrl::GetConnectWidget()
787 return GTK_WIDGET(m_text
);
790 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
792 if (m_windowStyle
& wxTE_MULTILINE
)
793 return (window
== GTK_TEXT(m_text
)->text_area
);
795 return (window
== GTK_ENTRY(m_text
)->text_area
);
798 // the font will change for subsequent text insertiongs
799 bool wxTextCtrl::SetFont( const wxFont
&font
)
801 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
803 if ( !wxWindowBase::SetFont(font
) )
805 // font didn't change, nothing to do
809 if ( m_windowStyle
& wxTE_MULTILINE
)
811 // for compatibility with other ports: the font is a global controls
812 // characteristic, so change the font globally
813 wxString value
= GetValue();
814 if ( !value
.IsEmpty() )
825 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
827 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
833 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
835 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
837 wxControl::SetBackgroundColour( colour
);
839 if (!m_widget
->window
)
842 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
843 if (sysbg
.Red() == colour
.Red() &&
844 sysbg
.Green() == colour
.Green() &&
845 sysbg
.Blue() == colour
.Blue())
847 return FALSE
; // FIXME or TRUE?
850 if (!m_backgroundColour
.Ok())
853 if (m_windowStyle
& wxTE_MULTILINE
)
855 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
858 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
859 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
860 gdk_window_clear( window
);
866 void wxTextCtrl::ApplyWidgetStyle()
868 if (m_windowStyle
& wxTE_MULTILINE
)
875 gtk_widget_set_style( m_text
, m_widgetStyle
);
879 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
884 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
889 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
894 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
899 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
904 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
906 event
.Enable( CanCut() );
909 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
911 event
.Enable( CanCopy() );
914 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
916 event
.Enable( CanPaste() );
919 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
921 event
.Enable( CanUndo() );
924 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
926 event
.Enable( CanRedo() );
929 void wxTextCtrl::OnInternalIdle()
931 wxCursor cursor
= m_cursor
;
932 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
936 GdkWindow
*window
= (GdkWindow
*) NULL
;
937 if (HasFlag(wxTE_MULTILINE
))
938 window
= GTK_TEXT(m_text
)->text_area
;
940 window
= GTK_ENTRY(m_text
)->text_area
;
943 gdk_window_set_cursor( window
, cursor
.GetCursor() );
945 if (!g_globalCursor
.Ok())
946 cursor
= *wxSTANDARD_CURSOR
;
948 window
= m_widget
->window
;
949 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
950 gdk_window_set_cursor( window
, cursor
.GetCursor() );