00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __GRIDBAGLAYOUT_G__
00021 #define __GRIDBAGLAYOUT_G__
00022
00023 #include "cslayout.h"
00024
00146 class csGridBagConstraint : public csLayoutConstraint
00147 {
00148 public:
00149 csGridBagConstraint (csComponent *comp);
00150 csGridBagConstraint (const csGridBagConstraint &c);
00151 csGridBagConstraint (csComponent *comp, int _gridx, int _gridy,
00152 int _gridwidth, int _gridheight, float _weightx,
00153 float _weighty, int _anchor, int _fill,
00154 csRect _insets, int _ipadx, int _ipady);
00155 csLayoutConstraint *Clone ();
00156 public:
00162 int gridx;
00169 int gridy;
00174 int gridwidth;
00179 int gridheight;
00186 float weightx;
00193 float weighty;
00208 int anchor;
00215 int fill;
00219 csRect insets;
00224 int ipadx;
00229 int ipady;
00230
00231 #undef RELATIVE
00232 #undef _LEFT
00233 #undef _CENTER
00234
00235 enum GRID_BAG_CONSTANTS
00236 {
00237 RELATIVE = -1,
00238 REMAINDER = 0,
00239
00240 NONE = 0,
00241 BOTH = 1,
00242 HORIZONTAL = 2,
00243 VERTICAL = 3,
00244
00245 CENTER = 10,
00246 NORTH = 11,
00247 NORTHEAST = 12,
00248 EAST = 13,
00249 SOUTHEAST = 14,
00250 SOUTH = 15,
00251 SOUTHWEST = 16,
00252 WEST = 17,
00253 NORTHWEST = 18
00254 };
00255
00256
00257
00258 enum GRID_BAG_CONSTANTS_INTERNAL
00259 {
00260 _LEFT = 20,
00261 _CENTER = 21,
00262 _RIGHT = 22
00263 };
00264
00265
00266 bool bSized;
00267 csPoint mPrefCompSize;
00268 };
00269
00270 class csGridBagLayout : public csLayout2
00271 {
00272 struct CellInfo
00273 {
00274 csComponent* comp;
00275
00276 int prefSize;
00277 int prefCompSize;
00278
00279 int cellSpan;
00280 int leftInset;
00281 int rightInset;
00282 int pad;
00283 int fill;
00284 int anchor;
00285
00286 float extraSpace;
00287 float weight;
00288
00289 int finalSize;
00290 int finalPos;
00291 int finalCompSize;
00292 int finalCompPos;
00293 };
00294
00295 struct CellHolder
00296 {
00297 csGridBagConstraint* constr;
00298 float weightx;
00299 float weighty;
00300
00301 int gridwidth;
00302 int gridheight;
00303 int actualWidth;
00304 int actualHeight;
00305
00306 bool isFirstCellForComp;
00307 int x, y;
00308 };
00309
00310 CS_DECLARE_TYPED_VECTOR(CellHolderArrayT, CellHolder);
00311
00312 public:
00313 csGridBagLayout (csComponent *pParent);
00314 ~csGridBagLayout ();
00315
00316 virtual void RemoveLayoutComponent (csComponent* comp);
00317 virtual void SuggestSize (int &sugw, int &sugh);
00318 virtual void LayoutContainer ();
00319
00320 virtual void MaximumLayoutSize (int &w, int &h);
00321 virtual float GetLayoutAlignmentX ();
00322 virtual float GetLayoutAlignmentY ();
00323
00324 csGridBagConstraint c;
00325
00326 protected:
00327 int CalcPrefSize (CellInfo* cells, int xCnt, int yCnt, int _arrayWidth);
00328 void LayoutCells (CellInfo* cells, int xCnt, int yCnt,
00329 int outterSize, int outterPos, int _arrayWidth );
00330
00331 void InitializeCellArray (CellInfo* cells, int size);
00332 void InitCellFromHolder (CellHolder& holder);
00333 void CreateMatrix ();
00334 long GetCellCode (int x, int y);
00335 void CleanupConstraints ();
00336 void ClearCachedData ();
00337 bool HasCashedInfo ();
00338 void SetComponentLocations ();
00339
00340 protected:
00341 CellInfo* mpHorizCellInfos;
00342 CellInfo* mpVertCellInfos;
00343 int mColCount;
00344 int mRowCount;
00345 };
00346
00347 #endif // __GRIDBAGLAYOUT_G__