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-2007 Novell, Inc.
23 // Geoff Norton <gnorton@novell.com>
28 using System.Threading;
30 using System.ComponentModel;
31 using System.Collections;
32 using System.Diagnostics;
33 using System.Runtime.InteropServices;
35 using Carbon = System.Windows.Forms.CarbonInternal;
38 namespace System.Windows.Forms {
39 internal delegate Rectangle [] HwndDelegate (IntPtr handle);
41 internal class XplatUICarbon : XplatUIDriver {
42 #region Local Variables
43 // General driver variables
44 private static XplatUICarbon Instance;
45 private static int RefCount;
46 private static bool themes_enabled;
48 // Internal members available to the event handler sub-system
49 internal static IntPtr FocusWindow;
50 internal static IntPtr ActiveWindow;
51 internal static IntPtr ReverseWindow;
52 internal static IntPtr CaretWindow;
54 internal static Hwnd MouseHwnd;
56 internal static MouseButtons MouseState;
57 internal static Carbon.Hover Hover;
59 internal static HwndDelegate HwndDelegate = new HwndDelegate (GetClippingRectangles);
61 internal Point mouse_position;
64 internal Carbon.ApplicationHandler ApplicationHandler;
65 internal Carbon.ControlHandler ControlHandler;
66 internal Carbon.HIObjectHandler HIObjectHandler;
67 internal Carbon.KeyboardHandler KeyboardHandler;
68 internal Carbon.MouseHandler MouseHandler;
69 internal Carbon.WindowHandler WindowHandler;
72 internal static GrabStruct Grab;
73 private static Carbon.Caret Caret;
74 private static Carbon.Dnd Dnd;
75 private static Hashtable WindowMapping;
76 private static Hashtable HandleMapping;
77 private static IntPtr FosterParent;
78 private static IntPtr Subclass;
79 private static int MenuBarHeight;
80 internal static ArrayList UtilityWindows;
83 private static Queue MessageQueue;
84 private static bool GetMessageResult;
86 private static bool ReverseWindowMapped;
89 private ArrayList TimerList;
91 static readonly object instancelock = new object ();
92 static readonly object queuelock = new object ();
95 internal override event EventHandler Idle;
99 private XplatUICarbon() {
102 TimerList = new ArrayList ();
103 MessageQueue = new Queue ();
109 // FIXME: Clean up the FosterParent here.
113 #region Singleton specific code
114 public static XplatUICarbon GetInstance() {
115 lock (instancelock) {
116 if (Instance == null) {
117 Instance = new XplatUICarbon ();
124 public int Reference {
131 #region Internal methods
132 internal void AddExpose (Hwnd hwnd, bool client, Carbon.HIRect rect) {
133 AddExpose (hwnd, client, (int) rect.origin.x, (int) rect.origin.y, (int) rect.size.width, (int) rect.size.height);
136 internal void AddExpose (Hwnd hwnd, bool client, Rectangle rect) {
137 AddExpose (hwnd, client, (int) rect.X, (int) rect.Y, (int) rect.Width, (int) rect.Height);
140 internal void FlushQueue () {
141 CheckTimers (DateTime.UtcNow);
142 while (MessageQueue.Count > 0) {
143 object queueobj = MessageQueue.Dequeue ();
144 if (queueobj is GCHandle) {
145 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)queueobj);
147 MSG msg = (MSG)queueobj;
148 NativeWindow.WndProc (msg.hwnd, msg.message, msg.wParam, msg.lParam);
153 internal static Rectangle [] GetClippingRectangles (IntPtr handle) {
154 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
158 if (hwnd.Handle != handle)
159 return new Rectangle [] {hwnd.ClientRect};
161 return (Rectangle []) hwnd.GetClippingRectangles ().ToArray (typeof (Rectangle));
164 internal IntPtr GetMousewParam(int Delta) {
167 if ((MouseState & MouseButtons.Left) != 0) {
168 result |= (int)MsgButtons.MK_LBUTTON;
171 if ((MouseState & MouseButtons.Middle) != 0) {
172 result |= (int)MsgButtons.MK_MBUTTON;
175 if ((MouseState & MouseButtons.Right) != 0) {
176 result |= (int)MsgButtons.MK_RBUTTON;
179 Keys mods = ModifierKeys;
180 if ((mods & Keys.Control) != 0) {
181 result |= (int)MsgButtons.MK_CONTROL;
184 if ((mods & Keys.Shift) != 0) {
185 result |= (int)MsgButtons.MK_SHIFT;
188 result |= Delta << 16;
190 return (IntPtr)result;
193 internal IntPtr HandleToWindow (IntPtr handle) {
194 if (HandleMapping [handle] != null)
195 return (IntPtr) HandleMapping [handle];
199 internal void Initialize () {
200 // Initialize the event handlers
201 Carbon.EventHandler.Driver = this;
202 ApplicationHandler = new Carbon.ApplicationHandler (this);
203 ControlHandler = new Carbon.ControlHandler (this);
204 HIObjectHandler = new Carbon.HIObjectHandler (this);
205 KeyboardHandler = new Carbon.KeyboardHandler (this);
206 MouseHandler = new Carbon.MouseHandler (this);
207 WindowHandler = new Carbon.WindowHandler (this);
209 // Initilize the mouse controls
210 Hover.Interval = 500;
211 Hover.Timer = new Timer ();
212 Hover.Timer.Enabled = false;
213 Hover.Timer.Interval = Hover.Interval;
214 Hover.Timer.Tick += new EventHandler (HoverCallback);
217 MouseState = MouseButtons.None;
218 mouse_position = Point.Empty;
220 // Initialize the Caret
221 Caret.Timer = new Timer ();
222 Caret.Timer.Interval = 500;
223 Caret.Timer.Tick += new EventHandler (CaretCallback);
225 // Initialize the D&D
226 Dnd = new Carbon.Dnd ();
228 // Initialize the Carbon Specific stuff
229 WindowMapping = new Hashtable ();
230 HandleMapping = new Hashtable ();
231 UtilityWindows = new ArrayList ();
233 // Initialize the FosterParent
234 Carbon.Rect rect = new Carbon.Rect ();
235 SetRect (ref rect, (short)0, (short)0, (short)0, (short)0);
236 Carbon.ProcessSerialNumber psn = new Carbon.ProcessSerialNumber();
238 GetCurrentProcess( ref psn );
239 TransformProcessType (ref psn, 1);
240 SetFrontProcess (ref psn);
242 HIObjectRegisterSubclass (__CFStringMakeConstantString ("com.novell.mwfview"), __CFStringMakeConstantString ("com.apple.hiview"), 0, Carbon.EventHandler.EventHandlerDelegate, (uint)Carbon.EventHandler.HIObjectEvents.Length, Carbon.EventHandler.HIObjectEvents, IntPtr.Zero, ref Subclass);
244 Carbon.EventHandler.InstallApplicationHandler ();
246 CreateNewWindow (Carbon.WindowClass.kDocumentWindowClass, Carbon.WindowAttributes.kWindowStandardHandlerAttribute | Carbon.WindowAttributes.kWindowCloseBoxAttribute | Carbon.WindowAttributes.kWindowFullZoomAttribute | Carbon.WindowAttributes.kWindowCollapseBoxAttribute | Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowCompositingAttribute, ref rect, ref FosterParent);
248 CreateNewWindow (Carbon.WindowClass.kOverlayWindowClass, Carbon.WindowAttributes.kWindowNoUpdatesAttribute | Carbon.WindowAttributes.kWindowNoActivatesAttribute, ref rect, ref ReverseWindow);
249 CreateNewWindow (Carbon.WindowClass.kOverlayWindowClass, Carbon.WindowAttributes.kWindowNoUpdatesAttribute | Carbon.WindowAttributes.kWindowNoActivatesAttribute, ref rect, ref CaretWindow);
251 // Get some values about bar heights
252 Carbon.Rect structRect = new Carbon.Rect ();
253 Carbon.Rect contentRect = new Carbon.Rect ();
254 GetWindowBounds (FosterParent, 32, ref structRect);
255 GetWindowBounds (FosterParent, 33, ref contentRect);
257 MenuBarHeight = GetMBarHeight ();
260 FocusWindow = IntPtr.Zero;
263 GetMessageResult = true;
265 ReverseWindowMapped = false;
268 internal void PerformNCCalc(Hwnd hwnd) {
269 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
273 rect = new Rectangle (0, 0, hwnd.Width, hwnd.Height);
275 ncp = new XplatUIWin32.NCCALCSIZE_PARAMS();
276 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ncp));
278 ncp.rgrc1.left = rect.Left;
279 ncp.rgrc1.top = rect.Top;
280 ncp.rgrc1.right = rect.Right;
281 ncp.rgrc1.bottom = rect.Bottom;
283 Marshal.StructureToPtr(ncp, ptr, true);
284 NativeWindow.WndProc(hwnd.client_window, Msg.WM_NCCALCSIZE, (IntPtr)1, ptr);
285 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(ptr, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
286 Marshal.FreeHGlobal(ptr);
289 rect = new Rectangle(ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right - ncp.rgrc1.left, ncp.rgrc1.bottom - ncp.rgrc1.top);
290 hwnd.ClientRect = rect;
292 rect = TranslateClientRectangleToQuartzClientRectangle (hwnd);
295 Carbon.HIRect r = new Carbon.HIRect (rect.X, rect.Y, rect.Width, rect.Height);
296 HIViewSetFrame (hwnd.client_window, ref r);
299 AddExpose (hwnd, false, 0, 0, hwnd.Width, hwnd.Height);
302 internal void ScreenToClient(IntPtr handle, ref Carbon.QDPoint point) {
303 int x = (int) point.x;
304 int y = (int) point.y;
306 ScreenToClient (handle, ref x, ref y);
312 internal static Rectangle TranslateClientRectangleToQuartzClientRectangle (Hwnd hwnd) {
313 return TranslateClientRectangleToQuartzClientRectangle (hwnd, Control.FromHandle (hwnd.Handle));
316 internal static Rectangle TranslateClientRectangleToQuartzClientRectangle (Hwnd hwnd, Control ctrl) {
318 * If this is a form with no window manager, X is handling all the border and caption painting
319 * so remove that from the area (since the area we set of the window here is the part of the window
320 * we're painting in only)
322 Rectangle rect = hwnd.ClientRect;
323 Form form = ctrl as Form;
324 CreateParams cp = null;
327 cp = form.GetCreateParams ();
329 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
330 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
331 Rectangle qrect = rect;
333 qrect.Y -= borders.top;
334 qrect.X -= borders.left;
335 qrect.Width += borders.left + borders.right;
336 qrect.Height += borders.top + borders.bottom;
341 if (rect.Width < 1 || rect.Height < 1) {
351 internal static Size TranslateWindowSizeToQuartzWindowSize (CreateParams cp) {
352 return TranslateWindowSizeToQuartzWindowSize (cp, new Size (cp.Width, cp.Height));
355 internal static Size TranslateWindowSizeToQuartzWindowSize (CreateParams cp, Size size) {
357 * If this is a form with no window manager, X is handling all the border and caption painting
358 * so remove that from the area (since the area we set of the window here is the part of the window
359 * we're painting in only)
361 Form form = cp.control as Form;
362 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
363 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
366 qsize.Width -= borders.left + borders.right;
367 qsize.Height -= borders.top + borders.bottom;
372 if (size.Height == 0)
379 internal static Size TranslateQuartzWindowSizeToWindowSize (CreateParams cp, int width, int height) {
381 * If this is a form with no window manager, X is handling all the border and caption painting
382 * so remove that from the area (since the area we set of the window here is the part of the window
383 * we're painting in only)
385 Size size = new Size (width, height);
386 Form form = cp.control as Form;
387 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
388 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
391 qsize.Width += borders.left + borders.right;
392 qsize.Height += borders.top + borders.bottom;
402 private void CaretCallback (object sender, EventArgs e) {
414 private void HoverCallback (object sender, EventArgs e) {
415 if ((Hover.X == mouse_position.X) && (Hover.Y == mouse_position.Y)) {
416 MSG msg = new MSG ();
417 msg.hwnd = Hover.Hwnd;
418 msg.message = Msg.WM_MOUSEHOVER;
419 msg.wParam = GetMousewParam (0);
420 msg.lParam = (IntPtr)((ushort)Hover.X << 16 | (ushort)Hover.X);
421 MessageQueue.Enqueue (msg);
426 #region Private Methods
427 private Point ConvertScreenPointToClient (IntPtr handle, Point point) {
428 Point converted_point = new Point ();
429 Carbon.Rect window_bounds = new Carbon.Rect ();
430 Carbon.CGPoint native_point = new Carbon.CGPoint ();
432 GetWindowBounds (HIViewGetWindow (handle), 32, ref window_bounds);
434 native_point.x = (point.X - window_bounds.left);
435 native_point.y = (point.Y - window_bounds.top);
437 HIViewConvertPoint (ref native_point, IntPtr.Zero, handle);
439 converted_point.X = (int)native_point.x;
440 converted_point.Y = (int)native_point.y;
442 return converted_point;
445 private Point ConvertClientPointToScreen (IntPtr handle, Point point) {
446 Point converted_point = new Point ();
447 Carbon.Rect window_bounds = new Carbon.Rect ();
448 Carbon.CGPoint native_point = new Carbon.CGPoint ();
450 GetWindowBounds (HIViewGetWindow (handle), 32, ref window_bounds);
452 native_point.x = point.X;
453 native_point.y = point.Y;
455 HIViewConvertPoint (ref native_point, handle, IntPtr.Zero);
457 converted_point.X = (int)(native_point.x + window_bounds.left);
458 converted_point.Y = (int)(native_point.y + window_bounds.top);
460 return converted_point;
463 private double NextTimeout () {
464 DateTime now = DateTime.UtcNow;
465 int timeout = 0x7FFFFFF;
467 foreach (Timer timer in TimerList) {
468 int next = (int) (timer.Expires - now).TotalMilliseconds;
475 if (timeout < Timer.Minimum)
476 timeout = Timer.Minimum;
478 return (double)((double)timeout/1000);
481 private void CheckTimers (DateTime now) {
483 int count = TimerList.Count;
486 for (int i = 0; i < TimerList.Count; i++) {
487 Timer timer = (Timer) TimerList [i];
488 if (timer.Enabled && timer.Expires <= now) {
496 private void WaitForHwndMessage (Hwnd hwnd, Msg message) {
497 MSG msg = new MSG ();
501 if (GetMessage(null, ref msg, IntPtr.Zero, 0, 0)) {
502 if ((Msg)msg.message == Msg.WM_QUIT) {
507 if (msg.hwnd == hwnd.Handle) {
508 if ((Msg)msg.message == message)
510 else if ((Msg)msg.message == Msg.WM_DESTROY)
514 TranslateMessage (ref msg);
515 DispatchMessage (ref msg);
521 private void SendParentNotify(IntPtr child, Msg cause, int x, int y) {
524 if (child == IntPtr.Zero) {
528 hwnd = Hwnd.GetObjectFromWindow (child);
534 if (hwnd.Handle == IntPtr.Zero) {
538 if (ExStyleSet ((int) hwnd.initial_ex_style, WindowExStyles.WS_EX_NOPARENTNOTIFY)) {
542 if (hwnd.Parent == null) {
546 if (hwnd.Parent.Handle == IntPtr.Zero) {
550 if (cause == Msg.WM_CREATE || cause == Msg.WM_DESTROY) {
551 SendMessage(hwnd.Parent.Handle, Msg.WM_PARENTNOTIFY, Control.MakeParam((int)cause, 0), child);
553 SendMessage(hwnd.Parent.Handle, Msg.WM_PARENTNOTIFY, Control.MakeParam((int)cause, 0), Control.MakeParam(x, y));
556 SendParentNotify (hwnd.Parent.Handle, cause, x, y);
559 private bool StyleSet (int s, WindowStyles ws) {
560 return (s & (int)ws) == (int)ws;
563 private bool ExStyleSet (int ex, WindowExStyles exws) {
564 return (ex & (int)exws) == (int)exws;
567 private void DeriveStyles(int Style, int ExStyle, out FormBorderStyle border_style, out bool border_static, out TitleStyle title_style, out int caption_height, out int tool_caption_height) {
570 tool_caption_height = 0;
571 border_static = false;
573 if (StyleSet (Style, WindowStyles.WS_CHILD)) {
574 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_CLIENTEDGE)) {
575 border_style = FormBorderStyle.Fixed3D;
576 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_STATICEDGE)) {
577 border_style = FormBorderStyle.Fixed3D;
578 border_static = true;
579 } else if (!StyleSet (Style, WindowStyles.WS_BORDER)) {
580 border_style = FormBorderStyle.None;
582 border_style = FormBorderStyle.FixedSingle;
584 title_style = TitleStyle.None;
586 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
588 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
589 title_style = TitleStyle.Tool;
591 title_style = TitleStyle.Normal;
595 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_MDICHILD)) {
598 if (StyleSet (Style, WindowStyles.WS_OVERLAPPEDWINDOW) ||
599 ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
600 border_style = (FormBorderStyle) 0xFFFF;
602 border_style = FormBorderStyle.None;
607 title_style = TitleStyle.None;
608 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
609 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
610 title_style = TitleStyle.Tool;
612 title_style = TitleStyle.Normal;
616 border_style = FormBorderStyle.None;
618 if (StyleSet (Style, WindowStyles.WS_THICKFRAME)) {
619 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
620 border_style = FormBorderStyle.SizableToolWindow;
622 border_style = FormBorderStyle.Sizable;
625 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
626 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_CLIENTEDGE)) {
627 border_style = FormBorderStyle.Fixed3D;
628 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_STATICEDGE)) {
629 border_style = FormBorderStyle.Fixed3D;
630 border_static = true;
631 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_DLGMODALFRAME)) {
632 border_style = FormBorderStyle.FixedDialog;
633 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
634 border_style = FormBorderStyle.FixedToolWindow;
635 } else if (StyleSet (Style, WindowStyles.WS_BORDER)) {
636 border_style = FormBorderStyle.FixedSingle;
639 if (StyleSet (Style, WindowStyles.WS_BORDER)) {
640 border_style = FormBorderStyle.FixedSingle;
647 private void SetHwndStyles(Hwnd hwnd, CreateParams cp) {
648 DeriveStyles(cp.Style, cp.ExStyle, out hwnd.border_style, out hwnd.border_static, out hwnd.title_style, out hwnd.caption_height, out hwnd.tool_caption_height);
651 private void ShowCaret () {
655 ShowWindow (CaretWindow);
656 Graphics g = Graphics.FromHwnd (HIViewGetRoot (CaretWindow));
658 g.FillRectangle (new SolidBrush (Color.Black), new Rectangle (0, 0, Caret.Width, Caret.Height));
663 private void HideCaret () {
667 HideWindow (CaretWindow);
670 private void AccumulateDestroyedHandles (Control c, ArrayList list) {
672 Control[] controls = c.Controls.GetAllControls ();
674 if (c.IsHandleCreated && !c.IsDisposed) {
675 Hwnd hwnd = Hwnd.ObjectFromHandle(c.Handle);
678 CleanupCachedWindows (hwnd);
681 for (int i = 0; i < controls.Length; i ++) {
682 AccumulateDestroyedHandles (controls[i], list);
688 private void CleanupCachedWindows (Hwnd hwnd) {
689 if (ActiveWindow == hwnd.Handle) {
690 SendMessage(hwnd.client_window, Msg.WM_ACTIVATE, (IntPtr)WindowActiveFlags.WA_INACTIVE, IntPtr.Zero);
691 ActiveWindow = IntPtr.Zero;
694 if (FocusWindow == hwnd.Handle) {
695 SendMessage(hwnd.client_window, Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
696 FocusWindow = IntPtr.Zero;
699 if (Grab.Hwnd == hwnd.Handle) {
700 Grab.Hwnd = IntPtr.Zero;
701 Grab.Confined = false;
704 DestroyCaret (hwnd.Handle);
707 private void AddExpose (Hwnd hwnd, bool client, int x, int y, int width, int height) {
709 if ((hwnd == null) || (x > hwnd.Width) || (y > hwnd.Height) || ((x + width) < 0) || ((y + height) < 0)) {
713 // Keep the invalid area as small as needed
714 if ((x + width) > hwnd.width) {
715 width = hwnd.width - x;
718 if ((y + height) > hwnd.height) {
719 height = hwnd.height - y;
723 hwnd.AddInvalidArea(x, y, width, height);
724 if (!hwnd.expose_pending && hwnd.visible) {
725 MSG msg = new MSG ();
726 msg.message = Msg.WM_PAINT;
727 msg.hwnd = hwnd.Handle;
728 MessageQueue.Enqueue (msg);
729 hwnd.expose_pending = true;
732 hwnd.AddNcInvalidArea (x, y, width, height);
733 if (!hwnd.nc_expose_pending && hwnd.visible) {
734 MSG msg = new MSG ();
735 Region rgn = new Region (hwnd.Invalid);
736 IntPtr hrgn = rgn.GetHrgn (null); // Graphics object isn't needed
737 msg.message = Msg.WM_NCPAINT;
738 msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
740 msg.hwnd = hwnd.Handle;
741 MessageQueue.Enqueue (msg);
742 hwnd.nc_expose_pending = true;
749 #region Public Methods
750 internal void EnqueueMessage (MSG msg) {
752 MessageQueue.Enqueue (msg);
756 internal override void RaiseIdle (EventArgs e)
762 internal override IntPtr InitializeDriver() {
766 internal override void ShutdownDriver(IntPtr token) {
769 internal override void EnableThemes() {
770 themes_enabled = true;
773 internal override void Activate(IntPtr handle) {
774 ActivateWindow (HIViewGetWindow (handle), true);
777 internal override void AudibleAlert() {
778 throw new NotImplementedException();
781 internal override void CaretVisible (IntPtr hwnd, bool visible) {
782 if (Caret.Hwnd == hwnd) {
784 if (Caret.Visible < 1) {
787 if (Caret.Visible == 1) {
789 Caret.Timer.Start ();
794 if (Caret.Visible == 0) {
802 internal override bool CalculateWindowRect(ref Rectangle ClientRect, CreateParams cp, Menu menu, out Rectangle WindowRect) {
803 WindowRect = Hwnd.GetWindowRectangle (cp, menu, ClientRect);
807 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
808 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
810 Point point = ConvertClientPointToScreen (hwnd.ClientWindow, new Point (x, y));
816 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
817 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
819 Point point = ConvertClientPointToScreen (hwnd.ClientWindow, new Point (x, y));
825 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
826 ArrayList list = new ArrayList ();
827 DataFormats.Format f = DataFormats.Format.List;
834 return (int [])list.ToArray (typeof (int));
837 internal override void ClipboardClose(IntPtr handle) {
840 //TODO: Map our internal formats to the right os code where we can
841 internal override int ClipboardGetID(IntPtr handle, string format) {
842 return (int)__CFStringMakeConstantString (format);
845 internal override IntPtr ClipboardOpen(bool primary_selection) {
846 if (primary_selection)
847 return Carbon.Pasteboard.Primary;
848 return Carbon.Pasteboard.Application;
851 internal override object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
852 return Carbon.Pasteboard.Retrieve (handle, type);
855 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
856 Carbon.Pasteboard.Store (handle, obj, type);
859 internal override void CreateCaret (IntPtr hwnd, int width, int height) {
860 if (Caret.Hwnd != IntPtr.Zero)
861 DestroyCaret (Caret.Hwnd);
865 Caret.Height = height;
870 internal override IntPtr CreateWindow(CreateParams cp) {
872 Hwnd parent_hwnd = null;
881 IntPtr WholeWindowTracking;
882 IntPtr ClientWindowTracking;
890 ParentHandle = IntPtr.Zero;
891 WindowHandle = IntPtr.Zero;
892 WholeWindow = IntPtr.Zero;
893 ClientWindow = IntPtr.Zero;
894 WholeWindowTracking = IntPtr.Zero;
895 ClientWindowTracking = IntPtr.Zero;
897 if (Width < 1) Width = 1;
898 if (Height < 1) Height = 1;
900 if (cp.Parent != IntPtr.Zero) {
901 parent_hwnd = Hwnd.ObjectFromHandle (cp.Parent);
902 ParentHandle = parent_hwnd.client_window;
904 if (StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
905 HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
910 if (cp.control is Form) {
911 next = Hwnd.GetNextStackedFormLocation (cp, parent_hwnd);
919 hwnd.height = Height;
920 hwnd.Parent = Hwnd.ObjectFromHandle (cp.Parent);
921 hwnd.initial_style = cp.WindowStyle;
922 hwnd.initial_ex_style = cp.WindowExStyle;
923 hwnd.visible = false;
925 if (StyleSet (cp.Style, WindowStyles.WS_DISABLED)) {
926 hwnd.enabled = false;
929 ClientWindow = IntPtr.Zero;
931 Size QWindowSize = TranslateWindowSizeToQuartzWindowSize (cp);
932 Rectangle QClientRect = TranslateClientRectangleToQuartzClientRectangle (hwnd, cp.control);
934 SetHwndStyles(hwnd, cp);
936 if (ParentHandle == IntPtr.Zero) {
937 IntPtr WindowView = IntPtr.Zero;
938 IntPtr GrowBox = IntPtr.Zero;
939 Carbon.WindowClass windowklass = Carbon.WindowClass.kOverlayWindowClass;
940 Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
941 if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZEBOX)) {
942 attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
944 if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZEBOX)) {
945 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
947 if (StyleSet (cp.Style, WindowStyles.WS_SYSMENU)) {
948 attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
950 if (StyleSet (cp.Style, WindowStyles.WS_CAPTION)) {
951 windowklass = Carbon.WindowClass.kDocumentWindowClass;
953 if (hwnd.border_style == FormBorderStyle.FixedToolWindow) {
954 windowklass = Carbon.WindowClass.kUtilityWindowClass;
955 } else if (hwnd.border_style == FormBorderStyle.SizableToolWindow) {
956 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute;
957 windowklass = Carbon.WindowClass.kUtilityWindowClass;
959 if (windowklass == Carbon.WindowClass.kOverlayWindowClass) {
960 attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
962 attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;
964 Carbon.Rect rect = new Carbon.Rect ();
965 if (StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
966 SetRect (ref rect, (short)X, (short)(Y), (short)(X + QWindowSize.Width), (short)(Y + QWindowSize.Height));
968 SetRect (ref rect, (short)X, (short)(Y + MenuBarHeight), (short)(X + QWindowSize.Width), (short)(Y + MenuBarHeight + QWindowSize.Height));
971 CreateNewWindow (windowklass, attributes, ref rect, ref WindowHandle);
973 Carbon.EventHandler.InstallWindowHandler (WindowHandle);
974 HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref WindowView);
975 HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 7), ref GrowBox);
976 HIGrowBoxViewSetTransparent (GrowBox, true);
977 SetAutomaticControlDragTrackingEnabledForWindow (WindowHandle, true);
978 ParentHandle = WindowView;
981 HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref WholeWindow);
982 HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref ClientWindow);
984 Carbon.EventHandler.InstallControlHandler (WholeWindow);
985 Carbon.EventHandler.InstallControlHandler (ClientWindow);
987 // Enable embedding on controls
988 HIViewChangeFeatures (WholeWindow, 1<<1, 0);
989 HIViewChangeFeatures (ClientWindow, 1<<1, 0);
991 HIViewNewTrackingArea (WholeWindow, IntPtr.Zero, (UInt64)WholeWindow, ref WholeWindowTracking);
992 HIViewNewTrackingArea (ClientWindow, IntPtr.Zero, (UInt64)ClientWindow, ref ClientWindowTracking);
993 Carbon.HIRect WholeRect;
994 if (WindowHandle != IntPtr.Zero) {
995 WholeRect = new Carbon.HIRect (0, 0, QWindowSize.Width, QWindowSize.Height);
997 WholeRect = new Carbon.HIRect (X, Y, QWindowSize.Width, QWindowSize.Height);
999 Carbon.HIRect ClientRect = new Carbon.HIRect (QClientRect.X, QClientRect.Y, QClientRect.Width, QClientRect.Height);
1000 HIViewSetFrame (WholeWindow, ref WholeRect);
1001 HIViewSetFrame (ClientWindow, ref ClientRect);
1003 HIViewAddSubview (ParentHandle, WholeWindow);
1004 HIViewAddSubview (WholeWindow, ClientWindow);
1006 hwnd.WholeWindow = WholeWindow;
1007 hwnd.ClientWindow = ClientWindow;
1009 if (WindowHandle != IntPtr.Zero) {
1010 WindowMapping [hwnd.Handle] = WindowHandle;
1011 HandleMapping [WindowHandle] = hwnd.Handle;
1012 if (hwnd.border_style == FormBorderStyle.FixedToolWindow || hwnd.border_style == FormBorderStyle.SizableToolWindow) {
1013 UtilityWindows.Add (WindowHandle);
1017 // Allow dnd on controls
1018 Dnd.SetAllowDrop (hwnd, true);
1020 Text (hwnd.Handle, cp.Caption);
1022 SendMessage (hwnd.Handle, Msg.WM_CREATE, (IntPtr)1, IntPtr.Zero /* XXX unused */);
1023 SendParentNotify (hwnd.Handle, Msg.WM_CREATE, int.MaxValue, int.MaxValue);
1025 if (StyleSet (cp.Style, WindowStyles.WS_VISIBLE) || StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
1026 if (WindowHandle != IntPtr.Zero) {
1027 if (Control.FromHandle(hwnd.Handle) is Form) {
1028 Form f = Control.FromHandle(hwnd.Handle) as Form;
1029 if (f.WindowState == FormWindowState.Normal) {
1030 SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
1033 IntPtr active = GetActive ();
1034 ShowWindow (WindowHandle);
1035 WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
1036 if (active != IntPtr.Zero)
1039 HIViewSetVisible (WholeWindow, true);
1040 HIViewSetVisible (ClientWindow, true);
1041 hwnd.visible = true;
1042 if (!(Control.FromHandle(hwnd.Handle) is Form)) {
1043 SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
1047 if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZE)) {
1048 SetWindowState(hwnd.Handle, FormWindowState.Minimized);
1049 } else if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZE)) {
1050 SetWindowState(hwnd.Handle, FormWindowState.Maximized);
1056 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
1057 CreateParams create_params = new CreateParams();
1059 create_params.Caption = "";
1060 create_params.X = X;
1061 create_params.Y = Y;
1062 create_params.Width = Width;
1063 create_params.Height = Height;
1065 create_params.ClassName=XplatUI.DefaultClassName;
1066 create_params.ClassStyle = 0;
1067 create_params.ExStyle=0;
1068 create_params.Parent=IntPtr.Zero;
1069 create_params.Param=0;
1071 return CreateWindow(create_params);
1074 internal override Bitmap DefineStdCursorBitmap (StdCursor id) {
1075 return Carbon.Cursor.DefineStdCursorBitmap (id);
1078 internal override IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
1079 return Carbon.Cursor.DefineCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
1082 internal override IntPtr DefineStdCursor (StdCursor id) {
1083 return Carbon.Cursor.DefineStdCursor (id);
1086 internal override IntPtr DefWndProc(ref Message msg) {
1087 Hwnd hwnd = Hwnd.ObjectFromHandle (msg.HWnd);
1088 switch ((Msg)msg.Msg) {
1090 if (WindowMapping [hwnd.Handle] != null)
1095 case Msg.WM_PAINT: {
1096 hwnd.expose_pending = false;
1099 case Msg.WM_NCPAINT: {
1100 hwnd.nc_expose_pending = false;
1103 case Msg.WM_NCCALCSIZE: {
1104 if (msg.WParam == (IntPtr)1) {
1105 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1106 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure (msg.LParam, typeof (XplatUIWin32.NCCALCSIZE_PARAMS));
1108 // Add all the stuff X is supposed to draw.
1109 Control ctrl = Control.FromHandle (hwnd.Handle);
1111 Hwnd.Borders rect = Hwnd.GetBorders (ctrl.GetCreateParams (), null);
1113 ncp.rgrc1.top += rect.top;
1114 ncp.rgrc1.bottom -= rect.bottom;
1115 ncp.rgrc1.left += rect.left;
1116 ncp.rgrc1.right -= rect.right;
1118 Marshal.StructureToPtr (ncp, msg.LParam, true);
1123 case Msg.WM_SETCURSOR: {
1124 // Pass to parent window first
1125 while ((hwnd.parent != null) && (msg.Result == IntPtr.Zero)) {
1127 msg.Result = NativeWindow.WndProc(hwnd.Handle, Msg.WM_SETCURSOR, msg.HWnd, msg.LParam);
1130 if (msg.Result == IntPtr.Zero) {
1133 switch((HitTest)(msg.LParam.ToInt32() & 0xffff)) {
1134 case HitTest.HTBOTTOM: handle = Cursors.SizeNS.handle; break;
1135 case HitTest.HTBORDER: handle = Cursors.SizeNS.handle; break;
1136 case HitTest.HTBOTTOMLEFT: handle = Cursors.SizeNESW.handle; break;
1137 case HitTest.HTBOTTOMRIGHT: handle = Cursors.SizeNWSE.handle; break;
1138 case HitTest.HTERROR: if ((msg.LParam.ToInt32() >> 16) == (int)Msg.WM_LBUTTONDOWN) {
1139 //FIXME: AudibleAlert();
1141 handle = Cursors.Default.handle;
1144 case HitTest.HTHELP: handle = Cursors.Help.handle; break;
1145 case HitTest.HTLEFT: handle = Cursors.SizeWE.handle; break;
1146 case HitTest.HTRIGHT: handle = Cursors.SizeWE.handle; break;
1147 case HitTest.HTTOP: handle = Cursors.SizeNS.handle; break;
1148 case HitTest.HTTOPLEFT: handle = Cursors.SizeNWSE.handle; break;
1149 case HitTest.HTTOPRIGHT: handle = Cursors.SizeNESW.handle; break;
1152 case HitTest.HTGROWBOX:
1153 case HitTest.HTSIZE:
1154 case HitTest.HTZOOM:
1155 case HitTest.HTVSCROLL:
1156 case HitTest.HTSYSMENU:
1157 case HitTest.HTREDUCE:
1158 case HitTest.HTNOWHERE:
1159 case HitTest.HTMAXBUTTON:
1160 case HitTest.HTMINBUTTON:
1161 case HitTest.HTMENU:
1162 case HitTest.HSCROLL:
1163 case HitTest.HTBOTTOM:
1164 case HitTest.HTCAPTION:
1165 case HitTest.HTCLIENT:
1166 case HitTest.HTCLOSE:
1168 default: handle = Cursors.Default.handle; break;
1170 SetCursor(msg.HWnd, handle);
1178 internal override void DestroyCaret (IntPtr hwnd) {
1179 if (Caret.Hwnd == hwnd) {
1180 if (Caret.Visible == 1) {
1181 Caret.Timer.Stop ();
1184 Caret.Hwnd = IntPtr.Zero;
1191 internal override void DestroyCursor(IntPtr cursor) {
1192 throw new NotImplementedException ();
1195 internal override void DestroyWindow(IntPtr handle) {
1198 hwnd = Hwnd.ObjectFromHandle(handle);
1204 SendParentNotify (hwnd.Handle, Msg.WM_DESTROY, int.MaxValue, int.MaxValue);
1206 CleanupCachedWindows (hwnd);
1208 ArrayList windows = new ArrayList ();
1210 AccumulateDestroyedHandles (Control.ControlNativeWindow.ControlFromHandle(hwnd.Handle), windows);
1213 foreach (Hwnd h in windows) {
1214 SendMessage (h.Handle, Msg.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
1218 // TODO: This is crashing swf-messageboxes
1220 if (false && hwnd.whole_window != IntPtr.Zero)
1221 CFRelease (hwnd.whole_window);
1222 if (false && hwnd.client_window != IntPtr.Zero)
1223 CFRelease (hwnd.client_window);
1226 if (WindowMapping [hwnd.Handle] != null) {
1227 DisposeWindow ((IntPtr)(WindowMapping [hwnd.Handle]));
1228 WindowMapping.Remove (hwnd.Handle);
1232 internal override IntPtr DispatchMessage(ref MSG msg) {
1233 return NativeWindow.WndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
1236 internal override void DoEvents() {
1239 internal override void EnableWindow(IntPtr handle, bool Enable) {
1240 //Like X11 we need not do anything here
1243 internal override void EndLoop(Thread thread) {
1246 internal void Exit () {
1247 GetMessageResult = false;
1250 internal override IntPtr GetActive() {
1251 foreach (DictionaryEntry entry in WindowMapping)
1252 if (IsWindowActive ((IntPtr)(entry.Value)))
1253 return (IntPtr)(entry.Key);
1258 internal override Region GetClipRegion(IntPtr hwnd) {
1263 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1270 internal override void GetDisplaySize(out Size size) {
1271 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1272 size = new Size ((int)bounds.size.width, (int)bounds.size.height);
1275 internal override IntPtr GetParent(IntPtr handle) {
1278 hwnd = Hwnd.ObjectFromHandle(handle);
1279 if (hwnd != null && hwnd.Parent != null) {
1280 return hwnd.Parent.Handle;
1285 internal override IntPtr GetPreviousWindow(IntPtr handle) {
1286 return HIViewGetPreviousView(handle);
1289 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1290 Carbon.QDPoint pt = new Carbon.QDPoint ();
1291 GetGlobalMouse (ref pt);
1296 internal override IntPtr GetFocus() {
1301 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1302 FontFamily ff = font.FontFamily;
1303 ascent = ff.GetCellAscent (font.Style);
1304 descent = ff.GetCellDescent (font.Style);
1308 internal override Point GetMenuOrigin(IntPtr handle) {
1311 hwnd = Hwnd.ObjectFromHandle(handle);
1314 return hwnd.MenuOrigin;
1319 internal override bool GetMessage(object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1320 IntPtr evtRef = IntPtr.Zero;
1321 IntPtr target = GetEventDispatcherTarget();
1322 CheckTimers (DateTime.UtcNow);
1323 ReceiveNextEvent (0, IntPtr.Zero, 0, true, ref evtRef);
1324 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1325 SendEventToEventTarget (evtRef, target);
1326 ReleaseEvent (evtRef);
1332 if (MessageQueue.Count <= 0) {
1334 Idle (this, EventArgs.Empty);
1335 else if (TimerList.Count == 0) {
1336 ReceiveNextEvent (0, IntPtr.Zero, Convert.ToDouble ("0." + Timer.Minimum), true, ref evtRef);
1337 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1338 SendEventToEventTarget (evtRef, target);
1339 ReleaseEvent (evtRef);
1342 ReceiveNextEvent (0, IntPtr.Zero, NextTimeout (), true, ref evtRef);
1343 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1344 SendEventToEventTarget (evtRef, target);
1345 ReleaseEvent (evtRef);
1348 msg.hwnd = IntPtr.Zero;
1349 msg.message = Msg.WM_ENTERIDLE;
1350 return GetMessageResult;
1352 object queueobj = MessageQueue.Dequeue ();
1353 if (queueobj is GCHandle) {
1354 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)queueobj);
1357 msg = (MSG)queueobj;
1360 return GetMessageResult;
1364 internal override bool GetText(IntPtr handle, out string text) {
1365 throw new NotImplementedException ();
1368 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) {
1371 hwnd = Hwnd.ObjectFromHandle(handle);
1377 height = hwnd.height;
1379 PerformNCCalc(hwnd);
1381 client_width = hwnd.ClientRect.Width;
1382 client_height = hwnd.ClientRect.Height;
1387 // Should we throw an exception or fail silently?
1388 // throw new ArgumentException("Called with an invalid window handle", "handle");
1398 internal override FormWindowState GetWindowState(IntPtr hwnd) {
1399 IntPtr window = HIViewGetWindow (hwnd);
1401 if (IsWindowCollapsed (window))
1402 return FormWindowState.Minimized;
1403 if (IsWindowInStandardState (window, IntPtr.Zero, IntPtr.Zero))
1404 return FormWindowState.Maximized;
1406 return FormWindowState.Normal;
1409 internal override void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
1411 GrabConfined = Grab.Confined;
1412 GrabArea = Grab.Area;
1415 internal override void GrabWindow(IntPtr handle, IntPtr confine_to_handle) {
1417 Grab.Confined = confine_to_handle != IntPtr.Zero;
1418 /* FIXME: Set the Grab.Area */
1421 internal override void UngrabWindow(IntPtr hwnd) {
1422 bool was_grabbed = Grab.Hwnd != IntPtr.Zero;
1424 Grab.Hwnd = IntPtr.Zero;
1425 Grab.Confined = false;
1428 // lparam should be the handle to the window gaining the mouse capture,
1429 // but we dont have that information like X11.
1430 // Also only generate WM_CAPTURECHANGED if the window actually was grabbed.
1431 SendMessage (hwnd, Msg.WM_CAPTURECHANGED, IntPtr.Zero, IntPtr.Zero);
1435 internal override void HandleException(Exception e) {
1436 StackTrace st = new StackTrace(e);
1437 Console.WriteLine("Exception '{0}'", e.Message+st.ToString());
1438 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1441 internal override void Invalidate (IntPtr handle, Rectangle rc, bool clear) {
1444 hwnd = Hwnd.ObjectFromHandle(handle);
1447 AddExpose (hwnd, true, hwnd.X, hwnd.Y, hwnd.Width, hwnd.Height);
1449 AddExpose (hwnd, true, rc.X, rc.Y, rc.Width, rc.Height);
1453 internal override void InvalidateNC (IntPtr handle)
1457 hwnd = Hwnd.ObjectFromHandle(handle);
1459 AddExpose (hwnd, false, 0, 0, hwnd.Width, hwnd.Height);
1462 internal override bool IsEnabled(IntPtr handle) {
1463 return Hwnd.ObjectFromHandle(handle).Enabled;
1466 internal override bool IsVisible(IntPtr handle) {
1467 return Hwnd.ObjectFromHandle(handle).visible;
1470 internal override void KillTimer(Timer timer) {
1472 TimerList.Remove(timer);
1477 internal override void OverrideCursor(IntPtr cursor) {
1480 internal override PaintEventArgs PaintEventStart(ref Message msg, IntPtr handle, bool client) {
1481 PaintEventArgs paint_event;
1485 hwnd = Hwnd.ObjectFromHandle(msg.HWnd);
1486 if (msg.HWnd == handle) {
1489 paint_hwnd = Hwnd.ObjectFromHandle (handle);
1492 if (Caret.Visible == 1) {
1493 Caret.Paused = true;
1500 dc = Graphics.FromHwnd (paint_hwnd.client_window);
1502 Region clip_region = new Region ();
1503 clip_region.MakeEmpty();
1505 foreach (Rectangle r in hwnd.ClipRectangles) {
1506 clip_region.Union (r);
1509 if (hwnd.UserClip != null) {
1510 clip_region.Intersect(hwnd.UserClip);
1513 // FIXME: Clip region is hosed
1514 dc.Clip = clip_region;
1515 paint_event = new PaintEventArgs(dc, hwnd.Invalid);
1516 hwnd.expose_pending = false;
1517 hwnd.ClearInvalidArea();
1519 hwnd.drawing_stack.Push (paint_event);
1520 hwnd.drawing_stack.Push (dc);
1522 dc = Graphics.FromHwnd (paint_hwnd.whole_window);
1524 if (!hwnd.nc_invalid.IsEmpty) {
1525 // FIXME: Clip region is hosed
1526 dc.SetClip (hwnd.nc_invalid);
1527 paint_event = new PaintEventArgs(dc, hwnd.nc_invalid);
1529 paint_event = new PaintEventArgs(dc, new Rectangle(0, 0, hwnd.width, hwnd.height));
1531 hwnd.nc_expose_pending = false;
1532 hwnd.ClearNcInvalidArea ();
1534 hwnd.drawing_stack.Push (paint_event);
1535 hwnd.drawing_stack.Push (dc);
1541 internal override void PaintEventEnd(ref Message msg, IntPtr handle, bool client) {
1544 hwnd = Hwnd.ObjectFromHandle(handle);
1546 // FIXME: Pop is causing invalid stack ops sometimes; race condition?
1548 Graphics dc = (Graphics)hwnd.drawing_stack.Pop();
1552 PaintEventArgs pe = (PaintEventArgs)hwnd.drawing_stack.Pop();
1553 pe.SetGraphics (null);
1557 if (Caret.Visible == 1) {
1559 Caret.Paused = false;
1563 internal override bool PeekMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1567 internal override bool PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
1568 MSG msg = new MSG();
1570 msg.message = message;
1571 msg.wParam = wParam;
1572 msg.lParam = lParam;
1573 MessageQueue.Enqueue (msg);
1577 internal override void PostQuitMessage(int exitCode) {
1578 PostMessage (FosterParent, Msg.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
1581 internal override void RequestAdditionalWM_NCMessages(IntPtr hwnd, bool hover, bool leave) {
1584 internal override void RequestNCRecalc(IntPtr handle) {
1587 hwnd = Hwnd.ObjectFromHandle(handle);
1593 PerformNCCalc(hwnd);
1594 SendMessage(handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1595 InvalidateNC(handle);
1599 internal override void ResetMouseHover(IntPtr handle) {
1600 throw new NotImplementedException();
1603 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y) {
1604 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1606 Point point = ConvertScreenPointToClient (hwnd.ClientWindow, new Point (x, y));
1612 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
1613 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1615 Point point = ConvertScreenPointToClient (hwnd.WholeWindow, new Point (x, y));
1621 internal override void ScrollWindow(IntPtr handle, Rectangle area, int XAmount, int YAmount, bool clear) {
1622 Carbon.HIRect scroll_rect = new Carbon.HIRect ();
1623 scroll_rect.origin.x = area.X;
1624 scroll_rect.origin.y = area.Y;
1625 scroll_rect.size.width = area.Width;
1626 scroll_rect.size.height = area.Height;
1627 HIViewScrollRect (handle, ref scroll_rect, (float)XAmount, (float)YAmount);
1631 internal override void ScrollWindow(IntPtr hwnd, int XAmount, int YAmount, bool clear) {
1632 Carbon.HIRect scroll_rect = new Carbon.HIRect ();
1634 HIViewGetBounds (hwnd, ref scroll_rect);
1635 HIViewScrollRect (hwnd, ref scroll_rect, (float)XAmount, (float)YAmount);
1639 internal override void SendAsyncMethod (AsyncMethodData method) {
1641 MessageQueue.Enqueue (GCHandle.Alloc (method));
1645 internal override IntPtr SendMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
1646 return NativeWindow.WndProc(hwnd, message, wParam, lParam);
1649 internal override int SendInput(IntPtr hwnd, Queue keys) {
1654 internal override void SetCaretPos (IntPtr hwnd, int x, int y) {
1655 if (Caret.Hwnd == hwnd) {
1656 ClientToScreen (hwnd, ref x, ref y);
1657 SizeWindow (new Rectangle (x, y, Caret.Width, Caret.Height), CaretWindow);
1658 Caret.Timer.Stop ();
1662 if (Caret.Visible == 1) {
1664 Caret.Timer.Start ();
1669 internal override void SetClipRegion(IntPtr hwnd, Region region) {
1670 throw new NotImplementedException();
1673 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1674 Hwnd hwnd = Hwnd.ObjectFromHandle (window);
1676 hwnd.Cursor = cursor;
1679 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1680 CGDisplayMoveCursorToPoint (CGMainDisplayID (), new Carbon.CGPoint (x, y));
1683 internal override void SetFocus(IntPtr handle) {
1684 if (FocusWindow != IntPtr.Zero) {
1685 PostMessage(FocusWindow, Msg.WM_KILLFOCUS, handle, IntPtr.Zero);
1687 PostMessage(handle, Msg.WM_SETFOCUS, FocusWindow, IntPtr.Zero);
1688 FocusWindow = handle;
1691 internal override void SetIcon(IntPtr handle, Icon icon) {
1692 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1694 // FIXME: we need to map the icon for active window switches
1695 if (WindowMapping [hwnd.Handle] != null) {
1697 RestoreApplicationDockTileImage ();
1704 bitmap = new Bitmap (128, 128);
1705 using (Graphics g = Graphics.FromImage (bitmap)) {
1706 g.DrawImage (icon.ToBitmap (), 0, 0, 128, 128);
1709 size = bitmap.Width * bitmap.Height;
1710 data = new IntPtr[size];
1712 for (int y = 0; y < bitmap.Height; y++) {
1713 for (int x = 0; x < bitmap.Width; x++) {
1714 int pixel = bitmap.GetPixel (x, y).ToArgb ();
1715 if (BitConverter.IsLittleEndian) {
1716 byte a = (byte) ((pixel >> 24) & 0xFF);
1717 byte r = (byte) ((pixel >> 16) & 0xFF);
1718 byte g = (byte) ((pixel >> 8) & 0xFF);
1719 byte b = (byte) (pixel & 0xFF);
1720 data[index++] = (IntPtr)(a + (r << 8) + (g << 16) + (b << 24));
1722 data[index++] = (IntPtr)pixel;
1727 IntPtr provider = CGDataProviderCreateWithData (IntPtr.Zero, data, size*4, IntPtr.Zero);
1728 IntPtr image = CGImageCreate (128, 128, 8, 32, 4*128, CGColorSpaceCreateDeviceRGB (), 4, provider, IntPtr.Zero, 0, 0);
1729 SetApplicationDockTileImage (image);
1735 internal override void SetModal(IntPtr handle, bool Modal) {
1736 IntPtr hWnd = HIViewGetWindow (Hwnd.ObjectFromHandle (handle).WholeWindow);
1738 BeginAppModalStateForWindow (hWnd);
1740 EndAppModalStateForWindow (hWnd);
1744 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1745 IntPtr ParentHandle = IntPtr.Zero;
1746 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1748 hwnd.Parent = Hwnd.ObjectFromHandle (parent);
1749 if (HIViewGetSuperview (hwnd.whole_window) != IntPtr.Zero) {
1750 HIViewRemoveFromSuperview (hwnd.whole_window);
1752 if (hwnd.parent == null)
1753 HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
1754 HIViewAddSubview (hwnd.parent == null ? ParentHandle : hwnd.Parent.client_window, hwnd.whole_window);
1755 HIViewPlaceInSuperviewAt (hwnd.whole_window, hwnd.X, hwnd.Y);
1756 HIViewAddSubview (hwnd.whole_window, hwnd.client_window);
1757 HIViewPlaceInSuperviewAt (hwnd.client_window, hwnd.ClientRect.X, hwnd.ClientRect.Y);
1762 internal override void SetTimer (Timer timer) {
1764 TimerList.Add (timer);
1768 internal override bool SetTopmost(IntPtr hWnd, bool Enabled) {
1769 HIViewSetZOrder (hWnd, 1, IntPtr.Zero);
1773 internal override bool SetOwner(IntPtr hWnd, IntPtr hWndOwner) {
1774 // TODO: Set window owner.
1778 internal override bool SetVisible(IntPtr handle, bool visible, bool activate) {
1779 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1780 object window = WindowMapping [hwnd.Handle];
1783 ShowWindow ((IntPtr)window);
1785 HideWindow ((IntPtr)window);
1788 SendMessage(handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1790 HIViewSetVisible (hwnd.whole_window, visible);
1791 HIViewSetVisible (hwnd.client_window, visible);
1793 hwnd.visible = visible;
1798 internal override void SetAllowDrop (IntPtr handle, bool value) {
1799 // Like X11 we allow drop on al windows and filter in our handler
1802 internal override DragDropEffects StartDrag (IntPtr handle, object data, DragDropEffects allowed_effects) {
1803 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1806 throw new ArgumentException ("Attempt to begin drag from invalid window handle (" + handle.ToInt32 () + ").");
1808 return Dnd.StartDrag (hwnd.client_window, data, allowed_effects);
1811 internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
1812 Form form = Control.FromHandle (handle) as Form;
1813 if (form != null && form.window_manager == null && (border_style == FormBorderStyle.FixedToolWindow ||
1814 border_style == FormBorderStyle.SizableToolWindow)) {
1815 form.window_manager = new ToolWindowManager (form);
1818 RequestNCRecalc(handle);
1821 internal override void SetMenu(IntPtr handle, Menu menu) {
1824 hwnd = Hwnd.ObjectFromHandle(handle);
1827 RequestNCRecalc(handle);
1830 internal override void SetWindowMinMax(IntPtr handle, Rectangle maximized, Size min, Size max) {
1833 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1834 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1840 // Win32 automatically changes negative width/height to 0.
1846 // X requires a sanity check for width & height; otherwise it dies
1847 if (hwnd.zero_sized && width > 0 && height > 0) {
1849 HIViewSetVisible(hwnd.WholeWindow, true);
1851 hwnd.zero_sized = false;
1854 if ((width < 1) || (height < 1)) {
1855 hwnd.zero_sized = true;
1856 HIViewSetVisible(hwnd.WholeWindow, false);
1859 // Save a server roundtrip (and prevent a feedback loop)
1860 if ((hwnd.x == x) && (hwnd.y == y) && (hwnd.width == width) && (hwnd.height == height)) {
1864 if (!hwnd.zero_sized) {
1868 hwnd.height = height;
1869 SendMessage(hwnd.client_window, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1871 Control ctrl = Control.FromHandle (handle);
1872 Size TranslatedSize = TranslateWindowSizeToQuartzWindowSize (ctrl.GetCreateParams (), new Size (width, height));
1873 Carbon.Rect rect = new Carbon.Rect ();
1875 if (WindowMapping [hwnd.Handle] != null) {
1876 SetRect (ref rect, (short)x, (short)(y+MenuBarHeight), (short)(x+TranslatedSize.Width), (short)(y+MenuBarHeight+TranslatedSize.Height));
1877 SetWindowBounds ((IntPtr) WindowMapping [hwnd.Handle], 33, ref rect);
1878 Carbon.HIRect frame_rect = new Carbon.HIRect (0, 0, TranslatedSize.Width, TranslatedSize.Height);
1879 HIViewSetFrame (hwnd.whole_window, ref frame_rect);
1881 Carbon.HIRect frame_rect = new Carbon.HIRect (x, y, TranslatedSize.Width, TranslatedSize.Height);
1882 HIViewSetFrame (hwnd.whole_window, ref frame_rect);
1884 PerformNCCalc(hwnd);
1890 hwnd.height = height;
1893 internal override void SetWindowState(IntPtr handle, FormWindowState state) {
1894 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1895 IntPtr window = HIViewGetWindow (handle);
1898 case FormWindowState.Minimized: {
1899 CollapseWindow (window, true);
1902 case FormWindowState.Normal: {
1903 ZoomWindow (window, 7, false);
1906 case FormWindowState.Maximized: {
1907 Form form = Control.FromHandle (hwnd.Handle) as Form;
1908 if (form != null && form.FormBorderStyle == FormBorderStyle.None) {
1909 Carbon.Rect rect = new Carbon.Rect ();
1910 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1911 SetRect (ref rect, (short)0, (short)0, (short)bounds.size.width, (short)bounds.size.height);
1912 SetWindowBounds ((IntPtr) WindowMapping [hwnd.Handle], 33, ref rect);
1913 HIViewSetFrame (hwnd.whole_window, ref bounds);
1915 ZoomWindow (window, 8, false);
1922 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1923 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1924 SetHwndStyles(hwnd, cp);
1926 if (WindowMapping [hwnd.Handle] != null) {
1927 Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
1928 if ((cp.Style & ((int)WindowStyles.WS_MINIMIZEBOX)) != 0) {
1929 attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
1931 if ((cp.Style & ((int)WindowStyles.WS_MAXIMIZEBOX)) != 0) {
1932 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
1934 if ((cp.Style & ((int)WindowStyles.WS_SYSMENU)) != 0) {
1935 attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
1937 if ((cp.ExStyle & ((int)WindowExStyles.WS_EX_TOOLWINDOW)) != 0) {
1938 attributes = Carbon.WindowAttributes.kWindowStandardHandlerAttribute | Carbon.WindowAttributes.kWindowCompositingAttribute;
1940 attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;
1942 Carbon.WindowAttributes outAttributes = Carbon.WindowAttributes.kWindowNoAttributes;
1943 GetWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], ref outAttributes);
1944 ChangeWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], attributes, outAttributes);
1948 internal override void SetWindowTransparency(IntPtr handle, double transparency, Color key) {
1951 internal override double GetWindowTransparency(IntPtr handle)
1956 internal override TransparencySupport SupportsTransparency() {
1957 return TransparencySupport.None;
1960 internal override bool SetZOrder(IntPtr handle, IntPtr after_handle, bool Top, bool Bottom) {
1961 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1964 HIViewSetZOrder (hwnd.whole_window, 2, IntPtr.Zero);
1966 } else if (!Bottom) {
1967 Hwnd after_hwnd = Hwnd.ObjectFromHandle (after_handle);
1968 HIViewSetZOrder (hwnd.whole_window, 2, after_hwnd.whole_window);
1970 HIViewSetZOrder (hwnd.whole_window, 1, IntPtr.Zero);
1976 internal override void ShowCursor(bool show) {
1978 CGDisplayShowCursor (CGMainDisplayID ());
1980 CGDisplayHideCursor (CGMainDisplayID ());
1983 internal override object StartLoop(Thread thread) {
1984 return new object ();
1988 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
1989 throw new NotImplementedException();
1993 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
1994 throw new NotImplementedException();
1998 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
1999 throw new NotImplementedException();
2004 internal override void SystrayBalloon(IntPtr hwnd, int timeout, string title, string text, ToolTipIcon icon)
2006 throw new NotImplementedException ();
2010 internal override bool Text(IntPtr handle, string text) {
2011 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
2012 if (WindowMapping [hwnd.Handle] != null) {
2013 SetWindowTitleWithCFString ((IntPtr)(WindowMapping [hwnd.Handle]), __CFStringMakeConstantString (text));
2015 SetControlTitleWithCFString (hwnd.whole_window, __CFStringMakeConstantString (text));
2016 SetControlTitleWithCFString (hwnd.client_window, __CFStringMakeConstantString (text));
2020 internal override void UpdateWindow(IntPtr handle) {
2023 hwnd = Hwnd.ObjectFromHandle(handle);
2025 if (!hwnd.visible || !HIViewIsVisible (handle)) {
2029 SendMessage(handle, Msg.WM_PAINT, IntPtr.Zero, IntPtr.Zero);
2032 internal override bool TranslateMessage(ref MSG msg) {
2033 return Carbon.EventHandler.TranslateMessage (ref msg);
2036 #region Reversible regions
2038 * Quartz has no concept of XOR drawing due to its compositing nature
2039 * We fake this by mapping a overlay window on the first draw and mapping it on the second.
2040 * This has some issues with it because its POSSIBLE for ControlPaint.DrawReversible* to actually
2041 * reverse two regions at once. We dont do this in MWF, but this behaviour woudn't work.
2042 * We could in theory cache the Rectangle/Color combination to handle this behaviour.
2044 * PROBLEMS: This has some flicker / banding
2046 internal void SizeWindow (Rectangle rect, IntPtr window) {
2047 Carbon.Rect qrect = new Carbon.Rect ();
2049 SetRect (ref qrect, (short)rect.X, (short)rect.Y, (short)(rect.X+rect.Width), (short)(rect.Y+rect.Height));
2051 SetWindowBounds (window, 33, ref qrect);
2054 internal override void DrawReversibleLine(Point start, Point end, Color backColor) {
2055 // throw new NotImplementedException();
2058 internal override void FillReversibleRectangle (Rectangle rectangle, Color backColor) {
2059 // throw new NotImplementedException();
2062 internal override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
2063 // throw new NotImplementedException();
2066 internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
2067 Rectangle size_rect = rect;
2071 if (ReverseWindowMapped) {
2072 HideWindow (ReverseWindow);
2073 ReverseWindowMapped = false;
2075 ClientToScreen(handle, ref new_x, ref new_y);
2077 size_rect.X += new_x;
2078 size_rect.Y += new_y;
2080 SizeWindow (size_rect, ReverseWindow);
2081 ShowWindow (ReverseWindow);
2088 Graphics g = Graphics.FromHwnd (HIViewGetRoot (ReverseWindow));
2090 for (int i = 0; i < line_width; i++) {
2091 g.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (Color.Black), rect);
2101 ReverseWindowMapped = true;
2106 internal override SizeF GetAutoScaleSize(Font font) {
2109 string magic_string = "The quick brown fox jumped over the lazy dog.";
2110 double magic_number = 44.549996948242189;
2112 g = Graphics.FromImage (new Bitmap (1, 1));
2114 width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
2115 return new SizeF(width, font.Height);
2118 internal override Point MousePosition {
2120 return mouse_position;
2125 #region System information
2126 internal override int KeyboardSpeed { get{ throw new NotImplementedException(); } }
2127 internal override int KeyboardDelay { get{ throw new NotImplementedException(); } }
2129 internal override int CaptionHeight {
2135 internal override Size CursorSize { get{ throw new NotImplementedException(); } }
2136 internal override bool DragFullWindows { get{ throw new NotImplementedException(); } }
2137 internal override Size DragSize {
2139 return new Size(4, 4);
2143 internal override Size FrameBorderSize {
2145 return new Size (2, 2);
2149 internal override Size IconSize { get{ throw new NotImplementedException(); } }
2150 internal override Size MaxWindowTrackSize { get{ throw new NotImplementedException(); } }
2151 internal override bool MenuAccessKeysUnderlined {
2156 internal override Size MinimizedWindowSize { get{ throw new NotImplementedException(); } }
2157 internal override Size MinimizedWindowSpacingSize { get{ throw new NotImplementedException(); } }
2159 internal override Size MinimumWindowSize {
2161 return new Size(110, 22);
2165 internal override Size MinWindowTrackSize { get{ throw new NotImplementedException(); } }
2167 internal override Keys ModifierKeys {
2169 return KeyboardHandler.ModifierKeys;
2172 internal override Size SmallIconSize { get{ throw new NotImplementedException(); } }
2173 internal override int MouseButtonCount { get{ throw new NotImplementedException(); } }
2174 internal override bool MouseButtonsSwapped { get{ throw new NotImplementedException(); } }
2175 internal override bool MouseWheelPresent { get{ throw new NotImplementedException(); } }
2177 internal override Rectangle VirtualScreen {
2183 internal override Rectangle WorkingArea {
2185 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
2186 return new Rectangle ((int)bounds.origin.x, (int)bounds.origin.y, (int)bounds.size.width, (int)bounds.size.height);
2189 internal override bool ThemesEnabled {
2191 return XplatUICarbon.themes_enabled;
2198 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2199 extern static int HIViewConvertPoint (ref Carbon.CGPoint point, IntPtr pView, IntPtr cView);
2200 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2201 extern static int HIViewChangeFeatures (IntPtr aView, ulong bitsin, ulong bitsout);
2202 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2203 extern static int HIViewFindByID (IntPtr rootWnd, Carbon.HIViewID id, ref IntPtr outPtr);
2204 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2205 extern static int HIGrowBoxViewSetTransparent (IntPtr GrowBox, bool transparency);
2206 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2207 extern static IntPtr HIViewGetRoot (IntPtr hWnd);
2208 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2209 extern static int HIObjectCreate (IntPtr cfStr, uint what, ref IntPtr hwnd);
2210 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2211 extern static int HIObjectRegisterSubclass (IntPtr classid, IntPtr superclassid, uint options, Carbon.EventDelegate upp, uint count, Carbon.EventTypeSpec [] list, IntPtr state, ref IntPtr cls);
2212 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2213 extern static int HIViewPlaceInSuperviewAt (IntPtr view, float x, float y);
2214 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2215 extern static int HIViewAddSubview (IntPtr parentHnd, IntPtr childHnd);
2216 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2217 extern static IntPtr HIViewGetPreviousView (IntPtr aView);
2218 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2219 extern static IntPtr HIViewGetSuperview (IntPtr aView);
2220 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2221 extern static int HIViewRemoveFromSuperview (IntPtr aView);
2222 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2223 extern static int HIViewSetVisible (IntPtr vHnd, bool visible);
2224 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2225 extern static bool HIViewIsVisible (IntPtr vHnd);
2226 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2227 extern static int HIViewGetBounds (IntPtr vHnd, ref Carbon.HIRect r);
2228 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2229 extern static int HIViewScrollRect (IntPtr vHnd, ref Carbon.HIRect rect, float x, float y);
2230 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2231 extern static int HIViewSetZOrder (IntPtr hWnd, int cmd, IntPtr oHnd);
2232 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2233 extern static int HIViewNewTrackingArea (IntPtr inView, IntPtr inShape, UInt64 inID, ref IntPtr outRef);
2234 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2235 extern static IntPtr HIViewGetWindow (IntPtr aView);
2236 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2237 extern static int HIViewSetFrame (IntPtr view_handle, ref Carbon.HIRect bounds);
2238 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2239 internal extern static int HIViewSetNeedsDisplayInRect (IntPtr view_handle, ref Carbon.HIRect rect, bool needs_display);
2241 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2242 extern static void SetRect (ref Carbon.Rect r, short left, short top, short right, short bottom);
2243 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2244 static extern int ActivateWindow (IntPtr windowHnd, bool inActivate);
2245 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2246 static extern bool IsWindowActive (IntPtr windowHnd);
2247 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2248 static extern int SetAutomaticControlDragTrackingEnabledForWindow (IntPtr window, bool enabled);
2250 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2251 extern static IntPtr GetEventDispatcherTarget ();
2252 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2253 extern static int SendEventToEventTarget (IntPtr evt, IntPtr target);
2254 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2255 extern static int ReleaseEvent (IntPtr evt);
2256 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2257 extern static int ReceiveNextEvent (uint evtCount, IntPtr evtTypes, double timeout, bool processEvt, ref IntPtr evt);
2259 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2260 extern static bool IsWindowCollapsed (IntPtr hWnd);
2261 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2262 extern static bool IsWindowInStandardState (IntPtr hWnd, IntPtr a, IntPtr b);
2263 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2264 extern static void CollapseWindow (IntPtr hWnd, bool collapse);
2265 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2266 extern static void ZoomWindow (IntPtr hWnd, short partCode, bool front);
2267 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2268 extern static int GetWindowAttributes (IntPtr hWnd, ref Carbon.WindowAttributes outAttributes);
2269 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2270 extern static int ChangeWindowAttributes (IntPtr hWnd, Carbon.WindowAttributes inAttributes, Carbon.WindowAttributes outAttributes);
2271 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2272 internal extern static int GetGlobalMouse (ref Carbon.QDPoint outData);
2274 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2275 extern static int BeginAppModalStateForWindow (IntPtr window);
2276 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2277 extern static int EndAppModalStateForWindow (IntPtr window);
2278 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2279 extern static int CreateNewWindow (Carbon.WindowClass klass, Carbon.WindowAttributes attributes, ref Carbon.Rect r, ref IntPtr window);
2280 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2281 extern static int DisposeWindow (IntPtr wHnd);
2282 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2283 internal extern static int ShowWindow (IntPtr wHnd);
2284 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2285 internal extern static int HideWindow (IntPtr wHnd);
2286 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2287 internal extern static bool IsWindowVisible (IntPtr wHnd);
2288 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2289 extern static int SetWindowBounds (IntPtr wHnd, uint reg, ref Carbon.Rect rect);
2290 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2291 extern static int GetWindowBounds (IntPtr wHnd, uint reg, ref Carbon.Rect rect);
2293 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2294 extern static int SetControlTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
2295 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2296 extern static int SetWindowTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
2297 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2298 internal extern static IntPtr __CFStringMakeConstantString (string cString);
2300 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2301 internal extern static int CFRelease (IntPtr wHnd);
2302 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2303 extern static short GetMBarHeight ();
2305 #region Cursor imports
2306 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2307 extern static Carbon.HIRect CGDisplayBounds (IntPtr displayID);
2308 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2309 extern static IntPtr CGMainDisplayID ();
2310 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2311 extern static void CGDisplayShowCursor (IntPtr display);
2312 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2313 extern static void CGDisplayHideCursor (IntPtr display);
2314 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2315 extern static void CGDisplayMoveCursorToPoint (IntPtr display, Carbon.CGPoint point);
2318 #region Process imports
2319 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2320 extern static int GetCurrentProcess (ref Carbon.ProcessSerialNumber psn);
2321 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2322 extern static int TransformProcessType (ref Carbon.ProcessSerialNumber psn, uint type);
2323 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2324 extern static int SetFrontProcess (ref Carbon.ProcessSerialNumber psn);
2327 #region Dock tile imports
2328 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2329 extern static IntPtr CGColorSpaceCreateDeviceRGB();
2330 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2331 extern static IntPtr CGDataProviderCreateWithData (IntPtr info, IntPtr [] data, int size, IntPtr releasefunc);
2332 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2333 extern static IntPtr CGImageCreate (int width, int height, int bitsPerComponent, int bitsPerPixel, int bytesPerRow, IntPtr colorspace, uint bitmapInfo, IntPtr provider, IntPtr decode, int shouldInterpolate, int intent);
2334 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2335 extern static void SetApplicationDockTileImage(IntPtr imageRef);
2336 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2337 extern static void RestoreApplicationDockTileImage();