| | 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 | |
|---|
| | 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 | |
|---|