bump product version to 5.0.4.1
[LibreOffice.git] / editeng / source / items / frmitems.cxx
blobd872838d7250b51e2daa95885b6f4d8003a919ed
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/uno/Any.hxx>
21 #include <com/sun/star/drawing/LineStyle.hpp>
22 #include <com/sun/star/script/Converter.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/table/ShadowLocation.hpp>
25 #include <com/sun/star/table/TableBorder.hpp>
26 #include <com/sun/star/table/ShadowFormat.hpp>
27 #include <com/sun/star/table/CellRangeAddress.hpp>
28 #include <com/sun/star/table/CellContentType.hpp>
29 #include <com/sun/star/table/TableOrientation.hpp>
30 #include <com/sun/star/util/SortField.hpp>
31 #include <com/sun/star/util/SortFieldType.hpp>
32 #include <com/sun/star/table/BorderLine2.hpp>
33 #include <com/sun/star/table/BorderLineStyle.hpp>
34 #include <com/sun/star/table/CellOrientation.hpp>
35 #include <com/sun/star/table/CellAddress.hpp>
36 #include <com/sun/star/style/PageStyleLayout.hpp>
37 #include <com/sun/star/style/BreakType.hpp>
38 #include <com/sun/star/style/GraphicLocation.hpp>
39 #include <com/sun/star/awt/Rectangle.hpp>
40 #include <com/sun/star/awt/Selection.hpp>
41 #include <com/sun/star/awt/Size.hpp>
42 #include <com/sun/star/text/WritingMode2.hpp>
43 #include <com/sun/star/frame/status/UpperLowerMarginScale.hpp>
44 #include <com/sun/star/drawing/ShadingPattern.hpp>
46 #include <i18nutil/unicode.hxx>
47 #include <unotools/securityoptions.hxx>
48 #include <unotools/ucbstreamhelper.hxx>
49 #include <limits.h>
50 #include <comphelper/processfactory.hxx>
51 #include <svtools/grfmgr.hxx>
52 #include <tools/urlobj.hxx>
53 #include <comphelper/types.hxx>
54 #include <svl/memberid.hrc>
55 #include <svl/cntwall.hxx>
56 #include <svtools/borderhelper.hxx>
57 #include <rtl/ustring.hxx>
58 #include <rtl/ustrbuf.hxx>
59 #include <tools/mapunit.hxx>
60 #include <vcl/graphicfilter.hxx>
61 #include <vcl/settings.hxx>
62 #include <vcl/svapp.hxx>
63 #include <editeng/editids.hrc>
64 #include <editeng/editrids.hrc>
65 #include <editeng/pbinitem.hxx>
66 #include <editeng/sizeitem.hxx>
67 #include <editeng/lrspitem.hxx>
68 #include <editeng/ulspitem.hxx>
69 #include <editeng/prntitem.hxx>
70 #include <editeng/opaqitem.hxx>
71 #include <editeng/protitem.hxx>
72 #include <editeng/shaditem.hxx>
73 #include <editeng/boxitem.hxx>
74 #include <editeng/formatbreakitem.hxx>
75 #include <editeng/keepitem.hxx>
76 #include <editeng/lineitem.hxx>
77 #include <editeng/brushitem.hxx>
78 #include <editeng/frmdiritem.hxx>
79 #include <editeng/itemtype.hxx>
80 #include <editeng/eerdll.hxx>
81 #include <editeng/unoprnms.hxx>
82 #include <editeng/memberids.hrc>
83 #include <editeng/editerr.hxx>
84 #include <libxml/xmlwriter.h>
85 #include <o3tl/enumrange.hxx>
87 using namespace ::editeng;
88 using namespace ::com::sun::star;
89 using namespace ::com::sun::star::drawing;
90 using namespace ::com::sun::star::table::BorderLineStyle;
93 SvxBorderLine is not an SfxPoolItem, and has no Store/Create serialization/deserialization methods.
94 Since border line information needs to be serialized by the table autoformat code, these file-local
95 methods are defined to encapsulate the necessary serialization logic.
97 namespace
99 /// Item version for saved border lines. The old version saves the line without style information.
100 const int BORDER_LINE_OLD_VERSION = 0;
101 /// Item version for saved border lies. The new version includes line style.
102 const int BORDER_LINE_WITH_STYLE_VERSION = 1;
104 /// Store a border line to a stream.
105 SvStream& StoreBorderLine(SvStream &stream, const SvxBorderLine &l, sal_uInt16 version)
107 WriteColor( stream, l.GetColor() );
108 stream.WriteUInt16( l.GetOutWidth() )
109 .WriteUInt16( l.GetInWidth() )
110 .WriteUInt16( l.GetDistance() );
112 if (version >= BORDER_LINE_WITH_STYLE_VERSION)
113 stream.WriteUInt16( l.GetBorderLineStyle() );
115 return stream;
118 /// Creates a border line from a stream.
119 SvxBorderLine CreateBorderLine(SvStream &stream, sal_uInt16 version)
121 sal_uInt16 nOutline, nInline, nDistance;
122 sal_uInt16 nStyle = css::table::BorderLineStyle::NONE;
123 Color aColor;
124 ReadColor( stream, aColor ).ReadUInt16( nOutline ).ReadUInt16( nInline ).ReadUInt16( nDistance );
126 if (version >= BORDER_LINE_WITH_STYLE_VERSION)
127 stream.ReadUInt16( nStyle );
129 SvxBorderLine border(&aColor);
130 border.GuessLinesWidths(nStyle, nOutline, nInline, nDistance);
131 return border;
134 /// Retrieves a BORDER_LINE_* version from a BOX_BORDER_* version.
135 sal_uInt16 BorderLineVersionFromBoxVersion(sal_uInt16 boxVersion)
137 return (boxVersion >= BOX_BORDER_STYLE_VERSION)? BORDER_LINE_WITH_STYLE_VERSION : BORDER_LINE_OLD_VERSION;
141 TYPEINIT1_FACTORY(SvxPaperBinItem, SfxByteItem, new SvxPaperBinItem(0));
142 TYPEINIT1_FACTORY(SvxSizeItem, SfxPoolItem, new SvxSizeItem(0));
143 TYPEINIT1_FACTORY(SvxLRSpaceItem, SfxPoolItem, new SvxLRSpaceItem(0));
144 TYPEINIT1_FACTORY(SvxULSpaceItem, SfxPoolItem, new SvxULSpaceItem(0));
145 TYPEINIT1_FACTORY(SvxPrintItem, SfxBoolItem, new SvxPrintItem(0));
146 TYPEINIT1_FACTORY(SvxOpaqueItem, SfxBoolItem, new SvxOpaqueItem(0));
147 TYPEINIT1_FACTORY(SvxProtectItem, SfxPoolItem, new SvxProtectItem(0));
148 TYPEINIT1_FACTORY(SvxBrushItem, SfxPoolItem, new SvxBrushItem(0));
149 TYPEINIT1_FACTORY(SvxShadowItem, SfxPoolItem, new SvxShadowItem(0));
150 TYPEINIT1_FACTORY(SvxBoxItem, SfxPoolItem, new SvxBoxItem(0));
151 TYPEINIT1_FACTORY(SvxBoxInfoItem, SfxPoolItem, new SvxBoxInfoItem(0));
152 TYPEINIT1_FACTORY(SvxFormatBreakItem, SfxEnumItem, new SvxFormatBreakItem(SVX_BREAK_NONE, 0));
153 TYPEINIT1_FACTORY(SvxFormatKeepItem, SfxBoolItem, new SvxFormatKeepItem(false, 0));
154 TYPEINIT1_FACTORY(SvxLineItem, SfxPoolItem, new SvxLineItem(0));
155 TYPEINIT1_FACTORY(SvxFrameDirectionItem, SfxUInt16Item, new SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP, 0));
157 // class SvxPaperBinItem ------------------------------------------------
159 SfxPoolItem* SvxPaperBinItem::Clone( SfxItemPool* ) const
161 return new SvxPaperBinItem( *this );
166 SvStream& SvxPaperBinItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
168 rStrm.WriteUChar( GetValue() );
169 return rStrm;
174 SfxPoolItem* SvxPaperBinItem::Create( SvStream& rStrm, sal_uInt16 ) const
176 sal_Int8 nBin;
177 rStrm.ReadSChar( nBin );
178 return new SvxPaperBinItem( Which(), nBin );
183 bool SvxPaperBinItem::GetPresentation
185 SfxItemPresentation ePres,
186 SfxMapUnit /*eCoreUnit*/,
187 SfxMapUnit /*ePresUnit*/,
188 OUString& rText, const IntlWrapper *
189 ) const
191 switch ( ePres )
193 case SFX_ITEM_PRESENTATION_NAMELESS:
194 rText = OUString::number( GetValue() );
195 return true;
197 case SFX_ITEM_PRESENTATION_COMPLETE:
199 sal_uInt8 nValue = GetValue();
201 if ( PAPERBIN_PRINTER_SETTINGS == nValue )
202 rText = EE_RESSTR(RID_SVXSTR_PAPERBIN_SETTINGS);
203 else
205 rText = EE_RESSTR(RID_SVXSTR_PAPERBIN) + " " + OUString::number( nValue );
207 return true;
209 //no break necessary
210 default: ;//prevent warning
213 return false;
216 // class SvxSizeItem -----------------------------------------------------
218 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId, const Size& rSize ) :
220 SfxPoolItem( nId ),
222 aSize( rSize )
227 bool SvxSizeItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
229 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
230 nMemberId &= ~CONVERT_TWIPS;
232 awt::Size aTmp(aSize.Width(), aSize.Height());
233 if( bConvert )
235 aTmp.Height = convertTwipToMm100(aTmp.Height);
236 aTmp.Width = convertTwipToMm100(aTmp.Width);
239 switch( nMemberId )
241 case MID_SIZE_SIZE: rVal <<= aTmp; break;
242 case MID_SIZE_WIDTH: rVal <<= aTmp.Width; break;
243 case MID_SIZE_HEIGHT: rVal <<= aTmp.Height; break;
244 default: OSL_FAIL("Wrong MemberId!"); return false;
247 return true;
250 bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
252 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
253 nMemberId &= ~CONVERT_TWIPS;
255 switch( nMemberId )
257 case MID_SIZE_SIZE:
259 awt::Size aTmp;
260 if( rVal >>= aTmp )
262 if(bConvert)
264 aTmp.Height = convertMm100ToTwip(aTmp.Height);
265 aTmp.Width = convertMm100ToTwip(aTmp.Width);
267 aSize = Size( aTmp.Width, aTmp.Height );
269 else
271 return false;
274 break;
275 case MID_SIZE_WIDTH:
277 sal_Int32 nVal = 0;
278 if(!(rVal >>= nVal ))
279 return false;
281 aSize.Width() = bConvert ? convertMm100ToTwip(nVal) : nVal;
283 break;
284 case MID_SIZE_HEIGHT:
286 sal_Int32 nVal = 0;
287 if(!(rVal >>= nVal))
288 return true;
290 aSize.Height() = bConvert ? convertMm100ToTwip(nVal) : nVal;
292 break;
293 default: OSL_FAIL("Wrong MemberId!");
294 return false;
296 return true;
301 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId ) :
303 SfxPoolItem( nId )
309 bool SvxSizeItem::operator==( const SfxPoolItem& rAttr ) const
311 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
313 return ( aSize == static_cast<const SvxSizeItem&>( rAttr ).GetSize() );
318 SfxPoolItem* SvxSizeItem::Clone( SfxItemPool* ) const
320 return new SvxSizeItem( *this );
325 bool SvxSizeItem::GetPresentation
327 SfxItemPresentation ePres,
328 SfxMapUnit eCoreUnit,
329 SfxMapUnit ePresUnit,
330 OUString& rText, const IntlWrapper *pIntl
331 ) const
333 OUString cpDelimTmp(cpDelim);
334 switch ( ePres )
336 case SFX_ITEM_PRESENTATION_NAMELESS:
337 rText = GetMetricText( aSize.Width(), eCoreUnit, ePresUnit, pIntl ) +
338 cpDelimTmp +
339 GetMetricText( aSize.Height(), eCoreUnit, ePresUnit, pIntl );
340 return true;
342 case SFX_ITEM_PRESENTATION_COMPLETE:
343 rText = EE_RESSTR(RID_SVXITEMS_SIZE_WIDTH) +
344 GetMetricText( aSize.Width(), eCoreUnit, ePresUnit, pIntl ) +
345 " " + EE_RESSTR(GetMetricId(ePresUnit)) +
346 cpDelimTmp +
347 EE_RESSTR(RID_SVXITEMS_SIZE_HEIGHT) +
348 GetMetricText( aSize.Height(), eCoreUnit, ePresUnit, pIntl ) +
349 " " + EE_RESSTR(GetMetricId(ePresUnit));
350 return true;
351 //no break necessary
352 default: ;//prevent warning
355 return false;
360 SvStream& SvxSizeItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
362 rStrm.WriteInt32( aSize.Width() );
363 rStrm.WriteInt32( aSize.Height() );
364 return rStrm;
369 bool SvxSizeItem::ScaleMetrics( long nMult, long nDiv )
371 aSize.Width() = Scale( aSize.Width(), nMult, nDiv );
372 aSize.Height() = Scale( aSize.Height(), nMult, nDiv );
373 return true;
378 bool SvxSizeItem::HasMetrics() const
380 return true;
385 SfxPoolItem* SvxSizeItem::Create( SvStream& rStrm, sal_uInt16 ) const
387 sal_Int32 nWidth(0), nHeight(0);
388 rStrm.ReadInt32( nWidth ).ReadInt32( nHeight );
390 SvxSizeItem* pAttr = new SvxSizeItem( Which() );
391 pAttr->SetSize(Size(nWidth, nHeight));
393 return pAttr;
396 // class SvxLRSpaceItem --------------------------------------------------
398 SvxLRSpaceItem::SvxLRSpaceItem( const sal_uInt16 nId ) :
400 SfxPoolItem( nId ),
402 nFirstLineOfst ( 0 ),
403 nTxtLeft ( 0 ),
404 nLeftMargin ( 0 ),
405 nRightMargin ( 0 ),
406 nPropFirstLineOfst( 100 ),
407 nPropLeftMargin( 100 ),
408 nPropRightMargin( 100 ),
409 bAutoFirst ( false ),
410 bExplicitZeroMarginValRight(false),
411 bExplicitZeroMarginValLeft(false)
417 SvxLRSpaceItem::SvxLRSpaceItem( const long nLeft, const long nRight,
418 const long nTLeft, const short nOfset,
419 const sal_uInt16 nId ) :
421 SfxPoolItem( nId ),
423 nFirstLineOfst ( nOfset ),
424 nTxtLeft ( nTLeft ),
425 nLeftMargin ( nLeft ),
426 nRightMargin ( nRight ),
427 nPropFirstLineOfst( 100 ),
428 nPropLeftMargin( 100 ),
429 nPropRightMargin( 100 ),
430 bAutoFirst ( false ),
431 bExplicitZeroMarginValRight(false),
432 bExplicitZeroMarginValLeft(false)
437 bool SvxLRSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
439 bool bRet = true;
440 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
441 nMemberId &= ~CONVERT_TWIPS;
442 switch( nMemberId )
444 // now all signed
445 case MID_L_MARGIN:
446 rVal <<= (sal_Int32)(bConvert ? convertTwipToMm100(nLeftMargin) : nLeftMargin);
447 break;
449 case MID_TXT_LMARGIN :
450 rVal <<= (sal_Int32)(bConvert ? convertTwipToMm100(nTxtLeft) : nTxtLeft);
451 break;
452 case MID_R_MARGIN:
453 rVal <<= (sal_Int32)(bConvert ? convertTwipToMm100(nRightMargin) : nRightMargin);
454 break;
455 case MID_L_REL_MARGIN:
456 rVal <<= (sal_Int16)nPropLeftMargin;
457 break;
458 case MID_R_REL_MARGIN:
459 rVal <<= (sal_Int16)nPropRightMargin;
460 break;
462 case MID_FIRST_LINE_INDENT:
463 rVal <<= (sal_Int32)(bConvert ? convertTwipToMm100(nFirstLineOfst) : nFirstLineOfst);
464 break;
466 case MID_FIRST_LINE_REL_INDENT:
467 rVal <<= (sal_Int16)(nPropFirstLineOfst);
468 break;
470 case MID_FIRST_AUTO:
471 rVal = Bool2Any(IsAutoFirst());
472 break;
474 default:
475 bRet = false;
476 OSL_FAIL("unknown MemberId");
478 return bRet;
482 bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
484 bool bConvert = 0 != (nMemberId&CONVERT_TWIPS);
485 nMemberId &= ~CONVERT_TWIPS;
486 sal_Int32 nVal = 0;
487 if( nMemberId != MID_FIRST_AUTO &&
488 nMemberId != MID_L_REL_MARGIN && nMemberId != MID_R_REL_MARGIN)
489 if(!(rVal >>= nVal))
490 return false;
492 switch( nMemberId )
494 case MID_L_MARGIN:
495 SetLeft( bConvert ? convertMm100ToTwip(nVal) : nVal );
496 break;
498 case MID_TXT_LMARGIN :
499 SetTextLeft( bConvert ? convertMm100ToTwip(nVal) : nVal );
500 break;
502 case MID_R_MARGIN:
503 SetRight(bConvert ? convertMm100ToTwip(nVal) : nVal);
504 break;
505 case MID_L_REL_MARGIN:
506 case MID_R_REL_MARGIN:
508 sal_Int32 nRel = 0;
509 if((rVal >>= nRel) && nRel >= 0 && nRel < USHRT_MAX)
511 if(MID_L_REL_MARGIN== nMemberId)
512 nPropLeftMargin = (sal_uInt16)nRel;
513 else
514 nPropRightMargin = (sal_uInt16)nRel;
516 else
517 return false;
519 break;
520 case MID_FIRST_LINE_INDENT :
521 SetTextFirstLineOfst((short)(bConvert ? convertMm100ToTwip(nVal) : nVal));
522 break;
524 case MID_FIRST_LINE_REL_INDENT:
525 SetPropTextFirstLineOfst ( (sal_uInt16)nVal );
526 break;
528 case MID_FIRST_AUTO:
529 SetAutoFirst( Any2Bool(rVal) );
530 break;
532 default:
533 OSL_FAIL("unknown MemberId");
534 return false;
536 return true;
541 // Adapt nLeftMargin and nTxtLeft.
543 void SvxLRSpaceItem::AdjustLeft()
545 if ( 0 > nFirstLineOfst )
546 nLeftMargin = nTxtLeft + nFirstLineOfst;
547 else
548 nLeftMargin = nTxtLeft;
553 bool SvxLRSpaceItem::operator==( const SfxPoolItem& rAttr ) const
555 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
557 const SvxLRSpaceItem& rOther = static_cast<const SvxLRSpaceItem&>(rAttr);
559 return (
560 nFirstLineOfst == rOther.GetTextFirstLineOfst() &&
561 nTxtLeft == rOther.GetTextLeft() &&
562 nLeftMargin == rOther.GetLeft() &&
563 nRightMargin == rOther.GetRight() &&
564 nPropFirstLineOfst == rOther.GetPropTextFirstLineOfst() &&
565 nPropLeftMargin == rOther.GetPropLeft() &&
566 nPropRightMargin == rOther.GetPropRight() &&
567 bAutoFirst == rOther.IsAutoFirst() &&
568 bExplicitZeroMarginValRight == rOther.IsExplicitZeroMarginValRight() &&
569 bExplicitZeroMarginValLeft == rOther.IsExplicitZeroMarginValLeft() );
574 SfxPoolItem* SvxLRSpaceItem::Clone( SfxItemPool* ) const
576 return new SvxLRSpaceItem( *this );
581 bool SvxLRSpaceItem::GetPresentation
583 SfxItemPresentation ePres,
584 SfxMapUnit eCoreUnit,
585 SfxMapUnit ePresUnit,
586 OUString& rText, const IntlWrapper* pIntl
587 ) const
589 switch ( ePres )
591 case SFX_ITEM_PRESENTATION_NAMELESS:
593 if ( 100 != nPropLeftMargin )
595 rText = unicode::formatPercent(nPropLeftMargin,
596 Application::GetSettings().GetUILanguageTag());
598 else
599 rText = GetMetricText( (long)nLeftMargin,
600 eCoreUnit, ePresUnit, pIntl );
601 rText += OUString(cpDelim);
602 if ( 100 != nPropFirstLineOfst )
604 rText += unicode::formatPercent(nPropFirstLineOfst,
605 Application::GetSettings().GetUILanguageTag());
607 else
608 rText += GetMetricText( (long)nFirstLineOfst,
609 eCoreUnit, ePresUnit, pIntl );
610 rText += OUString(cpDelim);
611 if ( 100 != nRightMargin )
613 rText += unicode::formatPercent(nRightMargin,
614 Application::GetSettings().GetUILanguageTag());
616 else
617 rText += GetMetricText( (long)nRightMargin,
618 eCoreUnit, ePresUnit, pIntl );
619 return true;
621 case SFX_ITEM_PRESENTATION_COMPLETE:
623 rText = EE_RESSTR(RID_SVXITEMS_LRSPACE_LEFT);
624 if ( 100 != nPropLeftMargin )
625 rText += unicode::formatPercent(nPropLeftMargin,
626 Application::GetSettings().GetUILanguageTag());
627 else
629 rText = rText +
630 GetMetricText( (long)nLeftMargin, eCoreUnit, ePresUnit, pIntl ) +
631 " " + EE_RESSTR(GetMetricId(ePresUnit));
633 rText += OUString(cpDelim);
634 if ( 100 != nPropFirstLineOfst || nFirstLineOfst )
636 rText += EE_RESSTR(RID_SVXITEMS_LRSPACE_FLINE);
637 if ( 100 != nPropFirstLineOfst )
638 rText = rText + unicode::formatPercent(nPropFirstLineOfst,
639 Application::GetSettings().GetUILanguageTag());
640 else
642 rText = rText +
643 GetMetricText( (long)nFirstLineOfst,
644 eCoreUnit, ePresUnit, pIntl ) +
645 " " + EE_RESSTR(GetMetricId(ePresUnit));
647 rText += OUString(cpDelim);
649 rText += EE_RESSTR(RID_SVXITEMS_LRSPACE_RIGHT);
650 if ( 100 != nPropRightMargin )
651 rText = rText + unicode::formatPercent(nPropRightMargin,
652 Application::GetSettings().GetUILanguageTag());
653 else
655 rText = rText +
656 GetMetricText( (long)nRightMargin,
657 eCoreUnit, ePresUnit, pIntl ) +
658 " " + EE_RESSTR(GetMetricId(ePresUnit));
660 return true;
662 default: ;//prevent warning
664 return false;
669 // BulletFI: Before 501 in the Outliner the bullet was not on the position of
670 // the FI, so in older documents one must set FI to 0.
671 #define BULLETLR_MARKER 0x599401FE
673 SvStream& SvxLRSpaceItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
675 short nSaveFI = nFirstLineOfst;
676 const_cast<SvxLRSpaceItem*>(this)->SetTextFirstLineOfst( 0 ); // nLeftMargin is manipulated together with this, see Create()
678 sal_uInt16 nMargin = 0;
679 if( nLeftMargin > 0 )
680 nMargin = sal_uInt16( nLeftMargin );
681 rStrm.WriteUInt16( nMargin );
682 rStrm.WriteUInt16( nPropLeftMargin );
683 if( nRightMargin > 0 )
684 nMargin = sal_uInt16( nRightMargin );
685 else
686 nMargin = 0;
687 rStrm.WriteUInt16( nMargin );
688 rStrm.WriteUInt16( nPropRightMargin );
689 rStrm.WriteInt16( nFirstLineOfst );
690 rStrm.WriteUInt16( nPropFirstLineOfst );
691 if( nTxtLeft > 0 )
692 nMargin = sal_uInt16( nTxtLeft );
693 else
694 nMargin = 0;
695 rStrm.WriteUInt16( nMargin );
696 if( nItemVersion >= LRSPACE_AUTOFIRST_VERSION )
698 sal_Int8 nAutoFirst = bAutoFirst ? 1 : 0;
699 if( nItemVersion >= LRSPACE_NEGATIVE_VERSION &&
700 ( nLeftMargin < 0 || nRightMargin < 0 || nTxtLeft < 0 ) )
701 nAutoFirst |= 0x80;
702 rStrm.WriteSChar( nAutoFirst );
704 // From 6.0 onwards, do not write Magic numbers...
705 DBG_ASSERT( rStrm.GetVersion() <= SOFFICE_FILEFORMAT_50, "Change File format SvxLRSpaceItem!" );
706 rStrm.WriteUInt32( BULLETLR_MARKER );
707 rStrm.WriteInt16( nSaveFI );
709 if( 0x80 & nAutoFirst )
711 rStrm.WriteInt32( nLeftMargin );
712 rStrm.WriteInt32( nRightMargin );
716 const_cast<SvxLRSpaceItem*>(this)->SetTextFirstLineOfst( nSaveFI );
718 return rStrm;
723 SfxPoolItem* SvxLRSpaceItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
725 sal_uInt16 left, prpleft, right, prpright, prpfirstline, txtleft;
726 short firstline;
727 sal_Int8 autofirst = 0;
729 if ( nVersion >= LRSPACE_AUTOFIRST_VERSION )
731 rStrm.ReadUInt16( left ).ReadUInt16( prpleft ).ReadUInt16( right ).ReadUInt16( prpright ).ReadInt16( firstline ). ReadUInt16( prpfirstline ).ReadUInt16( txtleft ).ReadSChar( autofirst );
733 sal_Size nPos = rStrm.Tell();
734 sal_uInt32 nMarker;
735 rStrm.ReadUInt32( nMarker );
736 if ( nMarker == BULLETLR_MARKER )
738 rStrm.ReadInt16( firstline );
739 if ( firstline < 0 )
740 left = left + static_cast<sal_uInt16>(firstline); // see below: txtleft = ...
742 else
743 rStrm.Seek( nPos );
745 else if ( nVersion == LRSPACE_TXTLEFT_VERSION )
747 rStrm.ReadUInt16( left ).ReadUInt16( prpleft ).ReadUInt16( right ).ReadUInt16( prpright ).ReadInt16( firstline ). ReadUInt16( prpfirstline ).ReadUInt16( txtleft );
749 else if ( nVersion == LRSPACE_16_VERSION )
751 rStrm.ReadUInt16( left ).ReadUInt16( prpleft ).ReadUInt16( right ).ReadUInt16( prpright ).ReadInt16( firstline ). ReadUInt16( prpfirstline );
753 else
755 sal_Int8 nL, nR, nFL;
756 rStrm.ReadUInt16( left ).ReadSChar( nL ).ReadUInt16( right ).ReadSChar( nR ).ReadInt16( firstline ).ReadSChar( nFL );
757 prpleft = (sal_uInt16)nL;
758 prpright = (sal_uInt16)nR;
759 prpfirstline = (sal_uInt16)nFL;
762 txtleft = firstline >= 0 ? left : left - firstline;
763 SvxLRSpaceItem* pAttr = new SvxLRSpaceItem( Which() );
765 pAttr->nLeftMargin = left;
766 pAttr->nPropLeftMargin = prpleft;
767 pAttr->nRightMargin = right;
768 pAttr->nPropRightMargin = prpright;
769 pAttr->nFirstLineOfst = firstline;
770 pAttr->nPropFirstLineOfst = prpfirstline;
771 pAttr->nTxtLeft = txtleft;
772 pAttr->bAutoFirst = autofirst & 0x01;
773 if( nVersion >= LRSPACE_NEGATIVE_VERSION && ( autofirst & 0x80 ) )
775 sal_Int32 nMargin;
776 rStrm.ReadInt32( nMargin );
777 pAttr->nLeftMargin = nMargin;
778 pAttr->nTxtLeft = firstline >= 0 ? nMargin : nMargin - firstline;
779 rStrm.ReadInt32( nMargin );
780 pAttr->nRightMargin = nMargin;
782 return pAttr;
787 sal_uInt16 SvxLRSpaceItem::GetVersion( sal_uInt16 nFileVersion ) const
789 return (nFileVersion == SOFFICE_FILEFORMAT_31)
790 ? LRSPACE_TXTLEFT_VERSION
791 : LRSPACE_NEGATIVE_VERSION;
796 bool SvxLRSpaceItem::ScaleMetrics( long nMult, long nDiv )
798 nFirstLineOfst = (short)Scale( nFirstLineOfst, nMult, nDiv );
799 nTxtLeft = Scale( nTxtLeft, nMult, nDiv );
800 nLeftMargin = Scale( nLeftMargin, nMult, nDiv );
801 nRightMargin = Scale( nRightMargin, nMult, nDiv );
802 return true;
807 bool SvxLRSpaceItem::HasMetrics() const
809 return true;
812 void SvxLRSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter) const
814 xmlTextWriterStartElement(pWriter, BAD_CAST("svxLRSpaceItem"));
815 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
816 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nFirstLineOfst"), BAD_CAST(OString::number(nFirstLineOfst).getStr()));
817 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nTxtLeft"), BAD_CAST(OString::number(nTxtLeft).getStr()));
818 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nLeftMargin"), BAD_CAST(OString::number(nLeftMargin).getStr()));
819 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nRightMargin"), BAD_CAST(OString::number(nRightMargin).getStr()));
820 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropFirstLineOfst"), BAD_CAST(OString::number(nPropFirstLineOfst).getStr()));
821 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropLeftMargin"), BAD_CAST(OString::number(nPropLeftMargin).getStr()));
822 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropRightMargin"), BAD_CAST(OString::number(nPropRightMargin).getStr()));
823 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bAutoFirst"), BAD_CAST(OString::number(int(bAutoFirst)).getStr()));
824 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bExplicitZeroMarginValRight"), BAD_CAST(OString::number(int(bExplicitZeroMarginValRight)).getStr()));
825 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bExplicitZeroMarginValLeft"), BAD_CAST(OString::number(int(bExplicitZeroMarginValLeft)).getStr()));
826 xmlTextWriterEndElement(pWriter);
829 // class SvxULSpaceItem --------------------------------------------------
831 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nId )
832 : SfxPoolItem(nId)
833 , nUpper(0)
834 , nLower(0)
835 , bContext(false)
836 , nPropUpper(100)
837 , nPropLower(100)
843 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nUp, const sal_uInt16 nLow,
844 const sal_uInt16 nId )
845 : SfxPoolItem(nId)
846 , nUpper(nUp)
847 , nLower(nLow)
848 , bContext(false)
849 , nPropUpper(100)
850 , nPropLower(100)
855 bool SvxULSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
857 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
858 nMemberId &= ~CONVERT_TWIPS;
859 switch( nMemberId )
861 // now all signed
862 case 0:
864 ::com::sun::star::frame::status::UpperLowerMarginScale aUpperLowerMarginScale;
865 aUpperLowerMarginScale.Upper = (sal_Int32)(bConvert ? convertTwipToMm100(nUpper) : nUpper);
866 aUpperLowerMarginScale.Lower = (sal_Int32)(bConvert ? convertTwipToMm100(nLower) : nPropUpper);
867 aUpperLowerMarginScale.ScaleUpper = (sal_Int16)nPropUpper;
868 aUpperLowerMarginScale.ScaleLower = (sal_Int16)nPropLower;
869 rVal <<= aUpperLowerMarginScale;
870 break;
872 case MID_UP_MARGIN: rVal <<= (sal_Int32)(bConvert ? convertTwipToMm100(nUpper) : nUpper); break;
873 case MID_LO_MARGIN: rVal <<= (sal_Int32)(bConvert ? convertTwipToMm100(nLower) : nLower); break;
874 case MID_CTX_MARGIN: rVal <<= bContext; break;
875 case MID_UP_REL_MARGIN: rVal <<= (sal_Int16) nPropUpper; break;
876 case MID_LO_REL_MARGIN: rVal <<= (sal_Int16) nPropLower; break;
878 return true;
882 bool SvxULSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
884 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
885 nMemberId &= ~CONVERT_TWIPS;
886 sal_Int32 nVal = 0;
887 bool bVal = false;
888 switch( nMemberId )
890 case 0:
892 ::com::sun::star::frame::status::UpperLowerMarginScale aUpperLowerMarginScale;
893 if ( !(rVal >>= aUpperLowerMarginScale ))
894 return false;
896 SetUpper((sal_uInt16)(bConvert ? convertMm100ToTwip( aUpperLowerMarginScale.Upper ) : aUpperLowerMarginScale.Upper));
897 SetLower((sal_uInt16)(bConvert ? convertMm100ToTwip( aUpperLowerMarginScale.Lower ) : aUpperLowerMarginScale.Lower));
898 if( aUpperLowerMarginScale.ScaleUpper > 1 )
899 nPropUpper = aUpperLowerMarginScale.ScaleUpper;
900 if( aUpperLowerMarginScale.ScaleLower > 1 )
901 nPropUpper = aUpperLowerMarginScale.ScaleLower;
904 break;
905 case MID_UP_MARGIN :
906 if(!(rVal >>= nVal) || nVal < 0)
907 return false;
908 SetUpper((sal_uInt16)(bConvert ? convertMm100ToTwip(nVal) : nVal));
909 break;
910 case MID_LO_MARGIN :
911 if(!(rVal >>= nVal) || nVal < 0)
912 return false;
913 SetLower((sal_uInt16)(bConvert ? convertMm100ToTwip(nVal) : nVal));
914 break;
915 case MID_CTX_MARGIN :
916 if (!(rVal >>= bVal))
917 return false;
918 SetContextValue(bVal);
919 break;
920 case MID_UP_REL_MARGIN:
921 case MID_LO_REL_MARGIN:
923 sal_Int32 nRel = 0;
924 if((rVal >>= nRel) && nRel > 1 )
926 if(MID_UP_REL_MARGIN == nMemberId)
927 nPropUpper = (sal_uInt16)nRel;
928 else
929 nPropLower = (sal_uInt16)nRel;
931 else
932 return false;
934 break;
936 default:
937 OSL_FAIL("unknown MemberId");
938 return false;
940 return true;
945 bool SvxULSpaceItem::operator==( const SfxPoolItem& rAttr ) const
947 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
949 const SvxULSpaceItem& rSpaceItem = static_cast<const SvxULSpaceItem&>( rAttr );
950 return ( nUpper == rSpaceItem.nUpper &&
951 nLower == rSpaceItem.nLower &&
952 bContext == rSpaceItem.bContext &&
953 nPropUpper == rSpaceItem.nPropUpper &&
954 nPropLower == rSpaceItem.nPropLower );
959 SfxPoolItem* SvxULSpaceItem::Clone( SfxItemPool* ) const
961 return new SvxULSpaceItem( *this );
966 bool SvxULSpaceItem::GetPresentation
968 SfxItemPresentation ePres,
969 SfxMapUnit eCoreUnit,
970 SfxMapUnit ePresUnit,
971 OUString& rText,
972 const IntlWrapper *pIntl
973 ) const
975 switch ( ePres )
977 case SFX_ITEM_PRESENTATION_NAMELESS:
979 if ( 100 != nPropUpper )
981 rText = unicode::formatPercent(nPropUpper,
982 Application::GetSettings().GetUILanguageTag());
984 else
985 rText = GetMetricText( (long)nUpper, eCoreUnit, ePresUnit, pIntl );
986 rText += OUString(cpDelim);
987 if ( 100 != nPropLower )
989 rText += unicode::formatPercent(nPropLower,
990 Application::GetSettings().GetUILanguageTag());
992 else
993 rText += GetMetricText( (long)nLower, eCoreUnit, ePresUnit, pIntl );
994 return true;
996 case SFX_ITEM_PRESENTATION_COMPLETE:
998 rText = EE_RESSTR(RID_SVXITEMS_ULSPACE_UPPER);
999 if ( 100 != nPropUpper )
1001 rText += unicode::formatPercent(nPropUpper,
1002 Application::GetSettings().GetUILanguageTag());
1004 else
1006 rText = rText +
1007 GetMetricText( (long)nUpper, eCoreUnit, ePresUnit, pIntl ) +
1008 " " + EE_RESSTR(GetMetricId(ePresUnit));
1010 rText = rText + OUString(cpDelim) + EE_RESSTR(RID_SVXITEMS_ULSPACE_LOWER);
1011 if ( 100 != nPropLower )
1013 rText += unicode::formatPercent(nPropLower,
1014 Application::GetSettings().GetUILanguageTag());
1016 else
1018 rText = rText +
1019 GetMetricText( (long)nLower, eCoreUnit, ePresUnit, pIntl ) +
1020 " " + EE_RESSTR(GetMetricId(ePresUnit));
1022 return true;
1024 default: ;//prevent warning
1026 return false;
1031 SvStream& SvxULSpaceItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1033 rStrm.WriteUInt16( GetUpper() )
1034 .WriteUInt16( GetPropUpper() )
1035 .WriteUInt16( GetLower() )
1036 .WriteUInt16( GetPropLower() );
1037 return rStrm;
1042 SfxPoolItem* SvxULSpaceItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
1044 sal_uInt16 upper, lower, nPL = 0, nPU = 0;
1046 if ( nVersion == ULSPACE_16_VERSION )
1047 rStrm.ReadUInt16( upper ).ReadUInt16( nPU ).ReadUInt16( lower ).ReadUInt16( nPL );
1048 else
1050 sal_Int8 nU, nL;
1051 rStrm.ReadUInt16( upper ).ReadSChar( nU ).ReadUInt16( lower ).ReadSChar( nL );
1052 nPL = (sal_uInt16)nL;
1053 nPU = (sal_uInt16)nU;
1056 SvxULSpaceItem* pAttr = new SvxULSpaceItem( Which() );
1057 pAttr->SetUpperValue( upper );
1058 pAttr->SetLowerValue( lower );
1059 pAttr->SetPropUpper( nPU );
1060 pAttr->SetPropLower( nPL );
1061 return pAttr;
1066 sal_uInt16 SvxULSpaceItem::GetVersion( sal_uInt16 /*nFileVersion*/ ) const
1068 return ULSPACE_16_VERSION;
1073 bool SvxULSpaceItem::ScaleMetrics( long nMult, long nDiv )
1075 nUpper = (sal_uInt16)Scale( nUpper, nMult, nDiv );
1076 nLower = (sal_uInt16)Scale( nLower, nMult, nDiv );
1077 return true;
1082 bool SvxULSpaceItem::HasMetrics() const
1084 return true;
1087 void SvxULSpaceItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1089 xmlTextWriterStartElement(pWriter, BAD_CAST("svxULSpaceItem"));
1090 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1091 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nUpper"), BAD_CAST(OString::number(nUpper).getStr()));
1092 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nLower"), BAD_CAST(OString::number(nLower).getStr()));
1093 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("bContext"), BAD_CAST(OString::boolean(bContext).getStr()));
1094 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropUpper"), BAD_CAST(OString::number(nPropUpper).getStr()));
1095 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nPropLower"), BAD_CAST(OString::number(nPropLower).getStr()));
1096 xmlTextWriterEndElement(pWriter);
1099 // class SvxPrintItem ----------------------------------------------------
1101 SfxPoolItem* SvxPrintItem::Clone( SfxItemPool* ) const
1103 return new SvxPrintItem( *this );
1108 SvStream& SvxPrintItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1110 rStrm.WriteSChar( (sal_Int8)GetValue() );
1111 return rStrm;
1116 SfxPoolItem* SvxPrintItem::Create( SvStream& rStrm, sal_uInt16 ) const
1118 sal_Int8 bIsPrint;
1119 rStrm.ReadSChar( bIsPrint );
1120 return new SvxPrintItem( Which(), bIsPrint != 0 );
1125 bool SvxPrintItem::GetPresentation
1127 SfxItemPresentation /*ePres*/,
1128 SfxMapUnit /*eCoreUnit*/,
1129 SfxMapUnit /*ePresUnit*/,
1130 OUString& rText, const IntlWrapper *
1131 ) const
1133 sal_uInt16 nId = RID_SVXITEMS_PRINT_FALSE;
1135 if ( GetValue() )
1136 nId = RID_SVXITEMS_PRINT_TRUE;
1137 rText = EE_RESSTR(nId);
1138 return true;
1141 // class SvxOpaqueItem ---------------------------------------------------
1143 SfxPoolItem* SvxOpaqueItem::Clone( SfxItemPool* ) const
1145 return new SvxOpaqueItem( *this );
1150 SvStream& SvxOpaqueItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1152 rStrm.WriteSChar( (sal_Int8)GetValue() );
1153 return rStrm;
1158 SfxPoolItem* SvxOpaqueItem::Create( SvStream& rStrm, sal_uInt16 ) const
1160 sal_Int8 bIsOpaque;
1161 rStrm.ReadSChar( bIsOpaque );
1162 return new SvxOpaqueItem( Which(), bIsOpaque != 0 );
1167 bool SvxOpaqueItem::GetPresentation
1169 SfxItemPresentation /*ePres*/,
1170 SfxMapUnit /*eCoreUnit*/,
1171 SfxMapUnit /*ePresUnit*/,
1172 OUString& rText, const IntlWrapper *
1173 ) const
1175 sal_uInt16 nId = RID_SVXITEMS_OPAQUE_FALSE;
1177 if ( GetValue() )
1178 nId = RID_SVXITEMS_OPAQUE_TRUE;
1179 rText = EE_RESSTR(nId);
1180 return true;
1183 // class SvxProtectItem --------------------------------------------------
1185 bool SvxProtectItem::operator==( const SfxPoolItem& rAttr ) const
1187 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1189 const SvxProtectItem& rItem = static_cast<const SvxProtectItem&>(rAttr);
1190 return ( bCntnt == rItem.bCntnt &&
1191 bSize == rItem.bSize &&
1192 bPos == rItem.bPos );
1195 bool SvxProtectItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1197 nMemberId &= ~CONVERT_TWIPS;
1198 bool bValue;
1199 switch(nMemberId)
1201 case MID_PROTECT_CONTENT : bValue = bCntnt; break;
1202 case MID_PROTECT_SIZE : bValue = bSize; break;
1203 case MID_PROTECT_POSITION: bValue = bPos; break;
1204 default:
1205 OSL_FAIL("Wrong MemberId");
1206 return false;
1209 rVal = Bool2Any( bValue );
1210 return true;
1213 bool SvxProtectItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1215 nMemberId &= ~CONVERT_TWIPS;
1216 bool bVal( Any2Bool(rVal) );
1217 switch(nMemberId)
1219 case MID_PROTECT_CONTENT : bCntnt = bVal; break;
1220 case MID_PROTECT_SIZE : bSize = bVal; break;
1221 case MID_PROTECT_POSITION: bPos = bVal; break;
1222 default:
1223 OSL_FAIL("Wrong MemberId");
1224 return false;
1226 return true;
1231 SfxPoolItem* SvxProtectItem::Clone( SfxItemPool* ) const
1233 return new SvxProtectItem( *this );
1238 bool SvxProtectItem::GetPresentation
1240 SfxItemPresentation /*ePres*/,
1241 SfxMapUnit /*eCoreUnit*/,
1242 SfxMapUnit /*ePresUnit*/,
1243 OUString& rText, const IntlWrapper *
1244 ) const
1246 sal_uInt16 nId = RID_SVXITEMS_PROT_CONTENT_FALSE;
1248 if ( bCntnt )
1249 nId = RID_SVXITEMS_PROT_CONTENT_TRUE;
1250 rText = EE_RESSTR(nId) + OUString(cpDelim);
1251 nId = RID_SVXITEMS_PROT_SIZE_FALSE;
1253 if ( bSize )
1254 nId = RID_SVXITEMS_PROT_SIZE_TRUE;
1255 rText = rText + EE_RESSTR(nId) + OUString(cpDelim);
1256 nId = RID_SVXITEMS_PROT_POS_FALSE;
1258 if ( bPos )
1259 nId = RID_SVXITEMS_PROT_POS_TRUE;
1260 rText += EE_RESSTR(nId);
1261 return true;
1266 SvStream& SvxProtectItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1268 sal_Int8 cProt = 0;
1269 if( IsPosProtected() ) cProt |= 0x01;
1270 if( IsSizeProtected() ) cProt |= 0x02;
1271 if( IsContentProtected() ) cProt |= 0x04;
1272 rStrm.WriteSChar( cProt );
1273 return rStrm;
1278 SfxPoolItem* SvxProtectItem::Create( SvStream& rStrm, sal_uInt16 ) const
1280 sal_Int8 cFlags;
1281 rStrm.ReadSChar( cFlags );
1282 SvxProtectItem* pAttr = new SvxProtectItem( Which() );
1283 pAttr->SetPosProtect( ( cFlags & 0x01 ) != 0 );
1284 pAttr->SetSizeProtect( ( cFlags & 0x02 ) != 0 );
1285 pAttr->SetContentProtect( ( cFlags & 0x04 ) != 0 );
1286 return pAttr;
1289 void SvxProtectItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1291 xmlTextWriterStartElement(pWriter, BAD_CAST("svxProtectItem"));
1292 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1293 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("content"), BAD_CAST(OString::boolean(bCntnt).getStr()));
1294 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("size"), BAD_CAST(OString::boolean(bSize).getStr()));
1295 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("position"), BAD_CAST(OString::boolean(bPos).getStr()));
1296 xmlTextWriterEndElement(pWriter);
1299 // class SvxShadowItem ---------------------------------------------------
1301 SvxShadowItem::SvxShadowItem( const sal_uInt16 nId,
1302 const Color *pColor, const sal_uInt16 nW,
1303 const SvxShadowLocation eLoc ) :
1304 SfxEnumItemInterface( nId ),
1305 aShadowColor(COL_GRAY),
1306 nWidth ( nW ),
1307 eLocation ( eLoc )
1309 if ( pColor )
1310 aShadowColor = *pColor;
1314 bool SvxShadowItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1316 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1317 nMemberId &= ~CONVERT_TWIPS;
1319 table::ShadowFormat aShadow;
1320 table::ShadowLocation eSet = table::ShadowLocation_NONE;
1321 switch( eLocation )
1323 case SVX_SHADOW_TOPLEFT : eSet = table::ShadowLocation_TOP_LEFT ; break;
1324 case SVX_SHADOW_TOPRIGHT : eSet = table::ShadowLocation_TOP_RIGHT ; break;
1325 case SVX_SHADOW_BOTTOMLEFT : eSet = table::ShadowLocation_BOTTOM_LEFT ; break;
1326 case SVX_SHADOW_BOTTOMRIGHT: eSet = table::ShadowLocation_BOTTOM_RIGHT; break;
1327 default: ;//prevent warning
1329 aShadow.Location = eSet;
1330 aShadow.ShadowWidth = bConvert ? convertTwipToMm100(nWidth) : nWidth;
1331 aShadow.IsTransparent = aShadowColor.GetTransparency() > 0;
1332 aShadow.Color = aShadowColor.GetColor();
1334 sal_Int8 nTransparence = rtl::math::round(float(aShadowColor.GetTransparency() * 100) / 255);
1336 switch ( nMemberId )
1338 case MID_LOCATION: rVal <<= aShadow.Location; break;
1339 case MID_WIDTH: rVal <<= aShadow.ShadowWidth; break;
1340 case MID_TRANSPARENT: rVal <<= aShadow.IsTransparent; break;
1341 case MID_BG_COLOR: rVal <<= aShadow.Color; break;
1342 case 0: rVal <<= aShadow; break;
1343 case MID_SHADOW_TRANSPARENCE: rVal <<= nTransparence; break;
1344 default: OSL_FAIL("Wrong MemberId!"); return false;
1347 return true;
1350 bool SvxShadowItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1352 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1353 nMemberId &= ~CONVERT_TWIPS;
1355 table::ShadowFormat aShadow;
1356 uno::Any aAny;
1357 bool bRet = QueryValue( aAny, bConvert ? CONVERT_TWIPS : 0 ) && ( aAny >>= aShadow );
1358 switch ( nMemberId )
1360 case MID_LOCATION:
1362 bRet = (rVal >>= aShadow.Location);
1363 if ( !bRet )
1365 sal_Int16 nVal = 0;
1366 bRet = (rVal >>= nVal);
1367 aShadow.Location = (table::ShadowLocation) nVal;
1370 break;
1373 case MID_WIDTH: rVal >>= aShadow.ShadowWidth; break;
1374 case MID_TRANSPARENT: rVal >>= aShadow.IsTransparent; break;
1375 case MID_BG_COLOR: rVal >>= aShadow.Color; break;
1376 case 0: rVal >>= aShadow; break;
1377 case MID_SHADOW_TRANSPARENCE:
1379 sal_Int32 nTransparence = 0;
1380 if (rVal >>= nTransparence)
1382 Color aColor(aShadow.Color);
1383 aColor.SetTransparency(rtl::math::round(float(nTransparence * 255) / 100));
1384 aShadow.Color = aColor.GetColor();
1386 break;
1388 default: OSL_FAIL("Wrong MemberId!"); return false;
1391 if ( bRet )
1393 // SvxShadowLocation eSet = SVX_SHADOW_NONE;
1394 switch( aShadow.Location )
1396 case table::ShadowLocation_TOP_LEFT : eLocation = SVX_SHADOW_TOPLEFT; break;
1397 case table::ShadowLocation_TOP_RIGHT : eLocation = SVX_SHADOW_TOPRIGHT; break;
1398 case table::ShadowLocation_BOTTOM_LEFT : eLocation = SVX_SHADOW_BOTTOMLEFT ; break;
1399 case table::ShadowLocation_BOTTOM_RIGHT: eLocation = SVX_SHADOW_BOTTOMRIGHT; break;
1400 default: ;//prevent warning
1403 nWidth = bConvert ? convertMm100ToTwip(aShadow.ShadowWidth) : aShadow.ShadowWidth;
1404 Color aSet(aShadow.Color);
1405 aShadowColor = aSet;
1408 return bRet;
1413 bool SvxShadowItem::operator==( const SfxPoolItem& rAttr ) const
1415 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1417 const SvxShadowItem& rItem = static_cast<const SvxShadowItem&>(rAttr);
1418 return ( ( aShadowColor == rItem.aShadowColor ) &&
1419 ( nWidth == rItem.GetWidth() ) &&
1420 ( eLocation == rItem.GetLocation() ) );
1425 SfxPoolItem* SvxShadowItem::Clone( SfxItemPool* ) const
1427 return new SvxShadowItem( *this );
1432 sal_uInt16 SvxShadowItem::CalcShadowSpace( SvxShadowItemSide nShadow ) const
1434 sal_uInt16 nSpace = 0;
1436 switch ( nShadow )
1438 case SvxShadowItemSide::TOP:
1439 if ( eLocation == SVX_SHADOW_TOPLEFT ||
1440 eLocation == SVX_SHADOW_TOPRIGHT )
1441 nSpace = nWidth;
1442 break;
1444 case SvxShadowItemSide::BOTTOM:
1445 if ( eLocation == SVX_SHADOW_BOTTOMLEFT ||
1446 eLocation == SVX_SHADOW_BOTTOMRIGHT )
1447 nSpace = nWidth;
1448 break;
1450 case SvxShadowItemSide::LEFT:
1451 if ( eLocation == SVX_SHADOW_TOPLEFT ||
1452 eLocation == SVX_SHADOW_BOTTOMLEFT )
1453 nSpace = nWidth;
1454 break;
1456 case SvxShadowItemSide::RIGHT:
1457 if ( eLocation == SVX_SHADOW_TOPRIGHT ||
1458 eLocation == SVX_SHADOW_BOTTOMRIGHT )
1459 nSpace = nWidth;
1460 break;
1462 default:
1463 OSL_FAIL( "wrong shadow" );
1465 return nSpace;
1470 bool SvxShadowItem::GetPresentation
1472 SfxItemPresentation ePres,
1473 SfxMapUnit eCoreUnit,
1474 SfxMapUnit ePresUnit,
1475 OUString& rText, const IntlWrapper *pIntl
1476 ) const
1478 switch ( ePres )
1480 case SFX_ITEM_PRESENTATION_NAMELESS:
1482 rText = ::GetColorString( aShadowColor ) + OUString(cpDelim);
1483 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
1485 if ( aShadowColor.GetTransparency() )
1486 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
1487 rText = rText +
1488 EE_RESSTR(nId) +
1489 OUString(cpDelim) +
1490 GetMetricText( (long)nWidth, eCoreUnit, ePresUnit, pIntl ) +
1491 OUString(cpDelim) +
1492 EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + eLocation);
1493 return true;
1495 case SFX_ITEM_PRESENTATION_COMPLETE:
1497 rText = EE_RESSTR(RID_SVXITEMS_SHADOW_COMPLETE) +
1498 ::GetColorString( aShadowColor ) +
1499 OUString(cpDelim);
1501 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
1502 if ( aShadowColor.GetTransparency() )
1503 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
1504 rText = rText +
1505 EE_RESSTR(nId) +
1506 OUString(cpDelim) +
1507 GetMetricText( (long)nWidth, eCoreUnit, ePresUnit, pIntl ) +
1508 " " + EE_RESSTR(GetMetricId(ePresUnit)) +
1509 OUString(cpDelim) +
1510 EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + eLocation);
1511 return true;
1513 default: ;//prevent warning
1515 return false;
1520 SvStream& SvxShadowItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1522 rStrm.WriteSChar( GetLocation() )
1523 .WriteUInt16( GetWidth() )
1524 .WriteBool( aShadowColor.GetTransparency() > 0 );
1525 WriteColor( rStrm, GetColor() );
1526 WriteColor( rStrm, GetColor() );
1527 rStrm.WriteSChar( aShadowColor.GetTransparency() > 0 ? 0 : 1 ); //BRUSH_NULL : BRUSH_SOLID
1528 return rStrm;
1533 bool SvxShadowItem::ScaleMetrics( long nMult, long nDiv )
1535 nWidth = (sal_uInt16)Scale( nWidth, nMult, nDiv );
1536 return true;
1541 bool SvxShadowItem::HasMetrics() const
1543 return true;
1548 SfxPoolItem* SvxShadowItem::Create( SvStream& rStrm, sal_uInt16 ) const
1550 sal_Int8 cLoc;
1551 sal_uInt16 _nWidth;
1552 bool bTrans;
1553 Color aColor;
1554 Color aFillColor;
1555 sal_Int8 nStyle;
1556 rStrm.ReadSChar( cLoc ).ReadUInt16( _nWidth )
1557 .ReadCharAsBool( bTrans );
1558 ReadColor( rStrm, aColor );
1559 ReadColor( rStrm, aFillColor ).ReadSChar( nStyle );
1560 aColor.SetTransparency(bTrans ? 0xff : 0);
1561 return new SvxShadowItem( Which(), &aColor, _nWidth, (SvxShadowLocation)cLoc );
1566 sal_uInt16 SvxShadowItem::GetValueCount() const
1568 return SVX_SHADOW_END; // SVX_SHADOW_BOTTOMRIGHT + 1
1573 OUString SvxShadowItem::GetValueTextByPos( sal_uInt16 nPos ) const
1575 DBG_ASSERT( nPos < SVX_SHADOW_END, "enum overflow!" );
1576 return EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + nPos );
1581 sal_uInt16 SvxShadowItem::GetEnumValue() const
1583 return (sal_uInt16)GetLocation();
1588 void SvxShadowItem::SetEnumValue( sal_uInt16 nVal )
1590 SetLocation( (const SvxShadowLocation)nVal );
1593 void SvxShadowItem::dumpAsXml(xmlTextWriterPtr pWriter) const
1595 xmlTextWriterStartElement(pWriter, BAD_CAST("svxShadowItem"));
1596 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
1597 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("aShadowColor"), BAD_CAST(aShadowColor.AsRGBHexString().toUtf8().getStr()));
1598 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("nWidth"), BAD_CAST(OString::number(nWidth).getStr()));
1599 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("eLocation"), BAD_CAST(OString::number(eLocation).getStr()));
1600 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + eLocation).toUtf8().getStr()));
1601 xmlTextWriterEndElement(pWriter);
1604 // class SvxBoxItem ------------------------------------------------------
1606 SvxBoxItem::SvxBoxItem( const SvxBoxItem& rCpy ) :
1608 SfxPoolItem ( rCpy ),
1609 nTopDist ( rCpy.nTopDist ),
1610 nBottomDist ( rCpy.nBottomDist ),
1611 nLeftDist ( rCpy.nLeftDist ),
1612 nRightDist ( rCpy.nRightDist )
1615 pTop = rCpy.GetTop() ? new SvxBorderLine( *rCpy.GetTop() ) : 0;
1616 pBottom = rCpy.GetBottom() ? new SvxBorderLine( *rCpy.GetBottom() ) : 0;
1617 pLeft = rCpy.GetLeft() ? new SvxBorderLine( *rCpy.GetLeft() ) : 0;
1618 pRight = rCpy.GetRight() ? new SvxBorderLine( *rCpy.GetRight() ) : 0;
1623 SvxBoxItem::SvxBoxItem( const sal_uInt16 nId ) :
1624 SfxPoolItem( nId ),
1626 pTop ( 0 ),
1627 pBottom ( 0 ),
1628 pLeft ( 0 ),
1629 pRight ( 0 ),
1630 nTopDist ( 0 ),
1631 nBottomDist ( 0 ),
1632 nLeftDist ( 0 ),
1633 nRightDist ( 0 )
1640 SvxBoxItem::~SvxBoxItem()
1642 delete pTop;
1643 delete pBottom;
1644 delete pLeft;
1645 delete pRight;
1650 SvxBoxItem& SvxBoxItem::operator=( const SvxBoxItem& rBox )
1652 nTopDist = rBox.nTopDist;
1653 nBottomDist = rBox.nBottomDist;
1654 nLeftDist = rBox.nLeftDist;
1655 nRightDist = rBox.nRightDist;
1656 SetLine( rBox.GetTop(), SvxBoxItemLine::TOP );
1657 SetLine( rBox.GetBottom(), SvxBoxItemLine::BOTTOM );
1658 SetLine( rBox.GetLeft(), SvxBoxItemLine::LEFT );
1659 SetLine( rBox.GetRight(), SvxBoxItemLine::RIGHT );
1660 return *this;
1665 inline bool CmpBrdLn( const SvxBorderLine* pBrd1, const SvxBorderLine* pBrd2 )
1667 bool bRet;
1668 if( 0 != pBrd1 ? 0 == pBrd2 : 0 != pBrd2 )
1669 bRet = false;
1670 else
1671 if( !pBrd1 )
1672 bRet = true;
1673 else
1674 bRet = (*pBrd1 == *pBrd2);
1675 return bRet;
1680 bool SvxBoxItem::operator==( const SfxPoolItem& rAttr ) const
1682 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1684 const SvxBoxItem& rBoxItem = static_cast<const SvxBoxItem&>(rAttr);
1685 return (
1686 ( nTopDist == rBoxItem.nTopDist ) &&
1687 ( nBottomDist == rBoxItem.nBottomDist ) &&
1688 ( nLeftDist == rBoxItem.nLeftDist ) &&
1689 ( nRightDist == rBoxItem.nRightDist ) &&
1690 CmpBrdLn( pTop, rBoxItem.GetTop() ) &&
1691 CmpBrdLn( pBottom, rBoxItem.GetBottom() ) &&
1692 CmpBrdLn( pLeft, rBoxItem.GetLeft() ) &&
1693 CmpBrdLn( pRight, rBoxItem.GetRight() ) );
1697 table::BorderLine2 SvxBoxItem::SvxLineToLine(const SvxBorderLine* pLine, bool bConvert)
1699 table::BorderLine2 aLine;
1700 if(pLine)
1702 aLine.Color = pLine->GetColor().GetColor() ;
1703 aLine.InnerLineWidth = sal_uInt16( bConvert ? convertTwipToMm100(pLine->GetInWidth() ): pLine->GetInWidth() );
1704 aLine.OuterLineWidth = sal_uInt16( bConvert ? convertTwipToMm100(pLine->GetOutWidth()): pLine->GetOutWidth() );
1705 aLine.LineDistance = sal_uInt16( bConvert ? convertTwipToMm100(pLine->GetDistance()): pLine->GetDistance() );
1706 aLine.LineStyle = pLine->GetBorderLineStyle();
1707 aLine.LineWidth = sal_uInt32( bConvert ? convertTwipToMm100( pLine->GetWidth( ) ) : pLine->GetWidth( ) );
1709 else
1710 aLine.Color = aLine.InnerLineWidth = aLine.OuterLineWidth = aLine.LineDistance = 0;
1711 return aLine;
1714 bool SvxBoxItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1716 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1717 table::BorderLine2 aRetLine;
1718 sal_uInt16 nDist = 0;
1719 bool bDistMember = false;
1720 nMemberId &= ~CONVERT_TWIPS;
1721 switch(nMemberId)
1723 case 0:
1725 // 4 Borders and 5 distances
1726 uno::Sequence< uno::Any > aSeq( 9 );
1727 aSeq[0] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetLeft(), bConvert) );
1728 aSeq[1] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetRight(), bConvert) );
1729 aSeq[2] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetBottom(), bConvert) );
1730 aSeq[3] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetTop(), bConvert) );
1731 aSeq[4] <<= uno::makeAny( (sal_Int32)(bConvert ? convertTwipToMm100( GetDistance()) : GetDistance()));
1732 aSeq[5] <<= uno::makeAny( (sal_Int32)(bConvert ? convertTwipToMm100( nTopDist ) : nTopDist ));
1733 aSeq[6] <<= uno::makeAny( (sal_Int32)(bConvert ? convertTwipToMm100( nBottomDist ) : nBottomDist ));
1734 aSeq[7] <<= uno::makeAny( (sal_Int32)(bConvert ? convertTwipToMm100( nLeftDist ) : nLeftDist ));
1735 aSeq[8] <<= uno::makeAny( (sal_Int32)(bConvert ? convertTwipToMm100( nRightDist ) : nRightDist ));
1736 rVal = uno::makeAny( aSeq );
1737 return true;
1739 case MID_LEFT_BORDER:
1740 case LEFT_BORDER:
1741 aRetLine = SvxBoxItem::SvxLineToLine(GetLeft(), bConvert);
1742 break;
1743 case MID_RIGHT_BORDER:
1744 case RIGHT_BORDER:
1745 aRetLine = SvxBoxItem::SvxLineToLine(GetRight(), bConvert);
1746 break;
1747 case MID_BOTTOM_BORDER:
1748 case BOTTOM_BORDER:
1749 aRetLine = SvxBoxItem::SvxLineToLine(GetBottom(), bConvert);
1750 break;
1751 case MID_TOP_BORDER:
1752 case TOP_BORDER:
1753 aRetLine = SvxBoxItem::SvxLineToLine(GetTop(), bConvert);
1754 break;
1755 case BORDER_DISTANCE:
1756 nDist = GetDistance();
1757 bDistMember = true;
1758 break;
1759 case TOP_BORDER_DISTANCE:
1760 nDist = nTopDist;
1761 bDistMember = true;
1762 break;
1763 case BOTTOM_BORDER_DISTANCE:
1764 nDist = nBottomDist;
1765 bDistMember = true;
1766 break;
1767 case LEFT_BORDER_DISTANCE:
1768 nDist = nLeftDist;
1769 bDistMember = true;
1770 break;
1771 case RIGHT_BORDER_DISTANCE:
1772 nDist = nRightDist;
1773 bDistMember = true;
1774 break;
1775 case LINE_STYLE:
1776 case LINE_WIDTH:
1777 // it doesn't make sense to return a value for these since it's
1778 // probably ambiguous
1779 return true;
1780 break;
1783 if( bDistMember )
1784 rVal <<= (sal_Int32)(bConvert ? convertTwipToMm100(nDist) : nDist);
1785 else
1786 rVal <<= aRetLine;
1788 return true;
1791 namespace
1794 bool
1795 lcl_lineToSvxLine(const table::BorderLine& rLine, SvxBorderLine& rSvxLine, bool bConvert, bool bGuessWidth)
1797 rSvxLine.SetColor( Color(rLine.Color));
1798 if ( bGuessWidth )
1800 rSvxLine.GuessLinesWidths( rSvxLine.GetBorderLineStyle(),
1801 sal_uInt16( bConvert ? convertMm100ToTwip(rLine.OuterLineWidth) : rLine.OuterLineWidth ),
1802 sal_uInt16( bConvert ? convertMm100ToTwip(rLine.InnerLineWidth) : rLine.InnerLineWidth ),
1803 sal_uInt16( bConvert ? convertMm100ToTwip(rLine.LineDistance ) : rLine.LineDistance ));
1806 bool bRet = !rSvxLine.isEmpty();
1807 return bRet;
1813 bool SvxBoxItem::LineToSvxLine(const ::com::sun::star::table::BorderLine& rLine, SvxBorderLine& rSvxLine, bool bConvert)
1815 return lcl_lineToSvxLine(rLine, rSvxLine, bConvert, true);
1818 bool
1819 SvxBoxItem::LineToSvxLine(const ::com::sun::star::table::BorderLine2& rLine, SvxBorderLine& rSvxLine, bool bConvert)
1821 SvxBorderStyle const nStyle =
1822 (rLine.LineStyle < 0 || BORDER_LINE_STYLE_MAX < rLine.LineStyle)
1823 ? SOLID // default
1824 : rLine.LineStyle;
1826 rSvxLine.SetBorderLineStyle( nStyle );
1828 bool bGuessWidth = true;
1829 if ( rLine.LineWidth )
1831 rSvxLine.SetWidth( bConvert? convertMm100ToTwip( rLine.LineWidth ) : rLine.LineWidth );
1832 // fdo#46112: double does not necessarily mean symmetric
1833 // for backwards compatibility
1834 bGuessWidth = ((DOUBLE == nStyle || DOUBLE_THIN == nStyle)) &&
1835 (rLine.InnerLineWidth > 0) && (rLine.OuterLineWidth > 0);
1838 return lcl_lineToSvxLine(rLine, rSvxLine, bConvert, bGuessWidth);
1843 namespace
1846 bool
1847 lcl_extractBorderLine(const uno::Any& rAny, table::BorderLine2& rLine)
1849 if (rAny >>= rLine)
1850 return true;
1852 table::BorderLine aBorderLine;
1853 if (rAny >>= aBorderLine)
1855 rLine.Color = aBorderLine.Color;
1856 rLine.InnerLineWidth = aBorderLine.InnerLineWidth;
1857 rLine.OuterLineWidth = aBorderLine.OuterLineWidth;
1858 rLine.LineDistance = aBorderLine.LineDistance;
1859 rLine.LineStyle = table::BorderLineStyle::SOLID;
1860 return true;
1863 return false;
1866 template<typename Item, typename Line>
1867 bool
1868 lcl_setLine(const uno::Any& rAny, Item& rItem, Line nLine, const bool bConvert)
1870 bool bDone = false;
1871 table::BorderLine2 aBorderLine;
1872 if (lcl_extractBorderLine(rAny, aBorderLine))
1874 SvxBorderLine aLine;
1875 bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
1876 rItem.SetLine( bSet ? &aLine : NULL, nLine);
1877 bDone = true;
1879 return bDone;
1884 bool SvxBoxItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1886 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1887 SvxBoxItemLine nLine = SvxBoxItemLine::TOP;
1888 bool bDistMember = false;
1889 nMemberId &= ~CONVERT_TWIPS;
1890 switch(nMemberId)
1892 case 0:
1894 uno::Sequence< uno::Any > aSeq;
1895 if (( rVal >>= aSeq ) && ( aSeq.getLength() == 9 ))
1897 // 4 Borders and 5 distances
1898 const SvxBoxItemLine aBorders[] = { SvxBoxItemLine::LEFT, SvxBoxItemLine::RIGHT, SvxBoxItemLine::BOTTOM, SvxBoxItemLine::TOP };
1899 for (int n(0); n != SAL_N_ELEMENTS(aBorders); ++n)
1901 if (!lcl_setLine(aSeq[n], *this, aBorders[n], bConvert))
1902 return false;
1905 // WTH are the borders and the distances saved in different order?
1906 SvxBoxItemLine nLines[4] = { SvxBoxItemLine::TOP, SvxBoxItemLine::BOTTOM, SvxBoxItemLine::LEFT, SvxBoxItemLine::RIGHT };
1907 for ( sal_Int32 n = 4; n < 9; n++ )
1909 sal_Int32 nDist = 0;
1910 if ( aSeq[n] >>= nDist )
1912 if( bConvert )
1913 nDist = convertMm100ToTwip(nDist);
1914 if ( n == 4 )
1915 SetDistance( sal_uInt16( nDist ));
1916 else
1917 SetDistance( sal_uInt16( nDist ), nLines[n-5] );
1919 else
1920 return false;
1923 return true;
1925 else
1926 return false;
1928 case LEFT_BORDER_DISTANCE:
1929 bDistMember = true;
1930 //fall-through
1931 case LEFT_BORDER:
1932 case MID_LEFT_BORDER:
1933 nLine = SvxBoxItemLine::LEFT;
1934 break;
1935 case RIGHT_BORDER_DISTANCE:
1936 bDistMember = true;
1937 //fall-through
1938 case RIGHT_BORDER:
1939 case MID_RIGHT_BORDER:
1940 nLine = SvxBoxItemLine::RIGHT;
1941 break;
1942 case BOTTOM_BORDER_DISTANCE:
1943 bDistMember = true;
1944 //fall-through
1945 case BOTTOM_BORDER:
1946 case MID_BOTTOM_BORDER:
1947 nLine = SvxBoxItemLine::BOTTOM;
1948 break;
1949 case TOP_BORDER_DISTANCE:
1950 bDistMember = true;
1951 //fall-through
1952 case TOP_BORDER:
1953 case MID_TOP_BORDER:
1954 nLine = SvxBoxItemLine::TOP;
1955 break;
1956 case LINE_STYLE:
1958 drawing::LineStyle eDrawingStyle;
1959 rVal >>= eDrawingStyle;
1960 editeng::SvxBorderStyle eBorderStyle = css::table::BorderLineStyle::NONE;
1961 switch ( eDrawingStyle )
1963 default:
1964 case drawing::LineStyle_NONE:
1965 break;
1966 case drawing::LineStyle_SOLID:
1967 eBorderStyle = SOLID;
1968 break;
1969 case drawing::LineStyle_DASH:
1970 eBorderStyle = DASHED;
1971 break;
1974 // Set the line style on all borders
1975 for( SvxBoxItemLine n : o3tl::enumrange<SvxBoxItemLine>() )
1977 editeng::SvxBorderLine* pLine = const_cast< editeng::SvxBorderLine* >( GetLine( n ) );
1978 if( pLine )
1979 pLine->SetBorderLineStyle( eBorderStyle );
1981 return true;
1983 break;
1984 case LINE_WIDTH:
1986 // Set the line width on all borders
1987 long nWidth(0);
1988 rVal >>= nWidth;
1989 if( bConvert )
1990 nWidth = convertMm100ToTwip( nWidth );
1992 // Set the line Width on all borders
1993 for( SvxBoxItemLine n : o3tl::enumrange<SvxBoxItemLine>() )
1995 editeng::SvxBorderLine* pLine = const_cast< editeng::SvxBorderLine* >( GetLine( n ) );
1996 if( pLine )
1997 pLine->SetWidth( nWidth );
2000 return true;
2003 if( bDistMember || nMemberId == BORDER_DISTANCE )
2005 sal_Int32 nDist = 0;
2006 if(!(rVal >>= nDist))
2007 return false;
2009 if(nDist >= 0)
2011 if( bConvert )
2012 nDist = convertMm100ToTwip(nDist);
2013 if( nMemberId == BORDER_DISTANCE )
2014 SetDistance( sal_uInt16( nDist ));
2015 else
2016 SetDistance( sal_uInt16( nDist ), nLine );
2019 else
2021 SvxBorderLine aLine;
2022 if( !rVal.hasValue() )
2023 return false;
2025 table::BorderLine2 aBorderLine;
2026 if( lcl_extractBorderLine(rVal, aBorderLine) )
2028 // usual struct
2030 else if (rVal.getValueTypeClass() == uno::TypeClass_SEQUENCE )
2032 // serialization for basic macro recording
2033 uno::Reference < script::XTypeConverter > xConverter
2034 ( script::Converter::create(::comphelper::getProcessComponentContext()) );
2035 uno::Sequence < uno::Any > aSeq;
2036 uno::Any aNew;
2037 try { aNew = xConverter->convertTo( rVal, cppu::UnoType<uno::Sequence < uno::Any >>::get() ); }
2038 catch (const uno::Exception&) {}
2040 aNew >>= aSeq;
2041 if (aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2043 sal_Int32 nVal = 0;
2044 if ( aSeq[0] >>= nVal )
2045 aBorderLine.Color = nVal;
2046 if ( aSeq[1] >>= nVal )
2047 aBorderLine.InnerLineWidth = (sal_Int16) nVal;
2048 if ( aSeq[2] >>= nVal )
2049 aBorderLine.OuterLineWidth = (sal_Int16) nVal;
2050 if ( aSeq[3] >>= nVal )
2051 aBorderLine.LineDistance = (sal_Int16) nVal;
2052 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2054 if (aSeq[4] >>= nVal)
2056 aBorderLine.LineStyle = nVal;
2058 if (aSeq.getLength() >= 6)
2060 if (aSeq[5] >>= nVal)
2062 aBorderLine.LineWidth = nVal;
2067 else
2068 return false;
2070 else
2071 return false;
2073 bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
2074 SetLine(bSet ? &aLine : 0, nLine);
2077 return true;
2082 SfxPoolItem* SvxBoxItem::Clone( SfxItemPool* ) const
2084 return new SvxBoxItem( *this );
2089 bool SvxBoxItem::GetPresentation
2091 SfxItemPresentation ePres,
2092 SfxMapUnit eCoreUnit,
2093 SfxMapUnit ePresUnit,
2094 OUString& rText, const IntlWrapper *pIntl
2095 ) const
2097 OUString cpDelimTmp = OUString(cpDelim);
2098 switch ( ePres )
2100 case SFX_ITEM_PRESENTATION_NAMELESS:
2102 rText.clear();
2104 if ( pTop )
2106 rText = pTop->GetValueString( eCoreUnit, ePresUnit, pIntl ) + cpDelimTmp;
2108 if( !(pTop && pBottom && pLeft && pRight &&
2109 *pTop == *pBottom && *pTop == *pLeft && *pTop == *pRight) )
2111 if ( pBottom )
2113 rText = rText + pBottom->GetValueString( eCoreUnit, ePresUnit, pIntl ) + cpDelimTmp;
2115 if ( pLeft )
2117 rText = rText + pLeft->GetValueString( eCoreUnit, ePresUnit, pIntl ) + cpDelimTmp;
2119 if ( pRight )
2121 rText = rText + pRight->GetValueString( eCoreUnit, ePresUnit, pIntl ) + cpDelimTmp;
2124 rText += GetMetricText( (long)nTopDist, eCoreUnit, ePresUnit, pIntl );
2125 if( nTopDist != nBottomDist || nTopDist != nLeftDist ||
2126 nTopDist != nRightDist )
2128 rText = rText +
2129 cpDelimTmp +
2130 GetMetricText( (long)nBottomDist, eCoreUnit,
2131 ePresUnit, pIntl ) +
2132 cpDelimTmp +
2133 GetMetricText( (long)nLeftDist, eCoreUnit, ePresUnit, pIntl ) +
2134 cpDelimTmp +
2135 GetMetricText( (long)nRightDist, eCoreUnit,
2136 ePresUnit, pIntl );
2138 return true;
2140 case SFX_ITEM_PRESENTATION_COMPLETE:
2142 if( !(pTop || pBottom || pLeft || pRight) )
2144 rText = EE_RESSTR(RID_SVXITEMS_BORDER_NONE) + cpDelimTmp;
2146 else
2148 rText = EE_RESSTR(RID_SVXITEMS_BORDER_COMPLETE);
2149 if( pTop && pBottom && pLeft && pRight &&
2150 *pTop == *pBottom && *pTop == *pLeft && *pTop == *pRight )
2152 rText += pTop->GetValueString( eCoreUnit, ePresUnit, pIntl, true ) + cpDelimTmp;
2154 else
2156 if ( pTop )
2158 rText = rText +
2159 EE_RESSTR(RID_SVXITEMS_BORDER_TOP) +
2160 pTop->GetValueString( eCoreUnit, ePresUnit, pIntl, true ) +
2161 cpDelimTmp;
2163 if ( pBottom )
2165 rText = rText +
2166 EE_RESSTR(RID_SVXITEMS_BORDER_BOTTOM) +
2167 pBottom->GetValueString( eCoreUnit, ePresUnit, pIntl, true ) +
2168 cpDelimTmp;
2170 if ( pLeft )
2172 rText = rText +
2173 EE_RESSTR(RID_SVXITEMS_BORDER_LEFT) +
2174 pLeft->GetValueString( eCoreUnit, ePresUnit, pIntl, true ) +
2175 cpDelimTmp;
2177 if ( pRight )
2179 rText = rText +
2180 EE_RESSTR(RID_SVXITEMS_BORDER_RIGHT) +
2181 pRight->GetValueString( eCoreUnit, ePresUnit, pIntl, true ) +
2182 cpDelimTmp;
2187 rText += EE_RESSTR(RID_SVXITEMS_BORDER_DISTANCE);
2188 if( nTopDist == nBottomDist && nTopDist == nLeftDist &&
2189 nTopDist == nRightDist )
2191 rText = rText +
2192 GetMetricText( (long)nTopDist, eCoreUnit,
2193 ePresUnit, pIntl ) +
2194 " " + EE_RESSTR(GetMetricId(ePresUnit));
2196 else
2198 rText = rText +
2199 EE_RESSTR(RID_SVXITEMS_BORDER_TOP) +
2200 GetMetricText( (long)nTopDist, eCoreUnit,
2201 ePresUnit, pIntl ) +
2202 " " + EE_RESSTR(GetMetricId(ePresUnit)) +
2203 cpDelimTmp +
2204 EE_RESSTR(RID_SVXITEMS_BORDER_BOTTOM) +
2205 GetMetricText( (long)nBottomDist, eCoreUnit,
2206 ePresUnit, pIntl ) +
2207 " " + EE_RESSTR(GetMetricId(ePresUnit)) +
2208 cpDelimTmp +
2209 EE_RESSTR(RID_SVXITEMS_BORDER_LEFT) +
2210 GetMetricText( (long)nLeftDist, eCoreUnit,
2211 ePresUnit, pIntl ) +
2212 " " + EE_RESSTR(GetMetricId(ePresUnit)) +
2213 cpDelimTmp +
2214 EE_RESSTR(RID_SVXITEMS_BORDER_RIGHT) +
2215 GetMetricText( (long)nRightDist, eCoreUnit,
2216 ePresUnit, pIntl ) +
2217 " " + EE_RESSTR(GetMetricId(ePresUnit));
2219 return true;
2221 default: ;//prevent warning
2223 return false;
2228 SvStream& SvxBoxItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
2230 rStrm.WriteUInt16( GetDistance() );
2231 const SvxBorderLine* pLine[ 4 ]; // top, left, right, bottom
2232 pLine[ 0 ] = GetTop();
2233 pLine[ 1 ] = GetLeft();
2234 pLine[ 2 ] = GetRight();
2235 pLine[ 3 ] = GetBottom();
2237 for( int i = 0; i < 4; i++ )
2239 const SvxBorderLine* l = pLine[ i ];
2240 if( l )
2242 rStrm.WriteSChar(i);
2243 StoreBorderLine(rStrm, *l, BorderLineVersionFromBoxVersion(nItemVersion));
2246 sal_Int8 cLine = 4;
2247 if( nItemVersion >= BOX_4DISTS_VERSION &&
2248 !(nTopDist == nLeftDist &&
2249 nTopDist == nRightDist &&
2250 nTopDist == nBottomDist) )
2252 cLine |= 0x10;
2255 rStrm.WriteSChar( cLine );
2257 if( nItemVersion >= BOX_4DISTS_VERSION && (cLine & 0x10) != 0 )
2259 rStrm.WriteUInt16( nTopDist )
2260 .WriteUInt16( nLeftDist )
2261 .WriteUInt16( nRightDist )
2262 .WriteUInt16( nBottomDist );
2265 return rStrm;
2270 sal_uInt16 SvxBoxItem::GetVersion( sal_uInt16 nFFVer ) const
2272 DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
2273 SOFFICE_FILEFORMAT_40==nFFVer ||
2274 SOFFICE_FILEFORMAT_50==nFFVer,
2275 "SvxBoxItem: Gibt es ein neues Fileformat?" );
2276 return SOFFICE_FILEFORMAT_31==nFFVer ||
2277 SOFFICE_FILEFORMAT_40==nFFVer ? 0 : BOX_BORDER_STYLE_VERSION;
2282 bool SvxBoxItem::ScaleMetrics( long nMult, long nDiv )
2284 if ( pTop ) pTop->ScaleMetrics( nMult, nDiv );
2285 if ( pBottom ) pBottom->ScaleMetrics( nMult, nDiv );
2286 if ( pLeft ) pLeft->ScaleMetrics( nMult, nDiv );
2287 if ( pRight ) pRight->ScaleMetrics( nMult, nDiv );
2288 nTopDist = (sal_uInt16)Scale( nTopDist, nMult, nDiv );
2289 nBottomDist = (sal_uInt16)Scale( nBottomDist, nMult, nDiv );
2290 nLeftDist = (sal_uInt16)Scale( nLeftDist, nMult, nDiv );
2291 nRightDist = (sal_uInt16)Scale( nRightDist, nMult, nDiv );
2292 return true;
2297 bool SvxBoxItem::HasMetrics() const
2299 return true;
2304 SfxPoolItem* SvxBoxItem::Create( SvStream& rStrm, sal_uInt16 nIVersion ) const
2306 sal_uInt16 nDistance;
2307 rStrm.ReadUInt16( nDistance );
2308 SvxBoxItem* pAttr = new SvxBoxItem( Which() );
2310 SvxBoxItemLine aLineMap[4] = { SvxBoxItemLine::TOP, SvxBoxItemLine::LEFT,
2311 SvxBoxItemLine::RIGHT, SvxBoxItemLine::BOTTOM };
2313 sal_Int8 cLine;
2314 while( true )
2316 rStrm.ReadSChar( cLine );
2318 if( cLine > 3 )
2319 break;
2321 SvxBorderLine aBorder = CreateBorderLine(rStrm, BorderLineVersionFromBoxVersion(nIVersion));
2322 pAttr->SetLine( &aBorder, aLineMap[cLine] );
2325 if( nIVersion >= BOX_4DISTS_VERSION && (cLine&0x10) != 0 )
2327 for( sal_uInt16 i=0; i < 4; i++ )
2329 sal_uInt16 nDist;
2330 rStrm.ReadUInt16( nDist );
2331 pAttr->SetDistance( nDist, aLineMap[i] );
2334 else
2336 pAttr->SetDistance( nDistance );
2339 return pAttr;
2344 const SvxBorderLine *SvxBoxItem::GetLine( SvxBoxItemLine nLine ) const
2346 const SvxBorderLine *pRet = 0;
2348 switch ( nLine )
2350 case SvxBoxItemLine::TOP:
2351 pRet = pTop;
2352 break;
2353 case SvxBoxItemLine::BOTTOM:
2354 pRet = pBottom;
2355 break;
2356 case SvxBoxItemLine::LEFT:
2357 pRet = pLeft;
2358 break;
2359 case SvxBoxItemLine::RIGHT:
2360 pRet = pRight;
2361 break;
2362 default:
2363 OSL_FAIL( "wrong line" );
2364 break;
2367 return pRet;
2372 void SvxBoxItem::SetLine( const SvxBorderLine* pNew, SvxBoxItemLine nLine )
2374 SvxBorderLine* pTmp = pNew ? new SvxBorderLine( *pNew ) : 0;
2376 switch ( nLine )
2378 case SvxBoxItemLine::TOP:
2379 delete pTop;
2380 pTop = pTmp;
2381 break;
2382 case SvxBoxItemLine::BOTTOM:
2383 delete pBottom;
2384 pBottom = pTmp;
2385 break;
2386 case SvxBoxItemLine::LEFT:
2387 delete pLeft;
2388 pLeft = pTmp;
2389 break;
2390 case SvxBoxItemLine::RIGHT:
2391 delete pRight;
2392 pRight = pTmp;
2393 break;
2394 default:
2395 delete pTmp;
2396 OSL_FAIL( "wrong line" );
2402 sal_uInt16 SvxBoxItem::GetDistance() const
2404 // The smallest distance that is not 0 will be returned.
2405 sal_uInt16 nDist = nTopDist;
2406 if( nBottomDist && (!nDist || nBottomDist < nDist) )
2407 nDist = nBottomDist;
2408 if( nLeftDist && (!nDist || nLeftDist < nDist) )
2409 nDist = nLeftDist;
2410 if( nRightDist && (!nDist || nRightDist < nDist) )
2411 nDist = nRightDist;
2413 return nDist;
2418 sal_uInt16 SvxBoxItem::GetDistance( SvxBoxItemLine nLine ) const
2420 sal_uInt16 nDist = 0;
2421 switch ( nLine )
2423 case SvxBoxItemLine::TOP:
2424 nDist = nTopDist;
2425 break;
2426 case SvxBoxItemLine::BOTTOM:
2427 nDist = nBottomDist;
2428 break;
2429 case SvxBoxItemLine::LEFT:
2430 nDist = nLeftDist;
2431 break;
2432 case SvxBoxItemLine::RIGHT:
2433 nDist = nRightDist;
2434 break;
2435 default:
2436 OSL_FAIL( "wrong line" );
2439 return nDist;
2444 void SvxBoxItem::SetDistance( sal_uInt16 nNew, SvxBoxItemLine nLine )
2446 switch ( nLine )
2448 case SvxBoxItemLine::TOP:
2449 nTopDist = nNew;
2450 break;
2451 case SvxBoxItemLine::BOTTOM:
2452 nBottomDist = nNew;
2453 break;
2454 case SvxBoxItemLine::LEFT:
2455 nLeftDist = nNew;
2456 break;
2457 case SvxBoxItemLine::RIGHT:
2458 nRightDist = nNew;
2459 break;
2460 default:
2461 OSL_FAIL( "wrong line" );
2467 sal_uInt16 SvxBoxItem::CalcLineSpace( SvxBoxItemLine nLine, bool bIgnoreLine ) const
2469 SvxBorderLine* pTmp = 0;
2470 sal_uInt16 nDist = 0;
2471 switch ( nLine )
2473 case SvxBoxItemLine::TOP:
2474 pTmp = pTop;
2475 nDist = nTopDist;
2476 break;
2477 case SvxBoxItemLine::BOTTOM:
2478 pTmp = pBottom;
2479 nDist = nBottomDist;
2480 break;
2481 case SvxBoxItemLine::LEFT:
2482 pTmp = pLeft;
2483 nDist = nLeftDist;
2484 break;
2485 case SvxBoxItemLine::RIGHT:
2486 pTmp = pRight;
2487 nDist = nRightDist;
2488 break;
2489 default:
2490 OSL_FAIL( "wrong line" );
2493 if( pTmp )
2495 nDist = nDist + pTmp->GetScaledWidth();
2497 else if( !bIgnoreLine )
2498 nDist = 0;
2499 return nDist;
2502 // class SvxBoxInfoItem --------------------------------------------------
2504 SvxBoxInfoItem::SvxBoxInfoItem( const sal_uInt16 nId ) :
2505 SfxPoolItem( nId ),
2506 pHori ( 0 ),
2507 pVert ( 0 ),
2508 mbEnableHor( false ),
2509 mbEnableVer( false ),
2510 nDefDist( 0 )
2512 bDist = bMinDist = false;
2513 ResetFlags();
2518 SvxBoxInfoItem::SvxBoxInfoItem( const SvxBoxInfoItem& rCpy ) :
2519 SfxPoolItem( rCpy ),
2520 mbEnableHor( rCpy.mbEnableHor ),
2521 mbEnableVer( rCpy.mbEnableVer )
2523 pHori = rCpy.GetHori() ? new SvxBorderLine( *rCpy.GetHori() ) : 0;
2524 pVert = rCpy.GetVert() ? new SvxBorderLine( *rCpy.GetVert() ) : 0;
2525 bDist = rCpy.IsDist();
2526 bMinDist = rCpy.IsMinDist();
2527 nValidFlags = rCpy.nValidFlags;
2528 nDefDist = rCpy.GetDefDist();
2533 SvxBoxInfoItem::~SvxBoxInfoItem()
2535 delete pHori;
2536 delete pVert;
2541 SvxBoxInfoItem &SvxBoxInfoItem::operator=( const SvxBoxInfoItem& rCpy )
2543 delete pHori;
2544 delete pVert;
2545 pHori = rCpy.GetHori() ? new SvxBorderLine( *rCpy.GetHori() ) : 0;
2546 pVert = rCpy.GetVert() ? new SvxBorderLine( *rCpy.GetVert() ) : 0;
2547 mbEnableHor = rCpy.mbEnableHor;
2548 mbEnableVer = rCpy.mbEnableVer;
2549 bDist = rCpy.IsDist();
2550 bMinDist = rCpy.IsMinDist();
2551 nValidFlags = rCpy.nValidFlags;
2552 nDefDist = rCpy.GetDefDist();
2553 return *this;
2558 bool SvxBoxInfoItem::operator==( const SfxPoolItem& rAttr ) const
2560 const SvxBoxInfoItem& rBoxInfo = static_cast<const SvxBoxInfoItem&>(rAttr);
2562 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
2564 return ( mbEnableHor == rBoxInfo.mbEnableHor
2565 && mbEnableVer == rBoxInfo.mbEnableVer
2566 && bDist == rBoxInfo.IsDist()
2567 && bMinDist == rBoxInfo.IsMinDist()
2568 && nValidFlags == rBoxInfo.nValidFlags
2569 && nDefDist == rBoxInfo.GetDefDist()
2570 && CmpBrdLn( pHori, rBoxInfo.GetHori() )
2571 && CmpBrdLn( pVert, rBoxInfo.GetVert() )
2577 void SvxBoxInfoItem::SetLine( const SvxBorderLine* pNew, SvxBoxInfoItemLine nLine )
2579 SvxBorderLine* pTmp = pNew ? new SvxBorderLine( *pNew ) : 0;
2581 if ( SvxBoxInfoItemLine::HORI == nLine )
2583 delete pHori;
2584 pHori = pTmp;
2586 else if ( SvxBoxInfoItemLine::VERT == nLine )
2588 delete pVert;
2589 pVert = pTmp;
2591 else
2593 delete pTmp;
2594 OSL_FAIL( "wrong line" );
2600 SfxPoolItem* SvxBoxInfoItem::Clone( SfxItemPool* ) const
2602 return new SvxBoxInfoItem( *this );
2607 bool SvxBoxInfoItem::GetPresentation
2609 SfxItemPresentation /*ePres*/,
2610 SfxMapUnit /*eCoreUnit*/,
2611 SfxMapUnit /*ePresUnit*/,
2612 OUString& rText, const IntlWrapper *
2613 ) const
2615 rText.clear();
2616 return false;
2621 SvStream& SvxBoxInfoItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
2623 sal_Int8 cFlags = 0;
2625 if ( IsTable() )
2626 cFlags |= 0x01;
2627 if ( IsDist() )
2628 cFlags |= 0x02;
2629 if ( IsMinDist() )
2630 cFlags |= 0x04;
2631 rStrm.WriteSChar( cFlags )
2632 .WriteUInt16( GetDefDist() );
2633 const SvxBorderLine* pLine[ 2 ];
2634 pLine[ 0 ] = GetHori();
2635 pLine[ 1 ] = GetVert();
2637 for( int i = 0; i < 2; i++ )
2639 const SvxBorderLine* l = pLine[ i ];
2640 if( l )
2642 rStrm.WriteChar( (char) i );
2643 WriteColor( rStrm, l->GetColor() );
2644 rStrm.WriteInt16( l->GetOutWidth() )
2645 .WriteInt16( l->GetInWidth() )
2646 .WriteInt16( l->GetDistance() );
2649 rStrm.WriteChar( (char) 2 );
2650 return rStrm;
2655 bool SvxBoxInfoItem::ScaleMetrics( long nMult, long nDiv )
2657 if ( pHori ) pHori->ScaleMetrics( nMult, nDiv );
2658 if ( pVert ) pVert->ScaleMetrics( nMult, nDiv );
2659 nDefDist = (sal_uInt16)Scale( nDefDist, nMult, nDiv );
2660 return true;
2665 bool SvxBoxInfoItem::HasMetrics() const
2667 return true;
2672 SfxPoolItem* SvxBoxInfoItem::Create( SvStream& rStrm, sal_uInt16 ) const
2674 sal_Int8 cFlags;
2675 sal_uInt16 _nDefDist;
2676 rStrm.ReadSChar( cFlags ).ReadUInt16( _nDefDist );
2678 SvxBoxInfoItem* pAttr = new SvxBoxInfoItem( Which() );
2680 pAttr->SetTable ( ( cFlags & 0x01 ) != 0 );
2681 pAttr->SetDist ( ( cFlags & 0x02 ) != 0 );
2682 pAttr->SetMinDist( ( cFlags & 0x04 ) != 0 );
2683 pAttr->SetDefDist( _nDefDist );
2685 while( true )
2687 sal_Int8 cLine;
2688 rStrm.ReadSChar( cLine );
2690 if( cLine > 1 )
2691 break;
2692 short nOutline, nInline, nDistance;
2693 Color aColor;
2694 ReadColor( rStrm, aColor ).ReadInt16( nOutline ).ReadInt16( nInline ).ReadInt16( nDistance );
2695 SvxBorderLine aBorder( &aColor );
2696 aBorder.GuessLinesWidths(css::table::BorderLineStyle::NONE, nOutline, nInline, nDistance);
2698 switch( cLine )
2700 case 0: pAttr->SetLine( &aBorder, SvxBoxInfoItemLine::HORI ); break;
2701 case 1: pAttr->SetLine( &aBorder, SvxBoxInfoItemLine::VERT ); break;
2704 return pAttr;
2709 void SvxBoxInfoItem::ResetFlags()
2711 nValidFlags = static_cast<SvxBoxInfoItemValidFlags>(0x7F); // all valid except Disable
2714 bool SvxBoxInfoItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
2716 bool bConvert = 0 != (nMemberId & CONVERT_TWIPS);
2717 table::BorderLine2 aRetLine;
2718 sal_Int16 nVal=0;
2719 bool bIntMember = false;
2720 nMemberId &= ~CONVERT_TWIPS;
2721 switch(nMemberId)
2723 case 0:
2725 // 2 BorderLines, flags, valid flags and distance
2726 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq( 5 );
2727 aSeq[0] = ::com::sun::star::uno::makeAny( SvxBoxItem::SvxLineToLine( pHori, bConvert) );
2728 aSeq[1] = ::com::sun::star::uno::makeAny( SvxBoxItem::SvxLineToLine( pVert, bConvert) );
2729 if ( IsTable() )
2730 nVal |= 0x01;
2731 if ( IsDist() )
2732 nVal |= 0x02;
2733 if ( IsMinDist() )
2734 nVal |= 0x04;
2735 aSeq[2] = ::com::sun::star::uno::makeAny( nVal );
2736 aSeq[3] = ::com::sun::star::uno::makeAny( static_cast<sal_Int16>(nValidFlags) );
2737 aSeq[4] = ::com::sun::star::uno::makeAny( (sal_Int32)(bConvert ? convertTwipToMm100(GetDefDist()) : GetDefDist()) );
2738 rVal = ::com::sun::star::uno::makeAny( aSeq );
2739 return true;
2742 case MID_HORIZONTAL:
2743 aRetLine = SvxBoxItem::SvxLineToLine( pHori, bConvert);
2744 break;
2745 case MID_VERTICAL:
2746 aRetLine = SvxBoxItem::SvxLineToLine( pVert, bConvert);
2747 break;
2748 case MID_FLAGS:
2749 bIntMember = true;
2750 if ( IsTable() )
2751 nVal |= 0x01;
2752 if ( IsDist() )
2753 nVal |= 0x02;
2754 if ( IsMinDist() )
2755 nVal |= 0x04;
2756 rVal <<= nVal;
2757 break;
2758 case MID_VALIDFLAGS:
2759 bIntMember = true;
2760 rVal <<= static_cast<sal_Int16>(nValidFlags);
2761 break;
2762 case MID_DISTANCE:
2763 bIntMember = true;
2764 rVal <<= (sal_Int32)(bConvert ? convertTwipToMm100(GetDefDist()) : GetDefDist());
2765 break;
2766 default: OSL_FAIL("Wrong MemberId!"); return false;
2769 if( !bIntMember )
2770 rVal <<= aRetLine;
2772 return true;
2777 bool SvxBoxInfoItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
2779 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2780 nMemberId &= ~CONVERT_TWIPS;
2781 bool bRet;
2782 switch(nMemberId)
2784 case 0:
2786 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq;
2787 if (( rVal >>= aSeq ) && ( aSeq.getLength() == 5 ))
2789 // 2 BorderLines, flags, valid flags and distance
2790 if (!lcl_setLine(aSeq[0], *this, SvxBoxInfoItemLine::HORI, bConvert))
2791 return false;
2792 if (!lcl_setLine(aSeq[1], *this, SvxBoxInfoItemLine::VERT, bConvert))
2793 return false;
2795 sal_Int16 nFlags( 0 );
2796 sal_Int32 nVal( 0 );
2797 if ( aSeq[2] >>= nFlags )
2799 SetTable ( ( nFlags & 0x01 ) != 0 );
2800 SetDist ( ( nFlags & 0x02 ) != 0 );
2801 SetMinDist( ( nFlags & 0x04 ) != 0 );
2803 else
2804 return false;
2805 if ( aSeq[3] >>= nFlags )
2806 nValidFlags = static_cast<SvxBoxInfoItemValidFlags>(nFlags);
2807 else
2808 return false;
2809 if (( aSeq[4] >>= nVal ) && ( nVal >= 0 ))
2811 if( bConvert )
2812 nVal = convertMm100ToTwip(nVal);
2813 SetDefDist( (sal_uInt16)nVal );
2816 return true;
2819 case MID_HORIZONTAL:
2820 case MID_VERTICAL:
2822 if( !rVal.hasValue() )
2823 return false;
2825 table::BorderLine2 aBorderLine;
2826 if( lcl_extractBorderLine(rVal, aBorderLine) )
2828 // usual struct
2830 else if (rVal.getValueTypeClass() == uno::TypeClass_SEQUENCE )
2832 // serialization for basic macro recording
2833 uno::Reference < script::XTypeConverter > xConverter( script::Converter::create(::comphelper::getProcessComponentContext()) );
2834 uno::Any aNew;
2835 uno::Sequence < uno::Any > aSeq;
2836 try { aNew = xConverter->convertTo( rVal, cppu::UnoType<uno::Sequence < uno::Any >>::get() ); }
2837 catch (const uno::Exception&) {}
2839 if ((aNew >>= aSeq) &&
2840 aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2842 sal_Int32 nVal = 0;
2843 if ( aSeq[0] >>= nVal )
2844 aBorderLine.Color = nVal;
2845 if ( aSeq[1] >>= nVal )
2846 aBorderLine.InnerLineWidth = (sal_Int16) nVal;
2847 if ( aSeq[2] >>= nVal )
2848 aBorderLine.OuterLineWidth = (sal_Int16) nVal;
2849 if ( aSeq[3] >>= nVal )
2850 aBorderLine.LineDistance = (sal_Int16) nVal;
2851 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2853 if (aSeq[4] >>= nVal)
2855 aBorderLine.LineStyle = nVal;
2857 if (aSeq.getLength() >= 6)
2859 if (aSeq[5] >>= nVal)
2861 aBorderLine.LineWidth = nVal;
2866 else
2867 return false;
2869 else if (rVal.getValueType() == cppu::UnoType<css::uno::Sequence < sal_Int16 >>::get() )
2871 // serialization for basic macro recording
2872 ::com::sun::star::uno::Sequence < sal_Int16 > aSeq;
2873 rVal >>= aSeq;
2874 if (aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2876 aBorderLine.Color = aSeq[0];
2877 aBorderLine.InnerLineWidth = aSeq[1];
2878 aBorderLine.OuterLineWidth = aSeq[2];
2879 aBorderLine.LineDistance = aSeq[3];
2880 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2882 aBorderLine.LineStyle = aSeq[4];
2883 if (aSeq.getLength() >= 6)
2885 aBorderLine.LineWidth = aSeq[5];
2889 else
2890 return false;
2892 else
2893 return false;
2895 SvxBorderLine aLine;
2896 bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
2897 if ( bSet )
2898 SetLine( &aLine, nMemberId == MID_HORIZONTAL ? SvxBoxInfoItemLine::HORI : SvxBoxInfoItemLine::VERT );
2899 break;
2901 case MID_FLAGS:
2903 sal_Int16 nFlags = sal_Int16();
2904 bRet = (rVal >>= nFlags);
2905 if ( bRet )
2907 SetTable ( ( nFlags & 0x01 ) != 0 );
2908 SetDist ( ( nFlags & 0x02 ) != 0 );
2909 SetMinDist( ( nFlags & 0x04 ) != 0 );
2912 break;
2914 case MID_VALIDFLAGS:
2916 sal_Int16 nFlags = sal_Int16();
2917 bRet = (rVal >>= nFlags);
2918 if ( bRet )
2919 nValidFlags = static_cast<SvxBoxInfoItemValidFlags>(nFlags);
2920 break;
2922 case MID_DISTANCE:
2924 sal_Int32 nVal = 0;
2925 bRet = (rVal >>= nVal);
2926 if ( bRet && nVal>=0 )
2928 if( bConvert )
2929 nVal = convertMm100ToTwip(nVal);
2930 SetDefDist( (sal_uInt16)nVal );
2932 break;
2934 default: OSL_FAIL("Wrong MemberId!"); return false;
2937 return true;
2940 // class SvxFormatBreakItem -------------------------------------------------
2942 bool SvxFormatBreakItem::operator==( const SfxPoolItem& rAttr ) const
2944 DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "unequal types" );
2946 return GetValue() == static_cast<const SvxFormatBreakItem&>( rAttr ).GetValue();
2951 bool SvxFormatBreakItem::GetPresentation
2953 SfxItemPresentation /*ePres*/,
2954 SfxMapUnit /*eCoreUnit*/,
2955 SfxMapUnit /*ePresUnit*/,
2956 OUString& rText, const IntlWrapper *
2957 ) const
2959 rText = GetValueTextByPos( GetValue() );
2960 return true;
2965 OUString SvxFormatBreakItem::GetValueTextByPos( sal_uInt16 nPos ) const
2967 DBG_ASSERT( nPos < SVX_BREAK_END, "enum overflow!" );
2968 return EE_RESSTR(RID_SVXITEMS_BREAK_BEGIN + nPos);
2972 bool SvxFormatBreakItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
2974 style::BreakType eBreak = style::BreakType_NONE;
2975 switch ( (SvxBreak)GetValue() )
2977 case SVX_BREAK_COLUMN_BEFORE: eBreak = style::BreakType_COLUMN_BEFORE; break;
2978 case SVX_BREAK_COLUMN_AFTER: eBreak = style::BreakType_COLUMN_AFTER ; break;
2979 case SVX_BREAK_COLUMN_BOTH: eBreak = style::BreakType_COLUMN_BOTH ; break;
2980 case SVX_BREAK_PAGE_BEFORE: eBreak = style::BreakType_PAGE_BEFORE ; break;
2981 case SVX_BREAK_PAGE_AFTER: eBreak = style::BreakType_PAGE_AFTER ; break;
2982 case SVX_BREAK_PAGE_BOTH: eBreak = style::BreakType_PAGE_BOTH ; break;
2983 default: ;//prevent warning
2985 rVal <<= eBreak;
2986 return true;
2989 bool SvxFormatBreakItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
2991 style::BreakType nBreak;
2993 if(!(rVal >>= nBreak))
2995 sal_Int32 nValue = 0;
2996 if(!(rVal >>= nValue))
2997 return false;
2999 nBreak = (style::BreakType) nValue;
3002 SvxBreak eBreak = SVX_BREAK_NONE;
3003 switch( nBreak )
3005 case style::BreakType_COLUMN_BEFORE: eBreak = SVX_BREAK_COLUMN_BEFORE; break;
3006 case style::BreakType_COLUMN_AFTER: eBreak = SVX_BREAK_COLUMN_AFTER; break;
3007 case style::BreakType_COLUMN_BOTH: eBreak = SVX_BREAK_COLUMN_BOTH; break;
3008 case style::BreakType_PAGE_BEFORE: eBreak = SVX_BREAK_PAGE_BEFORE; break;
3009 case style::BreakType_PAGE_AFTER: eBreak = SVX_BREAK_PAGE_AFTER; break;
3010 case style::BreakType_PAGE_BOTH: eBreak = SVX_BREAK_PAGE_BOTH; break;
3011 default: ;//prevent warning
3013 SetValue((sal_uInt16) eBreak);
3015 return true;
3020 SfxPoolItem* SvxFormatBreakItem::Clone( SfxItemPool* ) const
3022 return new SvxFormatBreakItem( *this );
3027 SvStream& SvxFormatBreakItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
3029 rStrm.WriteSChar( GetValue() );
3030 if( FMTBREAK_NOAUTO > nItemVersion )
3031 rStrm.WriteSChar( 0x01 );
3032 return rStrm;
3037 sal_uInt16 SvxFormatBreakItem::GetVersion( sal_uInt16 nFFVer ) const
3039 DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
3040 SOFFICE_FILEFORMAT_40==nFFVer ||
3041 SOFFICE_FILEFORMAT_50==nFFVer,
3042 "SvxFormatBreakItem: Is there a new file format? ");
3043 return SOFFICE_FILEFORMAT_31==nFFVer ||
3044 SOFFICE_FILEFORMAT_40==nFFVer ? 0 : FMTBREAK_NOAUTO;
3049 SfxPoolItem* SvxFormatBreakItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
3051 sal_Int8 eBreak, bDummy;
3052 rStrm.ReadSChar( eBreak );
3053 if( FMTBREAK_NOAUTO > nVersion )
3054 rStrm.ReadSChar( bDummy );
3055 return new SvxFormatBreakItem( (const SvxBreak)eBreak, Which() );
3060 sal_uInt16 SvxFormatBreakItem::GetValueCount() const
3062 return SVX_BREAK_END; // SVX_BREAK_PAGE_BOTH + 1
3065 // class SvxFormatKeepItem -------------------------------------------------
3067 SfxPoolItem* SvxFormatKeepItem::Clone( SfxItemPool* ) const
3069 return new SvxFormatKeepItem( *this );
3074 SvStream& SvxFormatKeepItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
3076 rStrm.WriteSChar( (sal_Int8)GetValue() );
3077 return rStrm;
3082 SfxPoolItem* SvxFormatKeepItem::Create( SvStream& rStrm, sal_uInt16 ) const
3084 sal_Int8 bIsKeep;
3085 rStrm.ReadSChar( bIsKeep );
3086 return new SvxFormatKeepItem( bIsKeep != 0, Which() );
3091 bool SvxFormatKeepItem::GetPresentation
3093 SfxItemPresentation /*ePres*/,
3094 SfxMapUnit /*eCoreUnit*/,
3095 SfxMapUnit /*ePresUnit*/,
3096 OUString& rText, const IntlWrapper *
3097 ) const
3099 sal_uInt16 nId = RID_SVXITEMS_FMTKEEP_FALSE;
3101 if ( GetValue() )
3102 nId = RID_SVXITEMS_FMTKEEP_TRUE;
3103 rText = EE_RESSTR(nId);
3104 return true;
3107 // class SvxLineItem ------------------------------------------------------
3109 SvxLineItem::SvxLineItem( const sal_uInt16 nId ) :
3111 SfxPoolItem ( nId ),
3113 pLine( NULL )
3119 SvxLineItem::SvxLineItem( const SvxLineItem& rCpy ) :
3121 SfxPoolItem ( rCpy )
3123 pLine = rCpy.GetLine() ? new SvxBorderLine( *rCpy.GetLine() ) : 0;
3128 SvxLineItem::~SvxLineItem()
3130 delete pLine;
3135 SvxLineItem& SvxLineItem::operator=( const SvxLineItem& rLine )
3137 SetLine( rLine.GetLine() );
3139 return *this;
3144 bool SvxLineItem::operator==( const SfxPoolItem& rAttr ) const
3146 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
3148 return CmpBrdLn( pLine, static_cast<const SvxLineItem&>(rAttr).GetLine() );
3153 SfxPoolItem* SvxLineItem::Clone( SfxItemPool* ) const
3155 return new SvxLineItem( *this );
3158 bool SvxLineItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemId ) const
3160 bool bConvert = 0!=(nMemId&CONVERT_TWIPS);
3161 nMemId &= ~CONVERT_TWIPS;
3162 if ( nMemId == 0 )
3164 rVal <<= uno::makeAny( SvxBoxItem::SvxLineToLine(pLine, bConvert) );
3165 return true;
3167 else if ( pLine )
3169 switch ( nMemId )
3171 case MID_FG_COLOR: rVal <<= sal_Int32(pLine->GetColor().GetColor()); break;
3172 case MID_OUTER_WIDTH: rVal <<= sal_Int32(pLine->GetOutWidth()); break;
3173 case MID_INNER_WIDTH: rVal <<= sal_Int32(pLine->GetInWidth( )); break;
3174 case MID_DISTANCE: rVal <<= sal_Int32(pLine->GetDistance()); break;
3175 default:
3176 OSL_FAIL( "Wrong MemberId" );
3177 return false;
3181 return true;
3186 bool SvxLineItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemId )
3188 bool bConvert = 0!=(nMemId&CONVERT_TWIPS);
3189 nMemId &= ~CONVERT_TWIPS;
3190 sal_Int32 nVal = 0;
3191 if ( nMemId == 0 )
3193 table::BorderLine2 aLine;
3194 if ( lcl_extractBorderLine(rVal, aLine) )
3196 if ( !pLine )
3197 pLine = new SvxBorderLine;
3198 if( !SvxBoxItem::LineToSvxLine(aLine, *pLine, bConvert) )
3199 DELETEZ( pLine );
3200 return true;
3202 return false;
3204 else if ( rVal >>= nVal )
3206 if ( !pLine )
3207 pLine = new SvxBorderLine;
3209 switch ( nMemId )
3211 case MID_FG_COLOR: pLine->SetColor( Color(nVal) ); break;
3212 case MID_LINE_STYLE:
3213 pLine->SetBorderLineStyle(static_cast<SvxBorderStyle>(nVal));
3214 break;
3215 default:
3216 OSL_FAIL( "Wrong MemberId" );
3217 return false;
3220 return true;
3223 return false;
3228 bool SvxLineItem::GetPresentation
3230 SfxItemPresentation ePres,
3231 SfxMapUnit eCoreUnit,
3232 SfxMapUnit ePresUnit,
3233 OUString& rText, const IntlWrapper *pIntl
3234 ) const
3236 rText.clear();
3238 if ( pLine )
3239 rText = pLine->GetValueString( eCoreUnit, ePresUnit, pIntl,
3240 (SFX_ITEM_PRESENTATION_COMPLETE == ePres) );
3241 return true;
3246 SvStream& SvxLineItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
3248 if( pLine )
3250 WriteColor( rStrm, pLine->GetColor() );
3251 rStrm.WriteInt16( pLine->GetOutWidth() )
3252 .WriteInt16( pLine->GetInWidth() )
3253 .WriteInt16( pLine->GetDistance() );
3255 else
3257 WriteColor( rStrm, Color() );
3258 rStrm.WriteInt16( 0 ).WriteInt16( 0 ).WriteInt16( 0 );
3260 return rStrm;
3265 bool SvxLineItem::ScaleMetrics( long nMult, long nDiv )
3267 if ( pLine ) pLine->ScaleMetrics( nMult, nDiv );
3268 return true;
3273 bool SvxLineItem::HasMetrics() const
3275 return true;
3280 SfxPoolItem* SvxLineItem::Create( SvStream& rStrm, sal_uInt16 ) const
3282 SvxLineItem* _pLine = new SvxLineItem( Which() );
3283 short nOutline, nInline, nDistance;
3284 Color aColor;
3286 ReadColor( rStrm, aColor ).ReadInt16( nOutline ).ReadInt16( nInline ).ReadInt16( nDistance );
3287 if( nOutline )
3289 SvxBorderLine aLine( &aColor );
3290 aLine.GuessLinesWidths(css::table::BorderLineStyle::NONE, nOutline, nInline, nDistance);
3291 _pLine->SetLine( &aLine );
3293 return _pLine;
3298 void SvxLineItem::SetLine( const SvxBorderLine* pNew )
3300 delete pLine;
3301 pLine = pNew ? new SvxBorderLine( *pNew ) : 0;
3304 // class SvxBrushItem ----------------------------------------------------
3306 #define LOAD_GRAPHIC ((sal_uInt16)0x0001)
3307 #define LOAD_LINK ((sal_uInt16)0x0002)
3308 #define LOAD_FILTER ((sal_uInt16)0x0004)
3310 // class SvxBrushItem_Impl -----------------------------------------------
3312 class SvxBrushItem_Impl
3314 public:
3315 GraphicObject* pGraphicObject;
3316 sal_Int8 nGraphicTransparency; //contains a percentage value which is
3317 //copied to the GraphicObject when necessary
3318 Link<> aDoneLink;
3319 SvStream* pStream;
3321 SvxBrushItem_Impl( GraphicObject* p ) : pGraphicObject( p ), nGraphicTransparency(0), pStream(0) {}
3326 void SvxBrushItem::SetDoneLink( const Link<>& rLink )
3328 pImpl->aDoneLink = rLink;
3333 SvxBrushItem::SvxBrushItem( sal_uInt16 _nWhich ) :
3335 SfxPoolItem( _nWhich ),
3337 aColor ( COL_TRANSPARENT ),
3338 nShadingValue ( ShadingPattern::CLEAR ),
3339 pImpl ( new SvxBrushItem_Impl( 0 ) ),
3340 maStrLink (),
3341 maStrFilter (),
3342 eGraphicPos ( GPOS_NONE ),
3343 bLoadAgain ( true )
3350 SvxBrushItem::SvxBrushItem( const Color& rColor, sal_uInt16 _nWhich) :
3352 SfxPoolItem( _nWhich ),
3354 aColor ( rColor ),
3355 nShadingValue ( ShadingPattern::CLEAR ),
3356 pImpl ( new SvxBrushItem_Impl( 0 ) ),
3357 maStrLink (),
3358 maStrFilter (),
3359 eGraphicPos ( GPOS_NONE ),
3360 bLoadAgain ( true )
3367 SvxBrushItem::SvxBrushItem( const Graphic& rGraphic, SvxGraphicPosition ePos,
3368 sal_uInt16 _nWhich ) :
3370 SfxPoolItem( _nWhich ),
3372 aColor ( COL_TRANSPARENT ),
3373 nShadingValue ( ShadingPattern::CLEAR ),
3374 pImpl ( new SvxBrushItem_Impl( new GraphicObject( rGraphic ) ) ),
3375 maStrLink (),
3376 maStrFilter (),
3377 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3378 bLoadAgain ( true )
3381 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3386 SvxBrushItem::SvxBrushItem( const GraphicObject& rGraphicObj,
3387 SvxGraphicPosition ePos, sal_uInt16 _nWhich ) :
3389 SfxPoolItem( _nWhich ),
3391 aColor ( COL_TRANSPARENT ),
3392 nShadingValue ( ShadingPattern::CLEAR ),
3393 pImpl ( new SvxBrushItem_Impl( new GraphicObject( rGraphicObj ) ) ),
3394 maStrLink (),
3395 maStrFilter (),
3396 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3397 bLoadAgain ( true )
3400 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3405 SvxBrushItem::SvxBrushItem(
3406 const OUString& rLink, const OUString& rFilter,
3407 SvxGraphicPosition ePos, sal_uInt16 _nWhich ) :
3409 SfxPoolItem( _nWhich ),
3411 aColor ( COL_TRANSPARENT ),
3412 nShadingValue ( ShadingPattern::CLEAR ),
3413 pImpl ( new SvxBrushItem_Impl( NULL ) ),
3414 maStrLink ( rLink ),
3415 maStrFilter ( rFilter ),
3416 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3417 bLoadAgain ( true )
3420 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3425 SvxBrushItem::SvxBrushItem( SvStream& rStream, sal_uInt16 nVersion,
3426 sal_uInt16 _nWhich )
3427 : SfxPoolItem( _nWhich )
3428 , aColor ( COL_TRANSPARENT )
3429 , nShadingValue ( ShadingPattern::CLEAR )
3430 , pImpl ( new SvxBrushItem_Impl( NULL ) )
3431 , maStrLink ()
3432 , maStrFilter ()
3433 , eGraphicPos ( GPOS_NONE )
3434 , bLoadAgain (false)
3436 bool bTrans;
3437 Color aTempColor;
3438 Color aTempFillColor;
3439 sal_Int8 nStyle;
3441 rStream.ReadCharAsBool( bTrans );
3442 ReadColor( rStream, aTempColor );
3443 ReadColor( rStream, aTempFillColor );
3444 rStream.ReadSChar( nStyle );
3446 switch ( nStyle )
3448 case 8://BRUSH_25:
3450 sal_uInt32 nRed = aTempColor.GetRed();
3451 sal_uInt32 nGreen = aTempColor.GetGreen();
3452 sal_uInt32 nBlue = aTempColor.GetBlue();
3453 nRed += (sal_uInt32)(aTempFillColor.GetRed())*2;
3454 nGreen += (sal_uInt32)(aTempFillColor.GetGreen())*2;
3455 nBlue += (sal_uInt32)(aTempFillColor.GetBlue())*2;
3456 aColor = Color( (sal_Int8)(nRed/3), (sal_Int8)(nGreen/3), (sal_Int8)(nBlue/3) );
3458 break;
3460 case 9://BRUSH_50:
3462 sal_uInt32 nRed = aTempColor.GetRed();
3463 sal_uInt32 nGreen = aTempColor.GetGreen();
3464 sal_uInt32 nBlue = aTempColor.GetBlue();
3465 nRed += (sal_uInt32)(aTempFillColor.GetRed());
3466 nGreen += (sal_uInt32)(aTempFillColor.GetGreen());
3467 nBlue += (sal_uInt32)(aTempFillColor.GetBlue());
3468 aColor = Color( (sal_Int8)(nRed/2), (sal_Int8)(nGreen/2), (sal_Int8)(nBlue/2) );
3470 break;
3472 case 10://BRUSH_75:
3474 sal_uInt32 nRed = aTempColor.GetRed()*2;
3475 sal_uInt32 nGreen = aTempColor.GetGreen()*2;
3476 sal_uInt32 nBlue = aTempColor.GetBlue()*2;
3477 nRed += (sal_uInt32)(aTempFillColor.GetRed());
3478 nGreen += (sal_uInt32)(aTempFillColor.GetGreen());
3479 nBlue += (sal_uInt32)(aTempFillColor.GetBlue());
3480 aColor = Color( (sal_Int8)(nRed/3), (sal_Int8)(nGreen/3), (sal_Int8)(nBlue/3) );
3482 break;
3484 case 0://BRUSH_NULL:
3485 aColor = Color( COL_TRANSPARENT );
3486 break;
3488 default:
3489 aColor = aTempColor;
3492 if ( nVersion >= BRUSH_GRAPHIC_VERSION )
3494 sal_uInt16 nDoLoad = 0;
3495 sal_Int8 nPos;
3497 rStream.ReadUInt16( nDoLoad );
3499 if ( nDoLoad & LOAD_GRAPHIC )
3501 Graphic aGraphic;
3503 ReadGraphic( rStream, aGraphic );
3504 pImpl->pGraphicObject = new GraphicObject( aGraphic );
3506 if( SVSTREAM_FILEFORMAT_ERROR == rStream.GetError() )
3508 rStream.ResetError();
3509 rStream.SetError( ERRCODE_SVX_GRAPHIC_WRONG_FILEFORMAT|
3510 ERRCODE_WARNING_MASK );
3514 if ( nDoLoad & LOAD_LINK )
3516 // UNICODE: rStream >> aRel;
3517 OUString aRel = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
3519 // TODO/MBA: how can we get a BaseURL here?!
3520 OSL_FAIL("No BaseURL!");
3521 OUString aAbs = INetURLObject::GetAbsURL( "", aRel );
3522 DBG_ASSERT( !aAbs.isEmpty(), "Invalid URL!" );
3523 maStrLink = aAbs;
3526 if ( nDoLoad & LOAD_FILTER )
3528 // UNICODE: rStream >> maStrFilter;
3529 maStrFilter = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
3532 rStream.ReadSChar( nPos );
3534 eGraphicPos = (SvxGraphicPosition)nPos;
3540 SvxBrushItem::SvxBrushItem( const SvxBrushItem& rItem ) :
3542 SfxPoolItem( rItem.Which() ),
3543 nShadingValue ( ShadingPattern::CLEAR ),
3544 pImpl ( new SvxBrushItem_Impl( NULL ) ),
3545 maStrLink (),
3546 maStrFilter (),
3547 eGraphicPos ( GPOS_NONE ),
3548 bLoadAgain ( true )
3551 *this = rItem;
3556 SvxBrushItem::~SvxBrushItem()
3558 delete pImpl->pGraphicObject;
3559 delete pImpl;
3564 sal_uInt16 SvxBrushItem::GetVersion( sal_uInt16 /*nFileVersion*/ ) const
3566 return BRUSH_GRAPHIC_VERSION;
3570 static inline sal_Int8 lcl_PercentToTransparency(long nPercent)
3572 //0xff must not be returned!
3573 return sal_Int8(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
3575 sal_Int8 SvxBrushItem::TransparencyToPercent(sal_Int32 nTrans)
3577 return (sal_Int8)((nTrans * 100 + 127) / 254);
3580 bool SvxBrushItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
3582 nMemberId &= ~CONVERT_TWIPS;
3583 switch( nMemberId)
3585 case MID_BACK_COLOR:
3586 rVal <<= (sal_Int32)( aColor.GetColor() );
3587 break;
3588 case MID_BACK_COLOR_R_G_B:
3589 rVal <<= (sal_Int32)( aColor.GetRGBColor() );
3590 break;
3591 case MID_BACK_COLOR_TRANSPARENCY:
3592 rVal <<= SvxBrushItem::TransparencyToPercent(aColor.GetTransparency());
3593 break;
3594 case MID_GRAPHIC_POSITION:
3595 rVal <<= (style::GraphicLocation)(sal_Int16)eGraphicPos;
3596 break;
3598 case MID_GRAPHIC:
3599 SAL_WARN( "editeng.items", "not implemented" );
3600 break;
3602 case MID_GRAPHIC_TRANSPARENT:
3603 rVal = Bool2Any( aColor.GetTransparency() == 0xff );
3604 break;
3606 case MID_GRAPHIC_URL:
3608 OUString sLink;
3609 if ( !maStrLink.isEmpty() )
3610 sLink = maStrLink;
3611 else if( pImpl->pGraphicObject )
3613 OUString sPrefix(
3614 UNO_NAME_GRAPHOBJ_URLPREFIX);
3615 OUString sId(OStringToOUString(
3616 pImpl->pGraphicObject->GetUniqueID(),
3617 RTL_TEXTENCODING_ASCII_US));
3618 sLink = sPrefix + sId;
3620 rVal <<= sLink;
3622 break;
3624 case MID_GRAPHIC_FILTER:
3626 rVal <<= maStrFilter;
3628 break;
3630 case MID_GRAPHIC_TRANSPARENCY:
3631 rVal <<= pImpl->nGraphicTransparency;
3632 break;
3634 case MID_SHADING_VALUE:
3636 rVal <<= nShadingValue;
3638 break;
3641 return true;
3646 bool SvxBrushItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
3648 nMemberId &= ~CONVERT_TWIPS;
3649 switch( nMemberId)
3651 case MID_BACK_COLOR:
3652 case MID_BACK_COLOR_R_G_B:
3654 sal_Int32 nCol = 0;
3655 if ( !( rVal >>= nCol ) )
3656 return false;
3657 if(MID_BACK_COLOR_R_G_B == nMemberId)
3659 nCol = COLORDATA_RGB( nCol );
3660 nCol += aColor.GetColor() & 0xff000000;
3662 aColor = Color( nCol );
3664 break;
3665 case MID_BACK_COLOR_TRANSPARENCY:
3667 sal_Int32 nTrans = 0;
3668 if ( !( rVal >>= nTrans ) || nTrans < 0 || nTrans > 100 )
3669 return false;
3670 aColor.SetTransparency(lcl_PercentToTransparency(nTrans));
3672 break;
3674 case MID_GRAPHIC_POSITION:
3676 style::GraphicLocation eLocation;
3677 if ( !( rVal>>=eLocation ) )
3679 sal_Int32 nValue = 0;
3680 if ( !( rVal >>= nValue ) )
3681 return false;
3682 eLocation = (style::GraphicLocation)nValue;
3684 SetGraphicPos( (SvxGraphicPosition)(sal_uInt16)eLocation );
3686 break;
3688 case MID_GRAPHIC:
3689 SAL_WARN( "editeng.items", "not implemented" );
3690 break;
3692 case MID_GRAPHIC_TRANSPARENT:
3693 aColor.SetTransparency( Any2Bool( rVal ) ? 0xff : 0 );
3694 break;
3696 case MID_GRAPHIC_URL:
3698 if ( rVal.getValueType() == ::cppu::UnoType<OUString>::get() )
3700 OUString sLink;
3701 rVal >>= sLink;
3702 if( sLink.startsWith( UNO_NAME_GRAPHOBJ_URLPKGPREFIX ) )
3704 OSL_FAIL( "package urls aren't implemented" );
3706 else if( sLink.startsWith( UNO_NAME_GRAPHOBJ_URLPREFIX ) )
3708 maStrLink.clear();
3709 OString sId(OUStringToOString(sLink.copy( sizeof(UNO_NAME_GRAPHOBJ_URLPREFIX)-1 ),
3710 RTL_TEXTENCODING_ASCII_US));
3711 GraphicObject *pOldGrfObj = pImpl->pGraphicObject;
3712 pImpl->pGraphicObject = new GraphicObject( sId );
3713 ApplyGraphicTransparency_Impl();
3714 delete pOldGrfObj;
3716 else
3718 SetGraphicLink(sLink);
3720 if ( !sLink.isEmpty() && eGraphicPos == GPOS_NONE )
3721 eGraphicPos = GPOS_MM;
3722 else if( sLink.isEmpty() )
3723 eGraphicPos = GPOS_NONE;
3726 break;
3728 case MID_GRAPHIC_FILTER:
3730 if( rVal.getValueType() == ::cppu::UnoType<OUString>::get() )
3732 OUString sLink;
3733 rVal >>= sLink;
3734 SetGraphicFilter( sLink );
3737 break;
3738 case MID_GRAPHIC_TRANSPARENCY :
3740 sal_Int32 nTmp = 0;
3741 rVal >>= nTmp;
3742 if(nTmp >= 0 && nTmp <= 100)
3744 pImpl->nGraphicTransparency = sal_Int8(nTmp);
3745 if(pImpl->pGraphicObject)
3746 ApplyGraphicTransparency_Impl();
3749 break;
3751 case MID_SHADING_VALUE:
3753 sal_Int32 nVal = 0;
3754 if (!(rVal >>= nVal))
3755 return false;
3757 SetShadingValue( nVal );
3759 break;
3762 return true;
3767 bool SvxBrushItem::GetPresentation
3769 SfxItemPresentation /*ePres*/,
3770 SfxMapUnit /*eCoreUnit*/,
3771 SfxMapUnit /*ePresUnit*/,
3772 OUString& rText, const IntlWrapper *
3773 ) const
3775 if ( GPOS_NONE == eGraphicPos )
3777 rText = ::GetColorString( aColor ) + OUString(cpDelim);
3778 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
3780 if ( aColor.GetTransparency() )
3781 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
3782 rText += EE_RESSTR(nId);
3784 else
3786 rText = EE_RESSTR(RID_SVXITEMS_GRAPHIC);
3789 return true;
3794 SvxBrushItem& SvxBrushItem::operator=( const SvxBrushItem& rItem )
3796 aColor = rItem.aColor;
3797 eGraphicPos = rItem.eGraphicPos;
3799 DELETEZ( pImpl->pGraphicObject );
3800 maStrLink.clear();
3801 maStrFilter.clear();
3803 if ( GPOS_NONE != eGraphicPos )
3805 maStrLink = rItem.maStrLink;
3806 maStrFilter = rItem.maStrFilter;
3807 if ( rItem.pImpl->pGraphicObject )
3809 pImpl->pGraphicObject = new GraphicObject( *rItem.pImpl->pGraphicObject );
3813 nShadingValue = rItem.nShadingValue;
3815 pImpl->nGraphicTransparency = rItem.pImpl->nGraphicTransparency;
3816 return *this;
3821 bool SvxBrushItem::operator==( const SfxPoolItem& rAttr ) const
3823 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
3825 const SvxBrushItem& rCmp = static_cast<const SvxBrushItem&>(rAttr);
3826 bool bEqual = ( aColor == rCmp.aColor && eGraphicPos == rCmp.eGraphicPos &&
3827 pImpl->nGraphicTransparency == rCmp.pImpl->nGraphicTransparency);
3829 if ( bEqual )
3831 if ( GPOS_NONE != eGraphicPos )
3833 bEqual = maStrLink == rCmp.maStrLink;
3835 if ( bEqual )
3837 bEqual = maStrFilter == rCmp.maStrFilter;
3840 if ( bEqual )
3842 if ( !rCmp.pImpl->pGraphicObject )
3843 bEqual = !pImpl->pGraphicObject;
3844 else
3845 bEqual = pImpl->pGraphicObject &&
3846 ( *pImpl->pGraphicObject == *rCmp.pImpl->pGraphicObject );
3850 if (bEqual)
3852 bEqual = nShadingValue == rCmp.nShadingValue;
3856 return bEqual;
3861 SfxPoolItem* SvxBrushItem::Clone( SfxItemPool* ) const
3863 return new SvxBrushItem( *this );
3868 SfxPoolItem* SvxBrushItem::Create( SvStream& rStream, sal_uInt16 nVersion ) const
3870 return new SvxBrushItem( rStream, nVersion, Which() );
3875 SvStream& SvxBrushItem::Store( SvStream& rStream , sal_uInt16 /*nItemVersion*/ ) const
3877 rStream.WriteBool( false );
3878 WriteColor( rStream, aColor );
3879 WriteColor( rStream, aColor );
3880 rStream.WriteSChar( aColor.GetTransparency() > 0 ? 0 : 1 ); //BRUSH_NULL : BRUSH_SOLID
3882 sal_uInt16 nDoLoad = 0;
3884 if ( pImpl->pGraphicObject && maStrLink.isEmpty() )
3885 nDoLoad |= LOAD_GRAPHIC;
3886 if ( !maStrLink.isEmpty() )
3887 nDoLoad |= LOAD_LINK;
3888 if ( !maStrFilter.isEmpty() )
3889 nDoLoad |= LOAD_FILTER;
3890 rStream.WriteUInt16( nDoLoad );
3892 if ( pImpl->pGraphicObject && maStrLink.isEmpty() )
3893 WriteGraphic( rStream, pImpl->pGraphicObject->GetGraphic() );
3894 if ( !maStrLink.isEmpty() )
3896 OSL_FAIL("No BaseURL!");
3897 // TODO/MBA: how to get a BaseURL?!
3898 OUString aRel = INetURLObject::GetRelURL( "", maStrLink );
3899 // UNICODE: rStream << aRel;
3900 rStream.WriteUniOrByteString(aRel, rStream.GetStreamCharSet());
3902 if ( !maStrFilter.isEmpty() )
3904 // UNICODE: rStream << maStrFilter;
3905 rStream.WriteUniOrByteString(maStrFilter, rStream.GetStreamCharSet());
3907 rStream.WriteSChar( eGraphicPos );
3908 return rStream;
3913 void SvxBrushItem::PurgeMedium() const
3915 DELETEZ( pImpl->pStream );
3919 const GraphicObject* SvxBrushItem::GetGraphicObject(OUString const & referer) const
3921 if ( bLoadAgain && !maStrLink.isEmpty() && !pImpl->pGraphicObject )
3922 // when graphics already loaded, use as a cache
3924 if (SvtSecurityOptions().isUntrustedReferer(referer)) {
3925 return 0;
3927 pImpl->pStream = utl::UcbStreamHelper::CreateStream( maStrLink, STREAM_STD_READ );
3928 if( pImpl->pStream && !pImpl->pStream->GetError() )
3930 Graphic aGraphic;
3931 int nRes;
3932 pImpl->pStream->Seek( STREAM_SEEK_TO_BEGIN );
3933 nRes = GraphicFilter::GetGraphicFilter().
3934 ImportGraphic( aGraphic, maStrLink, *pImpl->pStream,
3935 GRFILTER_FORMAT_DONTKNOW, NULL, GraphicFilterImportFlags::DontSetLogsizeForJpeg );
3937 if( nRes != GRFILTER_OK )
3939 bLoadAgain = false;
3941 else
3943 pImpl->pGraphicObject = new GraphicObject;
3944 pImpl->pGraphicObject->SetGraphic( aGraphic );
3945 const_cast < SvxBrushItem*> (this)->ApplyGraphicTransparency_Impl();
3948 else
3950 bLoadAgain = false;
3954 return pImpl->pGraphicObject;
3957 //UUUU
3958 sal_Int8 SvxBrushItem::getGraphicTransparency() const
3960 return pImpl->nGraphicTransparency;
3963 // -----------------------------------------------------------------------
3964 //UUUU
3965 void SvxBrushItem::setGraphicTransparency(sal_Int8 nNew)
3967 if(nNew != pImpl->nGraphicTransparency)
3969 pImpl->nGraphicTransparency = nNew;
3970 ApplyGraphicTransparency_Impl();
3974 // -----------------------------------------------------------------------
3977 const Graphic* SvxBrushItem::GetGraphic(OUString const & referer) const
3979 const GraphicObject* pGrafObj = GetGraphicObject(referer);
3980 return( pGrafObj ? &( pGrafObj->GetGraphic() ) : NULL );
3985 void SvxBrushItem::SetGraphicPos( SvxGraphicPosition eNew )
3987 eGraphicPos = eNew;
3989 if ( GPOS_NONE == eGraphicPos )
3991 DELETEZ( pImpl->pGraphicObject );
3992 maStrLink.clear();
3993 maStrFilter.clear();
3995 else
3997 if ( !pImpl->pGraphicObject && maStrLink.isEmpty() )
3999 pImpl->pGraphicObject = new GraphicObject; // Creating a dummy
4006 void SvxBrushItem::SetGraphic( const Graphic& rNew )
4008 if ( maStrLink.isEmpty() )
4010 if ( pImpl->pGraphicObject )
4011 pImpl->pGraphicObject->SetGraphic( rNew );
4012 else
4013 pImpl->pGraphicObject = new GraphicObject( rNew );
4015 ApplyGraphicTransparency_Impl();
4017 if ( GPOS_NONE == eGraphicPos )
4018 eGraphicPos = GPOS_MM; // None would be brush, then Default: middle
4020 else
4022 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
4028 void SvxBrushItem::SetGraphicObject( const GraphicObject& rNewObj )
4030 if ( maStrLink.isEmpty() )
4032 if ( pImpl->pGraphicObject )
4033 *pImpl->pGraphicObject = rNewObj;
4034 else
4035 pImpl->pGraphicObject = new GraphicObject( rNewObj );
4037 ApplyGraphicTransparency_Impl();
4039 if ( GPOS_NONE == eGraphicPos )
4040 eGraphicPos = GPOS_MM; // None would be brush, then Default: middle
4042 else
4044 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
4050 void SvxBrushItem::SetGraphicLink( const OUString& rNew )
4052 if ( rNew.isEmpty() )
4053 maStrLink.clear();
4054 else
4056 maStrLink = rNew;
4057 DELETEZ( pImpl->pGraphicObject );
4063 void SvxBrushItem::SetGraphicFilter( const OUString& rNew )
4065 maStrFilter = rNew;
4068 void SvxBrushItem::SetShadingValue( const sal_Int32 nNew )
4070 nShadingValue = nNew;
4073 //static
4074 SvxGraphicPosition SvxBrushItem::WallpaperStyle2GraphicPos( WallpaperStyle eStyle )
4076 SvxGraphicPosition eResult;
4077 // The switch is not the fastest, but the safest
4078 switch( eStyle )
4080 case WALLPAPER_NULL: eResult = GPOS_NONE; break;
4081 case WALLPAPER_TILE: eResult = GPOS_TILED; break;
4082 case WALLPAPER_CENTER: eResult = GPOS_MM; break;
4083 case WALLPAPER_SCALE: eResult = GPOS_AREA; break;
4084 case WALLPAPER_TOPLEFT: eResult = GPOS_LT; break;
4085 case WALLPAPER_TOP: eResult = GPOS_MT; break;
4086 case WALLPAPER_TOPRIGHT: eResult = GPOS_RT; break;
4087 case WALLPAPER_LEFT: eResult = GPOS_LM; break;
4088 case WALLPAPER_RIGHT: eResult = GPOS_RM; break;
4089 case WALLPAPER_BOTTOMLEFT: eResult = GPOS_LB; break;
4090 case WALLPAPER_BOTTOM: eResult = GPOS_MB; break;
4091 case WALLPAPER_BOTTOMRIGHT: eResult = GPOS_RB; break;
4092 default: eResult = GPOS_NONE;
4094 return eResult;
4097 //static
4098 WallpaperStyle SvxBrushItem::GraphicPos2WallpaperStyle( SvxGraphicPosition ePos )
4100 WallpaperStyle eResult;
4101 switch( ePos )
4103 case GPOS_NONE: eResult = WALLPAPER_NULL; break;
4104 case GPOS_TILED: eResult = WALLPAPER_TILE; break;
4105 case GPOS_MM: eResult = WALLPAPER_CENTER; break;
4106 case GPOS_AREA: eResult = WALLPAPER_SCALE; break;
4107 case GPOS_LT: eResult = WALLPAPER_TOPLEFT; break;
4108 case GPOS_MT: eResult = WALLPAPER_TOP; break;
4109 case GPOS_RT: eResult = WALLPAPER_TOPRIGHT; break;
4110 case GPOS_LM: eResult = WALLPAPER_LEFT; break;
4111 case GPOS_RM: eResult = WALLPAPER_RIGHT; break;
4112 case GPOS_LB: eResult = WALLPAPER_BOTTOMLEFT; break;
4113 case GPOS_MB: eResult = WALLPAPER_BOTTOM; break;
4114 case GPOS_RB: eResult = WALLPAPER_BOTTOMRIGHT; break;
4115 default: eResult = WALLPAPER_NULL;
4117 return eResult;
4120 SvxBrushItem::SvxBrushItem( const CntWallpaperItem& rItem, sal_uInt16 _nWhich ) :
4121 SfxPoolItem ( _nWhich ),
4122 nShadingValue ( ShadingPattern::CLEAR ),
4123 pImpl ( new SvxBrushItem_Impl( 0 ) ),
4124 maStrLink (),
4125 maStrFilter (),
4126 bLoadAgain ( true )
4128 aColor = rItem.GetColor();
4130 if (!rItem.GetBitmapURL().isEmpty())
4132 maStrLink = rItem.GetBitmapURL();
4133 SetGraphicPos( WallpaperStyle2GraphicPos((WallpaperStyle)rItem.GetStyle() ) );
4135 else
4137 SetGraphicPos( GPOS_NONE );
4141 void SvxBrushItem::ApplyGraphicTransparency_Impl()
4143 DBG_ASSERT(pImpl->pGraphicObject, "no GraphicObject available" );
4144 if(pImpl->pGraphicObject)
4146 GraphicAttr aAttr(pImpl->pGraphicObject->GetAttr());
4147 aAttr.SetTransparency(lcl_PercentToTransparency(
4148 pImpl->nGraphicTransparency));
4149 pImpl->pGraphicObject->SetAttr(aAttr);
4153 void SvxBrushItem::dumpAsXml(xmlTextWriterPtr pWriter) const
4155 xmlTextWriterStartElement(pWriter, BAD_CAST("svxBrushItem"));
4156 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
4157 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("color"), BAD_CAST(aColor.AsRGBHexString().toUtf8().getStr()));
4158 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("shadingValue"), BAD_CAST(OString::number(nShadingValue).getStr()));
4159 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("link"), BAD_CAST(maStrLink.toUtf8().getStr()));
4160 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("filter"), BAD_CAST(maStrFilter.toUtf8().getStr()));
4161 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("graphicPos"), BAD_CAST(OString::number(eGraphicPos).getStr()));
4162 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("loadAgain"), BAD_CAST(OString::boolean(bLoadAgain).getStr()));
4163 xmlTextWriterEndElement(pWriter);
4166 // class SvxFrameDirectionItem ----------------------------------------------
4168 SvxFrameDirectionItem::SvxFrameDirectionItem( SvxFrameDirection nValue ,
4169 sal_uInt16 _nWhich )
4170 : SfxUInt16Item( _nWhich, (sal_uInt16)nValue )
4174 SvxFrameDirectionItem::~SvxFrameDirectionItem()
4178 bool SvxFrameDirectionItem::operator==( const SfxPoolItem& rCmp ) const
4180 DBG_ASSERT( SfxPoolItem::operator==(rCmp), "unequal types" );
4182 return GetValue() == static_cast<const SvxFrameDirectionItem&>(rCmp).GetValue();
4185 SfxPoolItem* SvxFrameDirectionItem::Clone( SfxItemPool * ) const
4187 return new SvxFrameDirectionItem( *this );
4190 SfxPoolItem* SvxFrameDirectionItem::Create( SvStream & rStrm, sal_uInt16 /*nVer*/ ) const
4192 sal_uInt16 nValue;
4193 rStrm.ReadUInt16( nValue );
4194 return new SvxFrameDirectionItem( (SvxFrameDirection)nValue, Which() );
4197 SvStream& SvxFrameDirectionItem::Store( SvStream & rStrm, sal_uInt16 /*nIVer*/ ) const
4199 sal_uInt16 nValue = GetValue();
4200 rStrm.WriteUInt16( nValue );
4201 return rStrm;
4204 sal_uInt16 SvxFrameDirectionItem::GetVersion( sal_uInt16 nFVer ) const
4206 return SOFFICE_FILEFORMAT_50 > nFVer ? USHRT_MAX : 0;
4209 bool SvxFrameDirectionItem::GetPresentation(
4210 SfxItemPresentation /*ePres*/,
4211 SfxMapUnit /*eCoreUnit*/,
4212 SfxMapUnit /*ePresUnit*/,
4213 OUString& rText, const IntlWrapper *) const
4215 rText = EE_RESSTR( RID_SVXITEMS_FRMDIR_BEGIN + GetValue() );
4216 return true;
4219 bool SvxFrameDirectionItem::PutValue( const com::sun::star::uno::Any& rVal,
4220 sal_uInt8 )
4222 sal_Int16 nVal = sal_Int16();
4223 bool bRet = ( rVal >>= nVal );
4224 if( bRet )
4226 // translate WritingDirection2 constants into SvxFrameDirection
4227 switch( nVal )
4229 case text::WritingMode2::LR_TB:
4230 SetValue( FRMDIR_HORI_LEFT_TOP );
4231 break;
4232 case text::WritingMode2::RL_TB:
4233 SetValue( FRMDIR_HORI_RIGHT_TOP );
4234 break;
4235 case text::WritingMode2::TB_RL:
4236 SetValue( FRMDIR_VERT_TOP_RIGHT );
4237 break;
4238 case text::WritingMode2::TB_LR:
4239 SetValue( FRMDIR_VERT_TOP_LEFT );
4240 break;
4241 case text::WritingMode2::PAGE:
4242 SetValue( FRMDIR_ENVIRONMENT );
4243 break;
4244 default:
4245 bRet = false;
4246 break;
4250 return bRet;
4253 bool SvxFrameDirectionItem::QueryValue( com::sun::star::uno::Any& rVal,
4254 sal_uInt8 ) const
4256 // translate SvxFrameDirection into WritingDirection2
4257 sal_Int16 nVal;
4258 bool bRet = true;
4259 switch( GetValue() )
4261 case FRMDIR_HORI_LEFT_TOP:
4262 nVal = text::WritingMode2::LR_TB;
4263 break;
4264 case FRMDIR_HORI_RIGHT_TOP:
4265 nVal = text::WritingMode2::RL_TB;
4266 break;
4267 case FRMDIR_VERT_TOP_RIGHT:
4268 nVal = text::WritingMode2::TB_RL;
4269 break;
4270 case FRMDIR_VERT_TOP_LEFT:
4271 nVal = text::WritingMode2::TB_LR;
4272 break;
4273 case FRMDIR_ENVIRONMENT:
4274 nVal = text::WritingMode2::PAGE;
4275 break;
4276 default:
4277 OSL_FAIL("Unknown SvxFrameDirection value!");
4278 bRet = false;
4279 break;
4282 // return value + error state
4283 if( bRet )
4285 rVal <<= nVal;
4287 return bRet;
4290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */