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