[428] | 1 | //
|
---|
| 2 | // ICeCoffEEMenuOutlineView.m
|
---|
| 3 | // ICeCoffEE
|
---|
| 4 | //
|
---|
| 5 | // Created by Nicholas Riley on 3/2/08.
|
---|
| 6 | // Copyright 2008 Nicholas Riley. All rights reserved.
|
---|
| 7 | //
|
---|
| 8 |
|
---|
| 9 | #import "ICeCoffEEMenuOutlineView.h"
|
---|
| 10 | #import <Carbon/Carbon.h>
|
---|
| 11 |
|
---|
[433] | 12 | // Tiger or later, indicates whether highlighted row should draw as active
|
---|
| 13 | @interface NSWindow (IC_KeyboardFocus)
|
---|
| 14 | - (BOOL)_isKeyWindowIgnoringFocus;
|
---|
| 15 | @end
|
---|
| 16 |
|
---|
| 17 | BOOL 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 |
|
---|
[428] | 40 | @implementation ICeCoffEEMenuOutlineView
|
---|
| 41 |
|
---|
[429] | 42 | // undocumented, Leopard-only, only way I can figure out to bypass inter-cell navigation
|
---|
| 43 | - (BOOL)canFocusCell:(NSCell *)cell atTableColumn:(NSTableColumn *)tableColumn row:(int)row;
|
---|
| 44 | {
|
---|
| 45 | return NO;
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[428] | 48 | - (void)highlightSelectionInClipRect:(NSRect)clipRect;
|
---|
| 49 | {
|
---|
| 50 | NSRange rows = [self rowsInRect: clipRect];
|
---|
| 51 | unsigned maxRow = NSMaxRange(rows);
|
---|
| 52 |
|
---|
| 53 | HIThemeMenuItemDrawInfo drawInfo = {0, kThemeMenuItemHierBackground | kThemeMenuItemPopUpBackground, kThemeMenuSelected};
|
---|
[433] | 54 | if (!ICCF_ViewHasKeyboardFocus(self)) {
|
---|
[428] | 55 | [super highlightSelectionInClipRect: clipRect];
|
---|
| 56 | return;
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | for (unsigned row = rows.location ; row < maxRow ; ++row) {
|
---|
| 60 | if (![self isRowSelected: row])
|
---|
| 61 | continue;
|
---|
| 62 |
|
---|
| 63 | NSRect rowRect = [self rectOfRow: row];
|
---|
| 64 | rowRect.size.height += 2;
|
---|
| 65 | if (NSIntersectsRect(rowRect, clipRect)) {
|
---|
| 66 | OSStatus err = HIThemeDrawMenuItem((HIRect *)&clipRect,
|
---|
| 67 | (HIRect *)&rowRect,
|
---|
| 68 | &drawInfo,
|
---|
| 69 | (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort],
|
---|
| 70 | kHIThemeOrientationInverted,
|
---|
| 71 | (HIRect *)&rowRect);
|
---|
| 72 | if (err != noErr) {
|
---|
| 73 | [super highlightSelectionInClipRect: clipRect];
|
---|
| 74 | return;
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | @end
|
---|