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 #ifndef INCLUDED_NUMBERINGMANAGER_HXX
24 #define INCLUDED_NUMBERINGMANAGER_HXX
25 
26 #include "PropertyMap.hxx"
27 
28 #include <WriterFilterDllApi.hxx>
29 #include <dmapper/DomainMapper.hxx>
30 #include <resourcemodel/LoggedResources.hxx>
31 
32 #include <com/sun/star/container/XIndexReplace.hpp>
33 
34 namespace writerfilter {
35 namespace dmapper {
36 
37 class DomainMapper;
38 class StyleSheetEntry;
39 
40 
41 /** Class representing the numbering level properties.
42  */
43 class ListLevel : public PropertyMap
44 {
45     sal_Int32                                     m_nIStartAt;       //LN_ISTARTAT
46     sal_Int32                                     m_nNFC;            //LN_NFC
47     sal_Int32                                     m_nJC;             //LN_JC
48     sal_Int32                                     m_nFLegal;         //LN_FLEGAL
49     sal_Int32                                     m_nFNoRestart;     //LN_FNORESTART
50     sal_Int32                                     m_nFPrev;          //LN_FPREV
51     sal_Int32                                     m_nFPrevSpace;     //LN_FPREVSPACE
52     sal_Int32                                     m_nFWord6;         //LN_FWORD6
53     ::rtl::OUString                               m_sRGBXchNums;     //LN_RGBXCHNUMS
54     sal_Int32                                     m_nXChFollow;      //LN_IXCHFOLLOW
55     ::rtl::OUString                               m_sBulletChar;
56     sal_Int32                                     m_nTabstop;
57     boost::shared_ptr< StyleSheetEntry >          m_pParaStyle;
58 
59 public:
60 
61     typedef boost::shared_ptr< ListLevel > Pointer;
62 
ListLevel()63     ListLevel() :
64         m_nIStartAt(-1)
65         ,m_nNFC(-1)
66         ,m_nJC(-1)
67         ,m_nFLegal(-1)
68         ,m_nFNoRestart(-1)
69         ,m_nFPrev(-1)
70         ,m_nFPrevSpace(-1)
71         ,m_nFWord6(-1)
72         ,m_nXChFollow(-1)
73         ,m_nTabstop( 0 )
74         {}
75 
~ListLevel()76     ~ListLevel( ){ }
77 
78     // Setters for the import
79     void SetValue( Id nId, sal_Int32 nValue );
SetBulletChar(rtl::OUString sValue)80     void SetBulletChar( rtl::OUString sValue ) { m_sBulletChar = sValue; };
SetParaStyle(boost::shared_ptr<StyleSheetEntry> pStyle)81     void SetParaStyle( boost::shared_ptr< StyleSheetEntry > pStyle )
82     {
83         m_pParaStyle = pStyle;
84     };
AddRGBXchNums(rtl::OUString sValue)85     void AddRGBXchNums( rtl::OUString sValue ) { m_sRGBXchNums += sValue; };
86 
87     // Getters
GetBulletChar()88     rtl::OUString GetBulletChar( ) { return m_sBulletChar; };
GetParaStyle()89     boost::shared_ptr< StyleSheetEntry > GetParaStyle( ) { return m_pParaStyle; };
90 
91     // UNO mapping functions
92 
93     // rPrefix and rSuffix are out parameters
94     static sal_Int16 GetParentNumbering( rtl::OUString sText, sal_Int16 nLevel,
95         rtl::OUString& rPrefix, rtl::OUString& rSuffix );
96 
97     com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
98         GetProperties(  );
99 
100     com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue>
101         GetCharStyleProperties( );
102 private:
103 
104     com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
105         GetLevelProperties(  );
106 
107     com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
108         GetParaProperties(  );
109 };
110 
111 class AbstractListDef
112 {
113 private:
114     sal_Int32                            m_nTPLC;          //LN_TPLC
115     ::rtl::OUString                      m_sRGISTD;        //LN_RGISTD
116     sal_Int32                            m_nSimpleList;    //LN_FSIMPLELIST
117     sal_Int32                            m_nRestart;       //LN_FRESTARTHDN
118     sal_Int32                            m_nUnsigned;      //LN_UNSIGNED26_2
119 
120     // The ID member reflects either the abstractNumId or the numId
121     // depending on the use of the class
122     sal_Int32                            m_nId;
123 
124     // Properties of each level. This can also reflect the overridden
125     // levels of a numbering.
126     ::std::vector< ListLevel::Pointer >  m_aLevels;
127 
128     // Only used during the numberings import
129     ListLevel::Pointer                         m_pCurrentLevel;
130 
131     // The style name linked to.
132     ::rtl::OUString                      m_sNumStyleLink;
133 
134 public:
135     typedef boost::shared_ptr< AbstractListDef > Pointer;
136 
137     AbstractListDef( );
138     ~AbstractListDef( );
139 
140     // Setters using during the import
SetId(sal_Int32 nId)141     void SetId( sal_Int32 nId ) { m_nId = nId; };
142     void SetValue( sal_uInt32 nSprmId, sal_Int32 nValue );
AddRGISTD(rtl::OUString sValue)143     void AddRGISTD( rtl::OUString sValue ) { m_sRGISTD += sValue; };
144 
145     // Accessors
GetId() const146     sal_Int32             GetId( ) const { return m_nId; };
147 
Size()148     sal_Int16             Size( ) { return sal_Int16( m_aLevels.size( ) ); };
149     ListLevel::Pointer    GetLevel( sal_uInt16 nLvl );
150     void                  AddLevel( );
151 
GetCurrentLevel() const152     ListLevel::Pointer    GetCurrentLevel( ) const { return m_pCurrentLevel; };
153 
154     virtual com::sun::star::uno::Sequence<
155         com::sun::star::uno::Sequence<
156             com::sun::star::beans::PropertyValue > > GetPropertyValues( );
157 
SetNumStyleLink(rtl::OUString sValue)158     void                  SetNumStyleLink(rtl::OUString sValue) { m_sNumStyleLink = sValue; };
GetNumStyleLink()159     ::rtl::OUString       GetNumStyleLink() { return m_sNumStyleLink; };
160 };
161 
162 class ListDef : public AbstractListDef
163 {
164 private:
165     // Pointer to the abstract numbering
166     AbstractListDef::Pointer             m_pAbstractDef;
167 
168     // Cache for the UNO numbering rules
169     uno::Reference< container::XIndexReplace > m_xNumRules;
170 
171 public:
172     typedef boost::shared_ptr< ListDef > Pointer;
173 
174     ListDef( );
175     ~ListDef( );
176 
177     // Accessors
SetAbstractDefinition(AbstractListDef::Pointer pAbstract)178     void SetAbstractDefinition( AbstractListDef::Pointer pAbstract ) { m_pAbstractDef = pAbstract; };
GetAbstractDefinition()179     AbstractListDef::Pointer GetAbstractDefinition( ) { return m_pAbstractDef; };
180 
181     // Mapping functions
182     static rtl::OUString GetStyleName( sal_Int32 nId );
183 
184     com::sun::star::uno::Sequence<
185         com::sun::star::uno::Sequence<
186             com::sun::star::beans::PropertyValue > > GetPropertyValues( );
187 
188     void CreateNumberingRules(
189             DomainMapper& rDMapper,
190             com::sun::star::uno::Reference<
191                 com::sun::star::lang::XMultiServiceFactory> xFactory );
192 
193     ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexReplace >
GetNumberingRules()194             GetNumberingRules( ) { return m_xNumRules; };
195 
196 };
197 
198 /** This class provides access to the defined numbering styles.
199   */
200 class ListsManager :
201     public LoggedProperties,
202     public LoggedTable
203 {
204 private:
205 
206     DomainMapper&                                       m_rDMapper;
207     com::sun::star::uno::Reference<
208         com::sun::star::lang::XMultiServiceFactory >    m_xFactory;
209 
210     // The numbering entries
211     std::vector< AbstractListDef::Pointer >             m_aAbstractLists;
212     std::vector< ListDef::Pointer >                     m_aLists;
213 
214 
215     // These members are used for import only
216     AbstractListDef::Pointer                            m_pCurrentDefinition;
217     bool                                                m_bIsLFOImport;
218 
219     AbstractListDef::Pointer    GetAbstractList( sal_Int32 nId );
220 
221     // Properties
222     virtual void lcl_attribute( Id nName, Value & rVal );
223     virtual void lcl_sprm(Sprm & sprm);
224 
225     // Table
226     virtual void lcl_entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref);
227 
228 public:
229 
230     ListsManager(
231             DomainMapper& rDMapper,
232             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > xFactory);
233     virtual ~ListsManager();
234 
235     typedef boost::shared_ptr< ListsManager >  Pointer;
236 
237     // Config methods
SetLFOImport(bool bLFOImport)238     void SetLFOImport( bool bLFOImport ) { m_bIsLFOImport = bLFOImport; };
239 
240     // Numberings accessors
GetCurrentDef()241     AbstractListDef::Pointer GetCurrentDef( ) { return m_pCurrentDefinition; };
242 
Size() const243     sal_uInt32              Size() const
244         { return sal_uInt32( m_aLists.size( ) ); };
245     ListDef::Pointer        GetList( sal_Int32 nId );
246 
247     // Mapping methods
248     void CreateNumberingRules( );
249 };
250 
251 } }
252 
253 #endif
254 
255