diff --git a/escher/include/escher/view.h b/escher/include/escher/view.h index f674a47b8..32bfe796d 100644 --- a/escher/include/escher/view.h +++ b/escher/include/escher/view.h @@ -26,12 +26,21 @@ class View { friend class TransparentView; public: View(); - virtual ~View(); + virtual ~View() { + for (int i = 0; i < numberOfSubviews(); i++) { + View * subview = subviewAtIndex(i); + if (subview != nullptr) { + subview->m_superview = nullptr; + } + } + } View(View&& other) = default; View(const View& other) = delete; View& operator=(const View& other) = delete; View& operator=(View&& other) = delete; - void resetSuperview(); + void resetSuperview() { + m_superview = nullptr; + } /* The drawRect method should be implemented by each View subclass. In a * typical drawRect implementation, a subclass will make drawing calls to the * Kandinsky library using the provided context. */ @@ -66,8 +75,12 @@ protected: #endif KDRect m_frame; private: - virtual int numberOfSubviews() const; - virtual View * subviewAtIndex(int index); + virtual int numberOfSubviews() const { + return 0; + } + virtual View * subviewAtIndex(int index) { + return nullptr; + } virtual void layoutSubviews(); virtual const Window * window() const; KDRect redraw(KDRect rect, KDRect forceRedrawRect = KDRectZero); diff --git a/escher/src/view.cpp b/escher/src/view.cpp index 64cfcc62d..6ba058589 100644 --- a/escher/src/view.cpp +++ b/escher/src/view.cpp @@ -10,19 +10,6 @@ View::View() : { } -View::~View() { - for (int i = 0; i < numberOfSubviews(); i++) { - View * subview = subviewAtIndex(i); - if (subview != nullptr) { - subview->m_superview = nullptr; - } - } -} - -void View::resetSuperview() { - m_superview = nullptr; -} - void View::drawRect(KDContext * ctx, KDRect rect) const { // By default, a view doesn't do anything // It's transparent! @@ -121,7 +108,6 @@ void View::setSize(KDSize size) { setFrame(KDRect(m_frame.origin(), size)); } - void View::setFrame(KDRect frame) { if (frame == m_frame) { return; @@ -183,15 +169,6 @@ KDSize View::minimalSizeForOptimalDisplay() const { return KDSizeZero; } -int View::numberOfSubviews() const { - return 0; -} - -View * View::subviewAtIndex(int index) { - assert(false); - return nullptr; -} - void View::layoutSubviews() { }