File: WindowHandler.cs

package info (click to toggle)
mono 6.8.0.105%2Bdfsg-3.3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,284,512 kB
  • sloc: cs: 11,172,132; xml: 2,850,069; ansic: 671,653; cpp: 122,091; perl: 59,366; javascript: 30,841; asm: 22,168; makefile: 20,093; sh: 15,020; python: 4,827; pascal: 925; sql: 859; sed: 16; php: 1
file content (235 lines) | stat: -rw-r--r-- 10,068 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
// 
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc.
//
// Authors:
//	Geoff Norton  <gnorton@novell.com>
//
//

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace System.Windows.Forms.CarbonInternal {
	internal class WindowHandler : EventHandlerBase, IEventHandler {
		internal const uint kEventWindowUpdate = 1;
		internal const uint kEventWindowDrawContent = 2;
		internal const uint kEventWindowActivated = 5;
		internal const uint kEventWindowDeactivated = 6;
		internal const uint kEventWindowGetClickActivation = 7;
		internal const uint kEventWindowShowing = 22;
		internal const uint kEventWindowHiding = 23;
		internal const uint kEventWindowShown = 24;
		internal const uint kEventWindowHidden = 25;
		internal const uint kEventWindowCollapsing = 86;
		internal const uint kEventWindowExpanding = 87;
		internal const uint kEventWindowZoomed = 76;
		internal const uint kEventWindowBoundsChanging = 26;
		internal const uint kEventWindowBoundsChanged = 27;
		internal const uint kEventWindowResizeStarted = 28;
		internal const uint kEventWindowResizeCompleted = 29;
		internal const uint kEventWindowDragStarted = 30;
		internal const uint kEventWindowDragCompleted = 31;
		internal const uint kEventWindowTransitionStarted = 88;
		internal const uint kEventWindowTransitionCompleted = 89;
		internal const uint kEventWindowClickDragRgn = 32;
		internal const uint kEventWindowClickResizeRgn = 33;
		internal const uint kEventWindowClickCollapseRgn = 34;
		internal const uint kEventWindowClickCloseRgn = 35;
		internal const uint kEventWindowClickZoomRgn = 36;
		internal const uint kEventWindowClickContentRgn = 37;
		internal const uint kEventWindowClickProxyIconRgn = 38;
		internal const uint kEventWindowClickToolbarButtonRgn = 41;
		internal const uint kEventWindowClickStructureRgn = 42;
		internal const uint kEventWindowCursorChange = 40;
		internal const uint kEventWindowCollapse = 66;
		internal const uint kEventWindowCollapsed = 67;
		internal const uint kEventWindowCollapseAll = 68;
		internal const uint kEventWindowExpand = 69;
		internal const uint kEventWindowExpanded = 70;
		internal const uint kEventWindowExpandAll = 71;
		internal const uint kEventWindowClose = 72;
		internal const uint kEventWindowClosed = 73;
		internal const uint kEventWindowCloseAll = 74;
		internal const uint kEventWindowZoom = 75;
		internal const uint kEventWindowZoomAll = 77;
		internal const uint kEventWindowContextualMenuSelect = 78;
		internal const uint kEventWindowPathSelect = 79;
		internal const uint kEventWindowGetIdealSize = 80;
		internal const uint kEventWindowGetMinimumSize = 81;
		internal const uint kEventWindowGetMaximumSize = 82;
		internal const uint kEventWindowConstrain = 83;
		internal const uint kEventWindowHandleContentClick = 85;
		internal const uint kEventWindowGetDockTileMenu = 90;
		internal const uint kEventWindowHandleActivate = 91;
		internal const uint kEventWindowHandleDeactivate = 92;
		internal const uint kEventWindowProxyBeginDrag = 128;
		internal const uint kEventWindowProxyEndDrag = 129;
		internal const uint kEventWindowToolbarSwitchMode = 150;
		internal const uint kEventWindowFocusAcquired = 200;
		internal const uint kEventWindowFocusRelinquish = 201;
		internal const uint kEventWindowFocusContent = 202;
		internal const uint kEventWindowFocusToolbar = 203;
		internal const uint kEventWindowDrawerOpening = 220;
		internal const uint kEventWindowDrawerOpened = 221;
		internal const uint kEventWindowDrawerClosing = 222;
		internal const uint kEventWindowDrawerClosed = 223;
		internal const uint kEventWindowDrawFrame = 1000;
		internal const uint kEventWindowDrawPart = 1001;
		internal const uint kEventWindowGetRegion = 1002;
		internal const uint kEventWindowHitTest = 1003;
		internal const uint kEventWindowInit = 1004;
		internal const uint kEventWindowDispose = 1005;
		internal const uint kEventWindowDragHilite = 1006;
		internal const uint kEventWindowModified = 1007;
		internal const uint kEventWindowSetupProxyDragImage = 1008;
		internal const uint kEventWindowStateChanged = 1009;
		internal const uint kEventWindowMeasureTitle = 1010;
		internal const uint kEventWindowDrawGrowBox = 1011;
		internal const uint kEventWindowGetGrowImageRegion = 1012;
		internal const uint kEventWindowPaint = 1013;
		
		internal WindowHandler (XplatUICarbon driver) : base (driver) {}

		public bool ProcessEvent (IntPtr callref, IntPtr eventref, IntPtr handle, uint kind, ref MSG msg) {
			IntPtr window = Driver.HandleToWindow (handle);
			Hwnd hwnd = Hwnd.ObjectFromHandle (window);
			if (window != IntPtr.Zero) {
				switch (kind) {
					case kEventWindowActivated: {
						Control c = Control.FromHandle (hwnd.client_window);
						if (c != null) {
							Form form = c.FindForm ();
							if (form != null && !form.IsDisposed) {
								Driver.SendMessage (form.Handle, Msg.WM_ACTIVATE, (IntPtr) WindowActiveFlags.WA_ACTIVE, IntPtr.Zero);
								XplatUICarbon.ActiveWindow = hwnd.client_window;
							}
						}

						foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
							if (utility_window != handle && !XplatUICarbon.IsWindowVisible (utility_window))
								XplatUICarbon.ShowWindow (utility_window);
						}	
						break;
					}
					case kEventWindowExpanding:
						foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
							if (utility_window != handle && !XplatUICarbon.IsWindowVisible (utility_window))
								XplatUICarbon.ShowWindow (utility_window);
						}
						msg.hwnd = hwnd.Handle;
						msg.message = Msg.WM_ENTERSIZEMOVE;
						return true;
					case kEventWindowExpanded:
						NativeWindow.WndProc (hwnd.Handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
						msg.hwnd = hwnd.Handle;
						msg.message = Msg.WM_EXITSIZEMOVE;
						return true;
					case kEventWindowDeactivated: {
						Control c = Control.FromHandle (hwnd.client_window);
						if (c != null) {
							Form form = c.FindForm ();
							if (form != null && XplatUICarbon.UnactiveWindow != form.Handle) {
								Driver.SendMessage (form.Handle, Msg.WM_ACTIVATE, (IntPtr) WindowActiveFlags.WA_INACTIVE, IntPtr.Zero);
								XplatUICarbon.ActiveWindow = IntPtr.Zero;
							}
						}
						foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
							if (utility_window != handle && XplatUICarbon.IsWindowVisible (utility_window))
								XplatUICarbon.HideWindow (utility_window);
						}
						break;
					}
					case kEventWindowCollapsing:
						foreach (IntPtr utility_window in XplatUICarbon.UtilityWindows) {
							if (utility_window != handle && XplatUICarbon.IsWindowVisible (utility_window))
								XplatUICarbon.HideWindow (utility_window);
						}	
						msg.hwnd = hwnd.Handle;
						msg.message = Msg.WM_ENTERSIZEMOVE;
						return true;
					case kEventWindowCollapsed:
						NativeWindow.WndProc (hwnd.Handle, Msg.WM_WINDOWPOSCHANGED, IntPtr.Zero, IntPtr.Zero);
						msg.hwnd = hwnd.Handle;
						msg.message = Msg.WM_EXITSIZEMOVE;
						return true;
					case kEventWindowClose:
						NativeWindow.WndProc (hwnd.Handle, Msg.WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
						return false;
					case kEventWindowShown: { 
						msg.message = Msg.WM_SHOWWINDOW;
						msg.lParam = (IntPtr) 1;
						msg.wParam = (IntPtr) 0;
						msg.hwnd = hwnd.Handle;

						return true;
					}
					case kEventWindowResizeStarted: {
						msg.message = Msg.WM_ENTERSIZEMOVE;
						msg.hwnd = hwnd.Handle;
						return true;
					}
					case kEventWindowResizeCompleted: {
						msg.message = Msg.WM_EXITSIZEMOVE;
						msg.hwnd = hwnd.Handle;

						return true;
					}
					case kEventWindowBoundsChanged: {
						Rect window_bounds = new Rect ();
						HIRect view_bounds = new HIRect ();
						Size size;

						GetWindowBounds (handle, 33, ref window_bounds);
						
						view_bounds.size.width = window_bounds.right - window_bounds.left;
						view_bounds.size.height = window_bounds.bottom - window_bounds.top;

						HIViewSetFrame (hwnd.WholeWindow, ref view_bounds);

						size = XplatUICarbon.TranslateQuartzWindowSizeToWindowSize (Control.FromHandle (hwnd.Handle).GetCreateParams (), (int)view_bounds.size.width, (int)view_bounds.size.height);

						hwnd.X = (int) window_bounds.left;
						hwnd.Y = (int) window_bounds.top;
						hwnd.Width = (int) size.Width;
						hwnd.Height = (int) size.Height;

						Driver.PerformNCCalc (hwnd);

						msg.hwnd = hwnd.Handle;
						msg.message = Msg.WM_WINDOWPOSCHANGED;
						Driver.SetCaretPos (XplatUICarbon.Caret.Hwnd, XplatUICarbon.Caret.X, XplatUICarbon.Caret.Y);

						return true;
					}
				}
			}
			return false;
		}

		[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
		static extern int GetWindowBounds (IntPtr handle, uint region, ref Rect bounds);

		[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
		static extern int HIViewSetFrame (IntPtr handle, ref HIRect bounds);
	}
}