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) 2007 Novell, Inc.
23 // Geoff Norton <gnorton@novell.com>
29 using System.Runtime.InteropServices;
31 namespace System.Windows.Forms.CarbonInternal {
32 internal class WindowHandler : EventHandlerBase, IEventHandler {
33 internal const uint kEventWindowUpdate = 1;
34 internal const uint kEventWindowDrawContent = 2;
35 internal const uint kEventWindowActivated = 5;
36 internal const uint kEventWindowDeactivated = 6;
37 internal const uint kEventWindowGetClickActivation = 7;
38 internal const uint kEventWindowShowing = 22;
39 internal const uint kEventWindowHiding = 23;
40 internal const uint kEventWindowShown = 24;
41 internal const uint kEventWindowHidden = 25;
42 internal const uint kEventWindowCollapsing = 86;
43 internal const uint kEventWindowExpanding = 87;
44 internal const uint kEventWindowZoomed = 76;
45 internal const uint kEventWindowBoundsChanging = 26;
46 internal const uint kEventWindowBoundsChanged = 27;
47 internal const uint kEventWindowResizeStarted = 28;
48 internal const uint kEventWindowResizeCompleted = 29;
49 internal const uint kEventWindowDragStarted = 30;
50 internal const uint kEventWindowDragCompleted = 31;
51 internal const uint kEventWindowTransitionStarted = 88;
52 internal const uint kEventWindowTransitionCompleted = 89;
53 internal const uint kEventWindowClickDragRgn = 32;
54 internal const uint kEventWindowClickResizeRgn = 33;
55 internal const uint kEventWindowClickCollapseRgn = 34;
56 internal const uint kEventWindowClickCloseRgn = 35;
57 internal const uint kEventWindowClickZoomRgn = 36;
58 internal const uint kEventWindowClickContentRgn = 37;
59 internal const uint kEventWindowClickProxyIconRgn = 38;
60 internal const uint kEventWindowClickToolbarButtonRgn = 41;
61 internal const uint kEventWindowClickStructureRgn = 42;
62 internal const uint kEventWindowCursorChange = 40;
63 internal const uint kEventWindowCollapse = 66;
64 internal const uint kEventWindowCollapsed = 67;
65 internal const uint kEventWindowCollapseAll = 68;
66 internal const uint kEventWindowExpand = 69;
67 internal const uint kEventWindowExpanded = 70;
68 internal const uint kEventWindowExpandAll = 71;
69 internal const uint kEventWindowClose = 72;
70 internal const uint kEventWindowClosed = 73;
71 internal const uint kEventWindowCloseAll = 74;
72 internal const uint kEventWindowZoom = 75;
73 internal const uint kEventWindowZoomAll = 77;
74 internal const uint kEventWindowContextualMenuSelect = 78;
75 internal const uint kEventWindowPathSelect = 79;
76 internal const uint kEventWindowGetIdealSize = 80;
77 internal const uint kEventWindowGetMinimumSize = 81;
78 internal const uint kEventWindowGetMaximumSize = 82;
79 internal const uint kEventWindowConstrain = 83;
80 internal const uint kEventWindowHandleContentClick = 85;
81 internal const uint kEventWindowGetDockTileMenu = 90;
82 internal const uint kEventWindowHandleActivate = 91;
83 internal const uint kEventWindowHandleDeactivate = 92;
84 internal const uint kEventWindowProxyBeginDrag = 128;
85 internal const uint kEventWindowProxyEndDrag = 129;
86 internal const uint kEventWindowToolbarSwitchMode = 150;
87 internal const uint kEventWindowFocusAcquired = 200;
88 internal const uint kEventWindowFocusRelinquish = 201;
89 internal const uint kEventWindowFocusContent = 202;
90 internal const uint kEventWindowFocusToolbar = 203;
91 internal const uint kEventWindowDrawerOpening = 220;
92 internal const uint kEventWindowDrawerOpened = 221;
93 internal const uint kEventWindowDrawerClosing = 222;
94 internal const uint kEventWindowDrawerClosed = 223;
95 internal const uint kEventWindowDrawFrame = 1000;
96 internal const uint kEventWindowDrawPart = 1001;
97 internal const uint kEventWindowGetRegion = 1002;
98 internal const uint kEventWindowHitTest = 1003;
99 internal const uint kEventWindowInit = 1004;
100 internal const uint kEventWindowDispose = 1005;
101 internal const uint kEventWindowDragHilite = 1006;
102 internal const uint kEventWindowModified = 1007;
103 internal const uint kEventWindowSetupProxyDragImage = 1008;
104 internal const uint kEventWindowStateChanged = 1009;
105 internal const uint kEventWindowMeasureTitle = 1010;
106 internal const uint kEventWindowDrawGrowBox = 1011;
107 internal const uint kEventWindowGetGrowImageRegion = 1012;
108 internal const uint kEventWindowPaint = 1013;
110 internal WindowHandler (XplatUICarbon driver) : base (driver) {}
112 public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
113 IntPtr window = Driver.HandleToWindow (handle);
114 if (window != IntPtr.Zero) {
116 case kEventWindowClose:
117 NativeWindow.WndProc (window, Msg.WM_DESTROY, IntPtr.Zero, IntPtr.Zero);
119 case kEventWindowShown: {
120 Hwnd hwnd = Hwnd.ObjectFromHandle (window);
122 msg.message = Msg.WM_SHOWWINDOW;
123 msg.lParam = (IntPtr) 1;
124 msg.wParam = (IntPtr) 0;
125 msg.hwnd = hwnd.Handle;
129 case kEventWindowBoundsChanged: {
130 Rect window_bounds = new Rect ();
131 HIRect view_bounds = new HIRect ();
132 Hwnd hwnd = Hwnd.ObjectFromHandle (window);
135 GetWindowBounds (handle, 33, ref window_bounds);
137 view_bounds.size.width = window_bounds.right - window_bounds.left;
138 view_bounds.size.height = window_bounds.bottom - window_bounds.top;
140 HIViewSetFrame (hwnd.WholeWindow, ref view_bounds);
142 size = XplatUICarbon.TranslateQuartzWindowSizeToWindowSize (Control.FromHandle (hwnd.Handle).GetCreateParams (), (int)view_bounds.size.width, (int)view_bounds.size.height);
144 hwnd.X = (int) window_bounds.left;
145 hwnd.Y = (int) window_bounds.top;
146 hwnd.Width = (int) size.Width;
147 hwnd.Height = (int) size.Height;
149 Driver.PerformNCCalc (hwnd);
151 msg.message = Msg.WM_WINDOWPOSCHANGED;
152 msg.hwnd = hwnd.Handle;
161 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
162 static extern int GetWindowBounds (IntPtr handle, uint region, ref Rect bounds);
164 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
165 static extern int HIViewSetFrame (IntPtr handle, ref HIRect bounds);