LibreOffice Module apple_remote (master) 1
RemoteMainController.m
Go to the documentation of this file.
1/* -*- Mode: ObjC; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*****************************************************************************
3 * RemoteMainController.m
4 *
5 * Created by Martin Kahr on 11.03.06 under a MIT-style license.
6 * Copyright (c) 2006 martinkahr.com. All rights reserved.
7 *
8 * Code modified and adapted to OpenOffice.org
9 * by Eric Bachard on 11.08.2008 under the same License
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 * THE SOFTWARE.
28 *
29 *****************************************************************************/
30
32#import "AppleRemote.h"
37
38
39// Sample Code 3: Multi Click Behavior and Hold Event Simulation
40
41
43
44- (id) init {
45 self = [super init]; // because we redefined our own init instead of use the fu..nny awakeFromNib
46 if (self != nil) {
47
48 // 1. instantiate the desired behavior for the remote control device
50
51 // 2. configure the behavior
53
54 // 3. a Remote Control Container manages a number of devices and conforms to the RemoteControl interface
55 // Therefore you can enable or disable all the devices of the container with a single "startListening:" call.
56 RemoteControlContainer* container = [[RemoteControlContainer alloc] initWithDelegate: remoteControlBehavior];
57
58 if ( [container instantiateAndAddRemoteControlDeviceWithClass: [AppleRemote class]] != 0 ) {
59#ifdef DEBUG
60 NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [AppleRemote class]] successful");
61 }
62 else {
63 NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [AppleRemote class]] failed");
64#endif
65 }
66
67 if ( [container instantiateAndAddRemoteControlDeviceWithClass: [GlobalKeyboardDevice class]] != 0 ) {
68#ifdef DEBUG
69 NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [GlobalKeyboardDevice class]] successful");
70 }
71 else {
72 NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [GlobalKeyboardDevice class]] failed");
73#endif
74 }
75 // to give the binding mechanism a chance to see the change of the attribute
76 [self setValue: container forKey: @"remoteControl"];
77#ifdef DEBUG
78 NSLog(@"AppleRemoteMainController init done");
79#endif
80 }
81 else
82 NSLog(@"AppleRemoteMainController init failed");
83 return self;
84}
85
86- (void) postTheEvent: (short int)buttonIdentifier modifierFlags:(int)modifierFlags
87{
89 // 'NSApplicationDefined' is deprecated: first deprecated in macOS 10.12
90 [NSApp postEvent:
91 [NSEvent otherEventWithType:NSApplicationDefined
92 location:NSZeroPoint
93 modifierFlags:modifierFlags
94 timestamp: 0
95 windowNumber:[[NSApp keyWindow] windowNumber]
96 context:nil
97 subtype:AppleRemoteControlEvent
98 data1: buttonIdentifier
99 data2: 0]
100 atStart: NO];
102}
103
104
105- (void) remoteButton: (RemoteControlEventIdentifier)buttonIdentifier pressedDown: (BOOL) pressedDown clickCount: (unsigned int)clickCount
106{
107 (void)clickCount;
108#ifdef DEBUG
109 NSString* pressed = @"";
110 NSString* buttonName = nil;
111#endif
112 if (pressedDown)
113 {
114#ifdef DEBUG
115 pressed = @"(AppleRemoteMainController: button pressed)";
116
117 switch(buttonIdentifier)
118 {
119 case kRemoteButtonPlus: buttonName = @"Volume up"; break; // MEDIA_COMMAND_VOLUME_UP ( see include/vcl/commandevent.hxx )
120 case kRemoteButtonMinus: buttonName = @"Volume down"; break; // MEDIA_COMMAND_VOLUME_DOWN
121 case kRemoteButtonMenu: buttonName = @"Menu"; break; // MEDIA_COMMAND_MENU
122 case kRemoteButtonPlay: buttonName = @"Play"; break; // MEDIA_COMMAND_PLAY
123 case kRemoteButtonRight: buttonName = @"Next slide"; break; // MEDIA_COMMAND_NEXTTRACK
124 case kRemoteButtonLeft: buttonName = @"Left"; break; // MEDIA_COMMAND_PREVIOUSTRACK
125 case kRemoteButtonRight_Hold: buttonName = @"Last slide"; break; // MEDIA_COMMAND_NEXTTRACK_HOLD
126 case kRemoteButtonLeft_Hold: buttonName = @"First slide"; break; // MEDIA_COMMAND_PREVIOUSTRACK_HOLD
127 case kRemoteButtonPlus_Hold: buttonName = @"Volume up holding"; break;
128 case kRemoteButtonMinus_Hold: buttonName = @"Volume down holding"; break;
129 case kRemoteButtonPlay_Hold: buttonName = @"Play (sleep mode)"; break; // MEDIA_COMMAND_PLAY_HOLD
130 case kRemoteButtonMenu_Hold: buttonName = @"Menu (long)"; break; // MEDIA_COMMAND_MENU_HOLD
131 case kRemoteControl_Switched: buttonName = @"Remote Control Switched";break;
132
133 default: NSLog( @"AppleRemoteMainController: Unmapped event for button %d", buttonIdentifier); break;
134 }
135#endif
136 [ self postTheEvent:buttonIdentifier modifierFlags: 0 ];
137 }
138 else // not pressed
139 {
140#ifdef DEBUG
141 pressed = @"(AppleRemoteMainController: button released)";
142#endif
143 }
144
145#ifdef DEBUG
146 //NSLog(@"Button %@ pressed %@", buttonName, pressed);
147 NSString* clickCountString = @"";
148 if (clickCount > 1) clickCountString = [NSString stringWithFormat: @"%d clicks", clickCount];
149 NSString* feedbackString = [NSString stringWithFormat:@"(Value:%4d) %@ %@ %@", buttonIdentifier, buttonName, pressed, clickCountString];
150
151 // print out events
152 NSLog(@"%@", feedbackString);
153
154 if (pressedDown == NO) printf("\n");
155 // simulate slow processing of events
156 // [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
157#endif
158}
159
160- (void) dealloc {
161 [ remoteControl release ]; remoteControl = nil;
162 [ remoteControlBehavior release ]; remoteControlBehavior = nil;
163 [super dealloc];
164}
165
166// for bindings access
168 return remoteControl;
169}
170
173}
174
175@end
176
177/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
RemoteControlEventIdentifier
Definition: RemoteControl.h:54
@ kRemoteControl_Switched
Definition: RemoteControl.h:72
@ kRemoteButtonRight_Hold
Definition: RemoteControl.h:68
@ kRemoteButtonMinus
Definition: RemoteControl.h:57
@ kRemoteButtonRight
Definition: RemoteControl.h:60
@ kRemoteButtonPlay_Hold
Definition: RemoteControl.h:67
@ kRemoteButtonPlus_Hold
Definition: RemoteControl.h:64
@ kRemoteButtonPlus
Definition: RemoteControl.h:56
@ kRemoteButtonMenu
Definition: RemoteControl.h:58
@ kRemoteButtonLeft
Definition: RemoteControl.h:61
@ kRemoteButtonPlay
Definition: RemoteControl.h:59
@ kRemoteButtonMenu_Hold
Definition: RemoteControl.h:66
@ kRemoteButtonMinus_Hold
Definition: RemoteControl.h:65
@ kRemoteButtonLeft_Hold
Definition: RemoteControl.h:69
FILE * init(int, char **)
MultiClickRemoteBehavior * remoteBehavior()
MultiClickRemoteBehavior * remoteControlBehavior
A behavior that adds multiclick and hold events on top of a device.
const wchar_t *typedef BOOL
#define SAL_WNODEPRECATED_DECLARATIONS_POP
#define SAL_WNODEPRECATED_DECLARATIONS_PUSH