2002-11-21 12:48:50 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2004-01-06 12:45:34 +00:00
|
|
|
* Copyright (C) 2002-2004 The ScummVM project
|
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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2003-08-10 20:57:41 +00:00
|
|
|
#include "stdafx.h"
|
2003-11-10 23:40:48 +00:00
|
|
|
#include "gui/chooser.h"
|
|
|
|
#include "gui/newgui.h"
|
|
|
|
#include "gui/ListWidget.h"
|
|
|
|
|
|
|
|
namespace GUI {
|
2002-11-21 12:48:50 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
kChooseCmd = 'Chos'
|
|
|
|
};
|
|
|
|
|
2003-11-28 21:56:14 +00:00
|
|
|
ChooserDialog::ChooserDialog(const String &title, const String &buttonLabel, int height)
|
2003-11-08 23:22:16 +00:00
|
|
|
: Dialog(8, (200 - height) / 2, 320 - 2 * 8, height) {
|
2002-11-21 12:48:50 +00:00
|
|
|
// Headline
|
2003-11-03 20:16:23 +00:00
|
|
|
new StaticTextWidget(this, 10, 6, _w - 2 * 10, kLineHeight, title, kTextAlignCenter);
|
2003-03-06 19:52:54 +00:00
|
|
|
|
2002-11-21 12:48:50 +00:00
|
|
|
// Add choice list
|
2003-11-03 20:16:23 +00:00
|
|
|
_list = new ListWidget(this, 10, 18, _w - 2 * 10, _h - 14 - 24 - 10);
|
2002-11-21 12:48:50 +00:00
|
|
|
_list->setNumberingMode(kListNumberingOff);
|
|
|
|
|
|
|
|
// Buttons
|
2003-03-06 19:52:54 +00:00
|
|
|
addButton(_w - 2 * (kButtonWidth + 10), _h - 24, "Cancel", kCloseCmd, 0);
|
2003-11-03 20:16:23 +00:00
|
|
|
_chooseButton = addButton(_w-(kButtonWidth + 10), _h - 24, buttonLabel, kChooseCmd, 0);
|
2002-11-21 12:48:50 +00:00
|
|
|
_chooseButton->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
2003-11-28 21:56:14 +00:00
|
|
|
void ChooserDialog::setList(const StringList& list) {
|
|
|
|
_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:
|
|
|
|
case kListItemDoubleClickedCmd:
|
|
|
|
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
|