Changeset 2558 for trunk/AICustomTabCell.m
- Timestamp:
- 04/20/05 19:37:46 (4 years ago)
- Files:
-
- trunk/AICustomTabCell.m (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/AICustomTabCell.m
r2054 r2558 58 58 { 59 59 static BOOL haveLoadedImages = NO; 60 60 61 61 [super init]; 62 62 63 63 //Share these images between all AICustomTabCell instances 64 64 if(!haveLoadedImages){ … … 66 66 tabFrontMiddle = [[NSImage imageNamed:@"aquaTabMiddle"] retain]; 67 67 tabFrontRight = [[NSImage imageNamed:@"aquaTabRight"] retain]; 68 68 69 69 tabCloseFront = [[NSImage imageNamed:@"aquaTabClose"] retain]; 70 70 tabCloseBack = [[NSImage imageNamed:@"aquaTabCloseBack"] retain]; … … 74 74 leftCapSize = [tabFrontLeft size]; 75 75 rightCapSize = [tabFrontRight size]; 76 76 77 77 haveLoadedImages = YES; 78 78 } 79 79 80 80 tabViewItem = [inTabViewItem retain]; 81 81 view = inView; … … 88 88 closeTrackingTag = 0; 89 89 toolTipTag = 0; 90 90 91 91 return(self); 92 92 } … … 106 106 int width = leftCapSize.width + [[self attributedLabel] size].width + rightCapSize.width + 107 107 (TAB_CLOSE_LEFTPAD + [[tabViewItem icon] size].width + TAB_CLOSE_RIGHTPAD) + TAB_RIGHT_PAD; 108 108 109 109 return( NSMakeSize((width > TAB_MIN_WIDTH ? width : TAB_MIN_WIDTH), leftCapSize.height) ); 110 110 } … … 115 115 int tabWidth = [tab size].width; 116 116 int ourWidth = [self size].width; 117 117 118 118 if(tabWidth > ourWidth){ 119 119 return(NSOrderedAscending); 120 120 121 121 }else if(tabWidth < ourWidth){ 122 122 return(NSOrderedDescending); 123 123 124 124 }else{ 125 125 return(NSOrderedSame); 126 126 127 127 } 128 128 } … … 152 152 NSSize imageSize = [[tabViewItem icon] size]; 153 153 int centerY = (frame.size.height - imageSize.height) / 2.0; 154 154 155 155 return(NSMakeRect(frame.origin.x + leftCapSize.width + TAB_CLOSE_LEFTPAD, 156 156 frame.origin.y + centerY + TAB_CLOSE_Y_OFFSET, … … 226 226 NSSize labelSize; 227 227 NSPoint destPoint; 228 228 229 229 //Pre-calc some dimensions 230 230 labelSize = [tabViewItem sizeOfLabel:NO]; … … 232 232 middleRightEdge = (rect.origin.x + rect.size.width - rightCapSize.width); 233 233 middleLeftEdge = (rect.origin.x + leftCapSize.width); 234 234 235 235 //Background 236 236 if(selected && !ignoreSelection){ 237 237 //Draw the left cap 238 238 [tabFrontLeft compositeToPoint:NSMakePoint(rect.origin.x, rect.origin.y) operation:NSCompositeSourceOver]; 239 239 240 240 //Draw the middle 241 241 sourceRect = NSMakeRect(0, 0, [tabFrontMiddle size].width, [tabFrontMiddle size].height); 242 242 destRect = NSMakeRect(middleLeftEdge, rect.origin.y, sourceRect.size.width, sourceRect.size.height); 243 243 244 244 while(destRect.origin.x < middleRightEdge){ 245 245 if((destRect.origin.x + destRect.size.width) > middleRightEdge){ … … 249 249 destRect.origin.x += destRect.size.width; 250 250 } 251 251 252 252 //Draw the right cap 253 253 [tabFrontRight compositeToPoint:NSMakePoint(middleRightEdge, rect.origin.y) operation:NSCompositeSourceOver]; 254 254 255 255 }else if(highlighted){ 256 256 [[NSColor colorWithCalibratedWhite:0.0 alpha:0.1] set]; 257 257 [NSBezierPath fillRect:NSMakeRect(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height)]; 258 258 } 259 259 260 260 //We'll display our close icon if the user is hovering. Otherwise, we display the tab specified icon 261 261 NSImage *leftIcon = [tabViewItem icon]; 262 if((hoveringClose && (selected || allowsInactiveTabClosing || ( [[[NSApplication sharedApplication] currentEvent] modifierFlags] & NSCommandKeyMask ))) || !leftIcon){ 262 if((hoveringClose && (selected || allowsInactiveTabClosing || ( [[[NSApplication sharedApplication] currentEvent] modifierFlags] & NSCommandKeyMask ))) || !leftIcon){ 263 263 if(hoveringClose){ 264 264 leftIcon = (trackingClose ? tabCloseFrontPressed : tabCloseFrontRollover); … … 278 278 rect.origin.x += offsetX; 279 279 rect.size.width -= offsetX + TAB_RIGHT_PAD; 280 280 281 281 //Draw our label 282 282 destRect = NSMakeRect(rect.origin.x, … … 285 285 rect.size.height - ((rect.size.height - labelSize.height) / 2.0)); 286 286 if(TAB_SELECTED_HIGHER && !ignoreSelection && selected) destRect.origin.y += 1.0; 287 [[self attributedLabel] drawInRect:destRect]; 287 [[self attributedLabel] drawInRect:destRect]; 288 288 } 289 289 … … 292 292 { 293 293 NSString *label = [tabViewItem label]; 294 294 295 295 if(![label isEqualToString:[attributedLabel string]] || wasEnabled != [tabViewItem isEnabled] ){ 296 296 wasEnabled = [tabViewItem isEnabled]; … … 299 299 [paragraphStyle setAlignment:NSCenterTextAlignment]; 300 300 [paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail]; 301 301 302 302 //Update the attributed string 303 303 [attributedLabel release]; … … 309 309 nil]]; 310 310 } 311 311 312 312 return(attributedLabel); 313 313 } … … 324 324 assumeInside:NSPointInRect(cursorLocation, trackRect)]; 325 325 [self setHighlighted:NSPointInRect(cursorLocation, trackRect)]; 326 326 327 327 closeTrackingTag = [view addTrackingRect:[self _closeButtonRect] 328 328 owner:self … … 349 349 // [[tabViewItem tabView] selectTabViewItem:tabViewItem]; 350 350 // } 351 351 352 352 //Set ourself (or our close button) as hovered 353 353 if((allowsInactiveTabClosing || selected || ( [[[NSApplication sharedApplication] currentEvent] modifierFlags] & NSCommandKeyMask )) && … … 378 378 (SHOW_CLOSE_BUTTON_FOR_SINGLE_TAB || [[tabViewItem tabView] numberOfTabViewItems] != 1) && 379 379 NSPointInRect([controlView convertPoint:[theEvent locationInWindow] fromView:nil], [self _closeButtonRect])){ 380 380 381 381 [self trackMouse:theEvent inRect:[self _closeButtonRect] ofView:controlView untilMouseUp:YES]; 382 382 return(YES); 383 383 384 384 }else{ 385 385 return(NO); 386 386 387 387 } 388 388 } … … 394 394 hoveringClose = YES; 395 395 [controlView setNeedsDisplayInRect:[self _closeButtonRect]]; 396 396 397 397 return(YES); 398 398 } … … 402 402 { 403 403 BOOL hovering = NSPointInRect(currentPoint, [self _closeButtonRect]); 404 404 405 405 if(hoveringClose != hovering){ 406 406 hoveringClose = hovering; 407 407 [controlView setNeedsDisplayInRect:[self _closeButtonRect]]; 408 408 } 409 409 410 410 return(YES); 411 411 } … … 415 415 { 416 416 BOOL hovering = NSPointInRect(stopPoint, [self _closeButtonRect]); 417 417 418 418 //Closes all the other tabs in the current window if option is held down (And we have more than one tab) 419 419 if(hovering && ([[[controlView window] currentEvent] modifierFlags] & NSAlternateKeyMask) && [[tabViewItem tabView] numberOfTabViewItems] > 1){ … … 422 422 [(AICustomTabsView *)controlView closeTab:self]; 423 423 } 424 424 425 425 hoveringClose = NO; 426 426 trackingClose = NO;
