1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_vcl.hxx" 26 27 #include "aqua/saltimer.h" 28 #include "aqua/salnstimer.h" 29 #include "aqua/saldata.hxx" 30 #include "aqua/salframe.h" 31 #include "aqua/salinst.h" 32 33 // ======================================================================= 34 35 NSTimer* AquaSalTimer::pRunningTimer = nil; 36 bool AquaSalTimer::bDispatchTimer = false; 37 38 ImplSalStartTimer(sal_uLong nMS)39void ImplSalStartTimer( sal_uLong nMS ) 40 { 41 SalData* pSalData = GetSalData(); 42 if( pSalData->mpFirstInstance->isNSAppThread() ) 43 { 44 AquaSalTimer::bDispatchTimer = true; 45 NSTimeInterval aTI = double(nMS)/1000.0; 46 if( AquaSalTimer::pRunningTimer != nil ) 47 { 48 if( [AquaSalTimer::pRunningTimer timeInterval] == aTI ) 49 // set new fire date 50 [AquaSalTimer::pRunningTimer setFireDate: [NSDate dateWithTimeIntervalSinceNow: aTI]]; 51 else 52 { 53 [AquaSalTimer::pRunningTimer invalidate]; 54 AquaSalTimer::pRunningTimer = nil; 55 } 56 } 57 if( AquaSalTimer::pRunningTimer == nil ) 58 { 59 AquaSalTimer::pRunningTimer = [NSTimer scheduledTimerWithTimeInterval: aTI 60 target: [[[TimerCallbackCaller alloc] init] autorelease] 61 selector: @selector(timerElapsed:) 62 userInfo: nil 63 repeats: YES]; 64 /* #i84055# add timer to tracking run loop mode, 65 so they also elapse while e.g. life resize 66 */ 67 [[NSRunLoop currentRunLoop] addTimer: AquaSalTimer::pRunningTimer forMode: NSEventTrackingRunLoopMode]; 68 } 69 } 70 else 71 { 72 SalData::ensureThreadAutoreleasePool(); 73 // post an event so we can get into the main thread 74 NSEvent* pEvent = [NSEvent otherEventWithType: NSApplicationDefined 75 location: NSZeroPoint 76 modifierFlags: 0 77 timestamp: [NSDate timeIntervalSinceReferenceDate] 78 windowNumber: 0 79 context: nil 80 subtype: AquaSalInstance::AppStartTimerEvent 81 data1: (int)nMS 82 data2: 0 ]; 83 if( pEvent ) 84 [NSApp postEvent: pEvent atStart: YES]; 85 } 86 } 87 ImplSalStopTimer()88void ImplSalStopTimer() 89 { 90 AquaSalTimer::bDispatchTimer = false; 91 } 92 handleStartTimerEvent(NSEvent * pEvent)93void AquaSalTimer::handleStartTimerEvent( NSEvent* pEvent ) 94 { 95 ImplSVData* pSVData = ImplGetSVData(); 96 if( pSVData->mpSalTimer ) 97 { 98 NSTimeInterval posted = [pEvent timestamp] + NSTimeInterval([pEvent data1])/1000.0; 99 NSTimeInterval current = [NSDate timeIntervalSinceReferenceDate]; 100 if( (posted - current) <= 0.0 ) 101 { 102 YIELD_GUARD; 103 // timer already elapsed since event posted 104 pSVData->mpSalTimer->CallCallback(); 105 } 106 ImplSalStartTimer( sal_uLong( [pEvent data1] ) ); 107 } 108 109 } 110 AquaSalTimer()111AquaSalTimer::AquaSalTimer( ) 112 { 113 } 114 ~AquaSalTimer()115AquaSalTimer::~AquaSalTimer() 116 { 117 ImplSalStopTimer(); 118 } 119 Start(sal_uLong nMS)120void AquaSalTimer::Start( sal_uLong nMS ) 121 { 122 ImplSalStartTimer( nMS ); 123 } 124 Stop()125void AquaSalTimer::Stop() 126 { 127 ImplSalStopTimer(); 128 } 129 130 131