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>
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
39using namespace ::com::sun::star;
40
41const WhichRangesContainer SwFootNotePage::s_aPageRg(svl::Items<FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO>);
42
43// handler to switch between the different possibilities how the footnote
44// region's height can be set.
46{
47 if (m_xMaxHeightPageBtn->get_active())
48 m_xMaxHeightEdit->set_sensitive(false);
49}
50
52{
53 if (m_xMaxHeightBtn->get_active())
54 {
55 m_xMaxHeightEdit->set_sensitive(true);
56 m_xMaxHeightEdit->grab_focus();
57 }
58}
59
60// handler limit values
62{
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)))),
66 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)))),
72 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)))),
78 FieldUnit::TWIP);
79}
80
82{
83 sal_Int64 nVal = m_xLineWidthEdit->get_value(FieldUnit::NONE);
84 nVal = static_cast<sal_Int64>(vcl::ConvertDoubleValue(
85 nVal,
86 m_xLineWidthEdit->get_digits(),
87 m_xLineWidthEdit->get_unit(), MapUnit::MapTwip ));
88 m_xLineTypeBox->SetWidth(nVal);
89}
90
91IMPL_LINK(SwFootNotePage, LineColorSelected_Impl, ColorListBox&, rColorBox, void)
92{
93 m_xLineTypeBox->SetColor(rColorBox.GetSelectEntryColor());
94}
95
97 : SfxTabPage(pPage, pController, "modules/swriter/ui/footnoteareapage.ui", "FootnoteAreaPage", &rSet)
98 , m_lMaxHeight(0)
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))
110{
111 SetExchangeSupport();
112 FieldUnit aMetric = ::GetDfltMetric(false);
113 ::SetFieldUnit(*m_xMaxHeightEdit, aMetric);
114 ::SetFieldUnit(*m_xDistEdit, aMetric);
115 ::SetFieldUnit(*m_xLineDistEdit, aMetric);
117 tools::Long nHeightValue = MeasurementSystem::Metric != eSys ? 1440 : 1134;
118 m_xMaxHeightEdit->set_value(m_xMaxHeightEdit->normalize(nHeightValue),FieldUnit::TWIP);
119}
120
122{
123 m_xLineColorBox.reset();
124 m_xLineTypeBox.reset();
125}
126
127std::unique_ptr<SfxTabPage> SwFootNotePage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet *rSet)
128{
129 return std::make_unique<SwFootNotePage>(pPage, pController, *rSet);
130}
131
133{
134 // if no example exists, otherwise Init here in Activate
135 std::optional<SwPageFootnoteInfo> pDefFootnoteInfo;
136 const SwPageFootnoteInfo* pFootnoteInfo;
138 if( pItem )
139 {
140 pFootnoteInfo = &static_cast<const SwPageFootnoteInfoItem*>(pItem)->GetPageFootnoteInfo();
141 }
142 else
143 {
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;
148 }
149 // footnote area's height
150 SwTwips lHeight = pFootnoteInfo->GetHeight();
151 if(lHeight)
152 {
153 m_xMaxHeightEdit->set_value(m_xMaxHeightEdit->normalize(lHeight),FieldUnit::TWIP);
154 m_xMaxHeightBtn->set_active(true);
155 }
156 else
157 {
158 m_xMaxHeightPageBtn->set_active(true);
159 m_xMaxHeightEdit->set_sensitive(false);
160 }
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);
167
168 // Separator width
169 m_xLineWidthEdit->connect_value_changed(LINK(this, SwFootNotePage, LineWidthChanged_Impl));
170
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);
175
176 // Separator style
177 m_xLineTypeBox->SetSourceUnit( FieldUnit::TWIP );
178
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() );
190
191 // Separator Color
192 m_xLineColorBox->SelectEntry(pFootnoteInfo->GetLineColor());
193 m_xLineColorBox->SetSelectHdl(LINK(this, SwFootNotePage, LineColorSelected_Impl));
194 m_xLineTypeBox->SetColor(pFootnoteInfo->GetLineColor());
195
196 // position
197 m_xLinePosBox->set_active(static_cast<sal_Int32>(pFootnoteInfo->GetAdj()));
198
199 // width
200 Fraction aTmp( 100, 1 );
201 aTmp *= pFootnoteInfo->GetWidth();
202 m_xLineLengthEdit->set_value(static_cast<tools::Long>(aTmp), FieldUnit::PERCENT);
203
204 // gap footnote area
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 );
209}
210
211// stuff attributes into the set, when OK
213{
215
216 // that's the original
217 SwPageFootnoteInfo &rFootnoteInfo = aItem.GetPageFootnoteInfo();
218
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))));
223 else
224 rFootnoteInfo.SetHeight(0);
225
226 // gap footnote area
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))));
231
232 // Separator style
233 rFootnoteInfo.SetLineStyle(m_xLineTypeBox->GetSelectEntryStyle());
234
235 // Separator width
236 sal_Int64 nWidth = m_xLineWidthEdit->get_value(FieldUnit::NONE);
237 nWidth = static_cast<tools::Long>(vcl::ConvertDoubleValue(
238 nWidth,
239 m_xLineWidthEdit->get_digits(),
240 m_xLineWidthEdit->get_unit(), MapUnit::MapTwip ));
241 rFootnoteInfo.SetLineWidth( nWidth );
242
243 // Separator color
244 rFootnoteInfo.SetLineColor(m_xLineColorBox->GetSelectEntryColor());
245
246 // Position
247 rFootnoteInfo.SetAdj(static_cast<css::text::HorizontalAdjust>(m_xLinePosBox->get_active()));
248
249 // Width
250 rFootnoteInfo.SetWidth(Fraction(m_xLineLengthEdit->get_value(FieldUnit::PERCENT), 100));
251
252 const SfxPoolItem* pOldItem;
253 if(nullptr == (pOldItem = GetOldItem( *rSet, FN_PARAM_FTN_INFO )) ||
254 aItem != *pOldItem )
255 rSet->Put(aItem);
256
257 return true;
258}
259
261{
262 auto const & rSize = rSet.Get( RES_FRM_SIZE );
263 m_lMaxHeight = rSize.GetHeight();
264
265 if( const SvxSetItem* pHeaderSetItem = rSet.GetItemIfSet( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET), false ) )
266 {
267 const SfxItemSet& rHeaderSet = pHeaderSetItem->GetItemSet();
268 const SfxBoolItem& rHeaderOn =
269 rHeaderSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_ON ) );
270
271 if ( rHeaderOn.GetValue() )
272 {
273 const SvxSizeItem& rSizeItem =
274 rHeaderSet.Get(rSet.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE));
275 m_lMaxHeight -= rSizeItem.GetSize().Height();
276 }
277 }
278
279 if( const SvxSetItem* pFooterSetItem = rSet.GetItemIfSet( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET),
280 false ) )
281 {
282 const SfxItemSet& rFooterSet = pFooterSetItem->GetItemSet();
283 const SfxBoolItem& rFooterOn = rFooterSet.Get( SID_ATTR_PAGE_ON );
284
285 if ( rFooterOn.GetValue() )
286 {
287 const SvxSizeItem& rSizeItem =
288 rFooterSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE ) );
289 m_lMaxHeight -= rSizeItem.GetSize().Height();
290 }
291 }
292
293 if ( const SvxULSpaceItem* pSpaceItem = rSet.GetItemIfSet( RES_UL_SPACE , false ) )
294 {
295 m_lMaxHeight -= pSpaceItem->GetUpper() + pSpaceItem->GetLower();
296 }
297
298 m_lMaxHeight *= 8;
299 m_lMaxHeight /= 10;
300
301 // set maximum values
302 HeightModify(*m_xMaxHeightEdit);
303}
304
306{
307 if(_pSet)
308 FillItemSet(_pSet);
309
310 return DeactivateRC::LeavePage;
311}
312
313/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
MeasurementSystem getMeasurementSystemEnum() const
bool GetValue() const
sal_uInt16 GetWhich(sal_uInt16 nSlot, bool bDeep=true) const
SfxItemPool * GetPool() const
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SfxItemSet & GetItemSet() const
SfxOkDialogController * GetDialogController() const
static const SfxPoolItem * GetItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
const SfxPoolItem * GetOldItem(const SfxItemSet &rSet, sal_uInt16 nSlot, bool bDeep=true)
constexpr tools::Long Height() const
const LocaleDataWrapper & GetLocaleData() const
const Size & GetSize() const
static const WhichRangesContainer s_aPageRg
Definition: pgfnote.hxx:29
std::unique_ptr< ColorListBox > m_xLineColorBox
Definition: pgfnote.hxx:51
virtual bool FillItemSet(SfxItemSet *rSet) override
Definition: pgfnote.cxx:212
std::unique_ptr< weld::MetricSpinButton > m_xLineDistEdit
Definition: pgfnote.hxx:53
std::unique_ptr< weld::MetricSpinButton > m_xDistEdit
Definition: pgfnote.hxx:47
std::unique_ptr< weld::MetricSpinButton > m_xLineLengthEdit
Definition: pgfnote.hxx:52
std::unique_ptr< SvtLineListBox > m_xLineTypeBox
Definition: pgfnote.hxx:49
SwFootNotePage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: pgfnote.cxx:96
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: pgfnote.cxx:260
virtual void Reset(const SfxItemSet *rSet) override
Definition: pgfnote.cxx:132
std::unique_ptr< weld::MetricSpinButton > m_xLineWidthEdit
Definition: pgfnote.hxx:50
std::unique_ptr< weld::RadioButton > m_xMaxHeightPageBtn
Definition: pgfnote.hxx:44
tools::Long m_lMaxHeight
Definition: pgfnote.hxx:42
std::unique_ptr< weld::RadioButton > m_xMaxHeightBtn
Definition: pgfnote.hxx:45
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: pgfnote.cxx:127
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: pgfnote.cxx:305
virtual ~SwFootNotePage() override
Definition: pgfnote.cxx:121
std::unique_ptr< weld::ComboBox > m_xLinePosBox
Definition: pgfnote.hxx:48
std::unique_ptr< weld::MetricSpinButton > m_xMaxHeightEdit
Definition: pgfnote.hxx:46
SwPageFootnoteInfo & GetPageFootnoteInfo()
Definition: uiitems.hxx:57
Footnote information.
Definition: pagedesc.hxx:49
SwTwips GetHeight() const
Definition: pagedesc.hxx:61
sal_uLong GetLineWidth() const
Definition: pagedesc.hxx:62
SwTwips GetTopDist() const
Definition: pagedesc.hxx:67
void SetBottomDist(SwTwips const nNew)
Definition: pagedesc.hxx:77
void SetWidth(const Fraction &rNew)
Definition: pagedesc.hxx:74
void SetLineWidth(sal_uLong const nSet)
Definition: pagedesc.hxx:71
css::text::HorizontalAdjust GetAdj() const
Definition: pagedesc.hxx:66
void SetLineStyle(SvxBorderLineStyle const eSet)
Definition: pagedesc.hxx:72
void SetAdj(css::text::HorizontalAdjust const eNew)
Definition: pagedesc.hxx:75
const Color & GetLineColor() const
Definition: pagedesc.hxx:63
void SetHeight(SwTwips const nNew)
Definition: pagedesc.hxx:70
void SetTopDist(SwTwips const nNew)
Definition: pagedesc.hxx:76
SwTwips GetBottomDist() const
Definition: pagedesc.hxx:68
void SetLineColor(const Color &rCol)
Definition: pagedesc.hxx:73
const Fraction & GetWidth() const
Definition: pagedesc.hxx:65
SvxBorderLineStyle GetLineStyle() const
Definition: pagedesc.hxx:64
static BorderWidthImpl getWidthImpl(SvxBorderLineStyle nStyle)
#define FN_PARAM_FTN_INFO
Definition: cmdid.h:808
FieldUnit
constexpr TypedWhichId< SwFormatFrameSize > RES_FRM_SIZE(89)
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(98)
MeasurementSystem
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
long Long
double ConvertDoubleValue(double nValue, sal_Int64 mnBaseValue, sal_uInt16 nDecDigits, FieldUnit eInUnit, FieldUnit eOutUnit)
IMPL_LINK(SwFootNotePage, LineColorSelected_Impl, ColorListBox &, rColorBox, void)
Definition: pgfnote.cxx:91
IMPL_LINK_NOARG(SwFootNotePage, HeightPage, weld::Toggleable &, void)
Definition: pgfnote.cxx:45
static SfxItemSet & rSet
tools::Long SwTwips
Definition: swtypes.hxx:51
DeactivateRC
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:756