Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / editeng / source / items / frmitems.cxx
blob35c04bbb7bc73b563c6231d003e66f0a771cbed4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/uno/Any.hxx>
21 #include <com/sun/star/drawing/LineStyle.hpp>
22 #include <com/sun/star/script/Converter.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/table/ShadowLocation.hpp>
25 #include <com/sun/star/table/TableBorder.hpp>
26 #include <com/sun/star/table/ShadowFormat.hpp>
27 #include <com/sun/star/table/CellRangeAddress.hpp>
28 #include <com/sun/star/table/CellContentType.hpp>
29 #include <com/sun/star/table/TableOrientation.hpp>
30 #include <com/sun/star/util/SortField.hpp>
31 #include <com/sun/star/util/SortFieldType.hpp>
32 #include <com/sun/star/table/BorderLine2.hpp>
33 #include <com/sun/star/table/BorderLineStyle.hpp>
34 #include <com/sun/star/table/CellOrientation.hpp>
35 #include <com/sun/star/table/CellAddress.hpp>
36 #include <com/sun/star/style/PageStyleLayout.hpp>
37 #include <com/sun/star/style/BreakType.hpp>
38 #include <com/sun/star/style/GraphicLocation.hpp>
39 #include <com/sun/star/awt/Rectangle.hpp>
40 #include <com/sun/star/awt/Selection.hpp>
41 #include <com/sun/star/awt/Size.hpp>
42 #include <com/sun/star/text/WritingMode2.hpp>
43 #include <com/sun/star/frame/status/UpperLowerMarginScale.hpp>
45 #include <unotools/ucbstreamhelper.hxx>
46 #include <limits.h>
47 #include <comphelper/processfactory.hxx>
48 #include <svtools/grfmgr.hxx>
49 #include <tools/urlobj.hxx>
50 #include <comphelper/types.hxx>
51 #include <svl/memberid.hrc>
52 #include <svtools/wallitem.hxx>
53 #include <svl/cntwall.hxx>
54 #include <svtools/borderhelper.hxx>
55 #include <rtl/ustring.hxx>
56 #include <rtl/ustrbuf.hxx>
57 #include <vcl/graphicfilter.hxx>
58 #include <editeng/editids.hrc>
59 #include <editeng/editrids.hrc>
60 #include <editeng/pbinitem.hxx>
61 #include <editeng/sizeitem.hxx>
62 #include <editeng/lrspitem.hxx>
63 #include <editeng/ulspitem.hxx>
64 #include <editeng/prntitem.hxx>
65 #include <editeng/opaqitem.hxx>
66 #include <editeng/protitem.hxx>
67 #include <editeng/shaditem.hxx>
68 #include <editeng/boxitem.hxx>
69 #include <editeng/brkitem.hxx>
70 #include <editeng/keepitem.hxx>
71 #include <editeng/bolnitem.hxx>
72 #include <editeng/brshitem.hxx>
73 #include <editeng/frmdiritem.hxx>
74 #include <editeng/itemtype.hxx>
75 #include <editeng/eerdll.hxx>
76 #include <editeng/unoprnms.hxx>
77 #include <editeng/memberids.hrc>
78 #include <editeng/editerr.hxx>
80 using namespace ::editeng;
81 using namespace ::rtl;
82 using namespace ::com::sun::star;
83 using namespace ::com::sun::star::table::BorderLineStyle;
86 // Conversion for UNO
87 #define TWIP_TO_MM100(TWIP) ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
88 #define MM100_TO_TWIP(MM100) ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
89 #define TWIP_TO_MM100_UNSIGNED(TWIP) ((((TWIP)*127L+36L)/72L))
90 #define MM100_TO_TWIP_UNSIGNED(MM100) ((((MM100)*72L+63L)/127L))
92 // STATIC DATA -----------------------------------------------------------
94 inline void SetValueProp( XubString& rStr, const sal_uInt16 nValue,
95 const sal_uInt16 nProp )
97 if( 100 == nProp )
98 rStr += String::CreateFromInt32( nValue );
99 else
100 ( rStr += String::CreateFromInt32( nProp )) += sal_Unicode('%');
103 inline void SetValueProp( XubString& rStr, const short nValue,
104 const sal_uInt16 nProp )
106 if( 100 == nProp )
107 rStr += String::CreateFromInt32( nValue );
108 else
109 ( rStr += String::CreateFromInt32( nProp )) += sal_Unicode('%');
112 // -----------------------------------------------------------------------
115 SvxBorderLine is not an SfxPoolItem, and has no Store/Create serialization/deserialization methods.
116 Since border line information needs to be serialized by the table autoformat code, these file-local
117 methods are defined to encapsulate the necessary serialization logic.
119 namespace
121 /// Item version for saved border lines. The old version saves the line without style information.
122 const int BORDER_LINE_OLD_VERSION = 0;
123 /// Item version for saved border lies. The new version includes line style.
124 const int BORDER_LINE_WITH_STYLE_VERSION = 1;
126 /// Store a border line to a stream.
127 SvStream& StoreBorderLine(SvStream &stream, const SvxBorderLine &l, sal_uInt16 version)
129 stream << l.GetColor()
130 << l.GetOutWidth()
131 << l.GetInWidth()
132 << l.GetDistance();
134 if (version >= BORDER_LINE_WITH_STYLE_VERSION)
135 stream << static_cast<sal_uInt16>(l.GetBorderLineStyle());
137 return stream;
140 /// Creates a border line from a stream.
141 SvxBorderLine CreateBorderLine(SvStream &stream, sal_uInt16 version)
143 sal_uInt16 nOutline, nInline, nDistance;
144 sal_uInt16 nStyle = NONE;
145 Color aColor;
146 stream >> aColor >> nOutline >> nInline >> nDistance;
148 if (version >= BORDER_LINE_WITH_STYLE_VERSION)
149 stream >> nStyle;
151 SvxBorderLine border(&aColor);
152 border.GuessLinesWidths(nStyle, nOutline, nInline, nDistance);
153 return border;
156 /// Retrieves a BORDER_LINE_* version from a BOX_BORDER_* version.
157 sal_uInt16 BorderLineVersionFromBoxVersion(sal_uInt16 boxVersion)
159 return (boxVersion >= BOX_BORDER_STYLE_VERSION)? BORDER_LINE_WITH_STYLE_VERSION : BORDER_LINE_OLD_VERSION;
163 TYPEINIT1_FACTORY(SvxPaperBinItem, SfxByteItem, new SvxPaperBinItem(0));
164 TYPEINIT1_FACTORY(SvxSizeItem, SfxPoolItem, new SvxSizeItem(0));
165 TYPEINIT1_FACTORY(SvxLRSpaceItem, SfxPoolItem, new SvxLRSpaceItem(0));
166 TYPEINIT1_FACTORY(SvxULSpaceItem, SfxPoolItem, new SvxULSpaceItem(0));
167 TYPEINIT1_FACTORY(SvxPrintItem, SfxBoolItem, new SvxPrintItem(0));
168 TYPEINIT1_FACTORY(SvxOpaqueItem, SfxBoolItem, new SvxOpaqueItem(0));
169 TYPEINIT1_FACTORY(SvxProtectItem, SfxPoolItem, new SvxProtectItem(0));
170 TYPEINIT1_FACTORY(SvxBrushItem, SfxPoolItem, new SvxBrushItem(0));
171 TYPEINIT1_FACTORY(SvxShadowItem, SfxPoolItem, new SvxShadowItem(0));
172 TYPEINIT1_FACTORY(SvxBoxItem, SfxPoolItem, new SvxBoxItem(0));
173 TYPEINIT1_FACTORY(SvxBoxInfoItem, SfxPoolItem, new SvxBoxInfoItem(0));
174 TYPEINIT1_FACTORY(SvxFmtBreakItem, SfxEnumItem, new SvxFmtBreakItem(SVX_BREAK_NONE, 0));
175 TYPEINIT1_FACTORY(SvxFmtKeepItem, SfxBoolItem, new SvxFmtKeepItem(sal_False, 0));
176 TYPEINIT1_FACTORY(SvxLineItem, SfxPoolItem, new SvxLineItem(0));
177 TYPEINIT1_FACTORY(SvxFrameDirectionItem, SfxUInt16Item, new SvxFrameDirectionItem(FRMDIR_HORI_LEFT_TOP, 0));
179 // class SvxPaperBinItem ------------------------------------------------
181 SfxPoolItem* SvxPaperBinItem::Clone( SfxItemPool* ) const
183 return new SvxPaperBinItem( *this );
186 // -----------------------------------------------------------------------
188 SvStream& SvxPaperBinItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
190 rStrm << GetValue();
191 return rStrm;
194 // -----------------------------------------------------------------------
196 SfxPoolItem* SvxPaperBinItem::Create( SvStream& rStrm, sal_uInt16 ) const
198 sal_Int8 nBin;
199 rStrm >> nBin;
200 return new SvxPaperBinItem( Which(), nBin );
203 // -----------------------------------------------------------------------
205 SfxItemPresentation SvxPaperBinItem::GetPresentation
207 SfxItemPresentation ePres,
208 SfxMapUnit /*eCoreUnit*/,
209 SfxMapUnit /*ePresUnit*/,
210 XubString& rText, const IntlWrapper *
211 ) const
213 switch ( ePres )
215 case SFX_ITEM_PRESENTATION_NONE:
216 rText.Erase();
217 return SFX_ITEM_PRESENTATION_NONE;
219 case SFX_ITEM_PRESENTATION_NAMELESS:
220 rText = String::CreateFromInt32( GetValue() );
221 return SFX_ITEM_PRESENTATION_NAMELESS;
223 case SFX_ITEM_PRESENTATION_COMPLETE:
225 sal_uInt8 nValue = GetValue();
227 if ( PAPERBIN_PRINTER_SETTINGS == nValue )
228 rText = EE_RESSTR(RID_SVXSTR_PAPERBIN_SETTINGS);
229 else
231 rText = EE_RESSTR(RID_SVXSTR_PAPERBIN);
232 rText += sal_Unicode(' ');
233 rText += String::CreateFromInt32( nValue );
235 return SFX_ITEM_PRESENTATION_COMPLETE;
237 //no break necessary
238 default: ;//prevent warning
241 return SFX_ITEM_PRESENTATION_NONE;
244 // class SvxSizeItem -----------------------------------------------------
246 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId, const Size& rSize ) :
248 SfxPoolItem( nId ),
250 aSize( rSize )
254 // -----------------------------------------------------------------------
255 bool SvxSizeItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
257 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
258 nMemberId &= ~CONVERT_TWIPS;
260 awt::Size aTmp(aSize.Width(), aSize.Height());
261 if( bConvert )
263 aTmp.Height = TWIP_TO_MM100(aTmp.Height);
264 aTmp.Width = TWIP_TO_MM100(aTmp.Width);
267 switch( nMemberId )
269 case MID_SIZE_SIZE: rVal <<= aTmp; break;
270 case MID_SIZE_WIDTH: rVal <<= aTmp.Width; break;
271 case MID_SIZE_HEIGHT: rVal <<= aTmp.Height; break;
272 default: OSL_FAIL("Wrong MemberId!"); return false;
275 return true;
277 // -----------------------------------------------------------------------
278 bool SvxSizeItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
280 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
281 nMemberId &= ~CONVERT_TWIPS;
283 switch( nMemberId )
285 case MID_SIZE_SIZE:
287 awt::Size aTmp;
288 if( rVal >>= aTmp )
290 if(bConvert)
292 aTmp.Height = MM100_TO_TWIP(aTmp.Height);
293 aTmp.Width = MM100_TO_TWIP(aTmp.Width);
295 aSize = Size( aTmp.Width, aTmp.Height );
297 else
299 return false;
302 break;
303 case MID_SIZE_WIDTH:
305 sal_Int32 nVal = 0;
306 if(!(rVal >>= nVal ))
307 return false;
309 aSize.Width() = bConvert ? MM100_TO_TWIP(nVal) : nVal;
311 break;
312 case MID_SIZE_HEIGHT:
314 sal_Int32 nVal = 0;
315 if(!(rVal >>= nVal))
316 return true;
318 aSize.Height() = bConvert ? MM100_TO_TWIP(nVal) : nVal;
320 break;
321 default: OSL_FAIL("Wrong MemberId!");
322 return false;
324 return true;
327 // -----------------------------------------------------------------------
329 SvxSizeItem::SvxSizeItem( const sal_uInt16 nId ) :
331 SfxPoolItem( nId )
335 // -----------------------------------------------------------------------
337 int SvxSizeItem::operator==( const SfxPoolItem& rAttr ) const
339 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
341 return ( aSize == ( (SvxSizeItem&)rAttr ).GetSize() );
344 // -----------------------------------------------------------------------
346 SfxPoolItem* SvxSizeItem::Clone( SfxItemPool* ) const
348 return new SvxSizeItem( *this );
351 //------------------------------------------------------------------------
353 SfxItemPresentation SvxSizeItem::GetPresentation
355 SfxItemPresentation ePres,
356 SfxMapUnit eCoreUnit,
357 SfxMapUnit ePresUnit,
358 XubString& rText, const IntlWrapper *pIntl
359 ) const
361 switch ( ePres )
363 case SFX_ITEM_PRESENTATION_NONE:
364 rText.Erase();
365 return SFX_ITEM_PRESENTATION_NONE;
367 case SFX_ITEM_PRESENTATION_NAMELESS:
368 rText = GetMetricText( aSize.Width(), eCoreUnit, ePresUnit, pIntl );
369 rText += cpDelim;
370 rText += GetMetricText( aSize.Height(), eCoreUnit, ePresUnit, pIntl );
371 return SFX_ITEM_PRESENTATION_NAMELESS;
373 case SFX_ITEM_PRESENTATION_COMPLETE:
374 rText = EE_RESSTR(RID_SVXITEMS_SIZE_WIDTH);
375 rText += GetMetricText( aSize.Width(), eCoreUnit, ePresUnit, pIntl );
376 rText += EE_RESSTR(GetMetricId(ePresUnit));
377 rText += cpDelim;
378 rText += EE_RESSTR(RID_SVXITEMS_SIZE_HEIGHT);
379 rText += GetMetricText( aSize.Height(), eCoreUnit, ePresUnit, pIntl );
380 rText += EE_RESSTR(GetMetricId(ePresUnit));
381 return SFX_ITEM_PRESENTATION_COMPLETE;
382 //no break necessary
383 default: ;//prevent warning
386 return SFX_ITEM_PRESENTATION_NONE;
389 // -----------------------------------------------------------------------
391 SvStream& SvxSizeItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
393 //#fdo39428 SvStream no longer supports operator<<(long)
394 rStrm << sal::static_int_cast<sal_Int32>(aSize.Width());
395 rStrm << sal::static_int_cast<sal_Int32>(aSize.Height());
396 return rStrm;
399 // -----------------------------------------------------------------------
401 bool SvxSizeItem::ScaleMetrics( long nMult, long nDiv )
403 aSize.Width() = Scale( aSize.Width(), nMult, nDiv );
404 aSize.Height() = Scale( aSize.Height(), nMult, nDiv );
405 return true;
408 // -----------------------------------------------------------------------
410 bool SvxSizeItem::HasMetrics() const
412 return true;
415 // -----------------------------------------------------------------------
417 SfxPoolItem* SvxSizeItem::Create( SvStream& rStrm, sal_uInt16 ) const
419 //#fdo39428 SvStream no longer supports operator>>(long&)
420 sal_Int32 nWidth(0), nHeight(0);
421 rStrm >> nWidth >> nHeight;
423 SvxSizeItem* pAttr = new SvxSizeItem( Which() );
424 pAttr->SetSize(Size(nWidth, nHeight));
426 return pAttr;
429 // class SvxLRSpaceItem --------------------------------------------------
431 SvxLRSpaceItem::SvxLRSpaceItem( const sal_uInt16 nId ) :
433 SfxPoolItem( nId ),
435 nFirstLineOfst ( 0 ),
436 nTxtLeft ( 0 ),
437 nLeftMargin ( 0 ),
438 nRightMargin ( 0 ),
439 nPropFirstLineOfst( 100 ),
440 nPropLeftMargin( 100 ),
441 nPropRightMargin( 100 ),
442 bAutoFirst ( 0 )
446 // -----------------------------------------------------------------------
448 SvxLRSpaceItem::SvxLRSpaceItem( const long nLeft, const long nRight,
449 const long nTLeft, const short nOfset,
450 const sal_uInt16 nId ) :
452 SfxPoolItem( nId ),
454 nFirstLineOfst ( nOfset ),
455 nTxtLeft ( nTLeft ),
456 nLeftMargin ( nLeft ),
457 nRightMargin ( nRight ),
458 nPropFirstLineOfst( 100 ),
459 nPropLeftMargin( 100 ),
460 nPropRightMargin( 100 ),
461 bAutoFirst ( 0 )
465 // -----------------------------------------------------------------------
466 bool SvxLRSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
468 bool bRet = true;
469 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
470 nMemberId &= ~CONVERT_TWIPS;
471 switch( nMemberId )
473 // now all signed
474 case MID_L_MARGIN:
475 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100(nLeftMargin) : nLeftMargin);
476 break;
478 case MID_TXT_LMARGIN :
479 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100(nTxtLeft) : nTxtLeft);
480 break;
481 case MID_R_MARGIN:
482 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100(nRightMargin) : nRightMargin);
483 break;
484 case MID_L_REL_MARGIN:
485 rVal <<= (sal_Int16)nPropLeftMargin;
486 break;
487 case MID_R_REL_MARGIN:
488 rVal <<= (sal_Int16)nPropRightMargin;
489 break;
491 case MID_FIRST_LINE_INDENT:
492 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100(nFirstLineOfst) : nFirstLineOfst);
493 break;
495 case MID_FIRST_LINE_REL_INDENT:
496 rVal <<= (sal_Int16)(nPropFirstLineOfst);
497 break;
499 case MID_FIRST_AUTO:
500 rVal = Bool2Any(IsAutoFirst());
501 break;
503 default:
504 bRet = false;
505 OSL_FAIL("unknown MemberId");
507 return bRet;
510 // -----------------------------------------------------------------------
511 bool SvxLRSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
513 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
514 nMemberId &= ~CONVERT_TWIPS;
515 sal_Int32 nVal = 0;
516 if( nMemberId != MID_FIRST_AUTO &&
517 nMemberId != MID_L_REL_MARGIN && nMemberId != MID_R_REL_MARGIN)
518 if(!(rVal >>= nVal))
519 return sal_False;
521 switch( nMemberId )
523 case MID_L_MARGIN:
524 SetLeft((sal_Int32)bConvert ? MM100_TO_TWIP(nVal) : nVal);
525 break;
527 case MID_TXT_LMARGIN :
528 SetTxtLeft((sal_Int32)bConvert ? MM100_TO_TWIP(nVal) : nVal);
529 break;
531 case MID_R_MARGIN:
532 SetRight((sal_Int32) bConvert ? MM100_TO_TWIP(nVal) : nVal);
533 break;
534 case MID_L_REL_MARGIN:
535 case MID_R_REL_MARGIN:
537 sal_Int32 nRel = 0;
538 if((rVal >>= nRel) && nRel >= 0 && nRel < USHRT_MAX)
540 if(MID_L_REL_MARGIN== nMemberId)
541 nPropLeftMargin = (sal_uInt16)nRel;
542 else
543 nPropRightMargin = (sal_uInt16)nRel;
545 else
546 return false;
548 break;
549 case MID_FIRST_LINE_INDENT :
550 SetTxtFirstLineOfst((short)(bConvert ? MM100_TO_TWIP(nVal) : nVal));
551 break;
553 case MID_FIRST_LINE_REL_INDENT:
554 SetPropTxtFirstLineOfst ( (sal_uInt16)nVal );
555 break;
557 case MID_FIRST_AUTO:
558 SetAutoFirst( Any2Bool(rVal) );
559 break;
561 default:
562 OSL_FAIL("unknown MemberId");
563 return false;
565 return true;
568 // -----------------------------------------------------------------------
570 // Adapt nLeftMargin and nTxtLeft.
572 void SvxLRSpaceItem::AdjustLeft()
574 if ( 0 > nFirstLineOfst )
575 nLeftMargin = nTxtLeft + nFirstLineOfst;
576 else
577 nLeftMargin = nTxtLeft;
580 // -----------------------------------------------------------------------
582 int SvxLRSpaceItem::operator==( const SfxPoolItem& rAttr ) const
584 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
586 return (
587 nLeftMargin == ((SvxLRSpaceItem&)rAttr).GetLeft() &&
588 nRightMargin == ((SvxLRSpaceItem&)rAttr).GetRight() &&
589 nFirstLineOfst == ((SvxLRSpaceItem&)rAttr).GetTxtFirstLineOfst() &&
590 nPropLeftMargin == ((SvxLRSpaceItem&)rAttr).GetPropLeft() &&
591 nPropRightMargin == ((SvxLRSpaceItem&)rAttr).GetPropRight() &&
592 nPropFirstLineOfst == ((SvxLRSpaceItem&)rAttr).GetPropTxtFirstLineOfst() &&
593 bAutoFirst == ((SvxLRSpaceItem&)rAttr).IsAutoFirst() );
596 // -----------------------------------------------------------------------
598 SfxPoolItem* SvxLRSpaceItem::Clone( SfxItemPool* ) const
600 return new SvxLRSpaceItem( *this );
603 //------------------------------------------------------------------------
605 SfxItemPresentation SvxLRSpaceItem::GetPresentation
607 SfxItemPresentation ePres,
608 SfxMapUnit eCoreUnit,
609 SfxMapUnit ePresUnit,
610 XubString& rText, const IntlWrapper* pIntl
611 ) const
613 switch ( ePres )
615 case SFX_ITEM_PRESENTATION_NONE:
616 rText.Erase();
617 return SFX_ITEM_PRESENTATION_NONE;
618 case SFX_ITEM_PRESENTATION_NAMELESS:
620 if ( 100 != nPropLeftMargin )
621 ( rText = String::CreateFromInt32( nPropLeftMargin )) += sal_Unicode('%');
622 else
623 rText = GetMetricText( (long)nLeftMargin,
624 eCoreUnit, ePresUnit, pIntl );
625 rText += cpDelim;
626 if ( 100 != nPropFirstLineOfst )
627 ( rText += String::CreateFromInt32( nPropFirstLineOfst )) += sal_Unicode('%');
628 else
629 rText += GetMetricText( (long)nFirstLineOfst,
630 eCoreUnit, ePresUnit, pIntl );
631 rText += cpDelim;
632 if ( 100 != nRightMargin )
633 ( rText += String::CreateFromInt32( nRightMargin )) += sal_Unicode('%');
634 else
635 rText += GetMetricText( (long)nRightMargin,
636 eCoreUnit, ePresUnit, pIntl );
637 return SFX_ITEM_PRESENTATION_NAMELESS;
639 case SFX_ITEM_PRESENTATION_COMPLETE:
641 rText = EE_RESSTR(RID_SVXITEMS_LRSPACE_LEFT);
642 if ( 100 != nPropLeftMargin )
643 ( rText += String::CreateFromInt32( nPropLeftMargin )) += sal_Unicode('%');
644 else
646 rText += GetMetricText( (long)nLeftMargin,
647 eCoreUnit, ePresUnit, pIntl );
648 rText += EE_RESSTR(GetMetricId(ePresUnit));
650 rText += cpDelim;
651 if ( 100 != nPropFirstLineOfst || nFirstLineOfst )
653 rText += EE_RESSTR(RID_SVXITEMS_LRSPACE_FLINE);
654 if ( 100 != nPropFirstLineOfst )
655 ( rText += String::CreateFromInt32( nPropFirstLineOfst ))
656 += sal_Unicode('%');
657 else
659 rText += GetMetricText( (long)nFirstLineOfst,
660 eCoreUnit, ePresUnit, pIntl );
661 rText += EE_RESSTR(GetMetricId(ePresUnit));
663 rText += cpDelim;
665 rText += EE_RESSTR(RID_SVXITEMS_LRSPACE_RIGHT);
666 if ( 100 != nPropRightMargin )
667 ( rText += String::CreateFromInt32( nPropRightMargin )) += sal_Unicode('%');
668 else
670 rText += GetMetricText( (long)nRightMargin,
671 eCoreUnit, ePresUnit, pIntl );
672 rText += EE_RESSTR(GetMetricId(ePresUnit));
674 return SFX_ITEM_PRESENTATION_COMPLETE;
676 default: ;//prevent warning
678 return SFX_ITEM_PRESENTATION_NONE;
681 // -----------------------------------------------------------------------
683 // BulletFI: Before 501 in the Outliner the bullet was not on the position of
684 // the FI, so in older documents one must set FI to 0.
685 #define BULLETLR_MARKER 0x599401FE
687 SvStream& SvxLRSpaceItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
689 short nSaveFI = nFirstLineOfst;
690 ((SvxLRSpaceItem*)this)->SetTxtFirstLineOfst( 0 ); // nLeftMargin is manipulated together with this, see Create()
692 sal_uInt16 nMargin = 0;
693 if( nLeftMargin > 0 )
694 nMargin = sal_uInt16( nLeftMargin );
695 rStrm << nMargin;
696 rStrm << nPropLeftMargin;
697 if( nRightMargin > 0 )
698 nMargin = sal_uInt16( nRightMargin );
699 else
700 nMargin = 0;
701 rStrm << nMargin;
702 rStrm << nPropRightMargin;
703 rStrm << nFirstLineOfst;
704 rStrm << nPropFirstLineOfst;
705 if( nTxtLeft > 0 )
706 nMargin = sal_uInt16( nTxtLeft );
707 else
708 nMargin = 0;
709 rStrm << nMargin;
710 if( nItemVersion >= LRSPACE_AUTOFIRST_VERSION )
712 sal_Int8 nAutoFirst = bAutoFirst ? 1 : 0;
713 if( nItemVersion >= LRSPACE_NEGATIVE_VERSION &&
714 ( nLeftMargin < 0 || nRightMargin < 0 || nTxtLeft < 0 ) )
715 nAutoFirst |= 0x80;
716 rStrm << nAutoFirst;
718 // From 6.0 onwards, do not write Magic numbers...
719 DBG_ASSERT( rStrm.GetVersion() <= SOFFICE_FILEFORMAT_50, "Change File format SvxLRSpaceItem!" );
720 rStrm << (sal_uInt32) BULLETLR_MARKER;
721 rStrm << nSaveFI;
723 if( 0x80 & nAutoFirst )
725 rStrm << static_cast<sal_Int32>(nLeftMargin);
726 rStrm << static_cast<sal_Int32>(nRightMargin);
730 ((SvxLRSpaceItem*)this)->SetTxtFirstLineOfst( nSaveFI );
732 return rStrm;
735 // -----------------------------------------------------------------------
737 SfxPoolItem* SvxLRSpaceItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
739 sal_uInt16 left, prpleft, right, prpright, prpfirstline, txtleft;
740 short firstline;
741 sal_Int8 autofirst = 0;
743 if ( nVersion >= LRSPACE_AUTOFIRST_VERSION )
745 rStrm >> left >> prpleft >> right >> prpright >> firstline >>
746 prpfirstline >> txtleft >> autofirst;
748 sal_uInt32 nPos = rStrm.Tell();
749 sal_uInt32 nMarker;
750 rStrm >> nMarker;
751 if ( nMarker == BULLETLR_MARKER )
753 rStrm >> firstline;
754 if ( firstline < 0 )
755 left = left + static_cast<sal_uInt16>(firstline); // see below: txtleft = ...
757 else
758 rStrm.Seek( nPos );
760 else if ( nVersion == LRSPACE_TXTLEFT_VERSION )
762 rStrm >> left >> prpleft >> right >> prpright >> firstline >>
763 prpfirstline >> txtleft;
765 else if ( nVersion == LRSPACE_16_VERSION )
767 rStrm >> left >> prpleft >> right >> prpright >> firstline >>
768 prpfirstline;
770 else
772 sal_Int8 nL, nR, nFL;
773 rStrm >> left >> nL >> right >> nR >> firstline >> nFL;
774 prpleft = (sal_uInt16)nL;
775 prpright = (sal_uInt16)nR;
776 prpfirstline = (sal_uInt16)nFL;
779 txtleft = firstline >= 0 ? left : left - firstline;
780 SvxLRSpaceItem* pAttr = new SvxLRSpaceItem( Which() );
782 pAttr->nLeftMargin = left;
783 pAttr->nPropLeftMargin = prpleft;
784 pAttr->nRightMargin = right;
785 pAttr->nPropRightMargin = prpright;
786 pAttr->nFirstLineOfst = firstline;
787 pAttr->nPropFirstLineOfst = prpfirstline;
788 pAttr->nTxtLeft = txtleft;
789 pAttr->bAutoFirst = autofirst & 0x01;
790 if( nVersion >= LRSPACE_NEGATIVE_VERSION && ( autofirst & 0x80 ) )
792 sal_Int32 nMargin;
793 rStrm >> nMargin;
794 pAttr->nLeftMargin = nMargin;
795 pAttr->nTxtLeft = firstline >= 0 ? nMargin : nMargin - firstline;
796 rStrm >> nMargin;
797 pAttr->nRightMargin = nMargin;
799 return pAttr;
802 // -----------------------------------------------------------------------
804 sal_uInt16 SvxLRSpaceItem::GetVersion( sal_uInt16 nFileVersion ) const
806 return (nFileVersion == SOFFICE_FILEFORMAT_31)
807 ? LRSPACE_TXTLEFT_VERSION
808 : LRSPACE_NEGATIVE_VERSION;
811 // -----------------------------------------------------------------------
813 bool SvxLRSpaceItem::ScaleMetrics( long nMult, long nDiv )
815 nFirstLineOfst = (short)Scale( nFirstLineOfst, nMult, nDiv );
816 nTxtLeft = Scale( nTxtLeft, nMult, nDiv );
817 nLeftMargin = Scale( nLeftMargin, nMult, nDiv );
818 nRightMargin = Scale( nRightMargin, nMult, nDiv );
819 return true;
822 // -----------------------------------------------------------------------
824 bool SvxLRSpaceItem::HasMetrics() const
826 return true;
829 // class SvxULSpaceItem --------------------------------------------------
831 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nId )
832 : SfxPoolItem(nId)
833 , nUpper(0)
834 , nLower(0)
835 , bContext(false)
836 , nPropUpper(100)
837 , nPropLower(100)
841 // -----------------------------------------------------------------------
843 SvxULSpaceItem::SvxULSpaceItem( const sal_uInt16 nUp, const sal_uInt16 nLow,
844 const sal_uInt16 nId )
845 : SfxPoolItem(nId)
846 , nUpper(nUp)
847 , nLower(nLow)
848 , bContext(false)
849 , nPropUpper(100)
850 , nPropLower(100)
854 // -----------------------------------------------------------------------
855 bool SvxULSpaceItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
857 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
858 nMemberId &= ~CONVERT_TWIPS;
859 switch( nMemberId )
861 // now all signed
862 case 0:
864 ::com::sun::star::frame::status::UpperLowerMarginScale aUpperLowerMarginScale;
865 aUpperLowerMarginScale.Upper = (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nUpper) : nUpper);
866 aUpperLowerMarginScale.Lower = (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nLower) : nPropUpper);
867 aUpperLowerMarginScale.ScaleUpper = (sal_Int16)nPropUpper;
868 aUpperLowerMarginScale.ScaleLower = (sal_Int16)nPropLower;
869 rVal <<= aUpperLowerMarginScale;
870 break;
872 case MID_UP_MARGIN: rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nUpper) : nUpper); break;
873 case MID_LO_MARGIN: rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nLower) : nLower); break;
874 case MID_CTX_MARGIN: rVal <<= bContext; break;
875 case MID_UP_REL_MARGIN: rVal <<= (sal_Int16) nPropUpper; break;
876 case MID_LO_REL_MARGIN: rVal <<= (sal_Int16) nPropLower; break;
878 return true;
881 // -----------------------------------------------------------------------
882 bool SvxULSpaceItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
884 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
885 nMemberId &= ~CONVERT_TWIPS;
886 sal_Int32 nVal = 0;
887 sal_Bool bVal = 0;
888 switch( nMemberId )
890 case 0:
892 ::com::sun::star::frame::status::UpperLowerMarginScale aUpperLowerMarginScale;
893 if ( !(rVal >>= aUpperLowerMarginScale ))
894 return false;
896 SetUpper((sal_uInt16)(bConvert ? MM100_TO_TWIP( aUpperLowerMarginScale.Upper ) : aUpperLowerMarginScale.Upper));
897 SetLower((sal_uInt16)(bConvert ? MM100_TO_TWIP( aUpperLowerMarginScale.Lower ) : aUpperLowerMarginScale.Lower));
898 if( aUpperLowerMarginScale.ScaleUpper > 1 )
899 nPropUpper = aUpperLowerMarginScale.ScaleUpper;
900 if( aUpperLowerMarginScale.ScaleLower > 1 )
901 nPropUpper = aUpperLowerMarginScale.ScaleLower;
905 case MID_UP_MARGIN :
906 if(!(rVal >>= nVal) || nVal < 0)
907 return false;
908 SetUpper((sal_uInt16)(bConvert ? MM100_TO_TWIP(nVal) : nVal));
909 break;
910 case MID_LO_MARGIN :
911 if(!(rVal >>= nVal) || nVal < 0)
912 return false;
913 SetLower((sal_uInt16)(bConvert ? MM100_TO_TWIP(nVal) : nVal));
914 break;
915 case MID_CTX_MARGIN :
916 if (!(rVal >>= bVal))
917 return false;
918 SetContextValue(bVal);
919 break;
920 case MID_UP_REL_MARGIN:
921 case MID_LO_REL_MARGIN:
923 sal_Int32 nRel = 0;
924 if((rVal >>= nRel) && nRel > 1 )
926 if(MID_UP_REL_MARGIN == nMemberId)
927 nPropUpper = (sal_uInt16)nRel;
928 else
929 nPropLower = (sal_uInt16)nRel;
931 else
932 return false;
934 break;
936 default:
937 OSL_FAIL("unknown MemberId");
938 return false;
940 return true;
943 // -----------------------------------------------------------------------
945 int SvxULSpaceItem::operator==( const SfxPoolItem& rAttr ) const
947 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
949 return ( nUpper == ( (SvxULSpaceItem&)rAttr ).nUpper &&
950 nLower == ( (SvxULSpaceItem&)rAttr ).nLower &&
951 bContext == ( (SvxULSpaceItem&)rAttr ).bContext &&
952 nPropUpper == ( (SvxULSpaceItem&)rAttr ).nPropUpper &&
953 nPropLower == ( (SvxULSpaceItem&)rAttr ).nPropLower );
956 // -----------------------------------------------------------------------
958 SfxPoolItem* SvxULSpaceItem::Clone( SfxItemPool* ) const
960 return new SvxULSpaceItem( *this );
963 //------------------------------------------------------------------------
965 SfxItemPresentation SvxULSpaceItem::GetPresentation
967 SfxItemPresentation ePres,
968 SfxMapUnit eCoreUnit,
969 SfxMapUnit ePresUnit,
970 XubString& rText, const IntlWrapper *pIntl
971 ) const
973 switch ( ePres )
975 case SFX_ITEM_PRESENTATION_NONE:
976 rText.Erase();
977 return SFX_ITEM_PRESENTATION_NONE;
978 case SFX_ITEM_PRESENTATION_NAMELESS:
980 if ( 100 != nPropUpper )
981 ( rText = String::CreateFromInt32( nPropUpper )) += sal_Unicode('%');
982 else
983 rText = GetMetricText( (long)nUpper, eCoreUnit, ePresUnit, pIntl );
984 rText += cpDelim;
985 if ( 100 != nPropLower )
986 ( rText += String::CreateFromInt32( nPropLower )) += sal_Unicode('%');
987 else
988 rText += GetMetricText( (long)nLower, eCoreUnit, ePresUnit, pIntl );
989 return SFX_ITEM_PRESENTATION_NAMELESS;
991 case SFX_ITEM_PRESENTATION_COMPLETE:
993 rText = EE_RESSTR(RID_SVXITEMS_ULSPACE_UPPER);
994 if ( 100 != nPropUpper )
995 ( rText += String::CreateFromInt32( nPropUpper )) += sal_Unicode('%');
996 else
998 rText += GetMetricText( (long)nUpper, eCoreUnit, ePresUnit, pIntl );
999 rText += EE_RESSTR(GetMetricId(ePresUnit));
1001 rText += cpDelim;
1002 rText += EE_RESSTR(RID_SVXITEMS_ULSPACE_LOWER);
1003 if ( 100 != nPropLower )
1004 ( rText += String::CreateFromInt32( nPropLower )) += sal_Unicode('%');
1005 else
1007 rText += GetMetricText( (long)nLower, eCoreUnit, ePresUnit, pIntl );
1008 rText += EE_RESSTR(GetMetricId(ePresUnit));
1010 return SFX_ITEM_PRESENTATION_COMPLETE;
1012 default: ;//prevent warning
1014 return SFX_ITEM_PRESENTATION_NONE;
1017 // -----------------------------------------------------------------------
1019 SvStream& SvxULSpaceItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1021 rStrm << GetUpper()
1022 << GetPropUpper()
1023 << GetLower()
1024 << GetPropLower();
1025 return rStrm;
1028 // -----------------------------------------------------------------------
1030 SfxPoolItem* SvxULSpaceItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
1032 sal_uInt16 upper, lower, nPL = 0, nPU = 0;
1034 if ( nVersion == ULSPACE_16_VERSION )
1035 rStrm >> upper >> nPU >> lower >> nPL;
1036 else
1038 sal_Int8 nU, nL;
1039 rStrm >> upper >> nU >> lower >> nL;
1040 nPL = (sal_uInt16)nL;
1041 nPU = (sal_uInt16)nU;
1044 SvxULSpaceItem* pAttr = new SvxULSpaceItem( Which() );
1045 pAttr->SetUpperValue( upper );
1046 pAttr->SetLowerValue( lower );
1047 pAttr->SetPropUpper( nPU );
1048 pAttr->SetPropLower( nPL );
1049 return pAttr;
1052 // -----------------------------------------------------------------------
1054 sal_uInt16 SvxULSpaceItem::GetVersion( sal_uInt16 /*nFileVersion*/ ) const
1056 return ULSPACE_16_VERSION;
1059 // -----------------------------------------------------------------------
1061 bool SvxULSpaceItem::ScaleMetrics( long nMult, long nDiv )
1063 nUpper = (sal_uInt16)Scale( nUpper, nMult, nDiv );
1064 nLower = (sal_uInt16)Scale( nLower, nMult, nDiv );
1065 return true;
1068 // -----------------------------------------------------------------------
1070 bool SvxULSpaceItem::HasMetrics() const
1072 return true;
1075 // class SvxPrintItem ----------------------------------------------------
1077 SfxPoolItem* SvxPrintItem::Clone( SfxItemPool* ) const
1079 return new SvxPrintItem( *this );
1082 // -----------------------------------------------------------------------
1084 SvStream& SvxPrintItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1086 rStrm << (sal_Int8)GetValue();
1087 return rStrm;
1090 // -----------------------------------------------------------------------
1092 SfxPoolItem* SvxPrintItem::Create( SvStream& rStrm, sal_uInt16 ) const
1094 sal_Int8 bIsPrint;
1095 rStrm >> bIsPrint;
1096 return new SvxPrintItem( Which(), sal_Bool( bIsPrint != 0 ) );
1099 //------------------------------------------------------------------------
1101 SfxItemPresentation SvxPrintItem::GetPresentation
1103 SfxItemPresentation ePres,
1104 SfxMapUnit /*eCoreUnit*/,
1105 SfxMapUnit /*ePresUnit*/,
1106 XubString& rText, const IntlWrapper *
1107 ) const
1109 switch ( ePres )
1111 case SFX_ITEM_PRESENTATION_NONE:
1112 rText.Erase();
1113 return ePres;
1115 case SFX_ITEM_PRESENTATION_NAMELESS:
1116 case SFX_ITEM_PRESENTATION_COMPLETE:
1118 sal_uInt16 nId = RID_SVXITEMS_PRINT_FALSE;
1120 if ( GetValue() )
1121 nId = RID_SVXITEMS_PRINT_TRUE;
1122 rText = EE_RESSTR(nId);
1123 return ePres;
1125 default: ;//prevent warning
1127 return SFX_ITEM_PRESENTATION_NONE;
1130 // class SvxOpaqueItem ---------------------------------------------------
1132 SfxPoolItem* SvxOpaqueItem::Clone( SfxItemPool* ) const
1134 return new SvxOpaqueItem( *this );
1137 // -----------------------------------------------------------------------
1139 SvStream& SvxOpaqueItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1141 rStrm << (sal_Int8)GetValue();
1142 return rStrm;
1145 // -----------------------------------------------------------------------
1147 SfxPoolItem* SvxOpaqueItem::Create( SvStream& rStrm, sal_uInt16 ) const
1149 sal_Int8 bIsOpaque;
1150 rStrm >> bIsOpaque;
1151 return new SvxOpaqueItem( Which(), sal_Bool( bIsOpaque != 0 ) );
1154 //------------------------------------------------------------------------
1156 SfxItemPresentation SvxOpaqueItem::GetPresentation
1158 SfxItemPresentation ePres,
1159 SfxMapUnit /*eCoreUnit*/,
1160 SfxMapUnit /*ePresUnit*/,
1161 XubString& rText, const IntlWrapper *
1162 ) const
1164 switch ( ePres )
1166 case SFX_ITEM_PRESENTATION_NONE:
1167 rText.Erase();
1168 return ePres;
1170 case SFX_ITEM_PRESENTATION_NAMELESS:
1171 case SFX_ITEM_PRESENTATION_COMPLETE:
1173 sal_uInt16 nId = RID_SVXITEMS_OPAQUE_FALSE;
1175 if ( GetValue() )
1176 nId = RID_SVXITEMS_OPAQUE_TRUE;
1177 rText = EE_RESSTR(nId);
1178 return ePres;
1180 default: ;//prevent warning
1182 return SFX_ITEM_PRESENTATION_NONE;
1185 // class SvxProtectItem --------------------------------------------------
1187 int SvxProtectItem::operator==( const SfxPoolItem& rAttr ) const
1189 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1191 return ( bCntnt == ( (SvxProtectItem&)rAttr ).bCntnt &&
1192 bSize == ( (SvxProtectItem&)rAttr ).bSize &&
1193 bPos == ( (SvxProtectItem&)rAttr ).bPos );
1196 bool SvxProtectItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1198 nMemberId &= ~CONVERT_TWIPS;
1199 sal_Bool bValue;
1200 switch(nMemberId)
1202 case MID_PROTECT_CONTENT : bValue = bCntnt; break;
1203 case MID_PROTECT_SIZE : bValue = bSize; break;
1204 case MID_PROTECT_POSITION: bValue = bPos; break;
1205 default:
1206 OSL_FAIL("Wrong MemberId");
1207 return false;
1210 rVal = Bool2Any( bValue );
1211 return true;
1214 bool SvxProtectItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1216 nMemberId &= ~CONVERT_TWIPS;
1217 sal_Bool bVal( Any2Bool(rVal) );
1218 switch(nMemberId)
1220 case MID_PROTECT_CONTENT : bCntnt = bVal; break;
1221 case MID_PROTECT_SIZE : bSize = bVal; break;
1222 case MID_PROTECT_POSITION: bPos = bVal; break;
1223 default:
1224 OSL_FAIL("Wrong MemberId");
1225 return false;
1227 return true;
1230 // -----------------------------------------------------------------------
1232 SfxPoolItem* SvxProtectItem::Clone( SfxItemPool* ) const
1234 return new SvxProtectItem( *this );
1237 //------------------------------------------------------------------------
1239 SfxItemPresentation SvxProtectItem::GetPresentation
1241 SfxItemPresentation ePres,
1242 SfxMapUnit /*eCoreUnit*/,
1243 SfxMapUnit /*ePresUnit*/,
1244 XubString& rText, const IntlWrapper *
1245 ) const
1247 switch ( ePres )
1249 case SFX_ITEM_PRESENTATION_NONE:
1250 rText.Erase();
1251 return ePres;
1253 case SFX_ITEM_PRESENTATION_NAMELESS:
1254 case SFX_ITEM_PRESENTATION_COMPLETE:
1256 sal_uInt16 nId = RID_SVXITEMS_PROT_CONTENT_FALSE;
1258 if ( bCntnt )
1259 nId = RID_SVXITEMS_PROT_CONTENT_TRUE;
1260 rText = EE_RESSTR(nId);
1261 rText += cpDelim;
1262 nId = RID_SVXITEMS_PROT_SIZE_FALSE;
1264 if ( bSize )
1265 nId = RID_SVXITEMS_PROT_SIZE_TRUE;
1266 rText += EE_RESSTR(nId);
1267 rText += cpDelim;
1268 nId = RID_SVXITEMS_PROT_POS_FALSE;
1270 if ( bPos )
1271 nId = RID_SVXITEMS_PROT_POS_TRUE;
1272 rText += EE_RESSTR(nId);
1273 return ePres;
1275 default: ;//prevent warning
1277 return SFX_ITEM_PRESENTATION_NONE;
1280 // -----------------------------------------------------------------------
1282 SvStream& SvxProtectItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1284 sal_Int8 cProt = 0;
1285 if( IsPosProtected() ) cProt |= 0x01;
1286 if( IsSizeProtected() ) cProt |= 0x02;
1287 if( IsCntntProtected() ) cProt |= 0x04;
1288 rStrm << (sal_Int8) cProt;
1289 return rStrm;
1292 // -----------------------------------------------------------------------
1294 SfxPoolItem* SvxProtectItem::Create( SvStream& rStrm, sal_uInt16 ) const
1296 sal_Int8 cFlags;
1297 rStrm >> cFlags;
1298 SvxProtectItem* pAttr = new SvxProtectItem( Which() );
1299 pAttr->SetPosProtect( sal_Bool( ( cFlags & 0x01 ) != 0 ) );
1300 pAttr->SetSizeProtect( sal_Bool( ( cFlags & 0x02 ) != 0 ) );
1301 pAttr->SetCntntProtect( sal_Bool( ( cFlags & 0x04 ) != 0 ) );
1302 return pAttr;
1305 // class SvxShadowItem ---------------------------------------------------
1307 SvxShadowItem::SvxShadowItem( const sal_uInt16 nId,
1308 const Color *pColor, const sal_uInt16 nW,
1309 const SvxShadowLocation eLoc ) :
1310 SfxEnumItemInterface( nId ),
1311 aShadowColor(COL_GRAY),
1312 nWidth ( nW ),
1313 eLocation ( eLoc )
1315 if ( pColor )
1316 aShadowColor = *pColor;
1319 // -----------------------------------------------------------------------
1320 bool SvxShadowItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1322 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1323 nMemberId &= ~CONVERT_TWIPS;
1325 table::ShadowFormat aShadow;
1326 table::ShadowLocation eSet = table::ShadowLocation_NONE;
1327 switch( eLocation )
1329 case SVX_SHADOW_TOPLEFT : eSet = table::ShadowLocation_TOP_LEFT ; break;
1330 case SVX_SHADOW_TOPRIGHT : eSet = table::ShadowLocation_TOP_RIGHT ; break;
1331 case SVX_SHADOW_BOTTOMLEFT : eSet = table::ShadowLocation_BOTTOM_LEFT ; break;
1332 case SVX_SHADOW_BOTTOMRIGHT: eSet = table::ShadowLocation_BOTTOM_RIGHT; break;
1333 default: ;//prevent warning
1335 aShadow.Location = eSet;
1336 aShadow.ShadowWidth = bConvert ? TWIP_TO_MM100_UNSIGNED(nWidth) : nWidth;
1337 aShadow.IsTransparent = aShadowColor.GetTransparency() > 0;
1338 aShadow.Color = aShadowColor.GetRGBColor();
1340 switch ( nMemberId )
1342 case MID_LOCATION: rVal <<= aShadow.Location; break;
1343 case MID_WIDTH: rVal <<= aShadow.ShadowWidth; break;
1344 case MID_TRANSPARENT: rVal <<= aShadow.IsTransparent; break;
1345 case MID_BG_COLOR: rVal <<= aShadow.Color; break;
1346 case 0: rVal <<= aShadow; break;
1347 default: OSL_FAIL("Wrong MemberId!"); return false;
1350 return true;
1352 // -----------------------------------------------------------------------
1353 bool SvxShadowItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1355 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1356 nMemberId &= ~CONVERT_TWIPS;
1358 table::ShadowFormat aShadow;
1359 uno::Any aAny;
1360 bool bRet = QueryValue( aAny, bConvert ? CONVERT_TWIPS : 0 ) && ( aAny >>= aShadow );
1361 switch ( nMemberId )
1363 case MID_LOCATION:
1365 bRet = (rVal >>= aShadow.Location);
1366 if ( !bRet )
1368 sal_Int16 nVal = 0;
1369 bRet = (rVal >>= nVal);
1370 aShadow.Location = (table::ShadowLocation) nVal;
1373 break;
1376 case MID_WIDTH: rVal >>= aShadow.ShadowWidth; break;
1377 case MID_TRANSPARENT: rVal >>= aShadow.IsTransparent; break;
1378 case MID_BG_COLOR: rVal >>= aShadow.Color; break;
1379 case 0: rVal >>= aShadow; break;
1380 default: OSL_FAIL("Wrong MemberId!"); return sal_False;
1383 if ( bRet )
1385 // SvxShadowLocation eSet = SVX_SHADOW_NONE;
1386 switch( aShadow.Location )
1388 case table::ShadowLocation_TOP_LEFT : eLocation = SVX_SHADOW_TOPLEFT; break;
1389 case table::ShadowLocation_TOP_RIGHT : eLocation = SVX_SHADOW_TOPRIGHT; break;
1390 case table::ShadowLocation_BOTTOM_LEFT : eLocation = SVX_SHADOW_BOTTOMLEFT ; break;
1391 case table::ShadowLocation_BOTTOM_RIGHT: eLocation = SVX_SHADOW_BOTTOMRIGHT; break;
1392 default: ;//prevent warning
1395 nWidth = bConvert ? MM100_TO_TWIP(aShadow.ShadowWidth) : aShadow.ShadowWidth;
1396 Color aSet(aShadow.Color);
1397 aSet.SetTransparency(aShadow.IsTransparent ? 0xff : 0);
1398 aShadowColor = aSet;
1401 return bRet;
1404 // -----------------------------------------------------------------------
1406 int SvxShadowItem::operator==( const SfxPoolItem& rAttr ) const
1408 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1410 return ( ( aShadowColor == ( (SvxShadowItem&)rAttr ).aShadowColor ) &&
1411 ( nWidth == ( (SvxShadowItem&)rAttr ).GetWidth() ) &&
1412 ( eLocation == ( (SvxShadowItem&)rAttr ).GetLocation() ) );
1415 // -----------------------------------------------------------------------
1417 SfxPoolItem* SvxShadowItem::Clone( SfxItemPool* ) const
1419 return new SvxShadowItem( *this );
1422 // -----------------------------------------------------------------------
1424 sal_uInt16 SvxShadowItem::CalcShadowSpace( sal_uInt16 nShadow ) const
1426 sal_uInt16 nSpace = 0;
1428 switch ( nShadow )
1430 case SHADOW_TOP:
1431 if ( eLocation == SVX_SHADOW_TOPLEFT ||
1432 eLocation == SVX_SHADOW_TOPRIGHT )
1433 nSpace = nWidth;
1434 break;
1436 case SHADOW_BOTTOM:
1437 if ( eLocation == SVX_SHADOW_BOTTOMLEFT ||
1438 eLocation == SVX_SHADOW_BOTTOMRIGHT )
1439 nSpace = nWidth;
1440 break;
1442 case SHADOW_LEFT:
1443 if ( eLocation == SVX_SHADOW_TOPLEFT ||
1444 eLocation == SVX_SHADOW_BOTTOMLEFT )
1445 nSpace = nWidth;
1446 break;
1448 case SHADOW_RIGHT:
1449 if ( eLocation == SVX_SHADOW_TOPRIGHT ||
1450 eLocation == SVX_SHADOW_BOTTOMRIGHT )
1451 nSpace = nWidth;
1452 break;
1454 default:
1455 OSL_FAIL( "wrong shadow" );
1457 return nSpace;
1460 //------------------------------------------------------------------------
1462 SfxItemPresentation SvxShadowItem::GetPresentation
1464 SfxItemPresentation ePres,
1465 SfxMapUnit eCoreUnit,
1466 SfxMapUnit ePresUnit,
1467 XubString& rText, const IntlWrapper *pIntl
1468 ) const
1470 switch ( ePres )
1472 case SFX_ITEM_PRESENTATION_NONE:
1473 rText.Erase();
1474 return ePres;
1476 case SFX_ITEM_PRESENTATION_NAMELESS:
1478 rText = ::GetColorString( aShadowColor );
1479 rText += cpDelim;
1480 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
1482 if ( aShadowColor.GetTransparency() )
1483 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
1484 rText += EE_RESSTR(nId);
1485 rText += cpDelim;
1486 rText += GetMetricText( (long)nWidth, eCoreUnit, ePresUnit, pIntl );
1487 rText += cpDelim;
1488 rText += EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + eLocation);
1489 return ePres;
1491 case SFX_ITEM_PRESENTATION_COMPLETE:
1493 rText = EE_RESSTR(RID_SVXITEMS_SHADOW_COMPLETE);
1494 rText += ::GetColorString( aShadowColor );
1495 rText += cpDelim;
1497 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
1498 if ( aShadowColor.GetTransparency() )
1499 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
1500 rText += EE_RESSTR(nId);
1501 rText += cpDelim;
1502 rText += GetMetricText( (long)nWidth, eCoreUnit, ePresUnit, pIntl );
1503 rText += EE_RESSTR(GetMetricId(ePresUnit));
1504 rText += cpDelim;
1505 rText += EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + eLocation);
1506 return ePres;
1508 default: ;//prevent warning
1510 return SFX_ITEM_PRESENTATION_NONE;
1513 // -----------------------------------------------------------------------
1515 SvStream& SvxShadowItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
1517 rStrm << (sal_Int8) GetLocation()
1518 << (sal_uInt16) GetWidth()
1519 << (sal_Bool)(aShadowColor.GetTransparency() > 0)
1520 << GetColor()
1521 << GetColor()
1522 << (sal_Int8)(aShadowColor.GetTransparency() > 0 ? 0 : 1); //BRUSH_NULL : BRUSH_SOLID
1523 return rStrm;
1526 // -----------------------------------------------------------------------
1528 bool SvxShadowItem::ScaleMetrics( long nMult, long nDiv )
1530 nWidth = (sal_uInt16)Scale( nWidth, nMult, nDiv );
1531 return true;
1534 // -----------------------------------------------------------------------
1536 bool SvxShadowItem::HasMetrics() const
1538 return true;
1541 // -----------------------------------------------------------------------
1543 SfxPoolItem* SvxShadowItem::Create( SvStream& rStrm, sal_uInt16 ) const
1545 sal_Int8 cLoc;
1546 sal_uInt16 _nWidth;
1547 sal_Bool bTrans;
1548 Color aColor;
1549 Color aFillColor;
1550 sal_Int8 nStyle;
1551 rStrm >> cLoc >> _nWidth
1552 >> bTrans >> aColor >> aFillColor >> nStyle;
1553 aColor.SetTransparency(bTrans ? 0xff : 0);
1554 return new SvxShadowItem( Which(), &aColor, _nWidth, (SvxShadowLocation)cLoc );
1557 // -----------------------------------------------------------------------
1559 sal_uInt16 SvxShadowItem::GetValueCount() const
1561 return SVX_SHADOW_END; // SVX_SHADOW_BOTTOMRIGHT + 1
1564 // -----------------------------------------------------------------------
1566 rtl::OUString SvxShadowItem::GetValueTextByPos( sal_uInt16 nPos ) const
1568 DBG_ASSERT( nPos < SVX_SHADOW_END, "enum overflow!" );
1569 return EE_RESSTR(RID_SVXITEMS_SHADOW_BEGIN + nPos );
1572 // -----------------------------------------------------------------------
1574 sal_uInt16 SvxShadowItem::GetEnumValue() const
1576 return (sal_uInt16)GetLocation();
1579 // -----------------------------------------------------------------------
1581 void SvxShadowItem::SetEnumValue( sal_uInt16 nVal )
1583 SetLocation( (const SvxShadowLocation)nVal );
1586 // class SvxBoxItem ------------------------------------------------------
1588 SvxBoxItem::SvxBoxItem( const SvxBoxItem& rCpy ) :
1590 SfxPoolItem ( rCpy ),
1591 nTopDist ( rCpy.nTopDist ),
1592 nBottomDist ( rCpy.nBottomDist ),
1593 nLeftDist ( rCpy.nLeftDist ),
1594 nRightDist ( rCpy.nRightDist )
1597 pTop = rCpy.GetTop() ? new SvxBorderLine( *rCpy.GetTop() ) : 0;
1598 pBottom = rCpy.GetBottom() ? new SvxBorderLine( *rCpy.GetBottom() ) : 0;
1599 pLeft = rCpy.GetLeft() ? new SvxBorderLine( *rCpy.GetLeft() ) : 0;
1600 pRight = rCpy.GetRight() ? new SvxBorderLine( *rCpy.GetRight() ) : 0;
1603 // -----------------------------------------------------------------------
1605 SvxBoxItem::SvxBoxItem( const sal_uInt16 nId ) :
1606 SfxPoolItem( nId ),
1608 pTop ( 0 ),
1609 pBottom ( 0 ),
1610 pLeft ( 0 ),
1611 pRight ( 0 ),
1612 nTopDist ( 0 ),
1613 nBottomDist ( 0 ),
1614 nLeftDist ( 0 ),
1615 nRightDist ( 0 )
1620 // -----------------------------------------------------------------------
1622 SvxBoxItem::~SvxBoxItem()
1624 delete pTop;
1625 delete pBottom;
1626 delete pLeft;
1627 delete pRight;
1630 // -----------------------------------------------------------------------
1632 SvxBoxItem& SvxBoxItem::operator=( const SvxBoxItem& rBox )
1634 nTopDist = rBox.nTopDist;
1635 nBottomDist = rBox.nBottomDist;
1636 nLeftDist = rBox.nLeftDist;
1637 nRightDist = rBox.nRightDist;
1638 SetLine( rBox.GetTop(), BOX_LINE_TOP );
1639 SetLine( rBox.GetBottom(), BOX_LINE_BOTTOM );
1640 SetLine( rBox.GetLeft(), BOX_LINE_LEFT );
1641 SetLine( rBox.GetRight(), BOX_LINE_RIGHT );
1642 return *this;
1645 // -----------------------------------------------------------------------
1647 inline sal_Bool CmpBrdLn( const SvxBorderLine* pBrd1, const SvxBorderLine* pBrd2 )
1649 sal_Bool bRet;
1650 if( 0 != pBrd1 ? 0 == pBrd2 : 0 != pBrd2 )
1651 bRet = sal_False;
1652 else
1653 if( !pBrd1 )
1654 bRet = sal_True;
1655 else
1656 bRet = (*pBrd1 == *pBrd2);
1657 return bRet;
1660 // -----------------------------------------------------------------------
1662 int SvxBoxItem::operator==( const SfxPoolItem& rAttr ) const
1664 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
1666 return (
1667 ( nTopDist == ( (SvxBoxItem&)rAttr ).nTopDist ) &&
1668 ( nBottomDist == ( (SvxBoxItem&)rAttr ).nBottomDist ) &&
1669 ( nLeftDist == ( (SvxBoxItem&)rAttr ).nLeftDist ) &&
1670 ( nRightDist == ( (SvxBoxItem&)rAttr ).nRightDist ) &&
1671 CmpBrdLn( pTop, ( (SvxBoxItem&)rAttr ).GetTop() ) &&
1672 CmpBrdLn( pBottom, ( (SvxBoxItem&)rAttr ).GetBottom() ) &&
1673 CmpBrdLn( pLeft, ( (SvxBoxItem&)rAttr ).GetLeft() ) &&
1674 CmpBrdLn( pRight, ( (SvxBoxItem&)rAttr ).GetRight() ) );
1677 // -----------------------------------------------------------------------
1678 table::BorderLine2 SvxBoxItem::SvxLineToLine(const SvxBorderLine* pLine, sal_Bool bConvert)
1680 table::BorderLine2 aLine;
1681 if(pLine)
1683 aLine.Color = pLine->GetColor().GetColor() ;
1684 aLine.InnerLineWidth = sal_uInt16( bConvert ? TWIP_TO_MM100_UNSIGNED(pLine->GetInWidth() ): pLine->GetInWidth() );
1685 aLine.OuterLineWidth = sal_uInt16( bConvert ? TWIP_TO_MM100_UNSIGNED(pLine->GetOutWidth()): pLine->GetOutWidth() );
1686 aLine.LineDistance = sal_uInt16( bConvert ? TWIP_TO_MM100_UNSIGNED(pLine->GetDistance()): pLine->GetDistance() );
1687 aLine.LineStyle = pLine->GetBorderLineStyle();
1688 aLine.LineWidth = sal_uInt32( bConvert ? TWIP_TO_MM100( pLine->GetWidth( ) ) : pLine->GetWidth( ) );
1690 else
1691 aLine.Color = aLine.InnerLineWidth = aLine.OuterLineWidth = aLine.LineDistance = 0;
1692 return aLine;
1694 // -----------------------------------------------------------------------
1695 bool SvxBoxItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
1697 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1698 table::BorderLine2 aRetLine;
1699 sal_uInt16 nDist = 0;
1700 sal_Bool bDistMember = sal_False;
1701 nMemberId &= ~CONVERT_TWIPS;
1702 switch(nMemberId)
1704 case 0:
1706 // 4 Borders and 5 distances
1707 uno::Sequence< uno::Any > aSeq( 9 );
1708 aSeq[0] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetLeft(), bConvert) );
1709 aSeq[1] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetRight(), bConvert) );
1710 aSeq[2] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetBottom(), bConvert) );
1711 aSeq[3] = uno::makeAny( SvxBoxItem::SvxLineToLine(GetTop(), bConvert) );
1712 aSeq[4] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( GetDistance()) : GetDistance()));
1713 aSeq[5] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( nTopDist ) : nTopDist ));
1714 aSeq[6] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( nBottomDist ) : nBottomDist ));
1715 aSeq[7] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( nLeftDist ) : nLeftDist ));
1716 aSeq[8] <<= uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED( nRightDist ) : nRightDist ));
1717 rVal = uno::makeAny( aSeq );
1718 return sal_True;
1720 case MID_LEFT_BORDER:
1721 case LEFT_BORDER:
1722 aRetLine = SvxBoxItem::SvxLineToLine(GetLeft(), bConvert);
1723 break;
1724 case MID_RIGHT_BORDER:
1725 case RIGHT_BORDER:
1726 aRetLine = SvxBoxItem::SvxLineToLine(GetRight(), bConvert);
1727 break;
1728 case MID_BOTTOM_BORDER:
1729 case BOTTOM_BORDER:
1730 aRetLine = SvxBoxItem::SvxLineToLine(GetBottom(), bConvert);
1731 break;
1732 case MID_TOP_BORDER:
1733 case TOP_BORDER:
1734 aRetLine = SvxBoxItem::SvxLineToLine(GetTop(), bConvert);
1735 break;
1736 case BORDER_DISTANCE:
1737 nDist = GetDistance();
1738 bDistMember = sal_True;
1739 break;
1740 case TOP_BORDER_DISTANCE:
1741 nDist = nTopDist;
1742 bDistMember = sal_True;
1743 break;
1744 case BOTTOM_BORDER_DISTANCE:
1745 nDist = nBottomDist;
1746 bDistMember = sal_True;
1747 break;
1748 case LEFT_BORDER_DISTANCE:
1749 nDist = nLeftDist;
1750 bDistMember = sal_True;
1751 break;
1752 case RIGHT_BORDER_DISTANCE:
1753 nDist = nRightDist;
1754 bDistMember = sal_True;
1755 break;
1758 if( bDistMember )
1759 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(nDist) : nDist);
1760 else
1761 rVal <<= aRetLine;
1763 return true;
1766 namespace
1769 sal_Bool
1770 lcl_lineToSvxLine(const table::BorderLine& rLine, SvxBorderLine& rSvxLine, sal_Bool bConvert, sal_Bool bGuessWidth)
1772 rSvxLine.SetColor( Color(rLine.Color));
1773 if ( bGuessWidth )
1775 rSvxLine.GuessLinesWidths( rSvxLine.GetBorderLineStyle(),
1776 sal_uInt16( bConvert ? MM100_TO_TWIP(rLine.OuterLineWidth) : rLine.OuterLineWidth ),
1777 sal_uInt16( bConvert ? MM100_TO_TWIP(rLine.InnerLineWidth) : rLine.InnerLineWidth ),
1778 sal_uInt16( bConvert ? MM100_TO_TWIP(rLine.LineDistance ) : rLine.LineDistance ));
1781 sal_Bool bRet = !rSvxLine.isEmpty();
1782 return bRet;
1787 // -----------------------------------------------------------------------
1788 sal_Bool SvxBoxItem::LineToSvxLine(const ::com::sun::star::table::BorderLine& rLine, SvxBorderLine& rSvxLine, sal_Bool bConvert)
1790 return lcl_lineToSvxLine(rLine, rSvxLine, bConvert, sal_True);
1793 sal_Bool
1794 SvxBoxItem::LineToSvxLine(const ::com::sun::star::table::BorderLine2& rLine, SvxBorderLine& rSvxLine, sal_Bool bConvert)
1796 SvxBorderStyle const nStyle =
1797 (rLine.LineStyle < 0 || BORDER_LINE_STYLE_MAX < rLine.LineStyle)
1798 ? SOLID // default
1799 : rLine.LineStyle;
1801 rSvxLine.SetBorderLineStyle( nStyle );
1803 sal_Bool bGuessWidth = sal_True;
1804 if ( rLine.LineWidth )
1806 rSvxLine.SetWidth( bConvert? MM100_TO_TWIP_UNSIGNED( rLine.LineWidth ) : rLine.LineWidth );
1807 // fdo#46112: double does not necessarily mean symmetric
1808 // for backwards compatibility
1809 bGuessWidth = (DOUBLE == nStyle) &&
1810 (rLine.InnerLineWidth > 0) && (rLine.OuterLineWidth > 0);
1813 return lcl_lineToSvxLine(rLine, rSvxLine, bConvert, bGuessWidth);
1816 // -----------------------------------------------------------------------
1818 namespace
1821 bool
1822 lcl_extractBorderLine(const uno::Any& rAny, table::BorderLine2& rLine)
1824 if (rAny >>= rLine)
1825 return true;
1827 table::BorderLine aBorderLine;
1828 if (rAny >>= aBorderLine)
1830 rLine.Color = aBorderLine.Color;
1831 rLine.InnerLineWidth = aBorderLine.InnerLineWidth;
1832 rLine.OuterLineWidth = aBorderLine.OuterLineWidth;
1833 rLine.LineDistance = aBorderLine.LineDistance;
1834 rLine.LineStyle = table::BorderLineStyle::SOLID;
1835 return true;
1838 return false;
1841 template<typename Item>
1842 bool
1843 lcl_setLine(const uno::Any& rAny, Item& rItem, sal_uInt16 nLine, const bool bConvert)
1845 bool bDone = false;
1846 table::BorderLine2 aBorderLine;
1847 if (lcl_extractBorderLine(rAny, aBorderLine))
1849 SvxBorderLine aLine;
1850 bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
1851 rItem.SetLine( bSet ? &aLine : NULL, nLine);
1852 bDone = true;
1854 return bDone;
1859 bool SvxBoxItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
1861 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
1862 sal_uInt16 nLine = BOX_LINE_TOP;
1863 sal_Bool bDistMember = sal_False;
1864 nMemberId &= ~CONVERT_TWIPS;
1865 switch(nMemberId)
1867 case 0:
1869 uno::Sequence< uno::Any > aSeq;
1870 if (( rVal >>= aSeq ) && ( aSeq.getLength() == 9 ))
1872 // 4 Borders and 5 distances
1873 const sal_uInt16 aBorders[] = { BOX_LINE_LEFT, BOX_LINE_RIGHT, BOX_LINE_BOTTOM, BOX_LINE_TOP };
1874 for (int n(0); n != SAL_N_ELEMENTS(aBorders); ++n)
1876 if (!lcl_setLine(aSeq[n], *this, aBorders[n], bConvert))
1877 return sal_False;
1880 // WTH are the borders and the distances saved in different order?
1881 sal_uInt16 nLines[4] = { BOX_LINE_TOP, BOX_LINE_BOTTOM, BOX_LINE_LEFT, BOX_LINE_RIGHT };
1882 for ( sal_Int32 n = 4; n < 9; n++ )
1884 sal_Int32 nDist = 0;
1885 if ( aSeq[n] >>= nDist )
1887 if( bConvert )
1888 nDist = MM100_TO_TWIP(nDist);
1889 if ( n == 4 )
1890 SetDistance( sal_uInt16( nDist ));
1891 else
1892 SetDistance( sal_uInt16( nDist ), nLines[n-5] );
1894 else
1895 return sal_False;
1898 return sal_True;
1900 else
1901 return sal_False;
1903 case LEFT_BORDER_DISTANCE:
1904 bDistMember = sal_True;
1905 case LEFT_BORDER:
1906 case MID_LEFT_BORDER:
1907 nLine = BOX_LINE_LEFT;
1908 break;
1909 case RIGHT_BORDER_DISTANCE:
1910 bDistMember = sal_True;
1911 case RIGHT_BORDER:
1912 case MID_RIGHT_BORDER:
1913 nLine = BOX_LINE_RIGHT;
1914 break;
1915 case BOTTOM_BORDER_DISTANCE:
1916 bDistMember = sal_True;
1917 case BOTTOM_BORDER:
1918 case MID_BOTTOM_BORDER:
1919 nLine = BOX_LINE_BOTTOM;
1920 break;
1921 case TOP_BORDER_DISTANCE:
1922 bDistMember = sal_True;
1923 case TOP_BORDER:
1924 case MID_TOP_BORDER:
1925 nLine = BOX_LINE_TOP;
1926 break;
1927 case LINE_STYLE:
1929 drawing::LineStyle eDrawingStyle;
1930 rVal >>= eDrawingStyle;
1931 editeng::SvxBorderStyle eBorderStyle = NONE;
1932 switch ( eDrawingStyle )
1934 default:
1935 case drawing::LineStyle_NONE:
1936 break;
1937 case drawing::LineStyle_SOLID:
1938 eBorderStyle = SOLID;
1939 break;
1940 case drawing::LineStyle_DASH:
1941 eBorderStyle = DASHED;
1942 break;
1945 // Set the line style on all borders
1946 const sal_uInt16 aBorders[] = { BOX_LINE_LEFT, BOX_LINE_RIGHT, BOX_LINE_BOTTOM, BOX_LINE_TOP };
1947 for (int n(0); n != SAL_N_ELEMENTS(aBorders); ++n)
1949 editeng::SvxBorderLine* pLine = const_cast< editeng::SvxBorderLine* >( GetLine( aBorders[n] ) );
1950 if( pLine )
1951 pLine->SetBorderLineStyle( eBorderStyle );
1953 return sal_True;
1955 break;
1956 case LINE_WIDTH:
1958 // Set the line width on all borders
1959 long nWidth(0);
1960 rVal >>= nWidth;
1961 if( bConvert )
1962 nWidth = MM100_TO_TWIP( nWidth );
1964 // Set the line Width on all borders
1965 const sal_uInt16 aBorders[] = { BOX_LINE_LEFT, BOX_LINE_RIGHT, BOX_LINE_BOTTOM, BOX_LINE_TOP };
1966 for (int n(0); n != SAL_N_ELEMENTS(aBorders); ++n)
1968 editeng::SvxBorderLine* pLine = const_cast< editeng::SvxBorderLine* >( GetLine( aBorders[n] ) );
1969 pLine->SetWidth( nWidth );
1972 return sal_True;
1973 break;
1976 if( bDistMember || nMemberId == BORDER_DISTANCE )
1978 sal_Int32 nDist = 0;
1979 if(!(rVal >>= nDist))
1980 return sal_False;
1982 if(nDist >= 0)
1984 if( bConvert )
1985 nDist = MM100_TO_TWIP(nDist);
1986 if( nMemberId == BORDER_DISTANCE )
1987 SetDistance( sal_uInt16( nDist ));
1988 else
1989 SetDistance( sal_uInt16( nDist ), nLine );
1992 else
1994 SvxBorderLine aLine;
1995 if( !rVal.hasValue() )
1996 return sal_False;
1998 table::BorderLine2 aBorderLine;
1999 if( lcl_extractBorderLine(rVal, aBorderLine) )
2001 // usual struct
2003 else if (rVal.getValueTypeClass() == uno::TypeClass_SEQUENCE )
2005 // serialization for basic macro recording
2006 uno::Reference < script::XTypeConverter > xConverter
2007 ( script::Converter::create(::comphelper::getProcessComponentContext()) );
2008 uno::Sequence < uno::Any > aSeq;
2009 uno::Any aNew;
2010 try { aNew = xConverter->convertTo( rVal, ::getCppuType((const uno::Sequence < uno::Any >*)0) ); }
2011 catch (const uno::Exception&) {}
2013 aNew >>= aSeq;
2014 if (aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2016 sal_Int32 nVal = 0;
2017 if ( aSeq[0] >>= nVal )
2018 aBorderLine.Color = nVal;
2019 if ( aSeq[1] >>= nVal )
2020 aBorderLine.InnerLineWidth = (sal_Int16) nVal;
2021 if ( aSeq[2] >>= nVal )
2022 aBorderLine.OuterLineWidth = (sal_Int16) nVal;
2023 if ( aSeq[3] >>= nVal )
2024 aBorderLine.LineDistance = (sal_Int16) nVal;
2025 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2027 if (aSeq[4] >>= nVal)
2029 aBorderLine.LineStyle = nVal;
2031 if (aSeq.getLength() >= 6)
2033 if (aSeq[5] >>= nVal)
2035 aBorderLine.LineWidth = nVal;
2040 else
2041 return sal_False;
2043 else
2044 return sal_False;
2046 sal_Bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
2047 SetLine(bSet ? &aLine : 0, nLine);
2050 return sal_True;
2053 // -----------------------------------------------------------------------
2055 SfxPoolItem* SvxBoxItem::Clone( SfxItemPool* ) const
2057 return new SvxBoxItem( *this );
2060 //------------------------------------------------------------------------
2062 SfxItemPresentation SvxBoxItem::GetPresentation
2064 SfxItemPresentation ePres,
2065 SfxMapUnit eCoreUnit,
2066 SfxMapUnit ePresUnit,
2067 XubString& rText, const IntlWrapper *pIntl
2068 ) const
2070 switch ( ePres )
2072 case SFX_ITEM_PRESENTATION_NONE:
2073 rText.Erase();
2074 return SFX_ITEM_PRESENTATION_NONE;
2076 case SFX_ITEM_PRESENTATION_NAMELESS:
2078 rText.Erase();
2080 if ( pTop )
2082 rText = pTop->GetValueString( eCoreUnit, ePresUnit, pIntl );
2083 rText += cpDelim;
2085 if( !(pTop && pBottom && pLeft && pRight &&
2086 *pTop == *pBottom && *pTop == *pLeft && *pTop == *pRight) )
2088 if ( pBottom )
2090 rText += pBottom->GetValueString( eCoreUnit, ePresUnit, pIntl );
2091 rText += cpDelim;
2093 if ( pLeft )
2095 rText += pLeft->GetValueString( eCoreUnit, ePresUnit, pIntl );
2096 rText += cpDelim;
2098 if ( pRight )
2100 rText += pRight->GetValueString( eCoreUnit, ePresUnit, pIntl );
2101 rText += cpDelim;
2104 rText += GetMetricText( (long)nTopDist, eCoreUnit, ePresUnit, pIntl );
2105 if( nTopDist != nBottomDist || nTopDist != nLeftDist ||
2106 nTopDist != nRightDist )
2108 (((((rText += cpDelim)
2109 += GetMetricText( (long)nBottomDist, eCoreUnit,
2110 ePresUnit, pIntl ))
2111 += cpDelim)
2112 += GetMetricText( (long)nLeftDist, eCoreUnit, ePresUnit, pIntl ))
2113 += cpDelim)
2114 += GetMetricText( (long)nRightDist, eCoreUnit,
2115 ePresUnit, pIntl );
2117 return SFX_ITEM_PRESENTATION_NAMELESS;
2119 case SFX_ITEM_PRESENTATION_COMPLETE:
2121 if( !(pTop || pBottom || pLeft || pRight) )
2123 rText = EE_RESSTR(RID_SVXITEMS_BORDER_NONE);
2124 rText += cpDelim;
2126 else
2128 rText = EE_RESSTR(RID_SVXITEMS_BORDER_COMPLETE);
2129 if( pTop && pBottom && pLeft && pRight &&
2130 *pTop == *pBottom && *pTop == *pLeft && *pTop == *pRight )
2132 rText += pTop->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2133 rText += cpDelim;
2135 else
2137 if ( pTop )
2139 rText += EE_RESSTR(RID_SVXITEMS_BORDER_TOP);
2140 rText += pTop->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2141 rText += cpDelim;
2143 if ( pBottom )
2145 rText += EE_RESSTR(RID_SVXITEMS_BORDER_BOTTOM);
2146 rText += pBottom->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2147 rText += cpDelim;
2149 if ( pLeft )
2151 rText += EE_RESSTR(RID_SVXITEMS_BORDER_LEFT);
2152 rText += pLeft->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2153 rText += cpDelim;
2155 if ( pRight )
2157 rText += EE_RESSTR(RID_SVXITEMS_BORDER_RIGHT);
2158 rText += pRight->GetValueString( eCoreUnit, ePresUnit, pIntl, sal_True );
2159 rText += cpDelim;
2164 rText += EE_RESSTR(RID_SVXITEMS_BORDER_DISTANCE);
2165 if( nTopDist == nBottomDist && nTopDist == nLeftDist &&
2166 nTopDist == nRightDist )
2168 rText += GetMetricText( (long)nTopDist, eCoreUnit,
2169 ePresUnit, pIntl );
2170 rText += EE_RESSTR(GetMetricId(ePresUnit));
2172 else
2174 (((rText += EE_RESSTR(RID_SVXITEMS_BORDER_TOP))
2175 += GetMetricText( (long)nTopDist, eCoreUnit,
2176 ePresUnit, pIntl ))
2177 += EE_RESSTR(GetMetricId(ePresUnit)))
2178 += cpDelim;
2179 (((rText += EE_RESSTR(RID_SVXITEMS_BORDER_BOTTOM))
2180 += GetMetricText( (long)nBottomDist, eCoreUnit,
2181 ePresUnit, pIntl ))
2182 += EE_RESSTR(GetMetricId(ePresUnit)))
2183 += cpDelim;
2184 (((rText += EE_RESSTR(RID_SVXITEMS_BORDER_LEFT))
2185 += GetMetricText( (long)nLeftDist, eCoreUnit,
2186 ePresUnit, pIntl ))
2187 += EE_RESSTR(GetMetricId(ePresUnit)))
2188 += cpDelim;
2189 ((rText += EE_RESSTR(RID_SVXITEMS_BORDER_RIGHT))
2190 += GetMetricText( (long)nRightDist, eCoreUnit,
2191 ePresUnit, pIntl ))
2192 += EE_RESSTR(GetMetricId(ePresUnit));
2194 return SFX_ITEM_PRESENTATION_COMPLETE;
2196 default: ;//prevent warning
2198 return SFX_ITEM_PRESENTATION_NONE;
2201 // -----------------------------------------------------------------------
2203 SvStream& SvxBoxItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
2205 rStrm << (sal_uInt16) GetDistance();
2206 const SvxBorderLine* pLine[ 4 ]; // top, left, right, bottom
2207 pLine[ 0 ] = GetTop();
2208 pLine[ 1 ] = GetLeft();
2209 pLine[ 2 ] = GetRight();
2210 pLine[ 3 ] = GetBottom();
2212 for( int i = 0; i < 4; i++ )
2214 const SvxBorderLine* l = pLine[ i ];
2215 if( l )
2217 rStrm << static_cast<sal_Int8>(i);
2218 StoreBorderLine(rStrm, *l, BorderLineVersionFromBoxVersion(nItemVersion));
2221 sal_Int8 cLine = 4;
2222 if( nItemVersion >= BOX_4DISTS_VERSION &&
2223 !(nTopDist == nLeftDist &&
2224 nTopDist == nRightDist &&
2225 nTopDist == nBottomDist) )
2227 cLine |= 0x10;
2230 rStrm << cLine;
2232 if( nItemVersion >= BOX_4DISTS_VERSION && (cLine & 0x10) != 0 )
2234 rStrm << (sal_uInt16)nTopDist
2235 << (sal_uInt16)nLeftDist
2236 << (sal_uInt16)nRightDist
2237 << (sal_uInt16)nBottomDist;
2240 return rStrm;
2243 // -----------------------------------------------------------------------
2245 sal_uInt16 SvxBoxItem::GetVersion( sal_uInt16 nFFVer ) const
2247 DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
2248 SOFFICE_FILEFORMAT_40==nFFVer ||
2249 SOFFICE_FILEFORMAT_50==nFFVer,
2250 "SvxBoxItem: Gibt es ein neues Fileformat?" );
2251 return SOFFICE_FILEFORMAT_31==nFFVer ||
2252 SOFFICE_FILEFORMAT_40==nFFVer ? 0 : BOX_BORDER_STYLE_VERSION;
2255 // -----------------------------------------------------------------------
2257 bool SvxBoxItem::ScaleMetrics( long nMult, long nDiv )
2259 if ( pTop ) pTop->ScaleMetrics( nMult, nDiv );
2260 if ( pBottom ) pBottom->ScaleMetrics( nMult, nDiv );
2261 if ( pLeft ) pLeft->ScaleMetrics( nMult, nDiv );
2262 if ( pRight ) pBottom->ScaleMetrics( nMult, nDiv );
2263 nTopDist = (sal_uInt16)Scale( nTopDist, nMult, nDiv );
2264 nBottomDist = (sal_uInt16)Scale( nBottomDist, nMult, nDiv );
2265 nLeftDist = (sal_uInt16)Scale( nLeftDist, nMult, nDiv );
2266 nRightDist = (sal_uInt16)Scale( nRightDist, nMult, nDiv );
2267 return true;
2270 // -----------------------------------------------------------------------
2272 bool SvxBoxItem::HasMetrics() const
2274 return true;
2277 // -----------------------------------------------------------------------
2279 SfxPoolItem* SvxBoxItem::Create( SvStream& rStrm, sal_uInt16 nIVersion ) const
2281 sal_uInt16 nDistance;
2282 rStrm >> nDistance;
2283 SvxBoxItem* pAttr = new SvxBoxItem( Which() );
2285 sal_uInt16 aLineMap[4] = { BOX_LINE_TOP, BOX_LINE_LEFT,
2286 BOX_LINE_RIGHT, BOX_LINE_BOTTOM };
2288 sal_Int8 cLine;
2289 while( sal_True )
2291 rStrm >> cLine;
2293 if( cLine > 3 )
2294 break;
2296 SvxBorderLine aBorder = CreateBorderLine(rStrm, BorderLineVersionFromBoxVersion(nIVersion));
2297 pAttr->SetLine( &aBorder, aLineMap[cLine] );
2300 if( nIVersion >= BOX_4DISTS_VERSION && (cLine&0x10) != 0 )
2302 for( sal_uInt16 i=0; i < 4; i++ )
2304 sal_uInt16 nDist;
2305 rStrm >> nDist;
2306 pAttr->SetDistance( nDist, aLineMap[i] );
2309 else
2311 pAttr->SetDistance( nDistance );
2314 return pAttr;
2317 // -----------------------------------------------------------------------
2319 const SvxBorderLine *SvxBoxItem::GetLine( sal_uInt16 nLine ) const
2321 const SvxBorderLine *pRet = 0;
2323 switch ( nLine )
2325 case BOX_LINE_TOP:
2326 pRet = pTop;
2327 break;
2328 case BOX_LINE_BOTTOM:
2329 pRet = pBottom;
2330 break;
2331 case BOX_LINE_LEFT:
2332 pRet = pLeft;
2333 break;
2334 case BOX_LINE_RIGHT:
2335 pRet = pRight;
2336 break;
2337 default:
2338 OSL_FAIL( "wrong line" );
2339 break;
2342 return pRet;
2345 // -----------------------------------------------------------------------
2347 void SvxBoxItem::SetLine( const SvxBorderLine* pNew, sal_uInt16 nLine )
2349 SvxBorderLine* pTmp = pNew ? new SvxBorderLine( *pNew ) : 0;
2351 switch ( nLine )
2353 case BOX_LINE_TOP:
2354 delete pTop;
2355 pTop = pTmp;
2356 break;
2357 case BOX_LINE_BOTTOM:
2358 delete pBottom;
2359 pBottom = pTmp;
2360 break;
2361 case BOX_LINE_LEFT:
2362 delete pLeft;
2363 pLeft = pTmp;
2364 break;
2365 case BOX_LINE_RIGHT:
2366 delete pRight;
2367 pRight = pTmp;
2368 break;
2369 default:
2370 delete pTmp;
2371 OSL_FAIL( "wrong line" );
2375 // -----------------------------------------------------------------------
2377 sal_uInt16 SvxBoxItem::GetDistance() const
2379 // The smallest distance that is not 0 will be returned.
2380 sal_uInt16 nDist = nTopDist;
2381 if( nBottomDist && (!nDist || nBottomDist < nDist) )
2382 nDist = nBottomDist;
2383 if( nLeftDist && (!nDist || nLeftDist < nDist) )
2384 nDist = nLeftDist;
2385 if( nRightDist && (!nDist || nRightDist < nDist) )
2386 nDist = nRightDist;
2388 return nDist;
2391 // -----------------------------------------------------------------------
2393 sal_uInt16 SvxBoxItem::GetDistance( sal_uInt16 nLine ) const
2395 sal_uInt16 nDist = 0;
2396 switch ( nLine )
2398 case BOX_LINE_TOP:
2399 nDist = nTopDist;
2400 break;
2401 case BOX_LINE_BOTTOM:
2402 nDist = nBottomDist;
2403 break;
2404 case BOX_LINE_LEFT:
2405 nDist = nLeftDist;
2406 break;
2407 case BOX_LINE_RIGHT:
2408 nDist = nRightDist;
2409 break;
2410 default:
2411 OSL_FAIL( "wrong line" );
2414 return nDist;
2417 // -----------------------------------------------------------------------
2419 void SvxBoxItem::SetDistance( sal_uInt16 nNew, sal_uInt16 nLine )
2421 switch ( nLine )
2423 case BOX_LINE_TOP:
2424 nTopDist = nNew;
2425 break;
2426 case BOX_LINE_BOTTOM:
2427 nBottomDist = nNew;
2428 break;
2429 case BOX_LINE_LEFT:
2430 nLeftDist = nNew;
2431 break;
2432 case BOX_LINE_RIGHT:
2433 nRightDist = nNew;
2434 break;
2435 default:
2436 OSL_FAIL( "wrong line" );
2440 // -----------------------------------------------------------------------
2442 sal_uInt16 SvxBoxItem::CalcLineSpace( sal_uInt16 nLine, sal_Bool bIgnoreLine ) const
2444 SvxBorderLine* pTmp = 0;
2445 sal_uInt16 nDist = 0;
2446 switch ( nLine )
2448 case BOX_LINE_TOP:
2449 pTmp = pTop;
2450 nDist = nTopDist;
2451 break;
2452 case BOX_LINE_BOTTOM:
2453 pTmp = pBottom;
2454 nDist = nBottomDist;
2455 break;
2456 case BOX_LINE_LEFT:
2457 pTmp = pLeft;
2458 nDist = nLeftDist;
2459 break;
2460 case BOX_LINE_RIGHT:
2461 pTmp = pRight;
2462 nDist = nRightDist;
2463 break;
2464 default:
2465 OSL_FAIL( "wrong line" );
2468 if( pTmp )
2470 nDist = nDist + (sal_uInt16)(pTmp->GetOutWidth()) + (sal_uInt16)(pTmp->GetInWidth()) + (sal_uInt16)(pTmp->GetDistance());
2472 else if( !bIgnoreLine )
2473 nDist = 0;
2474 return nDist;
2477 // class SvxBoxInfoItem --------------------------------------------------
2479 SvxBoxInfoItem::SvxBoxInfoItem( const sal_uInt16 nId ) :
2480 SfxPoolItem( nId ),
2481 pHori ( 0 ),
2482 pVert ( 0 ),
2483 mbEnableHor( false ),
2484 mbEnableVer( false ),
2485 nDefDist( 0 )
2487 bDist = bMinDist = sal_False;
2488 ResetFlags();
2491 // -----------------------------------------------------------------------
2493 SvxBoxInfoItem::SvxBoxInfoItem( const SvxBoxInfoItem& rCpy ) :
2494 SfxPoolItem( rCpy ),
2495 mbEnableHor( rCpy.mbEnableHor ),
2496 mbEnableVer( rCpy.mbEnableVer )
2498 pHori = rCpy.GetHori() ? new SvxBorderLine( *rCpy.GetHori() ) : 0;
2499 pVert = rCpy.GetVert() ? new SvxBorderLine( *rCpy.GetVert() ) : 0;
2500 bDist = rCpy.IsDist();
2501 bMinDist = rCpy.IsMinDist();
2502 nValidFlags = rCpy.nValidFlags;
2503 nDefDist = rCpy.GetDefDist();
2506 // -----------------------------------------------------------------------
2508 SvxBoxInfoItem::~SvxBoxInfoItem()
2510 delete pHori;
2511 delete pVert;
2514 // -----------------------------------------------------------------------
2516 SvxBoxInfoItem &SvxBoxInfoItem::operator=( const SvxBoxInfoItem& rCpy )
2518 delete pHori;
2519 delete pVert;
2520 pHori = rCpy.GetHori() ? new SvxBorderLine( *rCpy.GetHori() ) : 0;
2521 pVert = rCpy.GetVert() ? new SvxBorderLine( *rCpy.GetVert() ) : 0;
2522 mbEnableHor = rCpy.mbEnableHor;
2523 mbEnableVer = rCpy.mbEnableVer;
2524 bDist = rCpy.IsDist();
2525 bMinDist = rCpy.IsMinDist();
2526 nValidFlags = rCpy.nValidFlags;
2527 nDefDist = rCpy.GetDefDist();
2528 return *this;
2531 // -----------------------------------------------------------------------
2533 int SvxBoxInfoItem::operator==( const SfxPoolItem& rAttr ) const
2535 SvxBoxInfoItem& rBoxInfo = (SvxBoxInfoItem&)rAttr;
2537 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
2539 return ( mbEnableHor == rBoxInfo.mbEnableHor
2540 && mbEnableVer == rBoxInfo.mbEnableVer
2541 && bDist == rBoxInfo.IsDist()
2542 && bMinDist == rBoxInfo.IsMinDist()
2543 && nValidFlags == rBoxInfo.nValidFlags
2544 && nDefDist == rBoxInfo.GetDefDist()
2545 && CmpBrdLn( pHori, rBoxInfo.GetHori() )
2546 && CmpBrdLn( pVert, rBoxInfo.GetVert() )
2550 // -----------------------------------------------------------------------
2552 void SvxBoxInfoItem::SetLine( const SvxBorderLine* pNew, sal_uInt16 nLine )
2554 SvxBorderLine* pTmp = pNew ? new SvxBorderLine( *pNew ) : 0;
2556 if ( BOXINFO_LINE_HORI == nLine )
2558 delete pHori;
2559 pHori = pTmp;
2561 else if ( BOXINFO_LINE_VERT == nLine )
2563 delete pVert;
2564 pVert = pTmp;
2566 else
2568 delete pTmp;
2569 OSL_FAIL( "wrong line" );
2573 // -----------------------------------------------------------------------
2575 SfxPoolItem* SvxBoxInfoItem::Clone( SfxItemPool* ) const
2577 return new SvxBoxInfoItem( *this );
2580 //------------------------------------------------------------------------
2582 SfxItemPresentation SvxBoxInfoItem::GetPresentation
2584 SfxItemPresentation /*ePres*/,
2585 SfxMapUnit /*eCoreUnit*/,
2586 SfxMapUnit /*ePresUnit*/,
2587 XubString& rText, const IntlWrapper *
2588 ) const
2590 rText.Erase();
2591 return SFX_ITEM_PRESENTATION_NONE;
2594 // -----------------------------------------------------------------------
2596 SvStream& SvxBoxInfoItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
2598 sal_Int8 cFlags = 0;
2600 if ( IsTable() )
2601 cFlags |= 0x01;
2602 if ( IsDist() )
2603 cFlags |= 0x02;
2604 if ( IsMinDist() )
2605 cFlags |= 0x04;
2606 rStrm << (sal_Int8) cFlags
2607 << (sal_uInt16) GetDefDist();
2608 const SvxBorderLine* pLine[ 2 ];
2609 pLine[ 0 ] = GetHori();
2610 pLine[ 1 ] = GetVert();
2612 for( int i = 0; i < 2; i++ )
2614 const SvxBorderLine* l = pLine[ i ];
2615 if( l )
2617 rStrm << (char) i
2618 << l->GetColor()
2619 << (short) l->GetOutWidth()
2620 << (short) l->GetInWidth()
2621 << (short) l->GetDistance();
2624 rStrm << (char) 2;
2625 return rStrm;
2628 // -----------------------------------------------------------------------
2630 bool SvxBoxInfoItem::ScaleMetrics( long nMult, long nDiv )
2632 if ( pHori ) pHori->ScaleMetrics( nMult, nDiv );
2633 if ( pVert ) pVert->ScaleMetrics( nMult, nDiv );
2634 nDefDist = (sal_uInt16)Scale( nDefDist, nMult, nDiv );
2635 return true;
2638 // -----------------------------------------------------------------------
2640 bool SvxBoxInfoItem::HasMetrics() const
2642 return true;
2645 // -----------------------------------------------------------------------
2647 SfxPoolItem* SvxBoxInfoItem::Create( SvStream& rStrm, sal_uInt16 ) const
2649 sal_Int8 cFlags;
2650 sal_uInt16 _nDefDist;
2651 rStrm >> cFlags >> _nDefDist;
2653 SvxBoxInfoItem* pAttr = new SvxBoxInfoItem( Which() );
2655 pAttr->SetTable ( ( cFlags & 0x01 ) != 0 );
2656 pAttr->SetDist ( ( cFlags & 0x02 ) != 0 );
2657 pAttr->SetMinDist( ( cFlags & 0x04 ) != 0 );
2658 pAttr->SetDefDist( _nDefDist );
2660 while( sal_True )
2662 sal_Int8 cLine;
2663 rStrm >> cLine;
2665 if( cLine > 1 )
2666 break;
2667 short nOutline, nInline, nDistance;
2668 Color aColor;
2669 rStrm >> aColor >> nOutline >> nInline >> nDistance;
2670 SvxBorderLine aBorder( &aColor );
2671 aBorder.GuessLinesWidths(NONE, nOutline, nInline, nDistance);
2673 switch( cLine )
2675 case 0: pAttr->SetLine( &aBorder, BOXINFO_LINE_HORI ); break;
2676 case 1: pAttr->SetLine( &aBorder, BOXINFO_LINE_VERT ); break;
2679 return pAttr;
2682 // -----------------------------------------------------------------------
2684 void SvxBoxInfoItem::ResetFlags()
2686 nValidFlags = 0x7F; // all valid except Disable
2689 bool SvxBoxInfoItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
2691 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2692 table::BorderLine2 aRetLine;
2693 sal_Int16 nVal=0;
2694 sal_Bool bIntMember = sal_False;
2695 nMemberId &= ~CONVERT_TWIPS;
2696 switch(nMemberId)
2698 case 0:
2700 // 2 BorderLines, flags, valid flags and distance
2701 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq( 5 );
2702 aSeq[0] = ::com::sun::star::uno::makeAny( SvxBoxItem::SvxLineToLine( pHori, bConvert) );
2703 aSeq[1] = ::com::sun::star::uno::makeAny( SvxBoxItem::SvxLineToLine( pVert, bConvert) );
2704 if ( IsTable() )
2705 nVal |= 0x01;
2706 if ( IsDist() )
2707 nVal |= 0x02;
2708 if ( IsMinDist() )
2709 nVal |= 0x04;
2710 aSeq[2] = ::com::sun::star::uno::makeAny( nVal );
2711 nVal = nValidFlags;
2712 aSeq[3] = ::com::sun::star::uno::makeAny( nVal );
2713 aSeq[4] = ::com::sun::star::uno::makeAny( (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(GetDefDist()) : GetDefDist()) );
2714 rVal = ::com::sun::star::uno::makeAny( aSeq );
2715 return sal_True;
2718 case MID_HORIZONTAL:
2719 aRetLine = SvxBoxItem::SvxLineToLine( pHori, bConvert);
2720 break;
2721 case MID_VERTICAL:
2722 aRetLine = SvxBoxItem::SvxLineToLine( pVert, bConvert);
2723 break;
2724 case MID_FLAGS:
2725 bIntMember = sal_True;
2726 if ( IsTable() )
2727 nVal |= 0x01;
2728 if ( IsDist() )
2729 nVal |= 0x02;
2730 if ( IsMinDist() )
2731 nVal |= 0x04;
2732 rVal <<= nVal;
2733 break;
2734 case MID_VALIDFLAGS:
2735 bIntMember = sal_True;
2736 nVal = nValidFlags;
2737 rVal <<= nVal;
2738 break;
2739 case MID_DISTANCE:
2740 bIntMember = sal_True;
2741 rVal <<= (sal_Int32)(bConvert ? TWIP_TO_MM100_UNSIGNED(GetDefDist()) : GetDefDist());
2742 break;
2743 default: OSL_FAIL("Wrong MemberId!"); return false;
2746 if( !bIntMember )
2747 rVal <<= aRetLine;
2749 return true;
2752 // -----------------------------------------------------------------------
2754 bool SvxBoxInfoItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
2756 sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
2757 nMemberId &= ~CONVERT_TWIPS;
2758 sal_Bool bRet;
2759 switch(nMemberId)
2761 case 0:
2763 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any > aSeq;
2764 if (( rVal >>= aSeq ) && ( aSeq.getLength() == 5 ))
2766 // 2 BorderLines, flags, valid flags and distance
2767 if (!lcl_setLine(aSeq[0], *this, BOXINFO_LINE_HORI, bConvert))
2768 return sal_False;
2769 if (!lcl_setLine(aSeq[1], *this, BOXINFO_LINE_VERT, bConvert))
2770 return sal_False;
2772 sal_Int16 nFlags( 0 );
2773 sal_Int32 nVal( 0 );
2774 if ( aSeq[2] >>= nFlags )
2776 SetTable ( ( nFlags & 0x01 ) != 0 );
2777 SetDist ( ( nFlags & 0x02 ) != 0 );
2778 SetMinDist( ( nFlags & 0x04 ) != 0 );
2780 else
2781 return sal_False;
2782 if ( aSeq[3] >>= nFlags )
2783 nValidFlags = (sal_uInt8)nFlags;
2784 else
2785 return sal_False;
2786 if (( aSeq[4] >>= nVal ) && ( nVal >= 0 ))
2788 if( bConvert )
2789 nVal = MM100_TO_TWIP(nVal);
2790 SetDefDist( (sal_uInt16)nVal );
2793 return sal_True;
2796 case MID_HORIZONTAL:
2797 case MID_VERTICAL:
2799 if( !rVal.hasValue() )
2800 return sal_False;
2802 table::BorderLine2 aBorderLine;
2803 if( lcl_extractBorderLine(rVal, aBorderLine) )
2805 // usual struct
2807 else if (rVal.getValueTypeClass() == uno::TypeClass_SEQUENCE )
2809 // serialization for basic macro recording
2810 uno::Reference < script::XTypeConverter > xConverter( script::Converter::create(::comphelper::getProcessComponentContext()) );
2811 uno::Any aNew;
2812 uno::Sequence < uno::Any > aSeq;
2813 try { aNew = xConverter->convertTo( rVal, ::getCppuType((const uno::Sequence < uno::Any >*)0) ); }
2814 catch (const uno::Exception&) {}
2816 if ((aNew >>= aSeq) &&
2817 aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2819 sal_Int32 nVal = 0;
2820 if ( aSeq[0] >>= nVal )
2821 aBorderLine.Color = nVal;
2822 if ( aSeq[1] >>= nVal )
2823 aBorderLine.InnerLineWidth = (sal_Int16) nVal;
2824 if ( aSeq[2] >>= nVal )
2825 aBorderLine.OuterLineWidth = (sal_Int16) nVal;
2826 if ( aSeq[3] >>= nVal )
2827 aBorderLine.LineDistance = (sal_Int16) nVal;
2828 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2830 if (aSeq[4] >>= nVal)
2832 aBorderLine.LineStyle = nVal;
2834 if (aSeq.getLength() >= 6)
2836 if (aSeq[5] >>= nVal)
2838 aBorderLine.LineWidth = nVal;
2843 else
2844 return sal_False;
2846 else if (rVal.getValueType() == ::getCppuType((const ::com::sun::star::uno::Sequence < sal_Int16 >*)0) )
2848 // serialization for basic macro recording
2849 ::com::sun::star::uno::Sequence < sal_Int16 > aSeq;
2850 rVal >>= aSeq;
2851 if (aSeq.getLength() >= 4 && aSeq.getLength() <= 6)
2853 aBorderLine.Color = aSeq[0];
2854 aBorderLine.InnerLineWidth = aSeq[1];
2855 aBorderLine.OuterLineWidth = aSeq[2];
2856 aBorderLine.LineDistance = aSeq[3];
2857 if (aSeq.getLength() >= 5) // fdo#40874 added fields
2859 aBorderLine.LineStyle = aSeq[4];
2860 if (aSeq.getLength() >= 6)
2862 aBorderLine.LineWidth = aSeq[5];
2866 else
2867 return sal_False;
2869 else
2870 return sal_False;
2872 SvxBorderLine aLine;
2873 sal_Bool bSet = SvxBoxItem::LineToSvxLine(aBorderLine, aLine, bConvert);
2874 if ( bSet )
2875 SetLine( &aLine, nMemberId == MID_HORIZONTAL ? BOXINFO_LINE_HORI : BOXINFO_LINE_VERT );
2876 break;
2878 case MID_FLAGS:
2880 sal_Int16 nFlags = sal_Int16();
2881 bRet = (rVal >>= nFlags);
2882 if ( bRet )
2884 SetTable ( ( nFlags & 0x01 ) != 0 );
2885 SetDist ( ( nFlags & 0x02 ) != 0 );
2886 SetMinDist( ( nFlags & 0x04 ) != 0 );
2889 break;
2891 case MID_VALIDFLAGS:
2893 sal_Int16 nFlags = sal_Int16();
2894 bRet = (rVal >>= nFlags);
2895 if ( bRet )
2896 nValidFlags = (sal_uInt8)nFlags;
2897 break;
2899 case MID_DISTANCE:
2901 sal_Int32 nVal = 0;
2902 bRet = (rVal >>= nVal);
2903 if ( bRet && nVal>=0 )
2905 if( bConvert )
2906 nVal = MM100_TO_TWIP(nVal);
2907 SetDefDist( (sal_uInt16)nVal );
2909 break;
2911 default: OSL_FAIL("Wrong MemberId!"); return sal_False;
2914 return sal_True;
2917 // class SvxFmtBreakItem -------------------------------------------------
2919 int SvxFmtBreakItem::operator==( const SfxPoolItem& rAttr ) const
2921 DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "unequal types" );
2923 return GetValue() == ( (SvxFmtBreakItem&)rAttr ).GetValue();
2926 //------------------------------------------------------------------------
2928 SfxItemPresentation SvxFmtBreakItem::GetPresentation
2930 SfxItemPresentation ePres,
2931 SfxMapUnit /*eCoreUnit*/,
2932 SfxMapUnit /*ePresUnit*/,
2933 XubString& rText, const IntlWrapper *
2934 ) const
2936 switch ( ePres )
2938 case SFX_ITEM_PRESENTATION_NONE:
2939 rText.Erase();
2940 return SFX_ITEM_PRESENTATION_NONE;
2942 case SFX_ITEM_PRESENTATION_NAMELESS:
2943 case SFX_ITEM_PRESENTATION_COMPLETE:
2944 rText = GetValueTextByPos( GetValue() );
2945 return ePres;
2946 default: ;//prevent warning
2948 return SFX_ITEM_PRESENTATION_NONE;
2951 // -----------------------------------------------------------------------
2953 rtl::OUString SvxFmtBreakItem::GetValueTextByPos( sal_uInt16 nPos ) const
2955 DBG_ASSERT( nPos < SVX_BREAK_END, "enum overflow!" );
2956 return EE_RESSTR(RID_SVXITEMS_BREAK_BEGIN + nPos);
2959 // -----------------------------------------------------------------------
2960 bool SvxFmtBreakItem::QueryValue( uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
2962 style::BreakType eBreak = style::BreakType_NONE;
2963 switch ( (SvxBreak)GetValue() )
2965 case SVX_BREAK_COLUMN_BEFORE: eBreak = style::BreakType_COLUMN_BEFORE; break;
2966 case SVX_BREAK_COLUMN_AFTER: eBreak = style::BreakType_COLUMN_AFTER ; break;
2967 case SVX_BREAK_COLUMN_BOTH: eBreak = style::BreakType_COLUMN_BOTH ; break;
2968 case SVX_BREAK_PAGE_BEFORE: eBreak = style::BreakType_PAGE_BEFORE ; break;
2969 case SVX_BREAK_PAGE_AFTER: eBreak = style::BreakType_PAGE_AFTER ; break;
2970 case SVX_BREAK_PAGE_BOTH: eBreak = style::BreakType_PAGE_BOTH ; break;
2971 default: ;//prevent warning
2973 rVal <<= eBreak;
2974 return true;
2976 // -----------------------------------------------------------------------
2977 bool SvxFmtBreakItem::PutValue( const uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
2979 style::BreakType nBreak;
2981 if(!(rVal >>= nBreak))
2983 sal_Int32 nValue = 0;
2984 if(!(rVal >>= nValue))
2985 return sal_False;
2987 nBreak = (style::BreakType) nValue;
2990 SvxBreak eBreak = SVX_BREAK_NONE;
2991 switch( nBreak )
2993 case style::BreakType_COLUMN_BEFORE: eBreak = SVX_BREAK_COLUMN_BEFORE; break;
2994 case style::BreakType_COLUMN_AFTER: eBreak = SVX_BREAK_COLUMN_AFTER; break;
2995 case style::BreakType_COLUMN_BOTH: eBreak = SVX_BREAK_COLUMN_BOTH; break;
2996 case style::BreakType_PAGE_BEFORE: eBreak = SVX_BREAK_PAGE_BEFORE; break;
2997 case style::BreakType_PAGE_AFTER: eBreak = SVX_BREAK_PAGE_AFTER; break;
2998 case style::BreakType_PAGE_BOTH: eBreak = SVX_BREAK_PAGE_BOTH; break;
2999 default: ;//prevent warning
3001 SetValue((sal_uInt16) eBreak);
3003 return true;
3006 // -----------------------------------------------------------------------
3008 SfxPoolItem* SvxFmtBreakItem::Clone( SfxItemPool* ) const
3010 return new SvxFmtBreakItem( *this );
3013 // -----------------------------------------------------------------------
3015 SvStream& SvxFmtBreakItem::Store( SvStream& rStrm , sal_uInt16 nItemVersion ) const
3017 rStrm << (sal_Int8)GetValue();
3018 if( FMTBREAK_NOAUTO > nItemVersion )
3019 rStrm << (sal_Int8)0x01;
3020 return rStrm;
3023 // -----------------------------------------------------------------------
3025 sal_uInt16 SvxFmtBreakItem::GetVersion( sal_uInt16 nFFVer ) const
3027 DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
3028 SOFFICE_FILEFORMAT_40==nFFVer ||
3029 SOFFICE_FILEFORMAT_50==nFFVer,
3030 "SvxFmtBreakItem: Is there a new file format? ");
3031 return SOFFICE_FILEFORMAT_31==nFFVer ||
3032 SOFFICE_FILEFORMAT_40==nFFVer ? 0 : FMTBREAK_NOAUTO;
3035 // -----------------------------------------------------------------------
3037 SfxPoolItem* SvxFmtBreakItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
3039 sal_Int8 eBreak, bDummy;
3040 rStrm >> eBreak;
3041 if( FMTBREAK_NOAUTO > nVersion )
3042 rStrm >> bDummy;
3043 return new SvxFmtBreakItem( (const SvxBreak)eBreak, Which() );
3046 // -----------------------------------------------------------------------
3048 sal_uInt16 SvxFmtBreakItem::GetValueCount() const
3050 return SVX_BREAK_END; // SVX_BREAK_PAGE_BOTH + 1
3053 // class SvxFmtKeepItem -------------------------------------------------
3055 SfxPoolItem* SvxFmtKeepItem::Clone( SfxItemPool* ) const
3057 return new SvxFmtKeepItem( *this );
3060 // -----------------------------------------------------------------------
3062 SvStream& SvxFmtKeepItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
3064 rStrm << (sal_Int8)GetValue();
3065 return rStrm;
3068 // -----------------------------------------------------------------------
3070 SfxPoolItem* SvxFmtKeepItem::Create( SvStream& rStrm, sal_uInt16 ) const
3072 sal_Int8 bIsKeep;
3073 rStrm >> bIsKeep;
3074 return new SvxFmtKeepItem( sal_Bool( bIsKeep != 0 ), Which() );
3077 //------------------------------------------------------------------------
3079 SfxItemPresentation SvxFmtKeepItem::GetPresentation
3081 SfxItemPresentation ePres,
3082 SfxMapUnit /*eCoreUnit*/,
3083 SfxMapUnit /*ePresUnit*/,
3084 XubString& rText, const IntlWrapper *
3085 ) const
3087 switch ( ePres )
3089 case SFX_ITEM_PRESENTATION_NONE:
3090 rText.Erase();
3091 return ePres;
3093 case SFX_ITEM_PRESENTATION_NAMELESS:
3094 case SFX_ITEM_PRESENTATION_COMPLETE:
3096 sal_uInt16 nId = RID_SVXITEMS_FMTKEEP_FALSE;
3098 if ( GetValue() )
3099 nId = RID_SVXITEMS_FMTKEEP_TRUE;
3100 rText = EE_RESSTR(nId);
3101 return ePres;
3103 default: ;//prevent warning
3105 return SFX_ITEM_PRESENTATION_NONE;
3108 // class SvxLineItem ------------------------------------------------------
3110 SvxLineItem::SvxLineItem( const sal_uInt16 nId ) :
3112 SfxPoolItem ( nId ),
3114 pLine( NULL )
3118 // -----------------------------------------------------------------------
3120 SvxLineItem::SvxLineItem( const SvxLineItem& rCpy ) :
3122 SfxPoolItem ( rCpy )
3124 pLine = rCpy.GetLine() ? new SvxBorderLine( *rCpy.GetLine() ) : 0;
3127 // -----------------------------------------------------------------------
3129 SvxLineItem::~SvxLineItem()
3131 delete pLine;
3134 // -----------------------------------------------------------------------
3136 SvxLineItem& SvxLineItem::operator=( const SvxLineItem& rLine )
3138 SetLine( rLine.GetLine() );
3140 return *this;
3143 // -----------------------------------------------------------------------
3145 int SvxLineItem::operator==( const SfxPoolItem& rAttr ) const
3147 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
3149 return CmpBrdLn( pLine, ((SvxLineItem&)rAttr).GetLine() );
3152 // -----------------------------------------------------------------------
3154 SfxPoolItem* SvxLineItem::Clone( SfxItemPool* ) const
3156 return new SvxLineItem( *this );
3159 bool SvxLineItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemId ) const
3161 sal_Bool bConvert = 0!=(nMemId&CONVERT_TWIPS);
3162 nMemId &= ~CONVERT_TWIPS;
3163 if ( nMemId == 0 )
3165 rVal <<= uno::makeAny( SvxBoxItem::SvxLineToLine(pLine, bConvert) );
3166 return true;
3168 else if ( pLine )
3170 switch ( nMemId )
3172 case MID_FG_COLOR: rVal <<= sal_Int32(pLine->GetColor().GetColor()); break;
3173 case MID_OUTER_WIDTH: rVal <<= sal_Int32(pLine->GetOutWidth()); break;
3174 case MID_INNER_WIDTH: rVal <<= sal_Int32(pLine->GetInWidth( )); break;
3175 case MID_DISTANCE: rVal <<= sal_Int32(pLine->GetDistance()); break;
3176 default:
3177 OSL_FAIL( "Wrong MemberId" );
3178 return false;
3182 return true;
3185 // -----------------------------------------------------------------------
3187 bool SvxLineItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemId )
3189 sal_Bool bConvert = 0!=(nMemId&CONVERT_TWIPS);
3190 nMemId &= ~CONVERT_TWIPS;
3191 sal_Int32 nVal = 0;
3192 if ( nMemId == 0 )
3194 table::BorderLine2 aLine;
3195 if ( lcl_extractBorderLine(rVal, aLine) )
3197 if ( !pLine )
3198 pLine = new SvxBorderLine;
3199 if( !SvxBoxItem::LineToSvxLine(aLine, *pLine, bConvert) )
3200 DELETEZ( pLine );
3201 return true;
3203 return false;
3205 else if ( rVal >>= nVal )
3207 if ( !pLine )
3208 pLine = new SvxBorderLine;
3210 switch ( nMemId )
3212 case MID_FG_COLOR: pLine->SetColor( Color(nVal) ); break;
3213 case MID_LINE_STYLE:
3214 pLine->SetBorderLineStyle(static_cast<SvxBorderStyle>(nVal));
3215 break;
3216 default:
3217 OSL_FAIL( "Wrong MemberId" );
3218 return sal_False;
3221 return true;
3224 return false;
3227 //------------------------------------------------------------------------
3229 SfxItemPresentation SvxLineItem::GetPresentation
3231 SfxItemPresentation ePres,
3232 SfxMapUnit eCoreUnit,
3233 SfxMapUnit ePresUnit,
3234 XubString& rText, const IntlWrapper *pIntl
3235 ) const
3237 rText.Erase();
3239 switch ( ePres )
3241 case SFX_ITEM_PRESENTATION_NONE:
3242 return SFX_ITEM_PRESENTATION_NONE;
3243 case SFX_ITEM_PRESENTATION_NAMELESS:
3244 case SFX_ITEM_PRESENTATION_COMPLETE:
3246 if ( pLine )
3247 rText = pLine->GetValueString( eCoreUnit, ePresUnit, pIntl,
3248 (SFX_ITEM_PRESENTATION_COMPLETE == ePres) );
3249 return ePres;
3251 default: ;//prevent warning
3253 return SFX_ITEM_PRESENTATION_NONE;
3256 // -----------------------------------------------------------------------
3258 SvStream& SvxLineItem::Store( SvStream& rStrm , sal_uInt16 /*nItemVersion*/ ) const
3260 if( pLine )
3262 rStrm << pLine->GetColor()
3263 << (short)pLine->GetOutWidth()
3264 << (short)pLine->GetInWidth()
3265 << (short)pLine->GetDistance();
3267 else
3268 rStrm << Color() << (short)0 << (short)0 << (short)0;
3269 return rStrm;
3272 // -----------------------------------------------------------------------
3274 bool SvxLineItem::ScaleMetrics( long nMult, long nDiv )
3276 if ( pLine ) pLine->ScaleMetrics( nMult, nDiv );
3277 return true;
3280 // -----------------------------------------------------------------------
3282 bool SvxLineItem::HasMetrics() const
3284 return true;
3287 // -----------------------------------------------------------------------
3289 SfxPoolItem* SvxLineItem::Create( SvStream& rStrm, sal_uInt16 ) const
3291 SvxLineItem* _pLine = new SvxLineItem( Which() );
3292 short nOutline, nInline, nDistance;
3293 Color aColor;
3295 rStrm >> aColor >> nOutline >> nInline >> nDistance;
3296 if( nOutline )
3298 SvxBorderLine aLine( &aColor );
3299 aLine.GuessLinesWidths(NONE, nOutline, nInline, nDistance);
3300 _pLine->SetLine( &aLine );
3302 return _pLine;
3305 // -----------------------------------------------------------------------
3307 void SvxLineItem::SetLine( const SvxBorderLine* pNew )
3309 delete pLine;
3310 pLine = pNew ? new SvxBorderLine( *pNew ) : 0;
3313 #ifdef _MSC_VER
3314 #pragma optimize ( "", off )
3315 #endif
3317 // class SvxBrushItem ----------------------------------------------------
3319 #define LOAD_GRAPHIC ((sal_uInt16)0x0001)
3320 #define LOAD_LINK ((sal_uInt16)0x0002)
3321 #define LOAD_FILTER ((sal_uInt16)0x0004)
3323 // class SvxBrushItem_Impl -----------------------------------------------
3325 class SvxBrushItem_Impl
3327 public:
3328 GraphicObject* pGraphicObject;
3329 sal_Int8 nGraphicTransparency; //contains a percentage value which is
3330 //copied to the GraphicObject when necessary
3331 Link aDoneLink;
3332 SvStream* pStream;
3334 SvxBrushItem_Impl( GraphicObject* p ) : pGraphicObject( p ), nGraphicTransparency(0), pStream(0) {}
3337 // -----------------------------------------------------------------------
3339 void SvxBrushItem::SetDoneLink( const Link& rLink )
3341 pImpl->aDoneLink = rLink;
3344 // -----------------------------------------------------------------------
3346 SvxBrushItem::SvxBrushItem( sal_uInt16 _nWhich ) :
3348 SfxPoolItem( _nWhich ),
3350 aColor ( COL_TRANSPARENT ),
3351 pImpl ( new SvxBrushItem_Impl( 0 ) ),
3352 pStrLink ( NULL ),
3353 pStrFilter ( NULL ),
3354 eGraphicPos ( GPOS_NONE ),
3355 bLoadAgain ( sal_True )
3360 // -----------------------------------------------------------------------
3362 SvxBrushItem::SvxBrushItem( const Color& rColor, sal_uInt16 _nWhich) :
3364 SfxPoolItem( _nWhich ),
3366 aColor ( rColor ),
3367 pImpl ( new SvxBrushItem_Impl( 0 ) ),
3368 pStrLink ( NULL ),
3369 pStrFilter ( NULL ),
3370 eGraphicPos ( GPOS_NONE ),
3371 bLoadAgain ( sal_True )
3376 // -----------------------------------------------------------------------
3378 SvxBrushItem::SvxBrushItem( const Graphic& rGraphic, SvxGraphicPosition ePos,
3379 sal_uInt16 _nWhich ) :
3381 SfxPoolItem( _nWhich ),
3383 aColor ( COL_TRANSPARENT ),
3384 pImpl ( new SvxBrushItem_Impl( new GraphicObject( rGraphic ) ) ),
3385 pStrLink ( NULL ),
3386 pStrFilter ( NULL ),
3387 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3388 bLoadAgain ( sal_True )
3391 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3394 // -----------------------------------------------------------------------
3396 SvxBrushItem::SvxBrushItem( const GraphicObject& rGraphicObj,
3397 SvxGraphicPosition ePos, sal_uInt16 _nWhich ) :
3399 SfxPoolItem( _nWhich ),
3401 aColor ( COL_TRANSPARENT ),
3402 pImpl ( new SvxBrushItem_Impl( new GraphicObject( rGraphicObj ) ) ),
3403 pStrLink ( NULL ),
3404 pStrFilter ( NULL ),
3405 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3406 bLoadAgain ( sal_True )
3409 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3412 // -----------------------------------------------------------------------
3414 SvxBrushItem::SvxBrushItem(
3415 const String& rLink, const String& rFilter,
3416 SvxGraphicPosition ePos, sal_uInt16 _nWhich ) :
3418 SfxPoolItem( _nWhich ),
3420 aColor ( COL_TRANSPARENT ),
3421 pImpl ( new SvxBrushItem_Impl( NULL ) ),
3422 pStrLink ( new String( rLink ) ),
3423 pStrFilter ( new String( rFilter ) ),
3424 eGraphicPos ( ( GPOS_NONE != ePos ) ? ePos : GPOS_MM ),
3425 bLoadAgain ( sal_True )
3428 DBG_ASSERT( GPOS_NONE != ePos, "SvxBrushItem-Ctor with GPOS_NONE == ePos" );
3431 // -----------------------------------------------------------------------
3433 SvxBrushItem::SvxBrushItem( SvStream& rStream, sal_uInt16 nVersion,
3434 sal_uInt16 _nWhich ) :
3436 SfxPoolItem( _nWhich ),
3438 aColor ( COL_TRANSPARENT ),
3439 pImpl ( new SvxBrushItem_Impl( NULL ) ),
3440 pStrLink ( NULL ),
3441 pStrFilter ( NULL ),
3442 eGraphicPos ( GPOS_NONE )
3445 sal_Bool bTrans;
3446 Color aTempColor;
3447 Color aTempFillColor;
3448 sal_Int8 nStyle;
3450 rStream >> bTrans;
3451 rStream >> aTempColor;
3452 rStream >> aTempFillColor;
3453 rStream >> nStyle;
3455 switch ( nStyle )
3457 case 8://BRUSH_25:
3459 sal_uInt32 nRed = aTempColor.GetRed();
3460 sal_uInt32 nGreen = aTempColor.GetGreen();
3461 sal_uInt32 nBlue = aTempColor.GetBlue();
3462 nRed += (sal_uInt32)(aTempFillColor.GetRed())*2;
3463 nGreen += (sal_uInt32)(aTempFillColor.GetGreen())*2;
3464 nBlue += (sal_uInt32)(aTempFillColor.GetBlue())*2;
3465 aColor = Color( (sal_Int8)(nRed/3), (sal_Int8)(nGreen/3), (sal_Int8)(nBlue/3) );
3467 break;
3469 case 9://BRUSH_50:
3471 sal_uInt32 nRed = aTempColor.GetRed();
3472 sal_uInt32 nGreen = aTempColor.GetGreen();
3473 sal_uInt32 nBlue = aTempColor.GetBlue();
3474 nRed += (sal_uInt32)(aTempFillColor.GetRed());
3475 nGreen += (sal_uInt32)(aTempFillColor.GetGreen());
3476 nBlue += (sal_uInt32)(aTempFillColor.GetBlue());
3477 aColor = Color( (sal_Int8)(nRed/2), (sal_Int8)(nGreen/2), (sal_Int8)(nBlue/2) );
3479 break;
3481 case 10://BRUSH_75:
3483 sal_uInt32 nRed = aTempColor.GetRed()*2;
3484 sal_uInt32 nGreen = aTempColor.GetGreen()*2;
3485 sal_uInt32 nBlue = aTempColor.GetBlue()*2;
3486 nRed += (sal_uInt32)(aTempFillColor.GetRed());
3487 nGreen += (sal_uInt32)(aTempFillColor.GetGreen());
3488 nBlue += (sal_uInt32)(aTempFillColor.GetBlue());
3489 aColor = Color( (sal_Int8)(nRed/3), (sal_Int8)(nGreen/3), (sal_Int8)(nBlue/3) );
3491 break;
3493 case 0://BRUSH_NULL:
3494 aColor = Color( COL_TRANSPARENT );
3495 break;
3497 default:
3498 aColor = aTempColor;
3501 if ( nVersion >= BRUSH_GRAPHIC_VERSION )
3503 sal_uInt16 nDoLoad = 0;
3504 sal_Int8 nPos;
3506 rStream >> nDoLoad;
3508 if ( nDoLoad & LOAD_GRAPHIC )
3510 Graphic aGraphic;
3512 rStream >> aGraphic;
3513 pImpl->pGraphicObject = new GraphicObject( aGraphic );
3515 if( SVSTREAM_FILEFORMAT_ERROR == rStream.GetError() )
3517 rStream.ResetError();
3518 rStream.SetError( ERRCODE_SVX_GRAPHIC_WRONG_FILEFORMAT|
3519 ERRCODE_WARNING_MASK );
3523 if ( nDoLoad & LOAD_LINK )
3525 // UNICODE: rStream >> aRel;
3526 String aRel = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
3528 // TODO/MBA: how can we get a BaseURL here?!
3529 OSL_FAIL("No BaseURL!");
3530 String aAbs = INetURLObject::GetAbsURL( String(), aRel );
3531 DBG_ASSERT( aAbs.Len(), "Invalid URL!" );
3532 pStrLink = new String( aAbs );
3535 if ( nDoLoad & LOAD_FILTER )
3537 pStrFilter = new String;
3538 // UNICODE: rStream >> *pStrFilter;
3539 *pStrFilter = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
3542 rStream >> nPos;
3544 eGraphicPos = (SvxGraphicPosition)nPos;
3548 // -----------------------------------------------------------------------
3550 SvxBrushItem::SvxBrushItem( const SvxBrushItem& rItem ) :
3552 SfxPoolItem( rItem.Which() ),
3554 pImpl ( new SvxBrushItem_Impl( NULL ) ),
3555 pStrLink ( NULL ),
3556 pStrFilter ( NULL ),
3557 eGraphicPos ( GPOS_NONE ),
3558 bLoadAgain ( sal_True )
3561 *this = rItem;
3564 // -----------------------------------------------------------------------
3566 SvxBrushItem::~SvxBrushItem()
3568 delete pImpl->pGraphicObject;
3569 delete pImpl;
3570 delete pStrLink;
3571 delete pStrFilter;
3574 // -----------------------------------------------------------------------
3576 sal_uInt16 SvxBrushItem::GetVersion( sal_uInt16 /*nFileVersion*/ ) const
3578 return BRUSH_GRAPHIC_VERSION;
3581 // -----------------------------------------------------------------------
3582 static inline sal_Int8 lcl_PercentToTransparency(long nPercent)
3584 //0xff must not be returned!
3585 return sal_Int8(nPercent ? (50 + 0xfe * nPercent) / 100 : 0);
3587 static inline sal_Int8 lcl_TransparencyToPercent(sal_Int32 nTrans)
3589 return (sal_Int8)((nTrans * 100 + 127) / 254);
3592 bool SvxBrushItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
3594 nMemberId &= ~CONVERT_TWIPS;
3595 switch( nMemberId)
3597 case MID_BACK_COLOR:
3598 rVal <<= (sal_Int32)( aColor.GetColor() );
3599 break;
3600 case MID_BACK_COLOR_R_G_B:
3601 rVal <<= (sal_Int32)( aColor.GetRGBColor() );
3602 break;
3603 case MID_BACK_COLOR_TRANSPARENCY:
3604 rVal <<= lcl_TransparencyToPercent(aColor.GetTransparency());
3605 break;
3606 case MID_GRAPHIC_POSITION:
3607 rVal <<= (style::GraphicLocation)(sal_Int16)eGraphicPos;
3608 break;
3610 case MID_GRAPHIC:
3611 SAL_WARN( "editeng.items", "not implemented" );
3612 break;
3614 case MID_GRAPHIC_TRANSPARENT:
3615 rVal = Bool2Any( aColor.GetTransparency() == 0xff );
3616 break;
3618 case MID_GRAPHIC_URL:
3620 OUString sLink;
3621 if ( pStrLink )
3622 sLink = *pStrLink;
3623 else if( pImpl->pGraphicObject )
3625 OUString sPrefix(
3626 UNO_NAME_GRAPHOBJ_URLPREFIX);
3627 OUString sId(rtl::OStringToOUString(
3628 pImpl->pGraphicObject->GetUniqueID(),
3629 RTL_TEXTENCODING_ASCII_US));
3630 sLink = sPrefix + sId;
3632 rVal <<= sLink;
3634 break;
3636 case MID_GRAPHIC_FILTER:
3638 OUString sFilter;
3639 if ( pStrFilter )
3640 sFilter = *pStrFilter;
3641 rVal <<= sFilter;
3643 break;
3644 case MID_GRAPHIC_TRANSPARENCY :
3645 rVal <<= pImpl->nGraphicTransparency;
3646 break;
3649 return true;
3652 // -----------------------------------------------------------------------
3654 bool SvxBrushItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
3656 nMemberId &= ~CONVERT_TWIPS;
3657 switch( nMemberId)
3659 case MID_BACK_COLOR:
3660 case MID_BACK_COLOR_R_G_B:
3662 sal_Int32 nCol = 0;
3663 if ( !( rVal >>= nCol ) )
3664 return sal_False;
3665 if(MID_BACK_COLOR_R_G_B == nMemberId)
3667 nCol = COLORDATA_RGB( nCol );
3668 nCol += aColor.GetColor() & 0xff000000;
3670 aColor = Color( nCol );
3672 break;
3673 case MID_BACK_COLOR_TRANSPARENCY:
3675 sal_Int32 nTrans = 0;
3676 if ( !( rVal >>= nTrans ) || nTrans < 0 || nTrans > 100 )
3677 return sal_False;
3678 aColor.SetTransparency(lcl_PercentToTransparency(nTrans));
3680 break;
3682 case MID_GRAPHIC_POSITION:
3684 style::GraphicLocation eLocation;
3685 if ( !( rVal>>=eLocation ) )
3687 sal_Int32 nValue = 0;
3688 if ( !( rVal >>= nValue ) )
3689 return sal_False;
3690 eLocation = (style::GraphicLocation)nValue;
3692 SetGraphicPos( (SvxGraphicPosition)(sal_uInt16)eLocation );
3694 break;
3696 case MID_GRAPHIC:
3697 SAL_WARN( "editeng.items", "not implemented" );
3698 break;
3700 case MID_GRAPHIC_TRANSPARENT:
3701 aColor.SetTransparency( Any2Bool( rVal ) ? 0xff : 0 );
3702 break;
3704 case MID_GRAPHIC_URL:
3706 if ( rVal.getValueType() == ::getCppuType( (OUString*)0 ) )
3708 OUString sLink;
3709 rVal >>= sLink;
3710 if( 0 == sLink.compareToAscii( UNO_NAME_GRAPHOBJ_URLPKGPREFIX,
3711 sizeof(UNO_NAME_GRAPHOBJ_URLPKGPREFIX)-1 ) )
3713 OSL_FAIL( "package urls aren't implemented" );
3715 else if( 0 == sLink.compareToAscii( UNO_NAME_GRAPHOBJ_URLPREFIX,
3716 sizeof(UNO_NAME_GRAPHOBJ_URLPREFIX)-1 ) )
3718 DELETEZ( pStrLink );
3719 String sTmp( sLink );
3720 rtl::OString sId(rtl::OUStringToOString(sTmp.Copy(
3721 sizeof(UNO_NAME_GRAPHOBJ_URLPREFIX)-1),
3722 RTL_TEXTENCODING_ASCII_US));
3723 GraphicObject *pOldGrfObj = pImpl->pGraphicObject;
3724 pImpl->pGraphicObject = new GraphicObject( sId );
3725 ApplyGraphicTransparency_Impl();
3726 delete pOldGrfObj;
3728 else
3730 SetGraphicLink(sLink);
3732 if ( !sLink.isEmpty() && eGraphicPos == GPOS_NONE )
3733 eGraphicPos = GPOS_MM;
3734 else if( sLink.isEmpty() )
3735 eGraphicPos = GPOS_NONE;
3738 break;
3740 case MID_GRAPHIC_FILTER:
3742 if( rVal.getValueType() == ::getCppuType( (OUString*)0 ) )
3744 OUString sLink;
3745 rVal >>= sLink;
3746 SetGraphicFilter( sLink );
3749 break;
3750 case MID_GRAPHIC_TRANSPARENCY :
3752 sal_Int32 nTmp = 0;
3753 rVal >>= nTmp;
3754 if(nTmp >= 0 && nTmp <= 100)
3756 pImpl->nGraphicTransparency = sal_Int8(nTmp);
3757 if(pImpl->pGraphicObject)
3758 ApplyGraphicTransparency_Impl();
3761 break;
3764 return true;
3767 // -----------------------------------------------------------------------
3769 SfxItemPresentation SvxBrushItem::GetPresentation
3771 SfxItemPresentation ePres,
3772 SfxMapUnit /*eCoreUnit*/,
3773 SfxMapUnit /*ePresUnit*/,
3774 XubString& rText, const IntlWrapper *
3775 ) const
3777 switch ( ePres )
3779 case SFX_ITEM_PRESENTATION_NONE:
3780 rText.Erase();
3781 return ePres;
3783 case SFX_ITEM_PRESENTATION_NAMELESS:
3784 case SFX_ITEM_PRESENTATION_COMPLETE:
3786 if ( GPOS_NONE == eGraphicPos )
3788 rText = ::GetColorString( aColor );
3789 rText += cpDelim;
3790 sal_uInt16 nId = RID_SVXITEMS_TRANSPARENT_FALSE;
3792 if ( aColor.GetTransparency() )
3793 nId = RID_SVXITEMS_TRANSPARENT_TRUE;
3794 rText += EE_RESSTR(nId);
3796 else
3798 rText = EE_RESSTR(RID_SVXITEMS_GRAPHIC);
3801 return ePres;
3803 default: ;//prevent warning
3806 return SFX_ITEM_PRESENTATION_NONE;
3809 // -----------------------------------------------------------------------
3811 SvxBrushItem& SvxBrushItem::operator=( const SvxBrushItem& rItem )
3813 aColor = rItem.aColor;
3814 eGraphicPos = rItem.eGraphicPos;
3816 DELETEZ( pImpl->pGraphicObject );
3817 DELETEZ( pStrLink );
3818 DELETEZ( pStrFilter );
3820 if ( GPOS_NONE != eGraphicPos )
3822 if ( rItem.pStrLink )
3823 pStrLink = new String( *rItem.pStrLink );
3824 if ( rItem.pStrFilter )
3825 pStrFilter = new String( *rItem.pStrFilter );
3826 if ( rItem.pImpl->pGraphicObject )
3828 pImpl->pGraphicObject = new GraphicObject( *rItem.pImpl->pGraphicObject );
3831 pImpl->nGraphicTransparency = rItem.pImpl->nGraphicTransparency;
3832 return *this;
3835 // -----------------------------------------------------------------------
3837 int SvxBrushItem::operator==( const SfxPoolItem& rAttr ) const
3839 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
3841 SvxBrushItem& rCmp = (SvxBrushItem&)rAttr;
3842 sal_Bool bEqual = ( aColor == rCmp.aColor && eGraphicPos == rCmp.eGraphicPos &&
3843 pImpl->nGraphicTransparency == rCmp.pImpl->nGraphicTransparency);
3845 if ( bEqual )
3847 if ( GPOS_NONE != eGraphicPos )
3849 if ( !rCmp.pStrLink )
3850 bEqual = !pStrLink;
3851 else
3852 bEqual = pStrLink && ( *pStrLink == *rCmp.pStrLink );
3854 if ( bEqual )
3856 if ( !rCmp.pStrFilter )
3857 bEqual = !pStrFilter;
3858 else
3859 bEqual = pStrFilter && ( *pStrFilter == *rCmp.pStrFilter );
3862 if ( bEqual && !rCmp.pStrLink )
3864 if ( !rCmp.pImpl->pGraphicObject )
3865 bEqual = !pImpl->pGraphicObject;
3866 else
3867 bEqual = pImpl->pGraphicObject &&
3868 ( *pImpl->pGraphicObject == *rCmp.pImpl->pGraphicObject );
3873 return bEqual;
3876 // -----------------------------------------------------------------------
3878 SfxPoolItem* SvxBrushItem::Clone( SfxItemPool* ) const
3880 return new SvxBrushItem( *this );
3883 // -----------------------------------------------------------------------
3885 SfxPoolItem* SvxBrushItem::Create( SvStream& rStream, sal_uInt16 nVersion ) const
3887 return new SvxBrushItem( rStream, nVersion, Which() );
3890 // -----------------------------------------------------------------------
3892 SvStream& SvxBrushItem::Store( SvStream& rStream , sal_uInt16 /*nItemVersion*/ ) const
3894 rStream << (sal_Bool)sal_False;
3895 rStream << aColor;
3896 rStream << aColor;
3897 rStream << (sal_Int8)(aColor.GetTransparency() > 0 ? 0 : 1); //BRUSH_NULL : BRUSH_SOLID
3899 sal_uInt16 nDoLoad = 0;
3901 if ( pImpl->pGraphicObject && !pStrLink )
3902 nDoLoad |= LOAD_GRAPHIC;
3903 if ( pStrLink )
3904 nDoLoad |= LOAD_LINK;
3905 if ( pStrFilter )
3906 nDoLoad |= LOAD_FILTER;
3907 rStream << nDoLoad;
3909 if ( pImpl->pGraphicObject && !pStrLink )
3910 rStream << pImpl->pGraphicObject->GetGraphic();
3911 if ( pStrLink )
3913 OSL_FAIL("No BaseURL!");
3914 // TODO/MBA: how to get a BaseURL?!
3915 String aRel = INetURLObject::GetRelURL( String(), *pStrLink );
3916 // UNICODE: rStream << aRel;
3917 rStream.WriteUniOrByteString(aRel, rStream.GetStreamCharSet());
3919 if ( pStrFilter )
3921 // UNICODE: rStream << *pStrFilter;
3922 rStream.WriteUniOrByteString(*pStrFilter, rStream.GetStreamCharSet());
3924 rStream << (sal_Int8)eGraphicPos;
3925 return rStream;
3928 // -----------------------------------------------------------------------
3930 void SvxBrushItem::PurgeMedium() const
3932 DELETEZ( pImpl->pStream );
3935 // -----------------------------------------------------------------------
3936 const GraphicObject* SvxBrushItem::GetGraphicObject() const
3938 if ( bLoadAgain && pStrLink && !pImpl->pGraphicObject )
3939 // when graphics already loaded, use as a cache
3941 // only with "valid" names - empty names now allowed
3942 if( pStrLink->Len() )
3944 pImpl->pStream = utl::UcbStreamHelper::CreateStream( *pStrLink, STREAM_STD_READ );
3945 if( pImpl->pStream && !pImpl->pStream->GetError() )
3947 Graphic aGraphic;
3948 int nRes;
3949 pImpl->pStream->Seek( STREAM_SEEK_TO_BEGIN );
3950 nRes = GraphicFilter::GetGraphicFilter().
3951 ImportGraphic( aGraphic, *pStrLink, *pImpl->pStream,
3952 GRFILTER_FORMAT_DONTKNOW, NULL, GRFILTER_I_FLAGS_DONT_SET_LOGSIZE_FOR_JPEG );
3954 if( nRes != GRFILTER_OK )
3956 const_cast < SvxBrushItem*> (this)->bLoadAgain = sal_False;
3958 else
3960 pImpl->pGraphicObject = new GraphicObject;
3961 pImpl->pGraphicObject->SetGraphic( aGraphic );
3962 const_cast < SvxBrushItem*> (this)->ApplyGraphicTransparency_Impl();
3965 else
3967 const_cast < SvxBrushItem*> (this)->bLoadAgain = sal_False;
3972 return pImpl->pGraphicObject;
3975 // -----------------------------------------------------------------------
3977 const Graphic* SvxBrushItem::GetGraphic() const
3979 const GraphicObject* pGrafObj = GetGraphicObject();
3980 return( pGrafObj ? &( pGrafObj->GetGraphic() ) : NULL );
3983 // -----------------------------------------------------------------------
3985 void SvxBrushItem::SetGraphicPos( SvxGraphicPosition eNew )
3987 eGraphicPos = eNew;
3989 if ( GPOS_NONE == eGraphicPos )
3991 DELETEZ( pImpl->pGraphicObject );
3992 DELETEZ( pStrLink );
3993 DELETEZ( pStrFilter );
3995 else
3997 if ( !pImpl->pGraphicObject && !pStrLink )
3999 pImpl->pGraphicObject = new GraphicObject; // Creating a dummy
4004 // -----------------------------------------------------------------------
4006 void SvxBrushItem::SetGraphic( const Graphic& rNew )
4008 if ( !pStrLink )
4010 if ( pImpl->pGraphicObject )
4011 pImpl->pGraphicObject->SetGraphic( rNew );
4012 else
4013 pImpl->pGraphicObject = new GraphicObject( rNew );
4015 ApplyGraphicTransparency_Impl();
4017 if ( GPOS_NONE == eGraphicPos )
4018 eGraphicPos = GPOS_MM; // None would be brush, then Default: middle
4020 else
4022 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
4026 // -----------------------------------------------------------------------
4028 void SvxBrushItem::SetGraphicObject( const GraphicObject& rNewObj )
4030 if ( !pStrLink )
4032 if ( pImpl->pGraphicObject )
4033 *pImpl->pGraphicObject = rNewObj;
4034 else
4035 pImpl->pGraphicObject = new GraphicObject( rNewObj );
4037 ApplyGraphicTransparency_Impl();
4039 if ( GPOS_NONE == eGraphicPos )
4040 eGraphicPos = GPOS_MM; // None would be brush, then Default: middle
4042 else
4044 OSL_FAIL( "SetGraphic() on linked graphic! :-/" );
4048 // -----------------------------------------------------------------------
4050 void SvxBrushItem::SetGraphicLink( const String& rNew )
4052 if ( !rNew.Len() )
4053 DELETEZ( pStrLink );
4054 else
4056 if ( pStrLink )
4057 *pStrLink = rNew;
4058 else
4059 pStrLink = new String( rNew );
4061 DELETEZ( pImpl->pGraphicObject );
4065 // -----------------------------------------------------------------------
4067 void SvxBrushItem::SetGraphicFilter( const String& rNew )
4069 if ( !rNew.Len() )
4070 DELETEZ( pStrFilter );
4071 else
4073 if ( pStrFilter )
4074 *pStrFilter = rNew;
4075 else
4076 pStrFilter = new String( rNew );
4080 //static
4081 SvxGraphicPosition SvxBrushItem::WallpaperStyle2GraphicPos( WallpaperStyle eStyle )
4083 SvxGraphicPosition eResult;
4084 // The switch is not the fastest, but the safest
4085 switch( eStyle )
4087 case WALLPAPER_NULL: eResult = GPOS_NONE; break;
4088 case WALLPAPER_TILE: eResult = GPOS_TILED; break;
4089 case WALLPAPER_CENTER: eResult = GPOS_MM; break;
4090 case WALLPAPER_SCALE: eResult = GPOS_AREA; break;
4091 case WALLPAPER_TOPLEFT: eResult = GPOS_LT; break;
4092 case WALLPAPER_TOP: eResult = GPOS_MT; break;
4093 case WALLPAPER_TOPRIGHT: eResult = GPOS_RT; break;
4094 case WALLPAPER_LEFT: eResult = GPOS_LM; break;
4095 case WALLPAPER_RIGHT: eResult = GPOS_RM; break;
4096 case WALLPAPER_BOTTOMLEFT: eResult = GPOS_LB; break;
4097 case WALLPAPER_BOTTOM: eResult = GPOS_MB; break;
4098 case WALLPAPER_BOTTOMRIGHT: eResult = GPOS_RB; break;
4099 default: eResult = GPOS_NONE;
4101 return eResult;
4104 //static
4105 WallpaperStyle SvxBrushItem::GraphicPos2WallpaperStyle( SvxGraphicPosition ePos )
4107 WallpaperStyle eResult;
4108 switch( ePos )
4110 case GPOS_NONE: eResult = WALLPAPER_NULL; break;
4111 case GPOS_TILED: eResult = WALLPAPER_TILE; break;
4112 case GPOS_MM: eResult = WALLPAPER_CENTER; break;
4113 case GPOS_AREA: eResult = WALLPAPER_SCALE; break;
4114 case GPOS_LT: eResult = WALLPAPER_TOPLEFT; break;
4115 case GPOS_MT: eResult = WALLPAPER_TOP; break;
4116 case GPOS_RT: eResult = WALLPAPER_TOPRIGHT; break;
4117 case GPOS_LM: eResult = WALLPAPER_LEFT; break;
4118 case GPOS_RM: eResult = WALLPAPER_RIGHT; break;
4119 case GPOS_LB: eResult = WALLPAPER_BOTTOMLEFT; break;
4120 case GPOS_MB: eResult = WALLPAPER_BOTTOM; break;
4121 case GPOS_RB: eResult = WALLPAPER_BOTTOMRIGHT; break;
4122 default: eResult = WALLPAPER_NULL;
4124 return eResult;
4127 SvxBrushItem::SvxBrushItem( const CntWallpaperItem& rItem, sal_uInt16 _nWhich ) :
4128 SfxPoolItem( _nWhich ),
4129 pImpl( new SvxBrushItem_Impl( 0 ) ),
4130 pStrLink(0),
4131 pStrFilter(0),
4132 bLoadAgain( sal_True )
4134 aColor = rItem.GetColor();
4136 if (!rItem.GetBitmapURL().isEmpty())
4138 pStrLink = new String( rItem.GetBitmapURL() );
4139 SetGraphicPos( WallpaperStyle2GraphicPos((WallpaperStyle)rItem.GetStyle() ) );
4143 #ifdef _MSC_VER
4144 #pragma optimize ( "", on )
4145 #endif
4147 void SvxBrushItem::ApplyGraphicTransparency_Impl()
4149 DBG_ASSERT(pImpl->pGraphicObject, "no GraphicObject available" );
4150 if(pImpl->pGraphicObject)
4152 GraphicAttr aAttr(pImpl->pGraphicObject->GetAttr());
4153 aAttr.SetTransparency(lcl_PercentToTransparency(
4154 pImpl->nGraphicTransparency));
4155 pImpl->pGraphicObject->SetAttr(aAttr);
4158 // class SvxFrameDirectionItem ----------------------------------------------
4160 SvxFrameDirectionItem::SvxFrameDirectionItem( SvxFrameDirection nValue ,
4161 sal_uInt16 _nWhich )
4162 : SfxUInt16Item( _nWhich, (sal_uInt16)nValue )
4166 SvxFrameDirectionItem::~SvxFrameDirectionItem()
4170 int SvxFrameDirectionItem::operator==( const SfxPoolItem& rCmp ) const
4172 DBG_ASSERT( SfxPoolItem::operator==(rCmp), "unequal types" );
4174 return GetValue() == ((SvxFrameDirectionItem&)rCmp).GetValue();
4177 SfxPoolItem* SvxFrameDirectionItem::Clone( SfxItemPool * ) const
4179 return new SvxFrameDirectionItem( *this );
4182 SfxPoolItem* SvxFrameDirectionItem::Create( SvStream & rStrm, sal_uInt16 /*nVer*/ ) const
4184 sal_uInt16 nValue;
4185 rStrm >> nValue;
4186 return new SvxFrameDirectionItem( (SvxFrameDirection)nValue, Which() );
4189 SvStream& SvxFrameDirectionItem::Store( SvStream & rStrm, sal_uInt16 /*nIVer*/ ) const
4191 sal_uInt16 nValue = GetValue();
4192 rStrm << nValue;
4193 return rStrm;
4196 sal_uInt16 SvxFrameDirectionItem::GetVersion( sal_uInt16 nFVer ) const
4198 return SOFFICE_FILEFORMAT_50 > nFVer ? USHRT_MAX : 0;
4201 SfxItemPresentation SvxFrameDirectionItem::GetPresentation(
4202 SfxItemPresentation ePres,
4203 SfxMapUnit /*eCoreUnit*/,
4204 SfxMapUnit /*ePresUnit*/,
4205 XubString& rText, const IntlWrapper *) const
4207 SfxItemPresentation eRet = ePres;
4208 switch( ePres )
4210 case SFX_ITEM_PRESENTATION_NONE:
4211 rText.Erase();
4212 break;
4214 case SFX_ITEM_PRESENTATION_NAMELESS:
4215 case SFX_ITEM_PRESENTATION_COMPLETE:
4216 rText = EE_RESSTR( RID_SVXITEMS_FRMDIR_BEGIN + GetValue() );
4217 break;
4219 default:
4220 eRet = SFX_ITEM_PRESENTATION_NONE;
4222 return eRet;
4225 bool SvxFrameDirectionItem::PutValue( const com::sun::star::uno::Any& rVal,
4226 sal_uInt8 )
4228 sal_Int16 nVal = sal_Int16();
4229 sal_Bool bRet = ( rVal >>= nVal );
4230 if( bRet )
4232 // translate WritingDirection2 constants into SvxFrameDirection
4233 switch( nVal )
4235 case text::WritingMode2::LR_TB:
4236 SetValue( FRMDIR_HORI_LEFT_TOP );
4237 break;
4238 case text::WritingMode2::RL_TB:
4239 SetValue( FRMDIR_HORI_RIGHT_TOP );
4240 break;
4241 case text::WritingMode2::TB_RL:
4242 SetValue( FRMDIR_VERT_TOP_RIGHT );
4243 break;
4244 case text::WritingMode2::TB_LR:
4245 SetValue( FRMDIR_VERT_TOP_LEFT );
4246 break;
4247 case text::WritingMode2::PAGE:
4248 SetValue( FRMDIR_ENVIRONMENT );
4249 break;
4250 default:
4251 bRet = false;
4252 break;
4256 return bRet;
4259 bool SvxFrameDirectionItem::QueryValue( com::sun::star::uno::Any& rVal,
4260 sal_uInt8 ) const
4262 // translate SvxFrameDirection into WritingDirection2
4263 sal_Int16 nVal;
4264 bool bRet = true;
4265 switch( GetValue() )
4267 case FRMDIR_HORI_LEFT_TOP:
4268 nVal = text::WritingMode2::LR_TB;
4269 break;
4270 case FRMDIR_HORI_RIGHT_TOP:
4271 nVal = text::WritingMode2::RL_TB;
4272 break;
4273 case FRMDIR_VERT_TOP_RIGHT:
4274 nVal = text::WritingMode2::TB_RL;
4275 break;
4276 case FRMDIR_VERT_TOP_LEFT:
4277 nVal = text::WritingMode2::TB_LR;
4278 break;
4279 case FRMDIR_ENVIRONMENT:
4280 nVal = text::WritingMode2::PAGE;
4281 break;
4282 default:
4283 OSL_FAIL("Unknown SvxFrameDirection value!");
4284 bRet = false;
4285 break;
4288 // return value + error state
4289 if( bRet )
4291 rVal <<= nVal;
4293 return bRet;
4296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */