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_H 00023 #define TABLE_H 00024 00025 #include <vector> 00026 00027 #include <guichan/keylistener.hpp> 00028 #include <guichan/mouselistener.hpp> 00029 #include <guichan/widget.hpp> 00030 00031 #include "table_model.h" 00032 00033 class GuiTableActionListener; 00034 00044 class GuiTable : public gcn::Widget, 00045 public gcn::MouseListener, 00046 public gcn::KeyListener, 00047 public TableModelListener 00048 { 00049 // so that the action listener can call distributeActionEvent 00050 friend class GuiTableActionListener; 00051 00052 public: 00053 GuiTable(TableModel * initial_model = NULL, gcn::Color background = 0xffffff, 00054 bool opacity = true); 00055 00056 virtual ~GuiTable(); 00057 00061 TableModel *getModel() const; 00062 00071 void setModel(TableModel *m); 00072 00073 const TableModel* getModel() {return mModel;} 00074 00075 void setSelected(int row, int column); 00076 00077 int getSelectedRow(); 00078 00079 int getSelectedColumn(); 00080 00081 void setSelectedRow(int selected); 00082 00083 void setSelectedColumn(int selected); 00084 00085 bool isWrappingEnabled() const {return mWrappingEnabled;} 00086 00087 void setWrappingEnabled(bool wrappingEnabled) 00088 {mWrappingEnabled = wrappingEnabled;} 00089 00090 gcn::Rectangle getChildrenArea(void); 00091 00103 void setLinewiseSelection(bool linewise); 00104 00105 // Inherited from Widget 00106 virtual void draw(gcn::Graphics* graphics); 00107 00108 virtual gcn::Widget *getWidgetAt(int x, int y); 00109 00110 virtual void moveToTop(gcn::Widget *child); 00111 00112 virtual void moveToBottom(gcn::Widget *child); 00113 00114 virtual void _setFocusHandler(gcn::FocusHandler* focusHandler); 00115 00116 // Inherited from KeyListener 00117 virtual void keyPressed(gcn::KeyEvent& keyEvent); 00118 00125 virtual void setOpaque(bool opaque) {mOpaque = opaque;} 00126 00133 virtual bool isOpaque() const {return mOpaque;} 00134 00135 // Inherited from MouseListener 00136 virtual void mousePressed(gcn::MouseEvent& mouseEvent); 00137 00138 virtual void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); 00139 00140 virtual void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); 00141 00142 virtual void mouseDragged(gcn::MouseEvent& mouseEvent); 00143 00144 // Constraints inherited from TableModelListener 00145 virtual void modelUpdated(bool); 00146 00147 protected: 00149 virtual void uninstallActionListeners(); 00151 virtual void installActionListeners(); 00152 00153 virtual int getRowHeight(); 00154 virtual int getColumnWidth(int i); 00155 00156 private: 00157 int getRowForY(int y); // -1 on error 00158 int getColumnForX(int x); // -1 on error 00159 void recomputeDimensions(); 00160 bool mLinewiseMode; 00161 bool mWrappingEnabled; 00162 bool mOpaque; 00163 00164 static float mAlpha; 00165 00169 gcn::Color mBackgroundColor; 00170 00171 TableModel *mModel; 00172 00173 int mSelectedRow; 00174 int mSelectedColumn; 00175 00177 int mPopFramesNr; 00178 00180 gcn::Widget *mTopWidget; 00181 00183 std::vector<GuiTableActionListener *> mActionListeners; 00184 }; 00185 00186 00187 #endif /* !defined(TABLE_H) */