Forum Navigation
Forum breadcrumbs - You are here:WeLoveGod RallysPublic Forums: fbcocoaDragNDrop
You need to log in to create posts and topics.

DragNDrop

Posted by: fbcocoa.bw <fbcocoa.bw@...>

SVV wrote:


 a special view is not used to mark a 'drop' on the window; instead the background color of the window is changed so that there is visual confirmation

Nice.
Below is one way to implement Steve's idea with an FB window. Thanks Steve.
'---------------
include "Tlbx HIView.incl"
include "FBLog.incl"
BeginCDeclaration
typedef void (*DragDropWindowCallbackType)(CFArrayRef,void*);
@interface DragDropWindow : NSObject <NSWindowDelegate> {
     WindowRef wndRef;
     ThemeBrush enterTheme;
     ThemeBrush exitTheme;
     DragDropWindowCallbackType _callback;
     void *userData;
     BOOL dragInside;
}
@end
void MakeWindowDragDrop( WindowRef w, ThemeBrush enterTheme, ThemeBrush exitTheme, void *callback, void *userData );
EndC
BeginCFunction
static DragDropWindow *sDragDropWindow;
@implementation DragDropWindow
- (DragDropWindow *)initWithWindowRef:(WindowRef)wnd enterTheme:(ThemeBrush)enTheme exitTheme:(ThemeBrush)exTheme callback:(void *)callback userData:(void *)ud {
     self = [super init];
     wndRef = wnd;
     enterTheme = enTheme;
     exitTheme = exTheme;
     _callback = callback;
     userData = ud;
     NSWindow *window = [[NSWindow alloc] initWithWindowRef:wnd];
     [window registerForDraggedTypes:[NSArray arrayWithObjects:NSFilenamesPboardType, nil]];
     [window setDelegate:self];
     return self;
}
- (NSDragOperation)draggingEntered:(id < NSDraggingInfo >)sender {
     NSPasteboard *pboard = [sender draggingPasteboard];
     if ( [[pboard types] containsObject:NSFilenamesPboardType] ) {
          dragInside = YES;
          SetThemeWindowBackground( wndRef, enterTheme, true );
          return NSDragOperationLink;
     }
     return NSDragOperationNone;
}
- (void)draggingExited:(id < NSDraggingInfo >)sender {
     dragInside = NO;
     SetThemeWindowBackground( wndRef, exitTheme, true );
}
- (BOOL)performDragOperation:(id < NSDraggingInfo >)sender {
     NSPasteboard *pboard = [sender draggingPasteboard];
     if ([[pboard types] containsObject:NSFilenamesPboardType]) {
          NSArray *files = [pboard propertyListForType:NSFilenamesPboardType];
          if ( _callback != nil ) (*_callback)( (CFArrayRef)files, userData );
          [self draggingExited:sender];
          return YES;
     }
     return NO;
}
@end
void MakeWindowDragDrop( WindowRef wRef, ThemeBrush enterTheme, ThemeBrush exitTheme, void *callback, void *userData )
{ sDragDropWindow = [[DragDropWindow alloc] initWithWindowRef:wRef enterTheme:enterTheme exitTheme:exitTheme callback:callback userData:userData]; }
EndC
toolbox MakeWindowDragDrop( WindowRef w, ThemeBrush enterTheme, ThemeBrush exitTheme, ptr callback, ptr userData )
local fn MyDragDropWindowCallback( array as CFArrayRef, userData as ptr )
'~'1
FBLog( @"%@", array )// do something with array of file paths
end fn
local fn BuildWindow
'~'1
appearance window 1, "DragDrop", (0,0)-(300,250), _kDocumentWindowClass
fn SetWindowBackground( _kThemeActiveDialogBackgroundBrush, _zTrue )
MakeWindowDragDrop( window( _wndRef ), _kThemeBrushWhite, _kThemeActiveDialogBackgroundBrush, @fn MyDragDropWindowCallback, NULL )
end fn
fn BuildWindow()
RunApplicationEventLoop()
'---------------


To unsubscribe, e-mail: fbcocoa-unsubscribe@welovegod.org For additional commands, e-mail: fbcocoa-help@freegroups.net