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_STYLESHEETTABLE_HXX
24 #define INCLUDED_STYLESHEETTABLE_HXX
25 
26 #include "TblStylePrHandler.hxx"
27 
28 #include <WriterFilterDllApi.hxx>
29 #include <dmapper/DomainMapper.hxx>
30 #include <com/sun/star/lang/XComponent.hpp>
31 #include <PropertyMap.hxx>
32 #include <FontTable.hxx>
33 #include <resourcemodel/LoggedResources.hxx>
34 
35 namespace com{ namespace sun { namespace star { namespace text{
36     class XTextDocument;
37 }}}}
38 
39 
40 namespace writerfilter {
41 namespace dmapper
42 {
43 
44 
45 enum StyleType
46 {
47     STYLE_TYPE_UNKNOWN,
48     STYLE_TYPE_PARA,
49     STYLE_TYPE_CHAR,
50     STYLE_TYPE_TABLE,
51     STYLE_LIST
52 };
53 
54 struct StyleSheetTable_Impl;
55 class StyleSheetEntry
56 {
57 public:
58     ::rtl::OUString sStyleIdentifierI;
59     ::rtl::OUString sStyleIdentifierD;
60     bool            bIsDefaultStyle;
61     bool            bInvalidHeight;
62     bool            bHasUPE; //universal property expansion
63     StyleType       nStyleTypeCode; //sgc
64     ::rtl::OUString sBaseStyleIdentifier;
65     ::rtl::OUString sNextStyleIdentifier;
66     ::rtl::OUString sStyleName;
67     ::rtl::OUString sStyleName1;
68     PropertyMapPtr  pProperties;
69     ::rtl::OUString sConvertedStyleName;
70 
71     StyleSheetEntry();
72     virtual ~StyleSheetEntry();
73 };
74 
75 typedef boost::shared_ptr<StyleSheetEntry> StyleSheetEntryPtr;
76 typedef ::std::deque<StyleSheetEntryPtr> StyleSheetEntryDeque;
77 typedef boost::shared_ptr<StyleSheetEntryDeque> StyleSheetEntryDequePtr;
78 
79 class DomainMapper;
80 class StyleSheetTable :
81         public LoggedProperties,
82         public LoggedTable
83 {
84     StyleSheetTable_Impl   *m_pImpl;
85 
86 public:
87     StyleSheetTable( DomainMapper& rDMapper,
88                         ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextDocument> xTextDocument );
89     virtual ~StyleSheetTable();
90 
91     void ApplyStyleSheets( FontTablePtr rFontTable );
92     const StyleSheetEntryPtr FindStyleSheetByISTD(const ::rtl::OUString& sIndex);
93     const StyleSheetEntryPtr FindStyleSheetByStyleName(const ::rtl::OUString& rIndex);
94     const StyleSheetEntryPtr FindStyleSheetByConvertedStyleName(const ::rtl::OUString& rIndex);
95     // returns the parent of the one with the given name - if empty the parent of the current style sheet is returned
96     const StyleSheetEntryPtr FindParentStyleSheet(::rtl::OUString sBaseStyle);
97 
98     ::rtl::OUString ConvertStyleName( const ::rtl::OUString& rWWName, bool bExtendedSearch = false );
99     ::rtl::OUString GetStyleIdFromIndex(const sal_uInt32 sti);
100 
101     ::rtl::OUString getOrCreateCharStyle( PropertyValueVector_t& rCharProperties );
102 
103 private:
104     // Properties
105     virtual void lcl_attribute(Id Name, Value & val);
106     virtual void lcl_sprm(Sprm & sprm);
107 
108     // Table
109     virtual void lcl_entry(int pos, writerfilter::Reference<Properties>::Pointer_t ref);
110 
111     void resolveAttributeProperties(Value & val);
112     void resolveSprmProps(Sprm & sprm_);
113     void applyDefaults(bool bParaProperties);
114 };
115 typedef boost::shared_ptr< StyleSheetTable >    StyleSheetTablePtr;
116 
117 
118 class WRITERFILTER_DLLPRIVATE TableStyleSheetEntry :
119     public StyleSheetEntry
120 {
121 private:
122     typedef std::map<TblStyleType, PropertyMapPtr> TblStylePrs;
123 
124     StyleSheetTable* m_pStyleSheet;
125     TblStylePrs m_aStyles;
126 
127 public:
128 
129     short m_nColBandSize;
130     short m_nRowBandSize;
131 
132     // Adds a new tblStylePr to the table style entry. This method
133     // fixes some possible properties conflicts, like borders ones.
134     void AddTblStylePr( TblStyleType nType, PropertyMapPtr pProps );
135 
136     // Gets all the properties
137     //     + corresponding to the mask,
138     //     + from the parent styles
139     //
140     // @param mask      mask describing which properties to return
141     // @param pStack    already processed StyleSheetEntries
142     PropertyMapPtr GetProperties( sal_Int32 nMask, StyleSheetEntryDequePtr pStack = StyleSheetEntryDequePtr());
143 
144     TableStyleSheetEntry( StyleSheetEntry& aEntry, StyleSheetTable* pStyles );
145     virtual ~TableStyleSheetEntry( );
146 
147 protected:
148     PropertyMapPtr GetLocalPropertiesFromMask( const sal_Int32 nMask );
149     void           MergePropertiesFromMask(const short nBit, const sal_Int32 nMask,
150                                            const TblStyleType nStyleId, PropertyMapPtr pToFill);
151 };
152 typedef boost::shared_ptr<TableStyleSheetEntry> TableStyleSheetEntryPtr;
153 
154 }}
155 
156 #endif //
157