Imported Upstream version 4.2.0.179

Former-commit-id: 0a113cb3a6feb7873f632839b1307cc6033cd595
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent 183bba2c9a
commit 6992685b86
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -0,0 +1,78 @@
// 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:
//
// 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 <gnorton@novell.com>
//
//
using System;
namespace System.Windows.Forms.CarbonInternal {
internal class ApplicationHandler : EventHandlerBase, IEventHandler {
internal const uint kEventAppActivated = 1;
internal const uint kEventAppDeactivated = 2;
internal const uint kEventAppQuit = 3;
internal const uint kEventAppLaunchNotification = 4;
internal const uint kEventAppLaunched = 5;
internal const uint kEventAppTerminated = 6;
internal const uint kEventAppFrontSwitched = 7;
internal const uint kEventAppFocusMenuBar = 8;
internal const uint kEventAppFocusNextDocumentWindow = 9;
internal const uint kEventAppFocusNextFloatingWindow = 10;
internal const uint kEventAppFocusToolbar = 11;
internal const uint kEventAppFocusDrawer = 12;
internal const uint kEventAppGetDockTileMenu = 20;
internal const uint kEventAppIsEventInInstantMouser = 104;
internal const uint kEventAppHidden = 107;
internal const uint kEventAppShown = 108;
internal const uint kEventAppSystemUIModeChanged = 109;
internal const uint kEventAppAvailableWindowBoundsChanged = 110;
internal const uint kEventAppActiveWindowChanged = 111;
internal ApplicationHandler (XplatUICarbon driver) : base (driver) {}
public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
switch (kind) {
case kEventAppActivated: {
foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows)
if (!XplatUICarbon.IsWindowVisible (utility_window))
XplatUICarbon.ShowWindow (utility_window);
break;
}
case kEventAppDeactivated: {
if (XplatUICarbon.FocusWindow != IntPtr.Zero) {
Driver.SendMessage (XplatUICarbon.FocusWindow, Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
}
if (XplatUICarbon.Grab.Hwnd != IntPtr.Zero) {
Driver.SendMessage (Hwnd.ObjectFromHandle (XplatUICarbon.Grab.Hwnd).Handle, Msg.WM_LBUTTONDOWN, (IntPtr)MsgButtons.MK_LBUTTON, (IntPtr) (Driver.MousePosition.X << 16 | Driver.MousePosition.Y));
}
foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows)
if (XplatUICarbon.IsWindowVisible (utility_window))
XplatUICarbon.HideWindow (utility_window);
break;
}
}
return true;
}
}
}

View File

@@ -0,0 +1,261 @@
2009-06-26 Atsushi Enomoto <atsushi@ximian.com>
* KeyboardHandler.cs : support multi-byte text input.
Fixed bug #501276.
2009-01-07 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Don't attempt to activate a disposed Form.
Fixes several of the nunit winforms crashes on Mac.
2008-08-14 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Revert the change which didn't set ActiveWindow
here and fix the problem in the driver. Fully fixes #393317.
2008-08-01 Geoff Norton <gnorton@novell.com>
* CarbonCursor.cs: If the window doesn't have a cursor set, revert
to the default. Fixes #411114.
2008-07-31 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Dont set ActiveWindow when emitting the event,
its set when the event is handled. Fixes #393317.
2008-05-10 Geoff Norton <gnorton@novell.com>
* MouseHandler.cs: Fix the generation of msg.wParam for mouse up/down
events. Fixes #368041
2008-05-10 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Send ENTER/EXITSIZEMOVE when doing minimize/maximize
events as well as resize events. Fixes #346529
2008-05-10 Geoff Norton <gnorton@novell.com>
* EventHandler.cs: Subscribe to Collapsed/Expanded.
* WindowHandler.cs: Send WINDOWPOSCHANGED with Collapsed/Expanded. Fixes
#325122
2008-05-10 Geoff Norton <gnorton@novell.com>
* MouseHandler.cs: For some reason carbon gives us kEventMouseDown
in the grow box, but not kEventMouseUp. If a form has a managed resize
grow box under our unmanaged one, it can get confused into thinking the
mouse is permanantly down. Lets just not report grow box events.
Fixes #381097
2008-05-10 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Properly raise inactiate/activate events
Partially fixes #386504
2008-04-11 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Move the caret back to the real screen position
after a window bounds is changed.
2008-04-11 Geoff Norton <gnorton@novell.com>
* KeyboardHandler.cs: Fix keyboard support on little endian
architectures.
2008-03-21 Geoff Norton <gnorton@novell.com>
* KeyboardHandler.cs: Fix mapping of Delete.
2008-02-26 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Send WM_CLOSE instead of WM_DESTROY. Fixes
#364281
2008-02-14 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Ensure we send WM_ACTIVATE when we activate our
Form. Fixes #360721
2008-02-04 Geoff Norton <gnorton@novell.com>
* KeyboardHandler.cs: Filter the translate call.
2008-02-04 Geoff Norton <gnorton@novell.com>
* KeyboardHandler.cs: Commit support for the last batch of keytypes
(F1-12; Fn+modifiers; etc).
2008-02-04 Geoff Norton <gnorton@novell.com>
* KeyboardHandler.cs: lParam should be cleared in the broken menu
filter case.
2008-02-04 Geoff Norton <gnorton@novell.com>
* KeyboardHandler.cs: Control+key does not generate SYSKEY, it prevents
SYSKEY (ctrl+alt+foo). Also implement broken menu keyup filtering.
2008-02-04 Geoff Norton <gnorton@novell.com>
* KeyboardHandler.cs: Control+key generates SYSKEY/SYSCHAR as well
as Alt+key.
2008-02-04 Geoff Norton <gnorton@novell.com>
* EventHandler.cs: Expose GetEventClass internally. Subscribe to
the unicode text events.
* KeyboardHandler.cs: Commit the new keyboard handler. We grab
the unicode characters provided by apple and push them thru a translation
table to generate windows style keyboard events.
2008-01-28 Geoff Norton <gnorton@novell.com>
* EventHandler.cs: Subscribe ot ResizeBegin and ResizeEnd events.
* WindowHandler.cs: Send WM_ENTERSIZEMOVE and WM_EXITSIZEMOVE
2008-01-23 Geoff Norton <gnorton@novell.com>
* Cursor.cs: Expose the colors to avoid some warnings until we use them
2008-01-23 Geoff Norton <gnorton@novell.com>
* MouseHandler.cs: Send HITTEST events.
* Cursor.cs: Initial support for Theme cursors. Custom cursors not
quite yet.
2008-01-23 Geoff Norton <gnorton@novell.com>
* ControlHandler.cs: Remove some dead code that was causing warnings.
2008-01-22 Geoff Norton <gnorton@novell.com>
* EventHandler.cs: Subscribe to the MouseWheel and MouseScroll events.
* MouseHandler.cs: Post MOUSEWHEEL events when scrolling with old
mice, and mighty mice, and two-finger scrolling.
2008-01-16 Geoff Norton <gnorton@novell.com>
* ControlHandler.cs: Flicker be gone! Generate our messages in
AddExpose instead of trusting apples compositing manager which doesn't
work for our use case.
2008-01-16 Geoff Norton <gnorton@novell.com>
* ControlHandler.cs: Dont send another invalidate when carbon
already knows that the control is dirty.
2008-01-16 Geoff Norton <gnorton@novell.com>
* KeyboardHandler.cs: Track the control key(s) as well and put them
into KeyboardModifiers as toggled.
* MouseHandler.cs: Support simulating right click on single-button
mouse macintoshs with the standard Control+Click usage pattern.
2008-01-15 Geoff Norton <gnorton@novell.com>
* ControlHandler.cs: Only mark the dirty area as dirty when we are
told to expose by the subsystem.
2008-01-15 Geoff Norton <gnorton@novell.com>
* MouseHandler.cs: Avoid a NRE if we dont know the window the event
came in on.
2008-01-15 Geoff Norton <gnorton@novell.com>
* ApplicationHandler.cs: Fix the Grab declaration.
* MouseHandler.cs: Fix the grab declaration and a minor optimization.
2008-01-10 Geoff Norton <gnorton@novell.com>
* ControlHAndler.cs: Mark all dirty areas as dirty with the Hwnd system.
2008-01-10 Geoff Norton <gnorton@novell.com>
* ControlHandler.cs: Ensure we send controls a WM_WINDOWPOSCHANGED
when their bounds are changed by the carbon system. Fixes initial sizing
of PDN DocumentWorkspace bug.
2008-01-09 Geoff Norton <gnorton@novell.com>
* WindowHandler.cs: Hide utility windows when the window is minimizing
or deactivating. Show them when the window is restored.
* ApplicationHandler.cs: Hide the utility windows when the app
deactivates. Restore them when we get focus back.
2008-01-04 Geoff Norton <gnorton@novell.com>
* Enums.cs: Fix a typo
* MouseHandler.cs: Send NC events in global coordinates.
2007-12-21 Geoff Norton <gnorton@novell.com>
* Dnd.cs: Flush the message queue during drag callbacks. This allows
queued paints to occur when we're dragging.
2007-12-21 Geoff Norton <gnorton@novell.com>
* Dnd.cs: Add support for D&D of objects internally and serialized
objects across instances.
2007-12-21 Geoff Norton <gnorton@novell.com>
* *Handler.cs: Update the ProcessEvent method to pass the callref
in as well.
* ControlHandler.cs: Direct the kEventControlDrag events to our
Dnd implementation.
* EventHandler.cs: Register kEventControlDrag event callbacks and
HIObject subclassing callbacks.
* KeyboardHandler.cs: Keep some key modifiers in a Keys state.
* MouseHandler.cs: Dont prevent non-hwnd events from going to the next
Event handler.
* Dnd.cs: Initial D&D implementation. Supports dragging internally
and from finder->mwf apps.
* Pasteboard.cs: Initial clipboard support.
* HIObjectHandler.cs: Subclass HIView and run our own specialized
native object constructor. This is required for dnd.
2007-12-07 Geoff Norton <gnorton@novell.com>
* ControlHandler.cs: Properly update our invalidated information when
Quartz asks us to redraw. This helps fix TabControl but introduces
over-zealous drawing causing our flicker. Implement visibility tracking
to generate out WM_SHOWWINDOW calls. Refactor mouse tracking to live
entirely in MouseHandler.
* EventHandler.cs: Unregister some events we no longer handle. Register
the new MouseEvents that we do handle.
* KeyboardHandler.cs: Implement some more key translations.
* MouseHandler.cs: Handle all mouse events at the application level now
This allows us to paint while dragging the mouse, and handle double
click events properly.
* WindowHandler.cs: Properly generate WM_SHOWWINDOW messages when
our application window is exposed.
2007-11-21 Geoff Norton <gnorton@novell.com>
* ControlHandler.cs: Allow custom HIView to get keyboard focus.
* Enums.cs: Remove some unused Enums.
* EventHandler.cs: Make controls listen to kEventControlGetFocusPart
* KeyboardHandler.cs: Get the focus control from Carbon before returning control from the function
2007-11-15 Geoff Norton <gnorton@novell.com>
* EventHandler.cs: The new event handler dispatcher for the Carbon port.
Every event is dispatched thru this class and directed to the appropriate
event type handler.
* ApplicationHandler.cs: Handles the application level events AppActivated
and AppDeactivated. We hook these to remove overlay windows when the application
looses focus.
* ControlHandler.cs: Handles the control level events Click, Track, Draw and BoundsChanged.
Translates these events to their WndProc equivalents and routes them to the appropriate
Control.
* KeyboardHandler.cs: Handles the keyboard level events KeyDown, KeyUp, KeyRepeat, KeyModifiersChanged
translated them to the WndProc message and routes it to the keyboard focus control.
* MouseHandler.cs: Handles the global mouse events and sends the appropriate WM_MOUSEMOVE to the
control affected.
* WindowHandler.cs: Handles the window level events BoundsChanged and Close and resizes the Hwnds
or destroys them accordingly.
* EventHandlerBase.cs: Base class for all the EventHandlers.
* IEventHandler.cs: Interface declaring the methods needed for all EventHandlers.
* Enums.cs: Contains needed enums for the Carbon port.
* Structs.cs: Contains all the needed structs for the Carbon port.

View File

@@ -0,0 +1,229 @@
// 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:
//
// 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 <gnorton@novell.com>
//
//
using System;
using System.Drawing;
using System.Runtime.InteropServices;
namespace System.Windows.Forms.CarbonInternal {
internal class ControlHandler : EventHandlerBase, IEventHandler {
internal const uint kEventControlInitialize = 1000;
internal const uint kEventControlDispose = 1001;
internal const uint kEventControlGetOptimalBounds = 1003;
internal const uint kEventControlDefInitialize = kEventControlInitialize;
internal const uint kEventControlDefDispose = kEventControlDispose;
internal const uint kEventControlHit = 1;
internal const uint kEventControlSimulateHit = 2;
internal const uint kEventControlHitTest = 3;
internal const uint kEventControlDraw = 4;
internal const uint kEventControlApplyBackground = 5;
internal const uint kEventControlApplyTextColor = 6;
internal const uint kEventControlSetFocusPart = 7;
internal const uint kEventControlGetFocusPart = 8;
internal const uint kEventControlActivate = 9;
internal const uint kEventControlDeactivate = 10;
internal const uint kEventControlSetCursor = 11;
internal const uint kEventControlContextualMenuClick = 12;
internal const uint kEventControlClick = 13;
internal const uint kEventControlGetNextFocusCandidate = 14;
internal const uint kEventControlGetAutoToggleValue = 15;
internal const uint kEventControlInterceptSubviewClick = 16;
internal const uint kEventControlGetClickActivation = 17;
internal const uint kEventControlDragEnter = 18;
internal const uint kEventControlDragWithin = 19;
internal const uint kEventControlDragLeave = 20;
internal const uint kEventControlDragReceive = 21;
internal const uint kEventControlInvalidateForSizeChange = 22;
internal const uint kEventControlTrackingAreaEntered = 23;
internal const uint kEventControlTrackingAreaExited = 24;
internal const uint kEventControlTrack = 51;
internal const uint kEventControlGetScrollToHereStartPoint = 52;
internal const uint kEventControlGetIndicatorDragConstraint = 53;
internal const uint kEventControlIndicatorMoved = 54;
internal const uint kEventControlGhostingFinished = 55;
internal const uint kEventControlGetActionProcPart = 56;
internal const uint kEventControlGetPartRegion = 101;
internal const uint kEventControlGetPartBounds = 102;
internal const uint kEventControlSetData = 103;
internal const uint kEventControlGetData = 104;
internal const uint kEventControlGetSizeConstraints= 105;
internal const uint kEventControlGetFrameMetrics = 106;
internal const uint kEventControlValueFieldChanged = 151;
internal const uint kEventControlAddedSubControl = 152;
internal const uint kEventControlRemovingSubControl = 153;
internal const uint kEventControlBoundsChanged = 154;
internal const uint kEventControlVisibilityChanged = 157;
internal const uint kEventControlTitleChanged = 158;
internal const uint kEventControlOwningWindowChanged = 159;
internal const uint kEventControlHiliteChanged = 160;
internal const uint kEventControlEnabledStateChanged = 161;
internal const uint kEventControlLayoutInfoChanged = 162;
internal const uint kEventControlArbitraryMessage = 201;
internal const uint kEventParamCGContextRef = 1668183160;
internal const uint kEventParamDirectObject = 757935405;
internal const uint kEventParamControlPart = 1668313716;
internal const uint kEventParamControlLikesDrag = 1668047975;
internal const uint kEventParamRgnHandle = 1919381096;
internal const uint typeControlRef = 1668575852;
internal const uint typeCGContextRef = 1668183160;
internal const uint typeQDPoint = 1363439732;
internal const uint typeQDRgnHandle = 1919381096;
internal const uint typeControlPartCode = 1668313716;
internal const uint typeBoolean = 1651470188;
internal ControlHandler (XplatUICarbon driver) : base (driver) {}
public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
Hwnd hwnd;
bool client;
GetEventParameter (eventref, kEventParamDirectObject, typeControlRef, IntPtr.Zero, (uint) Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref handle);
hwnd = Hwnd.ObjectFromHandle (handle);
if (hwnd == null)
return false;
msg.hwnd = hwnd.Handle;
client = (hwnd.ClientWindow == handle ? true : false);
switch (kind) {
case kEventControlDraw: {
IntPtr rgn = IntPtr.Zero;
HIRect bounds = new HIRect ();
GetEventParameter (eventref, kEventParamRgnHandle, typeQDRgnHandle, IntPtr.Zero, (uint) Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref rgn);
if (rgn != IntPtr.Zero) {
Rect rbounds = new Rect ();
GetRegionBounds (rgn, ref rbounds);
bounds.origin.x = rbounds.left;
bounds.origin.y = rbounds.top;
bounds.size.width = rbounds.right - rbounds.left;
bounds.size.height = rbounds.bottom - rbounds.top;
} else {
HIViewGetBounds (handle, ref bounds);
}
if (!hwnd.visible) {
if (client) {
hwnd.expose_pending = false;
} else {
hwnd.nc_expose_pending = false;
}
return false;
}
if (!client) {
DrawBorders (hwnd);
}
Driver.AddExpose (hwnd, client, bounds);
return true;
}
case kEventControlVisibilityChanged: {
if (client) {
msg.message = Msg.WM_SHOWWINDOW;
msg.lParam = (IntPtr) 0;
msg.wParam = (HIViewIsVisible (handle) ? (IntPtr)1 : (IntPtr)0);
return true;
}
return false;
}
case kEventControlBoundsChanged: {
HIRect view_frame = new HIRect ();
HIViewGetFrame (handle, ref view_frame);
if (!client) {
hwnd.X = (int) view_frame.origin.x;
hwnd.Y = (int) view_frame.origin.y;
hwnd.Width = (int) view_frame.size.width;
hwnd.Height = (int) view_frame.size.height;
Driver.PerformNCCalc (hwnd);
}
msg.message = Msg.WM_WINDOWPOSCHANGED;
msg.hwnd = hwnd.Handle;
return true;
}
case kEventControlGetFocusPart: {
short pcode = 0;
SetEventParameter (eventref, kEventParamControlPart, typeControlPartCode, (uint)Marshal.SizeOf (typeof (short)), ref pcode);
return false;
}
case kEventControlDragEnter:
case kEventControlDragWithin:
case kEventControlDragLeave:
case kEventControlDragReceive:
return Dnd.HandleEvent (callref, eventref, handle, kind, ref msg);
}
return false;
}
private void DrawBorders (Hwnd hwnd) {
switch (hwnd.border_style) {
case FormBorderStyle.Fixed3D: {
Graphics g;
g = Graphics.FromHwnd(hwnd.whole_window);
if (hwnd.border_static)
ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Border3DStyle.SunkenOuter);
else
ControlPaint.DrawBorder3D(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Border3DStyle.Sunken);
g.Dispose();
break;
}
case FormBorderStyle.FixedSingle: {
Graphics g;
g = Graphics.FromHwnd(hwnd.whole_window);
ControlPaint.DrawBorder(g, new Rectangle(0, 0, hwnd.Width, hwnd.Height), Color.Black, ButtonBorderStyle.Solid);
g.Dispose();
break;
}
}
}
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetRegionBounds (IntPtr rgnhandle, ref Rect region);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref IntPtr data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int SetEventParameter (IntPtr eventref, uint name, uint type, uint size, ref short data);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int HIViewGetBounds (IntPtr handle, ref HIRect rect);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int HIViewGetFrame (IntPtr handle, ref HIRect rect);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static bool HIViewIsVisible (IntPtr vHnd);
}
}

