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 internal 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;
90 private static bool in_doevents;
92 static readonly object instancelock = new object ();
93 static readonly object queuelock = new object ();
96 internal override event EventHandler Idle;
100 private XplatUICarbon() {
103 TimerList = new ArrayList ();
105 MessageQueue = new Queue ();
111 // FIXME: Clean up the FosterParent here.
115 #region Singleton specific code
116 public static XplatUICarbon GetInstance() {
117 lock (instancelock) {
118 if (Instance == null) {
119 Instance = new XplatUICarbon ();
126 public int Reference {
133 #region Internal methods
134 internal void AddExpose (Hwnd hwnd, bool client, Carbon.HIRect rect) {
135 AddExpose (hwnd, client, (int) rect.origin.x, (int) rect.origin.y, (int) rect.size.width, (int) rect.size.height);
138 internal void AddExpose (Hwnd hwnd, bool client, Rectangle rect) {
139 AddExpose (hwnd, client, (int) rect.X, (int) rect.Y, (int) rect.Width, (int) rect.Height);
142 internal void FlushQueue () {
143 CheckTimers (DateTime.UtcNow);
144 while (MessageQueue.Count > 0) {
145 object queueobj = MessageQueue.Dequeue ();
146 if (queueobj is GCHandle) {
147 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)queueobj);
149 MSG msg = (MSG)queueobj;
150 NativeWindow.WndProc (msg.hwnd, msg.message, msg.wParam, msg.lParam);
155 internal static Rectangle [] GetClippingRectangles (IntPtr handle) {
156 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
160 if (hwnd.Handle != handle)
161 return new Rectangle [] {hwnd.ClientRect};
163 return (Rectangle []) hwnd.GetClippingRectangles ().ToArray (typeof (Rectangle));
166 internal IntPtr GetMousewParam(int Delta) {
169 if ((MouseState & MouseButtons.Left) != 0) {
170 result |= (int)MsgButtons.MK_LBUTTON;
173 if ((MouseState & MouseButtons.Middle) != 0) {
174 result |= (int)MsgButtons.MK_MBUTTON;
177 if ((MouseState & MouseButtons.Right) != 0) {
178 result |= (int)MsgButtons.MK_RBUTTON;
181 Keys mods = ModifierKeys;
182 if ((mods & Keys.Control) != 0) {
183 result |= (int)MsgButtons.MK_CONTROL;
186 if ((mods & Keys.Shift) != 0) {
187 result |= (int)MsgButtons.MK_SHIFT;
190 result |= Delta << 16;
192 return (IntPtr)result;
195 internal IntPtr HandleToWindow (IntPtr handle) {
196 if (HandleMapping [handle] != null)
197 return (IntPtr) HandleMapping [handle];
201 internal void Initialize () {
202 // Initialize the event handlers
203 Carbon.EventHandler.Driver = this;
204 ApplicationHandler = new Carbon.ApplicationHandler (this);
205 ControlHandler = new Carbon.ControlHandler (this);
206 HIObjectHandler = new Carbon.HIObjectHandler (this);
207 KeyboardHandler = new Carbon.KeyboardHandler (this);
208 MouseHandler = new Carbon.MouseHandler (this);
209 WindowHandler = new Carbon.WindowHandler (this);
211 // Initilize the mouse controls
212 Hover.Interval = 500;
213 Hover.Timer = new Timer ();
214 Hover.Timer.Enabled = false;
215 Hover.Timer.Interval = Hover.Interval;
216 Hover.Timer.Tick += new EventHandler (HoverCallback);
219 MouseState = MouseButtons.None;
220 mouse_position = Point.Empty;
222 // Initialize the Caret
223 Caret.Timer = new Timer ();
224 Caret.Timer.Interval = 500;
225 Caret.Timer.Tick += new EventHandler (CaretCallback);
227 // Initialize the D&D
228 Dnd = new Carbon.Dnd ();
230 // Initialize the Carbon Specific stuff
231 WindowMapping = new Hashtable ();
232 HandleMapping = new Hashtable ();
233 UtilityWindows = new ArrayList ();
235 // Initialize the FosterParent
236 Carbon.Rect rect = new Carbon.Rect ();
237 SetRect (ref rect, (short)0, (short)0, (short)0, (short)0);
238 Carbon.ProcessSerialNumber psn = new Carbon.ProcessSerialNumber();
240 GetCurrentProcess( ref psn );
241 TransformProcessType (ref psn, 1);
242 SetFrontProcess (ref psn);
244 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);
246 Carbon.EventHandler.InstallApplicationHandler ();
248 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);
250 CreateNewWindow (Carbon.WindowClass.kOverlayWindowClass, Carbon.WindowAttributes.kWindowNoUpdatesAttribute | Carbon.WindowAttributes.kWindowNoActivatesAttribute, ref rect, ref ReverseWindow);
251 CreateNewWindow (Carbon.WindowClass.kOverlayWindowClass, Carbon.WindowAttributes.kWindowNoUpdatesAttribute | Carbon.WindowAttributes.kWindowNoActivatesAttribute, ref rect, ref CaretWindow);
253 // Get some values about bar heights
254 Carbon.Rect structRect = new Carbon.Rect ();
255 Carbon.Rect contentRect = new Carbon.Rect ();
256 GetWindowBounds (FosterParent, 32, ref structRect);
257 GetWindowBounds (FosterParent, 33, ref contentRect);
259 MenuBarHeight = GetMBarHeight ();
262 FocusWindow = IntPtr.Zero;
265 GetMessageResult = true;
267 ReverseWindowMapped = false;
270 internal void PerformNCCalc(Hwnd hwnd) {
271 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
275 rect = new Rectangle (0, 0, hwnd.Width, hwnd.Height);
277 ncp = new XplatUIWin32.NCCALCSIZE_PARAMS();
278 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ncp));
280 ncp.rgrc1.left = rect.Left;
281 ncp.rgrc1.top = rect.Top;
282 ncp.rgrc1.right = rect.Right;
283 ncp.rgrc1.bottom = rect.Bottom;
285 Marshal.StructureToPtr(ncp, ptr, true);
286 NativeWindow.WndProc(hwnd.client_window, Msg.WM_NCCALCSIZE, (IntPtr)1, ptr);
287 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(ptr, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
288 Marshal.FreeHGlobal(ptr);
291 rect = new Rectangle(ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right - ncp.rgrc1.left, ncp.rgrc1.bottom - ncp.rgrc1.top);
292 hwnd.ClientRect = rect;
294 rect = TranslateClientRectangleToQuartzClientRectangle (hwnd);
297 Carbon.HIRect r = new Carbon.HIRect (rect.X, rect.Y, rect.Width, rect.Height);
298 HIViewSetFrame (hwnd.client_window, ref r);
301 AddExpose (hwnd, false, 0, 0, hwnd.Width, hwnd.Height);
304 internal void ScreenToClient(IntPtr handle, ref Carbon.QDPoint point) {
305 int x = (int) point.x;
306 int y = (int) point.y;
308 ScreenToClient (handle, ref x, ref y);
314 internal static Rectangle TranslateClientRectangleToQuartzClientRectangle (Hwnd hwnd) {
315 return TranslateClientRectangleToQuartzClientRectangle (hwnd, Control.FromHandle (hwnd.Handle));
318 internal static Rectangle TranslateClientRectangleToQuartzClientRectangle (Hwnd hwnd, Control ctrl) {
320 * If this is a form with no window manager, X is handling all the border and caption painting
321 * so remove that from the area (since the area we set of the window here is the part of the window
322 * we're painting in only)
324 Rectangle rect = hwnd.ClientRect;
325 Form form = ctrl as Form;
326 CreateParams cp = null;
329 cp = form.GetCreateParams ();
331 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
332 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
333 Rectangle qrect = rect;
335 qrect.Y -= borders.top;
336 qrect.X -= borders.left;
337 qrect.Width += borders.left + borders.right;
338 qrect.Height += borders.top + borders.bottom;
343 if (rect.Width < 1 || rect.Height < 1) {
353 internal static Size TranslateWindowSizeToQuartzWindowSize (CreateParams cp) {
354 return TranslateWindowSizeToQuartzWindowSize (cp, new Size (cp.Width, cp.Height));
357 internal static Size TranslateWindowSizeToQuartzWindowSize (CreateParams cp, Size size) {
359 * If this is a form with no window manager, X is handling all the border and caption painting
360 * so remove that from the area (since the area we set of the window here is the part of the window
361 * we're painting in only)
363 Form form = cp.control as Form;
364 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
365 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
368 qsize.Width -= borders.left + borders.right;
369 qsize.Height -= borders.top + borders.bottom;
374 if (size.Height == 0)
381 internal static Size TranslateQuartzWindowSizeToWindowSize (CreateParams cp, int width, int height) {
383 * If this is a form with no window manager, X is handling all the border and caption painting
384 * so remove that from the area (since the area we set of the window here is the part of the window
385 * we're painting in only)
387 Size size = new Size (width, height);
388 Form form = cp.control as Form;
389 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
390 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
393 qsize.Width += borders.left + borders.right;
394 qsize.Height += borders.top + borders.bottom;
404 private void CaretCallback (object sender, EventArgs e) {
416 private void HoverCallback (object sender, EventArgs e) {
417 if ((Hover.X == mouse_position.X) && (Hover.Y == mouse_position.Y)) {
418 MSG msg = new MSG ();
419 msg.hwnd = Hover.Hwnd;
420 msg.message = Msg.WM_MOUSEHOVER;
421 msg.wParam = GetMousewParam (0);
422 msg.lParam = (IntPtr)((ushort)Hover.X << 16 | (ushort)Hover.X);
423 MessageQueue.Enqueue (msg);
428 #region Private Methods
429 private Point ConvertScreenPointToClient (IntPtr handle, Point point) {
430 Point converted_point = new Point ();
431 Carbon.Rect window_bounds = new Carbon.Rect ();
432 Carbon.CGPoint native_point = new Carbon.CGPoint ();
434 GetWindowBounds (HIViewGetWindow (handle), 32, ref window_bounds);
436 native_point.x = (point.X - window_bounds.left);
437 native_point.y = (point.Y - window_bounds.top);
439 HIViewConvertPoint (ref native_point, IntPtr.Zero, handle);
441 converted_point.X = (int)native_point.x;
442 converted_point.Y = (int)native_point.y;
444 return converted_point;
447 private Point ConvertClientPointToScreen (IntPtr handle, Point point) {
448 Point converted_point = new Point ();
449 Carbon.Rect window_bounds = new Carbon.Rect ();
450 Carbon.CGPoint native_point = new Carbon.CGPoint ();
452 GetWindowBounds (HIViewGetWindow (handle), 32, ref window_bounds);
454 native_point.x = point.X;
455 native_point.y = point.Y;
457 HIViewConvertPoint (ref native_point, handle, IntPtr.Zero);
459 converted_point.X = (int)(native_point.x + window_bounds.left);
460 converted_point.Y = (int)(native_point.y + window_bounds.top);
462 return converted_point;
465 private double NextTimeout () {
466 DateTime now = DateTime.UtcNow;
467 int timeout = 0x7FFFFFF;
469 foreach (Timer timer in TimerList) {
470 int next = (int) (timer.Expires - now).TotalMilliseconds;
477 if (timeout < Timer.Minimum)
478 timeout = Timer.Minimum;
480 return (double)((double)timeout/1000);
483 private void CheckTimers (DateTime now) {
485 int count = TimerList.Count;
488 for (int i = 0; i < TimerList.Count; i++) {
489 Timer timer = (Timer) TimerList [i];
490 if (timer.Enabled && timer.Expires <= now) {
492 // - Before MainForm.OnLoad if DoEvents () is called.
493 // - After MainForm.OnLoad if not.
496 (Application.MWFThread.Current.Context != null &&
497 Application.MWFThread.Current.Context.MainForm != null &&
498 Application.MWFThread.Current.Context.MainForm.IsLoaded)) {
507 private void WaitForHwndMessage (Hwnd hwnd, Msg message) {
508 MSG msg = new MSG ();
512 if (GetMessage(null, ref msg, IntPtr.Zero, 0, 0)) {
513 if ((Msg)msg.message == Msg.WM_QUIT) {
518 if (msg.hwnd == hwnd.Handle) {
519 if ((Msg)msg.message == message)
521 else if ((Msg)msg.message == Msg.WM_DESTROY)
525 TranslateMessage (ref msg);
526 DispatchMessage (ref msg);
532 private void SendParentNotify(IntPtr child, Msg cause, int x, int y) {
535 if (child == IntPtr.Zero) {
539 hwnd = Hwnd.GetObjectFromWindow (child);
545 if (hwnd.Handle == IntPtr.Zero) {
549 if (ExStyleSet ((int) hwnd.initial_ex_style, WindowExStyles.WS_EX_NOPARENTNOTIFY)) {
553 if (hwnd.Parent == null) {
557 if (hwnd.Parent.Handle == IntPtr.Zero) {
561 if (cause == Msg.WM_CREATE || cause == Msg.WM_DESTROY) {
562 SendMessage(hwnd.Parent.Handle, Msg.WM_PARENTNOTIFY, Control.MakeParam((int)cause, 0), child);
564 SendMessage(hwnd.Parent.Handle, Msg.WM_PARENTNOTIFY, Control.MakeParam((int)cause, 0), Control.MakeParam(x, y));
567 SendParentNotify (hwnd.Parent.Handle, cause, x, y);
570 private bool StyleSet (int s, WindowStyles ws) {
571 return (s & (int)ws) == (int)ws;
574 private bool ExStyleSet (int ex, WindowExStyles exws) {
575 return (ex & (int)exws) == (int)exws;
578 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) {
581 tool_caption_height = 0;
582 border_static = false;
584 if (StyleSet (Style, WindowStyles.WS_CHILD)) {
585 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_CLIENTEDGE)) {
586 border_style = FormBorderStyle.Fixed3D;
587 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_STATICEDGE)) {
588 border_style = FormBorderStyle.Fixed3D;
589 border_static = true;
590 } else if (!StyleSet (Style, WindowStyles.WS_BORDER)) {
591 border_style = FormBorderStyle.None;
593 border_style = FormBorderStyle.FixedSingle;
595 title_style = TitleStyle.None;
597 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
599 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
600 title_style = TitleStyle.Tool;
602 title_style = TitleStyle.Normal;
606 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_MDICHILD)) {
609 if (StyleSet (Style, WindowStyles.WS_OVERLAPPEDWINDOW) ||
610 ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
611 border_style = (FormBorderStyle) 0xFFFF;
613 border_style = FormBorderStyle.None;
618 title_style = TitleStyle.None;
619 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
620 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
621 title_style = TitleStyle.Tool;
623 title_style = TitleStyle.Normal;
627 border_style = FormBorderStyle.None;
629 if (StyleSet (Style, WindowStyles.WS_THICKFRAME)) {
630 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
631 border_style = FormBorderStyle.SizableToolWindow;
633 border_style = FormBorderStyle.Sizable;
636 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
637 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_CLIENTEDGE)) {
638 border_style = FormBorderStyle.Fixed3D;
639 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_STATICEDGE)) {
640 border_style = FormBorderStyle.Fixed3D;
641 border_static = true;
642 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_DLGMODALFRAME)) {
643 border_style = FormBorderStyle.FixedDialog;
644 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
645 border_style = FormBorderStyle.FixedToolWindow;
646 } else if (StyleSet (Style, WindowStyles.WS_BORDER)) {
647 border_style = FormBorderStyle.FixedSingle;
650 if (StyleSet (Style, WindowStyles.WS_BORDER)) {
651 border_style = FormBorderStyle.FixedSingle;
658 private void SetHwndStyles(Hwnd hwnd, CreateParams cp) {
659 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);
662 private void ShowCaret () {
666 ShowWindow (CaretWindow);
667 Graphics g = Graphics.FromHwnd (HIViewGetRoot (CaretWindow));
669 g.FillRectangle (new SolidBrush (Color.Black), new Rectangle (0, 0, Caret.Width, Caret.Height));
674 private void HideCaret () {
678 HideWindow (CaretWindow);
681 private void AccumulateDestroyedHandles (Control c, ArrayList list) {
683 Control[] controls = c.Controls.GetAllControls ();
685 if (c.IsHandleCreated && !c.IsDisposed) {
686 Hwnd hwnd = Hwnd.ObjectFromHandle(c.Handle);
689 CleanupCachedWindows (hwnd);
692 for (int i = 0; i < controls.Length; i ++) {
693 AccumulateDestroyedHandles (controls[i], list);
699 private void CleanupCachedWindows (Hwnd hwnd) {
700 if (ActiveWindow == hwnd.Handle) {
701 SendMessage(hwnd.client_window, Msg.WM_ACTIVATE, (IntPtr)WindowActiveFlags.WA_INACTIVE, IntPtr.Zero);
702 ActiveWindow = IntPtr.Zero;
705 if (FocusWindow == hwnd.Handle) {
706 SendMessage(hwnd.client_window, Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
707 FocusWindow = IntPtr.Zero;
710 if (Grab.Hwnd == hwnd.Handle) {
711 Grab.Hwnd = IntPtr.Zero;
712 Grab.Confined = false;
715 DestroyCaret (hwnd.Handle);
718 private void AddExpose (Hwnd hwnd, bool client, int x, int y, int width, int height) {
720 if ((hwnd == null) || (x > hwnd.Width) || (y > hwnd.Height) || ((x + width) < 0) || ((y + height) < 0)) {
724 // Keep the invalid area as small as needed
725 if ((x + width) > hwnd.width) {
726 width = hwnd.width - x;
729 if ((y + height) > hwnd.height) {
730 height = hwnd.height - y;
734 hwnd.AddInvalidArea(x, y, width, height);
735 if (!hwnd.expose_pending && hwnd.visible) {
736 MSG msg = new MSG ();
737 msg.message = Msg.WM_PAINT;
738 msg.hwnd = hwnd.Handle;
739 MessageQueue.Enqueue (msg);
740 hwnd.expose_pending = true;
743 hwnd.AddNcInvalidArea (x, y, width, height);
744 if (!hwnd.nc_expose_pending && hwnd.visible) {
745 MSG msg = new MSG ();
746 Region rgn = new Region (hwnd.Invalid);
747 IntPtr hrgn = rgn.GetHrgn (null); // Graphics object isn't needed
748 msg.message = Msg.WM_NCPAINT;
749 msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
751 msg.hwnd = hwnd.Handle;
752 MessageQueue.Enqueue (msg);
753 hwnd.nc_expose_pending = true;
760 #region Public Methods
761 internal void EnqueueMessage (MSG msg) {
763 MessageQueue.Enqueue (msg);
767 internal override void RaiseIdle (EventArgs e)
773 internal override IntPtr InitializeDriver() {
777 internal override void ShutdownDriver(IntPtr token) {
780 internal override void EnableThemes() {
781 themes_enabled = true;
784 internal override void Activate(IntPtr handle) {
785 if (ActiveWindow != IntPtr.Zero) {
786 ActivateWindow (HIViewGetWindow (ActiveWindow), false);
788 ActivateWindow (HIViewGetWindow (handle), true);
789 ActiveWindow = handle;
792 internal override void AudibleAlert() {
793 throw new NotImplementedException();
796 internal override void CaretVisible (IntPtr hwnd, bool visible) {
797 if (Caret.Hwnd == hwnd) {
799 if (Caret.Visible < 1) {
802 if (Caret.Visible == 1) {
804 Caret.Timer.Start ();
809 if (Caret.Visible == 0) {
817 internal override bool CalculateWindowRect(ref Rectangle ClientRect, CreateParams cp, Menu menu, out Rectangle WindowRect) {
818 WindowRect = Hwnd.GetWindowRectangle (cp, menu, ClientRect);
822 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
823 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
825 Point point = ConvertClientPointToScreen (hwnd.ClientWindow, new Point (x, y));
831 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
832 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
834 Point point = ConvertClientPointToScreen (hwnd.ClientWindow, new Point (x, y));
840 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
841 ArrayList list = new ArrayList ();
842 DataFormats.Format f = DataFormats.Format.List;
849 return (int [])list.ToArray (typeof (int));
852 internal override void ClipboardClose(IntPtr handle) {
855 //TODO: Map our internal formats to the right os code where we can
856 internal override int ClipboardGetID(IntPtr handle, string format) {
857 return (int)__CFStringMakeConstantString (format);
860 internal override IntPtr ClipboardOpen(bool primary_selection) {
861 if (primary_selection)
862 return Carbon.Pasteboard.Primary;
863 return Carbon.Pasteboard.Application;
866 internal override object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
867 return Carbon.Pasteboard.Retrieve (handle, type);
870 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
871 Carbon.Pasteboard.Store (handle, obj, type);
874 internal override void CreateCaret (IntPtr hwnd, int width, int height) {
875 if (Caret.Hwnd != IntPtr.Zero)
876 DestroyCaret (Caret.Hwnd);
880 Caret.Height = height;
885 internal override IntPtr CreateWindow(CreateParams cp) {
887 Hwnd parent_hwnd = null;
896 IntPtr WholeWindowTracking;
897 IntPtr ClientWindowTracking;
905 ParentHandle = IntPtr.Zero;
906 WindowHandle = IntPtr.Zero;
907 WholeWindow = IntPtr.Zero;
908 ClientWindow = IntPtr.Zero;
909 WholeWindowTracking = IntPtr.Zero;
910 ClientWindowTracking = IntPtr.Zero;
912 if (Width < 1) Width = 1;
913 if (Height < 1) Height = 1;
915 if (cp.Parent != IntPtr.Zero) {
916 parent_hwnd = Hwnd.ObjectFromHandle (cp.Parent);
917 ParentHandle = parent_hwnd.client_window;
919 if (StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
920 HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
925 if (cp.control is Form) {
926 next = Hwnd.GetNextStackedFormLocation (cp, parent_hwnd);
934 hwnd.height = Height;
935 hwnd.Parent = Hwnd.ObjectFromHandle (cp.Parent);
936 hwnd.initial_style = cp.WindowStyle;
937 hwnd.initial_ex_style = cp.WindowExStyle;
938 hwnd.visible = false;
940 if (StyleSet (cp.Style, WindowStyles.WS_DISABLED)) {
941 hwnd.enabled = false;
944 ClientWindow = IntPtr.Zero;
946 Size QWindowSize = TranslateWindowSizeToQuartzWindowSize (cp);
947 Rectangle QClientRect = TranslateClientRectangleToQuartzClientRectangle (hwnd, cp.control);
949 SetHwndStyles(hwnd, cp);
951 if (ParentHandle == IntPtr.Zero) {
952 IntPtr WindowView = IntPtr.Zero;
953 IntPtr GrowBox = IntPtr.Zero;
954 Carbon.WindowClass windowklass = Carbon.WindowClass.kOverlayWindowClass;
955 Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
956 if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZEBOX)) {
957 attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
959 if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZEBOX)) {
960 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
962 if (StyleSet (cp.Style, WindowStyles.WS_SYSMENU)) {
963 attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
965 if (StyleSet (cp.Style, WindowStyles.WS_CAPTION)) {
966 windowklass = Carbon.WindowClass.kDocumentWindowClass;
968 if (hwnd.border_style == FormBorderStyle.FixedToolWindow) {
969 windowklass = Carbon.WindowClass.kUtilityWindowClass;
970 } else if (hwnd.border_style == FormBorderStyle.SizableToolWindow) {
971 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute;
972 windowklass = Carbon.WindowClass.kUtilityWindowClass;
974 if (windowklass == Carbon.WindowClass.kOverlayWindowClass) {
975 attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
977 attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;
979 Carbon.Rect rect = new Carbon.Rect ();
980 if (StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
981 SetRect (ref rect, (short)X, (short)(Y), (short)(X + QWindowSize.Width), (short)(Y + QWindowSize.Height));
983 SetRect (ref rect, (short)X, (short)(Y + MenuBarHeight), (short)(X + QWindowSize.Width), (short)(Y + MenuBarHeight + QWindowSize.Height));
986 CreateNewWindow (windowklass, attributes, ref rect, ref WindowHandle);
988 Carbon.EventHandler.InstallWindowHandler (WindowHandle);
989 HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref WindowView);
990 HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 7), ref GrowBox);
991 HIGrowBoxViewSetTransparent (GrowBox, true);
992 SetAutomaticControlDragTrackingEnabledForWindow (WindowHandle, true);
993 ParentHandle = WindowView;
996 HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref WholeWindow);
997 HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref ClientWindow);
999 Carbon.EventHandler.InstallControlHandler (WholeWindow);
1000 Carbon.EventHandler.InstallControlHandler (ClientWindow);
1002 // Enable embedding on controls
1003 HIViewChangeFeatures (WholeWindow, 1<<1, 0);
1004 HIViewChangeFeatures (ClientWindow, 1<<1, 0);
1006 HIViewNewTrackingArea (WholeWindow, IntPtr.Zero, (UInt64)WholeWindow, ref WholeWindowTracking);
1007 HIViewNewTrackingArea (ClientWindow, IntPtr.Zero, (UInt64)ClientWindow, ref ClientWindowTracking);
1008 Carbon.HIRect WholeRect;
1009 if (WindowHandle != IntPtr.Zero) {
1010 WholeRect = new Carbon.HIRect (0, 0, QWindowSize.Width, QWindowSize.Height);
1012 WholeRect = new Carbon.HIRect (X, Y, QWindowSize.Width, QWindowSize.Height);
1014 Carbon.HIRect ClientRect = new Carbon.HIRect (QClientRect.X, QClientRect.Y, QClientRect.Width, QClientRect.Height);
1015 HIViewSetFrame (WholeWindow, ref WholeRect);
1016 HIViewSetFrame (ClientWindow, ref ClientRect);
1018 HIViewAddSubview (ParentHandle, WholeWindow);
1019 HIViewAddSubview (WholeWindow, ClientWindow);
1021 hwnd.WholeWindow = WholeWindow;
1022 hwnd.ClientWindow = ClientWindow;
1024 if (WindowHandle != IntPtr.Zero) {
1025 WindowMapping [hwnd.Handle] = WindowHandle;
1026 HandleMapping [WindowHandle] = hwnd.Handle;
1027 if (hwnd.border_style == FormBorderStyle.FixedToolWindow || hwnd.border_style == FormBorderStyle.SizableToolWindow) {
1028 UtilityWindows.Add (WindowHandle);
1032 // Allow dnd on controls
1033 Dnd.SetAllowDrop (hwnd, true);
1035 Text (hwnd.Handle, cp.Caption);
1037 SendMessage (hwnd.Handle, Msg.WM_CREATE, (IntPtr)1, IntPtr.Zero /* XXX unused */);
1038 SendParentNotify (hwnd.Handle, Msg.WM_CREATE, int.MaxValue, int.MaxValue);
1040 if (StyleSet (cp.Style, WindowStyles.WS_VISIBLE)) {
1041 if (WindowHandle != IntPtr.Zero) {
1042 if (Control.FromHandle(hwnd.Handle) is Form) {
1043 Form f = Control.FromHandle(hwnd.Handle) as Form;
1044 if (f.WindowState == FormWindowState.Normal) {
1045 SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
1048 ShowWindow (WindowHandle);
1049 WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
1051 HIViewSetVisible (WholeWindow, true);
1052 HIViewSetVisible (ClientWindow, true);
1053 hwnd.visible = true;
1054 if (!(Control.FromHandle(hwnd.Handle) is Form)) {
1055 SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
1059 if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZE)) {
1060 SetWindowState(hwnd.Handle, FormWindowState.Minimized);
1061 } else if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZE)) {
1062 SetWindowState(hwnd.Handle, FormWindowState.Maximized);
1068 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
1069 CreateParams create_params = new CreateParams();
1071 create_params.Caption = "";
1072 create_params.X = X;
1073 create_params.Y = Y;
1074 create_params.Width = Width;
1075 create_params.Height = Height;
1077 create_params.ClassName=XplatUI.DefaultClassName;
1078 create_params.ClassStyle = 0;
1079 create_params.ExStyle=0;
1080 create_params.Parent=IntPtr.Zero;
1081 create_params.Param=0;
1083 return CreateWindow(create_params);
1086 internal override Bitmap DefineStdCursorBitmap (StdCursor id) {
1087 return Carbon.Cursor.DefineStdCursorBitmap (id);
1090 internal override IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
1091 return Carbon.Cursor.DefineCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
1094 internal override IntPtr DefineStdCursor (StdCursor id) {
1095 return Carbon.Cursor.DefineStdCursor (id);
1098 internal override IntPtr DefWndProc(ref Message msg) {
1099 Hwnd hwnd = Hwnd.ObjectFromHandle (msg.HWnd);
1100 switch ((Msg)msg.Msg) {
1102 if (WindowMapping [hwnd.Handle] != null)
1107 case Msg.WM_PAINT: {
1108 hwnd.expose_pending = false;
1111 case Msg.WM_NCPAINT: {
1112 hwnd.nc_expose_pending = false;
1115 case Msg.WM_NCCALCSIZE: {
1116 if (msg.WParam == (IntPtr)1) {
1117 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1118 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure (msg.LParam, typeof (XplatUIWin32.NCCALCSIZE_PARAMS));
1120 // Add all the stuff X is supposed to draw.
1121 Control ctrl = Control.FromHandle (hwnd.Handle);
1123 Hwnd.Borders rect = Hwnd.GetBorders (ctrl.GetCreateParams (), null);
1125 ncp.rgrc1.top += rect.top;
1126 ncp.rgrc1.bottom -= rect.bottom;
1127 ncp.rgrc1.left += rect.left;
1128 ncp.rgrc1.right -= rect.right;
1130 Marshal.StructureToPtr (ncp, msg.LParam, true);
1135 case Msg.WM_SETCURSOR: {
1136 // Pass to parent window first
1137 while ((hwnd.parent != null) && (msg.Result == IntPtr.Zero)) {
1139 msg.Result = NativeWindow.WndProc(hwnd.Handle, Msg.WM_SETCURSOR, msg.HWnd, msg.LParam);
1142 if (msg.Result == IntPtr.Zero) {
1145 switch((HitTest)(msg.LParam.ToInt32() & 0xffff)) {
1146 case HitTest.HTBOTTOM: handle = Cursors.SizeNS.handle; break;
1147 case HitTest.HTBORDER: handle = Cursors.SizeNS.handle; break;
1148 case HitTest.HTBOTTOMLEFT: handle = Cursors.SizeNESW.handle; break;
1149 case HitTest.HTBOTTOMRIGHT: handle = Cursors.SizeNWSE.handle; break;
1150 case HitTest.HTERROR: if ((msg.LParam.ToInt32() >> 16) == (int)Msg.WM_LBUTTONDOWN) {
1151 //FIXME: AudibleAlert();
1153 handle = Cursors.Default.handle;
1156 case HitTest.HTHELP: handle = Cursors.Help.handle; break;
1157 case HitTest.HTLEFT: handle = Cursors.SizeWE.handle; break;
1158 case HitTest.HTRIGHT: handle = Cursors.SizeWE.handle; break;
1159 case HitTest.HTTOP: handle = Cursors.SizeNS.handle; break;
1160 case HitTest.HTTOPLEFT: handle = Cursors.SizeNWSE.handle; break;
1161 case HitTest.HTTOPRIGHT: handle = Cursors.SizeNESW.handle; break;
1164 case HitTest.HTGROWBOX:
1165 case HitTest.HTSIZE:
1166 case HitTest.HTZOOM:
1167 case HitTest.HTVSCROLL:
1168 case HitTest.HTSYSMENU:
1169 case HitTest.HTREDUCE:
1170 case HitTest.HTNOWHERE:
1171 case HitTest.HTMAXBUTTON:
1172 case HitTest.HTMINBUTTON:
1173 case HitTest.HTMENU:
1174 case HitTest.HSCROLL:
1175 case HitTest.HTBOTTOM:
1176 case HitTest.HTCAPTION:
1177 case HitTest.HTCLIENT:
1178 case HitTest.HTCLOSE:
1180 default: handle = Cursors.Default.handle; break;
1182 SetCursor(msg.HWnd, handle);
1190 internal override void DestroyCaret (IntPtr hwnd) {
1191 if (Caret.Hwnd == hwnd) {
1192 if (Caret.Visible == 1) {
1193 Caret.Timer.Stop ();
1196 Caret.Hwnd = IntPtr.Zero;
1203 internal override void DestroyCursor(IntPtr cursor) {
1204 throw new NotImplementedException ();
1207 internal override void DestroyWindow(IntPtr handle) {
1210 hwnd = Hwnd.ObjectFromHandle(handle);
1216 SendParentNotify (hwnd.Handle, Msg.WM_DESTROY, int.MaxValue, int.MaxValue);
1218 CleanupCachedWindows (hwnd);
1220 ArrayList windows = new ArrayList ();
1222 AccumulateDestroyedHandles (Control.ControlNativeWindow.ControlFromHandle(hwnd.Handle), windows);
1225 foreach (Hwnd h in windows) {
1226 SendMessage (h.Handle, Msg.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
1230 // TODO: This is crashing swf-messageboxes
1232 if (false && hwnd.whole_window != IntPtr.Zero)
1233 CFRelease (hwnd.whole_window);
1234 if (false && hwnd.client_window != IntPtr.Zero)
1235 CFRelease (hwnd.client_window);
1238 if (WindowMapping [hwnd.Handle] != null) {
1239 DisposeWindow ((IntPtr)(WindowMapping [hwnd.Handle]));
1240 WindowMapping.Remove (hwnd.Handle);
1244 internal override IntPtr DispatchMessage(ref MSG msg) {
1245 return NativeWindow.WndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
1248 internal override void DoEvents() {
1249 MSG msg = new MSG ();
1252 while (PeekMessage (null, ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)) {
1253 TranslateMessage (ref msg);
1254 DispatchMessage (ref msg);
1256 in_doevents = false;
1260 internal override void EnableWindow(IntPtr handle, bool Enable) {
1261 //Like X11 we need not do anything here
1264 internal override void EndLoop(Thread thread) {
1267 internal void Exit () {
1268 GetMessageResult = false;
1271 internal override IntPtr GetActive() {
1272 return ActiveWindow;
1275 internal override Region GetClipRegion(IntPtr hwnd) {
1280 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1287 internal override void GetDisplaySize(out Size size) {
1288 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1289 size = new Size ((int)bounds.size.width, (int)bounds.size.height);
1292 internal override IntPtr GetParent(IntPtr handle) {
1295 hwnd = Hwnd.ObjectFromHandle(handle);
1296 if (hwnd != null && hwnd.Parent != null) {
1297 return hwnd.Parent.Handle;
1302 internal override IntPtr GetPreviousWindow(IntPtr handle) {
1303 return HIViewGetPreviousView(handle);
1306 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1307 Carbon.QDPoint pt = new Carbon.QDPoint ();
1308 GetGlobalMouse (ref pt);
1313 internal override IntPtr GetFocus() {
1318 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1319 FontFamily ff = font.FontFamily;
1320 ascent = ff.GetCellAscent (font.Style);
1321 descent = ff.GetCellDescent (font.Style);
1325 internal override Point GetMenuOrigin(IntPtr handle) {
1328 hwnd = Hwnd.ObjectFromHandle(handle);
1331 return hwnd.MenuOrigin;
1336 internal override bool GetMessage(object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1337 IntPtr evtRef = IntPtr.Zero;
1338 IntPtr target = GetEventDispatcherTarget();
1339 CheckTimers (DateTime.UtcNow);
1340 ReceiveNextEvent (0, IntPtr.Zero, 0, true, ref evtRef);
1341 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1342 SendEventToEventTarget (evtRef, target);
1343 ReleaseEvent (evtRef);
1349 if (MessageQueue.Count <= 0) {
1351 Idle (this, EventArgs.Empty);
1352 else if (TimerList.Count == 0) {
1353 ReceiveNextEvent (0, IntPtr.Zero, 0.15, true, ref evtRef);
1354 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1355 SendEventToEventTarget (evtRef, target);
1356 ReleaseEvent (evtRef);
1359 ReceiveNextEvent (0, IntPtr.Zero, NextTimeout (), true, ref evtRef);
1360 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1361 SendEventToEventTarget (evtRef, target);
1362 ReleaseEvent (evtRef);
1365 msg.hwnd = IntPtr.Zero;
1366 msg.message = Msg.WM_ENTERIDLE;
1367 return GetMessageResult;
1369 object queueobj = MessageQueue.Dequeue ();
1370 if (queueobj is GCHandle) {
1371 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)queueobj);
1374 msg = (MSG)queueobj;
1377 return GetMessageResult;
1381 internal override bool GetText(IntPtr handle, out string text) {
1382 throw new NotImplementedException ();
1385 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) {
1388 hwnd = Hwnd.ObjectFromHandle(handle);
1394 height = hwnd.height;
1396 PerformNCCalc(hwnd);
1398 client_width = hwnd.ClientRect.Width;
1399 client_height = hwnd.ClientRect.Height;
1404 // Should we throw an exception or fail silently?
1405 // throw new ArgumentException("Called with an invalid window handle", "handle");
1415 internal override FormWindowState GetWindowState(IntPtr hwnd) {
1416 IntPtr window = HIViewGetWindow (hwnd);
1418 if (IsWindowCollapsed (window))
1419 return FormWindowState.Minimized;
1420 if (IsWindowInStandardState (window, IntPtr.Zero, IntPtr.Zero))
1421 return FormWindowState.Maximized;
1423 return FormWindowState.Normal;
1426 internal override void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
1428 GrabConfined = Grab.Confined;
1429 GrabArea = Grab.Area;
1432 internal override void GrabWindow(IntPtr handle, IntPtr confine_to_handle) {
1434 Grab.Confined = confine_to_handle != IntPtr.Zero;
1435 /* FIXME: Set the Grab.Area */
1438 internal override void UngrabWindow(IntPtr hwnd) {
1439 bool was_grabbed = Grab.Hwnd != IntPtr.Zero;
1441 Grab.Hwnd = IntPtr.Zero;
1442 Grab.Confined = false;
1445 // lparam should be the handle to the window gaining the mouse capture,
1446 // but we dont have that information like X11.
1447 // Also only generate WM_CAPTURECHANGED if the window actually was grabbed.
1448 SendMessage (hwnd, Msg.WM_CAPTURECHANGED, IntPtr.Zero, IntPtr.Zero);
1452 internal override void HandleException(Exception e) {
1453 StackTrace st = new StackTrace(e);
1454 Console.WriteLine("Exception '{0}'", e.Message+st.ToString());
1455 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1458 internal override void Invalidate (IntPtr handle, Rectangle rc, bool clear) {
1461 hwnd = Hwnd.ObjectFromHandle(handle);
1464 AddExpose (hwnd, true, hwnd.X, hwnd.Y, hwnd.Width, hwnd.Height);
1466 AddExpose (hwnd, true, rc.X, rc.Y, rc.Width, rc.Height);
1470 internal override void InvalidateNC (IntPtr handle)
1474 hwnd = Hwnd.ObjectFromHandle(handle);
1476 AddExpose (hwnd, false, 0, 0, hwnd.Width, hwnd.Height);
1479 internal override bool IsEnabled(IntPtr handle) {
1480 return Hwnd.ObjectFromHandle(handle).Enabled;
1483 internal override bool IsVisible(IntPtr handle) {
1484 return Hwnd.ObjectFromHandle(handle).visible;
1487 internal override void KillTimer(Timer timer) {
1489 TimerList.Remove(timer);
1494 internal override void OverrideCursor(IntPtr cursor) {
1497 internal override PaintEventArgs PaintEventStart(ref Message msg, IntPtr handle, bool client) {
1498 PaintEventArgs paint_event;
1502 hwnd = Hwnd.ObjectFromHandle(msg.HWnd);
1503 if (msg.HWnd == handle) {
1506 paint_hwnd = Hwnd.ObjectFromHandle (handle);
1509 if (Caret.Visible == 1) {
1510 Caret.Paused = true;
1517 dc = Graphics.FromHwnd (paint_hwnd.client_window);
1519 Region clip_region = new Region ();
1520 clip_region.MakeEmpty();
1522 foreach (Rectangle r in hwnd.ClipRectangles) {
1523 clip_region.Union (r);
1526 if (hwnd.UserClip != null) {
1527 clip_region.Intersect(hwnd.UserClip);
1530 // FIXME: Clip region is hosed
1531 dc.Clip = clip_region;
1532 paint_event = new PaintEventArgs(dc, hwnd.Invalid);
1533 hwnd.expose_pending = false;
1534 hwnd.ClearInvalidArea();
1536 hwnd.drawing_stack.Push (paint_event);
1537 hwnd.drawing_stack.Push (dc);
1539 dc = Graphics.FromHwnd (paint_hwnd.whole_window);
1541 if (!hwnd.nc_invalid.IsEmpty) {
1542 // FIXME: Clip region is hosed
1543 dc.SetClip (hwnd.nc_invalid);
1544 paint_event = new PaintEventArgs(dc, hwnd.nc_invalid);
1546 paint_event = new PaintEventArgs(dc, new Rectangle(0, 0, hwnd.width, hwnd.height));
1548 hwnd.nc_expose_pending = false;
1549 hwnd.ClearNcInvalidArea ();
1551 hwnd.drawing_stack.Push (paint_event);
1552 hwnd.drawing_stack.Push (dc);
1558 internal override void PaintEventEnd(ref Message msg, IntPtr handle, bool client) {
1561 hwnd = Hwnd.ObjectFromHandle(handle);
1563 // FIXME: Pop is causing invalid stack ops sometimes; race condition?
1565 Graphics dc = (Graphics)hwnd.drawing_stack.Pop();
1569 PaintEventArgs pe = (PaintEventArgs)hwnd.drawing_stack.Pop();
1570 pe.SetGraphics (null);
1574 if (Caret.Visible == 1) {
1576 Caret.Paused = false;
1580 internal override bool PeekMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1581 IntPtr evtRef = IntPtr.Zero;
1582 IntPtr target = GetEventDispatcherTarget();
1583 CheckTimers (DateTime.UtcNow);
1584 ReceiveNextEvent (0, IntPtr.Zero, 0, true, ref evtRef);
1585 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1586 SendEventToEventTarget (evtRef, target);
1587 ReleaseEvent (evtRef);
1591 if (MessageQueue.Count <= 0) {
1595 if (flags == (uint)PeekMessageFlags.PM_REMOVE)
1596 queueobj = MessageQueue.Dequeue ();
1598 queueobj = MessageQueue.Peek ();
1600 if (queueobj is GCHandle) {
1601 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)queueobj);
1604 msg = (MSG)queueobj;
1610 internal override bool PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
1611 MSG msg = new MSG();
1613 msg.message = message;
1614 msg.wParam = wParam;
1615 msg.lParam = lParam;
1616 MessageQueue.Enqueue (msg);
1620 internal override void PostQuitMessage(int exitCode) {
1621 PostMessage (FosterParent, Msg.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
1624 internal override void RequestAdditionalWM_NCMessages(IntPtr hwnd, bool hover, bool leave) {
1627 internal override void RequestNCRecalc(IntPtr handle) {
1630 hwnd = Hwnd.ObjectFromHandle(handle);
1636 PerformNCCalc(hwnd);
1637 SendMessage(handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1638 InvalidateNC(handle);
1642 internal override void ResetMouseHover(IntPtr handle) {
1643 throw new NotImplementedException();
1646 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y) {
1647 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1649 Point point = ConvertScreenPointToClient (hwnd.ClientWindow, new Point (x, y));
1655 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
1656 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1658 Point point = ConvertScreenPointToClient (hwnd.WholeWindow, new Point (x, y));
1664 internal override void ScrollWindow(IntPtr handle, Rectangle area, int XAmount, int YAmount, bool clear) {
1666 * This used to use a HIViewScrollRect but this causes issues with the fact that we dont coalesce
1667 * updates properly with our short-circuiting of the window manager. For now we'll do a less
1668 * efficient invalidation of the entire handle which appears to fix the problem
1671 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1672 Invalidate (handle, new Rectangle (0, 0, hwnd.Width, hwnd.Height), false);
1676 internal override void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool clear) {
1677 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1678 Invalidate (handle, new Rectangle (0, 0, hwnd.Width, hwnd.Height), false);
1682 internal override void SendAsyncMethod (AsyncMethodData method) {
1684 MessageQueue.Enqueue (GCHandle.Alloc (method));
1688 internal override IntPtr SendMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
1689 return NativeWindow.WndProc(hwnd, message, wParam, lParam);
1692 internal override int SendInput(IntPtr hwnd, Queue keys) {
1697 internal override void SetCaretPos (IntPtr hwnd, int x, int y) {
1698 if (hwnd != IntPtr.Zero && hwnd == Caret.Hwnd) {
1701 ClientToScreen (hwnd, ref x, ref y);
1702 SizeWindow (new Rectangle (x, y, Caret.Width, Caret.Height), CaretWindow);
1703 Caret.Timer.Stop ();
1705 if (Caret.Visible == 1) {
1707 Caret.Timer.Start ();
1712 internal override void SetClipRegion(IntPtr hwnd, Region region) {
1713 throw new NotImplementedException();
1716 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1717 Hwnd hwnd = Hwnd.ObjectFromHandle (window);
1719 hwnd.Cursor = cursor;
1722 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1723 CGDisplayMoveCursorToPoint (CGMainDisplayID (), new Carbon.CGPoint (x, y));
1726 internal override void SetFocus(IntPtr handle) {
1727 if (FocusWindow != IntPtr.Zero) {
1728 PostMessage(FocusWindow, Msg.WM_KILLFOCUS, handle, IntPtr.Zero);
1730 PostMessage(handle, Msg.WM_SETFOCUS, FocusWindow, IntPtr.Zero);
1731 FocusWindow = handle;
1734 internal override void SetIcon(IntPtr handle, Icon icon) {
1735 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1737 // FIXME: we need to map the icon for active window switches
1738 if (WindowMapping [hwnd.Handle] != null) {
1740 RestoreApplicationDockTileImage ();
1747 bitmap = new Bitmap (128, 128);
1748 using (Graphics g = Graphics.FromImage (bitmap)) {
1749 g.DrawImage (icon.ToBitmap (), 0, 0, 128, 128);
1752 size = bitmap.Width * bitmap.Height;
1753 data = new IntPtr[size];
1755 for (int y = 0; y < bitmap.Height; y++) {
1756 for (int x = 0; x < bitmap.Width; x++) {
1757 int pixel = bitmap.GetPixel (x, y).ToArgb ();
1758 if (BitConverter.IsLittleEndian) {
1759 byte a = (byte) ((pixel >> 24) & 0xFF);
1760 byte r = (byte) ((pixel >> 16) & 0xFF);
1761 byte g = (byte) ((pixel >> 8) & 0xFF);
1762 byte b = (byte) (pixel & 0xFF);
1763 data[index++] = (IntPtr)(a + (r << 8) + (g << 16) + (b << 24));
1765 data[index++] = (IntPtr)pixel;
1770 IntPtr provider = CGDataProviderCreateWithData (IntPtr.Zero, data, size*4, IntPtr.Zero);
1771 IntPtr image = CGImageCreate (128, 128, 8, 32, 4*128, CGColorSpaceCreateDeviceRGB (), 4, provider, IntPtr.Zero, 0, 0);
1772 SetApplicationDockTileImage (image);
1778 internal override void SetModal(IntPtr handle, bool Modal) {
1779 IntPtr hWnd = HIViewGetWindow (Hwnd.ObjectFromHandle (handle).WholeWindow);
1781 BeginAppModalStateForWindow (hWnd);
1783 EndAppModalStateForWindow (hWnd);
1787 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1788 IntPtr ParentHandle = IntPtr.Zero;
1789 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1791 hwnd.Parent = Hwnd.ObjectFromHandle (parent);
1792 if (HIViewGetSuperview (hwnd.whole_window) != IntPtr.Zero) {
1793 HIViewRemoveFromSuperview (hwnd.whole_window);
1795 if (hwnd.parent == null)
1796 HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
1797 HIViewAddSubview (hwnd.parent == null ? ParentHandle : hwnd.Parent.client_window, hwnd.whole_window);
1798 HIViewPlaceInSuperviewAt (hwnd.whole_window, hwnd.X, hwnd.Y);
1799 HIViewAddSubview (hwnd.whole_window, hwnd.client_window);
1800 HIViewPlaceInSuperviewAt (hwnd.client_window, hwnd.ClientRect.X, hwnd.ClientRect.Y);
1805 internal override void SetTimer (Timer timer) {
1807 TimerList.Add (timer);
1811 internal override bool SetTopmost(IntPtr hWnd, bool Enabled) {
1812 HIViewSetZOrder (hWnd, 1, IntPtr.Zero);
1816 internal override bool SetOwner(IntPtr hWnd, IntPtr hWndOwner) {
1817 // TODO: Set window owner.
1821 internal override bool SetVisible(IntPtr handle, bool visible, bool activate) {
1822 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1823 object window = WindowMapping [hwnd.Handle];
1826 ShowWindow ((IntPtr)window);
1828 HideWindow ((IntPtr)window);
1831 SendMessage(handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1833 HIViewSetVisible (hwnd.whole_window, visible);
1834 HIViewSetVisible (hwnd.client_window, visible);
1836 hwnd.visible = visible;
1841 internal override void SetAllowDrop (IntPtr handle, bool value) {
1842 // Like X11 we allow drop on al windows and filter in our handler
1845 internal override DragDropEffects StartDrag (IntPtr handle, object data, DragDropEffects allowed_effects) {
1846 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1849 throw new ArgumentException ("Attempt to begin drag from invalid window handle (" + handle.ToInt32 () + ").");
1851 return Dnd.StartDrag (hwnd.client_window, data, allowed_effects);
1854 internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
1855 Form form = Control.FromHandle (handle) as Form;
1856 if (form != null && form.window_manager == null && (border_style == FormBorderStyle.FixedToolWindow ||
1857 border_style == FormBorderStyle.SizableToolWindow)) {
1858 form.window_manager = new ToolWindowManager (form);
1861 RequestNCRecalc(handle);
1864 internal override void SetMenu(IntPtr handle, Menu menu) {
1867 hwnd = Hwnd.ObjectFromHandle(handle);
1870 RequestNCRecalc(handle);
1873 internal override void SetWindowMinMax(IntPtr handle, Rectangle maximized, Size min, Size max) {
1876 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1877 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1883 // Win32 automatically changes negative width/height to 0.
1889 // X requires a sanity check for width & height; otherwise it dies
1890 if (hwnd.zero_sized && width > 0 && height > 0) {
1892 HIViewSetVisible(hwnd.WholeWindow, true);
1894 hwnd.zero_sized = false;
1897 if ((width < 1) || (height < 1)) {
1898 hwnd.zero_sized = true;
1899 HIViewSetVisible(hwnd.WholeWindow, false);
1902 // Save a server roundtrip (and prevent a feedback loop)
1903 if ((hwnd.x == x) && (hwnd.y == y) && (hwnd.width == width) && (hwnd.height == height)) {
1907 if (!hwnd.zero_sized) {
1911 hwnd.height = height;
1912 SendMessage(hwnd.client_window, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1914 Control ctrl = Control.FromHandle (handle);
1915 CreateParams cp = ctrl.GetCreateParams ();
1916 Size TranslatedSize = TranslateWindowSizeToQuartzWindowSize (cp, new Size (width, height));
1917 Carbon.Rect rect = new Carbon.Rect ();
1919 if (WindowMapping [hwnd.Handle] != null) {
1920 if (StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
1921 SetRect (ref rect, (short)x, (short)y, (short)(x+TranslatedSize.Width), (short)(y+TranslatedSize.Height));
1923 SetRect (ref rect, (short)x, (short)(y+MenuBarHeight), (short)(x+TranslatedSize.Width), (short)(y+MenuBarHeight+TranslatedSize.Height));
1925 SetWindowBounds ((IntPtr) WindowMapping [hwnd.Handle], 33, ref rect);
1926 Carbon.HIRect frame_rect = new Carbon.HIRect (0, 0, TranslatedSize.Width, TranslatedSize.Height);
1927 HIViewSetFrame (hwnd.whole_window, ref frame_rect);
1928 SetCaretPos (Caret.Hwnd, Caret.X, Caret.Y);
1930 Carbon.HIRect frame_rect = new Carbon.HIRect (x, y, TranslatedSize.Width, TranslatedSize.Height);
1931 HIViewSetFrame (hwnd.whole_window, ref frame_rect);
1933 PerformNCCalc(hwnd);
1939 hwnd.height = height;
1942 internal override void SetWindowState(IntPtr handle, FormWindowState state) {
1943 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1944 IntPtr window = HIViewGetWindow (handle);
1947 case FormWindowState.Minimized: {
1948 CollapseWindow (window, true);
1951 case FormWindowState.Normal: {
1952 ZoomWindow (window, 7, false);
1955 case FormWindowState.Maximized: {
1956 Form form = Control.FromHandle (hwnd.Handle) as Form;
1957 if (form != null && form.FormBorderStyle == FormBorderStyle.None) {
1958 Carbon.Rect rect = new Carbon.Rect ();
1959 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1960 SetRect (ref rect, (short)0, (short)0, (short)bounds.size.width, (short)bounds.size.height);
1961 SetWindowBounds ((IntPtr) WindowMapping [hwnd.Handle], 33, ref rect);
1962 HIViewSetFrame (hwnd.whole_window, ref bounds);
1964 ZoomWindow (window, 8, false);
1971 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1972 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1973 SetHwndStyles(hwnd, cp);
1975 if (WindowMapping [hwnd.Handle] != null) {
1976 Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
1977 if ((cp.Style & ((int)WindowStyles.WS_MINIMIZEBOX)) != 0) {
1978 attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
1980 if ((cp.Style & ((int)WindowStyles.WS_MAXIMIZEBOX)) != 0) {
1981 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
1983 if ((cp.Style & ((int)WindowStyles.WS_SYSMENU)) != 0) {
1984 attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
1986 if ((cp.ExStyle & ((int)WindowExStyles.WS_EX_TOOLWINDOW)) != 0) {
1987 attributes = Carbon.WindowAttributes.kWindowStandardHandlerAttribute | Carbon.WindowAttributes.kWindowCompositingAttribute;
1989 attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;
1991 Carbon.WindowAttributes outAttributes = Carbon.WindowAttributes.kWindowNoAttributes;
1992 GetWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], ref outAttributes);
1993 ChangeWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], attributes, outAttributes);
1997 internal override void SetWindowTransparency(IntPtr handle, double transparency, Color key) {
2000 internal override double GetWindowTransparency(IntPtr handle)
2005 internal override TransparencySupport SupportsTransparency() {
2006 return TransparencySupport.None;
2009 internal override bool SetZOrder(IntPtr handle, IntPtr after_handle, bool Top, bool Bottom) {
2010 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
2013 HIViewSetZOrder (hwnd.whole_window, 2, IntPtr.Zero);
2015 } else if (!Bottom) {
2016 Hwnd after_hwnd = Hwnd.ObjectFromHandle (after_handle);
2017 HIViewSetZOrder (hwnd.whole_window, 2, (after_handle == IntPtr.Zero ? IntPtr.Zero : after_hwnd.whole_window));
2019 HIViewSetZOrder (hwnd.whole_window, 1, IntPtr.Zero);
2025 internal override void ShowCursor(bool show) {
2027 CGDisplayShowCursor (CGMainDisplayID ());
2029 CGDisplayHideCursor (CGMainDisplayID ());
2032 internal override object StartLoop(Thread thread) {
2033 return new object ();
2037 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
2038 throw new NotImplementedException();
2042 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
2043 throw new NotImplementedException();
2047 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
2048 throw new NotImplementedException();
2053 internal override void SystrayBalloon(IntPtr hwnd, int timeout, string title, string text, ToolTipIcon icon)
2055 throw new NotImplementedException ();
2059 internal override bool Text(IntPtr handle, string text) {
2060 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
2061 if (WindowMapping [hwnd.Handle] != null) {
2062 SetWindowTitleWithCFString ((IntPtr)(WindowMapping [hwnd.Handle]), __CFStringMakeConstantString (text));
2064 SetControlTitleWithCFString (hwnd.whole_window, __CFStringMakeConstantString (text));
2065 SetControlTitleWithCFString (hwnd.client_window, __CFStringMakeConstantString (text));
2069 internal override void UpdateWindow(IntPtr handle) {
2072 hwnd = Hwnd.ObjectFromHandle(handle);
2074 if (!hwnd.visible || !HIViewIsVisible (handle)) {
2078 SendMessage(handle, Msg.WM_PAINT, IntPtr.Zero, IntPtr.Zero);
2081 internal override bool TranslateMessage(ref MSG msg) {
2082 return Carbon.EventHandler.TranslateMessage (ref msg);
2085 #region Reversible regions
2087 * Quartz has no concept of XOR drawing due to its compositing nature
2088 * We fake this by mapping a overlay window on the first draw and mapping it on the second.
2089 * This has some issues with it because its POSSIBLE for ControlPaint.DrawReversible* to actually
2090 * reverse two regions at once. We dont do this in MWF, but this behaviour woudn't work.
2091 * We could in theory cache the Rectangle/Color combination to handle this behaviour.
2093 * PROBLEMS: This has some flicker / banding
2095 internal void SizeWindow (Rectangle rect, IntPtr window) {
2096 Carbon.Rect qrect = new Carbon.Rect ();
2098 SetRect (ref qrect, (short)rect.X, (short)rect.Y, (short)(rect.X+rect.Width), (short)(rect.Y+rect.Height));
2100 SetWindowBounds (window, 33, ref qrect);
2103 internal override void DrawReversibleLine(Point start, Point end, Color backColor) {
2104 // throw new NotImplementedException();
2107 internal override void FillReversibleRectangle (Rectangle rectangle, Color backColor) {
2108 // throw new NotImplementedException();
2111 internal override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
2112 // throw new NotImplementedException();
2115 internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
2116 Rectangle size_rect = rect;
2120 if (ReverseWindowMapped) {
2121 HideWindow (ReverseWindow);
2122 ReverseWindowMapped = false;
2124 ClientToScreen(handle, ref new_x, ref new_y);
2126 size_rect.X += new_x;
2127 size_rect.Y += new_y;
2129 SizeWindow (size_rect, ReverseWindow);
2130 ShowWindow (ReverseWindow);
2137 Graphics g = Graphics.FromHwnd (HIViewGetRoot (ReverseWindow));
2139 for (int i = 0; i < line_width; i++) {
2140 g.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (Color.Black), rect);
2150 ReverseWindowMapped = true;
2155 internal override SizeF GetAutoScaleSize(Font font) {
2158 string magic_string = "The quick brown fox jumped over the lazy dog.";
2159 double magic_number = 44.549996948242189;
2161 g = Graphics.FromImage (new Bitmap (1, 1));
2163 width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
2164 return new SizeF(width, font.Height);
2167 internal override Point MousePosition {
2169 return mouse_position;
2174 #region System information
2175 internal override int KeyboardSpeed { get{ throw new NotImplementedException(); } }
2176 internal override int KeyboardDelay { get{ throw new NotImplementedException(); } }
2178 internal override int CaptionHeight {
2184 internal override Size CursorSize { get{ throw new NotImplementedException(); } }
2185 internal override bool DragFullWindows { get{ throw new NotImplementedException(); } }
2186 internal override Size DragSize {
2188 return new Size(4, 4);
2192 internal override Size FrameBorderSize {
2194 return new Size (2, 2);
2198 internal override Size IconSize { get{ throw new NotImplementedException(); } }
2199 internal override Size MaxWindowTrackSize { get{ throw new NotImplementedException(); } }
2200 internal override bool MenuAccessKeysUnderlined {
2205 internal override Size MinimizedWindowSpacingSize { get{ throw new NotImplementedException(); } }
2207 internal override Size MinimumWindowSize {
2209 return new Size(110, 22);
2213 internal override Keys ModifierKeys {
2215 return KeyboardHandler.ModifierKeys;
2218 internal override Size SmallIconSize { get{ throw new NotImplementedException(); } }
2219 internal override int MouseButtonCount { get{ throw new NotImplementedException(); } }
2220 internal override bool MouseButtonsSwapped { get{ throw new NotImplementedException(); } }
2221 internal override bool MouseWheelPresent { get{ throw new NotImplementedException(); } }
2223 internal override MouseButtons MouseButtons {
2229 internal override Rectangle VirtualScreen {
2235 internal override Rectangle WorkingArea {
2237 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
2238 return new Rectangle ((int)bounds.origin.x, (int)bounds.origin.y, (int)bounds.size.width, (int)bounds.size.height);
2241 internal override bool ThemesEnabled {
2243 return XplatUICarbon.themes_enabled;
2250 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2251 extern static int HIViewConvertPoint (ref Carbon.CGPoint point, IntPtr pView, IntPtr cView);
2252 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2253 extern static int HIViewChangeFeatures (IntPtr aView, ulong bitsin, ulong bitsout);
2254 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2255 extern static int HIViewFindByID (IntPtr rootWnd, Carbon.HIViewID id, ref IntPtr outPtr);
2256 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2257 extern static int HIGrowBoxViewSetTransparent (IntPtr GrowBox, bool transparency);
2258 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2259 extern static IntPtr HIViewGetRoot (IntPtr hWnd);
2260 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2261 extern static int HIObjectCreate (IntPtr cfStr, uint what, ref IntPtr hwnd);
2262 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2263 extern static int HIObjectRegisterSubclass (IntPtr classid, IntPtr superclassid, uint options, Carbon.EventDelegate upp, uint count, Carbon.EventTypeSpec [] list, IntPtr state, ref IntPtr cls);
2264 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2265 extern static int HIViewPlaceInSuperviewAt (IntPtr view, float x, float y);
2266 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2267 extern static int HIViewAddSubview (IntPtr parentHnd, IntPtr childHnd);
2268 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2269 extern static IntPtr HIViewGetPreviousView (IntPtr aView);
2270 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2271 extern static IntPtr HIViewGetSuperview (IntPtr aView);
2272 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2273 extern static int HIViewRemoveFromSuperview (IntPtr aView);
2274 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2275 extern static int HIViewSetVisible (IntPtr vHnd, bool visible);
2276 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2277 extern static bool HIViewIsVisible (IntPtr vHnd);
2278 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2279 extern static int HIViewGetBounds (IntPtr vHnd, ref Carbon.HIRect r);
2280 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2281 extern static int HIViewScrollRect (IntPtr vHnd, ref Carbon.HIRect rect, float x, float y);
2282 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2283 extern static int HIViewSetZOrder (IntPtr hWnd, int cmd, IntPtr oHnd);
2284 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2285 extern static int HIViewNewTrackingArea (IntPtr inView, IntPtr inShape, UInt64 inID, ref IntPtr outRef);
2286 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2287 extern static IntPtr HIViewGetWindow (IntPtr aView);
2288 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2289 extern static int HIViewSetFrame (IntPtr view_handle, ref Carbon.HIRect bounds);
2290 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2291 internal extern static int HIViewSetNeedsDisplayInRect (IntPtr view_handle, ref Carbon.HIRect rect, bool needs_display);
2293 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2294 extern static void SetRect (ref Carbon.Rect r, short left, short top, short right, short bottom);
2295 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2296 static extern int ActivateWindow (IntPtr windowHnd, bool inActivate);
2297 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2298 static extern bool IsWindowActive (IntPtr windowHnd);
2299 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2300 static extern int SetAutomaticControlDragTrackingEnabledForWindow (IntPtr window, bool enabled);
2302 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2303 extern static IntPtr GetEventDispatcherTarget ();
2304 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2305 extern static int SendEventToEventTarget (IntPtr evt, IntPtr target);
2306 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2307 extern static int ReleaseEvent (IntPtr evt);
2308 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2309 extern static int ReceiveNextEvent (uint evtCount, IntPtr evtTypes, double timeout, bool processEvt, ref IntPtr evt);
2311 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2312 extern static bool IsWindowCollapsed (IntPtr hWnd);
2313 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2314 extern static bool IsWindowInStandardState (IntPtr hWnd, IntPtr a, IntPtr b);
2315 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2316 extern static void CollapseWindow (IntPtr hWnd, bool collapse);
2317 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2318 extern static void ZoomWindow (IntPtr hWnd, short partCode, bool front);
2319 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2320 extern static int GetWindowAttributes (IntPtr hWnd, ref Carbon.WindowAttributes outAttributes);
2321 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2322 extern static int ChangeWindowAttributes (IntPtr hWnd, Carbon.WindowAttributes inAttributes, Carbon.WindowAttributes outAttributes);
2323 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2324 internal extern static int GetGlobalMouse (ref Carbon.QDPoint outData);
2326 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2327 extern static int BeginAppModalStateForWindow (IntPtr window);
2328 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2329 extern static int EndAppModalStateForWindow (IntPtr window);
2330 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2331 extern static int CreateNewWindow (Carbon.WindowClass klass, Carbon.WindowAttributes attributes, ref Carbon.Rect r, ref IntPtr window);
2332 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2333 extern static int DisposeWindow (IntPtr wHnd);
2334 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2335 internal extern static int ShowWindow (IntPtr wHnd);
2336 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2337 internal extern static int HideWindow (IntPtr wHnd);
2338 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2339 internal extern static bool IsWindowVisible (IntPtr wHnd);
2340 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2341 extern static int SetWindowBounds (IntPtr wHnd, uint reg, ref Carbon.Rect rect);
2342 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2343 extern static int GetWindowBounds (IntPtr wHnd, uint reg, ref Carbon.Rect rect);
2345 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2346 extern static int SetControlTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
2347 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2348 extern static int SetWindowTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
2349 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2350 internal extern static IntPtr __CFStringMakeConstantString (string cString);
2352 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2353 internal extern static int CFRelease (IntPtr wHnd);
2354 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2355 extern static short GetMBarHeight ();
2357 #region Cursor imports
2358 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2359 extern static Carbon.HIRect CGDisplayBounds (IntPtr displayID);
2360 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2361 extern static IntPtr CGMainDisplayID ();
2362 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2363 extern static void CGDisplayShowCursor (IntPtr display);
2364 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2365 extern static void CGDisplayHideCursor (IntPtr display);
2366 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2367 extern static void CGDisplayMoveCursorToPoint (IntPtr display, Carbon.CGPoint point);
2370 #region Process imports
2371 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2372 extern static int GetCurrentProcess (ref Carbon.ProcessSerialNumber psn);
2373 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2374 extern static int TransformProcessType (ref Carbon.ProcessSerialNumber psn, uint type);
2375 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2376 extern static int SetFrontProcess (ref Carbon.ProcessSerialNumber psn);
2379 #region Dock tile imports
2380 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2381 extern static IntPtr CGColorSpaceCreateDeviceRGB();
2382 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2383 extern static IntPtr CGDataProviderCreateWithData (IntPtr info, IntPtr [] data, int size, IntPtr releasefunc);
2384 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2385 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);
2386 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2387 extern static void SetApplicationDockTileImage(IntPtr imageRef);
2388 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2389 extern static void RestoreApplicationDockTileImage();