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  const bool)
161 {
162  switch(nSId)
163  {
164  case SID_ATTR_PAGE_SIZE:
165  {
166  const SvxSizeItem* pSizeItem = nullptr;
167  if (eState >= SfxItemState::DEFAULT)
168  pSizeItem = dynamic_cast< const SvxSizeItem* >(pState);
169  if (pSizeItem)
170  {
171  Size aPaperSize = pSizeItem->GetSize();
172 
173  mpPaperWidth->SetValue( mpPaperWidth->Normalize( aPaperSize.Width() ), FieldUnit::TWIP );
174  mpPaperHeight->SetValue( mpPaperHeight->Normalize( aPaperSize.Height() ), FieldUnit::TWIP );
175 
177  Swap(aPaperSize);
178 
179  Paper ePaper = SvxPaperInfo::GetSvxPaper(aPaperSize, meUnit);
180  mpPaperSizeBox->SetSelection( ePaper );
181  }
182  }
183  break;
184  case SID_ATTR_METRIC:
185  {
187  meFUnit = GetCurrentUnit(eState, pState);
188  if(meFUnit != meLastFUnit)
189  {
192  }
194  }
195  break;
196  case SID_ATTR_PAGE:
197  {
198  if ( eState >= SfxItemState::DEFAULT &&
199  dynamic_cast< const SvxPageItem *>( pState ) )
200  {
201  mpPageItem.reset( static_cast<SvxPageItem*>(pState->Clone()) );
202  if ( mpPageItem->IsLandscape() )
204  else
206  }
207  }
208  break;
209  case SID_ATTR_PAGE_LRSPACE:
210  {
211  if ( eState >= SfxItemState::DEFAULT &&
212  dynamic_cast< const SvxLongLRSpaceItem *>( pState ) )
213  {
214  mpPageLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
215  UpdateMarginBox();
216  }
217  }
218  break;
219  case SID_ATTR_PAGE_ULSPACE:
220  {
221  if ( eState >= SfxItemState::DEFAULT &&
222  dynamic_cast< const SvxLongULSpaceItem *>( pState ) )
223  {
224  mpPageULMarginItem.reset( static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
225  UpdateMarginBox();
226  }
227  }
228  break;
229  default:
230  break;
231  }
232 }
233 
234 IMPL_LINK_NOARG(PageFormatPanel, PaperFormatModifyHdl, ListBox&, void)
235 {
236  Paper ePaper = mpPaperSizeBox->GetSelection();
237  Size aSize;
238 
239  if(ePaper!=PAPER_USER)
240  aSize = SvxPaperInfo::GetPaperSize(ePaper, meUnit);
241  else
242  aSize = Size(GetCoreValue( *mpPaperWidth, meUnit ), GetCoreValue( *mpPaperHeight, meUnit));
243 
244  if(mpPaperOrientation->GetSelectedEntryPos() == 1 || ePaper==PAPER_USER)
245  Swap(aSize);
246 
247  mpPageItem->SetLandscape(mpPaperOrientation->GetSelectedEntryPos() == 1);
248  SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, aSize);
249  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem, mpPageItem.get() });
250 }
251 
252 IMPL_LINK_NOARG(PageFormatPanel, PaperSizeModifyHdl, Edit&, void)
253 {
254  Size aSize( GetCoreValue( *mpPaperWidth, meUnit ), GetCoreValue( *mpPaperHeight, meUnit));
255  SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, aSize);
256  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE_SIZE, SfxCallMode::RECORD, { &aSizeItem });
257 }
258 
259 IMPL_LINK_NOARG(PageFormatPanel, PaperModifyMarginHdl, ListBox&, void)
260 {
261  bool bMirrored = false;
262  bool bApplyNewPageMargins = true;
263  switch ( mpMarginSelectBox->GetSelectedEntryPos() )
264  {
265  case 0:
266  SetNone(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
267  break;
268  case 1:
269  SetNarrow(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
270  break;
271  case 2:
272  SetModerate(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
273  break;
274  case 3:
275  SetNormal075(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
276  break;
277  case 4:
278  SetNormal100(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
279  break;
280  case 5:
281  SetNormal125(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
282  break;
283  case 6:
284  SetWide(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
285  break;
286  case 7:
287  SetMirrored(mnPageLeftMargin, mnPageRightMargin, mnPageTopMargin, mnPageBottomMargin, bMirrored);
288  break;
289  default:
290  bApplyNewPageMargins = false;
291  break;
292  }
293 
294  if(bApplyNewPageMargins)
295  {
296  ExecuteMarginLRChange( mnPageLeftMargin, mnPageRightMargin );
297  ExecuteMarginULChange( mnPageTopMargin, mnPageBottomMargin );
298  if(bMirrored != (mpPageItem->GetPageUsage() == SvxPageUsage::Mirror))
299  {
300  mpPageItem->SetPageUsage( bMirrored ? SvxPageUsage::Mirror : SvxPageUsage::All );
301  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_PAGE,
302  SfxCallMode::RECORD, { mpPageItem.get() });
303  }
304  }
305 }
306 
308 {
309  FieldUnit eUnit = FieldUnit::NONE;
310 
311  if ( pState && eState >= SfxItemState::DEFAULT )
312  eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
313  else
314  {
316  SfxObjectShell* pSh = nullptr;
317  if ( pFrame )
318  pSh = pFrame->GetObjectShell();
319  if ( pSh )
320  {
321  SfxModule* pModule = pSh->GetModule();
322  if ( pModule )
323  {
324  const SfxPoolItem* pItem = pModule->GetItem( SID_ATTR_METRIC );
325  if ( pItem )
326  eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
327  }
328  else
329  {
330  SAL_WARN("sw.ui", "GetModuleFieldUnit(): no module found");
331  }
332  }
333  }
334 
335  return eUnit;
336 }
337 
338 void PageFormatPanel::ExecuteMarginLRChange( const long nPageLeftMargin, const long nPageRightMargin )
339 {
340  mpPageLRMarginItem->SetLeft( nPageLeftMargin );
341  mpPageLRMarginItem->SetRight( nPageRightMargin );
342  mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_LRSPACE, SfxCallMode::RECORD, { mpPageLRMarginItem.get() });
343 }
344 
345 void PageFormatPanel::ExecuteMarginULChange(const long nPageTopMargin, const long nPageBottomMargin)
346 {
347  mpPageULMarginItem->SetUpper( nPageTopMargin );
348  mpPageULMarginItem->SetLower( nPageBottomMargin );
349  mpBindings->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_ULSPACE, SfxCallMode::RECORD, { mpPageULMarginItem.get() });
350 }
351 
353 {
356  mnPageTopMargin = mpPageULMarginItem->GetUpper();
358 
359  bool bMirrored = (mpPageItem->GetPageUsage() == SvxPageUsage::Mirror);
361  {
364  }
366  {
369  }
371  {
374  }
376  {
379  }
381  {
384  }
386  {
389  }
391  {
394  }
396  {
399  }
400  else
401  {
405  }
406 }
407 
408 } }
409 
410 /* 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
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:710
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:191
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
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState, const bool bIsEnabled) override
#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)