|
From: andrew7 <bd...@us...> - 2007-06-19 01:13:23
|
Update of /cvsroot/smartwin/SmartWin/include/smartwin/widgets In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv28800 Modified Files: WidgetWindowBase.h Log Message: Add killTimer funciton so timers can be aborted. Index: WidgetWindowBase.h =================================================================== RCS file: /cvsroot/smartwin/SmartWin/include/smartwin/widgets/WidgetWindowBase.h,v retrieving revision 1.35 retrieving revision 1.36 diff -u -d -r1.35 -r1.36 --- WidgetWindowBase.h 26 Dec 2006 01:17:29 -0000 1.35 +++ WidgetWindowBase.h 19 Jun 2007 01:13:17 -0000 1.36 @@ -258,6 +258,9 @@ void createTimer( typename ThisMessageMap::voidFunctionTakingCommand eventHandler, unsigned int milliSecond, const SmartWin::Command & command ); #endif + /// Removes the "its" timer + void killTimer( const Command & command ); + /// Closes the window /** Call this function to raise the "Closing" event. <br> * This will normally try to close the window. <br> @@ -334,6 +337,8 @@ {} private: + unsigned int getNewTimerEvent(); + // Static/Global timer map std::map< UINT, typename ThisMessageMap::TupleCommandFunctionGlobal > itsTimerMap; @@ -404,6 +409,47 @@ } + +template< class EventHandlerClass, class MessageMapPolicy > +void WidgetWindowBase< EventHandlerClass, MessageMapPolicy >::killTimer( const Command & command ) +{ + // Find the event ID in itsTimerMapThis, and then kill the timer. + CommandPtr comInList; + typename std::map < UINT, typename ThisMessageMap::TupleCommandFunctionThis >::iterator idx; + + for ( idx= itsTimerMapThis.begin(); idx != itsTimerMapThis.end(); idx++ ) { + typename ThisMessageMap::TupleCommandFunctionThis tfc= idx->second; + comInList= tfc.template get< 1 >(); + if ( comInList->Name() == command.Name() ) { + ::KillTimer( handle(), idx->first ); + itsTimerMapThis.erase( idx->first ); + return; + } + } +} + + +// There are some unanswered questions here: +// 1) Is it possible to actually use the timer outside of a WidgetWindow ? +// 2) If not, why bother with itsTimerMap instead of just itsTimerMapThis ? +// 3) Is it time to outfactor this into an aspect ? +// +template< class EventHandlerClass, class MessageMapPolicy > +unsigned int WidgetWindowBase< EventHandlerClass, MessageMapPolicy >::getNewTimerEvent() +{ + for ( int n = 0; n < 100; ++n ) { // Why not n=1; n <101 as below ? + typename std::map < UINT, + typename ThisMessageMap::TupleCommandFunctionGlobal >::iterator idx = itsTimerMap.find( n ); + if ( idx == itsTimerMap.end() ) { + return n; // Return an event not already used. + } + } + + xCeption x( _T( "More than 100 timers defined" ) ); + throw x; +} + +// This is unused ? template< class EventHandlerClass, class MessageMapPolicy > #ifdef _MSC_VER void WidgetWindowBase< EventHandlerClass, MessageMapPolicy >::createTimer( voidFunctionTakingCommand eventHandler, @@ -417,23 +463,7 @@ const Command & command ) #endif { - unsigned int event = - 1; - for ( int n = 0; n < 100; ++n ) - { - typename std::map < UINT, - typename ThisMessageMap::TupleCommandFunctionGlobal >::iterator idx - = itsTimerMap.find( n ); - if ( idx == itsTimerMap.end() ) - { - event = n; - break; - } - } - if ( event == - 1 ) - { - xCeption x( _T( "More than 100 timers defined" ) ); - throw x; - } + unsigned int event = getNewTimerEvent(); CommandPtr comPtr( command.clone().release() ); itsTimerMap[event] = typename ThisMessageMap::TupleCommandFunctionGlobal( eventHandler, comPtr ); @@ -441,6 +471,8 @@ } + +// This is the createTimer actually used by in-widget response function. template< class EventHandlerClass, class MessageMapPolicy > #ifdef _MSC_VER |