Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
dw_simple_container.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2014 Sebastian Geerken <sgeerken@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <math.h>
21
23
24using namespace dw::core;
25using namespace dw::core::style;
26using namespace lout::misc;
27
28namespace dw {
29
31
32// ----------------------------------------------------------------------
33
35(SimpleContainer *simpleContainer, Content::Type mask, bool atEnd) :
36 Iterator (simpleContainer, mask, atEnd)
37{
39}
40
42{
45 getMask(), false);
46 sci->content = content;
47 return sci;
48}
49
51{
52 switch (content.type) {
53 case Content::START:
54 return 0;
56 return 1;
57 case Content::END:
58 return 2;
59 default:
61 return 0;
62 }
63}
64
67{
68 return index () - ((SimpleContainerIterator*)other)->index ();
69}
70
72{
73 SimpleContainer *simpleContainer = (SimpleContainer*)getWidget();
74
75 if (content.type == Content::END)
76 return false;
77
78 // simple containers only contain widgets:
79 if ((getMask() & Content::WIDGET_IN_FLOW) == 0) {
80 content.type = Content::END;
81 return false;
82 }
83
84 if (content.type == Content::START) {
85 if (simpleContainer->child != NULL) {
86 content.type = Content::WIDGET_IN_FLOW;
87 content.widget = simpleContainer->child;
88 return true;
89 } else {
90 content.type = Content::END;
91 return false;
92 }
93 } else /* if (content.type == Content::WIDGET) */ {
94 content.type = Content::END;
95 return false;
96 }
97}
98
100{
101 SimpleContainer *simpleContainer = (SimpleContainer*)getWidget();
102
103 if (content.type == Content::START)
104 return false;
105
106 // simple containers only contain widgets:
107 if ((getMask() & Content::WIDGET_IN_FLOW) == 0) {
108 content.type = Content::START;
109 return false;
110 }
111
112 if (content.type == Content::END) {
113 if (simpleContainer->child != NULL) {
114 content.type = Content::WIDGET_IN_FLOW;
115 content.widget = simpleContainer->child;
116 return true;
117 } else {
118 content.type = Content::START;
119 return false;
120 }
121 } else /* if (content.type == Content::WIDGET) */ {
122 content.type = Content::START;
123 return false;
124 }
125}
126
128 int end,
129 HighlightLayer layer)
130{
132}
133
136 layer)
137{
139}
140
142 int end,
144 *allocation)
145{
147}
148
149// ----------------------------------------------------------------------
150
152{
153 registerName ("dw::SimpleContainer", &CLASS_ID);
154 child = NULL;
155}
156
158{
159 if (child)
160 delete child;
161}
162
164{
165 Requisition childReq;
166 if (child)
167 child->sizeRequest (&childReq);
168 else
169 childReq.width = childReq.ascent = childReq.descent = 0;
170
171 requisition->width = childReq.width + boxDiffWidth ();
172 requisition->ascent = childReq.ascent + boxOffsetY ();
173 requisition->descent = childReq.descent + boxRestHeight ();
174
176}
177
178
180{
181 Extremes childExtr;
182 if (child)
183 child->getExtremes (&childExtr);
184 else
185 childExtr.minWidth = childExtr.minWidthIntrinsic = childExtr.maxWidth =
187
188 extremes->minWidth = childExtr.minWidth + boxDiffWidth ();
190 extremes->maxWidth = childExtr.maxWidth + boxDiffWidth ();
193
195}
196
198{
199 Allocation childAlloc;
200
201 if (child) {
202 childAlloc.x = allocation->x + boxOffsetX ();
203 childAlloc.y = allocation->y + boxOffsetY ();
204 childAlloc.width = allocation->width - boxDiffWidth ();
205 childAlloc.ascent = allocation->ascent - boxOffsetY ();
206 childAlloc.descent = allocation->descent - boxRestHeight ();
207 child->sizeAllocate (&childAlloc);
208 }
209}
210
212 DrawingContext *context)
213{
214 drawWidgetBox (view, area, false);
215 Rectangle childArea;
216 if (child && child->intersects (this, area, &childArea))
217 child->draw (view, &childArea, context);
218}
219
221{
222 return new SimpleContainerIterator (this, mask, atEnd);
223}
224
226{
227 assert (child == this->child);
228 this->child = NULL;
229
230 queueResize (0, true);
231}
232
234{
235 if (this->child)
236 delete this->child;
237
238 this->child = child;
239 if (this->child)
240 this->child->setParent (this);
241
242 queueResize (0, true);
243}
244
245} // namespace dw
bool prev()
Move iterator backward and store content it.
void unhighlight(int direction, core::HighlightLayer layer)
Shrink highlighted region to no longer contain the current content.
void highlight(int start, int end, core::HighlightLayer layer)
Extend highlighted region to contain part of the current content.
int compareTo(lout::object::Comparable *other)
Compare two objects, this and other.
lout::object::Object * clone()
Return an exact copy of the object.
bool next()
Move iterator forward and store content it.
SimpleContainerIterator(SimpleContainer *simpleContainer, core::Content::Type mask, bool atEnd)
void getAllocation(int start, int end, core::Allocation *allocation)
Return the shape, which a part of the item, the iterator points on, allocates.
Simple widget used for testing concepts.
core::Iterator * iterator(core::Content::Type mask, bool atEnd)
Return an iterator for this widget.
void sizeAllocateImpl(core::Allocation *allocation)
See Sizes of Dillo Widgets.
void removeChild(Widget *child)
void getExtremesSimpl(core::Extremes *extremes)
Simple variant, to be implemented by widgets with extremes not depending on positions.
void draw(core::View *view, core::Rectangle *area, core::DrawingContext *context)
Area is given in widget coordinates.
void setChild(core::Widget *child)
void sizeRequestSimpl(core::Requisition *requisition)
Simple variant, to be implemented by widgets with sizes not depending on positions.
Set at the top when drawing.
Definition types.hh:295
Iterators are used to iterate through the contents of a widget.
Definition iterator.hh:20
dw::core::Shape implemtation for simple rectangles.
Definition types.hh:70
An interface to encapsulate platform dependent drawing.
Definition view.hh:17
The base class of all dillo widgets.
Definition widget.hh:44
void sizeAllocate(Allocation *allocation)
Wrapper for Widget::sizeAllocateImpl, calls the latter only when needed.
Definition widget.cc:1209
Extremes extremes
Analogue to dw::core::Widget::requisition.
Definition widget.hh:166
bool intersects(Widget *refWidget, Rectangle *area, Rectangle *intersection)
Calculates the intersection of the visible allocation (i.
Definition widget.cc:151
Allocation allocation
The current allocation: size and position, always relative to the canvas.
Definition widget.hh:204
virtual void draw(View *view, Rectangle *area, DrawingContext *context)=0
Area is given in widget coordinates.
void sizeRequest(Requisition *requisition, int numPos=0, Widget **references=NULL, int *x=NULL, int *y=NULL)
This method is a wrapper for Widget::sizeRequestImpl(); it calls the latter only when needed.
Definition widget.cc:550
int boxDiffWidth()
Definition widget.hh:495
void drawWidgetBox(View *view, Rectangle *area, bool inverse)
Draw borders and background of a widget.
Definition widget.cc:1512
void correctRequisition(Requisition *requisition, void(*splitHeightFun)(int, int *, int *), bool allowDecreaseWidth, bool allowDecreaseHeight)
Definition widget.cc:820
Requisition requisition
Size_request() stores the result of the last call of size_request_impl().
Definition widget.hh:160
void setParent(Widget *parent)
Definition widget.cc:243
int boxRestHeight()
Definition widget.hh:498
void queueResize(int ref, bool extremesChanged, bool fast)
This method should be called, when a widget changes its size.
Definition widget.cc:321
void correctExtremes(Extremes *extremes, bool useAdjustmentWidth)
Definition widget.cc:870
void getExtremes(Extremes *extremes, int numPos=0, Widget **references=NULL, int *x=NULL, int *y=NULL)
Wrapper for Widget::getExtremesImpl().
Definition widget.cc:1093
void registerName(const char *className, int *classId)
This method must be called in the constructor for the sub class.
Definition identity.cc:83
Instances of a sub class of may be compared (less, greater).
Definition object.hh:42
This is the base class for many other classes, which defines very common virtual methods.
Definition object.hh:25
Anything related to Dillo Widget styles is defined here.
Definition style.cc:34
The core of Dw is defined in this namespace.
Definition core.hh:23
HighlightLayer
Definition types.hh:43
void splitHeightPreserveAscent(int height, int *ascent, int *descent)
Definition widget.cc:2244
Dw is in this namespace, or sub namespaces of this one.
Miscellaneous stuff, which does not fit anywhere else.
Definition misc.cc:31
void assertNotReached()
Definition misc.hh:56
Represents the allocation, i.e.
Definition types.hh:164
@ WIDGET_IN_FLOW
widget in normal flow, so that this widget (containing this content) is both container (parent) and g...
Definition types.hh:207