1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_vcl.hxx" 30 31 #include "aqua/saltimer.h" 32 #include "aqua/salnstimer.h" 33 #include "aqua/saldata.hxx" 34 #include "aqua/salframe.h" 35 #include "aqua/salinst.h" 36 37 // ======================================================================= 38 39 NSTimer* AquaSalTimer::pRunningTimer = nil; 40 bool AquaSalTimer::bDispatchTimer = false; 41 42 43 void ImplSalStartTimer( sal_uLong nMS ) 44 { 45 SalData* pSalData = GetSalData(); 46 if( pSalData->mpFirstInstance->isNSAppThread() ) 47 { 48 AquaSalTimer::bDispatchTimer = true; 49 NSTimeInterval aTI = double(nMS)/1000.0; 50 if( AquaSalTimer::pRunningTimer != nil ) 51 { 52 if( [AquaSalTimer::pRunningTimer timeInterval] == aTI ) 53 // set new fire date 54 [AquaSalTimer::pRunningTimer setFireDate: [NSDate dateWithTimeIntervalSinceNow: aTI]]; 55 else 56 { 57 [AquaSalTimer::pRunningTimer invalidate]; 58 AquaSalTimer::pRunningTimer = nil; 59 } 60 } 61 if( AquaSalTimer::pRunningTimer == nil ) 62 { 63 AquaSalTimer::pRunningTimer = [NSTimer scheduledTimerWithTimeInterval: aTI 64 target: [[[TimerCallbackCaller alloc] init] autorelease] 65 selector: @selector(timerElapsed:) 66 userInfo: nil 67 repeats: YES]; 68 /* #i84055# add timer to tracking run loop mode, 69 so they also elapse while e.g. life resize 70 */ 71 [[NSRunLoop currentRunLoop] addTimer: AquaSalTimer::pRunningTimer forMode: NSEventTrackingRunLoopMode]; 72 } 73 } 74 else 75 { 76 SalData::ensureThreadAutoreleasePool(); 77 // post an event so we can get into the main thread 78 NSPoint aPt = { 0, 0 }; 79 NSEvent* pEvent = [NSEvent otherEventWithType: NSApplicationDefined 80 location: aPt 81 modifierFlags: 0 82 timestamp: [NSDate timeIntervalSinceReferenceDate] 83 windowNumber: 0 84 context: nil 85 subtype: AquaSalInstance::AppStartTimerEvent 86 data1: (int)nMS 87 data2: 0 ]; 88 if( pEvent ) 89 [NSApp postEvent: pEvent atStart: YES]; 90 } 91 } 92 93 void ImplSalStopTimer() 94 { 95 AquaSalTimer::bDispatchTimer = false; 96 } 97 98 void AquaSalTimer::handleStartTimerEvent( NSEvent* pEvent ) 99 { 100 ImplSVData* pSVData = ImplGetSVData(); 101 if( pSVData->mpSalTimer ) 102 { 103 NSTimeInterval posted = [pEvent timestamp] + NSTimeInterval([pEvent data1])/1000.0; 104 NSTimeInterval current = [NSDate timeIntervalSinceReferenceDate]; 105 if( (posted - current) <= 0.0 ) 106 { 107 YIELD_GUARD; 108 // timer already elapsed since event posted 109 pSVData->mpSalTimer->CallCallback(); 110 } 111 ImplSalStartTimer( sal_uLong( [pEvent data1] ) ); 112 } 113 114 } 115 116 AquaSalTimer::AquaSalTimer( ) 117 { 118 } 119 120 AquaSalTimer::~AquaSalTimer() 121 { 122 ImplSalStopTimer(); 123 } 124 125 void AquaSalTimer::Start( sal_uLong nMS ) 126 { 127 ImplSalStartTimer( nMS ); 128 } 129 130 void AquaSalTimer::Stop() 131 { 132 ImplSalStopTimer(); 133 } 134 135 136