mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
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
This commit is contained in:
parent
3bd8d9bf51
commit
e8a2be07ec
35 changed files with 1366 additions and 0 deletions
34
bazaar/Dispatcher/Dispatcher.cpp
Normal file
34
bazaar/Dispatcher/Dispatcher.cpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include "Dispatcher.hpp"
|
||||
|
||||
DispatcherGen::DispatcherGen()
|
||||
{
|
||||
}
|
||||
|
||||
DispatcherGen::~DispatcherGen()
|
||||
{
|
||||
//ASSERT(dests.IsEmpty()); //FIXME, DispatcherGen does keep the Dispatcher<T> instances, cause Dispatchable<T> 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<T> instances, cause Dispatchable<T> are Register()ed there (forwarded) and do Unregister() only there as well.
|
||||
}
|
||||
|
||||
#if 0 //for compile / debug only
|
||||
template class Dispatchable<int>;
|
||||
template class Dispatcher<int>;
|
||||
|
||||
template void DispatcherGen::DoDispatch<int>(const int & o, unsigned param) const;
|
||||
template void DispatcherGen::Register<int>(Dispatchable<int> & d, unsigned key);
|
||||
template void DispatcherGen::Unregister<int>(Dispatchable<int> & d, unsigned key);
|
||||
|
||||
DispatcherGen gen;
|
||||
DispatcherCBGen gencb;
|
||||
#endif
|
||||
125
bazaar/Dispatcher/Dispatcher.h
Normal file
125
bazaar/Dispatcher/Dispatcher.h
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
#ifndef _Dispatcher_Dispatcher_h
|
||||
#define _Dispatcher_Dispatcher_h
|
||||
|
||||
#include <Core/Core.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
template<class T>
|
||||
class Dispatcher;
|
||||
|
||||
class DispatcherGen;
|
||||
|
||||
template<class T>
|
||||
class Dispatchable
|
||||
{
|
||||
friend class Dispatcher<T>;
|
||||
friend class DispatcherGen;
|
||||
public:
|
||||
typedef Dispatchable<T> 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<T> & 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<unsigned, Any> & GetSrc() const { return src; }
|
||||
|
||||
private:
|
||||
VectorMap<unsigned, Any> src;
|
||||
VectorMap<unsigned, unsigned> key; //cache under which key registered for removal
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class Dispatcher
|
||||
{
|
||||
public:
|
||||
typedef Dispatcher<T> CLASSNAME;
|
||||
Dispatcher();
|
||||
virtual ~Dispatcher();
|
||||
|
||||
void DoDispatch(const T & o, unsigned param = 0) const;
|
||||
|
||||
void Register(Dispatchable<T> & d, unsigned key = 0);
|
||||
void Unregister(Dispatchable<T> & d, unsigned key = 0);
|
||||
Dispatchable<T> * GetDispatchable(unsigned key) const;
|
||||
const VectorMap<unsigned, Dispatchable<T> * > & GetDests() const { return dests; }
|
||||
|
||||
private:
|
||||
VectorMap<unsigned, Dispatchable<T> * > dests;
|
||||
};
|
||||
|
||||
//a generic version that accepts any Dispatchable<T>
|
||||
class DispatcherGen
|
||||
{
|
||||
public:
|
||||
typedef DispatcherGen CLASSNAME;
|
||||
DispatcherGen();
|
||||
virtual ~DispatcherGen();
|
||||
|
||||
template<class T>
|
||||
void DoDispatch(const T & o, unsigned param = 0) const;
|
||||
|
||||
template<class T>
|
||||
void Register(Dispatchable<T> & d, unsigned key = 0);
|
||||
template<class T>
|
||||
void Unregister(Dispatchable<T> & d, unsigned key = 0);
|
||||
template<class T>
|
||||
Dispatcher<T> & GetDispatcher();
|
||||
|
||||
private:
|
||||
Vector<Any> dests; //now does store the different Dispatcher<T>
|
||||
};
|
||||
|
||||
|
||||
//Callback variant
|
||||
//spares out Dispatchable<T> interface
|
||||
|
||||
template<class T>
|
||||
class DispatcherCB
|
||||
{
|
||||
public:
|
||||
typedef DispatcherCB<T> CLASSNAME;
|
||||
DispatcherCB();
|
||||
virtual ~DispatcherCB();
|
||||
|
||||
void DoDispatch(const T & o, unsigned param = 0) const;
|
||||
|
||||
void Register(Callback2<const T &, unsigned> d, unsigned key);
|
||||
void Unregister(unsigned key);
|
||||
Callback2<const T &, unsigned> GetDispatchable(unsigned key);
|
||||
const VectorMap<unsigned, Callback2<const T &, unsigned> > & GetDests() const { return dests; }
|
||||
|
||||
private:
|
||||
VectorMap<unsigned, Callback2<const T &, unsigned> > dests;
|
||||
};
|
||||
|
||||
//a generic version that accepts any Callback<cons T &, unsigned>
|
||||
class DispatcherCBGen
|
||||
{
|
||||
public:
|
||||
typedef DispatcherCBGen CLASSNAME;
|
||||
DispatcherCBGen();
|
||||
virtual ~DispatcherCBGen();
|
||||
|
||||
template<class T>
|
||||
void DoDispatch(const T & o, unsigned param = 0) const;
|
||||
|
||||
template<class T>
|
||||
void Register(Callback2<const T &, unsigned> d, unsigned key);
|
||||
template<class T>
|
||||
void Unregister(unsigned key);
|
||||
template<class T>
|
||||
DispatcherCB<T> & GetDispatcherCB();
|
||||
|
||||
private:
|
||||
Vector<Any> dests; //now does store the different DispatcherCB<T>
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
251
bazaar/Dispatcher/Dispatcher.hpp
Normal file
251
bazaar/Dispatcher/Dispatcher.hpp
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
#include "Dispatcher.h"
|
||||
|
||||
template<class T>
|
||||
Dispatchable<T>::Dispatchable()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Dispatchable<T>::~Dispatchable()
|
||||
{
|
||||
UnregisterAll();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Dispatchable<T>::Unregister(const Any & _src)
|
||||
{
|
||||
if(_src.Is<Dispatcher<T> * >())
|
||||
{
|
||||
Dispatcher<T> * disp = _src.Get<Dispatcher<T> * >();
|
||||
disp->Unregister(*this, key.Get(GetPtrHashValue(disp)));
|
||||
}
|
||||
else
|
||||
if(_src.Is<DispatcherGen * >())
|
||||
{
|
||||
DispatcherGen * disp = _src.Get<DispatcherGen * >();
|
||||
disp->Unregister(*this, key.Get(GetPtrHashValue(disp)));
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Dispatchable<T>::UnregisterAll()
|
||||
{
|
||||
while(src.GetCount()>0)
|
||||
{
|
||||
Unregister(src[0]);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Dispatcher<T>::Dispatcher()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Dispatcher<T>::~Dispatcher()
|
||||
{
|
||||
ASSERT(dests.IsEmpty());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Dispatcher<T>::DoDispatch(const T & o, unsigned param) const
|
||||
{
|
||||
for(int i = 0; i < dests.GetCount(); i++)
|
||||
{
|
||||
Dispatchable<T> * dest = dests.operator[](i);
|
||||
dest->Dispatch(o, param);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Dispatcher<T>::Register(Dispatchable<T> & 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<Dispatcher<T> * >() = this;
|
||||
d.key.Add(GetPtrHashValue(this)) = key;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void Dispatcher<T>::Unregister(Dispatchable<T> & 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<class T>
|
||||
Dispatchable<T> * Dispatcher<T>::GetDispatchable(unsigned key) const
|
||||
{
|
||||
int i = dests.Find(key);
|
||||
if(i<0) return NULL;
|
||||
Dispatchable<T> * dest = dests.operator[](i);
|
||||
return dest;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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<Dispatcher<T> >()) continue;
|
||||
const Dispatcher<T> & dest = a.Get<Dispatcher<T> >();
|
||||
dest.DoDispatch(o, param);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DispatcherGen::Register(Dispatchable<T> & d, unsigned key)
|
||||
{
|
||||
for(int i = 0; i < dests.GetCount(); i++)
|
||||
{
|
||||
Any & a = dests.operator[](i);
|
||||
if(!a.Is<Dispatcher<T> >()) continue;
|
||||
Dispatcher<T> & dest = a.Get<Dispatcher<T> >();
|
||||
dest.Register(d, key);
|
||||
return;
|
||||
}
|
||||
dests.Add().Create<Dispatcher<T> >().Register(d,key);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DispatcherGen::Unregister(Dispatchable<T> & d, unsigned key)
|
||||
{
|
||||
for(int i = 0; i < dests.GetCount(); i++)
|
||||
{
|
||||
Any & a = dests.operator[](i);
|
||||
if(!a.Is<Dispatcher<T> >()) continue;
|
||||
Dispatcher<T> & dest = a.Get<Dispatcher<T> >();
|
||||
dest.Unregister(d, key);
|
||||
if(dest.GetDests().GetCount()<=0)
|
||||
dests.Remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Dispatcher<T> & DispatcherGen::GetDispatcher()
|
||||
{
|
||||
for(int i = 0; i < dests.GetCount(); i++)
|
||||
{
|
||||
const Any & a = dests.operator[](i);
|
||||
if(!a.Is<Dispatcher<T> >()) continue;
|
||||
Dispatcher<T> & dest = a.Get<Dispatcher<T> >();
|
||||
return dest;
|
||||
}
|
||||
return dests.Add().Create<Dispatcher<T> >();
|
||||
}
|
||||
|
||||
|
||||
//Callback variant
|
||||
|
||||
template<class T>
|
||||
DispatcherCB<T>::DispatcherCB()
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
DispatcherCB<T>::~DispatcherCB()
|
||||
{
|
||||
ASSERT(dests.IsEmpty());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DispatcherCB<T>::DoDispatch(const T & o, unsigned param) const
|
||||
{
|
||||
for(int i = 0; i < dests.GetCount(); i++)
|
||||
{
|
||||
const Callback2<const T &, unsigned> & dest = dests.operator[](i);
|
||||
dest(o, param);
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DispatcherCB<T>::Register(Callback2<const T &, unsigned> d, unsigned key)
|
||||
{
|
||||
int i = dests.Find(key);
|
||||
if(i>=0) return;
|
||||
dests.Add(key) = d;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DispatcherCB<T>::Unregister(unsigned key)
|
||||
{
|
||||
int i = dests.Find(key);
|
||||
if(i<0) return;
|
||||
dests.Remove(i);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
Callback2<const T &, unsigned> DispatcherCB<T>::GetDispatchable(unsigned key)
|
||||
{
|
||||
int i = dests.Find(key);
|
||||
if(i<0) return;
|
||||
Callback2<const T &, unsigned> & dest = dests.operator[](i);
|
||||
return dest;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
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<DispatcherCB<T> >()) continue;
|
||||
const DispatcherCB<T> & dest = a.Get<DispatcherCB<T> >();
|
||||
dest.DoDispatch(o, param);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DispatcherCBGen::Register(Callback2<const T &, unsigned> d, unsigned key)
|
||||
{
|
||||
for(int i = 0; i < dests.GetCount(); i++)
|
||||
{
|
||||
Any & a = dests.operator[](i);
|
||||
if(!a.Is<DispatcherCB<T> >()) continue;
|
||||
DispatcherCB<T> & dest = a.Get<DispatcherCB<T> >();
|
||||
dest.Register(d, key);
|
||||
return;
|
||||
}
|
||||
dests.Add().Create<DispatcherCB<T> >().Register(d,key);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void DispatcherCBGen::Unregister(unsigned key)
|
||||
{
|
||||
for(int i = 0; i < dests.GetCount(); i++)
|
||||
{
|
||||
Any & a = dests.operator[](i);
|
||||
if(!a.Is<DispatcherCB<T> >()) continue;
|
||||
DispatcherCB<T> & dest = a.Get<DispatcherCB<T> >();
|
||||
dest.Unregister(key);
|
||||
if(dest.GetDests().GetCount()<=0)
|
||||
dests.Remove(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
template<class T>
|
||||
DispatcherCB<T> & DispatcherCBGen::GetDispatcherCB()
|
||||
{
|
||||
for(int i = 0; i < dests.GetCount(); i++)
|
||||
{
|
||||
const Any & a = dests.operator[](i);
|
||||
if(!a.Is<DispatcherCB<T> >()) continue;
|
||||
DispatcherCB<T> & dest = a.Get<DispatcherCB<T> >();
|
||||
return dest;
|
||||
}
|
||||
return dests.Add().Create<DispatcherCB<T> >();
|
||||
}
|
||||
10
bazaar/Dispatcher/Dispatcher.upp
Normal file
10
bazaar/Dispatcher/Dispatcher.upp
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
description "a templateable object dispatcher class\377";
|
||||
|
||||
uses
|
||||
Core;
|
||||
|
||||
file
|
||||
Dispatcher.h,
|
||||
Dispatcher.hpp,
|
||||
Dispatcher.cpp;
|
||||
|
||||
4
bazaar/Dispatcher/init
Normal file
4
bazaar/Dispatcher/init
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#ifndef _Dispatcher_icpp_init_stub
|
||||
#define _Dispatcher_icpp_init_stub
|
||||
#include "Core/init"
|
||||
#endif
|
||||
39
bazaar/DispatcherTest/DispatcherTest.h
Normal file
39
bazaar/DispatcherTest/DispatcherTest.h
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#ifndef _DispatcherTest_DispatcherTest_h
|
||||
#define _DispatcherTest_DispatcherTest_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <DispatcherTest/DispatcherTest.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#include <Dispatcher/Dispatcher.hpp>
|
||||
|
||||
class MyPane
|
||||
: public WithPane<ParentCtrl>
|
||||
, public Dispatchable<Value>
|
||||
{
|
||||
public:
|
||||
typedef MyPane CLASSNAME;
|
||||
MyPane();
|
||||
|
||||
virtual void Dispatch(const Value & o, unsigned param);
|
||||
};
|
||||
|
||||
class DispatcherTest : public WithDispatcherTestLayout<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef DispatcherTest CLASSNAME;
|
||||
DispatcherTest();
|
||||
|
||||
void sliderCB();
|
||||
|
||||
Dispatcher<Value> disp;
|
||||
|
||||
Splitter splith1, splith2, splitv;
|
||||
MyPane pane1, pane2, pane3, pane4;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
12
bazaar/DispatcherTest/DispatcherTest.lay
Normal file
12
bazaar/DispatcherTest/DispatcherTest.lay
Normal file
|
|
@ -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
|
||||
|
||||
14
bazaar/DispatcherTest/DispatcherTest.upp
Normal file
14
bazaar/DispatcherTest/DispatcherTest.upp
Normal file
|
|
@ -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";
|
||||
|
||||
5
bazaar/DispatcherTest/init
Normal file
5
bazaar/DispatcherTest/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _DispatcherTest_icpp_init_stub
|
||||
#define _DispatcherTest_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Dispatcher/init"
|
||||
#endif
|
||||
60
bazaar/DispatcherTest/main.cpp
Normal file
60
bazaar/DispatcherTest/main.cpp
Normal file
|
|
@ -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();
|
||||
}
|
||||
|
||||
43
bazaar/DispatcherTest2/DispatcherTest.h
Normal file
43
bazaar/DispatcherTest2/DispatcherTest.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef _DispatcherTest_DispatcherTest_h
|
||||
#define _DispatcherTest_DispatcherTest_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <DispatcherTest2/DispatcherTest.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#include <Dispatcher/Dispatcher.hpp>
|
||||
|
||||
class MyPane
|
||||
: public WithPane<ParentCtrl>
|
||||
, public Dispatchable<Value>
|
||||
, public Dispatchable<int>
|
||||
{
|
||||
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<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef DispatcherTest CLASSNAME;
|
||||
DispatcherTest();
|
||||
|
||||
void sliderCB();
|
||||
void slideriCB();
|
||||
|
||||
Dispatcher<Value> disp;
|
||||
Dispatcher<int> dispi;
|
||||
|
||||
Splitter splith1, splith2, splitv;
|
||||
MyPane pane1, pane2, pane3, pane4;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
14
bazaar/DispatcherTest2/DispatcherTest.lay
Normal file
14
bazaar/DispatcherTest2/DispatcherTest.lay
Normal file
|
|
@ -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
|
||||
|
||||
14
bazaar/DispatcherTest2/DispatcherTest2.upp
Normal file
14
bazaar/DispatcherTest2/DispatcherTest2.upp
Normal file
|
|
@ -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";
|
||||
|
||||
5
bazaar/DispatcherTest2/init
Normal file
5
bazaar/DispatcherTest2/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _DispatcherTest_icpp_init_stub
|
||||
#define _DispatcherTest_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Dispatcher/init"
|
||||
#endif
|
||||
84
bazaar/DispatcherTest2/main.cpp
Normal file
84
bazaar/DispatcherTest2/main.cpp
Normal file
|
|
@ -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();
|
||||
}
|
||||
|
||||
61
bazaar/DispatcherTest3/DispatcherTest.h
Normal file
61
bazaar/DispatcherTest3/DispatcherTest.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#ifndef _DispatcherTest_DispatcherTest_h
|
||||
#define _DispatcherTest_DispatcherTest_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <DispatcherTest3/DispatcherTest.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#include <Dispatcher/Dispatcher.hpp>
|
||||
|
||||
template<class C, class T>
|
||||
class WithDispatch
|
||||
: public C
|
||||
, public Dispatchable<T>
|
||||
|
||||
{
|
||||
public:
|
||||
typedef WithDispatch<C, T> CLASSNAME;
|
||||
|
||||
virtual void Dispatch(const T & o, unsigned param)
|
||||
{
|
||||
C::SetData(o);
|
||||
}
|
||||
};
|
||||
|
||||
template<class T>
|
||||
class ProgressIndicatorWithDispatch
|
||||
: public ProgressIndicator
|
||||
, public Dispatchable<T>
|
||||
|
||||
{
|
||||
public:
|
||||
typedef ProgressIndicatorWithDispatch<T> CLASSNAME;
|
||||
|
||||
virtual void Dispatch(const T & o, unsigned param)
|
||||
{
|
||||
Set(o);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DispatcherTest : public WithDispatcherTestLayout<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef DispatcherTest CLASSNAME;
|
||||
DispatcherTest();
|
||||
|
||||
void sliderCB();
|
||||
void slideriCB();
|
||||
|
||||
Dispatcher<Value> disp;
|
||||
Dispatcher<int> dispi;
|
||||
|
||||
Array<Ctrl> ctrls;
|
||||
Splitter splitv1, splitv2, splith;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
5
bazaar/DispatcherTest3/DispatcherTest.lay
Normal file
5
bazaar/DispatcherTest3/DispatcherTest.lay
Normal file
|
|
@ -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
|
||||
|
||||
14
bazaar/DispatcherTest3/DispatcherTest3.upp
Normal file
14
bazaar/DispatcherTest3/DispatcherTest3.upp
Normal file
|
|
@ -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";
|
||||
|
||||
5
bazaar/DispatcherTest3/init
Normal file
5
bazaar/DispatcherTest3/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _DispatcherTest_icpp_init_stub
|
||||
#define _DispatcherTest_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Dispatcher/init"
|
||||
#endif
|
||||
63
bazaar/DispatcherTest3/main.cpp
Normal file
63
bazaar/DispatcherTest3/main.cpp
Normal file
|
|
@ -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<EditInt, Value> * pctrl = new WithDispatch<EditInt, Value>();
|
||||
ctrls.Add(pctrl);
|
||||
pctrl->MinMax(0, 100);
|
||||
disp.Register(*pctrl);
|
||||
splitv1 << *pctrl;
|
||||
}
|
||||
|
||||
splitv2.Vert();
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
ProgressIndicatorWithDispatch<Value> * pctrl = new ProgressIndicatorWithDispatch<Value>();
|
||||
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();
|
||||
}
|
||||
|
||||
66
bazaar/DispatcherTest4/DispatcherTest.h
Normal file
66
bazaar/DispatcherTest4/DispatcherTest.h
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
#ifndef _DispatcherTest_DispatcherTest_h
|
||||
#define _DispatcherTest_DispatcherTest_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <DispatcherTest4/DispatcherTest.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#include <Dispatcher/Dispatcher.hpp>
|
||||
|
||||
class MyEditInt
|
||||
: public EditInt
|
||||
, public Dispatchable<Value>
|
||||
, public Dispatchable<int>
|
||||
{
|
||||
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<Value>
|
||||
, public Dispatchable<int>
|
||||
{
|
||||
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<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef DispatcherTest CLASSNAME;
|
||||
DispatcherTest();
|
||||
|
||||
void sliderCB();
|
||||
void slideriCB();
|
||||
|
||||
Dispatcher<Value> disp;
|
||||
Dispatcher<int> dispi;
|
||||
|
||||
Array<Ctrl> ctrls;
|
||||
Splitter splitv1, splitv2, splith;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
7
bazaar/DispatcherTest4/DispatcherTest.lay
Normal file
7
bazaar/DispatcherTest4/DispatcherTest.lay
Normal file
|
|
@ -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
|
||||
|
||||
14
bazaar/DispatcherTest4/DispatcherTest4.upp
Normal file
14
bazaar/DispatcherTest4/DispatcherTest4.upp
Normal file
|
|
@ -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";
|
||||
|
||||
5
bazaar/DispatcherTest4/init
Normal file
5
bazaar/DispatcherTest4/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _DispatcherTest_icpp_init_stub
|
||||
#define _DispatcherTest_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Dispatcher/init"
|
||||
#endif
|
||||
72
bazaar/DispatcherTest4/main.cpp
Normal file
72
bazaar/DispatcherTest4/main.cpp
Normal file
|
|
@ -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();
|
||||
}
|
||||
|
||||
65
bazaar/DispatcherTest5/DispatcherTest.h
Normal file
65
bazaar/DispatcherTest5/DispatcherTest.h
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
#ifndef _DispatcherTest_DispatcherTest_h
|
||||
#define _DispatcherTest_DispatcherTest_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <DispatcherTest5/DispatcherTest.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#include <Dispatcher/Dispatcher.hpp>
|
||||
|
||||
class MyEditInt
|
||||
: public EditInt
|
||||
, public Dispatchable<Value>
|
||||
, public Dispatchable<int>
|
||||
{
|
||||
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<Value>
|
||||
, public Dispatchable<int>
|
||||
{
|
||||
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<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef DispatcherTest CLASSNAME;
|
||||
DispatcherTest();
|
||||
|
||||
void sliderCB();
|
||||
void slideriCB();
|
||||
|
||||
DispatcherGen disp;
|
||||
|
||||
Array<Ctrl> ctrls;
|
||||
Splitter splitv1, splitv2, splith;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
7
bazaar/DispatcherTest5/DispatcherTest.lay
Normal file
7
bazaar/DispatcherTest5/DispatcherTest.lay
Normal file
|
|
@ -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
|
||||
|
||||
14
bazaar/DispatcherTest5/DispatcherTest5.upp
Normal file
14
bazaar/DispatcherTest5/DispatcherTest5.upp
Normal file
|
|
@ -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";
|
||||
|
||||
5
bazaar/DispatcherTest5/init
Normal file
5
bazaar/DispatcherTest5/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _DispatcherTest_icpp_init_stub
|
||||
#define _DispatcherTest_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Dispatcher/init"
|
||||
#endif
|
||||
73
bazaar/DispatcherTest5/main.cpp
Normal file
73
bazaar/DispatcherTest5/main.cpp
Normal file
|
|
@ -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<Value>(*pctrl);
|
||||
disp.Register<int>(*pctrl);
|
||||
|
||||
//disp.Unregister<Value>(*pctrl);
|
||||
//disp.Unregister<int>(*pctrl);
|
||||
|
||||
splitv1 << *pctrl;
|
||||
}
|
||||
|
||||
splitv2.Vert();
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
MyProgressIndicator * pctrl = new MyProgressIndicator();
|
||||
ctrls.Add(pctrl);
|
||||
pctrl->SetTotal(100);
|
||||
disp.Register<Value>(*pctrl);
|
||||
disp.Register<int>(*pctrl);
|
||||
|
||||
//disp.Unregister<Value>(*pctrl);
|
||||
//disp.Unregister<int>(*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();
|
||||
}
|
||||
|
||||
63
bazaar/DispatcherTest6/DispatcherTest.h
Normal file
63
bazaar/DispatcherTest6/DispatcherTest.h
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef _DispatcherTest_DispatcherTest_h
|
||||
#define _DispatcherTest_DispatcherTest_h
|
||||
|
||||
#include <CtrlLib/CtrlLib.h>
|
||||
|
||||
using namespace Upp;
|
||||
|
||||
#define LAYOUTFILE <DispatcherTest6/DispatcherTest.lay>
|
||||
#include <CtrlCore/lay.h>
|
||||
|
||||
#include <Dispatcher/Dispatcher.hpp>
|
||||
|
||||
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<TopWindow>
|
||||
{
|
||||
public:
|
||||
typedef DispatcherTest CLASSNAME;
|
||||
DispatcherTest();
|
||||
~DispatcherTest();
|
||||
|
||||
void sliderCB();
|
||||
void slideriCB();
|
||||
virtual void Dispatch(const Value & o, unsigned param);
|
||||
|
||||
DispatcherCBGen disp;
|
||||
|
||||
Array<Ctrl> ctrls;
|
||||
Splitter splitv1, splitv2, splith;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
7
bazaar/DispatcherTest6/DispatcherTest.lay
Normal file
7
bazaar/DispatcherTest6/DispatcherTest.lay
Normal file
|
|
@ -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
|
||||
|
||||
14
bazaar/DispatcherTest6/DispatcherTest6.upp
Normal file
14
bazaar/DispatcherTest6/DispatcherTest6.upp
Normal file
|
|
@ -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";
|
||||
|
||||
5
bazaar/DispatcherTest6/init
Normal file
5
bazaar/DispatcherTest6/init
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#ifndef _DispatcherTest_icpp_init_stub
|
||||
#define _DispatcherTest_icpp_init_stub
|
||||
#include "CtrlLib/init"
|
||||
#include "Dispatcher/init"
|
||||
#endif
|
||||
87
bazaar/DispatcherTest6/main.cpp
Normal file
87
bazaar/DispatcherTest6/main.cpp
Normal file
|
|
@ -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<Value>(callback(pctrl, &MyEditInt::DispatchV), i);
|
||||
disp.Register<int>(callback(pctrl, &MyEditInt::DispatchI), 100+i);
|
||||
|
||||
//disp.Unregister<Value>(i);
|
||||
//disp.Unregister<int>(100+i);
|
||||
|
||||
splitv1 << *pctrl;
|
||||
}
|
||||
|
||||
splitv2.Vert();
|
||||
for(; i < 20; i++)
|
||||
{
|
||||
MyProgressIndicator * pctrl = new MyProgressIndicator();
|
||||
ctrls.Add(pctrl);
|
||||
pctrl->SetTotal(100);
|
||||
|
||||
disp.Register<Value>(callback(pctrl, &MyProgressIndicator::DispatchV), i);
|
||||
disp.Register<int>(callback(pctrl, &MyProgressIndicator::DispatchI), 100+i);
|
||||
|
||||
//disp.Unregister<Value>(i);
|
||||
//disp.Unregister<int>(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<Value>(i);
|
||||
disp.Unregister<int>(100+i);
|
||||
}
|
||||
}
|
||||
GUI_APP_MAIN
|
||||
{
|
||||
DispatcherTest().Run();
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue