LibreOffice Module sc (master)  1
pivotsh.cxx
Go to the documentation of this file.
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 
43 
44 void ScPivotShell::InitInterface_Impl()
45 {
46  GetStaticInterface()->RegisterPopupMenu("pivot");
47 }
48 
50  SfxShell(pViewSh),
51  pViewShell( pViewSh )
52 {
53  SetPool( &pViewSh->GetPool() );
54  ScViewData& rViewData = pViewSh->GetViewData();
55  SfxUndoManager* pMgr = rViewData.GetSfxDocShell()->GetUndoManager();
56  SetUndoManager( pMgr );
57  if ( !rViewData.GetDocument().IsUndoEnabled() )
58  {
59  pMgr->SetMaxUndoActionCount( 0 );
60  }
61  SetName("Pivot");
63 }
64 
66 {
67 }
68 
69 void ScPivotShell::Execute( const SfxRequest& rReq )
70 {
71  switch ( rReq.GetSlot() )
72  {
73  case SID_PIVOT_RECALC:
75  break;
76 
77  case SID_PIVOT_KILL:
79  break;
80 
81  case SID_DP_FILTER:
82  {
83  ScDPObject* pDPObj = GetCurrDPObject();
84  if( pDPObj )
85  {
86  ScQueryParam aQueryParam;
87  SCTAB nSrcTab = 0;
88  const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
89  OSL_ENSURE( pDesc, "no sheet source for DP filter dialog" );
90  if( pDesc )
91  {
92  aQueryParam = pDesc->GetQueryParam();
93  nSrcTab = pDesc->GetSourceRange().aStart.Tab();
94  }
95 
96  ScViewData& rViewData = pViewShell->GetViewData();
97  SfxItemSet aArgSet( pViewShell->GetPool(),
99  aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, &rViewData, &aQueryParam ) );
100 
102 
104  pViewShell->GetFrameWeld(), aArgSet, nSrcTab));
105 
106  if( pDlg->Execute() == RET_OK )
107  {
108  ScSheetSourceDesc aNewDesc(&rViewData.GetDocument());
109  if( pDesc )
110  aNewDesc = *pDesc;
111 
112  const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
113  aNewDesc.SetQueryParam(rQueryItem.GetQueryData());
114 
115  ScDPObject aNewObj( *pDPObj );
116  aNewObj.SetSheetDesc( aNewDesc );
117  ScDBDocFunc aFunc( *rViewData.GetDocShell() );
118  aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false );
119  rViewData.GetView()->CursorPosChanged(); // shells may be switched
120  }
121  }
122  }
123  break;
124  }
125 }
126 
128 {
130  ScDocument& rDoc = pDocSh->GetDocument();
131  bool bDisable = pDocSh->IsReadOnly() || rDoc.GetChangeTrack();
132 
133  SfxWhichIter aIter(rSet);
134  sal_uInt16 nWhich = aIter.FirstWhich();
135  while (nWhich)
136  {
137  switch (nWhich)
138  {
139  case SID_PIVOT_RECALC:
140  case SID_PIVOT_KILL:
141  {
143  if ( bDisable )
144  {
145  rSet.DisableItem( nWhich );
146  }
147  }
148  break;
149  case SID_DP_FILTER:
150  {
151  ScDPObject* pDPObj = GetCurrDPObject();
152  if( bDisable || !pDPObj || !pDPObj->IsSheetData() )
153  rSet.DisableItem( nWhich );
154  }
155  break;
156  }
157  nWhich = aIter.NextWhich();
158  }
159 }
160 
162 {
163  const ScViewData& rViewData = pViewShell->GetViewData();
164  return rViewData.GetDocument().GetDPAtCursor(
165  rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
166 }
167 
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:372
ScPivotShell(ScTabViewShell *pView)
Definition: pivotsh.cxx:49
void RecalcPivotTable()
Definition: dbfunc3.cxx:721
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScAddress aStart
Definition: address.hxx:500
#define SFX_IMPL_INTERFACE(Class, SuperClass)
void CursorPosChanged()
Definition: tabview3.cxx:625
void GetState(SfxItemSet &rSet)
Definition: pivotsh.cxx:127
sal_uInt16 char char * pDesc
Definition: callform.cxx:58
SCROW GetCurY() const
Definition: viewdata.hxx:402
sal_uInt16 FirstWhich()
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void Execute(const SfxRequest &rReq)
Definition: pivotsh.cxx:69
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
virtual short Execute()=0
#define SCITEM_QUERYDATA
Definition: scitems.hxx:91
sal_uInt16 NextWhich()
SCTAB Tab() const
Definition: address.hxx:271
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
Definition: dpshttab.cxx:229
void SetUndoManager(SfxUndoManager *pNewUndoMgr)
void SetSheetDesc(const ScSheetSourceDesc &rDesc)
Definition: dpobject.cxx:414
ScViewData & GetViewData()
Definition: tabview.hxx:332
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2392
SfxItemPool & GetPool() const
const ScQueryParam & GetQueryParam() const
Definition: dpshttab.hxx:63
bool DataPilotUpdate(ScDPObject *pOldObj, const ScDPObject *pNewObj, bool bRecord, bool bApi, bool bAllowMove=false)
Definition: dbdocfun.cxx:1239
bool IsSheetData() const
Definition: dpobject.cxx:484
void SetPool(SfxItemPool *pNewPool)
ScDPObject * GetCurrDPObject()
Definition: pivotsh.cxx:161
const ScQueryParam & GetQueryData() const
Definition: uiitems.cxx:214
void SetName(const OUString &rName)
bool IsReadOnly() const
ScDBFunc * GetView() const
Definition: viewdata.cxx:852
sal_uInt16 GetSlot() const
static const OUString & GetContextName(const Context eContext)
virtual const ScQueryItem & GetOutputItem()=0
void DisableItem(sal_uInt16 nWhich)
weld::Window * GetFrameWeld() const
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:38
RET_OK
const ScSheetSourceDesc * GetSheetDesc() const
Definition: dpobject.hxx:156
void DeletePivotTable()
Definition: dbfunc3.cxx:704
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
virtual VclPtr< AbstractScPivotFilterDlg > CreateScPivotFilterDlg(weld::Window *pParent, const SfxItemSet &rArgSet, sal_uInt16 nSourceTab)=0
virtual ~ScPivotShell() override
Definition: pivotsh.cxx:65
ScTabViewShell * pViewShell
Definition: pivotsh.hxx:48
This class contains authoritative information on the internal reference used as the data source for d...
Definition: dpshttab.hxx:39
void SetContextName(const OUString &rsContextName)
void SetMaxUndoActionCount(size_t nMaxUndoActionCount)
sal_Int16 SCTAB
Definition: types.hxx:23
SCCOL GetCurX() const
Definition: viewdata.hxx:401
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo