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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    }
Note: See TracChangeset for help on using the changeset viewer.