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