PDA

View Full Version : Radio buttons in Carcon C with XCode, simple question




GothicChess.Com
Jun 22, 2007, 05:56 PM
I'm just trying to turn off one radio button and turn the other one on when a hit on it occurs. I am NOT using a pre-defined cluster from Interface Builder, just 2 separate radio buttons.

Is there any reason why I can see my dialog box (indicating I made it into the code block) yet the controls do not reflect the fact I hit them?

I must be missing something so elementary it almost defies explanation :)



#define kFirstRadioSig 'frad'
#define KSecondRadioSig 'srad'

#define kFirstRadio_ID 63
#define KSecondRadio_ID 64

DialogRef alert;
DialogItemIndex userItemHit;

ControlID radio_button_control_ID;
ControlRef radio_button_control_ref;

GetEventParameter(your_event, kEventParamDirectObject, typeHICommand, NULL, sizeof(HICommand), NULL, &the_command);

switch(the_command.commandID)
{
case KSecondRadioSig:
/**********************************/
/* 1st radio button turns off ... */
/**********************************/

radio_button_control_ID.signature = kFirstRadioSig;
radio_button_control_ID.id = kFirstRadio_ID;
GetControlByID(g_drawer_window_with_buttons, &radio_button_control_ID, &radio_button_control_ref);
SetControlValue(radio_button_control_ref, 0);

/**********************************/
/* 2nd radio button turns on ... */
/**********************************/

radio_button_control_ID.signature = KSecondRadioSig;
radio_button_control_ID.id = KSecondRadio_ID;
GetControlByID(g_drawer_window_with_buttons, &radio_button_control_ID, &radio_button_control_ref);
SetControlValue(radio_button_control_ref, 1);

CreateStandardAlert(kAlertPlainAlert, CFSTR("--- YOU MADE IT HERE ---"), CFSTR("Definitely made it to this part of the code for sure."), NULL, &alert);
RunStandardAlert(alert, NULL, &userItemHit);
break;
}



kainjow
Jun 22, 2007, 10:05 PM
I must be missing something so elementary it almost defies explanation :)

AppKit? ;)

GothicChess.Com
Jun 23, 2007, 02:56 AM
AppKit? ;)

This was of no help whatsoever, thanks.

:)

cblackburn
Jun 25, 2007, 05:47 AM
Where did the variable g_drawer_window_with_buttons come from. You use it to try and change the radio buttons but you do not use it to create the alert, hence if the problem was here you would get the alerts but not the expected behavior.

Also can you breakpoint on the GetControlByID() function and see if radio_button_control_ID etc are updated to reasonable values i.e. not 0x0 or null.

btw, now might be the time to mention I am a Cocoa programmer so I'm debugging this completely abstractly :-P.

Chris

GothicChess.Com
Jun 25, 2007, 10:01 PM
Where did the variable g_drawer_window_with_buttons come from. You use it to try and change the radio buttons but you do not use it to create the alert, hence if the problem was here you would get the alerts but not the expected behavior.

Also can you breakpoint on the GetControlByID() function and see if radio_button_control_ID etc are updated to reasonable values i.e. not 0x0 or null.

btw, now might be the time to mention I am a Cocoa programmer so I'm debugging this completely abstractly :-P.

Chris

Hi Chris,

I built this with XCode and InterfaceBuilder. So, g_drawer_window_with_buttons is just a name I made up for the window (which is a drawer that slides out of another window) and it is of type WindowRef. The actual resource for the window is in InterfaceBuilder.

The odd thing is, the radio buttons "do their thing" from the code module properly, namely, the code block does what I want when I hit them, its just they don't fill in and indicate that I hit them! In the good-ole-days all you have to do was call SetCtlValue with a data type of ControlHandle but now I am trying to figure out how to do it.

cblackburn
Jun 26, 2007, 02:06 AM
Could you package up the code as a small independent Xcode project exemplifying the problem. It's really difficult to debug without seeing it :)

Thanks

Chris