Changeset 433


Ignore:
Timestamp:
03/03/08 09:25:06 (12 years ago)
Author:
Nicholas Riley
Message:

Undocumented method / hack fallback to determine whether we should draw the highlighted row as active.

Location:
trunk/ICeCoffEE/ICeCoffEE
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEInvertingTextFieldCell.m

    r432 r433  
    2020- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
    2121{
    22     // XXX note cast to ICeCoffEEMenuOutlineView *; this is not general-purpose
    23     if ([self isHighlighted] && [(ICeCoffEEMenuOutlineView *)controlView shouldUseActiveHighlight]) {
     22    if ([self isHighlighted] && ICCF_ViewHasKeyboardFocus(controlView)) {
    2423        NSMutableAttributedString *astr = [[self attributedStringValue] mutableCopy];
    2524        unsigned location = 0, length = [astr length];
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEMenuOutlineView.h

    r432 r433  
    99#import <Cocoa/Cocoa.h>
    1010
     11BOOL ICCF_ViewHasKeyboardFocus(NSView *view);
    1112
    1213@interface ICeCoffEEMenuOutlineView : NSOutlineView {
    13     NSWindow *mainWindow; // not retained
     14
    1415}
    1516
    16 - (BOOL)shouldUseActiveHighlight;
    17 
    1817@end
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEMenuOutlineView.m

    r432 r433  
    1010#import <Carbon/Carbon.h>
    1111
     12// Tiger or later, indicates whether highlighted row should draw as active
     13@interface NSWindow (IC_KeyboardFocus)
     14- (BOOL)_isKeyWindowIgnoringFocus;
     15@end
     16
     17BOOL ICCF_ViewHasKeyboardFocus(NSView *view) {
     18    NSWindow *window = [view window];
     19    if ([window firstResponder] != view)
     20        return NO;
     21   
     22    if ([window respondsToSelector: @selector(_isKeyWindowIgnoringFocus)])
     23        return [window _isKeyWindowIgnoringFocus];
     24   
     25    // XXX is there a documented way to do this?
     26    // see <http://lists.apple.com/archives/cocoa-dev/2008/Mar/msg00036.html>
     27   
     28    // test cases:
     29    // - About System Preferences...
     30    // - focused character palette
     31    // - Help menu search (Shortcut)
     32    // - menu extras
     33    NSWindow *keyWindow = [NSApp keyWindow];
     34    if (window != keyWindow && (keyWindow == nil || [keyWindow isKindOfClass: [NSPanel class]]))
     35        return NO; // exclude NSCarbonMenuWindow
     36   
     37    return YES;
     38}
     39
    1240@implementation ICeCoffEEMenuOutlineView
    1341
     
    1846}
    1947
    20 // maintains main window (e.g., window to which sheet is attached) for use by shouldUseActiveHighlight
    21 - (void)viewDidMoveToWindow;
    22 {
    23     mainWindow = [NSApp mainWindow];
    24     [super viewDidMoveToWindow];
    25 }
    26 
    2748- (BOOL)shouldUseActiveHighlight;
    2849{
    2950    return NO;
    30     // test cases: - XXX there should be a better way to do this
    31     // see <http://lists.apple.com/archives/cocoa-dev/2008/Mar/msg00036.html>
    32     // - About System Preferences...
    33     // - focused character palette
    34     // - Help menu search (Shortcut)
    35     // - menu extras
    36     NSWindow *keyWindow = [NSApp keyWindow], *thisWindow = [self window];
    37     if (keyWindow != thisWindow && [keyWindow isKindOfClass: [NSPanel class]])
    38         return NO; // exclude NSCarbonMenuWindow
    39     return [thisWindow firstResponder] == self && [NSApp mainWindow] == mainWindow;
     51    return [[self window] _isKeyWindowIgnoringFocus];
    4052}
    4153
     
    4658
    4759    HIThemeMenuItemDrawInfo drawInfo = {0, kThemeMenuItemHierBackground | kThemeMenuItemPopUpBackground, kThemeMenuSelected};
    48     NSLog(@"firstResponder %@ key %@ isKey %d main %@", [[self window] firstResponder], [NSApp keyWindow], [[self window] isKeyWindow], [NSApp mainWindow]);
    49     if (![self shouldUseActiveHighlight]) {
    50         instrumentObjcMessageSends(YES);
     60    if (!ICCF_ViewHasKeyboardFocus(self)) {
    5161        [super highlightSelectionInClipRect: clipRect];
    52         instrumentObjcMessageSends(NO);
    5362        return;
    5463    }
  • trunk/ICeCoffEE/ICeCoffEE/ICeCoffEEServicePrefController.m

    r432 r433  
    478478   
    479479    if (![outlineView isRowSelected: [outlineView rowForItem: item]] ||
    480         ![(ICeCoffEEMenuOutlineView *)outlineView shouldUseActiveHighlight]) {
     480        !ICCF_ViewHasKeyboardFocus(outlineView)) {
    481481        if (!isInverted)
    482482            return;
Note: See TracChangeset for help on using the changeset viewer.