welcome to errorville... population me... (code snippet / please help)

Discussion in 'Mac Programming' started by Darkroom, Nov 14, 2007.

  1. Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #1
    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...

    Code:
    #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
    
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    Code:
    - (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:
    Code:
    [self setFrame:NSMakeRect(50, 50, 200, 200) display:YES animate:NO];
     
  3. macrumors 6502

    Joined:
    Feb 16, 2007
    #3
    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.
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    Also, you need to pay attention to compiler warnings. They alone should tell you that this code won't work.
     
  5. thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #5
    Code:
    - (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:

    Code:
    [self setFrame:NSMakeRect(50, 50, 200, 200) display:YES animate:NO];
    [/QUOTE]
     
  6. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #6
    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.
     
  7. thread starter Guest

    Darkroom

    Joined:
    Dec 15, 2006
    Location:
    Montréal, Canada
    #7
    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.
     

Share This Page