Bump version to 4.1-6
[LibreOffice.git] / vcl / win / source / app / saltimer.cxx
blobdbe4ddc2d23038e613f13abd3be4de6b693d20ec
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svsys.h>
21 #include <win/saldata.hxx>
22 #include <win/saltimer.h>
23 #include <win/salinst.h>
25 #ifdef __MINGW32__
26 #include <sehandler.hxx>
27 #endif
29 // =======================================================================
31 // Maximale Periode
32 #define MAX_SYSPERIOD 65533
34 // =======================================================================
36 void ImplSalStartTimer( sal_uLong nMS, sal_Bool bMutex )
38 SalData* pSalData = GetSalData();
40 // Remenber the time of the timer
41 pSalData->mnTimerMS = nMS;
42 if ( !bMutex )
43 pSalData->mnTimerOrgMS = nMS;
45 // duration has to fit into Window's sal_uInt16
46 if ( nMS > MAX_SYSPERIOD )
47 nMS = MAX_SYSPERIOD;
49 // kill timer if it exists
50 if ( pSalData->mnTimerId )
51 KillTimer( 0, pSalData->mnTimerId );
53 // Make a new timer with new period
54 pSalData->mnTimerId = SetTimer( 0, 0, (UINT)nMS, SalTimerProc );
55 pSalData->mnNextTimerTime = pSalData->mnLastEventTime + nMS;
58 // -----------------------------------------------------------------------
60 WinSalTimer::~WinSalTimer()
64 void WinSalTimer::Start( sal_uLong nMS )
66 // switch to main thread
67 SalData* pSalData = GetSalData();
68 if ( pSalData->mpFirstInstance )
70 if ( pSalData->mnAppThreadId != GetCurrentThreadId() )
71 ImplPostMessage( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_STARTTIMER, 0, (LPARAM)nMS );
72 else
73 ImplSendMessage( pSalData->mpFirstInstance->mhComWnd, SAL_MSG_STARTTIMER, 0, (LPARAM)nMS );
75 else
76 ImplSalStartTimer( nMS, FALSE );
79 void WinSalTimer::Stop()
81 SalData* pSalData = GetSalData();
83 // If we have a timer, than
84 if ( pSalData->mnTimerId )
86 KillTimer( 0, pSalData->mnTimerId );
87 pSalData->mnTimerId = 0;
88 pSalData->mnNextTimerTime = 0;
92 // -----------------------------------------------------------------------
94 void CALLBACK SalTimerProc( HWND, UINT, UINT_PTR nId, DWORD )
96 #ifdef __MINGW32__
97 jmp_buf jmpbuf;
98 __SEHandler han;
99 if (__builtin_setjmp(jmpbuf) == 0)
101 han.Set(jmpbuf, NULL, (__SEHandler::PF)EXCEPTION_EXECUTE_HANDLER);
102 #else
103 __try
105 #endif
106 SalData* pSalData = GetSalData();
107 ImplSVData* pSVData = ImplGetSVData();
109 // Test for MouseLeave
110 SalTestMouseLeave();
112 bool bRecursive = pSalData->mbInTimerProc && (nId != SALTIMERPROC_RECURSIVE);
113 if ( pSVData->mpSalTimer && ! bRecursive )
115 // Try to aquire the mutex. If we don't get the mutex then we
116 // try this a short time later again.
117 if ( ImplSalYieldMutexTryToAcquire() )
119 bRecursive = pSalData->mbInTimerProc && (nId != SALTIMERPROC_RECURSIVE);
120 if ( pSVData->mpSalTimer && ! bRecursive )
122 pSalData->mbInTimerProc = TRUE;
123 pSVData->mpSalTimer->CallCallback();
124 pSalData->mbInTimerProc = FALSE;
125 ImplSalYieldMutexRelease();
127 // Run the timer in the correct time, if we start this
128 // with a small timeout, because we don't get the mutex
129 if ( pSalData->mnTimerId &&
130 (pSalData->mnTimerMS != pSalData->mnTimerOrgMS) )
131 ImplSalStartTimer( pSalData->mnTimerOrgMS, FALSE );
134 else
135 ImplSalStartTimer( 10, TRUE );
138 #ifdef __MINGW32__
139 han.Reset();
140 #else
141 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
144 #endif
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */