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