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 using System.Threading;
32 using System.ComponentModel;
33 using System.Collections;
34 using System.Diagnostics;
35 using System.Runtime.InteropServices;
38 namespace System.Windows.Forms {
40 delegate int CarbonEventHandler (IntPtr inCallRef, IntPtr inEvent, IntPtr userData);
42 internal class XplatUIOSX : XplatUIDriver {
44 private static XplatUIOSX instance;
45 private static int ref_count;
47 internal static MouseButtons mouse_state;
48 internal static Point mouse_position;
50 internal static IntPtr mouseInWindow;
51 private static Hashtable handle_data;
52 private static Queue carbonEvents;
53 private CarbonEventHandler viewEventHandler;
54 private CarbonEventHandler windowEventHandler;
55 private static Hashtable view_window_mapping;
56 private static IntPtr grabWindow;
58 private static EventTypeSpec [] viewEvents = new EventTypeSpec [] {
59 new EventTypeSpec (1668183148, 4)
61 private static EventTypeSpec [] windowEvents = new EventTypeSpec[] {
62 new EventTypeSpec (1836021107, 1),
63 new EventTypeSpec (1836021107, 2),
64 new EventTypeSpec (1836021107, 5),
65 new EventTypeSpec (1836021107, 6),
66 new EventTypeSpec (1836021107, 10),
67 new EventTypeSpec (2003398244, 27)
70 private ArrayList timer_list;
73 internal override Keys ModifierKeys {
75 throw new NotImplementedException ();
79 internal override MouseButtons MouseButtons {
85 internal override Point MousePosition {
87 return mouse_position;
92 internal override bool DropTarget {
94 throw new NotImplementedException ();
97 throw new NotImplementedException ();
101 private XplatUIOSX() {
102 viewEventHandler = new CarbonEventHandler (ViewHandler);
103 windowEventHandler = new CarbonEventHandler (WindowHandler);
105 mouseInWindow = IntPtr.Zero;
106 handle_data = new Hashtable ();
107 carbonEvents = new Queue ();
108 grabWindow = IntPtr.Zero;
109 view_window_mapping = new Hashtable ();
110 mouse_state=MouseButtons.None;
111 mouse_position=Point.Empty;
113 timer_list = new ArrayList ();
118 throw new NotImplementedException ();
121 public static XplatUIOSX GetInstance() {
122 lock (typeof (XplatUIOSX)) {
123 if (instance == null) {
124 instance = new XplatUIOSX ();
131 internal override event EventHandler Idle;
134 public int Reference {
136 throw new NotImplementedException ();
141 private void MouseHover (object sender, EventArgs e) {
142 throw new NotImplementedException ();
146 internal override IntPtr InitializeDriver() {
147 throw new NotImplementedException ();
151 internal override void ShutdownDriver(IntPtr token) {
152 throw new NotImplementedException ();
155 internal void Version() {
156 Console.WriteLine("Xplat version $revision: $");
159 internal override void Exit() {
160 Console.WriteLine("XplatUIOSX.Exit");
164 internal override void GetDisplaySize(out Size size) {
166 size = new Size (1024, 768);
167 // throw new NotImplementedException ();
171 internal override void EnableThemes() {
172 throw new NotImplementedException ();
175 internal override IntPtr CreateWindow(CreateParams cp) {
176 IntPtr hWnd = IntPtr.Zero;
177 IntPtr windowHnd = IntPtr.Zero;
178 IntPtr parentHnd = cp.Parent;
179 bool realWindow = false;
181 if (parentHnd == IntPtr.Zero) {
182 if ((cp.Style & (int)(WindowStyles.WS_CHILD))!=0) {
183 // This is a child view that is going to be parentless;
185 } else if ((cp.Style & (int)(WindowStyles.WS_POPUP))!=0) {
186 // This is a popup window that will be real.
189 // This is a real root window too
190 if (cp.X < 1) cp.X = 0;
191 if (cp.Y < 1) cp.Y = 0;
199 IntPtr rect = IntPtr.Zero;
200 IntPtr viewHnd = IntPtr.Zero;
201 SetRect (ref rect, (short)cp.X, (short)cp.Y, (short)(cp.Width+cp.X), (short)(cp.Height+cp.Y));
202 CheckError (CreateNewWindow (6, 33554432 | 31 | 524288 , ref rect, ref windowHnd), "CreateNewWindow ()");
203 CheckError (InstallEventHandler (GetWindowEventTarget (windowHnd), windowEventHandler, (uint)windowEvents.Length, windowEvents, windowHnd, IntPtr.Zero), "InstallEventHandler ()");
204 CheckError (HIViewFindByID (HIViewGetRoot (windowHnd), new HIViewID (2003398244, 1), ref viewHnd), "HIViewFindByID ()");
207 HIRect r = new HIRect (0, 0, cp.Width, cp.Height);
208 CheckError (HIObjectCreate (__CFStringMakeConstantString ("com.apple.hiview"), 0, ref hWnd), "HIObjectCreate ()");
209 CheckError (InstallEventHandler (GetControlEventTarget (hWnd), viewEventHandler, (uint)viewEvents.Length, viewEvents, hWnd, IntPtr.Zero), "InstallEventHandler ()");
210 CheckError (HIViewChangeFeatures (hWnd, 1 << 1, 0), "HIViewChangeFeatures ()");
211 CheckError (HIViewSetFrame (hWnd, ref r), "HIViewSetFrame ()");
212 if (parentHnd != IntPtr.Zero && parentHnd != hWnd) {
213 CheckError (HIViewAddSubview (parentHnd, hWnd), "HIViewAddSubview ()");
214 if ((cp.Style & (int)(WindowStyles.WS_VISIBLE))!=0) {
215 CheckError (HIViewSetVisible (hWnd, true), "HIViewSetVisible ()");
217 CheckError (HIViewSetVisible (hWnd, IsVisible (parentHnd)), "HIViewSetVisible ()");
221 view_window_mapping [hWnd] = windowHnd;
222 if ((cp.Style & (int)(WindowStyles.WS_VISIBLE))!=0) {
223 CheckError (ShowWindow (windowHnd));
224 CheckError (HIViewSetVisible (hWnd, true), "HIViewSetVisible ()");
230 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
231 CreateParams create_params = new CreateParams();
233 create_params.Caption = "";
236 create_params.Width = Width;
237 create_params.Height = Height;
239 create_params.ClassName=XplatUI.DefaultClassName;
240 create_params.ClassStyle = 0;
241 create_params.ExStyle=0;
242 create_params.Parent=IntPtr.Zero;
243 create_params.Param=0;
245 return CreateWindow(create_params);
249 internal override void DestroyWindow(IntPtr handle) {
250 throw new NotImplementedException ();
254 internal override void RefreshWindow(IntPtr handle) {
255 IntPtr outEvent = IntPtr.Zero;
256 HIViewSetNeedsDisplay (handle, true);
259 [MonoTODO("Find a way to make all the views do this; not just the window view")]
260 internal override void SetWindowBackground(IntPtr handle, Color color) {
261 if (view_window_mapping [handle] != null) {
262 RGBColor backColor = new RGBColor ();
263 backColor.red = (short)(color.R * 257);
264 backColor.green = (short)(color.G * 257);
265 backColor.blue = (short)(color.B * 257);
267 CheckError (SetWindowContentColor ((IntPtr) view_window_mapping [handle], ref backColor));
272 internal override PaintEventArgs PaintEventStart(IntPtr handle) {
273 PaintEventArgs paint_event;
275 HandleData data = (HandleData) handle_data [handle];
277 throw new Exception ("null data on paint event start: " + handle);
280 data.DeviceContext = Graphics.FromHwnd (handle);
281 paint_event = new PaintEventArgs((Graphics)data.DeviceContext, data.InvalidArea);
287 internal override void PaintEventEnd(IntPtr handle) {
288 HandleData data = (HandleData) handle_data [handle];
290 throw new Exception ("null data on PaintEventEnd");
291 data.ClearInvalidArea ();
292 Graphics g = (Graphics) data.DeviceContext;
297 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
298 if (view_window_mapping [handle] != null) {
299 if (x == 0 && y == 0) {
300 Rect bounds = new Rect ();
301 CheckError (GetWindowBounds ((IntPtr) view_window_mapping [handle], 32, ref bounds), "GetWindowBounds ()");
305 IntPtr rect = IntPtr.Zero;
306 SetRect (ref rect, (short)x, (short)y, (short)(x+width), (short)(y+height));
307 CheckError (SetWindowBounds ((IntPtr) view_window_mapping [handle], 32, ref rect), "SetWindowBounds ()");
308 HIRect r = new HIRect (0, 0, width, height);
309 CheckError (HIViewSetFrame (handle, ref r), "HIViewSetFrame ()");
311 HIRect r = new HIRect (x, y, width, height);
312 CheckError (HIViewSetFrame (handle, ref r), "HIViewSetFrame ()");
317 internal override void GetWindowPos(IntPtr handle, out int x, out int y, out int width, out int height, out int client_width, out int client_height) {
318 HIRect r = new HIRect ();
319 CheckError (HIViewGetFrame (handle, ref r), "HIViewGetFrame ()");
322 width = (int)r.size.width;
323 height = (int)r.size.height;
324 client_width = width;
325 client_height = height;
329 internal override void Activate(IntPtr handle) {
330 throw new NotImplementedException ();
334 internal override void EnableWindow(IntPtr handle, bool Enable) {
335 //throw new NotImplementedException ();
339 internal override void SetModal(IntPtr handle, bool Modal) {
340 // FIXME: What do we do here on OSX?
345 internal override void Invalidate (IntPtr handle, Rectangle rc, bool clear) {
346 // FIXME: What do we do here
347 // throw new NotImplementedException ();
351 internal override IntPtr DefWndProc(ref Message msg) {
356 internal override void HandleException(Exception e) {
357 throw new NotImplementedException ();
361 internal override void DoEvents() {
362 throw new NotImplementedException ();
366 internal override bool PeekMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
367 throw new NotImplementedException ();
370 internal int WindowHandler (IntPtr inCallRef, IntPtr inEvent, IntPtr controlHnd) {
371 int eventClass = GetEventClass (inEvent);
372 int eventKind = GetEventKind (inEvent);
373 MSG msg = new MSG ();
374 msg.hwnd = IntPtr.Zero;
375 lock (carbonEvents) {
376 switch (eventClass) {
380 // This is our real window; so we have to resize the corresponding view as well
381 IDictionaryEnumerator e = view_window_mapping.GetEnumerator ();
382 while (e.MoveNext ()) {
383 if ((IntPtr)e.Value == controlHnd) {
384 Rect bounds = new Rect ();
385 CheckError (GetWindowBounds (controlHnd, 32, ref bounds), "GetWindowBounds ()");
386 HIRect r = new HIRect ();
387 CheckError (HIViewGetFrame ((IntPtr)e.Key, ref r), "HIViewGetFrame ()");
388 r.size.width = bounds.right-bounds.left;
389 r.size.height = bounds.bottom-bounds.top;
390 CheckError (HIViewSetFrame ((IntPtr)e.Key, ref r), "HIViewSetFrame ()");
391 msg.message = Msg.WM_WINDOWPOSCHANGED;
392 msg.hwnd = (IntPtr)e.Key;
393 msg.wParam = IntPtr.Zero;
394 msg.lParam = IntPtr.Zero;
395 carbonEvents.Enqueue (msg);
408 QDPoint point = new QDPoint ();
409 IntPtr pView = IntPtr.Zero;
410 IntPtr rView = IntPtr.Zero;
413 GetEventParameter (inEvent, 1835168878, 1835168878, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (ushort)), IntPtr.Zero, ref btn);
414 CheckError (GetEventParameter (inEvent, 1835822947, 1363439732, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref point), "GetEventParameter() MouseLocation");
415 SetPortWindowPort (controlHnd);
416 GlobalToLocal (ref point);
417 // Translate this point
418 Rect bounds = new Rect ();
419 CheckError (GetWindowBounds (controlHnd, 32, ref bounds), "GetWindowBounds ()");
420 // Swizzle it so its pointed at the right control
421 CGPoint hiPoint = new CGPoint (point.y, point.x);
422 CheckError (HIViewFindByID (HIViewGetRoot (controlHnd), new HIViewID (2003398244, 1), ref pView), "HIViewFindByID ()");
423 CheckError (HIViewGetSubviewHit (pView, ref hiPoint, true, ref rView));
424 HIViewConvertPoint (ref hiPoint, pView, rView);
425 if (grabWindow == IntPtr.Zero)
428 msg.hwnd = grabWindow;
431 if (eventKind == 1) {
432 mouse_state |= MouseButtons.Left;
433 msg.message = Msg.WM_LBUTTONDOWN;
434 wParam |= (int)MsgButtons.MK_LBUTTON;
436 mouse_state &= MouseButtons.Left;
437 msg.message = Msg.WM_LBUTTONUP;
438 wParam |= (int)MsgButtons.MK_LBUTTON;
442 if (eventKind == 1) {
443 mouse_state |= MouseButtons.Middle;
444 msg.message = Msg.WM_MBUTTONDOWN;
445 wParam |= (int)MsgButtons.MK_MBUTTON;
447 mouse_state &= MouseButtons.Middle;
448 msg.message = Msg.WM_MBUTTONUP;
449 wParam |= (int)MsgButtons.MK_MBUTTON;
453 if (eventKind == 1) {
454 mouse_state |= MouseButtons.Right;
455 msg.message = Msg.WM_RBUTTONDOWN;
456 wParam |= (int)MsgButtons.MK_RBUTTON;
458 mouse_state &= MouseButtons.Right;
459 msg.message = Msg.WM_RBUTTONUP;
460 wParam |= (int)MsgButtons.MK_RBUTTON;
464 msg.wParam = (IntPtr)wParam;
465 msg.lParam = (IntPtr) ((ushort)hiPoint.y << 16 | (ushort)hiPoint.x);
466 mouse_position.X = (int)hiPoint.x;
467 mouse_position.Y = (int)hiPoint.y;
468 carbonEvents.Enqueue (msg);
472 QDPoint point = new QDPoint ();
473 IntPtr pView = IntPtr.Zero;
474 IntPtr rView = IntPtr.Zero;
476 GetEventParameter (inEvent, 1835168878, 1835168878, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (ushort)), IntPtr.Zero, ref btn);
477 CheckError (GetEventParameter (inEvent, 1835822947, 1363439732, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref point), "GetEventParameter() MouseLocation");
478 SetPortWindowPort (controlHnd);
479 GlobalToLocal (ref point);
480 // Translate this point
481 Rect bounds = new Rect ();
482 CheckError (GetWindowBounds (controlHnd, 32, ref bounds), "GetWindowBounds ()");
483 // Swizzle it so its pointed at the right control
484 CGPoint hiPoint = new CGPoint (point.y, point.x);
485 CheckError (HIViewFindByID (HIViewGetRoot (controlHnd), new HIViewID (2003398244, 1), ref pView), "HIViewFindByID ()");
486 CheckError (HIViewGetSubviewHit (pView, ref hiPoint, true, ref rView));
487 HIViewConvertPoint (ref hiPoint, pView, rView);
488 if (mouseInWindow != rView && grabWindow != IntPtr.Zero) {
489 msg.hwnd = mouseInWindow;
490 msg.message = Msg.WM_MOUSE_LEAVE;
491 carbonEvents.Enqueue (msg);
493 msg.message = Msg.WM_MOUSE_ENTER;
494 carbonEvents.Enqueue (msg);
495 mouseInWindow = rView;
501 QDPoint point = new QDPoint ();
502 IntPtr pView = IntPtr.Zero;
503 IntPtr rView = IntPtr.Zero;
505 GetEventParameter (inEvent, 1835168878, 1835168878, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (ushort)), IntPtr.Zero, ref btn);
506 CheckError (GetEventParameter (inEvent, 1835822947, 1363439732, IntPtr.Zero, (uint)Marshal.SizeOf (typeof (QDPoint)), IntPtr.Zero, ref point), "GetEventParameter() MouseLocation");
507 SetPortWindowPort (controlHnd);
508 GlobalToLocal (ref point);
509 // Translate this point
510 Rect bounds = new Rect ();
511 CheckError (GetWindowBounds (controlHnd, 32, ref bounds), "GetWindowBounds ()");
512 // Swizzle it so its pointed at the right control
513 CGPoint hiPoint = new CGPoint (point.y, point.x);
514 CheckError (HIViewFindByID (HIViewGetRoot (controlHnd), new HIViewID (2003398244, 1), ref pView), "HIViewFindByID ()");
515 CheckError (HIViewGetSubviewHit (pView, ref hiPoint, true, ref rView));
516 HIViewConvertPoint (ref hiPoint, pView, rView);
517 if (mouseInWindow != rView && grabWindow != IntPtr.Zero) {
518 msg.hwnd = mouseInWindow;
519 msg.message = Msg.WM_MOUSE_LEAVE;
520 carbonEvents.Enqueue (msg);
522 msg.message = Msg.WM_MOUSE_ENTER;
523 carbonEvents.Enqueue (msg);
524 mouseInWindow = rView;
527 if (grabWindow == IntPtr.Zero)
530 msg.hwnd = grabWindow;
531 msg.message = Msg.WM_MOUSEMOVE;
532 msg.lParam = (IntPtr) ((ushort)hiPoint.y << 16 | (ushort)hiPoint.x);
533 msg.wParam = GetMousewParam (0);
534 mouse_position.X = (int)hiPoint.x;
535 mouse_position.Y = (int)hiPoint.y;
536 carbonEvents.Enqueue (msg);
540 Console.WriteLine (eventKind);
546 msg.message = Msg.WM_ENTERIDLE;
547 carbonEvents.Enqueue (msg);
551 internal int ViewHandler (IntPtr inCallRef, IntPtr inEvent, IntPtr controlHnd) {
552 int eventClass = GetEventClass (inEvent);
553 int eventKind = GetEventKind (inEvent);
554 MSG msg = new MSG ();
555 msg.hwnd = controlHnd;
556 lock (carbonEvents) {
557 switch (eventClass) {
561 if (handle_data [controlHnd] == null)
562 handle_data [controlHnd] = new HandleData ();
563 HIRect bounds = new HIRect ();
564 HIViewGetBounds (controlHnd, ref bounds);
565 ((HandleData) handle_data [controlHnd]).AddToInvalidArea ((int)bounds.origin.x, (int)bounds.origin.y, (int)bounds.size.width, (int)bounds.size.height);
566 msg.message = Msg.WM_PAINT;
567 msg.wParam = IntPtr.Zero;
568 msg.lParam = IntPtr.Zero;
569 DispatchMessage (ref msg);
570 //// carbonEvents.Enqueue (msg);
576 msg.message = Msg.WM_ENTERIDLE;
577 carbonEvents.Enqueue (msg);
583 //FIXME: If there are timers; we can loop really hard churning cpu
584 internal override bool GetMessage(ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
585 IntPtr evtRef = IntPtr.Zero;
586 IntPtr target = GetEventDispatcherTarget();
587 CheckTimers (DateTime.Now);
588 ReceiveNextEvent (0, IntPtr.Zero, 0, true, ref evtRef);
589 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
590 SendEventToEventTarget (evtRef, target);
591 ReleaseEvent (evtRef);
594 lock (carbonEvents) {
595 if (carbonEvents.Count <= 0) {
597 Idle (this, EventArgs.Empty);
598 else if (timer_list.Count == 0) {
599 ReceiveNextEvent (0, IntPtr.Zero, 0x7FFFFFFF, true, ref evtRef);
600 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
601 SendEventToEventTarget (evtRef, target);
602 ReleaseEvent (evtRef);
605 msg.hwnd = IntPtr.Zero;
606 msg.message = Msg.WM_ENTERIDLE;
609 msg = (MSG) carbonEvents.Dequeue ();
614 internal override bool TranslateMessage(ref MSG msg) {
618 internal override IntPtr DispatchMessage(ref MSG msg) {
619 return NativeWindow.WndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
623 internal override bool SetZOrder(IntPtr hWnd, IntPtr AfterhWnd, bool Top, bool Bottom) {
624 throw new NotImplementedException ();
628 internal override bool SetTopmost(IntPtr hWnd, IntPtr hWndOwner, bool Enabled) {
633 internal override bool Text(IntPtr handle, string text) {
634 // FIXME: We need to set the window as well if this is the root control.
635 if (view_window_mapping [handle] != null) {
636 CheckError (SetWindowTitleWithCFString ((IntPtr)(view_window_mapping [handle]), __CFStringMakeConstantString (text)));
638 CheckError (SetControlTitleWithCFString (handle, __CFStringMakeConstantString (text)));
643 internal override bool GetText(IntPtr handle, out string text) {
644 throw new NotImplementedException ();
647 internal override bool SetVisible(IntPtr handle, bool visible) {
648 // We dont have "windows" on OSX, we have views; so we toggle the view visibility here
649 HandleData data = (HandleData) handle_data [handle];
652 data = new HandleData ();
653 handle_data [handle] = data;
655 if (view_window_mapping [handle] != null && visible == true) {
656 ShowWindow ((IntPtr) view_window_mapping [handle]);
658 if (view_window_mapping [handle] != null && visible == false) {
659 HideWindow ((IntPtr) view_window_mapping [handle]);
661 data.IsVisible = visible;
663 CheckError (HIViewSetVisible (handle, visible));
664 // We have to manually reset all children as well
669 internal override bool IsVisible(IntPtr handle) {
670 HandleData data = (HandleData) handle_data [handle];
672 if (data == null || data.IsVisible == true) {
678 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
679 if (HIViewGetSuperview (handle) != IntPtr.Zero)
680 CheckError (HIViewRemoveFromSuperview (handle), "HIViewRemoveFromSuperview ()");
681 HIViewAddSubview (parent, handle);
682 SetVisible (handle, IsVisible (parent));
686 internal override IntPtr GetParent(IntPtr handle) {
687 return HIViewGetSuperview (handle);
691 internal override void GrabWindow(IntPtr hWnd, IntPtr confine_hwnd) {
696 internal override void GrabInfo(out IntPtr hWnd, out bool GrabConfined, out Rectangle GrabArea) {
697 throw new NotImplementedException ();
700 internal override void ReleaseWindow(IntPtr hWnd) {
701 grabWindow = IntPtr.Zero;
704 internal override bool CalculateWindowRect(IntPtr hWnd, ref Rectangle ClientRect, int Style, bool HasMenu, out Rectangle WindowRect) {
705 WindowRect = new Rectangle(ClientRect.Left, ClientRect.Top, ClientRect.Width, ClientRect.Height);
710 internal override void SetCursorPos(IntPtr handle, int x, int y) {
711 throw new NotImplementedException ();
714 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
715 x = mouse_position.X;
716 y = mouse_position.Y;
720 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y) {
721 // throw new NotImplementedException ();
725 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
726 // throw new NotImplementedException ();
730 internal override void SendAsyncMethod (AsyncMethodData method) {
731 throw new NotImplementedException ();
734 private IntPtr GetMousewParam(int Delta) {
737 if ((mouse_state & MouseButtons.Left) != 0) {
738 result |= (int)MsgButtons.MK_LBUTTON;
741 if ((mouse_state & MouseButtons.Middle) != 0) {
742 result |= (int)MsgButtons.MK_MBUTTON;
745 if ((mouse_state & MouseButtons.Right) != 0) {
746 result |= (int)MsgButtons.MK_RBUTTON;
749 return (IntPtr)result;
752 private void CheckTimers (DateTime now)
755 int count = timer_list.Count;
758 for (int i = 0; i < timer_list.Count; i++) {
759 Timer timer = (Timer) timer_list [i];
760 if (timer.Enabled && timer.Expires <= now) {
768 internal override void SetTimer (Timer timer) {
770 timer_list.Add (timer);
774 internal override void KillTimer (Timer timer)
777 timer_list.Remove (timer);
782 internal override void CreateCaret(IntPtr hwnd, int width, int height) {
786 internal override void DestroyCaret(IntPtr hwnd) {
790 internal override void SetCaretPos(IntPtr hwnd, int x, int y) {
794 internal override void CaretVisible(IntPtr hwnd, bool visible) {
799 internal override int KeyboardSpeed {
801 throw new NotImplementedException ();
806 internal override int KeyboardDelay {
808 throw new NotImplementedException ();
812 internal void CheckError (int result, string error) {
814 throw new Exception ("XplatUIOSX.cs::" + error + "() Carbon subsystem threw an error: " + result);
816 internal void CheckError (int result) {
818 throw new Exception ("XplatUIOSX.cs::Carbon subsystem threw an error: " + result);
821 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
822 internal static extern int HIViewGetSubviewHit (IntPtr contentView, ref CGPoint point, bool tval, ref IntPtr outPtr);
823 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
824 internal static extern int HIViewConvertPoint (ref CGPoint point, IntPtr pView, IntPtr cView);
825 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
826 internal static extern int HIViewChangeFeatures (IntPtr aView, ulong bitsin, ulong bitsout);
827 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
828 internal static extern int HIViewFindByID (IntPtr rootWnd, HIViewID id, ref IntPtr outPtr);
829 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
830 internal static extern IntPtr HIViewGetRoot (IntPtr hWnd);
831 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
832 internal static extern int HIObjectCreate (IntPtr cfStr, uint what, ref IntPtr hwnd);
833 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
834 internal static extern int HIViewSetNeedsDisplay (IntPtr viewHnd, bool update);
835 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
836 internal static extern int HIViewGetFrame (IntPtr viewHnd, ref HIRect rect);
837 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
838 internal static extern int HIViewSetFrame (IntPtr viewHnd, ref HIRect rect);
839 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
840 internal static extern int HIViewPlaceInSuperviewAt (IntPtr view, float x, float y);
841 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
842 internal static extern int HIViewAddSubview (IntPtr parentHnd, IntPtr childHnd);
843 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
844 internal static extern IntPtr HIViewGetNextView (IntPtr aView);
845 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
846 internal static extern IntPtr HIViewGetPreviousView (IntPtr aView);
847 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
848 internal static extern IntPtr HIViewGetSuperview (IntPtr aView);
849 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
850 internal static extern int HIViewRemoveFromSuperview (IntPtr aView);
851 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
852 internal static extern int HIViewSetVisible (IntPtr vHnd, bool visible);
853 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
854 internal static extern bool HIViewIsVisible (IntPtr vHnd);
855 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
856 internal static extern int HIViewGetBounds (IntPtr vHnd, ref HIRect r);
858 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
859 internal static extern void SetRect (ref IntPtr r, short left, short top, short right, short bottom);
861 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
862 static extern int CreateEvent (IntPtr allocator, uint classid, uint kind, double when, uint attributes, ref IntPtr outEvent);
863 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
864 static extern int InstallEventHandler (IntPtr window, CarbonEventHandler handlerProc, uint numtypes, EventTypeSpec [] typeList, IntPtr userData, IntPtr handlerRef);
865 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
866 internal static extern IntPtr GetWindowEventTarget (IntPtr window);
867 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
868 internal static extern IntPtr GetControlEventTarget (IntPtr aControl);
869 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
870 internal static extern IntPtr GetEventDispatcherTarget ();
871 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
872 internal static extern int SendEventToEventTarget (IntPtr evt, IntPtr target);
873 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
874 internal static extern int ReleaseEvent (IntPtr evt);
875 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
876 internal static extern int ReceiveNextEvent (uint evtCount, IntPtr evtTypes, double timeout, bool processEvt, ref IntPtr evt);
877 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
878 static extern int GetEventClass (IntPtr eventRef);
879 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
880 static extern int GetEventKind (IntPtr eventRef);
881 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
882 static extern int GetEventParameter (IntPtr evt, uint inName, uint inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref IntPtr outData);
883 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
884 static extern int GetEventParameter (IntPtr evt, uint inName, uint inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref ushort outData);
885 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
886 static extern int GetEventParameter (IntPtr evt, uint inName, uint inType, IntPtr outActualType, uint bufSize, IntPtr outActualSize, ref QDPoint outData);
888 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
889 static extern int SetPortWindowPort (IntPtr hWnd);
890 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
891 static extern int GlobalToLocal (ref QDPoint outData);
893 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
894 internal static extern int CreateNewWindow (int klass, uint attributes, ref IntPtr r, ref IntPtr window);
895 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
896 internal static extern int ShowWindow (IntPtr wHnd);
897 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
898 internal static extern int HideWindow (IntPtr wHnd);
899 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
900 internal static extern int SetWindowBounds (IntPtr wHnd, uint reg, ref IntPtr rect);
901 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
902 internal static extern int GetWindowBounds (IntPtr wHnd, uint reg, ref Rect rect);
904 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
905 internal static extern int SetControlTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
906 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
907 internal static extern int SetWindowTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
908 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
909 internal static extern IntPtr __CFStringMakeConstantString (string cString);
911 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
912 internal static extern void CGContextRestoreGState (IntPtr ctx);
913 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
914 internal static extern void CGContextSaveGState (IntPtr ctx);
915 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
916 internal static extern void CGContextTranslateCTM (IntPtr ctx, double tx, double ty);
917 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
918 internal static extern void CGContextScaleCTM (IntPtr ctx, double tx, double ty);
920 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
921 static extern int SetWindowContentColor (IntPtr hWnd, ref RGBColor backColor);
924 internal struct CGSize {
928 public CGSize (int w, int h) {
929 this.width = (float)w;
930 this.height = (float)h;
934 internal struct QDPoint {
938 public QDPoint (short x, short y) {
943 internal struct CGPoint {
947 public CGPoint (int x, int y) {
953 internal struct HIRect {
954 public CGPoint origin;
957 public HIRect (int x, int y, int w, int h) {
958 this.origin = new CGPoint (x, y);
959 this.size = new CGSize (w, h);
963 internal struct HIViewID {
967 public HIViewID (uint type, uint id) {
973 internal struct EventTypeSpec
975 public UInt32 eventClass;
976 public UInt32 eventKind;
978 public EventTypeSpec (UInt32 eventClass, UInt32 eventKind)
980 this.eventClass = eventClass;
981 this.eventKind = eventKind;
985 internal struct CarbonEvent
990 public CarbonEvent (IntPtr hWnd, IntPtr evt)
997 internal struct RGBColor
1004 internal struct Rect
1008 public short bottom;