you guys... sheesh... that hooksecurefunction stuff does not make what you have put in the function capable of functioning in the secure environment. In other words just because you use hooksecure does not make it secure.
This is a chunk of secure code that runs the GrimUI context menu. It makes it so the context menu(a tray of buttons) can be shown/hidden in combat without taint.
Code:
local hotSpot = CreateFrame('Button', nil, UIParent, 'SecureHandlerClickTemplate')
hotSpot:SetHeight(16)
hotSpot:SetWidth(16)
hotSpot:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
hotSpot:SetFrameRef("contextMenu", contextMenu)
hotSpot:SetAttribute('_onclick', [[
local frame = self:GetFrameRef("contextMenu")
if button == 'LeftButton' then
if IsControlKeyDown() then
control:CallMethod("ToggleMiniMap")
else
if frame:IsVisible() then
frame:Hide(true)
else
frame:Show(true)
end
end
elseif button == 'RightButton' then
if IsControlKeyDown() then
control:CallMethod("ToggleInfoLog")
else
control:CallMethod("ToggleCombatLog")
end
end
]])
In order to get around taint issues you need to use code like this for any kind of show/hide or reposition of secured frames. A secured frame is any frame bliz has decided you could use an addon to move around during combat in a method that would allow you to "cheat" action bars fall into this catagory, the bosstargetframes, the focus frame, item buttons, the mounted control frame, some others to including the worldmap frame in a strange way... having to do with the questblobframe.
here is another example, this is the GrimUI config button. made secure so it could toggle the micro bar and options windows while in combat, note however that even though the options can be opened in combat 90% of them will not function. You pretty much can not move around any secure frame during combat no mater how you code it.
Code:
local configButton = CreateFrame('Button', configButton, UIParent, 'SecureHandlerClickTemplate')
configButton:SetHeight(30)
configButton:SetWidth(62)
configButton:RegisterForClicks('AnyUp')
configButton:SetNormalTexture([[Interface\AddOns\]] .. addonName .. [[\Media\ConfigButton]])
configButton:SetHighlightTexture([[Interface\AddOns\]] .. addonName .. [[\Media\ConfigButton]])
configButton:SetPoint('BOTTOMRIGHT', addon.skin, 'TOPRIGHT', -2, 0)
configButton:SetAttribute('_onclick', [[
if button == 'LeftButton' and not IsControlKeyDown() then
local microBar = self:GetFrameRef("microBar")
if microBar:IsVisible() then
microBar:Hide()
else
microBar:Show()
end
elseif button == 'RightButton' and not IsControlKeyDown() then
control:CallMethod("OpenConfig")
end
]])
function configButton:OpenConfig()
if addon.configPanel then
if addon.configPanel:IsVisible() then
InterfaceOptionsFrame:Hide()
else
addon.configPanel()
end
end
end
Also here is some good functions for show/hide/lock frames to prevent the reappearance of pesky frames.
Code:
--[[-----------------------------------------------------------------------------
DoNothing - A simple dummie/do nothing function
-------------------------------------------------------------------------------]]
local function DoNothing()
end
addon.DoNothing = DoNothing
--[[-----------------------------------------------------------------------------
HideTooltip - Hide GameTooltip (several frames use this)
-------------------------------------------------------------------------------]]
function addon:HideTooltip()
GameTooltip:Hide()
self.tooltip = nil
end
--[[-----------------------------------------------------------------------------
HideFrame - Hide a frame, prevents it from being reshown
-------------------------------------------------------------------------------]]
function addon:HideFrame(reference)
local frame = type(reference) == 'string' and _G[reference] or reference
if type(frame) ~= 'table' then return end
frame.Show = DoNothing
frame:Hide()
end
--[[-----------------------------------------------------------------------------
ShowFrame - Show a frame, undoing :HideFrame behavior
-------------------------------------------------------------------------------]]
function addon:ShowFrame(reference)
local frame = type(reference) == 'string' and _G[reference] or reference
if type(frame) ~= 'table' then return end
frame.Show = nil
frame:Show()
end
--[[-----------------------------------------------------------------------------
LockFrame - Lock a frame, prevents SetPoint and ClearAllPoints from working
-------------------------------------------------------------------------------]]
function addon:LockFrame(reference)
local frame = type(reference) == 'string' and _G[reference] or reference
if type(frame) ~= 'table' then return end
frame.SetPoint = DoNothing
frame.ClearAllPoints = DoNothing
end
--[[-----------------------------------------------------------------------------
UnlockFrame - Undo :LockFrame
-------------------------------------------------------------------------------]]
function addon:UnlockFrame(reference)
local frame = type(reference) == 'string' and _G[reference] or reference
if type(frame) ~= 'table' then return end
frame.SetPoint = nil
frame.ClearAllPoints = nil
end