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();
98  aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, &rViewData, &aQueryParam ) );
99 
101 
103  pViewShell->GetFrameWeld(), aArgSet, nSrcTab));
104 
105  if( pDlg->Execute() == RET_OK )
106  {
107  ScSheetSourceDesc aNewDesc(&rViewData.GetDocument());
108  if( pDesc )
109  aNewDesc = *pDesc;
110 
111  const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
112  aNewDesc.SetQueryParam(rQueryItem.GetQueryData());
113 
114  ScDPObject aNewObj( *pDPObj );
115  aNewObj.SetSheetDesc( aNewDesc );
116  ScDBDocFunc aFunc( *rViewData.GetDocShell() );
117  aFunc.DataPilotUpdate( pDPObj, &aNewObj, true, false );
118  rViewData.GetView()->CursorPosChanged(); // shells may be switched
119  }
120  }
121  }
122  break;
123  }
124 }
125 
127 {
129  ScDocument& rDoc = pDocSh->GetDocument();
130  bool bDisable = pDocSh->IsReadOnly() || rDoc.GetChangeTrack();
131 
132  SfxWhichIter aIter(rSet);
133  sal_uInt16 nWhich = aIter.FirstWhich();
134  while (nWhich)
135  {
136  switch (nWhich)
137  {
138  case SID_PIVOT_RECALC:
139  case SID_PIVOT_KILL:
140  {
142  if ( bDisable )
143  {
144  rSet.DisableItem( nWhich );
145  }
146  }
147  break;
148  case SID_DP_FILTER:
149  {
150  ScDPObject* pDPObj = GetCurrDPObject();
151  if( bDisable || !pDPObj || !pDPObj->IsSheetData() )
152  rSet.DisableItem( nWhich );
153  }
154  break;
155  }
156  nWhich = aIter.NextWhich();
157  }
158 }
159 
161 {
162  const ScViewData& rViewData = pViewShell->GetViewData();
163  return rViewData.GetDocument().GetDPAtCursor(
164  rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
165 }
166 
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC ScDPObject * GetDPAtCursor(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: documen3.cxx:377
ScPivotShell(ScTabViewShell *pView)
Definition: pivotsh.cxx:49
void RecalcPivotTable()
Definition: dbfunc3.cxx:723
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
ScAddress aStart
Definition: address.hxx:497
#define SFX_IMPL_INTERFACE(Class, SuperClass)
void CursorPosChanged()
Definition: tabview3.cxx:629
void GetState(SfxItemSet &rSet)
Definition: pivotsh.cxx:126
sal_uInt16 char char * pDesc
Definition: callform.cxx:57
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:283
SC_DLLPUBLIC const ScRange & GetSourceRange() const
Get the range that contains the source data.
Definition: dpshttab.cxx:230
void SetUndoManager(SfxUndoManager *pNewUndoMgr)
void SetSheetDesc(const ScSheetSourceDesc &rDesc)
Definition: dpobject.cxx:414
ScViewData & GetViewData()
Definition: tabview.hxx:333
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2485
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:1297
bool IsSheetData() const
Definition: dpobject.cxx:484
void SetPool(SfxItemPool *pNewPool)
ScDPObject * GetCurrDPObject()
Definition: pivotsh.cxx:160
const ScQueryParam & GetQueryData() const
Definition: uiitems.cxx:214
void SetName(const OUString &rName)
bool IsReadOnly() const
ScDBFunc * GetView() const
Definition: viewdata.cxx:863
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
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:37
RET_OK
const ScSheetSourceDesc * GetSheetDesc() const
Definition: dpobject.hxx:156
void DeletePivotTable()
Definition: dbfunc3.cxx:706
const ScDocument & GetDocument() const
Definition: docsh.hxx:220
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:47
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:22
SCCOL GetCurX() const
Definition: viewdata.hxx:401
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo