BecomeKeyWindow from

Discussion in 'Mac Programming' started by Nolis, Jun 17, 2011.

  1. macrumors newbie

    Joined:
    Jun 17, 2011
    #1
    Hey guys,
    I coded a simple cocoa webbrowser app with WebView, this Browser loads only an homepage, wihtout browser navigation or address line.. so basicly a simple fullscreen webbrowser. It resize to an fullscreen app:
    Code:
    styleMask:NSBorderlessWindowMask
    the Problem is when I use: NSBorderlessWindowMask I loose the Keyfunktion and also the html css onmouseover styles dosn't work... if I change it to an: NSTitledWindowMask everything works fine.. bun not in Fullscreen... can anyone help my out.. please notice that I'm bloody beginner in Xcode.

    here is my .h file
    Code:
    #import <Cocoa/Cocoa.h>
    #import <WebKit/WebKit.h>
    
    
    
    @interface TimeWarpAppDelegate : NSObject <NSApplicationDelegate> {
        NSWindow *window;
    	IBOutlet WebView*webview;
    
    		
    }
    
    @property (assign) IBOutlet NSWindow *window;
    
    
    @end
    
    here is my .m file
    Code:
    #import "TimeWarpAppDelegate.h"
    
    
    @implementation TimeWarpAppDelegate
    
    
    
    @synthesize window;
    
    
    - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    	// Insert code here to initialize your application 
    	
    	
    	
    	
    	[webview setDrawsBackground:NO];
    	
    	
    	[window orderOut:self];
        NSRect screenRect = [[NSScreen mainScreen] frame];
        NSView * iv = [window contentView];
        self.window = [[NSWindow alloc] initWithContentRect:screenRect
    // styleMask:NSTitledWindowMask
    styleMask:NSBorderlessWindowMask
    backing:NSBackingStoreBuffered
    defer:NO screen:[NSScreen mainScreen]];
    [self.window setContentView:iv];
    [self.window setLevel:CGShieldingWindowLevel()];
    [self.window makeKeyAndOrderFront:nil];  
    		
    	NSURL*url=[NSURL URLWithString:@"http://localhost/"];
        NSURLRequest*request=[NSURLRequest requestWithURL:url];
        [[webview mainFrame] loadRequest:request];
    	
    
    }
    
    - (BOOL)canBecomeKeyWindow
    {
    	return YES;
    }
    
    @end
    
    greetz Noli ;-)
     
  2. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    canBecomeKeyWindow is a method on NSWindow, so you need to subclass NSWindow, add that method into your subclass, then use your subclass instead of NSWindow when creating your window.
     
  3. thread starter macrumors newbie

    Joined:
    Jun 17, 2011
    #3
    I added a new class named it: activeView and put into activeView.h
    Code:
    #import <Cocoa/Cocoa.h>
    
    
    @interface activeView : NSWindow {
    
    }
    
    @end
    and I put this into the activeView.m
    Code:
    #import "activeView.h"
    
    
    @implementation activeView
    
    
    - (BOOL)canBecomeKeyWindow
    {
    	return YES;
    }
    
    - (BOOL)canBecomeMainWindow
    {
    	return YES;
    }
    
    
    @end
    
    I set the Class "NSWindow" from the MainWindow to "activeView" ...but it don't work... whats wrong ?
     
  4. Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #4
    In your applicationDidFinishLaunching: method, you're re-creating the window manually, but using NSWindow instead of your subclass. You need to change that to your subclass.
     
  5. thread starter macrumors newbie

    Joined:
    Jun 17, 2011
    #5
    I'm a bloody beginner, and I'm try very hard to it... can you please give me an code example.. ?

    greetz Noli ;-)
     
  6. macrumors 603

    Joined:
    Aug 9, 2009
    #6
    If you understand what the red-hilited code is doing, and what kainjow wrote, then you should know how to fix it.

    If you don't understand what the red-hilited code is doing, then you should pick a simpler project at this time. You're in over your head.
     

Share This Page