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-2018 The ManaPlus Developers
6  *
7  * This file is part of The ManaPlus Client.
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef GUI_WIDGETS_GUITABLE_H
24 #define GUI_WIDGETS_GUITABLE_H
25 
26 #include "localconsts.h"
27 
29 
30 #include "listeners/keylistener.h"
33 
34 #include "gui/widgets/widget.h"
35 
37 class TableModel;
38 
48 class GuiTable final : public Widget,
49  public MouseListener,
50  public KeyListener,
51  public TableModelListener
52 {
53  // so that the action listener can call distributeActionEvent
54  friend class GuiTableActionListener;
55 
56  public:
57  GuiTable(const Widget2 *const widget,
58  TableModel *const initial_model,
59  const Opaque opacity);
60 
62 
64 
73  void setModel(TableModel *const m);
74 
79 
80  void setSelected(const int row, const int column);
81 
82  int getSelectedRow() const A_WARN_UNUSED;
83 
84  int getSelectedColumn() const A_WARN_UNUSED;
85 
86  void setSelectedRow(const int selected);
87 
88  void setSelectedColumn(const int selected);
89 
90  bool isWrappingEnabled() const noexcept2 A_WARN_UNUSED
91  { return mWrappingEnabled; }
92 
93  void setWrappingEnabled(bool wrappingEnabled)
94  { mWrappingEnabled = wrappingEnabled; }
95 
96  Rect getChildrenArea() override final A_WARN_UNUSED;
97 
111  void setLinewiseSelection(bool linewise)
112  { mLinewiseMode = linewise; }
113 
114  // Inherited from Widget
115  void draw(Graphics *const graphics) override final A_NONNULL(2);
116 
117  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
118 
119  Widget *getWidgetAt(int x, int y) override final A_WARN_UNUSED;
120 
121  void moveToTop(Widget *const widget) override final;
122 
123  void moveToBottom(Widget *const widget) override final;
124 
125  void setFocusHandler(FocusHandler *const focusHandler) override final;
126 
127  // Inherited from KeyListener
128  void keyPressed(KeyEvent& event) override final;
129 
136  void setOpaque(Opaque opaque)
137  { mOpaque = opaque; }
138 
145  bool isOpaque() const noexcept2 A_WARN_UNUSED
146  { return mOpaque == Opaque_true; }
147 
148  // Inherited from MouseListener
149  void mousePressed(MouseEvent& event) override final;
150 
151  void mouseWheelMovedUp(MouseEvent& event) override final;
152 
153  void mouseWheelMovedDown(MouseEvent& event) override final;
154 
155  void mouseDragged(MouseEvent& event) override final;
156 
157  // Constraints inherited from TableModelListener
158  void modelUpdated(const bool completed) override final;
159 
160  void requestFocus() override;
161 
162  void setSelectableGui(bool b)
163  { mSelectableGui = b; }
164 
165  protected:
168 
170  void installActionListeners();
171 
172  int getRowHeight() const A_WARN_UNUSED;
173 
174  int getColumnWidth(const int i) const A_WARN_UNUSED;
175 
176  private:
177  int getRowForY(const int y) const A_WARN_UNUSED; // -1 on error
178 
179  int getColumnForX(const int x) const A_WARN_UNUSED; // -1 on error
180 
181  void recomputeDimensions();
182 
183  static float mAlpha;
184 
186 
189 
191  STD_VECTOR<GuiTableActionListener *> mActionListeners2;
192 
197 
200 
205 };
206 
207 #endif // GUI_WIDGETS_GUITABLE_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
std::vector< GuiTableActionListener * > mActionListeners2
Definition: guitable.h:191
void keyPressed(KeyEvent &event)
Definition: guitable.cpp:481
void draw(Graphics *const graphics)
Definition: guitable.cpp:226
bool mSelectableGui
Definition: guitable.h:204
Widget * getWidgetAt(int x, int y)
Definition: guitable.cpp:594
#define A_NONNULLPOINTER
Definition: localconsts.h:257
const TableModel * getModel() const
Definition: guitable.cpp:79
void mousePressed(MouseEvent &event)
Definition: guitable.cpp:525
bool isOpaque() const
Definition: guitable.h:145
~GuiTable()
Definition: guitable.cpp:70
void setSelected(const int row, const int column)
Definition: guitable.cpp:124
int getColumnWidth(const int i) const
Definition: guitable.cpp:145
Definition: rect.h:72
void mouseWheelMovedDown(MouseEvent &event)
Definition: guitable.cpp:558
int getRowHeight() const
Definition: guitable.cpp:140
#define A_WARN_UNUSED
Definition: localconsts.h:152
#define final
Definition: localconsts.h:45
GuiTable(const Widget2 *const widget, TableModel *const initial_model, const Opaque opacity)
Definition: guitable.cpp:42
void installActionListeners()
Definition: guitable.cpp:204
void moveToTop(Widget *const widget)
Definition: guitable.cpp:462
Widget * mTopWidget
Definition: guitable.h:188
#define A_NONNULL(...)
Definition: localconsts.h:159
void recomputeDimensions()
Definition: guitable.cpp:99
TableModel * mModel
Definition: guitable.h:185
bool isWrappingEnabled() const
Definition: guitable.h:90
void setFocusHandler(FocusHandler *const focusHandler)
Definition: guitable.cpp:648
void setSelectedColumn(const int selected)
Definition: guitable.cpp:179
int mSelectedRow
Definition: guitable.h:198
Color mHighlightColor
Definition: guitable.h:196
int getSelectedRow() const
Definition: guitable.cpp:130
void setLinewiseSelection(bool linewise)
Definition: guitable.h:111
bool mWrappingEnabled
Definition: guitable.h:202
int mSelectedColumn
Definition: guitable.h:199
int getColumnForX(const int x) const
Definition: guitable.cpp:630
int getRowForY(const int y) const
Definition: guitable.cpp:617
void setModel(TableModel *const m)
Definition: guitable.cpp:84
void mouseDragged(MouseEvent &event)
Definition: guitable.cpp:567
void setOpaque(Opaque opaque)
Definition: guitable.h:136
void mouseWheelMovedUp(MouseEvent &event)
Definition: guitable.cpp:547
void setWrappingEnabled(bool wrappingEnabled)
Definition: guitable.h:93
Definition: widget.h:97
void moveToBottom(Widget *const widget)
Definition: guitable.cpp:468
const bool Opaque_true
Definition: opaque.h:29
void requestFocus()
Definition: guitable.cpp:670
Opaque mOpaque
Definition: guitable.h:203
void setSelectableGui(bool b)
Definition: guitable.h:162
void modelUpdated(const bool completed)
Definition: guitable.cpp:580
Definition: color.h:74
#define override
Definition: localconsts.h:46
void safeDraw(Graphics *const graphics)
Definition: guitable.cpp:344
void uninstallActionListeners()
Definition: guitable.cpp:198
bool mLinewiseMode
Definition: guitable.h:201
void setSelectedRow(const int selected)
Definition: guitable.cpp:150
int getSelectedColumn() const
Definition: guitable.cpp:135
static float mAlpha
Definition: guitable.h:183
#define noexcept2
Definition: localconsts.h:49
Rect getChildrenArea()
Definition: guitable.cpp:475
#define RETURNS_NONNULL
Definition: localconsts.h:158