Adium

Changeset 24110

Show
Ignore:
Timestamp:
06/30/2008 11:13:06 AM (6 months ago)
Author:
evands
Message:

Greatly improved the appearance of the between-row drop targeter in the contact list. Credit to Cathy Shive's "Styling an NSTableView" sample code for the starting point.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Frameworks/Adium Framework/Source/AIListOutlineView.h

    r23280 r24110  
    104104- (NSCell *)outlineViewDataCellForGroup:(NSOutlineView *)outlineView; 
    105105@end 
    106  
    107  
  • trunk/Frameworks/Adium Framework/Source/AIListOutlineView.m

    r24089 r24110  
    552552 
    553553#pragma mark Drag & Drop Drawing 
     554/* The drop highlight hackery below was heavily inspired by Cathy Shive's "Styling an NSTableView" sample code at http://katidev.com/blog/tag/nstableview/ 
     555 * which is distributed under the following license: 
     556 * 
     557 * Copyright (c) 2008 Cathy Shive 
     558 *  
     559 * Permission is hereby granted, free of charge, to any person obtaining a copy 
     560 * of this code to reuse the code without restriction, subject to the following conditions: 
     561 *  
     562 * My name may not be used to endorse or promote products derived from this software without prior written permission from me. 
     563 *  
     564 * THIS CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. In other words, you agree not to sue me if anything goes wrong. 
     565 */ 
     566 
    554567/*! 
    555568 * @brief Called by NSOutineView to draw a drop highight 
     
    586599} 
    587600 
     601/*! 
     602 * @brief Draw the line between two rows during a drag 
     603 */ 
     604- (void)performDrawDropHighlightBetweenUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex atOffset:(float)theOffset 
     605{        
     606        NSRect  aHighlightRect; 
     607        float   aYPosition = 0; 
     608        int             indentationLevelRow; 
     609 
     610        if (theUpperRowIndex < 0) { 
     611                //If the lower row index is the first row, get the rect of the lowerRowIndex and draw above it 
     612                indentationLevelRow = theLowerRowIndex; 
     613                aHighlightRect = [self rectOfRow:theLowerRowIndex]; 
     614                aYPosition = NSMinY(aHighlightRect); 
     615 
     616        } else { 
     617                //In all other cases draw below theUpperRowIndex. However, we'll be dropping at the indentation level of the one below. 
     618                indentationLevelRow = theUpperRowIndex + 1; 
     619                aHighlightRect = [self rectOfRow:theUpperRowIndex]; 
     620                aYPosition = NSMinY(aHighlightRect) + NSHeight(aHighlightRect); 
     621        } 
     622 
     623         
     624        id item = [self itemAtRow:indentationLevelRow]; 
     625        AIListCell *cell = [self cellForTableColumn:nil item:item]; 
     626         
     627        [[self delegate] outlineView:self 
     628                                 willDisplayCell:cell  
     629                                  forTableColumn:nil 
     630                                                        item:item]; 
     631 
     632        switch ([cell textAlignment]) { 
     633                case NSRightTextAlignment: 
     634                        //Right alignment indents on the right 
     635                        aHighlightRect.size.width -= [cell indentation]; 
     636                        break; 
     637                default: 
     638                        //All other alignments indent on the left 
     639                        aHighlightRect.origin.x += [cell indentation]; 
     640                        aHighlightRect.size.width -= [cell indentation]; 
     641                        break; 
     642        } 
     643 
     644        //Accent rect will be where we draw the little circle 
     645        float   anAccentRectSize = 6; 
     646        float   anAccentRectXOffset = 2; 
     647        NSRect  anAccentRect = NSMakeRect(NSMinX(aHighlightRect) + anAccentRectXOffset, 
     648                                                                          aYPosition - anAccentRectSize*.5, 
     649                                                                          anAccentRectSize, 
     650                                                                          anAccentRectSize); 
     651         
     652        //Make points to define the line starting after the accent circle, extending the width of the row 
     653        NSPoint aStartPoint = NSMakePoint(NSMaxX(anAccentRect), aYPosition); 
     654        NSPoint anEndPoint = NSMakePoint(NSMaxX(aHighlightRect) - NSWidth(anAccentRect), aYPosition); 
     655         
     656        //Lock focus for drawing 
     657        [self lockFocus]; 
     658         
     659        //Make a bezier path, add the circle and line 
     660        NSBezierPath *aHighlightPath = [NSBezierPath bezierPath]; 
     661        [aHighlightPath appendBezierPathWithOvalInRect:anAccentRect]; 
     662        [aHighlightPath moveToPoint:aStartPoint]; 
     663        [aHighlightPath lineToPoint:anEndPoint]; 
     664         
     665        //Fill with white for the accent circle and stroke the path with black 
     666        [[NSColor whiteColor] set]; 
     667        [aHighlightPath fill]; 
     668        [aHighlightPath setLineWidth:2.0]; 
     669        [[NSColor blackColor] set]; 
     670        [aHighlightPath stroke]; 
     671         
     672        //Unlock focus 
     673        [self unlockFocus]; 
     674} 
     675 
     676/*! 
     677 * @brief Private NSOutlineView method called in 10.5 to draw the line between rows during a drag&drop operation 
     678 */ 
     679- (void)_drawDropHighlightBetweenUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex onRow:(int)theRow atOffset:(float)theOffset 
     680{ 
     681        [self performDrawDropHighlightBetweenUpperRow:theUpperRowIndex 
     682                                                                          andLowerRow:theLowerRowIndex 
     683                                                                                 atOffset:theOffset]; 
     684} 
     685 
     686/*! 
     687 * @brief Private NSOutlineView method called in 10.4 to draw the line between rows during a drag&drop operation 
     688 */ 
     689- (void) _drawDropHighlightBetweenUpperRow:(int)theUpperRowIndex andLowerRow:(int)theLowerRowIndex atOffset:(float)theOffset 
     690{ 
     691        [self performDrawDropHighlightBetweenUpperRow:theUpperRowIndex 
     692                                                                          andLowerRow:theLowerRowIndex 
     693                                                                                 atOffset:theOffset]; 
     694} 
     695 
    588696#pragma mark Attach & Detach Groups 
    589697 
     
    637745        AIListGroup             *currentGroup = nil;    // Current group being dragged 
    638746         
    639         //If nothing is being dragged, stop now. 
    640         //How would this happen? -evands 
    641         if (!dragContent) 
     747        if (!dragContent || (operation == NSDragOperationNone)) { 
     748                //The drag was canceled 
     749                //If nothing is being dragged, stop now. (How would this happen? -evands) 
     750                [[self dataSource] outlineView:self draggedImage:anImage endedAt:aPoint operation:operation];  
     751                [self setNeedsDisplay:YES]; 
    642752                return; 
    643          
    644         //The drag was canceled 
    645         if (operation == NSDragOperationNone) 
    646                 return; 
     753        } 
    647754 
    648755        id<AIInterfaceController>               interfaceController = [[AIObject sharedAdiumInstance] interfaceController]; 
     
    681788        dragContent = nil; 
    682789         
     790        [self setNeedsDisplay:YES]; 
    683791        [[self dataSource] outlineView:self draggedImage:anImage endedAt:aPoint operation:operation];  
    684792}