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