Forum Navigation
You need to log in to create posts and topics.

: ) Steve Van Voorst Cocoa Demos 1-6 (Concatenated)

Posted by: artlythere <artlythere@...>

I wanted a single go-to demo for Steve's jewels thus far so...Concatenation Time...

I left out the email text and explanations , however.

'FBtoC + FB5

Compile as "Objective-C // For Cocoa parts

// Set source-file combining to "Maximum" in Preferences...(Thanks SVV, RC)
// All-in-one-der of Steve Van Voorst Cocoa Demos 1-6, as of Dec 7, 2011
// Set all to 0 except for demo = 1 for the one you want.
// Brutal approach, but...

_demoTest1 = 0
_demoTest2 = 0
_demoTest3 = 0
_demoTest4 = 0
_demoTest5 = 1 // run this one, #5
_demoTest6 = 0

'~'1
/*
_demoTest1 = 1 // Run this one...etc
_demoTest2 = 0
_demoTest3 = 0
_demoTest4 = 0
_demoTest5 = 0
_demoTest6 = 0
*/
'~'1

#if _demoTest1
'----- begin -----

BeginCDeclaration
//@interface
//@end // interface
EndC

BeginCFunction
//@implementation
//@end //implementation
EndC

BeginCCode
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];

[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];

#define _wndW 430
#define _wndH 300

id window = [ [ NSWindow alloc ]
initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )
styleMask: NSClosableWindowMask | NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];

[window center];
[window setTitle: @"NSWindow" ];
[window makeKeyAndOrderFront:nil];

[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
[pool drain];
return NSApplicationMain(argc, (const char **) argv);
}
EndC

'----- end -----

#endif

#if _demoTest2
'---- start -----

BeginCDeclaration
@interface AppDelegate : NSObject
//methods automatically called
@end //interface
EndC

BeginCFunction
@implementation AppDelegate
// --- Taken from NSApplicationDelegate Protocol Reference ---- //
-(BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) theApp;
{
return YES;
}
@end //implementation
EndC

BeginCDeclaration
@interface AppController : NSObject
{
}
// ---- Methods listed here ---- //
- (void) myBtnAction:(id)sender;

@end //interface
EndC

BeginCFunction
@implementation AppController
// --- Methods defined here ---- //
-(void) myBtnAction:(id)sender
{
NSBeep();
}
@end //implementation
EndC

BeginCCode
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];

[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

// --- Menu bar and menus ---- //
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];
// ---- Window ------- //
#define _wndW 430
#define _wndH 300
id window = [ [ NSWindow alloc ]
initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )
styleMask: NSClosableWindowMask | NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window center];
[window setTitle: @"Controller/Delegate_demo" ];
[window makeKeyAndOrderFront:nil];

// Create an instance of AppDelegate (NSObject)
id myDelegate = [[AppDelegate alloc]init];
[NSApp setDelegate:myDelegate];

// Create an instance of AppController (NSObject)
id myController = [[AppController alloc]init];

NSButton*btn = [[NSButton alloc]initWithFrame:NSMakeRect( 100, _wndH - 100, 150, 30 )];
[[window contentView] addSubview: btn];
[btn setBezelStyle:NSRoundedBezelStyle ];
[btn setTitle: @"Beep" ];
[btn setTarget:myController];
[btn setAction:@selector(myBtnAction:)];
[btn release];

NSButton *quitBtn = [[NSButton alloc]initWithFrame:NSMakeRect( _wndW - 130, 30, 95, 30 )];
[quitBtn setBezelStyle:NSRoundedBezelStyle ];
[quitBtn setTitle: @"Quit" ];
[quitBtn setAction:@selector(terminate:)];
[[window contentView] addSubview: quitBtn];
[quitBtn release];

[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
[pool drain];
return NSApplicationMain(argc, (const char **) argv);
}
EndC

'------ end -----
#endif

#if _demoTest3
'----- start -----

