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
,
105 const wxString
&value
,
109 const wxValidator
& validator
,
110 const wxString
&name
)
113 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
116 bool wxTextCtrl::Create( wxWindow
*parent
,
118 const wxString
&value
,
122 const wxValidator
& validator
,
123 const wxString
&name
)
126 m_acceptsFocus
= TRUE
;
128 if (!PreCreation( parent
, pos
, size
) ||
129 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
131 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
136 m_vScrollbarVisible
= FALSE
;
138 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
141 #if (GTK_MINOR_VERSION > 2)
142 /* a multi-line edit control: create a vertical scrollbar by default and
143 horizontal if requested */
144 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
146 bool bHasHScrollbar
= FALSE
;
149 /* create our control ... */
150 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
152 /* ... and put into the upper left hand corner of the table */
153 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
154 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
155 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
156 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
157 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
160 /* always wrap words */
161 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
163 #if (GTK_MINOR_VERSION > 2)
164 /* put the horizontal scrollbar in the lower left hand corner */
167 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
168 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
169 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
170 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
173 gtk_widget_show(hscrollbar
);
175 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
176 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
180 /* finally, put the vertical scrollbar in the upper right corner */
181 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
182 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
183 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
185 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
190 /* a single-line text control: no need for scrollbars */
192 m_text
= gtk_entry_new();
195 SetSizeOrDefault( size
);
197 m_parent
->DoAddChild( this );
202 gtk_widget_show(m_text
);
204 /* we want to be notified about text changes */
205 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
206 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
210 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
211 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
214 if (!value
.IsEmpty())
218 #if GTK_MINOR_VERSION == 0
219 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
220 // gtk_editable_insert_text()
221 gtk_widget_realize(m_text
);
225 wxWX2MBbuf val
= value
.mbc_str();
226 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
228 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
229 #endif // Unicode/!Unicode
233 /* bring editable's cursor uptodate. bug in GTK. */
235 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
239 if (style
& wxTE_PASSWORD
)
242 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
245 if (style
& wxTE_READONLY
)
248 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
253 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
256 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) );
257 SetForegroundColour( parent
->GetForegroundColour() );
259 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
266 void wxTextCtrl::CalculateScrollbar()
268 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
270 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
272 if (adj
->upper
- adj
->page_size
< 0.8)
274 if (m_vScrollbarVisible
)
276 gtk_widget_hide( m_vScrollbar
);
277 m_vScrollbarVisible
= FALSE
;
282 if (!m_vScrollbarVisible
)
284 gtk_widget_show( m_vScrollbar
);
285 m_vScrollbarVisible
= TRUE
;
290 wxString
wxTextCtrl::GetValue() const
292 wxCHECK_MSG( m_text
!= NULL
, wxT(""), wxT("invalid text ctrl") );
295 if (m_windowStyle
& wxTE_MULTILINE
)
297 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
298 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
299 tmp
= wxString(text
,*wxConvCurrent
);
304 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConvCurrent
);
309 void wxTextCtrl::SetValue( const wxString
&value
)
311 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
313 wxString tmp
= wxT("");
314 if (!value
.IsNull()) tmp
= value
;
315 if (m_windowStyle
& wxTE_MULTILINE
)
317 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
318 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
321 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
322 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
324 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
329 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
333 void wxTextCtrl::WriteText( const wxString
&text
)
335 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
337 if (text
.IsEmpty()) return;
339 if (m_windowStyle
& wxTE_MULTILINE
)
341 /* this moves the cursor pos to behind the inserted text */
342 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
345 wxWX2MBbuf buf
= text
.mbc_str();
346 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
348 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
351 /* bring editable's cursor uptodate. bug in GTK. */
352 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
356 /* this moves the cursor pos to behind the inserted text */
357 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
359 wxWX2MBbuf buf
= text
.mbc_str();
360 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
362 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
365 /* bring editable's cursor uptodate. bug in GTK. */
366 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
368 /* bring entry's cursor uptodate. bug in GTK. */
369 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
373 void wxTextCtrl::AppendText( const wxString
&text
)
375 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
377 if (text
.IsEmpty()) return;
379 if (m_windowStyle
& wxTE_MULTILINE
)
381 bool hasSpecialAttributes
= m_font
.Ok() ||
382 m_foregroundColour
.Ok() ||
383 m_backgroundColour
.Ok();
384 if ( hasSpecialAttributes
)
386 gtk_text_insert( GTK_TEXT(m_text
),
387 m_font
.GetInternalFont(),
388 m_foregroundColour
.GetColor(),
389 m_backgroundColour
.GetColor(),
390 text
.mbc_str(), text
.length());
395 /* we'll insert at the last position */
396 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
398 wxWX2MBbuf buf
= text
.mbc_str();
399 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
401 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
405 /* bring editable's cursor uptodate. bug in GTK. */
406 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
410 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
414 wxString
wxTextCtrl::GetLineText( long lineNo
) const
416 if (m_windowStyle
& wxTE_MULTILINE
)
418 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
419 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
423 wxString
buf(wxT(""));
426 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
431 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
438 return wxEmptyString
;
442 if (lineNo
== 0) return GetValue();
443 return wxEmptyString
;
447 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
449 /* If you implement this, don't forget to update the documentation!
450 * (file docs/latex/wx/text.tex) */
451 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
454 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
456 if ( m_windowStyle
& wxTE_MULTILINE
)
458 wxString text
= GetValue();
460 // cast to prevent warning. But pos really should've been unsigned.
461 if( (unsigned long)pos
> text
.Len() )
467 const wxChar
* stop
= text
.c_str() + pos
;
468 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
479 else // single line control
481 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
488 // index out of bounds
496 long wxTextCtrl::XYToPosition(long x
, long y
) const
498 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
501 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
507 int wxTextCtrl::GetLineLength(long lineNo
) const
509 wxString str
= GetLineText (lineNo
);
510 return (int) str
.Length();
513 int wxTextCtrl::GetNumberOfLines() const
515 if (m_windowStyle
& wxTE_MULTILINE
)
517 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
518 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
523 for (int i
= 0; i
< len
; i
++ )
530 // currentLine is 0 based, add 1 to get number of lines
531 return currentLine
+ 1;
544 void wxTextCtrl::SetInsertionPoint( long pos
)
546 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
548 if (m_windowStyle
& wxTE_MULTILINE
)
550 /* seems to be broken in GTK 1.0.X:
551 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
553 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
554 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
556 /* we fake a set_point by inserting and deleting. as the user
557 isn't supposed to get to know about thos non-sense, we
558 disconnect so that no events are sent to the user program. */
560 gint tmp
= (gint
)pos
;
561 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
562 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
564 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
565 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
567 /* bring editable's cursor uptodate. another bug in GTK. */
569 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
573 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
575 /* bring editable's cursor uptodate. bug in GTK. */
577 GTK_EDITABLE(m_text
)->current_pos
= (guint32
)pos
;
581 void wxTextCtrl::SetInsertionPointEnd()
583 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
585 if (m_windowStyle
& wxTE_MULTILINE
)
586 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
588 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
591 void wxTextCtrl::SetEditable( bool editable
)
593 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
595 if (m_windowStyle
& wxTE_MULTILINE
)
596 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
598 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
601 void wxTextCtrl::DiscardEdits()
606 void wxTextCtrl::SetSelection( long from
, long to
)
608 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
610 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
613 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
615 // SetInsertionPoint( pos );
618 long wxTextCtrl::GetInsertionPoint() const
620 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
622 return (long) GTK_EDITABLE(m_text
)->current_pos
;
625 long wxTextCtrl::GetLastPosition() const
627 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
630 if (m_windowStyle
& wxTE_MULTILINE
)
631 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
633 pos
= GTK_ENTRY(m_text
)->text_length
;
638 void wxTextCtrl::Remove( long from
, long to
)
640 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
642 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
645 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
647 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
649 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
651 if (!value
.IsEmpty())
653 gint pos
= (gint
)from
;
655 wxWX2MBbuf buf
= value
.mbc_str();
656 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
658 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
663 void wxTextCtrl::Cut()
665 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
667 #if (GTK_MINOR_VERSION > 0)
668 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
670 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
674 void wxTextCtrl::Copy()
676 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
678 #if (GTK_MINOR_VERSION > 0)
679 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
681 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
685 void wxTextCtrl::Paste()
687 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
689 #if (GTK_MINOR_VERSION > 0)
690 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
692 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
696 bool wxTextCtrl::CanCopy() const
698 // Can copy if there's a selection
700 GetSelection(& from
, & to
);
701 return (from
!= to
) ;
704 bool wxTextCtrl::CanCut() const
706 // Can cut if there's a selection
708 GetSelection(& from
, & to
);
709 return (from
!= to
) ;
712 bool wxTextCtrl::CanPaste() const
714 return IsEditable() ;
718 void wxTextCtrl::Undo()
721 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
724 void wxTextCtrl::Redo()
727 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
730 bool wxTextCtrl::CanUndo() const
733 wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
737 bool wxTextCtrl::CanRedo() const
740 wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
744 // If the return values from and to are the same, there is no
746 void wxTextCtrl::GetSelection(long* from
, long* to
) const
748 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
750 if (!(GTK_EDITABLE(m_text
)->has_selection
))
757 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
758 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
761 bool wxTextCtrl::IsEditable() const
763 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
765 return GTK_EDITABLE(m_text
)->editable
;
768 bool wxTextCtrl::IsModified() const
773 void wxTextCtrl::Clear()
778 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
780 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
782 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
784 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
785 event
.SetEventObject(this);
786 if (GetEventHandler()->ProcessEvent(event
)) return;
789 if ((key_event
.KeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
791 wxWindow
*top_frame
= m_parent
;
792 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
793 top_frame
= top_frame
->GetParent();
794 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
796 if (window
->default_widget
)
798 gtk_widget_activate (window
->default_widget
);
806 GtkWidget
* wxTextCtrl::GetConnectWidget()
808 return GTK_WIDGET(m_text
);
811 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
813 if (m_windowStyle
& wxTE_MULTILINE
)
814 return (window
== GTK_TEXT(m_text
)->text_area
);
816 return (window
== GTK_ENTRY(m_text
)->text_area
);
819 // the font will change for subsequent text insertiongs
820 bool wxTextCtrl::SetFont( const wxFont
&font
)
822 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
824 if ( !wxWindowBase::SetFont(font
) )
826 // font didn't change, nothing to do
830 if ( m_windowStyle
& wxTE_MULTILINE
)
832 // for compatibility with other ports: the font is a global controls
833 // characteristic, so change the font globally
834 wxString value
= GetValue();
835 if ( !value
.IsEmpty() )
846 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
848 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
854 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
856 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
858 wxControl::SetBackgroundColour( colour
);
860 if (!m_widget
->window
)
863 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
864 if (sysbg
.Red() == colour
.Red() &&
865 sysbg
.Green() == colour
.Green() &&
866 sysbg
.Blue() == colour
.Blue())
868 return FALSE
; // FIXME or TRUE?
871 if (!m_backgroundColour
.Ok())
874 if (m_windowStyle
& wxTE_MULTILINE
)
876 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
879 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
880 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
881 gdk_window_clear( window
);
887 void wxTextCtrl::ApplyWidgetStyle()
889 if (m_windowStyle
& wxTE_MULTILINE
)
896 gtk_widget_set_style( m_text
, m_widgetStyle
);
900 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
905 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
910 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
915 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
920 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
925 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
927 event
.Enable( CanCut() );
930 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
932 event
.Enable( CanCopy() );
935 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
937 event
.Enable( CanPaste() );
940 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
942 event
.Enable( CanUndo() );
945 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
947 event
.Enable( CanRedo() );
950 void wxTextCtrl::OnInternalIdle()
952 wxCursor cursor
= m_cursor
;
953 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
957 GdkWindow
*window
= (GdkWindow
*) NULL
;
958 if (HasFlag(wxTE_MULTILINE
))
959 window
= GTK_TEXT(m_text
)->text_area
;
961 window
= GTK_ENTRY(m_text
)->text_area
;
964 gdk_window_set_cursor( window
, cursor
.GetCursor() );
966 if (!g_globalCursor
.Ok())
967 cursor
= *wxSTANDARD_CURSOR
;
969 window
= m_widget
->window
;
970 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
971 gdk_window_set_cursor( window
, cursor
.GetCursor() );
977 wxSize
wxTextCtrl::DoGetBestSize() const
979 // FIXME should be different for multi-line controls...
980 return wxSize(80, 26);