merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / docshell / docsh6.cxx
blob19d2caa5ccb135b867101ab2249a98f46a58c55d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docsh6.cxx,v $
10 * $Revision: 1.17 $
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 // System - Includes -----------------------------------------------------
38 #ifndef PCH
39 #include "scitems.hxx"
41 #include <svx/pageitem.hxx>
42 #include <vcl/virdev.hxx>
43 #include <svx/linkmgr.hxx>
44 #endif
46 // INCLUDE ---------------------------------------------------------------
48 //#include <svxlink.hxx>
50 #include "docsh.hxx"
52 #include "stlsheet.hxx"
53 #include "stlpool.hxx"
54 #include "global.hxx"
55 #include "viewdata.hxx"
56 #include "tabvwsh.hxx"
57 #include "tablink.hxx"
58 #include "collect.hxx"
60 struct ScStylePair
62 SfxStyleSheetBase *pSource;
63 SfxStyleSheetBase *pDest;
67 // STATIC DATA -----------------------------------------------------------
69 //----------------------------------------------------------------------
72 // Ole
75 void __EXPORT ScDocShell::SetVisArea( const Rectangle & rVisArea )
77 // with the SnapVisArea call in SetVisAreaOrSize, it's safe to always
78 // use both the size and position of the VisArea
79 SetVisAreaOrSize( rVisArea, TRUE );
82 void lcl_SetTopRight( Rectangle& rRect, const Point& rPos )
84 Size aSize = rRect.GetSize();
85 rRect.Right() = rPos.X();
86 rRect.Left() = rPos.X() - aSize.Width() + 1;
87 rRect.Top() = rPos.Y();
88 rRect.Bottom() = rPos.Y() + aSize.Height() - 1;
91 void ScDocShell::SetVisAreaOrSize( const Rectangle& rVisArea, BOOL bModifyStart )
93 BOOL bNegativePage = aDocument.IsNegativePage( aDocument.GetVisibleTab() );
95 Rectangle aArea = rVisArea;
96 if (bModifyStart)
98 // when loading, don't check for negative values, because the sheet orientation
99 // might be set later
100 if ( !aDocument.IsImportingXML() )
102 if ( ( bNegativePage ? (aArea.Right() > 0) : (aArea.Left() < 0) ) || aArea.Top() < 0 )
104 // VisArea start position can't be negative.
105 // Move the VisArea, otherwise only the upper left position would
106 // be changed in SnapVisArea, and the size would be wrong.
108 Point aNewPos( 0, Max( aArea.Top(), (long) 0 ) );
109 if ( bNegativePage )
111 aNewPos.X() = Min( aArea.Right(), (long) 0 );
112 lcl_SetTopRight( aArea, aNewPos );
114 else
116 aNewPos.X() = Max( aArea.Left(), (long) 0 );
117 aArea.SetPos( aNewPos );
122 else
124 Rectangle aOldVisArea = SfxObjectShell::GetVisArea();
125 if ( bNegativePage )
126 lcl_SetTopRight( aArea, aOldVisArea.TopRight() );
127 else
128 aArea.SetPos( aOldVisArea.TopLeft() );
131 // hier Position anpassen!
133 // #92248# when loading an ole object, the VisArea is set from the document's
134 // view settings and must be used as-is (document content may not be complete yet).
135 if ( !aDocument.IsImportingXML() )
136 aDocument.SnapVisArea( aArea );
138 //TODO/LATER: it's unclear which IPEnv is used here
140 SvInPlaceEnvironment* pEnv = GetIPEnv();
141 if (pEnv)
143 Window* pWin = pEnv->GetEditWin();
144 pEnv->MakeScale( aArea.GetSize(), MAP_100TH_MM,
145 pWin->LogicToPixel( aArea.GetSize() ) );
146 } */
148 //TODO/LATER: formerly in SvInplaceObject
149 SfxObjectShell::SetVisArea( aArea );
151 if (bIsInplace) // Zoom in der InPlace View einstellen
153 ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
154 if (pViewSh)
156 if (pViewSh->GetViewData()->GetDocShell() == this)
157 pViewSh->UpdateOleZoom();
159 //else
160 // DataChanged( SvDataType() ); // fuer Zuppeln wenn nicht IP-aktiv
163 if (aDocument.IsEmbedded())
165 ScRange aOld;
166 aDocument.GetEmbedded( aOld);
167 aDocument.SetEmbedded( aArea );
168 ScRange aNew;
169 aDocument.GetEmbedded( aNew);
170 if (aOld != aNew)
171 PostPaint(0,0,0,MAXCOL,MAXROW,MAXTAB,PAINT_GRID);
173 //TODO/LATER: currently not implemented
174 //ViewChanged( ASPECT_CONTENT ); // auch im Container anzeigen
178 BOOL ScDocShell::IsOle()
180 return (GetCreateMode() == SFX_CREATE_MODE_EMBEDDED);
183 void ScDocShell::UpdateOle( const ScViewData* pViewData, BOOL bSnapSize )
185 // wenn's gar nicht Ole ist, kann man sich die Berechnungen sparen
186 // (VisArea wird dann beim Save wieder zurueckgesetzt)
188 if (GetCreateMode() == SFX_CREATE_MODE_STANDARD)
189 return;
191 DBG_ASSERT(pViewData,"pViewData==0 bei ScDocShell::UpdateOle");
193 Rectangle aOldArea = SfxObjectShell::GetVisArea();
194 Rectangle aNewArea = aOldArea;
196 BOOL bChange = FALSE;
197 BOOL bEmbedded = aDocument.IsEmbedded();
198 if (bEmbedded)
199 aNewArea = aDocument.GetEmbeddedRect();
200 else
202 SCTAB nTab = pViewData->GetTabNo();
203 if ( nTab != aDocument.GetVisibleTab() )
205 aDocument.SetVisibleTab( nTab );
206 bChange = TRUE;
209 BOOL bNegativePage = aDocument.IsNegativePage( nTab );
210 SCCOL nX = pViewData->GetPosX(SC_SPLIT_LEFT);
211 SCROW nY = pViewData->GetPosY(SC_SPLIT_BOTTOM);
212 Rectangle aMMRect = aDocument.GetMMRect( nX,nY, nX,nY, nTab );
213 if (bNegativePage)
214 lcl_SetTopRight( aNewArea, aMMRect.TopRight() );
215 else
216 aNewArea.SetPos( aMMRect.TopLeft() );
217 if (bSnapSize)
218 aDocument.SnapVisArea(aNewArea); // uses the new VisibleTab
221 if (aNewArea != aOldArea)
223 SetVisAreaOrSize( aNewArea, TRUE ); // hier muss auch der Start angepasst werden
224 bChange = TRUE;
227 // if (bChange)
228 // DataChanged( SvDataType() ); //! passiert auch bei SetModified
232 // Style-Krempel fuer Organizer etc.
235 SfxStyleSheetBasePool* __EXPORT ScDocShell::GetStyleSheetPool()
237 return (SfxStyleSheetBasePool*)aDocument.GetStyleSheetPool();
241 // nach dem Laden von Vorlagen aus einem anderen Dokment (LoadStyles, Insert)
242 // muessen die SetItems (ATTR_PAGE_HEADERSET, ATTR_PAGE_FOOTERSET) auf den richtigen
243 // Pool umgesetzt werden, bevor der Quell-Pool geloescht wird.
245 void lcl_AdjustPool( SfxStyleSheetBasePool* pStylePool )
247 pStylePool->SetSearchMask(SFX_STYLE_FAMILY_PAGE, 0xffff);
248 SfxStyleSheetBase *pStyle = pStylePool->First();
249 while ( pStyle )
251 SfxItemSet& rStyleSet = pStyle->GetItemSet();
253 const SfxPoolItem* pItem;
254 if (rStyleSet.GetItemState(ATTR_PAGE_HEADERSET,FALSE,&pItem) == SFX_ITEM_SET)
256 SfxItemSet& rSrcSet = ((SvxSetItem*)pItem)->GetItemSet();
257 SfxItemSet* pDestSet = new SfxItemSet(*rStyleSet.GetPool(),rSrcSet.GetRanges());
258 pDestSet->Put(rSrcSet);
259 rStyleSet.Put(SvxSetItem(ATTR_PAGE_HEADERSET,pDestSet));
261 if (rStyleSet.GetItemState(ATTR_PAGE_FOOTERSET,FALSE,&pItem) == SFX_ITEM_SET)
263 SfxItemSet& rSrcSet = ((SvxSetItem*)pItem)->GetItemSet();
264 SfxItemSet* pDestSet = new SfxItemSet(*rStyleSet.GetPool(),rSrcSet.GetRanges());
265 pDestSet->Put(rSrcSet);
266 rStyleSet.Put(SvxSetItem(ATTR_PAGE_FOOTERSET,pDestSet));
269 pStyle = pStylePool->Next();
273 void __EXPORT ScDocShell::LoadStyles( SfxObjectShell &rSource )
275 aDocument.StylesToNames();
277 SfxObjectShell::LoadStyles(rSource);
278 lcl_AdjustPool( GetStyleSheetPool() ); // SetItems anpassen
280 aDocument.UpdStlShtPtrsFrmNms();
282 UpdateAllRowHeights();
284 // Paint
286 PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID | PAINT_LEFT );
289 void ScDocShell::LoadStylesArgs( ScDocShell& rSource, BOOL bReplace, BOOL bCellStyles, BOOL bPageStyles )
291 // similar to LoadStyles, but with selectable behavior for XStyleLoader::loadStylesFromURL call
293 if ( !bCellStyles && !bPageStyles ) // nothing to do
294 return;
296 ScStyleSheetPool* pSourcePool = rSource.GetDocument()->GetStyleSheetPool();
297 ScStyleSheetPool* pDestPool = aDocument.GetStyleSheetPool();
299 SfxStyleFamily eFamily = bCellStyles ?
300 ( bPageStyles ? SFX_STYLE_FAMILY_ALL : SFX_STYLE_FAMILY_PARA ) :
301 SFX_STYLE_FAMILY_PAGE;
302 SfxStyleSheetIterator aIter( pSourcePool, eFamily );
303 USHORT nSourceCount = aIter.Count();
304 if ( nSourceCount == 0 )
305 return; // no source styles
307 ScStylePair* pStyles = new ScStylePair[ nSourceCount ];
308 USHORT nFound = 0;
310 // first create all new styles
312 SfxStyleSheetBase* pSourceStyle = aIter.First();
313 while (pSourceStyle)
315 String aName = pSourceStyle->GetName();
316 SfxStyleSheetBase* pDestStyle = pDestPool->Find( pSourceStyle->GetName(), pSourceStyle->GetFamily() );
317 if ( pDestStyle )
319 // touch existing styles only if replace flag is set
320 if ( bReplace )
322 pStyles[nFound].pSource = pSourceStyle;
323 pStyles[nFound].pDest = pDestStyle;
324 ++nFound;
327 else
329 pStyles[nFound].pSource = pSourceStyle;
330 pStyles[nFound].pDest = &pDestPool->Make( aName, pSourceStyle->GetFamily(), pSourceStyle->GetMask() );
331 ++nFound;
334 pSourceStyle = aIter.Next();
337 // then copy contents (after inserting all styles, for parent etc.)
339 for ( USHORT i = 0; i < nFound; ++i )
341 pStyles[i].pDest->GetItemSet().PutExtended(
342 pStyles[i].pSource->GetItemSet(), SFX_ITEM_DONTCARE, SFX_ITEM_DEFAULT);
343 if(pStyles[i].pSource->HasParentSupport())
344 pStyles[i].pDest->SetParent(pStyles[i].pSource->GetParent());
345 // follow is never used
348 lcl_AdjustPool( GetStyleSheetPool() ); // adjust SetItems
349 UpdateAllRowHeights();
350 PostPaint( 0,0,0, MAXCOL,MAXROW,MAXTAB, PAINT_GRID | PAINT_LEFT ); // Paint
352 delete[] pStyles;
356 BOOL __EXPORT ScDocShell::Insert( SfxObjectShell &rSource,
357 USHORT nSourceIdx1, USHORT nSourceIdx2, USHORT nSourceIdx3,
358 USHORT &nIdx1, USHORT &nIdx2, USHORT &nIdx3, USHORT &rIdxDeleted )
360 BOOL bRet = SfxObjectShell::Insert( rSource, nSourceIdx1, nSourceIdx2, nSourceIdx3,
361 nIdx1, nIdx2, nIdx3, rIdxDeleted );
362 if (bRet)
363 lcl_AdjustPool( GetStyleSheetPool() ); // SetItems anpassen
365 return bRet;
368 void ScDocShell::UpdateLinks()
370 SvxLinkManager* pLinkManager = aDocument.GetLinkManager();
371 ScStrCollection aNames;
373 // nicht mehr benutzte Links raus
375 USHORT nCount = pLinkManager->GetLinks().Count();
376 for (USHORT k=nCount; k>0; )
378 --k;
379 ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[k];
380 if (pBase->ISA(ScTableLink))
382 ScTableLink* pTabLink = (ScTableLink*)pBase;
383 if (pTabLink->IsUsed())
385 StrData* pData = new StrData(pTabLink->GetFileName());
386 if (!aNames.Insert(pData))
387 delete pData;
389 else // nicht mehr benutzt -> loeschen
391 pTabLink->SetAddUndo(TRUE);
392 pLinkManager->Remove(k);
398 // neue Links eintragen
400 SCTAB nTabCount = aDocument.GetTableCount();
401 for (SCTAB i=0; i<nTabCount; i++)
402 if (aDocument.IsLinked(i))
404 String aDocName = aDocument.GetLinkDoc(i);
405 String aFltName = aDocument.GetLinkFlt(i);
406 String aOptions = aDocument.GetLinkOpt(i);
407 ULONG nRefresh = aDocument.GetLinkRefreshDelay(i);
408 BOOL bThere = FALSE;
409 for (SCTAB j=0; j<i && !bThere; j++) // im Dokument mehrfach?
410 if (aDocument.IsLinked(j)
411 && aDocument.GetLinkDoc(j) == aDocName
412 && aDocument.GetLinkFlt(j) == aFltName
413 && aDocument.GetLinkOpt(j) == aOptions)
414 // Ignore refresh delay in compare, it should be the
415 // same for identical links and we don't want dupes
416 // if it ain't.
417 bThere = TRUE;
419 if (!bThere) // schon als Filter eingetragen?
421 StrData* pData = new StrData(aDocName);
422 if (!aNames.Insert(pData))
424 delete pData;
425 bThere = TRUE;
428 if (!bThere)
430 ScTableLink* pLink = new ScTableLink( this, aDocName, aFltName, aOptions, nRefresh );
431 pLink->SetInCreate( TRUE );
432 pLinkManager->InsertFileLink( *pLink, OBJECT_CLIENT_FILE, aDocName, &aFltName );
433 pLink->Update();
434 pLink->SetInCreate( FALSE );
439 bool ScDocShell::GetApplicationFlag(SfxApplicationFlagType eFlagType)
441 switch (eFlagType)
443 case SFX_APPFLAG_ALWAYS_ALLOW_SAVE:
444 return true;
446 return false;
449 BOOL ScDocShell::ReloadTabLinks()
451 SvxLinkManager* pLinkManager = aDocument.GetLinkManager();
453 BOOL bAny = FALSE;
454 USHORT nCount = pLinkManager->GetLinks().Count();
455 for (USHORT i=0; i<nCount; i++ )
457 ::sfx2::SvBaseLink* pBase = *pLinkManager->GetLinks()[i];
458 if (pBase->ISA(ScTableLink))
460 ScTableLink* pTabLink = (ScTableLink*)pBase;
461 // pTabLink->SetAddUndo(FALSE); //! Undo's zusammenfassen
462 pTabLink->SetPaint(FALSE); // Paint nur einmal am Ende
463 pTabLink->Update();
464 pTabLink->SetPaint(TRUE);
465 // pTabLink->SetAddUndo(TRUE);
466 bAny = TRUE;
470 if ( bAny )
472 // Paint nur einmal
473 PostPaint( ScRange(0,0,0,MAXCOL,MAXROW,MAXTAB),
474 PAINT_GRID | PAINT_TOP | PAINT_LEFT );
476 SetDocumentModified();
479 return TRUE; //! Fehler erkennen