aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSebastian Geerken <devnull@localhost>2013-09-10 21:00:58 +0200
committerSebastian Geerken <devnull@localhost>2013-09-10 21:00:58 +0200
commit06f5833b8f41196bc427c06e39ed21d431c1e665 (patch)
tree17654b3a7449ffdcfae9916fc211d5750789dfad /src
parent6acc9e9c711bad1f9d0125d884b9993ed1c4789e (diff)
Some refactoring: the image decoding code now only accesses dw::core::ImgRenderer, not dw::Image (which now implements the former) anymore.
Diffstat (limited to 'src')
-rw-r--r--src/dicache.c7
-rw-r--r--src/form.cc8
-rw-r--r--src/html.cc25
-rw-r--r--src/image.cc13
-rw-r--r--src/image.hh4
-rw-r--r--src/imgbuf.cc6
-rw-r--r--src/imgbuf.hh2
7 files changed, 41 insertions, 24 deletions
diff --git a/src/dicache.c b/src/dicache.c
index 55232846..673d5907 100644
--- a/src/dicache.c
+++ b/src/dicache.c
@@ -276,7 +276,8 @@ void a_Dicache_set_parms(DilloUrl *url, int version, DilloImage *Image,
/* BUG: there's just one image-type now */
#define I_RGB 0
- DicEntry->v_imgbuf = a_Imgbuf_new(Image->dw, I_RGB, width, height, gamma);
+ DicEntry->v_imgbuf =
+ a_Imgbuf_new(Image->layout, I_RGB, width, height, gamma);
DicEntry->TotalSize = width * height * 3;
DicEntry->width = width;
@@ -402,7 +403,7 @@ static void *Dicache_image(int ImgType, const char *MimeType, void *Ptr,
dReturn_val_if_fail(MimeType && Ptr, NULL);
if (!web->Image) {
- web->Image = a_Image_new(NULL, web->bgColor);
+ web->Image = a_Image_new(NULL, NULL, web->bgColor);
a_Image_ref(web->Image);
}
@@ -429,7 +430,7 @@ static void *Dicache_image(int ImgType, const char *MimeType, void *Ptr,
*Data = DicEntry->DecoderData;
*Call = (CA_Callback_t) a_Dicache_callback;
- return (web->Image->dw);
+ return (web->Image->img_rnd);
}
/*
diff --git a/src/form.cc b/src/form.cc
index f756a1c9..7c747c5a 100644
--- a/src/form.cc
+++ b/src/form.cc
@@ -2004,10 +2004,14 @@ static Embed *Html_input_image(DilloHtml *html, const char *tag, int tagsize)
/* create new image and add it to the button */
a_Html_image_attrs(html, tag, tagsize);
if ((Image = a_Html_image_new(html, tag, tagsize))) {
- IM2DW(Image)->setStyle (html->styleEngine->backgroundStyle ());
+ // At this point, we know that Image->ir represents an image
+ // widget. Notice that the order of the casts matters, because
+ // of multiple inheritance.
+ dw::Image *dwi = (dw::Image*)(dw::core::ImgRenderer*)Image->img_rnd;
+ dwi->setStyle (html->styleEngine->backgroundStyle ());
ResourceFactory *factory = HT2LT(html)->getResourceFactory();
ComplexButtonResource *complex_b_r =
- factory->createComplexButtonResource(IM2DW(Image), false);
+ factory->createComplexButtonResource(dwi, false);
button = new Embed(complex_b_r);
HT2TB(html)->addWidget (button, html->styleEngine->style ());
}
diff --git a/src/html.cc b/src/html.cc
index adfd818e..e8aeb12d 100644
--- a/src/html.cc
+++ b/src/html.cc
@@ -2195,7 +2195,9 @@ DilloImage *a_Html_image_new(DilloHtml *html, const char *tag, int tagsize)
alt_ptr = dStrdup("[IMG]"); // Place holder for img_off mode
}
- image = a_Image_new(alt_ptr, 0);
+ dw::Image *dw = new dw::Image(alt_ptr);
+ image =
+ a_Image_new(html->dw->getLayout(), (void*)(dw::core::ImgRenderer*)dw, 0);
if (HT2TB(html)->getBgColor())
image->bg_color = HT2TB(html)->getBgColor()->getColor();
@@ -2272,11 +2274,15 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
/* TODO: usemap URLs outside of the document are not used. */
usemap_url = a_Html_url_new(html, attrbuf, NULL, 0);
- HT2TB(html)->addWidget((Widget*)Image->dw, html->styleEngine->style());
+ // At this point, we know that Image->ir represents an image
+ // widget. Notice that the order of the casts matters, because of
+ // multiple inheritance.
+ dw::Image *dwi = (dw::Image*)(dw::core::ImgRenderer*)Image->img_rnd;
+ HT2TB(html)->addWidget(dwi, html->styleEngine->style());
/* Image maps */
if (a_Html_get_attr(html, tag, tagsize, "ismap")) {
- ((::dw::Image*)Image->dw)->setIsMap();
+ dwi->setIsMap();
_MSG(" Html_tag_open_img: server-side map (ISMAP)\n");
} else if (html->styleEngine->style ()->x_link != -1 &&
usemap_url == NULL) {
@@ -2286,8 +2292,7 @@ static void Html_tag_content_img(DilloHtml *html, const char *tag, int tagsize)
}
if (usemap_url) {
- ((::dw::Image*)Image->dw)->setUseMap(&html->maps,
- new ::object::String(URL_STR(usemap_url)));
+ dwi->setUseMap(&html->maps, new ::object::String(URL_STR(usemap_url)));
a_Url_free (usemap_url);
}
}
@@ -2330,8 +2335,14 @@ static void Html_tag_close_map(DilloHtml *html)
for (int i = 0; i < html->images->size(); i++) {
DilloImage *img = html->images->get(i)->image;
- if (img)
- ((dw::Image*) img->dw)->forceMapRedraw();
+ if (img) {
+ // At this point, we know that img->ir represents an image
+ // widget. (Really? Is this assumtion safe?) Notice that the
+ // order of the casts matters, because of multiple
+ // inheritance.
+ dw::Image *dwi = (dw::Image*)(dw::core::ImgRenderer*)img->img_rnd;
+ dwi->forceMapRedraw();
+ }
}
html->InFlags &= ~IN_MAP;
}
diff --git a/src/image.cc b/src/image.cc
index c499d977..570c012a 100644
--- a/src/image.cc
+++ b/src/image.cc
@@ -23,19 +23,20 @@
using namespace dw::core;
-// Image to Object-Image macro
-#define I2DW(Image) ((dw::Image*)(Image->dw))
+// Image to Object-ImgRenderer macro
+#define I2IR(Image) ((dw::core::ImgRenderer*)(Image->img_rnd))
/*
* Create and initialize a new image structure.
*/
-DilloImage *a_Image_new(const char *alt_text, int32_t bg_color)
+DilloImage *a_Image_new(void *layout, void *img_rnd, int32_t bg_color)
{
DilloImage *Image;
Image = dNew(DilloImage, 1);
- Image->dw = (void*) new dw::Image(alt_text);
+ Image->layout = layout;
+ Image->img_rnd = img_rnd;
Image->width = 0;
Image->height = 0;
Image->bg_color = bg_color;
@@ -88,7 +89,7 @@ void a_Image_set_parms(DilloImage *Image, void *v_imgbuf, DilloUrl *url,
_MSG("a_Image_set_parms: width=%d height=%d\n", width, height);
bool resize = (Image->width != width || Image->height != height);
- I2DW(Image)->setBuffer((Imgbuf*)v_imgbuf, resize);
+ I2IR(Image)->setBuffer((Imgbuf*)v_imgbuf, resize);
if (!Image->BitVec)
Image->BitVec = a_Bitvec_new(height);
@@ -106,7 +107,7 @@ void a_Image_write(DilloImage *Image, uint_t y)
dReturn_if_fail ( y < Image->height );
/* Update the row in DwImage */
- I2DW(Image)->drawRow(y);
+ I2IR(Image)->drawRow(y);
a_Bitvec_set_bit(Image->BitVec, y);
Image->State = IMG_Write;
}
diff --git a/src/image.hh b/src/image.hh
index a66edaae..80f23461 100644
--- a/src/image.hh
+++ b/src/image.hh
@@ -44,7 +44,7 @@ typedef enum {
} ImageState;
struct _DilloImage {
- void *dw;
+ void *layout, *img_rnd;
/* Parameters as told by image data */
uint_t width;
@@ -62,7 +62,7 @@ struct _DilloImage {
/*
* Function prototypes
*/
-DilloImage *a_Image_new(const char *alt_text, int32_t bg_color);
+DilloImage *a_Image_new(void *layout, void *img_rnd, int32_t bg_color);
void a_Image_ref(DilloImage *Image);
void a_Image_unref(DilloImage *Image);
diff --git a/src/imgbuf.cc b/src/imgbuf.cc
index 16eb5c31..48e6bde5 100644
--- a/src/imgbuf.cc
+++ b/src/imgbuf.cc
@@ -90,10 +90,9 @@ void a_Imgbuf_unref(void *v_imgbuf)
/*
* Create a new Imgbuf
*/
-void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height,
+void *a_Imgbuf_new(void *layout, int img_type, uint_t width, uint_t height,
double gamma)
{
- Layout *layout = ((Widget*)v_dw)->getLayout();
if (!layout) {
MSG_ERR("a_Imgbuf_new: layout is NULL.\n");
exit(1);
@@ -104,7 +103,8 @@ void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height,
linebuf = (uchar_t*) dRealloc(linebuf, linebuf_size);
}
- return (void*)layout->createImgbuf(Imgbuf::RGB, width, height, gamma);
+ return (void*)((Layout*)layout)->createImgbuf(Imgbuf::RGB, width, height,
+ gamma);
}
/*
diff --git a/src/imgbuf.hh b/src/imgbuf.hh
index af0bf9a6..efa1b48c 100644
--- a/src/imgbuf.hh
+++ b/src/imgbuf.hh
@@ -16,7 +16,7 @@ extern "C" {
*/
void a_Imgbuf_ref(void *v_imgbuf);
void a_Imgbuf_unref(void *v_imgbuf);
-void *a_Imgbuf_new(void *v_dw, int img_type, uint_t width, uint_t height,
+void *a_Imgbuf_new(void *v_ir, int img_type, uint_t width, uint_t height,
double gamma);
int a_Imgbuf_last_reference(void *v_imgbuf);
void a_Imgbuf_update(void *v_imgbuf, const uchar_t *buf, DilloImgType type,