blob: 429a90edba3d0a4b1465c8416c50949416c17aca [file] [log] [blame]
Alexandre Lision2db8f472015-07-22 15:05:46 -04001/*
Alexandre Lision9fe374b2016-01-06 10:17:31 -05002 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
Alexandre Lision2db8f472015-07-22 15:05:46 -04003 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Alexandre Lision2db8f472015-07-22 15:05:46 -040018 */
19
20#import "RingOutlineView.h"
21
Alexandre Lision4e280d62015-09-09 15:56:30 -040022#import "HoverTableRowView.h" // For the grid drawing shared code
23
Alexandre Lision2db8f472015-07-22 15:05:46 -040024@implementation RingOutlineView
25
26- (NSMenu*)menuForEvent:(NSEvent*)evt
27{
28 NSPoint pt = [self convertPoint:[evt locationInWindow] fromView:nil];
29 int rowIdx = [self rowAtPoint:pt];
Alexandre Lision12946a72016-03-08 13:39:34 -050030 if (self.contextMenuDelegate && rowIdx >= 0) {
31 return [self.contextMenuDelegate contextualMenuForIndex:[self itemAtRow:rowIdx]];
Alexandre Lision2db8f472015-07-22 15:05:46 -040032 }
33 return nil;
34}
35
36- (void)keyDown:(NSEvent *)theEvent
37{
38 // Handle the Tab key
39 if ([[theEvent characters] characterAtIndex:0] == NSTabCharacter) {
40 if (([theEvent modifierFlags] & NSShiftKeyMask) != NSShiftKeyMask) {
41 [[self window] selectKeyViewFollowingView:self];
42 } else {
43 [[self window] selectKeyViewPrecedingView:self];
44 }
45 }
46 else if (([theEvent modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask) {
47 if (self.shortcutsDelegate) {
48 if ([[theEvent characters] characterAtIndex:0] == 'a') {
49 [self.shortcutsDelegate onAddShortcut];
50 }
51 }
52 } else
53 [super keyDown:theEvent];
54}
55
Alexandre Lision4e280d62015-09-09 15:56:30 -040056- (CGFloat)yPositionPastLastRow {
57 // Only draw the grid past the last visible row
58 NSInteger numberOfRows = self.numberOfRows;
59 CGFloat yStart = 0;
60 if (numberOfRows > 0) {
61 yStart = NSMaxY([self rectOfRow:numberOfRows - 1]);
62 }
63 return yStart;
64}
65
66- (void)drawGridInClipRect:(NSRect)clipRect {
67 // Only draw the grid past the last visible row
68 CGFloat yStart = [self yPositionPastLastRow];
69 // Draw the first separator one row past the last row
70 yStart += self.rowHeight;
71
72 // One thing to do is smarter clip testing to see if we actually need to draw!
73 NSRect boundsToDraw = self.bounds;
74 NSRect separatorRect = boundsToDraw;
75 separatorRect.size.height = 1;
76 while (yStart < NSMaxY(boundsToDraw)) {
77 separatorRect.origin.y = yStart;
78 DrawSeparatorInRect(separatorRect);
79 yStart += self.rowHeight;
80 }
81}
82
83- (void)setFrameSize:(NSSize)size {
84 [super setFrameSize:size];
85 // We need to invalidate more things when live-resizing since we fill with a gradient and stroke
86 if ([self inLiveResize]) {
87 CGFloat yStart = [self yPositionPastLastRow];
88 if (NSHeight(self.bounds) > yStart) {
89 // Redraw our horizontal grid lines
90 NSRect boundsPastY = self.bounds;
91 boundsPastY.size.height -= yStart;
92 boundsPastY.origin.y = yStart;
93 [self setNeedsDisplayInRect:boundsPastY];
94 }
95 }
96}
97
Alexandre Lision2db8f472015-07-22 15:05:46 -040098@end