ef6cb13a30
2009-01-11 00:33:34 +0100 ericb r266127 : #i97925# start the presentation if and only if an Impress document is focused 2009-01-10 00:02:19 +0100 ericb r266124 : #i96978# cosmetic changes 2009-01-09 23:56:02 +0100 ericb r266123 : #i96978# simplify the code, and make the remote work in windowed mode 2009-01-08 21:25:52 +0100 ericb r266040 : #i96978# avoid to add the eventlistener several times 2009-01-08 14:54:38 +0100 ericb r266013 : #i96978# keep the MEDIA_COMMAND_VOLUME cases for QUARTZ only for the moment 2009-01-08 14:49:17 +0100 ericb r266011 : #i96978# fix wrong comments 2009-01-03 01:42:02 +0100 cloph r265848 : CWS-TOOLING: rebase CWS appleremote02 -> DEV300_m38 (manually, module was left out when using the tooling) 2008-12-30 00:11:30 +0100 ericb r265827 : CWS-TOOLING: rebase CWS appleremote02 to trunk@265758 (milestone: DEV300:m38) 2008-12-29 21:42:14 +0100 ericb r265825 : #i96978# comment the menu in appleremote02 2008-12-29 10:30:40 +0100 ericb r265816 : #i97195# remove the event listener in the dtor 2008-12-23 23:39:55 +0100 ericb r265794 : #i96978# cleanup 2008-12-23 08:49:49 +0100 ericb r265771 : #i96978# add MEDIA_COMMAND_VOLUME_UP and MEDIA_COMMAND_VOLUME_DOWN and the kRemoteButtonMenu (temporarly) 2008-12-23 08:47:27 +0100 ericb r265769 : #i96978# add all cases, for future use 2008-12-20 13:38:25 +0100 ericb r265743 : #i96978# fix a potential breaker (causing warning) 2008-12-20 12:22:15 +0100 ericb r265742 : #i97195# implement the new event listener + callback in Impress, to detect play 2008-12-20 12:20:42 +0100 ericb r265741 : #i97195# add the event listener in SdModule 2008-12-20 12:19:02 +0100 ericb r265740 : #i97195# add the nCommand for MEDIA_COMMAND_PLAY 2008-12-14 18:32:52 +0100 ericb r265456 : #i96978# add the possibility to switch the way to send the PLAY event in debug mode (will be removed once i97195 will be fixed) 2008-12-08 22:18:29 +0100 ericb r265050 : #i96978# removing Carbon dependancy and simplify 2008-12-07 19:54:18 +0100 ericb r264966 : #i96978# implement the new MEDIA_COMMAND events in salinst 2008-12-07 19:53:10 +0100 ericb r264965 : #i96978# add new event type for the Apple Remote on Mac OS X 2008-12-07 19:51:21 +0100 ericb r264964 : #i96978# add gotoLastSlide with MEDIA_COMMAND events (was missing) 2008-12-07 19:46:35 +0100 ericb r264962 : #i96992# fix an error when building with debug enabled 2008-12-07 19:45:04 +0100 ericb r264961 : #i96978# Implement a new event mangement for the Apple remote 2008-12-07 18:59:58 +0100 ericb r264957 : #i96554# fix wrong argument causing warnings 2008-12-07 18:57:56 +0100 ericb r264956 : #i96554# fix wrong argument type 2008-12-07 18:55:22 +0100 ericb r264955 : #i96978# adding a new event type
177 lines
No EOL
7.5 KiB
Objective-C
177 lines
No EOL
7.5 KiB
Objective-C
/*****************************************************************************
|
|
* RemoteMainController.m
|
|
*
|
|
* Created by Martin Kahr on 11.03.06 under a MIT-style license.
|
|
* Copyright (c) 2006 martinkahr.com. All rights reserved.
|
|
*
|
|
* Code modified and adapted to OpenOffice.org
|
|
* by Eric Bachard on 11.08.2008 under the same License
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
* THE SOFTWARE.
|
|
*
|
|
*****************************************************************************/
|
|
|
|
#import "RemoteMainController.h"
|
|
#import "AppleRemote.h"
|
|
#import "KeyspanFrontRowControl.h"
|
|
#import "GlobalKeyboardDevice.h"
|
|
#import "RemoteControlContainer.h"
|
|
#import "MultiClickRemoteBehavior.h"
|
|
|
|
// -------------------------------------------------------------------------------------------
|
|
// Sample Code 3: Multi Click Behavior and Hold Event Simulation
|
|
// -------------------------------------------------------------------------------------------
|
|
|
|
@implementation MainController
|
|
|
|
- (id) init {
|
|
self = [super init]; // because we redefined our own init instead of use the fu..nny awakeFromNib
|
|
if (self != nil) {
|
|
|
|
// 1. instantiate the desired behavior for the remote control device
|
|
remoteControlBehavior = [[MultiClickRemoteBehavior alloc] init];
|
|
|
|
// 2. configure the behavior
|
|
[remoteControlBehavior setDelegate: self];
|
|
|
|
// 3. a Remote Control Container manages a number of devices and conforms to the RemoteControl interface
|
|
// Therefore you can enable or disable all the devices of the container with a single "startListening:" call.
|
|
RemoteControlContainer* container = [[RemoteControlContainer alloc] initWithDelegate: remoteControlBehavior];
|
|
|
|
if ( [container instantiateAndAddRemoteControlDeviceWithClass: [AppleRemote class]] != 0 ) {
|
|
#ifdef DEBUG
|
|
NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [AppleRemote class]] successfull");
|
|
}
|
|
else {
|
|
NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [AppleRemote class]] failed");
|
|
#endif
|
|
}
|
|
|
|
if ( [container instantiateAndAddRemoteControlDeviceWithClass: [KeyspanFrontRowControl class]] != 0 ) {
|
|
#ifdef DEBUG
|
|
NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [KeyspanFrontRowControl class]] successfull");
|
|
}
|
|
else {
|
|
NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [KeyspanFrontRowControl class]] failed");
|
|
#endif
|
|
}
|
|
|
|
if ( [container instantiateAndAddRemoteControlDeviceWithClass: [GlobalKeyboardDevice class]] != 0 ) {
|
|
#ifdef DEBUG
|
|
NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [GlobalKeyboardDevice class]] successfull");
|
|
}
|
|
else {
|
|
NSLog(@"[container instantiateAndAddRemoteControlDeviceWithClass: [GlobalKeyboardDevice class]] failed");
|
|
#endif
|
|
}
|
|
// to give the binding mechanism a chance to see the change of the attribute
|
|
[self setValue: container forKey: @"remoteControl"];
|
|
#ifdef DEBUG
|
|
NSLog(@"MainController init done");
|
|
#endif
|
|
}
|
|
else
|
|
NSLog(@"MainController init failed");
|
|
return self;
|
|
}
|
|
|
|
- (void) postTheEvent: (short int)buttonIdentifier modifierFlags:(int)modifierFlags
|
|
{
|
|
[NSApp postEvent:
|
|
[NSEvent otherEventWithType:NSApplicationDefined
|
|
location:NSZeroPoint
|
|
modifierFlags:modifierFlags
|
|
timestamp: 0
|
|
windowNumber:[[NSApp keyWindow] windowNumber]
|
|
context:nil
|
|
subtype:AppleRemoteControlEvent
|
|
data1: buttonIdentifier
|
|
data2: 0]
|
|
atStart: NO];
|
|
}
|
|
|
|
|
|
- (void) remoteButton: (RemoteControlEventIdentifier)buttonIdentifier pressedDown: (BOOL) pressedDown clickCount: (unsigned int)clickCount
|
|
{
|
|
NSString* pressed = @"";
|
|
#ifdef DEBUG
|
|
NSString* buttonName = nil;
|
|
#endif
|
|
if (pressedDown)
|
|
{
|
|
pressed = @"(pressed)";
|
|
|
|
#ifdef DEBUG
|
|
switch(buttonIdentifier)
|
|
{
|
|
case kRemoteButtonPlus: buttonName = @"Volume up"; break; // MEDIA_COMMAND_VOLUME_UP ( see vcl/inc/vcl/cmdevt.hxx )
|
|
case kRemoteButtonMinus: buttonName = @"Volume down"; break; // MEDIA_COMMAND_VOLUME_DOWN
|
|
case kRemoteButtonMenu: buttonName = @"Menu"; break; // MEDIA_COMMAND_MENU
|
|
case kRemoteButtonPlay: buttonName = @"Play"; break; // MEDIA_COMMAND_PLAY
|
|
case kRemoteButtonRight: buttonName = @"Next slide"; break; // MEDIA_COMMAND_NEXTTRACK
|
|
case kRemoteButtonLeft: buttonName = @"Left"; break; // MEDIA_COMMAND_PREVIOUSTRACK
|
|
case kRemoteButtonRight_Hold: buttonName = @"Last slide"; break; // MEDIA_COMMAND_NEXTTRACK_HOLD
|
|
case kRemoteButtonLeft_Hold: buttonName = @"First slide"; break; // MEDIA_COMMAND_PREVIOUSTRACK_HOLD
|
|
case kRemoteButtonPlus_Hold: buttonName = @"Volume up holding"; break;
|
|
case kRemoteButtonMinus_Hold: buttonName = @"Volume down holding"; break;
|
|
case kRemoteButtonPlay_Hold: buttonName = @"Play (sleep mode)"; break; // MEDIA_COMMAND_PLAY_HOLD
|
|
case kRemoteButtonMenu_Hold: buttonName = @"Menu (long)"; break; // MEDIA_COMMAND_MENU_HOLD
|
|
case kRemoteControl_Switched: buttonName = @"Remote Control Switched";break;
|
|
|
|
default: NSLog(@"Unmapped event for button %d", buttonIdentifier); break;
|
|
}
|
|
#endif
|
|
[ self postTheEvent:buttonIdentifier modifierFlags: 0 ];
|
|
}
|
|
else // not pressed
|
|
{
|
|
pressed = @"(released)";
|
|
}
|
|
|
|
#ifdef DEBUG
|
|
//NSLog(@"Button %@ pressed %@", buttonName, pressed);
|
|
NSString* clickCountString = @"";
|
|
if (clickCount > 1) clickCountString = [NSString stringWithFormat: @"%d clicks", clickCount];
|
|
NSString* feedbackString = [NSString stringWithFormat:@"(Value:%4d) %@ %@ %@",buttonIdentifier, buttonName, pressed, clickCountString];
|
|
|
|
// print out events
|
|
NSLog(@"%@", feedbackString);
|
|
|
|
if (pressedDown == NO) printf("\n");
|
|
// simulate slow processing of events
|
|
// [NSThread sleepUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.5]];
|
|
#endif
|
|
}
|
|
|
|
- (void) dealloc {
|
|
[remoteControl autorelease];
|
|
[remoteControlBehavior autorelease];
|
|
[super dealloc];
|
|
}
|
|
|
|
// for bindings access
|
|
- (RemoteControl*) remoteControl {
|
|
return remoteControl;
|
|
}
|
|
|
|
- (MultiClickRemoteBehavior*) remoteBehavior {
|
|
return remoteControlBehavior;
|
|
}
|
|
|
|
@end |