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>.
25 @implementation PadView
27 - (id)initWithFrame:(NSRect)frameRect
29 if ((self = [super initWithFrame:frameRect]) != nil) {
30 controller = [[ControllerList alloc] initWithConfig];
31 [self setController:0];
42 - (void)drawRect:(NSRect)rect
46 - (IBAction)setType:(id)sender
48 g.cfg.PadDef[[ControllerList currentController]].Type =
49 ([sender indexOfSelectedItem] > 0 ? PSE_PAD_TYPE_ANALOGPAD : PSE_PAD_TYPE_STANDARD);
51 [tableView reloadData];
54 - (IBAction)setDevice:(id)sender
56 g.cfg.PadDef[[ControllerList currentController]].DevNum = (int)[sender indexOfSelectedItem] - 1;
59 - (void)setController:(int)which
63 [ControllerList setCurrentController:which];
64 [tableView setDataSource:controller];
66 [deviceMenu removeAllItems];
67 [deviceMenu addItemWithTitle:@"(Keyboard only)"];
69 for (i = 0; i < SDL_NumJoysticks(); i++) {
70 [deviceMenu addItemWithTitle:[NSString stringWithUTF8String:SDL_JoystickName(i)]];
73 if (g.cfg.PadDef[which].DevNum >= SDL_NumJoysticks()) {
74 g.cfg.PadDef[which].DevNum = -1;
77 [deviceMenu selectItemAtIndex:g.cfg.PadDef[which].DevNum + 1];
78 [typeMenu selectItemAtIndex:(g.cfg.PadDef[which].Type == PSE_PAD_TYPE_ANALOGPAD ? 1 : 0)];
80 [tableView reloadData];
84 - (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor
89 /* handles key events on the pad list */
90 - (void)keyDown:(NSEvent *)theEvent
92 int key = [theEvent keyCode];
94 if ([[theEvent window] firstResponder] == tableView) {
95 if (key == 51 || key == 117) {
96 // delete keys - remove the mappings for the selected item
97 [controller deleteRow:[tableView selectedRow]];
98 [tableView reloadData];
100 } else if (key == 36) {
101 // return key - configure the selected item
102 [tableView editColumn:[tableView columnWithIdentifier:@"button"] row:[tableView selectedRow] withEvent:nil select:YES];
107 [super keyDown:theEvent];