Browse files

Fix #39: Badges not drawn correctly when Source List row is selected.

This fix consists of two parts:
1) We first need to check the backgroundStyle property in
PXSourceListBadgeCell to determine whether to draw the light badge
background or not.

2) Next we need to determine whether the enclosing Source List (or child
view) is focused to decide whether to draw the badge text using the bright
blue or grey-blue. To do this, we walk up the view hierarchy
from the common ancestor view of the controlView and firstResponder
until we hit a PXSourceList instance. If we find one, then the source
list is selected, otherwise not.

Walking up the tree from the common ancestor view catches the highly-
unlikely but possible scenario where there are two PXSourceList
instances on screen and one is focused.
  • Loading branch information...
Perspx committed Mar 5, 2014
1 parent 3eadddb commit 60974e14fd4fc369f4c56131743d402dc7e7b7ae
Showing with 20 additions and 2 deletions.
  1. +20 −2 PXSourceList/PXSourceListBadgeCell.m
@@ -9,6 +9,8 @@
#import "PXSourceListBadgeCell.h"
#import "PXSourceList.h"
//Drawing constants
static inline NSColor *badgeBackgroundColor() { return [NSColor colorWithCalibratedRed:(152/255.0) green:(168/255.0) blue:(202/255.0) alpha:1]; }
static inline NSColor *badgeHiddenBackgroundColor() { return [NSColor colorWithDeviceWhite:(180/255.0) alpha:1]; }
@@ -40,11 +42,27 @@ - (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
NSDictionary *attributes;
NSColor *backgroundColor;
if(self.isHighlighted) {
if(self.isHighlighted || self.backgroundStyle == NSBackgroundStyleDark) {
backgroundColor = [NSColor whiteColor];
NSResponder *firstResponder = controlView.window.firstResponder;
BOOL isFocused = [firstResponder isKindOfClass:[NSView class]] && [(NSView *)firstResponder isDescendantOf:controlView];
BOOL isFocused = NO;
// Starting with the closest ancestor of the control view and the first responder (to make sure both views are in the
// same subtree of the view hierarchy), keep going up the view hierarchy until we hit a PXSourceList instance to tell
// if the source list is focused.
// This covers both the cell-based and view-based cases as well as if a child view of the NSTableCellView (such as
// a text field) is focused.
if ([firstResponder isKindOfClass:[NSView class]]) {
NSView *view = [(NSView*)firstResponder ancestorSharedWithView:controlView];
do {
if ([view isKindOfClass:[PXSourceList class]]) {
isFocused = YES;
} while ((view = [view superview]));
NSColor *textColor;
if (isMainWindowVisible && isFocused)

0 comments on commit 60974e1

Please sign in to comment.