Opentk/Source/OpenTK/Platform/MacOS/Application.cs

105 lines
2.7 KiB
C#
Raw Normal View History

2008-11-04 18:35:17 +00:00
//
//
// xCSCarbon
//
// Created by Erik Ylvisaker on 3/17/08.
// Copyright 2008 __MyCompanyName__. All rights reserved.
//
//
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace OpenTK.Platform.MacOS.Carbon
{
static class Application
{
static bool mInitialized = false;
static IntPtr uppHandler;
static Application()
{
Initialize();
}
internal static void Initialize()
{
if (mInitialized) return;
2008-11-04 18:35:17 +00:00
API.AcquireRootMenu();
ConnectEvents();
}
static void ConnectEvents()
{
EventTypeSpec[] eventTypes = new EventTypeSpec[]
{
new EventTypeSpec(EventClass.Application, AppEventKind.AppActivated),
new EventTypeSpec(EventClass.Application, AppEventKind.AppDeactivated),
new EventTypeSpec(EventClass.Application, AppEventKind.AppQuit),
new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent),
};
MacOSEventHandler handler = EventHandler;
uppHandler = API.NewEventHandlerUPP(handler);
API.InstallApplicationEventHandler(
uppHandler, eventTypes, IntPtr.Zero, IntPtr.Zero);
mInitialized = true;
}
static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
{
EventInfo evt = new EventInfo(inEvent);
2009-02-03 07:43:36 +00:00
//Debug.Print("{0}", evt);
2008-11-04 18:35:17 +00:00
if (evt.EventClass == EventClass.Application)
{
switch (evt.AppEventKind)
{
default:
return OSStatus.EventNotHandled;
}
}
else if (evt.EventClass == EventClass.AppleEvent)
{
// only event here is the apple event.
Debug.Print("Processing apple event.");
2008-11-04 18:35:17 +00:00
API.ProcessAppleEvent(inEvent);
}
return OSStatus.EventNotHandled;
}
public static void Run(CarbonGLNative window)
{
window.Destroy += MainWindowClosed;
window.Show();
API.RunApplicationEventLoop();
window.Destroy -= MainWindowClosed;
}
static void MainWindowClosed(object sender, EventArgs e)
{
Debug.Print("Quitting application event loop.");
2008-11-04 18:35:17 +00:00
API.QuitApplicationEventLoop();
}
internal static void ProcessEvents()
{
API.ProcessEvents();
}
}
}