1*b1cdbd2cSJim Jagielski /*****************************************************************************
2*b1cdbd2cSJim Jagielski  * MultiClickRemoteBehavior.h
3*b1cdbd2cSJim Jagielski  * RemoteControlWrapper
4*b1cdbd2cSJim Jagielski  *
5*b1cdbd2cSJim Jagielski  * Created by Martin Kahr on 11.03.06 under a MIT-style license.
6*b1cdbd2cSJim Jagielski  * Copyright (c) 2006 martinkahr.com. All rights reserved.
7*b1cdbd2cSJim Jagielski  *
8*b1cdbd2cSJim Jagielski  * Code modified and adapted to OpenOffice.org
9*b1cdbd2cSJim Jagielski  * by Eric Bachard on 11.08.2008 under the same License
10*b1cdbd2cSJim Jagielski  *
11*b1cdbd2cSJim Jagielski  * Permission is hereby granted, free of charge, to any person obtaining a
12*b1cdbd2cSJim Jagielski  * copy of this software and associated documentation files (the "Software"),
13*b1cdbd2cSJim Jagielski  * to deal in the Software without restriction, including without limitation
14*b1cdbd2cSJim Jagielski  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15*b1cdbd2cSJim Jagielski  * and/or sell copies of the Software, and to permit persons to whom the
16*b1cdbd2cSJim Jagielski  * Software is furnished to do so, subject to the following conditions:
17*b1cdbd2cSJim Jagielski  *
18*b1cdbd2cSJim Jagielski  * The above copyright notice and this permission notice shall be included
19*b1cdbd2cSJim Jagielski  * in all copies or substantial portions of the Software.
20*b1cdbd2cSJim Jagielski  *
21*b1cdbd2cSJim Jagielski  * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22*b1cdbd2cSJim Jagielski  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23*b1cdbd2cSJim Jagielski  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24*b1cdbd2cSJim Jagielski  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25*b1cdbd2cSJim Jagielski  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26*b1cdbd2cSJim Jagielski  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27*b1cdbd2cSJim Jagielski  * THE SOFTWARE.
28*b1cdbd2cSJim Jagielski  *
29*b1cdbd2cSJim Jagielski  *****************************************************************************/
30*b1cdbd2cSJim Jagielski 
31*b1cdbd2cSJim Jagielski 
32*b1cdbd2cSJim Jagielski #import <Cocoa/Cocoa.h>
33*b1cdbd2cSJim Jagielski #import "RemoteControl.h"
34*b1cdbd2cSJim Jagielski 
35*b1cdbd2cSJim Jagielski /**
36*b1cdbd2cSJim Jagielski 	A behavior that adds multiclick and hold events on top of a device.
37*b1cdbd2cSJim Jagielski 	Events are generated and send to a delegate
38*b1cdbd2cSJim Jagielski  */
39*b1cdbd2cSJim Jagielski @interface MultiClickRemoteBehavior : NSObject {
40*b1cdbd2cSJim Jagielski 	id delegate;
41*b1cdbd2cSJim Jagielski 
42*b1cdbd2cSJim Jagielski 	// state for simulating plus/minus hold
43*b1cdbd2cSJim Jagielski 	BOOL simulateHoldEvents;
44*b1cdbd2cSJim Jagielski 	BOOL lastEventSimulatedHold;
45*b1cdbd2cSJim Jagielski 	RemoteControlEventIdentifier lastHoldEvent;
46*b1cdbd2cSJim Jagielski 	NSTimeInterval lastHoldEventTime;
47*b1cdbd2cSJim Jagielski 
48*b1cdbd2cSJim Jagielski 	// state for multi click
49*b1cdbd2cSJim Jagielski 	unsigned int clickCountEnabledButtons;
50*b1cdbd2cSJim Jagielski 	NSTimeInterval maxClickTimeDifference;
51*b1cdbd2cSJim Jagielski 	NSTimeInterval lastClickCountEventTime;
52*b1cdbd2cSJim Jagielski 	RemoteControlEventIdentifier lastClickCountEvent;
53*b1cdbd2cSJim Jagielski 	unsigned int eventClickCount;
54*b1cdbd2cSJim Jagielski }
55*b1cdbd2cSJim Jagielski 
init()56*b1cdbd2cSJim Jagielski - (id) init;
57*b1cdbd2cSJim Jagielski 
58*b1cdbd2cSJim Jagielski // Delegates are not retained
setDelegate:(id)59*b1cdbd2cSJim Jagielski - (void) setDelegate: (id) delegate;
delegate()60*b1cdbd2cSJim Jagielski - (id) delegate;
61*b1cdbd2cSJim Jagielski 
62*b1cdbd2cSJim Jagielski // Simulating hold events does deactivate sending of individual requests for pressed down/released.
63*b1cdbd2cSJim Jagielski // Instead special hold events are being triggered when the user is pressing and holding a button for a small period.
64*b1cdbd2cSJim Jagielski // Simulation is activated only for those buttons and remote control that do not have a seperate event already
simulateHoldEvent()65*b1cdbd2cSJim Jagielski - (BOOL) simulateHoldEvent;
setSimulateHoldEvent:(BOOL)66*b1cdbd2cSJim Jagielski - (void) setSimulateHoldEvent: (BOOL) value;
67*b1cdbd2cSJim Jagielski 
68*b1cdbd2cSJim Jagielski // click counting makes it possible to recognize if the user has pressed a button repeatedly
69*b1cdbd2cSJim Jagielski // click counting does delay each event as it has to wait if there is another event (second click)
70*b1cdbd2cSJim Jagielski // therefore there is a slight time difference (maximumClickCountTimeDifference) between a single click
71*b1cdbd2cSJim Jagielski // of the user and the call of your delegate method
72*b1cdbd2cSJim Jagielski // click counting can be enabled individually for specific buttons. Use the property clickCountEnableButtons to
73*b1cdbd2cSJim Jagielski // set the buttons for which click counting shall be enabled
clickCountingEnabled()74*b1cdbd2cSJim Jagielski - (BOOL) clickCountingEnabled;
setClickCountingEnabled:(BOOL)75*b1cdbd2cSJim Jagielski - (void) setClickCountingEnabled: (BOOL) value;
76*b1cdbd2cSJim Jagielski 
clickCountEnabledButtons()77*b1cdbd2cSJim Jagielski - (unsigned int) clickCountEnabledButtons;
setClickCountEnabledButtons:(unsigned int)78*b1cdbd2cSJim Jagielski - (void) setClickCountEnabledButtons: (unsigned int)value;
79*b1cdbd2cSJim Jagielski 
80*b1cdbd2cSJim Jagielski // the maximum time difference till which clicks are recognized as multi clicks
maximumClickCountTimeDifference()81*b1cdbd2cSJim Jagielski - (NSTimeInterval) maximumClickCountTimeDifference;
setMaximumClickCountTimeDifference:(NSTimeInterval)82*b1cdbd2cSJim Jagielski - (void) setMaximumClickCountTimeDifference: (NSTimeInterval) timeDiff;
83*b1cdbd2cSJim Jagielski 
84*b1cdbd2cSJim Jagielski @end
85*b1cdbd2cSJim Jagielski 
86*b1cdbd2cSJim Jagielski /*
87*b1cdbd2cSJim Jagielski  * Method definitions for the delegate of the MultiClickRemoteBehavior class
88*b1cdbd2cSJim Jagielski  */
89*b1cdbd2cSJim Jagielski @interface NSObject(MultiClickRemoteBehaviorDelegate)
90*b1cdbd2cSJim Jagielski 
remoteButton:pressedDown:clickCount:(RemoteControlEventIdentifier,BOOL,unsigned int)91*b1cdbd2cSJim Jagielski - (void) remoteButton: (RemoteControlEventIdentifier)buttonIdentifier pressedDown: (BOOL) pressedDown clickCount: (unsigned int) count;
92*b1cdbd2cSJim Jagielski 
93*b1cdbd2cSJim Jagielski @end
94