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