android: Update app-specific/MIME type icons
[LibreOffice.git] / sw / source / ui / vba / vbapagesetup.cxx
blobb22437dbd2605012fc0fb3451c54a450f8fb7c60
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "vbapagesetup.hxx"
20 #include <com/sun/star/frame/XModel.hpp>
21 #include <com/sun/star/text/XPageCursor.hpp>
22 #include <ooo/vba/word/WdSectionStart.hpp>
23 #include <ooo/vba/word/WdOrientation.hpp>
24 #include "wordvbahelper.hxx"
26 using namespace ::com::sun::star;
27 using namespace ::ooo::vba;
29 SwVbaPageSetup::SwVbaPageSetup(const uno::Reference< XHelperInterface >& xParent,
30 const uno::Reference< uno::XComponentContext >& xContext,
31 const uno::Reference< frame::XModel >& xModel,
32 const uno::Reference< beans::XPropertySet >& xProps ):
33 SwVbaPageSetup_BASE( xParent, xContext )
35 mxModel.set( xModel, uno::UNO_SET_THROW );
36 mxPageProps.set( xProps, uno::UNO_SET_THROW );
37 mnOrientPortrait = word::WdOrientation::wdOrientPortrait;
38 mnOrientLandscape = word::WdOrientation::wdOrientLandscape;
41 double SAL_CALL SwVbaPageSetup::getGutter()
43 // not support in Writer
44 return 0;
47 void SAL_CALL SwVbaPageSetup::setGutter( double _gutter )
49 // default add gutter into left margin
50 if( _gutter != 0 )
52 double margin = VbaPageSetupBase::getLeftMargin() + _gutter;
53 VbaPageSetupBase::setLeftMargin( margin );
57 double SAL_CALL SwVbaPageSetup::getHeaderDistance()
59 bool isHeaderOn = false;
60 mxPageProps->getPropertyValue("HeaderIsOn") >>= isHeaderOn;
61 if( !isHeaderOn )
62 mxPageProps->setPropertyValue("HeaderIsOn", uno::Any( true ) );
63 return VbaPageSetupBase::getHeaderMargin();
66 /**
67 * changes the value of TopMargin to the value of new MS-Word-HeaderDistance. Subtracts the difference
68 * between old TopMargin and the new headerDistance from the value of HeaderSpacing (which defines the
69 * space between the header and the body of the text). calculates the new HeaderHeight (= height of the
70 * header + headerBodyDistance).
72 * @param: headerDistance is the value that is set in MS Word for the distance from the top of the page
73 * to the header
75 void SAL_CALL SwVbaPageSetup::setHeaderDistance( double _headerdistance )
77 sal_Int32 newHeaderDistance = Millimeter::getInHundredthsOfOneMillimeter( _headerdistance );
78 bool isHeaderOn = false;
79 sal_Int32 currentTopMargin = 0;
80 sal_Int32 currentSpacing = 0;
81 sal_Int32 currentHeaderHeight = 0;
83 mxPageProps->getPropertyValue("HeaderIsOn") >>= isHeaderOn;
84 if( !isHeaderOn )
85 mxPageProps->setPropertyValue("HeaderIsOn", uno::Any( true ) );
87 mxPageProps->getPropertyValue("TopMargin") >>= currentTopMargin;
88 mxPageProps->getPropertyValue("HeaderBodyDistance") >>= currentSpacing;
89 mxPageProps->getPropertyValue("HeaderHeight") >>= currentHeaderHeight;
91 sal_Int32 newSpacing = currentSpacing - ( newHeaderDistance - currentTopMargin );
92 sal_Int32 height = currentHeaderHeight - currentSpacing;
93 sal_Int32 newHeaderHeight = newSpacing + height;
95 mxPageProps->setPropertyValue("TopMargin", uno::Any( newHeaderDistance ) );
96 mxPageProps->setPropertyValue("HeaderBodyDistance", uno::Any( newSpacing ) );
97 mxPageProps->setPropertyValue("HeaderHeight", uno::Any( newHeaderHeight ) );
100 double SAL_CALL SwVbaPageSetup::getFooterDistance()
102 bool isFooterOn = false;
103 mxPageProps->getPropertyValue("FooterIsOn") >>= isFooterOn;
104 if( !isFooterOn )
105 mxPageProps->setPropertyValue("FooterIsOn", uno::Any( true ) );
106 return VbaPageSetupBase::getFooterMargin();
109 void SAL_CALL SwVbaPageSetup::setFooterDistance( double _footerdistance )
111 sal_Int32 newFooterDistance = Millimeter::getInHundredthsOfOneMillimeter( _footerdistance );
112 bool isFooterOn = false;
113 sal_Int32 currentBottomMargin = 0;
114 sal_Int32 currentSpacing = 0;
115 sal_Int32 currentFooterHeight = 0;
117 mxPageProps->getPropertyValue("FooterIsOn") >>= isFooterOn;
118 if( !isFooterOn )
119 mxPageProps->setPropertyValue("FooterIsOn", uno::Any( true ) );
121 mxPageProps->getPropertyValue("BottomMargin") >>= currentBottomMargin;
122 mxPageProps->getPropertyValue("FooterBodyDistance") >>= currentSpacing;
123 mxPageProps->getPropertyValue("FooterHeight") >>= currentFooterHeight;
125 sal_Int32 newSpacing = currentSpacing - ( newFooterDistance - currentBottomMargin );
126 sal_Int32 height = currentFooterHeight - currentSpacing;
127 sal_Int32 newFooterHeight = newSpacing + height;
129 mxPageProps->setPropertyValue("BottomMargin", uno::Any( newFooterDistance ) );
130 mxPageProps->setPropertyValue("FooterBodyDistance", uno::Any( newSpacing ) );
131 mxPageProps->setPropertyValue("FooterHeight", uno::Any( newFooterHeight ) );
134 sal_Bool SAL_CALL SwVbaPageSetup::getDifferentFirstPageHeaderFooter()
136 OUString pageStyle = getStyleOfFirstPage();
137 if ( pageStyle == "First Page" )
138 return true;
140 return false;
143 void SAL_CALL SwVbaPageSetup::setDifferentFirstPageHeaderFooter( sal_Bool status )
145 if( status == getDifferentFirstPageHeaderFooter() )
146 return;
148 OUString newStyle;
149 if( status )
150 newStyle = "First Page";
151 else
152 newStyle = "Standard";
154 uno::Reference< beans::XPropertySet > xStyleProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
155 sal_Int32 nTopMargin = 0;
156 xStyleProps->getPropertyValue("TopMargin") >>= nTopMargin;
157 sal_Int32 nBottomMargin = 0;
158 xStyleProps->getPropertyValue("BottomMargin") >>= nBottomMargin;
159 sal_Int32 nLeftMargin = 0;
160 xStyleProps->getPropertyValue("LeftMargin") >>= nLeftMargin;
161 sal_Int32 nRightMargin = 0;
162 xStyleProps->getPropertyValue("RightMargin") >>= nRightMargin;
163 sal_Int32 nHeaderHeight = 0;
164 xStyleProps->getPropertyValue("HeaderHeight") >>= nHeaderHeight;
165 sal_Int32 nFooterHeight = 0;
166 xStyleProps->getPropertyValue("FooterHeight") >>= nFooterHeight;
168 bool isHeaderOn = false;
169 xStyleProps->getPropertyValue("HeaderIsOn") >>= isHeaderOn;
170 if( isHeaderOn )
172 nTopMargin += nHeaderHeight;
173 nBottomMargin += nFooterHeight;
174 xStyleProps->setPropertyValue("HeaderIsOn", uno::Any( false ) );
175 xStyleProps->setPropertyValue("FooterIsOn", uno::Any( false ) );
177 uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( mxModel ), uno::UNO_QUERY_THROW );
178 if( xPageCursor->getPage() != 1 )
180 xPageCursor->jumpToFirstPage();
183 uno::Reference< beans::XPropertySet > xCursorProps( xPageCursor, uno::UNO_QUERY_THROW );
184 uno::Reference< beans::XPropertySet > xTableProps( xCursorProps->getPropertyValue("TextTable"), uno::UNO_QUERY );
185 if( xTableProps.is() )
187 xTableProps->setPropertyValue("PageDescName", uno::Any( newStyle ) );
189 else
191 xCursorProps->setPropertyValue("PageDescName", uno::Any( newStyle ) );
194 uno::Reference< beans::XPropertySet > xFirstPageProps( word::getCurrentPageStyle( mxModel ), uno::UNO_QUERY_THROW );
195 xFirstPageProps->setPropertyValue("TopMargin", uno::Any( nTopMargin ) );
196 xFirstPageProps->setPropertyValue("BottomMargin", uno::Any( nBottomMargin ) );
197 xFirstPageProps->setPropertyValue("LeftMargin", uno::Any( nLeftMargin ) );
198 xFirstPageProps->setPropertyValue("RightMargin", uno::Any( nRightMargin ) );
201 OUString SwVbaPageSetup::getStyleOfFirstPage() const
203 OUString styleFirstPage;
204 uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( mxModel ), uno::UNO_QUERY_THROW );
205 if( xPageCursor->getPage() != 1 )
207 xPageCursor->jumpToFirstPage();
210 uno::Reference< beans::XPropertySet > xCursorProps( xPageCursor, uno::UNO_QUERY_THROW );
211 uno::Reference< beans::XPropertySet > xTableProps( xCursorProps->getPropertyValue("TextTable"), uno::UNO_QUERY );
212 if( xTableProps.is() )
214 xTableProps->getPropertyValue("PageDescName") >>= styleFirstPage;
216 else
218 xCursorProps->getPropertyValue("PageDescName") >>= styleFirstPage;
220 return styleFirstPage;
223 ::sal_Int32 SAL_CALL SwVbaPageSetup::getSectionStart()
225 // FIXME:
226 sal_Int32 wdSectionStart = word::WdSectionStart::wdSectionNewPage;
227 uno::Reference< container::XNamed > xNamed( mxPageProps, uno::UNO_QUERY_THROW );
228 OUString sStyleName = xNamed->getName();
229 if ( sStyleName == "Left Page" )
230 wdSectionStart = word::WdSectionStart::wdSectionEvenPage;
231 else if ( sStyleName == "Right Page" )
232 wdSectionStart = word::WdSectionStart::wdSectionOddPage;
233 else
234 wdSectionStart = word::WdSectionStart::wdSectionNewPage;
235 return wdSectionStart;
238 void SAL_CALL SwVbaPageSetup::setSectionStart( ::sal_Int32 /*_sectionstart*/ )
240 // fail to find corresponding feature in Writer
241 // #FIXME:
244 OUString
245 SwVbaPageSetup::getServiceImplName()
247 return "SwVbaPageSetup";
250 uno::Sequence< OUString >
251 SwVbaPageSetup::getServiceNames()
253 static uno::Sequence< OUString > const aServiceNames
255 "ooo.vba.word.PageSetup"
257 return aServiceNames;
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */