blob: ca1b9af6d068206edde98eb10089b1ed6068bd02 [file] [log] [blame]
Olivier Soldanod4311552017-11-20 15:09:53 -05001/*
2 * Copyright (C) 2015-2016 Savoir-faire Linux Inc.
3 * 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.
18 */
19
20#import "RingTableView.h"
21
22#import "HoverTableRowView.h" // For the grid drawing shared code
23
24@implementation RingTableView
25
26- (NSMenu*)menuForEvent:(NSEvent*)evt
27{
28 // TODO : Reimplement without outlineView itemAtRow: method
Kateryna Kostiukd51a3252018-04-04 09:20:37 -040029 NSPoint pt = [self convertPoint:[evt locationInWindow] fromView:nil];
30 int rowIdx = [self rowAtPoint:pt];
31 if (self.contextMenuDelegate && rowIdx >= 0) {
32 return [self.contextMenuDelegate contextualMenuForRow:rowIdx];
33 }
Olivier Soldanod4311552017-11-20 15:09:53 -050034 return nil;
35}
36
37- (void)keyDown:(NSEvent *)theEvent
38{
39 // Handle the Tab key
40 if ([[theEvent characters] characterAtIndex:0] == NSTabCharacter) {
41 if (([theEvent modifierFlags] & NSShiftKeyMask) != NSShiftKeyMask) {
42 [[self window] selectKeyViewFollowingView:self];
43 } else {
44 [[self window] selectKeyViewPrecedingView:self];
45 }
46 }
47 else if (([theEvent modifierFlags] & NSCommandKeyMask) == NSCommandKeyMask) {
48 if (self.shortcutsDelegate) {
49 if ([[theEvent characters] characterAtIndex:0] == 'a') {
50 [self.shortcutsDelegate onAddShortcut];
51 }
52 }
53 } else
54 [super keyDown:theEvent];
55}
56
57- (CGFloat)yPositionPastLastRow {
58 // Only draw the grid past the last visible row
59 NSInteger numberOfRows = self.numberOfRows;
60 CGFloat yStart = 0;
61 if (numberOfRows > 0) {
62 yStart = NSMaxY([self rectOfRow:numberOfRows - 1]);
63 }
64 return yStart;
65}
66
67- (void)drawGridInClipRect:(NSRect)clipRect {
68 // Only draw the grid past the last visible row
69 CGFloat yStart = [self yPositionPastLastRow];
70 // Draw the first separator one row past the last row
71 yStart += self.rowHeight;
72
73 // One thing to do is smarter clip testing to see if we actually need to draw!
74 NSRect boundsToDraw = self.bounds;
75 NSRect separatorRect = boundsToDraw;
76 separatorRect.size.height = 1;
77 while (yStart < NSMaxY(boundsToDraw)) {
78 separatorRect.origin.y = yStart;
79 DrawSeparatorInRect(separatorRect);
80 yStart += self.rowHeight;
81 }
82}
83
84- (void)setFrameSize:(NSSize)size {
85 [super setFrameSize:size];
86 // We need to invalidate more things when live-resizing since we fill with a gradient and stroke
87 if ([self inLiveResize]) {
88 CGFloat yStart = [self yPositionPastLastRow];
89 if (NSHeight(self.bounds) > yStart) {
90 // Redraw our horizontal grid lines
91 NSRect boundsPastY = self.bounds;
92 boundsPastY.size.height -= yStart;
93 boundsPastY.origin.y = yStart;
94 [self setNeedsDisplayInRect:boundsPastY];
95 }
96 }
97}
98
99@end