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()
102 m_vScrollbar
= (GtkWidget
*)NULL
;
105 wxTextCtrl::wxTextCtrl( wxWindow
*parent
,
107 const wxString
&value
,
111 const wxValidator
& validator
,
112 const wxString
&name
)
115 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
118 bool wxTextCtrl::Create( wxWindow
*parent
,
120 const wxString
&value
,
124 const wxValidator
& validator
,
125 const wxString
&name
)
128 m_acceptsFocus
= TRUE
;
130 if (!PreCreation( parent
, pos
, size
) ||
131 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
133 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
138 m_vScrollbarVisible
= FALSE
;
140 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
143 #if (GTK_MINOR_VERSION > 2)
144 /* a multi-line edit control: create a vertical scrollbar by default and
145 horizontal if requested */
146 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
148 bool bHasHScrollbar
= FALSE
;
151 /* create our control ... */
152 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
154 /* ... and put into the upper left hand corner of the table */
155 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
156 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
157 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
158 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
159 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
162 /* always wrap words */
163 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
165 #if (GTK_MINOR_VERSION > 2)
166 /* put the horizontal scrollbar in the lower left hand corner */
169 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
170 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
171 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
172 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
175 gtk_widget_show(hscrollbar
);
177 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
178 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
182 /* finally, put the vertical scrollbar in the upper right corner */
183 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
184 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
185 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
187 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
192 /* a single-line text control: no need for scrollbars */
194 m_text
= gtk_entry_new();
197 m_parent
->DoAddChild( this );
201 SetFont( parent
->GetFont() );
203 wxSize
size_best( DoGetBestSize() );
204 wxSize
new_size( size
);
205 if (new_size
.x
== -1)
206 new_size
.x
= size_best
.x
;
207 if (new_size
.y
== -1)
208 new_size
.y
= size_best
.y
;
209 if ((new_size
.x
!= size
.x
) || (new_size
.y
!= size
.y
))
210 SetSize( new_size
.x
, new_size
.y
);
213 gtk_widget_show(m_text
);
215 /* we want to be notified about text changes */
216 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
217 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
221 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
222 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
225 if (!value
.IsEmpty())
229 #if GTK_MINOR_VERSION == 0
230 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
231 // gtk_editable_insert_text()
232 gtk_widget_realize(m_text
);
236 wxWX2MBbuf val
= value
.mbc_str();
237 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
239 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
240 #endif // Unicode/!Unicode
244 /* bring editable's cursor uptodate. bug in GTK. */
246 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
250 if (style
& wxTE_PASSWORD
)
253 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
256 if (style
& wxTE_READONLY
)
259 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
264 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
267 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) );
268 SetForegroundColour( parent
->GetForegroundColour() );
270 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
277 void wxTextCtrl::CalculateScrollbar()
279 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
281 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
283 if (adj
->upper
- adj
->page_size
< 0.8)
285 if (m_vScrollbarVisible
)
287 gtk_widget_hide( m_vScrollbar
);
288 m_vScrollbarVisible
= FALSE
;
293 if (!m_vScrollbarVisible
)
295 gtk_widget_show( m_vScrollbar
);
296 m_vScrollbarVisible
= TRUE
;
301 wxString
wxTextCtrl::GetValue() const
303 wxCHECK_MSG( m_text
!= NULL
, wxT(""), wxT("invalid text ctrl") );
306 if (m_windowStyle
& wxTE_MULTILINE
)
308 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
309 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
310 tmp
= wxString(text
,*wxConvCurrent
);
315 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConvCurrent
);
320 void wxTextCtrl::SetValue( const wxString
&value
)
322 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
324 wxString tmp
= wxT("");
325 if (!value
.IsNull()) tmp
= value
;
326 if (m_windowStyle
& wxTE_MULTILINE
)
328 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
329 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
332 wxWX2MBbuf tmpbuf
= tmp
.mbc_str();
333 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
335 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmp
.mbc_str(), tmp
.Length(), &len
);
340 gtk_entry_set_text( GTK_ENTRY(m_text
), tmp
.mbc_str() );
343 // GRG, Jun/2000: Changed this after a lot of discussion in
344 // the lists. wxWindows 2.2 will have a set of flags to
345 // customize this behaviour.
346 SetInsertionPoint(0);
351 void wxTextCtrl::WriteText( const wxString
&text
)
353 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
355 if (text
.IsEmpty()) return;
357 if (m_windowStyle
& wxTE_MULTILINE
)
359 /* this moves the cursor pos to behind the inserted text */
360 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
363 wxWX2MBbuf buf
= text
.mbc_str();
364 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
366 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
369 /* bring editable's cursor uptodate. bug in GTK. */
370 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
374 /* this moves the cursor pos to behind the inserted text */
375 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
377 wxWX2MBbuf buf
= text
.mbc_str();
378 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
380 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
383 /* bring editable's cursor uptodate. bug in GTK. */
384 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
386 /* bring entry's cursor uptodate. bug in GTK. */
387 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
391 void wxTextCtrl::AppendText( const wxString
&text
)
393 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
395 if (text
.IsEmpty()) return;
397 if (m_windowStyle
& wxTE_MULTILINE
)
399 bool hasSpecialAttributes
= m_font
.Ok() ||
400 m_foregroundColour
.Ok() ||
401 m_backgroundColour
.Ok();
402 if ( hasSpecialAttributes
)
404 gtk_text_insert( GTK_TEXT(m_text
),
405 m_font
.GetInternalFont(),
406 m_foregroundColour
.GetColor(),
407 m_backgroundColour
.GetColor(),
408 text
.mbc_str(), text
.length());
413 /* we'll insert at the last position */
414 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
416 wxWX2MBbuf buf
= text
.mbc_str();
417 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
419 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
423 /* bring editable's cursor uptodate. bug in GTK. */
424 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
428 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
432 wxString
wxTextCtrl::GetLineText( long lineNo
) const
434 if (m_windowStyle
& wxTE_MULTILINE
)
436 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
437 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
441 wxString
buf(wxT(""));
444 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
449 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
456 return wxEmptyString
;
460 if (lineNo
== 0) return GetValue();
461 return wxEmptyString
;
465 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
467 /* If you implement this, don't forget to update the documentation!
468 * (file docs/latex/wx/text.tex) */
469 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
472 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
474 if ( m_windowStyle
& wxTE_MULTILINE
)
476 wxString text
= GetValue();
478 // cast to prevent warning. But pos really should've been unsigned.
479 if( (unsigned long)pos
> text
.Len() )
485 const wxChar
* stop
= text
.c_str() + pos
;
486 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
497 else // single line control
499 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
506 // index out of bounds
514 long wxTextCtrl::XYToPosition(long x
, long y
) const
516 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
519 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
525 int wxTextCtrl::GetLineLength(long lineNo
) const
527 wxString str
= GetLineText (lineNo
);
528 return (int) str
.Length();
531 int wxTextCtrl::GetNumberOfLines() const
533 if (m_windowStyle
& wxTE_MULTILINE
)
535 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
536 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
541 for (int i
= 0; i
< len
; i
++ )
548 // currentLine is 0 based, add 1 to get number of lines
549 return currentLine
+ 1;
562 void wxTextCtrl::SetInsertionPoint( long pos
)
564 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
566 if (m_windowStyle
& wxTE_MULTILINE
)
568 /* seems to be broken in GTK 1.0.X:
569 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
571 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
572 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
574 /* we fake a set_point by inserting and deleting. as the user
575 isn't supposed to get to know about thos non-sense, we
576 disconnect so that no events are sent to the user program. */
578 gint tmp
= (gint
)pos
;
579 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
580 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
582 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
583 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
585 /* bring editable's cursor uptodate. another bug in GTK. */
587 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
591 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
593 /* bring editable's cursor uptodate. bug in GTK. */
595 GTK_EDITABLE(m_text
)->current_pos
= (guint32
)pos
;
599 void wxTextCtrl::SetInsertionPointEnd()
601 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
603 if (m_windowStyle
& wxTE_MULTILINE
)
604 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
606 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
609 void wxTextCtrl::SetEditable( bool editable
)
611 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
613 if (m_windowStyle
& wxTE_MULTILINE
)
614 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
616 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
619 bool wxTextCtrl::Enable( bool enable
)
621 if (!wxWindowBase::Enable(enable
))
627 if (m_windowStyle
& wxTE_MULTILINE
)
629 gtk_text_set_editable( GTK_TEXT(m_text
), enable
);
633 gtk_widget_set_sensitive( m_text
, enable
);
639 void wxTextCtrl::DiscardEdits()
644 void wxTextCtrl::SetSelection( long from
, long to
)
646 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
648 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
651 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
653 // SetInsertionPoint( pos );
656 long wxTextCtrl::GetInsertionPoint() const
658 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
660 return (long) GTK_EDITABLE(m_text
)->current_pos
;
663 long wxTextCtrl::GetLastPosition() const
665 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
668 if (m_windowStyle
& wxTE_MULTILINE
)
669 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
671 pos
= GTK_ENTRY(m_text
)->text_length
;
676 void wxTextCtrl::Remove( long from
, long to
)
678 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
680 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
683 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
685 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
687 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
689 if (!value
.IsEmpty())
691 gint pos
= (gint
)from
;
693 wxWX2MBbuf buf
= value
.mbc_str();
694 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
696 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
701 void wxTextCtrl::Cut()
703 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
705 #if (GTK_MINOR_VERSION > 0)
706 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
708 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
712 void wxTextCtrl::Copy()
714 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
716 #if (GTK_MINOR_VERSION > 0)
717 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
719 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
723 void wxTextCtrl::Paste()
725 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
727 #if (GTK_MINOR_VERSION > 0)
728 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
730 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
734 bool wxTextCtrl::CanCopy() const
736 // Can copy if there's a selection
738 GetSelection(& from
, & to
);
739 return (from
!= to
) ;
742 bool wxTextCtrl::CanCut() const
744 // Can cut if there's a selection
746 GetSelection(& from
, & to
);
747 return (from
!= to
) && (IsEditable());
750 bool wxTextCtrl::CanPaste() const
752 return IsEditable() ;
756 void wxTextCtrl::Undo()
759 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
762 void wxTextCtrl::Redo()
765 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
768 bool wxTextCtrl::CanUndo() const
771 wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
775 bool wxTextCtrl::CanRedo() const
778 wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
782 // If the return values from and to are the same, there is no
784 void wxTextCtrl::GetSelection(long* from
, long* to
) const
786 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
788 if (!(GTK_EDITABLE(m_text
)->has_selection
))
790 long i
= GetInsertionPoint();
796 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
797 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
800 bool wxTextCtrl::IsEditable() const
802 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
804 return GTK_EDITABLE(m_text
)->editable
;
807 bool wxTextCtrl::IsModified() const
812 void wxTextCtrl::Clear()
817 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
819 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
821 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
823 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
824 event
.SetEventObject(this);
825 event
.SetString(GetValue());
826 if (GetEventHandler()->ProcessEvent(event
)) return;
829 if ((key_event
.KeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
831 wxWindow
*top_frame
= m_parent
;
832 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
833 top_frame
= top_frame
->GetParent();
834 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
836 if (window
->default_widget
)
838 gtk_widget_activate (window
->default_widget
);
846 GtkWidget
* wxTextCtrl::GetConnectWidget()
848 return GTK_WIDGET(m_text
);
851 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
853 if (m_windowStyle
& wxTE_MULTILINE
)
854 return (window
== GTK_TEXT(m_text
)->text_area
);
856 return (window
== GTK_ENTRY(m_text
)->text_area
);
859 // the font will change for subsequent text insertiongs
860 bool wxTextCtrl::SetFont( const wxFont
&font
)
862 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
864 if ( !wxWindowBase::SetFont(font
) )
866 // font didn't change, nothing to do
870 if ( m_windowStyle
& wxTE_MULTILINE
)
872 // for compatibility with other ports: the font is a global controls
873 // characteristic, so change the font globally
874 wxString value
= GetValue();
875 if ( !value
.IsEmpty() )
886 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
888 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
894 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
896 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
898 wxControl::SetBackgroundColour( colour
);
900 if (!m_widget
->window
)
903 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
904 if (sysbg
.Red() == colour
.Red() &&
905 sysbg
.Green() == colour
.Green() &&
906 sysbg
.Blue() == colour
.Blue())
908 return FALSE
; // FIXME or TRUE?
911 if (!m_backgroundColour
.Ok())
914 if (m_windowStyle
& wxTE_MULTILINE
)
916 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
919 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
920 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
921 gdk_window_clear( window
);
927 void wxTextCtrl::ApplyWidgetStyle()
929 if (m_windowStyle
& wxTE_MULTILINE
)
936 gtk_widget_set_style( m_text
, m_widgetStyle
);
940 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
945 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
950 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
955 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
960 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
965 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
967 event
.Enable( CanCut() );
970 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
972 event
.Enable( CanCopy() );
975 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
977 event
.Enable( CanPaste() );
980 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
982 event
.Enable( CanUndo() );
985 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
987 event
.Enable( CanRedo() );
990 void wxTextCtrl::OnInternalIdle()
992 wxCursor cursor
= m_cursor
;
993 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
997 GdkWindow
*window
= (GdkWindow
*) NULL
;
998 if (HasFlag(wxTE_MULTILINE
))
999 window
= GTK_TEXT(m_text
)->text_area
;
1001 window
= GTK_ENTRY(m_text
)->text_area
;
1004 gdk_window_set_cursor( window
, cursor
.GetCursor() );
1006 if (!g_globalCursor
.Ok())
1007 cursor
= *wxSTANDARD_CURSOR
;
1009 window
= m_widget
->window
;
1010 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
1011 gdk_window_set_cursor( window
, cursor
.GetCursor() );
1017 wxSize
wxTextCtrl::DoGetBestSize() const
1019 // FIXME should be different for multi-line controls...
1020 wxSize
ret( wxControl::DoGetBestSize() );
1021 return wxSize(80, ret
.y
);