Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSLayoutManager.h

Go to the documentation of this file.
00001 #ifndef CSLayouManager_h
00002 #define CSLayouManager_h
00003 
00004 // USES SDL_Surface
00005 
00006 #ifdef WIN32
00007 #pragma warning(disable : 4786 )
00008 #endif
00009 
00010 #include <vector>
00011 #include <string>
00012 //#include <CSGrafikElement.h>
00013 
00014 class CSGrafikElement;
00015 typedef std::vector<CSGrafikElement *> CSGrafikElements;
00016 class CSLayoutManager;
00017 
00018 //typedef std::vector<CSLayoutManager *> CSLayoutManagers;
00019 
00020 /** LayoutData is responsible ONLY for the GraphicElement it is set to.
00021 */
00022 class CSLayoutData
00023 {
00024     private:
00025         int mX;                     // Position in Parent
00026         int mY;                     // Position in Parent
00027         int mPosition;              // Position in Parent
00028         bool mCenteredHorizontal;   // centered in Parent
00029         bool mCenteredVertical;     // centered in Parent
00030         bool mStretchedHorizontal;  // stretched self
00031         bool mStretchedVertical;    // stretched self
00032         bool mPackedHorizontal;     // packed self
00033         bool mPackedVertical;       // packed self      
00034         int mVerticalSpacing;       // spacing of children inside
00035         int mHorizontalSpacing;     // spacing of children inside
00036         bool mSpacingSet;
00037     public:
00038         CSLayoutData()
00039         {
00040             init();
00041         }
00042         CSLayoutData(int x, int y)
00043         {
00044             init();
00045             mX = x;
00046             mY = y;
00047         }
00048 
00049         CSLayoutData(int position, bool stretchAndCentered = false)
00050         {
00051             init();
00052             mPosition = position;
00053             mCenteredHorizontal = stretchAndCentered;
00054             mCenteredVertical = stretchAndCentered;
00055             mStretchedVertical = stretchAndCentered;
00056             mStretchedHorizontal = stretchAndCentered;
00057         }
00058         void init();
00059         bool getStretched()
00060         {
00061             return mStretchedVertical||mStretchedHorizontal;
00062         }
00063         bool getPacked()
00064         {
00065             return mPackedVertical||mPackedHorizontal;
00066         }
00067         void setPackedHorizontal(bool c) {mPackedHorizontal = c; if (c) mStretchedHorizontal = false;}
00068         const bool getPackedHorizontal() {return mPackedHorizontal;}
00069         void setPackedVertical(bool c) {mPackedVertical = c; if (c) mStretchedVertical = false;}
00070         const bool getPackedVertical() {return mPackedVertical;}
00071         void setCenteredHorizontal(bool c) {mCenteredHorizontal = c;}
00072         const bool getCenteredHorizontal() {return mCenteredHorizontal;}
00073         void setCenteredVertical(bool c) {mCenteredVertical = c;}
00074         const bool getCenteredVertical() {return mCenteredVertical;}
00075         const bool getStretchedVertical() {return mStretchedVertical;}
00076         void setStretchedVertical(bool s) {mStretchedVertical = s;if (s) mPackedVertical = false;}
00077         const bool getStretchedHorizontal() {return mStretchedHorizontal;}
00078         void setStretchedHorizontal(bool s) {mStretchedHorizontal = s;if (s) mPackedHorizontal = false;}
00079         void setSpacing(int v, int h) {mVerticalSpacing = v; mHorizontalSpacing = h; mSpacingSet = true;}
00080         const void getSpacing(int &v, int &h) {v = mVerticalSpacing; h = mHorizontalSpacing;}
00081         const int getX() {return mX;}
00082         const int getY() {return mY;}
00083         void setX(int x) {mX = x;}
00084         void setY(int y) {mY = y;}
00085         const int getPosition() {return mPosition;}
00086         void setPosition(int position) {mPosition = position;}
00087         bool getSpacingSet() {return mSpacingSet;}
00088 };
00089 
00090 class CSLayoutManager
00091 {
00092     private:
00093         CSGrafikElement *mHostingElement;
00094 
00095     protected:
00096         bool mPropagateSizeChangesOnly;
00097         CSGrafikElement *getHostingElement() {return mHostingElement;}
00098         CSGrafikElement *getParent(CSGrafikElement *element);
00099         CSGrafikElements *getElements(CSGrafikElement *element);
00100         bool setLayout(CSGrafikElement *visitor, int x, int y, int width ,int height);
00101         CSLayoutData *getLayoutData(CSGrafikElement *visitor);
00102         int getViewportWidth(CSGrafikElement *element);
00103         int getViewportHeight(CSGrafikElement *element);
00104         int getWidth(CSGrafikElement *element);
00105         int getHeight(CSGrafikElement *element);
00106         int getMinWidth(CSGrafikElement *element);
00107         int getMinHeight(CSGrafikElement *element);
00108         int getParentWidth(CSGrafikElement *element);
00109         int getParentHeight(CSGrafikElement *element);
00110         int getBorderWidth(CSGrafikElement *element);
00111         int getBorderHeight(CSGrafikElement *element);
00112         int getInsetWidth(CSGrafikElement *element);
00113         int getInsetHeight(CSGrafikElement *element);
00114         virtual void layoutElements(){}
00115         
00116 
00117     public:
00118         static const char *CLASS;
00119         virtual std::string getType() {return (std::string) CLASS;}
00120         CSLayoutManager() 
00121         {
00122             mHostingElement = 0;
00123             mPropagateSizeChangesOnly = false;
00124         }
00125         virtual ~CSLayoutManager() {}
00126         void setHostingElement(CSGrafikElement *hostingElement) {mHostingElement = hostingElement;}
00127         virtual int getMinimumWidth(CSGrafikElement *element) = 0;  
00128         virtual int getMinimumHeight(CSGrafikElement *element) = 0; 
00129         //! not all LayoutManagers support Packing!
00130         //! Packing changes the size of the element and possibly the size of
00131         //! stretching children
00132         //! it does not change the position of THIS element
00133         //! Packing is done AFTER layout is finished
00134         //! it cannot be called straight, but must be set with setPack(true);
00135         //      virtual void pack() {}  
00136         void pack(CSGrafikElement *element);
00137         void layout(); //!< layout does not change the size of the component! (might change size of children!)
00138         void setPropagateSizeChangesOnly(bool b) {mPropagateSizeChangesOnly = b;}
00139         bool getPropagateSizeChangesOnly() {return mPropagateSizeChangesOnly;}
00140         void buildArea(CSGrafikElement *element);
00141 };
00142 
00143 class CSLayoutManagerXY : public CSLayoutManager
00144 {
00145     private:
00146     protected:
00147         virtual void layoutElements();
00148         bool mComponentSizeOnly;
00149     public:
00150         static const char *CLASS;
00151         virtual std::string getType() {return (std::string) CLASS;}
00152         CSLayoutManagerXY() {mComponentSizeOnly = false;}
00153         virtual ~CSLayoutManagerXY() {}
00154         virtual int getMinimumWidth(CSGrafikElement *element);  
00155         virtual int getMinimumHeight(CSGrafikElement *element); 
00156         
00157         // Use only the size of the components to calculate the minimum size of the
00158         // to be layouted component
00159         // that is ignore the start position of the elements
00160         // usefull if size of the component is calculated on the fly - and dependend of
00161         // other components (scrollbar size, the position of the mMore button is
00162         // dependend of the size of the parent, and the elements of the panel to be scrolled)
00163         void setComponentSizeOnly(bool b) {mComponentSizeOnly = b;}
00164 };
00165 
00166 class CSLayoutManagerStackHorizontal : public CSLayoutManager
00167 {
00168     private:
00169     protected:
00170         virtual void layoutElements();
00171     public:
00172         static const char *CLASS;
00173         virtual std::string getType() {return (std::string) CLASS;}
00174         CSLayoutManagerStackHorizontal() {}
00175         virtual ~CSLayoutManagerStackHorizontal() {}
00176         virtual int getMinimumWidth(CSGrafikElement *element);  
00177         virtual int getMinimumHeight(CSGrafikElement *element); 
00178 };
00179 
00180 class CSLayoutManagerStackVertical : public CSLayoutManager
00181 {
00182     private:
00183     protected:
00184         virtual void layoutElements();
00185     public:
00186         static const char *CLASS;
00187         virtual std::string getType() {return (std::string) CLASS;}
00188         CSLayoutManagerStackVertical() {}
00189         virtual ~CSLayoutManagerStackVertical() {}
00190         virtual int getMinimumWidth(CSGrafikElement *element);  
00191         virtual int getMinimumHeight(CSGrafikElement *element); 
00192 };
00193 
00194 /**
00195     For Non Viewported only Non-Centered is supported!
00196   */
00197 class CSLayoutManagerBorder : public CSLayoutManager
00198 {
00199     private:
00200     protected:
00201         virtual void layoutElements();
00202     public:
00203         static const char *CLASS;
00204         virtual std::string getType() {return (std::string) CLASS;}
00205         CSLayoutManagerBorder() {}
00206         virtual ~CSLayoutManagerBorder() {}
00207         virtual int getMinimumWidth(CSGrafikElement *element);  
00208         virtual int getMinimumHeight(CSGrafikElement *element); 
00209 };
00210 #endif // CSLayouManager_h

Generated on Wed Jul 14 00:43:30 2004 for CSLib by doxygen 1.3.6