GCC Code Coverage Report
Directory: src/ Exec Total Coverage
File: src/gui/widgets/basiccontainer.h Lines: 2 2 100.0 %
Date: 2021-03-17 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/*
2
 *  The ManaPlus Client
3
 *  Copyright (C) 2011-2019  The ManaPlus Developers
4
 *  Copyright (C) 2019-2021  Andrei Karas
5
 *
6
 *  This file is part of The ManaPlus Client.
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  any later version.
12
 *
13
 *  This program is distributed in the hope that it will be useful,
14
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 *  GNU General Public License for more details.
17
 *
18
 *  You should have received a copy of the GNU General Public License
19
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 */
21
22
/*      _______   __   __   __   ______   __   __   _______   __   __
23
 *     / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___  /\ /  |\/ /\
24
 *    / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / /
25
 *   / / /__   / / // / // / // / /    / ___  / // ___  / // /| ' / /
26
 *  / /_// /\ / /_// / // / // /_/_   / / // / // /\_/ / // / |  / /
27
 * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ /
28
 * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/
29
 *
30
 * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson
31
 *
32
 *
33
 * Per Larsson a.k.a finalman
34
 * Olof Naessén a.k.a jansem/yakslem
35
 *
36
 * Visit: http://guichan.sourceforge.net
37
 *
38
 * License: (BSD)
39
 * Redistribution and use in source and binary forms, with or without
40
 * modification, are permitted provided that the following conditions
41
 * are met:
42
 * 1. Redistributions of source code must retain the above copyright
43
 *    notice, this list of conditions and the following disclaimer.
44
 * 2. Redistributions in binary form must reproduce the above copyright
45
 *    notice, this list of conditions and the following disclaimer in
46
 *    the documentation and/or other materials provided with the
47
 *    distribution.
48
 * 3. Neither the name of Guichan nor the names of its contributors may
49
 *    be used to endorse or promote products derived from this software
50
 *    without specific prior written permission.
51
 *
52
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
58
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
59
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
60
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
61
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
62
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63
 */
64
65
#ifndef GUI_WIDGETS_BASICCONTAINER_H
66
#define GUI_WIDGETS_BASICCONTAINER_H
67
68
#include "gui/widgets/widget.h"
69
70
#include "listeners/widgetdeathlistener.h"
71
72
/**
73
  * A base class for containers. The class implements the most
74
  * common things for a container. If you are implementing a
75
  * container, consider inheriting from this class.
76
  *
77
  * @see Container
78
  */
79
class BasicContainer notfinal : public Widget,
80
                                public WidgetDeathListener
81
{
82
    public:
83
877
        explicit BasicContainer(const Widget2 *restrict const widget) :
84
            Widget(widget),
85
            WidgetDeathListener(),
86
            mWidgets(),
87
3508
            mLogicWidgets()
88
        { }
89
90
        A_DELETE_COPY(BasicContainer)
91
92
        /**
93
          * Destructor
94
          */
95
        ~BasicContainer() override;
96
97
        /**
98
          * Shows a certain part of a widget in the basic container.
99
          * Used when widgets want a specific part to be visible in
100
          * its parent. An example is a TextArea that wants a specific
101
          * part of its text to be visible when a TextArea is a child
102
          * of a ScrollArea.
103
          *
104
          * @param widget The widget whom wants a specific part of
105
          *               itself to be visible.
106
          * @param area The rectangle to be visible.
107
          */
108
        void showWidgetPart(Widget *restrict const widget,
109
                            const Rect &restrict area) restrict2 override;
110
111
        // Inherited from Widget
112
113
        void moveToTop(Widget *const widget) restrict2 override;
114
115
        void moveToBottom(Widget *const widget) restrict2 override;
116
117
        Rect getChildrenArea() restrict2 override A_WARN_UNUSED;
118
119
        void focusNext() restrict2 override;
120
121
        void focusPrevious() restrict2 override;
122
123
        void logic() restrict2 override;
124
125
        void setFocusHandler(FocusHandler *restrict const focusHandler)
126
                             restrict2 override;
127
128
        void setInternalFocusHandler(FocusHandler *const restrict focusHandler)
129
                                     restrict2;
130
131
        Widget *getWidgetAt(int x, int y) restrict2 override A_WARN_UNUSED;
132
133
        // Inherited from WidgetDeathListener
134
135
        void death(const Event &restrict event) restrict2 override;
136
137
        Widget *findFirstWidget(const std::set<Widget*> &restrict list)
138
                                restrict2;
139
140
        /**
141
          * Adds a widget to the basic container.
142
          *
143
          * @param widget The widget to add.
144
          * @see remove, clear
145
          */
146
        void add(Widget *const widget) restrict2;
147
148
        /**
149
          * Removes a widget from the basic container.
150
          *
151
          * @param widget The widget to remove.
152
          * @see add, clear
153
          */
154
        virtual void remove(Widget *const restrict widget) restrict2;
155
156
        /**
157
          * Clears the basic container from all widgets.
158
          *
159
          * @see remove, clear
160
          */
161
        virtual void clear() restrict2;
162
163
    protected:
164
        /**
165
          * Draws the children widgets of the basic container.
166
          *
167
          * @param graphics A graphics object to draw with.
168
          */
169
        virtual void drawChildren(Graphics *const restrict graphics)
170
                                  restrict2 A_NONNULL(2);
171
172
        virtual void safeDrawChildren(Graphics *const restrict graphics)
173
                                      restrict2 A_NONNULL(2);
174
175
        /**
176
          * Calls logic for the children widgets of the basic
177
          * container.
178
          */
179
        virtual void logicChildren() restrict2;
180
181
        /**
182
          * Typedef.
183
          */
184
        typedef STD_VECTOR<Widget *> WidgetList;
185
186
          /**
187
          * Typedef.
188
          */
189
        typedef WidgetList::iterator WidgetListIterator;
190
191
          /**
192
          * Typedef.
193
          */
194
        typedef WidgetList::const_iterator WidgetListConstIterator;
195
196
        /**
197
          * Typedef.
198
          */
199
        typedef WidgetList::reverse_iterator WidgetListReverseIterator;
200
201
        /**
202
          * Typedef.
203
          */
204
        typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator;
205
206
        /**
207
          * Holds all widgets of the basic container.
208
          */
209
        WidgetList mWidgets;
210
211
        WidgetList mLogicWidgets;
212
};
213
214
#endif  // GUI_WIDGETS_BASICCONTAINER_H