summaryrefslogtreecommitdiff
path: root/ext/mac-ui-macgap1-wrapper/src/MacGap/Classes/Window.m
blob: 2444f62eac04c53aed04ded095262a70e7c1fa23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#import "Window.h"

@implementation Window

@synthesize windowController, webView;

- (id) initWithWebView:(WebView*)view
{
    if(self = [super init]) {
        self.webView = view;
    }
    return self;
}

- (void) open:(NSDictionary *)properties
{
    self.windowController = [[WindowController alloc] initWithURL:[properties valueForKey:@"url"]];
    [self.windowController showWindow: [NSApplication sharedApplication].delegate];
    [self.windowController.window makeKeyWindow];
}

- (void) minimize {
    [[NSApp mainWindow] miniaturize:[NSApp mainWindow]];
}

- (void) toggleFullscreen {
    [[NSApp mainWindow] toggleFullScreen:[NSApp mainWindow]];
}

- (void) maximize {
    CGRect a = [NSApp mainWindow].frame;
    _oldRestoreFrame = CGRectMake(a.origin.x, a.origin.y, a.size.width, a.size.height);
    [[NSApp mainWindow] setFrame:[[NSScreen mainScreen] visibleFrame] display:YES];
}

- (Boolean) isMaximized {
    NSRect a = [NSApp mainWindow].frame;
    NSRect b = [[NSScreen mainScreen] visibleFrame];
    return a.origin.x == b.origin.x && a.origin.y == b.origin.y && a.size.width == b.size.width && a.size.height == b.size.height;
}

- (CGFloat) getX {
    NSRect frame = [self.webView window].frame;
    return frame.origin.x;
}

- (CGFloat) getY {
    NSRect frame = [self.webView window].frame;
    return frame.origin.y;
}

- (void) move:(NSDictionary *)properties
{
    NSRect frame = [self.webView window].frame;
    frame.origin.x = [[properties valueForKey:@"x"] doubleValue];
    frame.origin.y = [[properties valueForKey:@"y"] doubleValue];
    [[self.webView window] setFrame:frame display:YES];
    
}

- (void) resize:(NSDictionary *) properties
{
    NSRect frame = [self.webView window].frame;
    frame.size.width = [[properties valueForKey:@"width"] doubleValue];
    frame.size.height = [[properties valueForKey:@"height"] doubleValue];
    [[self.webView window] setFrame:frame display:YES];    
}


+ (BOOL) isSelectorExcludedFromWebScript:(SEL)selector
{
    return NO;
}

+ (NSString*) webScriptNameForSelector:(SEL)selector{
	id	result = nil;
	
	if (selector == @selector(open:)) {
		result = @"open";
	}else if (selector == @selector(move:)){
        result = @"move";
    }else if (selector == @selector(resize:)){
        result = @"resize";
    }
	
	return result;
}

+ (BOOL) isKeyExcludedFromWebScript:(const char*)name
{
	return YES;
}

@end