PDA

View Full Version : welcome to errorville... population me... (code snippet / please help)




Darkroom
Nov 14, 2007, 10:56 AM
hi there... i know some of you will look at this code and roll your eyes until they fall out, but it's the farthest i've come over the past several hours to making this code snippet make any sense to me, and at the risk of ridicule, i'm seeking help.

the window starts in full screen... i've simply created two IBActions (full screen mode and window mode) that i want to change the NSwindow's screen mode... simple right? yeahh... right...


#import "mainWindow.h"
#import <Carbon/Carbon.h>

@implementation mainWindow

- (id) initWithContentRect: (NSRect) contentRect
styleMask: (unsigned int) aStyle
backing: (NSBackingStoreType) bufferingType
defer: (BOOL) flag
{
self = [super initWithContentRect: contentRect
styleMask: NSBorderlessWindowMask
backing: bufferingType
defer: flag];


SetSystemUIMode(kUIModeAllHidden, 0);
[self setFrame:[[NSScreen mainScreen] visibleFrame] display:YES animate:NO];
SetSystemUIMode(kUIModeAllSuppressed, 0);


return self;
}

- (IBAction)goWindowMode:(id)sender {
[super initWithContentRect: contentRect
styleMask: NSResizableWindowMask | NSMiniaturizableWindowMask
backing: bufferingType
defer: flag];


SetSystemUIMode(kUIModeNormal, 0);
[self setFrame:[[NSWindow mainWindow] visibleFrame] display:YES animate:NO];


}

- (IBAction)goFullScreenMode:(id)sender {

}


@end



kainjow
Nov 14, 2007, 11:50 AM
- (IBAction)goWindowMode:(id)sender {
[super initWithContentRect: contentRect
styleMask: NSResizableWindowMask | NSMiniaturizableWindowMask
backing: bufferingType
defer: flag];


SetSystemUIMode(kUIModeNormal, 0);
[self setFrame:[[NSWindow mainWindow] visibleFrame] display:YES animate:NO];


}

First, you are calling [super initWithContentRect...] here. This is only to be used in an init... method, like you use it above. It is used to initialize the class using the super class's initialization method. Using it anywhere else is incorrect.

Second, when you're changing the window frame, you're just setting it to be full screen again. You need to create a new NSRect and set it to that. For example: [self setFrame:NSMakeRect(50, 50, 200, 200) display:YES animate:NO];

glennyboiwpg
Nov 14, 2007, 11:51 AM
I've never programmed for the mac (I'm a Java junkie) but I'm guessing a screenshot of the error (Or stacktrace, if Objective-c has those) would be helpeful for those who actually know objective-c.


Good Luck.

kainjow
Nov 14, 2007, 11:58 AM
Also, you need to pay attention to compiler warnings. They alone should tell you that this code won't work.

Darkroom
Nov 14, 2007, 01:38 PM
- (IBAction)goWindowMode:(id)sender {
styleMask: NSResizableWindowMask | NSMiniaturizableWindowMask
}


if i write this, in trying to tell the style mask to switch from it's initial NSBorderlessWindowMask, it says it hasn't been declared... like, i just don't understand how i can write it any way else... i've been searching online and thru the docs all afternoon to no avail...

but thanks for the following code example:

[self setFrame:NSMakeRect(50, 50, 200, 200) display:YES animate:NO];[/QUOTE]

kainjow
Nov 14, 2007, 01:54 PM
You can't change the styleMask once the window has been created. I'd suggest creating a separate window for your full screen window, and use the setContentView: method to synchronize the content views of both windows.

See Apple's example at /Developer/Examples/Quartz/Core Image/FunHouse. They manage two NSWindowControllers - one for full screen, and one for normal.

Darkroom
Nov 15, 2007, 12:34 AM
oh ok... that kinda makes sense then... i was just hoping that the style mask could be dynamically changed thru if/else statements or something... thanks for the help.