SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
GenieGraphPanel.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Windows;
6 using System.Windows.Controls;
7 
8 namespace SeciControls
9 {
10  public class GenieGraphPanel : Panel
11  {
12  public GenieGraphPanel()
13  : base()
14  {
15  }
16 
17  protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize)
18  {
19  foreach (UIElement child in InternalChildren)
20  {
21  child.Measure(availableSize);
22  }
23  return availableSize;
24  }
25 
26  protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)
27  {
28  double geniesWidth = 0;
29  double geniesHeight = 0;
30  Boolean geniesVertical = false;
31  Boolean graphTop = true;
32 
33  UIElementCollection children = InternalChildren;
34  UIElement graph;
35  UIElement genie1;
36  UIElement genie2 = null;
37 
38  if (children[0].IsVisible)
39  {
40  //It has a visible graph
41  graph = children[0];
42  genie1 = children[1];
43  if (children[2].IsVisible)
44  {
45  genie2 = children[2];
46 
47  if (2.0 * genie1.DesiredSize.Width > finalSize.Width)
48  {
49  geniesVertical = true;
50  geniesWidth = genie1.DesiredSize.Width;
51  geniesHeight = 2.0 * genie1.DesiredSize.Height;
52  }
53  else
54  {
55  geniesVertical = false;
56  geniesWidth = 2.0 * genie1.DesiredSize.Width;
57  geniesHeight = genie1.DesiredSize.Height;
58  }
59  }
60  else
61  {
62  geniesVertical = false; //Does not really matter as there is only one genie
63  geniesWidth = genie1.DesiredSize.Width;
64  geniesHeight = genie1.DesiredSize.Height;
65  }
66 
67  //Calculate where the most free space is
68  double topHeight = finalSize.Height - geniesHeight;
69  double topWidth = finalSize.Width;
70  double topArea = topHeight * topWidth;
71 
72  double rightHeight = finalSize.Height;
73  double rightWidth = finalSize.Width - geniesWidth;
74  double rightArea = rightHeight * rightWidth;
75 
76  //if (rightArea > topArea)
77  //{
78  // graphTop = false;
79  //}
80 
81 
82  if (finalSize.Width - geniesWidth > finalSize.Height - geniesHeight && rightHeight / rightWidth > topHeight / topWidth)
83  {
84  //Move graph to rightside
85  graphTop = false;
86  }
87 
88  if (graphTop)
89  {
90  graph.Arrange(new Rect(0, 0, finalSize.Width, finalSize.Height - geniesHeight));
91  System.Windows.Controls.Primitives.UniformGrid temp = graph as System.Windows.Controls.Primitives.UniformGrid;
92  if (temp != null)
93  {
94  temp.Columns = temp.Children.Count;
95  temp.Rows = 1;
96  }
97  genie1.Arrange(new Rect(new Point(0, finalSize.Height - geniesHeight), genie1.DesiredSize));
98  if (genie2 != null)
99  {
100  if (geniesVertical)
101  {
102  genie2.Arrange(new Rect(new Point(0, finalSize.Height - geniesHeight + genie1.DesiredSize.Height), genie2.DesiredSize));
103  }
104  else
105  {
106  genie2.Arrange(new Rect(new Point(genie1.DesiredSize.Width, finalSize.Height - geniesHeight), genie2.DesiredSize));
107  }
108  }
109  }
110  else
111  {
112  genie1.Arrange(new Rect(new Point(0, 0), genie1.DesiredSize));
113  if (genie2 != null)
114  {
115  genie2.Arrange(new Rect(new Point(0, genie1.DesiredSize.Height), genie2.DesiredSize));
116  }
117  graph.Arrange(new Rect(genie1.DesiredSize.Width, 0, finalSize.Width - genie1.DesiredSize.Width, finalSize.Height));
118  System.Windows.Controls.Primitives.UniformGrid temp = graph as System.Windows.Controls.Primitives.UniformGrid;
119  if (temp != null)
120  {
121  temp.Columns = 1;
122  temp.Rows = temp.Children.Count;
123  }
124  }
125  }
126  else if (children[1].IsVisible)
127  {
128  //No graph so treat as a wrappanel
129  genie1 = children[1];
130  if (children[2].IsVisible)
131  {
132  genie2 = children[2];
133  }
134  genie1.Arrange(new Rect(new Point(0, 0), genie1.DesiredSize));
135 
136  if (genie2 != null)
137  {
138  if (2.0 * genie1.DesiredSize.Width > finalSize.Width)
139  {
140  genie2.Arrange(new Rect(new Point(0, genie1.DesiredSize.Height), genie2.DesiredSize));
141  }
142  else
143  {
144  genie2.Arrange(new Rect(new Point(genie1.DesiredSize.Width, 0), genie2.DesiredSize));
145  }
146  }
147 
148  }
149 
150  return finalSize;
151  }
152  }
153 }
154 
override System.Windows.Size MeasureOverride(System.Windows.Size availableSize)
override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)