0x47 stub
[scummvm-innocent.git] / gui / KeysDialog.cpp
blob7a9256e30f4428aeb0b45faed0ac832f355c3e82
1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * $URL$
22 * $Id$
26 #include "gui/KeysDialog.h"
27 #include "gui/Actions.h"
28 #include <SDL_keyboard.h>
30 #ifdef _WIN32_WCE
31 #include "CEDevice.h"
32 #endif
34 namespace GUI {
36 enum {
37 kMapCmd = 'map ',
38 kOKCmd = 'ok '
41 KeysDialog::KeysDialog(const Common::String &title)
42 : GUI::Dialog("KeysDialog") {
44 new ButtonWidget(this, "KeysDialog.Map", "Map", kMapCmd, 0);
45 new ButtonWidget(this, "KeysDialog.Ok", "OK", kOKCmd, 0);
46 new ButtonWidget(this, "KeysDialog.Cancel", "Cancel", kCloseCmd, 0);
48 _actionsList = new ListWidget(this, "KeysDialog.List");
49 _actionsList->setNumberingMode(kListNumberingZero);
51 _actionTitle = new StaticTextWidget(this, "KeysDialog.Action", title);
52 _keyMapping = new StaticTextWidget(this, "KeysDialog.Mapping", "Select an action and click 'Map'");
54 _actionTitle->setFlags(WIDGET_CLEARBG);
55 _keyMapping->setFlags(WIDGET_CLEARBG);
57 // Get actions names
58 Common::StringList l;
60 for (int i = 0; i < Actions::Instance()->size(); i++)
61 l.push_back(Actions::Instance()->actionName((ActionType)i));
63 _actionsList->setList(l);
65 _actionSelected = -1;
66 Actions::Instance()->beginMapping(false);
69 void KeysDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
70 switch (cmd) {
72 case kListSelectionChangedCmd:
73 if (_actionsList->getSelected() >= 0) {
74 char selection[100];
76 uint16 key = Actions::Instance()->getMapping(_actionsList->getSelected());
77 #ifdef __SYMBIAN32__
78 // ScummVM mappings for F1-F9 are different from SDL so remap back to sdl
79 if (key >= Common::ASCII_F1 && key <= Common::ASCII_F9)
80 key = key - Common::ASCII_F1 + SDLK_F1;
81 #endif
82 if (key != 0)
83 sprintf(selection, "Associated key : %s", SDL_GetKeyName((SDLKey)key));
84 else
85 sprintf(selection, "Associated key : none");
87 _keyMapping->setLabel(selection);
88 _keyMapping->draw();
90 break;
91 case kMapCmd:
92 if (_actionsList->getSelected() < 0) {
93 _actionTitle->setLabel("Please select an action");
94 } else {
95 char selection[100];
97 _actionSelected = _actionsList->getSelected();
98 uint16 key = Actions::Instance()->getMapping(_actionSelected);
99 #ifdef __SYMBIAN32__
100 // ScummVM mappings for F1-F9 are different from SDL so remap back to sdl
101 if (key >= Common::ASCII_F1 && key <= Common::ASCII_F9)
102 key = key - Common::ASCII_F1 + SDLK_F1;
103 #endif
104 if (key != 0)
105 sprintf(selection, "Associated key : %s", SDL_GetKeyName((SDLKey)key));
106 else
107 sprintf(selection, "Associated key : none");
109 _actionTitle->setLabel("Press the key to associate");
110 _keyMapping->setLabel(selection);
111 _keyMapping->draw();
112 Actions::Instance()->beginMapping(true);
113 _actionsList->setEnabled(false);
115 _actionTitle->draw();
116 break;
117 case kOKCmd:
118 Actions::Instance()->saveMapping();
119 close();
120 break;
121 case kCloseCmd:
122 Actions::Instance()->loadMapping();
123 close();
124 break;
128 void KeysDialog::handleKeyDown(Common::KeyState state){
129 if (!Actions::Instance()->mappingActive())
130 Dialog::handleKeyDown(state);
133 void KeysDialog::handleKeyUp(Common::KeyState state) {
134 #ifdef __SYMBIAN32__
135 if (Actions::Instance()->mappingActive()) {
136 #else
137 if (state.flags == 0xff && Actions::Instance()->mappingActive()) { // GAPI key was selected
138 #endif
139 char selection[100];
141 Actions::Instance()->setMapping((ActionType)_actionSelected, state.ascii);
143 if (state.ascii != 0)
144 sprintf(selection, "Associated key : %s", SDL_GetKeyName((SDLKey) state.keycode));
145 else
146 sprintf(selection, "Associated key : none");
148 _actionTitle->setLabel("Choose an action to map");
149 _keyMapping->setLabel(selection);
150 _keyMapping->draw();
151 _actionTitle->draw();
152 _actionSelected = -1;
153 _actionsList->setEnabled(true);
154 Actions::Instance()->beginMapping(false);
155 } else
156 Dialog::handleKeyUp(state);
159 } // namespace GUI