2 * Copyright (c) 2010, Wei Mingzhi <whistler@openoffice.org>.
5 * Based on: HIDInput by Gil Pedersen.
6 * Copyright (c) 2004, Gil Pedersen.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses>.
22 #import <Cocoa/Cocoa.h>
23 #import "PadController.h"
26 static NSWindow *padWindow;
27 static PadController *padController;
29 #define APP_ID @"net.pcsx.DFInputPlugin"
32 // Get parent application instance
33 NSApplication *app = [NSApplication sharedApplication];
34 NSBundle *bundle = [NSBundle bundleWithIdentifier:APP_ID];
37 NSString *path = [bundle pathForResource:@"Credits" ofType:@"rtf"];
38 NSAttributedString *credits;
40 credits = [[[NSAttributedString alloc] initWithPath: path
41 documentAttributes:NULL] autorelease];
43 credits = [[[NSAttributedString alloc] initWithString:@""] autorelease];
46 // Get Application Icon
47 NSImage *icon = [[NSWorkspace sharedWorkspace] iconForFile:[bundle bundlePath]];
48 NSSize size = NSMakeSize(64, 64);
51 [app orderFrontStandardAboutPanelWithOptions:[NSDictionary dictionaryWithObjectsAndKeys:
52 [bundle objectForInfoDictionaryKey:@"CFBundleName"], @"ApplicationName",
53 icon, @"ApplicationIcon",
54 [bundle objectForInfoDictionaryKey:@"CFBundleShortVersionString"], @"ApplicationVersion",
55 [bundle objectForInfoDictionaryKey:@"CFBundleVersion"], @"Version",
56 [bundle objectForInfoDictionaryKey:@"NSHumanReadableCopyright"], @"Copyright",
57 credits, @"Credits", nil]];
60 long DoConfiguration() {
61 SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_NOPARACHUTE);
64 if (padWindow == nil) {
65 if (padController == nil) {
66 padController = [[PadController alloc] initWithWindowNibName:@"NetPcsxHIDInputPluginMain"];
68 padWindow = [padController window];
72 [padWindow makeKeyAndOrderFront:nil];
77 @implementation PadController
79 - (IBAction)cancel:(id)sender
85 - (IBAction)ok:(id)sender
94 [[NSNotificationCenter defaultCenter] addObserver:self
95 selector:@selector(windowWillClose:)
96 name:NSWindowWillCloseNotification object:[self window]];
98 [controllerView1 addSubview: controllerView];
99 [controllerView setController:0];
102 - (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
104 PadView *newView = nil;
105 if ([[tabViewItem identifier] isEqualToString:@"pad1"])
106 newView = controllerView1;
107 else if ([[tabViewItem identifier] isEqualToString:@"pad2"])
108 newView = controllerView2;
110 if (nil != newView) {
111 [controllerView removeFromSuperviewWithoutNeedingDisplay];
112 [newView addSubview: controllerView];
113 [controllerView setFrame:[newView frame]];
114 [controllerView setController:[newView isEqual:controllerView1] ? 0 : 1];
118 - (void)windowBecameKey:(NSNotification *)notification
120 if ([[controllerView1 subviews] count] > 0)
121 [controllerView setController:0];
122 else if ([[controllerView2 subviews] count] > 0)
123 [controllerView setController:1];
125 [[NSNotificationCenter defaultCenter] removeObserver:self
126 name:NSWindowDidBecomeKeyNotification object:[self window]];
129 - (void)windowWillClose:(NSNotification *)aNotification
131 if ([aNotification object] == [self window]) {
132 [[NSNotificationCenter defaultCenter] addObserver:self
133 selector:@selector(windowBecameKey:)
134 name:NSWindowDidBecomeKeyNotification object:[self window]];