1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pgfnote.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
43 #include <hintids.hxx>
44 #include <tools/ref.hxx>
45 #ifndef _SVX_DIALOGS_HRC
46 #include <svx/dialogs.hrc>
48 #include <vcl/field.hxx>
49 #include <vcl/svapp.hxx>
50 #include <unotools/localedatawrapper.hxx>
51 #include <svtools/syslocale.hxx>
52 #include <svx/sizeitem.hxx>
53 #include <svx/pageitem.hxx>
54 #include <svtools/eitem.hxx>
55 #include <svx/ulspitem.hxx>
57 #include <pagedesc.hxx>
58 #include <pgfnote.hxx>
59 #include <uiitems.hxx>
62 #include <globals.hrc>
68 #include <pgfnote.hrc>
71 #define TWIP_TO_LBOX 5
72 /*-----------------------------------------------------#---------------
73 Beschreibung: vordefinierte Linien in Point
74 --------------------------------------------------------------------*/
76 static const USHORT __FAR_DATA nLines
[] = {
85 static const USHORT nLineCount
= sizeof(nLines
) / sizeof(nLines
[0]);
87 static USHORT __FAR_DATA aPageRg
[] = {
88 FN_PARAM_FTN_INFO
, FN_PARAM_FTN_INFO
,
93 /*------------------------------------------------------------------------
94 Beschreibung: liefert zurueck, ob die Linienbreite nWidth bereits
95 in der Listbox enthalten ist.
96 ------------------------------------------------------------------------*/
99 BOOL
lcl_HasLineWidth(USHORT nWidth
)
101 for(USHORT i
= 0; i
< nLineCount
; ++i
) {
102 if(nLines
[i
] == nWidth
)
108 /*------------------------------------------------------------------------
109 Beschreibung: Handler fuer umschalten zwischen den unterschiedlichen
110 Arten, wie die Hoehe des Fussnotenbereiches angegeben
112 ------------------------------------------------------------------------*/
115 IMPL_LINK_INLINE_START( SwFootNotePage
, HeightPage
, Button
*, EMPTYARG
)
117 aMaxHeightEdit
.Enable(FALSE
);
120 IMPL_LINK_INLINE_END( SwFootNotePage
, HeightPage
, Button
*, EMPTYARG
)
123 IMPL_LINK_INLINE_START( SwFootNotePage
, HeightMetric
, Button
*, EMPTYARG
)
125 aMaxHeightEdit
.Enable();
126 aMaxHeightEdit
.GrabFocus();
129 IMPL_LINK_INLINE_END( SwFootNotePage
, HeightMetric
, Button
*, EMPTYARG
)
131 /*------------------------------------------------------------------------
132 Beschreibung: Handler Grenzwerte
133 ------------------------------------------------------------------------*/
136 IMPL_LINK( SwFootNotePage
, HeightModify
, MetricField
*, EMPTYARG
)
138 aMaxHeightEdit
.SetMax(aMaxHeightEdit
.Normalize(lMaxHeight
-
139 (aDistEdit
.Denormalize(aDistEdit
.GetValue(FUNIT_TWIP
)) +
140 aLineDistEdit
.Denormalize(aLineDistEdit
.GetValue(FUNIT_TWIP
)))),
142 if(aMaxHeightEdit
.GetValue() < 0)
143 aMaxHeightEdit
.SetValue(0);
144 aDistEdit
.SetMax(aDistEdit
.Normalize(lMaxHeight
-
145 (aMaxHeightEdit
.Denormalize(aMaxHeightEdit
.GetValue(FUNIT_TWIP
)) +
146 aLineDistEdit
.Denormalize(aLineDistEdit
.GetValue(FUNIT_TWIP
)))),
148 if(aDistEdit
.GetValue() < 0)
149 aDistEdit
.SetValue(0);
150 aLineDistEdit
.SetMax(aLineDistEdit
.Normalize(lMaxHeight
-
151 (aMaxHeightEdit
.Denormalize(aMaxHeightEdit
.GetValue(FUNIT_TWIP
)) +
152 aDistEdit
.Denormalize(aDistEdit
.GetValue(FUNIT_TWIP
)))),
157 // CTOR / DTOR -----------------------------------------------------------
159 SwFootNotePage::SwFootNotePage(Window
*pParent
, const SfxItemSet
&rSet
) :
161 SfxTabPage(pParent
, SW_RES(TP_FOOTNOTE_PAGE
), rSet
),
163 aMaxHeightPageBtn(this, SW_RES(RB_MAXHEIGHT_PAGE
)),
164 aMaxHeightBtn(this, SW_RES(RB_MAXHEIGHT
)),
165 aMaxHeightEdit(this, SW_RES(ED_MAXHEIGHT
)),
166 aDistLbl(this, SW_RES(FT_DIST
)),
167 aDistEdit(this, SW_RES(ED_DIST
)),
168 aPosHeader(this, SW_RES(FL_FOOTNOTE_SIZE
)),
170 aLinePosLbl(this, SW_RES(FT_LINEPOS
)),
171 aLinePosBox(this, SW_RES(DLB_LINEPOS
)),
172 aLineTypeLbl(this, SW_RES(FT_LINETYPE
)),
173 aLineTypeBox(this, SW_RES(DLB_LINETYPE
)),
174 aLineWidthLbl(this, SW_RES(FT_LINEWIDTH
)),
175 aLineWidthEdit(this, SW_RES(ED_LINEWIDTH
)),
176 aLineDistLbl(this, SW_RES(FT_LINEDIST
)),
177 aLineDistEdit(this, SW_RES(ED_LINEDIST
)),
178 aLineHeader(this, SW_RES(FL_LINE
))
182 SetExchangeSupport();
183 FieldUnit aMetric
= ::GetDfltMetric(FALSE
);
184 SetMetric( aMaxHeightEdit
, aMetric
);
185 SetMetric( aDistEdit
, aMetric
);
186 SetMetric( aLineDistEdit
, aMetric
);
187 MeasurementSystem eSys
= SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
188 long nHeightValue
= MEASURE_METRIC
!= eSys
? 1440 : 1134;
189 aMaxHeightEdit
.SetValue(aMaxHeightEdit
.Normalize(nHeightValue
),FUNIT_TWIP
);;
192 SwFootNotePage::~SwFootNotePage()
197 SfxTabPage
* SwFootNotePage::Create(Window
*pParent
, const SfxItemSet
&rSet
)
199 return new SwFootNotePage(pParent
, rSet
);
203 /*--------------------------------------------------------------------
205 --------------------------------------------------------------------*/
208 void SwFootNotePage::Reset(const SfxItemSet
&rSet
)
210 // Falls noch kein Bsp vorhanden Init hier sonst im Activate
212 SwPageFtnInfo
* pDefFtnInfo
= 0;
213 const SwPageFtnInfo
* pFtnInfo
;
214 const SfxPoolItem
* pItem
= SfxTabPage::GetItem(rSet
, FN_PARAM_FTN_INFO
);
217 pFtnInfo
= &((const SwPageFtnInfoItem
*)pItem
)->GetPageFtnInfo();
221 // wenn "Standard" betaetigt wird, wird das Fussnotenitem geloescht,
222 // deswegen muss hier eine Fussnotenstruktur erzeugt werden
223 pDefFtnInfo
= new SwPageFtnInfo();
224 pFtnInfo
= pDefFtnInfo
;
226 // Hoehe Fussnotenbereich
227 SwTwips lHeight
= pFtnInfo
->GetHeight();
230 aMaxHeightEdit
.SetValue(aMaxHeightEdit
.Normalize(lHeight
),FUNIT_TWIP
);
231 aMaxHeightBtn
.Check(TRUE
);
235 aMaxHeightPageBtn
.Check(TRUE
);
236 aMaxHeightEdit
.Enable(FALSE
);
238 aMaxHeightPageBtn
.SetClickHdl(LINK(this,SwFootNotePage
,HeightPage
));
239 aMaxHeightBtn
.SetClickHdl(LINK(this,SwFootNotePage
,HeightMetric
));
240 Link aLk
= LINK(this, SwFootNotePage
, HeightModify
);
241 aMaxHeightEdit
.SetLoseFocusHdl( aLk
);
242 aDistEdit
.SetLoseFocusHdl( aLk
);
243 aLineDistEdit
.SetLoseFocusHdl( aLk
);
246 for(USHORT i
= 0; i
< nLineCount
; ++i
)
247 aLineTypeBox
.InsertEntry(nLines
[i
]);
249 const USHORT nWidth
= (USHORT
)pFtnInfo
->GetLineWidth() * TWIP_TO_LBOX
;
250 if ( !lcl_HasLineWidth(nWidth
) )
251 aLineTypeBox
.InsertEntry(nWidth
);
252 aLineTypeBox
.SelectEntry(nWidth
);
255 aLinePosBox
.SelectEntryPos( static_cast< USHORT
>(pFtnInfo
->GetAdj()) );
258 Fraction
aTmp( 100, 1 );
259 aTmp
*= pFtnInfo
->GetWidth();
260 aLineWidthEdit
.SetValue( static_cast<long>(aTmp
) );
262 // Abstand Fussnotenbereich
263 aDistEdit
.SetValue(aDistEdit
.Normalize(pFtnInfo
->GetTopDist()),FUNIT_TWIP
);
264 aLineDistEdit
.SetValue(
265 aLineDistEdit
.Normalize(pFtnInfo
->GetBottomDist()), FUNIT_TWIP
);
266 ActivatePage( rSet
);
270 /*--------------------------------------------------------------------
271 Beschreibung: Attribute in den Set stopfen bei OK
272 --------------------------------------------------------------------*/
275 BOOL
SwFootNotePage::FillItemSet(SfxItemSet
&rSet
)
277 SwPageFtnInfoItem
aItem((const SwPageFtnInfoItem
&)GetItemSet().Get(FN_PARAM_FTN_INFO
));
279 // Das ist das Original
280 SwPageFtnInfo
&rFtnInfo
= aItem
.GetPageFtnInfo();
282 // Hoehe Fussnotenbereich
283 if(aMaxHeightBtn
.IsChecked())
284 rFtnInfo
.SetHeight( static_cast< SwTwips
>(
285 aMaxHeightEdit
.Denormalize(aMaxHeightEdit
.GetValue(FUNIT_TWIP
))));
287 rFtnInfo
.SetHeight(0);
289 // Abstand Fussnotenbereich
290 rFtnInfo
.SetTopDist( static_cast< SwTwips
>(
291 aDistEdit
.Denormalize(aDistEdit
.GetValue(FUNIT_TWIP
))));
292 rFtnInfo
.SetBottomDist( static_cast< SwTwips
>(
293 aLineDistEdit
.Denormalize(aLineDistEdit
.GetValue(FUNIT_TWIP
))));
296 const USHORT nPos
= aLineTypeBox
.GetSelectEntryPos();
297 if( LISTBOX_ENTRY_NOTFOUND
!= nPos
)
298 rFtnInfo
.SetLineWidth(nLines
[nPos
] / TWIP_TO_LBOX
);
301 rFtnInfo
.SetAdj((SwFtnAdj
)aLinePosBox
.GetSelectEntryPos());
304 rFtnInfo
.SetWidth(Fraction( static_cast< long >(aLineWidthEdit
.GetValue()), 100));
306 const SfxPoolItem
* pOldItem
;
307 if(0 == (pOldItem
= GetOldItem( rSet
, FN_PARAM_FTN_INFO
)) ||
314 void SwFootNotePage::ActivatePage(const SfxItemSet
& rSet
)
316 const SvxSizeItem
& rSize
= (const SvxSizeItem
&)rSet
.Get( RES_FRM_SIZE
);
317 lMaxHeight
= rSize
.GetSize().Height();
319 const SfxPoolItem
* pItem
;
320 if( SFX_ITEM_SET
== rSet
.GetItemState( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET
), FALSE
, &pItem
) )
322 const SfxItemSet
& rHeaderSet
= ((SvxSetItem
*)pItem
)->GetItemSet();
323 const SfxBoolItem
& rHeaderOn
=
324 (const SfxBoolItem
&)rHeaderSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_ON
) );
326 if ( rHeaderOn
.GetValue() )
328 const SvxSizeItem
& rSizeItem
=
329 (const SvxSizeItem
&)rHeaderSet
.Get(rSet
.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE
));
330 lMaxHeight
-= rSizeItem
.GetSize().Height();
334 if( SFX_ITEM_SET
== rSet
.GetItemState( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET
),
337 const SfxItemSet
& rFooterSet
= ((SvxSetItem
*)pItem
)->GetItemSet();
338 const SfxBoolItem
& rFooterOn
=
339 (const SfxBoolItem
&)rFooterSet
.Get( SID_ATTR_PAGE_ON
);
341 if ( rFooterOn
.GetValue() )
343 const SvxSizeItem
& rSizeItem
=
344 (const SvxSizeItem
&)rFooterSet
.Get( rSet
.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE
) );
345 lMaxHeight
-= rSizeItem
.GetSize().Height();
349 if ( rSet
.GetItemState( RES_UL_SPACE
, FALSE
) == SFX_ITEM_SET
)
351 const SvxULSpaceItem
&rUL
= (const SvxULSpaceItem
&)rSet
.Get( RES_UL_SPACE
);
352 lMaxHeight
-= rUL
.GetUpper() + rUL
.GetLower();
358 // Maximalwerte setzen
362 int SwFootNotePage::DeactivatePage( SfxItemSet
* _pSet
)
370 USHORT
* SwFootNotePage::GetRanges()