You need to log in to create posts and topics.
DragNDrop
1,678 Posts
#1 · May 19, 2013, 5:54 am
Quote from Forum Archives on May 19, 2013, 5:54 amPosted 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"BeginCDeclarationtypedef void (*DragDropWindowCallbackType)(CFArrayRef,void*);@interface DragDropWindow : NSObject <NSWindowDelegate> {WindowRef wndRef;ThemeBrush enterTheme;ThemeBrush exitTheme;DragDropWindowCallbackType _callback;void *userData;BOOL dragInside;}@endvoid MakeWindowDragDrop( WindowRef w, ThemeBrush enterTheme, ThemeBrush exitTheme, void *callback, void *userData );EndCBeginCFunctionstatic 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;}@endvoid MakeWindowDragDrop( WindowRef wRef, ThemeBrush enterTheme, ThemeBrush exitTheme, void *callback, void *userData ){ sDragDropWindow = [[DragDropWindow alloc] initWithWindowRef:wRef enterTheme:enterTheme exitTheme:exitTheme callback:callback userData:userData]; }EndCtoolbox MakeWindowDragDrop( WindowRef w, ThemeBrush enterTheme, ThemeBrush exitTheme, ptr callback, ptr userData )local fn MyDragDropWindowCallback( array as CFArrayRef, userData as ptr )'~'1FBLog( @"%@", array )// do something with array of file pathsend fnlocal fn BuildWindow'~'1appearance window 1, "DragDrop", (0,0)-(300,250), _kDocumentWindowClassfn SetWindowBackground( _kThemeActiveDialogBackgroundBrush, _zTrue )MakeWindowDragDrop( window( _wndRef ), _kThemeBrushWhite, _kThemeActiveDialogBackgroundBrush, @fn MyDragDropWindowCallback, NULL )end fnfn BuildWindow()RunApplicationEventLoop()'---------------
To unsubscribe, e-mail: fbcocoa-unsubscribe@welovegod.org For additional commands, e-mail: fbcocoa-help@freegroups.net
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
Click for thumbs down.0Click for thumbs up.0