libyui  3.4.2
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 protected:
140 
141  /**
142  * Add up all the children's weights.
143  **/
144  int childrenTotalWeight( YUIDimension dimension );
145 
146  /**
147  * Return the maximum preferred size of all children in the specified
148  * dimension.
149  **/
150  int childrenMaxPreferredSize( YUIDimension dimension );
151 
152  /**
153  * Add up all the non-weighted children's preferred sizes in the specified
154  * dimension.
155  **/
156  int totalNonWeightedChildrenPreferredSize( YUIDimension dimension );
157 
158  /**
159  * Count the number of non-weighted children.
160  **/
161  int countNonWeightedChildren( YUIDimension dimension );
162 
163  /**
164  * Count the number of stretchable ( non-weighted ) children.
165  * Note: Weighted children are _always_ considered stretchable.
166  **/
167  int countStretchableChildren( YUIDimension dimension );
168 
169  /**
170  * Count the number of "rubber bands", i.e. the number of
171  * stretchable layout spacings ( e.g. {H|V}Weight,
172  * {H|V}Spacing ). Only those without a weight are counted.
173  **/
174  int countLayoutStretchChildren( YUIDimension dimension );
175 
176  /**
177  * Determine the number of the "dominating child" - the child widget that
178  * determines the overall size with respect to its weight.
179  *
180  * Return 0 if there is no dominating child, i.e. none of the children has
181  * a weight specified.
182  **/
184 
185  /**
186  * Calculate the sizes and positions of all children in the primary
187  * dimension and store them in "childSize" and "childPos".
188  **/
189  void calcPrimaryGeometry ( int newSize,
190  sizeVector & childSize,
191  posVector & childPos );
192 
193  /**
194  * Calculate the sizes and positions of all children in the secondary
195  * dimension and store them in "childSize" and "childPos".
196  **/
197  void calcSecondaryGeometry ( int newSize,
198  sizeVector & childSize,
199  posVector & childPos );
200 
201  /**
202  * Actually perform resizing and moving the child widgets to the
203  * appropriate position.
204  *
205  * The vectors passed are the sizes previously calculated by
206  * calcPrimaryGeometry() and calcSecondaryGeometry().
207  **/
208  void doResize( sizeVector & width,
209  sizeVector & height,
210  posVector & x_pos,
211  posVector & y_pos );
212 
213 
214 private:
215 
217 };
218 
219 
220 typedef YLayoutBox YVBox;
221 typedef YLayoutBox YHBox;
222 
223 
224 #endif // YLayoutBox_h
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.
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
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
bool debugLayout() const
Returns &#39;true&#39; if layout debugging (verbose logging during layout) is on.
Definition: YLayoutBox.cc:96
virtual int preferredWidth()
Preferred width of the widget.
Definition: YLayoutBox.cc:159
YUIDimension secondary() const
Return the secondary dimension.
Definition: YLayoutBox.cc:89
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
YWidget * parent() const
Return this widget&#39;s parent or 0 if it doesn&#39;t have a parent.
Definition: YWidget.cc:269
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
int countStretchableChildren(YUIDimension dimension)
Count the number of stretchable ( non-weighted ) children.
Definition: YLayoutBox.cc:297
YWidget * findDominatingChild()
Determine the number of the "dominating child" - the child widget that determines the overall size wi...
Definition: YLayoutBox.cc:185
virtual const char * widgetClass() const
Returns a descriptive name of this widget class for logging, debugging etc.
Definition: YLayoutBox.cc:775
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
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
virtual ~YLayoutBox()
Destructor.
Definition: YLayoutBox.cc:75