Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | Related Pages

table.h

00001 /*
00002   libwftk - Worldforge Toolkit - a widget library
00003   Copyright (C) 2003 Ron Steinke <rsteinke@w-link.net>
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 _TABLE_H
00022 #define _TABLE_H
00023 
00024 #include <wftk/screenarea.h>
00025 #include <vector>
00026 
00027 namespace wftk {
00028 
00030 class Table : public ScreenArea
00031 {
00032  public:
00034   Table() : top_(0), left_(0) {}
00036   ~Table() {freeGrid();} // ScreenArea destructor will clear the children's parents
00037 
00039   bool pack(ScreenArea*, unsigned x, unsigned y, unsigned w = 1, unsigned h = 1);
00040 
00042 
00045   void insertRow(unsigned index) {insertEdge(index, false);}
00047 
00050   void insertColumn(unsigned index) {insertEdge(index, true);}
00051 
00053   void remove(ScreenArea*);
00055   void clear();
00056 
00058   ScreenArea* child(unsigned x, unsigned y) const
00059     {GridElem* elem = gridPos(x, y); return elem ? elem->content : 0;}
00060 
00062   PackingInfo::Expander getRowPackingInfo(unsigned) const;
00064   PackingInfo::Expander getColumnPackingInfo(unsigned) const;
00065 
00066  protected:
00068   virtual void handleResize(Uint16 w, Uint16 h);
00070   virtual void setPackingInfo();
00071  private:
00072 
00073   struct GridElem
00074   {
00075     GridElem() : right(0), down(0), content(0) {}
00076 
00077     GridElem* traverse(unsigned, unsigned);
00078 
00079     GridElem *right, *down;
00080     ScreenArea *content;
00081   };
00082 
00083   struct GridEdge
00084   {
00085     GridEdge() : elems(0), next(0), pixels(0) {}
00086 
00087     GridEdge* traverse(unsigned);
00088 
00089     PackingInfo::Expander packing;
00090     GridElem *elems;
00091     GridEdge *next;
00092 
00093     // used to cache row/column size during handleResize()
00094     Uint16 pixels;
00095   };
00096 
00097   GridEdge *top_, *left_;
00098 
00099   PackingInfo::Weights x_weight_, y_weight_;
00100 
00101   struct GridSpan
00102   {
00103     Uint16 min;
00104     Uint16 pref;
00105     GridEdge* start;
00106     unsigned char length;
00107 
00108     Uint16 min_overage;
00109     Uint16 pref_overage;
00110 
00111     void calcOverage();
00112 
00113     // for sorting spans
00114     bool operator<(const GridSpan&) const;
00115   };
00116 
00117   typedef std::vector<GridSpan> SpanList;
00118 
00119   // free memory used by grid elements
00120   void freeGrid();
00121 
00122   // insert either a row or column, returns true if one was added to the grid
00123   bool insertEdge(unsigned index, bool down);
00124 
00125   void packingFromEdge(GridEdge*, PackingInfo::Expander&, PackingInfo::Weights&);
00126 
00127   void setPixels(GridEdge*, PackingInfo::Weights&);
00128   // this function trashes the SpanList
00129   void incorporateSpans(GridEdge*, SpanList&);
00130 
00131   // get the GridElem at the specified location, or 0 if it's off the grid
00132   GridElem* gridPos(unsigned, unsigned) const;
00133 };
00134 
00135 }
00136 
00137 #endif // !_TABLE_H

Generated Thu Mar 18 20:06:04 2004.
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.