Mercurial > silverbladetech
comparison SilverlightGlimpse/FloatableWindow/FloatableWindowAutomationPeer.cs @ 62:810116cd6b8e
ErrorWindow working
author | Steven Hollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sun, 22 Apr 2012 09:01:20 +0100 |
parents | |
children | a0bcd783e612 |
comparison
equal
deleted
inserted
replaced
61:9de81c9ad319 | 62:810116cd6b8e |
---|---|
1 // (c) Copyright Microsoft Corporation. | |
2 // This source is subject to the Microsoft Public License (Ms-PL). | |
3 // Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details. | |
4 // All other rights reserved. | |
5 | |
6 using System.Windows.Automation.Provider; | |
7 using System.Windows.Controls; | |
8 using System.Windows.Media; | |
9 | |
10 namespace System.Windows.Automation.Peers | |
11 { | |
12 /// <summary> | |
13 /// Exposes <see cref="T:System.Windows.Controls.FloatableWindow" /> types to UI | |
14 /// automation. | |
15 /// </summary> | |
16 /// <QualityBand>Preview</QualityBand> | |
17 public class FloatableWindowAutomationPeer : FrameworkElementAutomationPeer, IWindowProvider, ITransformProvider | |
18 { | |
19 #region Data | |
20 | |
21 /// <summary> | |
22 /// Specifies whether the FloatableWindow is the top most element. | |
23 /// </summary> | |
24 private bool _isTopMost; | |
25 | |
26 #endregion Data | |
27 | |
28 #region Properties | |
29 | |
30 /// <summary> | |
31 /// Gets or sets a value indicating whether the FloatableWindow is the top most element. | |
32 /// </summary> | |
33 private bool IsTopMostPrivate | |
34 { | |
35 get | |
36 { | |
37 return this._isTopMost; | |
38 } | |
39 set | |
40 { | |
41 if (this._isTopMost != value) | |
42 { | |
43 this._isTopMost = value; | |
44 this.RaisePropertyChangedEvent(WindowPatternIdentifiers.IsTopmostProperty, !this._isTopMost, this._isTopMost); | |
45 } | |
46 } | |
47 } | |
48 | |
49 /// <summary> | |
50 /// Gets the owning FloatableWindow. | |
51 /// </summary> | |
52 private FloatableWindow OwningFloatableWindow | |
53 { | |
54 get | |
55 { | |
56 return (FloatableWindow)Owner; | |
57 } | |
58 } | |
59 | |
60 #endregion Properties | |
61 | |
62 /// <summary> | |
63 /// Initializes a new instance of the | |
64 /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" /> | |
65 /// class. | |
66 /// </summary> | |
67 /// <param name="owner"> | |
68 /// The <see cref="T:System.Windows.Controls.FloatableWindow" /> to | |
69 /// associate with this | |
70 /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. | |
71 /// </param> | |
72 public FloatableWindowAutomationPeer(FloatableWindow owner) | |
73 : base(owner) | |
74 { | |
75 if (owner == null) | |
76 { | |
77 throw new ArgumentNullException("owner"); | |
78 } | |
79 this.RefreshIsTopMostProperty(); | |
80 } | |
81 | |
82 #region AutomationPeer overrides | |
83 | |
84 /// <summary> | |
85 /// Gets the control pattern for this | |
86 /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. | |
87 /// </summary> | |
88 /// <param name="patternInterface"> | |
89 /// One of the enumeration values. | |
90 /// </param> | |
91 /// <returns> | |
92 /// The object that implements the pattern interface, or null if the | |
93 /// specified pattern interface is not implemented by this peer. | |
94 /// </returns> | |
95 public override object GetPattern(PatternInterface patternInterface) | |
96 { | |
97 if (patternInterface == PatternInterface.Transform || patternInterface == PatternInterface.Window) | |
98 { | |
99 return this; | |
100 } | |
101 | |
102 return base.GetPattern(patternInterface); | |
103 } | |
104 | |
105 /// <summary> | |
106 /// Gets the | |
107 /// <see cref="T:System.Windows.Automation.Peers.AutomationControlType" /> | |
108 /// for the element associated with this | |
109 /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. | |
110 /// Called by | |
111 /// <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetAutomationControlType" />. | |
112 /// </summary> | |
113 /// <returns>A value of the enumeration.</returns> | |
114 protected override AutomationControlType GetAutomationControlTypeCore() | |
115 { | |
116 return AutomationControlType.Window; | |
117 } | |
118 | |
119 /// <summary> | |
120 /// Gets the name of the class for the object associated with this | |
121 /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. | |
122 /// Called by | |
123 /// <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetClassName" />. | |
124 /// </summary> | |
125 /// <returns> | |
126 /// A string value that represents the type of the child window. | |
127 /// </returns> | |
128 protected override string GetClassNameCore() | |
129 { | |
130 return this.Owner.GetType().Name; | |
131 } | |
132 | |
133 /// <summary> | |
134 /// Gets the text label of the | |
135 /// <see cref="T:System.Windows.Controls.FloatableWindow" /> that is | |
136 /// associated with this | |
137 /// <see cref="T:System.Windows.Automation.Peers.FloatableWindowAutomationPeer" />. | |
138 /// Called by | |
139 /// <see cref="M:System.Windows.Automation.Peers.AutomationPeer.GetName" />. | |
140 /// </summary> | |
141 /// <returns> | |
142 /// The text label of the element that is associated with this | |
143 /// automation peer. | |
144 /// </returns> | |
145 protected override string GetNameCore() | |
146 { | |
147 string name = base.GetNameCore(); | |
148 if (string.IsNullOrEmpty(name)) | |
149 { | |
150 AutomationPeer labeledBy = GetLabeledByCore(); | |
151 if (labeledBy != null) | |
152 { | |
153 name = labeledBy.GetName(); | |
154 } | |
155 | |
156 if (string.IsNullOrEmpty(name) && this.OwningFloatableWindow.Title != null) | |
157 { | |
158 name = this.OwningFloatableWindow.Title.ToString(); | |
159 } | |
160 } | |
161 return name; | |
162 } | |
163 | |
164 #endregion AutomationPeer overrides | |
165 | |
166 #region IWindowProvider | |
167 | |
168 /// <summary> | |
169 /// Gets the interaction state of the window. | |
170 /// </summary> | |
171 /// <value> | |
172 /// The interaction state of the control, as a value of the enumeration. | |
173 /// </value> | |
174 WindowInteractionState IWindowProvider.InteractionState | |
175 { | |
176 get | |
177 { | |
178 return this.OwningFloatableWindow.InteractionState; | |
179 } | |
180 } | |
181 | |
182 /// <summary> | |
183 /// Gets a value indicating whether the window is modal. | |
184 /// </summary> | |
185 /// <value> | |
186 /// True in all cases. | |
187 /// </value> | |
188 bool IWindowProvider.IsModal | |
189 { | |
190 get { return true; } | |
191 } | |
192 | |
193 /// <summary> | |
194 /// Gets a value indicating whether the window is the topmost | |
195 /// element in the z-order of layout. | |
196 /// </summary> | |
197 /// <value> | |
198 /// True if the window is topmost; otherwise, false. | |
199 /// </value> | |
200 bool IWindowProvider.IsTopmost | |
201 { | |
202 get | |
203 { | |
204 return this.IsTopMostPrivate; | |
205 } | |
206 } | |
207 | |
208 /// <summary> | |
209 /// Gets a value indicating whether the window can be maximized. | |
210 /// </summary> | |
211 /// <value>False in all cases.</value> | |
212 bool IWindowProvider.Maximizable | |
213 { | |
214 get { return false; } | |
215 } | |
216 | |
217 /// <summary> | |
218 /// Gets a value indicating whether the window can be minimized. | |
219 /// </summary> | |
220 /// <value>False in all cases.</value> | |
221 bool IWindowProvider.Minimizable | |
222 { | |
223 get { return false; } | |
224 } | |
225 | |
226 /// <summary> | |
227 /// Gets the visual state of the window. | |
228 /// </summary> | |
229 /// <value> | |
230 /// <see cref="F:System.Windows.Automation.WindowVisualState.Normal" /> | |
231 /// in all cases. | |
232 /// </value> | |
233 WindowVisualState IWindowProvider.VisualState | |
234 { | |
235 get | |
236 { | |
237 return WindowVisualState.Normal; | |
238 } | |
239 } | |
240 | |
241 /// <summary> | |
242 /// Closes the window. | |
243 /// </summary> | |
244 void IWindowProvider.Close() | |
245 { | |
246 this.OwningFloatableWindow.Close(); | |
247 } | |
248 | |
249 /// <summary> | |
250 /// Changes the visual state of the window (such as minimizing or | |
251 /// maximizing it). | |
252 /// </summary> | |
253 /// <param name="state"> | |
254 /// The visual state of the window to change to, as a value of the | |
255 /// enumeration. | |
256 /// </param> | |
257 void IWindowProvider.SetVisualState(WindowVisualState state) | |
258 { | |
259 } | |
260 | |
261 /// <summary> | |
262 /// Blocks the calling code for the specified time or until the | |
263 /// associated process enters an idle state, whichever completes first. | |
264 /// </summary> | |
265 /// <param name="milliseconds"> | |
266 /// The amount of time, in milliseconds, to wait for the associated | |
267 /// process to become idle. | |
268 /// </param> | |
269 /// <returns> | |
270 /// True if the window has entered the idle state; false if the timeout | |
271 /// occurred. | |
272 /// </returns> | |
273 bool IWindowProvider.WaitForInputIdle(int milliseconds) | |
274 { | |
275 return false; | |
276 } | |
277 | |
278 #endregion IWindowProvider | |
279 | |
280 #region ITransformProvider | |
281 | |
282 /// <summary> | |
283 /// Moves the control. | |
284 /// </summary> | |
285 /// <param name="x"> | |
286 /// The absolute screen coordinates of the left side of the control. | |
287 /// </param> | |
288 /// <param name="y"> | |
289 /// The absolute screen coordinates of the top of the control. | |
290 /// </param> | |
291 void ITransformProvider.Move(double x, double y) | |
292 { | |
293 if (x < 0) | |
294 { | |
295 x = 0; | |
296 } | |
297 | |
298 if (y < 0) | |
299 { | |
300 y = 0; | |
301 } | |
302 | |
303 if (x > this.OwningFloatableWindow.Width) | |
304 { | |
305 x = this.OwningFloatableWindow.Width; | |
306 } | |
307 | |
308 if (y > this.OwningFloatableWindow.Height) | |
309 { | |
310 y = this.OwningFloatableWindow.Height; | |
311 } | |
312 | |
313 FrameworkElement contentRoot = this.OwningFloatableWindow.ContentRoot; | |
314 | |
315 if (contentRoot != null) | |
316 { | |
317 GeneralTransform gt = contentRoot.TransformToVisual(null); | |
318 | |
319 if (gt != null) | |
320 { | |
321 Point p = gt.Transform(new Point(0, 0)); | |
322 | |
323 TransformGroup transformGroup = contentRoot.RenderTransform as TransformGroup; | |
324 | |
325 if (transformGroup == null) | |
326 { | |
327 transformGroup = new TransformGroup(); | |
328 transformGroup.Children.Add(contentRoot.RenderTransform); | |
329 } | |
330 | |
331 TranslateTransform t = new TranslateTransform(); | |
332 t.X = x - p.X; | |
333 t.Y = y - p.Y; | |
334 | |
335 if (transformGroup != null) | |
336 { | |
337 transformGroup.Children.Add(t); | |
338 contentRoot.RenderTransform = transformGroup; | |
339 } | |
340 } | |
341 } | |
342 } | |
343 | |
344 /// <summary> | |
345 /// Resizes the control. | |
346 /// </summary> | |
347 /// <param name="width">The new width of the window, in pixels.</param> | |
348 /// <param name="height"> | |
349 /// The new height of the window, in pixels. | |
350 /// </param> | |
351 void ITransformProvider.Resize(double width, double height) | |
352 { | |
353 } | |
354 | |
355 /// <summary> | |
356 /// Rotates the control. | |
357 /// </summary> | |
358 /// <param name="degrees"> | |
359 /// The number of degrees to rotate the control. A positive number | |
360 /// rotates the control clockwise. A negative number rotates the | |
361 /// control counterclockwise. | |
362 /// </param> | |
363 void ITransformProvider.Rotate(double degrees) | |
364 { | |
365 } | |
366 | |
367 /// <summary> | |
368 /// Gets a value indicating whether the element can be moved. | |
369 /// </summary> | |
370 /// <value>True in all cases.</value> | |
371 bool ITransformProvider.CanMove | |
372 { | |
373 get { return true; } | |
374 } | |
375 | |
376 /// <summary> | |
377 /// Gets a value indicating whether the element can be resized. | |
378 /// </summary> | |
379 /// <value>False in all cases.</value> | |
380 bool ITransformProvider.CanResize | |
381 { | |
382 get { return false; } | |
383 } | |
384 | |
385 /// <summary> | |
386 /// Gets a value indicating whether the element can be rotated. | |
387 /// </summary> | |
388 /// <value>False in all cases.</value> | |
389 bool ITransformProvider.CanRotate | |
390 { | |
391 get { return false; } | |
392 } | |
393 | |
394 #endregion ITransformProvider | |
395 | |
396 #region Methods | |
397 | |
398 /// <summary> | |
399 /// Returns if the FloatableWindow is the top most element. | |
400 /// </summary> | |
401 /// <returns>Bool value.</returns> | |
402 private bool GetIsTopMostCore() | |
403 { | |
404 return !(this.OwningFloatableWindow.InteractionState == WindowInteractionState.BlockedByModalWindow); | |
405 } | |
406 | |
407 /// <summary> | |
408 /// Raises PropertyChangedEvent for WindowInteractionStateProperty. | |
409 /// </summary> | |
410 /// <param name="oldValue">Old WindowInteractionStateProperty.</param> | |
411 /// <param name="newValue">New WindowInteractionStateProperty.</param> | |
412 internal void RaiseInteractionStatePropertyChangedEvent(WindowInteractionState oldValue, WindowInteractionState newValue) | |
413 { | |
414 this.RaisePropertyChangedEvent(WindowPatternIdentifiers.WindowInteractionStateProperty, oldValue, newValue); | |
415 this.RefreshIsTopMostProperty(); | |
416 } | |
417 | |
418 /// <summary> | |
419 /// Updates the IsTopMostPrivate property. | |
420 /// </summary> | |
421 private void RefreshIsTopMostProperty() | |
422 { | |
423 this.IsTopMostPrivate = this.GetIsTopMostCore(); | |
424 } | |
425 | |
426 #endregion Methods | |
427 } | |
428 } | |
429 |