Commit 3cd40a7d authored by twanvl's avatar twanvl

Layout() always called when editor/viewer control changes size

parent 7b570b21
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include <data/stylesheet.hpp> #include <data/stylesheet.hpp>
#include <wx/dcbuffer.h> #include <wx/dcbuffer.h>
// ----------------------------------------------------------------------------- : Events
DEFINE_EVENT_TYPE(EVENT_SIZE_CHANGE);
// ----------------------------------------------------------------------------- : CardViewer // ----------------------------------------------------------------------------- : CardViewer
CardViewer::CardViewer(Window* parent, int id, long style) CardViewer::CardViewer(Window* parent, int id, long style)
...@@ -30,6 +34,16 @@ void CardViewer::onChange() { ...@@ -30,6 +34,16 @@ void CardViewer::onChange() {
up_to_date = false; 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 #ifdef _DEBUG
DECLARE_DYNAMIC_ARG(bool, inOnPaint); DECLARE_DYNAMIC_ARG(bool, inOnPaint);
IMPLEMENT_DYNAMIC_ARG(bool, inOnPaint, false); IMPLEMENT_DYNAMIC_ARG(bool, inOnPaint, false);
......
...@@ -12,6 +12,13 @@ ...@@ -12,6 +12,13 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <render/card/viewer.hpp> #include <render/card/viewer.hpp>
// ----------------------------------------------------------------------------- : Events
/// Event that indicates the size of a CardViewer has changed
DECLARE_EVENT_TYPE(EVENT_SIZE_CHANGE, <not used>)
/// Handle EVENT_SIZE_CHANGE events
#define EVT_SIZE_CHANGE(id, handler) EVT_COMMAND(id, EVENT_SIZE_CHANGE, handler)
// ----------------------------------------------------------------------------- : CardViewer // ----------------------------------------------------------------------------- : CardViewer
/// A control to view a single card /// A control to view a single card
...@@ -28,6 +35,7 @@ class CardViewer : public wxControl, public DataViewer { ...@@ -28,6 +35,7 @@ class CardViewer : public wxControl, public DataViewer {
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
virtual void onChange(); virtual void onChange();
virtual void onChangeSize();
private: private:
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
......
...@@ -196,19 +196,6 @@ bool CardsPanel::wantsToHandle(const Action&, bool undone) const { ...@@ -196,19 +196,6 @@ bool CardsPanel::wantsToHandle(const Action&, bool undone) const {
return false; 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 // ----------------------------------------------------------------------------- : Clipboard
bool CardsPanel::canCut() const { return focused_control(this) == ID_EDITOR ? editor->canCut() : card_list->canCut(); } bool CardsPanel::canCut() const { return focused_control(this) == ID_EDITOR ? editor->canCut() : card_list->canCut(); }
......
...@@ -37,8 +37,6 @@ class CardsPanel : public SetWindowPanel { ...@@ -37,8 +37,6 @@ class CardsPanel : public SetWindowPanel {
// --------------------------------------------------- : Actions // --------------------------------------------------- : Actions
virtual bool wantsToHandle(const Action&, bool undone) const; virtual bool wantsToHandle(const Action&, bool undone) const;
virtual void onAction(const Action&, bool undone);
virtual void onRenderSettingsChange();
public: public:
// --------------------------------------------------- : Clipboard // --------------------------------------------------- : Clipboard
......
...@@ -49,8 +49,6 @@ class SetWindowPanel : public wxPanel, public SetView { ...@@ -49,8 +49,6 @@ class SetWindowPanel : public wxPanel, public SetView {
virtual bool wantsToHandle(const Action&, bool undone) const { return false; } virtual bool wantsToHandle(const Action&, bool undone) const { return false; }
/// Handle an action that changes the current set /// Handle an action that changes the current set
virtual void onAction(const Action&, bool undone) {} virtual void onAction(const Action&, bool undone) {}
/// The settings for rendering cards have changed, refresh card viewers/editors
virtual void onRenderSettingsChange() {}
// --------------------------------------------------- : Clipboard // --------------------------------------------------- : Clipboard
virtual bool canPaste() const { return false; } ///< Is pasting possible? virtual bool canPaste() const { return false; } ///< Is pasting possible?
......
...@@ -53,15 +53,13 @@ void StylePanel::onChangeSet() { ...@@ -53,15 +53,13 @@ void StylePanel::onChangeSet() {
void StylePanel::onAction(const Action& action, bool undone) { void StylePanel::onAction(const Action& action, bool undone) {
TYPE_CASE_(action, ChangeSetStyleAction) { TYPE_CASE_(action, ChangeSetStyleAction) {
list->select(set->stylesheetFor(card)->name(), false); list->select(set->stylesheetFor(card)->name(), false);
// updateSize();
} }
TYPE_CASE(action, ChangeCardStyleAction) { TYPE_CASE(action, ChangeCardStyleAction) {
if (action.card == card) { 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); list->select(set->stylesheetFor(card)->name(), false);
// updateSize();
} }
} }
use_for_all->Enable(card && card->stylesheet);
} }
// ----------------------------------------------------------------------------- : Selection // ----------------------------------------------------------------------------- : Selection
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <gui/set/keywords_panel.hpp> #include <gui/set/keywords_panel.hpp>
#include <gui/set/stats_panel.hpp> #include <gui/set/stats_panel.hpp>
#include <gui/control/card_list.hpp> #include <gui/control/card_list.hpp>
#include <gui/control/card_viewer.hpp>
#include <gui/control/gallery_list.hpp> #include <gui/control/gallery_list.hpp>
#include <gui/about_window.hpp> #include <gui/about_window.hpp>
#include <gui/update_checker.hpp> #include <gui/update_checker.hpp>
...@@ -232,11 +233,12 @@ void SetWindow::onChangeSet() { ...@@ -232,11 +233,12 @@ void SetWindow::onChangeSet() {
} }
void SetWindow::onAction(const Action& action, bool undone) { 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 // The style changed, maybe also the size of card viewers
if (current_panel) current_panel->Layout(); if (current_panel) current_panel->Layout();
fixMinWindowSize(); fixMinWindowSize();
} }
*/
} }
...@@ -244,14 +246,6 @@ void SetWindow::onCardSelect(CardSelectEvent& ev) { ...@@ -244,14 +246,6 @@ void SetWindow::onCardSelect(CardSelectEvent& ev) {
FOR_EACH(p, panels) { FOR_EACH(p, panels) {
p->selectCard(ev.card); p->selectCard(ev.card);
} }
fixMinWindowSize();
}
void SetWindow::onRenderSettingsChange() {
FOR_EACH(p, panels) {
p->onRenderSettingsChange();
}
fixMinWindowSize();
} }
void SetWindow::fixMinWindowSize() { void SetWindow::fixMinWindowSize() {
...@@ -267,6 +261,12 @@ void SetWindow::fixMinWindowSize() { ...@@ -267,6 +261,12 @@ void SetWindow::fixMinWindowSize() {
SetMinSize(minSize); SetMinSize(minSize);
} }
void SetWindow::onSizeChange(wxCommandEvent&) {
FOR_EACH(p, panels) {
p->Layout();
}
fixMinWindowSize();
}
// ----------------------------------------------------------------------------- : Window events - close // ----------------------------------------------------------------------------- : Window events - close
...@@ -603,4 +603,5 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame) ...@@ -603,4 +603,5 @@ BEGIN_EVENT_TABLE(SetWindow, wxFrame)
EVT_CLOSE ( SetWindow::onClose) EVT_CLOSE ( SetWindow::onClose)
EVT_IDLE ( SetWindow::onIdle) EVT_IDLE ( SetWindow::onIdle)
EVT_CARD_SELECT (wxID_ANY, SetWindow::onCardSelect) EVT_CARD_SELECT (wxID_ANY, SetWindow::onCardSelect)
EVT_SIZE_CHANGE (wxID_ANY, SetWindow::onSizeChange)
END_EVENT_TABLE () END_EVENT_TABLE ()
...@@ -76,10 +76,7 @@ class SetWindow : public wxFrame, public SetView { ...@@ -76,10 +76,7 @@ class SetWindow : public wxFrame, public SetView {
private: private:
/// A different card has been selected /// A different card has been selected
void onCardSelect(CardSelectEvent&); void onCardSelect(CardSelectEvent&);
/// Render settings have changed (because of editing of preferences)
void onRenderSettingsChange();
// minSize = mainSizer->getMinWindowSize(this) // minSize = mainSizer->getMinWindowSize(this)
// but wx made that private // but wx made that private
void fixMinWindowSize(); void fixMinWindowSize();
...@@ -149,6 +146,8 @@ class SetWindow : public wxFrame, public SetView { ...@@ -149,6 +146,8 @@ class SetWindow : public wxFrame, public SetView {
void onChildMenu (wxCommandEvent&); void onChildMenu (wxCommandEvent&);
void onIdle (wxIdleEvent&); void onIdle (wxIdleEvent&);
void onSizeChange (wxCommandEvent&);
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
...@@ -58,6 +58,7 @@ ValueViewer* DataViewer::focusedViewer() const { return nullptr; } ...@@ -58,6 +58,7 @@ ValueViewer* DataViewer::focusedViewer() const { return nullptr; }
Context& DataViewer::getContext() const { return set->getContext(); } Context& DataViewer::getContext() const { return set->getContext(); }
Rotation DataViewer::getRotation() const { Rotation DataViewer::getRotation() const {
if (!stylesheet) stylesheet = set->stylesheet;
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet); StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), true); return Rotation(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom(), true);
} }
...@@ -71,6 +72,7 @@ void DataViewer::setCard(const CardP& card) { ...@@ -71,6 +72,7 @@ void DataViewer::setCard(const CardP& card) {
stylesheet = set->stylesheetFor(card); stylesheet = set->stylesheetFor(card);
setStyles(stylesheet, stylesheet->card_style); setStyles(stylesheet, stylesheet->card_style);
setData(card->data); setData(card->data);
onChangeSize();
} }
// ----------------------------------------------------------------------------- : Viewers // ----------------------------------------------------------------------------- : Viewers
......
...@@ -73,14 +73,15 @@ class DataViewer : public SetView { ...@@ -73,14 +73,15 @@ class DataViewer : public SetView {
/// Notification that the total image has changed /// Notification that the total image has changed
virtual void onChange() {} virtual void onChange() {}
/// Notification that the viewers are initialized /// Notification that the viewers are initialized
virtual void onInit() {} virtual void onInit() {}
/// Notification that the size of the viewer may have changed
virtual void onChangeSize() {}
vector<ValueViewerP> viewers; ///< The viewers for the different values in the data vector<ValueViewerP> viewers; ///< The viewers for the different values in the data
CardP card; ///< The card that is currently displayed, if any CardP card; ///< The card that is currently displayed, if any
public: public:
StyleSheetP stylesheet; ///< Stylesheet being used mutable StyleSheetP stylesheet; ///< Stylesheet being used
}; };
// ----------------------------------------------------------------------------- : EOF // ----------------------------------------------------------------------------- : EOF
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment