|
12 | 12 |
|
13 | 13 | @interface PBSourceViewCell()
|
14 | 14 | - (NSRect)infoButtonRectForBounds:(NSRect)bounds;
|
| 15 | +- (void)mouseEntered:(NSEvent *)event; |
| 16 | +- (void)mouseExited:(NSEvent *)event; |
15 | 17 | @end
|
16 | 18 |
|
17 | 19 | @implementation PBSourceViewCell
|
@@ -91,91 +93,28 @@ - (void)drawInteriorWithFrame:(NSRect)bounds inView:(NSView *)controlView {
|
91 | 93 | }
|
92 | 94 | }
|
93 | 95 |
|
94 |
| - |
95 |
| -//- (NSUInteger)hitTestForEvent:(NSEvent *)event inRect:(NSRect)cellFrame ofView:(NSView *)controlView { |
96 |
| -// if (showsActionButton) { |
97 |
| -// NSPoint point = [controlView convertPoint:[event locationInWindow] fromView:nil]; |
98 |
| -// // |
99 |
| -// // NSRect titleRect = [self titleRectForBounds:cellFrame]; |
100 |
| -// // if (NSMouseInRect(point, titleRect, [controlView isFlipped])) { |
101 |
| -// // return NSCellHitContentArea | NSCellHitEditableTextArea; |
102 |
| -// // } |
103 |
| -// // |
104 |
| -// // NSRect imageRect = [self imageRectForBounds:cellFrame]; |
105 |
| -// // if (NSMouseInRect(point, imageRect, [controlView isFlipped])) { |
106 |
| -// // return NSCellHitContentArea; |
107 |
| -// // } |
108 |
| -// // |
109 |
| -// // // Did we hit the sub title? |
110 |
| -// // NSAttributedString *attributedSubTitle = [self attributedSubTitle]; |
111 |
| -// // if ([attributedSubTitle length] > 0) { |
112 |
| -// // NSRect attributedSubTitleRect = [self rectForSubTitleBasedOnTitleRect:titleRect inBounds:cellFrame]; |
113 |
| -// // if (NSMouseInRect(point, attributedSubTitleRect, [controlView isFlipped])) { |
114 |
| -// // // Notice that this text isn't an editable area. Clicking on it won't begin an editing session. |
115 |
| -// // return NSCellHitContentArea; |
116 |
| -// // } |
117 |
| -// // } |
118 |
| -// |
119 |
| -// // How about the info button? |
120 |
| -// NSRect infoButtonRect = [self infoButtonRectForBounds:cellFrame]; |
121 |
| -// if (NSMouseInRect(point, infoButtonRect, [controlView isFlipped])) { |
122 |
| -// return NSCellHitContentArea | NSCellHitTrackableArea; |
123 |
| -// } |
124 |
| -// } |
125 |
| -// |
126 |
| -// return [super hitTestForEvent:event inRect:cellFrame ofView:controlView]; |
127 |
| -//} |
128 |
| - |
129 |
| -//+ (BOOL)prefersTrackingUntilMouseUp { |
130 |
| -// // NSCell returns NO for this by default. If you want to have trackMouse:inRect:ofView:untilMouseUp: always track until the mouse is up, then you MUST return YES. Otherwise, strange things will happen. |
131 |
| -// return YES; |
132 |
| -//} |
133 |
| - |
134 | 96 | // Mouse tracking -- the only part we want to track is the "info" button
|
135 | 97 | - (BOOL)trackMouse:(NSEvent *)theEvent inRect:(NSRect)cellFrame ofView:(NSView *)controlView untilMouseUp:(BOOL)flag {
|
136 |
| -// [self setControlView:controlView]; |
137 |
| -// |
138 |
| - NSRect infoButtonRect = [self infoButtonRectForBounds:cellFrame]; |
139 |
| - if ([theEvent type] != NSLeftMouseUp) { |
140 |
| - // This is VERY simple event tracking. We simply check to see if the mouse is in the "i" button or not and dispatch entered/exited mouse events |
141 |
| - NSPoint point = [controlView convertPoint:[theEvent locationInWindow] fromView:nil]; |
142 |
| - BOOL mouseInButton = NSMouseInRect(point, infoButtonRect, [controlView isFlipped]); |
143 |
| - if (iMouseDownInInfoButton != mouseInButton) { |
144 |
| - iMouseDownInInfoButton = mouseInButton; |
145 |
| - [controlView setNeedsDisplayInRect:cellFrame]; |
146 |
| - } |
147 |
| - if ([theEvent type] == NSMouseEntered || [theEvent type] == NSMouseExited) { |
148 |
| - [NSApp sendEvent:theEvent]; |
149 |
| - } |
150 |
| - // Note that we process mouse entered and exited events and dispatch them to properly handle updates |
151 |
| - theEvent = [[controlView window] nextEventMatchingMask:(NSLeftMouseUpMask | NSLeftMouseDraggedMask | NSMouseEnteredMask | NSMouseExitedMask)]; |
152 |
| - } |
153 |
| - |
154 |
| - // Another way of implementing the above code would be to keep an NSButtonCell as an ivar, and simply call trackMouse:inRect:ofView:untilMouseUp: on it, if the tracking area was inside of it. |
155 |
| - |
156 | 98 | NSPoint locationOfTouch = [controlView convertPoint:[theEvent locationInWindow] fromView:nil];
|
157 | 99 |
|
158 | 100 | BOOL mouseInButton = NSMouseInRect(locationOfTouch, [self infoButtonRectForBounds:cellFrame], [controlView isFlipped]);
|
159 | 101 | if (mouseInButton) {
|
| 102 | + [self mouseEntered:theEvent]; |
160 | 103 | // show menu
|
161 | 104 | NSMenu *menu = [self menuForEvent:theEvent inRect:cellFrame ofView:controlView];
|
162 | 105 | if (menu){
|
163 | 106 | [NSMenu popUpContextMenu:menu withEvent:theEvent forView:controlView];
|
| 107 | + return YES; |
164 | 108 | }
|
165 | 109 | }
|
166 | 110 |
|
167 |
| - if (iMouseDownInInfoButton) { |
168 |
| - // Send the action, and redisplay |
169 |
| - iMouseDownInInfoButton = NO; |
170 |
| - [controlView setNeedsDisplayInRect:cellFrame]; |
171 |
| - } |
| 111 | + if (iMouseDownInInfoButton) { |
| 112 | + // Send the action, and redisplay |
| 113 | + iMouseDownInInfoButton = NO; |
| 114 | + [controlView setNeedsDisplayInRect:cellFrame]; |
| 115 | + } |
172 | 116 |
|
173 | 117 | return [super trackMouse:theEvent inRect:cellFrame ofView:controlView untilMouseUp:flag];
|
174 |
| - |
175 |
| - |
176 |
| -// |
177 |
| -// // We return YES since the mouse was released while we were tracking. Not returning YES when you processed the mouse up is an easy way to introduce bugs! |
178 |
| -// return YES; |
179 | 118 | }
|
180 | 119 |
|
181 | 120 |
|
|
0 commit comments