1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: saltimer.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #define _SV_SALTIMER_CXX
34 #include <saldata.hxx>
38 // =======================================================================
41 #define MAX_SYSPERIOD 65533
44 // =======================================================================
46 void ImplSalStartTimer( ULONG nMS
, BOOL bMutex
)
48 SalData
* pSalData
= GetSalData();
50 // Periode darf nicht zu gross sein, da OS2 2.11 mit USHORT arbeitet
51 // Remenber the time of the timer
52 pSalData
->mnTimerMS
= nMS
;
54 pSalData
->mnTimerOrgMS
= nMS
;
56 // Periode darf nicht zu gross sein, da Windows mit USHORT arbeitet
57 if ( nMS
> MAX_SYSPERIOD
)
60 // Gibt es einen Timer, dann zerstoren
61 if ( pSalData
->mnTimerId
)
62 WinStopTimer( pSalData
->mhAB
, pSalData
->mpFirstInstance
->mhComWnd
, pSalData
->mnTimerId
);
64 // Make a new timer with new period
65 pSalData
->mnTimerId
= WinStartTimer( pSalData
->mhAB
, pSalData
->mpFirstInstance
->mhComWnd
, IDTIMER
, nMS
);
66 pSalData
->mnNextTimerTime
= pSalData
->mnLastEventTime
+ nMS
;
69 // -----------------------------------------------------------------------
71 Os2SalTimer::~Os2SalTimer()
75 // -----------------------------------------------------------------------
77 void Os2SalTimer::Start( ULONG nMS
)
79 // Um auf Main-Thread umzuschalten
80 SalData
* pSalData
= GetSalData();
81 if ( pSalData
->mpFirstInstance
)
83 if ( pSalData
->mnAppThreadId
!= GetCurrentThreadId() )
84 WinPostMsg( pSalData
->mpFirstInstance
->mhComWnd
, SAL_MSG_STARTTIMER
, 0, (MPARAM
)nMS
);
86 WinSendMsg( pSalData
->mpFirstInstance
->mhComWnd
, SAL_MSG_STARTTIMER
, 0, (MPARAM
)nMS
);
89 ImplSalStartTimer( nMS
, FALSE
);
92 // -----------------------------------------------------------------------
94 void Os2SalTimer::Stop()
96 SalData
* pSalData
= GetSalData();
98 // Exitstiert ein Timer, dann diesen zerstoeren
99 if ( pSalData
->mnTimerId
) {
100 WinStopTimer( pSalData
->mhAB
, pSalData
->mpFirstInstance
->mhComWnd
, pSalData
->mnTimerId
);
101 pSalData
->mnTimerId
= 0;
102 pSalData
->mnNextTimerTime
= 0;
106 // -----------------------------------------------------------------------
108 void SalTimerProc( HWND
, UINT
, UINT nId
, ULONG
)
110 SalData
* pSalData
= GetSalData();
111 ImplSVData
* pSVData
= ImplGetSVData();
113 // Test for MouseLeave
116 bool bRecursive
= pSalData
->mbInTimerProc
&& (nId
!= SALTIMERPROC_RECURSIVE
);
117 if ( pSVData
->mpSalTimer
&& ! bRecursive
)
119 // Try to aquire the mutex. If we don't get the mutex then we
120 // try this a short time later again.
121 if ( ImplSalYieldMutexTryToAcquire() )
123 bRecursive
= pSalData
->mbInTimerProc
&& (nId
!= SALTIMERPROC_RECURSIVE
);
124 if ( pSVData
->mpSalTimer
&& ! bRecursive
)
126 pSalData
->mbInTimerProc
= TRUE
;
127 pSVData
->mpSalTimer
->CallCallback();
128 pSalData
->mbInTimerProc
= FALSE
;
129 ImplSalYieldMutexRelease();
131 // Run the timer in the correct time, if we start this
132 // with a small timeout, because we don't get the mutex
133 if ( pSalData
->mnTimerId
&&
134 (pSalData
->mnTimerMS
!= pSalData
->mnTimerOrgMS
) )
135 ImplSalStartTimer( pSalData
->mnTimerOrgMS
, FALSE
);
139 ImplSalStartTimer( 10, TRUE
);