Icon-O-Matic: Make GradientTransformable a BReferenceable

* Switch to using support/Referenceable.h instead of using an older copy
   of this code.
 * Make GradientTransformable a BReferenceable and fix #12033.
This commit is contained in:
Stephan Aßmus
2015-05-09 21:38:15 +02:00
parent 8f1823774c
commit 0cbb6c11ee
36 changed files with 79 additions and 167 deletions
-1
View File
@@ -198,7 +198,6 @@ Application Icon-O-Matic :
Selection.cpp
# generic/support
Referenceable.cpp
RWLocker.cpp
support.cpp
support_ui.cpp
+2 -2
View File
@@ -839,7 +839,7 @@ MainWindow::SetIcon(Icon* icon)
fIcon = icon;
if (fIcon != NULL)
fIcon->Acquire();
fIcon->AcquireReference();
else
MakeEmpty();
@@ -865,7 +865,7 @@ MainWindow::SetIcon(Icon* icon)
// keep this last
if (oldIcon != NULL)
oldIcon->Release();
oldIcon->ReleaseReference();
}
+2 -2
View File
@@ -46,7 +46,7 @@ Document::~Document()
{
delete fCommandStack;
delete fSelection;
fIcon->Release();
fIcon->ReleaseReference();
delete fNativeSaver;
delete fExportSaver;
}
@@ -92,7 +92,7 @@ Document::SetIcon(_ICON_NAMESPACE Icon* icon)
if (fIcon == icon)
return;
fIcon->Release();
fIcon->ReleaseReference();
fIcon = icon;
@@ -17,7 +17,7 @@
// constructor
IconObject::IconObject(const char* name)
: Observable(),
Referenceable(),
BReferenceable(),
Selectable(),
fName(name)
@@ -27,7 +27,7 @@ IconObject::IconObject(const char* name)
// copy constructor
IconObject::IconObject(const IconObject& other)
: Observable(),
Referenceable(),
BReferenceable(),
Selectable(),
fName(other.fName)
@@ -37,7 +37,7 @@ IconObject::IconObject(const IconObject& other)
// archive constructor
IconObject::IconObject(BMessage* archive)
: Observable(),
Referenceable(),
BReferenceable(),
Selectable(),
fName()
+2 -2
View File
@@ -9,17 +9,17 @@
#ifndef ICON_OBJECT_H
#define ICON_OBJECT_H
#include <Referenceable.h>
#include <String.h>
#include "Observable.h"
#include "Referenceable.h"
#include "Selectable.h"
class BMessage;
class PropertyObject;
class IconObject : public Observable,
public Referenceable,
public BReferenceable,
public Selectable {
public:
IconObject(const char* name);
@@ -1,77 +0,0 @@
/*
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <[email protected]>
* Axel Dörfler, [email protected]
* Stephan Aßmus <[email protected]>
*/
#include "Referenceable.h"
#define TRACE 0
#if TRACE
#define ICON 1
#include <debugger.h>
#include <stdio.h>
#if ICON
#include "IconObject.h"
#endif
#endif
// constructor
Referenceable::Referenceable()
: fReferenceCount(1)
{
}
// destructor
Referenceable::~Referenceable()
{
}
// Acquire
void
Referenceable::Acquire()
{
atomic_add(&fReferenceCount, 1);
}
// Release
bool
Referenceable::Release()
{
#if TRACE
int32 old = atomic_add(&fReferenceCount, -1);
//#if ICON
// if (old > 1) {
//IconObject* object = dynamic_cast<IconObject*>(this);
//printf("Referenceable::Release() - %s: %ld\n",
// object ? object->Name() : "unkown", fReferenceCount);
// } else
//#endif
if (old == 1) {
#if ICON
IconObject* object = dynamic_cast<IconObject*>(this);
printf("Referenceable::Release() - deleting %s\n",
object ? object->Name() : "unkown");
#else
printf("Referenceable::Release() - deleting\n");
#endif
delete this;
return true;
} else if (old < 1)
debugger("Referenceable::Release() - already deleted");
#else
if (atomic_add(&fReferenceCount, -1) == 1) {
delete this;
return true;
}
#endif
return false;
}
@@ -1,27 +0,0 @@
/*
* Copyright 2001-2006, Haiku.
* Distributed under the terms of the MIT License.
*
* Authors:
* DarkWyrm <[email protected]>
* Axel Dörfler, [email protected]
* Stephan Aßmus <[email protected]>
*/
#ifndef REFERENCABLE_H
#define REFERENCABLE_H
#include <SupportDefs.h>
class Referenceable {
public:
Referenceable();
virtual ~Referenceable();
void Acquire();
bool Release();
private:
int32 fReferenceCount;
};
#endif // REFERENCABLE_H
@@ -204,14 +204,14 @@ IconObjectListView::_SetObject(IconObject* object)
if (fObject) {
fObject->RemoveObserver(this);
fObject->Release();
fObject->ReleaseReference();
}
fObject = object;
PropertyObject* propertyObject = NULL;
if (fObject) {
fObject->Acquire();
fObject->AcquireReference();
fObject->AddObserver(this);
propertyObject = fObject->MakePropertyObject();
}
+2 -2
View File
@@ -129,13 +129,13 @@ public:
if (path) {
path->RemoveObserver(this);
path->Release();
path->ReleaseReference();
}
path = p;
if (path) {
path->Acquire();
path->AcquireReference();
path->AddObserver(this);
UpdateText();
}
+2 -2
View File
@@ -76,13 +76,13 @@ public:
if (shape) {
shape->RemoveObserver(this);
shape->Release();
shape->ReleaseReference();
}
shape = s;
if (shape) {
shape->Acquire();
shape->AcquireReference();
shape->AddObserver(this);
UpdateText();
}
+2 -2
View File
@@ -130,13 +130,13 @@ public:
if (style) {
style->RemoveObserver(this);
style->Release();
style->ReleaseReference();
}
style = s;
if (style) {
style->Acquire();
style->AcquireReference();
style->AddObserver(this);
UpdateText();
}
+11 -5
View File
@@ -253,14 +253,14 @@ StyleView::SetStyle(Style* style)
if (fStyle) {
fStyle->RemoveObserver(this);
fStyle->Release();
fStyle->ReleaseReference();
}
fStyle = style;
Gradient* gradient = NULL;
if (fStyle) {
fStyle->Acquire();
fStyle->AcquireReference();
fStyle->AddObserver(this);
gradient = fStyle->Gradient();
@@ -308,13 +308,16 @@ StyleView::_SetGradient(Gradient* gradient, bool forceControlUpdate,
if (!forceControlUpdate && fGradient == gradient)
return;
if (fGradient)
fGradient->RemoveObserver(this);
Gradient* oldGradient = fGradient;
if (oldGradient != NULL)
oldGradient->RemoveObserver(this);
fGradient = gradient;
if (fGradient)
if (fGradient) {
fGradient->AcquireReference();
fGradient->AddObserver(this);
}
if (fGradient) {
fGradientControl->SetEnabled(true);
@@ -329,6 +332,9 @@ StyleView::_SetGradient(Gradient* gradient, bool forceControlUpdate,
_MarkType(fGradientType->Menu(), -1);
}
if (oldGradient != NULL)
oldGradient->ReleaseReference();
if (sendMessage) {
BMessage message(MSG_STYLE_TYPE_CHANGED);
message.AddPointer("style", fStyle);
@@ -68,13 +68,13 @@ class TransformerItem : public SimpleItem,
if (transformer) {
transformer->RemoveObserver(this);
transformer->Release();
transformer->ReleaseReference();
}
transformer = t;
if (transformer) {
transformer->Acquire();
transformer->AcquireReference();
transformer->AddObserver(this);
UpdateText();
}
@@ -534,7 +534,7 @@ printf("scale: %f\n", scale);
if (*style == *earlierStyle) {
shape->SetStyle(earlierStyle);
icon->Styles()->RemoveStyle(style);
style->Release();
style->ReleaseReference();
break;
}
}
@@ -649,7 +649,7 @@ AddPathsFromVertexSource(Icon* icon, Shape* shape,
//printf(" path with no points!\n");
icon->Paths()->RemovePath(path);
shape->Paths()->RemovePath(path);
path->Release();
path->ReleaseReference();
}
path = new (nothrow) VectorPath();
if (!path || !icon->Paths()->AddPath(path)) {
@@ -745,7 +745,7 @@ AddPathsFromVertexSource(Icon* icon, Shape* shape,
//printf("path with no points!\n");
icon->Paths()->RemovePath(path);
shape->Paths()->RemovePath(path);
path->Release();
path->ReleaseReference();
}
return B_OK;
@@ -235,7 +235,7 @@ PathManipulator::PathManipulator(VectorPath* path)
fLastNudgeTime(system_time()),
fNudgeCommand(NULL)
{
fPath->Acquire();
fPath->AcquireReference();
fPath->AddListener(this);
fPath->AddObserver(this);
}
@@ -255,7 +255,7 @@ PathManipulator::~PathManipulator()
fPath->RemoveObserver(this);
fPath->RemoveListener(this);
fPath->Release();
fPath->ReleaseReference();
}
@@ -48,7 +48,7 @@ AddPathsCommand::AddPathsCommand(PathContainer* container,
// Add references to paths
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] != NULL)
fPaths[i]->Acquire();
fPaths[i]->AcquireReference();
}
}
}
@@ -59,7 +59,7 @@ AddPathsCommand::~AddPathsCommand()
if (!fPathsAdded && fPaths) {
for (int32 i = 0; i < fCount; i++) {
if (fPaths[i] != NULL)
fPaths[i]->Release();
fPaths[i]->ReleaseReference();
}
}
delete[] fPaths;
@@ -52,7 +52,7 @@ AddShapesCommand::~AddShapesCommand()
{
if (!fShapesAdded && fShapes) {
for (int32 i = 0; i < fCount; i++)
fShapes[i]->Release();
fShapes[i]->ReleaseReference();
}
delete[] fShapes;
}
@@ -58,7 +58,7 @@ RemovePathsCommand::~RemovePathsCommand()
if (fPathsRemoved && fInfos) {
for (int32 i = 0; i < fCount; i++) {
if (fInfos[i].path)
fInfos[i].path->Release();
fInfos[i].path->ReleaseReference();
}
}
delete[] fInfos;
@@ -49,7 +49,7 @@ RemoveShapesCommand::~RemoveShapesCommand()
{
if (fShapesRemoved && fShapes) {
for (int32 i = 0; i < fCount; i++)
fShapes[i]->Release();
fShapes[i]->ReleaseReference();
}
delete[] fShapes;
delete[] fIndices;
@@ -34,7 +34,7 @@ UnassignPathCommand::UnassignPathCommand(Shape* shape,
UnassignPathCommand::~UnassignPathCommand()
{
if (fPathRemoved && fPath)
fPath->Release();
fPath->ReleaseReference();
}
// InitCheck
@@ -48,7 +48,7 @@ AddStylesCommand::~AddStylesCommand()
{
if (!fStylesAdded && fStyles) {
for (int32 i = 0; i < fCount; i++)
fStyles[i]->Release();
fStyles[i]->ReleaseReference();
}
delete[] fStyles;
}
@@ -28,18 +28,18 @@ AssignStyleCommand::AssignStyleCommand(Shape* shape,
fNewStyle(style)
{
if (fOldStyle)
fOldStyle->Acquire();
fOldStyle->AcquireReference();
if (fNewStyle)
fNewStyle->Acquire();
fNewStyle->AcquireReference();
}
// destructor
AssignStyleCommand::~AssignStyleCommand()
{
if (fOldStyle)
fOldStyle->Release();
fOldStyle->ReleaseReference();
if (fNewStyle)
fNewStyle->Release();
fNewStyle->ReleaseReference();
}
// InitCheck
@@ -58,7 +58,7 @@ RemoveStylesCommand::~RemoveStylesCommand()
if (fStylesRemoved && fInfos) {
for (int32 i = 0; i < fCount; i++) {
if (fInfos[i].style)
fInfos[i].style->Release();
fInfos[i].style->ReleaseReference();
}
}
delete[] fInfos;
@@ -36,7 +36,8 @@ SetGradientCommand::SetGradientCommand(Style* style,
// destructor
SetGradientCommand::~SetGradientCommand()
{
delete fGradient;
if (fGradient != NULL)
fGradient->ReleaseReference();
}
// InitCheck
@@ -77,9 +78,9 @@ SetGradientCommand::Perform()
return B_NO_MEMORY;
}
}
} else {
} else if (fGradient != NULL) {
// the style didn't have a gradient set
delete fGradient;
fGradient->ReleaseReference();
fGradient = NULL;
}
@@ -33,7 +33,7 @@ TransformGradientBox::TransformGradientBox(CanvasView* view, Gradient* gradient,
fGradient(gradient)
{
if (fShape) {
fShape->Acquire();
fShape->AcquireReference();
fShape->AddObserver(this);
}
if (fGradient) {
@@ -50,7 +50,7 @@ TransformGradientBox::~TransformGradientBox()
{
if (fShape) {
fShape->RemoveObserver(this);
fShape->Release();
fShape->ReleaseReference();
}
if (fGradient)
fGradient->RemoveObserver(this);
@@ -27,7 +27,7 @@ TransformGradientCommand::TransformGradientCommand(TransformBox* box,
if (fGradient == NULL)
return;
// fGradient->Acquire();
fGradient->AcquireReference();
if (fTransformBox != NULL)
fTransformBox->AddListener(this);
@@ -36,8 +36,8 @@ TransformGradientCommand::TransformGradientCommand(TransformBox* box,
TransformGradientCommand::~TransformGradientCommand()
{
// if (fGradient != NULL)
// fGradient->Release();
if (fGradient != NULL)
fGradient->ReleaseReference();
if (fTransformBox != NULL)
fTransformBox->RemoveListener(this);
@@ -31,7 +31,7 @@ TransformPointsBox::TransformPointsBox(CanvasView* view,
fCount(count),
fPoints(count > 0 ? new (nothrow) control_point[count] : NULL)
{
fPath->Acquire();
fPath->AcquireReference();
BRect bounds(0, 0, -1, -1);
@@ -70,7 +70,7 @@ TransformPointsBox::~TransformPointsBox()
{
delete[] fIndices;
delete[] fPoints;
fPath->Release();
fPath->ReleaseReference();
}
// #pragma mark -
@@ -40,7 +40,7 @@ TransformShapesBox::TransformShapesBox(CanvasView* view,
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i]) {
fShapes[i]->Acquire();
fShapes[i]->AcquireReference();
fShapes[i]->AddObserver(this);
}
}
@@ -59,7 +59,7 @@ TransformShapesBox::~TransformShapesBox()
for (int32 i = 0; i < fCount; i++) {
if (fShapes[i]) {
fShapes[i]->RemoveObserver(this);
fShapes[i]->Release();
fShapes[i]->ReleaseReference();
}
}
delete[] fShapes;
+2 -2
View File
@@ -14,9 +14,9 @@
#ifdef ICON_O_MATIC
# include <List.h>
# include <Referenceable.h>
# include "Observer.h"
# include "Referenceable.h"
#else
# include <SupportDefs.h>
#endif
@@ -43,7 +43,7 @@ class IconListener {
#ifdef ICON_O_MATIC
class Icon : public ShapeContainerListener,
public Observer,
public Referenceable {
public BReferenceable {
#else
class Icon {
#endif
+1 -1
View File
@@ -179,7 +179,7 @@ PathContainer::_MakeEmpty()
#ifdef ICON_O_MATIC
_NotifyPathRemoved(path);
if (fOwnsPaths)
path->Release();
path->ReleaseReference();
#else
if (fOwnsPaths)
delete path;
+4 -4
View File
@@ -335,7 +335,7 @@ Shape::ObjectChanged(const Observable* object)
void
Shape::PathAdded(VectorPath* path, int32 index)
{
path->Acquire();
path->AcquireReference();
path->AddListener(this);
_NotifyRerender();
}
@@ -346,7 +346,7 @@ Shape::PathRemoved(VectorPath* path)
{
path->RemoveListener(this);
_NotifyRerender();
path->Release();
path->ReleaseReference();
}
// #pragma mark -
@@ -417,7 +417,7 @@ Shape::SetStyle(::Style* style)
#ifdef ICON_O_MATIC
if (fStyle) {
fStyle->RemoveObserver(this);
fStyle->Release();
fStyle->ReleaseReference();
}
::Style* oldStyle = fStyle;
#endif
@@ -426,7 +426,7 @@ Shape::SetStyle(::Style* style)
#ifdef ICON_O_MATIC
if (fStyle) {
fStyle->Acquire();
fStyle->AcquireReference();
fStyle->AddObserver(this);
}
+1 -1
View File
@@ -187,7 +187,7 @@ ShapeContainer::_MakeEmpty()
Shape* shape = ShapeAtFast(i);
#ifdef ICON_O_MATIC
_NotifyShapeRemoved(shape);
shape->Release();
shape->ReleaseReference();
#else
delete shape;
#endif
@@ -22,6 +22,7 @@ Gradient::Gradient(bool empty)
#ifdef ICON_O_MATIC
: BArchivable(),
Observable(),
BReferenceable(),
Transformable(),
#else
: Transformable(),
@@ -43,6 +44,7 @@ Gradient::Gradient(BMessage* archive)
#ifdef ICON_O_MATIC
: BArchivable(archive),
Observable(),
BReferenceable(),
Transformable(),
#else
: Transformable(),
@@ -89,6 +91,7 @@ Gradient::Gradient(const Gradient& other)
#ifdef ICON_O_MATIC
: BArchivable(other),
Observable(),
BReferenceable(),
Transformable(other),
#else
: Transformable(other),
@@ -11,6 +11,7 @@
#ifdef ICON_O_MATIC
# include <Archivable.h>
# include <Referenceable.h>
# include "Observable.h"
#endif // ICON_O_MATIC
@@ -45,6 +46,7 @@ _BEGIN_ICON_NAMESPACE
#ifdef ICON_O_MATIC
class Gradient : public BArchivable,
public Observable,
public BReferenceable,
public Transformable {
#else
class Gradient : public Transformable {
+5
View File
@@ -223,7 +223,12 @@ Style::SetGradient(const ::Gradient* gradient)
#endif
delete[] fColors;
delete[] fGammaCorrectedColors;
#ifdef ICON_O_MATIC
if (fGradient != NULL)
fGradient->ReleaseReference();
#else
delete fGradient;
#endif
fColors = NULL;
fGammaCorrectedColors = NULL;
fGradient = NULL;
+1 -1
View File
@@ -180,7 +180,7 @@ StyleContainer::_MakeEmpty()
Style* style = StyleAtFast(i);
#ifdef ICON_O_MATIC
_NotifyStyleRemoved(style);
style->Release();
style->ReleaseReference();
#else
delete style;
#endif