view classes/GridProxy.lua @ 148:de1da46dadb3

moved unitwatch handling into bar
author Flick <flickerstreak@gmail.com>
date Fri, 08 May 2009 00:06:53 +0000
parents 729232aeeb5e
children
line wrap: on
line source
--
-- A hack for a ShowGrid secure handler, using a bastardized Blizzard ActionBarButton.
--
local gridProxy = { }
ReAction.gridProxy = gridProxy

local f = CreateFrame("CheckButton","ReActionShowGridProxy",UIParent,"ActionBarButtonTemplate, SecureHandlerAttributeTemplate")
  -- SecureHandlerAttributeTemplate overwrites the onAttributeChanged handler, as it's last in the list
f:UnregisterAllEvents()
f:SetScript("OnEnter",nil)
f:SetScript("OnLeave",nil)
f:SetScript("PostClick",nil)
f:SetScript("OnDragStart",nil)
f:SetScript("OnReceiveDrag",nil)
f:SetScript("OnUpdate",nil)
f:SetAttribute("showgrid",0)
f:SetAttribute("action",0)
f.action = 0
f:EnableMouse(false)
for _, child in ipairs({f:GetChildren()}) do
  child:Hide()
end
for _, region in ipairs({f:GetRegions()}) do
  region:Hide()
end
f:SetPoint("TOPLEFT")
f:Hide()

-- The existing onEvent handler will set the 'showgrid' attribute
-- on this frame. Re-register for those events, but don't touch the
-- onEvent handler, to keep it secure.
f:RegisterEvent("ACTIONBAR_SHOWGRID");
f:RegisterEvent("ACTIONBAR_HIDEGRID");

f:Execute(
  [[
    frames = newtable()
  ]])

-- shuttle 'showgrid' to the registered frames via state-showgrid attribute
f:SetAttribute("_onattributechanged", 
  -- function _onattributechanged(self,name,value)
  [[
    if name == "showgrid" then
      for _, f in pairs(frames) do
        f:SetAttribute("state-showgrid",value)
      end
    end
  ]])

function gridProxy:AddFrame(frame)
  f:SetFrameRef("add",frame)
  f:SetAttribute("frame-add-id",frame:GetName())
  f:Execute(
    [[
      frames[self:GetAttribute("frame-add-id")] = self:GetFrameRef("add")
    ]])
end

function gridProxy:RemoveFrame(frame)
  f:SetAttribute("frame-remove-id",frame:GetName())
  f:Execute(
    [[
      frames[self:GetAttribute("frame-remove-id")] = nil
    ]])
end