From 014c7e945947976817a8b14d4b4f89563f769f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Mon, 7 Aug 2006 20:47:20 +0000 Subject: [PATCH] * Transformable::Reset() + Invert() didn't notify * Path and StyleContainer take an index in Add...() * FlatIconImporter works when "appending" another icon git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18448 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/libs/icon/flat_icon/FlatIconImporter.cpp | 35 ++++++++++++++++--- src/libs/icon/flat_icon/FlatIconImporter.h | 15 +++++++- src/libs/icon/shape/PathContainer.cpp | 15 +++++--- src/libs/icon/shape/PathContainer.h | 6 ++-- src/libs/icon/shape/Shape.cpp | 2 +- src/libs/icon/shape/Shape.h | 2 +- src/libs/icon/style/StyleContainer.cpp | 15 +++++--- src/libs/icon/style/StyleContainer.h | 6 ++-- src/libs/icon/transformable/Transformable.cpp | 10 ++++-- 9 files changed, 85 insertions(+), 21 deletions(-) diff --git a/src/libs/icon/flat_icon/FlatIconImporter.cpp b/src/libs/icon/flat_icon/FlatIconImporter.cpp index 652fccee58..228c187c26 100644 --- a/src/libs/icon/flat_icon/FlatIconImporter.cpp +++ b/src/libs/icon/flat_icon/FlatIconImporter.cpp @@ -35,6 +35,9 @@ using std::nothrow; // constructor FlatIconImporter::FlatIconImporter() +#ifdef ICON_O_MATIC + : Importer() +#endif { } @@ -47,6 +50,14 @@ FlatIconImporter::~FlatIconImporter() status_t FlatIconImporter::Import(Icon* icon, BPositionIO* stream) { +#ifdef ICON_O_MATIC + status_t ret = Init(icon); + if (ret < B_OK) + return ret; +#else + status_t ret; +#endif + // seek around in the stream to figure out the size off_t size = stream->Seek(0, SEEK_END); if (stream->Seek(0, SEEK_SET) != 0) @@ -64,7 +75,7 @@ FlatIconImporter::Import(Icon* icon, BPositionIO* stream) if (stream->Read(buffer.Buffer(), size) != size) return B_ERROR; - status_t ret = _ParseSections(buffer, icon); + ret = _ParseSections(buffer, icon); return ret; } @@ -73,6 +84,12 @@ FlatIconImporter::Import(Icon* icon, BPositionIO* stream) status_t FlatIconImporter::Import(Icon* icon, uint8* _buffer, size_t size) { +#ifdef ICON_O_MATIC + status_t ret = Init(icon); + if (ret < B_OK) + return ret; +#endif + if (!_buffer) return B_BAD_VALUE; @@ -465,9 +482,10 @@ _ReadTransformer(LittleEndianBuffer& buffer, VertexSource& source) } // _ReadPathSourceShape -static Shape* -_ReadPathSourceShape(LittleEndianBuffer& buffer, - StyleContainer* styles, PathContainer* paths) +Shape* +FlatIconImporter::_ReadPathSourceShape(LittleEndianBuffer& buffer, + StyleContainer* styles, + PathContainer* paths) { // find out which style this shape uses uint8 styleIndex; @@ -475,7 +493,12 @@ _ReadPathSourceShape(LittleEndianBuffer& buffer, if (!buffer.Read(styleIndex) || !buffer.Read(pathCount)) return NULL; +#ifdef ICON_O_MATIC + Style* style = styles->StyleAt(StyleIndexFor(styleIndex)); +#else Style* style = styles->StyleAt(styleIndex); +#endif + if (!style) { printf("_ReadPathSourceShape() - " "shape references non-existing style %d\n", styleIndex); @@ -495,7 +518,11 @@ _ReadPathSourceShape(LittleEndianBuffer& buffer, if (!buffer.Read(pathIndex)) return NULL; +#ifdef ICON_O_MATIC + VectorPath* path = paths->PathAt(PathIndexFor(pathIndex)); +#else VectorPath* path = paths->PathAt(pathIndex); +#endif if (!path) { printf("_ReadPathSourceShape() - " "shape references non-existing path %d\n", pathIndex); diff --git a/src/libs/icon/flat_icon/FlatIconImporter.h b/src/libs/icon/flat_icon/FlatIconImporter.h index 0215a649ef..76efc198c8 100644 --- a/src/libs/icon/flat_icon/FlatIconImporter.h +++ b/src/libs/icon/flat_icon/FlatIconImporter.h @@ -9,17 +9,26 @@ #ifndef FLAT_ICON_IMPORTER_H #define FLAT_ICON_IMPORTER_H -#include +#ifdef ICON_O_MATIC +# include "Importer.h" +#else +# include +#endif class BMessage; class BPositionIO; class Icon; class LittleEndianBuffer; class PathContainer; +class Shape; class ShapeContainer; class StyleContainer; +#ifdef ICON_O_MATIC +class FlatIconImporter : public Importer { +#else class FlatIconImporter { +#endif public: FlatIconImporter(); virtual ~FlatIconImporter(); @@ -40,6 +49,10 @@ class FlatIconImporter { StyleContainer* styles); status_t _ParsePaths(LittleEndianBuffer& buffer, PathContainer* paths); + Shape* _ReadPathSourceShape( + LittleEndianBuffer& buffer, + StyleContainer* styles, + PathContainer* paths); status_t _ParseShapes(LittleEndianBuffer& buffer, StyleContainer* styles, PathContainer* paths, diff --git a/src/libs/icon/shape/PathContainer.cpp b/src/libs/icon/shape/PathContainer.cpp index e0d3367baa..71541ee84f 100644 --- a/src/libs/icon/shape/PathContainer.cpp +++ b/src/libs/icon/shape/PathContainer.cpp @@ -49,6 +49,13 @@ PathContainer::~PathContainer() // AddPath bool PathContainer::AddPath(VectorPath* path) +{ + return AddPath(path, CountPaths()); +} + +// AddPath +bool +PathContainer::AddPath(VectorPath* path, int32 index) { if (!path) return false; @@ -57,9 +64,9 @@ PathContainer::AddPath(VectorPath* path) if (HasPath(path)) return false; - if (fPaths.AddItem((void*)path)) { + if (fPaths.AddItem((void*)path, index)) { #ifdef ICON_O_MATIC - _NotifyPathAdded(path); + _NotifyPathAdded(path, index); #endif return true; } @@ -186,14 +193,14 @@ PathContainer::_MakeEmpty() #ifdef ICON_O_MATIC // _NotifyPathAdded void -PathContainer::_NotifyPathAdded(VectorPath* path) const +PathContainer::_NotifyPathAdded(VectorPath* path, int32 index) const { BList listeners(fListeners); int32 count = listeners.CountItems(); for (int32 i = 0; i < count; i++) { PathContainerListener* listener = (PathContainerListener*)listeners.ItemAtFast(i); - listener->PathAdded(path); + listener->PathAdded(path, index); } } diff --git a/src/libs/icon/shape/PathContainer.h b/src/libs/icon/shape/PathContainer.h index acddb9f6cb..a2e0101698 100644 --- a/src/libs/icon/shape/PathContainer.h +++ b/src/libs/icon/shape/PathContainer.h @@ -19,7 +19,7 @@ class PathContainerListener { PathContainerListener(); virtual ~PathContainerListener(); - virtual void PathAdded(VectorPath* path) = 0; + virtual void PathAdded(VectorPath* path, int32 index) = 0; virtual void PathRemoved(VectorPath* path) = 0; }; #endif // ICON_O_MATIC @@ -30,6 +30,7 @@ class PathContainer { virtual ~PathContainer(); bool AddPath(VectorPath* path); + bool AddPath(VectorPath* path, int32 index); bool RemovePath(VectorPath* path); VectorPath* RemovePath(int32 index); @@ -54,7 +55,8 @@ class PathContainer { bool RemoveListener(PathContainerListener* listener); private: - void _NotifyPathAdded(VectorPath* path) const; + void _NotifyPathAdded(VectorPath* path, + int32 index) const; void _NotifyPathRemoved(VectorPath* path) const; BList fListeners; diff --git a/src/libs/icon/shape/Shape.cpp b/src/libs/icon/shape/Shape.cpp index b49f579a8b..a8edbde7fb 100644 --- a/src/libs/icon/shape/Shape.cpp +++ b/src/libs/icon/shape/Shape.cpp @@ -329,7 +329,7 @@ Shape::ObjectChanged(const Observable* object) // PathAdded void -Shape::PathAdded(VectorPath* path) +Shape::PathAdded(VectorPath* path, int32 index) { path->Acquire(); path->AddListener(this); diff --git a/src/libs/icon/shape/Shape.h b/src/libs/icon/shape/Shape.h index 932dd5313c..e80ee73596 100644 --- a/src/libs/icon/shape/Shape.h +++ b/src/libs/icon/shape/Shape.h @@ -72,7 +72,7 @@ class Shape : public Transformable { virtual void ObjectChanged(const Observable* object); // PathContainerListener interface - virtual void PathAdded(VectorPath* path); + virtual void PathAdded(VectorPath* path, int32 index); virtual void PathRemoved(VectorPath* path); // PathListener interface diff --git a/src/libs/icon/style/StyleContainer.cpp b/src/libs/icon/style/StyleContainer.cpp index 877e2427cd..8431c8ca0e 100644 --- a/src/libs/icon/style/StyleContainer.cpp +++ b/src/libs/icon/style/StyleContainer.cpp @@ -49,6 +49,13 @@ StyleContainer::~StyleContainer() // AddStyle bool StyleContainer::AddStyle(Style* style) +{ + return AddStyle(style, CountStyles()); +} + +// AddStyle +bool +StyleContainer::AddStyle(Style* style, int32 index) { if (!style) return false; @@ -57,9 +64,9 @@ StyleContainer::AddStyle(Style* style) if (HasStyle(style)) return false; - if (fStyles.AddItem((void*)style)) { + if (fStyles.AddItem((void*)style, index)) { #ifdef ICON_O_MATIC - _NotifyStyleAdded(style); + _NotifyStyleAdded(style, index); #endif return true; } @@ -187,14 +194,14 @@ StyleContainer::_MakeEmpty() // _NotifyStyleAdded void -StyleContainer::_NotifyStyleAdded(Style* style) const +StyleContainer::_NotifyStyleAdded(Style* style, int32 index) const { BList listeners(fListeners); int32 count = listeners.CountItems(); for (int32 i = 0; i < count; i++) { StyleContainerListener* listener = (StyleContainerListener*)listeners.ItemAtFast(i); - listener->StyleAdded(style); + listener->StyleAdded(style, index); } } diff --git a/src/libs/icon/style/StyleContainer.h b/src/libs/icon/style/StyleContainer.h index 164ae7b876..7db3f68e02 100644 --- a/src/libs/icon/style/StyleContainer.h +++ b/src/libs/icon/style/StyleContainer.h @@ -19,7 +19,7 @@ class StyleContainerListener { StyleContainerListener(); virtual ~StyleContainerListener(); - virtual void StyleAdded(Style* style) = 0; + virtual void StyleAdded(Style* style, int32 index) = 0; virtual void StyleRemoved(Style* style) = 0; }; #endif // ICON_O_MATIC @@ -30,6 +30,7 @@ class StyleContainer { virtual ~StyleContainer(); bool AddStyle(Style* style); + bool AddStyle(Style* style, int32 index); bool RemoveStyle(Style* style); Style* RemoveStyle(int32 index); @@ -53,7 +54,8 @@ class StyleContainer { bool RemoveListener(StyleContainerListener* listener); private: - void _NotifyStyleAdded(Style* style) const; + void _NotifyStyleAdded(Style* style, + int32 index) const; void _NotifyStyleRemoved(Style* style) const; BList fListeners; diff --git a/src/libs/icon/transformable/Transformable.cpp b/src/libs/icon/transformable/Transformable.cpp index 02e181a06d..bcdd57fc30 100644 --- a/src/libs/icon/transformable/Transformable.cpp +++ b/src/libs/icon/transformable/Transformable.cpp @@ -87,14 +87,20 @@ Transformable::Multiply(const Transformable& other) void Transformable::Reset() { - reset(); + if (!IsIdentity()) { + reset(); + TransformationChanged(); + } } // Invert void Transformable::Invert() { - invert(); + if (!IsIdentity()) { + invert(); + TransformationChanged(); + } } // IsIdentity