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.
|
2006-10-08 18:22:28 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "gui/themebrowser.h"
|
2010-11-16 10:11:57 +00:00
|
|
|
#include "gui/widgets/list.h"
|
2006-10-08 18:22:28 +00:00
|
|
|
#include "gui/widget.h"
|
2010-11-16 10:29:31 +00:00
|
|
|
#include "gui/gui-manager.h"
|
2006-11-08 21:31:47 +00:00
|
|
|
|
2010-06-15 10:44:51 +00:00
|
|
|
#include "common/translation.h"
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kChooseCmd = 'Chos'
|
|
|
|
};
|
|
|
|
|
|
|
|
// TODO: this is a rip off of GUI::Browser right now
|
|
|
|
// it will get some more output like theme name,
|
|
|
|
// theme style, theme preview(?) in the future
|
|
|
|
// but for now this simple browser works,
|
|
|
|
// also it will get its own theme config values
|
|
|
|
// and not use 'browser_' anymore
|
2008-08-09 22:40:05 +00:00
|
|
|
ThemeBrowser::ThemeBrowser() : Dialog("Browser") {
|
2006-10-08 18:22:28 +00:00
|
|
|
_fileList = 0;
|
|
|
|
|
2010-06-15 10:44:51 +00:00
|
|
|
new StaticTextWidget(this, "Browser.Headline", _("Select a Theme"));
|
2006-10-08 18:22:28 +00:00
|
|
|
|
|
|
|
// Add file list
|
2008-08-09 22:40:05 +00:00
|
|
|
_fileList = new ListWidget(this, "Browser.List");
|
2006-10-08 18:22:28 +00:00
|
|
|
_fileList->setNumberingMode(kListNumberingOff);
|
|
|
|
_fileList->setEditable(false);
|
|
|
|
|
2008-11-10 11:24:55 +00:00
|
|
|
_backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
|
2006-10-08 18:22:28 +00:00
|
|
|
|
|
|
|
// Buttons
|
2010-06-15 10:52:35 +00:00
|
|
|
new ButtonWidget(this, "Browser.Cancel", _("Cancel"), 0, kCloseCmd);
|
|
|
|
new ButtonWidget(this, "Browser.Choose", _("Choose"), 0, kChooseCmd);
|
2006-10-08 18:22:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeBrowser::open() {
|
|
|
|
// Alway refresh file list
|
|
|
|
updateListing();
|
|
|
|
|
|
|
|
// Call super implementation
|
|
|
|
Dialog::open();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeBrowser::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
|
|
|
|
switch (cmd) {
|
|
|
|
case kChooseCmd:
|
|
|
|
case kListItemActivatedCmd:
|
2006-10-08 19:45:27 +00:00
|
|
|
case kListItemDoubleClickedCmd: {
|
2006-10-08 18:22:28 +00:00
|
|
|
int selection = _fileList->getSelected();
|
|
|
|
if (selection < 0)
|
|
|
|
break;
|
2009-01-02 20:03:45 +00:00
|
|
|
|
2009-05-24 15:17:42 +00:00
|
|
|
// TODO:
|
2009-01-02 21:24:13 +00:00
|
|
|
// Currently ThemeEngine::listUseableThemes uses a
|
2009-01-02 20:03:45 +00:00
|
|
|
// list. Thus we can not use operator[] here but
|
|
|
|
// need to iterate through the list. We might want
|
|
|
|
// to think of changing it, but it should not be
|
|
|
|
// of high importance anyway.
|
|
|
|
ThemeDescList::const_iterator sel = _themes.begin();
|
|
|
|
for (int i = 0; i < selection; ++i)
|
|
|
|
++sel;
|
|
|
|
|
|
|
|
_select = sel->id;
|
2006-10-08 18:22:28 +00:00
|
|
|
setResult(1);
|
|
|
|
close();
|
|
|
|
break;
|
2006-10-08 19:45:27 +00:00
|
|
|
}
|
2006-10-08 18:22:28 +00:00
|
|
|
default:
|
|
|
|
Dialog::handleCommand(sender, cmd, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThemeBrowser::updateListing() {
|
|
|
|
_themes.clear();
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2009-01-02 21:24:13 +00:00
|
|
|
ThemeEngine::listUsableThemes(_themes);
|
2006-10-08 18:22:28 +00:00
|
|
|
|
2009-05-24 15:17:42 +00:00
|
|
|
const Common::String currentThemeId = g_gui.theme()->getThemeId();
|
2009-03-26 20:24:16 +00:00
|
|
|
int currentThemeIndex = 0, index = 0;
|
|
|
|
|
2010-03-18 15:09:24 +00:00
|
|
|
ListWidget::StringArray list;
|
2009-03-26 20:24:16 +00:00
|
|
|
for (ThemeDescList::const_iterator i = _themes.begin(); i != _themes.end(); ++i, ++index) {
|
2006-10-08 18:22:28 +00:00
|
|
|
list.push_back(i->name);
|
|
|
|
|
2009-03-26 20:24:16 +00:00
|
|
|
if (i->id == currentThemeId)
|
|
|
|
currentThemeIndex = index;
|
|
|
|
}
|
|
|
|
|
2006-10-08 18:22:28 +00:00
|
|
|
_fileList->setList(list);
|
|
|
|
_fileList->scrollTo(0);
|
2009-03-26 20:24:16 +00:00
|
|
|
_fileList->setSelected(currentThemeIndex);
|
2006-10-08 18:22:28 +00:00
|
|
|
|
|
|
|
// Finally, redraw
|
|
|
|
draw();
|
|
|
|
}
|
|
|
|
|
2009-10-04 21:26:33 +00:00
|
|
|
} // End of namespace GUI
|