Thread Tools Display Modes
05/27/14, 03:59 PM   #1
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Question Adding multiple handlers

If a control has a handler already set, for example for "OnMouseEnter", you can add your own handler like this:

local oldHandler = control:GetHandler(event)
control:SetHandler(event, function(...) oldHandler(...) myhandler(...) end)

Unfortunately, this doesn't work when the oldHandler function uses private functions. As the function is now called from the addon environment, this leads to an exception for trying to call a private function.

Any ideas how to circumvent this problem?

I tried assigning the old handler to a global variable and use "CallSecureProtected("myglobalvariablename", ...), but this didn't work either, it's not called at all.
  Reply With Quote
05/27/14, 04:13 PM   #2
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
You could try using ZO_PreHookHandler() that I THINK exists because I THINK I remember hearing someone talking about it in IRC or some other thread...

But I believe that would be a 100% safe way to do what you're wanting UNLESS you absolutely need a post-hook instead...

In a case like that, I'd still prehook and then in the called function, do a zo_callLater(myFunction(myArgs), 25) to make the function fire almost instantly after the handle function. Very hacky, but it works.
  Reply With Quote
05/27/14, 04:34 PM   #3
Vuelhering
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 169
haha, yeah... that's just aching for a race condition on a crappy computer.
  Reply With Quote
05/27/14, 07:13 PM   #4
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
Originally Posted by Vuelhering View Post
haha, yeah... that's just aching for a race condition on a crappy computer.
You're not wrong, but if a mouse-over event handler takes more than 25ms to terminate, there's a whole host of other problems.
  Reply With Quote
05/28/14, 01:08 PM   #5
Iyanga
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 183
Originally Posted by ingeniousclown View Post
You could try using ZO_PreHookHandler() that I THINK exists because I THINK I remember hearing someone talking about it in IRC or some other thread...
Yeah, that's what I thought, too, couldn't find the thread yesterday though. Guess was blind, I wrote in that thread, too.

ZO_PreHookHandler() works like a charm for my case, no problem with internals overriding my settings afterwards.
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Adding multiple handlers

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off