in class/Microsoft.SilverlightControls/:
[moon.git] / class / System.Windows / System.Windows / UIElement.cs
blob4d9b74c57a6ea26256c9a88a6ad674a3837389e5
1 //
2 // System.Windows.UIElement.cs
3 //
4 // Contact:
5 // Moonlight List (moonlight-list@lists.ximian.com)
6 //
7 // Copyright 2007 Novell, Inc.
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System;
30 using System.Collections.Generic;
31 using System.Runtime.InteropServices;
32 using System.Windows;
33 using System.Windows.Automation.Peers;
34 using System.Windows.Media;
35 using System.Windows.Input;
36 using Mono;
38 namespace System.Windows {
39 public abstract partial class UIElement : DependencyObject {
41 public Transform RenderTransform {
42 get {
43 Transform t = (Transform)GetValue (RenderTransformProperty);
44 return t == null ? new MatrixTransform () : t;
46 set {
47 if (value == null)
48 ClearValue (RenderTransformProperty);
49 else
50 SetValue (RenderTransformProperty, value);
54 public bool CaptureMouse ()
56 return NativeMethods.uielement_capture_mouse (native);
59 public void ReleaseMouseCapture ()
61 NativeMethods.uielement_release_mouse_capture (native);
64 public void Arrange (Rect finalRect)
66 if (finalRect.IsEmpty)
67 throw new InvalidOperationException ("Empty Rect");
69 if (Double.IsInfinity (finalRect.Width) || Double.IsInfinity (finalRect.Height) || Double.IsInfinity (finalRect.X) || Double.IsInfinity (finalRect.Y))
70 throw new InvalidOperationException ("Infinite Rect");
71 if (Double.IsNaN (finalRect.Width) || Double.IsNaN (finalRect.Height) || Double.IsNaN (finalRect.X) || Double.IsNaN (finalRect.Y))
72 throw new InvalidOperationException ("NaN Rect");
74 NativeMethods.uielement_arrange(native, finalRect);
77 public void InvalidateArrange ()
79 NativeMethods.uielement_invalidate_arrange(native);
82 public void Measure (Size availableSize)
84 NativeMethods.uielement_measure (native, availableSize);
87 public void InvalidateMeasure ()
89 NativeMethods.uielement_invalidate_measure (native);
92 public void UpdateLayout ()
94 NativeMethods.uielement_update_layout (native);
97 public GeneralTransform TransformToVisual (UIElement visual)
99 IntPtr t = NativeMethods.uielement_get_transform_to_uielement (native, visual == null ? IntPtr.Zero : visual.native);
101 return (MatrixTransform) NativeDependencyObjectHelper.Lookup (Kind.MATRIXTRANSFORM, t);
104 protected virtual AutomationPeer OnCreateAutomationPeer ()
106 // there's no automation object associated with UIElement so null is returned
107 // it could have been abtract but that that would have forced everyone (without
108 // automation support) to override this default
109 return null;
112 internal AutomationPeer AutomationPeer {
113 get; set;
116 // needed by FrameworkElementAutomationPeer
117 internal AutomationPeer CreateAutomationPeer ()
119 return OnCreateAutomationPeer ();
122 public Size DesiredSize {
123 get {
124 return NativeMethods.uielement_get_desired_size (native);
128 public Size RenderSize {
129 get {
130 return NativeMethods.uielement_get_render_size (native);
134 #if NET_3_0
135 public event MouseButtonEventHandler MouseRightButtonDown {
136 add {
137 RegisterEvent (EventIds.UIElement_MouseRightButtonDownEvent, value, Events.CreateMouseButtonEventHandlerDispatcher (value));
139 remove {
140 UnregisterEvent (EventIds.UIElement_MouseRightButtonDownEvent, value);
144 public event MouseButtonEventHandler MouseRightButtonUp {
145 add {
146 RegisterEvent (EventIds.UIElement_MouseRightButtonUpEvent, value, Events.CreateMouseButtonEventHandlerDispatcher (value));
148 remove {
149 UnregisterEvent (EventIds.UIElement_MouseRightButtonUpEvent, value);
152 #endif
154 public void AddHandler (RoutedEvent routedEvent,
155 Delegate handler,
156 bool handledEventsToo)
159 // FIXME: we don't handle handledEventsToo
160 RegisterEvent (routedEvent.EventId, handler, Events.CreateDispatcherFromEventId (routedEvent.EventId, handler));