| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
#import "AICustomTabDragWindow.h" |
|---|
| 10 |
#import "AICustomTabsView.h" |
|---|
| 11 |
#import "AICustomTabCell.h" |
|---|
| 12 |
#import "ESFloater.h" |
|---|
| 13 |
|
|---|
| 14 |
#define CUSTOM_TABS_INDENT 3 //Indent on left and right of tabbar |
|---|
| 15 |
#define CONTENT_OFFSET_X 1 //Offset of content view relative to tabs |
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
@interface AICustomTabDragWindow (PRIVATE) |
|---|
| 19 |
- (id)initForCustomTabView:(AICustomTabsView *)inTabView cell:(AICustomTabCell *)inTabCell transparent:(BOOL)transparent; |
|---|
| 20 |
@end |
|---|
| 21 |
|
|---|
| 22 |
@implementation AICustomTabDragWindow |
|---|
| 23 |
+ (AICustomTabDragWindow *)dragWindowForCustomTabView:(AICustomTabsView *)inTabView cell:(AICustomTabCell *)inTabCell transparent:(BOOL)transparent |
|---|
| 24 |
{ |
|---|
| 25 |
return([[[self alloc] initForCustomTabView:inTabView cell:inTabCell transparent:transparent] autorelease]); |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
- (id)initForCustomTabView:(AICustomTabsView *)inTabView cell:(AICustomTabCell *)inTabCell transparent:(BOOL)transparent |
|---|
| 30 |
|
|---|
| 31 |
{ |
|---|
| 32 |
[super init]; |
|---|
| 33 |
|
|---|
| 34 |
floaterTabImage = [[self dragTabImageForTabCell:inTabCell inCustomTabsView:inTabView] retain]; |
|---|
| 35 |
floaterWindowImage = [[self dragWindowImageForWindow:[inTabView window] customTabsView:inTabView tabCell:inTabCell] retain]; |
|---|
| 36 |
useFancyAnimations = ( floaterWindowImage ? YES : NO ); |
|---|
| 37 |
|
|---|
| 38 |
if(useFancyAnimations){ |
|---|
| 39 |
|
|---|
| 40 |
dragTabFloater = [ESFloater floaterWithImage:floaterTabImage styleMask:NSBorderlessWindowMask title:nil]; |
|---|
| 41 |
[dragTabFloater setMaxOpacity:1.0]; |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
dragWindowFloater = [ESFloater floaterWithImage:floaterWindowImage styleMask:NSTitledWindowMask title:[[inTabView window] title]]; |
|---|
| 45 |
[dragWindowFloater setMaxOpacity:(transparent ? 0.75 : 1.00)]; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
return(self); |
|---|
| 49 |
} |
|---|
| 50 |
|
|---|
| 51 |
- (void)closeWindow |
|---|
| 52 |
{ |
|---|
| 53 |
[dragTabFloater close:nil]; dragTabFloater = nil; |
|---|
| 54 |
[dragWindowFloater close:nil]; dragWindowFloater = nil; |
|---|
| 55 |
} |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
- (void)dealloc |
|---|
| 59 |
{ |
|---|
| 60 |
[floaterTabImage release]; |
|---|
| 61 |
[floaterWindowImage release]; |
|---|
| 62 |
[dragTabFloater close:nil]; |
|---|
| 63 |
[dragWindowFloater close:nil]; |
|---|
| 64 |
|
|---|
| 65 |
[super dealloc]; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 |
- (void)setDisplayingFullWindow:(BOOL)inFullWindow animate:(BOOL)animate |
|---|
| 70 |
{ |
|---|
| 71 |
if(useFancyAnimations){ |
|---|
| 72 |
fullWindow = inFullWindow; |
|---|
| 73 |
[dragWindowFloater setVisible:fullWindow animate:animate]; |
|---|
| 74 |
[dragTabFloater setVisible:!fullWindow animate:animate]; |
|---|
| 75 |
} |
|---|
| 76 |
} |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
- (void)moveToPoint:(NSPoint)inPoint |
|---|
| 81 |
{ |
|---|
| 82 |
if(useFancyAnimations){ |
|---|
| 83 |
[dragTabFloater moveFloaterToPoint:inPoint]; |
|---|
| 84 |
if(fullWindow) [dragWindowFloater moveFloaterToPoint:NSMakePoint(inPoint.x - CUSTOM_TABS_INDENT, inPoint.y)]; |
|---|
| 85 |
} |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
#pragma mark Drag Images |
|---|
| 91 |
|
|---|
| 92 |
- (NSImage *)dragTabImageForTabCell:(AICustomTabCell *)tabCell inCustomTabsView:(AICustomTabsView *)customTabsView |
|---|
| 93 |
{ |
|---|
| 94 |
NSImage *dragTabImage = nil; |
|---|
| 95 |
|
|---|
| 96 |
if([customTabsView canDraw]){ |
|---|
| 97 |
dragTabImage = [[[NSImage alloc] init] autorelease]; |
|---|
| 98 |
[customTabsView lockFocus]; |
|---|
| 99 |
[dragTabImage addRepresentation:[[[NSBitmapImageRep alloc] initWithFocusedViewRect:[tabCell frame]] autorelease]]; |
|---|
| 100 |
[customTabsView unlockFocus]; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
return(dragTabImage); |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 |
- (NSImage *)dragWindowImageForWindow:(NSWindow *)window customTabsView:(AICustomTabsView *)customTabsView tabCell:(AICustomTabCell *)tabCell |
|---|
| 108 |
{ |
|---|
| 109 |
NSView *contentView = [[tabCell tabViewItem] view]; |
|---|
| 110 |
NSImage *dragWindowImage = nil; |
|---|
| 111 |
NSImage *contentImage, *tabImage; |
|---|
| 112 |
NSPoint insertPoint; |
|---|
| 113 |
|
|---|
| 114 |
if([customTabsView canDraw] && [contentView canDraw]){ |
|---|
| 115 |
|
|---|
| 116 |
tabImage = [[[NSImage alloc] init] autorelease]; |
|---|
| 117 |
[customTabsView lockFocus]; |
|---|
| 118 |
[tabImage addRepresentation:[[[NSBitmapImageRep alloc] initWithFocusedViewRect:[tabCell frame]] autorelease]]; |
|---|
| 119 |
[customTabsView unlockFocus]; |
|---|
| 120 |
|
|---|
| 121 |
|
|---|
| 122 |
contentImage = [[[NSImage alloc] init] autorelease]; |
|---|
| 123 |
[contentView lockFocus]; |
|---|
| 124 |
[contentImage addRepresentation:[[[NSBitmapImageRep alloc] initWithFocusedViewRect:[contentView frame]] autorelease]]; |
|---|
| 125 |
[contentView unlockFocus]; |
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 |
dragWindowImage = [[[NSImage alloc] initWithSize:[[window contentView] frame].size] autorelease]; |
|---|
| 129 |
[dragWindowImage setBackgroundColor:[NSColor clearColor]]; |
|---|
| 130 |
[dragWindowImage lockFocus]; |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
[customTabsView drawBackgroundInRect:[customTabsView frame] withFrame:[customTabsView frame] selectedTabRect:NSMakeRect(0,0,0,0)]; |
|---|
| 134 |
insertPoint = [customTabsView frame].origin; |
|---|
| 135 |
insertPoint.x += CUSTOM_TABS_INDENT; |
|---|
| 136 |
[tabImage compositeToPoint:insertPoint operation:NSCompositeCopy]; |
|---|
| 137 |
|
|---|
| 138 |
|
|---|
| 139 |
NSPoint frameOrigin = [[[tabCell tabViewItem] tabView] frame].origin; |
|---|
| 140 |
[contentImage compositeToPoint:NSMakePoint(frameOrigin.x + CONTENT_OFFSET_X, frameOrigin.y) operation:NSCompositeCopy]; |
|---|
| 141 |
|
|---|
| 142 |
[dragWindowImage unlockFocus]; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
return(dragWindowImage); |
|---|
| 146 |
} |
|---|
| 147 |
|
|---|
| 148 |
|
|---|
| 149 |
|
|---|
| 150 |
|
|---|
| 151 |
- (NSImage *)dragImage |
|---|
| 152 |
{ |
|---|
| 153 |
if(useFancyAnimations){ |
|---|
| 154 |
return([[[NSImage alloc] initWithSize:[floaterTabImage size]] autorelease]); |
|---|
| 155 |
}else{ |
|---|
| 156 |
return(floaterTabImage); |
|---|
| 157 |
} |
|---|
| 158 |
} |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
@end |
|---|