Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
12 user(s) are online (8 user(s) are browsing Forums)

Members: 1
Guests: 11

MartinW, more...

Support us!

Headlines

 
  Register To Post  

speedbar.gadget and 16bit IDs
Home away from home
Home away from home


See User information
Discovered something interesting today:
In all my previous Amiga-specific coding (main loop, message handling, switch-case on gadget IDs), I’ve always used int32 code, and it worked fine for everything — until now.

While experimenting with speedbar.gadget, I noticed that code wasn’t matching any of my expected IDs. Instead of getting 1, 2, 3, 4, 5, 6 ., I got:

unknown button ID65536
unknown button ID
131072
unknown button ID
196608
unknown button ID
262144
unknown button ID
32760
unknown button ID
393216


Turns out that SpeedBar.gadget encodes the button ID in the upper 16 bits of "int32 code", while WMHI_GADGETMASK (0xFFFF) filters the lower 16 bits of result. So unless you shift code >> 16, switch will never match.

For quick fix i manually shift the ID out of code:

if ((result WMHI_GADGETMASK) == GID_SPEEDBAR)
{
    
uint32 buttonID code >> 16;
    switch (
buttonID)
    {
        case 
SBID_NEW:   // etc.
        
.....



But what i am wondering about now: should I always keep code value as int32 and just shift when needed (seems rare, and speedbar.gadget only specific), or should I make "code" as uint16 from the start to avoid this kind of surprise and hope int16 will bring no other issues instead ?:)

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: speedbar.gadget and 16bit IDs
Just can't stay away
Just can't stay away


See User information
Hi, WM_HANDLEINPUT ('code' variable)? IIRC it should be uint16:

ULONG HandleMainWindowIDCMP(const BOOL AllowIconify)
{
 
ULONG result,done=FALSE;
 
uint16 code;
 
Upload=FALSE;

 while (
MainWin_Object &&
    (
result=IDoMethod(MainWin_ObjectWM_HANDLEINPUT, &code))!=WMHI_LASTMSG)
 {
  switch (
result WMHI_CLASSMASK)
  {
   case 
WMHI_CLOSEWINDOW:
    
done=TRUE;
    break;
   case 
WMHI_GADGETUP:
    switch (
result WMHI_GADGETMASK)
        {
     case 
MG_SpeedBar:
            if (!
HandleSpeedBar(code)) done=TRUE;
        break;
...


then look in https://github.com/OS4Welt/AmiFTP/blob/master/src/amiftp/SpeedBar.c
above snipped is from amiftp too (https://github.com/OS4Welt/AmiFTP/blob ... /amiftp/MainWindow.c#L115)

https://wiki.amigaos.net/amiga/autodocs/window_cl.doc.txt

Go to top
Re: speedbar.gadget and 16bit IDs
Just can't stay away
Just can't stay away


See User information
@kas1e

That's because you are defining code wrong. It should be a 16-bit variable (e.g. uint16/int16) not an int32.

Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project