From e8a2be07ec8506967b561d116793c6d420c41712 Mon Sep 17 00:00:00 2001 From: kohait Date: Tue, 17 Aug 2010 20:13:39 +0000 Subject: [PATCH] bazaar: Dispatcher generic class to dispatch data to arbitrary recepients (very simple), see examples git-svn-id: svn://ultimatepp.org/upp/trunk@2623 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- bazaar/Dispatcher/Dispatcher.cpp | 34 +++ bazaar/Dispatcher/Dispatcher.h | 125 ++++++++++ bazaar/Dispatcher/Dispatcher.hpp | 251 +++++++++++++++++++++ bazaar/Dispatcher/Dispatcher.upp | 10 + bazaar/Dispatcher/init | 4 + bazaar/DispatcherTest/DispatcherTest.h | 39 ++++ bazaar/DispatcherTest/DispatcherTest.lay | 12 + bazaar/DispatcherTest/DispatcherTest.upp | 14 ++ bazaar/DispatcherTest/init | 5 + bazaar/DispatcherTest/main.cpp | 60 +++++ bazaar/DispatcherTest2/DispatcherTest.h | 43 ++++ bazaar/DispatcherTest2/DispatcherTest.lay | 14 ++ bazaar/DispatcherTest2/DispatcherTest2.upp | 14 ++ bazaar/DispatcherTest2/init | 5 + bazaar/DispatcherTest2/main.cpp | 84 +++++++ bazaar/DispatcherTest3/DispatcherTest.h | 61 +++++ bazaar/DispatcherTest3/DispatcherTest.lay | 5 + bazaar/DispatcherTest3/DispatcherTest3.upp | 14 ++ bazaar/DispatcherTest3/init | 5 + bazaar/DispatcherTest3/main.cpp | 63 ++++++ bazaar/DispatcherTest4/DispatcherTest.h | 66 ++++++ bazaar/DispatcherTest4/DispatcherTest.lay | 7 + bazaar/DispatcherTest4/DispatcherTest4.upp | 14 ++ bazaar/DispatcherTest4/init | 5 + bazaar/DispatcherTest4/main.cpp | 72 ++++++ bazaar/DispatcherTest5/DispatcherTest.h | 65 ++++++ bazaar/DispatcherTest5/DispatcherTest.lay | 7 + bazaar/DispatcherTest5/DispatcherTest5.upp | 14 ++ bazaar/DispatcherTest5/init | 5 + bazaar/DispatcherTest5/main.cpp | 73 ++++++ bazaar/DispatcherTest6/DispatcherTest.h | 63 ++++++ bazaar/DispatcherTest6/DispatcherTest.lay | 7 + bazaar/DispatcherTest6/DispatcherTest6.upp | 14 ++ bazaar/DispatcherTest6/init | 5 + bazaar/DispatcherTest6/main.cpp | 87 +++++++ 35 files changed, 1366 insertions(+) create mode 100644 bazaar/Dispatcher/Dispatcher.cpp create mode 100644 bazaar/Dispatcher/Dispatcher.h create mode 100644 bazaar/Dispatcher/Dispatcher.hpp create mode 100644 bazaar/Dispatcher/Dispatcher.upp create mode 100644 bazaar/Dispatcher/init create mode 100644 bazaar/DispatcherTest/DispatcherTest.h create mode 100644 bazaar/DispatcherTest/DispatcherTest.lay create mode 100644 bazaar/DispatcherTest/DispatcherTest.upp create mode 100644 bazaar/DispatcherTest/init create mode 100644 bazaar/DispatcherTest/main.cpp create mode 100644 bazaar/DispatcherTest2/DispatcherTest.h create mode 100644 bazaar/DispatcherTest2/DispatcherTest.lay create mode 100644 bazaar/DispatcherTest2/DispatcherTest2.upp create mode 100644 bazaar/DispatcherTest2/init create mode 100644 bazaar/DispatcherTest2/main.cpp create mode 100644 bazaar/DispatcherTest3/DispatcherTest.h create mode 100644 bazaar/DispatcherTest3/DispatcherTest.lay create mode 100644 bazaar/DispatcherTest3/DispatcherTest3.upp create mode 100644 bazaar/DispatcherTest3/init create mode 100644 bazaar/DispatcherTest3/main.cpp create mode 100644 bazaar/DispatcherTest4/DispatcherTest.h create mode 100644 bazaar/DispatcherTest4/DispatcherTest.lay create mode 100644 bazaar/DispatcherTest4/DispatcherTest4.upp create mode 100644 bazaar/DispatcherTest4/init create mode 100644 bazaar/DispatcherTest4/main.cpp create mode 100644 bazaar/DispatcherTest5/DispatcherTest.h create mode 100644 bazaar/DispatcherTest5/DispatcherTest.lay create mode 100644 bazaar/DispatcherTest5/DispatcherTest5.upp create mode 100644 bazaar/DispatcherTest5/init create mode 100644 bazaar/DispatcherTest5/main.cpp create mode 100644 bazaar/DispatcherTest6/DispatcherTest.h create mode 100644 bazaar/DispatcherTest6/DispatcherTest.lay create mode 100644 bazaar/DispatcherTest6/DispatcherTest6.upp create mode 100644 bazaar/DispatcherTest6/init create mode 100644 bazaar/DispatcherTest6/main.cpp diff --git a/bazaar/Dispatcher/Dispatcher.cpp b/bazaar/Dispatcher/Dispatcher.cpp new file mode 100644 index 000000000..f642ddd64 --- /dev/null +++ b/bazaar/Dispatcher/Dispatcher.cpp @@ -0,0 +1,34 @@ +#include "Dispatcher.hpp" + +DispatcherGen::DispatcherGen() +{ +} + +DispatcherGen::~DispatcherGen() +{ + //ASSERT(dests.IsEmpty()); //FIXME, DispatcherGen does keep the Dispatcher instances, cause Dispatchable are Register()ed there (forwarded) and do Unregister() only there as well. +} + + +//Callback variant + +DispatcherCBGen::DispatcherCBGen() +{ +} + +DispatcherCBGen::~DispatcherCBGen() +{ + //ASSERT(dests.IsEmpty()); //FIXME, DispatcherGen does keep the Dispatcher instances, cause Dispatchable are Register()ed there (forwarded) and do Unregister() only there as well. +} + +#if 0 //for compile / debug only +template class Dispatchable; +template class Dispatcher; + +template void DispatcherGen::DoDispatch(const int & o, unsigned param) const; +template void DispatcherGen::Register(Dispatchable & d, unsigned key); +template void DispatcherGen::Unregister(Dispatchable & d, unsigned key); + +DispatcherGen gen; +DispatcherCBGen gencb; +#endif \ No newline at end of file diff --git a/bazaar/Dispatcher/Dispatcher.h b/bazaar/Dispatcher/Dispatcher.h new file mode 100644 index 000000000..5d42b5f01 --- /dev/null +++ b/bazaar/Dispatcher/Dispatcher.h @@ -0,0 +1,125 @@ +#ifndef _Dispatcher_Dispatcher_h +#define _Dispatcher_Dispatcher_h + +#include + +using namespace Upp; + +template +class Dispatcher; + +class DispatcherGen; + +template +class Dispatchable +{ + friend class Dispatcher; + friend class DispatcherGen; +public: + typedef Dispatchable CLASSNAME; + Dispatchable(); + virtual ~Dispatchable(); + +public: + virtual void Dispatch(const T & o, unsigned param = 0) = 0; + + void Unregister(const Any & _src); + void UnregisterAll(); + void Unregister(Dispatcher & from) { int i = src.Find(GetPtrHashValue(&from)); if(i<0) return; Unregister(src[i]); } + void Unregister(DispatcherGen & from) { int i = src.Find(GetPtrHashValue(&from)); if(i<0) return; Unregister(src[i]); } + + const VectorMap & GetSrc() const { return src; } + +private: + VectorMap src; + VectorMap key; //cache under which key registered for removal +}; + +template +class Dispatcher +{ +public: + typedef Dispatcher CLASSNAME; + Dispatcher(); + virtual ~Dispatcher(); + + void DoDispatch(const T & o, unsigned param = 0) const; + + void Register(Dispatchable & d, unsigned key = 0); + void Unregister(Dispatchable & d, unsigned key = 0); + Dispatchable * GetDispatchable(unsigned key) const; + const VectorMap * > & GetDests() const { return dests; } + +private: + VectorMap * > dests; +}; + +//a generic version that accepts any Dispatchable +class DispatcherGen +{ +public: + typedef DispatcherGen CLASSNAME; + DispatcherGen(); + virtual ~DispatcherGen(); + + template + void DoDispatch(const T & o, unsigned param = 0) const; + + template + void Register(Dispatchable & d, unsigned key = 0); + template + void Unregister(Dispatchable & d, unsigned key = 0); + template + Dispatcher & GetDispatcher(); + +private: + Vector dests; //now does store the different Dispatcher +}; + + +//Callback variant +//spares out Dispatchable interface + +template +class DispatcherCB +{ +public: + typedef DispatcherCB CLASSNAME; + DispatcherCB(); + virtual ~DispatcherCB(); + + void DoDispatch(const T & o, unsigned param = 0) const; + + void Register(Callback2 d, unsigned key); + void Unregister(unsigned key); + Callback2 GetDispatchable(unsigned key); + const VectorMap > & GetDests() const { return dests; } + +private: + VectorMap > dests; +}; + +//a generic version that accepts any Callback +class DispatcherCBGen +{ +public: + typedef DispatcherCBGen CLASSNAME; + DispatcherCBGen(); + virtual ~DispatcherCBGen(); + + template + void DoDispatch(const T & o, unsigned param = 0) const; + + template + void Register(Callback2 d, unsigned key); + template + void Unregister(unsigned key); + template + DispatcherCB & GetDispatcherCB(); + +private: + Vector dests; //now does store the different DispatcherCB +}; + +#endif + diff --git a/bazaar/Dispatcher/Dispatcher.hpp b/bazaar/Dispatcher/Dispatcher.hpp new file mode 100644 index 000000000..896b379fb --- /dev/null +++ b/bazaar/Dispatcher/Dispatcher.hpp @@ -0,0 +1,251 @@ +#include "Dispatcher.h" + +template +Dispatchable::Dispatchable() +{ + +} + +template +Dispatchable::~Dispatchable() +{ + UnregisterAll(); +} + +template +void Dispatchable::Unregister(const Any & _src) +{ + if(_src.Is * >()) + { + Dispatcher * disp = _src.Get * >(); + disp->Unregister(*this, key.Get(GetPtrHashValue(disp))); + } + else + if(_src.Is()) + { + DispatcherGen * disp = _src.Get(); + disp->Unregister(*this, key.Get(GetPtrHashValue(disp))); + } +} + +template +void Dispatchable::UnregisterAll() +{ + while(src.GetCount()>0) + { + Unregister(src[0]); + } +} + +template +Dispatcher::Dispatcher() +{ + +} + +template +Dispatcher::~Dispatcher() +{ + ASSERT(dests.IsEmpty()); +} + +template +void Dispatcher::DoDispatch(const T & o, unsigned param) const +{ + for(int i = 0; i < dests.GetCount(); i++) + { + Dispatchable * dest = dests.operator[](i); + dest->Dispatch(o, param); + } +} + +template +void Dispatcher::Register(Dispatchable & d, unsigned key) +{ + if(key == 0) key = GetPtrHashValue(&d); + int i = dests.Find(key); + if(i>=0) return; + dests.Add(key) = &d; + Any & a = d.src.Add(GetPtrHashValue(this)); + a.Create * >() = this; + d.key.Add(GetPtrHashValue(this)) = key; +} + +template +void Dispatcher::Unregister(Dispatchable & d, unsigned key) +{ + if(key == 0) key = GetPtrHashValue(&d); + int i = dests.Find(key); + if(i<0) return; + dests.Remove(i); + d.src.RemoveKey(GetPtrHashValue(this)); + d.key.RemoveKey(GetPtrHashValue(this)); +} + +template +Dispatchable * Dispatcher::GetDispatchable(unsigned key) const +{ + int i = dests.Find(key); + if(i<0) return NULL; + Dispatchable * dest = dests.operator[](i); + return dest; +} + +template +void DispatcherGen::DoDispatch(const T & o, unsigned param) const +{ + for(int i = 0; i < dests.GetCount(); i++) + { + const Any & a = dests.operator[](i); + if(!a.Is >()) continue; + const Dispatcher & dest = a.Get >(); + dest.DoDispatch(o, param); + return; + } +} + +template +void DispatcherGen::Register(Dispatchable & d, unsigned key) +{ + for(int i = 0; i < dests.GetCount(); i++) + { + Any & a = dests.operator[](i); + if(!a.Is >()) continue; + Dispatcher & dest = a.Get >(); + dest.Register(d, key); + return; + } + dests.Add().Create >().Register(d,key); +} + +template +void DispatcherGen::Unregister(Dispatchable & d, unsigned key) +{ + for(int i = 0; i < dests.GetCount(); i++) + { + Any & a = dests.operator[](i); + if(!a.Is >()) continue; + Dispatcher & dest = a.Get >(); + dest.Unregister(d, key); + if(dest.GetDests().GetCount()<=0) + dests.Remove(i); + return; + } +} + +template +Dispatcher & DispatcherGen::GetDispatcher() +{ + for(int i = 0; i < dests.GetCount(); i++) + { + const Any & a = dests.operator[](i); + if(!a.Is >()) continue; + Dispatcher & dest = a.Get >(); + return dest; + } + return dests.Add().Create >(); +} + + +//Callback variant + +template +DispatcherCB::DispatcherCB() +{ +} + +template +DispatcherCB::~DispatcherCB() +{ + ASSERT(dests.IsEmpty()); +} + +template +void DispatcherCB::DoDispatch(const T & o, unsigned param) const +{ + for(int i = 0; i < dests.GetCount(); i++) + { + const Callback2 & dest = dests.operator[](i); + dest(o, param); + } +} + +template +void DispatcherCB::Register(Callback2 d, unsigned key) +{ + int i = dests.Find(key); + if(i>=0) return; + dests.Add(key) = d; +} + +template +void DispatcherCB::Unregister(unsigned key) +{ + int i = dests.Find(key); + if(i<0) return; + dests.Remove(i); +} + +template +Callback2 DispatcherCB::GetDispatchable(unsigned key) +{ + int i = dests.Find(key); + if(i<0) return; + Callback2 & dest = dests.operator[](i); + return dest; +} + +template +void DispatcherCBGen::DoDispatch(const T & o, unsigned param) const +{ + for(int i = 0; i < dests.GetCount(); i++) + { + const Any & a = dests.operator[](i); + if(!a.Is >()) continue; + const DispatcherCB & dest = a.Get >(); + dest.DoDispatch(o, param); + return; + } +} + +template +void DispatcherCBGen::Register(Callback2 d, unsigned key) +{ + for(int i = 0; i < dests.GetCount(); i++) + { + Any & a = dests.operator[](i); + if(!a.Is >()) continue; + DispatcherCB & dest = a.Get >(); + dest.Register(d, key); + return; + } + dests.Add().Create >().Register(d,key); +} + +template +void DispatcherCBGen::Unregister(unsigned key) +{ + for(int i = 0; i < dests.GetCount(); i++) + { + Any & a = dests.operator[](i); + if(!a.Is >()) continue; + DispatcherCB & dest = a.Get >(); + dest.Unregister(key); + if(dest.GetDests().GetCount()<=0) + dests.Remove(i); + return; + } +} + +template +DispatcherCB & DispatcherCBGen::GetDispatcherCB() +{ + for(int i = 0; i < dests.GetCount(); i++) + { + const Any & a = dests.operator[](i); + if(!a.Is >()) continue; + DispatcherCB & dest = a.Get >(); + return dest; + } + return dests.Add().Create >(); +} diff --git a/bazaar/Dispatcher/Dispatcher.upp b/bazaar/Dispatcher/Dispatcher.upp new file mode 100644 index 000000000..a440ac835 --- /dev/null +++ b/bazaar/Dispatcher/Dispatcher.upp @@ -0,0 +1,10 @@ +description "a templateable object dispatcher class\377"; + +uses + Core; + +file + Dispatcher.h, + Dispatcher.hpp, + Dispatcher.cpp; + diff --git a/bazaar/Dispatcher/init b/bazaar/Dispatcher/init new file mode 100644 index 000000000..6cd0e49bb --- /dev/null +++ b/bazaar/Dispatcher/init @@ -0,0 +1,4 @@ +#ifndef _Dispatcher_icpp_init_stub +#define _Dispatcher_icpp_init_stub +#include "Core/init" +#endif diff --git a/bazaar/DispatcherTest/DispatcherTest.h b/bazaar/DispatcherTest/DispatcherTest.h new file mode 100644 index 000000000..81c0a8ca9 --- /dev/null +++ b/bazaar/DispatcherTest/DispatcherTest.h @@ -0,0 +1,39 @@ +#ifndef _DispatcherTest_DispatcherTest_h +#define _DispatcherTest_DispatcherTest_h + +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +#include + +class MyPane + : public WithPane + , public Dispatchable +{ +public: + typedef MyPane CLASSNAME; + MyPane(); + + virtual void Dispatch(const Value & o, unsigned param); +}; + +class DispatcherTest : public WithDispatcherTestLayout +{ +public: + typedef DispatcherTest CLASSNAME; + DispatcherTest(); + + void sliderCB(); + + Dispatcher disp; + + Splitter splith1, splith2, splitv; + MyPane pane1, pane2, pane3, pane4; +}; + +#endif + diff --git a/bazaar/DispatcherTest/DispatcherTest.lay b/bazaar/DispatcherTest/DispatcherTest.lay new file mode 100644 index 000000000..bc67bed21 --- /dev/null +++ b/bazaar/DispatcherTest/DispatcherTest.lay @@ -0,0 +1,12 @@ +LAYOUT(DispatcherTestLayout, 388, 240) + ITEM(SliderCtrl, sl, HSizePosZ(48, 8).TopPosZ(8, 24)) + ITEM(StaticText, dv___1, SetText(t_("Value")).LeftPosZ(8, 40).TopPosZ(8, 24)) +END_LAYOUT + +LAYOUT(Pane, 200, 64) + ITEM(StaticText, st, LeftPosZ(8, 88).TopPosZ(8, 19)) + ITEM(DropList, dl, RightPosZ(8, 88).TopPosZ(8, 19)) + ITEM(EditInt, ei, LeftPosZ(8, 88).BottomPosZ(9, 19)) + ITEM(ProgressIndicator, pi, RightPosZ(8, 88).BottomPosZ(8, 24)) +END_LAYOUT + diff --git a/bazaar/DispatcherTest/DispatcherTest.upp b/bazaar/DispatcherTest/DispatcherTest.upp new file mode 100644 index 000000000..058adb185 --- /dev/null +++ b/bazaar/DispatcherTest/DispatcherTest.upp @@ -0,0 +1,14 @@ +description "functional demo for Dispatcher. how to extend an application with Dispatchable interface\377"; + +uses + CtrlLib, + Dispatcher; + +file + DispatcherTest.h, + main.cpp, + DispatcherTest.lay; + +mainconfig + "" = "GUI MT"; + diff --git a/bazaar/DispatcherTest/init b/bazaar/DispatcherTest/init new file mode 100644 index 000000000..1926a7436 --- /dev/null +++ b/bazaar/DispatcherTest/init @@ -0,0 +1,5 @@ +#ifndef _DispatcherTest_icpp_init_stub +#define _DispatcherTest_icpp_init_stub +#include "CtrlLib/init" +#include "Dispatcher/init" +#endif diff --git a/bazaar/DispatcherTest/main.cpp b/bazaar/DispatcherTest/main.cpp new file mode 100644 index 000000000..b2bbae04c --- /dev/null +++ b/bazaar/DispatcherTest/main.cpp @@ -0,0 +1,60 @@ +#include "DispatcherTest.h" + +MyPane::MyPane() +{ + CtrlLayout(*this); + + ei.MinMax(0, 100); + pi.SetTotal(100); + for(int i = 0; i < 100; i++) + dl.Add(i); +} + +void MyPane::Dispatch(const Value & o, unsigned param) +{ + ei.SetData(o); + //pi.SetData(o); + pi.Set(o); + dl.SetData(o); + st.SetText(String().Cat() << o); +} + +// + +void DispatcherTest::sliderCB() +{ + Value o = sl.GetData(); + disp.DoDispatch(o, 123); +} + +DispatcherTest::DispatcherTest() +{ + CtrlLayout(*this, "Window title"); + + splith1.Horz() + << pane1 << pane2; + splith2.Horz() + << pane3 << pane4; + splitv.Vert() + << splith1 << splith2; + Add(splitv.HSizePos().VSizePos(50, 0)); + Sizeable().Zoomable(); + + disp.Register(pane1); + disp.Register(pane2); + disp.Register(pane3); + disp.Register(pane4); + + sl.MinMax(0,100); + sl <<= THISBACK(sliderCB); + + //for beauty only, send once to see stuff already + sl.SetData(75); + sliderCB(); +} + +GUI_APP_MAIN +{ + DispatcherTest().Run(); +} + diff --git a/bazaar/DispatcherTest2/DispatcherTest.h b/bazaar/DispatcherTest2/DispatcherTest.h new file mode 100644 index 000000000..14fbec7ca --- /dev/null +++ b/bazaar/DispatcherTest2/DispatcherTest.h @@ -0,0 +1,43 @@ +#ifndef _DispatcherTest_DispatcherTest_h +#define _DispatcherTest_DispatcherTest_h + +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +#include + +class MyPane + : public WithPane + , public Dispatchable + , public Dispatchable +{ +public: + typedef MyPane CLASSNAME; + MyPane(); + + virtual void Dispatch(const Value & o, unsigned param); + virtual void Dispatch(const int & o, unsigned param); +}; + +class DispatcherTest : public WithDispatcherTestLayout +{ +public: + typedef DispatcherTest CLASSNAME; + DispatcherTest(); + + void sliderCB(); + void slideriCB(); + + Dispatcher disp; + Dispatcher dispi; + + Splitter splith1, splith2, splitv; + MyPane pane1, pane2, pane3, pane4; +}; + +#endif + diff --git a/bazaar/DispatcherTest2/DispatcherTest.lay b/bazaar/DispatcherTest2/DispatcherTest.lay new file mode 100644 index 000000000..d49c5c11b --- /dev/null +++ b/bazaar/DispatcherTest2/DispatcherTest.lay @@ -0,0 +1,14 @@ +LAYOUT(DispatcherTestLayout, 388, 240) + ITEM(SliderCtrl, sl, LeftPosZ(48, 144).TopPosZ(8, 24)) + ITEM(StaticText, dv___1, SetText(t_("Value")).LeftPosZ(8, 40).TopPosZ(8, 24)) + ITEM(SliderCtrl, sli, RightPosZ(48, 148).TopPosZ(8, 24)) + ITEM(StaticText, dv___3, SetText(t_("int")).RightPosZ(8, 40).TopPosZ(8, 24)) +END_LAYOUT + +LAYOUT(Pane, 200, 64) + ITEM(StaticText, st, LeftPosZ(8, 88).TopPosZ(8, 19)) + ITEM(DropList, dl, RightPosZ(8, 88).TopPosZ(8, 19)) + ITEM(EditInt, ei, LeftPosZ(8, 88).BottomPosZ(9, 19)) + ITEM(ProgressIndicator, pi, RightPosZ(8, 88).BottomPosZ(8, 24)) +END_LAYOUT + diff --git a/bazaar/DispatcherTest2/DispatcherTest2.upp b/bazaar/DispatcherTest2/DispatcherTest2.upp new file mode 100644 index 000000000..0eb810f56 --- /dev/null +++ b/bazaar/DispatcherTest2/DispatcherTest2.upp @@ -0,0 +1,14 @@ +description "functional demo for Dispatcher, how to support multiple Dispatchable interfaces\377"; + +uses + CtrlLib, + Dispatcher; + +file + DispatcherTest.h, + main.cpp, + DispatcherTest.lay; + +mainconfig + "" = "GUI MT"; + diff --git a/bazaar/DispatcherTest2/init b/bazaar/DispatcherTest2/init new file mode 100644 index 000000000..1926a7436 --- /dev/null +++ b/bazaar/DispatcherTest2/init @@ -0,0 +1,5 @@ +#ifndef _DispatcherTest_icpp_init_stub +#define _DispatcherTest_icpp_init_stub +#include "CtrlLib/init" +#include "Dispatcher/init" +#endif diff --git a/bazaar/DispatcherTest2/main.cpp b/bazaar/DispatcherTest2/main.cpp new file mode 100644 index 000000000..bcec0df8f --- /dev/null +++ b/bazaar/DispatcherTest2/main.cpp @@ -0,0 +1,84 @@ +#include "DispatcherTest.h" + +MyPane::MyPane() +{ + CtrlLayout(*this); + + ei.MinMax(0, 100); + pi.SetTotal(100); + for(int i = 0; i < 100; i++) + dl.Add(i); +} + +void MyPane::Dispatch(const Value & o, unsigned param) +{ + ei.SetData(o); + //pi.SetData(o); + pi.Set(o); + dl.SetData(o); + st.SetText(String().Cat() << o); +} + +void MyPane::Dispatch(const int & o, unsigned param) +{ + ei.SetData(o); + //pi.SetData(o); + pi.Set(o); + dl.SetData(o); + st.SetText(String().Cat() << o); +} + +// + +void DispatcherTest::sliderCB() +{ + Value o = sl.GetData(); + disp.DoDispatch(o, 123); +} + +void DispatcherTest::slideriCB() +{ + int o = sli.GetData(); + dispi.DoDispatch(o, 125); +} + +DispatcherTest::DispatcherTest() +{ + CtrlLayout(*this, "Window title"); + + splith1.Horz() + << pane1 << pane2; + splith2.Horz() + << pane3 << pane4; + splitv.Vert() + << splith1 << splith2; + Add(splitv.HSizePos().VSizePos(50, 0)); + Sizeable().Zoomable(); + + disp.Register(pane1); + disp.Register(pane2); + disp.Register(pane3); + disp.Register(pane4); + + dispi.Register(pane1); + dispi.Register(pane2); + dispi.Register(pane3); + dispi.Register(pane4); + + sl.MinMax(0,100); + sl <<= THISBACK(sliderCB); + sli.MinMax(0,100); + sli <<= THISBACK(slideriCB); + + //for beauty only, send once to see stuff already + sl.SetData(75); + sliderCB(); + + sli.SetData(75); +} + +GUI_APP_MAIN +{ + DispatcherTest().Run(); +} + diff --git a/bazaar/DispatcherTest3/DispatcherTest.h b/bazaar/DispatcherTest3/DispatcherTest.h new file mode 100644 index 000000000..98d3cec37 --- /dev/null +++ b/bazaar/DispatcherTest3/DispatcherTest.h @@ -0,0 +1,61 @@ +#ifndef _DispatcherTest_DispatcherTest_h +#define _DispatcherTest_DispatcherTest_h + +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +#include + +template +class WithDispatch + : public C + , public Dispatchable + +{ +public: + typedef WithDispatch CLASSNAME; + + virtual void Dispatch(const T & o, unsigned param) + { + C::SetData(o); + } +}; + +template +class ProgressIndicatorWithDispatch + : public ProgressIndicator + , public Dispatchable + +{ +public: + typedef ProgressIndicatorWithDispatch CLASSNAME; + + virtual void Dispatch(const T & o, unsigned param) + { + Set(o); + } +}; + + +class DispatcherTest : public WithDispatcherTestLayout +{ +public: + typedef DispatcherTest CLASSNAME; + DispatcherTest(); + + void sliderCB(); + void slideriCB(); + + Dispatcher disp; + Dispatcher dispi; + + Array ctrls; + Splitter splitv1, splitv2, splith; +}; + +#endif + diff --git a/bazaar/DispatcherTest3/DispatcherTest.lay b/bazaar/DispatcherTest3/DispatcherTest.lay new file mode 100644 index 000000000..7cb4f8552 --- /dev/null +++ b/bazaar/DispatcherTest3/DispatcherTest.lay @@ -0,0 +1,5 @@ +LAYOUT(DispatcherTestLayout, 388, 240) + ITEM(SliderCtrl, sl, HSizePosZ(48, 8).TopPosZ(8, 24)) + ITEM(StaticText, dv___1, SetText(t_("Value")).LeftPosZ(8, 40).TopPosZ(8, 24)) +END_LAYOUT + diff --git a/bazaar/DispatcherTest3/DispatcherTest3.upp b/bazaar/DispatcherTest3/DispatcherTest3.upp new file mode 100644 index 000000000..df6af526b --- /dev/null +++ b/bazaar/DispatcherTest3/DispatcherTest3.upp @@ -0,0 +1,14 @@ +description "functional demo for Dispatcher, how to use multiple Ctrl's with Dispatchable interface\377"; + +uses + CtrlLib, + Dispatcher; + +file + DispatcherTest.h, + main.cpp, + DispatcherTest.lay; + +mainconfig + "" = "GUI MT"; + diff --git a/bazaar/DispatcherTest3/init b/bazaar/DispatcherTest3/init new file mode 100644 index 000000000..1926a7436 --- /dev/null +++ b/bazaar/DispatcherTest3/init @@ -0,0 +1,5 @@ +#ifndef _DispatcherTest_icpp_init_stub +#define _DispatcherTest_icpp_init_stub +#include "CtrlLib/init" +#include "Dispatcher/init" +#endif diff --git a/bazaar/DispatcherTest3/main.cpp b/bazaar/DispatcherTest3/main.cpp new file mode 100644 index 000000000..0984bfb49 --- /dev/null +++ b/bazaar/DispatcherTest3/main.cpp @@ -0,0 +1,63 @@ +#include "DispatcherTest.h" + +void DispatcherTest::sliderCB() +{ + Value o = sl.GetData(); + disp.DoDispatch(o, 123); +} + +/* +void DispatcherTest::slideriCB() +{ + int o = sli.GetData(); + dispi.DoDispatch(o, 125); +} +*/ + +DispatcherTest::DispatcherTest() +{ + CtrlLayout(*this, "Window title"); + + splitv1.Vert(); + for(int i = 0; i < 10; i++) + { + WithDispatch * pctrl = new WithDispatch(); + ctrls.Add(pctrl); + pctrl->MinMax(0, 100); + disp.Register(*pctrl); + splitv1 << *pctrl; + } + + splitv2.Vert(); + for(int i = 0; i < 10; i++) + { + ProgressIndicatorWithDispatch * pctrl = new ProgressIndicatorWithDispatch(); + ctrls.Add(pctrl); + pctrl->SetTotal(100); + disp.Register(*pctrl); + splitv2 << *pctrl; + } + + splith.Horz() + << splitv1 << splitv2; + + Add(splith.HSizePos().VSizePos(50, 0)); + Sizeable().Zoomable(); + + sl.MinMax(0,100); + sl <<= THISBACK(sliderCB); +// sli.MinMax(0,100); +// sli <<= THISBACK(slideriCB); + + //for beauty only, send once to see stuff already + sl.SetData(75); + sliderCB(); + +// sli.SetData(75); +} + +GUI_APP_MAIN +{ + DispatcherTest().Run(); +} + diff --git a/bazaar/DispatcherTest4/DispatcherTest.h b/bazaar/DispatcherTest4/DispatcherTest.h new file mode 100644 index 000000000..e382111a9 --- /dev/null +++ b/bazaar/DispatcherTest4/DispatcherTest.h @@ -0,0 +1,66 @@ +#ifndef _DispatcherTest_DispatcherTest_h +#define _DispatcherTest_DispatcherTest_h + +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +#include + +class MyEditInt + : public EditInt + , public Dispatchable + , public Dispatchable +{ +public: + typedef MyEditInt CLASSNAME; + + virtual void Dispatch(const Value & o, unsigned param) + { + SetData(o); + } + virtual void Dispatch(const int & o, unsigned param) + { + SetData(o); + } +}; + +class MyProgressIndicator + : public ProgressIndicator + , public Dispatchable + , public Dispatchable +{ +public: + typedef MyProgressIndicator CLASSNAME; + + virtual void Dispatch(const Value & o, unsigned param) + { + Set(o); + } + virtual void Dispatch(const int & o, unsigned param) + { + Set(o); + } +}; + +class DispatcherTest : public WithDispatcherTestLayout +{ +public: + typedef DispatcherTest CLASSNAME; + DispatcherTest(); + + void sliderCB(); + void slideriCB(); + + Dispatcher disp; + Dispatcher dispi; + + Array ctrls; + Splitter splitv1, splitv2, splith; +}; + +#endif + diff --git a/bazaar/DispatcherTest4/DispatcherTest.lay b/bazaar/DispatcherTest4/DispatcherTest.lay new file mode 100644 index 000000000..eb6305508 --- /dev/null +++ b/bazaar/DispatcherTest4/DispatcherTest.lay @@ -0,0 +1,7 @@ +LAYOUT(DispatcherTestLayout, 388, 240) + ITEM(SliderCtrl, sl, LeftPosZ(48, 148).TopPosZ(8, 24)) + ITEM(SliderCtrl, sli, RightPosZ(48, 144).TopPosZ(8, 24)) + ITEM(StaticText, dv___2, SetText(t_("Value")).LeftPosZ(8, 40).TopPosZ(8, 24)) + ITEM(StaticText, dv___3, SetText(t_("int")).RightPosZ(8, 40).TopPosZ(8, 24)) +END_LAYOUT + diff --git a/bazaar/DispatcherTest4/DispatcherTest4.upp b/bazaar/DispatcherTest4/DispatcherTest4.upp new file mode 100644 index 000000000..b5e706eef --- /dev/null +++ b/bazaar/DispatcherTest4/DispatcherTest4.upp @@ -0,0 +1,14 @@ +description "functional demo for Dispatcher, how to use multiple Ctrl's with multiple Dispatchable interfaces\377"; + +uses + CtrlLib, + Dispatcher; + +file + DispatcherTest.h, + main.cpp, + DispatcherTest.lay; + +mainconfig + "" = "GUI MT"; + diff --git a/bazaar/DispatcherTest4/init b/bazaar/DispatcherTest4/init new file mode 100644 index 000000000..1926a7436 --- /dev/null +++ b/bazaar/DispatcherTest4/init @@ -0,0 +1,5 @@ +#ifndef _DispatcherTest_icpp_init_stub +#define _DispatcherTest_icpp_init_stub +#include "CtrlLib/init" +#include "Dispatcher/init" +#endif diff --git a/bazaar/DispatcherTest4/main.cpp b/bazaar/DispatcherTest4/main.cpp new file mode 100644 index 000000000..39cd5f8c5 --- /dev/null +++ b/bazaar/DispatcherTest4/main.cpp @@ -0,0 +1,72 @@ +#include "DispatcherTest.h" + +void DispatcherTest::sliderCB() +{ + Value o = sl.GetData(); + disp.DoDispatch(o, 123); +} + +void DispatcherTest::slideriCB() +{ + int o = sli.GetData(); + dispi.DoDispatch(o, 125); +} + + +DispatcherTest::DispatcherTest() +{ + CtrlLayout(*this, "Window title"); + + splitv1.Vert(); + for(int i = 0; i < 10; i++) + { + MyEditInt * pctrl = new MyEditInt(); + ctrls.Add(pctrl); + pctrl->MinMax(0, 100); + disp.Register(*pctrl); + dispi.Register(*pctrl); + + //disp.Unregister(*pctrl); + //dispi.Unregister(*pctrl); + + splitv1 << *pctrl; + } + + splitv2.Vert(); + for(int i = 0; i < 10; i++) + { + MyProgressIndicator * pctrl = new MyProgressIndicator(); + ctrls.Add(pctrl); + pctrl->SetTotal(100); + disp.Register(*pctrl); + dispi.Register(*pctrl); + + //disp.Unregister(*pctrl); + //dispi.Unregister(*pctrl); + + splitv2 << *pctrl; + } + + splith.Horz() + << splitv1 << splitv2; + + Add(splith.HSizePos().VSizePos(50, 0)); + Sizeable().Zoomable(); + + sl.MinMax(0,100); + sl <<= THISBACK(sliderCB); + sli.MinMax(0,100); + sli <<= THISBACK(slideriCB); + + //for beauty only, send once to see stuff already + sl.SetData(75); + sliderCB(); + + sli.SetData(75); +} + +GUI_APP_MAIN +{ + DispatcherTest().Run(); +} + diff --git a/bazaar/DispatcherTest5/DispatcherTest.h b/bazaar/DispatcherTest5/DispatcherTest.h new file mode 100644 index 000000000..9fefc2cc3 --- /dev/null +++ b/bazaar/DispatcherTest5/DispatcherTest.h @@ -0,0 +1,65 @@ +#ifndef _DispatcherTest_DispatcherTest_h +#define _DispatcherTest_DispatcherTest_h + +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +#include + +class MyEditInt + : public EditInt + , public Dispatchable + , public Dispatchable +{ +public: + typedef MyEditInt CLASSNAME; + + virtual void Dispatch(const Value & o, unsigned param) + { + SetData(o); + } + virtual void Dispatch(const int & o, unsigned param) + { + SetData(o); + } +}; + +class MyProgressIndicator + : public ProgressIndicator + , public Dispatchable + , public Dispatchable +{ +public: + typedef MyProgressIndicator CLASSNAME; + + virtual void Dispatch(const Value & o, unsigned param) + { + Set(o); + } + virtual void Dispatch(const int & o, unsigned param) + { + Set(o); + } +}; + +class DispatcherTest : public WithDispatcherTestLayout +{ +public: + typedef DispatcherTest CLASSNAME; + DispatcherTest(); + + void sliderCB(); + void slideriCB(); + + DispatcherGen disp; + + Array ctrls; + Splitter splitv1, splitv2, splith; +}; + +#endif + diff --git a/bazaar/DispatcherTest5/DispatcherTest.lay b/bazaar/DispatcherTest5/DispatcherTest.lay new file mode 100644 index 000000000..eb6305508 --- /dev/null +++ b/bazaar/DispatcherTest5/DispatcherTest.lay @@ -0,0 +1,7 @@ +LAYOUT(DispatcherTestLayout, 388, 240) + ITEM(SliderCtrl, sl, LeftPosZ(48, 148).TopPosZ(8, 24)) + ITEM(SliderCtrl, sli, RightPosZ(48, 144).TopPosZ(8, 24)) + ITEM(StaticText, dv___2, SetText(t_("Value")).LeftPosZ(8, 40).TopPosZ(8, 24)) + ITEM(StaticText, dv___3, SetText(t_("int")).RightPosZ(8, 40).TopPosZ(8, 24)) +END_LAYOUT + diff --git a/bazaar/DispatcherTest5/DispatcherTest5.upp b/bazaar/DispatcherTest5/DispatcherTest5.upp new file mode 100644 index 000000000..1249e64b7 --- /dev/null +++ b/bazaar/DispatcherTest5/DispatcherTest5.upp @@ -0,0 +1,14 @@ +description "functional demo for GenDispatcher, how to use multiple Ctrl's with multiple Dispatchable interfaces on a generic Dispatcher\377"; + +uses + CtrlLib, + Dispatcher; + +file + DispatcherTest.h, + main.cpp, + DispatcherTest.lay; + +mainconfig + "" = "GUI MT"; + diff --git a/bazaar/DispatcherTest5/init b/bazaar/DispatcherTest5/init new file mode 100644 index 000000000..1926a7436 --- /dev/null +++ b/bazaar/DispatcherTest5/init @@ -0,0 +1,5 @@ +#ifndef _DispatcherTest_icpp_init_stub +#define _DispatcherTest_icpp_init_stub +#include "CtrlLib/init" +#include "Dispatcher/init" +#endif diff --git a/bazaar/DispatcherTest5/main.cpp b/bazaar/DispatcherTest5/main.cpp new file mode 100644 index 000000000..c4df3d466 --- /dev/null +++ b/bazaar/DispatcherTest5/main.cpp @@ -0,0 +1,73 @@ +#include "DispatcherTest.h" + +void DispatcherTest::sliderCB() +{ + Value o = sl.GetData(); + disp.DoDispatch(o, 123); +} + +void DispatcherTest::slideriCB() +{ + int o = sli.GetData(); + disp.DoDispatch(o, 125); +} + + +DispatcherTest::DispatcherTest() +{ + CtrlLayout(*this, "Window title"); + + splitv1.Vert(); + for(int i = 0; i < 10; i++) + { + MyEditInt * pctrl = new MyEditInt(); + ctrls.Add(pctrl); + pctrl->MinMax(0, 100); + + disp.Register(*pctrl); + disp.Register(*pctrl); + + //disp.Unregister(*pctrl); + //disp.Unregister(*pctrl); + + splitv1 << *pctrl; + } + + splitv2.Vert(); + for(int i = 0; i < 10; i++) + { + MyProgressIndicator * pctrl = new MyProgressIndicator(); + ctrls.Add(pctrl); + pctrl->SetTotal(100); + disp.Register(*pctrl); + disp.Register(*pctrl); + + //disp.Unregister(*pctrl); + //disp.Unregister(*pctrl); + + splitv2 << *pctrl; + } + + splith.Horz() + << splitv1 << splitv2; + + Add(splith.HSizePos().VSizePos(50, 0)); + Sizeable().Zoomable(); + + sl.MinMax(0,100); + sl <<= THISBACK(sliderCB); + sli.MinMax(0,100); + sli <<= THISBACK(slideriCB); + + //for beauty only, send once to see stuff already + sl.SetData(75); + sliderCB(); + + sli.SetData(75); +} + +GUI_APP_MAIN +{ + DispatcherTest().Run(); +} + diff --git a/bazaar/DispatcherTest6/DispatcherTest.h b/bazaar/DispatcherTest6/DispatcherTest.h new file mode 100644 index 000000000..a4818cc58 --- /dev/null +++ b/bazaar/DispatcherTest6/DispatcherTest.h @@ -0,0 +1,63 @@ +#ifndef _DispatcherTest_DispatcherTest_h +#define _DispatcherTest_DispatcherTest_h + +#include + +using namespace Upp; + +#define LAYOUTFILE +#include + +#include + +class MyEditInt + : public EditInt +{ +public: + typedef MyEditInt CLASSNAME; + + virtual void DispatchV(const Value & o, unsigned param) + { + SetData(o); + } + virtual void DispatchI(const int & o, unsigned param) + { + SetData(o); + } +}; + +class MyProgressIndicator + : public ProgressIndicator +{ +public: + typedef MyProgressIndicator CLASSNAME; + + virtual void DispatchV(const Value & o, unsigned param) + { + Set(o); + } + virtual void DispatchI(const int & o, unsigned param) + { + Set(o); + } +}; + +class DispatcherTest : public WithDispatcherTestLayout +{ +public: + typedef DispatcherTest CLASSNAME; + DispatcherTest(); + ~DispatcherTest(); + + void sliderCB(); + void slideriCB(); + virtual void Dispatch(const Value & o, unsigned param); + + DispatcherCBGen disp; + + Array ctrls; + Splitter splitv1, splitv2, splith; +}; + +#endif + diff --git a/bazaar/DispatcherTest6/DispatcherTest.lay b/bazaar/DispatcherTest6/DispatcherTest.lay new file mode 100644 index 000000000..eb6305508 --- /dev/null +++ b/bazaar/DispatcherTest6/DispatcherTest.lay @@ -0,0 +1,7 @@ +LAYOUT(DispatcherTestLayout, 388, 240) + ITEM(SliderCtrl, sl, LeftPosZ(48, 148).TopPosZ(8, 24)) + ITEM(SliderCtrl, sli, RightPosZ(48, 144).TopPosZ(8, 24)) + ITEM(StaticText, dv___2, SetText(t_("Value")).LeftPosZ(8, 40).TopPosZ(8, 24)) + ITEM(StaticText, dv___3, SetText(t_("int")).RightPosZ(8, 40).TopPosZ(8, 24)) +END_LAYOUT + diff --git a/bazaar/DispatcherTest6/DispatcherTest6.upp b/bazaar/DispatcherTest6/DispatcherTest6.upp new file mode 100644 index 000000000..2b2d2fe65 --- /dev/null +++ b/bazaar/DispatcherTest6/DispatcherTest6.upp @@ -0,0 +1,14 @@ +description "functional demo for DispatcherCB, how to use multiple Ctrl's on a Callback Dispatcher\377"; + +uses + CtrlLib, + Dispatcher; + +file + DispatcherTest.h, + main.cpp, + DispatcherTest.lay; + +mainconfig + "" = "GUI MT"; + diff --git a/bazaar/DispatcherTest6/init b/bazaar/DispatcherTest6/init new file mode 100644 index 000000000..1926a7436 --- /dev/null +++ b/bazaar/DispatcherTest6/init @@ -0,0 +1,5 @@ +#ifndef _DispatcherTest_icpp_init_stub +#define _DispatcherTest_icpp_init_stub +#include "CtrlLib/init" +#include "Dispatcher/init" +#endif diff --git a/bazaar/DispatcherTest6/main.cpp b/bazaar/DispatcherTest6/main.cpp new file mode 100644 index 000000000..676bbc79a --- /dev/null +++ b/bazaar/DispatcherTest6/main.cpp @@ -0,0 +1,87 @@ +#include "DispatcherTest.h" + +void DispatcherTest::sliderCB() +{ + Value o = sl.GetData(); + disp.DoDispatch(o, 123); +} + +void DispatcherTest::slideriCB() +{ + int o = sli.GetData(); + disp.DoDispatch(o, 125); +} + +void DispatcherTest::Dispatch(const Value & o, unsigned param) +{ + int a = 0; +} + +DispatcherTest::DispatcherTest() +{ + CtrlLayout(*this, "Window title"); + + splitv1.Vert(); + int i = 0; + for(; i < 10; i++) + { + MyEditInt * pctrl = new MyEditInt(); + ctrls.Add(pctrl); + pctrl->MinMax(0, 100); + + disp.Register(callback(pctrl, &MyEditInt::DispatchV), i); + disp.Register(callback(pctrl, &MyEditInt::DispatchI), 100+i); + + //disp.Unregister(i); + //disp.Unregister(100+i); + + splitv1 << *pctrl; + } + + splitv2.Vert(); + for(; i < 20; i++) + { + MyProgressIndicator * pctrl = new MyProgressIndicator(); + ctrls.Add(pctrl); + pctrl->SetTotal(100); + + disp.Register(callback(pctrl, &MyProgressIndicator::DispatchV), i); + disp.Register(callback(pctrl, &MyProgressIndicator::DispatchI), 100+i); + + //disp.Unregister(i); + //disp.Unregister(100+i); + + splitv2 << *pctrl; + } + + splith.Horz() + << splitv1 << splitv2; + + Add(splith.HSizePos().VSizePos(50, 0)); + Sizeable().Zoomable(); + + sl.MinMax(0,100); + sl <<= THISBACK(sliderCB); + sli.MinMax(0,100); + sli <<= THISBACK(slideriCB); + + //for beauty only, send once to see stuff already + sl.SetData(75); + sliderCB(); + + sli.SetData(75); +} + +DispatcherTest::~DispatcherTest() +{ + for(int i = 0; i < 20; i++) + { + disp.Unregister(i); + disp.Unregister(100+i); + } +} +GUI_APP_MAIN +{ + DispatcherTest().Run(); +} +