[solved] How to retrieve the Gadget ID in WMHI_MOUSEBUTTONS or in a WINDOW_AppMsgHook hook ?

6 posts / 0 new
Last post
zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
[solved] How to retrieve the Gadget ID in WMHI_MOUSEBUTTONS or in a WINDOW_AppMsgHook hook ?

Hi,
I would like to retrieve the GadgetID of the gadget where I use Right Mouse Button or where I drag an external object on it. Is it possible ?

For now, it works for me in Left mouse button release.

  1. case WMHI_GADGETUP:
  2.  
  3. if ( ((result & WMHI_GADGETMASK) - LAST_NUM) < nb_program)
  4. printf("GadgetID = %d \n",(result & WMHI_GADGETMASK) - LAST_NUM) ;

but no in "case WMHI_MOUSEBUTTONS:" or in WINDOW_AppMsgHook hook.

For these 2 cases, I have to calculate the coordinate of the targeted object with Window->MouseX or msg->am_MouseX and to determine the gadgetID on my window by calculating the width of the existing gadgets... Not very nice.

Is it a easier solution ?

Thank you by advance
Guillaume

jabirulo
jabirulo's picture
Offline
Last seen: 3 weeks 1 day ago
Joined: 2013-05-30 00:53
Hi, can you elaborate it a

Hi, can you elaborate it a bit further please?
You want that when user clicks RMB over some gadget to act/show something?
Why not with LMB?

TIA

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Hi Javier, Thanks for your

Hi Javier,
Thanks for your reply.

yes, i want that when I RMB on a gadget or when I drag an element on a gadget to be able to retrieve the gadget ID of this gadget.

It works well by using LMB thanks to (results & WMHI_GADGETMASK) but not when with right mouse button or drag'n drop (appmsghook)

Thank you.

broadblues
broadblues's picture
Offline
Last seen: 4 years 9 months ago
Joined: 2012-05-02 21:48
For drag and drop I think the

For drag and drop I think the only way is to take the coordinates of the from the appmessage and compare them with your gadgets. You *might* be able to send a GM_HITTEST to each gadget you are interested in, I say *might* because I'm not sure if it's legal for an application to send this message or onlt intuition.

For captureing RMB events it's more complex, as by default button.gadgets do not monitor the RMB, so you might need to create a subclass, even then the gadget wil not recive input till active so you may need to monitor the mouse position and activate the gadgets hovered over via WM_ACTIVATEGADGET

However be aware that this will messup menu access so you will be to process the RMB click appropriatly, basically you need to do some studying of the gadgets section of the RKMs (on the wiki.amigaos.net)and the gadget_gc autodoc

*But* if you are intended to bring up a popup menu then you might take look at the new menuclass (not sure if you have access to latest SDK or not)

jabirulo
jabirulo's picture
Offline
Last seen: 3 weeks 1 day ago
Joined: 2013-05-30 00:53
Maybe it's sort of a hack but

Maybe it's sort of a hack but you can use this code to check on RMB click and then perform/call/simulate a LMB click.

  1. /*
  2. gcc -N -Wall TestMouse.c -o TestMouse
  3. quit
  4.  
  5. BIT QUALIFIER KEY/BUTTON
  6.  0 IEQUALIFIER_LSHIFT Left Shift
  7.  1 IEQUALIFIER_RSHIFT Right Shift
  8.  2 IEQUALIFIER_CAPSLOCK Caps Lock
  9.  3 IEQUALIFIER_CONTROL Control
  10.  4 IEQUALIFIER_LALT Left Alt
  11.  5 IEQUALIFIER_RALT Right Alt
  12.  6 IEQUALIFIER_LCOMMAND Left-Amiga
  13.  7 IEQUALIFIER_RCOMMAND Right-Amiga
  14. 12 IEQUALIFIER_MIDBUTTON Middle Mouse
  15. 13 IEQUALIFIER_RBUTTON Right Mouse
  16. 14 IEQUALIFIER_LEFTBUTTON Left Mouse
  17. */
  18.  
  19. #include <proto/exec.h>
  20. #include <proto/dos.h>
  21. #include <proto/input.h>
  22.  
  23. int main(void)
  24. {
  25. struct IOStdReq *InputIO; // I/O request block
  26. uint16 Quals; // qualifiers
  27.  
  28. struct MsgPort *mp;
  29. mp = IExec->AllocSysObject(ASOT_PORT, NULL);
  30. InputIO = IExec->AllocSysObjectTags(ASOT_IOREQUEST, ASOIOR_ReplyPort, mp,
  31. ASOIOR_Size, sizeof(*InputIO),
  32. TAG_END);
  33.  
  34. if( !IExec->OpenDevice("input.device", 0, (struct IORequest *)InputIO, 0) )
  35. {
  36. // Set input device base address in InputBase
  37. struct Library *InputBase = (struct Library *)InputIO->io_Device;
  38. struct InputIFace *IInput = (struct InputIFace *)IExec->GetInterface(InputBase, "main", 1, NULL);
  39.  
  40. // Call the function
  41. while( !(Quals = IInput->PeekQualifier() & IEQUALIFIER_RBUTTON) );
  42. IDOS->Printf("InputQuals=%lx\n",Quals);
  43.  
  44. // InputIO->io_Device = NULL;
  45. IExec->DropInterface( (struct Interface *)IInput );
  46. IExec->CloseDevice( (struct IORequest *)InputIO );
  47. IExec->FreeSysObject(ASOT_IOREQUEST, InputIO);
  48. IExec->FreeSysObject(ASOT_PORT, mp);
  49. }
  50.  
  51. return 0;
  52. }

Or use popupmenu/new_menu class as broadblues suggested if you want to show just a contextmenu under gadgets.

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

zzd10h
zzd10h's picture
Offline
Last seen: 7 years 3 weeks ago
Joined: 2012-08-24 20:56
Thank you Broadblues and

Thank you Broadblues and Jabirulo,
therefore no easy way to retrieve the gadget ID in these cases.

I still calculate the targeted gadget by calculating the position with MouseX and am_MouseX. It works well, I wondered if there is not an easier way. At least it works !

Thank you

Log in or register to post comments