Update ooo320-m1
[ooovba.git] / sc / source / ui / view / pivotsh.cxx
blobcd33bdea167d9deb7a1713edf6e9e9a2a93f376c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pivotsh.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 //------------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/srchitem.hxx>
40 #include <sfx2/app.hxx>
41 #include <sfx2/objface.hxx>
42 #include <sfx2/objsh.hxx>
43 #include <sfx2/request.hxx>
44 #include <svtools/whiter.hxx>
45 #include <vcl/msgbox.hxx>
47 #include "sc.hrc"
48 #include "pivotsh.hxx"
49 #include "tabvwsh.hxx"
50 #include "docsh.hxx"
51 #include "scresid.hxx"
52 #include "document.hxx"
53 #include "dpobject.hxx"
54 #include "dpshttab.hxx"
55 #include "dbdocfun.hxx"
56 #include "uiitems.hxx"
57 //CHINA001 #include "pfiltdlg.hxx"
58 #include "scabstdlg.hxx" //CHINA001
60 #include "autoform.hxx"
61 #include "scuiautofmt.hxx"
62 #include "editable.hxx"
65 //------------------------------------------------------------------------
67 #define ScPivotShell
68 #include "scslots.hxx"
70 //------------------------------------------------------------------------
72 TYPEINIT1( ScPivotShell, SfxShell );
74 SFX_IMPL_INTERFACE(ScPivotShell, SfxShell, ScResId(SCSTR_PIVOTSHELL))
76 SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_PIVOT) );
80 //------------------------------------------------------------------------
82 ScPivotShell::ScPivotShell( ScTabViewShell* pViewSh ) :
83 SfxShell(pViewSh),
84 pViewShell( pViewSh )
86 SetPool( &pViewSh->GetPool() );
87 ScViewData* pViewData = pViewSh->GetViewData();
88 SfxUndoManager* pMgr = pViewData->GetSfxDocShell()->GetUndoManager();
89 SetUndoManager( pMgr );
90 if ( !pViewData->GetDocument()->IsUndoEnabled() )
92 pMgr->SetMaxUndoActionCount( 0 );
94 SetHelpId( HID_SCSHELL_PIVOTSH );
95 SetName(String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("Pivot")));
98 //------------------------------------------------------------------------
99 ScPivotShell::~ScPivotShell()
103 //------------------------------------------------------------------------
104 void ScPivotShell::Execute( SfxRequest& rReq )
106 switch ( rReq.GetSlot() )
108 case SID_PIVOT_RECALC:
109 pViewShell->RecalcPivotTable();
110 break;
111 case SID_PIVOT_AFMT:
113 ScViewData* pViewData = pViewShell->GetViewData();
115 pViewShell->GetDBData( TRUE, SC_DB_OLD );
116 const ScMarkData& rMark1 = pViewData->GetMarkData();
117 if ( !rMark1.IsMarked() && !rMark1.IsMultiMarked() )
118 pViewShell->MarkDataArea( TRUE );
120 Window* pDlgParent = pViewShell->GetDialogParent();
122 pViewData->MoveNextRow();
124 ScGlobal::ClearAutoFormat();
125 ScAutoFormatData* pNewEntry = pViewShell->CreateAutoFormatData();
126 ScAutoFormatDlg* pDlg = new ScAutoFormatDlg(
127 pDlgParent, ScGlobal::GetAutoFormat(), pNewEntry, pViewData->GetDocument() );
129 if ( pDlg->Execute() == RET_OK )
131 ScEditableTester aTester( pViewShell );
132 if ( !aTester.IsEditable() )
134 pViewShell->ErrorMessage(aTester.GetMessageId());
136 else
138 /* AutoFormat and Store the index */
139 pViewShell->AutoFormat( pDlg->GetIndex() );
140 pViewShell->AutoFormatPivotTable( pDlg->GetIndex() );
143 delete pDlg;
144 delete pNewEntry;
146 //pViewShell->DeletePivotTable();
147 //pViewShell->RecalcPivotTable();
149 break;
150 case SID_PIVOT_KILL:
151 pViewShell->DeletePivotTable();
152 break;
154 case SID_DP_FILTER:
156 ScDPObject* pDPObj = GetCurrDPObject();
157 if( pDPObj )
159 ScQueryParam aQueryParam;
160 SCTAB nSrcTab = 0;
161 const ScSheetSourceDesc* pDesc = pDPObj->GetSheetDesc();
162 DBG_ASSERT( pDesc, "no sheet source for DP filter dialog" );
163 if( pDesc )
165 aQueryParam = pDesc->aQueryParam;
166 nSrcTab = pDesc->aSourceRange.aStart.Tab();
169 ScViewData* pViewData = pViewShell->GetViewData();
170 SfxItemSet aArgSet( pViewShell->GetPool(),
171 SCITEM_QUERYDATA, SCITEM_QUERYDATA );
172 aArgSet.Put( ScQueryItem( SCITEM_QUERYDATA, pViewData, &aQueryParam ) );
174 //CHINA001 ScPivotFilterDlg* pDlg = new ScPivotFilterDlg(
175 //CHINA001 pViewShell->GetDialogParent(), aArgSet, nSrcTab );
177 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
178 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
180 AbstractScPivotFilterDlg* pDlg = pFact->CreateScPivotFilterDlg( pViewShell->GetDialogParent(),
181 aArgSet, nSrcTab,
182 RID_SCDLG_PIVOTFILTER);
183 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
185 if( pDlg->Execute() == RET_OK )
187 ScSheetSourceDesc aNewDesc;
188 if( pDesc )
189 aNewDesc = *pDesc;
191 const ScQueryItem& rQueryItem = pDlg->GetOutputItem();
192 aNewDesc.aQueryParam = rQueryItem.GetQueryData();
194 ScDPObject aNewObj( *pDPObj );
195 aNewObj.SetSheetDesc( aNewDesc );
196 ScDBDocFunc aFunc( *pViewData->GetDocShell() );
197 aFunc.DataPilotUpdate( pDPObj, &aNewObj, TRUE, FALSE );
198 pViewData->GetView()->CursorPosChanged(); // shells may be switched
200 delete pDlg;
203 break;
207 //------------------------------------------------------------------------
208 void __EXPORT ScPivotShell::GetState( SfxItemSet& rSet )
210 ScDocShell* pDocSh = pViewShell->GetViewData()->GetDocShell();
211 ScDocument* pDoc = pDocSh->GetDocument();
212 BOOL bDisable = pDocSh->IsReadOnly() || pDoc->GetChangeTrack();
214 SfxWhichIter aIter(rSet);
215 USHORT nWhich = aIter.FirstWhich();
216 while (nWhich)
218 switch (nWhich)
220 case SID_PIVOT_RECALC:
221 case SID_PIVOT_KILL:
223 //! move ReadOnly check to idl flags
224 if ( bDisable )
226 rSet.DisableItem( nWhich );
229 break;
230 case SID_DP_FILTER:
232 ScDPObject* pDPObj = GetCurrDPObject();
233 if( bDisable || !pDPObj || !pDPObj->IsSheetData() )
234 rSet.DisableItem( nWhich );
236 break;
238 nWhich = aIter.NextWhich();
243 //------------------------------------------------------------------------
245 ScDPObject* ScPivotShell::GetCurrDPObject()
247 const ScViewData& rViewData = *pViewShell->GetViewData();
248 return rViewData.GetDocument()->GetDPAtCursor(
249 rViewData.GetCurX(), rViewData.GetCurY(), rViewData.GetTabNo() );