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 <hintids.hxx>
22 #include <svx/dialogs.hrc>
23 #include <svx/drawitem.hxx>
24 #include <svx/xtable.hxx> // XColorList
25 #include <sal/macros.h>
26 #include <vcl/field.hxx>
27 #include <vcl/svapp.hxx>
28 #include <unotools/localedatawrapper.hxx>
29 #include <unotools/syslocale.hxx>
30 #include <editeng/borderline.hxx>
31 #include <editeng/sizeitem.hxx>
32 #include <svx/pageitem.hxx>
33 #include <svl/eitem.hxx>
34 #include <editeng/ulspitem.hxx>
36 #include <pagedesc.hxx>
37 #include <pgfnote.hxx>
38 #include <uiitems.hxx>
39 #include <sfx2/objsh.hxx>
41 #include <globals.hrc>
45 using namespace ::com::sun::star
;
47 static sal_uInt16 aPageRg
[] = {
48 FN_PARAM_FTN_INFO
, FN_PARAM_FTN_INFO
,
52 /*------------------------------------------------------------------------
53 Description: handler to switch between the different possibilities
54 how the footnote region's height can be set.
55 ------------------------------------------------------------------------*/
56 IMPL_LINK_NOARG_INLINE_START(SwFootNotePage
, HeightPage
)
58 m_pMaxHeightEdit
->Enable(sal_False
);
61 IMPL_LINK_NOARG_INLINE_END(SwFootNotePage
, HeightPage
)
64 IMPL_LINK_NOARG_INLINE_START(SwFootNotePage
, HeightMetric
)
66 m_pMaxHeightEdit
->Enable();
67 m_pMaxHeightEdit
->GrabFocus();
70 IMPL_LINK_NOARG_INLINE_END(SwFootNotePage
, HeightMetric
)
72 /*------------------------------------------------------------------------
73 Description: handler limit values
74 ------------------------------------------------------------------------*/
75 IMPL_LINK_NOARG(SwFootNotePage
, HeightModify
)
77 m_pMaxHeightEdit
->SetMax(m_pMaxHeightEdit
->Normalize(lMaxHeight
-
78 (m_pDistEdit
->Denormalize(m_pDistEdit
->GetValue(FUNIT_TWIP
)) +
79 m_pLineDistEdit
->Denormalize(m_pLineDistEdit
->GetValue(FUNIT_TWIP
)))),
81 if(m_pMaxHeightEdit
->GetValue() < 0)
82 m_pMaxHeightEdit
->SetValue(0);
83 m_pDistEdit
->SetMax(m_pDistEdit
->Normalize(lMaxHeight
-
84 (m_pMaxHeightEdit
->Denormalize(m_pMaxHeightEdit
->GetValue(FUNIT_TWIP
)) +
85 m_pLineDistEdit
->Denormalize(m_pLineDistEdit
->GetValue(FUNIT_TWIP
)))),
87 if(m_pDistEdit
->GetValue() < 0)
88 m_pDistEdit
->SetValue(0);
89 m_pLineDistEdit
->SetMax(m_pLineDistEdit
->Normalize(lMaxHeight
-
90 (m_pMaxHeightEdit
->Denormalize(m_pMaxHeightEdit
->GetValue(FUNIT_TWIP
)) +
91 m_pDistEdit
->Denormalize(m_pDistEdit
->GetValue(FUNIT_TWIP
)))),
96 IMPL_LINK_NOARG(SwFootNotePage
, LineWidthChanged_Impl
)
98 sal_Int64 nVal
= static_cast<sal_Int64
>(MetricField::ConvertDoubleValue(
99 m_pLineWidthEdit
->GetValue( ),
100 m_pLineWidthEdit
->GetDecimalDigits( ),
101 m_pLineWidthEdit
->GetUnit(), MAP_TWIP
));
102 m_pLineTypeBox
->SetWidth( nVal
);
107 IMPL_LINK_NOARG(SwFootNotePage
, LineColorSelected_Impl
)
109 m_pLineTypeBox
->SetColor( m_pLineColorBox
->GetSelectEntryColor() );
113 SwFootNotePage::SwFootNotePage(Window
*pParent
, const SfxItemSet
&rSet
)
114 : SfxTabPage(pParent
, "FootnoteAreaPage",
115 "modules/swriter/ui/footnoteareapage.ui", rSet
)
117 get(m_pMaxHeightPageBtn
, "maxheightpage");
118 get(m_pMaxHeightBtn
, "maxheight");
119 get(m_pMaxHeightEdit
, "maxheightsb");
120 get(m_pDistEdit
, "spacetotext");
122 get(m_pLinePosBox
, "position");
123 get(m_pLineTypeBox
, "style");
124 get(m_pLineWidthEdit
, "thickness");
125 get(m_pLineColorBox
, "color");
126 get(m_pLineLengthEdit
, "length");
127 get(m_pLineDistEdit
, "spacingtocontents");
129 SetExchangeSupport();
130 FieldUnit aMetric
= ::GetDfltMetric(sal_False
);
131 SetMetric(*m_pMaxHeightEdit
, aMetric
);
132 SetMetric(*m_pDistEdit
, aMetric
);
133 SetMetric(*m_pLineDistEdit
, aMetric
);
134 MeasurementSystem eSys
= SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
135 long nHeightValue
= MEASURE_METRIC
!= eSys
? 1440 : 1134;
136 m_pMaxHeightEdit
->SetValue(m_pMaxHeightEdit
->Normalize(nHeightValue
),FUNIT_TWIP
);
139 SwFootNotePage::~SwFootNotePage()
143 SfxTabPage
* SwFootNotePage::Create(Window
*pParent
, const SfxItemSet
&rSet
)
145 return new SwFootNotePage(pParent
, rSet
);
148 void SwFootNotePage::Reset(const SfxItemSet
&rSet
)
150 // if no example exists, otherwise Init here in Activate
151 SwPageFtnInfo
* pDefFtnInfo
= 0;
152 const SwPageFtnInfo
* pFtnInfo
;
153 const SfxPoolItem
* pItem
= SfxTabPage::GetItem(rSet
, FN_PARAM_FTN_INFO
);
156 pFtnInfo
= &((const SwPageFtnInfoItem
*)pItem
)->GetPageFtnInfo();
160 // when "standard" is being activated the footnote item is deleted,
161 // that's why a footnote structure has to be created here
162 pDefFtnInfo
= new SwPageFtnInfo();
163 pFtnInfo
= pDefFtnInfo
;
165 // footnote area's height
166 SwTwips lHeight
= pFtnInfo
->GetHeight();
169 m_pMaxHeightEdit
->SetValue(m_pMaxHeightEdit
->Normalize(lHeight
),FUNIT_TWIP
);
170 m_pMaxHeightBtn
->Check(sal_True
);
174 m_pMaxHeightPageBtn
->Check(sal_True
);
175 m_pMaxHeightEdit
->Enable(sal_False
);
177 m_pMaxHeightPageBtn
->SetClickHdl(LINK(this,SwFootNotePage
,HeightPage
));
178 m_pMaxHeightBtn
->SetClickHdl(LINK(this,SwFootNotePage
,HeightMetric
));
179 Link aLk
= LINK(this, SwFootNotePage
, HeightModify
);
180 m_pMaxHeightEdit
->SetLoseFocusHdl( aLk
);
181 m_pDistEdit
->SetLoseFocusHdl( aLk
);
182 m_pLineDistEdit
->SetLoseFocusHdl( aLk
);
185 m_pLineWidthEdit
->SetModifyHdl( LINK( this, SwFootNotePage
, LineWidthChanged_Impl
) );
187 sal_Int64 nWidthPt
= static_cast<sal_Int64
>(MetricField::ConvertDoubleValue(
188 sal_Int64( pFtnInfo
->GetLineWidth() ), m_pLineWidthEdit
->GetDecimalDigits(),
189 MAP_TWIP
, m_pLineWidthEdit
->GetUnit( ) ));
190 m_pLineWidthEdit
->SetValue( nWidthPt
);
193 m_pLineTypeBox
->SetSourceUnit( FUNIT_TWIP
);
195 m_pLineTypeBox
->SetNone(SW_RESSTR(SW_STR_NONE
));
196 m_pLineTypeBox
->InsertEntry(
197 ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::SOLID
),
198 table::BorderLineStyle::SOLID
);
199 m_pLineTypeBox
->InsertEntry(
200 ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DOTTED
),
201 table::BorderLineStyle::DOTTED
);
202 m_pLineTypeBox
->InsertEntry(
203 ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DASHED
),
204 table::BorderLineStyle::DASHED
);
205 m_pLineTypeBox
->SetWidth( pFtnInfo
->GetLineWidth( ) );
206 m_pLineTypeBox
->SelectEntry( pFtnInfo
->GetLineStyle() );
209 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
210 XColorListRef pColorList
;
212 OSL_ENSURE( pDocSh
, "DocShell not found!" );
216 const SfxPoolItem
* pColorItem
= pDocSh
->GetItem( SID_COLOR_TABLE
);
217 if ( pColorItem
!= NULL
)
218 pColorList
= ( (SvxColorListItem
*)pColorItem
)->GetColorList();
221 OSL_ENSURE( pColorList
.is(), "ColorTable not found!" );
223 if ( pColorList
.is() )
225 m_pLineColorBox
->SetUpdateMode( sal_False
);
227 for ( long i
= 0; i
< pColorList
->Count(); ++i
)
229 XColorEntry
* pEntry
= pColorList
->GetColor(i
);
230 m_pLineColorBox
->InsertEntry( pEntry
->GetColor(), pEntry
->GetName() );
232 m_pLineColorBox
->SetUpdateMode( sal_True
);
235 // select color in the list or add it as a user color
236 sal_uInt16 nSelPos
= m_pLineColorBox
->GetEntryPos( pFtnInfo
->GetLineColor() );
237 if( nSelPos
== LISTBOX_ENTRY_NOTFOUND
)
238 nSelPos
= m_pLineColorBox
->InsertEntry( pFtnInfo
->GetLineColor(),
239 String( SW_RES( RID_SVXSTR_COLOR_USER
) ) );
241 m_pLineColorBox
->SetSelectHdl( LINK( this, SwFootNotePage
, LineColorSelected_Impl
) );
242 m_pLineColorBox
->SelectEntryPos( nSelPos
);
243 m_pLineTypeBox
->SetColor( pFtnInfo
->GetLineColor() );
247 m_pLinePosBox
->SelectEntryPos( static_cast< sal_uInt16
>(pFtnInfo
->GetAdj()) );
250 Fraction
aTmp( 100, 1 );
251 aTmp
*= pFtnInfo
->GetWidth();
252 m_pLineLengthEdit
->SetValue( static_cast<long>(aTmp
) );
255 m_pDistEdit
->SetValue(m_pDistEdit
->Normalize(pFtnInfo
->GetTopDist()),FUNIT_TWIP
);
256 m_pLineDistEdit
->SetValue(
257 m_pLineDistEdit
->Normalize(pFtnInfo
->GetBottomDist()), FUNIT_TWIP
);
258 ActivatePage( rSet
);
262 /*--------------------------------------------------------------------
263 Description: stuff attributes into the set, when OK
264 --------------------------------------------------------------------*/
265 sal_Bool
SwFootNotePage::FillItemSet(SfxItemSet
&rSet
)
267 SwPageFtnInfoItem
aItem((const SwPageFtnInfoItem
&)GetItemSet().Get(FN_PARAM_FTN_INFO
));
269 // that's the original
270 SwPageFtnInfo
&rFtnInfo
= aItem
.GetPageFtnInfo();
272 // footnote area's height
273 if(m_pMaxHeightBtn
->IsChecked())
274 rFtnInfo
.SetHeight( static_cast< SwTwips
>(
275 m_pMaxHeightEdit
->Denormalize(m_pMaxHeightEdit
->GetValue(FUNIT_TWIP
))));
277 rFtnInfo
.SetHeight(0);
280 rFtnInfo
.SetTopDist( static_cast< SwTwips
>(
281 m_pDistEdit
->Denormalize(m_pDistEdit
->GetValue(FUNIT_TWIP
))));
282 rFtnInfo
.SetBottomDist( static_cast< SwTwips
>(
283 m_pLineDistEdit
->Denormalize(m_pLineDistEdit
->GetValue(FUNIT_TWIP
))));
286 rFtnInfo
.SetLineStyle( ::editeng::SvxBorderStyle( m_pLineTypeBox
->GetSelectEntryStyle() ) );
289 long nWidth
= static_cast<long>(MetricField::ConvertDoubleValue(
290 m_pLineWidthEdit
->GetValue( ),
291 m_pLineWidthEdit
->GetDecimalDigits( ),
292 m_pLineWidthEdit
->GetUnit(), MAP_TWIP
));
293 rFtnInfo
.SetLineWidth( nWidth
);
296 rFtnInfo
.SetLineColor( m_pLineColorBox
->GetSelectEntryColor() );
299 rFtnInfo
.SetAdj((SwFtnAdj
)m_pLinePosBox
->GetSelectEntryPos());
302 rFtnInfo
.SetWidth(Fraction( static_cast< long >(m_pLineLengthEdit
->GetValue()), 100));
304 const SfxPoolItem
* pOldItem
;
305 if(0 == (pOldItem
= GetOldItem( rSet
, FN_PARAM_FTN_INFO
)) ||
312 void SwFootNotePage::ActivatePage(const SfxItemSet
& rSet
)
314 const SvxSizeItem
& rSize
= (const SvxSizeItem
&)rSet
.Get( RES_FRM_SIZE
);
315 lMaxHeight
= rSize
.GetSize().Height();
317 const SfxPoolItem
* pItem
;
318 if( SFX_ITEM_SET
== rSet
.GetItemState( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET
), sal_False
, &pItem
) )
320 const SfxItemSet
& rHeaderSet
= ((SvxSetItem
*)pItem
)->GetItemSet();
321 const SfxBoolItem
& rHeaderOn
=
322 (const SfxBoolItem
&)rHeaderSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_ON
) );
324 if ( rHeaderOn
.GetValue() )
326 const SvxSizeItem
& rSizeItem
=
327 (const SvxSizeItem
&)rHeaderSet
.Get(rSet
.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE
));
328 lMaxHeight
-= rSizeItem
.GetSize().Height();
332 if( SFX_ITEM_SET
== rSet
.GetItemState( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET
),
333 sal_False
, &pItem
) )
335 const SfxItemSet
& rFooterSet
= ((SvxSetItem
*)pItem
)->GetItemSet();
336 const SfxBoolItem
& rFooterOn
=
337 (const SfxBoolItem
&)rFooterSet
.Get( SID_ATTR_PAGE_ON
);
339 if ( rFooterOn
.GetValue() )
341 const SvxSizeItem
& rSizeItem
=
342 (const SvxSizeItem
&)rFooterSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE
) );
343 lMaxHeight
-= rSizeItem
.GetSize().Height();
347 if ( rSet
.GetItemState( RES_UL_SPACE
, sal_False
) == SFX_ITEM_SET
)
349 const SvxULSpaceItem
&rUL
= (const SvxULSpaceItem
&)rSet
.Get( RES_UL_SPACE
);
350 lMaxHeight
-= rUL
.GetUpper() + rUL
.GetLower();
356 // set maximum values
360 int SwFootNotePage::DeactivatePage( SfxItemSet
* _pSet
)
368 sal_uInt16
* SwFootNotePage::GetRanges()
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */