24 #include "../lout/msg.h" 25 #include "../lout/debug.hh" 35 bool Widget::WidgetImgRenderer::readyToDraw ()
37 return widget->wasAllocated ();
40 void Widget::WidgetImgRenderer::getBgArea (
int *x,
int *y,
int *width,
43 widget->getPaddingArea (x, y, width, height);
46 void Widget::WidgetImgRenderer::getRefArea (
int *xRef,
int *yRef,
int *widthRef,
49 widget->getPaddingArea (xRef, yRef, widthRef, heightRef);
54 return widget->getStyle ();
57 void Widget::WidgetImgRenderer::draw (
int x,
int y,
int width,
int height)
59 widget->queueDrawArea (x - widget->allocation.x, y - widget->allocation.y,
65 int Widget::CLASS_ID = -1;
70 registerName (
"dw::core::Widget", &CLASS_ID);
72 flags = (
Flags)(NEEDS_RESIZE | EXTREMES_CHANGED | HAS_CONTENTS);
79 allocation.ascent = 1;
80 allocation.descent = 0;
84 buttonSensitive =
true;
85 buttonSensitiveSet =
false;
87 deleteCallbackData = NULL;
88 deleteCallbackFunc = NULL;
90 widgetImgRenderer = NULL;
95 if (deleteCallbackFunc)
96 deleteCallbackFunc (deleteCallbackData);
98 if (widgetImgRenderer) {
99 if (style && style->backgroundImage)
100 style->backgroundImage->removeExternalImgRenderer (widgetImgRenderer);
101 delete widgetImgRenderer;
108 parent->removeChild (
this);
110 layout->removeWidget ();
128 parentArea.
x += parent->allocation.x;
129 parentArea.
y += parent->allocation.y;
131 childArea.
x = allocation.x;
132 childArea.
y = allocation.y;
133 childArea.
width = allocation.width;
134 childArea.
height = getHeight ();
137 intersection->
x -= allocation.x;
138 intersection->
y -= allocation.y;
146 this->parent = parent;
149 if (!buttonSensitiveSet)
158 void Widget::queueDrawArea (
int x,
int y,
int width,
int height)
161 layout->queueDraw (x + allocation.x, y + allocation.y, width, height);
162 _MSG(
"Widget::queueDrawArea alloc(%d %d %d %d) wid(%d %d %d %d)\n",
163 allocation.x, allocation.y,
164 allocation.width, allocation.ascent + allocation.descent,
165 x, y, width, height);
171 void Widget::queueResize (
int ref,
bool extremesChanged)
178 setFlags (NEEDS_RESIZE);
179 setFlags (NEEDS_ALLOCATE);
180 markSizeChange (ref);
182 if (extremesChanged) {
183 setFlags (EXTREMES_CHANGED);
184 markExtremesChange (ref);
187 for (widget2 = parent, child =
this;
189 child = widget2, widget2 = widget2->
parent) {
190 widget2->setFlags (NEEDS_RESIZE);
191 widget2->markSizeChange (child->
parentRef);
192 widget2->setFlags (NEEDS_ALLOCATE);
199 if (extremesChanged) {
200 widget2->setFlags (EXTREMES_CHANGED);
201 widget2->markExtremesChange (child->
parentRef);
206 layout->queueResize ();
216 if (needsResize ()) {
218 sizeRequestImpl (requisition);
219 this->requisition = *requisition;
220 unsetFlags (NEEDS_RESIZE);
226 *requisition = this->requisition;
234 if (extremesChanged ()) {
235 getExtremesImpl (extremes);
236 this->extremes = *extremes;
237 unsetFlags (EXTREMES_CHANGED);
242 *extremes = this->extremes;
251 if (needsAllocate () ||
252 allocation->
x != this->allocation.x ||
253 allocation->
y != this->allocation.y ||
254 allocation->
width != this->allocation.width ||
255 allocation->
ascent != this->allocation.ascent ||
256 allocation->
descent != this->allocation.descent) {
258 if (wasAllocated ()) {
259 layout->queueDrawExcept (
262 this->allocation.width,
263 this->allocation.ascent + this->allocation.descent,
270 sizeAllocateImpl (allocation);
277 this->allocation = *allocation;
278 unsetFlags (NEEDS_ALLOCATE);
279 setFlags (WAS_ALLOCATED);
295 return buttonPressImpl (event);
300 return buttonReleaseImpl (event);
305 return motionNotifyImpl (event);
310 enterNotifyImpl (event);
315 leaveNotifyImpl (event);
336 sizeChanged = this->style->
sizeDiffs (style);
337 this->style->
unref ();
349 if (widgetImgRenderer == NULL)
354 if (layout != NULL) {
355 layout->updateCursor ();
359 queueResize (0,
true);
371 this->bgColor = bgColor;
381 while (widget != NULL) {
401 int x,
int y,
int width,
int height,
bool inverse)
404 canvasArea.
x = area->
x + allocation.x;
405 canvasArea.
y = area->
y + allocation.y;
410 allocation.
x + x, allocation.y + y,
411 width, height, style, inverse);
417 int xPad, yPad, widthPad, heightPad;
418 getPaddingArea (&xPad, &yPad, &widthPad, &heightPad);
420 (view, layout, &canvasArea,
427 xPad, yPad, widthPad, heightPad, style, inverse,
false);
439 canvasArea.
x = area->
x + allocation.x;
440 canvasArea.
y = area->
y + allocation.y;
445 allocation.width, getHeight (), style, inverse);
447 int xPad, yPad, widthPad, heightPad;
448 getPaddingArea (&xPad, &yPad, &widthPad, &heightPad);
450 xPad, yPad, widthPad, heightPad,
451 xPad, yPad, widthPad, heightPad,
452 style, inverse, parent == NULL);
474 void Widget::setButtonSensitive (
bool buttonSensitive)
476 this->buttonSensitive = buttonSensitive;
477 buttonSensitiveSet =
true;
499 int Widget::getLevel ()
518 Widget *widget1 =
this, *widget2 = otherWidget;
519 int level1 = widget1->
getLevel (), level2 = widget2->getLevel();
522 while (level1 > level2) {
523 widget1 = widget1->
parent;
527 while (level2 > level1) {
528 widget2 = widget2->
parent;
533 while (widget1 != widget2) {
534 if (widget1->
parent == NULL) {
535 MSG_WARN(
"widgets in different trees\n");
539 widget1 = widget1->
parent;
540 widget2 = widget2->
parent;
552 Widget *Widget::getWidgetAtPoint (
int x,
int y,
int level)
561 if (x >= allocation.x &&
563 x <= allocation.x + allocation.width &&
564 y <= allocation.y + getHeight ()) {
572 it = iterator (Content::WIDGET,
false);
574 while (childAtPoint == NULL && it->
next ())
590 int x,
int y,
int width,
int height)
593 x + allocation.x, y + allocation.y, width, height);
602 void Widget::getPaddingArea (
int *xPad,
int *yPad,
int *widthPad,
605 *xPad = allocation.x + style->margin.left + style->borderWidth.left;
606 *yPad = allocation.y + style->margin.top + style->borderWidth.top;
607 *widthPad = allocation.width - style->margin.left - style->borderWidth.left
608 - style->margin.right - style->borderWidth.right;
609 *heightPad = getHeight () - style->margin.top - style->borderWidth.top
610 - style->margin.bottom - style->borderWidth.bottom;
617 sizeRequest (&requisition);
625 void Widget::markSizeChange (
int ref)
629 void Widget::markExtremesChange (
int ref)
633 void Widget::setWidth (
int width)
637 void Widget::setAscent (
int ascent)
641 void Widget::setDescent (
int descent)