Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "vbapagesetup.hxx"
29 : : #include <com/sun/star/text/XText.hpp>
30 : : #include <com/sun/star/text/XPageCursor.hpp>
31 : : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
32 : : #include <com/sun/star/container/XNameAccess.hpp>
33 : : #include <ooo/vba/word/WdSectionStart.hpp>
34 : : #include <ooo/vba/word/WdOrientation.hpp>
35 : : #include "wordvbahelper.hxx"
36 : :
37 : : using namespace ::com::sun::star;
38 : : using namespace ::ooo::vba;
39 : :
40 : 0 : SwVbaPageSetup::SwVbaPageSetup(const uno::Reference< XHelperInterface >& xParent,
41 : : const uno::Reference< uno::XComponentContext >& xContext,
42 : : const uno::Reference< frame::XModel >& xModel,
43 : : const uno::Reference< beans::XPropertySet >& xProps ) throw (uno::RuntimeException):
44 : 0 : SwVbaPageSetup_BASE( xParent, xContext )
45 : : {
46 [ # # ]: 0 : mxModel.set( xModel, uno::UNO_QUERY_THROW );
47 [ # # ]: 0 : mxPageProps.set( xProps, uno::UNO_QUERY_THROW );
48 : 0 : mnOrientPortrait = word::WdOrientation::wdOrientPortrait;
49 : 0 : mnOrientLandscape = word::WdOrientation::wdOrientLandscape;
50 : 0 : }
51 : :
52 : 0 : double SAL_CALL SwVbaPageSetup::getGutter() throw (uno::RuntimeException)
53 : : {
54 : : // not support in Writer
55 : 0 : return 0;
56 : : }
57 : :
58 : 0 : void SAL_CALL SwVbaPageSetup::setGutter( double _gutter ) throw (uno::RuntimeException)
59 : : {
60 : : // default add gutter into left margin
61 [ # # ]: 0 : if( _gutter != 0 )
62 : : {
63 : 0 : double margin = VbaPageSetupBase::getLeftMargin() + _gutter;
64 : 0 : VbaPageSetupBase::setLeftMargin( margin );
65 : : }
66 : 0 : }
67 : :
68 : 0 : double SAL_CALL SwVbaPageSetup::getHeaderDistance() throw (uno::RuntimeException)
69 : : {
70 : 0 : sal_Bool isHeaderOn = sal_False;
71 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))) >>= isHeaderOn;
[ # # ]
72 [ # # ]: 0 : if( !isHeaderOn )
73 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn")), uno::makeAny( sal_True ) );
[ # # ][ # # ]
74 [ # # ]: 0 : return VbaPageSetupBase::getHeaderMargin();
75 : : }
76 : :
77 : : /**
78 : : * changes the value of TopMargin to the value of new MS-Word-HeaderDistance. Subtracts the difference
79 : : * between old TopMargin and the new headerDistance from the value of HeaderSpacing (which defines the
80 : : * space between the header and the body of the text). calculates the new HeaderHeight (= height of the
81 : : * header + headerBodyDistance).
82 : : *
83 : : * @param: headerDistance is the value that is set in MS Word for the distance from the top of the page
84 : : * to the header
85 : : */
86 : 0 : void SAL_CALL SwVbaPageSetup::setHeaderDistance( double _headerdistance ) throw (uno::RuntimeException)
87 : : {
88 [ # # ]: 0 : sal_Int32 newHeaderDistance = Millimeter::getInHundredthsOfOneMillimeter( _headerdistance );
89 : 0 : sal_Bool isHeaderOn = sal_False;
90 : 0 : sal_Int32 aktTopMargin = 0;
91 : 0 : sal_Int32 aktSpacing = 0;
92 : 0 : sal_Int32 aktHeaderHeight = 0;
93 : :
94 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))) >>= isHeaderOn;
[ # # ]
95 [ # # ]: 0 : if( !isHeaderOn )
96 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn")), uno::makeAny( sal_True ) );
[ # # ][ # # ]
97 : :
98 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin"))) >>= aktTopMargin;
[ # # ]
99 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderBodyDistance"))) >>= aktSpacing;
[ # # ]
100 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight"))) >>= aktHeaderHeight;
[ # # ]
101 : :
102 : 0 : sal_Int32 newSpacing = aktSpacing - ( newHeaderDistance - aktTopMargin );
103 : 0 : sal_Int32 height = aktHeaderHeight - aktSpacing;
104 : 0 : sal_Int32 newHeaderHeight = newSpacing + height;
105 : :
106 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin")), uno::makeAny( newHeaderDistance ) );
[ # # ][ # # ]
107 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderBodyDistance")), uno::makeAny( newSpacing ) );
[ # # ][ # # ]
108 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight")), uno::makeAny( newHeaderHeight ) );
[ # # ][ # # ]
109 : 0 : }
110 : :
111 : 0 : double SAL_CALL SwVbaPageSetup::getFooterDistance() throw (uno::RuntimeException)
112 : : {
113 : 0 : sal_Bool isFooterOn = sal_False;
114 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn"))) >>= isFooterOn;
[ # # ]
115 [ # # ]: 0 : if( !isFooterOn )
116 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")), uno::makeAny( sal_True ) );
[ # # ][ # # ]
117 [ # # ]: 0 : return VbaPageSetupBase::getFooterMargin();
118 : : }
119 : :
120 : 0 : void SAL_CALL SwVbaPageSetup::setFooterDistance( double _footerdistance ) throw (uno::RuntimeException)
121 : : {
122 [ # # ]: 0 : sal_Int32 newFooterDistance = Millimeter::getInHundredthsOfOneMillimeter( _footerdistance );
123 : 0 : sal_Bool isFooterOn = sal_False;
124 : 0 : sal_Int32 aktBottomMargin = 0;
125 : 0 : sal_Int32 aktSpacing = 0;
126 : 0 : sal_Int32 aktFooterHeight = 0;
127 : :
128 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn"))) >>= isFooterOn;
[ # # ]
129 [ # # ]: 0 : if( !isFooterOn )
130 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")), uno::makeAny( sal_True ) );
[ # # ][ # # ]
131 : :
132 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin"))) >>= aktBottomMargin;
[ # # ]
133 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterBodyDistance"))) >>= aktSpacing;
[ # # ]
134 [ # # ][ # # ]: 0 : mxPageProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight"))) >>= aktFooterHeight;
[ # # ]
135 : :
136 : 0 : sal_Int32 newSpacing = aktSpacing - ( newFooterDistance - aktBottomMargin );
137 : 0 : sal_Int32 height = aktFooterHeight - aktSpacing;
138 : 0 : sal_Int32 newFooterHeight = newSpacing + height;
139 : :
140 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin")), uno::makeAny( newFooterDistance ) );
[ # # ][ # # ]
141 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterBodyDistance")), uno::makeAny( newSpacing ) );
[ # # ][ # # ]
142 [ # # ][ # # ]: 0 : mxPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight")), uno::makeAny( newFooterHeight ) );
[ # # ][ # # ]
143 : 0 : }
144 : :
145 : 0 : sal_Bool SAL_CALL SwVbaPageSetup::getDifferentFirstPageHeaderFooter() throw (uno::RuntimeException)
146 : : {
147 [ # # ]: 0 : rtl::OUString pageStyle = getStyleOfFirstPage();
148 [ # # ]: 0 : if ( pageStyle == "First Page" )
149 : 0 : return sal_True;
150 : :
151 : 0 : return sal_False;
152 : : }
153 : :
154 : 0 : void SAL_CALL SwVbaPageSetup::setDifferentFirstPageHeaderFooter( sal_Bool status ) throw (uno::RuntimeException)
155 : : {
156 [ # # ][ # # ]: 0 : if( status == getDifferentFirstPageHeaderFooter() )
157 : 0 : return;
158 : :
159 : 0 : rtl::OUString newStyle;
160 [ # # ]: 0 : if( status )
161 [ # # ]: 0 : newStyle = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("First Page") );
162 : : else
163 [ # # ]: 0 : newStyle = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Standard") );
164 : :
165 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
166 : 0 : sal_Int32 nTopMargin = 0;
167 [ # # ][ # # ]: 0 : xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin"))) >>= nTopMargin;
[ # # ]
168 : 0 : sal_Int32 nBottomMargin = 0;
169 [ # # ][ # # ]: 0 : xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin"))) >>= nBottomMargin;
[ # # ]
170 : 0 : sal_Int32 nLeftMargin = 0;
171 [ # # ][ # # ]: 0 : xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin"))) >>= nLeftMargin;
[ # # ]
172 : 0 : sal_Int32 nRightMargin = 0;
173 [ # # ][ # # ]: 0 : xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin"))) >>= nRightMargin;
[ # # ]
174 : 0 : sal_Int32 nHeaderHeight = 0;
175 [ # # ][ # # ]: 0 : xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderHeight"))) >>= nHeaderHeight;
[ # # ]
176 : 0 : sal_Int32 nFooterHeight = 0;
177 [ # # ][ # # ]: 0 : xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterHeight"))) >>= nFooterHeight;
[ # # ]
178 : :
179 : 0 : sal_Bool isHeaderOn = sal_False;
180 [ # # ][ # # ]: 0 : xStyleProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn"))) >>= isHeaderOn;
[ # # ]
181 [ # # ]: 0 : if( isHeaderOn )
182 : : {
183 : 0 : nTopMargin += nHeaderHeight;
184 : 0 : nBottomMargin += nFooterHeight;
185 [ # # ][ # # ]: 0 : xStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("HeaderIsOn")), uno::makeAny( sal_False ) );
[ # # ][ # # ]
186 [ # # ][ # # ]: 0 : xStyleProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("FooterIsOn")), uno::makeAny( sal_False ) );
[ # # ][ # # ]
187 : : }
188 [ # # ][ # # ]: 0 : uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( mxModel ), uno::UNO_QUERY_THROW );
189 [ # # ][ # # ]: 0 : if( xPageCursor->getPage() != 1 )
[ # # ]
190 : : {
191 [ # # ][ # # ]: 0 : xPageCursor->jumpToFirstPage();
192 : : }
193 : :
194 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( xPageCursor, uno::UNO_QUERY_THROW );
195 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xTableProps( xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ), uno::UNO_QUERY );
[ # # ][ # # ]
196 [ # # ]: 0 : if( xTableProps.is() )
197 : : {
198 [ # # ][ # # ]: 0 : xTableProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageDescName") ), uno::makeAny( newStyle ) );
[ # # ][ # # ]
199 : : }
200 : : else
201 : : {
202 [ # # ][ # # ]: 0 : xCursorProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageDescName") ), uno::makeAny( newStyle ) );
[ # # ][ # # ]
203 : : }
204 : :
205 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xFirstPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
206 [ # # ][ # # ]: 0 : xFirstPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TopMargin") ), uno::makeAny( nTopMargin ) );
[ # # ][ # # ]
207 [ # # ][ # # ]: 0 : xFirstPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("BottomMargin") ), uno::makeAny( nBottomMargin ) );
[ # # ][ # # ]
208 [ # # ][ # # ]: 0 : xFirstPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("LeftMargin") ), uno::makeAny( nLeftMargin ) );
[ # # ][ # # ]
209 [ # # ][ # # ]: 0 : xFirstPageProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("RightMargin") ), uno::makeAny( nRightMargin ) );
[ # # ][ # # ]
210 : : }
211 : :
212 : 0 : rtl::OUString SwVbaPageSetup::getStyleOfFirstPage() throw (uno::RuntimeException)
213 : : {
214 : 0 : rtl::OUString styleFirstPage;
215 [ # # ][ # # ]: 0 : uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( mxModel ), uno::UNO_QUERY_THROW );
216 [ # # ][ # # ]: 0 : if( xPageCursor->getPage() != 1 )
[ # # ]
217 : : {
218 [ # # ][ # # ]: 0 : xPageCursor->jumpToFirstPage();
219 : : }
220 : :
221 [ # # ]: 0 : uno::Reference< beans::XPropertySet > xCursorProps( xPageCursor, uno::UNO_QUERY_THROW );
222 [ # # ][ # # ]: 0 : uno::Reference< beans::XPropertySet > xTableProps( xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextTable") ) ), uno::UNO_QUERY );
[ # # ][ # # ]
223 [ # # ]: 0 : if( xTableProps.is() )
224 : : {
225 [ # # ][ # # ]: 0 : xTableProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageDescName") ) ) >>= styleFirstPage;
[ # # ]
226 : : }
227 : : else
228 : : {
229 [ # # ][ # # ]: 0 : xCursorProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageDescName") ) ) >>= styleFirstPage;
[ # # ]
230 : : }
231 : 0 : return styleFirstPage;
232 : : }
233 : :
234 : 0 : ::sal_Int32 SAL_CALL SwVbaPageSetup::getSectionStart() throw (uno::RuntimeException)
235 : : {
236 : : // FIXME:
237 : 0 : sal_Int32 wdSectionStart = word::WdSectionStart::wdSectionNewPage;
238 [ # # ]: 0 : uno::Reference< container::XNamed > xNamed( mxPageProps, uno::UNO_QUERY_THROW );
239 [ # # ][ # # ]: 0 : rtl::OUString sStyleName = xNamed->getName();
240 [ # # ]: 0 : if ( sStyleName == "Left Page" )
241 : 0 : wdSectionStart = word::WdSectionStart::wdSectionEvenPage;
242 [ # # ]: 0 : else if ( sStyleName == "Right Page" )
243 : 0 : wdSectionStart = word::WdSectionStart::wdSectionOddPage;
244 : : else
245 : 0 : wdSectionStart = word::WdSectionStart::wdSectionNewPage;
246 : 0 : return wdSectionStart;
247 : : }
248 : :
249 : 0 : void SAL_CALL SwVbaPageSetup::setSectionStart( ::sal_Int32 /*_sectionstart*/ ) throw (uno::RuntimeException)
250 : : {
251 : : // fail to find corresponding feature in Writer
252 : : // #FIXME:
253 : 0 : }
254 : :
255 : : rtl::OUString
256 : 0 : SwVbaPageSetup::getServiceImplName()
257 : : {
258 : 0 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SwVbaPageSetup"));
259 : : }
260 : :
261 : : uno::Sequence< rtl::OUString >
262 : 0 : SwVbaPageSetup::getServiceNames()
263 : : {
264 [ # # ][ # # ]: 0 : static uno::Sequence< rtl::OUString > aServiceNames;
[ # # ][ # # ]
265 [ # # ]: 0 : if ( aServiceNames.getLength() == 0 )
266 : : {
267 : 0 : aServiceNames.realloc( 1 );
268 [ # # ]: 0 : aServiceNames[ 0 ] = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ooo.vba.word.PageSetup" ) );
269 : : }
270 : 0 : return aServiceNames;
271 : : }
272 : :
273 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|