update dev300-m58
[ooovba.git] / sc / source / ui / docshell / docsh4.cxx
blob2fb37e0e1c0093c52c71b443e00c6082cb9d55e7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: docsh4.cxx,v $
10 * $Revision: 1.61.30.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 #include <com/sun/star/embed/XEmbeddedObject.hpp>
36 #include <com/sun/star/frame/XComponentLoader.hpp>
39 using namespace ::com::sun::star;
41 // INCLUDE ---------------------------------------------------------------
42 #if STLPORT_VERSION>=321
43 #include <math.h> // prevent conflict between exception and std::exception
44 #endif
46 #include "scitems.hxx"
47 #include <sfx2/fcontnr.hxx>
48 #include <svx/eeitem.hxx>
50 #include <sfx2/app.hxx>
51 #include <sfx2/bindings.hxx>
52 #include <sfx2/docfile.hxx>
53 #include <sfx2/docfilt.hxx>
54 #include <svtools/ehdl.hxx>
55 #include <basic/sbxcore.hxx>
56 #include <sfx2/printer.hxx>
57 #include <sfx2/request.hxx>
58 #include <svtools/sfxecode.hxx>
59 #include <sfx2/topfrm.hxx>
60 #include <svx/ofaitem.hxx>
61 #include <sot/formats.hxx>
62 #include <svtools/printdlg.hxx>
63 #include <svtools/whiter.hxx>
64 #include <vcl/msgbox.hxx>
65 #include <vcl/waitobj.hxx>
66 #include <tools/multisel.hxx>
67 #include <svx/drawitem.hxx>
68 #include <svx/fmview.hxx>
69 #include <svx/pageitem.hxx>
70 #include <svx/svditer.hxx>
71 #include <svx/svdpage.hxx>
72 #include <svx/fmshell.hxx>
73 #include <sfx2/passwd.hxx>
74 #include <sfx2/filedlghelper.hxx>
75 #include <sfx2/docinsert.hxx>
76 #include <svtools/PasswordHelper.hxx>
77 #include <svtools/documentlockfile.hxx>
78 #include <svtools/sharecontrolfile.hxx>
80 #include <comphelper/processfactory.hxx>
81 #include "docuno.hxx"
83 #include <com/sun/star/sdbc/XResultSet.hpp>
84 #include "docsh.hxx"
85 #include "docshimp.hxx"
86 #include "docfunc.hxx"
87 #include "sc.hrc"
88 #include "stlsheet.hxx"
89 #include "stlpool.hxx"
90 #include "appoptio.hxx"
91 #include "globstr.hrc"
92 #include "global.hxx"
93 //CHINA001 #include "styledlg.hxx"
94 //CHINA001 #include "hfedtdlg.hxx"
95 #include "dbdocfun.hxx"
96 #include "printfun.hxx" // DrawToDev
97 #include "viewdata.hxx"
98 #include "tabvwsh.hxx"
99 #include "impex.hxx"
100 #include "attrib.hxx"
101 //CHINA001 #include "corodlg.hxx"
102 #include "undodat.hxx"
103 #include "autostyl.hxx"
104 #include "undocell.hxx"
105 #include "undotab.hxx"
106 #include "inputhdl.hxx"
107 #include "dbcolect.hxx"
108 #include "servobj.hxx"
109 #include "rangenam.hxx"
110 #include "scmod.hxx"
111 //CHINA001 #include "scendlg.hxx"
112 #include "chgviset.hxx"
113 #include "reffact.hxx"
114 #include "chartlis.hxx"
115 #include "waitoff.hxx"
116 #include "tablink.hxx" // ScDocumentLoader statics
117 #include "drwlayer.hxx"
118 #include "docoptio.hxx"
119 #include "undostyl.hxx"
120 #include "rangeseq.hxx"
121 #include "chgtrack.hxx"
122 #include "printopt.hxx"
123 #include <com/sun/star/document/UpdateDocMode.hpp>
124 #include "scresid.hxx" //add by CHINA001
125 #include "scabstdlg.hxx" //CHINA001
126 #include "externalrefmgr.hxx"
128 #include "sharedocdlg.hxx"
129 #include "conditio.hxx"
131 //------------------------------------------------------------------
133 #define IS_SHARE_HEADER(set) \
134 ((SfxBoolItem&) \
135 ((SvxSetItem&)(set).Get(ATTR_PAGE_HEADERSET)).GetItemSet(). \
136 Get(ATTR_PAGE_SHARED)).GetValue()
138 #define IS_SHARE_FOOTER(set) \
139 ((SfxBoolItem&) \
140 ((SvxSetItem&)(set).Get(ATTR_PAGE_FOOTERSET)).GetItemSet(). \
141 Get(ATTR_PAGE_SHARED)).GetValue()
143 #define IS_AVAILABLE(WhichId,ppItem) \
144 (pReqArgs->GetItemState((WhichId), TRUE, ppItem ) == SFX_ITEM_SET)
146 #define SC_PREVIEW_SIZE_X 10000
147 #define SC_PREVIEW_SIZE_Y 12400
150 //------------------------------------------------------------------
152 void ScDocShell::Execute( SfxRequest& rReq )
154 // SID_SC_RANGE (Range),
155 // SID_SC_CELLTEXT (CellText),
156 // SID_SC_CELLS (Cells) - removed (old Basic)
158 const SfxItemSet* pReqArgs = rReq.GetArgs();
159 SfxBindings* pBindings = GetViewBindings();
160 BOOL bUndo (aDocument.IsUndoEnabled());
162 USHORT nSlot = rReq.GetSlot();
163 switch ( nSlot )
165 case SID_SC_SETTEXT:
167 const SfxPoolItem* pColItem;
168 const SfxPoolItem* pRowItem;
169 const SfxPoolItem* pTabItem;
170 const SfxPoolItem* pTextItem;
171 if( pReqArgs && IS_AVAILABLE( FN_PARAM_1, &pColItem ) &&
172 IS_AVAILABLE( FN_PARAM_2, &pRowItem ) &&
173 IS_AVAILABLE( FN_PARAM_3, &pTabItem ) &&
174 IS_AVAILABLE( SID_SC_SETTEXT, &pTextItem ) )
176 // Parameter sind 1-based !!!
177 SCCOL nCol = ((SfxInt16Item*)pColItem)->GetValue() - 1;
178 SCROW nRow = ((SfxInt32Item*)pRowItem)->GetValue() - 1;
179 SCTAB nTab = ((SfxInt16Item*)pTabItem)->GetValue() - 1;
181 SCTAB nTabCount = aDocument.GetTableCount();
182 if ( ValidCol(nCol) && ValidRow(nRow) && ValidTab(nTab,nTabCount) )
184 if ( aDocument.IsBlockEditable( nTab, nCol,nRow, nCol, nRow ) )
186 String aVal = ((const SfxStringItem*)pTextItem)->GetValue();
187 aDocument.SetString( nCol, nRow, nTab, aVal );
189 PostPaintCell( nCol, nRow, nTab );
190 SetDocumentModified();
192 rReq.Done();
193 break;
195 else // geschuetzte Zelle
197 SbxBase::SetError( SbxERR_BAD_PARAMETER ); //! welchen Fehler ?
198 break;
202 SbxBase::SetError( SbxERR_NO_OBJECT );
204 break;
207 // SID_SBA_QRY_CHANGETARGET gibts nicht mehr - auch in idl raus
209 case SID_SBA_IMPORT:
211 if (pReqArgs)
213 const sal_Unicode cSbaSep = 11; // Trennzeichen
215 const SfxPoolItem* pItem;
216 String sSbaData, sTarget;
217 if ( pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET )
218 sSbaData = ((const SfxStringItem*)pItem)->GetValue();
219 if ( pReqArgs->GetItemState( FN_PARAM_1, TRUE, &pItem ) == SFX_ITEM_SET )
220 sTarget = ((const SfxStringItem*)pItem)->GetValue();
222 BOOL bIsNewArea = TRUE; // Default TRUE (keine Nachfrage)
223 if ( pReqArgs->GetItemState( FN_PARAM_2, TRUE, &pItem ) == SFX_ITEM_SET )
224 bIsNewArea = ((const SfxBoolItem*)pItem)->GetValue();
226 ::com::sun::star::uno::Reference<
227 ::com::sun::star::sdbc::XResultSet > xResultSet;
228 if ( pReqArgs->GetItemState( FN_PARAM_3, FALSE, &pItem ) == SFX_ITEM_SET && pItem )
229 xResultSet.set(((const SfxUsrAnyItem*)pItem)->GetValue(),::com::sun::star::uno::UNO_QUERY);
231 String sDBName = sSbaData.GetToken(0,cSbaSep); // Datenbankname
232 String sDBTable = sSbaData.GetToken(1,cSbaSep); // Tabellen- oder Query-Name
233 String sTabFlag = sSbaData.GetToken(2,cSbaSep);
234 String sDBSql = sSbaData.GetToken(3,cSbaSep); // SQL im Klartext
236 BYTE nType = ScDbTable; // "0" oder "1"
237 if ( sTabFlag.EqualsAscii("0") ) // "0" = Query, "1" = Table (Default)
238 nType = ScDbQuery;
240 SbaSelectionListRef pSelectionList = new SbaSelectionList;
241 xub_StrLen nCount = sSbaData.GetTokenCount(cSbaSep);
243 for (xub_StrLen i = 4; i < nCount; i++)
245 String aSelItem = sSbaData.GetToken(i,cSbaSep);
246 if (aSelItem.Len())
248 void *pPtr = (void*)aSelItem.ToInt32();
249 pSelectionList->Insert( pPtr, LIST_APPEND );
253 // bei Bedarf neuen Datenbankbereich anlegen
254 BOOL bMakeArea = FALSE;
255 if (bIsNewArea)
257 ScDBCollection* pDBColl = aDocument.GetDBCollection();
258 USHORT nDummy;
259 if ( !pDBColl || !pDBColl->SearchName( sTarget, nDummy ) )
261 ScAddress aPos;
262 if ( aPos.Parse( sTarget, &aDocument, aDocument.GetAddressConvention() ) & SCA_VALID )
264 bMakeArea = TRUE;
265 if (bUndo)
267 String aStrImport = ScGlobal::GetRscString( STR_UNDO_IMPORTDATA );
268 GetUndoManager()->EnterListAction( aStrImport, aStrImport );
271 ScDBData* pDBData = GetDBData( ScRange(aPos), SC_DB_IMPORT, FALSE );
272 DBG_ASSERT(pDBData, "kann DB-Daten nicht anlegen");
273 sTarget = pDBData->GetName();
278 // nachfragen, bevor alter DB-Bereich ueberschrieben wird
279 BOOL bDo = TRUE;
280 if (!bIsNewArea)
282 String aTemplate = ScGlobal::GetRscString( STR_IMPORT_REPLACE );
283 String aMessage = aTemplate.GetToken( 0, '#' );
284 aMessage += sTarget;
285 aMessage += aTemplate.GetToken( 1, '#' );
287 QueryBox aBox( 0, WinBits(WB_YES_NO | WB_DEF_YES), aMessage );
288 bDo = ( aBox.Execute() == RET_YES );
291 if (bDo)
293 ScDBDocFunc(*this).UpdateImport( sTarget, sDBName,
294 sDBTable, sDBSql, TRUE, nType, xResultSet,
295 pSelectionList );
296 rReq.Done();
298 // UpdateImport aktualisiert auch die internen Operationen
300 else
301 rReq.Ignore();
303 if ( bMakeArea && bUndo)
304 GetUndoManager()->LeaveListAction();
306 else
308 DBG_ERROR( "arguments expected" );
311 break;
313 case SID_CHART_SOURCE:
314 case SID_CHART_ADDSOURCE:
315 if (pReqArgs)
317 ScDocument* pDoc = GetDocument();
318 // BOOL bUndo (pDoc->IsUndoEnabled());
319 const SfxPoolItem* pItem;
320 String aChartName, aRangeName;
322 ScRange aSingleRange;
323 ScRangeListRef aRangeListRef;
324 BOOL bMultiRange = FALSE;
326 BOOL bColHeaders = TRUE;
327 BOOL bRowHeaders = TRUE;
328 BOOL bColInit = FALSE;
329 BOOL bRowInit = FALSE;
330 BOOL bAddRange = (nSlot == SID_CHART_ADDSOURCE);
332 if( IS_AVAILABLE( SID_CHART_NAME, &pItem ) )
333 aChartName = ((const SfxStringItem*)pItem)->GetValue();
335 if( IS_AVAILABLE( SID_CHART_SOURCE, &pItem ) )
336 aRangeName = ((const SfxStringItem*)pItem)->GetValue();
338 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) )
340 bColHeaders = ((const SfxBoolItem*)pItem)->GetValue();
341 bColInit = TRUE;
343 if( IS_AVAILABLE( FN_PARAM_2, &pItem ) )
345 bRowHeaders = ((const SfxBoolItem*)pItem)->GetValue();
346 bRowInit = TRUE;
349 ScAddress::Details aDetails(pDoc->GetAddressConvention(), 0, 0);
350 BOOL bValid = ( aSingleRange.ParseAny( aRangeName, pDoc, aDetails ) & SCA_VALID ) != 0;
351 if (!bValid)
353 aRangeListRef = new ScRangeList;
354 aRangeListRef->Parse( aRangeName, pDoc );
355 if ( aRangeListRef->Count() )
357 bMultiRange = TRUE;
358 aSingleRange = *aRangeListRef->GetObject(0); // fuer Header
359 bValid = TRUE;
361 else
362 aRangeListRef.Clear();
365 ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
366 if (pViewSh && bValid && aChartName.Len() != 0 )
368 Window* pParent = pViewSh->GetDialogParent();
370 SCCOL nCol1 = aSingleRange.aStart.Col();
371 SCROW nRow1 = aSingleRange.aStart.Row();
372 SCCOL nCol2 = aSingleRange.aEnd.Col();
373 SCROW nRow2 = aSingleRange.aEnd.Row();
374 SCTAB nTab = aSingleRange.aStart.Tab();
376 //! immer oder gar nicht begrenzen ???
377 if (!bMultiRange)
378 aDocument.LimitChartArea( nTab, nCol1,nRow1, nCol2,nRow2 );
380 // Dialog fuer Spalten/Zeilenkoepfe
381 BOOL bOk = TRUE;
382 if ( !bAddRange && ( !bColInit || !bRowInit ) )
384 // Spalten/Zeilenkoepfe testen wie in chartarr
385 if (!bColInit)
387 for (SCCOL i=nCol1; i<=nCol2 && bColHeaders; i++)
388 if (aDocument.HasValueData( i, nRow1, nTab ))
389 bColHeaders = FALSE;
391 if (!bRowInit)
393 for (SCROW i=nRow1; i<=nRow2 && bRowHeaders; i++)
394 if (aDocument.HasValueData( nCol1, i, nTab ))
395 bRowHeaders = FALSE;
398 //CHINA001 ScColRowLabelDlg aDlg( pParent, bRowHeaders, bColHeaders );
399 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
400 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
402 AbstractScColRowLabelDlg* pDlg = pFact->CreateScColRowLabelDlg( pParent, RID_SCDLG_CHARTCOLROW, bRowHeaders, bColHeaders);
403 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
404 if ( pDlg->Execute() == RET_OK ) //CHINA001 if ( aDlg.Execute() == RET_OK )
406 bColHeaders = pDlg->IsRow(); //CHINA001 bColHeaders = aDlg.IsRow(); // Spaltenkoepfe = 1. Zeile
407 bRowHeaders = pDlg->IsCol(); //CHINA001 bRowHeaders = aDlg.IsCol();
409 rReq.AppendItem(SfxBoolItem(FN_PARAM_1, bColHeaders));
410 rReq.AppendItem(SfxBoolItem(FN_PARAM_2, bRowHeaders));
412 else
413 bOk = FALSE;
414 delete pDlg; //CHINA001
417 if (bOk) // ausfuehren
419 if (bMultiRange)
421 if (bUndo)
423 GetUndoManager()->AddUndoAction(
424 new ScUndoChartData( this, aChartName, aRangeListRef,
425 bColHeaders, bRowHeaders, bAddRange ) );
427 aDocument.UpdateChartArea( aChartName, aRangeListRef,
428 bColHeaders, bRowHeaders, bAddRange );
430 else
432 ScRange aNewRange( nCol1,nRow1,nTab, nCol2,nRow2,nTab );
433 if (bUndo)
435 GetUndoManager()->AddUndoAction(
436 new ScUndoChartData( this, aChartName, aNewRange,
437 bColHeaders, bRowHeaders, bAddRange ) );
439 aDocument.UpdateChartArea( aChartName, aNewRange,
440 bColHeaders, bRowHeaders, bAddRange );
444 else
446 DBG_ERROR("UpdateChartArea: keine ViewShell oder falsche Daten");
448 rReq.Done();
450 else
452 DBG_ERROR("SID_CHART_SOURCE ohne Argumente");
454 break;
456 case FID_AUTO_CALC:
458 BOOL bNewVal;
459 const SfxPoolItem* pItem;
460 if ( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( nSlot, TRUE, &pItem ) )
461 bNewVal = ((const SfxBoolItem*)pItem)->GetValue();
462 else
463 bNewVal = !aDocument.GetAutoCalc(); // Toggle fuer Menue
464 aDocument.SetAutoCalc( bNewVal );
465 SetDocumentModified();
466 if (pBindings)
468 pBindings->Invalidate( FID_AUTO_CALC );
469 // pBindings->Invalidate( FID_RECALC ); // jetzt immer enabled
471 rReq.AppendItem( SfxBoolItem( FID_AUTO_CALC, bNewVal ) );
472 rReq.Done();
474 break;
475 case FID_RECALC:
476 DoRecalc( rReq.IsAPI() );
477 rReq.Done();
478 break;
479 case FID_HARD_RECALC:
480 DoHardRecalc( rReq.IsAPI() );
481 rReq.Done();
482 break;
483 case SID_UPDATETABLINKS:
485 ScDocument* pDoc = GetDocument();
487 ScLkUpdMode nSet=pDoc->GetLinkMode();
489 USHORT nDlgRet=RET_NO;
490 if(nSet==LM_UNKNOWN)
492 ScAppOptions aAppOptions=SC_MOD()->GetAppOptions();
493 nSet=aAppOptions.GetLinkMode();
496 if (nCanUpdate == com::sun::star::document::UpdateDocMode::NO_UPDATE)
497 nSet = LM_NEVER;
498 else if (nCanUpdate == com::sun::star::document::UpdateDocMode::QUIET_UPDATE &&
499 nSet == LM_ON_DEMAND)
500 nSet = LM_NEVER;
501 else if (nCanUpdate == com::sun::star::document::UpdateDocMode::FULL_UPDATE)
502 nSet = LM_ALWAYS;
504 if(nSet==LM_ON_DEMAND)
506 QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
507 ScGlobal::GetRscString(STR_RELOAD_TABLES) );
509 nDlgRet=aBox.Execute();
512 if (nDlgRet == RET_YES || nSet==LM_ALWAYS)
514 ReloadTabLinks();
515 aDocument.UpdateExternalRefLinks();
516 aDocument.UpdateDdeLinks();
517 aDocument.UpdateAreaLinks();
519 //! Test, ob Fehler
520 rReq.Done();
522 else
523 rReq.Ignore();
525 break;
527 case SID_REIMPORT_AFTER_LOAD:
529 // wird nach dem Laden aufgerufen, wenn DB-Bereiche mit
530 // weggelassenen Daten enthalten sind
532 BOOL bDone = FALSE;
533 ScDBCollection* pDBColl = aDocument.GetDBCollection();
535 if ((nCanUpdate != com::sun::star::document::UpdateDocMode::NO_UPDATE) &&
536 (nCanUpdate != com::sun::star::document::UpdateDocMode::QUIET_UPDATE))
538 ScRange aRange;
539 ScTabViewShell* pViewSh = GetBestViewShell();
540 DBG_ASSERT(pViewSh,"SID_REIMPORT_AFTER_LOAD: keine View");
541 if (pViewSh && pDBColl)
543 QueryBox aBox( GetActiveDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES),
544 ScGlobal::GetRscString(STR_REIMPORT_AFTER_LOAD) );
545 if (aBox.Execute() == RET_YES)
547 for (USHORT i=0; i<pDBColl->GetCount(); i++)
549 ScDBData* pDBData = (*pDBColl)[i];
550 if ( pDBData->IsStripData() &&
551 pDBData->HasImportParam() && !pDBData->HasImportSelection() )
553 pDBData->GetArea(aRange);
554 pViewSh->MarkRange(aRange);
556 // Import und interne Operationen wie SID_REFRESH_DBAREA
557 // (Abfrage auf Import hier nicht noetig)
559 ScImportParam aImportParam;
560 pDBData->GetImportParam( aImportParam );
561 BOOL bContinue = pViewSh->ImportData( aImportParam );
562 pDBData->SetImportParam( aImportParam );
564 // markieren (Groesse kann sich geaendert haben)
565 pDBData->GetArea(aRange);
566 pViewSh->MarkRange(aRange);
568 if ( bContinue ) // #41905# Fehler beim Import -> Abbruch
570 // interne Operationen, wenn welche gespeichert
572 if ( pDBData->HasQueryParam() || pDBData->HasSortParam() ||
573 pDBData->HasSubTotalParam() )
574 pViewSh->RepeatDB();
576 // Pivottabellen die den Bereich als Quelldaten haben
578 RefreshPivotTables(aRange);
582 bDone = TRUE;
587 if ( !bDone && pDBColl )
589 // wenn nicht, dann aber die abhaengigen Formeln updaten
590 //! auch fuer einzelne Bereiche, die nicht aktualisiert werden koennen
592 aDocument.CalcAll(); //! nur die abhaengigen
593 PostDataChanged();
596 if (bDone)
597 rReq.Done();
598 else
599 rReq.Ignore();
601 break;
604 case SID_AUTO_STYLE:
605 DBG_ERROR("use ScAutoStyleHint instead of SID_AUTO_STYLE");
606 break;
608 case SID_GET_COLORTABLE:
610 // passende ColorTable ist per PutItem gesetzt worden
611 SvxColorTableItem* pColItem = (SvxColorTableItem*)GetItem(SID_COLOR_TABLE);
612 XColorTable* pTable = pColItem->GetColorTable();
613 rReq.SetReturnValue(OfaPtrItem(SID_GET_COLORTABLE, pTable));
615 break;
617 case FID_CHG_RECORD:
619 ScDocument* pDoc = GetDocument();
620 if(pDoc!=NULL)
622 // get argument (recorded macro)
623 SFX_REQUEST_ARG( rReq, pItem, SfxBoolItem, FID_CHG_RECORD, sal_False );
624 BOOL bDo = TRUE;
626 // xmlsec05/06:
627 // getting real parent window when called from Security-Options TP
628 Window* pParent = NULL;
629 const SfxPoolItem* pParentItem;
630 if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_PARENTWINDOW, FALSE, &pParentItem ) )
631 pParent = ( Window* ) ( ( const OfaPtrItem* ) pParentItem )->GetValue();
633 // desired state
634 ScChangeTrack* pChangeTrack = pDoc->GetChangeTrack();
635 BOOL bActivateTracking = (pChangeTrack == 0); // toggle
636 if ( pItem )
637 bActivateTracking = pItem->GetValue(); // from argument
639 if ( !bActivateTracking )
641 if ( !pItem )
643 // no dialog on playing the macro
644 WarningBox aBox( pParent ? pParent : GetActiveDialogParent(),
645 WinBits(WB_YES_NO | WB_DEF_NO),
646 ScGlobal::GetRscString( STR_END_REDLINING ) );
647 bDo = ( aBox.Execute() == RET_YES );
650 if ( bDo )
652 if ( pChangeTrack->IsProtected() )
653 bDo = ExecuteChangeProtectionDialog( NULL );
654 if ( bDo )
656 pDoc->EndChangeTracking();
657 PostPaintGridAll();
661 else
663 pDoc->StartChangeTracking();
664 ScChangeViewSettings aChangeViewSet;
665 aChangeViewSet.SetShowChanges(TRUE);
666 pDoc->SetChangeViewSettings(aChangeViewSet);
669 if ( bDo )
671 // update "accept changes" dialog
672 //! notify all views
673 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
674 if ( pViewFrm && pViewFrm->HasChildWindow(FID_CHG_ACCEPT) )
676 SfxChildWindow* pChild = pViewFrm->GetChildWindow(FID_CHG_ACCEPT);
677 if (pChild)
679 ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg();
683 // Slots invalidieren
684 if (pBindings)
685 pBindings->InvalidateAll(FALSE);
686 if ( !pItem )
687 rReq.AppendItem( SfxBoolItem( FID_CHG_RECORD, bActivateTracking ) );
688 rReq.Done();
690 else
691 rReq.Ignore();
694 break;
696 case SID_CHG_PROTECT :
698 Window* pParent = NULL;
699 const SfxPoolItem* pParentItem;
700 if( pReqArgs && SFX_ITEM_SET == pReqArgs->GetItemState( SID_ATTR_PARENTWINDOW, FALSE, &pParentItem ) )
701 pParent = ( Window* ) ( ( const OfaPtrItem* ) pParentItem )->GetValue();
702 if ( ExecuteChangeProtectionDialog( pParent ) )
704 rReq.Done();
705 SetDocumentModified();
707 else
708 rReq.Ignore();
710 break;
712 case SID_DOCUMENT_MERGE:
713 case SID_DOCUMENT_COMPARE:
715 BOOL bDo = TRUE;
716 ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
717 if ( pChangeTrack && !pImpl->bIgnoreLostRedliningWarning )
719 if ( nSlot == SID_DOCUMENT_COMPARE )
720 { //! old changes trace will be lost
721 WarningBox aBox( GetActiveDialogParent(),
722 WinBits(WB_YES_NO | WB_DEF_NO),
723 ScGlobal::GetRscString( STR_END_REDLINING ) );
724 if( aBox.Execute() == RET_YES )
725 bDo = ExecuteChangeProtectionDialog( NULL, TRUE );
726 else
727 bDo = FALSE;
729 else // merge might reject some actions
730 bDo = ExecuteChangeProtectionDialog( NULL, TRUE );
732 if ( !bDo )
734 rReq.Ignore();
735 break;
737 SfxApplication* pApp = SFX_APP();
738 const SfxPoolItem* pItem;
739 SfxMedium* pMed = NULL;
740 if ( pReqArgs &&
741 pReqArgs->GetItemState( SID_FILE_NAME, TRUE, &pItem ) == SFX_ITEM_SET &&
742 pItem->ISA(SfxStringItem) )
744 String aFileName = ((const SfxStringItem*)pItem)->GetValue();
746 String aFilterName;
747 if ( pReqArgs->GetItemState( SID_FILTER_NAME, TRUE, &pItem ) == SFX_ITEM_SET &&
748 pItem->ISA(SfxStringItem) )
750 aFilterName = ((const SfxStringItem*)pItem)->GetValue();
752 String aOptions;
753 if ( pReqArgs->GetItemState( SID_FILE_FILTEROPTIONS, TRUE, &pItem ) == SFX_ITEM_SET &&
754 pItem->ISA(SfxStringItem) )
756 aOptions = ((const SfxStringItem*)pItem)->GetValue();
758 short nVersion = 0;
759 if ( pReqArgs->GetItemState( SID_VERSION, TRUE, &pItem ) == SFX_ITEM_SET &&
760 pItem->ISA(SfxInt16Item) )
762 nVersion = ((const SfxInt16Item*)pItem)->GetValue();
765 // kein Filter angegeben -> Detection
766 if ( !aFilterName.Len() )
767 ScDocumentLoader::GetFilterName( aFileName, aFilterName, aOptions, TRUE, FALSE );
769 // filter name from dialog contains application prefix,
770 // GetFilter needs name without the prefix.
771 ScDocumentLoader::RemoveAppPrefix( aFilterName );
773 const SfxFilter* pFilter = ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName );
774 SfxItemSet* pSet = new SfxAllItemSet( pApp->GetPool() );
775 if ( aOptions.Len() )
776 pSet->Put( SfxStringItem( SID_FILE_FILTEROPTIONS, aOptions ) );
777 if ( nVersion != 0 )
778 pSet->Put( SfxInt16Item( SID_VERSION, nVersion ) );
779 pMed = new SfxMedium( aFileName, STREAM_STD_READ, FALSE, pFilter, pSet );
781 else
783 // start file dialog asynchronous
784 pImpl->bIgnoreLostRedliningWarning = true;
785 delete pImpl->pRequest;
786 pImpl->pRequest = new SfxRequest( rReq );
787 delete pImpl->pDocInserter;
788 pImpl->pDocInserter = new ::sfx2::DocumentInserter(
789 0, String::CreateFromAscii( ScDocShell::Factory().GetShortName() ), 0 );
790 pImpl->pDocInserter->StartExecuteModal( LINK( this, ScDocShell, DialogClosedHdl ) );
791 return ;
794 if ( pMed ) // nun wirklich ausfuehren...
796 SfxErrorContext aEc( ERRCTX_SFX_OPENDOC, pMed->GetName() );
798 ScDocShell* pOtherDocSh = new ScDocShell;
799 SfxObjectShellRef aDocShTablesRef = pOtherDocSh;
800 pOtherDocSh->DoLoad( pMed );
801 ULONG nErr = pOtherDocSh->GetErrorCode();
802 if (nErr)
803 ErrorHandler::HandleError( nErr ); // auch Warnings
805 if ( !pOtherDocSh->GetError() ) // nur Errors
807 BOOL bHadTrack = ( aDocument.GetChangeTrack() != NULL );
808 ULONG nStart = 0;
809 if ( nSlot == SID_DOCUMENT_MERGE && pChangeTrack )
811 nStart = pChangeTrack->GetActionMax() + 1;
814 if ( nSlot == SID_DOCUMENT_COMPARE )
815 CompareDocument( *pOtherDocSh->GetDocument() );
816 else
817 MergeDocument( *pOtherDocSh->GetDocument() );
819 // show "accept changes" dialog
820 //! get view for this document!
821 if ( !IsDocShared() )
823 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
824 if ( pViewFrm )
826 pViewFrm->ShowChildWindow( ScAcceptChgDlgWrapper::GetChildWindowId(), TRUE ); //@51669
828 if ( pBindings )
830 pBindings->Invalidate( FID_CHG_ACCEPT );
834 rReq.SetReturnValue( SfxInt32Item( nSlot, 0 ) ); //! ???????
835 rReq.Done();
837 if (!bHadTrack) // neu eingeschaltet -> auch anzeigen
839 ScChangeViewSettings* pOldSet = aDocument.GetChangeViewSettings();
840 if ( !pOldSet || !pOldSet->ShowChanges() )
842 ScChangeViewSettings aChangeViewSet;
843 aChangeViewSet.SetShowChanges(TRUE);
844 aDocument.SetChangeViewSettings(aChangeViewSet);
847 else if ( nSlot == SID_DOCUMENT_MERGE && IsDocShared() && pChangeTrack )
849 ULONG nEnd = pChangeTrack->GetActionMax();
850 if ( nEnd >= nStart )
852 // only show changes from merged document
853 ScChangeViewSettings aChangeViewSet;
854 aChangeViewSet.SetShowChanges( TRUE );
855 aChangeViewSet.SetShowAccepted( TRUE );
856 aChangeViewSet.SetHasActionRange( true );
857 aChangeViewSet.SetTheActionRange( nStart, nEnd );
858 aDocument.SetChangeViewSettings( aChangeViewSet );
860 // update view
861 PostPaintExtras();
862 PostPaintGridAll();
866 pOtherDocSh->DoClose(); // delete passiert mit der Ref
869 break;
871 case SID_DELETE_SCENARIO:
872 if (pReqArgs)
874 const SfxPoolItem* pItem;
875 if ( pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET )
877 if ( pItem->ISA(SfxStringItem) )
879 String aName = ((const SfxStringItem*)pItem)->GetValue();
880 SCTAB nTab;
881 if (aDocument.GetTable( aName, nTab ))
883 // DeleteTable von viewfunc nach docfunc verschieben!
885 ScTabViewShell* pSh = GetBestViewShell();
886 if ( pSh )
888 //! SetTabNo in DeleteTable weglassen?
889 SCTAB nDispTab = pSh->GetViewData()->GetTabNo();
890 pSh->DeleteTable( nTab );
891 pSh->SetTabNo(nDispTab);
892 rReq.Done();
898 break;
900 case SID_EDIT_SCENARIO:
902 const SfxPoolItem* pItem;
903 if ( pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET )
905 if ( pItem->ISA(SfxStringItem) )
907 String aName = ((const SfxStringItem*)pItem)->GetValue();
908 SCTAB nTab;
909 if (aDocument.GetTable( aName, nTab ))
911 if (aDocument.IsScenario(nTab))
913 String aComment;
914 Color aColor;
915 USHORT nFlags;
916 aDocument.GetScenarioData( nTab, aComment, aColor, nFlags );
918 // Determine if the Sheet that the Scenario was created on
919 // is protected. But first we need to find that Sheet.
920 // Rewind back to the actual sheet.
921 SCTAB nActualTab = nTab;
924 nActualTab--;
926 while(aDocument.IsScenario(nActualTab));
927 BOOL bSheetProtected = aDocument.IsTabProtected(nActualTab);
929 //! anderen Titel am Dialog setzen
930 //CHINA001 ScNewScenarioDlg* pNewDlg =
931 //CHINA001 new ScNewScenarioDlg( GetActiveDialogParent(), aName, TRUE, bSheetProtected);
932 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
933 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
935 AbstractScNewScenarioDlg* pNewDlg = pFact->CreateScNewScenarioDlg( GetActiveDialogParent(), aName, RID_SCDLG_NEWSCENARIO, TRUE,bSheetProtected);
936 DBG_ASSERT(pNewDlg, "Dialog create fail!");//CHINA001
937 pNewDlg->SetScenarioData( aName, aComment, aColor, nFlags );
938 if ( pNewDlg->Execute() == RET_OK )
940 pNewDlg->GetScenarioData( aName, aComment, aColor, nFlags );
941 ModifyScenario( nTab, aName, aComment, aColor, nFlags );
942 rReq.Done();
944 delete pNewDlg;
950 break;
952 case SID_ATTR_YEAR2000 :
954 const SfxPoolItem* pItem;
955 if ( pReqArgs->GetItemState( nSlot, TRUE, &pItem ) == SFX_ITEM_SET )
957 if ( pItem->ISA(SfxUInt16Item) )
959 UINT16 nY2k = ((SfxUInt16Item*)pItem)->GetValue();
960 // immer an den DocOptions setzen, damit das auch fuer SO50
961 // gespeichert wird (und alle Abfragen bisher auch darauf laufen).
962 // SetDocOptions propagiert das an den NumberFormatter
963 ScDocOptions aDocOpt( aDocument.GetDocOptions() );
964 aDocOpt.SetYear2000( nY2k );
965 aDocument.SetDocOptions( aDocOpt );
966 // die FormShell soll es mitbekommen
967 ScTabViewShell* pSh = GetBestViewShell();
968 if ( pSh )
970 FmFormShell* pFSh = pSh->GetFormShell();
971 if ( pFSh )
972 pFSh->SetY2KState( nY2k );
977 break;
979 case SID_SHARE_DOC:
981 ScViewData* pViewData = GetViewData();
982 if ( !pViewData )
984 rReq.Ignore();
985 break;
988 ScShareDocumentDlg aDlg( GetActiveDialogParent(), pViewData );
989 if ( aDlg.Execute() == RET_OK )
991 bool bSetShared = aDlg.IsShareDocumentChecked();
992 if ( bSetShared != static_cast< bool >( IsDocShared() ) )
994 if ( bSetShared )
996 bool bContinue = true;
997 if ( HasName() )
999 QueryBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
1000 ScGlobal::GetRscString( STR_DOC_WILLBESAVED ) );
1001 if ( aBox.Execute() == RET_NO )
1003 bContinue = false;
1006 if ( bContinue )
1008 EnableSharedSettings( true );
1010 SC_MOD()->SetInSharedDocSaving( true );
1011 if ( !SwitchToShared( sal_True, sal_True ) )
1013 // TODO/LATER: what should be done in case the switch has failed?
1014 // for example in case the user has cancelled the saveAs operation
1017 SC_MOD()->SetInSharedDocSaving( false );
1019 InvalidateName();
1020 GetUndoManager()->Clear();
1022 ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
1023 if ( pTabView )
1025 pTabView->UpdateLayerLocks();
1029 else
1031 uno::Reference< frame::XModel > xModel;
1034 // load shared file
1035 xModel.set( LoadSharedDocument(), uno::UNO_QUERY_THROW );
1036 uno::Reference< util::XCloseable > xCloseable( xModel, uno::UNO_QUERY_THROW );
1038 // check if shared flag is set in shared file
1039 bool bShared = false;
1040 ScModelObj* pDocObj = ScModelObj::getImplementation( xModel );
1041 if ( pDocObj )
1043 ScDocShell* pDocShell = dynamic_cast< ScDocShell* >( pDocObj->GetEmbeddedObject() );
1044 if ( pDocShell )
1046 bShared = pDocShell->HasSharedXMLFlagSet();
1050 // #i87870# check if shared status was disabled and enabled again
1051 bool bOwnEntry = false;
1054 ::svt::ShareControlFile aControlFile( GetSharedFileURL() );
1055 bOwnEntry = aControlFile.HasOwnEntry();
1057 catch ( uno::Exception& )
1061 if ( bShared && bOwnEntry )
1063 uno::Reference< frame::XStorable > xStorable( xModel, uno::UNO_QUERY_THROW );
1064 if ( xStorable->isReadonly() )
1066 xCloseable->close( sal_True );
1068 String aUserName( ScGlobal::GetRscString( STR_UNKNOWN_USER ) );
1071 ::svt::DocumentLockFile aLockFile( GetSharedFileURL() );
1072 uno::Sequence< ::rtl::OUString > aData = aLockFile.GetLockData();
1073 if ( aData.getLength() > LOCKFILE_SYSUSERNAME_ID )
1075 if ( aData[LOCKFILE_OOOUSERNAME_ID].getLength() > 0 )
1077 aUserName = aData[LOCKFILE_OOOUSERNAME_ID];
1079 else if ( aData[LOCKFILE_SYSUSERNAME_ID].getLength() > 0 )
1081 aUserName = aData[LOCKFILE_SYSUSERNAME_ID];
1085 catch ( uno::Exception& )
1088 String aMessage( ScGlobal::GetRscString( STR_FILE_LOCKED_TRY_LATER ) );
1089 aMessage.SearchAndReplaceAscii( "%1", aUserName );
1091 WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ), aMessage );
1092 aBox.Execute();
1094 else
1096 WarningBox aBox( GetActiveDialogParent(), WinBits( WB_YES_NO | WB_DEF_YES ),
1097 ScGlobal::GetRscString( STR_DOC_DISABLESHARED ) );
1098 if ( aBox.Execute() == RET_YES )
1100 xCloseable->close( sal_True );
1102 if ( !SwitchToShared( sal_False, sal_True ) )
1104 // TODO/LATER: what should be done in case the switch has failed?
1105 // for example in case the user has cancelled the saveAs operation
1108 EnableSharedSettings( false );
1110 if ( pBindings )
1112 pBindings->ExecuteSynchron( SID_SAVEDOC );
1115 ScTabView* pTabView = dynamic_cast< ScTabView* >( pViewData->GetView() );
1116 if ( pTabView )
1118 pTabView->UpdateLayerLocks();
1121 else
1123 xCloseable->close( sal_True );
1127 else
1129 xCloseable->close( sal_True );
1130 WarningBox aBox( GetActiveDialogParent(), WinBits( WB_OK ),
1131 ScGlobal::GetRscString( STR_DOC_NOLONGERSHARED ) );
1132 aBox.Execute();
1135 catch ( uno::Exception& )
1137 DBG_ERROR( "SID_SHARE_DOC: caught exception\n" );
1138 SC_MOD()->SetInSharedDocSaving( false );
1142 uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
1143 xClose->close( sal_True );
1145 catch ( uno::Exception& )
1152 rReq.Done();
1154 break;
1156 default:
1158 // kleiner (?) Hack -> forward der Slots an TabViewShell
1159 ScTabViewShell* pSh = GetBestViewShell();
1160 if ( pSh )
1161 pSh->Execute( rReq );
1162 else
1163 SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT );
1169 //------------------------------------------------------------------
1171 BOOL ScDocShell::ExecuteChangeProtectionDialog( Window* _pParent, BOOL bJustQueryIfProtected )
1173 BOOL bDone = FALSE;
1174 ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
1175 if ( pChangeTrack )
1177 BOOL bProtected = pChangeTrack->IsProtected();
1178 if ( bJustQueryIfProtected && !bProtected )
1179 return TRUE;
1181 String aTitle( ScResId( bProtected ? SCSTR_CHG_UNPROTECT : SCSTR_CHG_PROTECT ) );
1182 String aText( ScResId( SCSTR_PASSWORD ) );
1183 String aPassword;
1185 SfxPasswordDialog* pDlg = new SfxPasswordDialog(
1186 _pParent ? _pParent : GetActiveDialogParent(), &aText );
1187 pDlg->SetText( aTitle );
1188 pDlg->SetMinLen( 1 );
1189 pDlg->SetHelpId( SID_CHG_PROTECT );
1190 pDlg->SetEditHelpId( HID_CHG_PROTECT );
1191 if ( !bProtected )
1192 pDlg->ShowExtras( SHOWEXTRAS_CONFIRM );
1193 if ( pDlg->Execute() == RET_OK )
1194 aPassword = pDlg->GetPassword();
1195 delete pDlg;
1197 if ( aPassword.Len() )
1199 if ( bProtected )
1201 if ( SvPasswordHelper::CompareHashPassword(pChangeTrack->GetProtection(), aPassword) )
1203 if ( bJustQueryIfProtected )
1204 bDone = TRUE;
1205 else
1206 pChangeTrack->SetProtection(
1207 com::sun::star::uno::Sequence< sal_Int8 > (0) );
1209 else
1211 InfoBox aBox( GetActiveDialogParent(),
1212 String( ScResId( SCSTR_WRONGPASSWORD ) ) );
1213 aBox.Execute();
1216 else
1218 com::sun::star::uno::Sequence< sal_Int8 > aPass;
1219 SvPasswordHelper::GetHashPassword( aPass, aPassword );
1220 pChangeTrack->SetProtection( aPass );
1222 if ( bProtected != pChangeTrack->IsProtected() )
1224 // update "accept changes" dialog
1225 //! notify all views
1226 SfxViewFrame* pViewFrm = SfxViewFrame::Current();
1227 if ( pViewFrm && pViewFrm->HasChildWindow( FID_CHG_ACCEPT ) )
1229 SfxChildWindow* pChild = pViewFrm->GetChildWindow( FID_CHG_ACCEPT );
1230 if ( pChild )
1231 ((ScAcceptChgDlgWrapper*)pChild)->ReInitDlg();
1233 bDone = TRUE;
1237 else if ( bJustQueryIfProtected )
1238 bDone = TRUE;
1239 return bDone;
1243 //------------------------------------------------------------------
1245 void ScDocShell::DoRecalc( BOOL bApi )
1247 BOOL bDone = FALSE;
1248 ScTabViewShell* pSh = GetBestViewShell();
1249 if ( pSh )
1251 ScInputHandler* pHdl = SC_MOD()->GetInputHdl(pSh);
1252 if ( pHdl && pHdl->IsInputMode() && pHdl->IsFormulaMode() && !bApi )
1254 pHdl->FormulaPreview(); // Teilergebnis als QuickHelp
1255 bDone = TRUE;
1257 else
1259 pSh->UpdateInputLine(); // InputEnterHandler
1260 pSh->UpdateInputHandler();
1263 if (!bDone) // sonst Dokument neu berechnen
1265 WaitObject aWaitObj( GetActiveDialogParent() );
1266 aDocument.CalcFormulaTree();
1267 if ( pSh )
1269 pSh->UpdateCharts(TRUE);
1270 aDocument.BroadcastUno(ScHint(SC_HINT_DATACHANGED, ScAddress(), NULL));
1273 aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
1275 // #47939# Wenn es Charts gibt, dann alles painten, damit nicht
1276 // PostDataChanged und die Charts nacheinander kommen und Teile
1277 // doppelt gepainted werden.
1279 ScChartListenerCollection* pCharts = aDocument.GetChartListenerCollection();
1280 if ( pCharts && pCharts->GetCount() )
1281 PostPaintGridAll();
1282 else
1283 PostDataChanged();
1287 void ScDocShell::DoHardRecalc( BOOL /* bApi */ )
1289 WaitObject aWaitObj( GetActiveDialogParent() );
1290 ScTabViewShell* pSh = GetBestViewShell();
1291 if ( pSh )
1293 pSh->UpdateInputLine(); // InputEnterHandler
1294 pSh->UpdateInputHandler();
1296 aDocument.CalcAll();
1297 GetDocFunc().DetectiveRefresh(); // erzeugt eigenes Undo
1298 if ( pSh )
1299 pSh->UpdateCharts(TRUE);
1301 // CalcAll doesn't broadcast value changes, so SC_HINT_CALCALL is broadcasted globally
1302 // in addition to SFX_HINT_DATACHANGED.
1303 aDocument.BroadcastUno( SfxSimpleHint( SC_HINT_CALCALL ) );
1304 aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
1306 // use hard recalc also to disable stream-copying of all sheets
1307 // (somewhat consistent with charts)
1308 SCTAB nTabCount = aDocument.GetTableCount();
1309 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1310 if (aDocument.IsStreamValid(nTab))
1311 aDocument.SetStreamValid(nTab, FALSE);
1313 PostPaintGridAll();
1316 //------------------------------------------------------------------
1318 void ScDocShell::DoAutoStyle( const ScRange& rRange, const String& rStyle )
1320 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1321 ScStyleSheet* pStyleSheet =
1322 pStylePool->FindCaseIns( rStyle, SFX_STYLE_FAMILY_PARA );
1323 if (!pStyleSheet)
1324 pStyleSheet = (ScStyleSheet*)
1325 pStylePool->Find( ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA );
1326 if (pStyleSheet)
1328 DBG_ASSERT(rRange.aStart.Tab() == rRange.aEnd.Tab(),
1329 "DoAutoStyle mit mehreren Tabellen");
1330 SCTAB nTab = rRange.aStart.Tab();
1331 SCCOL nStartCol = rRange.aStart.Col();
1332 SCROW nStartRow = rRange.aStart.Row();
1333 SCCOL nEndCol = rRange.aEnd.Col();
1334 SCROW nEndRow = rRange.aEnd.Row();
1335 aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
1336 aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
1337 PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PAINT_GRID );
1341 //------------------------------------------------------------------
1343 void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint )
1345 USHORT nId = rHint.GetHint();
1346 const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet();
1347 if (!pStyle)
1348 return;
1350 if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PAGE )
1352 if ( nId == SFX_STYLESHEET_MODIFIED )
1354 ScDocShellModificator aModificator( *this );
1356 String aNewName = pStyle->GetName();
1357 String aOldName = aNewName;
1358 BOOL bExtended = rHint.ISA(SfxStyleSheetHintExtended); // Name geaendert?
1359 if (bExtended)
1360 aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName();
1362 if ( aNewName != aOldName )
1363 aDocument.RenamePageStyleInUse( aOldName, aNewName );
1365 SCTAB nTabCount = aDocument.GetTableCount();
1366 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1367 if (aDocument.GetPageStyle(nTab) == aNewName) // schon auf neu angepasst
1369 aDocument.PageStyleModified( nTab, aNewName );
1370 ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1371 aPrintFunc.UpdatePages();
1374 aModificator.SetDocumentModified();
1376 if (bExtended)
1378 SfxBindings* pBindings = GetViewBindings();
1379 if (pBindings)
1381 pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1382 pBindings->Invalidate( SID_STYLE_FAMILY4 );
1383 pBindings->Invalidate( FID_RESET_PRINTZOOM );
1384 pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1385 pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1390 else if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PARA )
1392 if ( nId == SFX_STYLESHEET_MODIFIED)
1394 String aNewName = pStyle->GetName();
1395 String aOldName = aNewName;
1396 BOOL bExtended = rHint.ISA(SfxStyleSheetHintExtended);
1397 if (bExtended)
1398 aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName();
1399 if ( aNewName != aOldName )
1401 ScConditionalFormatList* pList = aDocument.GetCondFormList();
1402 if (pList)
1403 pList->RenameCellStyle( aOldName,aNewName );
1408 // alles andere geht ueber Slots...
1411 // wie in printfun.cxx
1412 #define ZOOM_MIN 10
1414 void ScDocShell::SetPrintZoom( SCTAB nTab, USHORT nScale, USHORT nPages )
1416 BOOL bUndo(aDocument.IsUndoEnabled());
1417 String aStyleName = aDocument.GetPageStyle( nTab );
1418 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1419 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
1420 DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1421 if ( pStyleSheet )
1423 ScDocShellModificator aModificator( *this );
1425 SfxItemSet& rSet = pStyleSheet->GetItemSet();
1426 if (bUndo)
1428 USHORT nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue();
1429 USHORT nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
1430 GetUndoManager()->AddUndoAction( new ScUndoPrintZoom(
1431 this, nTab, nOldScale, nOldPages, nScale, nPages ) );
1434 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
1435 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
1437 ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1438 aPrintFunc.UpdatePages();
1439 aModificator.SetDocumentModified();
1441 SfxBindings* pBindings = GetViewBindings();
1442 if (pBindings)
1443 pBindings->Invalidate( FID_RESET_PRINTZOOM );
1447 BOOL ScDocShell::AdjustPrintZoom( const ScRange& rRange )
1449 BOOL bChange = FALSE;
1450 SCTAB nTab = rRange.aStart.Tab();
1452 String aStyleName = aDocument.GetPageStyle( nTab );
1453 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1454 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
1455 DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1456 if ( pStyleSheet )
1458 SfxItemSet& rSet = pStyleSheet->GetItemSet();
1459 BOOL bHeaders = ((const SfxBoolItem&)rSet.Get(ATTR_PAGE_HEADERS)).GetValue();
1460 USHORT nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue();
1461 USHORT nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
1462 const ScRange* pRepeatCol = aDocument.GetRepeatColRange( nTab );
1463 const ScRange* pRepeatRow = aDocument.GetRepeatRowRange( nTab );
1465 // benoetigte Skalierung fuer Selektion ausrechnen
1467 USHORT nNewScale = nOldScale;
1469 long nBlkTwipsX = 0;
1470 if (bHeaders)
1471 nBlkTwipsX += (long) PRINT_HEADER_WIDTH;
1472 SCCOL nStartCol = rRange.aStart.Col();
1473 SCCOL nEndCol = rRange.aEnd.Col();
1474 if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
1476 for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); i++ )
1477 nBlkTwipsX += aDocument.GetColWidth( i, nTab );
1478 if ( nStartCol <= pRepeatCol->aEnd.Col() )
1479 nStartCol = pRepeatCol->aEnd.Col() + 1;
1481 // legacy compilers' own scope for i
1483 for ( SCCOL i=nStartCol; i<=nEndCol; i++ )
1484 nBlkTwipsX += aDocument.GetColWidth( i, nTab );
1487 long nBlkTwipsY = 0;
1488 if (bHeaders)
1489 nBlkTwipsY += (long) PRINT_HEADER_HEIGHT;
1490 SCROW nStartRow = rRange.aStart.Row();
1491 SCROW nEndRow = rRange.aEnd.Row();
1492 if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
1494 nBlkTwipsY += aDocument.FastGetRowHeight( pRepeatRow->aStart.Row(),
1495 pRepeatRow->aEnd.Row(), nTab );
1496 if ( nStartRow <= pRepeatRow->aEnd.Row() )
1497 nStartRow = pRepeatRow->aEnd.Row() + 1;
1499 nBlkTwipsY += aDocument.FastGetRowHeight( nStartRow, nEndRow, nTab );
1501 Size aPhysPage;
1502 long nHdr, nFtr;
1503 ScPrintFunc aOldPrFunc( this, GetPrinter(), nTab );
1504 aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr );
1505 nBlkTwipsY += nHdr + nFtr;
1507 if ( nBlkTwipsX == 0 ) // #100639# hidden columns/rows may lead to 0
1508 nBlkTwipsX = 1;
1509 if ( nBlkTwipsY == 0 )
1510 nBlkTwipsY = 1;
1512 long nNeeded = Min( aPhysPage.Width() * 100 / nBlkTwipsX,
1513 aPhysPage.Height() * 100 / nBlkTwipsY );
1514 if ( nNeeded < ZOOM_MIN )
1515 nNeeded = ZOOM_MIN; // Begrenzung
1516 if ( nNeeded < (long) nNewScale )
1517 nNewScale = (USHORT) nNeeded;
1519 bChange = ( nNewScale != nOldScale || nOldPages != 0 );
1520 if ( bChange )
1521 SetPrintZoom( nTab, nNewScale, 0 );
1523 return bChange;
1526 void ScDocShell::PageStyleModified( const String& rStyleName, BOOL bApi )
1528 ScDocShellModificator aModificator( *this );
1530 BOOL bWarn = FALSE;
1532 SCTAB nTabCount = aDocument.GetTableCount();
1533 SCTAB nUseTab = MAXTAB+1;
1534 for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++)
1535 if ( aDocument.GetPageStyle(nTab) == rStyleName &&
1536 ( !bApi || aDocument.GetPageSize(nTab).Width() ) )
1537 nUseTab = nTab;
1538 // bei bApi nur, wenn Umbrueche schon angezeigt
1540 if (ValidTab(nUseTab)) // nicht verwendet -> nichts zu tun
1542 ScPrintFunc aPrintFunc( this, GetPrinter(), nUseTab ); //! ohne CountPages auskommen
1543 if (!aPrintFunc.UpdatePages()) // setzt Umbrueche auf allen Tabs
1544 bWarn = TRUE;
1546 if (bWarn && !bApi)
1548 ScWaitCursorOff aWaitOff( GetActiveDialogParent() );
1549 InfoBox aInfoBox(GetActiveDialogParent(),
1550 ScGlobal::GetRscString(STR_PRINT_INVALID_AREA));
1551 aInfoBox.Execute();
1555 aModificator.SetDocumentModified();
1557 SfxBindings* pBindings = GetViewBindings();
1558 if (pBindings)
1560 pBindings->Invalidate( FID_RESET_PRINTZOOM );
1561 pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1562 pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1566 void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,
1567 SfxRequest& rReq,
1568 SCTAB nCurTab )
1570 const SfxItemSet* pReqArgs = rReq.GetArgs();
1572 switch ( rReq.GetSlot() )
1574 case SID_STATUS_PAGESTYLE: // Click auf StatusBar-Control
1575 case SID_FORMATPAGE:
1577 if ( pReqArgs != NULL )
1580 else if ( pReqArgs == NULL )
1582 BOOL bUndo(aDocument.IsUndoEnabled());
1583 String aOldName = aDocument.GetPageStyle( nCurTab );
1584 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1585 SfxStyleSheetBase* pStyleSheet
1586 = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
1588 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1590 if ( pStyleSheet )
1592 ScStyleSaveData aOldData;
1593 if (bUndo)
1594 aOldData.InitFromStyle( pStyleSheet );
1596 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1598 //CHINA001 ScStyleDlg* pDlg = new ScStyleDlg( GetActiveDialogParent(),
1599 //CHINA001 *pStyleSheet,
1600 //CHINA001 RID_SCDLG_STYLES_PAGE );
1601 //CHINA001
1602 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1603 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1605 SfxAbstractTabDialog* pDlg = pFact->CreateScStyleDlg( GetActiveDialogParent(), *pStyleSheet, RID_SCDLG_STYLES_PAGE, RID_SCDLG_STYLES_PAGE );
1606 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1608 if ( pDlg->Execute() == RET_OK )
1610 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1612 WaitObject aWait( GetActiveDialogParent() );
1614 String aNewName = pStyleSheet->GetName();
1615 if ( aNewName != aOldName &&
1616 aDocument.RenamePageStyleInUse( aOldName, aNewName ) )
1618 SfxBindings* pBindings = GetViewBindings();
1619 if (pBindings)
1621 pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1622 pBindings->Invalidate( FID_RESET_PRINTZOOM );
1626 if ( pOutSet )
1627 aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1629 // merken fuer GetState():
1630 GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
1631 rCaller.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT );
1633 ScStyleSaveData aNewData;
1634 aNewData.InitFromStyle( pStyleSheet );
1635 if (bUndo)
1637 GetUndoManager()->AddUndoAction(
1638 new ScUndoModifyStyle( this, SFX_STYLE_FAMILY_PAGE,
1639 aOldData, aNewData ) );
1642 PageStyleModified( aNewName, FALSE );
1643 rReq.Done();
1645 delete pDlg;
1647 rStyleSet.ClearItem( ATTR_PAGE_PAPERTRAY );
1651 break;
1653 case SID_HFEDIT:
1655 if ( pReqArgs != NULL )
1658 else if ( pReqArgs == NULL )
1660 String aStr( aDocument.GetPageStyle( nCurTab ) );
1662 ScStyleSheetPool* pStylePool
1663 = aDocument.GetStyleSheetPool();
1665 SfxStyleSheetBase* pStyleSheet
1666 = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE );
1668 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1670 if ( pStyleSheet )
1672 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1674 SvxPageUsage eUsage =
1675 SvxPageUsage( ((const SvxPageItem&)
1676 rStyleSet.Get( ATTR_PAGE )).
1677 GetPageUsage() );
1678 BOOL bShareHeader = IS_SHARE_HEADER(rStyleSet);
1679 BOOL bShareFooter = IS_SHARE_FOOTER(rStyleSet);
1680 USHORT nResId = 0;
1682 switch ( eUsage )
1684 case SVX_PAGE_LEFT:
1685 case SVX_PAGE_RIGHT:
1687 if ( bHeaderOn && bFooterOn )
1688 nResId = RID_SCDLG_HFEDIT;
1689 else if ( SVX_PAGE_RIGHT == eUsage )
1691 if ( !bHeaderOn && bFooterOn )
1692 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1693 else if ( bHeaderOn && !bFooterOn )
1694 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1696 else
1698 // #69193a# respect "shared" setting
1699 if ( !bHeaderOn && bFooterOn )
1700 nResId = bShareFooter ?
1701 RID_SCDLG_HFEDIT_RIGHTFOOTER :
1702 RID_SCDLG_HFEDIT_LEFTFOOTER;
1703 else if ( bHeaderOn && !bFooterOn )
1704 nResId = bShareHeader ?
1705 RID_SCDLG_HFEDIT_RIGHTHEADER :
1706 RID_SCDLG_HFEDIT_LEFTHEADER;
1709 break;
1711 case SVX_PAGE_MIRROR:
1712 case SVX_PAGE_ALL:
1713 default:
1715 if ( !bShareHeader && !bShareFooter )
1717 if ( bHeaderOn && bFooterOn )
1718 nResId = RID_SCDLG_HFEDIT_ALL;
1719 else if ( !bHeaderOn && bFooterOn )
1720 nResId = RID_SCDLG_HFEDIT_FOOTER;
1721 else if ( bHeaderOn && !bFooterOn )
1722 nResId = RID_SCDLG_HFEDIT_HEADER;
1724 else if ( bShareHeader && bShareFooter )
1726 if ( bHeaderOn && bFooterOn )
1727 nResId = RID_SCDLG_HFEDIT;
1728 else
1730 if ( !bHeaderOn && bFooterOn )
1731 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1732 else if ( bHeaderOn && !bFooterOn )
1733 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1736 else if ( !bShareHeader && bShareFooter )
1738 if ( bHeaderOn && bFooterOn )
1739 nResId = RID_SCDLG_HFEDIT_SFTR;
1740 else if ( !bHeaderOn && bFooterOn )
1741 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1742 else if ( bHeaderOn && !bFooterOn )
1743 nResId = RID_SCDLG_HFEDIT_HEADER;
1745 else if ( bShareHeader && !bShareFooter )
1747 if ( bHeaderOn && bFooterOn )
1748 nResId = RID_SCDLG_HFEDIT_SHDR;
1749 else if ( !bHeaderOn && bFooterOn )
1750 nResId = RID_SCDLG_HFEDIT_FOOTER;
1751 else if ( bHeaderOn && !bFooterOn )
1752 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1757 //CHINA001 ScHFEditDlg* pDlg
1758 //CHINA001 = new ScHFEditDlg( SFX_APP()->GetViewFrame(),
1759 //CHINA001 GetActiveDialogParent(),
1760 //CHINA001 rStyleSet,
1761 //CHINA001 aStr,
1762 //CHINA001 nResId );
1763 //CHINA001
1764 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1765 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1767 SfxAbstractTabDialog* pDlg = pFact->CreateScHFEditDlg( SfxViewFrame::Current(),
1768 GetActiveDialogParent(),
1769 rStyleSet,
1770 aStr,
1771 RID_SCDLG_HFEDIT, nResId);
1772 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1773 if ( pDlg->Execute() == RET_OK )
1775 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1777 if ( pOutSet )
1778 aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1780 SetDocumentModified();
1781 rReq.Done();
1783 delete pDlg;
1787 break;
1789 default:
1790 break;
1794 void ScDocShell::GetStatePageStyle( SfxViewShell& /* rCaller */,
1795 SfxItemSet& rSet,
1796 SCTAB nCurTab )
1798 SfxWhichIter aIter(rSet);
1799 USHORT nWhich = aIter.FirstWhich();
1800 while ( nWhich )
1802 switch (nWhich)
1804 case SID_STATUS_PAGESTYLE:
1805 rSet.Put( SfxStringItem( nWhich, aDocument.GetPageStyle( nCurTab ) ) );
1806 break;
1808 case SID_HFEDIT:
1810 String aStr = aDocument.GetPageStyle( nCurTab );
1811 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1812 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE );
1814 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1816 if ( pStyleSheet )
1818 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1820 GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
1822 if ( !bHeaderOn && !bFooterOn )
1823 rSet.DisableItem( nWhich );
1826 break;
1829 nWhich = aIter.NextWhich();
1833 void lcl_GetPrintData( ScDocShell* pDocShell /*in*/,
1834 ScDocument* pDocument /*in*/, SfxPrinter* pPrinter /*in*/,
1835 PrintDialog* pPrintDialog /*in*/, bool bForceSelected /*in*/,
1836 ScMarkData* pMarkData /*inout*/, bool& rbHasOptions /*out*/,
1837 ScPrintOptions& rOptions /*out*/, bool& rbAllTabs /*out*/,
1838 long& rnTotalPages /*out*/, long aPageArr[] /*out*/,
1839 MultiSelection& rPageRanges /*out*/, ScRange** ppMarkedRange /*out*/ )
1841 // get settings from print options sub-dialog
1842 const SfxItemSet& rOptionSet = pPrinter->GetOptions();
1843 const SfxPoolItem* pItem;
1844 rbHasOptions = ( rOptionSet.GetItemState( SID_SCPRINTOPTIONS, FALSE, &pItem ) == SFX_ITEM_SET );
1845 if ( rbHasOptions )
1847 rOptions = ((const ScTpPrintItem*)pItem)->GetPrintOptions();
1849 else
1851 // use configuration
1852 rOptions = SC_MOD()->GetPrintOptions();
1855 // update all pending row heights with a single progress bar,
1856 // instead of a separate progress for each sheet from ScPrintFunc
1857 pDocShell->UpdatePendingRowHeights( MAXTAB, true );
1859 // get number of total pages
1860 rnTotalPages = 0;
1861 SCTAB nTabCount = pDocument->GetTableCount();
1862 for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
1864 ScPrintFunc aPrintFunc( pDocShell, pPrinter, nTab, 0, 0, NULL, &rOptions );
1865 long nThisTab = aPrintFunc.GetTotalPages();
1866 aPageArr[nTab] = nThisTab;
1867 rnTotalPages += nThisTab;
1870 rPageRanges.SetTotalRange( Range( 0, RANGE_MAX ) );
1871 rPageRanges.Select( Range( 1, rnTotalPages ) );
1873 rbAllTabs = ( pPrintDialog ? ( pPrintDialog->GetCheckedSheetRange() == PRINTSHEETS_ALL ) : SC_MOD()->GetPrintOptions().GetAllSheets() );
1874 if ( bForceSelected )
1876 rbAllTabs = false;
1879 if ( ( pPrintDialog && pPrintDialog->GetCheckedSheetRange() == PRINTSHEETS_SELECTED_CELLS ) || bForceSelected )
1881 if ( pMarkData && ( pMarkData->IsMarked() || pMarkData->IsMultiMarked() ) )
1883 pMarkData->MarkToMulti();
1884 *ppMarkedRange = new ScRange;
1885 pMarkData->GetMultiMarkArea( **ppMarkedRange );
1886 pMarkData->MarkToSimple();
1890 PrintDialogRange eDlgOption = pPrintDialog ? pPrintDialog->GetCheckedRange() : PRINTDIALOG_ALL;
1891 if ( eDlgOption == PRINTDIALOG_RANGE )
1893 rPageRanges = MultiSelection( pPrintDialog->GetRangeText() );
1896 // get number of total pages if selection
1897 if ( !rbAllTabs )
1899 rnTotalPages = 0;
1900 for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
1902 if ( *ppMarkedRange ) // selected range is used instead of print ranges -> page count is different
1904 ScPrintFunc aPrintFunc( pDocShell, pPrinter, nTab, 0, 0, *ppMarkedRange, &rOptions );
1905 aPageArr[nTab] = aPrintFunc.GetTotalPages();
1907 if ( !pMarkData || pMarkData->GetTableSelect( nTab ) )
1909 rnTotalPages += aPageArr[nTab];
1912 if ( eDlgOption == PRINTDIALOG_ALL || bForceSelected )
1914 rPageRanges.Select( Range( 1, rnTotalPages ) );
1919 bool ScDocShell::CheckPrint( PrintDialog* pPrintDialog, ScMarkData* pMarkData, bool bForceSelected, bool bIsAPI )
1921 SfxPrinter* pPrinter = GetPrinter();
1922 if ( !pPrinter )
1924 return false;
1927 bool bHasOptions = false;
1928 ScPrintOptions aOptions;
1929 bool bAllTabs = true;
1930 long nTotalPages = 0;
1931 long aPageArr[MAXTABCOUNT]; // pages per sheet
1932 MultiSelection aPageRanges; // pages to print
1933 ScRange* pMarkedRange = NULL;
1935 lcl_GetPrintData( this, &aDocument, pPrinter, pPrintDialog, bForceSelected,
1936 pMarkData, bHasOptions, aOptions, bAllTabs, nTotalPages,
1937 aPageArr, aPageRanges, &pMarkedRange );
1939 delete pMarkedRange;
1941 if ( nTotalPages == 0 )
1943 if ( !bIsAPI )
1945 WarningBox aWarningBox( GetActiveDialogParent(), WinBits( WB_OK ),
1946 String( ScResId( STR_PRINT_NOTHING ) ) );
1947 aWarningBox.Execute();
1949 return false;
1952 return true;
1955 void ScDocShell::PreparePrint( PrintDialog* pPrintDialog, ScMarkData* pMarkData )
1957 SfxPrinter* pPrinter = GetPrinter();
1958 if ( !pPrinter )
1960 return;
1963 delete pOldJobSetup; // gesetzt nur bei Fehler in StartJob()
1964 pOldJobSetup = new ScJobSetup( pPrinter ); // Einstellungen merken
1966 // Einstellungen fuer die erste gedruckte Seite muessen hier (vor StartJob) gesetzt werden
1967 //! Selection etc. mit Print() zusammenfassen !!!
1968 //! Seiten nur einmal zaehlen
1970 bool bHasOptions = false;
1971 ScPrintOptions aOptions;
1972 bool bAllTabs = true;
1973 long nTotalPages = 0;
1974 long aPageArr[MAXTABCOUNT]; // pages per sheet
1975 MultiSelection aPageRanges; // pages to print
1976 ScRange* pMarkedRange = NULL;
1978 lcl_GetPrintData( this, &aDocument, pPrinter, pPrintDialog, false,
1979 pMarkData, bHasOptions, aOptions, bAllTabs, nTotalPages,
1980 aPageArr, aPageRanges, &pMarkedRange );
1982 BOOL bFound = FALSE; // erste Seite gefunden
1983 long nTabStart = 0;
1984 SCTAB nTabCount = aDocument.GetTableCount();
1985 for ( SCTAB nTab=0; nTab<nTabCount && !bFound; nTab++ )
1987 if ( bAllTabs || !pMarkData || pMarkData->GetTableSelect( nTab ) )
1989 long nNext = nTabStart + aPageArr[nTab];
1990 BOOL bSelected = FALSE;
1991 for (long nP=nTabStart+1; nP<=nNext; nP++) // 1-basiert
1992 if (aPageRanges.IsSelected( nP )) // eine Seite von dieser Tabelle selektiert?
1993 bSelected = TRUE;
1995 if (bSelected)
1997 ScPrintFunc aPrintFunc( this, pPrinter, nTab );
1999 aPrintFunc.ApplyPrintSettings(); // dann Settings fuer diese Tabelle
2000 bFound = TRUE;
2002 nTabStart = nNext;
2006 delete pMarkedRange;
2009 BOOL lcl_HasTransparent( ScDocument* pDoc, SCTAB nTab, const ScRange* pRange )
2011 BOOL bFound = FALSE;
2012 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
2013 if (pDrawLayer)
2015 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
2016 DBG_ASSERT(pPage,"Page ?");
2017 if (pPage)
2019 Rectangle aMMRect;
2020 if ( pRange )
2021 aMMRect = pDoc->GetMMRect( pRange->aStart.Col(), pRange->aStart.Row(),
2022 pRange->aEnd.Col(), pRange->aEnd.Row(), nTab );
2024 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
2025 SdrObject* pObject = aIter.Next();
2026 while (pObject && !bFound)
2028 if (pObject->IsTransparent())
2030 if ( pRange )
2032 Rectangle aObjRect = pObject->GetLogicRect();
2033 if ( aObjRect.IsOver( aMMRect ) )
2034 bFound = TRUE;
2036 else
2037 bFound = TRUE;
2040 pObject = aIter.Next();
2045 return bFound;
2048 void ScDocShell::Print( SfxProgress& rProgress, PrintDialog* pPrintDialog,
2049 ScMarkData* pMarkData, Window* pDialogParent, BOOL bForceSelected, BOOL bIsAPI )
2051 SfxPrinter* pPrinter = GetPrinter();
2052 if ( !pPrinter )
2054 return;
2057 bool bHasOptions = false;
2058 ScPrintOptions aOptions;
2059 bool bAllTabs = true;
2060 long nTotalPages = 0;
2061 long aPageArr[MAXTABCOUNT]; // pages per sheet
2062 MultiSelection aPageRanges; // pages to print
2063 ScRange* pMarkedRange = NULL;
2065 lcl_GetPrintData( this, &aDocument, pPrinter, pPrintDialog, bForceSelected,
2066 pMarkData, bHasOptions, aOptions, bAllTabs, nTotalPages,
2067 aPageArr, aPageRanges, &pMarkedRange );
2069 USHORT nCollateCopies = 1;
2070 if ( pPrintDialog && pPrintDialog->IsCollateEnabled() && pPrintDialog->IsCollateChecked() )
2071 nCollateCopies = pPrintDialog->GetCopyCount();
2073 // test if printed range contains transparent objects
2075 BOOL bHasTransp = FALSE;
2076 BOOL bAnyPrintRanges = aDocument.HasPrintRange();
2077 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
2078 SCTAB nTabCount = aDocument.GetTableCount();
2079 for ( SCTAB nTab=0; nTab<nTabCount && !bHasTransp; nTab++ )
2081 if ( bAllTabs || !pMarkData || pMarkData->GetTableSelect( nTab ) )
2083 SfxStyleSheetBase* pStyleSheet = pStylePool->Find(
2084 aDocument.GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE );
2085 if ( pStyleSheet )
2087 const SfxItemSet& rSet = pStyleSheet->GetItemSet();
2088 if ( ((const ScViewObjectModeItem&)rSet.Get(ATTR_PAGE_CHARTS)).GetValue() == VOBJ_MODE_SHOW ||
2089 ((const ScViewObjectModeItem&)rSet.Get(ATTR_PAGE_OBJECTS)).GetValue() == VOBJ_MODE_SHOW ||
2090 ((const ScViewObjectModeItem&)rSet.Get(ATTR_PAGE_DRAWINGS)).GetValue() == VOBJ_MODE_SHOW )
2092 if ( pMarkedRange )
2093 bHasTransp = bHasTransp || lcl_HasTransparent( &aDocument, nTab, pMarkedRange );
2094 else if ( aDocument.GetPrintRangeCount(nTab) )
2096 USHORT nRangeCount = aDocument.GetPrintRangeCount(nTab);
2097 for (USHORT i=0; i<nRangeCount; i++)
2098 bHasTransp = bHasTransp ||
2099 lcl_HasTransparent( &aDocument, nTab, aDocument.GetPrintRange( nTab, i ) );
2101 else if (!bAnyPrintRanges || aDocument.IsPrintEntireSheet(nTab))
2102 bHasTransp = bHasTransp || lcl_HasTransparent( &aDocument, nTab, NULL );
2108 BOOL bContinue = pPrinter->InitJob( pDialogParent, !bIsAPI && bHasTransp );
2110 if ( bContinue )
2112 for ( USHORT n=0; n<nCollateCopies; n++ )
2114 long nTabStart = 0;
2115 long nDisplayStart = 0;
2116 long nAttrPage = 1;
2117 long nPrinted = 0;
2119 for ( SCTAB nTab=0; nTab<nTabCount; nTab++ )
2121 if ( bAllTabs || !pMarkData || pMarkData->GetTableSelect( nTab ) )
2123 FmFormView* pDrawView = NULL;
2124 Rectangle aFull( 0, 0, LONG_MAX, LONG_MAX );
2126 // #114135#
2127 ScDrawLayer* pModel = aDocument.GetDrawLayer(); // ist nicht NULL
2129 if(pModel)
2131 pDrawView = new FmFormView( pModel, pPrinter );
2132 pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
2133 pDrawView->SetPrintPreview( TRUE );
2136 ScPrintFunc aPrintFunc( this, pPrinter, nTab, nAttrPage, nTotalPages, pMarkedRange, &aOptions );
2137 aPrintFunc.SetDrawView( pDrawView );
2138 nPrinted += aPrintFunc.DoPrint( aPageRanges, nTabStart, nDisplayStart, TRUE, &rProgress, NULL );
2140 nTabStart += aPageArr[nTab];
2141 if ( aDocument.NeedPageResetAfterTab(nTab) )
2142 nDisplayStart = 0;
2143 else
2144 nDisplayStart += aPageArr[nTab];
2145 nAttrPage = aPrintFunc.GetFirstPageNo(); // behalten oder aus Vorlage
2147 delete pDrawView;
2151 if ( n+1 < nCollateCopies && pPrinter->GetDuplexMode() == DUPLEX_ON && ( nPrinted % 2 ) == 1 )
2153 // #105584# when several collated copies are printed in duplex mode, and there is
2154 // an odd number of pages, print an empty page between copies, so the first page of
2155 // the second copy isn't printed on the back of the last page of the first copy.
2156 // (same as in Writer ViewShell::Prt)
2158 pPrinter->StartPage();
2159 pPrinter->EndPage();
2164 delete pMarkedRange;
2166 if (pOldJobSetup)
2168 pPrinter->SetOrientation( pOldJobSetup->eOrientation );
2169 pPrinter->SetPaperBin ( pOldJobSetup->nPaperBin );
2170 pPrinter->SetPaper ( pOldJobSetup->ePaper );
2172 if ( PAPER_USER == pOldJobSetup->ePaper )
2174 pPrinter->SetMapMode( pOldJobSetup->aUserMapMode );
2175 pPrinter->SetPaperSizeUser( pOldJobSetup->aUserSize );
2178 delete pOldJobSetup;
2179 pOldJobSetup = NULL;
2182 if ( bHasOptions )
2184 // remove PrintOptions from printer ItemSet,
2185 // so next time the options from the configuration are used
2187 SfxItemSet aSet( pPrinter->GetOptions() );
2188 aSet.ClearItem( SID_SCPRINTOPTIONS );
2189 pPrinter->SetOptions( aSet );
2192 PostPaintGridAll(); //! nur wenn geaendert
2195 void ScDocShell::GetState( SfxItemSet &rSet )
2197 SfxWhichIter aIter(rSet);
2198 USHORT nWhich = aIter.FirstWhich();
2199 while ( nWhich )
2201 switch (nWhich)
2203 case FID_AUTO_CALC:
2204 if ( (BOOL) aDocument.GetHardRecalcState() )
2205 rSet.DisableItem( nWhich );
2206 else
2207 rSet.Put( SfxBoolItem( nWhich, aDocument.GetAutoCalc() ) );
2208 break;
2210 case FID_CHG_RECORD:
2211 if ( IsDocShared() )
2212 rSet.DisableItem( nWhich );
2213 else
2214 rSet.Put( SfxBoolItem( nWhich,
2215 aDocument.GetChangeTrack() != NULL ) );
2216 break;
2218 case SID_CHG_PROTECT:
2220 ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
2221 if ( pChangeTrack && !IsDocShared() )
2222 rSet.Put( SfxBoolItem( nWhich,
2223 pChangeTrack->IsProtected() ) );
2224 else
2225 rSet.DisableItem( nWhich );
2227 break;
2229 case SID_DOCUMENT_COMPARE:
2231 if ( IsDocShared() )
2233 rSet.DisableItem( nWhich );
2236 break;
2238 // Wenn eine Formel editiert wird, muss FID_RECALC auf jeden Fall enabled sein.
2239 // Recalc fuer das Doc war mal wegen #29898# disabled, wenn AutoCalc an war,
2240 // ist jetzt wegen #41540# aber auch immer enabled.
2241 // case FID_RECALC:
2242 // if ( aDocument.GetAutoCalc() )
2243 // rSet.DisableItem( nWhich );
2244 // break;
2246 case SID_TABLES_COUNT:
2247 rSet.Put( SfxInt16Item( nWhich, aDocument.GetTableCount() ) );
2248 break;
2250 case SID_ATTR_YEAR2000 :
2251 rSet.Put( SfxUInt16Item( nWhich,
2252 aDocument.GetDocOptions().GetYear2000() ) );
2253 break;
2255 case SID_SHARE_DOC:
2257 if ( IsReadOnly() )
2259 rSet.DisableItem( nWhich );
2262 break;
2264 default:
2267 break;
2270 nWhich = aIter.NextWhich();
2274 void ScDocShell::GetSbxState( SfxItemSet &rSet )
2276 // SID_SC_SELECTION (Selection),
2277 // SID_SC_ACTIVECELL (ActiveCell),
2278 // SID_SC_ACTIVETAB (ActiveTable),
2279 // SID_TABLES_GET (Tables),
2280 // SID_PIVOT_GET (DataPilotTables) - removed (old Basic)
2283 // Wenn hier Slots von der View-Shell executed werden, muss auch der
2284 // GetState weitergeleitet werden!
2287 ScTabViewShell* pVisibleSh = GetBestViewShell(); // sichtbare View
2288 if ( pVisibleSh )
2289 pVisibleSh->GetState( rSet );
2292 void __EXPORT ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, USHORT nAspect )
2294 // bIsOle = TRUE; // jetzt ueber den CreateMode
2296 SCTAB nVisTab = aDocument.GetVisibleTab();
2297 if (!aDocument.HasTable(nVisTab))
2298 return;
2300 ULONG nOldLayoutMode = pDev->GetLayoutMode();
2301 pDev->SetLayoutMode( TEXT_LAYOUT_DEFAULT ); // even if it's the same, to get the metafile action
2303 if ( nAspect == ASPECT_THUMBNAIL )
2305 Rectangle aBoundRect = GetVisArea( ASPECT_THUMBNAIL );
2306 ScViewData aTmpData( this, NULL );
2307 aTmpData.SetTabNo(nVisTab);
2308 aDocument.SnapVisArea( aBoundRect );
2309 aTmpData.SetScreen( aBoundRect );
2310 ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, TRUE );
2312 else
2314 Rectangle aBoundRect = SfxObjectShell::GetVisArea();
2315 ScViewData aTmpData( this, NULL );
2316 aTmpData.SetTabNo(nVisTab);
2317 aDocument.SnapVisArea( aBoundRect );
2318 aTmpData.SetScreen( aBoundRect );
2319 ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, TRUE );
2322 pDev->SetLayoutMode( nOldLayoutMode );
2325 Rectangle __EXPORT ScDocShell::GetVisArea( USHORT nAspect ) const
2327 SfxObjectCreateMode eShellMode = GetCreateMode();
2328 if ( eShellMode == SFX_CREATE_MODE_ORGANIZER )
2330 // ohne Inhalte wissen wir auch nicht, wie gross die Inhalte sind
2331 // leeres Rechteck zurueckgeben, das wird dann nach dem Laden berechnet
2332 return Rectangle();
2335 if( nAspect == ASPECT_THUMBNAIL )
2337 // Rectangle aArea( 0,0, 3175,3175 ); // 120x120 Pixel in 1:1
2338 Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X,SC_PREVIEW_SIZE_Y );
2339 BOOL bNegativePage = aDocument.IsNegativePage( aDocument.GetVisibleTab() );
2340 if ( bNegativePage )
2341 ScDrawLayer::MirrorRectRTL( aArea );
2342 aDocument.SnapVisArea( aArea );
2343 return aArea;
2345 else if( nAspect == ASPECT_CONTENT && eShellMode != SFX_CREATE_MODE_EMBEDDED )
2347 // Visarea holen wie nach Load
2349 SCTAB nVisTab = aDocument.GetVisibleTab();
2350 if (!aDocument.HasTable(nVisTab))
2352 nVisTab = 0;
2353 ((ScDocShell*)this)->aDocument.SetVisibleTab(nVisTab);
2355 SCCOL nStartCol;
2356 SCROW nStartRow;
2357 aDocument.GetDataStart( nVisTab, nStartCol, nStartRow );
2358 SCCOL nEndCol;
2359 SCROW nEndRow;
2360 aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow );
2361 if (nStartCol>nEndCol)
2362 nStartCol = nEndCol;
2363 if (nStartRow>nEndRow)
2364 nStartRow = nEndRow;
2365 Rectangle aNewArea = ((ScDocument&)aDocument)
2366 .GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab );
2367 //TODO/LATER: different methods for setting VisArea?!
2368 ((ScDocShell*)this)->SfxObjectShell::SetVisArea( aNewArea );
2369 return aNewArea;
2371 else
2372 return SfxObjectShell::GetVisArea( nAspect );
2375 void ScDocShell::GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
2376 SCTAB nCurTab,
2377 BOOL& rbHeader,
2378 BOOL& rbFooter )
2380 if ( !pStyleSet )
2382 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
2383 SfxStyleSheetBase* pStyleSheet = pStylePool->
2384 Find( aDocument.GetPageStyle( nCurTab ),
2385 SFX_STYLE_FAMILY_PAGE );
2387 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
2389 if ( pStyleSheet )
2390 pStyleSet = &pStyleSheet->GetItemSet();
2391 else
2392 rbHeader = rbFooter = FALSE;
2395 DBG_ASSERT( pStyleSet, "PageStyle-Set not found! :-(" );
2397 //--------------------------------------------------------------------
2399 const SvxSetItem* pSetItem = NULL;
2400 const SfxItemSet* pSet = NULL;
2402 pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_HEADERSET );
2403 pSet = &pSetItem->GetItemSet();
2404 rbHeader = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue();
2406 pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_FOOTERSET );
2407 pSet = &pSetItem->GetItemSet();
2408 rbFooter = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue();
2411 long __EXPORT ScDocShell::DdeGetData( const String& rItem,
2412 const String& rMimeType,
2413 ::com::sun::star::uno::Any & rValue )
2415 if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ) )
2417 if( rItem.EqualsIgnoreCaseAscii( "Format" ) )
2419 ByteString aFmtByte( aDdeTextFmt, gsl_getSystemTextEncoding() );
2420 rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
2421 (sal_Int8*)aFmtByte.GetBuffer(),
2422 aFmtByte.Len() + 1 );
2423 return 1;
2425 ScImportExport aObj( &aDocument, rItem );
2426 if ( !aObj.IsRef() )
2427 return 0; // ungueltiger Bereich
2429 if( aDdeTextFmt.GetChar(0) == 'F' )
2430 aObj.SetFormulas( TRUE );
2431 if( aDdeTextFmt.EqualsAscii( "SYLK" ) ||
2432 aDdeTextFmt.EqualsAscii( "FSYLK" ) )
2434 ByteString aData;
2435 if( aObj.ExportByteString( aData, gsl_getSystemTextEncoding(),
2436 SOT_FORMATSTR_ID_SYLK ) )
2438 rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
2439 (sal_Int8*)aData.GetBuffer(),
2440 aData.Len() + 1 );
2441 return 1;
2443 else
2444 return 0;
2446 if( aDdeTextFmt.EqualsAscii( "CSV" ) ||
2447 aDdeTextFmt.EqualsAscii( "FCSV" ) )
2448 aObj.SetSeparator( ',' );
2449 aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2450 return aObj.ExportData( rMimeType, rValue ) ? 1 : 0;
2453 ScImportExport aObj( &aDocument, rItem );
2454 aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2455 if( aObj.IsRef() )
2456 return aObj.ExportData( rMimeType, rValue ) ? 1 : 0;
2457 return 0;
2460 long __EXPORT ScDocShell::DdeSetData( const String& rItem,
2461 const String& rMimeType,
2462 const ::com::sun::star::uno::Any & rValue )
2464 if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ))
2466 if( rItem.EqualsIgnoreCaseAscii( "Format" ) )
2468 if ( ScByteSequenceToString::GetString( aDdeTextFmt, rValue, gsl_getSystemTextEncoding() ) )
2470 aDdeTextFmt.ToUpperAscii();
2471 return 1;
2473 return 0;
2475 ScImportExport aObj( &aDocument, rItem );
2476 if( aDdeTextFmt.GetChar(0) == 'F' )
2477 aObj.SetFormulas( TRUE );
2478 if( aDdeTextFmt.EqualsAscii( "SYLK" ) ||
2479 aDdeTextFmt.EqualsAscii( "FSYLK" ) )
2481 String aData;
2482 if ( ScByteSequenceToString::GetString( aData, rValue, gsl_getSystemTextEncoding() ) )
2484 return aObj.ImportString( aData, SOT_FORMATSTR_ID_SYLK ) ? 1 : 0;
2486 return 0;
2488 if( aDdeTextFmt.EqualsAscii( "CSV" ) ||
2489 aDdeTextFmt.EqualsAscii( "FCSV" ) )
2490 aObj.SetSeparator( ',' );
2491 return aObj.ImportData( rMimeType, rValue ) ? 1 : 0;
2493 ScImportExport aObj( &aDocument, rItem );
2494 if( aObj.IsRef() )
2495 return aObj.ImportData( rMimeType, rValue ) ? 1 : 0;
2496 return 0;
2499 ::sfx2::SvLinkSource* __EXPORT ScDocShell::DdeCreateLinkSource( const String& rItem )
2501 // only check for valid item string - range is parsed again in ScServerObject ctor
2503 // named range?
2504 String aPos = rItem;
2505 ScRangeName* pRange = aDocument.GetRangeName();
2506 if( pRange )
2508 USHORT nPos;
2509 if( pRange->SearchName( aPos, nPos ) )
2511 ScRangeData* pData = (*pRange)[ nPos ];
2512 if( pData->HasType( RT_REFAREA )
2513 || pData->HasType( RT_ABSAREA )
2514 || pData->HasType( RT_ABSPOS ) )
2515 pData->GetSymbol( aPos ); // continue with the name's contents
2519 // Address in DDE function must be always parsed as CONV_OOO so that it
2520 // would always work regardless of current address convension. We do this
2521 // because the address item in a DDE entry is *not* normalized when saved
2522 // into ODF.
2523 ScRange aRange;
2524 bool bValid = ( (aRange.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO ) & SCA_VALID) ||
2525 (aRange.aStart.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO) & SCA_VALID) );
2527 ScServerObject* pObj = NULL; // NULL = error
2528 if ( bValid )
2529 pObj = new ScServerObject( this, rItem );
2531 // GetLinkManager()->InsertServer() is in the ScServerObject ctor
2533 return pObj;
2536 //------------------------------------------------------------------
2538 ScViewData* ScDocShell::GetViewData()
2540 SfxViewShell* pCur = SfxViewShell::Current();
2541 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pCur);
2542 return pViewSh ? pViewSh->GetViewData() : NULL;
2545 //------------------------------------------------------------------
2547 SCTAB ScDocShell::GetCurTab()
2549 //! this must be made non-static and use a ViewShell from this document!
2551 ScViewData* pViewData = GetViewData();
2553 return pViewData ? pViewData->GetTabNo() : static_cast<SCTAB>(0);
2556 ScTabViewShell* ScDocShell::GetBestViewShell( BOOL bOnlyVisible )
2558 ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
2559 // falsches Doc?
2560 if( pViewSh && pViewSh->GetViewData()->GetDocShell() != this )
2561 pViewSh = NULL;
2562 if( !pViewSh )
2564 // 1. ViewShell suchen
2565 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, TYPE(SfxTopViewFrame), bOnlyVisible );
2566 if( pFrame )
2568 SfxViewShell* p = pFrame->GetViewShell();
2569 pViewSh = PTR_CAST(ScTabViewShell,p);
2572 return pViewSh;
2575 SfxBindings* ScDocShell::GetViewBindings()
2577 // used to invalidate slots after changes to this document
2579 SfxViewShell* pViewSh = GetBestViewShell();
2580 if (pViewSh)
2581 return &pViewSh->GetViewFrame()->GetBindings();
2582 else
2583 return NULL;
2586 //------------------------------------------------------------------
2588 ScDocShell* ScDocShell::GetShellByNum( USHORT nDocNo ) // static
2590 ScDocShell* pFound = NULL;
2591 SfxObjectShell* pShell = SfxObjectShell::GetFirst();
2592 USHORT nShellCnt = 0;
2594 while ( pShell && !pFound )
2596 if ( pShell->Type() == TYPE(ScDocShell) )
2598 if ( nShellCnt == nDocNo )
2599 pFound = (ScDocShell*) pShell;
2600 else
2601 ++nShellCnt;
2603 pShell = SfxObjectShell::GetNext( *pShell );
2606 return pFound;
2609 //------------------------------------------------------------------
2611 IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
2613 DBG_ASSERT( _pFileDlg, "ScDocShell::DialogClosedHdl(): no file dialog" );
2614 DBG_ASSERT( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
2616 if ( ERRCODE_NONE == _pFileDlg->GetError() )
2618 USHORT nSlot = pImpl->pRequest->GetSlot();
2619 SfxMedium* pMed = pImpl->pDocInserter->CreateMedium();
2620 // #i87094# If a .odt was selected pMed is NULL.
2621 if (pMed)
2623 pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
2624 if ( SID_DOCUMENT_COMPARE == nSlot )
2626 if ( pMed->GetFilter() )
2627 pImpl->pRequest->AppendItem(
2628 SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
2629 String sOptions = ScDocumentLoader::GetOptions( *pMed );
2630 if ( sOptions.Len() > 0 )
2631 pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2633 const SfxPoolItem* pItem = NULL;
2634 SfxItemSet* pSet = pMed->GetItemSet();
2635 if ( pSet &&
2636 pSet->GetItemState( SID_VERSION, TRUE, &pItem ) == SFX_ITEM_SET &&
2637 pItem->ISA( SfxInt16Item ) )
2639 pImpl->pRequest->AppendItem( *pItem );
2642 Execute( *(pImpl->pRequest) );
2646 pImpl->bIgnoreLostRedliningWarning = false;
2647 return 0;
2650 //------------------------------------------------------------------
2652 void ScDocShell::EnableSharedSettings( bool bEnable )
2654 SetDocumentModified();
2656 if ( bEnable )
2658 aDocument.EndChangeTracking();
2659 aDocument.StartChangeTracking();
2661 // hide accept or reject changes dialog
2662 USHORT nId = ScAcceptChgDlgWrapper::GetChildWindowId();
2663 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
2664 if ( pViewFrame && pViewFrame->HasChildWindow( nId ) )
2666 pViewFrame->ToggleChildWindow( nId );
2667 SfxBindings* pBindings = GetViewBindings();
2668 if ( pBindings )
2670 pBindings->Invalidate( FID_CHG_ACCEPT );
2674 else
2676 aDocument.EndChangeTracking();
2679 ScChangeViewSettings aChangeViewSet;
2680 aChangeViewSet.SetShowChanges( FALSE );
2681 aDocument.SetChangeViewSettings( aChangeViewSet );
2684 uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument()
2686 uno::Reference< frame::XModel > xModel;
2689 SC_MOD()->SetInSharedDocLoading( true );
2690 uno::Reference< lang::XMultiServiceFactory > xFactory(
2691 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
2692 uno::Reference< frame::XComponentLoader > xLoader(
2693 xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ),
2694 uno::UNO_QUERY_THROW );
2695 uno::Sequence < beans::PropertyValue > aArgs( 1 );
2696 aArgs[0].Name = ::rtl::OUString::createFromAscii( "Hidden" );
2697 aArgs[0].Value <<= sal_True;
2699 if ( GetMedium() )
2701 SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False);
2702 if ( pPasswordItem && pPasswordItem->GetValue().Len() )
2704 aArgs.realloc( 2 );
2705 aArgs[1].Name = ::rtl::OUString::createFromAscii( "Password" );
2706 aArgs[1].Value <<= ::rtl::OUString( pPasswordItem->GetValue() );
2710 xModel.set(
2711 xLoader->loadComponentFromURL( GetSharedFileURL(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, aArgs ),
2712 uno::UNO_QUERY_THROW );
2713 SC_MOD()->SetInSharedDocLoading( false );
2715 catch ( uno::Exception& )
2717 DBG_ERROR( "ScDocShell::LoadSharedDocument(): caught exception\n" );
2718 SC_MOD()->SetInSharedDocLoading( false );
2721 uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
2722 xClose->close( sal_True );
2723 return uno::Reference< frame::XModel >();
2725 catch ( uno::Exception& )
2727 return uno::Reference< frame::XModel >();
2730 return xModel;