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