You can't, you'll have to do it manually. That's funny I'm currently investigating this for my CompareDir utility Once you built it, you only have to call its PM_OPEN method.
Not currently I'm investigating the (ugly IMHO) solution to trap IDCMP_MOUSEBUTTONS and then somehow determine which is the affected node... Not really get further but I have the impression that sometimes agao I read something somewhere in one autodoc that would have permitted me to do this (I just need to remember which one it was)...
Yeah I tried IDCMP_MOUSEBUTTONS too but I don't get any events from inside the window, only mouse clicks on the intuition parts (window edges, drag bar ect)
Tried to do this myself and have a subclass of listbrowser. Gave up in the end and had to write my own popup class as well.
When I tried I found that PM_Open cannot be called from any callback hooks including WA_MenuHook_- it just locks the OS. You have to use the IDCMP_Flags and trap the RMB.
Guessing here but the reason for the lockup is that PM_Open doesn't return until an item is selected but the OS is waiting for the hook to return before any further messages can be processed.
These "Intuition" hooks are called in the context of input.device, and while it is sitting there waiting for you to select a menu item, it cannot service any of the other intuition stuff, so the mouse pointer is not updated. The machine has not crashed, it is simply waiting for an event that can never be supplied. The use of hooks such as these requires extreme care. One solution I have adopted is to implement an IPC system that the hook signals the main task in order to use the popup menu. Handling the event is a bit hit and miss too, but I have it working.
Hmm forget that, today I get the events. Must have been very tired last night. Ohh well.
Anyway, the program menu is still dead of course, can I forward the event to input.device somehow? Rigo mentioned something like that, but I have no idea how to do that.
If that's possible I can check if the mouse pointer is above a listbrowser entry (after figuring out how ;), set it to selected and then open the main menu (or a context sensitive popup menu).
I can't get it to work though. I don't get any such messages in my RA_HandleInput() loop.
Even if I set: WA_IDCMP, IDCMP_MENUVERIFY in the Reaction WindowObject macro.
"If you want to catch the RMB simply set the IDCMP_MENUVERIFY's code field to MENUCANCEL, reply and then take this as an RMB down event."
What does "set the IDCMP_MENUVERIFY's code field" mean? (If it means the message then you don't get a message in a RA_HandleInput() loop, so how can you set something)
How do you reply a message in a RA_HandleInput() loop?
The prototype for a hook function looks like this: ULONG HookFunc(struct Hook *hook, APTR object, APTR message);
The IDCMPHook function in particular will be called with these parameters: uint32 Func(struct Hook *hook, APTR window, struct IntuiMessage *msg)
I must do IDOS->Reply(msg) as quickly as possible (or not?)
To prevent the menu from opening I must do msg->code = MENUCANCEL;
Example code:
struct Hook myIDCMPHook;
myIDCMPHook.mlnNode.mln_Succ = NULL;
myIDCMPHook.mlnNode.mLn_Pred = NULL;
myIDCMPHook.h_Entry = (HOOKFUNC)MyIDCMPHookFunc;
myIDCMPHook.h_SubEntry = NULL;
myIDCMPHook.h_Data = inst; // Just some data
// Part of WindowObject macro:
WINDOW_IDCMPHook, &myIDCMPHook,
WINDOW_IDCMPHookBits, IDCMP_MENUVERIFY,
ULONG MyIDCMPHookFunc(struct Hook *hook, APTR window, struc IntuiMessage *msg)
{
// ...
// Somehow find out which node the pointer was at, if any.
// Mark node as selected
// ...
if(hook->h_Data->allowpopup)
{
msg->code = MENUCANCEL;
IDOS->Reply(msg); // Might not be needed?
// .. open popup menu and do whatever ..
}
else
{
IDOS->Reply(msg); // Might not be needed?
}
return WHOOKRSLT_IGNORE;
}
Unanswered questions:
Can I use msg.IAddress to find out which list browser node that RMB was clicked on?
if not then:
Can I find out which node it was by using msg.MouseX, msg.MouseY ?
Edited by orgin on 2009/3/23 20:53:46 Edited by orgin on 2009/3/23 21:41:12
Ooh, nice to have a working example, as I hadn't actually got round to trying it myself yet!
I'm not sure how you'd find out which item was right-clicked on, you'd probably need to calculate it through the mouse position, or perhaps act the context menu on the last known selected entry, rather than the one it is currently over.