Icon-O-Matic: Fix references not being acquired/released
* Replaces the relavent raw pointers with BReferences * Fixes one observer not being released Fixes #12076 Fixes #16577 Change-Id: I67b68478911084637e9b474e56066aee7550ffaf Reviewed-on: https://review.haiku-os.org/c/haiku/+/6182 Tested-by: Automation <automation@haiku-os.org> Reviewed-by: waddlesplash <waddlesplash@gmail.com> Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>
This commit is contained in:
parent
7b00795fb4
commit
2263aa8f9c
@ -122,6 +122,10 @@ StyleView::~StyleView()
|
||||
SetStyle(NULL);
|
||||
SetCurrentColor(NULL);
|
||||
fGradientControl->Gradient()->RemoveObserver(this);
|
||||
|
||||
if (fGradient.IsSet()) {
|
||||
fGradient->RemoveObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -193,7 +197,7 @@ StyleView::ObjectChanged(const Observable* object)
|
||||
// NOTE: it is important to compare the gradients
|
||||
// before assignment, or we will get into an endless loop
|
||||
if (object == controlGradient) {
|
||||
if (!fGradient)
|
||||
if (!fGradient.IsSet())
|
||||
return;
|
||||
if (fIgnoreControlGradientNotifications)
|
||||
return;
|
||||
@ -305,21 +309,19 @@ void
|
||||
StyleView::_SetGradient(Gradient* gradient, bool forceControlUpdate,
|
||||
bool sendMessage)
|
||||
{
|
||||
if (!forceControlUpdate && fGradient == gradient)
|
||||
if (!forceControlUpdate && gradient == fGradient)
|
||||
return;
|
||||
|
||||
Gradient* oldGradient = fGradient;
|
||||
if (oldGradient != NULL)
|
||||
oldGradient->RemoveObserver(this);
|
||||
if (fGradient.IsSet())
|
||||
fGradient->RemoveObserver(this);
|
||||
|
||||
fGradient = gradient;
|
||||
fGradient.SetTo(gradient);
|
||||
|
||||
if (fGradient) {
|
||||
fGradient->AcquireReference();
|
||||
if (fGradient.IsSet()) {
|
||||
fGradient->AddObserver(this);
|
||||
}
|
||||
|
||||
if (fGradient) {
|
||||
if (fGradient.IsSet()) {
|
||||
fGradientControl->SetEnabled(true);
|
||||
fGradientControl->SetGradient(fGradient);
|
||||
fGradientType->SetEnabled(true);
|
||||
@ -332,9 +334,6 @@ 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);
|
||||
@ -398,7 +397,7 @@ StyleView::_AdoptCurrentColor(rgb_color color)
|
||||
if (!fStyle)
|
||||
return;
|
||||
|
||||
if (fGradient) {
|
||||
if (fGradient.IsSet()) {
|
||||
// set the focused gradient color stop
|
||||
if (fGradientControl->IsFocus()) {
|
||||
fGradientControl->SetCurrentStop(color);
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "IconBuild.h"
|
||||
#include "Observer.h"
|
||||
|
||||
#include <Referenceable.h>
|
||||
#include <View.h>
|
||||
|
||||
|
||||
@ -37,48 +38,48 @@ enum {
|
||||
|
||||
class StyleView : public BView, public Observer {
|
||||
public:
|
||||
StyleView(BRect frame);
|
||||
virtual ~StyleView();
|
||||
StyleView(BRect frame);
|
||||
virtual ~StyleView();
|
||||
|
||||
// BView interface
|
||||
virtual void AttachedToWindow();
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void FrameResized(float width, float height);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MinSize();
|
||||
|
||||
// Observer interface
|
||||
virtual void ObjectChanged(const Observable* object);
|
||||
virtual void ObjectChanged(const Observable* object);
|
||||
|
||||
// StyleView
|
||||
void SetStyle(Style* style);
|
||||
void SetCommandStack(CommandStack* stack);
|
||||
void SetCurrentColor(CurrentColor* color);
|
||||
void SetStyle(Style* style);
|
||||
void SetCommandStack(CommandStack* stack);
|
||||
void SetCurrentColor(CurrentColor* color);
|
||||
|
||||
private:
|
||||
void _SetGradient(Gradient* gradient,
|
||||
bool forceControlUpdate = false,
|
||||
bool sendMessage = false);
|
||||
void _MarkType(BMenu* menu, int32 type) const;
|
||||
void _SetStyleType(int32 type);
|
||||
void _SetGradientType(int32 type);
|
||||
void _AdoptCurrentColor(rgb_color color);
|
||||
void _TransferGradientStopColor();
|
||||
void _SetGradient(Gradient* gradient,
|
||||
bool forceControlUpdate = false,
|
||||
bool sendMessage = false);
|
||||
void _MarkType(BMenu* menu, int32 type) const;
|
||||
void _SetStyleType(int32 type);
|
||||
void _SetGradientType(int32 type);
|
||||
void _AdoptCurrentColor(rgb_color color);
|
||||
void _TransferGradientStopColor();
|
||||
|
||||
private:
|
||||
CommandStack* fCommandStack;
|
||||
CurrentColor* fCurrentColor;
|
||||
CommandStack* fCommandStack;
|
||||
CurrentColor* fCurrentColor;
|
||||
|
||||
Style* fStyle;
|
||||
Gradient* fGradient;
|
||||
bool fIgnoreCurrentColorNotifications;
|
||||
bool fIgnoreControlGradientNotifications;
|
||||
Style* fStyle;
|
||||
BReference<Gradient> fGradient;
|
||||
bool fIgnoreCurrentColorNotifications;
|
||||
bool fIgnoreControlGradientNotifications;
|
||||
|
||||
GradientControl* fGradientControl;
|
||||
BMenuField* fStyleType;
|
||||
BMenuField* fGradientType;
|
||||
GradientControl* fGradientControl;
|
||||
BMenuField* fStyleType;
|
||||
BMenuField* fGradientType;
|
||||
|
||||
BRect fPreviousBounds;
|
||||
BRect fPreviousBounds;
|
||||
};
|
||||
|
||||
|
||||
|
@ -36,7 +36,7 @@ TransformGradientBox::TransformGradientBox(CanvasView* view, Gradient* gradient,
|
||||
fShape->AcquireReference();
|
||||
fShape->AddObserver(this);
|
||||
}
|
||||
if (fGradient) {
|
||||
if (fGradient.IsSet()) {
|
||||
// trigger init
|
||||
ObjectChanged(fGradient);
|
||||
} else {
|
||||
@ -52,8 +52,9 @@ TransformGradientBox::~TransformGradientBox()
|
||||
fShape->RemoveObserver(this);
|
||||
fShape->ReleaseReference();
|
||||
}
|
||||
if (fGradient)
|
||||
if (fGradient.IsSet()) {
|
||||
fGradient->RemoveObserver(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -69,7 +70,7 @@ TransformGradientBox::Update(bool deep)
|
||||
dirty.InsetBy(-8, -8);
|
||||
fView->Invalidate(dirty);
|
||||
|
||||
if (!deep || !fGradient)
|
||||
if (!deep || !fGradient.IsSet())
|
||||
return;
|
||||
|
||||
fGradient->RemoveObserver(this);
|
||||
@ -95,7 +96,7 @@ TransformGradientBox::Update(bool deep)
|
||||
void
|
||||
TransformGradientBox::ObjectChanged(const Observable* object)
|
||||
{
|
||||
if (!fGradient || !fView->LockLooper())
|
||||
if (!fGradient.IsSet() || !fView->LockLooper())
|
||||
return;
|
||||
|
||||
if (object == fShape) {
|
||||
|
@ -8,10 +8,11 @@
|
||||
#ifndef TRANSFORM_GRADIENT_BOX_H
|
||||
#define TRANSFORM_GRADIENT_BOX_H
|
||||
|
||||
|
||||
#include "IconBuild.h"
|
||||
#include "TransformBox.h"
|
||||
|
||||
#include <Referenceable.h>
|
||||
|
||||
|
||||
class CanvasView;
|
||||
|
||||
@ -25,38 +26,38 @@ _USING_ICON_NAMESPACE
|
||||
|
||||
class TransformGradientBox : public TransformBox {
|
||||
public:
|
||||
TransformGradientBox(CanvasView* view,
|
||||
Gradient* gradient,
|
||||
Shape* parent);
|
||||
virtual ~TransformGradientBox();
|
||||
TransformGradientBox(CanvasView* view,
|
||||
Gradient* gradient,
|
||||
Shape* parent);
|
||||
virtual ~TransformGradientBox();
|
||||
|
||||
// Observer interface (Manipulator is an Observer)
|
||||
virtual void ObjectChanged(const Observable* object);
|
||||
virtual void ObjectChanged(const Observable* object);
|
||||
|
||||
// TransformBox interface
|
||||
virtual void Update(bool deep = true);
|
||||
virtual void Update(bool deep = true);
|
||||
|
||||
virtual void TransformFromCanvas(BPoint& point) const;
|
||||
virtual void TransformToCanvas(BPoint& point) const;
|
||||
virtual float ZoomLevel() const;
|
||||
virtual double ViewSpaceRotation() const;
|
||||
virtual void TransformFromCanvas(BPoint& point) const;
|
||||
virtual void TransformToCanvas(BPoint& point) const;
|
||||
virtual float ZoomLevel() const;
|
||||
virtual double ViewSpaceRotation() const;
|
||||
|
||||
virtual TransformCommand* MakeCommand(const char* actionName,
|
||||
uint32 nameIndex);
|
||||
virtual TransformCommand* MakeCommand(const char* actionName,
|
||||
uint32 nameIndex);
|
||||
|
||||
// TransformGradientBox
|
||||
Command* Perform();
|
||||
Command* Cancel();
|
||||
Command* Perform();
|
||||
Command* Cancel();
|
||||
private:
|
||||
CanvasView* fCanvasView;
|
||||
CanvasView* fCanvasView;
|
||||
|
||||
Shape* fShape;
|
||||
Gradient* fGradient;
|
||||
int32 fCount;
|
||||
Shape* fShape;
|
||||
BReference<Gradient> fGradient;
|
||||
int32 fCount;
|
||||
|
||||
// saves the transformable object transformation states
|
||||
// prior to this transformation
|
||||
double fOriginals[matrix_size];
|
||||
double fOriginals[matrix_size];
|
||||
};
|
||||
|
||||
#endif // TRANSFORM_GRADIENT_BOX_H
|
||||
|
Loading…
Reference in New Issue
Block a user