Bump version to 24.04.3.4
[LibreOffice.git] / editeng / source / items / paraitem.cxx
blobe10c323bcdf66b5e20d66f50b3fbc48faba4e9a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/style/TabStop.hpp>
21 #include <com/sun/star/style/LineSpacing.hpp>
22 #include <com/sun/star/style/LineSpacingMode.hpp>
23 #include <com/sun/star/uno/Sequence.hxx>
24 #include <libxml/xmlwriter.h>
25 #include <comphelper/extract.hxx>
26 #include <osl/diagnose.h>
27 #include <unotools/localedatawrapper.hxx>
28 #include <unotools/syslocale.hxx>
29 #include <tools/mapunit.hxx>
30 #include <tools/UnitConversion.hxx>
31 #include <svl/itempool.hxx>
32 #include <svl/memberid.h>
33 #include <editeng/editrids.hrc>
34 #include <editeng/lspcitem.hxx>
35 #include <editeng/adjustitem.hxx>
36 #include <editeng/orphitem.hxx>
37 #include <editeng/widwitem.hxx>
38 #include <editeng/tstpitem.hxx>
39 #include <editeng/pmdlitem.hxx>
40 #include <editeng/spltitem.hxx>
41 #include <editeng/hyphenzoneitem.hxx>
42 #include <editeng/scriptspaceitem.hxx>
43 #include <editeng/hngpnctitem.hxx>
44 #include <editeng/forbiddenruleitem.hxx>
45 #include <editeng/paravertalignitem.hxx>
46 #include <editeng/pgrditem.hxx>
47 #include <rtl/ustring.hxx>
48 #include <sal/log.hxx>
49 #include <editeng/memberids.h>
50 #include <editeng/itemtype.hxx>
51 #include <editeng/eerdll.hxx>
53 using namespace ::com::sun::star;
56 SfxPoolItem* SvxLineSpacingItem::CreateDefault() { return new SvxLineSpacingItem(LINE_SPACE_DEFAULT_HEIGHT, 0);}
57 SfxPoolItem* SvxAdjustItem::CreateDefault() { return new SvxAdjustItem(SvxAdjust::Left, 0);}
58 SfxPoolItem* SvxWidowsItem::CreateDefault() { return new SvxWidowsItem(0, 0);}
59 SfxPoolItem* SvxOrphansItem::CreateDefault() { return new SvxOrphansItem(0, 0);}
60 SfxPoolItem* SvxHyphenZoneItem::CreateDefault() { return new SvxHyphenZoneItem(false, 0);}
61 SfxPoolItem* SvxTabStopItem::CreateDefault() { return new SvxTabStopItem(0);}
62 SfxPoolItem* SvxFormatSplitItem::CreateDefault() { return new SvxFormatSplitItem(false, 0);}
63 SfxPoolItem* SvxPageModelItem::CreateDefault() { return new SvxPageModelItem(TypedWhichId<SvxPageModelItem>(0));}
64 SfxPoolItem* SvxParaVertAlignItem::CreateDefault() { return new SvxParaVertAlignItem(Align::Automatic, TypedWhichId<SvxParaVertAlignItem>(0));}
66 namespace {
68 enum class SvxSpecialLineSpace
70 User,
71 OneLine,
72 OnePointFiveLines,
73 TwoLines,
74 End
79 SvxLineSpacingItem::SvxLineSpacingItem( sal_uInt16 nHeight, const sal_uInt16 nId )
80 : SfxEnumItemInterface( nId )
82 nPropLineSpace = 100;
83 nInterLineSpace = 0;
84 nLineHeight = nHeight;
85 eLineSpaceRule = SvxLineSpaceRule::Auto;
86 eInterLineSpaceRule = SvxInterLineSpaceRule::Off;
90 bool SvxLineSpacingItem::operator==( const SfxPoolItem& rAttr ) const
92 assert(SfxPoolItem::operator==(rAttr));
94 const SvxLineSpacingItem& rLineSpace = static_cast<const SvxLineSpacingItem&>(rAttr);
95 return
96 // Same Linespacing Rule?
97 (eLineSpaceRule == rLineSpace.eLineSpaceRule)
98 // For maximum and minimum Linespacing be the size must coincide.
99 && (eLineSpaceRule == SvxLineSpaceRule::Auto ||
100 nLineHeight == rLineSpace.nLineHeight)
101 // Same Linespacing Rule?
102 && ( eInterLineSpaceRule == rLineSpace.eInterLineSpaceRule )
103 // Either set proportional or additive.
104 && (( eInterLineSpaceRule == SvxInterLineSpaceRule::Off)
105 || (eInterLineSpaceRule == SvxInterLineSpaceRule::Prop
106 && nPropLineSpace == rLineSpace.nPropLineSpace)
107 || (eInterLineSpaceRule == SvxInterLineSpaceRule::Fix
108 && (nInterLineSpace == rLineSpace.nInterLineSpace)));
111 /* Who does still know why the LineSpacingItem is so complicated?
112 We can not use it for UNO since there are only two values:
113 - a sal_uInt16 for the mode
114 - a sal_uInt32 for all values (distance, height, rel. detail)
116 bool SvxLineSpacingItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
118 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
119 nMemberId &= ~CONVERT_TWIPS;
121 style::LineSpacing aLSp;
122 switch( eLineSpaceRule )
124 case SvxLineSpaceRule::Auto:
125 if(eInterLineSpaceRule == SvxInterLineSpaceRule::Fix)
127 aLSp.Mode = style::LineSpacingMode::LEADING;
128 aLSp.Height = ( bConvert ? static_cast<short>(convertTwipToMm100(nInterLineSpace)) : nInterLineSpace);
130 else if(eInterLineSpaceRule == SvxInterLineSpaceRule::Off)
132 aLSp.Mode = style::LineSpacingMode::PROP;
133 aLSp.Height = 100;
135 else
137 aLSp.Mode = style::LineSpacingMode::PROP;
138 aLSp.Height = nPropLineSpace;
140 break;
141 case SvxLineSpaceRule::Fix :
142 case SvxLineSpaceRule::Min :
143 aLSp.Mode = eLineSpaceRule == SvxLineSpaceRule::Fix ? style::LineSpacingMode::FIX : style::LineSpacingMode::MINIMUM;
144 aLSp.Height = ( bConvert ? static_cast<short>(convertTwipToMm100(nLineHeight)) : nLineHeight );
145 break;
146 default:
147 ;//prevent warning about SvxLineSpaceRule::End
150 switch ( nMemberId )
152 case 0 : rVal <<= aLSp; break;
153 case MID_LINESPACE : rVal <<= aLSp.Mode; break;
154 case MID_HEIGHT : rVal <<= aLSp.Height; break;
155 default: OSL_FAIL("Wrong MemberId!"); break;
158 return true;
161 bool SvxLineSpacingItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
163 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
164 nMemberId &= ~CONVERT_TWIPS;
166 // fill with current data
167 style::LineSpacing aLSp;
168 uno::Any aAny;
169 bool bRet = QueryValue( aAny, bConvert ? CONVERT_TWIPS : 0 ) && ( aAny >>= aLSp );
171 // get new data
172 switch ( nMemberId )
174 case 0 : bRet = (rVal >>= aLSp); break;
175 case MID_LINESPACE : bRet = (rVal >>= aLSp.Mode); break;
176 case MID_HEIGHT : bRet = (rVal >>= aLSp.Height); break;
177 default: OSL_FAIL("Wrong MemberId!"); break;
180 if( bRet )
182 nLineHeight = aLSp.Height;
183 switch( aLSp.Mode )
185 case style::LineSpacingMode::LEADING:
187 eInterLineSpaceRule = SvxInterLineSpaceRule::Fix;
188 eLineSpaceRule = SvxLineSpaceRule::Auto;
189 nInterLineSpace = aLSp.Height;
190 if(bConvert)
191 nInterLineSpace = o3tl::toTwips(nInterLineSpace, o3tl::Length::mm100);
194 break;
195 case style::LineSpacingMode::PROP:
197 eLineSpaceRule = SvxLineSpaceRule::Auto;
198 nPropLineSpace = aLSp.Height;
199 if(100 == aLSp.Height)
200 eInterLineSpaceRule = SvxInterLineSpaceRule::Off;
201 else
202 eInterLineSpaceRule = SvxInterLineSpaceRule::Prop;
204 break;
205 case style::LineSpacingMode::FIX:
206 case style::LineSpacingMode::MINIMUM:
208 eInterLineSpaceRule = SvxInterLineSpaceRule::Off;
209 eLineSpaceRule = aLSp.Mode == style::LineSpacingMode::FIX ? SvxLineSpaceRule::Fix : SvxLineSpaceRule::Min;
210 nLineHeight = aLSp.Height;
211 if(bConvert)
212 nLineHeight = o3tl::toTwips(nLineHeight, o3tl::Length::mm100);
214 break;
218 return bRet;
221 SvxLineSpacingItem* SvxLineSpacingItem::Clone( SfxItemPool * ) const
223 return new SvxLineSpacingItem( *this );
226 bool SvxLineSpacingItem::GetPresentation
228 SfxItemPresentation ePres,
229 MapUnit eCoreUnit,
230 MapUnit ePresUnit,
231 OUString& rText, const IntlWrapper& rIntl
232 ) const
234 switch ( ePres )
236 case SfxItemPresentation::Nameless:
237 case SfxItemPresentation::Complete:
239 switch( GetLineSpaceRule() )
241 case SvxLineSpaceRule::Auto:
243 SvxInterLineSpaceRule eInter = GetInterLineSpaceRule();
245 switch( eInter )
247 // Default single line spacing
248 case SvxInterLineSpaceRule::Off:
249 rText = EditResId(RID_SVXITEMS_LINESPACING_SINGLE);
250 break;
252 // Default single line spacing
253 case SvxInterLineSpaceRule::Prop:
254 if ( 100 == GetPropLineSpace() )
256 rText = EditResId(RID_SVXITEMS_LINESPACING_SINGLE);
257 break;
259 // 1.15 line spacing
260 if ( 115 == GetPropLineSpace() )
262 rText = EditResId(RID_SVXITEMS_LINESPACING_115);
263 break;
265 // 1.5 line spacing
266 if ( 150 == GetPropLineSpace() )
268 rText = EditResId(RID_SVXITEMS_LINESPACING_15);
269 break;
271 // double line spacing
272 if ( 200 == GetPropLineSpace() )
274 rText = EditResId(RID_SVXITEMS_LINESPACING_DOUBLE);
275 break;
277 // the set per cent value
278 rText = EditResId(RID_SVXITEMS_LINESPACING_PROPORTIONAL) + " " + OUString::number(GetPropLineSpace()) + "%";
279 break;
281 case SvxInterLineSpaceRule::Fix:
282 rText = EditResId(RID_SVXITEMS_LINESPACING_LEADING) +
283 " " + GetMetricText(GetInterLineSpace(), eCoreUnit, ePresUnit, &rIntl) +
284 " " + EditResId(GetMetricId(ePresUnit));
285 break;
286 default: ;//prevent warning
289 break;
290 case SvxLineSpaceRule::Fix:
291 rText = EditResId(RID_SVXITEMS_LINESPACING_FIXED) +
292 " " + GetMetricText(GetLineHeight(), eCoreUnit, ePresUnit, &rIntl) +
293 " " + EditResId(GetMetricId(ePresUnit));
294 break;
296 case SvxLineSpaceRule::Min:
297 rText = EditResId(RID_SVXITEMS_LINESPACING_MIN) +
298 " " + GetMetricText(GetLineHeight(), eCoreUnit, ePresUnit, &rIntl) +
299 " " + EditResId(GetMetricId(ePresUnit));
300 break;
301 default: ;//prevent warning
305 return true;
308 sal_uInt16 SvxLineSpacingItem::GetValueCount() const
310 return sal_uInt16(SvxSpecialLineSpace::End); // SvxSpecialLineSpace::TwoLines + 1
314 sal_uInt16 SvxLineSpacingItem::GetEnumValue() const
316 SvxSpecialLineSpace nVal;
317 switch ( nPropLineSpace )
319 case 100: nVal = SvxSpecialLineSpace::OneLine; break;
320 case 150: nVal = SvxSpecialLineSpace::OnePointFiveLines; break;
321 case 200: nVal = SvxSpecialLineSpace::TwoLines; break;
322 default: nVal = SvxSpecialLineSpace::User; break;
324 return static_cast<sal_uInt16>(nVal);
328 void SvxLineSpacingItem::SetEnumValue( sal_uInt16 nVal )
330 switch ( static_cast<SvxSpecialLineSpace>(nVal) )
332 case SvxSpecialLineSpace::OneLine: nPropLineSpace = 100; break;
333 case SvxSpecialLineSpace::OnePointFiveLines: nPropLineSpace = 150; break;
334 case SvxSpecialLineSpace::TwoLines: nPropLineSpace = 200; break;
335 default: break;
339 // class SvxAdjustItem ---------------------------------------------------
341 SvxAdjustItem::SvxAdjustItem(const SvxAdjust eAdjst, const sal_uInt16 nId )
342 : SfxEnumItemInterface( nId ),
343 bOneBlock( false ), bLastCenter( false ), bLastBlock( false )
345 SetAdjust( eAdjst );
349 bool SvxAdjustItem::operator==( const SfxPoolItem& rAttr ) const
351 assert(SfxPoolItem::operator==(rAttr));
353 const SvxAdjustItem& rItem = static_cast<const SvxAdjustItem&>(rAttr);
354 return GetAdjust() == rItem.GetAdjust() &&
355 bOneBlock == rItem.bOneBlock &&
356 bLastCenter == rItem.bLastCenter &&
357 bLastBlock == rItem.bLastBlock;
360 bool SvxAdjustItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
362 nMemberId &= ~CONVERT_TWIPS;
363 switch( nMemberId )
365 case MID_PARA_ADJUST : rVal <<= static_cast<sal_Int16>(GetAdjust()); break;
366 case MID_LAST_LINE_ADJUST : rVal <<= static_cast<sal_Int16>(GetLastBlock()); break;
367 case MID_EXPAND_SINGLE :
369 rVal <<= bOneBlock;
370 break;
372 default: ;//prevent warning
374 return true;
377 bool SvxAdjustItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
379 nMemberId &= ~CONVERT_TWIPS;
380 switch( nMemberId )
382 case MID_PARA_ADJUST :
383 case MID_LAST_LINE_ADJUST :
385 sal_Int32 eVal = - 1;
386 ::cppu::enum2int(eVal,rVal);
387 if(eVal >= 0 && eVal <= 4)
389 SvxAdjust eAdjust = static_cast<SvxAdjust>(eVal);
390 if(MID_LAST_LINE_ADJUST == nMemberId &&
391 eAdjust != SvxAdjust::Left &&
392 eAdjust != SvxAdjust::Block &&
393 eAdjust != SvxAdjust::Center)
394 return false;
395 nMemberId == MID_PARA_ADJUST ? SetAdjust(eAdjust) : SetLastBlock(eAdjust);
398 break;
399 case MID_EXPAND_SINGLE :
400 bOneBlock = Any2Bool(rVal);
401 break;
403 return true;
406 SvxAdjustItem* SvxAdjustItem::Clone( SfxItemPool * ) const
408 return new SvxAdjustItem( *this );
411 bool SvxAdjustItem::GetPresentation
413 SfxItemPresentation ePres,
414 MapUnit /*eCoreUnit*/,
415 MapUnit /*ePresUnit*/,
416 OUString& rText, const IntlWrapper&
417 ) const
419 switch ( ePres )
421 case SfxItemPresentation::Nameless:
422 case SfxItemPresentation::Complete:
423 rText = GetValueTextByPos( static_cast<sal_uInt16>(GetAdjust()) );
424 return true;
425 default: ;//prevent warning
427 return false;
431 sal_uInt16 SvxAdjustItem::GetValueCount() const
433 return sal_uInt16(SvxAdjust::End); // SvxAdjust::BlockLine + 1
436 OUString SvxAdjustItem::GetValueTextByPos( sal_uInt16 nPos )
438 static TranslateId RID_SVXITEMS_ADJUST[] =
440 RID_SVXITEMS_ADJUST_LEFT,
441 RID_SVXITEMS_ADJUST_RIGHT,
442 RID_SVXITEMS_ADJUST_BLOCK,
443 RID_SVXITEMS_ADJUST_CENTER,
444 RID_SVXITEMS_ADJUST_BLOCKLINE
446 static_assert(SAL_N_ELEMENTS(RID_SVXITEMS_ADJUST) - 1 == size_t(SvxAdjust::BlockLine), "unexpected size");
447 assert(nPos <= sal_uInt16(SvxAdjust::BlockLine) && "enum overflow!");
448 return EditResId(RID_SVXITEMS_ADJUST[nPos]);
451 sal_uInt16 SvxAdjustItem::GetEnumValue() const
453 return static_cast<sal_uInt16>(GetAdjust());
457 void SvxAdjustItem::SetEnumValue( sal_uInt16 nVal )
459 SetAdjust( static_cast<SvxAdjust>(nVal) );
463 // class SvxWidowsItem ---------------------------------------------------
465 SvxWidowsItem::SvxWidowsItem(const sal_uInt8 nL, const sal_uInt16 nId ) :
466 SfxByteItem( nId, nL )
470 SvxWidowsItem* SvxWidowsItem::Clone( SfxItemPool * ) const
472 return new SvxWidowsItem( *this );
475 bool SvxWidowsItem::GetPresentation
477 SfxItemPresentation ePres,
478 MapUnit /*eCoreUnit*/,
479 MapUnit /*ePresUnit*/,
480 OUString& rText, const IntlWrapper&
481 ) const
483 switch ( ePres )
485 case SfxItemPresentation::Nameless:
487 rText = EditResId(RID_SVXITEMS_LINES);
488 break;
491 case SfxItemPresentation::Complete:
493 rText = EditResId(RID_SVXITEMS_WIDOWS_COMPLETE) + " " + EditResId(RID_SVXITEMS_LINES);
494 break;
497 default:
499 SAL_WARN( "editeng.items", "SvxWidowsItem::GetPresentation(): unknown SfxItemPresentation" );
503 rText = rText.replaceFirst( "%1", OUString::number( GetValue() ) );
504 return true;
507 // class SvxOrphansItem --------------------------------------------------
509 SvxOrphansItem::SvxOrphansItem(const sal_uInt8 nL, const sal_uInt16 nId ) :
510 SfxByteItem( nId, nL )
514 SvxOrphansItem* SvxOrphansItem::Clone( SfxItemPool * ) const
516 return new SvxOrphansItem( *this );
519 bool SvxOrphansItem::GetPresentation
521 SfxItemPresentation ePres,
522 MapUnit /*eCoreUnit*/,
523 MapUnit /*ePresUnit*/,
524 OUString& rText, const IntlWrapper&
525 ) const
527 switch ( ePres )
529 case SfxItemPresentation::Nameless:
531 rText = EditResId(RID_SVXITEMS_LINES);
532 break;
535 case SfxItemPresentation::Complete:
537 rText = EditResId(RID_SVXITEMS_ORPHANS_COMPLETE) + " " + EditResId(RID_SVXITEMS_LINES);
538 break;
541 default:
543 SAL_WARN( "editeng.items", "SvxOrphansItem::GetPresentation(): unknown SfxItemPresentation" );
547 rText = rText.replaceFirst( "%1", OUString::number( GetValue() ) );
548 return true;
551 // class SvxHyphenZoneItem -----------------------------------------------
553 SvxHyphenZoneItem::SvxHyphenZoneItem( const bool bHyph, const sal_uInt16 nId ) :
554 SfxPoolItem( nId ),
555 bHyphen(bHyph),
556 bPageEnd(true),
557 bNoCapsHyphenation(false),
558 bNoLastWordHyphenation(false),
559 nMinLead(0),
560 nMinTrail(0),
561 nMaxHyphens(255),
562 nMinWordLength(0),
563 nTextHyphenZone(0)
568 bool SvxHyphenZoneItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
570 nMemberId &= ~CONVERT_TWIPS;
571 switch(nMemberId)
573 case MID_IS_HYPHEN:
574 rVal <<= bHyphen;
575 break;
576 case MID_HYPHEN_MIN_LEAD:
577 rVal <<= static_cast<sal_Int16>(nMinLead);
578 break;
579 case MID_HYPHEN_MIN_TRAIL:
580 rVal <<= static_cast<sal_Int16>(nMinTrail);
581 break;
582 case MID_HYPHEN_MAX_HYPHENS:
583 rVal <<= static_cast<sal_Int16>(nMaxHyphens);
584 break;
585 case MID_HYPHEN_NO_CAPS:
586 rVal <<= bNoCapsHyphenation;
587 break;
588 case MID_HYPHEN_NO_LAST_WORD:
589 rVal <<= bNoLastWordHyphenation;
590 break;
591 case MID_HYPHEN_MIN_WORD_LENGTH:
592 rVal <<= static_cast<sal_Int16>(nMinWordLength);
593 break;
594 case MID_HYPHEN_ZONE:
595 rVal <<= static_cast<sal_Int16>(nTextHyphenZone);
596 break;
598 return true;
601 bool SvxHyphenZoneItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
603 nMemberId &= ~CONVERT_TWIPS;
604 sal_Int16 nNewVal = 0;
606 if( nMemberId != MID_IS_HYPHEN && nMemberId != MID_HYPHEN_NO_CAPS &&
607 nMemberId != MID_HYPHEN_NO_LAST_WORD )
609 if(!(rVal >>= nNewVal))
610 return false;
613 switch(nMemberId)
615 case MID_IS_HYPHEN:
616 bHyphen = Any2Bool(rVal);
617 break;
618 case MID_HYPHEN_MIN_LEAD:
619 nMinLead = static_cast<sal_uInt8>(nNewVal);
620 break;
621 case MID_HYPHEN_MIN_TRAIL:
622 nMinTrail = static_cast<sal_uInt8>(nNewVal);
623 break;
624 case MID_HYPHEN_MAX_HYPHENS:
625 nMaxHyphens = static_cast<sal_uInt8>(nNewVal);
626 break;
627 case MID_HYPHEN_NO_CAPS:
628 bNoCapsHyphenation = Any2Bool(rVal);
629 break;
630 case MID_HYPHEN_NO_LAST_WORD:
631 bNoLastWordHyphenation = Any2Bool(rVal);
632 break;
633 case MID_HYPHEN_MIN_WORD_LENGTH:
634 nMinWordLength = static_cast<sal_uInt8>(nNewVal);
635 break;
636 case MID_HYPHEN_ZONE:
637 nTextHyphenZone = nNewVal;
638 break;
640 return true;
644 bool SvxHyphenZoneItem::operator==( const SfxPoolItem& rAttr ) const
646 assert(SfxPoolItem::operator==(rAttr));
648 const SvxHyphenZoneItem& rItem = static_cast<const SvxHyphenZoneItem&>(rAttr);
649 return ( rItem.bHyphen == bHyphen
650 && rItem.bNoCapsHyphenation == bNoCapsHyphenation
651 && rItem.bNoLastWordHyphenation == bNoLastWordHyphenation
652 && rItem.bPageEnd == bPageEnd
653 && rItem.nMinLead == nMinLead
654 && rItem.nMinTrail == nMinTrail
655 && rItem.nMaxHyphens == nMaxHyphens
656 && rItem.nMinWordLength == nMinWordLength
657 && rItem.nTextHyphenZone == nTextHyphenZone );
660 SvxHyphenZoneItem* SvxHyphenZoneItem::Clone( SfxItemPool * ) const
662 return new SvxHyphenZoneItem( *this );
665 bool SvxHyphenZoneItem::GetPresentation
667 SfxItemPresentation ePres,
668 MapUnit eCoreUnit,
669 MapUnit ePresUnit,
670 OUString& rText, const IntlWrapper& rIntl
671 ) const
673 OUString cpDelimTmp(cpDelim);
674 switch ( ePres )
676 case SfxItemPresentation::Nameless:
678 TranslateId pId = RID_SVXITEMS_HYPHEN_FALSE;
680 if ( bHyphen )
681 pId = RID_SVXITEMS_HYPHEN_TRUE;
682 rText = EditResId(pId) + cpDelimTmp;
683 pId = RID_SVXITEMS_PAGE_END_FALSE;
685 if ( bPageEnd )
686 pId = RID_SVXITEMS_PAGE_END_TRUE;
687 rText += EditResId(pId) + cpDelimTmp +
688 OUString::number( nMinLead ) + cpDelimTmp +
689 OUString::number( nMinTrail ) + cpDelimTmp +
690 OUString::number( nMaxHyphens ) + cpDelimTmp +
691 OUString::number( nMinWordLength ) + cpDelimTmp +
692 GetMetricText( nTextHyphenZone, eCoreUnit, ePresUnit, &rIntl ) +
693 " " + EditResId(GetMetricId(ePresUnit));
695 if ( bNoCapsHyphenation )
696 rText += cpDelimTmp + EditResId(RID_SVXITEMS_HYPHEN_NO_CAPS_TRUE);
698 if ( bNoLastWordHyphenation )
699 rText += cpDelimTmp + EditResId(RID_SVXITEMS_HYPHEN_LAST_WORD_TRUE);
701 return true;
703 case SfxItemPresentation::Complete:
705 TranslateId pId = RID_SVXITEMS_HYPHEN_FALSE;
707 if ( bHyphen )
708 pId = RID_SVXITEMS_HYPHEN_TRUE;
709 rText = EditResId(pId) + cpDelimTmp;
710 pId = RID_SVXITEMS_PAGE_END_FALSE;
712 if ( bPageEnd )
713 pId = RID_SVXITEMS_PAGE_END_TRUE;
714 rText += EditResId(pId) +
715 cpDelimTmp +
716 EditResId(RID_SVXITEMS_HYPHEN_MINLEAD).replaceAll("%1", OUString::number(nMinLead)) +
717 cpDelimTmp +
718 EditResId(RID_SVXITEMS_HYPHEN_MINTRAIL).replaceAll("%1", OUString::number(nMinTrail)) +
719 cpDelimTmp +
720 EditResId(RID_SVXITEMS_HYPHEN_MAX).replaceAll("%1", OUString::number(nMaxHyphens)) +
721 cpDelimTmp +
722 EditResId(RID_SVXITEMS_HYPHEN_MINWORDLEN).replaceAll("%1", OUString::number(nMinWordLength));
724 if ( nTextHyphenZone > 0 )
726 rText += cpDelimTmp + EditResId(RID_SVXITEMS_HYPHEN_ZONE) +
727 GetMetricText( nTextHyphenZone, eCoreUnit, ePresUnit, &rIntl ) +
728 " " + EditResId(GetMetricId(ePresUnit));
731 if ( bNoCapsHyphenation )
732 rText += cpDelimTmp + EditResId(RID_SVXITEMS_HYPHEN_NO_CAPS_TRUE);
734 if ( bNoLastWordHyphenation )
735 rText += cpDelimTmp + EditResId(RID_SVXITEMS_HYPHEN_LAST_WORD_TRUE);
737 return true;
739 default: ;//prevent warning
741 return false;
745 // class SvxTabStop ------------------------------------------------------
747 SvxTabStop::SvxTabStop()
749 nTabPos = 0;
750 eAdjustment = SvxTabAdjust::Left;
751 m_cDecimal = cDfltDecimalChar;
752 cFill = cDfltFillChar;
756 SvxTabStop::SvxTabStop( const sal_Int32 nPos, const SvxTabAdjust eAdjst,
757 const sal_Unicode cDec, const sal_Unicode cFil )
759 nTabPos = nPos;
760 eAdjustment = eAdjst;
761 m_cDecimal = cDec;
762 cFill = cFil;
765 void SvxTabStop::fillDecimal() const
767 if ( cDfltDecimalChar == m_cDecimal )
768 m_cDecimal = SvtSysLocale().GetLocaleData().getNumDecimalSep()[0];
771 void SvxTabStop::dumpAsXml(xmlTextWriterPtr pWriter) const
773 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTabStop"));
774 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nTabPos"),
775 BAD_CAST(OString::number(nTabPos).getStr()));
776 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("eAdjustment"),
777 BAD_CAST(OString::number(static_cast<int>(eAdjustment)).getStr()));
778 (void)xmlTextWriterEndElement(pWriter);
781 // class SvxTabStopItem --------------------------------------------------
783 SvxTabStopItem::SvxTabStopItem( sal_uInt16 _nWhich ) :
784 SfxPoolItem( _nWhich )
786 const sal_uInt16 nTabs = SVX_TAB_DEFCOUNT, nDist = SVX_TAB_DEFDIST;
787 const SvxTabAdjust eAdjst= SvxTabAdjust::Default;
789 for (sal_uInt16 i = 0; i < nTabs; ++i)
791 SvxTabStop aTab( (i + 1) * nDist, eAdjst );
792 maTabStops.insert( aTab );
797 SvxTabStopItem::SvxTabStopItem( const sal_uInt16 nTabs,
798 const sal_uInt16 nDist,
799 const SvxTabAdjust eAdjst,
800 sal_uInt16 _nWhich ) :
801 SfxPoolItem( _nWhich )
803 for ( sal_uInt16 i = 0; i < nTabs; ++i )
805 SvxTabStop aTab( (i + 1) * nDist, eAdjst );
806 maTabStops.insert( aTab );
811 sal_uInt16 SvxTabStopItem::GetPos( const SvxTabStop& rTab ) const
813 SvxTabStopArr::const_iterator it = maTabStops.find( rTab );
814 return it != maTabStops.end() ? it - maTabStops.begin() : SVX_TAB_NOTFOUND;
818 sal_uInt16 SvxTabStopItem::GetPos( const sal_Int32 nPos ) const
820 SvxTabStopArr::const_iterator it = maTabStops.find( SvxTabStop( nPos ) );
821 return it != maTabStops.end() ? it - maTabStops.begin() : SVX_TAB_NOTFOUND;
824 void SvxTabStopItem::SetDefaultDistance(sal_Int32 nDefaultDistance)
826 mnDefaultDistance = nDefaultDistance;
829 sal_Int32 SvxTabStopItem::GetDefaultDistance() const
831 return mnDefaultDistance;
834 bool SvxTabStopItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
836 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
837 nMemberId &= ~CONVERT_TWIPS;
838 switch ( nMemberId )
840 case MID_TABSTOPS:
842 sal_uInt16 nCount = Count();
843 uno::Sequence< style::TabStop> aSeq(nCount);
844 style::TabStop* pArr = aSeq.getArray();
845 for(sal_uInt16 i = 0; i < nCount; i++)
847 const SvxTabStop& rTab = (*this)[i];
848 pArr[i].Position = bConvert ? convertTwipToMm100(rTab.GetTabPos()) : rTab.GetTabPos();
849 switch(rTab.GetAdjustment())
851 case SvxTabAdjust::Left : pArr[i].Alignment = style::TabAlign_LEFT; break;
852 case SvxTabAdjust::Right : pArr[i].Alignment = style::TabAlign_RIGHT; break;
853 case SvxTabAdjust::Decimal: pArr[i].Alignment = style::TabAlign_DECIMAL; break;
854 case SvxTabAdjust::Center : pArr[i].Alignment = style::TabAlign_CENTER; break;
855 default: //SvxTabAdjust::Default
856 pArr[i].Alignment = style::TabAlign_DEFAULT;
859 pArr[i].DecimalChar = rTab.GetDecimal();
860 pArr[i].FillChar = rTab.GetFill();
862 rVal <<= aSeq;
863 break;
865 case MID_STD_TAB:
867 const SvxTabStop &rTab = maTabStops.front();
868 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(rTab.GetTabPos()) : rTab.GetTabPos());
869 break;
871 case MID_TABSTOP_DEFAULT_DISTANCE:
873 rVal <<= static_cast<sal_Int32>(bConvert ? convertTwipToMm100(mnDefaultDistance) : mnDefaultDistance);
874 break;
877 return true;
880 bool SvxTabStopItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
882 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
883 nMemberId &= ~CONVERT_TWIPS;
884 switch ( nMemberId )
886 case MID_TABSTOPS:
888 uno::Sequence< style::TabStop> aSeq;
889 if(!(rVal >>= aSeq))
891 uno::Sequence < uno::Sequence < uno::Any > > aAnySeq;
892 if (!(rVal >>= aAnySeq))
893 return false;
894 auto aAnySeqRange = asNonConstRange(aAnySeq);
895 sal_Int32 nLength = aAnySeq.getLength();
896 aSeq.realloc( nLength );
897 auto pSeq = aSeq.getArray();
898 for ( sal_Int32 n=0; n<nLength; n++ )
900 uno::Sequence < uno::Any >& rAnySeq = aAnySeqRange[n];
901 if ( rAnySeq.getLength() == 4 )
903 if (!(rAnySeq[0] >>= pSeq[n].Position)) return false;
904 if (!(rAnySeq[1] >>= pSeq[n].Alignment))
906 sal_Int32 nVal = 0;
907 if (rAnySeq[1] >>= nVal)
908 pSeq[n].Alignment = static_cast<css::style::TabAlign>(nVal);
909 else
910 return false;
912 if (!(rAnySeq[2] >>= pSeq[n].DecimalChar))
914 OUString aVal;
915 if ( (rAnySeq[2] >>= aVal) && aVal.getLength() == 1 )
916 pSeq[n].DecimalChar = aVal.toChar();
917 else
918 return false;
920 if (!(rAnySeq[3] >>= pSeq[n].FillChar))
922 OUString aVal;
923 if ( (rAnySeq[3] >>= aVal) && aVal.getLength() == 1 )
924 pSeq[n].FillChar = aVal.toChar();
925 else
926 return false;
929 else
930 return false;
934 maTabStops.clear();
935 const style::TabStop* pArr = aSeq.getConstArray();
936 const sal_uInt16 nCount = static_cast<sal_uInt16>(aSeq.getLength());
937 for(sal_uInt16 i = 0; i < nCount ; i++)
939 SvxTabAdjust eAdjust = SvxTabAdjust::Default;
940 switch(pArr[i].Alignment)
942 case style::TabAlign_LEFT : eAdjust = SvxTabAdjust::Left; break;
943 case style::TabAlign_CENTER : eAdjust = SvxTabAdjust::Center; break;
944 case style::TabAlign_RIGHT : eAdjust = SvxTabAdjust::Right; break;
945 case style::TabAlign_DECIMAL: eAdjust = SvxTabAdjust::Decimal; break;
946 default: ;//prevent warning
948 sal_Unicode cFill = pArr[i].FillChar;
949 sal_Unicode cDecimal = pArr[i].DecimalChar;
950 SvxTabStop aTab( bConvert ? o3tl::toTwips(pArr[i].Position, o3tl::Length::mm100) : pArr[i].Position,
951 eAdjust,
952 cDecimal,
953 cFill );
954 Insert(aTab);
956 break;
958 case MID_STD_TAB:
960 sal_Int32 nNewPos = 0;
961 if (!(rVal >>= nNewPos) )
962 return false;
963 if (bConvert)
964 nNewPos = o3tl::toTwips(nNewPos, o3tl::Length::mm100);
965 if (nNewPos <= 0)
966 return false;
967 const SvxTabStop& rTab = maTabStops.front();
968 SvxTabStop aNewTab ( nNewPos, rTab.GetAdjustment(), rTab.GetDecimal(), rTab.GetFill() );
969 Remove( 0 );
970 Insert( aNewTab );
971 break;
973 case MID_TABSTOP_DEFAULT_DISTANCE:
975 sal_Int32 nNewDefaultDistance = 0;
976 if (!(rVal >>= nNewDefaultDistance))
977 return false;
978 if (bConvert)
979 nNewDefaultDistance = o3tl::toTwips(nNewDefaultDistance, o3tl::Length::mm100);
980 if (nNewDefaultDistance < 0)
981 return false;
982 mnDefaultDistance = nNewDefaultDistance;
983 break;
986 return true;
990 bool SvxTabStopItem::operator==( const SfxPoolItem& rAttr ) const
992 assert(SfxPoolItem::operator==(rAttr));
994 const SvxTabStopItem& rTSI = static_cast<const SvxTabStopItem&>(rAttr);
996 if ( mnDefaultDistance != rTSI.GetDefaultDistance() )
997 return false;
999 if ( Count() != rTSI.Count() )
1000 return false;
1002 for ( sal_uInt16 i = 0; i < Count(); ++i )
1003 if( (*this)[i] != rTSI[i] )
1004 return false;
1005 return true;
1008 SvxTabStopItem* SvxTabStopItem::Clone( SfxItemPool * ) const
1010 return new SvxTabStopItem( *this );
1013 bool SvxTabStopItem::GetPresentation
1015 SfxItemPresentation ePres,
1016 MapUnit eCoreUnit,
1017 MapUnit ePresUnit,
1018 OUString& rText, const IntlWrapper& rIntl
1019 ) const
1021 rText.clear();
1022 // TODO also consider mnDefaultTabDistance here
1024 bool bComma = false;
1026 for ( sal_uInt16 i = 0; i < Count(); ++i )
1028 if ( SvxTabAdjust::Default != ((*this)[i]).GetAdjustment() )
1030 if ( bComma )
1031 rText += ",";
1032 rText += GetMetricText(
1033 ((*this)[i]).GetTabPos(), eCoreUnit, ePresUnit, &rIntl );
1034 if ( SfxItemPresentation::Complete == ePres )
1036 rText += " " + EditResId(GetMetricId(ePresUnit));
1038 bComma = true;
1041 return true;
1045 bool SvxTabStopItem::Insert( const SvxTabStop& rTab )
1047 sal_uInt16 nTabPos = GetPos(rTab);
1048 if(SVX_TAB_NOTFOUND != nTabPos )
1049 Remove(nTabPos);
1050 return maTabStops.insert( rTab ).second;
1053 void SvxTabStopItem::Insert( const SvxTabStopItem* pTabs )
1055 for( sal_uInt16 i = 0; i < pTabs->Count(); i++ )
1057 const SvxTabStop& rTab = (*pTabs)[i];
1058 sal_uInt16 nTabPos = GetPos(rTab);
1059 if(SVX_TAB_NOTFOUND != nTabPos)
1060 Remove(nTabPos);
1062 for( sal_uInt16 i = 0; i < pTabs->Count(); i++ )
1064 maTabStops.insert( (*pTabs)[i] );
1068 void SvxTabStopItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1070 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SvxTabStopItem"));
1071 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("mnDefaultDistance"),
1072 BAD_CAST(OString::number(mnDefaultDistance).getStr()));
1073 for (const auto& rTabStop : maTabStops)
1074 rTabStop.dumpAsXml(pWriter);
1075 (void)xmlTextWriterEndElement(pWriter);
1078 // class SvxFormatSplitItem -------------------------------------------------
1079 SvxFormatSplitItem::~SvxFormatSplitItem()
1083 SvxFormatSplitItem* SvxFormatSplitItem::Clone( SfxItemPool * ) const
1085 return new SvxFormatSplitItem( *this );
1088 bool SvxFormatSplitItem::GetPresentation
1090 SfxItemPresentation /*ePres*/,
1091 MapUnit /*eCoreUnit*/,
1092 MapUnit /*ePresUnit*/,
1093 OUString& rText, const IntlWrapper&
1094 ) const
1096 TranslateId pId = RID_SVXITEMS_FMTSPLIT_FALSE;
1098 if ( GetValue() )
1099 pId = RID_SVXITEMS_FMTSPLIT_TRUE;
1100 rText = EditResId(pId);
1101 return true;
1104 SvxPageModelItem* SvxPageModelItem::Clone( SfxItemPool* ) const
1106 return new SvxPageModelItem( *this );
1109 bool SvxPageModelItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
1111 nMemberId &= ~CONVERT_TWIPS;
1113 switch ( nMemberId )
1115 case MID_AUTO: rVal <<= bAuto; break;
1116 case MID_NAME: rVal <<= GetValue(); break;
1117 default: OSL_FAIL("Wrong MemberId!"); return false;
1120 return true;
1123 bool SvxPageModelItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
1125 nMemberId &= ~CONVERT_TWIPS;
1126 bool bRet;
1127 OUString aStr;
1128 switch ( nMemberId )
1130 case MID_AUTO: bRet = ( rVal >>= bAuto ); break;
1131 case MID_NAME: bRet = ( rVal >>= aStr ); if ( bRet ) SetValue(aStr); break;
1132 default: OSL_FAIL("Wrong MemberId!"); return false;
1135 return bRet;
1138 bool SvxPageModelItem::operator==( const SfxPoolItem& rAttr ) const
1140 return SfxStringItem::operator==(rAttr) &&
1141 bAuto == static_cast<const SvxPageModelItem&>( rAttr ).bAuto;
1144 bool SvxPageModelItem::GetPresentation
1146 SfxItemPresentation ePres,
1147 MapUnit /*eCoreUnit*/,
1148 MapUnit /*ePresUnit*/,
1149 OUString& rText, const IntlWrapper&
1150 ) const
1152 rText.clear();
1153 bool bSet = !GetValue().isEmpty();
1155 switch ( ePres )
1157 case SfxItemPresentation::Nameless:
1158 if ( bSet )
1159 rText = GetValue();
1160 return true;
1162 case SfxItemPresentation::Complete:
1163 if ( bSet )
1165 rText = EditResId(RID_SVXITEMS_PAGEMODEL_COMPLETE) + GetValue();
1167 return true;
1168 default: ;//prevent warning
1170 return false;
1174 SvxScriptSpaceItem::SvxScriptSpaceItem( bool bOn, const sal_uInt16 nId )
1175 : SfxBoolItem( nId, bOn )
1179 SvxScriptSpaceItem* SvxScriptSpaceItem::Clone( SfxItemPool * ) const
1181 return new SvxScriptSpaceItem( *this );
1184 bool SvxScriptSpaceItem::GetPresentation(
1185 SfxItemPresentation /*ePres*/,
1186 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
1187 OUString &rText, const IntlWrapper& /*rIntl*/ ) const
1189 rText = EditResId( !GetValue()
1190 ? RID_SVXITEMS_SCRPTSPC_OFF
1191 : RID_SVXITEMS_SCRPTSPC_ON );
1192 return true;
1196 SvxHangingPunctuationItem::SvxHangingPunctuationItem(
1197 bool bOn, const sal_uInt16 nId )
1198 : SfxBoolItem( nId, bOn )
1202 SvxHangingPunctuationItem* SvxHangingPunctuationItem::Clone( SfxItemPool * ) const
1204 return new SvxHangingPunctuationItem( *this );
1207 bool SvxHangingPunctuationItem::GetPresentation(
1208 SfxItemPresentation /*ePres*/,
1209 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
1210 OUString &rText, const IntlWrapper& /*rIntl*/ ) const
1212 rText = EditResId( !GetValue()
1213 ? RID_SVXITEMS_HNGPNCT_OFF
1214 : RID_SVXITEMS_HNGPNCT_ON );
1215 return true;
1219 SvxForbiddenRuleItem::SvxForbiddenRuleItem(
1220 bool bOn, const sal_uInt16 nId )
1221 : SfxBoolItem( nId, bOn )
1225 SvxForbiddenRuleItem* SvxForbiddenRuleItem::Clone( SfxItemPool * ) const
1227 return new SvxForbiddenRuleItem( *this );
1230 bool SvxForbiddenRuleItem::GetPresentation(
1231 SfxItemPresentation /*ePres*/,
1232 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
1233 OUString &rText, const IntlWrapper& /*rIntl*/ ) const
1235 rText = EditResId( !GetValue()
1236 ? RID_SVXITEMS_FORBIDDEN_RULE_OFF
1237 : RID_SVXITEMS_FORBIDDEN_RULE_ON );
1238 return true;
1241 /*************************************************************************
1242 |* class SvxParaVertAlignItem
1243 *************************************************************************/
1245 SvxParaVertAlignItem::SvxParaVertAlignItem( Align nValue,
1246 TypedWhichId<SvxParaVertAlignItem> nW )
1247 : SfxUInt16Item( nW, static_cast<sal_uInt16>(nValue) )
1251 SvxParaVertAlignItem* SvxParaVertAlignItem::Clone( SfxItemPool* ) const
1253 return new SvxParaVertAlignItem( *this );
1256 bool SvxParaVertAlignItem::GetPresentation(
1257 SfxItemPresentation /*ePres*/,
1258 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
1259 OUString &rText, const IntlWrapper& ) const
1261 TranslateId pTmp;
1262 switch( GetValue() )
1264 case Align::Automatic: pTmp = RID_SVXITEMS_PARAVERTALIGN_AUTO; break;
1265 case Align::Top: pTmp = RID_SVXITEMS_PARAVERTALIGN_TOP; break;
1266 case Align::Center: pTmp = RID_SVXITEMS_PARAVERTALIGN_CENTER; break;
1267 case Align::Bottom: pTmp = RID_SVXITEMS_PARAVERTALIGN_BOTTOM; break;
1268 default: pTmp = RID_SVXITEMS_PARAVERTALIGN_BASELINE; break;
1270 rText = EditResId(pTmp);
1271 return true;
1274 bool SvxParaVertAlignItem::QueryValue( css::uno::Any& rVal,
1275 sal_uInt8 /*nMemberId*/ ) const
1277 rVal <<= static_cast<sal_Int16>(GetValue());
1278 return true;
1281 bool SvxParaVertAlignItem::PutValue( const css::uno::Any& rVal,
1282 sal_uInt8 /*nMemberId*/ )
1284 sal_Int16 nVal = sal_Int16();
1285 if((rVal >>= nVal) && nVal >=0 && nVal <= sal_uInt16(Align::Bottom) )
1287 SetValue( static_cast<Align>(nVal) );
1288 return true;
1290 else
1291 return false;
1294 SvxParaGridItem::SvxParaGridItem( bool bOn, const sal_uInt16 nId )
1295 : SfxBoolItem( nId, bOn )
1299 SvxParaGridItem* SvxParaGridItem::Clone( SfxItemPool * ) const
1301 return new SvxParaGridItem( *this );
1304 bool SvxParaGridItem::GetPresentation(
1305 SfxItemPresentation /*ePres*/,
1306 MapUnit /*eCoreMetric*/, MapUnit /*ePresMetric*/,
1307 OUString &rText, const IntlWrapper& /*rIntl*/ ) const
1309 rText = GetValue() ?
1310 EditResId( RID_SVXITEMS_PARASNAPTOGRID_ON ) :
1311 EditResId( RID_SVXITEMS_PARASNAPTOGRID_OFF );
1313 return true;
1317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */