merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / misc / pgfnote.cxx
blobd684116f4e1964b2d3c3f8dae9c95034de71d61a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pgfnote.cxx,v $
10 * $Revision: 1.12 $
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
36 #endif
40 #ifndef _CMDID_H
41 #include <cmdid.h>
42 #endif
43 #include <hintids.hxx>
44 #include <tools/ref.hxx>
45 #ifndef _SVX_DIALOGS_HRC
46 #include <svx/dialogs.hrc>
47 #endif
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>
56 #include <uitool.hxx>
57 #include <pagedesc.hxx>
58 #include <pgfnote.hxx>
59 #include <uiitems.hxx>
61 #ifndef _GLOBALS_HRC
62 #include <globals.hrc>
63 #endif
64 #ifndef _MISC_HRC
65 #include <misc.hrc>
66 #endif
67 #ifndef _PGFNOTE_HRC
68 #include <pgfnote.hrc>
69 #endif
71 #define TWIP_TO_LBOX 5
72 /*-----------------------------------------------------#---------------
73 Beschreibung: vordefinierte Linien in Point
74 --------------------------------------------------------------------*/
76 static const USHORT __FAR_DATA nLines[] = {
78 50,
79 100,
80 150,
81 200,
82 500
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)
103 return TRUE;
105 return FALSE;
108 /*------------------------------------------------------------------------
109 Beschreibung: Handler fuer umschalten zwischen den unterschiedlichen
110 Arten, wie die Hoehe des Fussnotenbereiches angegeben
111 werden kann.
112 ------------------------------------------------------------------------*/
115 IMPL_LINK_INLINE_START( SwFootNotePage, HeightPage, Button *, EMPTYARG )
117 aMaxHeightEdit.Enable(FALSE);
118 return 0;
120 IMPL_LINK_INLINE_END( SwFootNotePage, HeightPage, Button *, EMPTYARG )
123 IMPL_LINK_INLINE_START( SwFootNotePage, HeightMetric, Button *, EMPTYARG )
125 aMaxHeightEdit.Enable();
126 aMaxHeightEdit.GrabFocus();
127 return 0;
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)))),
141 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)))),
147 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)))),
153 FUNIT_TWIP);
154 return 0;
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))
180 FreeResource();
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 /*--------------------------------------------------------------------
204 Beschreibung:
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);
215 if( pItem )
217 pFtnInfo = &((const SwPageFtnInfoItem*)pItem)->GetPageFtnInfo();
219 else
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();
228 if(lHeight)
230 aMaxHeightEdit.SetValue(aMaxHeightEdit.Normalize(lHeight),FUNIT_TWIP);
231 aMaxHeightBtn.Check(TRUE);
233 else
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 );
245 // Trennlinie
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);
254 // Position
255 aLinePosBox.SelectEntryPos( static_cast< USHORT >(pFtnInfo->GetAdj()) );
257 // Breite
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 );
267 delete pDefFtnInfo;
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))));
286 else
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))));
295 // Trennlinie
296 const USHORT nPos = aLineTypeBox.GetSelectEntryPos();
297 if( LISTBOX_ENTRY_NOTFOUND != nPos )
298 rFtnInfo.SetLineWidth(nLines[nPos] / TWIP_TO_LBOX);
300 // Position
301 rFtnInfo.SetAdj((SwFtnAdj)aLinePosBox.GetSelectEntryPos());
303 // Breite
304 rFtnInfo.SetWidth(Fraction( static_cast< long >(aLineWidthEdit.GetValue()), 100));
306 const SfxPoolItem* pOldItem;
307 if(0 == (pOldItem = GetOldItem( rSet, FN_PARAM_FTN_INFO )) ||
308 aItem != *pOldItem )
309 rSet.Put(aItem);
311 return TRUE;
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),
335 FALSE, &pItem ) )
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();
355 lMaxHeight *= 8;
356 lMaxHeight /= 10;
358 // Maximalwerte setzen
359 HeightModify(0);
362 int SwFootNotePage::DeactivatePage( SfxItemSet* _pSet)
364 if(_pSet)
365 FillItemSet(*_pSet);
367 return TRUE;
370 USHORT* SwFootNotePage::GetRanges()
372 return aPageRg;