libyui
3.0.10
|
00001 /* 00002 Copyright (C) 2000-2012 Novell, Inc 00003 This library is free software; you can redistribute it and/or modify 00004 it under the terms of the GNU Lesser General Public License as 00005 published by the Free Software Foundation; either version 2.1 of the 00006 License, or (at your option) version 3.0 of the License. This library 00007 is distributed in the hope that it will be useful, but WITHOUT ANY 00008 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00009 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 00010 License for more details. You should have received a copy of the GNU 00011 Lesser General Public License along with this library; if not, write 00012 to the Free Software Foundation, Inc., 51 Franklin Street, Fifth 00013 Floor, Boston, MA 02110-1301 USA 00014 */ 00015 00016 00017 /*-/ 00018 00019 File: YLayoutBox.h 00020 00021 Author: Stefan Hundhammer <sh@suse.de> 00022 00023 /-*/ 00024 00025 #ifndef YLayoutBox_h 00026 #define YLayoutBox_h 00027 00028 #include <vector> 00029 #include "YWidget.h" 00030 00031 00032 class YLayoutBoxPrivate; 00033 00034 00035 class YLayoutBox : public YWidget 00036 { 00037 public: 00038 typedef std::vector<int> sizeVector; 00039 typedef std::vector<int> posVector; 00040 00041 protected: 00042 /** 00043 * Constructor. 00044 * 00045 * Creates a VBox for dim == YD_VERT or a HBox for YD_HORIZ. 00046 **/ 00047 YLayoutBox( YWidget * parent, YUIDimension dim ); 00048 00049 public: 00050 /** 00051 * Destructor. 00052 **/ 00053 virtual ~YLayoutBox(); 00054 00055 /** 00056 * Returns a descriptive name of this widget class for logging, 00057 * debugging etc. 00058 **/ 00059 virtual const char * widgetClass() const; 00060 00061 /** 00062 * Return the primary dimension, i.e., the dimension this LayoutBox lays 00063 * out its children in: YD_VERT for a VBox, YD_HORIZ for a HBox. 00064 **/ 00065 YUIDimension primary() const; 00066 00067 /** 00068 * Return the secondary dimension. 00069 **/ 00070 YUIDimension secondary() const; 00071 00072 /** 00073 * Returns 'true' if layout debugging (verbose logging during layout) is on. 00074 **/ 00075 bool debugLayout() const; 00076 00077 /** 00078 * Enable or disable layout debugging. 00079 **/ 00080 void setDebugLayout( bool deb = true ); 00081 00082 /** 00083 * Preferred size of the widget in the specified dimension. 00084 * 00085 * Reimplemented from YWidget. 00086 **/ 00087 virtual int preferredSize( YUIDimension dim ); 00088 00089 /** 00090 * Preferred width of the widget. 00091 * 00092 * Reimplemented from YWidget. 00093 **/ 00094 virtual int preferredWidth(); 00095 00096 /** 00097 * Preferred height of the widget. 00098 * 00099 * Reimplemented from YWidget. 00100 **/ 00101 virtual int preferredHeight(); 00102 00103 /** 00104 * Sets the size of the layout box. This is where the layout policy 00105 * is implemented. 00106 * 00107 * Derived classes can reimplement this, but this base class method should 00108 * be called in the reimplemented function. 00109 * 00110 * Reimplemented from YWidget. 00111 **/ 00112 virtual void setSize( int newWidth, int newHeight ); 00113 00114 /** 00115 * Returns the stretchability of the layout box: 00116 * The layout box is stretchable if one of the children is stretchable in 00117 * this dimension or if one of the child widgets has a layout weight in 00118 * this dimension. 00119 * 00120 * Reimplemented from YWidget. 00121 **/ 00122 virtual bool stretchable( YUIDimension dimension ) const; 00123 00124 /** 00125 * Move a child to a new position. 00126 * 00127 * Derived classes are required to implement this. 00128 **/ 00129 virtual void moveChild( YWidget * child, int newX, int newY ) = 0; 00130 00131 /** 00132 * Check if this is a layout stretch widget in the specfied dimension, 00133 * i.e. an empty widget that is stretchable. 00134 **/ 00135 static bool isLayoutStretch( YWidget * child, YUIDimension dimension ); 00136 00137 00138 protected: 00139 00140 /** 00141 * Add up all the children's weights. 00142 **/ 00143 int childrenTotalWeight( YUIDimension dimension ); 00144 00145 /** 00146 * Return the maximum preferred size of all children in the specified 00147 * dimension. 00148 **/ 00149 int childrenMaxPreferredSize( YUIDimension dimension ); 00150 00151 /** 00152 * Add up all the non-weighted children's preferred sizes in the specified 00153 * dimension. 00154 **/ 00155 int totalNonWeightedChildrenPreferredSize( YUIDimension dimension ); 00156 00157 /** 00158 * Count the number of non-weighted children. 00159 **/ 00160 int countNonWeightedChildren( YUIDimension dimension ); 00161 00162 /** 00163 * Count the number of stretchable ( non-weighted ) children. 00164 * Note: Weighted children are _always_ considered stretchable. 00165 **/ 00166 int countStretchableChildren( YUIDimension dimension ); 00167 00168 /** 00169 * Count the number of "rubber bands", i.e. the number of 00170 * stretchable layout spacings ( e.g. {H|V}Weight, 00171 * {H|V}Spacing ). Only those without a weight are counted. 00172 **/ 00173 int countLayoutStretchChildren( YUIDimension dimension ); 00174 00175 /** 00176 * Determine the number of the "dominating child" - the child widget that 00177 * determines the overall size with respect to its weight. 00178 * 00179 * Return 0 if there is no dominating child, i.e. none of the children has 00180 * a weight specified. 00181 **/ 00182 YWidget * findDominatingChild(); 00183 00184 /** 00185 * Calculate the sizes and positions of all children in the primary 00186 * dimension and store them in "childSize" and "childPos". 00187 **/ 00188 void calcPrimaryGeometry ( int newSize, 00189 sizeVector & childSize, 00190 posVector & childPos ); 00191 00192 /** 00193 * Calculate the sizes and positions of all children in the secondary 00194 * dimension and store them in "childSize" and "childPos". 00195 **/ 00196 void calcSecondaryGeometry ( int newSize, 00197 sizeVector & childSize, 00198 posVector & childPos ); 00199 00200 /** 00201 * Actually perform resizing and moving the child widgets to the 00202 * appropriate position. 00203 * 00204 * The vectors passed are the sizes previously calculated by 00205 * calcPrimaryGeometry() and calcSecondaryGeometry(). 00206 **/ 00207 void doResize( sizeVector & width, 00208 sizeVector & height, 00209 posVector & x_pos, 00210 posVector & y_pos ); 00211 00212 00213 private: 00214 00215 ImplPtr<YLayoutBoxPrivate> priv; 00216 }; 00217 00218 00219 typedef YLayoutBox YVBox; 00220 typedef YLayoutBox YHBox; 00221 00222 00223 #endif // YLayoutBox_h