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/svxids.hrc>
26 #include <svx/dlgutil.hxx>
27 #include <svx/rulritem.hxx>
28 #include <svx/svdtrans.hxx>
29 #include "PageFormatPanel.hxx"
30 #include "PageMarginUtils.hxx"
32 #include <sfx2/dispatch.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/module.hxx>
35 #include <sfx2/viewsh.hxx>
36 #include <sfx2/objsh.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <pageformatpanel.hrc>
39 #include <cmdid.h>
40 #include <uitool.hxx>
41 #include <svtools/unitconv.hxx>
43 
44 #include <com/sun/star/lang/IllegalArgumentException.hpp>
45 
46 namespace sw { namespace sidebar{
47 
49  vcl::Window* pParent,
50  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
51  SfxBindings* pBindings)
52 {
53  if( pParent == nullptr )
54  throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageFormatPanel::Create", nullptr, 0);
55  if( !rxFrame.is() )
56  throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageFormatPanel::Create", nullptr, 0);
57 
58  return VclPtr<PageFormatPanel>::Create(pParent, rxFrame, pBindings);
59 }
60 
62  vcl::Window* pParent,
63  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
64  SfxBindings* pBindings) :
65  PanelLayout(pParent, "PageFormatPanel", "modules/swriter/ui/pageformatpanel.ui", rxFrame),
66  mpBindings( pBindings ),
67  maPaperSizeController(SID_ATTR_PAGE_SIZE, *pBindings, *this),
68  maPaperOrientationController(SID_ATTR_PAGE, *pBindings, *this),
69  maMetricController(SID_ATTR_METRIC, *pBindings,*this),
70  maSwPageLRControl(SID_ATTR_PAGE_LRSPACE, *pBindings, *this),
71  maSwPageULControl(SID_ATTR_PAGE_ULSPACE, *pBindings, *this),
72  mpPageItem( new SvxPageItem(SID_ATTR_PAGE) ),
73  mpPageLRMarginItem( new SvxLongLRSpaceItem( 0, 0, SID_ATTR_PAGE_LRSPACE ) ),
74  mpPageULMarginItem( new SvxLongULSpaceItem( 0, 0, SID_ATTR_PAGE_ULSPACE ) ),
75  meFUnit(GetModuleFieldUnit()),
76  meLastFUnit(GetModuleFieldUnit()),
77  meUnit(),
78  aCustomEntry()
79 {
80  get(mpPaperSizeBox, "papersize");
81  get(mpPaperWidth, "paperwidth");
82  get(mpPaperHeight, "paperheight");
83  get(mpPaperOrientation, "paperorientation");
84  get(mpMarginSelectBox, "marginLB");
85  FieldUnit eMetric = ::GetDfltMetric(false);
86  if (IsInch(eMetric))
87  {
88  for (size_t i = 0; i < SAL_N_ELEMENTS(RID_PAGEFORMATPANEL_MARGINS_INCH); ++i)
89  mpMarginSelectBox->InsertEntry(SwResId(RID_PAGEFORMATPANEL_MARGINS_INCH[i]));
90  }
91  else
92  {
93  for (size_t i = 0; i < SAL_N_ELEMENTS(RID_PAGEFORMATPANEL_MARGINS_CM); ++i)
94  mpMarginSelectBox->InsertEntry(SwResId(RID_PAGEFORMATPANEL_MARGINS_CM[i]));
95  }
96  get(mpCustomEntry, "customlabel");
97  Initialize();
98 }
99 
101 {
102  disposeOnce();
103 }
104 
106 {
113 
119  mpPageULMarginItem.reset();
120  mpPageLRMarginItem.reset();
121  mpPageItem.reset();
122 
124 }
125 
127 {
128  mpPaperSizeBox->FillPaperSizeEntries( PaperSizeApp::Std );
129  mpPaperSizeBox->SetDropDownLineCount(6);
134 
135  const SvtOptionsDrawinglayer aDrawinglayerOpt;
136  mpPaperWidth->SetMax(mpPaperWidth->Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FieldUnit::CM);
137  mpPaperWidth->SetLast(mpPaperWidth->Normalize(aDrawinglayerOpt.GetMaximumPaperWidth()), FieldUnit::CM);
138  mpPaperHeight->SetMax(mpPaperHeight->Normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FieldUnit::CM);
139  mpPaperHeight->SetLast(mpPaperHeight->Normalize(aDrawinglayerOpt.GetMaximumPaperHeight()), FieldUnit::CM);
140 
141  mpPaperSizeBox->SetSelectHdl( LINK(this, PageFormatPanel, PaperFormatModifyHdl ));
142  mpPaperOrientation->SetSelectHdl( LINK(this, PageFormatPanel, PaperFormatModifyHdl ));
143  mpPaperHeight->SetModifyHdl( LINK(this, PageFormatPanel, PaperSizeModifyHdl ));
144  mpPaperWidth->SetModifyHdl( LINK(this, PageFormatPanel, PaperSizeModifyHdl ));
145  mpMarginSelectBox->SetSelectHdl( LINK(this, PageFormatPanel, PaperModifyMarginHdl));
146 
147  mpBindings->Update(SID_ATTR_METRIC);
148  mpBindings->Update(SID_ATTR_PAGE);
149  mpBindings->Update(SID_ATTR_PAGE_SIZE);
150  mpBindings->Update( SID_ATTR_PAGE_LRSPACE );
151  mpBindings->Update( SID_ATTR_PAGE_ULSPACE );
152 
153  UpdateMarginBox();
154 }
155 
157  const sal_uInt16 nSId,
158  const SfxItemState eState,
159  const SfxPoolItem* pState)
160 {
161  switch(nSId)
162  {
163  case SID_ATTR_PAGE_SIZE:
164  {
165  const SvxSizeItem* pSizeItem = nullptr;
166  if (eState >= SfxItemState::DEFAULT)
167  pSizeItem = dynamic_cast< const SvxSizeItem* >(pState);
168  if (pSizeItem)
169  {
170  Size aPaperSize = pSizeItem->GetSize();
171 
172  mpPaperWidth->SetValue( mpPaperWidth->Normalize( aPaperSize.Width() ), FieldUnit::TWIP );
173  mpPaperHeight->SetValue( mpPaperHeight->Normalize( aPaperSize.Height() ), FieldUnit::TWIP );
174 
176  Swap(aPaperSize);
177 
178  Paper ePaper = SvxPaperInfo::GetSvxPaper(aPaperSize, meUnit);
179  mpPaperSizeBox->SetSelection( ePaper );
180  }
181  }
182  break;
183  case SID_ATTR_METRIC:
184  {
186  meFUnit = GetCurrentUnit(eState, pState);
187  if(meFUnit != meLastFUnit)
188  {
191  }
193  }
194  break;
195  case SID_ATTR_PAGE:
196  {
197  if ( eState >= SfxItemState::DEFAULT &&
198  dynamic_cast< const SvxPageItem *>( pState ) )
199  {
200  mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) );
201  if ( mpPageItem->IsLandscape() )
203  else
205  }
206  }
207  break;
208  case SID_ATTR_PAGE_LRSPACE:
209  {
210  if ( eState >= SfxItemState::DEFAULT &&
211  dynamic_cast< const SvxLongLRSpaceItem *>( pState ) )
212  {
213  mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
214  UpdateMarginBox();
215  }
216  }
217  break;
218  case SID_ATTR_PAGE_ULSPACE:
219  {
220  if ( eState >= SfxItemState::DEFAULT &&
221  dynamic_cast< const SvxLongULSpaceItem *>( pState ) )
222  {
223  mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
224  UpdateMarginBox();
225  }
226  }
227  break;
228  default:
229  break;
230  }
231 }
232 
233 IMPL_LINK_NOARG(PageFormatPanel, PaperFormatModifyHdl, ListBox&, void)
234 {
235  Paper ePaper = mpPaperSizeBox->GetSelection();
236  Size aSize;
237 
238  if(ePaper!=PAPER_USER)
239  aSize = SvxPaperInfo::GetPaperSize(ePaper, meUnit);
240  else
241  aSize = Size(GetCoreValue( *mpPaperWidth, meUnit ), GetCoreValue( *mpPaperHeight, meUnit));
242 
243  if(mpPaperOrientation->GetSelectedEntryPos() == 1 || ePaper==PAPER_USER)
244  Swap(aSize);
245 
246  mpPageItem->SetLandscape(mpPaperOrientation->GetSelectedEntryPos() == 1);
247  SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, aSize);
248  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem, mpPageItem.get() });
249 }
250 
251 IMPL_LINK_NOARG(PageFormatPanel, PaperSizeModifyHdl, Edit&, void)
252 {
253  Size aSize( GetCoreValue( *mpPaperWidth, meUnit ), GetCoreValue( *mpPaperHeight, meUnit));
254  SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, aSize);
255  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem });
256 }
257 
258 IMPL_LINK_NOARG(PageFormatPanel, PaperModifyMarginHdl, ListBox&, void)
259 {
260  bool bMirrored = false;
261  bool bApplyNewPageMargins = true;
262  switch ( mpMarginSelectBox->GetSelectedEntryPos() )
263  {
264  case 0:
265  SetNone(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
266  break;
267  case 1:
268  SetNarrow(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
269  break;
270  case 2:
271  SetModerate(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
272  break;
273  case 3:
274  SetNormal075(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
275  break;
276  case 4:
277  SetNormal100(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
278  break;
279  case 5:
280  SetNormal125(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
281  break;
282  case 6:
283  SetWide(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
284  break;
285  case 7:
286  SetMirrored(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
287  break;
288  default:
289  bApplyNewPageMargins = false;
290  break;
291  }
292 
293  if(bApplyNewPageMargins)
294  {
295  ExecuteMarginLRChange( mnPageLeftMargin, mnPageRightMargin );
296  ExecuteMarginULChange( mnPageTopMargin, mnPageBottomMargin );
297  if(bMirrored != (mpPageItem->GetPageUsage() == SvxPageUsage::Mirror))
298  {
299  mpPageItem->SetPageUsage( bMirrored ? SvxPageUsage::Mirror : SvxPageUsage::All );
300  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE,
301  SfxCallMode::RECORD, { mpPageItem.get() });
302  }
303  }
304 }
305 
307 {
308  FieldUnit eUnit = FieldUnit::NONE;
309 
310  if ( pState && eState >= SfxItemState::DEFAULT )
311  eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
312  else
313  {
315  SfxObjectShell* pSh = nullptr;
316  if ( pFrame )
317  pSh = pFrame->GetObjectShell();
318  if ( pSh )
319  {
320  SfxModule* pModule = pSh->GetModule();
321  if ( pModule )
322  {
323  const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
324  if ( pItem )
325  eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
326  }
327  else
328  {
329  SAL_WARN("sw.ui", "GetModuleFieldUnit(): no module found");
330  }
331  }
332  }
333 
334  return eUnit;
335 }
336 
337 void PageFormatPanel::ExecuteMarginLRChange( const long nPageLeftMargin, const long nPageRightMargin )
338 {
339  mpPageLRMarginItem->SetLeft( nPageLeftMargin );
340  mpPageLRMarginItem->SetRight( nPageRightMargin );
341  mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, SfxCallMode::RECORD, { mpPageLRMarginItem.get() });
342 }
343 
344 void PageFormatPanel::ExecuteMarginULChange(const long nPageTopMargin, const long nPageBottomMargin)
345 {
346  mpPageULMarginItem->SetUpper( nPageTopMargin );
347  mpPageULMarginItem->SetLower( nPageBottomMargin );
348  mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, SfxCallMode::RECORD, { mpPageULMarginItem.get() });
349 }
350 
352 {
355  mnPageTopMargin = mpPageULMarginItem->GetUpper();
357 
358  bool bMirrored = (mpPageItem->GetPageUsage() == SvxPageUsage::Mirror);
360  {
363  }
365  {
368  }
370  {
373  }
375  {
378  }
380  {
383  }
385  {
388  }
390  {
393  }
395  {
398  }
399  else
400  {
404  }
405 }
406 
407 } }
408 
409 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
void SetFieldUnit(weld::MetricSpinButton &rField, FieldUnit eUnit, bool bAll)
::sfx2::sidebar::ControllerItem maPaperOrientationController
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 * >())
FieldUnit
void SetNormal100(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
void ExecuteMarginULChange(const long nPageTopMargin, const long nPageBottomMargin)
Size & Swap(Size &rSize)
sal_Int32 GetSelectedEntryPos(sal_Int32 nSelIndex=0) const
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::string GetValue
::sfx2::sidebar::ControllerItem maSwPageLRControl
long Height() const
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
void disposeAndClear()
bool IsNarrow(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
MapUnit GetCoreMetric() const
void RemoveEntry(const OUString &rStr)
Dialog to specify the properties of date form field.
VclPtr< SvxRelativeField > mpPaperWidth
virtual SfxObjectShell * GetObjectShell() override
void FillPaperSizeEntries(PaperSizeApp eApp)
#define LISTBOX_ENTRY_NOTFOUND
sal_uInt32 GetMaximumPaperWidth() const
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
void SelectEntry(const OUString &rStr, bool bSelect=true)
bool IsNormal075(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
SfxModule * GetModule() const
Paper
void SetNarrow(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
void ExecuteMarginLRChange(const long nPageLeftMargin, const long nPageRightMargin)
bool IsMirrored(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
::sfx2::sidebar::ControllerItem maSwPageULControl
static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem *pState)
virtual OUString GetText() const
VclPtr< PaperSizeListBox > mpPaperSizeBox
void SetWide(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
#define SAL_N_ELEMENTS(arr)
bool IsWide(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:709
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, Button *, void)
void SelectEntryPos(sal_Int32 nPos, bool bSelect=true)
int i
int GetCoreValue(const weld::MetricSpinButton &rField, MapUnit eUnit)
sal_Int32 InsertEntry(const OUString &rStr, sal_Int32 nPos=LISTBOX_APPEND)
std::unique_ptr< SvxPageItem > mpPageItem
std::unique_ptr< SvxLongLRSpaceItem > mpPageLRMarginItem
static Size GetPaperSize(Paper ePaper, MapUnit eUnit=MapUnit::MapTwip)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:190
VclPtr< FixedText > mpCustomEntry
::sfx2::sidebar::ControllerItem maMetricController
void SetSelectHdl(const Link< ListBox &, void > &rLink)
VclPtr< ListBox > mpMarginSelectBox
void SetNone(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
void Update(sal_uInt16 nId)
virtual void dispose() override
sal_uInt32 GetMaximumPaperHeight() const
VclPtr< SvxRelativeField > mpPaperHeight
sal_Int32 GetEntryPos(const OUString &rStr) const
void SetModerate(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
PageFormatPanel(vcl::Window *pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame, SfxBindings *pBindings)
static SfxViewFrame * Current()
SfxItemState
std::unique_ptr< SvxLongULSpaceItem > mpPageULMarginItem
virtual ~PageFormatPanel() override
void SetSelection(Paper eSize)
virtual void dispose() override
static VclPtr< reference_type > Create(Arg &&...arg)
void SetNormal125(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
bool IsInch(MapUnit eU)
SfxDispatcher * GetDispatcher() const
#define SAL_WARN(area, stream)
void SetMirrored(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
bool IsNormal100(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
::sfx2::sidebar::ControllerItem maPaperSizeController
VclPtr< ListBox > mpPaperOrientation
bool IsNormal125(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
virtual void dispose() override
PAPER_USER
bool IsNone(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
void SetNormal075(long &nPageLeftMargin, long &nPageRightMargin, long &nPageTopMargin, long &nPageBottomMargin, bool &bMirrored)
bool IsModerate(const long nPageLeftMargin, const long nPageRightMargin, const long nPageTopMargin, const long nPageBottomMargin, bool bMirrored)
const Size & GetSize() const
static Paper GetSvxPaper(const Size &rSize, MapUnit eUnit)
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame, SfxBindings *pBindings)