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 "scitems.hxx"
21 #include <svl/srchitem.hxx>
22 #include <sfx2/app.hxx>
23 #include <sfx2/objface.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <sfx2/request.hxx>
26 #include <svl/whiter.hxx>
27 #include <vcl/msgbox.hxx>
28 #include <sfx2/sidebar/EnumContext.hxx>
31 #include "pivotsh.hxx"
32 #include "tabvwsh.hxx"
34 #include "scresid.hxx"
35 #include "document.hxx"
36 #include "dpobject.hxx"
37 #include "dpshttab.hxx"
38 #include "dbdocfun.hxx"
39 #include "uiitems.hxx"
40 #include "scabstdlg.hxx"
43 #include "scslots.hxx"
47 SFX_IMPL_INTERFACE(ScPivotShell
, SfxShell
)
49 void ScPivotShell::InitInterface_Impl()
51 GetStaticInterface()->RegisterPopupMenu("pivot");
54 ScPivotShell::ScPivotShell( ScTabViewShell
* pViewSh
) :
58 SetPool( &pViewSh
->GetPool() );
59 ScViewData
& rViewData
= pViewSh
->GetViewData();
60 ::svl::IUndoManager
* pMgr
= rViewData
.GetSfxDocShell()->GetUndoManager();
61 SetUndoManager( pMgr
);
62 if ( !rViewData
.GetDocument()->IsUndoEnabled() )
64 pMgr
->SetMaxUndoActionCount( 0 );
66 SetHelpId( HID_SCSHELL_PIVOTSH
);
68 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Pivot
));
71 ScPivotShell::~ScPivotShell()
75 void ScPivotShell::Execute( SfxRequest
& rReq
)
77 switch ( rReq
.GetSlot() )
79 case SID_PIVOT_RECALC
:
80 pViewShell
->RecalcPivotTable();
84 pViewShell
->DeletePivotTable();
89 ScDPObject
* pDPObj
= GetCurrDPObject();
92 ScQueryParam aQueryParam
;
94 const ScSheetSourceDesc
* pDesc
= pDPObj
->GetSheetDesc();
95 OSL_ENSURE( pDesc
, "no sheet source for DP filter dialog" );
98 aQueryParam
= pDesc
->GetQueryParam();
99 nSrcTab
= pDesc
->GetSourceRange().aStart
.Tab();
102 ScViewData
& rViewData
= pViewShell
->GetViewData();
103 SfxItemSet
aArgSet( pViewShell
->GetPool(),
104 SCITEM_QUERYDATA
, SCITEM_QUERYDATA
);
105 aArgSet
.Put( ScQueryItem( SCITEM_QUERYDATA
, &rViewData
, &aQueryParam
) );
107 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
108 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
110 std::unique_ptr
<AbstractScPivotFilterDlg
> pDlg(pFact
->CreateScPivotFilterDlg(
111 pViewShell
->GetDialogParent(), aArgSet
, nSrcTab
));
112 OSL_ENSURE(pDlg
, "Dialog create fail!");
114 if( pDlg
->Execute() == RET_OK
)
116 ScSheetSourceDesc
aNewDesc(rViewData
.GetDocument());
120 const ScQueryItem
& rQueryItem
= pDlg
->GetOutputItem();
121 aNewDesc
.SetQueryParam(rQueryItem
.GetQueryData());
123 ScDPObject
aNewObj( *pDPObj
);
124 aNewObj
.SetSheetDesc( aNewDesc
);
125 ScDBDocFunc
aFunc( *rViewData
.GetDocShell() );
126 aFunc
.DataPilotUpdate( pDPObj
, &aNewObj
, true, false );
127 rViewData
.GetView()->CursorPosChanged(); // shells may be switched
135 void ScPivotShell::GetState( SfxItemSet
& rSet
)
137 ScDocShell
* pDocSh
= pViewShell
->GetViewData().GetDocShell();
138 ScDocument
& rDoc
= pDocSh
->GetDocument();
139 bool bDisable
= pDocSh
->IsReadOnly() || rDoc
.GetChangeTrack();
141 SfxWhichIter
aIter(rSet
);
142 sal_uInt16 nWhich
= aIter
.FirstWhich();
147 case SID_PIVOT_RECALC
:
150 //! move ReadOnly check to idl flags
153 rSet
.DisableItem( nWhich
);
159 ScDPObject
* pDPObj
= GetCurrDPObject();
160 if( bDisable
|| !pDPObj
|| !pDPObj
->IsSheetData() )
161 rSet
.DisableItem( nWhich
);
165 nWhich
= aIter
.NextWhich();
169 ScDPObject
* ScPivotShell::GetCurrDPObject()
171 const ScViewData
& rViewData
= pViewShell
->GetViewData();
172 return rViewData
.GetDocument()->GetDPAtCursor(
173 rViewData
.GetCurX(), rViewData
.GetCurY(), rViewData
.GetTabNo() );
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */