libyui  3.1.5
 All Classes Files Functions Variables Typedefs Enumerations Friends Pages
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 class YLayoutBox : public YWidget
36 {
37 public:
38  typedef std::vector<int> sizeVector;
39  typedef std::vector<int> posVector;
40 
41 protected:
42  /**
43  * Constructor.
44  *
45  * Creates a VBox for dim == YD_VERT or a HBox for YD_HORIZ.
46  **/
47  YLayoutBox( YWidget * parent, YUIDimension dim );
48 
49 public:
50  /**
51  * Destructor.
52  **/
53  virtual ~YLayoutBox();
54 
55  /**
56  * Returns a descriptive name of this widget class for logging,
57  * debugging etc.
58  **/
59  virtual const char * widgetClass() const;
60 
61  /**
62  * Return the primary dimension, i.e., the dimension this LayoutBox lays
63  * out its children in: YD_VERT for a VBox, YD_HORIZ for a HBox.
64  **/
65  YUIDimension primary() const;
66 
67  /**
68  * Return the secondary dimension.
69  **/
70  YUIDimension secondary() const;
71 
72  /**
73  * Returns 'true' if layout debugging (verbose logging during layout) is on.
74  **/
75  bool debugLayout() const;
76 
77  /**
78  * Enable or disable layout debugging.
79  **/
80  void setDebugLayout( bool deb = true );
81 
82  /**
83  * Preferred size of the widget in the specified dimension.
84  *
85  * Reimplemented from YWidget.
86  **/
87  virtual int preferredSize( YUIDimension dim );
88 
89  /**
90  * Preferred width of the widget.
91  *
92  * Reimplemented from YWidget.
93  **/
94  virtual int preferredWidth();
95 
96  /**
97  * Preferred height of the widget.
98  *
99  * Reimplemented from YWidget.
100  **/
101  virtual int preferredHeight();
102 
103  /**
104  * Sets the size of the layout box. This is where the layout policy
105  * is implemented.
106  *
107  * Derived classes can reimplement this, but this base class method should
108  * be called in the reimplemented function.
109  *
110  * Reimplemented from YWidget.
111  **/
112  virtual void setSize( int newWidth, int newHeight );
113 
114  /**
115  * Returns the stretchability of the layout box:
116  * The layout box is stretchable if one of the children is stretchable in
117  * this dimension or if one of the child widgets has a layout weight in
118  * this dimension.
119  *
120  * Reimplemented from YWidget.
121  **/
122  virtual bool stretchable( YUIDimension dimension ) const;
123 
124  /**
125  * Move a child to a new position.
126  *
127  * Derived classes are required to implement this.
128  **/
129  virtual void moveChild( YWidget * child, int newX, int newY ) = 0;
130 
131  /**
132  * Check if this is a layout stretch widget in the specfied dimension,
133  * i.e. an empty widget that is stretchable.
134  **/
135  static bool isLayoutStretch( YWidget * child, YUIDimension dimension );
136 
137 
138 protected:
139 
140  /**
141  * Add up all the children's weights.
142  **/
143  int childrenTotalWeight( YUIDimension dimension );
144 
145  /**
146  * Return the maximum preferred size of all children in the specified
147  * dimension.
148  **/
149  int childrenMaxPreferredSize( YUIDimension dimension );
150 
151  /**
152  * Add up all the non-weighted children's preferred sizes in the specified
153  * dimension.
154  **/
155  int totalNonWeightedChildrenPreferredSize( YUIDimension dimension );
156 
157  /**
158  * Count the number of non-weighted children.
159  **/
160  int countNonWeightedChildren( YUIDimension dimension );
161 
162  /**
163  * Count the number of stretchable ( non-weighted ) children.
164  * Note: Weighted children are _always_ considered stretchable.
165  **/
166  int countStretchableChildren( YUIDimension dimension );
167 
168  /**
169  * Count the number of "rubber bands", i.e. the number of
170  * stretchable layout spacings ( e.g. {H|V}Weight,
171  * {H|V}Spacing ). Only those without a weight are counted.
172  **/
173  int countLayoutStretchChildren( YUIDimension dimension );
174 
175  /**
176  * Determine the number of the "dominating child" - the child widget that
177  * determines the overall size with respect to its weight.
178  *
179  * Return 0 if there is no dominating child, i.e. none of the children has
180  * a weight specified.
181  **/
183 
184  /**
185  * Calculate the sizes and positions of all children in the primary
186  * dimension and store them in "childSize" and "childPos".
187  **/
188  void calcPrimaryGeometry ( int newSize,
189  sizeVector & childSize,
190  posVector & childPos );
191 
192  /**
193  * Calculate the sizes and positions of all children in the secondary
194  * dimension and store them in "childSize" and "childPos".
195  **/
196  void calcSecondaryGeometry ( int newSize,
197  sizeVector & childSize,
198  posVector & childPos );
199 
200  /**
201  * Actually perform resizing and moving the child widgets to the
202  * appropriate position.
203  *
204  * The vectors passed are the sizes previously calculated by
205  * calcPrimaryGeometry() and calcSecondaryGeometry().
206  **/
207  void doResize( sizeVector & width,
208  sizeVector & height,
209  posVector & x_pos,
210  posVector & y_pos );
211 
212 
213 private:
214 
216 };
217 
218 
219 typedef YLayoutBox YVBox;
220 typedef YLayoutBox YHBox;
221 
222 
223 #endif // YLayoutBox_h
bool debugLayout() const
Returns 'true' if layout debugging (verbose logging during layout) is on.
Definition: YLayoutBox.cc:96
int childrenTotalWeight(YUIDimension dimension)
Add up all the children'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's parent or 0 if it doesn'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
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'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