1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include <svpm.h> 29 30 #define _SV_SALTIMER_CXX 31 #include <saldata.hxx> 32 #include <saltimer.h> 33 #include <salinst.h> 34 35 // ======================================================================= 36 37 // Maximale Periode 38 #define MAX_SYSPERIOD 65533 39 #define IDTIMER 10 40 41 // ======================================================================= 42 43 void ImplSalStartTimer( ULONG nMS, BOOL bMutex ) 44 { 45 SalData* pSalData = GetSalData(); 46 47 // Periode darf nicht zu gross sein, da OS2 2.11 mit USHORT arbeitet 48 // Remenber the time of the timer 49 pSalData->mnTimerMS = nMS; 50 if ( !bMutex ) 51 pSalData->mnTimerOrgMS = nMS; 52 53 // Periode darf nicht zu gross sein, da Windows mit USHORT arbeitet 54 if ( nMS > MAX_SYSPERIOD ) 55 nMS = MAX_SYSPERIOD; 56 57 // Gibt es einen Timer, dann zerstoren 58 if ( pSalData->mnTimerId ) 59 WinStopTimer( pSalData->mhAB, pSalData->mpFirstInstance->mhComWnd, pSalData->mnTimerId ); 60 61 // Make a new timer with new period 62 pSalData->mnTimerId = WinStartTimer( pSalData->mhAB, pSalData->mpFirstInstance->mhComWnd, IDTIMER, nMS ); 63 pSalData->mnNextTimerTime = pSalData->mnLastEventTime + nMS; 64 } 65 66 // ----------------------------------------------------------------------- 67 68 Os2SalTimer::~Os2SalTimer() 69 { 70 } 71 72 // ----------------------------------------------------------------------- 73 74 void Os2SalTimer::Start( ULONG nMS ) 75 { 76 // Um auf Main-Thread umzuschalten 77 SalData* pSalData = GetSalData(); 78 if ( pSalData->mpFirstInstance ) 79 { 80 if ( pSalData->mnAppThreadId != GetCurrentThreadId() ) 81 WinPostMsg( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_STARTTIMER, 0, (MPARAM)nMS ); 82 else 83 WinSendMsg( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_STARTTIMER, 0, (MPARAM)nMS ); 84 } 85 else 86 ImplSalStartTimer( nMS, FALSE); 87 } 88 89 // ----------------------------------------------------------------------- 90 91 void Os2SalTimer::Stop() 92 { 93 SalData* pSalData = GetSalData(); 94 95 // Exitstiert ein Timer, dann diesen zerstoeren 96 if ( pSalData->mnTimerId ) { 97 WinStopTimer( pSalData->mhAB, pSalData->mpFirstInstance->mhComWnd, pSalData->mnTimerId ); 98 pSalData->mnTimerId = 0; 99 pSalData->mnNextTimerTime = 0; 100 } 101 } 102 103 // ----------------------------------------------------------------------- 104 105 void SalTimerProc( HWND, UINT, UINT nId, ULONG ) 106 { 107 SalData* pSalData = GetSalData(); 108 ImplSVData* pSVData = ImplGetSVData(); 109 110 // Test for MouseLeave 111 SalTestMouseLeave(); 112 113 bool bRecursive = pSalData->mbInTimerProc && (nId != SALTIMERPROC_RECURSIVE); 114 if ( pSVData->mpSalTimer && ! bRecursive ) 115 { 116 // Try to aquire the mutex. If we don't get the mutex then we 117 // try this a short time later again. 118 if ( ImplSalYieldMutexTryToAcquire() ) 119 { 120 bRecursive = pSalData->mbInTimerProc && (nId != SALTIMERPROC_RECURSIVE); 121 if ( pSVData->mpSalTimer && ! bRecursive ) 122 { 123 pSalData->mbInTimerProc = TRUE; 124 pSVData->mpSalTimer->CallCallback(); 125 pSalData->mbInTimerProc = FALSE; 126 ImplSalYieldMutexRelease(); 127 128 // Run the timer in the correct time, if we start this 129 // with a small timeout, because we don't get the mutex 130 if ( pSalData->mnTimerId && 131 (pSalData->mnTimerMS != pSalData->mnTimerOrgMS) ) 132 ImplSalStartTimer( pSalData->mnTimerOrgMS, FALSE ); 133 } 134 } 135 else 136 ImplSalStartTimer( 10, TRUE ); 137 } 138 139 } 140 141