xref: /trunk/main/sc/source/ui/view/pivotsh.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 
32 
33 //------------------------------------------------------------------
34 
35 #include "scitems.hxx"
36 #include <svl/srchitem.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/objface.hxx>
39 #include <sfx2/objsh.hxx>
40 #include <sfx2/request.hxx>
41 #include <svl/whiter.hxx>
42 #include <vcl/msgbox.hxx>
43 
44 #include "sc.hrc"
45 #include "pivotsh.hxx"
46 #include "tabvwsh.hxx"
47 #include "docsh.hxx"
48 #include "scresid.hxx"
49 #include "document.hxx"
50 #include "dpobject.hxx"
51 #include "dpshttab.hxx"
52 #include "dbdocfun.hxx"
53 #include "uiitems.hxx"
54 //CHINA001 #include "pfiltdlg.hxx"
55 #include "scabstdlg.hxx" //CHINA001
56 //------------------------------------------------------------------------
57 
58 #define ScPivotShell
59 #include "scslots.hxx"
60 
61 //------------------------------------------------------------------------
62 
63 TYPEINIT1( ScPivotShell, SfxShell );
64 
65 SFX_IMPL_INTERFACE(ScPivotShell, SfxShell, ScResId(SCSTR_PIVOTSHELL))
66 {
67     SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_PIVOT) );
68 }
69 
70 
71 //------------------------------------------------------------------------
72 
73 ScPivotShell::ScPivotShell( ScTabViewShell* pViewSh ) :
74     SfxShell(pViewSh),
75     pViewShell( pViewSh )
76 {
77     SetPool( &pViewSh->GetPool() );
78     ScViewData* pViewData = pViewSh->GetViewData();
79     ::svl::IUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
80     SetUndoManager( pMgr );
81     if ( !pViewData->GetDocument()->IsUndoEnabled() )
82     {
83         pMgr->SetMaxUndoActionCount( 0 );
84     }
85     SetHelpId( HID_SCSHELL_PIVOTSH );
86     SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Pivot")));
87 }
88 
89 //------------------------------------------------------------------------
90 ScPivotShell::~ScPivotShell()
91 {
92 }
93 
94 //------------------------------------------------------------------------
95 void ScPivotShell::Execute( SfxRequest& rReq )
96 {
97     switch ( rReq.GetSlot() )
98     {
99         case SID_PIVOT_RECALC:
100             pViewShell->RecalcPivotTable();
101             break;
102 
103         case SID_PIVOT_KILL:
104             pViewShell->DeletePivotTable();
105             break;
106 
107         case SID_DP_FILTER:
108         {
109             ScDPObject* pDPObj = GetCurrDPObject();
110             if( pDPObj )
111             {
112                 ScQueryParam aQueryParam;
113                 SCTAB nSrcTab = 0;
114                 const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
115                 DBG_ASSERT( pDesc, "no sheet source for DP filter dialog" );
116                 if( pDesc )
117                 {
118                     aQueryParam = pDesc->aQueryParam;
119                     nSrcTab = pDesc->aSourceRange.aStart.Tab();
120                 }
121 
122                 ScViewData* pViewData = pViewShell->GetViewData();
123                 SfxItemSet aArgSet( pViewShell->GetPool(),
124                     SCITEM_QUERYDATA, SCITEM_QUERYDATA );
125                 aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, pViewData, &aQueryParam ) );
126 
127                 //CHINA001 ScPivotFilterDlg* pDlg = new ScPivotFilterDlg(
128                 //CHINA001     pViewShell->GetDialogParent(), aArgSet, nSrcTab );
129 
130                 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
131                 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
132 
133                 AbstractScPivotFilterDlg* pDlg = pFact->CreateScPivotFilterDlg( pViewShell->GetDialogParent(),
134                                                                                 aArgSet, nSrcTab,
135                                                                                 RID_SCDLG_PIVOTFILTER);
136                 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
137 
138                 if( pDlg->Execute() == RET_OK )
139                 {
140                     ScSheetSourceDesc aNewDesc;
141                     if( pDesc )
142                         aNewDesc = *pDesc;
143 
144                     const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
145                     aNewDesc.aQueryParam = rQueryItem.GetQueryData();
146 
147                     ScDPObject aNewObj( *pDPObj );
148                     aNewObj.SetSheetDesc( aNewDesc );
149                     ScDBDocFunc aFunc( *pViewData->GetDocShell() );
150                     aFunc.DataPilotUpdate( pDPObj, &aNewObj, sal_True, sal_False );
151                     pViewData->GetView()->CursorPosChanged();       // shells may be switched
152                 }
153                 delete pDlg;
154             }
155         }
156         break;
157     }
158 }
159 
160 //------------------------------------------------------------------------
161 void __EXPORT ScPivotShell::GetState( SfxItemSet& rSet )
162 {
163     ScDocShell* pDocSh = pViewShell->GetViewData()->GetDocShell();
164     ScDocument* pDoc = pDocSh->GetDocument();
165     sal_Bool bDisable = pDocSh->IsReadOnly() || pDoc->GetChangeTrack();
166 
167     SfxWhichIter aIter(rSet);
168     sal_uInt16 nWhich = aIter.FirstWhich();
169     while (nWhich)
170     {
171         switch (nWhich)
172         {
173             case SID_PIVOT_RECALC:
174             case SID_PIVOT_KILL:
175             {
176                 //! move ReadOnly check to idl flags
177                 if ( bDisable )
178                 {
179                     rSet.DisableItem( nWhich );
180                 }
181             }
182             break;
183             case SID_DP_FILTER:
184             {
185                 ScDPObject* pDPObj = GetCurrDPObject();
186                 if( bDisable || !pDPObj || !pDPObj->IsSheetData() )
187                     rSet.DisableItem( nWhich );
188             }
189             break;
190         }
191         nWhich = aIter.NextWhich();
192     }
193 }
194 
195 
196 //------------------------------------------------------------------------
197 
198 ScDPObject* ScPivotShell::GetCurrDPObject()
199 {
200     const ScViewData& rViewData = *pViewShell->GetViewData();
201     return rViewData.GetDocument()->GetDPAtCursor(
202         rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );
203 }
204 
205