update dev300-m58
[ooovba.git] / sc / source / core / data / documen9.cxx
blob5591d98b1f3761875b7c7c8554e1d2b9c6b1b923
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: documen9.cxx,v $
10 * $Revision: 1.43.52.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <com/sun/star/embed/XEmbeddedObject.hpp>
35 #include <com/sun/star/embed/XClassifiedObject.hpp>
36 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
38 // INCLUDE ---------------------------------------------------------------
40 #include "scitems.hxx"
41 #include <svx/eeitem.hxx>
43 #include <sot/exchange.hxx>
44 #include <svx/akrnitem.hxx>
45 #include <svx/fontitem.hxx>
46 #include <svx/forbiddencharacterstable.hxx>
47 #include <svx/langitem.hxx>
48 #include <svx/svdetc.hxx>
49 #include <svx/svditer.hxx>
50 #include <svx/svdocapt.hxx>
51 #include <svx/svdograf.hxx>
52 #include <svx/svdoole2.hxx>
53 #include <svx/svdouno.hxx>
54 #include <svx/svdpage.hxx>
55 #include <svx/svdundo.hxx>
56 #include <svx/xtable.hxx>
57 #include <sfx2/objsh.hxx>
58 #include <sfx2/printer.hxx>
59 #include <svtools/saveopt.hxx>
60 #include <svtools/pathoptions.hxx>
62 #include "document.hxx"
63 #include "docoptio.hxx"
64 #include "table.hxx"
65 #include "drwlayer.hxx"
66 #include "markdata.hxx"
67 #include "patattr.hxx"
68 #include "rechead.hxx"
69 #include "poolhelp.hxx"
70 #include "docpool.hxx"
71 #include "chartarr.hxx"
72 #include "detfunc.hxx" // for UpdateAllComments
73 #include "editutil.hxx"
74 #include "postit.hxx"
76 using namespace ::com::sun::star;
78 // -----------------------------------------------------------------------
81 SfxBroadcaster* ScDocument::GetDrawBroadcaster()
83 return pDrawLayer;
86 void ScDocument::BeginDrawUndo()
88 if (pDrawLayer)
89 pDrawLayer->BeginCalcUndo();
92 XColorTable* ScDocument::GetColorTable()
94 if (pDrawLayer)
95 return pDrawLayer->GetColorTable();
96 else
98 if (!pColorTable)
100 SvtPathOptions aPathOpt;
101 pColorTable = new XColorTable( aPathOpt.GetPalettePath() );
104 return pColorTable;
108 BOOL lcl_AdjustRanges( ScRangeList& rRanges, SCTAB nSource, SCTAB nDest, SCTAB nTabCount )
110 //! if multiple sheets are copied, update references into the other copied sheets?
112 BOOL bChanged = FALSE;
114 ULONG nCount = rRanges.Count();
115 for (ULONG i=0; i<nCount; i++)
117 ScRange* pRange = rRanges.GetObject(i);
118 if ( pRange->aStart.Tab() == nSource && pRange->aEnd.Tab() == nSource )
120 pRange->aStart.SetTab( nDest );
121 pRange->aEnd.SetTab( nDest );
122 bChanged = TRUE;
124 if ( pRange->aStart.Tab() >= nTabCount )
126 pRange->aStart.SetTab( nTabCount > 0 ? ( nTabCount - 1 ) : 0 );
127 bChanged = TRUE;
129 if ( pRange->aEnd.Tab() >= nTabCount )
131 pRange->aEnd.SetTab( nTabCount > 0 ? ( nTabCount - 1 ) : 0 );
132 bChanged = TRUE;
136 return bChanged;
139 void ScDocument::TransferDrawPage(ScDocument* pSrcDoc, SCTAB nSrcPos, SCTAB nDestPos)
141 if (pDrawLayer && pSrcDoc->pDrawLayer)
143 SdrPage* pOldPage = pSrcDoc->pDrawLayer->GetPage(static_cast<sal_uInt16>(nSrcPos));
144 SdrPage* pNewPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nDestPos));
146 if (pOldPage && pNewPage)
148 SdrObjListIter aIter( *pOldPage, IM_FLAT );
149 SdrObject* pOldObject = aIter.Next();
150 while (pOldObject)
152 // #116235#
153 SdrObject* pNewObject = pOldObject->Clone();
154 // SdrObject* pNewObject = pOldObject->Clone( pNewPage, pDrawLayer );
155 pNewObject->SetModel(pDrawLayer);
156 pNewObject->SetPage(pNewPage);
158 pNewObject->NbcMove(Size(0,0));
159 pNewPage->InsertObject( pNewObject );
161 if (pDrawLayer->IsRecording())
162 pDrawLayer->AddCalcUndo( new SdrUndoInsertObj( *pNewObject ) );
164 // #71726# if it's a chart, make sure the data references are valid
165 // (this must be after InsertObject!)
167 if ( pNewObject->GetObjIdentifier() == OBJ_OLE2 )
169 uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pNewObject)->GetObjRef();
170 uno::Reference< embed::XClassifiedObject > xClassified( xIPObj, uno::UNO_QUERY );
171 SvGlobalName aObjectClassName;
172 if ( xClassified.is() )
174 try {
175 aObjectClassName = SvGlobalName( xClassified->getClassID() );
176 } catch( uno::Exception& )
178 // TODO: handle error?
182 if ( xIPObj.is() && SotExchange::IsChart( aObjectClassName ) )
184 String aChartName = ((SdrOle2Obj*)pNewObject)->GetPersistName();
186 uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( aChartName ) );
187 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
188 if( xChartDoc.is() && xReceiver.is() )
190 if( !xChartDoc->hasInternalDataProvider() )
192 ::std::vector< ScRangeList > aRangesVector;
193 GetChartRanges( aChartName, aRangesVector, pSrcDoc );
195 ::std::vector< ScRangeList >::iterator aIt( aRangesVector.begin() );
196 for( ; aIt!=aRangesVector.end(); aIt++ )
198 ScRangeList& rScRangeList( *aIt );
199 lcl_AdjustRanges( rScRangeList, nSrcPos, nDestPos, GetTableCount() );
201 SetChartRanges( aChartName, aRangesVector );
207 pOldObject = aIter.Next();
213 void ScDocument::InitDrawLayer( SfxObjectShell* pDocShell )
215 if (pDocShell && !pShell)
216 pShell = pDocShell;
218 // DBG_ASSERT(pShell,"InitDrawLayer ohne Shell");
220 if (!pDrawLayer)
222 String aName;
223 if ( pShell && !pShell->IsLoading() ) // #88438# don't call GetTitle while loading
224 aName = pShell->GetTitle();
225 pDrawLayer = new ScDrawLayer( this, aName );
226 if (GetLinkManager())
227 pDrawLayer->SetLinkManager( pLinkManager );
229 // Drawing pages are accessed by table number, so they must also be present
230 // for preceding table numbers, even if the tables aren't allocated
231 // (important for clipboard documents).
233 SCTAB nDrawPages = 0;
234 SCTAB nTab;
235 for (nTab=0; nTab<=MAXTAB; nTab++)
236 if (pTab[nTab])
237 nDrawPages = nTab + 1; // needed number of pages
239 for (nTab=0; nTab<nDrawPages; nTab++)
241 pDrawLayer->ScAddPage( nTab ); // always add page, with or without the table
242 if (pTab[nTab])
244 String aTabName;
245 pTab[nTab]->GetName(aTabName);
246 pDrawLayer->ScRenamePage( nTab, aTabName );
248 pTab[nTab]->SetDrawPageSize(false); // #54782# set the right size immediately
249 #if 0
250 ULONG nx = (ULONG) ((double) (MAXCOL+1) * STD_COL_WIDTH * HMM_PER_TWIPS );
251 ULONG ny = (ULONG) ((double) (MAXROW+1) * ScGlobal::nStdRowHeight * HMM_PER_TWIPS );
252 pDrawLayer->SetPageSize( nTab, Size( nx, ny ) );
253 #endif
257 pDrawLayer->SetDefaultTabulator( GetDocOptions().GetTabDistance() );
259 UpdateDrawPrinter();
260 UpdateDrawDefaults();
261 UpdateDrawLanguages();
262 if (bImportingXML)
263 pDrawLayer->EnableAdjust(FALSE);
265 pDrawLayer->SetForbiddenCharsTable( xForbiddenCharacters );
266 pDrawLayer->SetCharCompressType( GetAsianCompression() );
267 pDrawLayer->SetKernAsianPunctuation( GetAsianKerning() );
271 void ScDocument::UpdateDrawLanguages()
273 if (pDrawLayer)
275 SfxItemPool& rDrawPool = pDrawLayer->GetItemPool();
276 rDrawPool.SetPoolDefaultItem( SvxLanguageItem( eLanguage, EE_CHAR_LANGUAGE ) );
277 rDrawPool.SetPoolDefaultItem( SvxLanguageItem( eCjkLanguage, EE_CHAR_LANGUAGE_CJK ) );
278 rDrawPool.SetPoolDefaultItem( SvxLanguageItem( eCtlLanguage, EE_CHAR_LANGUAGE_CTL ) );
282 void ScDocument::UpdateDrawDefaults()
284 // drawing layer defaults that are set for new documents (if InitNew was called)
286 if ( pDrawLayer && bSetDrawDefaults )
288 SfxItemPool& rDrawPool = pDrawLayer->GetItemPool();
289 rDrawPool.SetPoolDefaultItem( SvxAutoKernItem( TRUE, EE_CHAR_PAIRKERNING ) );
293 void ScDocument::UpdateDrawPrinter()
295 if (pDrawLayer)
297 // use the printer even if IsValid is false
298 // Application::GetDefaultDevice causes trouble with changing MapModes
300 // OutputDevice* pRefDev = GetPrinter();
301 // pRefDev->SetMapMode( MAP_100TH_MM );
302 pDrawLayer->SetRefDevice(GetRefDevice());
306 sal_Bool ScDocument::IsChart( const SdrObject* pObject )
308 // #109985#
309 // IsChart() implementation moved to svx drawinglayer
310 if(pObject && OBJ_OLE2 == pObject->GetObjIdentifier())
312 return ((SdrOle2Obj*)pObject)->IsChart();
315 return sal_False;
318 IMPL_LINK_INLINE_START( ScDocument, GetUserDefinedColor, USHORT *, pColorIndex )
320 return (long) &((GetColorTable()->GetColor(*pColorIndex))->GetColor());
322 IMPL_LINK_INLINE_END( ScDocument, GetUserDefinedColor, USHORT *, pColorIndex )
324 void ScDocument::DeleteDrawLayer()
326 delete pDrawLayer;
329 void ScDocument::DeleteColorTable()
331 delete pColorTable;
334 BOOL ScDocument::DrawGetPrintArea( ScRange& rRange, BOOL bSetHor, BOOL bSetVer ) const
336 return pDrawLayer->GetPrintArea( rRange, bSetHor, bSetVer );
339 void ScDocument::DrawMovePage( USHORT nOldPos, USHORT nNewPos )
341 pDrawLayer->ScMovePage(nOldPos,nNewPos);
344 void ScDocument::DrawCopyPage( USHORT nOldPos, USHORT nNewPos )
346 // angelegt wird die Page schon im ScTable ctor
347 pDrawLayer->ScCopyPage( nOldPos, nNewPos, FALSE );
350 void ScDocument::DeleteObjectsInArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
351 const ScMarkData& rMark )
353 if (!pDrawLayer)
354 return;
356 SCTAB nTabCount = GetTableCount();
357 for (SCTAB nTab=0; nTab<=nTabCount; nTab++)
358 if (pTab[nTab] && rMark.GetTableSelect(nTab))
359 pDrawLayer->DeleteObjectsInArea( nTab, nCol1, nRow1, nCol2, nRow2 );
362 void ScDocument::DeleteObjectsInSelection( const ScMarkData& rMark )
364 if (!pDrawLayer)
365 return;
367 pDrawLayer->DeleteObjectsInSelection( rMark );
370 BOOL ScDocument::HasOLEObjectsInArea( const ScRange& rRange, const ScMarkData* pTabMark )
372 // pTabMark is used only for selected tables. If pTabMark is 0, all tables of rRange are used.
374 if (!pDrawLayer)
375 return FALSE;
377 SCTAB nStartTab = 0;
378 SCTAB nEndTab = MAXTAB;
379 if ( !pTabMark )
381 nStartTab = rRange.aStart.Tab();
382 nEndTab = rRange.aEnd.Tab();
385 for (SCTAB nTab = nStartTab; nTab <= nEndTab; nTab++)
387 if ( !pTabMark || pTabMark->GetTableSelect(nTab) )
389 Rectangle aMMRect = GetMMRect( rRange.aStart.Col(), rRange.aStart.Row(),
390 rRange.aEnd.Col(), rRange.aEnd.Row(), nTab );
392 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
393 DBG_ASSERT(pPage,"Page ?");
394 if (pPage)
396 SdrObjListIter aIter( *pPage, IM_FLAT );
397 SdrObject* pObject = aIter.Next();
398 while (pObject)
400 if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
401 aMMRect.IsInside( pObject->GetCurrentBoundRect() ) )
402 return TRUE;
404 pObject = aIter.Next();
410 return FALSE;
414 void ScDocument::StartAnimations( SCTAB nTab, Window* pWin )
416 if (!pDrawLayer)
417 return;
418 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
419 DBG_ASSERT(pPage,"Page ?");
420 if (!pPage)
421 return;
423 SdrObjListIter aIter( *pPage, IM_FLAT );
424 SdrObject* pObject = aIter.Next();
425 while (pObject)
427 if (pObject->ISA(SdrGrafObj))
429 SdrGrafObj* pGrafObj = (SdrGrafObj*)pObject;
430 if ( pGrafObj->IsAnimated() )
432 const Rectangle& rRect = pGrafObj->GetCurrentBoundRect();
433 pGrafObj->StartAnimation( pWin, rRect.TopLeft(), rRect.GetSize() );
436 pObject = aIter.Next();
440 //UNUSED2008-05 void ScDocument::RefreshNoteFlags()
441 //UNUSED2008-05 {
442 //UNUSED2008-05 if (!pDrawLayer)
443 //UNUSED2008-05 return;
444 //UNUSED2008-05
445 //UNUSED2008-05 BOOL bAnyIntObj = FALSE;
446 //UNUSED2008-05 SCTAB nTab;
447 //UNUSED2008-05 ScPostIt aNote(this);
448 //UNUSED2008-05 for (nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++)
449 //UNUSED2008-05 {
450 //UNUSED2008-05 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
451 //UNUSED2008-05 DBG_ASSERT(pPage,"Page ?");
452 //UNUSED2008-05 if (pPage)
453 //UNUSED2008-05 {
454 //UNUSED2008-05 SdrObjListIter aIter( *pPage, IM_FLAT );
455 //UNUSED2008-05 SdrObject* pObject = aIter.Next();
456 //UNUSED2008-05 while (pObject)
457 //UNUSED2008-05 {
458 //UNUSED2008-05 if ( pObject->GetLayer() == SC_LAYER_INTERN )
459 //UNUSED2008-05 {
460 //UNUSED2008-05 bAnyIntObj = TRUE; // for all internal objects, including detective
461 //UNUSED2008-05
462 //UNUSED2008-05 if ( pObject->ISA( SdrCaptionObj ) )
463 //UNUSED2008-05 {
464 //UNUSED2008-05 ScDrawObjData* pData = ScDrawLayer::GetObjData( pObject );
465 //UNUSED2008-05 if ( pData )
466 //UNUSED2008-05 {
467 //UNUSED2008-05 if ( GetNote( pData->aStt.Col(), pData->aStt.Row(), nTab, aNote))
468 //UNUSED2008-05 if ( !aNote.IsShown() )
469 //UNUSED2008-05 {
470 //UNUSED2008-05 aNote.SetShown(TRUE);
471 //UNUSED2008-05 SetNote( pData->aStt.Col(), pData->aStt.Row(), nTab, aNote);
472 //UNUSED2008-05 }
473 //UNUSED2008-05 }
474 //UNUSED2008-05 }
475 //UNUSED2008-05 }
476 //UNUSED2008-05 pObject = aIter.Next();
477 //UNUSED2008-05 }
478 //UNUSED2008-05 }
479 //UNUSED2008-05 }
480 //UNUSED2008-05
481 //UNUSED2008-05 if (bAnyIntObj)
482 //UNUSED2008-05 {
483 //UNUSED2008-05 // update attributes for all note objects and the colors of detective objects
484 //UNUSED2008-05 // (we don't know with which settings the file was created)
485 //UNUSED2008-05
486 //UNUSED2008-05 ScDetectiveFunc aFunc( this, 0 );
487 //UNUSED2008-05 aFunc.UpdateAllComments();
488 //UNUSED2008-05 aFunc.UpdateAllArrowColors();
489 //UNUSED2008-05 }
490 //UNUSED2008-05 }
492 BOOL ScDocument::HasBackgroundDraw( SCTAB nTab, const Rectangle& rMMRect )
494 // Gibt es Objekte auf dem Hintergrund-Layer, die (teilweise) von rMMRect
495 // betroffen sind?
496 // (fuer Drawing-Optimierung, vor dem Hintergrund braucht dann nicht geloescht
497 // zu werden)
499 if (!pDrawLayer)
500 return FALSE;
501 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
502 DBG_ASSERT(pPage,"Page ?");
503 if (!pPage)
504 return FALSE;
506 BOOL bFound = FALSE;
508 SdrObjListIter aIter( *pPage, IM_FLAT );
509 SdrObject* pObject = aIter.Next();
510 while (pObject && !bFound)
512 if ( pObject->GetLayer() == SC_LAYER_BACK && pObject->GetCurrentBoundRect().IsOver( rMMRect ) )
513 bFound = TRUE;
514 pObject = aIter.Next();
517 return bFound;
520 BOOL ScDocument::HasAnyDraw( SCTAB nTab, const Rectangle& rMMRect )
522 // Gibt es ueberhaupt Objekte, die (teilweise) von rMMRect
523 // betroffen sind?
524 // (um leere Seiten beim Drucken zu erkennen)
526 if (!pDrawLayer)
527 return FALSE;
528 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
529 DBG_ASSERT(pPage,"Page ?");
530 if (!pPage)
531 return FALSE;
533 BOOL bFound = FALSE;
535 SdrObjListIter aIter( *pPage, IM_FLAT );
536 SdrObject* pObject = aIter.Next();
537 while (pObject && !bFound)
539 if ( pObject->GetCurrentBoundRect().IsOver( rMMRect ) )
540 bFound = TRUE;
541 pObject = aIter.Next();
544 return bFound;
547 void ScDocument::EnsureGraphicNames()
549 if (pDrawLayer)
550 pDrawLayer->EnsureGraphicNames();
553 SdrObject* ScDocument::GetObjectAtPoint( SCTAB nTab, const Point& rPos )
555 // fuer Drag&Drop auf Zeichenobjekt
557 SdrObject* pFound = NULL;
558 if (pDrawLayer && pTab[nTab])
560 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
561 DBG_ASSERT(pPage,"Page ?");
562 if (pPage)
564 SdrObjListIter aIter( *pPage, IM_FLAT );
565 SdrObject* pObject = aIter.Next();
566 while (pObject)
568 if ( pObject->GetCurrentBoundRect().IsInside(rPos) )
570 // Intern interessiert gar nicht
571 // Objekt vom Back-Layer nur, wenn kein Objekt von anderem Layer getroffen
573 SdrLayerID nLayer = pObject->GetLayer();
574 if ( (nLayer != SC_LAYER_INTERN) && (nLayer != SC_LAYER_HIDDEN) )
576 if ( nLayer != SC_LAYER_BACK ||
577 !pFound || pFound->GetLayer() == SC_LAYER_BACK )
579 pFound = pObject;
583 // weitersuchen -> letztes (oberstes) getroffenes Objekt nehmen
585 pObject = aIter.Next();
589 return pFound;
592 BOOL ScDocument::IsPrintEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
593 SCCOL nEndCol, SCROW nEndRow, BOOL bLeftIsEmpty,
594 ScRange* pLastRange, Rectangle* pLastMM ) const
596 if (!IsBlockEmpty( nTab, nStartCol, nStartRow, nEndCol, nEndRow ))
597 return FALSE;
599 ScDocument* pThis = (ScDocument*)this; //! GetMMRect / HasAnyDraw etc. const !!!
601 Rectangle aMMRect;
602 if ( pLastRange && pLastMM && nTab == pLastRange->aStart.Tab() &&
603 nStartRow == pLastRange->aStart.Row() && nEndRow == pLastRange->aEnd.Row() )
605 // keep vertical part of aMMRect, only update horizontal position
606 aMMRect = *pLastMM;
608 long nLeft = 0;
609 SCCOL i;
610 for (i=0; i<nStartCol; i++)
611 nLeft += GetColWidth(i,nTab);
612 long nRight = nLeft;
613 for (i=nStartCol; i<=nEndCol; i++)
614 nRight += GetColWidth(i,nTab);
616 aMMRect.Left() = (long)(nLeft * HMM_PER_TWIPS);
617 aMMRect.Right() = (long)(nRight * HMM_PER_TWIPS);
619 else
620 aMMRect = pThis->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
622 if ( pLastRange && pLastMM )
624 *pLastRange = ScRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab );
625 *pLastMM = aMMRect;
628 if ( pThis->HasAnyDraw( nTab, aMMRect ))
629 return FALSE;
631 if ( nStartCol > 0 && !bLeftIsEmpty )
633 // aehnlich wie in ScPrintFunc::AdjustPrintArea
634 //! ExtendPrintArea erst ab Start-Spalte des Druckbereichs
636 SCCOL nExtendCol = nStartCol - 1;
637 SCROW nTmpRow = nEndRow;
639 pThis->ExtendMerge( 0,nStartRow, nExtendCol,nTmpRow, nTab,
640 FALSE, TRUE ); // kein Refresh, incl. Attrs
642 OutputDevice* pDev = pThis->GetPrinter();
643 pDev->SetMapMode( MAP_PIXEL ); // wichtig fuer GetNeededSize
644 pThis->ExtendPrintArea( pDev, nTab, 0, nStartRow, nExtendCol, nEndRow );
645 if ( nExtendCol >= nStartCol )
646 return FALSE;
649 return TRUE;
652 void ScDocument::Clear( sal_Bool bFromDestructor )
654 for (SCTAB i=0; i<=MAXTAB; i++)
655 if (pTab[i])
657 delete pTab[i];
658 pTab[i]=NULL;
660 delete pSelectionAttr;
661 pSelectionAttr = NULL;
663 if (pDrawLayer)
665 // #116168#
666 //pDrawLayer->Clear();
667 pDrawLayer->ClearModel( bFromDestructor );
671 BOOL ScDocument::HasControl( SCTAB nTab, const Rectangle& rMMRect )
673 BOOL bFound = FALSE;
675 if (pDrawLayer)
677 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
678 DBG_ASSERT(pPage,"Page ?");
679 if (pPage)
681 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
682 SdrObject* pObject = aIter.Next();
683 while (pObject && !bFound)
685 if (pObject->ISA(SdrUnoObj))
687 Rectangle aObjRect = pObject->GetLogicRect();
688 if ( aObjRect.IsOver( rMMRect ) )
689 bFound = TRUE;
692 pObject = aIter.Next();
697 return bFound;
700 void ScDocument::InvalidateControls( Window* pWin, SCTAB nTab, const Rectangle& rMMRect )
702 if (pDrawLayer)
704 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
705 DBG_ASSERT(pPage,"Page ?");
706 if (pPage)
708 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
709 SdrObject* pObject = aIter.Next();
710 while (pObject)
712 if (pObject->ISA(SdrUnoObj))
714 Rectangle aObjRect = pObject->GetLogicRect();
715 if ( aObjRect.IsOver( rMMRect ) )
717 // Uno-Controls zeichnen sich immer komplett, ohne Ruecksicht
718 // auf ClippingRegions. Darum muss das ganze Objekt neu gepainted
719 // werden, damit die Selektion auf der Tabelle nicht uebermalt wird.
721 //pWin->Invalidate( aObjRect.GetIntersection( rMMRect ) );
722 pWin->Invalidate( aObjRect );
726 pObject = aIter.Next();
732 BOOL ScDocument::HasDetectiveObjects(SCTAB nTab) const
734 // looks for detective objects, annotations don't count
735 // (used to adjust scale so detective objects hit their cells better)
737 BOOL bFound = FALSE;
739 if (pDrawLayer)
741 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
742 DBG_ASSERT(pPage,"Page ?");
743 if (pPage)
745 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
746 SdrObject* pObject = aIter.Next();
747 while (pObject && !bFound)
749 // anything on the internal layer except captions (annotations)
750 if ( (pObject->GetLayer() == SC_LAYER_INTERN) && !ScDrawLayer::IsNoteCaption( pObject ) )
751 bFound = TRUE;
753 pObject = aIter.Next();
758 return bFound;
761 void ScDocument::UpdateFontCharSet()
763 // In alten Versionen (bis incl. 4.0 ohne SP) wurden beim Austausch zwischen
764 // Systemen die CharSets in den Font-Attributen nicht angepasst.
765 // Das muss fuer Dokumente bis incl SP2 nun nachgeholt werden:
766 // Alles, was nicht SYMBOL ist, wird auf den System-CharSet umgesetzt.
767 // Bei neuen Dokumenten (Version SC_FONTCHARSET) sollte der CharSet stimmen.
769 BOOL bUpdateOld = ( nSrcVer < SC_FONTCHARSET );
771 CharSet eSysSet = gsl_getSystemTextEncoding();
772 if ( eSrcSet != eSysSet || bUpdateOld )
774 USHORT nCount,i;
775 SvxFontItem* pItem;
777 ScDocumentPool* pPool = xPoolHelper->GetDocPool();
778 nCount = pPool->GetItemCount(ATTR_FONT);
779 for (i=0; i<nCount; i++)
781 pItem = (SvxFontItem*)pPool->GetItem(ATTR_FONT, i);
782 if ( pItem && ( pItem->GetCharSet() == eSrcSet ||
783 ( bUpdateOld && pItem->GetCharSet() != RTL_TEXTENCODING_SYMBOL ) ) )
784 pItem->GetCharSet() = eSysSet;
787 if ( pDrawLayer )
789 SfxItemPool& rDrawPool = pDrawLayer->GetItemPool();
790 nCount = rDrawPool.GetItemCount(EE_CHAR_FONTINFO);
791 for (i=0; i<nCount; i++)
793 pItem = (SvxFontItem*)rDrawPool.GetItem(EE_CHAR_FONTINFO, i);
794 if ( pItem && ( pItem->GetCharSet() == eSrcSet ||
795 ( bUpdateOld && pItem->GetCharSet() != RTL_TEXTENCODING_SYMBOL ) ) )
796 pItem->GetCharSet() = eSysSet;
802 void ScDocument::SetLoadingMedium( bool bVal )
804 bLoadingMedium = bVal;
807 bool ScDocument::IsLoadingMedium() const
809 return bLoadingMedium;
812 void ScDocument::SetImportingXML( BOOL bVal )
814 bImportingXML = bVal;
815 if (pDrawLayer)
816 pDrawLayer->EnableAdjust(!bImportingXML);
818 if ( !bVal )
820 // #i57869# after loading, do the real RTL mirroring for the sheets that have the LoadingRTL flag set
822 for ( SCTAB nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++ )
823 if ( pTab[nTab]->IsLoadingRTL() )
825 pTab[nTab]->SetLoadingRTL( FALSE );
826 SetLayoutRTL( nTab, TRUE ); // includes mirroring; bImportingXML must be cleared first
831 void ScDocument::SetXMLFromWrapper( BOOL bVal )
833 bXMLFromWrapper = bVal;
836 vos::ORef<SvxForbiddenCharactersTable> ScDocument::GetForbiddenCharacters()
838 return xForbiddenCharacters;
841 void ScDocument::SetForbiddenCharacters( const vos::ORef<SvxForbiddenCharactersTable> xNew )
843 xForbiddenCharacters = xNew;
844 if ( pEditEngine )
845 pEditEngine->SetForbiddenCharsTable( xForbiddenCharacters );
846 if ( pDrawLayer )
847 pDrawLayer->SetForbiddenCharsTable( xForbiddenCharacters );
850 BOOL ScDocument::IsValidAsianCompression() const
852 return ( nAsianCompression != SC_ASIANCOMPRESSION_INVALID );
855 BYTE ScDocument::GetAsianCompression() const
857 if ( nAsianCompression == SC_ASIANCOMPRESSION_INVALID )
858 return 0;
859 else
860 return nAsianCompression;
863 void ScDocument::SetAsianCompression(BYTE nNew)
865 nAsianCompression = nNew;
866 if ( pEditEngine )
867 pEditEngine->SetAsianCompressionMode( nAsianCompression );
868 if ( pDrawLayer )
869 pDrawLayer->SetCharCompressType( nAsianCompression );
872 BOOL ScDocument::IsValidAsianKerning() const
874 return ( nAsianKerning != SC_ASIANKERNING_INVALID );
877 BOOL ScDocument::GetAsianKerning() const
879 if ( nAsianKerning == SC_ASIANKERNING_INVALID )
880 return FALSE;
881 else
882 return (BOOL)nAsianKerning;
885 void ScDocument::SetAsianKerning(BOOL bNew)
887 nAsianKerning = (BYTE)bNew;
888 if ( pEditEngine )
889 pEditEngine->SetKernAsianPunctuation( (BOOL)nAsianKerning );
890 if ( pDrawLayer )
891 pDrawLayer->SetKernAsianPunctuation( (BOOL)nAsianKerning );