what i am trying to do is to hook to SecureActionButton_OnClick to track action usage, the idea is to process whenever the user clicking on action bar's button. However i've got some issues:
1. if i've no bar addons loaded - my hooksecurefunc(SecureActionButton_OnClick, myfunc) works just fine, but if i've (ie) bartender4 addon loaded - myfunc never gets control. i thought any frame which inherits SecureTemplate should work thru SecureActionButton_OnClick, why?
2. hooksecurefunc(SecureActionButton_OnClick, myfunc) works (w/o addons) only if i "click" on the button via keybinding but doesnt work if i click w/ mouse, why ?
what would be the best way to call custom function when player trying to do the action (not actual cast because it can fail due distance/etc...)?
It's a bit murky, but check out SecureTemplates.xml. SecureActionButton_OnClick is assigned to the "onClick" handler of each SecureActionButtonTemplate instance at the time that the frame is created. Now, that bit of code is Blizzard's XML pseudo-code, not true Lua, so we can't be sure whether it does a global lookup each time OnClick is invoked, or if it does an assignment of the function reference once at load time for each frame (heck it might do it once at startup for the base template and everything just inherits the assigned reference). If the latter, then calling hooksecurefunc() will only install your hooked wrapper on frames which are created after your hook has taken effect. I'm surprised hooking SecureActionButton_OnClick works at all on Blizzard's default frames, frankly.
If you want to hook other addons' SecureActionButtons, then make sure that (a) your addon is loaded first in the list, e.g. by prefixing its name with '!' or '+', and (b) you call hooksecurefunc() in the main chunk, not in an initialization event handler.
As for why it would work with keybindings but not mouse clicks, that's a bit of a mystery. We don't have any visibility into how Blizzard's keybinding API actually maps key presses to clicks.
You may need to dig into the dark realm of COMBAT_LOG_EVENT_UNFILTERED to get what you want. It does report instances of attempted ability casts which failed including reason for failure.
thanks for respond,
COMBAT_LOG_EVENT_UNFILTERED wont work for some failed situation like, caster is not in range, facing away from target etc... thanks for idea to load addon first - gotta try it out.
however, i still not get why my hook is not working w/ bartender4..
BT4 is using libaction library which simple creates frame buttons inherited from SecureUnitButtonTemplate. SecureUnitButtonTemplate is using SecureActionButton_OnClick in SecureTemplates.lua. stock Blizzard UI does pretty much same and my hook works w/ Blizzard UI and not with BT4... duh...