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"
44 #include <boost/scoped_ptr.hpp>
46 TYPEINIT1( ScPivotShell
, SfxShell
);
48 SFX_IMPL_INTERFACE(ScPivotShell
, SfxShell
)
50 void ScPivotShell::InitInterface_Impl()
52 GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_PIVOT
));
55 ScPivotShell::ScPivotShell( ScTabViewShell
* pViewSh
) :
59 SetPool( &pViewSh
->GetPool() );
60 ScViewData
& rViewData
= pViewSh
->GetViewData();
61 ::svl::IUndoManager
* pMgr
= rViewData
.GetSfxDocShell()->GetUndoManager();
62 SetUndoManager( pMgr
);
63 if ( !rViewData
.GetDocument()->IsUndoEnabled() )
65 pMgr
->SetMaxUndoActionCount( 0 );
67 SetHelpId( HID_SCSHELL_PIVOTSH
);
68 SetName(OUString("Pivot"));
69 SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Pivot
));
72 ScPivotShell::~ScPivotShell()
76 void ScPivotShell::Execute( SfxRequest
& rReq
)
78 switch ( rReq
.GetSlot() )
80 case SID_PIVOT_RECALC
:
81 pViewShell
->RecalcPivotTable();
85 pViewShell
->DeletePivotTable();
90 ScDPObject
* pDPObj
= GetCurrDPObject();
93 ScQueryParam aQueryParam
;
95 const ScSheetSourceDesc
* pDesc
= pDPObj
->GetSheetDesc();
96 OSL_ENSURE( pDesc
, "no sheet source for DP filter dialog" );
99 aQueryParam
= pDesc
->GetQueryParam();
100 nSrcTab
= pDesc
->GetSourceRange().aStart
.Tab();
103 ScViewData
& rViewData
= pViewShell
->GetViewData();
104 SfxItemSet
aArgSet( pViewShell
->GetPool(),
105 SCITEM_QUERYDATA
, SCITEM_QUERYDATA
);
106 aArgSet
.Put( ScQueryItem( SCITEM_QUERYDATA
, &rViewData
, &aQueryParam
) );
108 ScAbstractDialogFactory
* pFact
= ScAbstractDialogFactory::Create();
109 OSL_ENSURE(pFact
, "ScAbstractFactory create fail!");
111 boost::scoped_ptr
<AbstractScPivotFilterDlg
> pDlg(pFact
->CreateScPivotFilterDlg(
112 pViewShell
->GetDialogParent(), aArgSet
, nSrcTab
));
113 OSL_ENSURE(pDlg
, "Dialog create fail!");
115 if( pDlg
->Execute() == RET_OK
)
117 ScSheetSourceDesc
aNewDesc(rViewData
.GetDocument());
121 const ScQueryItem
& rQueryItem
= pDlg
->GetOutputItem();
122 aNewDesc
.SetQueryParam(rQueryItem
.GetQueryData());
124 ScDPObject
aNewObj( *pDPObj
);
125 aNewObj
.SetSheetDesc( aNewDesc
);
126 ScDBDocFunc
aFunc( *rViewData
.GetDocShell() );
127 aFunc
.DataPilotUpdate( pDPObj
, &aNewObj
, true, false );
128 rViewData
.GetView()->CursorPosChanged(); // shells may be switched
136 void ScPivotShell::GetState( SfxItemSet
& rSet
)
138 ScDocShell
* pDocSh
= pViewShell
->GetViewData().GetDocShell();
139 ScDocument
& rDoc
= pDocSh
->GetDocument();
140 bool bDisable
= pDocSh
->IsReadOnly() || rDoc
.GetChangeTrack();
142 SfxWhichIter
aIter(rSet
);
143 sal_uInt16 nWhich
= aIter
.FirstWhich();
148 case SID_PIVOT_RECALC
:
151 //! move ReadOnly check to idl flags
154 rSet
.DisableItem( nWhich
);
160 ScDPObject
* pDPObj
= GetCurrDPObject();
161 if( bDisable
|| !pDPObj
|| !pDPObj
->IsSheetData() )
162 rSet
.DisableItem( nWhich
);
166 nWhich
= aIter
.NextWhich();
170 ScDPObject
* ScPivotShell::GetCurrDPObject()
172 const ScViewData
& rViewData
= pViewShell
->GetViewData();
173 return rViewData
.GetDocument()->GetDPAtCursor(
174 rViewData
.GetCurX(), rViewData
.GetCurY(), rViewData
.GetTabNo() );
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */