LibreOffice Module sw (master) 1
vbapagesetup.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
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"
25
26using namespace ::com::sun::star;
27using namespace ::ooo::vba;
28
29SwVbaPageSetup::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 )
34{
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;
39}
40
42{
43 // not support in Writer
44 return 0;
45}
46
47void SAL_CALL SwVbaPageSetup::setGutter( double _gutter )
48{
49 // default add gutter into left margin
50 if( _gutter != 0 )
51 {
52 double margin = VbaPageSetupBase::getLeftMargin() + _gutter;
54 }
55}
56
58{
59 bool isHeaderOn = false;
60 mxPageProps->getPropertyValue("HeaderIsOn") >>= isHeaderOn;
61 if( !isHeaderOn )
62 mxPageProps->setPropertyValue("HeaderIsOn", uno::Any( true ) );
64}
65
75void SAL_CALL SwVbaPageSetup::setHeaderDistance( double _headerdistance )
76{
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;
82
83 mxPageProps->getPropertyValue("HeaderIsOn") >>= isHeaderOn;
84 if( !isHeaderOn )
85 mxPageProps->setPropertyValue("HeaderIsOn", uno::Any( true ) );
86
87 mxPageProps->getPropertyValue("TopMargin") >>= currentTopMargin;
88 mxPageProps->getPropertyValue("HeaderBodyDistance") >>= currentSpacing;
89 mxPageProps->getPropertyValue("HeaderHeight") >>= currentHeaderHeight;
90
91 sal_Int32 newSpacing = currentSpacing - ( newHeaderDistance - currentTopMargin );
92 sal_Int32 height = currentHeaderHeight - currentSpacing;
93 sal_Int32 newHeaderHeight = newSpacing + height;
94
95 mxPageProps->setPropertyValue("TopMargin", uno::Any( newHeaderDistance ) );
96 mxPageProps->setPropertyValue("HeaderBodyDistance", uno::Any( newSpacing ) );
97 mxPageProps->setPropertyValue("HeaderHeight", uno::Any( newHeaderHeight ) );
98}
99
101{
102 bool isFooterOn = false;
103 mxPageProps->getPropertyValue("FooterIsOn") >>= isFooterOn;
104 if( !isFooterOn )
105 mxPageProps->setPropertyValue("FooterIsOn", uno::Any( true ) );
107}
108
109void SAL_CALL SwVbaPageSetup::setFooterDistance( double _footerdistance )
110{
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;
116
117 mxPageProps->getPropertyValue("FooterIsOn") >>= isFooterOn;
118 if( !isFooterOn )
119 mxPageProps->setPropertyValue("FooterIsOn", uno::Any( true ) );
120
121 mxPageProps->getPropertyValue("BottomMargin") >>= currentBottomMargin;
122 mxPageProps->getPropertyValue("FooterBodyDistance") >>= currentSpacing;
123 mxPageProps->getPropertyValue("FooterHeight") >>= currentFooterHeight;
124
125 sal_Int32 newSpacing = currentSpacing - ( newFooterDistance - currentBottomMargin );
126 sal_Int32 height = currentFooterHeight - currentSpacing;
127 sal_Int32 newFooterHeight = newSpacing + height;
128
129 mxPageProps->setPropertyValue("BottomMargin", uno::Any( newFooterDistance ) );
130 mxPageProps->setPropertyValue("FooterBodyDistance", uno::Any( newSpacing ) );
131 mxPageProps->setPropertyValue("FooterHeight", uno::Any( newFooterHeight ) );
132}
133
135{
136 OUString pageStyle = getStyleOfFirstPage();
137 if ( pageStyle == "First Page" )
138 return true;
139
140 return false;
141}
142
144{
145 if( status == getDifferentFirstPageHeaderFooter() )
146 return;
147
148 OUString newStyle;
149 if( status )
150 newStyle = "First Page";
151 else
152 newStyle = "Standard";
153
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;
167
168 bool isHeaderOn = false;
169 xStyleProps->getPropertyValue("HeaderIsOn") >>= isHeaderOn;
170 if( isHeaderOn )
171 {
172 nTopMargin += nHeaderHeight;
173 nBottomMargin += nFooterHeight;
174 xStyleProps->setPropertyValue("HeaderIsOn", uno::Any( false ) );
175 xStyleProps->setPropertyValue("FooterIsOn", uno::Any( false ) );
176 }
177 uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( mxModel ), uno::UNO_QUERY_THROW );
178 if( xPageCursor->getPage() != 1 )
179 {
180 xPageCursor->jumpToFirstPage();
181 }
182
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() )
186 {
187 xTableProps->setPropertyValue("PageDescName", uno::Any( newStyle ) );
188 }
189 else
190 {
191 xCursorProps->setPropertyValue("PageDescName", uno::Any( newStyle ) );
192 }
193
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 ) );
199}
200
202{
203 OUString styleFirstPage;
204 uno::Reference< text::XPageCursor > xPageCursor( word::getXTextViewCursor( mxModel ), uno::UNO_QUERY_THROW );
205 if( xPageCursor->getPage() != 1 )
206 {
207 xPageCursor->jumpToFirstPage();
208 }
209
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() )
213 {
214 xTableProps->getPropertyValue("PageDescName") >>= styleFirstPage;
215 }
216 else
217 {
218 xCursorProps->getPropertyValue("PageDescName") >>= styleFirstPage;
219 }
220 return styleFirstPage;
221}
222
224{
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;
236}
237
238void SAL_CALL SwVbaPageSetup::setSectionStart( ::sal_Int32 /*_sectionstart*/ )
239{
240 // fail to find corresponding feature in Writer
241 // #FIXME:
242}
243
244OUString
246{
247 return "SwVbaPageSetup";
248}
249
250uno::Sequence< OUString >
252{
253 static uno::Sequence< OUString > const aServiceNames
254 {
255 "ooo.vba.word.PageSetup"
256 };
257 return aServiceNames;
258}
259
260/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XModel2 > mxModel
virtual double SAL_CALL getGutter() override
virtual double SAL_CALL getHeaderDistance() override
virtual void SAL_CALL setDifferentFirstPageHeaderFooter(sal_Bool status) override
virtual OUString getServiceImplName() override
virtual void SAL_CALL setFooterDistance(double _footerdistance) override
virtual ::sal_Int32 SAL_CALL getSectionStart() override
virtual sal_Bool SAL_CALL getDifferentFirstPageHeaderFooter() override
virtual void SAL_CALL setSectionStart(::sal_Int32 _sectionstart) override
OUString getStyleOfFirstPage() const
SwVbaPageSetup(const css::uno::Reference< ooo::vba::XHelperInterface > &xParent, const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XModel > &xModel, const css::uno::Reference< css::beans::XPropertySet > &xProps)
virtual css::uno::Sequence< OUString > getServiceNames() override
virtual double SAL_CALL getFooterDistance() override
virtual void SAL_CALL setHeaderDistance(double _headerdistance) override
changes the value of TopMargin to the value of new MS-Word-HeaderDistance.
virtual void SAL_CALL setGutter(double _gutter) override
virtual double SAL_CALL getFooterMargin()
virtual double SAL_CALL getHeaderMargin()
virtual double SAL_CALL getLeftMargin() override
virtual void SAL_CALL setLeftMargin(double margin) override
Sequence< OUString > aServiceNames
tools::Long const nRightMargin
tools::Long const nBottomMargin
tools::Long const nTopMargin
tools::Long const nLeftMargin
uno::Reference< text::XTextViewCursor > getXTextViewCursor(const uno::Reference< frame::XModel > &xModel)
uno::Reference< style::XStyle > getCurrentPageStyle(const uno::Reference< frame::XModel > &xModel)
Reference< XModel > xModel
unsigned char sal_Bool
cppu::ImplInheritanceHelper< VbaPageSetupBase, ooo::vba::word::XPageSetup > SwVbaPageSetup_BASE