xref: /AOO41X/main/sw/source/ui/misc/pgfnote.cxx (revision efeef26f81c84063fb0a91bde3856d4a51172d90)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 #ifdef SW_DLLIMPLEMENTATION
28 #undef SW_DLLIMPLEMENTATION
29 #endif
30 
31 
32 
33 #ifndef _CMDID_H
34 #include <cmdid.h>
35 #endif
36 #include <hintids.hxx>
37 #include <tools/ref.hxx>
38 #ifndef _SVX_DIALOGS_HRC
39 #include <svx/dialogs.hrc>
40 #endif
41 #include <vcl/field.hxx>
42 #include <vcl/svapp.hxx>
43 #include <unotools/localedatawrapper.hxx>
44 #include <unotools/syslocale.hxx>
45 #include <editeng/sizeitem.hxx>
46 #include <svx/pageitem.hxx>
47 #include <svl/eitem.hxx>
48 #include <editeng/ulspitem.hxx>
49 #include <uitool.hxx>
50 #include <pagedesc.hxx>
51 #include <pgfnote.hxx>
52 #include <uiitems.hxx>
53 
54 #ifndef _GLOBALS_HRC
55 #include <globals.hrc>
56 #endif
57 #ifndef _MISC_HRC
58 #include <misc.hrc>
59 #endif
60 #ifndef _PGFNOTE_HRC
61 #include <pgfnote.hrc>
62 #endif
63 
64 #define TWIP_TO_LBOX 5
65 /*-----------------------------------------------------#---------------
66     Beschreibung:   vordefinierte Linien in Point
67  --------------------------------------------------------------------*/
68 
69 static const sal_uInt16 __FAR_DATA nLines[] = {
70     0,
71     50,
72     100,
73     150,
74     200,
75     500
76 };
77 
78 static const sal_uInt16 nLineCount = sizeof(nLines) / sizeof(nLines[0]);
79 
80 static sal_uInt16 __FAR_DATA aPageRg[] = {
81     FN_PARAM_FTN_INFO, FN_PARAM_FTN_INFO,
82     0
83 };
84 
85 
86 /*------------------------------------------------------------------------
87  Beschreibung:  liefert zurueck, ob die Linienbreite nWidth bereits
88                 in der Listbox enthalten ist.
89 ------------------------------------------------------------------------*/
90 
91 
lcl_HasLineWidth(sal_uInt16 nWidth)92 sal_Bool lcl_HasLineWidth(sal_uInt16 nWidth)
93 {
94     for(sal_uInt16 i = 0; i < nLineCount; ++i) {
95         if(nLines[i] == nWidth)
96             return sal_True;
97     }
98     return sal_False;
99 }
100 
101 /*------------------------------------------------------------------------
102  Beschreibung:  Handler fuer umschalten zwischen den unterschiedlichen
103                 Arten, wie die Hoehe des Fussnotenbereiches angegeben
104                 werden kann.
105 ------------------------------------------------------------------------*/
106 
107 
IMPL_LINK_INLINE_START(SwFootNotePage,HeightPage,Button *,EMPTYARG)108 IMPL_LINK_INLINE_START( SwFootNotePage, HeightPage, Button *, EMPTYARG )
109 {
110     aMaxHeightEdit.Enable(sal_False);
111     return 0;
112 }
IMPL_LINK_INLINE_END(SwFootNotePage,HeightPage,Button *,EMPTYARG)113 IMPL_LINK_INLINE_END( SwFootNotePage, HeightPage, Button *, EMPTYARG )
114 
115 
116 IMPL_LINK_INLINE_START( SwFootNotePage, HeightMetric, Button *, EMPTYARG )
117 {
118     aMaxHeightEdit.Enable();
119     aMaxHeightEdit.GrabFocus();
120     return 0;
121 }
IMPL_LINK_INLINE_END(SwFootNotePage,HeightMetric,Button *,EMPTYARG)122 IMPL_LINK_INLINE_END( SwFootNotePage, HeightMetric, Button *, EMPTYARG )
123 
124 /*------------------------------------------------------------------------
125  Beschreibung:  Handler Grenzwerte
126 ------------------------------------------------------------------------*/
127 
128 
129 IMPL_LINK( SwFootNotePage, HeightModify, MetricField *, EMPTYARG )
130 {
131     aMaxHeightEdit.SetMax(aMaxHeightEdit.Normalize(lMaxHeight -
132             (aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP)) +
133             aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP)))),
134             FUNIT_TWIP);
135     if(aMaxHeightEdit.GetValue() < 0)
136         aMaxHeightEdit.SetValue(0);
137     aDistEdit.SetMax(aDistEdit.Normalize(lMaxHeight -
138             (aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP)) +
139             aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP)))),
140             FUNIT_TWIP);
141     if(aDistEdit.GetValue() < 0)
142         aDistEdit.SetValue(0);
143     aLineDistEdit.SetMax(aLineDistEdit.Normalize(lMaxHeight -
144             (aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP)) +
145             aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP)))),
146             FUNIT_TWIP);
147     return 0;
148 }
149 
150 // CTOR / DTOR -----------------------------------------------------------
151 
SwFootNotePage(Window * pParent,const SfxItemSet & rSet)152 SwFootNotePage::SwFootNotePage(Window *pParent, const SfxItemSet &rSet) :
153 
154     SfxTabPage(pParent, SW_RES(TP_FOOTNOTE_PAGE), rSet),
155     aPosHeader(this,        SW_RES(FL_FOOTNOTE_SIZE)),
156     aMaxHeightPageBtn(this, SW_RES(RB_MAXHEIGHT_PAGE)),
157     aMaxHeightBtn(this,     SW_RES(RB_MAXHEIGHT)),
158     aMaxHeightEdit(this,    SW_RES(ED_MAXHEIGHT)),
159     aDistLbl(this,          SW_RES(FT_DIST)),
160     aDistEdit(this,         SW_RES(ED_DIST)),
161 
162     aLineHeader(this,       SW_RES(FL_LINE)),
163     aLinePosLbl(this,       SW_RES(FT_LINEPOS)),
164     aLinePosBox(this,       SW_RES(DLB_LINEPOS)),
165     aLineTypeLbl(this,      SW_RES(FT_LINETYPE)),
166     aLineTypeBox(this,      SW_RES(DLB_LINETYPE)),
167     aLineWidthLbl(this,     SW_RES(FT_LINEWIDTH)),
168     aLineWidthEdit(this,    SW_RES(ED_LINEWIDTH)),
169     aLineDistLbl(this,      SW_RES(FT_LINEDIST)),
170     aLineDistEdit(this,     SW_RES(ED_LINEDIST))
171     {
172     FreeResource();
173 
174     SetExchangeSupport();
175     FieldUnit aMetric = ::GetDfltMetric(sal_False);
176     SetMetric( aMaxHeightEdit,  aMetric );
177     SetMetric( aDistEdit,       aMetric );
178     SetMetric( aLineDistEdit,   aMetric );
179     MeasurementSystem eSys = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
180     long nHeightValue = MEASURE_METRIC != eSys ? 1440 : 1134;
181     aMaxHeightEdit.SetValue(aMaxHeightEdit.Normalize(nHeightValue),FUNIT_TWIP);;
182     aMaxHeightEdit.SetAccessibleRelationLabeledBy(&aMaxHeightBtn);
183 }
184 
~SwFootNotePage()185 SwFootNotePage::~SwFootNotePage()
186 {
187 }
188 
189 
Create(Window * pParent,const SfxItemSet & rSet)190 SfxTabPage* SwFootNotePage::Create(Window *pParent, const SfxItemSet &rSet)
191 {
192     return new SwFootNotePage(pParent, rSet);
193 }
194 
195 
196 /*--------------------------------------------------------------------
197     Beschreibung:
198  --------------------------------------------------------------------*/
199 
200 
Reset(const SfxItemSet & rSet)201 void SwFootNotePage::Reset(const SfxItemSet &rSet)
202 {
203     // Falls noch kein Bsp vorhanden Init hier sonst im Activate
204     //
205     SwPageFtnInfo* pDefFtnInfo = 0;
206     const SwPageFtnInfo* pFtnInfo;
207     const SfxPoolItem* pItem = SfxTabPage::GetItem(rSet, FN_PARAM_FTN_INFO);
208     if( pItem )
209     {
210         pFtnInfo = &((const SwPageFtnInfoItem*)pItem)->GetPageFtnInfo();
211     }
212     else
213     {
214         // wenn "Standard" betaetigt wird, wird das Fussnotenitem geloescht,
215         // deswegen muss hier eine Fussnotenstruktur erzeugt werden
216         pDefFtnInfo = new SwPageFtnInfo();
217         pFtnInfo = pDefFtnInfo;
218     }
219         // Hoehe Fussnotenbereich
220     SwTwips lHeight = pFtnInfo->GetHeight();
221     if(lHeight)
222     {
223         aMaxHeightEdit.SetValue(aMaxHeightEdit.Normalize(lHeight),FUNIT_TWIP);
224         aMaxHeightBtn.Check(sal_True);
225     }
226     else
227     {
228         aMaxHeightPageBtn.Check(sal_True);
229         aMaxHeightEdit.Enable(sal_False);
230     }
231     aMaxHeightPageBtn.SetClickHdl(LINK(this,SwFootNotePage,HeightPage));
232     aMaxHeightBtn.SetClickHdl(LINK(this,SwFootNotePage,HeightMetric));
233     Link aLk = LINK(this, SwFootNotePage, HeightModify);
234     aMaxHeightEdit.SetLoseFocusHdl( aLk );
235     aDistEdit.SetLoseFocusHdl( aLk );
236     aLineDistEdit.SetLoseFocusHdl( aLk );
237 
238     // Trennlinie
239     for(sal_uInt16 i = 0; i < nLineCount; ++i)
240         aLineTypeBox.InsertEntry(nLines[i]);
241 
242     const sal_uInt16 nWidth = (sal_uInt16)pFtnInfo->GetLineWidth() * TWIP_TO_LBOX;
243     if ( !lcl_HasLineWidth(nWidth) )
244         aLineTypeBox.InsertEntry(nWidth);
245     aLineTypeBox.SelectEntry(nWidth);
246 
247     // Position
248     aLinePosBox.SelectEntryPos( static_cast< sal_uInt16 >(pFtnInfo->GetAdj()) );
249 
250         // Breite
251     Fraction aTmp( 100, 1 );
252     aTmp *= pFtnInfo->GetWidth();
253     aLineWidthEdit.SetValue( static_cast<long>(aTmp) );
254 
255         // Abstand Fussnotenbereich
256     aDistEdit.SetValue(aDistEdit.Normalize(pFtnInfo->GetTopDist()),FUNIT_TWIP);
257     aLineDistEdit.SetValue(
258         aLineDistEdit.Normalize(pFtnInfo->GetBottomDist()), FUNIT_TWIP);
259     ActivatePage( rSet );
260     delete pDefFtnInfo;
261 }
262 
263 /*--------------------------------------------------------------------
264     Beschreibung:   Attribute in den Set stopfen bei OK
265  --------------------------------------------------------------------*/
266 
267 
FillItemSet(SfxItemSet & rSet)268 sal_Bool SwFootNotePage::FillItemSet(SfxItemSet &rSet)
269 {
270     SwPageFtnInfoItem aItem((const SwPageFtnInfoItem&)GetItemSet().Get(FN_PARAM_FTN_INFO));
271 
272     // Das ist das Original
273     SwPageFtnInfo &rFtnInfo = aItem.GetPageFtnInfo();
274 
275         // Hoehe Fussnotenbereich
276     if(aMaxHeightBtn.IsChecked())
277         rFtnInfo.SetHeight( static_cast< SwTwips >(
278                 aMaxHeightEdit.Denormalize(aMaxHeightEdit.GetValue(FUNIT_TWIP))));
279     else
280         rFtnInfo.SetHeight(0);
281 
282         // Abstand Fussnotenbereich
283     rFtnInfo.SetTopDist(  static_cast< SwTwips >(
284             aDistEdit.Denormalize(aDistEdit.GetValue(FUNIT_TWIP))));
285     rFtnInfo.SetBottomDist(  static_cast< SwTwips >(
286             aLineDistEdit.Denormalize(aLineDistEdit.GetValue(FUNIT_TWIP))));
287 
288         // Trennlinie
289     const sal_uInt16 nPos = aLineTypeBox.GetSelectEntryPos();
290     if( LISTBOX_ENTRY_NOTFOUND != nPos )
291         rFtnInfo.SetLineWidth(nLines[nPos] / TWIP_TO_LBOX);
292 
293         // Position
294     rFtnInfo.SetAdj((SwFtnAdj)aLinePosBox.GetSelectEntryPos());
295 
296         // Breite
297     rFtnInfo.SetWidth(Fraction( static_cast< long >(aLineWidthEdit.GetValue()), 100));
298 
299     const SfxPoolItem* pOldItem;
300     if(0 == (pOldItem = GetOldItem( rSet, FN_PARAM_FTN_INFO )) ||
301                 aItem != *pOldItem )
302         rSet.Put(aItem);
303 
304     return sal_True;
305 }
306 
ActivatePage(const SfxItemSet & rSet)307 void SwFootNotePage::ActivatePage(const SfxItemSet& rSet)
308 {
309     const SvxSizeItem& rSize = (const SvxSizeItem&)rSet.Get( RES_FRM_SIZE );
310     lMaxHeight = rSize.GetSize().Height();
311 
312     const SfxPoolItem* pItem;
313     if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_HEADERSET), sal_False, &pItem ) )
314     {
315         const SfxItemSet& rHeaderSet = ((SvxSetItem*)pItem)->GetItemSet();
316         const SfxBoolItem& rHeaderOn =
317             (const SfxBoolItem&)rHeaderSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_ON ) );
318 
319         if ( rHeaderOn.GetValue() )
320         {
321             const SvxSizeItem& rSizeItem =
322                 (const SvxSizeItem&)rHeaderSet.Get(rSet.GetPool()->GetWhich(SID_ATTR_PAGE_SIZE));
323             lMaxHeight -= rSizeItem.GetSize().Height();
324         }
325     }
326 
327     if( SFX_ITEM_SET == rSet.GetItemState( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_FOOTERSET),
328             sal_False, &pItem ) )
329     {
330         const SfxItemSet& rFooterSet = ((SvxSetItem*)pItem)->GetItemSet();
331         const SfxBoolItem& rFooterOn =
332             (const SfxBoolItem&)rFooterSet.Get( SID_ATTR_PAGE_ON );
333 
334         if ( rFooterOn.GetValue() )
335         {
336             const SvxSizeItem& rSizeItem =
337                 (const SvxSizeItem&)rFooterSet.Get( rSet.GetPool()->GetWhich( SID_ATTR_PAGE_SIZE ) );
338             lMaxHeight -= rSizeItem.GetSize().Height();
339         }
340     }
341 
342     if ( rSet.GetItemState( RES_UL_SPACE , sal_False ) == SFX_ITEM_SET )
343     {
344         const SvxULSpaceItem &rUL = (const SvxULSpaceItem&)rSet.Get( RES_UL_SPACE );
345         lMaxHeight -= rUL.GetUpper() + rUL.GetLower();
346     }
347 
348     lMaxHeight *= 8;
349     lMaxHeight /= 10;
350 
351     // Maximalwerte setzen
352     HeightModify(0);
353 }
354 
DeactivatePage(SfxItemSet * _pSet)355 int SwFootNotePage::DeactivatePage( SfxItemSet* _pSet)
356 {
357     if(_pSet)
358         FillItemSet(*_pSet);
359 
360     return sal_True;
361 }
362 
GetRanges()363 sal_uInt16* SwFootNotePage::GetRanges()
364 {
365     return aPageRg;
366 }
367 
368 
369 
370