1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5b3f79822SAndrew Rist * distributed with this work for additional information
6b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10b3f79822SAndrew Rist *
11b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist *
13b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist * software distributed under the License is distributed on an
15b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17b3f79822SAndrew Rist * specific language governing permissions and limitations
18b3f79822SAndrew Rist * under the License.
19b3f79822SAndrew Rist *
20b3f79822SAndrew Rist *************************************************************/
21b3f79822SAndrew Rist
22b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedObject.hpp>
29cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
30cdf0e10cSrcweir
31cdf0e10cSrcweir
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir
34cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
35cdf0e10cSrcweir #include <math.h> // prevent conflict between exception and std::exception
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include "scitems.hxx"
38cdf0e10cSrcweir #include <sfx2/fcontnr.hxx>
39cdf0e10cSrcweir #include <editeng/eeitem.hxx>
40cdf0e10cSrcweir #include <sfx2/objface.hxx>
41cdf0e10cSrcweir #include <sfx2/app.hxx>
42cdf0e10cSrcweir #include <sfx2/bindings.hxx>
43cdf0e10cSrcweir #include <sfx2/docfile.hxx>
44cdf0e10cSrcweir #include <sfx2/docfilt.hxx>
45cdf0e10cSrcweir #include <svtools/ehdl.hxx>
46cdf0e10cSrcweir #include <basic/sbxcore.hxx>
47cdf0e10cSrcweir #include <sfx2/printer.hxx>
48cdf0e10cSrcweir #include <sfx2/request.hxx>
49cdf0e10cSrcweir #include <svtools/sfxecode.hxx>
50cdf0e10cSrcweir #include <svx/ofaitem.hxx>
51cdf0e10cSrcweir #include <sot/formats.hxx>
52cdf0e10cSrcweir #include <svl/whiter.hxx>
53cdf0e10cSrcweir #include <vcl/msgbox.hxx>
54cdf0e10cSrcweir #include <vcl/waitobj.hxx>
55cdf0e10cSrcweir #include <tools/multisel.hxx>
56cdf0e10cSrcweir #include <svx/dataaccessdescriptor.hxx>
57cdf0e10cSrcweir #include <svx/drawitem.hxx>
58cdf0e10cSrcweir #include <svx/fmview.hxx>
59cdf0e10cSrcweir #include <svx/pageitem.hxx>
60cdf0e10cSrcweir #include <svx/svditer.hxx>
61cdf0e10cSrcweir #include <svx/svdpage.hxx>
62cdf0e10cSrcweir #include <svx/fmshell.hxx>
63cdf0e10cSrcweir #include <svtools/xwindowitem.hxx>
64cdf0e10cSrcweir #include <sfx2/passwd.hxx>
65cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx>
66cdf0e10cSrcweir #include <sfx2/docinsert.hxx>
67cdf0e10cSrcweir #include <svl/PasswordHelper.hxx>
68cdf0e10cSrcweir #include <svl/documentlockfile.hxx>
69cdf0e10cSrcweir #include <svl/sharecontrolfile.hxx>
70*65fffafdSAndrea Pescetti #include <unotools/securityoptions.hxx>
71cdf0e10cSrcweir
72cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
73cdf0e10cSrcweir #include "docuno.hxx"
74cdf0e10cSrcweir
75cdf0e10cSrcweir #include <com/sun/star/sdbc/XResultSet.hpp>
76cdf0e10cSrcweir #include "docsh.hxx"
77cdf0e10cSrcweir #include "docshimp.hxx"
78cdf0e10cSrcweir #include "docfunc.hxx"
79cdf0e10cSrcweir #include "sc.hrc"
80cdf0e10cSrcweir #include "stlsheet.hxx"
81cdf0e10cSrcweir #include "stlpool.hxx"
82cdf0e10cSrcweir #include "appoptio.hxx"
83cdf0e10cSrcweir #include "globstr.hrc"
84cdf0e10cSrcweir #include "global.hxx"
85cdf0e10cSrcweir //CHINA001 #include "styledlg.hxx"
86cdf0e10cSrcweir //CHINA001 #include "hfedtdlg.hxx"
87cdf0e10cSrcweir #include "dbdocfun.hxx"
88cdf0e10cSrcweir #include "printfun.hxx" // DrawToDev
89cdf0e10cSrcweir #include "viewdata.hxx"
90cdf0e10cSrcweir #include "tabvwsh.hxx"
91cdf0e10cSrcweir #include "impex.hxx"
92cdf0e10cSrcweir #include "attrib.hxx"
93cdf0e10cSrcweir //CHINA001 #include "corodlg.hxx"
94cdf0e10cSrcweir #include "undodat.hxx"
95cdf0e10cSrcweir #include "autostyl.hxx"
96cdf0e10cSrcweir #include "undocell.hxx"
97cdf0e10cSrcweir #include "undotab.hxx"
98cdf0e10cSrcweir #include "inputhdl.hxx"
99cdf0e10cSrcweir #include "dbcolect.hxx"
100cdf0e10cSrcweir #include "servobj.hxx"
101cdf0e10cSrcweir #include "rangenam.hxx"
102cdf0e10cSrcweir #include "scmod.hxx"
103cdf0e10cSrcweir //CHINA001 #include "scendlg.hxx"
104cdf0e10cSrcweir #include "chgviset.hxx"
105cdf0e10cSrcweir #include "reffact.hxx"
106cdf0e10cSrcweir #include "chartlis.hxx"
107cdf0e10cSrcweir #include "chartpos.hxx"
108cdf0e10cSrcweir #include "waitoff.hxx"
109cdf0e10cSrcweir #include "tablink.hxx" // ScDocumentLoader statics
110cdf0e10cSrcweir #include "drwlayer.hxx"
111cdf0e10cSrcweir #include "docoptio.hxx"
112cdf0e10cSrcweir #include "undostyl.hxx"
113cdf0e10cSrcweir #include "rangeseq.hxx"
114cdf0e10cSrcweir #include "chgtrack.hxx"
115cdf0e10cSrcweir #include "printopt.hxx"
116cdf0e10cSrcweir #include <com/sun/star/document/UpdateDocMode.hpp>
117cdf0e10cSrcweir #include "scresid.hxx" //add by CHINA001
118cdf0e10cSrcweir #include "scabstdlg.hxx" //CHINA001
119cdf0e10cSrcweir #include "externalrefmgr.hxx"
120cdf0e10cSrcweir #include "sharedocdlg.hxx"
121cdf0e10cSrcweir #include "conditio.hxx"
122cdf0e10cSrcweir #include "sheetevents.hxx"
123cdf0e10cSrcweir
124cdf0e10cSrcweir //------------------------------------------------------------------
125cdf0e10cSrcweir
126cdf0e10cSrcweir #define IS_SHARE_HEADER(set) \
127cdf0e10cSrcweir ((SfxBoolItem&) \
128cdf0e10cSrcweir ((SvxSetItem&)(set).Get(ATTR_PAGE_HEADERSET)).GetItemSet(). \
129cdf0e10cSrcweir Get(ATTR_PAGE_SHARED)).GetValue()
130cdf0e10cSrcweir
131cdf0e10cSrcweir #define IS_SHARE_FOOTER(set) \
132cdf0e10cSrcweir ((SfxBoolItem&) \
133cdf0e10cSrcweir ((SvxSetItem&)(set).Get(ATTR_PAGE_FOOTERSET)).GetItemSet(). \
134cdf0e10cSrcweir Get(ATTR_PAGE_SHARED)).GetValue()
135cdf0e10cSrcweir
136cdf0e10cSrcweir #define IS_AVAILABLE(WhichId,ppItem) \
137cdf0e10cSrcweir (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET)
138cdf0e10cSrcweir
139cdf0e10cSrcweir #define SC_PREVIEW_SIZE_X 10000
140cdf0e10cSrcweir #define SC_PREVIEW_SIZE_Y 12400
141cdf0e10cSrcweir
142cdf0e10cSrcweir
143cdf0e10cSrcweir //------------------------------------------------------------------
144cdf0e10cSrcweir
Execute(SfxRequest & rReq)145cdf0e10cSrcweir void ScDocShell::Execute( SfxRequest& rReq )
146cdf0e10cSrcweir {
147cdf0e10cSrcweir // SID_SC_RANGE (Range),
148cdf0e10cSrcweir // SID_SC_CELLTEXT (CellText),
149cdf0e10cSrcweir // SID_SC_CELLS (Cells) - removed (old Basic)
150cdf0e10cSrcweir
151cdf0e10cSrcweir const SfxItemSet* pReqArgs = rReq.GetArgs();
152cdf0e10cSrcweir SfxBindings* pBindings = GetViewBindings();
153cdf0e10cSrcweir sal_Bool bUndo (aDocument.IsUndoEnabled());
154cdf0e10cSrcweir
155cdf0e10cSrcweir sal_uInt16 nSlot = rReq.GetSlot();
156cdf0e10cSrcweir switch ( nSlot )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir case SID_SC_SETTEXT:
159cdf0e10cSrcweir {
160cdf0e10cSrcweir const SfxPoolItem* pColItem;
161cdf0e10cSrcweir const SfxPoolItem* pRowItem;
162cdf0e10cSrcweir const SfxPoolItem* pTabItem;
163cdf0e10cSrcweir const SfxPoolItem* pTextItem;
164cdf0e10cSrcweir if( pReqArgs && IS_AVAILABLE( FN_PARAM_1, &pColItem ) &&
165cdf0e10cSrcweir IS_AVAILABLE( FN_PARAM_2, &pRowItem ) &&
166cdf0e10cSrcweir IS_AVAILABLE( FN_PARAM_3, &pTabItem ) &&
167cdf0e10cSrcweir IS_AVAILABLE( SID_SC_SETTEXT, &pTextItem ) )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir // Parameter sind 1-based !!!
170cdf0e10cSrcweir SCCOL nCol = ((SfxInt16Item*)pColItem)->GetValue() - 1;
171cdf0e10cSrcweir SCROW nRow = ((SfxInt32Item*)pRowItem)->GetValue() - 1;
172cdf0e10cSrcweir SCTAB nTab = ((SfxInt16Item*)pTabItem)->GetValue() - 1;
173cdf0e10cSrcweir
174cdf0e10cSrcweir SCTAB nTabCount = aDocument.GetTableCount();
175cdf0e10cSrcweir if ( ValidCol(nCol) && ValidRow(nRow) && ValidTab(nTab,nTabCount) )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir if ( aDocument.IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir String aVal = ((const SfxStringItem*)pTextItem)->GetValue();
180cdf0e10cSrcweir aDocument.SetString( nCol, nRow, nTab, aVal );
181cdf0e10cSrcweir
182cdf0e10cSrcweir PostPaintCell( nCol, nRow, nTab );
183cdf0e10cSrcweir SetDocumentModified();
184cdf0e10cSrcweir
185cdf0e10cSrcweir rReq.Done();
186cdf0e10cSrcweir break;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir else // geschuetzte Zelle
189cdf0e10cSrcweir {
190cdf0e10cSrcweir SbxBase::SetError( SbxERR_BAD_PARAMETER ); //! welchen Fehler ?
191cdf0e10cSrcweir break;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir }
194cdf0e10cSrcweir }
195cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_OBJECT );
196cdf0e10cSrcweir }
197cdf0e10cSrcweir break;
198cdf0e10cSrcweir
199cdf0e10cSrcweir case SID_SBA_IMPORT:
200cdf0e10cSrcweir {
201cdf0e10cSrcweir if (pReqArgs)
202cdf0e10cSrcweir {
203cdf0e10cSrcweir const SfxPoolItem* pItem;
204cdf0e10cSrcweir svx::ODataAccessDescriptor aDesc;
205cdf0e10cSrcweir if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir uno::Any aAny = static_cast<const SfxUsrAnyItem*>(pItem)->GetValue();
208cdf0e10cSrcweir uno::Sequence<beans::PropertyValue> aProperties;
209cdf0e10cSrcweir if ( aAny >>= aProperties )
210cdf0e10cSrcweir aDesc.initializeFrom( aProperties );
211cdf0e10cSrcweir }
212cdf0e10cSrcweir
213cdf0e10cSrcweir String sTarget;
214cdf0e10cSrcweir if ( pReqArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) == SFX_ITEM_SET )
215cdf0e10cSrcweir sTarget = ((const SfxStringItem*)pItem)->GetValue();
216cdf0e10cSrcweir
217cdf0e10cSrcweir sal_Bool bIsNewArea = sal_True; // Default sal_True (keine Nachfrage)
218cdf0e10cSrcweir if ( pReqArgs->GetItemState( FN_PARAM_2, sal_True, &pItem ) == SFX_ITEM_SET )
219cdf0e10cSrcweir bIsNewArea = ((const SfxBoolItem*)pItem)->GetValue();
220cdf0e10cSrcweir
221cdf0e10cSrcweir // bei Bedarf neuen Datenbankbereich anlegen
222cdf0e10cSrcweir sal_Bool bMakeArea = sal_False;
223cdf0e10cSrcweir if (bIsNewArea)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir ScDBCollection* pDBColl = aDocument.GetDBCollection();
226cdf0e10cSrcweir sal_uInt16 nDummy;
227cdf0e10cSrcweir if ( !pDBColl || !pDBColl->SearchName( sTarget, nDummy ) )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir ScAddress aPos;
230cdf0e10cSrcweir if ( aPos.Parse( sTarget, &aDocument, aDocument.GetAddressConvention() ) & SCA_VALID )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir bMakeArea = sal_True;
233cdf0e10cSrcweir if (bUndo)
234cdf0e10cSrcweir {
235cdf0e10cSrcweir String aStrImport = ScGlobal::GetRscString( STR_UNDO_IMPORTDATA );
236cdf0e10cSrcweir GetUndoManager()->EnterListAction( aStrImport, aStrImport );
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
239cdf0e10cSrcweir ScDBData* pDBData = GetDBData( ScRange(aPos), SC_DB_IMPORT, SC_DBSEL_KEEP );
240cdf0e10cSrcweir DBG_ASSERT(pDBData, "kann DB-Daten nicht anlegen");
241cdf0e10cSrcweir sTarget = pDBData->GetName();
242cdf0e10cSrcweir }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir
246cdf0e10cSrcweir // nachfragen, bevor alter DB-Bereich ueberschrieben wird
247cdf0e10cSrcweir sal_Bool bDo = sal_True;
248cdf0e10cSrcweir if (!bIsNewArea)
249cdf0e10cSrcweir {
250cdf0e10cSrcweir String aTemplate = ScGlobal::GetRscString( STR_IMPORT_REPLACE );
251cdf0e10cSrcweir String aMessage = aTemplate.GetToken( 0, '#' );
252cdf0e10cSrcweir aMessage += sTarget;
253cdf0e10cSrcweir aMessage += aTemplate.GetToken( 1, '#' );
254cdf0e10cSrcweir
255cdf0e10cSrcweir QueryBox aBox( 0, WinBits(WB_YES_NO | WB_DEF_YES), aMessage );
256cdf0e10cSrcweir bDo = ( aBox.Execute() == RET_YES );
257cdf0e10cSrcweir }
258cdf0e10cSrcweir
259cdf0e10cSrcweir if (bDo)
260cdf0e10cSrcweir {
261cdf0e10cSrcweir ScDBDocFunc(*this).UpdateImport( sTarget, aDesc );
262cdf0e10cSrcweir rReq.Done();
263cdf0e10cSrcweir
264cdf0e10cSrcweir // UpdateImport aktualisiert auch die internen Operationen
265cdf0e10cSrcweir }
266cdf0e10cSrcweir else
267cdf0e10cSrcweir rReq.Ignore();
268cdf0e10cSrcweir
269cdf0e10cSrcweir if ( bMakeArea && bUndo)
270cdf0e10cSrcweir GetUndoManager()->LeaveListAction();
271cdf0e10cSrcweir }
272cdf0e10cSrcweir else
273cdf0e10cSrcweir {
274cdf0e10cSrcweir DBG_ERROR( "arguments expected" );
275cdf0e10cSrcweir }
276cdf0e10cSrcweir }
277cdf0e10cSrcweir break;
278cdf0e10cSrcweir
279cdf0e10cSrcweir case SID_CHART_SOURCE:
280cdf0e10cSrcweir case SID_CHART_ADDSOURCE:
281cdf0e10cSrcweir if (pReqArgs)
282cdf0e10cSrcweir {
283cdf0e10cSrcweir ScDocument* pDoc = GetDocument();
284cdf0e10cSrcweir // sal_Bool bUndo (pDoc->IsUndoEnabled());
285cdf0e10cSrcweir const SfxPoolItem* pItem;
286cdf0e10cSrcweir String aChartName, aRangeName;
287cdf0e10cSrcweir
288cdf0e10cSrcweir ScRange aSingleRange;
289cdf0e10cSrcweir ScRangeListRef aRangeListRef;
290cdf0e10cSrcweir sal_Bool bMultiRange = sal_False;
291cdf0e10cSrcweir
292cdf0e10cSrcweir sal_Bool bColHeaders = sal_True;
293cdf0e10cSrcweir sal_Bool bRowHeaders = sal_True;
294cdf0e10cSrcweir sal_Bool bColInit = sal_False;
295cdf0e10cSrcweir sal_Bool bRowInit = sal_False;
296cdf0e10cSrcweir sal_Bool bAddRange = (nSlot == SID_CHART_ADDSOURCE);
297cdf0e10cSrcweir
298cdf0e10cSrcweir if( IS_AVAILABLE( SID_CHART_NAME, &pItem ) )
299cdf0e10cSrcweir aChartName = ((const SfxStringItem*)pItem)->GetValue();
300cdf0e10cSrcweir
301cdf0e10cSrcweir if( IS_AVAILABLE( SID_CHART_SOURCE, &pItem ) )
302cdf0e10cSrcweir aRangeName = ((const SfxStringItem*)pItem)->GetValue();
303cdf0e10cSrcweir
304cdf0e10cSrcweir if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir bColHeaders = ((const SfxBoolItem*)pItem)->GetValue();
307cdf0e10cSrcweir bColInit = sal_True;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir if( IS_AVAILABLE( FN_PARAM_2, &pItem ) )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir bRowHeaders = ((const SfxBoolItem*)pItem)->GetValue();
312cdf0e10cSrcweir bRowInit = sal_True;
313cdf0e10cSrcweir }
314cdf0e10cSrcweir
315cdf0e10cSrcweir ScAddress::Details aDetails(pDoc->GetAddressConvention(), 0, 0);
316cdf0e10cSrcweir sal_Bool bValid = ( aSingleRange.ParseAny( aRangeName, pDoc, aDetails ) & SCA_VALID ) != 0;
317cdf0e10cSrcweir if (!bValid)
318cdf0e10cSrcweir {
319cdf0e10cSrcweir aRangeListRef = new ScRangeList;
320cdf0e10cSrcweir aRangeListRef->Parse( aRangeName, pDoc );
321cdf0e10cSrcweir if ( aRangeListRef->Count() )
322cdf0e10cSrcweir {
323cdf0e10cSrcweir bMultiRange = sal_True;
324cdf0e10cSrcweir aSingleRange = *aRangeListRef->GetObject(0); // fuer Header
325cdf0e10cSrcweir bValid = sal_True;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir else
328cdf0e10cSrcweir aRangeListRef.Clear();
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
331cdf0e10cSrcweir ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
332cdf0e10cSrcweir if (pViewSh && bValid && aChartName.Len() != 0 )
333cdf0e10cSrcweir {
334cdf0e10cSrcweir Window* pParent = pViewSh->GetDialogParent();
335cdf0e10cSrcweir
336cdf0e10cSrcweir SCCOL nCol1 = aSingleRange.aStart.Col();
337cdf0e10cSrcweir SCROW nRow1 = aSingleRange.aStart.Row();
338cdf0e10cSrcweir SCCOL nCol2 = aSingleRange.aEnd.Col();
339cdf0e10cSrcweir SCROW nRow2 = aSingleRange.aEnd.Row();
340cdf0e10cSrcweir SCTAB nTab = aSingleRange.aStart.Tab();
341cdf0e10cSrcweir
342cdf0e10cSrcweir //! immer oder gar nicht begrenzen ???
343cdf0e10cSrcweir if (!bMultiRange)
344cdf0e10cSrcweir aDocument.LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 );
345cdf0e10cSrcweir
346cdf0e10cSrcweir // Dialog fuer Spalten/Zeilenkoepfe
347cdf0e10cSrcweir sal_Bool bOk = sal_True;
348cdf0e10cSrcweir if ( !bAddRange && ( !bColInit || !bRowInit ) )
349cdf0e10cSrcweir {
350cdf0e10cSrcweir ScChartPositioner aChartPositioner( &aDocument, nTab, nCol1,nRow1, nCol2,nRow2 );
351cdf0e10cSrcweir if (!bColInit)
352cdf0e10cSrcweir bColHeaders = aChartPositioner.HasColHeaders();
353cdf0e10cSrcweir if (!bRowInit)
354cdf0e10cSrcweir bRowHeaders = aChartPositioner.HasRowHeaders();
355cdf0e10cSrcweir
356cdf0e10cSrcweir //CHINA001 ScColRowLabelDlg aDlg( pParent, bRowHeaders, bColHeaders );
357cdf0e10cSrcweir ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
358cdf0e10cSrcweir DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
359cdf0e10cSrcweir
360cdf0e10cSrcweir AbstractScColRowLabelDlg* pDlg = pFact->CreateScColRowLabelDlg( pParent, RID_SCDLG_CHARTCOLROW, bRowHeaders, bColHeaders);
361cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
362cdf0e10cSrcweir if ( pDlg->Execute() == RET_OK ) //CHINA001 if ( aDlg.Execute() == RET_OK )
363cdf0e10cSrcweir {
364cdf0e10cSrcweir bColHeaders = pDlg->IsRow(); //CHINA001 bColHeaders = aDlg.IsRow(); // Spaltenkoepfe = 1. Zeile
365cdf0e10cSrcweir bRowHeaders = pDlg->IsCol(); //CHINA001 bRowHeaders = aDlg.IsCol();
366cdf0e10cSrcweir
367cdf0e10cSrcweir rReq.AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders));
368cdf0e10cSrcweir rReq.AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders));
369cdf0e10cSrcweir }
370cdf0e10cSrcweir else
371cdf0e10cSrcweir bOk = sal_False;
372cdf0e10cSrcweir delete pDlg; //CHINA001
373cdf0e10cSrcweir }
374cdf0e10cSrcweir
375cdf0e10cSrcweir if (bOk) // ausfuehren
376cdf0e10cSrcweir {
377cdf0e10cSrcweir if (bMultiRange)
378cdf0e10cSrcweir {
379cdf0e10cSrcweir if (bUndo)
380cdf0e10cSrcweir {
381cdf0e10cSrcweir GetUndoManager()->AddUndoAction(
382cdf0e10cSrcweir new ScUndoChartData( this, aChartName, aRangeListRef,
383cdf0e10cSrcweir bColHeaders, bRowHeaders, bAddRange ) );
384cdf0e10cSrcweir }
385cdf0e10cSrcweir aDocument.UpdateChartArea( aChartName, aRangeListRef,
386cdf0e10cSrcweir bColHeaders, bRowHeaders, bAddRange );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir else
389cdf0e10cSrcweir {
390cdf0e10cSrcweir ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
391cdf0e10cSrcweir if (bUndo)
392cdf0e10cSrcweir {
393cdf0e10cSrcweir GetUndoManager()->AddUndoAction(
394cdf0e10cSrcweir new ScUndoChartData( this, aChartName, aNewRange,
395cdf0e10cSrcweir bColHeaders, bRowHeaders, bAddRange ) );
396cdf0e10cSrcweir }
397cdf0e10cSrcweir aDocument.UpdateChartArea( aChartName, aNewRange,
398cdf0e10cSrcweir bColHeaders, bRowHeaders, bAddRange );
399cdf0e10cSrcweir }
400cdf0e10cSrcweir }
401cdf0e10cSrcweir }
402cdf0e10cSrcweir else
403cdf0e10cSrcweir {
404cdf0e10cSrcweir DBG_ERROR("UpdateChartArea: keine ViewShell oder falsche Daten");
405cdf0e10cSrcweir }
406cdf0e10cSrcweir rReq.Done();
407cdf0e10cSrcweir }
408cdf0e10cSrcweir else
409cdf0e10cSrcweir {
410cdf0e10cSrcweir DBG_ERROR("SID_CHART_SOURCE ohne Argumente");
411cdf0e10cSrcweir }
412cdf0e10cSrcweir break;
413cdf0e10cSrcweir
414cdf0e10cSrcweir case FID_AUTO_CALC:
415cdf0e10cSrcweir {
416cdf0e10cSrcweir sal_Bool bNewVal;
417cdf0e10cSrcweir const SfxPoolItem* pItem;
418cdf0e10cSrcweir if ( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( nSlot, sal_True, &pItem ) )
419cdf0e10cSrcweir bNewVal = ((const SfxBoolItem*)pItem)->GetValue();
420cdf0e10cSrcweir else
421cdf0e10cSrcweir bNewVal = !aDocument.GetAutoCalc(); // Toggle fuer Menue
422cdf0e10cSrcweir aDocument.SetAutoCalc( bNewVal );
423cdf0e10cSrcweir SetDocumentModified();
424cdf0e10cSrcweir if (pBindings)
425cdf0e10cSrcweir {
426cdf0e10cSrcweir pBindings->Invalidate( FID_AUTO_CALC );
427cdf0e10cSrcweir // pBindings->Invalidate( FID_RECALC ); // jetzt immer enabled
428cdf0e10cSrcweir }
429cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( FID_AUTO_CALC, bNewVal ) );
430cdf0e10cSrcweir rReq.Done();
431cdf0e10cSrcweir }
432cdf0e10cSrcweir break;
433cdf0e10cSrcweir case FID_RECALC:
434cdf0e10cSrcweir DoRecalc( rReq.IsAPI() );
435cdf0e10cSrcweir rReq.Done();
436cdf0e10cSrcweir break;
437cdf0e10cSrcweir case FID_HARD_RECALC:
438cdf0e10cSrcweir DoHardRecalc( rReq.IsAPI() );
439cdf0e10cSrcweir rReq.Done();
440cdf0e10cSrcweir break;
441cdf0e10cSrcweir case SID_UPDATETABLINKS:
442cdf0e10cSrcweir {
443cdf0e10cSrcweir ScDocument* pDoc = GetDocument();
444cdf0e10cSrcweir
445cdf0e10cSrcweir ScLkUpdMode nSet=pDoc->GetLinkMode();
446cdf0e10cSrcweir
447cdf0e10cSrcweir sal_uInt16 nDlgRet=RET_NO;
448cdf0e10cSrcweir if(nSet==LM_UNKNOWN)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir ScAppOptions aAppOptions=SC_MOD()->GetAppOptions();
451cdf0e10cSrcweir nSet=aAppOptions.GetLinkMode();
452cdf0e10cSrcweir }
453cdf0e10cSrcweir
454cdf0e10cSrcweir if (nCanUpdate == com::sun::star::document::UpdateDocMode::NO_UPDATE)
455cdf0e10cSrcweir nSet = LM_NEVER;
456cdf0e10cSrcweir else if (nCanUpdate == com::sun::star::document::UpdateDocMode::FULL_UPDATE)
457cdf0e10cSrcweir nSet = LM_ALWAYS;
458cdf0e10cSrcweir
459*65fffafdSAndrea Pescetti if (nSet == LM_ALWAYS && !(SvtSecurityOptions().GetMacroSecurityLevel() == 0))
460*65fffafdSAndrea Pescetti nSet = LM_ON_DEMAND;
461*65fffafdSAndrea Pescetti if (nCanUpdate == com::sun::star::document::UpdateDocMode::QUIET_UPDATE &&
462*65fffafdSAndrea Pescetti nSet == LM_ON_DEMAND)
463*65fffafdSAndrea Pescetti nSet = LM_NEVER;
464*65fffafdSAndrea Pescetti
465cdf0e10cSrcweir if(nSet==LM_ON_DEMAND)
466cdf0e10cSrcweir {
467cdf0e10cSrcweir QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
468cdf0e10cSrcweir ScGlobal::GetRscString(STR_RELOAD_TABLES) );
469cdf0e10cSrcweir
470cdf0e10cSrcweir nDlgRet=aBox.Execute();
471cdf0e10cSrcweir }
472cdf0e10cSrcweir
473cdf0e10cSrcweir if (nDlgRet == RET_YES || nSet==LM_ALWAYS)
474cdf0e10cSrcweir {
475cdf0e10cSrcweir ReloadTabLinks();
476cdf0e10cSrcweir aDocument.UpdateExternalRefLinks();
477cdf0e10cSrcweir aDocument.UpdateDdeLinks();
478cdf0e10cSrcweir aDocument.UpdateAreaLinks();
479cdf0e10cSrcweir
480cdf0e10cSrcweir //! Test, ob Fehler
481cdf0e10cSrcweir rReq.Done();
482cdf0e10cSrcweir }
483cdf0e10cSrcweir else
484cdf0e10cSrcweir rReq.Ignore();
485cdf0e10cSrcweir }
486cdf0e10cSrcweir break;
487cdf0e10cSrcweir
488cdf0e10cSrcweir case SID_REIMPORT_AFTER_LOAD:
489cdf0e10cSrcweir {
490cdf0e10cSrcweir // wird nach dem Laden aufgerufen, wenn DB-Bereiche mit
491cdf0e10cSrcweir // weggelassenen Daten enthalten sind
492cdf0e10cSrcweir
493cdf0e10cSrcweir sal_Bool bDone = sal_False;
494cdf0e10cSrcweir ScDBCollection* pDBColl = aDocument.GetDBCollection();
495cdf0e10cSrcweir
496cdf0e10cSrcweir if ((nCanUpdate != com::sun::star::document::UpdateDocMode::NO_UPDATE) &&
497cdf0e10cSrcweir (nCanUpdate != com::sun::star::document::UpdateDocMode::QUIET_UPDATE))
498cdf0e10cSrcweir {
499cdf0e10cSrcweir ScRange aRange;
500cdf0e10cSrcweir ScTabViewShell* pViewSh = GetBestViewShell();
501cdf0e10cSrcweir DBG_ASSERT(pViewSh,"SID_REIMPORT_AFTER_LOAD: keine View");
502cdf0e10cSrcweir if (pViewSh && pDBColl)
503cdf0e10cSrcweir {
504cdf0e10cSrcweir QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
505cdf0e10cSrcweir ScGlobal::GetRscString(STR_REIMPORT_AFTER_LOAD) );
506cdf0e10cSrcweir if (aBox.Execute() == RET_YES)
507cdf0e10cSrcweir {
508cdf0e10cSrcweir for (sal_uInt16 i=0; i<pDBColl->GetCount(); i++)
509cdf0e10cSrcweir {
510cdf0e10cSrcweir ScDBData* pDBData = (*pDBColl)[i];
511cdf0e10cSrcweir if ( pDBData->IsStripData() &&
512cdf0e10cSrcweir pDBData->HasImportParam() && !pDBData->HasImportSelection() )
513cdf0e10cSrcweir {
514cdf0e10cSrcweir pDBData->GetArea(aRange);
515cdf0e10cSrcweir pViewSh->MarkRange(aRange);
516cdf0e10cSrcweir
517cdf0e10cSrcweir // Import und interne Operationen wie SID_REFRESH_DBAREA
518cdf0e10cSrcweir // (Abfrage auf Import hier nicht noetig)
519cdf0e10cSrcweir
520cdf0e10cSrcweir ScImportParam aImportParam;
521cdf0e10cSrcweir pDBData->GetImportParam( aImportParam );
522cdf0e10cSrcweir sal_Bool bContinue = pViewSh->ImportData( aImportParam );
523cdf0e10cSrcweir pDBData->SetImportParam( aImportParam );
524cdf0e10cSrcweir
525cdf0e10cSrcweir // markieren (Groesse kann sich geaendert haben)
526cdf0e10cSrcweir pDBData->GetArea(aRange);
527cdf0e10cSrcweir pViewSh->MarkRange(aRange);
528cdf0e10cSrcweir
529cdf0e10cSrcweir if ( bContinue ) // #41905# Fehler beim Import -> Abbruch
530cdf0e10cSrcweir {
531cdf0e10cSrcweir // interne Operationen, wenn welche gespeichert
532cdf0e10cSrcweir
533cdf0e10cSrcweir if ( pDBData->HasQueryParam() || pDBData->HasSortParam() ||
534cdf0e10cSrcweir pDBData->HasSubTotalParam() )
535cdf0e10cSrcweir pViewSh->RepeatDB();
536cdf0e10cSrcweir
537cdf0e10cSrcweir // Pivottabellen die den Bereich als Quelldaten haben
538cdf0e10cSrcweir
539cdf0e10cSrcweir RefreshPivotTables(aRange);
540cdf0e10cSrcweir }
541cdf0e10cSrcweir }
542cdf0e10cSrcweir }
543cdf0e10cSrcweir bDone = sal_True;
544cdf0e10cSrcweir }
545cdf0e10cSrcweir }
546cdf0e10cSrcweir }
547cdf0e10cSrcweir
548cdf0e10cSrcweir if ( !bDone && pDBColl )
549cdf0e10cSrcweir {
550cdf0e10cSrcweir // wenn nicht, dann aber die abhaengigen Formeln updaten
551cdf0e10cSrcweir //! auch fuer einzelne Bereiche, die nicht aktualisiert werden koennen
552cdf0e10cSrcweir
553cdf0e10cSrcweir aDocument.CalcAll(); //! nur die abhaengigen
554cdf0e10cSrcweir PostDataChanged();
555cdf0e10cSrcweir }
556cdf0e10cSrcweir
557cdf0e10cSrcweir if (bDone)
558cdf0e10cSrcweir rReq.Done();
559cdf0e10cSrcweir else
560cdf0e10cSrcweir rReq.Ignore();
561cdf0e10cSrcweir }
562cdf0e10cSrcweir break;
563cdf0e10cSrcweir
564cdf0e10cSrcweir
565cdf0e10cSrcweir case SID_AUTO_STYLE:
566cdf0e10cSrcweir DBG_ERROR("use ScAutoStyleHint instead of SID_AUTO_STYLE");
567cdf0e10cSrcweir break;
568cdf0e10cSrcweir
569cdf0e10cSrcweir case SID_GET_COLORTABLE:
570cdf0e10cSrcweir {
571cdf0e10cSrcweir // passende ColorTable ist per PutItem gesetzt worden
572c7be74b1SArmin Le Grand const SvxColorTableItem* pColItem = static_cast< const SvxColorTableItem* >(GetItem(SID_COLOR_TABLE));
573c7be74b1SArmin Le Grand XColorListSharedPtr aTable = pColItem->GetColorTable();
574c7be74b1SArmin Le Grand
575c7be74b1SArmin Le Grand rReq.SetReturnValue(SvxColorTableItem(aTable, SID_GET_COLORTABLE));
576cdf0e10cSrcweir }
577cdf0e10cSrcweir break;
578cdf0e10cSrcweir
579cdf0e10cSrcweir case FID_CHG_RECORD:
580cdf0e10cSrcweir {
581cdf0e10cSrcweir ScDocument* pDoc = GetDocument();
582cdf0e10cSrcweir if(pDoc!=NULL)
583cdf0e10cSrcweir {
584cdf0e10cSrcweir // get argument (recorded macro)
585cdf0e10cSrcweir SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FID_CHG_RECORD, sal_False );
586cdf0e10cSrcweir sal_Bool bDo = sal_True;
587cdf0e10cSrcweir
588cdf0e10cSrcweir // xmlsec05/06:
589cdf0e10cSrcweir // getting real parent window when called from Security-Options TP
590cdf0e10cSrcweir Window* pParent = NULL;
591cdf0e10cSrcweir const SfxPoolItem* pParentItem;
592cdf0e10cSrcweir if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_XWINDOW, sal_False, &pParentItem ) )
593cdf0e10cSrcweir pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr();
594cdf0e10cSrcweir
595cdf0e10cSrcweir // desired state
596cdf0e10cSrcweir ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
597cdf0e10cSrcweir sal_Bool bActivateTracking = (pChangeTrack == 0); // toggle
598cdf0e10cSrcweir if ( pItem )
599cdf0e10cSrcweir bActivateTracking = pItem->GetValue(); // from argument
600cdf0e10cSrcweir
601cdf0e10cSrcweir if ( !bActivateTracking )
602cdf0e10cSrcweir {
603cdf0e10cSrcweir if ( !pItem )
604cdf0e10cSrcweir {
605cdf0e10cSrcweir // no dialog on playing the macro
606cdf0e10cSrcweir WarningBox aBox( pParent ? pParent : GetActiveDialogParent(),
607cdf0e10cSrcweir WinBits(WB_YES_NO | WB_DEF_NO),
608cdf0e10cSrcweir ScGlobal::GetRscString( STR_END_REDLINING ) );
609cdf0e10cSrcweir bDo = ( aBox.Execute() == RET_YES );
610cdf0e10cSrcweir }
611cdf0e10cSrcweir
612cdf0e10cSrcweir if ( bDo )
613cdf0e10cSrcweir {
614cdf0e10cSrcweir if ( pChangeTrack->IsProtected() )
615cdf0e10cSrcweir bDo = ExecuteChangeProtectionDialog( NULL );
616cdf0e10cSrcweir if ( bDo )
617cdf0e10cSrcweir {
618cdf0e10cSrcweir pDoc->EndChangeTracking();
619cdf0e10cSrcweir PostPaintGridAll();
620cdf0e10cSrcweir }
621cdf0e10cSrcweir }
622cdf0e10cSrcweir }
623cdf0e10cSrcweir else
624cdf0e10cSrcweir {
625cdf0e10cSrcweir pDoc->StartChangeTracking();
626cdf0e10cSrcweir ScChangeViewSettings aChangeViewSet;
627cdf0e10cSrcweir aChangeViewSet.SetShowChanges(sal_True);
628cdf0e10cSrcweir pDoc->SetChangeViewSettings(aChangeViewSet);
629cdf0e10cSrcweir }
630cdf0e10cSrcweir
631cdf0e10cSrcweir if ( bDo )
632cdf0e10cSrcweir {
633cdf0e10cSrcweir UpdateAcceptChangesDialog();
634cdf0e10cSrcweir
635cdf0e10cSrcweir // Slots invalidieren
636cdf0e10cSrcweir if (pBindings)
637cdf0e10cSrcweir pBindings->InvalidateAll(sal_False);
638cdf0e10cSrcweir if ( !pItem )
639cdf0e10cSrcweir rReq.AppendItem( SfxBoolItem( FID_CHG_RECORD, bActivateTracking ) );
640cdf0e10cSrcweir rReq.Done();
641cdf0e10cSrcweir }
642cdf0e10cSrcweir else
643cdf0e10cSrcweir rReq.Ignore();
644cdf0e10cSrcweir }
645cdf0e10cSrcweir }
646cdf0e10cSrcweir break;
647cdf0e10cSrcweir
648cdf0e10cSrcweir case SID_CHG_PROTECT :
649cdf0e10cSrcweir {
650cdf0e10cSrcweir Window* pParent = NULL;
651cdf0e10cSrcweir const SfxPoolItem* pParentItem;
652cdf0e10cSrcweir if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_XWINDOW, sal_False, &pParentItem ) )
653cdf0e10cSrcweir pParent = ( ( const XWindowItem* ) pParentItem )->GetWindowPtr();
654cdf0e10cSrcweir if ( ExecuteChangeProtectionDialog( pParent ) )
655cdf0e10cSrcweir {
656cdf0e10cSrcweir rReq.Done();
657cdf0e10cSrcweir SetDocumentModified();
658cdf0e10cSrcweir }
659cdf0e10cSrcweir else
660cdf0e10cSrcweir rReq.Ignore();
661cdf0e10cSrcweir }
662cdf0e10cSrcweir break;
663cdf0e10cSrcweir
664cdf0e10cSrcweir case SID_DOCUMENT_MERGE:
665cdf0e10cSrcweir case SID_DOCUMENT_COMPARE:
666cdf0e10cSrcweir {
667cdf0e10cSrcweir sal_Bool bDo = sal_True;
668cdf0e10cSrcweir ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
669cdf0e10cSrcweir if ( pChangeTrack && !pImpl->bIgnoreLostRedliningWarning )
670cdf0e10cSrcweir {
671cdf0e10cSrcweir if ( nSlot == SID_DOCUMENT_COMPARE )
672cdf0e10cSrcweir { //! old changes trace will be lost
673cdf0e10cSrcweir WarningBox aBox( GetActiveDialogParent(),
674cdf0e10cSrcweir WinBits(WB_YES_NO | WB_DEF_NO),
675cdf0e10cSrcweir ScGlobal::GetRscString( STR_END_REDLINING ) );
676cdf0e10cSrcweir if( aBox.Execute() == RET_YES )
677cdf0e10cSrcweir bDo = ExecuteChangeProtectionDialog( NULL, sal_True );
678cdf0e10cSrcweir else
679cdf0e10cSrcweir bDo = sal_False;
680cdf0e10cSrcweir }
681cdf0e10cSrcweir else // merge might reject some actions
682cdf0e10cSrcweir bDo = ExecuteChangeProtectionDialog( NULL, sal_True );
683cdf0e10cSrcweir }
684cdf0e10cSrcweir if ( !bDo )
685cdf0e10cSrcweir {
686cdf0e10cSrcweir rReq.Ignore();
687cdf0e10cSrcweir break;
688cdf0e10cSrcweir }
689cdf0e10cSrcweir SfxApplication* pApp = SFX_APP();
690cdf0e10cSrcweir const SfxPoolItem* pItem;
691cdf0e10cSrcweir SfxMedium* pMed = NULL;
692cdf0e10cSrcweir if ( pReqArgs &&
693cdf0e10cSrcweir pReqArgs->GetItemState( SID_FILE_NAME, sal_True, &pItem ) == SFX_ITEM_SET &&
694cdf0e10cSrcweir pItem->ISA(SfxStringItem) )
695cdf0e10cSrcweir {
696cdf0e10cSrcweir String aFileName = ((const SfxStringItem*)pItem)->GetValue();
697cdf0e10cSrcweir
698cdf0e10cSrcweir String aFilterName;
699cdf0e10cSrcweir if ( pReqArgs->GetItemState( SID_FILTER_NAME, sal_True, &pItem ) == SFX_ITEM_SET &&
700cdf0e10cSrcweir pItem->ISA(SfxStringItem) )
701cdf0e10cSrcweir {
702cdf0e10cSrcweir aFilterName = ((const SfxStringItem*)pItem)->GetValue();
703cdf0e10cSrcweir }
704cdf0e10cSrcweir String aOptions;
705cdf0e10cSrcweir if ( pReqArgs->GetItemState( SID_FILE_FILTEROPTIONS, sal_True, &pItem ) == SFX_ITEM_SET &&
706cdf0e10cSrcweir pItem->ISA(SfxStringItem) )
707cdf0e10cSrcweir {
708cdf0e10cSrcweir aOptions = ((const SfxStringItem*)pItem)->GetValue();
709cdf0e10cSrcweir }
710cdf0e10cSrcweir short nVersion = 0;
711cdf0e10cSrcweir if ( pReqArgs->GetItemState( SID_VERSION, sal_True, &pItem ) == SFX_ITEM_SET &&
712cdf0e10cSrcweir pItem->ISA(SfxInt16Item) )
713cdf0e10cSrcweir {
714cdf0e10cSrcweir nVersion = ((const SfxInt16Item*)pItem)->GetValue();
715cdf0e10cSrcweir }
716cdf0e10cSrcweir
717cdf0e10cSrcweir // kein Filter angegeben -> Detection
718cdf0e10cSrcweir if ( !aFilterName.Len() )
719cdf0e10cSrcweir ScDocumentLoader::GetFilterName( aFileName, aFilterName, aOptions, sal_True, sal_False );
720cdf0e10cSrcweir
721cdf0e10cSrcweir // filter name from dialog contains application prefix,
722cdf0e10cSrcweir // GetFilter needs name without the prefix.
723cdf0e10cSrcweir ScDocumentLoader::RemoveAppPrefix( aFilterName );
724cdf0e10cSrcweir
725cdf0e10cSrcweir const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
726cdf0e10cSrcweir SfxItemSet* pSet = new SfxAllItemSet( pApp->GetPool() );
727cdf0e10cSrcweir if ( aOptions.Len() )
728cdf0e10cSrcweir pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
729cdf0e10cSrcweir if ( nVersion != 0 )
730cdf0e10cSrcweir pSet->Put( SfxInt16Item( SID_VERSION, nVersion ) );
731cdf0e10cSrcweir pMed = new SfxMedium( aFileName, STREAM_STD_READ, sal_False, pFilter, pSet );
732cdf0e10cSrcweir }
733cdf0e10cSrcweir else
734cdf0e10cSrcweir {
735cdf0e10cSrcweir // start file dialog asynchronous
736cdf0e10cSrcweir pImpl->bIgnoreLostRedliningWarning = true;
737cdf0e10cSrcweir delete pImpl->pRequest;
738cdf0e10cSrcweir pImpl->pRequest = new SfxRequest( rReq );
739cdf0e10cSrcweir delete pImpl->pDocInserter;
740cdf0e10cSrcweir pImpl->pDocInserter = new ::sfx2::DocumentInserter(
741cdf0e10cSrcweir 0, String::CreateFromAscii( ScDocShell::Factory().GetShortName() ), 0 );
742cdf0e10cSrcweir pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) );
743cdf0e10cSrcweir return ;
744cdf0e10cSrcweir }
745cdf0e10cSrcweir
746cdf0e10cSrcweir if ( pMed ) // nun wirklich ausfuehren...
747cdf0e10cSrcweir {
748cdf0e10cSrcweir SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() );
749cdf0e10cSrcweir
750cdf0e10cSrcweir // pOtherDocSh->DoClose() will be called explicitly later, but it is still more safe to use SfxObjectShellLock here
751cdf0e10cSrcweir ScDocShell* pOtherDocSh = new ScDocShell;
752cdf0e10cSrcweir SfxObjectShellLock aDocShTablesRef = pOtherDocSh;
753cdf0e10cSrcweir pOtherDocSh->DoLoad( pMed );
754cdf0e10cSrcweir sal_uLong nErr = pOtherDocSh->GetErrorCode();
755cdf0e10cSrcweir if (nErr)
756cdf0e10cSrcweir ErrorHandler::HandleError( nErr ); // auch Warnings
757cdf0e10cSrcweir
758cdf0e10cSrcweir if ( !pOtherDocSh->GetError() ) // nur Errors
759cdf0e10cSrcweir {
760cdf0e10cSrcweir sal_Bool bHadTrack = ( aDocument.GetChangeTrack() != NULL );
761cdf0e10cSrcweir sal_uLong nStart = 0;
762cdf0e10cSrcweir if ( nSlot == SID_DOCUMENT_MERGE && pChangeTrack )
763cdf0e10cSrcweir {
764cdf0e10cSrcweir nStart = pChangeTrack->GetActionMax() + 1;
765cdf0e10cSrcweir }
766cdf0e10cSrcweir
767cdf0e10cSrcweir if ( nSlot == SID_DOCUMENT_COMPARE )
768cdf0e10cSrcweir CompareDocument( *pOtherDocSh->GetDocument() );
769cdf0e10cSrcweir else
770cdf0e10cSrcweir MergeDocument( *pOtherDocSh->GetDocument() );
771cdf0e10cSrcweir
772cdf0e10cSrcweir // show "accept changes" dialog
773cdf0e10cSrcweir //! get view for this document!
774cdf0e10cSrcweir if ( !IsDocShared() )
775cdf0e10cSrcweir {
776cdf0e10cSrcweir SfxViewFrame* pViewFrm = SfxViewFrame::Current();
777cdf0e10cSrcweir if ( pViewFrm )
778cdf0e10cSrcweir {
779cdf0e10cSrcweir pViewFrm->ShowChildWindow( ScAcceptChgDlgWrapper::GetChildWindowId(), sal_True ); //@51669
780cdf0e10cSrcweir }
781cdf0e10cSrcweir if ( pBindings )
782cdf0e10cSrcweir {
783cdf0e10cSrcweir pBindings->Invalidate( FID_CHG_ACCEPT );
784cdf0e10cSrcweir }
785cdf0e10cSrcweir }
786cdf0e10cSrcweir
787cdf0e10cSrcweir rReq.SetReturnValue( SfxInt32Item( nSlot, 0 ) ); //! ???????
788cdf0e10cSrcweir rReq.Done();
789cdf0e10cSrcweir
790cdf0e10cSrcweir if (!bHadTrack) // neu eingeschaltet -> auch anzeigen
791cdf0e10cSrcweir {
792cdf0e10cSrcweir ScChangeViewSettings* pOldSet = aDocument.GetChangeViewSettings();
793cdf0e10cSrcweir if ( !pOldSet || !pOldSet->ShowChanges() )
794cdf0e10cSrcweir {
795cdf0e10cSrcweir ScChangeViewSettings aChangeViewSet;
796cdf0e10cSrcweir aChangeViewSet.SetShowChanges(sal_True);
797cdf0e10cSrcweir aDocument.SetChangeViewSettings(aChangeViewSet);
798cdf0e10cSrcweir }
799cdf0e10cSrcweir }
800cdf0e10cSrcweir else if ( nSlot == SID_DOCUMENT_MERGE && IsDocShared() && pChangeTrack )
801cdf0e10cSrcweir {
802cdf0e10cSrcweir sal_uLong nEnd = pChangeTrack->GetActionMax();
803cdf0e10cSrcweir if ( nEnd >= nStart )
804cdf0e10cSrcweir {
805cdf0e10cSrcweir // only show changes from merged document
806cdf0e10cSrcweir ScChangeViewSettings aChangeViewSet;
807cdf0e10cSrcweir aChangeViewSet.SetShowChanges( sal_True );
808cdf0e10cSrcweir aChangeViewSet.SetShowAccepted( sal_True );
809cdf0e10cSrcweir aChangeViewSet.SetHasActionRange( true );
810cdf0e10cSrcweir aChangeViewSet.SetTheActionRange( nStart, nEnd );
811cdf0e10cSrcweir aDocument.SetChangeViewSettings( aChangeViewSet );
812cdf0e10cSrcweir
813cdf0e10cSrcweir // update view
814cdf0e10cSrcweir PostPaintExtras();
815cdf0e10cSrcweir PostPaintGridAll();
816cdf0e10cSrcweir }
817cdf0e10cSrcweir }
818cdf0e10cSrcweir }
819cdf0e10cSrcweir pOtherDocSh->DoClose(); // delete passiert mit der Ref
820cdf0e10cSrcweir }
821cdf0e10cSrcweir }
822cdf0e10cSrcweir break;
823cdf0e10cSrcweir
824cdf0e10cSrcweir case SID_DELETE_SCENARIO:
825cdf0e10cSrcweir if (pReqArgs)
826cdf0e10cSrcweir {
827cdf0e10cSrcweir const SfxPoolItem* pItem;
828cdf0e10cSrcweir if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
829cdf0e10cSrcweir {
830cdf0e10cSrcweir if ( pItem->ISA(SfxStringItem) )
831cdf0e10cSrcweir {
832cdf0e10cSrcweir String aName = ((const SfxStringItem*)pItem)->GetValue();
833cdf0e10cSrcweir SCTAB nTab;
834cdf0e10cSrcweir if (aDocument.GetTable( aName, nTab ))
835cdf0e10cSrcweir {
836cdf0e10cSrcweir // DeleteTable von viewfunc nach docfunc verschieben!
837cdf0e10cSrcweir
838cdf0e10cSrcweir ScTabViewShell* pSh = GetBestViewShell();
839cdf0e10cSrcweir if ( pSh )
840cdf0e10cSrcweir {
841cdf0e10cSrcweir //! SetTabNo in DeleteTable weglassen?
842cdf0e10cSrcweir SCTAB nDispTab = pSh->GetViewData()->GetTabNo();
843cdf0e10cSrcweir pSh->DeleteTable( nTab );
844cdf0e10cSrcweir pSh->SetTabNo(nDispTab);
845cdf0e10cSrcweir rReq.Done();
846cdf0e10cSrcweir }
847cdf0e10cSrcweir }
848cdf0e10cSrcweir }
849cdf0e10cSrcweir }
850cdf0e10cSrcweir }
851cdf0e10cSrcweir break;
852cdf0e10cSrcweir
853cdf0e10cSrcweir case SID_EDIT_SCENARIO:
854cdf0e10cSrcweir {
855cdf0e10cSrcweir const SfxPoolItem* pItem;
856cdf0e10cSrcweir if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
857cdf0e10cSrcweir {
858cdf0e10cSrcweir if ( pItem->ISA(SfxStringItem) )
859cdf0e10cSrcweir {
860cdf0e10cSrcweir String aName = ((const SfxStringItem*)pItem)->GetValue();
861cdf0e10cSrcweir SCTAB nTab;
862cdf0e10cSrcweir if (aDocument.GetTable( aName, nTab ))
863cdf0e10cSrcweir {
864cdf0e10cSrcweir if (aDocument.IsScenario(nTab))
865cdf0e10cSrcweir {
866cdf0e10cSrcweir String aComment;
867cdf0e10cSrcweir Color aColor;
868cdf0e10cSrcweir sal_uInt16 nFlags;
869cdf0e10cSrcweir aDocument.GetScenarioData( nTab, aComment, aColor, nFlags );
870cdf0e10cSrcweir
871cdf0e10cSrcweir // Determine if the Sheet that the Scenario was created on
872cdf0e10cSrcweir // is protected. But first we need to find that Sheet.
873cdf0e10cSrcweir // Rewind back to the actual sheet.
874cdf0e10cSrcweir SCTAB nActualTab = nTab;
875cdf0e10cSrcweir do
876cdf0e10cSrcweir {
877cdf0e10cSrcweir nActualTab--;
878cdf0e10cSrcweir }
879cdf0e10cSrcweir while(aDocument.IsScenario(nActualTab));
880cdf0e10cSrcweir sal_Bool bSheetProtected = aDocument.IsTabProtected(nActualTab);
881cdf0e10cSrcweir
882cdf0e10cSrcweir //! anderen Titel am Dialog setzen
883cdf0e10cSrcweir //CHINA001 ScNewScenarioDlg* pNewDlg =
884cdf0e10cSrcweir //CHINA001 new ScNewScenarioDlg( GetActiveDialogParent(), aName, sal_True, bSheetProtected);
885cdf0e10cSrcweir ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
886cdf0e10cSrcweir DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
887cdf0e10cSrcweir
888cdf0e10cSrcweir AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg( GetActiveDialogParent(), aName, RID_SCDLG_NEWSCENARIO, sal_True,bSheetProtected);
889cdf0e10cSrcweir DBG_ASSERT(pNewDlg, "Dialog create fail!");//CHINA001
890cdf0e10cSrcweir pNewDlg->SetScenarioData( aName, aComment, aColor, nFlags );
891cdf0e10cSrcweir if ( pNewDlg->Execute() == RET_OK )
892cdf0e10cSrcweir {
893cdf0e10cSrcweir pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
894cdf0e10cSrcweir ModifyScenario( nTab, aName, aComment, aColor, nFlags );
895cdf0e10cSrcweir rReq.Done();
896cdf0e10cSrcweir }
897cdf0e10cSrcweir delete pNewDlg;
898cdf0e10cSrcweir }
899cdf0e10cSrcweir }
900cdf0e10cSrcweir }
901cdf0e10cSrcweir }
902cdf0e10cSrcweir }
903cdf0e10cSrcweir break;
904cdf0e10cSrcweir
905cdf0e10cSrcweir case SID_ATTR_YEAR2000 :
906cdf0e10cSrcweir {
907cdf0e10cSrcweir const SfxPoolItem* pItem;
908cdf0e10cSrcweir if ( pReqArgs->GetItemState( nSlot, sal_True, &pItem ) == SFX_ITEM_SET )
909cdf0e10cSrcweir {
910cdf0e10cSrcweir if ( pItem->ISA(SfxUInt16Item) )
911cdf0e10cSrcweir {
912cdf0e10cSrcweir sal_uInt16 nY2k = ((SfxUInt16Item*)pItem)->GetValue();
913cdf0e10cSrcweir // immer an den DocOptions setzen, damit das auch fuer SO50
914cdf0e10cSrcweir // gespeichert wird (und alle Abfragen bisher auch darauf laufen).
915cdf0e10cSrcweir // SetDocOptions propagiert das an den NumberFormatter
916cdf0e10cSrcweir ScDocOptions aDocOpt( aDocument.GetDocOptions() );
917cdf0e10cSrcweir aDocOpt.SetYear2000( nY2k );
918cdf0e10cSrcweir aDocument.SetDocOptions( aDocOpt );
919cdf0e10cSrcweir // die FormShell soll es mitbekommen
920cdf0e10cSrcweir ScTabViewShell* pSh = GetBestViewShell();
921cdf0e10cSrcweir if ( pSh )
922cdf0e10cSrcweir {
923cdf0e10cSrcweir FmFormShell* pFSh = pSh->GetFormShell();
924cdf0e10cSrcweir if ( pFSh )
925cdf0e10cSrcweir pFSh->SetY2KState( nY2k );
926cdf0e10cSrcweir }
927cdf0e10cSrcweir }
928cdf0e10cSrcweir }
929cdf0e10cSrcweir }
930cdf0e10cSrcweir break;
931cdf0e10cSrcweir
932cdf0e10cSrcweir case SID_SHARE_DOC:
933cdf0e10cSrcweir {
934cdf0e10cSrcweir ScViewData* pViewData = GetViewData();
935cdf0e10cSrcweir if ( !pViewData )
936cdf0e10cSrcweir {
937cdf0e10cSrcweir rReq.Ignore();
938cdf0e10cSrcweir break;
939cdf0e10cSrcweir }
940cdf0e10cSrcweir
941cdf0e10cSrcweir ScShareDocumentDlg aDlg( GetActiveDialogParent(), pViewData );
942cdf0e10cSrcweir if ( aDlg.Execute() == RET_OK )
943cdf0e10cSrcweir {
944cdf0e10cSrcweir bool bSetShared = aDlg.IsShareDocumentChecked();
945cdf0e10cSrcweir if ( bSetShared != static_cast< bool >( IsDocShared() ) )
946cdf0e10cSrcweir {
947cdf0e10cSrcweir if ( bSetShared )
948cdf0e10cSrcweir {
949cdf0e10cSrcweir bool bContinue = true;
950cdf0e10cSrcweir if ( HasName() )
951cdf0e10cSrcweir {
952cdf0e10cSrcweir QueryBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
953cdf0e10cSrcweir ScGlobal::GetRscString( STR_DOC_WILLBESAVED ) );
954cdf0e10cSrcweir if ( aBox.Execute() == RET_NO )
955cdf0e10cSrcweir {
956cdf0e10cSrcweir bContinue = false;
957cdf0e10cSrcweir }
958cdf0e10cSrcweir }
959cdf0e10cSrcweir if ( bContinue )
960cdf0e10cSrcweir {
961cdf0e10cSrcweir EnableSharedSettings( true );
962cdf0e10cSrcweir
963cdf0e10cSrcweir SC_MOD()->SetInSharedDocSaving( true );
964cdf0e10cSrcweir if ( !SwitchToShared( sal_True, sal_True ) )
965cdf0e10cSrcweir {
966cdf0e10cSrcweir // TODO/LATER: what should be done in case the switch has failed?
967cdf0e10cSrcweir // for example in case the user has cancelled the saveAs operation
968cdf0e10cSrcweir }
969cdf0e10cSrcweir
970cdf0e10cSrcweir SC_MOD()->SetInSharedDocSaving( false );
971cdf0e10cSrcweir
972cdf0e10cSrcweir InvalidateName();
973cdf0e10cSrcweir GetUndoManager()->Clear();
974cdf0e10cSrcweir
975cdf0e10cSrcweir ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
976cdf0e10cSrcweir if ( pTabView )
977cdf0e10cSrcweir {
978cdf0e10cSrcweir pTabView->UpdateLayerLocks();
979cdf0e10cSrcweir }
980cdf0e10cSrcweir }
981cdf0e10cSrcweir }
982cdf0e10cSrcweir else
983cdf0e10cSrcweir {
984cdf0e10cSrcweir uno::Reference< frame::XModel > xModel;
985cdf0e10cSrcweir try
986cdf0e10cSrcweir {
987cdf0e10cSrcweir // load shared file
988cdf0e10cSrcweir xModel.set( LoadSharedDocument(), uno::UNO_QUERY_THROW );
989cdf0e10cSrcweir uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW );
990cdf0e10cSrcweir
991cdf0e10cSrcweir // check if shared flag is set in shared file
992cdf0e10cSrcweir bool bShared = false;
993cdf0e10cSrcweir ScModelObj* pDocObj = ScModelObj::getImplementation( xModel );
994cdf0e10cSrcweir if ( pDocObj )
995cdf0e10cSrcweir {
996cdf0e10cSrcweir ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pDocObj->GetEmbeddedObject() );
997cdf0e10cSrcweir if ( pDocShell )
998cdf0e10cSrcweir {
999cdf0e10cSrcweir bShared = pDocShell->HasSharedXMLFlagSet();
1000cdf0e10cSrcweir }
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir
1003cdf0e10cSrcweir // #i87870# check if shared status was disabled and enabled again
1004cdf0e10cSrcweir bool bOwnEntry = false;
1005cdf0e10cSrcweir try
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
1008cdf0e10cSrcweir bOwnEntry = aControlFile.HasOwnEntry();
1009cdf0e10cSrcweir }
1010cdf0e10cSrcweir catch ( uno::Exception& )
1011cdf0e10cSrcweir {
1012cdf0e10cSrcweir }
1013cdf0e10cSrcweir
1014cdf0e10cSrcweir if ( bShared && bOwnEntry )
1015cdf0e10cSrcweir {
1016cdf0e10cSrcweir uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW );
1017cdf0e10cSrcweir if ( xStorable->isReadonly() )
1018cdf0e10cSrcweir {
1019cdf0e10cSrcweir xCloseable->close( sal_True );
1020cdf0e10cSrcweir
1021cdf0e10cSrcweir String aUserName( ScGlobal::GetRscString( STR_UNKNOWN_USER ) );
1022cdf0e10cSrcweir try
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
1025cdf0e10cSrcweir uno::Sequence< ::rtl::OUString > aData = aLockFile.GetLockData();
1026cdf0e10cSrcweir if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
1027cdf0e10cSrcweir {
1028cdf0e10cSrcweir if ( aData[LOCKFILE_OOOUSERNAME_ID].getLength() > 0 )
1029cdf0e10cSrcweir {
1030cdf0e10cSrcweir aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir else if ( aData[LOCKFILE_SYSUSERNAME_ID].getLength() > 0 )
1033cdf0e10cSrcweir {
1034cdf0e10cSrcweir aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
1035cdf0e10cSrcweir }
1036cdf0e10cSrcweir }
1037cdf0e10cSrcweir }
1038cdf0e10cSrcweir catch ( uno::Exception& )
1039cdf0e10cSrcweir {
1040cdf0e10cSrcweir }
1041cdf0e10cSrcweir String aMessage( ScGlobal::GetRscString( STR_FILE_LOCKED_TRY_LATER ) );
1042cdf0e10cSrcweir aMessage.SearchAndReplaceAscii( "%1", aUserName );
1043cdf0e10cSrcweir
1044cdf0e10cSrcweir WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ), aMessage );
1045cdf0e10cSrcweir aBox.Execute();
1046cdf0e10cSrcweir }
1047cdf0e10cSrcweir else
1048cdf0e10cSrcweir {
1049cdf0e10cSrcweir WarningBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
1050cdf0e10cSrcweir ScGlobal::GetRscString( STR_DOC_DISABLESHARED ) );
1051cdf0e10cSrcweir if ( aBox.Execute() == RET_YES )
1052cdf0e10cSrcweir {
1053cdf0e10cSrcweir xCloseable->close( sal_True );
1054cdf0e10cSrcweir
1055cdf0e10cSrcweir if ( !SwitchToShared( sal_False, sal_True ) )
1056cdf0e10cSrcweir {
1057cdf0e10cSrcweir // TODO/LATER: what should be done in case the switch has failed?
1058cdf0e10cSrcweir // for example in case the user has cancelled the saveAs operation
1059cdf0e10cSrcweir }
1060cdf0e10cSrcweir
1061cdf0e10cSrcweir EnableSharedSettings( false );
1062cdf0e10cSrcweir
1063cdf0e10cSrcweir if ( pBindings )
1064cdf0e10cSrcweir {
1065cdf0e10cSrcweir pBindings->ExecuteSynchron( SID_SAVEDOC );
1066cdf0e10cSrcweir }
1067cdf0e10cSrcweir
1068cdf0e10cSrcweir ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
1069cdf0e10cSrcweir if ( pTabView )
1070cdf0e10cSrcweir {
1071cdf0e10cSrcweir pTabView->UpdateLayerLocks();
1072cdf0e10cSrcweir }
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir else
1075cdf0e10cSrcweir {
1076cdf0e10cSrcweir xCloseable->close( sal_True );
1077cdf0e10cSrcweir }
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir }
1080cdf0e10cSrcweir else
1081cdf0e10cSrcweir {
1082cdf0e10cSrcweir xCloseable->close( sal_True );
1083cdf0e10cSrcweir WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ),
1084cdf0e10cSrcweir ScGlobal::GetRscString( STR_DOC_NOLONGERSHARED ) );
1085cdf0e10cSrcweir aBox.Execute();
1086cdf0e10cSrcweir }
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir catch ( uno::Exception& )
1089cdf0e10cSrcweir {
1090cdf0e10cSrcweir DBG_ERROR( "SID_SHARE_DOC: caught exception\n" );
1091cdf0e10cSrcweir SC_MOD()->SetInSharedDocSaving( false );
1092cdf0e10cSrcweir
1093cdf0e10cSrcweir try
1094cdf0e10cSrcweir {
1095cdf0e10cSrcweir uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
1096cdf0e10cSrcweir xClose->close( sal_True );
1097cdf0e10cSrcweir }
1098cdf0e10cSrcweir catch ( uno::Exception& )
1099cdf0e10cSrcweir {
1100cdf0e10cSrcweir }
1101cdf0e10cSrcweir }
1102cdf0e10cSrcweir }
1103cdf0e10cSrcweir }
1104cdf0e10cSrcweir }
1105cdf0e10cSrcweir rReq.Done();
1106cdf0e10cSrcweir }
1107cdf0e10cSrcweir break;
1108cdf0e10cSrcweir
1109cdf0e10cSrcweir default:
1110cdf0e10cSrcweir {
1111cdf0e10cSrcweir // kleiner (?) Hack -> forward der Slots an TabViewShell
1112cdf0e10cSrcweir ScTabViewShell* pSh = GetBestViewShell();
1113cdf0e10cSrcweir if ( pSh )
1114cdf0e10cSrcweir pSh->Execute( rReq );
1115cdf0e10cSrcweir else
1116cdf0e10cSrcweir SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT );
1117cdf0e10cSrcweir }
1118cdf0e10cSrcweir }
1119cdf0e10cSrcweir }
1120cdf0e10cSrcweir
1121cdf0e10cSrcweir
1122cdf0e10cSrcweir //------------------------------------------------------------------
1123cdf0e10cSrcweir
UpdateAcceptChangesDialog()1124cdf0e10cSrcweir void UpdateAcceptChangesDialog()
1125cdf0e10cSrcweir {
1126cdf0e10cSrcweir // update "accept changes" dialog
1127cdf0e10cSrcweir //! notify all views
1128cdf0e10cSrcweir SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1129cdf0e10cSrcweir if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) )
1130cdf0e10cSrcweir {
1131cdf0e10cSrcweir SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT );
1132cdf0e10cSrcweir if ( pChild )
1133cdf0e10cSrcweir ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg();
1134cdf0e10cSrcweir }
1135cdf0e10cSrcweir }
1136cdf0e10cSrcweir
1137cdf0e10cSrcweir //------------------------------------------------------------------
1138cdf0e10cSrcweir
ExecuteChangeProtectionDialog(Window * _pParent,sal_Bool bJustQueryIfProtected)1139cdf0e10cSrcweir sal_Bool ScDocShell::ExecuteChangeProtectionDialog( Window* _pParent, sal_Bool bJustQueryIfProtected )
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir sal_Bool bDone = sal_False;
1142cdf0e10cSrcweir ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
1143cdf0e10cSrcweir if ( pChangeTrack )
1144cdf0e10cSrcweir {
1145cdf0e10cSrcweir sal_Bool bProtected = pChangeTrack->IsProtected();
1146cdf0e10cSrcweir if ( bJustQueryIfProtected && !bProtected )
1147cdf0e10cSrcweir return sal_True;
1148cdf0e10cSrcweir
1149cdf0e10cSrcweir String aTitle( ScResId( bProtected ? SCSTR_CHG_UNPROTECT : SCSTR_CHG_PROTECT ) );
1150cdf0e10cSrcweir String aText( ScResId( SCSTR_PASSWORD ) );
1151cdf0e10cSrcweir String aPassword;
1152cdf0e10cSrcweir
1153cdf0e10cSrcweir SfxPasswordDialog* pDlg = new SfxPasswordDialog(
1154cdf0e10cSrcweir _pParent ? _pParent : GetActiveDialogParent(), &aText );
1155cdf0e10cSrcweir pDlg->SetText( aTitle );
1156cdf0e10cSrcweir pDlg->SetMinLen( 1 );
1157cdf0e10cSrcweir pDlg->SetHelpId( GetStaticInterface()->GetSlot(SID_CHG_PROTECT)->GetCommand() );
1158cdf0e10cSrcweir pDlg->SetEditHelpId( HID_CHG_PROTECT );
1159cdf0e10cSrcweir if ( !bProtected )
1160cdf0e10cSrcweir pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1161cdf0e10cSrcweir if ( pDlg->Execute() == RET_OK )
1162cdf0e10cSrcweir aPassword = pDlg->GetPassword();
1163cdf0e10cSrcweir delete pDlg;
1164cdf0e10cSrcweir
1165cdf0e10cSrcweir if ( aPassword.Len() )
1166cdf0e10cSrcweir {
1167cdf0e10cSrcweir if ( bProtected )
1168cdf0e10cSrcweir {
1169cdf0e10cSrcweir if ( SvPasswordHelper::CompareHashPassword(pChangeTrack->GetProtection(), aPassword) )
1170cdf0e10cSrcweir {
1171cdf0e10cSrcweir if ( bJustQueryIfProtected )
1172cdf0e10cSrcweir bDone = sal_True;
1173cdf0e10cSrcweir else
1174cdf0e10cSrcweir pChangeTrack->SetProtection(
1175cdf0e10cSrcweir com::sun::star::uno::Sequence< sal_Int8 > (0) );
1176cdf0e10cSrcweir }
1177cdf0e10cSrcweir else
1178cdf0e10cSrcweir {
1179cdf0e10cSrcweir InfoBox aBox( GetActiveDialogParent(),
1180cdf0e10cSrcweir String( ScResId( SCSTR_WRONGPASSWORD ) ) );
1181cdf0e10cSrcweir aBox.Execute();
1182cdf0e10cSrcweir }
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir else
1185cdf0e10cSrcweir {
1186cdf0e10cSrcweir com::sun::star::uno::Sequence< sal_Int8 > aPass;
1187cdf0e10cSrcweir SvPasswordHelper::GetHashPassword( aPass, aPassword );
1188cdf0e10cSrcweir pChangeTrack->SetProtection( aPass );
1189cdf0e10cSrcweir }
1190cdf0e10cSrcweir if ( bProtected != pChangeTrack->IsProtected() )
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir UpdateAcceptChangesDialog();
1193cdf0e10cSrcweir bDone = sal_True;
1194cdf0e10cSrcweir }
1195cdf0e10cSrcweir }
1196cdf0e10cSrcweir }
1197cdf0e10cSrcweir else if ( bJustQueryIfProtected )
1198cdf0e10cSrcweir bDone = sal_True;
1199cdf0e10cSrcweir return bDone;
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir
1203cdf0e10cSrcweir //------------------------------------------------------------------
1204cdf0e10cSrcweir
DoRecalc(sal_Bool bApi)1205cdf0e10cSrcweir void ScDocShell::DoRecalc( sal_Bool bApi )
1206cdf0e10cSrcweir {
1207cdf0e10cSrcweir sal_Bool bDone = sal_False;
1208cdf0e10cSrcweir ScTabViewShell* pSh = GetBestViewShell();
1209cdf0e10cSrcweir if ( pSh )
1210cdf0e10cSrcweir {
1211cdf0e10cSrcweir ScInputHandler* pHdl = SC_MOD()->GetInputHdl(pSh);
1212cdf0e10cSrcweir if ( pHdl && pHdl->IsInputMode() && pHdl->IsFormulaMode() && !bApi )
1213cdf0e10cSrcweir {
1214cdf0e10cSrcweir pHdl->FormulaPreview(); // Teilergebnis als QuickHelp
1215cdf0e10cSrcweir bDone = sal_True;
1216cdf0e10cSrcweir }
1217cdf0e10cSrcweir else
1218cdf0e10cSrcweir {
1219cdf0e10cSrcweir pSh->UpdateInputLine(); // InputEnterHandler
1220cdf0e10cSrcweir pSh->UpdateInputHandler();
1221cdf0e10cSrcweir }
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir if (!bDone) // sonst Dokument neu berechnen
1224cdf0e10cSrcweir {
1225cdf0e10cSrcweir WaitObject aWaitObj( GetActiveDialogParent() );
1226cdf0e10cSrcweir aDocument.CalcFormulaTree();
1227cdf0e10cSrcweir if ( pSh )
1228cdf0e10cSrcweir pSh->UpdateCharts(sal_True);
1229cdf0e10cSrcweir
1230cdf0e10cSrcweir aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
1231cdf0e10cSrcweir
1232cdf0e10cSrcweir // #47939# Wenn es Charts gibt, dann alles painten, damit nicht
1233cdf0e10cSrcweir // PostDataChanged und die Charts nacheinander kommen und Teile
1234cdf0e10cSrcweir // doppelt gepainted werden.
1235cdf0e10cSrcweir
1236cdf0e10cSrcweir ScChartListenerCollection* pCharts = aDocument.GetChartListenerCollection();
1237cdf0e10cSrcweir if ( pCharts && pCharts->GetCount() )
1238cdf0e10cSrcweir PostPaintGridAll();
1239cdf0e10cSrcweir else
1240cdf0e10cSrcweir PostDataChanged();
1241cdf0e10cSrcweir }
1242cdf0e10cSrcweir }
1243cdf0e10cSrcweir
DoHardRecalc(sal_Bool)1244cdf0e10cSrcweir void ScDocShell::DoHardRecalc( sal_Bool /* bApi */ )
1245cdf0e10cSrcweir {
1246cdf0e10cSrcweir WaitObject aWaitObj( GetActiveDialogParent() );
1247cdf0e10cSrcweir ScTabViewShell* pSh = GetBestViewShell();
1248cdf0e10cSrcweir if ( pSh )
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir pSh->UpdateInputLine(); // InputEnterHandler
1251cdf0e10cSrcweir pSh->UpdateInputHandler();
1252cdf0e10cSrcweir }
1253cdf0e10cSrcweir aDocument.CalcAll();
1254cdf0e10cSrcweir GetDocFunc().DetectiveRefresh(); // erzeugt eigenes Undo
1255cdf0e10cSrcweir if ( pSh )
1256cdf0e10cSrcweir pSh->UpdateCharts(sal_True);
1257cdf0e10cSrcweir
1258cdf0e10cSrcweir // set notification flags for "calculate" event (used in SFX_HINT_DATACHANGED broadcast)
1259cdf0e10cSrcweir // (might check for the presence of any formulas on each sheet)
1260cdf0e10cSrcweir SCTAB nTabCount = aDocument.GetTableCount();
1261cdf0e10cSrcweir SCTAB nTab;
1262cdf0e10cSrcweir if (aDocument.HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE, true )) // search also for VBA hendler
1263cdf0e10cSrcweir for (nTab=0; nTab<nTabCount; nTab++)
1264cdf0e10cSrcweir aDocument.SetCalcNotification(nTab);
1265cdf0e10cSrcweir
1266cdf0e10cSrcweir // CalcAll doesn't broadcast value changes, so SC_HINT_CALCALL is broadcasted globally
1267cdf0e10cSrcweir // in addition to SFX_HINT_DATACHANGED.
1268cdf0e10cSrcweir aDocument.BroadcastUno( SfxSimpleHint( SC_HINT_CALCALL ) );
1269cdf0e10cSrcweir aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
1270cdf0e10cSrcweir
1271cdf0e10cSrcweir // use hard recalc also to disable stream-copying of all sheets
1272cdf0e10cSrcweir // (somewhat consistent with charts)
1273cdf0e10cSrcweir for (nTab=0; nTab<nTabCount; nTab++)
1274cdf0e10cSrcweir if (aDocument.IsStreamValid(nTab))
1275cdf0e10cSrcweir aDocument.SetStreamValid(nTab, sal_False);
1276cdf0e10cSrcweir
1277cdf0e10cSrcweir PostPaintGridAll();
1278cdf0e10cSrcweir }
1279cdf0e10cSrcweir
1280cdf0e10cSrcweir //------------------------------------------------------------------
1281cdf0e10cSrcweir
DoAutoStyle(const ScRange & rRange,const String & rStyle)1282cdf0e10cSrcweir void ScDocShell::DoAutoStyle( const ScRange& rRange, const String& rStyle )
1283cdf0e10cSrcweir {
1284cdf0e10cSrcweir ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1285cdf0e10cSrcweir ScStyleSheet* pStyleSheet =
1286cdf0e10cSrcweir pStylePool->FindCaseIns( rStyle, SFX_STYLE_FAMILY_PARA );
1287cdf0e10cSrcweir if (!pStyleSheet)
1288cdf0e10cSrcweir pStyleSheet = (ScStyleSheet*)
1289cdf0e10cSrcweir pStylePool->Find( ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA );
1290cdf0e10cSrcweir if (pStyleSheet)
1291cdf0e10cSrcweir {
1292cdf0e10cSrcweir DBG_ASSERT(rRange.aStart.Tab() == rRange.aEnd.Tab(),
1293cdf0e10cSrcweir "DoAutoStyle mit mehreren Tabellen");
1294cdf0e10cSrcweir SCTAB nTab = rRange.aStart.Tab();
1295cdf0e10cSrcweir SCCOL nStartCol = rRange.aStart.Col();
1296cdf0e10cSrcweir SCROW nStartRow = rRange.aStart.Row();
1297cdf0e10cSrcweir SCCOL nEndCol = rRange.aEnd.Col();
1298cdf0e10cSrcweir SCROW nEndRow = rRange.aEnd.Row();
1299cdf0e10cSrcweir aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
1300cdf0e10cSrcweir aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
1301cdf0e10cSrcweir PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PAINT_GRID );
1302cdf0e10cSrcweir }
1303cdf0e10cSrcweir }
1304cdf0e10cSrcweir
1305cdf0e10cSrcweir //------------------------------------------------------------------
1306cdf0e10cSrcweir
NotifyStyle(const SfxStyleSheetHint & rHint)1307cdf0e10cSrcweir void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint )
1308cdf0e10cSrcweir {
1309cdf0e10cSrcweir sal_uInt16 nId = rHint.GetHint();
1310cdf0e10cSrcweir const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet();
1311cdf0e10cSrcweir if (!pStyle)
1312cdf0e10cSrcweir return;
1313cdf0e10cSrcweir
1314cdf0e10cSrcweir if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PAGE )
1315cdf0e10cSrcweir {
1316cdf0e10cSrcweir if ( nId == SFX_STYLESHEET_MODIFIED )
1317cdf0e10cSrcweir {
1318cdf0e10cSrcweir ScDocShellModificator aModificator( *this );
1319cdf0e10cSrcweir
1320cdf0e10cSrcweir String aNewName = pStyle->GetName();
1321cdf0e10cSrcweir String aOldName = aNewName;
1322cdf0e10cSrcweir sal_Bool bExtended = rHint.ISA(SfxStyleSheetHintExtended); // Name geaendert?
1323cdf0e10cSrcweir if (bExtended)
1324cdf0e10cSrcweir aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName();
1325cdf0e10cSrcweir
1326cdf0e10cSrcweir if ( aNewName != aOldName )
1327cdf0e10cSrcweir aDocument.RenamePageStyleInUse( aOldName, aNewName );
1328cdf0e10cSrcweir
1329cdf0e10cSrcweir SCTAB nTabCount = aDocument.GetTableCount();
1330cdf0e10cSrcweir for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1331cdf0e10cSrcweir if (aDocument.GetPageStyle(nTab) == aNewName) // schon auf neu angepasst
1332cdf0e10cSrcweir {
1333cdf0e10cSrcweir aDocument.PageStyleModified( nTab, aNewName );
1334cdf0e10cSrcweir ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1335cdf0e10cSrcweir aPrintFunc.UpdatePages();
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir
1338cdf0e10cSrcweir aModificator.SetDocumentModified();
1339cdf0e10cSrcweir
1340cdf0e10cSrcweir if (bExtended)
1341cdf0e10cSrcweir {
1342cdf0e10cSrcweir SfxBindings* pBindings = GetViewBindings();
1343cdf0e10cSrcweir if (pBindings)
1344cdf0e10cSrcweir {
1345cdf0e10cSrcweir pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1346cdf0e10cSrcweir pBindings->Invalidate( SID_STYLE_FAMILY4 );
1347cdf0e10cSrcweir pBindings->Invalidate( FID_RESET_PRINTZOOM );
1348cdf0e10cSrcweir pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1349cdf0e10cSrcweir pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1350cdf0e10cSrcweir }
1351cdf0e10cSrcweir }
1352cdf0e10cSrcweir }
1353cdf0e10cSrcweir }
1354cdf0e10cSrcweir else if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PARA )
1355cdf0e10cSrcweir {
1356cdf0e10cSrcweir if ( nId == SFX_STYLESHEET_MODIFIED)
1357cdf0e10cSrcweir {
1358cdf0e10cSrcweir String aNewName = pStyle->GetName();
1359cdf0e10cSrcweir String aOldName = aNewName;
1360cdf0e10cSrcweir sal_Bool bExtended = rHint.ISA(SfxStyleSheetHintExtended);
1361cdf0e10cSrcweir if (bExtended)
1362cdf0e10cSrcweir aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName();
1363cdf0e10cSrcweir if ( aNewName != aOldName )
1364cdf0e10cSrcweir {
1365cdf0e10cSrcweir ScConditionalFormatList* pList = aDocument.GetCondFormList();
1366cdf0e10cSrcweir if (pList)
1367cdf0e10cSrcweir pList->RenameCellStyle( aOldName,aNewName );
1368cdf0e10cSrcweir }
1369cdf0e10cSrcweir }
1370cdf0e10cSrcweir }
1371cdf0e10cSrcweir
1372cdf0e10cSrcweir // alles andere geht ueber Slots...
1373cdf0e10cSrcweir }
1374cdf0e10cSrcweir
1375cdf0e10cSrcweir // wie in printfun.cxx
1376cdf0e10cSrcweir #define ZOOM_MIN 10
1377cdf0e10cSrcweir
SetPrintZoom(SCTAB nTab,sal_uInt16 nScale,sal_uInt16 nPages)1378cdf0e10cSrcweir void ScDocShell::SetPrintZoom( SCTAB nTab, sal_uInt16 nScale, sal_uInt16 nPages )
1379cdf0e10cSrcweir {
1380cdf0e10cSrcweir sal_Bool bUndo(aDocument.IsUndoEnabled());
1381cdf0e10cSrcweir String aStyleName = aDocument.GetPageStyle( nTab );
1382cdf0e10cSrcweir ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1383cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
1384cdf0e10cSrcweir DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1385cdf0e10cSrcweir if ( pStyleSheet )
1386cdf0e10cSrcweir {
1387cdf0e10cSrcweir ScDocShellModificator aModificator( *this );
1388cdf0e10cSrcweir
1389cdf0e10cSrcweir SfxItemSet& rSet = pStyleSheet->GetItemSet();
1390cdf0e10cSrcweir if (bUndo)
1391cdf0e10cSrcweir {
1392cdf0e10cSrcweir sal_uInt16 nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue();
1393cdf0e10cSrcweir sal_uInt16 nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
1394cdf0e10cSrcweir GetUndoManager()->AddUndoAction( new ScUndoPrintZoom(
1395cdf0e10cSrcweir this, nTab, nOldScale, nOldPages, nScale, nPages ) );
1396cdf0e10cSrcweir }
1397cdf0e10cSrcweir
1398cdf0e10cSrcweir rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
1399cdf0e10cSrcweir rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
1400cdf0e10cSrcweir
1401cdf0e10cSrcweir ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1402cdf0e10cSrcweir aPrintFunc.UpdatePages();
1403cdf0e10cSrcweir aModificator.SetDocumentModified();
1404cdf0e10cSrcweir
1405cdf0e10cSrcweir SfxBindings* pBindings = GetViewBindings();
1406cdf0e10cSrcweir if (pBindings)
1407cdf0e10cSrcweir pBindings->Invalidate( FID_RESET_PRINTZOOM );
1408cdf0e10cSrcweir }
1409cdf0e10cSrcweir }
1410cdf0e10cSrcweir
AdjustPrintZoom(const ScRange & rRange)1411cdf0e10cSrcweir sal_Bool ScDocShell::AdjustPrintZoom( const ScRange& rRange )
1412cdf0e10cSrcweir {
1413cdf0e10cSrcweir sal_Bool bChange = sal_False;
1414cdf0e10cSrcweir SCTAB nTab = rRange.aStart.Tab();
1415cdf0e10cSrcweir
1416cdf0e10cSrcweir String aStyleName = aDocument.GetPageStyle( nTab );
1417cdf0e10cSrcweir ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1418cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
1419cdf0e10cSrcweir DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1420cdf0e10cSrcweir if ( pStyleSheet )
1421cdf0e10cSrcweir {
1422cdf0e10cSrcweir SfxItemSet& rSet = pStyleSheet->GetItemSet();
1423cdf0e10cSrcweir sal_Bool bHeaders = ((const SfxBoolItem&)rSet.Get(ATTR_PAGE_HEADERS)).GetValue();
1424cdf0e10cSrcweir sal_uInt16 nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue();
1425cdf0e10cSrcweir sal_uInt16 nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
1426cdf0e10cSrcweir const ScRange* pRepeatCol = aDocument.GetRepeatColRange( nTab );
1427cdf0e10cSrcweir const ScRange* pRepeatRow = aDocument.GetRepeatRowRange( nTab );
1428cdf0e10cSrcweir
1429cdf0e10cSrcweir // benoetigte Skalierung fuer Selektion ausrechnen
1430cdf0e10cSrcweir
1431cdf0e10cSrcweir sal_uInt16 nNewScale = nOldScale;
1432cdf0e10cSrcweir
1433cdf0e10cSrcweir long nBlkTwipsX = 0;
1434cdf0e10cSrcweir if (bHeaders)
1435cdf0e10cSrcweir nBlkTwipsX += (long) PRINT_HEADER_WIDTH;
1436cdf0e10cSrcweir SCCOL nStartCol = rRange.aStart.Col();
1437cdf0e10cSrcweir SCCOL nEndCol = rRange.aEnd.Col();
1438cdf0e10cSrcweir if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
1439cdf0e10cSrcweir {
1440cdf0e10cSrcweir for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); i++ )
1441cdf0e10cSrcweir nBlkTwipsX += aDocument.GetColWidth( i, nTab );
1442cdf0e10cSrcweir if ( nStartCol <= pRepeatCol->aEnd.Col() )
1443cdf0e10cSrcweir nStartCol = pRepeatCol->aEnd.Col() + 1;
1444cdf0e10cSrcweir }
1445cdf0e10cSrcweir // legacy compilers' own scope for i
1446cdf0e10cSrcweir {
1447cdf0e10cSrcweir for ( SCCOL i=nStartCol; i<=nEndCol; i++ )
1448cdf0e10cSrcweir nBlkTwipsX += aDocument.GetColWidth( i, nTab );
1449cdf0e10cSrcweir }
1450cdf0e10cSrcweir
1451cdf0e10cSrcweir long nBlkTwipsY = 0;
1452cdf0e10cSrcweir if (bHeaders)
1453cdf0e10cSrcweir nBlkTwipsY += (long) PRINT_HEADER_HEIGHT;
1454cdf0e10cSrcweir SCROW nStartRow = rRange.aStart.Row();
1455cdf0e10cSrcweir SCROW nEndRow = rRange.aEnd.Row();
1456cdf0e10cSrcweir if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
1457cdf0e10cSrcweir {
1458cdf0e10cSrcweir nBlkTwipsY += aDocument.GetRowHeight( pRepeatRow->aStart.Row(),
1459cdf0e10cSrcweir pRepeatRow->aEnd.Row(), nTab );
1460cdf0e10cSrcweir if ( nStartRow <= pRepeatRow->aEnd.Row() )
1461cdf0e10cSrcweir nStartRow = pRepeatRow->aEnd.Row() + 1;
1462cdf0e10cSrcweir }
1463cdf0e10cSrcweir nBlkTwipsY += aDocument.GetRowHeight( nStartRow, nEndRow, nTab );
1464cdf0e10cSrcweir
1465cdf0e10cSrcweir Size aPhysPage;
1466cdf0e10cSrcweir long nHdr, nFtr;
1467cdf0e10cSrcweir ScPrintFunc aOldPrFunc( this, GetPrinter(), nTab );
1468cdf0e10cSrcweir aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr );
1469cdf0e10cSrcweir nBlkTwipsY += nHdr + nFtr;
1470cdf0e10cSrcweir
1471cdf0e10cSrcweir if ( nBlkTwipsX == 0 ) // #100639# hidden columns/rows may lead to 0
1472cdf0e10cSrcweir nBlkTwipsX = 1;
1473cdf0e10cSrcweir if ( nBlkTwipsY == 0 )
1474cdf0e10cSrcweir nBlkTwipsY = 1;
1475cdf0e10cSrcweir
1476cdf0e10cSrcweir long nNeeded = Min( aPhysPage.Width() * 100 / nBlkTwipsX,
1477cdf0e10cSrcweir aPhysPage.Height() * 100 / nBlkTwipsY );
1478cdf0e10cSrcweir if ( nNeeded < ZOOM_MIN )
1479cdf0e10cSrcweir nNeeded = ZOOM_MIN; // Begrenzung
1480cdf0e10cSrcweir if ( nNeeded < (long) nNewScale )
1481cdf0e10cSrcweir nNewScale = (sal_uInt16) nNeeded;
1482cdf0e10cSrcweir
1483cdf0e10cSrcweir bChange = ( nNewScale != nOldScale || nOldPages != 0 );
1484cdf0e10cSrcweir if ( bChange )
1485cdf0e10cSrcweir SetPrintZoom( nTab, nNewScale, 0 );
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir return bChange;
1488cdf0e10cSrcweir }
1489cdf0e10cSrcweir
PageStyleModified(const String & rStyleName,sal_Bool bApi)1490cdf0e10cSrcweir void ScDocShell::PageStyleModified( const String& rStyleName, sal_Bool bApi )
1491cdf0e10cSrcweir {
1492cdf0e10cSrcweir ScDocShellModificator aModificator( *this );
1493cdf0e10cSrcweir
1494cdf0e10cSrcweir sal_Bool bWarn = sal_False;
1495cdf0e10cSrcweir
1496cdf0e10cSrcweir SCTAB nTabCount = aDocument.GetTableCount();
1497cdf0e10cSrcweir SCTAB nUseTab = MAXTAB+1;
1498cdf0e10cSrcweir for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++)
1499cdf0e10cSrcweir if ( aDocument.GetPageStyle(nTab) == rStyleName &&
1500cdf0e10cSrcweir ( !bApi || aDocument.GetPageSize(nTab).Width() ) )
1501cdf0e10cSrcweir nUseTab = nTab;
1502cdf0e10cSrcweir // bei bApi nur, wenn Umbrueche schon angezeigt
1503cdf0e10cSrcweir
1504cdf0e10cSrcweir if (ValidTab(nUseTab)) // nicht verwendet -> nichts zu tun
1505cdf0e10cSrcweir {
1506cdf0e10cSrcweir ScPrintFunc aPrintFunc( this, GetPrinter(), nUseTab ); //! ohne CountPages auskommen
1507cdf0e10cSrcweir if (!aPrintFunc.UpdatePages()) // setzt Umbrueche auf allen Tabs
1508cdf0e10cSrcweir bWarn = sal_True;
1509cdf0e10cSrcweir
1510cdf0e10cSrcweir if (bWarn && !bApi)
1511cdf0e10cSrcweir {
1512cdf0e10cSrcweir ScWaitCursorOff aWaitOff( GetActiveDialogParent() );
1513cdf0e10cSrcweir InfoBox aInfoBox(GetActiveDialogParent(),
1514cdf0e10cSrcweir ScGlobal::GetRscString(STR_PRINT_INVALID_AREA));
1515cdf0e10cSrcweir aInfoBox.Execute();
1516cdf0e10cSrcweir }
1517cdf0e10cSrcweir }
1518cdf0e10cSrcweir
1519cdf0e10cSrcweir aModificator.SetDocumentModified();
1520cdf0e10cSrcweir
1521cdf0e10cSrcweir SfxBindings* pBindings = GetViewBindings();
1522cdf0e10cSrcweir if (pBindings)
1523cdf0e10cSrcweir {
1524cdf0e10cSrcweir pBindings->Invalidate( FID_RESET_PRINTZOOM );
1525cdf0e10cSrcweir pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1526cdf0e10cSrcweir pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1527cdf0e10cSrcweir }
1528cdf0e10cSrcweir }
1529cdf0e10cSrcweir
ExecutePageStyle(SfxViewShell & rCaller,SfxRequest & rReq,SCTAB nCurTab)1530cdf0e10cSrcweir void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,
1531cdf0e10cSrcweir SfxRequest& rReq,
1532cdf0e10cSrcweir SCTAB nCurTab )
1533cdf0e10cSrcweir {
1534cdf0e10cSrcweir const SfxItemSet* pReqArgs = rReq.GetArgs();
1535cdf0e10cSrcweir
1536cdf0e10cSrcweir switch ( rReq.GetSlot() )
1537cdf0e10cSrcweir {
1538cdf0e10cSrcweir case SID_STATUS_PAGESTYLE: // Click auf StatusBar-Control
1539cdf0e10cSrcweir case SID_FORMATPAGE:
1540cdf0e10cSrcweir {
1541cdf0e10cSrcweir if ( pReqArgs != NULL )
1542cdf0e10cSrcweir {
1543cdf0e10cSrcweir }
1544cdf0e10cSrcweir else if ( pReqArgs == NULL )
1545cdf0e10cSrcweir {
1546cdf0e10cSrcweir sal_Bool bUndo(aDocument.IsUndoEnabled());
1547cdf0e10cSrcweir String aOldName = aDocument.GetPageStyle( nCurTab );
1548cdf0e10cSrcweir ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1549cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet
1550cdf0e10cSrcweir = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
1551cdf0e10cSrcweir
1552cdf0e10cSrcweir DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1553cdf0e10cSrcweir
1554cdf0e10cSrcweir if ( pStyleSheet )
1555cdf0e10cSrcweir {
1556cdf0e10cSrcweir ScStyleSaveData aOldData;
1557cdf0e10cSrcweir if (bUndo)
1558cdf0e10cSrcweir aOldData.InitFromStyle( pStyleSheet );
1559cdf0e10cSrcweir
1560cdf0e10cSrcweir SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1561cdf0e10cSrcweir
1562cdf0e10cSrcweir //CHINA001 ScStyleDlg* pDlg = new ScStyleDlg( GetActiveDialogParent(),
1563cdf0e10cSrcweir //CHINA001 *pStyleSheet,
1564cdf0e10cSrcweir //CHINA001 RID_SCDLG_STYLES_PAGE );
1565cdf0e10cSrcweir //CHINA001
1566cdf0e10cSrcweir ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1567cdf0e10cSrcweir DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1568cdf0e10cSrcweir
1569cdf0e10cSrcweir SfxAbstractTabDialog* pDlg = pFact->CreateScStyleDlg( GetActiveDialogParent(), *pStyleSheet, RID_SCDLG_STYLES_PAGE, RID_SCDLG_STYLES_PAGE );
1570cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1571cdf0e10cSrcweir
1572cdf0e10cSrcweir if ( pDlg->Execute() == RET_OK )
1573cdf0e10cSrcweir {
1574cdf0e10cSrcweir const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1575cdf0e10cSrcweir
1576cdf0e10cSrcweir WaitObject aWait( GetActiveDialogParent() );
1577cdf0e10cSrcweir
1578cdf0e10cSrcweir String aNewName = pStyleSheet->GetName();
1579cdf0e10cSrcweir if ( aNewName != aOldName &&
1580cdf0e10cSrcweir aDocument.RenamePageStyleInUse( aOldName, aNewName ) )
1581cdf0e10cSrcweir {
1582cdf0e10cSrcweir SfxBindings* pBindings = GetViewBindings();
1583cdf0e10cSrcweir if (pBindings)
1584cdf0e10cSrcweir {
1585cdf0e10cSrcweir pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1586cdf0e10cSrcweir pBindings->Invalidate( FID_RESET_PRINTZOOM );
1587cdf0e10cSrcweir }
1588cdf0e10cSrcweir }
1589cdf0e10cSrcweir
1590cdf0e10cSrcweir if ( pOutSet )
1591cdf0e10cSrcweir aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1592cdf0e10cSrcweir
1593cdf0e10cSrcweir // merken fuer GetState():
1594cdf0e10cSrcweir GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
1595cdf0e10cSrcweir rCaller.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT );
1596cdf0e10cSrcweir
1597cdf0e10cSrcweir ScStyleSaveData aNewData;
1598cdf0e10cSrcweir aNewData.InitFromStyle( pStyleSheet );
1599cdf0e10cSrcweir if (bUndo)
1600cdf0e10cSrcweir {
1601cdf0e10cSrcweir GetUndoManager()->AddUndoAction(
1602cdf0e10cSrcweir new ScUndoModifyStyle( this, SFX_STYLE_FAMILY_PAGE,
1603cdf0e10cSrcweir aOldData, aNewData ) );
1604cdf0e10cSrcweir }
1605cdf0e10cSrcweir
1606cdf0e10cSrcweir PageStyleModified( aNewName, sal_False );
1607cdf0e10cSrcweir rReq.Done();
1608cdf0e10cSrcweir }
1609cdf0e10cSrcweir delete pDlg;
1610cdf0e10cSrcweir
1611cdf0e10cSrcweir rStyleSet.ClearItem( ATTR_PAGE_PAPERTRAY );
1612cdf0e10cSrcweir }
1613cdf0e10cSrcweir }
1614cdf0e10cSrcweir }
1615cdf0e10cSrcweir break;
1616cdf0e10cSrcweir
1617cdf0e10cSrcweir case SID_HFEDIT:
1618cdf0e10cSrcweir {
1619cdf0e10cSrcweir if ( pReqArgs != NULL )
1620cdf0e10cSrcweir {
1621cdf0e10cSrcweir }
1622cdf0e10cSrcweir else if ( pReqArgs == NULL )
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir String aStr( aDocument.GetPageStyle( nCurTab ) );
1625cdf0e10cSrcweir
1626cdf0e10cSrcweir ScStyleSheetPool* pStylePool
1627cdf0e10cSrcweir = aDocument.GetStyleSheetPool();
1628cdf0e10cSrcweir
1629cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet
1630cdf0e10cSrcweir = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE );
1631cdf0e10cSrcweir
1632cdf0e10cSrcweir DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1633cdf0e10cSrcweir
1634cdf0e10cSrcweir if ( pStyleSheet )
1635cdf0e10cSrcweir {
1636cdf0e10cSrcweir SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1637cdf0e10cSrcweir
1638cdf0e10cSrcweir SvxPageUsage eUsage =
1639cdf0e10cSrcweir SvxPageUsage( ((const SvxPageItem&)
1640cdf0e10cSrcweir rStyleSet.Get( ATTR_PAGE )).
1641cdf0e10cSrcweir GetPageUsage() );
1642cdf0e10cSrcweir sal_Bool bShareHeader = IS_SHARE_HEADER(rStyleSet);
1643cdf0e10cSrcweir sal_Bool bShareFooter = IS_SHARE_FOOTER(rStyleSet);
1644cdf0e10cSrcweir sal_uInt16 nResId = 0;
1645cdf0e10cSrcweir
1646cdf0e10cSrcweir switch ( eUsage )
1647cdf0e10cSrcweir {
1648cdf0e10cSrcweir case SVX_PAGE_LEFT:
1649cdf0e10cSrcweir case SVX_PAGE_RIGHT:
1650cdf0e10cSrcweir {
1651cdf0e10cSrcweir if ( bHeaderOn && bFooterOn )
1652cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT;
1653cdf0e10cSrcweir else if ( SVX_PAGE_RIGHT == eUsage )
1654cdf0e10cSrcweir {
1655cdf0e10cSrcweir if ( !bHeaderOn && bFooterOn )
1656cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1657cdf0e10cSrcweir else if ( bHeaderOn && !bFooterOn )
1658cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1659cdf0e10cSrcweir }
1660cdf0e10cSrcweir else
1661cdf0e10cSrcweir {
1662cdf0e10cSrcweir // #69193a# respect "shared" setting
1663cdf0e10cSrcweir if ( !bHeaderOn && bFooterOn )
1664cdf0e10cSrcweir nResId = bShareFooter ?
1665cdf0e10cSrcweir RID_SCDLG_HFEDIT_RIGHTFOOTER :
1666cdf0e10cSrcweir RID_SCDLG_HFEDIT_LEFTFOOTER;
1667cdf0e10cSrcweir else if ( bHeaderOn && !bFooterOn )
1668cdf0e10cSrcweir nResId = bShareHeader ?
1669cdf0e10cSrcweir RID_SCDLG_HFEDIT_RIGHTHEADER :
1670cdf0e10cSrcweir RID_SCDLG_HFEDIT_LEFTHEADER;
1671cdf0e10cSrcweir }
1672cdf0e10cSrcweir }
1673cdf0e10cSrcweir break;
1674cdf0e10cSrcweir
1675cdf0e10cSrcweir case SVX_PAGE_MIRROR:
1676cdf0e10cSrcweir case SVX_PAGE_ALL:
1677cdf0e10cSrcweir default:
1678cdf0e10cSrcweir {
1679cdf0e10cSrcweir if ( !bShareHeader && !bShareFooter )
1680cdf0e10cSrcweir {
1681cdf0e10cSrcweir if ( bHeaderOn && bFooterOn )
1682cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_ALL;
1683cdf0e10cSrcweir else if ( !bHeaderOn && bFooterOn )
1684cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_FOOTER;
1685cdf0e10cSrcweir else if ( bHeaderOn && !bFooterOn )
1686cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_HEADER;
1687cdf0e10cSrcweir }
1688cdf0e10cSrcweir else if ( bShareHeader && bShareFooter )
1689cdf0e10cSrcweir {
1690cdf0e10cSrcweir if ( bHeaderOn && bFooterOn )
1691cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT;
1692cdf0e10cSrcweir else
1693cdf0e10cSrcweir {
1694cdf0e10cSrcweir if ( !bHeaderOn && bFooterOn )
1695cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1696cdf0e10cSrcweir else if ( bHeaderOn && !bFooterOn )
1697cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1698cdf0e10cSrcweir }
1699cdf0e10cSrcweir }
1700cdf0e10cSrcweir else if ( !bShareHeader && bShareFooter )
1701cdf0e10cSrcweir {
1702cdf0e10cSrcweir if ( bHeaderOn && bFooterOn )
1703cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_SFTR;
1704cdf0e10cSrcweir else if ( !bHeaderOn && bFooterOn )
1705cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1706cdf0e10cSrcweir else if ( bHeaderOn && !bFooterOn )
1707cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_HEADER;
1708cdf0e10cSrcweir }
1709cdf0e10cSrcweir else if ( bShareHeader && !bShareFooter )
1710cdf0e10cSrcweir {
1711cdf0e10cSrcweir if ( bHeaderOn && bFooterOn )
1712cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_SHDR;
1713cdf0e10cSrcweir else if ( !bHeaderOn && bFooterOn )
1714cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_FOOTER;
1715cdf0e10cSrcweir else if ( bHeaderOn && !bFooterOn )
1716cdf0e10cSrcweir nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1717cdf0e10cSrcweir }
1718cdf0e10cSrcweir }
1719cdf0e10cSrcweir }
1720cdf0e10cSrcweir
1721cdf0e10cSrcweir //CHINA001 ScHFEditDlg* pDlg
1722cdf0e10cSrcweir //CHINA001 = new ScHFEditDlg( SFX_APP()->GetViewFrame(),
1723cdf0e10cSrcweir //CHINA001 GetActiveDialogParent(),
1724cdf0e10cSrcweir //CHINA001 rStyleSet,
1725cdf0e10cSrcweir //CHINA001 aStr,
1726cdf0e10cSrcweir //CHINA001 nResId );
1727cdf0e10cSrcweir //CHINA001
1728cdf0e10cSrcweir ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1729cdf0e10cSrcweir DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1730cdf0e10cSrcweir
1731cdf0e10cSrcweir SfxAbstractTabDialog* pDlg = pFact->CreateScHFEditDlg( SfxViewFrame::Current(),
1732cdf0e10cSrcweir GetActiveDialogParent(),
1733cdf0e10cSrcweir rStyleSet,
1734cdf0e10cSrcweir aStr,
1735cdf0e10cSrcweir RID_SCDLG_HFEDIT, nResId);
1736cdf0e10cSrcweir DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1737cdf0e10cSrcweir if ( pDlg->Execute() == RET_OK )
1738cdf0e10cSrcweir {
1739cdf0e10cSrcweir const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1740cdf0e10cSrcweir
1741cdf0e10cSrcweir if ( pOutSet )
1742cdf0e10cSrcweir aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1743cdf0e10cSrcweir
1744cdf0e10cSrcweir SetDocumentModified();
1745cdf0e10cSrcweir rReq.Done();
1746cdf0e10cSrcweir }
1747cdf0e10cSrcweir delete pDlg;
1748cdf0e10cSrcweir }
1749cdf0e10cSrcweir }
1750cdf0e10cSrcweir }
1751cdf0e10cSrcweir break;
1752cdf0e10cSrcweir
1753cdf0e10cSrcweir default:
1754cdf0e10cSrcweir break;
1755cdf0e10cSrcweir }
1756cdf0e10cSrcweir }
1757cdf0e10cSrcweir
GetStatePageStyle(SfxViewShell &,SfxItemSet & rSet,SCTAB nCurTab)1758cdf0e10cSrcweir void ScDocShell::GetStatePageStyle( SfxViewShell& /* rCaller */,
1759cdf0e10cSrcweir SfxItemSet& rSet,
1760cdf0e10cSrcweir SCTAB nCurTab )
1761cdf0e10cSrcweir {
1762cdf0e10cSrcweir SfxWhichIter aIter(rSet);
1763cdf0e10cSrcweir sal_uInt16 nWhich = aIter.FirstWhich();
1764cdf0e10cSrcweir while ( nWhich )
1765cdf0e10cSrcweir {
1766cdf0e10cSrcweir switch (nWhich)
1767cdf0e10cSrcweir {
1768cdf0e10cSrcweir case SID_STATUS_PAGESTYLE:
1769cdf0e10cSrcweir rSet.Put( SfxStringItem( nWhich, aDocument.GetPageStyle( nCurTab ) ) );
1770cdf0e10cSrcweir break;
1771cdf0e10cSrcweir
1772cdf0e10cSrcweir case SID_HFEDIT:
1773cdf0e10cSrcweir {
1774cdf0e10cSrcweir String aStr = aDocument.GetPageStyle( nCurTab );
1775cdf0e10cSrcweir ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1776cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE );
1777cdf0e10cSrcweir
1778cdf0e10cSrcweir DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1779cdf0e10cSrcweir
1780cdf0e10cSrcweir if ( pStyleSheet )
1781cdf0e10cSrcweir {
1782cdf0e10cSrcweir SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1783cdf0e10cSrcweir
1784cdf0e10cSrcweir GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
1785cdf0e10cSrcweir
1786cdf0e10cSrcweir if ( !bHeaderOn && !bFooterOn )
1787cdf0e10cSrcweir rSet.DisableItem( nWhich );
1788cdf0e10cSrcweir }
1789cdf0e10cSrcweir }
1790cdf0e10cSrcweir break;
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir
1793cdf0e10cSrcweir nWhich = aIter.NextWhich();
1794cdf0e10cSrcweir }
1795cdf0e10cSrcweir }
1796cdf0e10cSrcweir
GetState(SfxItemSet & rSet)1797cdf0e10cSrcweir void ScDocShell::GetState( SfxItemSet &rSet )
1798cdf0e10cSrcweir {
1799cdf0e10cSrcweir SfxWhichIter aIter(rSet);
1800cdf0e10cSrcweir sal_uInt16 nWhich = aIter.FirstWhich();
1801cdf0e10cSrcweir while ( nWhich )
1802cdf0e10cSrcweir {
1803cdf0e10cSrcweir switch (nWhich)
1804cdf0e10cSrcweir {
1805cdf0e10cSrcweir case FID_AUTO_CALC:
1806cdf0e10cSrcweir if ( (sal_Bool) aDocument.GetHardRecalcState() )
1807cdf0e10cSrcweir rSet.DisableItem( nWhich );
1808cdf0e10cSrcweir else
1809cdf0e10cSrcweir rSet.Put( SfxBoolItem( nWhich, aDocument.GetAutoCalc() ) );
1810cdf0e10cSrcweir break;
1811cdf0e10cSrcweir
1812cdf0e10cSrcweir case FID_CHG_RECORD:
1813cdf0e10cSrcweir if ( IsDocShared() )
1814cdf0e10cSrcweir rSet.DisableItem( nWhich );
1815cdf0e10cSrcweir else
1816cdf0e10cSrcweir rSet.Put( SfxBoolItem( nWhich,
1817cdf0e10cSrcweir aDocument.GetChangeTrack() != NULL ) );
1818cdf0e10cSrcweir break;
1819cdf0e10cSrcweir
1820cdf0e10cSrcweir case SID_CHG_PROTECT:
1821cdf0e10cSrcweir {
1822cdf0e10cSrcweir ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
1823cdf0e10cSrcweir if ( pChangeTrack && !IsDocShared() )
1824cdf0e10cSrcweir rSet.Put( SfxBoolItem( nWhich,
1825cdf0e10cSrcweir pChangeTrack->IsProtected() ) );
1826cdf0e10cSrcweir else
1827cdf0e10cSrcweir rSet.DisableItem( nWhich );
1828cdf0e10cSrcweir }
1829cdf0e10cSrcweir break;
1830cdf0e10cSrcweir
1831cdf0e10cSrcweir case SID_DOCUMENT_COMPARE:
1832cdf0e10cSrcweir {
1833cdf0e10cSrcweir if ( IsDocShared() )
1834cdf0e10cSrcweir {
1835cdf0e10cSrcweir rSet.DisableItem( nWhich );
1836cdf0e10cSrcweir }
1837cdf0e10cSrcweir }
1838cdf0e10cSrcweir break;
1839cdf0e10cSrcweir
1840cdf0e10cSrcweir // Wenn eine Formel editiert wird, muss FID_RECALC auf jeden Fall enabled sein.
1841cdf0e10cSrcweir // Recalc fuer das Doc war mal wegen #29898# disabled, wenn AutoCalc an war,
1842cdf0e10cSrcweir // ist jetzt wegen #41540# aber auch immer enabled.
1843cdf0e10cSrcweir // case FID_RECALC:
1844cdf0e10cSrcweir // if ( aDocument.GetAutoCalc() )
1845cdf0e10cSrcweir // rSet.DisableItem( nWhich );
1846cdf0e10cSrcweir // break;
1847cdf0e10cSrcweir
1848cdf0e10cSrcweir case SID_TABLES_COUNT:
1849cdf0e10cSrcweir rSet.Put( SfxInt16Item( nWhich, aDocument.GetTableCount() ) );
1850cdf0e10cSrcweir break;
1851cdf0e10cSrcweir
1852cdf0e10cSrcweir case SID_ATTR_YEAR2000 :
1853cdf0e10cSrcweir rSet.Put( SfxUInt16Item( nWhich,
1854cdf0e10cSrcweir aDocument.GetDocOptions().GetYear2000() ) );
1855cdf0e10cSrcweir break;
1856cdf0e10cSrcweir
1857cdf0e10cSrcweir case SID_SHARE_DOC:
1858cdf0e10cSrcweir {
1859cdf0e10cSrcweir if ( IsReadOnly() )
1860cdf0e10cSrcweir {
1861cdf0e10cSrcweir rSet.DisableItem( nWhich );
1862cdf0e10cSrcweir }
1863cdf0e10cSrcweir }
1864cdf0e10cSrcweir break;
1865cdf0e10cSrcweir
1866cdf0e10cSrcweir default:
1867cdf0e10cSrcweir {
1868cdf0e10cSrcweir }
1869cdf0e10cSrcweir break;
1870cdf0e10cSrcweir }
1871cdf0e10cSrcweir
1872cdf0e10cSrcweir nWhich = aIter.NextWhich();
1873cdf0e10cSrcweir }
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir
GetSbxState(SfxItemSet & rSet)1876cdf0e10cSrcweir void ScDocShell::GetSbxState( SfxItemSet &rSet )
1877cdf0e10cSrcweir {
1878cdf0e10cSrcweir // SID_SC_SELECTION (Selection),
1879cdf0e10cSrcweir // SID_SC_ACTIVECELL (ActiveCell),
1880cdf0e10cSrcweir // SID_SC_ACTIVETAB (ActiveTable),
1881cdf0e10cSrcweir // SID_TABLES_GET (Tables),
1882cdf0e10cSrcweir // SID_PIVOT_GET (DataPilotTables) - removed (old Basic)
1883cdf0e10cSrcweir
1884cdf0e10cSrcweir //
1885cdf0e10cSrcweir // Wenn hier Slots von der View-Shell executed werden, muss auch der
1886cdf0e10cSrcweir // GetState weitergeleitet werden!
1887cdf0e10cSrcweir //
1888cdf0e10cSrcweir
1889cdf0e10cSrcweir ScTabViewShell* pVisibleSh = GetBestViewShell(); // sichtbare View
1890cdf0e10cSrcweir if ( pVisibleSh )
1891cdf0e10cSrcweir pVisibleSh->GetState( rSet );
1892cdf0e10cSrcweir }
1893cdf0e10cSrcweir
Draw(OutputDevice * pDev,const JobSetup &,sal_uInt16 nAspect)1894cdf0e10cSrcweir void __EXPORT ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, sal_uInt16 nAspect )
1895cdf0e10cSrcweir {
1896cdf0e10cSrcweir // bIsOle = sal_True; // jetzt ueber den CreateMode
1897cdf0e10cSrcweir
1898cdf0e10cSrcweir SCTAB nVisTab = aDocument.GetVisibleTab();
1899cdf0e10cSrcweir if (!aDocument.HasTable(nVisTab))
1900cdf0e10cSrcweir return;
1901cdf0e10cSrcweir
1902cdf0e10cSrcweir sal_uLong nOldLayoutMode = pDev->GetLayoutMode();
1903cdf0e10cSrcweir pDev->SetLayoutMode( TEXT_LAYOUT_DEFAULT ); // even if it's the same, to get the metafile action
1904cdf0e10cSrcweir
1905cdf0e10cSrcweir if ( nAspect == ASPECT_THUMBNAIL )
1906cdf0e10cSrcweir {
1907cdf0e10cSrcweir Rectangle aBoundRect = GetVisArea( ASPECT_THUMBNAIL );
1908cdf0e10cSrcweir ScViewData aTmpData( this, NULL );
1909cdf0e10cSrcweir aTmpData.SetTabNo(nVisTab);
1910cdf0e10cSrcweir aDocument.SnapVisArea( aBoundRect );
1911cdf0e10cSrcweir aTmpData.SetScreen( aBoundRect );
1912cdf0e10cSrcweir ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, sal_True );
1913cdf0e10cSrcweir }
1914cdf0e10cSrcweir else
1915cdf0e10cSrcweir {
1916cdf0e10cSrcweir Rectangle aBoundRect = SfxObjectShell::GetVisArea();
1917cdf0e10cSrcweir ScViewData aTmpData( this, NULL );
1918cdf0e10cSrcweir aTmpData.SetTabNo(nVisTab);
1919cdf0e10cSrcweir aDocument.SnapVisArea( aBoundRect );
1920cdf0e10cSrcweir aTmpData.SetScreen( aBoundRect );
1921cdf0e10cSrcweir ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, sal_True );
1922cdf0e10cSrcweir }
1923cdf0e10cSrcweir
1924cdf0e10cSrcweir pDev->SetLayoutMode( nOldLayoutMode );
1925cdf0e10cSrcweir }
1926cdf0e10cSrcweir
GetVisArea(sal_uInt16 nAspect) const1927cdf0e10cSrcweir Rectangle __EXPORT ScDocShell::GetVisArea( sal_uInt16 nAspect ) const
1928cdf0e10cSrcweir {
1929cdf0e10cSrcweir SfxObjectCreateMode eShellMode = GetCreateMode();
1930cdf0e10cSrcweir if ( eShellMode == SFX_CREATE_MODE_ORGANIZER )
1931cdf0e10cSrcweir {
1932cdf0e10cSrcweir // ohne Inhalte wissen wir auch nicht, wie gross die Inhalte sind
1933cdf0e10cSrcweir // leeres Rechteck zurueckgeben, das wird dann nach dem Laden berechnet
1934cdf0e10cSrcweir return Rectangle();
1935cdf0e10cSrcweir }
1936cdf0e10cSrcweir
1937cdf0e10cSrcweir if( nAspect == ASPECT_THUMBNAIL )
1938cdf0e10cSrcweir {
1939cdf0e10cSrcweir // Rectangle aArea( 0,0, 3175,3175 ); // 120x120 Pixel in 1:1
1940cdf0e10cSrcweir Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X,SC_PREVIEW_SIZE_Y );
1941cdf0e10cSrcweir sal_Bool bNegativePage = aDocument.IsNegativePage( aDocument.GetVisibleTab() );
1942cdf0e10cSrcweir if ( bNegativePage )
1943cdf0e10cSrcweir ScDrawLayer::MirrorRectRTL( aArea );
1944cdf0e10cSrcweir aDocument.SnapVisArea( aArea );
1945cdf0e10cSrcweir return aArea;
1946cdf0e10cSrcweir }
1947cdf0e10cSrcweir else if( nAspect == ASPECT_CONTENT && eShellMode != SFX_CREATE_MODE_EMBEDDED )
1948cdf0e10cSrcweir {
1949cdf0e10cSrcweir // Visarea holen wie nach Load
1950cdf0e10cSrcweir
1951cdf0e10cSrcweir SCTAB nVisTab = aDocument.GetVisibleTab();
1952cdf0e10cSrcweir if (!aDocument.HasTable(nVisTab))
1953cdf0e10cSrcweir {
1954cdf0e10cSrcweir nVisTab = 0;
1955cdf0e10cSrcweir ((ScDocShell*)this)->aDocument.SetVisibleTab(nVisTab);
1956cdf0e10cSrcweir }
1957cdf0e10cSrcweir SCCOL nStartCol;
1958cdf0e10cSrcweir SCROW nStartRow;
1959cdf0e10cSrcweir aDocument.GetDataStart( nVisTab, nStartCol, nStartRow );
1960cdf0e10cSrcweir SCCOL nEndCol;
1961cdf0e10cSrcweir SCROW nEndRow;
1962cdf0e10cSrcweir aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow );
1963cdf0e10cSrcweir if (nStartCol>nEndCol)
1964cdf0e10cSrcweir nStartCol = nEndCol;
1965cdf0e10cSrcweir if (nStartRow>nEndRow)
1966cdf0e10cSrcweir nStartRow = nEndRow;
1967cdf0e10cSrcweir Rectangle aNewArea = ((ScDocument&)aDocument)
1968cdf0e10cSrcweir .GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab );
1969cdf0e10cSrcweir //TODO/LATER: different methods for setting VisArea?!
1970cdf0e10cSrcweir ((ScDocShell*)this)->SfxObjectShell::SetVisArea( aNewArea );
1971cdf0e10cSrcweir return aNewArea;
1972cdf0e10cSrcweir }
1973cdf0e10cSrcweir else
1974cdf0e10cSrcweir return SfxObjectShell::GetVisArea( nAspect );
1975cdf0e10cSrcweir }
1976cdf0e10cSrcweir
GetPageOnFromPageStyleSet(const SfxItemSet * pStyleSet,SCTAB nCurTab,sal_Bool & rbHeader,sal_Bool & rbFooter)1977cdf0e10cSrcweir void ScDocShell::GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
1978cdf0e10cSrcweir SCTAB nCurTab,
1979cdf0e10cSrcweir sal_Bool& rbHeader,
1980cdf0e10cSrcweir sal_Bool& rbFooter )
1981cdf0e10cSrcweir {
1982cdf0e10cSrcweir if ( !pStyleSet )
1983cdf0e10cSrcweir {
1984cdf0e10cSrcweir ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1985cdf0e10cSrcweir SfxStyleSheetBase* pStyleSheet = pStylePool->
1986cdf0e10cSrcweir Find( aDocument.GetPageStyle( nCurTab ),
1987cdf0e10cSrcweir SFX_STYLE_FAMILY_PAGE );
1988cdf0e10cSrcweir
1989cdf0e10cSrcweir DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1990cdf0e10cSrcweir
1991cdf0e10cSrcweir if ( pStyleSheet )
1992cdf0e10cSrcweir pStyleSet = &pStyleSheet->GetItemSet();
1993cdf0e10cSrcweir else
1994cdf0e10cSrcweir rbHeader = rbFooter = sal_False;
1995cdf0e10cSrcweir }
1996cdf0e10cSrcweir
1997cdf0e10cSrcweir DBG_ASSERT( pStyleSet, "PageStyle-Set not found! :-(" );
1998cdf0e10cSrcweir
1999cdf0e10cSrcweir //--------------------------------------------------------------------
2000cdf0e10cSrcweir
2001cdf0e10cSrcweir const SvxSetItem* pSetItem = NULL;
2002cdf0e10cSrcweir const SfxItemSet* pSet = NULL;
2003cdf0e10cSrcweir
2004cdf0e10cSrcweir pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_HEADERSET );
2005cdf0e10cSrcweir pSet = &pSetItem->GetItemSet();
2006cdf0e10cSrcweir rbHeader = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue();
2007cdf0e10cSrcweir
2008cdf0e10cSrcweir pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_FOOTERSET );
2009cdf0e10cSrcweir pSet = &pSetItem->GetItemSet();
2010cdf0e10cSrcweir rbFooter = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue();
2011cdf0e10cSrcweir }
2012cdf0e10cSrcweir
DdeGetData(const String & rItem,const String & rMimeType,::com::sun::star::uno::Any & rValue)2013cdf0e10cSrcweir long __EXPORT ScDocShell::DdeGetData( const String& rItem,
2014cdf0e10cSrcweir const String& rMimeType,
2015cdf0e10cSrcweir ::com::sun::star::uno::Any & rValue )
2016cdf0e10cSrcweir {
2017cdf0e10cSrcweir if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ) )
2018cdf0e10cSrcweir {
2019cdf0e10cSrcweir if( rItem.EqualsIgnoreCaseAscii( "Format" ) )
2020cdf0e10cSrcweir {
2021cdf0e10cSrcweir ByteString aFmtByte( aDdeTextFmt, gsl_getSystemTextEncoding() );
2022cdf0e10cSrcweir rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
2023cdf0e10cSrcweir (sal_Int8*)aFmtByte.GetBuffer(),
2024cdf0e10cSrcweir aFmtByte.Len() + 1 );
2025cdf0e10cSrcweir return 1;
2026cdf0e10cSrcweir }
2027cdf0e10cSrcweir ScImportExport aObj( &aDocument, rItem );
2028cdf0e10cSrcweir if ( !aObj.IsRef() )
2029cdf0e10cSrcweir return 0; // ungueltiger Bereich
2030cdf0e10cSrcweir
2031cdf0e10cSrcweir if( aDdeTextFmt.GetChar(0) == 'F' )
2032cdf0e10cSrcweir aObj.SetFormulas( sal_True );
2033cdf0e10cSrcweir if( aDdeTextFmt.EqualsAscii( "SYLK" ) ||
2034cdf0e10cSrcweir aDdeTextFmt.EqualsAscii( "FSYLK" ) )
2035cdf0e10cSrcweir {
2036cdf0e10cSrcweir ByteString aData;
2037cdf0e10cSrcweir if( aObj.ExportByteString( aData, gsl_getSystemTextEncoding(),
2038cdf0e10cSrcweir SOT_FORMATSTR_ID_SYLK ) )
2039cdf0e10cSrcweir {
2040cdf0e10cSrcweir rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
2041cdf0e10cSrcweir (sal_Int8*)aData.GetBuffer(),
2042cdf0e10cSrcweir aData.Len() + 1 );
2043cdf0e10cSrcweir return 1;
2044cdf0e10cSrcweir }
2045cdf0e10cSrcweir else
2046cdf0e10cSrcweir return 0;
2047cdf0e10cSrcweir }
2048cdf0e10cSrcweir if( aDdeTextFmt.EqualsAscii( "CSV" ) ||
2049cdf0e10cSrcweir aDdeTextFmt.EqualsAscii( "FCSV" ) )
2050cdf0e10cSrcweir aObj.SetSeparator( ',' );
2051cdf0e10cSrcweir aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2052cdf0e10cSrcweir return aObj.ExportData( rMimeType, rValue ) ? 1 : 0;
2053cdf0e10cSrcweir }
2054cdf0e10cSrcweir
2055cdf0e10cSrcweir ScImportExport aObj( &aDocument, rItem );
2056cdf0e10cSrcweir aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2057cdf0e10cSrcweir if( aObj.IsRef() )
2058cdf0e10cSrcweir return aObj.ExportData( rMimeType, rValue ) ? 1 : 0;
2059cdf0e10cSrcweir return 0;
2060cdf0e10cSrcweir }
2061cdf0e10cSrcweir
DdeSetData(const String & rItem,const String & rMimeType,const::com::sun::star::uno::Any & rValue)2062cdf0e10cSrcweir long __EXPORT ScDocShell::DdeSetData( const String& rItem,
2063cdf0e10cSrcweir const String& rMimeType,
2064cdf0e10cSrcweir const ::com::sun::star::uno::Any & rValue )
2065cdf0e10cSrcweir {
2066cdf0e10cSrcweir if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ))
2067cdf0e10cSrcweir {
2068cdf0e10cSrcweir if( rItem.EqualsIgnoreCaseAscii( "Format" ) )
2069cdf0e10cSrcweir {
2070cdf0e10cSrcweir if ( ScByteSequenceToString::GetString( aDdeTextFmt, rValue, gsl_getSystemTextEncoding() ) )
2071cdf0e10cSrcweir {
2072cdf0e10cSrcweir aDdeTextFmt.ToUpperAscii();
2073cdf0e10cSrcweir return 1;
2074cdf0e10cSrcweir }
2075cdf0e10cSrcweir return 0;
2076cdf0e10cSrcweir }
2077cdf0e10cSrcweir ScImportExport aObj( &aDocument, rItem );
2078cdf0e10cSrcweir if( aDdeTextFmt.GetChar(0) == 'F' )
2079cdf0e10cSrcweir aObj.SetFormulas( sal_True );
2080cdf0e10cSrcweir if( aDdeTextFmt.EqualsAscii( "SYLK" ) ||
2081cdf0e10cSrcweir aDdeTextFmt.EqualsAscii( "FSYLK" ) )
2082cdf0e10cSrcweir {
2083cdf0e10cSrcweir String aData;
2084cdf0e10cSrcweir if ( ScByteSequenceToString::GetString( aData, rValue, gsl_getSystemTextEncoding() ) )
2085cdf0e10cSrcweir {
2086cdf0e10cSrcweir return aObj.ImportString( aData, SOT_FORMATSTR_ID_SYLK ) ? 1 : 0;
2087cdf0e10cSrcweir }
2088cdf0e10cSrcweir return 0;
2089cdf0e10cSrcweir }
2090cdf0e10cSrcweir if( aDdeTextFmt.EqualsAscii( "CSV" ) ||
2091cdf0e10cSrcweir aDdeTextFmt.EqualsAscii( "FCSV" ) )
2092cdf0e10cSrcweir aObj.SetSeparator( ',' );
2093cdf0e10cSrcweir return aObj.ImportData( rMimeType, rValue ) ? 1 : 0;
2094cdf0e10cSrcweir }
2095cdf0e10cSrcweir ScImportExport aObj( &aDocument, rItem );
2096cdf0e10cSrcweir if( aObj.IsRef() )
2097cdf0e10cSrcweir return aObj.ImportData( rMimeType, rValue ) ? 1 : 0;
2098cdf0e10cSrcweir return 0;
2099cdf0e10cSrcweir }
2100cdf0e10cSrcweir
DdeCreateLinkSource(const String & rItem)2101cdf0e10cSrcweir ::sfx2::SvLinkSource* __EXPORT ScDocShell::DdeCreateLinkSource( const String& rItem )
2102cdf0e10cSrcweir {
2103cdf0e10cSrcweir // only check for valid item string - range is parsed again in ScServerObject ctor
2104cdf0e10cSrcweir
2105cdf0e10cSrcweir // named range?
2106cdf0e10cSrcweir String aPos = rItem;
2107cdf0e10cSrcweir ScRangeName* pRange = aDocument.GetRangeName();
2108cdf0e10cSrcweir if( pRange )
2109cdf0e10cSrcweir {
2110cdf0e10cSrcweir sal_uInt16 nPos;
2111cdf0e10cSrcweir if( pRange->SearchName( aPos, nPos ) )
2112cdf0e10cSrcweir {
2113cdf0e10cSrcweir ScRangeData* pData = (*pRange)[ nPos ];
2114cdf0e10cSrcweir if( pData->HasType( RT_REFAREA )
2115cdf0e10cSrcweir || pData->HasType( RT_ABSAREA )
2116cdf0e10cSrcweir || pData->HasType( RT_ABSPOS ) )
2117cdf0e10cSrcweir pData->GetSymbol( aPos ); // continue with the name's contents
2118cdf0e10cSrcweir }
2119cdf0e10cSrcweir }
2120cdf0e10cSrcweir
2121cdf0e10cSrcweir // Address in DDE function must be always parsed as CONV_OOO so that it
2122cdf0e10cSrcweir // would always work regardless of current address convension. We do this
2123cdf0e10cSrcweir // because the address item in a DDE entry is *not* normalized when saved
2124cdf0e10cSrcweir // into ODF.
2125cdf0e10cSrcweir ScRange aRange;
2126cdf0e10cSrcweir bool bValid = ( (aRange.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO ) & SCA_VALID) ||
2127cdf0e10cSrcweir (aRange.aStart.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO) & SCA_VALID) );
2128cdf0e10cSrcweir
2129cdf0e10cSrcweir ScServerObject* pObj = NULL; // NULL = error
2130cdf0e10cSrcweir if ( bValid )
2131cdf0e10cSrcweir pObj = new ScServerObject( this, rItem );
2132cdf0e10cSrcweir
2133cdf0e10cSrcweir // GetLinkManager()->InsertServer() is in the ScServerObject ctor
2134cdf0e10cSrcweir
2135cdf0e10cSrcweir return pObj;
2136cdf0e10cSrcweir }
2137cdf0e10cSrcweir
2138cdf0e10cSrcweir //------------------------------------------------------------------
2139cdf0e10cSrcweir
GetViewData()2140cdf0e10cSrcweir ScViewData* ScDocShell::GetViewData()
2141cdf0e10cSrcweir {
2142cdf0e10cSrcweir SfxViewShell* pCur = SfxViewShell::Current();
2143cdf0e10cSrcweir ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pCur);
2144cdf0e10cSrcweir return pViewSh ? pViewSh->GetViewData() : NULL;
2145cdf0e10cSrcweir }
2146cdf0e10cSrcweir
2147cdf0e10cSrcweir //------------------------------------------------------------------
2148cdf0e10cSrcweir
GetCurTab()2149cdf0e10cSrcweir SCTAB ScDocShell::GetCurTab()
2150cdf0e10cSrcweir {
2151cdf0e10cSrcweir //! this must be made non-static and use a ViewShell from this document!
2152cdf0e10cSrcweir
2153cdf0e10cSrcweir ScViewData* pViewData = GetViewData();
2154cdf0e10cSrcweir
2155cdf0e10cSrcweir return pViewData ? pViewData->GetTabNo() : static_cast<SCTAB>(0);
2156cdf0e10cSrcweir }
2157cdf0e10cSrcweir
GetBestViewShell(sal_Bool bOnlyVisible)2158cdf0e10cSrcweir ScTabViewShell* ScDocShell::GetBestViewShell( sal_Bool bOnlyVisible )
2159cdf0e10cSrcweir {
2160cdf0e10cSrcweir ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
2161cdf0e10cSrcweir // falsches Doc?
2162cdf0e10cSrcweir if( pViewSh && pViewSh->GetViewData()->GetDocShell() != this )
2163cdf0e10cSrcweir pViewSh = NULL;
2164cdf0e10cSrcweir if( !pViewSh )
2165cdf0e10cSrcweir {
2166cdf0e10cSrcweir // 1. ViewShell suchen
2167cdf0e10cSrcweir SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, bOnlyVisible );
2168cdf0e10cSrcweir if( pFrame )
2169cdf0e10cSrcweir {
2170cdf0e10cSrcweir SfxViewShell* p = pFrame->GetViewShell();
2171cdf0e10cSrcweir pViewSh = PTR_CAST(ScTabViewShell,p);
2172cdf0e10cSrcweir }
2173cdf0e10cSrcweir }
2174cdf0e10cSrcweir return pViewSh;
2175cdf0e10cSrcweir }
2176cdf0e10cSrcweir
GetViewBindings()2177cdf0e10cSrcweir SfxBindings* ScDocShell::GetViewBindings()
2178cdf0e10cSrcweir {
2179cdf0e10cSrcweir // used to invalidate slots after changes to this document
2180cdf0e10cSrcweir
2181cdf0e10cSrcweir SfxViewShell* pViewSh = GetBestViewShell();
2182cdf0e10cSrcweir if (pViewSh)
2183cdf0e10cSrcweir return &pViewSh->GetViewFrame()->GetBindings();
2184cdf0e10cSrcweir else
2185cdf0e10cSrcweir return NULL;
2186cdf0e10cSrcweir }
2187cdf0e10cSrcweir
2188cdf0e10cSrcweir //------------------------------------------------------------------
2189cdf0e10cSrcweir
GetShellByNum(sal_uInt16 nDocNo)2190cdf0e10cSrcweir ScDocShell* ScDocShell::GetShellByNum( sal_uInt16 nDocNo ) // static
2191cdf0e10cSrcweir {
2192cdf0e10cSrcweir ScDocShell* pFound = NULL;
2193cdf0e10cSrcweir SfxObjectShell* pShell = SfxObjectShell::GetFirst();
2194cdf0e10cSrcweir sal_uInt16 nShellCnt = 0;
2195cdf0e10cSrcweir
2196cdf0e10cSrcweir while ( pShell && !pFound )
2197cdf0e10cSrcweir {
2198cdf0e10cSrcweir if ( pShell->Type() == TYPE(ScDocShell) )
2199cdf0e10cSrcweir {
2200cdf0e10cSrcweir if ( nShellCnt == nDocNo )
2201cdf0e10cSrcweir pFound = (ScDocShell*) pShell;
2202cdf0e10cSrcweir else
2203cdf0e10cSrcweir ++nShellCnt;
2204cdf0e10cSrcweir }
2205cdf0e10cSrcweir pShell = SfxObjectShell::GetNext( *pShell );
2206cdf0e10cSrcweir }
2207cdf0e10cSrcweir
2208cdf0e10cSrcweir return pFound;
2209cdf0e10cSrcweir }
2210cdf0e10cSrcweir
2211cdf0e10cSrcweir //------------------------------------------------------------------
2212cdf0e10cSrcweir
IMPL_LINK(ScDocShell,DialogClosedHdl,sfx2::FileDialogHelper *,_pFileDlg)2213cdf0e10cSrcweir IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
2214cdf0e10cSrcweir {
2215cdf0e10cSrcweir DBG_ASSERT( _pFileDlg, "ScDocShell::DialogClosedHdl(): no file dialog" );
2216cdf0e10cSrcweir DBG_ASSERT( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
2217cdf0e10cSrcweir
2218cdf0e10cSrcweir if ( ERRCODE_NONE == _pFileDlg->GetError() )
2219cdf0e10cSrcweir {
2220cdf0e10cSrcweir sal_uInt16 nSlot = pImpl->pRequest->GetSlot();
2221cdf0e10cSrcweir SfxMedium* pMed = pImpl->pDocInserter->CreateMedium();
2222cdf0e10cSrcweir // #i87094# If a .odt was selected pMed is NULL.
2223cdf0e10cSrcweir if (pMed)
2224cdf0e10cSrcweir {
2225cdf0e10cSrcweir pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
2226cdf0e10cSrcweir if ( SID_DOCUMENT_COMPARE == nSlot )
2227cdf0e10cSrcweir {
2228cdf0e10cSrcweir if ( pMed->GetFilter() )
2229cdf0e10cSrcweir pImpl->pRequest->AppendItem(
2230cdf0e10cSrcweir SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
2231cdf0e10cSrcweir String sOptions = ScDocumentLoader::GetOptions( *pMed );
2232cdf0e10cSrcweir if ( sOptions.Len() > 0 )
2233cdf0e10cSrcweir pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2234cdf0e10cSrcweir }
2235cdf0e10cSrcweir const SfxPoolItem* pItem = NULL;
2236cdf0e10cSrcweir SfxItemSet* pSet = pMed->GetItemSet();
2237cdf0e10cSrcweir if ( pSet &&
2238cdf0e10cSrcweir pSet->GetItemState( SID_VERSION, sal_True, &pItem ) == SFX_ITEM_SET &&
2239cdf0e10cSrcweir pItem->ISA( SfxInt16Item ) )
2240cdf0e10cSrcweir {
2241cdf0e10cSrcweir pImpl->pRequest->AppendItem( *pItem );
2242cdf0e10cSrcweir }
2243cdf0e10cSrcweir
2244cdf0e10cSrcweir Execute( *(pImpl->pRequest) );
2245cdf0e10cSrcweir }
2246cdf0e10cSrcweir }
2247cdf0e10cSrcweir
2248cdf0e10cSrcweir pImpl->bIgnoreLostRedliningWarning = false;
2249cdf0e10cSrcweir return 0;
2250cdf0e10cSrcweir }
2251cdf0e10cSrcweir
2252cdf0e10cSrcweir //------------------------------------------------------------------
2253cdf0e10cSrcweir
EnableSharedSettings(bool bEnable)2254cdf0e10cSrcweir void ScDocShell::EnableSharedSettings( bool bEnable )
2255cdf0e10cSrcweir {
2256cdf0e10cSrcweir SetDocumentModified();
2257cdf0e10cSrcweir
2258cdf0e10cSrcweir if ( bEnable )
2259cdf0e10cSrcweir {
2260cdf0e10cSrcweir aDocument.EndChangeTracking();
2261cdf0e10cSrcweir aDocument.StartChangeTracking();
2262cdf0e10cSrcweir
2263cdf0e10cSrcweir // hide accept or reject changes dialog
2264cdf0e10cSrcweir sal_uInt16 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
2265cdf0e10cSrcweir SfxViewFrame* pViewFrame = SfxViewFrame::Current();
2266cdf0e10cSrcweir if ( pViewFrame && pViewFrame->HasChildWindow( nId ) )
2267cdf0e10cSrcweir {
2268cdf0e10cSrcweir pViewFrame->ToggleChildWindow( nId );
2269cdf0e10cSrcweir SfxBindings* pBindings = GetViewBindings();
2270cdf0e10cSrcweir if ( pBindings )
2271cdf0e10cSrcweir {
2272cdf0e10cSrcweir pBindings->Invalidate( FID_CHG_ACCEPT );
2273cdf0e10cSrcweir }
2274cdf0e10cSrcweir }
2275cdf0e10cSrcweir }
2276cdf0e10cSrcweir else
2277cdf0e10cSrcweir {
2278cdf0e10cSrcweir aDocument.EndChangeTracking();
2279cdf0e10cSrcweir }
2280cdf0e10cSrcweir
2281cdf0e10cSrcweir ScChangeViewSettings aChangeViewSet;
2282cdf0e10cSrcweir aChangeViewSet.SetShowChanges( sal_False );
2283cdf0e10cSrcweir aDocument.SetChangeViewSettings( aChangeViewSet );
2284cdf0e10cSrcweir }
2285cdf0e10cSrcweir
LoadSharedDocument()2286cdf0e10cSrcweir uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument()
2287cdf0e10cSrcweir {
2288cdf0e10cSrcweir uno::Reference< frame::XModel > xModel;
2289cdf0e10cSrcweir try
2290cdf0e10cSrcweir {
2291cdf0e10cSrcweir SC_MOD()->SetInSharedDocLoading( true );
2292cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory(
2293cdf0e10cSrcweir ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
2294cdf0e10cSrcweir uno::Reference< frame::XComponentLoader > xLoader(
2295cdf0e10cSrcweir xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ),
2296cdf0e10cSrcweir uno::UNO_QUERY_THROW );
2297cdf0e10cSrcweir uno::Sequence < beans::PropertyValue > aArgs( 1 );
2298cdf0e10cSrcweir aArgs[0].Name = ::rtl::OUString::createFromAscii( "Hidden" );
2299cdf0e10cSrcweir aArgs[0].Value <<= sal_True;
2300cdf0e10cSrcweir
2301cdf0e10cSrcweir if ( GetMedium() )
2302cdf0e10cSrcweir {
2303cdf0e10cSrcweir SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False);
2304cdf0e10cSrcweir if ( pPasswordItem && pPasswordItem->GetValue().Len() )
2305cdf0e10cSrcweir {
2306cdf0e10cSrcweir aArgs.realloc( 2 );
2307cdf0e10cSrcweir aArgs[1].Name = ::rtl::OUString::createFromAscii( "Password" );
2308cdf0e10cSrcweir aArgs[1].Value <<= ::rtl::OUString( pPasswordItem->GetValue() );
2309cdf0e10cSrcweir }
2310cdf0e10cSrcweir }
2311cdf0e10cSrcweir
2312cdf0e10cSrcweir xModel.set(
2313cdf0e10cSrcweir xLoader->loadComponentFromURL( GetSharedFileURL(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, aArgs ),
2314cdf0e10cSrcweir uno::UNO_QUERY_THROW );
2315cdf0e10cSrcweir SC_MOD()->SetInSharedDocLoading( false );
2316cdf0e10cSrcweir }
2317cdf0e10cSrcweir catch ( uno::Exception& )
2318cdf0e10cSrcweir {
2319cdf0e10cSrcweir DBG_ERROR( "ScDocShell::LoadSharedDocument(): caught exception\n" );
2320cdf0e10cSrcweir SC_MOD()->SetInSharedDocLoading( false );
2321cdf0e10cSrcweir try
2322cdf0e10cSrcweir {
2323cdf0e10cSrcweir uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
2324cdf0e10cSrcweir xClose->close( sal_True );
2325cdf0e10cSrcweir return uno::Reference< frame::XModel >();
2326cdf0e10cSrcweir }
2327cdf0e10cSrcweir catch ( uno::Exception& )
2328cdf0e10cSrcweir {
2329cdf0e10cSrcweir return uno::Reference< frame::XModel >();
2330cdf0e10cSrcweir }
2331cdf0e10cSrcweir }
2332cdf0e10cSrcweir return xModel;
2333cdf0e10cSrcweir }
2334