1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef OOX_HELPER_MODELOBJECTHELPER_HXX
29 #define OOX_HELPER_MODELOBJECTHELPER_HXX
30 
31 #include <com/sun/star/uno/Reference.hxx>
32 
33 namespace com { namespace sun { namespace star {
34     namespace awt { struct Gradient; }
35     namespace container { class XNameContainer; }
36     namespace drawing { struct LineDash; }
37     namespace drawing { struct PolyPolygonBezierCoords; }
38     namespace lang { class XMultiServiceFactory; }
39 } } }
40 
41 namespace oox {
42 
43 // ============================================================================
44 
45 /** This helper manages named objects in a container, which is created on demand.
46  */
47 class ObjectContainer
48 {
49 public:
50     explicit            ObjectContainer(
51                             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory,
52                             const ::rtl::OUString& rServiceName );
53                         ~ObjectContainer();
54 
55     /** Returns true, if the object with the passed name exists in the container. */
56     bool                hasObject( const ::rtl::OUString& rObjName ) const;
57 
58     /** Returns the object with the passed name from the container. */
59     ::com::sun::star::uno::Any getObject( const ::rtl::OUString& rObjName ) const;
60 
61     /** Inserts the passed object into the container, returns its final name. */
62     ::rtl::OUString     insertObject(
63                             const ::rtl::OUString& rObjName,
64                             const ::com::sun::star::uno::Any& rObj,
65                             bool bInsertByUnusedName );
66 
67 private:
68     void                createContainer() const;
69 
70 private:
71     mutable ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
72                         mxModelFactory;         /// Factory to create the container.
73     mutable ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
74                         mxContainer;            /// Container for the objects.
75     ::rtl::OUString     maServiceName;          /// Service name to create the container.
76     sal_Int32           mnIndex;                /// Index to create unique identifiers.
77 };
78 
79 // ============================================================================
80 
81 /** Contains tables for named drawing objects for a document model.
82 
83     Contains tables for named line markers, line dashes, fill gradients, and
84     fill bitmap URLs. The class is needed to handle different document models
85     in the same filter (e.g. embedded charts) which carry their own drawing
86     object tables.
87  */
88 class ModelObjectHelper
89 {
90 public:
91     explicit            ModelObjectHelper(
92                             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory );
93 
94     /** Returns true, if the model contains a line marker with the passed name. */
95     bool                hasLineMarker( const ::rtl::OUString& rMarkerName ) const;
96 
97     /** Inserts a new named line marker, overwrites an existing line marker
98         with the same name. Returns true, if the marker could be inserted. */
99     bool                insertLineMarker(
100                             const ::rtl::OUString& rMarkerName,
101                             const ::com::sun::star::drawing::PolyPolygonBezierCoords& rMarker );
102 
103     /** Inserts a new named line dash, returns the line dash name, based on an
104         internal constant name with a new unused index appended. */
105     ::rtl::OUString     insertLineDash( const ::com::sun::star::drawing::LineDash& rDash );
106 
107     /** Inserts a new named fill gradient, returns the gradient name, based on
108         an internal constant name with a new unused index appended. */
109     ::rtl::OUString     insertFillGradient( const ::com::sun::star::awt::Gradient& rGradient );
110 
111     /** Inserts a new named fill bitmap URL, returns the bitmap name, based on
112         an internal constant name with a new unused index appended. */
113     ::rtl::OUString     insertFillBitmapUrl( const ::rtl::OUString& rGraphicUrl );
114 
115 private:
116     ObjectContainer     maMarkerContainer;      /// Contains all named line markers (line end polygons).
117     ObjectContainer     maDashContainer;        /// Contains all named line dsahes.
118     ObjectContainer     maGradientContainer;    /// Contains all named fill gradients.
119     ObjectContainer     maBitmapUrlContainer;   /// Contains all named fill bitmap URLs.
120     const ::rtl::OUString maDashNameBase;       /// Base name for all named line dashes.
121     const ::rtl::OUString maGradientNameBase;   /// Base name for all named fill gradients.
122     const ::rtl::OUString maBitmapUrlNameBase;  /// Base name for all named fill bitmap URLs.
123 };
124 
125 // ============================================================================
126 
127 } // namespace oox
128 
129 #endif
130