/src/libreoffice/sc/source/ui/view/pivotsh.cxx
Line | Count | Source (jump to first uncovered line) |
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 <sfx2/objface.hxx> |
22 | | #include <sfx2/objsh.hxx> |
23 | | #include <sfx2/request.hxx> |
24 | | #include <svl/whiter.hxx> |
25 | | #include <vcl/EnumContext.hxx> |
26 | | |
27 | | #include <sc.hrc> |
28 | | #include <pivotsh.hxx> |
29 | | #include <tabvwsh.hxx> |
30 | | #include <docsh.hxx> |
31 | | #include <document.hxx> |
32 | | #include <dpobject.hxx> |
33 | | #include <dpshttab.hxx> |
34 | | #include <dbdocfun.hxx> |
35 | | #include <uiitems.hxx> |
36 | | #include <scabstdlg.hxx> |
37 | | |
38 | | #define ShellClass_ScPivotShell |
39 | | #include <scslots.hxx> |
40 | | |
41 | | |
42 | | SFX_IMPL_INTERFACE(ScPivotShell, SfxShell) |
43 | | |
44 | | void ScPivotShell::InitInterface_Impl() |
45 | 11 | { |
46 | 11 | GetStaticInterface()->RegisterPopupMenu(u"pivot"_ustr); |
47 | 11 | } |
48 | | |
49 | | ScPivotShell::ScPivotShell( ScTabViewShell* pViewSh ) : |
50 | 0 | SfxShell(pViewSh), |
51 | 0 | pViewShell( pViewSh ) |
52 | 0 | { |
53 | 0 | SetPool( &pViewSh->GetPool() ); |
54 | 0 | ScViewData& rViewData = pViewSh->GetViewData(); |
55 | 0 | SfxUndoManager* pMgr = rViewData.GetSfxDocShell().GetUndoManager(); |
56 | 0 | SetUndoManager( pMgr ); |
57 | 0 | if ( !rViewData.GetDocument().IsUndoEnabled() ) |
58 | 0 | { |
59 | 0 | pMgr->SetMaxUndoActionCount( 0 ); |
60 | 0 | } |
61 | 0 | SetName(u"Pivot"_ustr); |
62 | 0 | SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Pivot)); |
63 | 0 | } |
64 | | |
65 | | ScPivotShell::~ScPivotShell() |
66 | 0 | { |
67 | 0 | } |
68 | | |
69 | | void ScPivotShell::Execute( const SfxRequest& rReq ) |
70 | 0 | { |
71 | 0 | switch ( rReq.GetSlot() ) |
72 | 0 | { |
73 | 0 | case SID_PIVOT_RECALC: |
74 | 0 | pViewShell->RecalcPivotTable(); |
75 | 0 | break; |
76 | | |
77 | 0 | case SID_PIVOT_KILL: |
78 | 0 | pViewShell->DeletePivotTable(); |
79 | 0 | break; |
80 | | |
81 | 0 | case SID_DP_FILTER: |
82 | 0 | { |
83 | 0 | ScDPObject* pDPObj = GetCurrDPObject(); |
84 | 0 | if( pDPObj ) |
85 | 0 | { |
86 | 0 | ScQueryParam aQueryParam; |
87 | 0 | SCTAB nSrcTab = 0; |
88 | 0 | const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc(); |
89 | 0 | OSL_ENSURE( pDesc, "no sheet source for DP filter dialog" ); |
90 | 0 | if( pDesc ) |
91 | 0 | { |
92 | 0 | aQueryParam = pDesc->GetQueryParam(); |
93 | 0 | nSrcTab = pDesc->GetSourceRange().aStart.Tab(); |
94 | 0 | } |
95 | |
|
96 | 0 | ScViewData& rViewData = pViewShell->GetViewData(); |
97 | 0 | SfxItemSetFixed<SCITEM_QUERYDATA, SCITEM_QUERYDATA> aArgSet( pViewShell->GetPool() ); |
98 | 0 | aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, &aQueryParam ) ); |
99 | |
|
100 | 0 | ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); |
101 | |
|
102 | 0 | ScopedVclPtr<AbstractScPivotFilterDlg> pDlg(pFact->CreateScPivotFilterDlg( |
103 | 0 | pViewShell->GetFrameWeld(), aArgSet, rViewData, nSrcTab)); |
104 | |
|
105 | 0 | if( pDlg->Execute() == RET_OK ) |
106 | 0 | { |
107 | 0 | ScSheetSourceDesc aNewDesc(&rViewData.GetDocument()); |
108 | 0 | if( pDesc ) |
109 | 0 | aNewDesc = *pDesc; |
110 | |
|
111 | 0 | const ScQueryItem& rQueryItem = pDlg->GetOutputItem(); |
112 | 0 | aNewDesc.SetQueryParam(rQueryItem.GetQueryData()); |
113 | |
|
114 | 0 | ScDPObject aNewObj( *pDPObj ); |
115 | 0 | aNewObj.SetSheetDesc( aNewDesc ); |
116 | 0 | ScDBDocFunc aFunc( rViewData.GetDocShell() ); |
117 | 0 | aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false ); |
118 | 0 | rViewData.GetView()->CursorPosChanged(); // shells may be switched |
119 | 0 | } |
120 | 0 | } |
121 | 0 | } |
122 | 0 | break; |
123 | 0 | } |
124 | 0 | } |
125 | | |
126 | | void ScPivotShell::GetState( SfxItemSet& rSet ) |
127 | 0 | { |
128 | 0 | ScDocShell& rDocSh = pViewShell->GetViewData().GetDocShell(); |
129 | 0 | ScDocument& rDoc = rDocSh.GetDocument(); |
130 | 0 | bool bDisable = rDocSh.IsReadOnly() || rDoc.GetChangeTrack(); |
131 | 0 | bool bFilterDisable = bDisable; |
132 | 0 | if (!bDisable) |
133 | 0 | { |
134 | 0 | SCCOL nTab = pViewShell->GetViewData().GetTabNo(); |
135 | 0 | const ScTableProtection* pTabProt = rDoc.GetTabProtection(nTab); |
136 | 0 | if (pTabProt && pTabProt->isProtected()) |
137 | 0 | { |
138 | 0 | bDisable = true; |
139 | 0 | if (!pTabProt->isOptionEnabled(ScTableProtection::PIVOT_TABLES)) |
140 | 0 | bFilterDisable = true; |
141 | 0 | } |
142 | 0 | } |
143 | |
|
144 | 0 | SfxWhichIter aIter(rSet); |
145 | 0 | sal_uInt16 nWhich = aIter.FirstWhich(); |
146 | 0 | while (nWhich) |
147 | 0 | { |
148 | 0 | switch (nWhich) |
149 | 0 | { |
150 | 0 | case SID_PIVOT_RECALC: |
151 | 0 | case SID_PIVOT_KILL: |
152 | 0 | { |
153 | | //! move ReadOnly check to idl flags |
154 | 0 | if ( bDisable ) |
155 | 0 | { |
156 | 0 | rSet.DisableItem( nWhich ); |
157 | 0 | } |
158 | 0 | } |
159 | 0 | break; |
160 | 0 | case SID_DP_FILTER: |
161 | 0 | { |
162 | 0 | ScDPObject* pDPObj = GetCurrDPObject(); |
163 | 0 | if( bFilterDisable || !pDPObj || !pDPObj->IsSheetData() ) |
164 | 0 | rSet.DisableItem( nWhich ); |
165 | 0 | } |
166 | 0 | break; |
167 | 0 | } |
168 | 0 | nWhich = aIter.NextWhich(); |
169 | 0 | } |
170 | 0 | } |
171 | | |
172 | | ScDPObject* ScPivotShell::GetCurrDPObject() |
173 | 0 | { |
174 | 0 | const ScViewData& rViewData = pViewShell->GetViewData(); |
175 | 0 | return rViewData.GetDocument().GetDPAtCursor( |
176 | 0 | rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() ); |
177 | 0 | } |
178 | | |
179 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |