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 :
29 : #include "sc.hrc"
30 : #include "pivotsh.hxx"
31 : #include "tabvwsh.hxx"
32 : #include "docsh.hxx"
33 : #include "scresid.hxx"
34 : #include "document.hxx"
35 : #include "dpobject.hxx"
36 : #include "dpshttab.hxx"
37 : #include "dbdocfun.hxx"
38 : #include "uiitems.hxx"
39 : #include "scabstdlg.hxx"
40 : //------------------------------------------------------------------------
41 :
42 : #define ScPivotShell
43 : #include "scslots.hxx"
44 :
45 : //------------------------------------------------------------------------
46 :
47 0 : TYPEINIT1( ScPivotShell, SfxShell );
48 :
49 20 : SFX_IMPL_INTERFACE(ScPivotShell, SfxShell, ScResId(SCSTR_PIVOTSHELL))
50 : {
51 5 : SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_PIVOT) );
52 5 : }
53 :
54 :
55 : //------------------------------------------------------------------------
56 :
57 0 : ScPivotShell::ScPivotShell( ScTabViewShell* pViewSh ) :
58 : SfxShell(pViewSh),
59 0 : pViewShell( pViewSh )
60 : {
61 0 : SetPool( &pViewSh->GetPool() );
62 0 : ScViewData* pViewData = pViewSh->GetViewData();
63 0 : ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
64 0 : SetUndoManager( pMgr );
65 0 : if ( !pViewData->GetDocument()->IsUndoEnabled() )
66 : {
67 0 : pMgr->SetMaxUndoActionCount( 0 );
68 : }
69 0 : SetHelpId( HID_SCSHELL_PIVOTSH );
70 0 : SetName(rtl::OUString("Pivot"));
71 0 : }
72 :
73 : //------------------------------------------------------------------------
74 0 : ScPivotShell::~ScPivotShell()
75 : {
76 0 : }
77 :
78 : //------------------------------------------------------------------------
79 0 : void ScPivotShell::Execute( SfxRequest& rReq )
80 : {
81 0 : switch ( rReq.GetSlot() )
82 : {
83 : case SID_PIVOT_RECALC:
84 0 : pViewShell->RecalcPivotTable();
85 0 : break;
86 :
87 : case SID_PIVOT_KILL:
88 0 : pViewShell->DeletePivotTable();
89 0 : break;
90 :
91 : case SID_DP_FILTER:
92 : {
93 0 : ScDPObject* pDPObj = GetCurrDPObject();
94 0 : if( pDPObj )
95 : {
96 0 : ScQueryParam aQueryParam;
97 0 : SCTAB nSrcTab = 0;
98 0 : const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
99 : OSL_ENSURE( pDesc, "no sheet source for DP filter dialog" );
100 0 : if( pDesc )
101 : {
102 0 : aQueryParam = pDesc->GetQueryParam();
103 0 : nSrcTab = pDesc->GetSourceRange().aStart.Tab();
104 : }
105 :
106 0 : ScViewData* pViewData = pViewShell->GetViewData();
107 0 : SfxItemSet aArgSet( pViewShell->GetPool(),
108 0 : SCITEM_QUERYDATA, SCITEM_QUERYDATA );
109 0 : aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, pViewData, &aQueryParam ) );
110 :
111 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
112 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
113 :
114 : AbstractScPivotFilterDlg* pDlg = pFact->CreateScPivotFilterDlg( pViewShell->GetDialogParent(),
115 : aArgSet, nSrcTab,
116 0 : RID_SCDLG_PIVOTFILTER);
117 : OSL_ENSURE(pDlg, "Dialog create fail!");
118 :
119 0 : if( pDlg->Execute() == RET_OK )
120 : {
121 0 : ScSheetSourceDesc aNewDesc(pViewData->GetDocument());
122 0 : if( pDesc )
123 0 : aNewDesc = *pDesc;
124 :
125 0 : const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
126 0 : aNewDesc.SetQueryParam(rQueryItem.GetQueryData());
127 :
128 0 : ScDPObject aNewObj( *pDPObj );
129 0 : aNewObj.SetSheetDesc( aNewDesc );
130 0 : ScDBDocFunc aFunc( *pViewData->GetDocShell() );
131 0 : aFunc.DataPilotUpdate( pDPObj, &aNewObj, sal_True, false );
132 0 : pViewData->GetView()->CursorPosChanged(); // shells may be switched
133 : }
134 0 : delete pDlg;
135 : }
136 : }
137 0 : break;
138 : }
139 0 : }
140 :
141 : //------------------------------------------------------------------------
142 0 : void ScPivotShell::GetState( SfxItemSet& rSet )
143 : {
144 0 : ScDocShell* pDocSh = pViewShell->GetViewData()->GetDocShell();
145 0 : ScDocument* pDoc = pDocSh->GetDocument();
146 0 : sal_Bool bDisable = pDocSh->IsReadOnly() || pDoc->GetChangeTrack();
147 :
148 0 : SfxWhichIter aIter(rSet);
149 0 : sal_uInt16 nWhich = aIter.FirstWhich();
150 0 : while (nWhich)
151 : {
152 0 : switch (nWhich)
153 : {
154 : case SID_PIVOT_RECALC:
155 : case SID_PIVOT_KILL:
156 : {
157 : //! move ReadOnly check to idl flags
158 0 : if ( bDisable )
159 : {
160 0 : rSet.DisableItem( nWhich );
161 : }
162 : }
163 0 : break;
164 : case SID_DP_FILTER:
165 : {
166 0 : ScDPObject* pDPObj = GetCurrDPObject();
167 0 : if( bDisable || !pDPObj || !pDPObj->IsSheetData() )
168 0 : rSet.DisableItem( nWhich );
169 : }
170 0 : break;
171 : }
172 0 : nWhich = aIter.NextWhich();
173 0 : }
174 0 : }
175 :
176 :
177 : //------------------------------------------------------------------------
178 :
179 0 : ScDPObject* ScPivotShell::GetCurrDPObject()
180 : {
181 0 : const ScViewData& rViewData = *pViewShell->GetViewData();
182 : return rViewData.GetDocument()->GetDPAtCursor(
183 0 : rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
184 15 : }
185 :
186 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|