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_GRID_H 00022 #define WT_GRID_H 00023 00024 #include <wt/frame.h> 00025 #include <wt/gridlayout.h> 00026 00027 namespace Wt { 00028 00029 class Grid : public Frame { 00030 public: 00031 Grid(Widget *parent = 0, 00032 const std::string &name = "Grid::anon", int wflags = 0) : 00033 Frame(parent, name, wflags) { 00034 new GridLayout(this); 00035 gridLayout().autoAdd = true; 00036 } 00037 00038 Grid& operator()(int row_from, int row_to, 00039 int column_from, int column_to) { 00040 cs.setFromTo(row_from, row_to, column_from, column_to); 00041 return *this; 00042 } 00043 00044 Grid& operator()(int row, int column) { 00045 cs.setSpan(row, column); 00046 return *this; 00047 } 00048 00049 Grid& operator=(LayoutItem *li) { 00050 assert(cs.isValid()); 00051 cs.setLayoutItem(li); 00052 gridLayout().cellSpanQueue.push(cs); 00053 gridLayout().addItem(li); 00054 cs.invalidate(); 00055 return *this; 00056 } 00057 00058 template <typename T> 00059 T cell(int row, int column) const { 00060 LayoutItem *li = gridLayout()(row, column); 00061 return dynamic_cast<T>(li); 00062 } 00063 00064 int numRows() const { 00065 return gridLayout().numRows(); 00066 } 00067 00068 int numCols() const { 00069 return gridLayout().numCols(); 00070 } 00071 00072 protected: 00073 GridLayout& gridLayout() const { 00074 return *dynamic_cast<GridLayout *>(layout()); 00075 } 00076 00077 private: 00078 GridLayout::CellSpan cs; 00079 }; 00080 00081 } 00082 00083 #endif // WT_GRID_H
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.