LibreOffice Module sw (master)  1
pgfnote.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 
20 #include <cmdid.h>
21 #include <fmtfsize.hxx>
22 #include <hintids.hxx>
23 #include <svtools/unitconv.hxx>
24 #include <svx/dialogs.hrc>
25 #include <svx/svxids.hrc>
26 #include <svx/drawitem.hxx>
27 #include <svx/xtable.hxx>
28 #include <sal/macros.h>
29 #include <vcl/field.hxx>
30 #include <vcl/svapp.hxx>
32 #include <unotools/syslocale.hxx>
33 #include <editeng/borderline.hxx>
34 #include <editeng/sizeitem.hxx>
35 #include <svx/pageitem.hxx>
36 #include <svl/eitem.hxx>
37 #include <editeng/ulspitem.hxx>
38 #include <uitool.hxx>
39 #include <pagedesc.hxx>
40 #include <pgfnote.hxx>
41 #include <uiitems.hxx>
42 #include <sfx2/objsh.hxx>
43 
44 #include <globals.hrc>
45 #include <strings.hrc>
46 #include <memory>
47 
48 using namespace ::com::sun::star;
49 
50 const sal_uInt16 SwFootNotePage::aPageRg[] = {
52  0
53 };
54 
55 // handler to switch between the different possibilities how the footnote
56 // region's height can be set.
58 {
59  if (m_xMaxHeightPageBtn->get_active())
60  m_xMaxHeightEdit->set_sensitive(false);
61 }
62 
64 {
65  if (m_xMaxHeightBtn->get_active())
66  {
67  m_xMaxHeightEdit->set_sensitive(true);
68  m_xMaxHeightEdit->grab_focus();
69  }
70 }
71 
72 // handler limit values
74 {
75  m_xMaxHeightEdit->set_max(m_xMaxHeightEdit->normalize(lMaxHeight -
76  (m_xDistEdit->denormalize(m_xDistEdit->get_value(FieldUnit::TWIP)) +
77  m_xLineDistEdit->denormalize(m_xLineDistEdit->get_value(FieldUnit::TWIP)))),
78  FieldUnit::TWIP);
79  if (m_xMaxHeightEdit->get_value(FieldUnit::NONE) < 0)
80  m_xMaxHeightEdit->set_value(0, FieldUnit::NONE);
81  m_xDistEdit->set_max(m_xDistEdit->normalize(lMaxHeight -
82  (m_xMaxHeightEdit->denormalize(m_xMaxHeightEdit->get_value(FieldUnit::TWIP)) +
83  m_xLineDistEdit->denormalize(m_xLineDistEdit->get_value(FieldUnit::TWIP)))),
84  FieldUnit::TWIP);
85  if (m_xDistEdit->get_value(FieldUnit::NONE) < 0)
86  m_xDistEdit->set_value(0, FieldUnit::NONE);
87  m_xLineDistEdit->set_max(m_xLineDistEdit->normalize(lMaxHeight -
88  (m_xMaxHeightEdit->denormalize(m_xMaxHeightEdit->get_value(FieldUnit::TWIP)) +
89  m_xDistEdit->denormalize(m_xDistEdit->get_value(FieldUnit::TWIP)))),
90  FieldUnit::TWIP);
91 }
92 
93 IMPL_LINK_NOARG(SwFootNotePage, LineWidthChanged_Impl, weld::MetricSpinButton&, void)
94 {
95  sal_Int64 nVal = m_xLineWidthEdit->get_value(FieldUnit::NONE);
96  nVal = static_cast<sal_Int64>(MetricField::ConvertDoubleValue(
97  nVal,
98  m_xLineWidthEdit->get_digits(),
99  m_xLineWidthEdit->get_unit(), MapUnit::MapTwip ));
100  m_xLineTypeBox->SetWidth(nVal);
101 }
102 
103 IMPL_LINK(SwFootNotePage, LineColorSelected_Impl, ColorListBox&, rColorBox, void)
104 {
105  m_xLineTypeBox->SetColor(rColorBox.GetSelectEntryColor());
106 }
107 
109  : SfxTabPage(pParent, "modules/swriter/ui/footnoteareapage.ui", "FootnoteAreaPage", &rSet)
110  , lMaxHeight(0)
111  , m_xMaxHeightPageBtn(m_xBuilder->weld_radio_button("maxheightpage"))
112  , m_xMaxHeightBtn(m_xBuilder->weld_radio_button("maxheight"))
113  , m_xMaxHeightEdit(m_xBuilder->weld_metric_spin_button("maxheightsb", FieldUnit::CM))
114  , m_xDistEdit(m_xBuilder->weld_metric_spin_button("spacetotext", FieldUnit::CM))
115  , m_xLinePosBox(m_xBuilder->weld_combo_box("position"))
116  , m_xLineTypeBox(new SvtLineListBox(m_xBuilder->weld_menu_button("style")))
117  , m_xLineWidthEdit(m_xBuilder->weld_metric_spin_button("thickness", FieldUnit::POINT))
118  , m_xLineColorBox(new ColorListBox(m_xBuilder->weld_menu_button("color"), pParent.GetFrameWeld()))
119  , m_xLineLengthEdit(m_xBuilder->weld_metric_spin_button("length", FieldUnit::PERCENT))
120  , m_xLineDistEdit(m_xBuilder->weld_metric_spin_button("spacingtocontents", FieldUnit::CM))
121 {
123  FieldUnit aMetric = ::GetDfltMetric(false);
124  ::SetFieldUnit(*m_xMaxHeightEdit, aMetric);
125  ::SetFieldUnit(*m_xDistEdit, aMetric);
126  ::SetFieldUnit(*m_xLineDistEdit, aMetric);
128  long nHeightValue = MeasurementSystem::Metric != eSys ? 1440 : 1134;
129  m_xMaxHeightEdit->set_value(m_xMaxHeightEdit->normalize(nHeightValue),FieldUnit::TWIP);
130 }
131 
133 {
134  disposeOnce();
135 }
136 
138 {
139  m_xLineColorBox.reset();
140  m_xLineTypeBox.reset();
142 }
143 
145 {
146  return VclPtr<SwFootNotePage>::Create(pParent, *rSet);
147 }
148 
150 {
151  // if no example exists, otherwise Init here in Activate
152  std::unique_ptr<SwPageFootnoteInfo> pDefFootnoteInfo;
153  const SwPageFootnoteInfo* pFootnoteInfo;
154  const SfxPoolItem* pItem = SfxTabPage::GetItem(*rSet, FN_PARAM_FTN_INFO);
155  if( pItem )
156  {
157  pFootnoteInfo = &static_cast<const SwPageFootnoteInfoItem*>(pItem)->GetPageFootnoteInfo();
158  }
159  else
160  {
161  // when "standard" is being activated the footnote item is deleted,
162  // that's why a footnote structure has to be created here
163  pDefFootnoteInfo.reset(new SwPageFootnoteInfo());
164  pFootnoteInfo = pDefFootnoteInfo.get();
165  }
166  // footnote area's height
167  SwTwips lHeight = pFootnoteInfo->GetHeight();
168  if(lHeight)
169  {
170  m_xMaxHeightEdit->set_value(m_xMaxHeightEdit->normalize(lHeight),FieldUnit::TWIP);
171  m_xMaxHeightBtn->set_active(true);
172  }
173  else
174  {
175  m_xMaxHeightPageBtn->set_active(true);
176  m_xMaxHeightEdit->set_sensitive(false);
177  }
178  m_xMaxHeightPageBtn->connect_toggled(LINK(this,SwFootNotePage,HeightPage));
179  m_xMaxHeightBtn->connect_toggled(LINK(this,SwFootNotePage,HeightMetric));
180  Link<weld::MetricSpinButton&,void> aLk = LINK(this, SwFootNotePage, HeightModify);
181  m_xMaxHeightEdit->connect_value_changed(aLk);
182  m_xDistEdit->connect_value_changed(aLk);
183  m_xLineDistEdit->connect_value_changed(aLk);
184 
185  // Separator width
186  m_xLineWidthEdit->connect_value_changed(LINK(this, SwFootNotePage, LineWidthChanged_Impl));
187 
188  sal_Int64 nWidthPt = static_cast<sal_Int64>(MetricField::ConvertDoubleValue(
189  sal_Int64( pFootnoteInfo->GetLineWidth() ), m_xLineWidthEdit->get_digits(),
190  MapUnit::MapTwip, m_xLineWidthEdit->get_unit( ) ));
191  m_xLineWidthEdit->set_value(nWidthPt, FieldUnit::NONE);
192 
193  // Separator style
194  m_xLineTypeBox->SetSourceUnit( FieldUnit::TWIP );
195 
196  m_xLineTypeBox->InsertEntry(
197  ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::SOLID),
198  SvxBorderLineStyle::SOLID );
199  m_xLineTypeBox->InsertEntry(
200  ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::DOTTED),
201  SvxBorderLineStyle::DOTTED );
202  m_xLineTypeBox->InsertEntry(
203  ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::DASHED),
204  SvxBorderLineStyle::DASHED );
205  m_xLineTypeBox->SetWidth( pFootnoteInfo->GetLineWidth( ) );
206  m_xLineTypeBox->SelectEntry( pFootnoteInfo->GetLineStyle() );
207 
208  // Separator Color
209  m_xLineColorBox->SelectEntry(pFootnoteInfo->GetLineColor());
210  m_xLineColorBox->SetSelectHdl(LINK(this, SwFootNotePage, LineColorSelected_Impl));
211  m_xLineTypeBox->SetColor(pFootnoteInfo->GetLineColor());
212 
213  // position
214  m_xLinePosBox->set_active(static_cast<sal_Int32>(pFootnoteInfo->GetAdj()));
215 
216  // width
217  Fraction aTmp( 100, 1 );
218  aTmp *= pFootnoteInfo->GetWidth();
219  m_xLineLengthEdit->set_value(static_cast<long>(aTmp), FieldUnit::PERCENT);
220 
221  // gap footnote area
222  m_xDistEdit->set_value(m_xDistEdit->normalize(pFootnoteInfo->GetTopDist()), FieldUnit::TWIP);
223  m_xLineDistEdit->set_value(
224  m_xLineDistEdit->normalize(pFootnoteInfo->GetBottomDist()), FieldUnit::TWIP);
225  ActivatePage( *rSet );
226 }
227 
228 // stuff attributes into the set, when OK
230 {
231  SwPageFootnoteInfoItem aItem(static_cast<const SwPageFootnoteInfoItem&>(GetItemSet().Get(FN_PARAM_FTN_INFO)));
232 
233  // that's the original
234  SwPageFootnoteInfo &rFootnoteInfo = aItem.GetPageFootnoteInfo();
235 
236  // footnote area's height
237  if (m_xMaxHeightBtn->get_active())
238  rFootnoteInfo.SetHeight( static_cast< SwTwips >(
239  m_xMaxHeightEdit->denormalize(m_xMaxHeightEdit->get_value(FieldUnit::TWIP))));
240  else
241  rFootnoteInfo.SetHeight(0);
242 
243  // gap footnote area
244  rFootnoteInfo.SetTopDist( static_cast< SwTwips >(
245  m_xDistEdit->denormalize(m_xDistEdit->get_value(FieldUnit::TWIP))));
246  rFootnoteInfo.SetBottomDist( static_cast< SwTwips >(
247  m_xLineDistEdit->denormalize(m_xLineDistEdit->get_value(FieldUnit::TWIP))));
248 
249  // Separator style
250  rFootnoteInfo.SetLineStyle(m_xLineTypeBox->GetSelectEntryStyle());
251 
252  // Separator width
253  sal_Int64 nWidth = m_xLineWidthEdit->get_value(FieldUnit::NONE);
254  nWidth = static_cast<long>(MetricField::ConvertDoubleValue(
255  nWidth,
256  m_xLineWidthEdit->get_digits(),
257  m_xLineWidthEdit->get_unit(), MapUnit::MapTwip ));
258  rFootnoteInfo.SetLineWidth( nWidth );
259 
260  // Separator color
261  rFootnoteInfo.SetLineColor(m_xLineColorBox->GetSelectEntryColor());
262 
263  // Position
264  rFootnoteInfo.SetAdj(static_cast<css::text::HorizontalAdjust>(m_xLinePosBox->get_active()));
265 
266  // Width
267  rFootnoteInfo.SetWidth(Fraction(m_xLineLengthEdit->get_value(FieldUnit::PERCENT), 100));
268 
269  const SfxPoolItem* pOldItem;
270  if(nullptr == (pOldItem = GetOldItem( *rSet, FN_PARAM_FTN_INFO )) ||
271  aItem != *pOldItem )
272  rSet->Put(aItem);
273 
274  return true;
275 }
276 
278 {
279  auto const & rSize = rSet.Get( RES_FRM_SIZE );
280  lMaxHeight = rSize.GetHeight();
281 
282  const SfxPoolItem* pItem;
283  if( SfxItemState::SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET), false, &pItem ) )
284  {
285  const SfxItemSet& rHeaderSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
286  const SfxBoolItem& rHeaderOn =
287  static_cast<const SfxBoolItem&>(rHeaderSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_ON ) ));
288 
289  if ( rHeaderOn.GetValue() )
290  {
291  const SvxSizeItem& rSizeItem =
292  static_cast<const SvxSizeItem&>(rHeaderSet.Get(rSet.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE)));
293  lMaxHeight -= rSizeItem.GetSize().Height();
294  }
295  }
296 
297  if( SfxItemState::SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET),
298  false, &pItem ) )
299  {
300  const SfxItemSet& rFooterSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
301  const SfxBoolItem& rFooterOn = rFooterSet.Get( SID_ATTR_PAGE_ON );
302 
303  if ( rFooterOn.GetValue() )
304  {
305  const SvxSizeItem& rSizeItem =
306  static_cast<const SvxSizeItem&>(rFooterSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE ) ));
307  lMaxHeight -= rSizeItem.GetSize().Height();
308  }
309  }
310 
311  if ( rSet.GetItemState( RES_UL_SPACE , false ) == SfxItemState::SET )
312  {
313  const SvxULSpaceItem &rUL = rSet.Get( RES_UL_SPACE );
314  lMaxHeight -= rUL.GetUpper() + rUL.GetLower();
315  }
316 
317  lMaxHeight *= 8;
318  lMaxHeight /= 10;
319 
320  // set maximum values
321  HeightModify(*m_xMaxHeightEdit);
322 }
323 
325 {
326  if(_pSet)
327  FillItemSet(_pSet);
328 
329  return DeactivateRC::LeavePage;
330 }
331 
332 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool GetValue() const
virtual void Reset(const SfxItemSet *rSet) override
Definition: pgfnote.cxx:149
void SetTopDist(SwTwips const nNew)
Definition: pagedesc.hxx:75
FieldUnit
#define RES_FRM_SIZE
Definition: hintids.hxx:194
sal_uInt16 GetLower() const
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: pgfnote.cxx:324
void SetLineStyle(SvxBorderLineStyle const eSet)
Definition: pagedesc.hxx:71
IMPL_LINK_NOARG(SwFootNotePage, HeightPage, weld::ToggleButton &, void)
Definition: pgfnote.cxx:57
long Height() const
void SetBottomDist(SwTwips const nNew)
Definition: pagedesc.hxx:76
SwTwips GetBottomDist() const
Definition: pagedesc.hxx:67
long SwTwips
Definition: swtypes.hxx:49
void SetHeight(SwTwips const nNew)
Definition: pagedesc.hxx:69
static const SfxPoolItem * GetItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
MeasurementSystem
SwTwips GetTopDist() const
Definition: pagedesc.hxx:66
const LocaleDataWrapper & GetLocaleData() const
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: pgfnote.cxx:229
virtual void dispose() override
Definition: pgfnote.cxx:137
std::unique_ptr< SvtLineListBox > m_xLineTypeBox
Definition: pgfnote.hxx:51
void SetExchangeSupport()
#define FN_PARAM_FTN_INFO
Definition: cmdid.h:743
std::unique_ptr< ColorListBox > m_xLineColorBox
Definition: pgfnote.hxx:53
#define RES_UL_SPACE
Definition: hintids.hxx:197
SwTwips GetHeight() const
Definition: pagedesc.hxx:60
virtual ~SwFootNotePage() override
Definition: pgfnote.cxx:132
virtual void dispose() override
const SfxItemSet & GetItemSet() const
const SfxPoolItem * GetOldItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
std::unique_ptr< weld::RadioButton > m_xMaxHeightBtn
Definition: pgfnote.hxx:47
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:710
void SetAdj(css::text::HorizontalAdjust const eNew)
Definition: pagedesc.hxx:74
void SetWidth(const Fraction &rNew)
Definition: pagedesc.hxx:73
SwFootNotePage(TabPageParent pParent, const SfxItemSet &rSet)
Definition: pgfnote.cxx:108
weld::Window * GetFrameWeld(SfxFrame *pFrame)
Definition: dialoghelp.cxx:20
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: pgfnote.cxx:277
std::unique_ptr< weld::ComboBox > m_xLinePosBox
Definition: pgfnote.hxx:50
SfxItemPool * GetPool() const
std::unique_ptr< weld::MetricSpinButton > m_xDistEdit
Definition: pgfnote.hxx:49
std::unique_ptr< weld::MetricSpinButton > m_xMaxHeightEdit
Definition: pgfnote.hxx:48
static BorderWidthImpl getWidthImpl(SvxBorderLineStyle nStyle)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
Footnote information.
Definition: pagedesc.hxx:47
const Fraction & GetWidth() const
Definition: pagedesc.hxx:64
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
std::unique_ptr< weld::RadioButton > m_xMaxHeightPageBtn
Definition: pgfnote.hxx:46
void SetLineColor(const Color &rCol)
Definition: pagedesc.hxx:72
std::unique_ptr< weld::MetricSpinButton > m_xLineDistEdit
Definition: pgfnote.hxx:55
css::text::HorizontalAdjust GetAdj() const
Definition: pagedesc.hxx:65
static VclPtr< reference_type > Create(Arg &&...arg)
sal_uLong GetLineWidth() const
Definition: pagedesc.hxx:61
const OUString PERCENT("Percent")
std::unique_ptr< weld::MetricSpinButton > m_xLineWidthEdit
Definition: pgfnote.hxx:52
void SetLineWidth(sal_uLong const nSet)
Definition: pagedesc.hxx:70
DeactivateRC
static VclPtr< SfxTabPage > Create(TabPageParent pParent, const SfxItemSet *rSet)
Definition: pgfnote.cxx:144
long lMaxHeight
Definition: pgfnote.hxx:44
SVX_DLLPUBLIC MSO_SPT Get(const OUString &)
static double ConvertDoubleValue(double nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
SwPageFootnoteInfo & GetPageFootnoteInfo()
Definition: uiitems.hxx:57
SvxBorderLineStyle GetLineStyle() const
Definition: pagedesc.hxx:63
std::unique_ptr< weld::MetricSpinButton > m_xLineLengthEdit
Definition: pgfnote.hxx:54
static const sal_uInt16 aPageRg[]
Definition: pgfnote.hxx:31
const Color & GetLineColor() const
Definition: pagedesc.hxx:62
IMPL_LINK(SwFootNotePage, LineColorSelected_Impl, ColorListBox &, rColorBox, void)
Definition: pgfnote.cxx:103
const Size & GetSize() const
sal_uInt16 GetUpper() const
MeasurementSystem getMeasurementSystemEnum() const