/*
Template code:

NSWhatever *ctrlName = [[NSWhatever alloc] initWithFrame:NSMakeRect( left, top, width, height )];
[[window contentView] addSubview:ctrlName];

S.Van Voorst {20110901}
*/

//include resources "myImage.png"

BeginCCode
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];

[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

// ****** Menubar ****** //
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];

// ****** Window ******* //
#define _wndW 650
#define _wndH 530
id window = [ [ NSWindow alloc ] initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )
styleMask: NSClosableWindowMask | NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window center];
[window setTitle: @"Cocoa Controls - Programmatic" ];
[window makeKeyAndOrderFront:nil];

// ***** Text Field ***** //
NSTextField *txtFld = [[NSTextField alloc] initWithFrame:NSMakeRect( 30, _wndH - 40, 240, 20 )];
[[window contentView] addSubview:txtFld];
[txtFld setStringValue:@"Welcome to Cocoa without a nib."];
[txtFld release];

// ***** Slider ****** //
NSSlider *slider = [[NSSlider alloc] initWithFrame:NSMakeRect( 30, _wndH - 72, 240, 20 )];
[[window contentView] addSubview:slider];
[slider setMinValue:0];
[slider setMaxValue:12];
[slider setIntValue:8];
[slider release];

// ****** ComboBox ****** //
NSComboBox *combo = [[NSComboBox alloc] initWithFrame:NSMakeRect( 30, _wndH - 102, 100, 24 )];
[[window contentView] addSubview:combo];
NSArray *fruit = [NSArray arrayWithObjects: @"Apples", @"Oranges", @"Peaches",nil];
[combo addItemsWithObjectValues:fruit];
[combo release];

// ***** PopUp with Menu ****** //
NSPopUpButton *pup = [[NSPopUpButton alloc] initWithFrame:NSMakeRect( 150, _wndH - 102, 120, 24 )];
[[window contentView] addSubview:pup];
[pup insertItemWithTitle:@"Item 1" atIndex:0];
[pup insertItemWithTitle:@"Item 2" atIndex:1];
[pup insertItemWithTitle:@"Item 3" atIndex:2];
[pup release];

// ****** ImageView ****** //
NSImageView *imageView = [[NSImageView alloc] initWithFrame:NSMakeRect( 290, _wndH - 110, 100, 100 )];
[[window contentView] addSubview:imageView];
NSImage *image = [NSImage imageNamed:@"myImage.png"];
[imageView setImageScaling:NSScaleToFit];
[imageView setImage:image];
[imageView release];

// ****** NSTextView with Scroll ****** //
NSScrollView *scrlView = [[NSScrollView alloc] initWithFrame:NSMakeRect( 410, _wndH - 140, 180, 120 )];
[[window contentView] addSubview:scrlView];
[scrlView setHasVerticalScroller: YES];
NSTextView *txtView = [[NSTextView alloc] initWithFrame:NSMakeRect( 250, _wndH - 260, 136, 100 )];
[scrlView setDocumentView: txtView];
[txtView insertText:@"Enter text - Right click for menu."];
[scrlView release];
[txtView release];

// ****** ColorWell ****** //
NSColorWell *well = [[NSColorWell alloc] initWithFrame:NSMakeRect( 30, _wndH - 150, 60, 30 )];
[[window contentView] addSubview:well];
[well release];

// ****** Date Picker ****** //
NSDatePicker *datePick = [[NSDatePicker alloc] initWithFrame:NSMakeRect( 120, _wndH - 145, 200, 24 )];
[[window contentView] addSubview:datePick];
[datePick release];

