From a16c098eac5048bf36e15f1d672af512026d8946 Mon Sep 17 00:00:00 2001 From: twanvl Date: Fri, 22 Dec 2006 15:33:14 +0000 Subject: [PATCH] Layout() always called when editor/viewer control changes size git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@145 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/control/card_viewer.cpp | 14 ++++++++++++++ src/gui/control/card_viewer.hpp | 8 ++++++++ src/gui/set/cards_panel.cpp | 13 ------------- src/gui/set/cards_panel.hpp | 2 -- src/gui/set/panel.hpp | 2 -- src/gui/set/style_panel.cpp | 4 +--- src/gui/set/window.cpp | 19 ++++++++++--------- src/gui/set/window.hpp | 7 +++---- src/render/card/viewer.cpp | 2 ++ src/render/card/viewer.hpp | 5 +++-- 10 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/gui/control/card_viewer.cpp b/src/gui/control/card_viewer.cpp index c1d88f70..a11c4954 100644 --- a/src/gui/control/card_viewer.cpp +++ b/src/gui/control/card_viewer.cpp @@ -10,6 +10,10 @@ #include #include +// ----------------------------------------------------------------------------- : Events + +DEFINE_EVENT_TYPE(EVENT_SIZE_CHANGE); + // ----------------------------------------------------------------------------- : CardViewer CardViewer::CardViewer(Window* parent, int id, long style) @@ -30,6 +34,16 @@ void CardViewer::onChange() { up_to_date = false; } +void CardViewer::onChangeSize() { + wxSize ws = GetSize(), cs = GetClientSize(); + wxSize desired_cs = (wxSize)getRotation().getExternalSize() + ws - cs; + if (desired_cs != cs) { + wxCommandEvent ev(EVENT_SIZE_CHANGE, GetId()); + ProcessEvent(ev); + } +} + + #ifdef _DEBUG DECLARE_DYNAMIC_ARG(bool, inOnPaint); IMPLEMENT_DYNAMIC_ARG(bool, inOnPaint, false); diff --git a/src/gui/control/card_viewer.hpp b/src/gui/control/card_viewer.hpp index 0192c05e..b4fc388d 100644 --- a/src/gui/control/card_viewer.hpp +++ b/src/gui/control/card_viewer.hpp @@ -12,6 +12,13 @@ #include #include +// ----------------------------------------------------------------------------- : Events + +/// Event that indicates the size of a CardViewer has changed +DECLARE_EVENT_TYPE(EVENT_SIZE_CHANGE, ) +/// Handle EVENT_SIZE_CHANGE events +#define EVT_SIZE_CHANGE(id, handler) EVT_COMMAND(id, EVENT_SIZE_CHANGE, handler) + // ----------------------------------------------------------------------------- : CardViewer /// A control to view a single card @@ -28,6 +35,7 @@ class CardViewer : public wxControl, public DataViewer { virtual wxSize DoGetBestSize() const; virtual void onChange(); + virtual void onChangeSize(); private: DECLARE_EVENT_TABLE(); diff --git a/src/gui/set/cards_panel.cpp b/src/gui/set/cards_panel.cpp index 6fb7f884..4207ac81 100644 --- a/src/gui/set/cards_panel.cpp +++ b/src/gui/set/cards_panel.cpp @@ -196,19 +196,6 @@ bool CardsPanel::wantsToHandle(const Action&, bool undone) const { return false; } -void CardsPanel::onAction(const Action& action, bool undone) { - TYPE_CASE_(action, DisplayChangeAction) { - // The style changed, maybe also the size of editor - Layout(); - //if (current_panel) current_panel->Layout(); - //fixMinWindowSize(); - } -} - -void CardsPanel::onRenderSettingsChange() { - // TODO -} - // ----------------------------------------------------------------------------- : Clipboard bool CardsPanel::canCut() const { return focused_control(this) == ID_EDITOR ? editor->canCut() : card_list->canCut(); } diff --git a/src/gui/set/cards_panel.hpp b/src/gui/set/cards_panel.hpp index e98fdb47..ed426972 100644 --- a/src/gui/set/cards_panel.hpp +++ b/src/gui/set/cards_panel.hpp @@ -37,8 +37,6 @@ class CardsPanel : public SetWindowPanel { // --------------------------------------------------- : Actions virtual bool wantsToHandle(const Action&, bool undone) const; - virtual void onAction(const Action&, bool undone); - virtual void onRenderSettingsChange(); public: // --------------------------------------------------- : Clipboard diff --git a/src/gui/set/panel.hpp b/src/gui/set/panel.hpp index fd7f95e7..7331856b 100644 --- a/src/gui/set/panel.hpp +++ b/src/gui/set/panel.hpp @@ -49,8 +49,6 @@ class SetWindowPanel : public wxPanel, public SetView { virtual bool wantsToHandle(const Action&, bool undone) const { return false; } /// Handle an action that changes the current set virtual void onAction(const Action&, bool undone) {} - /// The settings for rendering cards have changed, refresh card viewers/editors - virtual void onRenderSettingsChange() {} // --------------------------------------------------- : Clipboard virtual bool canPaste() const { return false; } ///< Is pasting possible? diff --git a/src/gui/set/style_panel.cpp b/src/gui/set/style_panel.cpp index 59c7fc54..f82c60e8 100644 --- a/src/gui/set/style_panel.cpp +++ b/src/gui/set/style_panel.cpp @@ -53,15 +53,13 @@ void StylePanel::onChangeSet() { void StylePanel::onAction(const Action& action, bool undone) { TYPE_CASE_(action, ChangeSetStyleAction) { list->select(set->stylesheetFor(card)->name(), false); -// updateSize(); } TYPE_CASE(action, ChangeCardStyleAction) { if (action.card == card) { -// preview->onAction(action, undone); // update the preview control before we determine our new size list->select(set->stylesheetFor(card)->name(), false); -// updateSize(); } } + use_for_all->Enable(card && card->stylesheet); } // ----------------------------------------------------------------------------- : Selection diff --git a/src/gui/set/window.cpp b/src/gui/set/window.cpp index 0b89963b..34c7de37 100644 --- a/src/gui/set/window.cpp +++ b/src/gui/set/window.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -232,11 +233,12 @@ void SetWindow::onChangeSet() { } void SetWindow::onAction(const Action& action, bool undone) { - TYPE_CASE_(action, DisplayChangeAction) { +/* TYPE_CASE_(action, DisplayChangeAction) { // The style changed, maybe also the size of card viewers if (current_panel) current_panel->Layout(); fixMinWindowSize(); } +*/ } @@ -244,14 +246,6 @@ void SetWindow::onCardSelect(CardSelectEvent& ev) { FOR_EACH(p, panels) { p->selectCard(ev.card); } - fixMinWindowSize(); -} - -void SetWindow::onRenderSettingsChange() { - FOR_EACH(p, panels) { - p->onRenderSettingsChange(); - } - fixMinWindowSize(); } void SetWindow::fixMinWindowSize() { @@ -267,6 +261,12 @@ void SetWindow::fixMinWindowSize() { SetMinSize(minSize); } +void SetWindow::onSizeChange(wxCommandEvent&) { + FOR_EACH(p, panels) { + p->Layout(); + } + fixMinWindowSize(); +} // ----------------------------------------------------------------------------- : Window events - close @@ -603,4 +603,5 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame) EVT_CLOSE ( SetWindow::onClose) EVT_IDLE ( SetWindow::onIdle) EVT_CARD_SELECT (wxID_ANY, SetWindow::onCardSelect) + EVT_SIZE_CHANGE (wxID_ANY, SetWindow::onSizeChange) END_EVENT_TABLE () diff --git a/src/gui/set/window.hpp b/src/gui/set/window.hpp index 05dc35e6..d23c32ba 100644 --- a/src/gui/set/window.hpp +++ b/src/gui/set/window.hpp @@ -76,10 +76,7 @@ class SetWindow : public wxFrame, public SetView { private: /// A different card has been selected void onCardSelect(CardSelectEvent&); - - /// Render settings have changed (because of editing of preferences) - void onRenderSettingsChange(); - + // minSize = mainSizer->getMinWindowSize(this) // but wx made that private void fixMinWindowSize(); @@ -149,6 +146,8 @@ class SetWindow : public wxFrame, public SetView { void onChildMenu (wxCommandEvent&); void onIdle (wxIdleEvent&); + + void onSizeChange (wxCommandEvent&); }; // ----------------------------------------------------------------------------- : EOF diff --git a/src/render/card/viewer.cpp b/src/render/card/viewer.cpp index d8ecf656..5de39658 100644 --- a/src/render/card/viewer.cpp +++ b/src/render/card/viewer.cpp @@ -58,6 +58,7 @@ ValueViewer* DataViewer::focusedViewer() const { return nullptr; } Context& DataViewer::getContext() const { return set->getContext(); } Rotation DataViewer::getRotation() const { + if (!stylesheet) stylesheet = set->stylesheet; StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet); return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), true); } @@ -71,6 +72,7 @@ void DataViewer::setCard(const CardP& card) { stylesheet = set->stylesheetFor(card); setStyles(stylesheet, stylesheet->card_style); setData(card->data); + onChangeSize(); } // ----------------------------------------------------------------------------- : Viewers diff --git a/src/render/card/viewer.hpp b/src/render/card/viewer.hpp index c9bfd6a9..b3fe626e 100644 --- a/src/render/card/viewer.hpp +++ b/src/render/card/viewer.hpp @@ -73,14 +73,15 @@ class DataViewer : public SetView { /// Notification that the total image has changed virtual void onChange() {} - /// Notification that the viewers are initialized virtual void onInit() {} + /// Notification that the size of the viewer may have changed + virtual void onChangeSize() {} vector viewers; ///< The viewers for the different values in the data CardP card; ///< The card that is currently displayed, if any public: - StyleSheetP stylesheet; ///< Stylesheet being used + mutable StyleSheetP stylesheet; ///< Stylesheet being used }; // ----------------------------------------------------------------------------- : EOF