summaryrefslogtreecommitdiff
path: root/src/SFML/Window/OSXCocoa/.svn/text-base/AppController.mm.svn-base
diff options
context:
space:
mode:
Diffstat (limited to 'src/SFML/Window/OSXCocoa/.svn/text-base/AppController.mm.svn-base')
-rw-r--r--src/SFML/Window/OSXCocoa/.svn/text-base/AppController.mm.svn-base370
1 files changed, 0 insertions, 370 deletions
diff --git a/src/SFML/Window/OSXCocoa/.svn/text-base/AppController.mm.svn-base b/src/SFML/Window/OSXCocoa/.svn/text-base/AppController.mm.svn-base
deleted file mode 100644
index a997c61..0000000
--- a/src/SFML/Window/OSXCocoa/.svn/text-base/AppController.mm.svn-base
+++ /dev/null
@@ -1,370 +0,0 @@
-////////////////////////////////////////////////////////////
-//
-// SFML - Simple and Fast Multimedia Library
-// Copyright (C) 2007-2008 Lucas Soltic (elmerod@gmail.com) and Laurent Gomila (laurent.gom@gmail.com)
-//
-// This software is provided 'as-is', without any express or implied warranty.
-// In no event will the authors be held liable for any damages arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it freely,
-// subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented;
-// you must not claim that you wrote the original software.
-// If you use this software in a product, an acknowledgment
-// in the product documentation would be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such,
-// and must not be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source distribution.
-//
-////////////////////////////////////////////////////////////
-
-
-////////////////////////////////////////////////////////////
-// Headers
-////////////////////////////////////////////////////////////
-#import <SFML/Window/OSXCocoa/AppController.h>
-#import <SFML/Window/OSXCocoa/WindowImplCocoa.hpp>
-
-
-static AppController *shared = nil;
-
-
-/* setAppleMenu disappeared from the headers in 10.4 */
-#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
-@interface NSApplication (SFML)
-- (void)setAppleMenu:(NSMenu *)menu;
-@end
-#endif
-
-@implementation NSApplication (SFML)
-
-- (void)setRunning:(BOOL)flag
-{
- // Note: _running is a short, not a BOOL
- if (flag)
- _running = 1;
- else
- _running = 0;
-}
-
-@end
-
-@implementation AppController
-
-- (id)init
-{
- self = [super init];
-
- if (self != nil) {
- windows = new std::vector <sf::priv::WindowImplCocoa *>;
- cleaner = new sf::Clock;
- }
-
- return self;
-}
-
-- (void)dealloc
-{
- delete windows;
- delete cleaner;
- [super dealloc];
-}
-
-////////////////////////////////////////////////////////////
-/// Return the shared AppController object. Makes one if needed
-////////////////////////////////////////////////////////////
-+ (AppController *)sharedController
-{
- if (nil == shared)
- shared = [[AppController alloc] init];
-
- return shared;
-}
-
-////////////////////////////////////////////////////////////
-/// Reallocate main pool to release autoreleased objects
-////////////////////////////////////////////////////////////
-- (void)resetPool
-{
- [mainPool release];
-
- if (nil == (mainPool = [[NSAutoreleasePool alloc] init])) {
- error(__FILE__, __LINE__, "couldn't create main autorelease pool");
- }
-}
-
-////////////////////////////////////////////////////////////
-/// Register our application and launch it if needed
-////////////////////////////////////////////////////////////
-- (void)runApplication
-{
- if ([NSApp isRunning])
- return;
-
- // We want our application to appear in the Dock and be able
- // to get focus
- ProcessSerialNumber psn;
-
- if (!GetCurrentProcess(&psn)) {
- TransformProcessType(&psn, kProcessTransformToForegroundApplication);
- SetFrontProcess(&psn);
- }
-
- if (NSApp == nil) {
- if (nil == [NSApplication sharedApplication]) {
- error(__FILE__, __LINE__, "failed to make application instance");
- }
- }
-
- if ([NSApp mainMenu] == nil) {
- [self makeMenuBar];
- }
-
- [NSApp finishLaunching];
- [NSApp setRunning:YES];
- [NSApp setDelegate:self];
-}
-
-////////////////////////////////////////////////////////////
-/// Terminate the current running application
-////////////////////////////////////////////////////////////
-- (void)quitApplication:(id)sender
-{
- // Close all windows
- // SFML user has to detect when all windows are closed
- NSWindow *current = nil;
- sf::priv::WindowImplCocoa *priv = NULL;
-
- while (windows->size()) {
- priv = windows->at(0);
- current = static_cast <NSWindow *> (priv->CocoaWindow());
- [current close];
- windows->erase(windows->begin());
- }
-}
-
-////////////////////////////////////////////////////////////
-/// Make menu bar
-////////////////////////////////////////////////////////////
-- (void)makeMenuBar
-{
- // Source taken from SDL 1.3 >>
-
- NSString *appName = nil;
- NSString *title = nil;
- NSMenu *appleMenu = nil;
- NSMenu *fileMenu = nil;
- NSMenu *windowMenu = nil;
- NSMenuItem *menuItem = nil;
- NSMenuItem *quitMenuItem = nil;
-
- /* Determine the application name */
- appName = [[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleName"];
-
- if (![appName length])
- appName = [[NSProcessInfo processInfo] processName];
-
-
- /* Create the main menu bar */
- [NSApp setMainMenu:[[NSMenu alloc] init]];
-
- /* Create the application menu */
- appleMenu = [[NSMenu alloc] initWithTitle:@""];
-
- /* Add menu items */
- title = [@"About " stringByAppendingString:appName];
- [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];
-
- [appleMenu addItem:[NSMenuItem separatorItem]];
-
- title = [@"Hide " stringByAppendingString:appName];
- [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];
-
- menuItem = static_cast <NSMenuItem *> ([appleMenu addItemWithTitle:@"Hide Others"
- action:@selector(hideOtherApplications:)
- keyEquivalent:@"h"]);
- [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];
-
- [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];
-
- [appleMenu addItem:[NSMenuItem separatorItem]];
-
- title = [@"Quit " stringByAppendingString:appName];
- quitMenuItem = [[[NSMenuItem alloc] initWithTitle:title
- action:@selector(quitApplication:)
- keyEquivalent:@"q"] autorelease];
-
- // My personal addition : i want to be the target :P
- [quitMenuItem setTarget:self];
- [appleMenu addItem:quitMenuItem];
-
- /* Put menu into the menubar */
- menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];
- [menuItem setSubmenu:appleMenu];
- [[NSApp mainMenu] addItem:menuItem];
- [menuItem release];
-
- /* Tell the application object that this is now the application menu */
- [NSApp setAppleMenu:appleMenu];
- [appleMenu release];
-
-
- fileMenu = [[NSMenu alloc] initWithTitle:@"File"];
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Close" action:@selector(performClose:) keyEquivalent:@"w"];
- [fileMenu addItem:menuItem];
- [menuItem release];
-
- menuItem = [[NSMenuItem alloc] initWithTitle:@"File" action:nil keyEquivalent:@""];
- [menuItem setSubmenu:fileMenu];
- [[NSApp mainMenu] addItem:menuItem];
- [menuItem release];
-
- /* Create the window menu */
- windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];
-
- /* "Minimize" item */
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];
- [windowMenu addItem:menuItem];
- [menuItem release];
-
- /* Put menu into the menubar */
- menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];
- [menuItem setSubmenu:windowMenu];
- [[NSApp mainMenu] addItem:menuItem];
- [menuItem release];
-
- /* Tell the application object that this is now the window menu */
- [NSApp setWindowsMenu:windowMenu];
- [windowMenu release];
-}
-
-////////////////////////////////////////////////////////////
-/// Delegate method in order to prevent usual -terminate:
-////////////////////////////////////////////////////////////
-- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
-{
- [self quitApplication:nil];
- return NSTerminateCancel;
-}
-
-////////////////////////////////////////////////////////////
-/// Get the events and put them into an array for each window
-////////////////////////////////////////////////////////////
-- (void)processEvents
-{
- // Release the main autorelease pool every second
- if (cleaner->GetElapsedTime() > 1.0f) {
- cleaner->Reset();
- [self resetPool];
- }
-
- NSEvent *event = nil;
-
- while (nil != (event = [NSApp nextEventMatchingMask:NSAnyEventMask
- untilDate:nil
- inMode:NSEventTrackingRunLoopMode
- dequeue:YES])) {
- NSWindow *keyWindow = [NSApp keyWindow];
-
- if (keyWindow == nil) {
- // Is there a fullscreen WindowImpl object ?
- [NSApp sendEvent:event];
- } else {
-
- std::vector<sf::priv::WindowImplCocoa *>::size_type cnt = windows->size();
- std::vector<sf::priv::WindowImplCocoa *>::size_type idx;
-
- // is the key window a SFML window ?
- for (idx = 0;idx < cnt; idx++) {
- sf::priv::WindowImplCocoa *ptr = windows->at(idx);;
-
- if (ptr->CocoaWindow() == keyWindow) {
- // yup, it is
- ptr->HandleEvent(static_cast <void *> (event));
- break;
- }
- }
-
- // nop, it isn't
- if (idx == cnt) {
- [NSApp sendEvent:event];
- }
- }
- }
-}
-
-////////////////////////////////////////////////////////////
-/// Add the 'windowImplObj' object to the list of known windows
-////////////////////////////////////////////////////////////
-- (void)registerWindow:(sf::priv::WindowImplCocoa *)windowImplObj
-{
-
- if (windowImplObj != NULL) {
- std::vector<sf::priv::WindowImplCocoa *>::size_type sz = windows->size();
- std::vector<sf::priv::WindowImplCocoa *>::size_type idx;
-
- for (idx = 0; idx < sz; idx++) {
- if (windows->at(idx) == windowImplObj) {
- break;
- }
- }
-
-
- // Register window only if not already registered
- if (sz == idx) {
- windows->push_back(windowImplObj);
- }
- }
-}
-
-////////////////////////////////////////////////////////////
-/// Remove the 'windowImplObj' object from the list of known windows
-////////////////////////////////////////////////////////////
-- (void)unregisterWindow:(sf::priv::WindowImplCocoa *)windowImplObj
-{
- if (windowImplObj != NULL) {
- std::vector<sf::priv::WindowImplCocoa *>::size_type sz = windows->size();
- std::vector<sf::priv::WindowImplCocoa *>::size_type idx;
-
- for (idx = 0; idx < sz; idx++) {
- if (windows->at(idx) == windowImplObj) {
- break;
- }
- }
-
- if (idx < sz) {
- windows->erase(windows->begin() + idx);
- }
- }
-}
-
-@end
-
-
-#pragma mark -
-#pragma mark Debug
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
-
-
-void error (char const *filename, unsigned ln, char const *description, ...)
-{
- va_list ap;
- char *buffer = NULL;
-
- va_start(ap, description);
- vasprintf(&buffer, description, ap);
-
- printf("*** [SFML] A critical error occured in %s line %d : %s\n",
- (filename != NULL) ? filename : "<no file>",
- ln,
- (buffer != NULL) ? buffer : "no available description");
-
- abort();
-}