2010-10-14 08:27:31 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-06-21 14:30:25 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2013-12-05 22:01:05 +02:00
|
|
|
#include "osx/saltimer.h"
|
|
|
|
#include "osx/salnstimer.h"
|
|
|
|
#include "osx/saldata.hxx"
|
|
|
|
#include "osx/salframe.h"
|
|
|
|
#include "osx/salinst.h"
|
2000-11-29 23:01:54 +00:00
|
|
|
|
2008-01-14 15:16:19 +00:00
|
|
|
NSTimer* AquaSalTimer::pRunningTimer = nil;
|
|
|
|
bool AquaSalTimer::bDispatchTimer = false;
|
2007-07-05 09:06:19 +00:00
|
|
|
|
2011-01-19 15:42:25 +01:00
|
|
|
void ImplSalStartTimer( sal_uLong nMS )
|
2007-10-09 14:13:56 +00:00
|
|
|
{
|
2007-07-05 09:06:19 +00:00
|
|
|
SalData* pSalData = GetSalData();
|
2007-10-09 14:13:56 +00:00
|
|
|
if( pSalData->mpFirstInstance->isNSAppThread() )
|
2007-07-05 09:06:19 +00:00
|
|
|
{
|
2008-01-14 15:16:19 +00:00
|
|
|
AquaSalTimer::bDispatchTimer = true;
|
2007-10-09 14:13:56 +00:00
|
|
|
NSTimeInterval aTI = double(nMS)/1000.0;
|
2008-01-14 15:16:19 +00:00
|
|
|
if( AquaSalTimer::pRunningTimer != nil )
|
2007-10-09 14:13:56 +00:00
|
|
|
{
|
2008-01-14 15:16:19 +00:00
|
|
|
if( [AquaSalTimer::pRunningTimer timeInterval] == aTI )
|
2007-10-09 14:13:56 +00:00
|
|
|
// set new fire date
|
2008-01-14 15:16:19 +00:00
|
|
|
[AquaSalTimer::pRunningTimer setFireDate: [NSDate dateWithTimeIntervalSinceNow: aTI]];
|
2007-10-09 14:13:56 +00:00
|
|
|
else
|
|
|
|
{
|
2008-01-14 15:16:19 +00:00
|
|
|
[AquaSalTimer::pRunningTimer invalidate];
|
|
|
|
AquaSalTimer::pRunningTimer = nil;
|
2007-10-09 14:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
2008-01-14 15:16:19 +00:00
|
|
|
if( AquaSalTimer::pRunningTimer == nil )
|
2007-10-09 14:13:56 +00:00
|
|
|
{
|
2008-01-14 15:16:19 +00:00
|
|
|
AquaSalTimer::pRunningTimer = [NSTimer scheduledTimerWithTimeInterval: aTI
|
|
|
|
target: [[[TimerCallbackCaller alloc] init] autorelease]
|
|
|
|
selector: @selector(timerElapsed:)
|
|
|
|
userInfo: nil
|
|
|
|
repeats: YES];
|
|
|
|
/* #i84055# add timer to tracking run loop mode,
|
|
|
|
so they also elapse while e.g. life resize
|
|
|
|
*/
|
|
|
|
[[NSRunLoop currentRunLoop] addTimer: AquaSalTimer::pRunningTimer forMode: NSEventTrackingRunLoopMode];
|
2007-10-09 14:13:56 +00:00
|
|
|
}
|
2007-07-05 09:06:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-05-30 07:00:42 +00:00
|
|
|
SalData::ensureThreadAutoreleasePool();
|
2007-10-09 14:13:56 +00:00
|
|
|
// post an event so we can get into the main thread
|
|
|
|
NSEvent* pEvent = [NSEvent otherEventWithType: NSApplicationDefined
|
2014-02-24 09:08:02 +00:00
|
|
|
location: NSZeroPoint
|
2007-10-09 14:13:56 +00:00
|
|
|
modifierFlags: 0
|
|
|
|
timestamp: [NSDate timeIntervalSinceReferenceDate]
|
|
|
|
windowNumber: 0
|
|
|
|
context: nil
|
|
|
|
subtype: AquaSalInstance::AppStartTimerEvent
|
|
|
|
data1: (int)nMS
|
|
|
|
data2: 0 ];
|
|
|
|
if( pEvent )
|
|
|
|
[NSApp postEvent: pEvent atStart: YES];
|
2007-07-05 09:06:19 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2007-10-09 14:13:56 +00:00
|
|
|
void ImplSalStopTimer()
|
2007-07-05 09:06:19 +00:00
|
|
|
{
|
2008-01-14 15:16:19 +00:00
|
|
|
AquaSalTimer::bDispatchTimer = false;
|
2007-10-09 14:13:56 +00:00
|
|
|
}
|
2007-07-05 09:06:19 +00:00
|
|
|
|
2007-10-09 14:13:56 +00:00
|
|
|
void AquaSalTimer::handleStartTimerEvent( NSEvent* pEvent )
|
|
|
|
{
|
|
|
|
ImplSVData* pSVData = ImplGetSVData();
|
|
|
|
if( pSVData->mpSalTimer )
|
|
|
|
{
|
|
|
|
NSTimeInterval posted = [pEvent timestamp] + NSTimeInterval([pEvent data1])/1000.0;
|
|
|
|
NSTimeInterval current = [NSDate timeIntervalSinceReferenceDate];
|
2008-05-30 07:00:42 +00:00
|
|
|
if( (posted - current) <= 0.0 )
|
|
|
|
{
|
2008-08-18 12:04:24 +00:00
|
|
|
YIELD_GUARD;
|
2015-03-10 12:52:36 +01:00
|
|
|
if( pSVData->mpSalTimer )
|
|
|
|
{
|
|
|
|
// timer already elapsed since event posted
|
|
|
|
bool idle = true; // TODO
|
|
|
|
pSVData->mpSalTimer->CallCallback( idle );
|
|
|
|
}
|
2008-05-30 07:00:42 +00:00
|
|
|
}
|
2011-01-19 15:42:25 +01:00
|
|
|
ImplSalStartTimer( sal_uLong( [pEvent data1] ) );
|
2007-07-05 09:06:19 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2007-10-09 14:13:56 +00:00
|
|
|
}
|
2007-07-05 09:06:19 +00:00
|
|
|
|
|
|
|
AquaSalTimer::AquaSalTimer( )
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2007-07-05 09:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AquaSalTimer::~AquaSalTimer()
|
|
|
|
{
|
2007-10-09 14:13:56 +00:00
|
|
|
ImplSalStopTimer();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
|
|
|
|
2011-01-19 15:42:25 +01:00
|
|
|
void AquaSalTimer::Start( sal_uLong nMS )
|
2007-07-05 09:06:19 +00:00
|
|
|
{
|
2007-10-09 14:13:56 +00:00
|
|
|
ImplSalStartTimer( nMS );
|
2007-07-05 09:06:19 +00:00
|
|
|
}
|
2000-09-18 16:07:07 +00:00
|
|
|
|
2007-07-05 09:06:19 +00:00
|
|
|
void AquaSalTimer::Stop()
|
2000-09-18 16:07:07 +00:00
|
|
|
{
|
2007-10-09 14:13:56 +00:00
|
|
|
ImplSalStopTimer();
|
2000-09-18 16:07:07 +00:00
|
|
|
}
|
2007-07-05 09:06:19 +00:00
|
|
|
|
2010-10-14 08:27:31 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|