SecureHandlerClickTemplate

From Wowpedia
Jump to: navigation, search

SecureHandlerClickTemplate and SecureHandlerDoubleClickTemplate are SecureHandlers which can perform protected actions in response to clicks, but only within a restricted environment that parses a string to perform protected actions using a limited subset of the API.

Handler

The templates each introduce a handler, _onclick or _ondoubleclick, with the following payload:

self 
table - Secure frame handle to the frame being clicked.
button 
string - Mouse button being clicked ("LeftButton", ...).
down 
boolean - True when the click is fired by a down-stroke; otherwise false.

Example

Suppose we wanted to make a button that would show/hide multiple protected frames, even while in combat.

local frame = CreateFrame("BUTTON", "MyClickButton", UIParent, "SecureHandlerClickTemplate")
frame:SetAttribute("_onclick", [=[
	local show, i, ref = button == "LeftButton", 2, self:GetFrameRef("frame1")
	while ref do
		if show then
			ref:Show();
		else 
			ref:Hide();
		end
		i, ref = i + 1, self:GetFrameRef("frame" .. i);
	end
]=]); 
frame:RegisterForClicks("AnyUp");
frame:SetFrameRef("frame1", PlayerFrame);
frame:SetFrameRef("frame2", TargetFrame);

The _onclick snippet would get executed, check whether the click was a left-click, and, based on that, iterate through all "frameX" frame references on the button and show/hide them.