summaryrefslogtreecommitdiff
path: root/frontends/cocoa/PSMTabBarControl/PSMTabDragWindow.m
blob: d6fcc95a3f66061f56645e3c1577c511b23dc31a (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
//
//  PSMTabDragWindow.m
//  PSMTabBarControl
//
//  Created by Kent Sutherland on 6/1/06.
//  Copyright 2006 Kent Sutherland. All rights reserved.
//

#import "PSMTabDragWindow.h"
#import "PSMTabDragView.h"

@implementation PSMTabDragWindow

+ (PSMTabDragWindow *)dragWindowWithImage:(NSImage *)image styleMask:(NSUInteger)styleMask {
	return [[[PSMTabDragWindow alloc] initWithImage:image styleMask:styleMask] autorelease];
}

- (id)initWithImage:(NSImage *)image styleMask:(NSUInteger)styleMask {
	NSSize size = [image size];

	if((self = [super initWithContentRect:NSMakeRect(0, 0, size.width, size.height) styleMask:styleMask backing:NSBackingStoreBuffered defer:NO])) {
		_dragView = [[[PSMTabDragView alloc] initWithFrame:NSMakeRect(0, 0, size.width, size.height)] autorelease];
		[self setContentView:_dragView];
		[self setLevel:NSStatusWindowLevel];
		[self setIgnoresMouseEvents:YES];
		[self setOpaque:NO];

		[_dragView setImage:image];

		//Set the size of the window to be the exact size of the drag image
		NSRect windowFrame = [self frame];
		windowFrame.origin.y += windowFrame.size.height - size.height;
		windowFrame.size = size;

		if(styleMask | NSBorderlessWindowMask) {
			windowFrame.size.height += 22;
		}

		[self setFrame:windowFrame display:YES];
	}
	return self;
}

- (PSMTabDragView *)dragView {
	return _dragView;
}

@end