Do not generate wxEVT_PG_SELECTED with direct ClearSelection() and SelectProperty() calls

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61644 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2009-08-11 16:53:05 +00:00
parent 90666795d4
commit 01b5ad3b50
7 changed files with 84 additions and 38 deletions

View File

@@ -448,6 +448,8 @@ enum wxPG_KEYBOARD_ACTIONS
#define wxPG_SEL_SETUNSPEC 0x20 #define wxPG_SEL_SETUNSPEC 0x20
// Property's event handler changed the value // Property's event handler changed the value
#define wxPG_SEL_DIALOGVAL 0x40 #define wxPG_SEL_DIALOGVAL 0x40
// Set to disable sending of wxEVT_PG_SELECTED event
#define wxPG_SEL_DONT_SEND_EVENT 0x80
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -542,8 +544,11 @@ enum wxPG_KEYBOARD_ACTIONS
@beginEventTable{wxPropertyGridEvent} @beginEventTable{wxPropertyGridEvent}
@event{EVT_PG_SELECTED (id, func)} @event{EVT_PG_SELECTED (id, func)}
Respond to wxEVT_PG_SELECTED event, generated when property value Respond to wxEVT_PG_SELECTED event, generated when a property selection
has been changed by user. has been changed, either by user action or by indirect program
function. For instance, collapsing a parent property programmatically
causes any selected child property to become unselected, and may
therefore cause this event to be generated.
@event{EVT_PG_CHANGING(id, func)} @event{EVT_PG_CHANGING(id, func)}
Respond to wxEVT_PG_CHANGING event, generated when property value Respond to wxEVT_PG_CHANGING event, generated when property value
is about to be changed by user. Use wxPropertyGridEvent::GetValue() is about to be changed by user. Use wxPropertyGridEvent::GetValue()
@@ -935,19 +940,22 @@ public:
/** /**
Selects a property. Selects a property.
Editor widget is automatically created, but not focused unless focus is Editor widget is automatically created, but not focused unless focus is
true. This will generate wxEVT_PG_SELECT event. true.
@param id @param id
Property to select. Property to select.
@return @return
True if selection finished successfully. Usually only fails if True if selection finished successfully. Usually only fails if
current value in editor is not valid. current value in editor is not valid.
@remarks In wxPropertyGrid 1.4, this member function used to generate
wxEVT_PG_SELECTED. In wxWidgets 2.9 and later, it no longer
does that.
@see wxPropertyGrid::Unselect @see wxPropertyGrid::Unselect
*/ */
bool SelectProperty( wxPGPropArg id, bool focus = false ) bool SelectProperty( wxPGPropArg id, bool focus = false );
{
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
return DoSelectProperty(p,focus?wxPG_SEL_FOCUS:0);
}
/** Sets category caption background colour. */ /** Sets category caption background colour. */
void SetCaptionBackgroundColour(const wxColour& col); void SetCaptionBackgroundColour(const wxColour& col);
@@ -1779,7 +1787,11 @@ protected:
void CorrectEditorWidgetPosY(); void CorrectEditorWidgetPosY();
/** Deselect current selection, if any. Returns true if success /** Deselect current selection, if any. Returns true if success
(ie. validator did not intercept). */ (ie. validator did not intercept).
Unlike ClearSelection(), DoClearSelection() sends the
wxEVT_PG_SELECTED event.
*/
bool DoClearSelection(); bool DoClearSelection();
int DoDrawItems( wxDC& dc, int DoDrawItems( wxDC& dc,

View File

@@ -210,6 +210,10 @@ public:
@return Returns @true if successful or if there was no selection. May @return Returns @true if successful or if there was no selection. May
fail if validation was enabled and active editor had invalid fail if validation was enabled and active editor had invalid
value. value.
@remarks In wxPropertyGrid 1.4, this member function used to send
wxPG_EVT_SELECTED. In wxWidgets 2.9 and later, it no longer
does that.
*/ */
bool ClearSelection( bool validation = false ); bool ClearSelection( bool validation = false );

View File

@@ -411,7 +411,12 @@ public:
/** Select and displays a given page. */ /** Select and displays a given page. */
void SelectPage( wxPropertyGridPage* page ); void SelectPage( wxPropertyGridPage* page );
/** Select a property. */ /**
Select a property.
@see wxPropertyGrid::SelectProperty(),
wxPropertyGridInterface::ClearSelection()
*/
bool SelectProperty( wxPGPropArg id, bool focus = false ); bool SelectProperty( wxPGPropArg id, bool focus = false );
/** /**

View File

@@ -320,8 +320,11 @@ typedef int (*wxPGSortCallback)(wxPropertyGrid* propGrid,
@beginEventEmissionTable{wxPropertyGridEvent} @beginEventEmissionTable{wxPropertyGridEvent}
@event{EVT_PG_SELECTED (id, func)} @event{EVT_PG_SELECTED (id, func)}
Respond to wxEVT_PG_SELECTED event, generated when property value Respond to wxEVT_PG_SELECTED event, generated when a property selection
has been changed by user. has been changed, either by user action or by indirect program
function. For instance, collapsing a parent property programmatically
causes any selected child property to become unselected, and may
therefore cause this event to be generated.
@event{EVT_PG_CHANGING(id, func)} @event{EVT_PG_CHANGING(id, func)}
Respond to wxEVT_PG_CHANGING event, generated when property value Respond to wxEVT_PG_CHANGING event, generated when property value
is about to be changed by user. Use wxPropertyGridEvent::GetValue() is about to be changed by user. Use wxPropertyGridEvent::GetValue()
@@ -707,8 +710,7 @@ public:
/** /**
Selects a property. Editor widget is automatically created, but Selects a property. Editor widget is automatically created, but
not focused unless focus is true. This will generate wxEVT_PG_SELECT not focused unless focus is true.
event.
@param id @param id
Property to select (name or pointer). Property to select (name or pointer).
@@ -719,7 +721,11 @@ public:
@return returns @true if selection finished successfully. Usually only @return returns @true if selection finished successfully. Usually only
fails if current value in editor is not valid. fails if current value in editor is not valid.
@see wxPropertyGrid::ClearSelection() @remarks In wxPropertyGrid 1.4, this member function used to generate
wxEVT_PG_SELECTED. In wxWidgets 2.9 and later, it no longer
does that.
@see wxPropertyGridInterface::ClearSelection()
*/ */
bool SelectProperty( wxPGPropArg id, bool focus = false ); bool SelectProperty( wxPGPropArg id, bool focus = false );

View File

@@ -91,6 +91,12 @@ public:
@return Returns @true if successful or if there was no selection. May @return Returns @true if successful or if there was no selection. May
fail if validation was enabled and active editor had invalid fail if validation was enabled and active editor had invalid
value. value.
@remarks In wxPropertyGrid 1.4, this member function used to send
wxPG_EVT_SELECTED. In wxWidgets 2.9 and later, it no longer
does that.
@see wxPropertyGrid::SelectProperty()
*/ */
bool ClearSelection( bool validation = false); bool ClearSelection( bool validation = false);

View File

@@ -849,7 +849,7 @@ void wxPropertyGrid::OnTLPChanging( wxWindow* newTLP )
void wxPropertyGrid::OnTLPClose( wxCloseEvent& event ) void wxPropertyGrid::OnTLPClose( wxCloseEvent& event )
{ {
// ClearSelection forces value validation/commit. // ClearSelection forces value validation/commit.
if ( event.CanVeto() && !ClearSelection() ) if ( event.CanVeto() && !DoClearSelection() )
{ {
event.Veto(); event.Veto();
return; return;
@@ -1071,7 +1071,7 @@ void wxPropertyGrid::ResetColours()
bool wxPropertyGrid::SetFont( const wxFont& font ) bool wxPropertyGrid::SetFont( const wxFont& font )
{ {
// Must disable active editor. // Must disable active editor.
ClearSelection(false); DoClearSelection();
bool res = wxScrolledWindow::SetFont( font ); bool res = wxScrolledWindow::SetFont( font );
if ( res && GetParent()) // may not have been Create()ed yet if ( res && GetParent()) // may not have been Create()ed yet
@@ -2168,7 +2168,7 @@ void wxPropertyGrid::Clear()
bool wxPropertyGrid::EnableCategories( bool enable ) bool wxPropertyGrid::EnableCategories( bool enable )
{ {
ClearSelection(false); DoClearSelection();
if ( enable ) if ( enable )
{ {
@@ -2220,7 +2220,7 @@ void wxPropertyGrid::SwitchState( wxPropertyGridPageState* pNewState )
wxPGProperty* oldSelection = m_selected; wxPGProperty* oldSelection = m_selected;
ClearSelection(false); DoClearSelection();
m_pState->m_selected = oldSelection; m_pState->m_selected = oldSelection;
@@ -3608,6 +3608,7 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags )
m_inDoSelectProperty = 0; m_inDoSelectProperty = 0;
// call wx event handler (here so that it also occurs on deselection) // call wx event handler (here so that it also occurs on deselection)
if ( !(flags & wxPG_SEL_DONT_SEND_EVENT) )
SendEvent( wxEVT_PG_SELECTED, m_selected, NULL, flags ); SendEvent( wxEVT_PG_SELECTED, m_selected, NULL, flags );
return true; return true;
@@ -3661,11 +3662,23 @@ void wxPropertyGrid::RefreshEditor()
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// This method is not inline because it called dozens of times bool wxPropertyGrid::SelectProperty( wxPGPropArg id, bool focus )
// (i.e. two-arg function calls create smaller code size). {
wxPG_PROP_ARG_CALL_PROLOG_RETVAL(false)
int flags = wxPG_SEL_DONT_SEND_EVENT;
if ( focus )
flags |= wxPG_SEL_FOCUS;
return DoSelectProperty(p, flags);
}
// -----------------------------------------------------------------------
bool wxPropertyGrid::DoClearSelection() bool wxPropertyGrid::DoClearSelection()
{ {
return DoSelectProperty(NULL); // Unlike ClearSelection(), here we send the wxEVT_PG_SELECTED event.
return DoSelectProperty(NULL, 0);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -3679,7 +3692,7 @@ bool wxPropertyGrid::DoCollapse( wxPGProperty* p, bool sendEvents )
// If active editor was inside collapsed section, then disable it // If active editor was inside collapsed section, then disable it
if ( m_selected && m_selected->IsSomeParent(p) ) if ( m_selected && m_selected->IsSomeParent(p) )
{ {
ClearSelection(false); DoClearSelection();
} }
// Store dont-center-splitter flag 'cause we need to temporarily set it // Store dont-center-splitter flag 'cause we need to temporarily set it
@@ -3764,7 +3777,7 @@ bool wxPropertyGrid::DoHideProperty( wxPGProperty* p, bool hide, int flags )
( m_selected == p || m_selected->IsSomeParent(p) ) ( m_selected == p || m_selected->IsSomeParent(p) )
) )
{ {
ClearSelection(false); DoClearSelection();
} }
m_pState->DoHideProperty(p, hide, flags); m_pState->DoHideProperty(p, hide, flags);

View File

@@ -220,7 +220,7 @@ wxPGProperty* wxPropertyGridInterface::ReplaceProperty( wxPGPropArg id, wxPGProp
bool wxPropertyGridInterface::ClearSelection( bool validation ) bool wxPropertyGridInterface::ClearSelection( bool validation )
{ {
int flags = 0; int flags = wxPG_SEL_DONT_SEND_EVENT;
if ( !validation ) if ( !validation )
flags |= wxPG_SEL_NOVALIDATE; flags |= wxPG_SEL_NOVALIDATE;
@@ -297,7 +297,7 @@ bool wxPropertyGridInterface::ExpandAll( bool doExpand )
if ( GetSelection() && GetSelection() != state->DoGetRoot() && if ( GetSelection() && GetSelection() != state->DoGetRoot() &&
!doExpand ) !doExpand )
{ {
pg->ClearSelection(false); pg->DoClearSelection();
} }
wxPGVIterator it; wxPGVIterator it;
@@ -579,7 +579,7 @@ void wxPropertyGridInterface::Sort( int flags )
{ {
wxPropertyGrid* pg = GetPropertyGrid(); wxPropertyGrid* pg = GetPropertyGrid();
pg->ClearSelection(false); pg->DoClearSelection();
unsigned int pageIndex = 0; unsigned int pageIndex = 0;
@@ -1091,9 +1091,9 @@ bool wxPropertyGridInterface::RestoreEditableState( const wxString& src, int res
if ( pgSelectionSet ) if ( pgSelectionSet )
{ {
if ( newSelection ) if ( newSelection )
pg->SelectProperty(newSelection); pg->DoSelectProperty(newSelection);
else else
pg->ClearSelection(); pg->DoClearSelection();
} }
if ( selectedPage != -1 ) if ( selectedPage != -1 )