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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/svwin.h>
37 #include <saldata.hxx>
41 // =======================================================================
44 #define MAX_SYSPERIOD 65533
46 // =======================================================================
48 void ImplSalStartTimer( ULONG nMS
, BOOL bMutex
)
50 SalData
* pSalData
= GetSalData();
52 // Remenber the time of the timer
53 pSalData
->mnTimerMS
= nMS
;
55 pSalData
->mnTimerOrgMS
= nMS
;
57 // Periode darf nicht zu gross sein, da Windows mit USHORT arbeitet
58 if ( nMS
> MAX_SYSPERIOD
)
61 // Gibt es einen Timer, dann zerstoren
62 if ( pSalData
->mnTimerId
)
63 KillTimer( 0, pSalData
->mnTimerId
);
65 // Make a new timer with new period
66 pSalData
->mnTimerId
= SetTimer( 0, 0, (UINT
)nMS
, SalTimerProc
);
67 pSalData
->mnNextTimerTime
= pSalData
->mnLastEventTime
+ nMS
;
70 // -----------------------------------------------------------------------
72 WinSalTimer::~WinSalTimer()
76 void WinSalTimer::Start( ULONG nMS
)
78 // switch to main thread
79 SalData
* pSalData
= GetSalData();
80 if ( pSalData
->mpFirstInstance
)
82 if ( pSalData
->mnAppThreadId
!= GetCurrentThreadId() )
83 ImplPostMessage( pSalData
->mpFirstInstance
->mhComWnd
, SAL_MSG_STARTTIMER
, 0, (LPARAM
)nMS
);
85 ImplSendMessage( pSalData
->mpFirstInstance
->mhComWnd
, SAL_MSG_STARTTIMER
, 0, (LPARAM
)nMS
);
88 ImplSalStartTimer( nMS
, FALSE
);
91 void WinSalTimer::Stop()
93 SalData
* pSalData
= GetSalData();
95 // If we have a timer, than
96 if ( pSalData
->mnTimerId
)
98 KillTimer( 0, pSalData
->mnTimerId
);
99 pSalData
->mnTimerId
= 0;
100 pSalData
->mnNextTimerTime
= 0;
104 // -----------------------------------------------------------------------
106 void CALLBACK
SalTimerProc( HWND
, UINT
, UINT_PTR nId
, DWORD
)
111 if (__builtin_setjmp(jmpbuf
) == 0)
113 han
.Set(jmpbuf
, NULL
, (__SEHandler::PF
)EXCEPTION_EXECUTE_HANDLER
);
118 SalData
* pSalData
= GetSalData();
119 ImplSVData
* pSVData
= ImplGetSVData();
121 // Test for MouseLeave
124 bool bRecursive
= pSalData
->mbInTimerProc
&& (nId
!= SALTIMERPROC_RECURSIVE
);
125 if ( pSVData
->mpSalTimer
&& ! bRecursive
)
127 // Try to aquire the mutex. If we don't get the mutex then we
128 // try this a short time later again.
129 if ( ImplSalYieldMutexTryToAcquire() )
131 bRecursive
= pSalData
->mbInTimerProc
&& (nId
!= SALTIMERPROC_RECURSIVE
);
132 if ( pSVData
->mpSalTimer
&& ! bRecursive
)
134 pSalData
->mbInTimerProc
= TRUE
;
135 pSVData
->mpSalTimer
->CallCallback();
136 pSalData
->mbInTimerProc
= FALSE
;
137 ImplSalYieldMutexRelease();
139 // Run the timer in the correct time, if we start this
140 // with a small timeout, because we don't get the mutex
141 if ( pSalData
->mnTimerId
&&
142 (pSalData
->mnTimerMS
!= pSalData
->mnTimerOrgMS
) )
143 ImplSalStartTimer( pSalData
->mnTimerOrgMS
, FALSE
);
147 ImplSalStartTimer( 10, TRUE
);
153 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))