// ****** Level Indicator ***** //
NSLevelIndicator *level = [[NSLevelIndicator alloc] initWithFrame:NSMakeRect( 30, _wndH - 180, 200, 18 )];
[[window contentView] addSubview:level];
[[level cell] setLevelIndicatorStyle: NSContinuousCapacityLevelIndicatorStyle];
[level setMinValue:0];
[level setMaxValue:12];
[level setIntValue:6];
[level release];
/*
NSRelevancyLevelIndicatorStyle, NSContinuousCapacityLevelIndicatorStyle,
NSDiscreteCapacityLevelIndicatorStyle, NSRatingLevelIndicatorStyle
*/
// ***** Progress Indicator ***** //
NSProgressIndicator *progress = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect( 30, _wndH - 220, 200, 20 )];
[[window contentView] addSubview:progress];
[progress release];

// ****** Segmented Control ****** //
NSSegmentedControl *seg = [[NSSegmentedControl alloc] initWithFrame:NSMakeRect( 30, _wndH - 260, 120, 24 )];
[[window contentView] addSubview:seg];
[seg release];
[seg setSegmentCount:2];
[seg setLabel:@"First" forSegment:0];
[seg setLabel:@"Second" forSegment:1];

// ****** Arrw/ValueFld ****** //
NSStepper *arrw = [[NSStepper alloc] initWithFrame:NSMakeRect( 160, _wndH - 260, 22, 26 )];
[[window contentView] addSubview:arrw];
[arrw release];
[arrw setContinuous:YES];
[arrw setAutorepeat:YES];
[arrw setValueWraps:NO];
[arrw setMaxValue:100];
[arrw setMinValue:0];
[arrw setIntValue:60];

NSTextField *valueFld = [[NSTextField alloc] initWithFrame:NSMakeRect( 180, _wndH - 257, 50, 20 )];
[[window contentView] addSubview:valueFld];
[valueFld release];
[valueFld setAlignment:NSCenterTextAlignment];
[valueFld takeStringValueFrom:arrw];

// Make each target of the other
[arrw setTarget:valueFld];
[arrw setAction:@selector(takeIntValueFrom:)];
[valueFld setTarget:arrw];
[valueFld setAction:@selector(takeIntValueFrom:)];

// ***** NSTabView ******* //
NSTabView *tab = [[NSTabView alloc] initWithFrame:NSMakeRect( 340, _wndH - 260, 280, 100 )];
NSTabViewItem* item1=[[NSTabViewItem alloc] initWithIdentifier:@"1"];
[item1 setLabel:@"One"];
[tab addTabViewItem:item1];
[item1 release];
NSTabViewItem* item2=[[NSTabViewItem alloc] initWithIdentifier:@"2"];
[item2 setLabel:@"Two"];
[tab addTabViewItem:item2];
[item2 release];
NSTabViewItem* item3=[[NSTabViewItem alloc] initWithIdentifier:@"3"];
[item3 setLabel:@"Three"];
[tab addTabViewItem:item3];
[item3 release];
[[window contentView] addSubview:tab];
[tab release];

// ***** NSMatrix ***** //
int n;

NSButtonCell *cell = [[NSButtonCell alloc]init];
[cell setButtonType:NSRadioButton];
// Width/height not critical if sizeToCells is used!
id matrix = [[NSMatrix alloc] initWithFrame:NSMakeRect( 260, _wndH - 270, 100, 100 )
mode:NSRadioModeMatrix
prototype:cell
numberOfRows:3
numberOfColumns:2];
[matrix setCellSize:NSMakeSize( 34, 34 )];
[matrix setIntercellSpacing: NSMakeSize( 3, 3 )];
[matrix sizeToCells];

NSArray *cellArray = [matrix cells];
for ( n = 0; n <= 5; n++ )
{
[[cellArray objectAtIndex: n ] setTitle:[NSString stringWithFormat:@"%d", n+1] ];
[[cellArray objectAtIndex: n ] setTag: n + 1 ];
}
[[window contentView] addSubview:matrix];
[cell release];
[matrix release];

// ***** NSButton Types ****** //
#define _top _wndH - 320
#define _left 30
#define _cellW 190
#define _cellH 40
#define _vg 10 //vertical gutter
#define _hg 6

NSButton *btn[14];
NSInteger count, row, col;
NSRect btnR;
count = 1;

