merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / data / attrib.cxx
blobf9943906e527b8f9e002ee9b19003c42df9863ab
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: attrib.cxx,v $
10 * $Revision: 1.19.32.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
39 #include <com/sun/star/util/CellProtection.hpp>
40 #include <com/sun/star/util/XProtectable.hpp>
41 #include <com/sun/star/text/XText.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include "scitems.hxx"
45 #include <svx/eeitem.hxx>
47 #include <svx/boxitem.hxx>
48 #include <svx/editdata.hxx>
49 #include <svx/editeng.hxx>
50 #include <svx/editobj.hxx>
51 #include <svx/flditem.hxx>
53 #include "attrib.hxx"
54 #include "global.hxx"
55 #include "editutil.hxx"
56 #include "sc.hrc"
57 #include "globstr.hrc"
59 #include "textuno.hxx" // ScHeaderFooterContentObj
61 using namespace com::sun::star;
63 //------------------------------------------------------------------------
65 TYPEINIT1(ScMergeAttr, SfxPoolItem);
66 TYPEINIT1_AUTOFACTORY(ScProtectionAttr, SfxPoolItem);
67 TYPEINIT1(ScRangeItem, SfxPoolItem);
68 TYPEINIT1(ScTableListItem, SfxPoolItem);
69 TYPEINIT1(ScPageHFItem, SfxPoolItem);
70 TYPEINIT1(ScViewObjectModeItem, SfxEnumItem);
71 TYPEINIT1(ScDoubleItem, SfxPoolItem);
72 TYPEINIT1(ScPageScaleToItem, SfxPoolItem);
74 //------------------------------------------------------------------------
77 // allgemeine Hilfsfunktionen
80 BOOL ScHasPriority( const SvxBorderLine* pThis, const SvxBorderLine* pOther )
82 // DBG_ASSERT( pThis || pOther, "LineAttr == 0" );
84 if (!pThis)
85 return FALSE;
86 if (!pOther)
87 return TRUE;
89 USHORT nThisSize = pThis->GetOutWidth() + pThis->GetDistance() + pThis->GetInWidth();
90 USHORT nOtherSize = pOther->GetOutWidth() + pOther->GetDistance() + pOther->GetInWidth();
92 if (nThisSize > nOtherSize)
93 return TRUE;
94 else if (nThisSize < nOtherSize)
95 return FALSE;
96 else
98 if ( pOther->GetInWidth() && !pThis->GetInWidth() )
99 return TRUE;
100 else if ( pThis->GetInWidth() && !pOther->GetInWidth() )
101 return FALSE;
102 else
104 return TRUE; //! ???
111 // Item - Implementierungen
114 //------------------------------------------------------------------------
115 // Merge
116 //------------------------------------------------------------------------
118 ScMergeAttr::ScMergeAttr():
119 SfxPoolItem(ATTR_MERGE),
120 nColMerge(0),
121 nRowMerge(0)
124 //------------------------------------------------------------------------
126 ScMergeAttr::ScMergeAttr( SCsCOL nCol, SCsROW nRow):
127 SfxPoolItem(ATTR_MERGE),
128 nColMerge(nCol),
129 nRowMerge(nRow)
132 //------------------------------------------------------------------------
134 ScMergeAttr::ScMergeAttr(const ScMergeAttr& rItem):
135 SfxPoolItem(ATTR_MERGE)
137 nColMerge = rItem.nColMerge;
138 nRowMerge = rItem.nRowMerge;
141 ScMergeAttr::~ScMergeAttr()
145 //------------------------------------------------------------------------
147 String ScMergeAttr::GetValueText() const
149 String aString( '(' );
150 aString += String::CreateFromInt32( nColMerge );
151 aString += ',';
152 aString += String::CreateFromInt32( nRowMerge );
153 aString += ')';
154 return aString;
157 //------------------------------------------------------------------------
159 int ScMergeAttr::operator==( const SfxPoolItem& rItem ) const
161 DBG_ASSERT( Which() != rItem.Which() || Type() == rItem.Type(), "which ==, type !=" );
162 return (Which() == rItem.Which())
163 && (nColMerge == ((ScMergeAttr&)rItem).nColMerge)
164 && (nRowMerge == ((ScMergeAttr&)rItem).nRowMerge);
167 //------------------------------------------------------------------------
169 SfxPoolItem* ScMergeAttr::Clone( SfxItemPool * ) const
171 return new ScMergeAttr(*this);
174 //------------------------------------------------------------------------
176 SfxPoolItem* ScMergeAttr::Create( SvStream& rStream, USHORT /* nVer */ ) const
178 INT16 nCol;
179 INT16 nRow;
180 rStream >> nCol;
181 rStream >> nRow;
182 return new ScMergeAttr(static_cast<SCCOL>(nCol),static_cast<SCROW>(nRow));
185 //------------------------------------------------------------------------
186 // MergeFlag
187 //------------------------------------------------------------------------
189 ScMergeFlagAttr::ScMergeFlagAttr():
190 SfxInt16Item(ATTR_MERGE_FLAG, 0)
194 //------------------------------------------------------------------------
196 ScMergeFlagAttr::ScMergeFlagAttr(INT16 nFlags):
197 SfxInt16Item(ATTR_MERGE_FLAG, nFlags)
201 ScMergeFlagAttr::~ScMergeFlagAttr()
205 //------------------------------------------------------------------------
206 // Protection
207 //------------------------------------------------------------------------
209 ScProtectionAttr::ScProtectionAttr():
210 SfxPoolItem(ATTR_PROTECTION),
211 bProtection(TRUE),
212 bHideFormula(FALSE),
213 bHideCell(FALSE),
214 bHidePrint(FALSE)
218 //------------------------------------------------------------------------
220 ScProtectionAttr::ScProtectionAttr( BOOL bProtect, BOOL bHFormula,
221 BOOL bHCell, BOOL bHPrint):
222 SfxPoolItem(ATTR_PROTECTION),
223 bProtection(bProtect),
224 bHideFormula(bHFormula),
225 bHideCell(bHCell),
226 bHidePrint(bHPrint)
230 //------------------------------------------------------------------------
232 ScProtectionAttr::ScProtectionAttr(const ScProtectionAttr& rItem):
233 SfxPoolItem(ATTR_PROTECTION)
235 bProtection = rItem.bProtection;
236 bHideFormula = rItem.bHideFormula;
237 bHideCell = rItem.bHideCell;
238 bHidePrint = rItem.bHidePrint;
241 ScProtectionAttr::~ScProtectionAttr()
245 //------------------------------------------------------------------------
247 BOOL ScProtectionAttr::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
249 nMemberId &= ~CONVERT_TWIPS;
250 switch ( nMemberId )
252 case 0 :
254 util::CellProtection aProtection;
255 aProtection.IsLocked = bProtection;
256 aProtection.IsFormulaHidden = bHideFormula;
257 aProtection.IsHidden = bHideCell;
258 aProtection.IsPrintHidden = bHidePrint;
259 rVal <<= aProtection;
260 break;
262 case MID_1 :
263 rVal <<= (sal_Bool ) bProtection; break;
264 case MID_2 :
265 rVal <<= (sal_Bool ) bHideFormula; break;
266 case MID_3 :
267 rVal <<= (sal_Bool ) bHideCell; break;
268 case MID_4 :
269 rVal <<= (sal_Bool ) bHidePrint; break;
270 default:
271 DBG_ERROR("Wrong MemberID!");
272 return FALSE;
275 return TRUE;
278 BOOL ScProtectionAttr::PutValue( const uno::Any& rVal, BYTE nMemberId )
280 BOOL bRet = FALSE;
281 sal_Bool bVal = sal_Bool();
282 nMemberId &= ~CONVERT_TWIPS;
283 switch ( nMemberId )
285 case 0 :
287 util::CellProtection aProtection;
288 if ( rVal >>= aProtection )
290 bProtection = aProtection.IsLocked;
291 bHideFormula = aProtection.IsFormulaHidden;
292 bHideCell = aProtection.IsHidden;
293 bHidePrint = aProtection.IsPrintHidden;
294 bRet = TRUE;
296 else
298 DBG_ERROR("exception - wrong argument");
300 break;
302 case MID_1 :
303 bRet = (rVal >>= bVal); if (bRet) bProtection=bVal; break;
304 case MID_2 :
305 bRet = (rVal >>= bVal); if (bRet) bHideFormula=bVal; break;
306 case MID_3 :
307 bRet = (rVal >>= bVal); if (bRet) bHideCell=bVal; break;
308 case MID_4 :
309 bRet = (rVal >>= bVal); if (bRet) bHidePrint=bVal; break;
310 default:
311 DBG_ERROR("Wrong MemberID!");
314 return bRet;
317 //------------------------------------------------------------------------
319 String ScProtectionAttr::GetValueText() const
321 String aValue;
322 String aStrYes ( ScGlobal::GetRscString(STR_YES) );
323 String aStrNo ( ScGlobal::GetRscString(STR_NO) );
324 sal_Unicode cDelim = ',';
326 aValue = '(';
327 aValue += (bProtection ? aStrYes : aStrNo); aValue += cDelim;
328 aValue += (bHideFormula ? aStrYes : aStrNo); aValue += cDelim;
329 aValue += (bHideCell ? aStrYes : aStrNo); aValue += cDelim;
330 aValue += (bHidePrint ? aStrYes : aStrNo);
331 aValue += ')';
333 return aValue;
336 //------------------------------------------------------------------------
338 SfxItemPresentation ScProtectionAttr::GetPresentation
340 SfxItemPresentation ePres,
341 SfxMapUnit /* eCoreMetric */,
342 SfxMapUnit /* ePresMetric */,
343 String& rText,
344 const IntlWrapper* /* pIntl */
345 ) const
347 String aStrYes ( ScGlobal::GetRscString(STR_YES) );
348 String aStrNo ( ScGlobal::GetRscString(STR_NO) );
349 String aStrSep = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
350 String aStrDelim = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( ", " ));
352 switch ( ePres )
354 case SFX_ITEM_PRESENTATION_NONE:
355 rText.Erase();
356 break;
358 case SFX_ITEM_PRESENTATION_NAMELESS:
359 rText = GetValueText();
360 break;
362 case SFX_ITEM_PRESENTATION_COMPLETE:
363 rText = ScGlobal::GetRscString(STR_PROTECTION); rText += aStrSep;
364 rText += (bProtection ? aStrYes : aStrNo); rText += aStrDelim;
365 rText += ScGlobal::GetRscString(STR_FORMULAS); rText += aStrSep;
366 rText += (!bHideFormula ? aStrYes : aStrNo); rText += aStrDelim;
367 rText += ScGlobal::GetRscString(STR_HIDE); rText += aStrSep;
368 rText += (bHideCell ? aStrYes : aStrNo); rText += aStrDelim;
369 rText += ScGlobal::GetRscString(STR_PRINT); rText += aStrSep;
370 rText += (!bHidePrint ? aStrYes : aStrNo);
371 break;
373 default:
374 ePres = SFX_ITEM_PRESENTATION_NONE;
377 return ePres;
380 //------------------------------------------------------------------------
382 int ScProtectionAttr::operator==( const SfxPoolItem& rItem ) const
384 DBG_ASSERT( Which() != rItem.Which() || Type() == rItem.Type(), "which ==, type !=" );
385 return (Which() == rItem.Which())
386 && (bProtection == ((ScProtectionAttr&)rItem).bProtection)
387 && (bHideFormula == ((ScProtectionAttr&)rItem).bHideFormula)
388 && (bHideCell == ((ScProtectionAttr&)rItem).bHideCell)
389 && (bHidePrint == ((ScProtectionAttr&)rItem).bHidePrint);
392 //------------------------------------------------------------------------
394 SfxPoolItem* ScProtectionAttr::Clone( SfxItemPool * ) const
396 return new ScProtectionAttr(*this);
399 //------------------------------------------------------------------------
401 SfxPoolItem* ScProtectionAttr::Create( SvStream& rStream, USHORT /* n */ ) const
403 BOOL bProtect;
404 BOOL bHFormula;
405 BOOL bHCell;
406 BOOL bHPrint;
408 rStream >> bProtect;
409 rStream >> bHFormula;
410 rStream >> bHCell;
411 rStream >> bHPrint;
413 return new ScProtectionAttr(bProtect,bHFormula,bHCell,bHPrint);
416 //------------------------------------------------------------------------
418 BOOL ScProtectionAttr::SetProtection( BOOL bProtect)
420 bProtection = bProtect;
421 return TRUE;
424 //------------------------------------------------------------------------
426 BOOL ScProtectionAttr::SetHideFormula( BOOL bHFormula)
428 bHideFormula = bHFormula;
429 return TRUE;
432 //------------------------------------------------------------------------
434 BOOL ScProtectionAttr::SetHideCell( BOOL bHCell)
436 bHideCell = bHCell;
437 return TRUE;
440 //------------------------------------------------------------------------
442 BOOL ScProtectionAttr::SetHidePrint( BOOL bHPrint)
444 bHidePrint = bHPrint;
445 return TRUE;
448 // -----------------------------------------------------------------------
449 // ScRangeItem - Tabellenbereich
450 // -----------------------------------------------------------------------
452 int ScRangeItem::operator==( const SfxPoolItem& rAttr ) const
454 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
456 return ( aRange == ( (ScRangeItem&)rAttr ).aRange );
459 // -----------------------------------------------------------------------
461 SfxPoolItem* ScRangeItem::Clone( SfxItemPool* ) const
463 return new ScRangeItem( *this );
466 //------------------------------------------------------------------------
468 SfxItemPresentation ScRangeItem::GetPresentation
470 SfxItemPresentation ePres,
471 SfxMapUnit /* eCoreUnit */,
472 SfxMapUnit /* ePresUnit */,
473 String& rText,
474 const IntlWrapper* /* pIntl */
475 ) const
477 rText.Erase();
479 switch ( ePres )
481 case SFX_ITEM_PRESENTATION_COMPLETE:
482 rText = ScGlobal::GetRscString(STR_AREA);
483 rText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
484 // break;// Durchfallen !!!
486 case SFX_ITEM_PRESENTATION_NAMELESS:
488 String aText;
489 /* Always use OOo:A1 format */
490 aRange.Format( aText );
491 rText += aText;
493 break;
495 default:
497 // added to avoid warnings
501 return ePres;
504 // -----------------------------------------------------------------------
505 // ScTableListItem - Liste von Tabellen(-nummern)
506 // -----------------------------------------------------------------------
508 ScTableListItem::ScTableListItem( const ScTableListItem& rCpy )
509 : SfxPoolItem ( rCpy.Which() ),
510 nCount ( rCpy.nCount )
512 if ( nCount > 0 )
514 pTabArr = new SCTAB [nCount];
516 for ( USHORT i=0; i<nCount; i++ )
517 pTabArr[i] = rCpy.pTabArr[i];
519 else
520 pTabArr = NULL;
523 // -----------------------------------------------------------------------
525 //UNUSED2008-05 ScTableListItem::ScTableListItem( const USHORT nWhichP, const List& rList )
526 //UNUSED2008-05 : SfxPoolItem ( nWhichP ),
527 //UNUSED2008-05 nCount ( 0 ),
528 //UNUSED2008-05 pTabArr ( NULL )
529 //UNUSED2008-05 {
530 //UNUSED2008-05 SetTableList( rList );
531 //UNUSED2008-05 }
533 // -----------------------------------------------------------------------
535 ScTableListItem::~ScTableListItem()
537 delete [] pTabArr;
540 // -----------------------------------------------------------------------
542 ScTableListItem& ScTableListItem::operator=( const ScTableListItem& rCpy )
544 delete [] pTabArr;
546 if ( rCpy.nCount > 0 )
548 pTabArr = new SCTAB [rCpy.nCount];
549 for ( USHORT i=0; i<rCpy.nCount; i++ )
550 pTabArr[i] = rCpy.pTabArr[i];
552 else
553 pTabArr = NULL;
555 nCount = rCpy.nCount;
557 return *this;
560 // -----------------------------------------------------------------------
562 int ScTableListItem::operator==( const SfxPoolItem& rAttr ) const
564 DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
566 ScTableListItem& rCmp = (ScTableListItem&)rAttr;
567 BOOL bEqual = (nCount == rCmp.nCount);
569 if ( nCount > 0 )
571 USHORT i=0;
573 bEqual = ( pTabArr && rCmp.pTabArr );
575 while ( bEqual && i<nCount )
577 bEqual = ( pTabArr[i] == rCmp.pTabArr[i] );
578 i++;
581 return bEqual;
584 // -----------------------------------------------------------------------
586 SfxPoolItem* ScTableListItem::Clone( SfxItemPool* ) const
588 return new ScTableListItem( *this );
591 //------------------------------------------------------------------------
593 SfxItemPresentation ScTableListItem::GetPresentation
595 SfxItemPresentation ePres,
596 SfxMapUnit /* eCoreUnit */,
597 SfxMapUnit /* ePresUnit */,
598 String& rText,
599 const IntlWrapper* /* pIntl */
600 ) const
602 const sal_Unicode cDelim = ',';
604 switch ( ePres )
606 case SFX_ITEM_PRESENTATION_NONE:
607 rText.Erase();
608 return ePres;
610 case SFX_ITEM_PRESENTATION_NAMELESS:
612 rText = '(';
613 if ( nCount>0 && pTabArr )
614 for ( USHORT i=0; i<nCount; i++ )
616 rText += String::CreateFromInt32( pTabArr[i] );
617 if ( i<(nCount-1) )
618 rText += cDelim;
620 rText += ')';
622 return ePres;
624 case SFX_ITEM_PRESENTATION_COMPLETE:
625 rText.Erase();
626 return SFX_ITEM_PRESENTATION_NONE;
628 default:
630 // added to avoid warnings
634 return SFX_ITEM_PRESENTATION_NONE;
637 // -----------------------------------------------------------------------
639 //UNUSED2009-05 BOOL ScTableListItem::GetTableList( List& aList ) const
640 //UNUSED2009-05 {
641 //UNUSED2009-05 for ( USHORT i=0; i<nCount; i++ )
642 //UNUSED2009-05 aList.Insert( new SCTAB( pTabArr[i] ) );
643 //UNUSED2009-05
644 //UNUSED2009-05 return ( nCount > 0 );
645 //UNUSED2009-05 }
647 // -----------------------------------------------------------------------
649 //UNUSED2009-05 void ScTableListItem::SetTableList( const List& rList )
650 //UNUSED2009-05 {
651 //UNUSED2009-05 nCount = (USHORT)rList.Count();
652 //UNUSED2009-05
653 //UNUSED2009-05 delete [] pTabArr;
654 //UNUSED2009-05
655 //UNUSED2009-05 if ( nCount > 0 )
656 //UNUSED2009-05 {
657 //UNUSED2009-05 pTabArr = new SCTAB [nCount];
658 //UNUSED2009-05
659 //UNUSED2009-05 for ( USHORT i=0; i<nCount; i++ )
660 //UNUSED2009-05 pTabArr[i] = *( (SCTAB*)rList.GetObject( i ) );
661 //UNUSED2009-05 }
662 //UNUSED2009-05 else
663 //UNUSED2009-05 pTabArr = NULL;
664 //UNUSED2009-05 }
667 // -----------------------------------------------------------------------
668 // ScPageHFItem - Daten der Kopf-/Fusszeilen
669 // -----------------------------------------------------------------------
671 ScPageHFItem::ScPageHFItem( USHORT nWhichP )
672 : SfxPoolItem ( nWhichP ),
673 pLeftArea ( NULL ),
674 pCenterArea ( NULL ),
675 pRightArea ( NULL )
679 //------------------------------------------------------------------------
681 ScPageHFItem::ScPageHFItem( const ScPageHFItem& rItem )
682 : SfxPoolItem ( rItem ),
683 pLeftArea ( NULL ),
684 pCenterArea ( NULL ),
685 pRightArea ( NULL )
687 if ( rItem.pLeftArea )
688 pLeftArea = rItem.pLeftArea->Clone();
689 if ( rItem.pCenterArea )
690 pCenterArea = rItem.pCenterArea->Clone();
691 if ( rItem.pRightArea )
692 pRightArea = rItem.pRightArea->Clone();
695 //------------------------------------------------------------------------
697 ScPageHFItem::~ScPageHFItem()
699 delete pLeftArea;
700 delete pCenterArea;
701 delete pRightArea;
704 //------------------------------------------------------------------------
706 BOOL ScPageHFItem::QueryValue( uno::Any& rVal, BYTE /* nMemberId */ ) const
708 uno::Reference<sheet::XHeaderFooterContent> xContent =
709 new ScHeaderFooterContentObj( pLeftArea, pCenterArea, pRightArea );
711 rVal <<= xContent;
712 return TRUE;
715 BOOL ScPageHFItem::PutValue( const uno::Any& rVal, BYTE /* nMemberId */ )
717 BOOL bRet = FALSE;
718 uno::Reference<sheet::XHeaderFooterContent> xContent;
719 if ( rVal >>= xContent )
721 if ( xContent.is() )
723 ScHeaderFooterContentObj* pImp =
724 ScHeaderFooterContentObj::getImplementation( xContent );
725 if (pImp)
727 const EditTextObject* pImpLeft = pImp->GetLeftEditObject();
728 delete pLeftArea;
729 pLeftArea = pImpLeft ? pImpLeft->Clone() : NULL;
731 const EditTextObject* pImpCenter = pImp->GetCenterEditObject();
732 delete pCenterArea;
733 pCenterArea = pImpCenter ? pImpCenter->Clone() : NULL;
735 const EditTextObject* pImpRight = pImp->GetRightEditObject();
736 delete pRightArea;
737 pRightArea = pImpRight ? pImpRight->Clone() : NULL;
739 if ( !pLeftArea || !pCenterArea || !pRightArea )
741 // keine Texte auf NULL stehen lassen
742 ScEditEngineDefaulter aEngine( EditEngine::CreatePool(), TRUE );
743 if (!pLeftArea)
744 pLeftArea = aEngine.CreateTextObject();
745 if (!pCenterArea)
746 pCenterArea = aEngine.CreateTextObject();
747 if (!pRightArea)
748 pRightArea = aEngine.CreateTextObject();
751 bRet = TRUE;
756 if (!bRet)
758 DBG_ERROR("exception - wrong argument");
761 return bRet;
764 //------------------------------------------------------------------------
766 String ScPageHFItem::GetValueText() const
768 return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ScPageHFItem"));
771 //------------------------------------------------------------------------
773 int ScPageHFItem::operator==( const SfxPoolItem& rItem ) const
775 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
777 const ScPageHFItem& r = (const ScPageHFItem&)rItem;
779 return ScGlobal::EETextObjEqual(pLeftArea, r.pLeftArea)
780 && ScGlobal::EETextObjEqual(pCenterArea, r.pCenterArea)
781 && ScGlobal::EETextObjEqual(pRightArea, r.pRightArea);
784 //------------------------------------------------------------------------
786 SfxPoolItem* ScPageHFItem::Clone( SfxItemPool* ) const
788 return new ScPageHFItem( *this );
791 //------------------------------------------------------------------------
793 void lcl_SetSpace( String& rStr, const ESelection& rSel )
795 // Text durch ein Leerzeichen ersetzen, damit Positionen stimmen:
797 xub_StrLen nLen = rSel.nEndPos-rSel.nStartPos;
798 rStr.Erase( rSel.nStartPos, nLen-1 );
799 rStr.SetChar( rSel.nStartPos, ' ' );
802 BOOL lcl_ConvertFields(EditEngine& rEng, const String* pCommands)
804 BOOL bChange = FALSE;
805 USHORT nParCnt = rEng.GetParagraphCount();
806 for (USHORT nPar = 0; nPar<nParCnt; nPar++)
808 String aStr = rEng.GetText( nPar );
809 xub_StrLen nPos;
811 while ((nPos = aStr.Search(pCommands[0])) != STRING_NOTFOUND)
813 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[0].Len() );
814 rEng.QuickInsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), aSel );
815 lcl_SetSpace(aStr, aSel ); bChange = TRUE;
817 while ((nPos = aStr.Search(pCommands[1])) != STRING_NOTFOUND)
819 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[1].Len() );
820 rEng.QuickInsertField( SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD), aSel );
821 lcl_SetSpace(aStr, aSel ); bChange = TRUE;
823 while ((nPos = aStr.Search(pCommands[2])) != STRING_NOTFOUND)
825 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[2].Len() );
826 rEng.QuickInsertField( SvxFieldItem(SvxDateField(Date(),SVXDATETYPE_VAR), EE_FEATURE_FIELD), aSel );
827 lcl_SetSpace(aStr, aSel ); bChange = TRUE;
829 while ((nPos = aStr.Search(pCommands[3])) != STRING_NOTFOUND)
831 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[3].Len() );
832 rEng.QuickInsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD ), aSel );
833 lcl_SetSpace(aStr, aSel ); bChange = TRUE;
835 while ((nPos = aStr.Search(pCommands[4])) != STRING_NOTFOUND)
837 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[4].Len() );
838 rEng.QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD), aSel );
839 lcl_SetSpace(aStr, aSel ); bChange = TRUE;
841 while ((nPos = aStr.Search(pCommands[5])) != STRING_NOTFOUND)
843 ESelection aSel( nPar,nPos, nPar,nPos+pCommands[5].Len() );
844 rEng.QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD), aSel );
845 lcl_SetSpace(aStr, aSel ); bChange = TRUE;
848 return bChange;
851 #define SC_FIELD_COUNT 6
853 SfxPoolItem* ScPageHFItem::Create( SvStream& rStream, USHORT nVer ) const
855 EditTextObject* pLeft = EditTextObject::Create(rStream);
856 EditTextObject* pCenter = EditTextObject::Create(rStream);
857 EditTextObject* pRight = EditTextObject::Create(rStream);
859 DBG_ASSERT( pLeft && pCenter && pRight, "Error reading ScPageHFItem" );
861 if ( pLeft == NULL || pLeft->GetParagraphCount() == 0 ||
862 pCenter == NULL || pCenter->GetParagraphCount() == 0 ||
863 pRight == NULL || pRight->GetParagraphCount() == 0 )
865 // If successfully loaded, each object contains at least one paragraph.
866 // Excel import in 5.1 created broken TextObjects (#67442#) that are
867 // corrected here to avoid saving wrong files again (#90487#).
869 ScEditEngineDefaulter aEngine( EditEngine::CreatePool(), TRUE );
870 if ( pLeft == NULL || pLeft->GetParagraphCount() == 0 )
872 delete pLeft;
873 pLeft = aEngine.CreateTextObject();
875 if ( pCenter == NULL || pCenter->GetParagraphCount() == 0 )
877 delete pCenter;
878 pCenter = aEngine.CreateTextObject();
880 if ( pRight == NULL || pRight->GetParagraphCount() == 0 )
882 delete pRight;
883 pRight = aEngine.CreateTextObject();
887 if ( nVer < 1 ) // alte Feldbefehle umsetzen
889 USHORT i;
890 const String& rDel = ScGlobal::GetRscString( STR_HFCMD_DELIMITER );
891 String aCommands[SC_FIELD_COUNT];
892 for (i=0; i<SC_FIELD_COUNT; i++)
893 aCommands[i] = rDel;
894 aCommands[0] += ScGlobal::GetRscString(STR_HFCMD_PAGE);
895 aCommands[1] += ScGlobal::GetRscString(STR_HFCMD_PAGES);
896 aCommands[2] += ScGlobal::GetRscString(STR_HFCMD_DATE);
897 aCommands[3] += ScGlobal::GetRscString(STR_HFCMD_TIME);
898 aCommands[4] += ScGlobal::GetRscString(STR_HFCMD_FILE);
899 aCommands[5] += ScGlobal::GetRscString(STR_HFCMD_TABLE);
900 for (i=0; i<SC_FIELD_COUNT; i++)
901 aCommands[i] += rDel;
903 ScEditEngineDefaulter aEngine( EditEngine::CreatePool(), TRUE );
904 aEngine.SetText(*pLeft);
905 if (lcl_ConvertFields(aEngine,aCommands))
907 delete pLeft;
908 pLeft = aEngine.CreateTextObject();
910 aEngine.SetText(*pCenter);
911 if (lcl_ConvertFields(aEngine,aCommands))
913 delete pCenter;
914 pCenter = aEngine.CreateTextObject();
916 aEngine.SetText(*pRight);
917 if (lcl_ConvertFields(aEngine,aCommands))
919 delete pRight;
920 pRight = aEngine.CreateTextObject();
923 else if ( nVer < 2 )
924 { // nichts tun, SvxFileField nicht gegen SvxExtFileField austauschen
927 ScPageHFItem* pItem = new ScPageHFItem( Which() );
928 pItem->SetArea( pLeft, SC_HF_LEFTAREA );
929 pItem->SetArea( pCenter, SC_HF_CENTERAREA );
930 pItem->SetArea( pRight, SC_HF_RIGHTAREA );
932 return pItem;
935 //------------------------------------------------------------------------
937 //UNUSED2009-05 class ScFieldChangerEditEngine : public ScEditEngineDefaulter
938 //UNUSED2009-05 {
939 //UNUSED2009-05 TypeId aExtFileId;
940 //UNUSED2009-05 USHORT nConvPara;
941 //UNUSED2009-05 xub_StrLen nConvPos;
942 //UNUSED2009-05 BOOL bConvert;
943 //UNUSED2009-05
944 //UNUSED2009-05 public:
945 //UNUSED2009-05 ScFieldChangerEditEngine( SfxItemPool* pEnginePool, BOOL bDeleteEnginePool );
946 //UNUSED2009-05 virtual ~ScFieldChangerEditEngine() {}
947 //UNUSED2009-05
948 //UNUSED2009-05 virtual String CalcFieldValue( const SvxFieldItem& rField, USHORT nPara,
949 //UNUSED2009-05 USHORT nPos, Color*& rTxtColor,
950 //UNUSED2009-05 Color*& rFldColor );
951 //UNUSED2009-05
952 //UNUSED2009-05 BOOL ConvertFields();
953 //UNUSED2009-05 };
954 //UNUSED2009-05
955 //UNUSED2009-05 ScFieldChangerEditEngine::ScFieldChangerEditEngine( SfxItemPool* pEnginePoolP,
956 //UNUSED2009-05 BOOL bDeleteEnginePoolP ) :
957 //UNUSED2009-05 ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP ),
958 //UNUSED2009-05 aExtFileId( TYPE( SvxExtFileField ) ),
959 //UNUSED2009-05 nConvPara( 0 ),
960 //UNUSED2009-05 nConvPos( 0 ),
961 //UNUSED2009-05 bConvert( FALSE )
962 //UNUSED2009-05 {
963 //UNUSED2009-05 }
964 //UNUSED2009-05
965 //UNUSED2009-05 String ScFieldChangerEditEngine::CalcFieldValue( const SvxFieldItem& rField,
966 //UNUSED2009-05 USHORT nPara, USHORT nPos, Color*& /* rTxtColor */, Color*& /* rFldColor */ )
967 //UNUSED2009-05 {
968 //UNUSED2009-05 const SvxFieldData* pFieldData = rField.GetField();
969 //UNUSED2009-05 if ( pFieldData && pFieldData->Type() == aExtFileId )
970 //UNUSED2009-05 {
971 //UNUSED2009-05 bConvert = TRUE;
972 //UNUSED2009-05 nConvPara = nPara;
973 //UNUSED2009-05 nConvPos = nPos;
974 //UNUSED2009-05 }
975 //UNUSED2009-05 return EMPTY_STRING;
976 //UNUSED2009-05 }
977 //UNUSED2009-05
978 //UNUSED2009-05 BOOL ScFieldChangerEditEngine::ConvertFields()
979 //UNUSED2009-05 {
980 //UNUSED2009-05 BOOL bConverted = FALSE;
981 //UNUSED2009-05 do
982 //UNUSED2009-05 {
983 //UNUSED2009-05 bConvert = FALSE;
984 //UNUSED2009-05 UpdateFields();
985 //UNUSED2009-05 if ( bConvert )
986 //UNUSED2009-05 {
987 //UNUSED2009-05 ESelection aSel( nConvPara, nConvPos, nConvPara, nConvPos+1 );
988 //UNUSED2009-05 QuickInsertField( SvxFieldItem( SvxFileField(), EE_FEATURE_FIELD), aSel );
989 //UNUSED2009-05 bConverted = TRUE;
990 //UNUSED2009-05 }
991 //UNUSED2009-05 } while ( bConvert );
992 //UNUSED2009-05 return bConverted;
993 //UNUSED2009-05 }
995 void ScPageHFItem::SetLeftArea( const EditTextObject& rNew )
997 delete pLeftArea;
998 pLeftArea = rNew.Clone();
1001 //------------------------------------------------------------------------
1003 void ScPageHFItem::SetCenterArea( const EditTextObject& rNew )
1005 delete pCenterArea;
1006 pCenterArea = rNew.Clone();
1009 //------------------------------------------------------------------------
1011 void ScPageHFItem::SetRightArea( const EditTextObject& rNew )
1013 delete pRightArea;
1014 pRightArea = rNew.Clone();
1017 void ScPageHFItem::SetArea( EditTextObject *pNew, int nArea )
1019 switch ( nArea )
1021 case SC_HF_LEFTAREA: delete pLeftArea; pLeftArea = pNew; break;
1022 case SC_HF_CENTERAREA: delete pCenterArea; pCenterArea = pNew; break;
1023 case SC_HF_RIGHTAREA: delete pRightArea; pRightArea = pNew; break;
1024 default:
1025 DBG_ERROR( "New Area?" );
1029 //-----------------------------------------------------------------------
1030 // ScViewObjectModeItem - Darstellungsmodus von ViewObjekten
1031 //-----------------------------------------------------------------------
1033 ScViewObjectModeItem::ScViewObjectModeItem( USHORT nWhichP )
1034 : SfxEnumItem( nWhichP, VOBJ_MODE_SHOW )
1038 //------------------------------------------------------------------------
1040 ScViewObjectModeItem::ScViewObjectModeItem( USHORT nWhichP, ScVObjMode eMode )
1041 : SfxEnumItem( nWhichP, sal::static_int_cast<USHORT>(eMode) )
1045 //------------------------------------------------------------------------
1047 ScViewObjectModeItem::~ScViewObjectModeItem()
1051 //------------------------------------------------------------------------
1053 SfxItemPresentation ScViewObjectModeItem::GetPresentation
1055 SfxItemPresentation ePres,
1056 SfxMapUnit /* eCoreUnit */,
1057 SfxMapUnit /* ePresUnit */,
1058 String& rText,
1059 const IntlWrapper* /* pIntl */
1060 ) const
1062 String aDel = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(": "));
1063 rText.Erase();
1065 switch ( ePres )
1067 case SFX_ITEM_PRESENTATION_COMPLETE:
1068 switch( Which() )
1070 case SID_SCATTR_PAGE_CHARTS:
1071 rText = ScGlobal::GetRscString(STR_VOBJ_CHART);
1072 rText += aDel;
1073 break;
1075 case SID_SCATTR_PAGE_OBJECTS:
1076 rText = ScGlobal::GetRscString(STR_VOBJ_OBJECT);
1077 rText += aDel;
1078 break;
1080 case SID_SCATTR_PAGE_DRAWINGS:
1081 rText = ScGlobal::GetRscString(STR_VOBJ_DRAWINGS);
1082 rText += aDel;
1083 break;
1085 default:
1086 ePres = SFX_ITEM_PRESENTATION_NAMELESS;//das geht immer!
1087 break;
1089 // break; // DURCHFALLEN!!!
1091 case SFX_ITEM_PRESENTATION_NAMELESS:
1092 rText += ScGlobal::GetRscString(STR_VOBJ_MODE_SHOW+GetValue());
1093 break;
1095 default:
1097 // added to avoid warnings
1101 return ePres;
1104 //------------------------------------------------------------------------
1106 String ScViewObjectModeItem::GetValueText( USHORT nVal ) const
1108 DBG_ASSERT( nVal <= VOBJ_MODE_HIDE, "enum overflow!" );
1110 return ScGlobal::GetRscString( STR_VOBJ_MODE_SHOW + (nVal % 2));
1113 //------------------------------------------------------------------------
1115 USHORT ScViewObjectModeItem::GetValueCount() const
1117 return 2;
1120 //------------------------------------------------------------------------
1122 SfxPoolItem* ScViewObjectModeItem::Clone( SfxItemPool* ) const
1124 return new ScViewObjectModeItem( *this );
1127 //------------------------------------------------------------------------
1129 USHORT ScViewObjectModeItem::GetVersion( USHORT /* nFileVersion */ ) const
1131 return 1;
1134 //------------------------------------------------------------------------
1136 SfxPoolItem* ScViewObjectModeItem::Create(
1137 SvStream& rStream,
1138 USHORT nVersion ) const
1140 if ( nVersion == 0 )
1142 // alte Version mit AllEnumItem -> mit Mode "Show" erzeugen
1143 return new ScViewObjectModeItem( Which() );
1145 else
1147 USHORT nVal;
1148 rStream >> nVal;
1150 //#i80528# adapt to new range eventually
1151 if((USHORT)VOBJ_MODE_HIDE < nVal) nVal = (USHORT)VOBJ_MODE_SHOW;
1153 return new ScViewObjectModeItem( Which(), (ScVObjMode)nVal);
1157 // -----------------------------------------------------------------------
1158 // double
1159 // -----------------------------------------------------------------------
1161 ScDoubleItem::ScDoubleItem( USHORT nWhichP, double nVal )
1162 : SfxPoolItem ( nWhichP ),
1163 nValue ( nVal )
1167 //------------------------------------------------------------------------
1169 ScDoubleItem::ScDoubleItem( const ScDoubleItem& rItem )
1170 : SfxPoolItem ( rItem )
1172 nValue = rItem.nValue;
1175 //------------------------------------------------------------------------
1177 String ScDoubleItem::GetValueText() const
1179 return String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("ScDoubleItem"));
1182 //------------------------------------------------------------------------
1184 int ScDoubleItem::operator==( const SfxPoolItem& rItem ) const
1186 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal Which or Type" );
1187 const ScDoubleItem& _rItem = (const ScDoubleItem&)rItem;
1188 return int(nValue == _rItem.nValue);
1189 //int(nValue == ((const ScDoubleItem&)rItem).nValue);
1192 //------------------------------------------------------------------------
1194 SfxPoolItem* ScDoubleItem::Clone( SfxItemPool* ) const
1196 return new ScDoubleItem( *this );
1199 //------------------------------------------------------------------------
1201 SfxPoolItem* ScDoubleItem::Create( SvStream& rStream, USHORT /* nVer */ ) const
1203 double nTmp=0;
1204 rStream >> nTmp;
1206 ScDoubleItem* pItem = new ScDoubleItem( Which(), nTmp );
1208 return pItem;
1211 //------------------------------------------------------------------------
1213 ScDoubleItem::~ScDoubleItem()
1218 // ============================================================================
1220 ScPageScaleToItem::ScPageScaleToItem() :
1221 SfxPoolItem( ATTR_PAGE_SCALETO ),
1222 mnWidth( 0 ),
1223 mnHeight( 0 )
1227 ScPageScaleToItem::ScPageScaleToItem( sal_uInt16 nWidth, sal_uInt16 nHeight ) :
1228 SfxPoolItem( ATTR_PAGE_SCALETO ),
1229 mnWidth( nWidth ),
1230 mnHeight( nHeight )
1234 ScPageScaleToItem::~ScPageScaleToItem()
1238 ScPageScaleToItem* ScPageScaleToItem::Clone( SfxItemPool* ) const
1240 return new ScPageScaleToItem( *this );
1243 int ScPageScaleToItem::operator==( const SfxPoolItem& rCmp ) const
1245 DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "ScPageScaleToItem::operator== - unequal wid or type" );
1246 const ScPageScaleToItem& rPageCmp = static_cast< const ScPageScaleToItem& >( rCmp );
1247 return ((mnWidth == rPageCmp.mnWidth) && (mnHeight == rPageCmp.mnHeight)) ? 1 : 0;
1250 namespace {
1251 void lclAppendScalePageCount( String& rText, sal_uInt16 nPages )
1253 rText.AppendAscii( ": " );
1254 if( nPages )
1256 String aPages( ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALE_PAGES ) );
1257 aPages.SearchAndReplaceAscii( "%1", String::CreateFromInt32( nPages ) );
1258 rText.Append( aPages );
1260 else
1261 rText.Append( ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALE_AUTO ) );
1263 } // namespace
1265 SfxItemPresentation ScPageScaleToItem::GetPresentation(
1266 SfxItemPresentation ePres, SfxMapUnit, SfxMapUnit, XubString& rText, const IntlWrapper* ) const
1268 rText.Erase();
1269 if( !IsValid() || (ePres == SFX_ITEM_PRESENTATION_NONE) )
1270 return SFX_ITEM_PRESENTATION_NONE;
1272 String aName( ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALETO ) );
1273 String aValue( ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALE_WIDTH ) );
1274 lclAppendScalePageCount( aValue, mnWidth );
1275 aValue.AppendAscii( ", " ).Append( ScGlobal::GetRscString( STR_SCATTR_PAGE_SCALE_HEIGHT ) );
1276 lclAppendScalePageCount( aValue, mnHeight );
1278 switch( ePres )
1280 case SFX_ITEM_PRESENTATION_NONE:
1281 break;
1283 case SFX_ITEM_PRESENTATION_NAMEONLY:
1284 rText = aName;
1285 break;
1287 case SFX_ITEM_PRESENTATION_NAMELESS:
1288 rText = aValue;
1289 break;
1291 case SFX_ITEM_PRESENTATION_COMPLETE:
1292 rText.Assign( aName ).AppendAscii( " (" ).Append( aValue ).Append( ')' );
1293 break;
1295 default:
1296 DBG_ERRORFILE( "ScPageScaleToItem::GetPresentation - unknown presentation mode" );
1297 ePres = SFX_ITEM_PRESENTATION_NONE;
1299 return ePres;
1302 BOOL ScPageScaleToItem::QueryValue( uno::Any& rAny, BYTE nMemberId ) const
1304 BOOL bRet = TRUE;
1305 switch( nMemberId )
1307 case SC_MID_PAGE_SCALETO_WIDTH: rAny <<= mnWidth; break;
1308 case SC_MID_PAGE_SCALETO_HEIGHT: rAny <<= mnHeight; break;
1309 default:
1310 DBG_ERRORFILE( "ScPageScaleToItem::QueryValue - unknown member ID" );
1311 bRet = FALSE;
1313 return bRet;
1316 BOOL ScPageScaleToItem::PutValue( const uno::Any& rAny, BYTE nMemberId )
1318 BOOL bRet = FALSE;
1319 switch( nMemberId )
1321 case SC_MID_PAGE_SCALETO_WIDTH: bRet = rAny >>= mnWidth; break;
1322 case SC_MID_PAGE_SCALETO_HEIGHT: bRet = rAny >>= mnHeight; break;
1323 default:
1324 DBG_ERRORFILE( "ScPageScaleToItem::PutValue - unknown member ID" );
1326 return bRet;
1329 // ============================================================================