From a6bda7eb9f2023a489e278848b44349cf40139e8 Mon Sep 17 00:00:00 2001 From: klugier Date: Sun, 4 Oct 2020 20:25:02 +0000 Subject: [PATCH] Bazaar: AutoScroller now uses always single inclued. git-svn-id: svn://ultimatepp.org/upp/trunk@15202 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/AutoScroller/AutoScroller.h | 64 ++++++++++++-------- bazaar/AutoScroller/AutoScroller.hpp | 50 --------------- bazaar/AutoScroller/AutoScroller.upp | 5 +- bazaar/AutoScroller/AutoScrollerParentCtrl.h | 38 ++++++++++++ bazaar/AutoScrollerTest/AutoScrollerTest.h | 14 ++--- bazaar/AutoScrollerTest/main.cpp | 12 ++-- 6 files changed, 91 insertions(+), 92 deletions(-) delete mode 100644 bazaar/AutoScroller/AutoScroller.hpp create mode 100644 bazaar/AutoScroller/AutoScrollerParentCtrl.h diff --git a/bazaar/AutoScroller/AutoScroller.h b/bazaar/AutoScroller/AutoScroller.h index 62e8a2ea4..61bd4a525 100644 --- a/bazaar/AutoScroller/AutoScroller.h +++ b/bazaar/AutoScroller/AutoScroller.h @@ -1,38 +1,50 @@ -#ifndef _AutoScroller_AutoScroller_h_ -#define _AutoScroller_AutoScroller_h_ +#ifndef _AutoScroller_AutoScroller_hpp_ +#define _AutoScroller_AutoScroller_hpp_ -#include +#include "AutoScrollerParentCtrl.h" namespace Upp { - template - class AutoScroller : public C + template + AutoScroller::AutoScroller() { - public: - using CLASSNAME = AutoScroller; - AutoScroller(); - - public: - virtual void Layout(); - - void EnableScroll(bool b = true); - void DisableScroll() { EnableScroll(false); } - bool IsEnabledScroll() const { return scroll.x.IsEnabled() || scroll.y.IsEnabled(); } + C::AddFrame(scroll); + scroll.AutoHide(); + scroll.WhenScroll = THISBACK(OnScroll); + } - void AddPane(Ctrl& c) { ClearPane(); pane = &c; C::Add(c); } - Ctrl* GetPane() const { return pane; } - inline bool HasPane() const { return (~pane != NULL); } - void ClearPane() { if(! ~pane) return; pane->Remove(); pane = NULL; } + template + void AutoScroller::Scroll(const Point& p) + { + if(!HasPane()) return; + Rect _r = pane->GetRect(); + Rect r(-p, _r.GetSize()); + pane->SetRect(r); + WhenScrolled(); + } - void Scroll(const Point& p); - void OnScroll(); + template + void AutoScroller::OnScroll() + { + Scroll(scroll.Get()); + } - Callback WhenScrolled; - ScrollBars scroll; + template + void AutoScroller::Layout() + { + Size psz = C::GetSize(); + scroll.SetPage(psz); + if(!HasPane()) return; + Size tsz = pane->GetSize(); + scroll.SetTotal(tsz); + } - protected: - Ptr pane; - }; + template + void AutoScroller::EnableScroll(bool b) + { + scroll.x.Enable(b); + scroll.y.Enable(b); + } } #endif diff --git a/bazaar/AutoScroller/AutoScroller.hpp b/bazaar/AutoScroller/AutoScroller.hpp deleted file mode 100644 index 4eb41b5ee..000000000 --- a/bazaar/AutoScroller/AutoScroller.hpp +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _AutoScroller_AutoScroller_hpp_ -#define _AutoScroller_AutoScroller_hpp_ - -#include "AutoScroller.h" - -namespace Upp -{ - template - AutoScroller::AutoScroller() - { - C::AddFrame(scroll); - scroll.AutoHide(); - scroll.WhenScroll = THISBACK(OnScroll); - } - - template - void AutoScroller::Scroll(const Point& p) - { - if(!HasPane()) return; - Rect _r = pane->GetRect(); - Rect r(-p, _r.GetSize()); - pane->SetRect(r); - WhenScrolled(); - } - - template - void AutoScroller::OnScroll() - { - Scroll(scroll.Get()); - } - - template - void AutoScroller::Layout() - { - Size psz = C::GetSize(); - scroll.SetPage(psz); - if(!HasPane()) return; - Size tsz = pane->GetSize(); - scroll.SetTotal(tsz); - } - - template - void AutoScroller::EnableScroll(bool b) - { - scroll.x.Enable(b); - scroll.y.Enable(b); - } -} - -#endif diff --git a/bazaar/AutoScroller/AutoScroller.upp b/bazaar/AutoScroller/AutoScroller.upp index 2a45be736..b97f08a02 100644 --- a/bazaar/AutoScroller/AutoScroller.upp +++ b/bazaar/AutoScroller/AutoScroller.upp @@ -5,6 +5,7 @@ uses file AutoScroller.h, - AutoScroller.hpp, - AutoScroller.cpp; + AutoScroller.cpp, + Specialisations readonly separator, + AutoScrollerParentCtrl.h; diff --git a/bazaar/AutoScroller/AutoScrollerParentCtrl.h b/bazaar/AutoScroller/AutoScrollerParentCtrl.h new file mode 100644 index 000000000..5a5144818 --- /dev/null +++ b/bazaar/AutoScroller/AutoScrollerParentCtrl.h @@ -0,0 +1,38 @@ +#ifndef _AutoScroller_AutoScroller_h_ +#define _AutoScroller_AutoScroller_h_ + +#include + +namespace Upp +{ + template + class AutoScroller : public C + { + public: + using CLASSNAME = AutoScroller; + AutoScroller(); + + public: + virtual void Layout() override; + + void EnableScroll(bool b = true); + void DisableScroll() { EnableScroll(false); } + bool IsEnabledScroll() const { return scroll.x.IsEnabled() || scroll.y.IsEnabled(); } + + void AddPane(Ctrl& c) { ClearPane(); pane = &c; C::Add(c); } + Ctrl* GetPane() const { return pane; } + inline bool HasPane() const { return (~pane != nullptr); } + void ClearPane() { if(! ~pane) return; pane->Remove(); pane = nullptr; } + + void Scroll(const Point& p); + void OnScroll(); + + Callback WhenScrolled; + ScrollBars scroll; + + protected: + Ptr pane; + }; +} + +#endif diff --git a/bazaar/AutoScrollerTest/AutoScrollerTest.h b/bazaar/AutoScrollerTest/AutoScrollerTest.h index c534b5bca..58815376d 100644 --- a/bazaar/AutoScrollerTest/AutoScrollerTest.h +++ b/bazaar/AutoScrollerTest/AutoScrollerTest.h @@ -2,8 +2,9 @@ #define _AutoScrollerTest_AutoScrollerTest_h #include +#include -using namespace Upp; +namespace Upp { #define LAYOUTFILE #include @@ -11,21 +12,16 @@ using namespace Upp; #define IMAGEFILE #include -//if use only ParentCtrl as base -//#include -//if use custom base -#include - class AutoScrollerTest : public WithAutoScrollerTestLayout { public: - typedef AutoScrollerTest CLASSNAME; AutoScrollerTest(); void Toggle(); - AutoScroller sc; + AutoScroller sc; WithTestLay view; }; -#endif +} +#endif diff --git a/bazaar/AutoScrollerTest/main.cpp b/bazaar/AutoScrollerTest/main.cpp index e2b388f7f..ffe958671 100644 --- a/bazaar/AutoScrollerTest/main.cpp +++ b/bazaar/AutoScrollerTest/main.cpp @@ -1,5 +1,7 @@ #include "AutoScrollerTest.h" +using namespace Upp; + #define IMAGEFILE #include @@ -17,13 +19,13 @@ AutoScrollerTest::AutoScrollerTest() sc.EnableScroll(); Add(sc.SizePos()); - CtrlLayout(view); //will determine desired size of pane - sc.AddPane(view); //size remains as specified, if view changes size, sc.Layout() needs to be called. - //if sc changes its size, it recalculates the scroll bars automatically + CtrlLayout(view); // will determine desired size of pane + sc.AddPane(view); // size remains as specified, if view changes size, sc.Layout() needs to be called. + // if sc changes its size, it recalculates the scroll bars automatically - //sc.WhenScrolled = THISBACK(); //after scrolling events + //sc.WhenScrolled = [=] {}; //after scrolling events - view.tg <<= THISBACK(Toggle); + view.tg << [=] { Toggle(); }; view.doc0 <<= "doc0"; view.doc1 <<= "doc1";