1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir #include "vbaparagraphformat.hxx"
28*cdf0e10cSrcweir #include <vbahelper/vbahelper.hxx>
29*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
30*cdf0e10cSrcweir #include "wordvbahelper.hxx"
31*cdf0e10cSrcweir #include <com/sun/star/style/LineSpacingMode.hpp>
32*cdf0e10cSrcweir #include <ooo/vba/word/WdLineSpacing.hpp>
33*cdf0e10cSrcweir #include <ooo/vba/word/WdParagraphAlignment.hpp>
34*cdf0e10cSrcweir #include <ooo/vba/word/WdOutlineLevel.hpp>
35*cdf0e10cSrcweir #include <com/sun/star/style/ParagraphAdjust.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/style/BreakType.hpp>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using namespace ::ooo::vba;
40*cdf0e10cSrcweir using namespace ::com::sun::star;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir static const sal_Int16 CHARACTER_INDENT_FACTOR = 12;
43*cdf0e10cSrcweir static const sal_Int16 PERCENT100 = 100;
44*cdf0e10cSrcweir static const sal_Int16 PERCENT150 = 150;
45*cdf0e10cSrcweir static const sal_Int16 PERCENT200 = 200;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir SwVbaParagraphFormat::SwVbaParagraphFormat( const uno::Reference< ooo::vba::XHelperInterface >& rParent, const uno::Reference< uno::XComponentContext >& rContext, const uno::Reference< text::XTextDocument >& rTextDocument, const uno::Reference< beans::XPropertySet >& rParaProps ) : SwVbaParagraphFormat_BASE( rParent, rContext ), mxTextDocument( rTextDocument ), mxParaProps( rParaProps )
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir }
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir SwVbaParagraphFormat::~SwVbaParagraphFormat()
52*cdf0e10cSrcweir {
53*cdf0e10cSrcweir }
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir sal_Int32 SAL_CALL SwVbaParagraphFormat::getAlignment() throw (uno::RuntimeException)
56*cdf0e10cSrcweir {
57*cdf0e10cSrcweir     style::ParagraphAdjust aParaAdjust = style::ParagraphAdjust_LEFT;
58*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaAdjust") ) ) >>= aParaAdjust;
59*cdf0e10cSrcweir     return getMSWordAlignment( aParaAdjust );
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setAlignment( sal_Int32 _alignment ) throw (uno::RuntimeException)
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir     style::ParagraphAdjust aParaAdjust = ( style::ParagraphAdjust ) getOOoAlignment( _alignment );
65*cdf0e10cSrcweir     mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaAdjust") ), uno::makeAny( aParaAdjust ) );
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir float SAL_CALL SwVbaParagraphFormat::getFirstLineIndent() throw (uno::RuntimeException)
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     sal_Int32 indent = 0;
71*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaFirstLineIndent") ) ) >>= indent;
72*cdf0e10cSrcweir     return (float)( Millimeter::getInPoints( indent ) );
73*cdf0e10cSrcweir }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setFirstLineIndent( float _firstlineindent ) throw (uno::RuntimeException)
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     sal_Int32 indent = Millimeter::getInHundredthsOfOneMillimeter( _firstlineindent );
78*cdf0e10cSrcweir     mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaFirstLineIndent") ), uno::makeAny( indent ) );
79*cdf0e10cSrcweir }
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir uno::Any SAL_CALL SwVbaParagraphFormat::getKeepTogether() throw (uno::RuntimeException)
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir     sal_Bool bKeep = sal_False;
84*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaKeepTogether") ) ) >>= bKeep;
85*cdf0e10cSrcweir     return uno::makeAny ( bKeep );
86*cdf0e10cSrcweir }
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setKeepTogether( const uno::Any& _keeptogether ) throw (uno::RuntimeException)
89*cdf0e10cSrcweir {
90*cdf0e10cSrcweir     sal_Bool bKeep = sal_False;
91*cdf0e10cSrcweir     if( _keeptogether >>= bKeep )
92*cdf0e10cSrcweir     {
93*cdf0e10cSrcweir         mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaKeepTogether") ), uno::makeAny( bKeep ) );
94*cdf0e10cSrcweir     }
95*cdf0e10cSrcweir     else
96*cdf0e10cSrcweir     {
97*cdf0e10cSrcweir         DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir uno::Any SAL_CALL SwVbaParagraphFormat::getKeepWithNext() throw (uno::RuntimeException)
102*cdf0e10cSrcweir {
103*cdf0e10cSrcweir     sal_Bool bKeep = sal_False;
104*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaSplit") ) ) >>= bKeep;
105*cdf0e10cSrcweir     return uno::makeAny ( bKeep );
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setKeepWithNext( const uno::Any& _keepwithnext ) throw (uno::RuntimeException)
109*cdf0e10cSrcweir {
110*cdf0e10cSrcweir     sal_Bool bKeep = sal_False;
111*cdf0e10cSrcweir     if( _keepwithnext >>= bKeep )
112*cdf0e10cSrcweir     {
113*cdf0e10cSrcweir         mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaSplit") ), uno::makeAny( bKeep ) );
114*cdf0e10cSrcweir     }
115*cdf0e10cSrcweir     else
116*cdf0e10cSrcweir     {
117*cdf0e10cSrcweir         DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
118*cdf0e10cSrcweir     }
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir uno::Any SAL_CALL SwVbaParagraphFormat::getHyphenation() throw (uno::RuntimeException)
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     sal_Bool bHypn = sal_False;
124*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaIsHyphenation") ) ) >>= bHypn;
125*cdf0e10cSrcweir     return uno::makeAny ( bHypn );
126*cdf0e10cSrcweir }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setHyphenation( const uno::Any& _hyphenation ) throw (uno::RuntimeException)
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir     sal_Bool bHypn = sal_False;
131*cdf0e10cSrcweir     if( _hyphenation >>= bHypn )
132*cdf0e10cSrcweir     {
133*cdf0e10cSrcweir         mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaIsHyphenation") ), uno::makeAny( bHypn ) );
134*cdf0e10cSrcweir     }
135*cdf0e10cSrcweir     else
136*cdf0e10cSrcweir     {
137*cdf0e10cSrcweir         DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
138*cdf0e10cSrcweir     }
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir float SAL_CALL SwVbaParagraphFormat::getLineSpacing() throw (uno::RuntimeException)
142*cdf0e10cSrcweir {
143*cdf0e10cSrcweir     style::LineSpacing aLineSpacing;
144*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLineSpacing") ) ) >>= aLineSpacing;
145*cdf0e10cSrcweir     return getMSWordLineSpacing( aLineSpacing );
146*cdf0e10cSrcweir }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setLineSpacing( float _linespacing ) throw (uno::RuntimeException)
149*cdf0e10cSrcweir {
150*cdf0e10cSrcweir     style::LineSpacing aLineSpacing;
151*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLineSpacing") ) ) >>= aLineSpacing;
152*cdf0e10cSrcweir     aLineSpacing = getOOoLineSpacing( _linespacing, aLineSpacing.Mode );
153*cdf0e10cSrcweir     mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLineSpacing") ), uno::makeAny( aLineSpacing ) );
154*cdf0e10cSrcweir }
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir sal_Int32 SAL_CALL SwVbaParagraphFormat::getLineSpacingRule() throw (uno::RuntimeException)
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir     style::LineSpacing aLineSpacing;
159*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLineSpacing") ) ) >>= aLineSpacing;
160*cdf0e10cSrcweir     return getMSWordLineSpacingRule( aLineSpacing );
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setLineSpacingRule( sal_Int32 _linespacingrule ) throw (uno::RuntimeException)
164*cdf0e10cSrcweir {
165*cdf0e10cSrcweir     style::LineSpacing aLineSpacing = getOOoLineSpacingFromRule( _linespacingrule );
166*cdf0e10cSrcweir     mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLineSpacing") ), uno::makeAny( aLineSpacing ) );
167*cdf0e10cSrcweir }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir uno::Any SAL_CALL SwVbaParagraphFormat::getNoLineNumber() throw (uno::RuntimeException)
170*cdf0e10cSrcweir {
171*cdf0e10cSrcweir     sal_Bool noLineNum = sal_False;
172*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLineNumberCount") ) ) >>= noLineNum;
173*cdf0e10cSrcweir     return uno::makeAny ( noLineNum );
174*cdf0e10cSrcweir }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setNoLineNumber( const uno::Any& _nolinenumber ) throw (uno::RuntimeException)
177*cdf0e10cSrcweir {
178*cdf0e10cSrcweir     sal_Bool noLineNum = sal_False;
179*cdf0e10cSrcweir     if( _nolinenumber >>= noLineNum )
180*cdf0e10cSrcweir     {
181*cdf0e10cSrcweir         mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLineNumberCount") ), uno::makeAny( noLineNum ) );
182*cdf0e10cSrcweir     }
183*cdf0e10cSrcweir     else
184*cdf0e10cSrcweir     {
185*cdf0e10cSrcweir         DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
186*cdf0e10cSrcweir     }
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir sal_Int32 SAL_CALL SwVbaParagraphFormat::getOutlineLevel() throw (uno::RuntimeException)
190*cdf0e10cSrcweir {
191*cdf0e10cSrcweir     sal_Int32 nLevel = word::WdOutlineLevel::wdOutlineLevelBodyText;
192*cdf0e10cSrcweir     rtl::OUString aHeading;
193*cdf0e10cSrcweir     const rtl::OUString HEADING = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Heading") );
194*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaStyleName") ) ) >>= aHeading;
195*cdf0e10cSrcweir     if( aHeading.indexOf( HEADING ) == 0 )
196*cdf0e10cSrcweir     {
197*cdf0e10cSrcweir         // get the sub string after "Heading"
198*cdf0e10cSrcweir         nLevel = aHeading.copy( HEADING.getLength() ).toInt32();
199*cdf0e10cSrcweir     }
200*cdf0e10cSrcweir     return nLevel;
201*cdf0e10cSrcweir }
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setOutlineLevel( sal_Int32 /*_outlinelevel*/ ) throw (uno::RuntimeException)
204*cdf0e10cSrcweir {
205*cdf0e10cSrcweir     throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
206*cdf0e10cSrcweir }
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir uno::Any SAL_CALL SwVbaParagraphFormat::getPageBreakBefore() throw (uno::RuntimeException)
209*cdf0e10cSrcweir {
210*cdf0e10cSrcweir     style::BreakType aBreakType;
211*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BreakType") ) ) >>= aBreakType;
212*cdf0e10cSrcweir     sal_Bool bBreakBefore = ( aBreakType == style::BreakType_PAGE_BEFORE || aBreakType == style::BreakType_PAGE_BOTH );
213*cdf0e10cSrcweir     return uno::makeAny( bBreakBefore );
214*cdf0e10cSrcweir }
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setPageBreakBefore( const uno::Any& _breakbefore ) throw (uno::RuntimeException)
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir     sal_Bool bBreakBefore = sal_False;
219*cdf0e10cSrcweir     if( _breakbefore >>= bBreakBefore )
220*cdf0e10cSrcweir     {
221*cdf0e10cSrcweir         style::BreakType aBreakType;
222*cdf0e10cSrcweir         mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BreakType") ) ) >>= aBreakType;
223*cdf0e10cSrcweir         if( bBreakBefore )
224*cdf0e10cSrcweir         {
225*cdf0e10cSrcweir             if( aBreakType == style::BreakType_NONE )
226*cdf0e10cSrcweir                 aBreakType = style::BreakType_PAGE_BEFORE;
227*cdf0e10cSrcweir             else if ( aBreakType == style::BreakType_PAGE_AFTER )
228*cdf0e10cSrcweir                 aBreakType = style::BreakType_PAGE_BOTH;
229*cdf0e10cSrcweir         }
230*cdf0e10cSrcweir         else
231*cdf0e10cSrcweir         {
232*cdf0e10cSrcweir             if( aBreakType == style::BreakType_PAGE_BOTH )
233*cdf0e10cSrcweir                 aBreakType = style::BreakType_PAGE_AFTER;
234*cdf0e10cSrcweir             else if ( aBreakType == style::BreakType_PAGE_BEFORE )
235*cdf0e10cSrcweir                 aBreakType = style::BreakType_PAGE_AFTER;
236*cdf0e10cSrcweir         }
237*cdf0e10cSrcweir         mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BreakType") ), uno::makeAny( aBreakType ) );
238*cdf0e10cSrcweir     }
239*cdf0e10cSrcweir     else
240*cdf0e10cSrcweir     {
241*cdf0e10cSrcweir         DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
242*cdf0e10cSrcweir     }
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir float SAL_CALL SwVbaParagraphFormat::getSpaceBefore() throw (uno::RuntimeException)
246*cdf0e10cSrcweir {
247*cdf0e10cSrcweir     sal_Int32 nSpace = 0;
248*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaTopMargin") ) ) >>= nSpace;
249*cdf0e10cSrcweir     return (float)( Millimeter::getInPoints( nSpace ) );
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setSpaceBefore( float _space ) throw (uno::RuntimeException)
253*cdf0e10cSrcweir {
254*cdf0e10cSrcweir     sal_Int32 nSpace = Millimeter::getInHundredthsOfOneMillimeter( _space );
255*cdf0e10cSrcweir     mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaTopMargin") ), uno::makeAny( nSpace ) );
256*cdf0e10cSrcweir }
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir float SAL_CALL SwVbaParagraphFormat::getSpaceAfter() throw (uno::RuntimeException)
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir     sal_Int32 nSpace = 0;
261*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaBottomMargin") ) ) >>= nSpace;
262*cdf0e10cSrcweir     return (float)( Millimeter::getInPoints( nSpace ) );
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setSpaceAfter( float _space ) throw (uno::RuntimeException)
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir     sal_Int32 nSpace = Millimeter::getInHundredthsOfOneMillimeter( _space );
268*cdf0e10cSrcweir     mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaBottomMargin") ), uno::makeAny( nSpace ) );
269*cdf0e10cSrcweir }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir float SAL_CALL SwVbaParagraphFormat::getLeftIndent() throw (uno::RuntimeException)
272*cdf0e10cSrcweir {
273*cdf0e10cSrcweir     sal_Int32 nIndent = 0;
274*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLeftMargin") ) ) >>= nIndent;
275*cdf0e10cSrcweir     return (float)( Millimeter::getInPoints( nIndent ) );
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setLeftIndent( float _leftindent ) throw (uno::RuntimeException)
279*cdf0e10cSrcweir {
280*cdf0e10cSrcweir     sal_Int32 nIndent = Millimeter::getInHundredthsOfOneMillimeter( _leftindent );
281*cdf0e10cSrcweir     mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaLeftMargin") ), uno::makeAny( nIndent ) );
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir 
284*cdf0e10cSrcweir float SAL_CALL SwVbaParagraphFormat::getRightIndent() throw (uno::RuntimeException)
285*cdf0e10cSrcweir {
286*cdf0e10cSrcweir     sal_Int32 nIndent = 0;
287*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaRightMargin") ) ) >>= nIndent;
288*cdf0e10cSrcweir     return (float)( Millimeter::getInPoints( nIndent ) );
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setRightIndent( float _rightindent ) throw (uno::RuntimeException)
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir     sal_Int32 nIndent = Millimeter::getInHundredthsOfOneMillimeter( _rightindent );
294*cdf0e10cSrcweir     mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaRightMargin") ), uno::makeAny( nIndent ) );
295*cdf0e10cSrcweir }
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir uno::Any SAL_CALL SwVbaParagraphFormat::getTabStops() throw (uno::RuntimeException)
298*cdf0e10cSrcweir {
299*cdf0e10cSrcweir     throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
300*cdf0e10cSrcweir }
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setTabStops( const uno::Any& /*_tabstops*/ ) throw (uno::RuntimeException)
303*cdf0e10cSrcweir {
304*cdf0e10cSrcweir     throw uno::RuntimeException( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Not implemented") ), uno::Reference< uno::XInterface >() );
305*cdf0e10cSrcweir }
306*cdf0e10cSrcweir 
307*cdf0e10cSrcweir uno::Any SAL_CALL SwVbaParagraphFormat::getWidowControl() throw (uno::RuntimeException)
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir     sal_Bool bWidow = sal_False;
310*cdf0e10cSrcweir     sal_Int8 nWidow = 0;
311*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaWidows") ) ) >>= nWidow;
312*cdf0e10cSrcweir     sal_Int8 nOrphan = 0;
313*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaOrphans") ) ) >>= nOrphan;
314*cdf0e10cSrcweir     // if the amount of single lines on one page > 1 and the same of start and end of the paragraph,
315*cdf0e10cSrcweir     // true is retured.
316*cdf0e10cSrcweir     bWidow = ( nWidow > 1 && nOrphan == nWidow );
317*cdf0e10cSrcweir     return uno::makeAny( bWidow );
318*cdf0e10cSrcweir }
319*cdf0e10cSrcweir 
320*cdf0e10cSrcweir void SAL_CALL SwVbaParagraphFormat::setWidowControl( const uno::Any& _widowcontrol ) throw (uno::RuntimeException)
321*cdf0e10cSrcweir {
322*cdf0e10cSrcweir     // if we get true, the part of the paragraph on one page has to be
323*cdf0e10cSrcweir     // at least two lines
324*cdf0e10cSrcweir     sal_Bool bWidow = sal_False;
325*cdf0e10cSrcweir     if( _widowcontrol >>= bWidow )
326*cdf0e10cSrcweir     {
327*cdf0e10cSrcweir         sal_Int8 nControl = bWidow? 2:1;
328*cdf0e10cSrcweir         mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaWidows") ), uno::makeAny( nControl ) );
329*cdf0e10cSrcweir         mxParaProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ParaOrphans") ), uno::makeAny( nControl ) );
330*cdf0e10cSrcweir     }
331*cdf0e10cSrcweir     else
332*cdf0e10cSrcweir     {
333*cdf0e10cSrcweir         DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir }
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir style::LineSpacing SwVbaParagraphFormat::getOOoLineSpacing( float _lineSpace, sal_Int16 mode )
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     style::LineSpacing aLineSpacing;
340*cdf0e10cSrcweir     if( mode != style::LineSpacingMode::MINIMUM && mode != style::LineSpacingMode::FIX )
341*cdf0e10cSrcweir     {
342*cdf0e10cSrcweir         // special behaviour of word: if the space is set to these values, the rule and
343*cdf0e10cSrcweir         // the height are changed accordingly
344*cdf0e10cSrcweir         if( _lineSpace == CHARACTER_INDENT_FACTOR )
345*cdf0e10cSrcweir         {
346*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::PROP;
347*cdf0e10cSrcweir             aLineSpacing.Height = PERCENT100;
348*cdf0e10cSrcweir         }
349*cdf0e10cSrcweir         else if( _lineSpace == ( sal_Int16 )( CHARACTER_INDENT_FACTOR * 1.5 ) )
350*cdf0e10cSrcweir         {
351*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::PROP;
352*cdf0e10cSrcweir             aLineSpacing.Height = PERCENT150;
353*cdf0e10cSrcweir         }
354*cdf0e10cSrcweir         else if( _lineSpace == ( sal_Int16 )( ( CHARACTER_INDENT_FACTOR ) * 2 ) )
355*cdf0e10cSrcweir         {
356*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::PROP;
357*cdf0e10cSrcweir             aLineSpacing.Height = PERCENT200;
358*cdf0e10cSrcweir         }
359*cdf0e10cSrcweir         else
360*cdf0e10cSrcweir         {
361*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::FIX;
362*cdf0e10cSrcweir             aLineSpacing.Height = ( sal_Int16 )( Millimeter::getInHundredthsOfOneMillimeter( _lineSpace ) );
363*cdf0e10cSrcweir         }
364*cdf0e10cSrcweir     }
365*cdf0e10cSrcweir     else
366*cdf0e10cSrcweir     {
367*cdf0e10cSrcweir         aLineSpacing.Mode = mode;
368*cdf0e10cSrcweir         aLineSpacing.Height = ( sal_Int16 )( Millimeter::getInHundredthsOfOneMillimeter( _lineSpace ) );
369*cdf0e10cSrcweir     }
370*cdf0e10cSrcweir     return aLineSpacing;
371*cdf0e10cSrcweir }
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir style::LineSpacing SwVbaParagraphFormat::getOOoLineSpacingFromRule( sal_Int32 _linespacingrule )
374*cdf0e10cSrcweir {
375*cdf0e10cSrcweir     style::LineSpacing aLineSpacing;
376*cdf0e10cSrcweir     switch( _linespacingrule )
377*cdf0e10cSrcweir     {
378*cdf0e10cSrcweir         case word::WdLineSpacing::wdLineSpace1pt5:
379*cdf0e10cSrcweir         {
380*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::PROP;
381*cdf0e10cSrcweir             aLineSpacing.Height = PERCENT150;
382*cdf0e10cSrcweir             break;
383*cdf0e10cSrcweir         }
384*cdf0e10cSrcweir         case word::WdLineSpacing::wdLineSpaceAtLeast:
385*cdf0e10cSrcweir         {
386*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::MINIMUM;
387*cdf0e10cSrcweir             aLineSpacing.Height = getCharHeight();
388*cdf0e10cSrcweir             break;
389*cdf0e10cSrcweir         }
390*cdf0e10cSrcweir         case word::WdLineSpacing::wdLineSpaceDouble:
391*cdf0e10cSrcweir         {
392*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::PROP;
393*cdf0e10cSrcweir             aLineSpacing.Height = getCharHeight();
394*cdf0e10cSrcweir             break;
395*cdf0e10cSrcweir         }
396*cdf0e10cSrcweir         case word::WdLineSpacing::wdLineSpaceExactly:
397*cdf0e10cSrcweir         case word::WdLineSpacing::wdLineSpaceMultiple:
398*cdf0e10cSrcweir         {
399*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::FIX;
400*cdf0e10cSrcweir             aLineSpacing.Height = getCharHeight();
401*cdf0e10cSrcweir             break;
402*cdf0e10cSrcweir         }
403*cdf0e10cSrcweir         case word::WdLineSpacing::wdLineSpaceSingle:
404*cdf0e10cSrcweir         {
405*cdf0e10cSrcweir             aLineSpacing.Mode = style::LineSpacingMode::PROP;
406*cdf0e10cSrcweir             aLineSpacing.Height = PERCENT100;
407*cdf0e10cSrcweir             break;
408*cdf0e10cSrcweir         }
409*cdf0e10cSrcweir         default:
410*cdf0e10cSrcweir         {
411*cdf0e10cSrcweir             DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
412*cdf0e10cSrcweir             break;
413*cdf0e10cSrcweir         }
414*cdf0e10cSrcweir     }
415*cdf0e10cSrcweir     return aLineSpacing;
416*cdf0e10cSrcweir }
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir float SwVbaParagraphFormat::getMSWordLineSpacing( style::LineSpacing& rLineSpacing )
419*cdf0e10cSrcweir {
420*cdf0e10cSrcweir     float wdLineSpacing = 0;
421*cdf0e10cSrcweir     if( rLineSpacing.Mode != style::LineSpacingMode::PROP )
422*cdf0e10cSrcweir     {
423*cdf0e10cSrcweir         wdLineSpacing = (float)( Millimeter::getInPoints( rLineSpacing.Height ) );
424*cdf0e10cSrcweir     }
425*cdf0e10cSrcweir     else
426*cdf0e10cSrcweir     {
427*cdf0e10cSrcweir         wdLineSpacing = (float)( CHARACTER_INDENT_FACTOR * rLineSpacing.Height ) / PERCENT100;
428*cdf0e10cSrcweir     }
429*cdf0e10cSrcweir     return wdLineSpacing;
430*cdf0e10cSrcweir }
431*cdf0e10cSrcweir 
432*cdf0e10cSrcweir sal_Int32 SwVbaParagraphFormat::getMSWordLineSpacingRule( style::LineSpacing& rLineSpacing )
433*cdf0e10cSrcweir {
434*cdf0e10cSrcweir     sal_Int32 wdLineSpacing = word::WdLineSpacing::wdLineSpaceSingle;
435*cdf0e10cSrcweir     switch( rLineSpacing.Mode )
436*cdf0e10cSrcweir     {
437*cdf0e10cSrcweir         case style::LineSpacingMode::PROP:
438*cdf0e10cSrcweir         {
439*cdf0e10cSrcweir             switch( rLineSpacing.Height )
440*cdf0e10cSrcweir             {
441*cdf0e10cSrcweir                 case PERCENT100:
442*cdf0e10cSrcweir                 {
443*cdf0e10cSrcweir                     wdLineSpacing = word::WdLineSpacing::wdLineSpaceSingle;
444*cdf0e10cSrcweir                     break;
445*cdf0e10cSrcweir                 }
446*cdf0e10cSrcweir                 case PERCENT150:
447*cdf0e10cSrcweir                 {
448*cdf0e10cSrcweir                     wdLineSpacing = word::WdLineSpacing::wdLineSpace1pt5;
449*cdf0e10cSrcweir                     break;
450*cdf0e10cSrcweir                 }
451*cdf0e10cSrcweir                 case PERCENT200:
452*cdf0e10cSrcweir                 {
453*cdf0e10cSrcweir                     wdLineSpacing = word::WdLineSpacing::wdLineSpaceDouble;
454*cdf0e10cSrcweir                     break;
455*cdf0e10cSrcweir                 }
456*cdf0e10cSrcweir                 default:
457*cdf0e10cSrcweir                 {
458*cdf0e10cSrcweir                     wdLineSpacing = word::WdLineSpacing::wdLineSpaceMultiple;
459*cdf0e10cSrcweir                 }
460*cdf0e10cSrcweir             }
461*cdf0e10cSrcweir             break;
462*cdf0e10cSrcweir         }
463*cdf0e10cSrcweir         case style::LineSpacingMode::MINIMUM:
464*cdf0e10cSrcweir         {
465*cdf0e10cSrcweir             wdLineSpacing = word::WdLineSpacing::wdLineSpaceAtLeast;
466*cdf0e10cSrcweir             break;
467*cdf0e10cSrcweir         }
468*cdf0e10cSrcweir         case style::LineSpacingMode::FIX:
469*cdf0e10cSrcweir         case style::LineSpacingMode::LEADING:
470*cdf0e10cSrcweir         {
471*cdf0e10cSrcweir             wdLineSpacing = word::WdLineSpacing::wdLineSpaceExactly;
472*cdf0e10cSrcweir             break;
473*cdf0e10cSrcweir         }
474*cdf0e10cSrcweir         default:
475*cdf0e10cSrcweir         {
476*cdf0e10cSrcweir             DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
477*cdf0e10cSrcweir         }
478*cdf0e10cSrcweir     }
479*cdf0e10cSrcweir     return wdLineSpacing;
480*cdf0e10cSrcweir }
481*cdf0e10cSrcweir 
482*cdf0e10cSrcweir sal_Int16 SwVbaParagraphFormat::getCharHeight() throw (uno::RuntimeException)
483*cdf0e10cSrcweir {
484*cdf0e10cSrcweir     float fCharHeight = 0.0;
485*cdf0e10cSrcweir     mxParaProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CharHeight") ) ) >>= fCharHeight;
486*cdf0e10cSrcweir     return (sal_Int16)( Millimeter::getInHundredthsOfOneMillimeter( fCharHeight ) );
487*cdf0e10cSrcweir }
488*cdf0e10cSrcweir 
489*cdf0e10cSrcweir sal_Int32 SwVbaParagraphFormat::getOOoAlignment( sal_Int32 _alignment )
490*cdf0e10cSrcweir {
491*cdf0e10cSrcweir     sal_Int32 nParaAjust = style::ParagraphAdjust_LEFT;
492*cdf0e10cSrcweir     switch( _alignment )
493*cdf0e10cSrcweir     {
494*cdf0e10cSrcweir         case word::WdParagraphAlignment::wdAlignParagraphCenter:
495*cdf0e10cSrcweir         {
496*cdf0e10cSrcweir             nParaAjust = style::ParagraphAdjust_CENTER;
497*cdf0e10cSrcweir             break;
498*cdf0e10cSrcweir         }
499*cdf0e10cSrcweir         case word::WdParagraphAlignment::wdAlignParagraphJustify:
500*cdf0e10cSrcweir         {
501*cdf0e10cSrcweir             nParaAjust = style::ParagraphAdjust_BLOCK;
502*cdf0e10cSrcweir             break;
503*cdf0e10cSrcweir         }
504*cdf0e10cSrcweir         case word::WdParagraphAlignment::wdAlignParagraphLeft:
505*cdf0e10cSrcweir         {
506*cdf0e10cSrcweir             nParaAjust = style::ParagraphAdjust_LEFT;
507*cdf0e10cSrcweir             break;
508*cdf0e10cSrcweir         }
509*cdf0e10cSrcweir         case word::WdParagraphAlignment::wdAlignParagraphRight:
510*cdf0e10cSrcweir         {
511*cdf0e10cSrcweir             nParaAjust = style::ParagraphAdjust_RIGHT;
512*cdf0e10cSrcweir             break;
513*cdf0e10cSrcweir         }
514*cdf0e10cSrcweir         default:
515*cdf0e10cSrcweir         {
516*cdf0e10cSrcweir             DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
517*cdf0e10cSrcweir         }
518*cdf0e10cSrcweir     }
519*cdf0e10cSrcweir     return nParaAjust;
520*cdf0e10cSrcweir }
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir sal_Int32 SwVbaParagraphFormat::getMSWordAlignment( sal_Int32 _alignment )
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir     sal_Int32 wdAlignment = word::WdParagraphAlignment::wdAlignParagraphLeft;
525*cdf0e10cSrcweir     switch( _alignment )
526*cdf0e10cSrcweir     {
527*cdf0e10cSrcweir         case style::ParagraphAdjust_CENTER:
528*cdf0e10cSrcweir         {
529*cdf0e10cSrcweir             wdAlignment = word::WdParagraphAlignment::wdAlignParagraphCenter;
530*cdf0e10cSrcweir             break;
531*cdf0e10cSrcweir         }
532*cdf0e10cSrcweir         case style::ParagraphAdjust_LEFT:
533*cdf0e10cSrcweir         {
534*cdf0e10cSrcweir             wdAlignment = word::WdParagraphAlignment::wdAlignParagraphLeft;
535*cdf0e10cSrcweir             break;
536*cdf0e10cSrcweir         }
537*cdf0e10cSrcweir         case style::ParagraphAdjust_BLOCK:
538*cdf0e10cSrcweir         {
539*cdf0e10cSrcweir             wdAlignment = word::WdParagraphAlignment::wdAlignParagraphJustify;
540*cdf0e10cSrcweir             break;
541*cdf0e10cSrcweir         }
542*cdf0e10cSrcweir         case style::ParagraphAdjust_RIGHT:
543*cdf0e10cSrcweir         {
544*cdf0e10cSrcweir             wdAlignment = word::WdParagraphAlignment::wdAlignParagraphRight;
545*cdf0e10cSrcweir             break;
546*cdf0e10cSrcweir         }
547*cdf0e10cSrcweir         default:
548*cdf0e10cSrcweir         {
549*cdf0e10cSrcweir             DebugHelper::exception( SbERR_BAD_PARAMETER, rtl::OUString() );
550*cdf0e10cSrcweir         }
551*cdf0e10cSrcweir     }
552*cdf0e10cSrcweir     return wdAlignment;
553*cdf0e10cSrcweir }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir rtl::OUString&
556*cdf0e10cSrcweir SwVbaParagraphFormat::getServiceImplName()
557*cdf0e10cSrcweir {
558*cdf0e10cSrcweir 	static rtl::OUString sImplName( RTL_CONSTASCII_USTRINGPARAM("SwVbaParagraphFormat") );
559*cdf0e10cSrcweir 	return sImplName;
560*cdf0e10cSrcweir }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir uno::Sequence< rtl::OUString >
563*cdf0e10cSrcweir SwVbaParagraphFormat::getServiceNames()
564*cdf0e10cSrcweir {
565*cdf0e10cSrcweir 	static uno::Sequence< rtl::OUString > aServiceNames;
566*cdf0e10cSrcweir 	if ( aServiceNames.getLength() == 0 )
567*cdf0e10cSrcweir 	{
568*cdf0e10cSrcweir 		aServiceNames.realloc( 1 );
569*cdf0e10cSrcweir 		aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.ParagraphFormat" ) );
570*cdf0e10cSrcweir 	}
571*cdf0e10cSrcweir 	return aServiceNames;
572*cdf0e10cSrcweir }
573*cdf0e10cSrcweir 
574