for ( row = 0 ; row <= 4; row++ )
{
for ( col = 0; col <= 2; col++ )
{
if( row == 4 && col == 2 ) break; //Creates unbalanced grid
btnR = NSMakeRect( _left + (_cellW+_vg)*col, _top - (_cellH+_hg)*row, _cellW, _cellH );
btn[count] = [[NSButton alloc]initWithFrame:btnR];
[btn[count] setBezelStyle:count ];
switch (count)
{
case 1: [btn[count] setTitle: @"NSRoundedBezelStyle" ]; break;
case 2: [btn[count] setTitle: @"NSRegularSquareBezelStyle" ]; break;
case 3: [btn[count] setTitle: @"NSThickSquareBezelStyle" ]; break;
case 4: [btn[count] setTitle: @"NSThickerSquareBezelStyle" ]; break;
case 5: [btn[count] setTitle: @"" ]; break; // NSDisclosureBezelStyle
case 6: [btn[count] setTitle: @"NSShadowlessSquareBezelStyle" ]; break;
case 7: [btn[count] setTitle: @"" ]; break; // NSCircularBezelStyle
case 8: [btn[count] setTitle: @"NSTexturedSquareBezelStyle" ]; break;
case 9: [btn[count] setTitle: @"" ]; break; // NSHelpButtonBezelStyle
case 10: [btn[count] setTitle: @"NSSmallSquareBezelStyle" ]; break;
case 11: [btn[count] setTitle: @"NSTexturedRoundedBezelStyle" ]; break;
case 12: [btn[count] setTitle: @"NSRoundRectBezelStyle" ]; break;
case 13: [btn[count] setTitle: @"NSRecessedBezelStyle" ]; break;
case 14: [btn[count] setTitle: @"" ]; break; // NSRoundedDisclosureBezelStyle
}
[[window contentView] addSubview: btn[count]];
[btn[count] release];
count++;
}
}

[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
[pool drain];
}
EndC

'----- end ------
#endif

#if _demoTest4
'------ start -----

BeginCDeclaration
@interface DrawView : NSView
//methods automatically called
@end //interface
EndC

BeginCFunction
@implementation DrawView : NSView;

- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil)
{
self = [super initWithFrame:frameRect];
// Add initialization code here
}
return self;
}

