diff --git a/src/apps/icon-o-matic/Jamfile b/src/apps/icon-o-matic/Jamfile index 4dc03bf997..36e02e7ed1 100644 --- a/src/apps/icon-o-matic/Jamfile +++ b/src/apps/icon-o-matic/Jamfile @@ -43,6 +43,7 @@ Application Icon-O-Matic : Icon.cpp IconObject.cpp IconRenderer.cpp + SetPropertiesCommand.cpp # generic/command Command.cpp CommandStack.cpp @@ -107,6 +108,7 @@ Application Icon-O-Matic : support.cpp support_ui.cpp # gui + IconObjectListView.cpp PathListView.cpp ShapeListView.cpp SwatchGroup.cpp diff --git a/src/apps/icon-o-matic/MainWindow.cpp b/src/apps/icon-o-matic/MainWindow.cpp index 1035f1c322..a15329eed4 100644 --- a/src/apps/icon-o-matic/MainWindow.cpp +++ b/src/apps/icon-o-matic/MainWindow.cpp @@ -19,9 +19,11 @@ #include "Document.h" #include "CanvasView.h" #include "CommandStack.h" +#include "IconObjectListView.h" #include "IconEditorApp.h" #include "IconView.h" #include "PathListView.h" +#include "ScrollView.h" #include "ShapeListView.h" #include "SwatchGroup.h" #include "TransformerFactory.h" @@ -54,7 +56,7 @@ enum { // constructor MainWindow::MainWindow(IconEditorApp* app, Document* document) - : BWindow(BRect(50, 50, 781, 781), "Icon-O-Matic", + : BWindow(BRect(50, 50, 891, 781), "Icon-O-Matic", B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS), fApp(app), @@ -205,6 +207,11 @@ MainWindow::_Init() fShapeListView->SetCommandStack(fDocument->CommandStack()); fShapeListView->SetSelection(fDocument->Selection()); + fTransformerListView->SetSelection(fDocument->Selection()); + + fPropertyListView->SetCommandStack(fDocument->CommandStack()); + fPropertyListView->SetSelection(fDocument->Selection()); + fIconPreview16->SetIcon(fDocument->Icon()); fIconPreview32->SetIcon(fDocument->Icon()); // fIconPreview48->SetIcon(fDocument->Icon()); @@ -332,6 +339,9 @@ MainWindow::_CreateGUI(BRect bounds) fTransformerListView = new TransformerListView(bounds, "transformer list view"); + // property list view + fPropertyListView = new IconObjectListView(); + bg->AddChild(fSwatchGroup); bg->AddChild(fIconPreview16); @@ -346,15 +356,24 @@ MainWindow::_CreateGUI(BRect bounds) B_NO_BORDER)); bg->AddChild(new BScrollView("shape list scroll view", fShapeListView, - B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, + B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true, B_NO_BORDER)); bg->AddChild(new BScrollView("transformer list scroll view", fTransformerListView, - B_FOLLOW_RIGHT | B_FOLLOW_TOP, + B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, false, true, B_NO_BORDER)); + // scroll view around property list view + bounds.OffsetBy(bounds.Width() + 6 + B_V_SCROLL_BAR_WIDTH, 0); + bg->AddChild(new ScrollView(fPropertyListView, + SCROLL_VERTICAL | SCROLL_NO_FRAME, + bounds, "property scroll view", + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, + B_WILL_DRAW | B_FRAME_EVENTS)); + + bg->AddChild(fCanvasView); return bg; diff --git a/src/apps/icon-o-matic/MainWindow.h b/src/apps/icon-o-matic/MainWindow.h index 6b4090e46f..8bc2118596 100644 --- a/src/apps/icon-o-matic/MainWindow.h +++ b/src/apps/icon-o-matic/MainWindow.h @@ -17,6 +17,7 @@ class BMenuBar; class BMenuItem; class CanvasView; class Document; +class IconObjectListView; class IconEditorApp; class IconView; class PathListView; @@ -62,6 +63,7 @@ class MainWindow : public BWindow, PathListView* fPathListView; ShapeListView* fShapeListView; TransformerListView* fTransformerListView; + IconObjectListView* fPropertyListView; // TODO: for testing only... MultipleManipulatorState* fState; diff --git a/src/apps/icon-o-matic/document/IconObject.cpp b/src/apps/icon-o-matic/document/IconObject.cpp index 1b933e986e..d69cdd676d 100644 --- a/src/apps/icon-o-matic/document/IconObject.cpp +++ b/src/apps/icon-o-matic/document/IconObject.cpp @@ -8,11 +8,27 @@ #include "IconObject.h" +#include "CommonPropertyIDs.h" +#include "Property.h" +#include "PropertyObject.h" + // constructor -IconObject::IconObject() +IconObject::IconObject(const char* name) : Observable(), Referenceable(), - Selectable() + Selectable(), + + fName(name) +{ +} + +// copy constructor +IconObject::IconObject(const IconObject& other) + : Observable(), + Referenceable(), + Selectable(), + + fName(other.fName) { } @@ -26,7 +42,7 @@ void IconObject::SelectedChanged() { // simply pass on the event for now - Notify(); +// Notify(); } // #pragma mark - @@ -35,13 +51,33 @@ IconObject::SelectedChanged() PropertyObject* IconObject::MakePropertyObject() const { - return NULL; + PropertyObject* object = new PropertyObject(); + + object->AddProperty(new StringProperty(PROPERTY_NAME, fName.String())); + + return object; } // SetToPropertyObject bool IconObject::SetToPropertyObject(const PropertyObject* object) { - return false; + AutoNotificationSuspender _(this); + + BString name; + if (object->GetValue(PROPERTY_NAME, name)) + SetName(name.String()); + + return HasPendingNotifications(); } +// SetName +void +IconObject::SetName(const char* name) +{ + if (fName == name) + return; + + fName = name; + Notify(); +} diff --git a/src/apps/icon-o-matic/document/IconObject.h b/src/apps/icon-o-matic/document/IconObject.h index 2c7afe991c..c919c90841 100644 --- a/src/apps/icon-o-matic/document/IconObject.h +++ b/src/apps/icon-o-matic/document/IconObject.h @@ -9,6 +9,8 @@ #ifndef ICON_OBJECT_H #define ICON_OBJECT_H +#include + #include "Observable.h" #include "Referenceable.h" #include "Selectable.h" @@ -19,7 +21,8 @@ class IconObject : public Observable, public Referenceable, public Selectable { public: - IconObject(); + IconObject(const char* name); + IconObject(const IconObject& other); virtual ~IconObject(); // Selectable interface @@ -30,7 +33,12 @@ class IconObject : public Observable, virtual bool SetToPropertyObject( const PropertyObject* object); + void SetName(const char* name); + const char* Name() const + { return fName.String(); } + private: + BString fName; }; #endif // ICON_OBJECT_H diff --git a/src/apps/icon-o-matic/document/SetPropertiesCommand.cpp b/src/apps/icon-o-matic/document/SetPropertiesCommand.cpp new file mode 100644 index 0000000000..67a4d6957d --- /dev/null +++ b/src/apps/icon-o-matic/document/SetPropertiesCommand.cpp @@ -0,0 +1,89 @@ +/* + * Copyright 2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus + */ + +#include "SetPropertiesCommand.h" + +#include + +#include "CommonPropertyIDs.h" +#include "IconObject.h" +#include "Property.h" +#include "PropertyObject.h" + +// constructor +SetPropertiesCommand::SetPropertiesCommand(IconObject** objects, + int32 objectCount, + PropertyObject* previous, + PropertyObject* current) + : Command(), + fObjects(objects), + fObjectCount(objectCount), + + fOldProperties(previous), + fNewProperties(current) +{ +} + +// destructor +SetPropertiesCommand::~SetPropertiesCommand() +{ + delete[] fObjects; + delete fOldProperties; + delete fNewProperties; +} + +// InitCheck +status_t +SetPropertiesCommand::InitCheck() +{ + return fObjects && fOldProperties && fNewProperties + && fObjectCount > 0 && fOldProperties->CountProperties() > 0 + && fOldProperties->ContainsSameProperties(*fNewProperties) ? + B_OK : B_NO_INIT; +} + +// Perform +status_t +SetPropertiesCommand::Perform() +{ + for (int32 i = 0; i < fObjectCount; i++) { + if (fObjects[i]) + fObjects[i]->SetToPropertyObject(fNewProperties); + } + return B_OK; +} + +// Undo +status_t +SetPropertiesCommand::Undo() +{ + for (int32 i = 0; i < fObjectCount; i++) { + if (fObjects[i]) + fObjects[i]->SetToPropertyObject(fOldProperties); + } + return B_OK; +} + +// GetName +void +SetPropertiesCommand::GetName(BString& name) +{ + if (fOldProperties->CountProperties() > 1) { + if (fObjectCount > 1) + name << "Multi Paste Properties"; + else + name << "Paste Properties"; + } else { + BString property = name_for_id( + fOldProperties->PropertyAt(0)->Identifier()); + if (fObjectCount > 1) + name << "Multi Set " << property; + else + name << "Set " << property; + } +} diff --git a/src/apps/icon-o-matic/document/SetPropertiesCommand.h b/src/apps/icon-o-matic/document/SetPropertiesCommand.h new file mode 100644 index 0000000000..b1e3f0d223 --- /dev/null +++ b/src/apps/icon-o-matic/document/SetPropertiesCommand.h @@ -0,0 +1,40 @@ +/* + * Copyright 2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus + */ + +#ifndef SET_PROPERTIES_COMMAND_H +#define SET_PROPERTIES_COMMAND_H + +#include "Command.h" + +class IconObject; +class PropertyObject; + +class SetPropertiesCommand : public Command { + public: + SetPropertiesCommand(IconObject** objects, + int32 objectCount, + PropertyObject* previous, + PropertyObject* current); + virtual ~SetPropertiesCommand(); + + virtual status_t InitCheck(); + + virtual status_t Perform(); + virtual status_t Undo(); + + virtual void GetName(BString& name); + + private: + IconObject** fObjects; + int32 fObjectCount; + + PropertyObject* fOldProperties; + PropertyObject* fNewProperties; +}; + +#endif // SET_PROPERTIES_COMMAND_H diff --git a/src/apps/icon-o-matic/generic/gui/stateview/StateView.cpp b/src/apps/icon-o-matic/generic/gui/stateview/StateView.cpp index 73296c9723..e339d94b8d 100644 --- a/src/apps/icon-o-matic/generic/gui/stateview/StateView.cpp +++ b/src/apps/icon-o-matic/generic/gui/stateview/StateView.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include "Command.h" @@ -32,6 +33,8 @@ class EventFilter : public BMessageFilter { filter_result result = B_DISPATCH_MESSAGE; switch (message->what) { case B_KEY_DOWN: { + if (dynamic_cast(*target)) + break; uint32 key; uint32 modifiers; if (message->FindInt32("raw_char", (int32*)&key) >= B_OK @@ -41,6 +44,8 @@ class EventFilter : public BMessageFilter { break; } case B_KEY_UP: { + if (dynamic_cast(*target)) + break; uint32 key; uint32 modifiers; if (message->FindInt32("raw_char", (int32*)&key) >= B_OK diff --git a/src/apps/icon-o-matic/generic/listener/Observable.h b/src/apps/icon-o-matic/generic/listener/Observable.h index bfeeffaa32..8562c6a2d4 100644 --- a/src/apps/icon-o-matic/generic/listener/Observable.h +++ b/src/apps/icon-o-matic/generic/listener/Observable.h @@ -25,6 +25,8 @@ class Observable { void SuspendNotifications(bool suspend); + bool HasPendingNotifications() const + { return fPendingNotifications; } private: BList fObservers; diff --git a/src/apps/icon-o-matic/generic/property/CommonPropertyIDs.cpp b/src/apps/icon-o-matic/generic/property/CommonPropertyIDs.cpp index 9eedfe6570..cb4299760b 100644 --- a/src/apps/icon-o-matic/generic/property/CommonPropertyIDs.cpp +++ b/src/apps/icon-o-matic/generic/property/CommonPropertyIDs.cpp @@ -8,6 +8,10 @@ #include "CommonPropertyIDs.h" +#include + +#include + // name_for_id const char* name_for_id(int32 id) @@ -42,6 +46,10 @@ name_for_id(int32 id) name = "Miter Limit"; break; + case PROPERTY_CLOSED: + name = "Closed"; + break; + default: name = ""; break; diff --git a/src/apps/icon-o-matic/generic/property/CommonPropertyIDs.h b/src/apps/icon-o-matic/generic/property/CommonPropertyIDs.h index 3634aff2b4..09afc69577 100644 --- a/src/apps/icon-o-matic/generic/property/CommonPropertyIDs.h +++ b/src/apps/icon-o-matic/generic/property/CommonPropertyIDs.h @@ -23,6 +23,8 @@ enum { PROPERTY_CAP_MODE = 'cpmd', PROPERTY_JOIN_MODE = 'jnmd', PROPERTY_MITER_LIMIT = 'mtlm', + + PROPERTY_CLOSED = 'clsd', }; diff --git a/src/apps/icon-o-matic/generic/property/view/PropertyEditorView.cpp b/src/apps/icon-o-matic/generic/property/view/PropertyEditorView.cpp index 90e4434b12..068c76971a 100644 --- a/src/apps/icon-o-matic/generic/property/view/PropertyEditorView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/PropertyEditorView.cpp @@ -14,12 +14,11 @@ #include "PropertyItemView.h" // constructor -PropertyEditorView::PropertyEditorView(Property* property) +PropertyEditorView::PropertyEditorView() : BView(BRect(0.0, 0.0, 10.0, 10.0), "property item", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), fParent(NULL), - fProperty(property), fSelected(false) { } @@ -107,4 +106,3 @@ PropertyEditorView::ValueChanged() fParent->UpdateObject(); } - diff --git a/src/apps/icon-o-matic/generic/property/view/PropertyEditorView.h b/src/apps/icon-o-matic/generic/property/view/PropertyEditorView.h index ae7b0dfe06..dc50cb4f5b 100644 --- a/src/apps/icon-o-matic/generic/property/view/PropertyEditorView.h +++ b/src/apps/icon-o-matic/generic/property/view/PropertyEditorView.h @@ -16,7 +16,7 @@ class PropertyItemView; class PropertyEditorView : public BView { public: - PropertyEditorView(Property* property); + PropertyEditorView(); virtual ~PropertyEditorView(); // BView @@ -30,9 +30,6 @@ class PropertyEditorView : public BView { // PropertyEditorView virtual float PreferredHeight() const; - Property* GetProperty() const - { return fProperty; } - void SetSelected(bool selected); bool IsSelected() const { return fSelected; } @@ -47,12 +44,12 @@ class PropertyEditorView : public BView { virtual void ValueChanged(); virtual bool AdoptProperty(Property* property) = 0; + virtual Property* GetProperty() const = 0; protected: PropertyItemView* fParent; private: - Property* fProperty; bool fSelected; }; diff --git a/src/apps/icon-o-matic/generic/property/view/PropertyItemView.cpp b/src/apps/icon-o-matic/generic/property/view/PropertyItemView.cpp index d49d906c1c..13ea27b718 100644 --- a/src/apps/icon-o-matic/generic/property/view/PropertyItemView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/PropertyItemView.cpp @@ -25,7 +25,7 @@ // constructor PropertyItemView::PropertyItemView(Property* property) : BView(BRect(0.0, 0.0, 10.0, 10.0), "property item", - B_FOLLOW_LEFT | B_FOLLOW_TOP, + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP, B_NAVIGABLE | B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE), fParent(NULL), fEditorView(/*factory->*/EditorFor(property)), diff --git a/src/apps/icon-o-matic/generic/property/view/PropertyListView.cpp b/src/apps/icon-o-matic/generic/property/view/PropertyListView.cpp index a76df19ba3..51f7d6fb97 100644 --- a/src/apps/icon-o-matic/generic/property/view/PropertyListView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/PropertyListView.cpp @@ -85,6 +85,7 @@ PropertyListView::PropertyListView() fPropertyM(NULL), fPropertyObject(NULL), + fSavedProperties(new PropertyObject()), fLastClickedItem(NULL), fSuspendUpdates(false), @@ -103,6 +104,7 @@ PropertyListView::~PropertyListView() delete fClipboard; delete fPropertyObject; + delete fSavedProperties; delete fMouseWheelFilter; delete fTabFilter; @@ -346,6 +348,7 @@ PropertyListView::SetTo(PropertyObject* object) if (fPropertyObject && object && fPropertyObject->ContainsSameProperties(*object)) { // iterate over view items and update their value views + bool error = false; for (int32 i = 0; PropertyItemView* item = _ItemAt(i); i++) { Property* property = object->PropertyAt(i); if (!item->AdoptProperty(property)) { @@ -354,13 +357,24 @@ PropertyListView::SetTo(PropertyObject* object) // there is no editor view at this item fprintf(stderr, "PropertyListView::_SetTo() - " "property mismatch at %ld\n", i); + error = true; break; } if (property) item->SetEnabled(property->IsEditable()); } - // we didn't take on ownership, but kept our old object - delete object; + // we didn't need to make empty, but transfer ownership + // of the object + if (!error) { + // if the "adopt" process went only halfway, + // some properties of the original object + // are still referenced, so we can only + // delete the original object if the process + // was successful and leak Properties otherwise, + // but this case is only theoretical anyways... + delete fPropertyObject; + } + fPropertyObject = object; } else { // remember scroll pos, selection and focused item BPoint scrollOffset = ScrollOffset(); @@ -406,14 +420,17 @@ PropertyListView::SetTo(PropertyObject* object) SetDataRect(_ItemsRect()); } + _UpdateSavedProperties(); _CheckMenuStatus(); } -// UpdateObject +// PropertyChanged void -PropertyListView::UpdateObject(uint32 propertyID) +PropertyListView::PropertyChanged(const Property* previous, + const Property* current) { - printf("PropertyListView::UpdateObject(%s)\n", name_for_id(propertyID)); + printf("PropertyListView::PropertyChanged(%s)\n", + name_for_id(current->Identifier())); } // PasteProperties @@ -442,6 +459,20 @@ PropertyListView::IsEditingMultipleObjects() // #pragma mark - +// UpdateObject +void +PropertyListView::UpdateObject(uint32 propertyID) +{ + Property* previous = fSavedProperties->FindProperty(propertyID); + Property* current = fPropertyObject->FindProperty(propertyID); + if (previous && current) { + // call hook function + PropertyChanged(previous, current); + // update saved property + previous->SetValue(current); + } +} + // ScrollOffsetChanged void PropertyListView::ScrollOffsetChanged(BPoint oldOffset, BPoint newOffset) @@ -508,13 +539,28 @@ PropertyListView::DoubleClicked(PropertyItemView* item) { if (fLastClickedItem == item) { printf("implement PropertyListView::DoubleClicked()\n"); -// ...->EditObject(item->GetProperty()); } fLastClickedItem = NULL; } // #pragma mark - +// _UpdateSavedProperties +void +PropertyListView::_UpdateSavedProperties() +{ + fSavedProperties->DeleteProperties(); + + if (!fPropertyObject) + return; + + int32 count = fPropertyObject->CountProperties(); + for (int32 i = 0; i < count; i++) { + const Property* p = fPropertyObject->PropertyAtFast(i); + fSavedProperties->AddProperty(p->Clone()); + } +} + // _AddItem bool PropertyListView::_AddItem(PropertyItemView* item) diff --git a/src/apps/icon-o-matic/generic/property/view/PropertyListView.h b/src/apps/icon-o-matic/generic/property/view/PropertyListView.h index 3ea298959d..ada24b2c8c 100644 --- a/src/apps/icon-o-matic/generic/property/view/PropertyListView.h +++ b/src/apps/icon-o-matic/generic/property/view/PropertyListView.h @@ -52,7 +52,8 @@ class PropertyListView : public BView, // PropertyListView void SetTo(PropertyObject* object); // takes ownership of the object - virtual void UpdateObject(uint32 propertyID); + virtual void PropertyChanged(const Property* previous, + const Property* current); // implement to know when a property changed virtual void PasteProperties(const PropertyObject* object); // implement to know when a property changed @@ -63,6 +64,8 @@ class PropertyListView : public BView, void UpdateStrings(); // interface for Property framework + void UpdateObject(uint32 propertyID); + bool TabFocus(bool shift); void Select(PropertyItemView* item); @@ -72,6 +75,8 @@ class PropertyListView : public BView, void DoubleClicked(PropertyItemView* item); private: + void _UpdateSavedProperties(); + bool _AddItem(PropertyItemView* item); PropertyItemView* _RemoveItem(int32 index); PropertyItemView* _ItemAt(int32 index) const; @@ -96,6 +101,7 @@ class PropertyListView : public BView, BMenuItem* fPasteMI; PropertyObject* fPropertyObject; + PropertyObject* fSavedProperties; PropertyItemView* fLastClickedItem; diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/BoolValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/BoolValueView.cpp index 101d9fc61a..75b798353a 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/BoolValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/BoolValueView.cpp @@ -10,13 +10,11 @@ #include -#include "Property.h" - #include "ui_defines.h" // constructor BoolValueView::BoolValueView(BoolProperty* property) - : PropertyEditorView(property), + : PropertyEditorView(), fProperty(property), fCheckBoxRect(0.0, 0.0, -1.0, -1.0), fEnabled(true) diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/BoolValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/BoolValueView.h index 221a1d51c5..5ef9767190 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/BoolValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/BoolValueView.h @@ -9,10 +9,9 @@ #ifndef BOOL_VALUE_VIEW_H #define BOOL_VALUE_VIEW_H +#include "Property.h" #include "PropertyEditorView.h" -class BoolProperty; - class BoolValueView : public PropertyEditorView { public: BoolValueView(BoolProperty* property); @@ -31,6 +30,8 @@ class BoolValueView : public PropertyEditorView { virtual void SetEnabled(bool enabled); virtual bool AdoptProperty(Property* property); + virtual Property* GetProperty() const + { return fProperty; } private: void _ToggleValue(); diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/ColorValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/ColorValueView.cpp index 2aa05d410c..66fda1d72f 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/ColorValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/ColorValueView.cpp @@ -16,7 +16,6 @@ #include "support_ui.h" -#include "ColorProperty.h" #include "PropertyItemView.h" #include "SwatchValueView.h" @@ -26,7 +25,7 @@ enum { // constructor ColorValueView::ColorValueView(ColorProperty* property) - : PropertyEditorView(property), + : PropertyEditorView(), fProperty(property) { fSwatchView = new SwatchValueView("swatch property view", diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/ColorValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/ColorValueView.h index 2c7377c9a0..63d8778243 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/ColorValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/ColorValueView.h @@ -9,9 +9,9 @@ #ifndef COLOR_VALUE_VIEW_H #define COLOR_VALUE_VIEW_H +#include "ColorProperty.h" #include "PropertyEditorView.h" -class ColorProperty; class SwatchValueView; class ColorValueView : public PropertyEditorView { @@ -32,6 +32,8 @@ class ColorValueView : public PropertyEditorView { virtual bool IsFocused() const; virtual bool AdoptProperty(Property* property); + virtual Property* GetProperty() const + { return fProperty; } protected: ColorProperty* fProperty; diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/FloatValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/FloatValueView.cpp index 6f14e4d79c..ef2b6b67c0 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/FloatValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/FloatValueView.cpp @@ -10,12 +10,11 @@ #include -#include "Property.h" #include "NummericalTextView.h" // constructor FloatValueView::FloatValueView(FloatProperty* property) - : TextInputValueView(property), + : TextInputValueView(), fProperty(property) { BRect b = Bounds(); diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/FloatValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/FloatValueView.h index 0acf575252..481433436c 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/FloatValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/FloatValueView.h @@ -9,9 +9,9 @@ #ifndef FLOAT_VALUE_VIEW_H #define FLOAT_VALUE_VIEW_H +#include "Property.h" #include "TextInputValueView.h" -class FloatProperty; class NummericalTextView; class FloatValueView : public TextInputValueView { @@ -26,6 +26,8 @@ class FloatValueView : public TextInputValueView { virtual void ValueChanged(); virtual bool AdoptProperty(Property* property); + virtual Property* GetProperty() const + { return fProperty; } private: FloatProperty* fProperty; diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/IconValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/IconValueView.cpp index 53bd9acbaf..a07abef665 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/IconValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/IconValueView.cpp @@ -6,20 +6,19 @@ * Stephan Aßmus */ +#include "IconValueView.h" + #include #include #include #include -#include "IconProperty.h" #include "PropertyItemView.h" -#include "IconValueView.h" - // constructor IconValueView::IconValueView(IconProperty* property) - : PropertyEditorView(property), + : PropertyEditorView(), fProperty(property), fIcon(NULL) { diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/IconValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/IconValueView.h index 15c05d44f4..b97d898f05 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/IconValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/IconValueView.h @@ -9,9 +9,9 @@ #ifndef ICON_VALUE_VIEW_H #define ICON_VALUE_VIEW_H +#include "IconProperty.h" #include "PropertyEditorView.h" -class IconProperty; class NummericalTextView; class IconValueView : public PropertyEditorView { @@ -26,6 +26,8 @@ class IconValueView : public PropertyEditorView { virtual void SetEnabled(bool enabled); virtual bool AdoptProperty(Property* property); + virtual Property* GetProperty() const + { return fProperty; } // IconValueView status_t SetIcon(const unsigned char* bitsFromQuickRes, diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/Int64ValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/Int64ValueView.cpp index aed3cdae05..c6d8e3ee1f 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/Int64ValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/Int64ValueView.cpp @@ -10,12 +10,11 @@ #include -#include "Int64Property.h" #include "NummericalTextView.h" // constructor Int64ValueView::Int64ValueView(Int64Property* property) - : TextInputValueView(property), + : TextInputValueView(), fProperty(property) { BRect b = Bounds(); diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/Int64ValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/Int64ValueView.h index d87d6c8210..44dd3457ac 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/Int64ValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/Int64ValueView.h @@ -9,9 +9,9 @@ #ifndef INT64_VALUE_VIEW_H #define INT64_VALUE_VIEW_H +#include "Int64Property.h" #include "TextInputValueView.h" -class Int64Property; class NummericalTextView; class Int64ValueView : public TextInputValueView { @@ -26,6 +26,8 @@ class Int64ValueView : public TextInputValueView { virtual void ValueChanged(); virtual bool AdoptProperty(Property* property); + virtual Property* GetProperty() const + { return fProperty; } private: Int64Property* fProperty; diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.cpp index 99da45d93a..6c6de21c33 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.cpp @@ -10,12 +10,11 @@ #include -#include "Property.h" #include "NummericalTextView.h" // constructor IntValueView::IntValueView(IntProperty* property) - : TextInputValueView(property), + : TextInputValueView(), fProperty(property) { BRect b = Bounds(); diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.h index b674548cf3..5257d75c1f 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/IntValueView.h @@ -9,9 +9,9 @@ #ifndef INT_VALUE_VIEW_H #define INT_VALUE_VIEW_H +#include "Property.h" #include "TextInputValueView.h" -class IntProperty; class NummericalTextView; class IntValueView : public TextInputValueView { @@ -26,6 +26,8 @@ class IntValueView : public TextInputValueView { virtual void ValueChanged(); virtual bool AdoptProperty(Property* property); + virtual Property* GetProperty() const + { return fProperty; } private: IntProperty* fProperty; diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/OptionValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/OptionValueView.cpp index d5adc845c1..0abea905fa 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/OptionValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/OptionValueView.cpp @@ -6,6 +6,8 @@ * Stephan Aßmus */ +#include "OptionValueView.h" + #include #include @@ -14,17 +16,13 @@ #include #include -#include "OptionProperty.h" - -#include "OptionValueView.h" - enum { MSG_OPTION_CHANGED = 'opch', }; // constructor OptionValueView::OptionValueView(OptionProperty* property) - : PropertyEditorView(property), + : PropertyEditorView(), fProperty(property), fCurrentOption(""), fEnabled(true) diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/OptionValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/OptionValueView.h index 6d534c2924..c9b12c3fea 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/OptionValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/OptionValueView.h @@ -11,10 +11,9 @@ #include +#include "OptionProperty.h" #include "PropertyEditorView.h" -class OptionProperty; - class OptionValueView : public PropertyEditorView { public: OptionValueView(OptionProperty* property); @@ -35,6 +34,8 @@ class OptionValueView : public PropertyEditorView { virtual void ValueChanged(); virtual bool AdoptProperty(Property* property); + virtual Property* GetProperty() const + { return fProperty; } private: OptionProperty* fProperty; diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.cpp index e52b75815a..cc3dfba6d0 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.cpp @@ -11,12 +11,11 @@ #include #include -#include "Property.h" #include "StringTextView.h" // constructor StringValueView::StringValueView(StringProperty* property) - : TextInputValueView(property), + : TextInputValueView(), fProperty(property) { BRect b = Bounds(); diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.h index e632fa3806..fb85bf1f41 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/StringValueView.h @@ -9,9 +9,10 @@ #ifndef STRING_VALUE_VIEW_H #define STRING_VALUE_VIEW_H +#include "OptionProperty.h" +#include "Property.h" #include "TextInputValueView.h" -class StringProperty; class StringTextView; class StringValueView : public TextInputValueView { @@ -26,6 +27,8 @@ class StringValueView : public TextInputValueView { virtual void ValueChanged(); virtual bool AdoptProperty(Property* property); + virtual Property* GetProperty() const + { return fProperty; } private: StringProperty* fProperty; diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/TextInputValueView.cpp b/src/apps/icon-o-matic/generic/property/view/specific_properties/TextInputValueView.cpp index 8a94744561..660ec4d3db 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/TextInputValueView.cpp +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/TextInputValueView.cpp @@ -21,8 +21,8 @@ enum { }; // constructor -TextInputValueView::TextInputValueView(Property* property) - : PropertyEditorView(property) +TextInputValueView::TextInputValueView() + : PropertyEditorView() { } diff --git a/src/apps/icon-o-matic/generic/property/view/specific_properties/TextInputValueView.h b/src/apps/icon-o-matic/generic/property/view/specific_properties/TextInputValueView.h index 92d3945221..727fdb8117 100644 --- a/src/apps/icon-o-matic/generic/property/view/specific_properties/TextInputValueView.h +++ b/src/apps/icon-o-matic/generic/property/view/specific_properties/TextInputValueView.h @@ -21,7 +21,7 @@ class InputTextView; class TextInputValueView : public PropertyEditorView { public: - TextInputValueView(Property* property); + TextInputValueView(); virtual ~TextInputValueView(); // BView interface diff --git a/src/apps/icon-o-matic/gui/IconObjectListView.cpp b/src/apps/icon-o-matic/gui/IconObjectListView.cpp new file mode 100644 index 0000000000..d3b1a26eda --- /dev/null +++ b/src/apps/icon-o-matic/gui/IconObjectListView.cpp @@ -0,0 +1,153 @@ +/* + * Copyright 2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus + */ + +#include "IconObjectListView.h" + +#include +#include +#include + +#include "CommandStack.h" +#include "IconObject.h" +#include "Property.h" +#include "PropertyObject.h" +#include "Selection.h" +#include "SetPropertiesCommand.h" + +using std::nothrow; + +// constructor +IconObjectListView::IconObjectListView() + : PropertyListView(), + + fSelection(NULL), + fCommandStack(NULL), + fObject(NULL), + fIgnoreObjectChange(false) +{ +} + +// destructor +IconObjectListView::~IconObjectListView() +{ + SetSelection(NULL); + _SetObject(NULL); +} + +// PropertyChanged +void +IconObjectListView::PropertyChanged(const Property* previous, + const Property* current) +{ + if (!fCommandStack || !fObject) + return; + + PropertyObject* oldObject = new (nothrow) PropertyObject(); + if (oldObject) + oldObject->AddProperty(previous->Clone()); + + PropertyObject* newObject = new (nothrow) PropertyObject(); + if (newObject) + newObject->AddProperty(current->Clone()); + + IconObject** objects = new (nothrow) IconObject*[1]; + if (objects) + objects[0] = fObject; + + Command* command = new (nothrow) SetPropertiesCommand(objects, 1, + oldObject, + newObject); + fIgnoreObjectChange = true; + fCommandStack->Perform(command); + fIgnoreObjectChange = false; +} + +// PasteProperties +void +IconObjectListView::PasteProperties(const PropertyObject* object) +{ + printf("IconObjectListView::PasteProperties()\n"); + + PropertyListView::PasteProperties(object); +} + +// IsEditingMultipleObjects +bool +IconObjectListView::IsEditingMultipleObjects() +{ + return false; +} + +// #pragma mark - + +// ObjectChanged +void +IconObjectListView::ObjectChanged(const Observable* object) +{ + if (object == fSelection) { + Selectable* selected = fSelection->SelectableAt(0); + _SetObject(dynamic_cast(selected)); + } + + if (object == fObject && !fIgnoreObjectChange) { +printf("IconObjectListView::ObjectChanged(fObject)\n"); + SetTo(fObject->MakePropertyObject()); + } +} + +// #pragma mark - + +// SetSelection +void +IconObjectListView::SetSelection(Selection* selection) +{ + if (fSelection == selection) + return; + + if (fSelection) + fSelection->RemoveObserver(this); + + fSelection = selection; + + if (fSelection) + fSelection->AddObserver(this); +} + +// SetCommandStack +void +IconObjectListView::SetCommandStack(CommandStack* stack) +{ + fCommandStack = stack; +} + +// #pragma mark - + +// _SetObject +void +IconObjectListView::_SetObject(IconObject* object) +{ + if (fObject == object) + return; + + if (fObject) { + fObject->RemoveObserver(this); + fObject->Release(); + } + + fObject = object; + PropertyObject* propertyObject = NULL; + + if (fObject) { + fObject->Acquire(); + fObject->AddObserver(this); + propertyObject = fObject->MakePropertyObject(); + } + + SetTo(propertyObject); +} + diff --git a/src/apps/icon-o-matic/gui/IconObjectListView.h b/src/apps/icon-o-matic/gui/IconObjectListView.h new file mode 100644 index 0000000000..a8917a7c38 --- /dev/null +++ b/src/apps/icon-o-matic/gui/IconObjectListView.h @@ -0,0 +1,48 @@ +/* + * Copyright 2006, Haiku. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stephan Aßmus + */ + +#ifndef ICON_OBJECT_LIST_VIEW_H +#define ICON_OBJECT_LIST_VIEW_H + +#include "Observer.h" +#include "PropertyListView.h" + +class CommandStack; +class IconObject; +class Selection; + +class IconObjectListView : public PropertyListView, + public Observer { + public: + IconObjectListView(); + virtual ~IconObjectListView(); + + // PropertyListView interface + virtual void PropertyChanged(const Property* previous, + const Property* current); + virtual void PasteProperties(const PropertyObject* object); + virtual bool IsEditingMultipleObjects(); + + // Observer interface + virtual void ObjectChanged(const Observable* object); + + // IconObjectListView + void SetSelection(Selection* selection); + void SetCommandStack(CommandStack* stack); + + private: + void _SetObject(IconObject* object); + + Selection* fSelection; + CommandStack* fCommandStack; + + IconObject* fObject; + bool fIgnoreObjectChange; +}; + +#endif // ICON_OBJECT_LIST_VIEW_H diff --git a/src/apps/icon-o-matic/gui/PathListView.cpp b/src/apps/icon-o-matic/gui/PathListView.cpp index 0e64660229..029185953b 100644 --- a/src/apps/icon-o-matic/gui/PathListView.cpp +++ b/src/apps/icon-o-matic/gui/PathListView.cpp @@ -128,29 +128,29 @@ class PathListItem : public SimpleItem, } void SetMarkEnabled(bool enabled) - { - if (fMarkEnabled == enabled) - return; - fMarkEnabled = enabled; - Invalidate(); - } + { + if (fMarkEnabled == enabled) + return; + fMarkEnabled = enabled; + Invalidate(); + } void SetMarked(bool marked) - { - if (fMarked == marked) - return; - fMarked = marked; - Invalidate(); - } + { + if (fMarked == marked) + return; + fMarked = marked; + Invalidate(); + } void Invalidate() - { - // :-/ - if (fListView->LockLooper()) { - fListView->InvalidateItem( - fListView->IndexOf(this)); - fListView->UnlockLooper(); - } - } + { + // :-/ + if (fListView->LockLooper()) { + fListView->InvalidateItem( + fListView->IndexOf(this)); + fListView->UnlockLooper(); + } + } VectorPath* path; private: @@ -265,10 +265,10 @@ PathListView::SelectionChanged() if (!fSelection) return; -// if (item) -// fSelection->Select(item->path); -// else -// fSelection->DeselectAll(); + if (item) + fSelection->Select(item->path); + else + fSelection->DeselectAll(); } // MouseDown diff --git a/src/apps/icon-o-matic/gui/TransformerListView.cpp b/src/apps/icon-o-matic/gui/TransformerListView.cpp index 2a45c6b1a0..4694af0bda 100644 --- a/src/apps/icon-o-matic/gui/TransformerListView.cpp +++ b/src/apps/icon-o-matic/gui/TransformerListView.cpp @@ -26,19 +26,62 @@ using std::nothrow; -class TransformerItem : public SimpleItem { +class TransformerItem : public SimpleItem, + public Observer { public: - TransformerItem(Transformer* t) + TransformerItem(Transformer* t, + TransformerListView* listView) : SimpleItem(t->Name()), - transformer(t) + transformer(NULL), + fListView(listView) { + SetTransformer(t); } virtual ~TransformerItem() { + SetTransformer(NULL); + } + + // Observer interface + virtual void ObjectChanged(const Observable* object) + { + UpdateText(); + } + + // TransformerItem + void SetTransformer(Transformer* t) + { + if (t == transformer) + return; + + if (transformer) { + transformer->RemoveObserver(this); + transformer->Release(); + } + + transformer = t; + + if (transformer) { + transformer->Acquire(); + transformer->AddObserver(this); + UpdateText(); + } + } + void UpdateText() + { + SetText(transformer->Name()); + // :-/ + if (fListView->LockLooper()) { + fListView->InvalidateItem( + fListView->IndexOf(this)); + fListView->UnlockLooper(); + } } Transformer* transformer; + private: + TransformerListView* fListView; }; // #pragma mark - @@ -171,7 +214,8 @@ BListItem* TransformerListView::CloneItem(int32 index) const { if (TransformerItem* item = dynamic_cast(ItemAt(index))) { - return new TransformerItem(item->transformer); + return new TransformerItem(item->transformer, + const_cast(this)); } return NULL; } @@ -258,7 +302,7 @@ bool TransformerListView::_AddTransformer(Transformer* transformer, int32 index) { if (transformer) - return AddItem(new TransformerItem(transformer), index); + return AddItem(new TransformerItem(transformer, this), index); return false; } diff --git a/src/apps/icon-o-matic/shape/Shape.cpp b/src/apps/icon-o-matic/shape/Shape.cpp index e37221da40..b03cb1f3a9 100644 --- a/src/apps/icon-o-matic/shape/Shape.cpp +++ b/src/apps/icon-o-matic/shape/Shape.cpp @@ -25,7 +25,7 @@ ShapeListener::~ShapeListener() // constructor Shape::Shape(::Style* style) - : IconObject(), + : IconObject(""), Observer(), PathContainerListener(), @@ -35,9 +35,7 @@ Shape::Shape(::Style* style) fPathSource(fPaths), fTransformers(4), - fLastBounds(0, 0, -1, -1), - - fName("") + fLastBounds(0, 0, -1, -1) { if (fPaths) fPaths->AddListener(this); @@ -47,7 +45,7 @@ Shape::Shape(::Style* style) // constructor Shape::Shape(const Shape& other) - : IconObject(), + : IconObject(other), Observer(), PathContainerListener(), @@ -57,9 +55,7 @@ Shape::Shape(const Shape& other) fPathSource(fPaths), fTransformers(4), - fLastBounds(0, 0, -1, -1), - - fName(other.fName) + fLastBounds(0, 0, -1, -1) { if (fPaths) { fPaths->AddListener(this); @@ -82,8 +78,11 @@ Shape::Shape(const Shape& other) Shape::~Shape() { int32 count = fTransformers.CountItems(); - for (int32 i = 0; i < count; i++) - delete (Transformer*)fTransformers.ItemAtFast(i); + for (int32 i = 0; i < count; i++) { + Transformer* t = (Transformer*)fTransformers.ItemAtFast(i); + t->RemoveObserver(this); + delete t; + } fPaths->MakeEmpty(); fPaths->RemoveListener(this); @@ -99,7 +98,7 @@ void Shape::ObjectChanged(const Observable* object) { // simply pass on the event for now - // (a path or the style changed, + // (a path, transformer or the style changed, // the shape needs to be re-rendered) Notify(); } @@ -157,26 +156,6 @@ Shape::SetStyle(::Style* style) // #pragma mark - -// SetName -void -Shape::SetName(const char* name) -{ - if (fName == name) - return; - - fName = name; - Notify(); -} - -// Name -const char* -Shape::Name() const -{ - return fName.String(); -} - -// #pragma mark - - // Bounds BRect Shape::Bounds(bool updateLast) const @@ -217,6 +196,8 @@ Shape::VertexSource() source = t; } + source->SetLast(); + return *source; } @@ -237,6 +218,8 @@ Shape::AddTransformer(Transformer* transformer, int32 index) if (!fTransformers.AddItem((void*)transformer, index)) return false; + transformer->AddObserver(this); + _NotifyTransformerAdded(transformer, index); return true; } @@ -246,6 +229,8 @@ bool Shape::RemoveTransformer(Transformer* transformer) { if (fTransformers.RemoveItem((void*)transformer)) { + transformer->RemoveObserver(this); + _NotifyTransformerRemoved(transformer); return true; } diff --git a/src/apps/icon-o-matic/shape/Shape.h b/src/apps/icon-o-matic/shape/Shape.h index faee727470..a86ee809f3 100644 --- a/src/apps/icon-o-matic/shape/Shape.h +++ b/src/apps/icon-o-matic/shape/Shape.h @@ -3,7 +3,6 @@ #include #include -#include #include "IconObject.h" #include "Observer.h" @@ -48,9 +47,6 @@ class Shape : public IconObject, inline ::Style* Style() const { return fStyle; } - void SetName(const char* name); - const char* Name() const; - inline BRect LastBounds() const { return fLastBounds; } BRect Bounds(bool updateLast = false) const; @@ -87,8 +83,6 @@ class Shape : public IconObject, BList fListeners; mutable BRect fLastBounds; - - BString fName; }; #endif // SHAPE_H diff --git a/src/apps/icon-o-matic/shape/VectorPath.cpp b/src/apps/icon-o-matic/shape/VectorPath.cpp index 4220b9465f..638d6a3036 100644 --- a/src/apps/icon-o-matic/shape/VectorPath.cpp +++ b/src/apps/icon-o-matic/shape/VectorPath.cpp @@ -24,6 +24,10 @@ #include "support.h" +#include "CommonPropertyIDs.h" +#include "Property.h" +#include "PropertyObject.h" + #define obj_new(type, n) ((type *)malloc ((n) * sizeof(type))) #define obj_renew(p, type, n) ((type *)realloc (p, (n) * sizeof(type))) #define obj_free free @@ -56,11 +60,6 @@ get_path_storage(agg::path_storage& path, points[0].point.x, points[0].point.y); path.close_polygon(); - } else { - // straight line from last to first control point - path.line_to(points[0].point.x, - points[0].point.y); - path.close_polygon(); } return true; @@ -72,27 +71,23 @@ get_path_storage(agg::path_storage& path, // constructor VectorPath::VectorPath() : BArchivable(), - Observable(), - Referenceable(), + IconObject(""), fPath(NULL), fClosed(false), fPointCount(0), fAllocCount(0), - fCachedBounds(0.0, 0.0, -1.0, -1.0), - fName("") + fCachedBounds(0.0, 0.0, -1.0, -1.0) { } // constructor VectorPath::VectorPath(const VectorPath& from) : BArchivable(), - Observable(), - Referenceable(), + IconObject(from), fPath(NULL), fPointCount(0), fAllocCount(0), - fCachedBounds(0.0, 0.0, -1.0, -1.0), - fName() + fCachedBounds(0.0, 0.0, -1.0, -1.0) { *this = from; } @@ -100,14 +95,12 @@ VectorPath::VectorPath(const VectorPath& from) // constructor VectorPath::VectorPath(const BMessage* archive) : BArchivable(), - Observable(), - Referenceable(), + IconObject(""/*archive*/), fPath(NULL), fClosed(false), fPointCount(0), fAllocCount(0), - fCachedBounds(0.0, 0.0, -1.0, -1.0), - fName() + fCachedBounds(0.0, 0.0, -1.0, -1.0) { if (archive) { type_code typeFound; @@ -133,9 +126,6 @@ VectorPath::VectorPath(const BMessage* archive) if (archive->FindBool("path closed", &fClosed) < B_OK) { fClosed = false; } - if (archive->FindString("name", &fName) < B_OK) { - fName = ""; - } } } @@ -146,6 +136,35 @@ VectorPath::~VectorPath() obj_free(fPath); } +// #pragma mark - + +// MakePropertyObject +PropertyObject* +VectorPath::MakePropertyObject() const +{ + PropertyObject* object = IconObject::MakePropertyObject(); + if (!object) + return NULL; + + object->AddProperty(new BoolProperty(PROPERTY_CLOSED, fClosed)); + + return object; +} + +// SetToPropertyObject +bool +VectorPath::SetToPropertyObject(const PropertyObject* object) +{ + AutoNotificationSuspender _(this); + IconObject::SetToPropertyObject(object); + + SetClosed(object->Value(PROPERTY_CLOSED, fClosed)); + + return HasPendingNotifications(); +} + +// #pragma mark - + // operator= VectorPath& VectorPath::operator=(const VectorPath& from) @@ -161,7 +180,6 @@ VectorPath::operator=(const VectorPath& from) fPointCount = 0; fCachedBounds.Set(0.0, 0.0, -1.0, -1.0); } - fName = from.fName; return *this; } @@ -213,13 +231,8 @@ VectorPath::Archive(BMessage* into, bool deep) const fprintf(stderr, "failed adding points!\n"); } if (ret >= B_OK) { - ret = into->AddString("name", fName.String()); - } else { fprintf(stderr, "failed adding close!\n"); } - if (ret < B_OK) { - fprintf(stderr, "failed adding name!\n"); - } // finish off if (ret < B_OK) { ret = into->AddString("class", "VectorPath"); @@ -228,6 +241,8 @@ VectorPath::Archive(BMessage* into, bool deep) const return ret; } +// #pragma mark - + // AddPoint bool VectorPath::AddPoint(BPoint point) @@ -414,6 +429,8 @@ VectorPath::SetInOutConnected(int32 index, bool connected) return false; } +// #pragma mark - + // GetPointAt bool VectorPath::GetPointAt(int32 index, BPoint& point) const @@ -478,6 +495,8 @@ VectorPath::CountPoints() const return fPointCount; } +// #pragma mark - + // distance_to_curve static float distance_to_curve(const BPoint& p, const BPoint& a, const BPoint& aOut, const BPoint& bIn, const BPoint& b) @@ -845,26 +864,6 @@ VectorPath::_SetPoint(int32 index, BPoint point) // #pragma mark - -// SetName -void -VectorPath::SetName(const char* name) -{ - if (fName == name) - return; - - fName = name; - Notify(); -} - -// Name -const char* -VectorPath::Name() const -{ - return fName.String(); -} - -// #pragma mark - - // _SetPointCount bool VectorPath::_SetPointCount(int32 count) diff --git a/src/apps/icon-o-matic/shape/VectorPath.h b/src/apps/icon-o-matic/shape/VectorPath.h index 98f59545ce..96a6117c2f 100644 --- a/src/apps/icon-o-matic/shape/VectorPath.h +++ b/src/apps/icon-o-matic/shape/VectorPath.h @@ -15,8 +15,7 @@ #include -#include "Observable.h" -#include "Referenceable.h" +#include "IconObject.h" class BBitmap; class BMessage; @@ -30,8 +29,7 @@ struct control_point { }; class VectorPath : public BArchivable, - public Observable, - public Referenceable { + public IconObject { public: class Iterator { @@ -48,6 +46,12 @@ class VectorPath : public BArchivable, VectorPath(const BMessage* archive); virtual ~VectorPath(); + // IconObject + virtual PropertyObject* MakePropertyObject() const; + virtual bool SetToPropertyObject( + const PropertyObject* object); + + // VectorPath VectorPath& operator=(const VectorPath& from); // bool operator==(const VectorPath& frrom) const; @@ -122,9 +126,6 @@ class VectorPath : public BArchivable, bool GetAGGPathStorage(agg::path_storage& path) const; - void SetName(const char* name); - const char* Name() const; - private: BRect _Bounds() const; void _SetPoint(int32 index, BPoint point); @@ -138,9 +139,6 @@ class VectorPath : public BArchivable, int32 fAllocCount; mutable BRect fCachedBounds; - - // TODO: should this really be part of VectorPath? - BString fName; }; #endif // VECTOR_PATH_H diff --git a/src/apps/icon-o-matic/style/Style.cpp b/src/apps/icon-o-matic/style/Style.cpp index 3699e520a4..d7fce826cb 100644 --- a/src/apps/icon-o-matic/style/Style.cpp +++ b/src/apps/icon-o-matic/style/Style.cpp @@ -12,7 +12,7 @@ // constructor Style::Style() - : IconObject(), + : IconObject("