2009-11-13 Jeffrey Stedfast <fejj@novell.com>
[moon.git] / src / grid.h
blobbf587bfdd5a3394b3f977c9177d191b890afe261
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * grid.h
5 * Copyright 2008 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
8 *
9 */
11 #ifndef __MOON_GRID_H__
12 #define __MOON_GRID_H__
14 #include <glib.h>
15 #include "panel.h"
17 /* @IncludeInKinds */
18 /* @Namespace=System.Windows */
19 struct GridLength {
20 public:
21 double val;
22 GridUnitType type;
24 GridLength () {
25 val = 0;
26 type = GridUnitTypeAuto;
29 GridLength (double v, GridUnitType t)
31 val = v;
32 type = t;
36 /* @Namespace=System.Windows.Controls */
37 class ColumnDefinition : public DependencyObject {
38 protected:
39 virtual ~ColumnDefinition ();
41 public:
42 /* @PropertyType=double,DefaultValue=INFINITY,GenerateAccessors */
43 const static int MaxWidthProperty;
44 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
45 const static int MinWidthProperty;
46 /* @PropertyType=GridLength,DefaultValue=GridLength (1.0\, GridUnitTypeStar),GenerateAccessors */
47 const static int WidthProperty;
48 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors,ManagedSetterAccess=Private,ManagedFieldAccess=Private */
49 const static int ActualWidthProperty;
51 /* @GenerateCBinding,GeneratePInvoke */
52 ColumnDefinition ();
54 // property accessors
55 double GetActualWidth ();
56 void SetActualWidth (double value);
58 double GetMaxWidth();
59 void SetMaxWidth (double value);
61 double GetMinWidth();
62 void SetMinWidth (double value);
64 GridLength* GetWidth();
65 void SetWidth (GridLength *value);
68 /* @Namespace=System.Windows.Controls */
69 class RowDefinition : public DependencyObject {
70 protected:
71 virtual ~RowDefinition ();
73 public:
74 /* @PropertyType=GridLength,DefaultValue=GridLength (1.0\, GridUnitTypeStar),GenerateAccessors */
75 const static int HeightProperty;
76 /* @PropertyType=double,DefaultValue=INFINITY,GenerateAccessors */
77 const static int MaxHeightProperty;
78 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
79 const static int MinHeightProperty;
80 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors,ManagedSetterAccess=Private,ManagedFieldAccess=Private */
81 const static int ActualHeightProperty;
83 /* @GenerateCBinding,GeneratePInvoke */
84 RowDefinition ();
86 // property accessors
87 double GetActualHeight ();
88 void SetActualHeight (double value);
90 double GetMaxHeight();
91 void SetMaxHeight (double value);
93 double GetMinHeight();
94 void SetMinHeight (double value);
96 GridLength* GetHeight();
97 void SetHeight (GridLength *value);
100 /* @Namespace=System.Windows.Controls */
101 class ColumnDefinitionCollection : public DependencyObjectCollection {
102 protected:
103 virtual ~ColumnDefinitionCollection ();
105 virtual bool AddedToCollection (Value *value, MoonError *error);
107 public:
108 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
109 ColumnDefinitionCollection ();
111 virtual Type::Kind GetElementType () { return Type::COLUMNDEFINITION; }
115 /* @Namespace=System.Windows.Controls */
116 class RowDefinitionCollection : public DependencyObjectCollection {
117 protected:
118 virtual ~RowDefinitionCollection ();
120 virtual bool AddedToCollection (Value *value, MoonError *error);
122 public:
123 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
124 RowDefinitionCollection ();
126 virtual Type::Kind GetElementType () { return Type::ROWDEFINITION; }
129 struct Segment {
130 double max;
131 double min;
132 double size;
133 double stars;
134 GridUnitType type;
136 Segment ();
137 Segment (double size, double min, double max, GridUnitType type);
139 private:
140 void Init (double size, double min, double max, GridUnitType type);
143 /* @Namespace=System.Windows.Controls */
144 class Grid : public Panel {
145 int row_matrix_dim;
146 int col_matrix_dim;
147 Segment **row_matrix;
148 Segment **col_matrix;
150 void AllocateGridSegments (int row_count, int col_count);
151 void AssignSize (Segment **matrix, int start, int end, double *size, GridUnitType type);
152 void CreateMatrices (int row_count, int col_count);
153 void DestroyMatrices ();
154 void TryExpandStarRows (Size availableSize, bool force_width_nan, bool force_height_nan);
155 void TryExpandStarCols (Size availableSize, bool force_width_nan, bool force_height_nan);
157 protected:
158 virtual ~Grid ();
159 virtual void PostRender (cairo_t *cr, Region *region, bool front_to_back);
161 public:
162 /* @PropertyType=gint32,DefaultValue=0,Attached,GenerateAccessors,Validator=PositiveIntValidator */
163 const static int ColumnProperty;
164 /* @PropertyType=ColumnDefinitionCollection,AutoCreateValue,ManagedFieldAccess=Internal,ManagedSetterAccess=Internal,GenerateAccessors */
165 const static int ColumnDefinitionsProperty;
166 /* @PropertyType=gint32,DefaultValue=1,Attached,GenerateAccessors,Validator=IntGreaterThanZeroValidator */
167 const static int ColumnSpanProperty;
168 /* @PropertyType=gint32,DefaultValue=0,Attached,GenerateAccessors,Validator=PositiveIntValidator */
169 const static int RowProperty;
170 /* @PropertyType=RowDefinitionCollection,AutoCreateValue,ManagedFieldAccess=Internal,ManagedSetterAccess=Internal,GenerateAccessors */
171 const static int RowDefinitionsProperty;
172 /* @PropertyType=gint32,DefaultValue=1,Attached,GenerateAccessors,Validator=IntGreaterThanZeroValidator */
173 const static int RowSpanProperty;
176 * NOTE: The ShowGridLines property defaults to false but appears
177 * to be uninitialized before InitializeComponents is called
178 * causing the current moon-unit test to fail.
180 /* @PropertyType=bool,DefaultValue=false,GenerateAccessors */
181 const static int ShowGridLinesProperty;
183 /* @GenerateCBinding,GeneratePInvoke */
184 Grid ();
186 virtual void OnPropertyChanged (PropertyChangedEventArgs *args, MoonError *error);
187 virtual void OnCollectionChanged (Collection *col, CollectionChangedEventArgs *args);
188 virtual void OnCollectionItemChanged (Collection *col, DependencyObject *obj, PropertyChangedEventArgs *args);
189 virtual void ComputeBounds ();
191 virtual Size MeasureOverride (Size availableSize);
192 virtual Size ArrangeOverride (Size finalSize);
194 // property accessors
195 ColumnDefinitionCollection *GetColumnDefinitions ();
196 void SetColumnDefinitions (ColumnDefinitionCollection* value);
198 static gint32 GetColumn (DependencyObject *obj);
199 static void SetColumn (DependencyObject *obj, gint32 value);
201 static gint32 GetColumnSpan (DependencyObject *obj);
202 static void SetColumnSpan (DependencyObject *obj, gint32 value);
204 RowDefinitionCollection *GetRowDefinitions ();
205 void SetRowDefinitions (RowDefinitionCollection* value);
207 static gint32 GetRow (DependencyObject *obj);
208 static void SetRow (DependencyObject *obj, gint32 value);
210 static gint32 GetRowSpan (DependencyObject *obj);
211 static void SetRowSpan (DependencyObject *obj, gint32 value);
213 bool GetShowGridLines ();
214 void SetShowGridLines (bool value);
216 static double Clamp (double val, double min, double max);
219 // We need this class to figure out what kinds of elements the grid
220 // contains before the grid starts measuring them.
221 class GridWalker {
222 public:
223 bool HasAutoAuto () { return has_auto_auto; }
224 bool HasStarAuto () { return has_star_auto; }
225 bool HasAutoStar () { return has_auto_star; }
226 GridWalker (Grid *grid, Segment **row_matrix, int row_count, Segment **col_matrix, int col_count);
228 private:
229 bool has_auto_auto;
230 bool has_star_auto;
231 bool has_auto_star;
234 class GridNode : public List::Node {
235 public:
236 int row;
237 int col;
238 double size;
239 Segment ** matrix;
241 GridNode (Segment **matrix, int row, int col, double size) {
242 this->matrix = matrix;
243 this->row = row;
244 this->col = col;
245 this->size = size;
248 #endif /* __MOON_PANEL_H__ */