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
This commit is contained in:
Jaakko Salli
2010-07-11 16:06:03 +00:00
parent 6dc6bcd8ab
commit 895e26a04b
2 changed files with 44 additions and 25 deletions

View File

@@ -867,6 +867,11 @@ public:
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& sz = wxDefaultSize ); const wxSize& sz = wxDefaultSize );
void EnableCustomNewAction()
{
m_hasCustomNewAction = true;
}
/** Set value modified by dialog. /** Set value modified by dialog.
*/ */
virtual void SetDialogValue( const wxVariant& WXUNUSED(value) ) virtual void SetDialogValue( const wxVariant& WXUNUSED(value) )
@@ -901,8 +906,6 @@ public:
// wxEditableListBox utilities // wxEditableListBox utilities
int GetSelection() const; int GetSelection() const;
//const wxArrayString& GetStrings() const { return m_array; }
// implementation from now on // implementation from now on
void OnAddClick(wxCommandEvent& event); void OnAddClick(wxCommandEvent& event);
void OnDeleteClick(wxCommandEvent& event); void OnDeleteClick(wxCommandEvent& event);
@@ -913,21 +916,17 @@ public:
protected: protected:
wxEditableListBox* m_elb; wxEditableListBox* m_elb;
wxButton* m_butCustom; // required for disabling/enabling changing.
wxButton* m_butUp;
wxButton* m_butDown;
// These are used for focus repair // These are used for focus repair
wxWindow* m_elbSubPanel; wxWindow* m_elbSubPanel;
wxWindow* m_lastFocused; wxWindow* m_lastFocused;
const wxChar* m_custBtText;
// A new item, edited by user, is pending at this index. // A new item, edited by user, is pending at this index.
// It will be committed once list ctrl item editing is done. // It will be committed once list ctrl item editing is done.
int m_itemPendingAtIndex; int m_itemPendingAtIndex;
bool m_modified; bool m_modified;
bool m_hasCustomNewAction;
// These must be overridden - must return true on success. // These must be overridden - must return true on success.
virtual wxString ArrayGet( size_t index ) = 0; virtual wxString ArrayGet( size_t index ) = 0;
@@ -936,6 +935,10 @@ protected:
virtual bool ArraySet( size_t index, const wxString& str ) = 0; virtual bool ArraySet( size_t index, const wxString& str ) = 0;
virtual void ArrayRemoveAt( int index ) = 0; virtual void ArrayRemoveAt( int index ) = 0;
virtual void ArraySwap( size_t first, size_t second ) = 0; virtual void ArraySwap( size_t first, size_t second ) = 0;
virtual bool OnCustomNewAction(wxString* WXUNUSED(resString))
{
return false;
}
private: private:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog) DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog)
@@ -967,13 +970,17 @@ public:
return m_array; return m_array;
} }
void SetCustomButton( const wxChar* custBtText, wxArrayStringProperty* pcc ) void SetCustomButton( const wxString& custBtText,
wxArrayStringProperty* pcc )
{ {
m_custBtText = custBtText; if ( custBtText.length() )
m_pCallingClass = pcc; {
EnableCustomNewAction();
m_pCallingClass = pcc;
}
} }
void OnCustomEditClick(wxCommandEvent& event); virtual bool OnCustomNewAction(wxString* resString);
protected: protected:
wxArrayString m_array; wxArrayString m_array;

View File

@@ -2053,8 +2053,8 @@ wxPGArrayEditorDialog::wxPGArrayEditorDialog()
void wxPGArrayEditorDialog::Init() void wxPGArrayEditorDialog::Init()
{ {
m_custBtText = NULL;
m_lastFocused = NULL; m_lastFocused = NULL;
m_hasCustomNewAction = false;
m_itemPendingAtIndex = -1; m_itemPendingAtIndex = -1;
} }
@@ -2196,9 +2196,29 @@ int wxPGArrayEditorDialog::GetSelection() const
void wxPGArrayEditorDialog::OnAddClick(wxCommandEvent& event) void wxPGArrayEditorDialog::OnAddClick(wxCommandEvent& event)
{ {
wxListCtrl* lc = m_elb->GetListCtrl(); 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) IMPLEMENT_DYNAMIC_CLASS(wxPGArrayStringEditorDialog, wxPGArrayEditorDialog)
BEGIN_EVENT_TABLE(wxPGArrayStringEditorDialog, wxPGArrayEditorDialog) BEGIN_EVENT_TABLE(wxPGArrayStringEditorDialog, wxPGArrayEditorDialog)
EVT_BUTTON(28, wxPGArrayStringEditorDialog::OnCustomEditClick)
END_EVENT_TABLE() END_EVENT_TABLE()
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -2347,17 +2366,10 @@ void wxPGArrayStringEditorDialog::Init()
m_pCallingClass = NULL; m_pCallingClass = NULL;
} }
void wxPGArrayStringEditorDialog::OnCustomEditClick(wxCommandEvent& ) bool
wxPGArrayStringEditorDialog::OnCustomNewAction(wxString* resString)
{ {
/*wxASSERT( m_pCallingClass ); return m_pCallingClass->OnCustomStringEdit(m_parent, *resString);
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;
}*/
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------