1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef OOX_HELPER_MODELOBJECTHELPER_HXX
25 #define OOX_HELPER_MODELOBJECTHELPER_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 
29 namespace com { namespace sun { namespace star {
30     namespace awt { struct Gradient; }
31     namespace container { class XNameContainer; }
32     namespace drawing { struct LineDash; }
33     namespace drawing { struct PolyPolygonBezierCoords; }
34     namespace lang { class XMultiServiceFactory; }
35 } } }
36 
37 namespace oox {
38 
39 // ============================================================================
40 
41 /** This helper manages named objects in a container, which is created on demand.
42  */
43 class ObjectContainer
44 {
45 public:
46     explicit            ObjectContainer(
47                             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory,
48                             const ::rtl::OUString& rServiceName );
49                         ~ObjectContainer();
50 
51     /** Returns true, if the object with the passed name exists in the container. */
52     bool                hasObject( const ::rtl::OUString& rObjName ) const;
53 
54     /** Returns the object with the passed name from the container. */
55     ::com::sun::star::uno::Any getObject( const ::rtl::OUString& rObjName ) const;
56 
57     /** Inserts the passed object into the container, returns its final name. */
58     ::rtl::OUString     insertObject(
59                             const ::rtl::OUString& rObjName,
60                             const ::com::sun::star::uno::Any& rObj,
61                             bool bInsertByUnusedName );
62 
63 private:
64     void                createContainer() const;
65 
66 private:
67     mutable ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
68                         mxModelFactory;         /// Factory to create the container.
69     mutable ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameContainer >
70                         mxContainer;            /// Container for the objects.
71     ::rtl::OUString     maServiceName;          /// Service name to create the container.
72     sal_Int32           mnIndex;                /// Index to create unique identifiers.
73 };
74 
75 // ============================================================================
76 
77 /** Contains tables for named drawing objects for a document model.
78 
79     Contains tables for named line markers, line dashes, fill gradients, and
80     fill bitmap URLs. The class is needed to handle different document models
81     in the same filter (e.g. embedded charts) which carry their own drawing
82     object tables.
83  */
84 class ModelObjectHelper
85 {
86 public:
87     explicit            ModelObjectHelper(
88                             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& rxModelFactory );
89 
90     /** Returns true, if the model contains a line marker with the passed name. */
91     bool                hasLineMarker( const ::rtl::OUString& rMarkerName ) const;
92 
93     /** Inserts a new named line marker, overwrites an existing line marker
94         with the same name. Returns true, if the marker could be inserted. */
95     bool                insertLineMarker(
96                             const ::rtl::OUString& rMarkerName,
97                             const ::com::sun::star::drawing::PolyPolygonBezierCoords& rMarker );
98 
99     /** Inserts a new named line dash, returns the line dash name, based on an
100         internal constant name with a new unused index appended. */
101     ::rtl::OUString     insertLineDash( const ::com::sun::star::drawing::LineDash& rDash );
102 
103     /** Inserts a new named fill gradient, returns the gradient name, based on
104         an internal constant name with a new unused index appended. */
105     ::rtl::OUString     insertFillGradient( const ::com::sun::star::awt::Gradient& rGradient );
106 
107     /** Inserts a new named fill bitmap URL, returns the bitmap name, based on
108         an internal constant name with a new unused index appended. */
109     ::rtl::OUString     insertFillBitmapUrl( const ::rtl::OUString& rGraphicUrl );
110 
111 private:
112     ObjectContainer     maMarkerContainer;      /// Contains all named line markers (line end polygons).
113     ObjectContainer     maDashContainer;        /// Contains all named line dsahes.
114     ObjectContainer     maGradientContainer;    /// Contains all named fill gradients.
115     ObjectContainer     maBitmapUrlContainer;   /// Contains all named fill bitmap URLs.
116     const ::rtl::OUString maDashNameBase;       /// Base name for all named line dashes.
117     const ::rtl::OUString maGradientNameBase;   /// Base name for all named fill gradients.
118     const ::rtl::OUString maBitmapUrlNameBase;  /// Base name for all named fill bitmap URLs.
119 };
120 
121 // ============================================================================
122 
123 } // namespace oox
124 
125 #endif
126