Store property name and value in wxPropertyGridEvent, keep track of live event instances, and clear property/grid information in them in wxPropertyGrid dtor. This allows application to relay events for later processing without fear of losing most relevant information within.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62168 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2009-09-27 14:35:02 +00:00
parent 9867e3e498
commit 644b283d6a
3 changed files with 152 additions and 22 deletions

View File

@@ -582,6 +582,20 @@ wxPropertyGrid::~wxPropertyGrid()
{
size_t i;
#if wxUSE_THREAD
wxCriticalSectionLocker(wxPGGlobalVars->m_critSect);
#endif
//
// Remove grid and property pointers from live wxPropertyGridEvents.
for ( i=0; i<m_liveEvents.size(); i++ )
{
wxPropertyGridEvent* evt = m_liveEvents[i];
evt->SetPropertyGrid(NULL);
evt->SetProperty(NULL);
}
m_liveEvents.clear();
if ( m_processedEvent )
{
// All right... we are being deleted while wxPropertyGrid event
@@ -592,7 +606,7 @@ wxPropertyGrid::~wxPropertyGrid()
m_processedEvent->StopPropagation();
// Let's use wxMessageBox to make the message appear more
// reliably (and *before* the crash can happend).
// reliably (and *before* the crash can happen).
::wxMessageBox("wxPropertyGrid was being destroyed in an event "
"generated by it. This usually leads to a crash "
"so it is recommended to destroy the control "
@@ -4399,25 +4413,26 @@ bool wxPropertyGrid::SendEvent( int eventType, wxPGProperty* p,
evt.SetEventObject(m_eventObject);
evt.SetProperty(p);
evt.SetColumn(column);
if ( pValue )
if ( eventType == wxEVT_PG_CHANGING )
{
wxASSERT( pValue );
evt.SetCanVeto(true);
evt.SetupValidationInfo();
m_validationInfo.m_pValue = pValue;
evt.SetupValidationInfo();
}
else if ( !(selFlags & wxPG_SEL_NOVALIDATE) )
else
{
evt.SetCanVeto(true);
if ( p )
evt.SetPropertyValue(p->GetValue());
if ( !(selFlags & wxPG_SEL_NOVALIDATE) )
evt.SetCanVeto(true);
}
m_processedEvent = &evt;
wxEvtHandler* evtHandler = m_eventObject->GetEventHandler();
m_eventObject->HandleWindowEvent(evt);
m_processedEvent = NULL;
evtHandler->ProcessEvent(evt);
return evt.WasVetoed();
}
@@ -5860,6 +5875,7 @@ wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent& event)
m_eventType = event.GetEventType();
m_eventObject = event.m_eventObject;
m_pg = event.m_pg;
OnPropertyGridSet();
m_property = event.m_property;
m_validationInfo = event.m_validationInfo;
m_canVeto = event.m_canVeto;
@@ -5868,8 +5884,40 @@ wxPropertyGridEvent::wxPropertyGridEvent(const wxPropertyGridEvent& event)
// -----------------------------------------------------------------------
void wxPropertyGridEvent::OnPropertyGridSet()
{
if ( !m_pg )
return;
#if wxUSE_THREAD
wxCriticalSectionLocker(wxPGGlobalVars->m_critSect);
#endif
m_pg->m_liveEvents.push_back(this);
}
// -----------------------------------------------------------------------
wxPropertyGridEvent::~wxPropertyGridEvent()
{
if ( m_pg )
{
#if wxUSE_THREAD
wxCriticalSectionLocker(wxPGGlobalVars->m_critSect);
#endif
// Use iterate from the back since it is more likely that the event
// being desroyed is at the end of the array.
wxVector<wxPropertyGridEvent*>& liveEvents = m_pg->m_liveEvents;
for ( int i = liveEvents.size()-1; i >= 0; i-- )
{
if ( liveEvents[i] == this )
{
liveEvents.erase(liveEvents.begin() + i);
break;
}
}
}
}
// -----------------------------------------------------------------------