* EventInfo.cs, AglContext.cs, MacOSKeyMap.cs, Application.cs,
CarbonInput.cs, CarbonGLNative.cs, MacOSException.cs,
CarbonBindings/Agl.cs, CarbonBindings/CarbonAPI.cs,
CarbonBindings/MacOSKeys.cs, CarbonBindings/SpeechChannel.cs,
CarbonBindings/CoreFoundation.cs,
CarbonBindings/QuartzDisplayServicesAPI.cs:
Normalized licensing information.
2010-11-26 11:41:45 +00:00
|
|
|
#region License
|
2009-02-22 10:43:35 +00:00
|
|
|
//
|
* EventInfo.cs, AglContext.cs, MacOSKeyMap.cs, Application.cs,
CarbonInput.cs, CarbonGLNative.cs, MacOSException.cs,
CarbonBindings/Agl.cs, CarbonBindings/CarbonAPI.cs,
CarbonBindings/MacOSKeys.cs, CarbonBindings/SpeechChannel.cs,
CarbonBindings/CoreFoundation.cs,
CarbonBindings/QuartzDisplayServicesAPI.cs:
Normalized licensing information.
2010-11-26 11:41:45 +00:00
|
|
|
// The Open Toolkit Library License
|
2009-02-22 10:43:35 +00:00
|
|
|
//
|
* EventInfo.cs, AglContext.cs, MacOSKeyMap.cs, Application.cs,
CarbonInput.cs, CarbonGLNative.cs, MacOSException.cs,
CarbonBindings/Agl.cs, CarbonBindings/CarbonAPI.cs,
CarbonBindings/MacOSKeys.cs, CarbonBindings/SpeechChannel.cs,
CarbonBindings/CoreFoundation.cs,
CarbonBindings/QuartzDisplayServicesAPI.cs:
Normalized licensing information.
2010-11-26 11:41:45 +00:00
|
|
|
// Copyright (c) 2006 - 2010 the Open Toolkit library.
|
2009-02-22 10:43:35 +00:00
|
|
|
//
|
* EventInfo.cs, AglContext.cs, MacOSKeyMap.cs, Application.cs,
CarbonInput.cs, CarbonGLNative.cs, MacOSException.cs,
CarbonBindings/Agl.cs, CarbonBindings/CarbonAPI.cs,
CarbonBindings/MacOSKeys.cs, CarbonBindings/SpeechChannel.cs,
CarbonBindings/CoreFoundation.cs,
CarbonBindings/QuartzDisplayServicesAPI.cs:
Normalized licensing information.
2010-11-26 11:41:45 +00:00
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
// of this software and associated documentation files (the "Software"), to deal
|
|
|
|
// in the Software without restriction, including without limitation the rights to
|
|
|
|
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
// the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
// so, subject to the following conditions:
|
2009-02-22 10:43:35 +00:00
|
|
|
//
|
* EventInfo.cs, AglContext.cs, MacOSKeyMap.cs, Application.cs,
CarbonInput.cs, CarbonGLNative.cs, MacOSException.cs,
CarbonBindings/Agl.cs, CarbonBindings/CarbonAPI.cs,
CarbonBindings/MacOSKeys.cs, CarbonBindings/SpeechChannel.cs,
CarbonBindings/CoreFoundation.cs,
CarbonBindings/QuartzDisplayServicesAPI.cs:
Normalized licensing information.
2010-11-26 11:41:45 +00:00
|
|
|
// The above copyright notice and this permission notice shall be included in all
|
|
|
|
// copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
|
|
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
|
|
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
// OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
//
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Created by Erik Ylvisaker on 3/17/08.
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.MacOS.Carbon
|
|
|
|
{
|
2009-07-19 17:50:41 +00:00
|
|
|
static class Application
|
|
|
|
{
|
2009-02-22 10:43:35 +00:00
|
|
|
static bool mInitialized = false;
|
|
|
|
static IntPtr uppHandler;
|
|
|
|
static CarbonGLNative eventHandler;
|
2009-03-02 01:49:23 +00:00
|
|
|
static int osMajor, osMinor, osBugfix;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
static Application()
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
2010-11-02 19:49:24 +00:00
|
|
|
static internal void Initialize()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2010-11-02 19:49:24 +00:00
|
|
|
if (mInitialized)
|
|
|
|
return;
|
2009-07-19 17:50:41 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
API.AcquireRootMenu();
|
2010-11-02 19:49:24 +00:00
|
|
|
|
2009-03-02 01:49:23 +00:00
|
|
|
ConnectEvents();
|
2010-11-02 19:49:24 +00:00
|
|
|
|
2009-03-02 01:49:23 +00:00
|
|
|
API.Gestalt(GestaltSelector.SystemVersionMajor, out osMajor);
|
|
|
|
API.Gestalt(GestaltSelector.SystemVersionMinor, out osMinor);
|
|
|
|
API.Gestalt(GestaltSelector.SystemVersionBugFix, out osBugfix);
|
2010-11-02 19:49:24 +00:00
|
|
|
|
2009-03-02 01:49:23 +00:00
|
|
|
Debug.Print("Running on Mac OS X {0}.{1}.{2}.", osMajor, osMinor, osBugfix);
|
2010-11-02 19:49:24 +00:00
|
|
|
|
|
|
|
TransformProcessToForeground();
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2010-11-02 19:49:24 +00:00
|
|
|
private static void TransformProcessToForeground()
|
|
|
|
{
|
|
|
|
Carbon.ProcessSerialNumber psn = new ProcessSerialNumber();
|
|
|
|
|
|
|
|
Debug.Print("Setting process to be foreground application.");
|
|
|
|
|
|
|
|
API.GetCurrentProcess(ref psn);
|
|
|
|
API.TransformProcessType(ref psn, ProcessApplicationTransformState.kProcessTransformToForegroundApplication);
|
|
|
|
API.SetFrontProcess(ref psn);
|
|
|
|
}
|
2009-11-16 18:45:41 +00:00
|
|
|
|
2010-11-02 19:49:24 +00:00
|
|
|
static internal CarbonGLNative WindowEventHandler
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
get { return eventHandler; }
|
|
|
|
set { eventHandler = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ConnectEvents()
|
|
|
|
{
|
2010-11-02 19:49:24 +00:00
|
|
|
|
2013-08-10 06:20:49 +00:00
|
|
|
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.Mouse, MouseEventKind.MouseDown),
|
|
|
|
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseUp),
|
|
|
|
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseMoved),
|
|
|
|
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseDragged),
|
|
|
|
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseEntered),
|
|
|
|
new EventTypeSpec(EventClass.Mouse, MouseEventKind.MouseExited),
|
|
|
|
new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelMoved),
|
|
|
|
new EventTypeSpec(EventClass.Mouse, MouseEventKind.WheelScroll),
|
2010-11-02 19:49:24 +00:00
|
|
|
|
|
|
|
|
2013-08-10 06:20:49 +00:00
|
|
|
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyDown),
|
|
|
|
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyRepeat),
|
|
|
|
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyUp),
|
|
|
|
new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyModifiersChanged),
|
|
|
|
new EventTypeSpec(EventClass.AppleEvent, AppleEventKind.AppleEvent),
|
|
|
|
};
|
2010-11-02 19:49:24 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
MacOSEventHandler handler = EventHandler;
|
|
|
|
uppHandler = API.NewEventHandlerUPP(handler);
|
2010-11-02 19:49:24 +00:00
|
|
|
|
|
|
|
API.InstallApplicationEventHandler(uppHandler, eventTypes, IntPtr.Zero, IntPtr.Zero);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
mInitialized = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
|
|
|
|
{
|
|
|
|
EventInfo evt = new EventInfo(inEvent);
|
|
|
|
|
|
|
|
switch (evt.EventClass)
|
|
|
|
{
|
2010-11-02 19:49:24 +00:00
|
|
|
case EventClass.Application:
|
|
|
|
switch (evt.AppEventKind)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2010-11-02 19:49:24 +00:00
|
|
|
|
|
|
|
case EventClass.AppleEvent:
|
|
|
|
// only event here is the apple event.
|
|
|
|
Debug.Print("Processing apple event.");
|
|
|
|
API.ProcessAppleEvent(inEvent);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EventClass.Keyboard:
|
|
|
|
case EventClass.Mouse:
|
|
|
|
if (WindowEventHandler != null)
|
|
|
|
{
|
|
|
|
return WindowEventHandler.DispatchEvent(inCaller, inEvent, evt, userData);
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
2010-11-02 19:49:24 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void Run(CarbonGLNative window)
|
|
|
|
{
|
2009-06-24 14:42:40 +00:00
|
|
|
window.Closed += MainWindowClosed;
|
2009-06-02 15:49:39 +00:00
|
|
|
window.Visible = true;
|
2010-11-02 19:49:24 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
API.RunApplicationEventLoop();
|
2010-11-02 19:49:24 +00:00
|
|
|
|
2009-06-24 14:42:40 +00:00
|
|
|
window.Closed -= MainWindowClosed;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MainWindowClosed(object sender, EventArgs e)
|
|
|
|
{
|
2009-07-19 17:50:41 +00:00
|
|
|
Debug.Print("Quitting application event loop.");
|
2009-02-22 10:43:35 +00:00
|
|
|
API.QuitApplicationEventLoop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-02 19:49:24 +00:00
|
|
|
static internal void ProcessEvents()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
API.ProcessEvents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|