annotate lib/LibShowActionGrid-1.0/LibShowActionGrid-1.0.lua @ 308:08bd2dec1f01 stable tip

Merge 1.1 beta 13 to stable
author Flick
date Wed, 14 Nov 2012 20:32:03 -0800
parents 576c50e51fc5
children
rev   line source
flickerstreak@193 1 --
flickerstreak@193 2 -- A secure proxy for ACTIONBAR_SHOW/HIDEGRID events
flickerstreak@193 3 -- The events are transmitted via SetAttribute("state-showgrid",count) to frames registered with :AddFrame()
flickerstreak@193 4 -- and can be handled by an appropriate SecureHandlerStateTemplate or SecureHandlerAttributeTemplate.
flickerstreak@193 5 --
flickerstreak@193 6
flickerstreak@193 7 -- This library is internal to ReAction. If an addon author finds another use for this library, PM me on wowace
flickerstreak@193 8 -- and I'll see about re-exporting it as a standalone library.
flickerstreak@193 9
flickerstreak@193 10 local libName = "ReAction-LibShowActionGrid-1.0"
flickerstreak@193 11 local minor = 1
flickerstreak@193 12 assert(LibStub, libName.." requires LibStub")
flickerstreak@193 13 local lib = LibStub:NewLibrary(libName, minor)
flickerstreak@193 14 if not lib then return end
flickerstreak@193 15
flickerstreak@193 16 -- this being v1, no upgrade actions necessary
flickerstreak@193 17
flickerstreak@193 18 local f = CreateFrame("CheckButton","LibShowActionGridProxyFrame-1.0-"..minor,UIParent,"ActionBarButtonTemplate, SecureHandlerAttributeTemplate")
flickerstreak@193 19
flickerstreak@193 20 f:UnregisterAllEvents()
flickerstreak@193 21 f:RegisterEvent("ACTIONBAR_SHOWGRID");
flickerstreak@193 22 f:RegisterEvent("ACTIONBAR_HIDEGRID");
flickerstreak@193 23
flickerstreak@193 24 f:SetScript("OnEnter",nil)
flickerstreak@193 25 f:SetScript("OnLeave",nil)
flickerstreak@193 26 f:SetScript("PostClick",nil)
flickerstreak@193 27 f:SetScript("OnDragStart",nil)
flickerstreak@193 28 f:SetScript("OnReceiveDrag",nil)
flickerstreak@193 29 f:SetScript("OnUpdate",nil)
flickerstreak@193 30 -- leave OnEvent
flickerstreak@193 31
flickerstreak@193 32 f:SetAttribute("showgrid",10) -- set to >0 to prevent a call to HasAction(nil) that will cause a lua error
flickerstreak@193 33 f:SetAttribute("action",0)
flickerstreak@193 34 f:EnableMouse(false)
flickerstreak@193 35 for _, child in ipairs({f:GetChildren()}) do
flickerstreak@193 36 child:Hide()
flickerstreak@193 37 end
flickerstreak@193 38 for _, region in ipairs({f:GetRegions()}) do
flickerstreak@193 39 region:Hide()
flickerstreak@193 40 end
flickerstreak@193 41 f:SetPoint("TOPLEFT")
flickerstreak@193 42 f:Hide()
flickerstreak@193 43
flickerstreak@193 44 f:Execute(
flickerstreak@193 45 [[
flickerstreak@193 46 frames = newtable()
flickerstreak@193 47 ]])
flickerstreak@193 48
flickerstreak@193 49 f:SetAttribute("_onattributechanged",
flickerstreak@193 50 -- function _onattributechanged(self,name,value)
flickerstreak@193 51 [[
flickerstreak@193 52 if name == "showgrid" then
flickerstreak@193 53 for _, f in ipairs(frames) do
flickerstreak@193 54 f:SetAttribute("state-showgrid",(tonumber(value) or 10) - 10)
flickerstreak@193 55 end
flickerstreak@193 56 end
flickerstreak@193 57 ]])
flickerstreak@193 58
flickerstreak@193 59 lib.frame = f
flickerstreak@193 60 lib.framelist = setmetatable({},{__mode="k"})
flickerstreak@193 61
flickerstreak@193 62 ---
flickerstreak@193 63 --- library interface
flickerstreak@193 64 ---
flickerstreak@193 65
flickerstreak@193 66 function lib:AddFrame(frame)
flickerstreak@193 67 self.framelist[frame] = true
flickerstreak@193 68 self.frame:SetFrameRef("add-frame",frame)
flickerstreak@193 69 self.frame:Execute(
flickerstreak@193 70 [[
flickerstreak@193 71 local frame = self:GetFrameRef("add-frame")
flickerstreak@193 72 for _, f in ipairs(frames) do
flickerstreak@193 73 if f == frame then return end
flickerstreak@193 74 end
flickerstreak@193 75 table.insert(frames,frame)
flickerstreak@193 76 ]])
flickerstreak@193 77 end
flickerstreak@193 78
flickerstreak@193 79 function lib:RemoveFrame(frame)
flickerstreak@193 80 self.frame:SetFrameRef("remove-frame",frame)
flickerstreak@193 81 self.frame:Execute(
flickerstreak@193 82 [[
flickerstreak@193 83 local frame = self:GetFrameRef("remove-frame")
flickerstreak@193 84 for idx, f in ipairs(frames) do
flickerstreak@193 85 if f == frame then
flickerstreak@193 86 table.remove(frames,idx)
flickerstreak@193 87 return
flickerstreak@193 88 end
flickerstreak@193 89 end
flickerstreak@193 90 ]])
flickerstreak@193 91 self.framelist[frame] = nil
flickerstreak@193 92 end
flickerstreak@193 93
flickerstreak@193 94