merged tag ooo/DEV300_m102
[LibreOffice.git] / vcl / win / source / app / saltimer.cxx
blob6026f80e6346e4d777b022b6f22fe01ecd120245
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 #include <tools/svwin.h>
31 #ifdef __MINGW32__
32 #include <excpt.h>
33 #endif
34 #include <saldata.hxx>
35 #include <saltimer.h>
36 #include <salinst.h>
38 // =======================================================================
40 // Maximale Periode
41 #define MAX_SYSPERIOD 65533
43 // =======================================================================
45 void ImplSalStartTimer( sal_uLong nMS, sal_Bool bMutex )
47 SalData* pSalData = GetSalData();
49 // Remenber the time of the timer
50 pSalData->mnTimerMS = nMS;
51 if ( !bMutex )
52 pSalData->mnTimerOrgMS = nMS;
54 // Periode darf nicht zu gross sein, da Windows mit sal_uInt16 arbeitet
55 if ( nMS > MAX_SYSPERIOD )
56 nMS = MAX_SYSPERIOD;
58 // Gibt es einen Timer, dann zerstoren
59 if ( pSalData->mnTimerId )
60 KillTimer( 0, pSalData->mnTimerId );
62 // Make a new timer with new period
63 pSalData->mnTimerId = SetTimer( 0, 0, (UINT)nMS, SalTimerProc );
64 pSalData->mnNextTimerTime = pSalData->mnLastEventTime + nMS;
67 // -----------------------------------------------------------------------
69 WinSalTimer::~WinSalTimer()
73 void WinSalTimer::Start( sal_uLong nMS )
75 // switch to main thread
76 SalData* pSalData = GetSalData();
77 if ( pSalData->mpFirstInstance )
79 if ( pSalData->mnAppThreadId != GetCurrentThreadId() )
80 ImplPostMessage( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_STARTTIMER, 0, (LPARAM)nMS );
81 else
82 ImplSendMessage( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_STARTTIMER, 0, (LPARAM)nMS );
84 else
85 ImplSalStartTimer( nMS, FALSE );
88 void WinSalTimer::Stop()
90 SalData* pSalData = GetSalData();
92 // If we have a timer, than
93 if ( pSalData->mnTimerId )
95 KillTimer( 0, pSalData->mnTimerId );
96 pSalData->mnTimerId = 0;
97 pSalData->mnNextTimerTime = 0;
101 // -----------------------------------------------------------------------
103 void CALLBACK SalTimerProc( HWND, UINT, UINT_PTR nId, DWORD )
105 #ifdef __MINGW32__
106 jmp_buf jmpbuf;
107 __SEHandler han;
108 if (__builtin_setjmp(jmpbuf) == 0)
110 han.Set(jmpbuf, NULL, (__SEHandler::PF)EXCEPTION_EXECUTE_HANDLER);
111 #else
112 __try
114 #endif
115 SalData* pSalData = GetSalData();
116 ImplSVData* pSVData = ImplGetSVData();
118 // Test for MouseLeave
119 SalTestMouseLeave();
121 bool bRecursive = pSalData->mbInTimerProc && (nId != SALTIMERPROC_RECURSIVE);
122 if ( pSVData->mpSalTimer && ! bRecursive )
124 // Try to aquire the mutex. If we don't get the mutex then we
125 // try this a short time later again.
126 if ( ImplSalYieldMutexTryToAcquire() )
128 bRecursive = pSalData->mbInTimerProc && (nId != SALTIMERPROC_RECURSIVE);
129 if ( pSVData->mpSalTimer && ! bRecursive )
131 pSalData->mbInTimerProc = TRUE;
132 pSVData->mpSalTimer->CallCallback();
133 pSalData->mbInTimerProc = FALSE;
134 ImplSalYieldMutexRelease();
136 // Run the timer in the correct time, if we start this
137 // with a small timeout, because we don't get the mutex
138 if ( pSalData->mnTimerId &&
139 (pSalData->mnTimerMS != pSalData->mnTimerOrgMS) )
140 ImplSalStartTimer( pSalData->mnTimerOrgMS, FALSE );
143 else
144 ImplSalStartTimer( 10, TRUE );
147 #ifdef __MINGW32__
148 han.Reset();
149 #else
150 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
153 #endif