Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / core / data / attrib.cxx
blob71d9caee6778b36aa511547feab4464bbb3b10b3
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/util/CellProtection.hpp>
21 #include <com/sun/star/util/XProtectable.hpp>
22 #include <com/sun/star/text/XText.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include "scitems.hxx"
26 #include <editeng/eeitem.hxx>
28 #include <editeng/boxitem.hxx>
29 #include <editeng/editdata.hxx>
30 #include <editeng/editeng.hxx>
31 #include <editeng/editobj.hxx>
32 #include <editeng/flditem.hxx>
34 #include "attrib.hxx"
35 #include "global.hxx"
36 #include "editutil.hxx"
37 #include "sc.hrc"
38 #include "globstr.hrc"
40 #include "textuno.hxx"
42 using namespace com::sun::star;
44 //------------------------------------------------------------------------
46 TYPEINIT1(ScMergeAttr, SfxPoolItem);
47 TYPEINIT1_AUTOFACTORY(ScProtectionAttr, SfxPoolItem);
48 TYPEINIT1(ScRangeItem, SfxPoolItem);
49 TYPEINIT1(ScTableListItem, SfxPoolItem);
50 TYPEINIT1(ScPageHFItem, SfxPoolItem);
51 TYPEINIT1(ScViewObjectModeItem, SfxEnumItem);
52 TYPEINIT1(ScDoubleItem, SfxPoolItem);
53 TYPEINIT1(ScPageScaleToItem, SfxPoolItem);
54 TYPEINIT1(ScCondFormatItem, SfxPoolItem);
56 //------------------------------------------------------------------------
59 // General Help Function
62 bool ScHasPriority( const ::editeng::SvxBorderLine* pThis, const ::editeng::SvxBorderLine* pOther )
65 if (!pThis)
66 return false;
67 if (!pOther)
68 return true;
70 sal_uInt16 nThisSize = pThis->GetScaledWidth();
71 sal_uInt16 nOtherSize = pOther->GetScaledWidth();
73 if (nThisSize > nOtherSize)
74 return true;
75 else if (nThisSize < nOtherSize)
76 return false;
77 else
79 if ( pOther->GetInWidth() && !pThis->GetInWidth() )
80 return true;
81 else if ( pThis->GetInWidth() && !pOther->GetInWidth() )
82 return false;
83 else
85 return true; //! ???
92 // Item - Implementierungen
95 //------------------------------------------------------------------------
96 // Merge
97 //------------------------------------------------------------------------
99 ScMergeAttr::ScMergeAttr():
100 SfxPoolItem(ATTR_MERGE),
101 nColMerge(0),
102 nRowMerge(0)
105 //------------------------------------------------------------------------
107 ScMergeAttr::ScMergeAttr( SCsCOL nCol, SCsROW nRow):
108 SfxPoolItem(ATTR_MERGE),
109 nColMerge(nCol),
110 nRowMerge(nRow)
113 //------------------------------------------------------------------------
115 ScMergeAttr::ScMergeAttr(const ScMergeAttr& rItem):
116 SfxPoolItem(ATTR_MERGE)
118 nColMerge = rItem.nColMerge;
119 nRowMerge = rItem.nRowMerge;
122 ScMergeAttr::~ScMergeAttr()
126 //------------------------------------------------------------------------
128 OUString ScMergeAttr::GetValueText() const
130 OUString aRet = "("
131 + OUString::number(static_cast<sal_Int32>(nColMerge))
132 + ","
133 + OUString::number(static_cast<sal_Int32>(nRowMerge))
134 + ")";
135 return aRet;
138 //------------------------------------------------------------------------
140 int ScMergeAttr::operator==( const SfxPoolItem& rItem ) const
142 OSL_ENSURE( Which() != rItem.Which() || Type() == rItem.Type(), "which ==, type !=" );
143 return (Which() == rItem.Which())
144 && (nColMerge == ((ScMergeAttr&)rItem).nColMerge)
145 && (nRowMerge == ((ScMergeAttr&)rItem).nRowMerge);
148 //------------------------------------------------------------------------
150 SfxPoolItem* ScMergeAttr::Clone( SfxItemPool * ) const
152 return new ScMergeAttr(*this);
155 //------------------------------------------------------------------------
157 SfxPoolItem* ScMergeAttr::Create( SvStream& rStream, sal_uInt16 /* nVer */ ) const
159 sal_Int16 nCol;
160 sal_Int16 nRow;
161 rStream >> nCol;
162 rStream >> nRow;
163 return new ScMergeAttr(static_cast<SCCOL>(nCol),static_cast<SCROW>(nRow));
166 //------------------------------------------------------------------------
167 // MergeFlag
168 //------------------------------------------------------------------------
170 ScMergeFlagAttr::ScMergeFlagAttr():
171 SfxInt16Item(ATTR_MERGE_FLAG, 0)
175 //------------------------------------------------------------------------
177 ScMergeFlagAttr::ScMergeFlagAttr(sal_Int16 nFlags):
178 SfxInt16Item(ATTR_MERGE_FLAG, nFlags)
182 ScMergeFlagAttr::~ScMergeFlagAttr()
186 bool ScMergeFlagAttr::HasPivotButton() const
188 return (GetValue() & SC_MF_BUTTON) != 0;
191 bool ScMergeFlagAttr::HasPivotPopupButton() const
193 return (GetValue() & SC_MF_BUTTON_POPUP) != 0;
196 //------------------------------------------------------------------------
197 // Protection
198 //------------------------------------------------------------------------
200 ScProtectionAttr::ScProtectionAttr():
201 SfxPoolItem(ATTR_PROTECTION),
202 bProtection(true),
203 bHideFormula(false),
204 bHideCell(false),
205 bHidePrint(false)
209 //------------------------------------------------------------------------
211 ScProtectionAttr::ScProtectionAttr( bool bProtect, bool bHFormula,
212 bool bHCell, bool bHPrint):
213 SfxPoolItem(ATTR_PROTECTION),
214 bProtection(bProtect),
215 bHideFormula(bHFormula),
216 bHideCell(bHCell),
217 bHidePrint(bHPrint)
221 //------------------------------------------------------------------------
223 ScProtectionAttr::ScProtectionAttr(const ScProtectionAttr& rItem):
224 SfxPoolItem(ATTR_PROTECTION)
226 bProtection = rItem.bProtection;
227 bHideFormula = rItem.bHideFormula;
228 bHideCell = rItem.bHideCell;
229 bHidePrint = rItem.bHidePrint;
232 ScProtectionAttr::~ScProtectionAttr()
236 //------------------------------------------------------------------------
238 bool ScProtectionAttr::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
240 nMemberId &= ~CONVERT_TWIPS;
241 switch ( nMemberId )
243 case 0 :
245 util::CellProtection aProtection;
246 aProtection.IsLocked = bProtection;
247 aProtection.IsFormulaHidden = bHideFormula;
248 aProtection.IsHidden = bHideCell;
249 aProtection.IsPrintHidden = bHidePrint;
250 rVal <<= aProtection;
251 break;
253 case MID_1 :
254 rVal <<= (sal_Bool ) bProtection; break;
255 case MID_2 :
256 rVal <<= (sal_Bool ) bHideFormula; break;
257 case MID_3 :
258 rVal <<= (sal_Bool ) bHideCell; break;
259 case MID_4 :
260 rVal <<= (sal_Bool ) bHidePrint; break;
261 default:
262 OSL_FAIL("Wrong MemberID!");
263 return false;
266 return true;
269 bool ScProtectionAttr::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
271 bool bRet = false;
272 sal_Bool bVal = sal_False;
273 nMemberId &= ~CONVERT_TWIPS;
274 switch ( nMemberId )
276 case 0 :
278 util::CellProtection aProtection;
279 if ( rVal >>= aProtection )
281 bProtection = aProtection.IsLocked;
282 bHideFormula = aProtection.IsFormulaHidden;
283 bHideCell = aProtection.IsHidden;
284 bHidePrint = aProtection.IsPrintHidden;
285 bRet = true;
287 else
289 OSL_FAIL("exception - wrong argument");
291 break;
293 case MID_1 :
294 bRet = (rVal >>= bVal); if (bRet) bProtection=bVal; break;
295 case MID_2 :
296 bRet = (rVal >>= bVal); if (bRet) bHideFormula=bVal; break;
297 case MID_3 :
298 bRet = (rVal >>= bVal); if (bRet) bHideCell=bVal; break;
299 case MID_4 :
300 bRet = (rVal >>= bVal); if (bRet) bHidePrint=bVal; break;
301 default:
302 OSL_FAIL("Wrong MemberID!");
305 return bRet;
308 //------------------------------------------------------------------------
310 OUString ScProtectionAttr::GetValueText() const
312 const OUString aStrYes ( ScGlobal::GetRscString(STR_YES) );
313 const OUString aStrNo ( ScGlobal::GetRscString(STR_NO) );
315 const OUString aValue = "("
316 + (bProtection ? aStrYes : aStrNo)
317 + ","
318 + (bHideFormula ? aStrYes : aStrNo)
319 + ","
320 + (bHideCell ? aStrYes : aStrNo)
321 + ","
322 + (bHidePrint ? aStrYes : aStrNo)
323 + ")";
325 return aValue;
328 //------------------------------------------------------------------------
330 SfxItemPresentation ScProtectionAttr::GetPresentation
332 SfxItemPresentation ePres,
333 SfxMapUnit /* eCoreMetric */,
334 SfxMapUnit /* ePresMetric */,
335 OUString& rText,
336 const IntlWrapper* /* pIntl */
337 ) const
339 const OUString aStrYes ( ScGlobal::GetRscString(STR_YES) );
340 const OUString aStrNo ( ScGlobal::GetRscString(STR_NO) );
342 switch ( ePres )
344 case SFX_ITEM_PRESENTATION_NONE:
345 rText = OUString();
346 break;
348 case SFX_ITEM_PRESENTATION_NAMELESS:
349 rText = GetValueText();
350 break;
352 case SFX_ITEM_PRESENTATION_COMPLETE:
353 rText = ScGlobal::GetRscString(STR_PROTECTION)
354 + ": "
355 + (bProtection ? aStrYes : aStrNo)
356 + ", "
357 + ScGlobal::GetRscString(STR_FORMULAS)
358 + ": "
359 + (!bHideFormula ? aStrYes : aStrNo)
360 + ", "
361 + ScGlobal::GetRscString(STR_HIDE)
362 + ": "
363 + (bHideCell ? aStrYes : aStrNo)
364 + ", "
365 + ScGlobal::GetRscString(STR_PRINT)
366 + ": "
367 + (!bHidePrint ? aStrYes : aStrNo);
368 break;
370 default:
371 ePres = SFX_ITEM_PRESENTATION_NONE;
374 return ePres;
377 //------------------------------------------------------------------------
379 int ScProtectionAttr::operator==( const SfxPoolItem& rItem ) const
381 OSL_ENSURE( Which() != rItem.Which() || Type() == rItem.Type(), "which ==, type !=" );
382 return (Which() == rItem.Which())
383 && (bProtection == ((ScProtectionAttr&)rItem).bProtection)
384 && (bHideFormula == ((ScProtectionAttr&)rItem).bHideFormula)
385 && (bHideCell == ((ScProtectionAttr&)rItem).bHideCell)
386 && (bHidePrint == ((ScProtectionAttr&)rItem).bHidePrint);
389 //------------------------------------------------------------------------
391 SfxPoolItem* ScProtectionAttr::Clone( SfxItemPool * ) const
393 return new ScProtectionAttr(*this);
396 //------------------------------------------------------------------------
398 SfxPoolItem* ScProtectionAttr::Create( SvStream& rStream, sal_uInt16 /* n */ ) const
400 sal_Bool bProtect;
401 sal_Bool bHFormula;
402 sal_Bool bHCell;
403 sal_Bool bHPrint;
405 rStream >> bProtect;
406 rStream >> bHFormula;
407 rStream >> bHCell;
408 rStream >> bHPrint;
410 return new ScProtectionAttr(bProtect,bHFormula,bHCell,bHPrint);
413 //------------------------------------------------------------------------
415 bool ScProtectionAttr::SetProtection( bool bProtect)
417 bProtection = bProtect;
418 return true;
421 //------------------------------------------------------------------------
423 bool ScProtectionAttr::SetHideFormula( bool bHFormula)
425 bHideFormula = bHFormula;
426 return true;
429 //------------------------------------------------------------------------
431 bool ScProtectionAttr::SetHideCell( bool bHCell)
433 bHideCell = bHCell;
434 return true;
437 //------------------------------------------------------------------------
439 bool ScProtectionAttr::SetHidePrint( bool bHPrint)
441 bHidePrint = bHPrint;
442 return true;
445 // -----------------------------------------------------------------------
446 // ScRangeItem - Tabellenbereich
447 // -----------------------------------------------------------------------
449 int ScRangeItem::operator==( const SfxPoolItem& rAttr ) const
451 OSL_ENSURE( SfxPoolItem::operator==(rAttr), "unequal types" );
453 return ( aRange == ( (ScRangeItem&)rAttr ).aRange );
456 // -----------------------------------------------------------------------
458 SfxPoolItem* ScRangeItem::Clone( SfxItemPool* ) const
460 return new ScRangeItem( *this );
463 //------------------------------------------------------------------------
465 SfxItemPresentation ScRangeItem::GetPresentation
467 SfxItemPresentation ePres,
468 SfxMapUnit /* eCoreUnit */,
469 SfxMapUnit /* ePresUnit */,
470 OUString& rText,
471 const IntlWrapper* /* pIntl */
472 ) const
474 rText = OUString();
476 switch ( ePres )
478 case SFX_ITEM_PRESENTATION_COMPLETE:
479 rText = ScGlobal::GetRscString(STR_AREA) + ": ";
480 /* !!! fall-through !!! */
482 case SFX_ITEM_PRESENTATION_NAMELESS:
484 /* Always use OOo:A1 format */
485 rText += aRange.Format();
487 break;
489 default:
491 // added to avoid warnings
495 return ePres;
498 // -----------------------------------------------------------------------
499 // ScTableListItem - List from Tables (-numbers)
500 // -----------------------------------------------------------------------
502 ScTableListItem::ScTableListItem( const ScTableListItem& rCpy )
503 : SfxPoolItem ( rCpy.Which() ),
504 nCount ( rCpy.nCount )
506 if ( nCount > 0 )
508 pTabArr = new SCTAB [nCount];
510 for ( sal_uInt16 i=0; i<nCount; i++ )
511 pTabArr[i] = rCpy.pTabArr[i];
513 else
514 pTabArr = NULL;
517 // -----------------------------------------------------------------------
520 ScTableListItem::~ScTableListItem()
522 delete [] pTabArr;
525 // -----------------------------------------------------------------------
527 ScTableListItem& ScTableListItem::operator=( const ScTableListItem& rCpy )
529 delete [] pTabArr;
531 if ( rCpy.nCount > 0 )
533 pTabArr = new SCTAB [rCpy.nCount];
534 for ( sal_uInt16 i=0; i<rCpy.nCount; i++ )
535 pTabArr[i] = rCpy.pTabArr[i];
537 else
538 pTabArr = NULL;
540 nCount = rCpy.nCount;
542 return *this;
545 // -----------------------------------------------------------------------
547 int ScTableListItem::operator==( const SfxPoolItem& rAttr ) const
549 OSL_ENSURE( SfxPoolItem::operator==(rAttr), "unequal types" );
551 ScTableListItem& rCmp = (ScTableListItem&)rAttr;
552 bool bEqual = (nCount == rCmp.nCount);
554 if ( nCount > 0 )
556 sal_uInt16 i=0;
558 bEqual = ( pTabArr && rCmp.pTabArr );
560 while ( bEqual && i<nCount )
562 bEqual = ( pTabArr[i] == rCmp.pTabArr[i] );
563 i++;
566 return bEqual;
569 // -----------------------------------------------------------------------
571 SfxPoolItem* ScTableListItem::Clone( SfxItemPool* ) const
573 return new ScTableListItem( *this );
576 //------------------------------------------------------------------------
578 SfxItemPresentation ScTableListItem::GetPresentation
580 SfxItemPresentation ePres,
581 SfxMapUnit /* eCoreUnit */,
582 SfxMapUnit /* ePresUnit */,
583 OUString& rText,
584 const IntlWrapper* /* pIntl */
585 ) const
587 switch ( ePres )
589 case SFX_ITEM_PRESENTATION_NONE:
590 rText = OUString();
591 return ePres;
593 case SFX_ITEM_PRESENTATION_NAMELESS:
595 rText = "(";
596 if ( nCount>0 && pTabArr )
597 for ( sal_uInt16 i=0; i<nCount; i++ )
599 rText += OUString::number( pTabArr[i] );
600 if ( i<(nCount-1) )
601 rText += ",";
603 rText += ")";
605 return ePres;
607 case SFX_ITEM_PRESENTATION_COMPLETE:
608 rText = OUString();
609 return SFX_ITEM_PRESENTATION_NONE;
611 default:
613 // added to avoid warnings
617 return SFX_ITEM_PRESENTATION_NONE;
621 // -----------------------------------------------------------------------
622 // ScPageHFItem - Dates from the Head and Foot lines
623 // -----------------------------------------------------------------------
625 ScPageHFItem::ScPageHFItem( sal_uInt16 nWhichP )
626 : SfxPoolItem ( nWhichP ),
627 pLeftArea ( NULL ),
628 pCenterArea ( NULL ),
629 pRightArea ( NULL )
633 //------------------------------------------------------------------------
635 ScPageHFItem::ScPageHFItem( const ScPageHFItem& rItem )
636 : SfxPoolItem ( rItem ),
637 pLeftArea ( NULL ),
638 pCenterArea ( NULL ),
639 pRightArea ( NULL )
641 if ( rItem.pLeftArea )
642 pLeftArea = rItem.pLeftArea->Clone();
643 if ( rItem.pCenterArea )
644 pCenterArea = rItem.pCenterArea->Clone();
645 if ( rItem.pRightArea )
646 pRightArea = rItem.pRightArea->Clone();
649 //------------------------------------------------------------------------
651 ScPageHFItem::~ScPageHFItem()
653 delete pLeftArea;
654 delete pCenterArea;
655 delete pRightArea;
658 //------------------------------------------------------------------------
660 bool ScPageHFItem::QueryValue( uno::Any& rVal, sal_uInt8 /* nMemberId */ ) const
662 uno::Reference<sheet::XHeaderFooterContent> xContent =
663 new ScHeaderFooterContentObj( pLeftArea, pCenterArea, pRightArea );
665 rVal <<= xContent;
666 return true;
669 bool ScPageHFItem::PutValue( const uno::Any& rVal, sal_uInt8 /* nMemberId */ )
671 bool bRet = false;
672 uno::Reference<sheet::XHeaderFooterContent> xContent;
673 if ( rVal >>= xContent )
675 if ( xContent.is() )
677 ScHeaderFooterContentObj* pImp =
678 ScHeaderFooterContentObj::getImplementation( xContent );
679 if (pImp)
681 const EditTextObject* pImpLeft = pImp->GetLeftEditObject();
682 delete pLeftArea;
683 pLeftArea = pImpLeft ? pImpLeft->Clone() : NULL;
685 const EditTextObject* pImpCenter = pImp->GetCenterEditObject();
686 delete pCenterArea;
687 pCenterArea = pImpCenter ? pImpCenter->Clone() : NULL;
689 const EditTextObject* pImpRight = pImp->GetRightEditObject();
690 delete pRightArea;
691 pRightArea = pImpRight ? pImpRight->Clone() : NULL;
693 if ( !pLeftArea || !pCenterArea || !pRightArea )
695 // no Text with Null are left
696 ScEditEngineDefaulter aEngine( EditEngine::CreatePool(), true );
697 if (!pLeftArea)
698 pLeftArea = aEngine.CreateTextObject();
699 if (!pCenterArea)
700 pCenterArea = aEngine.CreateTextObject();
701 if (!pRightArea)
702 pRightArea = aEngine.CreateTextObject();
705 bRet = true;
710 if (!bRet)
712 OSL_FAIL("exception - wrong argument");
715 return true;
718 //------------------------------------------------------------------------
720 OUString ScPageHFItem::GetValueText() const
722 return OUString("ScPageHFItem");
725 //------------------------------------------------------------------------
727 int ScPageHFItem::operator==( const SfxPoolItem& rItem ) const
729 OSL_ENSURE( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
731 const ScPageHFItem& r = (const ScPageHFItem&)rItem;
733 return ScGlobal::EETextObjEqual(pLeftArea, r.pLeftArea)
734 && ScGlobal::EETextObjEqual(pCenterArea, r.pCenterArea)
735 && ScGlobal::EETextObjEqual(pRightArea, r.pRightArea);
738 //------------------------------------------------------------------------
740 SfxPoolItem* ScPageHFItem::Clone( SfxItemPool* ) const
742 return new ScPageHFItem( *this );
745 //------------------------------------------------------------------------
747 static void lcl_SetSpace( OUString& rStr, const ESelection& rSel )
749 // Text replaced by a space to ensure they are positions:
751 xub_StrLen nLen = rSel.nEndPos-rSel.nStartPos;
752 rStr = rStr.replaceAt( rSel.nStartPos, nLen, " " );
755 static bool lcl_ConvertFields(EditEngine& rEng, const OUString* pCommands)
757 bool bChange = false;
758 sal_Int32 nParCnt = rEng.GetParagraphCount();
759 for (sal_Int32 nPar = 0; nPar<nParCnt; nPar++)
761 OUString aStr = rEng.GetText( nPar );
762 sal_Int32 nPos;
764 while ((nPos = aStr.indexOf(pCommands[0])) != -1)
766 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[0].getLength() );
767 rEng.QuickInsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), aSel );
768 lcl_SetSpace(aStr, aSel ); bChange = true;
770 while ((nPos = aStr.indexOf(pCommands[1])) != -1)
772 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[1].getLength() );
773 rEng.QuickInsertField( SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), aSel );
774 lcl_SetSpace(aStr, aSel ); bChange = true;
776 while ((nPos = aStr.indexOf(pCommands[2])) != -1)
778 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[2].getLength() );
779 rEng.QuickInsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM ),SVXDATETYPE_VAR), EE_FEATURE_FIELD), aSel );
780 lcl_SetSpace(aStr, aSel ); bChange = true;
782 while ((nPos = aStr.indexOf(pCommands[3])) != -1)
784 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[3].getLength() );
785 rEng.QuickInsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD ), aSel );
786 lcl_SetSpace(aStr, aSel ); bChange = true;
788 while ((nPos = aStr.indexOf(pCommands[4])) != -1)
790 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[4].getLength() );
791 rEng.QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), aSel );
792 lcl_SetSpace(aStr, aSel ); bChange = true;
794 while ((nPos = aStr.indexOf(pCommands[5])) != -1)
796 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[5].getLength() );
797 rEng.QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), aSel );
798 lcl_SetSpace(aStr, aSel ); bChange = true;
801 return bChange;
804 #define SC_FIELD_COUNT 6
806 SfxPoolItem* ScPageHFItem::Create( SvStream& rStream, sal_uInt16 nVer ) const
808 EditTextObject* pLeft = EditTextObject::Create(rStream);
809 EditTextObject* pCenter = EditTextObject::Create(rStream);
810 EditTextObject* pRight = EditTextObject::Create(rStream);
812 OSL_ENSURE( pLeft && pCenter && pRight, "Error reading ScPageHFItem" );
814 if ( pLeft == NULL || pLeft->GetParagraphCount() == 0 ||
815 pCenter == NULL || pCenter->GetParagraphCount() == 0 ||
816 pRight == NULL || pRight->GetParagraphCount() == 0 )
818 // If successfully loaded, each object contains at least one paragraph.
819 // Excel import in 5.1 created broken TextObjects (#67442#) that are
820 // corrected here to avoid saving wrong files again (#90487#).
822 ScEditEngineDefaulter aEngine( EditEngine::CreatePool(), true );
823 if ( pLeft == NULL || pLeft->GetParagraphCount() == 0 )
825 delete pLeft;
826 pLeft = aEngine.CreateTextObject();
828 if ( pCenter == NULL || pCenter->GetParagraphCount() == 0 )
830 delete pCenter;
831 pCenter = aEngine.CreateTextObject();
833 if ( pRight == NULL || pRight->GetParagraphCount() == 0 )
835 delete pRight;
836 pRight = aEngine.CreateTextObject();
840 if ( nVer < 1 ) //old field command conversions
842 sal_uInt16 i;
843 const OUString& rDel = ScGlobal::GetRscString( STR_HFCMD_DELIMITER );
844 OUString aCommands[SC_FIELD_COUNT];
845 for (i=0; i<SC_FIELD_COUNT; i++)
846 aCommands[i] = rDel;
847 aCommands[0] += ScGlobal::GetRscString(STR_HFCMD_PAGE);
848 aCommands[1] += ScGlobal::GetRscString(STR_HFCMD_PAGES);
849 aCommands[2] += ScGlobal::GetRscString(STR_HFCMD_DATE);
850 aCommands[3] += ScGlobal::GetRscString(STR_HFCMD_TIME);
851 aCommands[4] += ScGlobal::GetRscString(STR_HFCMD_FILE);
852 aCommands[5] += ScGlobal::GetRscString(STR_HFCMD_TABLE);
853 for (i=0; i<SC_FIELD_COUNT; i++)
854 aCommands[i] += rDel;
856 ScEditEngineDefaulter aEngine( EditEngine::CreatePool(), true );
857 aEngine.SetText(*pLeft);
858 if (lcl_ConvertFields(aEngine,aCommands))
860 delete pLeft;
861 pLeft = aEngine.CreateTextObject();
863 aEngine.SetText(*pCenter);
864 if (lcl_ConvertFields(aEngine,aCommands))
866 delete pCenter;
867 pCenter = aEngine.CreateTextObject();
869 aEngine.SetText(*pRight);
870 if (lcl_ConvertFields(aEngine,aCommands))
872 delete pRight;
873 pRight = aEngine.CreateTextObject();
876 else if ( nVer < 2 )
877 { // not to do, SvxFileField is not exchanged for SvxExtFileField
880 ScPageHFItem* pItem = new ScPageHFItem( Which() );
881 pItem->SetArea( pLeft, SC_HF_LEFTAREA );
882 pItem->SetArea( pCenter, SC_HF_CENTERAREA );
883 pItem->SetArea( pRight, SC_HF_RIGHTAREA );
885 return pItem;
888 //------------------------------------------------------------------------
891 void ScPageHFItem::SetLeftArea( const EditTextObject& rNew )
893 delete pLeftArea;
894 pLeftArea = rNew.Clone();
897 //------------------------------------------------------------------------
899 void ScPageHFItem::SetCenterArea( const EditTextObject& rNew )
901 delete pCenterArea;
902 pCenterArea = rNew.Clone();
905 //------------------------------------------------------------------------
907 void ScPageHFItem::SetRightArea( const EditTextObject& rNew )
909 delete pRightArea;
910 pRightArea = rNew.Clone();
913 void ScPageHFItem::SetArea( EditTextObject *pNew, int nArea )
915 switch ( nArea )
917 case SC_HF_LEFTAREA: delete pLeftArea; pLeftArea = pNew; break;
918 case SC_HF_CENTERAREA: delete pCenterArea; pCenterArea = pNew; break;
919 case SC_HF_RIGHTAREA: delete pRightArea; pRightArea = pNew; break;
920 default:
921 OSL_FAIL( "New Area?" );
925 //-----------------------------------------------------------------------
926 // ScViewObjectModeItem - Display Mode of View Objects
927 //-----------------------------------------------------------------------
929 ScViewObjectModeItem::ScViewObjectModeItem( sal_uInt16 nWhichP )
930 : SfxEnumItem( nWhichP, VOBJ_MODE_SHOW )
934 //------------------------------------------------------------------------
936 ScViewObjectModeItem::ScViewObjectModeItem( sal_uInt16 nWhichP, ScVObjMode eMode )
937 : SfxEnumItem( nWhichP, sal::static_int_cast<sal_uInt16>(eMode) )
941 //------------------------------------------------------------------------
943 ScViewObjectModeItem::~ScViewObjectModeItem()
947 //------------------------------------------------------------------------
949 SfxItemPresentation ScViewObjectModeItem::GetPresentation
951 SfxItemPresentation ePres,
952 SfxMapUnit /* eCoreUnit */,
953 SfxMapUnit /* ePresUnit */,
954 OUString& rText,
955 const IntlWrapper* /* pIntl */
956 ) const
958 OUString aDel(": ");
959 rText = OUString();
961 switch ( ePres )
963 case SFX_ITEM_PRESENTATION_COMPLETE:
964 switch( Which() )
966 case SID_SCATTR_PAGE_CHARTS:
967 rText = ScGlobal::GetRscString(STR_VOBJ_CHART) + aDel;
968 break;
970 case SID_SCATTR_PAGE_OBJECTS:
971 rText = ScGlobal::GetRscString(STR_VOBJ_OBJECT) + aDel;
972 break;
974 case SID_SCATTR_PAGE_DRAWINGS:
975 rText = ScGlobal::GetRscString(STR_VOBJ_DRAWINGS) + aDel;
976 break;
978 default:
979 ePres = SFX_ITEM_PRESENTATION_NAMELESS;//this always goes!
980 break;
982 /* !!! fall-through !!! */
984 case SFX_ITEM_PRESENTATION_NAMELESS:
985 rText += ScGlobal::GetRscString(STR_VOBJ_MODE_SHOW+GetValue());
986 break;
988 default:
990 // added to avoid warnings
994 return ePres;
997 //------------------------------------------------------------------------
999 OUString ScViewObjectModeItem::GetValueText( sal_uInt16 nVal ) const
1001 OSL_ENSURE( nVal <= VOBJ_MODE_HIDE, "enum overflow!" );
1003 return ScGlobal::GetRscString( STR_VOBJ_MODE_SHOW + (nVal % 2));
1006 //------------------------------------------------------------------------
1008 sal_uInt16 ScViewObjectModeItem::GetValueCount() const
1010 return 2;
1013 //------------------------------------------------------------------------
1015 SfxPoolItem* ScViewObjectModeItem::Clone( SfxItemPool* ) const
1017 return new ScViewObjectModeItem( *this );
1020 //------------------------------------------------------------------------
1022 sal_uInt16 ScViewObjectModeItem::GetVersion( sal_uInt16 /* nFileVersion */ ) const
1024 return 1;
1027 //------------------------------------------------------------------------
1029 SfxPoolItem* ScViewObjectModeItem::Create(
1030 SvStream& rStream,
1031 sal_uInt16 nVersion ) const
1033 if ( nVersion == 0 )
1035 // Old Version with AllEnuItem -> produce with Mode "Show"
1036 return new ScViewObjectModeItem( Which() );
1038 else
1040 sal_uInt16 nVal;
1041 rStream >> nVal;
1043 //#i80528# adapt to new range eventually
1044 if((sal_uInt16)VOBJ_MODE_HIDE < nVal) nVal = (sal_uInt16)VOBJ_MODE_SHOW;
1046 return new ScViewObjectModeItem( Which(), (ScVObjMode)nVal);
1050 // -----------------------------------------------------------------------
1051 // double
1052 // -----------------------------------------------------------------------
1054 ScDoubleItem::ScDoubleItem( sal_uInt16 nWhichP, double nVal )
1055 : SfxPoolItem ( nWhichP ),
1056 nValue ( nVal )
1060 //------------------------------------------------------------------------
1062 ScDoubleItem::ScDoubleItem( const ScDoubleItem& rItem )
1063 : SfxPoolItem ( rItem )
1065 nValue = rItem.nValue;
1068 //------------------------------------------------------------------------
1070 OUString ScDoubleItem::GetValueText() const
1072 return OUString("ScDoubleItem");
1075 //------------------------------------------------------------------------
1077 int ScDoubleItem::operator==( const SfxPoolItem& rItem ) const
1079 OSL_ENSURE( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
1080 const ScDoubleItem& _rItem = (const ScDoubleItem&)rItem;
1081 return int(nValue == _rItem.nValue);
1084 //------------------------------------------------------------------------
1086 SfxPoolItem* ScDoubleItem::Clone( SfxItemPool* ) const
1088 return new ScDoubleItem( *this );
1091 //------------------------------------------------------------------------
1093 SfxPoolItem* ScDoubleItem::Create( SvStream& rStream, sal_uInt16 /* nVer */ ) const
1095 double nTmp=0;
1096 rStream >> nTmp;
1098 ScDoubleItem* pItem = new ScDoubleItem( Which(), nTmp );
1100 return pItem;
1103 //------------------------------------------------------------------------
1105 ScDoubleItem::~ScDoubleItem()
1110 // ============================================================================
1112 ScPageScaleToItem::ScPageScaleToItem() :
1113 SfxPoolItem( ATTR_PAGE_SCALETO ),
1114 mnWidth( 0 ),
1115 mnHeight( 0 )
1119 ScPageScaleToItem::ScPageScaleToItem( sal_uInt16 nWidth, sal_uInt16 nHeight ) :
1120 SfxPoolItem( ATTR_PAGE_SCALETO ),
1121 mnWidth( nWidth ),
1122 mnHeight( nHeight )
1126 ScPageScaleToItem::~ScPageScaleToItem()
1130 ScPageScaleToItem* ScPageScaleToItem::Clone( SfxItemPool* ) const
1132 return new ScPageScaleToItem( *this );
1135 int ScPageScaleToItem::operator==( const SfxPoolItem& rCmp ) const
1137 OSL_ENSURE( SfxPoolItem::operator==( rCmp ), "ScPageScaleToItem::operator== - unequal wid or type" );
1138 const ScPageScaleToItem& rPageCmp = static_cast< const ScPageScaleToItem& >( rCmp );
1139 return ((mnWidth == rPageCmp.mnWidth) && (mnHeight == rPageCmp.mnHeight)) ? 1 : 0;
1142 namespace {
1143 void lclAppendScalePageCount( OUString& rText, sal_uInt16 nPages )
1145 rText += ": ";
1146 if( nPages )
1148 OUString aPages( ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALE_PAGES ) );
1149 rText += aPages.replaceFirst( "%1", OUString::number( nPages ) );
1151 else
1152 rText += ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALE_AUTO );
1154 } // namespace
1156 SfxItemPresentation ScPageScaleToItem::GetPresentation(
1157 SfxItemPresentation ePres, SfxMapUnit, SfxMapUnit, OUString& rText, const IntlWrapper* ) const
1159 rText = OUString();
1160 if( !IsValid() || (ePres == SFX_ITEM_PRESENTATION_NONE) )
1161 return SFX_ITEM_PRESENTATION_NONE;
1163 OUString aName( ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALETO ) );
1164 OUString aValue( ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALE_WIDTH ) );
1165 lclAppendScalePageCount( aValue, mnWidth );
1166 aValue = aValue + ", " + ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALE_HEIGHT );
1167 lclAppendScalePageCount( aValue, mnHeight );
1169 switch( ePres )
1171 case SFX_ITEM_PRESENTATION_NONE:
1172 break;
1174 case SFX_ITEM_PRESENTATION_NAMEONLY:
1175 rText = aName;
1176 break;
1178 case SFX_ITEM_PRESENTATION_NAMELESS:
1179 rText = aValue;
1180 break;
1182 case SFX_ITEM_PRESENTATION_COMPLETE:
1183 rText = aName + " (" + aValue + ")";
1184 break;
1186 default:
1187 OSL_FAIL( "ScPageScaleToItem::GetPresentation - unknown presentation mode" );
1188 ePres = SFX_ITEM_PRESENTATION_NONE;
1190 return ePres;
1193 bool ScPageScaleToItem::QueryValue( uno::Any& rAny, sal_uInt8 nMemberId ) const
1195 bool bRet = true;
1196 switch( nMemberId )
1198 case SC_MID_PAGE_SCALETO_WIDTH: rAny <<= mnWidth; break;
1199 case SC_MID_PAGE_SCALETO_HEIGHT: rAny <<= mnHeight; break;
1200 default:
1201 OSL_FAIL( "ScPageScaleToItem::QueryValue - unknown member ID" );
1202 bRet = false;
1204 return bRet;
1207 bool ScPageScaleToItem::PutValue( const uno::Any& rAny, sal_uInt8 nMemberId )
1209 bool bRet = false;
1210 switch( nMemberId )
1212 case SC_MID_PAGE_SCALETO_WIDTH: bRet = rAny >>= mnWidth; break;
1213 case SC_MID_PAGE_SCALETO_HEIGHT: bRet = rAny >>= mnHeight; break;
1214 default:
1215 OSL_FAIL( "ScPageScaleToItem::PutValue - unknown member ID" );
1217 return bRet;
1220 // ============================================================================
1222 ScCondFormatItem::ScCondFormatItem():
1223 SfxPoolItem( ATTR_CONDITIONAL )
1227 ScCondFormatItem::ScCondFormatItem( const std::vector<sal_uInt32>& rIndex ):
1228 SfxPoolItem( ATTR_CONDITIONAL ),
1229 maIndex( rIndex )
1233 ScCondFormatItem::~ScCondFormatItem()
1237 int ScCondFormatItem::operator==( const SfxPoolItem& rCmp ) const
1239 return maIndex == static_cast<const ScCondFormatItem&>(rCmp).maIndex;
1242 ScCondFormatItem* ScCondFormatItem::Clone(SfxItemPool*) const
1244 return new ScCondFormatItem(maIndex);
1247 const std::vector<sal_uInt32>& ScCondFormatItem::GetCondFormatData() const
1249 return maIndex;
1252 void ScCondFormatItem::AddCondFormatData( sal_uInt32 nIndex )
1254 maIndex.push_back(nIndex);
1257 void ScCondFormatItem::SetCondFormatData( const std::vector<sal_uInt32>& rIndex )
1259 maIndex = rIndex;
1263 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */