2 // System.Windows.UIElement.cs
5 // Moonlight List (moonlight-list@lists.ximian.com)
7 // Copyright 2007 Novell, Inc.
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System
.Collections
.Generic
;
31 using System
.Runtime
.InteropServices
;
33 using System
.Windows
.Automation
.Peers
;
34 using System
.Windows
.Media
;
35 using System
.Windows
.Input
;
38 namespace System
.Windows
{
39 public abstract partial class UIElement
: DependencyObject
{
41 public Transform RenderTransform
{
43 Transform t
= (Transform
)GetValue (RenderTransformProperty
);
44 return t
== null ? new MatrixTransform () : t
;
48 ClearValue (RenderTransformProperty
);
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
112 internal AutomationPeer AutomationPeer
{
116 // needed by FrameworkElementAutomationPeer
117 internal AutomationPeer
CreateAutomationPeer ()
119 return OnCreateAutomationPeer ();
122 public Size DesiredSize
{
124 return NativeMethods
.uielement_get_desired_size (native
);
128 public Size RenderSize
{
130 return NativeMethods
.uielement_get_render_size (native
);
135 public event MouseButtonEventHandler MouseRightButtonDown
{
137 RegisterEvent (EventIds
.UIElement_MouseRightButtonDownEvent
, value, Events
.CreateMouseButtonEventHandlerDispatcher (value));
140 UnregisterEvent (EventIds
.UIElement_MouseRightButtonDownEvent
, value);
144 public event MouseButtonEventHandler MouseRightButtonUp
{
146 RegisterEvent (EventIds
.UIElement_MouseRightButtonUpEvent
, value, Events
.CreateMouseButtonEventHandlerDispatcher (value));
149 UnregisterEvent (EventIds
.UIElement_MouseRightButtonUpEvent
, value);
154 public void AddHandler (RoutedEvent routedEvent
,
156 bool handledEventsToo
)
159 // FIXME: we don't handle handledEventsToo
160 RegisterEvent (routedEvent
.EventId
, handler
, Events
.CreateDispatcherFromEventId (routedEvent
.EventId
, handler
));