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-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  * Copyright (C) 2009 Aethyra Development Team
8  *
9  * This file is part of The ManaPlus Client.
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef GUI_WIDGETS_BROWSERBOX_H
26 #define GUI_WIDGETS_BROWSERBOX_H
27 
29 
30 #include "enums/gui/colorname.h"
31 
32 #include "gui/browserlink.h"
33 
34 #include "gui/widgets/linepart.h"
35 #include "gui/widgets/widget.h"
36 
39 
40 #include "localconsts.h"
41 
42 class LinkHandler;
43 
48 class BrowserBox final : public Widget,
49  public MouseListener,
50  public WidgetListener
51 {
52  public:
56  BrowserBox(const Widget2 *const widget,
57  const Opaque opaque,
58  const std::string &skin);
59 
61 
62 
65  ~BrowserBox() override final;
66 
70  void setLinkHandler(LinkHandler *linkHandler);
71 
75  void setOpaque(Opaque opaque)
76  { mOpaque = opaque; }
77 
81  void setMaxRow(unsigned max)
82  { mMaxRows = max; }
83 
87  void addRow(const std::string &row,
88  const bool atTop);
89 
93  void addRow(const std::string &cmd, const char *const text);
94 
95  void addImage(const std::string &path);
96 
100  void clearRows();
101 
105  void mousePressed(MouseEvent &event) override final;
106 
107  void mouseMoved(MouseEvent &event) override final;
108 
109  void mouseExited(MouseEvent& event) override final;
110 
114  void draw(Graphics *const graphics) override final A_NONNULL(2);
115 
116  void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
117 
118  void updateHeight();
119 
120  void updateSize(const bool always);
121 
122  typedef std::list<std::string> TextRows;
123 
125  { return mTextRows; }
126 
128  { return !mTextRows.empty(); }
129 
130  void setAlwaysUpdate(const bool n) noexcept2
131  { mAlwaysUpdate = n; }
132 
133  void setProcessVars(const bool n) noexcept2
134  { mProcessVars = n; }
135 
136  void setEnableImages(const bool n) noexcept2
137  { mEnableImages = n; }
138 
139  void setEnableKeys(const bool n) noexcept2
140  { mEnableKeys = n; }
141 
142  void setEnableTabs(const bool n) noexcept2
143  { mEnableTabs = n; }
144 
145  std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED;
146 
148  { return mPadding; }
149 
150  void setForegroundColorAll(const Color &color1,
151  const Color &color2);
152 
153  unsigned int getDataWidth() const noexcept2 A_WARN_UNUSED
154  { return mDataWidth; }
155 
156  void moveSelectionUp();
157 
158  void moveSelectionDown();
159 
160  void selectSelection();
161 
162  void widgetResized(const Event &event) override final;
163 
164  private:
166 
167  typedef TextRows::iterator TextRowIterator;
168  typedef TextRows::const_iterator TextRowCIter;
171 
173  typedef LinePartList::iterator LinePartIterator;
174  typedef LinePartList::const_iterator LinePartCIter;
176 
178  typedef Links::iterator LinkIterator;
180 
183  unsigned int mHighlightMode;
185  unsigned int mMaxRows;
186  int mHeight;
187  int mWidth;
188  int mYStart;
189  time_t mUpdateTime;
190  int mPadding;
191  unsigned int mNewLinePadding;
193  unsigned int mDataWidth;
194 
198 
207 
208  static ImageSet *mEmotes;
209  static int mInstances;
210 };
211 
212 #endif // GUI_WIDGETS_BROWSERBOX_H
bool mEnableTabs
Definition: browserbox.h:206
unsigned int mDataWidth
Definition: browserbox.h:193
TextRows::iterator TextRowIterator
Definition: browserbox.h:167
int mPadding
Definition: browserbox.h:190
void setAlwaysUpdate(const bool n)
Definition: browserbox.h:130
TextRows::const_iterator TextRowCIter
Definition: browserbox.h:168
void mousePressed(MouseEvent &event)
Definition: browserbox.cpp:372
BrowserBox(const Widget2 *const widget, const Opaque opaque, const std::string &skin)
Definition: browserbox.cpp:61
void updateHeight()
Definition: browserbox.cpp:851
std::string getTextAtPos(const int x, const int y) const
Definition: browserbox.cpp:870
unsigned int getDataWidth() const
Definition: browserbox.h:153
Color mColors[2][ColorName::COLORS_MAX]
Definition: browserbox.h:197
Links mLinks
Definition: browserbox.h:179
std::vector< LinePart > LinePartList
Definition: browserbox.h:172
unsigned int mHighlightMode
Definition: browserbox.h:183
int mSelectedLink
Definition: browserbox.h:184
std::vector< BrowserLink > Links
Definition: browserbox.h:177
void setMaxRow(unsigned max)
Definition: browserbox.h:81
void updateSize(const bool always)
Definition: browserbox.cpp:863
Color mHyperLinkColor
Definition: browserbox.h:196
bool hasRows() const
Definition: browserbox.h:127
Skin * mSkin
Definition: browserbox.h:182
TextRows & getRows()
Definition: browserbox.h:124
static ImageSet * mEmotes
Definition: browserbox.h:208
void setForegroundColorAll(const Color &color1, const Color &color2)
Definition: browserbox.cpp:905
Links::iterator LinkIterator
Definition: browserbox.h:178
void widgetResized(const Event &event)
Definition: browserbox.cpp:940
void setEnableTabs(const bool n)
Definition: browserbox.h:142
std::list< std::string > TextRows
Definition: browserbox.h:122
void addRow(const std::string &row, const bool atTop)
Definition: browserbox.cpp:171
LinePartList::iterator LinePartIterator
Definition: browserbox.h:173
time_t mUpdateTime
Definition: browserbox.h:189
bool mEnableKeys
Definition: browserbox.h:205
void mouseMoved(MouseEvent &event)
Definition: browserbox.cpp:387
void addImage(const std::string &path)
Definition: browserbox.cpp:350
void setLinkHandler(LinkHandler *linkHandler)
Definition: browserbox.cpp:166
void setEnableImages(const bool n)
Definition: browserbox.h:136
LinkHandler * mLinkHandler
Definition: browserbox.h:181
void moveSelectionUp()
Definition: browserbox.cpp:912
std::list< int > mTextRowLinksCount
Definition: browserbox.h:170
bool mAlwaysUpdate
Definition: browserbox.h:202
unsigned int mMaxRows
Definition: browserbox.h:185
void clearRows()
Definition: browserbox.cpp:359
int mItemPadding
Definition: browserbox.h:192
void mouseExited(MouseEvent &event)
Definition: browserbox.cpp:396
Opaque mOpaque
Definition: browserbox.h:199
Color mHighlightColor
Definition: browserbox.h:195
void setEnableKeys(const bool n)
Definition: browserbox.h:139
LinePartList mLineParts
Definition: browserbox.h:175
void safeDraw(Graphics *const graphics)
Definition: browserbox.cpp:490
LinePartList::const_iterator LinePartCIter
Definition: browserbox.h:174
bool mProcessVars
Definition: browserbox.h:203
void setOpaque(Opaque opaque)
Definition: browserbox.h:75
int getPadding() const
Definition: browserbox.h:147
bool mEnableImages
Definition: browserbox.h:204
bool mUseLinksAndUserColors
Definition: browserbox.h:200
void draw(Graphics *const graphics)
Definition: browserbox.cpp:401
TextRows mTextRows
Definition: browserbox.h:169
int calcHeight()
Definition: browserbox.cpp:495
void selectSelection()
Definition: browserbox.cpp:927
void setProcessVars(const bool n)
Definition: browserbox.h:133
bool mUseEmotes
Definition: browserbox.h:201
unsigned int mNewLinePadding
Definition: browserbox.h:191
void moveSelectionDown()
Definition: browserbox.cpp:920
static int mInstances
Definition: browserbox.h:209
Definition: color.h:76
Definition: event.h:79
Definition: skin.h:37
Definition: widget.h:99
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define A_NONNULL(...)
Definition: localconsts.h:168
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
@ COLORS_MAX
Definition: colorname.h:42
bool Opaque
Definition: opaque.h:30
#define STD_VECTOR
Definition: vector.h:30