Line data Source code
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 <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>
35 : #include <uitool.hxx>
36 : #include <pagedesc.hxx>
37 : #include <pgfnote.hxx>
38 : #include <uiitems.hxx>
39 : #include <sfx2/objsh.hxx>
40 :
41 : #include <globals.hrc>
42 : #include <misc.hrc>
43 :
44 :
45 : using namespace ::com::sun::star;
46 :
47 : static sal_uInt16 aPageRg[] = {
48 : FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO,
49 : 0
50 : };
51 :
52 : /*------------------------------------------------------------------------
53 : Description: handler to switch between the different possibilities
54 : how the footnote region's height can be set.
55 : ------------------------------------------------------------------------*/
56 0 : IMPL_LINK_NOARG_INLINE_START(SwFootNotePage, HeightPage)
57 : {
58 0 : m_pMaxHeightEdit->Enable(sal_False);
59 0 : return 0;
60 : }
61 0 : IMPL_LINK_NOARG_INLINE_END(SwFootNotePage, HeightPage)
62 :
63 :
64 0 : IMPL_LINK_NOARG_INLINE_START(SwFootNotePage, HeightMetric)
65 : {
66 0 : m_pMaxHeightEdit->Enable();
67 0 : m_pMaxHeightEdit->GrabFocus();
68 0 : return 0;
69 : }
70 0 : IMPL_LINK_NOARG_INLINE_END(SwFootNotePage, HeightMetric)
71 :
72 : /*------------------------------------------------------------------------
73 : Description: handler limit values
74 : ------------------------------------------------------------------------*/
75 0 : IMPL_LINK_NOARG(SwFootNotePage, HeightModify)
76 : {
77 : m_pMaxHeightEdit->SetMax(m_pMaxHeightEdit->Normalize(lMaxHeight -
78 0 : (m_pDistEdit->Denormalize(m_pDistEdit->GetValue(FUNIT_TWIP)) +
79 0 : m_pLineDistEdit->Denormalize(m_pLineDistEdit->GetValue(FUNIT_TWIP)))),
80 0 : FUNIT_TWIP);
81 0 : if(m_pMaxHeightEdit->GetValue() < 0)
82 0 : m_pMaxHeightEdit->SetValue(0);
83 : m_pDistEdit->SetMax(m_pDistEdit->Normalize(lMaxHeight -
84 0 : (m_pMaxHeightEdit->Denormalize(m_pMaxHeightEdit->GetValue(FUNIT_TWIP)) +
85 0 : m_pLineDistEdit->Denormalize(m_pLineDistEdit->GetValue(FUNIT_TWIP)))),
86 0 : FUNIT_TWIP);
87 0 : if(m_pDistEdit->GetValue() < 0)
88 0 : m_pDistEdit->SetValue(0);
89 : m_pLineDistEdit->SetMax(m_pLineDistEdit->Normalize(lMaxHeight -
90 0 : (m_pMaxHeightEdit->Denormalize(m_pMaxHeightEdit->GetValue(FUNIT_TWIP)) +
91 0 : m_pDistEdit->Denormalize(m_pDistEdit->GetValue(FUNIT_TWIP)))),
92 0 : FUNIT_TWIP);
93 0 : return 0;
94 : }
95 :
96 0 : IMPL_LINK_NOARG(SwFootNotePage, LineWidthChanged_Impl)
97 : {
98 : sal_Int64 nVal = static_cast<sal_Int64>(MetricField::ConvertDoubleValue(
99 0 : m_pLineWidthEdit->GetValue( ),
100 0 : m_pLineWidthEdit->GetDecimalDigits( ),
101 0 : m_pLineWidthEdit->GetUnit(), MAP_TWIP ));
102 0 : m_pLineTypeBox->SetWidth( nVal );
103 :
104 0 : return 0;
105 : }
106 :
107 0 : IMPL_LINK_NOARG(SwFootNotePage, LineColorSelected_Impl)
108 : {
109 0 : m_pLineTypeBox->SetColor( m_pLineColorBox->GetSelectEntryColor() );
110 0 : return 0;
111 : }
112 :
113 0 : SwFootNotePage::SwFootNotePage(Window *pParent, const SfxItemSet &rSet)
114 : : SfxTabPage(pParent, "FootnoteAreaPage",
115 0 : "modules/swriter/ui/footnoteareapage.ui", rSet)
116 : {
117 0 : get(m_pMaxHeightPageBtn, "maxheightpage");
118 0 : get(m_pMaxHeightBtn, "maxheight");
119 0 : get(m_pMaxHeightEdit, "maxheightsb");
120 0 : get(m_pDistEdit, "spacetotext");
121 :
122 0 : get(m_pLinePosBox, "position");
123 0 : get(m_pLineTypeBox, "style");
124 0 : get(m_pLineWidthEdit, "thickness");
125 0 : get(m_pLineColorBox, "color");
126 0 : get(m_pLineLengthEdit, "length");
127 0 : get(m_pLineDistEdit, "spacingtocontents");
128 :
129 0 : SetExchangeSupport();
130 0 : FieldUnit aMetric = ::GetDfltMetric(sal_False);
131 0 : SetMetric(*m_pMaxHeightEdit, aMetric);
132 0 : SetMetric(*m_pDistEdit, aMetric);
133 0 : SetMetric(*m_pLineDistEdit, aMetric);
134 0 : MeasurementSystem eSys = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
135 0 : long nHeightValue = MEASURE_METRIC != eSys ? 1440 : 1134;
136 0 : m_pMaxHeightEdit->SetValue(m_pMaxHeightEdit->Normalize(nHeightValue),FUNIT_TWIP);
137 0 : }
138 :
139 0 : SwFootNotePage::~SwFootNotePage()
140 : {
141 0 : }
142 :
143 0 : SfxTabPage* SwFootNotePage::Create(Window *pParent, const SfxItemSet &rSet)
144 : {
145 0 : return new SwFootNotePage(pParent, rSet);
146 : }
147 :
148 0 : void SwFootNotePage::Reset(const SfxItemSet &rSet)
149 : {
150 : // if no example exists, otherwise Init here in Activate
151 0 : SwPageFtnInfo* pDefFtnInfo = 0;
152 : const SwPageFtnInfo* pFtnInfo;
153 0 : const SfxPoolItem* pItem = SfxTabPage::GetItem(rSet, FN_PARAM_FTN_INFO);
154 0 : if( pItem )
155 : {
156 0 : pFtnInfo = &((const SwPageFtnInfoItem*)pItem)->GetPageFtnInfo();
157 : }
158 : else
159 : {
160 : // when "standard" is being activated the footnote item is deleted,
161 : // that's why a footnote structure has to be created here
162 0 : pDefFtnInfo = new SwPageFtnInfo();
163 0 : pFtnInfo = pDefFtnInfo;
164 : }
165 : // footnote area's height
166 0 : SwTwips lHeight = pFtnInfo->GetHeight();
167 0 : if(lHeight)
168 : {
169 0 : m_pMaxHeightEdit->SetValue(m_pMaxHeightEdit->Normalize(lHeight),FUNIT_TWIP);
170 0 : m_pMaxHeightBtn->Check(sal_True);
171 : }
172 : else
173 : {
174 0 : m_pMaxHeightPageBtn->Check(sal_True);
175 0 : m_pMaxHeightEdit->Enable(sal_False);
176 : }
177 0 : m_pMaxHeightPageBtn->SetClickHdl(LINK(this,SwFootNotePage,HeightPage));
178 0 : m_pMaxHeightBtn->SetClickHdl(LINK(this,SwFootNotePage,HeightMetric));
179 0 : Link aLk = LINK(this, SwFootNotePage, HeightModify);
180 0 : m_pMaxHeightEdit->SetLoseFocusHdl( aLk );
181 0 : m_pDistEdit->SetLoseFocusHdl( aLk );
182 0 : m_pLineDistEdit->SetLoseFocusHdl( aLk );
183 :
184 : // Separator width
185 0 : m_pLineWidthEdit->SetModifyHdl( LINK( this, SwFootNotePage, LineWidthChanged_Impl ) );
186 :
187 : sal_Int64 nWidthPt = static_cast<sal_Int64>(MetricField::ConvertDoubleValue(
188 0 : sal_Int64( pFtnInfo->GetLineWidth() ), m_pLineWidthEdit->GetDecimalDigits(),
189 0 : MAP_TWIP, m_pLineWidthEdit->GetUnit( ) ));
190 0 : m_pLineWidthEdit->SetValue( nWidthPt );
191 :
192 : // Separator style
193 0 : m_pLineTypeBox->SetSourceUnit( FUNIT_TWIP );
194 :
195 0 : m_pLineTypeBox->SetNone(SW_RESSTR(SW_STR_NONE));
196 : m_pLineTypeBox->InsertEntry(
197 : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::SOLID),
198 0 : table::BorderLineStyle::SOLID );
199 : m_pLineTypeBox->InsertEntry(
200 : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DOTTED),
201 0 : table::BorderLineStyle::DOTTED );
202 : m_pLineTypeBox->InsertEntry(
203 : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DASHED),
204 0 : table::BorderLineStyle::DASHED );
205 0 : m_pLineTypeBox->SetWidth( pFtnInfo->GetLineWidth( ) );
206 0 : m_pLineTypeBox->SelectEntry( pFtnInfo->GetLineStyle() );
207 :
208 : // Separator Color
209 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
210 0 : XColorListRef pColorList;
211 :
212 : OSL_ENSURE( pDocSh, "DocShell not found!" );
213 :
214 0 : if ( pDocSh )
215 : {
216 0 : const SfxPoolItem* pColorItem = pDocSh->GetItem( SID_COLOR_TABLE );
217 0 : if ( pColorItem != NULL )
218 0 : pColorList = ( (SvxColorListItem*)pColorItem )->GetColorList();
219 : }
220 :
221 : OSL_ENSURE( pColorList.is(), "ColorTable not found!" );
222 :
223 0 : if ( pColorList.is() )
224 : {
225 0 : m_pLineColorBox->SetUpdateMode( sal_False );
226 :
227 0 : for ( long i = 0; i < pColorList->Count(); ++i )
228 : {
229 0 : XColorEntry* pEntry = pColorList->GetColor(i);
230 0 : m_pLineColorBox->InsertEntry( pEntry->GetColor(), pEntry->GetName() );
231 : }
232 0 : m_pLineColorBox->SetUpdateMode( sal_True );
233 : }
234 :
235 : // select color in the list or add it as a user color
236 0 : sal_uInt16 nSelPos = m_pLineColorBox->GetEntryPos( pFtnInfo->GetLineColor() );
237 0 : if( nSelPos == LISTBOX_ENTRY_NOTFOUND )
238 0 : nSelPos = m_pLineColorBox->InsertEntry( pFtnInfo->GetLineColor(),
239 0 : String( SW_RES( RID_SVXSTR_COLOR_USER ) ) );
240 :
241 0 : m_pLineColorBox->SetSelectHdl( LINK( this, SwFootNotePage, LineColorSelected_Impl ) );
242 0 : m_pLineColorBox->SelectEntryPos( nSelPos );
243 0 : m_pLineTypeBox->SetColor( pFtnInfo->GetLineColor() );
244 :
245 :
246 : // position
247 0 : m_pLinePosBox->SelectEntryPos( static_cast< sal_uInt16 >(pFtnInfo->GetAdj()) );
248 :
249 : // width
250 0 : Fraction aTmp( 100, 1 );
251 0 : aTmp *= pFtnInfo->GetWidth();
252 0 : m_pLineLengthEdit->SetValue( static_cast<long>(aTmp) );
253 :
254 : // gap footnote area
255 0 : m_pDistEdit->SetValue(m_pDistEdit->Normalize(pFtnInfo->GetTopDist()),FUNIT_TWIP);
256 : m_pLineDistEdit->SetValue(
257 0 : m_pLineDistEdit->Normalize(pFtnInfo->GetBottomDist()), FUNIT_TWIP);
258 0 : ActivatePage( rSet );
259 0 : delete pDefFtnInfo;
260 0 : }
261 :
262 : /*--------------------------------------------------------------------
263 : Description: stuff attributes into the set, when OK
264 : --------------------------------------------------------------------*/
265 0 : sal_Bool SwFootNotePage::FillItemSet(SfxItemSet &rSet)
266 : {
267 0 : SwPageFtnInfoItem aItem((const SwPageFtnInfoItem&)GetItemSet().Get(FN_PARAM_FTN_INFO));
268 :
269 : // that's the original
270 0 : SwPageFtnInfo &rFtnInfo = aItem.GetPageFtnInfo();
271 :
272 : // footnote area's height
273 0 : if(m_pMaxHeightBtn->IsChecked())
274 : rFtnInfo.SetHeight( static_cast< SwTwips >(
275 0 : m_pMaxHeightEdit->Denormalize(m_pMaxHeightEdit->GetValue(FUNIT_TWIP))));
276 : else
277 0 : rFtnInfo.SetHeight(0);
278 :
279 : // gap footnote area
280 : rFtnInfo.SetTopDist( static_cast< SwTwips >(
281 0 : m_pDistEdit->Denormalize(m_pDistEdit->GetValue(FUNIT_TWIP))));
282 : rFtnInfo.SetBottomDist( static_cast< SwTwips >(
283 0 : m_pLineDistEdit->Denormalize(m_pLineDistEdit->GetValue(FUNIT_TWIP))));
284 :
285 : // Separator style
286 0 : rFtnInfo.SetLineStyle( ::editeng::SvxBorderStyle( m_pLineTypeBox->GetSelectEntryStyle() ) );
287 :
288 : // Separator width
289 : long nWidth = static_cast<long>(MetricField::ConvertDoubleValue(
290 0 : m_pLineWidthEdit->GetValue( ),
291 0 : m_pLineWidthEdit->GetDecimalDigits( ),
292 0 : m_pLineWidthEdit->GetUnit(), MAP_TWIP ));
293 0 : rFtnInfo.SetLineWidth( nWidth );
294 :
295 : // Separator color
296 0 : rFtnInfo.SetLineColor( m_pLineColorBox->GetSelectEntryColor() );
297 :
298 : // Position
299 0 : rFtnInfo.SetAdj((SwFtnAdj)m_pLinePosBox->GetSelectEntryPos());
300 :
301 : // Breite
302 0 : rFtnInfo.SetWidth(Fraction( static_cast< long >(m_pLineLengthEdit->GetValue()), 100));
303 :
304 : const SfxPoolItem* pOldItem;
305 0 : if(0 == (pOldItem = GetOldItem( rSet, FN_PARAM_FTN_INFO )) ||
306 0 : aItem != *pOldItem )
307 0 : rSet.Put(aItem);
308 :
309 0 : return sal_True;
310 : }
311 :
312 0 : void SwFootNotePage::ActivatePage(const SfxItemSet& rSet)
313 : {
314 0 : const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get( RES_FRM_SIZE );
315 0 : lMaxHeight = rSize.GetSize().Height();
316 :
317 : const SfxPoolItem* pItem;
318 0 : if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET), sal_False, &pItem ) )
319 : {
320 0 : const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
321 : const SfxBoolItem& rHeaderOn =
322 0 : (const SfxBoolItem&)rHeaderSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_ON ) );
323 :
324 0 : if ( rHeaderOn.GetValue() )
325 : {
326 : const SvxSizeItem& rSizeItem =
327 0 : (const SvxSizeItem&)rHeaderSet.Get(rSet.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE));
328 0 : lMaxHeight -= rSizeItem.GetSize().Height();
329 : }
330 : }
331 :
332 0 : if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET),
333 0 : sal_False, &pItem ) )
334 : {
335 0 : const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
336 : const SfxBoolItem& rFooterOn =
337 0 : (const SfxBoolItem&)rFooterSet.Get( SID_ATTR_PAGE_ON );
338 :
339 0 : if ( rFooterOn.GetValue() )
340 : {
341 : const SvxSizeItem& rSizeItem =
342 0 : (const SvxSizeItem&)rFooterSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE ) );
343 0 : lMaxHeight -= rSizeItem.GetSize().Height();
344 : }
345 : }
346 :
347 0 : if ( rSet.GetItemState( RES_UL_SPACE , sal_False ) == SFX_ITEM_SET )
348 : {
349 0 : const SvxULSpaceItem &rUL = (const SvxULSpaceItem&)rSet.Get( RES_UL_SPACE );
350 0 : lMaxHeight -= rUL.GetUpper() + rUL.GetLower();
351 : }
352 :
353 0 : lMaxHeight *= 8;
354 0 : lMaxHeight /= 10;
355 :
356 : // set maximum values
357 0 : HeightModify(0);
358 0 : }
359 :
360 0 : int SwFootNotePage::DeactivatePage( SfxItemSet* _pSet)
361 : {
362 0 : if(_pSet)
363 0 : FillItemSet(*_pSet);
364 :
365 0 : return sal_True;
366 : }
367 :
368 0 : sal_uInt16* SwFootNotePage::GetRanges()
369 : {
370 0 : return aPageRg;
371 0 : }
372 :
373 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|