- (void)drawRect:(NSRect)rect
{
// ****** Background ***** //
[[NSColor whiteColor] set];
[NSBezierPath fillRect:rect];

// ****** Attributed text ****** //
NSString *myStr;
NSPoint myPt;
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
[attr setObject:[NSFont fontWithName:@"Lucida Grande" size:18] forKey:NSFontAttributeName];
myStr = @"Attributed Text Drawn in an NSView";
myPt = NSMakePoint(30,20);
[myStr drawAtPoint:myPt withAttributes:attr];

[NSBezierPath setDefaultLineWidth:3.0];

// ****** Line ****** //
NSPoint begin, end;
begin = NSMakePoint( 30, 50 );
end = NSMakePoint( 360, 50 );
[NSBezierPath strokeLineFromPoint: begin toPoint:end];

// ***** Hashed Line ****** //
float lineDash[1];
NSBezierPath *hash = [NSBezierPath bezierPath];
[hash moveToPoint:NSMakePoint( 30, 70 )];
[hash lineToPoint:NSMakePoint( 360, 70 )];
lineDash[0] = 10; //dash
lineDash[1] = 4; //gap
[hash setLineDash:lineDash count: 2 phase:0.0 ];
[hash stroke];

// ****** Rounded Rectangle ****** //
NSRect R = NSMakeRect(100, 100, 100, 100);
[[NSColor greenColor] set];
NSBezierPath *parr = [NSBezierPath bezierPath];
[parr appendBezierPathWithRoundedRect: R xRadius: 10.0 yRadius: 10.0 ];
[parr stroke];

// ****** Circle ****** //
NSRect dotR = NSMakeRect( rect.size.width/2 - 50, rect.size.height/2 - 80, 100, 100 );
[[NSColor redColor] set];
[[NSBezierPath bezierPathWithOvalInRect:dotR] fill];

// ****** Oval ****** //
NSRect ovalR = NSMakeRect( 100, 230, 200, 100 );
[[NSColor magentaColor] set];
[[NSBezierPath bezierPathWithOvalInRect:ovalR] fill];

// ***** Polygon ****** //
[[NSColor blackColor] set];
NSBezierPath *path = [NSBezierPath bezierPath];
[path moveToPoint: NSMakePoint( 220.0, 150.0 )];
[path lineToPoint: NSMakePoint( 245.0, 175.0 )];
[path lineToPoint: NSMakePoint( 270.0, 150.0 )];
[path lineToPoint: NSMakePoint( 295.0, 150.0 )];
[path lineToPoint: NSMakePoint( 250.0, 120.0 )];
[path lineToPoint: NSMakePoint( 220.0, 150.0 )];
[path closePath];
[path setLineJoinStyle: NSRoundLineJoinStyle];
[path stroke];

NSRect outer = NSMakeRect( 80, 310, 100, 50 );
NSRect inner = NSInsetRect( outer, 1, 1 );
// ****** Filled Rectangle ***** //
[[NSColor blueColor] set];
[NSBezierPath fillRect:inner];
// ****** Stroked Rectangle ****** //
[[NSColor grayColor] set];
[NSBezierPath strokeRect:outer];

// ******Arc ******* //
[[NSColor blackColor] set];
NSBezierPath *arc = [NSBezierPath bezierPath];
[arc moveToPoint:NSMakePoint( 200, 320 )];
[arc appendBezierPathWithArcFromPoint:NSMakePoint( 200, 380 ) toPoint:NSMakePoint( 260, 380 ) radius:60];
[arc stroke];
}
// ----- Use this if you want 0,0 (origin) to be top, left ---- //
// ----- Otherwise origin will be at bottom, left (Unflipped) ----- //
-(BOOL)isFlipped
{
return YES;
}
@end //implementation
EndC

BeginCCode
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

// ----- Menubar and Menu ---- //
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];

//----- Window ---- //
#define _wndW 440
#define _wndH 500
id window = [ [ NSWindow alloc ]
initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )
styleMask: NSClosableWindowMask | NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window center];
[window setTitle: @"NSView_demo" ];
[window makeKeyAndOrderFront:nil];

// ------- Create an instance of DrawView (NSView) ------ //
id myDrawView = [[DrawView alloc]initWithFrame:NSMakeRect( 20, 20, _wndW - 40, _wndH - 40 )];
[[window contentView] addSubview:myDrawView];
[myDrawView release];

[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
[pool drain];
}
EndC

'----- end ------

#endif

#if _demoTest5
'------ start -------

///////////////////////////////////////
// FBtoC Preferences Settings: //
// Requires 10.6 Base SDK //
// Compile As Objective-C checked //
// or Un-REM first line below //
///////////////////////////////////////

//compile as "Objective-C"

BeginCDeclaration
// Create controller class
@interface AppController : NSObject
{
}
- (void)printView:(id)sender;

@end //interface
EndC

BeginCFunction
@implementation AppController

// These are used in lieu of outlets.
id gQuitBtnID;
id gPrintBtnID;
id gDrawViewID;

- (void)printView:(id)sender
{
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];
[printInfo setVerticallyCentered:NO];
[printInfo setHorizontallyCentered:YES];
[printInfo setTopMargin:60];
[printInfo setBottomMargin:10];
[printInfo setLeftMargin:45];
[printInfo setRightMargin:45];
[printInfo setOrientation:NSPortraitOrientation];

NSPrintOperation *printOp;
printOp = [NSPrintOperation printOperationWithView:gDrawViewID printInfo:printInfo];
//[printOp setShowsPrintPanel:YES];
//--Temporarily remove buttons overlying DrawView ---
[gPrintBtnID setHidden:YES];
[gQuitBtnID setHidden:YES];
//-- Run print operation ---
[printOp runOperation];
// -- Restore buttons ---
[gPrintBtnID setHidden:NO];
[gQuitBtnID setHidden:NO];
}
@end
EndC

BeginCDeclaration
@interface DrawView : NSView
//methods automatically called
@end //interface
EndC

BeginCFunction
@implementation DrawView : NSView;

- (id)initWithFrame:(NSRect)frameRect
{
if ((self = [super initWithFrame:frameRect]) != nil)
{
self = [super initWithFrame:frameRect];
// Add initialization code here
}
return self;
}

- (void)drawRect:(NSRect)rect
{
// ****** Filled Background ***** //
[[NSColor whiteColor] set];
[NSBezierPath fillRect:rect];

// ****** Attributed text ****** //
NSString *myStr;
NSPoint myPt;
NSMutableDictionary *attr = [NSMutableDictionary dictionary];
[attr setObject:[NSFont fontWithName:@"Lucida Grande" size:18] forKey:NSFontAttributeName];
myStr = @"Attributed Text Drawn in an NSView";
myPt = NSMakePoint(30,20);
[myStr drawAtPoint:myPt withAttributes:attr];

[NSBezierPath setDefaultLineWidth:3.0];

// ****** Line ****** //
NSPoint begin, end;
begin = NSMakePoint( 30, 50 );
end = NSMakePoint( 360, 50 );
[NSBezierPath strokeLineFromPoint: begin toPoint:end];

// ***** Hashed Line ****** //
float lineDash[1];
NSBezierPath *hash = [NSBezierPath bezierPath];
[hash moveToPoint:NSMakePoint( 30, 70 )];
[hash lineToPoint:NSMakePoint( 360, 70 )];
lineDash[0] = 10; //dash
lineDash[1] = 4; //gap
[hash setLineDash:lineDash count: 2 phase:0.0 ];
[hash stroke];

// ****** Rounded Rectangle ****** //
NSRect R = NSMakeRect(100, 100, 100, 100);
[[NSColor greenColor] set];
NSBezierPath *parr = [NSBezierPath bezierPath];
[parr appendBezierPathWithRoundedRect: R xRadius: 10.0 yRadius: 10.0 ];
[parr stroke];

// ****** Circle ****** //
NSRect dotR = NSMakeRect( rect.size.width/2 - 50, rect.size.height/2 - 80, 100, 100 );
[[NSColor redColor] set];
[[NSBezierPath bezierPathWithOvalInRect:dotR] fill];

// ****** Oval ****** //
NSRect ovalR = NSMakeRect( 100, 230, 200, 100 );
[[NSColor magentaColor] set];
[[NSBezierPath bezierPathWithOvalInRect:ovalR] fill];

// ***** Polygon ****** //
[[NSColor blackColor] set];
NSBezierPath *path = [NSBezierPath bezierPath];
[path moveToPoint: NSMakePoint( 220.0, 150.0 )];
[path lineToPoint: NSMakePoint( 245.0, 175.0 )];
[path lineToPoint: NSMakePoint( 270.0, 150.0 )];
[path lineToPoint: NSMakePoint( 295.0, 150.0 )];
[path lineToPoint: NSMakePoint( 250.0, 120.0 )];
[path lineToPoint: NSMakePoint( 220.0, 150.0 )];
[path closePath];
[path setLineJoinStyle: NSRoundLineJoinStyle];
[path stroke];

NSRect outer = NSMakeRect( 80, 310, 100, 50 );
NSRect inner = NSInsetRect( outer, 1, 1 );
// ****** Filled Rectangle ***** //
[[NSColor blueColor] set];
[NSBezierPath fillRect:inner];
// ****** Stroked Rectangle ****** //
[[NSColor grayColor] set];
[NSBezierPath strokeRect:outer];

// ******Arc ******* //
[[NSColor blackColor] set];
NSBezierPath *arc = [NSBezierPath bezierPath];
[arc moveToPoint:NSMakePoint( 200, 320 )];
[arc appendBezierPathWithArcFromPoint:NSMakePoint( 200, 380 ) toPoint:NSMakePoint( 260, 380 ) radius:60];
[arc stroke];
}

