xref: /AOO41X/main/sc/source/core/data/documen9.cxx (revision d3e0dd8eb215533c15e891ee35bd141abe9397ee)
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 
GetDrawBroadcaster()70 SfxBroadcaster* ScDocument::GetDrawBroadcaster()
71 {
72     return pDrawLayer;
73 }
74 
BeginDrawUndo()75 void ScDocument::BeginDrawUndo()
76 {
77     if (pDrawLayer)
78         pDrawLayer->BeginCalcUndo(false);
79 }
80 
IsDrawRecording() const81 sal_Bool ScDocument::IsDrawRecording() const
82 {
83     return pDrawLayer ? pDrawLayer->IsRecording() : sal_False;
84 }
85 
EndDrawUndo()86 void ScDocument::EndDrawUndo()
87 {
88     if( pDrawLayer )
89         delete pDrawLayer->GetCalcUndo();
90 }
91 
GetColorTable()92 XColorListSharedPtr ScDocument::GetColorTable()
93 {
94     if (pDrawLayer)
95         return pDrawLayer->GetColorTableFromSdrModel();
96     else
97     {
98         if (!maColorTable.get())
99         {
100             SvtPathOptions aPathOpt;
101             maColorTable = XPropertyListFactory::CreateSharedXColorList(aPathOpt.GetPalettePath());
102         }
103 
104         return maColorTable;
105     }
106 }
107 
TransferDrawPage(ScDocument * pSrcDoc,SCTAB nSrcPos,SCTAB nDestPos)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 
InitDrawLayer(SfxObjectShell * pDocShell)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 
UpdateDrawLanguages()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 
UpdateDrawPrinter()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 
IsChart(const SdrObject * pObject)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 
IMPL_LINK_INLINE_START(ScDocument,GetUserDefinedColor,sal_uInt16 *,pColorIndex)249 IMPL_LINK_INLINE_START( ScDocument, GetUserDefinedColor, sal_uInt16 *, pColorIndex )
250 {
251     return (long) &((GetColorTable()->GetColor(*pColorIndex))->GetColor());
252 }
IMPL_LINK_INLINE_END(ScDocument,GetUserDefinedColor,sal_uInt16 *,pColorIndex)253 IMPL_LINK_INLINE_END( ScDocument, GetUserDefinedColor, sal_uInt16 *, pColorIndex )
254 
255 void ScDocument::DeleteDrawLayer()
256 {
257     delete pDrawLayer;
258 }
259 
DrawGetPrintArea(ScRange & rRange,sal_Bool bSetHor,sal_Bool bSetVer) const260 sal_Bool ScDocument::DrawGetPrintArea( ScRange& rRange, sal_Bool bSetHor, sal_Bool bSetVer ) const
261 {
262     return pDrawLayer->GetPrintArea( rRange, bSetHor, bSetVer );
263 }
264 
DrawMovePage(sal_uInt16 nOldPos,sal_uInt16 nNewPos)265 void ScDocument::DrawMovePage( sal_uInt16 nOldPos, sal_uInt16 nNewPos )
266 {
267     pDrawLayer->ScMovePage(nOldPos,nNewPos);
268 }
269 
DrawCopyPage(sal_uInt16 nOldPos,sal_uInt16 nNewPos)270 void ScDocument::DrawCopyPage( sal_uInt16 nOldPos, sal_uInt16 nNewPos )
271 {
272     // angelegt wird die Page schon im ScTable ctor
273     pDrawLayer->ScCopyPage( nOldPos, nNewPos, sal_False );
274 }
275 
DeleteObjectsInArea(SCCOL nCol1,SCROW nRow1,SCCOL nCol2,SCROW nRow2,const ScMarkData & rMark)276 void ScDocument::DeleteObjectsInArea( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
277                         const ScMarkData& rMark )
278 {
279     if (!pDrawLayer)
280         return;
281 
282     SCTAB nTabCount = GetTableCount();
283     for (SCTAB nTab=0; nTab<=nTabCount; nTab++)
284         if (pTab[nTab] && rMark.GetTableSelect(nTab))
285             pDrawLayer->DeleteObjectsInArea( nTab, nCol1, nRow1, nCol2, nRow2 );
286 }
287 
DeleteObjectsInSelection(const ScMarkData & rMark)288 void ScDocument::DeleteObjectsInSelection( const ScMarkData& rMark )
289 {
290     if (!pDrawLayer)
291         return;
292 
293     pDrawLayer->DeleteObjectsInSelection( rMark );
294 }
295 
HasOLEObjectsInArea(const ScRange & rRange,const ScMarkData * pTabMark)296 sal_Bool ScDocument::HasOLEObjectsInArea( const ScRange& rRange, const ScMarkData* pTabMark )
297 {
298     //  pTabMark is used only for selected tables. If pTabMark is 0, all tables of rRange are used.
299 
300     if (!pDrawLayer)
301         return sal_False;
302 
303     SCTAB nStartTab = 0;
304     SCTAB nEndTab = MAXTAB;
305     if ( !pTabMark )
306     {
307         nStartTab = rRange.aStart.Tab();
308         nEndTab = rRange.aEnd.Tab();
309     }
310 
311     for (SCTAB nTab = nStartTab; nTab <= nEndTab; nTab++)
312     {
313         if ( !pTabMark || pTabMark->GetTableSelect(nTab) )
314         {
315             Rectangle aMMRect = GetMMRect( rRange.aStart.Col(), rRange.aStart.Row(),
316                                             rRange.aEnd.Col(), rRange.aEnd.Row(), nTab );
317 
318             SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
319             DBG_ASSERT(pPage,"Page ?");
320             if (pPage)
321             {
322                 SdrObjListIter aIter( *pPage, IM_FLAT );
323                 SdrObject* pObject = aIter.Next();
324                 while (pObject)
325                 {
326                     if ( pObject->GetObjIdentifier() == OBJ_OLE2 &&
327                             aMMRect.IsInside( pObject->GetCurrentBoundRect() ) )
328                         return sal_True;
329 
330                     pObject = aIter.Next();
331                 }
332             }
333         }
334     }
335 
336     return sal_False;
337 }
338 
339 
StartAnimations(SCTAB nTab,Window * pWin)340 void ScDocument::StartAnimations( SCTAB nTab, Window* pWin )
341 {
342     if (!pDrawLayer)
343         return;
344     SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
345     DBG_ASSERT(pPage,"Page ?");
346     if (!pPage)
347         return;
348 
349     SdrObjListIter aIter( *pPage, IM_FLAT );
350     SdrObject* pObject = aIter.Next();
351     while (pObject)
352     {
353         if (pObject->ISA(SdrGrafObj))
354         {
355             SdrGrafObj* pGrafObj = (SdrGrafObj*)pObject;
356             if ( pGrafObj->IsAnimated() )
357             {
358                 const Rectangle& rRect = pGrafObj->GetCurrentBoundRect();
359                 pGrafObj->StartAnimation( pWin, rRect.TopLeft(), rRect.GetSize() );
360             }
361         }
362         pObject = aIter.Next();
363     }
364 }
365 
366 //UNUSED2008-05  void ScDocument::RefreshNoteFlags()
367 //UNUSED2008-05  {
368 //UNUSED2008-05      if (!pDrawLayer)
369 //UNUSED2008-05          return;
370 //UNUSED2008-05
371 //UNUSED2008-05      sal_Bool bAnyIntObj = sal_False;
372 //UNUSED2008-05      SCTAB nTab;
373 //UNUSED2008-05      ScPostIt aNote(this);
374 //UNUSED2008-05      for (nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++)
375 //UNUSED2008-05      {
376 //UNUSED2008-05          SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
377 //UNUSED2008-05          DBG_ASSERT(pPage,"Page ?");
378 //UNUSED2008-05          if (pPage)
379 //UNUSED2008-05          {
380 //UNUSED2008-05              SdrObjListIter aIter( *pPage, IM_FLAT );
381 //UNUSED2008-05              SdrObject* pObject = aIter.Next();
382 //UNUSED2008-05              while (pObject)
383 //UNUSED2008-05              {
384 //UNUSED2008-05                  if ( pObject->GetLayer() == SC_LAYER_INTERN )
385 //UNUSED2008-05                  {
386 //UNUSED2008-05                      bAnyIntObj = sal_True;  // for all internal objects, including detective
387 //UNUSED2008-05
388 //UNUSED2008-05                      if ( pObject->ISA( SdrCaptionObj ) )
389 //UNUSED2008-05                      {
390 //UNUSED2008-05                          ScDrawObjData* pData = ScDrawLayer::GetObjData( pObject );
391 //UNUSED2008-05                          if ( pData )
392 //UNUSED2008-05                          {
393 //UNUSED2008-05                              if ( GetNote( pData->aStt.Col(), pData->aStt.Row(), nTab, aNote))
394 //UNUSED2008-05                                  if ( !aNote.IsShown() )
395 //UNUSED2008-05                                  {
396 //UNUSED2008-05                                      aNote.SetShown(sal_True);
397 //UNUSED2008-05                                      SetNote( pData->aStt.Col(), pData->aStt.Row(), nTab, aNote);
398 //UNUSED2008-05                                  }
399 //UNUSED2008-05                          }
400 //UNUSED2008-05                      }
401 //UNUSED2008-05                  }
402 //UNUSED2008-05                  pObject = aIter.Next();
403 //UNUSED2008-05              }
404 //UNUSED2008-05          }
405 //UNUSED2008-05      }
406 //UNUSED2008-05
407 //UNUSED2008-05      if (bAnyIntObj)
408 //UNUSED2008-05      {
409 //UNUSED2008-05          //  update attributes for all note objects and the colors of detective objects
410 //UNUSED2008-05          //  (we don't know with which settings the file was created)
411 //UNUSED2008-05
412 //UNUSED2008-05          ScDetectiveFunc aFunc( this, 0 );
413 //UNUSED2008-05          aFunc.UpdateAllComments();
414 //UNUSED2008-05          aFunc.UpdateAllArrowColors();
415 //UNUSED2008-05      }
416 //UNUSED2008-05  }
417 
HasBackgroundDraw(SCTAB nTab,const Rectangle & rMMRect)418 sal_Bool ScDocument::HasBackgroundDraw( SCTAB nTab, const Rectangle& rMMRect )
419 {
420     //  Gibt es Objekte auf dem Hintergrund-Layer, die (teilweise) von rMMRect
421     //  betroffen sind?
422     //  (fuer Drawing-Optimierung, vor dem Hintergrund braucht dann nicht geloescht
423     //   zu werden)
424 
425     if (!pDrawLayer)
426         return sal_False;
427     SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
428     DBG_ASSERT(pPage,"Page ?");
429     if (!pPage)
430         return sal_False;
431 
432     sal_Bool bFound = sal_False;
433 
434     SdrObjListIter aIter( *pPage, IM_FLAT );
435     SdrObject* pObject = aIter.Next();
436     while (pObject && !bFound)
437     {
438         if ( pObject->GetLayer() == SC_LAYER_BACK && pObject->GetCurrentBoundRect().IsOver( rMMRect ) )
439             bFound = sal_True;
440         pObject = aIter.Next();
441     }
442 
443     return bFound;
444 }
445 
HasAnyDraw(SCTAB nTab,const Rectangle & rMMRect)446 sal_Bool ScDocument::HasAnyDraw( SCTAB nTab, const Rectangle& rMMRect )
447 {
448     //  Gibt es ueberhaupt Objekte, die (teilweise) von rMMRect
449     //  betroffen sind?
450     //  (um leere Seiten beim Drucken zu erkennen)
451 
452     if (!pDrawLayer)
453         return sal_False;
454     SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
455     DBG_ASSERT(pPage,"Page ?");
456     if (!pPage)
457         return sal_False;
458 
459     sal_Bool bFound = sal_False;
460 
461     SdrObjListIter aIter( *pPage, IM_FLAT );
462     SdrObject* pObject = aIter.Next();
463     while (pObject && !bFound)
464     {
465         if ( pObject->GetCurrentBoundRect().IsOver( rMMRect ) )
466             bFound = sal_True;
467         pObject = aIter.Next();
468     }
469 
470     return bFound;
471 }
472 
EnsureGraphicNames()473 void ScDocument::EnsureGraphicNames()
474 {
475     if (pDrawLayer)
476         pDrawLayer->EnsureGraphicNames();
477 }
478 
GetObjectAtPoint(SCTAB nTab,const Point & rPos)479 SdrObject* ScDocument::GetObjectAtPoint( SCTAB nTab, const Point& rPos )
480 {
481     //  fuer Drag&Drop auf Zeichenobjekt
482 
483     SdrObject* pFound = NULL;
484     if (pDrawLayer && pTab[nTab])
485     {
486         SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
487         DBG_ASSERT(pPage,"Page ?");
488         if (pPage)
489         {
490             SdrObjListIter aIter( *pPage, IM_FLAT );
491             SdrObject* pObject = aIter.Next();
492             while (pObject)
493             {
494                 if ( pObject->GetCurrentBoundRect().IsInside(rPos) )
495                 {
496                     //  Intern interessiert gar nicht
497                     //  Objekt vom Back-Layer nur, wenn kein Objekt von anderem Layer getroffen
498 
499                     SdrLayerID nLayer = pObject->GetLayer();
500                     if ( (nLayer != SC_LAYER_INTERN) && (nLayer != SC_LAYER_HIDDEN) )
501                     {
502                         if ( nLayer != SC_LAYER_BACK ||
503                                 !pFound || pFound->GetLayer() == SC_LAYER_BACK )
504                         {
505                             pFound = pObject;
506                         }
507                     }
508                 }
509                 //  weitersuchen -> letztes (oberstes) getroffenes Objekt nehmen
510 
511                 pObject = aIter.Next();
512             }
513         }
514     }
515     return pFound;
516 }
517 
IsPrintEmpty(SCTAB nTab,SCCOL nStartCol,SCROW nStartRow,SCCOL nEndCol,SCROW nEndRow,sal_Bool bLeftIsEmpty,ScRange * pLastRange,Rectangle * pLastMM) const518 sal_Bool ScDocument::IsPrintEmpty( SCTAB nTab, SCCOL nStartCol, SCROW nStartRow,
519                                 SCCOL nEndCol, SCROW nEndRow, sal_Bool bLeftIsEmpty,
520                                 ScRange* pLastRange, Rectangle* pLastMM ) const
521 {
522     if (!IsBlockEmpty( nTab, nStartCol, nStartRow, nEndCol, nEndRow ))
523         return sal_False;
524 
525     ScDocument* pThis = (ScDocument*)this;  //! GetMMRect / HasAnyDraw etc. const !!!
526 
527     Rectangle aMMRect;
528     if ( pLastRange && pLastMM && nTab == pLastRange->aStart.Tab() &&
529             nStartRow == pLastRange->aStart.Row() && nEndRow == pLastRange->aEnd.Row() )
530     {
531         //  keep vertical part of aMMRect, only update horizontal position
532         aMMRect = *pLastMM;
533 
534         long nLeft = 0;
535         SCCOL i;
536         for (i=0; i<nStartCol; i++)
537             nLeft += GetColWidth(i,nTab);
538         long nRight = nLeft;
539         for (i=nStartCol; i<=nEndCol; i++)
540             nRight += GetColWidth(i,nTab);
541 
542         aMMRect.Left()  = (long)(nLeft  * HMM_PER_TWIPS);
543         aMMRect.Right() = (long)(nRight * HMM_PER_TWIPS);
544     }
545     else
546         aMMRect = pThis->GetMMRect( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
547 
548     if ( pLastRange && pLastMM )
549     {
550         *pLastRange = ScRange( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab );
551         *pLastMM = aMMRect;
552     }
553 
554     if ( pThis->HasAnyDraw( nTab, aMMRect ))
555         return sal_False;
556 
557     if ( nStartCol > 0 && !bLeftIsEmpty )
558     {
559         //  aehnlich wie in ScPrintFunc::AdjustPrintArea
560         //! ExtendPrintArea erst ab Start-Spalte des Druckbereichs
561 
562         SCCOL nExtendCol = nStartCol - 1;
563         SCROW nTmpRow = nEndRow;
564 
565         pThis->ExtendMerge( 0,nStartRow, nExtendCol,nTmpRow, nTab,
566                             sal_False, sal_True );      // kein Refresh, incl. Attrs
567 
568         OutputDevice* pDev = pThis->GetPrinter();
569         pDev->SetMapMode( MAP_PIXEL );              // wichtig fuer GetNeededSize
570         pThis->ExtendPrintArea( pDev, nTab, 0, nStartRow, nExtendCol, nEndRow );
571         if ( nExtendCol >= nStartCol )
572             return sal_False;
573     }
574 
575     return sal_True;
576 }
577 
Clear(sal_Bool bFromDestructor)578 void ScDocument::Clear( sal_Bool bFromDestructor )
579 {
580     for (SCTAB i=0; i<=MAXTAB; i++)
581         if (pTab[i])
582         {
583             delete pTab[i];
584             pTab[i]=NULL;
585         }
586     delete pSelectionAttr;
587     pSelectionAttr = NULL;
588 
589     if (pDrawLayer)
590     {
591         // #116168#
592         //pDrawLayer->Clear();
593         pDrawLayer->ClearModel( bFromDestructor );
594     }
595 }
596 
HasControl(SCTAB nTab,const Rectangle & rMMRect)597 sal_Bool ScDocument::HasControl( SCTAB nTab, const Rectangle& rMMRect )
598 {
599     sal_Bool bFound = sal_False;
600 
601     if (pDrawLayer)
602     {
603         SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
604         DBG_ASSERT(pPage,"Page ?");
605         if (pPage)
606         {
607             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
608             SdrObject* pObject = aIter.Next();
609             while (pObject && !bFound)
610             {
611                 if (pObject->ISA(SdrUnoObj))
612                 {
613                     Rectangle aObjRect = pObject->GetLogicRect();
614                     if ( aObjRect.IsOver( rMMRect ) )
615                         bFound = sal_True;
616                 }
617 
618                 pObject = aIter.Next();
619             }
620         }
621     }
622 
623     return bFound;
624 }
625 
InvalidateControls(Window * pWin,SCTAB nTab,const Rectangle & rMMRect)626 void ScDocument::InvalidateControls( Window* pWin, SCTAB nTab, const Rectangle& rMMRect )
627 {
628     if (pDrawLayer)
629     {
630         SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
631         DBG_ASSERT(pPage,"Page ?");
632         if (pPage)
633         {
634             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
635             SdrObject* pObject = aIter.Next();
636             while (pObject)
637             {
638                 if (pObject->ISA(SdrUnoObj))
639                 {
640                     Rectangle aObjRect = pObject->GetLogicRect();
641                     if ( aObjRect.IsOver( rMMRect ) )
642                     {
643                         //  Uno-Controls zeichnen sich immer komplett, ohne Ruecksicht
644                         //  auf ClippingRegions. Darum muss das ganze Objekt neu gepainted
645                         //  werden, damit die Selektion auf der Tabelle nicht uebermalt wird.
646 
647                         //pWin->Invalidate( aObjRect.GetIntersection( rMMRect ) );
648                         pWin->Invalidate( aObjRect );
649                     }
650                 }
651 
652                 pObject = aIter.Next();
653             }
654         }
655     }
656 }
657 
HasDetectiveObjects(SCTAB nTab) const658 sal_Bool ScDocument::HasDetectiveObjects(SCTAB nTab) const
659 {
660     //  looks for detective objects, annotations don't count
661     //  (used to adjust scale so detective objects hit their cells better)
662 
663     sal_Bool bFound = sal_False;
664 
665     if (pDrawLayer)
666     {
667         SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
668         DBG_ASSERT(pPage,"Page ?");
669         if (pPage)
670         {
671             SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
672             SdrObject* pObject = aIter.Next();
673             while (pObject && !bFound)
674             {
675                 // anything on the internal layer except captions (annotations)
676                 if ( (pObject->GetLayer() == SC_LAYER_INTERN) && !ScDrawLayer::IsNoteCaption( pObject ) )
677                     bFound = sal_True;
678 
679                 pObject = aIter.Next();
680             }
681         }
682     }
683 
684     return bFound;
685 }
686 
UpdateFontCharSet()687 void ScDocument::UpdateFontCharSet()
688 {
689     //  In alten Versionen (bis incl. 4.0 ohne SP) wurden beim Austausch zwischen
690     //  Systemen die CharSets in den Font-Attributen nicht angepasst.
691     //  Das muss fuer Dokumente bis incl SP2 nun nachgeholt werden:
692     //  Alles, was nicht SYMBOL ist, wird auf den System-CharSet umgesetzt.
693     //  Bei neuen Dokumenten (Version SC_FONTCHARSET) sollte der CharSet stimmen.
694 
695     sal_Bool bUpdateOld = ( nSrcVer < SC_FONTCHARSET );
696 
697     CharSet eSysSet = gsl_getSystemTextEncoding();
698     if ( eSrcSet != eSysSet || bUpdateOld )
699     {
700         sal_uInt32 nCount,i;
701         SvxFontItem* pItem;
702 
703         ScDocumentPool* pPool = xPoolHelper->GetDocPool();
704         nCount = pPool->GetItemCount2(ATTR_FONT);
705         for (i=0; i<nCount; i++)
706         {
707             pItem = (SvxFontItem*)pPool->GetItem2(ATTR_FONT, i);
708             if ( pItem && ( pItem->GetCharSet() == eSrcSet ||
709                             ( bUpdateOld && pItem->GetCharSet() != RTL_TEXTENCODING_SYMBOL ) ) )
710                 pItem->SetCharSet(eSysSet);
711         }
712 
713         if ( pDrawLayer )
714         {
715             SfxItemPool& rDrawPool = pDrawLayer->GetItemPool();
716             nCount = rDrawPool.GetItemCount2(EE_CHAR_FONTINFO);
717             for (i=0; i<nCount; i++)
718             {
719                 pItem = (SvxFontItem*)rDrawPool.GetItem2(EE_CHAR_FONTINFO, i);
720                 if ( pItem && ( pItem->GetCharSet() == eSrcSet ||
721                                 ( bUpdateOld && pItem->GetCharSet() != RTL_TEXTENCODING_SYMBOL ) ) )
722                     pItem->SetCharSet( eSysSet );
723             }
724         }
725     }
726 }
727 
SetLoadingMedium(bool bVal)728 void ScDocument::SetLoadingMedium( bool bVal )
729 {
730     bLoadingMedium = bVal;
731     for (SCTAB nTab = 0; nTab <= MAXTAB; ++nTab)
732     {
733         if (!pTab[nTab])
734             return;
735 
736         pTab[nTab]->SetLoadingMedium(bVal);
737     }
738 }
739 
SetImportingXML(bool bVal)740 void ScDocument::SetImportingXML( bool bVal )
741 {
742     bImportingXML = bVal;
743     if (pDrawLayer)
744         pDrawLayer->EnableAdjust(!bImportingXML);
745 
746     if ( !bVal )
747     {
748         // #i57869# after loading, do the real RTL mirroring for the sheets that have the LoadingRTL flag set
749 
750         for ( SCTAB nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++ )
751             if ( pTab[nTab]->IsLoadingRTL() )
752             {
753                 pTab[nTab]->SetLoadingRTL( sal_False );
754                 SetLayoutRTL( nTab, sal_True );             // includes mirroring; bImportingXML must be cleared first
755             }
756     }
757 
758     SetLoadingMedium(bVal);
759 }
760 
SetImportingMSXML(bool bVal)761 void ScDocument::SetImportingMSXML( bool bVal )
762 {
763     mbImportingMSXML = bVal;
764 
765     if (pDrawLayer)
766         pDrawLayer->SetUndoAllowed( !mbImportingMSXML );
767 }
768 
SetXMLFromWrapper(sal_Bool bVal)769 void ScDocument::SetXMLFromWrapper( sal_Bool bVal )
770 {
771     bXMLFromWrapper = bVal;
772 }
773 
GetForbiddenCharacters()774 vos::ORef<SvxForbiddenCharactersTable> ScDocument::GetForbiddenCharacters()
775 {
776     return xForbiddenCharacters;
777 }
778 
SetForbiddenCharacters(const vos::ORef<SvxForbiddenCharactersTable> xNew)779 void ScDocument::SetForbiddenCharacters( const vos::ORef<SvxForbiddenCharactersTable> xNew )
780 {
781     xForbiddenCharacters = xNew;
782     if ( pEditEngine )
783         pEditEngine->SetForbiddenCharsTable( xForbiddenCharacters );
784     if ( pDrawLayer )
785         pDrawLayer->SetForbiddenCharsTable( xForbiddenCharacters );
786 }
787 
IsValidAsianCompression() const788 sal_Bool ScDocument::IsValidAsianCompression() const
789 {
790     return ( nAsianCompression != SC_ASIANCOMPRESSION_INVALID );
791 }
792 
GetAsianCompression() const793 sal_uInt8 ScDocument::GetAsianCompression() const
794 {
795     if ( nAsianCompression == SC_ASIANCOMPRESSION_INVALID )
796         return 0;
797     else
798         return nAsianCompression;
799 }
800 
SetAsianCompression(sal_uInt8 nNew)801 void ScDocument::SetAsianCompression(sal_uInt8 nNew)
802 {
803     nAsianCompression = nNew;
804     if ( pEditEngine )
805         pEditEngine->SetAsianCompressionMode( nAsianCompression );
806     if ( pDrawLayer )
807         pDrawLayer->SetCharCompressType( nAsianCompression );
808 }
809 
IsValidAsianKerning() const810 sal_Bool ScDocument::IsValidAsianKerning() const
811 {
812     return ( nAsianKerning != SC_ASIANKERNING_INVALID );
813 }
814 
GetAsianKerning() const815 sal_Bool ScDocument::GetAsianKerning() const
816 {
817     if ( nAsianKerning == SC_ASIANKERNING_INVALID )
818         return sal_False;
819     else
820         return (sal_Bool)nAsianKerning;
821 }
822 
SetAsianKerning(sal_Bool bNew)823 void ScDocument::SetAsianKerning(sal_Bool bNew)
824 {
825     nAsianKerning = (sal_uInt8)bNew;
826     if ( pEditEngine )
827         pEditEngine->SetKernAsianPunctuation( (sal_Bool)nAsianKerning );
828     if ( pDrawLayer )
829         pDrawLayer->SetKernAsianPunctuation( (sal_Bool)nAsianKerning );
830 }
831 
ApplyAsianEditSettings(ScEditEngineDefaulter & rEngine)832 void ScDocument::ApplyAsianEditSettings( ScEditEngineDefaulter& rEngine )
833 {
834     rEngine.SetForbiddenCharsTable( xForbiddenCharacters );
835     rEngine.SetAsianCompressionMode( GetAsianCompression() );
836     rEngine.SetKernAsianPunctuation( GetAsianKerning() );
837 }
838 
839