Sha256: 9119a83ee8c5d81686f8f7136ac9212817ed2c41ad2bdffcfad31cc7859b49e5

Contents?: true

Size: 1.89 KB

Versions: 7

Compression:

Stored size: 1.89 KB

Contents

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


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


namespace Reflex
{


	bool initialized ();


	static Application* instance = NULL;


	Application*
	app ()
	{
		return instance;
	}


	Application::Application ()
	{
		if (!initialized() || !NSApp)
			reflex_error(__FILE__, __LINE__, "not initialized.");

		if (instance)
			reflex_error(__FILE__, __LINE__, "multiple application instances.");

		AppDelegate* delegate = (AppDelegate*) [NSApp delegate];
		if (!delegate)
			invalid_state_error(__FILE__, __LINE__);

		[delegate bind: this];

		instance = this;
	}

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

	void
	Application::start ()
	{
		if (!*this)
			invalid_state_error(__FILE__, __LINE__);

		[NSApp run];
	}

	void
	Application::quit ()
	{
		if (!*this)
			invalid_state_error(__FILE__, __LINE__);

		[NSApp terminate: nil];
	}

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

		if (!*this)
			invalid_state_error(__FILE__, __LINE__);

		self->name = name;
	}

	const char*
	Application::name () const
	{
		if (!*this)
			invalid_state_error(__FILE__, __LINE__);

		return self->name.c_str();
	}

	void
	Application::on_start (Event* e)
	{
		if (!*this)
			invalid_state_error(__FILE__, __LINE__);
	}

	void
	Application::on_quit (Event* e)
	{
		if (!*this)
			invalid_state_error(__FILE__, __LINE__);
	}

	void
	Application::on_preference (Event* e)
	{
		if (!*this)
			invalid_state_error(__FILE__, __LINE__);
	}

	void
	Application::on_about (Event* e)
	{
		if (!*this)
			invalid_state_error(__FILE__, __LINE__);

		[NSApp orderFrontStandardAboutPanel: nil];
	}

	Application::operator bool () const
	{
		return self && *self;
	}

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


}// Reflex

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reflexion-0.1.12 src/osx/application.mm
reflexion-0.1.11 src/osx/application.mm
reflexion-0.1.10 src/osx/application.mm
reflexion-0.1.9.1 src/osx/application.mm
reflexion-0.1.9 src/osx/application.mm
reflexion-0.1.8 src/osx/application.mm
reflexion-0.1.7 src/osx/application.mm