hedgewars/SDLMain.m
changeset 3697 d5b30d6373fc
parent 2666 2b8c8f16421e
child 4336 006133b13b32
equal deleted inserted replaced
3695:c11abf387a7d 3697:d5b30d6373fc
    48 
    48 
    49     /* Determine the application name */
    49     /* Determine the application name */
    50     dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
    50     dict = (const NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle());
    51     if (dict)
    51     if (dict)
    52         appName = [dict objectForKey: @"CFBundleName"];
    52         appName = [dict objectForKey: @"CFBundleName"];
    53     
    53 
    54     if (![appName length])
    54     if (![appName length])
    55         appName = [[NSProcessInfo processInfo] processName];
    55         appName = [[NSProcessInfo processInfo] processName];
    56 
    56 
    57     return appName;
    57     return appName;
    58 }
    58 }
   129     /* warning: this code is very odd */
   129     /* warning: this code is very odd */
   130     NSMenu *appleMenu;
   130     NSMenu *appleMenu;
   131     NSMenuItem *menuItem;
   131     NSMenuItem *menuItem;
   132     NSString *title;
   132     NSString *title;
   133     NSString *appName;
   133     NSString *appName;
   134     
   134 
   135     appName = getApplicationName();
   135     appName = getApplicationName();
   136     appleMenu = [[NSMenu alloc] initWithTitle:@""];
   136     appleMenu = [[NSMenu alloc] initWithTitle:@""];
   137     
   137 
   138     /* Add menu items */
   138     /* Add menu items */
   139     title = [@"About " stringByAppendingString:appName];
   139     title = [@"About " stringByAppendingString:appName];
   140     [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
   140     [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
   141 
   141 
   142     [appleMenu addItem:[NSMenuItem separatorItem]];
   142     [appleMenu addItem:[NSMenuItem separatorItem]];
   152     [appleMenu addItem:[NSMenuItem separatorItem]];
   152     [appleMenu addItem:[NSMenuItem separatorItem]];
   153 
   153 
   154     title = [@"Quit " stringByAppendingString:appName];
   154     title = [@"Quit " stringByAppendingString:appName];
   155     [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
   155     [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];
   156 
   156 
   157     
   157 
   158     /* Put menu into the menubar */
   158     /* Put menu into the menubar */
   159     menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
   159     menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
   160     [menuItem setSubmenu:appleMenu];
   160     [menuItem setSubmenu:appleMenu];
   161     [[NSApp mainMenu] addItem:menuItem];
   161     [[NSApp mainMenu] addItem:menuItem];
   162 
   162 
   174     NSMenu      *windowMenu;
   174     NSMenu      *windowMenu;
   175     NSMenuItem  *windowMenuItem;
   175     NSMenuItem  *windowMenuItem;
   176     NSMenuItem  *menuItem;
   176     NSMenuItem  *menuItem;
   177 
   177 
   178     windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
   178     windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
   179     
   179 
   180     /* "Minimize" item */
   180     /* "Minimize" item */
   181     menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
   181     menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
   182     [windowMenu addItem:menuItem];
   182     [windowMenu addItem:menuItem];
   183     [menuItem release];
   183     [menuItem release];
   184     
   184 
   185     /* Put menu into the menubar */
   185     /* Put menu into the menubar */
   186     windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
   186     windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
   187     [windowMenuItem setSubmenu:windowMenu];
   187     [windowMenuItem setSubmenu:windowMenu];
   188     [[NSApp mainMenu] addItem:windowMenuItem];
   188     [[NSApp mainMenu] addItem:windowMenuItem];
   189     
   189 
   190     /* Tell the application object that this is now the window menu */
   190     /* Tell the application object that this is now the window menu */
   191     [NSApp setWindowsMenu:windowMenu];
   191     [NSApp setWindowsMenu:windowMenu];
   192 
   192 
   193     /* Finally give up our references to the objects */
   193     /* Finally give up our references to the objects */
   194     [windowMenu release];
   194     [windowMenu release];
   201     NSAutoreleasePool	*pool = [[NSAutoreleasePool alloc] init];
   201     NSAutoreleasePool	*pool = [[NSAutoreleasePool alloc] init];
   202     SDLMain				*sdlMain;
   202     SDLMain				*sdlMain;
   203 
   203 
   204     /* Ensure the application object is initialised */
   204     /* Ensure the application object is initialised */
   205     [SDLApplication sharedApplication];
   205     [SDLApplication sharedApplication];
   206     
   206 
   207 #ifdef SDL_USE_CPS
   207 #ifdef SDL_USE_CPS
   208     {
   208     {
   209         CPSProcessSerNum PSN;
   209         CPSProcessSerNum PSN;
   210         /* Tell the dock about us */
   210         /* Tell the dock about us */
   211         if (!CPSGetCurrentProcess(&PSN))
   211         if (!CPSGetCurrentProcess(&PSN))
   221     setupWindowMenu();
   221     setupWindowMenu();
   222 
   222 
   223     /* Create SDLMain and make it the app delegate */
   223     /* Create SDLMain and make it the app delegate */
   224     sdlMain = [[SDLMain alloc] init];
   224     sdlMain = [[SDLMain alloc] init];
   225     [NSApp setDelegate:sdlMain];
   225     [NSApp setDelegate:sdlMain];
   226     
   226 
   227     /* Start the main event loop */
   227     /* Start the main event loop */
   228     [NSApp run];
   228     [NSApp run];
   229     
   229 
   230     [sdlMain release];
   230     [sdlMain release];
   231     [pool release];
   231     [pool release];
   232 }
   232 }
   233 
   233 
   234 #endif
   234 #endif
   317     NSRange localRange;
   317     NSRange localRange;
   318     NSString *result;
   318     NSString *result;
   319 
   319 
   320     bufferSize = selfLen + aStringLen - aRange.length;
   320     bufferSize = selfLen + aStringLen - aRange.length;
   321     buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
   321     buffer = (unichar *)NSAllocateMemoryPages(bufferSize*sizeof(unichar));
   322     
   322 
   323     /* Get first part into buffer */
   323     /* Get first part into buffer */
   324     localRange.location = 0;
   324     localRange.location = 0;
   325     localRange.length = aRange.location;
   325     localRange.length = aRange.location;
   326     [self getCharacters:buffer range:localRange];
   326     [self getCharacters:buffer range:localRange];
   327     
   327 
   328     /* Get middle part into buffer */
   328     /* Get middle part into buffer */
   329     localRange.location = 0;
   329     localRange.location = 0;
   330     localRange.length = aStringLen;
   330     localRange.length = aStringLen;
   331     [aString getCharacters:(buffer+aRange.location) range:localRange];
   331     [aString getCharacters:(buffer+aRange.location) range:localRange];
   332      
   332 
   333     /* Get last part into buffer */
   333     /* Get last part into buffer */
   334     localRange.location = aRange.location + aRange.length;
   334     localRange.location = aRange.location + aRange.length;
   335     localRange.length = selfLen - localRange.location;
   335     localRange.length = selfLen - localRange.location;
   336     [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
   336     [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
   337     
   337 
   338     /* Build output string */
   338     /* Build output string */
   339     result = [NSString stringWithCharacters:buffer length:bufferSize];
   339     result = [NSString stringWithCharacters:buffer length:bufferSize];
   340     
   340 
   341     NSDeallocateMemoryPages(buffer, bufferSize);
   341     NSDeallocateMemoryPages(buffer, bufferSize);
   342     
   342 
   343     return result;
   343     return result;
   344 }
   344 }
   345 
   345 
   346 @end
   346 @end
   347 
   347