1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include <svpm.h> 25cdf0e10cSrcweir 26cdf0e10cSrcweir #define _SV_SALTIMER_CXX 27cdf0e10cSrcweir #include <saldata.hxx> 28cdf0e10cSrcweir #include <saltimer.h> 29cdf0e10cSrcweir #include <salinst.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir // ======================================================================= 32cdf0e10cSrcweir 33cdf0e10cSrcweir // Maximale Periode 34cdf0e10cSrcweir #define MAX_SYSPERIOD 65533 35cdf0e10cSrcweir #define IDTIMER 10 36cdf0e10cSrcweir 37cdf0e10cSrcweir // ======================================================================= 38cdf0e10cSrcweir 39cdf0e10cSrcweir void ImplSalStartTimer( ULONG nMS, BOOL bMutex ) 40cdf0e10cSrcweir { 41cdf0e10cSrcweir SalData* pSalData = GetSalData(); 42cdf0e10cSrcweir 43cdf0e10cSrcweir // Periode darf nicht zu gross sein, da OS2 2.11 mit USHORT arbeitet 44cdf0e10cSrcweir // Remenber the time of the timer 45cdf0e10cSrcweir pSalData->mnTimerMS = nMS; 46cdf0e10cSrcweir if ( !bMutex ) 47cdf0e10cSrcweir pSalData->mnTimerOrgMS = nMS; 48cdf0e10cSrcweir 49cdf0e10cSrcweir // Periode darf nicht zu gross sein, da Windows mit USHORT arbeitet 50cdf0e10cSrcweir if ( nMS > MAX_SYSPERIOD ) 51cdf0e10cSrcweir nMS = MAX_SYSPERIOD; 52cdf0e10cSrcweir 53cdf0e10cSrcweir // Gibt es einen Timer, dann zerstoren 54cdf0e10cSrcweir if ( pSalData->mnTimerId ) 55cdf0e10cSrcweir WinStopTimer( pSalData->mhAB, pSalData->mpFirstInstance->mhComWnd, pSalData->mnTimerId ); 56cdf0e10cSrcweir 57cdf0e10cSrcweir // Make a new timer with new period 58cdf0e10cSrcweir pSalData->mnTimerId = WinStartTimer( pSalData->mhAB, pSalData->mpFirstInstance->mhComWnd, IDTIMER, nMS ); 59cdf0e10cSrcweir pSalData->mnNextTimerTime = pSalData->mnLastEventTime + nMS; 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir // ----------------------------------------------------------------------- 63cdf0e10cSrcweir 64cdf0e10cSrcweir Os2SalTimer::~Os2SalTimer() 65cdf0e10cSrcweir { 66cdf0e10cSrcweir } 67cdf0e10cSrcweir 68cdf0e10cSrcweir // ----------------------------------------------------------------------- 69cdf0e10cSrcweir 70cdf0e10cSrcweir void Os2SalTimer::Start( ULONG nMS ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir // Um auf Main-Thread umzuschalten 73cdf0e10cSrcweir SalData* pSalData = GetSalData(); 74cdf0e10cSrcweir if ( pSalData->mpFirstInstance ) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir if ( pSalData->mnAppThreadId != GetCurrentThreadId() ) 77cdf0e10cSrcweir WinPostMsg( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_STARTTIMER, 0, (MPARAM)nMS ); 78cdf0e10cSrcweir else 79cdf0e10cSrcweir WinSendMsg( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_STARTTIMER, 0, (MPARAM)nMS ); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir else 82cdf0e10cSrcweir ImplSalStartTimer( nMS, FALSE); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir // ----------------------------------------------------------------------- 86cdf0e10cSrcweir 87cdf0e10cSrcweir void Os2SalTimer::Stop() 88cdf0e10cSrcweir { 89cdf0e10cSrcweir SalData* pSalData = GetSalData(); 90cdf0e10cSrcweir 91cdf0e10cSrcweir // Exitstiert ein Timer, dann diesen zerstoeren 92cdf0e10cSrcweir if ( pSalData->mnTimerId ) { 93cdf0e10cSrcweir WinStopTimer( pSalData->mhAB, pSalData->mpFirstInstance->mhComWnd, pSalData->mnTimerId ); 94cdf0e10cSrcweir pSalData->mnTimerId = 0; 95cdf0e10cSrcweir pSalData->mnNextTimerTime = 0; 96cdf0e10cSrcweir } 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir // ----------------------------------------------------------------------- 100cdf0e10cSrcweir 101cdf0e10cSrcweir void SalTimerProc( HWND, UINT, UINT nId, ULONG ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir SalData* pSalData = GetSalData(); 104cdf0e10cSrcweir ImplSVData* pSVData = ImplGetSVData(); 105cdf0e10cSrcweir 106cdf0e10cSrcweir // Test for MouseLeave 107cdf0e10cSrcweir SalTestMouseLeave(); 108cdf0e10cSrcweir 109cdf0e10cSrcweir bool bRecursive = pSalData->mbInTimerProc && (nId != SALTIMERPROC_RECURSIVE); 110cdf0e10cSrcweir if ( pSVData->mpSalTimer && ! bRecursive ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir // Try to aquire the mutex. If we don't get the mutex then we 113cdf0e10cSrcweir // try this a short time later again. 114cdf0e10cSrcweir if ( ImplSalYieldMutexTryToAcquire() ) 115cdf0e10cSrcweir { 116cdf0e10cSrcweir bRecursive = pSalData->mbInTimerProc && (nId != SALTIMERPROC_RECURSIVE); 117cdf0e10cSrcweir if ( pSVData->mpSalTimer && ! bRecursive ) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir pSalData->mbInTimerProc = TRUE; 120cdf0e10cSrcweir pSVData->mpSalTimer->CallCallback(); 121cdf0e10cSrcweir pSalData->mbInTimerProc = FALSE; 122cdf0e10cSrcweir ImplSalYieldMutexRelease(); 123cdf0e10cSrcweir 124cdf0e10cSrcweir // Run the timer in the correct time, if we start this 125cdf0e10cSrcweir // with a small timeout, because we don't get the mutex 126cdf0e10cSrcweir if ( pSalData->mnTimerId && 127cdf0e10cSrcweir (pSalData->mnTimerMS != pSalData->mnTimerOrgMS) ) 128cdf0e10cSrcweir ImplSalStartTimer( pSalData->mnTimerOrgMS, FALSE ); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir } 131cdf0e10cSrcweir else 132cdf0e10cSrcweir ImplSalStartTimer( 10, TRUE ); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137