ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

themebrowser.cpp

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "gui/themebrowser.h"
00024 #include "gui/widgets/list.h"
00025 #include "gui/widget.h"
00026 #include "gui/gui-manager.h"
00027 
00028 #include "common/translation.h"
00029 
00030 namespace GUI {
00031 
00032 enum {
00033     kChooseCmd = 'Chos'
00034 };
00035 
00036 // TODO: this is a rip off of GUI::Browser right now
00037 // it will get some more output like theme name,
00038 // theme style, theme preview(?) in the future
00039 // but for now this simple browser works,
00040 // also it will get its own theme config values
00041 // and not use 'browser_' anymore
00042 ThemeBrowser::ThemeBrowser() : Dialog("Browser") {
00043     _fileList = 0;
00044 
00045     new StaticTextWidget(this, "Browser.Headline", _("Select a Theme"));
00046 
00047     // Add file list
00048     _fileList = new ListWidget(this, "Browser.List");
00049     _fileList->setNumberingMode(kListNumberingOff);
00050     _fileList->setEditable(false);
00051 
00052     _backgroundType = GUI::ThemeEngine::kDialogBackgroundPlain;
00053 
00054     // Buttons
00055     new ButtonWidget(this, "Browser.Cancel", _("Cancel"), 0, kCloseCmd);
00056     new ButtonWidget(this, "Browser.Choose", _("Choose"), 0, kChooseCmd);
00057 }
00058 
00059 void ThemeBrowser::open() {
00060     // Alway refresh file list
00061     updateListing();
00062 
00063     // Call super implementation
00064     Dialog::open();
00065 }
00066 
00067 void ThemeBrowser::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
00068     switch (cmd) {
00069     case kChooseCmd:
00070     case kListItemActivatedCmd:
00071     case kListItemDoubleClickedCmd: {
00072         int selection = _fileList->getSelected();
00073         if (selection < 0)
00074             break;
00075 
00076         // TODO:
00077         // Currently ThemeEngine::listUseableThemes uses a
00078         // list. Thus we can not use operator[] here but
00079         // need to iterate through the list. We might want
00080         // to think of changing it, but it should not be
00081         // of high importance anyway.
00082         ThemeDescList::const_iterator sel = _themes.begin();
00083         for (int i = 0; i < selection; ++i)
00084             ++sel;
00085 
00086         _select = sel->id;
00087         _selectName = sel->name;
00088         setResult(1);
00089         close();
00090         break;
00091     }
00092     default:
00093         Dialog::handleCommand(sender, cmd, data);
00094     }
00095 }
00096 
00097 void ThemeBrowser::updateListing() {
00098     _themes.clear();
00099 
00100     ThemeEngine::listUsableThemes(_themes);
00101 
00102     const Common::String currentThemeId = g_gui.theme()->getThemeId();
00103     int currentThemeIndex = 0, index = 0;
00104 
00105     ListWidget::StringArray list;
00106     for (ThemeDescList::const_iterator i = _themes.begin(); i != _themes.end(); ++i, ++index) {
00107         list.push_back(i->name);
00108 
00109         if (i->id == currentThemeId)
00110             currentThemeIndex = index;
00111     }
00112 
00113     _fileList->setList(list);
00114     _fileList->scrollTo(0);
00115     _fileList->setSelected(currentThemeIndex);
00116 
00117     // Finally, redraw
00118     g_gui.scheduleTopDialogRedraw();
00119 }
00120 
00121 } // End of namespace GUI


Generated on Sat May 18 2019 05:01:22 for ResidualVM by doxygen 1.7.1
curved edge   curved edge