View File

@@ -0,0 +1,245 @@
// 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:
//
// 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) 2008 Novell, Inc.
//
// Authors:
// Geoff Norton (gnorton@novell.com)
//
//
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace System.Windows.Forms.CarbonInternal {
internal class Cursor {
internal static CarbonCursor defcur = new CarbonCursor (StdCursor.Default);
internal static Bitmap DefineStdCursorBitmap (StdCursor id) {
// FIXME
return new Bitmap (16, 16);
}
internal static IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
CarbonCursor cc = new CarbonCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
return (IntPtr) GCHandle.Alloc (cc);
}
internal static IntPtr DefineStdCursor (StdCursor id) {
CarbonCursor cc = new CarbonCursor (id);
return (IntPtr) GCHandle.Alloc (cc);
}
internal static void SetCursor (IntPtr cursor) {
if (cursor == IntPtr.Zero) {
defcur.SetCursor ();
return;
}
CarbonCursor cc = (CarbonCursor) ((GCHandle) cursor).Target;
cc.SetCursor ();
}
}
internal struct CarbonCursor {
private Bitmap bmp;
private Bitmap mask;
private Color cursor_color;
private Color mask_color;
private int hot_x;
private int hot_y;
private StdCursor id;
private bool standard;
public CarbonCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
this.id = StdCursor.Default;
this.bmp = bitmap;
this.mask = mask;
this.cursor_color = cursor_pixel;
this.mask_color = mask_pixel;
this.hot_x = xHotSpot;
this.hot_y = yHotSpot;
standard = true;
}
public CarbonCursor (StdCursor id) {
this.id = id;
this.bmp = null;
this.mask = null;
this.cursor_color = Color.Black;
this.mask_color = Color.Black;
this.hot_x = 0;
this.hot_y = 0;
standard = true;
}
public StdCursor StdCursor {
get {
return id;
}
}
public Bitmap Bitmap {
get {
return bmp;
}
}
public Bitmap Mask {
get {
return mask;
}
}
public Color CursorColor {
get {
return cursor_color;
}
}
public Color MaskColor {
get {
return mask_color;
}
}
public int HotSpotX {
get {
return hot_x;
}
}
public int HotSpotY {
get {
return hot_y;
}
}
public void SetCursor () {
if (standard)
SetStandardCursor ();
else
SetCustomCursor ();
}
public void SetCustomCursor () {
throw new NotImplementedException ("We dont support custom cursors yet");
}
public void SetStandardCursor () {
switch (id) {
case StdCursor.AppStarting:
SetThemeCursor (ThemeCursor.kThemeSpinningCursor);
break;
case StdCursor.Arrow:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.Cross:
SetThemeCursor (ThemeCursor.kThemeCrossCursor);
break;
case StdCursor.Default:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.Hand:
SetThemeCursor (ThemeCursor.kThemeOpenHandCursor);
break;
case StdCursor.Help:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.HSplit:
SetThemeCursor (ThemeCursor.kThemeResizeLeftRightCursor);
break;
case StdCursor.IBeam:
SetThemeCursor (ThemeCursor.kThemeIBeamCursor);
break;
case StdCursor.No:
SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
break;
case StdCursor.NoMove2D:
SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
break;
case StdCursor.NoMoveHoriz:
SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
break;
case StdCursor.NoMoveVert:
SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
break;
case StdCursor.PanEast:
SetThemeCursor (ThemeCursor.kThemeResizeRightCursor);
break;
case StdCursor.PanNE:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.PanNorth:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.PanNW:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.PanSE:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.PanSouth:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.PanSW:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.PanWest:
SetThemeCursor (ThemeCursor.kThemeResizeLeftCursor);
break;
case StdCursor.SizeAll:
SetThemeCursor (ThemeCursor.kThemeResizeLeftRightCursor);
break;
case StdCursor.SizeNESW:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.SizeNS:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.SizeNWSE:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.SizeWE:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.UpArrow:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.VSplit:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
case StdCursor.WaitCursor:
SetThemeCursor (ThemeCursor.kThemeSpinningCursor);
break;
default:
SetThemeCursor (ThemeCursor.kThemeArrowCursor);
break;
}
return;
}
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int SetThemeCursor (ThemeCursor cursor);
}
}

View File

