Quantcast WoWInterface: SVN - HealMeNow - Blame - Rev 3 - /trunk/Libs/AceEvent-3.0/AceEvent-3.0.lua

WoWInterface SVN HealMeNow

[/] [trunk/] [Libs/] [AceEvent-3.0/] [AceEvent-3.0.lua] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 SeiferTim-84726
--[[ $Id: AceEvent-3.0.lua 60131 2008-02-03 13:03:56Z nevcairiel $ ]]
2 SeiferTim-84726
local MAJOR, MINOR = "AceEvent-3.0", 3
3 SeiferTim-84726
local AceEvent = LibStub:NewLibrary(MAJOR, MINOR)
4 SeiferTim-84726
 
5 SeiferTim-84726
if not AceEvent then return end
6 SeiferTim-84726
 
7 SeiferTim-84726
local CallbackHandler = LibStub:GetLibrary("CallbackHandler-1.0")
8 SeiferTim-84726
 
9 SeiferTim-84726
 
10 SeiferTim-84726
AceEvent.frame = AceEvent.frame or CreateFrame("Frame", "AceEvent30Frame") -- our event frame
11 SeiferTim-84726
AceEvent.embeds = AceEvent.embeds or {} -- what objects embed this lib
12 SeiferTim-84726
 
13 SeiferTim-84726
 
14 SeiferTim-84726
-- APIs and registry for blizzard events, using CallbackHandler lib
15 SeiferTim-84726
if not AceEvent.events then
16 SeiferTim-84726
        AceEvent.events = CallbackHandler:New(AceEvent,
17 SeiferTim-84726
                "RegisterEvent", "UnregisterEvent", "UnregisterAllEvents")
18 SeiferTim-84726
end
19 SeiferTim-84726
 
20 SeiferTim-84726
function AceEvent.events:OnUsed(target, eventname)
21 SeiferTim-84726
        AceEvent.frame:RegisterEvent(eventname)
22 SeiferTim-84726
end
23 SeiferTim-84726
 
24 SeiferTim-84726
function AceEvent.events:OnUnused(target, eventname)
25 SeiferTim-84726
        AceEvent.frame:UnregisterEvent(eventname)
26 SeiferTim-84726
end
27 SeiferTim-84726
 
28 SeiferTim-84726
 
29 SeiferTim-84726
-- APIs and registry for IPC messages, using CallbackHandler lib
30 SeiferTim-84726
if not AceEvent.messages then
31 SeiferTim-84726
        AceEvent.messages = CallbackHandler:New(AceEvent,
32 SeiferTim-84726
                "RegisterMessage", "UnregisterMessage", "UnregisterAllMessages"
33 SeiferTim-84726
        )
34 SeiferTim-84726
        AceEvent.SendMessage = AceEvent.messages.Fire
35 SeiferTim-84726
end
36 SeiferTim-84726
 
37 SeiferTim-84726
--- embedding and embed handling
38 SeiferTim-84726
local mixins = {
39 SeiferTim-84726
        "RegisterEvent", "UnregisterEvent",
40 SeiferTim-84726
        "RegisterMessage", "UnregisterMessage",
41 SeiferTim-84726
        "SendMessage",
42 SeiferTim-84726
        "UnregisterAllEvents", "UnregisterAllMessages",
43 SeiferTim-84726
}
44 SeiferTim-84726
 
45 SeiferTim-84726
-- AceEvent:Embed( target )
46 SeiferTim-84726
-- target (object) - target object to embed AceEvent in
47 SeiferTim-84726
--
48 SeiferTim-84726
-- Embeds AceEvent into the target object making the functions from the mixins list available on target:..
49 SeiferTim-84726
function AceEvent:Embed(target)
50 SeiferTim-84726
        for k, v in pairs(mixins) do
51 SeiferTim-84726
                target[v] = self[v]
52 SeiferTim-84726
        end
53 SeiferTim-84726
        self.embeds[target] = true
54 SeiferTim-84726
        return target
55 SeiferTim-84726
end
56 SeiferTim-84726
 
57 SeiferTim-84726
-- AceEvent:OnEmbedDisable( target )
58 SeiferTim-84726
-- target (object) - target object that is being disabled
59 SeiferTim-84726
--
60 SeiferTim-84726
-- Unregister all events messages etc when the target disables.
61 SeiferTim-84726
-- this method should be called by the target manually or by an addon framework
62 SeiferTim-84726
function AceEvent:OnEmbedDisable(target)
63 SeiferTim-84726
        target:UnregisterAllEvents()
64 SeiferTim-84726
        target:UnregisterAllMessages()
65 SeiferTim-84726
end
66 SeiferTim-84726
 
67 SeiferTim-84726
-- Script to fire blizzard events into the event listeners
68 SeiferTim-84726
local events = AceEvent.events
69 SeiferTim-84726
AceEvent.frame:SetScript("OnEvent", function(this, event, ...)
70 SeiferTim-84726
        events:Fire(event, ...)
71 SeiferTim-84726
end)
72 SeiferTim-84726
 
73 SeiferTim-84726
--- Finally: upgrade our old embeds
74 SeiferTim-84726
for target, v in pairs(AceEvent.embeds) do
75 SeiferTim-84726
        AceEvent:Embed(target)
76 SeiferTim-84726
end