@@ -123,38 +123,68 @@ void CEvents::RemoveAllEvents()
123123 m_EventHashMap.clear ();
124124}
125125
126- void CEvents::PreEventPulse ()
126+ void CEvents::PreEventPulse (CEventContext* pContext )
127127{
128+ assert (pContext);
129+
128130 m_CancelledList.push_back (m_bEventCancelled);
131+ m_ContextStack.push_back (pContext);
132+
133+ pContext->Reset ();
134+
129135 m_bEventCancelled = false ;
130136 m_bWasEventCancelled = false ;
131137 m_strLastError = " " ;
132138}
133139
134- void CEvents::PostEventPulse ()
140+ void CEvents::PostEventPulse (CEventContext* pContext )
135141{
136- m_bWasEventCancelled = m_bEventCancelled;
142+ assert (pContext);
143+ assert (!m_ContextStack.empty ());
144+ assert (m_ContextStack.back () == pContext);
145+
146+ m_bWasEventCancelled = pContext->IsCancelled ();
137147 m_bEventCancelled = m_CancelledList.back () ? true : false ;
138148 m_CancelledList.pop_back ();
149+ m_ContextStack.pop_back ();
139150}
140151
141152void CEvents::CancelEvent (bool bCancelled)
142153{
143- m_bEventCancelled = bCancelled;
154+ CancelEvent ( bCancelled, nullptr ) ;
144155}
145156
146157void CEvents::CancelEvent (bool bCancelled, const char * szReason)
147158{
159+ // ALWAYS set the old global variable for backward compatibility
148160 m_bEventCancelled = bCancelled;
149- m_strLastError = SStringX (szReason);
161+
162+ // Also update context if it exists
163+ if (!m_ContextStack.empty ())
164+ {
165+ CEventContext* pCurrentContext = m_ContextStack.back ();
166+ if (bCancelled)
167+ pCurrentContext->Cancel (szReason);
168+ else
169+ pCurrentContext->Reset ();
170+ }
171+
172+ if (szReason)
173+ m_strLastError = szReason;
150174}
151175
152176bool CEvents::WasEventCancelled ()
153177{
154- return m_bWasEventCancelled;
178+ if (!m_ContextStack.empty ())
179+ return m_ContextStack.back ()->IsCancelled ();
180+
181+ return m_bEventCancelled || m_bWasEventCancelled;
155182}
156183
157184const char * CEvents::GetLastError ()
158185{
186+ if (!m_ContextStack.empty ())
187+ return m_ContextStack.back ()->GetCancelReason ().c_str ();
188+
159189 return m_strLastError;
160190}
0 commit comments