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();
54 win
->UpdateFontIfNeeded();
56 wxCommandEvent
event( wxEVT_COMMAND_TEXT_UPDATED
, win
->GetId() );
57 event
.SetString( win
->GetValue() );
58 event
.SetEventObject( win
);
59 win
->GetEventHandler()->ProcessEvent( event
);
62 //-----------------------------------------------------------------------------
63 // "changed" from vertical scrollbar
64 //-----------------------------------------------------------------------------
67 gtk_scrollbar_changed_callback( GtkWidget
*WXUNUSED(widget
), wxTextCtrl
*win
)
69 if (!win
->m_hasVMT
) return;
72 wxapp_install_idle_handler();
74 win
->CalculateScrollbar();
77 //-----------------------------------------------------------------------------
79 //-----------------------------------------------------------------------------
81 IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl
,wxControl
)
83 BEGIN_EVENT_TABLE(wxTextCtrl
, wxControl
)
84 EVT_CHAR(wxTextCtrl::OnChar
)
86 EVT_MENU(wxID_CUT
, wxTextCtrl::OnCut
)
87 EVT_MENU(wxID_COPY
, wxTextCtrl::OnCopy
)
88 EVT_MENU(wxID_PASTE
, wxTextCtrl::OnPaste
)
89 EVT_MENU(wxID_UNDO
, wxTextCtrl::OnUndo
)
90 EVT_MENU(wxID_REDO
, wxTextCtrl::OnRedo
)
92 EVT_UPDATE_UI(wxID_CUT
, wxTextCtrl::OnUpdateCut
)
93 EVT_UPDATE_UI(wxID_COPY
, wxTextCtrl::OnUpdateCopy
)
94 EVT_UPDATE_UI(wxID_PASTE
, wxTextCtrl::OnUpdatePaste
)
95 EVT_UPDATE_UI(wxID_UNDO
, wxTextCtrl::OnUpdateUndo
)
96 EVT_UPDATE_UI(wxID_REDO
, wxTextCtrl::OnUpdateRedo
)
99 void wxTextCtrl::Init()
102 m_updateFont
= FALSE
;
104 m_vScrollbar
= (GtkWidget
*)NULL
;
107 wxTextCtrl::wxTextCtrl( wxWindow
*parent
,
109 const wxString
&value
,
113 const wxValidator
& validator
,
114 const wxString
&name
)
118 Create( parent
, id
, value
, pos
, size
, style
, validator
, name
);
121 bool wxTextCtrl::Create( wxWindow
*parent
,
123 const wxString
&value
,
127 const wxValidator
& validator
,
128 const wxString
&name
)
131 m_acceptsFocus
= TRUE
;
133 if (!PreCreation( parent
, pos
, size
) ||
134 !CreateBase( parent
, id
, pos
, size
, style
, validator
, name
))
136 wxFAIL_MSG( wxT("wxTextCtrl creation failed") );
141 m_vScrollbarVisible
= FALSE
;
143 bool multi_line
= (style
& wxTE_MULTILINE
) != 0;
146 #if (GTK_MINOR_VERSION > 2)
147 /* a multi-line edit control: create a vertical scrollbar by default and
148 horizontal if requested */
149 bool bHasHScrollbar
= (style
& wxHSCROLL
) != 0;
151 bool bHasHScrollbar
= FALSE
;
154 /* create our control ... */
155 m_text
= gtk_text_new( (GtkAdjustment
*) NULL
, (GtkAdjustment
*) NULL
);
157 /* ... and put into the upper left hand corner of the table */
158 m_widget
= gtk_table_new(bHasHScrollbar
? 2 : 1, 2, FALSE
);
159 GTK_WIDGET_UNSET_FLAGS( m_widget
, GTK_CAN_FOCUS
);
160 gtk_table_attach( GTK_TABLE(m_widget
), m_text
, 0, 1, 0, 1,
161 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
162 (GtkAttachOptions
)(GTK_FILL
| GTK_EXPAND
| GTK_SHRINK
),
165 /* always wrap words */
166 gtk_text_set_word_wrap( GTK_TEXT(m_text
), TRUE
);
168 #if (GTK_MINOR_VERSION > 2)
169 /* put the horizontal scrollbar in the lower left hand corner */
172 GtkWidget
*hscrollbar
= gtk_hscrollbar_new(GTK_TEXT(m_text
)->hadj
);
173 GTK_WIDGET_UNSET_FLAGS( hscrollbar
, GTK_CAN_FOCUS
);
174 gtk_table_attach(GTK_TABLE(m_widget
), hscrollbar
, 0, 1, 1, 2,
175 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
178 gtk_widget_show(hscrollbar
);
180 /* don't wrap lines, otherwise we wouldn't need the scrollbar */
181 gtk_text_set_line_wrap( GTK_TEXT(m_text
), FALSE
);
185 /* finally, put the vertical scrollbar in the upper right corner */
186 m_vScrollbar
= gtk_vscrollbar_new( GTK_TEXT(m_text
)->vadj
);
187 GTK_WIDGET_UNSET_FLAGS( m_vScrollbar
, GTK_CAN_FOCUS
);
188 gtk_table_attach(GTK_TABLE(m_widget
), m_vScrollbar
, 1, 2, 0, 1,
190 (GtkAttachOptions
)(GTK_EXPAND
| GTK_FILL
| GTK_SHRINK
),
195 /* a single-line text control: no need for scrollbars */
197 m_text
= gtk_entry_new();
200 m_parent
->DoAddChild( this );
204 SetFont( parent
->GetFont() );
206 wxSize
size_best( DoGetBestSize() );
207 wxSize
new_size( size
);
208 if (new_size
.x
== -1)
209 new_size
.x
= size_best
.x
;
210 if (new_size
.y
== -1)
211 new_size
.y
= size_best
.y
;
212 if ((new_size
.x
!= size
.x
) || (new_size
.y
!= size
.y
))
213 SetSize( new_size
.x
, new_size
.y
);
216 gtk_widget_show(m_text
);
218 /* we want to be notified about text changes */
219 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
220 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
224 gtk_signal_connect(GTK_OBJECT(GTK_TEXT(m_text
)->vadj
), "changed",
225 (GtkSignalFunc
) gtk_scrollbar_changed_callback
, (gpointer
) this );
228 if (!value
.IsEmpty())
232 #if GTK_MINOR_VERSION == 0
233 // if we don't realize it, GTK 1.0.6 dies with a SIGSEGV in
234 // gtk_editable_insert_text()
235 gtk_widget_realize(m_text
);
239 wxWX2MBbuf val
= value
.mbc_str();
240 gtk_editable_insert_text( GTK_EDITABLE(m_text
), val
, strlen(val
), &tmp
);
242 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &tmp
);
243 #endif // Unicode/!Unicode
247 /* bring editable's cursor uptodate. bug in GTK. */
249 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
253 if (style
& wxTE_PASSWORD
)
256 gtk_entry_set_visibility( GTK_ENTRY(m_text
), FALSE
);
259 if (style
& wxTE_READONLY
)
262 gtk_entry_set_editable( GTK_ENTRY(m_text
), FALSE
);
267 gtk_text_set_editable( GTK_TEXT(m_text
), 1 );
270 SetBackgroundColour( wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW
) );
271 SetForegroundColour( parent
->GetForegroundColour() );
273 m_cursor
= wxCursor( wxCURSOR_IBEAM
);
280 void wxTextCtrl::CalculateScrollbar()
282 if ((m_windowStyle
& wxTE_MULTILINE
) == 0) return;
284 GtkAdjustment
*adj
= GTK_TEXT(m_text
)->vadj
;
286 if (adj
->upper
- adj
->page_size
< 0.8)
288 if (m_vScrollbarVisible
)
290 gtk_widget_hide( m_vScrollbar
);
291 m_vScrollbarVisible
= FALSE
;
296 if (!m_vScrollbarVisible
)
298 gtk_widget_show( m_vScrollbar
);
299 m_vScrollbarVisible
= TRUE
;
304 wxString
wxTextCtrl::GetValue() const
306 wxCHECK_MSG( m_text
!= NULL
, wxT(""), wxT("invalid text ctrl") );
309 if (m_windowStyle
& wxTE_MULTILINE
)
311 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
312 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
313 tmp
= wxString(text
,*wxConvCurrent
);
318 tmp
= wxString(gtk_entry_get_text( GTK_ENTRY(m_text
) ),*wxConvCurrent
);
323 void wxTextCtrl::SetValue( const wxString
&value
)
325 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
327 if (m_windowStyle
& wxTE_MULTILINE
)
329 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
330 gtk_editable_delete_text( GTK_EDITABLE(m_text
), 0, len
);
333 wxWX2MBbuf tmpbuf
= value
.mbc_str();
334 gtk_editable_insert_text( GTK_EDITABLE(m_text
), tmpbuf
, strlen(tmpbuf
), &len
);
336 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
.mbc_str(), value
.Length(), &len
);
341 gtk_entry_set_text( GTK_ENTRY(m_text
), value
.mbc_str() );
344 // GRG, Jun/2000: Changed this after a lot of discussion in
345 // the lists. wxWindows 2.2 will have a set of flags to
346 // customize this behaviour.
347 SetInsertionPoint(0);
352 void wxTextCtrl::WriteText( const wxString
&text
)
354 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
356 if (text
.IsEmpty()) return;
358 if (m_windowStyle
& wxTE_MULTILINE
)
360 /* this moves the cursor pos to behind the inserted text */
361 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
364 wxWX2MBbuf buf
= text
.mbc_str();
365 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
367 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
370 /* bring editable's cursor uptodate. bug in GTK. */
371 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
375 /* this moves the cursor pos to behind the inserted text */
376 gint len
= GTK_EDITABLE(m_text
)->current_pos
;
378 wxWX2MBbuf buf
= text
.mbc_str();
379 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
381 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
384 /* bring editable's cursor uptodate. bug in GTK. */
385 GTK_EDITABLE(m_text
)->current_pos
+= text
.Len();
387 /* bring entry's cursor uptodate. bug in GTK. */
388 gtk_entry_set_position( GTK_ENTRY(m_text
), GTK_EDITABLE(m_text
)->current_pos
);
392 void wxTextCtrl::AppendText( const wxString
&text
)
394 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
396 if (text
.IsEmpty()) return;
398 if (m_windowStyle
& wxTE_MULTILINE
)
400 bool hasSpecialAttributes
= m_font
.Ok() ||
401 m_foregroundColour
.Ok() ||
402 m_backgroundColour
.Ok();
403 if ( hasSpecialAttributes
)
405 gtk_text_insert( GTK_TEXT(m_text
),
406 m_font
.GetInternalFont(),
407 m_foregroundColour
.GetColor(),
408 m_backgroundColour
.GetColor(),
409 text
.mbc_str(), text
.length());
414 /* we'll insert at the last position */
415 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
417 wxWX2MBbuf buf
= text
.mbc_str();
418 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &len
);
420 gtk_editable_insert_text( GTK_EDITABLE(m_text
), text
, text
.Length(), &len
);
424 /* bring editable's cursor uptodate. bug in GTK. */
425 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
429 gtk_entry_append_text( GTK_ENTRY(m_text
), text
.mbc_str() );
433 wxString
wxTextCtrl::GetLineText( long lineNo
) const
435 if (m_windowStyle
& wxTE_MULTILINE
)
437 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
438 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
442 wxString
buf(wxT(""));
445 for (i
= 0; currentLine
!= lineNo
&& text
[i
]; i
++ )
450 for (j
= 0; text
[i
] && text
[i
] != '\n'; i
++, j
++ )
457 return wxEmptyString
;
461 if (lineNo
== 0) return GetValue();
462 return wxEmptyString
;
466 void wxTextCtrl::OnDropFiles( wxDropFilesEvent
&WXUNUSED(event
) )
468 /* If you implement this, don't forget to update the documentation!
469 * (file docs/latex/wx/text.tex) */
470 wxFAIL_MSG( wxT("wxTextCtrl::OnDropFiles not implemented") );
473 bool wxTextCtrl::PositionToXY(long pos
, long *x
, long *y
) const
475 if ( m_windowStyle
& wxTE_MULTILINE
)
477 wxString text
= GetValue();
479 // cast to prevent warning. But pos really should've been unsigned.
480 if( (unsigned long)pos
> text
.Len() )
486 const wxChar
* stop
= text
.c_str() + pos
;
487 for ( const wxChar
*p
= text
.c_str(); p
< stop
; p
++ )
498 else // single line control
500 if ( pos
<= GTK_ENTRY(m_text
)->text_length
)
507 // index out of bounds
515 long wxTextCtrl::XYToPosition(long x
, long y
) const
517 if (!(m_windowStyle
& wxTE_MULTILINE
)) return 0;
520 for( int i
=0; i
<y
; i
++ ) pos
+= GetLineLength(i
) + 1; // one for '\n'
526 int wxTextCtrl::GetLineLength(long lineNo
) const
528 wxString str
= GetLineText (lineNo
);
529 return (int) str
.Length();
532 int wxTextCtrl::GetNumberOfLines() const
534 if (m_windowStyle
& wxTE_MULTILINE
)
536 gint len
= gtk_text_get_length( GTK_TEXT(m_text
) );
537 char *text
= gtk_editable_get_chars( GTK_EDITABLE(m_text
), 0, len
);
542 for (int i
= 0; i
< len
; i
++ )
549 // currentLine is 0 based, add 1 to get number of lines
550 return currentLine
+ 1;
563 void wxTextCtrl::SetInsertionPoint( long pos
)
565 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
567 if (m_windowStyle
& wxTE_MULTILINE
)
569 /* seems to be broken in GTK 1.0.X:
570 gtk_text_set_point( GTK_TEXT(m_text), (int)pos ); */
572 gtk_signal_disconnect_by_func( GTK_OBJECT(m_text
),
573 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
575 /* we fake a set_point by inserting and deleting. as the user
576 isn't supposed to get to know about thos non-sense, we
577 disconnect so that no events are sent to the user program. */
579 gint tmp
= (gint
)pos
;
580 gtk_editable_insert_text( GTK_EDITABLE(m_text
), " ", 1, &tmp
);
581 gtk_editable_delete_text( GTK_EDITABLE(m_text
), tmp
-1, tmp
);
583 gtk_signal_connect( GTK_OBJECT(m_text
), "changed",
584 GTK_SIGNAL_FUNC(gtk_text_changed_callback
), (gpointer
)this);
586 /* bring editable's cursor uptodate. another bug in GTK. */
588 GTK_EDITABLE(m_text
)->current_pos
= gtk_text_get_point( GTK_TEXT(m_text
) );
592 gtk_entry_set_position( GTK_ENTRY(m_text
), (int)pos
);
594 /* bring editable's cursor uptodate. bug in GTK. */
596 GTK_EDITABLE(m_text
)->current_pos
= (guint32
)pos
;
600 void wxTextCtrl::SetInsertionPointEnd()
602 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
604 if (m_windowStyle
& wxTE_MULTILINE
)
605 SetInsertionPoint(gtk_text_get_length(GTK_TEXT(m_text
)));
607 gtk_entry_set_position( GTK_ENTRY(m_text
), -1 );
610 void wxTextCtrl::SetEditable( bool editable
)
612 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
614 if (m_windowStyle
& wxTE_MULTILINE
)
615 gtk_text_set_editable( GTK_TEXT(m_text
), editable
);
617 gtk_entry_set_editable( GTK_ENTRY(m_text
), editable
);
620 bool wxTextCtrl::Enable( bool enable
)
622 if (!wxWindowBase::Enable(enable
))
628 if (m_windowStyle
& wxTE_MULTILINE
)
630 gtk_text_set_editable( GTK_TEXT(m_text
), enable
);
634 gtk_widget_set_sensitive( m_text
, enable
);
640 void wxTextCtrl::DiscardEdits()
645 void wxTextCtrl::SetSelection( long from
, long to
)
647 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
649 gtk_editable_select_region( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
652 void wxTextCtrl::ShowPosition( long WXUNUSED(pos
) )
654 // SetInsertionPoint( pos );
657 long wxTextCtrl::GetInsertionPoint() const
659 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
661 return (long) GTK_EDITABLE(m_text
)->current_pos
;
664 long wxTextCtrl::GetLastPosition() const
666 wxCHECK_MSG( m_text
!= NULL
, 0, wxT("invalid text ctrl") );
669 if (m_windowStyle
& wxTE_MULTILINE
)
670 pos
= gtk_text_get_length( GTK_TEXT(m_text
) );
672 pos
= GTK_ENTRY(m_text
)->text_length
;
677 void wxTextCtrl::Remove( long from
, long to
)
679 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
681 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
684 void wxTextCtrl::Replace( long from
, long to
, const wxString
&value
)
686 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
688 gtk_editable_delete_text( GTK_EDITABLE(m_text
), (gint
)from
, (gint
)to
);
690 if (!value
.IsEmpty())
692 gint pos
= (gint
)from
;
694 wxWX2MBbuf buf
= value
.mbc_str();
695 gtk_editable_insert_text( GTK_EDITABLE(m_text
), buf
, strlen(buf
), &pos
);
697 gtk_editable_insert_text( GTK_EDITABLE(m_text
), value
, value
.Length(), &pos
);
702 void wxTextCtrl::Cut()
704 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
706 #if (GTK_MINOR_VERSION > 0)
707 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
) );
709 gtk_editable_cut_clipboard( GTK_EDITABLE(m_text
), 0 );
713 void wxTextCtrl::Copy()
715 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
717 #if (GTK_MINOR_VERSION > 0)
718 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
) );
720 gtk_editable_copy_clipboard( GTK_EDITABLE(m_text
), 0 );
724 void wxTextCtrl::Paste()
726 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
728 #if (GTK_MINOR_VERSION > 0)
729 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
) );
731 gtk_editable_paste_clipboard( GTK_EDITABLE(m_text
), 0 );
735 bool wxTextCtrl::CanCopy() const
737 // Can copy if there's a selection
739 GetSelection(& from
, & to
);
740 return (from
!= to
) ;
743 bool wxTextCtrl::CanCut() const
745 // Can cut if there's a selection
747 GetSelection(& from
, & to
);
748 return (from
!= to
) && (IsEditable());
751 bool wxTextCtrl::CanPaste() const
753 return IsEditable() ;
757 void wxTextCtrl::Undo()
760 wxFAIL_MSG( wxT("wxTextCtrl::Undo not implemented") );
763 void wxTextCtrl::Redo()
766 wxFAIL_MSG( wxT("wxTextCtrl::Redo not implemented") );
769 bool wxTextCtrl::CanUndo() const
772 wxFAIL_MSG( wxT("wxTextCtrl::CanUndo not implemented") );
776 bool wxTextCtrl::CanRedo() const
779 wxFAIL_MSG( wxT("wxTextCtrl::CanRedo not implemented") );
783 // If the return values from and to are the same, there is no
785 void wxTextCtrl::GetSelection(long* from
, long* to
) const
787 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
789 if (!(GTK_EDITABLE(m_text
)->has_selection
))
791 long i
= GetInsertionPoint();
797 if (from
) *from
= (long) GTK_EDITABLE(m_text
)->selection_start_pos
;
798 if (to
) *to
= (long) GTK_EDITABLE(m_text
)->selection_end_pos
;
801 bool wxTextCtrl::IsEditable() const
803 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
805 return GTK_EDITABLE(m_text
)->editable
;
808 bool wxTextCtrl::IsModified() const
813 void wxTextCtrl::Clear()
818 void wxTextCtrl::OnChar( wxKeyEvent
&key_event
)
820 wxCHECK_RET( m_text
!= NULL
, wxT("invalid text ctrl") );
822 if ((key_event
.KeyCode() == WXK_RETURN
) && (m_windowStyle
& wxPROCESS_ENTER
))
824 wxCommandEvent
event(wxEVT_COMMAND_TEXT_ENTER
, m_windowId
);
825 event
.SetEventObject(this);
826 event
.SetString(GetValue());
827 if (GetEventHandler()->ProcessEvent(event
)) return;
830 if ((key_event
.KeyCode() == WXK_RETURN
) && !(m_windowStyle
& wxTE_MULTILINE
))
832 wxWindow
*top_frame
= m_parent
;
833 while (top_frame
->GetParent() && !(top_frame
->IsTopLevel()))
834 top_frame
= top_frame
->GetParent();
835 GtkWindow
*window
= GTK_WINDOW(top_frame
->m_widget
);
837 if (window
->default_widget
)
839 gtk_widget_activate (window
->default_widget
);
847 GtkWidget
* wxTextCtrl::GetConnectWidget()
849 return GTK_WIDGET(m_text
);
852 bool wxTextCtrl::IsOwnGtkWindow( GdkWindow
*window
)
854 if (m_windowStyle
& wxTE_MULTILINE
)
855 return (window
== GTK_TEXT(m_text
)->text_area
);
857 return (window
== GTK_ENTRY(m_text
)->text_area
);
860 // the font will change for subsequent text insertiongs
861 bool wxTextCtrl::SetFont( const wxFont
&font
)
863 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
865 if ( !wxWindowBase::SetFont(font
) )
867 // font didn't change, nothing to do
871 if ( m_windowStyle
& wxTE_MULTILINE
)
875 ChangeFontGlobally();
881 void wxTextCtrl::ChangeFontGlobally()
883 // this method is very inefficient and hence should be called as rarely as
885 wxASSERT_MSG( (m_windowStyle
& wxTE_MULTILINE
) && m_updateFont
,
886 _T("shouldn't be called for single line controls") );
888 wxString value
= GetValue();
889 if ( !value
.IsEmpty() )
894 m_updateFont
= FALSE
;
898 void wxTextCtrl::UpdateFontIfNeeded()
901 ChangeFontGlobally();
904 bool wxTextCtrl::SetForegroundColour( const wxColour
&WXUNUSED(colour
) )
906 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
912 bool wxTextCtrl::SetBackgroundColour( const wxColour
&colour
)
914 wxCHECK_MSG( m_text
!= NULL
, FALSE
, wxT("invalid text ctrl") );
916 wxControl::SetBackgroundColour( colour
);
918 if (!m_widget
->window
)
921 wxColour sysbg
= wxSystemSettings::GetSystemColour( wxSYS_COLOUR_BTNFACE
);
922 if (sysbg
.Red() == colour
.Red() &&
923 sysbg
.Green() == colour
.Green() &&
924 sysbg
.Blue() == colour
.Blue())
926 return FALSE
; // FIXME or TRUE?
929 if (!m_backgroundColour
.Ok())
932 if (m_windowStyle
& wxTE_MULTILINE
)
934 GdkWindow
*window
= GTK_TEXT(m_text
)->text_area
;
937 m_backgroundColour
.CalcPixel( gdk_window_get_colormap( window
) );
938 gdk_window_set_background( window
, m_backgroundColour
.GetColor() );
939 gdk_window_clear( window
);
945 void wxTextCtrl::ApplyWidgetStyle()
947 if (m_windowStyle
& wxTE_MULTILINE
)
954 gtk_widget_set_style( m_text
, m_widgetStyle
);
958 void wxTextCtrl::OnCut(wxCommandEvent
& WXUNUSED(event
))
963 void wxTextCtrl::OnCopy(wxCommandEvent
& WXUNUSED(event
))
968 void wxTextCtrl::OnPaste(wxCommandEvent
& WXUNUSED(event
))
973 void wxTextCtrl::OnUndo(wxCommandEvent
& WXUNUSED(event
))
978 void wxTextCtrl::OnRedo(wxCommandEvent
& WXUNUSED(event
))
983 void wxTextCtrl::OnUpdateCut(wxUpdateUIEvent
& event
)
985 event
.Enable( CanCut() );
988 void wxTextCtrl::OnUpdateCopy(wxUpdateUIEvent
& event
)
990 event
.Enable( CanCopy() );
993 void wxTextCtrl::OnUpdatePaste(wxUpdateUIEvent
& event
)
995 event
.Enable( CanPaste() );
998 void wxTextCtrl::OnUpdateUndo(wxUpdateUIEvent
& event
)
1000 event
.Enable( CanUndo() );
1003 void wxTextCtrl::OnUpdateRedo(wxUpdateUIEvent
& event
)
1005 event
.Enable( CanRedo() );
1008 void wxTextCtrl::OnInternalIdle()
1010 wxCursor cursor
= m_cursor
;
1011 if (g_globalCursor
.Ok()) cursor
= g_globalCursor
;
1015 GdkWindow
*window
= (GdkWindow
*) NULL
;
1016 if (HasFlag(wxTE_MULTILINE
))
1017 window
= GTK_TEXT(m_text
)->text_area
;
1019 window
= GTK_ENTRY(m_text
)->text_area
;
1022 gdk_window_set_cursor( window
, cursor
.GetCursor() );
1024 if (!g_globalCursor
.Ok())
1025 cursor
= *wxSTANDARD_CURSOR
;
1027 window
= m_widget
->window
;
1028 if ((window
) && !(GTK_WIDGET_NO_WINDOW(m_widget
)))
1029 gdk_window_set_cursor( window
, cursor
.GetCursor() );
1035 wxSize
wxTextCtrl::DoGetBestSize() const
1037 // FIXME should be different for multi-line controls...
1038 wxSize
ret( wxControl::DoGetBestSize() );
1039 return wxSize(80, ret
.y
);