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;
103 static readonly object lockobj = new object ();
106 internal override event EventHandler Idle;
111 private XplatUIOSX() {
114 TimerList = new ArrayList ();
115 MessageQueue = new Queue ();
121 // FIXME: Clean up the FosterParent here.
126 #region Singleton specific code
128 public static XplatUIOSX GetInstance() {
130 if (Instance == null) {
131 Instance = new XplatUIOSX ();
138 public int Reference {
146 #region Internal methods
148 internal void Initialize () {
150 // Initialize the Event Handler delegate
151 CarbonEventHandler = new CarbonEventDelegate (EventCallback);
153 // Initilize the mouse controls
154 Hover.Interval = 500;
155 Hover.Timer = new Timer ();
156 Hover.Timer.Enabled = false;
157 Hover.Timer.Interval = Hover.Interval;
158 Hover.Timer.Tick += new EventHandler (HoverCallback);
161 MouseState = MouseButtons.None;
162 MousePosition = Point.Empty;
164 // Initialize the Caret
165 Caret.Timer = new Timer ();
166 Caret.Timer.Interval = 500;
167 Caret.Timer.Tick += new EventHandler (CaretCallback);
169 // Initialize the OSX Specific stuff
170 WindowMapping = new Hashtable ();
171 WindowBackgrounds = new Hashtable ();
173 // Initialize the FosterParent
174 IntPtr rect = IntPtr.Zero;
175 SetRect (ref rect, (short)0, (short)0, (short)0, (short)0);
176 CheckError (CreateNewWindow (WindowClass.kDocumentWindowClass, WindowAttributes.kWindowStandardHandlerAttribute | WindowAttributes.kWindowCloseBoxAttribute | WindowAttributes.kWindowFullZoomAttribute | WindowAttributes.kWindowCollapseBoxAttribute | WindowAttributes.kWindowResizableAttribute | WindowAttributes.kWindowCompositingAttribute, ref rect, ref FosterParent), "CreateFosterParent ()");
178 // Get some values about bar heights
179 Rect structRect = new Rect ();
180 Rect contentRect = new Rect ();
181 CheckError (GetWindowBounds (FosterParent, 32, ref structRect), "GetWindowBounds ()");
182 CheckError (GetWindowBounds (FosterParent, 33, ref contentRect), "GetWindowBounds ()");
184 TitleBarHeight = Math.Abs(structRect.top - contentRect.top);
185 MenuBarHeight = GetMBarHeight ();
188 FocusWindow = IntPtr.Zero;
191 GetMessageResult = true;
196 #region Private methods
201 private void CaretCallback (object sender, EventArgs e) {
213 private void HoverCallback (object sender, EventArgs e) {
214 if ((Hover.X == MousePosition.X) && (Hover.Y == MousePosition.Y)) {
215 MSG msg = new MSG ();
216 msg.hwnd = Hover.Hwnd;
217 msg.message = Msg.WM_MOUSEHOVER;
218 msg.wParam = GetMousewParam (0);
219 msg.lParam = (IntPtr)((ushort)Hover.X << 16 | (ushort)Hover.X);
220 MessageQueue.Enqueue (msg);
224 internal int EventCallback (IntPtr inCallRef, IntPtr inEvent, IntPtr handle) {
225 uint eventClass = GetEventClass (inEvent);
226 uint eventKind = GetEventKind (inEvent);
228 lock (MessageQueue) {
229 switch (eventClass) {
231 case OSXConstants.kEventClassKeyboard: {
232 retVal = ProcessKeyboardEvent (inEvent, eventKind, handle);
236 case OSXConstants.kEventClassWindow: {
237 retVal = ProcessWindowEvent (inEvent, eventKind, handle);
241 case OSXConstants.kEventClassMouse: {
242 retVal = ProcessMouseEvent (inEvent, eventKind, handle);
246 case OSXConstants.kEventClassControl: {
247 retVal = ProcessControlEvent (inEvent, eventKind, handle);
251 Console.WriteLine ("WARNING: Unhandled eventClass {0}", eventClass);
262 #region Private Methods
264 // This sucks write a real driver
265 private int ProcessKeyboardEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
266 MSG msg = new MSG ();
267 byte charCode = 0x00;
268 GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamKeyMacCharCodes, OSXConstants.EventParamType.typeChar, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (byte)), IntPtr.Zero, ref charCode);
269 IntPtr cntrl = IntPtr.Zero;
270 CheckError (GetKeyboardFocus (handle, ref cntrl), "GetKeyboardFocus()");
272 msg.lParam = IntPtr.Zero;
287 msg.wParam = (IntPtr)charCode;
290 case OSXConstants.kEventRawKeyDown: {
291 msg.message = Msg.WM_KEYDOWN;
295 case OSXConstants.kEventRawKeyRepeat: {
296 msg.message = Msg.WM_KEYDOWN;
300 case OSXConstants.kEventRawKeyUp: {
301 msg.message = Msg.WM_KEYUP;
305 MessageQueue.Enqueue (msg);
309 private int ProcessWindowEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
310 MSG msg = new MSG ();
312 // Someone closed a window
313 case OSXConstants.kEventWindowClose: {
314 // This is our real window; so we have to post to the corresponding view
315 // FIXME: Should we doublehash the table to get the real window handle without this loop?
316 IDictionaryEnumerator e = WindowMapping.GetEnumerator ();
317 while (e.MoveNext ()) {
318 if ((IntPtr)e.Value == handle) {
319 NativeWindow.WndProc((IntPtr)e.Key, Msg.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
324 case OSXConstants.kEventWindowBoundsChanged: {
325 // This is our real window; so we have to resize the corresponding view as well
326 // FIXME: Should we doublehash the table to get the real window handle without this loop?
328 IDictionaryEnumerator e = WindowMapping.GetEnumerator ();
329 while (e.MoveNext ()) {
330 if ((IntPtr)e.Value == handle) {
331 Hwnd hwnd = Hwnd.ObjectFromHandle ((IntPtr) e.Key);
332 // Get the bounds of the window
333 Rect bounds = new Rect ();
334 CheckError (GetWindowBounds (handle, 33, ref bounds), "GetWindowBounds ()");
335 HIRect r = new HIRect ();
337 // Get our frame for the Handle
338 CheckError (HIViewGetFrame (hwnd.Handle, ref r), "HIViewGetFrame ()");
339 r.size.width = bounds.right-bounds.left;
340 r.size.height = bounds.bottom-bounds.top;
341 // Set the view to the new size
342 CheckError (HIViewSetFrame (hwnd.WholeWindow, ref r), "HIViewSetFrame ()");
344 // Update the hwnd internal size representation
345 hwnd.x = (int)r.origin.x;
346 hwnd.y = (int)r.origin.y;
347 hwnd.width = (int)r.size.width;
348 hwnd.height = (int)r.size.height;
349 Rectangle client_rect = hwnd.ClientRect;
351 r.size.width = client_rect.Width;
352 r.size.height = client_rect.Height;
353 r.origin.x = client_rect.X;
354 r.origin.y = client_rect.Y;
356 // Update the client area too
357 CheckError (HIViewSetFrame (hwnd.ClientWindow, ref r));
359 // Add the message to the queue
360 msg.message = Msg.WM_WINDOWPOSCHANGED;
361 msg.hwnd = hwnd.Handle;
362 msg.wParam = IntPtr.Zero;
363 msg.lParam = IntPtr.Zero;
364 MessageQueue.Enqueue (msg);
375 private int ProcessMouseEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
376 MSG msg = new MSG ();
379 case OSXConstants.kEventMouseMoved: {
380 // Where is the mouse in global coordinates
381 QDPoint pt = new QDPoint ();
382 GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamMouseLocation, OSXConstants.EventParamType.typeQDPoint, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref pt);
384 // Where is the mouse in the window
385 Rect window_bounds = new Rect ();
386 GetWindowBounds (handle, 33, ref window_bounds);
387 CGPoint window_pt = new CGPoint ((short) (pt.x - window_bounds.left), (short) (pt.y - window_bounds.top));
389 IntPtr window_handle = IntPtr.Zero;
390 HIViewFindByID (HIViewGetRoot (handle), new HIViewID (OSXConstants.kEventClassWindow, 1), ref window_handle);
392 // Determine which control was hit
393 IntPtr view_handle = IntPtr.Zero;
394 HIViewGetSubviewHit (window_handle, ref window_pt, true, ref view_handle);
396 // Convert the point to view local coordinates
397 HIViewConvertPoint (ref window_pt, window_handle, view_handle);
399 Hwnd hwnd = Hwnd.ObjectFromHandle (view_handle);
404 // Generate the message
405 msg.hwnd = hwnd.Handle;
406 msg.message = Msg.WM_MOUSEMOVE;
407 msg.lParam = (IntPtr) ((ushort)window_pt.y << 16 | (ushort)window_pt.x);
408 msg.wParam = GetMousewParam (0);
409 MousePosition.X = (int)window_pt.x;
410 MousePosition.Y = (int)window_pt.y;
412 Hover.Hwnd = msg.hwnd;
413 Hover.Timer.Enabled = true;
414 MessageQueue.Enqueue (msg);
421 private int ProcessControlEvent (IntPtr inEvent, uint eventKind, IntPtr handle) {
422 GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamDirectObject, OSXConstants.EventParamType.typeControlRef, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref handle);
423 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
424 MSG msg = new MSG ();
427 case OSXConstants.kEventControlDraw: {
429 if(!hwnd.visible || !HIViewIsVisible (handle))
433 IntPtr rgnhandle = IntPtr.Zero;
434 GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamRgnHandle, OSXConstants.EventParamType.typeQDRgnHandle, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref rgnhandle);
435 IntPtr duprgn = NewRgn ();
436 CopyRgn (rgnhandle, duprgn);
437 ClipRegions [hwnd.Handle] = duprgn;
440 // Get the dirty area
441 HIRect bounds = new HIRect ();
442 HIViewGetBounds (handle, ref bounds);
444 bool client = (hwnd.ClientWindow == handle ? true : false);
446 if (!client && bounds.origin.x >= hwnd.ClientRect.X && bounds.origin.y >= hwnd.ClientRect.Y) {
447 // This is a paint on WholeWindow inside the clientRect; we can safely discard this
451 hwnd.AddInvalidArea ((int)bounds.origin.x, (int)bounds.origin.y, (int)bounds.size.width, (int)bounds.size.height);
452 if (WindowBackgrounds [hwnd] != null) {
453 Color c = (Color)WindowBackgrounds [hwnd];
454 IntPtr contextref = IntPtr.Zero;
455 GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamCGContextRef, OSXConstants.EventParamType.typeCGContextRef, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (IntPtr)), IntPtr.Zero, ref contextref);
456 CGContextSetRGBFillColor (contextref, (float)c.R/255, (float)c.G/255, (float)c.B/255, (float)c.A/255);
457 CGContextFillRect (contextref, bounds);
460 // Add a paint to the queue
461 msg.hwnd = hwnd.Handle;
462 msg.message = Msg.WM_PAINT;
463 msg.wParam = IntPtr.Zero;
464 msg.lParam = IntPtr.Zero;
465 MessageQueue.Enqueue (msg);
469 case OSXConstants.kEventControlBoundsChanged: {
470 // This can happen before our HWND is created so we need to check to make sure its not null
473 HIRect bounds = new HIRect ();
474 HIViewGetFrame (handle, ref bounds);
475 // Update the hwnd size
476 hwnd.x = (int)bounds.origin.x;
477 hwnd.y = (int)bounds.origin.y;
478 hwnd.width = (int)bounds.size.width;
479 hwnd.height = (int)bounds.size.height;
481 // TODO: Do we need to send a paint here or does BoundsChanged make a ControlDraw for the exposed area?
485 case OSXConstants.kEventControlTrack: {
486 // get the point that was hit
487 QDPoint point = new QDPoint ();
488 CheckError (GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamMouseLocation, OSXConstants.EventParamType.typeQDPoint, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref point), "GetEventParameter() MouseLocation");
489 MouseTrackingResult mousestatus = MouseTrackingResult.kMouseTrackingMouseDown;
490 IntPtr modifiers = IntPtr.Zero;
492 while (mousestatus != MouseTrackingResult.kMouseTrackingMouseUp) {
493 CheckTimers (DateTime.Now);
494 if (mousestatus == MouseTrackingResult.kMouseTrackingMouseDragged) {
495 QDPoint realpoint = point;
498 ScreenToClient (hwnd.Handle, ref x, ref y);
499 realpoint.x = (short)x;
500 realpoint.y = (short)y;
501 NativeWindow.WndProc (hwnd.Handle, Msg.WM_MOUSEMOVE, GetMousewParam (0), (IntPtr) ((ushort)realpoint.y << 16 | (ushort)realpoint.x));
503 // Process the rest of the event queue
504 while (MessageQueue.Count > 0) {
505 msg = (MSG)MessageQueue.Dequeue ();
506 NativeWindow.WndProc (msg.hwnd, msg.message, msg.wParam, msg.lParam);
508 TrackMouseLocationWithOptions ((IntPtr)(-1), 0, 0.01, ref point, ref modifiers, ref mousestatus);
511 msg.hwnd = hwnd.Handle;
513 bool client = (hwnd.ClientWindow == handle ? true : false);
515 int wparam = (int)GetMousewParam (0);
516 switch (MouseState) {
517 case MouseButtons.Left:
518 MouseState &= ~MouseButtons.Left;
519 msg.message = (client ? Msg.WM_LBUTTONUP : Msg.WM_NCLBUTTONUP);
520 wparam &= (int)MsgButtons.MK_LBUTTON;
522 case MouseButtons.Middle:
523 MouseState &= ~MouseButtons.Middle;
524 msg.message = (client ? Msg.WM_MBUTTONUP : Msg.WM_NCMBUTTONUP);
525 wparam &= (int)MsgButtons.MK_MBUTTON;
527 case MouseButtons.Right:
528 MouseState &= ~MouseButtons.Right;
529 msg.message = (client ? Msg.WM_RBUTTONUP : Msg.WM_NCRBUTTONUP);
530 wparam &= (int)MsgButtons.MK_RBUTTON;
535 ScreenToClient (hwnd.Handle, ref x2, ref y2);
539 msg.wParam = (IntPtr)wparam;
541 msg.lParam = (IntPtr) ((ushort)point.y << 16 | (ushort)point.x);
542 MousePosition.X = (int)point.x;
543 MousePosition.Y = (int)point.y;
544 //NativeWindow.WndProc (msg.hwnd, msg.message, msg.lParam, msg.wParam);
545 MessageQueue.Enqueue (msg);
547 IntPtr window = GetControlOwner (hwnd.Handle);
548 SetKeyboardFocus (window, hwnd.Handle, 1);
552 case OSXConstants.kEventControlContextualMenuClick:
553 case OSXConstants.kEventControlClick: {
554 // get the point that was hit
555 QDPoint point = new QDPoint ();
556 CheckError (GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamMouseLocation, OSXConstants.EventParamType.typeQDPoint, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref point), "GetEventParameter() MouseLocation");
557 QDPoint trackpoint = point;
560 ScreenToClient (hwnd.Handle, ref x, ref y);
564 // which button was pressed?
566 GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamMouseButton, OSXConstants.EventParamType.typeMouseButton, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (ushort)), IntPtr.Zero, ref button);
568 point.x = (short)MousePosition.X;
569 point.y = (short)MousePosition.Y;
572 msg.hwnd = hwnd.Handle;
574 bool client = (hwnd.ClientWindow == handle ? true : false);
576 int wparam = (int)GetMousewParam (0);
579 MouseState |= MouseButtons.Left;
580 msg.message = (client ? Msg.WM_LBUTTONDOWN : Msg.WM_NCLBUTTONDOWN);
581 wparam |= (int)MsgButtons.MK_LBUTTON;
584 MouseState |= MouseButtons.Right;
585 msg.message = (client ? Msg.WM_RBUTTONDOWN : Msg.WM_NCRBUTTONDOWN);
586 wparam |= (int)MsgButtons.MK_RBUTTON;
589 MouseState |= MouseButtons.Middle;
590 msg.message = (client ? Msg.WM_MBUTTONDOWN : Msg.WM_NCMBUTTONDOWN);
591 wparam |= (int)MsgButtons.MK_MBUTTON;
594 msg.wParam = (IntPtr)wparam;
596 msg.lParam = (IntPtr) ((ushort)point.y << 16 | (ushort)point.x);
597 MousePosition.X = (int)point.x;
598 MousePosition.Y = (int)point.y;
599 NativeWindow.WndProc (msg.hwnd, msg.message, msg.wParam, msg.lParam);
601 TrackControl (handle, trackpoint, IntPtr.Zero);
604 case OSXConstants.kEventControlSetFocusPart: {
605 // This handles setting focus
607 GetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamControlPart, OSXConstants.EventParamType.typeControlPartCode, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (short)), IntPtr.Zero, ref pcode);
615 SetEventParameter (inEvent, OSXConstants.EventParamName.kEventParamControlPart, OSXConstants.EventParamType.typeControlPartCode, (uint)Marshal.SizeOf (typeof (short)), ref pcode);
621 private IntPtr GetMousewParam(int Delta) {
624 if ((MouseState & MouseButtons.Left) != 0) {
625 result |= (int)MsgButtons.MK_LBUTTON;
628 if ((MouseState & MouseButtons.Middle) != 0) {
629 result |= (int)MsgButtons.MK_MBUTTON;
632 if ((MouseState & MouseButtons.Right) != 0) {
633 result |= (int)MsgButtons.MK_RBUTTON;
636 return (IntPtr)result;
639 private double NextTimeout ()
641 DateTime now = DateTime.Now;
642 int timeout = 0x7FFFFFF;
644 foreach (Timer timer in TimerList) {
645 int next = (int) (timer.Expires - now).TotalMilliseconds;
652 if (timeout < Timer.Minimum)
653 timeout = Timer.Minimum;
655 return (double)((double)timeout/1000);
658 private void CheckTimers (DateTime now)
661 int count = TimerList.Count;
664 for (int i = 0; i < TimerList.Count; i++) {
665 Timer timer = (Timer) TimerList [i];
666 if (timer.Enabled && timer.Expires <= now) {
674 internal void InvertCaret () {
675 IntPtr window = GetControlOwner (Caret.Hwnd);
676 SetPortWindowPort (window);
677 Rect r = new Rect ();
678 GetWindowPortBounds (window, ref r);
679 r.top += (short)Caret.Y;
680 r.left += (short)Caret.X;
681 r.bottom = (short)(r.top + Caret.Height);
682 r.right = (short)(r.left + Caret.Width);
686 private void SetHwndStyles(Hwnd hwnd, CreateParams cp) {
687 throw new NotImplementedException();
690 internal void ShowCaret () {
697 internal void HideCaret () {
704 internal void InstallTracking (Hwnd hwnd) {
705 // This is currently not used
708 if (hwnd.client_region_ptr != IntPtr.Zero) {
709 ReleaseMouseTrackingRegion (hwnd.client_region_ptr);
710 hwnd.client_region_ptr = IntPtr.Zero;
712 if (hwnd.whole_region_ptr != IntPtr.Zero) {
713 ReleaseMouseTrackingRegion (hwnd.whole_region_ptr);
714 hwnd.whole_region_ptr = IntPtr.Zero;
716 // Setup the new track region
718 HIRect client_bounds = new HIRect ();
719 HIViewGetBounds (hwnd.client_window, ref client_bounds);
720 HIViewConvertRect (ref client_bounds, hwnd.client_window, IntPtr.Zero);
722 IntPtr rgn = NewRgn ();
723 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));
724 CreateMouseTrackingRegion (GetControlOwner (hwnd.client_window), rgn, IntPtr.Zero, 0, hwnd.client_region_id, hwnd.client_window, IntPtr.Zero, ref hwnd.client_region_ptr);
725 Console.WriteLine (hwnd.ClientRect);
726 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));
727 if (hwnd.ClientRect.X > 0 && hwnd.ClientRect.Y > 0) {
728 HIRect window_bounds = new HIRect ();
729 HIViewGetBounds (hwnd.whole_window, ref window_bounds);
730 HIViewConvertRect (ref window_bounds, hwnd.whole_window, IntPtr.Zero);
732 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));
733 CreateMouseTrackingRegion (GetControlOwner (hwnd.whole_window), rgn, IntPtr.Zero, 0, hwnd.whole_region_id, hwnd.whole_window, IntPtr.Zero, ref hwnd.whole_region_ptr);
734 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));
740 internal void CheckError (int result, string error) {
742 throw new Exception ("XplatUIOSX.cs::" + error + "() Carbon subsystem threw an error: " + result);
745 internal void CheckError (int result) {
747 throw new Exception ("XplatUIOSX.cs::Carbon subsystem threw an error: " + result);
752 #region Public Methods
754 internal override IntPtr InitializeDriver() {
758 internal override void ShutdownDriver(IntPtr token) {
761 internal override void EnableThemes() {
762 ThemesEnabled = true;
765 internal override void Activate(IntPtr handle) {
766 ActivateWindow (GetControlOwner (handle), true);
769 internal override void CaretVisible (IntPtr hwnd, bool visible) {
770 if (Caret.Hwnd == hwnd) {
772 if (Caret.Visible < 1) {
775 if (Caret.Visible == 1) {
777 Caret.Timer.Start ();
782 if (Caret.Visible == 0) {
790 internal override bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, int ExStyle, IntPtr MenuHandle, out Rectangle WindowRect) {
791 FormBorderStyle border_style;
792 TitleStyle title_style;
794 title_style = TitleStyle.None;
795 if ((Style & (int)WindowStyles.WS_CAPTION) != 0) {
796 if ((ExStyle & (int)WindowStyles.WS_EX_TOOLWINDOW) != 0) {
797 title_style = TitleStyle.Tool;
799 title_style = TitleStyle.Normal;
803 border_style = FormBorderStyle.None;
804 if ((ExStyle & (int)WindowStyles.WS_EX_WINDOWEDGE) != 0) {
805 if ((ExStyle & (int)WindowStyles.WS_EX_TOOLWINDOW) != 0) {
806 if ((Style & (int)WindowStyles.WS_THICKFRAME) != 0) {
807 border_style = FormBorderStyle.SizableToolWindow;
809 border_style = FormBorderStyle.FixedToolWindow;
811 } else if ((ExStyle & (int)WindowStyles.WS_EX_DLGMODALFRAME) != 0) {
812 border_style = FormBorderStyle.FixedDialog;
813 } else if ((ExStyle & (int)WindowStyles.WS_THICKFRAME) != 0) {
814 border_style = FormBorderStyle.Sizable;
816 border_style = FormBorderStyle.FixedSingle;
819 border_style = FormBorderStyle.Fixed3D;
822 WindowRect = Hwnd.GetWindowRectangle(border_style, MenuHandle, title_style, ClientRect);
827 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
828 CGPoint pt = new CGPoint ();
829 Rect wBounds = new Rect ();
832 hwnd = Hwnd.ObjectFromHandle(handle);
837 GetWindowBounds (GetControlOwner (hwnd.client_window), 32, ref wBounds);
838 HIViewConvertPoint (ref pt, handle, IntPtr.Zero);
840 x = (int)(pt.x+wBounds.left);
841 y = (int)(pt.y+wBounds.top);
844 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
848 internal override void ClipboardClose(IntPtr handle) {
849 throw new NotImplementedException();
852 internal override int ClipboardGetID(IntPtr handle, string format) {
856 internal override IntPtr ClipboardOpen() {
857 throw new NotImplementedException();
860 internal override object ClipboardRetrieve(IntPtr handle, int id, XplatUI.ClipboardToObject converter) {
861 throw new NotImplementedException();
864 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
865 throw new NotImplementedException();
868 internal override void CreateCaret (IntPtr hwnd, int width, int height) {
869 if (Caret.Hwnd != IntPtr.Zero)
870 DestroyCaret (Caret.Hwnd);
874 Caret.Height = height;
879 internal override IntPtr CreateWindow(CreateParams cp) {
880 IntPtr windowHnd = IntPtr.Zero;
881 IntPtr parentHnd = cp.Parent;
882 bool realWindow = false;
883 Rectangle clientRect;
884 Hwnd hwnd = new Hwnd ();
886 SetHwndStyles (hwnd, cp);
888 if (parentHnd == IntPtr.Zero) {
889 if ((cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
890 // This is a child view that is going to be parentless;
892 CheckError (HIViewFindByID (HIViewGetRoot (FosterParent), new HIViewID (OSXConstants.kEventClassWindow, 1), ref parentHnd), "HIViewFindByID ()");
893 } else if ((cp.Style & (int)(WindowStyles.WS_POPUP))!=0) {
894 // This is a popup window that will be real.
895 if (cp.X < 1) cp.X = 0;
896 if (cp.Y < 1) cp.Y = 0;
899 // This is a real root window too
900 if (cp.X < 1) cp.X = 0;
901 if (cp.Y < 1) cp.Y = 0;
909 WindowClass windowklass = WindowClass.kOverlayWindowClass;
910 WindowAttributes attributes = WindowAttributes.kWindowCompositingAttribute | WindowAttributes.kWindowStandardHandlerAttribute;
911 if ((cp.Style & ((int)WindowStyles.WS_MINIMIZEBOX)) != 0) {
912 attributes |= WindowAttributes.kWindowCollapseBoxAttribute;
914 if ((cp.Style & ((int)WindowStyles.WS_MAXIMIZEBOX)) != 0) {
915 attributes |= WindowAttributes.kWindowResizableAttribute | WindowAttributes.kWindowHorizontalZoomAttribute | WindowAttributes.kWindowVerticalZoomAttribute;
917 if ((cp.Style & ((int)WindowStyles.WS_SYSMENU)) != 0) {
918 attributes |= WindowAttributes.kWindowCloseBoxAttribute;
920 if ((cp.ExStyle & ((int)WindowStyles.WS_EX_TOOLWINDOW)) != 0) {
921 attributes = WindowAttributes.kWindowStandardHandlerAttribute | WindowAttributes.kWindowCompositingAttribute;
923 if ((cp.Style & ((int)WindowStyles.WS_CAPTION)) != 0) {
924 windowklass = WindowClass.kDocumentWindowClass;
927 IntPtr rect = IntPtr.Zero;
928 IntPtr viewHnd = IntPtr.Zero;
929 SetRect (ref rect, (short)cp.X, (short)(cp.Y + MenuBarHeight + TitleBarHeight), (short)(cp.Width+cp.X), (short)(cp.Height+cp.Y+MenuBarHeight+TitleBarHeight));
930 CheckError (CreateNewWindow (windowklass, attributes, ref rect, ref windowHnd), "CreateNewWindow ()");
932 CheckError (InstallEventHandler (GetWindowEventTarget (windowHnd), CarbonEventHandler, (uint)windowEvents.Length, windowEvents, windowHnd, IntPtr.Zero), "InstallEventHandler ()");
933 CheckError (HIViewFindByID (HIViewGetRoot (windowHnd), new HIViewID (OSXConstants.kEventClassWindow, 1), ref viewHnd), "HIViewFindByID ()");
938 hwnd.Width = cp.Width;
939 hwnd.Height = cp.Height;
940 hwnd.Parent = Hwnd.ObjectFromHandle (cp.Parent);
941 hwnd.visible = false;
942 clientRect = hwnd.ClientRect;
944 HIRect r = new HIRect (0, 0, cp.Width, cp.Height);
945 CheckError (HIObjectCreate (__CFStringMakeConstantString ("com.apple.hiview"), 0, ref hwnd.whole_window), "HIObjectCreate ()");
946 CheckError (InstallEventHandler (GetControlEventTarget (hwnd.whole_window), CarbonEventHandler, (uint)viewEvents.Length, viewEvents, hwnd.whole_window, IntPtr.Zero), "InstallEventHandler ()");
947 CheckError (HIViewChangeFeatures (hwnd.whole_window, 1 << 1, 0), "HIViewChangeFeatures ()");
948 CheckError (HIViewSetFrame (hwnd.whole_window, ref r), "HIViewSetFrame ()");
949 hwnd.WholeWindow = hwnd.whole_window;
951 r = new HIRect (0, 0, clientRect.Width, clientRect.Height);
952 CheckError (HIObjectCreate (__CFStringMakeConstantString ("com.apple.hiview"), 0, ref hwnd.client_window), "HIObjectCreate ()");
953 CheckError (InstallEventHandler (GetControlEventTarget (hwnd.client_window), CarbonEventHandler, (uint)viewEvents.Length, viewEvents, hwnd.client_window, IntPtr.Zero), "InstallEventHandler ()");
954 CheckError (HIViewChangeFeatures (hwnd.client_window, 1 << 1, 0), "HIViewChangeFeatures ()");
955 CheckError (HIViewSetFrame (hwnd.client_window, ref r), "HIViewSetFrame ()");
956 hwnd.ClientWindow = hwnd.client_window;
958 CheckError (HIViewAddSubview (hwnd.whole_window, hwnd.client_window));
959 CheckError (HIViewPlaceInSuperviewAt (hwnd.client_window, clientRect.X, clientRect.Y));
961 if (parentHnd != IntPtr.Zero && parentHnd != hwnd.WholeWindow) {
962 CheckError (HIViewAddSubview (parentHnd, hwnd.whole_window), "HIViewAddSubview ()");
963 CheckError (HIViewPlaceInSuperviewAt (hwnd.whole_window, cp.X, cp.Y), "HIPlaceInSuperviewAt ()");
964 if ((cp.Style & (int)(WindowStyles.WS_VISIBLE))!=0) {
965 CheckError (HIViewSetVisible (hwnd.whole_window, true), "HIViewSetVisible ()");
966 CheckError (HIViewSetVisible (hwnd.client_window, true), "HIViewSetVisible ()");
969 CheckError (HIViewSetVisible (hwnd.whole_window, false), "HIViewSetVisible ()");
970 CheckError (HIViewSetVisible (hwnd.client_window, false), "HIViewSetVisible ()");
971 hwnd.visible = false;
975 WindowMapping [hwnd.Handle] = windowHnd;
976 if ((cp.Style & (int)(WindowStyles.WS_VISIBLE))!=0) {
977 CheckError (ShowWindow (windowHnd));
978 CheckError (HIViewSetVisible (hwnd.whole_window, true), "HIViewSetVisible ()");
979 CheckError (HIViewSetVisible (hwnd.client_window, true), "HIViewSetVisible ()");
982 if ((cp.Style & (int)(WindowStyles.WS_POPUP))!=0) {
983 CheckError (HIViewSetVisible (hwnd.whole_window, true), "HIViewSetVisible ()");
984 CheckError (HIViewSetVisible (hwnd.client_window, true), "HIViewSetVisible ()");
992 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
993 CreateParams create_params = new CreateParams();
995 create_params.Caption = "";
998 create_params.Width = Width;
999 create_params.Height = Height;
1001 create_params.ClassName=XplatUI.DefaultClassName;
1002 create_params.ClassStyle = 0;
1003 create_params.ExStyle=0;
1004 create_params.Parent=IntPtr.Zero;
1005 create_params.Param=0;
1007 return CreateWindow(create_params);
1011 internal override IntPtr DefineCursor(Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
1012 throw new NotImplementedException ();
1016 internal override IntPtr DefineStdCursor(StdCursor id) {
1018 case StdCursor.AppStarting:
1019 return (IntPtr)ThemeCursor.kThemeSpinningCursor;
1020 case StdCursor.Arrow:
1021 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1022 case StdCursor.Cross:
1023 return (IntPtr)ThemeCursor.kThemeCrossCursor;
1024 case StdCursor.Default:
1025 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1026 case StdCursor.Hand:
1027 return (IntPtr)ThemeCursor.kThemeOpenHandCursor;
1028 case StdCursor.Help:
1029 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1030 case StdCursor.HSplit:
1031 return (IntPtr)ThemeCursor.kThemeResizeLeftRightCursor;
1032 case StdCursor.IBeam:
1033 return (IntPtr)ThemeCursor.kThemeIBeamCursor;
1035 return (IntPtr)ThemeCursor.kThemeNotAllowedCursor;
1036 case StdCursor.NoMove2D:
1037 return (IntPtr)ThemeCursor.kThemeNotAllowedCursor;
1038 case StdCursor.NoMoveHoriz:
1039 return (IntPtr)ThemeCursor.kThemeNotAllowedCursor;
1040 case StdCursor.NoMoveVert:
1041 return (IntPtr)ThemeCursor.kThemeNotAllowedCursor;
1042 case StdCursor.PanEast:
1043 return (IntPtr)ThemeCursor.kThemeResizeRightCursor;
1044 case StdCursor.PanNE:
1045 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1046 case StdCursor.PanNorth:
1047 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1048 case StdCursor.PanNW:
1049 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1050 case StdCursor.PanSE:
1051 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1052 case StdCursor.PanSouth:
1053 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1054 case StdCursor.PanSW:
1055 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1056 case StdCursor.PanWest:
1057 return (IntPtr)ThemeCursor.kThemeResizeLeftCursor;
1058 case StdCursor.SizeAll:
1059 return (IntPtr)ThemeCursor.kThemeResizeLeftRightCursor;
1060 case StdCursor.SizeNESW:
1061 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1062 case StdCursor.SizeNS:
1063 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1064 case StdCursor.SizeNWSE:
1065 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1066 case StdCursor.SizeWE:
1067 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1068 case StdCursor.UpArrow:
1069 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1070 case StdCursor.VSplit:
1071 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1072 case StdCursor.WaitCursor:
1073 return (IntPtr)ThemeCursor.kThemeSpinningCursor;
1075 return (IntPtr)ThemeCursor.kThemeArrowCursor;
1079 internal override IntPtr DefWndProc(ref Message msg) {
1080 Hwnd hwnd = Hwnd.ObjectFromHandle (msg.HWnd);
1081 switch ((Msg)msg.Msg) {
1082 case Msg.WM_DESTROY: {
1083 if (WindowMapping [hwnd.Handle] != null)
1092 internal override void DestroyCaret (IntPtr hwnd) {
1093 if (Caret.Hwnd == hwnd) {
1094 if (Caret.Visible == 1) {
1095 Caret.Timer.Stop ();
1098 Caret.Hwnd = IntPtr.Zero;
1105 internal override void DestroyCursor(IntPtr cursor) {
1106 throw new NotImplementedException ();
1109 internal override void DestroyWindow(IntPtr handle) {
1112 hwnd = Hwnd.ObjectFromHandle(handle);
1114 if ((hwnd.whole_window != IntPtr.Zero) && HIViewGetSuperview (hwnd.whole_window) != IntPtr.Zero)
1115 CheckError (HIViewRemoveFromSuperview (handle), "HIViewRemoveFromSuperview ()");
1117 if (WindowMapping [hwnd.Handle] != null) {
1118 DisposeWindow ((IntPtr)(WindowMapping [hwnd.Handle]));
1120 CFRelease (hwnd.ClientWindow);
1121 CFRelease (hwnd.WholeWindow);
1124 internal override IntPtr DispatchMessage(ref MSG msg) {
1125 return NativeWindow.WndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
1128 internal override void DoEvents() {
1131 internal override void EnableWindow(IntPtr handle, bool Enable) {
1132 //Like X11 we need not do anything here
1135 internal override void Exit() {
1136 GetMessageResult = false;
1140 internal override IntPtr GetActive() {
1141 foreach (DictionaryEntry entry in WindowMapping)
1142 if (IsWindowActive ((IntPtr)(entry.Value)))
1143 return (IntPtr)(entry.Key);
1149 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1150 throw new NotImplementedException ();
1153 internal override void GetDisplaySize(out Size size) {
1154 HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1155 size = new Size ((int)bounds.size.width, (int)bounds.size.height);
1158 internal override IntPtr GetParent(IntPtr handle) {
1161 hwnd = Hwnd.ObjectFromHandle(handle);
1162 if (hwnd != null && hwnd.parent != null) {
1163 return hwnd.parent.Handle;
1168 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1169 QDPoint pt = new QDPoint ();
1170 GetGlobalMouse (ref pt);
1175 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1176 return GetFontMetrics(g.GetHdc(), font.ToHfont(), out ascent, out descent);
1180 internal override Graphics GetMenuDC(IntPtr hwnd, IntPtr ncpaint_region) {
1181 throw new NotImplementedException();
1185 internal override Point GetMenuOrigin(IntPtr hwnd) {
1186 throw new NotImplementedException();
1189 internal override bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1190 IntPtr evtRef = IntPtr.Zero;
1191 IntPtr target = GetEventDispatcherTarget();
1192 CheckTimers (DateTime.Now);
1193 ReceiveNextEvent (0, IntPtr.Zero, 0, true, ref evtRef);
1194 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1195 SendEventToEventTarget (evtRef, target);
1196 ReleaseEvent (evtRef);
1199 lock (MessageQueue) {
1200 if (MessageQueue.Count <= 0) {
1202 Idle (this, EventArgs.Empty);
1203 else if (TimerList.Count == 0) {
1204 ReceiveNextEvent (0, IntPtr.Zero, Convert.ToDouble ("0." + Timer.Minimum), true, ref evtRef);
1205 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1206 SendEventToEventTarget (evtRef, target);
1207 ReleaseEvent (evtRef);
1210 ReceiveNextEvent (0, IntPtr.Zero, NextTimeout (), true, ref evtRef);
1211 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1212 SendEventToEventTarget (evtRef, target);
1213 ReleaseEvent (evtRef);
1216 msg.hwnd = IntPtr.Zero;
1217 msg.message = Msg.WM_ENTERIDLE;
1218 return GetMessageResult;
1220 msg = (MSG) MessageQueue.Dequeue ();
1222 return GetMessageResult;
1226 internal override bool GetText(IntPtr handle, out string text) {
1227 throw new NotImplementedException ();
1230 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) {
1231 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1232 Rectangle rect = hwnd.ClientRect;
1237 height = hwnd.height;
1239 client_width = rect.Width;
1240 client_height = rect.Height;
1243 internal override FormWindowState GetWindowState(IntPtr hwnd) {
1244 IntPtr window = GetControlOwner (hwnd);
1246 if (IsWindowCollapsed (window))
1247 return FormWindowState.Minimized;
1248 if (IsWindowInStandardState (window, IntPtr.Zero, IntPtr.Zero))
1249 return FormWindowState.Maximized;
1251 return FormWindowState.Normal;
1254 internal override void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
1256 GrabConfined = Grab.Confined;
1257 GrabArea = Grab.Area;
1260 internal override void GrabWindow(IntPtr handle, IntPtr confine_to_handle) {
1261 GrabWindowHwnd = Hwnd.ObjectFromHandle (handle);
1264 internal override void UngrabWindow(IntPtr hwnd) {
1265 GrabWindowHwnd = null;
1266 Grab.Hwnd = IntPtr.Zero;
1267 Grab.Confined = false;
1270 internal override void HandleException(Exception e) {
1271 StackTrace st = new StackTrace(e);
1272 Console.WriteLine("Exception '{0}'", e.Message+st.ToString());
1273 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1276 internal override void Invalidate (IntPtr handle, Rectangle rc, bool clear) {
1277 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1279 if (hwnd.visible && HIViewIsVisible (handle)) {
1280 MSG msg = new MSG ();
1281 msg.hwnd = hwnd.Handle;
1282 msg.wParam = IntPtr.Zero;
1283 msg.lParam = IntPtr.Zero;
1284 msg.message = Msg.WM_PAINT;
1285 MessageQueue.Enqueue (msg);
1286 // This is currently causing some graphics corruption
1287 //hwnd.AddInvalidArea (rc.X, rc.Y, rc.Width, rc.Height);
1288 hwnd.AddInvalidArea (0, 0, hwnd.ClientRect.Width, hwnd.ClientRect.Height);
1289 hwnd.expose_pending = true;
1293 internal override bool IsVisible(IntPtr handle) {
1294 return Hwnd.ObjectFromHandle(handle).visible;
1297 internal override void KillTimer(Timer timer) {
1299 TimerList.Remove(timer);
1303 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
1304 CGPoint pt = new CGPoint ();
1305 Rect wBounds = new Rect ();
1308 hwnd = Hwnd.ObjectFromHandle(handle);
1313 GetWindowBounds (GetControlOwner (hwnd.whole_window), 32, ref wBounds);
1314 HIViewConvertPoint (ref pt, handle, IntPtr.Zero);
1316 x = (int)(pt.x+wBounds.left);
1317 y = (int)(pt.y+wBounds.top);
1321 internal override void OverrideCursor(IntPtr cursor) {
1322 throw new NotImplementedException ();
1325 internal override PaintEventArgs PaintEventStart(IntPtr handle, bool client) {
1326 PaintEventArgs paint_event;
1329 hwnd = Hwnd.ObjectFromHandle(handle);
1331 if (Caret.Visible == 1) {
1332 Caret.Paused = true;
1336 hwnd.client_dc = Graphics.FromHwnd (hwnd.client_window);
1337 paint_event = new PaintEventArgs(hwnd.client_dc, hwnd.invalid);
1342 internal override void PaintEventEnd(IntPtr handle, bool client) {
1345 hwnd = Hwnd.ObjectFromHandle(handle);
1347 hwnd.ClearInvalidArea();
1349 hwnd.client_dc.Flush();
1350 hwnd.client_dc.Dispose();
1351 hwnd.client_dc = null;
1352 hwnd.expose_pending = false;
1354 if (Caret.Visible == 1) {
1356 Caret.Paused = false;
1360 internal override bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1361 Console.WriteLine("XplatUIOSX.PeekMessage");
1365 public static void PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
1366 MSG msg = new MSG();
1368 msg.message = message;
1369 msg.wParam = wParam;
1370 msg.lParam = lParam;
1371 MessageQueue.Enqueue (msg);
1375 internal override void ReleaseMenuDC(IntPtr hwnd, Graphics dc) {
1376 throw new NotImplementedException();
1379 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y) {
1380 CGPoint pt = new CGPoint ();
1381 Rect wBounds = new Rect ();
1383 GetWindowBounds (GetControlOwner (handle), 32, ref wBounds);
1384 pt.x = (x-wBounds.left);
1385 pt.y = (y-wBounds.top);
1386 HIViewConvertPoint (ref pt, IntPtr.Zero, handle);
1393 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
1394 CGPoint pt = new CGPoint ();
1395 Rect wBounds = new Rect ();
1397 GetWindowBounds (GetControlOwner (handle), 32, ref wBounds);
1398 pt.x = (x-wBounds.left);
1399 pt.y = (y-wBounds.top);
1400 HIViewConvertPoint (ref pt, IntPtr.Zero, handle);
1406 internal override void ScrollWindow(IntPtr handle, Rectangle area, int XAmount, int YAmount, bool clear) {
1407 //IntPtr rect = IntPtr.Zero;
1408 //HIRect vBounds = new HIRect ();
1410 Hwnd hwnd = Hwnd.ObjectFromHandle(handle);
1413 if (hwnd.invalid != Rectangle.Empty) {
1414 // BIG FAT WARNING. This only works with how we use this function right now
1415 // where we basically still scroll the whole window, but work around areas
1416 // that are covered by our children
1418 hwnd.invalid.X += XAmount;
1419 hwnd.invalid.Y += YAmount;
1421 if (hwnd.invalid.X < 0) {
1422 hwnd.invalid.Width += hwnd.invalid.X;
1426 if (hwnd.invalid.Y < 0) {
1427 hwnd.invalid.Height += hwnd.invalid.Y;
1432 HIRect scrollrect = new HIRect ();
1433 scrollrect.origin.x = area.X;
1434 scrollrect.origin.y = area.Y;
1435 scrollrect.size.width = area.Width;
1436 scrollrect.size.height = area.Height;
1437 HIViewScrollRect (hwnd.Handle, ref scrollrect, (float)XAmount, (float)-YAmount);
1439 HIViewGetBounds (hwnd.client_window, ref vBounds);
1440 HIViewConvertRect (ref vBounds, hwnd.client_window, IntPtr.Zero);
1441 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));
1442 ScrollRect (ref rect, (short)XAmount, (short)-YAmount, IntPtr.Zero);
1444 // Generate an expose for the area exposed by the horizontal scroll
1447 hwnd.AddInvalidArea (area.X, area.Y, XAmount, area.Height);
1448 } else if (XAmount < 0) {
1449 hwnd.AddInvalidArea (XAmount + area.X + area.Width, area.Y, -XAmount, area.Height);
1452 // Generate an expose for the area exposed by the vertical scroll
1454 hwnd.AddInvalidArea (area.X, area.Y, area.Width, YAmount);
1455 } else if (YAmount < 0) {
1456 hwnd.AddInvalidArea (area.X, YAmount + area.Y + area.Height, area.Width, -YAmount);
1459 UpdateWindow (handle);
1464 internal override void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool clear) {
1465 throw new NotImplementedException("");
1469 internal override void SendAsyncMethod (AsyncMethodData method) {
1470 throw new NotImplementedException ();
1473 internal override void SetCaretPos (IntPtr hwnd, int x, int y) {
1474 if (Caret.Hwnd == hwnd) {
1475 CGPoint cpt = new CGPoint ();
1478 HIViewConvertPoint (ref cpt, hwnd, IntPtr.Zero);
1479 Caret.Timer.Stop ();
1481 Caret.X = (int)cpt.x;
1482 Caret.Y = (int)cpt.y-23;
1483 if (Caret.Visible == 1) {
1485 Caret.Timer.Start ();
1490 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1491 SetThemeCursor ((uint) cursor);
1494 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1495 CGDisplayMoveCursorToPoint (CGMainDisplayID (), new CGPoint (x, y));
1498 internal override void SetFocus(IntPtr handle) {
1499 if (FocusWindow != IntPtr.Zero) {
1500 PostMessage(FocusWindow, Msg.WM_KILLFOCUS, handle, IntPtr.Zero);
1502 PostMessage(handle, Msg.WM_SETFOCUS, FocusWindow, IntPtr.Zero);
1503 FocusWindow = handle;
1507 internal override void SetIcon(IntPtr handle, Icon icon) {
1508 throw new NotImplementedException();
1512 internal override void SetModal(IntPtr handle, bool Modal) {
1513 IntPtr hWnd = GetControlOwner (Hwnd.ObjectFromHandle (handle).WholeWindow);
1515 BeginAppModalStateForWindow (hWnd);
1517 EndAppModalStateForWindow (hWnd);
1521 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1522 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1524 hwnd.parent = Hwnd.ObjectFromHandle (parent);
1525 if (HIViewGetSuperview (hwnd.whole_window) != IntPtr.Zero) {
1526 CheckError (HIViewRemoveFromSuperview (hwnd.whole_window), "HIViewRemoveFromSuperview ()");
1528 CheckError (HIViewAddSubview (hwnd.parent.client_window, hwnd.whole_window));
1529 CheckError (HIViewAddSubview (hwnd.whole_window, hwnd.client_window));
1530 HIViewPlaceInSuperviewAt (hwnd.client_window, hwnd.ClientRect.X, hwnd.ClientRect.Y);
1535 internal override void SetTimer (Timer timer) {
1537 TimerList.Add (timer);
1541 internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
1542 HIViewSetZOrder (hWnd, 1, IntPtr.Zero);
1547 internal override bool SetVisible(IntPtr handle, bool visible) {
1548 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1549 object window = WindowMapping [hwnd.Handle];
1552 ShowWindow ((IntPtr)window);
1554 HideWindow ((IntPtr)window);
1556 HIViewSetVisible (hwnd.whole_window, visible);
1557 HIViewSetVisible (hwnd.client_window, visible);
1558 hwnd.visible = visible;
1562 internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
1565 hwnd = Hwnd.ObjectFromHandle(handle);
1566 hwnd.border_style = border_style;
1568 // FIXME - do we need to trigger some resize?
1571 internal override void SetMenu(IntPtr handle, IntPtr menu_handle) {
1574 hwnd = Hwnd.ObjectFromHandle(handle);
1575 hwnd.menu_handle = menu_handle;
1577 // FIXME - do we need to trigger some resize?
1580 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1581 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1582 Rectangle client_rect = Hwnd.GetClientRectangle(hwnd.border_style, hwnd.menu_handle, hwnd.title_style, width, height);
1584 // Save a server roundtrip (and prevent a feedback loop)
1585 if ((hwnd.x == x) && (hwnd.y == y) && (hwnd.width == width) && (hwnd.height == height)) {
1590 if (WindowMapping [hwnd.Handle] != null) {
1591 if (y <= MenuBarHeight+TitleBarHeight) {
1592 y+=MenuBarHeight+TitleBarHeight;
1594 IntPtr rect = IntPtr.Zero;
1595 SetRect (ref rect, (short)x, (short)y, (short)(x+width), (short)(y+height));
1596 CheckError (SetWindowBounds ((IntPtr) WindowMapping [hwnd.Handle], 33, ref rect), "SetWindowBounds ()");
1597 HIRect r = new HIRect (0, 0, width, height);
1598 CheckError (HIViewSetFrame (hwnd.whole_window, ref r), "HIViewSetFrame ()");
1599 r = new HIRect (client_rect.X, client_rect.Y, client_rect.X+client_rect.Width, client_rect.Y+client_rect.Height);
1600 CheckError (HIViewSetFrame (hwnd.client_window, ref r), "HIViewSetFrame ()");
1602 HIRect r = new HIRect (x, y, width, height);
1603 CheckError (HIViewSetFrame (hwnd.whole_window, ref r), "HIViewSetFrame ()");
1604 r = new HIRect (client_rect.X, client_rect.Y, client_rect.X+client_rect.Width, client_rect.Y+client_rect.Height);
1605 CheckError (HIViewSetFrame (hwnd.client_window, ref r), "HIViewSetFrame ()");
1609 internal override void SetWindowState(IntPtr hwnd, FormWindowState state) {
1610 IntPtr window = GetControlOwner (hwnd);
1613 case FormWindowState.Minimized: {
1614 CollapseWindow (window, true);
1617 case FormWindowState.Normal: {
1618 ZoomWindow (window, 7, false);
1621 case FormWindowState.Maximized: {
1622 ZoomWindow (window, 8, false);
1628 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1629 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1630 SetHwndStyles(hwnd, cp);
1632 if (WindowMapping [hwnd.Handle] != null) {
1633 WindowAttributes attributes = WindowAttributes.kWindowCompositingAttribute | WindowAttributes.kWindowStandardHandlerAttribute;
1634 if ((cp.Style & ((int)WindowStyles.WS_MINIMIZEBOX)) != 0) {
1635 attributes |= WindowAttributes.kWindowCollapseBoxAttribute;
1637 if ((cp.Style & ((int)WindowStyles.WS_MAXIMIZEBOX)) != 0) {
1638 attributes |= WindowAttributes.kWindowResizableAttribute | WindowAttributes.kWindowHorizontalZoomAttribute | WindowAttributes.kWindowVerticalZoomAttribute;
1640 if ((cp.Style & ((int)WindowStyles.WS_SYSMENU)) != 0) {
1641 attributes |= WindowAttributes.kWindowCloseBoxAttribute;
1643 if ((cp.ExStyle & ((int)WindowStyles.WS_EX_TOOLWINDOW)) != 0) {
1644 attributes = WindowAttributes.kWindowStandardHandlerAttribute | WindowAttributes.kWindowCompositingAttribute;
1647 WindowAttributes outAttributes = WindowAttributes.kWindowNoAttributes;
1648 GetWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], ref outAttributes);
1649 ChangeWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], attributes, outAttributes);
1653 internal override bool SetZOrder(IntPtr handle, IntPtr after_handle, bool Top, bool Bottom) {
1654 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1657 HIViewSetZOrder (hwnd.whole_window, 2, IntPtr.Zero);
1659 } else if (!Bottom) {
1660 Hwnd after_hwnd = Hwnd.ObjectFromHandle (after_handle);
1661 HIViewSetZOrder (hwnd.whole_window, 2, after_hwnd.whole_window);
1663 HIViewSetZOrder (hwnd.whole_window, 1, IntPtr.Zero);
1669 internal override void ShowCursor(bool show) {
1671 CGDisplayShowCursor (CGMainDisplayID ());
1673 CGDisplayHideCursor (CGMainDisplayID ());
1677 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
1678 throw new NotImplementedException();
1682 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
1683 throw new NotImplementedException();
1687 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
1688 throw new NotImplementedException();
1691 internal override bool Text(IntPtr handle, string text) {
1692 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1693 if (WindowMapping [hwnd.Handle] != null) {
1694 CheckError (SetWindowTitleWithCFString ((IntPtr)(WindowMapping [hwnd.Handle]), __CFStringMakeConstantString (text)));
1696 CheckError (SetControlTitleWithCFString (hwnd.whole_window, __CFStringMakeConstantString (text)));
1697 CheckError (SetControlTitleWithCFString (hwnd.client_window, __CFStringMakeConstantString (text)));
1701 internal override void UpdateWindow(IntPtr handle) {
1702 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1704 if (hwnd.visible && HIViewIsVisible (handle) && !hwnd.expose_pending) {
1705 MSG msg = new MSG ();
1706 msg.message = Msg.WM_PAINT;
1707 msg.hwnd = hwnd.Handle;
1708 msg.lParam = IntPtr.Zero;
1709 msg.wParam = IntPtr.Zero;
1710 MessageQueue.Enqueue (msg);
1714 internal override bool TranslateMessage(ref MSG msg) {
1716 Hwnd hwnd = Hwnd.ObjectFromHandle (msg.hwnd);
1718 switch (msg.message) {
1719 case Msg.WM_MOUSEMOVE: {
1721 if (GrabWindowHwnd != null) {
1722 if (GrabWindowHwnd.Handle != hwnd.Handle) {
1726 if (MouseWindow != null) {
1727 if (MouseWindow.Handle != hwnd.Handle) {
1728 PostMessage (MouseWindow.Handle, Msg.WM_MOUSE_LEAVE, IntPtr.Zero, IntPtr.Zero);
1729 PostMessage (hwnd.Handle, Msg.WM_MOUSE_ENTER, IntPtr.Zero, IntPtr.Zero);
1738 case Msg.WM_SETFOCUS: {
1744 // This is a hideous temporary keyboard hack to bind some keys
1745 if (msg.message >= Msg.WM_KEYFIRST && msg.message <= Msg.WM_KEYLAST)
1748 if (msg.message != Msg.WM_KEYDOWN && msg.message != Msg.WM_SYSKEYDOWN)
1751 if ((int)msg.wParam >= (int)'0' && (int)msg.wParam <= (int)'z') {
1753 message = Msg.WM_CHAR;
1754 PostMessage (msg.hwnd, message, msg.wParam, msg.lParam);
1759 internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
1760 throw new NotImplementedException();
1764 internal override SizeF GetAutoScaleSize(Font font) {
1765 throw new NotImplementedException();
1769 #region System information
1770 internal override int KeyboardSpeed { get{ throw new NotImplementedException(); } }
1771 internal override int KeyboardDelay { get{ throw new NotImplementedException(); } }
1773 internal override int Caption { get{ throw new NotImplementedException(); } }
1774 internal override Size CursorSize { get{ throw new NotImplementedException(); } }
1775 internal override bool DragFullWindows { get{ throw new NotImplementedException(); } }
1776 internal override Size DragSize { get{ throw new NotImplementedException(); } }
1777 internal override Size FrameBorderSize { get{ throw new NotImplementedException(); } }
1778 internal override Size IconSize { get{ throw new NotImplementedException(); } }
1779 internal override Size MaxWindowTrackSize { get{ throw new NotImplementedException(); } }
1780 internal override Size MinimizedWindowSize { get{ throw new NotImplementedException(); } }
1781 internal override Size MinimizedWindowSpacingSize { get{ throw new NotImplementedException(); } }
1782 internal override Size MinimumWindowSize { get{ throw new NotImplementedException(); } }
1783 internal override Size MinWindowTrackSize { get{ throw new NotImplementedException(); } }
1784 internal override Size SmallIconSize { get{ throw new NotImplementedException(); } }
1785 internal override int MouseButtonCount { get{ throw new NotImplementedException(); } }
1786 internal override bool MouseButtonsSwapped { get{ throw new NotImplementedException(); } }
1787 internal override bool MouseWheelPresent { get{ throw new NotImplementedException(); } }
1788 internal override Rectangle VirtualScreen { get{ throw new NotImplementedException(); } }
1789 internal override Rectangle WorkingArea {
1791 HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1792 return new Rectangle ((int)bounds.origin.x, (int)bounds.origin.y, (int)bounds.size.width, (int)bounds.size.height);
1797 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1798 internal static extern int HIViewSetNeedsDisplayInRegion (IntPtr view, IntPtr rgn, bool needsDisplay);
1799 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1800 internal static extern int HIViewGetSubviewHit (IntPtr contentView, ref CGPoint point, bool tval, ref IntPtr outPtr);
1801 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1802 internal static extern int HIViewGetViewForMouseEvent (IntPtr inView, IntPtr inEvent, ref IntPtr outView);
1803 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1804 internal static extern int HIViewConvertPoint (ref CGPoint point, IntPtr pView, IntPtr cView);
1805 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1806 internal static extern int HIViewChangeFeatures (IntPtr aView, ulong bitsin, ulong bitsout);
1807 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1808 internal static extern int HIViewFindByID (IntPtr rootWnd, HIViewID id, ref IntPtr outPtr);
1809 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1810 internal static extern IntPtr HIViewGetRoot (IntPtr hWnd);
1811 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1812 internal static extern int HIObjectCreate (IntPtr cfStr, uint what, ref IntPtr hwnd);
1813 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1814 internal static extern int HIViewSetNeedsDisplay (IntPtr viewHnd, bool update);
1815 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1816 internal static extern int HIViewGetFrame (IntPtr viewHnd, ref HIRect rect);
1817 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1818 internal static extern int HIViewSetFrame (IntPtr viewHnd, ref HIRect rect);
1819 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1820 internal static extern int HIViewPlaceInSuperviewAt (IntPtr view, float x, float y);
1821 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1822 internal static extern int HIViewAddSubview (IntPtr parentHnd, IntPtr childHnd);
1823 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1824 internal static extern IntPtr HIViewGetNextView (IntPtr aView);
1825 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1826 internal static extern IntPtr HIViewGetPreviousView (IntPtr aView);
1827 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1828 internal static extern IntPtr HIViewGetFirstSubview (IntPtr aView);
1829 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1830 internal static extern IntPtr HIViewGetSuperview (IntPtr aView);
1831 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1832 internal static extern int HIViewRemoveFromSuperview (IntPtr aView);
1833 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1834 internal static extern int HIViewSetVisible (IntPtr vHnd, bool visible);
1835 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1836 internal static extern bool HIViewIsVisible (IntPtr vHnd);
1837 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1838 internal static extern int HIViewGetBounds (IntPtr vHnd, ref HIRect r);
1839 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1840 internal static extern int HIViewScrollRect (IntPtr vHnd, ref HIRect rect, float x, float y);
1841 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1842 internal static extern int HIViewScrollRect (IntPtr vHnd, IntPtr rect, float x, float y);
1843 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1844 internal static extern int HIViewSetZOrder (IntPtr hWnd, int cmd, IntPtr oHnd);
1845 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1846 internal static extern int HIViewSetBoundsOrigin (IntPtr vHnd, float x, float y);
1847 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1848 internal static extern int HIViewConvertRect (ref HIRect r, IntPtr a, IntPtr b);
1850 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1851 internal static extern void ScrollRect (ref IntPtr r, short dh, short dv, IntPtr rgnHandle);
1852 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1853 internal static extern void SetRect (ref IntPtr r, short left, short top, short right, short bottom);
1855 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1856 static extern int CreateEvent (IntPtr allocator, uint classid, uint kind, double when, uint attributes, ref IntPtr outEvent);
1857 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1858 static extern int InstallEventHandler (IntPtr window, CarbonEventDelegate handlerProc, uint numtypes, EventTypeSpec [] typeList, IntPtr userData, IntPtr handlerRef);
1859 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1860 internal static extern IntPtr GetControlOwner (IntPtr aView);
1861 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1862 static extern int ActivateWindow (IntPtr windowHnd, bool inActivate);
1863 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1864 static extern bool IsWindowActive (IntPtr windowHnd);
1865 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1866 static extern int SetKeyboardFocus (IntPtr windowHdn, IntPtr cntrlHnd, short partcode);
1867 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1868 static extern int GetKeyboardFocus (IntPtr handle, ref IntPtr cntrl);
1870 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1871 internal static extern IntPtr GetWindowEventTarget (IntPtr window);
1872 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1873 internal static extern IntPtr GetControlEventTarget (IntPtr aControl);
1874 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1875 internal static extern IntPtr GetEventDispatcherTarget ();
1876 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1877 internal static extern int SendEventToEventTarget (IntPtr evt, IntPtr target);
1878 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1879 internal static extern int ReleaseEvent (IntPtr evt);
1880 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1881 internal static extern int ReceiveNextEvent (uint evtCount, IntPtr evtTypes, double timeout, bool processEvt, ref IntPtr evt);
1882 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1883 static extern uint GetEventClass (IntPtr eventRef);
1884 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1885 static extern uint GetEventKind (IntPtr eventRef);
1886 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1887 static extern int GetEventParameter (IntPtr evt, OSXConstants.EventParamName inName, OSXConstants.EventParamType inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref byte outData);
1888 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1889 static extern int GetEventParameter (IntPtr evt, OSXConstants.EventParamName inName, OSXConstants.EventParamType inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref IntPtr outData);
1890 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1891 static extern int GetEventParameter (IntPtr evt, OSXConstants.EventParamName inName, OSXConstants.EventParamType inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref ushort outData);
1892 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1893 static extern int GetEventParameter (IntPtr evt, OSXConstants.EventParamName inName, OSXConstants.EventParamType inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref short outData);
1894 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1895 static extern int GetEventParameter (IntPtr evt, OSXConstants.EventParamName inName, OSXConstants.EventParamType inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref QDPoint outData);
1896 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1897 static extern int SetEventParameter (IntPtr evt, OSXConstants.EventParamName inName, OSXConstants.EventParamType inType, uint bufSize, ref short outData);
1898 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1899 static extern int SetEventParameter (IntPtr evt, OSXConstants.EventParamName inName, OSXConstants.EventParamType inType, uint bufSize, ref IntPtr outData);
1901 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1902 internal static extern void CGContextFlush (IntPtr cgc);
1903 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1904 internal static extern int CGContextFillRect (IntPtr cgc, HIRect r);
1905 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1906 internal static extern CGAffineTransform CGContextGetTextMatrix (IntPtr cgContext);
1907 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1908 internal static extern int CGContextSetTextMatrix (IntPtr cgContext, CGAffineTransform ctm);
1909 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1910 internal static extern int CGContextSetRGBFillColor (IntPtr cgContext, float r, float g, float b, float alpha);
1911 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1912 internal static extern int CGContextSetRGBStrokeColor (IntPtr cgContext, float r, float g, float b, float alpha);
1913 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1914 internal static extern int CGContextSetTextDrawingMode (IntPtr cgContext, int drawingMode);
1915 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1916 internal static extern int CGContextSelectFont (IntPtr cgContext, string fontName, float size, int textEncoding);
1917 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1918 internal static extern int CGContextShowTextAtPoint (IntPtr cgContext, float x, float y, string text, int length);
1919 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1920 internal static extern int CGContextClipToRect (IntPtr cgContext, HIRect clip);
1921 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1922 internal static extern void CreateCGContextForPort (IntPtr port, ref IntPtr cgc);
1923 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1924 internal static extern bool IsWindowCollapsed (IntPtr hWnd);
1925 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1926 internal static extern bool IsWindowInStandardState (IntPtr hWnd, IntPtr a, IntPtr b);
1927 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1928 internal static extern void CollapseWindow (IntPtr hWnd, bool collapse);
1929 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1930 internal static extern void ZoomWindow (IntPtr hWnd, short partCode, bool front);
1931 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1932 internal static extern int GetWindowAttributes (IntPtr hWnd, ref WindowAttributes outAttributes);
1933 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1934 internal static extern int ChangeWindowAttributes (IntPtr hWnd, WindowAttributes inAttributes, WindowAttributes outAttributes);
1935 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1936 internal static extern IntPtr GetWindowPort (IntPtr hWnd);
1937 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1938 static extern int SetPortWindowPort (IntPtr hWnd);
1939 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1940 static extern int GetGlobalMouse (ref QDPoint outData);
1941 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1942 static extern int GlobalToLocal (ref QDPoint outData);
1943 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1944 static extern int LocalToGlobal (ref QDPoint outData);
1945 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1946 static extern int TrackControl (IntPtr handle, QDPoint point, IntPtr data);
1948 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1949 internal static extern int BeginAppModalStateForWindow (IntPtr window);
1950 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1951 internal static extern int EndAppModalStateForWindow (IntPtr window);
1952 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1953 internal static extern int CreateNewWindow (WindowClass klass, WindowAttributes attributes, ref IntPtr r, ref IntPtr window);
1954 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1955 internal static extern int DisposeWindow (IntPtr wHnd);
1956 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1957 internal static extern int ShowWindow (IntPtr wHnd);
1958 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1959 internal static extern int HideWindow (IntPtr wHnd);
1960 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1961 internal static extern int SetWindowBounds (IntPtr wHnd, uint reg, ref IntPtr rect);
1962 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1963 internal static extern int GetWindowPortBounds (IntPtr wHnd, ref Rect rect);
1964 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1965 internal static extern int GetWindowBounds (IntPtr wHnd, uint reg, ref Rect rect);
1966 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1967 internal static extern int InvertRect (ref Rect r);
1969 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1970 internal static extern int SetControlTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
1971 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1972 internal static extern int SetWindowTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
1973 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1974 internal static extern IntPtr __CFStringMakeConstantString (string cString);
1976 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1977 internal static extern void CGContextRestoreGState (IntPtr ctx);
1978 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1979 internal static extern void CGContextSaveGState (IntPtr ctx);
1980 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1981 internal static extern void CGContextTranslateCTM (IntPtr ctx, double tx, double ty);
1982 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1983 internal static extern void CGContextScaleCTM (IntPtr ctx, double tx, double ty);
1985 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1986 static extern int SetWindowContentColor (IntPtr hWnd, ref RGBColor backColor);
1987 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1988 static extern int TrackMouseLocationWithOptions (IntPtr port, int options, double eventtimeout, ref QDPoint point, ref IntPtr modifier, ref MouseTrackingResult status);
1989 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1990 static extern int CreateMouseTrackingRegion (IntPtr windowref, IntPtr rgn, IntPtr clip, int options, MouseTrackingRegionID rid, IntPtr refcon, IntPtr evttargetref, ref IntPtr mousetrackref);
1991 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1992 static extern int ReleaseMouseTrackingRegion (IntPtr region_handle);
1994 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1995 internal static extern int CFRelease (IntPtr wHnd);
1997 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
1998 internal extern static IntPtr NewRgn ();
1999 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2000 internal extern static void CopyRgn (IntPtr srcrgn, IntPtr destrgn);
2001 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2002 internal extern static void SetRectRgn (IntPtr rgn, short left, short top, short right, short bottom);
2003 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2004 internal extern static void DisposeRgn (IntPtr rgn);
2005 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2006 internal extern static void ExitToShell ();
2007 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2008 internal extern static short GetMBarHeight ();
2010 #region Cursor imports
2011 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2012 internal extern static HIRect CGDisplayBounds (IntPtr displayID);
2013 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2014 internal extern static IntPtr CGMainDisplayID ();
2015 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2016 internal extern static void CGDisplayShowCursor (IntPtr display);
2017 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2018 internal extern static void CGDisplayHideCursor (IntPtr display);
2019 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2020 internal extern static void CGDisplayMoveCursorToPoint (IntPtr display, CGPoint point);
2021 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2022 internal extern static void SetThemeCursor (uint inCursor);
2025 [DllImport ("gdiplus", EntryPoint="GetFontMetrics")]
2026 internal extern static bool GetFontMetrics(IntPtr graphicsObject, IntPtr nativeObject, out int ascent, out int descent);