mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-16 14:16:09 -06:00
Some Callback parameters now are Function<void ()>
git-svn-id: svn://ultimatepp.org/upp/trunk@9945 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
d720a38c65
commit
fa2f875bfc
5 changed files with 55 additions and 48 deletions
|
|
@ -99,24 +99,24 @@ enum {
|
|||
DELAY_MINIMAL = 0
|
||||
};
|
||||
|
||||
void SetTimeCallback(int delay_ms, Callback cb, void *id = NULL); // delay_ms < 0 -> periodic
|
||||
void SetTimeCallback(int delay_ms, Function<void ()> cb, void *id = NULL); // delay_ms < 0 -> periodic
|
||||
void KillTimeCallback(void *id);
|
||||
bool ExistsTimeCallback(void *id);
|
||||
dword GetTimeClick();
|
||||
|
||||
inline
|
||||
void PostCallback(Callback cb, void *id = NULL) { SetTimeCallback(1, cb, id); }
|
||||
void PostCallback(Function<void ()> cb, void *id = NULL) { SetTimeCallback(1, cb, id); }
|
||||
|
||||
class TimeCallback
|
||||
{
|
||||
public:
|
||||
~TimeCallback() { Kill(); (void)dummy; }
|
||||
~TimeCallback() { Kill(); (void)dummy; }
|
||||
|
||||
void Set(int delay, Callback cb) { UPP::SetTimeCallback(delay, cb, this); }
|
||||
void Post(Callback cb) { UPP::PostCallback(cb, this); }
|
||||
void Kill() { UPP::KillTimeCallback(this); }
|
||||
void KillSet(int delay, Callback cb) { Kill(); Set(delay, cb); }
|
||||
void KillPost(Callback cb) { Kill(); Post(cb); }
|
||||
void Set(int delay, Function<void ()> cb) { UPP::SetTimeCallback(delay, cb, this); }
|
||||
void Post(Function<void ()> cb) { UPP::PostCallback(cb, this); }
|
||||
void Kill() { UPP::KillTimeCallback(this); }
|
||||
void KillSet(int delay, Function<void ()> cb) { Kill(); Set(delay, cb); }
|
||||
void KillPost(Function<void ()> cb) { Kill(); Post(cb); }
|
||||
|
||||
private:
|
||||
byte dummy;
|
||||
|
|
@ -780,7 +780,7 @@ public:
|
|||
static void InstallStateHook(StateHook hook);
|
||||
static void DeinstallStateHook(StateHook hook);
|
||||
|
||||
static int RegisterSystemHotKey(dword key, Callback cb);
|
||||
static int RegisterSystemHotKey(dword key, Function<void ()> cb);
|
||||
static void UnregisterSystemHotKey(int id);
|
||||
|
||||
virtual bool Accept();
|
||||
|
|
@ -1140,15 +1140,14 @@ public:
|
|||
|
||||
Callback operator<<=(Callback action) { WhenAction = action; return action; }
|
||||
|
||||
Callback& operator<<(Callback action) { return WhenAction << action; }
|
||||
Callback& operator<<(Upp::Function<void ()> action) { return WhenAction << action; }
|
||||
Callback& operator<<(Function<void ()> action) { return WhenAction << action; }
|
||||
|
||||
void SetTimeCallback(int delay_ms, Callback cb, int id = 0);
|
||||
void SetTimeCallback(int delay_ms, Function<void ()> cb, int id = 0);
|
||||
void KillTimeCallback(int id = 0);
|
||||
void KillSetTimeCallback(int delay_ms, Callback cb, int id);
|
||||
void KillSetTimeCallback(int delay_ms, Function<void ()> cb, int id);
|
||||
bool ExistsTimeCallback(int id = 0) const;
|
||||
void PostCallback(Callback cb, int id = 0);
|
||||
void KillPostCallback(Callback cb, int id);
|
||||
void PostCallback(Function<void ()> cb, int id = 0);
|
||||
void KillPostCallback(Function<void ()> cb, int id);
|
||||
|
||||
enum { TIMEID_COUNT = 1 };
|
||||
|
||||
|
|
|
|||
|
|
@ -39,11 +39,11 @@ static void sTimeCallback(dword time, int delay, Callback cb, void *id) {
|
|||
LLOG("sTimeCalllback " << ne->time << " " << ne->delay << " " << ne->id);
|
||||
}
|
||||
|
||||
void SetTimeCallback(int delay_ms, Callback cb, void *id) {
|
||||
void SetTimeCallback(int delay_ms, Function<void ()> cb, void *id) {
|
||||
Mutex::Lock __(sTimerLock);
|
||||
ASSERT(abs(delay_ms) < 0x40000000);
|
||||
LLOG("SetTimeCallback " << delay_ms << " " << id);
|
||||
sTimeCallback(GetTickCount() + abs(delay_ms), delay_ms, cb, id);
|
||||
sTimeCallback(GetTickCount() + abs(delay_ms), delay_ms, Callback() << cb, id);
|
||||
}
|
||||
|
||||
void KillTimeCallbacks(void *id, void *idlim) {
|
||||
|
|
@ -145,7 +145,7 @@ void Ctrl::InitTimer()
|
|||
tevents();
|
||||
}
|
||||
|
||||
void Ctrl::SetTimeCallback(int delay_ms, Callback cb, int id) {
|
||||
void Ctrl::SetTimeCallback(int delay_ms, Function<void ()> cb, int id) {
|
||||
ASSERT(id >= 0 && (size_t)id < (int)sizeof(Ctrl));
|
||||
UPP::SetTimeCallback(delay_ms, cb, (byte *)this + id);
|
||||
}
|
||||
|
|
@ -155,18 +155,18 @@ void Ctrl::KillTimeCallback(int id) {
|
|||
UPP::KillTimeCallback((byte *)this + id);
|
||||
}
|
||||
|
||||
void Ctrl::KillSetTimeCallback(int delay_ms, Callback cb, int id)
|
||||
void Ctrl::KillSetTimeCallback(int delay_ms, Function<void ()> cb, int id)
|
||||
{
|
||||
KillTimeCallback(id);
|
||||
SetTimeCallback(delay_ms, cb, id);
|
||||
}
|
||||
|
||||
void Ctrl::PostCallback(Callback cb, int id)
|
||||
void Ctrl::PostCallback(Function<void ()> cb, int id)
|
||||
{
|
||||
SetTimeCallback(0, cb, id);
|
||||
}
|
||||
|
||||
void Ctrl::KillPostCallback(Callback cb, int id)
|
||||
void Ctrl::KillPostCallback(Function<void ()> cb, int id)
|
||||
{
|
||||
KillSetTimeCallback(0, cb, id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -716,7 +716,7 @@ bool PassWindowsKey(int wParam)
|
|||
|
||||
Vector<Callback> Ctrl::hotkey;
|
||||
|
||||
int Ctrl::RegisterSystemHotKey(dword key, Callback cb)
|
||||
int Ctrl::RegisterSystemHotKey(dword key, Function<void ()> cb)
|
||||
{
|
||||
ASSERT(key >= K_DELTA);
|
||||
int q = hotkey.GetCount();
|
||||
|
|
@ -725,7 +725,7 @@ int Ctrl::RegisterSystemHotKey(dword key, Callback cb)
|
|||
q = i;
|
||||
break;
|
||||
}
|
||||
hotkey.At(q) = cb;
|
||||
hotkey.At(q) = Callback() << cb;
|
||||
dword mod = 0;
|
||||
if(key & K_ALT)
|
||||
mod |= MOD_ALT;
|
||||
|
|
|
|||
|
|
@ -2224,33 +2224,18 @@ trl])&]
|
|||
[s2;b17;a17; Same as SetData(v).&]
|
||||
[s7;i1120;a17; [%-*C@3 v]-|New Value of Ctrl.&]
|
||||
[s7;i1120;a17; [*/ Return value]-|Reference to v.&]
|
||||
[s3;%- &]
|
||||
[s4;%- &]
|
||||
[s5;:Ctrl`:`:operator`<`<`=`(Callback`):%- [_^`:`:Callback^ Callback]_[* operator<<`=]([_^`:`:Callback^ C
|
||||
allback]_[*@3 action])&]
|
||||
[s2;b17;a17; Same as WhenAction `= action;&]
|
||||
[s7;i1120;a17; [%-*C@3 action]-|Callback that is invoked when user changes
|
||||
value of Ctrl.&]
|
||||
[s7;i1120;a17; [*/ Return value]-|The value of callback, so that it
|
||||
can be assigned to several Ctrls in one statement.&]
|
||||
[s3;%- &]
|
||||
[s4;%- &]
|
||||
[s5;:Ctrl`:`:operator`<`<`(Callback`):%- [_^`:`:Callback^ Callback][@(0.0.255) `&]_[* opera
|
||||
tor<<]([_^`:`:Callback^ Callback]_[*@3 action])&]
|
||||
[s5;:Upp`:`:Ctrl`:`:operator`<`<`(std`:`:function`<void`(`)`>`):%- [_^Upp`:`:Callback^ C
|
||||
allback][@(0.0.255) `&]_[* operator<<]([_^std`:`:function^ std`::function]<[@(0.0.255) voi
|
||||
d]_()>_[*@3 action])&]
|
||||
[s2;b17;a17; Same as WhenAction << action, second variant suitable
|
||||
for C`+`+11 lambdas.&]
|
||||
[s7;i1120;a17; [%-*C@3 action]-|Callback that is to be added to callbacks
|
||||
that are invoked when user changes value of Ctrl.&]
|
||||
[s7;i1120;a17; [*/ Return value]-|Reference to WhenAction.&]
|
||||
[s3;%- &]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Ctrl`:`:SetTimeCallback`(int`,Callback`,int`):%- [@(0.0.255) void]_[* SetTimeCallbac
|
||||
k]([@(0.0.255) int]_[*@3 delay`_ms], [_^`:`:Callback^ Callback]_[*@3 cb],
|
||||
[@(0.0.255) int]_[*@3 id]_`=_[@3 0])&]
|
||||
[s5;:Upp`:`:Ctrl`:`:operator`<`<`(Upp`:`:Function`<void`(`)`>`):%- [_^Upp`:`:Callback^ C
|
||||
allback][@(0.0.255) `&]_[* operator<<]([_^Upp`:`:Function^ Upp`::Function]<[@(0.0.255) voi
|
||||
d]_()>_[*@3 action])&]
|
||||
[s2; Same as WhenAction << action, can be used both with lambdas
|
||||
and Events (former Callbacks)..&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:Ctrl`:`:SetTimeCallback`(int`,Upp`:`:Function`<void`(`)`>`,int`):%- [@(0.0.255) v
|
||||
oid]_[* SetTimeCallback]([@(0.0.255) int]_[*@3 delay`_ms], [_^Upp`:`:Function^ Function]<
|
||||
[@(0.0.255) void]_()>_[*@3 cb], [@(0.0.255) int]_[*@3 id]_`=_[@3 0])&]
|
||||
[s2;b17;a17; Puts delayed callback to the timer queue. As an identifier
|
||||
of callback, which is void `* in timer queue, [* this] `+ [* id]
|
||||
is used. When Ctrl is destroyed, all callbacks with [* id] in range
|
||||
|
|
@ -2277,6 +2262,12 @@ nt]_[*@3 id]_`=_[@3 0])&]
|
|||
[s7;i1120;a17; [%-*C@3 id]-|Id of callback.&]
|
||||
[s3;%- &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:Ctrl`:`:KillSetTimeCallback`(int`,Upp`:`:Function`<void`(`)`>`,int`):%- [@(0.0.255) v
|
||||
oid]_[* KillSetTimeCallback]([@(0.0.255) int]_[*@3 delay`_ms], [_^Upp`:`:Function^ Functi
|
||||
on]<[@(0.0.255) void]_()>_[*@3 cb], [@(0.0.255) int]_[*@3 id])&]
|
||||
[s2; Removes callback with [%-*@3 id] and sets it again.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Ctrl`:`:ExistsTimeCallback`(int`)const:%- [@(0.0.255) bool]_[* ExistsTimeCallback]([@(0.0.255) i
|
||||
nt]_[*@3 id]_`=_[@3 0])_[@(0.0.255) const]&]
|
||||
[s2;b17;a17; Tests whether Ctrl has associated callback in timer
|
||||
|
|
@ -2285,6 +2276,20 @@ queue.&]
|
|||
[s7;i1120;a17; [*/ Return value]-|true when id is found in timer queue.&]
|
||||
[s3;%- &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:Ctrl`:`:PostCallback`(Upp`:`:Function`<void`(`)`>`,int`):%- [@(0.0.255) voi
|
||||
d]_[* PostCallback]([_^Upp`:`:Function^ Function]<[@(0.0.255) void]_()>_[*@3 cb],
|
||||
[@(0.0.255) int]_[*@3 id]_`=_[@3 0])&]
|
||||
[s2; Posts callback to be executed immediately (but in the main loop
|
||||
after all current GUI events).&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Upp`:`:Ctrl`:`:KillPostCallback`(Upp`:`:Function`<void`(`)`>`,int`):%- [@(0.0.255) v
|
||||
oid]_[* KillPostCallback]([_^Upp`:`:Function^ Function]<[@(0.0.255) void]_()>_[*@3 cb],
|
||||
[@(0.0.255) int]_[*@3 id])&]
|
||||
[s2; Similar to PostCallback, but removes callback(s) with the same
|
||||
id from the queue first.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
[s5;:Ctrl`:`:GetActiveCtrl`(`):%- [@(0.0.255) static] [_^`:`:Ctrl^ Ctrl]_`*[* GetActiveCtrl
|
||||
]()&]
|
||||
[s2;b17;a17; Returns pointer to active Ctrl. Active Ctrl is top`-level
|
||||
|
|
|
|||
|
|
@ -307,6 +307,9 @@ mage]([@(0.0.255) const]_[_^Image^ UPP`::Image][@(0.0.255) `&]_[*@3 img])&]
|
|||
[s4;%- &]
|
||||
[s5;:Bar`:`:Item`:`:Text`(const char`*`):%- [@(0.0.255) virtual] [_^Bar`:`:Item^ Item][@(0.0.255) `&
|
||||
]_[* Text]([@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 text])&]
|
||||
[s5;:Upp`:`:Bar`:`:Item`:`:Text`(const Upp`:`:String`&`):%- [@(0.0.255) virtual]
|
||||
[_^Upp`:`:Bar`:`:Item^ Item][@(0.0.255) `&]_[* Text]([@(0.0.255) const]_[_^Upp`:`:String^ S
|
||||
tring][@(0.0.255) `&]_[*@3 text])&]
|
||||
[s2; Sets the [%-*@3 text] of item.&]
|
||||
[s3; &]
|
||||
[s4;%- &]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue