From 150e31d2088687cbfbab548f9e98918f8683d9b5 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Thu, 9 Dec 2004 15:16:51 +0000 Subject: [PATCH] Added further 'missing' wxTextCtrl-like functions to wxComboBox git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@30918 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/combobox.tex | 46 ++++++++ include/wx/cocoa/combobox.h | 18 +++ include/wx/combobox.h | 13 +++ include/wx/gtk/combobox.h | 30 ++++- include/wx/gtk1/combobox.h | 30 ++++- include/wx/mac/carbon/combobox.h | 13 +++ include/wx/mac/classic/combobox.h | 13 +++ include/wx/msw/combobox.h | 29 +++++ include/wx/palmos/combobox.h | 13 ++- include/wx/univ/combobox.h | 11 ++ src/gtk/combobox.cpp | 183 +++++++++++++++++++++++++++-- src/gtk1/combobox.cpp | 183 +++++++++++++++++++++++++++-- src/mac/carbon/combobox.cpp | 108 ++++++++++++++---- src/mac/carbon/combobxc.cpp | 174 ++++++++++++++++++++++------ src/mac/classic/combobox.cpp | 97 +++++++++++++--- src/msw/combobox.cpp | 184 +++++++++++++++++++++++++++++- src/palmos/combobox.cpp | 47 +++++++- src/univ/combobox.cpp | 73 +++++++++++- 18 files changed, 1155 insertions(+), 110 deletions(-) diff --git a/docs/latex/wx/combobox.tex b/docs/latex/wx/combobox.tex index 06ac8e649c..67960d7911 100644 --- a/docs/latex/wx/combobox.tex +++ b/docs/latex/wx/combobox.tex @@ -123,6 +123,41 @@ Creates the combobox for two-step construction. Derived classes should call or replace this function. See \helpref{wxComboBox::wxComboBox}{wxcomboboxctor}\rtfsp for further details. +\membersection{wxComboBox::CanCopy}\label{wxcomboboxcancopy} + +\constfunc{bool}{CanCopy}{\void} + +Returns true if the combobox is editable and there is a text selection to copy to the clipboard. +Only available on Windows. + +\membersection{wxComboBox::CanCut}\label{wxcomboboxcancut} + +\constfunc{bool}{CanCut}{\void} + +Returns true if the combobox is editable and there is a text selection to copy to the clipboard. +Only available on Windows. + +\membersection{wxComboBox::CanPaste}\label{wxcomboboxcanpaste} + +\constfunc{bool}{CanPaste}{\void} + +Returns true if the combobox is editable and there is text on the clipboard that can be pasted into the +text field. Only available on Windows. + +\membersection{wxComboBox::CanRedo}\label{wxcomboboxcanredo} + +\constfunc{bool}{CanRedo}{\void} + +Returns true if the combobox is editable and the last undo can be redone. +Only available on Windows. + +\membersection{wxComboBox::CanUndo}\label{wxcomboboxcanundo} + +\constfunc{bool}{CanUndo}{\void} + +Returns true if the combobox is editable and the last edit can be undone. +Only available on Windows. + \membersection{wxComboBox::Copy}\label{wxcomboboxcopy} \func{void}{Copy}{\void} @@ -159,6 +194,12 @@ Returns the current value in the combobox text field. Pastes text from the clipboard to the text field. +\membersection{wxComboBox::Redo}\label{wxcomboboxredo} + +\func{void}{Redo}{\void} + +Redoes the last undo in the text field. Windows only. + \membersection{wxComboBox::Replace}\label{wxcomboboxreplace} \func{void}{Replace}{\param{long}{ from}, \param{long}{ to}, \param{const wxString\& }{text}} @@ -230,4 +271,9 @@ the combobox choices list, otherwise the call to SetValue() is ignored. \docparam{text}{The text to set.} +\membersection{wxComboBox::Undo}\label{wxcomboboxundo} + +\func{void}{Undo}{\void} + +Undoes the last edit in the text field. Windows only. diff --git a/include/wx/cocoa/combobox.h b/include/wx/cocoa/combobox.h index b1abb3950c..84f16fefe2 100644 --- a/include/wx/cocoa/combobox.h +++ b/include/wx/cocoa/combobox.h @@ -122,6 +122,24 @@ public: { wxTextCtrl::SetSelection(from,to); } virtual void SetEditable(bool editable) { wxTextCtrl::SetEditable(editable); } + virtual bool IsEditable() const + { return !HasFlag(wxCB_READONLY); } + virtual void Undo() + { wxTextCtrl::Undo(); } + virtual void Redo() + { wxTextCtrl::Redo(); } + virtual void SelectAll() + { wxTextCtrl::SelectAll(); } + virtual bool CanCopy() const + { return wxTextCtrl::CanCopy(); } + virtual bool CanCut() const = 0 + { return wxTextCtrl::CanCut(); } + virtual bool CanPaste() const + { return wxTextCtrl::CanPaste(); } + virtual bool CanUndo() const + { return wxTextCtrl::CanUndo(); } + virtual bool CanRedo() const + { return wxTextCtrl::CanRedo(); } }; #endif // __WX_COCOA_COMBOBOX_H__ diff --git a/include/wx/combobox.h b/include/wx/combobox.h index e914de482e..51b88e169f 100644 --- a/include/wx/combobox.h +++ b/include/wx/combobox.h @@ -45,6 +45,19 @@ public: { SetInsertionPoint(GetLastPosition()); } virtual void Remove(long from, long to) { Replace(from, to, wxEmptyString); } + + virtual bool IsEditable() const = 0; + + virtual void Undo() = 0; + virtual void Redo() = 0; + virtual void SelectAll() = 0; + + virtual bool CanCopy() const = 0; + virtual bool CanCut() const = 0; + virtual bool CanPaste() const = 0; + virtual bool CanUndo() const = 0; + virtual bool CanRedo() const = 0; + }; // ---------------------------------------------------------------------------- diff --git a/include/wx/gtk/combobox.h b/include/wx/gtk/combobox.h index 0592f6f193..c27d532b47 100644 --- a/include/wx/gtk/combobox.h +++ b/include/wx/gtk/combobox.h @@ -105,6 +105,9 @@ public: void Copy(); void Cut(); void Paste(); + bool CanCopy() const; + bool CanCut() const; + bool CanPaste() const; void SetInsertionPoint( long pos ); void SetInsertionPointEnd() { SetInsertionPoint( -1 ); } long GetInsertionPoint() const; @@ -112,7 +115,15 @@ public: void Remove(long from, long to) { Replace(from, to, wxEmptyString); } void Replace( long from, long to, const wxString& value ); void SetSelection( long from, long to ); + void GetSelection( long* from, long* to ) const; void SetEditable( bool editable ); + void Undo() ; + void Redo() ; + bool CanUndo() const; + bool CanRedo() const; + void SelectAll(); + bool IsEditable() const { return !HasFlag(wxCB_READONLY); } + bool HasSelection() const ; // implementation @@ -121,6 +132,23 @@ public: void OnSize( wxSizeEvent &event ); void OnChar( wxKeyEvent &event ); + // Standard event handling + void OnCut(wxCommandEvent& event); + void OnCopy(wxCommandEvent& event); + void OnPaste(wxCommandEvent& event); + void OnUndo(wxCommandEvent& event); + void OnRedo(wxCommandEvent& event); + void OnDelete(wxCommandEvent& event); + void OnSelectAll(wxCommandEvent& event); + + void OnUpdateCut(wxUpdateUIEvent& event); + void OnUpdateCopy(wxUpdateUIEvent& event); + void OnUpdatePaste(wxUpdateUIEvent& event); + void OnUpdateUndo(wxUpdateUIEvent& event); + void OnUpdateRedo(wxUpdateUIEvent& event); + void OnUpdateDelete(wxUpdateUIEvent& event); + void OnUpdateSelectAll(wxUpdateUIEvent& event); + bool m_ignoreNextUpdate:1; wxList m_clientDataList; wxList m_clientObjectList; @@ -136,7 +164,7 @@ public: static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); - + protected: virtual int DoAppend(const wxString& item); virtual int DoInsert(const wxString& item, int pos); diff --git a/include/wx/gtk1/combobox.h b/include/wx/gtk1/combobox.h index 0592f6f193..c27d532b47 100644 --- a/include/wx/gtk1/combobox.h +++ b/include/wx/gtk1/combobox.h @@ -105,6 +105,9 @@ public: void Copy(); void Cut(); void Paste(); + bool CanCopy() const; + bool CanCut() const; + bool CanPaste() const; void SetInsertionPoint( long pos ); void SetInsertionPointEnd() { SetInsertionPoint( -1 ); } long GetInsertionPoint() const; @@ -112,7 +115,15 @@ public: void Remove(long from, long to) { Replace(from, to, wxEmptyString); } void Replace( long from, long to, const wxString& value ); void SetSelection( long from, long to ); + void GetSelection( long* from, long* to ) const; void SetEditable( bool editable ); + void Undo() ; + void Redo() ; + bool CanUndo() const; + bool CanRedo() const; + void SelectAll(); + bool IsEditable() const { return !HasFlag(wxCB_READONLY); } + bool HasSelection() const ; // implementation @@ -121,6 +132,23 @@ public: void OnSize( wxSizeEvent &event ); void OnChar( wxKeyEvent &event ); + // Standard event handling + void OnCut(wxCommandEvent& event); + void OnCopy(wxCommandEvent& event); + void OnPaste(wxCommandEvent& event); + void OnUndo(wxCommandEvent& event); + void OnRedo(wxCommandEvent& event); + void OnDelete(wxCommandEvent& event); + void OnSelectAll(wxCommandEvent& event); + + void OnUpdateCut(wxUpdateUIEvent& event); + void OnUpdateCopy(wxUpdateUIEvent& event); + void OnUpdatePaste(wxUpdateUIEvent& event); + void OnUpdateUndo(wxUpdateUIEvent& event); + void OnUpdateRedo(wxUpdateUIEvent& event); + void OnUpdateDelete(wxUpdateUIEvent& event); + void OnUpdateSelectAll(wxUpdateUIEvent& event); + bool m_ignoreNextUpdate:1; wxList m_clientDataList; wxList m_clientObjectList; @@ -136,7 +164,7 @@ public: static wxVisualAttributes GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); - + protected: virtual int DoAppend(const wxString& item); virtual int DoInsert(const wxString& item, int pos); diff --git a/include/wx/mac/carbon/combobox.h b/include/wx/mac/carbon/combobox.h index 774d7a13f4..93d4f549f1 100644 --- a/include/wx/mac/carbon/combobox.h +++ b/include/wx/mac/carbon/combobox.h @@ -117,6 +117,19 @@ class WXDLLEXPORT wxComboBox : public wxControl, public wxComboBoxBase virtual void SetSelection(long from, long to); virtual void SetEditable(bool editable); virtual int GetCount() const ; + + virtual bool IsEditable() const ; + + virtual void Undo() ; + virtual void Redo() ; + virtual void SelectAll() ; + + virtual bool CanCopy() const ; + virtual bool CanCut() const ; + virtual bool CanPaste() const ; + virtual bool CanUndo() const ; + virtual bool CanRedo() const ; + wxInt32 MacControlHit( WXEVENTHANDLERREF handler , WXEVENTREF event ) ; wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST diff --git a/include/wx/mac/classic/combobox.h b/include/wx/mac/classic/combobox.h index 68b3b02820..d21925377c 100644 --- a/include/wx/mac/classic/combobox.h +++ b/include/wx/mac/classic/combobox.h @@ -112,6 +112,19 @@ class WXDLLEXPORT wxComboBox : public wxControl, public wxComboBoxBase virtual void SetSelection(long from, long to); virtual void SetEditable(bool editable); virtual int GetCount() const { return m_choice->GetCount() ; } + + virtual bool IsEditable() const ; + + virtual void Undo() ; + virtual void Redo() ; + virtual void SelectAll() ; + + virtual bool CanCopy() const ; + virtual bool CanCut() const ; + virtual bool CanPaste() const ; + virtual bool CanUndo() const ; + virtual bool CanRedo() const ; + void MacHandleControlClick( WXWidget control , wxInt16 controlpart , bool mouseStillDown ) ; wxCONTROL_ITEMCONTAINER_CLIENTDATAOBJECT_RECAST diff --git a/include/wx/msw/combobox.h b/include/wx/msw/combobox.h index c9eb4dcbe8..4b269e401c 100644 --- a/include/wx/msw/combobox.h +++ b/include/wx/msw/combobox.h @@ -86,6 +86,9 @@ public: virtual void Copy(); virtual void Cut(); virtual void Paste(); + virtual bool CanCopy() const; + virtual bool CanCut() const; + virtual bool CanPaste() const; virtual void SetInsertionPoint(long pos); virtual void SetInsertionPointEnd(); virtual long GetInsertionPoint() const; @@ -99,6 +102,14 @@ public: virtual void SetEditable(bool editable); virtual void Clear() { wxChoice::Clear(); m_selectionOld = -1; } + virtual void Undo() ; + virtual void Redo() ; + virtual bool CanUndo() const; + virtual bool CanRedo() const; + virtual void SelectAll(); + virtual bool IsEditable() const ; + virtual bool HasSelection() const; + // implementation only from now on virtual bool MSWCommand(WXUINT param, WXWORD id); bool MSWProcessEditMsg(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam); @@ -106,6 +117,23 @@ public: WXHWND GetEditHWND() const; + // Standard event handling + void OnCut(wxCommandEvent& event); + void OnCopy(wxCommandEvent& event); + void OnPaste(wxCommandEvent& event); + void OnUndo(wxCommandEvent& event); + void OnRedo(wxCommandEvent& event); + void OnDelete(wxCommandEvent& event); + void OnSelectAll(wxCommandEvent& event); + + void OnUpdateCut(wxUpdateUIEvent& event); + void OnUpdateCopy(wxUpdateUIEvent& event); + void OnUpdatePaste(wxUpdateUIEvent& event); + void OnUpdateUndo(wxUpdateUIEvent& event); + void OnUpdateRedo(wxUpdateUIEvent& event); + void OnUpdateDelete(wxUpdateUIEvent& event); + void OnUpdateSelectAll(wxUpdateUIEvent& event); + protected: virtual WXDWORD MSWGetStyle(long style, WXDWORD *exstyle) const; @@ -121,6 +149,7 @@ protected: private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxComboBox) + DECLARE_EVENT_TABLE() }; #endif // wxUSE_COMBOBOX diff --git a/include/wx/palmos/combobox.h b/include/wx/palmos/combobox.h index c70c5fbec1..ac52a54f39 100644 --- a/include/wx/palmos/combobox.h +++ b/include/wx/palmos/combobox.h @@ -4,7 +4,7 @@ // Author: William Osborne // Modified by: // Created: 10/13/04 -// RCS-ID: $Id: +// RCS-ID: $Id: // Copyright: (c) William Osborne // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -91,6 +91,17 @@ public: virtual void SetSelection(int n) { wxChoice::SetSelection(n); } virtual void SetSelection(long from, long to); virtual void SetEditable(bool editable); + virtual bool IsEditable() const; + + virtual void Undo(); + virtual void Redo(); + virtual void SelectAll(); + + virtual bool CanCopy() const; + virtual bool CanCut() const; + virtual bool CanPaste() const; + virtual bool CanUndo() const; + virtual bool CanRedo() const; // implementation only from now on virtual bool MSWCommand(WXUINT param, WXWORD id); diff --git a/include/wx/univ/combobox.h b/include/wx/univ/combobox.h index 13c5302326..b417a4e2f0 100644 --- a/include/wx/univ/combobox.h +++ b/include/wx/univ/combobox.h @@ -282,6 +282,17 @@ public: virtual void Remove(long from, long to); virtual void SetSelection(long from, long to); virtual void SetEditable(bool editable); + virtual bool IsEditable() const; + + virtual void Undo(); + virtual void Redo(); + virtual void SelectAll(); + + virtual bool CanCopy() const; + virtual bool CanCut() const; + virtual bool CanPaste() const; + virtual bool CanUndo() const; + virtual bool CanRedo() const; // wxControlWithItems methods virtual void Clear(); diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index b72887da0c..99e75910c2 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -50,7 +50,7 @@ gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) if (g_isIdle) wxapp_install_idle_handler(); if (combo->m_ignoreNextUpdate) - { + { combo->m_ignoreNextUpdate = FALSE; return; } @@ -87,7 +87,7 @@ gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(wi GtkWidget *list = GTK_COMBO(combo->m_widget)->list; gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection ); - + combo->m_prevSelection = curSelection; // Quickly set the value of the combo box @@ -103,10 +103,10 @@ gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(wi event.SetInt( curSelection ); event.SetString( combo->GetStringSelection() ); event.SetEventObject( combo ); - + combo->GetEventHandler()->ProcessEvent( event ); - // Now send the event ourselves + // Now send the event ourselves wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); event2.SetString( combo->GetValue() ); event2.SetEventObject( combo ); @@ -122,6 +122,22 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl) BEGIN_EVENT_TABLE(wxComboBox, wxControl) EVT_SIZE(wxComboBox::OnSize) EVT_CHAR(wxComboBox::OnChar) + + EVT_MENU(wxID_CUT, wxComboBox::OnCut) + EVT_MENU(wxID_COPY, wxComboBox::OnCopy) + EVT_MENU(wxID_PASTE, wxComboBox::OnPaste) + EVT_MENU(wxID_UNDO, wxComboBox::OnUndo) + EVT_MENU(wxID_REDO, wxComboBox::OnRedo) + EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete) + EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll) + + EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut) + EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy) + EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste) + EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo) + EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo) + EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete) + EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll) END_EVENT_TABLE() bool wxComboBox::Create( wxWindow *parent, wxWindowID id, @@ -214,7 +230,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, // This is required for tool bar support wxSize setsize = GetSize(); gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); - + return TRUE; } @@ -329,7 +345,7 @@ int wxComboBox::DoInsert( const wxString &item, int pos ) m_clientObjectList.Insert( pos, (wxObject*) NULL ); EnableEvents(); - + InvalidateBestSize(); return pos; @@ -431,9 +447,9 @@ void wxComboBox::Delete( int n ) node = m_clientDataList.Item( n ); if (node) m_clientDataList.Erase( node ); - + EnableEvents(); - + InvalidateBestSize(); } @@ -454,7 +470,7 @@ void wxComboBox::SetString(int n, const wxString &text) { wxFAIL_MSG( wxT("wxComboBox: wrong index") ); } - + InvalidateBestSize(); } @@ -618,7 +634,7 @@ void wxComboBox::SetValue( const wxString& value ) wxString tmp = wxT(""); if (!value.IsNull()) tmp = value; gtk_entry_set_text( GTK_ENTRY(entry), wxGTK_CONV( tmp ) ); - + InvalidateBestSize(); } @@ -646,6 +662,63 @@ void wxComboBox::Paste() gtk_editable_paste_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG); } +void wxComboBox::Undo() +{ + // TODO +} + +void wxComboBox::Redo() +{ + // TODO +} + +void wxComboBox::SelectAll() +{ + Select(0, GetLastPosition()); +} + +bool wxComboBox::CanUndo() const +{ + // TODO + return false; +} + +bool wxComboBox::CanRedo() const +{ + // TODO + return false; +} + +bool wxComboBox::HasSelection() const +{ + long from, to; + GetSelection(&from, &to); + return from != to; +} + +bool wxComboBox::CanCopy() const +{ + // Can copy if there's a selection + return HasSelection(); +} + +bool wxComboBox::CanCut() const +{ + return CanCopy() && IsEditable(); +} + +bool wxComboBox::CanPaste() const +{ + // TODO: check for text on the clipboard + return IsEditable() ; +} + +bool wxComboBox::IsEditable() const +{ + return !HasFlag(wxCB_READONLY); +} + + void wxComboBox::SetInsertionPoint( long pos ) { wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); @@ -692,6 +765,16 @@ void wxComboBox::SetSelection( long from, long to ) gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to ); } +void wxComboBox::GetSelection( long* from, long* to ) const +{ + if (IsEditable()) + { + GtkEditable *editable = GTK_EDITABLE(GTK_COMBO(m_widget)->entry); + *from = (long) editable->selection_start_pos; + *to = (long) editable->selection_end_pos; + } +} + void wxComboBox::SetEditable( bool editable ) { GtkWidget *entry = GTK_COMBO(m_widget)->entry; @@ -722,7 +805,7 @@ void wxComboBox::OnChar( wxKeyEvent &event ) GtkWindow *window = GTK_WINDOW(top_frame->m_widget); if (window->default_widget) - gtk_widget_activate (window->default_widget); + gtk_widget_activate (window->default_widget); } } @@ -828,4 +911,82 @@ wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true); } +// ---------------------------------------------------------------------------- +// standard event handling +// ---------------------------------------------------------------------------- + +void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event)) +{ + Cut(); +} + +void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event)) +{ + Copy(); +} + +void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event)) +{ + Paste(); +} + +void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event)) +{ + Undo(); +} + +void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event)) +{ + Redo(); +} + +void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event)) +{ + long from, to; + GetSelection(& from, & to); + if (from != -1 && to != -1) + Remove(from, to); +} + +void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event)) +{ + SetSelection(-1, -1); +} + +void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event) +{ + event.Enable( CanCut() ); +} + +void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event) +{ + event.Enable( CanCopy() ); +} + +void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event) +{ + event.Enable( CanPaste() ); +} + +void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event) +{ + event.Enable( CanUndo() ); +} + +void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event) +{ + event.Enable( CanRedo() ); +} + +void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event) +{ + event.Enable(HasSelection() && IsEditable()) ; +} + +void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event) +{ + event.Enable(GetLastPosition() > 0); +} + #endif + diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index b72887da0c..99e75910c2 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -50,7 +50,7 @@ gtk_text_changed_callback( GtkWidget *WXUNUSED(widget), wxComboBox *combo ) if (g_isIdle) wxapp_install_idle_handler(); if (combo->m_ignoreNextUpdate) - { + { combo->m_ignoreNextUpdate = FALSE; return; } @@ -87,7 +87,7 @@ gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(wi GtkWidget *list = GTK_COMBO(combo->m_widget)->list; gtk_list_unselect_item( GTK_LIST(list), combo->m_prevSelection ); - + combo->m_prevSelection = curSelection; // Quickly set the value of the combo box @@ -103,10 +103,10 @@ gtk_combo_select_child_callback( GtkList *WXUNUSED(list), GtkWidget *WXUNUSED(wi event.SetInt( curSelection ); event.SetString( combo->GetStringSelection() ); event.SetEventObject( combo ); - + combo->GetEventHandler()->ProcessEvent( event ); - // Now send the event ourselves + // Now send the event ourselves wxCommandEvent event2( wxEVT_COMMAND_TEXT_UPDATED, combo->GetId() ); event2.SetString( combo->GetValue() ); event2.SetEventObject( combo ); @@ -122,6 +122,22 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox,wxControl) BEGIN_EVENT_TABLE(wxComboBox, wxControl) EVT_SIZE(wxComboBox::OnSize) EVT_CHAR(wxComboBox::OnChar) + + EVT_MENU(wxID_CUT, wxComboBox::OnCut) + EVT_MENU(wxID_COPY, wxComboBox::OnCopy) + EVT_MENU(wxID_PASTE, wxComboBox::OnPaste) + EVT_MENU(wxID_UNDO, wxComboBox::OnUndo) + EVT_MENU(wxID_REDO, wxComboBox::OnRedo) + EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete) + EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll) + + EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut) + EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy) + EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste) + EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo) + EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo) + EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete) + EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll) END_EVENT_TABLE() bool wxComboBox::Create( wxWindow *parent, wxWindowID id, @@ -214,7 +230,7 @@ bool wxComboBox::Create( wxWindow *parent, wxWindowID id, const wxString& value, // This is required for tool bar support wxSize setsize = GetSize(); gtk_widget_set_usize( m_widget, setsize.x, setsize.y ); - + return TRUE; } @@ -329,7 +345,7 @@ int wxComboBox::DoInsert( const wxString &item, int pos ) m_clientObjectList.Insert( pos, (wxObject*) NULL ); EnableEvents(); - + InvalidateBestSize(); return pos; @@ -431,9 +447,9 @@ void wxComboBox::Delete( int n ) node = m_clientDataList.Item( n ); if (node) m_clientDataList.Erase( node ); - + EnableEvents(); - + InvalidateBestSize(); } @@ -454,7 +470,7 @@ void wxComboBox::SetString(int n, const wxString &text) { wxFAIL_MSG( wxT("wxComboBox: wrong index") ); } - + InvalidateBestSize(); } @@ -618,7 +634,7 @@ void wxComboBox::SetValue( const wxString& value ) wxString tmp = wxT(""); if (!value.IsNull()) tmp = value; gtk_entry_set_text( GTK_ENTRY(entry), wxGTK_CONV( tmp ) ); - + InvalidateBestSize(); } @@ -646,6 +662,63 @@ void wxComboBox::Paste() gtk_editable_paste_clipboard( GTK_EDITABLE(entry) DUMMY_CLIPBOARD_ARG); } +void wxComboBox::Undo() +{ + // TODO +} + +void wxComboBox::Redo() +{ + // TODO +} + +void wxComboBox::SelectAll() +{ + Select(0, GetLastPosition()); +} + +bool wxComboBox::CanUndo() const +{ + // TODO + return false; +} + +bool wxComboBox::CanRedo() const +{ + // TODO + return false; +} + +bool wxComboBox::HasSelection() const +{ + long from, to; + GetSelection(&from, &to); + return from != to; +} + +bool wxComboBox::CanCopy() const +{ + // Can copy if there's a selection + return HasSelection(); +} + +bool wxComboBox::CanCut() const +{ + return CanCopy() && IsEditable(); +} + +bool wxComboBox::CanPaste() const +{ + // TODO: check for text on the clipboard + return IsEditable() ; +} + +bool wxComboBox::IsEditable() const +{ + return !HasFlag(wxCB_READONLY); +} + + void wxComboBox::SetInsertionPoint( long pos ) { wxCHECK_RET( m_widget != NULL, wxT("invalid combobox") ); @@ -692,6 +765,16 @@ void wxComboBox::SetSelection( long from, long to ) gtk_editable_select_region( GTK_EDITABLE(entry), (gint)from, (gint)to ); } +void wxComboBox::GetSelection( long* from, long* to ) const +{ + if (IsEditable()) + { + GtkEditable *editable = GTK_EDITABLE(GTK_COMBO(m_widget)->entry); + *from = (long) editable->selection_start_pos; + *to = (long) editable->selection_end_pos; + } +} + void wxComboBox::SetEditable( bool editable ) { GtkWidget *entry = GTK_COMBO(m_widget)->entry; @@ -722,7 +805,7 @@ void wxComboBox::OnChar( wxKeyEvent &event ) GtkWindow *window = GTK_WINDOW(top_frame->m_widget); if (window->default_widget) - gtk_widget_activate (window->default_widget); + gtk_widget_activate (window->default_widget); } } @@ -828,4 +911,82 @@ wxComboBox::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) return GetDefaultAttributesFromGTKWidget(gtk_combo_new, true); } +// ---------------------------------------------------------------------------- +// standard event handling +// ---------------------------------------------------------------------------- + +void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event)) +{ + Cut(); +} + +void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event)) +{ + Copy(); +} + +void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event)) +{ + Paste(); +} + +void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event)) +{ + Undo(); +} + +void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event)) +{ + Redo(); +} + +void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event)) +{ + long from, to; + GetSelection(& from, & to); + if (from != -1 && to != -1) + Remove(from, to); +} + +void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event)) +{ + SetSelection(-1, -1); +} + +void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event) +{ + event.Enable( CanCut() ); +} + +void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event) +{ + event.Enable( CanCopy() ); +} + +void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event) +{ + event.Enable( CanPaste() ); +} + +void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event) +{ + event.Enable( CanUndo() ); +} + +void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event) +{ + event.Enable( CanRedo() ); +} + +void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event) +{ + event.Enable(HasSelection() && IsEditable()) ; +} + +void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event) +{ + event.Enable(GetLastPosition() > 0); +} + #endif + diff --git a/src/mac/carbon/combobox.cpp b/src/mac/carbon/combobox.cpp index 196c2e1d3c..070285404f 100644 --- a/src/mac/carbon/combobox.cpp +++ b/src/mac/carbon/combobox.cpp @@ -26,7 +26,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) static int nextPopUpMenuId = 1000 ; -MenuHandle NewUniqueMenu() +MenuHandle NewUniqueMenu() { MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ; nextPopUpMenuId++ ; @@ -75,7 +75,7 @@ protected: NavEvent.SetEventObject(this); NavEvent.SetDirection(true); NavEvent.SetWindowChange(false); - + // Get the parent of the combo and have it process the navigation? if (m_cb->GetParent()->GetEventHandler()->ProcessEvent(NavEvent)) return; @@ -111,7 +111,7 @@ protected: return; } } - + event.Skip(); } @@ -124,7 +124,7 @@ protected: wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_cb->GetId()); event.SetString( GetValue() ); event.SetEventObject( m_cb ); - m_cb->GetEventHandler()->ProcessEvent(event); + m_cb->GetEventHandler()->ProcessEvent(event); } } private: @@ -183,7 +183,7 @@ protected: if (! m_cb->HasFlag(wxCB_READONLY) ) sz.x = GetPopupWidth() ; return sz ; - } + } private: wxComboBox *m_cb; @@ -223,7 +223,7 @@ wxSize wxComboBox::DoGetBestSize() const if (!m_choice && !m_text) return GetSize(); wxSize size = m_choice->GetBestSize(); - + if ( m_text != NULL ) { wxSize sizeText = m_text->GetBestSize(); @@ -241,10 +241,10 @@ wxSize wxComboBox::DoGetBestSize() const return size; } -void wxComboBox::DoMoveWindow(int x, int y, int width, int height) +void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { wxControl::DoMoveWindow(x, y, width , height ); - + if ( m_text == NULL ) { // we might not be fully constructed yet, therefore watch out... @@ -257,7 +257,7 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height) m_text->SetSize(TEXTFOCUSBORDER, TEXTFOCUSBORDER, wText, -1 ); // put it at an inset of 1 to have outer area shadows drawn as well m_choice->SetSize(TEXTFOCUSBORDER + wText + MARGIN - 1 , TEXTFOCUSBORDER, m_choice->GetPopupWidth() , -1); - } + } } @@ -342,15 +342,15 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, else { m_text = new wxComboBoxText(this); - if ( size.y == -1 ) + if ( size.y == -1 ) { csize.y = m_text->GetSize().y ; csize.y += 2 * TEXTFOCUSBORDER ; } } - + DoSetSize(pos.x, pos.y, csize.x, csize.y); - + for ( int i = 0 ; i < n ; i++ ) { m_choice->DoAppend( choices[ i ] ); @@ -364,7 +364,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, wxString wxComboBox::GetValue() const { wxString result; - + if ( m_text == NULL ) { result = m_choice->GetString( m_choice->GetSelection() ); @@ -378,8 +378,8 @@ wxString wxComboBox::GetValue() const } int wxComboBox::GetCount() const -{ - return m_choice->GetCount() ; +{ + return m_choice->GetCount() ; } void wxComboBox::SetValue(const wxString& value) @@ -429,7 +429,7 @@ void wxComboBox::SetEditable(bool editable) int currentX, currentY; GetPosition( ¤tX, ¤tY ); - + int currentW, currentH; GetSize( ¤tW, ¤tH ); @@ -473,17 +473,17 @@ void wxComboBox::SetSelection(long from, long to) // TODO } -int wxComboBox::DoAppend(const wxString& item) +int wxComboBox::DoAppend(const wxString& item) { return m_choice->DoAppend( item ) ; } -int wxComboBox::DoInsert(const wxString& item, int pos) +int wxComboBox::DoInsert(const wxString& item, int pos) { return m_choice->DoInsert( item , pos ) ; } -void wxComboBox::DoSetItemClientData(int n, void* clientData) +void wxComboBox::DoSetItemClientData(int n, void* clientData) { return m_choice->DoSetItemClientData( n , clientData ) ; } @@ -498,7 +498,7 @@ void wxComboBox::DoSetItemClientObject(int n, wxClientData* clientData) return m_choice->DoSetItemClientObject( n , clientData ) ; } -wxClientData* wxComboBox::DoGetItemClientObject(int n) const +wxClientData* wxComboBox::DoGetItemClientObject(int n) const { return m_choice->DoGetItemClientObject( n ) ; } @@ -537,7 +537,7 @@ int wxComboBox::GetSelection() const void wxComboBox::SetSelection(int n) { m_choice->SetSelection( n ); - + if ( m_text != NULL ) { m_text->SetValue( GetString( n ) ); @@ -575,13 +575,75 @@ bool wxComboBox::SetStringSelection(const wxString& sel) return FALSE; } -void wxComboBox::SetString(int n, const wxString& s) +void wxComboBox::SetString(int n, const wxString& s) { m_choice->SetString( n , s ) ; } +bool wxComboBox::IsEditable() const +{ + return m_text != NULL && !HasFlag(wxCB_READONLY); +} + +void wxComboBox::Undo() +{ + if (m_text != NULL) + m_text->Undo(); +} + +void wxComboBox::Redo() +{ + if (m_text != NULL) + m_text->Redo(); +} + +void wxComboBox::SelectAll() +{ + if (m_text != NULL) + m_text->SelectAll(); +} + +bool wxComboBox::CanCopy() const +{ + if (m_text != NULL) + return m_text->CanCopy(); + else + return false; +} + +bool wxComboBox::CanCut() const +{ + if (m_text != NULL) + return m_text->CanCut(); + else + return false; +} + +bool wxComboBox::CanPaste() const +{ + if (m_text != NULL) + return m_text->CanPaste(); + else + return false; +} + +bool wxComboBox::CanUndo() const +{ + if (m_text != NULL) + return m_text->CanUndo(); + else + return false; +} + +bool wxComboBox::CanRedo() const +{ + if (m_text != NULL) + return m_text->CanRedo(); + else + return false; +} -wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { /* For consistency with other platforms, clicking in the text area does not constitute a selection wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); diff --git a/src/mac/carbon/combobxc.cpp b/src/mac/carbon/combobxc.cpp index 8cee1e946e..b26e9741da 100644 --- a/src/mac/carbon/combobxc.cpp +++ b/src/mac/carbon/combobxc.cpp @@ -36,7 +36,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) #endif static int nextPopUpMenuId = 1000 ; -MenuHandle NewUniqueMenu() +MenuHandle NewUniqueMenu() { MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ; nextPopUpMenuId++ ; @@ -53,7 +53,7 @@ static pascal OSStatus wxMacComboBoxEventHandler( EventHandlerCallRef handler , { OSStatus result = eventNotHandledErr ; wxComboBox* cb = (wxComboBox*) data ; - + wxMacCarbonEvent cEvent( event ) ; switch( cEvent.GetClass() ) @@ -77,7 +77,7 @@ static pascal OSStatus wxMacComboBoxEventHandler( EventHandlerCallRef handler , default : break ; } - + return result ; } @@ -169,7 +169,7 @@ protected: return; } } - + event.Skip(); } private: @@ -208,7 +208,7 @@ protected: wxSize sz = wxChoice::DoGetBestSize() ; sz.x = POPUPWIDTH ; return sz ; - } + } private: wxComboBox *m_cb; @@ -249,11 +249,11 @@ wxSize wxComboBox::DoGetBestSize() const return wxControl::DoGetBestSize(); #else wxSize size = m_choice->GetBestSize(); - + if ( m_text != NULL ) { wxSize sizeText = m_text->GetBestSize(); - + size.x = POPUPWIDTH + sizeText.x + MARGIN; } @@ -266,7 +266,7 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { wxControl::DoMoveWindow(x, y, width, height); #else height = POPUPHEIGHT; - + wxControl::DoMoveWindow(x, y, width, height); if ( m_text == NULL ) @@ -281,7 +281,7 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { m_text->SetSize(0, 0, wText, height); m_choice->SetSize(0 + wText + MARGIN, 0, POPUPWIDTH, -1); } -#endif +#endif } @@ -368,12 +368,12 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, #if USE_HICOMBOBOX Rect bounds = wxMacGetBoundsForControl( this , pos , size ) ; HIRect hiRect; - + hiRect.origin.x = 20; //bounds.left; hiRect.origin.y = 25; //bounds.top; hiRect.size.width = 120;// bounds.right - bounds.left; - hiRect.size.height = 24; - + hiRect.size.height = 24; + //For some reason, this code causes the combo box not to be displayed at all. //hiRect.origin.x = bounds.left; //hiRect.origin.y = bounds.top; @@ -383,32 +383,32 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, //printf("x = %d, y = %d, width = %d, height = %d\n", hibounds.origin.x, hibounds.origin.y, hibounds.size.width, hibounds.size.height); m_peer = new wxMacControl() ; verify_noerr( HIComboBoxCreate( &hiRect, CFSTR(""), NULL, NULL, kHIComboBoxStandardAttributes, *m_peer ) ); - + SetControl32BitMinimum( *m_peer , 0 ) ; SetControl32BitMaximum( *m_peer , 100) ; if ( n > 0 ) SetControl32BitValue( *m_peer , 1 ) ; - + MacPostControlCreate(pos,size) ; - + for ( int i = 0 ; i < n ; i++ ) { DoAppend( choices[ i ] ); } - + HIViewSetVisible( *m_peer, true ); SetSelection(0); EventHandlerRef comboEventHandler ; InstallControlEventHandler( *m_peer, GetwxMacComboBoxEventHandlerUPP(), - GetEventTypeCount(eventList), eventList, this, + GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&comboEventHandler); #else m_choice = new wxComboBoxChoice(this, style ); m_choice = new wxComboBoxChoice(this, style ); m_choice->SetSizeHints( wxSize( POPUPWIDTH , POPUPHEIGHT ) ) ; - + wxSize csize = size; if ( style & wxCB_READONLY ) { @@ -421,9 +421,9 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, csize.y = m_text->GetSize().y ; } } - + DoSetSize(pos.x, pos.y, csize.x, csize.y); - + for ( int i = 0 ; i < n ; i++ ) { m_choice->DoAppend( choices[ i ] ); @@ -442,7 +442,7 @@ wxString wxComboBox::GetValue() const return wxMacCFStringHolder( myString, m_font.GetEncoding() ).AsString(); #else wxString result; - + if ( m_text == NULL ) { result = m_choice->GetString( m_choice->GetSelection() ); @@ -451,7 +451,7 @@ wxString wxComboBox::GetValue() const { result = m_text->GetValue(); } - + return result; #endif } @@ -459,7 +459,7 @@ wxString wxComboBox::GetValue() const void wxComboBox::SetValue(const wxString& value) { #if USE_HICOMBOBOX - + #else int s = FindString (value); if (s == wxNOT_FOUND && !HasFlag(wxCB_READONLY) ) @@ -509,7 +509,7 @@ void wxComboBox::SetEditable(bool editable) int currentX, currentY; GetPosition( ¤tX, ¤tY ); - + int currentW, currentH; GetSize( ¤tW, ¤tH ); @@ -553,7 +553,7 @@ void wxComboBox::SetSelection(long from, long to) // TODO } -int wxComboBox::DoAppend(const wxString& item) +int wxComboBox::DoAppend(const wxString& item) { #if USE_HICOMBOBOX CFIndex outIndex; @@ -565,20 +565,20 @@ int wxComboBox::DoAppend(const wxString& item) #endif } -int wxComboBox::DoInsert(const wxString& item, int pos) +int wxComboBox::DoInsert(const wxString& item, int pos) { #if USE_HICOMBOBOX HIComboBoxInsertTextItemAtIndex( *m_peer, (CFIndex)pos, wxMacCFStringHolder(item, m_font.GetEncoding()) ); - + //SetControl32BitMaximum( *m_peer, GetCount() ); - + return pos; #else return m_choice->DoInsert( item , pos ) ; #endif } -void wxComboBox::DoSetItemClientData(int n, void* clientData) +void wxComboBox::DoSetItemClientData(int n, void* clientData) { #if USE_HICOMBOBOX return; //TODO @@ -605,7 +605,7 @@ void wxComboBox::DoSetItemClientObject(int n, wxClientData* clientData) #endif } -wxClientData* wxComboBox::DoGetItemClientObject(int n) const +wxClientData* wxComboBox::DoGetItemClientObject(int n) const { #if USE_HICOMBOBOX return NULL; @@ -630,7 +630,7 @@ int wxComboBox::GetCount() const { #if USE_HICOMBOBOX return (int) HIComboBoxGetItemCount( *m_peer ); #else - return m_choice->GetCount() ; + return m_choice->GetCount() ; #endif } @@ -673,7 +673,7 @@ void wxComboBox::SetSelection(int n) SetControl32BitValue( *m_peer , n + 1 ) ; #else m_choice->SetSelection( n ); - + if ( m_text != NULL ) { m_text->SetValue( GetString( n ) ); @@ -731,10 +731,10 @@ bool wxComboBox::SetStringSelection(const wxString& sel) return FALSE; } -void wxComboBox::SetString(int n, const wxString& s) +void wxComboBox::SetString(int n, const wxString& s) { #if USE_HICOMBOBOX - verify_noerr ( HIComboBoxInsertTextItemAtIndex( *m_peer, (CFIndex) n, + verify_noerr ( HIComboBoxInsertTextItemAtIndex( *m_peer, (CFIndex) n, wxMacCFStringHolder(s, m_font.GetEncoding()) ) ); verify_noerr ( HIComboBoxRemoveItemAtIndex( *m_peer, (CFIndex) n + 1 ) ); #else @@ -742,8 +742,112 @@ void wxComboBox::SetString(int n, const wxString& s) #endif } +bool wxComboBox::IsEditable() const +{ +#if USE_HICOMBOBOX + // TODO + return !HasFlag(wxCB_READONLY); +#else + return m_text != NULL && !HasFlag(wxCB_READONLY); +#endif +} + +void wxComboBox::Undo() +{ +#if USE_HICOMBOBOX + // TODO +#else + if (m_text != NULL) + m_text->Undo(); +#endif +} + +void wxComboBox::Redo() +{ +#if USE_HICOMBOBOX + // TODO +#else + if (m_text != NULL) + m_text->Redo(); +#endif +} + +void wxComboBox::SelectAll() +{ +#if USE_HICOMBOBOX + // TODO +#else + if (m_text != NULL) + m_text->SelectAll(); +#endif +} + +bool wxComboBox::CanCopy() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanCopy(); + else + return false; +#endif +} + +bool wxComboBox::CanCut() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanCut(); + else + return false; +#endif +} + +bool wxComboBox::CanPaste() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanPaste(); + else + return false; +#endif +} + +bool wxComboBox::CanUndo() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanUndo(); + else + return false; +#endif +} + +bool wxComboBox::CanRedo() const +{ +#if USE_HICOMBOBOX + // TODO + return false; +#else + if (m_text != NULL) + return m_text->CanRedo(); + else + return false; +#endif +} -wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) +wxInt32 wxComboBox::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENTREF WXUNUSED(event) ) { wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); event.SetInt(GetSelection()); diff --git a/src/mac/classic/combobox.cpp b/src/mac/classic/combobox.cpp index 27aa1a58de..061a8b165b 100644 --- a/src/mac/classic/combobox.cpp +++ b/src/mac/classic/combobox.cpp @@ -26,7 +26,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) static int nextPopUpMenuId = 1000 ; -MenuHandle NewUniqueMenu() +MenuHandle NewUniqueMenu() { MenuHandle handle = NewMenu( nextPopUpMenuId , "\pMenu" ) ; nextPopUpMenuId++ ; @@ -114,7 +114,7 @@ protected: return; } } - + event.Skip(); } @@ -186,11 +186,11 @@ wxComboBox::~wxComboBox() wxSize wxComboBox::DoGetBestSize() const { wxSize size = m_choice->GetBestSize(); - + if ( m_text != NULL ) { wxSize sizeText = m_text->GetBestSize(); - + size.x = POPUPWIDTH + sizeText.x + MARGIN; } @@ -199,7 +199,7 @@ wxSize wxComboBox::DoGetBestSize() const void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { height = POPUPHEIGHT; - + wxControl::DoMoveWindow(x, y, width, height); if ( m_text == NULL ) @@ -211,7 +211,7 @@ void wxComboBox::DoMoveWindow(int x, int y, int width, int height) { wxCoord wText = width - POPUPWIDTH - MARGIN; m_text->SetSize(0, 0, wText, height); m_choice->SetSize(0 + wText + MARGIN, 0, POPUPWIDTH, -1); - } + } } @@ -301,9 +301,9 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, csize.y = m_text->GetSize().y ; } } - + DoSetSize(pos.x, pos.y, csize.x, csize.y); - + for ( int i = 0 ; i < n ; i++ ) { m_choice->DoAppend( choices[ i ] ); @@ -315,7 +315,7 @@ bool wxComboBox::Create(wxWindow *parent, wxWindowID id, wxString wxComboBox::GetValue() const { wxString result; - + if ( m_text == NULL ) { result = m_choice->GetString( m_choice->GetSelection() ); @@ -377,7 +377,7 @@ void wxComboBox::SetEditable(bool editable) int currentX, currentY; GetPosition( ¤tX, ¤tY ); - + int currentW, currentH; GetSize( ¤tW, ¤tH ); @@ -421,17 +421,17 @@ void wxComboBox::SetSelection(long from, long to) // TODO } -int wxComboBox::DoAppend(const wxString& item) +int wxComboBox::DoAppend(const wxString& item) { return m_choice->DoAppend( item ) ; } -int wxComboBox::DoInsert(const wxString& item, int pos) +int wxComboBox::DoInsert(const wxString& item, int pos) { return m_choice->DoInsert( item , pos ) ; } -void wxComboBox::DoSetItemClientData(int n, void* clientData) +void wxComboBox::DoSetItemClientData(int n, void* clientData) { return m_choice->DoSetItemClientData( n , clientData ) ; } @@ -446,7 +446,7 @@ void wxComboBox::DoSetItemClientObject(int n, wxClientData* clientData) return m_choice->DoSetItemClientObject( n , clientData ) ; } -wxClientData* wxComboBox::DoGetItemClientObject(int n) const +wxClientData* wxComboBox::DoGetItemClientObject(int n) const { return m_choice->DoGetItemClientObject( n ) ; } @@ -485,7 +485,7 @@ int wxComboBox::GetSelection() const void wxComboBox::SetSelection(int n) { m_choice->SetSelection( n ); - + if ( m_text != NULL ) { m_text->SetValue( GetString( n ) ); @@ -523,13 +523,76 @@ bool wxComboBox::SetStringSelection(const wxString& sel) return FALSE; } -void wxComboBox::SetString(int n, const wxString& s) +void wxComboBox::SetString(int n, const wxString& s) { m_choice->SetString( n , s ) ; } +bool wxComboBox::IsEditable() const +{ + + return m_text != NULL && !HasFlag(wxCB_READONLY); +} + +void wxComboBox::Undo() +{ + if (m_text != NULL) + m_text->Undo(); +} + +void wxComboBox::Redo() +{ + if (m_text != NULL) + m_text->Redo(); +} + +void wxComboBox::SelectAll() +{ + if (m_text != NULL) + m_text->SelectAll(); +} + +bool wxComboBox::CanCopy() const +{ + if (m_text != NULL) + return m_text->CanCopy(); + else + return false; +} + +bool wxComboBox::CanCut() const +{ + if (m_text != NULL) + return m_text->CanCut(); + else + return false; +} + +bool wxComboBox::CanPaste() const +{ + if (m_text != NULL) + return m_text->CanPaste(); + else + return false; +} + +bool wxComboBox::CanUndo() const +{ + if (m_text != NULL) + return m_text->CanUndo(); + else + return false; +} + +bool wxComboBox::CanRedo() const +{ + if (m_text != NULL) + return m_text->CanRedo(); + else + return false; +} -void wxComboBox::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown)) +void wxComboBox::MacHandleControlClick( WXWidget WXUNUSED(control) , wxInt16 WXUNUSED(controlpart) , bool WXUNUSED(mouseStillDown)) { wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId ); event.SetInt(GetSelection()); diff --git a/src/msw/combobox.cpp b/src/msw/combobox.cpp index c14341c001..c07ac7bee0 100644 --- a/src/msw/combobox.cpp +++ b/src/msw/combobox.cpp @@ -111,6 +111,25 @@ wxEND_HANDLERS_TABLE() wxCONSTRUCTOR_5( wxComboBox , wxWindow* , Parent , wxWindowID , Id , wxString , Value , wxPoint , Position , wxSize , Size ) #else IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) + +BEGIN_EVENT_TABLE(wxComboBox, wxControl) + EVT_MENU(wxID_CUT, wxComboBox::OnCut) + EVT_MENU(wxID_COPY, wxComboBox::OnCopy) + EVT_MENU(wxID_PASTE, wxComboBox::OnPaste) + EVT_MENU(wxID_UNDO, wxComboBox::OnUndo) + EVT_MENU(wxID_REDO, wxComboBox::OnRedo) + EVT_MENU(wxID_CLEAR, wxComboBox::OnDelete) + EVT_MENU(wxID_SELECTALL, wxComboBox::OnSelectAll) + + EVT_UPDATE_UI(wxID_CUT, wxComboBox::OnUpdateCut) + EVT_UPDATE_UI(wxID_COPY, wxComboBox::OnUpdateCopy) + EVT_UPDATE_UI(wxID_PASTE, wxComboBox::OnUpdatePaste) + EVT_UPDATE_UI(wxID_UNDO, wxComboBox::OnUpdateUndo) + EVT_UPDATE_UI(wxID_REDO, wxComboBox::OnUpdateRedo) + EVT_UPDATE_UI(wxID_CLEAR, wxComboBox::OnUpdateDelete) + EVT_UPDATE_UI(wxID_SELECTALL, wxComboBox::OnUpdateSelectAll) +END_EVENT_TABLE() + #endif // ---------------------------------------------------------------------------- @@ -464,17 +483,99 @@ void wxComboBox::SetValue(const wxString& value) // Clipboard operations void wxComboBox::Copy() { - SendMessage(GetHwnd(), WM_COPY, 0, 0L); + SendMessage(GetHwnd(), WM_COPY, 0, 0L); } void wxComboBox::Cut() { - SendMessage(GetHwnd(), WM_CUT, 0, 0L); + SendMessage(GetHwnd(), WM_CUT, 0, 0L); } void wxComboBox::Paste() { - SendMessage(GetHwnd(), WM_PASTE, 0, 0L); + SendMessage(GetHwnd(), WM_PASTE, 0, 0L); +} + +void wxComboBox::Undo() +{ + if (CanUndo()) + { + HWND hEditWnd = (HWND) GetEditHWND() ; + if ( hEditWnd ) + ::SendMessage(hEditWnd, EM_UNDO, 0, 0); + } +} + +void wxComboBox::Redo() +{ + if (CanUndo()) + { + // Same as Undo, since Undo undoes the undo, i.e. a redo. + HWND hEditWnd = (HWND) GetEditHWND() ; + if ( hEditWnd ) + ::SendMessage(hEditWnd, EM_UNDO, 0, 0); + } +} + +void wxComboBox::SelectAll() +{ + SetSelection(0, GetLastPosition()); +} + +bool wxComboBox::CanUndo() const +{ + HWND hEditWnd = (HWND) GetEditHWND() ; + if ( hEditWnd ) + return ::SendMessage(hEditWnd, EM_CANUNDO, 0, 0) != 0; + else + return false; +} + +bool wxComboBox::CanRedo() const +{ + HWND hEditWnd = (HWND) GetEditHWND() ; + if ( hEditWnd ) + return ::SendMessage(hEditWnd, EM_CANUNDO, 0, 0) != 0; + else + return false; +} + +bool wxComboBox::HasSelection() const +{ + long from, to; + GetSelection(&from, &to); + return from != to; +} + +bool wxComboBox::CanCopy() const +{ + // Can copy if there's a selection + return HasSelection(); +} + +bool wxComboBox::CanCut() const +{ + return CanCopy() && IsEditable(); +} + +bool wxComboBox::CanPaste() const +{ + if ( !IsEditable() ) + return false; + + // Standard edit control: check for straight text on clipboard + if ( !::OpenClipboard(GetHwndOf(wxTheApp->GetTopWindow())) ) + return false; + + bool isTextAvailable = ::IsClipboardFormatAvailable(CF_TEXT) != 0; + ::CloseClipboard(); + + return isTextAvailable; +} + +bool wxComboBox::IsEditable() const +{ + return !HasFlag(wxCB_READONLY); } void wxComboBox::SetEditable(bool WXUNUSED(editable)) @@ -588,5 +689,82 @@ int wxComboBox::GetSelection() const return wxChoice::GetSelection(); } +// ---------------------------------------------------------------------------- +// standard event handling +// ---------------------------------------------------------------------------- + +void wxComboBox::OnCut(wxCommandEvent& WXUNUSED(event)) +{ + Cut(); +} + +void wxComboBox::OnCopy(wxCommandEvent& WXUNUSED(event)) +{ + Copy(); +} + +void wxComboBox::OnPaste(wxCommandEvent& WXUNUSED(event)) +{ + Paste(); +} + +void wxComboBox::OnUndo(wxCommandEvent& WXUNUSED(event)) +{ + Undo(); +} + +void wxComboBox::OnRedo(wxCommandEvent& WXUNUSED(event)) +{ + Redo(); +} + +void wxComboBox::OnDelete(wxCommandEvent& WXUNUSED(event)) +{ + long from, to; + GetSelection(& from, & to); + if (from != -1 && to != -1) + Remove(from, to); +} + +void wxComboBox::OnSelectAll(wxCommandEvent& WXUNUSED(event)) +{ + SetSelection(-1, -1); +} + +void wxComboBox::OnUpdateCut(wxUpdateUIEvent& event) +{ + event.Enable( CanCut() ); +} + +void wxComboBox::OnUpdateCopy(wxUpdateUIEvent& event) +{ + event.Enable( CanCopy() ); +} + +void wxComboBox::OnUpdatePaste(wxUpdateUIEvent& event) +{ + event.Enable( CanPaste() ); +} + +void wxComboBox::OnUpdateUndo(wxUpdateUIEvent& event) +{ + event.Enable( CanUndo() ); +} + +void wxComboBox::OnUpdateRedo(wxUpdateUIEvent& event) +{ + event.Enable( CanRedo() ); +} + +void wxComboBox::OnUpdateDelete(wxUpdateUIEvent& event) +{ + event.Enable(HasSelection() && IsEditable()) ; +} + +void wxComboBox::OnUpdateSelectAll(wxUpdateUIEvent& event) +{ + event.Enable(GetLastPosition() > 0); +} + #endif // wxUSE_COMBOBOX diff --git a/src/palmos/combobox.cpp b/src/palmos/combobox.cpp index 9f11f13fd2..d75825c416 100644 --- a/src/palmos/combobox.cpp +++ b/src/palmos/combobox.cpp @@ -4,7 +4,7 @@ // Author: William Osborne // Modified by: // Created: 10/13/04 -// RCS-ID: $Id: +// RCS-ID: $Id: // Copyright: (c) William Osborne // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -65,7 +65,7 @@ wxBEGIN_FLAGS( wxComboBoxStyle ) wxFLAGS_MEMBER(wxBORDER_RAISED) wxFLAGS_MEMBER(wxBORDER_STATIC) wxFLAGS_MEMBER(wxBORDER_NONE) - + // old style border flags wxFLAGS_MEMBER(wxSIMPLE_BORDER) wxFLAGS_MEMBER(wxSUNKEN_BORDER) @@ -261,5 +261,48 @@ void wxComboBox::SetSelection(long from, long to) { } +bool wxComboBox::IsEditable() const +{ + return false; +} + +void wxComboBox::Undo() +{ +} + +void wxComboBox::Redo() +{ +} + +void wxComboBox::SelectAll() +{ +} + +bool wxComboBox::CanCopy() const +{ + return false; +} + +bool wxComboBox::CanCut() const +{ + return false; +} + +bool wxComboBox::CanPaste() const +{ + return false; +} + +bool wxComboBox::CanUndo() const +{ + return false; +} + +bool wxComboBox::CanRedo() const +{ + return false; +} + + #endif // wxUSE_COMBOBOX diff --git a/src/univ/combobox.cpp b/src/univ/combobox.cpp index 6e6db1fce3..20a06a61d4 100644 --- a/src/univ/combobox.cpp +++ b/src/univ/combobox.cpp @@ -310,7 +310,7 @@ wxSize wxComboControl::DoGetBestClientSize() const widthPopup = m_popup->GetBestWidth(); } - return wxSize(wxMax(sizeText.x + g_comboMargin + sizeBtn.x, widthPopup), + return wxSize(wxMax(sizeText.x + g_comboMargin + sizeBtn.x, widthPopup), wxMax(sizeBtn.y, sizeText.y)); } @@ -365,7 +365,7 @@ bool wxComboControl::Show(bool show) #if wxUSE_TOOLTIPS void wxComboControl::DoSetToolTip(wxToolTip *tooltip) { - wxControl::DoSetToolTip(tooltip); + wxControl::DoSetToolTip(tooltip); // Set tool tip for button and text box if (m_text && m_btn) @@ -845,9 +845,9 @@ int wxComboBox::GetSelection() const #if 1 // FIXME:: What is the correct behavior? // if the current value isn't one of the listbox strings, return -1 return GetLBox()->GetSelection(); -#else - // Why oh why is this done this way? - // It is not because the value displayed in the text can be found +#else + // Why oh why is this done this way? + // It is not because the value displayed in the text can be found // in the list that it is the item that is selected! return FindString(GetText()->GetValue()); #endif @@ -890,6 +890,69 @@ wxClientData* wxComboBox::DoGetItemClientObject(int n) const return GetLBox()->GetClientObject(n); } +bool wxComboBox::IsEditable() const +{ + return GetText() != NULL && (!HasFlag(wxCB_READONLY) || GetText()->IsEditable()); +} + +void wxComboBox::Undo() +{ + if (IsEditable()) + GetText()->Undo(); +} + +void wxComboBox::Redo() +{ + if (IsEditable()) + GetText()->Redo(); +} + +void wxComboBox::SelectAll() +{ + GetText()->SelectAll(); +} + +bool wxComboBox::CanCopy() const +{ + if (GetText() != NULL) + return GetText()->CanCopy(); + else + return false; +} + +bool wxComboBox::CanCut() const +{ + if (GetText() != NULL) + return GetText()->CanCut(); + else + return false; +} + +bool wxComboBox::CanPaste() const +{ + if (IsEditable()) + return GetText()->CanPaste(); + else + return false; +} + +bool wxComboBox::CanUndo() const +{ + if (IsEditable()) + return GetText()->CanUndo(); + else + return false; +} + +bool wxComboBox::CanRedo() const +{ + if (IsEditable()) + return GetText()->CanRedo(); + else + return false; +} + + // ---------------------------------------------------------------------------- // input handling // ---------------------------------------------------------------------------- -- 2.45.2