Skip to content

Instantly share code, notes, and snippets.

@BlairDuncan
Created March 15, 2010 21:10
Show Gist options
  • Save BlairDuncan/333334 to your computer and use it in GitHub Desktop.
Save BlairDuncan/333334 to your computer and use it in GitHub Desktop.
@import <Foundation/CPObject.j>
@implementation AppController : CPObject
{
@outlet CPWindow theWindow; //this "outlet" is connected automatically by the Cib
}
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
{
[CPMenu setMenuBarVisible:YES];
var theSize = [theWindow frame].size;
theRect = CGRectMake(0, 0, theSize.width-40, theSize.height-40);
var anotherWindow = [[CPWindow alloc] initWithContentRect:theRect styleMask:CPClosableWindowMask];
[anotherWindow orderFront:self];
[anotherWindow center]
}
@end
@implementation CPWindow(fix_center) // takes into account the menubar
- (void)center
{
var size = [self frame].size,
containerSize = [CPPlatform isBrowser] ? [_platformWindow contentBounds].size : [[self screen] visibleFrame].size,
menuHeight = [CPMenu menuBarVisible] ? [CPMenu menuBarHeight] : 0;
[self setFrameOrigin:CGPointMake((containerSize.width - size.width) / 2.0, (containerSize.height - size.height + menuHeight) / 2.0)];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment