GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/browserbox.h Lines: 8 9 88.9 %
Date: 2018-12-09 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-2018  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() override final;
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
5
        { 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
2
        { mMaxRows = max; }
82
83
        /**
84
         * Adds a text row to the browser.
85
         */
86
        void addRow(const std::string &row,
87
                    const bool atTop);
88
89
        /**
90
         * Adds a menu line to the browser.
91
         */
92
        void addRow(const std::string &cmd, const char *const text);
93
94
        void addImage(const std::string &path);
95
96
        /**
97
         * Remove all rows.
98
         */
99
        void clearRows();
100
101
        /**
102
         * Handles mouse actions.
103
         */
104
        void mousePressed(MouseEvent &event) override final;
105
106
        void mouseMoved(MouseEvent &event) override final;
107
108
        void mouseExited(MouseEvent& event) override final;
109
110
        /**
111
         * Draws the browser box.
112
         */
113
        void draw(Graphics *const graphics) override final A_NONNULL(2);
114
115
        void safeDraw(Graphics *const graphics) override final A_NONNULL(2);
116
117
        void updateHeight();
118
119
        void updateSize(const bool always);
120
121
        typedef std::list<std::string> TextRows;
122
123
        TextRows &getRows() noexcept2 A_WARN_UNUSED
124
        { return mTextRows; }
125
126
        bool hasRows() const noexcept2 A_WARN_UNUSED
127
2
        { return !mTextRows.empty(); }
128
129
        void setAlwaysUpdate(const bool n) noexcept2
130
1
        { mAlwaysUpdate = n; }
131
132
        void setProcessVars(const bool n) noexcept2
133
1
        { mProcessVars = n; }
134
135
        void setEnableImages(const bool n) noexcept2
136
1
        { mEnableImages = n; }
137
138
        void setEnableKeys(const bool n) noexcept2
139
1
        { mEnableKeys = n; }
140
141
        void setEnableTabs(const bool n) noexcept2
142
1
        { mEnableTabs = n; }
143
144
        std::string getTextAtPos(const int x, const int y) const A_WARN_UNUSED;
145
146
        int getPadding() const noexcept2 A_WARN_UNUSED
147
        { return mPadding; }
148
149
        void setForegroundColorAll(const Color &color1,
150
                                   const Color &color2);
151
152
        unsigned int getDataWidth() const noexcept2 A_WARN_UNUSED
153
        { return mDataWidth; }
154
155
        void moveSelectionUp();
156
157
        void moveSelectionDown();
158
159
        void selectSelection();
160
161
        void widgetResized(const Event &event) override final;
162
163
    private:
164
        int calcHeight() A_WARN_UNUSED;
165
166
        typedef TextRows::iterator TextRowIterator;
167
        typedef TextRows::const_iterator TextRowCIter;
168
        TextRows mTextRows;
169
        std::list<int> mTextRowLinksCount;
170
171
        typedef STD_VECTOR<LinePart> LinePartList;
172
        typedef LinePartList::iterator LinePartIterator;
173
        typedef LinePartList::const_iterator LinePartCIter;
174
        LinePartList mLineParts;
175
176
        typedef STD_VECTOR<BrowserLink> Links;
177
        typedef Links::iterator LinkIterator;
178
        Links mLinks;
179
180
        LinkHandler *mLinkHandler;
181
        Skin *mSkin;
182
        unsigned int mHighlightMode;
183
        int mSelectedLink;
184
        unsigned int mMaxRows;
185
        int mHeight;
186
        int mWidth;
187
        int mYStart;
188
        time_t mUpdateTime;
189
        int mPadding;
190
        unsigned int mNewLinePadding;
191
        int mItemPadding;
192
        unsigned int mDataWidth;
193
194
        Color mHighlightColor;
195
        Color mHyperLinkColor;
196
        Color mColors[2][ColorName::COLORS_MAX];
197
198
        Opaque mOpaque;
199
        bool mUseLinksAndUserColors;
200
        bool mUseEmotes;
201
        bool mAlwaysUpdate;
202
        bool mProcessVars;
203
        bool mEnableImages;
204
        bool mEnableKeys;
205
        bool mEnableTabs;
206
207
        static ImageSet *mEmotes;
208
        static int mInstances;
209
};
210
211
#endif  // GUI_WIDGETS_BROWSERBOX_H