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