-(BOOL)isFlipped
{
return YES;
}
@end //implementation
EndC

BeginCCode
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

// Create an instance of the controller class
id myController = [[AppController alloc]init];

// ----- Menubar and Menu ---- //
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];

//----- Window ---- //
#define _wndW 440
#define _wndH 500
id window = [ [ NSWindow alloc ]
initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )
styleMask: NSClosableWindowMask | NSTitledWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window center];
[window setTitle: @"NSView_demo" ];
[window makeKeyAndOrderFront:nil];

// ------- Create an instance of DrawView (NSView) ------ //
id myDrawView = [[DrawView alloc]initWithFrame:NSMakeRect( 20, 20, _wndW - 40, _wndH - 40 )];
[[window contentView] addSubview:myDrawView];
gDrawViewID = myDrawView;
[myDrawView release];

NSButton *quitBtn = [[NSButton alloc]initWithFrame:NSMakeRect( _wndW - 160, _wndH - 80, 100, 30 )];
[quitBtn setBezelStyle:NSRoundedBezelStyle ];
[quitBtn setTitle: @"Quit" ];
[quitBtn setAction:@selector(terminate:)];
[myDrawView addSubview: quitBtn];
gQuitBtnID = quitBtn;
[quitBtn release];

NSButton *printBtn = [[NSButton alloc]initWithFrame:NSMakeRect( _wndW - 260, _wndH - 80, 100, 30 )];
[printBtn setBezelStyle:NSRoundedBezelStyle ];
[printBtn setTitle: @"Print" ];
[printBtn setTarget:myController];
[printBtn setAction:@selector(printView:)];
[myDrawView addSubview: printBtn];
gPrintBtnID = printBtn;
[printBtn release];

[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
[myController release];
[pool drain];
}
EndC

'----- end ---------
#endif

#if _demoTest6
'------- start --------

/////////////////////////////////////////
// FBtoC Preferences Settings: //
// Requires 10.6 Base SDK //
// "Compile As Objective-C" checked //
// or Un-REM first line below //
/////////////////////////////////////////

//compile as "Objective-C"

BeginCDeclaration
@interface AppController : NSObject
{
}
- (void) doAlert: (int) menuNum item: (int)itemNum;
- (void) menu2Item1:(id)sender;
- (void) menu2Item2:(id)sender;
- (void) menu3Item1Submenu1:(id)sender;
- (void) menu3Item2:(id)sender;
@end //interface
EndC

BeginCFunction
@implementation AppController

- (void) doAlert: (int) menuNum item: (int) itemNum
{
NSAlert *alert = [[NSAlert alloc]init];
[alert setAlertStyle: NSInformationalAlertStyle];
NSString *str = [[NSString alloc]initWithFormat:@"You chose menu %d, item %d.", menuNum,itemNum];
[alert setInformativeText:str];
[str release];
[alert runModal];
[alert release];
}

- (void) menu2Item1:(id)sender
{
[self doAlert:2 item:1];
}

- (void) menu2Item2:(id)sender
{
[self doAlert:2 item:2];
}

- (void) menu3Item1Submenu1:(id)sender
{
NSAlert *alert = [[NSAlert alloc]init];
[alert setAlertStyle: NSInformationalAlertStyle];
[alert setInformativeText:@"You chose menu 3, item 1, subMenu 1."];
[alert runModal];
[alert release];
}

- (void) menu3Item2:(id)sender
{
[self doAlert:3 item:2];
}

@end //implementation
EndC

BeginCCode
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init];
[NSApplication sharedApplication];
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];

