Adding Kent's ITTabView class to the ITKit. Please add this class to ITKitTester.
[ITKit.git] / ITTabView.m
1 #import "ITTabView.h"
2
3 @implementation ITTabView
4
5 - (id)initWithFrame:(NSRect)frame
6 {
7     if ( (self = [super initWithFrame:frame]) ) {
8         _draggedTab = nil;
9     }
10     return self;
11 }
12
13 - (void)mouseDown:(NSEvent *)event
14 {
15     NSPoint clickedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
16     NSTabViewItem *clickedTab = [self tabViewItemAtPoint:clickedPoint];
17     _draggedTab = clickedTab;
18     [super mouseDown:event];
19 }
20
21 - (void)mouseUp:(NSEvent *)event
22 {
23     NSPoint releasedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
24     NSTabViewItem *releasedTab = [self tabViewItemAtPoint:releasedPoint];
25     if (releasedTab && ![releasedTab isEqualTo:_draggedTab]) {
26         int releasedTabIndex = [self indexOfTabViewItem:releasedTab];
27         [_draggedTab retain];
28         [self removeTabViewItem:_draggedTab];
29         [self insertTabViewItem:_draggedTab atIndex:releasedTabIndex];
30         [self selectTabViewItem:_draggedTab];
31     }
32     _draggedTab = nil;
33     [super mouseUp:event];
34 }
35
36 - (void)mouseDragged:(NSEvent *)event
37 {
38     NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
39     NSTabViewItem *curTab = [self tabViewItemAtPoint:currentPoint];
40     if (curTab && ![curTab isEqualTo:_draggedTab]) {
41         int curTabIndex = [self indexOfTabViewItem:curTab];
42         [_draggedTab retain];
43         [self removeTabViewItem:_draggedTab];
44         [self insertTabViewItem:_draggedTab atIndex:curTabIndex];
45         [self selectTabViewItem:_draggedTab];
46     }
47     [super mouseDragged:event];
48 }
49
50 @end