2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
2002-11-21 12:48:50 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-11-21 12:48:50 +00:00
|
|
|
*/
|
|
|
|
|
2010-06-15 10:47:31 +00:00
|
|
|
#include "common/translation.h"
|
2003-11-10 23:40:48 +00:00
|
|
|
#include "gui/chooser.h"
|
2011-04-24 08:34:27 +00:00
|
|
|
#include "gui/widget.h"
|
2010-11-16 10:11:57 +00:00
|
|
|
#include "gui/widgets/list.h"
|
2003-11-10 23:40:48 +00:00
|
|
|
|
|
|
|
namespace GUI {
|
2002-11-21 12:48:50 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
kChooseCmd = 'Chos'
|
|
|
|
};
|
|
|
|
|
2008-10-15 11:22:22 +00:00
|
|
|
ChooserDialog::ChooserDialog(const String &title, String dialogId)
|
|
|
|
: Dialog(dialogId) {
|
2005-05-20 15:59:29 +00:00
|
|
|
|
2002-11-21 12:48:50 +00:00
|
|
|
// Headline
|
2008-10-15 11:22:22 +00:00
|
|
|
new StaticTextWidget(this, dialogId + ".Headline", title);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-11-21 12:48:50 +00:00
|
|
|
// Add choice list
|
2008-10-15 11:22:22 +00:00
|
|
|
_list = new ListWidget(this, dialogId + ".List");
|
2002-11-21 12:48:50 +00:00
|
|
|
_list->setNumberingMode(kListNumberingOff);
|
2008-12-22 15:40:11 +00:00
|
|
|
_list->setEditable(false);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2002-11-21 12:48:50 +00:00
|
|
|
// Buttons
|
2010-06-15 10:52:35 +00:00
|
|
|
new ButtonWidget(this, dialogId + ".Cancel", _("Cancel"), 0, kCloseCmd);
|
|
|
|
_chooseButton = new ButtonWidget(this, dialogId + ".Choose", _("Choose"), 0, kChooseCmd);
|
2002-11-21 12:48:50 +00:00
|
|
|
_chooseButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2010-03-18 15:09:24 +00:00
|
|
|
void ChooserDialog::setList(const StringArray& list) {
|
2003-11-28 21:56:14 +00:00
|
|
|
_list->setList(list);
|
|
|
|
}
|
|
|
|
|
2003-03-06 19:52:54 +00:00
|
|
|
void ChooserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
2002-11-21 12:48:50 +00:00
|
|
|
int item = _list->getSelected();
|
|
|
|
switch (cmd) {
|
|
|
|
case kChooseCmd:
|
2008-12-22 15:40:11 +00:00
|
|
|
case kListItemActivatedCmd:
|
2002-11-21 12:48:50 +00:00
|
|
|
case kListItemDoubleClickedCmd:
|
2005-03-27 11:27:07 +00:00
|
|
|
_list->endEditMode();
|
2002-11-21 12:48:50 +00:00
|
|
|
setResult(item);
|
|
|
|
close();
|
|
|
|
break;
|
|
|
|
case kListSelectionChangedCmd:
|
|
|
|
_chooseButton->setEnabled(item >= 0);
|
|
|
|
_chooseButton->draw();
|
|
|
|
break;
|
2003-11-03 20:16:23 +00:00
|
|
|
case kCloseCmd:
|
|
|
|
setResult(-1);
|
2002-11-21 12:48:50 +00:00
|
|
|
default:
|
|
|
|
Dialog::handleCommand(sender, cmd, data);
|
|
|
|
}
|
|
|
|
}
|
2003-11-10 23:40:48 +00:00
|
|
|
|
|
|
|
} // End of namespace GUI
|