showimage XCode: update SDLMain.m from SDL-1.2. add SDL_image framework include paths. SDL-1.2
authorOzkan Sezer <sezeroz@gmail.com>
Sun, 06 Oct 2019 17:15:32 +0300
branchSDL-1.2
changeset 7161647196cb153
parent 712 3a566f22eec9
showimage XCode: update SDLMain.m from SDL-1.2. add SDL_image framework include paths.
Xcode/showimage/SDLMain.m
Xcode/showimage/showimage.xcodeproj/project.pbxproj
     1.1 --- a/Xcode/showimage/SDLMain.m	Fri Oct 04 18:45:04 2019 +0300
     1.2 +++ b/Xcode/showimage/SDLMain.m	Sun Oct 06 17:15:32 2019 +0300
     1.3 @@ -5,7 +5,7 @@
     1.4      Feel free to customize this file to suit your needs
     1.5  */
     1.6  
     1.7 -#include <SDL/SDL.h>
     1.8 +#include "SDL.h"
     1.9  #include "SDLMain.h"
    1.10  #include <sys/param.h> /* for MAXPATHLEN */
    1.11  #include <unistd.h>
    1.12 @@ -20,22 +20,6 @@
    1.13  /* Use this flag to determine whether we use SDLMain.nib or not */
    1.14  #define		SDL_USE_NIB_FILE	0
    1.15  
    1.16 -/* Use this flag to determine whether we use CPS (docking) or not */
    1.17 -#define		SDL_USE_CPS		1
    1.18 -#ifdef SDL_USE_CPS
    1.19 -/* Portions of CPS.h */
    1.20 -typedef struct CPSProcessSerNum
    1.21 -{
    1.22 -	UInt32		lo;
    1.23 -	UInt32		hi;
    1.24 -} CPSProcessSerNum;
    1.25 -
    1.26 -extern OSErr	CPSGetCurrentProcess( CPSProcessSerNum *psn);
    1.27 -extern OSErr 	CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);
    1.28 -extern OSErr	CPSSetFrontProcess( CPSProcessSerNum *psn);
    1.29 -
    1.30 -#endif /* SDL_USE_CPS */
    1.31 -
    1.32  static int    gArgc;
    1.33  static char  **gArgv;
    1.34  static BOOL   gFinderLaunch;
    1.35 @@ -64,10 +48,10 @@
    1.36  @end
    1.37  #endif
    1.38  
    1.39 -@interface SDLApplication : NSApplication
    1.40 +@interface NSApplication (SDLApplication)
    1.41  @end
    1.42  
    1.43 -@implementation SDLApplication
    1.44 +@implementation NSApplication (SDLApplication)
    1.45  /* Invoked from the Quit menu item */
    1.46  - (void)terminate:(id)sender
    1.47  {
    1.48 @@ -119,7 +103,6 @@
    1.49          if ([menuItem hasSubmenu])
    1.50              [self fixMenu:[menuItem submenu] withAppName:appName];
    1.51      }
    1.52 -    [ aMenu sizeToFit ];
    1.53  }
    1.54  
    1.55  #else
    1.56 @@ -202,18 +185,7 @@
    1.57      SDLMain				*sdlMain;
    1.58  
    1.59      /* Ensure the application object is initialised */
    1.60 -    [SDLApplication sharedApplication];
    1.61 -    
    1.62 -#ifdef SDL_USE_CPS
    1.63 -    {
    1.64 -        CPSProcessSerNum PSN;
    1.65 -        /* Tell the dock about us */
    1.66 -        if (!CPSGetCurrentProcess(&PSN))
    1.67 -            if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))
    1.68 -                if (!CPSSetFrontProcess(&PSN))
    1.69 -                    [SDLApplication sharedApplication];
    1.70 -    }
    1.71 -#endif /* SDL_USE_CPS */
    1.72 +    [[NSApplication sharedApplication] activateIgnoringOtherApps: YES];
    1.73  
    1.74      /* Set up the menubar */
    1.75      [NSApp setMainMenu:[[NSMenu alloc] init]];
    1.76 @@ -346,18 +318,38 @@
    1.77  @end
    1.78  
    1.79  
    1.80 -
    1.81  #ifdef main
    1.82  #  undef main
    1.83  #endif
    1.84  
    1.85  
    1.86 +static int IsRootCwd()
    1.87 +{
    1.88 +    char buf[MAXPATHLEN];
    1.89 +    char *cwd = getcwd(buf, sizeof (buf));
    1.90 +    return (cwd && (strcmp(cwd, "/") == 0));
    1.91 +}
    1.92 +
    1.93 +static int IsFinderLaunch(const int argc, char **argv)
    1.94 +{
    1.95 +    /* -psn_XXX is passed if we are launched from Finder, SOMETIMES */
    1.96 +    if ( (argc >= 2) && (strncmp(argv[1], "-psn", 4) == 0) ) {
    1.97 +        return 1;
    1.98 +    } else if ((argc == 1) && IsRootCwd()) {
    1.99 +        /* we might still be launched from the Finder; on 10.9+, you might not
   1.100 +        get the -psn command line anymore. If there's no
   1.101 +        command line, and if our current working directory is "/", it
   1.102 +        might as well be a Finder launch. */
   1.103 +        return 1;
   1.104 +    }
   1.105 +    return 0;  /* not a Finder launch. */
   1.106 +}
   1.107 +
   1.108  /* Main entry point to executable - should *not* be SDL_main! */
   1.109  int main (int argc, char **argv)
   1.110  {
   1.111      /* Copy the arguments into a global variable */
   1.112 -    /* This is passed if we are launched by double-clicking */
   1.113 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   1.114 +    if (IsFinderLaunch(argc, argv)) {
   1.115          gArgv = (char **) SDL_malloc(sizeof (char *) * 2);
   1.116          gArgv[0] = argv[0];
   1.117          gArgv[1] = NULL;
   1.118 @@ -373,7 +365,6 @@
   1.119      }
   1.120  
   1.121  #if SDL_USE_NIB_FILE
   1.122 -    [SDLApplication poseAsClass:[NSApplication class]];
   1.123      NSApplicationMain (argc, argv);
   1.124  #else
   1.125      CustomApplicationMain (argc, argv);
     2.1 --- a/Xcode/showimage/showimage.xcodeproj/project.pbxproj	Fri Oct 04 18:45:04 2019 +0300
     2.2 +++ b/Xcode/showimage/showimage.xcodeproj/project.pbxproj	Sun Oct 06 17:15:32 2019 +0300
     2.3 @@ -227,6 +227,8 @@
     2.4  				HEADER_SEARCH_PATHS = (
     2.5  					"$(HOME)/Library/Frameworks/SDL.framework/Headers",
     2.6  					/Library/Frameworks/SDL.framework/Headers,
     2.7 +					"$(HOME)/Library/Frameworks/SDL_image.framework/Headers",
     2.8 +					/Library/Frameworks/SDL_image.framework/Headers,
     2.9  				);
    2.10  				INFOPLIST_FILE = "Info-showimage__Upgraded_.plist";
    2.11  				INSTALL_PATH = "$(HOME)/Applications";
    2.12 @@ -253,6 +255,8 @@
    2.13  				HEADER_SEARCH_PATHS = (
    2.14  					"$(HOME)/Library/Frameworks/SDL.framework/Headers",
    2.15  					/Library/Frameworks/SDL.framework/Headers,
    2.16 +					"$(HOME)/Library/Frameworks/SDL_image.framework/Headers",
    2.17 +					/Library/Frameworks/SDL_image.framework/Headers,
    2.18  				);
    2.19  				INFOPLIST_FILE = "Info-showimage__Upgraded_.plist";
    2.20  				INSTALL_PATH = "$(HOME)/Applications";
    2.21 @@ -278,6 +282,8 @@
    2.22  				HEADER_SEARCH_PATHS = (
    2.23  					"$(HOME)/Library/Frameworks/SDL.framework/Headers",
    2.24  					/Library/Frameworks/SDL.framework/Headers,
    2.25 +					"$(HOME)/Library/Frameworks/SDL_image.framework/Headers",
    2.26 +					/Library/Frameworks/SDL_image.framework/Headers,
    2.27  				);
    2.28  				INFOPLIST_FILE = "Info-showimage__Upgraded_.plist";
    2.29  				INSTALL_PATH = "$(HOME)/Applications";