flickerstreak@193: -- flickerstreak@193: -- A secure proxy for ACTIONBAR_SHOW/HIDEGRID events flickerstreak@193: -- The events are transmitted via SetAttribute("state-showgrid",count) to frames registered with :AddFrame() flickerstreak@193: -- and can be handled by an appropriate SecureHandlerStateTemplate or SecureHandlerAttributeTemplate. flickerstreak@193: -- flickerstreak@193: flickerstreak@193: -- This library is internal to ReAction. If an addon author finds another use for this library, PM me on wowace flickerstreak@193: -- and I'll see about re-exporting it as a standalone library. flickerstreak@193: flickerstreak@193: local libName = "ReAction-LibShowActionGrid-1.0" flickerstreak@193: local minor = 1 flickerstreak@193: assert(LibStub, libName.." requires LibStub") flickerstreak@193: local lib = LibStub:NewLibrary(libName, minor) flickerstreak@193: if not lib then return end flickerstreak@193: flickerstreak@193: -- this being v1, no upgrade actions necessary flickerstreak@193: flickerstreak@193: local f = CreateFrame("CheckButton","LibShowActionGridProxyFrame-1.0-"..minor,UIParent,"ActionBarButtonTemplate, SecureHandlerAttributeTemplate") flickerstreak@193: flickerstreak@193: f:UnregisterAllEvents() flickerstreak@193: f:RegisterEvent("ACTIONBAR_SHOWGRID"); flickerstreak@193: f:RegisterEvent("ACTIONBAR_HIDEGRID"); flickerstreak@193: flickerstreak@193: f:SetScript("OnEnter",nil) flickerstreak@193: f:SetScript("OnLeave",nil) flickerstreak@193: f:SetScript("PostClick",nil) flickerstreak@193: f:SetScript("OnDragStart",nil) flickerstreak@193: f:SetScript("OnReceiveDrag",nil) flickerstreak@193: f:SetScript("OnUpdate",nil) flickerstreak@193: -- leave OnEvent flickerstreak@193: flickerstreak@193: f:SetAttribute("showgrid",10) -- set to >0 to prevent a call to HasAction(nil) that will cause a lua error flickerstreak@193: f:SetAttribute("action",0) flickerstreak@193: f:EnableMouse(false) flickerstreak@193: for _, child in ipairs({f:GetChildren()}) do flickerstreak@193: child:Hide() flickerstreak@193: end flickerstreak@193: for _, region in ipairs({f:GetRegions()}) do flickerstreak@193: region:Hide() flickerstreak@193: end flickerstreak@193: f:SetPoint("TOPLEFT") flickerstreak@193: f:Hide() flickerstreak@193: flickerstreak@193: f:Execute( flickerstreak@193: [[ flickerstreak@193: frames = newtable() flickerstreak@193: ]]) flickerstreak@193: flickerstreak@193: f:SetAttribute("_onattributechanged", flickerstreak@193: -- function _onattributechanged(self,name,value) flickerstreak@193: [[ flickerstreak@193: if name == "showgrid" then flickerstreak@193: for _, f in ipairs(frames) do flickerstreak@193: f:SetAttribute("state-showgrid",(tonumber(value) or 10) - 10) flickerstreak@193: end flickerstreak@193: end flickerstreak@193: ]]) flickerstreak@193: flickerstreak@193: lib.frame = f flickerstreak@193: lib.framelist = setmetatable({},{__mode="k"}) flickerstreak@193: flickerstreak@193: --- flickerstreak@193: --- library interface flickerstreak@193: --- flickerstreak@193: flickerstreak@193: function lib:AddFrame(frame) flickerstreak@193: self.framelist[frame] = true flickerstreak@193: self.frame:SetFrameRef("add-frame",frame) flickerstreak@193: self.frame:Execute( flickerstreak@193: [[ flickerstreak@193: local frame = self:GetFrameRef("add-frame") flickerstreak@193: for _, f in ipairs(frames) do flickerstreak@193: if f == frame then return end flickerstreak@193: end flickerstreak@193: table.insert(frames,frame) flickerstreak@193: ]]) flickerstreak@193: end flickerstreak@193: flickerstreak@193: function lib:RemoveFrame(frame) flickerstreak@193: self.frame:SetFrameRef("remove-frame",frame) flickerstreak@193: self.frame:Execute( flickerstreak@193: [[ flickerstreak@193: local frame = self:GetFrameRef("remove-frame") flickerstreak@193: for idx, f in ipairs(frames) do flickerstreak@193: if f == frame then flickerstreak@193: table.remove(frames,idx) flickerstreak@193: return flickerstreak@193: end flickerstreak@193: end flickerstreak@193: ]]) flickerstreak@193: self.framelist[frame] = nil flickerstreak@193: end flickerstreak@193: flickerstreak@193: