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)
15 parent->m_childs.push_back(this);
18 void eWidget::move(ePoint pos)
22 event(evtChangedPosition);
25 void eWidget::resize(eSize size)
27 event(evtWillChangeSize, &size);
28 event(evtChangedSize);
31 void eWidget::invalidate(const gRegion ®ion)
33 gRegion res = /* region & */ m_visible_with_childs;
38 ePoint abspos = position();
39 while (root && !root->m_desktop)
41 root = root->m_parent;
43 abspos += root->position();
47 // eDebug("region to invalidate:");
49 root->m_desktop->invalidate(res);
59 /* TODO: optimize here to only recalc what's required. possibly merge with hide. */
61 ePoint abspos = position();
62 while (root && !root->m_desktop)
64 root = root->m_parent;
66 abspos += root->position();
69 root->m_desktop->recalcClipRegions();
71 gRegion abs = m_visible_with_childs;
73 root->m_desktop->invalidate(abs);
80 /* TODO: optimize here to only recalc what's required. possibly merge with show. */
82 ePoint abspos = position();
83 while (root && !root->m_desktop)
85 root = root->m_parent;
86 abspos += root->position();
88 assert(root->m_desktop);
90 gRegion abs = m_visible_with_childs;
93 root->m_desktop->recalcClipRegions();
94 root->m_desktop->invalidate(abs);
97 void eWidget::destruct()
100 m_parent->m_childs.remove(this);
106 /* destroy all childs */
107 ePtrList<eWidget>::iterator i(m_childs.begin());
108 while (i != m_childs.end())
111 i = m_childs.erase(i);
115 void eWidget::doPaint(gPainter &painter, const gRegion &r)
117 if (m_visible_with_childs.empty())
121 /* we were in parent's space, now we are in local space */
122 region.moveBy(-position());
124 painter.moveOffset(position());
125 /* walk all childs */
126 for (ePtrList<eWidget>::iterator i(m_childs.begin()); i != m_childs.end(); ++i)
127 i->doPaint(painter, region);
129 /* check if there's anything for us to paint */
130 region &= m_visible_region;
132 painter.resetClip(region);
133 event(evtPaint, ®ion, &painter);
135 painter.moveOffset(-position());
138 int eWidget::event(int event, void *data, void *data2)
144 static int counter = 0x18;
145 gPainter &painter = *(gPainter*)data2;
146 // eDebug("eWidget::evtPaint %d", counter);
147 // dumpRegion(*(gRegion*)data);
148 painter.setBackgroundColor(gColor(++counter));
154 case evtWillChangeSize:
155 m_size = *static_cast<eSize*>(data);
159 m_clip_region = gRegion(eRect(ePoint(0, 0), m_size));