00001 /* 00002 * The Mana World 00003 * Copyright (C) 2008 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #ifndef TABLE_MODEL_H 00023 #define TABLE_MODEL_H 00024 00025 #include <set> 00026 #include <vector> 00027 00028 class TableModelListener 00029 { 00030 public: 00040 virtual void modelUpdated(bool completed) = 0; 00041 }; 00042 00046 class TableModel 00047 { 00048 public: 00049 virtual ~TableModel() { } 00050 00054 virtual int getRows() = 0; 00055 00059 virtual int getColumns() = 0; 00060 00064 virtual int getRowHeight() = 0; 00065 00069 virtual int getColumnWidth(int index) = 0; 00070 00074 virtual gcn::Widget *getElementAt(int row, int column) = 0; 00075 00076 virtual void installListener(TableModelListener *listener); 00077 00078 virtual void removeListener(TableModelListener *listener); 00079 00080 protected: 00084 virtual void signalBeforeUpdate(); 00085 00089 virtual void signalAfterUpdate(); 00090 00091 private: 00092 std::set<TableModelListener *> listeners; 00093 }; 00094 00095 00096 class StaticTableModel : public TableModel 00097 { 00098 public: 00099 StaticTableModel(int width, int height); 00100 virtual ~StaticTableModel(); 00101 00107 virtual void set(int row, int column, gcn::Widget *widget); 00108 00115 virtual void fixColumnWidth(int column, int width); 00116 00122 virtual void fixRowHeight(int height); 00123 00127 virtual void resize(); 00128 00129 virtual int getRows(); 00130 virtual int getColumns(); 00131 virtual int getRowHeight(); 00132 virtual int getWidth(); 00133 virtual int getHeight(); 00134 virtual int getColumnWidth(int index); 00135 virtual gcn::Widget *getElementAt(int row, int column); 00136 00137 protected: 00138 int mRows, mColumns; 00139 int mHeight; 00140 std::vector<gcn::Widget *> mTableModel; 00141 std::vector<int> mWidths; 00142 }; 00143 00144 #endif /* !defined(TABLE_MODEL_H) */