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