1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_features.h>
22 #include <com/sun/star/embed/XEmbeddedObject.hpp>
23 #include <com/sun/star/frame/Desktop.hpp>
24 #include <com/sun/star/frame/XComponentLoader.hpp>
26 using namespace ::com::sun::star
;
30 #include "scitems.hxx"
31 #include <sfx2/fcontnr.hxx>
32 #include <sfx2/objface.hxx>
33 #include <sfx2/docfile.hxx>
34 #include <svtools/ehdl.hxx>
35 #include <basic/sbxcore.hxx>
36 #include <svtools/sfxecode.hxx>
37 #include <svx/ofaitem.hxx>
38 #include <svl/whiter.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <vcl/waitobj.hxx>
41 #include <svx/dataaccessdescriptor.hxx>
42 #include <svx/drawitem.hxx>
43 #include <svx/fmshell.hxx>
44 #include <svtools/xwindowitem.hxx>
45 #include <sfx2/passwd.hxx>
46 #include <sfx2/filedlghelper.hxx>
47 #include <sfx2/dispatch.hxx>
48 #include <svl/PasswordHelper.hxx>
49 #include <svl/documentlockfile.hxx>
50 #include <svl/sharecontrolfile.hxx>
52 #include <comphelper/processfactory.hxx>
55 #include <com/sun/star/sdbc/XResultSet.hpp>
57 #include "docshimp.hxx"
58 #include "docfunc.hxx"
60 #include "stlsheet.hxx"
61 #include "stlpool.hxx"
62 #include "appoptio.hxx"
63 #include "globstr.hrc"
65 #include "dbdocfun.hxx"
66 #include "printfun.hxx"
67 #include "viewdata.hxx"
68 #include "tabvwsh.hxx"
71 #include "undodat.hxx"
72 #include "autostyl.hxx"
73 #include "undocell.hxx"
74 #include "undotab.hxx"
75 #include "inputhdl.hxx"
77 #include "servobj.hxx"
78 #include "rangenam.hxx"
80 #include "chgviset.hxx"
81 #include "reffact.hxx"
82 #include "chartlis.hxx"
83 #include "chartpos.hxx"
84 #include "waitoff.hxx"
85 #include "tablink.hxx"
86 #include "drwlayer.hxx"
87 #include "docoptio.hxx"
88 #include "undostyl.hxx"
89 #include "rangeseq.hxx"
90 #include "chgtrack.hxx"
91 #include "printopt.hxx"
92 #include <com/sun/star/document/UpdateDocMode.hpp>
93 #include "scresid.hxx"
94 #include "scabstdlg.hxx"
95 #include "externalrefmgr.hxx"
96 #include "sharedocdlg.hxx"
97 #include "conditio.hxx"
98 #include "sheetevents.hxx"
100 //------------------------------------------------------------------
102 #define IS_SHARE_HEADER(set) \
104 ((SvxSetItem&)(set).Get(ATTR_PAGE_HEADERSET)).GetItemSet(). \
105 Get(ATTR_PAGE_SHARED)).GetValue()
107 #define IS_SHARE_FOOTER(set) \
109 ((SvxSetItem&)(set).Get(ATTR_PAGE_FOOTERSET)).GetItemSet(). \
110 Get(ATTR_PAGE_SHARED)).GetValue()
112 #define SC_PREVIEW_SIZE_X 10000
113 #define SC_PREVIEW_SIZE_Y 12400
116 //------------------------------------------------------------------
118 void ScDocShell::Execute( SfxRequest
& rReq
)
120 // SID_SC_RANGE (Range),
121 // SID_SC_CELLTEXT (CellText),
122 // SID_SC_CELLS (Cells) - removed (old Basic)
124 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
125 SfxBindings
* pBindings
= GetViewBindings();
126 sal_Bool
bUndo (aDocument
.IsUndoEnabled());
128 sal_uInt16 nSlot
= rReq
.GetSlot();
133 const SfxPoolItem
* pColItem
;
134 const SfxPoolItem
* pRowItem
;
135 const SfxPoolItem
* pTabItem
;
136 const SfxPoolItem
* pTextItem
;
137 if( pReqArgs
&& pReqArgs
->HasItem( FN_PARAM_1
, &pColItem
) &&
138 pReqArgs
->HasItem( FN_PARAM_2
, &pRowItem
) &&
139 pReqArgs
->HasItem( FN_PARAM_3
, &pTabItem
) &&
140 pReqArgs
->HasItem( SID_SC_SETTEXT
, &pTextItem
) )
142 // Parameter sind 1-based !!!
143 SCCOL nCol
= ((SfxInt16Item
*)pColItem
)->GetValue() - 1;
144 SCROW nRow
= ((SfxInt32Item
*)pRowItem
)->GetValue() - 1;
145 SCTAB nTab
= ((SfxInt16Item
*)pTabItem
)->GetValue() - 1;
147 SCTAB nTabCount
= aDocument
.GetTableCount();
148 if ( ValidCol(nCol
) && ValidRow(nRow
) && ValidTab(nTab
,nTabCount
) )
150 if ( aDocument
.IsBlockEditable( nTab
, nCol
,nRow
, nCol
, nRow
) )
152 OUString aVal
= ((const SfxStringItem
*)pTextItem
)->GetValue();
153 aDocument
.SetString( nCol
, nRow
, nTab
, aVal
);
155 PostPaintCell( nCol
, nRow
, nTab
);
156 SetDocumentModified();
161 else // geschuetzte Zelle
163 #ifndef DISABLE_SCRIPTING
164 SbxBase::SetError( SbxERR_BAD_PARAMETER
); //! welchen Fehler ?
170 #ifndef DISABLE_SCRIPTING
171 SbxBase::SetError( SbxERR_NO_OBJECT
);
180 const SfxPoolItem
* pItem
;
181 svx::ODataAccessDescriptor aDesc
;
182 if ( pReqArgs
->GetItemState( nSlot
, true, &pItem
) == SFX_ITEM_SET
)
184 uno::Any aAny
= static_cast<const SfxUsrAnyItem
*>(pItem
)->GetValue();
185 uno::Sequence
<beans::PropertyValue
> aProperties
;
186 if ( aAny
>>= aProperties
)
187 aDesc
.initializeFrom( aProperties
);
191 if ( pReqArgs
->GetItemState( FN_PARAM_1
, sal_True
, &pItem
) == SFX_ITEM_SET
)
192 sTarget
= ((const SfxStringItem
*)pItem
)->GetValue();
194 sal_Bool bIsNewArea
= sal_True
; // Default sal_True (keine Nachfrage)
195 if ( pReqArgs
->GetItemState( FN_PARAM_2
, sal_True
, &pItem
) == SFX_ITEM_SET
)
196 bIsNewArea
= ((const SfxBoolItem
*)pItem
)->GetValue();
198 // bei Bedarf neuen Datenbankbereich anlegen
199 bool bMakeArea
= false;
202 ScDBCollection
* pDBColl
= aDocument
.GetDBCollection();
203 if ( !pDBColl
|| !pDBColl
->getNamedDBs().findByUpperName(ScGlobal::pCharClass
->uppercase(sTarget
)) )
206 if ( aPos
.Parse( sTarget
, &aDocument
, aDocument
.GetAddressConvention() ) & SCA_VALID
)
211 OUString aStrImport
= ScGlobal::GetRscString( STR_UNDO_IMPORTDATA
);
212 GetUndoManager()->EnterListAction( aStrImport
, aStrImport
);
215 ScDBData
* pDBData
= GetDBData( ScRange(aPos
), SC_DB_IMPORT
, SC_DBSEL_KEEP
);
216 OSL_ENSURE(pDBData
, "kann DB-Daten nicht anlegen");
217 sTarget
= pDBData
->GetName();
222 // nachfragen, bevor alter DB-Bereich ueberschrieben wird
226 OUString aTemplate
= ScGlobal::GetRscString( STR_IMPORT_REPLACE
);
227 OUString aMessage
= aTemplate
.getToken( 0, '#' );
229 aMessage
+= aTemplate
.getToken( 1, '#' );
231 QueryBox
aBox( 0, WinBits(WB_YES_NO
| WB_DEF_YES
), aMessage
);
232 bDo
= ( aBox
.Execute() == RET_YES
);
237 ScDBDocFunc(*this).UpdateImport( sTarget
, aDesc
);
240 // UpdateImport aktualisiert auch die internen Operationen
245 if ( bMakeArea
&& bUndo
)
246 GetUndoManager()->LeaveListAction();
250 OSL_FAIL( "arguments expected" );
255 case SID_CHART_SOURCE
:
256 case SID_CHART_ADDSOURCE
:
259 ScDocument
* pDoc
= GetDocument();
260 const SfxPoolItem
* pItem
;
261 OUString aChartName
, aRangeName
;
263 ScRange aSingleRange
;
264 ScRangeListRef aRangeListRef
;
265 sal_Bool bMultiRange
= false;
267 sal_Bool bColHeaders
= sal_True
;
268 sal_Bool bRowHeaders
= sal_True
;
269 sal_Bool bColInit
= false;
270 sal_Bool bRowInit
= false;
271 sal_Bool bAddRange
= (nSlot
== SID_CHART_ADDSOURCE
);
273 if( pReqArgs
->HasItem( SID_CHART_NAME
, &pItem
) )
274 aChartName
= ((const SfxStringItem
*)pItem
)->GetValue();
276 if( pReqArgs
->HasItem( SID_CHART_SOURCE
, &pItem
) )
277 aRangeName
= ((const SfxStringItem
*)pItem
)->GetValue();
279 if( pReqArgs
->HasItem( FN_PARAM_1
, &pItem
) )
281 bColHeaders
= ((const SfxBoolItem
*)pItem
)->GetValue();
284 if( pReqArgs
->HasItem( FN_PARAM_2
, &pItem
) )
286 bRowHeaders
= ((const SfxBoolItem
*)pItem
)->GetValue();
290 ScAddress::Details
aDetails(pDoc
->GetAddressConvention(), 0, 0);
291 sal_Bool bValid
= ( aSingleRange
.ParseAny( aRangeName
, pDoc
, aDetails
) & SCA_VALID
) != 0;
294 aRangeListRef
= new ScRangeList
;
295 aRangeListRef
->Parse( aRangeName
, pDoc
);
296 if ( !aRangeListRef
->empty() )
299 aSingleRange
= *aRangeListRef
->front(); // fuer Header
303 aRangeListRef
.Clear();
306 ScTabViewShell
* pViewSh
= ScTabViewShell::GetActiveViewShell();
307 if (pViewSh
&& bValid
&& !aChartName
.isEmpty() )
309 Window
* pParent
= pViewSh
->GetDialogParent();
311 SCCOL nCol1
= aSingleRange
.aStart
.Col();
312 SCROW nRow1
= aSingleRange
.aStart
.Row();
313 SCCOL nCol2
= aSingleRange
.aEnd
.Col();
314 SCROW nRow2
= aSingleRange
.aEnd
.Row();
315 SCTAB nTab
= aSingleRange
.aStart
.Tab();
317 //! immer oder gar nicht begrenzen ???
319 aDocument
.LimitChartArea( nTab
, nCol1
,nRow1
, nCol2
,nRow2
);
321 // Dialog fuer Spalten/Zeilenkoepfe
322 sal_Bool bOk
= sal_True
;
323 if ( !bAddRange
&& ( !bColInit
|| !bRowInit
) )
325 ScChartPositioner
aChartPositioner( &aDocument
, nTab
, nCol1
,nRow1
, nCol2
,nRow2
);
327 bColHeaders
= aChartPositioner
.HasColHeaders();
329 bRowHeaders
= aChartPositioner
.HasRowHeaders();
331 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
332 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
334 AbstractScColRowLabelDlg
* pDlg
= pFact
->CreateScColRowLabelDlg( pParent
, RID_SCDLG_CHARTCOLROW
, bRowHeaders
, bColHeaders
);
335 OSL_ENSURE(pDlg
, "Dialog create fail!");
336 if ( pDlg
->Execute() == RET_OK
)
338 bColHeaders
= pDlg
->IsRow();
339 bRowHeaders
= pDlg
->IsCol();
341 rReq
.AppendItem(SfxBoolItem(FN_PARAM_1
, bColHeaders
));
342 rReq
.AppendItem(SfxBoolItem(FN_PARAM_2
, bRowHeaders
));
349 if (bOk
) // ausfuehren
355 GetUndoManager()->AddUndoAction(
356 new ScUndoChartData( this, aChartName
, aRangeListRef
,
357 bColHeaders
, bRowHeaders
, bAddRange
) );
359 aDocument
.UpdateChartArea( aChartName
, aRangeListRef
,
360 bColHeaders
, bRowHeaders
, bAddRange
);
364 ScRange
aNewRange( nCol1
,nRow1
,nTab
, nCol2
,nRow2
,nTab
);
367 GetUndoManager()->AddUndoAction(
368 new ScUndoChartData( this, aChartName
, aNewRange
,
369 bColHeaders
, bRowHeaders
, bAddRange
) );
371 aDocument
.UpdateChartArea( aChartName
, aNewRange
,
372 bColHeaders
, bRowHeaders
, bAddRange
);
378 OSL_FAIL("UpdateChartArea: keine ViewShell oder falsche Daten");
384 OSL_FAIL("SID_CHART_SOURCE ohne Argumente");
391 const SfxPoolItem
* pItem
;
392 if ( pReqArgs
&& SFX_ITEM_SET
== pReqArgs
->GetItemState( nSlot
, sal_True
, &pItem
) )
393 bNewVal
= ((const SfxBoolItem
*)pItem
)->GetValue();
395 bNewVal
= !aDocument
.GetAutoCalc(); // Toggle fuer Menue
396 aDocument
.SetAutoCalc( bNewVal
);
397 SetDocumentModified();
400 pBindings
->Invalidate( FID_AUTO_CALC
);
402 rReq
.AppendItem( SfxBoolItem( FID_AUTO_CALC
, bNewVal
) );
407 DoRecalc( rReq
.IsAPI() );
410 case FID_HARD_RECALC
:
411 DoHardRecalc( rReq
.IsAPI() );
414 case SID_UPDATETABLINKS
:
416 ScDocument
* pDoc
= GetDocument();
418 ScLkUpdMode nSet
=pDoc
->GetLinkMode();
420 sal_uInt16 nDlgRet
=RET_NO
;
423 ScAppOptions aAppOptions
=SC_MOD()->GetAppOptions();
424 nSet
=aAppOptions
.GetLinkMode();
427 if (nCanUpdate
== com::sun::star::document::UpdateDocMode::NO_UPDATE
)
429 else if (nCanUpdate
== com::sun::star::document::UpdateDocMode::QUIET_UPDATE
&&
430 nSet
== LM_ON_DEMAND
)
432 else if (nCanUpdate
== com::sun::star::document::UpdateDocMode::FULL_UPDATE
)
435 if(nSet
==LM_ON_DEMAND
)
437 QueryBox
aBox( GetActiveDialogParent(), WinBits(WB_YES_NO
| WB_DEF_YES
),
438 ScGlobal::GetRscString(STR_RELOAD_TABLES
) );
440 nDlgRet
=aBox
.Execute();
443 if (nDlgRet
== RET_YES
|| nSet
==LM_ALWAYS
)
446 aDocument
.UpdateExternalRefLinks(GetActiveDialogParent());
447 aDocument
.UpdateDdeLinks(GetActiveDialogParent());
448 aDocument
.UpdateAreaLinks();
458 case SID_REIMPORT_AFTER_LOAD
:
460 // wird nach dem Laden aufgerufen, wenn DB-Bereiche mit
461 // weggelassenen Daten enthalten sind
463 sal_Bool bDone
= false;
464 ScDBCollection
* pDBColl
= aDocument
.GetDBCollection();
466 if ((nCanUpdate
!= com::sun::star::document::UpdateDocMode::NO_UPDATE
) &&
467 (nCanUpdate
!= com::sun::star::document::UpdateDocMode::QUIET_UPDATE
))
470 ScTabViewShell
* pViewSh
= GetBestViewShell();
471 OSL_ENSURE(pViewSh
,"SID_REIMPORT_AFTER_LOAD: keine View");
472 if (pViewSh
&& pDBColl
)
474 QueryBox
aBox( GetActiveDialogParent(), WinBits(WB_YES_NO
| WB_DEF_YES
),
475 ScGlobal::GetRscString(STR_REIMPORT_AFTER_LOAD
) );
476 if (aBox
.Execute() == RET_YES
)
478 ScDBCollection::NamedDBs
& rDBs
= pDBColl
->getNamedDBs();
479 ScDBCollection::NamedDBs::iterator itr
= rDBs
.begin(), itrEnd
= rDBs
.end();
480 for (; itr
!= itrEnd
; ++itr
)
482 ScDBData
& rDBData
= *itr
;
483 if ( rDBData
.IsStripData() &&
484 rDBData
.HasImportParam() && !rDBData
.HasImportSelection() )
486 rDBData
.GetArea(aRange
);
487 pViewSh
->MarkRange(aRange
);
489 // Import und interne Operationen wie SID_REFRESH_DBAREA
490 // (Abfrage auf Import hier nicht noetig)
492 ScImportParam aImportParam
;
493 rDBData
.GetImportParam( aImportParam
);
494 bool bContinue
= pViewSh
->ImportData( aImportParam
);
495 rDBData
.SetImportParam( aImportParam
);
497 // markieren (Groesse kann sich geaendert haben)
498 rDBData
.GetArea(aRange
);
499 pViewSh
->MarkRange(aRange
);
501 if ( bContinue
) // Fehler beim Import -> Abbruch
503 // interne Operationen, wenn welche gespeichert
505 if ( rDBData
.HasQueryParam() || rDBData
.HasSortParam() ||
506 rDBData
.HasSubTotalParam() )
509 // Pivottabellen die den Bereich als Quelldaten haben
511 RefreshPivotTables(aRange
);
520 if ( !bDone
&& pDBColl
)
522 // wenn nicht, dann aber die abhaengigen Formeln updaten
523 //! auch fuer einzelne Bereiche, die nicht aktualisiert werden koennen
525 aDocument
.CalcAll(); //! nur die abhaengigen
538 OSL_FAIL("use ScAutoStyleHint instead of SID_AUTO_STYLE");
541 case SID_GET_COLORLIST
:
543 SvxColorListItem
* pColItem
= (SvxColorListItem
*)GetItem(SID_COLOR_TABLE
);
544 XColorListRef pList
= pColItem
->GetColorList();
545 rReq
.SetReturnValue(OfaRefItem
<XColorList
>(SID_GET_COLORLIST
, pList
));
551 ScDocument
* pDoc
= GetDocument();
554 // get argument (recorded macro)
555 SFX_REQUEST_ARG( rReq
, pItem
, SfxBoolItem
, FID_CHG_RECORD
, false );
556 sal_Bool bDo
= sal_True
;
559 // getting real parent window when called from Security-Options TP
560 Window
* pParent
= NULL
;
561 const SfxPoolItem
* pParentItem
;
562 if( pReqArgs
&& SFX_ITEM_SET
== pReqArgs
->GetItemState( SID_ATTR_XWINDOW
, false, &pParentItem
) )
563 pParent
= ( ( const XWindowItem
* ) pParentItem
)->GetWindowPtr();
566 ScChangeTrack
* pChangeTrack
= pDoc
->GetChangeTrack();
567 sal_Bool bActivateTracking
= (pChangeTrack
== 0); // toggle
569 bActivateTracking
= pItem
->GetValue(); // from argument
571 if ( !bActivateTracking
)
575 // no dialog on playing the macro
576 WarningBox
aBox( pParent
? pParent
: GetActiveDialogParent(),
577 WinBits(WB_YES_NO
| WB_DEF_NO
),
578 ScGlobal::GetRscString( STR_END_REDLINING
) );
579 bDo
= ( aBox
.Execute() == RET_YES
);
584 if ( pChangeTrack
->IsProtected() )
585 bDo
= ExecuteChangeProtectionDialog( NULL
);
588 pDoc
->EndChangeTracking();
595 pDoc
->StartChangeTracking();
596 ScChangeViewSettings aChangeViewSet
;
597 aChangeViewSet
.SetShowChanges(sal_True
);
598 pDoc
->SetChangeViewSettings(aChangeViewSet
);
603 UpdateAcceptChangesDialog();
605 // Slots invalidieren
607 pBindings
->InvalidateAll(false);
609 rReq
.AppendItem( SfxBoolItem( FID_CHG_RECORD
, bActivateTracking
) );
618 case SID_CHG_PROTECT
:
620 Window
* pParent
= NULL
;
621 const SfxPoolItem
* pParentItem
;
622 if( pReqArgs
&& SFX_ITEM_SET
== pReqArgs
->GetItemState( SID_ATTR_XWINDOW
, false, &pParentItem
) )
623 pParent
= ( ( const XWindowItem
* ) pParentItem
)->GetWindowPtr();
624 if ( ExecuteChangeProtectionDialog( pParent
) )
627 SetDocumentModified();
634 case SID_DOCUMENT_MERGE
:
635 case SID_DOCUMENT_COMPARE
:
637 sal_Bool bDo
= sal_True
;
638 ScChangeTrack
* pChangeTrack
= aDocument
.GetChangeTrack();
639 if ( pChangeTrack
&& !pImpl
->bIgnoreLostRedliningWarning
)
641 if ( nSlot
== SID_DOCUMENT_COMPARE
)
642 { //! old changes trace will be lost
643 WarningBox
aBox( GetActiveDialogParent(),
644 WinBits(WB_YES_NO
| WB_DEF_NO
),
645 ScGlobal::GetRscString( STR_END_REDLINING
) );
646 if( aBox
.Execute() == RET_YES
)
647 bDo
= ExecuteChangeProtectionDialog( NULL
, sal_True
);
651 else // merge might reject some actions
652 bDo
= ExecuteChangeProtectionDialog( NULL
, sal_True
);
659 SfxApplication
* pApp
= SFX_APP();
660 const SfxPoolItem
* pItem
;
661 SfxMedium
* pMed
= NULL
;
663 pReqArgs
->GetItemState( SID_FILE_NAME
, sal_True
, &pItem
) == SFX_ITEM_SET
&&
664 pItem
->ISA(SfxStringItem
) )
667 static_cast<const SfxStringItem
*>(pItem
)->GetValue();
669 OUString aFilterName
;
670 if ( pReqArgs
->GetItemState( SID_FILTER_NAME
, sal_True
, &pItem
) == SFX_ITEM_SET
&&
671 pItem
->ISA(SfxStringItem
) )
673 aFilterName
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
676 if ( pReqArgs
->GetItemState( SID_FILE_FILTEROPTIONS
, sal_True
, &pItem
) == SFX_ITEM_SET
&&
677 pItem
->ISA(SfxStringItem
) )
679 aOptions
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
682 if ( pReqArgs
->GetItemState( SID_VERSION
, sal_True
, &pItem
) == SFX_ITEM_SET
&&
683 pItem
->ISA(SfxInt16Item
) )
685 nVersion
= static_cast<const SfxInt16Item
*>(pItem
)->GetValue();
688 // kein Filter angegeben -> Detection
689 if (aFilterName
.isEmpty())
690 ScDocumentLoader::GetFilterName( aFileName
, aFilterName
, aOptions
, true, false );
692 // filter name from dialog contains application prefix,
693 // GetFilter needs name without the prefix.
694 ScDocumentLoader::RemoveAppPrefix( aFilterName
);
696 const SfxFilter
* pFilter
= ScDocShell::Factory().GetFilterContainer()->GetFilter4FilterName( aFilterName
);
697 SfxItemSet
* pSet
= new SfxAllItemSet( pApp
->GetPool() );
698 if (!aOptions
.isEmpty())
699 pSet
->Put( SfxStringItem( SID_FILE_FILTEROPTIONS
, aOptions
) );
701 pSet
->Put( SfxInt16Item( SID_VERSION
, nVersion
) );
702 pMed
= new SfxMedium( aFileName
, STREAM_STD_READ
, pFilter
, pSet
);
706 // start file dialog asynchronous
707 pImpl
->bIgnoreLostRedliningWarning
= true;
708 delete pImpl
->pRequest
;
709 pImpl
->pRequest
= new SfxRequest( rReq
);
710 delete pImpl
->pDocInserter
;
711 pImpl
->pDocInserter
= new ::sfx2::DocumentInserter(
712 OUString::createFromAscii( ScDocShell::Factory().GetShortName() ), 0 );
713 pImpl
->pDocInserter
->StartExecuteModal( LINK( this, ScDocShell
, DialogClosedHdl
) );
717 if ( pMed
) // nun wirklich ausfuehren...
719 SfxErrorContext
aEc( ERRCTX_SFX_OPENDOC
, pMed
->GetName() );
721 // pOtherDocSh->DoClose() will be called explicitly later, but it is still more safe to use SfxObjectShellLock here
722 ScDocShell
* pOtherDocSh
= new ScDocShell
;
723 SfxObjectShellLock aDocShTablesRef
= pOtherDocSh
;
724 pOtherDocSh
->DoLoad( pMed
);
725 sal_uLong nErr
= pOtherDocSh
->GetErrorCode();
727 ErrorHandler::HandleError( nErr
); // auch Warnings
729 if ( !pOtherDocSh
->GetError() ) // nur Errors
731 sal_Bool bHadTrack
= ( aDocument
.GetChangeTrack() != NULL
);
732 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
733 sal_uLong nStart
= 0;
734 if ( nSlot
== SID_DOCUMENT_MERGE
&& pChangeTrack
)
736 nStart
= pChangeTrack
->GetActionMax() + 1;
739 if ( nSlot
== SID_DOCUMENT_COMPARE
)
740 CompareDocument( *pOtherDocSh
->GetDocument() );
742 MergeDocument( *pOtherDocSh
->GetDocument() );
744 // show "accept changes" dialog
745 //! get view for this document!
746 if ( !IsDocShared() )
748 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
751 pViewFrm
->ShowChildWindow( ScAcceptChgDlgWrapper::GetChildWindowId(), sal_True
); //@51669
755 pBindings
->Invalidate( FID_CHG_ACCEPT
);
759 rReq
.SetReturnValue( SfxInt32Item( nSlot
, 0 ) ); //! ???????
762 if (!bHadTrack
) // neu eingeschaltet -> auch anzeigen
764 ScChangeViewSettings
* pOldSet
= aDocument
.GetChangeViewSettings();
765 if ( !pOldSet
|| !pOldSet
->ShowChanges() )
767 ScChangeViewSettings aChangeViewSet
;
768 aChangeViewSet
.SetShowChanges(sal_True
);
769 aDocument
.SetChangeViewSettings(aChangeViewSet
);
772 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
773 else if ( nSlot
== SID_DOCUMENT_MERGE
&& IsDocShared() && pChangeTrack
)
775 sal_uLong nEnd
= pChangeTrack
->GetActionMax();
776 if ( nEnd
>= nStart
)
778 // only show changes from merged document
779 ScChangeViewSettings aChangeViewSet
;
780 aChangeViewSet
.SetShowChanges( sal_True
);
781 aChangeViewSet
.SetShowAccepted( sal_True
);
782 aChangeViewSet
.SetHasActionRange( true );
783 aChangeViewSet
.SetTheActionRange( nStart
, nEnd
);
784 aDocument
.SetChangeViewSettings( aChangeViewSet
);
793 pOtherDocSh
->DoClose(); // delete passiert mit der Ref
798 case SID_DELETE_SCENARIO
:
801 const SfxPoolItem
* pItem
;
802 if ( pReqArgs
->GetItemState( nSlot
, sal_True
, &pItem
) == SFX_ITEM_SET
)
804 if ( pItem
->ISA(SfxStringItem
) )
806 OUString aName
= ((const SfxStringItem
*)pItem
)->GetValue();
808 if (aDocument
.GetTable( aName
, nTab
))
810 // DeleteTable von viewfunc nach docfunc verschieben!
812 ScTabViewShell
* pSh
= GetBestViewShell();
815 //! SetTabNo in DeleteTable weglassen?
816 SCTAB nDispTab
= pSh
->GetViewData()->GetTabNo();
817 pSh
->DeleteTable( nTab
);
818 pSh
->SetTabNo(nDispTab
);
827 case SID_EDIT_SCENARIO
:
829 const SfxPoolItem
* pItem
;
830 if ( pReqArgs
->GetItemState( nSlot
, sal_True
, &pItem
) == SFX_ITEM_SET
)
832 if ( pItem
->ISA(SfxStringItem
) )
834 OUString aName
= ((const SfxStringItem
*)pItem
)->GetValue();
836 if (aDocument
.GetTable( aName
, nTab
))
838 if (aDocument
.IsScenario(nTab
))
843 aDocument
.GetScenarioData( nTab
, aComment
, aColor
, nFlags
);
845 // Determine if the Sheet that the Scenario was created on
846 // is protected. But first we need to find that Sheet.
847 // Rewind back to the actual sheet.
848 SCTAB nActualTab
= nTab
;
853 while(aDocument
.IsScenario(nActualTab
));
854 sal_Bool bSheetProtected
= aDocument
.IsTabProtected(nActualTab
);
856 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
857 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
859 AbstractScNewScenarioDlg
* pNewDlg
= pFact
->CreateScNewScenarioDlg( GetActiveDialogParent(), aName
, RID_SCDLG_NEWSCENARIO
, true,bSheetProtected
);
860 OSL_ENSURE(pNewDlg
, "Dialog create fail!");
861 pNewDlg
->SetScenarioData( aName
, aComment
, aColor
, nFlags
);
862 if ( pNewDlg
->Execute() == RET_OK
)
864 pNewDlg
->GetScenarioData( aName
, aComment
, aColor
, nFlags
);
865 ModifyScenario( nTab
, aName
, aComment
, aColor
, nFlags
);
876 case SID_ATTR_YEAR2000
:
878 const SfxPoolItem
* pItem
;
879 if ( pReqArgs
->GetItemState( nSlot
, sal_True
, &pItem
) == SFX_ITEM_SET
)
881 if ( pItem
->ISA(SfxUInt16Item
) )
883 sal_uInt16 nY2k
= ((SfxUInt16Item
*)pItem
)->GetValue();
884 // immer an den DocOptions setzen, damit das auch fuer SO50
885 // gespeichert wird (und alle Abfragen bisher auch darauf laufen).
886 // SetDocOptions propagiert das an den NumberFormatter
887 ScDocOptions
aDocOpt( aDocument
.GetDocOptions() );
888 aDocOpt
.SetYear2000( nY2k
);
889 aDocument
.SetDocOptions( aDocOpt
);
890 // die FormShell soll es mitbekommen
891 ScTabViewShell
* pSh
= GetBestViewShell();
894 FmFormShell
* pFSh
= pSh
->GetFormShell();
896 pFSh
->SetY2KState( nY2k
);
903 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
906 ScViewData
* pViewData
= GetViewData();
913 ScShareDocumentDlg
aDlg( GetActiveDialogParent(), pViewData
);
914 if ( aDlg
.Execute() == RET_OK
)
916 bool bSetShared
= aDlg
.IsShareDocumentChecked();
917 if ( bSetShared
!= static_cast< bool >( IsDocShared() ) )
921 bool bContinue
= true;
924 QueryBox
aBox( GetActiveDialogParent(), WinBits( WB_YES_NO
| WB_DEF_YES
),
925 ScGlobal::GetRscString( STR_DOC_WILLBESAVED
) );
926 if ( aBox
.Execute() == RET_NO
)
933 EnableSharedSettings( true );
935 SC_MOD()->SetInSharedDocSaving( true );
936 if ( !SwitchToShared( sal_True
, sal_True
) )
938 // TODO/LATER: what should be done in case the switch has failed?
939 // for example in case the user has cancelled the saveAs operation
942 SC_MOD()->SetInSharedDocSaving( false );
945 GetUndoManager()->Clear();
947 ScTabView
* pTabView
= dynamic_cast< ScTabView
* >( pViewData
->GetView() );
950 pTabView
->UpdateLayerLocks();
956 uno::Reference
< frame::XModel
> xModel
;
960 xModel
.set( LoadSharedDocument(), uno::UNO_QUERY_THROW
);
961 uno::Reference
< util::XCloseable
> xCloseable( xModel
, uno::UNO_QUERY_THROW
);
963 // check if shared flag is set in shared file
964 bool bShared
= false;
965 ScModelObj
* pDocObj
= ScModelObj::getImplementation( xModel
);
968 ScDocShell
* pDocShell
= dynamic_cast< ScDocShell
* >( pDocObj
->GetEmbeddedObject() );
971 bShared
= pDocShell
->HasSharedXMLFlagSet();
975 // #i87870# check if shared status was disabled and enabled again
976 bool bOwnEntry
= false;
979 ::svt::ShareControlFile
aControlFile( GetSharedFileURL() );
980 bOwnEntry
= aControlFile
.HasOwnEntry();
982 catch ( uno::Exception
& )
986 if ( bShared
&& bOwnEntry
)
988 uno::Reference
< frame::XStorable
> xStorable( xModel
, uno::UNO_QUERY_THROW
);
989 if ( xStorable
->isReadonly() )
991 xCloseable
->close( sal_True
);
993 OUString
aUserName( ScGlobal::GetRscString( STR_UNKNOWN_USER
) );
996 ::svt::DocumentLockFile
aLockFile( GetSharedFileURL() );
997 uno::Sequence
< OUString
> aData
= aLockFile
.GetLockData();
998 if ( aData
.getLength() > LOCKFILE_SYSUSERNAME_ID
)
1000 if ( !aData
[LOCKFILE_OOOUSERNAME_ID
].isEmpty() )
1002 aUserName
= aData
[LOCKFILE_OOOUSERNAME_ID
];
1004 else if ( !aData
[LOCKFILE_SYSUSERNAME_ID
].isEmpty() )
1006 aUserName
= aData
[LOCKFILE_SYSUSERNAME_ID
];
1010 catch ( uno::Exception
& )
1013 OUString
aMessage( ScGlobal::GetRscString( STR_FILE_LOCKED_TRY_LATER
) );
1014 aMessage
= aMessage
.replaceFirst( "%1", aUserName
);
1016 WarningBox
aBox( GetActiveDialogParent(), WinBits( WB_OK
), aMessage
);
1021 WarningBox
aBox( GetActiveDialogParent(), WinBits( WB_YES_NO
| WB_DEF_YES
),
1022 ScGlobal::GetRscString( STR_DOC_DISABLESHARED
) );
1023 if ( aBox
.Execute() == RET_YES
)
1025 xCloseable
->close( sal_True
);
1027 if ( !SwitchToShared( false, sal_True
) )
1029 // TODO/LATER: what should be done in case the switch has failed?
1030 // for example in case the user has cancelled the saveAs operation
1033 EnableSharedSettings( false );
1037 pBindings
->ExecuteSynchron( SID_SAVEDOC
);
1040 ScTabView
* pTabView
= dynamic_cast< ScTabView
* >( pViewData
->GetView() );
1043 pTabView
->UpdateLayerLocks();
1048 xCloseable
->close( sal_True
);
1054 xCloseable
->close( sal_True
);
1055 WarningBox
aBox( GetActiveDialogParent(), WinBits( WB_OK
),
1056 ScGlobal::GetRscString( STR_DOC_NOLONGERSHARED
) );
1060 catch ( uno::Exception
& )
1062 OSL_FAIL( "SID_SHARE_DOC: caught exception\n" );
1063 SC_MOD()->SetInSharedDocSaving( false );
1067 uno::Reference
< util::XCloseable
> xClose( xModel
, uno::UNO_QUERY_THROW
);
1068 xClose
->close( sal_True
);
1070 catch ( uno::Exception
& )
1083 SfxStringItem
aApp(SID_DOC_SERVICE
, OUString("com.sun.star.sheet.SpreadsheetDocument"));
1084 SfxStringItem
aTarget(SID_TARGETNAME
, OUString("_blank"));
1085 GetViewData()->GetDispatcher().Execute(
1086 SID_OPENDOC
, SFX_CALLMODE_API
|SFX_CALLMODE_SYNCHRON
, &aApp
, &aTarget
, 0L);
1091 // kleiner (?) Hack -> forward der Slots an TabViewShell
1092 ScTabViewShell
* pSh
= GetBestViewShell();
1094 pSh
->Execute( rReq
);
1095 #ifndef DISABLE_SCRIPTING
1097 SbxBase::SetError( SbxERR_NO_ACTIVE_OBJECT
);
1104 //------------------------------------------------------------------
1106 void UpdateAcceptChangesDialog()
1108 // update "accept changes" dialog
1109 //! notify all views
1110 SfxViewFrame
* pViewFrm
= SfxViewFrame::Current();
1111 if ( pViewFrm
&& pViewFrm
->HasChildWindow( FID_CHG_ACCEPT
) )
1113 SfxChildWindow
* pChild
= pViewFrm
->GetChildWindow( FID_CHG_ACCEPT
);
1115 ((ScAcceptChgDlgWrapper
*)pChild
)->ReInitDlg();
1119 //------------------------------------------------------------------
1121 bool ScDocShell::ExecuteChangeProtectionDialog( Window
* _pParent
, sal_Bool bJustQueryIfProtected
)
1124 ScChangeTrack
* pChangeTrack
= aDocument
.GetChangeTrack();
1127 bool bProtected
= pChangeTrack
->IsProtected();
1128 if ( bJustQueryIfProtected
&& !bProtected
)
1131 OUString
aTitle( ScResId( bProtected
? SCSTR_CHG_UNPROTECT
: SCSTR_CHG_PROTECT
) );
1132 OUString
aText( ScResId( SCSTR_PASSWORD
) );
1135 SfxPasswordDialog
* pDlg
= new SfxPasswordDialog(
1136 _pParent
? _pParent
: GetActiveDialogParent(), &aText
);
1137 pDlg
->SetText( aTitle
);
1138 pDlg
->SetMinLen( 1 );
1139 pDlg
->SetHelpId( GetStaticInterface()->GetSlot(SID_CHG_PROTECT
)->GetCommand() );
1140 pDlg
->SetEditHelpId( HID_CHG_PROTECT
);
1142 pDlg
->ShowExtras( SHOWEXTRAS_CONFIRM
);
1143 if ( pDlg
->Execute() == RET_OK
)
1144 aPassword
= pDlg
->GetPassword();
1147 if (!aPassword
.isEmpty())
1151 if ( SvPasswordHelper::CompareHashPassword(pChangeTrack
->GetProtection(), aPassword
) )
1153 if ( bJustQueryIfProtected
)
1156 pChangeTrack
->SetProtection(
1157 com::sun::star::uno::Sequence
< sal_Int8
> (0) );
1161 InfoBox
aBox( GetActiveDialogParent(),
1162 OUString( ScResId( SCSTR_WRONGPASSWORD
) ) );
1168 com::sun::star::uno::Sequence
< sal_Int8
> aPass
;
1169 SvPasswordHelper::GetHashPassword( aPass
, aPassword
);
1170 pChangeTrack
->SetProtection( aPass
);
1172 if ( bProtected
!= pChangeTrack
->IsProtected() )
1174 UpdateAcceptChangesDialog();
1179 else if ( bJustQueryIfProtected
)
1185 //------------------------------------------------------------------
1187 void ScDocShell::DoRecalc( bool bApi
)
1190 ScTabViewShell
* pSh
= GetBestViewShell();
1193 ScInputHandler
* pHdl
= SC_MOD()->GetInputHdl(pSh
);
1194 if ( pHdl
&& pHdl
->IsInputMode() && pHdl
->IsFormulaMode() && !bApi
)
1196 pHdl
->FormulaPreview(); // Teilergebnis als QuickHelp
1201 pSh
->UpdateInputLine(); // InputEnterHandler
1202 pSh
->UpdateInputHandler();
1205 if (!bDone
) // sonst Dokument neu berechnen
1207 WaitObject
aWaitObj( GetActiveDialogParent() );
1208 aDocument
.CalcFormulaTree();
1210 pSh
->UpdateCharts(true);
1212 aDocument
.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED
) );
1214 // Wenn es Charts gibt, dann alles painten, damit nicht
1215 // PostDataChanged und die Charts nacheinander kommen und Teile
1216 // doppelt gepainted werden.
1218 ScChartListenerCollection
* pCharts
= aDocument
.GetChartListenerCollection();
1219 if ( pCharts
&& pCharts
->hasListeners() )
1226 void ScDocShell::DoHardRecalc( bool /* bApi */ )
1228 WaitObject
aWaitObj( GetActiveDialogParent() );
1229 ScTabViewShell
* pSh
= GetBestViewShell();
1232 pSh
->UpdateInputLine(); // InputEnterHandler
1233 pSh
->UpdateInputHandler();
1235 aDocument
.CalcAll();
1236 GetDocFunc().DetectiveRefresh(); // erzeugt eigenes Undo
1238 pSh
->UpdateCharts(true);
1240 // set notification flags for "calculate" event (used in SFX_HINT_DATACHANGED broadcast)
1241 // (might check for the presence of any formulas on each sheet)
1242 SCTAB nTabCount
= aDocument
.GetTableCount();
1244 if (aDocument
.HasAnySheetEventScript( SC_SHEETEVENT_CALCULATE
, true )) // search also for VBA hendler
1245 for (nTab
=0; nTab
<nTabCount
; nTab
++)
1246 aDocument
.SetCalcNotification(nTab
);
1248 // CalcAll doesn't broadcast value changes, so SC_HINT_CALCALL is broadcasted globally
1249 // in addition to SFX_HINT_DATACHANGED.
1250 aDocument
.BroadcastUno( SfxSimpleHint( SC_HINT_CALCALL
) );
1251 aDocument
.BroadcastUno( SfxSimpleHint( SFX_HINT_DATACHANGED
) );
1253 // use hard recalc also to disable stream-copying of all sheets
1254 // (somewhat consistent with charts)
1255 for (nTab
=0; nTab
<nTabCount
; nTab
++)
1256 if (aDocument
.IsStreamValid(nTab
))
1257 aDocument
.SetStreamValid(nTab
, false);
1262 //------------------------------------------------------------------
1264 void ScDocShell::DoAutoStyle( const ScRange
& rRange
, const OUString
& rStyle
)
1266 ScStyleSheetPool
* pStylePool
= aDocument
.GetStyleSheetPool();
1267 ScStyleSheet
* pStyleSheet
=
1268 pStylePool
->FindCaseIns( rStyle
, SFX_STYLE_FAMILY_PARA
);
1270 pStyleSheet
= (ScStyleSheet
*)
1271 pStylePool
->Find( ScGlobal::GetRscString(STR_STYLENAME_STANDARD
), SFX_STYLE_FAMILY_PARA
);
1274 OSL_ENSURE(rRange
.aStart
.Tab() == rRange
.aEnd
.Tab(),
1275 "DoAutoStyle mit mehreren Tabellen");
1276 SCTAB nTab
= rRange
.aStart
.Tab();
1277 SCCOL nStartCol
= rRange
.aStart
.Col();
1278 SCROW nStartRow
= rRange
.aStart
.Row();
1279 SCCOL nEndCol
= rRange
.aEnd
.Col();
1280 SCROW nEndRow
= rRange
.aEnd
.Row();
1281 aDocument
.ApplyStyleAreaTab( nStartCol
, nStartRow
, nEndCol
, nEndRow
, nTab
, *pStyleSheet
);
1282 aDocument
.ExtendMerge( nStartCol
, nStartRow
, nEndCol
, nEndRow
, nTab
);
1283 PostPaint( nStartCol
, nStartRow
, nTab
, nEndCol
, nEndRow
, nTab
, PAINT_GRID
);
1287 //------------------------------------------------------------------
1289 void ScDocShell::NotifyStyle( const SfxStyleSheetHint
& rHint
)
1291 sal_uInt16 nId
= rHint
.GetHint();
1292 const SfxStyleSheetBase
* pStyle
= rHint
.GetStyleSheet();
1296 if ( pStyle
->GetFamily() == SFX_STYLE_FAMILY_PAGE
)
1298 if ( nId
== SFX_STYLESHEET_MODIFIED
)
1300 ScDocShellModificator
aModificator( *this );
1302 OUString aNewName
= pStyle
->GetName();
1303 OUString aOldName
= aNewName
;
1304 sal_Bool bExtended
= rHint
.ISA(SfxStyleSheetHintExtended
); // Name geaendert?
1306 aOldName
= ((SfxStyleSheetHintExtended
&)rHint
).GetOldName();
1308 if ( aNewName
!= aOldName
)
1309 aDocument
.RenamePageStyleInUse( aOldName
, aNewName
);
1311 SCTAB nTabCount
= aDocument
.GetTableCount();
1312 for (SCTAB nTab
=0; nTab
<nTabCount
; nTab
++)
1313 if (aDocument
.GetPageStyle(nTab
) == aNewName
) // schon auf neu angepasst
1315 aDocument
.PageStyleModified( nTab
, aNewName
);
1316 ScPrintFunc
aPrintFunc( this, GetPrinter(), nTab
);
1317 aPrintFunc
.UpdatePages();
1320 aModificator
.SetDocumentModified();
1324 SfxBindings
* pBindings
= GetViewBindings();
1327 pBindings
->Invalidate( SID_STATUS_PAGESTYLE
);
1328 pBindings
->Invalidate( SID_STYLE_FAMILY4
);
1329 pBindings
->Invalidate( FID_RESET_PRINTZOOM
);
1330 pBindings
->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT
);
1331 pBindings
->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT
);
1336 else if ( pStyle
->GetFamily() == SFX_STYLE_FAMILY_PARA
)
1338 if ( nId
== SFX_STYLESHEET_MODIFIED
)
1340 OUString aNewName
= pStyle
->GetName();
1341 OUString aOldName
= aNewName
;
1342 sal_Bool bExtended
= rHint
.ISA(SfxStyleSheetHintExtended
);
1344 aOldName
= ((SfxStyleSheetHintExtended
&)rHint
).GetOldName();
1345 if ( aNewName
!= aOldName
)
1347 for(SCTAB i
= 0; i
< aDocument
.GetTableCount(); ++i
)
1349 ScConditionalFormatList
* pList
= aDocument
.GetCondFormList(i
);
1351 pList
->RenameCellStyle( aOldName
,aNewName
);
1357 // alles andere geht ueber Slots...
1360 // wie in printfun.cxx
1363 void ScDocShell::SetPrintZoom( SCTAB nTab
, sal_uInt16 nScale
, sal_uInt16 nPages
)
1365 sal_Bool
bUndo(aDocument
.IsUndoEnabled());
1366 OUString aStyleName
= aDocument
.GetPageStyle( nTab
);
1367 ScStyleSheetPool
* pStylePool
= aDocument
.GetStyleSheetPool();
1368 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aStyleName
, SFX_STYLE_FAMILY_PAGE
);
1369 OSL_ENSURE( pStyleSheet
, "PageStyle not found" );
1372 ScDocShellModificator
aModificator( *this );
1374 SfxItemSet
& rSet
= pStyleSheet
->GetItemSet();
1377 sal_uInt16 nOldScale
= ((const SfxUInt16Item
&)rSet
.Get(ATTR_PAGE_SCALE
)).GetValue();
1378 sal_uInt16 nOldPages
= ((const SfxUInt16Item
&)rSet
.Get(ATTR_PAGE_SCALETOPAGES
)).GetValue();
1379 GetUndoManager()->AddUndoAction( new ScUndoPrintZoom(
1380 this, nTab
, nOldScale
, nOldPages
, nScale
, nPages
) );
1383 rSet
.Put( SfxUInt16Item( ATTR_PAGE_SCALE
, nScale
) );
1384 rSet
.Put( SfxUInt16Item( ATTR_PAGE_SCALETOPAGES
, nPages
) );
1386 ScPrintFunc
aPrintFunc( this, GetPrinter(), nTab
);
1387 aPrintFunc
.UpdatePages();
1388 aModificator
.SetDocumentModified();
1390 SfxBindings
* pBindings
= GetViewBindings();
1392 pBindings
->Invalidate( FID_RESET_PRINTZOOM
);
1396 bool ScDocShell::AdjustPrintZoom( const ScRange
& rRange
)
1398 bool bChange
= false;
1399 SCTAB nTab
= rRange
.aStart
.Tab();
1401 OUString aStyleName
= aDocument
.GetPageStyle( nTab
);
1402 ScStyleSheetPool
* pStylePool
= aDocument
.GetStyleSheetPool();
1403 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aStyleName
, SFX_STYLE_FAMILY_PAGE
);
1404 OSL_ENSURE( pStyleSheet
, "PageStyle not found" );
1407 SfxItemSet
& rSet
= pStyleSheet
->GetItemSet();
1408 sal_Bool bHeaders
= ((const SfxBoolItem
&)rSet
.Get(ATTR_PAGE_HEADERS
)).GetValue();
1409 sal_uInt16 nOldScale
= ((const SfxUInt16Item
&)rSet
.Get(ATTR_PAGE_SCALE
)).GetValue();
1410 sal_uInt16 nOldPages
= ((const SfxUInt16Item
&)rSet
.Get(ATTR_PAGE_SCALETOPAGES
)).GetValue();
1411 const ScRange
* pRepeatCol
= aDocument
.GetRepeatColRange( nTab
);
1412 const ScRange
* pRepeatRow
= aDocument
.GetRepeatRowRange( nTab
);
1414 // benoetigte Skalierung fuer Selektion ausrechnen
1416 sal_uInt16 nNewScale
= nOldScale
;
1418 long nBlkTwipsX
= 0;
1420 nBlkTwipsX
+= (long) PRINT_HEADER_WIDTH
;
1421 SCCOL nStartCol
= rRange
.aStart
.Col();
1422 SCCOL nEndCol
= rRange
.aEnd
.Col();
1423 if ( pRepeatCol
&& nStartCol
>= pRepeatCol
->aStart
.Col() )
1425 for (SCCOL i
=pRepeatCol
->aStart
.Col(); i
<=pRepeatCol
->aEnd
.Col(); i
++ )
1426 nBlkTwipsX
+= aDocument
.GetColWidth( i
, nTab
);
1427 if ( nStartCol
<= pRepeatCol
->aEnd
.Col() )
1428 nStartCol
= pRepeatCol
->aEnd
.Col() + 1;
1430 // legacy compilers' own scope for i
1432 for ( SCCOL i
=nStartCol
; i
<=nEndCol
; i
++ )
1433 nBlkTwipsX
+= aDocument
.GetColWidth( i
, nTab
);
1436 long nBlkTwipsY
= 0;
1438 nBlkTwipsY
+= (long) PRINT_HEADER_HEIGHT
;
1439 SCROW nStartRow
= rRange
.aStart
.Row();
1440 SCROW nEndRow
= rRange
.aEnd
.Row();
1441 if ( pRepeatRow
&& nStartRow
>= pRepeatRow
->aStart
.Row() )
1443 nBlkTwipsY
+= aDocument
.GetRowHeight( pRepeatRow
->aStart
.Row(),
1444 pRepeatRow
->aEnd
.Row(), nTab
);
1445 if ( nStartRow
<= pRepeatRow
->aEnd
.Row() )
1446 nStartRow
= pRepeatRow
->aEnd
.Row() + 1;
1448 nBlkTwipsY
+= aDocument
.GetRowHeight( nStartRow
, nEndRow
, nTab
);
1452 ScPrintFunc
aOldPrFunc( this, GetPrinter(), nTab
);
1453 aOldPrFunc
.GetScaleData( aPhysPage
, nHdr
, nFtr
);
1454 nBlkTwipsY
+= nHdr
+ nFtr
;
1456 if ( nBlkTwipsX
== 0 ) // hidden columns/rows may lead to 0
1458 if ( nBlkTwipsY
== 0 )
1461 long nNeeded
= std::min( aPhysPage
.Width() * 100 / nBlkTwipsX
,
1462 aPhysPage
.Height() * 100 / nBlkTwipsY
);
1463 if ( nNeeded
< ZOOM_MIN
)
1464 nNeeded
= ZOOM_MIN
; // Begrenzung
1465 if ( nNeeded
< (long) nNewScale
)
1466 nNewScale
= (sal_uInt16
) nNeeded
;
1468 bChange
= ( nNewScale
!= nOldScale
|| nOldPages
!= 0 );
1470 SetPrintZoom( nTab
, nNewScale
, 0 );
1475 void ScDocShell::PageStyleModified( const OUString
& rStyleName
, sal_Bool bApi
)
1477 ScDocShellModificator
aModificator( *this );
1479 sal_Bool bWarn
= false;
1481 SCTAB nTabCount
= aDocument
.GetTableCount();
1482 SCTAB nUseTab
= MAXTAB
+1;
1483 for (SCTAB nTab
=0; nTab
<nTabCount
&& nUseTab
>MAXTAB
; nTab
++)
1484 if ( aDocument
.GetPageStyle(nTab
) == rStyleName
&&
1485 ( !bApi
|| aDocument
.GetPageSize(nTab
).Width() ) )
1487 // bei bApi nur, wenn Umbrueche schon angezeigt
1489 if (ValidTab(nUseTab
)) // nicht verwendet -> nichts zu tun
1491 ScPrintFunc
aPrintFunc( this, GetPrinter(), nUseTab
); //! ohne CountPages auskommen
1492 if (!aPrintFunc
.UpdatePages()) // setzt Umbrueche auf allen Tabs
1497 ScWaitCursorOff
aWaitOff( GetActiveDialogParent() );
1498 InfoBox
aInfoBox(GetActiveDialogParent(),
1499 ScGlobal::GetRscString(STR_PRINT_INVALID_AREA
));
1504 aModificator
.SetDocumentModified();
1506 SfxBindings
* pBindings
= GetViewBindings();
1509 pBindings
->Invalidate( FID_RESET_PRINTZOOM
);
1510 pBindings
->Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT
);
1511 pBindings
->Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT
);
1515 void ScDocShell::ExecutePageStyle( SfxViewShell
& rCaller
,
1519 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
1521 switch ( rReq
.GetSlot() )
1523 case SID_STATUS_PAGESTYLE
: // Click auf StatusBar-Control
1524 case SID_FORMATPAGE
:
1526 if ( pReqArgs
!= NULL
)
1529 else if ( pReqArgs
== NULL
)
1531 sal_Bool
bUndo(aDocument
.IsUndoEnabled());
1532 OUString aOldName
= aDocument
.GetPageStyle( nCurTab
);
1533 ScStyleSheetPool
* pStylePool
= aDocument
.GetStyleSheetPool();
1534 SfxStyleSheetBase
* pStyleSheet
1535 = pStylePool
->Find( aOldName
, SFX_STYLE_FAMILY_PAGE
);
1537 OSL_ENSURE( pStyleSheet
, "PageStyle not found! :-/" );
1541 ScStyleSaveData aOldData
;
1543 aOldData
.InitFromStyle( pStyleSheet
);
1545 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
1547 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
1548 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
1550 SfxAbstractTabDialog
* pDlg
= pFact
->CreateScStyleDlg( GetActiveDialogParent(), *pStyleSheet
, RID_SCDLG_STYLES_PAGE
, RID_SCDLG_STYLES_PAGE
);
1551 OSL_ENSURE(pDlg
, "Dialog create fail!");
1553 if ( pDlg
->Execute() == RET_OK
)
1555 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
1557 WaitObject
aWait( GetActiveDialogParent() );
1559 OUString aNewName
= pStyleSheet
->GetName();
1560 if ( aNewName
!= aOldName
&&
1561 aDocument
.RenamePageStyleInUse( aOldName
, aNewName
) )
1563 SfxBindings
* pBindings
= GetViewBindings();
1566 pBindings
->Invalidate( SID_STATUS_PAGESTYLE
);
1567 pBindings
->Invalidate( FID_RESET_PRINTZOOM
);
1572 aDocument
.ModifyStyleSheet( *pStyleSheet
, *pOutSet
);
1574 // merken fuer GetState():
1575 GetPageOnFromPageStyleSet( &rStyleSet
, nCurTab
, bHeaderOn
, bFooterOn
);
1576 rCaller
.GetViewFrame()->GetBindings().Invalidate( SID_HFEDIT
);
1578 ScStyleSaveData aNewData
;
1579 aNewData
.InitFromStyle( pStyleSheet
);
1582 GetUndoManager()->AddUndoAction(
1583 new ScUndoModifyStyle( this, SFX_STYLE_FAMILY_PAGE
,
1584 aOldData
, aNewData
) );
1587 PageStyleModified( aNewName
, false );
1592 rStyleSet
.ClearItem( ATTR_PAGE_PAPERTRAY
);
1600 if ( pReqArgs
!= NULL
)
1603 else if ( pReqArgs
== NULL
)
1605 OUString
aStr( aDocument
.GetPageStyle( nCurTab
) );
1607 ScStyleSheetPool
* pStylePool
1608 = aDocument
.GetStyleSheetPool();
1610 SfxStyleSheetBase
* pStyleSheet
1611 = pStylePool
->Find( aStr
, SFX_STYLE_FAMILY_PAGE
);
1613 OSL_ENSURE( pStyleSheet
, "PageStyle not found! :-/" );
1617 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
1619 SvxPageUsage eUsage
=
1620 SvxPageUsage( ((const SvxPageItem
&)
1621 rStyleSet
.Get( ATTR_PAGE
)).
1623 sal_Bool bShareHeader
= IS_SHARE_HEADER(rStyleSet
);
1624 sal_Bool bShareFooter
= IS_SHARE_FOOTER(rStyleSet
);
1625 sal_uInt16 nResId
= 0;
1630 case SVX_PAGE_RIGHT
:
1632 if ( bHeaderOn
&& bFooterOn
)
1633 nResId
= RID_SCDLG_HFEDIT
;
1634 else if ( SVX_PAGE_RIGHT
== eUsage
)
1636 if ( !bHeaderOn
&& bFooterOn
)
1637 nResId
= RID_SCDLG_HFEDIT_RIGHTFOOTER
;
1638 else if ( bHeaderOn
&& !bFooterOn
)
1639 nResId
= RID_SCDLG_HFEDIT_RIGHTHEADER
;
1643 // #69193a# respect "shared" setting
1644 if ( !bHeaderOn
&& bFooterOn
)
1645 nResId
= bShareFooter
?
1646 RID_SCDLG_HFEDIT_RIGHTFOOTER
:
1647 RID_SCDLG_HFEDIT_LEFTFOOTER
;
1648 else if ( bHeaderOn
&& !bFooterOn
)
1649 nResId
= bShareHeader
?
1650 RID_SCDLG_HFEDIT_RIGHTHEADER
:
1651 RID_SCDLG_HFEDIT_LEFTHEADER
;
1656 case SVX_PAGE_MIRROR
:
1660 if ( !bShareHeader
&& !bShareFooter
)
1662 if ( bHeaderOn
&& bFooterOn
)
1663 nResId
= RID_SCDLG_HFEDIT_ALL
;
1664 else if ( !bHeaderOn
&& bFooterOn
)
1665 nResId
= RID_SCDLG_HFEDIT_FOOTER
;
1666 else if ( bHeaderOn
&& !bFooterOn
)
1667 nResId
= RID_SCDLG_HFEDIT_HEADER
;
1669 else if ( bShareHeader
&& bShareFooter
)
1671 if ( bHeaderOn
&& bFooterOn
)
1672 nResId
= RID_SCDLG_HFEDIT
;
1675 if ( !bHeaderOn
&& bFooterOn
)
1676 nResId
= RID_SCDLG_HFEDIT_RIGHTFOOTER
;
1677 else if ( bHeaderOn
&& !bFooterOn
)
1678 nResId
= RID_SCDLG_HFEDIT_RIGHTHEADER
;
1681 else if ( !bShareHeader
&& bShareFooter
)
1683 if ( bHeaderOn
&& bFooterOn
)
1684 nResId
= RID_SCDLG_HFEDIT_SFTR
;
1685 else if ( !bHeaderOn
&& bFooterOn
)
1686 nResId
= RID_SCDLG_HFEDIT_RIGHTFOOTER
;
1687 else if ( bHeaderOn
&& !bFooterOn
)
1688 nResId
= RID_SCDLG_HFEDIT_HEADER
;
1690 else if ( bShareHeader
&& !bShareFooter
)
1692 if ( bHeaderOn
&& bFooterOn
)
1693 nResId
= RID_SCDLG_HFEDIT_SHDR
;
1694 else if ( !bHeaderOn
&& bFooterOn
)
1695 nResId
= RID_SCDLG_HFEDIT_FOOTER
;
1696 else if ( bHeaderOn
&& !bFooterOn
)
1697 nResId
= RID_SCDLG_HFEDIT_RIGHTHEADER
;
1702 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
1703 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
1705 SfxAbstractTabDialog
* pDlg
= pFact
->CreateScHFEditDlg( SfxViewFrame::Current(),
1706 GetActiveDialogParent(),
1710 OSL_ENSURE(pDlg
, "Dialog create fail!");
1711 if ( pDlg
->Execute() == RET_OK
)
1713 const SfxItemSet
* pOutSet
= pDlg
->GetOutputItemSet();
1716 aDocument
.ModifyStyleSheet( *pStyleSheet
, *pOutSet
);
1718 SetDocumentModified();
1732 void ScDocShell::GetStatePageStyle( SfxViewShell
& /* rCaller */,
1736 SfxWhichIter
aIter(rSet
);
1737 sal_uInt16 nWhich
= aIter
.FirstWhich();
1742 case SID_STATUS_PAGESTYLE
:
1743 rSet
.Put( SfxStringItem( nWhich
, aDocument
.GetPageStyle( nCurTab
) ) );
1748 OUString aStr
= aDocument
.GetPageStyle( nCurTab
);
1749 ScStyleSheetPool
* pStylePool
= aDocument
.GetStyleSheetPool();
1750 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->Find( aStr
, SFX_STYLE_FAMILY_PAGE
);
1752 OSL_ENSURE( pStyleSheet
, "PageStyle not found! :-/" );
1756 SfxItemSet
& rStyleSet
= pStyleSheet
->GetItemSet();
1757 GetPageOnFromPageStyleSet( &rStyleSet
, nCurTab
, bHeaderOn
, bFooterOn
);
1759 if ( !bHeaderOn
&& !bFooterOn
)
1760 rSet
.DisableItem( nWhich
);
1766 nWhich
= aIter
.NextWhich();
1770 void ScDocShell::GetState( SfxItemSet
&rSet
)
1772 bool bTabView
= GetBestViewShell(true) != NULL
;
1774 SfxWhichIter
aIter(rSet
);
1775 for (sal_uInt16 nWhich
= aIter
.FirstWhich(); nWhich
; nWhich
= aIter
.NextWhich())
1779 rSet
.DisableItem(nWhich
);
1786 if ( aDocument
.GetHardRecalcState() )
1787 rSet
.DisableItem( nWhich
);
1789 rSet
.Put( SfxBoolItem( nWhich
, aDocument
.GetAutoCalc() ) );
1792 case FID_CHG_RECORD
:
1793 if ( IsDocShared() )
1794 rSet
.DisableItem( nWhich
);
1796 rSet
.Put( SfxBoolItem( nWhich
,
1797 aDocument
.GetChangeTrack() != NULL
) );
1800 case SID_CHG_PROTECT
:
1802 ScChangeTrack
* pChangeTrack
= aDocument
.GetChangeTrack();
1803 if ( pChangeTrack
&& !IsDocShared() )
1804 rSet
.Put( SfxBoolItem( nWhich
,
1805 pChangeTrack
->IsProtected() ) );
1807 rSet
.DisableItem( nWhich
);
1811 case SID_DOCUMENT_COMPARE
:
1813 if ( IsDocShared() )
1815 rSet
.DisableItem( nWhich
);
1820 // Wenn eine Formel editiert wird, muss FID_RECALC auf jeden Fall enabled sein.
1821 // Recalc fuer das Doc war mal wegen eines Bugs disabled, wenn AutoCalc an war,
1822 // ist jetzt wegen eines anderen Bugs aber auch immer enabled.
1824 case SID_TABLES_COUNT
:
1825 rSet
.Put( SfxInt16Item( nWhich
, aDocument
.GetTableCount() ) );
1828 case SID_ATTR_YEAR2000
:
1829 rSet
.Put( SfxUInt16Item( nWhich
,
1830 aDocument
.GetDocOptions().GetYear2000() ) );
1837 rSet
.DisableItem( nWhich
);
1850 void ScDocShell::GetSbxState( SfxItemSet
&rSet
)
1852 // SID_SC_SELECTION (Selection),
1853 // SID_SC_ACTIVECELL (ActiveCell),
1854 // SID_SC_ACTIVETAB (ActiveTable),
1855 // SID_TABLES_GET (Tables),
1856 // SID_PIVOT_GET (DataPilotTables) - removed (old Basic)
1859 // Wenn hier Slots von der View-Shell executed werden, muss auch der
1860 // GetState weitergeleitet werden!
1863 ScTabViewShell
* pVisibleSh
= GetBestViewShell(); // sichtbare View
1865 pVisibleSh
->GetState( rSet
);
1868 void ScDocShell::Draw( OutputDevice
* pDev
, const JobSetup
& /* rSetup */, sal_uInt16 nAspect
)
1871 SCTAB nVisTab
= aDocument
.GetVisibleTab();
1872 if (!aDocument
.HasTable(nVisTab
))
1875 sal_uLong nOldLayoutMode
= pDev
->GetLayoutMode();
1876 pDev
->SetLayoutMode( TEXT_LAYOUT_DEFAULT
); // even if it's the same, to get the metafile action
1878 if ( nAspect
== ASPECT_THUMBNAIL
)
1880 Rectangle aBoundRect
= GetVisArea( ASPECT_THUMBNAIL
);
1881 ScViewData
aTmpData( this, NULL
);
1882 aTmpData
.SetTabNo(nVisTab
);
1883 SnapVisArea( aBoundRect
);
1884 aTmpData
.SetScreen( aBoundRect
);
1885 ScPrintFunc::DrawToDev( &aDocument
, pDev
, 1.0, aBoundRect
, &aTmpData
, sal_True
);
1889 Rectangle aBoundRect
= SfxObjectShell::GetVisArea();
1890 ScViewData
aTmpData( this, NULL
);
1891 aTmpData
.SetTabNo(nVisTab
);
1892 SnapVisArea( aBoundRect
);
1893 aTmpData
.SetScreen( aBoundRect
);
1894 ScPrintFunc::DrawToDev( &aDocument
, pDev
, 1.0, aBoundRect
, &aTmpData
, sal_True
);
1897 pDev
->SetLayoutMode( nOldLayoutMode
);
1900 Rectangle
ScDocShell::GetVisArea( sal_uInt16 nAspect
) const
1902 SfxObjectCreateMode eShellMode
= GetCreateMode();
1903 if ( eShellMode
== SFX_CREATE_MODE_ORGANIZER
)
1905 // ohne Inhalte wissen wir auch nicht, wie gross die Inhalte sind
1906 // leeres Rechteck zurueckgeben, das wird dann nach dem Laden berechnet
1910 if( nAspect
== ASPECT_THUMBNAIL
)
1912 Rectangle
aArea( 0,0, SC_PREVIEW_SIZE_X
,SC_PREVIEW_SIZE_Y
);
1913 sal_Bool bNegativePage
= aDocument
.IsNegativePage( aDocument
.GetVisibleTab() );
1914 if ( bNegativePage
)
1915 ScDrawLayer::MirrorRectRTL( aArea
);
1916 SnapVisArea( aArea
);
1919 else if( nAspect
== ASPECT_CONTENT
&& eShellMode
!= SFX_CREATE_MODE_EMBEDDED
)
1921 // Visarea holen wie nach Load
1923 SCTAB nVisTab
= aDocument
.GetVisibleTab();
1924 if (!aDocument
.HasTable(nVisTab
))
1927 ((ScDocShell
*)this)->aDocument
.SetVisibleTab(nVisTab
);
1931 aDocument
.GetDataStart( nVisTab
, nStartCol
, nStartRow
);
1934 aDocument
.GetPrintArea( nVisTab
, nEndCol
, nEndRow
);
1935 if (nStartCol
>nEndCol
)
1936 nStartCol
= nEndCol
;
1937 if (nStartRow
>nEndRow
)
1938 nStartRow
= nEndRow
;
1939 Rectangle aNewArea
= ((ScDocument
&)aDocument
)
1940 .GetMMRect( nStartCol
,nStartRow
, nEndCol
,nEndRow
, nVisTab
);
1941 //TODO/LATER: different methods for setting VisArea?!
1942 ((ScDocShell
*)this)->SfxObjectShell::SetVisArea( aNewArea
);
1946 return SfxObjectShell::GetVisArea( nAspect
);
1951 void SnapHor( const ScDocument
& rDoc
, SCTAB nTab
, long& rVal
, SCCOL
& rStartCol
)
1954 long nTwips
= (long) (rVal
/ HMM_PER_TWIPS
);
1956 while ( nCol
<MAXCOL
)
1958 long nAdd
= rDoc
.GetColWidth(nCol
, nTab
);
1959 if ( nSnap
+ nAdd
/2 < nTwips
|| nCol
< rStartCol
)
1967 rVal
= (long) ( nSnap
* HMM_PER_TWIPS
);
1971 void SnapVer( const ScDocument
& rDoc
, SCTAB nTab
, long& rVal
, SCROW
& rStartRow
)
1974 long nTwips
= (long) (rVal
/ HMM_PER_TWIPS
);
1977 bool bFound
= false;
1978 for (SCROW i
= nRow
; i
<= MAXROW
; ++i
)
1981 if (rDoc
.RowHidden(i
, nTab
, NULL
, &nLastRow
))
1988 long nAdd
= rDoc
.GetRowHeight(i
, nTab
);
1989 if ( nSnap
+ nAdd
/2 < nTwips
|| nRow
< rStartRow
)
2001 nRow
= MAXROW
; // all hidden down to the bottom
2003 rVal
= (long) ( nSnap
* HMM_PER_TWIPS
);
2010 void ScDocShell::SnapVisArea( Rectangle
& rRect
) const
2012 SCTAB nTab
= aDocument
.GetVisibleTab();
2013 bool bNegativePage
= aDocument
.IsNegativePage( nTab
);
2014 if ( bNegativePage
)
2015 ScDrawLayer::MirrorRectRTL( rRect
); // calculate with positive (LTR) values
2018 SnapHor( aDocument
, nTab
, rRect
.Left(), nCol
);
2019 ++nCol
; // mindestens eine Spalte
2020 SnapHor( aDocument
, nTab
, rRect
.Right(), nCol
);
2023 SnapVer( aDocument
, nTab
, rRect
.Top(), nRow
);
2024 ++nRow
; // mindestens eine Zeile
2025 SnapVer( aDocument
, nTab
, rRect
.Bottom(), nRow
);
2027 if ( bNegativePage
)
2028 ScDrawLayer::MirrorRectRTL( rRect
); // back to real rectangle
2031 void ScDocShell::GetPageOnFromPageStyleSet( const SfxItemSet
* pStyleSet
,
2038 ScStyleSheetPool
* pStylePool
= aDocument
.GetStyleSheetPool();
2039 SfxStyleSheetBase
* pStyleSheet
= pStylePool
->
2040 Find( aDocument
.GetPageStyle( nCurTab
),
2041 SFX_STYLE_FAMILY_PAGE
);
2043 OSL_ENSURE( pStyleSheet
, "PageStyle not found! :-/" );
2046 pStyleSet
= &pStyleSheet
->GetItemSet();
2048 rbHeader
= rbFooter
= false;
2051 OSL_ENSURE( pStyleSet
, "PageStyle-Set not found! :-(" );
2053 //--------------------------------------------------------------------
2055 const SvxSetItem
* pSetItem
= NULL
;
2056 const SfxItemSet
* pSet
= NULL
;
2058 pSetItem
= (const SvxSetItem
*) &pStyleSet
->Get( ATTR_PAGE_HEADERSET
);
2059 pSet
= &pSetItem
->GetItemSet();
2060 rbHeader
= ((const SfxBoolItem
&)pSet
->Get(ATTR_PAGE_ON
)).GetValue();
2062 pSetItem
= (const SvxSetItem
*) &pStyleSet
->Get( ATTR_PAGE_FOOTERSET
);
2063 pSet
= &pSetItem
->GetItemSet();
2064 rbFooter
= ((const SfxBoolItem
&)pSet
->Get(ATTR_PAGE_ON
)).GetValue();
2067 long ScDocShell::DdeGetData( const OUString
& rItem
,
2068 const OUString
& rMimeType
,
2069 ::com::sun::star::uno::Any
& rValue
)
2071 if( FORMAT_STRING
== SotExchange::GetFormatIdFromMimeType( rMimeType
) )
2073 if( rItem
.equalsIgnoreAsciiCase( "Format" ) )
2075 OString
aFmtByte(OUStringToOString(aDdeTextFmt
,
2076 osl_getThreadTextEncoding()));
2077 rValue
<<= ::com::sun::star::uno::Sequence
< sal_Int8
>(
2078 (const sal_Int8
*)aFmtByte
.getStr(),
2079 aFmtByte
.getLength() + 1 );
2082 ScImportExport
aObj( &aDocument
, rItem
);
2083 if ( !aObj
.IsRef() )
2084 return 0; // ungueltiger Bereich
2086 if( aDdeTextFmt
[0] == 'F' )
2087 aObj
.SetFormulas( sal_True
);
2088 if( aDdeTextFmt
== "SYLK" ||
2089 aDdeTextFmt
== "FSYLK" )
2092 if( aObj
.ExportByteString( aData
, osl_getThreadTextEncoding(),
2093 SOT_FORMATSTR_ID_SYLK
) )
2095 rValue
<<= ::com::sun::star::uno::Sequence
< sal_Int8
>(
2096 (const sal_Int8
*)aData
.getStr(),
2097 aData
.getLength() + 1 );
2103 if( aDdeTextFmt
== "CSV" ||
2104 aDdeTextFmt
== "FCSV" )
2105 aObj
.SetSeparator( ',' );
2106 aObj
.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace
, 0, false ) );
2107 return aObj
.ExportData( rMimeType
, rValue
) ? 1 : 0;
2110 ScImportExport
aObj( &aDocument
, rItem
);
2111 aObj
.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::ToSpace
, 0, false ) );
2113 return aObj
.ExportData( rMimeType
, rValue
) ? 1 : 0;
2117 long ScDocShell::DdeSetData( const OUString
& rItem
,
2118 const OUString
& rMimeType
,
2119 const ::com::sun::star::uno::Any
& rValue
)
2121 if( FORMAT_STRING
== SotExchange::GetFormatIdFromMimeType( rMimeType
))
2123 if( rItem
.equalsIgnoreAsciiCase( "Format" ) )
2125 if ( ScByteSequenceToString::GetString( aDdeTextFmt
, rValue
, osl_getThreadTextEncoding() ) )
2127 aDdeTextFmt
= aDdeTextFmt
.toAsciiUpperCase();
2132 ScImportExport
aObj( &aDocument
, rItem
);
2133 if( aDdeTextFmt
[0] == 'F' )
2134 aObj
.SetFormulas( sal_True
);
2135 if( aDdeTextFmt
== "SYLK" ||
2136 aDdeTextFmt
== "FSYLK" )
2139 if ( ScByteSequenceToString::GetString( aData
, rValue
, osl_getThreadTextEncoding() ) )
2141 return aObj
.ImportString( aData
, SOT_FORMATSTR_ID_SYLK
) ? 1 : 0;
2145 if( aDdeTextFmt
== "CSV" ||
2146 aDdeTextFmt
== "FCSV" )
2147 aObj
.SetSeparator( ',' );
2148 return aObj
.ImportData( rMimeType
, rValue
) ? 1 : 0;
2150 ScImportExport
aObj( &aDocument
, rItem
);
2152 return aObj
.ImportData( rMimeType
, rValue
) ? 1 : 0;
2156 ::sfx2::SvLinkSource
* ScDocShell::DdeCreateLinkSource( const OUString
& rItem
)
2158 // only check for valid item string - range is parsed again in ScServerObject ctor
2161 OUString aPos
= rItem
;
2162 ScRangeName
* pRange
= aDocument
.GetRangeName();
2165 const ScRangeData
* pData
= pRange
->findByUpperName(ScGlobal::pCharClass
->uppercase(aPos
));
2168 if( pData
->HasType( RT_REFAREA
)
2169 || pData
->HasType( RT_ABSAREA
)
2170 || pData
->HasType( RT_ABSPOS
) )
2171 pData
->GetSymbol( aPos
); // continue with the name's contents
2175 // Address in DDE function must be always parsed as CONV_OOO so that it
2176 // would always work regardless of current address convension. We do this
2177 // because the address item in a DDE entry is *not* normalized when saved
2180 bool bValid
= ( (aRange
.Parse(aPos
, &aDocument
, formula::FormulaGrammar::CONV_OOO
) & SCA_VALID
) ||
2181 (aRange
.aStart
.Parse(aPos
, &aDocument
, formula::FormulaGrammar::CONV_OOO
) & SCA_VALID
) );
2183 ScServerObject
* pObj
= NULL
; // NULL = error
2185 pObj
= new ScServerObject( this, rItem
);
2187 // GetLinkManager()->InsertServer() is in the ScServerObject ctor
2192 //------------------------------------------------------------------
2194 ScViewData
* ScDocShell::GetViewData()
2196 SfxViewShell
* pCur
= SfxViewShell::Current();
2197 ScTabViewShell
* pViewSh
= PTR_CAST(ScTabViewShell
,pCur
);
2198 return pViewSh
? pViewSh
->GetViewData() : NULL
;
2201 //------------------------------------------------------------------
2203 SCTAB
ScDocShell::GetCurTab()
2205 //! this must be made non-static and use a ViewShell from this document!
2207 ScViewData
* pViewData
= GetViewData();
2209 return pViewData
? pViewData
->GetTabNo() : static_cast<SCTAB
>(0);
2212 ScTabViewShell
* ScDocShell::GetBestViewShell( sal_Bool bOnlyVisible
)
2214 ScTabViewShell
* pViewSh
= ScTabViewShell::GetActiveViewShell();
2216 if( pViewSh
&& pViewSh
->GetViewData()->GetDocShell() != this )
2220 // 1. ViewShell suchen
2221 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( this, bOnlyVisible
);
2224 SfxViewShell
* p
= pFrame
->GetViewShell();
2225 pViewSh
= PTR_CAST(ScTabViewShell
,p
);
2231 SfxBindings
* ScDocShell::GetViewBindings()
2233 // used to invalidate slots after changes to this document
2235 SfxViewShell
* pViewSh
= GetBestViewShell();
2237 return &pViewSh
->GetViewFrame()->GetBindings();
2242 //------------------------------------------------------------------
2244 ScDocShell
* ScDocShell::GetShellByNum( sal_uInt16 nDocNo
) // static
2246 ScDocShell
* pFound
= NULL
;
2247 SfxObjectShell
* pShell
= SfxObjectShell::GetFirst();
2248 sal_uInt16 nShellCnt
= 0;
2250 while ( pShell
&& !pFound
)
2252 if ( pShell
->Type() == TYPE(ScDocShell
) )
2254 if ( nShellCnt
== nDocNo
)
2255 pFound
= (ScDocShell
*) pShell
;
2259 pShell
= SfxObjectShell::GetNext( *pShell
);
2265 //------------------------------------------------------------------
2267 IMPL_LINK( ScDocShell
, DialogClosedHdl
, sfx2::FileDialogHelper
*, _pFileDlg
)
2269 OSL_ENSURE( _pFileDlg
, "ScDocShell::DialogClosedHdl(): no file dialog" );
2270 OSL_ENSURE( pImpl
->pDocInserter
, "ScDocShell::DialogClosedHdl(): no document inserter" );
2272 if ( ERRCODE_NONE
== _pFileDlg
->GetError() )
2274 sal_uInt16 nSlot
= pImpl
->pRequest
->GetSlot();
2275 SfxMedium
* pMed
= pImpl
->pDocInserter
->CreateMedium();
2276 // #i87094# If a .odt was selected pMed is NULL.
2279 pImpl
->pRequest
->AppendItem( SfxStringItem( SID_FILE_NAME
, pMed
->GetName() ) );
2280 if ( SID_DOCUMENT_COMPARE
== nSlot
)
2282 if ( pMed
->GetFilter() )
2283 pImpl
->pRequest
->AppendItem(
2284 SfxStringItem( SID_FILTER_NAME
, pMed
->GetFilter()->GetFilterName() ) );
2285 OUString sOptions
= ScDocumentLoader::GetOptions( *pMed
);
2286 if ( !sOptions
.isEmpty() )
2287 pImpl
->pRequest
->AppendItem( SfxStringItem( SID_FILE_FILTEROPTIONS
, sOptions
) );
2289 const SfxPoolItem
* pItem
= NULL
;
2290 SfxItemSet
* pSet
= pMed
->GetItemSet();
2292 pSet
->GetItemState( SID_VERSION
, sal_True
, &pItem
) == SFX_ITEM_SET
&&
2293 pItem
->ISA( SfxInt16Item
) )
2295 pImpl
->pRequest
->AppendItem( *pItem
);
2298 Execute( *(pImpl
->pRequest
) );
2302 pImpl
->bIgnoreLostRedliningWarning
= false;
2306 #if HAVE_FEATURE_MULTIUSER_ENVIRONMENT
2308 void ScDocShell::EnableSharedSettings( bool bEnable
)
2310 SetDocumentModified();
2314 aDocument
.EndChangeTracking();
2315 aDocument
.StartChangeTracking();
2317 // hide accept or reject changes dialog
2318 sal_uInt16 nId
= ScAcceptChgDlgWrapper::GetChildWindowId();
2319 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
2320 if ( pViewFrame
&& pViewFrame
->HasChildWindow( nId
) )
2322 pViewFrame
->ToggleChildWindow( nId
);
2323 SfxBindings
* pBindings
= GetViewBindings();
2326 pBindings
->Invalidate( FID_CHG_ACCEPT
);
2332 aDocument
.EndChangeTracking();
2335 ScChangeViewSettings aChangeViewSet
;
2336 aChangeViewSet
.SetShowChanges( false );
2337 aDocument
.SetChangeViewSettings( aChangeViewSet
);
2340 uno::Reference
< frame::XModel
> ScDocShell::LoadSharedDocument()
2342 uno::Reference
< frame::XModel
> xModel
;
2345 SC_MOD()->SetInSharedDocLoading( true );
2346 uno::Reference
< frame::XDesktop2
> xLoader
= frame::Desktop::create( ::comphelper::getProcessComponentContext() );
2347 uno::Sequence
< beans::PropertyValue
> aArgs( 1 );
2348 aArgs
[0].Name
= "Hidden";
2349 aArgs
[0].Value
<<= sal_True
;
2353 SFX_ITEMSET_ARG( GetMedium()->GetItemSet(), pPasswordItem
, SfxStringItem
, SID_PASSWORD
, false);
2354 if ( pPasswordItem
&& !pPasswordItem
->GetValue().isEmpty() )
2357 aArgs
[1].Name
= "Password";
2358 aArgs
[1].Value
<<= pPasswordItem
->GetValue();
2363 xLoader
->loadComponentFromURL( GetSharedFileURL(), OUString( "_blank" ), 0, aArgs
),
2364 uno::UNO_QUERY_THROW
);
2365 SC_MOD()->SetInSharedDocLoading( false );
2367 catch ( uno::Exception
& )
2369 OSL_FAIL( "ScDocShell::LoadSharedDocument(): caught exception\n" );
2370 SC_MOD()->SetInSharedDocLoading( false );
2373 uno::Reference
< util::XCloseable
> xClose( xModel
, uno::UNO_QUERY_THROW
);
2374 xClose
->close( sal_True
);
2375 return uno::Reference
< frame::XModel
>();
2377 catch ( uno::Exception
& )
2379 return uno::Reference
< frame::XModel
>();
2387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */