1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: svdmodel.cxx,v $
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_svx.hxx"
34 #include <svx/svdmodel.hxx>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <osl/endian.h>
39 #include <rtl/logfile.hxx>
41 #include <tools/urlobj.hxx>
42 #include <unotools/ucbstreamhelper.hxx>
44 #include <tools/string.hxx>
45 #include <svtools/whiter.hxx>
46 #include <svx/xit.hxx>
47 #include <svx/xbtmpit.hxx>
48 #include <svx/xlndsit.hxx>
49 #include <svx/xlnedit.hxx>
50 #include <svx/xflgrit.hxx>
51 #include <svx/xflftrit.hxx>
52 #include <svx/xflhtit.hxx>
53 #include <svx/xlnstit.hxx>
55 #include "svditext.hxx"
56 #include <svx/editeng.hxx> // Fuer EditEngine::CreatePool()
58 #include <svx/xtable.hxx>
60 #include "svditer.hxx"
61 #include <svx/svdtrans.hxx>
62 #include <svx/svdpage.hxx>
63 #include <svx/svdlayer.hxx>
64 #include <svx/svdundo.hxx>
65 #include <svx/svdpool.hxx>
66 #include <svx/svdobj.hxx>
67 #include <svx/svdotext.hxx> // fuer ReformatAllTextObjects und CalcFieldValue
68 #include <svx/svdetc.hxx>
69 #include <svx/svdoutl.hxx>
70 #include <svx/svdoole2.hxx>
71 #include "svdglob.hxx" // Stringcache
72 #include "svdstr.hrc" // Objektname
73 #include "svdoutlinercache.hxx"
76 #include "asiancfg.hxx"
77 #include "fontitem.hxx"
78 #include <svx/colritem.hxx>
79 #include <svx/fhgtitem.hxx>
80 #include <svtools/style.hxx>
81 #include <tools/bigint.hxx>
82 #include <svx/numitem.hxx>
83 #include <bulitem.hxx>
84 #include <svx/outlobj.hxx>
85 #include "forbiddencharacterstable.hxx"
86 #include <svtools/zforlist.hxx>
87 #include <comphelper/processfactory.hxx>
90 #include <tools/tenccvt.hxx>
91 #include <svtools/syslocale.hxx>
94 #include <vcl/svapp.hxx>
95 #include <svx/sdr/properties/properties.hxx>
96 #include <svx/eeitem.hxx>
97 #include <svtools/itemset.hxx>
99 using namespace ::com::sun::star
;
100 using namespace ::com::sun::star::uno
;
101 using namespace ::com::sun::star::lang
;
103 ////////////////////////////////////////////////////////////////////////////////////////////////////
107 SfxUndoManager
* mpUndoManager
;
108 SdrUndoFactory
* mpUndoFactory
;
109 bool mbAllowShapePropertyChangeListener
;
112 ////////////////////////////////////////////////////////////////////////////////////////////////////
115 TYPEINIT1(SdrModel
,SfxBroadcaster
);
116 void SdrModel::ImpCtor(SfxItemPool
* pPool
, ::comphelper::IEmbeddedHelper
* _pEmbeddedHelper
,
117 bool bUseExtColorTable
, bool bLoadRefCounts
)
119 mpImpl
= new SdrModelImpl
;
120 mpImpl
->mpUndoManager
=0;
121 mpImpl
->mpUndoFactory
=0;
122 mpImpl
->mbAllowShapePropertyChangeListener
=false;
123 mbInDestruction
=false;
124 aObjUnit
=SdrEngineDefaults::GetMapFraction();
125 eObjUnit
=SdrEngineDefaults::GetMapUnit();
127 aUIScale
=Fraction(1,1);
133 m_pEmbeddedHelper
=_pEmbeddedHelper
;
135 pHitTestOutliner
=NULL
;
140 pDefaultStyleSheet
=NULL
;
150 bExtColorTable
=FALSE
;
151 mbChanged
= sal_False
;
157 bSaveCompressed
=FALSE
;
160 nSwapGraphicsMode
=SDR_SWAPGRAPHICSMODE_DEFAULT
;
161 bSaveOLEPreview
=FALSE
;
163 bNoBitmapCaching
=FALSE
;
165 nStreamCompressMode
=COMPRESSMODE_NONE
;
166 nStreamNumberFormat
=NUMBERFORMAT_INT_BIGENDIAN
;
174 mpNumberFormatter
= NULL
;
175 bTransparentTextFrames
=FALSE
;
176 bStarDrawPreviewMode
= FALSE
;
177 nStarDrawPreviewMasterPageNum
= SDRPAGE_NOTFOUND
;
178 pModelStorage
= NULL
;
179 mpForbiddenCharactersTable
= NULL
;
180 mbModelLocked
= FALSE
;
181 mpOutlinerCache
= NULL
;
182 mbKernAsianPunctuation
= sal_False
;
183 mbAddExtLeading
= sal_False
;
185 SvxAsianConfig aAsian
;
186 mnCharCompressType
= aAsian
.GetCharDistanceCompression();
189 nStreamNumberFormat
=NUMBERFORMAT_INT_LITTLEENDIAN
;
191 bExtColorTable
=bUseExtColorTable
;
195 pItemPool
=new SdrItemPool(0L, bLoadRefCounts
);
196 // Der Outliner hat keinen eigenen Pool, deshalb den der EditEngine
197 SfxItemPool
* pOutlPool
=EditEngine::CreatePool( bLoadRefCounts
);
198 // OutlinerPool als SecondaryPool des SdrPool
199 pItemPool
->SetSecondaryPool(pOutlPool
);
200 // Merken, dass ich mir die beiden Pools selbst gemacht habe
203 pItemPool
->SetDefaultMetric((SfxMapUnit
)eObjUnit
);
205 // SJ: #95129# using static SdrEngineDefaults only if default SvxFontHeight item is not available
206 const SfxPoolItem
* pPoolItem
= pItemPool
->GetPoolDefaultItem( EE_CHAR_FONTHEIGHT
);
208 nDefTextHgt
= ((SvxFontHeightItem
*)pPoolItem
)->GetHeight();
210 nDefTextHgt
= SdrEngineDefaults::GetFontHeight();
213 pLayerAdmin
=new SdrLayerAdmin
;
214 pLayerAdmin
->SetModel(this);
217 // den DrawOutliner OnDemand erzeugen geht noch nicht, weil ich den Pool
218 // sonst nicht kriege (erst ab 302!)
219 pDrawOutliner
= SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT
, this );
220 ImpSetOutlinerDefaults(pDrawOutliner
, TRUE
);
222 pHitTestOutliner
= SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT
, this );
223 ImpSetOutlinerDefaults(pHitTestOutliner
, TRUE
);
228 SdrModel::SdrModel(SfxItemPool
* pPool
, ::comphelper::IEmbeddedHelper
* pPers
, sal_Bool bLoadRefCounts
):
233 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog
, "svx", "aw93748", "SdrModel::SdrModel(...)" );
236 DBG_CTOR(SdrModel
,NULL
);
237 ImpCtor(pPool
,pPers
,FALSE
, (FASTBOOL
)bLoadRefCounts
);
240 SdrModel::SdrModel(const String
& rPath
, SfxItemPool
* pPool
, ::comphelper::IEmbeddedHelper
* pPers
, sal_Bool bLoadRefCounts
):
246 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog
, "svx", "aw93748", "SdrModel::SdrModel(...)" );
249 DBG_CTOR(SdrModel
,NULL
);
250 ImpCtor(pPool
,pPers
,FALSE
, (FASTBOOL
)bLoadRefCounts
);
253 SdrModel::SdrModel(SfxItemPool
* pPool
, ::comphelper::IEmbeddedHelper
* pPers
, FASTBOOL bUseExtColorTable
, sal_Bool bLoadRefCounts
):
258 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog
, "svx", "aw93748", "SdrModel::SdrModel(...)" );
261 DBG_CTOR(SdrModel
,NULL
);
262 ImpCtor(pPool
,pPers
,bUseExtColorTable
, (FASTBOOL
)bLoadRefCounts
);
265 SdrModel::SdrModel(const String
& rPath
, SfxItemPool
* pPool
, ::comphelper::IEmbeddedHelper
* pPers
, FASTBOOL bUseExtColorTable
, sal_Bool bLoadRefCounts
):
271 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog
, "svx", "aw93748", "SdrModel::SdrModel(...)" );
274 DBG_CTOR(SdrModel
,NULL
);
275 ImpCtor(pPool
,pPers
,bUseExtColorTable
, (FASTBOOL
)bLoadRefCounts
);
278 SdrModel::SdrModel(const SdrModel
& /*rSrcModel*/):
280 tools::WeakBase
< SdrModel
>(),
285 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog
, "svx", "aw93748", "SdrModel::SdrModel(...)" );
288 // noch nicht implementiert
289 DBG_ERROR("SdrModel::CopyCtor() ist noch nicht implementiert");
292 SdrModel::~SdrModel()
295 RTL_LOGFILE_CONTEXT_AUTHOR ( aLog
, "svx", "aw93748", "SdrModel::~SdrModel(...)" );
298 DBG_DTOR(SdrModel
,NULL
);
300 mbInDestruction
= true;
302 Broadcast(SdrHint(HINT_MODELCLEARED
));
304 delete mpOutlinerCache
;
310 ByteString
aStr("Im Dtor des SdrModel steht noch ein offenes Undo rum: \"");
312 aStr
+= ByteString(pAktUndoGroup
->GetComment(), gsl_getSystemTextEncoding());
315 DBG_ERROR(aStr
.GetBuffer());
318 if (pAktUndoGroup
!=NULL
)
319 delete pAktUndoGroup
;
322 ClearModel(sal_True
);
326 // Den DrawOutliner erst nach dem ItemPool loeschen, da
327 // der ItemPool Items des DrawOutliners referenziert !!! (<- das war mal)
328 // Wg. Problem bei Malte Reihenfolge wieder umgestellt.
329 // Loeschen des Outliners vor dem loeschen des ItemPools
330 delete pHitTestOutliner
;
331 delete pDrawOutliner
;
333 // delete StyleSheetPool, derived classes should not do this since
334 // the DrawingEngine may need it in its destrctor (SB)
335 if( mxStyleSheetPool
.is() )
337 Reference
< XComponent
> xComponent( dynamic_cast< cppu::OWeakObject
* >( mxStyleSheetPool
.get() ), UNO_QUERY
);
338 if( xComponent
.is() ) try
340 xComponent
->dispose();
342 catch( RuntimeException
& )
345 mxStyleSheetPool
.clear();
350 // Pools loeschen, falls es meine sind
351 SfxItemPool
* pOutlPool
=pItemPool
->GetSecondaryPool();
352 SfxItemPool::Free(pItemPool
);
353 // Der OutlinerPool muss nach dem ItemPool plattgemacht werden, da der
354 // ItemPool SetItems enthaelt die ihrerseits Items des OutlinerPools
355 // referenzieren (Joe)
356 SfxItemPool::Free(pOutlPool
);
359 if( mpForbiddenCharactersTable
)
360 mpForbiddenCharactersTable
->release();
362 // Tabellen, Listen und Paletten loeschen
368 delete pGradientList
;
371 if(mpNumberFormatter
)
372 delete mpNumberFormatter
;
374 delete mpImpl
->mpUndoFactory
;
378 bool SdrModel::IsInDestruction() const
380 return mbInDestruction
;
383 const SvNumberFormatter
& SdrModel::GetNumberFormatter() const
385 if(!mpNumberFormatter
)
387 // use cast here since from outside view this IS a const method
388 ((SdrModel
*)this)->mpNumberFormatter
= new SvNumberFormatter(
389 ::comphelper::getProcessServiceFactory(), LANGUAGE_SYSTEM
);
392 return *mpNumberFormatter
;
395 // noch nicht implementiert:
396 void SdrModel::operator=(const SdrModel
& /*rSrcModel*/)
398 DBG_ERROR("SdrModel::operator=() ist noch nicht implementiert");
401 FASTBOOL
SdrModel::operator==(const SdrModel
& /*rCmpModel*/) const
403 DBG_ERROR("SdrModel::operator==() ist noch nicht implementiert");
407 void SdrModel::SetSwapGraphics( FASTBOOL bSwap
)
409 bSwapGraphics
= bSwap
;
412 FASTBOOL
SdrModel::IsReadOnly() const
417 void SdrModel::SetReadOnly(FASTBOOL bYes
)
422 ////////////////////////////////////////////////////////////////////////////////////////////////////
424 void SdrModel::SetMaxUndoActionCount(ULONG nAnz
)
428 if (pUndoStack
!=NULL
) {
429 while (pUndoStack
->Count()>nMaxUndoCount
) {
430 delete (SfxUndoAction
*) pUndoStack
->Remove(pUndoStack
->Count());
435 void SdrModel::ClearUndoBuffer()
437 if (pUndoStack
!=NULL
) {
438 while (pUndoStack
->Count()!=0) {
439 delete (SfxUndoAction
*) pUndoStack
->Remove(pUndoStack
->Count()-1);
444 if (pRedoStack
!=NULL
) {
445 while (pRedoStack
->Count()!=0) {
446 delete (SfxUndoAction
*) pRedoStack
->Remove(pRedoStack
->Count()-1);
453 FASTBOOL
SdrModel::Undo()
456 if( mpImpl
->mpUndoManager
)
458 DBG_ERROR("svx::SdrModel::Undo(), method not supported with application undo manager!");
462 SfxUndoAction
* pDo
=(SfxUndoAction
*)GetUndoAction(0);
465 const bool bWasUndoEnabled
= mbUndoEnabled
;
466 mbUndoEnabled
= false;
469 pRedoStack
=new Container(1024,16,16);
470 pRedoStack
->Insert(pUndoStack
->Remove((ULONG
)0),(ULONG
)0);
471 mbUndoEnabled
= bWasUndoEnabled
;
477 FASTBOOL
SdrModel::Redo()
480 if( mpImpl
->mpUndoManager
)
482 DBG_ERROR("svx::SdrModel::Redo(), method not supported with application undo manager!");
486 SfxUndoAction
* pDo
=(SfxUndoAction
*)GetRedoAction(0);
489 const bool bWasUndoEnabled
= mbUndoEnabled
;
490 mbUndoEnabled
= false;
493 pUndoStack
=new Container(1024,16,16);
494 pUndoStack
->Insert(pRedoStack
->Remove((ULONG
)0),(ULONG
)0);
495 mbUndoEnabled
= bWasUndoEnabled
;
501 FASTBOOL
SdrModel::Repeat(SfxRepeatTarget
& rView
)
504 if( mpImpl
->mpUndoManager
)
506 DBG_ERROR("svx::SdrModel::Redo(), method not supported with application undo manager!");
510 SfxUndoAction
* pDo
=(SfxUndoAction
*)GetUndoAction(0);
513 if(pDo
->CanRepeat(rView
))
523 void SdrModel::ImpPostUndoAction(SdrUndoAction
* pUndo
)
525 DBG_ASSERT( mpImpl
->mpUndoManager
== 0, "svx::SdrModel::ImpPostUndoAction(), method not supported with application undo manager!" );
526 if( IsUndoEnabled() )
528 if (aUndoLink
.IsSet())
530 aUndoLink
.Call(pUndo
);
534 if (pUndoStack
==NULL
)
535 pUndoStack
=new Container(1024,16,16);
536 pUndoStack
->Insert(pUndo
,(ULONG
)0);
537 while (pUndoStack
->Count()>nMaxUndoCount
)
539 delete (SfxUndoAction
*)pUndoStack
->Remove(pUndoStack
->Count()-1);
541 if (pRedoStack
!=NULL
)
551 void SdrModel::BegUndo()
553 if( mpImpl
->mpUndoManager
)
556 mpImpl
->mpUndoManager
->EnterListAction(aEmpty
,aEmpty
);
559 else if( IsUndoEnabled() )
561 if(pAktUndoGroup
==NULL
)
563 pAktUndoGroup
= new SdrUndoGroup(*this);
573 void SdrModel::BegUndo(const XubString
& rComment
)
575 if( mpImpl
->mpUndoManager
)
578 mpImpl
->mpUndoManager
->EnterListAction( rComment
, aEmpty
);
581 else if( IsUndoEnabled() )
586 pAktUndoGroup
->SetComment(rComment
);
591 void SdrModel::BegUndo(const XubString
& rComment
, const XubString
& rObjDescr
, SdrRepeatFunc eFunc
)
593 if( mpImpl
->mpUndoManager
)
595 String
aComment(rComment
);
596 if( aComment
.Len() && rObjDescr
.Len() )
598 String
aSearchString(RTL_CONSTASCII_USTRINGPARAM("%1"));
599 aComment
.SearchAndReplace(aSearchString
, rObjDescr
);
602 mpImpl
->mpUndoManager
->EnterListAction( aComment
,aEmpty
);
605 else if( IsUndoEnabled() )
610 pAktUndoGroup
->SetComment(rComment
);
611 pAktUndoGroup
->SetObjDescription(rObjDescr
);
612 pAktUndoGroup
->SetRepeatFunction(eFunc
);
617 void SdrModel::BegUndo(SdrUndoGroup
* pUndoGrp
)
619 if( mpImpl
->mpUndoManager
)
621 DBG_ERROR("svx::SdrModel::BegUndo(), method not supported with application undo manager!" );
624 else if( IsUndoEnabled() )
626 if (pAktUndoGroup
==NULL
)
628 pAktUndoGroup
=pUndoGrp
;
643 void SdrModel::EndUndo()
645 DBG_ASSERT(nUndoLevel
!=0,"SdrModel::EndUndo(): UndoLevel is already 0!");
646 if( mpImpl
->mpUndoManager
)
651 mpImpl
->mpUndoManager
->LeaveListAction();
656 if(pAktUndoGroup
!=NULL
&& IsUndoEnabled())
661 if(pAktUndoGroup
->GetActionCount()!=0)
663 SdrUndoAction
* pUndo
=pAktUndoGroup
;
665 ImpPostUndoAction(pUndo
);
670 delete pAktUndoGroup
;
678 void SdrModel::SetUndoComment(const XubString
& rComment
)
680 DBG_ASSERT(nUndoLevel
!=0,"SdrModel::SetUndoComment(): UndoLevel is on level 0!");
682 if( mpImpl
->mpUndoManager
)
684 DBG_ERROR("svx::SdrModel::SetUndoComment(), method not supported with application undo manager!" );
686 else if( IsUndoEnabled() )
690 pAktUndoGroup
->SetComment(rComment
);
695 void SdrModel::SetUndoComment(const XubString
& rComment
, const XubString
& rObjDescr
)
697 DBG_ASSERT(nUndoLevel
!=0,"SdrModel::SetUndoComment(): UndoLevel is 0!");
698 if( mpImpl
->mpUndoManager
)
700 DBG_ERROR("svx::SdrModel::SetUndoComment(), method not supported with application undo manager!" );
706 pAktUndoGroup
->SetComment(rComment
);
707 pAktUndoGroup
->SetObjDescription(rObjDescr
);
712 void SdrModel::AddUndo(SdrUndoAction
* pUndo
)
714 if( mpImpl
->mpUndoManager
)
716 mpImpl
->mpUndoManager
->AddUndoAction( pUndo
);
718 else if( !IsUndoEnabled() )
724 if (pAktUndoGroup
!=NULL
)
726 pAktUndoGroup
->AddAction(pUndo
);
730 ImpPostUndoAction(pUndo
);
735 void SdrModel::EnableUndo( bool bEnable
)
737 if( mpImpl
->mpUndoManager
)
739 mpImpl
->mpUndoManager
->EnableUndo( bEnable
);
743 mbUndoEnabled
= bEnable
;
747 bool SdrModel::IsUndoEnabled() const
749 if( mpImpl
->mpUndoManager
)
751 return mpImpl
->mpUndoManager
->IsUndoEnabled();
755 return mbUndoEnabled
;
759 ////////////////////////////////////////////////////////////////////////////////////////////////////
761 void SdrModel::ImpCreateTables()
763 // der Writer hat seinen eigenen ColorTable
764 if (!bExtColorTable
) pColorTable
=new XColorTable(aTablePath
,(XOutdevItemPool
*)pItemPool
);
765 pDashList
=new XDashList (aTablePath
,(XOutdevItemPool
*)pItemPool
);
766 pLineEndList
=new XLineEndList (aTablePath
,(XOutdevItemPool
*)pItemPool
);
767 pHatchList
=new XHatchList (aTablePath
,(XOutdevItemPool
*)pItemPool
);
768 pGradientList
=new XGradientList(aTablePath
,(XOutdevItemPool
*)pItemPool
);
769 pBitmapList
=new XBitmapList (aTablePath
,(XOutdevItemPool
*)pItemPool
);
773 void SdrModel::ClearModel(sal_Bool bCalledFromDestructor
)
775 if(bCalledFromDestructor
)
777 mbInDestruction
= true;
781 // delete all drawing pages
782 sal_Int32 nAnz
=GetPageCount();
783 for (i
=nAnz
-1; i
>=0; i
--)
785 DeletePage( (USHORT
)i
);
791 // delete all Masterpages
792 nAnz
=GetMasterPageCount();
793 for(i
=nAnz
-1; i
>=0; i
--)
795 DeleteMasterPage( (USHORT
)i
);
799 MasterPageListChanged();
801 pLayerAdmin
->ClearLayer();
804 SdrModel
* SdrModel::AllocModel() const
806 SdrModel
* pModel
=new SdrModel
;
807 pModel
->SetScaleUnit(eObjUnit
,aObjUnit
);
811 SdrPage
* SdrModel::AllocPage(FASTBOOL bMasterPage
)
813 return new SdrPage(*this,bMasterPage
);
816 void SdrModel::SetTextDefaults() const
818 SetTextDefaults( pItemPool
, nDefTextHgt
);
821 void ImpGetDefaultFontsLanguage( SvxFontItem
& rLatin
, SvxFontItem
& rAsian
, SvxFontItem
& rComplex
)
823 const USHORT nItemCnt
= 3;
825 USHORT nFntType
, nLanguage
;
826 } aOutTypeArr
[ nItemCnt
] = {
827 { DEFAULTFONT_LATIN_TEXT
, LANGUAGE_ENGLISH_US
},
828 { DEFAULTFONT_CJK_TEXT
, LANGUAGE_ENGLISH_US
},
829 { DEFAULTFONT_CTL_TEXT
, LANGUAGE_ARABIC_SAUDI_ARABIA
}
831 SvxFontItem
* aItemArr
[ nItemCnt
] = { &rLatin
, &rAsian
, &rComplex
};
833 for( USHORT n
= 0; n
< nItemCnt
; ++n
)
835 Font
aFnt( OutputDevice::GetDefaultFont(
836 aOutTypeArr
[ n
].nFntType
, aOutTypeArr
[ n
].nLanguage
,
837 DEFAULTFONT_FLAGS_ONLYONE
, 0 ));
838 SvxFontItem
* pI
= aItemArr
[ n
];
839 pI
->GetFamily() = aFnt
.GetFamily();
840 pI
->GetFamilyName() = aFnt
.GetName();
841 pI
->GetStyleName().Erase();
842 pI
->GetPitch() = aFnt
.GetPitch();
843 pI
->GetCharSet() = aFnt
.GetCharSet();
847 void SdrModel::SetTextDefaults( SfxItemPool
* pItemPool
, ULONG nDefTextHgt
)
849 // #95114# set application-language specific dynamic pool language defaults
850 SvxFontItem
aSvxFontItem( EE_CHAR_FONTINFO
) ;
851 SvxFontItem
aSvxFontItemCJK(EE_CHAR_FONTINFO_CJK
);
852 SvxFontItem
aSvxFontItemCTL(EE_CHAR_FONTINFO_CTL
);
853 sal_uInt16
nLanguage(Application::GetSettings().GetLanguage());
855 // get DEFAULTFONT_LATIN_TEXT and set at pool as dynamic default
856 Font
aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_LATIN_TEXT
, nLanguage
, DEFAULTFONT_FLAGS_ONLYONE
, 0));
857 aSvxFontItem
.GetFamily() = aFont
.GetFamily();
858 aSvxFontItem
.GetFamilyName() = aFont
.GetName();
859 aSvxFontItem
.GetStyleName().Erase();
860 aSvxFontItem
.GetPitch() = aFont
.GetPitch();
861 aSvxFontItem
.GetCharSet() = aFont
.GetCharSet();
862 pItemPool
->SetPoolDefaultItem(aSvxFontItem
);
864 // get DEFAULTFONT_CJK_TEXT and set at pool as dynamic default
865 Font
aFontCJK(OutputDevice::GetDefaultFont(DEFAULTFONT_CJK_TEXT
, nLanguage
, DEFAULTFONT_FLAGS_ONLYONE
, 0));
866 aSvxFontItemCJK
.GetFamily() = aFontCJK
.GetFamily();
867 aSvxFontItemCJK
.GetFamilyName() = aFontCJK
.GetName();
868 aSvxFontItemCJK
.GetStyleName().Erase();
869 aSvxFontItemCJK
.GetPitch() = aFontCJK
.GetPitch();
870 aSvxFontItemCJK
.GetCharSet() = aFontCJK
.GetCharSet();
871 pItemPool
->SetPoolDefaultItem(aSvxFontItemCJK
);
873 // get DEFAULTFONT_CTL_TEXT and set at pool as dynamic default
874 Font
aFontCTL(OutputDevice::GetDefaultFont(DEFAULTFONT_CTL_TEXT
, nLanguage
, DEFAULTFONT_FLAGS_ONLYONE
, 0));
875 aSvxFontItemCTL
.GetFamily() = aFontCTL
.GetFamily();
876 aSvxFontItemCTL
.GetFamilyName() = aFontCTL
.GetName();
877 aSvxFontItemCTL
.GetStyleName().Erase();
878 aSvxFontItemCTL
.GetPitch() = aFontCTL
.GetPitch();
879 aSvxFontItemCTL
.GetCharSet() = aFontCTL
.GetCharSet();
880 pItemPool
->SetPoolDefaultItem(aSvxFontItemCTL
);
882 // set dynamic FontHeight defaults
883 pItemPool
->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt
, 100, EE_CHAR_FONTHEIGHT
) );
884 pItemPool
->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt
, 100, EE_CHAR_FONTHEIGHT_CJK
) );
885 pItemPool
->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt
, 100, EE_CHAR_FONTHEIGHT_CTL
) );
887 // set FontColor defaults
888 pItemPool
->SetPoolDefaultItem( SvxColorItem(SdrEngineDefaults::GetFontColor(), EE_CHAR_COLOR
) );
891 SdrOutliner
& SdrModel::GetDrawOutliner(const SdrTextObj
* pObj
) const
893 pDrawOutliner
->SetTextObj(pObj
);
894 return *pDrawOutliner
;
897 boost::shared_ptr
< SdrOutliner
> SdrModel::CreateDrawOutliner(const SdrTextObj
* pObj
)
899 boost::shared_ptr
< SdrOutliner
> xDrawOutliner( SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT
, this ) );
900 ImpSetOutlinerDefaults(xDrawOutliner
.get(), TRUE
);
901 xDrawOutliner
->SetTextObj(pObj
);
902 return xDrawOutliner
;
905 const SdrTextObj
* SdrModel::GetFormattingTextObj() const
907 if (pDrawOutliner
!=NULL
) {
908 return pDrawOutliner
->GetTextObj();
913 void SdrModel::ImpSetOutlinerDefaults( SdrOutliner
* pOutliner
, BOOL bInit
)
915 /**************************************************************************
916 * Initialisierung der Outliner fuer Textausgabe und HitTest
917 **************************************************************************/
920 pOutliner
->EraseVirtualDevice();
921 pOutliner
->SetUpdateMode(FALSE
);
922 pOutliner
->SetEditTextObjectPool(pItemPool
);
923 pOutliner
->SetDefTab(nDefaultTabulator
);
926 pOutliner
->SetRefDevice(GetRefDevice());
927 pOutliner
->SetForbiddenCharsTable(GetForbiddenCharsTable());
928 pOutliner
->SetAsianCompressionMode( mnCharCompressType
);
929 pOutliner
->SetKernAsianPunctuation( IsKernAsianPunctuation() );
930 pOutliner
->SetAddExtLeading( IsAddExtLeading() );
932 if ( !GetRefDevice() )
934 MapMode
aMapMode(eObjUnit
, Point(0,0), aObjUnit
, aObjUnit
);
935 pOutliner
->SetRefMapMode(aMapMode
);
939 void SdrModel::SetRefDevice(OutputDevice
* pDev
)
942 ImpSetOutlinerDefaults( pDrawOutliner
);
943 ImpSetOutlinerDefaults( pHitTestOutliner
);
947 void SdrModel::ImpReformatAllTextObjects()
952 USHORT nAnz
=GetMasterPageCount();
954 for (nNum
=0; nNum
<nAnz
; nNum
++) {
955 GetMasterPage(nNum
)->ReformatAllTextObjects();
958 for (nNum
=0; nNum
<nAnz
; nNum
++) {
959 GetPage(nNum
)->ReformatAllTextObjects();
964 steps over all available pages and sends notify messages to
965 all edge objects that are connected to other objects so that
966 they may reposition itselfs
968 void SdrModel::ImpReformatAllEdgeObjects()
973 sal_uInt16 nAnz
=GetMasterPageCount();
975 for (nNum
=0; nNum
<nAnz
; nNum
++)
977 GetMasterPage(nNum
)->ReformatAllEdgeObjects();
980 for (nNum
=0; nNum
<nAnz
; nNum
++)
982 GetPage(nNum
)->ReformatAllEdgeObjects();
986 SvStream
* SdrModel::GetDocumentStream(SdrDocumentStreamInfo
& /*rStreamInfo*/) const
991 // Die Vorlagenattribute der Zeichenobjekte in harte Attribute verwandeln.
992 void SdrModel::BurnInStyleSheetAttributes()
994 USHORT nAnz
=GetMasterPageCount();
996 for (nNum
=0; nNum
<nAnz
; nNum
++) {
997 GetMasterPage(nNum
)->BurnInStyleSheetAttributes();
1000 for (nNum
=0; nNum
<nAnz
; nNum
++) {
1001 GetPage(nNum
)->BurnInStyleSheetAttributes();
1005 void SdrModel::RefDeviceChanged()
1007 Broadcast(SdrHint(HINT_REFDEVICECHG
));
1008 ImpReformatAllTextObjects();
1011 void SdrModel::SetDefaultFontHeight(ULONG nVal
)
1013 if (nVal
!=nDefTextHgt
) {
1015 Broadcast(SdrHint(HINT_DEFFONTHGTCHG
));
1016 ImpReformatAllTextObjects();
1020 void SdrModel::SetDefaultTabulator(USHORT nVal
)
1022 if (nDefaultTabulator
!=nVal
) {
1023 nDefaultTabulator
=nVal
;
1024 Outliner
& rOutliner
=GetDrawOutliner();
1025 rOutliner
.SetDefTab(nVal
);
1026 Broadcast(SdrHint(HINT_DEFAULTTABCHG
));
1027 ImpReformatAllTextObjects();
1031 void SdrModel::ImpSetUIUnit()
1033 if(0 == aUIScale
.GetNumerator() || 0 == aUIScale
.GetDenominator())
1035 aUIScale
= Fraction(1,1);
1043 // normalize on meters resp. inch
1046 case MAP_100TH_MM
: nUIUnitKomma
+=5; break;
1047 case MAP_10TH_MM
: nUIUnitKomma
+=4; break;
1048 case MAP_MM
: nUIUnitKomma
+=3; break;
1049 case MAP_CM
: nUIUnitKomma
+=2; break;
1050 case MAP_1000TH_INCH
: nUIUnitKomma
+=3; break;
1051 case MAP_100TH_INCH
: nUIUnitKomma
+=2; break;
1052 case MAP_10TH_INCH
: nUIUnitKomma
+=1; break;
1053 case MAP_INCH
: nUIUnitKomma
+=0; break;
1054 case MAP_POINT
: nDiv
=72; break; // 1Pt = 1/72"
1055 case MAP_TWIP
: nDiv
=144; nUIUnitKomma
++; break; // 1Twip = 1/1440"
1056 case MAP_PIXEL
: break;
1057 case MAP_SYSFONT
: break;
1058 case MAP_APPFONT
: break;
1059 case MAP_RELATIVE
: break;
1063 // 1 mile = 8 furlong = 63.360" = 1.609.344,0mm
1064 // 1 furlong = 10 chains = 7.920" = 201.168,0mm
1065 // 1 chain = 4 poles = 792" = 20.116,8mm
1066 // 1 pole = 5 1/2 yd = 198" = 5.029,2mm
1067 // 1 yd = 3 ft = 36" = 914,4mm
1068 // 1 ft = 12 " = 1" = 304,8mm
1071 case FUNIT_NONE
: break;
1073 case FUNIT_100TH_MM
: nUIUnitKomma
-=5; break;
1074 case FUNIT_MM
: nUIUnitKomma
-=3; break;
1075 case FUNIT_CM
: nUIUnitKomma
-=2; break;
1076 case FUNIT_M
: nUIUnitKomma
+=0; break;
1077 case FUNIT_KM
: nUIUnitKomma
+=3; break;
1079 case FUNIT_TWIP
: nMul
=144; nUIUnitKomma
--; break; // 1Twip = 1/1440"
1080 case FUNIT_POINT
: nMul
=72; break; // 1Pt = 1/72"
1081 case FUNIT_PICA
: nMul
=6; break; // 1Pica = 1/6" ?
1082 case FUNIT_INCH
: break; // 1" = 1"
1083 case FUNIT_FOOT
: nDiv
*=12; break; // 1Ft = 12"
1084 case FUNIT_MILE
: nDiv
*=6336; nUIUnitKomma
++; break; // 1mile = 63360"
1086 case FUNIT_CUSTOM
: break;
1087 case FUNIT_PERCENT
: nUIUnitKomma
+=2; break;
1090 // check if mapping is from metric to inch and adapt
1091 const bool bMapInch(IsInch(eObjUnit
));
1092 const bool bUIMetr(IsMetric(eUIUnit
));
1094 if (bMapInch
&& bUIMetr
)
1100 // check if mapping is from inch to metric and adapt
1101 const bool bMapMetr(IsMetric(eObjUnit
));
1102 const bool bUIInch(IsInch(eUIUnit
));
1104 if (bMapMetr
&& bUIInch
)
1110 // use temporary fraction for reduction (fallback to 32bit here),
1111 // may need to be changed in the future, too
1112 if(1 != nMul
|| 1 != nDiv
)
1114 const Fraction
aTemp(static_cast< long >(nMul
), static_cast< long >(nDiv
));
1115 nMul
= aTemp
.GetNumerator();
1116 nDiv
= aTemp
.GetDenominator();
1119 // #i89872# take Unit of Measurement into account
1120 if(1 != aUIScale
.GetDenominator() || 1 != aUIScale
.GetNumerator())
1122 // divide by UIScale
1123 nMul
*= aUIScale
.GetDenominator();
1124 nDiv
*= aUIScale
.GetNumerator();
1127 // shorten trailing zeroes for dividend
1128 while(0 == (nMul
% 10))
1134 // shorten trailing zeroes for divisor
1135 while(0 == (nDiv
% 10))
1141 // end preparations, set member values
1142 aUIUnitFact
= Fraction(sal_Int32(nMul
), sal_Int32(nDiv
));
1143 bUIOnlyKomma
= (nMul
== nDiv
);
1144 TakeUnitStr(eUIUnit
, aUIUnitStr
);
1147 void SdrModel::SetScaleUnit(MapUnit eMap
, const Fraction
& rFrac
)
1149 if (eObjUnit
!=eMap
|| aObjUnit
!=rFrac
) {
1152 pItemPool
->SetDefaultMetric((SfxMapUnit
)eObjUnit
);
1154 ImpSetOutlinerDefaults( pDrawOutliner
);
1155 ImpSetOutlinerDefaults( pHitTestOutliner
);
1156 ImpReformatAllTextObjects(); // #40424#
1160 void SdrModel::SetScaleUnit(MapUnit eMap
)
1162 if (eObjUnit
!=eMap
) {
1164 pItemPool
->SetDefaultMetric((SfxMapUnit
)eObjUnit
);
1166 ImpSetOutlinerDefaults( pDrawOutliner
);
1167 ImpSetOutlinerDefaults( pHitTestOutliner
);
1168 ImpReformatAllTextObjects(); // #40424#
1172 void SdrModel::SetScaleFraction(const Fraction
& rFrac
)
1174 if (aObjUnit
!=rFrac
) {
1177 ImpSetOutlinerDefaults( pDrawOutliner
);
1178 ImpSetOutlinerDefaults( pHitTestOutliner
);
1179 ImpReformatAllTextObjects(); // #40424#
1183 void SdrModel::SetUIUnit(FieldUnit eUnit
)
1185 if (eUIUnit
!=eUnit
) {
1188 ImpReformatAllTextObjects(); // #40424#
1192 void SdrModel::SetUIScale(const Fraction
& rScale
)
1194 if (aUIScale
!=rScale
) {
1197 ImpReformatAllTextObjects(); // #40424#
1201 void SdrModel::SetUIUnit(FieldUnit eUnit
, const Fraction
& rScale
)
1203 if (eUIUnit
!=eUnit
|| aUIScale
!=rScale
) {
1207 ImpReformatAllTextObjects(); // #40424#
1211 void SdrModel::TakeUnitStr(FieldUnit eUnit
, XubString
& rStr
)
1222 case FUNIT_100TH_MM
:
1224 sal_Char aText
[] = "/100mm";
1225 rStr
= UniString(aText
, sizeof(aText
-1));
1230 sal_Char aText
[] = "mm";
1231 rStr
= UniString(aText
, sizeof(aText
-1));
1236 sal_Char aText
[] = "cm";
1237 rStr
= UniString(aText
, sizeof(aText
-1));
1243 rStr
+= sal_Unicode('m');
1248 sal_Char aText
[] = "km";
1249 rStr
= UniString(aText
, sizeof(aText
-1));
1254 sal_Char aText
[] = "twip";
1255 rStr
= UniString(aText
, sizeof(aText
-1));
1260 sal_Char aText
[] = "pt";
1261 rStr
= UniString(aText
, sizeof(aText
-1));
1266 sal_Char aText
[] = "pica";
1267 rStr
= UniString(aText
, sizeof(aText
-1));
1273 rStr
+= sal_Unicode('"');
1278 sal_Char aText
[] = "ft";
1279 rStr
= UniString(aText
, sizeof(aText
-1));
1284 sal_Char aText
[] = "mile(s)";
1285 rStr
= UniString(aText
, sizeof(aText
-1));
1291 rStr
+= sal_Unicode('%');
1297 void SdrModel::TakeMetricStr(long nVal
, XubString
& rStr
, FASTBOOL bNoUnitChars
, sal_Int32 nNumDigits
) const
1300 // change to double precision usage to not loose decimal places after comma
1301 const bool bNegative(nVal
< 0L);
1302 SvtSysLocale aSysLoc
;
1303 const LocaleDataWrapper
& rLoc(aSysLoc
.GetLocaleData());
1304 double fLocalValue(double(nVal
) * double(aUIUnitFact
));
1308 fLocalValue
= -fLocalValue
;
1311 if( -1 == nNumDigits
)
1313 nNumDigits
= rLoc
.getNumDigits();
1316 sal_Int32
nKomma(nUIUnitKomma
);
1318 if(nKomma
> nNumDigits
)
1320 const sal_Int32
nDiff(nKomma
- nNumDigits
);
1321 const double fFactor(pow(10.0, static_cast<const int>(nDiff
)));
1323 fLocalValue
/= fFactor
;
1324 nKomma
= nNumDigits
;
1326 else if(nKomma
< nNumDigits
)
1328 const sal_Int32
nDiff(nNumDigits
- nKomma
);
1329 const double fFactor(pow(10.0, static_cast<const int>(nDiff
)));
1331 fLocalValue
*= fFactor
;
1332 nKomma
= nNumDigits
;
1335 rStr
= UniString::CreateFromInt32(static_cast<sal_Int32
>(fLocalValue
+ 0.5));
1339 // Negatives Komma bedeutet: Nullen dran
1340 sal_Int32
nAnz(-nKomma
);
1342 for(sal_Int32 i
=0; i
<nAnz
; i
++)
1343 rStr
+= sal_Unicode('0');
1348 // #83257# the second condition needs to be <= since inside this loop
1349 // also the leading zero is inserted.
1350 if(nKomma
> 0 && rStr
.Len() <= nKomma
)
1352 // Fuer Komma evtl. vorne Nullen dran
1353 sal_Int32
nAnz(nKomma
- rStr
.Len());
1355 if(nAnz
>= 0 && rLoc
.isNumLeadingZero())
1358 for(sal_Int32 i
=0; i
<nAnz
; i
++)
1359 rStr
.Insert(sal_Unicode('0'), 0);
1362 sal_Unicode
cDec( rLoc
.getNumDecimalSep().GetChar(0) );
1364 // KommaChar einfuegen
1365 sal_Int32
nVorKomma(rStr
.Len() - nKomma
);
1368 rStr
.Insert(cDec
, (xub_StrLen
) nVorKomma
);
1370 if(!rLoc
.isNumTrailingZeros())
1372 while(rStr
.Len() && rStr
.GetChar(rStr
.Len() - 1) == sal_Unicode('0'))
1373 rStr
.Erase(rStr
.Len() - 1);
1375 if(rStr
.Len() && rStr
.GetChar(rStr
.Len() - 1) == cDec
)
1376 rStr
.Erase(rStr
.Len() - 1);
1379 // ggf. Trennpunkte bei jedem Tausender einfuegen
1382 String
aThoSep( rLoc
.getNumThousandSep() );
1383 if ( aThoSep
.Len() > 0 )
1385 sal_Unicode
cTho( aThoSep
.GetChar(0) );
1386 sal_Int32
i(nVorKomma
- 3);
1388 while(i
> 0) // #78311#
1390 rStr
.Insert(cTho
, (xub_StrLen
)i
);
1399 rStr
+= sal_Unicode('0');
1404 rStr
.Insert(sal_Unicode('-'), 0);
1411 void SdrModel::TakeWinkStr(long nWink
, XubString
& rStr
, FASTBOOL bNoDegChar
) const
1413 BOOL
bNeg(nWink
< 0);
1418 rStr
= UniString::CreateFromInt32(nWink
);
1420 SvtSysLocale aSysLoc
;
1421 const LocaleDataWrapper
& rLoc
= aSysLoc
.GetLocaleData();
1424 if(rLoc
.isNumLeadingZero())
1427 while(rStr
.Len() < nAnz
)
1428 rStr
.Insert(sal_Unicode('0'), 0);
1430 rStr
.Insert(rLoc
.getNumDecimalSep().GetChar(0), rStr
.Len() - 2);
1433 rStr
.Insert(sal_Unicode('-'), 0);
1436 rStr
+= DEGREE_CHAR
;
1439 void SdrModel::TakePercentStr(const Fraction
& rVal
, XubString
& rStr
, FASTBOOL bNoPercentChar
) const
1441 INT32
nMul(rVal
.GetNumerator());
1442 INT32
nDiv(rVal
.GetDenominator());
1443 BOOL
bNeg(nMul
< 0);
1458 rStr
= UniString::CreateFromInt32(nMul
);
1461 rStr
.Insert(sal_Unicode('-'), 0);
1464 rStr
+= sal_Unicode('%');
1467 void SdrModel::SetChanged(sal_Bool bFlg
)
1472 void SdrModel::RecalcPageNums(FASTBOOL bMaster
)
1474 Container
& rPL
=*(bMaster
? &maMaPag
: &maPages
);
1475 USHORT nAnz
=USHORT(rPL
.Count());
1477 for (i
=0; i
<nAnz
; i
++) {
1478 SdrPage
* pPg
=(SdrPage
*)(rPL
.GetObject(i
));
1481 if (bMaster
) bMPgNumsDirty
=FALSE
;
1482 else bPagNumsDirty
=FALSE
;
1485 void SdrModel::InsertPage(SdrPage
* pPage
, USHORT nPos
)
1487 USHORT nAnz
=GetPageCount();
1488 if (nPos
>nAnz
) nPos
=nAnz
;
1489 maPages
.Insert(pPage
,nPos
);
1492 pPage
->SetInserted(TRUE
);
1493 pPage
->SetPageNum(nPos
);
1494 pPage
->SetModel(this);
1495 if (nPos
<nAnz
) bPagNumsDirty
=TRUE
;
1497 SdrHint
aHint(HINT_PAGEORDERCHG
);
1498 aHint
.SetPage(pPage
);
1502 void SdrModel::DeletePage(USHORT nPgNum
)
1504 SdrPage
* pPg
=RemovePage(nPgNum
);
1508 SdrPage
* SdrModel::RemovePage(USHORT nPgNum
)
1510 SdrPage
* pPg
=(SdrPage
*)maPages
.Remove(nPgNum
);
1514 pPg
->SetInserted(FALSE
);
1518 SdrHint
aHint(HINT_PAGEORDERCHG
);
1524 void SdrModel::MovePage(USHORT nPgNum
, USHORT nNewPos
)
1526 SdrPage
* pPg
=(SdrPage
*)maPages
.Remove(nPgNum
);
1530 pPg
->SetInserted(FALSE
);
1531 InsertPage(pPg
,nNewPos
);
1535 void SdrModel::InsertMasterPage(SdrPage
* pPage
, USHORT nPos
)
1537 USHORT nAnz
=GetMasterPageCount();
1538 if (nPos
>nAnz
) nPos
=nAnz
;
1539 maMaPag
.Insert(pPage
,nPos
);
1541 MasterPageListChanged();
1542 pPage
->SetInserted(TRUE
);
1543 pPage
->SetPageNum(nPos
);
1544 pPage
->SetModel(this);
1549 SdrHint
aHint(HINT_PAGEORDERCHG
);
1550 aHint
.SetPage(pPage
);
1554 void SdrModel::DeleteMasterPage(USHORT nPgNum
)
1556 SdrPage
* pPg
=RemoveMasterPage(nPgNum
);
1557 if (pPg
!=NULL
) delete pPg
;
1560 SdrPage
* SdrModel::RemoveMasterPage(USHORT nPgNum
)
1562 SdrPage
* pRetPg
=(SdrPage
*)maMaPag
.Remove(nPgNum
);
1564 MasterPageListChanged();
1568 // Nun die Verweise der normalen Zeichenseiten auf die entfernte MasterPage loeschen
1569 sal_uInt16
nPageAnz(GetPageCount());
1571 for(sal_uInt16
np(0); np
< nPageAnz
; np
++)
1573 GetPage(np
)->TRG_ImpMasterPageRemoved(*pRetPg
);
1576 pRetPg
->SetInserted(FALSE
);
1581 SdrHint
aHint(HINT_PAGEORDERCHG
);
1582 aHint
.SetPage(pRetPg
);
1587 void SdrModel::MoveMasterPage(USHORT nPgNum
, USHORT nNewPos
)
1589 SdrPage
* pPg
=(SdrPage
*)maMaPag
.Remove(nPgNum
);
1591 MasterPageListChanged();
1593 pPg
->SetInserted(FALSE
);
1594 maMaPag
.Insert(pPg
,nNewPos
);
1596 MasterPageListChanged();
1600 SdrHint
aHint(HINT_PAGEORDERCHG
);
1605 ////////////////////////////////////////////////////////////////////////////////////////////////////
1607 FASTBOOL
SdrModel::CheckConsistence() const
1611 DBG_CHKTHIS(SdrModel
,NULL
);
1616 ////////////////////////////////////////////////////////////////////////////////////////////////////
1619 void SdrModel::CopyPages(USHORT nFirstPageNum
, USHORT nLastPageNum
,
1621 FASTBOOL bUndo
, FASTBOOL bMoveNoCopy
)
1623 if( bUndo
&& !IsUndoEnabled() )
1627 BegUndo(ImpGetResStr(STR_UndoMergeModel
));
1629 USHORT nPageAnz
=GetPageCount();
1630 USHORT nMaxPage
=nPageAnz
;
1634 if (nFirstPageNum
>nMaxPage
)
1635 nFirstPageNum
=nMaxPage
;
1636 if (nLastPageNum
>nMaxPage
)
1637 nLastPageNum
=nMaxPage
;
1638 FASTBOOL bReverse
=nLastPageNum
<nFirstPageNum
;
1639 if (nDestPos
>nPageAnz
)
1642 // Zunaechst die Zeiger der betroffenen Seiten in einem Array sichern
1643 USHORT nPageNum
=nFirstPageNum
;
1644 USHORT nCopyAnz
=((!bReverse
)?(nLastPageNum
-nFirstPageNum
):(nFirstPageNum
-nLastPageNum
))+1;
1645 SdrPage
** pPagePtrs
=new SdrPage
*[nCopyAnz
];
1647 for(nCopyNum
=0; nCopyNum
<nCopyAnz
; nCopyNum
++)
1649 pPagePtrs
[nCopyNum
]=GetPage(nPageNum
);
1656 // Jetzt die Seiten kopieren
1657 USHORT nDestNum
=nDestPos
;
1658 for (nCopyNum
=0; nCopyNum
<nCopyAnz
; nCopyNum
++)
1660 SdrPage
* pPg
=pPagePtrs
[nCopyNum
];
1661 USHORT nPageNum2
=pPg
->GetPageNum();
1664 const SdrPage
* pPg1
=GetPage(nPageNum2
);
1666 InsertPage(pPg
,nDestNum
);
1668 AddUndo(GetSdrUndoFactory().CreateUndoCopyPage(*pPg
));
1673 // Move ist nicht getestet!
1674 if (nDestNum
>nPageNum2
)
1678 AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*GetPage(nPageNum2
),nPageNum2
,nDestNum
));
1680 pPg
=RemovePage(nPageNum2
);
1681 InsertPage(pPg
,nDestNum
);
1696 void SdrModel::Merge(SdrModel
& rSourceModel
,
1697 USHORT nFirstPageNum
, USHORT nLastPageNum
,
1699 FASTBOOL bMergeMasterPages
, FASTBOOL bAllMasterPages
,
1700 FASTBOOL bUndo
, FASTBOOL bTreadSourceAsConst
)
1702 if (&rSourceModel
==this)
1704 CopyPages(nFirstPageNum
,nLastPageNum
,nDestPos
,bUndo
,!bTreadSourceAsConst
);
1708 if( bUndo
&& !IsUndoEnabled() )
1712 BegUndo(ImpGetResStr(STR_UndoMergeModel
));
1714 USHORT nSrcPageAnz
=rSourceModel
.GetPageCount();
1715 USHORT nSrcMasterPageAnz
=rSourceModel
.GetMasterPageCount();
1716 USHORT nDstMasterPageAnz
=GetMasterPageCount();
1717 FASTBOOL bInsPages
=(nFirstPageNum
<nSrcPageAnz
|| nLastPageNum
<nSrcPageAnz
);
1718 USHORT nMaxSrcPage
=nSrcPageAnz
; if (nMaxSrcPage
!=0) nMaxSrcPage
--;
1719 if (nFirstPageNum
>nMaxSrcPage
) nFirstPageNum
=nMaxSrcPage
;
1720 if (nLastPageNum
>nMaxSrcPage
) nLastPageNum
=nMaxSrcPage
;
1721 FASTBOOL bReverse
=nLastPageNum
<nFirstPageNum
;
1723 USHORT
* pMasterMap
=NULL
;
1724 FASTBOOL
* pMasterNeed
=NULL
;
1725 USHORT nMasterNeed
=0;
1726 if (bMergeMasterPages
&& nSrcMasterPageAnz
!=0) {
1727 // Feststellen, welche MasterPages aus rSrcModel benoetigt werden
1728 pMasterMap
=new USHORT
[nSrcMasterPageAnz
];
1729 pMasterNeed
=new FASTBOOL
[nSrcMasterPageAnz
];
1730 memset(pMasterMap
,0xFF,nSrcMasterPageAnz
*sizeof(USHORT
));
1731 if (bAllMasterPages
) {
1732 memset(pMasterNeed
,TRUE
,nSrcMasterPageAnz
*sizeof(FASTBOOL
));
1734 memset(pMasterNeed
,FALSE
,nSrcMasterPageAnz
*sizeof(FASTBOOL
));
1735 USHORT nAnf
= bReverse
? nLastPageNum
: nFirstPageNum
;
1736 USHORT nEnd
= bReverse
? nFirstPageNum
: nLastPageNum
;
1737 for (USHORT i
=nAnf
; i
<=nEnd
; i
++) {
1738 const SdrPage
* pPg
=rSourceModel
.GetPage(i
);
1739 if(pPg
->TRG_HasMasterPage())
1741 SdrPage
& rMasterPage
= pPg
->TRG_GetMasterPage();
1742 sal_uInt16
nMPgNum(rMasterPage
.GetPageNum());
1744 if(nMPgNum
< nSrcMasterPageAnz
)
1746 pMasterNeed
[nMPgNum
] = TRUE
;
1751 // Nun das Mapping der MasterPages bestimmen
1752 USHORT nAktMaPagNum
=nDstMasterPageAnz
;
1753 for (USHORT i
=0; i
<nSrcMasterPageAnz
; i
++) {
1754 if (pMasterNeed
[i
]) {
1755 pMasterMap
[i
]=nAktMaPagNum
;
1762 // rueberholen der Masterpages
1763 if (pMasterMap
!=NULL
&& pMasterNeed
!=NULL
&& nMasterNeed
!=0) {
1764 for (USHORT i
=nSrcMasterPageAnz
; i
>0;) {
1766 if (pMasterNeed
[i
]) {
1768 if (bTreadSourceAsConst
) {
1769 const SdrPage
* pPg1
=rSourceModel
.GetMasterPage(i
);
1772 pPg
=rSourceModel
.RemoveMasterPage(i
);
1775 // und alle ans einstige Ende des DstModel reinschieben.
1776 // nicht InsertMasterPage() verwenden da die Sache
1777 // inkonsistent ist bis alle drin sind
1778 maMaPag
.Insert(pPg
,nDstMasterPageAnz
);
1780 MasterPageListChanged();
1781 pPg
->SetInserted(TRUE
);
1782 pPg
->SetModel(this);
1784 if (bUndo
) AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pPg
));
1786 DBG_ERROR("SdrModel::Merge(): MasterPage im SourceModel nicht gefunden");
1792 // rueberholen der Zeichenseiten
1794 USHORT nSourcePos
=nFirstPageNum
;
1795 USHORT nMergeCount
=USHORT(Abs((long)((long)nFirstPageNum
-nLastPageNum
))+1);
1796 if (nDestPos
>GetPageCount()) nDestPos
=GetPageCount();
1797 while (nMergeCount
>0) {
1799 if (bTreadSourceAsConst
) {
1800 const SdrPage
* pPg1
=rSourceModel
.GetPage(nSourcePos
);
1803 pPg
=rSourceModel
.RemovePage(nSourcePos
);
1806 InsertPage(pPg
,nDestPos
);
1807 if (bUndo
) AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pPg
));
1808 // und nun zu den MasterPageDescriptoren
1810 if(pPg
->TRG_HasMasterPage())
1812 SdrPage
& rMasterPage
= pPg
->TRG_GetMasterPage();
1813 sal_uInt16
nMaPgNum(rMasterPage
.GetPageNum());
1815 if (bMergeMasterPages
)
1817 sal_uInt16
nNeuNum(0xFFFF);
1821 nNeuNum
= pMasterMap
[nMaPgNum
];
1824 if(nNeuNum
!= 0xFFFF)
1828 AddUndo(GetSdrUndoFactory().CreateUndoPageChangeMasterPage(*pPg
));
1831 pPg
->TRG_SetMasterPage(*GetMasterPage(nNeuNum
));
1833 DBG_ASSERT(nNeuNum
!=0xFFFF,"SdrModel::Merge(): Irgendwas ist krumm beim Mappen der MasterPages");
1835 if (nMaPgNum
>=nDstMasterPageAnz
) {
1836 // Aha, die ist ausserbalb des urspruenglichen Bereichs der Masterpages des DstModel
1837 pPg
->TRG_ClearMasterPage();
1843 DBG_ERROR("SdrModel::Merge(): Zeichenseite im SourceModel nicht gefunden");
1846 if (bReverse
) nSourcePos
--;
1847 else if (bTreadSourceAsConst
) nSourcePos
++;
1852 delete [] pMasterMap
;
1853 delete [] pMasterNeed
;
1859 // Fehlt: Mergen und Mapping der Layer
1860 // an den Objekten sowie an den MasterPageDescriptoren
1861 if (bUndo
) EndUndo();
1864 void SdrModel::SetStarDrawPreviewMode(BOOL bPreview
)
1866 if (!bPreview
&& bStarDrawPreviewMode
&& GetPageCount())
1868 // Das Zuruecksetzen ist nicht erlaubt, da das Model ev. nicht vollstaendig geladen wurde
1869 DBG_ASSERT(FALSE
,"SdrModel::SetStarDrawPreviewMode(): Zuruecksetzen nicht erlaubt, da Model ev. nicht vollstaendig");
1873 bStarDrawPreviewMode
= bPreview
;
1877 uno::Reference
< uno::XInterface
> SdrModel::getUnoModel()
1879 if( !mxUnoModel
.is() )
1880 mxUnoModel
= createUnoModel();
1885 void SdrModel::setUnoModel( ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xModel
)
1887 mxUnoModel
= xModel
;
1890 uno::Reference
< uno::XInterface
> SdrModel::createUnoModel()
1892 DBG_ERROR( "SdrModel::createUnoModel() - base implementation should not be called!" );
1893 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> xInt
;
1897 void SdrModel::setLock( BOOL bLock
)
1899 if( mbModelLocked
!= bLock
)
1901 if( sal_False
== bLock
)
1903 // ReformatAllTextObjects(); #103122# due to a typo in the above if, this code was never
1904 // executed, so I remove it until we discover that we need it here
1905 ImpReformatAllEdgeObjects(); // #103122#
1907 mbModelLocked
= bLock
;
1911 ////////////////////////////////////////////////////////////////////////////////////////////////////
1913 void SdrModel::MigrateItemSet( const SfxItemSet
* pSourceSet
, SfxItemSet
* pDestSet
, SdrModel
* pNewModel
)
1915 if( pSourceSet
&& pDestSet
&& (pSourceSet
!= pDestSet
) )
1917 if( pNewModel
== NULL
)
1920 SfxWhichIter
aWhichIter(*pSourceSet
);
1921 sal_uInt16
nWhich(aWhichIter
.FirstWhich());
1922 const SfxPoolItem
*pPoolItem
;
1926 if(SFX_ITEM_SET
== pSourceSet
->GetItemState(nWhich
, FALSE
, &pPoolItem
))
1928 const SfxPoolItem
* pItem
= pPoolItem
;
1932 case XATTR_FILLBITMAP
:
1933 pItem
= ((XFillBitmapItem
*)pItem
)->checkForUniqueItem( pNewModel
);
1935 case XATTR_LINEDASH
:
1936 pItem
= ((XLineDashItem
*)pItem
)->checkForUniqueItem( pNewModel
);
1938 case XATTR_LINESTART
:
1939 pItem
= ((XLineStartItem
*)pItem
)->checkForUniqueItem( pNewModel
);
1942 pItem
= ((XLineEndItem
*)pItem
)->checkForUniqueItem( pNewModel
);
1944 case XATTR_FILLGRADIENT
:
1945 pItem
= ((XFillGradientItem
*)pItem
)->checkForUniqueItem( pNewModel
);
1947 case XATTR_FILLFLOATTRANSPARENCE
:
1948 // #85953# allow all kinds of XFillFloatTransparenceItem to be set
1949 pItem
= ((XFillFloatTransparenceItem
*)pItem
)->checkForUniqueItem( pNewModel
);
1951 case XATTR_FILLHATCH
:
1952 pItem
= ((XFillHatchItem
*)pItem
)->checkForUniqueItem( pNewModel
);
1959 pDestSet
->Put(*pItem
);
1961 // delete item if it was a generated one
1962 if( pItem
!= pPoolItem
)
1963 delete (SfxPoolItem
*)pItem
;
1966 nWhich
= aWhichIter
.NextWhich();
1971 ////////////////////////////////////////////////////////////////////////////////////////////////////
1973 void SdrModel::SetForbiddenCharsTable( vos::ORef
<SvxForbiddenCharactersTable
> xForbiddenChars
)
1975 if( mpForbiddenCharactersTable
)
1976 mpForbiddenCharactersTable
->release();
1978 mpForbiddenCharactersTable
= xForbiddenChars
.getBodyPtr();
1980 if( mpForbiddenCharactersTable
)
1981 mpForbiddenCharactersTable
->acquire();
1983 ImpSetOutlinerDefaults( pDrawOutliner
);
1984 ImpSetOutlinerDefaults( pHitTestOutliner
);
1987 vos::ORef
<SvxForbiddenCharactersTable
> SdrModel::GetForbiddenCharsTable() const
1989 return mpForbiddenCharactersTable
;
1992 void SdrModel::SetCharCompressType( UINT16 nType
)
1994 if( nType
!= mnCharCompressType
)
1996 mnCharCompressType
= nType
;
1997 ImpSetOutlinerDefaults( pDrawOutliner
);
1998 ImpSetOutlinerDefaults( pHitTestOutliner
);
2002 void SdrModel::SetKernAsianPunctuation( sal_Bool bEnabled
)
2004 if( mbKernAsianPunctuation
!= bEnabled
)
2006 mbKernAsianPunctuation
= bEnabled
;
2007 ImpSetOutlinerDefaults( pDrawOutliner
);
2008 ImpSetOutlinerDefaults( pHitTestOutliner
);
2012 void SdrModel::SetAddExtLeading( sal_Bool bEnabled
)
2014 if( mbAddExtLeading
!= bEnabled
)
2016 mbAddExtLeading
= bEnabled
;
2017 ImpSetOutlinerDefaults( pDrawOutliner
);
2018 ImpSetOutlinerDefaults( pHitTestOutliner
);
2022 void SdrModel::ReformatAllTextObjects()
2024 ImpReformatAllTextObjects();
2027 FASTBOOL
SdrModel::HasTransparentObjects( BOOL bCheckForAlphaChannel
) const
2029 FASTBOOL bRet
= FALSE
;
2032 for( n
= 0, nCount
= GetMasterPageCount(); ( n
< nCount
) && !bRet
; n
++ )
2033 if( GetMasterPage( n
)->HasTransparentObjects( bCheckForAlphaChannel
) )
2038 for( n
= 0, nCount
= GetPageCount(); ( n
< nCount
) && !bRet
; n
++ )
2039 if( GetPage( n
)->HasTransparentObjects( bCheckForAlphaChannel
) )
2046 SdrOutliner
* SdrModel::createOutliner( USHORT nOutlinerMode
)
2048 if( NULL
== mpOutlinerCache
)
2049 mpOutlinerCache
= new SdrOutlinerCache(this);
2051 return mpOutlinerCache
->createOutliner( nOutlinerMode
);
2054 void SdrModel::disposeOutliner( SdrOutliner
* pOutliner
)
2056 if( mpOutlinerCache
)
2058 mpOutlinerCache
->disposeOutliner( pOutliner
);
2066 SvxNumType
SdrModel::GetPageNumType() const
2071 const SdrPage
* SdrModel::GetPage(sal_uInt16 nPgNum
) const
2073 DBG_ASSERT(nPgNum
< maPages
.Count(), "SdrModel::GetPage: Access out of range (!)");
2074 return (SdrPage
*)(maPages
.GetObject(nPgNum
));
2077 SdrPage
* SdrModel::GetPage(sal_uInt16 nPgNum
)
2079 DBG_ASSERT(nPgNum
< maPages
.Count(), "SdrModel::GetPage: Access out of range (!)");
2080 return (SdrPage
*)(maPages
.GetObject(nPgNum
));
2083 sal_uInt16
SdrModel::GetPageCount() const
2085 return sal_uInt16(maPages
.Count());
2088 void SdrModel::PageListChanged()
2092 const SdrPage
* SdrModel::GetMasterPage(sal_uInt16 nPgNum
) const
2094 DBG_ASSERT(nPgNum
< maMaPag
.Count(), "SdrModel::GetMasterPage: Access out of range (!)");
2095 return (SdrPage
*)(maMaPag
.GetObject(nPgNum
));
2098 SdrPage
* SdrModel::GetMasterPage(sal_uInt16 nPgNum
)
2100 DBG_ASSERT(nPgNum
< maMaPag
.Count(), "SdrModel::GetMasterPage: Access out of range (!)");
2101 return (SdrPage
*)(maMaPag
.GetObject(nPgNum
));
2104 sal_uInt16
SdrModel::GetMasterPageCount() const
2106 return sal_uInt16(maMaPag
.Count());
2109 void SdrModel::MasterPageListChanged()
2113 void SdrModel::SetSdrUndoManager( SfxUndoManager
* pUndoManager
)
2115 mpImpl
->mpUndoManager
= pUndoManager
;
2118 SdrUndoFactory
& SdrModel::GetSdrUndoFactory() const
2120 if( !mpImpl
->mpUndoFactory
)
2121 mpImpl
->mpUndoFactory
= new SdrUndoFactory
;
2122 return *mpImpl
->mpUndoFactory
;
2125 void SdrModel::SetSdrUndoFactory( SdrUndoFactory
* pUndoFactory
)
2127 if( pUndoFactory
&& (pUndoFactory
!= mpImpl
->mpUndoFactory
) )
2129 delete mpImpl
->mpUndoFactory
;
2130 mpImpl
->mpUndoFactory
= pUndoFactory
;
2134 /** cl: added this for OJ to complete his reporting engine, does not work
2135 correctly so only enable it for his model */
2136 bool SdrModel::IsAllowShapePropertyChangeListener() const
2138 return mpImpl
&& mpImpl
->mbAllowShapePropertyChangeListener
;
2141 void SdrModel::SetAllowShapePropertyChangeListener( bool bAllow
)
2145 mpImpl
->mbAllowShapePropertyChangeListener
= bAllow
;
2149 const ::com::sun::star::uno::Sequence
< sal_Int8
>& SdrModel::getUnoTunnelImplementationId()
2151 static ::com::sun::star::uno::Sequence
< sal_Int8
> * pSeq
= 0;
2154 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
2157 static Sequence
< sal_Int8
> aSeq( 16 );
2158 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
2165 ////////////////////////////////////////////////////////////////////////////////////////////////////
2167 TYPEINIT1(SdrHint
,SfxHint
);
2173 meHint(HINT_UNKNOWN
)
2177 SdrHint::SdrHint(SdrHintKind eNewHint
)
2185 SdrHint::SdrHint(const SdrObject
& rNewObj
)
2186 : mpPage(rNewObj
.GetPage()),
2188 mpObjList(rNewObj
.GetObjList()),
2191 maRectangle
= rNewObj
.GetLastBoundRect();
2194 SdrHint::SdrHint(const SdrObject
& rNewObj
, const Rectangle
& rRect
)
2195 : mpPage(rNewObj
.GetPage()),
2197 mpObjList(rNewObj
.GetObjList()),
2200 maRectangle
= rRect
;
2203 void SdrHint::SetPage(const SdrPage
* pNewPage
)
2208 void SdrHint::SetObjList(const SdrObjList
* pNewOL
)
2213 void SdrHint::SetObject(const SdrObject
* pNewObj
)
2218 void SdrHint::SetKind(SdrHintKind eNewKind
)
2223 void SdrHint::SetRect(const Rectangle
& rNewRect
)
2225 maRectangle
= rNewRect
;
2228 const SdrPage
* SdrHint::GetPage() const
2233 const SdrObjList
* SdrHint::GetObjList() const
2238 const SdrObject
* SdrHint::GetObject() const
2243 SdrHintKind
SdrHint::GetKind() const
2248 const Rectangle
& SdrHint::GetRect() const