Plumb some ownership around.
This commit is contained in:
15
dw/image.cc
15
dw/image.cc
@ -31,8 +31,8 @@ namespace dw {
|
|||||||
|
|
||||||
using namespace lout;
|
using namespace lout;
|
||||||
|
|
||||||
void ImageMapsList::ImageMap::draw (core::View *view,core::style::Style *style,
|
void
|
||||||
int x, int y)
|
ImageMapsList::ImageMap::draw( core::View *view, core::style::Style *style, int x, int y )
|
||||||
{
|
{
|
||||||
for( auto &shapeAndLink: shapesAndLinks )
|
for( auto &shapeAndLink: shapesAndLinks )
|
||||||
{
|
{
|
||||||
@ -40,9 +40,11 @@ void ImageMapsList::ImageMap::draw (core::View *view,core::style::Style *style,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageMapsList::ImageMap::add (core::Shape *shape, int link) {
|
void
|
||||||
|
ImageMapsList::ImageMap::add( std::unique_ptr< core::Shape > shape, int link )
|
||||||
|
{
|
||||||
auto shapeAndLink = std::make_unique< ShapeAndLink >();
|
auto shapeAndLink = std::make_unique< ShapeAndLink >();
|
||||||
shapeAndLink->shape = shape;
|
shapeAndLink->shape = std::move( shape );
|
||||||
shapeAndLink->link = link;
|
shapeAndLink->link = link;
|
||||||
shapesAndLinks.push_back( std::move( shapeAndLink ) );
|
shapesAndLinks.push_back( std::move( shapeAndLink ) );
|
||||||
}
|
}
|
||||||
@ -93,9 +95,10 @@ void ImageMapsList::startNewMap (object::Object *key)
|
|||||||
* "shape" is owned by the image map list, so a copy should be passed, when
|
* "shape" is owned by the image map list, so a copy should be passed, when
|
||||||
* necessary.
|
* necessary.
|
||||||
*/
|
*/
|
||||||
void ImageMapsList::addShapeToCurrentMap (core::Shape *shape, int link)
|
void
|
||||||
|
ImageMapsList::addShapeToCurrentMap( std::unique_ptr< core::Shape > shape, const int link )
|
||||||
{
|
{
|
||||||
currentMap->add (shape, link);
|
currentMap->add( std::move( shape ), link );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -27,10 +27,8 @@ private:
|
|||||||
private:
|
private:
|
||||||
class ShapeAndLink: public lout::object::Object {
|
class ShapeAndLink: public lout::object::Object {
|
||||||
public:
|
public:
|
||||||
core::Shape *shape;
|
std::unique_ptr< core::Shape > shape;
|
||||||
int link;
|
int link;
|
||||||
|
|
||||||
~ShapeAndLink () { if (shape) delete shape; };
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::list< std::unique_ptr< ShapeAndLink > > shapesAndLinks;
|
std::list< std::unique_ptr< ShapeAndLink > > shapesAndLinks;
|
||||||
@ -38,7 +36,7 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void draw (core::View *view, core::style::Style *style, int x, int y);
|
void draw (core::View *view, core::style::Style *style, int x, int y);
|
||||||
void add (core::Shape *shape, int link);
|
void add (std::unique_ptr< core::Shape > shape, int link);
|
||||||
void setDefaultLink (int link) { defaultLink = link; };
|
void setDefaultLink (int link) { defaultLink = link; };
|
||||||
int link (int x, int y);
|
int link (int x, int y);
|
||||||
};
|
};
|
||||||
@ -52,7 +50,7 @@ public:
|
|||||||
~ImageMapsList ();
|
~ImageMapsList ();
|
||||||
|
|
||||||
void startNewMap (lout::object::Object *key);
|
void startNewMap (lout::object::Object *key);
|
||||||
void addShapeToCurrentMap (core::Shape *shape, int link);
|
void addShapeToCurrentMap( std::unique_ptr< core::Shape > shape, int link );
|
||||||
void setCurrentMapDefaultLink (int link);
|
void setCurrentMapDefaultLink (int link);
|
||||||
void drawMap(lout::object::Object *key, core::View *view,
|
void drawMap(lout::object::Object *key, core::View *view,
|
||||||
core::style::Style *style, int x, int y);
|
core::style::Style *style, int x, int y);
|
||||||
|
|||||||
15
src/html.cc
15
src/html.cc
@ -2346,7 +2346,7 @@ static void
|
|||||||
DilloUrl* url;
|
DilloUrl* url;
|
||||||
const char *attrbuf;
|
const char *attrbuf;
|
||||||
int link = -1;
|
int link = -1;
|
||||||
Shape *shape = NULL;
|
std::unique_ptr< Shape > shape;
|
||||||
|
|
||||||
if (!(html->InFlags & IN_MAP)) {
|
if (!(html->InFlags & IN_MAP)) {
|
||||||
BUG_MSG("<area> not inside <map>.");
|
BUG_MSG("<area> not inside <map>.");
|
||||||
@ -2376,7 +2376,7 @@ static void
|
|||||||
if (coords->size() != 4)
|
if (coords->size() != 4)
|
||||||
BUG_MSG("<area> rectangle must have four coordinate values.");
|
BUG_MSG("<area> rectangle must have four coordinate values.");
|
||||||
if (coords->size() >= 4)
|
if (coords->size() >= 4)
|
||||||
shape = new Rectangle(coords->get(0),
|
shape = std::make_unique< Rectangle >(coords->get(0),
|
||||||
coords->get(1),
|
coords->get(1),
|
||||||
coords->get(2) - coords->get(0),
|
coords->get(2) - coords->get(0),
|
||||||
coords->get(3) - coords->get(1));
|
coords->get(3) - coords->get(1));
|
||||||
@ -2384,21 +2384,22 @@ static void
|
|||||||
if (coords->size() != 3)
|
if (coords->size() != 3)
|
||||||
BUG_MSG("<area> circle must have three coordinate values.");
|
BUG_MSG("<area> circle must have three coordinate values.");
|
||||||
if (coords->size() >= 3)
|
if (coords->size() >= 3)
|
||||||
shape = new Circle(coords->get(0), coords->get(1),
|
shape = std::make_unique< Circle >(coords->get(0), coords->get(1),
|
||||||
coords->get(2));
|
coords->get(2));
|
||||||
} else if (type == POLYGON) {
|
} else if (type == POLYGON) {
|
||||||
Polygon *poly;
|
std::unique_ptr< Polygon > poly;
|
||||||
int i;
|
int i;
|
||||||
if (coords->size() % 2)
|
if (coords->size() % 2)
|
||||||
BUG_MSG("<area> polygon with odd number of coordinates.");
|
BUG_MSG("<area> polygon with odd number of coordinates.");
|
||||||
shape = poly = new Polygon();
|
poly = std::make_unique< Polygon >();
|
||||||
for (i = 0; i < (coords->size() / 2); i++)
|
for (i = 0; i < (coords->size() / 2); i++)
|
||||||
poly->addPoint(coords->get(2*i), coords->get(2*i + 1));
|
poly->addPoint(coords->get(2*i), coords->get(2*i + 1));
|
||||||
|
shape= std::move( poly );
|
||||||
}
|
}
|
||||||
delete(coords);
|
delete(coords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (shape != NULL || type == BACKGROUND) {
|
if (shape != nullptr || type == BACKGROUND) {
|
||||||
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "href"))) {
|
if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "href"))) {
|
||||||
url = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
url = a_Html_url_new(html, attrbuf, NULL, 0).release();
|
||||||
dReturn_if_fail ( url != NULL );
|
dReturn_if_fail ( url != NULL );
|
||||||
@ -2408,7 +2409,7 @@ static void
|
|||||||
if (type == BACKGROUND)
|
if (type == BACKGROUND)
|
||||||
html->maps.setCurrentMapDefaultLink(link);
|
html->maps.setCurrentMapDefaultLink(link);
|
||||||
else
|
else
|
||||||
html->maps.addShapeToCurrentMap(shape, link);
|
html->maps.addShapeToCurrentMap(std::move( shape ), link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user