lok: Hide file linking in section
[LibreOffice.git] / sw / source / ui / misc / pgfnote.cxx
blob910bccd1c7f671c48aa9020101ecd76d082503d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
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>
31 #include <unotools/localedatawrapper.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>
44 #include <globals.hrc>
45 #include <strings.hrc>
46 #include <memory>
48 using namespace ::com::sun::star;
50 const sal_uInt16 SwFootNotePage::aPageRg[] = {
51 FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO,
55 // handler to switch between the different possibilities how the footnote
56 // region's height can be set.
57 IMPL_LINK_NOARG(SwFootNotePage, HeightPage, weld::ToggleButton&, void)
59 if (m_xMaxHeightPageBtn->get_active())
60 m_xMaxHeightEdit->set_sensitive(false);
63 IMPL_LINK_NOARG(SwFootNotePage, HeightMetric, weld::ToggleButton&, void)
65 if (m_xMaxHeightBtn->get_active())
67 m_xMaxHeightEdit->set_sensitive(true);
68 m_xMaxHeightEdit->grab_focus();
72 // handler limit values
73 IMPL_LINK_NOARG(SwFootNotePage, HeightModify, weld::MetricSpinButton&, void)
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);
93 IMPL_LINK_NOARG(SwFootNotePage, LineWidthChanged_Impl, weld::MetricSpinButton&, void)
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);
103 IMPL_LINK(SwFootNotePage, LineColorSelected_Impl, ColorListBox&, rColorBox, void)
105 m_xLineTypeBox->SetColor(rColorBox.GetSelectEntryColor());
108 SwFootNotePage::SwFootNotePage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet &rSet)
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))
122 SetExchangeSupport();
123 FieldUnit aMetric = ::GetDfltMetric(false);
124 ::SetFieldUnit(*m_xMaxHeightEdit, aMetric);
125 ::SetFieldUnit(*m_xDistEdit, aMetric);
126 ::SetFieldUnit(*m_xLineDistEdit, aMetric);
127 MeasurementSystem eSys = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
128 long nHeightValue = MeasurementSystem::Metric != eSys ? 1440 : 1134;
129 m_xMaxHeightEdit->set_value(m_xMaxHeightEdit->normalize(nHeightValue),FieldUnit::TWIP);
132 SwFootNotePage::~SwFootNotePage()
134 m_xLineColorBox.reset();
135 m_xLineTypeBox.reset();
138 std::unique_ptr<SfxTabPage> SwFootNotePage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
140 return std::make_unique<SwFootNotePage>(pPage, pController, *rSet);
143 void SwFootNotePage::Reset(const SfxItemSet *rSet)
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 )
151 pFootnoteInfo = &static_cast<const SwPageFootnoteInfoItem*>(pItem)->GetPageFootnoteInfo();
153 else
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();
160 // footnote area's height
161 SwTwips lHeight = pFootnoteInfo->GetHeight();
162 if(lHeight)
164 m_xMaxHeightEdit->set_value(m_xMaxHeightEdit->normalize(lHeight),FieldUnit::TWIP);
165 m_xMaxHeightBtn->set_active(true);
167 else
169 m_xMaxHeightPageBtn->set_active(true);
170 m_xMaxHeightEdit->set_sensitive(false);
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);
179 // Separator width
180 m_xLineWidthEdit->connect_value_changed(LINK(this, SwFootNotePage, LineWidthChanged_Impl));
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);
187 // Separator style
188 m_xLineTypeBox->SetSourceUnit( FieldUnit::TWIP );
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() );
202 // Separator Color
203 m_xLineColorBox->SelectEntry(pFootnoteInfo->GetLineColor());
204 m_xLineColorBox->SetSelectHdl(LINK(this, SwFootNotePage, LineColorSelected_Impl));
205 m_xLineTypeBox->SetColor(pFootnoteInfo->GetLineColor());
207 // position
208 m_xLinePosBox->set_active(static_cast<sal_Int32>(pFootnoteInfo->GetAdj()));
210 // width
211 Fraction aTmp( 100, 1 );
212 aTmp *= pFootnoteInfo->GetWidth();
213 m_xLineLengthEdit->set_value(static_cast<long>(aTmp), FieldUnit::PERCENT);
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 );
222 // stuff attributes into the set, when OK
223 bool SwFootNotePage::FillItemSet(SfxItemSet *rSet)
225 SwPageFootnoteInfoItem aItem(static_cast<const SwPageFootnoteInfoItem&>(GetItemSet().Get(FN_PARAM_FTN_INFO)));
227 // that's the original
228 SwPageFootnoteInfo &rFootnoteInfo = aItem.GetPageFootnoteInfo();
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);
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))));
243 // Separator style
244 rFootnoteInfo.SetLineStyle(m_xLineTypeBox->GetSelectEntryStyle());
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 );
254 // Separator color
255 rFootnoteInfo.SetLineColor(m_xLineColorBox->GetSelectEntryColor());
257 // Position
258 rFootnoteInfo.SetAdj(static_cast<css::text::HorizontalAdjust>(m_xLinePosBox->get_active()));
260 // Width
261 rFootnoteInfo.SetWidth(Fraction(m_xLineLengthEdit->get_value(FieldUnit::PERCENT), 100));
263 const SfxPoolItem* pOldItem;
264 if(nullptr == (pOldItem = GetOldItem( *rSet, FN_PARAM_FTN_INFO )) ||
265 aItem != *pOldItem )
266 rSet->Put(aItem);
268 return true;
271 void SwFootNotePage::ActivatePage(const SfxItemSet& rSet)
273 auto const & rSize = rSet.Get( RES_FRM_SIZE );
274 lMaxHeight = rSize.GetHeight();
276 const SfxPoolItem* pItem;
277 if( SfxItemState::SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET), false, &pItem ) )
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 ) ));
283 if ( rHeaderOn.GetValue() )
285 const SvxSizeItem& rSizeItem =
286 static_cast<const SvxSizeItem&>(rHeaderSet.Get(rSet.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE)));
287 lMaxHeight -= rSizeItem.GetSize().Height();
291 if( SfxItemState::SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET),
292 false, &pItem ) )
294 const SfxItemSet& rFooterSet = static_cast<const SvxSetItem*>(pItem)->GetItemSet();
295 const SfxBoolItem& rFooterOn = rFooterSet.Get( SID_ATTR_PAGE_ON );
297 if ( rFooterOn.GetValue() )
299 const SvxSizeItem& rSizeItem =
300 static_cast<const SvxSizeItem&>(rFooterSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE ) ));
301 lMaxHeight -= rSizeItem.GetSize().Height();
305 if ( rSet.GetItemState( RES_UL_SPACE , false ) == SfxItemState::SET )
307 const SvxULSpaceItem &rUL = rSet.Get( RES_UL_SPACE );
308 lMaxHeight -= rUL.GetUpper() + rUL.GetLower();
311 lMaxHeight *= 8;
312 lMaxHeight /= 10;
314 // set maximum values
315 HeightModify(*m_xMaxHeightEdit);
318 DeactivateRC SwFootNotePage::DeactivatePage( SfxItemSet* _pSet)
320 if(_pSet)
321 FillItemSet(_pSet);
323 return DeactivateRC::LeavePage;
326 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */