3 /*************************************************************************/
5 #pragma mark EVIL HACKERY
6 /*************************************************************************/
8 @interface NSTabViewItem (HACKHACKHACKHACK)
13 @implementation ITTabView
15 - (id)initWithFrame:(NSRect)frame
17 if ( (self = [super initWithFrame:frame]) ) {
20 _requiredModifiers = NSCommandKeyMask;
25 - (void)setAllowsDragging:(bool)flag
27 _allowsDragging = flag;
28 _requiredModifiers = NSCommandKeyMask;
31 - (bool)allowsDragging
33 return _allowsDragging;
36 - (void)setRequiredModifiers:(unsigned int)modifiers
38 _requiredModifiers = modifiers;
41 - (unsigned int)requiredModifiers
43 return _requiredModifiers;
46 - (void)moveTab:(NSTabViewItem *)tab toIndex:(int)index
48 if ([self indexOfTabViewItem:tab] != index)
51 [self removeTabViewItem:tab];
52 [self insertTabViewItem:tab atIndex:index];
53 [self selectTabViewItem:tab];
57 - (void)mouseDown:(NSEvent *)event
59 if ((_requiredModifiers == 0 || ([[NSApp currentEvent] modifierFlags] & _requiredModifiers)) && [self allowsDragging]) {
61 clickedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
62 NSTabViewItem *clickedTab = [self tabViewItemAtPoint:clickedPoint];
63 _draggedTab = clickedTab;
65 [super mouseDown:event];
68 - (void)mouseUp:(NSEvent *)event
70 if (_draggedTab && [self allowsDragging]) {
71 NSPoint releasedPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
72 NSTabViewItem *releasedTab = [self tabViewItemAtPoint:releasedPoint];
73 if (releasedTab && ![releasedTab isEqualTo:_draggedTab]) {
74 [self moveTab:_draggedTab toIndex:[self indexOfTabViewItem:releasedTab]];
78 [super mouseUp:event];
81 - (void)mouseDragged:(NSEvent *)event
83 if (_draggedTab && [self allowsDragging]) {
84 NSPoint currentPoint = [self convertPoint:[event locationInWindow] fromView:[[self window] contentView]];
85 NSTabViewItem *curTab = [self tabViewItemAtPoint:currentPoint];
86 if (curTab && ![curTab isEqualTo:_draggedTab]) {
87 [self moveTab:_draggedTab toIndex:[self indexOfTabViewItem:curTab]];
88 [self selectTabViewItem:_draggedTab];
91 [super mouseDragged:event];