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 wxSize new_size
= size
,
196 sizeBest
= DoGetBestSize();
197 if (new_size
.x
== -1)
198 new_size
.x
= sizeBest
.x
;
199 if (new_size
.y
== -1)
200 new_size
.y
= sizeBest
.y
;
202 if ((new_size
.x
!= size
.x
) || (new_size
.y
!= size
.y
))
203 SetSize( new_size
.x
, new_size
.y
);
205 m_parent
->DoAddChild( this );
210 gtk_widget_show(m_text
);
212 /* we want to be notified about text changes */
213 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
214 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
218 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
219 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
222 if (!value
.IsEmpty())
226 #if GTK_MINOR_VERSION == 0
227 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
228 // gtk_editable_insert_text()
229 gtk_widget_realize(m_text
);
233 wxWX2MBbuf val
= value
.mbc_str();
234 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
236 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
237 #endif // Unicode/!Unicode
241 /* bring editable's cursor uptodate. bug in GTK. */
243 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
247 if (style
& wxTE_PASSWORD
)
250 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
253 if (style
& wxTE_READONLY
)
256 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
261 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
264 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) );
265 SetForegroundColour( parent
->GetForegroundColour() );
267 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
274 void wxTextCtrl::CalculateScrollbar()
276 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
278 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
280 if (adj
->upper
- adj
->page_size
< 0.8)
282 if (m_vScrollbarVisible
)
284 gtk_widget_hide( m_vScrollbar
);
285 m_vScrollbarVisible
= FALSE
;
290 if (!m_vScrollbarVisible
)
292 gtk_widget_show( m_vScrollbar
);
293 m_vScrollbarVisible
= TRUE
;
298 wxString
wxTextCtrl::GetValue() const
300 wxCHECK_MSG( m_text
!= NULL
, wxT(""), wxT("invalid text ctrl") );
303 if (m_windowStyle
& wxTE_MULTILINE
)
305 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
306 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
307 tmp
= wxString(text
,*wxConvCurrent
);
312 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConvCurrent
);
317 void wxTextCtrl::SetValue( const wxString
&value
)
319 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
321 wxString tmp
= wxT("");
322 if (!value
.IsNull()) tmp
= value
;
323 if (m_windowStyle
& wxTE_MULTILINE
)
325 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
326 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
329 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
330 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
332 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
337 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
341 void wxTextCtrl::WriteText( const wxString
&text
)
343 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
345 if (text
.IsEmpty()) return;
347 if (m_windowStyle
& wxTE_MULTILINE
)
349 /* this moves the cursor pos to behind the inserted text */
350 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
353 wxWX2MBbuf buf
= text
.mbc_str();
354 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
356 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
359 /* bring editable's cursor uptodate. bug in GTK. */
360 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
364 /* this moves the cursor pos to behind the inserted text */
365 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
367 wxWX2MBbuf buf
= text
.mbc_str();
368 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
370 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
373 /* bring editable's cursor uptodate. bug in GTK. */
374 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
376 /* bring entry's cursor uptodate. bug in GTK. */
377 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
381 void wxTextCtrl::AppendText( const wxString
&text
)
383 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
385 if (text
.IsEmpty()) return;
387 if (m_windowStyle
& wxTE_MULTILINE
)
389 bool hasSpecialAttributes
= m_font
.Ok() ||
390 m_foregroundColour
.Ok() ||
391 m_backgroundColour
.Ok();
392 if ( hasSpecialAttributes
)
394 gtk_text_insert( GTK_TEXT(m_text
),
395 m_font
.GetInternalFont(),
396 m_foregroundColour
.GetColor(),
397 m_backgroundColour
.GetColor(),
398 text
.mbc_str(), text
.length());
403 /* we'll insert at the last position */
404 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
406 wxWX2MBbuf buf
= text
.mbc_str();
407 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
409 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
413 /* bring editable's cursor uptodate. bug in GTK. */
414 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
418 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
422 wxString
wxTextCtrl::GetLineText( long lineNo
) const
424 if (m_windowStyle
& wxTE_MULTILINE
)
426 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
427 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
431 wxString
buf(wxT(""));
434 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
439 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
446 return wxEmptyString
;
450 if (lineNo
== 0) return GetValue();
451 return wxEmptyString
;
455 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
457 /* If you implement this, don't forget to update the documentation!
458 * (file docs/latex/wx/text.tex) */
459 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
462 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
464 if ( m_windowStyle
& wxTE_MULTILINE
)
466 wxString text
= GetValue();
468 // cast to prevent warning. But pos really should've been unsigned.
469 if( (unsigned long)pos
> text
.Len() )
475 const wxChar
* stop
= text
.c_str() + pos
;
476 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
487 else // single line control
489 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
496 // index out of bounds
504 long wxTextCtrl::XYToPosition(long x
, long y
) const
506 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
509 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
515 int wxTextCtrl::GetLineLength(long lineNo
) const
517 wxString str
= GetLineText (lineNo
);
518 return (int) str
.Length();
521 int wxTextCtrl::GetNumberOfLines() const
523 if (m_windowStyle
& wxTE_MULTILINE
)
525 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
526 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
531 for (int i
= 0; i
< len
; i
++ )
538 // currentLine is 0 based, add 1 to get number of lines
539 return currentLine
+ 1;
552 void wxTextCtrl::SetInsertionPoint( long pos
)
554 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
556 if (m_windowStyle
& wxTE_MULTILINE
)
558 /* seems to be broken in GTK 1.0.X:
559 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
561 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
562 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
564 /* we fake a set_point by inserting and deleting. as the user
565 isn't supposed to get to know about thos non-sense, we
566 disconnect so that no events are sent to the user program. */
568 gint tmp
= (gint
)pos
;
569 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
570 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
572 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
573 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
575 /* bring editable's cursor uptodate. another bug in GTK. */
577 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
581 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
583 /* bring editable's cursor uptodate. bug in GTK. */
585 GTK_EDITABLE(m_text
)->current_pos
= (guint32
)pos
;
589 void wxTextCtrl::SetInsertionPointEnd()
591 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
593 if (m_windowStyle
& wxTE_MULTILINE
)
594 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
596 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
599 void wxTextCtrl::SetEditable( bool editable
)
601 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
603 if (m_windowStyle
& wxTE_MULTILINE
)
604 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
606 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
609 void wxTextCtrl::DiscardEdits()
614 void wxTextCtrl::SetSelection( long from
, long to
)
616 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
618 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
621 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
623 // SetInsertionPoint( pos );
626 long wxTextCtrl::GetInsertionPoint() const
628 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
630 return (long) GTK_EDITABLE(m_text
)->current_pos
;
633 long wxTextCtrl::GetLastPosition() const
635 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
638 if (m_windowStyle
& wxTE_MULTILINE
)
639 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
641 pos
= GTK_ENTRY(m_text
)->text_length
;
646 void wxTextCtrl::Remove( long from
, long to
)
648 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
650 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
653 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
655 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
657 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
659 if (!value
.IsEmpty())
661 gint pos
= (gint
)from
;
663 wxWX2MBbuf buf
= value
.mbc_str();
664 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
666 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
671 void wxTextCtrl::Cut()
673 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
675 #if (GTK_MINOR_VERSION > 0)
676 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
678 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
682 void wxTextCtrl::Copy()
684 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
686 #if (GTK_MINOR_VERSION > 0)
687 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
689 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
693 void wxTextCtrl::Paste()
695 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
697 #if (GTK_MINOR_VERSION > 0)
698 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
700 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
704 bool wxTextCtrl::CanCopy() const
706 // Can copy if there's a selection
708 GetSelection(& from
, & to
);
709 return (from
!= to
) ;
712 bool wxTextCtrl::CanCut() const
714 // Can cut if there's a selection
716 GetSelection(& from
, & to
);
717 return (from
!= to
) ;
720 bool wxTextCtrl::CanPaste() const
722 return IsEditable() ;
726 void wxTextCtrl::Undo()
729 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
732 void wxTextCtrl::Redo()
735 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
738 bool wxTextCtrl::CanUndo() const
741 wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
745 bool wxTextCtrl::CanRedo() const
748 wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
752 // If the return values from and to are the same, there is no
754 void wxTextCtrl::GetSelection(long* from
, long* to
) const
756 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
758 if (!(GTK_EDITABLE(m_text
)->has_selection
))
765 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
766 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
769 bool wxTextCtrl::IsEditable() const
771 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
773 return GTK_EDITABLE(m_text
)->editable
;
776 bool wxTextCtrl::IsModified() const
781 void wxTextCtrl::Clear()
786 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
788 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
790 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
792 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
793 event
.SetEventObject(this);
794 if (GetEventHandler()->ProcessEvent(event
)) return;
797 if ((key_event
.KeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
799 wxWindow
*top_frame
= m_parent
;
800 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
801 top_frame
= top_frame
->GetParent();
802 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
804 if (window
->default_widget
)
806 gtk_widget_activate (window
->default_widget
);
814 GtkWidget
* wxTextCtrl::GetConnectWidget()
816 return GTK_WIDGET(m_text
);
819 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
821 if (m_windowStyle
& wxTE_MULTILINE
)
822 return (window
== GTK_TEXT(m_text
)->text_area
);
824 return (window
== GTK_ENTRY(m_text
)->text_area
);
827 // the font will change for subsequent text insertiongs
828 bool wxTextCtrl::SetFont( const wxFont
&font
)
830 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
832 if ( !wxWindowBase::SetFont(font
) )
834 // font didn't change, nothing to do
838 if ( m_windowStyle
& wxTE_MULTILINE
)
840 // for compatibility with other ports: the font is a global controls
841 // characteristic, so change the font globally
842 wxString value
= GetValue();
843 if ( !value
.IsEmpty() )
854 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
856 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
862 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
864 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
866 wxControl::SetBackgroundColour( colour
);
868 if (!m_widget
->window
)
871 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
872 if (sysbg
.Red() == colour
.Red() &&
873 sysbg
.Green() == colour
.Green() &&
874 sysbg
.Blue() == colour
.Blue())
876 return FALSE
; // FIXME or TRUE?
879 if (!m_backgroundColour
.Ok())
882 if (m_windowStyle
& wxTE_MULTILINE
)
884 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
887 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
888 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
889 gdk_window_clear( window
);
895 void wxTextCtrl::ApplyWidgetStyle()
897 if (m_windowStyle
& wxTE_MULTILINE
)
904 gtk_widget_set_style( m_text
, m_widgetStyle
);
908 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
913 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
918 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
923 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
928 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
933 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
935 event
.Enable( CanCut() );
938 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
940 event
.Enable( CanCopy() );
943 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
945 event
.Enable( CanPaste() );
948 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
950 event
.Enable( CanUndo() );
953 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
955 event
.Enable( CanRedo() );
958 void wxTextCtrl::OnInternalIdle()
960 wxCursor cursor
= m_cursor
;
961 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
965 GdkWindow
*window
= (GdkWindow
*) NULL
;
966 if (HasFlag(wxTE_MULTILINE
))
967 window
= GTK_TEXT(m_text
)->text_area
;
969 window
= GTK_ENTRY(m_text
)->text_area
;
972 gdk_window_set_cursor( window
, cursor
.GetCursor() );
974 if (!g_globalCursor
.Ok())
975 cursor
= *wxSTANDARD_CURSOR
;
977 window
= m_widget
->window
;
978 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
979 gdk_window_set_cursor( window
, cursor
.GetCursor() );
985 wxSize
wxTextCtrl::DoGetBestSize() const
987 // FIXME should be different for multi-line controls...
988 wxSize
ret( wxControl::DoGetBestSize() );
989 return wxSize(80, ret
.y
);