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

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