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"
41 //------------------------------------------------------------------------
44 #include "scslots.hxx"
46 //------------------------------------------------------------------------
48 TYPEINIT1( ScPivotShell
, SfxShell
);
50 SFX_IMPL_INTERFACE(ScPivotShell
, SfxShell
, ScResId(SCSTR_PIVOTSHELL
))
52 SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_PIVOT
) );
56 //------------------------------------------------------------------------
58 ScPivotShell::ScPivotShell( ScTabViewShell
* pViewSh
) :
62 SetPool( &pViewSh
->GetPool() );
63 ScViewData
* pViewData
= pViewSh
->GetViewData();
64 ::svl::IUndoManager
* pMgr
= pViewData
->GetSfxDocShell()->GetUndoManager();
65 SetUndoManager( pMgr
);
66 if ( !pViewData
->GetDocument()->IsUndoEnabled() )
68 pMgr
->SetMaxUndoActionCount( 0 );
70 SetHelpId( HID_SCSHELL_PIVOTSH
);
71 SetName(OUString("Pivot"));
72 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Pivot
));
75 //------------------------------------------------------------------------
76 ScPivotShell::~ScPivotShell()
80 //------------------------------------------------------------------------
81 void ScPivotShell::Execute( SfxRequest
& rReq
)
83 switch ( rReq
.GetSlot() )
85 case SID_PIVOT_RECALC
:
86 pViewShell
->RecalcPivotTable();
90 pViewShell
->DeletePivotTable();
95 ScDPObject
* pDPObj
= GetCurrDPObject();
98 ScQueryParam aQueryParam
;
100 const ScSheetSourceDesc
* pDesc
= pDPObj
->GetSheetDesc();
101 OSL_ENSURE( pDesc
, "no sheet source for DP filter dialog" );
104 aQueryParam
= pDesc
->GetQueryParam();
105 nSrcTab
= pDesc
->GetSourceRange().aStart
.Tab();
108 ScViewData
* pViewData
= pViewShell
->GetViewData();
109 SfxItemSet
aArgSet( pViewShell
->GetPool(),
110 SCITEM_QUERYDATA
, SCITEM_QUERYDATA
);
111 aArgSet
.Put( ScQueryItem( SCITEM_QUERYDATA
, pViewData
, &aQueryParam
) );
113 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
114 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
116 AbstractScPivotFilterDlg
* pDlg
= pFact
->CreateScPivotFilterDlg( pViewShell
->GetDialogParent(),
118 RID_SCDLG_PIVOTFILTER
);
119 OSL_ENSURE(pDlg
, "Dialog create fail!");
121 if( pDlg
->Execute() == RET_OK
)
123 ScSheetSourceDesc
aNewDesc(pViewData
->GetDocument());
127 const ScQueryItem
& rQueryItem
= pDlg
->GetOutputItem();
128 aNewDesc
.SetQueryParam(rQueryItem
.GetQueryData());
130 ScDPObject
aNewObj( *pDPObj
);
131 aNewObj
.SetSheetDesc( aNewDesc
);
132 ScDBDocFunc
aFunc( *pViewData
->GetDocShell() );
133 aFunc
.DataPilotUpdate( pDPObj
, &aNewObj
, sal_True
, false );
134 pViewData
->GetView()->CursorPosChanged(); // shells may be switched
143 //------------------------------------------------------------------------
144 void ScPivotShell::GetState( SfxItemSet
& rSet
)
146 ScDocShell
* pDocSh
= pViewShell
->GetViewData()->GetDocShell();
147 ScDocument
* pDoc
= pDocSh
->GetDocument();
148 sal_Bool bDisable
= pDocSh
->IsReadOnly() || pDoc
->GetChangeTrack();
150 SfxWhichIter
aIter(rSet
);
151 sal_uInt16 nWhich
= aIter
.FirstWhich();
156 case SID_PIVOT_RECALC
:
159 //! move ReadOnly check to idl flags
162 rSet
.DisableItem( nWhich
);
168 ScDPObject
* pDPObj
= GetCurrDPObject();
169 if( bDisable
|| !pDPObj
|| !pDPObj
->IsSheetData() )
170 rSet
.DisableItem( nWhich
);
174 nWhich
= aIter
.NextWhich();
179 //------------------------------------------------------------------------
181 ScDPObject
* ScPivotShell::GetCurrDPObject()
183 const ScViewData
& rViewData
= *pViewShell
->GetViewData();
184 return rViewData
.GetDocument()->GetDPAtCursor(
185 rViewData
.GetCurX(), rViewData
.GetCurY(), rViewData
.GetTabNo() );
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */