Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <svx/svdmodel.hxx>
22 :
23 : #include <math.h>
24 :
25 : #include <osl/endian.h>
26 : #include <rtl/logfile.hxx>
27 : #include <rtl/strbuf.hxx>
28 :
29 : #include <com/sun/star/lang/XComponent.hpp>
30 : #include <com/sun/star/document/XStorageBasedDocument.hpp>
31 : #include <com/sun/star/embed/ElementModes.hpp>
32 :
33 : #include <unotools/ucbstreamhelper.hxx>
34 :
35 : #include <tools/string.hxx>
36 : #include <svl/whiter.hxx>
37 : #include <svx/xit.hxx>
38 : #include <svx/xbtmpit.hxx>
39 : #include <svx/xlndsit.hxx>
40 : #include <svx/xlnedit.hxx>
41 : #include <svx/xflgrit.hxx>
42 : #include <svx/xflftrit.hxx>
43 : #include <svx/xflhtit.hxx>
44 : #include <svx/xlnstit.hxx>
45 :
46 : #include "svx/svditext.hxx"
47 : #include <editeng/editeng.hxx> // for EditEngine::CreatePool()
48 :
49 : #include <svx/xtable.hxx>
50 :
51 : #include "svx/svditer.hxx"
52 : #include <svx/svdtrans.hxx>
53 : #include <svx/svdpage.hxx>
54 : #include <svx/svdlayer.hxx>
55 : #include <svx/svdundo.hxx>
56 : #include <svx/svdpool.hxx>
57 : #include <svx/svdobj.hxx>
58 : #include <svx/svdotext.hxx> // for ReformatAllTextObjects and CalcFieldValue
59 : #include <svx/svdetc.hxx>
60 : #include <svx/svdoutl.hxx>
61 : #include <svx/svdoole2.hxx>
62 : #include "svx/svdglob.hxx" // StringCache
63 : #include "svx/svdstr.hrc" // object's name
64 : #include "svdoutlinercache.hxx"
65 :
66 : #include "svx/xflclit.hxx"
67 : #include "svx/xflhtit.hxx"
68 : #include "svx/xlnclit.hxx"
69 :
70 : #include "officecfg/Office/Common.hxx"
71 : #include "editeng/fontitem.hxx"
72 : #include <editeng/colritem.hxx>
73 : #include <editeng/fhgtitem.hxx>
74 : #include <svl/style.hxx>
75 : #include <editeng/numitem.hxx>
76 : #include <editeng/bulitem.hxx>
77 : #include <editeng/outlobj.hxx>
78 : #include "editeng/forbiddencharacterstable.hxx"
79 : #include <svl/zforlist.hxx>
80 : #include <comphelper/servicehelper.hxx>
81 : #include <comphelper/storagehelper.hxx>
82 :
83 : #include <tools/tenccvt.hxx>
84 : #include <unotools/syslocale.hxx>
85 :
86 : #include <vcl/svapp.hxx>
87 : #include <svx/sdr/properties/properties.hxx>
88 : #include <editeng/eeitem.hxx>
89 : #include <svl/itemset.hxx>
90 :
91 : using namespace ::com::sun::star;
92 : using namespace ::com::sun::star::uno;
93 : using namespace ::com::sun::star::lang;
94 :
95 : ////////////////////////////////////////////////////////////////////////////////////////////////////
96 :
97 : struct SdrModelImpl
98 : {
99 : SfxUndoManager* mpUndoManager;
100 : SdrUndoFactory* mpUndoFactory;
101 : bool mbAllowShapePropertyChangeListener;
102 : };
103 :
104 : ////////////////////////////////////////////////////////////////////////////////////////////////////
105 :
106 : DBG_NAME(SdrModel)
107 246 : TYPEINIT1(SdrModel,SfxBroadcaster);
108 758 : void SdrModel::ImpCtor(SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* _pEmbeddedHelper,
109 : bool bUseExtColorTable, bool bLoadRefCounts)
110 : {
111 758 : mpImpl = new SdrModelImpl;
112 758 : mpImpl->mpUndoManager=0;
113 758 : mpImpl->mpUndoFactory=0;
114 758 : mpImpl->mbAllowShapePropertyChangeListener = false;
115 758 : mbInDestruction = false;
116 758 : aObjUnit=SdrEngineDefaults::GetMapFraction();
117 758 : eObjUnit=SdrEngineDefaults::GetMapUnit();
118 758 : eUIUnit=FUNIT_MM;
119 758 : aUIScale=Fraction(1,1);
120 758 : nUIUnitKomma=0;
121 758 : bUIOnlyKomma=sal_False;
122 758 : pLayerAdmin=NULL;
123 758 : pItemPool=pPool;
124 758 : bMyPool=sal_False;
125 758 : m_pEmbeddedHelper=_pEmbeddedHelper;
126 758 : pDrawOutliner=NULL;
127 758 : pHitTestOutliner=NULL;
128 758 : pRefOutDev=NULL;
129 758 : nProgressAkt=0;
130 758 : nProgressMax=0;
131 758 : nProgressOfs=0;
132 758 : pDefaultStyleSheet=NULL;
133 758 : pLinkManager=NULL;
134 758 : pUndoStack=NULL;
135 758 : pRedoStack=NULL;
136 758 : nMaxUndoCount=16;
137 758 : pAktUndoGroup=NULL;
138 758 : nUndoLevel=0;
139 758 : mbUndoEnabled=true;
140 758 : nProgressPercent=0;
141 758 : nLoadVersion=0;
142 758 : bExtColorTable=sal_False;
143 758 : mbChanged = sal_False;
144 758 : bInfoChanged=sal_False;
145 758 : bPagNumsDirty=sal_False;
146 758 : bMPgNumsDirty=sal_False;
147 758 : bPageNotValid=sal_False;
148 758 : bSavePortable=sal_False;
149 758 : bSaveCompressed=sal_False;
150 758 : bSaveNative=sal_False;
151 758 : bSwapGraphics=sal_False;
152 758 : nSwapGraphicsMode=SDR_SWAPGRAPHICSMODE_DEFAULT;
153 758 : bSaveOLEPreview=sal_False;
154 758 : bPasteResize=sal_False;
155 758 : bNoBitmapCaching=sal_False;
156 758 : bReadOnly=sal_False;
157 758 : nStreamCompressMode=COMPRESSMODE_NONE;
158 758 : nStreamNumberFormat=NUMBERFORMAT_INT_BIGENDIAN;
159 758 : nDefaultTabulator=0;
160 758 : mpNumberFormatter = NULL;
161 758 : bTransparentTextFrames=sal_False;
162 758 : bStarDrawPreviewMode = sal_False;
163 758 : nStarDrawPreviewMasterPageNum = SDRPAGE_NOTFOUND;
164 758 : mpForbiddenCharactersTable = NULL;
165 758 : mbModelLocked = false;
166 758 : mpOutlinerCache = NULL;
167 758 : mbKernAsianPunctuation = sal_False;
168 758 : mbAddExtLeading = sal_False;
169 758 : mnHandoutPageCount = 0;
170 :
171 : mnCharCompressType =
172 : officecfg::Office::Common::AsianLayout::CompressCharacterDistance::
173 758 : get();
174 :
175 : #ifdef OSL_LITENDIAN
176 758 : nStreamNumberFormat=NUMBERFORMAT_INT_LITTLEENDIAN;
177 : #endif
178 758 : bExtColorTable=bUseExtColorTable;
179 :
180 758 : if ( pPool == NULL )
181 : {
182 228 : pItemPool=new SdrItemPool(0L, bLoadRefCounts);
183 : // Outliner doesn't have its own Pool, so use the EditEngine's
184 228 : SfxItemPool* pOutlPool=EditEngine::CreatePool( bLoadRefCounts );
185 : // OutlinerPool as SecondaryPool of SdrPool
186 228 : pItemPool->SetSecondaryPool(pOutlPool);
187 : // remember that I created both pools myself
188 228 : bMyPool=sal_True;
189 : }
190 758 : pItemPool->SetDefaultMetric((SfxMapUnit)eObjUnit);
191 :
192 : // using static SdrEngineDefaults only if default SvxFontHeight item is not available
193 758 : const SfxPoolItem* pPoolItem = pItemPool->GetPoolDefaultItem( EE_CHAR_FONTHEIGHT );
194 758 : if ( pPoolItem )
195 530 : nDefTextHgt = ((SvxFontHeightItem*)pPoolItem)->GetHeight();
196 : else
197 228 : nDefTextHgt = SdrEngineDefaults::GetFontHeight();
198 :
199 758 : pItemPool->SetPoolDefaultItem( SdrTextWordWrapItem( sal_False ) );
200 :
201 758 : SetTextDefaults();
202 758 : pLayerAdmin=new SdrLayerAdmin;
203 758 : pLayerAdmin->SetModel(this);
204 758 : ImpSetUIUnit();
205 :
206 : // can't create DrawOutliner OnDemand, because I can't get the Pool,
207 : // then (only from 302 onwards!)
208 758 : pDrawOutliner = SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT, this );
209 758 : ImpSetOutlinerDefaults(pDrawOutliner, sal_True);
210 :
211 758 : pHitTestOutliner = SdrMakeOutliner( OUTLINERMODE_TEXTOBJECT, this );
212 758 : ImpSetOutlinerDefaults(pHitTestOutliner, sal_True);
213 :
214 758 : ImpCreateTables();
215 758 : }
216 :
217 0 : SdrModel::SdrModel(SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* pPers, sal_Bool bLoadRefCounts):
218 : aReadDate( DateTime::EMPTY ),
219 : maMaPag(),
220 0 : maPages()
221 : {
222 : #ifdef TIMELOG
223 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "svx", "aw93748", "SdrModel::SdrModel(...)" );
224 : #endif
225 :
226 : DBG_CTOR(SdrModel,NULL);
227 0 : ImpCtor(pPool, pPers, false, (bool)bLoadRefCounts);
228 0 : }
229 :
230 122 : SdrModel::SdrModel(const String& rPath, SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* pPers, sal_Bool bLoadRefCounts):
231 : aReadDate( DateTime::EMPTY ),
232 : maMaPag(),
233 : maPages(),
234 122 : aTablePath(rPath)
235 : {
236 : #ifdef TIMELOG
237 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "svx", "aw93748", "SdrModel::SdrModel(...)" );
238 : #endif
239 :
240 : DBG_CTOR(SdrModel,NULL);
241 122 : ImpCtor(pPool, pPers, false, (bool)bLoadRefCounts);
242 122 : }
243 :
244 0 : SdrModel::SdrModel(SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* pPers, bool bUseExtColorTable, sal_Bool bLoadRefCounts):
245 : aReadDate( DateTime::EMPTY ),
246 : maMaPag(),
247 0 : maPages()
248 : {
249 : #ifdef TIMELOG
250 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "svx", "aw93748", "SdrModel::SdrModel(...)" );
251 : #endif
252 :
253 : DBG_CTOR(SdrModel,NULL);
254 0 : ImpCtor(pPool,pPers,bUseExtColorTable, (bool)bLoadRefCounts);
255 0 : }
256 :
257 636 : SdrModel::SdrModel(const String& rPath, SfxItemPool* pPool, ::comphelper::IEmbeddedHelper* pPers, bool bUseExtColorTable, sal_Bool bLoadRefCounts):
258 : aReadDate( DateTime::EMPTY ),
259 : maMaPag(),
260 : maPages(),
261 636 : aTablePath(rPath)
262 : {
263 : #ifdef TIMELOG
264 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "svx", "aw93748", "SdrModel::SdrModel(...)" );
265 : #endif
266 :
267 : DBG_CTOR(SdrModel,NULL);
268 636 : ImpCtor(pPool,pPers,bUseExtColorTable, (bool)bLoadRefCounts);
269 636 : }
270 :
271 0 : SdrModel::SdrModel(const SdrModel& /*rSrcModel*/):
272 : SfxBroadcaster(),
273 : tools::WeakBase< SdrModel >(),
274 : aReadDate( DateTime::EMPTY ),
275 : maMaPag(),
276 0 : maPages()
277 : {
278 : #ifdef TIMELOG
279 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "svx", "aw93748", "SdrModel::SdrModel(...)" );
280 : #endif
281 :
282 : // not yet implemented
283 : OSL_FAIL("SdrModel::CopyCtor() is not yet implemented.");
284 0 : }
285 :
286 2988 : SdrModel::~SdrModel()
287 : {
288 : #ifdef TIMELOG
289 : RTL_LOGFILE_CONTEXT_AUTHOR ( aLog, "svx", "aw93748", "SdrModel::~SdrModel(...)" );
290 : #endif
291 :
292 : DBG_DTOR(SdrModel,NULL);
293 :
294 332 : mbInDestruction = true;
295 :
296 332 : Broadcast(SdrHint(HINT_MODELCLEARED));
297 :
298 332 : delete mpOutlinerCache;
299 :
300 332 : ClearUndoBuffer();
301 : #ifdef DBG_UTIL
302 : if(pAktUndoGroup)
303 : {
304 : rtl::OStringBuffer aStr(RTL_CONSTASCII_STRINGPARAM(
305 : "In the Dtor of the SdrModel there is an open Undo left: \""));
306 : aStr.append(rtl::OUStringToOString(pAktUndoGroup->GetComment(), osl_getThreadTextEncoding()))
307 : .append('\"');
308 : OSL_FAIL(aStr.getStr());
309 : }
310 : #endif
311 332 : if (pAktUndoGroup!=NULL)
312 0 : delete pAktUndoGroup;
313 :
314 332 : ClearModel(sal_True);
315 :
316 332 : delete pLayerAdmin;
317 :
318 : // Delete DrawOutliner only after deleting ItemPool, because ItemPool
319 : // references Items of the DrawOutliner!
320 332 : delete pHitTestOutliner;
321 332 : delete pDrawOutliner;
322 :
323 : // delete StyleSheetPool, derived classes should not do this since
324 : // the DrawingEngine may need it in its destructor
325 332 : if( mxStyleSheetPool.is() )
326 : {
327 36 : Reference< XComponent > xComponent( dynamic_cast< cppu::OWeakObject* >( mxStyleSheetPool.get() ), UNO_QUERY );
328 36 : if( xComponent.is() ) try
329 : {
330 36 : xComponent->dispose();
331 : }
332 0 : catch( RuntimeException& )
333 : {
334 : }
335 36 : mxStyleSheetPool.clear();
336 : }
337 :
338 332 : if (bMyPool)
339 : {
340 : // delete Pools if they're mine
341 210 : SfxItemPool* pOutlPool=pItemPool->GetSecondaryPool();
342 210 : SfxItemPool::Free(pItemPool);
343 : // OutlinerPool has to be deleted after deleting ItemPool, because
344 : // ItemPool contains SetItems that themselves reference Items from OutlinerPool.
345 210 : SfxItemPool::Free(pOutlPool);
346 : }
347 :
348 332 : if( mpForbiddenCharactersTable )
349 162 : mpForbiddenCharactersTable->release();
350 :
351 332 : if(mpNumberFormatter)
352 0 : delete mpNumberFormatter;
353 :
354 332 : delete mpImpl->mpUndoFactory;
355 332 : delete mpImpl;
356 2656 : }
357 :
358 96 : bool SdrModel::IsInDestruction() const
359 : {
360 96 : return mbInDestruction;
361 : }
362 :
363 : // not yet implemented
364 0 : void SdrModel::operator=(const SdrModel&)
365 : {
366 : OSL_FAIL("SdrModel::operator=() is not yet implemented.");
367 0 : }
368 :
369 0 : bool SdrModel::operator==(const SdrModel&) const
370 : {
371 : OSL_FAIL("SdrModel::operator==() is not yet implemented");
372 0 : return sal_False;
373 : }
374 :
375 672 : void SdrModel::SetSwapGraphics( bool bSwap )
376 : {
377 672 : bSwapGraphics = bSwap;
378 672 : }
379 :
380 0 : bool SdrModel::IsReadOnly() const
381 : {
382 0 : return bReadOnly;
383 : }
384 :
385 0 : void SdrModel::SetReadOnly(bool bYes)
386 : {
387 0 : bReadOnly=bYes;
388 0 : }
389 :
390 : ////////////////////////////////////////////////////////////////////////////////////////////////////
391 :
392 250 : void SdrModel::SetMaxUndoActionCount(sal_uIntPtr nAnz)
393 : {
394 250 : if (nAnz<1) nAnz=1;
395 250 : nMaxUndoCount=nAnz;
396 250 : if (pUndoStack!=NULL) {
397 0 : while (pUndoStack->size()>nMaxUndoCount) {
398 0 : delete pUndoStack->back();
399 0 : pUndoStack->pop_back();
400 : }
401 : }
402 250 : }
403 :
404 582 : void SdrModel::ClearUndoBuffer()
405 : {
406 582 : if (pUndoStack!=NULL) {
407 246 : while (!pUndoStack->empty()) {
408 82 : delete pUndoStack->back();
409 82 : pUndoStack->pop_back();
410 : }
411 82 : delete pUndoStack;
412 82 : pUndoStack=NULL;
413 : }
414 582 : if (pRedoStack!=NULL) {
415 0 : while (!pRedoStack->empty()) {
416 0 : delete pRedoStack->back();
417 0 : pRedoStack->pop_back();
418 : }
419 0 : delete pRedoStack;
420 0 : pRedoStack=NULL;
421 : }
422 582 : }
423 :
424 0 : bool SdrModel::HasUndoActions() const
425 : {
426 0 : return pUndoStack && !pUndoStack->empty();
427 : }
428 :
429 0 : bool SdrModel::HasRedoActions() const
430 : {
431 0 : return pRedoStack && !pRedoStack->empty();
432 : }
433 :
434 0 : bool SdrModel::Undo()
435 : {
436 0 : bool bRet = false;
437 0 : if( mpImpl->mpUndoManager )
438 : {
439 : OSL_FAIL("svx::SdrModel::Undo(), method not supported with application undo manager!");
440 : }
441 : else
442 : {
443 0 : SfxUndoAction* pDo = HasUndoActions() ? pUndoStack->front() : NULL;
444 0 : if(pDo!=NULL)
445 : {
446 0 : const bool bWasUndoEnabled = mbUndoEnabled;
447 0 : mbUndoEnabled = false;
448 0 : pDo->Undo();
449 0 : if(pRedoStack==NULL)
450 0 : pRedoStack=new std::deque<SfxUndoAction*>;
451 0 : SfxUndoAction* p = pUndoStack->front();
452 0 : pUndoStack->pop_front();
453 0 : pRedoStack->push_front(p);
454 0 : mbUndoEnabled = bWasUndoEnabled;
455 : }
456 : }
457 0 : return bRet;
458 : }
459 :
460 0 : bool SdrModel::Redo()
461 : {
462 0 : bool bRet = false;
463 0 : if( mpImpl->mpUndoManager )
464 : {
465 : OSL_FAIL("svx::SdrModel::Redo(), method not supported with application undo manager!");
466 : }
467 : else
468 : {
469 0 : SfxUndoAction* pDo = HasRedoActions() ? pRedoStack->front() : NULL;
470 0 : if(pDo!=NULL)
471 : {
472 0 : const bool bWasUndoEnabled = mbUndoEnabled;
473 0 : mbUndoEnabled = false;
474 0 : pDo->Redo();
475 0 : if(pUndoStack==NULL)
476 0 : pUndoStack=new std::deque<SfxUndoAction*>;
477 0 : SfxUndoAction* p = pRedoStack->front();
478 0 : pRedoStack->pop_front();
479 0 : pUndoStack->push_front(p);
480 0 : mbUndoEnabled = bWasUndoEnabled;
481 : }
482 : }
483 0 : return bRet;
484 : }
485 :
486 0 : bool SdrModel::Repeat(SfxRepeatTarget& rView)
487 : {
488 0 : bool bRet = false;
489 0 : if( mpImpl->mpUndoManager )
490 : {
491 : OSL_FAIL("svx::SdrModel::Redo(), method not supported with application undo manager!");
492 : }
493 : else
494 : {
495 0 : SfxUndoAction* pDo = HasUndoActions() ? pUndoStack->front() : NULL;
496 0 : if(pDo!=NULL)
497 : {
498 0 : if(pDo->CanRepeat(rView))
499 : {
500 0 : pDo->Repeat(rView);
501 0 : bRet = true;
502 : }
503 : }
504 : }
505 0 : return bRet;
506 : }
507 :
508 82 : void SdrModel::ImpPostUndoAction(SdrUndoAction* pUndo)
509 : {
510 : DBG_ASSERT( mpImpl->mpUndoManager == 0, "svx::SdrModel::ImpPostUndoAction(), method not supported with application undo manager!" );
511 82 : if( IsUndoEnabled() )
512 : {
513 82 : if (aUndoLink.IsSet())
514 : {
515 0 : aUndoLink.Call(pUndo);
516 : }
517 : else
518 : {
519 82 : if (pUndoStack==NULL)
520 82 : pUndoStack=new std::deque<SfxUndoAction*>;
521 82 : pUndoStack->push_front(pUndo);
522 164 : while (pUndoStack->size()>nMaxUndoCount)
523 : {
524 0 : delete pUndoStack->back();
525 0 : pUndoStack->pop_back();
526 : }
527 82 : if (pRedoStack!=NULL)
528 0 : pRedoStack->clear();
529 : }
530 : }
531 : else
532 : {
533 0 : delete pUndo;
534 : }
535 82 : }
536 :
537 82 : void SdrModel::BegUndo()
538 : {
539 82 : if( mpImpl->mpUndoManager )
540 : {
541 0 : const String aEmpty;
542 0 : mpImpl->mpUndoManager->EnterListAction(aEmpty,aEmpty);
543 0 : nUndoLevel++;
544 : }
545 82 : else if( IsUndoEnabled() )
546 : {
547 82 : if(pAktUndoGroup==NULL)
548 : {
549 82 : pAktUndoGroup = new SdrUndoGroup(*this);
550 82 : nUndoLevel=1;
551 : }
552 : else
553 : {
554 0 : nUndoLevel++;
555 : }
556 : }
557 82 : }
558 :
559 128 : void SdrModel::BegUndo(const XubString& rComment)
560 : {
561 128 : if( mpImpl->mpUndoManager )
562 : {
563 46 : const String aEmpty;
564 46 : mpImpl->mpUndoManager->EnterListAction( rComment, aEmpty );
565 46 : nUndoLevel++;
566 : }
567 82 : else if( IsUndoEnabled() )
568 : {
569 82 : BegUndo();
570 82 : if (nUndoLevel==1)
571 : {
572 82 : pAktUndoGroup->SetComment(rComment);
573 : }
574 : }
575 128 : }
576 :
577 0 : void SdrModel::BegUndo(const XubString& rComment, const XubString& rObjDescr, SdrRepeatFunc eFunc)
578 : {
579 0 : if( mpImpl->mpUndoManager )
580 : {
581 0 : String aComment(rComment);
582 0 : if( aComment.Len() && rObjDescr.Len() )
583 : {
584 0 : String aSearchString(RTL_CONSTASCII_USTRINGPARAM("%1"));
585 0 : aComment.SearchAndReplace(aSearchString, rObjDescr);
586 : }
587 0 : const String aEmpty;
588 0 : mpImpl->mpUndoManager->EnterListAction( aComment,aEmpty );
589 0 : nUndoLevel++;
590 : }
591 0 : else if( IsUndoEnabled() )
592 : {
593 0 : BegUndo();
594 0 : if (nUndoLevel==1)
595 : {
596 0 : pAktUndoGroup->SetComment(rComment);
597 0 : pAktUndoGroup->SetObjDescription(rObjDescr);
598 0 : pAktUndoGroup->SetRepeatFunction(eFunc);
599 : }
600 : }
601 0 : }
602 :
603 128 : void SdrModel::EndUndo()
604 : {
605 : DBG_ASSERT(nUndoLevel!=0,"SdrModel::EndUndo(): UndoLevel is already 0!");
606 128 : if( mpImpl->mpUndoManager )
607 : {
608 46 : if( nUndoLevel )
609 : {
610 46 : nUndoLevel--;
611 46 : mpImpl->mpUndoManager->LeaveListAction();
612 : }
613 : }
614 : else
615 : {
616 82 : if(pAktUndoGroup!=NULL && IsUndoEnabled())
617 : {
618 82 : nUndoLevel--;
619 82 : if(nUndoLevel==0)
620 : {
621 82 : if(pAktUndoGroup->GetActionCount()!=0)
622 : {
623 82 : SdrUndoAction* pUndo=pAktUndoGroup;
624 82 : pAktUndoGroup=NULL;
625 82 : ImpPostUndoAction(pUndo);
626 : }
627 : else
628 : {
629 : // was empty
630 0 : delete pAktUndoGroup;
631 0 : pAktUndoGroup=NULL;
632 : }
633 : }
634 : }
635 : }
636 128 : }
637 :
638 0 : void SdrModel::SetUndoComment(const XubString& rComment)
639 : {
640 : DBG_ASSERT(nUndoLevel!=0,"SdrModel::SetUndoComment(): UndoLevel is already 0!");
641 :
642 0 : if( mpImpl->mpUndoManager )
643 : {
644 : OSL_FAIL("svx::SdrModel::SetUndoComment(), method not supported with application undo manager!" );
645 : }
646 0 : else if( IsUndoEnabled() )
647 : {
648 0 : if(nUndoLevel==1)
649 : {
650 0 : pAktUndoGroup->SetComment(rComment);
651 : }
652 : }
653 0 : }
654 :
655 0 : void SdrModel::SetUndoComment(const XubString& rComment, const XubString& rObjDescr)
656 : {
657 : DBG_ASSERT(nUndoLevel!=0,"SdrModel::SetUndoComment(): UndoLevel is already 0!");
658 0 : if( mpImpl->mpUndoManager )
659 : {
660 : OSL_FAIL("svx::SdrModel::SetUndoComment(), method not supported with application undo manager!" );
661 : }
662 : else
663 : {
664 0 : if (nUndoLevel==1)
665 : {
666 0 : pAktUndoGroup->SetComment(rComment);
667 0 : pAktUndoGroup->SetObjDescription(rObjDescr);
668 : }
669 : }
670 0 : }
671 :
672 128 : void SdrModel::AddUndo(SdrUndoAction* pUndo)
673 : {
674 128 : if( mpImpl->mpUndoManager )
675 : {
676 46 : mpImpl->mpUndoManager->AddUndoAction( pUndo );
677 : }
678 82 : else if( !IsUndoEnabled() )
679 : {
680 0 : delete pUndo;
681 : }
682 : else
683 : {
684 82 : if (pAktUndoGroup!=NULL)
685 : {
686 82 : pAktUndoGroup->AddAction(pUndo);
687 : }
688 : else
689 : {
690 0 : ImpPostUndoAction(pUndo);
691 : }
692 : }
693 128 : }
694 :
695 10608 : void SdrModel::EnableUndo( bool bEnable )
696 : {
697 10608 : if( mpImpl->mpUndoManager )
698 : {
699 28 : mpImpl->mpUndoManager->EnableUndo( bEnable );
700 : }
701 : else
702 : {
703 10580 : mbUndoEnabled = bEnable;
704 : }
705 10608 : }
706 :
707 4000 : bool SdrModel::IsUndoEnabled() const
708 : {
709 4000 : if( mpImpl->mpUndoManager )
710 : {
711 124 : return mpImpl->mpUndoManager->IsUndoEnabled();
712 : }
713 : else
714 : {
715 3876 : return mbUndoEnabled;
716 : }
717 : }
718 :
719 758 : void SdrModel::ImpCreateTables()
720 : {
721 5306 : for( int i = 0; i < XPROPERTY_LIST_COUNT; i++ )
722 : {
723 4548 : if( !bExtColorTable || i != XCOLOR_LIST )
724 : maProperties[i] = XPropertyList::CreatePropertyList (
725 3912 : (XPropertyListType) i, aTablePath, (XOutdevItemPool*)pItemPool );
726 : }
727 758 : }
728 :
729 674 : void SdrModel::ClearModel(sal_Bool bCalledFromDestructor)
730 : {
731 674 : if(bCalledFromDestructor)
732 : {
733 674 : mbInDestruction = true;
734 : }
735 :
736 : sal_Int32 i;
737 : // delete all drawing pages
738 674 : sal_Int32 nAnz=GetPageCount();
739 1338 : for (i=nAnz-1; i>=0; i--)
740 : {
741 664 : DeletePage( (sal_uInt16)i );
742 : }
743 674 : maPages.clear();
744 674 : PageListChanged();
745 :
746 : // delete all Masterpages
747 674 : nAnz=GetMasterPageCount();
748 728 : for(i=nAnz-1; i>=0; i--)
749 : {
750 54 : DeleteMasterPage( (sal_uInt16)i );
751 : }
752 674 : maMaPag.clear();
753 674 : MasterPageListChanged();
754 :
755 674 : pLayerAdmin->ClearLayer();
756 674 : }
757 :
758 0 : SdrModel* SdrModel::AllocModel() const
759 : {
760 0 : SdrModel* pModel=new SdrModel;
761 0 : pModel->SetScaleUnit(eObjUnit,aObjUnit);
762 0 : return pModel;
763 : }
764 :
765 0 : SdrPage* SdrModel::AllocPage(bool bMasterPage)
766 : {
767 0 : return new SdrPage(*this,bMasterPage);
768 : }
769 :
770 758 : void SdrModel::SetTextDefaults() const
771 : {
772 758 : SetTextDefaults( pItemPool, nDefTextHgt );
773 758 : }
774 :
775 799 : void SdrModel::SetTextDefaults( SfxItemPool* pItemPool, sal_uIntPtr nDefTextHgt )
776 : {
777 : // set application-language specific dynamic pool language defaults
778 799 : SvxFontItem aSvxFontItem( EE_CHAR_FONTINFO) ;
779 799 : SvxFontItem aSvxFontItemCJK(EE_CHAR_FONTINFO_CJK);
780 799 : SvxFontItem aSvxFontItemCTL(EE_CHAR_FONTINFO_CTL);
781 799 : sal_uInt16 nLanguage(Application::GetSettings().GetLanguageTag().getLanguageType());
782 :
783 : // get DEFAULTFONT_LATIN_TEXT and set at pool as dynamic default
784 799 : Font aFont(OutputDevice::GetDefaultFont(DEFAULTFONT_LATIN_TEXT, nLanguage, DEFAULTFONT_FLAGS_ONLYONE, 0));
785 799 : aSvxFontItem.SetFamily(aFont.GetFamily());
786 799 : aSvxFontItem.SetFamilyName(aFont.GetName());
787 799 : aSvxFontItem.SetStyleName(String());
788 799 : aSvxFontItem.SetPitch( aFont.GetPitch());
789 799 : aSvxFontItem.SetCharSet( aFont.GetCharSet() );
790 799 : pItemPool->SetPoolDefaultItem(aSvxFontItem);
791 :
792 : // get DEFAULTFONT_CJK_TEXT and set at pool as dynamic default
793 799 : Font aFontCJK(OutputDevice::GetDefaultFont(DEFAULTFONT_CJK_TEXT, nLanguage, DEFAULTFONT_FLAGS_ONLYONE, 0));
794 799 : aSvxFontItemCJK.SetFamily( aFontCJK.GetFamily());
795 799 : aSvxFontItemCJK.SetFamilyName(aFontCJK.GetName());
796 799 : aSvxFontItemCJK.SetStyleName(String());
797 799 : aSvxFontItemCJK.SetPitch( aFontCJK.GetPitch());
798 799 : aSvxFontItemCJK.SetCharSet( aFontCJK.GetCharSet());
799 799 : pItemPool->SetPoolDefaultItem(aSvxFontItemCJK);
800 :
801 : // get DEFAULTFONT_CTL_TEXT and set at pool as dynamic default
802 799 : Font aFontCTL(OutputDevice::GetDefaultFont(DEFAULTFONT_CTL_TEXT, nLanguage, DEFAULTFONT_FLAGS_ONLYONE, 0));
803 799 : aSvxFontItemCTL.SetFamily(aFontCTL.GetFamily());
804 799 : aSvxFontItemCTL.SetFamilyName(aFontCTL.GetName());
805 799 : aSvxFontItemCTL.SetStyleName(String());
806 799 : aSvxFontItemCTL.SetPitch( aFontCTL.GetPitch() );
807 799 : aSvxFontItemCTL.SetCharSet( aFontCTL.GetCharSet());
808 799 : pItemPool->SetPoolDefaultItem(aSvxFontItemCTL);
809 :
810 : // set dynamic FontHeight defaults
811 799 : pItemPool->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt, 100, EE_CHAR_FONTHEIGHT ) );
812 799 : pItemPool->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt, 100, EE_CHAR_FONTHEIGHT_CJK ) );
813 799 : pItemPool->SetPoolDefaultItem( SvxFontHeightItem(nDefTextHgt, 100, EE_CHAR_FONTHEIGHT_CTL ) );
814 :
815 : // set FontColor defaults
816 799 : pItemPool->SetPoolDefaultItem( SvxColorItem(SdrEngineDefaults::GetFontColor(), EE_CHAR_COLOR) );
817 799 : }
818 :
819 53845 : SdrOutliner& SdrModel::GetDrawOutliner(const SdrTextObj* pObj) const
820 : {
821 53845 : pDrawOutliner->SetTextObj(pObj);
822 53845 : return *pDrawOutliner;
823 : }
824 :
825 0 : const SdrTextObj* SdrModel::GetFormattingTextObj() const
826 : {
827 0 : if (pDrawOutliner!=NULL) {
828 0 : return pDrawOutliner->GetTextObj();
829 : }
830 0 : return NULL;
831 : }
832 :
833 6568 : void SdrModel::ImpSetOutlinerDefaults( SdrOutliner* pOutliner, sal_Bool bInit )
834 : {
835 : /**************************************************************************
836 : * Initialization of the Outliners for drawing text and HitTest
837 : **************************************************************************/
838 6568 : if( bInit )
839 : {
840 1516 : pOutliner->EraseVirtualDevice();
841 1516 : pOutliner->SetUpdateMode(sal_False);
842 1516 : pOutliner->SetEditTextObjectPool(pItemPool);
843 1516 : pOutliner->SetDefTab(nDefaultTabulator);
844 : }
845 :
846 6568 : pOutliner->SetRefDevice(GetRefDevice());
847 6568 : pOutliner->SetForbiddenCharsTable(GetForbiddenCharsTable());
848 6568 : pOutliner->SetAsianCompressionMode( mnCharCompressType );
849 6568 : pOutliner->SetKernAsianPunctuation( IsKernAsianPunctuation() );
850 6568 : pOutliner->SetAddExtLeading( IsAddExtLeading() );
851 :
852 6568 : if ( !GetRefDevice() )
853 : {
854 4780 : MapMode aMapMode(eObjUnit, Point(0,0), aObjUnit, aObjUnit);
855 4780 : pOutliner->SetRefMapMode(aMapMode);
856 : }
857 6568 : }
858 :
859 786 : void SdrModel::SetRefDevice(OutputDevice* pDev)
860 : {
861 786 : pRefOutDev=pDev;
862 786 : ImpSetOutlinerDefaults( pDrawOutliner );
863 786 : ImpSetOutlinerDefaults( pHitTestOutliner );
864 786 : RefDeviceChanged();
865 786 : }
866 :
867 1592 : void SdrModel::ImpReformatAllTextObjects()
868 : {
869 1592 : if( isLocked() )
870 1612 : return;
871 :
872 1572 : sal_uInt16 nAnz=GetMasterPageCount();
873 : sal_uInt16 nNum;
874 1572 : for (nNum=0; nNum<nAnz; nNum++) {
875 0 : GetMasterPage(nNum)->ReformatAllTextObjects();
876 : }
877 1572 : nAnz=GetPageCount();
878 2462 : for (nNum=0; nNum<nAnz; nNum++) {
879 890 : GetPage(nNum)->ReformatAllTextObjects();
880 : }
881 : }
882 :
883 : /* steps over all available pages and sends notify messages to
884 : all edge objects that are connected to other objects so that
885 : they may reposition themselves
886 : */
887 159 : void SdrModel::ImpReformatAllEdgeObjects()
888 : {
889 159 : if( isLocked() )
890 318 : return;
891 :
892 0 : sal_uInt16 nAnz=GetMasterPageCount();
893 : sal_uInt16 nNum;
894 0 : for (nNum=0; nNum<nAnz; nNum++)
895 : {
896 0 : GetMasterPage(nNum)->ReformatAllEdgeObjects();
897 : }
898 0 : nAnz=GetPageCount();
899 0 : for (nNum=0; nNum<nAnz; nNum++)
900 : {
901 0 : GetPage(nNum)->ReformatAllEdgeObjects();
902 : }
903 : }
904 :
905 0 : uno::Reference<embed::XStorage> SdrModel::GetDocumentStorage() const
906 : {
907 : uno::Reference<document::XStorageBasedDocument> const xSBD(
908 0 : const_cast<SdrModel*>(this)->getUnoModel(), uno::UNO_QUERY);
909 0 : if (!xSBD.is())
910 : {
911 : SAL_WARN("svx", "no UNO model");
912 0 : return 0;
913 : }
914 0 : return xSBD->getDocumentStorage();
915 : }
916 :
917 : uno::Reference<io::XInputStream>
918 0 : SdrModel::GetDocumentStream( ::rtl::OUString const& rURL,
919 : ::comphelper::LifecycleProxy & rProxy) const
920 : {
921 0 : uno::Reference<embed::XStorage> const xStorage(GetDocumentStorage());
922 0 : if (!xStorage.is())
923 : {
924 : SAL_WARN("svx", "no storage?");
925 0 : return 0;
926 : }
927 : try {
928 : uno::Reference<io::XStream> const xStream(
929 : ::comphelper::OStorageHelper::GetStreamAtPackageURL(
930 0 : xStorage, rURL, embed::ElementModes::READ, rProxy));
931 0 : return (xStream.is()) ? xStream->getInputStream() : 0;
932 : }
933 0 : catch (container::NoSuchElementException const&)
934 : {
935 : SAL_INFO("svx", "not found");
936 : }
937 0 : catch (uno::Exception const& e)
938 : {
939 : SAL_WARN("svx", "exception: '" << e.Message << "'");
940 : }
941 0 : return 0;
942 : }
943 :
944 : // convert template attributes from the string into "hard" attributes
945 0 : void SdrModel::BurnInStyleSheetAttributes()
946 : {
947 0 : sal_uInt16 nAnz=GetMasterPageCount();
948 : sal_uInt16 nNum;
949 0 : for (nNum=0; nNum<nAnz; nNum++) {
950 0 : GetMasterPage(nNum)->BurnInStyleSheetAttributes();
951 : }
952 0 : nAnz=GetPageCount();
953 0 : for (nNum=0; nNum<nAnz; nNum++) {
954 0 : GetPage(nNum)->BurnInStyleSheetAttributes();
955 : }
956 0 : }
957 :
958 786 : void SdrModel::RefDeviceChanged()
959 : {
960 786 : Broadcast(SdrHint(HINT_REFDEVICECHG));
961 786 : ImpReformatAllTextObjects();
962 786 : }
963 :
964 122 : void SdrModel::SetDefaultFontHeight(sal_uIntPtr nVal)
965 : {
966 122 : if (nVal!=nDefTextHgt) {
967 82 : nDefTextHgt=nVal;
968 82 : Broadcast(SdrHint(HINT_DEFFONTHGTCHG));
969 82 : ImpReformatAllTextObjects();
970 : }
971 122 : }
972 :
973 150 : void SdrModel::SetDefaultTabulator(sal_uInt16 nVal)
974 : {
975 150 : if (nDefaultTabulator!=nVal) {
976 148 : nDefaultTabulator=nVal;
977 148 : Outliner& rOutliner=GetDrawOutliner();
978 148 : rOutliner.SetDefTab(nVal);
979 148 : Broadcast(SdrHint(HINT_DEFAULTTABCHG));
980 148 : ImpReformatAllTextObjects();
981 : }
982 150 : }
983 :
984 1328 : void SdrModel::ImpSetUIUnit()
985 : {
986 1328 : if(0 == aUIScale.GetNumerator() || 0 == aUIScale.GetDenominator())
987 : {
988 0 : aUIScale = Fraction(1,1);
989 : }
990 :
991 : // set start values
992 1328 : nUIUnitKomma = 0;
993 1328 : sal_Int64 nMul(1);
994 1328 : sal_Int64 nDiv(1);
995 :
996 : // normalize on meters resp. inch
997 1328 : switch (eObjUnit)
998 : {
999 798 : case MAP_100TH_MM : nUIUnitKomma+=5; break;
1000 0 : case MAP_10TH_MM : nUIUnitKomma+=4; break;
1001 0 : case MAP_MM : nUIUnitKomma+=3; break;
1002 0 : case MAP_CM : nUIUnitKomma+=2; break;
1003 0 : case MAP_1000TH_INCH: nUIUnitKomma+=3; break;
1004 0 : case MAP_100TH_INCH : nUIUnitKomma+=2; break;
1005 0 : case MAP_10TH_INCH : nUIUnitKomma+=1; break;
1006 0 : case MAP_INCH : nUIUnitKomma+=0; break;
1007 0 : case MAP_POINT : nDiv=72; break; // 1Pt = 1/72"
1008 530 : case MAP_TWIP : nDiv=144; nUIUnitKomma++; break; // 1Twip = 1/1440"
1009 0 : case MAP_PIXEL : break;
1010 0 : case MAP_SYSFONT : break;
1011 0 : case MAP_APPFONT : break;
1012 0 : case MAP_RELATIVE : break;
1013 0 : default: break;
1014 : } // switch
1015 :
1016 : // 1 mile = 8 furlong = 63.360" = 1.609.344,0mm
1017 : // 1 furlong = 10 chains = 7.920" = 201.168,0mm
1018 : // 1 chain = 4 poles = 792" = 20.116,8mm
1019 : // 1 pole = 5 1/2 yd = 198" = 5.029,2mm
1020 : // 1 yd = 3 ft = 36" = 914,4mm
1021 : // 1 ft = 12 " = 1" = 304,8mm
1022 1328 : switch (eUIUnit)
1023 : {
1024 0 : case FUNIT_NONE : break;
1025 : // metric
1026 0 : case FUNIT_100TH_MM: nUIUnitKomma-=5; break;
1027 1288 : case FUNIT_MM : nUIUnitKomma-=3; break;
1028 0 : case FUNIT_CM : nUIUnitKomma-=2; break;
1029 0 : case FUNIT_M : nUIUnitKomma+=0; break;
1030 0 : case FUNIT_KM : nUIUnitKomma+=3; break;
1031 : // Inch
1032 0 : case FUNIT_TWIP : nMul=144; nUIUnitKomma--; break; // 1Twip = 1/1440"
1033 0 : case FUNIT_POINT : nMul=72; break; // 1Pt = 1/72"
1034 0 : case FUNIT_PICA : nMul=6; break; // 1Pica = 1/6"
1035 40 : case FUNIT_INCH : break; // 1" = 1"
1036 0 : case FUNIT_FOOT : nDiv*=12; break; // 1Ft = 12"
1037 0 : case FUNIT_MILE : nDiv*=6336; nUIUnitKomma++; break; // 1mile = 63360"
1038 : // other
1039 0 : case FUNIT_CUSTOM : break;
1040 0 : case FUNIT_PERCENT: nUIUnitKomma+=2; break;
1041 : // TODO: Add code to handle the following if needed (added to remove warning)
1042 0 : case FUNIT_CHAR : break;
1043 0 : case FUNIT_LINE : break;
1044 : } // switch
1045 :
1046 : // check if mapping is from metric to inch and adapt
1047 1328 : const bool bMapInch(IsInch(eObjUnit));
1048 1328 : const bool bUIMetr(IsMetric(eUIUnit));
1049 :
1050 1328 : if (bMapInch && bUIMetr)
1051 : {
1052 530 : nUIUnitKomma += 4;
1053 530 : nMul *= 254;
1054 : }
1055 :
1056 : // check if mapping is from inch to metric and adapt
1057 1328 : const bool bMapMetr(IsMetric(eObjUnit));
1058 1328 : const bool bUIInch(IsInch(eUIUnit));
1059 :
1060 1328 : if (bMapMetr && bUIInch)
1061 : {
1062 40 : nUIUnitKomma -= 4;
1063 40 : nDiv *= 254;
1064 : }
1065 :
1066 : // use temporary fraction for reduction (fallback to 32bit here),
1067 : // may need to be changed in the future, too
1068 1328 : if(1 != nMul || 1 != nDiv)
1069 : {
1070 570 : const Fraction aTemp(static_cast< long >(nMul), static_cast< long >(nDiv));
1071 570 : nMul = aTemp.GetNumerator();
1072 570 : nDiv = aTemp.GetDenominator();
1073 : }
1074 :
1075 : // #i89872# take Unit of Measurement into account
1076 1328 : if(1 != aUIScale.GetDenominator() || 1 != aUIScale.GetNumerator())
1077 : {
1078 : // divide by UIScale
1079 0 : nMul *= aUIScale.GetDenominator();
1080 0 : nDiv *= aUIScale.GetNumerator();
1081 : }
1082 :
1083 : // shorten trailing zeros for dividend
1084 2656 : while(0 == (nMul % 10))
1085 : {
1086 0 : nUIUnitKomma--;
1087 0 : nMul /= 10;
1088 : }
1089 :
1090 : // shorten trailing zeros for divisor
1091 2656 : while(0 == (nDiv % 10))
1092 : {
1093 0 : nUIUnitKomma++;
1094 0 : nDiv /= 10;
1095 : }
1096 :
1097 : // end preparations, set member values
1098 1328 : aUIUnitFact = Fraction(sal_Int32(nMul), sal_Int32(nDiv));
1099 1328 : bUIOnlyKomma = (nMul == nDiv);
1100 1328 : TakeUnitStr(eUIUnit, aUIUnitStr);
1101 1328 : }
1102 :
1103 0 : void SdrModel::SetScaleUnit(MapUnit eMap, const Fraction& rFrac)
1104 : {
1105 0 : if (eObjUnit!=eMap || aObjUnit!=rFrac) {
1106 0 : eObjUnit=eMap;
1107 0 : aObjUnit=rFrac;
1108 0 : pItemPool->SetDefaultMetric((SfxMapUnit)eObjUnit);
1109 0 : ImpSetUIUnit();
1110 0 : ImpSetOutlinerDefaults( pDrawOutliner );
1111 0 : ImpSetOutlinerDefaults( pHitTestOutliner );
1112 0 : ImpReformatAllTextObjects();
1113 : }
1114 0 : }
1115 :
1116 758 : void SdrModel::SetScaleUnit(MapUnit eMap)
1117 : {
1118 758 : if (eObjUnit!=eMap) {
1119 530 : eObjUnit=eMap;
1120 530 : pItemPool->SetDefaultMetric((SfxMapUnit)eObjUnit);
1121 530 : ImpSetUIUnit();
1122 530 : ImpSetOutlinerDefaults( pDrawOutliner );
1123 530 : ImpSetOutlinerDefaults( pHitTestOutliner );
1124 530 : ImpReformatAllTextObjects();
1125 : }
1126 758 : }
1127 :
1128 122 : void SdrModel::SetScaleFraction(const Fraction& rFrac)
1129 : {
1130 122 : if (aObjUnit!=rFrac) {
1131 0 : aObjUnit=rFrac;
1132 0 : ImpSetUIUnit();
1133 0 : ImpSetOutlinerDefaults( pDrawOutliner );
1134 0 : ImpSetOutlinerDefaults( pHitTestOutliner );
1135 0 : ImpReformatAllTextObjects();
1136 : }
1137 122 : }
1138 :
1139 0 : void SdrModel::SetUIUnit(FieldUnit eUnit)
1140 : {
1141 0 : if (eUIUnit!=eUnit) {
1142 0 : eUIUnit=eUnit;
1143 0 : ImpSetUIUnit();
1144 0 : ImpReformatAllTextObjects();
1145 : }
1146 0 : }
1147 :
1148 0 : void SdrModel::SetUIScale(const Fraction& rScale)
1149 : {
1150 0 : if (aUIScale!=rScale) {
1151 0 : aUIScale=rScale;
1152 0 : ImpSetUIUnit();
1153 0 : ImpReformatAllTextObjects();
1154 : }
1155 0 : }
1156 :
1157 40 : void SdrModel::SetUIUnit(FieldUnit eUnit, const Fraction& rScale)
1158 : {
1159 40 : if (eUIUnit!=eUnit || aUIScale!=rScale) {
1160 40 : eUIUnit=eUnit;
1161 40 : aUIScale=rScale;
1162 40 : ImpSetUIUnit();
1163 40 : ImpReformatAllTextObjects();
1164 : }
1165 40 : }
1166 :
1167 1328 : void SdrModel::TakeUnitStr(FieldUnit eUnit, XubString& rStr)
1168 : {
1169 1328 : switch(eUnit)
1170 : {
1171 : default:
1172 : case FUNIT_NONE :
1173 : case FUNIT_CUSTOM :
1174 : {
1175 0 : rStr = String();
1176 0 : break;
1177 : }
1178 : case FUNIT_100TH_MM:
1179 : {
1180 0 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("/100mm"));
1181 0 : break;
1182 : }
1183 : case FUNIT_MM :
1184 : {
1185 1288 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("mm"));
1186 1288 : break;
1187 : }
1188 : case FUNIT_CM :
1189 : {
1190 0 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("cm"));
1191 0 : break;
1192 : }
1193 : case FUNIT_M :
1194 : {
1195 0 : rStr = String();
1196 0 : rStr += sal_Unicode('m');
1197 0 : break;
1198 : }
1199 : case FUNIT_KM :
1200 : {
1201 0 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("km"));
1202 0 : break;
1203 : }
1204 : case FUNIT_TWIP :
1205 : {
1206 0 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("twip"));
1207 0 : break;
1208 : }
1209 : case FUNIT_POINT :
1210 : {
1211 0 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("pt"));
1212 0 : break;
1213 : }
1214 : case FUNIT_PICA :
1215 : {
1216 0 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("pica"));
1217 0 : break;
1218 : }
1219 : case FUNIT_INCH :
1220 : {
1221 40 : rStr = String();
1222 40 : rStr += sal_Unicode('"');
1223 40 : break;
1224 : }
1225 : case FUNIT_FOOT :
1226 : {
1227 0 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("ft"));
1228 0 : break;
1229 : }
1230 : case FUNIT_MILE :
1231 : {
1232 0 : rStr = UniString(RTL_CONSTASCII_USTRINGPARAM("mile(s)"));
1233 0 : break;
1234 : }
1235 : case FUNIT_PERCENT:
1236 : {
1237 0 : rStr = String();
1238 0 : rStr += sal_Unicode('%');
1239 0 : break;
1240 : }
1241 : }
1242 1328 : }
1243 :
1244 0 : void SdrModel::TakeMetricStr(long nVal, rtl::OUString& rStr, bool bNoUnitChars, sal_Int32 nNumDigits) const
1245 : {
1246 : // #i22167#
1247 : // change to double precision usage to not lose decimal places
1248 0 : const bool bNegative(nVal < 0L);
1249 0 : SvtSysLocale aSysLoc;
1250 0 : const LocaleDataWrapper& rLoc(aSysLoc.GetLocaleData());
1251 0 : double fLocalValue(double(nVal) * double(aUIUnitFact));
1252 :
1253 0 : if(bNegative)
1254 : {
1255 0 : fLocalValue = -fLocalValue;
1256 : }
1257 :
1258 0 : if( -1 == nNumDigits )
1259 : {
1260 0 : nNumDigits = rLoc.getNumDigits();
1261 : }
1262 :
1263 0 : sal_Int32 nKomma(nUIUnitKomma);
1264 :
1265 0 : if(nKomma > nNumDigits)
1266 : {
1267 0 : const sal_Int32 nDiff(nKomma - nNumDigits);
1268 0 : const double fFactor(pow(10.0, static_cast<const int>(nDiff)));
1269 :
1270 0 : fLocalValue /= fFactor;
1271 0 : nKomma = nNumDigits;
1272 : }
1273 0 : else if(nKomma < nNumDigits)
1274 : {
1275 0 : const sal_Int32 nDiff(nNumDigits - nKomma);
1276 0 : const double fFactor(pow(10.0, static_cast<const int>(nDiff)));
1277 :
1278 0 : fLocalValue *= fFactor;
1279 0 : nKomma = nNumDigits;
1280 : }
1281 :
1282 0 : rtl::OUStringBuffer aBuf;
1283 0 : aBuf.append(static_cast<sal_Int32>(fLocalValue + 0.5));
1284 :
1285 0 : if(nKomma < 0)
1286 : {
1287 : // negative nKomma (decimal point) means: add zeros
1288 0 : sal_Int32 nAnz(-nKomma);
1289 :
1290 0 : for(sal_Int32 i=0; i<nAnz; i++)
1291 0 : aBuf.append(sal_Unicode('0'));
1292 :
1293 0 : nKomma = 0;
1294 : }
1295 :
1296 : // the second condition needs to be <= since inside this loop
1297 : // also the leading zero is inserted.
1298 0 : if (nKomma > 0 && aBuf.getLength() <= nKomma)
1299 : {
1300 : // if necessary, add zeros before the decimal point
1301 0 : sal_Int32 nAnz = nKomma - aBuf.getLength();
1302 :
1303 0 : if(nAnz >= 0 && rLoc.isNumLeadingZero())
1304 0 : nAnz++;
1305 :
1306 0 : for(sal_Int32 i=0; i<nAnz; i++)
1307 0 : aBuf.insert(0, sal_Unicode('0'));
1308 : }
1309 :
1310 0 : sal_Unicode cDec( rLoc.getNumDecimalSep()[0] );
1311 :
1312 : // insert KommaChar (decimal point character)
1313 0 : sal_Int32 nVorKomma = aBuf.getLength() - nKomma;
1314 :
1315 0 : if(nKomma > 0)
1316 0 : aBuf.insert(nVorKomma, cDec);
1317 :
1318 0 : if(!rLoc.isNumTrailingZeros())
1319 : {
1320 : // Remove all trailing zeros.
1321 0 : while (aBuf.getLength() && aBuf[aBuf.getLength()-1] == sal_Unicode('0'))
1322 0 : aBuf.remove(aBuf.getLength()-1, 1);
1323 :
1324 : // Remove decimal if it's the last character.
1325 0 : if (aBuf.getLength() && aBuf[aBuf.getLength()-1] == cDec)
1326 0 : aBuf.remove(aBuf.getLength()-1, 1);
1327 : }
1328 :
1329 : // if necessary, add separators before every third digit
1330 0 : if( nVorKomma > 3 )
1331 : {
1332 0 : String aThoSep( rLoc.getNumThousandSep() );
1333 0 : if ( aThoSep.Len() > 0 )
1334 : {
1335 0 : sal_Unicode cTho( aThoSep.GetChar(0) );
1336 0 : sal_Int32 i(nVorKomma - 3);
1337 :
1338 0 : while(i > 0)
1339 : {
1340 0 : aBuf.insert(i, cTho);
1341 0 : i -= 3;
1342 : }
1343 0 : }
1344 : }
1345 :
1346 0 : if (!aBuf.getLength())
1347 0 : aBuf.append(sal_Unicode('0'));
1348 :
1349 0 : if(bNegative)
1350 : {
1351 0 : aBuf.insert(0, sal_Unicode('-'));
1352 : }
1353 :
1354 0 : if(!bNoUnitChars)
1355 0 : aBuf.append(aUIUnitStr);
1356 :
1357 0 : rStr = aBuf.makeStringAndClear();
1358 0 : }
1359 :
1360 0 : void SdrModel::TakeWinkStr(long nWink, rtl::OUString& rStr, bool bNoDegChar) const
1361 : {
1362 0 : bool bNeg = nWink < 0;
1363 :
1364 0 : if(bNeg)
1365 0 : nWink = -nWink;
1366 :
1367 0 : rtl::OUStringBuffer aBuf;
1368 0 : aBuf.append(static_cast<sal_Int32>(nWink));
1369 :
1370 0 : SvtSysLocale aSysLoc;
1371 0 : const LocaleDataWrapper& rLoc = aSysLoc.GetLocaleData();
1372 0 : sal_Int32 nAnz = 2;
1373 :
1374 0 : if(rLoc.isNumLeadingZero())
1375 0 : nAnz++;
1376 :
1377 0 : while(aBuf.getLength() < nAnz)
1378 0 : aBuf.insert(0, sal_Unicode('0'));
1379 :
1380 0 : aBuf.insert(aBuf.getLength()-2, rLoc.getNumDecimalSep()[0]);
1381 :
1382 0 : if(bNeg)
1383 0 : aBuf.insert(0, sal_Unicode('-'));
1384 :
1385 0 : if(!bNoDegChar)
1386 0 : aBuf.append(DEGREE_CHAR);
1387 :
1388 0 : rStr = aBuf.makeStringAndClear();
1389 0 : }
1390 :
1391 0 : void SdrModel::TakePercentStr(const Fraction& rVal, XubString& rStr, bool bNoPercentChar) const
1392 : {
1393 0 : sal_Int32 nMul(rVal.GetNumerator());
1394 0 : sal_Int32 nDiv(rVal.GetDenominator());
1395 0 : sal_Bool bNeg(nMul < 0);
1396 :
1397 0 : if(nDiv < 0)
1398 0 : bNeg = !bNeg;
1399 :
1400 0 : if(nMul < 0)
1401 0 : nMul = -nMul;
1402 :
1403 0 : if(nDiv < 0)
1404 0 : nDiv = -nDiv;
1405 :
1406 0 : nMul *= 100;
1407 0 : nMul += nDiv/2;
1408 0 : nMul /= nDiv;
1409 :
1410 0 : rStr = UniString::CreateFromInt32(nMul);
1411 :
1412 0 : if(bNeg)
1413 0 : rStr.Insert(sal_Unicode('-'), 0);
1414 :
1415 0 : if(!bNoPercentChar)
1416 0 : rStr += sal_Unicode('%');
1417 0 : }
1418 :
1419 205131 : void SdrModel::SetChanged(sal_Bool bFlg)
1420 : {
1421 205131 : mbChanged = bFlg;
1422 205131 : }
1423 :
1424 0 : void SdrModel::RecalcPageNums(bool bMaster)
1425 : {
1426 0 : if(bMaster)
1427 : {
1428 0 : sal_uInt16 nAnz=sal_uInt16(maMaPag.size());
1429 : sal_uInt16 i;
1430 0 : for (i=0; i<nAnz; i++) {
1431 0 : SdrPage* pPg=maMaPag[i];
1432 0 : pPg->SetPageNum(i);
1433 : }
1434 0 : bMPgNumsDirty=sal_False;
1435 : }
1436 : else
1437 : {
1438 0 : sal_uInt16 nAnz=sal_uInt16(maPages.size());
1439 : sal_uInt16 i;
1440 0 : for (i=0; i<nAnz; i++) {
1441 0 : SdrPage* pPg=maPages[i];
1442 0 : pPg->SetPageNum(i);
1443 : }
1444 0 : bPagNumsDirty=sal_False;
1445 : }
1446 0 : }
1447 :
1448 1122 : void SdrModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
1449 : {
1450 1122 : sal_uInt16 nAnz=GetPageCount();
1451 1122 : if (nPos>nAnz) nPos=nAnz;
1452 1122 : maPages.insert(maPages.begin()+nPos,pPage);
1453 1122 : PageListChanged();
1454 1122 : pPage->SetInserted(sal_True);
1455 1122 : pPage->SetPageNum(nPos);
1456 1122 : pPage->SetModel(this);
1457 1122 : if (nPos<nAnz) bPagNumsDirty=sal_True;
1458 1122 : SetChanged();
1459 1122 : SdrHint aHint(HINT_PAGEORDERCHG);
1460 1122 : aHint.SetPage(pPage);
1461 1122 : Broadcast(aHint);
1462 1122 : }
1463 :
1464 672 : void SdrModel::DeletePage(sal_uInt16 nPgNum)
1465 : {
1466 672 : SdrPage* pPg=RemovePage(nPgNum);
1467 672 : delete pPg;
1468 672 : }
1469 :
1470 674 : SdrPage* SdrModel::RemovePage(sal_uInt16 nPgNum)
1471 : {
1472 674 : SdrPage* pPg=maPages[nPgNum];
1473 674 : maPages.erase(maPages.begin()+nPgNum);
1474 674 : PageListChanged();
1475 674 : if (pPg!=NULL) {
1476 674 : pPg->SetInserted(sal_False);
1477 : }
1478 674 : bPagNumsDirty=sal_True;
1479 674 : SetChanged();
1480 674 : SdrHint aHint(HINT_PAGEORDERCHG);
1481 674 : aHint.SetPage(pPg);
1482 674 : Broadcast(aHint);
1483 674 : return pPg;
1484 : }
1485 :
1486 2 : void SdrModel::MovePage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
1487 : {
1488 2 : SdrPage* pPg=maPages[nPgNum];
1489 2 : maPages.erase(maPages.begin()+nPgNum);
1490 2 : PageListChanged();
1491 2 : if (pPg!=NULL) {
1492 2 : pPg->SetInserted(sal_False);
1493 2 : InsertPage(pPg,nNewPos);
1494 : }
1495 2 : }
1496 :
1497 68 : void SdrModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
1498 : {
1499 68 : sal_uInt16 nAnz=GetMasterPageCount();
1500 68 : if (nPos>nAnz) nPos=nAnz;
1501 68 : maMaPag.insert(maMaPag.begin()+nPos,pPage);
1502 68 : MasterPageListChanged();
1503 68 : pPage->SetInserted(sal_True);
1504 68 : pPage->SetPageNum(nPos);
1505 68 : pPage->SetModel(this);
1506 68 : if (nPos<nAnz) {
1507 0 : bMPgNumsDirty=sal_True;
1508 : }
1509 68 : SetChanged();
1510 68 : SdrHint aHint(HINT_PAGEORDERCHG);
1511 68 : aHint.SetPage(pPage);
1512 68 : Broadcast(aHint);
1513 68 : }
1514 :
1515 56 : void SdrModel::DeleteMasterPage(sal_uInt16 nPgNum)
1516 : {
1517 56 : SdrPage* pPg=RemoveMasterPage(nPgNum);
1518 56 : if (pPg!=NULL) delete pPg;
1519 56 : }
1520 :
1521 56 : SdrPage* SdrModel::RemoveMasterPage(sal_uInt16 nPgNum)
1522 : {
1523 56 : SdrPage* pRetPg=maMaPag[nPgNum];
1524 56 : maMaPag.erase(maMaPag.begin()+nPgNum);
1525 56 : MasterPageListChanged();
1526 :
1527 56 : if(pRetPg)
1528 : {
1529 : // Now delete the links from the normal drawing pages to the deleted master page.
1530 56 : sal_uInt16 nPageAnz(GetPageCount());
1531 :
1532 56 : for(sal_uInt16 np(0); np < nPageAnz; np++)
1533 : {
1534 0 : GetPage(np)->TRG_ImpMasterPageRemoved(*pRetPg);
1535 : }
1536 :
1537 56 : pRetPg->SetInserted(sal_False);
1538 : }
1539 :
1540 56 : bMPgNumsDirty=sal_True;
1541 56 : SetChanged();
1542 56 : SdrHint aHint(HINT_PAGEORDERCHG);
1543 56 : aHint.SetPage(pRetPg);
1544 56 : Broadcast(aHint);
1545 56 : return pRetPg;
1546 : }
1547 :
1548 0 : void SdrModel::MoveMasterPage(sal_uInt16 nPgNum, sal_uInt16 nNewPos)
1549 : {
1550 0 : SdrPage* pPg=maMaPag[nPgNum];
1551 0 : maMaPag.erase(maMaPag.begin()+nPgNum);
1552 0 : MasterPageListChanged();
1553 0 : if (pPg!=NULL) {
1554 0 : pPg->SetInserted(sal_False);
1555 0 : maMaPag.insert(maMaPag.begin()+nNewPos,pPg);
1556 0 : MasterPageListChanged();
1557 : }
1558 0 : bMPgNumsDirty=sal_True;
1559 0 : SetChanged();
1560 0 : SdrHint aHint(HINT_PAGEORDERCHG);
1561 0 : aHint.SetPage(pPg);
1562 0 : Broadcast(aHint);
1563 0 : }
1564 :
1565 : ////////////////////////////////////////////////////////////////////////////////////////////////////
1566 :
1567 0 : void SdrModel::CopyPages(sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum,
1568 : sal_uInt16 nDestPos,
1569 : bool bUndo, bool bMoveNoCopy)
1570 : {
1571 0 : if( bUndo && !IsUndoEnabled() )
1572 0 : bUndo = false;
1573 :
1574 0 : if( bUndo )
1575 0 : BegUndo(ImpGetResStr(STR_UndoMergeModel));
1576 :
1577 0 : sal_uInt16 nPageAnz=GetPageCount();
1578 0 : sal_uInt16 nMaxPage=nPageAnz;
1579 :
1580 0 : if (nMaxPage!=0)
1581 0 : nMaxPage--;
1582 0 : if (nFirstPageNum>nMaxPage)
1583 0 : nFirstPageNum=nMaxPage;
1584 0 : if (nLastPageNum>nMaxPage)
1585 0 : nLastPageNum =nMaxPage;
1586 0 : bool bReverse=nLastPageNum<nFirstPageNum;
1587 0 : if (nDestPos>nPageAnz)
1588 0 : nDestPos=nPageAnz;
1589 :
1590 : // at first, save the pointers of the affected pages in an array
1591 0 : sal_uInt16 nPageNum=nFirstPageNum;
1592 0 : sal_uInt16 nCopyAnz=((!bReverse)?(nLastPageNum-nFirstPageNum):(nFirstPageNum-nLastPageNum))+1;
1593 0 : SdrPage** pPagePtrs=new SdrPage*[nCopyAnz];
1594 : sal_uInt16 nCopyNum;
1595 0 : for(nCopyNum=0; nCopyNum<nCopyAnz; nCopyNum++)
1596 : {
1597 0 : pPagePtrs[nCopyNum]=GetPage(nPageNum);
1598 0 : if (bReverse)
1599 0 : nPageNum--;
1600 : else
1601 0 : nPageNum++;
1602 : }
1603 :
1604 : // now copy the pages
1605 0 : sal_uInt16 nDestNum=nDestPos;
1606 0 : for (nCopyNum=0; nCopyNum<nCopyAnz; nCopyNum++)
1607 : {
1608 0 : SdrPage* pPg=pPagePtrs[nCopyNum];
1609 0 : sal_uInt16 nPageNum2=pPg->GetPageNum();
1610 0 : if (!bMoveNoCopy)
1611 : {
1612 0 : const SdrPage* pPg1=GetPage(nPageNum2);
1613 0 : pPg=pPg1->Clone();
1614 0 : InsertPage(pPg,nDestNum);
1615 0 : if (bUndo)
1616 0 : AddUndo(GetSdrUndoFactory().CreateUndoCopyPage(*pPg));
1617 0 : nDestNum++;
1618 : }
1619 : else
1620 : {
1621 : // TODO: Move is untested!
1622 0 : if (nDestNum>nPageNum2)
1623 0 : nDestNum--;
1624 :
1625 0 : if(bUndo)
1626 0 : AddUndo(GetSdrUndoFactory().CreateUndoSetPageNum(*GetPage(nPageNum2),nPageNum2,nDestNum));
1627 :
1628 0 : pPg=RemovePage(nPageNum2);
1629 0 : InsertPage(pPg,nDestNum);
1630 0 : nDestNum++;
1631 : }
1632 :
1633 0 : if(bReverse)
1634 0 : nPageNum2--;
1635 : else
1636 0 : nPageNum2++;
1637 : }
1638 :
1639 0 : delete[] pPagePtrs;
1640 0 : if(bUndo)
1641 0 : EndUndo();
1642 0 : }
1643 :
1644 0 : void SdrModel::Merge(SdrModel& rSourceModel,
1645 : sal_uInt16 nFirstPageNum, sal_uInt16 nLastPageNum,
1646 : sal_uInt16 nDestPos,
1647 : bool bMergeMasterPages, bool bAllMasterPages,
1648 : bool bUndo, bool bTreadSourceAsConst)
1649 : {
1650 0 : if (&rSourceModel==this)
1651 : {
1652 0 : CopyPages(nFirstPageNum,nLastPageNum,nDestPos,bUndo,!bTreadSourceAsConst);
1653 0 : return;
1654 : }
1655 :
1656 0 : if( bUndo && !IsUndoEnabled() )
1657 0 : bUndo = false;
1658 :
1659 0 : if (bUndo)
1660 0 : BegUndo(ImpGetResStr(STR_UndoMergeModel));
1661 :
1662 0 : sal_uInt16 nSrcPageAnz=rSourceModel.GetPageCount();
1663 0 : sal_uInt16 nSrcMasterPageAnz=rSourceModel.GetMasterPageCount();
1664 0 : sal_uInt16 nDstMasterPageAnz=GetMasterPageCount();
1665 0 : bool bInsPages=(nFirstPageNum<nSrcPageAnz || nLastPageNum<nSrcPageAnz);
1666 0 : sal_uInt16 nMaxSrcPage=nSrcPageAnz; if (nMaxSrcPage!=0) nMaxSrcPage--;
1667 0 : if (nFirstPageNum>nMaxSrcPage) nFirstPageNum=nMaxSrcPage;
1668 0 : if (nLastPageNum>nMaxSrcPage) nLastPageNum =nMaxSrcPage;
1669 0 : bool bReverse=nLastPageNum<nFirstPageNum;
1670 :
1671 0 : sal_uInt16* pMasterMap=NULL;
1672 0 : bool* pMasterNeed=NULL;
1673 0 : sal_uInt16 nMasterNeed=0;
1674 0 : if (bMergeMasterPages && nSrcMasterPageAnz!=0) {
1675 : // determine which MasterPages from rSrcModel we need
1676 0 : pMasterMap=new sal_uInt16[nSrcMasterPageAnz];
1677 0 : pMasterNeed=new bool[nSrcMasterPageAnz];
1678 0 : memset(pMasterMap,0xFF,nSrcMasterPageAnz*sizeof(sal_uInt16));
1679 0 : if (bAllMasterPages) {
1680 0 : memset(pMasterNeed, true, nSrcMasterPageAnz * sizeof(bool));
1681 : } else {
1682 0 : memset(pMasterNeed, false, nSrcMasterPageAnz * sizeof(bool));
1683 0 : sal_uInt16 nAnf= bReverse ? nLastPageNum : nFirstPageNum;
1684 0 : sal_uInt16 nEnd= bReverse ? nFirstPageNum : nLastPageNum;
1685 0 : for (sal_uInt16 i=nAnf; i<=nEnd; i++) {
1686 0 : const SdrPage* pPg=rSourceModel.GetPage(i);
1687 0 : if(pPg->TRG_HasMasterPage())
1688 : {
1689 0 : SdrPage& rMasterPage = pPg->TRG_GetMasterPage();
1690 0 : sal_uInt16 nMPgNum(rMasterPage.GetPageNum());
1691 :
1692 0 : if(nMPgNum < nSrcMasterPageAnz)
1693 : {
1694 0 : pMasterNeed[nMPgNum] = true;
1695 : }
1696 : }
1697 : }
1698 : }
1699 : // now determine the Mapping of the MasterPages
1700 0 : sal_uInt16 nAktMaPagNum=nDstMasterPageAnz;
1701 0 : for (sal_uInt16 i=0; i<nSrcMasterPageAnz; i++) {
1702 0 : if (pMasterNeed[i]) {
1703 0 : pMasterMap[i]=nAktMaPagNum;
1704 0 : nAktMaPagNum++;
1705 0 : nMasterNeed++;
1706 : }
1707 : }
1708 : }
1709 :
1710 : // get the MasterPages
1711 0 : if (pMasterMap!=NULL && pMasterNeed!=NULL && nMasterNeed!=0) {
1712 0 : for (sal_uInt16 i=nSrcMasterPageAnz; i>0;) {
1713 0 : i--;
1714 0 : if (pMasterNeed[i]) {
1715 0 : SdrPage* pPg=NULL;
1716 0 : if (bTreadSourceAsConst) {
1717 0 : const SdrPage* pPg1=rSourceModel.GetMasterPage(i);
1718 0 : pPg=pPg1->Clone();
1719 : } else {
1720 0 : pPg=rSourceModel.RemoveMasterPage(i);
1721 : }
1722 0 : if (pPg!=NULL) {
1723 : // Now append all of them to the end of the DstModel.
1724 : // Don't use InsertMasterPage(), because everything is
1725 : // inconsistent until all are in.
1726 0 : maMaPag.insert(maMaPag.begin()+nDstMasterPageAnz, pPg);
1727 0 : MasterPageListChanged();
1728 0 : pPg->SetInserted(sal_True);
1729 0 : pPg->SetModel(this);
1730 0 : bMPgNumsDirty=sal_True;
1731 0 : if (bUndo) AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pPg));
1732 : } else {
1733 : OSL_FAIL("SdrModel::Merge(): MasterPage not found in SourceModel.");
1734 : }
1735 : }
1736 : }
1737 : }
1738 :
1739 : // get the drawing pages
1740 0 : if (bInsPages) {
1741 0 : sal_uInt16 nSourcePos=nFirstPageNum;
1742 0 : sal_uInt16 nMergeCount=sal_uInt16(Abs((long)((long)nFirstPageNum-nLastPageNum))+1);
1743 0 : if (nDestPos>GetPageCount()) nDestPos=GetPageCount();
1744 0 : while (nMergeCount>0) {
1745 0 : SdrPage* pPg=NULL;
1746 0 : if (bTreadSourceAsConst) {
1747 0 : const SdrPage* pPg1=rSourceModel.GetPage(nSourcePos);
1748 0 : pPg=pPg1->Clone();
1749 : } else {
1750 0 : pPg=rSourceModel.RemovePage(nSourcePos);
1751 : }
1752 0 : if (pPg!=NULL) {
1753 0 : InsertPage(pPg,nDestPos);
1754 0 : if (bUndo) AddUndo(GetSdrUndoFactory().CreateUndoNewPage(*pPg));
1755 :
1756 0 : if(pPg->TRG_HasMasterPage())
1757 : {
1758 0 : SdrPage& rMasterPage = pPg->TRG_GetMasterPage();
1759 0 : sal_uInt16 nMaPgNum(rMasterPage.GetPageNum());
1760 :
1761 0 : if (bMergeMasterPages)
1762 : {
1763 0 : sal_uInt16 nNeuNum(0xFFFF);
1764 :
1765 0 : if(pMasterMap)
1766 : {
1767 0 : nNeuNum = pMasterMap[nMaPgNum];
1768 : }
1769 :
1770 0 : if(nNeuNum != 0xFFFF)
1771 : {
1772 0 : if(bUndo)
1773 : {
1774 0 : AddUndo(GetSdrUndoFactory().CreateUndoPageChangeMasterPage(*pPg));
1775 : }
1776 :
1777 0 : pPg->TRG_SetMasterPage(*GetMasterPage(nNeuNum));
1778 : }
1779 : DBG_ASSERT(nNeuNum!=0xFFFF,"SdrModel::Merge(): Something is crooked with the mapping of the MasterPages.");
1780 : } else {
1781 0 : if (nMaPgNum>=nDstMasterPageAnz) {
1782 : // This is outside of the original area of the MasterPage of the DstModel.
1783 0 : pPg->TRG_ClearMasterPage();
1784 : }
1785 : }
1786 : }
1787 :
1788 : } else {
1789 : OSL_FAIL("SdrModel::Merge(): Drawing page not found in SourceModel.");
1790 : }
1791 0 : nDestPos++;
1792 0 : if (bReverse) nSourcePos--;
1793 0 : else if (bTreadSourceAsConst) nSourcePos++;
1794 0 : nMergeCount--;
1795 : }
1796 : }
1797 :
1798 0 : delete [] pMasterMap;
1799 0 : delete [] pMasterNeed;
1800 :
1801 0 : bMPgNumsDirty=sal_True;
1802 0 : bPagNumsDirty=sal_True;
1803 :
1804 0 : SetChanged();
1805 : // TODO: Missing: merging and mapping of layers
1806 : // at the objects as well as at the MasterPageDescriptors
1807 0 : if (bUndo) EndUndo();
1808 : }
1809 :
1810 0 : void SdrModel::SetStarDrawPreviewMode(sal_Bool bPreview)
1811 : {
1812 0 : if (!bPreview && bStarDrawPreviewMode && GetPageCount())
1813 : {
1814 : // Resetting is not allowed, because the Model might not be loaded completely
1815 : DBG_ASSERT(sal_False,"SdrModel::SetStarDrawPreviewMode(): Resetting not allowed, because Model might not be complete.");
1816 : }
1817 : else
1818 : {
1819 0 : bStarDrawPreviewMode = bPreview;
1820 : }
1821 0 : }
1822 :
1823 958 : uno::Reference< uno::XInterface > SdrModel::getUnoModel()
1824 : {
1825 958 : if( !mxUnoModel.is() )
1826 110 : mxUnoModel = createUnoModel();
1827 :
1828 958 : return mxUnoModel;
1829 : }
1830 :
1831 0 : void SdrModel::setUnoModel( ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xModel )
1832 : {
1833 0 : mxUnoModel = xModel;
1834 0 : }
1835 :
1836 0 : uno::Reference< uno::XInterface > SdrModel::createUnoModel()
1837 : {
1838 : OSL_FAIL( "SdrModel::createUnoModel() - base implementation should not be called!" );
1839 0 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xInt;
1840 0 : return xInt;
1841 : }
1842 :
1843 355 : void SdrModel::setLock( bool bLock )
1844 : {
1845 355 : if( mbModelLocked != bLock )
1846 : {
1847 320 : if( sal_False == bLock )
1848 : {
1849 159 : ImpReformatAllEdgeObjects();
1850 : }
1851 320 : mbModelLocked = bLock;
1852 : }
1853 355 : }
1854 :
1855 : ////////////////////////////////////////////////////////////////////////////////////////////////////
1856 :
1857 934 : void SdrModel::MigrateItemSet( const SfxItemSet* pSourceSet, SfxItemSet* pDestSet, SdrModel* pNewModel )
1858 : {
1859 934 : if( pSourceSet && pDestSet && (pSourceSet != pDestSet ) )
1860 : {
1861 934 : if( pNewModel == NULL )
1862 0 : pNewModel = this;
1863 :
1864 934 : SfxWhichIter aWhichIter(*pSourceSet);
1865 934 : sal_uInt16 nWhich(aWhichIter.FirstWhich());
1866 : const SfxPoolItem *pPoolItem;
1867 :
1868 132422 : while(nWhich)
1869 : {
1870 130554 : if(SFX_ITEM_SET == pSourceSet->GetItemState(nWhich, sal_False, &pPoolItem))
1871 : {
1872 9172 : const SfxPoolItem* pItem = pPoolItem;
1873 :
1874 9172 : switch( nWhich )
1875 : {
1876 : case XATTR_FILLBITMAP:
1877 0 : pItem = ((XFillBitmapItem*)pItem)->checkForUniqueItem( pNewModel );
1878 0 : break;
1879 : case XATTR_LINEDASH:
1880 0 : pItem = ((XLineDashItem*)pItem)->checkForUniqueItem( pNewModel );
1881 0 : break;
1882 : case XATTR_LINESTART:
1883 6 : pItem = ((XLineStartItem*)pItem)->checkForUniqueItem( pNewModel );
1884 6 : break;
1885 : case XATTR_LINEEND:
1886 14 : pItem = ((XLineEndItem*)pItem)->checkForUniqueItem( pNewModel );
1887 14 : break;
1888 : case XATTR_FILLGRADIENT:
1889 2 : pItem = ((XFillGradientItem*)pItem)->checkForUniqueItem( pNewModel );
1890 2 : break;
1891 : case XATTR_FILLFLOATTRANSPARENCE:
1892 : // allow all kinds of XFillFloatTransparenceItem to be set
1893 0 : pItem = ((XFillFloatTransparenceItem*)pItem)->checkForUniqueItem( pNewModel );
1894 0 : break;
1895 : case XATTR_FILLHATCH:
1896 0 : pItem = ((XFillHatchItem*)pItem)->checkForUniqueItem( pNewModel );
1897 0 : break;
1898 : }
1899 :
1900 : // set item
1901 9172 : if( pItem )
1902 : {
1903 9172 : pDestSet->Put(*pItem);
1904 :
1905 : // delete item if it was a generated one
1906 9172 : if( pItem != pPoolItem)
1907 4 : delete (SfxPoolItem*)pItem;
1908 : }
1909 : }
1910 130554 : nWhich = aWhichIter.NextWhich();
1911 934 : }
1912 : }
1913 934 : }
1914 :
1915 : ////////////////////////////////////////////////////////////////////////////////////////////////////
1916 :
1917 680 : void SdrModel::SetForbiddenCharsTable( rtl::Reference<SvxForbiddenCharactersTable> xForbiddenChars )
1918 : {
1919 680 : if( mpForbiddenCharactersTable )
1920 0 : mpForbiddenCharactersTable->release();
1921 :
1922 680 : mpForbiddenCharactersTable = xForbiddenChars.get();
1923 :
1924 680 : if( mpForbiddenCharactersTable )
1925 574 : mpForbiddenCharactersTable->acquire();
1926 :
1927 680 : ImpSetOutlinerDefaults( pDrawOutliner );
1928 680 : ImpSetOutlinerDefaults( pHitTestOutliner );
1929 680 : }
1930 :
1931 13094 : rtl::Reference<SvxForbiddenCharactersTable> SdrModel::GetForbiddenCharsTable() const
1932 : {
1933 13094 : return mpForbiddenCharactersTable;
1934 : }
1935 :
1936 640 : void SdrModel::SetCharCompressType( sal_uInt16 nType )
1937 : {
1938 640 : if( nType != mnCharCompressType )
1939 : {
1940 2 : mnCharCompressType = nType;
1941 2 : ImpSetOutlinerDefaults( pDrawOutliner );
1942 2 : ImpSetOutlinerDefaults( pHitTestOutliner );
1943 : }
1944 640 : }
1945 :
1946 110 : void SdrModel::SetKernAsianPunctuation( sal_Bool bEnabled )
1947 : {
1948 110 : if( mbKernAsianPunctuation != (bool) bEnabled )
1949 : {
1950 0 : mbKernAsianPunctuation = bEnabled;
1951 0 : ImpSetOutlinerDefaults( pDrawOutliner );
1952 0 : ImpSetOutlinerDefaults( pHitTestOutliner );
1953 : }
1954 110 : }
1955 :
1956 530 : void SdrModel::SetAddExtLeading( sal_Bool bEnabled )
1957 : {
1958 530 : if( mbAddExtLeading != (bool) bEnabled )
1959 : {
1960 528 : mbAddExtLeading = bEnabled;
1961 528 : ImpSetOutlinerDefaults( pDrawOutliner );
1962 528 : ImpSetOutlinerDefaults( pHitTestOutliner );
1963 : }
1964 530 : }
1965 :
1966 6 : void SdrModel::ReformatAllTextObjects()
1967 : {
1968 6 : ImpReformatAllTextObjects();
1969 6 : }
1970 :
1971 2262 : SdrOutliner* SdrModel::createOutliner( sal_uInt16 nOutlinerMode )
1972 : {
1973 2262 : if( NULL == mpOutlinerCache )
1974 144 : mpOutlinerCache = new SdrOutlinerCache(this);
1975 :
1976 2262 : return mpOutlinerCache->createOutliner( nOutlinerMode );
1977 : }
1978 :
1979 2262 : void SdrModel::disposeOutliner( SdrOutliner* pOutliner )
1980 : {
1981 2262 : if( mpOutlinerCache )
1982 : {
1983 2262 : mpOutlinerCache->disposeOutliner( pOutliner );
1984 : }
1985 : else
1986 : {
1987 0 : delete pOutliner;
1988 : }
1989 2262 : }
1990 :
1991 0 : SvxNumType SdrModel::GetPageNumType() const
1992 : {
1993 0 : return SVX_ARABIC;
1994 : }
1995 :
1996 864 : const SdrPage* SdrModel::GetPage(sal_uInt16 nPgNum) const
1997 : {
1998 : DBG_ASSERT(nPgNum < maPages.size(), "SdrModel::GetPage: Access out of range (!)");
1999 864 : return maPages[nPgNum];
2000 : }
2001 :
2002 7300 : SdrPage* SdrModel::GetPage(sal_uInt16 nPgNum)
2003 : {
2004 : DBG_ASSERT(nPgNum < maPages.size(), "SdrModel::GetPage: Access out of range (!)");
2005 7300 : return maPages[nPgNum];
2006 : }
2007 :
2008 5390 : sal_uInt16 SdrModel::GetPageCount() const
2009 : {
2010 5390 : return sal_uInt16(maPages.size());
2011 : }
2012 :
2013 2040 : void SdrModel::PageListChanged()
2014 : {
2015 2040 : }
2016 :
2017 100 : const SdrPage* SdrModel::GetMasterPage(sal_uInt16 nPgNum) const
2018 : {
2019 : DBG_ASSERT(nPgNum < maMaPag.size(), "SdrModel::GetMasterPage: Access out of range (!)");
2020 100 : return maMaPag[nPgNum];
2021 : }
2022 :
2023 374 : SdrPage* SdrModel::GetMasterPage(sal_uInt16 nPgNum)
2024 : {
2025 : DBG_ASSERT(nPgNum < maMaPag.size(), "SdrModel::GetMasterPage: Access out of range (!)");
2026 374 : return maMaPag[nPgNum];
2027 : }
2028 :
2029 2606 : sal_uInt16 SdrModel::GetMasterPageCount() const
2030 : {
2031 2606 : return sal_uInt16(maMaPag.size());
2032 : }
2033 :
2034 638 : void SdrModel::MasterPageListChanged()
2035 : {
2036 638 : }
2037 :
2038 68 : void SdrModel::SetSdrUndoManager( SfxUndoManager* pUndoManager )
2039 : {
2040 68 : mpImpl->mpUndoManager = pUndoManager;
2041 68 : }
2042 :
2043 0 : SfxUndoManager* SdrModel::GetSdrUndoManager() const
2044 : {
2045 0 : return mpImpl->mpUndoManager;
2046 : }
2047 :
2048 128 : SdrUndoFactory& SdrModel::GetSdrUndoFactory() const
2049 : {
2050 128 : if( !mpImpl->mpUndoFactory )
2051 82 : mpImpl->mpUndoFactory = new SdrUndoFactory;
2052 128 : return *mpImpl->mpUndoFactory;
2053 : }
2054 :
2055 36 : void SdrModel::SetSdrUndoFactory( SdrUndoFactory* pUndoFactory )
2056 : {
2057 36 : if( pUndoFactory && (pUndoFactory != mpImpl->mpUndoFactory) )
2058 : {
2059 36 : delete mpImpl->mpUndoFactory;
2060 36 : mpImpl->mpUndoFactory = pUndoFactory;
2061 : }
2062 36 : }
2063 :
2064 : /* added for the reporting engine, but does not work
2065 : correctly, so only enable it for this model */
2066 0 : void SdrModel::SetAllowShapePropertyChangeListener( bool bAllow )
2067 : {
2068 0 : if( mpImpl )
2069 : {
2070 0 : mpImpl->mbAllowShapePropertyChangeListener = bAllow;
2071 : }
2072 0 : }
2073 :
2074 : namespace
2075 : {
2076 : class theSdrModelUnoTunnelImplementationId : public rtl::Static< UnoTunnelIdInit, theSdrModelUnoTunnelImplementationId > {};
2077 : }
2078 :
2079 24 : const ::com::sun::star::uno::Sequence< sal_Int8 >& SdrModel::getUnoTunnelImplementationId()
2080 : {
2081 24 : return theSdrModelUnoTunnelImplementationId::get().getSeq();
2082 : }
2083 :
2084 589 : void SdrModel::SetDrawingLayerPoolDefaults()
2085 : {
2086 589 : const String aNullStr;
2087 589 : const Color aNullLineCol(COL_DEFAULT_SHAPE_STROKE);
2088 589 : const Color aNullFillCol(COL_DEFAULT_SHAPE_FILLING);
2089 589 : const XHatch aNullHatch(aNullLineCol);
2090 :
2091 589 : pItemPool->SetPoolDefaultItem( XFillColorItem(aNullStr,aNullFillCol) );
2092 589 : pItemPool->SetPoolDefaultItem( XFillHatchItem(pItemPool,aNullHatch) );
2093 589 : pItemPool->SetPoolDefaultItem( XLineColorItem(aNullStr,aNullLineCol) );
2094 589 : }
2095 :
2096 : ////////////////////////////////////////////////////////////////////////////////////////////////////
2097 :
2098 2472842 : TYPEINIT1(SdrHint,SfxHint);
2099 :
2100 7926 : SdrHint::SdrHint(SdrHintKind eNewHint)
2101 : : mpPage(0L),
2102 : mpObj(0L),
2103 : mpObjList(0L),
2104 7926 : meHint(eNewHint)
2105 : {
2106 7926 : }
2107 :
2108 12983 : SdrHint::SdrHint(const SdrObject& rNewObj)
2109 12983 : : mpPage(rNewObj.GetPage()),
2110 : mpObj(&rNewObj),
2111 12983 : mpObjList(rNewObj.GetObjList()),
2112 38949 : meHint(HINT_OBJCHG)
2113 : {
2114 12983 : maRectangle = rNewObj.GetLastBoundRect();
2115 12983 : }
2116 :
2117 2418 : void SdrHint::SetPage(const SdrPage* pNewPage)
2118 : {
2119 2418 : mpPage = pNewPage;
2120 2418 : }
2121 :
2122 0 : void SdrHint::SetObject(const SdrObject* pNewObj)
2123 : {
2124 0 : mpObj = pNewObj;
2125 0 : }
2126 :
2127 8972 : void SdrHint::SetKind(SdrHintKind eNewKind)
2128 : {
2129 8972 : meHint = eNewKind;
2130 8972 : }
2131 :
2132 1264 : const SdrPage* SdrHint::GetPage() const
2133 : {
2134 1264 : return mpPage;
2135 : }
2136 :
2137 28216 : const SdrObject* SdrHint::GetObject() const
2138 : {
2139 28216 : return mpObj;
2140 : }
2141 :
2142 592353 : SdrHintKind SdrHint::GetKind() const
2143 : {
2144 592353 : return meHint;
2145 : }
2146 :
2147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|