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 "ControllerList.h"
26 static int currentController;
28 @implementation ControllerList
32 if (!(self = [super init])) return nil;
41 /* sets current controller data returned by data source */
42 + (void)setCurrentController:(int)which
44 currentController = which;
47 + (int)currentController
49 return currentController;
53 - (int)numberOfRowsInTableView:(NSTableView *)aTableView
55 return DKEY_TOTAL + (g.cfg.PadDef[currentController].Type == PSE_PAD_TYPE_ANALOGPAD ? 8 : -2);
58 static const NSString *LabelText[DKEY_TOTAL + 8] = {
85 static const int DPad[DKEY_TOTAL] = {
104 + (int)getButtonOfRow:(int)row
109 - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn
114 if ([((NSString *)[aTableColumn identifier]) isEqualToString:@"key"])
115 return LabelText[rowIndex];
118 if (rowIndex < DKEY_TOTAL) {
119 GetKeyDescription(buf, currentController, DPad[rowIndex]);
121 rowIndex -= DKEY_TOTAL;
122 GetAnalogDescription(buf, currentController, rowIndex / 4, rowIndex % 4);
125 return [NSString stringWithUTF8String:buf];
129 - (void)deleteRow:(int)which
131 if (which < DKEY_TOTAL) {
132 g.cfg.PadDef[currentController].KeyDef[DPad[which]].Key = 0;
133 g.cfg.PadDef[currentController].KeyDef[DPad[which]].JoyEvType = NONE;
134 g.cfg.PadDef[currentController].KeyDef[DPad[which]].J.d = 0;
137 g.cfg.PadDef[currentController].AnalogDef[which / 4][which % 4].Key = 0;
138 g.cfg.PadDef[currentController].AnalogDef[which / 4][which % 4].JoyEvType = NONE;
139 g.cfg.PadDef[currentController].AnalogDef[which / 4][which % 4].J.d = 0;