Skip to content

Instantly share code, notes, and snippets.

@karlforshaw
Created March 2, 2010 10:55
Show Gist options
  • Save karlforshaw/319429 to your computer and use it in GitHub Desktop.
Save karlforshaw/319429 to your computer and use it in GitHub Desktop.
var sharedWizardController = nil;
@implementation WizardController : CPWindowController
{
int _currentPage = 0;
}
- (WizardController)init
{
var wizardWindow = [[WizardWindow alloc] init];
var self = [super initWithWindow:wizardWindow];
if (self)
return self;
}
- (void)nextPage:(id)sender
{
alert('be patient');
}
- (void)previousPage:(id)sender
{
alert('looking back is never good');
}
+ (WizardController)getSharedWizardController
{
if (sharedWizardController == nil) {
//console.log("no wizardcontroller");
sharedWizardController = [[self alloc] init];
}
//console.log("wizard controller: ", sharedWizardController);
return sharedWizardController;
}
@end
@implementation WizardWindow : CPPanel
{
CPView _contentView;
CPView _pageViewInner;
}
- (WizardWindow)init
{
// Get the center of the window
var mainWindowBounds = [[[[CPApplication sharedApplication] mainWindow] contentView] bounds];
var width = 600;
var height = 450;
// Create the window
self = [super initWithContentRect:CGRectMake(
CGRectGetMidX(mainWindowBounds) - width / 2,
CGRectGetMidY(mainWindowBounds) - height / 2,
width, height)
styleMask:CPHUDBackgroundWindowMask | CPTitledWindowMask
];
if (self) {
[self setTitle:"Build Presentation Wizard"];
_contentView = [self contentView]; // Do we need this?
// Add the Back and Next Buttons
var nextButton = [[CPButton alloc] initWithFrame:CGRectMake(
CGRectGetMaxX([_contentView bounds]) - 50,
CGRectGetMaxY([_contentView bounds]) - 30,
40, 20
)];
[nextButton setTitle:"Next"];
[nextButton setBezelStyle:CPHUDBezelStyle];
[nextButton setTarget:self];
[nextButton setAction:@selector(nextPage:)];
[_contentView addSubview:nextButton];
var backButton = [[CPButton alloc] initWithFrame:CGRectMake(
CGRectGetMaxX([_contentView bounds]) - 100,
CGRectGetMaxY([_contentView bounds]) - 30,
40, 20
)];
[backButton setTitle:"Back"];
[backButton setBezelStyle:CPHUDBezelStyle];
[backButton setTarget:self];
[backButton setAction:@selector(previousPage:)];
[_contentView addSubview:backButton];
// Add the page view
_pageView = [[CPView alloc] initWithFrame:CGRectMake(
0,
20,
CGRectGetWidth([_contentView bounds]),
340
)];
[_pageView setBackgroundColor:[CPColor colorWithCalibratedWhite: 230.0/255.0 alpha: 1.0]];
[_contentView addSubview:_pageView];
// Add the first page
_pageViewInner = [self page1];
[_pageView addSubview:_pageViewInner];
return self;
}
else
alert('problem launching wizard');
}
-(void)nextPage:(id)aSender
{
alert('be patient');
}
-(void)previousPage:(id)aSender
{
alert('looking back is never good');
}
- (CPView)blankInner
{
return [[CPView alloc] initWithFrame:CGRectMake(
20,20,
CGRectGetWidth([_pageView bounds]) - 30,
CGRectGetHeight([_pageView bounds]) - 20
)];
}
- (CPView)page1
{
var view = [self blankInner];
var bounds = [view bounds];
var heading = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[heading setTextColor:[CPColor colorWithCalibratedWhite: 45.0/255.0 alpha: 1.0]];
[heading setFont:[CPFont boldSystemFontOfSize:26.0]];
[heading setStringValue:"Welcome to the Wizard"];
[heading sizeToFit];
[view addSubview:heading];
var welcomeText = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
[welcomeText setStringValue:"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer scelerisque turpis et elit ullamcorper sit amet rhoncus ante ultricies. Quisque non vulputate lacus. In viverra odio quis ipsum hendrerit lacinia. Suspendisse potenti. Suspendisse cursus sagittis massa sit amet ultrices. Vestibulum quis lorem justo. Pellentesque vel ipsum mauris. Curabitur dui tellus, convallis non lacinia a, eleifend ut enim."];
[welcomeText setLineBreakMode:CPLineBreakByWordWrapping];
[welcomeText setFrameSize:CPSizeMake(
CGRectGetWidth(bounds),
220)
];
[welcomeText setFrameOrigin:CPPointMake(0, 60)];
[view addSubview:welcomeText];
return view;
}
- (CPView)page2
{
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment