This is Control_4.m in view mode; [Download] [Up]
#import <appkit/appkit.h> // a minimal program to demonstrate how // to add controls to a window main() { // create an application object // to establish connection to // Window Server id NXApp = [Application new]; id theWindow; id theMenu; id theButton; id theSlider; id theTextField; id theForm; id targetWindow; NXRect theRect; // create a window that's at 125, 125 // and is 200 by 300 pixels NXSetRect(&theRect, 125, 125, 200, 300); theWindow = [ [Window alloc] initContent:&theRect style: NX_TITLEDSTYLE backing:NX_BUFFERED buttonMask:NX_MINIATURIZEBUTTONMASK defer:YES]; // create the menu theMenu = [ [Menu alloc] initTitle: [NXApp appName] ]; // create the menu option [theMenu addItem:"Quit" action:@selector(terminate:) keyEquivalent:'q']; // resize menu to accomodate menu option [theMenu sizeToFit]; [NXApp setMainMenu:theMenu]; // create a button that's 80 by 20 NXSetRect(&theRect, 0, 0, 80, 20); theButton = [ [Button alloc] initFrame:&theRect]; // set the title for the button [theButton setTitle:"Press Here"]; // since the button is a view, we need // to install it as the subview of the // window's contentview or else it // won't draw [ [theWindow contentView] addSubview: theButton]; // create the target window for the button targetWindow = [ [Window alloc] initContent:NULL style: NX_RESIZEBARSTYLE backing:NX_BUFFERED buttonMask:NX_MINIATURIZEBUTTONMASK defer:YES]; // make window target of button [theButton setTarget:targetWindow]; // when pressed, button sends // makeKeyAndOrderFront: message // to the window [theButton setAction:@selector (makeKeyAndOrderFront:)]; // create a horizontal slider 100 x 15 NXSetRect(&theRect, 0, 100, 100, 15); theSlider = [ [Slider alloc] initFrame:&theRect]; // set the min value to 0.0 [theSlider setMinValue:0.0]; // set the max value to 10.0 [theSlider setMaxValue:10.0]; [ [theWindow contentView] addSubview:theSlider]; // create a textfield that's 75 by 20 NXSetRect(&theRect, 0, 150, 75, 20); theTextField = [ [TextField alloc] initFrame:&theRect]; // make the text editable [theTextField setEditable:YES]; [ [theWindow contentView] addSubview:theTextField]; // make the textfield the target of // the slider and vice versa [theSlider setMinValue:0.0]; [theSlider setMaxValue:10.0]; [theSlider setTarget:theTextField]; [theSlider setAction: @selector(takeFloatValueFrom:)]; [theTextField setTarget:theSlider]; [theTextField setAction: @selector(takeFloatValueFrom:)]; // create a form that's 150 by 100 NXSetRect(&theRect, 0, 200, 150, 100); theForm = [ [Form alloc] initFrame:&theRect]; // add three entries to the form [theForm addEntry: "Name"]; [theForm addEntry: "Address"]; [theForm addEntry: "Phone"]; // set the size of the form [theForm sizeToFit]; [ [theWindow contentView] addSubview:theForm]; [theForm setTarget:theButton]; // button should act as though // it had been cliked [theForm setAction: @selector(performClick:)]; // send the window to the front // and display it [theWindow makeKeyAndOrderFront:nil]; // go into event loop to wait for events [NXApp run]; }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.