Accessing widget from NIB

execom_rt

Registered
I have an interface made by interface builder with 1 button and 2 popup buttons.

I wrote this a code to initialise the interface from the NIB, I can display it and can detect the button being pressed (had to use the debugger to get the value !).

Now i want to add to items in the popup button (seems to be limited to 3 by defaul t and was unable to add more from interface builder (!)).

The problem is how do I can access to the popup buttons now ? Is there a GetDlgItem function or something to get the popup button (i've made 1 signature (pop1) and 1 ID (128) for the first and pop2 and 129 for the second.

I'm using Carbon btw.

It seems that there some NSPopupButton class for Popup button but no means to access it from a windowRef.

In order to get something like this :

NSPopupButton *button = GetDlgItem(window, kPopup1);

and doing something later for example
button->addItem("Entry1"); ...

int ret = button->getCurrentSel();

----

I used the following source code.

I've searched everything but the documentation seems .. poor

enum
{
kOkButton = 1869291552 // Used the debugger to get this value :(
kPopup1 = 128,
kPopup2 = 129

};

static OSErr QuitAppleEventHandler( const AppleEvent *appleEvt, AppleEvent* reply, UInt32 refcon )
{
QuitApplicationEventLoop();
return noErr;
}

static pascal OSStatus MainWindowCommandHandler(EventHandlerCallRef handlerRef,
EventRef event, void *userData)
{
OSStatus err = eventNotHandledErr;
HICommand command;
GetEventParameter(event, kEventParamDirectObject, typeHICommand,
NULL, sizeof(HICommand), NULL, &command);
switch(command.commandID){
case kOkButton:
QuitApplicationEventLoop();
err = noErr;
ret = 3;
break;
}
return err;
}

int ControlPanel()
{

EventTypeSpec commSpec = { kEventClassCommand, kEventProcessCommand};

OSStatus err;

IBNibRef nibRef;
WindowRef window;
// Create a Nib reference passing the name of the nib file (without the .nib extension)
// CreateNibReference only searches into the application bundle.
err = CreateNibReference(CFSTR("main"), &nibRef);
require_noerr( err, CantGetNibRef );

// Once the nib reference is created, set the menu bar. "MainMenu" is the name of the menu bar
// object. This name is set in InterfaceBuilder when the nib is created.
err = SetMenuBarFromNib(nibRef, CFSTR("MenuBar"));
require_noerr( err, CantSetMenuBar );

// Then create a window. "SetupWindow" is the name of the window object. This name is set in
// InterfaceBuilder when the nib is created.
err = CreateWindowFromNib(nibRef, CFSTR("SetupWindow"), &window);
require_noerr( err, CantCreateWindow );

// We don't need the nib reference anymore.
DisposeNibReference(nibRef);

// The window was created hidden so show it.
ShowWindow( window );

InstallWindowEventHandler(window,
NewEventHandlerUPP(MainWindowCommandHandler),
1, &commSpec, (void*)window, NULL);

err = AEInstallEventHandler( kCoreEventClass, kAEQuitApplication, NewAEEventHandlerUPP((AEEventHandlerProcPtr)QuitAppleEventHandler), 0, false );

// Prepare combo box
PrepareComboBox(window);
// Call the event loop
RunApplicationEventLoop();

CantCreateWindow:
CantSetMenuBar:
CantGetNibRef:

return ret;
}:( :(
 
In terms of adding more items from the interface builder (which is all I can deal with right now, as tired as I am), click on the pop-up button so that the default three items (or their now-changed values) are listed. Then from the Cocoa Menues palate (the one with the drop-down menus, first one in the bunch) drag the Item icon onto your pop up button. This will add another item to your pop up.

It's not particularly intuitive, I know. Hopefully this helps. Will this help you with the rest of the work you're doing?

Pacifix
 
Ah yes, I can add more items now.
Ok, but how to modify my program in order that when i press Ok, I can get the current selection of my popup list ?
I've got a NIB project and I know the 'ID' and the 'Signature' of the popup list
 
Back
Top