1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <fmtfsize.hxx>
22 #include <hintids.hxx>
23 #include <svtools/unitconv.hxx>
24 #include <vcl/fieldvalues.hxx>
25 #include <unotools/localedatawrapper.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>
33 #include <pagedesc.hxx>
34 #include <pgfnote.hxx>
35 #include <uiitems.hxx>
39 using namespace ::com::sun::star
;
41 const WhichRangesContainer
SwFootNotePage::s_aPageRg(svl::Items
<FN_PARAM_FTN_INFO
, FN_PARAM_FTN_INFO
>);
43 // handler to switch between the different possibilities how the footnote
44 // region's height can be set.
45 IMPL_LINK_NOARG(SwFootNotePage
, HeightPage
, weld::Toggleable
&, void)
47 if (m_xMaxHeightPageBtn
->get_active())
48 m_xMaxHeightEdit
->set_sensitive(false);
51 IMPL_LINK_NOARG(SwFootNotePage
, HeightMetric
, weld::Toggleable
&, void)
53 if (m_xMaxHeightBtn
->get_active())
55 m_xMaxHeightEdit
->set_sensitive(true);
56 m_xMaxHeightEdit
->grab_focus();
60 // handler limit values
61 IMPL_LINK_NOARG(SwFootNotePage
, HeightModify
, weld::MetricSpinButton
&, void)
63 m_xMaxHeightEdit
->set_max(m_xMaxHeightEdit
->normalize(m_lMaxHeight
-
64 (m_xDistEdit
->denormalize(m_xDistEdit
->get_value(FieldUnit::TWIP
)) +
65 m_xLineDistEdit
->denormalize(m_xLineDistEdit
->get_value(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(m_lMaxHeight
-
70 (m_xMaxHeightEdit
->denormalize(m_xMaxHeightEdit
->get_value(FieldUnit::TWIP
)) +
71 m_xLineDistEdit
->denormalize(m_xLineDistEdit
->get_value(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(m_lMaxHeight
-
76 (m_xMaxHeightEdit
->denormalize(m_xMaxHeightEdit
->get_value(FieldUnit::TWIP
)) +
77 m_xDistEdit
->denormalize(m_xDistEdit
->get_value(FieldUnit::TWIP
)))),
81 IMPL_LINK_NOARG(SwFootNotePage
, LineWidthChanged_Impl
, weld::MetricSpinButton
&, void)
83 sal_Int64 nVal
= m_xLineWidthEdit
->get_value(FieldUnit::NONE
);
84 nVal
= static_cast<sal_Int64
>(vcl::ConvertDoubleValue(
86 m_xLineWidthEdit
->get_digits(),
87 m_xLineWidthEdit
->get_unit(), MapUnit::MapTwip
));
88 m_xLineTypeBox
->SetWidth(nVal
);
91 IMPL_LINK(SwFootNotePage
, LineColorSelected_Impl
, ColorListBox
&, rColorBox
, void)
93 m_xLineTypeBox
->SetColor(rColorBox
.GetSelectEntryColor());
96 SwFootNotePage::SwFootNotePage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rSet
)
97 : SfxTabPage(pPage
, pController
, "modules/swriter/ui/footnoteareapage.ui", "FootnoteAreaPage", &rSet
)
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
))
111 SetExchangeSupport();
112 FieldUnit aMetric
= ::GetDfltMetric(false);
113 ::SetFieldUnit(*m_xMaxHeightEdit
, aMetric
);
114 ::SetFieldUnit(*m_xDistEdit
, aMetric
);
115 ::SetFieldUnit(*m_xLineDistEdit
, aMetric
);
116 MeasurementSystem eSys
= SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
117 tools::Long nHeightValue
= MeasurementSystem::Metric
!= eSys
? 1440 : 1134;
118 m_xMaxHeightEdit
->set_value(m_xMaxHeightEdit
->normalize(nHeightValue
),FieldUnit::TWIP
);
121 SwFootNotePage::~SwFootNotePage()
123 m_xLineColorBox
.reset();
124 m_xLineTypeBox
.reset();
127 std::unique_ptr
<SfxTabPage
> SwFootNotePage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rSet
)
129 return std::make_unique
<SwFootNotePage
>(pPage
, pController
, *rSet
);
132 void SwFootNotePage::Reset(const SfxItemSet
*rSet
)
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
);
140 pFootnoteInfo
= &static_cast<const SwPageFootnoteInfoItem
*>(pItem
)->GetPageFootnoteInfo();
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
;
149 // footnote area's height
150 SwTwips lHeight
= pFootnoteInfo
->GetHeight();
153 m_xMaxHeightEdit
->set_value(m_xMaxHeightEdit
->normalize(lHeight
),FieldUnit::TWIP
);
154 m_xMaxHeightBtn
->set_active(true);
158 m_xMaxHeightPageBtn
->set_active(true);
159 m_xMaxHeightEdit
->set_sensitive(false);
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
);
169 m_xLineWidthEdit
->connect_value_changed(LINK(this, SwFootNotePage
, LineWidthChanged_Impl
));
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
);
177 m_xLineTypeBox
->SetSourceUnit( FieldUnit::TWIP
);
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() );
192 m_xLineColorBox
->SelectEntry(pFootnoteInfo
->GetLineColor());
193 m_xLineColorBox
->SetSelectHdl(LINK(this, SwFootNotePage
, LineColorSelected_Impl
));
194 m_xLineTypeBox
->SetColor(pFootnoteInfo
->GetLineColor());
197 m_xLinePosBox
->set_active(static_cast<sal_Int32
>(pFootnoteInfo
->GetAdj()));
200 Fraction
aTmp( 100, 1 );
201 aTmp
*= pFootnoteInfo
->GetWidth();
202 m_xLineLengthEdit
->set_value(static_cast<tools::Long
>(aTmp
), FieldUnit::PERCENT
);
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
);
211 // stuff attributes into the set, when OK
212 bool SwFootNotePage::FillItemSet(SfxItemSet
*rSet
)
214 SwPageFootnoteInfoItem
aItem(GetItemSet().Get(FN_PARAM_FTN_INFO
));
216 // that's the original
217 SwPageFootnoteInfo
&rFootnoteInfo
= aItem
.GetPageFootnoteInfo();
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
))));
224 rFootnoteInfo
.SetHeight(0);
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
))));
233 rFootnoteInfo
.SetLineStyle(m_xLineTypeBox
->GetSelectEntryStyle());
236 sal_Int64 nWidth
= m_xLineWidthEdit
->get_value(FieldUnit::NONE
);
237 nWidth
= static_cast<tools::Long
>(vcl::ConvertDoubleValue(
239 m_xLineWidthEdit
->get_digits(),
240 m_xLineWidthEdit
->get_unit(), MapUnit::MapTwip
));
241 rFootnoteInfo
.SetLineWidth( nWidth
);
244 rFootnoteInfo
.SetLineColor(m_xLineColorBox
->GetSelectEntryColor());
247 rFootnoteInfo
.SetAdj(static_cast<css::text::HorizontalAdjust
>(m_xLinePosBox
->get_active()));
250 rFootnoteInfo
.SetWidth(Fraction(m_xLineLengthEdit
->get_value(FieldUnit::PERCENT
), 100));
252 const SfxPoolItem
* pOldItem
;
253 if(nullptr == (pOldItem
= GetOldItem( *rSet
, FN_PARAM_FTN_INFO
)) ||
260 void SwFootNotePage::ActivatePage(const SfxItemSet
& rSet
)
262 auto const & rSize
= rSet
.Get( RES_FRM_SIZE
);
263 m_lMaxHeight
= rSize
.GetHeight();
265 if( const SvxSetItem
* pHeaderSetItem
= rSet
.GetItemIfSet( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET
), false ) )
267 const SfxItemSet
& rHeaderSet
= pHeaderSetItem
->GetItemSet();
268 const SfxBoolItem
& rHeaderOn
=
269 rHeaderSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_ON
) );
271 if ( rHeaderOn
.GetValue() )
273 const SvxSizeItem
& rSizeItem
=
274 rHeaderSet
.Get(rSet
.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE
));
275 m_lMaxHeight
-= rSizeItem
.GetSize().Height();
279 if( const SvxSetItem
* pFooterSetItem
= rSet
.GetItemIfSet( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET
),
282 const SfxItemSet
& rFooterSet
= pFooterSetItem
->GetItemSet();
283 const SfxBoolItem
& rFooterOn
= rFooterSet
.Get( SID_ATTR_PAGE_ON
);
285 if ( rFooterOn
.GetValue() )
287 const SvxSizeItem
& rSizeItem
=
288 rFooterSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE
) );
289 m_lMaxHeight
-= rSizeItem
.GetSize().Height();
293 if ( const SvxULSpaceItem
* pSpaceItem
= rSet
.GetItemIfSet( RES_UL_SPACE
, false ) )
295 m_lMaxHeight
-= pSpaceItem
->GetUpper() + pSpaceItem
->GetLower();
301 // set maximum values
302 HeightModify(*m_xMaxHeightEdit
);
305 DeactivateRC
SwFootNotePage::DeactivatePage( SfxItemSet
* _pSet
)
310 return DeactivateRC::LeavePage
;
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */