1 #include <lib/gui/ewidget.h>
2 #include <lib/gui/ewidgetdesktop.h>
4 extern void dumpRegion(const gRegion ®ion);
6 eWidget::eWidget(eWidget *parent): m_parent(parent ? parent->child() : 0)
10 m_have_background_color = 0;
17 m_parent->m_childs.push_back(this);
18 m_parent->getStyle(m_style);
22 void eWidget::move(ePoint pos)
24 if (m_position == pos)
29 /* we invalidate before and after the move to
30 cause a correct redraw. The area which is
31 included both before and after isn't redrawn
32 twice because a invalidate doesn't immediately
33 redraws the region. */
35 event(evtChangedPosition);
36 recalcClipRegionsWhenVisible();
40 void eWidget::resize(eSize size)
42 /* same strategy as with move: we first check if
43 the size changed at all, and if it did, we
44 invalidate both the old and new area.
45 TODO: check if either the old or new area
46 fits into the other completely, and invalidate
48 eSize old_size = m_size;
49 eSize offset = eSize(0, 0);
50 event(evtWillChangeSize, &size, &offset);
51 if (old_size == m_size)
53 move(position() + offset);
56 event(evtChangedSize);
57 recalcClipRegionsWhenVisible();
61 void eWidget::invalidate(const gRegion ®ion)
63 /* we determine the area to redraw, and re-position this
64 area to the absolute position, and then call the
65 desktop's invalidate() with that, which adds this
66 area into the dirty region. */
67 gRegion res = m_visible_with_childs;
75 ePoint abspos = position();
76 while (root && !root->m_desktop)
78 root = root->m_parent;
80 abspos += root->position();
84 // eDebug("region to invalidate:");
86 root->m_desktop->invalidate(res);
96 /* TODO: optimize here to only recalc what's required. possibly merge with hide. */
98 ePoint abspos = position();
99 while (root && !root->m_desktop)
101 root = root->m_parent;
103 abspos += root->position();
106 root->m_desktop->recalcClipRegions();
108 gRegion abs = m_visible_with_childs;
110 root->m_desktop->invalidate(abs);
115 /* TODO: when hiding an upper level widget, widgets get hidden but keep the */
116 /* wVisShow flag (because when the widget is shown again, the widgets must */
117 /* become visible again. */
118 if (!(m_vis & wVisShow))
122 /* this is a workaround to the above problem. when we are in the delete phase,
123 don't hide childs. */
124 if (!(m_parent || m_desktop))
127 /* TODO: optimize here to only recalc what's required. possibly merge with show. */
128 eWidget *root = this;
129 ePoint abspos = position();
130 while (root && !root->m_desktop)
132 root = root->m_parent;
133 abspos += root->position();
135 assert(root->m_desktop);
137 gRegion abs = m_visible_with_childs;
140 root->m_desktop->recalcClipRegions();
141 root->m_desktop->invalidate(abs);
144 void eWidget::destruct()
147 m_parent->m_childs.remove(this);
151 void eWidget::setBackgroundColor(const gRGB &col)
153 eDebug("set background color in ewidget!");
154 m_background_color = col;
155 m_have_background_color = 1;
163 m_parent->m_childs.remove(this);
167 /* destroy all childs */
168 ePtrList<eWidget>::iterator i(m_childs.begin());
169 while (i != m_childs.end())
173 i = m_childs.erase(i);
177 void eWidget::doPaint(gPainter &painter, const gRegion &r)
179 if (m_visible_with_childs.empty())
183 /* we were in parent's space, now we are in local space */
184 region.moveBy(-position());
186 painter.moveOffset(position());
187 /* walk all childs */
188 for (ePtrList<eWidget>::iterator i(m_childs.begin()); i != m_childs.end(); ++i)
189 i->doPaint(painter, region);
191 /* check if there's anything for us to paint */
192 region &= m_visible_region;
196 painter.resetClip(region);
197 event(evtPaint, ®ion, &painter);
200 painter.moveOffset(-position());
203 void eWidget::recalcClipRegionsWhenVisible()
208 if (!(t->m_vis & wVisShow))
212 t->m_desktop->recalcClipRegions();
220 int eWidget::event(int event, void *data, void *data2)
226 gPainter &painter = *(gPainter*)data2;
228 // eDebug("eWidget::evtPaint");
229 // dumpRegion(*(gRegion*)data);
230 if (!m_have_background_color)
232 ePtr<eWindowStyle> style;
233 if (!getStyle(style))
234 style->paintBackground(painter, ePoint(0, 0), size());
237 painter.setBackgroundColor(m_background_color);
244 case evtWillChangeSize:
245 m_size = *static_cast<eSize*>(data);
249 m_clip_region = gRegion(eRect(ePoint(0, 0), m_size));