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_animation(this), m_parent(parent ? parent->child() : 0)
10 m_have_background_color = 0;
12 m_client_offset = eSize(0, 0);
19 m_parent->m_childs.push_back(this);
20 m_parent->getStyle(m_style);
27 void eWidget::move(ePoint pos)
29 pos = pos + m_client_offset;
31 if (m_position == pos)
36 event(evtChangedPosition);
37 recalcClipRegionsWhenVisible();
39 /* try native move if supported. */
40 if ((m_vis & wVisShow) && ((!m_desktop) || m_desktop->movedWidget(this)))
44 void eWidget::resize(eSize size)
46 /* same strategy as with move: we first check if
47 the size changed at all, and if it did, we
48 invalidate both the old and new area.
49 TODO: check if either the old or new area
50 fits into the other completely, and invalidate
52 eSize old_size = m_size;
53 eSize old_offset = m_client_offset;
54 m_client_offset = eSize(0, 0);
55 event(evtWillChangeSize, &size, &m_client_offset);
56 if (old_size == m_size)
59 move(position() - old_offset);
62 event(evtChangedSize);
63 recalcClipRegionsWhenVisible();
67 void eWidget::invalidate(const gRegion ®ion)
69 /* we determine the area to redraw, and re-position this
70 area to the absolute position, and then call the
71 desktop's invalidate() with that, which adds this
72 area into the dirty region. */
73 gRegion res = m_visible_with_childs;
81 ePoint abspos = position();
82 while (root && !root->m_desktop)
84 root = root->m_parent;
86 abspos += root->position();
90 // eDebug("region to invalidate:");
92 root->m_desktop->invalidate(res);
102 /* TODO: optimize here to only recalc what's required. possibly merge with hide. */
103 eWidget *root = this;
104 ePoint abspos = position();
105 while (root && !root->m_desktop)
107 root = root->m_parent;
109 abspos += root->position();
112 root->m_desktop->recalcClipRegions(root);
114 gRegion abs = m_visible_with_childs;
116 root->m_desktop->invalidate(abs);
121 /* TODO: when hiding an upper level widget, widgets get hidden but keep the */
122 /* wVisShow flag (because when the widget is shown again, the widgets must */
123 /* become visible again. */
124 if (!(m_vis & wVisShow))
128 /* this is a workaround to the above problem. when we are in the delete phase,
129 don't hide childs. */
130 if (!(m_parent || m_desktop))
133 /* TODO: optimize here to only recalc what's required. possibly merge with show. */
134 eWidget *root = this;
135 ePoint abspos = position();
136 while (root && !root->m_desktop)
138 root = root->m_parent;
139 abspos += root->position();
141 assert(root->m_desktop);
143 gRegion abs = m_visible_with_childs;
146 root->m_desktop->recalcClipRegions(root);
147 root->m_desktop->invalidate(abs);
150 void eWidget::destruct()
153 m_parent->m_childs.remove(this);
157 void eWidget::setBackgroundColor(const gRGB &col)
159 m_background_color = col;
160 m_have_background_color = 1;
163 void eWidget::clearBackgroundColor()
165 m_have_background_color = 0;
168 void eWidget::mayKillFocus()
171 /* when we have the focus, remove it first. */
173 m_focus_owner->setFocus(0);
181 m_parent->m_childs.remove(this);
185 /* destroy all childs */
186 ePtrList<eWidget>::iterator i(m_childs.begin());
187 while (i != m_childs.end())
191 i = m_childs.erase(i);
195 void eWidget::doPaint(gPainter &painter, const gRegion &r)
197 if (m_visible_with_childs.empty())
201 /* we were in parent's space, now we are in local space */
202 region.moveBy(-position());
204 painter.moveOffset(position());
205 /* walk all childs */
206 for (ePtrList<eWidget>::iterator i(m_childs.begin()); i != m_childs.end(); ++i)
207 i->doPaint(painter, region);
209 /* check if there's anything for us to paint */
210 region &= m_visible_region;
214 painter.resetClip(region);
215 event(evtPaint, ®ion, &painter);
218 painter.moveOffset(-position());
221 void eWidget::recalcClipRegionsWhenVisible()
226 if (!(t->m_vis & wVisShow))
230 t->m_desktop->recalcClipRegions(t);
238 int eWidget::event(int event, void *data, void *data2)
244 gPainter &painter = *(gPainter*)data2;
246 // eDebug("eWidget::evtPaint");
247 // dumpRegion(*(gRegion*)data);
248 if (!m_have_background_color)
250 ePtr<eWindowStyle> style;
251 if (!getStyle(style))
252 style->paintBackground(painter, ePoint(0, 0), size());
255 painter.setBackgroundColor(m_background_color);
262 case evtWillChangeSize:
263 m_size = *static_cast<eSize*>(data);
267 m_clip_region = gRegion(eRect(ePoint(0, 0), m_size));
271 m_focus_owner = (eWidget*)data;
282 void eWidget::setFocus(eWidget *focus)
285 m_current_focus->event(evtFocusLost, this);
287 m_current_focus = focus;
290 m_current_focus->event(evtFocusGot, this);