Sha256: 6ed8af12799e91c69d12e565c1951ce8fcf3f31cfc5dab3b92cad0acd753e914

Contents?: true

Size: 1.87 KB

Versions: 9

Compression:

Stored size: 1.87 KB

Contents

// -*- objc -*-
#include "application.h"


#import <AppKit/NSApplication.h>
#include "reflex/exception.h"
#import "app_delegate.h"


namespace Reflex
{


	namespace global
	{

		static Application* instance = NULL;

	}// global


	Application*
	app ()
	{
		return global::instance;
	}


	Application::Application ()
	{
		if (global::instance)
			reflex_error(__FILE__, __LINE__, "multiple application instances.");

		global::instance = this;
	}

	Application::~Application ()
	{
		global::instance = NULL;
	}

	static ReflexAppDelegate*
	setup_app_delegate (NSApplication* app)
	{
		id<NSApplicationDelegate> delegate = [app delegate];
		if (!delegate)
		{
			delegate = [[[ReflexAppDelegate alloc] init] autorelease];
			[app setDelegate: delegate];
		}

		if (![delegate isKindOfClass: ReflexAppDelegate.class])
			reflex_error(__FILE__, __LINE__);

		return (ReflexAppDelegate*) delegate;
	}

	void
	Application::start ()
	{
		NSApplication* app          = [NSApplication sharedApplication];
		ReflexAppDelegate* delegate = setup_app_delegate(app);
		[delegate bind: this];

		if (![app isRunning])
			[app run];
		else
			[delegate callOnStart];
	}

	void
	Application::quit ()
	{
		[NSApp terminate: nil];
	}

	void
	Application::set_name (const char* name)
	{
		if (!name)
			argument_error(__FILE__, __LINE__);

		self->name = name;
	}

	const char*
	Application::name () const
	{
		return self->name.c_str();
	}

	void
	Application::on_start (Event* e)
	{
	}

	void
	Application::on_quit (Event* e)
	{
	}

	void
	Application::on_motion (MotionEvent* e)
	{
	}

	void
	Application::on_preference (Event* e)
	{
	}

	void
	Application::on_about (Event* e)
	{
		[NSApp orderFrontStandardAboutPanel: nil];
	}

	Application::operator bool () const
	{
		return true;
	}

	bool
	Application::operator ! () const
	{
		return !operator bool();
	}


	Application::Data::Data ()
	:	delegate(nil)
	{
	}


}// Reflex

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
reflexion-0.3 src/osx/application.mm
reflexion-0.2.1 src/osx/application.mm
reflexion-0.2 src/osx/application.mm
reflexion-0.1.57 src/osx/application.mm
reflexion-0.1.56 src/osx/application.mm
reflexion-0.1.55 src/osx/application.mm
reflexion-0.1.54 src/osx/application.mm
reflexion-0.1.53 src/osx/application.mm
reflexion-0.1.52 src/osx/application.mm