fix typo
[mcs.git] / class / Managed.Windows.Forms / System.Windows.Forms.CarbonInternal / WindowHandler.cs
blobbfac5dd6bbdf77d15d2d6873fac0bdbef547a2a8
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:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
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.
22 // Authors:
23 // Geoff Norton <gnorton@novell.com>
27 using System;
28 using System.Drawing;
29 using System.Windows.Forms;
30 using System.Runtime.InteropServices;
32 namespace System.Windows.Forms.CarbonInternal {
33 internal class WindowHandler : EventHandlerBase, IEventHandler {
34 internal const uint kEventWindowUpdate = 1;
35 internal const uint kEventWindowDrawContent = 2;
36 internal const uint kEventWindowActivated = 5;
37 internal const uint kEventWindowDeactivated = 6;
38 internal const uint kEventWindowGetClickActivation = 7;
39 internal const uint kEventWindowShowing = 22;
40 internal const uint kEventWindowHiding = 23;
41 internal const uint kEventWindowShown = 24;
42 internal const uint kEventWindowHidden = 25;
43 internal const uint kEventWindowCollapsing = 86;
44 internal const uint kEventWindowExpanding = 87;
45 internal const uint kEventWindowZoomed = 76;
46 internal const uint kEventWindowBoundsChanging = 26;
47 internal const uint kEventWindowBoundsChanged = 27;
48 internal const uint kEventWindowResizeStarted = 28;
49 internal const uint kEventWindowResizeCompleted = 29;
50 internal const uint kEventWindowDragStarted = 30;
51 internal const uint kEventWindowDragCompleted = 31;
52 internal const uint kEventWindowTransitionStarted = 88;
53 internal const uint kEventWindowTransitionCompleted = 89;
54 internal const uint kEventWindowClickDragRgn = 32;
55 internal const uint kEventWindowClickResizeRgn = 33;
56 internal const uint kEventWindowClickCollapseRgn = 34;
57 internal const uint kEventWindowClickCloseRgn = 35;
58 internal const uint kEventWindowClickZoomRgn = 36;
59 internal const uint kEventWindowClickContentRgn = 37;
60 internal const uint kEventWindowClickProxyIconRgn = 38;
61 internal const uint kEventWindowClickToolbarButtonRgn = 41;
62 internal const uint kEventWindowClickStructureRgn = 42;
63 internal const uint kEventWindowCursorChange = 40;
64 internal const uint kEventWindowCollapse = 66;
65 internal const uint kEventWindowCollapsed = 67;
66 internal const uint kEventWindowCollapseAll = 68;
67 internal const uint kEventWindowExpand = 69;
68 internal const uint kEventWindowExpanded = 70;
69 internal const uint kEventWindowExpandAll = 71;
70 internal const uint kEventWindowClose = 72;
71 internal const uint kEventWindowClosed = 73;
72 internal const uint kEventWindowCloseAll = 74;
73 internal const uint kEventWindowZoom = 75;
74 internal const uint kEventWindowZoomAll = 77;
75 internal const uint kEventWindowContextualMenuSelect = 78;
76 internal const uint kEventWindowPathSelect = 79;
77 internal const uint kEventWindowGetIdealSize = 80;
78 internal const uint kEventWindowGetMinimumSize = 81;
79 internal const uint kEventWindowGetMaximumSize = 82;
80 internal const uint kEventWindowConstrain = 83;
81 internal const uint kEventWindowHandleContentClick = 85;
82 internal const uint kEventWindowGetDockTileMenu = 90;
83 internal const uint kEventWindowHandleActivate = 91;
84 internal const uint kEventWindowHandleDeactivate = 92;
85 internal const uint kEventWindowProxyBeginDrag = 128;
86 internal const uint kEventWindowProxyEndDrag = 129;
87 internal const uint kEventWindowToolbarSwitchMode = 150;
88 internal const uint kEventWindowFocusAcquired = 200;
89 internal const uint kEventWindowFocusRelinquish = 201;
90 internal const uint kEventWindowFocusContent = 202;
91 internal const uint kEventWindowFocusToolbar = 203;
92 internal const uint kEventWindowDrawerOpening = 220;
93 internal const uint kEventWindowDrawerOpened = 221;
94 internal const uint kEventWindowDrawerClosing = 222;
95 internal const uint kEventWindowDrawerClosed = 223;
96 internal const uint kEventWindowDrawFrame = 1000;
97 internal const uint kEventWindowDrawPart = 1001;
98 internal const uint kEventWindowGetRegion = 1002;
99 internal const uint kEventWindowHitTest = 1003;
100 internal const uint kEventWindowInit = 1004;
101 internal const uint kEventWindowDispose = 1005;
102 internal const uint kEventWindowDragHilite = 1006;
103 internal const uint kEventWindowModified = 1007;
104 internal const uint kEventWindowSetupProxyDragImage = 1008;
105 internal const uint kEventWindowStateChanged = 1009;
106 internal const uint kEventWindowMeasureTitle = 1010;
107 internal const uint kEventWindowDrawGrowBox = 1011;
108 internal const uint kEventWindowGetGrowImageRegion = 1012;
109 internal const uint kEventWindowPaint = 1013;
111 internal WindowHandler (XplatUICarbon driver) : base (driver) {}
113 public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
114 IntPtr window = Driver.HandleToWindow (handle);
115 Hwnd hwnd = Hwnd.ObjectFromHandle (window);
116 if (window != IntPtr.Zero) {
117 switch (kind) {
118 case kEventWindowActivated: {
119 Control c = Control.FromHandle (hwnd.client_window);
120 if (c != null) {
121 Form form = c.FindForm ();
122 if (form != null && !form.IsDisposed) {
123 Driver.SendMessage (form.Handle, Msg.WM_ACTIVATE, (IntPtr) WindowActiveFlags.WA_ACTIVE, IntPtr.Zero);
124 XplatUICarbon.ActiveWindow = hwnd.client_window;
128 foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
129 if (utility_window != handle && !XplatUICarbon.IsWindowVisible (utility_window))
130 XplatUICarbon.ShowWindow (utility_window);
132 break;
134 case kEventWindowExpanding:
135 foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
136 if (utility_window != handle && !XplatUICarbon.IsWindowVisible (utility_window))
137 XplatUICarbon.ShowWindow (utility_window);
139 msg.hwnd = hwnd.Handle;
140 msg.message = Msg.WM_ENTERSIZEMOVE;
141 return true;
142 case kEventWindowExpanded:
143 NativeWindow.WndProc (hwnd.Handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
144 msg.hwnd = hwnd.Handle;
145 msg.message = Msg.WM_EXITSIZEMOVE;
146 return true;
147 case kEventWindowDeactivated: {
148 Control c = Control.FromHandle (hwnd.client_window);
149 if (c != null) {
150 Form form = c.FindForm ();
151 if (form != null) {
152 Driver.SendMessage (form.Handle, Msg.WM_ACTIVATE, (IntPtr) WindowActiveFlags.WA_INACTIVE, IntPtr.Zero);
153 XplatUICarbon.ActiveWindow = IntPtr.Zero;
156 foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
157 if (utility_window != handle && XplatUICarbon.IsWindowVisible (utility_window))
158 XplatUICarbon.HideWindow (utility_window);
160 break;
162 case kEventWindowCollapsing:
163 foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
164 if (utility_window != handle && XplatUICarbon.IsWindowVisible (utility_window))
165 XplatUICarbon.HideWindow (utility_window);
167 msg.hwnd = hwnd.Handle;
168 msg.message = Msg.WM_ENTERSIZEMOVE;
169 return true;
170 case kEventWindowCollapsed:
171 NativeWindow.WndProc (hwnd.Handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
172 msg.hwnd = hwnd.Handle;
173 msg.message = Msg.WM_EXITSIZEMOVE;
174 return true;
175 case kEventWindowClose:
176 NativeWindow.WndProc (hwnd.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
177 return false;
178 case kEventWindowShown: {
179 msg.message = Msg.WM_SHOWWINDOW;
180 msg.lParam = (IntPtr) 1;
181 msg.wParam = (IntPtr) 0;
182 msg.hwnd = hwnd.Handle;
184 return true;
186 case kEventWindowResizeStarted: {
187 msg.message = Msg.WM_ENTERSIZEMOVE;
188 msg.hwnd = hwnd.Handle;
189 return true;
191 case kEventWindowResizeCompleted: {
192 msg.message = Msg.WM_EXITSIZEMOVE;
193 msg.hwnd = hwnd.Handle;
195 return true;
197 case kEventWindowBoundsChanged: {
198 Rect window_bounds = new Rect ();
199 HIRect view_bounds = new HIRect ();
200 Size size;
202 GetWindowBounds (handle, 33, ref window_bounds);
204 view_bounds.size.width = window_bounds.right - window_bounds.left;
205 view_bounds.size.height = window_bounds.bottom - window_bounds.top;
207 HIViewSetFrame (hwnd.WholeWindow, ref view_bounds);
209 size = XplatUICarbon.TranslateQuartzWindowSizeToWindowSize (Control.FromHandle (hwnd.Handle).GetCreateParams (), (int)view_bounds.size.width, (int)view_bounds.size.height);
211 hwnd.X = (int) window_bounds.left;
212 hwnd.Y = (int) window_bounds.top;
213 hwnd.Width = (int) size.Width;
214 hwnd.Height = (int) size.Height;
216 Driver.PerformNCCalc (hwnd);
218 msg.hwnd = hwnd.Handle;
219 msg.message = Msg.WM_WINDOWPOSCHANGED;
220 Driver.SetCaretPos (XplatUICarbon.Caret.Hwnd, XplatUICarbon.Caret.X, XplatUICarbon.Caret.Y);
222 return true;
226 return false;
229 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
230 static extern int GetWindowBounds (IntPtr handle, uint region, ref Rect bounds);
232 [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
233 static extern int HIViewSetFrame (IntPtr handle, ref HIRect bounds);