xref: /aoo4110/main/sc/source/ui/view/pivotsh.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 
29 //------------------------------------------------------------------
30 
31 #include "scitems.hxx"
32 #include <svl/srchitem.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/objface.hxx>
35 #include <sfx2/objsh.hxx>
36 #include <sfx2/request.hxx>
37 #include <svl/whiter.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <sfx2/sidebar/EnumContext.hxx>
40 
41 #include "sc.hrc"
42 #include "pivotsh.hxx"
43 #include "tabvwsh.hxx"
44 #include "docsh.hxx"
45 #include "scresid.hxx"
46 #include "document.hxx"
47 #include "dpobject.hxx"
48 #include "dpshttab.hxx"
49 #include "dbdocfun.hxx"
50 #include "uiitems.hxx"
51 //CHINA001 #include "pfiltdlg.hxx"
52 #include "scabstdlg.hxx" //CHINA001
53 //------------------------------------------------------------------------
54 
55 #define ScPivotShell
56 #include "scslots.hxx"
57 
58 //------------------------------------------------------------------------
59 
60 TYPEINIT1( ScPivotShell, SfxShell );
61 
SFX_IMPL_INTERFACE(ScPivotShell,SfxShell,ScResId (SCSTR_PIVOTSHELL))62 SFX_IMPL_INTERFACE(ScPivotShell, SfxShell, ScResId(SCSTR_PIVOTSHELL))
63 {
64 	SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_PIVOT) );
65 }
66 
67 
68 //------------------------------------------------------------------------
69 
ScPivotShell(ScTabViewShell * pViewSh)70 ScPivotShell::ScPivotShell( ScTabViewShell* pViewSh ) :
71 	SfxShell(pViewSh),
72 	pViewShell( pViewSh )
73 {
74 	SetPool( &pViewSh->GetPool() );
75     ScViewData* pViewData = pViewSh->GetViewData();
76     ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
77     SetUndoManager( pMgr );
78     if ( !pViewData->GetDocument()->IsUndoEnabled() )
79     {
80         pMgr->SetMaxUndoActionCount( 0 );
81     }
82 	SetHelpId( HID_SCSHELL_PIVOTSH );
83 	SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Pivot")));
84     SfxShell::SetContextName(sfx2::sidebar::EnumContext::GetContextName(sfx2::sidebar::EnumContext::Context_Pivot));
85 }
86 
87 //------------------------------------------------------------------------
~ScPivotShell()88 ScPivotShell::~ScPivotShell()
89 {
90 }
91 
92 //------------------------------------------------------------------------
Execute(SfxRequest & rReq)93 void ScPivotShell::Execute( SfxRequest& rReq )
94 {
95 	switch ( rReq.GetSlot() )
96 	{
97 		case SID_PIVOT_RECALC:
98 			pViewShell->RecalcPivotTable();
99 			break;
100 
101 		case SID_PIVOT_KILL:
102 			pViewShell->DeletePivotTable();
103 			break;
104 
105         case SID_DP_FILTER:
106         {
107             ScDPObject* pDPObj = GetCurrDPObject();
108             if( pDPObj )
109             {
110                 ScQueryParam aQueryParam;
111                 SCTAB nSrcTab = 0;
112                 const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
113                 DBG_ASSERT( pDesc, "no sheet source for DP filter dialog" );
114                 if( pDesc )
115                 {
116                     aQueryParam = pDesc->aQueryParam;
117                     nSrcTab = pDesc->aSourceRange.aStart.Tab();
118                 }
119 
120                 ScViewData* pViewData = pViewShell->GetViewData();
121                 SfxItemSet aArgSet( pViewShell->GetPool(),
122                     SCITEM_QUERYDATA, SCITEM_QUERYDATA );
123                 aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, pViewData, &aQueryParam ) );
124 
125                 //CHINA001 ScPivotFilterDlg* pDlg = new ScPivotFilterDlg(
126                 //CHINA001     pViewShell->GetDialogParent(), aArgSet, nSrcTab );
127 
128 				ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
129 				DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
130 
131 				AbstractScPivotFilterDlg* pDlg = pFact->CreateScPivotFilterDlg( pViewShell->GetDialogParent(),
132 																				aArgSet, nSrcTab,
133 																				RID_SCDLG_PIVOTFILTER);
134 				DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
135 
136                 if( pDlg->Execute() == RET_OK )
137                 {
138                     ScSheetSourceDesc aNewDesc;
139                     if( pDesc )
140                         aNewDesc = *pDesc;
141 
142                     const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
143                     aNewDesc.aQueryParam = rQueryItem.GetQueryData();
144 
145                     ScDPObject aNewObj( *pDPObj );
146                     aNewObj.SetSheetDesc( aNewDesc );
147                     ScDBDocFunc aFunc( *pViewData->GetDocShell() );
148                     aFunc.DataPilotUpdate( pDPObj, &aNewObj, sal_True, sal_False );
149                     pViewData->GetView()->CursorPosChanged();       // shells may be switched
150                 }
151                 delete pDlg;
152             }
153         }
154         break;
155 	}
156 }
157 
158 //------------------------------------------------------------------------
GetState(SfxItemSet & rSet)159 void __EXPORT ScPivotShell::GetState( SfxItemSet& rSet )
160 {
161 	ScDocShell* pDocSh = pViewShell->GetViewData()->GetDocShell();
162 	ScDocument* pDoc = pDocSh->GetDocument();
163     sal_Bool bDisable = pDocSh->IsReadOnly() || pDoc->GetChangeTrack();
164 
165 	SfxWhichIter aIter(rSet);
166 	sal_uInt16 nWhich = aIter.FirstWhich();
167 	while (nWhich)
168 	{
169 		switch (nWhich)
170 		{
171 			case SID_PIVOT_RECALC:
172 			case SID_PIVOT_KILL:
173             {
174                 //! move ReadOnly check to idl flags
175                 if ( bDisable )
176                 {
177                     rSet.DisableItem( nWhich );
178                 }
179             }
180             break;
181             case SID_DP_FILTER:
182             {
183                 ScDPObject* pDPObj = GetCurrDPObject();
184                 if( bDisable || !pDPObj || !pDPObj->IsSheetData() )
185                     rSet.DisableItem( nWhich );
186             }
187             break;
188 		}
189 		nWhich = aIter.NextWhich();
190 	}
191 }
192 
193 
194 //------------------------------------------------------------------------
195 
GetCurrDPObject()196 ScDPObject* ScPivotShell::GetCurrDPObject()
197 {
198     const ScViewData& rViewData = *pViewShell->GetViewData();
199     return rViewData.GetDocument()->GetDPAtCursor(
200         rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
201 }
202