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: docsh6.cxx,v $
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 -----------------------------------------------------
39 #include "scitems.hxx"
41 #include <svx/pageitem.hxx>
42 #include <vcl/virdev.hxx>
43 #include <svx/linkmgr.hxx>
46 // INCLUDE ---------------------------------------------------------------
48 //#include <svxlink.hxx>
52 #include "stlsheet.hxx"
53 #include "stlpool.hxx"
55 #include "viewdata.hxx"
56 #include "tabvwsh.hxx"
57 #include "tablink.hxx"
58 #include "collect.hxx"
62 SfxStyleSheetBase
*pSource
;
63 SfxStyleSheetBase
*pDest
;
67 // STATIC DATA -----------------------------------------------------------
69 //----------------------------------------------------------------------
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
;
98 // when loading, don't check for negative values, because the sheet orientation
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 ) );
111 aNewPos
.X() = Min( aArea
.Right(), (long) 0 );
112 lcl_SetTopRight( aArea
, aNewPos
);
116 aNewPos
.X() = Max( aArea
.Left(), (long) 0 );
117 aArea
.SetPos( aNewPos
);
124 Rectangle aOldVisArea
= SfxObjectShell::GetVisArea();
126 lcl_SetTopRight( aArea
, aOldVisArea
.TopRight() );
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();
143 Window* pWin = pEnv->GetEditWin();
144 pEnv->MakeScale( aArea.GetSize(), MAP_100TH_MM,
145 pWin->LogicToPixel( aArea.GetSize() ) );
148 //TODO/LATER: formerly in SvInplaceObject
149 SfxObjectShell::SetVisArea( aArea
);
151 if (bIsInplace
) // Zoom in der InPlace View einstellen
153 ScTabViewShell
* pViewSh
= ScTabViewShell::GetActiveViewShell();
156 if (pViewSh
->GetViewData()->GetDocShell() == this)
157 pViewSh
->UpdateOleZoom();
160 // DataChanged( SvDataType() ); // fuer Zuppeln wenn nicht IP-aktiv
163 if (aDocument
.IsEmbedded())
166 aDocument
.GetEmbedded( aOld
);
167 aDocument
.SetEmbedded( aArea
);
169 aDocument
.GetEmbedded( 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
)
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();
199 aNewArea
= aDocument
.GetEmbeddedRect();
202 SCTAB nTab
= pViewData
->GetTabNo();
203 if ( nTab
!= aDocument
.GetVisibleTab() )
205 aDocument
.SetVisibleTab( nTab
);
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
);
214 lcl_SetTopRight( aNewArea
, aMMRect
.TopRight() );
216 aNewArea
.SetPos( aMMRect
.TopLeft() );
218 aDocument
.SnapVisArea(aNewArea
); // uses the new VisibleTab
221 if (aNewArea
!= aOldArea
)
223 SetVisAreaOrSize( aNewArea
, TRUE
); // hier muss auch der Start angepasst werden
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();
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();
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
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
];
310 // first create all new styles
312 SfxStyleSheetBase
* pSourceStyle
= aIter
.First();
315 String aName
= pSourceStyle
->GetName();
316 SfxStyleSheetBase
* pDestStyle
= pDestPool
->Find( pSourceStyle
->GetName(), pSourceStyle
->GetFamily() );
319 // touch existing styles only if replace flag is set
322 pStyles
[nFound
].pSource
= pSourceStyle
;
323 pStyles
[nFound
].pDest
= pDestStyle
;
329 pStyles
[nFound
].pSource
= pSourceStyle
;
330 pStyles
[nFound
].pDest
= &pDestPool
->Make( aName
, pSourceStyle
->GetFamily(), pSourceStyle
->GetMask() );
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
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
);
363 lcl_AdjustPool( GetStyleSheetPool() ); // SetItems anpassen
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; )
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
))
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
);
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
419 if (!bThere
) // schon als Filter eingetragen?
421 StrData
* pData
= new StrData(aDocName
);
422 if (!aNames
.Insert(pData
))
430 ScTableLink
* pLink
= new ScTableLink( this, aDocName
, aFltName
, aOptions
, nRefresh
);
431 pLink
->SetInCreate( TRUE
);
432 pLinkManager
->InsertFileLink( *pLink
, OBJECT_CLIENT_FILE
, aDocName
, &aFltName
);
434 pLink
->SetInCreate( FALSE
);
439 bool ScDocShell::GetApplicationFlag(SfxApplicationFlagType eFlagType
)
443 case SFX_APPFLAG_ALWAYS_ALLOW_SAVE
:
449 BOOL
ScDocShell::ReloadTabLinks()
451 SvxLinkManager
* pLinkManager
= aDocument
.GetLinkManager();
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
464 pTabLink
->SetPaint(TRUE
);
465 // pTabLink->SetAddUndo(TRUE);
473 PostPaint( ScRange(0,0,0,MAXCOL
,MAXROW
,MAXTAB
),
474 PAINT_GRID
| PAINT_TOP
| PAINT_LEFT
);
476 SetDocumentModified();
479 return TRUE
; //! Fehler erkennen