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 *)MenusBoxObj, mainwin, NULL,
GA_Selected, TRUE,
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_Width, 300,
WA_Height, 300,
WA_DepthGadget, TRUE,
WA_SizeGadget, TRUE,
WA_DragBar, TRUE,
WA_CloseGadget, TRUE,
WA_Activate, TRUE,
WINDOW_Position, WPOS_CENTERSCREEN,
WINDOW_ParentGroup, VLayoutObject,
LAYOUT_SpaceOuter, TRUE,
LAYOUT_DeferLayout, TRUE,
LAYOUT_AddChild, MenusBoxObj = (struct Gadget*)CheckBoxObject,
//GA_ID, GID_MENUS_BOX,
GA_RelVerify, TRUE,
GA_Text, "Native Menus",
//GA_Selected, TRUE,
//CHECKBOX_TextPlace, PLACETEXT_RIGHT,
CheckBoxEnd,
CHILD_NominalSize, TRUE,
EndMember,
EndWindow))
{
if( mainwin = (struct Window *) RA_OpenWindow(MainWinObj) )
{
window_is_open = TRUE;
}
}
}
void close_window()
{
if (window_is_open)
{
IIntuition->DisposeObject( MainWinObj );
window_is_open = FALSE;
}
return;
}
void event_loop()
{
ULONG wait, signal;
BOOL done = FALSE;
/* Obtain the window wait signal mask. */
IIntuition->GetAttr( WINDOW_SigMask, MainWinObj, &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??