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