PageRenderTime 15ms CodeModel.GetById 11ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/SharpTreeView/GeneralAdorner.cs

http://github.com/icsharpcode/ILSpy
C# | 81 lines | 56 code | 8 blank | 17 comment | 7 complexity | a4ba383c489f1b1ab591154cb00c1c46 MD5 | raw file
 1// Copyright (c) 2020 AlphaSierraPapa for the SharpDevelop Team
 2// 
 3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 4// software and associated documentation files (the "Software"), to deal in the Software
 5// without restriction, including without limitation the rights to use, copy, modify, merge,
 6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 7// to whom the Software is furnished to do so, subject to the following conditions:
 8// 
 9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11// 
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System.Windows.Documents;
20using System.Windows;
21using System.Windows.Media;
22
23namespace ICSharpCode.TreeView
24{
25	public class GeneralAdorner : Adorner
26	{
27		public GeneralAdorner(UIElement target)
28			: base(target)
29		{
30		}
31
32		FrameworkElement child;
33
34		public FrameworkElement Child
35		{
36			get
37			{
38				return child;
39			}
40			set
41			{
42				if (child != value) {
43					RemoveVisualChild(child);
44					RemoveLogicalChild(child);
45					child = value;
46					AddLogicalChild(value);
47					AddVisualChild(value);
48					InvalidateMeasure();
49				}
50			}
51		}
52
53		protected override int VisualChildrenCount
54		{
55			get { return child == null ? 0 : 1; }
56		}
57
58		protected override Visual GetVisualChild(int index)
59		{
60			return child;
61		}
62
63		protected override Size MeasureOverride(Size constraint)
64		{
65			if (child != null) {
66				child.Measure(constraint);
67				return child.DesiredSize;
68			}
69			return new Size();
70		}
71
72		protected override Size ArrangeOverride(Size finalSize)
73		{
74			if (child != null) {
75				child.Arrange(new Rect(finalSize));
76				return finalSize;
77			}
78			return new Size();
79		}
80	}
81}