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 SetSizeOrDefault( size
);
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() );
249 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
256 void wxTextCtrl::CalculateScrollbar()
258 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
260 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
262 if (adj
->upper
- adj
->page_size
< 0.8)
264 if (m_vScrollbarVisible
)
266 gtk_widget_hide( m_vScrollbar
);
267 m_vScrollbarVisible
= FALSE
;
272 if (!m_vScrollbarVisible
)
274 gtk_widget_show( m_vScrollbar
);
275 m_vScrollbarVisible
= TRUE
;
280 wxString
wxTextCtrl::GetValue() const
282 wxCHECK_MSG( m_text
!= NULL
, wxT(""), wxT("invalid text ctrl") );
285 if (m_windowStyle
& wxTE_MULTILINE
)
287 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
288 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
289 tmp
= wxString(text
,*wxConvCurrent
);
294 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConvCurrent
);
299 void wxTextCtrl::SetValue( const wxString
&value
)
301 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
303 wxString tmp
= wxT("");
304 if (!value
.IsNull()) tmp
= value
;
305 if (m_windowStyle
& wxTE_MULTILINE
)
307 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
308 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
311 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
312 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
314 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
319 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
323 void wxTextCtrl::WriteText( const wxString
&text
)
325 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
327 if (text
.IsEmpty()) return;
329 if (m_windowStyle
& wxTE_MULTILINE
)
331 /* this moves the cursor pos to behind the inserted text */
332 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
335 wxWX2MBbuf buf
= text
.mbc_str();
336 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
338 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
341 /* bring editable's cursor uptodate. bug in GTK. */
342 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
346 /* this moves the cursor pos to behind the inserted text */
347 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
349 wxWX2MBbuf buf
= text
.mbc_str();
350 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
352 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
+= text
.Len();
358 /* bring entry's cursor uptodate. bug in GTK. */
359 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
363 void wxTextCtrl::AppendText( const wxString
&text
)
365 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
367 if (text
.IsEmpty()) return;
369 if (m_windowStyle
& wxTE_MULTILINE
)
371 bool hasSpecialAttributes
= m_font
.Ok() ||
372 m_foregroundColour
.Ok() ||
373 m_backgroundColour
.Ok();
374 if ( hasSpecialAttributes
)
376 gtk_text_insert( GTK_TEXT(m_text
),
377 m_font
.GetInternalFont(),
378 m_foregroundColour
.GetColor(),
379 m_backgroundColour
.GetColor(),
380 text
.mbc_str(), text
.length());
385 /* we'll insert at the last position */
386 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
388 wxWX2MBbuf buf
= text
.mbc_str();
389 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
391 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
395 /* bring editable's cursor uptodate. bug in GTK. */
396 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
400 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
404 wxString
wxTextCtrl::GetLineText( long lineNo
) const
406 if (m_windowStyle
& wxTE_MULTILINE
)
408 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
409 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
413 wxString
buf(wxT(""));
416 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
421 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
428 return wxEmptyString
;
432 if (lineNo
== 0) return GetValue();
433 return wxEmptyString
;
437 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
439 /* If you implement this, don't forget to update the documentation!
440 * (file docs/latex/wx/text.tex) */
441 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
444 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
446 if ( m_windowStyle
& wxTE_MULTILINE
)
448 wxString text
= GetValue();
450 // cast to prevent warning. But pos really should've been unsigned.
451 if( (unsigned long)pos
> text
.Len() )
457 const wxChar
* stop
= text
.c_str() + pos
;
458 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
469 else // single line control
471 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
478 // index out of bounds
486 long wxTextCtrl::XYToPosition(long x
, long y
) const
488 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
491 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
497 int wxTextCtrl::GetLineLength(long lineNo
) const
499 wxString str
= GetLineText (lineNo
);
500 return (int) str
.Length();
503 int wxTextCtrl::GetNumberOfLines() const
505 if (m_windowStyle
& wxTE_MULTILINE
)
507 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
508 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
513 for (int i
= 0; i
< len
; i
++ )
520 // currentLine is 0 based, add 1 to get number of lines
521 return currentLine
+ 1;
534 void wxTextCtrl::SetInsertionPoint( long pos
)
536 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
538 if (m_windowStyle
& wxTE_MULTILINE
)
540 /* seems to be broken in GTK 1.0.X:
541 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
543 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
544 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
546 /* we fake a set_point by inserting and deleting. as the user
547 isn't supposed to get to know about thos non-sense, we
548 disconnect so that no events are sent to the user program. */
550 gint tmp
= (gint
)pos
;
551 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
552 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
554 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
555 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
557 /* bring editable's cursor uptodate. another bug in GTK. */
559 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
563 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
565 /* bring editable's cursor uptodate. bug in GTK. */
567 GTK_EDITABLE(m_text
)->current_pos
= (guint32
)pos
;
571 void wxTextCtrl::SetInsertionPointEnd()
573 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
575 if (m_windowStyle
& wxTE_MULTILINE
)
576 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
578 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
581 void wxTextCtrl::SetEditable( bool editable
)
583 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
585 if (m_windowStyle
& wxTE_MULTILINE
)
586 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
588 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
591 void wxTextCtrl::DiscardEdits()
596 void wxTextCtrl::SetSelection( long from
, long to
)
598 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
600 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
603 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
605 // SetInsertionPoint( pos );
608 long wxTextCtrl::GetInsertionPoint() const
610 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
612 return (long) GTK_EDITABLE(m_text
)->current_pos
;
615 long wxTextCtrl::GetLastPosition() const
617 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
620 if (m_windowStyle
& wxTE_MULTILINE
)
621 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
623 pos
= GTK_ENTRY(m_text
)->text_length
;
628 void wxTextCtrl::Remove( long from
, long to
)
630 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
632 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
635 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
637 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
639 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
641 if (!value
.IsEmpty())
643 gint pos
= (gint
)from
;
645 wxWX2MBbuf buf
= value
.mbc_str();
646 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
648 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
653 void wxTextCtrl::Cut()
655 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
657 #if (GTK_MINOR_VERSION > 0)
658 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
660 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
664 void wxTextCtrl::Copy()
666 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
668 #if (GTK_MINOR_VERSION > 0)
669 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
671 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
675 void wxTextCtrl::Paste()
677 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
679 #if (GTK_MINOR_VERSION > 0)
680 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
682 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
686 bool wxTextCtrl::CanCopy() const
688 // Can copy if there's a selection
690 GetSelection(& from
, & to
);
691 return (from
!= to
) ;
694 bool wxTextCtrl::CanCut() const
696 // Can cut if there's a selection
698 GetSelection(& from
, & to
);
699 return (from
!= to
) ;
702 bool wxTextCtrl::CanPaste() const
704 return IsEditable() ;
708 void wxTextCtrl::Undo()
711 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
714 void wxTextCtrl::Redo()
717 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
720 bool wxTextCtrl::CanUndo() const
723 wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
727 bool wxTextCtrl::CanRedo() const
730 wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
734 // If the return values from and to are the same, there is no
736 void wxTextCtrl::GetSelection(long* from
, long* to
) const
738 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
740 if (!(GTK_EDITABLE(m_text
)->has_selection
))
747 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
748 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
751 bool wxTextCtrl::IsEditable() const
753 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
755 return GTK_EDITABLE(m_text
)->editable
;
758 bool wxTextCtrl::IsModified() const
763 void wxTextCtrl::Clear()
768 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
770 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
772 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
774 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
775 event
.SetEventObject(this);
776 if (GetEventHandler()->ProcessEvent(event
)) return;
779 if ((key_event
.KeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
781 wxWindow
*top_frame
= m_parent
;
782 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
783 top_frame
= top_frame
->GetParent();
784 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
786 if (window
->default_widget
)
788 gtk_widget_activate (window
->default_widget
);
796 GtkWidget
* wxTextCtrl::GetConnectWidget()
798 return GTK_WIDGET(m_text
);
801 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
803 if (m_windowStyle
& wxTE_MULTILINE
)
804 return (window
== GTK_TEXT(m_text
)->text_area
);
806 return (window
== GTK_ENTRY(m_text
)->text_area
);
809 // the font will change for subsequent text insertiongs
810 bool wxTextCtrl::SetFont( const wxFont
&font
)
812 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
814 if ( !wxWindowBase::SetFont(font
) )
816 // font didn't change, nothing to do
820 if ( m_windowStyle
& wxTE_MULTILINE
)
822 // for compatibility with other ports: the font is a global controls
823 // characteristic, so change the font globally
824 wxString value
= GetValue();
825 if ( !value
.IsEmpty() )
836 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
838 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
844 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
846 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
848 wxControl::SetBackgroundColour( colour
);
850 if (!m_widget
->window
)
853 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
854 if (sysbg
.Red() == colour
.Red() &&
855 sysbg
.Green() == colour
.Green() &&
856 sysbg
.Blue() == colour
.Blue())
858 return FALSE
; // FIXME or TRUE?
861 if (!m_backgroundColour
.Ok())
864 if (m_windowStyle
& wxTE_MULTILINE
)
866 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
869 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
870 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
871 gdk_window_clear( window
);
877 void wxTextCtrl::ApplyWidgetStyle()
879 if (m_windowStyle
& wxTE_MULTILINE
)
886 gtk_widget_set_style( m_text
, m_widgetStyle
);
890 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
895 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
900 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
905 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
910 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
915 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
917 event
.Enable( CanCut() );
920 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
922 event
.Enable( CanCopy() );
925 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
927 event
.Enable( CanPaste() );
930 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
932 event
.Enable( CanUndo() );
935 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
937 event
.Enable( CanRedo() );
940 void wxTextCtrl::OnInternalIdle()
942 wxCursor cursor
= m_cursor
;
943 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
947 GdkWindow
*window
= (GdkWindow
*) NULL
;
948 if (HasFlag(wxTE_MULTILINE
))
949 window
= GTK_TEXT(m_text
)->text_area
;
951 window
= GTK_ENTRY(m_text
)->text_area
;
954 gdk_window_set_cursor( window
, cursor
.GetCursor() );
956 if (!g_globalCursor
.Ok())
957 cursor
= *wxSTANDARD_CURSOR
;
959 window
= m_widget
->window
;
960 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
961 gdk_window_set_cursor( window
, cursor
.GetCursor() );
967 wxSize
wxTextCtrl::DoGetBestSize() const
969 // FIXME should be different for multi-line controls...
970 return wxSize(80, 26);