src/video/cocoa/SDL_cocoawindow.m
changeset 9237 2cc90bb31777
parent 9236 a845edf98a80
child 9419 9763f689bced
equal deleted inserted replaced
9236:a845edf98a80 9237:2cc90bb31777
    32 #include "../SDL_sysvideo.h"
    32 #include "../SDL_sysvideo.h"
    33 #include "../../events/SDL_keyboard_c.h"
    33 #include "../../events/SDL_keyboard_c.h"
    34 #include "../../events/SDL_mouse_c.h"
    34 #include "../../events/SDL_mouse_c.h"
    35 #include "../../events/SDL_touch_c.h"
    35 #include "../../events/SDL_touch_c.h"
    36 #include "../../events/SDL_windowevents_c.h"
    36 #include "../../events/SDL_windowevents_c.h"
       
    37 #include "../../events/SDL_dropevents_c.h"
    37 #include "SDL_cocoavideo.h"
    38 #include "SDL_cocoavideo.h"
    38 #include "SDL_cocoashape.h"
    39 #include "SDL_cocoashape.h"
    39 #include "SDL_cocoamouse.h"
    40 #include "SDL_cocoamouse.h"
    40 #include "SDL_cocoaopengl.h"
    41 #include "SDL_cocoaopengl.h"
    41 #include "SDL_assert.h"
    42 #include "SDL_assert.h"
    50 
    51 
    51 
    52 
    52 #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
    53 #define FULLSCREEN_MASK (SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_FULLSCREEN)
    53 
    54 
    54 
    55 
    55 @interface SDLWindow : NSWindow
    56 @interface SDLWindow : NSWindow <NSDraggingDestination>
    56 /* These are needed for borderless/fullscreen windows */
    57 /* These are needed for borderless/fullscreen windows */
    57 - (BOOL)canBecomeKeyWindow;
    58 - (BOOL)canBecomeKeyWindow;
    58 - (BOOL)canBecomeMainWindow;
    59 - (BOOL)canBecomeMainWindow;
    59 - (void)sendEvent:(NSEvent *)event;
    60 - (void)sendEvent:(NSEvent *)event;
    60 - (void)doCommandBySelector:(SEL)aSelector;
    61 - (void)doCommandBySelector:(SEL)aSelector;
       
    62 
       
    63 /* Handle drag-and-drop of files onto the SDL window. */
       
    64 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender;
       
    65 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender;
       
    66 - (BOOL)wantsPeriodicDraggingUpdates;
    61 @end
    67 @end
    62 
    68 
    63 @implementation SDLWindow
    69 @implementation SDLWindow
       
    70 
    64 - (BOOL)canBecomeKeyWindow
    71 - (BOOL)canBecomeKeyWindow
    65 {
    72 {
    66     return YES;
    73     return YES;
    67 }
    74 }
    68 
    75 
    94  */
   101  */
    95 - (void)doCommandBySelector:(SEL)aSelector
   102 - (void)doCommandBySelector:(SEL)aSelector
    96 {
   103 {
    97     /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
   104     /*NSLog(@"doCommandBySelector: %@\n", NSStringFromSelector(aSelector));*/
    98 }
   105 }
       
   106 
       
   107 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
       
   108 {
       
   109     return NSDragOperationGeneric;
       
   110 }
       
   111 
       
   112 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
       
   113 {
       
   114     NSURL *fileURL = [NSURL URLFromPasteboard:[sender draggingPasteboard]];
       
   115     NSNumber *isAlias = nil;
       
   116 
       
   117     if (fileURL == nil) {
       
   118         return NO;
       
   119     }
       
   120 
       
   121     /* Functionality for resolving URL aliases was added with OS X 10.6. */
       
   122     if ([fileURL respondsToSelector:@selector(getResourceValue:forKey:error:)]) {
       
   123         [fileURL getResourceValue:&isAlias forKey:NSURLIsAliasFileKey error:nil];
       
   124     }
       
   125 
       
   126     /* If the URL is an alias, resolve it. */
       
   127     if ([isAlias boolValue]) {
       
   128         NSURLBookmarkResolutionOptions opts = NSURLBookmarkResolutionWithoutMounting | NSURLBookmarkResolutionWithoutUI;
       
   129         NSData *bookmark = [NSURL bookmarkDataWithContentsOfURL:fileURL error:nil];
       
   130         if (bookmark != nil) {
       
   131             NSURL *resolvedURL = [NSURL URLByResolvingBookmarkData:bookmark
       
   132                                                            options:opts
       
   133                                                      relativeToURL:nil
       
   134                                                bookmarkDataIsStale:nil
       
   135                                                              error:nil];
       
   136 
       
   137             if (resolvedURL != nil) {
       
   138                 fileURL = resolvedURL;
       
   139             }
       
   140         }
       
   141     }
       
   142 
       
   143     return (BOOL) SDL_SendDropFile([[fileURL path] UTF8String]);
       
   144 }
       
   145 
       
   146 - (BOOL)wantsPeriodicDraggingUpdates
       
   147 {
       
   148     return NO;
       
   149 }
       
   150 
    99 @end
   151 @end
   100 
   152 
   101 
   153 
   102 static Uint32 s_moveHack;
   154 static Uint32 s_moveHack;
   103 
   155 
  1118     }
  1170     }
  1119 
  1171 
  1120     [nswindow setContentView: contentView];
  1172     [nswindow setContentView: contentView];
  1121     [contentView release];
  1173     [contentView release];
  1122 
  1174 
       
  1175     /* Allow files and folders to be dragged onto the window by users */
       
  1176     [nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
       
  1177 
  1123     [pool release];
  1178     [pool release];
  1124 
  1179 
  1125     if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  1180     if (SetupWindowData(_this, window, nswindow, SDL_TRUE) < 0) {
  1126         [nswindow release];
  1181         [nswindow release];
  1127         return -1;
  1182         return -1;
  1349     }
  1404     }
  1350 
  1405 
  1351     [data->listener close];
  1406     [data->listener close];
  1352     data->nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:NO screen:[nswindow screen]];
  1407     data->nswindow = [[SDLWindow alloc] initWithContentRect:[[nswindow contentView] frame] styleMask:style backing:NSBackingStoreBuffered defer:NO screen:[nswindow screen]];
  1353     [data->nswindow setContentView:[nswindow contentView]];
  1408     [data->nswindow setContentView:[nswindow contentView]];
       
  1409     [data->nswindow registerForDraggedTypes:[NSArray arrayWithObject:(NSString *)kUTTypeFileURL]];
  1354     /* See comment in SetupWindowData. */
  1410     /* See comment in SetupWindowData. */
  1355     [data->nswindow setOneShot:NO];
  1411     [data->nswindow setOneShot:NO];
  1356     [data->listener listen:data];
  1412     [data->listener listen:data];
  1357 
  1413 
  1358     [nswindow close];
  1414     [nswindow close];