Delay the construction of controls is SetWindowPanels until the panel is actually shown (initUI). This makes the program start slightly faster.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1189 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-09-01 17:21:17 +00:00
parent 371795d740
commit dc9053baef
10 changed files with 107 additions and 7 deletions
+23 -1
View File
@@ -23,11 +23,15 @@
DECLARE_TYPEOF_COLLECTION(FieldP);
// ----------------------------------------------------------------------------- : StylePanel
// ----------------------------------------------------------------------------- : StylePanel : initialization
StylePanel::StylePanel(Window* parent, int id)
: SetWindowPanel(parent, id)
{
// delayed initialization by initControls()
}
void StylePanel::initControls() {
// init controls
preview = new CardViewer (this, wxID_ANY);
list = new PackageList (this, wxID_ANY);
@@ -48,7 +52,19 @@ StylePanel::StylePanel(Window* parent, int id)
s->SetSizeHints(this);
SetSizer(s);
}
void StylePanel::initUI(wxToolBar* tb, wxMenuBar* mb) {
if (!isInitialized()) {
wxBusyCursor busy;
initControls();
CardP cur_card = card;
onChangeSet();
selectCard(cur_card);
}
}
void StylePanel::updateListSize() {
if (!isInitialized()) return;
// how many columns fit?
size_t fit_columns = (size_t)((GetSize().y - 400) / 152);
// we only need enough columns to show all items
@@ -66,7 +82,10 @@ bool StylePanel::Layout() {
return SetWindowPanel::Layout();
}
// ----------------------------------------------------------------------------- : StylePanel
void StylePanel::onChangeSet() {
if (!isInitialized()) return;
list->showData<StyleSheet>(set->game->name() + _("-*"));
list->select(set->stylesheet->name(), false);
editor->setSet(set);
@@ -76,6 +95,7 @@ void StylePanel::onChangeSet() {
}
void StylePanel::onAction(const Action& action, bool undone) {
if (!isInitialized()) return;
TYPE_CASE_(action, ChangeSetStyleAction) {
list->select(set->stylesheetFor(card).name(), false);
editor->showCard(card);
@@ -113,6 +133,7 @@ void StylePanel::onAction(const Action& action, bool undone) {
void StylePanel::selectCard(const CardP& card) {
this->card = card;
if (!isInitialized()) return;
preview->setCard(card);
editor->showStylesheet(set->stylesheetForP(card));
editor->showCard(card);
@@ -126,6 +147,7 @@ void StylePanel::selectCard(const CardP& card) {
// determine what control to use for clipboard actions
#define CUT_COPY_PASTE(op,return) \
if (!isInitialized()) return false; \
int id = focused_control(this); \
if (id == ID_EDITOR) { return editor->op(); } \
else { return false; }