// --- Create an instance of the controller class --- //
id myController = [[AppController alloc]init];

// ******** Menubar and AppMenu ********//
id menubar = [[NSMenu new] autorelease];
id appMenuItem = [[NSMenuItem new] autorelease];
[menubar addItem:appMenuItem];
[NSApp setMainMenu:menubar];
id appMenu = [[NSMenu new] autorelease];
id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit"
action:@selector(terminate:) keyEquivalent:@"q"] autorelease];
[appMenu addItem:quitMenuItem];
[appMenuItem setSubmenu:appMenu];

// ******** Menu 2 ******* //
NSMenuItem *myNewMenu2 = [[[NSMenuItem alloc] init] autorelease];
[menubar addItem:myNewMenu2];
NSMenu *menu2 = [[[NSMenu alloc] initWithTitle:@"Menu 2"] autorelease];
[myNewMenu2 setSubmenu:menu2];

// ******** Menu 2 Item1 ******* //
id menu2Item1 = [[[NSMenuItem alloc]initWithTitle:@"Item One..."
action:@selector(menu2Item1:) keyEquivalent:@"o"] autorelease];
[menu2 addItem:menu2Item1];
[menu2Item1 setTarget:myController];

// ******** Menu 2 Item2 ******* //
id menu2Item2 = [[[NSMenuItem alloc]initWithTitle:@"Item Two..."
action:@selector(menu2Item2:) keyEquivalent:@"t"] autorelease];
[menu2 addItem:menu2Item2];
[menu2Item2 setTarget:myController];

// ******** Menu 3 ******** //
NSMenuItem *myNewMenu3 = [[[NSMenuItem alloc] init] autorelease];
[menubar addItem:myNewMenu3];
NSMenu *menu3 = [[[NSMenu alloc] initWithTitle:@"Menu 3"] autorelease];
[myNewMenu3 setSubmenu:menu3];

// ******** Menu 3 Item1 ******* //
id menu3Item1 = [[[NSMenuItem alloc]initWithTitle:@"Item One"
action:nil keyEquivalent:@""] autorelease];
[menu3 addItem:menu3Item1];

// ******* Menu 3 Item1 Submenu1 ********* //
NSMenuItem *myNewSubmenu1 = [[[NSMenuItem alloc] initWithTitle:@"Submenu 1..."
action:@selector(menu3Item1Submenu1:) keyEquivalent:@"9"] autorelease];
NSMenu *subMenu1 = [[[NSMenu alloc] init] autorelease];
[menu3Item1 setSubmenu:subMenu1];
[subMenu1 addItem:myNewSubmenu1];
[myNewSubmenu1 setTarget:myController];

// ******** Menu 3 Item2 ******* //
id menu3Item2 = [[[NSMenuItem alloc]initWithTitle:@"Item Two..."
action:@selector(menu3Item2:) keyEquivalent:@"t"] autorelease];
[menu3 addItem:menu3Item2];
[menu3Item2 setTarget:myController];

// ******** Window ******** //
#define _wndW 400
#define _wndH 280
id window = [[NSWindow alloc] initWithContentRect:NSMakeRect( 0, 0, _wndW, _wndH )
styleMask:NSTitledWindowMask | NSClosableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
[window center];
[window setTitle:@"Menu Building_demo"];
[window makeKeyAndOrderFront:nil];

// ***** Quit btn ***** //
NSButton *quitBtn = [[NSButton alloc]initWithFrame:NSMakeRect( _wndW - 130, 30, 95, 30 )];
[quitBtn setBezelStyle:NSRoundedBezelStyle ];
[quitBtn setTitle: @"Quit" ];
[quitBtn setAction:@selector(terminate:)];
[[window contentView] addSubview: quitBtn];
[quitBtn release];

[NSApp activateIgnoringOtherApps:YES];
[NSApp run];
[myController release];
[pool drain];
}
EndC

'------ end -----------
#endif