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_DRAWINGML_CHART_MODELBASE_HXX
25 #define OOX_DRAWINGML_CHART_MODELBASE_HXX
26 
27 #include "oox/helper/helper.hxx"
28 #include "oox/helper/refmap.hxx"
29 #include "oox/helper/refvector.hxx"
30 
31 namespace oox { class AttributeList; }
32 
33 namespace oox {
34 namespace drawingml {
35 namespace chart {
36 
37 // ============================================================================
38 
39 template< typename ModelType >
40 class ModelRef : public ::boost::shared_ptr< ModelType >
41 {
42 public:
ModelRef()43     inline explicit     ModelRef() {}
ModelRef(const::boost::shared_ptr<ModelType> & rxModel)44     inline              ModelRef( const ::boost::shared_ptr< ModelType >& rxModel ) : ::boost::shared_ptr< ModelType >( rxModel ) {}
~ModelRef()45     inline              ~ModelRef() {}
46 
is() const47     inline bool         is() const { return this->get() != 0; }
48 
create()49     inline ModelType&   create() { this->reset( new ModelType ); return **this; }
50     template< typename Param1Type >
create(const Param1Type & rParam1)51     inline ModelType&   create( const Param1Type& rParam1 ) { this->reset( new ModelType( rParam1 ) ); return **this; }
52 
getOrCreate()53     inline ModelType&   getOrCreate() { if( !*this ) this->reset( new ModelType ); return **this; }
54     template< typename Param1Type >
getOrCreate(const Param1Type & rParam1)55     inline ModelType&   getOrCreate( const Param1Type& rParam1 ) { if( !*this ) this->reset( new ModelType( rParam1 ) ); return **this; }
56 };
57 
58 // ============================================================================
59 
60 template< typename ModelType >
61 class ModelVector : public RefVector< ModelType >
62 {
63 public:
64     typedef typename RefVector< ModelType >::value_type value_type;
65     typedef typename RefVector< ModelType >::size_type  size_type;
66 
ModelVector()67     inline explicit     ModelVector() {}
~ModelVector()68     inline              ~ModelVector() {}
69 
create()70     inline ModelType&   create() { return append( new ModelType ); }
71     template< typename Param1Type >
create(const Param1Type & rParam1)72     inline ModelType&   create( const Param1Type& rParam1 ) { return append( new ModelType( rParam1 ) ); }
73 
74 private:
append(ModelType * pModel)75     inline ModelType&   append( ModelType* pModel ) { this->push_back( value_type( pModel ) ); return *pModel; }
76 };
77 
78 // ============================================================================
79 
80 template< typename KeyType, typename ModelType >
81 class ModelMap : public RefMap< KeyType, ModelType >
82 {
83 public:
84     typedef typename RefMap< KeyType, ModelType >::key_type     key_type;
85     typedef typename RefMap< KeyType, ModelType >::mapped_type  mapped_type;
86     typedef typename RefMap< KeyType, ModelType >::value_type   value_type;
87 
ModelMap()88     inline explicit     ModelMap() {}
~ModelMap()89     inline              ~ModelMap() {}
90 
create(KeyType eKey)91     inline ModelType&   create( KeyType eKey ) { return insert( eKey, new ModelType ); }
92     template< typename Param1Type >
create(KeyType eKey,const Param1Type & rParam1)93     inline ModelType&   create( KeyType eKey, const Param1Type& rParam1 ) { return insert( eKey, new ModelType( rParam1 ) ); }
94 
95 private:
insert(KeyType eKey,ModelType * pModel)96     inline ModelType&   insert( KeyType eKey, ModelType* pModel ) { (*this)[ eKey ].reset( pModel ); return *pModel; }
97 };
98 
99 // ============================================================================
100 
101 struct NumberFormat
102 {
103     ::rtl::OUString     maFormatCode;       /// Number format code.
104     bool                mbSourceLinked;     /// True = number format linked to source data.
105 
106     explicit            NumberFormat();
107 
108     void                setAttributes( const AttributeList& rAttribs );
109 };
110 
111 // ============================================================================
112 
113 struct LayoutModel
114 {
115     double              mfX;                /// Left position of this object.
116     double              mfY;                /// Top position of this object.
117     double              mfW;                /// Width of this object.
118     double              mfH;                /// Height of this object.
119     sal_Int32           mnXMode;            /// Mode for left position.
120     sal_Int32           mnYMode;            /// Mode for top position.
121     sal_Int32           mnWMode;            /// Mode for width.
122     sal_Int32           mnHMode;            /// Mode for height.
123     sal_Int32           mnTarget;           /// Layout target for plot area.
124     bool                mbAutoLayout;       /// True = automatic positioning.
125 
126     explicit            LayoutModel();
127                         ~LayoutModel();
128 };
129 
130 // ============================================================================
131 
132 } // namespace chart
133 } // namespace drawingml
134 } // namespace oox
135 
136 #endif
137