1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
5 * Copyright 2008 Novell, Inc. (http://www.novell.com)
7 * See the LICENSE file included with the distribution for details.
11 #ifndef __MOON_GRID_H__
12 #define __MOON_GRID_H__
18 /* @Namespace=System.Windows */
26 type
= GridUnitTypeAuto
;
29 GridLength (double v
, GridUnitType t
)
35 bool operator == (const GridLength
&v
) const
37 return (fabs (val
- v
.val
) < DBL_EPSILON
&& type
== v
.type
);
40 bool operator != (const GridLength
&point
) const
42 return !(*this == point
);
46 /* @Namespace=System.Windows.Controls */
47 class ColumnDefinition
: public DependencyObject
{
49 virtual ~ColumnDefinition ();
52 /* @PropertyType=double,DefaultValue=INFINITY,GenerateAccessors */
53 const static int MaxWidthProperty
;
54 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
55 const static int MinWidthProperty
;
56 /* @PropertyType=GridLength,DefaultValue=GridLength (1.0\, GridUnitTypeStar),GenerateAccessors */
57 const static int WidthProperty
;
58 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors,ManagedSetterAccess=Private,ManagedFieldAccess=Private */
59 const static int ActualWidthProperty
;
61 /* @GenerateCBinding,GeneratePInvoke */
65 double GetActualWidth ();
66 void SetActualWidth (double value
);
69 void SetMaxWidth (double value
);
72 void SetMinWidth (double value
);
74 GridLength
* GetWidth();
75 void SetWidth (GridLength
*value
);
78 /* @Namespace=System.Windows.Controls */
79 class RowDefinition
: public DependencyObject
{
81 virtual ~RowDefinition ();
84 /* @PropertyType=GridLength,DefaultValue=GridLength (1.0\, GridUnitTypeStar),GenerateAccessors */
85 const static int HeightProperty
;
86 /* @PropertyType=double,DefaultValue=INFINITY,GenerateAccessors */
87 const static int MaxHeightProperty
;
88 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors */
89 const static int MinHeightProperty
;
90 /* @PropertyType=double,DefaultValue=0.0,GenerateAccessors,ManagedSetterAccess=Private,ManagedFieldAccess=Private */
91 const static int ActualHeightProperty
;
93 /* @GenerateCBinding,GeneratePInvoke */
97 double GetActualHeight ();
98 void SetActualHeight (double value
);
100 double GetMaxHeight();
101 void SetMaxHeight (double value
);
103 double GetMinHeight();
104 void SetMinHeight (double value
);
106 GridLength
* GetHeight();
107 void SetHeight (GridLength
*value
);
110 /* @Namespace=System.Windows.Controls */
111 class ColumnDefinitionCollection
: public DependencyObjectCollection
{
113 virtual ~ColumnDefinitionCollection ();
115 virtual bool AddedToCollection (Value
*value
, MoonError
*error
);
118 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
119 ColumnDefinitionCollection ();
121 virtual Type::Kind
GetElementType () { return Type::COLUMNDEFINITION
; }
125 /* @Namespace=System.Windows.Controls */
126 class RowDefinitionCollection
: public DependencyObjectCollection
{
128 virtual ~RowDefinitionCollection ();
130 virtual bool AddedToCollection (Value
*value
, MoonError
*error
);
133 /* @GenerateCBinding,GeneratePInvoke,ManagedAccess=Internal */
134 RowDefinitionCollection ();
136 virtual Type::Kind
GetElementType () { return Type::ROWDEFINITION
; }
140 double original_size
;
148 Segment (double size
, double min
, double max
, GridUnitType type
);
151 void Init (double size
, double min
, double max
, GridUnitType type
);
154 /* @Namespace=System.Windows.Controls */
155 class Grid
: public Panel
{
158 Segment
**row_matrix
;
159 Segment
**col_matrix
;
161 void AllocateGridSegments (int row_count
, int col_count
);
162 void AssignSize (Segment
**matrix
, int start
, int end
, double *size
, GridUnitType type
);
163 void CreateMatrices (int row_count
, int col_count
);
164 void DestroyMatrices ();
165 void ExpandStarRows (Size availableSize
);
166 void ExpandStarCols (Size availableSize
);
168 void SaveMeasureResults ();
169 void RestoreMeasureResults ();
173 virtual void PostRender (cairo_t
*cr
, Region
*region
, bool front_to_back
);
176 /* @PropertyType=gint32,DefaultValue=0,Attached,GenerateAccessors,Validator=PositiveIntValidator */
177 const static int ColumnProperty
;
178 /* @PropertyType=ColumnDefinitionCollection,AutoCreateValue,ManagedFieldAccess=Internal,ManagedSetterAccess=Internal,GenerateAccessors */
179 const static int ColumnDefinitionsProperty
;
180 /* @PropertyType=gint32,DefaultValue=1,Attached,GenerateAccessors,Validator=IntGreaterThanZeroValidator */
181 const static int ColumnSpanProperty
;
182 /* @PropertyType=gint32,DefaultValue=0,Attached,GenerateAccessors,Validator=PositiveIntValidator */
183 const static int RowProperty
;
184 /* @PropertyType=RowDefinitionCollection,AutoCreateValue,ManagedFieldAccess=Internal,ManagedSetterAccess=Internal,GenerateAccessors */
185 const static int RowDefinitionsProperty
;
186 /* @PropertyType=gint32,DefaultValue=1,Attached,GenerateAccessors,Validator=IntGreaterThanZeroValidator */
187 const static int RowSpanProperty
;
190 * NOTE: The ShowGridLines property defaults to false but appears
191 * to be uninitialized before InitializeComponents is called
192 * causing the current moon-unit test to fail.
194 /* @PropertyType=bool,DefaultValue=false,GenerateAccessors */
195 const static int ShowGridLinesProperty
;
197 /* @GenerateCBinding,GeneratePInvoke */
200 virtual void OnPropertyChanged (PropertyChangedEventArgs
*args
, MoonError
*error
);
201 virtual void OnCollectionChanged (Collection
*col
, CollectionChangedEventArgs
*args
);
202 virtual void OnCollectionItemChanged (Collection
*col
, DependencyObject
*obj
, PropertyChangedEventArgs
*args
);
203 virtual void ComputeBounds ();
205 virtual Size
MeasureOverride (Size availableSize
);
206 virtual Size
ArrangeOverride (Size finalSize
);
208 // property accessors
209 ColumnDefinitionCollection
*GetColumnDefinitions ();
210 void SetColumnDefinitions (ColumnDefinitionCollection
* value
);
212 static gint32
GetColumn (DependencyObject
*obj
);
213 static void SetColumn (DependencyObject
*obj
, gint32 value
);
215 static gint32
GetColumnSpan (DependencyObject
*obj
);
216 static void SetColumnSpan (DependencyObject
*obj
, gint32 value
);
218 RowDefinitionCollection
*GetRowDefinitions ();
219 void SetRowDefinitions (RowDefinitionCollection
* value
);
221 static gint32
GetRow (DependencyObject
*obj
);
222 static void SetRow (DependencyObject
*obj
, gint32 value
);
224 static gint32
GetRowSpan (DependencyObject
*obj
);
225 static void SetRowSpan (DependencyObject
*obj
, gint32 value
);
227 bool GetShowGridLines ();
228 void SetShowGridLines (bool value
);
230 static double Clamp (double val
, double min
, double max
);
233 // We need this class to figure out what kinds of elements the grid
234 // contains before the grid starts measuring them.
237 bool HasAutoAuto () { return has_auto_auto
; }
238 bool HasStarAuto () { return has_star_auto
; }
239 bool HasAutoStar () { return has_auto_star
; }
240 GridWalker (Grid
*grid
, Segment
**row_matrix
, int row_count
, Segment
**col_matrix
, int col_count
);
248 class GridNode
: public List::Node
{
255 GridNode (Segment
**matrix
, int row
, int col
, double size
) {
256 this->matrix
= matrix
;
262 #endif /* __MOON_PANEL_H__ */