root/tags/2C11/AICustomTabDragWindow.m

Revision 2046, 5.9 kB (checked in by timothy, 4 years ago)

Add the title to the dragged tab window.

Line 
1 //
2 //  AICustomTabDragWindow.m
3 //  Adium
4 //
5 //  Created by Adam Iser on Sat Mar 06 2004.
6 //  Copyright (c) 2004 __MyCompanyName__. All rights reserved.
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 //init
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                 //Create a floating window for our tab
40                 dragTabFloater = [ESFloater floaterWithImage:floaterTabImage styleMask:NSBorderlessWindowMask title:nil];
41                 [dragTabFloater setMaxOpacity:1.0];
42                
43                 //Create a floating window for the stand-alone window our tab would produce
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 //dealloc
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 //Toggle display of the full drag window
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 //Move the drag floater to a screen point
79 //If the drag window is fading out, we don't move it.  Things look cleaner this way.
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 //Tab Imaging ----------------------------------------------------------------------------------------------------------
90 #pragma mark Drag Images
91 //Returns a drag image for the passed tab cell
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 //Returns a drag window image for the passed window/bar/cell
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         //Get an image of the tab
116         tabImage = [[[NSImage alloc] init] autorelease];
117         [customTabsView lockFocus];
118         [tabImage addRepresentation:[[[NSBitmapImageRep alloc] initWithFocusedViewRect:[tabCell frame]] autorelease]];
119         [customTabsView unlockFocus];
120        
121         //Get an image of the tabView content view
122         contentImage = [[[NSImage alloc] init] autorelease];
123         [contentView lockFocus];
124         [contentImage addRepresentation:[[[NSBitmapImageRep alloc] initWithFocusedViewRect:[contentView frame]] autorelease]];
125         [contentView unlockFocus];
126        
127         //Create a drag image the size of the window
128         dragWindowImage = [[[NSImage alloc] initWithSize:[[window contentView] frame].size] autorelease];
129         [dragWindowImage setBackgroundColor:[NSColor clearColor]];
130         [dragWindowImage lockFocus];
131        
132         //Draw the tabbar and tab
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; //Line the tab up a bit more realistically
136         [tabImage compositeToPoint:insertPoint operation:NSCompositeCopy];
137        
138         //Draw the content
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 //Returns the drag image for a drag system call.  In 10.3 we return a blank image to keep the system drag code happy
149 //Our custom drag image code (the floating windows) screws up drag tracking events in anything before panther (10.3)
150 //On earlier systems we fall back to using the stock dragging code
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
Note: See TracBrowser for help on using the browser.