xref: /aoo41x/main/xmloff/source/text/txtstyle.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_xmloff.hxx"
30 
31 #include <com/sun/star/style/ParagraphStyleCategory.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/beans/XPropertySetInfo.hpp>
34 #include <com/sun/star/beans/XPropertyState.hpp>
35 #include <com/sun/star/style/XStyle.hpp>
36 #include <xmloff/xmltoken.hxx>
37 #include "xmloff/xmlnmspe.hxx"
38 #include <xmloff/families.hxx>
39 #include <xmloff/txtparae.hxx>
40 #include <xmloff/xmlnume.hxx>
41 #include <xmloff/xmlexp.hxx>
42 #include "XMLSectionExport.hxx"
43 #include "XMLLineNumberingExport.hxx"
44 #include "txtexppr.hxx"
45 #include <xmloff/txtprmap.hxx>
46 
47 using ::rtl::OUString;
48 using ::rtl::OUStringBuffer;
49 
50 using namespace ::com::sun::star;
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::style;
53 using namespace ::com::sun::star::container;
54 using namespace ::com::sun::star::beans;
55 using namespace ::xmloff::token;
56 
57 void XMLTextParagraphExport::exportStyleAttributes(
58 		const ::com::sun::star::uno::Reference<
59 				::com::sun::star::style::XStyle > & rStyle )
60 {
61 	OUString sName;
62 	Any aAny;
63 	Reference< XPropertySet > xPropSet( rStyle, UNO_QUERY );
64 	Reference< XPropertySetInfo > xPropSetInfo(
65 			xPropSet->getPropertySetInfo());
66 	if( xPropSetInfo->hasPropertyByName( sCategory ) )
67 	{
68 		sal_Int16 nCategory = 0;
69 		xPropSet->getPropertyValue( sCategory ) >>= nCategory;
70 		enum XMLTokenEnum eValue = XML_TOKEN_INVALID;
71 		if( -1 != nCategory )
72 		{
73 			switch( nCategory )
74 			{
75 			case ParagraphStyleCategory::TEXT:
76 				eValue = XML_TEXT;
77 				break;
78 			case ParagraphStyleCategory::CHAPTER:
79 				eValue = XML_CHAPTER;
80 				break;
81 			case ParagraphStyleCategory::LIST:
82 				eValue = XML_LIST;
83 				break;
84 			case ParagraphStyleCategory::INDEX:
85 				eValue = XML_INDEX;
86 				break;
87 			case ParagraphStyleCategory::EXTRA:
88 				eValue = XML_EXTRA;
89 				break;
90 			case ParagraphStyleCategory::HTML:
91 				eValue = XML_HTML;
92 				break;
93 			}
94 		}
95 		if( eValue != XML_TOKEN_INVALID )
96 			GetExport().AddAttribute( XML_NAMESPACE_STYLE, XML_CLASS, eValue);
97 	}
98 	if( xPropSetInfo->hasPropertyByName( sPageDescName ) )
99 	{
100 		Reference< XPropertyState > xPropState( xPropSet, uno::UNO_QUERY );
101 		if( PropertyState_DIRECT_VALUE ==
102 				xPropState->getPropertyState( sPageDescName  ) )
103 		{
104 			xPropSet->getPropertyValue( sPageDescName ) >>= sName;
105 			// fix for #i5551#  if( sName.getLength() > 0 )
106 			    GetExport().AddAttribute( XML_NAMESPACE_STYLE,
107 				    					  XML_MASTER_PAGE_NAME,
108 					    				  GetExport().EncodeStyleName( sName ) );
109 		}
110 	}
111 	//sal_Int32 nOutlineLevel = //#outline level, zhaojianwei, moved to styleexp.cxx - XMLStyleExport::exportStyle(����)
112 	//	GetExport().GetTextParagraphExport()->GetHeadingLevel( rStyle->getName() );
113 	//if( nOutlineLevel != -1 )
114 	//{
115 	//	OUStringBuffer sTmp;
116 	//				sTmp.append( static_cast<sal_Int32>(nOutlineLevel+1L) );
117 	//	GetExport().AddAttribute( XML_NAMESPACE_STYLE,
118 	//						XML_DEFAULT_OUTLINE_LEVEL,
119 	//						sTmp.makeStringAndClear() );
120 	//}
121 
122 	if( bProgress )
123 	{
124 		ProgressBarHelper *pProgress = GetExport().GetProgressBarHelper();
125 			pProgress->SetValue( pProgress->GetValue()+2 );
126 	}
127 }
128 
129 void XMLTextParagraphExport::exportNumStyles( sal_Bool bUsed )
130 {
131 	SvxXMLNumRuleExport aNumRuleExport( GetExport() );
132 	aNumRuleExport.exportStyles( bUsed, pListAutoPool, !IsBlockMode() );
133 }
134 
135 void XMLTextParagraphExport::exportTextStyles( sal_Bool bUsed, sal_Bool bProg )
136 {
137 	sal_Bool bOldProg = bProgress;
138 	bProgress = bProg;
139 
140     Reference < lang::XMultiServiceFactory > xFactory (GetExport().GetModel(), UNO_QUERY);
141     if (xFactory.is())
142     {
143 		OUString sTextDefaults ( RTL_CONSTASCII_USTRINGPARAM ( "com.sun.star.text.Defaults" ) );
144         Reference < XPropertySet > xPropSet (xFactory->createInstance ( sTextDefaults ), UNO_QUERY);
145         if (xPropSet.is())
146         {
147             exportDefaultStyle( xPropSet, GetXMLToken(XML_PARAGRAPH), GetParaPropMapper());
148 
149             exportDefaultStyle(
150                 xPropSet,
151                 GetXMLToken(XML_TABLE),
152                 new XMLTextExportPropertySetMapper(
153                     new XMLTextPropertySetMapper(
154                         TEXT_PROP_MAP_TABLE_DEFAULTS ),
155                     GetExport() ) );
156 
157             exportDefaultStyle(
158                 xPropSet,
159                 GetXMLToken(XML_TABLE_ROW),
160                 new XMLTextExportPropertySetMapper(
161                     new XMLTextPropertySetMapper(
162                         TEXT_PROP_MAP_TABLE_ROW_DEFAULTS ),
163                     GetExport() ) );
164         }
165     }
166 	exportStyleFamily( "ParagraphStyles", GetXMLToken(XML_PARAGRAPH), GetParaPropMapper(),
167 					   bUsed, XML_STYLE_FAMILY_TEXT_PARAGRAPH, 0);
168 	exportStyleFamily( "CharacterStyles", GetXMLToken(XML_TEXT), GetTextPropMapper(),
169 					   bUsed, XML_STYLE_FAMILY_TEXT_TEXT );
170 	// get shape export to make sure the the frame family is added correctly.
171 	GetExport().GetShapeExport();
172 	exportStyleFamily( "FrameStyles", OUString(RTL_CONSTASCII_USTRINGPARAM(XML_STYLE_FAMILY_SD_GRAPHICS_NAME)), GetFramePropMapper(),
173 					   bUsed, XML_STYLE_FAMILY_TEXT_FRAME, 0);
174 	exportNumStyles( bUsed );
175 	if( !IsBlockMode() )
176 	{
177 		exportTextFootnoteConfiguration();
178 		XMLSectionExport::ExportBibliographyConfiguration(GetExport());
179 		XMLLineNumberingExport aLineNumberingExport(GetExport());
180 		aLineNumberingExport.Export();
181 	}
182 
183 	bProgress = bOldProg;
184 }
185