Added multiple selection feature to wxPropertyGrid (enabled by setting wxPG_EX_MULTIPLE_SELECTION style)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61681 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2009-08-17 18:36:00 +00:00
parent 17a5460272
commit fc72fab6c6
15 changed files with 663 additions and 197 deletions

View File

@@ -491,6 +491,12 @@ public:
*/
bool IsPageModified( size_t index ) const;
/**
Returns true if property is selected. Since selection is page
based, this function checks every page in the manager.
*/
virtual bool IsPropertySelected( wxPGPropArg id ) const;
virtual void Refresh( bool eraseBackground = true,
const wxRect* rect = (const wxRect*) NULL );

View File

@@ -435,7 +435,11 @@ wxPG_PROP_CLASS_SPECIFIC_1 = 0x00080000,
/** Indicates the bit useable by derived properties.
*/
wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000
wxPG_PROP_CLASS_SPECIFIC_2 = 0x00100000,
/** Indicates that the property is being deleted and should be ignored.
*/
wxPG_PROP_BEING_DELETED = 0x00200000
};

View File

@@ -247,7 +247,20 @@ wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES = 0x00400000,
/** Hides page selection buttons from toolbar.
*/
wxPG_EX_HIDE_PAGE_BUTTONS = 0x01000000
wxPG_EX_HIDE_PAGE_BUTTONS = 0x01000000,
/** Allows multiple properties to be selected by user (by pressing SHIFT
when clicking on a property, or by dragging with left mouse button
down).
You can get array of selected properties with
wxPropertyGridInterface::GetSelectedProperties(). In multiple selection
mode wxPropertyGridInterface::GetSelection() returns
property which has editor active (usually the first one
selected). Other useful member functions are ClearSelection(),
AddToSelection() and RemoveFromSelection().
*/
wxPG_EX_MULTIPLE_SELECTION = 0x02000000
};
@@ -839,12 +852,6 @@ public:
/** Returns currently selected property. */
wxPGProperty* GetSelectedProperty() const { return GetSelection(); }
/** Returns currently selected property. */
wxPGProperty* GetSelection() const
{
return m_selected;
}
/** Returns current selection background colour. */
wxColour GetSelectionBackgroundColour() const { return m_colSelBack; }
@@ -953,10 +960,46 @@ public:
wxEVT_PG_SELECTED. In wxWidgets 2.9 and later, it no longer
does that.
@see wxPropertyGrid::Unselect
@remarks This clears any previous selection.
*/
bool SelectProperty( wxPGPropArg id, bool focus = false );
/**
Set entire new selection from given list of properties.
*/
void SetSelection( const wxArrayPGProperty& newSelection )
{
DoSetSelection( newSelection, wxPG_SEL_DONT_SEND_EVENT );
}
/**
Adds given property into selection. If wxPG_EX_MULTIPLE_SELECTION
extra style is not used, then this has same effect as
calling SelectProperty().
@remarks Multiple selection is not supported for categories. This
means that if you have properties selected, you cannot
add category to selection, and also if you have category
selected, you cannot add other properties to selection.
This member function will fail silently in these cases,
even returning true.
*/
bool AddToSelection( wxPGPropArg id )
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
return DoAddToSelection(p, wxPG_SEL_DONT_SEND_EVENT);
}
/**
Removes given property from selection. If property is not selected,
an assertion failure will occur.
*/
bool RemoveFromSelection( wxPGPropArg id )
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
return DoRemoveFromSelection(p, wxPG_SEL_DONT_SEND_EVENT);
}
/** Sets category caption background colour. */
void SetCaptionBackgroundColour(const wxColour& col);
@@ -1443,7 +1486,6 @@ public:
//
// Public methods for semi-public use
// (not protected for optimization)
//
bool DoSelectProperty( wxPGProperty* p, unsigned int flags = 0 );
@@ -1635,12 +1677,6 @@ protected:
/** When drawing next time, clear this many item slots at the end. */
int m_clearThisMany;
/** Pointer to selected property. Note that this is duplicated in
m_state for better transiency between pages so that the selected
item can be retained.
*/
wxPGProperty* m_selected;
// pointer to property that has mouse hovering
wxPGProperty* m_propHover;
@@ -1767,6 +1803,10 @@ protected:
protected:
bool AddToSelectionFromInputEvent( wxPGProperty* prop,
wxMouseEvent* event = NULL,
int selFlags = 0 );
/**
Adjust the centering of the bitmap icons (collapse / expand) when the
caption font changes.
@@ -1786,14 +1826,6 @@ protected:
*/
void CorrectEditorWidgetPosY();
/** Deselect current selection, if any. Returns true if success
(ie. validator did not intercept).
Unlike ClearSelection(), DoClearSelection() sends the
wxEVT_PG_SELECTED event.
*/
bool DoClearSelection();
int DoDrawItems( wxDC& dc,
const wxRect* clipRect,
bool isBuffered ) const;
@@ -1826,6 +1858,15 @@ protected:
bool DoEditorValidate();
void DoSetSelection( const wxArrayPGProperty& newSelection,
int selFlags = 0 );
bool DoAddToSelection( wxPGProperty* prop,
int selFlags = 0 );
bool DoRemoveFromSelection( wxPGProperty* prop,
int selFlags = 0 );
wxPGProperty* DoGetItemAtY( int y ) const;
void DoSetSplitterPosition_( int newxpos,

View File

@@ -591,10 +591,23 @@ public:
}
#endif
/** Returns currently selected property. */
wxPGProperty* GetSelection() const
/**
Returns currently selected property. NULL if none.
@remarks When wxPG_EX_MULTIPLE_SELECTION extra style is used, this
member function returns the focused property, that is the
one which can have active editor.
*/
wxPGProperty* GetSelection() const;
/**
Returns list of currently selected properties.
@remarks wxArrayPGProperty should be compatible with std::vector API.
*/
const wxArrayPGProperty& GetSelectedProperties() const
{
return m_pState->GetSelection();
return m_pState->m_selection;
}
#ifndef SWIG
@@ -724,10 +737,19 @@ public:
return ( (p->GetFlags() & wxPG_PROP_MODIFIED) ? true : false );
}
/**
Returns true if property is selected.
*/
bool IsPropertySelected( wxPGPropArg id ) const
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
return m_pState->DoIsPropertySelected(p);
}
/**
Returns true if property is shown (ie hideproperty with true not
called for it).
*/
*/
bool IsPropertyShown( wxPGPropArg id ) const
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
@@ -1269,6 +1291,9 @@ public:
protected:
bool DoClearSelection( bool validation = false,
int selFlags = 0 );
/**
In derived class, implement to set editable state component with
given name to given value.

View File

@@ -475,11 +475,6 @@ public:
return (unsigned int) m_colWidths.size();
}
wxPGProperty* GetSelection() const
{
return m_selected;
}
int GetColumnMinWidth( int column ) const;
int GetColumnWidth( unsigned int column ) const
@@ -500,6 +495,28 @@ public:
return ((wxPropertyGridPageState*)this)->GetLastItem(flags);
}
/**
Returns currently selected property.
*/
wxPGProperty* GetSelection() const
{
if ( m_selection.size() == 0 )
return NULL;
return m_selection[0];
}
void DoSetSelection( wxPGProperty* prop )
{
m_selection.clear();
if ( prop )
m_selection.push_back(prop);
}
bool DoClearSelection()
{
return DoSelectProperty(NULL);
}
wxPropertyCategory* GetPropertyCategory( const wxPGProperty* p ) const;
wxPGProperty* GetPropertyByLabel( const wxString& name,
@@ -590,8 +607,6 @@ public:
bool PrepareAfterItemsAdded();
void SetSelection( wxPGProperty* p ) { m_selected = p; }
/** Called after virtual height needs to be recalculated.
*/
void VirtualHeightChanged()
@@ -605,14 +620,11 @@ public:
/** Returns property by its name. */
wxPGProperty* BaseGetPropertyByName( const wxString& name ) const;
void DoClearSelection()
{
m_selected = NULL;
}
/** Called in, for example, wxPropertyGrid::Clear. */
void DoClear();
bool DoIsPropertySelected( wxPGProperty* prop ) const;
bool DoCollapse( wxPGProperty* p );
bool DoExpand( wxPGProperty* p );
@@ -659,8 +671,8 @@ protected:
/** Most recently added category. */
wxPropertyCategory* m_currentCategory;
/** Pointer to selected property. */
wxPGProperty* m_selected;
/** Array of selected property. */
wxArrayPGProperty m_selection;
/** Virtual width. */
int m_width;