PDA

View Full Version : BecomeKeyWindow from




Nolis
Jun 17, 2011, 10:53 AM
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: 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
#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
#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 ;-)



kainjow
Jun 17, 2011, 01:43 PM
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.

Nolis
Jun 19, 2011, 02:01 AM
I added a new class named it: activeView and put into activeView.h
#import <Cocoa/Cocoa.h>


@interface activeView : NSWindow {

}

@end and I put this into the activeView.m
#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 ?

kainjow
Jun 19, 2011, 02:45 PM
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.

Nolis
Jun 19, 2011, 04:11 PM
I'm a bloody beginner, and I'm try very hard to it... can you please give me an code example.. ?

greetz Noli ;-)

chown33
Jun 19, 2011, 04:32 PM
here is my .m file
#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];

}


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.