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 .
20 #include "osx/saltimer.h"
21 #include "osx/salnstimer.h"
22 #include "osx/saldata.hxx"
23 #include "osx/salframe.h"
24 #include "osx/salinst.h"
26 NSTimer
* AquaSalTimer::pRunningTimer
= nil
;
27 bool AquaSalTimer::bDispatchTimer
= false;
29 void ImplSalStartTimer( sal_uLong nMS
)
31 SalData
* pSalData
= GetSalData();
32 if( pSalData
->mpFirstInstance
->isNSAppThread() )
34 AquaSalTimer::bDispatchTimer
= true;
35 NSTimeInterval aTI
= double(nMS
)/1000.0;
36 if( AquaSalTimer::pRunningTimer
!= nil
)
38 if( [AquaSalTimer::pRunningTimer timeInterval
] == aTI
)
40 [AquaSalTimer::pRunningTimer setFireDate
: [NSDate dateWithTimeIntervalSinceNow
: aTI
]];
43 [AquaSalTimer::pRunningTimer invalidate
];
44 AquaSalTimer::pRunningTimer
= nil
;
47 if( AquaSalTimer::pRunningTimer
== nil
)
49 AquaSalTimer::pRunningTimer
= [NSTimer scheduledTimerWithTimeInterval
: aTI
50 target
: [[[TimerCallbackCaller alloc
] init
] autorelease
]
51 selector
: @
selector(timerElapsed
:)
54 /* #i84055# add timer to tracking run loop mode,
55 so they also elapse while e.g. life resize
57 [[NSRunLoop currentRunLoop
] addTimer
: AquaSalTimer::pRunningTimer forMode
: NSEventTrackingRunLoopMode
];
62 SalData::ensureThreadAutoreleasePool();
63 // post an event so we can get into the main thread
64 NSEvent
* pEvent
= [NSEvent otherEventWithType
: NSApplicationDefined
67 timestamp
: [NSDate timeIntervalSinceReferenceDate
]
70 subtype
: AquaSalInstance::AppStartTimerEvent
74 [NSApp postEvent
: pEvent atStart
: YES
];
78 void ImplSalStopTimer()
80 AquaSalTimer::bDispatchTimer
= false;
83 void AquaSalTimer::handleStartTimerEvent( NSEvent
* pEvent
)
85 ImplSVData
* pSVData
= ImplGetSVData();
86 if( pSVData
->mpSalTimer
)
88 NSTimeInterval posted
= [pEvent timestamp
] + NSTimeInterval([pEvent data1
])/1000.0;
89 NSTimeInterval current
= [NSDate timeIntervalSinceReferenceDate
];
90 if( (posted
- current
) <= 0.0 )
93 if( pSVData
->mpSalTimer
)
95 // timer already elapsed since event posted
96 bool idle
= true; // TODO
97 pSVData
->mpSalTimer
->CallCallback( idle
);
100 ImplSalStartTimer( sal_uLong( [pEvent data1
] ) );
105 AquaSalTimer::AquaSalTimer( )
109 AquaSalTimer::~AquaSalTimer()
114 void AquaSalTimer::Start( sal_uLong nMS
)
116 ImplSalStartTimer( nMS
);
119 void AquaSalTimer::Stop()
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */