X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/223d09f6b523aac674ef9b72a883dfa8d37c5d4e..2bc6945a258b355f579d8533b7174f02ff8dc9e3:/src/gtk1/textctrl.cpp diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index db100d48ec..4cef1e8168 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -98,19 +98,31 @@ END_EVENT_TABLE() wxTextCtrl::wxTextCtrl() { m_modified = FALSE; + m_text = + m_vScrollbar = (GtkWidget *)NULL; } -wxTextCtrl::wxTextCtrl( wxWindow *parent, wxWindowID id, const wxString &value, - const wxPoint &pos, const wxSize &size, - int style, const wxValidator& validator, const wxString &name ) +wxTextCtrl::wxTextCtrl( wxWindow *parent, + wxWindowID id, + const wxString &value, + const wxPoint &pos, + const wxSize &size, + long style, + const wxValidator& validator, + const wxString &name ) { m_modified = FALSE; Create( parent, id, value, pos, size, style, validator, name ); } -bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, - const wxPoint &pos, const wxSize &size, - int style, const wxValidator& validator, const wxString &name ) +bool wxTextCtrl::Create( wxWindow *parent, + wxWindowID id, + const wxString &value, + const wxPoint &pos, + const wxSize &size, + long style, + const wxValidator& validator, + const wxString &name ) { m_needParent = TRUE; m_acceptsFocus = TRUE; @@ -119,7 +131,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, !CreateBase( parent, id, pos, size, style, validator, name )) { wxFAIL_MSG( wxT("wxTextCtrl creation failed") ); - return FALSE; + return FALSE; } @@ -182,15 +194,21 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, m_text = gtk_entry_new(); } - wxSize newSize = size; - if (newSize.x == -1) newSize.x = 80; - if (newSize.y == -1) newSize.y = 26; - SetSize( newSize.x, newSize.y ); - m_parent->DoAddChild( this ); PostCreation(); + SetFont( parent->GetFont() ); + + wxSize size_best( DoGetBestSize() ); + wxSize new_size( size ); + if (new_size.x == -1) + new_size.x = size_best.x; + if (new_size.y == -1) + new_size.y = size_best.y; + if ((new_size.x != size.x) || (new_size.y != size.y)) + SetSize( new_size.x, new_size.y ); + if (multi_line) gtk_widget_show(m_text); @@ -250,7 +268,7 @@ bool wxTextCtrl::Create( wxWindow *parent, wxWindowID id, const wxString &value, SetForegroundColour( parent->GetForegroundColour() ); m_cursor = wxCursor( wxCURSOR_IBEAM ); - + Show( TRUE ); return TRUE; @@ -321,6 +339,13 @@ void wxTextCtrl::SetValue( const wxString &value ) { gtk_entry_set_text( GTK_ENTRY(m_text), tmp.mbc_str() ); } + + // GRG, Jun/2000: Changed this after a lot of discussion in + // the lists. wxWindows 2.2 will have a set of flags to + // customize this behaviour. + SetInsertionPoint(0); + + m_modified = FALSE; } void wxTextCtrl::WriteText( const wxString &text ) @@ -567,7 +592,7 @@ void wxTextCtrl::SetInsertionPoint( long pos ) /* bring editable's cursor uptodate. bug in GTK. */ - GTK_EDITABLE(m_text)->current_pos = pos; + GTK_EDITABLE(m_text)->current_pos = (guint32)pos; } } @@ -591,6 +616,26 @@ void wxTextCtrl::SetEditable( bool editable ) gtk_entry_set_editable( GTK_ENTRY(m_text), editable ); } +bool wxTextCtrl::Enable( bool enable ) +{ + if (!wxWindowBase::Enable(enable)) + { + // nothing to do + return FALSE; + } + + if (m_windowStyle & wxTE_MULTILINE) + { + gtk_text_set_editable( GTK_TEXT(m_text), enable ); + } + else + { + gtk_widget_set_sensitive( m_text, enable ); + } + + return TRUE; +} + void wxTextCtrl::DiscardEdits() { m_modified = FALSE; @@ -699,7 +744,7 @@ bool wxTextCtrl::CanCut() const // Can cut if there's a selection long from, to; GetSelection(& from, & to); - return (from != to) ; + return (from != to) && (IsEditable()); } bool wxTextCtrl::CanPaste() const @@ -742,8 +787,9 @@ void wxTextCtrl::GetSelection(long* from, long* to) const if (!(GTK_EDITABLE(m_text)->has_selection)) { - if (from) *from = 0; - if (to) *to = 0; + long i = GetInsertionPoint(); + if (from) *from = i; + if (to) *to = i; return; } @@ -776,9 +822,24 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event ) { wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, m_windowId); event.SetEventObject(this); + event.SetString(GetValue()); if (GetEventHandler()->ProcessEvent(event)) return; } + if ((key_event.KeyCode() == WXK_RETURN) && !(m_windowStyle & wxTE_MULTILINE)) + { + wxWindow *top_frame = m_parent; + while (top_frame->GetParent() && !(top_frame->IsTopLevel())) + top_frame = top_frame->GetParent(); + GtkWindow *window = GTK_WINDOW(top_frame->m_widget); + + if (window->default_widget) + { + gtk_widget_activate (window->default_widget); + return; + } + } + key_event.Skip(); } @@ -931,16 +992,14 @@ void wxTextCtrl::OnInternalIdle() wxCursor cursor = m_cursor; if (g_globalCursor.Ok()) cursor = g_globalCursor; - if (cursor.Ok() && m_currentGdkCursor != cursor) + if (cursor.Ok()) { - m_currentGdkCursor = cursor; - GdkWindow *window = (GdkWindow*) NULL; - if (HasFlag(wxTE_MULTILINE)) + if (HasFlag(wxTE_MULTILINE)) window = GTK_TEXT(m_text)->text_area; else window = GTK_ENTRY(m_text)->text_area; - + if (window) gdk_window_set_cursor( window, cursor.GetCursor() ); @@ -948,7 +1007,16 @@ void wxTextCtrl::OnInternalIdle() cursor = *wxSTANDARD_CURSOR; window = m_widget->window; - if (window) + if ((window) && !(GTK_WIDGET_NO_WINDOW(m_widget))) gdk_window_set_cursor( window, cursor.GetCursor() ); } + + UpdateWindowUI(); +} + +wxSize wxTextCtrl::DoGetBestSize() const +{ + // FIXME should be different for multi-line controls... + wxSize ret( wxControl::DoGetBestSize() ); + return wxSize(80, ret.y); }