Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
29 :
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"
41 :
42 : #define ScPivotShell
43 : #include "scslots.hxx"
44 : #include <boost/scoped_ptr.hpp>
45 :
46 0 : TYPEINIT1( ScPivotShell, SfxShell );
47 :
48 156 : SFX_IMPL_INTERFACE(ScPivotShell, SfxShell)
49 :
50 52 : void ScPivotShell::InitInterface_Impl()
51 : {
52 52 : GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_PIVOT));
53 52 : }
54 :
55 1 : ScPivotShell::ScPivotShell( ScTabViewShell* pViewSh ) :
56 : SfxShell(pViewSh),
57 1 : pViewShell( pViewSh )
58 : {
59 1 : SetPool( &pViewSh->GetPool() );
60 1 : ScViewData& rViewData = pViewSh->GetViewData();
61 1 : ::svl::IUndoManager* pMgr = rViewData.GetSfxDocShell()->GetUndoManager();
62 1 : SetUndoManager( pMgr );
63 1 : if ( !rViewData.GetDocument()->IsUndoEnabled() )
64 : {
65 0 : pMgr->SetMaxUndoActionCount( 0 );
66 : }
67 1 : SetHelpId( HID_SCSHELL_PIVOTSH );
68 1 : SetName(OUString("Pivot"));
69 1 : SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Pivot));
70 1 : }
71 :
72 2 : ScPivotShell::~ScPivotShell()
73 : {
74 2 : }
75 :
76 0 : void ScPivotShell::Execute( SfxRequest& rReq )
77 : {
78 0 : switch ( rReq.GetSlot() )
79 : {
80 : case SID_PIVOT_RECALC:
81 0 : pViewShell->RecalcPivotTable();
82 0 : break;
83 :
84 : case SID_PIVOT_KILL:
85 0 : pViewShell->DeletePivotTable();
86 0 : break;
87 :
88 : case SID_DP_FILTER:
89 : {
90 0 : ScDPObject* pDPObj = GetCurrDPObject();
91 0 : if( pDPObj )
92 : {
93 0 : ScQueryParam aQueryParam;
94 0 : SCTAB nSrcTab = 0;
95 0 : const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
96 : OSL_ENSURE( pDesc, "no sheet source for DP filter dialog" );
97 0 : if( pDesc )
98 : {
99 0 : aQueryParam = pDesc->GetQueryParam();
100 0 : nSrcTab = pDesc->GetSourceRange().aStart.Tab();
101 : }
102 :
103 0 : ScViewData& rViewData = pViewShell->GetViewData();
104 0 : SfxItemSet aArgSet( pViewShell->GetPool(),
105 0 : SCITEM_QUERYDATA, SCITEM_QUERYDATA );
106 0 : aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, &rViewData, &aQueryParam ) );
107 :
108 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
109 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
110 :
111 : boost::scoped_ptr<AbstractScPivotFilterDlg> pDlg(pFact->CreateScPivotFilterDlg(
112 0 : pViewShell->GetDialogParent(), aArgSet, nSrcTab));
113 : OSL_ENSURE(pDlg, "Dialog create fail!");
114 :
115 0 : if( pDlg->Execute() == RET_OK )
116 : {
117 0 : ScSheetSourceDesc aNewDesc(rViewData.GetDocument());
118 0 : if( pDesc )
119 0 : aNewDesc = *pDesc;
120 :
121 0 : const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
122 0 : aNewDesc.SetQueryParam(rQueryItem.GetQueryData());
123 :
124 0 : ScDPObject aNewObj( *pDPObj );
125 0 : aNewObj.SetSheetDesc( aNewDesc );
126 0 : ScDBDocFunc aFunc( *rViewData.GetDocShell() );
127 0 : aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false );
128 0 : rViewData.GetView()->CursorPosChanged(); // shells may be switched
129 0 : }
130 : }
131 : }
132 0 : break;
133 : }
134 0 : }
135 :
136 0 : void ScPivotShell::GetState( SfxItemSet& rSet )
137 : {
138 0 : ScDocShell* pDocSh = pViewShell->GetViewData().GetDocShell();
139 0 : ScDocument& rDoc = pDocSh->GetDocument();
140 0 : bool bDisable = pDocSh->IsReadOnly() || rDoc.GetChangeTrack();
141 :
142 0 : SfxWhichIter aIter(rSet);
143 0 : sal_uInt16 nWhich = aIter.FirstWhich();
144 0 : while (nWhich)
145 : {
146 0 : switch (nWhich)
147 : {
148 : case SID_PIVOT_RECALC:
149 : case SID_PIVOT_KILL:
150 : {
151 : //! move ReadOnly check to idl flags
152 0 : if ( bDisable )
153 : {
154 0 : rSet.DisableItem( nWhich );
155 : }
156 : }
157 0 : break;
158 : case SID_DP_FILTER:
159 : {
160 0 : ScDPObject* pDPObj = GetCurrDPObject();
161 0 : if( bDisable || !pDPObj || !pDPObj->IsSheetData() )
162 0 : rSet.DisableItem( nWhich );
163 : }
164 0 : break;
165 : }
166 0 : nWhich = aIter.NextWhich();
167 0 : }
168 0 : }
169 :
170 0 : ScDPObject* ScPivotShell::GetCurrDPObject()
171 : {
172 0 : const ScViewData& rViewData = pViewShell->GetViewData();
173 : return rViewData.GetDocument()->GetDPAtCursor(
174 0 : rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
175 156 : }
176 :
177 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|