aboutsummaryrefslogtreecommitdiff
path: root/source/ShiftUI/Internal/EventHandler.cs
diff options
context:
space:
mode:
authorMichael VanOverbeek <[email protected]>2016-07-25 12:57:52 -0400
committerGitHub <[email protected]>2016-07-25 12:57:52 -0400
commit46c1c31302f111a1f3ec23a70e6f3986a9aa2a27 (patch)
treef00af7ea3f6ad2641fb26fa1d310fd8b7179b39c /source/ShiftUI/Internal/EventHandler.cs
parentaf48e774189596b8d7a058c564a7d6d75205ca03 (diff)
parent6fa16209519896de09949a27425dff00ebf2970a (diff)
downloadshiftos-c--46c1c31302f111a1f3ec23a70e6f3986a9aa2a27.tar.gz
shiftos-c--46c1c31302f111a1f3ec23a70e6f3986a9aa2a27.tar.bz2
shiftos-c--46c1c31302f111a1f3ec23a70e6f3986a9aa2a27.zip
Merge pull request #17 from MichaelTheShifter/shiftui_integration
Shiftui integration
Diffstat (limited to 'source/ShiftUI/Internal/EventHandler.cs')
-rw-r--r--source/ShiftUI/Internal/EventHandler.cs184
1 files changed, 184 insertions, 0 deletions
diff --git a/source/ShiftUI/Internal/EventHandler.cs b/source/ShiftUI/Internal/EventHandler.cs
new file mode 100644
index 0000000..673e3d0
--- /dev/null
+++ b/source/ShiftUI/Internal/EventHandler.cs
@@ -0,0 +1,184 @@
+// 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 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.
+//
+// Copyright (c) 2007 Novell, Inc.
+//
+// Authors:
+// Geoff Norton <[email protected]>
+//
+//
+
+using System;
+using System.Runtime.InteropServices;
+
+namespace ShiftUI.CarbonInternal {
+ internal delegate int EventDelegate (IntPtr callref, IntPtr eventref, IntPtr user_data);
+
+ internal class EventHandler {
+ internal static EventDelegate EventHandlerDelegate = new EventDelegate (EventCallback);
+ internal static XplatUICarbon Driver;
+
+ internal const int EVENT_NOT_HANDLED = 0;
+ internal const int EVENT_HANDLED = -9874;
+
+ internal const uint kEventClassMouse = 1836021107;
+ internal const uint kEventClassKeyboard = 1801812322;
+ internal const uint kEventClassTextInput = 1952807028;
+ internal const uint kEventClassApplication = 1634758764;
+ internal const uint kEventClassAppleEvent = 1701867619;
+ internal const uint kEventClassMenu = 1835363957;
+ internal const uint kEventClassWindow = 2003398244;
+ internal const uint kEventClassWidget = 1668183148;
+ internal const uint kEventClassCommand = 1668113523;
+ internal const uint kEventClassTablet = 1952607348;
+ internal const uint kEventClassVolume = 1987013664;
+ internal const uint kEventClassAppearance = 1634758765;
+ internal const uint kEventClassService = 1936028278;
+ internal const uint kEventClassToolbar = 1952604530;
+ internal const uint kEventClassToolbarItem = 1952606580;
+ internal const uint kEventClassAccessibility = 1633903461;
+ internal const uint kEventClassHIObject = 1751740258;
+
+ internal static EventTypeSpec [] HIObjectEvents = new EventTypeSpec [] {
+ new EventTypeSpec (kEventClassHIObject, HIObjectHandler.kEventHIObjectConstruct),
+ new EventTypeSpec (kEventClassHIObject, HIObjectHandler.kEventHIObjectInitialize),
+ new EventTypeSpec (kEventClassHIObject, HIObjectHandler.kEventHIObjectDestruct)
+ };
+ internal static EventTypeSpec [] WidgetEvents = new EventTypeSpec [] {
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetBoundsChanged),
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetDraw),
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetDragEnter),
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetDragWithin),
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetDragLeave),
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetDragReceive),
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetGetFocusPart),
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetInitialize),
+ new EventTypeSpec (kEventClassWidget, WidgetHandler.kEventWidgetVisibilityChanged)
+ };
+
+ internal static EventTypeSpec [] ApplicationEvents = new EventTypeSpec[] {
+ new EventTypeSpec (kEventClassApplication, ApplicationHandler.kEventAppActivated),
+ new EventTypeSpec (kEventClassApplication, ApplicationHandler.kEventAppDeactivated)
+ };
+
+ private static EventTypeSpec [] WindowEvents = new EventTypeSpec[] {
+ new EventTypeSpec (kEventClassMouse, MouseHandler.kEventMouseMoved),
+ new EventTypeSpec (kEventClassMouse, MouseHandler.kEventMouseDragged),
+ new EventTypeSpec (kEventClassMouse, MouseHandler.kEventMouseDown),
+ new EventTypeSpec (kEventClassMouse, MouseHandler.kEventMouseUp),
+ new EventTypeSpec (kEventClassMouse, MouseHandler.kEventMouseWheelMoved),
+ new EventTypeSpec (kEventClassMouse, MouseHandler.kEventMouseScroll),
+
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowDeactivated),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowActivated),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowDeactivated),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowCollapsed),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowCollapsing),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowExpanded),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowExpanding),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowBoundsChanged),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowResizeStarted),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowResizeCompleted),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowClose),
+ new EventTypeSpec (kEventClassWindow, WindowHandler.kEventWindowShown),
+
+ new EventTypeSpec (kEventClassKeyboard, KeyboardHandler.kEventRawKeyModifiersChanged),
+ new EventTypeSpec (kEventClassKeyboard, KeyboardHandler.kEventRawKeyDown),
+ new EventTypeSpec (kEventClassKeyboard, KeyboardHandler.kEventRawKeyRepeat),
+ new EventTypeSpec (kEventClassKeyboard, KeyboardHandler.kEventRawKeyUp),
+ new EventTypeSpec (kEventClassTextInput, KeyboardHandler.kEventTextInputUnicodeForKeyEvent)
+ };
+
+ internal static int EventCallback (IntPtr callref, IntPtr eventref, IntPtr handle) {
+ uint klass = GetEventClass (eventref);
+ uint kind = GetEventKind (eventref);
+ MSG msg = new MSG ();
+ IEventHandler handler = null;
+
+ switch (klass) {
+ case kEventClassHIObject: {
+ handler = (IEventHandler) Driver.HIObjectHandler;
+ break;
+ }
+ case kEventClassKeyboard:
+ case kEventClassTextInput:
+ handler = (IEventHandler) Driver.KeyboardHandler;
+ break;
+ case kEventClassWindow:
+ handler = (IEventHandler) Driver.WindowHandler;
+ break;
+ case kEventClassMouse:
+ handler = (IEventHandler) Driver.MouseHandler;
+ break;
+ case kEventClassWidget:
+ handler = (IEventHandler) Driver.WidgetHandler;
+ break;
+ case kEventClassApplication:
+ handler = (IEventHandler) Driver.ApplicationHandler;
+ break;
+ default:
+ return EVENT_NOT_HANDLED;
+ }
+
+ if (handler.ProcessEvent (callref, eventref, handle, kind, ref msg)) {
+ Driver.EnqueueMessage (msg);
+ return EVENT_HANDLED;
+ }
+
+ return EVENT_NOT_HANDLED;
+ }
+
+ internal static bool TranslateMessage (ref MSG msg) {
+ bool result = false;
+
+ if (!result)
+ result = Driver.KeyboardHandler.TranslateMessage (ref msg);
+ if (!result)
+ result = Driver.MouseHandler.TranslateMessage (ref msg);
+
+ return result;
+ }
+
+ internal static void InstallApplicationHandler () {
+ InstallEventHandler (GetApplicationEventTarget (), EventHandlerDelegate, (uint)ApplicationEvents.Length, ApplicationEvents, IntPtr.Zero, IntPtr.Zero);
+ }
+
+ internal static void InstallWidgetHandler (IntPtr Widget) {
+ InstallEventHandler (GetWidgetEventTarget (Widget), EventHandlerDelegate, (uint)WidgetEvents.Length, WidgetEvents, Widget, IntPtr.Zero);
+ }
+
+ internal static void InstallWindowHandler (IntPtr window) {
+ InstallEventHandler (GetWindowEventTarget (window), EventHandlerDelegate, (uint)WindowEvents.Length, WindowEvents, window, IntPtr.Zero);
+ }
+
+ [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+ static extern IntPtr GetApplicationEventTarget ();
+ [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+ internal static extern IntPtr GetWidgetEventTarget (IntPtr Widget);
+ [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+ internal static extern IntPtr GetWindowEventTarget (IntPtr window);
+
+ [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+ internal static extern uint GetEventClass (IntPtr eventref);
+ [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+ static extern uint GetEventKind (IntPtr eventref);
+
+ [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+ static extern int InstallEventHandler (IntPtr window, EventDelegate event_handler, uint count, EventTypeSpec [] types, IntPtr user_data, IntPtr handlerref);
+ }
+}