104,541pages on
this wiki
Add New Page
Add New Page Talk0

SecureHandlerClickTemplate is one of the SecureHandler templates introduced in Patch 3.0. Those templates exist in order to allow addon code to execute within a restricted environment, where it may perform protected actions but has access only to a limited subset of the API. SecureHandlerClickTemplate executes snippets in response to OnClick widget handler invocations.

Snippets Edit

The handler executes the following snippets in a restricted environment:

_onclick (self, button, down) 
The snippet is executed when button is clicked.
Secure frame handle to the frame being clicked.
String - mouse button being clicked ("LeftButton", ...)
Boolean (1/nil) - If true-equivalent, the click is fired by a down-stroke, i.e. the button being pushed down. If false-equivalent, the click is fired by an up-stroke, i.e. the button being released.

Example Edit

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);
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.

Also on Fandom

Random Wiki