1

ドラッグ可能なNSTabViewItemを提供することは可能ですか、
基本的に私が望むもの、NSTabViewITemのラベルのLボタンを押して移動する場合、TabViewアイテムをドラッグできるようにする必要があります、NSTabViewアイテムの移動のためにそれを行い、もう1つの機能があります、ユーザーがNSTabViewアイテムのラベルをドラッグして特定の領域に移動した場合、そのNSTabViewアイテムを削除できるようにする必要があります。

PSMTabバーを使用する方法は1つしか見つかりませんでしたが、NSTabViewアイテムにも他の機能があり、その方法を使用すると失われます。

4

1 に答える 1

1

調べてくれてありがとう、何とか私はそれを行うことができました....いくつかの重要なコードを投稿しています...

1 -- マウス イベントを処理するためのカスタム TabView クラスが必要です。

// 以下に掲載されているインターフェース、

#import <Cocoa/Cocoa.h>


typedef enum __itemDragState{
    itemNotDragging = 0,
    itemDragStatNormal = 0,
    itemDragging    = 1,
    itemDropped     = 2
} ItemDragStat;

@protocol CustomTabViewDelegate <NSObject>

@required
-(bool)allowDrag;
-(bool)allowDrop;
-(void)dragEnter;
-(void)acceptDrop;
-(void)draggingCancelled;
-(void)itemDropped:(id)draggedTabViewItem;
-(void)itemDroppedCompleted:(id)droppedTabViewItem;
@end

@interface CustomTab : NSTabView{
    ItemDragStat eItemDragStat; 
    id draggedItem;
}

@property(assign)id draggedItem;
@end

今重要な実装のいくつか

#import "CustomTab.h"
#include "Log.h"

@implementation CustomTab

@synthesize draggedItem;

- (id)initWithFrame:(NSRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code here.
    }

    return self;
}

# if 0
// don't delete it, might need later on
- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
}
# endif
- (void)mouseUp:(NSEvent *)theEvent{
    log(" Mouse up ");


    NSPoint location = [self convertPoint: [theEvent locationInWindow]
                                 fromView: nil];



    NSTabViewItem *anItem = [self tabViewItemAtPoint: location];

    if ( anItem == nil ) {
        // if its mouse up else where, reject dragging regardless
        eItemDragStat = itemDragStatNormal;
        log("Item will not be dropped");
        return;
    }

    if ( ![anItem isEqual:[self selectedTabViewItem]]){
        log("Mouse up is in nonselected item");

        if ( eItemDragStat == itemDragging){
            log("Item will be dropped into this ");


            id droppedTabViewItem = anItem;

            if ( droppedTabViewItem && [droppedTabViewItem respondsToSelector:@selector(itemDropped:)]){

                id selectedTabViewItem = [self selectedTabViewItem];

                [droppedTabViewItem performSelector:@selector(itemDropped:) withObject:selectedTabViewItem];

            }
        }
    }
    eItemDragStat = itemDragStatNormal;
    //   return;

    //    [super mouseUp:theEvent];
}
- (void)mouseDown:(NSEvent *)theEvent{

    NSPoint location = [self convertPoint: [theEvent locationInWindow]
                                 fromView: nil];

    draggedItem = [self tabViewItemAtPoint:location];

    NSTabViewItem *anItem = [self tabViewItemAtPoint: location];

    if (anItem != nil  &&  ![anItem isEqual: [self selectedTabViewItem]])
    {
        [self selectTabViewItem: anItem];
    }


}

- (void)mouseDragged:(NSEvent *)theEvent{

    NSPoint location = [self convertPoint: [theEvent locationInWindow]
                                 fromView: nil];


    id tabViewItemId = [self tabViewItemAtPoint:location];

    NSTabViewItem *anItem = [self tabViewItemAtPoint: location];

    if (anItem){
        if (![anItem isEqual:draggedItem]){

            if (tabViewItemId && [tabViewItemId respondsToSelector:@selector(allowDrag)]){
                eItemDragStat = itemDragging;

            }else{
                // drag will be cancelled now.
                // tell client item to stop dragging
                if (eItemDragStat == itemDragging){
                    if ( draggedItem && [ draggedItem respondsToSelector:@selector(draggingCancelled)]){

                        [draggedItem performSelector:@selector(draggingCancelled)];
                        draggedItem = nil;
                    }
                    }
                eItemDragStat = itemNotDragging;
                // if we have +cursor then it should be reset
            }

        }else{
           log(" Mouse dragged");
        }
    }else{
        // dragging went elsewhere, lets close this dragging operation
        if ( draggedItem && [ draggedItem respondsToSelector:@selector(draggingCancelled)]){

            [draggedItem performSelector:@selector(draggingCancelled)];
            draggedItem = nil;
        }
        // here reset the mouse pointer
         eItemDragStat = itemNotDragging;

    }
}

@end

もう少し微調整が必​​要です。

于 2013-02-12T12:03:52.770 に答える