sizepolicy.h

Go to the documentation of this file.
00001 /*
00002   libwt - Vassilis Virvilis Toolkit - a widget library
00003   Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm>
00004  
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the
00017   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018   Boston, MA  02111-1307, SA.
00019 */
00020 
00021 #ifndef WT_SIZEPOLICY_H
00022 #define WT_SIZEPOLICY_H
00023 
00024 #include <wt/wvar.h>
00025 
00026 namespace Wt {
00027 
00028 class SizePolicy {
00029 protected:
00030     typedef enum {
00031         MayGrow = 1 << 0,
00032         MayShrink = 1 << 1,
00033         ExpMask = 1 << 2
00034     } SizePolicyFlags;
00035 
00036     typedef enum {
00037         Horizontally = 1 << 0,
00038         Vertically = 1 << 1
00039     } ExpandDataFlags;
00040 
00041 public:
00042     /// SizePolicy types
00043     typedef enum {
00044         Fixed = 0,
00045         Minimum = MayGrow,
00046         Maximum = MayShrink,
00047         Preferred = MayGrow | MayShrink,
00048         MinimumExpanding = MayGrow | ExpMask,
00049         Expanding = MayGrow | MayShrink | ExpMask,
00050         Ignored = ExpMask
00051     } SizeType;
00052 
00053     typedef enum {
00054         NoDirection = 0,
00055         Horizontal = Horizontally,
00056         Vertical = Vertically,
00057         BothDirections = Horizontally | Vertically
00058     } ExpandData;
00059 
00060     SizePolicy() :
00061             horizontallData(Preferred),
00062             verticalData(Preferred),
00063             expandData(BothDirections),
00064             heightForWidth(false),
00065             horizontalStretch(0),
00066     verticalStretch(0) {}
00067 
00068     SizePolicy(SizeType hor, SizeType ver, bool hfw = false) :
00069             horizontallData(hor),
00070             verticalData(ver),
00071             expandData(BothDirections),
00072             heightForWidth(hfw),
00073             horizontalStretch(0),
00074     verticalStretch(0) {}
00075 
00076     SizePolicy(SizeType hor, SizeType ver,
00077                unsigned char horStretch, unsigned char verStretch, bool hfw = false) :
00078             horizontallData(hor),
00079             verticalData(ver),
00080             expandData(BothDirections),
00081             heightForWidth(hfw),
00082             horizontalStretch(horStretch),
00083     verticalStretch(verStretch) {}
00084 
00085     bool mayShrinkHorizontally() const {
00086         return (horizontallData & MayShrink) && (expandData & Horizontally);
00087     }
00088     bool mayShrinkVertically() const {
00089         return (verticalData & MayShrink) && (expandData & Vertically);
00090     };
00091     bool mayGrowHorizontally() const {
00092         return (horizontallData & MayGrow) && (expandData & Horizontally);
00093     }
00094     bool mayGrowVertically() const {
00095         return (verticalData & MayGrow) && (expandData & Vertically);
00096     };
00097 
00098     bool expandingHorizontally() const {
00099         return (horizontallData & ExpMask) && (expandData & Horizontally);
00100     }
00101     bool expandingVertically() const {
00102         return (verticalData & ExpMask) && (expandData & Vertically);
00103     };
00104 
00105     bool operator==(const SizePolicy& other) const {
00106         return horizontallData == other.horizontallData &&
00107                verticalData == other.verticalData &&
00108                expandData == other.expandData &&
00109                heightForWidth == other.heightForWidth &&
00110                horizontalStretch == other.horizontalStretch &&
00111                verticalStretch == other.verticalStretch;
00112     }
00113 
00114     WVar<int> horizontallData;
00115     WVar<int> verticalData;
00116     WVar<ExpandData> expandData;
00117     WVar<bool> heightForWidth;
00118     WVar<unsigned char> horizontalStretch;
00119     WVar<unsigned char> verticalStretch;
00120 };
00121 
00122 }
00123 
00124 #endif // WT_SIZEPOLICY_H

Generated Fri Jul 28 19:23:01 2006.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.