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 |
|
---|
12 | @implementation ICeCoffEEMenuOutlineView
|
---|
13 |
|
---|
14 | // undocumented, Leopard-only, only way I can figure out to bypass inter-cell navigation
|
---|
15 | - (BOOL)canFocusCell:(NSCell *)cell atTableColumn:(NSTableColumn *)tableColumn row:(int)row;
|
---|
16 | {
|
---|
17 | return NO;
|
---|
18 | }
|
---|
19 |
|
---|
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 |
|
---|
27 | - (BOOL)shouldUseActiveHighlight;
|
---|
28 | {
|
---|
29 | 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;
|
---|
40 | }
|
---|
41 |
|
---|
42 | - (void)highlightSelectionInClipRect:(NSRect)clipRect;
|
---|
43 | {
|
---|
44 | NSRange rows = [self rowsInRect: clipRect];
|
---|
45 | unsigned maxRow = NSMaxRange(rows);
|
---|
46 |
|
---|
47 | 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);
|
---|
51 | [super highlightSelectionInClipRect: clipRect];
|
---|
52 | instrumentObjcMessageSends(NO);
|
---|
53 | return;
|
---|
54 | }
|
---|
55 |
|
---|
56 | for (unsigned row = rows.location ; row < maxRow ; ++row) {
|
---|
57 | if (![self isRowSelected: row])
|
---|
58 | continue;
|
---|
59 |
|
---|
60 | NSRect rowRect = [self rectOfRow: row];
|
---|
61 | rowRect.size.height += 2;
|
---|
62 | if (NSIntersectsRect(rowRect, clipRect)) {
|
---|
63 | OSStatus err = HIThemeDrawMenuItem((HIRect *)&clipRect,
|
---|
64 | (HIRect *)&rowRect,
|
---|
65 | &drawInfo,
|
---|
66 | (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort],
|
---|
67 | kHIThemeOrientationInverted,
|
---|
68 | (HIRect *)&rowRect);
|
---|
69 | if (err != noErr) {
|
---|
70 | [super highlightSelectionInClipRect: clipRect];
|
---|
71 | return;
|
---|
72 | }
|
---|
73 | }
|
---|
74 | }
|
---|
75 | }
|
---|
76 |
|
---|
77 | @end
|
---|