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);
145 while (MessageQueue.Count > 0) {
146 object queueobj = MessageQueue.Dequeue ();
147 if (queueobj is GCHandle) {
148 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)queueobj);
150 MSG msg = (MSG)queueobj;
151 NativeWindow.WndProc (msg.hwnd, msg.message, msg.wParam, msg.lParam);
157 internal static Rectangle [] GetClippingRectangles (IntPtr handle) {
158 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
162 if (hwnd.Handle != handle)
163 return new Rectangle [] {hwnd.ClientRect};
165 return (Rectangle []) hwnd.GetClippingRectangles ().ToArray (typeof (Rectangle));
168 internal IntPtr GetMousewParam(int Delta) {
171 if ((MouseState & MouseButtons.Left) != 0) {
172 result |= (int)MsgButtons.MK_LBUTTON;
175 if ((MouseState & MouseButtons.Middle) != 0) {
176 result |= (int)MsgButtons.MK_MBUTTON;
179 if ((MouseState & MouseButtons.Right) != 0) {
180 result |= (int)MsgButtons.MK_RBUTTON;
183 Keys mods = ModifierKeys;
184 if ((mods & Keys.Control) != 0) {
185 result |= (int)MsgButtons.MK_CONTROL;
188 if ((mods & Keys.Shift) != 0) {
189 result |= (int)MsgButtons.MK_SHIFT;
192 result |= Delta << 16;
194 return (IntPtr)result;
197 internal IntPtr HandleToWindow (IntPtr handle) {
198 if (HandleMapping [handle] != null)
199 return (IntPtr) HandleMapping [handle];
203 internal void Initialize () {
204 // Initialize the event handlers
205 Carbon.EventHandler.Driver = this;
206 ApplicationHandler = new Carbon.ApplicationHandler (this);
207 ControlHandler = new Carbon.ControlHandler (this);
208 HIObjectHandler = new Carbon.HIObjectHandler (this);
209 KeyboardHandler = new Carbon.KeyboardHandler (this);
210 MouseHandler = new Carbon.MouseHandler (this);
211 WindowHandler = new Carbon.WindowHandler (this);
213 // Initilize the mouse controls
214 Hover.Interval = 500;
215 Hover.Timer = new Timer ();
216 Hover.Timer.Enabled = false;
217 Hover.Timer.Interval = Hover.Interval;
218 Hover.Timer.Tick += new EventHandler (HoverCallback);
221 MouseState = MouseButtons.None;
222 mouse_position = Point.Empty;
224 // Initialize the Caret
225 Caret.Timer = new Timer ();
226 Caret.Timer.Interval = 500;
227 Caret.Timer.Tick += new EventHandler (CaretCallback);
229 // Initialize the D&D
230 Dnd = new Carbon.Dnd ();
232 // Initialize the Carbon Specific stuff
233 WindowMapping = new Hashtable ();
234 HandleMapping = new Hashtable ();
235 UtilityWindows = new ArrayList ();
237 // Initialize the FosterParent
238 Carbon.Rect rect = new Carbon.Rect ();
239 SetRect (ref rect, (short)0, (short)0, (short)0, (short)0);
240 Carbon.ProcessSerialNumber psn = new Carbon.ProcessSerialNumber();
242 GetCurrentProcess( ref psn );
243 TransformProcessType (ref psn, 1);
244 SetFrontProcess (ref psn);
246 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);
248 Carbon.EventHandler.InstallApplicationHandler ();
250 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);
252 CreateNewWindow (Carbon.WindowClass.kOverlayWindowClass, Carbon.WindowAttributes.kWindowNoUpdatesAttribute | Carbon.WindowAttributes.kWindowNoActivatesAttribute, ref rect, ref ReverseWindow);
253 CreateNewWindow (Carbon.WindowClass.kOverlayWindowClass, Carbon.WindowAttributes.kWindowNoUpdatesAttribute | Carbon.WindowAttributes.kWindowNoActivatesAttribute, ref rect, ref CaretWindow);
255 // Get some values about bar heights
256 Carbon.Rect structRect = new Carbon.Rect ();
257 Carbon.Rect contentRect = new Carbon.Rect ();
258 GetWindowBounds (FosterParent, 32, ref structRect);
259 GetWindowBounds (FosterParent, 33, ref contentRect);
261 MenuBarHeight = GetMBarHeight ();
264 FocusWindow = IntPtr.Zero;
267 GetMessageResult = true;
269 ReverseWindowMapped = false;
272 internal void PerformNCCalc(Hwnd hwnd) {
273 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
277 rect = new Rectangle (0, 0, hwnd.Width, hwnd.Height);
279 ncp = new XplatUIWin32.NCCALCSIZE_PARAMS();
280 ptr = Marshal.AllocHGlobal(Marshal.SizeOf(ncp));
282 ncp.rgrc1.left = rect.Left;
283 ncp.rgrc1.top = rect.Top;
284 ncp.rgrc1.right = rect.Right;
285 ncp.rgrc1.bottom = rect.Bottom;
287 Marshal.StructureToPtr(ncp, ptr, true);
288 NativeWindow.WndProc(hwnd.client_window, Msg.WM_NCCALCSIZE, (IntPtr)1, ptr);
289 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure(ptr, typeof(XplatUIWin32.NCCALCSIZE_PARAMS));
290 Marshal.FreeHGlobal(ptr);
293 rect = new Rectangle(ncp.rgrc1.left, ncp.rgrc1.top, ncp.rgrc1.right - ncp.rgrc1.left, ncp.rgrc1.bottom - ncp.rgrc1.top);
294 hwnd.ClientRect = rect;
296 rect = TranslateClientRectangleToQuartzClientRectangle (hwnd);
299 Carbon.HIRect r = new Carbon.HIRect (rect.X, rect.Y, rect.Width, rect.Height);
300 HIViewSetFrame (hwnd.client_window, ref r);
303 AddExpose (hwnd, false, 0, 0, hwnd.Width, hwnd.Height);
306 internal void ScreenToClient(IntPtr handle, ref Carbon.QDPoint point) {
307 int x = (int) point.x;
308 int y = (int) point.y;
310 ScreenToClient (handle, ref x, ref y);
316 internal static Rectangle TranslateClientRectangleToQuartzClientRectangle (Hwnd hwnd) {
317 return TranslateClientRectangleToQuartzClientRectangle (hwnd, Control.FromHandle (hwnd.Handle));
320 internal static Rectangle TranslateClientRectangleToQuartzClientRectangle (Hwnd hwnd, Control ctrl) {
322 * If this is a form with no window manager, X is handling all the border and caption painting
323 * so remove that from the area (since the area we set of the window here is the part of the window
324 * we're painting in only)
326 Rectangle rect = hwnd.ClientRect;
327 Form form = ctrl as Form;
328 CreateParams cp = null;
331 cp = form.GetCreateParams ();
333 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
334 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
335 Rectangle qrect = rect;
337 qrect.Y -= borders.top;
338 qrect.X -= borders.left;
339 qrect.Width += borders.left + borders.right;
340 qrect.Height += borders.top + borders.bottom;
345 if (rect.Width < 1 || rect.Height < 1) {
355 internal static Size TranslateWindowSizeToQuartzWindowSize (CreateParams cp) {
356 return TranslateWindowSizeToQuartzWindowSize (cp, new Size (cp.Width, cp.Height));
359 internal static Size TranslateWindowSizeToQuartzWindowSize (CreateParams cp, Size size) {
361 * If this is a form with no window manager, X is handling all the border and caption painting
362 * so remove that from the area (since the area we set of the window here is the part of the window
363 * we're painting in only)
365 Form form = cp.control as Form;
366 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
367 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
370 qsize.Width -= borders.left + borders.right;
371 qsize.Height -= borders.top + borders.bottom;
376 if (size.Height == 0)
383 internal static Size TranslateQuartzWindowSizeToWindowSize (CreateParams cp, int width, int height) {
385 * If this is a form with no window manager, X is handling all the border and caption painting
386 * so remove that from the area (since the area we set of the window here is the part of the window
387 * we're painting in only)
389 Size size = new Size (width, height);
390 Form form = cp.control as Form;
391 if (form != null && (form.window_manager == null || cp.IsSet (WindowExStyles.WS_EX_TOOLWINDOW))) {
392 Hwnd.Borders borders = Hwnd.GetBorders (cp, null);
395 qsize.Width += borders.left + borders.right;
396 qsize.Height += borders.top + borders.bottom;
406 private void CaretCallback (object sender, EventArgs e) {
418 private void HoverCallback (object sender, EventArgs e) {
419 if ((Hover.X == mouse_position.X) && (Hover.Y == mouse_position.Y)) {
420 MSG msg = new MSG ();
421 msg.hwnd = Hover.Hwnd;
422 msg.message = Msg.WM_MOUSEHOVER;
423 msg.wParam = GetMousewParam (0);
424 msg.lParam = (IntPtr)((ushort)Hover.X << 16 | (ushort)Hover.X);
425 EnqueueMessage (msg);
430 #region Private Methods
431 private Point ConvertScreenPointToClient (IntPtr handle, Point point) {
432 Point converted_point = new Point ();
433 Carbon.Rect window_bounds = new Carbon.Rect ();
434 Carbon.CGPoint native_point = new Carbon.CGPoint ();
436 GetWindowBounds (HIViewGetWindow (handle), 32, ref window_bounds);
438 native_point.x = (point.X - window_bounds.left);
439 native_point.y = (point.Y - window_bounds.top);
441 HIViewConvertPoint (ref native_point, IntPtr.Zero, handle);
443 converted_point.X = (int)native_point.x;
444 converted_point.Y = (int)native_point.y;
446 return converted_point;
449 private Point ConvertClientPointToScreen (IntPtr handle, Point point) {
450 Point converted_point = new Point ();
451 Carbon.Rect window_bounds = new Carbon.Rect ();
452 Carbon.CGPoint native_point = new Carbon.CGPoint ();
454 GetWindowBounds (HIViewGetWindow (handle), 32, ref window_bounds);
456 native_point.x = point.X;
457 native_point.y = point.Y;
459 HIViewConvertPoint (ref native_point, handle, IntPtr.Zero);
461 converted_point.X = (int)(native_point.x + window_bounds.left);
462 converted_point.Y = (int)(native_point.y + window_bounds.top);
464 return converted_point;
467 private double NextTimeout () {
468 DateTime now = DateTime.UtcNow;
469 int timeout = 0x7FFFFFF;
471 foreach (Timer timer in TimerList) {
472 int next = (int) (timer.Expires - now).TotalMilliseconds;
479 if (timeout < Timer.Minimum)
480 timeout = Timer.Minimum;
482 return (double)((double)timeout/1000);
485 private void CheckTimers (DateTime now) {
487 int count = TimerList.Count;
490 for (int i = 0; i < TimerList.Count; i++) {
491 Timer timer = (Timer) TimerList [i];
492 if (timer.Enabled && timer.Expires <= now) {
494 // - Before MainForm.OnLoad if DoEvents () is called.
495 // - After MainForm.OnLoad if not.
498 (Application.MWFThread.Current.Context != null &&
499 Application.MWFThread.Current.Context.MainForm != null &&
500 Application.MWFThread.Current.Context.MainForm.IsLoaded)) {
509 private void WaitForHwndMessage (Hwnd hwnd, Msg message) {
510 MSG msg = new MSG ();
514 if (GetMessage(null, ref msg, IntPtr.Zero, 0, 0)) {
515 if ((Msg)msg.message == Msg.WM_QUIT) {
520 if (msg.hwnd == hwnd.Handle) {
521 if ((Msg)msg.message == message)
523 else if ((Msg)msg.message == Msg.WM_DESTROY)
527 TranslateMessage (ref msg);
528 DispatchMessage (ref msg);
534 private void SendParentNotify(IntPtr child, Msg cause, int x, int y) {
537 if (child == IntPtr.Zero) {
541 hwnd = Hwnd.GetObjectFromWindow (child);
547 if (hwnd.Handle == IntPtr.Zero) {
551 if (ExStyleSet ((int) hwnd.initial_ex_style, WindowExStyles.WS_EX_NOPARENTNOTIFY)) {
555 if (hwnd.Parent == null) {
559 if (hwnd.Parent.Handle == IntPtr.Zero) {
563 if (cause == Msg.WM_CREATE || cause == Msg.WM_DESTROY) {
564 SendMessage(hwnd.Parent.Handle, Msg.WM_PARENTNOTIFY, Control.MakeParam((int)cause, 0), child);
566 SendMessage(hwnd.Parent.Handle, Msg.WM_PARENTNOTIFY, Control.MakeParam((int)cause, 0), Control.MakeParam(x, y));
569 SendParentNotify (hwnd.Parent.Handle, cause, x, y);
572 private bool StyleSet (int s, WindowStyles ws) {
573 return (s & (int)ws) == (int)ws;
576 private bool ExStyleSet (int ex, WindowExStyles exws) {
577 return (ex & (int)exws) == (int)exws;
580 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) {
583 tool_caption_height = 0;
584 border_static = false;
586 if (StyleSet (Style, WindowStyles.WS_CHILD)) {
587 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_CLIENTEDGE)) {
588 border_style = FormBorderStyle.Fixed3D;
589 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_STATICEDGE)) {
590 border_style = FormBorderStyle.Fixed3D;
591 border_static = true;
592 } else if (!StyleSet (Style, WindowStyles.WS_BORDER)) {
593 border_style = FormBorderStyle.None;
595 border_style = FormBorderStyle.FixedSingle;
597 title_style = TitleStyle.None;
599 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
601 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
602 title_style = TitleStyle.Tool;
604 title_style = TitleStyle.Normal;
608 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_MDICHILD)) {
611 if (StyleSet (Style, WindowStyles.WS_OVERLAPPEDWINDOW) ||
612 ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
613 border_style = (FormBorderStyle) 0xFFFF;
615 border_style = FormBorderStyle.None;
620 title_style = TitleStyle.None;
621 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
622 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
623 title_style = TitleStyle.Tool;
625 title_style = TitleStyle.Normal;
629 border_style = FormBorderStyle.None;
631 if (StyleSet (Style, WindowStyles.WS_THICKFRAME)) {
632 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
633 border_style = FormBorderStyle.SizableToolWindow;
635 border_style = FormBorderStyle.Sizable;
638 if (StyleSet (Style, WindowStyles.WS_CAPTION)) {
639 if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_CLIENTEDGE)) {
640 border_style = FormBorderStyle.Fixed3D;
641 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_STATICEDGE)) {
642 border_style = FormBorderStyle.Fixed3D;
643 border_static = true;
644 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_DLGMODALFRAME)) {
645 border_style = FormBorderStyle.FixedDialog;
646 } else if (ExStyleSet (ExStyle, WindowExStyles.WS_EX_TOOLWINDOW)) {
647 border_style = FormBorderStyle.FixedToolWindow;
648 } else if (StyleSet (Style, WindowStyles.WS_BORDER)) {
649 border_style = FormBorderStyle.FixedSingle;
652 if (StyleSet (Style, WindowStyles.WS_BORDER)) {
653 border_style = FormBorderStyle.FixedSingle;
660 private void SetHwndStyles(Hwnd hwnd, CreateParams cp) {
661 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);
664 private void ShowCaret () {
668 ShowWindow (CaretWindow);
669 Graphics g = Graphics.FromHwnd (HIViewGetRoot (CaretWindow));
671 g.FillRectangle (new SolidBrush (Color.Black), new Rectangle (0, 0, Caret.Width, Caret.Height));
676 private void HideCaret () {
680 HideWindow (CaretWindow);
683 private void AccumulateDestroyedHandles (Control c, ArrayList list) {
685 Control[] controls = c.Controls.GetAllControls ();
687 if (c.IsHandleCreated && !c.IsDisposed) {
688 Hwnd hwnd = Hwnd.ObjectFromHandle(c.Handle);
691 CleanupCachedWindows (hwnd);
694 for (int i = 0; i < controls.Length; i ++) {
695 AccumulateDestroyedHandles (controls[i], list);
701 private void CleanupCachedWindows (Hwnd hwnd) {
702 if (ActiveWindow == hwnd.Handle) {
703 SendMessage(hwnd.client_window, Msg.WM_ACTIVATE, (IntPtr)WindowActiveFlags.WA_INACTIVE, IntPtr.Zero);
704 ActiveWindow = IntPtr.Zero;
707 if (FocusWindow == hwnd.Handle) {
708 SendMessage(hwnd.client_window, Msg.WM_KILLFOCUS, IntPtr.Zero, IntPtr.Zero);
709 FocusWindow = IntPtr.Zero;
712 if (Grab.Hwnd == hwnd.Handle) {
713 Grab.Hwnd = IntPtr.Zero;
714 Grab.Confined = false;
717 DestroyCaret (hwnd.Handle);
720 private void AddExpose (Hwnd hwnd, bool client, int x, int y, int width, int height) {
722 if ((hwnd == null) || (x > hwnd.Width) || (y > hwnd.Height) || ((x + width) < 0) || ((y + height) < 0)) {
726 // Keep the invalid area as small as needed
727 if ((x + width) > hwnd.width) {
728 width = hwnd.width - x;
731 if ((y + height) > hwnd.height) {
732 height = hwnd.height - y;
736 hwnd.AddInvalidArea(x, y, width, height);
737 if (!hwnd.expose_pending && hwnd.visible) {
738 MSG msg = new MSG ();
739 msg.message = Msg.WM_PAINT;
740 msg.hwnd = hwnd.Handle;
741 EnqueueMessage (msg);
742 hwnd.expose_pending = true;
745 hwnd.AddNcInvalidArea (x, y, width, height);
746 if (!hwnd.nc_expose_pending && hwnd.visible) {
747 MSG msg = new MSG ();
748 Region rgn = new Region (hwnd.Invalid);
749 IntPtr hrgn = rgn.GetHrgn (null); // Graphics object isn't needed
750 msg.message = Msg.WM_NCPAINT;
751 msg.wParam = hrgn == IntPtr.Zero ? (IntPtr)1 : hrgn;
753 msg.hwnd = hwnd.Handle;
754 EnqueueMessage (msg);
755 hwnd.nc_expose_pending = true;
762 #region Public Methods
763 internal void EnqueueMessage (MSG msg) {
765 MessageQueue.Enqueue (msg);
769 internal override void RaiseIdle (EventArgs e)
775 internal override IntPtr InitializeDriver() {
779 internal override void ShutdownDriver(IntPtr token) {
782 internal override void EnableThemes() {
783 themes_enabled = true;
786 internal override void Activate(IntPtr handle) {
787 if (ActiveWindow != IntPtr.Zero) {
788 ActivateWindow (HIViewGetWindow (ActiveWindow), false);
790 ActivateWindow (HIViewGetWindow (handle), true);
791 ActiveWindow = handle;
794 internal override void AudibleAlert() {
795 throw new NotImplementedException();
798 internal override void CaretVisible (IntPtr hwnd, bool visible) {
799 if (Caret.Hwnd == hwnd) {
801 if (Caret.Visible < 1) {
804 if (Caret.Visible == 1) {
806 Caret.Timer.Start ();
811 if (Caret.Visible == 0) {
819 internal override bool CalculateWindowRect(ref Rectangle ClientRect, CreateParams cp, Menu menu, out Rectangle WindowRect) {
820 WindowRect = Hwnd.GetWindowRectangle (cp, menu, ClientRect);
824 internal override void ClientToScreen(IntPtr handle, ref int x, ref int y) {
825 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
827 Point point = ConvertClientPointToScreen (hwnd.ClientWindow, new Point (x, y));
833 internal override void MenuToScreen(IntPtr handle, ref int x, ref int y) {
834 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
836 Point point = ConvertClientPointToScreen (hwnd.ClientWindow, new Point (x, y));
842 internal override int[] ClipboardAvailableFormats(IntPtr handle) {
843 ArrayList list = new ArrayList ();
844 DataFormats.Format f = DataFormats.Format.List;
851 return (int [])list.ToArray (typeof (int));
854 internal override void ClipboardClose(IntPtr handle) {
857 //TODO: Map our internal formats to the right os code where we can
858 internal override int ClipboardGetID(IntPtr handle, string format) {
859 return (int)__CFStringMakeConstantString (format);
862 internal override IntPtr ClipboardOpen(bool primary_selection) {
863 if (primary_selection)
864 return Carbon.Pasteboard.Primary;
865 return Carbon.Pasteboard.Application;
868 internal override object ClipboardRetrieve(IntPtr handle, int type, XplatUI.ClipboardToObject converter) {
869 return Carbon.Pasteboard.Retrieve (handle, type);
872 internal override void ClipboardStore(IntPtr handle, object obj, int type, XplatUI.ObjectToClipboard converter) {
873 Carbon.Pasteboard.Store (handle, obj, type);
876 internal override void CreateCaret (IntPtr hwnd, int width, int height) {
877 if (Caret.Hwnd != IntPtr.Zero)
878 DestroyCaret (Caret.Hwnd);
882 Caret.Height = height;
887 internal override IntPtr CreateWindow(CreateParams cp) {
889 Hwnd parent_hwnd = null;
898 IntPtr WholeWindowTracking;
899 IntPtr ClientWindowTracking;
907 ParentHandle = IntPtr.Zero;
908 WindowHandle = IntPtr.Zero;
909 WholeWindow = IntPtr.Zero;
910 ClientWindow = IntPtr.Zero;
911 WholeWindowTracking = IntPtr.Zero;
912 ClientWindowTracking = IntPtr.Zero;
914 if (Width < 1) Width = 1;
915 if (Height < 1) Height = 1;
917 if (cp.Parent != IntPtr.Zero) {
918 parent_hwnd = Hwnd.ObjectFromHandle (cp.Parent);
919 ParentHandle = parent_hwnd.client_window;
921 if (StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
922 HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
927 if (cp.control is Form) {
928 next = Hwnd.GetNextStackedFormLocation (cp, parent_hwnd);
936 hwnd.height = Height;
937 hwnd.Parent = Hwnd.ObjectFromHandle (cp.Parent);
938 hwnd.initial_style = cp.WindowStyle;
939 hwnd.initial_ex_style = cp.WindowExStyle;
940 hwnd.visible = false;
942 if (StyleSet (cp.Style, WindowStyles.WS_DISABLED)) {
943 hwnd.enabled = false;
946 ClientWindow = IntPtr.Zero;
948 Size QWindowSize = TranslateWindowSizeToQuartzWindowSize (cp);
949 Rectangle QClientRect = TranslateClientRectangleToQuartzClientRectangle (hwnd, cp.control);
951 SetHwndStyles(hwnd, cp);
953 if (ParentHandle == IntPtr.Zero) {
954 IntPtr WindowView = IntPtr.Zero;
955 IntPtr GrowBox = IntPtr.Zero;
956 Carbon.WindowClass windowklass = Carbon.WindowClass.kOverlayWindowClass;
957 Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
958 if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZEBOX)) {
959 attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
961 if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZEBOX)) {
962 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
964 if (StyleSet (cp.Style, WindowStyles.WS_SYSMENU)) {
965 attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
967 if (StyleSet (cp.Style, WindowStyles.WS_CAPTION)) {
968 windowklass = Carbon.WindowClass.kDocumentWindowClass;
970 if (hwnd.border_style == FormBorderStyle.FixedToolWindow) {
971 windowklass = Carbon.WindowClass.kUtilityWindowClass;
972 } else if (hwnd.border_style == FormBorderStyle.SizableToolWindow) {
973 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute;
974 windowklass = Carbon.WindowClass.kUtilityWindowClass;
976 if (windowklass == Carbon.WindowClass.kOverlayWindowClass) {
977 attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
979 attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;
981 Carbon.Rect rect = new Carbon.Rect ();
982 if (StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
983 SetRect (ref rect, (short)X, (short)(Y), (short)(X + QWindowSize.Width), (short)(Y + QWindowSize.Height));
985 SetRect (ref rect, (short)X, (short)(Y + MenuBarHeight), (short)(X + QWindowSize.Width), (short)(Y + MenuBarHeight + QWindowSize.Height));
988 CreateNewWindow (windowklass, attributes, ref rect, ref WindowHandle);
990 Carbon.EventHandler.InstallWindowHandler (WindowHandle);
991 HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref WindowView);
992 HIViewFindByID (HIViewGetRoot (WindowHandle), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 7), ref GrowBox);
993 HIGrowBoxViewSetTransparent (GrowBox, true);
994 SetAutomaticControlDragTrackingEnabledForWindow (WindowHandle, true);
995 ParentHandle = WindowView;
998 HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref WholeWindow);
999 HIObjectCreate (__CFStringMakeConstantString ("com.novell.mwfview"), 0, ref ClientWindow);
1001 Carbon.EventHandler.InstallControlHandler (WholeWindow);
1002 Carbon.EventHandler.InstallControlHandler (ClientWindow);
1004 // Enable embedding on controls
1005 HIViewChangeFeatures (WholeWindow, 1<<1, 0);
1006 HIViewChangeFeatures (ClientWindow, 1<<1, 0);
1008 HIViewNewTrackingArea (WholeWindow, IntPtr.Zero, (UInt64)WholeWindow, ref WholeWindowTracking);
1009 HIViewNewTrackingArea (ClientWindow, IntPtr.Zero, (UInt64)ClientWindow, ref ClientWindowTracking);
1010 Carbon.HIRect WholeRect;
1011 if (WindowHandle != IntPtr.Zero) {
1012 WholeRect = new Carbon.HIRect (0, 0, QWindowSize.Width, QWindowSize.Height);
1014 WholeRect = new Carbon.HIRect (X, Y, QWindowSize.Width, QWindowSize.Height);
1016 Carbon.HIRect ClientRect = new Carbon.HIRect (QClientRect.X, QClientRect.Y, QClientRect.Width, QClientRect.Height);
1017 HIViewSetFrame (WholeWindow, ref WholeRect);
1018 HIViewSetFrame (ClientWindow, ref ClientRect);
1020 HIViewAddSubview (ParentHandle, WholeWindow);
1021 HIViewAddSubview (WholeWindow, ClientWindow);
1023 hwnd.WholeWindow = WholeWindow;
1024 hwnd.ClientWindow = ClientWindow;
1026 if (WindowHandle != IntPtr.Zero) {
1027 WindowMapping [hwnd.Handle] = WindowHandle;
1028 HandleMapping [WindowHandle] = hwnd.Handle;
1029 if (hwnd.border_style == FormBorderStyle.FixedToolWindow || hwnd.border_style == FormBorderStyle.SizableToolWindow) {
1030 UtilityWindows.Add (WindowHandle);
1034 // Allow dnd on controls
1035 Dnd.SetAllowDrop (hwnd, true);
1037 Text (hwnd.Handle, cp.Caption);
1039 SendMessage (hwnd.Handle, Msg.WM_CREATE, (IntPtr)1, IntPtr.Zero /* XXX unused */);
1040 SendParentNotify (hwnd.Handle, Msg.WM_CREATE, int.MaxValue, int.MaxValue);
1042 if (StyleSet (cp.Style, WindowStyles.WS_VISIBLE)) {
1043 if (WindowHandle != IntPtr.Zero) {
1044 if (Control.FromHandle(hwnd.Handle) is Form) {
1045 Form f = Control.FromHandle(hwnd.Handle) as Form;
1046 if (f.WindowState == FormWindowState.Normal) {
1047 SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
1050 ShowWindow (WindowHandle);
1051 WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
1053 HIViewSetVisible (WholeWindow, true);
1054 HIViewSetVisible (ClientWindow, true);
1055 hwnd.visible = true;
1056 if (!(Control.FromHandle(hwnd.Handle) is Form)) {
1057 SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, (IntPtr)1, IntPtr.Zero);
1061 if (StyleSet (cp.Style, WindowStyles.WS_MINIMIZE)) {
1062 SetWindowState(hwnd.Handle, FormWindowState.Minimized);
1063 } else if (StyleSet (cp.Style, WindowStyles.WS_MAXIMIZE)) {
1064 SetWindowState(hwnd.Handle, FormWindowState.Maximized);
1070 internal override IntPtr CreateWindow(IntPtr Parent, int X, int Y, int Width, int Height) {
1071 CreateParams create_params = new CreateParams();
1073 create_params.Caption = "";
1074 create_params.X = X;
1075 create_params.Y = Y;
1076 create_params.Width = Width;
1077 create_params.Height = Height;
1079 create_params.ClassName=XplatUI.DefaultClassName;
1080 create_params.ClassStyle = 0;
1081 create_params.ExStyle=0;
1082 create_params.Parent=IntPtr.Zero;
1083 create_params.Param=0;
1085 return CreateWindow(create_params);
1088 internal override Bitmap DefineStdCursorBitmap (StdCursor id) {
1089 return Carbon.Cursor.DefineStdCursorBitmap (id);
1092 internal override IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
1093 return Carbon.Cursor.DefineCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
1096 internal override IntPtr DefineStdCursor (StdCursor id) {
1097 return Carbon.Cursor.DefineStdCursor (id);
1100 internal override IntPtr DefWndProc(ref Message msg) {
1101 Hwnd hwnd = Hwnd.ObjectFromHandle (msg.HWnd);
1102 switch ((Msg)msg.Msg) {
1104 if (WindowMapping [hwnd.Handle] != null)
1109 case Msg.WM_PAINT: {
1110 hwnd.expose_pending = false;
1113 case Msg.WM_NCPAINT: {
1114 hwnd.nc_expose_pending = false;
1117 case Msg.WM_NCCALCSIZE: {
1118 if (msg.WParam == (IntPtr)1) {
1119 XplatUIWin32.NCCALCSIZE_PARAMS ncp;
1120 ncp = (XplatUIWin32.NCCALCSIZE_PARAMS)Marshal.PtrToStructure (msg.LParam, typeof (XplatUIWin32.NCCALCSIZE_PARAMS));
1122 // Add all the stuff X is supposed to draw.
1123 Control ctrl = Control.FromHandle (hwnd.Handle);
1125 Hwnd.Borders rect = Hwnd.GetBorders (ctrl.GetCreateParams (), null);
1127 ncp.rgrc1.top += rect.top;
1128 ncp.rgrc1.bottom -= rect.bottom;
1129 ncp.rgrc1.left += rect.left;
1130 ncp.rgrc1.right -= rect.right;
1132 Marshal.StructureToPtr (ncp, msg.LParam, true);
1137 case Msg.WM_SETCURSOR: {
1138 // Pass to parent window first
1139 while ((hwnd.parent != null) && (msg.Result == IntPtr.Zero)) {
1141 msg.Result = NativeWindow.WndProc(hwnd.Handle, Msg.WM_SETCURSOR, msg.HWnd, msg.LParam);
1144 if (msg.Result == IntPtr.Zero) {
1147 switch((HitTest)(msg.LParam.ToInt32() & 0xffff)) {
1148 case HitTest.HTBOTTOM: handle = Cursors.SizeNS.handle; break;
1149 case HitTest.HTBORDER: handle = Cursors.SizeNS.handle; break;
1150 case HitTest.HTBOTTOMLEFT: handle = Cursors.SizeNESW.handle; break;
1151 case HitTest.HTBOTTOMRIGHT: handle = Cursors.SizeNWSE.handle; break;
1152 case HitTest.HTERROR: if ((msg.LParam.ToInt32() >> 16) == (int)Msg.WM_LBUTTONDOWN) {
1153 //FIXME: AudibleAlert();
1155 handle = Cursors.Default.handle;
1158 case HitTest.HTHELP: handle = Cursors.Help.handle; break;
1159 case HitTest.HTLEFT: handle = Cursors.SizeWE.handle; break;
1160 case HitTest.HTRIGHT: handle = Cursors.SizeWE.handle; break;
1161 case HitTest.HTTOP: handle = Cursors.SizeNS.handle; break;
1162 case HitTest.HTTOPLEFT: handle = Cursors.SizeNWSE.handle; break;
1163 case HitTest.HTTOPRIGHT: handle = Cursors.SizeNESW.handle; break;
1166 case HitTest.HTGROWBOX:
1167 case HitTest.HTSIZE:
1168 case HitTest.HTZOOM:
1169 case HitTest.HTVSCROLL:
1170 case HitTest.HTSYSMENU:
1171 case HitTest.HTREDUCE:
1172 case HitTest.HTNOWHERE:
1173 case HitTest.HTMAXBUTTON:
1174 case HitTest.HTMINBUTTON:
1175 case HitTest.HTMENU:
1176 case HitTest.HSCROLL:
1177 case HitTest.HTBOTTOM:
1178 case HitTest.HTCAPTION:
1179 case HitTest.HTCLIENT:
1180 case HitTest.HTCLOSE:
1182 default: handle = Cursors.Default.handle; break;
1184 SetCursor(msg.HWnd, handle);
1192 internal override void DestroyCaret (IntPtr hwnd) {
1193 if (Caret.Hwnd == hwnd) {
1194 if (Caret.Visible == 1) {
1195 Caret.Timer.Stop ();
1198 Caret.Hwnd = IntPtr.Zero;
1205 internal override void DestroyCursor(IntPtr cursor) {
1206 throw new NotImplementedException ();
1209 internal override void DestroyWindow(IntPtr handle) {
1212 hwnd = Hwnd.ObjectFromHandle(handle);
1218 SendParentNotify (hwnd.Handle, Msg.WM_DESTROY, int.MaxValue, int.MaxValue);
1220 CleanupCachedWindows (hwnd);
1222 ArrayList windows = new ArrayList ();
1224 AccumulateDestroyedHandles (Control.ControlNativeWindow.ControlFromHandle(hwnd.Handle), windows);
1227 foreach (Hwnd h in windows) {
1228 SendMessage (h.Handle, Msg.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
1232 // TODO: This is crashing swf-messageboxes
1234 if (false && hwnd.whole_window != IntPtr.Zero)
1235 CFRelease (hwnd.whole_window);
1236 if (false && hwnd.client_window != IntPtr.Zero)
1237 CFRelease (hwnd.client_window);
1240 if (WindowMapping [hwnd.Handle] != null) {
1241 DisposeWindow ((IntPtr)(WindowMapping [hwnd.Handle]));
1242 WindowMapping.Remove (hwnd.Handle);
1246 internal override IntPtr DispatchMessage(ref MSG msg) {
1247 return NativeWindow.WndProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
1250 internal override void DoEvents() {
1251 MSG msg = new MSG ();
1254 while (PeekMessage (null, ref msg, IntPtr.Zero, 0, 0, (uint)PeekMessageFlags.PM_REMOVE)) {
1255 TranslateMessage (ref msg);
1256 DispatchMessage (ref msg);
1258 in_doevents = false;
1262 internal override void EnableWindow(IntPtr handle, bool Enable) {
1263 //Like X11 we need not do anything here
1266 internal override void EndLoop(Thread thread) {
1269 internal void Exit () {
1270 GetMessageResult = false;
1273 internal override IntPtr GetActive() {
1274 return ActiveWindow;
1277 internal override Region GetClipRegion(IntPtr hwnd) {
1282 internal override void GetCursorInfo(IntPtr cursor, out int width, out int height, out int hotspot_x, out int hotspot_y) {
1289 internal override void GetDisplaySize(out Size size) {
1290 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1291 size = new Size ((int)bounds.size.width, (int)bounds.size.height);
1294 internal override IntPtr GetParent(IntPtr handle) {
1297 hwnd = Hwnd.ObjectFromHandle(handle);
1298 if (hwnd != null && hwnd.Parent != null) {
1299 return hwnd.Parent.Handle;
1304 internal override IntPtr GetPreviousWindow(IntPtr handle) {
1305 return HIViewGetPreviousView(handle);
1308 internal override void GetCursorPos(IntPtr handle, out int x, out int y) {
1309 Carbon.QDPoint pt = new Carbon.QDPoint ();
1310 GetGlobalMouse (ref pt);
1315 internal override IntPtr GetFocus() {
1320 internal override bool GetFontMetrics(Graphics g, Font font, out int ascent, out int descent) {
1321 FontFamily ff = font.FontFamily;
1322 ascent = ff.GetCellAscent (font.Style);
1323 descent = ff.GetCellDescent (font.Style);
1327 internal override Point GetMenuOrigin(IntPtr handle) {
1330 hwnd = Hwnd.ObjectFromHandle(handle);
1333 return hwnd.MenuOrigin;
1338 internal override bool GetMessage(object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax) {
1339 IntPtr evtRef = IntPtr.Zero;
1340 IntPtr target = GetEventDispatcherTarget();
1341 CheckTimers (DateTime.UtcNow);
1342 ReceiveNextEvent (0, IntPtr.Zero, 0, true, ref evtRef);
1343 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1344 SendEventToEventTarget (evtRef, target);
1345 ReleaseEvent (evtRef);
1351 if (MessageQueue.Count <= 0) {
1353 Idle (this, EventArgs.Empty);
1354 else if (TimerList.Count == 0) {
1355 ReceiveNextEvent (0, IntPtr.Zero, 0.15, true, ref evtRef);
1356 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1357 SendEventToEventTarget (evtRef, target);
1358 ReleaseEvent (evtRef);
1361 ReceiveNextEvent (0, IntPtr.Zero, NextTimeout (), true, ref evtRef);
1362 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1363 SendEventToEventTarget (evtRef, target);
1364 ReleaseEvent (evtRef);
1367 msg.hwnd = IntPtr.Zero;
1368 msg.message = Msg.WM_ENTERIDLE;
1369 return GetMessageResult;
1371 object queueobj = MessageQueue.Dequeue ();
1372 if (queueobj is GCHandle) {
1373 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)queueobj);
1376 msg = (MSG)queueobj;
1379 return GetMessageResult;
1383 internal override bool GetText(IntPtr handle, out string text) {
1384 throw new NotImplementedException ();
1387 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) {
1390 hwnd = Hwnd.ObjectFromHandle(handle);
1396 height = hwnd.height;
1398 PerformNCCalc(hwnd);
1400 client_width = hwnd.ClientRect.Width;
1401 client_height = hwnd.ClientRect.Height;
1406 // Should we throw an exception or fail silently?
1407 // throw new ArgumentException("Called with an invalid window handle", "handle");
1417 internal override FormWindowState GetWindowState(IntPtr hwnd) {
1418 IntPtr window = HIViewGetWindow (hwnd);
1420 if (IsWindowCollapsed (window))
1421 return FormWindowState.Minimized;
1422 if (IsWindowInStandardState (window, IntPtr.Zero, IntPtr.Zero))
1423 return FormWindowState.Maximized;
1425 return FormWindowState.Normal;
1428 internal override void GrabInfo(out IntPtr handle, out bool GrabConfined, out Rectangle GrabArea) {
1430 GrabConfined = Grab.Confined;
1431 GrabArea = Grab.Area;
1434 internal override void GrabWindow(IntPtr handle, IntPtr confine_to_handle) {
1436 Grab.Confined = confine_to_handle != IntPtr.Zero;
1437 /* FIXME: Set the Grab.Area */
1440 internal override void UngrabWindow(IntPtr hwnd) {
1441 bool was_grabbed = Grab.Hwnd != IntPtr.Zero;
1443 Grab.Hwnd = IntPtr.Zero;
1444 Grab.Confined = false;
1447 // lparam should be the handle to the window gaining the mouse capture,
1448 // but we dont have that information like X11.
1449 // Also only generate WM_CAPTURECHANGED if the window actually was grabbed.
1450 SendMessage (hwnd, Msg.WM_CAPTURECHANGED, IntPtr.Zero, IntPtr.Zero);
1454 internal override void HandleException(Exception e) {
1455 StackTrace st = new StackTrace(e);
1456 Console.WriteLine("Exception '{0}'", e.Message+st.ToString());
1457 Console.WriteLine("{0}{1}", e.Message, st.ToString());
1460 internal override void Invalidate (IntPtr handle, Rectangle rc, bool clear) {
1463 hwnd = Hwnd.ObjectFromHandle(handle);
1466 AddExpose (hwnd, true, hwnd.X, hwnd.Y, hwnd.Width, hwnd.Height);
1468 AddExpose (hwnd, true, rc.X, rc.Y, rc.Width, rc.Height);
1472 internal override void InvalidateNC (IntPtr handle)
1476 hwnd = Hwnd.ObjectFromHandle(handle);
1478 AddExpose (hwnd, false, 0, 0, hwnd.Width, hwnd.Height);
1481 internal override bool IsEnabled(IntPtr handle) {
1482 return Hwnd.ObjectFromHandle(handle).Enabled;
1485 internal override bool IsVisible(IntPtr handle) {
1486 return Hwnd.ObjectFromHandle(handle).visible;
1489 internal override void KillTimer(Timer timer) {
1491 TimerList.Remove(timer);
1496 internal override void OverrideCursor(IntPtr cursor) {
1499 internal override PaintEventArgs PaintEventStart(ref Message msg, IntPtr handle, bool client) {
1500 PaintEventArgs paint_event;
1504 hwnd = Hwnd.ObjectFromHandle(msg.HWnd);
1505 if (msg.HWnd == handle) {
1508 paint_hwnd = Hwnd.ObjectFromHandle (handle);
1511 if (Caret.Visible == 1) {
1512 Caret.Paused = true;
1519 dc = Graphics.FromHwnd (paint_hwnd.client_window);
1521 Region clip_region = new Region ();
1522 clip_region.MakeEmpty();
1524 foreach (Rectangle r in hwnd.ClipRectangles) {
1525 clip_region.Union (r);
1528 if (hwnd.UserClip != null) {
1529 clip_region.Intersect(hwnd.UserClip);
1532 // FIXME: Clip region is hosed
1533 dc.Clip = clip_region;
1534 paint_event = new PaintEventArgs(dc, hwnd.Invalid);
1535 hwnd.expose_pending = false;
1536 hwnd.ClearInvalidArea();
1538 hwnd.drawing_stack.Push (paint_event);
1539 hwnd.drawing_stack.Push (dc);
1541 dc = Graphics.FromHwnd (paint_hwnd.whole_window);
1543 if (!hwnd.nc_invalid.IsEmpty) {
1544 // FIXME: Clip region is hosed
1545 dc.SetClip (hwnd.nc_invalid);
1546 paint_event = new PaintEventArgs(dc, hwnd.nc_invalid);
1548 paint_event = new PaintEventArgs(dc, new Rectangle(0, 0, hwnd.width, hwnd.height));
1550 hwnd.nc_expose_pending = false;
1551 hwnd.ClearNcInvalidArea ();
1553 hwnd.drawing_stack.Push (paint_event);
1554 hwnd.drawing_stack.Push (dc);
1560 internal override void PaintEventEnd(ref Message msg, IntPtr handle, bool client) {
1563 hwnd = Hwnd.ObjectFromHandle(handle);
1565 // FIXME: Pop is causing invalid stack ops sometimes; race condition?
1567 Graphics dc = (Graphics)hwnd.drawing_stack.Pop();
1571 PaintEventArgs pe = (PaintEventArgs)hwnd.drawing_stack.Pop();
1572 pe.SetGraphics (null);
1576 if (Caret.Visible == 1) {
1578 Caret.Paused = false;
1582 internal override bool PeekMessage(Object queue_id, ref MSG msg, IntPtr hWnd, int wFilterMin, int wFilterMax, uint flags) {
1583 IntPtr evtRef = IntPtr.Zero;
1584 IntPtr target = GetEventDispatcherTarget();
1585 CheckTimers (DateTime.UtcNow);
1586 ReceiveNextEvent (0, IntPtr.Zero, 0, true, ref evtRef);
1587 if (evtRef != IntPtr.Zero && target != IntPtr.Zero) {
1588 SendEventToEventTarget (evtRef, target);
1589 ReleaseEvent (evtRef);
1593 if (MessageQueue.Count <= 0) {
1597 if (flags == (uint)PeekMessageFlags.PM_REMOVE)
1598 queueobj = MessageQueue.Dequeue ();
1600 queueobj = MessageQueue.Peek ();
1602 if (queueobj is GCHandle) {
1603 XplatUIDriverSupport.ExecuteClientMessage((GCHandle)queueobj);
1606 msg = (MSG)queueobj;
1612 internal override bool PostMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
1613 MSG msg = new MSG();
1615 msg.message = message;
1616 msg.wParam = wParam;
1617 msg.lParam = lParam;
1618 EnqueueMessage (msg);
1622 internal override void PostQuitMessage(int exitCode) {
1623 PostMessage (FosterParent, Msg.WM_QUIT, IntPtr.Zero, IntPtr.Zero);
1626 internal override void RequestAdditionalWM_NCMessages(IntPtr hwnd, bool hover, bool leave) {
1629 internal override void RequestNCRecalc(IntPtr handle) {
1632 hwnd = Hwnd.ObjectFromHandle(handle);
1638 PerformNCCalc(hwnd);
1639 SendMessage(handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1640 InvalidateNC(handle);
1644 internal override void ResetMouseHover(IntPtr handle) {
1645 throw new NotImplementedException();
1648 internal override void ScreenToClient(IntPtr handle, ref int x, ref int y) {
1649 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1651 Point point = ConvertScreenPointToClient (hwnd.ClientWindow, new Point (x, y));
1657 internal override void ScreenToMenu(IntPtr handle, ref int x, ref int y) {
1658 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1660 Point point = ConvertScreenPointToClient (hwnd.WholeWindow, new Point (x, y));
1666 internal override void ScrollWindow(IntPtr handle, Rectangle area, int XAmount, int YAmount, bool clear) {
1668 * This used to use a HIViewScrollRect but this causes issues with the fact that we dont coalesce
1669 * updates properly with our short-circuiting of the window manager. For now we'll do a less
1670 * efficient invalidation of the entire handle which appears to fix the problem
1673 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1674 Invalidate (handle, new Rectangle (0, 0, hwnd.Width, hwnd.Height), false);
1678 internal override void ScrollWindow(IntPtr handle, int XAmount, int YAmount, bool clear) {
1679 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1680 Invalidate (handle, new Rectangle (0, 0, hwnd.Width, hwnd.Height), false);
1684 internal override void SendAsyncMethod (AsyncMethodData method) {
1687 MessageQueue.Enqueue (GCHandle.Alloc (method));
1692 internal override IntPtr SendMessage (IntPtr hwnd, Msg message, IntPtr wParam, IntPtr lParam) {
1693 return NativeWindow.WndProc(hwnd, message, wParam, lParam);
1696 internal override int SendInput(IntPtr hwnd, Queue keys) {
1701 internal override void SetCaretPos (IntPtr hwnd, int x, int y) {
1702 if (hwnd != IntPtr.Zero && hwnd == Caret.Hwnd) {
1705 ClientToScreen (hwnd, ref x, ref y);
1706 SizeWindow (new Rectangle (x, y, Caret.Width, Caret.Height), CaretWindow);
1707 Caret.Timer.Stop ();
1709 if (Caret.Visible == 1) {
1711 Caret.Timer.Start ();
1716 internal override void SetClipRegion(IntPtr hwnd, Region region) {
1717 throw new NotImplementedException();
1720 internal override void SetCursor(IntPtr window, IntPtr cursor) {
1721 Hwnd hwnd = Hwnd.ObjectFromHandle (window);
1723 hwnd.Cursor = cursor;
1726 internal override void SetCursorPos(IntPtr handle, int x, int y) {
1727 CGDisplayMoveCursorToPoint (CGMainDisplayID (), new Carbon.CGPoint (x, y));
1730 internal override void SetFocus(IntPtr handle) {
1731 if (FocusWindow != IntPtr.Zero) {
1732 PostMessage(FocusWindow, Msg.WM_KILLFOCUS, handle, IntPtr.Zero);
1734 PostMessage(handle, Msg.WM_SETFOCUS, FocusWindow, IntPtr.Zero);
1735 FocusWindow = handle;
1738 internal override void SetIcon(IntPtr handle, Icon icon) {
1739 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1741 // FIXME: we need to map the icon for active window switches
1742 if (WindowMapping [hwnd.Handle] != null) {
1744 RestoreApplicationDockTileImage ();
1751 bitmap = new Bitmap (128, 128);
1752 using (Graphics g = Graphics.FromImage (bitmap)) {
1753 g.DrawImage (icon.ToBitmap (), 0, 0, 128, 128);
1756 size = bitmap.Width * bitmap.Height;
1757 data = new IntPtr[size];
1759 for (int y = 0; y < bitmap.Height; y++) {
1760 for (int x = 0; x < bitmap.Width; x++) {
1761 int pixel = bitmap.GetPixel (x, y).ToArgb ();
1762 if (BitConverter.IsLittleEndian) {
1763 byte a = (byte) ((pixel >> 24) & 0xFF);
1764 byte r = (byte) ((pixel >> 16) & 0xFF);
1765 byte g = (byte) ((pixel >> 8) & 0xFF);
1766 byte b = (byte) (pixel & 0xFF);
1767 data[index++] = (IntPtr)(a + (r << 8) + (g << 16) + (b << 24));
1769 data[index++] = (IntPtr)pixel;
1774 IntPtr provider = CGDataProviderCreateWithData (IntPtr.Zero, data, size*4, IntPtr.Zero);
1775 IntPtr image = CGImageCreate (128, 128, 8, 32, 4*128, CGColorSpaceCreateDeviceRGB (), 4, provider, IntPtr.Zero, 0, 0);
1776 SetApplicationDockTileImage (image);
1782 internal override void SetModal(IntPtr handle, bool Modal) {
1783 IntPtr hWnd = HIViewGetWindow (Hwnd.ObjectFromHandle (handle).WholeWindow);
1785 BeginAppModalStateForWindow (hWnd);
1787 EndAppModalStateForWindow (hWnd);
1791 internal override IntPtr SetParent(IntPtr handle, IntPtr parent) {
1792 IntPtr ParentHandle = IntPtr.Zero;
1793 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1795 hwnd.Parent = Hwnd.ObjectFromHandle (parent);
1796 if (HIViewGetSuperview (hwnd.whole_window) != IntPtr.Zero) {
1797 HIViewRemoveFromSuperview (hwnd.whole_window);
1799 if (hwnd.parent == null)
1800 HIViewFindByID (HIViewGetRoot (FosterParent), new Carbon.HIViewID (Carbon.EventHandler.kEventClassWindow, 1), ref ParentHandle);
1801 HIViewAddSubview (hwnd.parent == null ? ParentHandle : hwnd.Parent.client_window, hwnd.whole_window);
1802 HIViewPlaceInSuperviewAt (hwnd.whole_window, hwnd.X, hwnd.Y);
1803 HIViewAddSubview (hwnd.whole_window, hwnd.client_window);
1804 HIViewPlaceInSuperviewAt (hwnd.client_window, hwnd.ClientRect.X, hwnd.ClientRect.Y);
1809 internal override void SetTimer (Timer timer) {
1811 TimerList.Add (timer);
1815 internal override bool SetTopmost(IntPtr hWnd, bool Enabled) {
1816 HIViewSetZOrder (hWnd, 1, IntPtr.Zero);
1820 internal override bool SetOwner(IntPtr hWnd, IntPtr hWndOwner) {
1821 // TODO: Set window owner.
1825 internal override bool SetVisible(IntPtr handle, bool visible, bool activate) {
1826 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1827 object window = WindowMapping [hwnd.Handle];
1830 ShowWindow ((IntPtr)window);
1832 HideWindow ((IntPtr)window);
1835 SendMessage(handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1837 HIViewSetVisible (hwnd.whole_window, visible);
1838 HIViewSetVisible (hwnd.client_window, visible);
1840 hwnd.visible = visible;
1845 internal override void SetAllowDrop (IntPtr handle, bool value) {
1846 // Like X11 we allow drop on al windows and filter in our handler
1849 internal override DragDropEffects StartDrag (IntPtr handle, object data, DragDropEffects allowed_effects) {
1850 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1853 throw new ArgumentException ("Attempt to begin drag from invalid window handle (" + handle.ToInt32 () + ").");
1855 return Dnd.StartDrag (hwnd.client_window, data, allowed_effects);
1858 internal override void SetBorderStyle(IntPtr handle, FormBorderStyle border_style) {
1859 Form form = Control.FromHandle (handle) as Form;
1860 if (form != null && form.window_manager == null && (border_style == FormBorderStyle.FixedToolWindow ||
1861 border_style == FormBorderStyle.SizableToolWindow)) {
1862 form.window_manager = new ToolWindowManager (form);
1865 RequestNCRecalc(handle);
1868 internal override void SetMenu(IntPtr handle, Menu menu) {
1871 hwnd = Hwnd.ObjectFromHandle(handle);
1874 RequestNCRecalc(handle);
1877 internal override void SetWindowMinMax(IntPtr handle, Rectangle maximized, Size min, Size max) {
1880 internal override void SetWindowPos(IntPtr handle, int x, int y, int width, int height) {
1881 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1887 // Win32 automatically changes negative width/height to 0.
1893 // X requires a sanity check for width & height; otherwise it dies
1894 if (hwnd.zero_sized && width > 0 && height > 0) {
1896 HIViewSetVisible(hwnd.WholeWindow, true);
1898 hwnd.zero_sized = false;
1901 if ((width < 1) || (height < 1)) {
1902 hwnd.zero_sized = true;
1903 HIViewSetVisible(hwnd.WholeWindow, false);
1906 // Save a server roundtrip (and prevent a feedback loop)
1907 if ((hwnd.x == x) && (hwnd.y == y) && (hwnd.width == width) && (hwnd.height == height)) {
1911 if (!hwnd.zero_sized) {
1915 hwnd.height = height;
1916 SendMessage(hwnd.client_window, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
1918 Control ctrl = Control.FromHandle (handle);
1919 CreateParams cp = ctrl.GetCreateParams ();
1920 Size TranslatedSize = TranslateWindowSizeToQuartzWindowSize (cp, new Size (width, height));
1921 Carbon.Rect rect = new Carbon.Rect ();
1923 if (WindowMapping [hwnd.Handle] != null) {
1924 if (StyleSet (cp.Style, WindowStyles.WS_POPUP)) {
1925 SetRect (ref rect, (short)x, (short)y, (short)(x+TranslatedSize.Width), (short)(y+TranslatedSize.Height));
1927 SetRect (ref rect, (short)x, (short)(y+MenuBarHeight), (short)(x+TranslatedSize.Width), (short)(y+MenuBarHeight+TranslatedSize.Height));
1929 SetWindowBounds ((IntPtr) WindowMapping [hwnd.Handle], 33, ref rect);
1930 Carbon.HIRect frame_rect = new Carbon.HIRect (0, 0, TranslatedSize.Width, TranslatedSize.Height);
1931 HIViewSetFrame (hwnd.whole_window, ref frame_rect);
1932 SetCaretPos (Caret.Hwnd, Caret.X, Caret.Y);
1934 Carbon.HIRect frame_rect = new Carbon.HIRect (x, y, TranslatedSize.Width, TranslatedSize.Height);
1935 HIViewSetFrame (hwnd.whole_window, ref frame_rect);
1937 PerformNCCalc(hwnd);
1943 hwnd.height = height;
1946 internal override void SetWindowState(IntPtr handle, FormWindowState state) {
1947 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1948 IntPtr window = HIViewGetWindow (handle);
1951 case FormWindowState.Minimized: {
1952 CollapseWindow (window, true);
1955 case FormWindowState.Normal: {
1956 ZoomWindow (window, 7, false);
1959 case FormWindowState.Maximized: {
1960 Form form = Control.FromHandle (hwnd.Handle) as Form;
1961 if (form != null && form.FormBorderStyle == FormBorderStyle.None) {
1962 Carbon.Rect rect = new Carbon.Rect ();
1963 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
1964 SetRect (ref rect, (short)0, (short)0, (short)bounds.size.width, (short)bounds.size.height);
1965 SetWindowBounds ((IntPtr) WindowMapping [hwnd.Handle], 33, ref rect);
1966 HIViewSetFrame (hwnd.whole_window, ref bounds);
1968 ZoomWindow (window, 8, false);
1975 internal override void SetWindowStyle(IntPtr handle, CreateParams cp) {
1976 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
1977 SetHwndStyles(hwnd, cp);
1979 if (WindowMapping [hwnd.Handle] != null) {
1980 Carbon.WindowAttributes attributes = Carbon.WindowAttributes.kWindowCompositingAttribute | Carbon.WindowAttributes.kWindowStandardHandlerAttribute;
1981 if ((cp.Style & ((int)WindowStyles.WS_MINIMIZEBOX)) != 0) {
1982 attributes |= Carbon.WindowAttributes.kWindowCollapseBoxAttribute;
1984 if ((cp.Style & ((int)WindowStyles.WS_MAXIMIZEBOX)) != 0) {
1985 attributes |= Carbon.WindowAttributes.kWindowResizableAttribute | Carbon.WindowAttributes.kWindowHorizontalZoomAttribute | Carbon.WindowAttributes.kWindowVerticalZoomAttribute;
1987 if ((cp.Style & ((int)WindowStyles.WS_SYSMENU)) != 0) {
1988 attributes |= Carbon.WindowAttributes.kWindowCloseBoxAttribute;
1990 if ((cp.ExStyle & ((int)WindowExStyles.WS_EX_TOOLWINDOW)) != 0) {
1991 attributes = Carbon.WindowAttributes.kWindowStandardHandlerAttribute | Carbon.WindowAttributes.kWindowCompositingAttribute;
1993 attributes |= Carbon.WindowAttributes.kWindowLiveResizeAttribute;
1995 Carbon.WindowAttributes outAttributes = Carbon.WindowAttributes.kWindowNoAttributes;
1996 GetWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], ref outAttributes);
1997 ChangeWindowAttributes ((IntPtr)WindowMapping [hwnd.Handle], attributes, outAttributes);
2001 internal override void SetWindowTransparency(IntPtr handle, double transparency, Color key) {
2004 internal override double GetWindowTransparency(IntPtr handle)
2009 internal override TransparencySupport SupportsTransparency() {
2010 return TransparencySupport.None;
2013 internal override bool SetZOrder(IntPtr handle, IntPtr after_handle, bool Top, bool Bottom) {
2014 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
2017 HIViewSetZOrder (hwnd.whole_window, 2, IntPtr.Zero);
2019 } else if (!Bottom) {
2020 Hwnd after_hwnd = Hwnd.ObjectFromHandle (after_handle);
2021 HIViewSetZOrder (hwnd.whole_window, 2, (after_handle == IntPtr.Zero ? IntPtr.Zero : after_hwnd.whole_window));
2023 HIViewSetZOrder (hwnd.whole_window, 1, IntPtr.Zero);
2029 internal override void ShowCursor(bool show) {
2031 CGDisplayShowCursor (CGMainDisplayID ());
2033 CGDisplayHideCursor (CGMainDisplayID ());
2036 internal override object StartLoop(Thread thread) {
2037 return new object ();
2041 internal override bool SystrayAdd(IntPtr hwnd, string tip, Icon icon, out ToolTip tt) {
2042 throw new NotImplementedException();
2046 internal override bool SystrayChange(IntPtr hwnd, string tip, Icon icon, ref ToolTip tt) {
2047 throw new NotImplementedException();
2051 internal override void SystrayRemove(IntPtr hwnd, ref ToolTip tt) {
2052 throw new NotImplementedException();
2057 internal override void SystrayBalloon(IntPtr hwnd, int timeout, string title, string text, ToolTipIcon icon)
2059 throw new NotImplementedException ();
2063 internal override bool Text(IntPtr handle, string text) {
2064 Hwnd hwnd = Hwnd.ObjectFromHandle (handle);
2065 if (WindowMapping [hwnd.Handle] != null) {
2066 SetWindowTitleWithCFString ((IntPtr)(WindowMapping [hwnd.Handle]), __CFStringMakeConstantString (text));
2068 SetControlTitleWithCFString (hwnd.whole_window, __CFStringMakeConstantString (text));
2069 SetControlTitleWithCFString (hwnd.client_window, __CFStringMakeConstantString (text));
2073 internal override void UpdateWindow(IntPtr handle) {
2076 hwnd = Hwnd.ObjectFromHandle(handle);
2078 if (!hwnd.visible || !HIViewIsVisible (handle)) {
2082 SendMessage(handle, Msg.WM_PAINT, IntPtr.Zero, IntPtr.Zero);
2085 internal override bool TranslateMessage(ref MSG msg) {
2086 return Carbon.EventHandler.TranslateMessage (ref msg);
2089 #region Reversible regions
2091 * Quartz has no concept of XOR drawing due to its compositing nature
2092 * We fake this by mapping a overlay window on the first draw and mapping it on the second.
2093 * This has some issues with it because its POSSIBLE for ControlPaint.DrawReversible* to actually
2094 * reverse two regions at once. We dont do this in MWF, but this behaviour woudn't work.
2095 * We could in theory cache the Rectangle/Color combination to handle this behaviour.
2097 * PROBLEMS: This has some flicker / banding
2099 internal void SizeWindow (Rectangle rect, IntPtr window) {
2100 Carbon.Rect qrect = new Carbon.Rect ();
2102 SetRect (ref qrect, (short)rect.X, (short)rect.Y, (short)(rect.X+rect.Width), (short)(rect.Y+rect.Height));
2104 SetWindowBounds (window, 33, ref qrect);
2107 internal override void DrawReversibleLine(Point start, Point end, Color backColor) {
2108 // throw new NotImplementedException();
2111 internal override void FillReversibleRectangle (Rectangle rectangle, Color backColor) {
2112 // throw new NotImplementedException();
2115 internal override void DrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
2116 // throw new NotImplementedException();
2119 internal override void DrawReversibleRectangle(IntPtr handle, Rectangle rect, int line_width) {
2120 Rectangle size_rect = rect;
2124 if (ReverseWindowMapped) {
2125 HideWindow (ReverseWindow);
2126 ReverseWindowMapped = false;
2128 ClientToScreen(handle, ref new_x, ref new_y);
2130 size_rect.X += new_x;
2131 size_rect.Y += new_y;
2133 SizeWindow (size_rect, ReverseWindow);
2134 ShowWindow (ReverseWindow);
2141 Graphics g = Graphics.FromHwnd (HIViewGetRoot (ReverseWindow));
2143 for (int i = 0; i < line_width; i++) {
2144 g.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (Color.Black), rect);
2154 ReverseWindowMapped = true;
2159 internal override SizeF GetAutoScaleSize(Font font) {
2162 string magic_string = "The quick brown fox jumped over the lazy dog.";
2163 double magic_number = 44.549996948242189;
2165 g = Graphics.FromImage (new Bitmap (1, 1));
2167 width = (float) (g.MeasureString (magic_string, font).Width / magic_number);
2168 return new SizeF(width, font.Height);
2171 internal override Point MousePosition {
2173 return mouse_position;
2178 #region System information
2179 internal override int KeyboardSpeed { get{ throw new NotImplementedException(); } }
2180 internal override int KeyboardDelay { get{ throw new NotImplementedException(); } }
2182 internal override int CaptionHeight {
2188 internal override Size CursorSize { get{ throw new NotImplementedException(); } }
2189 internal override bool DragFullWindows { get{ throw new NotImplementedException(); } }
2190 internal override Size DragSize {
2192 return new Size(4, 4);
2196 internal override Size FrameBorderSize {
2198 return new Size (2, 2);
2202 internal override Size IconSize { get{ throw new NotImplementedException(); } }
2203 internal override Size MaxWindowTrackSize { get{ throw new NotImplementedException(); } }
2204 internal override bool MenuAccessKeysUnderlined {
2209 internal override Size MinimizedWindowSpacingSize { get{ throw new NotImplementedException(); } }
2211 internal override Size MinimumWindowSize {
2213 return new Size(110, 22);
2217 internal override Keys ModifierKeys {
2219 return KeyboardHandler.ModifierKeys;
2222 internal override Size SmallIconSize { get{ throw new NotImplementedException(); } }
2223 internal override int MouseButtonCount { get{ throw new NotImplementedException(); } }
2224 internal override bool MouseButtonsSwapped { get{ throw new NotImplementedException(); } }
2225 internal override bool MouseWheelPresent { get{ throw new NotImplementedException(); } }
2227 internal override MouseButtons MouseButtons {
2233 internal override Rectangle VirtualScreen {
2239 internal override Rectangle WorkingArea {
2241 Carbon.HIRect bounds = CGDisplayBounds (CGMainDisplayID ());
2242 return new Rectangle ((int)bounds.origin.x, (int)bounds.origin.y, (int)bounds.size.width, (int)bounds.size.height);
2245 internal override bool ThemesEnabled {
2247 return XplatUICarbon.themes_enabled;
2254 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2255 extern static int HIViewConvertPoint (ref Carbon.CGPoint point, IntPtr pView, IntPtr cView);
2256 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2257 extern static int HIViewChangeFeatures (IntPtr aView, ulong bitsin, ulong bitsout);
2258 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2259 extern static int HIViewFindByID (IntPtr rootWnd, Carbon.HIViewID id, ref IntPtr outPtr);
2260 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2261 extern static int HIGrowBoxViewSetTransparent (IntPtr GrowBox, bool transparency);
2262 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2263 extern static IntPtr HIViewGetRoot (IntPtr hWnd);
2264 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2265 extern static int HIObjectCreate (IntPtr cfStr, uint what, ref IntPtr hwnd);
2266 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2267 extern static int HIObjectRegisterSubclass (IntPtr classid, IntPtr superclassid, uint options, Carbon.EventDelegate upp, uint count, Carbon.EventTypeSpec [] list, IntPtr state, ref IntPtr cls);
2268 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2269 extern static int HIViewPlaceInSuperviewAt (IntPtr view, float x, float y);
2270 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2271 extern static int HIViewAddSubview (IntPtr parentHnd, IntPtr childHnd);
2272 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2273 extern static IntPtr HIViewGetPreviousView (IntPtr aView);
2274 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2275 extern static IntPtr HIViewGetSuperview (IntPtr aView);
2276 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2277 extern static int HIViewRemoveFromSuperview (IntPtr aView);
2278 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2279 extern static int HIViewSetVisible (IntPtr vHnd, bool visible);
2280 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2281 extern static bool HIViewIsVisible (IntPtr vHnd);
2282 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2283 extern static int HIViewGetBounds (IntPtr vHnd, ref Carbon.HIRect r);
2284 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2285 extern static int HIViewScrollRect (IntPtr vHnd, ref Carbon.HIRect rect, float x, float y);
2286 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2287 extern static int HIViewSetZOrder (IntPtr hWnd, int cmd, IntPtr oHnd);
2288 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2289 extern static int HIViewNewTrackingArea (IntPtr inView, IntPtr inShape, UInt64 inID, ref IntPtr outRef);
2290 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2291 extern static IntPtr HIViewGetWindow (IntPtr aView);
2292 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2293 extern static int HIViewSetFrame (IntPtr view_handle, ref Carbon.HIRect bounds);
2294 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2295 internal extern static int HIViewSetNeedsDisplayInRect (IntPtr view_handle, ref Carbon.HIRect rect, bool needs_display);
2297 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2298 extern static void SetRect (ref Carbon.Rect r, short left, short top, short right, short bottom);
2299 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2300 static extern int ActivateWindow (IntPtr windowHnd, bool inActivate);
2301 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2302 static extern bool IsWindowActive (IntPtr windowHnd);
2303 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2304 static extern int SetAutomaticControlDragTrackingEnabledForWindow (IntPtr window, bool enabled);
2306 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2307 extern static IntPtr GetEventDispatcherTarget ();
2308 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2309 extern static int SendEventToEventTarget (IntPtr evt, IntPtr target);
2310 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2311 extern static int ReleaseEvent (IntPtr evt);
2312 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2313 extern static int ReceiveNextEvent (uint evtCount, IntPtr evtTypes, double timeout, bool processEvt, ref IntPtr evt);
2315 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2316 extern static bool IsWindowCollapsed (IntPtr hWnd);
2317 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2318 extern static bool IsWindowInStandardState (IntPtr hWnd, IntPtr a, IntPtr b);
2319 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2320 extern static void CollapseWindow (IntPtr hWnd, bool collapse);
2321 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2322 extern static void ZoomWindow (IntPtr hWnd, short partCode, bool front);
2323 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2324 extern static int GetWindowAttributes (IntPtr hWnd, ref Carbon.WindowAttributes outAttributes);
2325 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2326 extern static int ChangeWindowAttributes (IntPtr hWnd, Carbon.WindowAttributes inAttributes, Carbon.WindowAttributes outAttributes);
2327 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2328 internal extern static int GetGlobalMouse (ref Carbon.QDPoint outData);
2330 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2331 extern static int BeginAppModalStateForWindow (IntPtr window);
2332 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2333 extern static int EndAppModalStateForWindow (IntPtr window);
2334 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2335 extern static int CreateNewWindow (Carbon.WindowClass klass, Carbon.WindowAttributes attributes, ref Carbon.Rect r, ref IntPtr window);
2336 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2337 extern static int DisposeWindow (IntPtr wHnd);
2338 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2339 internal extern static int ShowWindow (IntPtr wHnd);
2340 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2341 internal extern static int HideWindow (IntPtr wHnd);
2342 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2343 internal extern static bool IsWindowVisible (IntPtr wHnd);
2344 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2345 extern static int SetWindowBounds (IntPtr wHnd, uint reg, ref Carbon.Rect rect);
2346 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2347 extern static int GetWindowBounds (IntPtr wHnd, uint reg, ref Carbon.Rect rect);
2349 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2350 extern static int SetControlTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
2351 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2352 extern static int SetWindowTitleWithCFString (IntPtr hWnd, IntPtr titleCFStr);
2353 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2354 internal extern static IntPtr __CFStringMakeConstantString (string cString);
2356 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2357 internal extern static int CFRelease (IntPtr wHnd);
2358 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2359 extern static short GetMBarHeight ();
2361 #region Cursor imports
2362 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2363 extern static Carbon.HIRect CGDisplayBounds (IntPtr displayID);
2364 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2365 extern static IntPtr CGMainDisplayID ();
2366 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2367 extern static void CGDisplayShowCursor (IntPtr display);
2368 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2369 extern static void CGDisplayHideCursor (IntPtr display);
2370 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2371 extern static void CGDisplayMoveCursorToPoint (IntPtr display, Carbon.CGPoint point);
2374 #region Process imports
2375 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2376 extern static int GetCurrentProcess (ref Carbon.ProcessSerialNumber psn);
2377 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2378 extern static int TransformProcessType (ref Carbon.ProcessSerialNumber psn, uint type);
2379 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2380 extern static int SetFrontProcess (ref Carbon.ProcessSerialNumber psn);
2383 #region Dock tile imports
2384 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2385 extern static IntPtr CGColorSpaceCreateDeviceRGB();
2386 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2387 extern static IntPtr CGDataProviderCreateWithData (IntPtr info, IntPtr [] data, int size, IntPtr releasefunc);
2388 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2389 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);
2390 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2391 extern static void SetApplicationDockTileImage(IntPtr imageRef);
2392 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
2393 extern static void RestoreApplicationDockTileImage();