@@ -0,0 +1,371 @@
// 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:
//
// 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 (gnorton@novell.com)
//
//
using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Collections;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
namespace System.Windows.Forms.CarbonInternal {
internal delegate void DragTrackingDelegate (short message, IntPtr window, IntPtr data, IntPtr dragref);
internal class Dnd {
internal const uint kEventParamDragRef = 1685217639;
internal const uint typeDragRef = 1685217639;
internal const uint typeMono = 1836019311;
internal const uint typeMonoSerializedObject = 1836279154;
private static DragDropEffects effects = DragDropEffects.None;
private static DragTrackingDelegate DragTrackingHandler = new DragTrackingDelegate (TrackingCallback);
static Dnd () {
try {
InstallTrackingHandler (DragTrackingHandler, IntPtr.Zero, IntPtr.Zero);
} catch (EntryPointNotFoundException) {
// it is deprecated in 10.6 and does not exist anymore.
}
}
internal Dnd () {
}
internal static void TrackingCallback (short message, IntPtr window, IntPtr data, IntPtr dragref) {
XplatUICarbon.GetInstance ().FlushQueue ();
}
internal static DragDropEffects DragActionsToEffects (UInt32 actions) {
DragDropEffects effects = DragDropEffects.None;
if ((actions & 1) != 0)
effects |= DragDropEffects.Copy;
if ((actions & (1 << 4)) != 0)
effects |= DragDropEffects.Move;
if ((actions & 0xFFFFFFFF) != 0)
effects |= DragDropEffects.All;
return effects;
}
internal static DataObject DragToDataObject (IntPtr dragref) {
UInt32 items = 0;
ArrayList flavorlist = new ArrayList ();
CountDragItems (dragref, ref items);
for (uint item_counter = 1; item_counter <= items; item_counter++) {
IntPtr itemref = IntPtr.Zero;
UInt32 flavors = 0;
GetDragItemReferenceNumber (dragref, item_counter, ref itemref);
CountDragItemFlavors (dragref, itemref, ref flavors);
for (uint flavor_counter = 1; flavor_counter <= flavors; flavor_counter++) {
FlavorHandler flavor = new FlavorHandler (dragref, itemref, flavor_counter);
if (flavor.Supported)
flavorlist.Add (flavor);
}
}
if (flavorlist.Count > 0) {
return ((FlavorHandler) flavorlist [0]).Convert (flavorlist);
}
return new DataObject ();
}
internal static bool HandleEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
Control control;
DataObject data;
DragEventArgs drag_event;
DragDropEffects allowed;
QDPoint point = new QDPoint ();
UInt32 actions = 0;
IntPtr dragref = IntPtr.Zero;
Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
if (hwnd == null || hwnd.Handle != handle)
return false;
GetEventParameter (eventref, kEventParamDragRef, typeDragRef, IntPtr.Zero, (uint) Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref dragref);
XplatUICarbon.GetGlobalMouse (ref point);
GetDragAllowableActions (dragref, ref actions);
control = Control.FromHandle (hwnd.Handle);
allowed = DragActionsToEffects (actions);
data = DragToDataObject (dragref);
drag_event = new DragEventArgs (data, 0, point.x, point.y, allowed, DragDropEffects.None);
switch (kind) {
case ControlHandler.kEventControlDragEnter: {
bool accept = control.AllowDrop;
SetEventParameter (eventref, ControlHandler.kEventParamControlLikesDrag, ControlHandler.typeBoolean, (uint)Marshal.SizeOf (typeof (bool)), ref accept);
control.DndEnter (drag_event);
effects = drag_event.Effect;
return false;
}
case ControlHandler.kEventControlDragWithin:
control.DndOver (drag_event);
effects = drag_event.Effect;
break;
case ControlHandler.kEventControlDragLeave:
control.DndLeave (drag_event);
break;
case ControlHandler.kEventControlDragReceive:
control.DndDrop (drag_event);
break;
}
return true;
}
public void SetAllowDrop (Hwnd hwnd, bool allow) {
if (hwnd.allow_drop == allow)
return;
hwnd.allow_drop = allow;
SetControlDragTrackingEnabled (hwnd.whole_window, true);
SetControlDragTrackingEnabled (hwnd.client_window, true);
}
public void SendDrop (IntPtr handle, IntPtr from, IntPtr time) {
}
public DragDropEffects StartDrag (IntPtr handle, object data, DragDropEffects allowed_effects) {
IntPtr dragref = IntPtr.Zero;
EventRecord eventrecord = new EventRecord ();
effects = DragDropEffects.None;
NewDrag (ref dragref);
XplatUICarbon.GetGlobalMouse (ref eventrecord.mouse);
StoreObjectInDrag (handle, dragref, data);
TrackDrag (dragref, ref eventrecord, IntPtr.Zero);
DisposeDrag (dragref);
return effects;
}
public void StoreObjectInDrag (IntPtr handle, IntPtr dragref, object data) {
IntPtr type = IntPtr.Zero;
IntPtr dataptr = IntPtr.Zero;
Int32 size = 0;
if (data is string) {
// implement me
throw new NotSupportedException ("Implement me.");
} else if (data is ISerializable) {
MemoryStream stream = new MemoryStream ();
BinaryFormatter bf = new BinaryFormatter ();
bf.Serialize (stream, data);
dataptr = Marshal.AllocHGlobal ((int) stream.Length);
stream.Seek (0, 0);
for (int i = 0; i < stream.Length; i++) {
Marshal.WriteByte (dataptr, i, (byte) stream.ReadByte ());
}
type = (IntPtr) typeMonoSerializedObject;
size = (int) stream.Length;
} else {
dataptr = (IntPtr) GCHandle.Alloc (data);
type = (IntPtr) typeMono;
size = Marshal.SizeOf (typeof (IntPtr));
}
AddDragItemFlavor (dragref, handle, type, ref dataptr, size, 1 << 0);
}
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int InstallTrackingHandler (DragTrackingDelegate callback, IntPtr window, IntPtr data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref IntPtr data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int SetEventParameter (IntPtr eventref, uint name, uint type, uint size, ref bool data);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int SetControlDragTrackingEnabled (IntPtr view, bool enabled);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int AddDragItemFlavor (IntPtr dragref, IntPtr itemref, IntPtr flavortype, ref IntPtr data, Int32 size, UInt32 flags);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int CountDragItems (IntPtr dragref, ref UInt32 count);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int CountDragItemFlavors (IntPtr dragref, IntPtr itemref, ref UInt32 count);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int GetDragItemReferenceNumber (IntPtr dragref, UInt32 index, ref IntPtr itemref);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int NewDrag (ref IntPtr dragref);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int TrackDrag (IntPtr dragref, ref EventRecord eventrecord, IntPtr region);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int DisposeDrag (IntPtr dragref);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int GetDragAllowableActions (IntPtr dragref, ref UInt32 actions);
}
internal struct EventRecord {
internal UInt16 what;
internal UInt32 message;
internal UInt32 when;
internal QDPoint mouse;
internal UInt16 modifiers;
}
internal class FlavorHandler {
internal IntPtr flavorref;
internal IntPtr dragref;
internal IntPtr itemref;
internal Int32 size;
internal UInt32 flags;
internal byte [] data;
internal string fourcc;
internal FlavorHandler (IntPtr dragref, IntPtr itemref, uint counter) {
GetFlavorType (dragref, itemref, counter, ref flavorref);
GetFlavorFlags (dragref, itemref, flavorref, ref flags);
byte [] fourcc_b = BitConverter.GetBytes ((Int32)flavorref);
this.fourcc = String.Format ("{0}{1}{2}{3}", (char)fourcc_b [3], (char)fourcc_b [2], (char)fourcc_b [1], (char)fourcc_b [0]);
this.dragref = dragref;
this.itemref = itemref;
this.GetData ();
}
internal void GetData () {
GetFlavorDataSize (dragref, itemref, flavorref, ref size);
data = new byte [size];
GetFlavorData (dragref, itemref, flavorref, data, ref size, 0);
}
internal string DataString {
get { return Encoding.Default.GetString (this.data); }
}
internal byte[] DataArray {
get { return this.data; }
}
internal IntPtr DataPtr {
get { return (IntPtr) BitConverter.ToInt32 (this.data, 0); }
}
internal bool Supported {
get {
switch (fourcc) {
case "furl":
return true;
case "mono":
return true;
case "mser":
return true;
}
return false;
}
}
internal DataObject Convert (ArrayList flavorlist) {
switch (fourcc) {
case "furl":
return ConvertToFileDrop (flavorlist);
case "mono":
return ConvertToObject (flavorlist);
case "mser":
return DeserializeObject (flavorlist);
}
return new DataObject ();
}
internal DataObject DeserializeObject (ArrayList flavorlist) {
DataObject data = new DataObject ();
MemoryStream stream = new MemoryStream (this.DataArray);
BinaryFormatter bf = new BinaryFormatter ();
if (stream.Length == 0)
return data;
stream.Seek (0, 0);
data.SetData (bf.Deserialize (stream));
return data;
}
internal DataObject ConvertToObject (ArrayList flavorlist) {
DataObject data = new DataObject ();
foreach (FlavorHandler flavor in flavorlist) {
GCHandle handle = (GCHandle) flavor.DataPtr;
data.SetData (handle.Target);
}
return data;
}
internal DataObject ConvertToFileDrop (ArrayList flavorlist) {
DataObject data = new DataObject ();
ArrayList uri_list = new ArrayList ();
foreach (FlavorHandler flavor in flavorlist) {
try {
uri_list.Add (new Uri (flavor.DataString).LocalPath);
} catch { }
}
string [] l = (string []) uri_list.ToArray (typeof (string));
if (l.Length < 1)
return data;
data.SetData (DataFormats.FileDrop, l);
data.SetData ("FileName", l [0]);
data.SetData ("FileNameW", l [0]);
return data;
}
public override string ToString () {
return fourcc;
}
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int GetFlavorDataSize (IntPtr dragref, IntPtr itemref, IntPtr flavorref, ref Int32 size);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int GetFlavorData (IntPtr dragref, IntPtr itemref, IntPtr flavorref, [In, Out] byte[] data, ref Int32 size, UInt32 offset);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int GetFlavorFlags (IntPtr dragref, IntPtr itemref, IntPtr flavorref, ref UInt32 flags);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
extern static int GetFlavorType (IntPtr dragref, IntPtr itemref, UInt32 index, ref IntPtr flavor);
}
}

View File

@@ -0,0 +1,108 @@
// 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:
//
// 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 <gnorton@customerdna.com>
//
using System;
namespace System.Windows.Forms.CarbonInternal {
internal enum WindowClass : uint {
kAlertWindowClass = 1,
kMovableAlertWindowClass = 2,
kModalWindowClass = 3,
kMovableModalWindowClass = 4,
kFloatingWindowClass = 5,
kDocumentWindowClass = 6,
kUtilityWindowClass = 8,
kHelpWindowClass = 10,
kSheetWindowClass = 11,
kToolbarWindowClass = 12,
kPlainWindowClass = 13,
kOverlayWindowClass = 14,
kSheetAlertWindowClass = 15,
kAltPlainWindowClass = 16,
kDrawerWindowClass = 20,
kAllWindowClasses = 0xFFFFFFFF
}
internal enum WindowAttributes : uint {
kWindowNoAttributes = 0,
kWindowCloseBoxAttribute = (1u << 0),
kWindowHorizontalZoomAttribute = (1u << 1),
kWindowVerticalZoomAttribute = (1u << 2),
kWindowFullZoomAttribute = (kWindowVerticalZoomAttribute | kWindowHorizontalZoomAttribute),
kWindowCollapseBoxAttribute = (1u << 3),
kWindowResizableAttribute = (1u << 4),
kWindowSideTitlebarAttribute = (1u << 5),
kWindowToolbarButtonAttribute = (1u << 6),
kWindowMetalAttribute = (1u << 8),
kWindowNoUpdatesAttribute = (1u << 16),
kWindowNoActivatesAttribute = (1u << 17),
kWindowOpaqueForEventsAttribute = (1u << 18),
kWindowCompositingAttribute = (1u << 19),
kWindowNoShadowAttribute = (1u << 21),
kWindowHideOnSuspendAttribute = (1u << 24),
kWindowStandardHandlerAttribute = (1u << 25),
kWindowHideOnFullScreenAttribute = (1u << 26),
kWindowInWindowMenuAttribute = (1u << 27),
kWindowLiveResizeAttribute = (1u << 28),
kWindowIgnoreClicksAttribute = (1u << 29),
kWindowNoConstrainAttribute = (1u << 31),
kWindowStandardDocumentAttributes = (kWindowCloseBoxAttribute | kWindowFullZoomAttribute | kWindowCollapseBoxAttribute | kWindowResizableAttribute),
kWindowStandardFloatingAttributes = (kWindowCloseBoxAttribute | kWindowCollapseBoxAttribute)
}
internal enum ThemeCursor : uint {
kThemeArrowCursor = 0,
kThemeCopyArrowCursor = 1,
kThemeAliasArrowCursor = 2,
kThemeContextualMenuArrowCursor = 3,
kThemeIBeamCursor = 4,
kThemeCrossCursor = 5,
kThemePlusCursor = 6,
kThemeWatchCursor = 7,
kThemeClosedHandCursor = 8,
kThemeOpenHandCursor = 9,
kThemePointingHandCursor = 10,
kThemeCountingUpHandCursor = 11,
kThemeCountingDownHandCursor = 12,
kThemeCountingUpAndDownHandCursor = 13,
kThemeSpinningCursor = 14,
kThemeResizeLeftCursor = 15,
kThemeResizeRightCursor = 16,
kThemeResizeLeftRightCursor = 17,
kThemeNotAllowedCursor = 18
}
internal enum MouseTrackingResult : ushort {
kMouseTrackingMouseDown = 1,
kMouseTrackingMouseUp = 2,
kMouseTrackingMouseExited = 3,
kMouseTrackingMouseEntered = 4,
kMouseTrackingMouseDragged = 5,
kMouseTrackingKeyModifiersChanged = 6,
kMouseTrackingUserCancelled = 7,
kMouseTrackingTimedOut = 8,
kMouseTrackingMouseMoved = 9
}
}

View File

@@ -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 <gnorton@novell.com>
//
//
using System;
using System.Runtime.InteropServices;
namespace System.Windows.Forms.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 kEventClassControl = 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 [] ControlEvents = new EventTypeSpec [] {
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlBoundsChanged),
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlDraw),
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlDragEnter),
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlDragWithin),
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlDragLeave),
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlDragReceive),
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlGetFocusPart),
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlInitialize),
new EventTypeSpec (kEventClassControl, ControlHandler.kEventControlVisibilityChanged)
};
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 kEventClassControl:
handler = (IEventHandler) Driver.ControlHandler;
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 InstallControlHandler (IntPtr control) {
InstallEventHandler (GetControlEventTarget (control), EventHandlerDelegate, (uint)ControlEvents.Length, ControlEvents, control, 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 GetControlEventTarget (IntPtr control);
[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);
}
}

View File

@@ -0,0 +1,40 @@
// 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:
//
// 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 <gnorton@novell.com>
//
//
using System;
namespace System.Windows.Forms.CarbonInternal {
internal abstract class EventHandlerBase {
internal XplatUICarbon Driver;
public EventHandlerBase () {
}
public EventHandlerBase (XplatUICarbon driver) {
Driver = driver;
}
}
}

View File

@@ -0,0 +1,57 @@
// 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:
//
// 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 <gnorton@novell.com>
//
//
using System;
using System.Runtime.InteropServices;
namespace System.Windows.Forms.CarbonInternal {
internal class HIObjectHandler : EventHandlerBase, IEventHandler {
internal const uint kEventHIObjectConstruct = 1;
internal const uint kEventHIObjectInitialize = 2;
internal const uint kEventHIObjectDestruct = 3;
internal HIObjectHandler (XplatUICarbon driver) : base (driver) {}
public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
switch (kind) {
case kEventHIObjectConstruct:
IntPtr v = IntPtr.Zero;
GetEventParameter (eventref, (uint)1751740265, (uint)1751740258, IntPtr.Zero, 4, IntPtr.Zero, ref v);
return false;
case kEventHIObjectInitialize:
CallNextEventHandler (callref, eventref);
return false;
case kEventHIObjectDestruct:
return false;
}
return false;
}
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int CallNextEventHandler (IntPtr callref, IntPtr eventref);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref IntPtr data);
}
}

View File

@@ -0,0 +1,33 @@
// 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:
//
// 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 <gnorton@novell.com>
//
//
using System;
namespace System.Windows.Forms.CarbonInternal {
internal interface IEventHandler {
bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg);
}
}

View File

@@ -0,0 +1,329 @@
// 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:
//
// 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 (gnorton@novell.com)
//
//
using System;
using System.Collections;
using System.Text;
using System.Globalization;
using System.Runtime.InteropServices;
namespace System.Windows.Forms.CarbonInternal {
internal class KeyboardHandler : EventHandlerBase, IEventHandler {
internal const uint kEventRawKeyDown = 1;
internal const uint kEventRawKeyRepeat = 2;
internal const uint kEventRawKeyUp = 3;
internal const uint kEventRawKeyModifiersChanged = 4;
internal const uint kEventHotKeyPressed = 5;
internal const uint kEventHotKeyReleased = 6;
internal const uint kEventParamKeyMacCharCodes = 1801676914;
internal const uint kEventParamKeyCode = 1801678692;
internal const uint kEventParamKeyModifiers = 1802334052;
internal const uint kEventTextInputUnicodeForKeyEvent = 2;
internal const uint kEventParamTextInputSendText = 1953723512;
internal const uint typeChar = 1413830740;
internal const uint typeUInt32 = 1835100014;
internal const uint typeUnicodeText = 1970567284;
internal static byte [] key_filter_table;
internal static byte [] key_modifier_table;
internal static byte [] key_translation_table;
internal static byte [] char_translation_table;
internal static bool translate_modifier = false;
internal string ComposedString;
static KeyboardHandler () {
// our key filter table is a 256 byte array - if the corresponding byte
// is set the key should be filtered from WM_CHAR (apple pushes unicode events
// for some keys which win32 only handles as KEYDOWN
// currently filtered:
// fn+f* == 16
// left == 28
// right == 29
// up == 30
// down == 31
// Please update this list as well as the table as more keys are found
key_filter_table = new byte [256] {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
// our char translation table is a set of translations from mac char codes
// to win32 vkey codes
// most things map directly
char_translation_table = new byte [256] {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 0x25, 0x27, 0x26, 0x28,
32, 49, 34, 51, 52, 53, 55, 222, 57, 48, 56, 187, 188, 189, 190, 191,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 186, 60, 61, 62, 63,
50, 65, 66, 67, 68, 187, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 219, 220, 221, 54, 189,
192, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 123, 124, 125, 126, 0x2e,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
};
key_translation_table = new byte [256] {
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
0x74, 0x75, 0x76, 0x72, 0x77, 0x78, 0x79, 103, 104, 105, 106, 107, 108, 109, 0x7a, 0x7b,
112, 113, 114, 115, 116, 117, 0x73, 119, 0x71, 121, 0x70, 123, 124, 125, 126, 127,
128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191,
192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207,
208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255
};
// the key modifier table is a state table of the possible modifier keys
// apple currently only goes up to 1 << 14 keys, we've extended this to 32
// bytes as thats the size that apple uses
key_modifier_table = new byte [32];
}
internal KeyboardHandler (XplatUICarbon driver) : base (driver) {}
private void ModifierToVirtualKey (int i, ref MSG msg, bool down) {
msg.hwnd = XplatUICarbon.FocusWindow;
if (i == 9 || i == 13) {
msg.message = (down ? Msg.WM_KEYDOWN : Msg.WM_KEYUP);
msg.wParam = (IntPtr) VirtualKeys.VK_SHIFT;
msg.lParam = IntPtr.Zero;
return;
}
if (i == 12 || i == 14) {
msg.message = (down ? Msg.WM_KEYDOWN : Msg.WM_KEYUP);
msg.wParam = (IntPtr) VirtualKeys.VK_CONTROL;
msg.lParam = IntPtr.Zero;
return;
}
if (i == 8) {
msg.message = (down ? Msg.WM_SYSKEYDOWN : Msg.WM_SYSKEYUP);
msg.wParam = (IntPtr) VirtualKeys.VK_MENU;
msg.lParam = new IntPtr (0x20000000);
return;
}
return;
}
public void ProcessModifiers (IntPtr eventref, ref MSG msg) {
// we get notified when modifiers change, but not specifically what changed
UInt32 modifiers = 0;
GetEventParameter (eventref, kEventParamKeyModifiers, typeUInt32, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (UInt32)), IntPtr.Zero, ref modifiers);
for (int i = 0; i < 32; i++) {
if (key_modifier_table [i] == 0x01 && (modifiers & (1 << i)) == 0) {
ModifierToVirtualKey (i, ref msg, false);
key_modifier_table [i] = 0x00;
return;
} else if (key_modifier_table [i] == 0x00 && (modifiers & (1 << i)) == (1 << i)) {
ModifierToVirtualKey (i, ref msg, true);
key_modifier_table [i] = 0x01;
return;
}
}
return;
}
public void ProcessText (IntPtr eventref, ref MSG msg) {
UInt32 size = 0;
IntPtr buffer = IntPtr.Zero;
byte [] bdata;
// get the size of the unicode buffer
GetEventParameter (eventref, kEventParamTextInputSendText, typeUnicodeText, IntPtr.Zero, 0, ref size, IntPtr.Zero);
buffer = Marshal.AllocHGlobal ((int) size);
bdata = new byte [size];
// get the actual text buffer
GetEventParameter (eventref, kEventParamTextInputSendText, typeUnicodeText, IntPtr.Zero, size, IntPtr.Zero, buffer);
Marshal.Copy (buffer, bdata, 0, (int) size);
Marshal.FreeHGlobal (buffer);
if (key_filter_table [bdata [0]] == 0x00) {
if (size == 1) {
msg.message = Msg.WM_CHAR;
msg.wParam = BitConverter.IsLittleEndian ? (IntPtr) bdata [0] : (IntPtr) bdata [size-1];
msg.lParam = IntPtr.Zero;
msg.hwnd = XplatUICarbon.FocusWindow;
} else {
msg.message = Msg.WM_IME_COMPOSITION;
Encoding enc = BitConverter.IsLittleEndian ? Encoding.Unicode : Encoding.BigEndianUnicode;
ComposedString = enc.GetString (bdata);
msg.hwnd = XplatUICarbon.FocusWindow;
}
}
}
public void ProcessKeyPress (IntPtr eventref, ref MSG msg) {
byte charCode = 0x0;
byte keyCode = 0x0;
GetEventParameter (eventref, kEventParamKeyMacCharCodes, typeChar, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (byte)), IntPtr.Zero, ref charCode);
GetEventParameter (eventref, kEventParamKeyCode, typeUInt32, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (byte)), IntPtr.Zero, ref keyCode);
msg.lParam = (IntPtr) charCode;
msg.wParam = charCode == 0x10 ? (IntPtr) key_translation_table [keyCode] : (IntPtr) char_translation_table [charCode];
msg.hwnd = XplatUICarbon.FocusWindow;
}
public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
uint klass = EventHandler.GetEventClass (eventref);
bool result = true;
if (klass == EventHandler.kEventClassTextInput) {
switch (kind) {
case kEventTextInputUnicodeForKeyEvent:
ProcessText (eventref, ref msg);
break;
default:
Console.WriteLine ("WARNING: KeyboardHandler.ProcessEvent default handler for kEventClassTextInput should not be reached");
break;
}
} else if (klass == EventHandler.kEventClassKeyboard) {
switch (kind) {
case kEventRawKeyDown:
case kEventRawKeyRepeat:
msg.message = Msg.WM_KEYDOWN;
ProcessKeyPress (eventref, ref msg);
break;
case kEventRawKeyUp:
msg.message = Msg.WM_KEYUP;
ProcessKeyPress (eventref, ref msg);
break;
case kEventRawKeyModifiersChanged:
ProcessModifiers (eventref, ref msg);
break;
default:
Console.WriteLine ("WARNING: KeyboardHandler.ProcessEvent default handler for kEventClassKeyboard should not be reached");
break;
}
} else {
Console.WriteLine ("WARNING: KeyboardHandler.ProcessEvent default handler for kEventClassTextInput should not be reached");
}
return result;
}
public bool TranslateMessage (ref MSG msg) {
bool res = false;
if (msg.message >= Msg.WM_KEYFIRST && msg.message <= Msg.WM_KEYLAST)
res = true;
if (msg.message != Msg.WM_KEYDOWN && msg.message != Msg.WM_SYSKEYDOWN && msg.message != Msg.WM_KEYUP && msg.message != Msg.WM_SYSKEYUP && msg.message != Msg.WM_CHAR && msg.message != Msg.WM_SYSCHAR)
return res;
if (key_modifier_table [8] == 0x01 && key_modifier_table [12] == 0x00 && key_modifier_table [14] == 0x00) {
if (msg.message == Msg.WM_KEYDOWN) {
msg.message = Msg.WM_SYSKEYDOWN;
} else if (msg.message == Msg.WM_CHAR) {
msg.message = Msg.WM_SYSCHAR;
translate_modifier = true;
} else if (msg.message == Msg.WM_KEYUP) {
msg.message = Msg.WM_SYSKEYUP;
} else {
return res;
}
msg.lParam = new IntPtr (0x20000000);
} else if (msg.message == Msg.WM_SYSKEYUP && translate_modifier && msg.wParam == (IntPtr) 18) {
msg.message = Msg.WM_KEYUP;
msg.lParam = IntPtr.Zero;
translate_modifier = false;
}
return res;
}
internal Keys ModifierKeys {
get {
Keys keys = Keys.None;
if (key_modifier_table [9] == 0x01 || key_modifier_table [13] == 0x01) { keys |= Keys.Shift; }
if (key_modifier_table [8] == 0x01) { keys |= Keys.Alt; }
if (key_modifier_table [12] == 0x01 || key_modifier_table [14] == 0x01) { keys |= Keys.Control; }
return keys;
}
}
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, ref UInt32 outsize, IntPtr data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, IntPtr data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref byte data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref UInt32 data);
}
internal enum KeyboardModifiers : uint {
activeFlag = 1 << 0,
btnState = 1 << 7,
cmdKey = 1 << 8,
shiftKey = 1 << 9,
alphaLock = 1 << 10,
optionKey = 1 << 11,
controlKey = 1 << 12,
rightShiftKey = 1 << 13,
rightOptionKey = 1 << 14,
rightControlKey = 1 << 14,
}
}

View File

@@ -0,0 +1,228 @@
// 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:
//
// 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 <gnorton@novell.com>
//
//
using System;
using System.Runtime.InteropServices;
namespace System.Windows.Forms.CarbonInternal {
internal class MouseHandler : EventHandlerBase, IEventHandler {
internal const uint kEventMouseDown = 1;
internal const uint kEventMouseUp = 2;
internal const uint kEventMouseMoved = 5;
internal const uint kEventMouseDragged = 6;
internal const uint kEventMouseEntered = 8;
internal const uint kEventMouseExited = 9;
internal const uint kEventMouseWheelMoved = 10;
internal const uint kEventMouseScroll = 11;
internal const uint kEventParamMouseLocation = 1835822947;
internal const uint kEventParamMouseButton = 1835168878;
internal const uint kEventParamMouseWheelAxis = 1836540280;
internal const uint kEventParamMouseWheelDelta = 1836541036;
internal const uint typeLongInteger = 1819242087;
internal const uint typeMouseWheelAxis = 1836540280;
internal const uint typeMouseButton = 1835168878;
internal const uint typeQDPoint = 1363439732;
internal const uint kEventMouseWheelAxisX = 0;
internal const uint kEventMouseWheelAxisY = 1;
internal const uint DoubleClickInterval = 7500000;
internal static ClickStruct ClickPending;
internal MouseHandler (XplatUICarbon driver) : base (driver) {}
public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
QDPoint qdpoint = new QDPoint ();
CGPoint point = new CGPoint ();
Rect window_bounds = new Rect ();
IntPtr view_handle = IntPtr.Zero;
IntPtr window_handle = IntPtr.Zero;
bool client = true;
ushort button = 0;
Hwnd hwnd;
GetEventParameter (eventref, kEventParamMouseLocation, typeQDPoint, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref qdpoint);
GetEventParameter (eventref, kEventParamMouseButton, typeMouseButton, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (ushort)), IntPtr.Zero, ref button);
if (button == 1 && ((Driver.ModifierKeys & Keys.Control) != 0))
button = 2;
point.x = qdpoint.x;
point.y = qdpoint.y;
if (FindWindow (qdpoint, ref window_handle) == 5)
return true;
GetWindowBounds (handle, 33, ref window_bounds);
HIViewFindByID (HIViewGetRoot (handle), new HIViewID (EventHandler.kEventClassWindow, 1), ref window_handle);
point.x -= window_bounds.left;
point.y -= window_bounds.top;
HIViewGetSubviewHit (window_handle, ref point, true, ref view_handle);
HIViewConvertPoint (ref point, window_handle, view_handle);
hwnd = Hwnd.ObjectFromHandle (view_handle);
if (hwnd != null)
client = (hwnd.ClientWindow == view_handle ? true : false);
if (XplatUICarbon.Grab.Hwnd != IntPtr.Zero) {
hwnd = Hwnd.ObjectFromHandle (XplatUICarbon.Grab.Hwnd);
client = true;
}
if (hwnd == null)
return true;
if (client) {
qdpoint.x = (short) point.x;
qdpoint.y = (short) point.y;
Driver.ScreenToClient (hwnd.Handle, ref qdpoint);
} else {
point.x = qdpoint.x;
point.y = qdpoint.y;
}
msg.hwnd = hwnd.Handle;
msg.lParam = (IntPtr) ((ushort) point.y << 16 | (ushort) point.x);
switch (kind) {
case kEventMouseDown:
UpdateMouseState (button, true);
msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 1;
msg.wParam = Driver.GetMousewParam (0);
if (ClickPending.Pending && (((DateTime.Now.Ticks - ClickPending.Time) < DoubleClickInterval) && (msg.hwnd == ClickPending.Hwnd) && (msg.wParam == ClickPending.wParam) && (msg.lParam == ClickPending.lParam) && (msg.message == ClickPending.Message))) {
msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 3;
ClickPending.Pending = false;
} else {
ClickPending.Pending = true;
ClickPending.Hwnd = msg.hwnd;
ClickPending.Message = msg.message;
ClickPending.wParam = msg.wParam;
ClickPending.lParam = msg.lParam;
ClickPending.Time = DateTime.Now.Ticks;
}
break;
case kEventMouseUp:
UpdateMouseState (button, false);
msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE) + ((button - 1) * 3) + 2;
msg.wParam = Driver.GetMousewParam (0);
break;
case kEventMouseDragged:
case kEventMouseMoved:
if (XplatUICarbon.Grab.Hwnd == IntPtr.Zero) {
IntPtr ht = IntPtr.Zero;
if (client) {
ht = (IntPtr) HitTest.HTCLIENT;
NativeWindow.WndProc(msg.hwnd, Msg.WM_SETCURSOR, msg.hwnd, (IntPtr)HitTest.HTCLIENT);
} else {
ht = (IntPtr) NativeWindow.WndProc (hwnd.client_window, Msg.WM_NCHITTEST, IntPtr.Zero, msg.lParam).ToInt32 ();
NativeWindow.WndProc(hwnd.client_window, Msg.WM_SETCURSOR, msg.hwnd, ht);
}
}
msg.message = (client ? Msg.WM_MOUSEMOVE : Msg.WM_NCMOUSEMOVE);
msg.wParam = Driver.GetMousewParam (0);
break;
case kEventMouseWheelMoved:
case kEventMouseScroll:
UInt16 axis = 0;
Int32 delta = 0;
GetEventParameter (eventref, kEventParamMouseWheelAxis, typeMouseWheelAxis, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (UInt16)), IntPtr.Zero, ref axis);
GetEventParameter (eventref, kEventParamMouseWheelDelta, typeLongInteger, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (Int32)), IntPtr.Zero, ref delta);
if (axis == kEventMouseWheelAxisY) {
msg.hwnd = XplatUICarbon.FocusWindow;
msg.message = Msg.WM_MOUSEWHEEL;
msg.wParam = Driver.GetMousewParam (delta*40);
return true;
}
break;
default:
return false;
}
Driver.mouse_position.X = (int) point.x;
Driver.mouse_position.Y = (int) point.y;
return true;
}
internal bool TranslateMessage (ref MSG msg) {
if (msg.message == Msg.WM_MOUSEMOVE || msg.message == Msg.WM_NCMOUSEMOVE) {
Hwnd hwnd = Hwnd.ObjectFromHandle (msg.hwnd);
if (XplatUICarbon.MouseHwnd == null) {
Driver.PostMessage (hwnd.Handle, Msg.WM_MOUSE_ENTER, IntPtr.Zero, IntPtr.Zero);
Cursor.SetCursor (hwnd.Cursor);
} else if (XplatUICarbon.MouseHwnd.Handle != hwnd.Handle) {
Driver.PostMessage (XplatUICarbon.MouseHwnd.Handle, Msg.WM_MOUSELEAVE, IntPtr.Zero, IntPtr.Zero);
Driver.PostMessage (hwnd.Handle, Msg.WM_MOUSE_ENTER, IntPtr.Zero, IntPtr.Zero);
Cursor.SetCursor (hwnd.Cursor);
}
XplatUICarbon.MouseHwnd = hwnd;
}
return false;
}
private void UpdateMouseState (int button, bool down) {
switch (button) {
case 1:
if (down) XplatUICarbon.MouseState |= MouseButtons.Left; else XplatUICarbon.MouseState &= ~MouseButtons.Left;
break;
case 2:
if (down) XplatUICarbon.MouseState |= MouseButtons.Right; else XplatUICarbon.MouseState &= ~MouseButtons.Right;
break;
case 3:
if (down) XplatUICarbon.MouseState |= MouseButtons.Middle; else XplatUICarbon.MouseState &= ~MouseButtons.Middle;
break;
}
}
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref QDPoint data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref Int32 data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetEventParameter (IntPtr eventref, uint name, uint type, IntPtr outtype, uint size, IntPtr outsize, ref ushort data);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
internal static extern short FindWindow (QDPoint point, ref IntPtr handle);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
internal static extern int GetWindowBounds (IntPtr handle, uint region, ref Rect bounds);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
internal static extern int HIViewConvertPoint (ref CGPoint point, IntPtr source_view, IntPtr target_view);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
internal static extern IntPtr HIViewGetRoot (IntPtr handle);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
internal static extern int HIViewGetSubviewHit (IntPtr content_view, ref CGPoint point, bool tval, ref IntPtr hit_view);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
internal static extern int HIViewFindByID (IntPtr root_window, HIViewID id, ref IntPtr view_handle);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
internal static extern int GetCurrentEventButtonState ();
}
}

View File

@@ -0,0 +1,106 @@
// 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:
//
// 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 (gnorton@novell.com)
//
//
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace System.Windows.Forms.CarbonInternal {
internal class Pasteboard {
private static IntPtr primary_pbref;
private static IntPtr app_pbref;
private static IntPtr internal_format;
static Pasteboard () {
PasteboardCreate (XplatUICarbon.__CFStringMakeConstantString("com.apple.pasteboard.clipboard"), ref primary_pbref);
PasteboardCreate (IntPtr.Zero, ref app_pbref);
internal_format = XplatUICarbon.__CFStringMakeConstantString ("com.novell.mono.mwf.pasteboard");
}
internal static object Retrieve (IntPtr pbref, int key) {
UInt32 count = 0;
key = (int)internal_format;
PasteboardGetItemCount (pbref, ref count);
for (int i = 1; i <= count; i++) {
UInt32 itemid = 0;
PasteboardGetItemIdentifier (pbref, (UInt32)i, ref itemid);
//FIXME: We should get all the flavors and enumerate but we're cheating for now
if (itemid == 0xFACE) {
IntPtr pbdata = IntPtr.Zero;
PasteboardCopyItemFlavorData (pbref, (UInt32)0xFACE, (UInt32)key, ref pbdata);
if (pbdata != IntPtr.Zero) {
GCHandle handle = (GCHandle) Marshal.ReadIntPtr (CFDataGetBytePtr (pbdata));
return handle.Target;
}
}
}
return null;
}
internal static void Store (IntPtr pbref, object data, int key) {
IntPtr gcdata = (IntPtr) GCHandle.Alloc (data);
IntPtr pbdata = CFDataCreate (IntPtr.Zero, ref gcdata, Marshal.SizeOf (typeof (IntPtr)));
key = (int)internal_format;
PasteboardClear (pbref);
PasteboardPutItemFlavor (pbref, (UInt32)0xFACE, (UInt32)key, pbdata, 0);
}
internal static IntPtr Primary {
get { return primary_pbref; }
}
internal static IntPtr Application {
get { return app_pbref; }
}
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern IntPtr CFDataCreate (IntPtr allocator, ref IntPtr buf, Int32 length);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern IntPtr CFDataGetBytePtr (IntPtr data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int PasteboardClear (IntPtr pbref);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int PasteboardCreate (IntPtr str, ref IntPtr pbref);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int PasteboardCopyItemFlavorData (IntPtr pbref, UInt32 itemid, UInt32 key, ref IntPtr data);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int PasteboardGetItemCount (IntPtr pbref, ref UInt32 count);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int PasteboardGetItemIdentifier (IntPtr pbref, UInt32 itemindex, ref UInt32 itemid);
[DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int PasteboardPutItemFlavor (IntPtr pbref, UInt32 itemid, UInt32 key, IntPtr data, UInt32 flags);
}
}

View File

@@ -0,0 +1,157 @@
// 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:
//
// 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 <gnorton@customerdna.com>
//
using System;
namespace System.Windows.Forms.CarbonInternal {
internal struct CGSize {
public float width;
public float height;
public CGSize (int w, int h) {
this.width = (float)w;
this.height = (float)h;
}
}
internal struct QDPoint {
public short y;
public short x;
public QDPoint (short x, short y) {
this.x = x;
this.y = y;
}
}
internal struct CGPoint {
public float x;
public float y;
public CGPoint (int x, int y) {
this.x = (float)x;
this.y = (float)y;
}
}
internal struct HIRect {
public CGPoint origin;
public CGSize size;
public HIRect (int x, int y, int w, int h) {
this.origin = new CGPoint (x, y);
this.size = new CGSize (w, h);
}
}
internal struct HIViewID {
public uint type;
public uint id;
public HIViewID (uint type, uint id) {
this.type = type;
this.id = id;
}
}
internal struct EventTypeSpec {
public UInt32 eventClass;
public UInt32 eventKind;
public EventTypeSpec (UInt32 eventClass, UInt32 eventKind)
{
this.eventClass = eventClass;
this.eventKind = eventKind;
}
}
internal struct CarbonEvent {
public IntPtr hWnd;
public IntPtr evt;
public CarbonEvent (IntPtr hWnd, IntPtr evt)
{
this.hWnd = hWnd;
this.evt = evt;
}
}
internal struct RGBColor {
public short red;
public short green;
public short blue;
}
internal struct Rect {
public short top;
public short left;
public short bottom;
public short right;
}
internal struct Caret {
internal Timer Timer;
internal IntPtr Hwnd;
internal int X;
internal int Y;
internal int Width;
internal int Height;
internal int Visible;
internal bool On;
internal bool Paused;
}
internal struct Hover {
internal Timer Timer;
internal IntPtr Hwnd;
internal int X;
internal int Y;
internal int Interval;
}
internal struct CGAffineTransform {
internal float a;
internal float b;
internal float c;
internal float d;
internal float tx;
internal float ty;
}
internal struct MouseTrackingRegionID {
public uint signature;
public uint id;
public MouseTrackingRegionID (uint signature, uint id) {
this.signature = signature;
this.id = id;
}
}
internal struct ProcessSerialNumber {
public ulong highLongOfPSN;
public ulong lowLongOfPSN;
}
}

View File

@@ -0,0 +1,235 @@
// 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:
//
// 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 <gnorton@novell.com>
//
//
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace System.Windows.Forms.CarbonInternal {
internal class WindowHandler : EventHandlerBase, IEventHandler {
internal const uint kEventWindowUpdate = 1;
internal const uint kEventWindowDrawContent = 2;
internal const uint kEventWindowActivated = 5;
internal const uint kEventWindowDeactivated = 6;
internal const uint kEventWindowGetClickActivation = 7;
internal const uint kEventWindowShowing = 22;
internal const uint kEventWindowHiding = 23;
internal const uint kEventWindowShown = 24;
internal const uint kEventWindowHidden = 25;
internal const uint kEventWindowCollapsing = 86;
internal const uint kEventWindowExpanding = 87;
internal const uint kEventWindowZoomed = 76;
internal const uint kEventWindowBoundsChanging = 26;
internal const uint kEventWindowBoundsChanged = 27;
internal const uint kEventWindowResizeStarted = 28;
internal const uint kEventWindowResizeCompleted = 29;
internal const uint kEventWindowDragStarted = 30;
internal const uint kEventWindowDragCompleted = 31;
internal const uint kEventWindowTransitionStarted = 88;
internal const uint kEventWindowTransitionCompleted = 89;
internal const uint kEventWindowClickDragRgn = 32;
internal const uint kEventWindowClickResizeRgn = 33;
internal const uint kEventWindowClickCollapseRgn = 34;
internal const uint kEventWindowClickCloseRgn = 35;
internal const uint kEventWindowClickZoomRgn = 36;
internal const uint kEventWindowClickContentRgn = 37;
internal const uint kEventWindowClickProxyIconRgn = 38;
internal const uint kEventWindowClickToolbarButtonRgn = 41;
internal const uint kEventWindowClickStructureRgn = 42;
internal const uint kEventWindowCursorChange = 40;
internal const uint kEventWindowCollapse = 66;
internal const uint kEventWindowCollapsed = 67;
internal const uint kEventWindowCollapseAll = 68;
internal const uint kEventWindowExpand = 69;
internal const uint kEventWindowExpanded = 70;
internal const uint kEventWindowExpandAll = 71;
internal const uint kEventWindowClose = 72;
internal const uint kEventWindowClosed = 73;
internal const uint kEventWindowCloseAll = 74;
internal const uint kEventWindowZoom = 75;
internal const uint kEventWindowZoomAll = 77;
internal const uint kEventWindowContextualMenuSelect = 78;
internal const uint kEventWindowPathSelect = 79;
internal const uint kEventWindowGetIdealSize = 80;
internal const uint kEventWindowGetMinimumSize = 81;
internal const uint kEventWindowGetMaximumSize = 82;
internal const uint kEventWindowConstrain = 83;
internal const uint kEventWindowHandleContentClick = 85;
internal const uint kEventWindowGetDockTileMenu = 90;
internal const uint kEventWindowHandleActivate = 91;
internal const uint kEventWindowHandleDeactivate = 92;
internal const uint kEventWindowProxyBeginDrag = 128;
internal const uint kEventWindowProxyEndDrag = 129;
internal const uint kEventWindowToolbarSwitchMode = 150;
internal const uint kEventWindowFocusAcquired = 200;
internal const uint kEventWindowFocusRelinquish = 201;
internal const uint kEventWindowFocusContent = 202;
internal const uint kEventWindowFocusToolbar = 203;
internal const uint kEventWindowDrawerOpening = 220;
internal const uint kEventWindowDrawerOpened = 221;
internal const uint kEventWindowDrawerClosing = 222;
internal const uint kEventWindowDrawerClosed = 223;
internal const uint kEventWindowDrawFrame = 1000;
internal const uint kEventWindowDrawPart = 1001;
internal const uint kEventWindowGetRegion = 1002;
internal const uint kEventWindowHitTest = 1003;
internal const uint kEventWindowInit = 1004;
internal const uint kEventWindowDispose = 1005;
internal const uint kEventWindowDragHilite = 1006;
internal const uint kEventWindowModified = 1007;
internal const uint kEventWindowSetupProxyDragImage = 1008;
internal const uint kEventWindowStateChanged = 1009;
internal const uint kEventWindowMeasureTitle = 1010;
internal const uint kEventWindowDrawGrowBox = 1011;
internal const uint kEventWindowGetGrowImageRegion = 1012;
internal const uint kEventWindowPaint = 1013;
internal WindowHandler (XplatUICarbon driver) : base (driver) {}
public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
IntPtr window = Driver.HandleToWindow (handle);
Hwnd hwnd = Hwnd.ObjectFromHandle (window);
if (window != IntPtr.Zero) {
switch (kind) {
case kEventWindowActivated: {
Control c = Control.FromHandle (hwnd.client_window);
if (c != null) {
Form form = c.FindForm ();
if (form != null && !form.IsDisposed) {
Driver.SendMessage (form.Handle, Msg.WM_ACTIVATE, (IntPtr) WindowActiveFlags.WA_ACTIVE, IntPtr.Zero);
XplatUICarbon.ActiveWindow = hwnd.client_window;
}
}
foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
if (utility_window != handle && !XplatUICarbon.IsWindowVisible (utility_window))
XplatUICarbon.ShowWindow (utility_window);
}
break;
}
case kEventWindowExpanding:
foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
if (utility_window != handle && !XplatUICarbon.IsWindowVisible (utility_window))
XplatUICarbon.ShowWindow (utility_window);
}
msg.hwnd = hwnd.Handle;
msg.message = Msg.WM_ENTERSIZEMOVE;
return true;
case kEventWindowExpanded:
NativeWindow.WndProc (hwnd.Handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
msg.hwnd = hwnd.Handle;
msg.message = Msg.WM_EXITSIZEMOVE;
return true;
case kEventWindowDeactivated: {
Control c = Control.FromHandle (hwnd.client_window);
if (c != null) {
Form form = c.FindForm ();
if (form != null && XplatUICarbon.UnactiveWindow != form.Handle) {
Driver.SendMessage (form.Handle, Msg.WM_ACTIVATE, (IntPtr) WindowActiveFlags.WA_INACTIVE, IntPtr.Zero);
XplatUICarbon.ActiveWindow = IntPtr.Zero;
}
}
foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
if (utility_window != handle && XplatUICarbon.IsWindowVisible (utility_window))
XplatUICarbon.HideWindow (utility_window);
}
break;
}
case kEventWindowCollapsing:
foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
if (utility_window != handle && XplatUICarbon.IsWindowVisible (utility_window))
XplatUICarbon.HideWindow (utility_window);
}
msg.hwnd = hwnd.Handle;
msg.message = Msg.WM_ENTERSIZEMOVE;
return true;
case kEventWindowCollapsed:
NativeWindow.WndProc (hwnd.Handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
msg.hwnd = hwnd.Handle;
msg.message = Msg.WM_EXITSIZEMOVE;
return true;
case kEventWindowClose:
NativeWindow.WndProc (hwnd.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
return false;
case kEventWindowShown: {
msg.message = Msg.WM_SHOWWINDOW;
msg.lParam = (IntPtr) 1;
msg.wParam = (IntPtr) 0;
msg.hwnd = hwnd.Handle;
return true;
}
case kEventWindowResizeStarted: {
msg.message = Msg.WM_ENTERSIZEMOVE;
msg.hwnd = hwnd.Handle;
return true;
}
case kEventWindowResizeCompleted: {
msg.message = Msg.WM_EXITSIZEMOVE;
msg.hwnd = hwnd.Handle;
return true;
}
case kEventWindowBoundsChanged: {
Rect window_bounds = new Rect ();
HIRect view_bounds = new HIRect ();
Size size;
GetWindowBounds (handle, 33, ref window_bounds);
view_bounds.size.width = window_bounds.right - window_bounds.left;
view_bounds.size.height = window_bounds.bottom - window_bounds.top;
HIViewSetFrame (hwnd.WholeWindow, ref view_bounds);
size = XplatUICarbon.TranslateQuartzWindowSizeToWindowSize (Control.FromHandle (hwnd.Handle).GetCreateParams (), (int)view_bounds.size.width, (int)view_bounds.size.height);
hwnd.X = (int) window_bounds.left;
hwnd.Y = (int) window_bounds.top;
hwnd.Width = (int) size.Width;
hwnd.Height = (int) size.Height;
Driver.PerformNCCalc (hwnd);
msg.hwnd = hwnd.Handle;
msg.message = Msg.WM_WINDOWPOSCHANGED;
Driver.SetCaretPos (XplatUICarbon.Caret.Hwnd, XplatUICarbon.Caret.X, XplatUICarbon.Caret.Y);
return true;
}
}
}
return false;
}
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int GetWindowBounds (IntPtr handle, uint region, ref Rect bounds);
[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
static extern int HIViewSetFrame (IntPtr handle, ref HIRect bounds);
}
}