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 _XMLOFF_XMLSTYLE_HXX 25 #define _XMLOFF_XMLSTYLE_HXX 26 27 #include "sal/config.h" 28 #include "xmloff/dllapi.h" 29 #include "sal/types.h" 30 #include <rsc/rscsfx.hxx> 31 #include <tools/rtti.hxx> 32 #include <xmloff/uniref.hxx> 33 #include <xmloff/xmltkmap.hxx> 34 #include <xmloff/xmlictxt.hxx> 35 36 class SvXMLStylesContext_Impl; 37 class SvXMLUnitConverter; 38 class SvXMLImportPropertyMapper; 39 40 namespace com { namespace sun { namespace star { 41 namespace container { class XNameContainer; } 42 namespace style { class XAutoStyleFamily; } 43 } } } 44 45 enum XMLStyleStylesElemTokens 46 { 47 XML_TOK_STYLE_STYLE, 48 XML_TOK_STYLE_PAGE_MASTER, 49 XML_TOK_TEXT_LIST_STYLE, 50 XML_TOK_TEXT_OUTLINE, 51 XML_TOK_STYLES_GRADIENTSTYLES, 52 XML_TOK_STYLES_HATCHSTYLES, 53 XML_TOK_STYLES_BITMAPSTYLES, 54 XML_TOK_STYLES_TRANSGRADIENTSTYLES, 55 XML_TOK_STYLES_MARKERSTYLES, 56 XML_TOK_STYLES_DASHSTYLES, 57 XML_TOK_TEXT_NOTE_CONFIG, 58 XML_TOK_TEXT_BIBLIOGRAPHY_CONFIG, 59 XML_TOK_TEXT_LINENUMBERING_CONFIG, 60 XML_TOK_STYLE_DEFAULT_STYLE, 61 XML_TOK_STYLE_DEFAULT_PAGE_LAYOUT, //text grid enhancement 62 XML_TOK_STYLE_STYLES_ELEM_END=XML_TOK_UNKNOWN 63 }; 64 65 class XMLOFF_DLLPUBLIC SvXMLStyleContext : public SvXMLImportContext 66 { 67 ::rtl::OUString maName; 68 ::rtl::OUString maDisplayName; 69 ::rtl::OUString maAutoName; 70 ::rtl::OUString maParentName;// Will be moved to XMLPropStyle soon!!!! 71 ::rtl::OUString maFollow; // Will be moved to XMLPropStyle soon!!!! 72 73 ::rtl::OUString maHelpFile; // Will be removed very soon!!!! 74 75 sal_uInt32 mnHelpId; // Will be removed very soon!!!! 76 sal_uInt16 mnFamily; 77 78 sal_Bool mbValid : 1; // Set this to false in CreateAndInsert 79 // if the style shouldn't be processed 80 // by Finish() or si somehow invalid. 81 sal_Bool mbNew : 1; // Set this to false in CreateAnsInsert 82 // if the style is already existing. 83 sal_Bool mbDefaultStyle : 1; 84 85 protected: 86 87 virtual void SetAttribute( sal_uInt16 nPrefixKey, 88 const ::rtl::OUString& rLocalName, 89 const ::rtl::OUString& rValue ); 90 SetFamily(sal_uInt16 nSet)91 void SetFamily( sal_uInt16 nSet ) { mnFamily = nSet; } SetAutoName(const::rtl::OUString & rName)92 void SetAutoName( const ::rtl::OUString& rName ) { maAutoName = rName; } 93 94 public: 95 96 TYPEINFO(); 97 98 SvXMLStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, 99 const ::rtl::OUString& rLName, 100 const ::com::sun::star::uno::Reference< 101 ::com::sun::star::xml::sax::XAttributeList >& xAttrList, 102 sal_uInt16 nFamily=0, sal_Bool bDefaultStyle = sal_False ); 103 104 virtual ~SvXMLStyleContext(); 105 106 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, 107 const ::rtl::OUString& rLocalName, 108 const ::com::sun::star::uno::Reference< 109 ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); 110 111 virtual void StartElement( 112 const ::com::sun::star::uno::Reference< 113 ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); 114 GetName() const115 const ::rtl::OUString& GetName() const { return maName; } GetDisplayName() const116 const ::rtl::OUString& GetDisplayName() const { return maDisplayName.getLength() ? maDisplayName : maName; } GetAutoName() const117 const ::rtl::OUString& GetAutoName() const { return maAutoName; } GetParentName() const118 const ::rtl::OUString& GetParentName() const { return maParentName; } GetFollow() const119 const ::rtl::OUString& GetFollow() const { return maFollow; } 120 GetHelpFile() const121 const ::rtl::OUString& GetHelpFile() const { return maHelpFile; } GetHelpId() const122 sal_uInt32 GetHelpId() const { return mnHelpId; } 123 GetFamily() const124 sal_uInt16 GetFamily() const { return mnFamily; } 125 IsValid() const126 sal_Bool IsValid() const { return mbValid; } SetValid(sal_Bool b)127 void SetValid( sal_Bool b ) { mbValid = b; } 128 IsNew() const129 sal_Bool IsNew() const { return mbNew; } SetNew(sal_Bool b)130 void SetNew( sal_Bool b ) { mbNew = b; } 131 132 // This method is called for every default style 133 virtual void SetDefaults(); 134 135 // This method is called for every style. It must create it and insert 136 // it into the document. 137 virtual void CreateAndInsert( sal_Bool bOverwrite ); 138 139 // This method is called for every style. It must create it and insert 140 // it into the document if this hasn't happened already in CreateAndInsert(). 141 virtual void CreateAndInsertLate( sal_Bool bOverwrite ); 142 143 // This method is called fpr every style after all styles have been 144 // inserted into the document. 145 virtual void Finish( sal_Bool bOverwrite ); 146 IsDefaultStyle() const147 sal_Bool IsDefaultStyle() const { return mbDefaultStyle; } 148 149 /** if this method returns true, its parent styles context 150 should not add it to its container.<br> 151 Transient styles can't be accessed from its 152 parent SvXMLStylesContext after theyre imported and 153 the methods CreateAndInsert(), CreateAndInsertLate() 154 and Finish() will not be called. 155 The default return value is false 156 */ 157 virtual sal_Bool IsTransient() const; 158 }; 159 160 class XMLOFF_DLLPUBLIC SvXMLStylesContext : public SvXMLImportContext 161 { 162 const ::rtl::OUString msParaStyleServiceName; 163 const ::rtl::OUString msTextStyleServiceName; 164 165 SvXMLStylesContext_Impl *mpImpl; 166 SvXMLTokenMap *mpStyleStylesElemTokenMap; 167 168 169 ::com::sun::star::uno::Reference < 170 ::com::sun::star::container::XNameContainer > mxParaStyles; 171 172 ::com::sun::star::uno::Reference < 173 ::com::sun::star::container::XNameContainer > mxTextStyles; 174 175 ::com::sun::star::uno::Reference < 176 ::com::sun::star::style::XAutoStyleFamily > mxParaAutoStyles; 177 178 ::com::sun::star::uno::Reference < 179 ::com::sun::star::style::XAutoStyleFamily > mxTextAutoStyles; 180 181 UniReference < SvXMLImportPropertyMapper > mxParaImpPropMapper; 182 UniReference < SvXMLImportPropertyMapper > mxTextImpPropMapper; 183 UniReference < SvXMLImportPropertyMapper > mxShapeImpPropMapper; 184 mutable UniReference < SvXMLImportPropertyMapper > mxChartImpPropMapper; 185 mutable UniReference < SvXMLImportPropertyMapper > mxPageImpPropMapper; 186 187 SAL_DLLPRIVATE const SvXMLTokenMap& GetStyleStylesElemTokenMap(); 188 189 SAL_DLLPRIVATE SvXMLStylesContext(SvXMLStylesContext &); // not defined 190 SAL_DLLPRIVATE void operator =(SvXMLStylesContext &); // not defined 191 192 protected: 193 194 sal_uInt32 GetStyleCount() const; 195 SvXMLStyleContext *GetStyle( sal_uInt32 i ); 196 const SvXMLStyleContext *GetStyle( sal_uInt32 i ) const; 197 198 virtual SvXMLStyleContext *CreateStyleChildContext( sal_uInt16 nPrefix, 199 const ::rtl::OUString& rLocalName, 200 const ::com::sun::star::uno::Reference< 201 ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); 202 203 virtual SvXMLStyleContext *CreateStyleStyleChildContext( sal_uInt16 nFamily, 204 sal_uInt16 nPrefix, const ::rtl::OUString& rLocalName, 205 const ::com::sun::star::uno::Reference< 206 ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); 207 208 virtual SvXMLStyleContext *CreateDefaultStyleStyleChildContext( 209 sal_uInt16 nFamily, sal_uInt16 nPrefix, 210 const ::rtl::OUString& rLocalName, 211 const ::com::sun::star::uno::Reference< 212 ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); 213 214 virtual sal_Bool InsertStyleFamily( sal_uInt16 nFamily ) const; 215 216 public: 217 TYPEINFO(); 218 219 SvXMLStylesContext( SvXMLImport& rImport, sal_uInt16 nPrfx, 220 const ::rtl::OUString& rLName, 221 const ::com::sun::star::uno::Reference< 222 ::com::sun::star::xml::sax::XAttributeList > & xAttrList, 223 sal_Bool bAutomatic = sal_False ); 224 225 virtual ~SvXMLStylesContext(); 226 227 // Create child element. 228 virtual SvXMLImportContext *CreateChildContext( sal_uInt16 nPrefix, 229 const ::rtl::OUString& rLocalName, 230 const ::com::sun::star::uno::Reference< 231 ::com::sun::star::xml::sax::XAttributeList > & xAttrList ); 232 233 // This method must be overloaded to insert styles into the document. 234 virtual void EndElement(); 235 236 // This allows to add an SvXMLStyleContext to this context from extern 237 void AddStyle(SvXMLStyleContext& rNew); 238 239 const SvXMLStyleContext *FindStyleChildContext( 240 sal_uInt16 nFamily, 241 const ::rtl::OUString& rName, 242 sal_Bool bCreateIndex=sal_False ) const; 243 virtual sal_uInt16 GetFamily( const ::rtl::OUString& rFamily ) const; 244 virtual UniReference < SvXMLImportPropertyMapper > GetImportPropertyMapper( 245 sal_uInt16 nFamily ) const; 246 247 virtual ::com::sun::star::uno::Reference < 248 ::com::sun::star::container::XNameContainer > 249 GetStylesContainer( sal_uInt16 nFamily ) const; 250 virtual ::rtl::OUString GetServiceName( sal_uInt16 nFamily ) const; 251 252 virtual ::com::sun::star::uno::Reference < ::com::sun::star::style::XAutoStyleFamily > 253 GetAutoStyles( sal_uInt16 nFamily ) const; 254 void CopyAutoStylesToDoc(); 255 void CopyStylesToDoc( sal_Bool bOverwrite, sal_Bool bFinish=sal_True ); 256 void FinishStyles( sal_Bool bOverwrite ); 257 258 // This method must be called to release the references to all styles 259 // that are stored in the context. 260 void Clear(); 261 sal_Bool IsAutomaticStyle() const; 262 }; 263 264 #endif // _XMLOFF_XMLSTYLE_HXX 265 266