Commits

illume committed 94f40f0 Merge

Merged in tito/pygame (pull request #3)

  • Participants
  • Parent commits ca7f934, 9bc2b0f

Comments (0)

Files changed (4)

File docs/reST/ref/event.rst

 Events support equality comparison. Two events are equal if they are the same
 type and have identical attribute values. Inequality checks also work.
 
+.. versionadded:: 1.9.2
+
+    On MacOSX, USEREVENT can have `code = pygame.USEREVENT_DROPFILE`. That
+    means the user is trying to open a file with your application. The filename
+    can be found at `event.filename`
+
 .. function:: pump
 
    | :sl:`internally process pygame event handlers`

File src/constants.c

     DEC_CONSTN(KMOD_ALT);
     DEC_CONSTN(KMOD_META);
 
+#define PYGAME_USEREVENT_DROPFILE  0x1000
+    DEC_CONSTS(USEREVENT_DROPFILE, PYGAME_USEREVENT_DROPFILE);
+
     MODINIT_RETURN (module);
 
 }
         break;
 /* SDL_VIDEOEXPOSE and SDL_QUIT have no attributes */
     }
+    if (event->type == SDL_USEREVENT && event->user.code == 0x1000) {
+        insobj (dict, "filename", PyString_FromString(event->user.data1));
+        free(event->user.data1);
+        event->user.data1 = NULL;
+    }
     if (event->type >= SDL_USEREVENT && event->type < SDL_NUMEVENTS)
         insobj (dict, "code", PyInt_FromLong (event->user.code));
 

File src/sdlmain_osx.m

 }
 @end
 
+@interface SDLApplicationDelegate : NSObject
+@end
+@implementation SDLApplicationDelegate
+- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
+{
+    int posted;
+
+    /* Post the event, if desired */
+    posted = 0;
+    SDL_Event event;
+    event.type = SDL_USEREVENT;
+    event.user.code = 0x1000;
+    event.user.data1 = SDL_strdup([filename UTF8String]);
+    posted = (SDL_PushEvent(&event) > 0);
+    return (BOOL)(posted);
+}
+@end
+
 static void setApplicationMenu(void)
 {
     NSMenu *appleMenu;
 {
     char* icon_data = NULL;
     int data_len = 0;
+    SDLApplicationDelegate *sdlApplicationDelegate = NULL;
 
     NSAutoreleasePool	*pool = [[NSAutoreleasePool alloc] init];
 
     [NSApp activateIgnoringOtherApps:true];
 
     HasInstalledApplication = 1;
+
+    /* Create SDLApplicationDelegate and make it the app delegate */
+    sdlApplicationDelegate = [[SDLApplicationDelegate alloc] init];
+    [NSApp setDelegate:sdlApplicationDelegate];
     
 	Py_RETURN_TRUE;
 }