1 /* ScummVM - Graphic Adventure Engine
2 *
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.
6 *
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.
11 *
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.
16 *
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.
20 *
21 */
22
23 #include "common/translation.h"
24 #include "gui/chooser.h"
25 #include "gui/widget.h"
26 #include "gui/widgets/list.h"
27
28 namespace GUI {
29
30 enum {
31 kChooseCmd = 'Chos'
32 };
33
ChooserDialog(const String & title,String dialogId)34 ChooserDialog::ChooserDialog(const String &title, String dialogId)
35 : Dialog(dialogId) {
36
37 // Headline
38 new StaticTextWidget(this, dialogId + ".Headline", title);
39
40 // Add choice list
41 _list = new ListWidget(this, dialogId + ".List");
42 _list->setNumberingMode(kListNumberingOff);
43 _list->setEditable(false);
44
45 // Buttons
46 new ButtonWidget(this, dialogId + ".Cancel", _("Cancel"), 0, kCloseCmd);
47 _chooseButton = new ButtonWidget(this, dialogId + ".Choose", _("Choose"), 0, kChooseCmd);
48 _chooseButton->setEnabled(false);
49 }
50
setList(const StringArray & list)51 void ChooserDialog::setList(const StringArray& list) {
52 _list->setList(list);
53 }
54
handleCommand(CommandSender * sender,uint32 cmd,uint32 data)55 void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
56 int item = _list->getSelected();
57 switch (cmd) {
58 case kChooseCmd:
59 case kListItemActivatedCmd:
60 case kListItemDoubleClickedCmd:
61 _list->endEditMode();
62 setResult(item);
63 close();
64 break;
65 case kListSelectionChangedCmd:
66 _chooseButton->setEnabled(item >= 0);
67 _chooseButton->markAsDirty();
68 break;
69 case kCloseCmd:
70 setResult(-1);
71 // Fall through
72 default:
73 Dialog::handleCommand(sender, cmd, data);
74 }
75 }
76
77 } // End of namespace GUI
78