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>
32 #include <svl/grabbagitem.hxx>
34 #include <pagedesc.hxx>
35 #include <pgfnote.hxx>
36 #include <uiitems.hxx>
40 using namespace ::com::sun::star
;
42 const WhichRangesContainer
SwFootNotePage::s_aPageRg(svl::Items
<FN_PARAM_FTN_INFO
, FN_PARAM_FTN_INFO
>);
44 // handler to switch between the different possibilities how the footnote
45 // region's height can be set.
46 IMPL_LINK_NOARG(SwFootNotePage
, HeightPage
, weld::Toggleable
&, void)
48 if (m_xMaxHeightPageBtn
->get_active())
49 m_xMaxHeightEdit
->set_sensitive(false);
52 IMPL_LINK_NOARG(SwFootNotePage
, HeightMetric
, weld::Toggleable
&, void)
54 if (m_xMaxHeightBtn
->get_active())
56 m_xMaxHeightEdit
->set_sensitive(true);
57 m_xMaxHeightEdit
->grab_focus();
61 // handler limit values
62 IMPL_LINK_NOARG(SwFootNotePage
, HeightModify
, weld::MetricSpinButton
&, void)
64 m_xMaxHeightEdit
->set_max(m_xMaxHeightEdit
->normalize(m_lMaxHeight
-
65 (m_xDistEdit
->denormalize(m_xDistEdit
->get_value(FieldUnit::TWIP
)) +
66 m_xLineDistEdit
->denormalize(m_xLineDistEdit
->get_value(FieldUnit::TWIP
)))),
68 if (m_xMaxHeightEdit
->get_value(FieldUnit::NONE
) < 0)
69 m_xMaxHeightEdit
->set_value(0, FieldUnit::NONE
);
70 m_xDistEdit
->set_max(m_xDistEdit
->normalize(m_lMaxHeight
-
71 (m_xMaxHeightEdit
->denormalize(m_xMaxHeightEdit
->get_value(FieldUnit::TWIP
)) +
72 m_xLineDistEdit
->denormalize(m_xLineDistEdit
->get_value(FieldUnit::TWIP
)))),
74 if (m_xDistEdit
->get_value(FieldUnit::NONE
) < 0)
75 m_xDistEdit
->set_value(0, FieldUnit::NONE
);
76 m_xLineDistEdit
->set_max(m_xLineDistEdit
->normalize(m_lMaxHeight
-
77 (m_xMaxHeightEdit
->denormalize(m_xMaxHeightEdit
->get_value(FieldUnit::TWIP
)) +
78 m_xDistEdit
->denormalize(m_xDistEdit
->get_value(FieldUnit::TWIP
)))),
82 IMPL_LINK_NOARG(SwFootNotePage
, LineWidthChanged_Impl
, weld::MetricSpinButton
&, void)
84 sal_Int64 nVal
= m_xLineWidthEdit
->get_value(FieldUnit::NONE
);
85 nVal
= static_cast<sal_Int64
>(vcl::ConvertDoubleValue(
87 m_xLineWidthEdit
->get_digits(),
88 m_xLineWidthEdit
->get_unit(), MapUnit::MapTwip
));
89 m_xLineTypeBox
->SetWidth(nVal
);
92 IMPL_LINK(SwFootNotePage
, LineColorSelected_Impl
, ColorListBox
&, rColorBox
, void)
94 m_xLineTypeBox
->SetColor(rColorBox
.GetSelectEntryColor());
97 SwFootNotePage::SwFootNotePage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
&rSet
)
98 : SfxTabPage(pPage
, pController
, u
"modules/swriter/ui/footnoteareapage.ui"_ustr
, u
"FootnoteAreaPage"_ustr
, &rSet
)
100 , m_xMaxHeightPageBtn(m_xBuilder
->weld_radio_button(u
"maxheightpage"_ustr
))
101 , m_xMaxHeightBtn(m_xBuilder
->weld_radio_button(u
"maxheight"_ustr
))
102 , m_xMaxHeightEdit(m_xBuilder
->weld_metric_spin_button(u
"maxheightsb"_ustr
, FieldUnit::CM
))
103 , m_xDistLabel(m_xBuilder
->weld_label(u
"spacetotextlabel"_ustr
))
104 , m_xDistEdit(m_xBuilder
->weld_metric_spin_button(u
"spacetotext"_ustr
, FieldUnit::CM
))
105 , m_xLinePosLabel(m_xBuilder
->weld_label(u
"positionlabel"_ustr
))
106 , m_xLinePosBox(m_xBuilder
->weld_combo_box(u
"position"_ustr
))
107 , m_xLineTypeBox(new SvtLineListBox(m_xBuilder
->weld_menu_button(u
"style"_ustr
)))
108 , m_xLineWidthEdit(m_xBuilder
->weld_metric_spin_button(u
"thickness"_ustr
, FieldUnit::POINT
))
109 , m_xLineColorBox(new ColorListBox(m_xBuilder
->weld_menu_button(u
"color"_ustr
),
110 [this]{ return GetDialogController()->getDialog(); }))
111 , m_xLineLengthLabel(m_xBuilder
->weld_label(u
"lengthlabel"_ustr
))
112 , m_xLineLengthEdit(m_xBuilder
->weld_metric_spin_button(u
"length"_ustr
, FieldUnit::PERCENT
))
113 , m_xLineDistLabel(m_xBuilder
->weld_label(u
"spacingtocontentslabel"_ustr
))
114 , m_xLineDistEdit(m_xBuilder
->weld_metric_spin_button(u
"spacingtocontents"_ustr
, FieldUnit::CM
))
116 SetExchangeSupport();
117 FieldUnit aMetric
= ::GetDfltMetric(false);
118 ::SetFieldUnit(*m_xMaxHeightEdit
, aMetric
);
119 ::SetFieldUnit(*m_xDistEdit
, aMetric
);
120 ::SetFieldUnit(*m_xLineDistEdit
, aMetric
);
121 MeasurementSystem eSys
= SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
122 tools::Long nHeightValue
= MeasurementSystem::Metric
!= eSys
? 1440 : 1134;
123 m_xMaxHeightEdit
->set_value(m_xMaxHeightEdit
->normalize(nHeightValue
),FieldUnit::TWIP
);
125 bool bContinuousEndnotes
= false;
126 if (const SfxGrabBagItem
* pGragbagItem
= rSet
.GetItemIfSet(SID_ATTR_CHAR_GRABBAG
))
128 auto it
= pGragbagItem
->GetGrabBag().find(u
"ContinuousEndnotes"_ustr
);
129 if (it
!= pGragbagItem
->GetGrabBag().end())
131 it
->second
>>= bContinuousEndnotes
;
135 if (bContinuousEndnotes
)
137 // These are ignored in SwFootnoteContFrame::Format() and SwFootnoteContFrame::PaintLine(),
139 m_xDistLabel
->set_visible(false);
140 m_xDistEdit
->set_visible(false);
141 m_xLinePosLabel
->set_visible(false);
142 m_xLinePosBox
->set_visible(false);
143 m_xLineLengthLabel
->set_visible(false);
144 m_xLineLengthEdit
->set_visible(false);
145 m_xLineDistLabel
->set_visible(false);
146 m_xLineDistEdit
->set_visible(false);
150 SwFootNotePage::~SwFootNotePage()
152 m_xLineColorBox
.reset();
153 m_xLineTypeBox
.reset();
156 std::unique_ptr
<SfxTabPage
> SwFootNotePage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
*rSet
)
158 return std::make_unique
<SwFootNotePage
>(pPage
, pController
, *rSet
);
161 void SwFootNotePage::Reset(const SfxItemSet
*rSet
)
163 // if no example exists, otherwise Init here in Activate
164 std::optional
<SwPageFootnoteInfo
> pDefFootnoteInfo
;
165 const SwPageFootnoteInfo
* pFootnoteInfo
;
166 const SfxPoolItem
* pItem
= SfxTabPage::GetItem(*rSet
, FN_PARAM_FTN_INFO
);
169 pFootnoteInfo
= &static_cast<const SwPageFootnoteInfoItem
*>(pItem
)->GetPageFootnoteInfo();
173 // when "standard" is being activated the footnote item is deleted,
174 // that's why a footnote structure has to be created here
175 pDefFootnoteInfo
.emplace();
176 pFootnoteInfo
= &*pDefFootnoteInfo
;
178 // footnote area's height
179 SwTwips lHeight
= pFootnoteInfo
->GetHeight();
182 m_xMaxHeightEdit
->set_value(m_xMaxHeightEdit
->normalize(lHeight
),FieldUnit::TWIP
);
183 m_xMaxHeightBtn
->set_active(true);
187 m_xMaxHeightPageBtn
->set_active(true);
188 m_xMaxHeightEdit
->set_sensitive(false);
190 m_xMaxHeightPageBtn
->connect_toggled(LINK(this,SwFootNotePage
,HeightPage
));
191 m_xMaxHeightBtn
->connect_toggled(LINK(this,SwFootNotePage
,HeightMetric
));
192 Link
<weld::MetricSpinButton
&,void> aLk
= LINK(this, SwFootNotePage
, HeightModify
);
193 m_xMaxHeightEdit
->connect_value_changed(aLk
);
194 m_xDistEdit
->connect_value_changed(aLk
);
195 m_xLineDistEdit
->connect_value_changed(aLk
);
198 m_xLineWidthEdit
->connect_value_changed(LINK(this, SwFootNotePage
, LineWidthChanged_Impl
));
200 sal_Int64 nWidthPt
= static_cast<sal_Int64
>(vcl::ConvertDoubleValue(
201 sal_Int64( pFootnoteInfo
->GetLineWidth() ), m_xLineWidthEdit
->get_digits(),
202 MapUnit::MapTwip
, m_xLineWidthEdit
->get_unit( ) ));
203 m_xLineWidthEdit
->set_value(nWidthPt
, FieldUnit::NONE
);
206 m_xLineTypeBox
->SetSourceUnit( FieldUnit::TWIP
);
208 m_xLineTypeBox
->InsertEntry(
209 ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::SOLID
),
210 SvxBorderLineStyle::SOLID
);
211 m_xLineTypeBox
->InsertEntry(
212 ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::DOTTED
),
213 SvxBorderLineStyle::DOTTED
);
214 m_xLineTypeBox
->InsertEntry(
215 ::editeng::SvxBorderLine::getWidthImpl(SvxBorderLineStyle::DASHED
),
216 SvxBorderLineStyle::DASHED
);
217 m_xLineTypeBox
->SetWidth( pFootnoteInfo
->GetLineWidth( ) );
218 m_xLineTypeBox
->SelectEntry( pFootnoteInfo
->GetLineStyle() );
221 m_xLineColorBox
->SelectEntry(pFootnoteInfo
->GetLineColor());
222 m_xLineColorBox
->SetSelectHdl(LINK(this, SwFootNotePage
, LineColorSelected_Impl
));
223 m_xLineTypeBox
->SetColor(pFootnoteInfo
->GetLineColor());
226 m_xLinePosBox
->set_active(static_cast<sal_Int32
>(pFootnoteInfo
->GetAdj()));
229 Fraction
aTmp( 100, 1 );
230 aTmp
*= pFootnoteInfo
->GetWidth();
231 m_xLineLengthEdit
->set_value(static_cast<tools::Long
>(aTmp
), FieldUnit::PERCENT
);
234 m_xDistEdit
->set_value(m_xDistEdit
->normalize(pFootnoteInfo
->GetTopDist()), FieldUnit::TWIP
);
235 m_xLineDistEdit
->set_value(
236 m_xLineDistEdit
->normalize(pFootnoteInfo
->GetBottomDist()), FieldUnit::TWIP
);
237 ActivatePage( *rSet
);
240 // stuff attributes into the set, when OK
241 bool SwFootNotePage::FillItemSet(SfxItemSet
*rSet
)
243 SwPageFootnoteInfoItem
aItem(GetItemSet().Get(FN_PARAM_FTN_INFO
));
245 // that's the original
246 SwPageFootnoteInfo
&rFootnoteInfo
= aItem
.GetPageFootnoteInfo();
248 // footnote area's height
249 if (m_xMaxHeightBtn
->get_active())
250 rFootnoteInfo
.SetHeight( static_cast< SwTwips
>(
251 m_xMaxHeightEdit
->denormalize(m_xMaxHeightEdit
->get_value(FieldUnit::TWIP
))));
253 rFootnoteInfo
.SetHeight(0);
256 rFootnoteInfo
.SetTopDist( static_cast< SwTwips
>(
257 m_xDistEdit
->denormalize(m_xDistEdit
->get_value(FieldUnit::TWIP
))));
258 rFootnoteInfo
.SetBottomDist( static_cast< SwTwips
>(
259 m_xLineDistEdit
->denormalize(m_xLineDistEdit
->get_value(FieldUnit::TWIP
))));
262 rFootnoteInfo
.SetLineStyle(m_xLineTypeBox
->GetSelectEntryStyle());
265 sal_Int64 nWidth
= m_xLineWidthEdit
->get_value(FieldUnit::NONE
);
266 nWidth
= static_cast<tools::Long
>(vcl::ConvertDoubleValue(
268 m_xLineWidthEdit
->get_digits(),
269 m_xLineWidthEdit
->get_unit(), MapUnit::MapTwip
));
270 rFootnoteInfo
.SetLineWidth( nWidth
);
273 rFootnoteInfo
.SetLineColor(m_xLineColorBox
->GetSelectEntryColor());
276 rFootnoteInfo
.SetAdj(static_cast<css::text::HorizontalAdjust
>(m_xLinePosBox
->get_active()));
279 rFootnoteInfo
.SetWidth(Fraction(m_xLineLengthEdit
->get_value(FieldUnit::PERCENT
), 100));
281 const SfxPoolItem
* pOldItem
;
282 if(nullptr == (pOldItem
= GetOldItem( *rSet
, FN_PARAM_FTN_INFO
)) ||
289 void SwFootNotePage::ActivatePage(const SfxItemSet
& rSet
)
291 auto const & rSize
= rSet
.Get( RES_FRM_SIZE
);
292 m_lMaxHeight
= rSize
.GetHeight();
294 if( const SvxSetItem
* pHeaderSetItem
= rSet
.GetItemIfSet( rSet
.GetPool()->GetWhichIDFromSlotID( SID_ATTR_PAGE_HEADERSET
), false ) )
296 const SfxItemSet
& rHeaderSet
= pHeaderSetItem
->GetItemSet();
297 const SfxBoolItem
& rHeaderOn
=
298 rHeaderSet
.Get( rSet
.GetPool()->GetWhichIDFromSlotID( SID_ATTR_PAGE_ON
) );
300 if ( rHeaderOn
.GetValue() )
302 const SvxSizeItem
& rSizeItem
=
303 rHeaderSet
.Get(rSet
.GetPool()->GetWhichIDFromSlotID(SID_ATTR_PAGE_SIZE
));
304 m_lMaxHeight
-= rSizeItem
.GetSize().Height();
308 if( const SvxSetItem
* pFooterSetItem
= rSet
.GetItemIfSet( rSet
.GetPool()->GetWhichIDFromSlotID( SID_ATTR_PAGE_FOOTERSET
),
311 const SfxItemSet
& rFooterSet
= pFooterSetItem
->GetItemSet();
312 const SfxBoolItem
& rFooterOn
= rFooterSet
.Get( SID_ATTR_PAGE_ON
);
314 if ( rFooterOn
.GetValue() )
316 const SvxSizeItem
& rSizeItem
=
317 rFooterSet
.Get( rSet
.GetPool()->GetWhichIDFromSlotID( SID_ATTR_PAGE_SIZE
) );
318 m_lMaxHeight
-= rSizeItem
.GetSize().Height();
322 if ( const SvxULSpaceItem
* pSpaceItem
= rSet
.GetItemIfSet( RES_UL_SPACE
, false ) )
324 m_lMaxHeight
-= pSpaceItem
->GetUpper() + pSpaceItem
->GetLower();
330 // set maximum values
331 HeightModify(*m_xMaxHeightEdit
);
334 DeactivateRC
SwFootNotePage::DeactivatePage( SfxItemSet
* _pSet
)
339 return DeactivateRC::LeavePage
;
342 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */