merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / docshell / docsh4.cxx
blobdbbaef061182f8ead621885df70703aa90e08f35
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 )
1268 pSh->UpdateCharts(TRUE);
1270 aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
1272 // #47939# Wenn es Charts gibt, dann alles painten, damit nicht
1273 // PostDataChanged und die Charts nacheinander kommen und Teile
1274 // doppelt gepainted werden.
1276 ScChartListenerCollection* pCharts = aDocument.GetChartListenerCollection();
1277 if ( pCharts && pCharts->GetCount() )
1278 PostPaintGridAll();
1279 else
1280 PostDataChanged();
1284 void ScDocShell::DoHardRecalc( BOOL /* bApi */ )
1286 WaitObject aWaitObj( GetActiveDialogParent() );
1287 ScTabViewShell* pSh = GetBestViewShell();
1288 if ( pSh )
1290 pSh->UpdateInputLine(); // InputEnterHandler
1291 pSh->UpdateInputHandler();
1293 aDocument.CalcAll();
1294 GetDocFunc().DetectiveRefresh(); // erzeugt eigenes Undo
1295 if ( pSh )
1296 pSh->UpdateCharts(TRUE);
1298 // CalcAll doesn't broadcast value changes, so SC_HINT_CALCALL is broadcasted globally
1299 // in addition to SFX_HINT_DATACHANGED.
1300 aDocument.BroadcastUno( SfxSimpleHint( SC_HINT_CALCALL ) );
1301 aDocument.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED ) );
1303 // use hard recalc also to disable stream-copying of all sheets
1304 // (somewhat consistent with charts)
1305 SCTAB nTabCount = aDocument.GetTableCount();
1306 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1307 if (aDocument.IsStreamValid(nTab))
1308 aDocument.SetStreamValid(nTab, FALSE);
1310 PostPaintGridAll();
1313 //------------------------------------------------------------------
1315 void ScDocShell::DoAutoStyle( const ScRange& rRange, const String& rStyle )
1317 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1318 ScStyleSheet* pStyleSheet =
1319 pStylePool->FindCaseIns( rStyle, SFX_STYLE_FAMILY_PARA );
1320 if (!pStyleSheet)
1321 pStyleSheet = (ScStyleSheet*)
1322 pStylePool->Find( ScGlobal::GetRscString(STR_STYLENAME_STANDARD), SFX_STYLE_FAMILY_PARA );
1323 if (pStyleSheet)
1325 DBG_ASSERT(rRange.aStart.Tab() == rRange.aEnd.Tab(),
1326 "DoAutoStyle mit mehreren Tabellen");
1327 SCTAB nTab = rRange.aStart.Tab();
1328 SCCOL nStartCol = rRange.aStart.Col();
1329 SCROW nStartRow = rRange.aStart.Row();
1330 SCCOL nEndCol = rRange.aEnd.Col();
1331 SCROW nEndRow = rRange.aEnd.Row();
1332 aDocument.ApplyStyleAreaTab( nStartCol, nStartRow, nEndCol, nEndRow, nTab, *pStyleSheet );
1333 aDocument.ExtendMerge( nStartCol, nStartRow, nEndCol, nEndRow, nTab );
1334 PostPaint( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab, PAINT_GRID );
1338 //------------------------------------------------------------------
1340 void ScDocShell::NotifyStyle( const SfxStyleSheetHint& rHint )
1342 USHORT nId = rHint.GetHint();
1343 const SfxStyleSheetBase* pStyle = rHint.GetStyleSheet();
1344 if (!pStyle)
1345 return;
1347 if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PAGE )
1349 if ( nId == SFX_STYLESHEET_MODIFIED )
1351 ScDocShellModificator aModificator( *this );
1353 String aNewName = pStyle->GetName();
1354 String aOldName = aNewName;
1355 BOOL bExtended = rHint.ISA(SfxStyleSheetHintExtended); // Name geaendert?
1356 if (bExtended)
1357 aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName();
1359 if ( aNewName != aOldName )
1360 aDocument.RenamePageStyleInUse( aOldName, aNewName );
1362 SCTAB nTabCount = aDocument.GetTableCount();
1363 for (SCTAB nTab=0; nTab<nTabCount; nTab++)
1364 if (aDocument.GetPageStyle(nTab) == aNewName) // schon auf neu angepasst
1366 aDocument.PageStyleModified( nTab, aNewName );
1367 ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1368 aPrintFunc.UpdatePages();
1371 aModificator.SetDocumentModified();
1373 if (bExtended)
1375 SfxBindings* pBindings = GetViewBindings();
1376 if (pBindings)
1378 pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1379 pBindings->Invalidate( SID_STYLE_FAMILY4 );
1380 pBindings->Invalidate( FID_RESET_PRINTZOOM );
1381 pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1382 pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1387 else if ( pStyle->GetFamily() == SFX_STYLE_FAMILY_PARA )
1389 if ( nId == SFX_STYLESHEET_MODIFIED)
1391 String aNewName = pStyle->GetName();
1392 String aOldName = aNewName;
1393 BOOL bExtended = rHint.ISA(SfxStyleSheetHintExtended);
1394 if (bExtended)
1395 aOldName = ((SfxStyleSheetHintExtended&)rHint).GetOldName();
1396 if ( aNewName != aOldName )
1398 ScConditionalFormatList* pList = aDocument.GetCondFormList();
1399 if (pList)
1400 pList->RenameCellStyle( aOldName,aNewName );
1405 // alles andere geht ueber Slots...
1408 // wie in printfun.cxx
1409 #define ZOOM_MIN 10
1411 void ScDocShell::SetPrintZoom( SCTAB nTab, USHORT nScale, USHORT nPages )
1413 BOOL bUndo(aDocument.IsUndoEnabled());
1414 String aStyleName = aDocument.GetPageStyle( nTab );
1415 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1416 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
1417 DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1418 if ( pStyleSheet )
1420 ScDocShellModificator aModificator( *this );
1422 SfxItemSet& rSet = pStyleSheet->GetItemSet();
1423 if (bUndo)
1425 USHORT nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue();
1426 USHORT nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
1427 GetUndoManager()->AddUndoAction( new ScUndoPrintZoom(
1428 this, nTab, nOldScale, nOldPages, nScale, nPages ) );
1431 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALE, nScale ) );
1432 rSet.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES, nPages ) );
1434 ScPrintFunc aPrintFunc( this, GetPrinter(), nTab );
1435 aPrintFunc.UpdatePages();
1436 aModificator.SetDocumentModified();
1438 SfxBindings* pBindings = GetViewBindings();
1439 if (pBindings)
1440 pBindings->Invalidate( FID_RESET_PRINTZOOM );
1444 BOOL ScDocShell::AdjustPrintZoom( const ScRange& rRange )
1446 BOOL bChange = FALSE;
1447 SCTAB nTab = rRange.aStart.Tab();
1449 String aStyleName = aDocument.GetPageStyle( nTab );
1450 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1451 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName, SFX_STYLE_FAMILY_PAGE );
1452 DBG_ASSERT( pStyleSheet, "PageStyle not found" );
1453 if ( pStyleSheet )
1455 SfxItemSet& rSet = pStyleSheet->GetItemSet();
1456 BOOL bHeaders = ((const SfxBoolItem&)rSet.Get(ATTR_PAGE_HEADERS)).GetValue();
1457 USHORT nOldScale = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALE)).GetValue();
1458 USHORT nOldPages = ((const SfxUInt16Item&)rSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
1459 const ScRange* pRepeatCol = aDocument.GetRepeatColRange( nTab );
1460 const ScRange* pRepeatRow = aDocument.GetRepeatRowRange( nTab );
1462 // benoetigte Skalierung fuer Selektion ausrechnen
1464 USHORT nNewScale = nOldScale;
1466 long nBlkTwipsX = 0;
1467 if (bHeaders)
1468 nBlkTwipsX += (long) PRINT_HEADER_WIDTH;
1469 SCCOL nStartCol = rRange.aStart.Col();
1470 SCCOL nEndCol = rRange.aEnd.Col();
1471 if ( pRepeatCol && nStartCol >= pRepeatCol->aStart.Col() )
1473 for (SCCOL i=pRepeatCol->aStart.Col(); i<=pRepeatCol->aEnd.Col(); i++ )
1474 nBlkTwipsX += aDocument.GetColWidth( i, nTab );
1475 if ( nStartCol <= pRepeatCol->aEnd.Col() )
1476 nStartCol = pRepeatCol->aEnd.Col() + 1;
1478 // legacy compilers' own scope for i
1480 for ( SCCOL i=nStartCol; i<=nEndCol; i++ )
1481 nBlkTwipsX += aDocument.GetColWidth( i, nTab );
1484 long nBlkTwipsY = 0;
1485 if (bHeaders)
1486 nBlkTwipsY += (long) PRINT_HEADER_HEIGHT;
1487 SCROW nStartRow = rRange.aStart.Row();
1488 SCROW nEndRow = rRange.aEnd.Row();
1489 if ( pRepeatRow && nStartRow >= pRepeatRow->aStart.Row() )
1491 nBlkTwipsY += aDocument.FastGetRowHeight( pRepeatRow->aStart.Row(),
1492 pRepeatRow->aEnd.Row(), nTab );
1493 if ( nStartRow <= pRepeatRow->aEnd.Row() )
1494 nStartRow = pRepeatRow->aEnd.Row() + 1;
1496 nBlkTwipsY += aDocument.FastGetRowHeight( nStartRow, nEndRow, nTab );
1498 Size aPhysPage;
1499 long nHdr, nFtr;
1500 ScPrintFunc aOldPrFunc( this, GetPrinter(), nTab );
1501 aOldPrFunc.GetScaleData( aPhysPage, nHdr, nFtr );
1502 nBlkTwipsY += nHdr + nFtr;
1504 if ( nBlkTwipsX == 0 ) // #100639# hidden columns/rows may lead to 0
1505 nBlkTwipsX = 1;
1506 if ( nBlkTwipsY == 0 )
1507 nBlkTwipsY = 1;
1509 long nNeeded = Min( aPhysPage.Width() * 100 / nBlkTwipsX,
1510 aPhysPage.Height() * 100 / nBlkTwipsY );
1511 if ( nNeeded < ZOOM_MIN )
1512 nNeeded = ZOOM_MIN; // Begrenzung
1513 if ( nNeeded < (long) nNewScale )
1514 nNewScale = (USHORT) nNeeded;
1516 bChange = ( nNewScale != nOldScale || nOldPages != 0 );
1517 if ( bChange )
1518 SetPrintZoom( nTab, nNewScale, 0 );
1520 return bChange;
1523 void ScDocShell::PageStyleModified( const String& rStyleName, BOOL bApi )
1525 ScDocShellModificator aModificator( *this );
1527 BOOL bWarn = FALSE;
1529 SCTAB nTabCount = aDocument.GetTableCount();
1530 SCTAB nUseTab = MAXTAB+1;
1531 for (SCTAB nTab=0; nTab<nTabCount && nUseTab>MAXTAB; nTab++)
1532 if ( aDocument.GetPageStyle(nTab) == rStyleName &&
1533 ( !bApi || aDocument.GetPageSize(nTab).Width() ) )
1534 nUseTab = nTab;
1535 // bei bApi nur, wenn Umbrueche schon angezeigt
1537 if (ValidTab(nUseTab)) // nicht verwendet -> nichts zu tun
1539 ScPrintFunc aPrintFunc( this, GetPrinter(), nUseTab ); //! ohne CountPages auskommen
1540 if (!aPrintFunc.UpdatePages()) // setzt Umbrueche auf allen Tabs
1541 bWarn = TRUE;
1543 if (bWarn && !bApi)
1545 ScWaitCursorOff aWaitOff( GetActiveDialogParent() );
1546 InfoBox aInfoBox(GetActiveDialogParent(),
1547 ScGlobal::GetRscString(STR_PRINT_INVALID_AREA));
1548 aInfoBox.Execute();
1552 aModificator.SetDocumentModified();
1554 SfxBindings* pBindings = GetViewBindings();
1555 if (pBindings)
1557 pBindings->Invalidate( FID_RESET_PRINTZOOM );
1558 pBindings->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
1559 pBindings->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
1563 void ScDocShell::ExecutePageStyle( SfxViewShell& rCaller,
1564 SfxRequest& rReq,
1565 SCTAB nCurTab )
1567 const SfxItemSet* pReqArgs = rReq.GetArgs();
1569 switch ( rReq.GetSlot() )
1571 case SID_STATUS_PAGESTYLE: // Click auf StatusBar-Control
1572 case SID_FORMATPAGE:
1574 if ( pReqArgs != NULL )
1577 else if ( pReqArgs == NULL )
1579 BOOL bUndo(aDocument.IsUndoEnabled());
1580 String aOldName = aDocument.GetPageStyle( nCurTab );
1581 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1582 SfxStyleSheetBase* pStyleSheet
1583 = pStylePool->Find( aOldName, SFX_STYLE_FAMILY_PAGE );
1585 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1587 if ( pStyleSheet )
1589 ScStyleSaveData aOldData;
1590 if (bUndo)
1591 aOldData.InitFromStyle( pStyleSheet );
1593 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1595 //CHINA001 ScStyleDlg* pDlg = new ScStyleDlg( GetActiveDialogParent(),
1596 //CHINA001 *pStyleSheet,
1597 //CHINA001 RID_SCDLG_STYLES_PAGE );
1598 //CHINA001
1599 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1600 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1602 SfxAbstractTabDialog* pDlg = pFact->CreateScStyleDlg( GetActiveDialogParent(), *pStyleSheet, RID_SCDLG_STYLES_PAGE, RID_SCDLG_STYLES_PAGE );
1603 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1605 if ( pDlg->Execute() == RET_OK )
1607 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1609 WaitObject aWait( GetActiveDialogParent() );
1611 String aNewName = pStyleSheet->GetName();
1612 if ( aNewName != aOldName &&
1613 aDocument.RenamePageStyleInUse( aOldName, aNewName ) )
1615 SfxBindings* pBindings = GetViewBindings();
1616 if (pBindings)
1618 pBindings->Invalidate( SID_STATUS_PAGESTYLE );
1619 pBindings->Invalidate( FID_RESET_PRINTZOOM );
1623 if ( pOutSet )
1624 aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1626 // merken fuer GetState():
1627 GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
1628 rCaller.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT );
1630 ScStyleSaveData aNewData;
1631 aNewData.InitFromStyle( pStyleSheet );
1632 if (bUndo)
1634 GetUndoManager()->AddUndoAction(
1635 new ScUndoModifyStyle( this, SFX_STYLE_FAMILY_PAGE,
1636 aOldData, aNewData ) );
1639 PageStyleModified( aNewName, FALSE );
1640 rReq.Done();
1642 delete pDlg;
1644 rStyleSet.ClearItem( ATTR_PAGE_PAPERTRAY );
1648 break;
1650 case SID_HFEDIT:
1652 if ( pReqArgs != NULL )
1655 else if ( pReqArgs == NULL )
1657 String aStr( aDocument.GetPageStyle( nCurTab ) );
1659 ScStyleSheetPool* pStylePool
1660 = aDocument.GetStyleSheetPool();
1662 SfxStyleSheetBase* pStyleSheet
1663 = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE );
1665 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1667 if ( pStyleSheet )
1669 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1671 SvxPageUsage eUsage =
1672 SvxPageUsage( ((const SvxPageItem&)
1673 rStyleSet.Get( ATTR_PAGE )).
1674 GetPageUsage() );
1675 BOOL bShareHeader = IS_SHARE_HEADER(rStyleSet);
1676 BOOL bShareFooter = IS_SHARE_FOOTER(rStyleSet);
1677 USHORT nResId = 0;
1679 switch ( eUsage )
1681 case SVX_PAGE_LEFT:
1682 case SVX_PAGE_RIGHT:
1684 if ( bHeaderOn && bFooterOn )
1685 nResId = RID_SCDLG_HFEDIT;
1686 else if ( SVX_PAGE_RIGHT == eUsage )
1688 if ( !bHeaderOn && bFooterOn )
1689 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1690 else if ( bHeaderOn && !bFooterOn )
1691 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1693 else
1695 // #69193a# respect "shared" setting
1696 if ( !bHeaderOn && bFooterOn )
1697 nResId = bShareFooter ?
1698 RID_SCDLG_HFEDIT_RIGHTFOOTER :
1699 RID_SCDLG_HFEDIT_LEFTFOOTER;
1700 else if ( bHeaderOn && !bFooterOn )
1701 nResId = bShareHeader ?
1702 RID_SCDLG_HFEDIT_RIGHTHEADER :
1703 RID_SCDLG_HFEDIT_LEFTHEADER;
1706 break;
1708 case SVX_PAGE_MIRROR:
1709 case SVX_PAGE_ALL:
1710 default:
1712 if ( !bShareHeader && !bShareFooter )
1714 if ( bHeaderOn && bFooterOn )
1715 nResId = RID_SCDLG_HFEDIT_ALL;
1716 else if ( !bHeaderOn && bFooterOn )
1717 nResId = RID_SCDLG_HFEDIT_FOOTER;
1718 else if ( bHeaderOn && !bFooterOn )
1719 nResId = RID_SCDLG_HFEDIT_HEADER;
1721 else if ( bShareHeader && bShareFooter )
1723 if ( bHeaderOn && bFooterOn )
1724 nResId = RID_SCDLG_HFEDIT;
1725 else
1727 if ( !bHeaderOn && bFooterOn )
1728 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1729 else if ( bHeaderOn && !bFooterOn )
1730 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1733 else if ( !bShareHeader && bShareFooter )
1735 if ( bHeaderOn && bFooterOn )
1736 nResId = RID_SCDLG_HFEDIT_SFTR;
1737 else if ( !bHeaderOn && bFooterOn )
1738 nResId = RID_SCDLG_HFEDIT_RIGHTFOOTER;
1739 else if ( bHeaderOn && !bFooterOn )
1740 nResId = RID_SCDLG_HFEDIT_HEADER;
1742 else if ( bShareHeader && !bShareFooter )
1744 if ( bHeaderOn && bFooterOn )
1745 nResId = RID_SCDLG_HFEDIT_SHDR;
1746 else if ( !bHeaderOn && bFooterOn )
1747 nResId = RID_SCDLG_HFEDIT_FOOTER;
1748 else if ( bHeaderOn && !bFooterOn )
1749 nResId = RID_SCDLG_HFEDIT_RIGHTHEADER;
1754 //CHINA001 ScHFEditDlg* pDlg
1755 //CHINA001 = new ScHFEditDlg( SFX_APP()->GetViewFrame(),
1756 //CHINA001 GetActiveDialogParent(),
1757 //CHINA001 rStyleSet,
1758 //CHINA001 aStr,
1759 //CHINA001 nResId );
1760 //CHINA001
1761 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
1762 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
1764 SfxAbstractTabDialog* pDlg = pFact->CreateScHFEditDlg( SfxViewFrame::Current(),
1765 GetActiveDialogParent(),
1766 rStyleSet,
1767 aStr,
1768 RID_SCDLG_HFEDIT, nResId);
1769 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
1770 if ( pDlg->Execute() == RET_OK )
1772 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1774 if ( pOutSet )
1775 aDocument.ModifyStyleSheet( *pStyleSheet, *pOutSet );
1777 SetDocumentModified();
1778 rReq.Done();
1780 delete pDlg;
1784 break;
1786 default:
1787 break;
1791 void ScDocShell::GetStatePageStyle( SfxViewShell& /* rCaller */,
1792 SfxItemSet& rSet,
1793 SCTAB nCurTab )
1795 SfxWhichIter aIter(rSet);
1796 USHORT nWhich = aIter.FirstWhich();
1797 while ( nWhich )
1799 switch (nWhich)
1801 case SID_STATUS_PAGESTYLE:
1802 rSet.Put( SfxStringItem( nWhich, aDocument.GetPageStyle( nCurTab ) ) );
1803 break;
1805 case SID_HFEDIT:
1807 String aStr = aDocument.GetPageStyle( nCurTab );
1808 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
1809 SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStr, SFX_STYLE_FAMILY_PAGE );
1811 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
1813 if ( pStyleSheet )
1815 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1817 GetPageOnFromPageStyleSet( &rStyleSet, nCurTab, bHeaderOn, bFooterOn );
1819 if ( !bHeaderOn && !bFooterOn )
1820 rSet.DisableItem( nWhich );
1823 break;
1826 nWhich = aIter.NextWhich();
1830 void lcl_GetPrintData( ScDocShell* pDocShell /*in*/,
1831 ScDocument* pDocument /*in*/, SfxPrinter* pPrinter /*in*/,
1832 PrintDialog* pPrintDialog /*in*/, bool bForceSelected /*in*/,
1833 ScMarkData* pMarkData /*inout*/, bool& rbHasOptions /*out*/,
1834 ScPrintOptions& rOptions /*out*/, bool& rbAllTabs /*out*/,
1835 long& rnTotalPages /*out*/, long aPageArr[] /*out*/,
1836 MultiSelection& rPageRanges /*out*/, ScRange** ppMarkedRange /*out*/ )
1838 // get settings from print options sub-dialog
1839 const SfxItemSet& rOptionSet = pPrinter->GetOptions();
1840 const SfxPoolItem* pItem;
1841 rbHasOptions = ( rOptionSet.GetItemState( SID_SCPRINTOPTIONS, FALSE, &pItem ) == SFX_ITEM_SET );
1842 if ( rbHasOptions )
1844 rOptions = ((const ScTpPrintItem*)pItem)->GetPrintOptions();
1846 else
1848 // use configuration
1849 rOptions = SC_MOD()->GetPrintOptions();
1852 // update all pending row heights with a single progress bar,
1853 // instead of a separate progress for each sheet from ScPrintFunc
1854 pDocShell->UpdatePendingRowHeights( MAXTAB, true );
1856 // get number of total pages
1857 rnTotalPages = 0;
1858 SCTAB nTabCount = pDocument->GetTableCount();
1859 for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
1861 ScPrintFunc aPrintFunc( pDocShell, pPrinter, nTab, 0, 0, NULL, &rOptions );
1862 long nThisTab = aPrintFunc.GetTotalPages();
1863 aPageArr[nTab] = nThisTab;
1864 rnTotalPages += nThisTab;
1867 rPageRanges.SetTotalRange( Range( 0, RANGE_MAX ) );
1868 rPageRanges.Select( Range( 1, rnTotalPages ) );
1870 rbAllTabs = ( pPrintDialog ? ( pPrintDialog->GetCheckedSheetRange() == PRINTSHEETS_ALL ) : SC_MOD()->GetPrintOptions().GetAllSheets() );
1871 if ( bForceSelected )
1873 rbAllTabs = false;
1876 if ( ( pPrintDialog && pPrintDialog->GetCheckedSheetRange() == PRINTSHEETS_SELECTED_CELLS ) || bForceSelected )
1878 if ( pMarkData && ( pMarkData->IsMarked() || pMarkData->IsMultiMarked() ) )
1880 pMarkData->MarkToMulti();
1881 *ppMarkedRange = new ScRange;
1882 pMarkData->GetMultiMarkArea( **ppMarkedRange );
1883 pMarkData->MarkToSimple();
1887 PrintDialogRange eDlgOption = pPrintDialog ? pPrintDialog->GetCheckedRange() : PRINTDIALOG_ALL;
1888 if ( eDlgOption == PRINTDIALOG_RANGE )
1890 rPageRanges = MultiSelection( pPrintDialog->GetRangeText() );
1893 // get number of total pages if selection
1894 if ( !rbAllTabs )
1896 rnTotalPages = 0;
1897 for ( SCTAB nTab = 0; nTab < nTabCount; ++nTab )
1899 if ( *ppMarkedRange ) // selected range is used instead of print ranges -> page count is different
1901 ScPrintFunc aPrintFunc( pDocShell, pPrinter, nTab, 0, 0, *ppMarkedRange, &rOptions );
1902 aPageArr[nTab] = aPrintFunc.GetTotalPages();
1904 if ( !pMarkData || pMarkData->GetTableSelect( nTab ) )
1906 rnTotalPages += aPageArr[nTab];
1909 if ( eDlgOption == PRINTDIALOG_ALL || bForceSelected )
1911 rPageRanges.Select( Range( 1, rnTotalPages ) );
1916 bool ScDocShell::CheckPrint( PrintDialog* pPrintDialog, ScMarkData* pMarkData, bool bForceSelected, bool bIsAPI )
1918 SfxPrinter* pPrinter = GetPrinter();
1919 if ( !pPrinter )
1921 return false;
1924 bool bHasOptions = false;
1925 ScPrintOptions aOptions;
1926 bool bAllTabs = true;
1927 long nTotalPages = 0;
1928 long aPageArr[MAXTABCOUNT]; // pages per sheet
1929 MultiSelection aPageRanges; // pages to print
1930 ScRange* pMarkedRange = NULL;
1932 lcl_GetPrintData( this, &aDocument, pPrinter, pPrintDialog, bForceSelected,
1933 pMarkData, bHasOptions, aOptions, bAllTabs, nTotalPages,
1934 aPageArr, aPageRanges, &pMarkedRange );
1936 delete pMarkedRange;
1938 if ( nTotalPages == 0 )
1940 if ( !bIsAPI )
1942 WarningBox aWarningBox( GetActiveDialogParent(), WinBits( WB_OK ),
1943 String( ScResId( STR_PRINT_NOTHING ) ) );
1944 aWarningBox.Execute();
1946 return false;
1949 return true;
1952 void ScDocShell::PreparePrint( PrintDialog* pPrintDialog, ScMarkData* pMarkData )
1954 SfxPrinter* pPrinter = GetPrinter();
1955 if ( !pPrinter )
1957 return;
1960 delete pOldJobSetup; // gesetzt nur bei Fehler in StartJob()
1961 pOldJobSetup = new ScJobSetup( pPrinter ); // Einstellungen merken
1963 // Einstellungen fuer die erste gedruckte Seite muessen hier (vor StartJob) gesetzt werden
1964 //! Selection etc. mit Print() zusammenfassen !!!
1965 //! Seiten nur einmal zaehlen
1967 bool bHasOptions = false;
1968 ScPrintOptions aOptions;
1969 bool bAllTabs = true;
1970 long nTotalPages = 0;
1971 long aPageArr[MAXTABCOUNT]; // pages per sheet
1972 MultiSelection aPageRanges; // pages to print
1973 ScRange* pMarkedRange = NULL;
1975 lcl_GetPrintData( this, &aDocument, pPrinter, pPrintDialog, false,
1976 pMarkData, bHasOptions, aOptions, bAllTabs, nTotalPages,
1977 aPageArr, aPageRanges, &pMarkedRange );
1979 BOOL bFound = FALSE; // erste Seite gefunden
1980 long nTabStart = 0;
1981 SCTAB nTabCount = aDocument.GetTableCount();
1982 for ( SCTAB nTab=0; nTab<nTabCount && !bFound; nTab++ )
1984 if ( bAllTabs || !pMarkData || pMarkData->GetTableSelect( nTab ) )
1986 long nNext = nTabStart + aPageArr[nTab];
1987 BOOL bSelected = FALSE;
1988 for (long nP=nTabStart+1; nP<=nNext; nP++) // 1-basiert
1989 if (aPageRanges.IsSelected( nP )) // eine Seite von dieser Tabelle selektiert?
1990 bSelected = TRUE;
1992 if (bSelected)
1994 ScPrintFunc aPrintFunc( this, pPrinter, nTab );
1996 aPrintFunc.ApplyPrintSettings(); // dann Settings fuer diese Tabelle
1997 bFound = TRUE;
1999 nTabStart = nNext;
2003 delete pMarkedRange;
2006 BOOL lcl_HasTransparent( ScDocument* pDoc, SCTAB nTab, const ScRange* pRange )
2008 BOOL bFound = FALSE;
2009 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
2010 if (pDrawLayer)
2012 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
2013 DBG_ASSERT(pPage,"Page ?");
2014 if (pPage)
2016 Rectangle aMMRect;
2017 if ( pRange )
2018 aMMRect = pDoc->GetMMRect( pRange->aStart.Col(), pRange->aStart.Row(),
2019 pRange->aEnd.Col(), pRange->aEnd.Row(), nTab );
2021 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
2022 SdrObject* pObject = aIter.Next();
2023 while (pObject && !bFound)
2025 if (pObject->IsTransparent())
2027 if ( pRange )
2029 Rectangle aObjRect = pObject->GetLogicRect();
2030 if ( aObjRect.IsOver( aMMRect ) )
2031 bFound = TRUE;
2033 else
2034 bFound = TRUE;
2037 pObject = aIter.Next();
2042 return bFound;
2045 void ScDocShell::Print( SfxProgress& rProgress, PrintDialog* pPrintDialog,
2046 ScMarkData* pMarkData, Window* pDialogParent, BOOL bForceSelected, BOOL bIsAPI )
2048 SfxPrinter* pPrinter = GetPrinter();
2049 if ( !pPrinter )
2051 return;
2054 bool bHasOptions = false;
2055 ScPrintOptions aOptions;
2056 bool bAllTabs = true;
2057 long nTotalPages = 0;
2058 long aPageArr[MAXTABCOUNT]; // pages per sheet
2059 MultiSelection aPageRanges; // pages to print
2060 ScRange* pMarkedRange = NULL;
2062 lcl_GetPrintData( this, &aDocument, pPrinter, pPrintDialog, bForceSelected,
2063 pMarkData, bHasOptions, aOptions, bAllTabs, nTotalPages,
2064 aPageArr, aPageRanges, &pMarkedRange );
2066 USHORT nCollateCopies = 1;
2067 if ( pPrintDialog && pPrintDialog->IsCollateEnabled() && pPrintDialog->IsCollateChecked() )
2068 nCollateCopies = pPrintDialog->GetCopyCount();
2070 // test if printed range contains transparent objects
2072 BOOL bHasTransp = FALSE;
2073 BOOL bAnyPrintRanges = aDocument.HasPrintRange();
2074 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
2075 SCTAB nTabCount = aDocument.GetTableCount();
2076 for ( SCTAB nTab=0; nTab<nTabCount && !bHasTransp; nTab++ )
2078 if ( bAllTabs || !pMarkData || pMarkData->GetTableSelect( nTab ) )
2080 SfxStyleSheetBase* pStyleSheet = pStylePool->Find(
2081 aDocument.GetPageStyle( nTab ), SFX_STYLE_FAMILY_PAGE );
2082 if ( pStyleSheet )
2084 const SfxItemSet& rSet = pStyleSheet->GetItemSet();
2085 if ( ((const ScViewObjectModeItem&)rSet.Get(ATTR_PAGE_CHARTS)).GetValue() == VOBJ_MODE_SHOW ||
2086 ((const ScViewObjectModeItem&)rSet.Get(ATTR_PAGE_OBJECTS)).GetValue() == VOBJ_MODE_SHOW ||
2087 ((const ScViewObjectModeItem&)rSet.Get(ATTR_PAGE_DRAWINGS)).GetValue() == VOBJ_MODE_SHOW )
2089 if ( pMarkedRange )
2090 bHasTransp = bHasTransp || lcl_HasTransparent( &aDocument, nTab, pMarkedRange );
2091 else if ( aDocument.GetPrintRangeCount(nTab) )
2093 USHORT nRangeCount = aDocument.GetPrintRangeCount(nTab);
2094 for (USHORT i=0; i<nRangeCount; i++)
2095 bHasTransp = bHasTransp ||
2096 lcl_HasTransparent( &aDocument, nTab, aDocument.GetPrintRange( nTab, i ) );
2098 else if (!bAnyPrintRanges || aDocument.IsPrintEntireSheet(nTab))
2099 bHasTransp = bHasTransp || lcl_HasTransparent( &aDocument, nTab, NULL );
2105 BOOL bContinue = pPrinter->InitJob( pDialogParent, !bIsAPI && bHasTransp );
2107 if ( bContinue )
2109 for ( USHORT n=0; n<nCollateCopies; n++ )
2111 long nTabStart = 0;
2112 long nDisplayStart = 0;
2113 long nAttrPage = 1;
2114 long nPrinted = 0;
2116 for ( SCTAB nTab=0; nTab<nTabCount; nTab++ )
2118 if ( bAllTabs || !pMarkData || pMarkData->GetTableSelect( nTab ) )
2120 FmFormView* pDrawView = NULL;
2121 Rectangle aFull( 0, 0, LONG_MAX, LONG_MAX );
2123 // #114135#
2124 ScDrawLayer* pModel = aDocument.GetDrawLayer(); // ist nicht NULL
2126 if(pModel)
2128 pDrawView = new FmFormView( pModel, pPrinter );
2129 pDrawView->ShowSdrPage(pDrawView->GetModel()->GetPage(nTab));
2130 pDrawView->SetPrintPreview( TRUE );
2133 ScPrintFunc aPrintFunc( this, pPrinter, nTab, nAttrPage, nTotalPages, pMarkedRange, &aOptions );
2134 aPrintFunc.SetDrawView( pDrawView );
2135 nPrinted += aPrintFunc.DoPrint( aPageRanges, nTabStart, nDisplayStart, TRUE, &rProgress, NULL );
2137 nTabStart += aPageArr[nTab];
2138 if ( aDocument.NeedPageResetAfterTab(nTab) )
2139 nDisplayStart = 0;
2140 else
2141 nDisplayStart += aPageArr[nTab];
2142 nAttrPage = aPrintFunc.GetFirstPageNo(); // behalten oder aus Vorlage
2144 delete pDrawView;
2148 if ( n+1 < nCollateCopies && pPrinter->GetDuplexMode() == DUPLEX_ON && ( nPrinted % 2 ) == 1 )
2150 // #105584# when several collated copies are printed in duplex mode, and there is
2151 // an odd number of pages, print an empty page between copies, so the first page of
2152 // the second copy isn't printed on the back of the last page of the first copy.
2153 // (same as in Writer ViewShell::Prt)
2155 pPrinter->StartPage();
2156 pPrinter->EndPage();
2161 delete pMarkedRange;
2163 if (pOldJobSetup)
2165 pPrinter->SetOrientation( pOldJobSetup->eOrientation );
2166 pPrinter->SetPaperBin ( pOldJobSetup->nPaperBin );
2167 pPrinter->SetPaper ( pOldJobSetup->ePaper );
2169 if ( PAPER_USER == pOldJobSetup->ePaper )
2171 pPrinter->SetMapMode( pOldJobSetup->aUserMapMode );
2172 pPrinter->SetPaperSizeUser( pOldJobSetup->aUserSize );
2175 delete pOldJobSetup;
2176 pOldJobSetup = NULL;
2179 if ( bHasOptions )
2181 // remove PrintOptions from printer ItemSet,
2182 // so next time the options from the configuration are used
2184 SfxItemSet aSet( pPrinter->GetOptions() );
2185 aSet.ClearItem( SID_SCPRINTOPTIONS );
2186 pPrinter->SetOptions( aSet );
2189 PostPaintGridAll(); //! nur wenn geaendert
2192 void ScDocShell::GetState( SfxItemSet &rSet )
2194 SfxWhichIter aIter(rSet);
2195 USHORT nWhich = aIter.FirstWhich();
2196 while ( nWhich )
2198 switch (nWhich)
2200 case FID_AUTO_CALC:
2201 if ( (BOOL) aDocument.GetHardRecalcState() )
2202 rSet.DisableItem( nWhich );
2203 else
2204 rSet.Put( SfxBoolItem( nWhich, aDocument.GetAutoCalc() ) );
2205 break;
2207 case FID_CHG_RECORD:
2208 if ( IsDocShared() )
2209 rSet.DisableItem( nWhich );
2210 else
2211 rSet.Put( SfxBoolItem( nWhich,
2212 aDocument.GetChangeTrack() != NULL ) );
2213 break;
2215 case SID_CHG_PROTECT:
2217 ScChangeTrack* pChangeTrack = aDocument.GetChangeTrack();
2218 if ( pChangeTrack && !IsDocShared() )
2219 rSet.Put( SfxBoolItem( nWhich,
2220 pChangeTrack->IsProtected() ) );
2221 else
2222 rSet.DisableItem( nWhich );
2224 break;
2226 case SID_DOCUMENT_COMPARE:
2228 if ( IsDocShared() )
2230 rSet.DisableItem( nWhich );
2233 break;
2235 // Wenn eine Formel editiert wird, muss FID_RECALC auf jeden Fall enabled sein.
2236 // Recalc fuer das Doc war mal wegen #29898# disabled, wenn AutoCalc an war,
2237 // ist jetzt wegen #41540# aber auch immer enabled.
2238 // case FID_RECALC:
2239 // if ( aDocument.GetAutoCalc() )
2240 // rSet.DisableItem( nWhich );
2241 // break;
2243 case SID_TABLES_COUNT:
2244 rSet.Put( SfxInt16Item( nWhich, aDocument.GetTableCount() ) );
2245 break;
2247 case SID_ATTR_YEAR2000 :
2248 rSet.Put( SfxUInt16Item( nWhich,
2249 aDocument.GetDocOptions().GetYear2000() ) );
2250 break;
2252 case SID_SHARE_DOC:
2254 if ( IsReadOnly() )
2256 rSet.DisableItem( nWhich );
2259 break;
2261 default:
2264 break;
2267 nWhich = aIter.NextWhich();
2271 void ScDocShell::GetSbxState( SfxItemSet &rSet )
2273 // SID_SC_SELECTION (Selection),
2274 // SID_SC_ACTIVECELL (ActiveCell),
2275 // SID_SC_ACTIVETAB (ActiveTable),
2276 // SID_TABLES_GET (Tables),
2277 // SID_PIVOT_GET (DataPilotTables) - removed (old Basic)
2280 // Wenn hier Slots von der View-Shell executed werden, muss auch der
2281 // GetState weitergeleitet werden!
2284 ScTabViewShell* pVisibleSh = GetBestViewShell(); // sichtbare View
2285 if ( pVisibleSh )
2286 pVisibleSh->GetState( rSet );
2289 void __EXPORT ScDocShell::Draw( OutputDevice* pDev, const JobSetup & /* rSetup */, USHORT nAspect )
2291 // bIsOle = TRUE; // jetzt ueber den CreateMode
2293 SCTAB nVisTab = aDocument.GetVisibleTab();
2294 if (!aDocument.HasTable(nVisTab))
2295 return;
2297 ULONG nOldLayoutMode = pDev->GetLayoutMode();
2298 pDev->SetLayoutMode( TEXT_LAYOUT_DEFAULT ); // even if it's the same, to get the metafile action
2300 if ( nAspect == ASPECT_THUMBNAIL )
2302 Rectangle aBoundRect = GetVisArea( ASPECT_THUMBNAIL );
2303 ScViewData aTmpData( this, NULL );
2304 aTmpData.SetTabNo(nVisTab);
2305 aDocument.SnapVisArea( aBoundRect );
2306 aTmpData.SetScreen( aBoundRect );
2307 ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, TRUE );
2309 else
2311 Rectangle aBoundRect = SfxObjectShell::GetVisArea();
2312 ScViewData aTmpData( this, NULL );
2313 aTmpData.SetTabNo(nVisTab);
2314 aDocument.SnapVisArea( aBoundRect );
2315 aTmpData.SetScreen( aBoundRect );
2316 ScPrintFunc::DrawToDev( &aDocument, pDev, 1.0, aBoundRect, &aTmpData, TRUE );
2319 pDev->SetLayoutMode( nOldLayoutMode );
2322 Rectangle __EXPORT ScDocShell::GetVisArea( USHORT nAspect ) const
2324 SfxObjectCreateMode eShellMode = GetCreateMode();
2325 if ( eShellMode == SFX_CREATE_MODE_ORGANIZER )
2327 // ohne Inhalte wissen wir auch nicht, wie gross die Inhalte sind
2328 // leeres Rechteck zurueckgeben, das wird dann nach dem Laden berechnet
2329 return Rectangle();
2332 if( nAspect == ASPECT_THUMBNAIL )
2334 // Rectangle aArea( 0,0, 3175,3175 ); // 120x120 Pixel in 1:1
2335 Rectangle aArea( 0,0, SC_PREVIEW_SIZE_X,SC_PREVIEW_SIZE_Y );
2336 BOOL bNegativePage = aDocument.IsNegativePage( aDocument.GetVisibleTab() );
2337 if ( bNegativePage )
2338 ScDrawLayer::MirrorRectRTL( aArea );
2339 aDocument.SnapVisArea( aArea );
2340 return aArea;
2342 else if( nAspect == ASPECT_CONTENT && eShellMode != SFX_CREATE_MODE_EMBEDDED )
2344 // Visarea holen wie nach Load
2346 SCTAB nVisTab = aDocument.GetVisibleTab();
2347 if (!aDocument.HasTable(nVisTab))
2349 nVisTab = 0;
2350 ((ScDocShell*)this)->aDocument.SetVisibleTab(nVisTab);
2352 SCCOL nStartCol;
2353 SCROW nStartRow;
2354 aDocument.GetDataStart( nVisTab, nStartCol, nStartRow );
2355 SCCOL nEndCol;
2356 SCROW nEndRow;
2357 aDocument.GetPrintArea( nVisTab, nEndCol, nEndRow );
2358 if (nStartCol>nEndCol)
2359 nStartCol = nEndCol;
2360 if (nStartRow>nEndRow)
2361 nStartRow = nEndRow;
2362 Rectangle aNewArea = ((ScDocument&)aDocument)
2363 .GetMMRect( nStartCol,nStartRow, nEndCol,nEndRow, nVisTab );
2364 //TODO/LATER: different methods for setting VisArea?!
2365 ((ScDocShell*)this)->SfxObjectShell::SetVisArea( aNewArea );
2366 return aNewArea;
2368 else
2369 return SfxObjectShell::GetVisArea( nAspect );
2372 void ScDocShell::GetPageOnFromPageStyleSet( const SfxItemSet* pStyleSet,
2373 SCTAB nCurTab,
2374 BOOL& rbHeader,
2375 BOOL& rbFooter )
2377 if ( !pStyleSet )
2379 ScStyleSheetPool* pStylePool = aDocument.GetStyleSheetPool();
2380 SfxStyleSheetBase* pStyleSheet = pStylePool->
2381 Find( aDocument.GetPageStyle( nCurTab ),
2382 SFX_STYLE_FAMILY_PAGE );
2384 DBG_ASSERT( pStyleSheet, "PageStyle not found! :-/" );
2386 if ( pStyleSheet )
2387 pStyleSet = &pStyleSheet->GetItemSet();
2388 else
2389 rbHeader = rbFooter = FALSE;
2392 DBG_ASSERT( pStyleSet, "PageStyle-Set not found! :-(" );
2394 //--------------------------------------------------------------------
2396 const SvxSetItem* pSetItem = NULL;
2397 const SfxItemSet* pSet = NULL;
2399 pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_HEADERSET );
2400 pSet = &pSetItem->GetItemSet();
2401 rbHeader = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue();
2403 pSetItem = (const SvxSetItem*) &pStyleSet->Get( ATTR_PAGE_FOOTERSET );
2404 pSet = &pSetItem->GetItemSet();
2405 rbFooter = ((const SfxBoolItem&)pSet->Get(ATTR_PAGE_ON)).GetValue();
2408 long __EXPORT ScDocShell::DdeGetData( const String& rItem,
2409 const String& rMimeType,
2410 ::com::sun::star::uno::Any & rValue )
2412 if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ) )
2414 if( rItem.EqualsIgnoreCaseAscii( "Format" ) )
2416 ByteString aFmtByte( aDdeTextFmt, gsl_getSystemTextEncoding() );
2417 rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
2418 (sal_Int8*)aFmtByte.GetBuffer(),
2419 aFmtByte.Len() + 1 );
2420 return 1;
2422 ScImportExport aObj( &aDocument, rItem );
2423 if ( !aObj.IsRef() )
2424 return 0; // ungueltiger Bereich
2426 if( aDdeTextFmt.GetChar(0) == 'F' )
2427 aObj.SetFormulas( TRUE );
2428 if( aDdeTextFmt.EqualsAscii( "SYLK" ) ||
2429 aDdeTextFmt.EqualsAscii( "FSYLK" ) )
2431 ByteString aData;
2432 if( aObj.ExportByteString( aData, gsl_getSystemTextEncoding(),
2433 SOT_FORMATSTR_ID_SYLK ) )
2435 rValue <<= ::com::sun::star::uno::Sequence< sal_Int8 >(
2436 (sal_Int8*)aData.GetBuffer(),
2437 aData.Len() + 1 );
2438 return 1;
2440 else
2441 return 0;
2443 if( aDdeTextFmt.EqualsAscii( "CSV" ) ||
2444 aDdeTextFmt.EqualsAscii( "FCSV" ) )
2445 aObj.SetSeparator( ',' );
2446 aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2447 return aObj.ExportData( rMimeType, rValue ) ? 1 : 0;
2450 ScImportExport aObj( &aDocument, rItem );
2451 aObj.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace, 0, false ) );
2452 if( aObj.IsRef() )
2453 return aObj.ExportData( rMimeType, rValue ) ? 1 : 0;
2454 return 0;
2457 long __EXPORT ScDocShell::DdeSetData( const String& rItem,
2458 const String& rMimeType,
2459 const ::com::sun::star::uno::Any & rValue )
2461 if( FORMAT_STRING == SotExchange::GetFormatIdFromMimeType( rMimeType ))
2463 if( rItem.EqualsIgnoreCaseAscii( "Format" ) )
2465 if ( ScByteSequenceToString::GetString( aDdeTextFmt, rValue, gsl_getSystemTextEncoding() ) )
2467 aDdeTextFmt.ToUpperAscii();
2468 return 1;
2470 return 0;
2472 ScImportExport aObj( &aDocument, rItem );
2473 if( aDdeTextFmt.GetChar(0) == 'F' )
2474 aObj.SetFormulas( TRUE );
2475 if( aDdeTextFmt.EqualsAscii( "SYLK" ) ||
2476 aDdeTextFmt.EqualsAscii( "FSYLK" ) )
2478 String aData;
2479 if ( ScByteSequenceToString::GetString( aData, rValue, gsl_getSystemTextEncoding() ) )
2481 return aObj.ImportString( aData, SOT_FORMATSTR_ID_SYLK ) ? 1 : 0;
2483 return 0;
2485 if( aDdeTextFmt.EqualsAscii( "CSV" ) ||
2486 aDdeTextFmt.EqualsAscii( "FCSV" ) )
2487 aObj.SetSeparator( ',' );
2488 return aObj.ImportData( rMimeType, rValue ) ? 1 : 0;
2490 ScImportExport aObj( &aDocument, rItem );
2491 if( aObj.IsRef() )
2492 return aObj.ImportData( rMimeType, rValue ) ? 1 : 0;
2493 return 0;
2496 ::sfx2::SvLinkSource* __EXPORT ScDocShell::DdeCreateLinkSource( const String& rItem )
2498 // only check for valid item string - range is parsed again in ScServerObject ctor
2500 // named range?
2501 String aPos = rItem;
2502 ScRangeName* pRange = aDocument.GetRangeName();
2503 if( pRange )
2505 USHORT nPos;
2506 if( pRange->SearchName( aPos, nPos ) )
2508 ScRangeData* pData = (*pRange)[ nPos ];
2509 if( pData->HasType( RT_REFAREA )
2510 || pData->HasType( RT_ABSAREA )
2511 || pData->HasType( RT_ABSPOS ) )
2512 pData->GetSymbol( aPos ); // continue with the name's contents
2516 // Address in DDE function must be always parsed as CONV_OOO so that it
2517 // would always work regardless of current address convension. We do this
2518 // because the address item in a DDE entry is *not* normalized when saved
2519 // into ODF.
2520 ScRange aRange;
2521 bool bValid = ( (aRange.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO ) & SCA_VALID) ||
2522 (aRange.aStart.Parse(aPos, &aDocument, formula::FormulaGrammar::CONV_OOO) & SCA_VALID) );
2524 ScServerObject* pObj = NULL; // NULL = error
2525 if ( bValid )
2526 pObj = new ScServerObject( this, rItem );
2528 // GetLinkManager()->InsertServer() is in the ScServerObject ctor
2530 return pObj;
2533 //------------------------------------------------------------------
2535 ScViewData* ScDocShell::GetViewData()
2537 SfxViewShell* pCur = SfxViewShell::Current();
2538 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pCur);
2539 return pViewSh ? pViewSh->GetViewData() : NULL;
2542 //------------------------------------------------------------------
2544 SCTAB ScDocShell::GetCurTab()
2546 //! this must be made non-static and use a ViewShell from this document!
2548 ScViewData* pViewData = GetViewData();
2550 return pViewData ? pViewData->GetTabNo() : static_cast<SCTAB>(0);
2553 ScTabViewShell* ScDocShell::GetBestViewShell( BOOL bOnlyVisible )
2555 ScTabViewShell* pViewSh = ScTabViewShell::GetActiveViewShell();
2556 // falsches Doc?
2557 if( pViewSh && pViewSh->GetViewData()->GetDocShell() != this )
2558 pViewSh = NULL;
2559 if( !pViewSh )
2561 // 1. ViewShell suchen
2562 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( this, TYPE(SfxTopViewFrame), bOnlyVisible );
2563 if( pFrame )
2565 SfxViewShell* p = pFrame->GetViewShell();
2566 pViewSh = PTR_CAST(ScTabViewShell,p);
2569 return pViewSh;
2572 SfxBindings* ScDocShell::GetViewBindings()
2574 // used to invalidate slots after changes to this document
2576 SfxViewShell* pViewSh = GetBestViewShell();
2577 if (pViewSh)
2578 return &pViewSh->GetViewFrame()->GetBindings();
2579 else
2580 return NULL;
2583 //------------------------------------------------------------------
2585 ScDocShell* ScDocShell::GetShellByNum( USHORT nDocNo ) // static
2587 ScDocShell* pFound = NULL;
2588 SfxObjectShell* pShell = SfxObjectShell::GetFirst();
2589 USHORT nShellCnt = 0;
2591 while ( pShell && !pFound )
2593 if ( pShell->Type() == TYPE(ScDocShell) )
2595 if ( nShellCnt == nDocNo )
2596 pFound = (ScDocShell*) pShell;
2597 else
2598 ++nShellCnt;
2600 pShell = SfxObjectShell::GetNext( *pShell );
2603 return pFound;
2606 //------------------------------------------------------------------
2608 IMPL_LINK( ScDocShell, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg )
2610 DBG_ASSERT( _pFileDlg, "ScDocShell::DialogClosedHdl(): no file dialog" );
2611 DBG_ASSERT( pImpl->pDocInserter, "ScDocShell::DialogClosedHdl(): no document inserter" );
2613 if ( ERRCODE_NONE == _pFileDlg->GetError() )
2615 USHORT nSlot = pImpl->pRequest->GetSlot();
2616 SfxMedium* pMed = pImpl->pDocInserter->CreateMedium();
2617 // #i87094# If a .odt was selected pMed is NULL.
2618 if (pMed)
2620 pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_NAME, pMed->GetName() ) );
2621 if ( SID_DOCUMENT_COMPARE == nSlot )
2623 if ( pMed->GetFilter() )
2624 pImpl->pRequest->AppendItem(
2625 SfxStringItem( SID_FILTER_NAME, pMed->GetFilter()->GetFilterName() ) );
2626 String sOptions = ScDocumentLoader::GetOptions( *pMed );
2627 if ( sOptions.Len() > 0 )
2628 pImpl->pRequest->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS, sOptions ) );
2630 const SfxPoolItem* pItem = NULL;
2631 SfxItemSet* pSet = pMed->GetItemSet();
2632 if ( pSet &&
2633 pSet->GetItemState( SID_VERSION, TRUE, &pItem ) == SFX_ITEM_SET &&
2634 pItem->ISA( SfxInt16Item ) )
2636 pImpl->pRequest->AppendItem( *pItem );
2639 Execute( *(pImpl->pRequest) );
2643 pImpl->bIgnoreLostRedliningWarning = false;
2644 return 0;
2647 //------------------------------------------------------------------
2649 void ScDocShell::EnableSharedSettings( bool bEnable )
2651 SetDocumentModified();
2653 if ( bEnable )
2655 aDocument.EndChangeTracking();
2656 aDocument.StartChangeTracking();
2658 // hide accept or reject changes dialog
2659 USHORT nId = ScAcceptChgDlgWrapper::GetChildWindowId();
2660 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
2661 if ( pViewFrame && pViewFrame->HasChildWindow( nId ) )
2663 pViewFrame->ToggleChildWindow( nId );
2664 SfxBindings* pBindings = GetViewBindings();
2665 if ( pBindings )
2667 pBindings->Invalidate( FID_CHG_ACCEPT );
2671 else
2673 aDocument.EndChangeTracking();
2676 ScChangeViewSettings aChangeViewSet;
2677 aChangeViewSet.SetShowChanges( FALSE );
2678 aDocument.SetChangeViewSettings( aChangeViewSet );
2681 uno::Reference< frame::XModel > ScDocShell::LoadSharedDocument()
2683 uno::Reference< frame::XModel > xModel;
2686 SC_MOD()->SetInSharedDocLoading( true );
2687 uno::Reference< lang::XMultiServiceFactory > xFactory(
2688 ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY_THROW );
2689 uno::Reference< frame::XComponentLoader > xLoader(
2690 xFactory->createInstance( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.Desktop" ) ) ),
2691 uno::UNO_QUERY_THROW );
2692 uno::Sequence < beans::PropertyValue > aArgs( 1 );
2693 aArgs[0].Name = ::rtl::OUString::createFromAscii( "Hidden" );
2694 aArgs[0].Value <<= sal_True;
2696 if ( GetMedium() )
2698 SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem, SfxStringItem, SID_PASSWORD, sal_False);
2699 if ( pPasswordItem && pPasswordItem->GetValue().Len() )
2701 aArgs.realloc( 2 );
2702 aArgs[1].Name = ::rtl::OUString::createFromAscii( "Password" );
2703 aArgs[1].Value <<= ::rtl::OUString( pPasswordItem->GetValue() );
2707 xModel.set(
2708 xLoader->loadComponentFromURL( GetSharedFileURL(), ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "_blank" ) ), 0, aArgs ),
2709 uno::UNO_QUERY_THROW );
2710 SC_MOD()->SetInSharedDocLoading( false );
2712 catch ( uno::Exception& )
2714 DBG_ERROR( "ScDocShell::LoadSharedDocument(): caught exception\n" );
2715 SC_MOD()->SetInSharedDocLoading( false );
2718 uno::Reference< util::XCloseable > xClose( xModel, uno::UNO_QUERY_THROW );
2719 xClose->close( sal_True );
2720 return uno::Reference< frame::XModel >();
2722 catch ( uno::Exception& )
2724 return uno::Reference< frame::XModel >();
2727 return xModel;