26#include "../lout/msg.h"
27#include "../lout/misc.hh"
28#include "../lout/debug.hh"
42 delete shapesAndLinks;
48 container::typed::Iterator <ShapeAndLink> it;
50 for (it = shapesAndLinks->iterator (); it.
hasNext (); ) {
53 shapeAndLink->
shape->
draw(view, style, x, y);
59 shapeAndLink->
shape = shape;
61 shapesAndLinks->append (shapeAndLink);
65 container::typed::Iterator <ShapeAndLink> it;
66 int link = defaultLink;
68 for (it = shapesAndLinks->iterator (); it.
hasNext (); ) {
82 imageMaps =
new container::typed::HashTable <object::Object, ImageMap>
130 map->
draw(view, style, x, y);
151 registerName (
"dw::Image", &CLASS_ID);
152 this->altText = altText ?
dStrdup (altText) : NULL;
155 bufWidth = bufHeight = -1;
162 this->markEmpty = markEmpty;
179 savedStyle->unref ();
190 DEBUG_MSG(1,
"-- Image::sizeRequestSimpl() begins\n");
192 DEBUG_MSG(1,
"Image::sizeRequestImpl border: w=%d h=%d\n",
193 boxDiffWidth(), boxDiffHeight());
200 setStyle(savedStyle);
202 requisition->
width = buffer->getRootWidth ();
203 requisition->
ascent = buffer->getRootHeight ();
206 if (markEmpty && !useAltStyle) {
207 savedStyle = getStyle();
219 if (altText && altText[0]) {
220 if (altTextWidth == -1)
222 layout->textWidth (getStyle()->font, altText, strlen (altText));
224 requisition->
width = altTextWidth;
225 requisition->
ascent = getStyle()->font->ascent;
226 requisition->
descent = getStyle()->font->descent;
228 requisition->
width = 0;
234 requisition->
width += boxDiffWidth ();
235 requisition->
ascent += boxOffsetY ();
236 requisition->
descent += boxRestHeight ();
238 DEBUG_MSG(1,
"Image: initial requisition (with border): w=%d, h=%d\n",
248 DEBUG_MSG(1,
"Image: corrected requisition: w=%d, h=%d\n",
260 contentWidth = buffer->getRootWidth ();
262 if (altText && altText[0]) {
263 if (altTextWidth == -1)
265 layout->textWidth (getStyle()->font, altText, strlen (altText));
266 contentWidth = altTextWidth;
271 int width = contentWidth + boxDiffWidth ();
283 correctExtremes (extremes,
false);
291 DBG_OBJ_ENTER (
"resize", 0,
"sizeAllocateImpl",
"%d, %d; %d * (%d + %d)",
292 allocation->
x, allocation->
y, allocation->
width,
295 DEBUG_MSG(1,
"Image::sizeAllocateImpl x=%d y=%d w=%d h=(%d + %d)\n",
296 allocation->
x, allocation->
y, allocation->
width,
299 DEBUG_MSG(1,
"Image::sizeAllocateImpl border: w=%d h=%d\n",
300 boxDiffWidth(), boxDiffHeight());
303 int newBufWidth = allocation->
width - boxDiffWidth ();
307 if (buffer && newBufWidth > 0 && newBufHeight > 0 &&
309 (newBufWidth != bufWidth || newBufHeight != bufHeight)) {
312 DEBUG_MSG(1,
"Image::sizeAllocateImpl new buffer size: w=%d h=%d\n",
313 newBufWidth, newBufHeight);
316 buffer = oldBuffer->
getScaledBuf (newBufWidth, newBufHeight);
319 bufWidth = newBufWidth;
320 bufHeight = newBufHeight;
327 DEBUG_MSG(1,
"Image::sizeAllocateImpl x=%d y=%d w=%d h=(%d + %d)\n",
328 allocation->
x, allocation->
y, allocation->
width,
344 currLink = getStyle()->x_link;
346 if (currLink != -1) {
347 (void)
layout->emitLinkEnter (
this, currLink, -1, -1, -1);
349 Widget::enterNotifyImpl(event);
356 if (currLink != -1) {
358 (void)
layout->emitLinkEnter (
this, -1, -1, -1, -1);
360 Widget::leaveNotifyImpl(event);
370 int ret =
event->xWidget - boxOffsetX();
378 int ret =
event->yWidget - boxOffsetY();
386 if (mapList || isMap) {
387 int x = contentX(event);
388 int y = contentY(event);
392 int newLink = mapList->link (mapKey, x, y);
393 if (newLink != currLink) {
397 setCursor(newLink == -1 ? getStyle()->cursor :
399 (void)
layout->emitLinkEnter (
this, newLink, -1, -1, -1);
401 }
else if (isMap && currLink != -1) {
403 (void)
layout->emitLinkEnter (
this, currLink, -1, x, y);
413 currLink = mapList ? mapList->link(mapKey,contentX(event),contentY(event)) :
416 (void)
layout->emitLinkPress(
this, currLink, getStyle()->x_img, -1, -1,
419 }
else if (event->
button == 1 || currLink != -1){
428 currLink = mapList ? mapList->link(mapKey,contentX(event),contentY(event)) :
431 int x = isMap ? contentX(event) : -1;
432 int y = isMap ? contentY(event) : -1;
434 layout->emitLinkClick (
this, currLink, getStyle()->x_img, x, y, event);
446 drawWidgetBox (view, area,
false);
453 content.
width = getContentWidth ();
454 content.
height = getContentHeight ();
458 allocation.x + dx, allocation.y + dy,
459 intersection.
x - dx, intersection.
y - dy,
464 if (altText && altText[0]) {
469 if (altTextWidth == -1)
471 layout->textWidth (getStyle()->font, altText, strlen (altText));
473 if ((getContentWidth() < altTextWidth) ||
474 (getContentHeight() <
475 getStyle()->font->ascent + getStyle()->font->descent)) {
476 clippingView = usedView =
478 allocation.y + boxOffsetY (),
485 allocation.x + boxOffsetX (),
486 allocation.y + boxOffsetY (),
487 getContentWidth(), getContentHeight(), altText);
494 allocation.y + boxOffsetY (),
497 mapList->drawMap(mapKey, clippingView, getStyle(),
498 allocation.x + boxOffsetX (),
499 allocation.y + boxOffsetY ());
518 if (wasAllocated () && needsResize () &&
519 getContentWidth () > 0 && getContentHeight () > 0) {
523 bufWidth = getContentWidth ();
524 bufHeight = getContentHeight ();
525 this->buffer = buffer->
getScaledBuf (bufWidth, bufHeight);
527 this->buffer = buffer;
532 queueResize (0,
true);
535 this->ratio = (float) bufWidth / (
float) bufHeight;
549 assert (buffer != NULL);
551 buffer->getRowArea (row, &area);
553 queueDrawArea (area.
x + boxOffsetX (), area.
y + boxOffsetY (), area.
width,
587 if (mapKey && mapKey != key)
void setDefaultLink(int link)
void add(core::Shape *shape, int link)
void draw(core::View *view, core::style::Style *style, int x, int y)
lout::container::typed::List< ShapeAndLink > * shapesAndLinks
Represents a list of client-side image maps.
void drawMap(lout::object::Object *key, core::View *view, core::style::Style *style, int x, int y)
void addShapeToCurrentMap(core::Shape *shape, int link)
Add a shape to the current map-.
void startNewMap(lout::object::Object *key)
Start a new map and make it the current one.
lout::container::typed::HashTable< lout::object::Object, ImageMap > * imageMaps
void setCurrentMapDefaultLink(int link)
Set default link for current map-.
int link(lout::object::Object *key, int x, int y)
Image(const char *altText, bool markEmpty=false)
void setIsMap()
Sets image as server side image map.
void setUseMap(ImageMapsList *list, Object *key)
Sets image as client side image map.
core::Iterator * iterator(core::Content::Type mask, bool atEnd)
Return an iterator for this widget.
int contentY(core::MousePositionEvent *event)
void finish()
Called, when all image data has been retrieved.
void drawRow(int row)
Called, when data from a row is available and has been copied into the image buffer.
void sizeAllocateImpl(core::Allocation *allocation)
See Sizes of Dillo Widgets.
bool buttonReleaseImpl(core::EventButton *event)
void sizeRequestSimpl(core::Requisition *requisition)
Simple variant, to be implemented by widgets with sizes not depending on positions.
void containerSizeChangedForChildren()
bool buttonPressImpl(core::EventButton *event)
void fatal()
Called, when there are problems with the retrieval of image data.
int contentX(core::MousePositionEvent *event)
void getExtremesSimpl(core::Extremes *extremes)
Simple variant, to be implemented by widgets with extremes not depending on positions.
void setBuffer(core::Imgbuf *buffer, bool resize=false)
Called, when an image buffer is attached.
void enterNotifyImpl(core::EventCrossing *event)
void leaveNotifyImpl(core::EventCrossing *event)
bool motionNotifyImpl(core::EventMotion *event)
void draw(core::View *view, core::Rectangle *area, core::DrawingContext *context)
Area is given in widget coordinates.
Set at the top when drawing.
This implementation of dw::core::Iterator can be used by widgets with no contents.
Represents a enter or leave notify event.
Represents a mouse motion event.
The platform independent interface for image buffers.
virtual int getRootWidth()=0
virtual Imgbuf * getScaledBuf(int width, int height)=0
virtual int getRootHeight()=0
Iterators are used to iterate through the contents of a widget.
Base class for all mouse events related to a specific position.
dw::core::Shape implementation for simple rectangles.
bool intersectsWith(Rectangle *otherRect, Rectangle *dest)
Return whether this rectangle and otherRect intersect.
Abstract interface for different shapes.
virtual bool isPointWithin(int x, int y)=0
virtual void draw(core::View *view, core::style::Style *style, int x, int y)=0
An interface to encapsulate platform dependent drawing.
virtual void mergeClippingView(View *clippingView)=0
virtual void drawImage(Imgbuf *imgbuf, int xRoot, int yRoot, int x, int y, int width, int height)=0
virtual void drawSimpleWrappedText(style::Font *font, style::Color *color, style::Color::Shading shading, int x, int y, int w, int h, const char *text)=0
virtual View * getClippingView(int x, int y, int width, int height)=0
void setBorderStyle(BorderStyle val)
void setBorderColor(Color *val)
static Style * create(StyleAttrs *attrs)
This is the base class for many other classes, which defines very common virtual methods.
#define DEBUG_MSG(level,...)
#define DBG_OBJ_ENTER0(aspect, prio, funname)
#define DBG_OBJ_CREATE(klass)
#define DBG_OBJ_MSGF(aspect, prio, fmt,...)
#define DBG_OBJ_SET_NUM(var, val)
#define DBG_OBJ_MSG(aspect, prio, msg)
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt,...)
#define DBG_OBJ_ASSOC_CHILD(child)
char * dStrdup(const char *s)
bool isPerLength(Length l)
Returns true if l is a percentage.
void splitHeightPreserveDescent(int height, int *ascent, int *descent)
Dw is in this namespace, or sub namespaces of this one.
The DilloImage data-structure and methods.
Represents the allocation, i.e.