Sha256: 6b9416bf23ced19f2096e0660577af787355d3cf857401630c357d7248ed8fb7

Contents?: true

Size: 1.89 KB

Versions: 38

Compression:

Stored size: 1.89 KB

Contents

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


#include <assert.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

38 entries across 38 versions & 1 rubygems

Version Path
reflexion-0.1.51 src/osx/application.mm
reflexion-0.1.50 src/osx/application.mm
reflexion-0.1.49 src/osx/application.mm
reflexion-0.1.48 src/osx/application.mm
reflexion-0.1.47 src/osx/application.mm
reflexion-0.1.46 src/osx/application.mm
reflexion-0.1.45 src/osx/application.mm
reflexion-0.1.44 src/osx/application.mm
reflexion-0.1.43 src/osx/application.mm
reflexion-0.1.42 src/osx/application.mm
reflexion-0.1.41 src/osx/application.mm
reflexion-0.1.40 src/osx/application.mm
reflexion-0.1.39 src/osx/application.mm
reflexion-0.1.38 src/osx/application.mm
reflexion-0.1.37 src/osx/application.mm
reflexion-0.1.36 src/osx/application.mm
reflexion-0.1.35 src/osx/application.mm
reflexion-0.1.34 src/osx/application.mm
reflexion-0.1.33 src/osx/application.mm
reflexion-0.1.32 src/osx/application.mm