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