Revision: 24161
http://sourceforge.net/p/bibdesk/svn/24161
Author: hofman
Date: 2019-08-26 09:40:58 +0000 (Mon, 26 Aug 2019)
Log Message:
-----------
draw finder label highlights in cell rather than matrix
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m 2019-08-26
06:30:57 UTC (rev 24160)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVColorMenuView.m 2019-08-26
09:40:58 UTC (rev 24161)
@@ -48,14 +48,15 @@
@end
@interface FVColorMenuCell : NSButtonCell
+{
+ BOOL hovered;
+}
+- (BOOL)isHovered;
+- (void)setHovered:(BOOL)flag;
@end
@interface FVColorMenuMatrix : NSMatrix
-{
- NSInteger _boxedRow;
- NSInteger _boxedColumn;
-}
-- (NSString *)boxedLabelName;
+- (NSString *)hoveredLabelName;
@end
@interface FVColorMenuView (FVPrivate)
@@ -202,7 +203,7 @@
// notification posted in response to a mouseover so we can update the label
name
- (void)_handleColorNameUpdate:(NSNotification *)note
{
- [_labelNameCell setStringValue:[_matrix boxedLabelName]];
+ [_labelNameCell setStringValue:[_matrix hoveredLabelName]];
[self setNeedsDisplay:YES];
}
@@ -235,6 +236,16 @@
return CELL_SIZE;
}
+- (BOOL)isHovered
+{
+ return hovered;
+}
+
+- (void)setHovered:(BOOL)flag
+{
+ hovered = flag;
+}
+
static NSRect __FVSquareRectCenteredInRect(const NSRect iconRect)
{
// determine aspect ratio (copy paste from FVIcon)
@@ -253,6 +264,9 @@
return dstRect;
}
+#define BOX_WIDTH 1.5
+#define BOX_RADIUS 2
+
- (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)controlView
{
frame = __FVSquareRectCenteredInRect(frame);
@@ -264,6 +278,25 @@
// @@ Dark mode
+ // the X doesn't show as selected
+ if ([self state] == NSOnState && 0 != tag) {
+ [[NSColor lightGrayColor] setStroke];
+ NSRect boxRect = [controlView
centerScanRect:NSInsetRect(__FVSquareRectCenteredInRect(frame), 1.0, 1.0)];
+ NSBezierPath *boxPath = [NSBezierPath
fv_bezierPathWithRoundRect:boxRect xRadius:BOX_RADIUS yRadius:BOX_RADIUS];
+ [boxPath setLineWidth:BOX_WIDTH];
+ [boxPath stroke];
+ }
+ // draw a box around the moused-over cell (unless it's selected); the X
cell always gets highlighted, since it's never drawn as selected
+ else if ([self isHovered]) {
+ [[NSColor lightGrayColor] setStroke];
+ NSRect boxRect = [controlView
centerScanRect:NSInsetRect(__FVSquareRectCenteredInRect(frame), 1.0, 1.0)];
+ NSBezierPath *boxPath = [NSBezierPath
fv_bezierPathWithRoundRect:boxRect xRadius:BOX_RADIUS yRadius:BOX_RADIUS];
+ [[NSColor colorWithCalibratedWhite:0.5 alpha:0.3] setFill];
+ [boxPath fill];
+ [boxPath setLineWidth:BOX_WIDTH];
+ [boxPath stroke];
+ }
+
if (0 == tag) {
interiorFrame = NSInsetRect(interiorFrame, 2.0, 2.0);
NSBezierPath *p = [NSBezierPath bezierPath];
@@ -293,13 +326,8 @@
@implementation FVColorMenuMatrix
-#define NO_BOX -1
-
#define FINDER_LABELS { 0, 6, 7, 5, 2, 4, 3, 1 }
-#define BOX_WIDTH 1.5
-#define BOX_RADIUS 2
-
- (id)initWithFrame:(NSRect)frameRect
{
if (self = [super initWithFrame:frameRect]) {
@@ -312,8 +340,6 @@
NSInteger column, tags[8] = FINDER_LABELS;
for (column = 0; column < 8; column++)
[[self cellAtRow:0 column:column] setTag:tags[column]];
- _boxedRow = NO_BOX;
- _boxedColumn = NO_BOX;
}
return self;
}
@@ -347,8 +373,7 @@
- (void)viewWillMoveToWindow:(NSWindow *)window
{
- _boxedRow = NO_BOX;
- _boxedColumn = NO_BOX;
+ [[self cells] setValue:[NSNumber numberWithBool:NO] forKey:@"hovered"];
if (window)
[self rebuildTrackingAreas];
@@ -356,56 +381,14 @@
[self removeTrackingAreas];
}
-- (NSRect)boxRectForCellAtRow:(NSUInteger)r column:(NSUInteger)c
+- (void)mouseEntered:(NSEvent *)event
{
- NSRect boxRect = [self cellFrameAtRow:r column:c];
- boxRect = __FVSquareRectCenteredInRect(boxRect);
- return [self centerScanRect:NSInsetRect(boxRect, 1.0, 1.0)];
-}
-
-
-- (BOOL)_isBoxedCellSelected { return ([self selectedRow] == _boxedRow &&
[self selectedColumn] == _boxedColumn); }
-
-- (BOOL)_isFirstCellSelected { return ([self selectedRow] == 0 && [self
selectedColumn] == 0); }
-
-- (void)drawRect:(NSRect)aRect
-{
- // @@ Dark mode
+ NSInteger r = -1, c = -1;
- // draw a box around the moused-over cell (unless it's selected); the X
cell always gets highlighted, since it's never drawn as selected
- if (NO_BOX != _boxedRow && NO_BOX != _boxedColumn && (NO == [self
_isBoxedCellSelected] || [self _isFirstCellSelected])) {
- [[NSColor lightGrayColor] setStroke];
- NSRect boxRect = [self boxRectForCellAtRow:_boxedRow
column:_boxedColumn];
- NSBezierPath *boxPath = [NSBezierPath
fv_bezierPathWithRoundRect:boxRect xRadius:BOX_RADIUS yRadius:BOX_RADIUS];
- [[NSColor colorWithCalibratedWhite:0.5 alpha:0.3] setFill];
- [boxPath fill];
- [boxPath setLineWidth:BOX_WIDTH];
- [boxPath stroke];
- }
-
- // the X doesn't show as selected
- if ([self selectedRow] != 0 || [self selectedColumn] != 0) {
- [[NSColor lightGrayColor] setStroke];
- NSRect boxRect = [self boxRectForCellAtRow:[self selectedRow]
column:[self selectedColumn]];
- NSBezierPath *boxPath = [NSBezierPath
fv_bezierPathWithRoundRect:boxRect xRadius:BOX_RADIUS yRadius:BOX_RADIUS];
- [boxPath setLineWidth:BOX_WIDTH];
- [boxPath stroke];
- }
-
- [super drawRect:aRect];
-}
-
-- (void)mouseEntered:(NSEvent *)event
-{
- NSInteger r, c;
- if ([self getRow:&r column:&c forPoint:[self convertPoint:[event
locationInWindow] fromView:nil]]) {
- _boxedRow = r;
- _boxedColumn = c;
- }
- else {
- _boxedRow = NO_BOX;
- _boxedColumn = NO_BOX;
- }
+ [self getRow:&r column:&c forPoint:[self convertPoint:[event
locationInWindow] fromView:nil]];
+ [[self cells] setValue:[NSNumber numberWithBool:NO] forKey:@"hovered"];
+ if (r != -1 && c != -1)
+ [[self cellAtRow:r column:c] setHovered:YES];
[self setNeedsDisplay:YES];
[[NSNotificationCenter defaultCenter]
postNotificationName:FVColorNameUpdateNotification object:self];
[super mouseEntered:event];
@@ -413,20 +396,21 @@
- (void)mouseExited:(NSEvent *)event
{
- _boxedRow = NO_BOX;
- _boxedColumn = NO_BOX;
+ [[self cells] setValue:[NSNumber numberWithInteger:NSOffState]
forKey:@"hovered"];
[self setNeedsDisplay:YES];
[[NSNotificationCenter defaultCenter]
postNotificationName:FVColorNameUpdateNotification object:self];
[super mouseExited:event];
}
-- (NSString *)boxedLabelName;
+- (NSString *)hoveredLabelName;
{
- NSCell *cell = nil;
+ FVColorMenuCell *cell = nil;
+ NSEnumerator *cellEnum = [[self cells] objectEnumerator];
- // return @"" if a cell isn't hovered over
- if (NO_BOX != _boxedRow && NO_BOX != _boxedColumn)
- cell = [self cellAtRow:_boxedRow column:_boxedColumn];
+ while ((cell = [cellEnum nextObject])) {
+ if ([cell isHovered])
+ break;
+ }
// Finder uses curly quotes around the name, and displays nothing for the
X item
return 0 == [cell tag] ? @"" : [NSString stringWithFormat:@"%C%@%C",
(unichar)0x201C, [FVFinderLabel localizedNameForLabel:[cell tag]],
(unichar)0x201D];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit