Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
58 user(s) are online (41 user(s) are browsing Forums)

Members: 1
Guests: 57

MigthyMax, more...

Headlines

 
  Register To Post  

Reaction Checkbox and GA_Selected problem
Just can't stay away
Just can't stay away


See User information
I'm trying to get the status of a CheckboxObject, but it doesn't work.

Here is my code:

#include <proto/exec.h>
#include <proto/intuition.h>

#include <proto/window.h>
#include <proto/checkbox.h>
#include <proto/layout.h>

#include <classes/window.h>
#include <gadgets/checkbox.h>

#include <reaction/reaction_macros.h>

#include <stdio.h>
#include <stdlib.h>

struct Window *mainwin;
BOOL window_is_open FALSE;

Object *MainWinObj;
Object *MenusBoxObj;

void load_settings()
{
    
IIntuition->SetGadgetAttrs((struct Gadget *)MenusBoxObjmainwinNULL,
                                
GA_SelectedTRUE,
                                
TAG_END);
}

void save()
{
    
BOOL selected FALSE;
    
IIntuition->GetAttrs((struct Gadget *)MenusBoxObj,
                        
GA_Selected, &selected,
                        
TAG_DONE);

    
printf("selected = %d\n"selected);
}


void open_window()
{
    if(( 
MainWinObj WindowObject,
            
WA_ScreenTitle"Qt Prefs v0.1",
            
WA_Title"Qt Prefs",
            
WA_Width300,
            
WA_Height300,
            
WA_DepthGadgetTRUE,
            
WA_SizeGadgetTRUE,
            
WA_DragBarTRUE,
            
WA_CloseGadgetTRUE,
            
WA_ActivateTRUE,
            
WINDOW_PositionWPOS_CENTERSCREEN,

            
WINDOW_ParentGroupVLayoutObject,
                
LAYOUT_SpaceOuterTRUE,
                
LAYOUT_DeferLayoutTRUE,
                
                
LAYOUT_AddChildMenusBoxObj = (struct Gadget*)CheckBoxObject,
                    
//GA_ID, GID_MENUS_BOX,
                    
GA_RelVerifyTRUE,
                    
GA_Text"Native Menus",
                    
//GA_Selected, TRUE,
                    //CHECKBOX_TextPlace, PLACETEXT_RIGHT,
                
CheckBoxEnd,
                
CHILD_NominalSizeTRUE,
            
EndMember,
        
EndWindow))
    {
        if( 
mainwin = (struct Window *) RA_OpenWindow(MainWinObj) )
        {
            
window_is_open TRUE;
        }
    }
}

void close_window()
{
    if (
window_is_open)
    {
        
IIntuition->DisposeObjectMainWinObj );

        
window_is_open FALSE;
    }
    return;
}

void event_loop()
{
    
ULONG waitsignal;
    
BOOL done FALSE;

    
/* Obtain the window wait signal mask. */
    
IIntuition->GetAttrWINDOW_SigMaskMainWinObj, &signal );
            
    
/* Input Event Loop */
    
while( !done )
    {
        
wait IExec->Wait(signal);
        if(
wait signal)
        {
            
ULONG result;
            
WORD Code;

            while ((
result RA_HandleInput(MainWinObj, &Code)) != WMHI_LASTMSG && done != TRUE)
            {
                switch(
result WMHI_CLASSMASK)
                {
                    case 
WMHI_CLOSEWINDOW:
                        
done TRUE;
                        break;
                }
            }
        }
    }
    return;
}

int main()
{
    
open_window();
    
load_settings();
    
event_loop();
    
save();
    
close_window();
}


As you can see, I'm trying to set it to selected = TRUE in the load_settings() function, but it doesn't work. Also I am trying to get its status in the save() function at exit, but this doesn't work either (try checking the box and press close).

On the other hand, if I remove the comment before GA_Selected, TRUE in the window opening code, it "works".

What am I missing here??

Go to top
Re: Reaction Checkbox and GA_Selected problem
Just can't stay away
Just can't stay away


See User information
I suggest you use the define CHECKBOX_Checked instead of GA_Selected as it makes it clearer what you are doing.

Quote:

BOOL selected = FALSE;
IIntuition->GetAttrs((struct Gadget *)MenusBoxObj,
                        GA_Selected, &selected,
                        TAG_DONE);


This is wrong. The selected variable should be defined as a LONG or ULONG, or if code is AmigaOS 4 specific int32 or uint32. As a general rule the variables you use with GetAttr() should always be at least 32-bit. As it is you are just getting the high 16-bits of the result which is always 0 because the only return values are TRUE or FALSE (1 or 0).

Go to top
Re: Reaction Checkbox and GA_Selected problem
Just can't stay away
Just can't stay away


See User information
@salas00

Ahh, now I see my stupidity! I actually thought, that a BOOL was equal to an ULONG, but apparently it is typedef short. Dong!

..But just to justify my incompetence: In the autodocs under ICheckBox is says

Quote:
GA_Selected(BOOL)


And also CHECKBOX_Checked is not documented in the doc!


Go to top
Re: Reaction Checkbox and GA_Selected problem
Just popping in
Just popping in


See User information
The point is, that there is no really good documentation for beginners to AmigaOS programming. Else you would have seen how GetAttrs() is working internally. It is explained deep in the autodocs, that GetAttrs() gives back 32 bit values that you have to cast to the appropriate type afterwards (as documented in the autodocs regarding the specific attribute).

Time for a RKM overhaul...

Go to top
Re: Reaction Checkbox and GA_Selected problem
Home away from home
Home away from home


See User information
Quote:

whose wrote:
The point is, that there is no really good documentation for beginners to AmigaOS programming. Else you would have seen how GetAttrs() is working internally. It is explained deep in the autodocs, that GetAttrs() gives back 32 bit values that you have to cast to the appropriate type afterwards (as documented in the autodocs regarding the specific attribute).

Time for a RKM overhaul...


More documentation is certainly good but it's allready quite clear in the autodoc for IIntuition->GetAttr() that is takes a pointer to a uint32 / ULONG

Quote:


NAME
GetAttr -- Inquire the value of some attribute of an object. (V36)

SYNOPSIS
uint32 attr = GetAttr(uint32 attrId, Object *object, uint32 *storage);

FUNCTION
Inquires from the specified object the value of the specified attribute.

You always pass the address of a uint32 variable which will
receive the same value that would be passed to SetAttrs() in
the ti_Data portion of a TagItem element. See the documentation
for the class for exceptions to this general rule.



Even as a 'non beginner' I find it useful to scan the autodocs for functions I'm using pretty much every time I use them. It tends to flag up easy mistakes like this, and is better than relying on memory (or relying on *my* memory anyway!)

Go to top
Re: Reaction Checkbox and GA_Selected problem
Home away from home
Home away from home


See User information
Or check if there are some examples in the sdk.
But yes,updated docs for us noobs would be nice.

X5000
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-2023 The XOOPS Project