1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <win/saldata.hxx>
22 #include <win/saltimer.h>
23 #include <win/salinst.h>
26 #include <sehandler.hxx>
29 // =======================================================================
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
;
43 pSalData
->mnTimerOrgMS
= nMS
;
45 // duration has to fit into Window's sal_uInt16
46 if ( 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
);
73 ImplSendMessage( pSalData
->mpFirstInstance
->mhComWnd
, SAL_MSG_STARTTIMER
, 0, (LPARAM
)nMS
);
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
)
99 if (__builtin_setjmp(jmpbuf
) == 0)
101 han
.Set(jmpbuf
, NULL
, (__SEHandler::PF
)EXCEPTION_EXECUTE_HANDLER
);
106 SalData
* pSalData
= GetSalData();
107 ImplSVData
* pSVData
= ImplGetSVData();
109 // Test for MouseLeave
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
);
135 ImplSalStartTimer( 10, TRUE
);
141 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */