1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004 Novell, Inc.
23 // Geoff Norton <gnorton@customerdna.com>
27 // This really doesn't work at all; please dont file bugs on it yet.
30 // Fix clipping of children
34 using System.Threading;
36 using System.ComponentModel;
37 using System.Collections;
38 using System.Diagnostics;
39 using System.Runtime.InteropServices;
42 namespace System.Windows.Forms {
44 // The Carbon Event callback delegate
45 delegate int CarbonEventDelegate (IntPtr inCallRef, IntPtr inEvent, IntPtr userData);
47 internal class XplatUIOSX : XplatUIDriver {
49 #region Local Variables
51 // General driver variables
52 private static XplatUIOSX Instance;
53 private static int RefCount;
54 private static bool ThemesEnabled;
55 private static IntPtr FocusWindow;
58 private static MouseButtons MouseState;
59 private static Point MousePosition;
60 private static Hwnd MouseWindow;
63 private static GrabStruct Grab;
64 private static OSXCaret Caret;
65 private static OSXHover Hover;
66 private CarbonEventDelegate CarbonEventHandler;
67 private static Hashtable WindowMapping;
68 private static Hashtable WindowBackgrounds;
69 private static Hwnd GrabWindowHwnd;
70 private static IntPtr FosterParent;
71 private static int TitleBarHeight;
72 private static int MenuBarHeight;
73 private static EventTypeSpec [] viewEvents = new EventTypeSpec [] {
74 new EventTypeSpec (OSXConstants.kEventClassControl, OSXConstants.kEventControlSetFocusPart),
75 new EventTypeSpec (OSXConstants.kEventClassControl, OSXConstants.kEventControlClick),
76 new EventTypeSpec (OSXConstants.kEventClassControl, OSXConstants.kEventControlContextualMenuClick),
77 new EventTypeSpec (OSXConstants.kEventClassControl, OSXConstants.kEventControlTrack),
78 new EventTypeSpec (OSXConstants.kEventClassControl, OSXConstants.kEventControlSimulateHit),
79 new EventTypeSpec (OSXConstants.kEventClassControl, OSXConstants.kEventControlBoundsChanged),
80 new EventTypeSpec (OSXConstants.kEventClassControl, OSXConstants.kEventControlDraw)
82 private static EventTypeSpec [] windowEvents = new EventTypeSpec[] {
83 //new EventTypeSpec (OSXConstants.kEventClassMouse, OSXConstants.kEventMouseEntered),
84 //new EventTypeSpec (OSXConstants.kEventClassMouse, OSXConstants.kEventMouseExited),
85 new EventTypeSpec (OSXConstants.kEventClassMouse, OSXConstants.kEventMouseMoved),
86 //new EventTypeSpec (OSXConstants.kEventClassMouse, OSXConstants.kEventMouseDragged),
87 //new EventTypeSpec (OSXConstants.kEventClassMouse, OSXConstants.kEventMouseWheelMoved),
88 new EventTypeSpec (OSXConstants.kEventClassWindow, OSXConstants.kEventWindowBoundsChanged),
89 new EventTypeSpec (OSXConstants.kEventClassWindow, OSXConstants.kEventWindowClose),
90 new EventTypeSpec (OSXConstants.kEventClassKeyboard, OSXConstants.kEventRawKeyDown),
91 new EventTypeSpec (OSXConstants.kEventClassKeyboard, OSXConstants.kEventRawKeyRepeat),
92 new EventTypeSpec (OSXConstants.kEventClassKeyboard, OSXConstants.kEventRawKeyUp)
97 private static Queue MessageQueue;
98 private static bool GetMessageResult;
101 private ArrayList TimerList;
104 internal override event EventHandler Idle;
109 private XplatUIOSX() {
112 TimerList = new ArrayList ();
113 MessageQueue = new Queue ();
119 // FIXME: Clean up the FosterParent here.
124 #region Singleton specific code
126 public static XplatUIOSX GetInstance() {
127 lock (typeof (XplatUIOSX)) {
128 if (Instance == null) {
129 Instance = new XplatUIOSX ();
136 public int Reference {
144 #region Internal methods
146 internal void Initialize () {
148 // Initialize the Event Handler delegate
149 CarbonEventHandler = new CarbonEventDelegate (EventCallback);
151 // Initilize the mouse controls
152 Hover.Interval = 500;
153 Hover.Timer = new Timer ();
154 Hover.Timer.Enabled = false;
155 Hover.Timer.Interval = Hover.Interval;
156 Hover.Timer.Tick += new EventHandler (HoverCallback);
159 MouseState = MouseButtons.None;
160 MousePosition = Point.Empty;
162 // Initialize the Caret
163 Caret.Timer = new Timer ();
164 Caret.Timer.Interval = 500;
165 Caret.Timer.Tick += new EventHandler (CaretCallback);
167 // Initialize the OSX Specific stuff
168 WindowMapping = new Hashtable ();
169 WindowBackgrounds = new Hashtable ();
171 // Initialize the FosterParent
172 IntPtr rect = IntPtr.Zero;
173 SetRect (ref rect, (short)0, (short)0, (short)0, (short)0);
174 CheckError (CreateNewWindow (WindowClass.kDocumentWindowClass, WindowAttributes.kWindowStandardHandlerAttribute | WindowAttributes.kWindowCloseBoxAttribute | WindowAttributes.kWindowFullZoomAttribute | WindowAttributes.kWindowCollapseBoxAttribute | WindowAttributes.kWindowResizableAttribute | WindowAttributes.kWindowCompositingAttribute, ref rect, ref FosterParent), "CreateFosterParent ()");
176 // Get some values about bar heights
177 Rect structRect = new Rect ();
178 Rect contentRect = new Rect ();
179 CheckError (GetWindowBounds (FosterParent, 32, ref structRect), "GetWindowBounds ()");
180 CheckError (GetWindowBounds (FosterParent, 33, ref contentRect), "GetWindowBounds ()");
182 TitleBarHeight = Math.Abs(structRect.top - contentRect.top);
183 MenuBarHeight = GetMBarHeight ();
186 FocusWindow = IntPtr.Zero;
189 GetMessageResult = true;
194 #region Private methods
199 private void CaretCallback (object sender, EventArgs e) {
211 private void HoverCallback (object sender, EventArgs e) {
212 if ((Hover.X == MousePosition.X) && (Hover.Y == MousePosition.Y)) {
213 MSG msg = new MSG ();
214 msg.hwnd = Hover.Hwnd;
215 msg.message = Msg.WM_MOUSEHOVER;
216 msg.wParam = GetMousewParam (0);
217 msg.lParam = (IntPtr)((ushort)Hover.X << 16 | (ushort)Hover.X);
218 MessageQueue.Enqueue (msg);
222 internal int EventCallback (IntPtr inCallRef, IntPtr inEvent, IntPtr handle) {
223 uint eventClass = GetEventClass (inEvent);
224 uint eventKind = GetEventKind (inEvent);
226 lock (MessageQueue) {
227 switch (eventClass) {
229 case OSXConstants.kEventClassKeyboard: {
230 retVal = ProcessKeyboardEvent (inEvent, eventKind, handle);
234 case OSXConstants.kEventClassWindow: {
235 retVal = ProcessWindowEvent (inEvent, eventKind, handle);
239 case OSXConstants.kEventClassMouse: {
240 retVal = ProcessMouseEvent (inEvent, eventKind, handle);
244 case OSXConstants.kEventClassControl: {
245 retVal = ProcessControlEvent (inEvent, eventKind, handle);
249 Console.WriteLine ("WARNING: Unhandled eventClass {0}", eventClass);
260 #region Private Methods
262 // This sucks write a real driver
263 private int ProcessKeyboardEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
264 MSG msg = new MSG ();
265 byte charCode = 0x00;
266 GetEventParameter (inEvent, 1801676914, 1413830740, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (byte)), IntPtr.Zero, ref charCode);
267 IntPtr cntrl = IntPtr.Zero;
268 CheckError (GetKeyboardFocus (handle, ref cntrl), "GetKeyboardFocus()");
270 msg.lParam = IntPtr.Zero;
285 msg.wParam = (IntPtr)charCode;
288 case OSXConstants.kEventRawKeyDown: {
289 msg.message = Msg.WM_KEYDOWN;
293 case OSXConstants.kEventRawKeyRepeat: {
294 msg.message = Msg.WM_KEYDOWN;
298 case OSXConstants.kEventRawKeyUp: {
299 msg.message = Msg.WM_KEYUP;
303 MessageQueue.Enqueue (msg);
307 private int ProcessWindowEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
308 MSG msg = new MSG ();
310 // Someone closed a window
311 case OSXConstants.kEventWindowClose: {
312 // This is our real window; so we have to post to the corresponding view
313 // FIXME: Should we doublehash the table to get the real window handle without this loop?
314 IDictionaryEnumerator e = WindowMapping.GetEnumerator ();
315 while (e.MoveNext ()) {
316 if ((IntPtr)e.Value == handle) {
317 NativeWindow.WndProc((IntPtr)e.Key, Msg.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
322 case OSXConstants.kEventWindowBoundsChanged: {
323 // This is our real window; so we have to resize the corresponding view as well
324 // FIXME: Should we doublehash the table to get the real window handle without this loop?
326 IDictionaryEnumerator e = WindowMapping.GetEnumerator ();
327 while (e.MoveNext ()) {
328 if ((IntPtr)e.Value == handle) {
329 Hwnd hwnd = Hwnd.ObjectFromHandle ((IntPtr) e.Key);
330 // Get the bounds of the window
331 Rect bounds = new Rect ();
332 CheckError (GetWindowBounds (handle, 33, ref bounds), "GetWindowBounds ()");
333 HIRect r = new HIRect ();
335 // Get our frame for the Handle
336 CheckError (HIViewGetFrame (hwnd.Handle, ref r), "HIViewGetFrame ()");
337 r.size.width = bounds.right-bounds.left;
338 r.size.height = bounds.bottom-bounds.top;
339 // Set the view to the new size
340 CheckError (HIViewSetFrame (hwnd.WholeWindow, ref r), "HIViewSetFrame ()");
342 // Update the hwnd internal size representation
343 hwnd.x = (int)r.origin.x;
344 hwnd.y = (int)r.origin.y;
345 hwnd.width = (int)r.size.width;
346 hwnd.height = (int)r.size.height;
347 Rectangle client_rect = hwnd.ClientRect;
349 r.size.width = client_rect.Width;
350 r.size.height = client_rect.Height;
351 r.origin.x = client_rect.X;
352 r.origin.y = client_rect.Y;
354 // Update the client area too
355 CheckError (HIViewSetFrame (hwnd.ClientWindow, ref r));
357 // Add the message to the queue
358 msg.message = Msg.WM_WINDOWPOSCHANGED;
359 msg.hwnd = hwnd.Handle;
360 msg.wParam = IntPtr.Zero;
361 msg.lParam = IntPtr.Zero;
362 MessageQueue.Enqueue (msg);
373 private int ProcessMouseEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
374 MSG msg = new MSG ();
377 case OSXConstants.kEventMouseMoved: {
378 // Where is the mouse in global coordinates
379 QDPoint pt = new QDPoint ();
380 GetEventParameter (inEvent, 1835822947, 1363439732, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref pt);
382 // Where is the mouse in the window
383 Rect window_bounds = new Rect ();
384 GetWindowBounds (handle, 33, ref window_bounds);
385 CGPoint window_pt = new CGPoint ((short) (pt.x - window_bounds.left), (short) (pt.y - window_bounds.top));
387 IntPtr window_handle = IntPtr.Zero;
388 HIViewFindByID (HIViewGetRoot (handle), new HIViewID (OSXConstants.kEventClassWindow, 1), ref window_handle);
390 // Determine which control was hit
391 IntPtr view_handle = IntPtr.Zero;
392 HIViewGetSubviewHit (window_handle, ref window_pt, true, ref view_handle);
394 // Convert the point to view local coordinates
395 HIViewConvertPoint (ref window_pt, window_handle, view_handle);
397 Hwnd hwnd = Hwnd.ObjectFromHandle (view_handle);
402 // Generate the message
403 msg.hwnd = hwnd.Handle;
404 msg.message = Msg.WM_MOUSEMOVE;
405 msg.lParam = (IntPtr) ((ushort)window_pt.y << 16 | (ushort)window_pt.x);
406 msg.wParam = GetMousewParam (0);
407 MousePosition.X = (int)window_pt.x;
408 MousePosition.Y = (int)window_pt.y;
410 Hover.Hwnd = msg.hwnd;
411 Hover.Timer.Enabled = true;
412 MessageQueue.Enqueue (msg);
419 private int ProcessControlEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
420 GetEventParameter (inEvent, 757935405, 1668575852, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref handle);
421 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
422 MSG msg = new MSG ();
425 case OSXConstants.kEventControlDraw: {
431 IntPtr rgnhandle = IntPtr.Zero;
432 GetEventParameter (inEvent, 1919381096, 1919381096, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref rgnhandle);
433 IntPtr duprgn = NewRgn ();
434 CopyRgn (rgnhandle, duprgn);
435 ClipRegions [hwnd.Handle] = duprgn;
438 // Get the dirty area
439 HIRect bounds = new HIRect ();
440 HIViewGetBounds (handle, ref bounds);
442 bool client = (hwnd.ClientWindow == handle ? true : false);
444 if (!client && bounds.origin.x >= hwnd.ClientRect.X && bounds.origin.y >= hwnd.ClientRect.Y) {
445 // This is a paint on WholeWindow inside the clientRect; we can safely discard this
449 hwnd.AddInvalidArea ((int)bounds.origin.x, (int)bounds.origin.y, (int)bounds.size.width, (int)bounds.size.height);
450 if (WindowBackgrounds [hwnd] != null) {
451 Color c = (Color)WindowBackgrounds [hwnd];
452 IntPtr contextref = IntPtr.Zero;
453 GetEventParameter (inEvent, 1668183160, 1668183160, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref contextref);
454 CGContextSetRGBFillColor (contextref, (float)c.R/255, (float)c.G/255, (float)c.B/255, (float)c.A/255);
455 CGContextFillRect (contextref, bounds);
458 // Add a paint to the queue
459 msg.hwnd = hwnd.Handle;
460 msg.message = Msg.WM_PAINT;
461 msg.wParam = IntPtr.Zero;
462 msg.lParam = IntPtr.Zero;
463 MessageQueue.Enqueue (msg);
467 case OSXConstants.kEventControlBoundsChanged: {
468 // This can happen before our HWND is created so we need to check to make sure its not null
471 HIRect bounds = new HIRect ();
472 HIViewGetFrame (handle, ref bounds);
473 // Update the hwnd size
474 hwnd.x = (int)bounds.origin.x;
475 hwnd.y = (int)bounds.origin.y;
476 hwnd.width = (int)bounds.size.width;
477 hwnd.height = (int)bounds.size.height;
479 // TODO: Do we need to send a paint here or does BoundsChanged make a ControlDraw for the exposed area?
483 case OSXConstants.kEventControlTrack: {
484 // get the point that was hit
485 QDPoint point = new QDPoint ();
486 CheckError (GetEventParameter (inEvent, 1835822947, 1363439732, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref point), "GetEventParameter() MouseLocation");
487 MouseTrackingResult mousestatus = MouseTrackingResult.kMouseTrackingMouseDown;
488 IntPtr modifiers = IntPtr.Zero;
490 while (mousestatus != MouseTrackingResult.kMouseTrackingMouseUp) {
491 CheckTimers (DateTime.Now);
492 if (mousestatus == MouseTrackingResult.kMouseTrackingMouseDragged) {
493 NativeWindow.WndProc (hwnd.Handle, Msg.WM_MOUSEMOVE, GetMousewParam (0), (IntPtr) ((ushort)point.y << 16 | (ushort)point.x));
495 // Process the rest of the event queue
496 while (MessageQueue.Count > 0) {
497 msg = (MSG)MessageQueue.Dequeue ();
498 NativeWindow.WndProc (msg.hwnd, msg.message, msg.wParam, msg.lParam);
500 TrackMouseLocationWithOptions (IntPtr.Zero, 0, 0.01, ref point, ref modifiers, ref mousestatus);
503 ScreenToClient (hwnd.Handle, ref x, ref y);
508 msg.hwnd = hwnd.Handle;
510 bool client = (hwnd.ClientWindow == handle ? true : false);
512 int wparam = (int)GetMousewParam (0);
513 switch (MouseState) {
514 case MouseButtons.Left:
515 MouseState &= ~MouseButtons.Left;
516 msg.message = (client ? Msg.WM_LBUTTONUP : Msg.WM_NCLBUTTONUP);
517 wparam &= (int)MsgButtons.MK_LBUTTON;
519 case MouseButtons.Middle:
520 MouseState &= ~MouseButtons.Middle;
521 msg.message = (client ? Msg.WM_MBUTTONUP : Msg.WM_NCMBUTTONUP);
522 wparam &= (int)MsgButtons.MK_MBUTTON;
524 case MouseButtons.Right:
525 MouseState &= ~MouseButtons.Right;
526 msg.message = (client ? Msg.WM_RBUTTONUP : Msg.WM_NCRBUTTONUP);
527 wparam &= (int)MsgButtons.MK_RBUTTON;
530 msg.wParam = (IntPtr)wparam;
532 msg.lParam = (IntPtr) ((ushort)point.y << 16 | (ushort)point.x);
533 MousePosition.X = (int)point.x;
534 MousePosition.Y = (int)point.y;
535 //NativeWindow.WndProc (msg.hwnd, msg.message, msg.lParam, msg.wParam);
536 MessageQueue.Enqueue (msg);
538 IntPtr window = GetControlOwner (hwnd.Handle);
539 SetKeyboardFocus (window, hwnd.Handle, 1);
543 case OSXConstants.kEventControlContextualMenuClick:
544 case OSXConstants.kEventControlClick: {
545 // get the point that was hit
546 QDPoint point = new QDPoint ();
547 CheckError (GetEventParameter (inEvent, 1835822947, 1363439732, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref point), "GetEventParameter() MouseLocation");
550 ScreenToClient (hwnd.Handle, ref x, ref y);
554 // which button was pressed?
556 GetEventParameter (inEvent, 1835168878, 1835168878, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (ushort)), IntPtr.Zero, ref button);
558 point.x = (short)MousePosition.X;
559 point.y = (short)MousePosition.Y;
562 msg.hwnd = hwnd.Handle;
564 bool client = (hwnd.ClientWindow == handle ? true : false);
566 int wparam = (int)GetMousewParam (0);
569 MouseState |= MouseButtons.Left;
570 msg.message = (client ? Msg.WM_LBUTTONDOWN : Msg.WM_NCLBUTTONDOWN);
571 wparam |= (int)MsgButtons.MK_LBUTTON;
574 MouseState |= MouseButtons.Right;
575 msg.message = (client ? Msg.WM_RBUTTONDOWN : Msg.WM_NCRBUTTONDOWN);
576 wparam |= (int)MsgButtons.MK_RBUTTON;
579 MouseState |= MouseButtons.Middle;
580 msg.message = (client ? Msg.WM_MBUTTONDOWN : Msg.WM_NCMBUTTONDOWN);
581 wparam |= (int)MsgButtons.MK_MBUTTON;
584 msg.wParam = (IntPtr)wparam;
586 msg.lParam = (IntPtr) ((ushort)point.y << 16 | (ushort)point.x);
587 MousePosition.X = (int)point.x;
588 MousePosition.Y = (int)point.y;
589 NativeWindow.WndProc (msg.hwnd, msg.message, msg.wParam, msg.lParam);
591 TrackControl (handle, point, IntPtr.Zero);
594 case OSXConstants.kEventControlSetFocusPart: {
595 // This handles setting focus
597 GetEventParameter (inEvent, 1668313716, 1668313716, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (short)), IntPtr.Zero, ref pcode);
605 SetEventParameter (inEvent, 1668313716, 1668313716, (uint)Marshal.SizeOf (typeof (short)), ref pcode);
611 private IntPtr GetMousewParam(int Delta) {
614 if ((MouseState & MouseButtons.Left) != 0) {
615 result |= (int)MsgButtons.MK_LBUTTON;
618 if ((MouseState & MouseButtons.Middle) != 0) {
619 result |= (int)MsgButtons.MK_MBUTTON;
622 if ((MouseState & MouseButtons.Right) != 0) {
623 result |= (int)MsgButtons.MK_RBUTTON;
626 return (IntPtr)result;
629 private double NextTimeout ()
631 DateTime now = DateTime.Now;
632 int timeout = 0x7FFFFFF;
634 foreach (Timer timer in TimerList) {
635 int next = (int) (timer.Expires - now).TotalMilliseconds;
642 if (timeout < Timer.Minimum)
643 timeout = Timer.Minimum;
645 return (double)((double)timeout/1000);
648 private void CheckTimers (DateTime now)
651 int count = TimerList.Count;
654 for (int i = 0; i < TimerList.Count; i++) {
655 Timer timer = (Timer) TimerList [i];
656 if (timer.Enabled && timer.Expires <= now) {
664 internal void InvertCaret () {
665 IntPtr window = GetControlOwner (Caret.Hwnd);
666 SetPortWindowPort (window);
667 Rect r = new Rect ();
668 GetWindowPortBounds (window, ref r);
669 r.top += (short)Caret.Y;
670 r.left += (short)Caret.X;
671 r.bottom = (short)(r.top + Caret.Height);
672 r.right = (short)(r.left + Caret.Width);
676 private void SetHwndStyles(Hwnd hwnd, CreateParams cp) {
677 if ((cp.Style & (int)WindowStyles.WS_CHILD) != 0) {
678 if ((cp.Style & (int)WindowStyles.WS_THICKFRAME) != 0) {
679 hwnd.BorderStyle = BorderStyle.Fixed3D;
680 } else if ((cp.Style & (int)WindowStyles.WS_BORDER) != 0) {
681 hwnd.BorderStyle = BorderStyle.FixedSingle;
685 if ((cp.ExStyle & (int)WindowStyles.WS_EX_CLIENTEDGE) != 0) {
686 hwnd.edge_style = Border3DStyle.Sunken;
687 } else if ((cp.ExStyle & (int)WindowStyles.WS_EX_STATICEDGE) != 0) {
688 hwnd.edge_style = Border3DStyle.Flat;
689 } else if ((cp.ExStyle & (int)WindowStyles.WS_EX_WINDOWEDGE) != 0) {
690 hwnd.edge_style = Border3DStyle.Raised;
691 } else if ((cp.ExStyle & (int)WindowStyles.WS_EX_WINDOWEDGE) != 0) {
692 hwnd.edge_style = Border3DStyle.Raised;
695 if ((cp.Style & (int)WindowStyles.WS_CAPTION) != 0) {
696 if ((cp.ExStyle & (int)WindowStyles.WS_EX_TOOLWINDOW) != 0) {
697 hwnd.title_style = TitleStyle.Tool;
699 hwnd.title_style = TitleStyle.Normal;
704 internal void ShowCaret () {
711 internal void HideCaret () {
718 internal void InstallTracking (Hwnd hwnd) {
719 // This is currently not used
722 if (hwnd.client_region_ptr != IntPtr.Zero) {
723 ReleaseMouseTrackingRegion (hwnd.client_region_ptr);
724 hwnd.client_region_ptr = IntPtr.Zero;
726 if (hwnd.whole_region_ptr != IntPtr.Zero) {
727 ReleaseMouseTrackingRegion (hwnd.whole_region_ptr);
728 hwnd.whole_region_ptr = IntPtr.Zero;
730 // Setup the new track region
732 HIRect client_bounds = new HIRect ();
733 HIViewGetBounds (hwnd.client_window, ref client_bounds);
734 HIViewConvertRect (ref client_bounds, hwnd.client_window, IntPtr.Zero);
736 IntPtr rgn = NewRgn ();
737 SetRectRgn (rgn, (short)client_bounds.origin.x, (short)client_bounds.origin.y, (short)(client_bounds.origin.x+hwnd.ClientRect.Width), (short)(client_bounds.origin.y+hwnd.ClientRect.Height));
738 CreateMouseTrackingRegion (GetControlOwner (hwnd.client_window), rgn, IntPtr.Zero, 0, hwnd.client_region_id, hwnd.client_window, IntPtr.Zero, ref hwnd.client_region_ptr);
739 Console.WriteLine (hwnd.ClientRect);
740 Console.WriteLine ("Created a mouse trcaking region on the client window @ {0}x{1} {2}x{3}", (short)client_bounds.origin.x, (short)client_bounds.origin.y, (short)(client_bounds.origin.x+hwnd.ClientRect.Width), (short)(client_bounds.origin.y+hwnd.ClientRect.Height));
741 if (hwnd.ClientRect.X > 0 && hwnd.ClientRect.Y > 0) {
742 HIRect window_bounds = new HIRect ();
743 HIViewGetBounds (hwnd.whole_window, ref window_bounds);
744 HIViewConvertRect (ref window_bounds, hwnd.whole_window, IntPtr.Zero);
746 SetRectRgn (rgn, (short)window_bounds.origin.x, (short)window_bounds.origin.y, (short)(window_bounds.origin.x+hwnd.ClientRect.X), (short)(window_bounds.origin.y+hwnd.ClientRect.Y));
747 CreateMouseTrackingRegion (GetControlOwner (hwnd.whole_window), rgn, IntPtr.Zero, 0, hwnd.whole_region_id, hwnd.whole_window, IntPtr.Zero, ref hwnd.whole_region_ptr);
748 Console.WriteLine ("Created a mouse trcaking region on the whole window @ {0}x{1} {2}x{3}", (short)window_bounds.origin.x, (short)window_bounds.origin.y, (short)(window_bounds.origin.x+hwnd.ClientRect.X), (short)(window_bounds.origin.y+hwnd.ClientRect.Y));
754 internal void CheckError (int result, string error) {
756 throw new Exception ("XplatUIOSX.cs::" + error + "() Carbon subsystem threw an error: " + result);
759 internal void CheckError (int result) {
761 throw new Exception ("XplatUIOSX.cs::Carbon subsystem threw an error: " + result);
766 #region Public Methods
768 internal override IntPtr InitializeDriver() {
772 internal override void ShutdownDriver(IntPtr token) {
775 internal override void EnableThemes() {
776 ThemesEnabled = true;
779 internal override void Activate(IntPtr handle) {
780 ActivateWindow (GetControlOwner (handle), true);
783 internal override void CaretVisible (IntPtr hwnd, bool visible) {
784 if (Caret.Hwnd == hwnd) {
786 if (Caret.Visible < 1) {
789 if (Caret.Visible == 1) {
791 Caret.Timer.Start ();
796 if (Caret.Visible == 0) {
804 internal override bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, int ExStyle, IntPtr MenuHandle, out Rectangle WindowRect) {
805 BorderStyle border_style;
806 TitleStyle title_style;
808 title_style = TitleStyle.None;
809 if ((Style & (int)WindowStyles.WS_CAPTION) != 0) {
810 if ((ExStyle & (int)WindowStyles.WS_EX_TOOLWINDOW) != 0) {
811 title_style = TitleStyle.Tool;
813 title_style = TitleStyle.Normal;
817 border_style = BorderStyle.None;
818 if ((Style & (int)WindowStyles.WS_CHILD) != 0) {
819 if ((Style & (int)WindowStyles.WS_THICKFRAME) != 0) {
820 border_style = BorderStyle.Fixed3D;
821 } else if ((Style & (int)WindowStyles.WS_BORDER) != 0) {
822 border_style = BorderStyle.FixedSingle;
826 WindowRect = Hwnd.GetWindowRectangle(border_style, MenuHandle, title_style, ClientRect);
831 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
832 CGPoint pt = new CGPoint ();
833 Rect wBounds = new Rect ();
836 hwnd = Hwnd.ObjectFromHandle(handle);
841 GetWindowBounds (GetControlOwner (hwnd.client_window), 32, ref wBounds);
842 HIViewConvertPoint (ref pt, handle, IntPtr.Zero);
844 x = (int)(pt.x+wBounds.left);
845 y = (int)(pt.y+wBounds.top);
848 internal override void CreateCaret (IntPtr hwnd, int width, int height) {
849 if (Caret.Hwnd != IntPtr.Zero)
850 DestroyCaret (Caret.Hwnd);
854 Caret.Height = height;
859 internal override IntPtr CreateWindow(CreateParams cp) {
860 IntPtr windowHnd = IntPtr.Zero;
861 IntPtr parentHnd = cp.Parent;
862 bool realWindow = false;
863 Rectangle clientRect;
864 Hwnd hwnd = new Hwnd ();
866 SetHwndStyles (hwnd, cp);
868 if (parentHnd == IntPtr.Zero) {
869 if ((cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
870 // This is a child view that is going to be parentless;
872 CheckError (HIViewFindByID (HIViewGetRoot (FosterParent), new HIViewID (OSXConstants.kEventClassWindow, 1), ref parentHnd), "HIViewFindByID ()");
873 } else if ((cp.Style & (int)(WindowStyles.WS_POPUP))!=0) {
874 // This is a popup window that will be real.
875 if (cp.X < 1) cp.X = 0;
876 if (cp.Y < 1) cp.Y = 0;
879 // This is a real root window too
880 if (cp.X < 1) cp.X = 0;
881 if (cp.Y < 1) cp.Y = 0;
889 WindowClass windowklass = WindowClass.kOverlayWindowClass;
890 WindowAttributes attributes = WindowAttributes.kWindowCompositingAttribute | WindowAttributes.kWindowStandardHandlerAttribute;
891 if ((cp.Style & ((int)WindowStyles.WS_MINIMIZEBOX)) != 0) {
892 attributes |= WindowAttributes.kWindowCollapseBoxAttribute;
894 if ((cp.Style & ((int)WindowStyles.WS_MAXIMIZEBOX)) != 0) {
895 attributes |= WindowAttributes.kWindowResizableAttribute | WindowAttributes.kWindowHorizontalZoomAttribute | WindowAttributes.kWindowVerticalZoomAttribute;
897 if ((cp.Style & ((int)WindowStyles.WS_SYSMENU)) != 0) {
898 attributes |= WindowAttributes.kWindowCloseBoxAttribute;
900 if ((cp.ExStyle & ((int)WindowStyles.WS_EX_TOOLWINDOW)) != 0) {
901 attributes = WindowAttributes.kWindowStandardHandlerAttribute | WindowAttributes.kWindowCompositingAttribute;
903 if ((cp.Style & ((int)WindowStyles.WS_CAPTION)) != 0) {
904 windowklass = WindowClass.kDocumentWindowClass;
907 IntPtr rect = IntPtr.Zero;
908 IntPtr viewHnd = IntPtr.Zero;
909 SetRect (ref rect, (short)cp.X, (short)(cp.Y + MenuBarHeight + TitleBarHeight), (short)(cp.Width+cp.X), (short)(cp.Height+cp.Y+MenuBarHeight+TitleBarHeight));
910 CheckError (CreateNewWindow (windowklass, attributes, ref rect, ref windowHnd), "CreateNewWindow ()");
912 CheckError (InstallEventHandler (GetWindowEventTarget (windowHnd), CarbonEventHandler, (uint)windowEvents.Length, windowEvents, windowHnd, IntPtr.Zero), "InstallEventHandler ()");
913 CheckError (HIViewFindByID (HIViewGetRoot (windowHnd), new HIViewID (OSXConstants.kEventClassWindow, 1), ref viewHnd), "HIViewFindByID ()");
918 hwnd.Width = cp.Width;
919 hwnd.Height = cp.Height;
920 hwnd.Parent = Hwnd.ObjectFromHandle (cp.Parent);
921 hwnd.visible = false;
922 clientRect = hwnd.ClientRect;
924 HIRect r = new HIRect (0, 0, cp.Width, cp.Height);
925 CheckError (HIObjectCreate (__CFStringMakeConstantString ("com.apple.hiview"), 0, ref hwnd.whole_window), "HIObjectCreate ()");
926 CheckError (InstallEventHandler (GetControlEventTarget (hwnd.whole_window), CarbonEventHandler, (uint)viewEvents.Length, viewEvents, hwnd.whole_window, IntPtr.Zero), "InstallEventHandler ()");
927 CheckError (HIViewChangeFeatures (hwnd.whole_window, 1 << 1, 0), "HIViewChangeFeatures ()");
928 CheckError (HIViewSetFrame (hwnd.whole_window, ref r), "HIViewSetFrame ()");
929 hwnd.WholeWindow = hwnd.whole_window;
931 r = new HIRect (0, 0, clientRect.Width, clientRect.Height);
932 CheckError (HIObjectCreate (__CFStringMakeConstantString ("com.apple.hiview"), 0, ref hwnd.client_window), "HIObjectCreate ()");
933 CheckError (InstallEventHandler (GetControlEventTarget (hwnd.client_window), CarbonEventHandler, (uint)viewEvents.Length, viewEvents, hwnd.client_window, IntPtr.Zero), "InstallEventHandler ()");
934 CheckError (HIViewChangeFeatures (hwnd.client_window, 1 << 1, 0), "HIViewChangeFeatures ()");
935 CheckError (HIViewSetFrame (hwnd.client_window, ref r), "HIViewSetFrame ()");
936 hwnd.ClientWindow = hwnd.client_window;
938 CheckError (HIViewAddSubview (hwnd.whole_window, hwnd.client_window));
939 CheckError (HIViewPlaceInSuperviewAt (hwnd.client_window, clientRect.X, clientRect.Y));
941 if (parentHnd != IntPtr.Zero && parentHnd != hwnd.WholeWindow) {
942 CheckError (HIViewAddSubview (parentHnd, hwnd.whole_window), "HIViewAddSubview ()");
943 CheckError (HIViewPlaceInSuperviewAt (hwnd.whole_window, cp.X, cp.Y), "HIPlaceInSuperviewAt ()");
944 if ((cp.Style & (int)(WindowStyles.WS_VISIBLE))!=0) {
945 CheckError (HIViewSetVisible (hwnd.whole_window, true), "HIViewSetVisible ()");
946 CheckError (HIViewSetVisible (hwnd.client_window, true), "HIViewSetVisible ()");
949 CheckError (HIViewSetVisible (hwnd.whole_window, false), "HIViewSetVisible ()");
950 CheckError (HIViewSetVisible (hwnd.client_window, false), "HIViewSetVisible ()");
951 hwnd.visible = false;
955 WindowMapping [hwnd.Handle] = windowHnd;
956 if ((cp.Style & (int)(WindowStyles.WS_VISIBLE))!=0) {
957 CheckError (ShowWindow (windowHnd));
958 CheckError (HIViewSetVisible (hwnd.whole_window, true), "HIViewSetVisible ()");
959 CheckError (HIViewSetVisible (hwnd.client_window, true), "HIViewSetVisible ()");
962 if ((cp.Style & (int)(WindowStyles.WS_POPUP))!=0) {
963 CheckError (HIViewSetVisible (hwnd.whole_window, true), "HIViewSetVisible ()");
964 CheckError (HIViewSetVisible (hwnd.client_window, true), "HIViewSetVisible ()");
972 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
973 CreateParams create_params = new CreateParams();
975 create_params.Caption = "";
978 create_params.Width = Width;
979 create_params.Height = Height;
981 create_params.ClassName=XplatUI.DefaultClassName;
982 create_params.ClassStyle = 0;
983 create_params.ExStyle=0;
984 create_params.Parent=IntPtr.Zero;
985 create_params.Param=0;
987 return CreateWindow(create_params);
991 internal override IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
992 throw new NotImplementedException ();
996 internal override IntPtr DefineStdCursor(StdCursor id) {
998 case StdCursor.AppStarting:
999 return (IntPtr)ThemeCursor.kThemeSpinningCursor;
1000 case StdCursor.Arrow:
1001 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1002 case StdCursor.Cross:
1003 return (IntPtr)ThemeCursor.kThemeCrossCursor;
1004 case StdCursor.Default:
1005 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1006 case StdCursor.Hand:
1007 return (IntPtr)ThemeCursor.kThemeOpenHandCursor;
1008 case StdCursor.Help:
1009 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1010 case StdCursor.HSplit:
1011 return (IntPtr)ThemeCursor.kThemeResizeLeftRightCursor;
1012 case StdCursor.IBeam:
1013 return (IntPtr)ThemeCursor.kThemeIBeamCursor;
1015 return (IntPtr)ThemeCursor.kThemeNotAllowedCursor;
1016 case StdCursor.NoMove2D:
1017 return (IntPtr)ThemeCursor.kThemeNotAllowedCursor;
1018 case StdCursor.NoMoveHoriz:
1019 return (IntPtr)ThemeCursor.kThemeNotAllowedCursor;
1020 case StdCursor.NoMoveVert:
1021 return (IntPtr)ThemeCursor.kThemeNotAllowedCursor;
1022 case StdCursor.PanEast:
1023 return (IntPtr)ThemeCursor.kThemeResizeRightCursor;
1024 case StdCursor.PanNE:
1025 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1026 case StdCursor.PanNorth:
1027 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1028 case StdCursor.PanNW:
1029 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1030 case StdCursor.PanSE:
1031 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1032 case StdCursor.PanSouth:
1033 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1034 case StdCursor.PanSW:
1035 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1036 case StdCursor.PanWest:
1037 return (IntPtr)ThemeCursor.kThemeResizeLeftCursor;
1038 case StdCursor.SizeAll:
1039 return (IntPtr)ThemeCursor.kThemeResizeLeftRightCursor;
1040 case StdCursor.SizeNESW:
1041 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1042 case StdCursor.SizeNS:
1043 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1044 case StdCursor.SizeNWSE:
1045 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1046 case StdCursor.SizeWE:
1047 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1048 case StdCursor.UpArrow:
1049 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1050 case StdCursor.VSplit:
1051 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1052 case StdCursor.WaitCursor:
1053 return (IntPtr)ThemeCursor.kThemeSpinningCursor;
1055 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1059 internal override IntPtr DefWndProc(ref Message msg) {
1060 Hwnd hwnd = Hwnd.ObjectFromHandle (msg.HWnd);
1061 switch ((Msg)msg.Msg) {
1062 case Msg.WM_DESTROY: {
1063 if (WindowMapping [hwnd.Handle] != null)
1072 internal override void DestroyCaret (IntPtr hwnd) {
1073 if (Caret.Hwnd == hwnd) {
1074 if (Caret.Visible == 1) {
1075 Caret.Timer.Stop ();
1078 Caret.Hwnd = IntPtr.Zero;
1085 internal override void DestroyCursor(IntPtr cursor) {
\r
1086 throw new NotImplementedException ();
1089 internal override void DestroyWindow(IntPtr handle) {
1092 hwnd = Hwnd.ObjectFromHandle(handle);
1094 if ((hwnd.whole_window != IntPtr.Zero) && HIViewGetSuperview (hwnd.whole_window) != IntPtr.Zero)
1095 CheckError (HIViewRemoveFromSuperview (handle), "HIViewRemoveFromSuperview ()");
1097 if (WindowMapping [hwnd.Handle] != null) {
1098 DisposeWindow ((IntPtr)(WindowMapping [hwnd.Handle]));
1100 CFRelease (hwnd.ClientWindow);
1101 CFRelease (hwnd.WholeWindow);
1104 internal override IntPtr DispatchMessage(ref MSG msg) {
1105 return NativeWindow.WndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
1108 internal override void DoEvents() {
1111 internal override void EnableWindow(IntPtr handle, bool Enable) {
1112 //Like X11 we need not do anything here
1115 internal override void EraseWindowBackground(IntPtr handle, IntPtr wParam) {
\r
1116 throw new NotImplementedException();
\r
1120 internal override void Exit() {
1121 GetMessageResult = false;
1125 internal override IntPtr GetActive() {
1126 foreach (DictionaryEntry entry in WindowMapping)
1127 if (IsWindowActive ((IntPtr)(entry.Value)))
1128 return (IntPtr)(entry.Key);
1134 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1135 throw new NotImplementedException ();
1138 internal override void GetDisplaySize(out Size size) {
1139 HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1140 size = new Size ((int)bounds.size.width, (int)bounds.size.height);
1143 internal override IntPtr GetParent(IntPtr handle) {
1146 hwnd = Hwnd.ObjectFromHandle(handle);
1147 if (hwnd != null && hwnd.parent != null) {
1148 return hwnd.parent.Handle;
1153 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1154 QDPoint pt = new QDPoint ();
1155 GetGlobalMouse (ref pt);
1160 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1161 return GetFontMetrics(g.GetHdc(), font.ToHfont(), out ascent, out descent);
1165 internal override Graphics GetMenuDC(IntPtr hwnd, IntPtr ncpaint_region) {
1166 throw new NotImplementedException();
1170 internal override Point GetMenuOrigin(IntPtr hwnd) {
1171 throw new NotImplementedException();
1174 internal override bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1175 IntPtr evtRef = IntPtr.Zero;
1176 IntPtr target = GetEventDispatcherTarget();
1177 CheckTimers (DateTime.Now);
1178 ReceiveNextEvent (0, IntPtr.Zero, 0, true, ref evtRef);
1179 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1180 SendEventToEventTarget (evtRef, target);
1181 ReleaseEvent (evtRef);
1184 lock (MessageQueue) {
1185 if (MessageQueue.Count <= 0) {
1187 Idle (this, EventArgs.Empty);
1188 else if (TimerList.Count == 0) {
1189 ReceiveNextEvent (0, IntPtr.Zero, Convert.ToDouble ("0." + Timer.Minimum), true, ref evtRef);
1190 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1191 SendEventToEventTarget (evtRef, target);
1192 ReleaseEvent (evtRef);
1195 ReceiveNextEvent (0, IntPtr.Zero, NextTimeout (), true, ref evtRef);
1196 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1197 SendEventToEventTarget (evtRef, target);
1198 ReleaseEvent (evtRef);
1201 msg.hwnd = IntPtr.Zero;
1202 msg.message = Msg.WM_ENTERIDLE;
1203 return GetMessageResult;
1205 msg = (MSG) MessageQueue.Dequeue ();
1207 return GetMessageResult;
1211 internal override bool GetText(IntPtr handle, out string text) {
1212 throw new NotImplementedException ();
1215 internal override void GetWindowPos(IntPtr handle, bool is_toplevel, out int x, out int y, out int width, out int height, out int client_width, out int client_height) {
1216 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1217 Rectangle rect = hwnd.ClientRect;
1222 height = hwnd.height;
1224 client_width = rect.Width;
1225 client_height = rect.Height;
1228 internal override FormWindowState GetWindowState(IntPtr hwnd) {
1229 IntPtr window = GetControlOwner (hwnd);
1231 if (IsWindowCollapsed (window))
1232 return FormWindowState.Minimized;
1233 if (IsWindowInStandardState (window, IntPtr.Zero, IntPtr.Zero))
1234 return FormWindowState.Maximized;
1236 return FormWindowState.Normal;
1239 internal override void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
1241 GrabConfined = Grab.Confined;
1242 GrabArea = Grab.Area;
1245 internal override void GrabWindow(IntPtr handle, IntPtr confine_to_handle) {
1246 GrabWindowHwnd = Hwnd.ObjectFromHandle (handle);
1249 internal override void UngrabWindow(IntPtr hwnd) {
1250 GrabWindowHwnd = null;
1251 Grab.Hwnd = IntPtr.Zero;
1252 Grab.Confined = false;
1255 internal override void HandleException(Exception e) {
1256 StackTrace st = new StackTrace(e);
1257 Console.WriteLine("Exception '{0}'", e.Message+st.ToString());
1258 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1261 internal override void Invalidate (IntPtr handle, Rectangle rc, bool clear) {
1262 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1265 MSG msg = new MSG ();
1266 msg.hwnd = hwnd.Handle;
1267 msg.wParam = IntPtr.Zero;
1268 msg.lParam = IntPtr.Zero;
1269 msg.message = Msg.WM_PAINT;
1270 MessageQueue.Enqueue (msg);
1271 // This is currently causing some graphics corruption
1272 //hwnd.AddInvalidArea (rc.X, rc.Y, rc.Width, rc.Height);
1273 hwnd.AddInvalidArea (0, 0, hwnd.ClientRect.Width, hwnd.ClientRect.Height);
1274 hwnd.expose_pending = true;
1278 internal override bool IsVisible(IntPtr handle) {
1279 return Hwnd.ObjectFromHandle(handle).visible;
1282 internal override void KillTimer(Timer timer) {
1284 TimerList.Remove(timer);
1288 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
1289 CGPoint pt = new CGPoint ();
1290 Rect wBounds = new Rect ();
1293 hwnd = Hwnd.ObjectFromHandle(handle);
1298 GetWindowBounds (GetControlOwner (hwnd.whole_window), 32, ref wBounds);
1299 HIViewConvertPoint (ref pt, handle, IntPtr.Zero);
1301 x = (int)(pt.x+wBounds.left);
1302 y = (int)(pt.y+wBounds.top);
1306 internal override void OverrideCursor(IntPtr cursor) {
1307 throw new NotImplementedException ();
1310 internal override PaintEventArgs PaintEventStart(IntPtr handle) {
1311 PaintEventArgs paint_event;
1314 hwnd = Hwnd.ObjectFromHandle(handle);
1316 if (Caret.Visible == 1) {
1317 Caret.Paused = true;
1320 hwnd.client_dc = Graphics.FromHwnd (hwnd.client_window);
1321 paint_event = new PaintEventArgs(hwnd.client_dc, hwnd.invalid);
1326 internal override void PaintEventEnd(IntPtr handle) {
1329 hwnd = Hwnd.ObjectFromHandle(handle);
1331 hwnd.ClearInvalidArea();
1333 hwnd.client_dc.Flush();
1334 hwnd.client_dc.Dispose();
1335 hwnd.client_dc = null;
1336 hwnd.expose_pending = false;
1338 if (Caret.Visible == 1) {
1340 Caret.Paused = false;
1344 internal override bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1345 Console.WriteLine("XplatUIOSX.PeekMessage");
1349 public static void PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
1350 MSG msg = new MSG();
1352 msg.message = message;
1353 msg.wParam = wParam;
1354 msg.lParam = lParam;
1355 MessageQueue.Enqueue (msg);
1359 internal override void ReleaseMenuDC(IntPtr hwnd, Graphics dc) {
1360 throw new NotImplementedException();
1363 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y) {
1364 CGPoint pt = new CGPoint ();
1365 Rect wBounds = new Rect ();
1367 GetWindowBounds (GetControlOwner (handle), 32, ref wBounds);
1368 pt.x = (x-wBounds.left);
1369 pt.y = (y-wBounds.top);
1370 HIViewConvertPoint (ref pt, IntPtr.Zero, handle);
1377 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
1378 CGPoint pt = new CGPoint ();
1379 Rect wBounds = new Rect ();
1381 GetWindowBounds (GetControlOwner (handle), 32, ref wBounds);
1382 pt.x = (x-wBounds.left);
1383 pt.y = (y-wBounds.top);
1384 HIViewConvertPoint (ref pt, IntPtr.Zero, handle);
1390 internal override void ScrollWindow(IntPtr handle, Rectangle area, int XAmount, int YAmount, bool clear) {
1391 //IntPtr rect = IntPtr.Zero;
1392 //HIRect vBounds = new HIRect ();
1394 Hwnd hwnd = Hwnd.ObjectFromHandle(handle);
1397 if (hwnd.invalid != Rectangle.Empty) {
1398 // BIG FAT WARNING. This only works with how we use this function right now
1399 // where we basically still scroll the whole window, but work around areas
1400 // that are covered by our children
1402 hwnd.invalid.X += XAmount;
1403 hwnd.invalid.Y += YAmount;
1405 if (hwnd.invalid.X < 0) {
1406 hwnd.invalid.Width += hwnd.invalid.X;
1410 if (hwnd.invalid.Y < 0) {
1411 hwnd.invalid.Height += hwnd.invalid.Y;
1416 HIRect scrollrect = new HIRect ();
1417 scrollrect.origin.x = area.X;
1418 scrollrect.origin.y = area.Y;
1419 scrollrect.size.width = area.Width;
1420 scrollrect.size.height = area.Height;
1421 HIViewScrollRect (hwnd.Handle, ref scrollrect, (float)XAmount, (float)-YAmount);
1423 HIViewGetBounds (hwnd.client_window, ref vBounds);
1424 HIViewConvertRect (ref vBounds, hwnd.client_window, IntPtr.Zero);
1425 SetRect (ref rect, (short)(vBounds.origin.x+area.X), (short)(vBounds.origin.y-TitleBarHeight+area.Y), (short)(vBounds.origin.x+area.Width), (short)(vBounds.origin.y+area.Height-TitleBarHeight));
1426 ScrollRect (ref rect, (short)XAmount, (short)-YAmount, IntPtr.Zero);
1428 // Generate an expose for the area exposed by the horizontal scroll
1431 hwnd.AddInvalidArea (area.X, area.Y, XAmount, area.Height);
1432 } else if (XAmount < 0) {
1433 hwnd.AddInvalidArea (XAmount + area.X + area.Width, area.Y, -XAmount, area.Height);
1436 // Generate an expose for the area exposed by the vertical scroll
1438 hwnd.AddInvalidArea (area.X, area.Y, area.Width, YAmount);
1439 } else if (YAmount < 0) {
1440 hwnd.AddInvalidArea (area.X, YAmount + area.Y + area.Height, area.Width, -YAmount);
1443 UpdateWindow (handle);
1448 internal override void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool clear) {
1449 throw new NotImplementedException("");
1453 internal override void SendAsyncMethod (AsyncMethodData method) {
1454 throw new NotImplementedException ();
1457 internal override void SetCaretPos (IntPtr hwnd, int x, int y) {
1458 if (Caret.Hwnd == hwnd) {
1459 CGPoint cpt = new CGPoint ();
1462 HIViewConvertPoint (ref cpt, hwnd, IntPtr.Zero);
1463 Caret.Timer.Stop ();
1465 Caret.X = (int)cpt.x;
1466 Caret.Y = (int)cpt.y-23;
1467 if (Caret.Visible == 1) {
1469 Caret.Timer.Start ();
1474 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1475 SetThemeCursor ((uint) cursor);
1478 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1479 CGDisplayMoveCursorToPoint (CGMainDisplayID (), new CGPoint (x, y));
1482 internal override void SetFocus(IntPtr handle) {
1483 if (FocusWindow != IntPtr.Zero) {
1484 PostMessage(FocusWindow, Msg.WM_KILLFOCUS, handle, IntPtr.Zero);
1486 PostMessage(handle, Msg.WM_SETFOCUS, FocusWindow, IntPtr.Zero);
1487 FocusWindow = handle;
1491 internal override void SetIcon(IntPtr handle, Icon icon) {
\r
1492 throw new NotImplementedException();
\r
1496 internal override void SetModal(IntPtr handle, bool Modal) {
1497 IntPtr hWnd = GetControlOwner (Hwnd.ObjectFromHandle (handle).WholeWindow);
1499 BeginAppModalStateForWindow (hWnd);
1501 EndAppModalStateForWindow (hWnd);
1505 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1506 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1508 hwnd.parent = Hwnd.ObjectFromHandle (parent);
1509 if (HIViewGetSuperview (hwnd.whole_window) != IntPtr.Zero) {
1510 CheckError (HIViewRemoveFromSuperview (hwnd.whole_window), "HIViewRemoveFromSuperview ()");
1512 CheckError (HIViewAddSubview (hwnd.parent.client_window, hwnd.whole_window));
1513 CheckError (HIViewAddSubview (hwnd.whole_window, hwnd.client_window));
1514 HIViewPlaceInSuperviewAt (hwnd.client_window, hwnd.ClientRect.X, hwnd.ClientRect.Y);
1519 internal override void SetTimer (Timer timer) {
1521 TimerList.Add (timer);
1525 internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
1526 HIViewSetZOrder (hWnd, 1, IntPtr.Zero);
1531 internal override bool SetVisible(IntPtr handle, bool visible) {
1532 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1533 object window = WindowMapping [hwnd.Handle];
1536 ShowWindow ((IntPtr)window);
1538 HideWindow ((IntPtr)window);
1540 HIViewSetVisible (hwnd.whole_window, visible);
1541 HIViewSetVisible (hwnd.client_window, visible);
1542 hwnd.visible = visible;
1546 internal override void SetWindowBackground(IntPtr handle, Color color) {
1547 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1549 if (WindowMapping [hwnd.Handle] != null) {
1550 RGBColor backColor = new RGBColor ();
1551 backColor.red = (short)(color.R * 257);
1552 backColor.green = (short)(color.G * 257);
1553 backColor.blue = (short)(color.B * 257);
1555 CheckError (SetWindowContentColor ((IntPtr) WindowMapping [hwnd.Handle], ref backColor));
1557 WindowBackgrounds [hwnd] = color;
1561 internal override void SetBorderStyle(IntPtr handle, BorderStyle border_style) {
\r
1564 hwnd = Hwnd.ObjectFromHandle(handle);
\r
1565 hwnd.border_style = border_style;
\r
1567 // FIXME - do we need to trigger some resize?
\r
1570 internal override void SetMenu(IntPtr handle, IntPtr menu_handle) {
\r
1573 hwnd = Hwnd.ObjectFromHandle(handle);
\r
1574 hwnd.menu_handle = menu_handle;
\r
1576 // FIXME - do we need to trigger some resize?
\r
1579 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1580 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1581 Rectangle client_rect = Hwnd.GetClientRectangle(hwnd.border_style, hwnd.menu_handle, hwnd.title_style, width, height);
1583 // Save a server roundtrip (and prevent a feedback loop)
1584 if ((hwnd.x == x) && (hwnd.y == y) && (hwnd.width == width) && (hwnd.height == height)) {
1589 if (WindowMapping [hwnd.Handle] != null) {
1590 if (y <= MenuBarHeight+TitleBarHeight) {
1591 y+=MenuBarHeight+TitleBarHeight;
1593 IntPtr rect = IntPtr.Zero;
1594 SetRect (ref rect, (short)x, (short)y, (short)(x+width), (short)(y+height));
1595 CheckError (SetWindowBounds ((IntPtr) WindowMapping [hwnd.Handle], 33, ref rect), "SetWindowBounds ()");
1596 HIRect r = new HIRect (0, 0, width, height);
1597 CheckError (HIViewSetFrame (hwnd.whole_window, ref r), "HIViewSetFrame ()");
1598 r = new HIRect (client_rect.X, client_rect.Y, client_rect.X+client_rect.Width, client_rect.Y+client_rect.Height);
1599 CheckError (HIViewSetFrame (hwnd.client_window, ref r), "HIViewSetFrame ()");
1601 HIRect r = new HIRect (x, y, width, height);
1602 CheckError (HIViewSetFrame (hwnd.whole_window, ref r), "HIViewSetFrame ()");
1603 r = new HIRect (client_rect.X, client_rect.Y, client_rect.X+client_rect.Width, client_rect.Y+client_rect.Height);
1604 CheckError (HIViewSetFrame (hwnd.client_window, ref r), "HIViewSetFrame ()");
1608 internal override void SetWindowState(IntPtr hwnd, FormWindowState state) {
1609 IntPtr window = GetControlOwner (hwnd);
1612 case FormWindowState.Minimized: {
1613 CollapseWindow (window, true);
1616 case FormWindowState.Normal: {
1617 ZoomWindow (window, 7, false);
1620 case FormWindowState.Maximized: {
1621 ZoomWindow (window, 8, false);
1627 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1628 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1629 SetHwndStyles(hwnd, cp);
1631 if (WindowMapping [hwnd.Handle] != null) {
1632 WindowAttributes attributes = WindowAttributes.kWindowCompositingAttribute | WindowAttributes.kWindowStandardHandlerAttribute;
1633 if ((cp.Style & ((int)WindowStyles.WS_MINIMIZEBOX)) != 0) {
1634 attributes |= WindowAttributes.kWindowCollapseBoxAttribute;
1636 if ((cp.Style & ((int)WindowStyles.WS_MAXIMIZEBOX)) != 0) {
1637 attributes |= WindowAttributes.kWindowResizableAttribute | WindowAttributes.kWindowHorizontalZoomAttribute | WindowAttributes.kWindowVerticalZoomAttribute;
1639 if ((cp.Style & ((int)WindowStyles.WS_SYSMENU)) != 0) {
1640 attributes |= WindowAttributes.kWindowCloseBoxAttribute;
1642 if ((cp.ExStyle & ((int)WindowStyles.WS_EX_TOOLWINDOW)) != 0) {
1643 attributes = WindowAttributes.kWindowStandardHandlerAttribute | WindowAttributes.kWindowCompositingAttribute;
1646 WindowAttributes outAttributes = WindowAttributes.kWindowNoAttributes;
1647 GetWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], ref outAttributes);
1648 ChangeWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], attributes, outAttributes);
1652 internal override bool SetZOrder(IntPtr handle, IntPtr after_handle, bool Top, bool Bottom) {
1653 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1656 HIViewSetZOrder (hwnd.whole_window, 2, IntPtr.Zero);
1658 } else if (!Bottom) {
1659 Hwnd after_hwnd = Hwnd.ObjectFromHandle (after_handle);
1660 HIViewSetZOrder (hwnd.whole_window, 2, after_hwnd.whole_window);
1662 HIViewSetZOrder (hwnd.whole_window, 1, IntPtr.Zero);
1668 internal override void ShowCursor(bool show) {
1670 CGDisplayShowCursor (CGMainDisplayID ());
1672 CGDisplayHideCursor (CGMainDisplayID ());
1676 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
\r
1677 throw new NotImplementedException();
\r
1681 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
\r
1682 throw new NotImplementedException();
\r
1686 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
\r
1687 throw new NotImplementedException();
\r
1690 internal override bool Text(IntPtr handle, string text) {
1691 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1692 if (WindowMapping [hwnd.Handle] != null) {
1693 CheckError (SetWindowTitleWithCFString ((IntPtr)(WindowMapping [hwnd.Handle]), __CFStringMakeConstantString (text)));
1695 CheckError (SetControlTitleWithCFString (hwnd.whole_window, __CFStringMakeConstantString (text)));
1696 CheckError (SetControlTitleWithCFString (hwnd.client_window, __CFStringMakeConstantString (text)));
1700 internal override void UpdateWindow(IntPtr handle) {
1701 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1703 if (hwnd.visible && !hwnd.expose_pending) {
1704 MSG msg = new MSG ();
1705 msg.message = Msg.WM_PAINT;
1706 msg.hwnd = hwnd.Handle;
1707 msg.lParam = IntPtr.Zero;
1708 msg.wParam = IntPtr.Zero;
1709 MessageQueue.Enqueue (msg);
1713 internal override bool TranslateMessage(ref MSG msg) {
1715 Hwnd hwnd = Hwnd.ObjectFromHandle (msg.hwnd);
1717 switch (msg.message) {
1718 case Msg.WM_MOUSEMOVE: {
1720 if (GrabWindowHwnd != null) {
1721 if (GrabWindowHwnd.Handle != hwnd.Handle) {
1725 if (MouseWindow != null) {
1726 if (MouseWindow.Handle != hwnd.Handle) {
1727 PostMessage (MouseWindow.Handle, Msg.WM_MOUSE_LEAVE, IntPtr.Zero, IntPtr.Zero);
1728 PostMessage (hwnd.Handle, Msg.WM_MOUSE_ENTER, IntPtr.Zero, IntPtr.Zero);
1737 case Msg.WM_SETFOCUS: {
1743 // This is a hideous temporary keyboard hack to bind some keys
1744 if (msg.message >= Msg.WM_KEYFIRST && msg.message <= Msg.WM_KEYLAST)
1747 if (msg.message != Msg.WM_KEYDOWN && msg.message != Msg.WM_SYSKEYDOWN)
1750 if ((int)msg.wParam >= (int)'0' && (int)msg.wParam <= (int)'z') {
1752 message = Msg.WM_CHAR;
1753 PostMessage (msg.hwnd, message, msg.wParam, msg.lParam);
1760 #region System information
1761 internal override int KeyboardSpeed { get{ throw new NotImplementedException(); } }
1762 internal override int KeyboardDelay { get{ throw new NotImplementedException(); } }
1764 internal override Size CursorSize { get{ throw new NotImplementedException(); } }
1765 internal override bool DragFullWindows { get{ throw new NotImplementedException(); } }
1766 internal override Size DragSize { get{ throw new NotImplementedException(); } }
1767 internal override Size IconSize { get{ throw new NotImplementedException(); } }
1768 internal override Size MaxWindowTrackSize { get{ throw new NotImplementedException(); } }
1769 internal override Size MinimizedWindowSize { get{ throw new NotImplementedException(); } }
1770 internal override Size MinimizedWindowSpacingSize { get{ throw new NotImplementedException(); } }
1771 internal override Size MinimumWindowSize { get{ throw new NotImplementedException(); } }
1772 internal override Size MinWindowTrackSize { get{ throw new NotImplementedException(); } }
1773 internal override Size SmallIconSize { get{ throw new NotImplementedException(); } }
1774 internal override int MouseButtonCount { get{ throw new NotImplementedException(); } }
1775 internal override bool MouseButtonsSwapped { get{ throw new NotImplementedException(); } }
1776 internal override bool MouseWheelPresent { get{ throw new NotImplementedException(); } }
1777 internal override Rectangle VirtualScreen { get{ throw new NotImplementedException(); } }
1778 internal override Rectangle WorkingArea {
1780 HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1781 return new Rectangle ((int)bounds.origin.x, (int)bounds.origin.y, (int)bounds.size.width, (int)bounds.size.height);
1786 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1787 internal static extern int HIViewSetNeedsDisplayInRegion (IntPtr view, IntPtr rgn, bool needsDisplay);
1788 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1789 internal static extern int HIViewGetSubviewHit (IntPtr contentView, ref CGPoint point, bool tval, ref IntPtr outPtr);
1790 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1791 internal static extern int HIViewGetViewForMouseEvent (IntPtr inView, IntPtr inEvent, ref IntPtr outView);
1792 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1793 internal static extern int HIViewConvertPoint (ref CGPoint point, IntPtr pView, IntPtr cView);
1794 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1795 internal static extern int HIViewChangeFeatures (IntPtr aView, ulong bitsin, ulong bitsout);
1796 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1797 internal static extern int HIViewFindByID (IntPtr rootWnd, HIViewID id, ref IntPtr outPtr);
1798 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1799 internal static extern IntPtr HIViewGetRoot (IntPtr hWnd);
1800 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1801 internal static extern int HIObjectCreate (IntPtr cfStr, uint what, ref IntPtr hwnd);
1802 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1803 internal static extern int HIViewSetNeedsDisplay (IntPtr viewHnd, bool update);
1804 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1805 internal static extern int HIViewGetFrame (IntPtr viewHnd, ref HIRect rect);
1806 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1807 internal static extern int HIViewSetFrame (IntPtr viewHnd, ref HIRect rect);
1808 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1809 internal static extern int HIViewPlaceInSuperviewAt (IntPtr view, float x, float y);
1810 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1811 internal static extern int HIViewAddSubview (IntPtr parentHnd, IntPtr childHnd);
1812 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1813 internal static extern IntPtr HIViewGetNextView (IntPtr aView);
1814 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1815 internal static extern IntPtr HIViewGetPreviousView (IntPtr aView);
1816 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1817 internal static extern IntPtr HIViewGetFirstSubview (IntPtr aView);
1818 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1819 internal static extern IntPtr HIViewGetSuperview (IntPtr aView);
1820 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1821 internal static extern int HIViewRemoveFromSuperview (IntPtr aView);
1822 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1823 internal static extern int HIViewSetVisible (IntPtr vHnd, bool visible);
1824 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1825 internal static extern bool HIViewIsVisible (IntPtr vHnd);
1826 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1827 internal static extern int HIViewGetBounds (IntPtr vHnd, ref HIRect r);
1828 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1829 internal static extern int HIViewScrollRect (IntPtr vHnd, ref HIRect rect, float x, float y);
1830 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1831 internal static extern int HIViewScrollRect (IntPtr vHnd, IntPtr rect, float x, float y);
1832 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1833 internal static extern int HIViewSetZOrder (IntPtr hWnd, int cmd, IntPtr oHnd);
1834 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1835 internal static extern int HIViewSetBoundsOrigin (IntPtr vHnd, float x, float y);
1836 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1837 internal static extern int HIViewConvertRect (ref HIRect r, IntPtr a, IntPtr b);
1839 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1840 internal static extern void ScrollRect (ref IntPtr r, short dh, short dv, IntPtr rgnHandle);
1841 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1842 internal static extern void SetRect (ref IntPtr r, short left, short top, short right, short bottom);
1844 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1845 static extern int CreateEvent (IntPtr allocator, uint classid, uint kind, double when, uint attributes, ref IntPtr outEvent);
1846 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1847 static extern int InstallEventHandler (IntPtr window, CarbonEventDelegate handlerProc, uint numtypes, EventTypeSpec [] typeList, IntPtr userData, IntPtr handlerRef);
1848 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1849 internal static extern IntPtr GetControlOwner (IntPtr aView);
1850 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1851 static extern int ActivateWindow (IntPtr windowHnd, bool inActivate);
1852 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1853 static extern bool IsWindowActive (IntPtr windowHnd);
1854 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1855 static extern int SetKeyboardFocus (IntPtr windowHdn, IntPtr cntrlHnd, short partcode);
1856 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1857 static extern int GetKeyboardFocus (IntPtr handle, ref IntPtr cntrl);
1859 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1860 internal static extern IntPtr GetWindowEventTarget (IntPtr window);
1861 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1862 internal static extern IntPtr GetControlEventTarget (IntPtr aControl);
1863 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1864 internal static extern IntPtr GetEventDispatcherTarget ();
1865 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1866 internal static extern int SendEventToEventTarget (IntPtr evt, IntPtr target);
1867 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1868 internal static extern int ReleaseEvent (IntPtr evt);
1869 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1870 internal static extern int ReceiveNextEvent (uint evtCount, IntPtr evtTypes, double timeout, bool processEvt, ref IntPtr evt);
1871 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1872 static extern uint GetEventClass (IntPtr eventRef);
1873 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1874 static extern uint GetEventKind (IntPtr eventRef);
1875 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1876 static extern int GetEventParameter (IntPtr evt, uint inName, uint inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref byte outData);
1877 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1878 static extern int GetEventParameter (IntPtr evt, uint inName, uint inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref IntPtr outData);
1879 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1880 static extern int GetEventParameter (IntPtr evt, uint inName, uint inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref ushort outData);
1881 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1882 static extern int GetEventParameter (IntPtr evt, uint inName, uint inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref short outData);
1883 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1884 static extern int GetEventParameter (IntPtr evt, uint inName, uint inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref QDPoint outData);
1885 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1886 static extern int SetEventParameter (IntPtr evt, uint inName, uint inType, uint bufSize, ref short outData);
1887 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1888 static extern int SetEventParameter (IntPtr evt, uint inName, uint inType, uint bufSize, ref IntPtr outData);
1890 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1891 internal static extern void CGContextFlush (IntPtr cgc);
1892 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1893 internal static extern int CGContextFillRect (IntPtr cgc, HIRect r);
1894 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1895 internal static extern CGAffineTransform CGContextGetTextMatrix (IntPtr cgContext);
1896 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1897 internal static extern int CGContextSetTextMatrix (IntPtr cgContext, CGAffineTransform ctm);
1898 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1899 internal static extern int CGContextSetRGBFillColor (IntPtr cgContext, float r, float g, float b, float alpha);
1900 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1901 internal static extern int CGContextSetRGBStrokeColor (IntPtr cgContext, float r, float g, float b, float alpha);
1902 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1903 internal static extern int CGContextSetTextDrawingMode (IntPtr cgContext, int drawingMode);
1904 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1905 internal static extern int CGContextSelectFont (IntPtr cgContext, string fontName, float size, int textEncoding);
1906 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1907 internal static extern int CGContextShowTextAtPoint (IntPtr cgContext, float x, float y, string text, int length);
1908 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1909 internal static extern int CGContextClipToRect (IntPtr cgContext, HIRect clip);
1910 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1911 internal static extern void CreateCGContextForPort (IntPtr port, ref IntPtr cgc);
1912 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1913 internal static extern bool IsWindowCollapsed (IntPtr hWnd);
1914 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1915 internal static extern bool IsWindowInStandardState (IntPtr hWnd, IntPtr a, IntPtr b);
1916 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1917 internal static extern void CollapseWindow (IntPtr hWnd, bool collapse);
1918 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1919 internal static extern void ZoomWindow (IntPtr hWnd, short partCode, bool front);
1920 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1921 internal static extern int GetWindowAttributes (IntPtr hWnd, ref WindowAttributes outAttributes);
1922 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1923 internal static extern int ChangeWindowAttributes (IntPtr hWnd, WindowAttributes inAttributes, WindowAttributes outAttributes);
1924 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1925 internal static extern IntPtr GetWindowPort (IntPtr hWnd);
1926 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1927 static extern int SetPortWindowPort (IntPtr hWnd);
1928 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1929 static extern int GetGlobalMouse (ref QDPoint outData);
1930 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1931 static extern int GlobalToLocal (ref QDPoint outData);
1932 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1933 static extern int LocalToGlobal (ref QDPoint outData);
1934 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1935 static extern int TrackControl (IntPtr handle, QDPoint point, IntPtr data);
1937 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1938 internal static extern int BeginAppModalStateForWindow (IntPtr window);
1939 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1940 internal static extern int EndAppModalStateForWindow (IntPtr window);
1941 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1942 internal static extern int CreateNewWindow (WindowClass klass, WindowAttributes attributes, ref IntPtr r, ref IntPtr window);
1943 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1944 internal static extern int DisposeWindow (IntPtr wHnd);
1945 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1946 internal static extern int ShowWindow (IntPtr wHnd);
1947 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1948 internal static extern int HideWindow (IntPtr wHnd);
1949 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1950 internal static extern int SetWindowBounds (IntPtr wHnd, uint reg, ref IntPtr rect);
1951 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1952 internal static extern int GetWindowPortBounds (IntPtr wHnd, ref Rect rect);
1953 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1954 internal static extern int GetWindowBounds (IntPtr wHnd, uint reg, ref Rect rect);
1955 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1956 internal static extern int InvertRect (ref Rect r);
1958 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1959 internal static extern int SetControlTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
1960 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1961 internal static extern int SetWindowTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
1962 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1963 internal static extern IntPtr __CFStringMakeConstantString (string cString);
1965 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1966 internal static extern void CGContextRestoreGState (IntPtr ctx);
1967 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1968 internal static extern void CGContextSaveGState (IntPtr ctx);
1969 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1970 internal static extern void CGContextTranslateCTM (IntPtr ctx, double tx, double ty);
1971 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1972 internal static extern void CGContextScaleCTM (IntPtr ctx, double tx, double ty);
1974 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1975 static extern int SetWindowContentColor (IntPtr hWnd, ref RGBColor backColor);
1976 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1977 static extern int TrackMouseLocationWithOptions (IntPtr port, int options, double eventtimeout, ref QDPoint point, ref IntPtr modifier, ref MouseTrackingResult status);
1978 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1979 static extern int CreateMouseTrackingRegion (IntPtr windowref, IntPtr rgn, IntPtr clip, int options, MouseTrackingRegionID rid, IntPtr refcon, IntPtr evttargetref, ref IntPtr mousetrackref);
1980 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1981 static extern int ReleaseMouseTrackingRegion (IntPtr region_handle);
1983 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1984 internal static extern int CFRelease (IntPtr wHnd);
1986 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1987 internal extern static IntPtr NewRgn ();
1988 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1989 internal extern static void CopyRgn (IntPtr srcrgn, IntPtr destrgn);
1990 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1991 internal extern static void SetRectRgn (IntPtr rgn, short left, short top, short right, short bottom);
1992 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1993 internal extern static void DisposeRgn (IntPtr rgn);
1994 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1995 internal extern static void ExitToShell ();
1996 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1997 internal extern static short GetMBarHeight ();
1999 #region Cursor imports
2000 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2001 internal extern static HIRect CGDisplayBounds (IntPtr displayID);
2002 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2003 internal extern static IntPtr CGMainDisplayID ();
2004 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2005 internal extern static void CGDisplayShowCursor (IntPtr display);
2006 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2007 internal extern static void CGDisplayHideCursor (IntPtr display);
2008 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2009 internal extern static void CGDisplayMoveCursorToPoint (IntPtr display, CGPoint point);
2010 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2011 internal extern static void SetThemeCursor (uint inCursor);
2014 [DllImport ("gdiplus", EntryPoint="GetFontMetrics")]
2015 internal extern static bool GetFontMetrics(IntPtr graphicsObject, IntPtr nativeObject, out int ascent, out int descent);