[Scummvm-cvs-logs] SF.net SVN: scummvm:[41738] tools/branches/gsoc2009-gui/gui
Remere at users.sourceforge.net
Remere at users.sourceforge.net
Mon Jun 22 02:50:50 CEST 2009
Revision: 41738
http://scummvm.svn.sourceforge.net/scummvm/?rev=41738&view=rev
Author: Remere
Date: 2009-06-22 00:50:49 +0000 (Mon, 22 Jun 2009)
Log Message:
-----------
*Rewrote how pages work, the WizardPage class is no longer a window, but rather knows how to make a representation out of itself, and read data back in from the created window.
Modified Paths:
--------------
tools/branches/gsoc2009-gui/gui/main.cpp
tools/branches/gsoc2009-gui/gui/main.h
tools/branches/gsoc2009-gui/gui/pages.cpp
tools/branches/gsoc2009-gui/gui/pages.h
tools/branches/gsoc2009-gui/gui/tools.cpp
Modified: tools/branches/gsoc2009-gui/gui/main.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/main.cpp 2009-06-22 00:35:08 UTC (rev 41737)
+++ tools/branches/gsoc2009-gui/gui/main.cpp 2009-06-22 00:50:49 UTC (rev 41738)
@@ -97,57 +97,61 @@
_buttons = new WizardButtons(main, linetext);
sizer->Add(_buttons, wxSizerFlags().Border().Right());
+ // Create input page
+ WizardPage *introPage = new IntroPage(this);
+
// We create the intro page once the window is setup
wxSizer *panesizer = new wxBoxSizer(wxVERTICAL);
- WizardPage *introPage = new IntroPage(_wizardpane);
- panesizer->Add(introPage, wxSizerFlags(1).Expand());
+ wxWindow *introPanel = introPage->CreatePanel(_wizardpane);
+ panesizer->Add(introPanel, wxSizerFlags(1).Expand());
_wizardpane->SetSizerAndFit(panesizer);
-
main->SetSizer(sizer);
+ // Set current page
+ _pages.push_back(introPage);
+
// And reset the buttons to a standard state
- _buttons->setPage(introPage);
+ _buttons->setPage(introPage, introPanel);
}
ScummToolsFrame::~ScummToolsFrame() {
- for(std::vector<WizardPageClass *>::iterator iter = _previousPages.begin(); iter != _previousPages.end(); ++iter)
+ for(std::vector<WizardPage *>::iterator iter = _pages.begin(); iter != _pages.end(); ++iter)
delete *iter;
}
-void ScummToolsFrame::SwitchPage(WizardPage *next) {
+void ScummToolsFrame::switchPage(WizardPage *next, bool moveback) {
// Find the old page
- WizardPage *old = dynamic_cast<WizardPage*>(_wizardpane->FindWindow(wxT("Wizard Page")));
+ wxPanel *oldPanel = dynamic_cast<wxPanel *>(_wizardpane->FindWindow(wxT("Wizard Page")));
- wxASSERT_MSG(old, wxT("Expected the child 'Wizard Page' to be an actual Wizard Page window."));
+ _pages.back()->save(oldPanel, configuration);
- old->save(configuration);
+ if(moveback) {
+ // Don't save the old page (which is ontop of the stack already)
+ delete _pages.back();
+ _pages.pop_back();
+ } else {
+ _pages.push_back(next);
+ }
- // Save the old page
- _previousPages.push_back(old->getClass());
-
// Destroy the old page
- old->Destroy();
+ oldPanel->Destroy();
- next->load(configuration);
+ wxWindow *newPanel = _pages.back()->CreatePanel(_wizardpane);
// Add the new page!
- next->Reparent(_wizardpane);
- _wizardpane->GetSizer()->Add(next, wxSizerFlags(1).Expand());
+ _wizardpane->GetSizer()->Add(newPanel, wxSizerFlags(1).Expand());
// Make sure it fits
_wizardpane->Fit();
// And reset the buttons to a standard state
_buttons->reset();
- _buttons->setPage(next);
+ _buttons->setPage(_pages.back(), newPanel);
}
-void ScummToolsFrame::SwitchToPreviousPage() {
- WizardPage *prev = _previousPages.back()->create(_wizardpane);
- delete _previousPages.back();
- _previousPages.pop_back();
- SwitchPage(prev);
+void ScummToolsFrame::switchToPreviousPage() {
+ switchPage(NULL, true);
}
BEGIN_EVENT_TABLE(WizardButtons, wxPanel)
@@ -188,13 +192,14 @@
showFinish(false);
}
-void WizardButtons::setPage(WizardPage *current) {
+void WizardButtons::setPage(WizardPage *current, wxWindow *panel) {
_currentPage = current;
+ _currentPanel = panel;
// We call onUpdateButtons, which sets the _buttons member of WizardPage
// to this, and in turn calls updateButtons on itself and sets up the buttons
// We cannot set this up in the constructor of the WizardPage, since it's impossible
// to call reset *before* the page is created from SwicthPage
- current->onUpdateButtons(this);
+ _currentPage->updateButtons(_currentPanel, this);
}
void WizardButtons::enableNext(bool enable) {
@@ -224,18 +229,17 @@
// wx event handlers
void WizardButtons::onClickNext(wxCommandEvent &e) {
wxASSERT(_currentPage);
- _currentPage->Hide();
- _currentPage->onNext();
+ _currentPage->onNext(_currentPanel);
}
void WizardButtons::onClickPrevious(wxCommandEvent &e) {
wxASSERT(_currentPage);
- _currentPage->onPrevious();
+ _currentPage->onPrevious(_currentPanel);
}
void WizardButtons::onClickCancel(wxCommandEvent &e) {
wxASSERT(_currentPage);
- _currentPage->onCancel();
+ _currentPage->onCancel(_currentPanel);
}
BEGIN_EVENT_TABLE(Header, wxPanel)
Modified: tools/branches/gsoc2009-gui/gui/main.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/main.h 2009-06-22 00:35:08 UTC (rev 41737)
+++ tools/branches/gsoc2009-gui/gui/main.h 2009-06-22 00:50:49 UTC (rev 41738)
@@ -48,17 +48,18 @@
~ScummToolsFrame();
// Switches to this page and resets the buttons
- void SwitchPage(WizardPage *nextPage);
+ void switchPage(WizardPage *nextPage, bool moveback = false);
// Switches to the previous page
- void SwitchToPreviousPage();
+ void switchToPreviousPage();
+ Configuration configuration;
+
private:
- Configuration configuration;
wxPanel *_wizardpane;
WizardButtons *_buttons;
- std::vector<WizardPageClass *> _previousPages;
+ std::vector<WizardPage *> _pages;
DECLARE_EVENT_TABLE()
};
@@ -77,7 +78,7 @@
// Set the current wizard page, done from SwitchPage required
// for the buttons to know where to drop their events
- void setPage(WizardPage *current);
+ void setPage(WizardPage *current, wxWindow *panel);
// Set the label of the line above the buttons, can display some useful info here
void setLineLabel(wxString label);
@@ -104,6 +105,7 @@
wxButton *_cancel;
wxStaticText *_linetext;
WizardPage *_currentPage;
+ wxWindow *_currentPanel;
DECLARE_EVENT_TABLE()
};
Modified: tools/branches/gsoc2009-gui/gui/pages.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.cpp 2009-06-22 00:35:08 UTC (rev 41737)
+++ tools/branches/gsoc2009-gui/gui/pages.cpp 2009-06-22 00:50:49 UTC (rev 41738)
@@ -34,93 +34,70 @@
#include "pages.h"
#include "tools.h"
-WizardPage::WizardPage(wxWindow *parent)
- : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxT("Wizard Page")),
- _buttons(NULL)
+WizardPage::WizardPage(ScummToolsFrame *frame)
+ : _topframe(frame)
{
}
-void WizardPage::updateButtons() {
- // Do nothing
+wxWindow *WizardPage::CreatePanel(wxWindow *parent) {
+ return new wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxT("Wizard Page"));
}
-void WizardPage::SetAlignedSizer(wxSizer *sizer) {
+void WizardPage::switchPage(WizardPage *next) {
+ _topframe->switchPage(next);
+}
+
+void WizardPage::updateButtons(wxWindow *panel, WizardButtons *buttons) {
+ // Do nothing, keep default button state
+}
+
+void WizardPage::SetAlignedSizer(wxWindow *panel, wxSizer *sizer) {
wxSizer *topsizer = new wxBoxSizer(wxHORIZONTAL);
topsizer->AddSpacer(100);
topsizer->Add(sizer);
- SetSizer(topsizer);
+ panel->SetSizer(topsizer);
}
-void WizardPage::SwitchPage(WizardPage *next) {
- wxWindow *grandparent = GetParent();
- while(grandparent->GetParent() != NULL)
- grandparent = grandparent->GetParent();
-
- if(grandparent) {
- ScummToolsFrame *frame = dynamic_cast<ScummToolsFrame*>(grandparent);
- frame->SwitchPage(next);
- // We are probably dead now, make sure to do nothing
- // involving member variabls after this point
- }
-}
-
// Our default handler for next/prev/cancel
-void WizardPage::onNext() {
+void WizardPage::onNext(wxWindow *panel) {
}
-void WizardPage::onPrevious() {
- wxWindow *grandparent = GetParent();
- while(grandparent->GetParent() != NULL)
- grandparent = grandparent->GetParent();
-
- if(grandparent) {
- ScummToolsFrame *frame = dynamic_cast<ScummToolsFrame*>(grandparent);
- frame->SwitchToPreviousPage();
- // We are probably dead now, make sure to do nothing
- // involving member variabls after this point
- }
+void WizardPage::onPrevious(wxWindow *panel) {
+ _topframe->switchToPreviousPage();
}
-void WizardPage::onCancel() {
- wxMessageDialog dlg(this, wxT("Are you sure you want to abort the wizard?"), wxT("Abort"), wxYES | wxNO);
+void WizardPage::onCancel(wxWindow *panel) {
+ wxMessageDialog dlg(panel, wxT("Are you sure you want to abort the wizard?"), wxT("Abort"), wxYES | wxNO);
wxWindowID ret = dlg.ShowModal();
if(ret == wxID_YES) {
- wxWindow *grandparent = GetParent();
- while(grandparent->GetParent() != NULL)
- grandparent = grandparent->GetParent();
-
- grandparent->Close(true);
+ _topframe->Close(true);
} else {
// Do nothing
}
}
-void WizardPage::onUpdateButtons(WizardButtons *buttons) {
- // We have this functions to avoid having to this in every child handler
- _buttons = buttons;
- updateButtons();
-}
-
// Load/Save settings
-void WizardPage::load(Configuration &configuration) {
+void WizardPage::save(wxWindow *panel, Configuration &configuration) {
}
-void WizardPage::save(Configuration &configuration) {
-}
-
// Introduction page
-IntroPage::IntroPage(wxWindow *parent)
- : WizardPage(parent)
+IntroPage::IntroPage(ScummToolsFrame* frame)
+ : WizardPage(frame)
{
+}
+
+wxWindow *IntroPage::CreatePanel(wxWindow *parent) {
+ wxWindow *panel = WizardPage::CreatePanel(parent);
+
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->AddSpacer(15);
- sizer->Add(new wxStaticText(this, wxID_ANY,
+ sizer->Add(new wxStaticText(panel, wxID_ANY,
wxT("Welcome to the ScummVM extraction and compression utility.")));
- sizer->Add(new wxStaticText(this, wxID_ANY,
+ sizer->Add(new wxStaticText(panel, wxID_ANY,
wxT("Please select what you want to do, or drop a file or folder on this window for automatic .")));
wxString choices[] = {
@@ -129,55 +106,66 @@
wxT("Choose tool to use (advanced)")
};
- _options = new wxRadioBox(this, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 3, choices, 1, wxRA_SPECIFY_COLS | wxBORDER_NONE);
- sizer->Add(_options);
- _options->SetSelection(0);
+ wxRadioBox *options = new wxRadioBox(panel, wxID_ANY, wxT(""),
+ wxDefaultPosition, wxDefaultSize, 3, choices, 1,
+ wxRA_SPECIFY_COLS | wxBORDER_NONE, wxDefaultValidator, wxT("ChooseActivity"));
+ sizer->Add(options);
+ options->SetSelection(0);
- SetAlignedSizer(sizer);
-}
+ SetAlignedSizer(panel, sizer);
-void IntroPage::updateButtons() {
- _buttons->showPrevious(false);
- _buttons->enableNext(true);
-}
-
-void IntroPage::load(Configuration &config) {
- // TODO use generic way to get indexes
+ // Load options
+ Configuration &config = _topframe->configuration;
if(config.advanced)
- _options->SetSelection(2);
+ options->SetSelection(2);
else if(config.compressing)
- _options->SetSelection(1);
+ options->SetSelection(1);
else
- _options->SetSelection(0);
+ options->SetSelection(0);
+
+ return panel;
}
-void IntroPage::save(Configuration &config) {
- config.advanced = _options->GetStringSelection().Lower().Find(wxT("advanced")) != wxNOT_FOUND;
- config.compressing = _options->GetStringSelection().Lower().Find(wxT("extract")) == wxNOT_FOUND;
+void IntroPage::updateButtons(wxWindow *panel, WizardButtons *buttons) {
+ buttons->showPrevious(false);
+ buttons->enableNext(true);
}
-void IntroPage::onNext() {
- if(_options->GetStringSelection().Lower().Find(wxT("extract")) != wxNOT_FOUND) {
+void IntroPage::save(wxWindow *panel, Configuration &config) {
+ wxString selected_option = static_cast<wxRadioBox *>(panel->FindWindowByName(wxT("")))->GetStringSelection().Lower();
+
+ config.advanced = selected_option.Find(wxT("advanced")) != wxNOT_FOUND;
+ config.compressing = selected_option.Find(wxT("extract")) == wxNOT_FOUND;
+}
+
+void IntroPage::onNext(wxWindow *panel) {
+ wxString selected_option = static_cast<wxRadioBox *>(panel->FindWindowByName(wxT("")))->GetStringSelection().Lower();
+ if(selected_option.Find(wxT("extract")) != wxNOT_FOUND) {
// extract
- } else if(_options->GetStringSelection().Lower().Find(wxT("advanced")) != wxNOT_FOUND) {
+ } else if(selected_option.Find(wxT("advanced")) != wxNOT_FOUND) {
// advanced
- SwitchPage(new ChooseToolPage(this->GetParent()));
+ _topframe->switchPage(new ChooseToolPage(_topframe));
} else {
// compress
- SwitchPage(new ChooseCompressionPage(this->GetParent()));
+ _topframe->switchPage(new ChooseCompressionPage(_topframe));
}
}
// Page to choose what game files to compress
-ChooseCompressionPage::ChooseCompressionPage(wxWindow *parent)
- : WizardPage(parent)
+ChooseCompressionPage::ChooseCompressionPage(ScummToolsFrame* frame)
+ : WizardPage(frame)
{
+}
+
+wxWindow *ChooseCompressionPage::CreatePanel(wxWindow *parent) {
+ wxWindow *panel = WizardPage::CreatePanel(parent);
+
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->AddSpacer(15);
- sizer->Add(new wxStaticText(this, wxID_ANY,
+ sizer->Add(new wxStaticText(panel, wxID_ANY,
wxT("Please select for what game/engine you'd like to compress files.")));
// This list is most likely incomplete
@@ -233,33 +221,42 @@
// Sort the array for display
choices.Sort();
- _game = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
- sizer->Add(_game);
- _game->SetSelection(0);
+ wxChoice *game = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
+ choices, 0, wxDefaultValidator, wxT("GameSelection"));
+ sizer->Add(game);
+ game->SetSelection(0);
- SetAlignedSizer(sizer);
-}
+ SetAlignedSizer(panel, sizer);
+ // Load already set values
+ game->SetStringSelection(_topframe->configuration.selectedGame);
-// Load/Save settings
-void ChooseCompressionPage::load(Configuration &config) {
- _game->SetStringSelection(config.selectedGame);
+
+ return panel;
}
-void ChooseCompressionPage::save(Configuration &config) {
- config.selectedGame = _game->GetStringSelection();
+// Load/Save settings
+
+void ChooseCompressionPage::save(wxWindow *panel, Configuration &config) {
+ wxString game = static_cast<wxChoice *>(panel->FindWindowByName(wxT("GameSelection")))->GetStringSelection();
+ config.selectedGame = game;
}
// Page to choose ANY tool to use
-ChooseToolPage::ChooseToolPage(wxWindow *parent)
- : WizardPage(parent)
+ChooseToolPage::ChooseToolPage(ScummToolsFrame* frame)
+ : WizardPage(frame)
{
+}
+
+wxWindow *ChooseToolPage::CreatePanel(wxWindow *parent) {
+ wxWindow *panel = WizardPage::CreatePanel(parent);
+
wxSizer *sizer = new wxBoxSizer(wxVERTICAL);
sizer->AddSpacer(15);
- sizer->Add(new wxStaticText(this, wxID_ANY,
+ sizer->Add(new wxStaticText(panel, wxID_ANY,
wxT("Select what tool you'd like to use.")));
// This list is most likely incomplete
@@ -269,19 +266,20 @@
// they're stored in a ordered tree but you can never be too safe)
choices.Sort();
- _tool = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, choices);
- sizer->Add(_tool);
- _tool->SetSelection(0);
+ wxChoice *tool = new wxChoice(panel, wxID_ANY, wxDefaultPosition, wxDefaultSize,
+ choices, 0, wxDefaultValidator, wxT("ToolSelection"));
+ sizer->Add(tool);
+ tool->SetSelection(0);
- SetAlignedSizer(sizer);
-}
+ SetAlignedSizer(panel, sizer);
+ // Load configuration
+ tool->SetStringSelection(_topframe->configuration.selectedTool);
-// Load/Save settings
-void ChooseToolPage::load(Configuration &config) {
- _tool->SetStringSelection(config.selectedTool);
+ return panel;
}
-void ChooseToolPage::save(Configuration &config) {
- config.selectedTool = _tool->GetStringSelection();
+// Load/Save settings
+void ChooseToolPage::save(wxWindow *panel, Configuration &config) {
+ config.selectedTool = static_cast<wxChoice *>(panel->FindWindowByName(wxT("ToolSelection")))->GetStringSelection();
}
Modified: tools/branches/gsoc2009-gui/gui/pages.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.h 2009-06-22 00:35:08 UTC (rev 41737)
+++ tools/branches/gsoc2009-gui/gui/pages.h 2009-06-22 00:50:49 UTC (rev 41738)
@@ -24,49 +24,40 @@
#include "configuration.h"
-struct WizardPageClass {
- virtual WizardPage *create(wxWindow *parent) = 0;
-};
-
-template <typename T>
-struct WizardPageClass_ : public WizardPageClass {
- virtual WizardPage *create(wxWindow *parent) {return new T(parent);}
-};
-
// Wizard Page
// A page in the extraction wizard
-class WizardPage : public wxPanel
+class WizardPage : public wxEvtHandler
{
public:
- WizardPage(wxWindow *parent);
- virtual void updateButtons();
- virtual WizardPageClass *getClass() = 0;
+ WizardPage(ScummToolsFrame* frame);
+ ~WizardPage() {
+;
+ }
- // This adds an offset (about 100px) to the left of the sizer
- // to center the text somewhat, before adding it to the panel
- void SetAlignedSizer(wxSizer *sizer);
+ // Creates a visual representation of this page as a child problem of the supplied parent
+ virtual wxWindow *CreatePanel(wxWindow *parent);
- // This calls parent -> SwitchPage
- // This page WILL BE DELETED
- // You should return out of this class immedietly after calling this function
- void SwitchPage(WizardPage *next);
+ void switchPage(WizardPage *next);
- // Load/Save configuration
- virtual void load(Configuration &configuration);
- virtual void save(Configuration &configuration);
+ // Load/Save configuration, reads data from the panel supplied
+ virtual void save(wxWindow *panel, Configuration &configuration);
// Event handlers
// overload these to handle prev/next/cancel clicks
- virtual void onNext();
- virtual void onPrevious();
- virtual void onCancel(); // Default is to display 'Are you sure' and quit if you click 'Yes'
+ virtual void onNext(wxWindow *panel);
+ virtual void onPrevious(wxWindow *panel);
+ virtual void onCancel(wxWindow *panel); // Default is to display 'Are you sure' and quit if you click 'Yes'
- // Calls updateButtons
- void onUpdateButtons(WizardButtons *buttons);
+ // Update button states
+ virtual void updateButtons(wxWindow *panel, WizardButtons *buttons);
protected:
- WizardButtons *_buttons;
+ // This adds an offset (about 100px) to the left of the sizer
+ // to center the text somewhat, before adding it to the panel
+ void SetAlignedSizer(wxWindow *panel, wxSizer *sizer);
+
+ ScummToolsFrame* _topframe;
};
// Introduction page, with options to extract/compress
@@ -74,42 +65,33 @@
class IntroPage : public WizardPage
{
public:
- IntroPage(wxWindow *parent);
- virtual void updateButtons();
- virtual WizardPageClass *getClass() {return new WizardPageClass_<IntroPage>();}
+ IntroPage(ScummToolsFrame* frame);
+ wxWindow *CreatePanel(wxWindow *parent);
- void load(Configuration &configuration);
- void save(Configuration &configuration);
+ void save(wxWindow *panel, Configuration &configuration);
- virtual void onNext();
-
-protected:
- wxRadioBox *_options;
+ void onNext(wxWindow *panel);
+
+ void updateButtons(wxWindow *panel, WizardButtons *buttons);
};
class ChooseCompressionPage : public WizardPage
{
public:
- ChooseCompressionPage(wxWindow *parent);
- virtual WizardPageClass *getClass() {return new WizardPageClass_<ChooseCompressionPage>();}
+ ChooseCompressionPage(ScummToolsFrame* frame);
- void load(Configuration &configuration);
- void save(Configuration &configuration);
+ wxWindow *CreatePanel(wxWindow *parent);
-protected:
- wxChoice *_game;
+ void save(wxWindow *panel, Configuration &configuration);
};
class ChooseToolPage : public WizardPage
{
public:
- ChooseToolPage(wxWindow *parent);
- virtual WizardPageClass *getClass() {return new WizardPageClass_<ChooseToolPage>();}
+ ChooseToolPage(ScummToolsFrame* frame);
- void load(Configuration &configuration);
- void save(Configuration &configuration);
+ wxWindow *CreatePanel(wxWindow *parent);
-protected:
- wxChoice *_tool;
+ void save(wxWindow *panel, Configuration &configuration);
};
Modified: tools/branches/gsoc2009-gui/gui/tools.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/tools.cpp 2009-06-22 00:35:08 UTC (rev 41737)
+++ tools/branches/gsoc2009-gui/gui/tools.cpp 2009-06-22 00:50:49 UTC (rev 41738)
@@ -72,7 +72,9 @@
Tool::Tool() {
// should never be called
// required for std::map template to work
- wxLogError(wxT("Created empty tool, should never happened."));
+
+ // Seems std is allowed to create dummy objects in maps.
+ //wxLogError(wxT("Created empty tool, should never happened."));
}
Tool::Tool(wxString name, wxString input_extensions) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list