Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <cmdid.h>
30 : : #include <hintids.hxx>
31 : : #include <svx/dialogs.hrc>
32 : : #include <svx/drawitem.hxx>
33 : : #include <svx/xtable.hxx> // XColorList
34 : : #include <sal/macros.h>
35 : : #include <vcl/field.hxx>
36 : : #include <vcl/svapp.hxx>
37 : : #include <unotools/localedatawrapper.hxx>
38 : : #include <unotools/syslocale.hxx>
39 : : #include <editeng/borderline.hxx>
40 : : #include <editeng/sizeitem.hxx>
41 : : #include <svx/pageitem.hxx>
42 : : #include <svl/eitem.hxx>
43 : : #include <editeng/ulspitem.hxx>
44 : : #include <uitool.hxx>
45 : : #include <pagedesc.hxx>
46 : : #include <pgfnote.hxx>
47 : : #include <uiitems.hxx>
48 : : #include <sfx2/objsh.hxx>
49 : :
50 : : #include <globals.hrc>
51 : : #include <misc.hrc>
52 : : #include <pgfnote.hrc>
53 : :
54 : :
55 : : using namespace ::com::sun::star;
56 : :
57 : : static sal_uInt16 aPageRg[] = {
58 : : FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO,
59 : : 0
60 : : };
61 : :
62 : : /*------------------------------------------------------------------------
63 : : Description: handler to switch between the different possibilities
64 : : how the footnote region's height can be set.
65 : : ------------------------------------------------------------------------*/
66 : 0 : IMPL_LINK_NOARG_INLINE_START(SwFootNotePage, HeightPage)
67 : : {
68 : 0 : aMaxHeightEdit.Enable(sal_False);
69 : 0 : return 0;
70 : : }
71 : 0 : IMPL_LINK_NOARG_INLINE_END(SwFootNotePage, HeightPage)
72 : :
73 : :
74 : 0 : IMPL_LINK_NOARG_INLINE_START(SwFootNotePage, HeightMetric)
75 : : {
76 : 0 : aMaxHeightEdit.Enable();
77 : 0 : aMaxHeightEdit.GrabFocus();
78 : 0 : return 0;
79 : : }
80 : 0 : IMPL_LINK_NOARG_INLINE_END(SwFootNotePage, HeightMetric)
81 : :
82 : : /*------------------------------------------------------------------------
83 : : Description: handler limit values
84 : : ------------------------------------------------------------------------*/
85 : 0 : IMPL_LINK_NOARG(SwFootNotePage, HeightModify)
86 : : {
87 : : aMaxHeightEdit.SetMax(aMaxHeightEdit.Normalize(lMaxHeight -
88 : 0 : (aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP)) +
89 : 0 : aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP)))),
90 : 0 : FUNIT_TWIP);
91 : 0 : if(aMaxHeightEdit.GetValue() < 0)
92 : 0 : aMaxHeightEdit.SetValue(0);
93 : : aDistEdit.SetMax(aDistEdit.Normalize(lMaxHeight -
94 : 0 : (aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP)) +
95 : 0 : aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP)))),
96 : 0 : FUNIT_TWIP);
97 : 0 : if(aDistEdit.GetValue() < 0)
98 : 0 : aDistEdit.SetValue(0);
99 : : aLineDistEdit.SetMax(aLineDistEdit.Normalize(lMaxHeight -
100 : 0 : (aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP)) +
101 : 0 : aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP)))),
102 : 0 : FUNIT_TWIP);
103 : 0 : return 0;
104 : : }
105 : :
106 : 0 : IMPL_LINK_NOARG(SwFootNotePage, LineWidthChanged_Impl)
107 : : {
108 : : sal_Int64 nVal = static_cast<sal_Int64>(MetricField::ConvertDoubleValue(
109 : : aLineWidthEdit.GetValue( ),
110 : 0 : aLineWidthEdit.GetDecimalDigits( ),
111 : 0 : aLineWidthEdit.GetUnit(), MAP_TWIP ));
112 : 0 : aLineTypeBox.SetWidth( nVal );
113 : :
114 : 0 : return 0;
115 : : }
116 : :
117 : 0 : IMPL_LINK_NOARG(SwFootNotePage, LineColorSelected_Impl)
118 : : {
119 : 0 : aLineTypeBox.SetColor( aLineColorBox.GetSelectEntryColor() );
120 : 0 : return 0;
121 : : }
122 : :
123 : : // CTOR / DTOR -----------------------------------------------------------
124 : :
125 : 0 : SwFootNotePage::SwFootNotePage(Window *pParent, const SfxItemSet &rSet) :
126 : :
127 : : SfxTabPage(pParent, SW_RES(TP_FOOTNOTE_PAGE), rSet),
128 : : aPosHeader(this, SW_RES(FL_FOOTNOTE_SIZE)),
129 : : aMaxHeightPageBtn(this, SW_RES(RB_MAXHEIGHT_PAGE)),
130 : : aMaxHeightBtn(this, SW_RES(RB_MAXHEIGHT)),
131 : : aMaxHeightEdit(this, SW_RES(ED_MAXHEIGHT)),
132 : : aDistLbl(this, SW_RES(FT_DIST)),
133 : : aDistEdit(this, SW_RES(ED_DIST)),
134 : :
135 : : aLineHeader(this, SW_RES(FL_LINE)),
136 : : aLinePosLbl(this, SW_RES(FT_LINEPOS)),
137 : : aLinePosBox(this, SW_RES(DLB_LINEPOS)),
138 : : aLineTypeLbl(this, SW_RES(FT_LINETYPE)),
139 : : aLineTypeBox(this, SW_RES(DLB_LINETYPE)),
140 : : aLineWidthLbl(this, SW_RES(FT_LINEWIDTH)),
141 : : aLineWidthEdit(this, SW_RES(ED_LINEWIDTH)),
142 : : aLineColorLbl(this, SW_RES(FT_LINECOLOR)),
143 : : aLineColorBox(this, SW_RES(DLB_LINECOLOR)),
144 : : aLineLengthLbl(this, SW_RES(FT_LINELENGTH)),
145 : : aLineLengthEdit(this, SW_RES(ED_LINELENGTH)),
146 : : aLineDistLbl(this, SW_RES(FT_LINEDIST)),
147 : 0 : aLineDistEdit(this, SW_RES(ED_LINEDIST))
148 : : {
149 : 0 : FreeResource();
150 : :
151 : 0 : SetExchangeSupport();
152 : 0 : FieldUnit aMetric = ::GetDfltMetric(sal_False);
153 : 0 : SetMetric( aMaxHeightEdit, aMetric );
154 : 0 : SetMetric( aDistEdit, aMetric );
155 : 0 : SetMetric( aLineDistEdit, aMetric );
156 : 0 : MeasurementSystem eSys = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
157 : 0 : long nHeightValue = MEASURE_METRIC != eSys ? 1440 : 1134;
158 : 0 : aMaxHeightEdit.SetValue(aMaxHeightEdit.Normalize(nHeightValue),FUNIT_TWIP);
159 : 0 : aMaxHeightEdit.SetAccessibleRelationLabeledBy(&aMaxHeightBtn);
160 : 0 : }
161 : :
162 : 0 : SwFootNotePage::~SwFootNotePage()
163 : : {
164 : 0 : }
165 : :
166 : 0 : SfxTabPage* SwFootNotePage::Create(Window *pParent, const SfxItemSet &rSet)
167 : : {
168 : 0 : return new SwFootNotePage(pParent, rSet);
169 : : }
170 : :
171 : 0 : void SwFootNotePage::Reset(const SfxItemSet &rSet)
172 : : {
173 : : // if no example exists, otherwise Init here in Activate
174 : 0 : SwPageFtnInfo* pDefFtnInfo = 0;
175 : : const SwPageFtnInfo* pFtnInfo;
176 : 0 : const SfxPoolItem* pItem = SfxTabPage::GetItem(rSet, FN_PARAM_FTN_INFO);
177 : 0 : if( pItem )
178 : : {
179 : 0 : pFtnInfo = &((const SwPageFtnInfoItem*)pItem)->GetPageFtnInfo();
180 : : }
181 : : else
182 : : {
183 : : // when "standard" is being activated the footnote item is deleted,
184 : : // that's why a footnote structure has to be created here
185 : 0 : pDefFtnInfo = new SwPageFtnInfo();
186 : 0 : pFtnInfo = pDefFtnInfo;
187 : : }
188 : : // footnote area's height
189 : 0 : SwTwips lHeight = pFtnInfo->GetHeight();
190 : 0 : if(lHeight)
191 : : {
192 : 0 : aMaxHeightEdit.SetValue(aMaxHeightEdit.Normalize(lHeight),FUNIT_TWIP);
193 : 0 : aMaxHeightBtn.Check(sal_True);
194 : : }
195 : : else
196 : : {
197 : 0 : aMaxHeightPageBtn.Check(sal_True);
198 : 0 : aMaxHeightEdit.Enable(sal_False);
199 : : }
200 : 0 : aMaxHeightPageBtn.SetClickHdl(LINK(this,SwFootNotePage,HeightPage));
201 : 0 : aMaxHeightBtn.SetClickHdl(LINK(this,SwFootNotePage,HeightMetric));
202 : 0 : Link aLk = LINK(this, SwFootNotePage, HeightModify);
203 : 0 : aMaxHeightEdit.SetLoseFocusHdl( aLk );
204 : 0 : aDistEdit.SetLoseFocusHdl( aLk );
205 : 0 : aLineDistEdit.SetLoseFocusHdl( aLk );
206 : :
207 : : // Separator width
208 : 0 : aLineWidthEdit.SetModifyHdl( LINK( this, SwFootNotePage, LineWidthChanged_Impl ) );
209 : :
210 : : sal_Int64 nWidthPt = static_cast<sal_Int64>(MetricField::ConvertDoubleValue(
211 : 0 : sal_Int64( pFtnInfo->GetLineWidth() ), aLineWidthEdit.GetDecimalDigits(),
212 : 0 : MAP_TWIP, aLineWidthEdit.GetUnit( ) ));
213 : 0 : aLineWidthEdit.SetValue( nWidthPt );
214 : :
215 : : // Separator style
216 : 0 : aLineTypeBox.SetSourceUnit( FUNIT_TWIP );
217 : :
218 : 0 : aLineTypeBox.SetNone( String( SW_RES( STR_NONE ) ) );
219 : : aLineTypeBox.InsertEntry(
220 : : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::SOLID),
221 : 0 : table::BorderLineStyle::SOLID );
222 : : aLineTypeBox.InsertEntry(
223 : : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DOTTED),
224 : 0 : table::BorderLineStyle::DOTTED );
225 : : aLineTypeBox.InsertEntry(
226 : : ::editeng::SvxBorderLine::getWidthImpl(table::BorderLineStyle::DASHED),
227 : 0 : table::BorderLineStyle::DASHED );
228 : 0 : aLineTypeBox.SetWidth( pFtnInfo->GetLineWidth( ) );
229 : 0 : aLineTypeBox.SelectEntry( pFtnInfo->GetLineStyle() );
230 : :
231 : : // Separator Color
232 : 0 : SfxObjectShell* pDocSh = SfxObjectShell::Current();
233 : 0 : const SfxPoolItem* pColorItem = NULL;
234 : 0 : XColorListRef pColorList;
235 : :
236 : : OSL_ENSURE( pDocSh, "DocShell not found!" );
237 : :
238 : 0 : if ( pDocSh )
239 : : {
240 : 0 : pColorItem = pDocSh->GetItem( SID_COLOR_TABLE );
241 : 0 : if ( pColorItem != NULL )
242 : 0 : pColorList = ( (SvxColorListItem*)pColorItem )->GetColorList();
243 : : }
244 : :
245 : : OSL_ENSURE( pColorList.is(), "ColorTable not found!" );
246 : :
247 : 0 : if ( pColorList.is() )
248 : : {
249 : 0 : aLineColorBox.SetUpdateMode( sal_False );
250 : :
251 : 0 : for ( long i = 0; i < pColorList->Count(); ++i )
252 : : {
253 : 0 : XColorEntry* pEntry = pColorList->GetColor(i);
254 : 0 : aLineColorBox.InsertEntry( pEntry->GetColor(), pEntry->GetName() );
255 : : }
256 : 0 : aLineColorBox.SetUpdateMode( sal_True );
257 : : }
258 : :
259 : : // select color in the list or add it as a user color
260 : 0 : sal_uInt16 nSelPos = aLineColorBox.GetEntryPos( pFtnInfo->GetLineColor() );
261 : 0 : if( nSelPos == LISTBOX_ENTRY_NOTFOUND )
262 : 0 : nSelPos = aLineColorBox.InsertEntry( pFtnInfo->GetLineColor(),
263 : 0 : String( SW_RES( RID_SVXSTR_COLOR_USER ) ) );
264 : :
265 : 0 : aLineColorBox.SetSelectHdl( LINK( this, SwFootNotePage, LineColorSelected_Impl ) );
266 : 0 : aLineColorBox.SelectEntryPos( nSelPos );
267 : 0 : aLineTypeBox.SetColor( pFtnInfo->GetLineColor() );
268 : :
269 : :
270 : : // position
271 : 0 : aLinePosBox.SelectEntryPos( static_cast< sal_uInt16 >(pFtnInfo->GetAdj()) );
272 : :
273 : : // width
274 : 0 : Fraction aTmp( 100, 1 );
275 : 0 : aTmp *= pFtnInfo->GetWidth();
276 : 0 : aLineLengthEdit.SetValue( static_cast<long>(aTmp) );
277 : :
278 : : // gap footnote area
279 : 0 : aDistEdit.SetValue(aDistEdit.Normalize(pFtnInfo->GetTopDist()),FUNIT_TWIP);
280 : : aLineDistEdit.SetValue(
281 : 0 : aLineDistEdit.Normalize(pFtnInfo->GetBottomDist()), FUNIT_TWIP);
282 : 0 : ActivatePage( rSet );
283 : 0 : delete pDefFtnInfo;
284 : 0 : }
285 : :
286 : : /*--------------------------------------------------------------------
287 : : Description: stuff attributes into the set, when OK
288 : : --------------------------------------------------------------------*/
289 : 0 : sal_Bool SwFootNotePage::FillItemSet(SfxItemSet &rSet)
290 : : {
291 : 0 : SwPageFtnInfoItem aItem((const SwPageFtnInfoItem&)GetItemSet().Get(FN_PARAM_FTN_INFO));
292 : :
293 : : // that's the original
294 : 0 : SwPageFtnInfo &rFtnInfo = aItem.GetPageFtnInfo();
295 : :
296 : : // footnote area's height
297 : 0 : if(aMaxHeightBtn.IsChecked())
298 : : rFtnInfo.SetHeight( static_cast< SwTwips >(
299 : 0 : aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP))));
300 : : else
301 : 0 : rFtnInfo.SetHeight(0);
302 : :
303 : : // gap footnote area
304 : : rFtnInfo.SetTopDist( static_cast< SwTwips >(
305 : 0 : aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP))));
306 : : rFtnInfo.SetBottomDist( static_cast< SwTwips >(
307 : 0 : aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP))));
308 : :
309 : : // Separator style
310 : 0 : rFtnInfo.SetLineStyle( ::editeng::SvxBorderStyle( aLineTypeBox.GetSelectEntryStyle() ) );
311 : :
312 : : // Separator width
313 : : long nWidth = static_cast<long>(MetricField::ConvertDoubleValue(
314 : : aLineWidthEdit.GetValue( ),
315 : 0 : aLineWidthEdit.GetDecimalDigits( ),
316 : 0 : aLineWidthEdit.GetUnit(), MAP_TWIP ));
317 : 0 : rFtnInfo.SetLineWidth( nWidth );
318 : :
319 : : // Separator color
320 : 0 : rFtnInfo.SetLineColor( aLineColorBox.GetSelectEntryColor() );
321 : :
322 : : // Position
323 : 0 : rFtnInfo.SetAdj((SwFtnAdj)aLinePosBox.GetSelectEntryPos());
324 : :
325 : : // Breite
326 : 0 : rFtnInfo.SetWidth(Fraction( static_cast< long >(aLineLengthEdit.GetValue()), 100));
327 : :
328 : : const SfxPoolItem* pOldItem;
329 : 0 : if(0 == (pOldItem = GetOldItem( rSet, FN_PARAM_FTN_INFO )) ||
330 : 0 : aItem != *pOldItem )
331 : 0 : rSet.Put(aItem);
332 : :
333 : 0 : return sal_True;
334 : : }
335 : :
336 : 0 : void SwFootNotePage::ActivatePage(const SfxItemSet& rSet)
337 : : {
338 : 0 : const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get( RES_FRM_SIZE );
339 : 0 : lMaxHeight = rSize.GetSize().Height();
340 : :
341 : : const SfxPoolItem* pItem;
342 : 0 : if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET), sal_False, &pItem ) )
343 : : {
344 : 0 : const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
345 : : const SfxBoolItem& rHeaderOn =
346 : 0 : (const SfxBoolItem&)rHeaderSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_ON ) );
347 : :
348 : 0 : if ( rHeaderOn.GetValue() )
349 : : {
350 : : const SvxSizeItem& rSizeItem =
351 : 0 : (const SvxSizeItem&)rHeaderSet.Get(rSet.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE));
352 : 0 : lMaxHeight -= rSizeItem.GetSize().Height();
353 : : }
354 : : }
355 : :
356 : 0 : if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET),
357 : 0 : sal_False, &pItem ) )
358 : : {
359 : 0 : const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
360 : : const SfxBoolItem& rFooterOn =
361 : 0 : (const SfxBoolItem&)rFooterSet.Get( SID_ATTR_PAGE_ON );
362 : :
363 : 0 : if ( rFooterOn.GetValue() )
364 : : {
365 : : const SvxSizeItem& rSizeItem =
366 : 0 : (const SvxSizeItem&)rFooterSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE ) );
367 : 0 : lMaxHeight -= rSizeItem.GetSize().Height();
368 : : }
369 : : }
370 : :
371 : 0 : if ( rSet.GetItemState( RES_UL_SPACE , sal_False ) == SFX_ITEM_SET )
372 : : {
373 : 0 : const SvxULSpaceItem &rUL = (const SvxULSpaceItem&)rSet.Get( RES_UL_SPACE );
374 : 0 : lMaxHeight -= rUL.GetUpper() + rUL.GetLower();
375 : : }
376 : :
377 : 0 : lMaxHeight *= 8;
378 : 0 : lMaxHeight /= 10;
379 : :
380 : : // set maximum values
381 : 0 : HeightModify(0);
382 : 0 : }
383 : :
384 : 0 : int SwFootNotePage::DeactivatePage( SfxItemSet* _pSet)
385 : : {
386 : 0 : if(_pSet)
387 : 0 : FillItemSet(*_pSet);
388 : :
389 : 0 : return sal_True;
390 : : }
391 : :
392 : 0 : sal_uInt16* SwFootNotePage::GetRanges()
393 : : {
394 : 0 : return aPageRg;
395 : : }
396 : :
397 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|