GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/staticbrowserbox.h Lines: 6 6 100.0 %
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_STATICBROWSERBOX_H
26
#define GUI_WIDGETS_STATICBROWSERBOX_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
39
#include "localconsts.h"
40
41
class LinkHandler;
42
43
/**
44
 * A simple browser box able to handle links and forward events to the
45
 * parent conteiner.
46
 */
47
class StaticBrowserBox final : public Widget,
48
                               public MouseListener
49
{
50
    public:
51
        /**
52
         * Constructor.
53
         */
54
        StaticBrowserBox(const Widget2 *const widget,
55
                         const Opaque opaque,
56
                         const std::string &skin);
57
58
        A_DELETE_COPY(StaticBrowserBox)
59
60
        /**
61
         * Destructor.
62
         */
63
        ~StaticBrowserBox() override final;
64
65
        /**
66
         * Sets the handler for links.
67
         */
68
        void setLinkHandler(LinkHandler *linkHandler);
69
70
        /**
71
         * Sets the StaticBrowserBox opacity.
72
         */
73
        void setOpaque(Opaque opaque)
74
10
        { mOpaque = opaque; }
75
76
        void addSeparator(const std::string &row);
77
78
        /**
79
         * Adds a text row to the browser.
80
         */
81
        void addRow(const std::string &row,
82
                    const bool atTop);
83
84
        /**
85
         * Adds a menu line to the browser.
86
         */
87
        void addRow(const std::string &cmd,
88
                    const char *const text);
89
90
        void addImage(const std::string &path);
91
92
        /**
93
         * Remove all rows.
94
         */
95
        void clearRows();
96
97
        /**
98
         * Handles mouse actions.
99
         */
100
        void mousePressed(MouseEvent &event) override final;
101
102
        void mouseMoved(MouseEvent &event) override final;
103
104
        void mouseExited(MouseEvent& event) override final;
105
106
        /**
107
         * Draws the browser box.
108
         */
109
        void draw(Graphics *const graphics) override final A_NONNULL(2);
110
111
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
112
113
        void updateHeight();
114
115
        void updateSize();
116
117
        typedef std::list<std::string> TextRows;
118
119
        TextRows &getRows() noexcept2 A_WARN_UNUSED
120
        { return mTextRows; }
121
122
        bool hasRows() const noexcept2 A_WARN_UNUSED
123
2
        { return !mTextRows.empty(); }
124
125
        void setProcessVars(const bool n) noexcept2
126
6
        { mProcessVars = n; }
127
128
        void setEnableImages(const bool n) noexcept2
129
5
        { mEnableImages = n; }
130
131
        void setEnableKeys(const bool n) noexcept2
132
5
        { mEnableKeys = n; }
133
134
        void setEnableTabs(const bool n) noexcept2
135
6
        { mEnableTabs = n; }
136
137
        std::string getTextAtPos(const int x,
138
                                 const int y) const A_WARN_UNUSED;
139
140
        int getPadding() const noexcept2 A_WARN_UNUSED
141
        { return mPadding; }
142
143
        void setForegroundColorAll(const Color &color1,
144
                                   const Color &color2);
145
146
        void moveSelectionUp();
147
148
        void moveSelectionDown();
149
150
        void selectSelection();
151
152
    private:
153
        typedef TextRows::iterator TextRowIterator;
154
        typedef TextRows::const_iterator TextRowCIter;
155
        TextRows mTextRows;
156
        std::list<int> mTextRowLinksCount;
157
158
        typedef STD_VECTOR<LinePart> LinePartList;
159
        typedef LinePartList::iterator LinePartIterator;
160
        typedef LinePartList::const_iterator LinePartCIter;
161
        LinePartList mLineParts;
162
163
        typedef STD_VECTOR<BrowserLink> Links;
164
        typedef Links::iterator LinkIterator;
165
        Links mLinks;
166
167
        LinkHandler *mLinkHandler;
168
        Skin *mSkin;
169
        unsigned int mHighlightMode;
170
        int mSelectedLink;
171
        int mHeight;
172
        int mWidth;
173
        int mYStart;
174
        int mPadding;
175
        unsigned int mNewLinePadding;
176
        int mItemPadding;
177
178
        Color mHighlightColor;
179
        Color mHyperLinkColor;
180
        Color mColors[2][ColorName::COLORS_MAX];
181
182
        Opaque mOpaque;
183
        bool mUseLinksAndUserColors;
184
        bool mUseEmotes;
185
        bool mProcessVars;
186
        bool mEnableImages;
187
        bool mEnableKeys;
188
        bool mEnableTabs;
189
        bool mSeparator;
190
191
        static ImageSet *mEmotes;
192
        static int mInstances;
193
};
194
195
#endif  // GUI_WIDGETS_STATICBROWSERBOX_H