diff options
Diffstat (limited to 'dw/widget.cc')
-rw-r--r-- | dw/widget.cc | 136 |
1 files changed, 102 insertions, 34 deletions
diff --git a/dw/widget.cc b/dw/widget.cc index 9c6fe380..415da6bc 100644 --- a/dw/widget.cc +++ b/dw/widget.cc @@ -32,6 +32,36 @@ namespace core { // ---------------------------------------------------------------------- +bool Widget::WidgetImgRenderer::readyToDraw () +{ + return widget->wasAllocated (); +} + +void Widget::WidgetImgRenderer::getBgArea (int *x, int *y, int *width, + int *height) +{ + widget->getPaddingArea (x, y, width, height); +} + +void Widget::WidgetImgRenderer::getRefArea (int *xRef, int *yRef, int *widthRef, + int *heightRef) +{ + widget->getPaddingArea (xRef, yRef, widthRef, heightRef); +} + +style::Style *Widget::WidgetImgRenderer::getStyle () +{ + return widget->getStyle (); +} + +void Widget::WidgetImgRenderer::draw (int x, int y, int width, int height) +{ + widget->queueDrawArea (x - widget->allocation.x, y - widget->allocation.y, + width, height); +} + +// ---------------------------------------------------------------------- + int Widget::CLASS_ID = -1; Widget::Widget () @@ -55,6 +85,8 @@ Widget::Widget () deleteCallbackData = NULL; deleteCallbackFunc = NULL; + + widgetImgRenderer = NULL; } Widget::~Widget () @@ -62,6 +94,12 @@ Widget::~Widget () if (deleteCallbackFunc) deleteCallbackFunc (deleteCallbackData); + if (widgetImgRenderer) { + if (style && style->backgroundImage) + style->backgroundImage->removeExternalImgRenderer (widgetImgRenderer); + delete widgetImgRenderer; + } + if (style) style->unref (); @@ -281,6 +319,10 @@ void Widget::setStyle (style::Style *style) { bool sizeChanged; + if (widgetImgRenderer && this->style && this->style->backgroundImage) + this->style->backgroundImage->removeExternalImgRenderer + (widgetImgRenderer); + style->ref (); if (this->style) { @@ -291,6 +333,15 @@ void Widget::setStyle (style::Style *style) this->style = style; + if (style && style->backgroundImage) { + // Create instance of WidgetImgRenderer when needed. Until this + // widget is deleted, "widgetImgRenderer" will be kept, since it + // is not specific to the style, but only to this widget. + if (widgetImgRenderer == NULL) + widgetImgRenderer = new WidgetImgRenderer (this); + style->backgroundImage->putExternalImgRenderer (widgetImgRenderer); + } + if (layout != NULL) { layout->updateCursor (); } @@ -340,20 +391,31 @@ style::Color *Widget::getBgColor () void Widget::drawBox (View *view, style::Style *style, Rectangle *area, int x, int y, int width, int height, bool inverse) { - Rectangle viewArea; - viewArea.x = area->x + allocation.x; - viewArea.y = area->y + allocation.y; - viewArea.width = area->width; - viewArea.height = area->height; + Rectangle canvasArea; + canvasArea.x = area->x + allocation.x; + canvasArea.y = area->y + allocation.y; + canvasArea.width = area->width; + canvasArea.height = area->height; - style::drawBorder (view, &viewArea, allocation.x + x, allocation.y + y, + style::drawBorder (view, layout, &canvasArea, + allocation.x + x, allocation.y + y, width, height, style, inverse); - /** \todo Background images? */ - if (style->backgroundColor) - style::drawBackground (view, &viewArea, - allocation.x + x, allocation.y + y, width, height, - style, inverse); + // This method is used for inline elements, where the CSS 2 specification + // does not define what here is called "reference area". To make it look + // smoothly, the widget padding box is used. + + int xPad, yPad, widthPad, heightPad; + getPaddingArea (&xPad, &yPad, &widthPad, &heightPad); + style::drawBackground + (view, layout, &canvasArea, + allocation.x + x + style->margin.left + style->borderWidth.left, + allocation.y + y + style->margin.top + style->borderWidth.top, + width - style->margin.left - style->borderWidth.left + - style->margin.right - style->borderWidth.right, + height - style->margin.top - style->borderWidth.top + - style->margin.bottom - style->borderWidth.bottom, + xPad, yPad, widthPad, heightPad, style, inverse, false); } /** @@ -364,32 +426,21 @@ void Widget::drawBox (View *view, style::Style *style, Rectangle *area, */ void Widget::drawWidgetBox (View *view, Rectangle *area, bool inverse) { - Rectangle viewArea; - viewArea.x = area->x + allocation.x; - viewArea.y = area->y + allocation.y; - viewArea.width = area->width; - viewArea.height = area->height; + Rectangle canvasArea; + canvasArea.x = area->x + allocation.x; + canvasArea.y = area->y + allocation.y; + canvasArea.width = area->width; + canvasArea.height = area->height; - style::drawBorder (view, &viewArea, allocation.x, allocation.y, + style::drawBorder (view, layout, &canvasArea, allocation.x, allocation.y, allocation.width, getHeight (), style, inverse); - /** \todo Adjust following comment from the old dw sources. */ - /* - * - Toplevel widget background colors are set as viewport - * background color. This is not crucial for the rendering, but - * looks a bit nicer when scrolling. Furthermore, the viewport - * does anything else in this case. - * - * - Since widgets are always drawn from top to bottom, it is - * *not* necessary to draw the background if - * widget->style->background_color is NULL (shining through). - */ - /** \todo Background images? */ - - if (style->backgroundColor && - (parent || layout->getBgColor () != style->backgroundColor)) - style::drawBackground (view, &viewArea, allocation.x, allocation.y, - allocation.width, getHeight (), style, inverse); + int xPad, yPad, widthPad, heightPad; + getPaddingArea (&xPad, &yPad, &widthPad, &heightPad); + style::drawBackground (view, layout, &canvasArea, + xPad, yPad, widthPad, heightPad, + xPad, yPad, widthPad, heightPad, + style, inverse, parent == NULL); } /* @@ -533,6 +584,23 @@ void Widget::scrollTo (HPosition hpos, VPosition vpos, x + allocation.x, y + allocation.y, width, height); } +/** + * \brief Return the padding area (content plus padding). + * + * Used as "reference area" (ee comment of "style::drawBackground") + * for backgrounds. + */ +void Widget::getPaddingArea (int *xPad, int *yPad, int *widthPad, + int *heightPad) +{ + *xPad = allocation.x + style->margin.left + style->borderWidth.left; + *yPad = allocation.y + style->margin.top + style->borderWidth.top; + *widthPad = allocation.width - style->margin.left - style->borderWidth.left + - style->margin.right - style->borderWidth.right; + *heightPad = getHeight () - style->margin.top - style->borderWidth.top + - style->margin.bottom - style->borderWidth.bottom; +} + void Widget::getExtremesImpl (Extremes *extremes) { /* Simply return the requisition width */ |