ManaPlus
guitable.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2008-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUI_WIDGETS_GUITABLE_H
25 #define GUI_WIDGETS_GUITABLE_H
26 
27 #include "localconsts.h"
28 
30 
31 #include "listeners/keylistener.h"
34 
35 #include "gui/widgets/widget.h"
36 
38 class TableModel;
39 
49 class GuiTable final : public Widget,
50  public MouseListener,
51  public KeyListener,
52  public TableModelListener
53 {
54  // so that the action listener can call distributeActionEvent
55  friend class GuiTableActionListener;
56 
57  public:
58  GuiTable(const Widget2 *const widget,
59  TableModel *const initial_model,
60  const Opaque opacity);
61 
63 
65 
74  void setModel(TableModel *const m);
75 
80 
81  void setSelected(const int row, const int column);
82 
83  int getSelectedRow() const A_WARN_UNUSED;
84 
85  int getSelectedColumn() const A_WARN_UNUSED;
86 
87  void setSelectedRow(const int selected);
88 
89  void setSelectedColumn(const int selected);
90 
92  { return mWrappingEnabled; }
93 
94  void setWrappingEnabled(bool wrappingEnabled)
95  { mWrappingEnabled = wrappingEnabled; }
96 
98 
112  void setLinewiseSelection(bool linewise)
113  { mLinewiseMode = linewise; }
114 
115  // Inherited from Widget
116  void draw(Graphics *const graphics) override final A_NONNULL(2);
117 
118  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
119 
120  Widget *getWidgetAt(int x, int y) override final A_WARN_UNUSED;
121 
122  void moveToTop(Widget *const widget) override final;
123 
124  void moveToBottom(Widget *const widget) override final;
125 
126  void setFocusHandler(FocusHandler *const focusHandler) override final;
127 
128  // Inherited from KeyListener
129  void keyPressed(KeyEvent& event) override final;
130 
137  void setOpaque(Opaque opaque)
138  { mOpaque = opaque; }
139 
147  { return mOpaque == Opaque_true; }
148 
149  // Inherited from MouseListener
150  void mousePressed(MouseEvent& event) override final;
151 
152  void mouseWheelMovedUp(MouseEvent& event) override final;
153 
154  void mouseWheelMovedDown(MouseEvent& event) override final;
155 
156  void mouseDragged(MouseEvent& event) override final;
157 
158  // Constraints inherited from TableModelListener
159  void modelUpdated(const bool completed) override final;
160 
161  void requestFocus() override;
162 
163  void setSelectableGui(bool b)
164  { mSelectableGui = b; }
165 
166  protected:
169 
171  void installActionListeners();
172 
173  int getRowHeight() const A_WARN_UNUSED;
174 
175  int getColumnWidth(const int i) const A_WARN_UNUSED;
176 
177  private:
178  int getRowForY(const int y) const A_WARN_UNUSED; // -1 on error
179 
180  int getColumnForX(const int x) const A_WARN_UNUSED; // -1 on error
181 
182  void recomputeDimensions();
183 
184  static float mAlpha;
185 
187 
190 
193 
198 
201 
206 };
207 
208 #endif // GUI_WIDGETS_GUITABLE_H
Definition: color.h:76
bool mWrappingEnabled
Definition: guitable.h:203
void mouseDragged(MouseEvent &event)
Definition: guitable.cpp:568
void mouseWheelMovedUp(MouseEvent &event)
Definition: guitable.cpp:548
void installActionListeners()
Definition: guitable.cpp:205
int mSelectedRow
Definition: guitable.h:199
void mouseWheelMovedDown(MouseEvent &event)
Definition: guitable.cpp:559
bool isWrappingEnabled() const
Definition: guitable.h:91
void requestFocus()
Definition: guitable.cpp:671
void setSelectableGui(bool b)
Definition: guitable.h:163
void mousePressed(MouseEvent &event)
Definition: guitable.cpp:526
const TableModel * getModel() const
Definition: guitable.cpp:80
Widget * getWidgetAt(int x, int y)
Definition: guitable.cpp:595
GuiTable(const Widget2 *const widget, TableModel *const initial_model, const Opaque opacity)
Definition: guitable.cpp:43
void setSelected(const int row, const int column)
Definition: guitable.cpp:125
void setFocusHandler(FocusHandler *const focusHandler)
Definition: guitable.cpp:649
static float mAlpha
Definition: guitable.h:184
Widget * mTopWidget
Definition: guitable.h:189
void moveToTop(Widget *const widget)
Definition: guitable.cpp:463
Color mHighlightColor
Definition: guitable.h:197
int getSelectedColumn() const
Definition: guitable.cpp:136
void moveToBottom(Widget *const widget)
Definition: guitable.cpp:469
bool isOpaque() const
Definition: guitable.h:146
void modelUpdated(const bool completed)
Definition: guitable.cpp:581
void keyPressed(KeyEvent &event)
Definition: guitable.cpp:482
~GuiTable()
Definition: guitable.cpp:71
int getColumnForX(const int x) const
Definition: guitable.cpp:631
void setModel(TableModel *const m)
Definition: guitable.cpp:85
std::vector< GuiTableActionListener * > mActionListeners2
Definition: guitable.h:192
int getSelectedRow() const
Definition: guitable.cpp:131
int getRowHeight() const
Definition: guitable.cpp:141
int mSelectedColumn
Definition: guitable.h:200
void safeDraw(Graphics *const graphics)
Definition: guitable.cpp:345
void setOpaque(Opaque opaque)
Definition: guitable.h:137
void setSelectedRow(const int selected)
Definition: guitable.cpp:151
bool mLinewiseMode
Definition: guitable.h:202
void draw(Graphics *const graphics)
Definition: guitable.cpp:227
int getRowForY(const int y) const
Definition: guitable.cpp:618
void setWrappingEnabled(bool wrappingEnabled)
Definition: guitable.h:94
void setSelectedColumn(const int selected)
Definition: guitable.cpp:180
void recomputeDimensions()
Definition: guitable.cpp:100
void setLinewiseSelection(bool linewise)
Definition: guitable.h:112
int getColumnWidth(const int i) const
Definition: guitable.cpp:146
Rect getChildrenArea()
Definition: guitable.cpp:476
bool mSelectableGui
Definition: guitable.h:205
void uninstallActionListeners()
Definition: guitable.cpp:199
TableModel * mModel
Definition: guitable.h:186
Opaque mOpaque
Definition: guitable.h:204
Definition: rect.h:74
Definition: widget.h:99
#define override
Definition: localconsts.h:47
#define RETURNS_NONNULL
Definition: localconsts.h:167
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define A_NONNULLPOINTER
Definition: localconsts.h:266
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
const bool Opaque_true
Definition: opaque.h:30
bool Opaque
Definition: opaque.h:30
#define STD_VECTOR
Definition: vector.h:30