3 @interface NSTabViewItem (ITTabViewHacks)
7 @implementation ITTabView
9 - (id)initWithFrame:(NSRect)frame {
10 if ((self = [super initWithFrame:frame])) {
13 _requiredModifiers = NSCommandKeyMask;
18 - (void)setAllowsDragging:(BOOL)flag {
19 _allowsDragging = flag;
22 - (BOOL)allowsDragging {
23 return _allowsDragging;
26 - (void)setRequiredModifiers:(unsigned int)modifiers {
27 _requiredModifiers = modifiers;
30 - (unsigned int)requiredModifiers {
31 return _requiredModifiers;
34 - (void)moveTab:(NSTabViewItem *)tab toIndex:(int)index {
35 int oldIndex = [self indexOfTabViewItem:tab];
36 if ((oldIndex != NSNotFound) && (oldIndex != index)) {
38 [self removeTabViewItem:tab];
39 [self insertTabViewItem:tab atIndex:index];
40 [self selectTabViewItem:tab];
45 - (void)mouseDown:(NSEvent *)event {
46 if ((_requiredModifiers == 0 || ([[NSApp currentEvent] modifierFlags] & _requiredModifiers)) && [self allowsDragging]) {
48 clickedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
49 NSTabViewItem *clickedTab = [self tabViewItemAtPoint:clickedPoint];
50 _draggedTab = clickedTab;
52 [super mouseDown:event];
55 - (void)mouseUp:(NSEvent *)event {
56 if (_draggedTab && [self allowsDragging]) {
57 NSPoint releasedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
58 NSTabViewItem *releasedTab = [self tabViewItemAtPoint:releasedPoint];
59 if (releasedTab && ![releasedTab isEqualTo:_draggedTab]) {
60 [self moveTab:_draggedTab toIndex:[self indexOfTabViewItem:releasedTab]];
64 [super mouseUp:event];
67 - (void)mouseDragged:(NSEvent *)event {
68 if (_draggedTab && [self allowsDragging]) {
69 NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
70 NSTabViewItem *curTab = [self tabViewItemAtPoint:currentPoint];
71 if (curTab && ![curTab isEqualTo:_draggedTab]) {
72 [self moveTab:_draggedTab toIndex:[self indexOfTabViewItem:curTab]];
73 [self selectTabViewItem:_draggedTab];
76 [super mouseDragged:event];