Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / view / pivotsh.cxx
blobb5c13839438af23083b733f279c4f2f87618c889
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
30 #include "sc.hrc"
31 #include "pivotsh.hxx"
32 #include "tabvwsh.hxx"
33 #include "docsh.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"
42 #define ScPivotShell
43 #include "scslots.hxx"
44 #include <memory>
47 SFX_IMPL_INTERFACE(ScPivotShell, SfxShell)
49 void ScPivotShell::InitInterface_Impl()
51 GetStaticInterface()->RegisterPopupMenu("pivot");
54 ScPivotShell::ScPivotShell( ScTabViewShell* pViewSh ) :
55 SfxShell(pViewSh),
56 pViewShell( 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 );
67 SetName("Pivot");
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();
81 break;
83 case SID_PIVOT_KILL:
84 pViewShell->DeletePivotTable();
85 break;
87 case SID_DP_FILTER:
89 ScDPObject* pDPObj = GetCurrDPObject();
90 if( pDPObj )
92 ScQueryParam aQueryParam;
93 SCTAB nSrcTab = 0;
94 const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
95 OSL_ENSURE( pDesc, "no sheet source for DP filter dialog" );
96 if( pDesc )
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());
117 if( pDesc )
118 aNewDesc = *pDesc;
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
131 break;
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();
143 while (nWhich)
145 switch (nWhich)
147 case SID_PIVOT_RECALC:
148 case SID_PIVOT_KILL:
150 //! move ReadOnly check to idl flags
151 if ( bDisable )
153 rSet.DisableItem( nWhich );
156 break;
157 case SID_DP_FILTER:
159 ScDPObject* pDPObj = GetCurrDPObject();
160 if( bDisable || !pDPObj || !pDPObj->IsSheetData() )
161 rSet.DisableItem( nWhich );
163 break;
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: */