Mana
Loading...
Searching...
No Matches
table.h
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2008-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "tablemodel.h"
25
26#include <guichan/keylistener.hpp>
27#include <guichan/mouselistener.hpp>
28#include <guichan/widget.hpp>
29
30#include <vector>
31
33
43class GuiTable final : public gcn::Widget,
44 public gcn::MouseListener,
45 public gcn::KeyListener,
47{
48 // so that the action listener can call distributeActionEvent
50
51public:
52 GuiTable(TableModel *initialModel = nullptr, gcn::Color background = 0xffffff,
53 bool opacity = true);
54
55 ~GuiTable() override;
56
60 TableModel *getModel() const;
61
70 void setModel(TableModel *m);
71
72 void setSelected(int row, int column);
73
74 int getSelectedRow() const;
75
76 int getSelectedColumn() const;
77
78 void setSelectedRow(int selected);
79
80 void setSelectedColumn(int selected);
81
82 bool isWrappingEnabled() const {return mWrappingEnabled;}
83
84 void setWrappingEnabled(bool wrappingEnabled)
85 {mWrappingEnabled = wrappingEnabled;}
86
87 gcn::Rectangle getChildrenArea() override;
88
100 void setLinewiseSelection(bool linewise);
101
102 // Inherited from Widget
103 void draw(gcn::Graphics* graphics) override;
104
105 // Overridden to disable drawing of the frame
106 void drawFrame(gcn::Graphics* graphics) override {}
107
108 gcn::Widget *getWidgetAt(int x, int y) override;
109
110 void moveToTop(gcn::Widget *child) override;
111
112 void moveToBottom(gcn::Widget *child) override;
113
114 void _setFocusHandler(gcn::FocusHandler* focusHandler) override;
115
116 // Inherited from KeyListener
117 void keyPressed(gcn::KeyEvent& keyEvent) override;
118
125 void setOpaque(bool opaque) {mOpaque = opaque;}
126
133 bool isOpaque() const {return mOpaque;}
134
135 // Inherited from MouseListener
136 void mousePressed(gcn::MouseEvent& mouseEvent) override;
137
138 void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) override;
139
140 void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) override;
141
142 void mouseDragged(gcn::MouseEvent& mouseEvent) override;
143
144 // Constraints inherited from TableModelListener
145 void modelUpdated(bool) override;
146
147protected:
152
153 int getRowHeight() const;
154 int getColumnWidth(int i) const;
155
156private:
157 int getRowForY(int y) const; // -1 on error
158 int getColumnForX(int x) const; // -1 on error
159 void recomputeDimensions();
160
161 bool mLinewiseMode = false;
162 bool mWrappingEnabled = false;
164
169
170 TableModel *mModel = nullptr;
171
174
176 gcn::Widget *mTopWidget = nullptr;
177
179 std::vector<GuiTableActionListener *> mActionListeners;
180};
A table, with rows and columns made out of sub-widgets.
Definition table.h:47
bool mWrappingEnabled
Definition table.h:162
~GuiTable() override
Definition table.cpp:92
void installActionListeners()
Installs all action listeners on inner widgets.
Definition table.cpp:237
void mouseWheelMovedUp(gcn::MouseEvent &mouseEvent) override
Definition table.cpp:431
void setSelectedRow(int selected)
Definition table.cpp:178
int mSelectedRow
Definition table.h:172
void mousePressed(gcn::MouseEvent &mouseEvent) override
Definition table.cpp:413
void setOpaque(bool opaque)
Sets the table to be opaque, that is sets the table to display its background.
Definition table.h:125
void setSelectedColumn(int selected)
Definition table.cpp:206
bool isWrappingEnabled() const
Definition table.h:82
gcn::Widget * mTopWidget
If someone moves a fresh widget to the top, we must display it.
Definition table.h:176
void setModel(TableModel *m)
Sets the table model.
Definition table.cpp:103
bool mOpaque
Definition table.h:163
int getSelectedColumn() const
Definition table.cpp:154
bool isOpaque() const
Checks if the table is opaque, that is if the table area displays its background.
Definition table.h:133
void modelUpdated(bool) override
Must be invoked by the TableModel whenever a global change is about to occur or has occurred (e....
Definition table.cpp:468
int getSelectedRow() const
Definition table.cpp:149
int getRowHeight() const
Definition table.cpp:164
int mSelectedColumn
Definition table.h:173
int getRowForY(int y) const
Definition table.cpp:500
void drawFrame(gcn::Graphics *graphics) override
Definition table.h:106
gcn::Color mBackgroundColor
Holds the background color of the table.
Definition table.h:168
int getColumnWidth(int i) const
Definition table.cpp:171
TableModel * getModel() const
Retrieves the active table model.
Definition table.cpp:98
bool mLinewiseMode
Definition table.h:161
gcn::Rectangle getChildrenArea() override
Definition table.cpp:363
void moveToBottom(gcn::Widget *child) override
Definition table.cpp:356
std::vector< GuiTableActionListener * > mActionListeners
Vector for compactness; used as a list in practice.
Definition table.h:179
void mouseDragged(gcn::MouseEvent &mouseEvent) override
Definition table.cpp:454
void setWrappingEnabled(bool wrappingEnabled)
Definition table.h:84
void mouseWheelMovedDown(gcn::MouseEvent &mouseEvent) override
Definition table.cpp:444
void keyPressed(gcn::KeyEvent &keyEvent) override
Definition table.cpp:369
void recomputeDimensions()
Definition table.cpp:121
void setSelected(int row, int column)
Definition table.cpp:143
void setLinewiseSelection(bool linewise)
Toggle whether to use linewise selection mode, in which the table selects an entire line at a time,...
Definition table.cpp:159
void uninstallActionListeners()
Frees all action listeners on inner widgets.
Definition table.cpp:231
void _setFocusHandler(gcn::FocusHandler *focusHandler) override
Definition table.cpp:531
TableModel * mModel
Definition table.h:170
void draw(gcn::Graphics *graphics) override
Definition table.cpp:257
gcn::Widget * getWidgetAt(int x, int y) override
Definition table.cpp:482
void moveToTop(gcn::Widget *child) override
Definition table.cpp:350
int getColumnForX(int x) const
Definition table.cpp:513
A model for a regular table of widgets.
Definition tablemodel.h:50
Graphics * graphics
Definition client.cpp:104