LibreOffice Module sw (master) 1
PageFormatPanel.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 <sal/config.h>
20#include <sal/log.hxx>
21#include <swtypes.hxx>
22#include <svl/intitem.hxx>
23#include <editeng/sizeitem.hxx>
24#include <editeng/paperinf.hxx>
25#include <svx/dlgutil.hxx>
26#include <svx/rulritem.hxx>
27#include <svx/svdtrans.hxx>
28#include "PageFormatPanel.hxx"
29#include "PageMarginUtils.hxx"
30#include <sfx2/dispatch.hxx>
31#include <sfx2/bindings.hxx>
32#include <sfx2/module.hxx>
33#include <sfx2/objsh.hxx>
34#include <sfx2/viewfrm.hxx>
35#include <pageformatpanel.hrc>
36#include <cmdid.h>
39#include <vcl/settings.hxx>
40#include <vcl/svapp.hxx>
41
42#include <com/sun/star/lang/IllegalArgumentException.hpp>
43
44namespace sw::sidebar{
45
46std::unique_ptr<PanelLayout> PageFormatPanel::Create(
47 weld::Widget* pParent,
48 SfxBindings* pBindings)
49{
50 if( pParent == nullptr )
51 throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageFormatPanel::Create", nullptr, 0);
52
53 return std::make_unique<PageFormatPanel>(pParent, pBindings);
54}
55
57{
58 auto nSelected = mxMarginSelectBox->get_active();
59 mxMarginSelectBox->clear();
60
62 if (IsInch(meFUnit))
63 {
64 OUString sSuffix = weld::MetricSpinButton::MetricToString(FieldUnit::INCH);
65 for (size_t i = 0; i < SAL_N_ELEMENTS(RID_PAGEFORMATPANEL_MARGINS_INCH); ++i)
66 {
67 OUString sStr = rLocaleData.getNum(RID_PAGEFORMATPANEL_MARGINS_INCH[i].second, 2, true, false) + sSuffix;
68 mxMarginSelectBox->append_text(SwResId(RID_PAGEFORMATPANEL_MARGINS_INCH[i].first).replaceFirst("%1", sStr));
69 }
70 }
71 else
72 {
73 OUString sSuffix = weld::MetricSpinButton::MetricToString(FieldUnit::CM);
74 for (size_t i = 0; i < SAL_N_ELEMENTS(RID_PAGEFORMATPANEL_MARGINS_CM); ++i)
75 {
76 OUString sStr = rLocaleData.getNum(RID_PAGEFORMATPANEL_MARGINS_CM[i].second, 2, true, false) + " " + sSuffix;
77 mxMarginSelectBox->append_text(SwResId(RID_PAGEFORMATPANEL_MARGINS_CM[i].first).replaceFirst("%1", sStr));
78 }
79 }
80 mxMarginSelectBox->set_active(nSelected);
81}
82
84 PanelLayout(pParent, "PageFormatPanel", "modules/swriter/ui/pageformatpanel.ui"),
85 mpBindings( pBindings ),
86 mxPaperSizeBox(new SvxPaperSizeListBox(m_xBuilder->weld_combo_box("papersize"))),
87 mxPaperWidth(new SvxRelativeField(m_xBuilder->weld_metric_spin_button("paperwidth", FieldUnit::CM))),
88 mxPaperHeight(new SvxRelativeField(m_xBuilder->weld_metric_spin_button("paperheight", FieldUnit::CM))),
89 mxPaperOrientation(m_xBuilder->weld_combo_box("paperorientation")),
90 mxMarginSelectBox(m_xBuilder->weld_combo_box("marginLB")),
91 mxCustomEntry(m_xBuilder->weld_label("customlabel")),
92 maPaperSizeController(SID_ATTR_PAGE_SIZE, *pBindings, *this),
93 maPaperOrientationController(SID_ATTR_PAGE, *pBindings, *this),
94 maMetricController(SID_ATTR_METRIC, *pBindings,*this),
95 maSwPageLRControl(SID_ATTR_PAGE_LRSPACE, *pBindings, *this),
96 maSwPageULControl(SID_ATTR_PAGE_ULSPACE, *pBindings, *this),
97 mpPageItem( new SvxPageItem(SID_ATTR_PAGE) ),
98 mpPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ),
99 mpPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ),
100 meFUnit(GetModuleFieldUnit()),
101 meUnit()
102{
103 Initialize();
104}
105
107{
108 mxPaperSizeBox.reset();
109 mxPaperWidth.reset();
110 mxPaperHeight.reset();
111 mxPaperOrientation.reset();
112 mxMarginSelectBox.reset();
113 mxCustomEntry.reset();
114
120 mpPageULMarginItem.reset();
121 mpPageLRMarginItem.reset();
122 mpPageItem.reset();
123}
124
126{
127 mxPaperSizeBox->FillPaperSizeEntries( PaperSizeApp::Std );
130 mxPaperWidth->SetFieldUnit(meFUnit);
131 mxPaperHeight->SetFieldUnit(meFUnit);
133 m_aCustomEntry = mxCustomEntry->get_label();
134
135 mxPaperWidth->set_max(mxPaperWidth->normalize(SvtOptionsDrawinglayer::GetMaximumPaperWidth()), FieldUnit::CM);
137
138 mxPaperSizeBox->connect_changed( LINK(this, PageFormatPanel, PaperFormatModifyHdl ));
139 mxPaperOrientation->connect_changed( LINK(this, PageFormatPanel, PaperFormatModifyHdl ));
140 mxPaperHeight->connect_value_changed( LINK(this, PageFormatPanel, PaperSizeModifyHdl ));
141 mxPaperWidth->connect_value_changed( LINK(this, PageFormatPanel, PaperSizeModifyHdl ));
142 mxMarginSelectBox->connect_changed( LINK(this, PageFormatPanel, PaperModifyMarginHdl));
143
144 mpBindings->Update(SID_ATTR_METRIC);
145 mpBindings->Update(SID_ATTR_PAGE);
146 mpBindings->Update(SID_ATTR_PAGE_SIZE);
147 mpBindings->Update(SID_ATTR_PAGE_LRSPACE);
148 mpBindings->Update(SID_ATTR_PAGE_ULSPACE);
149
151}
152
154 const sal_uInt16 nSId,
155 const SfxItemState eState,
156 const SfxPoolItem* pState)
157{
158 switch(nSId)
159 {
160 case SID_ATTR_PAGE_SIZE:
161 {
162 const SvxSizeItem* pSizeItem = nullptr;
163 if (eState >= SfxItemState::DEFAULT)
164 pSizeItem = dynamic_cast< const SvxSizeItem* >(pState);
165 if (pSizeItem)
166 {
167 Size aPaperSize = pSizeItem->GetSize();
168
169 mxPaperWidth->set_value(mxPaperWidth->normalize(aPaperSize.Width()), FieldUnit::TWIP);
170 mxPaperHeight->set_value(mxPaperHeight->normalize(aPaperSize.Height()), FieldUnit::TWIP);
171
172 if(mxPaperOrientation->get_active() == 1)
173 Swap(aPaperSize);
174
175 Paper ePaper = SvxPaperInfo::GetSvxPaper(aPaperSize, meUnit);
176 mxPaperSizeBox->set_active_id( ePaper );
177 }
178 }
179 break;
180 case SID_ATTR_METRIC:
181 {
183 FieldUnit eFUnit = GetCurrentUnit(eState, pState);
184 if (eFUnit != meFUnit)
185 {
186 meFUnit = eFUnit;
187 mxPaperHeight->SetFieldUnit(meFUnit);
188 mxPaperWidth->SetFieldUnit(meFUnit);
191 }
192 }
193 break;
194 case SID_ATTR_PAGE:
195 {
196 if ( eState >= SfxItemState::DEFAULT &&
197 dynamic_cast< const SvxPageItem *>( pState ) )
198 {
199 mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) );
200 if ( mpPageItem->IsLandscape() )
201 mxPaperOrientation->set_active(1);
202 else
203 mxPaperOrientation->set_active(0);
204 }
205 }
206 break;
207 case SID_ATTR_PAGE_LRSPACE:
208 {
209 if ( eState >= SfxItemState::DEFAULT &&
210 dynamic_cast< const SvxLongLRSpaceItem *>( pState ) )
211 {
212 mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
214 }
215 }
216 break;
217 case SID_ATTR_PAGE_ULSPACE:
218 {
219 if ( eState >= SfxItemState::DEFAULT &&
220 dynamic_cast< const SvxLongULSpaceItem *>( pState ) )
221 {
222 mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
224 }
225 }
226 break;
227 default:
228 break;
229 }
230}
231
232IMPL_LINK_NOARG(PageFormatPanel, PaperFormatModifyHdl, weld::ComboBox&, void)
233{
234 Paper ePaper = mxPaperSizeBox->get_active_id();
235 Size aSize;
236
237 if(ePaper!=PAPER_USER)
238 aSize = SvxPaperInfo::GetPaperSize(ePaper, meUnit);
239 else
240 aSize = Size(mxPaperWidth->GetCoreValue(meUnit), mxPaperHeight->GetCoreValue(meUnit));
241
242 if (mxPaperOrientation->get_active() == 1 || ePaper==PAPER_USER)
243 Swap(aSize);
244
245 mpPageItem->SetLandscape(mxPaperOrientation->get_active() == 1);
246 SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, aSize);
247 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem, mpPageItem.get() });
248}
249
251{
252 Size aSize(mxPaperWidth->GetCoreValue(meUnit), mxPaperHeight->GetCoreValue(meUnit));
253 SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, aSize);
254 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem });
255}
256
257IMPL_LINK_NOARG(PageFormatPanel, PaperModifyMarginHdl, weld::ComboBox&, void)
258{
259 bool bMirrored = false;
260 bool bApplyNewPageMargins = true;
261 switch (mxMarginSelectBox->get_active())
262 {
263 case 0:
264 SetNone(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
265 break;
266 case 1:
267 SetNarrow(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
268 break;
269 case 2:
270 SetModerate(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
271 break;
272 case 3:
273 SetNormal075(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
274 break;
275 case 4:
276 SetNormal100(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
277 break;
278 case 5:
279 SetNormal125(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
280 break;
281 case 6:
282 SetWide(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
283 break;
284 case 7:
285 SetMirrored(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
286 break;
287 default:
288 bApplyNewPageMargins = false;
289 break;
290 }
291
292 if(bApplyNewPageMargins)
293 {
294 ExecuteMarginLRChange( mnPageLeftMargin, mnPageRightMargin );
295 ExecuteMarginULChange( mnPageTopMargin, mnPageBottomMargin );
296 if(bMirrored != (mpPageItem->GetPageUsage() == SvxPageUsage::Mirror))
297 {
298 mpPageItem->SetPageUsage( bMirrored ? SvxPageUsage::Mirror : SvxPageUsage::All );
299 mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE,
300 SfxCallMode::RECORD, { mpPageItem.get() });
301 }
302 }
303}
304
306{
307 FieldUnit eUnit = FieldUnit::NONE;
308
309 if ( pState && eState >= SfxItemState::DEFAULT )
310 eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
311 else
312 {
314 SfxObjectShell* pSh = nullptr;
315 if ( pFrame )
316 pSh = pFrame->GetObjectShell();
317 if ( pSh )
318 {
319 SfxModule* pModule = pSh->GetModule();
320 if ( pModule )
321 {
322 const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
323 if ( pItem )
324 eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
325 }
326 else
327 {
328 SAL_WARN("sw.ui", "GetModuleFieldUnit(): no module found");
329 }
330 }
331 }
332
333 return eUnit;
334}
335
336void PageFormatPanel::ExecuteMarginLRChange( const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin )
337{
338 mpPageLRMarginItem->SetLeft( nPageLeftMargin );
339 mpPageLRMarginItem->SetRight( nPageRightMargin );
340 mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, SfxCallMode::RECORD, { mpPageLRMarginItem.get() });
341}
342
343void PageFormatPanel::ExecuteMarginULChange(const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin)
344{
345 mpPageULMarginItem->SetUpper( nPageTopMargin );
346 mpPageULMarginItem->SetLower( nPageBottomMargin );
347 mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, SfxCallMode::RECORD, { mpPageULMarginItem.get() });
348}
349
351{
356
357 int nCustomEntry = mxMarginSelectBox->find_text(m_aCustomEntry);
358
359 bool bMirrored = (mpPageItem->GetPageUsage() == SvxPageUsage::Mirror);
361 {
362 mxMarginSelectBox->set_active(0);
363 if (nCustomEntry != -1)
364 mxMarginSelectBox->remove(nCustomEntry);
365 }
367 {
368 mxMarginSelectBox->set_active(1);
369 if (nCustomEntry != -1)
370 mxMarginSelectBox->remove(nCustomEntry);
371 }
373 {
374 mxMarginSelectBox->set_active(2);
375 if (nCustomEntry != -1)
376 mxMarginSelectBox->remove(nCustomEntry);
377 }
379 {
380 mxMarginSelectBox->set_active(3);
381 if (nCustomEntry != -1)
382 mxMarginSelectBox->remove(nCustomEntry);
383 }
385 {
386 mxMarginSelectBox->set_active(4);
387 if (nCustomEntry != -1)
388 mxMarginSelectBox->remove(nCustomEntry);
389 }
391 {
392 mxMarginSelectBox->set_active(5);
393 if (nCustomEntry != -1)
394 mxMarginSelectBox->remove(nCustomEntry);
395 }
397 {
398 mxMarginSelectBox->set_active(6);
399 if (nCustomEntry != -1)
400 mxMarginSelectBox->remove(nCustomEntry);
401 }
403 {
404 mxMarginSelectBox->set_active(7);
405 if (nCustomEntry != -1)
406 mxMarginSelectBox->remove(nCustomEntry);
407 }
408 else
409 {
410 if (nCustomEntry == -1)
411 mxMarginSelectBox->append_text(m_aCustomEntry);
412 mxMarginSelectBox->set_active_text(m_aCustomEntry);
413 }
414}
415
416}
417
418/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const LocaleDataWrapper & GetLocaleDataWrapper() const
static const AllSettings & GetSettings()
OUString getNum(sal_Int64 nNumber, sal_uInt16 nDecimals, bool bUseThousandSep=true, bool bTrailingZeros=true) const
void Update(sal_uInt16 nId)
SfxDispatcher * GetDispatcher() const
void SetFallbackCoreMetric(MapUnit eFallback)
virtual void dispose()
MapUnit GetCoreMetric() const
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SfxModule * GetModule() const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
static SfxViewFrame * Current()
virtual SfxObjectShell * GetObjectShell() override
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static Paper GetSvxPaper(const Size &rSize, MapUnit eUnit)
static Size GetPaperSize(Paper ePaper, MapUnit eUnit=MapUnit::MapTwip)
const Size & GetSize() const
PageFormatPanel(weld::Widget *pParent, SfxBindings *pBindings)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
std::unique_ptr< SvxRelativeField > mxPaperWidth
virtual ~PageFormatPanel() override
::sfx2::sidebar::ControllerItem maSwPageLRControl
::sfx2::sidebar::ControllerItem maSwPageULControl
::sfx2::sidebar::ControllerItem maPaperSizeController
std::unique_ptr< SvxLongULSpaceItem > mpPageULMarginItem
std::unique_ptr< SvxPaperSizeListBox > mxPaperSizeBox
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
void ExecuteMarginULChange(const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin)
std::unique_ptr< SvxPageItem > mpPageItem
std::unique_ptr< weld::Label > mxCustomEntry
std::unique_ptr< weld::ComboBox > mxMarginSelectBox
::sfx2::sidebar::ControllerItem maPaperOrientationController
void ExecuteMarginLRChange(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin)
std::unique_ptr< weld::ComboBox > mxPaperOrientation
static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem *pState)
std::unique_ptr< SvxLongLRSpaceItem > mpPageLRMarginItem
::sfx2::sidebar::ControllerItem maMetricController
std::unique_ptr< SvxRelativeField > mxPaperHeight
static OUString MetricToString(FieldUnit rUnit)
SVXCORE_DLLPUBLIC FieldUnit GetModuleFieldUnit(const SfxItemSet &)
FieldUnit
OUString sSuffix
#define SAL_WARN(area, stream)
#define SAL_N_ELEMENTS(arr)
sal_uInt32 GetMaximumPaperHeight()
sal_uInt32 GetMaximumPaperWidth()
int i
constexpr OUStringLiteral first
void SetNone(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsNarrow(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
bool IsWide(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
bool IsMirrored(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetModerate(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsModerate(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetWide(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
void SetNormal125(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
void SetNarrow(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsNone(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
void SetNormal100(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsNormal125(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
bool IsNormal100(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetNormal075(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
bool IsNormal075(const tools::Long nPageLeftMargin, const tools::Long nPageRightMargin, const tools::Long nPageTopMargin, const tools::Long nPageBottomMargin, bool bMirrored)
void SetMirrored(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
long Long
const char GetValue[]
Paper
PAPER_USER
Size & Swap(Size &rSize)
SfxItemState
bool IsInch(MapUnit eU)
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164