xref: /aoo42x/main/sc/source/core/data/documen9.cxx (revision 1396af09)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 // INCLUDE ---------------------------------------------------------------
28 
29 #include "scitems.hxx"
30 #include <editeng/eeitem.hxx>
31 
32 #include <sot/exchange.hxx>
33 #include <editeng/akrnitem.hxx>
34 #include <editeng/fontitem.hxx>
35 #include <editeng/forbiddencharacterstable.hxx>
36 #include <editeng/langitem.hxx>
37 #include <svx/svdetc.hxx>
38 #include <svx/svditer.hxx>
39 #include <svx/svdocapt.hxx>
40 #include <svx/svdograf.hxx>
41 #include <svx/svdoole2.hxx>
42 #include <svx/svdouno.hxx>
43 #include <svx/svdpage.hxx>
44 #include <svx/svdundo.hxx>
45 #include <svx/xtable.hxx>
46 #include <sfx2/objsh.hxx>
47 #include <sfx2/printer.hxx>
48 #include <unotools/saveopt.hxx>
49 #include <unotools/pathoptions.hxx>
50 
51 #include "document.hxx"
52 #include "docoptio.hxx"
53 #include "table.hxx"
54 #include "drwlayer.hxx"
55 #include "markdata.hxx"
56 #include "patattr.hxx"
57 #include "rechead.hxx"
58 #include "poolhelp.hxx"
59 #include "docpool.hxx"
60 #include "detfunc.hxx"		// for UpdateAllComments
61 #include "editutil.hxx"
62 #include "postit.hxx"
63 #include "charthelper.hxx"
64 
65 using namespace ::com::sun::star;
66 #include <stdio.h>
67 // -----------------------------------------------------------------------
68 
69 
70 SfxBroadcaster* ScDocument::GetDrawBroadcaster()
71 {
72 	return pDrawLayer;
73 }
74 
75 void ScDocument::BeginDrawUndo()
76 {
77 	if (pDrawLayer)
78 		pDrawLayer->BeginCalcUndo();
79 }
80 
81 sal_Bool ScDocument::IsDrawRecording() const
82 {
83 	return pDrawLayer ? pDrawLayer->IsRecording() : sal_False;
84 }
85 
86 void ScDocument::EndDrawUndo()
87 {
88 	if( pDrawLayer )
89 		delete pDrawLayer->GetCalcUndo();
90 }
91 
92 XColorTable* ScDocument::GetColorTable()
93 {
94 	if (pDrawLayer)
95 		return pDrawLayer->GetColorTable();
96 	else
97 	{
98 		if (!pColorTable)
99 		{
100 			SvtPathOptions aPathOpt;
101 			pColorTable = new XColorTable( aPathOpt.GetPalettePath() );
102 		}
103 
104 		return pColorTable;
105 	}
106 }
107 
108 void ScDocument::TransferDrawPage(ScDocument* pSrcDoc, SCTAB nSrcPos, SCTAB nDestPos)
109 {
110 	if (pDrawLayer && pSrcDoc->pDrawLayer)
111 	{
112 		SdrPage* pOldPage = pSrcDoc->pDrawLayer->GetPage(static_cast<sal_uInt16>(nSrcPos));
113 		SdrPage* pNewPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nDestPos));
114 
115 		if (pOldPage && pNewPage)
116 		{
117 			SdrObjListIter aIter( *pOldPage, IM_FLAT );
118 			SdrObject* pOldObject = aIter.Next();
119 			while (pOldObject)
120 			{
121                 // #i112034# do not copy internal objects (detective) and note captions
122                 if ( pOldObject->GetLayer() != SC_LAYER_INTERN && !ScDrawLayer::IsNoteCaption( pOldObject ) )
123                 {
124                     // #116235#
125                     SdrObject* pNewObject = pOldObject->Clone();
126                     // SdrObject* pNewObject = pOldObject->Clone( pNewPage, pDrawLayer );
127                     pNewObject->SetModel(pDrawLayer);
128                     pNewObject->SetPage(pNewPage);
129 
130                     pNewObject->NbcMove(Size(0,0));
131                     pNewPage->InsertObject( pNewObject );
132 
133                     if (pDrawLayer->IsRecording())
134 			pDrawLayer->AddCalcUndo< SdrUndoInsertObj >( *pNewObject );
135                 }
136 
137 				pOldObject = aIter.Next();
138 			}
139 		}
140 	}
141 
142     //	#71726# make sure the data references of charts are adapted
143 	//	(this must be after InsertObject!)
144     ScChartHelper::AdjustRangesOfChartsOnDestinationPage( pSrcDoc, this, nSrcPos, nDestPos );
145 	ScChartHelper::UpdateChartsOnDestinationPage(this, nDestPos);
146 }
147 
148 void ScDocument::InitDrawLayer( SfxObjectShell* pDocShell )
149 {
150 	if (pDocShell && !pShell)
151 		pShell = pDocShell;
152 
153 //	DBG_ASSERT(pShell,"InitDrawLayer ohne Shell");
154 
155 	if (!pDrawLayer)
156 	{
157 		String aName;
158 		if ( pShell && !pShell->IsLoading() )		// #88438# don't call GetTitle while loading
159 			aName = pShell->GetTitle();
160 		pDrawLayer = new ScDrawLayer( this, aName );
161 		if (GetLinkManager())
162 			pDrawLayer->SetLinkManager( pLinkManager );
163 
164 		//	Drawing pages are accessed by table number, so they must also be present
165 		//	for preceding table numbers, even if the tables aren't allocated
166 		//	(important for clipboard documents).
167 
168 		SCTAB nDrawPages = 0;
169 		SCTAB nTab;
170 		for (nTab=0; nTab<=MAXTAB; nTab++)
171 			if (pTab[nTab])
172 				nDrawPages = nTab + 1;			// needed number of pages
173 
174 		for (nTab=0; nTab<nDrawPages; nTab++)
175 		{
176 			pDrawLayer->ScAddPage( nTab );		// always add page, with or without the table
177 			if (pTab[nTab])
178 			{
179                 String aTabName;
180                 pTab[nTab]->GetName(aTabName);
181                 pDrawLayer->ScRenamePage( nTab, aTabName );
182 
183                 pTab[nTab]->SetDrawPageSize(false,false);     // #54782# set the right size immediately
184 #if 0
185 				sal_uLong nx = (sal_uLong) ((double) (MAXCOL+1) * STD_COL_WIDTH			  * HMM_PER_TWIPS );
186 				sal_uLong ny = (sal_uLong) ((double) (MAXROW+1) * ScGlobal::nStdRowHeight * HMM_PER_TWIPS );
187 				pDrawLayer->SetPageSize( nTab, Size( nx, ny ) );
188 #endif
189 			}
190 		}
191 
192 		pDrawLayer->SetDefaultTabulator( GetDocOptions().GetTabDistance() );
193 
194 		UpdateDrawPrinter();
195 
196         // set draw defaults directly
197         SfxItemPool& rDrawPool = pDrawLayer->GetItemPool();
198         rDrawPool.SetPoolDefaultItem( SvxAutoKernItem( sal_True, EE_CHAR_PAIRKERNING ) );
199 
200         UpdateDrawLanguages();
201 		if (bImportingXML)
202 			pDrawLayer->EnableAdjust(sal_False);
203 
204 		if( IsImportingMSXML( ) )
205 			pDrawLayer->SetUndoAllowed( false );
206 
207 		pDrawLayer->SetForbiddenCharsTable( xForbiddenCharacters );
208 		pDrawLayer->SetCharCompressType( GetAsianCompression() );
209 		pDrawLayer->SetKernAsianPunctuation( GetAsianKerning() );
210 	}
211 }
212 
213 void ScDocument::UpdateDrawLanguages()
214 {
215 	if (pDrawLayer)
216 	{
217 		SfxItemPool& rDrawPool = pDrawLayer->GetItemPool();
218 		rDrawPool.SetPoolDefaultItem( SvxLanguageItem( eLanguage, EE_CHAR_LANGUAGE ) );
219 		rDrawPool.SetPoolDefaultItem( SvxLanguageItem( eCjkLanguage, EE_CHAR_LANGUAGE_CJK ) );
220 		rDrawPool.SetPoolDefaultItem( SvxLanguageItem( eCtlLanguage, EE_CHAR_LANGUAGE_CTL ) );
221 	}
222 }
223 
224 void ScDocument::UpdateDrawPrinter()
225 {
226 	if (pDrawLayer)
227 	{
228 		// use the printer even if IsValid is false
229 		// Application::GetDefaultDevice causes trouble with changing MapModes
230 
231 //		OutputDevice* pRefDev = GetPrinter();
232 //		pRefDev->SetMapMode( MAP_100TH_MM );
233 		pDrawLayer->SetRefDevice(GetRefDevice());
234 	}
235 }
236 
237 sal_Bool ScDocument::IsChart( const SdrObject* pObject )
238 {
239 	// #109985#
240 	// IsChart() implementation moved to svx drawinglayer
241 	if(pObject && OBJ_OLE2 == pObject->GetObjIdentifier())
242 	{
243 		return ((SdrOle2Obj*)pObject)->IsChart();
244 	}
245 
246 	return sal_False;
247 }
248 
249 IMPL_LINK_INLINE_START( ScDocument, GetUserDefinedColor, sal_uInt16 *, pColorIndex )
250 {
251 	return (long) &((GetColorTable()->GetColor(*pColorIndex))->GetColor());
252 }
253 IMPL_LINK_INLINE_END( ScDocument, GetUserDefinedColor, sal_uInt16 *, pColorIndex )
254 
255 void ScDocument::DeleteDrawLayer()
256 {
257 	delete pDrawLayer;
258 }
259 
260 void ScDocument::DeleteColorTable()
261 {
262 	delete pColorTable;
263 }
264 
265 sal_Bool ScDocument::DrawGetPrintArea( ScRange& rRange, sal_Bool bSetHor, sal_Bool bSetVer ) const
266 {
267 	return pDrawLayer->GetPrintArea( rRange, bSetHor, bSetVer );
268 }
269 
270 void ScDocument::DrawMovePage( sal_uInt16 nOldPos, sal_uInt16 nNewPos )
271 {
272 	pDrawLayer->ScMovePage(nOldPos,nNewPos);
273 }
274 
275 void ScDocument::DrawCopyPage( sal_uInt16 nOldPos, sal_uInt16 nNewPos )
276 {
277 	// angelegt wird die Page schon im ScTable ctor
278 	pDrawLayer->ScCopyPage( nOldPos, nNewPos, sal_False );
279 }
280 
281 void ScDocument::DeleteObjectsInArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
282 						const ScMarkData& rMark )
283 {
284 	if (!pDrawLayer)
285 		return;
286 
287 	SCTAB nTabCount = GetTableCount();
288 	for (SCTAB nTab=0; nTab<=nTabCount; nTab++)
289 		if (pTab[nTab] && rMark.GetTableSelect(nTab))
290 			pDrawLayer->DeleteObjectsInArea( nTab, nCol1, nRow1, nCol2, nRow2 );
291 }
292 
293 void ScDocument::DeleteObjectsInSelection( const ScMarkData& rMark )
294 {
295 	if (!pDrawLayer)
296 		return;
297 
298 	pDrawLayer->DeleteObjectsInSelection( rMark );
299 }
300 
301 sal_Bool ScDocument::HasOLEObjectsInArea( const ScRange& rRange, const ScMarkData* pTabMark )
302 {
303 	//	pTabMark is used only for selected tables. If pTabMark is 0, all tables of rRange are used.
304 
305 	if (!pDrawLayer)
306 		return sal_False;
307 
308 	SCTAB nStartTab = 0;
309 	SCTAB nEndTab = MAXTAB;
310 	if ( !pTabMark )
311 	{
312 		nStartTab = rRange.aStart.Tab();
313 		nEndTab = rRange.aEnd.Tab();
314 	}
315 
316 	for (SCTAB nTab = nStartTab; nTab <= nEndTab; nTab++)
317 	{
318 		if ( !pTabMark || pTabMark->GetTableSelect(nTab) )
319 		{
320 			Rectangle aMMRect = GetMMRect( rRange.aStart.Col(), rRange.aStart.Row(),
321 											rRange.aEnd.Col(), rRange.aEnd.Row(), nTab );
322 
323 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
324 			DBG_ASSERT(pPage,"Page ?");
325 			if (pPage)
326 			{
327 				SdrObjListIter aIter( *pPage, IM_FLAT );
328 				SdrObject* pObject = aIter.Next();
329 				while (pObject)
330 				{
331 					if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
332 							aMMRect.IsInside( pObject->GetCurrentBoundRect() ) )
333 						return sal_True;
334 
335 					pObject = aIter.Next();
336 				}
337 			}
338 		}
339 	}
340 
341 	return sal_False;
342 }
343 
344 
345 void ScDocument::StartAnimations( SCTAB nTab, Window* pWin )
346 {
347 	if (!pDrawLayer)
348 		return;
349 	SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
350 	DBG_ASSERT(pPage,"Page ?");
351 	if (!pPage)
352 		return;
353 
354 	SdrObjListIter aIter( *pPage, IM_FLAT );
355 	SdrObject* pObject = aIter.Next();
356 	while (pObject)
357 	{
358 		if (pObject->ISA(SdrGrafObj))
359 		{
360 			SdrGrafObj* pGrafObj = (SdrGrafObj*)pObject;
361 			if ( pGrafObj->IsAnimated() )
362 			{
363 				const Rectangle& rRect = pGrafObj->GetCurrentBoundRect();
364 				pGrafObj->StartAnimation( pWin, rRect.TopLeft(), rRect.GetSize() );
365 			}
366 		}
367 		pObject = aIter.Next();
368 	}
369 }
370 
371 //UNUSED2008-05  void ScDocument::RefreshNoteFlags()
372 //UNUSED2008-05  {
373 //UNUSED2008-05      if (!pDrawLayer)
374 //UNUSED2008-05          return;
375 //UNUSED2008-05
376 //UNUSED2008-05      sal_Bool bAnyIntObj = sal_False;
377 //UNUSED2008-05      SCTAB nTab;
378 //UNUSED2008-05      ScPostIt aNote(this);
379 //UNUSED2008-05      for (nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++)
380 //UNUSED2008-05      {
381 //UNUSED2008-05          SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
382 //UNUSED2008-05          DBG_ASSERT(pPage,"Page ?");
383 //UNUSED2008-05          if (pPage)
384 //UNUSED2008-05          {
385 //UNUSED2008-05              SdrObjListIter aIter( *pPage, IM_FLAT );
386 //UNUSED2008-05              SdrObject* pObject = aIter.Next();
387 //UNUSED2008-05              while (pObject)
388 //UNUSED2008-05              {
389 //UNUSED2008-05                  if ( pObject->GetLayer() == SC_LAYER_INTERN )
390 //UNUSED2008-05                  {
391 //UNUSED2008-05                      bAnyIntObj = sal_True;  // for all internal objects, including detective
392 //UNUSED2008-05
393 //UNUSED2008-05                      if ( pObject->ISA( SdrCaptionObj ) )
394 //UNUSED2008-05                      {
395 //UNUSED2008-05                          ScDrawObjData* pData = ScDrawLayer::GetObjData( pObject );
396 //UNUSED2008-05                          if ( pData )
397 //UNUSED2008-05                          {
398 //UNUSED2008-05                              if ( GetNote( pData->aStt.Col(), pData->aStt.Row(), nTab, aNote))
399 //UNUSED2008-05                                  if ( !aNote.IsShown() )
400 //UNUSED2008-05                                  {
401 //UNUSED2008-05                                      aNote.SetShown(sal_True);
402 //UNUSED2008-05                                      SetNote( pData->aStt.Col(), pData->aStt.Row(), nTab, aNote);
403 //UNUSED2008-05                                  }
404 //UNUSED2008-05                          }
405 //UNUSED2008-05                      }
406 //UNUSED2008-05                  }
407 //UNUSED2008-05                  pObject = aIter.Next();
408 //UNUSED2008-05              }
409 //UNUSED2008-05          }
410 //UNUSED2008-05      }
411 //UNUSED2008-05
412 //UNUSED2008-05      if (bAnyIntObj)
413 //UNUSED2008-05      {
414 //UNUSED2008-05          //  update attributes for all note objects and the colors of detective objects
415 //UNUSED2008-05          //  (we don't know with which settings the file was created)
416 //UNUSED2008-05
417 //UNUSED2008-05          ScDetectiveFunc aFunc( this, 0 );
418 //UNUSED2008-05          aFunc.UpdateAllComments();
419 //UNUSED2008-05          aFunc.UpdateAllArrowColors();
420 //UNUSED2008-05      }
421 //UNUSED2008-05  }
422 
423 sal_Bool ScDocument::HasBackgroundDraw( SCTAB nTab, const Rectangle& rMMRect )
424 {
425 	//	Gibt es Objekte auf dem Hintergrund-Layer, die (teilweise) von rMMRect
426 	//	betroffen sind?
427 	//	(fuer Drawing-Optimierung, vor dem Hintergrund braucht dann nicht geloescht
428 	//	 zu werden)
429 
430 	if (!pDrawLayer)
431 		return sal_False;
432 	SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
433 	DBG_ASSERT(pPage,"Page ?");
434 	if (!pPage)
435 		return sal_False;
436 
437 	sal_Bool bFound = sal_False;
438 
439 	SdrObjListIter aIter( *pPage, IM_FLAT );
440 	SdrObject* pObject = aIter.Next();
441 	while (pObject && !bFound)
442 	{
443 		if ( pObject->GetLayer() == SC_LAYER_BACK && pObject->GetCurrentBoundRect().IsOver( rMMRect ) )
444 			bFound = sal_True;
445 		pObject = aIter.Next();
446 	}
447 
448 	return bFound;
449 }
450 
451 sal_Bool ScDocument::HasAnyDraw( SCTAB nTab, const Rectangle& rMMRect )
452 {
453 	//	Gibt es ueberhaupt Objekte, die (teilweise) von rMMRect
454 	//	betroffen sind?
455 	//	(um leere Seiten beim Drucken zu erkennen)
456 
457 	if (!pDrawLayer)
458 		return sal_False;
459 	SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
460 	DBG_ASSERT(pPage,"Page ?");
461 	if (!pPage)
462 		return sal_False;
463 
464 	sal_Bool bFound = sal_False;
465 
466 	SdrObjListIter aIter( *pPage, IM_FLAT );
467 	SdrObject* pObject = aIter.Next();
468 	while (pObject && !bFound)
469 	{
470 		if ( pObject->GetCurrentBoundRect().IsOver( rMMRect ) )
471 			bFound = sal_True;
472 		pObject = aIter.Next();
473 	}
474 
475 	return bFound;
476 }
477 
478 void ScDocument::EnsureGraphicNames()
479 {
480 	if (pDrawLayer)
481 		pDrawLayer->EnsureGraphicNames();
482 }
483 
484 SdrObject* ScDocument::GetObjectAtPoint( SCTAB nTab, const Point& rPos )
485 {
486 	//	fuer Drag&Drop auf Zeichenobjekt
487 
488 	SdrObject* pFound = NULL;
489 	if (pDrawLayer && pTab[nTab])
490 	{
491 		SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
492 		DBG_ASSERT(pPage,"Page ?");
493 		if (pPage)
494 		{
495 			SdrObjListIter aIter( *pPage, IM_FLAT );
496 			SdrObject* pObject = aIter.Next();
497 			while (pObject)
498 			{
499 				if ( pObject->GetCurrentBoundRect().IsInside(rPos) )
500 				{
501 					//	Intern interessiert gar nicht
502 					//	Objekt vom Back-Layer nur, wenn kein Objekt von anderem Layer getroffen
503 
504 					SdrLayerID nLayer = pObject->GetLayer();
505                     if ( (nLayer != SC_LAYER_INTERN) && (nLayer != SC_LAYER_HIDDEN) )
506 					{
507 						if ( nLayer != SC_LAYER_BACK ||
508 								!pFound || pFound->GetLayer() == SC_LAYER_BACK )
509 						{
510 							pFound = pObject;
511 						}
512 					}
513 				}
514 				//	weitersuchen -> letztes (oberstes) getroffenes Objekt nehmen
515 
516 				pObject = aIter.Next();
517 			}
518 		}
519 	}
520 	return pFound;
521 }
522 
523 sal_Bool ScDocument::IsPrintEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
524 								SCCOL nEndCol, SCROW nEndRow, sal_Bool bLeftIsEmpty,
525 								ScRange* pLastRange, Rectangle* pLastMM ) const
526 {
527 	if (!IsBlockEmpty( nTab, nStartCol, nStartRow, nEndCol, nEndRow ))
528 		return sal_False;
529 
530 	ScDocument* pThis = (ScDocument*)this;	//! GetMMRect / HasAnyDraw etc. const !!!
531 
532 	Rectangle aMMRect;
533 	if ( pLastRange && pLastMM && nTab == pLastRange->aStart.Tab() &&
534 			nStartRow == pLastRange->aStart.Row() && nEndRow == pLastRange->aEnd.Row() )
535 	{
536 		//	keep vertical part of aMMRect, only update horizontal position
537 		aMMRect = *pLastMM;
538 
539 		long nLeft = 0;
540 		SCCOL i;
541 		for (i=0; i<nStartCol; i++)
542 			nLeft += GetColWidth(i,nTab);
543 		long nRight = nLeft;
544 		for (i=nStartCol; i<=nEndCol; i++)
545 			nRight += GetColWidth(i,nTab);
546 
547 		aMMRect.Left()  = (long)(nLeft  * HMM_PER_TWIPS);
548 		aMMRect.Right() = (long)(nRight * HMM_PER_TWIPS);
549 	}
550 	else
551 		aMMRect = pThis->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
552 
553 	if ( pLastRange && pLastMM )
554 	{
555 		*pLastRange = ScRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab );
556 		*pLastMM = aMMRect;
557 	}
558 
559 	if ( pThis->HasAnyDraw( nTab, aMMRect ))
560 		return sal_False;
561 
562 	if ( nStartCol > 0 && !bLeftIsEmpty )
563 	{
564 		//	aehnlich wie in ScPrintFunc::AdjustPrintArea
565 		//!	ExtendPrintArea erst ab Start-Spalte des Druckbereichs
566 
567 		SCCOL nExtendCol = nStartCol - 1;
568 		SCROW nTmpRow = nEndRow;
569 
570 		pThis->ExtendMerge( 0,nStartRow, nExtendCol,nTmpRow, nTab,
571 							sal_False, sal_True );		// kein Refresh, incl. Attrs
572 
573 		OutputDevice* pDev = pThis->GetPrinter();
574 		pDev->SetMapMode( MAP_PIXEL );				// wichtig fuer GetNeededSize
575 		pThis->ExtendPrintArea( pDev, nTab, 0, nStartRow, nExtendCol, nEndRow );
576 		if ( nExtendCol >= nStartCol )
577 			return sal_False;
578 	}
579 
580 	return sal_True;
581 }
582 
583 void ScDocument::Clear( sal_Bool bFromDestructor )
584 {
585 	for (SCTAB i=0; i<=MAXTAB; i++)
586 		if (pTab[i])
587 		{
588 			delete pTab[i];
589 			pTab[i]=NULL;
590 		}
591 	delete pSelectionAttr;
592 	pSelectionAttr = NULL;
593 
594 	if (pDrawLayer)
595 	{
596 		// #116168#
597 		//pDrawLayer->Clear();
598 		pDrawLayer->ClearModel( bFromDestructor );
599 	}
600 }
601 
602 sal_Bool ScDocument::HasControl( SCTAB nTab, const Rectangle& rMMRect )
603 {
604 	sal_Bool bFound = sal_False;
605 
606 	if (pDrawLayer)
607 	{
608 		SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
609 		DBG_ASSERT(pPage,"Page ?");
610 		if (pPage)
611 		{
612 			SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
613 			SdrObject* pObject = aIter.Next();
614 			while (pObject && !bFound)
615 			{
616 				if (pObject->ISA(SdrUnoObj))
617 				{
618 					Rectangle aObjRect = pObject->GetLogicRect();
619 					if ( aObjRect.IsOver( rMMRect ) )
620 						bFound = sal_True;
621 				}
622 
623 				pObject = aIter.Next();
624 			}
625 		}
626 	}
627 
628 	return bFound;
629 }
630 
631 void ScDocument::InvalidateControls( Window* pWin, SCTAB nTab, const Rectangle& rMMRect )
632 {
633 	if (pDrawLayer)
634 	{
635 		SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
636 		DBG_ASSERT(pPage,"Page ?");
637 		if (pPage)
638 		{
639 			SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
640 			SdrObject* pObject = aIter.Next();
641 			while (pObject)
642 			{
643 				if (pObject->ISA(SdrUnoObj))
644 				{
645 					Rectangle aObjRect = pObject->GetLogicRect();
646 					if ( aObjRect.IsOver( rMMRect ) )
647 					{
648 						//	Uno-Controls zeichnen sich immer komplett, ohne Ruecksicht
649 						//	auf ClippingRegions. Darum muss das ganze Objekt neu gepainted
650 						//	werden, damit die Selektion auf der Tabelle nicht uebermalt wird.
651 
652 						//pWin->Invalidate( aObjRect.GetIntersection( rMMRect ) );
653 						pWin->Invalidate( aObjRect );
654 					}
655 				}
656 
657 				pObject = aIter.Next();
658 			}
659 		}
660 	}
661 }
662 
663 sal_Bool ScDocument::HasDetectiveObjects(SCTAB nTab) const
664 {
665 	//	looks for detective objects, annotations don't count
666 	//	(used to adjust scale so detective objects hit their cells better)
667 
668 	sal_Bool bFound = sal_False;
669 
670 	if (pDrawLayer)
671 	{
672 		SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
673 		DBG_ASSERT(pPage,"Page ?");
674 		if (pPage)
675 		{
676 			SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
677 			SdrObject* pObject = aIter.Next();
678 			while (pObject && !bFound)
679 			{
680 				// anything on the internal layer except captions (annotations)
681                 if ( (pObject->GetLayer() == SC_LAYER_INTERN) && !ScDrawLayer::IsNoteCaption( pObject ) )
682 					bFound = sal_True;
683 
684 				pObject = aIter.Next();
685 			}
686 		}
687 	}
688 
689 	return bFound;
690 }
691 
692 void ScDocument::UpdateFontCharSet()
693 {
694 	//	In alten Versionen (bis incl. 4.0 ohne SP) wurden beim Austausch zwischen
695 	//	Systemen die CharSets in den Font-Attributen nicht angepasst.
696 	//	Das muss fuer Dokumente bis incl SP2 nun nachgeholt werden:
697 	//	Alles, was nicht SYMBOL ist, wird auf den System-CharSet umgesetzt.
698 	//	Bei neuen Dokumenten (Version SC_FONTCHARSET) sollte der CharSet stimmen.
699 
700 	sal_Bool bUpdateOld = ( nSrcVer < SC_FONTCHARSET );
701 
702 	CharSet eSysSet = gsl_getSystemTextEncoding();
703 	if ( eSrcSet != eSysSet || bUpdateOld )
704 	{
705 		sal_uInt32 nCount,i;
706 		SvxFontItem* pItem;
707 
708 		ScDocumentPool* pPool = xPoolHelper->GetDocPool();
709 		nCount = pPool->GetItemCount2(ATTR_FONT);
710 		for (i=0; i<nCount; i++)
711 		{
712 			pItem = (SvxFontItem*)pPool->GetItem2(ATTR_FONT, i);
713 			if ( pItem && ( pItem->GetCharSet() == eSrcSet ||
714 							( bUpdateOld && pItem->GetCharSet() != RTL_TEXTENCODING_SYMBOL ) ) )
715                 pItem->SetCharSet(eSysSet);
716 		}
717 
718 		if ( pDrawLayer )
719 		{
720 			SfxItemPool& rDrawPool = pDrawLayer->GetItemPool();
721 			nCount = rDrawPool.GetItemCount2(EE_CHAR_FONTINFO);
722 			for (i=0; i<nCount; i++)
723 			{
724 				pItem = (SvxFontItem*)rDrawPool.GetItem2(EE_CHAR_FONTINFO, i);
725 				if ( pItem && ( pItem->GetCharSet() == eSrcSet ||
726 								( bUpdateOld && pItem->GetCharSet() != RTL_TEXTENCODING_SYMBOL ) ) )
727                     pItem->SetCharSet( eSysSet );
728 			}
729 		}
730 	}
731 }
732 
733 void ScDocument::SetLoadingMedium( bool bVal )
734 {
735     bLoadingMedium = bVal;
736     for (SCTAB nTab = 0; nTab <= MAXTAB; ++nTab)
737     {
738         if (!pTab[nTab])
739             return;
740 
741         pTab[nTab]->SetLoadingMedium(bVal);
742     }
743 }
744 
745 void ScDocument::SetImportingXML( bool bVal )
746 {
747 	bImportingXML = bVal;
748 	if (pDrawLayer)
749 		pDrawLayer->EnableAdjust(!bImportingXML);
750 
751     if ( !bVal )
752     {
753         // #i57869# after loading, do the real RTL mirroring for the sheets that have the LoadingRTL flag set
754 
755         for ( SCTAB nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++ )
756             if ( pTab[nTab]->IsLoadingRTL() )
757             {
758                 pTab[nTab]->SetLoadingRTL( sal_False );
759                 SetLayoutRTL( nTab, sal_True );             // includes mirroring; bImportingXML must be cleared first
760             }
761     }
762 
763     SetLoadingMedium(bVal);
764 }
765 
766 void ScDocument::SetImportingMSXML( bool bVal )
767 {
768     mbImportingMSXML = bVal;
769 
770     if (pDrawLayer)
771         pDrawLayer->SetUndoAllowed( !mbImportingMSXML );
772 }
773 
774 void ScDocument::SetXMLFromWrapper( sal_Bool bVal )
775 {
776     bXMLFromWrapper = bVal;
777 }
778 
779 vos::ORef<SvxForbiddenCharactersTable> ScDocument::GetForbiddenCharacters()
780 {
781 	return xForbiddenCharacters;
782 }
783 
784 void ScDocument::SetForbiddenCharacters( const vos::ORef<SvxForbiddenCharactersTable> xNew )
785 {
786 	xForbiddenCharacters = xNew;
787 	if ( pEditEngine )
788 		pEditEngine->SetForbiddenCharsTable( xForbiddenCharacters );
789 	if ( pDrawLayer )
790 		pDrawLayer->SetForbiddenCharsTable( xForbiddenCharacters );
791 }
792 
793 sal_Bool ScDocument::IsValidAsianCompression() const
794 {
795 	return ( nAsianCompression != SC_ASIANCOMPRESSION_INVALID );
796 }
797 
798 sal_uInt8 ScDocument::GetAsianCompression() const
799 {
800 	if ( nAsianCompression == SC_ASIANCOMPRESSION_INVALID )
801 		return 0;
802 	else
803 		return nAsianCompression;
804 }
805 
806 void ScDocument::SetAsianCompression(sal_uInt8 nNew)
807 {
808 	nAsianCompression = nNew;
809 	if ( pEditEngine )
810 		pEditEngine->SetAsianCompressionMode( nAsianCompression );
811 	if ( pDrawLayer )
812 		pDrawLayer->SetCharCompressType( nAsianCompression );
813 }
814 
815 sal_Bool ScDocument::IsValidAsianKerning() const
816 {
817 	return ( nAsianKerning != SC_ASIANKERNING_INVALID );
818 }
819 
820 sal_Bool ScDocument::GetAsianKerning() const
821 {
822 	if ( nAsianKerning == SC_ASIANKERNING_INVALID )
823 		return sal_False;
824 	else
825 		return (sal_Bool)nAsianKerning;
826 }
827 
828 void ScDocument::SetAsianKerning(sal_Bool bNew)
829 {
830 	nAsianKerning = (sal_uInt8)bNew;
831 	if ( pEditEngine )
832 		pEditEngine->SetKernAsianPunctuation( (sal_Bool)nAsianKerning );
833 	if ( pDrawLayer )
834 		pDrawLayer->SetKernAsianPunctuation( (sal_Bool)nAsianKerning );
835 }
836 
837 void ScDocument::ApplyAsianEditSettings( ScEditEngineDefaulter& rEngine )
838 {
839     rEngine.SetForbiddenCharsTable( xForbiddenCharacters );
840     rEngine.SetAsianCompressionMode( GetAsianCompression() );
841     rEngine.SetKernAsianPunctuation( GetAsianKerning() );
842 }
843 
844