Bump for 3.6-28
[LibreOffice.git] / editeng / source / items / frmitems.cxx
blobc1953dff4dd0d248b5bd57856e1c77cabfdf3ee9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
31 #include <com/sun/star/uno/Any.hxx>
32 #include <com/sun/star/drawing/LineStyle.hpp>
33 #include <com/sun/star/script/XTypeConverter.hpp>
34 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
35 #include <com/sun/star/table/ShadowLocation.hpp>
36 #include <com/sun/star/table/TableBorder.hpp>
37 #include <com/sun/star/table/ShadowFormat.hpp>
38 #include <com/sun/star/table/CellRangeAddress.hpp>
39 #include <com/sun/star/table/CellContentType.hpp>
40 #include <com/sun/star/table/TableOrientation.hpp>
41 #include <com/sun/star/util/SortField.hpp>
42 #include <com/sun/star/util/SortFieldType.hpp>
43 #include <com/sun/star/table/BorderLine2.hpp>
44 #include <com/sun/star/table/BorderLineStyle.hpp>
45 #include <com/sun/star/table/CellOrientation.hpp>
46 #include <com/sun/star/table/CellAddress.hpp>
47 #include <com/sun/star/style/PageStyleLayout.hpp>
48 #include <com/sun/star/style/BreakType.hpp>
49 #include <com/sun/star/style/GraphicLocation.hpp>
50 #include <com/sun/star/awt/Rectangle.hpp>
51 #include <com/sun/star/awt/Selection.hpp>
52 #include <com/sun/star/awt/Size.hpp>
53 #include <com/sun/star/text/WritingMode2.hpp>
54 #include <com/sun/star/frame/status/UpperLowerMarginScale.hpp>
56 #include <unotools/ucbstreamhelper.hxx>
57 #include <limits.h>
58 #include <comphelper/processfactory.hxx>
59 #include <svtools/grfmgr.hxx>
60 #include <tools/urlobj.hxx>
61 #include <comphelper/types.hxx>
62 #include <svl/memberid.hrc>
63 #include <svtools/wallitem.hxx>
64 #include <svl/cntwall.hxx>
65 #include <svtools/borderhelper.hxx>
66 #include <rtl/ustring.hxx>
67 #include <rtl/ustrbuf.hxx>
68 #include <vcl/graphicfilter.hxx>
70 #define _SVX_FRMITEMS_CXX
72 #include <editeng/editids.hrc>
73 #include <editeng/editrids.hrc>
74 #include <editeng/pbinitem.hxx>
75 #include <editeng/sizeitem.hxx>
76 #include <editeng/lrspitem.hxx>
77 #include <editeng/ulspitem.hxx>
78 #include <editeng/prntitem.hxx>
79 #include <editeng/opaqitem.hxx>
80 #include <editeng/protitem.hxx>
81 #include <editeng/shaditem.hxx>
82 #include <editeng/boxitem.hxx>
83 #include <editeng/brkitem.hxx>
84 #include <editeng/keepitem.hxx>
85 #include <editeng/bolnitem.hxx>
86 #include <editeng/brshitem.hxx>
87 #include <editeng/frmdiritem.hxx>
88 #include <editeng/itemtype.hxx>
89 #include <editeng/eerdll.hxx>
90 #include <editeng/unoprnms.hxx>
91 #include <editeng/memberids.hrc>
92 #include <editeng/editerr.hxx>
94 using namespace ::editeng;
95 using namespace ::rtl;
96 using namespace ::com::sun::star;
97 using namespace ::com::sun::star::table::BorderLineStyle;
100 // Conversion for UNO
101 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
102 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
103 #define TWIP_TO_MM100_UNSIGNED(TWIP) ((((TWIP)*127L+36L)/72L))
104 #define MM100_TO_TWIP_UNSIGNED(MM100) ((((MM100)*72L+63L)/127L))
106 // STATIC DATA -----------------------------------------------------------
108 inline void SetValueProp( XubString& rStr, const sal_uInt16 nValue,
109 const sal_uInt16 nProp )
111 if( 100 == nProp )
112 rStr += String::CreateFromInt32( nValue );
113 else
114 ( rStr += String::CreateFromInt32( nProp )) += sal_Unicode('%');
117 inline void SetValueProp( XubString& rStr, const short nValue,
118 const sal_uInt16 nProp )
120 if( 100 == nProp )
121 rStr += String::CreateFromInt32( nValue );
122 else
123 ( rStr += String::CreateFromInt32( nProp )) += sal_Unicode('%');
126 // -----------------------------------------------------------------------
129 SvxBorderLine is not an SfxPoolItem, and has no Store/Create serialization/deserialization methods.
130 Since border line information needs to be serialized by the table autoformat code, these file-local
131 methods are defined to encapsulate the necessary serialization logic.
133 namespace
135 /// Item version for saved border lines. The old version saves the line without style information.
136 const int BORDER_LINE_OLD_VERSION = 0;
137 /// Item version for saved border lies. The new version includes line style.
138 const int BORDER_LINE_WITH_STYLE_VERSION = 1;
140 /// Store a border line to a stream.
141 SvStream& StoreBorderLine(SvStream &stream, const SvxBorderLine &l, sal_uInt16 version)
143 stream << l.GetColor()
144 << l.GetOutWidth()
145 << l.GetInWidth()
146 << l.GetDistance();
148 if (version >= BORDER_LINE_WITH_STYLE_VERSION)
149 stream << static_cast<sal_uInt16>(l.GetBorderLineStyle());
151 return stream;
154 /// Creates a border line from a stream.
155 SvxBorderLine CreateBorderLine(SvStream &stream, sal_uInt16 version)
157 sal_uInt16 nOutline, nInline, nDistance;
158 sal_uInt16 nStyle = NONE;
159 Color aColor;
160 stream >> aColor >> nOutline >> nInline >> nDistance;
162 if (version >= BORDER_LINE_WITH_STYLE_VERSION)
163 stream >> nStyle;
165 SvxBorderLine border(&aColor);
166 border.GuessLinesWidths(nStyle, nOutline, nInline, nDistance);
167 return border;
170 /// Retrieves a BORDER_LINE_* version from a BOX_BORDER_* version.
171 sal_uInt16 BorderLineVersionFromBoxVersion(sal_uInt16 boxVersion)
173 return (boxVersion >= BOX_BORDER_STYLE_VERSION)? BORDER_LINE_WITH_STYLE_VERSION : BORDER_LINE_OLD_VERSION;
177 TYPEINIT1_FACTORY(SvxPaperBinItem, SfxByteItem, new SvxPaperBinItem(0));
178 TYPEINIT1_FACTORY(SvxSizeItem, SfxPoolItem, new SvxSizeItem(0));
179 TYPEINIT1_FACTORY(SvxLRSpaceItem, SfxPoolItem, new SvxLRSpaceItem(0));
180 TYPEINIT1_FACTORY(SvxULSpaceItem, SfxPoolItem, new SvxULSpaceItem(0));
181 TYPEINIT1_FACTORY(SvxPrintItem, SfxBoolItem, new SvxPrintItem(0));
182 TYPEINIT1_FACTORY(SvxOpaqueItem, SfxBoolItem, new SvxOpaqueItem(0));
183 TYPEINIT1_FACTORY(SvxProtectItem, SfxPoolItem, new SvxProtectItem(0));
184 TYPEINIT1_FACTORY(SvxBrushItem, SfxPoolItem, new SvxBrushItem(0));
185 TYPEINIT1_FACTORY(SvxShadowItem, SfxPoolItem, new SvxShadowItem(0));
186 TYPEINIT1_FACTORY(SvxBoxItem, SfxPoolItem, new SvxBoxItem(0));
187 TYPEINIT1_FACTORY(SvxBoxInfoItem, SfxPoolItem, new SvxBoxInfoItem(0));
188 TYPEINIT1_FACTORY(SvxFmtBreakItem, SfxEnumItem, new SvxFmtBreakItem(SVX_BREAK_NONE, 0));
189 TYPEINIT1_FACTORY(SvxFmtKeepItem, SfxBoolItem, new SvxFmtKeepItem(sal_False, 0));
190 TYPEINIT1_FACTORY(SvxLineItem, SfxPoolItem, new SvxLineItem(0));
191 TYPEINIT1_FACTORY(SvxFrameDirectionItem, SfxUInt16Item, new SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP, 0));
193 // class SvxPaperBinItem ------------------------------------------------
195 SfxPoolItem* SvxPaperBinItem::Clone( SfxItemPool* ) const
197 return new SvxPaperBinItem( *this );
200 // -----------------------------------------------------------------------
202 SvStream& SvxPaperBinItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
204 rStrm << GetValue();
205 return rStrm;
208 // -----------------------------------------------------------------------
210 SfxPoolItem* SvxPaperBinItem::Create( SvStream& rStrm, sal_uInt16 ) const
212 sal_Int8 nBin;
213 rStrm >> nBin;
214 return new SvxPaperBinItem( Which(), nBin );
217 // -----------------------------------------------------------------------
219 SfxItemPresentation SvxPaperBinItem::GetPresentation
221 SfxItemPresentation ePres,
222 SfxMapUnit /*eCoreUnit*/,
223 SfxMapUnit /*ePresUnit*/,
224 XubString& rText, const IntlWrapper *
225 ) const
227 switch ( ePres )
229 case SFX_ITEM_PRESENTATION_NONE:
230 rText.Erase();
231 return SFX_ITEM_PRESENTATION_NONE;
233 case SFX_ITEM_PRESENTATION_NAMELESS:
234 rText = String::CreateFromInt32( GetValue() );
235 return SFX_ITEM_PRESENTATION_NAMELESS;
237 case SFX_ITEM_PRESENTATION_COMPLETE:
239 sal_uInt8 nValue = GetValue();
241 if ( PAPERBIN_PRINTER_SETTINGS == nValue )
242 rText = EE_RESSTR(RID_SVXSTR_PAPERBIN_SETTINGS);
243 else
245 rText = EE_RESSTR(RID_SVXSTR_PAPERBIN);
246 rText += sal_Unicode(' ');
247 rText += String::CreateFromInt32( nValue );
249 return SFX_ITEM_PRESENTATION_COMPLETE;
251 //no break necessary
252 default: ;//prevent warning
255 return SFX_ITEM_PRESENTATION_NONE;
258 // class SvxSizeItem -----------------------------------------------------
260 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId, const Size& rSize ) :
262 SfxPoolItem( nId ),
264 aSize( rSize )
268 // -----------------------------------------------------------------------
269 bool SvxSizeItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
271 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
272 nMemberId &= ~CONVERT_TWIPS;
274 awt::Size aTmp(aSize.Width(), aSize.Height());
275 if( bConvert )
277 aTmp.Height = TWIP_TO_MM100(aTmp.Height);
278 aTmp.Width = TWIP_TO_MM100(aTmp.Width);
281 switch( nMemberId )
283 case MID_SIZE_SIZE: rVal <<= aTmp; break;
284 case MID_SIZE_WIDTH: rVal <<= aTmp.Width; break;
285 case MID_SIZE_HEIGHT: rVal <<= aTmp.Height; break;
286 default: OSL_FAIL("Wrong MemberId!"); return false;
289 return true;
291 // -----------------------------------------------------------------------
292 bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
294 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
295 nMemberId &= ~CONVERT_TWIPS;
297 switch( nMemberId )
299 case MID_SIZE_SIZE:
301 awt::Size aTmp;
302 if( rVal >>= aTmp )
304 if(bConvert)
306 aTmp.Height = MM100_TO_TWIP(aTmp.Height);
307 aTmp.Width = MM100_TO_TWIP(aTmp.Width);
309 aSize = Size( aTmp.Width, aTmp.Height );
311 else
313 return false;
316 break;
317 case MID_SIZE_WIDTH:
319 sal_Int32 nVal = 0;
320 if(!(rVal >>= nVal ))
321 return false;
323 aSize.Width() = bConvert ? MM100_TO_TWIP(nVal) : nVal;
325 break;
326 case MID_SIZE_HEIGHT:
328 sal_Int32 nVal = 0;
329 if(!(rVal >>= nVal))
330 return true;
332 aSize.Height() = bConvert ? MM100_TO_TWIP(nVal) : nVal;
334 break;
335 default: OSL_FAIL("Wrong MemberId!");
336 return false;
338 return true;
341 // -----------------------------------------------------------------------
343 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId ) :
345 SfxPoolItem( nId )
349 // -----------------------------------------------------------------------
351 int SvxSizeItem::operator==( const SfxPoolItem& rAttr ) const
353 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
355 return ( aSize == ( (SvxSizeItem&)rAttr ).GetSize() );
358 // -----------------------------------------------------------------------
360 SfxPoolItem* SvxSizeItem::Clone( SfxItemPool* ) const
362 return new SvxSizeItem( *this );
365 //------------------------------------------------------------------------
367 SfxItemPresentation SvxSizeItem::GetPresentation
369 SfxItemPresentation ePres,
370 SfxMapUnit eCoreUnit,
371 SfxMapUnit ePresUnit,
372 XubString& rText, const IntlWrapper *pIntl
373 ) const
375 switch ( ePres )
377 case SFX_ITEM_PRESENTATION_NONE:
378 rText.Erase();
379 return SFX_ITEM_PRESENTATION_NONE;
381 case SFX_ITEM_PRESENTATION_NAMELESS:
382 rText = GetMetricText( aSize.Width(), eCoreUnit, ePresUnit, pIntl );
383 rText += cpDelim;
384 rText += GetMetricText( aSize.Height(), eCoreUnit, ePresUnit, pIntl );
385 return SFX_ITEM_PRESENTATION_NAMELESS;
387 case SFX_ITEM_PRESENTATION_COMPLETE:
388 rText = EE_RESSTR(RID_SVXITEMS_SIZE_WIDTH);
389 rText += GetMetricText( aSize.Width(), eCoreUnit, ePresUnit, pIntl );
390 rText += EE_RESSTR(GetMetricId(ePresUnit));
391 rText += cpDelim;
392 rText += EE_RESSTR(RID_SVXITEMS_SIZE_HEIGHT);
393 rText += GetMetricText( aSize.Height(), eCoreUnit, ePresUnit, pIntl );
394 rText += EE_RESSTR(GetMetricId(ePresUnit));
395 return SFX_ITEM_PRESENTATION_COMPLETE;
396 //no break necessary
397 default: ;//prevent warning
400 return SFX_ITEM_PRESENTATION_NONE;
403 // -----------------------------------------------------------------------
405 SvStream& SvxSizeItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
407 //#fdo39428 SvStream no longer supports operator<<(long)
408 rStrm << sal::static_int_cast<sal_Int32>(aSize.Width());
409 rStrm << sal::static_int_cast<sal_Int32>(aSize.Height());
410 return rStrm;
413 // -----------------------------------------------------------------------
415 bool SvxSizeItem::ScaleMetrics( long nMult, long nDiv )
417 aSize.Width() = Scale( aSize.Width(), nMult, nDiv );
418 aSize.Height() = Scale( aSize.Height(), nMult, nDiv );
419 return true;
422 // -----------------------------------------------------------------------
424 bool SvxSizeItem::HasMetrics() const
426 return true;
429 // -----------------------------------------------------------------------
431 SfxPoolItem* SvxSizeItem::Create( SvStream& rStrm, sal_uInt16 ) const
433 //#fdo39428 SvStream no longer supports operator>>(long&)
434 sal_Int32 nWidth(0), nHeight(0);
435 rStrm >> nWidth >> nHeight;
437 SvxSizeItem* pAttr = new SvxSizeItem( Which() );
438 pAttr->SetSize(Size(nWidth, nHeight));
440 return pAttr;
443 // class SvxLRSpaceItem --------------------------------------------------
445 SvxLRSpaceItem::SvxLRSpaceItem( const sal_uInt16 nId ) :
447 SfxPoolItem( nId ),
449 nFirstLineOfst ( 0 ),
450 nTxtLeft ( 0 ),
451 nLeftMargin ( 0 ),
452 nRightMargin ( 0 ),
453 nPropFirstLineOfst( 100 ),
454 nPropLeftMargin( 100 ),
455 nPropRightMargin( 100 ),
456 bAutoFirst ( 0 )
460 // -----------------------------------------------------------------------
462 SvxLRSpaceItem::SvxLRSpaceItem( const long nLeft, const long nRight,
463 const long nTLeft, const short nOfset,
464 const sal_uInt16 nId ) :
466 SfxPoolItem( nId ),
468 nFirstLineOfst ( nOfset ),
469 nTxtLeft ( nTLeft ),
470 nLeftMargin ( nLeft ),
471 nRightMargin ( nRight ),
472 nPropFirstLineOfst( 100 ),
473 nPropLeftMargin( 100 ),
474 nPropRightMargin( 100 ),
475 bAutoFirst ( 0 )
479 // -----------------------------------------------------------------------
480 bool SvxLRSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
482 bool bRet = true;
483 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
484 nMemberId &= ~CONVERT_TWIPS;
485 switch( nMemberId )
487 // now all signed
488 case MID_L_MARGIN:
489 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100(nLeftMargin) : nLeftMargin);
490 break;
492 case MID_TXT_LMARGIN :
493 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100(nTxtLeft) : nTxtLeft);
494 break;
495 case MID_R_MARGIN:
496 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100(nRightMargin) : nRightMargin);
497 break;
498 case MID_L_REL_MARGIN:
499 rVal <<= (sal_Int16)nPropLeftMargin;
500 break;
501 case MID_R_REL_MARGIN:
502 rVal <<= (sal_Int16)nPropRightMargin;
503 break;
505 case MID_FIRST_LINE_INDENT:
506 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100(nFirstLineOfst) : nFirstLineOfst);
507 break;
509 case MID_FIRST_LINE_REL_INDENT:
510 rVal <<= (sal_Int16)(nPropFirstLineOfst);
511 break;
513 case MID_FIRST_AUTO:
514 rVal = Bool2Any(IsAutoFirst());
515 break;
517 default:
518 bRet = false;
519 OSL_FAIL("unknown MemberId");
521 return bRet;
524 // -----------------------------------------------------------------------
525 bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
527 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
528 nMemberId &= ~CONVERT_TWIPS;
529 sal_Int32 nVal = 0;
530 if( nMemberId != MID_FIRST_AUTO &&
531 nMemberId != MID_L_REL_MARGIN && nMemberId != MID_R_REL_MARGIN)
532 if(!(rVal >>= nVal))
533 return sal_False;
535 switch( nMemberId )
537 case MID_L_MARGIN:
538 SetLeft((sal_Int32)bConvert ? MM100_TO_TWIP(nVal) : nVal);
539 break;
541 case MID_TXT_LMARGIN :
542 SetTxtLeft((sal_Int32)bConvert ? MM100_TO_TWIP(nVal) : nVal);
543 break;
545 case MID_R_MARGIN:
546 SetRight((sal_Int32) bConvert ? MM100_TO_TWIP(nVal) : nVal);
547 break;
548 case MID_L_REL_MARGIN:
549 case MID_R_REL_MARGIN:
551 sal_Int32 nRel = 0;
552 if((rVal >>= nRel) && nRel >= 0 && nRel < USHRT_MAX)
554 if(MID_L_REL_MARGIN== nMemberId)
555 nPropLeftMargin = (sal_uInt16)nRel;
556 else
557 nPropRightMargin = (sal_uInt16)nRel;
559 else
560 return false;
562 break;
563 case MID_FIRST_LINE_INDENT :
564 SetTxtFirstLineOfst((short)(bConvert ? MM100_TO_TWIP(nVal) : nVal));
565 break;
567 case MID_FIRST_LINE_REL_INDENT:
568 SetPropTxtFirstLineOfst ( (sal_uInt16)nVal );
569 break;
571 case MID_FIRST_AUTO:
572 SetAutoFirst( Any2Bool(rVal) );
573 break;
575 default:
576 OSL_FAIL("unknown MemberId");
577 return false;
579 return true;
582 // -----------------------------------------------------------------------
584 // Adapt nLeftMargin and nTxtLeft.
586 void SvxLRSpaceItem::AdjustLeft()
588 if ( 0 > nFirstLineOfst )
589 nLeftMargin = nTxtLeft + nFirstLineOfst;
590 else
591 nLeftMargin = nTxtLeft;
594 // -----------------------------------------------------------------------
596 int SvxLRSpaceItem::operator==( const SfxPoolItem& rAttr ) const
598 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
600 return (
601 nLeftMargin == ((SvxLRSpaceItem&)rAttr).GetLeft() &&
602 nRightMargin == ((SvxLRSpaceItem&)rAttr).GetRight() &&
603 nFirstLineOfst == ((SvxLRSpaceItem&)rAttr).GetTxtFirstLineOfst() &&
604 nPropLeftMargin == ((SvxLRSpaceItem&)rAttr).GetPropLeft() &&
605 nPropRightMargin == ((SvxLRSpaceItem&)rAttr).GetPropRight() &&
606 nPropFirstLineOfst == ((SvxLRSpaceItem&)rAttr).GetPropTxtFirstLineOfst() &&
607 bAutoFirst == ((SvxLRSpaceItem&)rAttr).IsAutoFirst() );
610 // -----------------------------------------------------------------------
612 SfxPoolItem* SvxLRSpaceItem::Clone( SfxItemPool* ) const
614 return new SvxLRSpaceItem( *this );
617 //------------------------------------------------------------------------
619 SfxItemPresentation SvxLRSpaceItem::GetPresentation
621 SfxItemPresentation ePres,
622 SfxMapUnit eCoreUnit,
623 SfxMapUnit ePresUnit,
624 XubString& rText, const IntlWrapper* pIntl
625 ) const
627 switch ( ePres )
629 case SFX_ITEM_PRESENTATION_NONE:
630 rText.Erase();
631 return SFX_ITEM_PRESENTATION_NONE;
632 case SFX_ITEM_PRESENTATION_NAMELESS:
634 if ( 100 != nPropLeftMargin )
635 ( rText = String::CreateFromInt32( nPropLeftMargin )) += sal_Unicode('%');
636 else
637 rText = GetMetricText( (long)nLeftMargin,
638 eCoreUnit, ePresUnit, pIntl );
639 rText += cpDelim;
640 if ( 100 != nPropFirstLineOfst )
641 ( rText += String::CreateFromInt32( nPropFirstLineOfst )) += sal_Unicode('%');
642 else
643 rText += GetMetricText( (long)nFirstLineOfst,
644 eCoreUnit, ePresUnit, pIntl );
645 rText += cpDelim;
646 if ( 100 != nRightMargin )
647 ( rText += String::CreateFromInt32( nRightMargin )) += sal_Unicode('%');
648 else
649 rText += GetMetricText( (long)nRightMargin,
650 eCoreUnit, ePresUnit, pIntl );
651 return SFX_ITEM_PRESENTATION_NAMELESS;
653 case SFX_ITEM_PRESENTATION_COMPLETE:
655 rText = EE_RESSTR(RID_SVXITEMS_LRSPACE_LEFT);
656 if ( 100 != nPropLeftMargin )
657 ( rText += String::CreateFromInt32( nPropLeftMargin )) += sal_Unicode('%');
658 else
660 rText += GetMetricText( (long)nLeftMargin,
661 eCoreUnit, ePresUnit, pIntl );
662 rText += EE_RESSTR(GetMetricId(ePresUnit));
664 rText += cpDelim;
665 if ( 100 != nPropFirstLineOfst || nFirstLineOfst )
667 rText += EE_RESSTR(RID_SVXITEMS_LRSPACE_FLINE);
668 if ( 100 != nPropFirstLineOfst )
669 ( rText += String::CreateFromInt32( nPropFirstLineOfst ))
670 += sal_Unicode('%');
671 else
673 rText += GetMetricText( (long)nFirstLineOfst,
674 eCoreUnit, ePresUnit, pIntl );
675 rText += EE_RESSTR(GetMetricId(ePresUnit));
677 rText += cpDelim;
679 rText += EE_RESSTR(RID_SVXITEMS_LRSPACE_RIGHT);
680 if ( 100 != nPropRightMargin )
681 ( rText += String::CreateFromInt32( nPropRightMargin )) += sal_Unicode('%');
682 else
684 rText += GetMetricText( (long)nRightMargin,
685 eCoreUnit, ePresUnit, pIntl );
686 rText += EE_RESSTR(GetMetricId(ePresUnit));
688 return SFX_ITEM_PRESENTATION_COMPLETE;
690 default: ;//prevent warning
692 return SFX_ITEM_PRESENTATION_NONE;
695 // -----------------------------------------------------------------------
697 // BulletFI: Before 501 in the Outliner the bullet was not on the position of
698 // the FI, so in older documents one must set FI to 0.
699 #define BULLETLR_MARKER 0x599401FE
701 SvStream& SvxLRSpaceItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
703 short nSaveFI = nFirstLineOfst;
704 ((SvxLRSpaceItem*)this)->SetTxtFirstLineOfst( 0 ); // nLeftMargin is manipulated together with this, see Create()
706 sal_uInt16 nMargin = 0;
707 if( nLeftMargin > 0 )
708 nMargin = sal_uInt16( nLeftMargin );
709 rStrm << nMargin;
710 rStrm << nPropLeftMargin;
711 if( nRightMargin > 0 )
712 nMargin = sal_uInt16( nRightMargin );
713 else
714 nMargin = 0;
715 rStrm << nMargin;
716 rStrm << nPropRightMargin;
717 rStrm << nFirstLineOfst;
718 rStrm << nPropFirstLineOfst;
719 if( nTxtLeft > 0 )
720 nMargin = sal_uInt16( nTxtLeft );
721 else
722 nMargin = 0;
723 rStrm << nMargin;
724 if( nItemVersion >= LRSPACE_AUTOFIRST_VERSION )
726 sal_Int8 nAutoFirst = bAutoFirst ? 1 : 0;
727 if( nItemVersion >= LRSPACE_NEGATIVE_VERSION &&
728 ( nLeftMargin < 0 || nRightMargin < 0 || nTxtLeft < 0 ) )
729 nAutoFirst |= 0x80;
730 rStrm << nAutoFirst;
732 // From 6.0 onwards, do not write Magic numbers...
733 DBG_ASSERT( rStrm.GetVersion() <= SOFFICE_FILEFORMAT_50, "Change File format SvxLRSpaceItem!" );
734 rStrm << (sal_uInt32) BULLETLR_MARKER;
735 rStrm << nSaveFI;
737 if( 0x80 & nAutoFirst )
739 rStrm << static_cast<sal_Int32>(nLeftMargin);
740 rStrm << static_cast<sal_Int32>(nRightMargin);
744 ((SvxLRSpaceItem*)this)->SetTxtFirstLineOfst( nSaveFI );
746 return rStrm;
749 // -----------------------------------------------------------------------
751 SfxPoolItem* SvxLRSpaceItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
753 sal_uInt16 left, prpleft, right, prpright, prpfirstline, txtleft;
754 short firstline;
755 sal_Int8 autofirst = 0;
757 if ( nVersion >= LRSPACE_AUTOFIRST_VERSION )
759 rStrm >> left >> prpleft >> right >> prpright >> firstline >>
760 prpfirstline >> txtleft >> autofirst;
762 sal_uInt32 nPos = rStrm.Tell();
763 sal_uInt32 nMarker;
764 rStrm >> nMarker;
765 if ( nMarker == BULLETLR_MARKER )
767 rStrm >> firstline;
768 if ( firstline < 0 )
769 left = left + static_cast<sal_uInt16>(firstline); // see below: txtleft = ...
771 else
772 rStrm.Seek( nPos );
774 else if ( nVersion == LRSPACE_TXTLEFT_VERSION )
776 rStrm >> left >> prpleft >> right >> prpright >> firstline >>
777 prpfirstline >> txtleft;
779 else if ( nVersion == LRSPACE_16_VERSION )
781 rStrm >> left >> prpleft >> right >> prpright >> firstline >>
782 prpfirstline;
784 else
786 sal_Int8 nL, nR, nFL;
787 rStrm >> left >> nL >> right >> nR >> firstline >> nFL;
788 prpleft = (sal_uInt16)nL;
789 prpright = (sal_uInt16)nR;
790 prpfirstline = (sal_uInt16)nFL;
793 txtleft = firstline >= 0 ? left : left - firstline;
794 SvxLRSpaceItem* pAttr = new SvxLRSpaceItem( Which() );
796 pAttr->nLeftMargin = left;
797 pAttr->nPropLeftMargin = prpleft;
798 pAttr->nRightMargin = right;
799 pAttr->nPropRightMargin = prpright;
800 pAttr->nFirstLineOfst = firstline;
801 pAttr->nPropFirstLineOfst = prpfirstline;
802 pAttr->nTxtLeft = txtleft;
803 pAttr->bAutoFirst = autofirst & 0x01;
804 if( nVersion >= LRSPACE_NEGATIVE_VERSION && ( autofirst & 0x80 ) )
806 sal_Int32 nMargin;
807 rStrm >> nMargin;
808 pAttr->nLeftMargin = nMargin;
809 pAttr->nTxtLeft = firstline >= 0 ? nMargin : nMargin - firstline;
810 rStrm >> nMargin;
811 pAttr->nRightMargin = nMargin;
813 return pAttr;
816 // -----------------------------------------------------------------------
818 sal_uInt16 SvxLRSpaceItem::GetVersion( sal_uInt16 nFileVersion ) const
820 return (nFileVersion == SOFFICE_FILEFORMAT_31)
821 ? LRSPACE_TXTLEFT_VERSION
822 : LRSPACE_NEGATIVE_VERSION;
825 // -----------------------------------------------------------------------
827 bool SvxLRSpaceItem::ScaleMetrics( long nMult, long nDiv )
829 nFirstLineOfst = (short)Scale( nFirstLineOfst, nMult, nDiv );
830 nTxtLeft = Scale( nTxtLeft, nMult, nDiv );
831 nLeftMargin = Scale( nLeftMargin, nMult, nDiv );
832 nRightMargin = Scale( nRightMargin, nMult, nDiv );
833 return true;
836 // -----------------------------------------------------------------------
838 bool SvxLRSpaceItem::HasMetrics() const
840 return true;
843 // class SvxULSpaceItem --------------------------------------------------
845 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nId )
846 : SfxPoolItem(nId)
847 , nUpper(0)
848 , nLower(0)
849 , bContext(false)
850 , nPropUpper(100)
851 , nPropLower(100)
855 // -----------------------------------------------------------------------
857 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nUp, const sal_uInt16 nLow,
858 const sal_uInt16 nId )
859 : SfxPoolItem(nId)
860 , nUpper(nUp)
861 , nLower(nLow)
862 , bContext(false)
863 , nPropUpper(100)
864 , nPropLower(100)
868 // -----------------------------------------------------------------------
869 bool SvxULSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
871 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
872 nMemberId &= ~CONVERT_TWIPS;
873 switch( nMemberId )
875 // now all signed
876 case 0:
878 ::com::sun::star::frame::status::UpperLowerMarginScale aUpperLowerMarginScale;
879 aUpperLowerMarginScale.Upper = (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nUpper) : nUpper);
880 aUpperLowerMarginScale.Lower = (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nLower) : nPropUpper);
881 aUpperLowerMarginScale.ScaleUpper = (sal_Int16)nPropUpper;
882 aUpperLowerMarginScale.ScaleLower = (sal_Int16)nPropLower;
883 rVal <<= aUpperLowerMarginScale;
884 break;
886 case MID_UP_MARGIN: rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nUpper) : nUpper); break;
887 case MID_LO_MARGIN: rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nLower) : nLower); break;
888 case MID_CTX_MARGIN: rVal <<= bContext; break;
889 case MID_UP_REL_MARGIN: rVal <<= (sal_Int16) nPropUpper; break;
890 case MID_LO_REL_MARGIN: rVal <<= (sal_Int16) nPropLower; break;
892 return true;
895 // -----------------------------------------------------------------------
896 bool SvxULSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
898 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
899 nMemberId &= ~CONVERT_TWIPS;
900 sal_Int32 nVal = 0;
901 sal_Bool bVal = 0;
902 switch( nMemberId )
904 case 0:
906 ::com::sun::star::frame::status::UpperLowerMarginScale aUpperLowerMarginScale;
907 if ( !(rVal >>= aUpperLowerMarginScale ))
908 return false;
910 SetUpper((sal_uInt16)(bConvert ? MM100_TO_TWIP( aUpperLowerMarginScale.Upper ) : aUpperLowerMarginScale.Upper));
911 SetLower((sal_uInt16)(bConvert ? MM100_TO_TWIP( aUpperLowerMarginScale.Lower ) : aUpperLowerMarginScale.Lower));
912 if( aUpperLowerMarginScale.ScaleUpper > 1 )
913 nPropUpper = aUpperLowerMarginScale.ScaleUpper;
914 if( aUpperLowerMarginScale.ScaleLower > 1 )
915 nPropUpper = aUpperLowerMarginScale.ScaleLower;
919 case MID_UP_MARGIN :
920 if(!(rVal >>= nVal) || nVal < 0)
921 return false;
922 SetUpper((sal_uInt16)(bConvert ? MM100_TO_TWIP(nVal) : nVal));
923 break;
924 case MID_LO_MARGIN :
925 if(!(rVal >>= nVal) || nVal < 0)
926 return false;
927 SetLower((sal_uInt16)(bConvert ? MM100_TO_TWIP(nVal) : nVal));
928 break;
929 case MID_CTX_MARGIN :
930 if (!(rVal >>= bVal))
931 return false;
932 SetContextValue(bVal);
933 break;
934 case MID_UP_REL_MARGIN:
935 case MID_LO_REL_MARGIN:
937 sal_Int32 nRel = 0;
938 if((rVal >>= nRel) && nRel > 1 )
940 if(MID_UP_REL_MARGIN == nMemberId)
941 nPropUpper = (sal_uInt16)nRel;
942 else
943 nPropLower = (sal_uInt16)nRel;
945 else
946 return false;
948 break;
950 default:
951 OSL_FAIL("unknown MemberId");
952 return false;
954 return true;
957 // -----------------------------------------------------------------------
959 int SvxULSpaceItem::operator==( const SfxPoolItem& rAttr ) const
961 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
963 return ( nUpper == ( (SvxULSpaceItem&)rAttr ).nUpper &&
964 nLower == ( (SvxULSpaceItem&)rAttr ).nLower &&
965 bContext == ( (SvxULSpaceItem&)rAttr ).bContext &&
966 nPropUpper == ( (SvxULSpaceItem&)rAttr ).nPropUpper &&
967 nPropLower == ( (SvxULSpaceItem&)rAttr ).nPropLower );
970 // -----------------------------------------------------------------------
972 SfxPoolItem* SvxULSpaceItem::Clone( SfxItemPool* ) const
974 return new SvxULSpaceItem( *this );
977 //------------------------------------------------------------------------
979 SfxItemPresentation SvxULSpaceItem::GetPresentation
981 SfxItemPresentation ePres,
982 SfxMapUnit eCoreUnit,
983 SfxMapUnit ePresUnit,
984 XubString& rText, const IntlWrapper *pIntl
985 ) const
987 switch ( ePres )
989 case SFX_ITEM_PRESENTATION_NONE:
990 rText.Erase();
991 return SFX_ITEM_PRESENTATION_NONE;
992 case SFX_ITEM_PRESENTATION_NAMELESS:
994 if ( 100 != nPropUpper )
995 ( rText = String::CreateFromInt32( nPropUpper )) += sal_Unicode('%');
996 else
997 rText = GetMetricText( (long)nUpper, eCoreUnit, ePresUnit, pIntl );
998 rText += cpDelim;
999 if ( 100 != nPropLower )
1000 ( rText += String::CreateFromInt32( nPropLower )) += sal_Unicode('%');
1001 else
1002 rText += GetMetricText( (long)nLower, eCoreUnit, ePresUnit, pIntl );
1003 return SFX_ITEM_PRESENTATION_NAMELESS;
1005 case SFX_ITEM_PRESENTATION_COMPLETE:
1007 rText = EE_RESSTR(RID_SVXITEMS_ULSPACE_UPPER);
1008 if ( 100 != nPropUpper )
1009 ( rText += String::CreateFromInt32( nPropUpper )) += sal_Unicode('%');
1010 else
1012 rText += GetMetricText( (long)nUpper, eCoreUnit, ePresUnit, pIntl );
1013 rText += EE_RESSTR(GetMetricId(ePresUnit));
1015 rText += cpDelim;
1016 rText += EE_RESSTR(RID_SVXITEMS_ULSPACE_LOWER);
1017 if ( 100 != nPropLower )
1018 ( rText += String::CreateFromInt32( nPropLower )) += sal_Unicode('%');
1019 else
1021 rText += GetMetricText( (long)nLower, eCoreUnit, ePresUnit, pIntl );
1022 rText += EE_RESSTR(GetMetricId(ePresUnit));
1024 return SFX_ITEM_PRESENTATION_COMPLETE;
1026 default: ;//prevent warning
1028 return SFX_ITEM_PRESENTATION_NONE;
1031 // -----------------------------------------------------------------------
1033 SvStream& SvxULSpaceItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1035 rStrm << GetUpper()
1036 << GetPropUpper()
1037 << GetLower()
1038 << GetPropLower();
1039 return rStrm;
1042 // -----------------------------------------------------------------------
1044 SfxPoolItem* SvxULSpaceItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
1046 sal_uInt16 upper, lower, nPL = 0, nPU = 0;
1048 if ( nVersion == ULSPACE_16_VERSION )
1049 rStrm >> upper >> nPU >> lower >> nPL;
1050 else
1052 sal_Int8 nU, nL;
1053 rStrm >> upper >> nU >> lower >> nL;
1054 nPL = (sal_uInt16)nL;
1055 nPU = (sal_uInt16)nU;
1058 SvxULSpaceItem* pAttr = new SvxULSpaceItem( Which() );
1059 pAttr->SetUpperValue( upper );
1060 pAttr->SetLowerValue( lower );
1061 pAttr->SetPropUpper( nPU );
1062 pAttr->SetPropLower( nPL );
1063 return pAttr;
1066 // -----------------------------------------------------------------------
1068 sal_uInt16 SvxULSpaceItem::GetVersion( sal_uInt16 /*nFileVersion*/ ) const
1070 return ULSPACE_16_VERSION;
1073 // -----------------------------------------------------------------------
1075 bool SvxULSpaceItem::ScaleMetrics( long nMult, long nDiv )
1077 nUpper = (sal_uInt16)Scale( nUpper, nMult, nDiv );
1078 nLower = (sal_uInt16)Scale( nLower, nMult, nDiv );
1079 return true;
1082 // -----------------------------------------------------------------------
1084 bool SvxULSpaceItem::HasMetrics() const
1086 return true;
1089 // class SvxPrintItem ----------------------------------------------------
1091 SfxPoolItem* SvxPrintItem::Clone( SfxItemPool* ) const
1093 return new SvxPrintItem( *this );
1096 // -----------------------------------------------------------------------
1098 SvStream& SvxPrintItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1100 rStrm << (sal_Int8)GetValue();
1101 return rStrm;
1104 // -----------------------------------------------------------------------
1106 SfxPoolItem* SvxPrintItem::Create( SvStream& rStrm, sal_uInt16 ) const
1108 sal_Int8 bIsPrint;
1109 rStrm >> bIsPrint;
1110 return new SvxPrintItem( Which(), sal_Bool( bIsPrint != 0 ) );
1113 //------------------------------------------------------------------------
1115 SfxItemPresentation SvxPrintItem::GetPresentation
1117 SfxItemPresentation ePres,
1118 SfxMapUnit /*eCoreUnit*/,
1119 SfxMapUnit /*ePresUnit*/,
1120 XubString& rText, const IntlWrapper *
1121 ) const
1123 switch ( ePres )
1125 case SFX_ITEM_PRESENTATION_NONE:
1126 rText.Erase();
1127 return ePres;
1129 case SFX_ITEM_PRESENTATION_NAMELESS:
1130 case SFX_ITEM_PRESENTATION_COMPLETE:
1132 sal_uInt16 nId = RID_SVXITEMS_PRINT_FALSE;
1134 if ( GetValue() )
1135 nId = RID_SVXITEMS_PRINT_TRUE;
1136 rText = EE_RESSTR(nId);
1137 return ePres;
1139 default: ;//prevent warning
1141 return SFX_ITEM_PRESENTATION_NONE;
1144 // class SvxOpaqueItem ---------------------------------------------------
1146 SfxPoolItem* SvxOpaqueItem::Clone( SfxItemPool* ) const
1148 return new SvxOpaqueItem( *this );
1151 // -----------------------------------------------------------------------
1153 SvStream& SvxOpaqueItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1155 rStrm << (sal_Int8)GetValue();
1156 return rStrm;
1159 // -----------------------------------------------------------------------
1161 SfxPoolItem* SvxOpaqueItem::Create( SvStream& rStrm, sal_uInt16 ) const
1163 sal_Int8 bIsOpaque;
1164 rStrm >> bIsOpaque;
1165 return new SvxOpaqueItem( Which(), sal_Bool( bIsOpaque != 0 ) );
1168 //------------------------------------------------------------------------
1170 SfxItemPresentation SvxOpaqueItem::GetPresentation
1172 SfxItemPresentation ePres,
1173 SfxMapUnit /*eCoreUnit*/,
1174 SfxMapUnit /*ePresUnit*/,
1175 XubString& rText, const IntlWrapper *
1176 ) const
1178 switch ( ePres )
1180 case SFX_ITEM_PRESENTATION_NONE:
1181 rText.Erase();
1182 return ePres;
1184 case SFX_ITEM_PRESENTATION_NAMELESS:
1185 case SFX_ITEM_PRESENTATION_COMPLETE:
1187 sal_uInt16 nId = RID_SVXITEMS_OPAQUE_FALSE;
1189 if ( GetValue() )
1190 nId = RID_SVXITEMS_OPAQUE_TRUE;
1191 rText = EE_RESSTR(nId);
1192 return ePres;
1194 default: ;//prevent warning
1196 return SFX_ITEM_PRESENTATION_NONE;
1199 // class SvxProtectItem --------------------------------------------------
1201 int SvxProtectItem::operator==( const SfxPoolItem& rAttr ) const
1203 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1205 return ( bCntnt == ( (SvxProtectItem&)rAttr ).bCntnt &&
1206 bSize == ( (SvxProtectItem&)rAttr ).bSize &&
1207 bPos == ( (SvxProtectItem&)rAttr ).bPos );
1210 bool SvxProtectItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1212 nMemberId &= ~CONVERT_TWIPS;
1213 sal_Bool bValue;
1214 switch(nMemberId)
1216 case MID_PROTECT_CONTENT : bValue = bCntnt; break;
1217 case MID_PROTECT_SIZE : bValue = bSize; break;
1218 case MID_PROTECT_POSITION: bValue = bPos; break;
1219 default:
1220 OSL_FAIL("Wrong MemberId");
1221 return false;
1224 rVal = Bool2Any( bValue );
1225 return true;
1228 bool SvxProtectItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1230 nMemberId &= ~CONVERT_TWIPS;
1231 sal_Bool bVal( Any2Bool(rVal) );
1232 switch(nMemberId)
1234 case MID_PROTECT_CONTENT : bCntnt = bVal; break;
1235 case MID_PROTECT_SIZE : bSize = bVal; break;
1236 case MID_PROTECT_POSITION: bPos = bVal; break;
1237 default:
1238 OSL_FAIL("Wrong MemberId");
1239 return false;
1241 return true;
1244 // -----------------------------------------------------------------------
1246 SfxPoolItem* SvxProtectItem::Clone( SfxItemPool* ) const
1248 return new SvxProtectItem( *this );
1251 //------------------------------------------------------------------------
1253 SfxItemPresentation SvxProtectItem::GetPresentation
1255 SfxItemPresentation ePres,
1256 SfxMapUnit /*eCoreUnit*/,
1257 SfxMapUnit /*ePresUnit*/,
1258 XubString& rText, const IntlWrapper *
1259 ) const
1261 switch ( ePres )
1263 case SFX_ITEM_PRESENTATION_NONE:
1264 rText.Erase();
1265 return ePres;
1267 case SFX_ITEM_PRESENTATION_NAMELESS:
1268 case SFX_ITEM_PRESENTATION_COMPLETE:
1270 sal_uInt16 nId = RID_SVXITEMS_PROT_CONTENT_FALSE;
1272 if ( bCntnt )
1273 nId = RID_SVXITEMS_PROT_CONTENT_TRUE;
1274 rText = EE_RESSTR(nId);
1275 rText += cpDelim;
1276 nId = RID_SVXITEMS_PROT_SIZE_FALSE;
1278 if ( bSize )
1279 nId = RID_SVXITEMS_PROT_SIZE_TRUE;
1280 rText += EE_RESSTR(nId);
1281 rText += cpDelim;
1282 nId = RID_SVXITEMS_PROT_POS_FALSE;
1284 if ( bPos )
1285 nId = RID_SVXITEMS_PROT_POS_TRUE;
1286 rText += EE_RESSTR(nId);
1287 return ePres;
1289 default: ;//prevent warning
1291 return SFX_ITEM_PRESENTATION_NONE;
1294 // -----------------------------------------------------------------------
1296 SvStream& SvxProtectItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1298 sal_Int8 cProt = 0;
1299 if( IsPosProtected() ) cProt |= 0x01;
1300 if( IsSizeProtected() ) cProt |= 0x02;
1301 if( IsCntntProtected() ) cProt |= 0x04;
1302 rStrm << (sal_Int8) cProt;
1303 return rStrm;
1306 // -----------------------------------------------------------------------
1308 SfxPoolItem* SvxProtectItem::Create( SvStream& rStrm, sal_uInt16 ) const
1310 sal_Int8 cFlags;
1311 rStrm >> cFlags;
1312 SvxProtectItem* pAttr = new SvxProtectItem( Which() );
1313 pAttr->SetPosProtect( sal_Bool( ( cFlags & 0x01 ) != 0 ) );
1314 pAttr->SetSizeProtect( sal_Bool( ( cFlags & 0x02 ) != 0 ) );
1315 pAttr->SetCntntProtect( sal_Bool( ( cFlags & 0x04 ) != 0 ) );
1316 return pAttr;
1319 // class SvxShadowItem ---------------------------------------------------
1321 SvxShadowItem::SvxShadowItem( const sal_uInt16 nId,
1322 const Color *pColor, const sal_uInt16 nW,
1323 const SvxShadowLocation eLoc ) :
1324 SfxEnumItemInterface( nId ),
1325 aShadowColor(COL_GRAY),
1326 nWidth ( nW ),
1327 eLocation ( eLoc )
1329 if ( pColor )
1330 aShadowColor = *pColor;
1333 // -----------------------------------------------------------------------
1334 bool SvxShadowItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1336 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1337 nMemberId &= ~CONVERT_TWIPS;
1339 table::ShadowFormat aShadow;
1340 table::ShadowLocation eSet = table::ShadowLocation_NONE;
1341 switch( eLocation )
1343 case SVX_SHADOW_TOPLEFT : eSet = table::ShadowLocation_TOP_LEFT ; break;
1344 case SVX_SHADOW_TOPRIGHT : eSet = table::ShadowLocation_TOP_RIGHT ; break;
1345 case SVX_SHADOW_BOTTOMLEFT : eSet = table::ShadowLocation_BOTTOM_LEFT ; break;
1346 case SVX_SHADOW_BOTTOMRIGHT: eSet = table::ShadowLocation_BOTTOM_RIGHT; break;
1347 default: ;//prevent warning
1349 aShadow.Location = eSet;
1350 aShadow.ShadowWidth = bConvert ? TWIP_TO_MM100_UNSIGNED(nWidth) : nWidth;
1351 aShadow.IsTransparent = aShadowColor.GetTransparency() > 0;
1352 aShadow.Color = aShadowColor.GetRGBColor();
1354 switch ( nMemberId )
1356 case MID_LOCATION: rVal <<= aShadow.Location; break;
1357 case MID_WIDTH: rVal <<= aShadow.ShadowWidth; break;
1358 case MID_TRANSPARENT: rVal <<= aShadow.IsTransparent; break;
1359 case MID_BG_COLOR: rVal <<= aShadow.Color; break;
1360 case 0: rVal <<= aShadow; break;
1361 default: OSL_FAIL("Wrong MemberId!"); return false;
1364 return true;
1366 // -----------------------------------------------------------------------
1367 bool SvxShadowItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1369 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1370 nMemberId &= ~CONVERT_TWIPS;
1372 table::ShadowFormat aShadow;
1373 uno::Any aAny;
1374 bool bRet = QueryValue( aAny, bConvert ? CONVERT_TWIPS : 0 ) && ( aAny >>= aShadow );
1375 switch ( nMemberId )
1377 case MID_LOCATION:
1379 bRet = (rVal >>= aShadow.Location);
1380 if ( !bRet )
1382 sal_Int16 nVal = 0;
1383 bRet = (rVal >>= nVal);
1384 aShadow.Location = (table::ShadowLocation) nVal;
1387 break;
1390 case MID_WIDTH: rVal >>= aShadow.ShadowWidth; break;
1391 case MID_TRANSPARENT: rVal >>= aShadow.IsTransparent; break;
1392 case MID_BG_COLOR: rVal >>= aShadow.Color; break;
1393 case 0: rVal >>= aShadow; break;
1394 default: OSL_FAIL("Wrong MemberId!"); return sal_False;
1397 if ( bRet )
1399 // SvxShadowLocation eSet = SVX_SHADOW_NONE;
1400 switch( aShadow.Location )
1402 case table::ShadowLocation_TOP_LEFT : eLocation = SVX_SHADOW_TOPLEFT; break;
1403 case table::ShadowLocation_TOP_RIGHT : eLocation = SVX_SHADOW_TOPRIGHT; break;
1404 case table::ShadowLocation_BOTTOM_LEFT : eLocation = SVX_SHADOW_BOTTOMLEFT ; break;
1405 case table::ShadowLocation_BOTTOM_RIGHT: eLocation = SVX_SHADOW_BOTTOMRIGHT; break;
1406 default: ;//prevent warning
1409 nWidth = bConvert ? MM100_TO_TWIP(aShadow.ShadowWidth) : aShadow.ShadowWidth;
1410 Color aSet(aShadow.Color);
1411 aSet.SetTransparency(aShadow.IsTransparent ? 0xff : 0);
1412 aShadowColor = aSet;
1415 return bRet;
1418 // -----------------------------------------------------------------------
1420 int SvxShadowItem::operator==( const SfxPoolItem& rAttr ) const
1422 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1424 return ( ( aShadowColor == ( (SvxShadowItem&)rAttr ).aShadowColor ) &&
1425 ( nWidth == ( (SvxShadowItem&)rAttr ).GetWidth() ) &&
1426 ( eLocation == ( (SvxShadowItem&)rAttr ).GetLocation() ) );
1429 // -----------------------------------------------------------------------
1431 SfxPoolItem* SvxShadowItem::Clone( SfxItemPool* ) const
1433 return new SvxShadowItem( *this );
1436 // -----------------------------------------------------------------------
1438 sal_uInt16 SvxShadowItem::CalcShadowSpace( sal_uInt16 nShadow ) const
1440 sal_uInt16 nSpace = 0;
1442 switch ( nShadow )
1444 case SHADOW_TOP:
1445 if ( eLocation == SVX_SHADOW_TOPLEFT ||
1446 eLocation == SVX_SHADOW_TOPRIGHT )
1447 nSpace = nWidth;
1448 break;
1450 case SHADOW_BOTTOM:
1451 if ( eLocation == SVX_SHADOW_BOTTOMLEFT ||
1452 eLocation == SVX_SHADOW_BOTTOMRIGHT )
1453 nSpace = nWidth;
1454 break;
1456 case SHADOW_LEFT:
1457 if ( eLocation == SVX_SHADOW_TOPLEFT ||
1458 eLocation == SVX_SHADOW_BOTTOMLEFT )
1459 nSpace = nWidth;
1460 break;
1462 case SHADOW_RIGHT:
1463 if ( eLocation == SVX_SHADOW_TOPRIGHT ||
1464 eLocation == SVX_SHADOW_BOTTOMRIGHT )
1465 nSpace = nWidth;
1466 break;
1468 default:
1469 OSL_FAIL( "wrong shadow" );
1471 return nSpace;
1474 //------------------------------------------------------------------------
1476 SfxItemPresentation SvxShadowItem::GetPresentation
1478 SfxItemPresentation ePres,
1479 SfxMapUnit eCoreUnit,
1480 SfxMapUnit ePresUnit,
1481 XubString& rText, const IntlWrapper *pIntl
1482 ) const
1484 switch ( ePres )
1486 case SFX_ITEM_PRESENTATION_NONE:
1487 rText.Erase();
1488 return ePres;
1490 case SFX_ITEM_PRESENTATION_NAMELESS:
1492 rText = ::GetColorString( aShadowColor );
1493 rText += cpDelim;
1494 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
1496 if ( aShadowColor.GetTransparency() )
1497 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
1498 rText += EE_RESSTR(nId);
1499 rText += cpDelim;
1500 rText += GetMetricText( (long)nWidth, eCoreUnit, ePresUnit, pIntl );
1501 rText += cpDelim;
1502 rText += EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + eLocation);
1503 return ePres;
1505 case SFX_ITEM_PRESENTATION_COMPLETE:
1507 rText = EE_RESSTR(RID_SVXITEMS_SHADOW_COMPLETE);
1508 rText += ::GetColorString( aShadowColor );
1509 rText += cpDelim;
1511 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
1512 if ( aShadowColor.GetTransparency() )
1513 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
1514 rText += EE_RESSTR(nId);
1515 rText += cpDelim;
1516 rText += GetMetricText( (long)nWidth, eCoreUnit, ePresUnit, pIntl );
1517 rText += EE_RESSTR(GetMetricId(ePresUnit));
1518 rText += cpDelim;
1519 rText += EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + eLocation);
1520 return ePres;
1522 default: ;//prevent warning
1524 return SFX_ITEM_PRESENTATION_NONE;
1527 // -----------------------------------------------------------------------
1529 SvStream& SvxShadowItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1531 rStrm << (sal_Int8) GetLocation()
1532 << (sal_uInt16) GetWidth()
1533 << (sal_Bool)(aShadowColor.GetTransparency() > 0)
1534 << GetColor()
1535 << GetColor()
1536 << (sal_Int8)(aShadowColor.GetTransparency() > 0 ? 0 : 1); //BRUSH_NULL : BRUSH_SOLID
1537 return rStrm;
1540 // -----------------------------------------------------------------------
1542 bool SvxShadowItem::ScaleMetrics( long nMult, long nDiv )
1544 nWidth = (sal_uInt16)Scale( nWidth, nMult, nDiv );
1545 return true;
1548 // -----------------------------------------------------------------------
1550 bool SvxShadowItem::HasMetrics() const
1552 return true;
1555 // -----------------------------------------------------------------------
1557 SfxPoolItem* SvxShadowItem::Create( SvStream& rStrm, sal_uInt16 ) const
1559 sal_Int8 cLoc;
1560 sal_uInt16 _nWidth;
1561 sal_Bool bTrans;
1562 Color aColor;
1563 Color aFillColor;
1564 sal_Int8 nStyle;
1565 rStrm >> cLoc >> _nWidth
1566 >> bTrans >> aColor >> aFillColor >> nStyle;
1567 aColor.SetTransparency(bTrans ? 0xff : 0);
1568 return new SvxShadowItem( Which(), &aColor, _nWidth, (SvxShadowLocation)cLoc );
1571 // -----------------------------------------------------------------------
1573 sal_uInt16 SvxShadowItem::GetValueCount() const
1575 return SVX_SHADOW_END; // SVX_SHADOW_BOTTOMRIGHT + 1
1578 // -----------------------------------------------------------------------
1580 rtl::OUString SvxShadowItem::GetValueTextByPos( sal_uInt16 nPos ) const
1582 DBG_ASSERT( nPos < SVX_SHADOW_END, "enum overflow!" );
1583 return EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + nPos );
1586 // -----------------------------------------------------------------------
1588 sal_uInt16 SvxShadowItem::GetEnumValue() const
1590 return (sal_uInt16)GetLocation();
1593 // -----------------------------------------------------------------------
1595 void SvxShadowItem::SetEnumValue( sal_uInt16 nVal )
1597 SetLocation( (const SvxShadowLocation)nVal );
1600 // class SvxBoxItem ------------------------------------------------------
1602 SvxBoxItem::SvxBoxItem( const SvxBoxItem& rCpy ) :
1604 SfxPoolItem ( rCpy ),
1605 nTopDist ( rCpy.nTopDist ),
1606 nBottomDist ( rCpy.nBottomDist ),
1607 nLeftDist ( rCpy.nLeftDist ),
1608 nRightDist ( rCpy.nRightDist )
1611 pTop = rCpy.GetTop() ? new SvxBorderLine( *rCpy.GetTop() ) : 0;
1612 pBottom = rCpy.GetBottom() ? new SvxBorderLine( *rCpy.GetBottom() ) : 0;
1613 pLeft = rCpy.GetLeft() ? new SvxBorderLine( *rCpy.GetLeft() ) : 0;
1614 pRight = rCpy.GetRight() ? new SvxBorderLine( *rCpy.GetRight() ) : 0;
1617 // -----------------------------------------------------------------------
1619 SvxBoxItem::SvxBoxItem( const sal_uInt16 nId ) :
1620 SfxPoolItem( nId ),
1622 pTop ( 0 ),
1623 pBottom ( 0 ),
1624 pLeft ( 0 ),
1625 pRight ( 0 ),
1626 nTopDist ( 0 ),
1627 nBottomDist ( 0 ),
1628 nLeftDist ( 0 ),
1629 nRightDist ( 0 )
1634 // -----------------------------------------------------------------------
1636 SvxBoxItem::~SvxBoxItem()
1638 delete pTop;
1639 delete pBottom;
1640 delete pLeft;
1641 delete pRight;
1644 // -----------------------------------------------------------------------
1646 SvxBoxItem& SvxBoxItem::operator=( const SvxBoxItem& rBox )
1648 nTopDist = rBox.nTopDist;
1649 nBottomDist = rBox.nBottomDist;
1650 nLeftDist = rBox.nLeftDist;
1651 nRightDist = rBox.nRightDist;
1652 SetLine( rBox.GetTop(), BOX_LINE_TOP );
1653 SetLine( rBox.GetBottom(), BOX_LINE_BOTTOM );
1654 SetLine( rBox.GetLeft(), BOX_LINE_LEFT );
1655 SetLine( rBox.GetRight(), BOX_LINE_RIGHT );
1656 return *this;
1659 // -----------------------------------------------------------------------
1661 inline sal_Bool CmpBrdLn( const SvxBorderLine* pBrd1, const SvxBorderLine* pBrd2 )
1663 sal_Bool bRet;
1664 if( 0 != pBrd1 ? 0 == pBrd2 : 0 != pBrd2 )
1665 bRet = sal_False;
1666 else
1667 if( !pBrd1 )
1668 bRet = sal_True;
1669 else
1670 bRet = (*pBrd1 == *pBrd2);
1671 return bRet;
1674 // -----------------------------------------------------------------------
1676 int SvxBoxItem::operator==( const SfxPoolItem& rAttr ) const
1678 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1680 return (
1681 ( nTopDist == ( (SvxBoxItem&)rAttr ).nTopDist ) &&
1682 ( nBottomDist == ( (SvxBoxItem&)rAttr ).nBottomDist ) &&
1683 ( nLeftDist == ( (SvxBoxItem&)rAttr ).nLeftDist ) &&
1684 ( nRightDist == ( (SvxBoxItem&)rAttr ).nRightDist ) &&
1685 CmpBrdLn( pTop, ( (SvxBoxItem&)rAttr ).GetTop() ) &&
1686 CmpBrdLn( pBottom, ( (SvxBoxItem&)rAttr ).GetBottom() ) &&
1687 CmpBrdLn( pLeft, ( (SvxBoxItem&)rAttr ).GetLeft() ) &&
1688 CmpBrdLn( pRight, ( (SvxBoxItem&)rAttr ).GetRight() ) );
1691 // -----------------------------------------------------------------------
1692 table::BorderLine2 SvxBoxItem::SvxLineToLine(const SvxBorderLine* pLine, sal_Bool bConvert)
1694 table::BorderLine2 aLine;
1695 if(pLine)
1697 aLine.Color = pLine->GetColor().GetColor() ;
1698 aLine.InnerLineWidth = sal_uInt16( bConvert ? TWIP_TO_MM100_UNSIGNED(pLine->GetInWidth() ): pLine->GetInWidth() );
1699 aLine.OuterLineWidth = sal_uInt16( bConvert ? TWIP_TO_MM100_UNSIGNED(pLine->GetOutWidth()): pLine->GetOutWidth() );
1700 aLine.LineDistance = sal_uInt16( bConvert ? TWIP_TO_MM100_UNSIGNED(pLine->GetDistance()): pLine->GetDistance() );
1701 aLine.LineStyle = pLine->GetBorderLineStyle();
1702 aLine.LineWidth = sal_uInt32( bConvert ? TWIP_TO_MM100( pLine->GetWidth( ) ) : pLine->GetWidth( ) );
1704 else
1705 aLine.Color = aLine.InnerLineWidth = aLine.OuterLineWidth = aLine.LineDistance = 0;
1706 return aLine;
1708 // -----------------------------------------------------------------------
1709 bool SvxBoxItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1711 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1712 table::BorderLine2 aRetLine;
1713 sal_uInt16 nDist = 0;
1714 sal_Bool bDistMember = sal_False;
1715 nMemberId &= ~CONVERT_TWIPS;
1716 switch(nMemberId)
1718 case 0:
1720 // 4 Borders and 5 distances
1721 uno::Sequence< uno::Any > aSeq( 9 );
1722 aSeq[0] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetLeft(), bConvert) );
1723 aSeq[1] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetRight(), bConvert) );
1724 aSeq[2] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetBottom(), bConvert) );
1725 aSeq[3] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetTop(), bConvert) );
1726 aSeq[4] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( GetDistance()) : GetDistance()));
1727 aSeq[5] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( nTopDist ) : nTopDist ));
1728 aSeq[6] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( nBottomDist ) : nBottomDist ));
1729 aSeq[7] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( nLeftDist ) : nLeftDist ));
1730 aSeq[8] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( nRightDist ) : nRightDist ));
1731 rVal = uno::makeAny( aSeq );
1732 return sal_True;
1734 case MID_LEFT_BORDER:
1735 case LEFT_BORDER:
1736 aRetLine = SvxBoxItem::SvxLineToLine(GetLeft(), bConvert);
1737 break;
1738 case MID_RIGHT_BORDER:
1739 case RIGHT_BORDER:
1740 aRetLine = SvxBoxItem::SvxLineToLine(GetRight(), bConvert);
1741 break;
1742 case MID_BOTTOM_BORDER:
1743 case BOTTOM_BORDER:
1744 aRetLine = SvxBoxItem::SvxLineToLine(GetBottom(), bConvert);
1745 break;
1746 case MID_TOP_BORDER:
1747 case TOP_BORDER:
1748 aRetLine = SvxBoxItem::SvxLineToLine(GetTop(), bConvert);
1749 break;
1750 case BORDER_DISTANCE:
1751 nDist = GetDistance();
1752 bDistMember = sal_True;
1753 break;
1754 case TOP_BORDER_DISTANCE:
1755 nDist = nTopDist;
1756 bDistMember = sal_True;
1757 break;
1758 case BOTTOM_BORDER_DISTANCE:
1759 nDist = nBottomDist;
1760 bDistMember = sal_True;
1761 break;
1762 case LEFT_BORDER_DISTANCE:
1763 nDist = nLeftDist;
1764 bDistMember = sal_True;
1765 break;
1766 case RIGHT_BORDER_DISTANCE:
1767 nDist = nRightDist;
1768 bDistMember = sal_True;
1769 break;
1772 if( bDistMember )
1773 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nDist) : nDist);
1774 else
1775 rVal <<= aRetLine;
1777 return true;
1780 namespace
1783 sal_Bool
1784 lcl_lineToSvxLine(const table::BorderLine& rLine, SvxBorderLine& rSvxLine, sal_Bool bConvert, sal_Bool bGuessWidth)
1786 rSvxLine.SetColor( Color(rLine.Color));
1787 if ( bGuessWidth )
1789 rSvxLine.GuessLinesWidths( rSvxLine.GetBorderLineStyle(),
1790 sal_uInt16( bConvert ? MM100_TO_TWIP(rLine.OuterLineWidth) : rLine.OuterLineWidth ),
1791 sal_uInt16( bConvert ? MM100_TO_TWIP(rLine.InnerLineWidth) : rLine.InnerLineWidth ),
1792 sal_uInt16( bConvert ? MM100_TO_TWIP(rLine.LineDistance ) : rLine.LineDistance ));
1795 sal_Bool bRet = !rSvxLine.isEmpty();
1796 return bRet;
1801 // -----------------------------------------------------------------------
1802 sal_Bool SvxBoxItem::LineToSvxLine(const ::com::sun::star::table::BorderLine& rLine, SvxBorderLine& rSvxLine, sal_Bool bConvert)
1804 return lcl_lineToSvxLine(rLine, rSvxLine, bConvert, sal_True);
1807 sal_Bool
1808 SvxBoxItem::LineToSvxLine(const ::com::sun::star::table::BorderLine2& rLine, SvxBorderLine& rSvxLine, sal_Bool bConvert)
1810 SvxBorderStyle const nStyle =
1811 (rLine.LineStyle < 0 || BORDER_LINE_STYLE_MAX < rLine.LineStyle)
1812 ? SOLID // default
1813 : rLine.LineStyle;
1815 rSvxLine.SetBorderLineStyle( nStyle );
1817 sal_Bool bGuessWidth = sal_True;
1818 if ( rLine.LineWidth )
1820 rSvxLine.SetWidth( bConvert? MM100_TO_TWIP_UNSIGNED( rLine.LineWidth ) : rLine.LineWidth );
1821 // fdo#46112: double does not necessarily mean symmetric
1822 // for backwards compatibility
1823 bGuessWidth = (DOUBLE == nStyle) &&
1824 (rLine.InnerLineWidth > 0) && (rLine.OuterLineWidth > 0);
1827 return lcl_lineToSvxLine(rLine, rSvxLine, bConvert, bGuessWidth);
1830 // -----------------------------------------------------------------------
1832 namespace
1835 bool
1836 lcl_extractBorderLine(const uno::Any& rAny, table::BorderLine2& rLine)
1838 if (rAny >>= rLine)
1839 return true;
1841 table::BorderLine aBorderLine;
1842 if (rAny >>= aBorderLine)
1844 rLine.Color = aBorderLine.Color;
1845 rLine.InnerLineWidth = aBorderLine.InnerLineWidth;
1846 rLine.OuterLineWidth = aBorderLine.OuterLineWidth;
1847 rLine.LineDistance = aBorderLine.LineDistance;
1848 rLine.LineStyle = table::BorderLineStyle::SOLID;
1849 return true;
1852 return false;
1855 template<typename Item>
1856 bool
1857 lcl_setLine(const uno::Any& rAny, Item& rItem, sal_uInt16 nLine, const bool bConvert)
1859 bool bDone = false;
1860 table::BorderLine2 aBorderLine;
1861 if (lcl_extractBorderLine(rAny, aBorderLine))
1863 SvxBorderLine aLine;
1864 bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
1865 rItem.SetLine( bSet ? &aLine : NULL, nLine);
1866 bDone = true;
1868 return bDone;
1873 bool SvxBoxItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1875 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1876 sal_uInt16 nLine = BOX_LINE_TOP;
1877 sal_Bool bDistMember = sal_False;
1878 nMemberId &= ~CONVERT_TWIPS;
1879 switch(nMemberId)
1881 case 0:
1883 uno::Sequence< uno::Any > aSeq;
1884 if (( rVal >>= aSeq ) && ( aSeq.getLength() == 9 ))
1886 // 4 Borders and 5 distances
1887 const sal_uInt16 aBorders[] = { BOX_LINE_LEFT, BOX_LINE_RIGHT, BOX_LINE_BOTTOM, BOX_LINE_TOP };
1888 for (int n(0); n != SAL_N_ELEMENTS(aBorders); ++n)
1890 if (!lcl_setLine(aSeq[n], *this, aBorders[n], bConvert))
1891 return sal_False;
1894 // WTH are the borders and the distances saved in different order?
1895 sal_uInt16 nLines[4] = { BOX_LINE_TOP, BOX_LINE_BOTTOM, BOX_LINE_LEFT, BOX_LINE_RIGHT };
1896 for ( sal_Int32 n = 4; n < 9; n++ )
1898 sal_Int32 nDist = 0;
1899 if ( aSeq[n] >>= nDist )
1901 if( bConvert )
1902 nDist = MM100_TO_TWIP(nDist);
1903 if ( n == 4 )
1904 SetDistance( sal_uInt16( nDist ));
1905 else
1906 SetDistance( sal_uInt16( nDist ), nLines[n-5] );
1908 else
1909 return sal_False;
1912 return sal_True;
1914 else
1915 return sal_False;
1917 case LEFT_BORDER_DISTANCE:
1918 bDistMember = sal_True;
1919 case LEFT_BORDER:
1920 case MID_LEFT_BORDER:
1921 nLine = BOX_LINE_LEFT;
1922 break;
1923 case RIGHT_BORDER_DISTANCE:
1924 bDistMember = sal_True;
1925 case RIGHT_BORDER:
1926 case MID_RIGHT_BORDER:
1927 nLine = BOX_LINE_RIGHT;
1928 break;
1929 case BOTTOM_BORDER_DISTANCE:
1930 bDistMember = sal_True;
1931 case BOTTOM_BORDER:
1932 case MID_BOTTOM_BORDER:
1933 nLine = BOX_LINE_BOTTOM;
1934 break;
1935 case TOP_BORDER_DISTANCE:
1936 bDistMember = sal_True;
1937 case TOP_BORDER:
1938 case MID_TOP_BORDER:
1939 nLine = BOX_LINE_TOP;
1940 break;
1941 case LINE_STYLE:
1943 drawing::LineStyle eDrawingStyle;
1944 rVal >>= eDrawingStyle;
1945 editeng::SvxBorderStyle eBorderStyle = NONE;
1946 switch ( eDrawingStyle )
1948 default:
1949 case drawing::LineStyle_NONE:
1950 break;
1951 case drawing::LineStyle_SOLID:
1952 eBorderStyle = SOLID;
1953 break;
1954 case drawing::LineStyle_DASH:
1955 eBorderStyle = DASHED;
1956 break;
1959 // Set the line style on all borders
1960 const sal_uInt16 aBorders[] = { BOX_LINE_LEFT, BOX_LINE_RIGHT, BOX_LINE_BOTTOM, BOX_LINE_TOP };
1961 for (int n(0); n != SAL_N_ELEMENTS(aBorders); ++n)
1963 editeng::SvxBorderLine* pLine = const_cast< editeng::SvxBorderLine* >( GetLine( aBorders[n] ) );
1964 if( pLine )
1965 pLine->SetBorderLineStyle( eBorderStyle );
1967 return sal_True;
1969 break;
1970 case LINE_WIDTH:
1972 // Set the line width on all borders
1973 long nWidth(0);
1974 rVal >>= nWidth;
1975 if( bConvert )
1976 nWidth = MM100_TO_TWIP( nWidth );
1978 // Set the line Width on all borders
1979 const sal_uInt16 aBorders[] = { BOX_LINE_LEFT, BOX_LINE_RIGHT, BOX_LINE_BOTTOM, BOX_LINE_TOP };
1980 for (int n(0); n != SAL_N_ELEMENTS(aBorders); ++n)
1982 editeng::SvxBorderLine* pLine = const_cast< editeng::SvxBorderLine* >( GetLine( aBorders[n] ) );
1983 pLine->SetWidth( nWidth );
1986 return sal_True;
1987 break;
1990 if( bDistMember || nMemberId == BORDER_DISTANCE )
1992 sal_Int32 nDist = 0;
1993 if(!(rVal >>= nDist))
1994 return sal_False;
1996 if(nDist >= 0)
1998 if( bConvert )
1999 nDist = MM100_TO_TWIP(nDist);
2000 if( nMemberId == BORDER_DISTANCE )
2001 SetDistance( sal_uInt16( nDist ));
2002 else
2003 SetDistance( sal_uInt16( nDist ), nLine );
2006 else
2008 SvxBorderLine aLine;
2009 if( !rVal.hasValue() )
2010 return sal_False;
2012 table::BorderLine2 aBorderLine;
2013 if( lcl_extractBorderLine(rVal, aBorderLine) )
2015 // usual struct
2017 else if (rVal.getValueTypeClass() == uno::TypeClass_SEQUENCE )
2019 // serialization for basic macro recording
2020 uno::Reference < script::XTypeConverter > xConverter
2021 ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString("com.sun.star.script.Converter")),
2022 uno::UNO_QUERY );
2023 uno::Sequence < uno::Any > aSeq;
2024 uno::Any aNew;
2025 try { aNew = xConverter->convertTo( rVal, ::getCppuType((const uno::Sequence < uno::Any >*)0) ); }
2026 catch (const uno::Exception&) {}
2028 aNew >>= aSeq;
2029 if (aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2031 sal_Int32 nVal = 0;
2032 if ( aSeq[0] >>= nVal )
2033 aBorderLine.Color = nVal;
2034 if ( aSeq[1] >>= nVal )
2035 aBorderLine.InnerLineWidth = (sal_Int16) nVal;
2036 if ( aSeq[2] >>= nVal )
2037 aBorderLine.OuterLineWidth = (sal_Int16) nVal;
2038 if ( aSeq[3] >>= nVal )
2039 aBorderLine.LineDistance = (sal_Int16) nVal;
2040 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2042 if (aSeq[4] >>= nVal)
2044 aBorderLine.LineStyle = nVal;
2046 if (aSeq.getLength() >= 6)
2048 if (aSeq[5] >>= nVal)
2050 aBorderLine.LineWidth = nVal;
2055 else
2056 return sal_False;
2058 else
2059 return sal_False;
2061 sal_Bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
2062 SetLine(bSet ? &aLine : 0, nLine);
2065 return sal_True;
2068 // -----------------------------------------------------------------------
2070 SfxPoolItem* SvxBoxItem::Clone( SfxItemPool* ) const
2072 return new SvxBoxItem( *this );
2075 //------------------------------------------------------------------------
2077 SfxItemPresentation SvxBoxItem::GetPresentation
2079 SfxItemPresentation ePres,
2080 SfxMapUnit eCoreUnit,
2081 SfxMapUnit ePresUnit,
2082 XubString& rText, const IntlWrapper *pIntl
2083 ) const
2085 switch ( ePres )
2087 case SFX_ITEM_PRESENTATION_NONE:
2088 rText.Erase();
2089 return SFX_ITEM_PRESENTATION_NONE;
2091 case SFX_ITEM_PRESENTATION_NAMELESS:
2093 rText.Erase();
2095 if ( pTop )
2097 rText = pTop->GetValueString( eCoreUnit, ePresUnit, pIntl );
2098 rText += cpDelim;
2100 if( !(pTop && pBottom && pLeft && pRight &&
2101 *pTop == *pBottom && *pTop == *pLeft && *pTop == *pRight) )
2103 if ( pBottom )
2105 rText += pBottom->GetValueString( eCoreUnit, ePresUnit, pIntl );
2106 rText += cpDelim;
2108 if ( pLeft )
2110 rText += pLeft->GetValueString( eCoreUnit, ePresUnit, pIntl );
2111 rText += cpDelim;
2113 if ( pRight )
2115 rText += pRight->GetValueString( eCoreUnit, ePresUnit, pIntl );
2116 rText += cpDelim;
2119 rText += GetMetricText( (long)nTopDist, eCoreUnit, ePresUnit, pIntl );
2120 if( nTopDist != nBottomDist || nTopDist != nLeftDist ||
2121 nTopDist != nRightDist )
2123 (((((rText += cpDelim)
2124 += GetMetricText( (long)nBottomDist, eCoreUnit,
2125 ePresUnit, pIntl ))
2126 += cpDelim)
2127 += GetMetricText( (long)nLeftDist, eCoreUnit, ePresUnit, pIntl ))
2128 += cpDelim)
2129 += GetMetricText( (long)nRightDist, eCoreUnit,
2130 ePresUnit, pIntl );
2132 return SFX_ITEM_PRESENTATION_NAMELESS;
2134 case SFX_ITEM_PRESENTATION_COMPLETE:
2136 if( !(pTop || pBottom || pLeft || pRight) )
2138 rText = EE_RESSTR(RID_SVXITEMS_BORDER_NONE);
2139 rText += cpDelim;
2141 else
2143 rText = EE_RESSTR(RID_SVXITEMS_BORDER_COMPLETE);
2144 if( pTop && pBottom && pLeft && pRight &&
2145 *pTop == *pBottom && *pTop == *pLeft && *pTop == *pRight )
2147 rText += pTop->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2148 rText += cpDelim;
2150 else
2152 if ( pTop )
2154 rText += EE_RESSTR(RID_SVXITEMS_BORDER_TOP);
2155 rText += pTop->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2156 rText += cpDelim;
2158 if ( pBottom )
2160 rText += EE_RESSTR(RID_SVXITEMS_BORDER_BOTTOM);
2161 rText += pBottom->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2162 rText += cpDelim;
2164 if ( pLeft )
2166 rText += EE_RESSTR(RID_SVXITEMS_BORDER_LEFT);
2167 rText += pLeft->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2168 rText += cpDelim;
2170 if ( pRight )
2172 rText += EE_RESSTR(RID_SVXITEMS_BORDER_RIGHT);
2173 rText += pRight->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2174 rText += cpDelim;
2179 rText += EE_RESSTR(RID_SVXITEMS_BORDER_DISTANCE);
2180 if( nTopDist == nBottomDist && nTopDist == nLeftDist &&
2181 nTopDist == nRightDist )
2183 rText += GetMetricText( (long)nTopDist, eCoreUnit,
2184 ePresUnit, pIntl );
2185 rText += EE_RESSTR(GetMetricId(ePresUnit));
2187 else
2189 (((rText += EE_RESSTR(RID_SVXITEMS_BORDER_TOP))
2190 += GetMetricText( (long)nTopDist, eCoreUnit,
2191 ePresUnit, pIntl ))
2192 += EE_RESSTR(GetMetricId(ePresUnit)))
2193 += cpDelim;
2194 (((rText += EE_RESSTR(RID_SVXITEMS_BORDER_BOTTOM))
2195 += GetMetricText( (long)nBottomDist, eCoreUnit,
2196 ePresUnit, pIntl ))
2197 += EE_RESSTR(GetMetricId(ePresUnit)))
2198 += cpDelim;
2199 (((rText += EE_RESSTR(RID_SVXITEMS_BORDER_LEFT))
2200 += GetMetricText( (long)nLeftDist, eCoreUnit,
2201 ePresUnit, pIntl ))
2202 += EE_RESSTR(GetMetricId(ePresUnit)))
2203 += cpDelim;
2204 ((rText += EE_RESSTR(RID_SVXITEMS_BORDER_RIGHT))
2205 += GetMetricText( (long)nRightDist, eCoreUnit,
2206 ePresUnit, pIntl ))
2207 += EE_RESSTR(GetMetricId(ePresUnit));
2209 return SFX_ITEM_PRESENTATION_COMPLETE;
2211 default: ;//prevent warning
2213 return SFX_ITEM_PRESENTATION_NONE;
2216 // -----------------------------------------------------------------------
2218 SvStream& SvxBoxItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
2220 rStrm << (sal_uInt16) GetDistance();
2221 const SvxBorderLine* pLine[ 4 ]; // top, left, right, bottom
2222 pLine[ 0 ] = GetTop();
2223 pLine[ 1 ] = GetLeft();
2224 pLine[ 2 ] = GetRight();
2225 pLine[ 3 ] = GetBottom();
2227 for( int i = 0; i < 4; i++ )
2229 const SvxBorderLine* l = pLine[ i ];
2230 if( l )
2232 rStrm << static_cast<sal_Int8>(i);
2233 StoreBorderLine(rStrm, *l, BorderLineVersionFromBoxVersion(nItemVersion));
2236 sal_Int8 cLine = 4;
2237 if( nItemVersion >= BOX_4DISTS_VERSION &&
2238 !(nTopDist == nLeftDist &&
2239 nTopDist == nRightDist &&
2240 nTopDist == nBottomDist) )
2242 cLine |= 0x10;
2245 rStrm << cLine;
2247 if( nItemVersion >= BOX_4DISTS_VERSION && (cLine & 0x10) != 0 )
2249 rStrm << (sal_uInt16)nTopDist
2250 << (sal_uInt16)nLeftDist
2251 << (sal_uInt16)nRightDist
2252 << (sal_uInt16)nBottomDist;
2255 return rStrm;
2258 // -----------------------------------------------------------------------
2260 sal_uInt16 SvxBoxItem::GetVersion( sal_uInt16 nFFVer ) const
2262 DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
2263 SOFFICE_FILEFORMAT_40==nFFVer ||
2264 SOFFICE_FILEFORMAT_50==nFFVer,
2265 "SvxBoxItem: Gibt es ein neues Fileformat?" );
2266 return SOFFICE_FILEFORMAT_31==nFFVer ||
2267 SOFFICE_FILEFORMAT_40==nFFVer ? 0 : BOX_BORDER_STYLE_VERSION;
2270 // -----------------------------------------------------------------------
2272 bool SvxBoxItem::ScaleMetrics( long nMult, long nDiv )
2274 if ( pTop ) pTop->ScaleMetrics( nMult, nDiv );
2275 if ( pBottom ) pBottom->ScaleMetrics( nMult, nDiv );
2276 if ( pLeft ) pLeft->ScaleMetrics( nMult, nDiv );
2277 if ( pRight ) pBottom->ScaleMetrics( nMult, nDiv );
2278 nTopDist = (sal_uInt16)Scale( nTopDist, nMult, nDiv );
2279 nBottomDist = (sal_uInt16)Scale( nBottomDist, nMult, nDiv );
2280 nLeftDist = (sal_uInt16)Scale( nLeftDist, nMult, nDiv );
2281 nRightDist = (sal_uInt16)Scale( nRightDist, nMult, nDiv );
2282 return true;
2285 // -----------------------------------------------------------------------
2287 bool SvxBoxItem::HasMetrics() const
2289 return true;
2292 // -----------------------------------------------------------------------
2294 SfxPoolItem* SvxBoxItem::Create( SvStream& rStrm, sal_uInt16 nIVersion ) const
2296 sal_uInt16 nDistance;
2297 rStrm >> nDistance;
2298 SvxBoxItem* pAttr = new SvxBoxItem( Which() );
2300 sal_uInt16 aLineMap[4] = { BOX_LINE_TOP, BOX_LINE_LEFT,
2301 BOX_LINE_RIGHT, BOX_LINE_BOTTOM };
2303 sal_Int8 cLine;
2304 while( sal_True )
2306 rStrm >> cLine;
2308 if( cLine > 3 )
2309 break;
2311 SvxBorderLine aBorder = CreateBorderLine(rStrm, BorderLineVersionFromBoxVersion(nIVersion));
2312 pAttr->SetLine( &aBorder, aLineMap[cLine] );
2315 if( nIVersion >= BOX_4DISTS_VERSION && (cLine&0x10) != 0 )
2317 for( sal_uInt16 i=0; i < 4; i++ )
2319 sal_uInt16 nDist;
2320 rStrm >> nDist;
2321 pAttr->SetDistance( nDist, aLineMap[i] );
2324 else
2326 pAttr->SetDistance( nDistance );
2329 return pAttr;
2332 // -----------------------------------------------------------------------
2334 const SvxBorderLine *SvxBoxItem::GetLine( sal_uInt16 nLine ) const
2336 const SvxBorderLine *pRet = 0;
2338 switch ( nLine )
2340 case BOX_LINE_TOP:
2341 pRet = pTop;
2342 break;
2343 case BOX_LINE_BOTTOM:
2344 pRet = pBottom;
2345 break;
2346 case BOX_LINE_LEFT:
2347 pRet = pLeft;
2348 break;
2349 case BOX_LINE_RIGHT:
2350 pRet = pRight;
2351 break;
2352 default:
2353 OSL_FAIL( "wrong line" );
2354 break;
2357 return pRet;
2360 // -----------------------------------------------------------------------
2362 void SvxBoxItem::SetLine( const SvxBorderLine* pNew, sal_uInt16 nLine )
2364 SvxBorderLine* pTmp = pNew ? new SvxBorderLine( *pNew ) : 0;
2366 switch ( nLine )
2368 case BOX_LINE_TOP:
2369 delete pTop;
2370 pTop = pTmp;
2371 break;
2372 case BOX_LINE_BOTTOM:
2373 delete pBottom;
2374 pBottom = pTmp;
2375 break;
2376 case BOX_LINE_LEFT:
2377 delete pLeft;
2378 pLeft = pTmp;
2379 break;
2380 case BOX_LINE_RIGHT:
2381 delete pRight;
2382 pRight = pTmp;
2383 break;
2384 default:
2385 delete pTmp;
2386 OSL_FAIL( "wrong line" );
2390 // -----------------------------------------------------------------------
2392 sal_uInt16 SvxBoxItem::GetDistance() const
2394 // The smallest distance that is not 0 will be returned.
2395 sal_uInt16 nDist = nTopDist;
2396 if( nBottomDist && (!nDist || nBottomDist < nDist) )
2397 nDist = nBottomDist;
2398 if( nLeftDist && (!nDist || nLeftDist < nDist) )
2399 nDist = nLeftDist;
2400 if( nRightDist && (!nDist || nRightDist < nDist) )
2401 nDist = nRightDist;
2403 return nDist;
2406 // -----------------------------------------------------------------------
2408 sal_uInt16 SvxBoxItem::GetDistance( sal_uInt16 nLine ) const
2410 sal_uInt16 nDist = 0;
2411 switch ( nLine )
2413 case BOX_LINE_TOP:
2414 nDist = nTopDist;
2415 break;
2416 case BOX_LINE_BOTTOM:
2417 nDist = nBottomDist;
2418 break;
2419 case BOX_LINE_LEFT:
2420 nDist = nLeftDist;
2421 break;
2422 case BOX_LINE_RIGHT:
2423 nDist = nRightDist;
2424 break;
2425 default:
2426 OSL_FAIL( "wrong line" );
2429 return nDist;
2432 // -----------------------------------------------------------------------
2434 void SvxBoxItem::SetDistance( sal_uInt16 nNew, sal_uInt16 nLine )
2436 switch ( nLine )
2438 case BOX_LINE_TOP:
2439 nTopDist = nNew;
2440 break;
2441 case BOX_LINE_BOTTOM:
2442 nBottomDist = nNew;
2443 break;
2444 case BOX_LINE_LEFT:
2445 nLeftDist = nNew;
2446 break;
2447 case BOX_LINE_RIGHT:
2448 nRightDist = nNew;
2449 break;
2450 default:
2451 OSL_FAIL( "wrong line" );
2455 // -----------------------------------------------------------------------
2457 sal_uInt16 SvxBoxItem::CalcLineSpace( sal_uInt16 nLine, sal_Bool bIgnoreLine ) const
2459 SvxBorderLine* pTmp = 0;
2460 sal_uInt16 nDist = 0;
2461 switch ( nLine )
2463 case BOX_LINE_TOP:
2464 pTmp = pTop;
2465 nDist = nTopDist;
2466 break;
2467 case BOX_LINE_BOTTOM:
2468 pTmp = pBottom;
2469 nDist = nBottomDist;
2470 break;
2471 case BOX_LINE_LEFT:
2472 pTmp = pLeft;
2473 nDist = nLeftDist;
2474 break;
2475 case BOX_LINE_RIGHT:
2476 pTmp = pRight;
2477 nDist = nRightDist;
2478 break;
2479 default:
2480 OSL_FAIL( "wrong line" );
2483 if( pTmp )
2485 nDist = nDist + (sal_uInt16)(pTmp->GetOutWidth()) + (sal_uInt16)(pTmp->GetInWidth()) + (sal_uInt16)(pTmp->GetDistance());
2487 else if( !bIgnoreLine )
2488 nDist = 0;
2489 return nDist;
2492 // class SvxBoxInfoItem --------------------------------------------------
2494 SvxBoxInfoItem::SvxBoxInfoItem( const sal_uInt16 nId ) :
2495 SfxPoolItem( nId ),
2496 pHori ( 0 ),
2497 pVert ( 0 ),
2498 mbEnableHor( false ),
2499 mbEnableVer( false ),
2500 nDefDist( 0 )
2502 bDist = bMinDist = sal_False;
2503 ResetFlags();
2506 // -----------------------------------------------------------------------
2508 SvxBoxInfoItem::SvxBoxInfoItem( const SvxBoxInfoItem& rCpy ) :
2509 SfxPoolItem( rCpy ),
2510 mbEnableHor( rCpy.mbEnableHor ),
2511 mbEnableVer( rCpy.mbEnableVer )
2513 pHori = rCpy.GetHori() ? new SvxBorderLine( *rCpy.GetHori() ) : 0;
2514 pVert = rCpy.GetVert() ? new SvxBorderLine( *rCpy.GetVert() ) : 0;
2515 bDist = rCpy.IsDist();
2516 bMinDist = rCpy.IsMinDist();
2517 nValidFlags = rCpy.nValidFlags;
2518 nDefDist = rCpy.GetDefDist();
2521 // -----------------------------------------------------------------------
2523 SvxBoxInfoItem::~SvxBoxInfoItem()
2525 delete pHori;
2526 delete pVert;
2529 // -----------------------------------------------------------------------
2531 SvxBoxInfoItem &SvxBoxInfoItem::operator=( const SvxBoxInfoItem& rCpy )
2533 delete pHori;
2534 delete pVert;
2535 pHori = rCpy.GetHori() ? new SvxBorderLine( *rCpy.GetHori() ) : 0;
2536 pVert = rCpy.GetVert() ? new SvxBorderLine( *rCpy.GetVert() ) : 0;
2537 mbEnableHor = rCpy.mbEnableHor;
2538 mbEnableVer = rCpy.mbEnableVer;
2539 bDist = rCpy.IsDist();
2540 bMinDist = rCpy.IsMinDist();
2541 nValidFlags = rCpy.nValidFlags;
2542 nDefDist = rCpy.GetDefDist();
2543 return *this;
2546 // -----------------------------------------------------------------------
2548 int SvxBoxInfoItem::operator==( const SfxPoolItem& rAttr ) const
2550 SvxBoxInfoItem& rBoxInfo = (SvxBoxInfoItem&)rAttr;
2552 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
2554 return ( mbEnableHor == rBoxInfo.mbEnableHor
2555 && mbEnableVer == rBoxInfo.mbEnableVer
2556 && bDist == rBoxInfo.IsDist()
2557 && bMinDist == rBoxInfo.IsMinDist()
2558 && nValidFlags == rBoxInfo.nValidFlags
2559 && nDefDist == rBoxInfo.GetDefDist()
2560 && CmpBrdLn( pHori, rBoxInfo.GetHori() )
2561 && CmpBrdLn( pVert, rBoxInfo.GetVert() )
2565 // -----------------------------------------------------------------------
2567 void SvxBoxInfoItem::SetLine( const SvxBorderLine* pNew, sal_uInt16 nLine )
2569 SvxBorderLine* pTmp = pNew ? new SvxBorderLine( *pNew ) : 0;
2571 if ( BOXINFO_LINE_HORI == nLine )
2573 delete pHori;
2574 pHori = pTmp;
2576 else if ( BOXINFO_LINE_VERT == nLine )
2578 delete pVert;
2579 pVert = pTmp;
2581 else
2583 delete pTmp;
2584 OSL_FAIL( "wrong line" );
2588 // -----------------------------------------------------------------------
2590 SfxPoolItem* SvxBoxInfoItem::Clone( SfxItemPool* ) const
2592 return new SvxBoxInfoItem( *this );
2595 //------------------------------------------------------------------------
2597 SfxItemPresentation SvxBoxInfoItem::GetPresentation
2599 SfxItemPresentation /*ePres*/,
2600 SfxMapUnit /*eCoreUnit*/,
2601 SfxMapUnit /*ePresUnit*/,
2602 XubString& rText, const IntlWrapper *
2603 ) const
2605 rText.Erase();
2606 return SFX_ITEM_PRESENTATION_NONE;
2609 // -----------------------------------------------------------------------
2611 SvStream& SvxBoxInfoItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
2613 sal_Int8 cFlags = 0;
2615 if ( IsTable() )
2616 cFlags |= 0x01;
2617 if ( IsDist() )
2618 cFlags |= 0x02;
2619 if ( IsMinDist() )
2620 cFlags |= 0x04;
2621 rStrm << (sal_Int8) cFlags
2622 << (sal_uInt16) GetDefDist();
2623 const SvxBorderLine* pLine[ 2 ];
2624 pLine[ 0 ] = GetHori();
2625 pLine[ 1 ] = GetVert();
2627 for( int i = 0; i < 2; i++ )
2629 const SvxBorderLine* l = pLine[ i ];
2630 if( l )
2632 rStrm << (char) i
2633 << l->GetColor()
2634 << (short) l->GetOutWidth()
2635 << (short) l->GetInWidth()
2636 << (short) l->GetDistance();
2639 rStrm << (char) 2;
2640 return rStrm;
2643 // -----------------------------------------------------------------------
2645 bool SvxBoxInfoItem::ScaleMetrics( long nMult, long nDiv )
2647 if ( pHori ) pHori->ScaleMetrics( nMult, nDiv );
2648 if ( pVert ) pVert->ScaleMetrics( nMult, nDiv );
2649 nDefDist = (sal_uInt16)Scale( nDefDist, nMult, nDiv );
2650 return true;
2653 // -----------------------------------------------------------------------
2655 bool SvxBoxInfoItem::HasMetrics() const
2657 return true;
2660 // -----------------------------------------------------------------------
2662 SfxPoolItem* SvxBoxInfoItem::Create( SvStream& rStrm, sal_uInt16 ) const
2664 sal_Int8 cFlags;
2665 sal_uInt16 _nDefDist;
2666 rStrm >> cFlags >> _nDefDist;
2668 SvxBoxInfoItem* pAttr = new SvxBoxInfoItem( Which() );
2670 pAttr->SetTable ( ( cFlags & 0x01 ) != 0 );
2671 pAttr->SetDist ( ( cFlags & 0x02 ) != 0 );
2672 pAttr->SetMinDist( ( cFlags & 0x04 ) != 0 );
2673 pAttr->SetDefDist( _nDefDist );
2675 while( sal_True )
2677 sal_Int8 cLine;
2678 rStrm >> cLine;
2680 if( cLine > 1 )
2681 break;
2682 short nOutline, nInline, nDistance;
2683 Color aColor;
2684 rStrm >> aColor >> nOutline >> nInline >> nDistance;
2685 SvxBorderLine aBorder( &aColor );
2686 aBorder.GuessLinesWidths(NONE, nOutline, nInline, nDistance);
2688 switch( cLine )
2690 case 0: pAttr->SetLine( &aBorder, BOXINFO_LINE_HORI ); break;
2691 case 1: pAttr->SetLine( &aBorder, BOXINFO_LINE_VERT ); break;
2694 return pAttr;
2697 // -----------------------------------------------------------------------
2699 void SvxBoxInfoItem::ResetFlags()
2701 nValidFlags = 0x7F; // all valid except Disable
2704 bool SvxBoxInfoItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
2706 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2707 table::BorderLine2 aRetLine;
2708 sal_Int16 nVal=0;
2709 sal_Bool bIntMember = sal_False;
2710 nMemberId &= ~CONVERT_TWIPS;
2711 switch(nMemberId)
2713 case 0:
2715 // 2 BorderLines, flags, valid flags and distance
2716 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq( 5 );
2717 aSeq[0] = ::com::sun::star::uno::makeAny( SvxBoxItem::SvxLineToLine( pHori, bConvert) );
2718 aSeq[1] = ::com::sun::star::uno::makeAny( SvxBoxItem::SvxLineToLine( pVert, bConvert) );
2719 if ( IsTable() )
2720 nVal |= 0x01;
2721 if ( IsDist() )
2722 nVal |= 0x02;
2723 if ( IsMinDist() )
2724 nVal |= 0x04;
2725 aSeq[2] = ::com::sun::star::uno::makeAny( nVal );
2726 nVal = nValidFlags;
2727 aSeq[3] = ::com::sun::star::uno::makeAny( nVal );
2728 aSeq[4] = ::com::sun::star::uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(GetDefDist()) : GetDefDist()) );
2729 rVal = ::com::sun::star::uno::makeAny( aSeq );
2730 return sal_True;
2733 case MID_HORIZONTAL:
2734 aRetLine = SvxBoxItem::SvxLineToLine( pHori, bConvert);
2735 break;
2736 case MID_VERTICAL:
2737 aRetLine = SvxBoxItem::SvxLineToLine( pVert, bConvert);
2738 break;
2739 case MID_FLAGS:
2740 bIntMember = sal_True;
2741 if ( IsTable() )
2742 nVal |= 0x01;
2743 if ( IsDist() )
2744 nVal |= 0x02;
2745 if ( IsMinDist() )
2746 nVal |= 0x04;
2747 rVal <<= nVal;
2748 break;
2749 case MID_VALIDFLAGS:
2750 bIntMember = sal_True;
2751 nVal = nValidFlags;
2752 rVal <<= nVal;
2753 break;
2754 case MID_DISTANCE:
2755 bIntMember = sal_True;
2756 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(GetDefDist()) : GetDefDist());
2757 break;
2758 default: OSL_FAIL("Wrong MemberId!"); return false;
2761 if( !bIntMember )
2762 rVal <<= aRetLine;
2764 return true;
2767 // -----------------------------------------------------------------------
2769 bool SvxBoxInfoItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
2771 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2772 nMemberId &= ~CONVERT_TWIPS;
2773 sal_Bool bRet;
2774 switch(nMemberId)
2776 case 0:
2778 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq;
2779 if (( rVal >>= aSeq ) && ( aSeq.getLength() == 5 ))
2781 // 2 BorderLines, flags, valid flags and distance
2782 if (!lcl_setLine(aSeq[0], *this, BOXINFO_LINE_HORI, bConvert))
2783 return sal_False;
2784 if (!lcl_setLine(aSeq[1], *this, BOXINFO_LINE_VERT, bConvert))
2785 return sal_False;
2787 sal_Int16 nFlags( 0 );
2788 sal_Int32 nVal( 0 );
2789 if ( aSeq[2] >>= nFlags )
2791 SetTable ( ( nFlags & 0x01 ) != 0 );
2792 SetDist ( ( nFlags & 0x02 ) != 0 );
2793 SetMinDist( ( nFlags & 0x04 ) != 0 );
2795 else
2796 return sal_False;
2797 if ( aSeq[3] >>= nFlags )
2798 nValidFlags = (sal_uInt8)nFlags;
2799 else
2800 return sal_False;
2801 if (( aSeq[4] >>= nVal ) && ( nVal >= 0 ))
2803 if( bConvert )
2804 nVal = MM100_TO_TWIP(nVal);
2805 SetDefDist( (sal_uInt16)nVal );
2808 return sal_True;
2811 case MID_HORIZONTAL:
2812 case MID_VERTICAL:
2814 if( !rVal.hasValue() )
2815 return sal_False;
2817 table::BorderLine2 aBorderLine;
2818 if( lcl_extractBorderLine(rVal, aBorderLine) )
2820 // usual struct
2822 else if (rVal.getValueTypeClass() == uno::TypeClass_SEQUENCE )
2824 // serialization for basic macro recording
2825 uno::Reference < script::XTypeConverter > xConverter
2826 ( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString("com.sun.star.script.Converter")),
2827 uno::UNO_QUERY );
2828 uno::Any aNew;
2829 uno::Sequence < uno::Any > aSeq;
2830 try { aNew = xConverter->convertTo( rVal, ::getCppuType((const uno::Sequence < uno::Any >*)0) ); }
2831 catch (const uno::Exception&) {}
2833 if ((aNew >>= aSeq) &&
2834 aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2836 sal_Int32 nVal = 0;
2837 if ( aSeq[0] >>= nVal )
2838 aBorderLine.Color = nVal;
2839 if ( aSeq[1] >>= nVal )
2840 aBorderLine.InnerLineWidth = (sal_Int16) nVal;
2841 if ( aSeq[2] >>= nVal )
2842 aBorderLine.OuterLineWidth = (sal_Int16) nVal;
2843 if ( aSeq[3] >>= nVal )
2844 aBorderLine.LineDistance = (sal_Int16) nVal;
2845 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2847 if (aSeq[4] >>= nVal)
2849 aBorderLine.LineStyle = nVal;
2851 if (aSeq.getLength() >= 6)
2853 if (aSeq[5] >>= nVal)
2855 aBorderLine.LineWidth = nVal;
2860 else
2861 return sal_False;
2863 else if (rVal.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < sal_Int16 >*)0) )
2865 // serialization for basic macro recording
2866 ::com::sun::star::uno::Sequence < sal_Int16 > aSeq;
2867 rVal >>= aSeq;
2868 if (aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2870 aBorderLine.Color = aSeq[0];
2871 aBorderLine.InnerLineWidth = aSeq[1];
2872 aBorderLine.OuterLineWidth = aSeq[2];
2873 aBorderLine.LineDistance = aSeq[3];
2874 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2876 aBorderLine.LineStyle = aSeq[4];
2877 if (aSeq.getLength() >= 6)
2879 aBorderLine.LineWidth = aSeq[5];
2883 else
2884 return sal_False;
2886 else
2887 return sal_False;
2889 SvxBorderLine aLine;
2890 sal_Bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
2891 if ( bSet )
2892 SetLine( &aLine, nMemberId == MID_HORIZONTAL ? BOXINFO_LINE_HORI : BOXINFO_LINE_VERT );
2893 break;
2895 case MID_FLAGS:
2897 sal_Int16 nFlags = sal_Int16();
2898 bRet = (rVal >>= nFlags);
2899 if ( bRet )
2901 SetTable ( ( nFlags & 0x01 ) != 0 );
2902 SetDist ( ( nFlags & 0x02 ) != 0 );
2903 SetMinDist( ( nFlags & 0x04 ) != 0 );
2906 break;
2908 case MID_VALIDFLAGS:
2910 sal_Int16 nFlags = sal_Int16();
2911 bRet = (rVal >>= nFlags);
2912 if ( bRet )
2913 nValidFlags = (sal_uInt8)nFlags;
2914 break;
2916 case MID_DISTANCE:
2918 sal_Int32 nVal = 0;
2919 bRet = (rVal >>= nVal);
2920 if ( bRet && nVal>=0 )
2922 if( bConvert )
2923 nVal = MM100_TO_TWIP(nVal);
2924 SetDefDist( (sal_uInt16)nVal );
2926 break;
2928 default: OSL_FAIL("Wrong MemberId!"); return sal_False;
2931 return sal_True;
2934 // class SvxFmtBreakItem -------------------------------------------------
2936 int SvxFmtBreakItem::operator==( const SfxPoolItem& rAttr ) const
2938 DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "unequal types" );
2940 return GetValue() == ( (SvxFmtBreakItem&)rAttr ).GetValue();
2943 //------------------------------------------------------------------------
2945 SfxItemPresentation SvxFmtBreakItem::GetPresentation
2947 SfxItemPresentation ePres,
2948 SfxMapUnit /*eCoreUnit*/,
2949 SfxMapUnit /*ePresUnit*/,
2950 XubString& rText, const IntlWrapper *
2951 ) const
2953 switch ( ePres )
2955 case SFX_ITEM_PRESENTATION_NONE:
2956 rText.Erase();
2957 return SFX_ITEM_PRESENTATION_NONE;
2959 case SFX_ITEM_PRESENTATION_NAMELESS:
2960 case SFX_ITEM_PRESENTATION_COMPLETE:
2961 rText = GetValueTextByPos( GetValue() );
2962 return ePres;
2963 default: ;//prevent warning
2965 return SFX_ITEM_PRESENTATION_NONE;
2968 // -----------------------------------------------------------------------
2970 rtl::OUString SvxFmtBreakItem::GetValueTextByPos( sal_uInt16 nPos ) const
2972 DBG_ASSERT( nPos < SVX_BREAK_END, "enum overflow!" );
2973 return EE_RESSTR(RID_SVXITEMS_BREAK_BEGIN + nPos);
2976 // -----------------------------------------------------------------------
2977 bool SvxFmtBreakItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
2979 style::BreakType eBreak = style::BreakType_NONE;
2980 switch ( (SvxBreak)GetValue() )
2982 case SVX_BREAK_COLUMN_BEFORE: eBreak = style::BreakType_COLUMN_BEFORE; break;
2983 case SVX_BREAK_COLUMN_AFTER: eBreak = style::BreakType_COLUMN_AFTER ; break;
2984 case SVX_BREAK_COLUMN_BOTH: eBreak = style::BreakType_COLUMN_BOTH ; break;
2985 case SVX_BREAK_PAGE_BEFORE: eBreak = style::BreakType_PAGE_BEFORE ; break;
2986 case SVX_BREAK_PAGE_AFTER: eBreak = style::BreakType_PAGE_AFTER ; break;
2987 case SVX_BREAK_PAGE_BOTH: eBreak = style::BreakType_PAGE_BOTH ; break;
2988 default: ;//prevent warning
2990 rVal <<= eBreak;
2991 return true;
2993 // -----------------------------------------------------------------------
2994 bool SvxFmtBreakItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
2996 style::BreakType nBreak;
2998 if(!(rVal >>= nBreak))
3000 sal_Int32 nValue = 0;
3001 if(!(rVal >>= nValue))
3002 return sal_False;
3004 nBreak = (style::BreakType) nValue;
3007 SvxBreak eBreak = SVX_BREAK_NONE;
3008 switch( nBreak )
3010 case style::BreakType_COLUMN_BEFORE: eBreak = SVX_BREAK_COLUMN_BEFORE; break;
3011 case style::BreakType_COLUMN_AFTER: eBreak = SVX_BREAK_COLUMN_AFTER; break;
3012 case style::BreakType_COLUMN_BOTH: eBreak = SVX_BREAK_COLUMN_BOTH; break;
3013 case style::BreakType_PAGE_BEFORE: eBreak = SVX_BREAK_PAGE_BEFORE; break;
3014 case style::BreakType_PAGE_AFTER: eBreak = SVX_BREAK_PAGE_AFTER; break;
3015 case style::BreakType_PAGE_BOTH: eBreak = SVX_BREAK_PAGE_BOTH; break;
3016 default: ;//prevent warning
3018 SetValue((sal_uInt16) eBreak);
3020 return true;
3023 // -----------------------------------------------------------------------
3025 SfxPoolItem* SvxFmtBreakItem::Clone( SfxItemPool* ) const
3027 return new SvxFmtBreakItem( *this );
3030 // -----------------------------------------------------------------------
3032 SvStream& SvxFmtBreakItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
3034 rStrm << (sal_Int8)GetValue();
3035 if( FMTBREAK_NOAUTO > nItemVersion )
3036 rStrm << (sal_Int8)0x01;
3037 return rStrm;
3040 // -----------------------------------------------------------------------
3042 sal_uInt16 SvxFmtBreakItem::GetVersion( sal_uInt16 nFFVer ) const
3044 DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
3045 SOFFICE_FILEFORMAT_40==nFFVer ||
3046 SOFFICE_FILEFORMAT_50==nFFVer,
3047 "SvxFmtBreakItem: Is there a new file format? ");
3048 return SOFFICE_FILEFORMAT_31==nFFVer ||
3049 SOFFICE_FILEFORMAT_40==nFFVer ? 0 : FMTBREAK_NOAUTO;
3052 // -----------------------------------------------------------------------
3054 SfxPoolItem* SvxFmtBreakItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
3056 sal_Int8 eBreak, bDummy;
3057 rStrm >> eBreak;
3058 if( FMTBREAK_NOAUTO > nVersion )
3059 rStrm >> bDummy;
3060 return new SvxFmtBreakItem( (const SvxBreak)eBreak, Which() );
3063 // -----------------------------------------------------------------------
3065 sal_uInt16 SvxFmtBreakItem::GetValueCount() const
3067 return SVX_BREAK_END; // SVX_BREAK_PAGE_BOTH + 1
3070 // class SvxFmtKeepItem -------------------------------------------------
3072 SfxPoolItem* SvxFmtKeepItem::Clone( SfxItemPool* ) const
3074 return new SvxFmtKeepItem( *this );
3077 // -----------------------------------------------------------------------
3079 SvStream& SvxFmtKeepItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
3081 rStrm << (sal_Int8)GetValue();
3082 return rStrm;
3085 // -----------------------------------------------------------------------
3087 SfxPoolItem* SvxFmtKeepItem::Create( SvStream& rStrm, sal_uInt16 ) const
3089 sal_Int8 bIsKeep;
3090 rStrm >> bIsKeep;
3091 return new SvxFmtKeepItem( sal_Bool( bIsKeep != 0 ), Which() );
3094 //------------------------------------------------------------------------
3096 SfxItemPresentation SvxFmtKeepItem::GetPresentation
3098 SfxItemPresentation ePres,
3099 SfxMapUnit /*eCoreUnit*/,
3100 SfxMapUnit /*ePresUnit*/,
3101 XubString& rText, const IntlWrapper *
3102 ) const
3104 switch ( ePres )
3106 case SFX_ITEM_PRESENTATION_NONE:
3107 rText.Erase();
3108 return ePres;
3110 case SFX_ITEM_PRESENTATION_NAMELESS:
3111 case SFX_ITEM_PRESENTATION_COMPLETE:
3113 sal_uInt16 nId = RID_SVXITEMS_FMTKEEP_FALSE;
3115 if ( GetValue() )
3116 nId = RID_SVXITEMS_FMTKEEP_TRUE;
3117 rText = EE_RESSTR(nId);
3118 return ePres;
3120 default: ;//prevent warning
3122 return SFX_ITEM_PRESENTATION_NONE;
3125 // class SvxLineItem ------------------------------------------------------
3127 SvxLineItem::SvxLineItem( const sal_uInt16 nId ) :
3129 SfxPoolItem ( nId ),
3131 pLine( NULL )
3135 // -----------------------------------------------------------------------
3137 SvxLineItem::SvxLineItem( const SvxLineItem& rCpy ) :
3139 SfxPoolItem ( rCpy )
3141 pLine = rCpy.GetLine() ? new SvxBorderLine( *rCpy.GetLine() ) : 0;
3144 // -----------------------------------------------------------------------
3146 SvxLineItem::~SvxLineItem()
3148 delete pLine;
3151 // -----------------------------------------------------------------------
3153 SvxLineItem& SvxLineItem::operator=( const SvxLineItem& rLine )
3155 SetLine( rLine.GetLine() );
3157 return *this;
3160 // -----------------------------------------------------------------------
3162 int SvxLineItem::operator==( const SfxPoolItem& rAttr ) const
3164 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
3166 return CmpBrdLn( pLine, ((SvxLineItem&)rAttr).GetLine() );
3169 // -----------------------------------------------------------------------
3171 SfxPoolItem* SvxLineItem::Clone( SfxItemPool* ) const
3173 return new SvxLineItem( *this );
3176 bool SvxLineItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemId ) const
3178 sal_Bool bConvert = 0!=(nMemId&CONVERT_TWIPS);
3179 nMemId &= ~CONVERT_TWIPS;
3180 if ( nMemId == 0 )
3182 rVal <<= uno::makeAny( SvxBoxItem::SvxLineToLine(pLine, bConvert) );
3183 return true;
3185 else if ( pLine )
3187 switch ( nMemId )
3189 case MID_FG_COLOR: rVal <<= sal_Int32(pLine->GetColor().GetColor()); break;
3190 case MID_OUTER_WIDTH: rVal <<= sal_Int32(pLine->GetOutWidth()); break;
3191 case MID_INNER_WIDTH: rVal <<= sal_Int32(pLine->GetInWidth( )); break;
3192 case MID_DISTANCE: rVal <<= sal_Int32(pLine->GetDistance()); break;
3193 default:
3194 OSL_FAIL( "Wrong MemberId" );
3195 return false;
3199 return true;
3202 // -----------------------------------------------------------------------
3204 bool SvxLineItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemId )
3206 sal_Bool bConvert = 0!=(nMemId&CONVERT_TWIPS);
3207 nMemId &= ~CONVERT_TWIPS;
3208 sal_Int32 nVal = 0;
3209 if ( nMemId == 0 )
3211 table::BorderLine2 aLine;
3212 if ( lcl_extractBorderLine(rVal, aLine) )
3214 if ( !pLine )
3215 pLine = new SvxBorderLine;
3216 if( !SvxBoxItem::LineToSvxLine(aLine, *pLine, bConvert) )
3217 DELETEZ( pLine );
3218 return true;
3220 return false;
3222 else if ( rVal >>= nVal )
3224 if ( !pLine )
3225 pLine = new SvxBorderLine;
3227 switch ( nMemId )
3229 case MID_FG_COLOR: pLine->SetColor( Color(nVal) ); break;
3230 case MID_LINE_STYLE:
3231 pLine->SetBorderLineStyle(static_cast<SvxBorderStyle>(nVal));
3232 break;
3233 default:
3234 OSL_FAIL( "Wrong MemberId" );
3235 return sal_False;
3238 return true;
3241 return false;
3244 //------------------------------------------------------------------------
3246 SfxItemPresentation SvxLineItem::GetPresentation
3248 SfxItemPresentation ePres,
3249 SfxMapUnit eCoreUnit,
3250 SfxMapUnit ePresUnit,
3251 XubString& rText, const IntlWrapper *pIntl
3252 ) const
3254 rText.Erase();
3256 switch ( ePres )
3258 case SFX_ITEM_PRESENTATION_NONE:
3259 return SFX_ITEM_PRESENTATION_NONE;
3260 case SFX_ITEM_PRESENTATION_NAMELESS:
3261 case SFX_ITEM_PRESENTATION_COMPLETE:
3263 if ( pLine )
3264 rText = pLine->GetValueString( eCoreUnit, ePresUnit, pIntl,
3265 (SFX_ITEM_PRESENTATION_COMPLETE == ePres) );
3266 return ePres;
3268 default: ;//prevent warning
3270 return SFX_ITEM_PRESENTATION_NONE;
3273 // -----------------------------------------------------------------------
3275 SvStream& SvxLineItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
3277 if( pLine )
3279 rStrm << pLine->GetColor()
3280 << (short)pLine->GetOutWidth()
3281 << (short)pLine->GetInWidth()
3282 << (short)pLine->GetDistance();
3284 else
3285 rStrm << Color() << (short)0 << (short)0 << (short)0;
3286 return rStrm;
3289 // -----------------------------------------------------------------------
3291 bool SvxLineItem::ScaleMetrics( long nMult, long nDiv )
3293 if ( pLine ) pLine->ScaleMetrics( nMult, nDiv );
3294 return true;
3297 // -----------------------------------------------------------------------
3299 bool SvxLineItem::HasMetrics() const
3301 return true;
3304 // -----------------------------------------------------------------------
3306 SfxPoolItem* SvxLineItem::Create( SvStream& rStrm, sal_uInt16 ) const
3308 SvxLineItem* _pLine = new SvxLineItem( Which() );
3309 short nOutline, nInline, nDistance;
3310 Color aColor;
3312 rStrm >> aColor >> nOutline >> nInline >> nDistance;
3313 if( nOutline )
3315 SvxBorderLine aLine( &aColor );
3316 aLine.GuessLinesWidths(NONE, nOutline, nInline, nDistance);
3317 _pLine->SetLine( &aLine );
3319 return _pLine;
3322 // -----------------------------------------------------------------------
3324 void SvxLineItem::SetLine( const SvxBorderLine* pNew )
3326 delete pLine;
3327 pLine = pNew ? new SvxBorderLine( *pNew ) : 0;
3330 #ifdef _MSC_VER
3331 #pragma optimize ( "", off )
3332 #endif
3334 // class SvxBrushItem ----------------------------------------------------
3336 #define LOAD_GRAPHIC ((sal_uInt16)0x0001)
3337 #define LOAD_LINK ((sal_uInt16)0x0002)
3338 #define LOAD_FILTER ((sal_uInt16)0x0004)
3340 // class SvxBrushItem_Impl -----------------------------------------------
3342 class SvxBrushItem_Impl
3344 public:
3345 GraphicObject* pGraphicObject;
3346 sal_Int8 nGraphicTransparency; //contains a percentage value which is
3347 //copied to the GraphicObject when necessary
3348 Link aDoneLink;
3349 SvStream* pStream;
3351 SvxBrushItem_Impl( GraphicObject* p ) : pGraphicObject( p ), nGraphicTransparency(0), pStream(0) {}
3354 // -----------------------------------------------------------------------
3356 void SvxBrushItem::SetDoneLink( const Link& rLink )
3358 pImpl->aDoneLink = rLink;
3361 // -----------------------------------------------------------------------
3363 SvxBrushItem::SvxBrushItem( sal_uInt16 _nWhich ) :
3365 SfxPoolItem( _nWhich ),
3367 aColor ( COL_TRANSPARENT ),
3368 pImpl ( new SvxBrushItem_Impl( 0 ) ),
3369 pStrLink ( NULL ),
3370 pStrFilter ( NULL ),
3371 eGraphicPos ( GPOS_NONE ),
3372 bLoadAgain ( sal_True )
3377 // -----------------------------------------------------------------------
3379 SvxBrushItem::SvxBrushItem( const Color& rColor, sal_uInt16 _nWhich) :
3381 SfxPoolItem( _nWhich ),
3383 aColor ( rColor ),
3384 pImpl ( new SvxBrushItem_Impl( 0 ) ),
3385 pStrLink ( NULL ),
3386 pStrFilter ( NULL ),
3387 eGraphicPos ( GPOS_NONE ),
3388 bLoadAgain ( sal_True )
3393 // -----------------------------------------------------------------------
3395 SvxBrushItem::SvxBrushItem( const Graphic& rGraphic, SvxGraphicPosition ePos,
3396 sal_uInt16 _nWhich ) :
3398 SfxPoolItem( _nWhich ),
3400 aColor ( COL_TRANSPARENT ),
3401 pImpl ( new SvxBrushItem_Impl( new GraphicObject( rGraphic ) ) ),
3402 pStrLink ( NULL ),
3403 pStrFilter ( NULL ),
3404 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3405 bLoadAgain ( sal_True )
3408 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3411 // -----------------------------------------------------------------------
3413 SvxBrushItem::SvxBrushItem( const GraphicObject& rGraphicObj,
3414 SvxGraphicPosition ePos, sal_uInt16 _nWhich ) :
3416 SfxPoolItem( _nWhich ),
3418 aColor ( COL_TRANSPARENT ),
3419 pImpl ( new SvxBrushItem_Impl( new GraphicObject( rGraphicObj ) ) ),
3420 pStrLink ( NULL ),
3421 pStrFilter ( NULL ),
3422 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3423 bLoadAgain ( sal_True )
3426 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3429 // -----------------------------------------------------------------------
3431 SvxBrushItem::SvxBrushItem(
3432 const String& rLink, const String& rFilter,
3433 SvxGraphicPosition ePos, sal_uInt16 _nWhich ) :
3435 SfxPoolItem( _nWhich ),
3437 aColor ( COL_TRANSPARENT ),
3438 pImpl ( new SvxBrushItem_Impl( NULL ) ),
3439 pStrLink ( new String( rLink ) ),
3440 pStrFilter ( new String( rFilter ) ),
3441 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3442 bLoadAgain ( sal_True )
3445 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3448 // -----------------------------------------------------------------------
3450 SvxBrushItem::SvxBrushItem( SvStream& rStream, sal_uInt16 nVersion,
3451 sal_uInt16 _nWhich ) :
3453 SfxPoolItem( _nWhich ),
3455 aColor ( COL_TRANSPARENT ),
3456 pImpl ( new SvxBrushItem_Impl( NULL ) ),
3457 pStrLink ( NULL ),
3458 pStrFilter ( NULL ),
3459 eGraphicPos ( GPOS_NONE )
3462 sal_Bool bTrans;
3463 Color aTempColor;
3464 Color aTempFillColor;
3465 sal_Int8 nStyle;
3467 rStream >> bTrans;
3468 rStream >> aTempColor;
3469 rStream >> aTempFillColor;
3470 rStream >> nStyle;
3472 switch ( nStyle )
3474 case 8://BRUSH_25:
3476 sal_uInt32 nRed = aTempColor.GetRed();
3477 sal_uInt32 nGreen = aTempColor.GetGreen();
3478 sal_uInt32 nBlue = aTempColor.GetBlue();
3479 nRed += (sal_uInt32)(aTempFillColor.GetRed())*2;
3480 nGreen += (sal_uInt32)(aTempFillColor.GetGreen())*2;
3481 nBlue += (sal_uInt32)(aTempFillColor.GetBlue())*2;
3482 aColor = Color( (sal_Int8)(nRed/3), (sal_Int8)(nGreen/3), (sal_Int8)(nBlue/3) );
3484 break;
3486 case 9://BRUSH_50:
3488 sal_uInt32 nRed = aTempColor.GetRed();
3489 sal_uInt32 nGreen = aTempColor.GetGreen();
3490 sal_uInt32 nBlue = aTempColor.GetBlue();
3491 nRed += (sal_uInt32)(aTempFillColor.GetRed());
3492 nGreen += (sal_uInt32)(aTempFillColor.GetGreen());
3493 nBlue += (sal_uInt32)(aTempFillColor.GetBlue());
3494 aColor = Color( (sal_Int8)(nRed/2), (sal_Int8)(nGreen/2), (sal_Int8)(nBlue/2) );
3496 break;
3498 case 10://BRUSH_75:
3500 sal_uInt32 nRed = aTempColor.GetRed()*2;
3501 sal_uInt32 nGreen = aTempColor.GetGreen()*2;
3502 sal_uInt32 nBlue = aTempColor.GetBlue()*2;
3503 nRed += (sal_uInt32)(aTempFillColor.GetRed());
3504 nGreen += (sal_uInt32)(aTempFillColor.GetGreen());
3505 nBlue += (sal_uInt32)(aTempFillColor.GetBlue());
3506 aColor = Color( (sal_Int8)(nRed/3), (sal_Int8)(nGreen/3), (sal_Int8)(nBlue/3) );
3508 break;
3510 case 0://BRUSH_NULL:
3511 aColor = Color( COL_TRANSPARENT );
3512 break;
3514 default:
3515 aColor = aTempColor;
3518 if ( nVersion >= BRUSH_GRAPHIC_VERSION )
3520 sal_uInt16 nDoLoad = 0;
3521 sal_Int8 nPos;
3523 rStream >> nDoLoad;
3525 if ( nDoLoad & LOAD_GRAPHIC )
3527 Graphic aGraphic;
3529 rStream >> aGraphic;
3530 pImpl->pGraphicObject = new GraphicObject( aGraphic );
3532 if( SVSTREAM_FILEFORMAT_ERROR == rStream.GetError() )
3534 rStream.ResetError();
3535 rStream.SetError( ERRCODE_SVX_GRAPHIC_WRONG_FILEFORMAT|
3536 ERRCODE_WARNING_MASK );
3540 if ( nDoLoad & LOAD_LINK )
3542 // UNICODE: rStream >> aRel;
3543 String aRel = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
3545 // TODO/MBA: how can we get a BaseURL here?!
3546 OSL_FAIL("No BaseURL!");
3547 String aAbs = INetURLObject::GetAbsURL( String(), aRel );
3548 DBG_ASSERT( aAbs.Len(), "Invalid URL!" );
3549 pStrLink = new String( aAbs );
3552 if ( nDoLoad & LOAD_FILTER )
3554 pStrFilter = new String;
3555 // UNICODE: rStream >> *pStrFilter;
3556 *pStrFilter = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
3559 rStream >> nPos;
3561 eGraphicPos = (SvxGraphicPosition)nPos;
3565 // -----------------------------------------------------------------------
3567 SvxBrushItem::SvxBrushItem( const SvxBrushItem& rItem ) :
3569 SfxPoolItem( rItem.Which() ),
3571 pImpl ( new SvxBrushItem_Impl( NULL ) ),
3572 pStrLink ( NULL ),
3573 pStrFilter ( NULL ),
3574 eGraphicPos ( GPOS_NONE ),
3575 bLoadAgain ( sal_True )
3578 *this = rItem;
3581 // -----------------------------------------------------------------------
3583 SvxBrushItem::~SvxBrushItem()
3585 delete pImpl->pGraphicObject;
3586 delete pImpl;
3587 delete pStrLink;
3588 delete pStrFilter;
3591 // -----------------------------------------------------------------------
3593 sal_uInt16 SvxBrushItem::GetVersion( sal_uInt16 /*nFileVersion*/ ) const
3595 return BRUSH_GRAPHIC_VERSION;
3598 // -----------------------------------------------------------------------
3599 inline sal_Int8 lcl_PercentToTransparency(long nPercent)
3601 //0xff must not be returned!
3602 return sal_Int8(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
3604 inline sal_Int8 lcl_TransparencyToPercent(sal_Int32 nTrans)
3606 return (sal_Int8)((nTrans * 100 + 127) / 254);
3609 bool SvxBrushItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
3611 nMemberId &= ~CONVERT_TWIPS;
3612 switch( nMemberId)
3614 case MID_BACK_COLOR:
3615 rVal <<= (sal_Int32)( aColor.GetColor() );
3616 break;
3617 case MID_BACK_COLOR_R_G_B:
3618 rVal <<= (sal_Int32)( aColor.GetRGBColor() );
3619 break;
3620 case MID_BACK_COLOR_TRANSPARENCY:
3621 rVal <<= lcl_TransparencyToPercent(aColor.GetTransparency());
3622 break;
3623 case MID_GRAPHIC_POSITION:
3624 rVal <<= (style::GraphicLocation)(sal_Int16)eGraphicPos;
3625 break;
3627 case MID_GRAPHIC:
3628 SAL_WARN( "editeng.items", "not implemented" );
3629 break;
3631 case MID_GRAPHIC_TRANSPARENT:
3632 rVal = Bool2Any( aColor.GetTransparency() == 0xff );
3633 break;
3635 case MID_GRAPHIC_URL:
3637 OUString sLink;
3638 if ( pStrLink )
3639 sLink = *pStrLink;
3640 else if( pImpl->pGraphicObject )
3642 OUString sPrefix(
3643 UNO_NAME_GRAPHOBJ_URLPREFIX);
3644 OUString sId(rtl::OStringToOUString(
3645 pImpl->pGraphicObject->GetUniqueID(),
3646 RTL_TEXTENCODING_ASCII_US));
3647 sLink = sPrefix + sId;
3649 rVal <<= sLink;
3651 break;
3653 case MID_GRAPHIC_FILTER:
3655 OUString sFilter;
3656 if ( pStrFilter )
3657 sFilter = *pStrFilter;
3658 rVal <<= sFilter;
3660 break;
3661 case MID_GRAPHIC_TRANSPARENCY :
3662 rVal <<= pImpl->nGraphicTransparency;
3663 break;
3666 return true;
3669 // -----------------------------------------------------------------------
3671 bool SvxBrushItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
3673 nMemberId &= ~CONVERT_TWIPS;
3674 switch( nMemberId)
3676 case MID_BACK_COLOR:
3677 case MID_BACK_COLOR_R_G_B:
3679 sal_Int32 nCol = 0;
3680 if ( !( rVal >>= nCol ) )
3681 return sal_False;
3682 if(MID_BACK_COLOR_R_G_B == nMemberId)
3684 nCol = COLORDATA_RGB( nCol );
3685 nCol += aColor.GetColor() & 0xff000000;
3687 aColor = Color( nCol );
3689 break;
3690 case MID_BACK_COLOR_TRANSPARENCY:
3692 sal_Int32 nTrans = 0;
3693 if ( !( rVal >>= nTrans ) || nTrans < 0 || nTrans > 100 )
3694 return sal_False;
3695 aColor.SetTransparency(lcl_PercentToTransparency(nTrans));
3697 break;
3699 case MID_GRAPHIC_POSITION:
3701 style::GraphicLocation eLocation;
3702 if ( !( rVal>>=eLocation ) )
3704 sal_Int32 nValue = 0;
3705 if ( !( rVal >>= nValue ) )
3706 return sal_False;
3707 eLocation = (style::GraphicLocation)nValue;
3709 SetGraphicPos( (SvxGraphicPosition)(sal_uInt16)eLocation );
3711 break;
3713 case MID_GRAPHIC:
3714 SAL_WARN( "editeng.items", "not implemented" );
3715 break;
3717 case MID_GRAPHIC_TRANSPARENT:
3718 aColor.SetTransparency( Any2Bool( rVal ) ? 0xff : 0 );
3719 break;
3721 case MID_GRAPHIC_URL:
3723 if ( rVal.getValueType() == ::getCppuType( (OUString*)0 ) )
3725 OUString sLink;
3726 rVal >>= sLink;
3727 if( 0 == sLink.compareToAscii( UNO_NAME_GRAPHOBJ_URLPKGPREFIX,
3728 sizeof(UNO_NAME_GRAPHOBJ_URLPKGPREFIX)-1 ) )
3730 OSL_FAIL( "package urls aren't implemented" );
3732 else if( 0 == sLink.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX,
3733 sizeof(UNO_NAME_GRAPHOBJ_URLPREFIX)-1 ) )
3735 DELETEZ( pStrLink );
3736 String sTmp( sLink );
3737 rtl::OString sId(rtl::OUStringToOString(sTmp.Copy(
3738 sizeof(UNO_NAME_GRAPHOBJ_URLPREFIX)-1),
3739 RTL_TEXTENCODING_ASCII_US));
3740 GraphicObject *pOldGrfObj = pImpl->pGraphicObject;
3741 pImpl->pGraphicObject = new GraphicObject( sId );
3742 ApplyGraphicTransparency_Impl();
3743 delete pOldGrfObj;
3745 else
3747 SetGraphicLink(sLink);
3749 if ( !sLink.isEmpty() && eGraphicPos == GPOS_NONE )
3750 eGraphicPos = GPOS_MM;
3751 else if( sLink.isEmpty() )
3752 eGraphicPos = GPOS_NONE;
3755 break;
3757 case MID_GRAPHIC_FILTER:
3759 if( rVal.getValueType() == ::getCppuType( (OUString*)0 ) )
3761 OUString sLink;
3762 rVal >>= sLink;
3763 SetGraphicFilter( sLink );
3766 break;
3767 case MID_GRAPHIC_TRANSPARENCY :
3769 sal_Int32 nTmp = 0;
3770 rVal >>= nTmp;
3771 if(nTmp >= 0 && nTmp <= 100)
3773 pImpl->nGraphicTransparency = sal_Int8(nTmp);
3774 if(pImpl->pGraphicObject)
3775 ApplyGraphicTransparency_Impl();
3778 break;
3781 return true;
3784 // -----------------------------------------------------------------------
3786 SfxItemPresentation SvxBrushItem::GetPresentation
3788 SfxItemPresentation ePres,
3789 SfxMapUnit /*eCoreUnit*/,
3790 SfxMapUnit /*ePresUnit*/,
3791 XubString& rText, const IntlWrapper *
3792 ) const
3794 switch ( ePres )
3796 case SFX_ITEM_PRESENTATION_NONE:
3797 rText.Erase();
3798 return ePres;
3800 case SFX_ITEM_PRESENTATION_NAMELESS:
3801 case SFX_ITEM_PRESENTATION_COMPLETE:
3803 if ( GPOS_NONE == eGraphicPos )
3805 rText = ::GetColorString( aColor );
3806 rText += cpDelim;
3807 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
3809 if ( aColor.GetTransparency() )
3810 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
3811 rText += EE_RESSTR(nId);
3813 else
3815 rText = EE_RESSTR(RID_SVXITEMS_GRAPHIC);
3818 return ePres;
3820 default: ;//prevent warning
3823 return SFX_ITEM_PRESENTATION_NONE;
3826 // -----------------------------------------------------------------------
3828 SvxBrushItem& SvxBrushItem::operator=( const SvxBrushItem& rItem )
3830 aColor = rItem.aColor;
3831 eGraphicPos = rItem.eGraphicPos;
3833 DELETEZ( pImpl->pGraphicObject );
3834 DELETEZ( pStrLink );
3835 DELETEZ( pStrFilter );
3837 if ( GPOS_NONE != eGraphicPos )
3839 if ( rItem.pStrLink )
3840 pStrLink = new String( *rItem.pStrLink );
3841 if ( rItem.pStrFilter )
3842 pStrFilter = new String( *rItem.pStrFilter );
3843 if ( rItem.pImpl->pGraphicObject )
3845 pImpl->pGraphicObject = new GraphicObject( *rItem.pImpl->pGraphicObject );
3848 pImpl->nGraphicTransparency = rItem.pImpl->nGraphicTransparency;
3849 return *this;
3852 // -----------------------------------------------------------------------
3854 int SvxBrushItem::operator==( const SfxPoolItem& rAttr ) const
3856 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
3858 SvxBrushItem& rCmp = (SvxBrushItem&)rAttr;
3859 sal_Bool bEqual = ( aColor == rCmp.aColor && eGraphicPos == rCmp.eGraphicPos &&
3860 pImpl->nGraphicTransparency == rCmp.pImpl->nGraphicTransparency);
3862 if ( bEqual )
3864 if ( GPOS_NONE != eGraphicPos )
3866 if ( !rCmp.pStrLink )
3867 bEqual = !pStrLink;
3868 else
3869 bEqual = pStrLink && ( *pStrLink == *rCmp.pStrLink );
3871 if ( bEqual )
3873 if ( !rCmp.pStrFilter )
3874 bEqual = !pStrFilter;
3875 else
3876 bEqual = pStrFilter && ( *pStrFilter == *rCmp.pStrFilter );
3879 if ( bEqual && !rCmp.pStrLink )
3881 if ( !rCmp.pImpl->pGraphicObject )
3882 bEqual = !pImpl->pGraphicObject;
3883 else
3884 bEqual = pImpl->pGraphicObject &&
3885 ( *pImpl->pGraphicObject == *rCmp.pImpl->pGraphicObject );
3890 return bEqual;
3893 // -----------------------------------------------------------------------
3895 SfxPoolItem* SvxBrushItem::Clone( SfxItemPool* ) const
3897 return new SvxBrushItem( *this );
3900 // -----------------------------------------------------------------------
3902 SfxPoolItem* SvxBrushItem::Create( SvStream& rStream, sal_uInt16 nVersion ) const
3904 return new SvxBrushItem( rStream, nVersion, Which() );
3907 // -----------------------------------------------------------------------
3909 SvStream& SvxBrushItem::Store( SvStream& rStream , sal_uInt16 /*nItemVersion*/ ) const
3911 rStream << (sal_Bool)sal_False;
3912 rStream << aColor;
3913 rStream << aColor;
3914 rStream << (sal_Int8)(aColor.GetTransparency() > 0 ? 0 : 1); //BRUSH_NULL : BRUSH_SOLID
3916 sal_uInt16 nDoLoad = 0;
3918 if ( pImpl->pGraphicObject && !pStrLink )
3919 nDoLoad |= LOAD_GRAPHIC;
3920 if ( pStrLink )
3921 nDoLoad |= LOAD_LINK;
3922 if ( pStrFilter )
3923 nDoLoad |= LOAD_FILTER;
3924 rStream << nDoLoad;
3926 if ( pImpl->pGraphicObject && !pStrLink )
3927 rStream << pImpl->pGraphicObject->GetGraphic();
3928 if ( pStrLink )
3930 OSL_FAIL("No BaseURL!");
3931 // TODO/MBA: how to get a BaseURL?!
3932 String aRel = INetURLObject::GetRelURL( String(), *pStrLink );
3933 // UNICODE: rStream << aRel;
3934 rStream.WriteUniOrByteString(aRel, rStream.GetStreamCharSet());
3936 if ( pStrFilter )
3938 // UNICODE: rStream << *pStrFilter;
3939 rStream.WriteUniOrByteString(*pStrFilter, rStream.GetStreamCharSet());
3941 rStream << (sal_Int8)eGraphicPos;
3942 return rStream;
3945 // -----------------------------------------------------------------------
3947 void SvxBrushItem::PurgeMedium() const
3949 DELETEZ( pImpl->pStream );
3952 // -----------------------------------------------------------------------
3953 const GraphicObject* SvxBrushItem::GetGraphicObject() const
3955 if ( bLoadAgain && pStrLink && !pImpl->pGraphicObject )
3956 // when graphics already loaded, use as a cache
3958 // only with "valid" names - empty names now allowed
3959 if( pStrLink->Len() )
3961 pImpl->pStream = utl::UcbStreamHelper::CreateStream( *pStrLink, STREAM_STD_READ );
3962 if( pImpl->pStream && !pImpl->pStream->GetError() )
3964 Graphic aGraphic;
3965 int nRes;
3966 pImpl->pStream->Seek( STREAM_SEEK_TO_BEGIN );
3967 nRes = GraphicFilter::GetGraphicFilter().
3968 ImportGraphic( aGraphic, *pStrLink, *pImpl->pStream,
3969 GRFILTER_FORMAT_DONTKNOW, NULL, GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG );
3971 if( nRes != GRFILTER_OK )
3973 const_cast < SvxBrushItem*> (this)->bLoadAgain = sal_False;
3975 else
3977 pImpl->pGraphicObject = new GraphicObject;
3978 pImpl->pGraphicObject->SetGraphic( aGraphic );
3979 const_cast < SvxBrushItem*> (this)->ApplyGraphicTransparency_Impl();
3982 else
3984 const_cast < SvxBrushItem*> (this)->bLoadAgain = sal_False;
3989 return pImpl->pGraphicObject;
3992 // -----------------------------------------------------------------------
3994 const Graphic* SvxBrushItem::GetGraphic() const
3996 const GraphicObject* pGrafObj = GetGraphicObject();
3997 return( pGrafObj ? &( pGrafObj->GetGraphic() ) : NULL );
4000 // -----------------------------------------------------------------------
4002 void SvxBrushItem::SetGraphicPos( SvxGraphicPosition eNew )
4004 eGraphicPos = eNew;
4006 if ( GPOS_NONE == eGraphicPos )
4008 DELETEZ( pImpl->pGraphicObject );
4009 DELETEZ( pStrLink );
4010 DELETEZ( pStrFilter );
4012 else
4014 if ( !pImpl->pGraphicObject && !pStrLink )
4016 pImpl->pGraphicObject = new GraphicObject; // Creating a dummy
4021 // -----------------------------------------------------------------------
4023 void SvxBrushItem::SetGraphic( const Graphic& rNew )
4025 if ( !pStrLink )
4027 if ( pImpl->pGraphicObject )
4028 pImpl->pGraphicObject->SetGraphic( rNew );
4029 else
4030 pImpl->pGraphicObject = new GraphicObject( rNew );
4032 ApplyGraphicTransparency_Impl();
4034 if ( GPOS_NONE == eGraphicPos )
4035 eGraphicPos = GPOS_MM; // None would be brush, then Default: middle
4037 else
4039 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
4043 // -----------------------------------------------------------------------
4045 void SvxBrushItem::SetGraphicObject( const GraphicObject& rNewObj )
4047 if ( !pStrLink )
4049 if ( pImpl->pGraphicObject )
4050 *pImpl->pGraphicObject = rNewObj;
4051 else
4052 pImpl->pGraphicObject = new GraphicObject( rNewObj );
4054 ApplyGraphicTransparency_Impl();
4056 if ( GPOS_NONE == eGraphicPos )
4057 eGraphicPos = GPOS_MM; // None would be brush, then Default: middle
4059 else
4061 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
4065 // -----------------------------------------------------------------------
4067 void SvxBrushItem::SetGraphicLink( const String& rNew )
4069 if ( !rNew.Len() )
4070 DELETEZ( pStrLink );
4071 else
4073 if ( pStrLink )
4074 *pStrLink = rNew;
4075 else
4076 pStrLink = new String( rNew );
4078 DELETEZ( pImpl->pGraphicObject );
4082 // -----------------------------------------------------------------------
4084 void SvxBrushItem::SetGraphicFilter( const String& rNew )
4086 if ( !rNew.Len() )
4087 DELETEZ( pStrFilter );
4088 else
4090 if ( pStrFilter )
4091 *pStrFilter = rNew;
4092 else
4093 pStrFilter = new String( rNew );
4097 //static
4098 SvxGraphicPosition SvxBrushItem::WallpaperStyle2GraphicPos( WallpaperStyle eStyle )
4100 SvxGraphicPosition eResult;
4101 // The switch is not the fastest, but the safest
4102 switch( eStyle )
4104 case WALLPAPER_NULL: eResult = GPOS_NONE; break;
4105 case WALLPAPER_TILE: eResult = GPOS_TILED; break;
4106 case WALLPAPER_CENTER: eResult = GPOS_MM; break;
4107 case WALLPAPER_SCALE: eResult = GPOS_AREA; break;
4108 case WALLPAPER_TOPLEFT: eResult = GPOS_LT; break;
4109 case WALLPAPER_TOP: eResult = GPOS_MT; break;
4110 case WALLPAPER_TOPRIGHT: eResult = GPOS_RT; break;
4111 case WALLPAPER_LEFT: eResult = GPOS_LM; break;
4112 case WALLPAPER_RIGHT: eResult = GPOS_RM; break;
4113 case WALLPAPER_BOTTOMLEFT: eResult = GPOS_LB; break;
4114 case WALLPAPER_BOTTOM: eResult = GPOS_MB; break;
4115 case WALLPAPER_BOTTOMRIGHT: eResult = GPOS_RB; break;
4116 default: eResult = GPOS_NONE;
4118 return eResult;
4121 //static
4122 WallpaperStyle SvxBrushItem::GraphicPos2WallpaperStyle( SvxGraphicPosition ePos )
4124 WallpaperStyle eResult;
4125 switch( ePos )
4127 case GPOS_NONE: eResult = WALLPAPER_NULL; break;
4128 case GPOS_TILED: eResult = WALLPAPER_TILE; break;
4129 case GPOS_MM: eResult = WALLPAPER_CENTER; break;
4130 case GPOS_AREA: eResult = WALLPAPER_SCALE; break;
4131 case GPOS_LT: eResult = WALLPAPER_TOPLEFT; break;
4132 case GPOS_MT: eResult = WALLPAPER_TOP; break;
4133 case GPOS_RT: eResult = WALLPAPER_TOPRIGHT; break;
4134 case GPOS_LM: eResult = WALLPAPER_LEFT; break;
4135 case GPOS_RM: eResult = WALLPAPER_RIGHT; break;
4136 case GPOS_LB: eResult = WALLPAPER_BOTTOMLEFT; break;
4137 case GPOS_MB: eResult = WALLPAPER_BOTTOM; break;
4138 case GPOS_RB: eResult = WALLPAPER_BOTTOMRIGHT; break;
4139 default: eResult = WALLPAPER_NULL;
4141 return eResult;
4144 SvxBrushItem::SvxBrushItem( const CntWallpaperItem& rItem, sal_uInt16 _nWhich ) :
4145 SfxPoolItem( _nWhich ),
4146 pImpl( new SvxBrushItem_Impl( 0 ) ),
4147 pStrLink(0),
4148 pStrFilter(0),
4149 bLoadAgain( sal_True )
4151 aColor = rItem.GetColor();
4153 if (!rItem.GetBitmapURL().isEmpty())
4155 pStrLink = new String( rItem.GetBitmapURL() );
4156 SetGraphicPos( WallpaperStyle2GraphicPos((WallpaperStyle)rItem.GetStyle() ) );
4160 #ifdef _MSC_VER
4161 #pragma optimize ( "", on )
4162 #endif
4164 void SvxBrushItem::ApplyGraphicTransparency_Impl()
4166 DBG_ASSERT(pImpl->pGraphicObject, "no GraphicObject available" );
4167 if(pImpl->pGraphicObject)
4169 GraphicAttr aAttr(pImpl->pGraphicObject->GetAttr());
4170 aAttr.SetTransparency(lcl_PercentToTransparency(
4171 pImpl->nGraphicTransparency));
4172 pImpl->pGraphicObject->SetAttr(aAttr);
4175 // class SvxFrameDirectionItem ----------------------------------------------
4177 SvxFrameDirectionItem::SvxFrameDirectionItem( SvxFrameDirection nValue ,
4178 sal_uInt16 _nWhich )
4179 : SfxUInt16Item( _nWhich, (sal_uInt16)nValue )
4183 SvxFrameDirectionItem::~SvxFrameDirectionItem()
4187 int SvxFrameDirectionItem::operator==( const SfxPoolItem& rCmp ) const
4189 DBG_ASSERT( SfxPoolItem::operator==(rCmp), "unequal types" );
4191 return GetValue() == ((SvxFrameDirectionItem&)rCmp).GetValue();
4194 SfxPoolItem* SvxFrameDirectionItem::Clone( SfxItemPool * ) const
4196 return new SvxFrameDirectionItem( *this );
4199 SfxPoolItem* SvxFrameDirectionItem::Create( SvStream & rStrm, sal_uInt16 /*nVer*/ ) const
4201 sal_uInt16 nValue;
4202 rStrm >> nValue;
4203 return new SvxFrameDirectionItem( (SvxFrameDirection)nValue, Which() );
4206 SvStream& SvxFrameDirectionItem::Store( SvStream & rStrm, sal_uInt16 /*nIVer*/ ) const
4208 sal_uInt16 nValue = GetValue();
4209 rStrm << nValue;
4210 return rStrm;
4213 sal_uInt16 SvxFrameDirectionItem::GetVersion( sal_uInt16 nFVer ) const
4215 return SOFFICE_FILEFORMAT_50 > nFVer ? USHRT_MAX : 0;
4218 SfxItemPresentation SvxFrameDirectionItem::GetPresentation(
4219 SfxItemPresentation ePres,
4220 SfxMapUnit /*eCoreUnit*/,
4221 SfxMapUnit /*ePresUnit*/,
4222 XubString& rText, const IntlWrapper *) const
4224 SfxItemPresentation eRet = ePres;
4225 switch( ePres )
4227 case SFX_ITEM_PRESENTATION_NONE:
4228 rText.Erase();
4229 break;
4231 case SFX_ITEM_PRESENTATION_NAMELESS:
4232 case SFX_ITEM_PRESENTATION_COMPLETE:
4233 rText = EE_RESSTR( RID_SVXITEMS_FRMDIR_BEGIN + GetValue() );
4234 break;
4236 default:
4237 eRet = SFX_ITEM_PRESENTATION_NONE;
4239 return eRet;
4242 bool SvxFrameDirectionItem::PutValue( const com::sun::star::uno::Any& rVal,
4243 sal_uInt8 )
4245 sal_Int16 nVal = sal_Int16();
4246 sal_Bool bRet = ( rVal >>= nVal );
4247 if( bRet )
4249 // translate WritingDirection2 constants into SvxFrameDirection
4250 switch( nVal )
4252 case text::WritingMode2::LR_TB:
4253 SetValue( FRMDIR_HORI_LEFT_TOP );
4254 break;
4255 case text::WritingMode2::RL_TB:
4256 SetValue( FRMDIR_HORI_RIGHT_TOP );
4257 break;
4258 case text::WritingMode2::TB_RL:
4259 SetValue( FRMDIR_VERT_TOP_RIGHT );
4260 break;
4261 case text::WritingMode2::TB_LR:
4262 SetValue( FRMDIR_VERT_TOP_LEFT );
4263 break;
4264 case text::WritingMode2::PAGE:
4265 SetValue( FRMDIR_ENVIRONMENT );
4266 break;
4267 default:
4268 bRet = false;
4269 break;
4273 return bRet;
4276 bool SvxFrameDirectionItem::QueryValue( com::sun::star::uno::Any& rVal,
4277 sal_uInt8 ) const
4279 // translate SvxFrameDirection into WritingDirection2
4280 sal_Int16 nVal;
4281 bool bRet = true;
4282 switch( GetValue() )
4284 case FRMDIR_HORI_LEFT_TOP:
4285 nVal = text::WritingMode2::LR_TB;
4286 break;
4287 case FRMDIR_HORI_RIGHT_TOP:
4288 nVal = text::WritingMode2::RL_TB;
4289 break;
4290 case FRMDIR_VERT_TOP_RIGHT:
4291 nVal = text::WritingMode2::TB_RL;
4292 break;
4293 case FRMDIR_VERT_TOP_LEFT:
4294 nVal = text::WritingMode2::TB_LR;
4295 break;
4296 case FRMDIR_ENVIRONMENT:
4297 nVal = text::WritingMode2::PAGE;
4298 break;
4299 default:
4300 OSL_FAIL("Unknown SvxFrameDirection value!");
4301 bRet = false;
4302 break;
4305 // return value + error state
4306 if( bRet )
4308 rVal <<= nVal;
4310 return bRet;
4313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */