libyui  3.2.5
YLayoutBox.h
1 /*
2  Copyright (C) 2000-2012 Novell, Inc
3  This library is free software; you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as
5  published by the Free Software Foundation; either version 2.1 of the
6  License, or (at your option) version 3.0 of the License. This library
7  is distributed in the hope that it will be useful, but WITHOUT ANY
8  WARRANTY; without even the implied warranty of MERCHANTABILITY or
9  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
10  License for more details. You should have received a copy of the GNU
11  Lesser General Public License along with this library; if not, write
12  to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
13  Floor, Boston, MA 02110-1301 USA
14 */
15 
16 
17 /*-/
18 
19  File: YLayoutBox.h
20 
21  Author: Stefan Hundhammer <sh@suse.de>
22 
23 /-*/
24 
25 #ifndef YLayoutBox_h
26 #define YLayoutBox_h
27 
28 #include <vector>
29 #include "YWidget.h"
30 
31 
32 class YLayoutBoxPrivate;
33 
34 /**
35  * A vertical or horizontal stacking of widgets, implementing HBox and VBox.
36  **/
37 class YLayoutBox : public YWidget
38 {
39 public:
40  typedef std::vector<int> sizeVector;
41  typedef std::vector<int> posVector;
42 
43 protected:
44  /**
45  * Constructor.
46  *
47  * Creates a VBox for dim == YD_VERT or a HBox for YD_HORIZ.
48  **/
49  YLayoutBox( YWidget * parent, YUIDimension dim );
50 
51 public:
52  /**
53  * Destructor.
54  **/
55  virtual ~YLayoutBox();
56 
57  /**
58  * Returns a descriptive name of this widget class for logging,
59  * debugging etc.
60  **/
61  virtual const char * widgetClass() const;
62 
63  /**
64  * Return the primary dimension, i.e., the dimension this LayoutBox lays
65  * out its children in: YD_VERT for a VBox, YD_HORIZ for a HBox.
66  **/
67  YUIDimension primary() const;
68 
69  /**
70  * Return the secondary dimension.
71  **/
72  YUIDimension secondary() const;
73 
74  /**
75  * Returns 'true' if layout debugging (verbose logging during layout) is on.
76  **/
77  bool debugLayout() const;
78 
79  /**
80  * Enable or disable layout debugging.
81  **/
82  void setDebugLayout( bool deb = true );
83 
84  /**
85  * Preferred size of the widget in the specified dimension.
86  *
87  * Reimplemented from YWidget.
88  **/
89  virtual int preferredSize( YUIDimension dim );
90 
91  /**
92  * Preferred width of the widget.
93  *
94  * Reimplemented from YWidget.
95  **/
96  virtual int preferredWidth();
97 
98  /**
99  * Preferred height of the widget.
100  *
101  * Reimplemented from YWidget.
102  **/
103  virtual int preferredHeight();
104 
105  /**
106  * Sets the size of the layout box. This is where the layout policy
107  * is implemented.
108  *
109  * Derived classes can reimplement this, but this base class method should
110  * be called in the reimplemented function.
111  *
112  * Reimplemented from YWidget.
113  **/
114  virtual void setSize( int newWidth, int newHeight );
115 
116  /**
117  * Returns the stretchability of the layout box:
118  * The layout box is stretchable if one of the children is stretchable in
119  * this dimension or if one of the child widgets has a layout weight in
120  * this dimension.
121  *
122  * Reimplemented from YWidget.
123  **/
124  virtual bool stretchable( YUIDimension dimension ) const;
125 
126  /**
127  * Move a child to a new position.
128  *
129  * Derived classes are required to implement this.
130  **/
131  virtual void moveChild( YWidget * child, int newX, int newY ) = 0;
132 
133  /**
134  * Check if this is a layout stretch widget in the specfied dimension,
135  * i.e. an empty widget that is stretchable.
136  **/
137  static bool isLayoutStretch( YWidget * child, YUIDimension dimension );
138 
139 
140 protected:
141 
142  /**
143  * Add up all the children's weights.
144  **/
145  int childrenTotalWeight( YUIDimension dimension );
146 
147  /**
148  * Return the maximum preferred size of all children in the specified
149  * dimension.
150  **/
151  int childrenMaxPreferredSize( YUIDimension dimension );
152 
153  /**
154  * Add up all the non-weighted children's preferred sizes in the specified
155  * dimension.
156  **/
157  int totalNonWeightedChildrenPreferredSize( YUIDimension dimension );
158 
159  /**
160  * Count the number of non-weighted children.
161  **/
162  int countNonWeightedChildren( YUIDimension dimension );
163 
164  /**
165  * Count the number of stretchable ( non-weighted ) children.
166  * Note: Weighted children are _always_ considered stretchable.
167  **/
168  int countStretchableChildren( YUIDimension dimension );
169 
170  /**
171  * Count the number of "rubber bands", i.e. the number of
172  * stretchable layout spacings ( e.g. {H|V}Weight,
173  * {H|V}Spacing ). Only those without a weight are counted.
174  **/
175  int countLayoutStretchChildren( YUIDimension dimension );
176 
177  /**
178  * Determine the number of the "dominating child" - the child widget that
179  * determines the overall size with respect to its weight.
180  *
181  * Return 0 if there is no dominating child, i.e. none of the children has
182  * a weight specified.
183  **/
185 
186  /**
187  * Calculate the sizes and positions of all children in the primary
188  * dimension and store them in "childSize" and "childPos".
189  **/
190  void calcPrimaryGeometry ( int newSize,
191  sizeVector & childSize,
192  posVector & childPos );
193 
194  /**
195  * Calculate the sizes and positions of all children in the secondary
196  * dimension and store them in "childSize" and "childPos".
197  **/
198  void calcSecondaryGeometry ( int newSize,
199  sizeVector & childSize,
200  posVector & childPos );
201 
202  /**
203  * Actually perform resizing and moving the child widgets to the
204  * appropriate position.
205  *
206  * The vectors passed are the sizes previously calculated by
207  * calcPrimaryGeometry() and calcSecondaryGeometry().
208  **/
209  void doResize( sizeVector & width,
210  sizeVector & height,
211  posVector & x_pos,
212  posVector & y_pos );
213 
214 
215 private:
216 
218 };
219 
220 
221 typedef YLayoutBox YVBox;
222 typedef YLayoutBox YHBox;
223 
224 
225 #endif // YLayoutBox_h
bool debugLayout() const
Returns &#39;true&#39; if layout debugging (verbose logging during layout) is on.
Definition: YLayoutBox.cc:96
int childrenTotalWeight(YUIDimension dimension)
Add up all the children&#39;s weights.
Definition: YLayoutBox.cc:247
virtual void moveChild(YWidget *child, int newX, int newY)=0
Move a child to a new position.
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
static bool isLayoutStretch(YWidget *child, YUIDimension dimension)
Check if this is a layout stretch widget in the specfied dimension, i.e.
Definition: YLayoutBox.cc:333
A vertical or horizontal stacking of widgets, implementing HBox and VBox.
Definition: YLayoutBox.h:37
virtual int preferredWidth()
Preferred width of the widget.
Definition: YLayoutBox.cc:159
void calcPrimaryGeometry(int newSize, sizeVector &childSize, posVector &childPos)
Calculate the sizes and positions of all children in the primary dimension and store them in "childSi...
Definition: YLayoutBox.cc:398
void calcSecondaryGeometry(int newSize, sizeVector &childSize, posVector &childPos)
Calculate the sizes and positions of all children in the secondary dimension and store them in "child...
Definition: YLayoutBox.cc:694
void setDebugLayout(bool deb=true)
Enable or disable layout debugging.
Definition: YLayoutBox.cc:102
virtual void setSize(int newWidth, int newHeight)
Sets the size of the layout box.
Definition: YLayoutBox.cc:365
void doResize(sizeVector &width, sizeVector &height, posVector &x_pos, posVector &y_pos)
Actually perform resizing and moving the child widgets to the appropriate position.
Definition: YLayoutBox.cc:746
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YLayoutBox.cc:775
YUIDimension secondary() const
Return the secondary dimension.
Definition: YLayoutBox.cc:89
int countNonWeightedChildren(YUIDimension dimension)
Count the number of non-weighted children.
Definition: YLayoutBox.cc:280
int totalNonWeightedChildrenPreferredSize(YUIDimension dimension)
Add up all the non-weighted children&#39;s preferred sizes in the specified dimension.
Definition: YLayoutBox.cc:263
virtual int preferredSize(YUIDimension dim)
Preferred size of the widget in the specified dimension.
Definition: YLayoutBox.cc:111
virtual int preferredHeight()
Preferred height of the widget.
Definition: YLayoutBox.cc:165
YLayoutBox(YWidget *parent, YUIDimension dim)
Constructor.
Definition: YLayoutBox.cc:66
virtual bool stretchable(YUIDimension dimension) const
Returns the stretchability of the layout box: The layout box is stretchable if one of the children is...
Definition: YLayoutBox.cc:349
int countStretchableChildren(YUIDimension dimension)
Count the number of stretchable ( non-weighted ) children.
Definition: YLayoutBox.cc:297
YUIDimension primary() const
Return the primary dimension, i.e., the dimension this LayoutBox lays out its children in: YD_VERT fo...
Definition: YLayoutBox.cc:82
YWidget * findDominatingChild()
Determine the number of the "dominating child" - the child widget that determines the overall size wi...
Definition: YLayoutBox.cc:185
Abstract base class of all UI widgets.
Definition: YWidget.h:54
int childrenMaxPreferredSize(YUIDimension dimension)
Return the maximum preferred size of all children in the specified dimension.
Definition: YLayoutBox.cc:231
int countLayoutStretchChildren(YUIDimension dimension)
Count the number of "rubber bands", i.e.
Definition: YLayoutBox.cc:315
virtual ~YLayoutBox()
Destructor.
Definition: YLayoutBox.cc:75