Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <editeng/numitem.hxx>
22 :
23 : #include <com/sun/star/text/HoriOrientation.hpp>
24 : #include <com/sun/star/text/VertOrientation.hpp>
25 : #include <com/sun/star/text/RelOrientation.hpp>
26 : #include <editeng/brushitem.hxx>
27 : #include <vcl/font.hxx>
28 : #include <vcl/settings.hxx>
29 : #include <editeng/editids.hrc>
30 : #include <editeng/editrids.hrc>
31 : #include <editeng/numdef.hxx>
32 : #include <editeng/eeitem.hxx>
33 : #include <vcl/graph.hxx>
34 : #include <vcl/window.hxx>
35 : #include <vcl/svapp.hxx>
36 : #include <editeng/unolingu.hxx>
37 : #include <com/sun/star/text/XNumberingFormatter.hpp>
38 : #include <com/sun/star/text/DefaultNumberingProvider.hpp>
39 : #include <com/sun/star/text/XDefaultNumberingProvider.hpp>
40 : #include <com/sun/star/style/NumberingType.hpp>
41 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 : #include <com/sun/star/beans/PropertyValue.hpp>
43 : #include <comphelper/processfactory.hxx>
44 :
45 : #include <editeng/unonrule.hxx>
46 :
47 : #define MM100_TO_TWIP(MM100) ((MM100*72L+63L)/127L)
48 :
49 : #define DEF_WRITER_LSPACE 500 //Standard Indentation
50 : #define DEF_DRAW_LSPACE 800 //Standard Indentation
51 :
52 : #define NUMITEM_VERSION_03 0x03
53 : #define NUMITEM_VERSION_04 0x04
54 :
55 : using namespace ::com::sun::star;
56 : using namespace ::com::sun::star::lang;
57 : using namespace ::com::sun::star::uno;
58 : using namespace ::com::sun::star::text;
59 : using namespace ::com::sun::star::beans;
60 : using namespace ::com::sun::star::style;
61 :
62 : sal_Int32 SvxNumberType::nRefCount = 0;
63 102 : com::sun::star::uno::Reference<com::sun::star::text::XNumberingFormatter> SvxNumberType::xFormatter = 0;
64 6292 : static void lcl_getFormatter(com::sun::star::uno::Reference<com::sun::star::text::XNumberingFormatter>& _xFormatter)
65 : {
66 6292 : if(!_xFormatter.is())
67 : {
68 : try
69 : {
70 32 : Reference<XComponentContext> xContext( ::comphelper::getProcessComponentContext() );
71 64 : Reference<XDefaultNumberingProvider> xRet = text::DefaultNumberingProvider::create(xContext);
72 64 : _xFormatter = Reference<XNumberingFormatter> (xRet, UNO_QUERY);
73 : }
74 0 : catch(const Exception&)
75 : {
76 : SAL_WARN("editeng", "service missing: \"com.sun.star.text.DefaultNumberingProvider\"");
77 : }
78 : }
79 6292 : }
80 :
81 1657081 : SvxNumberType::SvxNumberType(sal_Int16 nType) :
82 : nNumType(nType),
83 1657081 : bShowSymbol(true)
84 : {
85 1657081 : nRefCount++;
86 1657081 : }
87 :
88 14087085 : SvxNumberType::SvxNumberType(const SvxNumberType& rType) :
89 : nNumType(rType.nNumType),
90 14087085 : bShowSymbol(rType.bShowSymbol)
91 : {
92 14087085 : nRefCount++;
93 14087085 : }
94 :
95 15742551 : SvxNumberType::~SvxNumberType()
96 : {
97 15742551 : if(!--nRefCount)
98 66 : xFormatter = 0;
99 15742551 : }
100 :
101 6292 : OUString SvxNumberType::GetNumStr( sal_uLong nNo ) const
102 : {
103 6292 : const LanguageTag& rLang = Application::GetSettings().GetLanguageTag();
104 6292 : return GetNumStr( nNo, rLang.getLocale() );
105 : }
106 :
107 6292 : OUString SvxNumberType::GetNumStr( sal_uLong nNo, const Locale& rLocale ) const
108 : {
109 6292 : lcl_getFormatter(xFormatter);
110 6292 : if(!xFormatter.is())
111 0 : return OUString();
112 :
113 6292 : if(bShowSymbol)
114 : {
115 6292 : switch(nNumType)
116 : {
117 : case NumberingType::CHAR_SPECIAL:
118 : case NumberingType::BITMAP:
119 0 : break;
120 : default:
121 : {
122 : // '0' allowed for ARABIC numberings
123 6292 : if(NumberingType::ARABIC == nNumType && 0 == nNo )
124 957 : return OUString('0');
125 : else
126 : {
127 5335 : Sequence< PropertyValue > aProperties(2);
128 5335 : PropertyValue* pValues = aProperties.getArray();
129 5335 : pValues[0].Name = "NumberingType";
130 5335 : pValues[0].Value <<= nNumType;
131 5335 : pValues[1].Name = "Value";
132 5335 : pValues[1].Value <<= (sal_Int32)nNo;
133 :
134 : try
135 : {
136 5335 : return xFormatter->makeNumberingString( aProperties, rLocale );
137 : }
138 0 : catch(const Exception&)
139 : {
140 0 : }
141 : }
142 : }
143 : }
144 : }
145 0 : return OUString();
146 : }
147 :
148 1644000 : SvxNumberFormat::SvxNumberFormat( sal_Int16 eType,
149 : SvxNumPositionAndSpaceMode ePositionAndSpaceMode )
150 : : SvxNumberType(eType),
151 : eNumAdjust(SVX_ADJUST_LEFT),
152 : nInclUpperLevels(0),
153 : nStart(1),
154 : cBullet(SVX_DEF_BULLET),
155 : nBulletRelSize(100),
156 : nBulletColor(COL_BLACK),
157 : mePositionAndSpaceMode( ePositionAndSpaceMode ),
158 : nFirstLineOffset(0),
159 : nAbsLSpace(0),
160 : nLSpace(0),
161 : nCharTextDistance(0),
162 : meLabelFollowedBy( LISTTAB ),
163 : mnListtabPos( 0 ),
164 : mnFirstLineIndent( 0 ),
165 : mnIndentAt( 0 ),
166 : pGraphicBrush(0),
167 : eVertOrient(text::VertOrientation::NONE),
168 1644000 : pBulletFont(0)
169 : {
170 1644000 : }
171 :
172 14080028 : SvxNumberFormat::SvxNumberFormat(const SvxNumberFormat& rFormat) :
173 : SvxNumberType(rFormat),
174 : mePositionAndSpaceMode( rFormat.mePositionAndSpaceMode ),
175 : pGraphicBrush(0),
176 14080028 : pBulletFont(0)
177 : {
178 14080028 : *this = rFormat;
179 14080028 : }
180 :
181 0 : SvxNumberFormat::SvxNumberFormat( SvStream &rStream )
182 : {
183 : sal_uInt16 nTmp16;
184 : sal_Int32 nTmp32;
185 0 : rStream.ReadUInt16( nTmp16 ); // Version number
186 :
187 0 : rStream.ReadUInt16( nTmp16 ); SetNumberingType( nTmp16 );
188 0 : rStream.ReadUInt16( nTmp16 ); eNumAdjust = ( SvxAdjust )nTmp16;
189 0 : rStream.ReadUInt16( nTmp16 ); nInclUpperLevels = nTmp16;
190 0 : rStream.ReadUInt16( nStart );
191 0 : rStream.ReadUInt16( nTmp16 ); cBullet = (sal_Unicode)nTmp16;
192 :
193 0 : rStream.ReadInt16( nFirstLineOffset );
194 0 : rStream.ReadInt16( nAbsLSpace );
195 0 : rStream.ReadInt16( nLSpace );
196 :
197 0 : rStream.ReadInt16( nCharTextDistance );
198 :
199 0 : sPrefix = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
200 0 : sSuffix = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
201 0 : sCharStyleName = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
202 :
203 0 : sal_uInt16 hasGraphicBrush = 0;
204 0 : rStream.ReadUInt16( hasGraphicBrush );
205 0 : if ( hasGraphicBrush )
206 : {
207 0 : pGraphicBrush = new SvxBrushItem( SID_ATTR_BRUSH );
208 0 : pGraphicBrush = (SvxBrushItem*)(pGraphicBrush->Create( rStream, BRUSH_GRAPHIC_VERSION ));
209 : }
210 0 : else pGraphicBrush = 0;
211 0 : rStream.ReadUInt16( nTmp16 ); eVertOrient = nTmp16;
212 :
213 0 : sal_uInt16 hasBulletFont = 0;
214 0 : rStream.ReadUInt16( hasBulletFont );
215 0 : if ( hasBulletFont )
216 : {
217 0 : pBulletFont = new Font( );
218 0 : ReadFont( rStream, *pBulletFont );
219 : }
220 0 : else pBulletFont = NULL;
221 0 : ReadPair( rStream, aGraphicSize );
222 :
223 0 : ReadColor( rStream, nBulletColor );
224 0 : rStream.ReadUInt16( nBulletRelSize );
225 0 : rStream.ReadUInt16( nTmp16 ); SetShowSymbol( nTmp16 );
226 :
227 0 : rStream.ReadUInt16( nTmp16 ); mePositionAndSpaceMode = ( SvxNumPositionAndSpaceMode )nTmp16;
228 0 : rStream.ReadUInt16( nTmp16 ); meLabelFollowedBy = ( LabelFollowedBy )nTmp16;
229 0 : rStream.ReadInt32( nTmp32 ); mnListtabPos = nTmp32;
230 0 : rStream.ReadInt32( nTmp32 ); mnFirstLineIndent = nTmp32;
231 0 : rStream.ReadInt32( nTmp32 ); mnIndentAt = nTmp32;
232 :
233 0 : }
234 39689795 : SvxNumberFormat::~SvxNumberFormat()
235 : {
236 15722429 : delete pGraphicBrush;
237 15722429 : delete pBulletFont;
238 23967366 : }
239 :
240 0 : SvStream& SvxNumberFormat::Store(SvStream &rStream, FontToSubsFontConverter pConverter)
241 : {
242 0 : if(pConverter && pBulletFont)
243 : {
244 0 : cBullet = ConvertFontToSubsFontChar(pConverter, cBullet);
245 0 : OUString sFontName = GetFontToSubsFontName(pConverter);
246 0 : pBulletFont->SetName(sFontName);
247 : }
248 :
249 0 : rStream.WriteUInt16( (sal_uInt16)NUMITEM_VERSION_04 );
250 :
251 0 : rStream.WriteUInt16( (sal_uInt16)GetNumberingType() );
252 0 : rStream.WriteUInt16( (sal_uInt16)eNumAdjust );
253 0 : rStream.WriteUInt16( (sal_uInt16)nInclUpperLevels );
254 0 : rStream.WriteUInt16( nStart );
255 0 : rStream.WriteUInt16( (sal_uInt16)cBullet );
256 :
257 0 : rStream.WriteInt16( nFirstLineOffset );
258 0 : rStream.WriteInt16( nAbsLSpace );
259 0 : rStream.WriteInt16( nLSpace );
260 :
261 0 : rStream.WriteInt16( nCharTextDistance );
262 0 : rtl_TextEncoding eEnc = osl_getThreadTextEncoding();
263 0 : rStream.WriteUniOrByteString(sPrefix, eEnc);
264 0 : rStream.WriteUniOrByteString(sSuffix, eEnc);
265 0 : rStream.WriteUniOrByteString(sCharStyleName, eEnc);
266 0 : if(pGraphicBrush)
267 : {
268 0 : rStream.WriteUInt16( (sal_uInt16)1 );
269 :
270 : // in SD or SI force bullet itself to be stored,
271 : // for that purpose throw away link when link and graphic
272 : // are present, so Brush save is forced
273 0 : if(!pGraphicBrush->GetGraphicLink().isEmpty() && pGraphicBrush->GetGraphic())
274 : {
275 0 : pGraphicBrush->SetGraphicLink("");
276 : }
277 :
278 0 : pGraphicBrush->Store(rStream, BRUSH_GRAPHIC_VERSION);
279 : }
280 : else
281 0 : rStream.WriteUInt16( (sal_uInt16)0 );
282 :
283 0 : rStream.WriteUInt16( (sal_uInt16)eVertOrient );
284 0 : if(pBulletFont)
285 : {
286 0 : rStream.WriteUInt16( (sal_uInt16)1 );
287 0 : WriteFont( rStream, *pBulletFont );
288 : }
289 : else
290 0 : rStream.WriteUInt16( (sal_uInt16)0 );
291 0 : WritePair( rStream, aGraphicSize );
292 :
293 0 : Color nTempColor = nBulletColor;
294 0 : if(COL_AUTO == nBulletColor.GetColor())
295 0 : nTempColor = COL_BLACK;
296 0 : WriteColor( rStream, nTempColor );
297 0 : rStream.WriteUInt16( nBulletRelSize );
298 0 : rStream.WriteUInt16( (sal_uInt16)IsShowSymbol() );
299 :
300 0 : rStream.WriteUInt16( ( sal_uInt16 ) mePositionAndSpaceMode );
301 0 : rStream.WriteUInt16( ( sal_uInt16 ) meLabelFollowedBy );
302 0 : rStream.WriteInt32( ( sal_Int32 ) mnListtabPos );
303 0 : rStream.WriteInt32( ( sal_Int32 ) mnFirstLineIndent );
304 0 : rStream.WriteInt32( ( sal_Int32 ) mnIndentAt );
305 :
306 0 : return rStream;
307 : }
308 :
309 14084679 : SvxNumberFormat& SvxNumberFormat::operator=( const SvxNumberFormat& rFormat )
310 : {
311 14084679 : if (& rFormat == this) { return *this; }
312 :
313 14084679 : SetNumberingType(rFormat.GetNumberingType());
314 14084679 : eNumAdjust = rFormat.eNumAdjust ;
315 14084679 : nInclUpperLevels = rFormat.nInclUpperLevels ;
316 14084679 : nStart = rFormat.nStart ;
317 14084679 : cBullet = rFormat.cBullet ;
318 14084679 : mePositionAndSpaceMode = rFormat.mePositionAndSpaceMode;
319 14084679 : nFirstLineOffset = rFormat.nFirstLineOffset;
320 14084679 : nAbsLSpace = rFormat.nAbsLSpace ;
321 14084679 : nLSpace = rFormat.nLSpace ;
322 14084679 : nCharTextDistance = rFormat.nCharTextDistance ;
323 14084679 : meLabelFollowedBy = rFormat.meLabelFollowedBy;
324 14084679 : mnListtabPos = rFormat.mnListtabPos;
325 14084679 : mnFirstLineIndent = rFormat.mnFirstLineIndent;
326 14084679 : mnIndentAt = rFormat.mnIndentAt;
327 14084679 : eVertOrient = rFormat.eVertOrient ;
328 14084679 : sPrefix = rFormat.sPrefix ;
329 14084679 : sSuffix = rFormat.sSuffix ;
330 14084679 : aGraphicSize = rFormat.aGraphicSize ;
331 14084679 : nBulletColor = rFormat.nBulletColor ;
332 14084679 : nBulletRelSize = rFormat.nBulletRelSize;
333 14084679 : SetShowSymbol(rFormat.IsShowSymbol());
334 14084679 : sCharStyleName = rFormat.sCharStyleName;
335 14084679 : DELETEZ(pGraphicBrush);
336 14084679 : if(rFormat.pGraphicBrush)
337 : {
338 400 : pGraphicBrush = new SvxBrushItem(*rFormat.pGraphicBrush);
339 400 : pGraphicBrush->SetDoneLink( STATIC_LINK( this, SvxNumberFormat, GraphicArrived) );
340 : }
341 14084679 : DELETEZ(pBulletFont);
342 14084679 : if(rFormat.pBulletFont)
343 174473 : pBulletFont = new Font(*rFormat.pBulletFont);
344 14084679 : return *this;
345 : }
346 :
347 4529794 : bool SvxNumberFormat::operator==( const SvxNumberFormat& rFormat) const
348 : {
349 13447978 : if( GetNumberingType() != rFormat.GetNumberingType() ||
350 8776770 : eNumAdjust != rFormat.eNumAdjust ||
351 8775958 : nInclUpperLevels != rFormat.nInclUpperLevels ||
352 8775074 : nStart != rFormat.nStart ||
353 8772459 : cBullet != rFormat.cBullet ||
354 8769835 : mePositionAndSpaceMode != rFormat.mePositionAndSpaceMode ||
355 8769457 : nFirstLineOffset != rFormat.nFirstLineOffset ||
356 8769099 : nAbsLSpace != rFormat.nAbsLSpace ||
357 8769028 : nLSpace != rFormat.nLSpace ||
358 8769028 : nCharTextDistance != rFormat.nCharTextDistance ||
359 8769015 : meLabelFollowedBy != rFormat.meLabelFollowedBy ||
360 8767074 : mnListtabPos != rFormat.mnListtabPos ||
361 8765136 : mnFirstLineIndent != rFormat.mnFirstLineIndent ||
362 8765124 : mnIndentAt != rFormat.mnIndentAt ||
363 8765122 : eVertOrient != rFormat.eVertOrient ||
364 8765116 : sPrefix != rFormat.sPrefix ||
365 8765104 : sSuffix != rFormat.sSuffix ||
366 8765098 : aGraphicSize != rFormat.aGraphicSize ||
367 8759464 : nBulletColor != rFormat.nBulletColor ||
368 8752920 : nBulletRelSize != rFormat.nBulletRelSize ||
369 13281804 : IsShowSymbol() != rFormat.IsShowSymbol() ||
370 4376005 : sCharStyleName != rFormat.sCharStyleName
371 : )
372 163098 : return false;
373 4366696 : if (
374 4366820 : (pGraphicBrush && !rFormat.pGraphicBrush) ||
375 13099964 : (!pGraphicBrush && rFormat.pGraphicBrush) ||
376 124 : (pGraphicBrush && *pGraphicBrush != *rFormat.pGraphicBrush)
377 : )
378 : {
379 0 : return false;
380 : }
381 4366696 : if (
382 4417239 : (pBulletFont && !rFormat.pBulletFont) ||
383 13050389 : (!pBulletFont && rFormat.pBulletFont) ||
384 50543 : (pBulletFont && *pBulletFont != *rFormat.pBulletFont)
385 : )
386 : {
387 1488 : return false;
388 : }
389 4365208 : return true;
390 : }
391 :
392 5962132 : void SvxNumberFormat::SetGraphicBrush( const SvxBrushItem* pBrushItem,
393 : const Size* pSize, const sal_Int16* pOrient)
394 : {
395 5962132 : if(!pBrushItem)
396 : {
397 5961854 : delete pGraphicBrush;
398 5961854 : pGraphicBrush = 0;
399 : }
400 278 : else if ( !pGraphicBrush || (pGraphicBrush && !(*pBrushItem == *pGraphicBrush)) )
401 : {
402 24 : delete pGraphicBrush;
403 24 : pGraphicBrush = (SvxBrushItem*)pBrushItem->Clone();
404 24 : pGraphicBrush->SetDoneLink( STATIC_LINK( this, SvxNumberFormat, GraphicArrived) );
405 : }
406 :
407 5962132 : if(pOrient)
408 5962108 : eVertOrient = *pOrient;
409 : else
410 24 : eVertOrient = text::VertOrientation::NONE;
411 5962132 : if(pSize)
412 5962132 : aGraphicSize = *pSize;
413 : else
414 0 : aGraphicSize.Width() = aGraphicSize.Height() = 0;
415 5962132 : }
416 :
417 0 : void SvxNumberFormat::SetGraphic( const OUString& rName )
418 : {
419 0 : if( pGraphicBrush && pGraphicBrush->GetGraphicLink() == rName )
420 0 : return ;
421 :
422 0 : delete pGraphicBrush;
423 0 : pGraphicBrush = new SvxBrushItem( rName, "", GPOS_AREA, 0 );
424 0 : pGraphicBrush->SetDoneLink( STATIC_LINK( this, SvxNumberFormat, GraphicArrived) );
425 0 : if( eVertOrient == text::VertOrientation::NONE )
426 0 : eVertOrient = text::VertOrientation::TOP;
427 :
428 0 : aGraphicSize.Width() = aGraphicSize.Height() = 0;
429 : }
430 :
431 0 : void SvxNumberFormat::SetVertOrient(sal_Int16 eSet)
432 : {
433 0 : eVertOrient = eSet;
434 0 : }
435 :
436 11924380 : sal_Int16 SvxNumberFormat::GetVertOrient() const
437 : {
438 11924380 : return eVertOrient;
439 : }
440 :
441 14364 : void SvxNumberFormat::SetBulletFont(const Font* pFont)
442 : {
443 14364 : delete pBulletFont;
444 14364 : pBulletFont = pFont ? new Font(*pFont): 0;
445 14364 : }
446 :
447 86087 : SvxNumberFormat::SvxNumPositionAndSpaceMode SvxNumberFormat::GetPositionAndSpaceMode() const
448 : {
449 86087 : return mePositionAndSpaceMode;
450 : }
451 48705 : void SvxNumberFormat::SetPositionAndSpaceMode( SvxNumPositionAndSpaceMode ePositionAndSpaceMode )
452 : {
453 48705 : mePositionAndSpaceMode = ePositionAndSpaceMode;
454 48705 : }
455 :
456 0 : short SvxNumberFormat::GetLSpace() const
457 : {
458 0 : return mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION ? nLSpace : 0;
459 : }
460 10943 : short SvxNumberFormat::GetAbsLSpace() const
461 : {
462 10943 : return mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION
463 : ? nAbsLSpace
464 10943 : : static_cast<short>( GetFirstLineIndent() + GetIndentAt() );
465 : }
466 16639 : short SvxNumberFormat::GetFirstLineOffset() const
467 : {
468 16639 : return mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION
469 : ? nFirstLineOffset
470 16639 : : static_cast<short>( GetFirstLineIndent() );
471 : }
472 4259 : short SvxNumberFormat::GetCharTextDistance() const
473 : {
474 4259 : return mePositionAndSpaceMode == LABEL_WIDTH_AND_POSITION ? nCharTextDistance : 0;
475 : }
476 :
477 50911 : void SvxNumberFormat::SetLabelFollowedBy( const LabelFollowedBy eLabelFollowedBy )
478 : {
479 50911 : meLabelFollowedBy = eLabelFollowedBy;
480 50911 : }
481 12134 : SvxNumberFormat::LabelFollowedBy SvxNumberFormat::GetLabelFollowedBy() const
482 : {
483 12134 : return meLabelFollowedBy;
484 : }
485 50965 : void SvxNumberFormat::SetListtabPos( const long nListtabPos )
486 : {
487 50965 : mnListtabPos = nListtabPos;
488 50965 : }
489 7700 : long SvxNumberFormat::GetListtabPos() const
490 : {
491 7700 : return mnListtabPos;
492 : }
493 51167 : void SvxNumberFormat::SetFirstLineIndent( const long nFirstLineIndent )
494 : {
495 51167 : mnFirstLineIndent = nFirstLineIndent;
496 51167 : }
497 25721 : long SvxNumberFormat::GetFirstLineIndent() const
498 : {
499 25721 : return mnFirstLineIndent;
500 : }
501 50123 : void SvxNumberFormat::SetIndentAt( const long nIndentAt )
502 : {
503 50123 : mnIndentAt = nIndentAt;
504 50123 : }
505 20388 : long SvxNumberFormat::GetIndentAt() const
506 : {
507 20388 : return mnIndentAt;
508 : }
509 :
510 0 : IMPL_STATIC_LINK( SvxNumberFormat, GraphicArrived, void *, EMPTYARG )
511 : {
512 : // if necessary, set the GrfSize:
513 0 : if( !pThis->aGraphicSize.Width() || !pThis->aGraphicSize.Height() )
514 : {
515 0 : const Graphic* pGrf = pThis->pGraphicBrush->GetGraphic();
516 0 : if( pGrf )
517 0 : pThis->aGraphicSize = SvxNumberFormat::GetGraphicSizeMM100( pGrf );
518 : }
519 0 : pThis->NotifyGraphicArrived();
520 0 : return 0;
521 : }
522 :
523 0 : void SvxNumberFormat::NotifyGraphicArrived()
524 : {
525 0 : }
526 :
527 0 : Size SvxNumberFormat::GetGraphicSizeMM100(const Graphic* pGraphic)
528 : {
529 0 : const MapMode aMapMM100( MAP_100TH_MM );
530 0 : const Size& rSize = pGraphic->GetPrefSize();
531 0 : Size aRetSize;
532 0 : if ( pGraphic->GetPrefMapMode().GetMapUnit() == MAP_PIXEL )
533 : {
534 0 : OutputDevice* pOutDev = Application::GetDefaultDevice();
535 0 : MapMode aOldMap( pOutDev->GetMapMode() );
536 0 : pOutDev->SetMapMode( aMapMM100 );
537 0 : aRetSize = pOutDev->PixelToLogic( rSize );
538 0 : pOutDev->SetMapMode( aOldMap );
539 : }
540 : else
541 0 : aRetSize = OutputDevice::LogicToLogic( rSize, pGraphic->GetPrefMapMode(), aMapMM100 );
542 0 : return aRetSize;
543 : }
544 :
545 0 : OUString SvxNumberFormat::CreateRomanString( sal_uLong nNo, bool bUpper )
546 : {
547 0 : nNo %= 4000; // more can not be displayed
548 : // i, ii, iii, iv, v, vi, vii, vii, viii, ix
549 : // (Dummy),1000,500,100,50,10,5,1
550 : const char *cRomanArr = bUpper
551 : ? "MDCLXVI--" // +2 Dummy entries!
552 0 : : "mdclxvi--"; // +2 Dummy entries!
553 :
554 0 : OUString sRet;
555 0 : sal_uInt16 nMask = 1000;
556 0 : while( nMask )
557 : {
558 0 : sal_uInt8 nZahl = sal_uInt8(nNo / nMask);
559 0 : sal_uInt8 nDiff = 1;
560 0 : nNo %= nMask;
561 :
562 0 : if( 5 < nZahl )
563 : {
564 0 : if( nZahl < 9 )
565 0 : sRet += OUString(*(cRomanArr-1));
566 0 : ++nDiff;
567 0 : nZahl -= 5;
568 : }
569 0 : switch( nZahl )
570 : {
571 0 : case 3: { sRet += OUString(*cRomanArr); }
572 0 : case 2: { sRet += OUString(*cRomanArr); }
573 0 : case 1: { sRet += OUString(*cRomanArr); }
574 0 : break;
575 :
576 : case 4: {
577 0 : sRet += OUString(*cRomanArr);
578 0 : sRet += OUString(*(cRomanArr-nDiff));
579 : }
580 0 : break;
581 0 : case 5: { sRet += OUString(*(cRomanArr-nDiff)); }
582 0 : break;
583 : }
584 :
585 0 : nMask /= 10; // for the next decade
586 0 : cRomanArr += 2;
587 : }
588 0 : return sRet;
589 : }
590 :
591 1436860 : OUString SvxNumberFormat::GetCharFmtName()const
592 : {
593 1436860 : return sCharStyleName;
594 : }
595 :
596 : sal_Int32 SvxNumRule::nRefCount = 0;
597 : static SvxNumberFormat* pStdNumFmt = 0;
598 : static SvxNumberFormat* pStdOutlineNumFmt = 0;
599 157575 : SvxNumRule::SvxNumRule( sal_uLong nFeatures,
600 : sal_uInt16 nLevels,
601 : bool bCont,
602 : SvxNumRuleType eType,
603 : SvxNumberFormat::SvxNumPositionAndSpaceMode
604 : eDefaultNumberFormatPositionAndSpaceMode )
605 : : nLevelCount(nLevels),
606 : nFeatureFlags(nFeatures),
607 : eNumberingType(eType),
608 157575 : bContinuousNumbering(bCont)
609 : {
610 157575 : ++nRefCount;
611 1733325 : for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++)
612 : {
613 1575750 : if(i < nLevels)
614 : {
615 1575394 : aFmts[i] = new SvxNumberFormat(SVX_NUM_CHARS_UPPER_LETTER);
616 : // It is a distinction between writer and draw
617 1575394 : if(nFeatures & NUM_CONTINUOUS)
618 : {
619 1566230 : if ( eDefaultNumberFormatPositionAndSpaceMode ==
620 : SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
621 : {
622 1566230 : aFmts[i]->SetLSpace( MM100_TO_TWIP(DEF_WRITER_LSPACE) );
623 1566230 : aFmts[i]->SetAbsLSpace( MM100_TO_TWIP(DEF_WRITER_LSPACE * (i+1)) );
624 1566230 : aFmts[i]->SetFirstLineOffset(MM100_TO_TWIP(-DEF_WRITER_LSPACE));
625 : }
626 0 : else if ( eDefaultNumberFormatPositionAndSpaceMode ==
627 : SvxNumberFormat::LABEL_ALIGNMENT )
628 : {
629 : // first line indent of general numbering in inch: -0,25 inch
630 0 : const long cFirstLineIndent = -1440/4;
631 : // indent values of general numbering in inch:
632 : // 0,5 0,75 1,0 1,25 1,5
633 : // 1,75 2,0 2,25 2,5 2,75
634 0 : const long cIndentAt = 1440/4;
635 0 : aFmts[i]->SetPositionAndSpaceMode( SvxNumberFormat::LABEL_ALIGNMENT );
636 0 : aFmts[i]->SetLabelFollowedBy( SvxNumberFormat::LISTTAB );
637 0 : aFmts[i]->SetListtabPos( cIndentAt * (i+2) );
638 0 : aFmts[i]->SetFirstLineIndent( cFirstLineIndent );
639 0 : aFmts[i]->SetIndentAt( cIndentAt * (i+2) );
640 : }
641 : }
642 : else
643 : {
644 9164 : aFmts[i]->SetLSpace( DEF_DRAW_LSPACE );
645 9164 : aFmts[i]->SetAbsLSpace( DEF_DRAW_LSPACE * (i) );
646 : }
647 : }
648 : else
649 356 : aFmts[i] = 0;
650 1575750 : aFmtsSet[i] = false;
651 : }
652 157575 : }
653 :
654 450386 : SvxNumRule::SvxNumRule(const SvxNumRule& rCopy)
655 : {
656 450386 : ++nRefCount;
657 450386 : aLocale = rCopy.aLocale;
658 450386 : nLevelCount = rCopy.nLevelCount ;
659 450386 : nFeatureFlags = rCopy.nFeatureFlags ;
660 450386 : bContinuousNumbering = rCopy.bContinuousNumbering;
661 450386 : eNumberingType = rCopy.eNumberingType;
662 450386 : memset( aFmts, 0, sizeof( aFmts ));
663 4954246 : for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++)
664 : {
665 4503860 : if(rCopy.aFmts[i])
666 4503297 : aFmts[i] = new SvxNumberFormat(*rCopy.aFmts[i]);
667 : else
668 563 : aFmts[i] = 0;
669 4503860 : aFmtsSet[i] = rCopy.aFmtsSet[i];
670 : }
671 450386 : }
672 :
673 0 : SvxNumRule::SvxNumRule( SvStream &rStream )
674 : {
675 : sal_uInt16 nTmp16;
676 0 : rStream.ReadUInt16( nTmp16 ); // NUM_ITEM_VERSION
677 0 : rStream.ReadUInt16( nLevelCount );
678 :
679 : // first nFeatureFlags of old Versions
680 0 : rStream.ReadUInt16( nTmp16 ); nFeatureFlags = nTmp16;
681 0 : rStream.ReadUInt16( nTmp16 ); bContinuousNumbering = nTmp16;
682 0 : rStream.ReadUInt16( nTmp16 ); eNumberingType = ( SvxNumRuleType )nTmp16;
683 :
684 0 : for (sal_uInt16 i = 0; i < SVX_MAX_NUM; i++)
685 : {
686 0 : rStream.ReadUInt16( nTmp16 );
687 0 : sal_Bool hasNumberingFormat = nTmp16 & 1;
688 0 : aFmtsSet[i] = nTmp16 & 2; // fdo#68648 reset flag
689 0 : if ( hasNumberingFormat ){
690 0 : aFmts[i] = new SvxNumberFormat( rStream );
691 : }
692 : else
693 : {
694 0 : aFmts[i] = 0;
695 0 : aFmtsSet[i] = false; // actually only false is valid
696 : }
697 : }
698 : //second nFeatureFlags for new versions
699 0 : rStream.ReadUInt16( nTmp16 ); nFeatureFlags = nTmp16;
700 0 : }
701 :
702 0 : SvStream& SvxNumRule::Store( SvStream &rStream )
703 : {
704 0 : rStream.WriteUInt16( (sal_uInt16)NUMITEM_VERSION_03 );
705 0 : rStream.WriteUInt16( nLevelCount );
706 : //first save of nFeatureFlags for old versions
707 0 : rStream.WriteUInt16( (sal_uInt16)nFeatureFlags );
708 0 : rStream.WriteUInt16( (sal_uInt16)bContinuousNumbering );
709 0 : rStream.WriteUInt16( (sal_uInt16)eNumberingType );
710 :
711 0 : FontToSubsFontConverter pConverter = 0;
712 0 : sal_Bool bConvertBulletFont = ( rStream.GetVersion() <= SOFFICE_FILEFORMAT_50 ) && ( rStream.GetVersion() );
713 0 : for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++)
714 : {
715 0 : sal_uInt16 nSetFlag(aFmtsSet[i] ? 2 : 0); // fdo#68648 store that too
716 0 : if(aFmts[i])
717 : {
718 0 : rStream.WriteUInt16( sal_uInt16(1 | nSetFlag) );
719 0 : if(bConvertBulletFont && aFmts[i]->GetBulletFont())
720 : {
721 0 : if(!pConverter)
722 : pConverter =
723 0 : CreateFontToSubsFontConverter(aFmts[i]->GetBulletFont()->GetName(),
724 0 : FONTTOSUBSFONT_EXPORT|FONTTOSUBSFONT_ONLYOLDSOSYMBOLFONTS);
725 : }
726 0 : aFmts[i]->Store(rStream, pConverter);
727 : }
728 : else
729 0 : rStream.WriteUInt16( sal_uInt16(0 | nSetFlag) );
730 : }
731 : //second save of nFeatureFlags for new versions
732 0 : rStream.WriteUInt16( (sal_uInt16)nFeatureFlags );
733 0 : if(pConverter)
734 0 : DestroyFontToSubsFontConverter(pConverter);
735 :
736 0 : return rStream;
737 : }
738 1664169 : SvxNumRule::~SvxNumRule()
739 : {
740 6686086 : for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++)
741 6078260 : delete aFmts[i];
742 607826 : if(!--nRefCount)
743 : {
744 71 : DELETEZ(pStdNumFmt);
745 71 : DELETEZ(pStdOutlineNumFmt);
746 : }
747 1056343 : }
748 :
749 0 : SvxNumRule& SvxNumRule::operator=( const SvxNumRule& rCopy )
750 : {
751 0 : nLevelCount = rCopy.nLevelCount;
752 0 : nFeatureFlags = rCopy.nFeatureFlags;
753 0 : bContinuousNumbering = rCopy.bContinuousNumbering;
754 0 : eNumberingType = rCopy.eNumberingType;
755 0 : for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++)
756 : {
757 0 : delete aFmts[i];
758 0 : if(rCopy.aFmts[i])
759 0 : aFmts[i] = new SvxNumberFormat(*rCopy.aFmts[i]);
760 : else
761 0 : aFmts[i] = 0;
762 0 : aFmtsSet[i] = rCopy.aFmtsSet[i];
763 : }
764 0 : return *this;
765 : }
766 :
767 26104 : int SvxNumRule::operator==( const SvxNumRule& rCopy) const
768 : {
769 50963 : if(nLevelCount != rCopy.nLevelCount ||
770 48286 : nFeatureFlags != rCopy.nFeatureFlags ||
771 46854 : bContinuousNumbering != rCopy.bContinuousNumbering ||
772 23427 : eNumberingType != rCopy.eNumberingType)
773 4732 : return sal_False;
774 169925 : for(sal_uInt16 i = 0; i < nLevelCount; i++)
775 : {
776 155136 : if (
777 309660 : (aFmtsSet[i] != rCopy.aFmtsSet[i]) ||
778 309048 : (!aFmts[i] && rCopy.aFmts[i]) ||
779 625291 : (aFmts[i] && !rCopy.aFmts[i]) ||
780 309048 : (aFmts[i] && *aFmts[i] != *rCopy.aFmts[i])
781 : )
782 : {
783 6583 : return sal_False;
784 : }
785 : }
786 14789 : return sal_True;
787 : }
788 :
789 2331574 : const SvxNumberFormat* SvxNumRule::Get(sal_uInt16 nLevel)const
790 : {
791 : DBG_ASSERT(nLevel < SVX_MAX_NUM, "Wrong Level" );
792 2331574 : if( nLevel < SVX_MAX_NUM )
793 2331574 : return aFmtsSet[nLevel] ? aFmts[nLevel] : 0;
794 : else
795 0 : return 0;
796 : }
797 :
798 1448187 : const SvxNumberFormat& SvxNumRule::GetLevel(sal_uInt16 nLevel)const
799 : {
800 1448187 : if(!pStdNumFmt)
801 : {
802 28 : pStdNumFmt = new SvxNumberFormat(SVX_NUM_ARABIC);
803 28 : pStdOutlineNumFmt = new SvxNumberFormat(SVX_NUM_NUMBER_NONE);
804 : }
805 :
806 : DBG_ASSERT(nLevel < SVX_MAX_NUM, "Wrong Level" );
807 :
808 1448187 : return ( ( nLevel < SVX_MAX_NUM ) && aFmts[nLevel] ) ?
809 1448187 : *aFmts[nLevel] : eNumberingType == SVX_RULETYPE_NUMBERING ?
810 2896374 : *pStdNumFmt : *pStdOutlineNumFmt;
811 : }
812 :
813 3019435 : void SvxNumRule::SetLevel( sal_uInt16 i, const SvxNumberFormat& rNumFmt, bool bIsValid )
814 : {
815 : DBG_ASSERT(i < SVX_MAX_NUM, "Wrong Level" );
816 :
817 3019435 : if( (i < SVX_MAX_NUM) )
818 : {
819 3019435 : bool bReplace = !aFmtsSet[i];
820 3019435 : if (!bReplace)
821 : {
822 858408 : const SvxNumberFormat *pFmt = Get(i);
823 858408 : bReplace = pFmt ? rNumFmt != *pFmt : true;
824 : }
825 :
826 3019435 : if (bReplace)
827 : {
828 2167539 : delete aFmts[i];
829 2167539 : aFmts[i] = new SvxNumberFormat(rNumFmt);
830 2167539 : aFmtsSet[i] = bIsValid;
831 : }
832 : }
833 3019435 : }
834 :
835 0 : void SvxNumRule::SetLevel(sal_uInt16 nLevel, const SvxNumberFormat* pFmt)
836 : {
837 : DBG_ASSERT(nLevel < SVX_MAX_NUM, "Wrong Level" );
838 :
839 0 : if( nLevel < SVX_MAX_NUM )
840 : {
841 0 : aFmtsSet[nLevel] = 0 != pFmt;
842 0 : if(pFmt)
843 0 : SetLevel(nLevel, *pFmt);
844 : else
845 : {
846 0 : delete aFmts[nLevel];
847 0 : aFmts[nLevel] = 0;
848 : }
849 : }
850 0 : }
851 :
852 0 : OUString SvxNumRule::MakeNumString( const SvxNodeNum& rNum, bool bInclStrings ) const
853 : {
854 0 : OUString aStr;
855 0 : if( SVX_NO_NUM > rNum.GetLevel() && !( SVX_NO_NUMLEVEL & rNum.GetLevel() ) )
856 : {
857 0 : const SvxNumberFormat& rMyNFmt = GetLevel( rNum.GetLevel() );
858 0 : if( SVX_NUM_NUMBER_NONE != rMyNFmt.GetNumberingType() )
859 : {
860 0 : sal_uInt8 i = rNum.GetLevel();
861 :
862 0 : if( !IsContinuousNumbering() &&
863 0 : 1 < rMyNFmt.GetIncludeUpperLevels() ) // only on own level?
864 : {
865 0 : sal_uInt8 n = rMyNFmt.GetIncludeUpperLevels();
866 0 : if( 1 < n )
867 : {
868 0 : if( i+1 >= n )
869 0 : i -= n - 1;
870 : else
871 0 : i = 0;
872 : }
873 : }
874 :
875 0 : for( ; i <= rNum.GetLevel(); ++i )
876 : {
877 0 : const SvxNumberFormat& rNFmt = GetLevel( i );
878 0 : if( SVX_NUM_NUMBER_NONE == rNFmt.GetNumberingType() )
879 : {
880 0 : continue;
881 : }
882 :
883 0 : sal_Bool bDot = sal_True;
884 0 : if( rNum.GetLevelVal()[ i ] )
885 : {
886 0 : if(SVX_NUM_BITMAP != rNFmt.GetNumberingType())
887 0 : aStr += rNFmt.GetNumStr( rNum.GetLevelVal()[ i ], aLocale );
888 : else
889 0 : bDot = sal_False;
890 : }
891 : else
892 0 : aStr += "0"; // all 0-levels are a 0
893 0 : if( i != rNum.GetLevel() && bDot)
894 0 : aStr += ".";
895 : }
896 : }
897 :
898 0 : if( bInclStrings )
899 : {
900 0 : aStr = rMyNFmt.GetPrefix() + aStr + rMyNFmt.GetSuffix();
901 : }
902 : }
903 0 : return aStr;
904 : }
905 :
906 : // changes linked to embedded bitmaps
907 143686 : bool SvxNumRule::UnLinkGraphics()
908 : {
909 143686 : sal_Bool bRet = sal_False;
910 1580546 : for(sal_uInt16 i = 0; i < GetLevelCount(); i++)
911 : {
912 1436860 : SvxNumberFormat aFmt(GetLevel(i));
913 1436860 : const SvxBrushItem* pBrush = aFmt.GetBrush();
914 1436860 : const Graphic* pGraphic = NULL;
915 1436860 : if(SVX_NUM_BITMAP == aFmt.GetNumberingType())
916 : {
917 96 : if(pBrush &&
918 96 : !pBrush->GetGraphicLink().isEmpty() &&
919 24 : 0 != (pGraphic = pBrush->GetGraphic()))
920 : {
921 0 : SvxBrushItem aTempItem(*pBrush);
922 0 : aTempItem.SetGraphicLink("");
923 0 : aTempItem.SetGraphic(*pGraphic);
924 0 : sal_Int16 eOrient = aFmt.GetVertOrient();
925 0 : aFmt.SetGraphicBrush( &aTempItem, &aFmt.GetGraphicSize(), &eOrient );
926 0 : bRet = sal_True;
927 : }
928 : }
929 1436836 : else if((SVX_NUM_BITMAP|LINK_TOKEN) == aFmt.GetNumberingType())
930 0 : aFmt.SetNumberingType(SVX_NUM_BITMAP);
931 1436860 : SetLevel(i, aFmt);
932 1436860 : }
933 143686 : return bRet;
934 : }
935 :
936 156623 : SvxNumBulletItem::SvxNumBulletItem(SvxNumRule& rRule) :
937 : SfxPoolItem(SID_ATTR_NUMBERING_RULE),
938 156623 : pNumRule(new SvxNumRule(rRule))
939 : {
940 156623 : }
941 :
942 937 : SvxNumBulletItem::SvxNumBulletItem(SvxNumRule& rRule, sal_uInt16 _nWhich ) :
943 : SfxPoolItem(_nWhich),
944 937 : pNumRule(new SvxNumRule(rRule))
945 : {
946 937 : }
947 :
948 0 : SfxPoolItem* SvxNumBulletItem::Create(SvStream &rStream, sal_uInt16 /*nItemVersion*/ ) const
949 : {
950 0 : SvxNumRule aNumRule( rStream );
951 0 : return new SvxNumBulletItem( aNumRule, EE_PARA_NUMBULLET );
952 : }
953 :
954 290427 : SvxNumBulletItem::SvxNumBulletItem(const SvxNumBulletItem& rCopy) :
955 290427 : SfxPoolItem(rCopy.Which())
956 : {
957 290427 : pNumRule = new SvxNumRule(*rCopy.pNumRule);
958 290427 : }
959 :
960 1185498 : SvxNumBulletItem::~SvxNumBulletItem()
961 : {
962 447852 : delete pNumRule;
963 737646 : }
964 :
965 26104 : bool SvxNumBulletItem::operator==( const SfxPoolItem& rCopy) const
966 : {
967 26104 : return *pNumRule == *((SvxNumBulletItem&)rCopy).pNumRule;
968 : }
969 :
970 289746 : SfxPoolItem* SvxNumBulletItem::Clone( SfxItemPool * ) const
971 : {
972 289746 : return new SvxNumBulletItem(*this);
973 : }
974 :
975 6888 : sal_uInt16 SvxNumBulletItem::GetVersion( sal_uInt16 /*nFileVersion*/ ) const
976 : {
977 6888 : return NUMITEM_VERSION_03;
978 : }
979 :
980 0 : SvStream& SvxNumBulletItem::Store(SvStream &rStream, sal_uInt16 /*nItemVersion*/ )const
981 : {
982 0 : pNumRule->Store(rStream);
983 0 : return rStream;
984 : }
985 :
986 0 : bool SvxNumBulletItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
987 : {
988 0 : rVal <<= SvxCreateNumRule( pNumRule );
989 0 : return true;
990 : }
991 :
992 669 : bool SvxNumBulletItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
993 : {
994 669 : uno::Reference< container::XIndexReplace > xRule;
995 669 : if( rVal >>= xRule )
996 : {
997 : try
998 : {
999 669 : SvxNumRule* pNewRule = new SvxNumRule( SvxGetNumRule( xRule ) );
1000 1330 : if( pNewRule->GetLevelCount() != pNumRule->GetLevelCount() ||
1001 665 : pNewRule->GetNumRuleType() != pNumRule->GetNumRuleType() )
1002 : {
1003 0 : SvxNumRule* pConverted = SvxConvertNumRule( pNewRule, pNumRule->GetLevelCount(), pNumRule->GetNumRuleType() );
1004 0 : delete pNewRule;
1005 0 : pNewRule = pConverted;
1006 : }
1007 665 : delete pNumRule;
1008 665 : pNumRule = pNewRule;
1009 665 : return true;
1010 : }
1011 4 : catch(const lang::IllegalArgumentException&)
1012 : {
1013 : }
1014 : }
1015 4 : return false;
1016 : }
1017 :
1018 0 : SvxNumRule* SvxConvertNumRule( const SvxNumRule* pRule, sal_uInt16 nLevels, SvxNumRuleType eType )
1019 : {
1020 0 : const sal_uInt16 nSrcLevels = pRule->GetLevelCount();
1021 0 : SvxNumRule* pNewRule = new SvxNumRule( pRule->GetFeatureFlags(), nLevels, pRule->IsContinuousNumbering(), eType );
1022 :
1023 0 : for( sal_uInt16 nLevel = 0; (nLevel < nLevels) && (nLevel < nSrcLevels); nLevel++ )
1024 0 : pNewRule->SetLevel( nLevel, pRule->GetLevel( nLevel ) );
1025 :
1026 0 : return pNewRule;
1027 306 : }
1028 :
1029 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|