diff --git a/src/apps/icon-o-matic/gui/StyleView.cpp b/src/apps/icon-o-matic/gui/StyleView.cpp index 9aa1bb2ce0..83a068312f 100644 --- a/src/apps/icon-o-matic/gui/StyleView.cpp +++ b/src/apps/icon-o-matic/gui/StyleView.cpp @@ -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); diff --git a/src/apps/icon-o-matic/gui/StyleView.h b/src/apps/icon-o-matic/gui/StyleView.h index 4d1c903347..bf601778ac 100644 --- a/src/apps/icon-o-matic/gui/StyleView.h +++ b/src/apps/icon-o-matic/gui/StyleView.h @@ -12,6 +12,7 @@ #include "IconBuild.h" #include "Observer.h" +#include #include @@ -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 fGradient; + bool fIgnoreCurrentColorNotifications; + bool fIgnoreControlGradientNotifications; - GradientControl* fGradientControl; - BMenuField* fStyleType; - BMenuField* fGradientType; + GradientControl* fGradientControl; + BMenuField* fStyleType; + BMenuField* fGradientType; - BRect fPreviousBounds; + BRect fPreviousBounds; }; diff --git a/src/apps/icon-o-matic/transformable/TransformGradientBox.cpp b/src/apps/icon-o-matic/transformable/TransformGradientBox.cpp index 2b1c9108ec..d7fdb18cc5 100644 --- a/src/apps/icon-o-matic/transformable/TransformGradientBox.cpp +++ b/src/apps/icon-o-matic/transformable/TransformGradientBox.cpp @@ -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) { diff --git a/src/apps/icon-o-matic/transformable/TransformGradientBox.h b/src/apps/icon-o-matic/transformable/TransformGradientBox.h index 3b3e440b8d..8c8e973512 100644 --- a/src/apps/icon-o-matic/transformable/TransformGradientBox.h +++ b/src/apps/icon-o-matic/transformable/TransformGradientBox.h @@ -8,10 +8,11 @@ #ifndef TRANSFORM_GRADIENT_BOX_H #define TRANSFORM_GRADIENT_BOX_H - #include "IconBuild.h" #include "TransformBox.h" +#include + 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 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