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