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