2009-06-02 15:49:39 +00:00
|
|
|
#region License
|
2009-02-22 10:43:35 +00:00
|
|
|
//
|
2009-06-02 15:49:39 +00:00
|
|
|
// The Open Toolkit Library License
|
2009-02-22 10:43:35 +00:00
|
|
|
//
|
2009-06-02 15:49:39 +00:00
|
|
|
// Copyright (c) 2006 - 2009 the Open Toolkit library.
|
2009-02-22 10:43:35 +00:00
|
|
|
//
|
2009-06-02 15:49:39 +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
|
|
|
//
|
2009-06-02 15:49:39 +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
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Diagnostics;
|
2009-11-01 12:44:38 +00:00
|
|
|
using System.Drawing;
|
2009-02-22 10:43:35 +00:00
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace OpenTK.Platform.MacOS
|
|
|
|
{
|
|
|
|
using Carbon;
|
|
|
|
using Graphics;
|
|
|
|
|
2009-06-24 14:38:48 +00:00
|
|
|
class CarbonGLNative : INativeWindow
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
#region Fields
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
CarbonWindowInfo window;
|
|
|
|
CarbonInput mInputDriver;
|
2009-11-16 18:45:41 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
static MacOSKeyMap Keymap = new MacOSKeyMap();
|
|
|
|
|
|
|
|
IntPtr uppHandler;
|
|
|
|
|
|
|
|
string title = "OpenTK Window";
|
2009-11-16 18:45:41 +00:00
|
|
|
Rectangle bounds, clientRectangle;
|
|
|
|
Rectangle windowedBounds;
|
2009-02-22 10:43:35 +00:00
|
|
|
bool mIsDisposed = false;
|
2009-11-09 07:18:54 +00:00
|
|
|
bool mExists = true;
|
2009-11-09 07:50:21 +00:00
|
|
|
DisplayDevice mDisplayDevice;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
WindowAttributes mWindowAttrib;
|
|
|
|
WindowClass mWindowClass;
|
|
|
|
WindowPositionMethod mPositionMethod = WindowPositionMethod.CenterOnMainScreen;
|
|
|
|
int mTitlebarHeight;
|
|
|
|
private WindowBorder windowBorder = WindowBorder.Resizable;
|
|
|
|
private WindowState windowState = WindowState.Normal;
|
|
|
|
|
|
|
|
static Dictionary<IntPtr, WeakReference> mWindows = new Dictionary<IntPtr, WeakReference>();
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
KeyPressEventArgs mKeyPressArgs = new KeyPressEventArgs((char)0);
|
|
|
|
|
|
|
|
bool mMouseIn = false;
|
|
|
|
bool mIsActive = false;
|
|
|
|
|
|
|
|
Icon mIcon;
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
2009-11-09 07:50:21 +00:00
|
|
|
#region AGL Device Hack
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-11-09 07:50:21 +00:00
|
|
|
static internal Dictionary<IntPtr, WeakReference> WindowRefMap { get { return mWindows; } }
|
|
|
|
internal DisplayDevice TargetDisplayDevice { get { return mDisplayDevice; } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Constructors
|
|
|
|
|
|
|
|
static CarbonGLNative()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
Application.Initialize();
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
CarbonGLNative()
|
2009-02-22 10:43:35 +00:00
|
|
|
: this(WindowClass.Document,
|
|
|
|
WindowAttributes.StandardDocument |
|
|
|
|
WindowAttributes.StandardHandler |
|
|
|
|
WindowAttributes.InWindowMenu |
|
|
|
|
WindowAttributes.LiveResize)
|
2009-06-02 15:49:39 +00:00
|
|
|
{ }
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
CarbonGLNative(WindowClass @class, WindowAttributes attrib)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
mWindowClass = @class;
|
|
|
|
mWindowAttrib = attrib;
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
public CarbonGLNative(int x, int y, int width, int height, string title, GraphicsMode mode, GameWindowFlags options, DisplayDevice device)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2010-02-03 19:04:42 +00:00
|
|
|
CreateNativeWindow(WindowClass.Document,
|
2009-06-02 15:49:39 +00:00
|
|
|
WindowAttributes.StandardDocument | WindowAttributes.StandardHandler |
|
|
|
|
WindowAttributes.InWindowMenu | WindowAttributes.LiveResize,
|
|
|
|
new Rect((short)x, (short)y, (short)width, (short)height));
|
2010-02-03 19:04:42 +00:00
|
|
|
|
2009-11-09 07:50:21 +00:00
|
|
|
mDisplayDevice = device;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region IDisposable
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
Dispose(true);
|
|
|
|
GC.SuppressFinalize(this);
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
protected virtual void Dispose(bool disposing)
|
|
|
|
{
|
|
|
|
if (mIsDisposed)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Debug.Print("Disposing of CarbonGLNative window.");
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
API.DisposeWindow(window.WindowRef);
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
mIsDisposed = true;
|
2009-11-09 07:18:54 +00:00
|
|
|
mExists = false;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
if (disposing)
|
|
|
|
{
|
|
|
|
mWindows.Remove(window.WindowRef);
|
|
|
|
|
|
|
|
window.Dispose();
|
|
|
|
window = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisposeUPP();
|
2009-11-16 18:45:41 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
Disposed(this, EventArgs.Empty);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
~CarbonGLNative()
|
|
|
|
{
|
|
|
|
Dispose(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Private Members
|
|
|
|
|
|
|
|
void DisposeUPP()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
if (uppHandler != IntPtr.Zero)
|
|
|
|
{
|
|
|
|
//API.RemoveEventHandler(uppHandler);
|
|
|
|
//API.DisposeEventHandlerUPP(uppHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
uppHandler = IntPtr.Zero;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CreateNativeWindow(WindowClass @class, WindowAttributes attrib, Rect r)
|
|
|
|
{
|
|
|
|
Debug.Print("Creating window...");
|
|
|
|
Debug.Indent();
|
|
|
|
|
|
|
|
IntPtr windowRef = API.CreateNewWindow(@class, attrib, r);
|
|
|
|
API.SetWindowTitle(windowRef, title);
|
|
|
|
|
|
|
|
window = new CarbonWindowInfo(windowRef, true, false);
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
SetLocation(r.X, r.Y);
|
2009-02-22 10:43:35 +00:00
|
|
|
SetSize(r.Width, r.Height);
|
|
|
|
|
|
|
|
Debug.Unindent();
|
|
|
|
Debug.Print("Created window.");
|
|
|
|
|
|
|
|
mWindows.Add(windowRef, new WeakReference(this));
|
|
|
|
|
|
|
|
LoadSize();
|
|
|
|
|
|
|
|
Rect titleSize = API.GetWindowBounds(window.WindowRef, WindowRegionCode.TitleBarRegion);
|
|
|
|
mTitlebarHeight = titleSize.Height;
|
|
|
|
|
|
|
|
Debug.Print("Titlebar size: {0}", titleSize);
|
|
|
|
|
|
|
|
ConnectEvents();
|
|
|
|
|
|
|
|
System.Diagnostics.Debug.Print("Attached window events.");
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
void ConnectEvents()
|
|
|
|
{
|
|
|
|
mInputDriver = new CarbonInput();
|
|
|
|
|
|
|
|
EventTypeSpec[] eventTypes = new EventTypeSpec[]
|
|
|
|
{
|
|
|
|
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClose),
|
|
|
|
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowClosed),
|
|
|
|
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowBoundsChanged),
|
2009-11-16 18:45:41 +00:00
|
|
|
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowActivate),
|
|
|
|
new EventTypeSpec(EventClass.Window, WindowEventKind.WindowDeactivate),
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
//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.Keyboard, KeyboardEventKind.RawKeyDown),
|
|
|
|
//new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyRepeat),
|
|
|
|
//new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyUp),
|
|
|
|
//new EventTypeSpec(EventClass.Keyboard, KeyboardEventKind.RawKeyModifiersChanged),
|
|
|
|
};
|
|
|
|
|
|
|
|
MacOSEventHandler handler = EventHandler;
|
|
|
|
uppHandler = API.NewEventHandlerUPP(handler);
|
|
|
|
|
|
|
|
API.InstallWindowEventHandler(window.WindowRef, uppHandler, eventTypes, window.WindowRef, IntPtr.Zero);
|
|
|
|
|
|
|
|
Application.WindowEventHandler = this;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
void Activate()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
API.SelectWindow(window.WindowRef);
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
void Show()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
IntPtr parent = IntPtr.Zero;
|
|
|
|
|
|
|
|
API.ShowWindow(window.WindowRef);
|
|
|
|
API.RepositionWindow(window.WindowRef, parent, WindowPositionMethod);
|
|
|
|
API.SelectWindow(window.WindowRef);
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
void Hide()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
API.HideWindow(window.WindowRef);
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
internal void SetFullscreen(AglContext context)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
windowedBounds = bounds;
|
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
int width, height;
|
|
|
|
|
|
|
|
context.SetFullScreen(window, out width, out height);
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
Debug.Print("Prev Size: {0}, {1}", Width, Height);
|
2010-02-03 19:04:42 +00:00
|
|
|
clientRectangle.Size = new Size(width, height);
|
|
|
|
Debug.Print("New Size: {0}, {1}", Width, Height);
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
// TODO: if we go full screen we need to make this use the device specified.
|
2010-02-03 19:04:42 +00:00
|
|
|
bounds = mDisplayDevice.Bounds;
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
|
|
|
|
windowState = WindowState.Fullscreen;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
internal void UnsetFullscreen(AglContext context)
|
2009-06-02 15:49:39 +00:00
|
|
|
{
|
2010-02-03 19:04:42 +00:00
|
|
|
context.UnsetFullScreen(window);
|
|
|
|
|
|
|
|
Debug.Print("Telling Carbon to reset window state to " + windowState.ToString());
|
|
|
|
SetCarbonWindowState();
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
SetSize((short)windowedBounds.Width, (short)windowedBounds.Height);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsDisposed
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
get { return mIsDisposed; }
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
WindowPositionMethod WindowPositionMethod
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
get { return mPositionMethod; }
|
|
|
|
set { mPositionMethod = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
internal OSStatus DispatchEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
|
|
|
|
{
|
|
|
|
switch (evt.EventClass)
|
|
|
|
{
|
|
|
|
case EventClass.Window:
|
|
|
|
return ProcessWindowEvent(inCaller, inEvent, evt, userData);
|
|
|
|
|
|
|
|
case EventClass.Mouse:
|
|
|
|
return ProcessMouseEvent(inCaller, inEvent, evt, userData);
|
|
|
|
|
|
|
|
case EventClass.Keyboard:
|
|
|
|
return ProcessKeyboardEvent(inCaller, inEvent, evt, userData);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static OSStatus EventHandler(IntPtr inCaller, IntPtr inEvent, IntPtr userData)
|
|
|
|
{
|
|
|
|
// bail out if the window passed in is not actually our window.
|
|
|
|
// I think this happens if using winforms with a GameWindow sometimes.
|
|
|
|
if (mWindows.ContainsKey(userData) == false)
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
|
|
|
|
WeakReference reference = mWindows[userData];
|
|
|
|
|
|
|
|
// bail out if the CarbonGLNative window has been garbage collected.
|
|
|
|
if (reference.IsAlive == false)
|
|
|
|
{
|
|
|
|
mWindows.Remove(userData);
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
|
|
|
|
2009-11-09 07:18:54 +00:00
|
|
|
CarbonGLNative window = (CarbonGLNative)reference.Target;
|
|
|
|
EventInfo evt = new EventInfo(inEvent);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
//Debug.Print("Processing {0} event for {1}.", evt, window.window);
|
|
|
|
|
|
|
|
if (window == null)
|
|
|
|
{
|
|
|
|
Debug.WriteLine("Window for event not found.");
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (evt.EventClass)
|
|
|
|
{
|
|
|
|
case EventClass.Window:
|
|
|
|
return window.ProcessWindowEvent(inCaller, inEvent, evt, userData);
|
|
|
|
|
|
|
|
case EventClass.Mouse:
|
|
|
|
return window.ProcessMouseEvent(inCaller, inEvent, evt, userData);
|
|
|
|
|
|
|
|
case EventClass.Keyboard:
|
|
|
|
return window.ProcessKeyboardEvent(inCaller, inEvent, evt, userData);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private OSStatus ProcessKeyboardEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
|
|
|
|
{
|
|
|
|
System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Keyboard);
|
2009-11-16 18:45:41 +00:00
|
|
|
MacOSKeyCode code = (MacOSKeyCode)0;
|
|
|
|
char charCode = '\0';
|
|
|
|
|
|
|
|
//Debug.Print("Processing keyboard event {0}", evt.KeyboardEventKind);
|
|
|
|
|
|
|
|
switch (evt.KeyboardEventKind)
|
|
|
|
{
|
|
|
|
case KeyboardEventKind.RawKeyDown:
|
|
|
|
case KeyboardEventKind.RawKeyRepeat:
|
|
|
|
case KeyboardEventKind.RawKeyUp:
|
|
|
|
GetCharCodes(inEvent, out code, out charCode);
|
|
|
|
mKeyPressArgs.KeyChar = charCode;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
switch (evt.KeyboardEventKind)
|
|
|
|
{
|
|
|
|
case KeyboardEventKind.RawKeyRepeat:
|
|
|
|
InputDriver.Keyboard[0].KeyRepeat = true;
|
|
|
|
goto case KeyboardEventKind.RawKeyDown;
|
|
|
|
|
|
|
|
case KeyboardEventKind.RawKeyDown:
|
2009-11-16 18:45:41 +00:00
|
|
|
OnKeyPress(mKeyPressArgs);
|
2009-02-22 10:43:35 +00:00
|
|
|
InputDriver.Keyboard[0][Keymap[code]] = true;
|
2010-02-03 19:04:42 +00:00
|
|
|
return OSStatus.NoError;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
case KeyboardEventKind.RawKeyUp:
|
|
|
|
InputDriver.Keyboard[0][Keymap[code]] = false;
|
2010-02-03 19:04:42 +00:00
|
|
|
|
|
|
|
return OSStatus.NoError;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
case KeyboardEventKind.RawKeyModifiersChanged:
|
|
|
|
ProcessModifierKey(inEvent);
|
2010-02-03 19:04:42 +00:00
|
|
|
return OSStatus.NoError;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2009-11-16 18:45:41 +00:00
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
private OSStatus ProcessWindowEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
|
|
|
|
{
|
|
|
|
System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Window);
|
|
|
|
|
|
|
|
switch (evt.WindowEventKind)
|
|
|
|
{
|
|
|
|
case WindowEventKind.WindowClose:
|
|
|
|
CancelEventArgs cancel = new CancelEventArgs();
|
2009-06-02 15:49:39 +00:00
|
|
|
OnClosing(cancel);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
if (cancel.Cancel)
|
|
|
|
return OSStatus.NoError;
|
|
|
|
else
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
|
|
|
|
case WindowEventKind.WindowClosed:
|
2009-11-09 07:18:54 +00:00
|
|
|
mExists = false;
|
|
|
|
OnClosed();
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
return OSStatus.NoError;
|
|
|
|
|
|
|
|
case WindowEventKind.WindowBoundsChanged:
|
|
|
|
int thisWidth = Width;
|
|
|
|
int thisHeight = Height;
|
2010-10-28 09:31:00 +00:00
|
|
|
int thisX = X;
|
|
|
|
int thisY = Y;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
LoadSize();
|
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
if (thisX != X || thisY != Y)
|
|
|
|
Move(this, EventArgs.Empty);
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
if (thisWidth != Width || thisHeight != Height)
|
2010-10-28 09:31:00 +00:00
|
|
|
Resize(this, EventArgs.Empty);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
case WindowEventKind.WindowActivate:
|
|
|
|
OnActivate();
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
|
|
|
|
case WindowEventKind.WindowDeactivate:
|
|
|
|
OnDeactivate();
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
default:
|
|
|
|
Debug.Print("{0}", evt);
|
|
|
|
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected OSStatus ProcessMouseEvent(IntPtr inCaller, IntPtr inEvent, EventInfo evt, IntPtr userData)
|
|
|
|
{
|
|
|
|
System.Diagnostics.Debug.Assert(evt.EventClass == EventClass.Mouse);
|
|
|
|
MouseButton button = MouseButton.Primary;
|
|
|
|
HIPoint pt = new HIPoint();
|
2009-11-16 18:45:41 +00:00
|
|
|
HIPoint screenLoc = new HIPoint();
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
OSStatus err = API.GetEventMouseLocation(inEvent, out screenLoc);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
if (this.windowState == WindowState.Fullscreen)
|
|
|
|
{
|
2009-11-16 18:45:41 +00:00
|
|
|
pt = screenLoc;
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = API.GetEventWindowMouseLocation(inEvent, out pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != OSStatus.NoError)
|
|
|
|
{
|
|
|
|
// this error comes up from the application event handler.
|
|
|
|
if (err != OSStatus.EventParameterNotFound)
|
|
|
|
{
|
|
|
|
throw new MacOSException(err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
Point mousePosInClient = new Point((int)pt.X, (int)pt.Y);
|
|
|
|
if (this.windowState != WindowState.Fullscreen)
|
|
|
|
{
|
|
|
|
mousePosInClient.Y -= mTitlebarHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check for enter/leave events
|
|
|
|
IntPtr thisEventWindow;
|
|
|
|
API.GetEventWindowRef(inEvent, out thisEventWindow);
|
|
|
|
CheckEnterLeaveEvents(thisEventWindow, mousePosInClient);
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
switch (evt.MouseEventKind)
|
|
|
|
{
|
|
|
|
case MouseEventKind.MouseDown:
|
|
|
|
button = API.GetEventMouseButton(inEvent);
|
|
|
|
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case MouseButton.Primary:
|
|
|
|
InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseButton.Secondary:
|
|
|
|
InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseButton.Tertiary:
|
|
|
|
InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
return OSStatus.NoError;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
case MouseEventKind.MouseUp:
|
2009-11-16 18:45:41 +00:00
|
|
|
button = API.GetEventMouseButton(inEvent);
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
case MouseButton.Primary:
|
|
|
|
InputDriver.Mouse[0][OpenTK.Input.MouseButton.Left] = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseButton.Secondary:
|
|
|
|
InputDriver.Mouse[0][OpenTK.Input.MouseButton.Right] = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MouseButton.Tertiary:
|
|
|
|
InputDriver.Mouse[0][OpenTK.Input.MouseButton.Middle] = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
button = API.GetEventMouseButton(inEvent);
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
return OSStatus.NoError;
|
|
|
|
|
|
|
|
case MouseEventKind.WheelMoved:
|
|
|
|
|
|
|
|
int delta = API.GetEventMouseWheelDelta(inEvent) / 3;
|
|
|
|
|
|
|
|
InputDriver.Mouse[0].Wheel += delta;
|
|
|
|
|
|
|
|
return OSStatus.NoError;
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
case MouseEventKind.MouseMoved:
|
|
|
|
case MouseEventKind.MouseDragged:
|
2009-11-16 18:45:41 +00:00
|
|
|
|
|
|
|
//Debug.Print("Mouse Location: {0}, {1}", pt.X, pt.Y);
|
|
|
|
|
|
|
|
if (this.windowState == WindowState.Fullscreen)
|
|
|
|
{
|
|
|
|
if (mousePosInClient.X != InputDriver.Mouse[0].X ||
|
|
|
|
mousePosInClient.Y != InputDriver.Mouse[0].Y)
|
|
|
|
{
|
|
|
|
InputDriver.Mouse[0].Position = mousePosInClient;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// ignore clicks in the title bar
|
|
|
|
if (pt.Y < 0)
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
|
|
|
|
if (mousePosInClient.X != InputDriver.Mouse[0].X ||
|
|
|
|
mousePosInClient.Y != InputDriver.Mouse[0].Y)
|
|
|
|
{
|
|
|
|
InputDriver.Mouse[0].Position = mousePosInClient;
|
|
|
|
}
|
|
|
|
}
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Debug.Print("{0}", evt);
|
|
|
|
|
|
|
|
return OSStatus.EventNotHandled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
private void CheckEnterLeaveEvents(IntPtr eventWindowRef, Point pt)
|
|
|
|
{
|
|
|
|
if (window == null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool thisIn = eventWindowRef == window.WindowRef;
|
|
|
|
|
|
|
|
if (pt.Y < 0)
|
|
|
|
thisIn = false;
|
|
|
|
|
|
|
|
if (thisIn != mMouseIn)
|
|
|
|
{
|
|
|
|
mMouseIn = thisIn;
|
|
|
|
|
|
|
|
if (mMouseIn)
|
|
|
|
OnMouseEnter();
|
|
|
|
else
|
|
|
|
OnMouseLeave();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
private static void GetCharCodes(IntPtr inEvent, out MacOSKeyCode code, out char charCode)
|
|
|
|
{
|
|
|
|
code = API.GetEventKeyboardKeyCode(inEvent);
|
|
|
|
charCode = API.GetEventKeyboardChar(inEvent);
|
|
|
|
}
|
|
|
|
private void ProcessModifierKey(IntPtr inEvent)
|
|
|
|
{
|
|
|
|
MacOSKeyModifiers modifiers = API.GetEventKeyModifiers(inEvent);
|
|
|
|
|
|
|
|
bool caps = (modifiers & MacOSKeyModifiers.CapsLock) != 0 ? true : false;
|
|
|
|
bool control = (modifiers & MacOSKeyModifiers.Control) != 0 ? true : false;
|
|
|
|
bool command = (modifiers & MacOSKeyModifiers.Command) != 0 ? true : false;
|
|
|
|
bool option = (modifiers & MacOSKeyModifiers.Option) != 0 ? true : false;
|
|
|
|
bool shift = (modifiers & MacOSKeyModifiers.Shift) != 0 ? true : false;
|
|
|
|
|
|
|
|
Debug.Print("Modifiers Changed: {0}", modifiers);
|
|
|
|
|
|
|
|
Input.KeyboardDevice keyboard = InputDriver.Keyboard[0];
|
|
|
|
|
|
|
|
if (keyboard[OpenTK.Input.Key.AltLeft] ^ option)
|
|
|
|
keyboard[OpenTK.Input.Key.AltLeft] = option;
|
|
|
|
|
|
|
|
if (keyboard[OpenTK.Input.Key.ShiftLeft] ^ shift)
|
|
|
|
keyboard[OpenTK.Input.Key.ShiftLeft] = shift;
|
|
|
|
|
|
|
|
if (keyboard[OpenTK.Input.Key.WinLeft] ^ command)
|
|
|
|
keyboard[OpenTK.Input.Key.WinLeft] = command;
|
|
|
|
|
|
|
|
if (keyboard[OpenTK.Input.Key.ControlLeft] ^ control)
|
|
|
|
keyboard[OpenTK.Input.Key.ControlLeft] = control;
|
|
|
|
|
|
|
|
if (keyboard[OpenTK.Input.Key.CapsLock] ^ caps)
|
|
|
|
keyboard[OpenTK.Input.Key.CapsLock] = caps;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Rect GetRegion()
|
|
|
|
{
|
|
|
|
Rect retval = API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
void SetLocation(short x, short y)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-06-02 15:49:39 +00:00
|
|
|
if (windowState == WindowState.Fullscreen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
API.MoveWindow(window.WindowRef, x, y, false);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
|
|
|
|
void SetSize(short width, short height)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
if (WindowState == WindowState.Fullscreen)
|
|
|
|
return;
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
// The bounds of the window should be the size specified, but
|
|
|
|
// API.SizeWindow sets the content region size. So
|
|
|
|
// we reduce the size to get the correct bounds.
|
|
|
|
width -= (short)(bounds.Width - clientRectangle.Width);
|
|
|
|
height -= (short)(bounds.Height - clientRectangle.Height);
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
API.SizeWindow(window.WindowRef, width, height, true);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2010-01-11 22:08:00 +00:00
|
|
|
void SetClientSize(short width, short height)
|
|
|
|
{
|
|
|
|
if (WindowState == WindowState.Fullscreen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
API.SizeWindow(window.WindowRef, width, height, true);
|
|
|
|
}
|
|
|
|
|
2009-02-22 10:43:35 +00:00
|
|
|
|
|
|
|
private void LoadSize()
|
|
|
|
{
|
|
|
|
if (WindowState == WindowState.Fullscreen)
|
|
|
|
return;
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
Rect r = API.GetWindowBounds(window.WindowRef, WindowRegionCode.StructureRegion);
|
|
|
|
bounds = new Rectangle(r.X, r.Y, r.Width, r.Height);
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
r = API.GetWindowBounds(window.WindowRef, WindowRegionCode.GlobalPortRegion);
|
|
|
|
clientRectangle = new Rectangle(0, 0, r.Width, r.Height);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
#region INativeWindow Members
|
2009-02-22 10:43:35 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
public void ProcessEvents()
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
|
|
|
Application.ProcessEvents();
|
|
|
|
}
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Point PointToClient(Point point)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2009-05-11 01:10:09 +00:00
|
|
|
Rect r = Carbon.API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
|
2010-02-03 19:04:42 +00:00
|
|
|
Debug.Print("Rect: {0}", r);
|
2009-05-11 01:10:09 +00:00
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
return new Point(point.X - r.X, point.Y - r.Y);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
2009-11-01 12:44:38 +00:00
|
|
|
public Point PointToScreen(Point point)
|
2009-02-22 10:43:35 +00:00
|
|
|
{
|
2010-02-03 19:04:42 +00:00
|
|
|
Rect r = Carbon.API.GetWindowBounds(window.WindowRef, WindowRegionCode.ContentRegion);
|
|
|
|
Debug.Print("Rect: {0}", r);
|
|
|
|
|
|
|
|
return new Point(point.X + r.X, point.Y + r.Y);
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public bool Exists
|
|
|
|
{
|
2009-11-09 07:18:54 +00:00
|
|
|
get { return mExists; }
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public IWindowInfo WindowInfo
|
|
|
|
{
|
|
|
|
get { return window; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool IsIdle
|
|
|
|
{
|
|
|
|
get { return true; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public OpenTK.Input.IInputDriver InputDriver
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return mInputDriver;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2009-11-02 09:33:53 +00:00
|
|
|
public Icon Icon
|
2009-10-18 16:52:07 +00:00
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
get { return mIcon; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value != Icon)
|
|
|
|
{
|
|
|
|
SetIcon(value);
|
|
|
|
mIcon = value;
|
|
|
|
IconChanged(this, EventArgs.Empty);
|
|
|
|
}
|
|
|
|
}
|
2009-10-18 16:52:07 +00:00
|
|
|
}
|
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
private void SetIcon(Icon icon)
|
|
|
|
{
|
|
|
|
// The code for this function was adapted from Mono's
|
|
|
|
// XplatUICarbon implementation, written by Geoff Norton
|
|
|
|
// http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/XplatUICarbon.cs?view=markup&pathrev=136932
|
|
|
|
if (icon == null)
|
|
|
|
{
|
|
|
|
API.RestoreApplicationDockTileImage();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Bitmap bitmap;
|
|
|
|
int size;
|
|
|
|
IntPtr[] data;
|
|
|
|
int index;
|
|
|
|
|
|
|
|
bitmap = new Bitmap(128, 128);
|
|
|
|
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap))
|
|
|
|
{
|
|
|
|
g.DrawImage(icon.ToBitmap(), 0, 0, 128, 128);
|
|
|
|
}
|
|
|
|
index = 0;
|
|
|
|
size = bitmap.Width * bitmap.Height;
|
|
|
|
data = new IntPtr[size];
|
|
|
|
|
|
|
|
for (int y = 0; y < bitmap.Height; y++)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < bitmap.Width; x++)
|
|
|
|
{
|
|
|
|
int pixel = bitmap.GetPixel(x, y).ToArgb();
|
|
|
|
if (BitConverter.IsLittleEndian)
|
|
|
|
{
|
|
|
|
byte a = (byte)((pixel >> 24) & 0xFF);
|
|
|
|
byte r = (byte)((pixel >> 16) & 0xFF);
|
|
|
|
byte g = (byte)((pixel >> 8) & 0xFF);
|
|
|
|
byte b = (byte)(pixel & 0xFF);
|
|
|
|
data[index++] = (IntPtr)(a + (r << 8) + (g << 16) + (b << 24));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
data[index++] = (IntPtr)pixel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IntPtr provider = API.CGDataProviderCreateWithData(IntPtr.Zero, data, size * 4, IntPtr.Zero);
|
|
|
|
IntPtr image = API.CGImageCreate(128, 128, 8, 32, 4 * 128, API.CGColorSpaceCreateDeviceRGB(), 4, provider, IntPtr.Zero, 0, 0);
|
|
|
|
API.SetApplicationDockTileImage(image);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public string Title
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return title;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
if (value != Title)
|
|
|
|
{
|
|
|
|
API.SetWindowTitle(window.WindowRef, value);
|
|
|
|
title = value;
|
|
|
|
TitleChanged(this, EventArgs.Empty);
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Visible
|
|
|
|
{
|
|
|
|
get { return API.IsWindowVisible(window.WindowRef); }
|
|
|
|
set
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
if (value != Visible)
|
|
|
|
{
|
|
|
|
if (value)
|
|
|
|
Show();
|
|
|
|
else
|
|
|
|
Hide();
|
|
|
|
|
|
|
|
VisibleChanged(this, EventArgs.Empty);
|
|
|
|
}
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool Focused
|
|
|
|
{
|
2009-11-16 18:45:41 +00:00
|
|
|
get { return this.mIsActive; }
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Rectangle Bounds
|
2009-06-02 15:49:39 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2009-11-16 18:45:41 +00:00
|
|
|
|
|
|
|
return bounds;
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
Location = value.Location;
|
|
|
|
Size = value.Size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Point Location
|
2009-06-02 15:49:39 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2009-11-16 18:45:41 +00:00
|
|
|
return Bounds.Location;
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
SetLocation((short)value.X, (short)value.Y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Size Size
|
2009-06-02 15:49:39 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return bounds.Size;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
SetSize((short)value.Width, (short)value.Height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Width
|
|
|
|
{
|
2010-01-11 22:08:00 +00:00
|
|
|
get { return ClientRectangle.Width; }
|
|
|
|
set { SetClientSize((short)value, (short)Height); }
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int Height
|
|
|
|
{
|
2010-01-11 22:08:00 +00:00
|
|
|
get { return ClientRectangle.Height; }
|
|
|
|
set { SetClientSize((short)Width, (short)value); }
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public int X
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2010-01-11 22:08:00 +00:00
|
|
|
return ClientRectangle.X;
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2009-11-01 12:44:38 +00:00
|
|
|
Location = new Point(value, Y);
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int Y
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2010-01-11 22:08:00 +00:00
|
|
|
return ClientRectangle.Y;
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2009-11-01 12:44:38 +00:00
|
|
|
Location = new Point(X, value);
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Rectangle ClientRectangle
|
2009-06-02 15:49:39 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
2009-11-16 18:45:41 +00:00
|
|
|
return clientRectangle;
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2009-11-16 18:45:41 +00:00
|
|
|
// just set the size, and ignore the location value.
|
|
|
|
// this is the behavior of the Windows WinGLNative.
|
|
|
|
ClientSize = value.Size;
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-01 12:44:38 +00:00
|
|
|
public Size ClientSize
|
2009-06-02 15:49:39 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return clientRectangle.Size;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
2009-11-16 18:45:41 +00:00
|
|
|
API.SizeWindow(window.WindowRef, (short)value.Width, (short)value.Height, true);
|
2010-10-28 09:31:00 +00:00
|
|
|
LoadSize();
|
|
|
|
Resize(this, EventArgs.Empty);
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-18 15:25:25 +00:00
|
|
|
public bool CursorVisible
|
|
|
|
{
|
|
|
|
get { return true; }
|
|
|
|
set { }
|
|
|
|
}
|
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
public void Close()
|
|
|
|
{
|
2009-11-16 18:45:41 +00:00
|
|
|
CancelEventArgs e = new CancelEventArgs();
|
|
|
|
OnClosing(e);
|
|
|
|
|
|
|
|
if (e.Cancel)
|
|
|
|
return;
|
|
|
|
|
|
|
|
OnClosed();
|
|
|
|
|
|
|
|
Dispose();
|
2009-06-02 15:49:39 +00:00
|
|
|
}
|
|
|
|
|
2009-08-17 09:34:15 +00:00
|
|
|
public WindowState WindowState
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
if (windowState == WindowState.Fullscreen)
|
|
|
|
return WindowState.Fullscreen;
|
|
|
|
|
|
|
|
if (Carbon.API.IsWindowCollapsed(window.WindowRef))
|
|
|
|
return WindowState.Minimized;
|
|
|
|
|
|
|
|
if (Carbon.API.IsWindowInStandardState(window.WindowRef))
|
|
|
|
{
|
|
|
|
return WindowState.Maximized;
|
|
|
|
}
|
|
|
|
|
|
|
|
return WindowState.Normal;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == WindowState)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Debug.Print("Switching window state from {0} to {1}", WindowState, value);
|
2010-02-03 19:04:42 +00:00
|
|
|
WindowState oldState = WindowState;
|
|
|
|
|
|
|
|
windowState = value;
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
if (oldState == WindowState.Fullscreen)
|
2009-08-17 09:34:15 +00:00
|
|
|
{
|
2010-02-03 19:04:42 +00:00
|
|
|
window.GoWindowedHack = true;
|
|
|
|
|
|
|
|
// when returning from full screen, wait until the context is updated
|
|
|
|
// to actually do the work.
|
|
|
|
return;
|
2009-08-17 09:34:15 +00:00
|
|
|
}
|
2010-02-03 19:04:42 +00:00
|
|
|
|
|
|
|
if (oldState == WindowState.Minimized)
|
2009-08-17 09:34:15 +00:00
|
|
|
{
|
|
|
|
API.CollapseWindow(window.WindowRef, false);
|
|
|
|
}
|
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
SetCarbonWindowState();
|
|
|
|
}
|
|
|
|
}
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
private void SetCarbonWindowState()
|
|
|
|
{
|
|
|
|
CarbonPoint idealSize;
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
switch (windowState)
|
|
|
|
{
|
|
|
|
case WindowState.Fullscreen:
|
|
|
|
window.GoFullScreenHack = true;
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
break;
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
case WindowState.Maximized:
|
|
|
|
// hack because mac os has no concept of maximized. Instead windows are "zoomed"
|
|
|
|
// meaning they are maximized up to their reported ideal size. So we report a
|
|
|
|
// large ideal size.
|
|
|
|
idealSize = new CarbonPoint(9000, 9000);
|
|
|
|
API.ZoomWindowIdeal(window.WindowRef, WindowPartCode.inZoomOut, ref idealSize);
|
|
|
|
break;
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
case WindowState.Normal:
|
|
|
|
if (WindowState == WindowState.Maximized)
|
|
|
|
{
|
|
|
|
idealSize = new CarbonPoint();
|
|
|
|
API.ZoomWindowIdeal(window.WindowRef, WindowPartCode.inZoomIn, ref idealSize);
|
|
|
|
}
|
|
|
|
break;
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2010-02-03 19:04:42 +00:00
|
|
|
case WindowState.Minimized:
|
|
|
|
API.CollapseWindow(window.WindowRef, true);
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
WindowStateChanged(this, EventArgs.Empty);
|
|
|
|
LoadSize();
|
|
|
|
Resize(this, EventArgs.Empty);
|
2010-02-03 19:04:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public WindowBorder WindowBorder
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return windowBorder;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (windowBorder == value)
|
|
|
|
return;
|
|
|
|
|
|
|
|
windowBorder = value;
|
|
|
|
|
|
|
|
if (windowBorder == WindowBorder.Resizable)
|
|
|
|
{
|
|
|
|
API.ChangeWindowAttributes(window.WindowRef, WindowAttributes.Resizable | WindowAttributes.FullZoom,
|
|
|
|
WindowAttributes.NoAttributes);
|
|
|
|
}
|
|
|
|
else if (windowBorder == WindowBorder.Fixed)
|
|
|
|
{
|
|
|
|
API.ChangeWindowAttributes(window.WindowRef, WindowAttributes.NoAttributes,
|
|
|
|
WindowAttributes.Resizable | WindowAttributes.FullZoom);
|
|
|
|
}
|
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
WindowBorderChanged(this, EventArgs.Empty);
|
2010-02-03 19:04:42 +00:00
|
|
|
}
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#region --- Event wrappers ---
|
|
|
|
|
|
|
|
private void OnKeyPress(KeyPressEventArgs keyPressArgs)
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
KeyPress(this, keyPressArgs);
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnWindowStateChanged()
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
WindowStateChanged(this, EventArgs.Empty);
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnClosing(CancelEventArgs e)
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
Closing(this, e);
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected virtual void OnClosed()
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
Closed(this, EventArgs.Empty);
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnMouseLeave()
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
MouseLeave(this, EventArgs.Empty);
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnMouseEnter()
|
|
|
|
{
|
2010-10-28 09:31:00 +00:00
|
|
|
MouseEnter(this, EventArgs.Empty);
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void OnActivate()
|
|
|
|
{
|
|
|
|
mIsActive = true;
|
2010-10-28 09:31:00 +00:00
|
|
|
FocusedChanged(this, EventArgs.Empty);
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
|
|
|
private void OnDeactivate()
|
|
|
|
{
|
|
|
|
mIsActive = false;
|
2010-10-28 09:31:00 +00:00
|
|
|
FocusedChanged(this, EventArgs.Empty);
|
2009-11-16 18:45:41 +00:00
|
|
|
}
|
2009-08-17 09:34:15 +00:00
|
|
|
|
2009-11-16 18:45:41 +00:00
|
|
|
#endregion
|
2009-06-02 15:49:39 +00:00
|
|
|
|
2010-10-28 09:31:00 +00:00
|
|
|
public event EventHandler<EventArgs> Move = delegate { };
|
|
|
|
public event EventHandler<EventArgs> Resize = delegate { };
|
|
|
|
public event EventHandler<CancelEventArgs> Closing = delegate { };
|
|
|
|
public event EventHandler<EventArgs> Closed = delegate { };
|
|
|
|
public event EventHandler<EventArgs> Disposed = delegate { };
|
|
|
|
public event EventHandler<EventArgs> IconChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> TitleChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> VisibleChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> FocusedChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> WindowBorderChanged = delegate { };
|
|
|
|
public event EventHandler<EventArgs> WindowStateChanged = delegate { };
|
|
|
|
public event EventHandler<KeyPressEventArgs> KeyPress = delegate { };
|
|
|
|
public event EventHandler<EventArgs> MouseEnter = delegate { };
|
|
|
|
public event EventHandler<EventArgs> MouseLeave = delegate { };
|
2009-10-27 23:57:44 +00:00
|
|
|
|
2009-06-02 15:49:39 +00:00
|
|
|
#endregion
|
2009-02-22 10:43:35 +00:00
|
|
|
}
|
|
|
|
}
|