merge the formfield patch from ooo-build
[ooovba.git] / svx / source / items / numitem.cxx
blob32a493b5bdac201e8a969a30547a774d8ebbd540
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: numitem.cxx,v $
10 * $Revision: 1.30 $
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_svx.hxx"
34 #include <svx/numitem.hxx>
36 #include <com/sun/star/text/HoriOrientation.hpp>
37 #include <com/sun/star/text/VertOrientation.hpp>
38 #include <com/sun/star/text/RelOrientation.hpp>
39 #include <svx/brshitem.hxx>
40 #include <vcl/font.hxx>
41 #ifndef _SVX_SVXIDS_HRC
42 #include <svx/svxids.hrc>
43 #endif
44 #ifndef _SVX_NUMDEF_HXX
45 #include <svx/numdef.hxx>
46 #endif
47 #include <vcl/graph.hxx>
48 #include <vcl/window.hxx>
49 #include <vcl/svapp.hxx>
50 #include <unolingu.hxx>
51 #include <com/sun/star/text/XNumberingFormatter.hpp>
52 #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
53 #include <com/sun/star/style/NumberingType.hpp>
54 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
55 #include <com/sun/star/beans/PropertyValue.hpp>
56 #include <comphelper/processfactory.hxx>
58 #include "unonrule.hxx"
60 #define MM100_TO_TWIP(MM100) ((MM100*72L+63L)/127L)
62 #define DEF_WRITER_LSPACE 500 //Standardeinrueckung
63 #define DEF_DRAW_LSPACE 800 //Standardeinrueckung
65 using namespace ::com::sun::star;
66 using namespace ::com::sun::star::lang;
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::text;
69 using namespace ::com::sun::star::beans;
70 using namespace ::com::sun::star::style;
72 sal_Int32 SvxNumberType::nRefCount = 0;
73 com::sun::star::uno::Reference<com::sun::star::text::XNumberingFormatter> SvxNumberType::xFormatter = 0;
74 void lcl_getFormatter(com::sun::star::uno::Reference<com::sun::star::text::XNumberingFormatter>& _xFormatter)
76 if(!_xFormatter.is())
78 try
80 Reference< XMultiServiceFactory > xMSF = ::comphelper::getProcessServiceFactory();
81 Reference < XInterface > xI = xMSF->createInstance(
82 ::rtl::OUString::createFromAscii( "com.sun.star.text.DefaultNumberingProvider" ) );
83 Reference<XDefaultNumberingProvider> xRet(xI, UNO_QUERY);
84 DBG_ASSERT(xRet.is(), "service missing: \"com.sun.star.text.DefaultNumberingProvider\"");
85 _xFormatter = Reference<XNumberingFormatter> (xRet, UNO_QUERY);
87 catch(Exception& )
92 /* -----------------------------22.02.01 14:24--------------------------------
94 ---------------------------------------------------------------------------*/
95 SvxNumberType::SvxNumberType(sal_Int16 nType) :
96 nNumType(nType),
97 bShowSymbol(sal_True)
99 nRefCount++;
101 /* -----------------------------22.02.01 14:31--------------------------------
103 ---------------------------------------------------------------------------*/
104 SvxNumberType::SvxNumberType(const SvxNumberType& rType) :
105 nNumType(rType.nNumType),
106 bShowSymbol(rType.bShowSymbol)
108 nRefCount++;
110 /* -----------------------------22.02.01 14:24--------------------------------
112 ---------------------------------------------------------------------------*/
113 SvxNumberType::~SvxNumberType()
115 if(!--nRefCount)
116 xFormatter = 0;
118 /* -----------------------------22.02.01 11:09--------------------------------
120 ---------------------------------------------------------------------------*/
121 String SvxNumberType::GetNumStr( ULONG nNo ) const
123 LanguageType eLang = Application::GetSettings().GetLanguage();
124 Locale aLocale = SvxCreateLocale(eLang);
125 return GetNumStr( nNo, aLocale );
127 /* -----------------28.10.98 15:56-------------------
129 * --------------------------------------------------*/
130 String SvxNumberType::GetNumStr( ULONG nNo, const Locale& rLocale ) const
132 lcl_getFormatter(xFormatter);
133 String aTmpStr;
134 if(!xFormatter.is())
135 return aTmpStr;
137 if(bShowSymbol)
139 switch(nNumType)
141 case NumberingType::CHAR_SPECIAL:
142 case NumberingType::BITMAP:
143 break;
144 default:
146 //#95525# '0' allowed for ARABIC numberings
147 if(NumberingType::ARABIC == nNumType && 0 == nNo )
148 aTmpStr = '0';
149 else
151 Sequence< PropertyValue > aProperties(2);
152 PropertyValue* pValues = aProperties.getArray();
153 pValues[0].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NumberingType"));
154 pValues[0].Value <<= nNumType;
155 pValues[1].Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Value"));
156 pValues[1].Value <<= (sal_Int32)nNo;
160 aTmpStr = xFormatter->makeNumberingString( aProperties, rLocale );
162 catch(Exception&)
169 return aTmpStr;
171 /* -----------------27.10.98 10:33-------------------
173 * --------------------------------------------------*/
174 // --> OD 2008-01-09 #newlistlevelattrs#
175 SvxNumberFormat::SvxNumberFormat( sal_Int16 eType,
176 SvxNumPositionAndSpaceMode ePositionAndSpaceMode )
177 // <--
178 : SvxNumberType(eType),
179 eNumAdjust(SVX_ADJUST_LEFT),
180 nInclUpperLevels(0),
181 nStart(1),
182 cBullet(SVX_DEF_BULLET),
183 nBulletRelSize(100),
184 nBulletColor(COL_BLACK),
185 // --> OD 2008-01-09 #newlistlevelattrs#
186 mePositionAndSpaceMode( ePositionAndSpaceMode ),
187 // <--
188 nFirstLineOffset(0),
189 nAbsLSpace(0),
190 nLSpace(0),
191 nCharTextDistance(0),
192 // --> OD 2008-01-09 #newlistlevelattrs#
193 meLabelFollowedBy( LISTTAB ),
194 mnListtabPos( 0 ),
195 mnFirstLineIndent( 0 ),
196 mnIndentAt( 0 ),
197 // <--
198 pGraphicBrush(0),
199 eVertOrient(text::VertOrientation::NONE),
200 pBulletFont(0)
203 /* -----------------27.10.98 10:56-------------------
205 * --------------------------------------------------*/
206 SvxNumberFormat::SvxNumberFormat(const SvxNumberFormat& rFormat) :
207 SvxNumberType(rFormat),
208 // --> OD 2008-01-09 #newlistlevelattrs#
209 mePositionAndSpaceMode( rFormat.mePositionAndSpaceMode ),
210 // <--
211 pGraphicBrush(0),
212 pBulletFont(0)
214 *this = rFormat;
216 /* -----------------27.10.98 10:56-------------------
218 * --------------------------------------------------*/
219 SvxNumberFormat::~SvxNumberFormat()
221 delete pGraphicBrush;
222 delete pBulletFont;
224 /* -----------------08.12.98 11:14-------------------
226 * --------------------------------------------------*/
227 //SvxNumberFormat::SvxNumberFormat(SvStream &rStream)
229 // USHORT nVersion;
230 // rStream >> nVersion;
232 // USHORT nUSHORT;
233 // rStream >> nUSHORT;
234 // SetNumberingType((sal_Int16)nUSHORT);
235 // rStream >> nUSHORT;
236 // eNumAdjust = (SvxAdjust)nUSHORT;
237 // rStream >> nUSHORT;
238 // nInclUpperLevels = (BYTE)nUSHORT;
239 // rStream >> nUSHORT;
240 // nStart = nUSHORT;
241 // rStream >> nUSHORT;
242 // cBullet = nUSHORT;
244 // short nShort;
245 // rStream >> nShort;
246 // nFirstLineOffset = nShort;
247 // rStream >> nShort;
248 // nAbsLSpace = nShort;
249 // rStream >> nShort;
250 // nLSpace = nShort;
252 // rStream >> nShort;
253 // nCharTextDistance = nShort;
254 // rtl_TextEncoding eEnc = gsl_getSystemTextEncoding();
255 // rStream.ReadByteString(sPrefix, eEnc);
256 // rStream.ReadByteString(sSuffix, eEnc);
257 // rStream.ReadByteString(sCharStyleName, eEnc);
258 // rStream >> nUSHORT;
259 // if(nUSHORT)
260 // {
261 // SvxBrushItem aHelper(0);
262 // pGraphicBrush = (SvxBrushItem*) aHelper.Create( rStream, BRUSH_GRAPHIC_VERSION );
263 // }
264 // else
265 // pGraphicBrush = 0;
267 // rStream >> nUSHORT;
268 // eVertOrient = (sal_Int16)nUSHORT;
270 // rStream >> nUSHORT;
271 // if(nUSHORT)
272 // {
273 // pBulletFont = new Font;
274 // rStream >> *pBulletFont;
275 // if(!pBulletFont->GetCharSet())
276 // pBulletFont->SetCharSet(rStream.GetStreamCharSet());
277 // }
278 // else
279 // pBulletFont = 0;
280 // rStream >> aGraphicSize;
282 // rStream >> nBulletColor;
283 // rStream >> nUSHORT;
284 // nBulletRelSize = nUSHORT;
285 // rStream >> nUSHORT;
286 // SetShowSymbol((BOOL)nUSHORT);
288 // if( nVersion < NUMITEM_VERSION_03 )
289 // cBullet = ByteString::ConvertToUnicode( (sal_Char)cBullet,
290 // (pBulletFont&&pBulletFont->GetCharSet()) ? pBulletFont->GetCharSet()
291 // : RTL_TEXTENCODING_SYMBOL );
292 // if(pBulletFont)
293 // {
294 // BOOL bConvertBulletFont = rStream.GetVersion() <= SOFFICE_FILEFORMAT_50;
295 // if(bConvertBulletFont)
296 // {
298 // FontToSubsFontConverter pConverter =
299 // CreateFontToSubsFontConverter(pBulletFont->GetName(),
300 // FONTTOSUBSFONT_IMPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS);
301 // if(pConverter)
302 // {
303 // cBullet = ConvertFontToSubsFontChar(pConverter, cBullet);
304 // String sFontName = GetFontToSubsFontName(pConverter);
305 // pBulletFont->SetName(sFontName);
306 // DestroyFontToSubsFontConverter(pConverter);
307 // }
308 // }
309 // }
311 /* -----------------08.12.98 11:14-------------------
313 * --------------------------------------------------*/
314 // --> OD 2008-01-09 #newlistlevelattrs# - no longer used
315 //SvStream& SvxNumberFormat::Store(SvStream &rStream, FontToSubsFontConverter pConverter)
317 // if(pConverter && pBulletFont)
318 // {
319 // cBullet = ConvertFontToSubsFontChar(pConverter, cBullet);
320 // String sFontName = GetFontToSubsFontName(pConverter);
321 // pBulletFont->SetName(sFontName);
322 // }
324 // rStream << (USHORT)NUMITEM_VERSION_03;
326 // rStream << (USHORT)GetNumberingType();
327 // rStream << (USHORT)eNumAdjust;
328 // rStream << (USHORT)nInclUpperLevels;
329 // rStream << nStart;
330 // rStream << (USHORT)cBullet;
332 // rStream << nFirstLineOffset;
333 // rStream << nAbsLSpace;
334 // rStream << nLSpace;
336 // rStream << nCharTextDistance;
337 // rtl_TextEncoding eEnc = gsl_getSystemTextEncoding();
338 // rStream.WriteByteString(sPrefix, eEnc);
339 // rStream.WriteByteString(sSuffix, eEnc);
340 // rStream.WriteByteString(sCharStyleName, eEnc);
341 // if(pGraphicBrush)
342 // {
343 // rStream << (USHORT)1;
345 // // #75113# in SD or SI force bullet itself to be stored,
346 // // for that purpose throw away link when link and graphic
347 // // are present, so Brush save is forced
348 // if(pGraphicBrush->GetGraphicLink() && pGraphicBrush->GetGraphic())
349 // {
350 // String aEmpty;
351 // pGraphicBrush->SetGraphicLink(aEmpty);
352 // }
354 // pGraphicBrush->Store(rStream, BRUSH_GRAPHIC_VERSION);
355 // }
356 // else
357 // rStream << (USHORT)0;
359 // rStream << (USHORT)eVertOrient;
360 // if(pBulletFont)
361 // {
362 // rStream << (USHORT)1;
363 // rStream << *pBulletFont;
364 // }
365 // else
366 // rStream << (USHORT)0;
367 // rStream << aGraphicSize;
369 // Color nTempColor = nBulletColor;
370 // if(COL_AUTO == nBulletColor.GetColor())
371 // nTempColor = COL_BLACK;
372 // rStream << nTempColor;
373 // rStream << nBulletRelSize;
374 // rStream << (USHORT)IsShowSymbol();
375 // return rStream;
377 // <--
378 /* -----------------------------23.02.01 11:10--------------------------------
380 ---------------------------------------------------------------------------*/
381 SvxNumberFormat& SvxNumberFormat::operator=( const SvxNumberFormat& rFormat )
383 SetNumberingType(rFormat.GetNumberingType());
384 eNumAdjust = rFormat.eNumAdjust ;
385 nInclUpperLevels = rFormat.nInclUpperLevels ;
386 nStart = rFormat.nStart ;
387 cBullet = rFormat.cBullet ;
388 // --> OD 2008-01-09 #newlistlevelattrs#
389 mePositionAndSpaceMode = rFormat.mePositionAndSpaceMode;
390 // <--
391 nFirstLineOffset = rFormat.nFirstLineOffset;
392 nAbsLSpace = rFormat.nAbsLSpace ;
393 nLSpace = rFormat.nLSpace ;
394 nCharTextDistance = rFormat.nCharTextDistance ;
395 // --> OD 2008-01-09 #newlistlevelattrs#
396 meLabelFollowedBy = rFormat.meLabelFollowedBy;
397 mnListtabPos = rFormat.mnListtabPos;
398 mnFirstLineIndent = rFormat.mnFirstLineIndent;
399 mnIndentAt = rFormat.mnIndentAt;
400 // <--
401 eVertOrient = rFormat.eVertOrient ;
402 sPrefix = rFormat.sPrefix ;
403 sSuffix = rFormat.sSuffix ;
404 aGraphicSize = rFormat.aGraphicSize ;
405 nBulletColor = rFormat.nBulletColor ;
406 nBulletRelSize = rFormat.nBulletRelSize;
407 SetShowSymbol(rFormat.IsShowSymbol());
408 sCharStyleName = rFormat.sCharStyleName;
409 DELETEZ(pGraphicBrush);
410 if(rFormat.pGraphicBrush)
412 pGraphicBrush = new SvxBrushItem(*rFormat.pGraphicBrush);
413 pGraphicBrush->SetDoneLink( STATIC_LINK( this, SvxNumberFormat, GraphicArrived) );
415 DELETEZ(pBulletFont);
416 if(rFormat.pBulletFont)
417 pBulletFont = new Font(*rFormat.pBulletFont);
418 return *this;
420 /* -----------------27.10.98 10:56-------------------
422 * --------------------------------------------------*/
423 BOOL SvxNumberFormat::operator==( const SvxNumberFormat& rFormat) const
425 if( GetNumberingType() != rFormat.GetNumberingType() ||
426 eNumAdjust != rFormat.eNumAdjust ||
427 nInclUpperLevels != rFormat.nInclUpperLevels ||
428 nStart != rFormat.nStart ||
429 cBullet != rFormat.cBullet ||
430 // --> OD 2008-01-09 #newlistlevelattrs#
431 mePositionAndSpaceMode != rFormat.mePositionAndSpaceMode ||
432 // <--
433 nFirstLineOffset != rFormat.nFirstLineOffset ||
434 nAbsLSpace != rFormat.nAbsLSpace ||
435 nLSpace != rFormat.nLSpace ||
436 nCharTextDistance != rFormat.nCharTextDistance ||
437 // --> OD 2008-01-09 #newlistlevelattrs#
438 meLabelFollowedBy != rFormat.meLabelFollowedBy ||
439 mnListtabPos != rFormat.mnListtabPos ||
440 mnFirstLineIndent != rFormat.mnFirstLineIndent ||
441 mnIndentAt != rFormat.mnIndentAt ||
442 // <--
443 eVertOrient != rFormat.eVertOrient ||
444 sPrefix != rFormat.sPrefix ||
445 sSuffix != rFormat.sSuffix ||
446 aGraphicSize != rFormat.aGraphicSize ||
447 nBulletColor != rFormat.nBulletColor ||
448 nBulletRelSize != rFormat.nBulletRelSize ||
449 IsShowSymbol() != rFormat.IsShowSymbol() ||
450 sCharStyleName != rFormat.sCharStyleName
452 return FALSE;
453 if (
454 (pGraphicBrush && !rFormat.pGraphicBrush) ||
455 (!pGraphicBrush && rFormat.pGraphicBrush) ||
456 (pGraphicBrush && *pGraphicBrush != *rFormat.pGraphicBrush)
459 return FALSE;
461 if (
462 (pBulletFont && !rFormat.pBulletFont) ||
463 (!pBulletFont && rFormat.pBulletFont) ||
464 (pBulletFont && *pBulletFont != *rFormat.pBulletFont)
467 return FALSE;
469 return TRUE;
471 /* -----------------28.10.98 09:53-------------------
473 * --------------------------------------------------*/
474 void SvxNumberFormat::SetGraphicBrush( const SvxBrushItem* pBrushItem,
475 const Size* pSize, const sal_Int16* pOrient)
477 if(!pBrushItem)
479 delete pGraphicBrush;
480 pGraphicBrush = 0;
482 else if ( !pGraphicBrush || (pGraphicBrush && !(*pBrushItem == *pGraphicBrush)) )
484 delete pGraphicBrush;
485 pGraphicBrush = (SvxBrushItem*)pBrushItem->Clone();
486 pGraphicBrush->SetDoneLink( STATIC_LINK( this, SvxNumberFormat, GraphicArrived) );
489 if(pOrient)
490 eVertOrient = *pOrient;
491 else
492 eVertOrient = text::VertOrientation::NONE;
493 if(pSize)
494 aGraphicSize = *pSize;
495 else
496 aGraphicSize.Width() = aGraphicSize.Height() = 0;
498 /* -----------------28.10.98 09:59-------------------
500 * --------------------------------------------------*/
501 void SvxNumberFormat::SetGraphic( const String& rName )
503 const String* pName;
504 if( pGraphicBrush &&
505 0 != (pName = pGraphicBrush->GetGraphicLink())
506 && *pName == rName )
507 return ;
509 delete pGraphicBrush;
510 String sTmp;
511 pGraphicBrush = new SvxBrushItem( rName, sTmp, GPOS_AREA, 0 );
512 pGraphicBrush->SetDoneLink( STATIC_LINK( this, SvxNumberFormat, GraphicArrived) );
513 if( eVertOrient == text::VertOrientation::NONE )
514 eVertOrient = text::VertOrientation::TOP;
516 aGraphicSize.Width() = aGraphicSize.Height() = 0;
518 /* -----------------------------22.02.01 15:55--------------------------------
520 ---------------------------------------------------------------------------*/
521 void SvxNumberFormat::SetVertOrient(sal_Int16 eSet)
523 eVertOrient = eSet;
525 /* -----------------------------22.02.01 15:55--------------------------------
527 ---------------------------------------------------------------------------*/
528 sal_Int16 SvxNumberFormat::GetVertOrient() const
530 return eVertOrient;
532 /* -----------------28.10.98 09:59-------------------
534 * --------------------------------------------------*/
535 void SvxNumberFormat::SetBulletFont(const Font* pFont)
537 delete pBulletFont;
538 pBulletFont = pFont ? new Font(*pFont): 0;
541 // --> OD 2008-01-09 #newlistlevelattrs#
542 SvxNumberFormat::SvxNumPositionAndSpaceMode SvxNumberFormat::GetPositionAndSpaceMode() const
544 return mePositionAndSpaceMode;
546 void SvxNumberFormat::SetPositionAndSpaceMode( SvxNumPositionAndSpaceMode ePositionAndSpaceMode )
548 mePositionAndSpaceMode = ePositionAndSpaceMode;
551 short SvxNumberFormat::GetLSpace() const
553 //#if OSL_DEBUG_LEVEL > 1
554 // DBG_ASSERT( mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION,
555 // "<SvxNumberFormat::GetLSpace()> - misusage: position-and-space-mode does not equal LABEL_WIDTH_AND_POSITION");
556 //#endif
557 return mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION ? nLSpace : 0;
559 short SvxNumberFormat::GetAbsLSpace() const
561 //#if OSL_DEBUG_LEVEL > 1
562 // DBG_ASSERT( mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION,
563 // "<SvxNumberFormat::GetAbsLSpace()> - misusage: position-and-space-mode does not equal LABEL_WIDTH_AND_POSITION");
564 //#endif
565 return mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION
566 ? nAbsLSpace
567 : static_cast<short>( GetFirstLineIndent() + GetIndentAt() );
569 short SvxNumberFormat::GetFirstLineOffset() const
571 //#if OSL_DEBUG_LEVEL > 1
572 // DBG_ASSERT( mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION,
573 // "<SvxNumberFormat::GetFirstLineOffset()> - misusage: position-and-space-mode does not equal LABEL_WIDTH_AND_POSITION");
574 //#endif
575 return mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION
576 ? nFirstLineOffset
577 : static_cast<short>( GetFirstLineIndent() );
579 short SvxNumberFormat::GetCharTextDistance() const
581 //#if OSL_DEBUG_LEVEL > 1
582 // DBG_ASSERT( mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION,
583 // "<SvxNumberFormat::GetCharTextDistance()> - misusage: position-and-space-mode does not equal LABEL_WIDTH_AND_POSITION");
584 //#endif
585 return mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION ? nCharTextDistance : 0;
588 void SvxNumberFormat::SetLabelFollowedBy( const SvxNumLabelFollowedBy eLabelFollowedBy )
590 meLabelFollowedBy = eLabelFollowedBy;
592 SvxNumberFormat::SvxNumLabelFollowedBy SvxNumberFormat::GetLabelFollowedBy() const
594 return meLabelFollowedBy;
596 void SvxNumberFormat::SetListtabPos( const long nListtabPos )
598 mnListtabPos = nListtabPos;
600 long SvxNumberFormat::GetListtabPos() const
602 return mnListtabPos;
604 void SvxNumberFormat::SetFirstLineIndent( const long nFirstLineIndent )
606 mnFirstLineIndent = nFirstLineIndent;
608 long SvxNumberFormat::GetFirstLineIndent() const
610 return mnFirstLineIndent;
612 void SvxNumberFormat::SetIndentAt( const long nIndentAt )
614 mnIndentAt = nIndentAt;
616 long SvxNumberFormat::GetIndentAt() const
618 return mnIndentAt;
620 // <--
622 /* -----------------28.10.98 10:03-------------------
624 * --------------------------------------------------*/
625 IMPL_STATIC_LINK( SvxNumberFormat, GraphicArrived, void *, EMPTYARG )
627 // ggfs. die GrfSize setzen:
628 if( !pThis->aGraphicSize.Width() || !pThis->aGraphicSize.Height() )
630 const Graphic* pGrf = pThis->pGraphicBrush->GetGraphic();
631 if( pGrf )
632 pThis->aGraphicSize = SvxNumberFormat::GetGraphicSizeMM100( pGrf );
634 pThis->NotifyGraphicArrived();
635 return 0;
637 /* -----------------------------02.07.01 15:36--------------------------------
639 ---------------------------------------------------------------------------*/
640 void SvxNumberFormat::NotifyGraphicArrived()
644 /* -----------------28.10.98 10:38-------------------
646 * --------------------------------------------------*/
647 Size SvxNumberFormat::GetGraphicSizeMM100(const Graphic* pGraphic)
649 const MapMode aMapMM100( MAP_100TH_MM );
650 const Size& rSize = pGraphic->GetPrefSize();
651 Size aRetSize;
652 if ( pGraphic->GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
654 OutputDevice* pOutDev = Application::GetDefaultDevice();
655 MapMode aOldMap( pOutDev->GetMapMode() );
656 pOutDev->SetMapMode( aMapMM100 );
657 aRetSize = pOutDev->PixelToLogic( rSize );
658 pOutDev->SetMapMode( aOldMap );
660 else
661 aRetSize = OutputDevice::LogicToLogic( rSize, pGraphic->GetPrefMapMode(), aMapMM100 );
662 return aRetSize;
664 /* -----------------28.10.98 15:57-------------------
666 * --------------------------------------------------*/
667 String SvxNumberFormat::CreateRomanString( ULONG nNo, BOOL bUpper )
669 nNo %= 4000; // mehr kann nicht dargestellt werden
670 // i, ii, iii, iv, v, vi, vii, vii, viii, ix
671 // (Dummy),1000,500,100,50,10,5,1
672 const char *cRomanArr = bUpper
673 ? "MDCLXVI--" // +2 Dummy-Eintraege !!
674 : "mdclxvi--"; // +2 Dummy-Eintraege !!
676 String sRet;
677 USHORT nMask = 1000;
678 while( nMask )
680 BYTE nZahl = BYTE(nNo / nMask);
681 BYTE nDiff = 1;
682 nNo %= nMask;
684 if( 5 < nZahl )
686 if( nZahl < 9 )
687 sRet += sal_Unicode(*(cRomanArr-1));
688 ++nDiff;
689 nZahl -= 5;
691 switch( nZahl )
693 case 3: { sRet += sal_Unicode(*cRomanArr); }
694 case 2: { sRet += sal_Unicode(*cRomanArr); }
695 case 1: { sRet += sal_Unicode(*cRomanArr); }
696 break;
698 case 4: {
699 sRet += sal_Unicode(*cRomanArr);
700 sRet += sal_Unicode(*(cRomanArr-nDiff));
702 break;
703 case 5: { sRet += sal_Unicode(*(cRomanArr-nDiff)); }
704 break;
707 nMask /= 10; // zur naechsten Dekade
708 cRomanArr += 2;
710 return sRet;
712 #ifdef OLD_NUMBER_FORMATTING
713 void SvxNumberFormat::GetCharStr( ULONG nNo, String& rStr ) const
715 DBG_ASSERT( nNo, "0 ist eine ungueltige Nummer !!" );
717 const ULONG coDiff = 'Z' - 'A' +1;
718 char cAdd = (SVX_NUM_CHARS_UPPER_LETTER == eNumType ? 'A' : 'a') - 1;
719 ULONG nCalc;
721 do {
722 nCalc = nNo % coDiff;
723 if( !nCalc )
724 nCalc = coDiff;
725 rStr.Insert( sal_Unicode(cAdd + nCalc ), 0 );
726 nNo -= nCalc;
727 if( nNo )
728 nNo /= coDiff;
729 } while( nNo );
732 void SvxNumberFormat::GetCharStrN( ULONG nNo, String& rStr ) const
734 DBG_ASSERT( nNo, "0 ist eine ungueltige Nummer !!" );
736 const ULONG coDiff = 'Z' - 'A' +1;
737 char cChar = (char)(--nNo % coDiff);
738 if( SVX_NUM_CHARS_UPPER_LETTER_N == eNumType )
739 cChar += 'A';
740 else
741 cChar += 'a';
743 rStr.Fill( (USHORT)(nNo / coDiff) + 1, sal_Unicode(cChar) );
745 #endif //OLD_NUMBER_FORMATTING
746 /* -----------------------------22.02.01 13:31--------------------------------
748 ---------------------------------------------------------------------------*/
749 const String& SvxNumberFormat::GetCharFmtName()const
751 return sCharStyleName;
753 /* -----------------27.10.98 10:38-------------------
755 * --------------------------------------------------*/
756 sal_Int32 SvxNumRule::nRefCount = 0;
757 static SvxNumberFormat* pStdNumFmt = 0;
758 static SvxNumberFormat* pStdOutlineNumFmt = 0;
759 // --> OD 2008-02-11 #newlistlevelattrs#
760 SvxNumRule::SvxNumRule( ULONG nFeatures,
761 USHORT nLevels,
762 BOOL bCont,
763 SvxNumRuleType eType,
764 SvxNumberFormat::SvxNumPositionAndSpaceMode
765 eDefaultNumberFormatPositionAndSpaceMode )
766 : nLevelCount(nLevels),
767 nFeatureFlags(nFeatures),
768 eNumberingType(eType),
769 bContinuousNumbering(bCont)
771 ++nRefCount;
772 LanguageType eLang = Application::GetSettings().GetLanguage();
773 aLocale = SvxCreateLocale(eLang);
774 for(USHORT i = 0; i < SVX_MAX_NUM; i++)
776 if(i < nLevels)
778 aFmts[i] = new SvxNumberFormat(SVX_NUM_CHARS_UPPER_LETTER);
779 //daran wird zwischen writer und draw unterschieden
780 if(nFeatures & NUM_CONTINUOUS)
782 // --> OD 2008-02-11 #newlistlevelattrs#
783 if ( eDefaultNumberFormatPositionAndSpaceMode ==
784 SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
786 aFmts[i]->SetLSpace( MM100_TO_TWIP(DEF_WRITER_LSPACE) );
787 aFmts[i]->SetAbsLSpace( MM100_TO_TWIP(DEF_WRITER_LSPACE * (i+1)) );
788 aFmts[i]->SetFirstLineOffset(MM100_TO_TWIP(-DEF_WRITER_LSPACE));
790 else if ( eDefaultNumberFormatPositionAndSpaceMode ==
791 SvxNumberFormat::LABEL_ALIGNMENT )
793 // first line indent of general numbering in inch: -0,25 inch
794 const long cFirstLineIndent = -1440/4;
795 // indent values of general numbering in inch:
796 // 0,5 0,75 1,0 1,25 1,5
797 // 1,75 2,0 2,25 2,5 2,75
798 const long cIndentAt = 1440/4;
799 aFmts[i]->SetPositionAndSpaceMode( SvxNumberFormat::LABEL_ALIGNMENT );
800 aFmts[i]->SetLabelFollowedBy( SvxNumberFormat::LISTTAB );
801 aFmts[i]->SetListtabPos( cIndentAt * (i+2) );
802 aFmts[i]->SetFirstLineIndent( cFirstLineIndent );
803 aFmts[i]->SetIndentAt( cIndentAt * (i+2) );
805 // <--
807 else
809 aFmts[i]->SetLSpace( DEF_DRAW_LSPACE );
810 aFmts[i]->SetAbsLSpace( DEF_DRAW_LSPACE * (i) );
813 else
814 aFmts[i] = 0;
815 aFmtsSet[i] = FALSE;
818 /* -----------------27.10.98 10:41-------------------
820 * --------------------------------------------------*/
821 SvxNumRule::SvxNumRule(const SvxNumRule& rCopy)
823 ++nRefCount;
824 aLocale = rCopy.aLocale;
825 nLevelCount = rCopy.nLevelCount ;
826 nFeatureFlags = rCopy.nFeatureFlags ;
827 bContinuousNumbering = rCopy.bContinuousNumbering;
828 eNumberingType = rCopy.eNumberingType;
829 memset( aFmts, 0, sizeof( aFmts ));
830 for(USHORT i = 0; i < SVX_MAX_NUM; i++)
832 if(rCopy.aFmts[i])
833 aFmts[i] = new SvxNumberFormat(*rCopy.aFmts[i]);
834 else
835 aFmts[i] = 0;
836 aFmtsSet[i] = rCopy.aFmtsSet[i];
839 /* -----------------08.12.98 11:07-------------------
841 * --------------------------------------------------*/
842 //SvxNumRule::SvxNumRule(SvStream &rStream)
844 // ++nRefCount;
845 // LanguageType eLang = Application::GetSettings().GetLanguage();
846 // aLocale = SvxCreateLocale(eLang);
847 // USHORT nVersion;
848 // USHORT nTemp;
849 // rStream >> nVersion;
850 // rStream >> nLevelCount;
851 // rStream >> nTemp;
852 // nFeatureFlags = nTemp;
853 // rStream >> nTemp;
854 // bContinuousNumbering = (BOOL)nTemp;
855 // rStream >> nTemp;
856 // eNumberingType = (SvxNumRuleType)nTemp;
857 // memset( aFmts, 0, sizeof( aFmts ));
859 // for(USHORT i = 0; i < SVX_MAX_NUM; i++)
860 // {
861 // USHORT nSet;
862 // rStream >> nSet;
863 // if(nSet)
864 // aFmts[i] = new SvxNumberFormat(rStream);
865 // else
866 // aFmts[i] = 0;
867 // aFmtsSet[i] = aFmts[i] ? TRUE : FALSE;
868 // }
869 // if(NUMITEM_VERSION_02 <= nVersion)
870 // {
871 // USHORT nShort;
872 // rStream >> nShort;
873 // nFeatureFlags = nShort;
874 // }
877 /* -----------------08.12.98 11:07-------------------
879 * --------------------------------------------------*/
880 // --> OD 2008-01-09 #newlistlevelattrs# - no longer used
881 //SvStream& SvxNumRule::Store(SvStream &rStream)
883 // rStream<<(USHORT)NUMITEM_VERSION_03;
884 // rStream<<nLevelCount;
885 // //first save of nFeatureFlags for old versions
886 // rStream<<(USHORT)nFeatureFlags;
887 // rStream<<(USHORT)bContinuousNumbering;
888 // rStream<<(USHORT)eNumberingType;
890 // FontToSubsFontConverter pConverter = 0;
891 // BOOL bConvertBulletFont = rStream.GetVersion() <= SOFFICE_FILEFORMAT_50;
892 // for(USHORT i = 0; i < SVX_MAX_NUM; i++)
893 // {
894 // if(aFmts[i])
895 // {
896 // rStream << USHORT(1);
897 // if(bConvertBulletFont && aFmts[i]->GetBulletFont())
898 // {
899 // if(!pConverter)
900 // pConverter =
901 // CreateFontToSubsFontConverter(aFmts[i]->GetBulletFont()->GetName(),
902 // FONTTOSUBSFONT_EXPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS);
903 // }
904 // aFmts[i]->Store(rStream, pConverter);
905 // }
906 // else
907 // rStream << USHORT(0);
908 // }
909 // //second save of nFeatureFlags for new versions
910 // rStream<<(USHORT)nFeatureFlags;
911 // if(pConverter)
912 // DestroyFontToSubsFontConverter(pConverter);
914 // return rStream;
917 /* -----------------27.10.98 10:41-------------------
919 * --------------------------------------------------*/
920 SvxNumRule::~SvxNumRule()
922 for(USHORT i = 0; i < SVX_MAX_NUM; i++)
923 delete aFmts[i];
924 if(!--nRefCount)
926 DELETEZ(pStdNumFmt);
927 DELETEZ(pStdOutlineNumFmt);
930 /* -----------------29.10.98 16:07-------------------
932 * --------------------------------------------------*/
933 SvxNumRule& SvxNumRule::operator=( const SvxNumRule& rCopy )
935 nLevelCount = rCopy.nLevelCount;
936 nFeatureFlags = rCopy.nFeatureFlags;
937 bContinuousNumbering = rCopy.bContinuousNumbering;
938 eNumberingType = rCopy.eNumberingType;
939 for(USHORT i = 0; i < SVX_MAX_NUM; i++)
941 delete aFmts[i];
942 if(rCopy.aFmts[i])
943 aFmts[i] = new SvxNumberFormat(*rCopy.aFmts[i]);
944 else
945 aFmts[i] = 0;
946 aFmtsSet[i] = rCopy.aFmtsSet[i];
948 return *this;
950 /* -----------------27.10.98 10:41-------------------
952 * --------------------------------------------------*/
953 int SvxNumRule::operator==( const SvxNumRule& rCopy) const
955 if(nLevelCount != rCopy.nLevelCount ||
956 nFeatureFlags != rCopy.nFeatureFlags ||
957 bContinuousNumbering != rCopy.bContinuousNumbering ||
958 eNumberingType != rCopy.eNumberingType)
959 return FALSE;
960 for(USHORT i = 0; i < nLevelCount; i++)
962 if (
963 (aFmtsSet[i] != rCopy.aFmtsSet[i]) ||
964 (!aFmts[i] && rCopy.aFmts[i]) ||
965 (aFmts[i] && !rCopy.aFmts[i]) ||
966 (aFmts[i] && *aFmts[i] != *rCopy.aFmts[i])
969 return FALSE;
972 return TRUE;
974 /* -----------------27.10.98 10:41-------------------
976 * --------------------------------------------------*/
977 const SvxNumberFormat* SvxNumRule::Get(USHORT nLevel)const
979 DBG_ASSERT(nLevel < SVX_MAX_NUM, "falsches Level" );
980 if( nLevel < SVX_MAX_NUM )
981 return aFmtsSet[nLevel] ? aFmts[nLevel] : 0;
982 else
983 return 0;
985 /* -----------------02.11.98 09:10-------------------
987 * --------------------------------------------------*/
988 const SvxNumberFormat& SvxNumRule::GetLevel(USHORT nLevel)const
990 if(!pStdNumFmt)
992 pStdNumFmt = new SvxNumberFormat(SVX_NUM_ARABIC);
993 pStdOutlineNumFmt = new SvxNumberFormat(SVX_NUM_NUMBER_NONE);
996 DBG_ASSERT(nLevel < SVX_MAX_NUM, "falsches Level" );
998 return ( ( nLevel < SVX_MAX_NUM ) && aFmts[nLevel] ) ?
999 *aFmts[nLevel] : eNumberingType == SVX_RULETYPE_NUMBERING ?
1000 *pStdNumFmt : *pStdOutlineNumFmt;
1003 /* -----------------29.10.98 09:08-------------------
1005 * --------------------------------------------------*/
1006 void SvxNumRule::SetLevel( USHORT i, const SvxNumberFormat& rNumFmt, BOOL bIsValid )
1008 DBG_ASSERT(i < SVX_MAX_NUM, "falsches Level" );
1010 if( (i < SVX_MAX_NUM) && (!aFmtsSet[i] || !(rNumFmt == *Get( i ))) )
1012 delete aFmts[ i ];
1013 aFmts[ i ] = new SvxNumberFormat( rNumFmt );
1014 aFmtsSet[i] = bIsValid;
1015 // bInvalidRuleFlag = TRUE;
1018 /* -----------------30.10.98 12:44-------------------
1020 * --------------------------------------------------*/
1021 void SvxNumRule::SetLevel(USHORT nLevel, const SvxNumberFormat* pFmt)
1023 DBG_ASSERT(nLevel < SVX_MAX_NUM, "falsches Level" );
1025 if( nLevel < SVX_MAX_NUM )
1027 aFmtsSet[nLevel] = 0 != pFmt;
1028 if(pFmt)
1029 SetLevel(nLevel, *pFmt);
1030 else
1032 delete aFmts[nLevel];
1033 aFmts[nLevel] = 0;
1037 /* -----------------28.10.98 15:38-------------------
1039 * --------------------------------------------------*/
1040 String SvxNumRule::MakeNumString( const SvxNodeNum& rNum, BOOL bInclStrings ) const
1042 String aStr;
1043 if( SVX_NO_NUM > rNum.GetLevel() && !( SVX_NO_NUMLEVEL & rNum.GetLevel() ) )
1045 const SvxNumberFormat& rMyNFmt = GetLevel( rNum.GetLevel() );
1046 if( SVX_NUM_NUMBER_NONE != rMyNFmt.GetNumberingType() )
1048 BYTE i = rNum.GetLevel();
1050 if( !IsContinuousNumbering() &&
1051 1 < rMyNFmt.GetIncludeUpperLevels() ) // nur der eigene Level ?
1053 BYTE n = rMyNFmt.GetIncludeUpperLevels();
1054 if( 1 < n )
1056 if( i+1 >= n )
1057 i -= n - 1;
1058 else
1059 i = 0;
1063 for( ; i <= rNum.GetLevel(); ++i )
1065 const SvxNumberFormat& rNFmt = GetLevel( i );
1066 if( SVX_NUM_NUMBER_NONE == rNFmt.GetNumberingType() )
1068 // Soll aus 1.1.1 --> 2. NoNum --> 1..1 oder 1.1 ??
1069 // if( i != rNum.nMyLevel )
1070 // aStr += aDotStr;
1071 continue;
1074 sal_Bool bDot = sal_True;
1075 if( rNum.GetLevelVal()[ i ] )
1077 if(SVX_NUM_BITMAP != rNFmt.GetNumberingType())
1078 aStr += rNFmt.GetNumStr( rNum.GetLevelVal()[ i ], aLocale );
1079 else
1080 bDot = sal_False;
1082 else
1083 aStr += sal_Unicode('0'); // alle 0-Level sind eine 0
1084 if( i != rNum.GetLevel() && bDot)
1085 aStr += sal_Unicode('.');
1089 if( bInclStrings )
1091 aStr.Insert( rMyNFmt.GetPrefix(), 0 );
1092 aStr += rMyNFmt.GetSuffix();
1095 return aStr;
1097 /* -----------------18.08.99 10:18-------------------
1098 Description: changes linked to embedded bitmaps
1099 --------------------------------------------------*/
1100 BOOL SvxNumRule::UnLinkGraphics()
1102 BOOL bRet = FALSE;
1103 for(USHORT i = 0; i < GetLevelCount(); i++)
1105 SvxNumberFormat aFmt(GetLevel(i));
1106 const SvxBrushItem* pBrush = aFmt.GetBrush();
1107 const String* pLinkStr;
1108 const Graphic* pGraphic;
1109 if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
1111 if(pBrush &&
1112 0 != (pLinkStr = pBrush->GetGraphicLink()) &&
1113 pLinkStr->Len() &&
1114 0 !=(pGraphic = pBrush->GetGraphic()))
1116 SvxBrushItem aTempItem(*pBrush);
1117 aTempItem.SetGraphicLink( String());
1118 aTempItem.SetGraphic(*pGraphic);
1119 sal_Int16 eOrient = aFmt.GetVertOrient();
1120 aFmt.SetGraphicBrush( &aTempItem, &aFmt.GetGraphicSize(), &eOrient );
1121 bRet = TRUE;
1124 else if((SVX_NUM_BITMAP|LINK_TOKEN) == aFmt.GetNumberingType())
1125 aFmt.SetNumberingType(SVX_NUM_BITMAP);
1126 SetLevel(i, aFmt);
1128 return bRet;
1131 /* -----------------27.10.98 10:41-------------------
1133 * --------------------------------------------------*/
1134 SvxNumBulletItem::SvxNumBulletItem(SvxNumRule& rRule) :
1135 SfxPoolItem(SID_ATTR_NUMBERING_RULE),
1136 pNumRule(new SvxNumRule(rRule))
1140 /*-----------------23.11.98 10:36-------------------
1141 MT: Das sind ja sehr sinnige Kommentare...
1142 --------------------------------------------------*/
1143 SvxNumBulletItem::SvxNumBulletItem(SvxNumRule& rRule, USHORT _nWhich ) :
1144 SfxPoolItem(_nWhich),
1145 pNumRule(new SvxNumRule(rRule))
1149 /* -----------------27.10.98 10:41-------------------
1151 * --------------------------------------------------*/
1152 SvxNumBulletItem::SvxNumBulletItem(const SvxNumBulletItem& rCopy) :
1153 SfxPoolItem(rCopy.Which())
1155 pNumRule = new SvxNumRule(*rCopy.pNumRule);
1157 /* -----------------27.10.98 10:41-------------------
1159 * --------------------------------------------------*/
1160 SvxNumBulletItem::~SvxNumBulletItem()
1162 delete pNumRule;
1165 /* -----------------27.10.98 10:41-------------------
1167 * --------------------------------------------------*/
1168 int SvxNumBulletItem::operator==( const SfxPoolItem& rCopy) const
1170 return *pNumRule == *((SvxNumBulletItem&)rCopy).pNumRule;
1172 /* -----------------27.10.98 10:41-------------------
1174 * --------------------------------------------------*/
1175 SfxPoolItem* SvxNumBulletItem::Clone( SfxItemPool * ) const
1177 return new SvxNumBulletItem(*this);
1179 /* -----------------08.12.98 10:43-------------------
1181 * --------------------------------------------------*/
1182 // --> OD 2008-01-09 #newlistlevelattrs# - no longer used
1183 //SfxPoolItem* SvxNumBulletItem::Create(SvStream &rStream, USHORT) const
1185 // SvxNumRule aRule(rStream);
1186 // return new SvxNumBulletItem(aRule, Which() );
1188 // <--
1189 /* -----------------08.12.98 10:43-------------------
1191 * --------------------------------------------------*/
1192 // --> OD 2008-01-09 #newlistlevelattrs# - no longer used
1193 //SvStream& SvxNumBulletItem::Store(SvStream &rStream, USHORT /*nItemVersion*/ )const
1195 // pNumRule->Store(rStream);
1196 // return rStream;
1198 // <--
1199 /* -----------------08.12.98 10:43-------------------
1201 * --------------------------------------------------*/
1202 // --> OD 2008-01-10 #newlistlevelattrs# - no longer used
1203 //USHORT SvxNumBulletItem::GetVersion( USHORT /*nFileVersion*/ ) const
1205 // return NUMITEM_VERSION_03;
1207 // <--
1209 /* -----------------08.12.98 10:43-------------------
1211 * --------------------------------------------------*/
1213 sal_Bool SvxNumBulletItem::QueryValue( com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ ) const
1215 rVal <<= SvxCreateNumRule( pNumRule );
1216 return sal_True;
1219 sal_Bool SvxNumBulletItem::PutValue( const com::sun::star::uno::Any& rVal, BYTE /*nMemberId*/ )
1221 uno::Reference< container::XIndexReplace > xRule;
1222 if( rVal >>= xRule )
1226 SvxNumRule* pNewRule = new SvxNumRule( SvxGetNumRule( xRule ) );
1227 if( pNewRule->GetLevelCount() != pNumRule->GetLevelCount() ||
1228 pNewRule->GetNumRuleType() != pNumRule->GetNumRuleType() )
1230 SvxNumRule* pConverted = SvxConvertNumRule( pNewRule, pNumRule->GetLevelCount(), pNumRule->GetNumRuleType() );
1231 delete pNewRule;
1232 pNewRule = pConverted;
1234 delete pNumRule;
1235 pNumRule = pNewRule;
1236 return sal_True;
1238 catch(lang::IllegalArgumentException&)
1242 return sal_False;
1245 /* -----------------08.12.98 10:43-------------------
1247 * --------------------------------------------------*/
1248 SvxNumRule* SvxConvertNumRule( const SvxNumRule* pRule, USHORT nLevels, SvxNumRuleType eType )
1250 const USHORT nSrcLevels = pRule->GetLevelCount();
1251 SvxNumRule* pNewRule = new SvxNumRule( pRule->GetFeatureFlags(), nLevels, pRule->IsContinuousNumbering(), eType );
1253 for( USHORT nLevel = 0; (nLevel < nLevels) && (nLevel < nSrcLevels); nLevel++ )
1254 pNewRule->SetLevel( nLevel, pRule->GetLevel( nLevel ) );
1256 return pNewRule;