ManaPlus
browserbox.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2018 The ManaPlus Developers
6  * Copyright (C) 2009 Aethyra Development Team
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_BROWSERBOX_H
25 #define GUI_WIDGETS_BROWSERBOX_H
26 
28 
29 #include "enums/gui/colorname.h"
30 
31 #include "gui/browserlink.h"
32 
33 #include "gui/widgets/linepart.h"
34 #include "gui/widgets/widget.h"
35 
38 
39 #include "localconsts.h"
40 
41 class LinkHandler;
42 
47 class BrowserBox final : public Widget,
48  public MouseListener,
49  public WidgetListener
50 {
51  public:
55  BrowserBox(const Widget2 *const widget,
56  const Opaque opaque,
57  const std::string &skin);
58 
60 
61 
64  ~BrowserBox() override final;
65 
69  void setLinkHandler(LinkHandler *linkHandler);
70 
74  void setOpaque(Opaque opaque)
75  { mOpaque = opaque; }
76 
80  void setMaxRow(unsigned max)
81  { mMaxRows = max; }
82 
86  void addRow(const std::string &row,
87  const bool atTop);
88 
92  void addRow(const std::string &cmd, const char *const text);
93 
94  void addImage(const std::string &path);
95 
99  void clearRows();
100 
104  void mousePressed(MouseEvent &event) override final;
105 
106  void mouseMoved(MouseEvent &event) override final;
107 
108  void mouseExited(MouseEvent& event) override final;
109 
113  void draw(Graphics *const graphics) override final A_NONNULL(2);
114 
115  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
116 
117  void updateHeight();
118 
119  void updateSize(const bool always);
120 
121  typedef std::list<std::string> TextRows;
122 
124  { return mTextRows; }
125 
127  { return !mTextRows.empty(); }
128 
129  void setAlwaysUpdate(const bool n) noexcept2
130  { mAlwaysUpdate = n; }
131 
132  void setProcessVars(const bool n) noexcept2
133  { mProcessVars = n; }
134 
135  void setEnableImages(const bool n) noexcept2
136  { mEnableImages = n; }
137 
138  void setEnableKeys(const bool n) noexcept2
139  { mEnableKeys = n; }
140 
141  void setEnableTabs(const bool n) noexcept2
142  { mEnableTabs = n; }
143 
144  std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED;
145 
146  int getPadding() const noexcept2 A_WARN_UNUSED
147  { return mPadding; }
148 
149  void setForegroundColorAll(const Color &color1,
150  const Color &color2);
151 
152  unsigned int getDataWidth() const noexcept2 A_WARN_UNUSED
153  { return mDataWidth; }
154 
155  void moveSelectionUp();
156 
157  void moveSelectionDown();
158 
159  void selectSelection();
160 
161  void widgetResized(const Event &event) override final;
162 
163  private:
165 
166  typedef TextRows::iterator TextRowIterator;
167  typedef TextRows::const_iterator TextRowCIter;
168  TextRows mTextRows;
169  std::list<int> mTextRowLinksCount;
170 
171  typedef STD_VECTOR<LinePart> LinePartList;
172  typedef LinePartList::iterator LinePartIterator;
173  typedef LinePartList::const_iterator LinePartCIter;
174  LinePartList mLineParts;
175 
176  typedef STD_VECTOR<BrowserLink> Links;
177  typedef Links::iterator LinkIterator;
178  Links mLinks;
179 
182  unsigned int mHighlightMode;
184  unsigned int mMaxRows;
185  int mHeight;
186  int mWidth;
187  int mYStart;
188  time_t mUpdateTime;
189  int mPadding;
190  unsigned int mNewLinePadding;
192  unsigned int mDataWidth;
193 
197 
206 
207  static ImageSet *mEmotes;
208  static int mInstances;
209 };
210 
211 #endif // GUI_WIDGETS_BROWSERBOX_H
#define A_DELETE_COPY(func)
Definition: localconsts.h:52
std::vector< BrowserLink > Links
Definition: browserbox.h:176
void moveSelectionUp()
Definition: browserbox.cpp:911
bool mEnableTabs
Definition: browserbox.h:205
void setEnableKeys(const bool n)
Definition: browserbox.h:138
Definition: skin.h:35
Color mHyperLinkColor
Definition: browserbox.h:195
LinePartList mLineParts
Definition: browserbox.h:174
unsigned int mMaxRows
Definition: browserbox.h:184
LinkHandler * mLinkHandler
Definition: browserbox.h:180
unsigned int mHighlightMode
Definition: browserbox.h:182
#define A_WARN_UNUSED
Definition: localconsts.h:160
int calcHeight()
Definition: browserbox.cpp:494
#define final
Definition: localconsts.h:45
void moveSelectionDown()
Definition: browserbox.cpp:919
bool mProcessVars
Definition: browserbox.h:202
std::list< int > mTextRowLinksCount
Definition: browserbox.h:169
#define A_NONNULL(...)
Definition: localconsts.h:167
TextRows & getRows()
Definition: browserbox.h:123
std::string getTextAtPos(const int x, const int y) const
Definition: browserbox.cpp:869
void selectSelection()
Definition: browserbox.cpp:926
time_t mUpdateTime
Definition: browserbox.h:188
Links mLinks
Definition: browserbox.h:178
void widgetResized(const Event &event)
Definition: browserbox.cpp:939
bool hasRows() const
Definition: browserbox.h:126
void mouseMoved(MouseEvent &event)
Definition: browserbox.cpp:386
bool mEnableImages
Definition: browserbox.h:203
BrowserBox(const Widget2 *const widget, const Opaque opaque, const std::string &skin)
Definition: browserbox.cpp:60
Color mColors[2][ColorName::COLORS_MAX]
Definition: browserbox.h:196
TextRows mTextRows
Definition: browserbox.h:168
static ImageSet * mEmotes
Definition: browserbox.h:207
Opaque mOpaque
Definition: browserbox.h:198
TextRows::const_iterator TextRowCIter
Definition: browserbox.h:167
static int mInstances
Definition: browserbox.h:208
void setProcessVars(const bool n)
Definition: browserbox.h:132
void setEnableTabs(const bool n)
Definition: browserbox.h:141
unsigned int getDataWidth() const
Definition: browserbox.h:152
bool mAlwaysUpdate
Definition: browserbox.h:201
bool mEnableKeys
Definition: browserbox.h:204
void draw(Graphics *const graphics)
Definition: browserbox.cpp:400
void addImage(const std::string &path)
Definition: browserbox.cpp:349
void safeDraw(Graphics *const graphics)
Definition: browserbox.cpp:489
Color mHighlightColor
Definition: browserbox.h:194
void setMaxRow(unsigned max)
Definition: browserbox.h:80
void addRow(const std::string &row, const bool atTop)
Definition: browserbox.cpp:170
Definition: widget.h:97
void setLinkHandler(LinkHandler *linkHandler)
Definition: browserbox.cpp:165
void setEnableImages(const bool n)
Definition: browserbox.h:135
std::vector< LinePart > LinePartList
Definition: browserbox.h:171
Definition: event.h:77
int mPadding
Definition: browserbox.h:189
void mouseExited(MouseEvent &event)
Definition: browserbox.cpp:395
bool mUseEmotes
Definition: browserbox.h:200
unsigned int mNewLinePadding
Definition: browserbox.h:190
Definition: color.h:74
void setOpaque(Opaque opaque)
Definition: browserbox.h:74
Links::iterator LinkIterator
Definition: browserbox.h:177
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: browserbox.cpp:904
bool mUseLinksAndUserColors
Definition: browserbox.h:199
Skin * mSkin
Definition: browserbox.h:181
int mItemPadding
Definition: browserbox.h:191
LinePartList::iterator LinePartIterator
Definition: browserbox.h:172
int mSelectedLink
Definition: browserbox.h:183
TextRows::iterator TextRowIterator
Definition: browserbox.h:166
unsigned int mDataWidth
Definition: browserbox.h:192
void updateSize(const bool always)
Definition: browserbox.cpp:862
#define noexcept2
Definition: localconsts.h:49
void updateHeight()
Definition: browserbox.cpp:850
void clearRows()
Definition: browserbox.cpp:358
void setAlwaysUpdate(const bool n)
Definition: browserbox.h:129
std::list< std::string > TextRows
Definition: browserbox.h:121
int getPadding() const
Definition: browserbox.h:146
void mousePressed(MouseEvent &event)
Definition: browserbox.cpp:371
LinePartList::const_iterator LinePartCIter
Definition: browserbox.h:173