From 895e26a04bb70facbc8d6bb54c1da8a872725557 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Sun, 11 Jul 2010 16:06:03 +0000 Subject: [PATCH] Have the new incarnation of wxPGArrayEditorDialog support the old-style 'custom button' event as something that happens when the wxEditableListBox's 'New Item' button is pressed git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64893 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/propgrid/props.h | 29 +++++++++++++++++---------- src/propgrid/props.cpp | 40 ++++++++++++++++++++++++------------- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/include/wx/propgrid/props.h b/include/wx/propgrid/props.h index c22e3f50b3..5eeb376e4f 100644 --- a/include/wx/propgrid/props.h +++ b/include/wx/propgrid/props.h @@ -867,6 +867,11 @@ public: const wxPoint& pos = wxDefaultPosition, const wxSize& sz = wxDefaultSize ); + void EnableCustomNewAction() + { + m_hasCustomNewAction = true; + } + /** Set value modified by dialog. */ virtual void SetDialogValue( const wxVariant& WXUNUSED(value) ) @@ -901,8 +906,6 @@ public: // wxEditableListBox utilities int GetSelection() const; - //const wxArrayString& GetStrings() const { return m_array; } - // implementation from now on void OnAddClick(wxCommandEvent& event); void OnDeleteClick(wxCommandEvent& event); @@ -913,21 +916,17 @@ public: protected: wxEditableListBox* m_elb; - wxButton* m_butCustom; // required for disabling/enabling changing. - wxButton* m_butUp; - wxButton* m_butDown; // These are used for focus repair wxWindow* m_elbSubPanel; wxWindow* m_lastFocused; - const wxChar* m_custBtText; - // A new item, edited by user, is pending at this index. // It will be committed once list ctrl item editing is done. int m_itemPendingAtIndex; bool m_modified; + bool m_hasCustomNewAction; // These must be overridden - must return true on success. virtual wxString ArrayGet( size_t index ) = 0; @@ -936,6 +935,10 @@ protected: virtual bool ArraySet( size_t index, const wxString& str ) = 0; virtual void ArrayRemoveAt( int index ) = 0; virtual void ArraySwap( size_t first, size_t second ) = 0; + virtual bool OnCustomNewAction(wxString* WXUNUSED(resString)) + { + return false; + } private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog) @@ -967,13 +970,17 @@ public: return m_array; } - void SetCustomButton( const wxChar* custBtText, wxArrayStringProperty* pcc ) + void SetCustomButton( const wxString& custBtText, + wxArrayStringProperty* pcc ) { - m_custBtText = custBtText; - m_pCallingClass = pcc; + if ( custBtText.length() ) + { + EnableCustomNewAction(); + m_pCallingClass = pcc; + } } - void OnCustomEditClick(wxCommandEvent& event); + virtual bool OnCustomNewAction(wxString* resString); protected: wxArrayString m_array; diff --git a/src/propgrid/props.cpp b/src/propgrid/props.cpp index 42a03bc5cc..b21beda0d4 100644 --- a/src/propgrid/props.cpp +++ b/src/propgrid/props.cpp @@ -2053,8 +2053,8 @@ wxPGArrayEditorDialog::wxPGArrayEditorDialog() void wxPGArrayEditorDialog::Init() { - m_custBtText = NULL; m_lastFocused = NULL; + m_hasCustomNewAction = false; m_itemPendingAtIndex = -1; } @@ -2196,9 +2196,29 @@ int wxPGArrayEditorDialog::GetSelection() const void wxPGArrayEditorDialog::OnAddClick(wxCommandEvent& event) { wxListCtrl* lc = m_elb->GetListCtrl(); - m_itemPendingAtIndex = lc->GetItemCount() - 1; + int newItemIndex = lc->GetItemCount() - 1; - event.Skip(); + if ( m_hasCustomNewAction ) + { + wxString str; + if ( OnCustomNewAction(&str) ) + { + if ( ArrayInsert(str, newItemIndex) ) + { + lc->InsertItem(newItemIndex, str); + m_modified = true; + } + } + + // Do *not* skip the event! We do not want the wxEditableListBox + // to do anything. + } + else + { + m_itemPendingAtIndex = newItemIndex; + + event.Skip(); + } } // ----------------------------------------------------------------------- @@ -2293,7 +2313,6 @@ void wxPGArrayEditorDialog::OnEndLabelEdit(wxListEvent& event) IMPLEMENT_DYNAMIC_CLASS(wxPGArrayStringEditorDialog, wxPGArrayEditorDialog) BEGIN_EVENT_TABLE(wxPGArrayStringEditorDialog, wxPGArrayEditorDialog) - EVT_BUTTON(28, wxPGArrayStringEditorDialog::OnCustomEditClick) END_EVENT_TABLE() // ----------------------------------------------------------------------- @@ -2347,17 +2366,10 @@ void wxPGArrayStringEditorDialog::Init() m_pCallingClass = NULL; } -void wxPGArrayStringEditorDialog::OnCustomEditClick(wxCommandEvent& ) +bool +wxPGArrayStringEditorDialog::OnCustomNewAction(wxString* resString) { - /*wxASSERT( m_pCallingClass ); - wxString str = m_edValue->GetValue(); - if ( m_pCallingClass->OnCustomStringEdit(m_parent,str) ) - { - //m_edValue->SetValue ( str ); - m_lbStrings->Append ( str ); - m_array.Add ( str ); - m_modified = true; - }*/ + return m_pCallingClass->OnCustomStringEdit(m_parent, *resString); } // ----------------------------------------------------------------------- -- 2.47.2