GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/browserbox.h Lines: 8 9 88.9 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
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
28
#include "enums/simpletypes/opaque.h"
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
37
#include "listeners/mouselistener.h"
38
#include "listeners/widgetlistener.h"
39
40
#include "localconsts.h"
41
42
class LinkHandler;
43
44
/**
45
 * A simple browser box able to handle links and forward events to the
46
 * parent conteiner.
47
 */
48
class BrowserBox final : public Widget,
49
                         public MouseListener,
50
                         public WidgetListener
51
{
52
    public:
53
        /**
54
         * Constructor.
55
         */
56
        BrowserBox(const Widget2 *const widget,
57
                   const Opaque opaque,
58
                   const std::string &skin);
59
60
        A_DELETE_COPY(BrowserBox)
61
62
        /**
63
         * Destructor.
64
         */
65
        ~BrowserBox() override final;
66
67
        /**
68
         * Sets the handler for links.
69
         */
70
        void setLinkHandler(LinkHandler *linkHandler);
71
72
        /**
73
         * Sets the BrowserBox opacity.
74
         */
75
        void setOpaque(Opaque opaque)
76
5
        { mOpaque = opaque; }
77
78
        /**
79
         * Sets the maximum numbers of rows in the browser box. 0 = no limit.
80
         */
81
        void setMaxRow(unsigned max)
82
2
        { mMaxRows = max; }
83
84
        /**
85
         * Adds a text row to the browser.
86
         */
87
        void addRow(const std::string &row,
88
                    const bool atTop);
89
90
        /**
91
         * Adds a menu line to the browser.
92
         */
93
        void addRow(const std::string &cmd, const char *const text);
94
95
        void addImage(const std::string &path);
96
97
        /**
98
         * Remove all rows.
99
         */
100
        void clearRows();
101
102
        /**
103
         * Handles mouse actions.
104
         */
105
        void mousePressed(MouseEvent &event) override final;
106
107
        void mouseMoved(MouseEvent &event) override final;
108
109
        void mouseExited(MouseEvent& event) override final;
110
111
        /**
112
         * Draws the browser box.
113
         */
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
124
        TextRows &getRows() noexcept2 A_WARN_UNUSED
125
        { return mTextRows; }
126
127
        bool hasRows() const noexcept2 A_WARN_UNUSED
128
2
        { return !mTextRows.empty(); }
129
130
        void setAlwaysUpdate(const bool n) noexcept2
131
1
        { mAlwaysUpdate = n; }
132
133
        void setProcessVars(const bool n) noexcept2
134
1
        { mProcessVars = n; }
135
136
        void setEnableImages(const bool n) noexcept2
137
1
        { mEnableImages = n; }
138
139
        void setEnableKeys(const bool n) noexcept2
140
1
        { mEnableKeys = n; }
141
142
        void setEnableTabs(const bool n) noexcept2
143
1
        { mEnableTabs = n; }
144
145
        std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED;
146
147
        int getPadding() const noexcept2 A_WARN_UNUSED
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:
165
        int calcHeight() A_WARN_UNUSED;
166
167
        typedef TextRows::iterator TextRowIterator;
168
        typedef TextRows::const_iterator TextRowCIter;
169
        TextRows mTextRows;
170
        std::list<int> mTextRowLinksCount;
171
172
        typedef STD_VECTOR<LinePart> LinePartList;
173
        typedef LinePartList::iterator LinePartIterator;
174
        typedef LinePartList::const_iterator LinePartCIter;
175
        LinePartList mLineParts;
176
177
        typedef STD_VECTOR<BrowserLink> Links;
178
        typedef Links::iterator LinkIterator;
179
        Links mLinks;
180
181
        LinkHandler *mLinkHandler;
182
        Skin *mSkin;
183
        unsigned int mHighlightMode;
184
        int mSelectedLink;
185
        unsigned int mMaxRows;
186
        int mHeight;
187
        int mWidth;
188
        int mYStart;
189
        time_t mUpdateTime;
190
        int mPadding;
191
        unsigned int mNewLinePadding;
192
        int mItemPadding;
193
        unsigned int mDataWidth;
194
195
        Color mHighlightColor;
196
        Color mHyperLinkColor;
197
        Color mColors[2][ColorName::COLORS_MAX];
198
199
        Opaque mOpaque;
200
        bool mUseLinksAndUserColors;
201
        bool mUseEmotes;
202
        bool mAlwaysUpdate;
203
        bool mProcessVars;
204
        bool mEnableImages;
205
        bool mEnableKeys;
206
        bool mEnableTabs;
207
208
        static ImageSet *mEmotes;
209
        static int mInstances;
210
};
211
212
#endif  // GUI_WIDGETS_BROWSERBOX_H