forked from mattball/mbtablegrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MBTableGridContentView.m
633 lines (504 loc) · 19.2 KB
/
MBTableGridContentView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
/*
Copyright (c) 2008 Matthew Ball - http://www.mattballdesign.com
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
*/
#import "MBTableGridContentView.h"
#import "MBTableGrid.h"
#import "MBTableGridCell.h"
@interface MBTableGrid (Private)
- (id)_objectValueForColumn:(NSUInteger)columnIndex row:(NSUInteger)rowIndex;
- (void)_setObjectValue:(id)value forColumn:(NSUInteger)columnIndex row:(NSUInteger)rowIndex;
- (BOOL)_canEditCellAtColumn:(NSUInteger)columnIndex row:(NSUInteger)rowIndex;
- (void)_setStickyColumn:(MBTableGridEdge)stickyColumn row:(MBTableGridEdge)stickyRow;
- (MBTableGridEdge)_stickyColumn;
- (MBTableGridEdge)_stickyRow;
@end
@interface MBTableGridContentView (Cursors)
- (NSCursor *)_cellSelectionCursor;
- (NSImage *)_cellSelectionCursorImage;
@end
@interface MBTableGridContentView (DragAndDrop)
- (void)_setDraggingColumnOrRow:(BOOL)flag;
- (void)_setDropColumn:(NSInteger)columnIndex;
- (void)_setDropRow:(NSInteger)rowIndex;
- (void)_timerAutoscrollCallback:(NSTimer *)aTimer;
@end
@implementation MBTableGridContentView
#pragma mark -
#pragma mark Initialization & Superclass Overrides
- (id)initWithFrame:(NSRect)frameRect
{
if(self = [super initWithFrame:frameRect]) {
mouseDownColumn = NSNotFound;
mouseDownRow = NSNotFound;
editedColumn = NSNotFound;
editedRow = NSNotFound;
dropColumn = NSNotFound;
dropRow = NSNotFound;
// Cache the cursor image
cursorImage = [[self _cellSelectionCursorImage] retain];
isDraggingColumnOrRow = NO;
_cell = [[MBTableGridCell alloc] initTextCell:@""];
[_cell setBezeled:YES];
[_cell setScrollable:YES];
[_cell setLineBreakMode:NSLineBreakByTruncatingTail];
}
return self;
}
- (void)dealloc
{
[_cell release];
[cursorImage release];
[super dealloc];
}
- (void)drawRect:(NSRect)rect
{
NSUInteger numberOfColumns = [[self tableGrid] numberOfColumns];
NSUInteger numberOfRows = [[self tableGrid] numberOfRows];
NSUInteger firstColumn = NSNotFound;
NSUInteger lastColumn = numberOfColumns - 1;
NSUInteger firstRow = NSNotFound;
NSUInteger lastRow = numberOfRows - 1;
// Find the columns to draw
NSUInteger column = 0;
while (column < numberOfColumns) {
NSRect columnRect = [self rectOfColumn:column];
if (firstColumn == NSNotFound && NSMinX([self visibleRect]) >= NSMinX(columnRect) && NSMinX([self visibleRect]) <= NSMaxX(columnRect)) {
firstColumn = column;
} else if (firstColumn != NSNotFound && NSMaxX([self visibleRect]) >= NSMinX(columnRect) && NSMaxX([self visibleRect]) <= NSMaxX(columnRect)) {
lastColumn = column;
break;
}
column++;
}
// Find the rows to draw
NSUInteger row = 0;
while (row < numberOfRows) {
NSRect rowRect = [self rectOfRow:row];
if (firstRow == NSNotFound && NSMinY([self visibleRect]) >= rowRect.origin.x && NSMinY([self visibleRect]) <= NSMaxY(rowRect)) {
firstRow = row;
} else if (firstRow != NSNotFound && NSMaxY([self visibleRect]) >= NSMinY(rowRect) && NSMaxY([self visibleRect]) <= NSMaxY(rowRect)) {
lastRow = row;
break;
}
row++;
}
column = firstColumn;
while (column <= lastColumn) {
row = firstRow;
while (row <= lastRow) {
NSRect cellFrame = [self frameOfCellAtColumn:column row:row];
// Only draw the cell if we need to
if ([self needsToDrawRect:cellFrame]) {
[_cell setObjectValue:[[self tableGrid] _objectValueForColumn:column row:row]];
[_cell drawWithFrame:cellFrame inView:self];
}
row++;
}
column++;
}
// Draw the selection rectangle
NSIndexSet *selectedColumns = [[self tableGrid] selectedColumnIndexes];
NSIndexSet *selectedRows = [[self tableGrid] selectedRowIndexes];
if([selectedColumns count] && [selectedRows count] && [[self tableGrid] numberOfColumns] > 0 && [[self tableGrid] numberOfRows] > 0) {
NSRect selectionTopLeft = [self frameOfCellAtColumn:[selectedColumns firstIndex] row:[selectedRows firstIndex]];
NSRect selectionBottomRight = [self frameOfCellAtColumn:[selectedColumns lastIndex] row:[selectedRows lastIndex]];
NSRect selectionRect;
selectionRect.origin = selectionTopLeft.origin;
selectionRect.size.width = NSMaxX(selectionBottomRight)-selectionTopLeft.origin.x;
selectionRect.size.height = NSMaxY(selectionBottomRight)-selectionTopLeft.origin.y;
NSBezierPath *selectionPath = [NSBezierPath bezierPathWithRect:NSInsetRect(selectionRect, 1, 1)];
NSAffineTransform *translate = [NSAffineTransform transform];
[translate translateXBy:-0.5 yBy:-0.5];
[selectionPath transformUsingAffineTransform:translate];
NSColor *selectionColor = [NSColor alternateSelectedControlColor];
// If the view is not the first responder, the use a gray selection color
NSResponder *firstResponder = [[self window] firstResponder];
if (![[firstResponder class] isSubclassOfClass:[NSView class]] || ![(NSView *)firstResponder isDescendantOf:[self tableGrid]] || ![[self window] isKeyWindow]) {
selectionColor = [[selectionColor colorUsingColorSpaceName:NSDeviceWhiteColorSpace] colorUsingColorSpaceName:NSDeviceRGBColorSpace];
}
[selectionColor set];
[selectionPath setLineWidth: 1.0];
[selectionPath stroke];
}
// Draw the column drop indicator
if (isDraggingColumnOrRow && dropColumn != NSNotFound && dropColumn <= [[self tableGrid] numberOfColumns] && dropRow == NSNotFound) {
NSRect columnBorder;
if(dropColumn < [[self tableGrid] numberOfColumns]) {
columnBorder = [self rectOfColumn:dropColumn];
} else {
columnBorder = [self rectOfColumn:dropColumn-1];
columnBorder.origin.x += columnBorder.size.width;
}
columnBorder.origin.x = NSMinX(columnBorder)-2.0;
columnBorder.size.width = 4.0;
NSColor *selectionColor = [NSColor alternateSelectedControlColor];
NSBezierPath *borderPath = [NSBezierPath bezierPathWithRect:columnBorder];
[borderPath setLineWidth:2.0];
[selectionColor set];
[borderPath stroke];
}
// Draw the row drop indicator
if (isDraggingColumnOrRow && dropRow != NSNotFound && dropRow <= [[self tableGrid] numberOfRows] && dropColumn == NSNotFound) {
NSRect rowBorder;
if(dropRow < [[self tableGrid] numberOfRows]) {
rowBorder = [self rectOfRow:dropRow];
} else {
rowBorder = [self rectOfRow:dropRow-1];
rowBorder.origin.y += rowBorder.size.height;
}
rowBorder.origin.y = NSMinY(rowBorder)-2.0;
rowBorder.size.height = 4.0;
NSColor *selectionColor = [NSColor alternateSelectedControlColor];
NSBezierPath *borderPath = [NSBezierPath bezierPathWithRect:rowBorder];
[borderPath setLineWidth:2.0];
[selectionColor set];
[borderPath stroke];
}
// Draw the cell drop indicator
if (!isDraggingColumnOrRow && dropRow != NSNotFound && dropRow <= [[self tableGrid] numberOfRows] && dropColumn != NSNotFound && dropColumn <= [[self tableGrid] numberOfColumns]) {
NSRect cellFrame = [self frameOfCellAtColumn:dropColumn row:dropRow];
cellFrame.origin.x -= 2.0;
cellFrame.origin.y -= 2.0;
cellFrame.size.width += 3.0;
cellFrame.size.height += 3.0;
NSBezierPath *borderPath = [NSBezierPath bezierPathWithRect:NSInsetRect(cellFrame, 2, 2)];
NSColor *dropColor = [NSColor alternateSelectedControlColor];
[dropColor set];
[borderPath setLineWidth:2.0];
[borderPath stroke];
}
}
- (BOOL)isFlipped
{
return YES;
}
- (void)mouseDown:(NSEvent *)theEvent
{
// Setup the timer for autoscrolling
// (the simply calling autoscroll: from mouseDragged: only works as long as the mouse is moving)
autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(_timerAutoscrollCallback:) userInfo:nil repeats:YES];
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
mouseDownColumn = [self columnAtPoint:loc];
mouseDownRow = [self rowAtPoint:loc];
if([theEvent clickCount] == 1) {
// Pass the event back to the MBTableGrid (Used to give First Responder status)
[[self tableGrid] mouseDown:theEvent];
// Single click
if(([theEvent modifierFlags] & NSShiftKeyMask) && [self tableGrid].allowsMultipleSelection) {
// If the shift key was held down, extend the selection
NSUInteger stickyColumn = [[self tableGrid].selectedColumnIndexes firstIndex];
NSUInteger stickyRow = [[self tableGrid].selectedRowIndexes firstIndex];
MBTableGridEdge stickyColumnEdge = [[self tableGrid] _stickyColumn];
MBTableGridEdge stickyRowEdge = [[self tableGrid] _stickyRow];
// Compensate for sticky edges
if (stickyColumnEdge == MBTableGridRightEdge) {
stickyColumn = [[self tableGrid].selectedColumnIndexes lastIndex];
}
if (stickyRowEdge == MBTableGridBottomEdge) {
stickyRow = [[self tableGrid].selectedRowIndexes lastIndex];
}
NSRange selectionColumnRange = NSMakeRange(stickyColumn, mouseDownColumn-stickyColumn+1);
NSRange selectionRowRange = NSMakeRange(stickyRow, mouseDownRow-stickyRow+1);
if (mouseDownColumn < stickyColumn) {
selectionColumnRange = NSMakeRange(mouseDownColumn, stickyColumn-mouseDownColumn+1);
stickyColumnEdge = MBTableGridRightEdge;
} else {
stickyColumnEdge = MBTableGridLeftEdge;
}
if (mouseDownRow < stickyRow) {
selectionRowRange = NSMakeRange(mouseDownRow, stickyRow-mouseDownRow+1);
stickyRowEdge = MBTableGridBottomEdge;
} else {
stickyRowEdge = MBTableGridTopEdge;
}
// Select the proper cells
[self tableGrid].selectedColumnIndexes = [NSIndexSet indexSetWithIndexesInRange:selectionColumnRange];
[self tableGrid].selectedRowIndexes = [NSIndexSet indexSetWithIndexesInRange:selectionRowRange];
// Set the sticky edges
[[self tableGrid] _setStickyColumn:stickyColumnEdge row:stickyRowEdge];
} else {
// No modifier keys, so change the selection
[self tableGrid].selectedColumnIndexes = [NSIndexSet indexSetWithIndex:mouseDownColumn];
[self tableGrid].selectedRowIndexes = [NSIndexSet indexSetWithIndex:mouseDownRow];
[[self tableGrid] _setStickyColumn:MBTableGridLeftEdge row:MBTableGridTopEdge];
}
} else if([theEvent clickCount] == 2) {
// Double click
[self editSelectedCell:self];
}
}
- (void)mouseDragged:(NSEvent *)theEvent
{
if (mouseDownColumn != NSNotFound && mouseDownRow != NSNotFound && [self tableGrid].allowsMultipleSelection) {
NSPoint loc = [self convertPoint:[theEvent locationInWindow] fromView:nil];
NSInteger column = [self columnAtPoint:loc];
NSInteger row = [self rowAtPoint:loc];
MBTableGridEdge columnEdge = MBTableGridLeftEdge;
MBTableGridEdge rowEdge = MBTableGridTopEdge;
// Select the appropriate number of columns
if(column != NSNotFound) {
NSInteger firstColumnToSelect = mouseDownColumn;
NSInteger numberOfColumnsToSelect = column-mouseDownColumn+1;
if(column < mouseDownColumn) {
firstColumnToSelect = column;
numberOfColumnsToSelect = mouseDownColumn-column+1;
// Set the sticky edge to the right
columnEdge = MBTableGridRightEdge;
}
[self tableGrid].selectedColumnIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(firstColumnToSelect,numberOfColumnsToSelect)];
}
// Select the appropriate number of rows
if(row != NSNotFound) {
NSInteger firstRowToSelect = mouseDownRow;
NSInteger numberOfRowsToSelect = row-mouseDownRow+1;
if(row < mouseDownRow) {
firstRowToSelect = row;
numberOfRowsToSelect = mouseDownRow-row+1;
// Set the sticky row to the bottom
rowEdge = MBTableGridBottomEdge;
}
[self tableGrid].selectedRowIndexes = [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(firstRowToSelect,numberOfRowsToSelect)];
}
// Set the sticky edges
[[self tableGrid] _setStickyColumn:columnEdge row:rowEdge];
}
// [self autoscroll:theEvent];
}
- (void)mouseUp:(NSEvent *)theEvent
{
[autoscrollTimer invalidate];
autoscrollTimer = nil;
mouseDownColumn = NSNotFound;
mouseDownRow = NSNotFound;
}
#pragma mark Cursor Rects
- (void)resetCursorRects
{
// The main cursor should be the cell selection cursor
[self addCursorRect:[self visibleRect] cursor:[self _cellSelectionCursor]];
}
#pragma mark -
#pragma mark Notifications
#pragma mark Field Editor
- (void)textDidEndEditing:(NSNotification *)aNotification
{
// Give focus back to the table grid (the field editor took it)
[[self window] makeFirstResponder:[self tableGrid]];
NSString *value = [[[aNotification object] string] copy];
[[self tableGrid] _setObjectValue:value forColumn:editedColumn row:editedRow];
editedColumn = NSNotFound;
editedRow = NSNotFound;
// End the editing session
[[[self tableGrid] cell] endEditing:[[self window] fieldEditor:NO forObject:self]];
}
#pragma mark -
#pragma mark Protocol Methods
#pragma mark NSDraggingDestination
/*
* These methods simply pass the drag event back to the table grid.
* They are only required for autoscrolling.
*/
- (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
{
// Setup the timer for autoscrolling
// (the simply calling autoscroll: from mouseDragged: only works as long as the mouse is moving)
autoscrollTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(_timerAutoscrollCallback:) userInfo:nil repeats:YES];
return [[self tableGrid] draggingEntered:sender];
}
- (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
{
return [[self tableGrid] draggingUpdated:sender];
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
[autoscrollTimer invalidate];
autoscrollTimer = nil;
[[self tableGrid] draggingExited:sender];
}
- (void)draggingEnded:(id <NSDraggingInfo>)sender
{
[[self tableGrid] draggingEnded:sender];
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return [[self tableGrid] prepareForDragOperation:sender];
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
return [[self tableGrid] performDragOperation:sender];
}
- (void)concludeDragOperation:(id <NSDraggingInfo>)sender
{
[[self tableGrid] concludeDragOperation:sender];
}
#pragma mark -
#pragma mark Subclass Methods
- (MBTableGrid *)tableGrid
{
return (MBTableGrid *)[[self enclosingScrollView] superview];
}
- (void)editSelectedCell:(id)sender
{
// Get the top-left selection
editedColumn = [[self tableGrid].selectedColumnIndexes firstIndex];
editedRow = [[self tableGrid].selectedRowIndexes firstIndex];
// Check if the cell can be edited
if(![[self tableGrid] _canEditCellAtColumn:editedColumn row:editedRow]) {
editedColumn = NSNotFound;
editedRow = NSNotFound;
return;
}
// Select it and only it
if([[self tableGrid].selectedColumnIndexes count] > 1) {
[self tableGrid].selectedColumnIndexes = [NSIndexSet indexSetWithIndex:editedColumn];
}
if([[self tableGrid].selectedRowIndexes count] > 1) {
[self tableGrid].selectedRowIndexes = [NSIndexSet indexSetWithIndex:editedRow];
}
NSTextFieldCell *cell = [[self tableGrid] cell];
[cell setEditable:YES];
[cell setSelectable:YES];
[cell setObjectValue:[[self tableGrid] _objectValueForColumn:editedColumn row:editedRow]];
NSRect cellFrame = [self frameOfCellAtColumn:editedColumn row:editedRow];
NSText *editor = [[self window] fieldEditor:YES forObject:self];
[cell editWithFrame:cellFrame inView:self editor:editor delegate:self event:nil];
}
#pragma mark Layout Support
- (NSRect)rectOfColumn:(NSUInteger)columnIndex
{
NSRect rect = NSMakeRect(0, 0, 60, [self frame].size.height);
//rect.origin.x += 60.0 * columnIndex;
NSUInteger i = 0;
while(i < columnIndex) {
float headerWidth = rect.size.width;
rect.origin.x += headerWidth;
i++;
}
return rect;
}
- (NSRect)rectOfRow:(NSUInteger)rowIndex
{
float heightForRow = 20.0;
NSRect rect = NSMakeRect(0, 0, [self frame].size.width, heightForRow);
rect.origin.y += 20.0 * rowIndex;
/*NSUInteger i = 0;
while(i < rowIndex) {
float rowHeight = rect.size.height;
rect.origin.y += rowHeight;
i++;
}*/
return rect;
}
- (NSRect)frameOfCellAtColumn:(NSUInteger)columnIndex row:(NSUInteger)rowIndex
{
NSRect columnRect = [self rectOfColumn:columnIndex];
NSRect rowRect = [self rectOfRow:rowIndex];
return NSMakeRect(columnRect.origin.x, rowRect.origin.y, columnRect.size.width, rowRect.size.height);
}
- (NSInteger)columnAtPoint:(NSPoint)aPoint
{
NSInteger column = 0;
while(column < [[self tableGrid] numberOfColumns]) {
NSRect columnFrame = [self rectOfColumn:column];
if(NSPointInRect(aPoint, columnFrame)) {
return column;
}
column++;
}
return NSNotFound;
}
- (NSInteger)rowAtPoint:(NSPoint)aPoint
{
NSInteger row = 0;
while(row < [[self tableGrid] numberOfRows]) {
NSRect rowFrame = [self rectOfRow:row];
if(NSPointInRect(aPoint, rowFrame)) {
return row;
}
row++;
}
return NSNotFound;
}
@end
@implementation MBTableGridContentView (Cursors)
- (NSCursor *)_cellSelectionCursor
{
NSCursor *cursor = [[NSCursor alloc] initWithImage:cursorImage hotSpot:NSMakePoint(8, 8)];
return [cursor autorelease];
}
/**
* @warning This method is not as efficient as it could be, but
* it should only be called once, at initialization.
* TODO: Make it faster
*/
- (NSImage *)_cellSelectionCursorImage
{
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(20, 20)];
[image setFlipped:YES];
[image lockFocus];
NSRect horizontalInner = NSMakeRect(7.0, 2.0, 2.0, 12.0);
NSRect verticalInner = NSMakeRect(2.0, 7.0, 12.0, 2.0);
NSRect horizontalOuter = NSInsetRect(horizontalInner, -1.0, -1.0);
NSRect verticalOuter = NSInsetRect(verticalInner, -1.0, -1.0);
// Set the shadow
NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowColor:[NSColor colorWithDeviceWhite:0.0 alpha:0.8]];
[shadow setShadowBlurRadius:2.0];
[shadow setShadowOffset:NSMakeSize(0, -1.0)];
[[NSGraphicsContext currentContext] saveGraphicsState];
[shadow set];
[[NSColor blackColor] set];
NSRectFill(horizontalOuter);
NSRectFill(verticalOuter);
[[NSGraphicsContext currentContext] restoreGraphicsState];
[shadow release];
// Fill them again to compensate for the shadows
NSRectFill(horizontalOuter);
NSRectFill(verticalOuter);
[[NSColor whiteColor] set];
NSRectFill(horizontalInner);
NSRectFill(verticalInner);
[image unlockFocus];
return [image autorelease];
}
@end
@implementation MBTableGridContentView (DragAndDrop)
- (void)_setDraggingColumnOrRow:(BOOL)flag
{
isDraggingColumnOrRow = flag;
}
- (void)_setDropColumn:(NSInteger)columnIndex
{
dropColumn = columnIndex;
[self setNeedsDisplay:YES];
}
- (void)_setDropRow:(NSInteger)rowIndex
{
dropRow = rowIndex;
[self setNeedsDisplay:YES];
}
- (void)_timerAutoscrollCallback:(NSTimer *)aTimer
{
NSEvent* event = [NSApp currentEvent];
if ([event type] == NSLeftMouseDragged )
[self autoscroll:event];
}
@end