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>
34 #include <saldata.hxx>
38 // =======================================================================
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
;
52 pSalData
->mnTimerOrgMS
= nMS
;
54 // Periode darf nicht zu gross sein, da Windows mit sal_uInt16 arbeitet
55 if ( 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
);
82 ImplSendMessage( pSalData
->mpFirstInstance
->mhComWnd
, SAL_MSG_STARTTIMER
, 0, (LPARAM
)nMS
);
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
)
108 if (__builtin_setjmp(jmpbuf
) == 0)
110 han
.Set(jmpbuf
, NULL
, (__SEHandler::PF
)EXCEPTION_EXECUTE_HANDLER
);
115 SalData
* pSalData
= GetSalData();
116 ImplSVData
* pSVData
= ImplGetSVData();
118 // Test for MouseLeave
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
);
144 ImplSalStartTimer( 10, TRUE
);
150 __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))