Index: vcl/aqua/inc/saldata.hxx =================================================================== RCS file: /cvs/gsl/vcl/aqua/inc/saldata.hxx,v retrieving revision 1.12.112.4 diff -u -r1.12.112.4 saldata.hxx --- vcl/aqua/inc/saldata.hxx 6 May 2007 18:36:19 -0000 1.12.112.4 +++ vcl/aqua/inc/saldata.hxx 8 May 2007 14:25:06 -0000 @@ -37,6 +37,11 @@ #ifndef _SV_SALDATA_HXX #define _SV_SALDATA_HXX +#include +#include +#include + + #ifndef _SV_SV_H #include #endif @@ -75,6 +80,17 @@ SalVirtualDevice *mpFirstVD; // first VirDev SalPrinter *mpFirstPrinter; // first printing printer SystemFontList* mpFontList; + + /* + * SalTimer related members + */ + BOOL mbInTimerProc; // timer event is currently being dispatched + BOOL mbTimerInstalled; // timer is in the event loop + ULONG mnTimerMS; // Current Time (in MS) of the Timer + ULONG mnTimerOrgMS; // Current Original Time (in MS) + + EventLoopTimerRef mrTimerRef; + EventLoopTimerUPP mrTimerUPP; }; inline void SetSalData( SalData* pData ) { ImplGetSVData()->mpSalData = (void*)pData; } Index: vcl/aqua/inc/saltimer.h =================================================================== RCS file: /cvs/gsl/vcl/aqua/inc/Attic/saltimer.h,v retrieving revision 1.2.2.2 diff -u -r1.2.2.2 saltimer.h --- vcl/aqua/inc/saltimer.h 2 Mar 2006 00:31:02 -0000 1.2.2.2 +++ vcl/aqua/inc/saltimer.h 8 May 2007 14:25:06 -0000 @@ -38,6 +38,7 @@ #include #include +#include #include #ifndef _SV_SALTIMER_HXX @@ -46,23 +47,14 @@ class AquaSalTimer : public SalTimer { -private: - TMTask mTask; // the timer task - BOOL mbInstalled; // timer task is in queue - long mMS; // current timer interval in msec - BOOL InstallTask(); // installs timer task and returns status - -public: + public: + AquaSalTimer(); virtual ~AquaSalTimer(); - - // overload all pure virtual methods - void Start( ULONG nMS ); - void Stop(); - - // restarts active tasks using the current timeout - // optional with different timeout (when nMS is != 0) - void ReStart( ULONG nMS = 0 ); + + void Start( ULONG nMS ); + void Stop(); + }; #endif Index: vcl/aqua/source/app/saltimer.cxx =================================================================== RCS file: /cvs/gsl/vcl/aqua/source/app/saltimer.cxx,v retrieving revision 1.10.112.7 diff -u -r1.10.112.7 saltimer.cxx --- vcl/aqua/source/app/saltimer.cxx 14 Oct 2006 13:28:53 -0000 1.10.112.7 +++ vcl/aqua/source/app/saltimer.cxx 8 May 2007 14:25:06 -0000 @@ -48,41 +48,79 @@ // ======================================================================= - #define USEMAINTHREAD 1 -void AquaSalTimerProc ( TMTaskPtr tmTaskPtr ) +void ImplSalStartTimer ( ULONG nMS, BOOL bMutex) { + fprintf(stderr, "ImplSalStartTimer\n"); + + SalData* pSalData = GetSalData(); + + // Store the new timeout + pSalData->mnTimerMS = nMS; + + if ( !bMutex ) + pSalData->mnTimerOrgMS = nMS; + + // Cancel current timer + if( pSalData->mbTimerInstalled ) + RemoveEventLoopTimer( pSalData->mrTimerRef ); + + // Install the timer task + if( InstallEventLoopTimer( GetMainEventLoop(), + kEventDurationMillisecond * nMS, + kEventDurationForever, + pSalData->mrTimerUPP, + NULL, + &pSalData->mrTimerRef) == noErr ) + pSalData->mbTimerInstalled = TRUE; + else + { + fprintf(stderr, "Could not install timer task!\n"); + pSalData->mbTimerInstalled = FALSE; + } +} + +void AquaSalTimerProc ( EventLoopTimerRef theTimer, void * /* userData */) +{ + fprintf(stderr, "...AquaSalTimerProc...\n"); + + SalData* pSalData = GetSalData(); ImplSVData* pSVData = ImplGetSVData(); - - AquaSalTimer *pSalTimer = (AquaSalTimer*) pSVData->mpSalTimer; - if( pSalTimer ) + + AquaSalTimer *pSalTimer = (AquaSalTimer*) pSVData->mpSalTimer; + + if( pSalTimer && !pSalData->mbInTimerProc ) { #ifdef USEMAINTHREAD - // send event to main thread - SalData* pSalData = GetSalData(); + // Send event to the main thread AquaSalFrame *pFrame = dynamic_cast(pSalData->mpFirstFrame); if( pFrame ) pFrame->PostTimerEvent( pSalTimer ); + + // FIXME? // fire again using current timeout as this is a single shot timer - pSalTimer->ReStart(); -#else + ImplSalStartTimer( pSalData->mnTimerOrgMS, FALSE ); +#else // call back directly from timer thread if( ImplSalYieldMutexTryToAcquire() ) { + pSalData->mbInTimerProc = TRUE; pSalTimer->CallCallback(); + pSalData->mbInTimerProc = FALSE; ImplSalYieldMutexRelease(); - + + // FIXME? // fire again using current timeout as this is a single shot timer - pSalTimer->ReStart(); + ImplSalStartTimer( pSalData->mnTimerOrgMS, FALSE ); } else { // could not acquire solar mutex, so // fire again with a short delay (10ms) - //fprintf(stderr, "TIMER: solar mutex not free\n"); - pSalTimer->ReStart( 10 ); + fprintf(stderr, "SHOULD NOT HAPPEN! TIMER: solar mutex not free\n"); + ImplSalStartTimer( 10, TRUE ); } #endif @@ -93,65 +131,43 @@ AquaSalTimer::AquaSalTimer( ) { - mbInstalled = FALSE; - mMS = 0; - mTask.tmAddr = NewTimerUPP( AquaSalTimerProc ); + fprintf(stderr, "AquaSalTimer::AquaSalTimer\n"); + SalData* pSalData = GetSalData(); + + pSalData->mbTimerInstalled = FALSE; + pSalData->mnTimerMS = 0; + pSalData->mnTimerOrgMS = 0; + pSalData->mrTimerUPP = NewEventLoopTimerUPP( AquaSalTimerProc ); } AquaSalTimer::~AquaSalTimer() { - if( mbInstalled ) - RemoveTimeTask( (QElemPtr) &mTask ); - DisposeTimerUPP( mTask.tmAddr ); -} + fprintf(stderr, "AquaSalTimer::~AquaSalTimer\n"); -// ----------------------------------------------------------------------- + SalData* pSalData = GetSalData(); + if( pSalData->mbTimerInstalled ) + RemoveEventLoopTimer( pSalData->mrTimerRef ); + + DisposeEventLoopTimerUPP( pSalData->mrTimerUPP ); +} void AquaSalTimer::Start( ULONG nMS ) { - // cancel current timer - if( mbInstalled ) - RemoveTimeTask( (QElemPtr) &mTask ); - - // store new timeout - mMS = nMS; - - // install the timer task - mbInstalled = InstallTask(); - - // fire - if( mbInstalled ) - PrimeTimeTask( (QElemPtr) &mTask, mMS ); -} - -void AquaSalTimer::ReStart( ULONG nMS ) -{ - if( mbInstalled ) - // use current timeout if nMS == 0 - PrimeTimeTask( (QElemPtr) &mTask, nMS ? nMS : mMS ); + fprintf(stderr, "AquaSalTimer::Start(%lu ms)\n", nMS); + + ImplSalStartTimer(nMS, FALSE); } void AquaSalTimer::Stop() { - if( mbInstalled ) - { - RemoveTimeTask( (QElemPtr) &mTask ); - mbInstalled = FALSE; - } -} + fprintf(stderr, "AquaSalTimer::Stop\n"); -BOOL AquaSalTimer::InstallTask() -{ - // install the timer task - mTask.tmWakeUp = 0; - mTask.tmCount = 0; - if( InstallTimeTask( (QElemPtr) &mTask ) == noErr ) - return TRUE; - else + SalData* pSalData = GetSalData(); + if( pSalData->mbTimerInstalled ) { - fprintf(stderr, "Could not install timer task!\n"); - return FALSE; + // FIXME + RemoveEventLoopTimer( pSalData->mrTimerRef ); + pSalData->mbTimerInstalled = FALSE; } } -// -----------------------------------------------------------------------