Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "pvlaydlg.hxx"
30 : : #include "dbdocfun.hxx"
31 : : #include "dpuiglobal.hxx"
32 : :
33 : : #include <sfx2/dispatch.hxx>
34 : : #include <vcl/msgbox.hxx>
35 : :
36 : : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
37 : : #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
38 : :
39 : : #include "uiitems.hxx"
40 : : #include "rangeutl.hxx"
41 : : #include "document.hxx"
42 : : #include "viewdata.hxx"
43 : : #include "tabvwsh.hxx"
44 : : #include "reffact.hxx"
45 : : #include "scresid.hxx"
46 : : #include "globstr.hrc"
47 : : #include "pivot.hrc"
48 : : #include "dpobject.hxx"
49 : : #include "dpsave.hxx"
50 : : #include "dpshttab.hxx"
51 : : #include "scmod.hxx"
52 : :
53 : : #include "sc.hrc"
54 : : #include "scabstdlg.hxx"
55 : :
56 : : using namespace com::sun::star;
57 : : using ::rtl::OUString;
58 : : using ::std::vector;
59 : : using ::std::for_each;
60 : :
61 : : //----------------------------------------------------------------------------
62 : :
63 : : #define FSTR(index) aFuncNameArr[index-1]
64 : : #define STD_FORMAT SCA_VALID | SCA_TAB_3D \
65 : : | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
66 : :
67 : : //============================================================================
68 : :
69 : : namespace {
70 : :
71 : 0 : PointerStyle lclGetPointerForField( ScDPFieldType eType )
72 : : {
73 [ # # # # : 0 : switch( eType )
# # ]
74 : : {
75 : 0 : case TYPE_PAGE: return POINTER_PIVOT_FIELD;
76 : 0 : case TYPE_COL: return POINTER_PIVOT_COL;
77 : 0 : case TYPE_ROW: return POINTER_PIVOT_ROW;
78 : 0 : case TYPE_DATA: return POINTER_PIVOT_FIELD;
79 : 0 : case TYPE_SELECT: return POINTER_PIVOT_FIELD;
80 : : }
81 : 0 : return POINTER_ARROW;
82 : : }
83 : :
84 : : } // namespace
85 : :
86 : : //============================================================================
87 : :
88 : : //----------------------------------------------------------------------------
89 : :
90 : 0 : ScDPLayoutDlg::ScDPLayoutDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
91 : : const ScDPObject& rDPObject, bool bNewOutput )
92 : : : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_PIVOT_LAYOUT ),
93 : : aFlLayout ( this, ScResId( FL_LAYOUT ) ),
94 : : aFtPage ( this, ScResId( FT_PAGE ) ),
95 : : aWndPage ( this, ScResId( WND_PAGE ), &aFtPage ),
96 : : aFtCol ( this, ScResId( FT_COL ) ),
97 : : aWndCol ( this, ScResId( WND_COL ), &aFtCol ),
98 : : aFtRow ( this, ScResId( FT_ROW ) ),
99 : : aWndRow ( this, ScResId( WND_ROW ), &aFtRow ),
100 : : aFtData ( this, ScResId( FT_DATA ) ),
101 : : aWndData ( this, ScResId( WND_DATA ), &aFtData ),
102 : : aWndSelect ( this, ScResId( WND_SELECT ), NULL ),
103 : : aFtInfo ( this, ScResId( FT_INFO ) ),
104 : :
105 : : aFlAreas ( this, ScResId( FL_OUTPUT ) ),
106 : :
107 : : aFtInArea ( this, ScResId( FT_INAREA) ),
108 : : aEdInPos ( this, ScResId( ED_INAREA) ),
109 : : aRbInPos ( this, ScResId( RB_INAREA ), &aEdInPos, this ),
110 : :
111 : : aLbOutPos ( this, ScResId( LB_OUTAREA ) ),
112 : : aFtOutArea ( this, ScResId( FT_OUTAREA ) ),
113 : : aEdOutPos ( this, this, ScResId( ED_OUTAREA ) ),
114 : : aRbOutPos ( this, ScResId( RB_OUTAREA ), &aEdOutPos, this ),
115 : : aBtnIgnEmptyRows( this, ScResId( BTN_IGNEMPTYROWS ) ),
116 : : aBtnDetectCat ( this, ScResId( BTN_DETECTCAT ) ),
117 : : aBtnTotalCol ( this, ScResId( BTN_TOTALCOL ) ),
118 : : aBtnTotalRow ( this, ScResId( BTN_TOTALROW ) ),
119 : : aBtnFilter ( this, ScResId( BTN_FILTER ) ),
120 : : aBtnDrillDown ( this, ScResId( BTN_DRILLDOWN ) ),
121 : :
122 : : aBtnOk ( this, ScResId( BTN_OK ) ),
123 : : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
124 : : aBtnHelp ( this, ScResId( BTN_HELP ) ),
125 : : aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
126 : : aBtnOptions ( this, ScResId( BTN_OPTIONS ) ),
127 : : aBtnMore ( this, ScResId( BTN_MORE ) ),
128 : :
129 : : aStrUndefined (SC_RESSTR(SCSTR_UNDEFINED)),
130 : : aStrNewTable (SC_RESSTR(SCSTR_NEWTABLE)),
131 : :
132 : : bIsDrag ( false ),
133 : :
134 : : pEditActive ( NULL ),
135 : :
136 : : eLastActiveType ( TYPE_SELECT ),
137 : : nOffset ( 0 ),
138 : : //
139 [ # # ]: 0 : xDlgDPObject ( new ScDPObject( rDPObject ) ),
140 [ # # ]: 0 : pViewData ( ((ScTabViewShell*)SfxViewShell::Current())->
141 : 0 : GetViewData() ),
142 [ # # ]: 0 : pDoc ( ((ScTabViewShell*)SfxViewShell::Current())->
143 [ # # ]: 0 : GetViewData()->GetDocument() ),
144 [ # # ][ # # ]: 0 : bRefInputMode (false)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
145 : : {
146 [ # # ]: 0 : xDlgDPObject->SetAlive( true ); // needed to get structure information
147 [ # # ]: 0 : xDlgDPObject->FillOldParam( thePivotData );
148 [ # # ]: 0 : xDlgDPObject->FillLabelData( thePivotData );
149 : :
150 [ # # ]: 0 : Init(bNewOutput);
151 [ # # ]: 0 : FreeResource();
152 : 0 : }
153 : :
154 : : //----------------------------------------------------------------------------
155 : :
156 [ # # ][ # # ]: 0 : ScDPLayoutDlg::~ScDPLayoutDlg()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
157 : : {
158 [ # # ]: 0 : sal_uInt16 nEntries = aLbOutPos.GetEntryCount();
159 : : sal_uInt16 i;
160 : :
161 [ # # ]: 0 : for ( i=2; i<nEntries; i++ )
162 [ # # ][ # # ]: 0 : delete (rtl::OUString*)aLbOutPos.GetEntryData( i );
163 [ # # ]: 0 : }
164 : :
165 : : //----------------------------------------------------------------------------
166 : :
167 : 0 : void ScDPLayoutDlg::Init(bool bNewOutput)
168 : : {
169 : : OSL_ENSURE( pViewData && pDoc,
170 : : "Ctor-Initialisierung fehlgeschlagen!" );
171 : :
172 [ # # ]: 0 : aBtnRemove.SetClickHdl( LINK( this, ScDPLayoutDlg, ClickHdl ) );
173 [ # # ]: 0 : aBtnOptions.SetClickHdl( LINK( this, ScDPLayoutDlg, ClickHdl ) );
174 : :
175 [ # # ]: 0 : aFuncNameArr.reserve( PIVOT_MAXFUNC );
176 [ # # ]: 0 : for ( sal_uInt16 i = 0; i < PIVOT_MAXFUNC; ++i )
177 [ # # ][ # # ]: 0 : aFuncNameArr.push_back(SC_RESSTR(i+1));
[ # # ]
178 : :
179 [ # # ]: 0 : aBtnMore.AddWindow( &aFlAreas );
180 [ # # ]: 0 : aBtnMore.AddWindow( &aFtInArea );
181 [ # # ]: 0 : aBtnMore.AddWindow( &aEdInPos );
182 [ # # ]: 0 : aBtnMore.AddWindow( &aRbInPos );
183 [ # # ]: 0 : aBtnMore.AddWindow( &aFtOutArea );
184 [ # # ]: 0 : aBtnMore.AddWindow( &aLbOutPos );
185 [ # # ]: 0 : aBtnMore.AddWindow( &aEdOutPos );
186 [ # # ]: 0 : aBtnMore.AddWindow( &aRbOutPos );
187 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnIgnEmptyRows );
188 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnDetectCat );
189 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnTotalCol );
190 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnTotalRow );
191 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnFilter );
192 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnDrillDown );
193 [ # # ]: 0 : aBtnMore.SetClickHdl( LINK( this, ScDPLayoutDlg, MoreClickHdl ) );
194 : :
195 [ # # ]: 0 : CalcWndSizes();
196 : :
197 : 0 : ScRange inRange;
198 : 0 : rtl::OUString inString;
199 [ # # ]: 0 : if (xDlgDPObject->GetSheetDesc())
200 : : {
201 [ # # ]: 0 : aEdInPos.Enable();
202 [ # # ]: 0 : aRbInPos.Enable();
203 : 0 : const ScSheetSourceDesc* p = xDlgDPObject->GetSheetDesc();
204 [ # # ]: 0 : OUString aRangeName = p->GetRangeName();
205 [ # # ]: 0 : if (!aRangeName.isEmpty())
206 [ # # ][ # # ]: 0 : aEdInPos.SetText(aRangeName);
[ # # ]
207 : : else
208 : : {
209 [ # # ]: 0 : aOldRange = p->GetSourceRange();
210 [ # # ][ # # ]: 0 : aOldRange.Format( inString, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
211 [ # # ][ # # ]: 0 : aEdInPos.SetText(inString);
[ # # ]
212 : 0 : }
213 : : }
214 : : else
215 : : {
216 : : /* Data is not reachable, so could be a remote database */
217 [ # # ]: 0 : aEdInPos.Disable();
218 [ # # ]: 0 : aRbInPos.Disable();
219 : : }
220 : :
221 [ # # ]: 0 : InitFields();
222 : :
223 [ # # ]: 0 : aLbOutPos .SetSelectHdl( LINK( this, ScDPLayoutDlg, SelAreaHdl ) );
224 [ # # ]: 0 : aEdOutPos .SetModifyHdl( LINK( this, ScDPLayoutDlg, EdModifyHdl ) );
225 [ # # ]: 0 : aEdInPos .SetModifyHdl( LINK( this, ScDPLayoutDlg, EdInModifyHdl ) );
226 [ # # ]: 0 : aBtnOk .SetClickHdl ( LINK( this, ScDPLayoutDlg, OkHdl ) );
227 [ # # ]: 0 : aBtnCancel.SetClickHdl ( LINK( this, ScDPLayoutDlg, CancelHdl ) );
228 [ # # ]: 0 : Link aLink = LINK( this, ScDPLayoutDlg, GetFocusHdl );
229 [ # # ][ # # ]: 0 : if ( aEdInPos.IsEnabled() )
230 : : // Once disabled it will never get enabled, so no need to handle focus.
231 : 0 : aEdInPos.SetGetFocusHdl( aLink );
232 : 0 : aEdOutPos.SetGetFocusHdl( aLink );
233 : :
234 [ # # ][ # # ]: 0 : if ( pViewData && pDoc )
235 : : {
236 : : /*
237 : : * Aus den RangeNames des Dokumentes werden nun die
238 : : * in einem Zeiger-Array gemerkt, bei denen es sich
239 : : * um sinnvolle Bereiche handelt
240 : : */
241 : :
242 [ # # ]: 0 : aLbOutPos.Clear();
243 [ # # ][ # # ]: 0 : aLbOutPos.InsertEntry( aStrUndefined, 0 );
[ # # ]
244 [ # # ][ # # ]: 0 : aLbOutPos.InsertEntry( aStrNewTable, 1 );
[ # # ]
245 : :
246 [ # # ]: 0 : ScAreaNameIterator aIter( pDoc );
247 : 0 : rtl::OUString aName;
248 : 0 : ScRange aRange;
249 : 0 : rtl::OUString aRefStr;
250 [ # # ][ # # ]: 0 : while ( aIter.Next( aName, aRange ) )
251 : : {
252 [ # # ]: 0 : if ( !aIter.WasDBName() ) // hier keine DB-Bereiche !
253 : : {
254 [ # # ][ # # ]: 0 : sal_uInt16 nInsert = aLbOutPos.InsertEntry( aName );
[ # # ]
255 : :
256 [ # # ][ # # ]: 0 : aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, pDoc->GetAddressConvention() );
257 [ # # ][ # # ]: 0 : aLbOutPos.SetEntryData(nInsert, new rtl::OUString(aRefStr));
258 : : }
259 : 0 : }
260 : : }
261 : :
262 [ # # ]: 0 : if (bNewOutput)
263 : : {
264 : : // Output to a new sheet by default for a brand-new output.
265 [ # # ]: 0 : aLbOutPos.SelectEntryPos(1);
266 [ # # ]: 0 : aEdOutPos.Disable();
267 [ # # ]: 0 : aRbOutPos.Disable();
268 : : }
269 : : else
270 : : {
271 : : // Modifying an existing dp output.
272 : :
273 [ # # ]: 0 : if ( thePivotData.nTab != MAXTAB+1 )
274 : : {
275 : 0 : rtl::OUString aStr;
276 : : ScAddress( thePivotData.nCol,
277 : : thePivotData.nRow,
278 [ # # ][ # # ]: 0 : thePivotData.nTab ).Format( aStr, STD_FORMAT, pDoc, pDoc->GetAddressConvention() );
279 [ # # ][ # # ]: 0 : aEdOutPos.SetText( aStr );
[ # # ]
280 [ # # ]: 0 : EdModifyHdl(0);
281 : : }
282 : : else
283 : : {
284 [ # # ][ # # ]: 0 : aLbOutPos.SelectEntryPos( aLbOutPos.GetEntryCount()-1 );
285 [ # # ]: 0 : SelAreaHdl(NULL);
286 : : }
287 : : }
288 : :
289 [ # # ]: 0 : aBtnIgnEmptyRows.Check( thePivotData.bIgnoreEmptyRows );
290 [ # # ]: 0 : aBtnDetectCat .Check( thePivotData.bDetectCategories );
291 [ # # ]: 0 : aBtnTotalCol .Check( thePivotData.bMakeTotalCol );
292 [ # # ]: 0 : aBtnTotalRow .Check( thePivotData.bMakeTotalRow );
293 : :
294 [ # # ]: 0 : if( const ScDPSaveData* pSaveData = xDlgDPObject->GetSaveData() )
295 : : {
296 [ # # ]: 0 : aBtnFilter.Check( pSaveData->GetFilterButton() );
297 [ # # ]: 0 : aBtnDrillDown.Check( pSaveData->GetDrillDown() );
298 : : }
299 : : else
300 : : {
301 [ # # ]: 0 : aBtnFilter.Check();
302 [ # # ]: 0 : aBtnDrillDown.Check();
303 : : }
304 : :
305 [ # # ]: 0 : aWndPage.SetHelpId( HID_SC_DPLAY_PAGE );
306 [ # # ]: 0 : aWndCol.SetHelpId( HID_SC_DPLAY_COLUMN );
307 [ # # ]: 0 : aWndRow.SetHelpId( HID_SC_DPLAY_ROW );
308 [ # # ]: 0 : aWndData.SetHelpId( HID_SC_DPLAY_DATA );
309 [ # # ]: 0 : aWndSelect.SetHelpId( HID_SC_DPLAY_SELECT );
310 : :
311 [ # # ]: 0 : InitFocus();
312 : 0 : }
313 : :
314 : : //----------------------------------------------------------------------------
315 : :
316 : 0 : sal_Bool ScDPLayoutDlg::Close()
317 : : {
318 : 0 : return DoClose( ScPivotLayoutWrapper::GetChildWindowId() );
319 : : }
320 : :
321 : : //----------------------------------------------------------------------------
322 : :
323 : 0 : void ScDPLayoutDlg::StateChanged( StateChangedType nStateChange )
324 : : {
325 : 0 : ScAnyRefDlg::StateChanged( nStateChange );
326 : :
327 [ # # ]: 0 : if ( nStateChange == STATE_CHANGE_INITSHOW )
328 : : {
329 : : // Hiding the FixedTexts and clearing the tab stop style bits
330 : : // has to be done after assigning the mnemonics, but Paint is too late,
331 : : // because the test tool may send key events to the dialog when it isn't visible.
332 : : // Mnemonics are assigned in the Dialog::StateChanged for STATE_CHANGE_INITSHOW,
333 : : // so this can be done immediately afterwards.
334 : :
335 : 0 : aWndPage.UseMnemonic();
336 : 0 : aWndCol.UseMnemonic();
337 : 0 : aWndRow.UseMnemonic();
338 : 0 : aWndData.UseMnemonic();
339 : : }
340 : 0 : }
341 : :
342 : : //----------------------------------------------------------------------------
343 : :
344 : 0 : void ScDPLayoutDlg::InitWndSelect(const ScDPLabelDataVec& rLabels)
345 : : {
346 : 0 : size_t nLabelCount = rLabels.size();
347 [ # # ]: 0 : if (nLabelCount > SC_DP_MAX_FIELDS)
348 : 0 : nLabelCount = SC_DP_MAX_FIELDS;
349 : :
350 : 0 : aLabelDataArr.clear();
351 : 0 : aLabelDataArr.reserve( nLabelCount );
352 [ # # ]: 0 : for ( size_t i=0; i < nLabelCount; i++ )
353 : : {
354 : 0 : const ScDPLabelData& r = rLabels[i];
355 : :
356 [ # # ]: 0 : aLabelDataArr.push_back(new ScDPLabelData(r));
357 [ # # ][ # # ]: 0 : if (r.mnOriginalDim < 0 && !r.mbDataLayout)
358 : : {
359 : : // For dimension with duplicates, use the layout name of the
360 : : // original dimension if available. Be aware that duplicate
361 : : // dimensions may have different layout names.
362 [ # # ]: 0 : aWndSelect.AddField(aLabelDataArr[i].getDisplayName(), i);
363 [ # # ]: 0 : aSelectArr.push_back(new ScDPFuncData(aLabelDataArr[i].mnCol, aLabelDataArr[i].mnFuncMask));
364 : : }
365 : : }
366 : 0 : aWndSelect.ResetScrollBar();
367 [ # # ]: 0 : aWndSelect.Paint(Rectangle());
368 : 0 : }
369 : :
370 : 0 : void ScDPLayoutDlg::InitWndData(const vector<PivotField>& rFields)
371 : : {
372 : 0 : vector<PivotField>::const_iterator it = rFields.begin(), itEnd = rFields.end();
373 [ # # ][ # # ]: 0 : for (; it != itEnd; ++it)
374 : : {
375 : 0 : SCCOL nCol = it->nCol;
376 : 0 : sal_uInt16 nMask = it->nFuncMask;
377 [ # # ]: 0 : if (nCol == PIVOT_DATA_FIELD)
378 : 0 : continue;
379 : :
380 : 0 : size_t nFieldIndex = aDataArr.size();
381 : : aDataArr.push_back(
382 [ # # ][ # # ]: 0 : new ScDPFuncData(nCol, it->mnOriginalDim, nMask, it->mnDupCount, it->maFieldRef));
[ # # ]
383 : :
384 : : // data field - we need to concatenate function name with the field name.
385 [ # # ]: 0 : ScDPLabelData* pData = GetLabelData(nCol);
386 : : OSL_ENSURE( pData, "ScDPLabelData not found" );
387 [ # # ]: 0 : if (pData)
388 : : {
389 : 0 : OUString aStr = pData->maLayoutName;
390 [ # # ]: 0 : if (aStr.isEmpty())
391 : : {
392 [ # # ]: 0 : sal_uInt16 nInitMask = aDataArr.back().mnFuncMask;
393 [ # # ]: 0 : aStr = GetFuncString(nInitMask, pData->mbIsValue);
394 : 0 : aStr += pData->maName;
395 : : }
396 : :
397 [ # # ]: 0 : aWndData.AddField(aStr, nFieldIndex);
398 : 0 : pData->mnFuncMask = nMask;
399 : : }
400 : : }
401 [ # # ]: 0 : aWndData.ResetScrollBar();
402 : 0 : }
403 : :
404 : 0 : void ScDPLayoutDlg::InitFieldWindow( const vector<PivotField>& rFields, ScDPFieldType eType )
405 : : {
406 : : OSL_ASSERT(eType != TYPE_DATA);
407 : 0 : ScDPFuncDataVec* pInitArr = GetFieldDataArray(eType);
408 : 0 : ScDPFieldControlBase* pInitWnd = GetFieldWindow(eType);
409 : :
410 [ # # ][ # # ]: 0 : if (!pInitArr || !pInitWnd)
411 : 0 : return;
412 : :
413 : 0 : vector<PivotField>::const_iterator itr = rFields.begin(), itrEnd = rFields.end();
414 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
415 : : {
416 : 0 : SCCOL nCol = itr->nCol;
417 : 0 : sal_uInt16 nMask = itr->nFuncMask;
418 [ # # ]: 0 : if (nCol == PIVOT_DATA_FIELD)
419 : 0 : continue;
420 : :
421 : 0 : size_t nFieldIndex = pInitArr->size();
422 : : pInitArr->push_back(
423 [ # # ][ # # ]: 0 : new ScDPFuncData(nCol, itr->mnOriginalDim, nMask, itr->mnDupCount, itr->maFieldRef));
[ # # ]
424 [ # # ][ # # ]: 0 : pInitWnd->AddField(GetLabelString(nCol), nFieldIndex);
425 : : }
426 [ # # ]: 0 : pInitWnd->ResetScrollBar();
427 : : }
428 : :
429 : : //----------------------------------------------------------------------------
430 : :
431 : 0 : void ScDPLayoutDlg::InitFocus()
432 : : {
433 [ # # ]: 0 : if( aWndSelect.IsEmpty() )
434 : : {
435 : 0 : aBtnOk.GrabFocus();
436 : 0 : NotifyFieldFocus( TYPE_SELECT, false );
437 : : }
438 : : else
439 : 0 : aWndSelect.GrabFocus();
440 : 0 : }
441 : :
442 : 0 : void ScDPLayoutDlg::InitFields()
443 : : {
444 : 0 : InitWndSelect(thePivotData.maLabelArray);
445 : 0 : InitFieldWindow(thePivotData.maPageFields, TYPE_PAGE);
446 : 0 : InitFieldWindow(thePivotData.maColFields, TYPE_COL);
447 : 0 : InitFieldWindow(thePivotData.maRowFields, TYPE_ROW);
448 : 0 : InitWndData(thePivotData.maDataFields);
449 : 0 : }
450 : :
451 : : //----------------------------------------------------------------------------
452 : :
453 : 0 : void ScDPLayoutDlg::AddField( size_t nFromIndex, ScDPFieldType eToType, const Point& rAtPos )
454 : : {
455 [ # # ]: 0 : ScDPFuncData fData = aSelectArr[nFromIndex];
456 : :
457 [ # # ]: 0 : bool bAllowed = IsOrientationAllowed( fData.mnCol, eToType );
458 [ # # ]: 0 : if (!bAllowed)
459 : : return;
460 : :
461 : 0 : size_t nAt = 0;
462 : 0 : ScDPFieldControlBase* toWnd = GetFieldWindow(eToType);
463 : 0 : ScDPFieldControlBase* rmWnd1 = NULL;
464 : 0 : ScDPFieldControlBase* rmWnd2 = NULL;
465 : 0 : GetOtherFieldWindows(eToType, rmWnd1, rmWnd2);
466 : :
467 : 0 : ScDPFuncDataVec* toArr = GetFieldDataArray(eToType);
468 : 0 : ScDPFuncDataVec* rmArr1 = NULL;
469 : 0 : ScDPFuncDataVec* rmArr2 = NULL;
470 : 0 : GetOtherDataArrays(eToType, rmArr1, rmArr2);
471 : :
472 [ # # ]: 0 : if (eToType == TYPE_DATA)
473 : : {
474 : : // Data field allows duplicates.
475 [ # # ]: 0 : ScDPLabelData* p = GetLabelData(fData.mnCol);
476 : 0 : OUString aStr = p->maLayoutName;
477 : 0 : sal_uInt16 nMask = fData.mnFuncMask;
478 [ # # ]: 0 : if (nMask == PIVOT_FUNC_NONE)
479 : 0 : nMask = PIVOT_FUNC_SUM; // Use SUM by default.
480 [ # # ]: 0 : if (aStr.isEmpty())
481 : : {
482 [ # # ]: 0 : aStr = GetFuncString(nMask);
483 : 0 : aStr += p->maName;
484 : : }
485 : :
486 : 0 : size_t nAddedAt = 0;
487 : 0 : sal_uInt8 nDupCount = 0;
488 [ # # ][ # # ]: 0 : if (toWnd->AddField(aStr, DlgPos2WndPos(rAtPos, *toWnd), nAddedAt, nDupCount))
[ # # ]
489 : : {
490 : 0 : fData.mnFuncMask = nMask;
491 : 0 : fData.mnDupCount = nDupCount;
492 [ # # ]: 0 : Insert(toArr, fData, nAddedAt);
493 [ # # ]: 0 : toWnd->GrabFocus();
494 : : }
495 : :
496 : 0 : return;
497 : : }
498 : :
499 [ # # ][ # # ]: 0 : if (!Contains(toArr, fData, nAt))
500 : : {
501 : : // ggF. in anderem Fenster entfernen
502 [ # # ]: 0 : if ( rmArr1 )
503 : : {
504 [ # # ][ # # ]: 0 : if ( Contains( rmArr1, fData, nAt ) )
505 : : {
506 [ # # ]: 0 : rmWnd1->DelField( nAt );
507 [ # # ]: 0 : Remove( rmArr1, nAt );
508 : : }
509 : : }
510 [ # # ]: 0 : if ( rmArr2 )
511 : : {
512 [ # # ][ # # ]: 0 : if ( Contains( rmArr2, fData, nAt ) )
513 : : {
514 [ # # ]: 0 : rmWnd2->DelField( nAt );
515 [ # # ]: 0 : Remove( rmArr2, nAt );
516 : : }
517 : : }
518 : :
519 : 0 : size_t nAddedAt = 0;
520 : 0 : sal_uInt8 nDupCount = 0;
521 [ # # ]: 0 : ScDPLabelData& rData = aLabelDataArr[nFromIndex+nOffset];
522 [ # # # # ]: 0 : if (toWnd->AddField(
523 [ # # ][ # # ]: 0 : rData.getDisplayName(), DlgPos2WndPos(rAtPos, *toWnd), nAddedAt, nDupCount))
524 : : {
525 : 0 : fData.mnDupCount = nDupCount;
526 [ # # ]: 0 : Insert( toArr, fData, nAddedAt );
527 [ # # ]: 0 : toWnd->GrabFocus();
528 : : }
529 [ # # ]: 0 : }
530 : : }
531 : :
532 : 0 : void ScDPLayoutDlg::AppendField(size_t nFromIndex, ScDPFieldType eToType)
533 : : {
534 [ # # ]: 0 : ScDPFuncData aFuncData = aSelectArr[nFromIndex];
535 : :
536 : 0 : size_t nAt = 0;
537 : 0 : ScDPFieldControlBase* toWnd = GetFieldWindow(eToType);
538 : 0 : ScDPFieldControlBase* rmWnd1 = NULL;
539 : 0 : ScDPFieldControlBase* rmWnd2 = NULL;
540 : 0 : GetOtherFieldWindows(eToType, rmWnd1, rmWnd2);
541 : :
542 : 0 : ScDPFuncDataVec* toArr = GetFieldDataArray(eToType);
543 : 0 : ScDPFuncDataVec* rmArr1 = NULL;
544 : 0 : ScDPFuncDataVec* rmArr2 = NULL;
545 : 0 : GetOtherDataArrays(eToType, rmArr1, rmArr2);
546 : :
547 : 0 : bool bDataArr = eToType == TYPE_DATA;
548 : :
549 [ # # ][ # # ]: 0 : if ( (!Contains( toArr, aFuncData, nAt )) )
550 : : {
551 : : // ggF. in anderem Fenster entfernen
552 [ # # ]: 0 : if ( rmArr1 )
553 : : {
554 [ # # ][ # # ]: 0 : if ( Contains( rmArr1, aFuncData, nAt ) )
555 : : {
556 [ # # ]: 0 : rmWnd1->DelField( nAt );
557 [ # # ]: 0 : Remove( rmArr1, nAt );
558 : : }
559 : : }
560 [ # # ]: 0 : if ( rmArr2 )
561 : : {
562 [ # # ][ # # ]: 0 : if ( Contains( rmArr2, aFuncData, nAt ) )
563 : : {
564 [ # # ]: 0 : rmWnd2->DelField( nAt );
565 [ # # ]: 0 : Remove( rmArr2, nAt );
566 : : }
567 : : }
568 : :
569 [ # # ]: 0 : ScDPLabelData& rData = aLabelDataArr[nFromIndex+nOffset];
570 : 0 : size_t nAddedAt = 0;
571 : :
572 [ # # ]: 0 : if ( !bDataArr )
573 : : {
574 [ # # ][ # # ]: 0 : if ( toWnd->AppendField(rData.getDisplayName(), nAddedAt) )
[ # # ]
575 : : {
576 [ # # ]: 0 : Insert( toArr, aFuncData, nAddedAt );
577 [ # # ]: 0 : toWnd->GrabFocus();
578 : : }
579 : : }
580 : : else
581 : : {
582 [ # # ]: 0 : ScDPLabelData* p = GetLabelData(aFuncData.mnCol);
583 : 0 : OUString aStr = p->maLayoutName;
584 : 0 : sal_uInt16 nMask = aFuncData.mnFuncMask;
585 [ # # ]: 0 : if (aStr.isEmpty())
586 : : {
587 [ # # ]: 0 : aStr = GetFuncString(nMask);
588 : 0 : aStr += p->maName;
589 : : }
590 : :
591 [ # # ][ # # ]: 0 : if ( toWnd->AppendField(aStr, nAddedAt) )
592 : : {
593 : 0 : aFuncData.mnFuncMask = nMask;
594 [ # # ]: 0 : Insert( toArr, aFuncData, nAddedAt );
595 [ # # ]: 0 : toWnd->GrabFocus();
596 : 0 : }
597 : : }
598 : 0 : }
599 : 0 : }
600 : :
601 : : //----------------------------------------------------------------------------
602 : :
603 : 0 : void ScDPLayoutDlg::MoveField( ScDPFieldType eFromType, size_t nFromIndex, ScDPFieldType eToType, const Point& rAtPos )
604 : : {
605 [ # # ]: 0 : if ( eFromType == TYPE_SELECT )
606 : 0 : AddField( nFromIndex, eToType, rAtPos );
607 [ # # ][ # # ]: 0 : else if (eFromType != TYPE_SELECT && eToType == TYPE_SELECT)
608 : 0 : RemoveField(eFromType, nFromIndex);
609 [ # # ]: 0 : else if ( eFromType != eToType )
610 : : {
611 : 0 : ScDPFieldControlBase* fromWnd = GetFieldWindow(eFromType);
612 : 0 : ScDPFieldControlBase* toWnd = GetFieldWindow(eToType);
613 : :
614 : 0 : ScDPFieldControlBase* rmWnd1 = NULL;
615 : 0 : ScDPFieldControlBase* rmWnd2 = NULL;
616 : 0 : GetOtherFieldWindows(eToType, rmWnd1, rmWnd2);
617 : :
618 : 0 : ScDPFuncDataVec* fromArr = GetFieldDataArray(eFromType);
619 : 0 : ScDPFuncDataVec* toArr = GetFieldDataArray(eToType);
620 : :
621 : 0 : ScDPFuncDataVec* rmArr1 = NULL;
622 : 0 : ScDPFuncDataVec* rmArr2 = NULL;
623 : 0 : GetOtherDataArrays(eToType, rmArr1, rmArr2);
624 : :
625 : 0 : bool bDataArr = eToType == TYPE_DATA;
626 : :
627 [ # # ][ # # ]: 0 : if ( fromArr && toArr && fromWnd && toWnd )
[ # # ][ # # ]
628 : : {
629 [ # # ]: 0 : ScDPFuncData fData = (*fromArr)[nFromIndex];
630 [ # # ]: 0 : bool bAllowed = IsOrientationAllowed( fData.mnCol, eToType );
631 : :
632 : 0 : size_t nAt = 0;
633 [ # # ][ # # ]: 0 : if ( bAllowed && Contains( fromArr, fData, nAt ) )
[ # # ][ # # ]
634 : : {
635 [ # # ]: 0 : fromWnd->DelField( nAt );
636 [ # # ]: 0 : Remove( fromArr, nAt );
637 : :
638 [ # # ][ # # ]: 0 : if (!Contains( toArr, fData, nAt ))
639 : : {
640 : 0 : size_t nAddedAt = 0;
641 : 0 : sal_uInt8 nDupCount = 0;
642 [ # # ]: 0 : if ( !bDataArr )
643 : : {
644 : : // ggF. in anderem Fenster entfernen
645 [ # # ]: 0 : if ( rmArr1 )
646 : : {
647 [ # # ][ # # ]: 0 : if ( Contains( rmArr1, fData, nAt ) )
648 : : {
649 [ # # ]: 0 : rmWnd1->DelField( nAt );
650 [ # # ]: 0 : Remove( rmArr1, nAt );
651 : : }
652 : : }
653 [ # # ]: 0 : if ( rmArr2 )
654 : : {
655 [ # # ][ # # ]: 0 : if ( Contains( rmArr2, fData, nAt ) )
656 : : {
657 [ # # ]: 0 : rmWnd2->DelField( nAt );
658 [ # # ]: 0 : Remove( rmArr2, nAt );
659 : : }
660 : : }
661 : :
662 [ # # # # ]: 0 : if ( toWnd->AddField( GetLabelString( fData.mnCol ),
663 : 0 : DlgPos2WndPos( rAtPos, *toWnd ),
664 [ # # ][ # # ]: 0 : nAddedAt, nDupCount) )
665 : : {
666 : 0 : fData.mnDupCount = nDupCount;
667 [ # # ]: 0 : Insert( toArr, fData, nAddedAt );
668 [ # # ]: 0 : toWnd->GrabFocus();
669 : : }
670 : : }
671 : : else
672 : : {
673 [ # # ]: 0 : ScDPLabelData* p = GetLabelData(fData.mnCol);
674 : 0 : OUString aStr = p->maLayoutName;
675 : 0 : sal_uInt16 nMask = fData.mnFuncMask;
676 [ # # ]: 0 : if (aStr.isEmpty())
677 : : {
678 [ # # ]: 0 : aStr = GetFuncString(nMask);
679 : 0 : aStr += p->maName;
680 : : }
681 : :
682 [ # # ][ # # ]: 0 : if ( toWnd->AddField( aStr,
683 : 0 : DlgPos2WndPos( rAtPos, *toWnd ),
684 [ # # ]: 0 : nAddedAt, nDupCount) )
685 : : {
686 : 0 : fData.mnFuncMask = nMask;
687 : 0 : fData.mnDupCount = nDupCount;
688 [ # # ]: 0 : Insert( toArr, fData, nAddedAt );
689 [ # # ]: 0 : toWnd->GrabFocus();
690 : 0 : }
691 : : }
692 : : }
693 : 0 : }
694 : : }
695 : : }
696 : : else // -> eFromType == eToType
697 : : {
698 : 0 : ScDPFieldControlBase* theWnd = GetFieldWindow(eFromType);
699 : 0 : ScDPFuncDataVec* theArr = GetFieldDataArray(eFromType);
700 : 0 : size_t nAt = 0;
701 : 0 : Point aToPos;
702 : :
703 [ # # ]: 0 : ScDPFuncData fData = (*theArr)[nFromIndex];
704 : :
705 [ # # ][ # # ]: 0 : if ( Contains( theArr, fData, nAt ) )
706 : : {
707 : 0 : size_t nToIndex = 0;
708 [ # # ]: 0 : aToPos = DlgPos2WndPos( rAtPos, *theWnd );
709 [ # # ]: 0 : theWnd->GetExistingIndex( aToPos, nToIndex );
710 : :
711 [ # # ]: 0 : if ( nToIndex != nAt )
712 : : {
713 : 0 : size_t nAddedAt = 0;
714 [ # # ][ # # ]: 0 : if (theWnd->MoveField(nAt, aToPos, nAddedAt))
715 : : {
716 [ # # ]: 0 : Remove(theArr, nAt);
717 [ # # ]: 0 : Insert(theArr, fData, nAddedAt);
718 : : }
719 : : }
720 : 0 : }
721 : : }
722 : 0 : }
723 : :
724 : 0 : void ScDPLayoutDlg::MoveFieldToEnd( ScDPFieldType eFromType, size_t nFromIndex, ScDPFieldType eToType )
725 : : {
726 [ # # ]: 0 : if ( eFromType == TYPE_SELECT )
727 : 0 : AppendField( nFromIndex, eToType );
728 [ # # ]: 0 : else if ( eFromType != eToType )
729 : : {
730 : 0 : ScDPFieldControlBase* fromWnd = GetFieldWindow(eFromType);
731 : 0 : ScDPFieldControlBase* toWnd = GetFieldWindow(eToType);
732 : :
733 : 0 : ScDPFieldControlBase* rmWnd1 = NULL;
734 : 0 : ScDPFieldControlBase* rmWnd2 = NULL;
735 : 0 : GetOtherFieldWindows(eToType, rmWnd1, rmWnd2);
736 : :
737 : 0 : ScDPFuncDataVec* fromArr = GetFieldDataArray(eFromType);
738 : 0 : ScDPFuncDataVec* toArr = GetFieldDataArray(eToType);
739 : :
740 : 0 : ScDPFuncDataVec* rmArr1 = NULL;
741 : 0 : ScDPFuncDataVec* rmArr2 = NULL;
742 : 0 : GetOtherDataArrays(eToType, rmArr1, rmArr2);
743 : :
744 : 0 : bool bDataArr = eToType == TYPE_DATA;
745 : :
746 [ # # ][ # # ]: 0 : if ( fromArr && toArr && fromWnd && toWnd )
[ # # ][ # # ]
747 : : {
748 [ # # ]: 0 : ScDPFuncData fData = (*fromArr)[nFromIndex];
749 : :
750 : 0 : size_t nAt = 0;
751 [ # # ][ # # ]: 0 : if ( Contains( fromArr, fData, nAt ) )
752 : : {
753 [ # # ]: 0 : fromWnd->DelField( nAt );
754 [ # # ]: 0 : Remove( fromArr, nAt );
755 : :
756 [ # # ][ # # ]: 0 : if (!Contains( toArr, fData, nAt ))
757 : : {
758 : 0 : size_t nAddedAt = 0;
759 [ # # ]: 0 : if ( !bDataArr )
760 : : {
761 : : // ggF. in anderem Fenster entfernen
762 [ # # ]: 0 : if ( rmArr1 )
763 : : {
764 [ # # ][ # # ]: 0 : if ( Contains( rmArr1, fData, nAt ) )
765 : : {
766 [ # # ]: 0 : rmWnd1->DelField( nAt );
767 [ # # ]: 0 : Remove( rmArr1, nAt );
768 : : }
769 : : }
770 [ # # ]: 0 : if ( rmArr2 )
771 : : {
772 [ # # ][ # # ]: 0 : if ( Contains( rmArr2, fData, nAt ) )
773 : : {
774 [ # # ]: 0 : rmWnd2->DelField( nAt );
775 [ # # ]: 0 : Remove( rmArr2, nAt );
776 : : }
777 : : }
778 : :
779 [ # # ][ # # ]: 0 : if ( toWnd->AppendField( GetLabelString( fData.mnCol ), nAddedAt ) )
[ # # ]
780 : : {
781 [ # # ]: 0 : Insert( toArr, fData, nAddedAt );
782 [ # # ]: 0 : toWnd->GrabFocus();
783 : : }
784 : : }
785 : : else
786 : : {
787 [ # # ]: 0 : ScDPLabelData* p = GetLabelData(fData.mnCol);
788 : 0 : OUString aStr = p->maLayoutName;
789 : 0 : sal_uInt16 nMask = fData.mnFuncMask;
790 [ # # ]: 0 : if (aStr.isEmpty())
791 : : {
792 [ # # ]: 0 : aStr = GetFuncString(nMask);
793 : 0 : aStr += p->maName;
794 : : }
795 : :
796 [ # # ][ # # ]: 0 : if ( toWnd->AppendField(aStr, nAddedAt) )
797 : : {
798 : 0 : fData.mnFuncMask = nMask;
799 [ # # ]: 0 : Insert( toArr, fData, nAddedAt );
800 [ # # ]: 0 : toWnd->GrabFocus();
801 : 0 : }
802 : : }
803 : : }
804 : 0 : }
805 : : }
806 : : }
807 : : else // -> eFromType == eToType
808 : : {
809 : 0 : ScDPFieldControlBase* theWnd = GetFieldWindow(eFromType);
810 : 0 : ScDPFuncDataVec* theArr = GetFieldDataArray(eFromType);
811 : 0 : size_t nAt = 0;
812 : 0 : Point aToPos;
813 : 0 : bool bDataArr = eFromType == TYPE_DATA;
814 : :
815 [ # # ]: 0 : ScDPFuncData fData = (*theArr)[nFromIndex];
816 : :
817 [ # # ][ # # ]: 0 : if ( Contains( theArr, fData, nAt ) )
818 : : {
819 : 0 : size_t nToIndex = 0;
820 [ # # ]: 0 : theWnd->GetExistingIndex( aToPos, nToIndex );
821 : :
822 [ # # ]: 0 : if ( nToIndex != nAt )
823 : : {
824 : 0 : size_t nAddedAt = 0;
825 : :
826 [ # # ]: 0 : theWnd->DelField( nAt );
827 [ # # ]: 0 : Remove( theArr, nAt );
828 : :
829 [ # # ]: 0 : if ( !bDataArr )
830 : : {
831 [ # # ][ # # ]: 0 : if ( theWnd->AppendField(GetLabelString( fData.mnCol ), nAddedAt) )
[ # # ]
832 : : {
833 [ # # ]: 0 : Insert( theArr, fData, nAddedAt );
834 : : }
835 : : }
836 : : else
837 : : {
838 [ # # ]: 0 : ScDPLabelData* p = GetLabelData(fData.mnCol);
839 : 0 : OUString aStr = p->maLayoutName;
840 : 0 : sal_uInt16 nMask = fData.mnFuncMask;
841 [ # # ]: 0 : if (aStr.isEmpty())
842 : : {
843 [ # # ]: 0 : aStr = GetFuncString(nMask);
844 : 0 : aStr += p->maName;
845 : : }
846 : :
847 [ # # ][ # # ]: 0 : if ( theWnd->AppendField(aStr, nAddedAt) )
848 : : {
849 : 0 : fData.mnFuncMask = nMask;
850 [ # # ]: 0 : Insert( theArr, fData, nAddedAt );
851 : 0 : }
852 : : }
853 : : }
854 : 0 : }
855 : : }
856 : 0 : }
857 : :
858 : : //----------------------------------------------------------------------------
859 : :
860 : 0 : void ScDPLayoutDlg::RemoveField( ScDPFieldType eFromType, size_t nIndex )
861 : : {
862 : 0 : ScDPFuncDataVec* pArr = GetFieldDataArray(eFromType);
863 : :
864 [ # # ]: 0 : if( pArr )
865 : : {
866 : 0 : ScDPFieldControlBase* pWnd = GetFieldWindow( eFromType );
867 [ # # ]: 0 : if (pWnd)
868 : : {
869 : 0 : pWnd->DelField( nIndex );
870 : 0 : Remove( pArr, nIndex );
871 [ # # ]: 0 : if( pWnd->IsEmpty() ) InitFocus();
872 : : }
873 : : }
874 : 0 : }
875 : :
876 : : //----------------------------------------------------------------------------
877 : :
878 : 0 : void ScDPLayoutDlg::NotifyMouseButtonUp( const Point& rAt )
879 : : {
880 [ # # ]: 0 : if ( bIsDrag )
881 : : {
882 : 0 : bIsDrag = false;
883 : :
884 : 0 : ScDPFieldType eDnDToType = TYPE_SELECT;
885 [ # # ]: 0 : Point aPos = ScreenToOutputPixel( rAt );
886 : 0 : bool bDel = false;
887 : :
888 [ # # ][ # # ]: 0 : if ( aRectPage.IsInside( aPos ) )
889 : : {
890 : 0 : eDnDToType = TYPE_PAGE;
891 : : }
892 [ # # ][ # # ]: 0 : else if ( aRectCol.IsInside( aPos ) )
893 : : {
894 : 0 : eDnDToType = TYPE_COL;
895 : : }
896 [ # # ][ # # ]: 0 : else if ( aRectRow.IsInside( aPos ) )
897 : : {
898 : 0 : eDnDToType = TYPE_ROW;
899 : : }
900 [ # # ][ # # ]: 0 : else if ( aRectData.IsInside( aPos ) )
901 : : {
902 : 0 : eDnDToType = TYPE_DATA;
903 : : }
904 [ # # ][ # # ]: 0 : else if ( aRectSelect.IsInside( aPos ) )
905 : : {
906 : 0 : eDnDToType = TYPE_SELECT;
907 : : }
908 : : else
909 : 0 : bDel = true;
910 : :
911 [ # # ]: 0 : if (bDel)
912 : : {
913 : : // We don't remove any buttons from the select field.
914 [ # # ]: 0 : if (eDnDFromType != TYPE_SELECT)
915 [ # # ]: 0 : RemoveField( eDnDFromType, nDnDFromIndex );
916 : : }
917 : : else
918 [ # # ]: 0 : MoveField( eDnDFromType, nDnDFromIndex, eDnDToType, aPos );
919 : : }
920 : 0 : }
921 : :
922 : : //----------------------------------------------------------------------------
923 : :
924 : 0 : PointerStyle ScDPLayoutDlg::NotifyMouseMove( const Point& rAt )
925 : : {
926 : 0 : PointerStyle ePtr = POINTER_ARROW;
927 : :
928 [ # # ]: 0 : if ( bIsDrag )
929 : : {
930 [ # # ]: 0 : Point aPos = ScreenToOutputPixel( rAt );
931 : 0 : ScDPFieldType eCheckTarget = TYPE_SELECT;
932 : :
933 [ # # ][ # # ]: 0 : if ( aRectPage.IsInside( aPos ) )
934 : 0 : eCheckTarget = TYPE_PAGE;
935 [ # # ][ # # ]: 0 : else if ( aRectCol.IsInside( aPos ) )
936 : 0 : eCheckTarget = TYPE_COL;
937 [ # # ][ # # ]: 0 : else if ( aRectRow.IsInside( aPos ) )
938 : 0 : eCheckTarget = TYPE_ROW;
939 [ # # ][ # # ]: 0 : else if ( aRectData.IsInside( aPos ) )
940 : 0 : eCheckTarget = TYPE_DATA;
941 [ # # ]: 0 : else if ( eDnDFromType != TYPE_SELECT )
942 : 0 : ePtr = POINTER_PIVOT_DELETE;
943 [ # # ][ # # ]: 0 : else if ( aRectSelect.IsInside( aPos ) )
944 : 0 : ePtr = lclGetPointerForField( TYPE_SELECT );
945 : : else
946 : 0 : ePtr = POINTER_NOTALLOWED;
947 : :
948 [ # # ]: 0 : if ( eCheckTarget != TYPE_SELECT )
949 : : {
950 : : // check if the target orientation is allowed for this field
951 : 0 : ScDPFuncDataVec* fromArr = NULL;
952 [ # # # # : 0 : switch ( eDnDFromType )
# # ]
953 : : {
954 : 0 : case TYPE_PAGE: fromArr = &aPageArr; break;
955 : 0 : case TYPE_COL: fromArr = &aColArr; break;
956 : 0 : case TYPE_ROW: fromArr = &aRowArr; break;
957 : 0 : case TYPE_DATA: fromArr = &aDataArr; break;
958 : 0 : case TYPE_SELECT: fromArr = &aSelectArr; break;
959 : : }
960 [ # # ]: 0 : ScDPFuncData fData = (*fromArr)[nDnDFromIndex];
961 [ # # ][ # # ]: 0 : if (IsOrientationAllowed( fData.mnCol, eCheckTarget ))
962 : 0 : ePtr = lclGetPointerForField( eCheckTarget );
963 : : else
964 : 0 : ePtr = POINTER_NOTALLOWED;
965 : : }
966 : : }
967 : :
968 : 0 : return ePtr;
969 : : }
970 : :
971 : : //----------------------------------------------------------------------------
972 : :
973 : 0 : PointerStyle ScDPLayoutDlg::NotifyMouseButtonDown( ScDPFieldType eType, size_t nFieldIndex )
974 : : {
975 : 0 : bIsDrag = true;
976 : 0 : eDnDFromType = eType;
977 : 0 : nDnDFromIndex = nFieldIndex;
978 : 0 : return lclGetPointerForField( eType );
979 : : }
980 : :
981 : : //----------------------------------------------------------------------------
982 : :
983 : 0 : void ScDPLayoutDlg::NotifyDoubleClick( ScDPFieldType eType, size_t nFieldIndex )
984 : : {
985 : 0 : ScDPFuncDataVec* pArr = GetFieldDataArray(eType);
986 : :
987 [ # # ]: 0 : if ( pArr )
988 : : {
989 [ # # ]: 0 : if ( nFieldIndex >= pArr->size() )
990 : : {
991 : : OSL_FAIL("invalid selection");
992 : 0 : return;
993 : : }
994 : :
995 : 0 : size_t nArrPos = 0;
996 [ # # ][ # # ]: 0 : if( ScDPLabelData* pData = GetLabelData( (*pArr)[nFieldIndex].mnCol, &nArrPos ) )
[ # # ]
997 : : {
998 [ # # ]: 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
999 : : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
1000 : :
1001 [ # # # ]: 0 : switch ( eType )
1002 : : {
1003 : : case TYPE_PAGE:
1004 : : case TYPE_COL:
1005 : : case TYPE_ROW:
1006 : : {
1007 : : // list of names of all data fields
1008 [ # # ]: 0 : vector<ScDPName> aDataFieldNames;
1009 [ # # ][ # # ]: 0 : for( ScDPFuncDataVec::const_iterator aIt = aDataArr.begin(), aEnd = aDataArr.end();
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1010 : : (aIt != aEnd); ++aIt)
1011 : : {
1012 [ # # ][ # # ]: 0 : ScDPLabelData* pDFData = GetLabelData(aIt->mnCol);
1013 [ # # ]: 0 : if (!pDFData)
1014 : 0 : continue;
1015 : :
1016 [ # # ]: 0 : if (pDFData->maName.isEmpty())
1017 : 0 : continue;
1018 : :
1019 : 0 : OUString aLayoutName = pDFData->maLayoutName;
1020 [ # # ]: 0 : if (aLayoutName.isEmpty())
1021 : : {
1022 : : // No layout name exists. Use the stock name.
1023 [ # # ]: 0 : sal_uInt16 nMask = aIt->mnFuncMask;
1024 [ # # ]: 0 : OUString aFuncStr = GetFuncString(nMask);
1025 : 0 : aLayoutName = aFuncStr + pDFData->maName;
1026 : : }
1027 [ # # ][ # # ]: 0 : aDataFieldNames.push_back(ScDPName(pDFData->maName, aLayoutName));
1028 : 0 : }
1029 : :
1030 : : bool bLayout = (eType == TYPE_ROW) &&
1031 [ # # ][ # # ]: 0 : ((aDataFieldNames.size() > 1) || (nFieldIndex + 1 < pArr->size()));
[ # # ]
1032 : :
1033 : : AbstractScDPSubtotalDlg* pDlg = pFact->CreateScDPSubtotalDlg(
1034 : : this, RID_SCDLG_PIVOTSUBT,
1035 [ # # ][ # # ]: 0 : *xDlgDPObject, *pData, (*pArr)[nFieldIndex], aDataFieldNames, bLayout );
1036 : :
1037 [ # # ][ # # ]: 0 : if ( pDlg->Execute() == RET_OK )
1038 : : {
1039 [ # # ]: 0 : pDlg->FillLabelData( *pData );
1040 [ # # ]: 0 : (*pArr)[nFieldIndex].mnFuncMask = pData->mnFuncMask;
1041 : : }
1042 [ # # ][ # # ]: 0 : delete pDlg;
1043 : : }
1044 : 0 : break;
1045 : :
1046 : : case TYPE_DATA:
1047 : : {
1048 [ # # ]: 0 : ScDPFuncData& rFuncData = aDataArr[nFieldIndex];
1049 : : AbstractScDPFunctionDlg* pDlg = pFact->CreateScDPFunctionDlg(
1050 : : this, RID_SCDLG_DPDATAFIELD,
1051 [ # # ]: 0 : aLabelDataArr, *pData, rFuncData);
1052 : :
1053 [ # # ][ # # ]: 0 : if ( pDlg->Execute() == RET_OK )
1054 : : {
1055 [ # # ]: 0 : bool bFuncChanged = rFuncData.mnFuncMask != pDlg->GetFuncMask();
1056 [ # # ]: 0 : rFuncData.mnFuncMask = pData->mnFuncMask = pDlg->GetFuncMask();
1057 [ # # ]: 0 : rFuncData.maFieldRef = pDlg->GetFieldRef();
1058 : :
1059 [ # # ]: 0 : if (bFuncChanged)
1060 : : // Get the new duplicate count since the function has changed.
1061 [ # # ]: 0 : rFuncData.mnDupCount = GetNextDupCount(aDataArr, rFuncData, nFieldIndex);
1062 : :
1063 [ # # ]: 0 : ScDPLabelData* p = GetLabelData(rFuncData.mnCol);
1064 : 0 : OUString aStr = p->maLayoutName;
1065 [ # # ]: 0 : if (aStr.isEmpty())
1066 : : {
1067 : : // Layout name is not available. Use default name.
1068 [ # # ]: 0 : aStr = GetFuncString (rFuncData.mnFuncMask);
1069 : 0 : aStr += p->maName;
1070 : : }
1071 [ # # ]: 0 : aWndData.SetFieldText(aStr, nFieldIndex, rFuncData.mnDupCount);
1072 : : }
1073 [ # # ][ # # ]: 0 : delete pDlg;
1074 : : }
1075 : 0 : break;
1076 : :
1077 : : default:
1078 : : {
1079 : : // added to avoid warnings
1080 : : }
1081 : : }
1082 : : }
1083 : : }
1084 : : }
1085 : :
1086 : : //----------------------------------------------------------------------------
1087 : :
1088 : 0 : void ScDPLayoutDlg::NotifyFieldFocus( ScDPFieldType eType, bool bGotFocus )
1089 : : {
1090 : : /* Enable Remove/Options buttons on GetFocus in field window.
1091 : : Enable them also, if dialog is deactivated (click into document).
1092 : : The !IsActive() condition handles the case that a LoseFocus event of a
1093 : : field window would follow the Deactivate event of this dialog. */
1094 [ # # ][ # # ]: 0 : bool bEnable = (bGotFocus || !IsActive()) && (eType != TYPE_SELECT);
[ # # ]
1095 : :
1096 : : // The TestTool may set the focus into an empty field.
1097 : : // Then the Remove/Options buttons must be disabled.
1098 : 0 : ScDPFieldControlBase* pWnd = GetFieldWindow(eType);
1099 [ # # ][ # # ]: 0 : if ( bEnable && bGotFocus && pWnd && pWnd->IsEmpty() )
[ # # ][ # # ]
[ # # ]
1100 : 0 : bEnable = false;
1101 : :
1102 : 0 : aBtnRemove.Enable( bEnable );
1103 : 0 : aBtnOptions.Enable( bEnable );
1104 [ # # ]: 0 : if( bGotFocus )
1105 : 0 : eLastActiveType = eType;
1106 : 0 : }
1107 : :
1108 : : //----------------------------------------------------------------------------
1109 : :
1110 : 0 : void ScDPLayoutDlg::NotifyMoveFieldToEnd( ScDPFieldType eToType )
1111 : : {
1112 : 0 : ScDPFieldControlBase* pWnd = GetFieldWindow(eLastActiveType);
1113 : 0 : ScDPFieldControlBase* pToWnd = GetFieldWindow(eToType);
1114 [ # # ][ # # ]: 0 : if (pWnd && pToWnd && (eToType != TYPE_SELECT) && !pWnd->IsEmpty())
[ # # ][ # # ]
[ # # ]
1115 : : {
1116 : 0 : MoveFieldToEnd(eLastActiveType, pWnd->GetSelectedField(), eToType);
1117 : :
1118 [ # # ]: 0 : if( pWnd->IsEmpty() )
1119 : 0 : NotifyFieldFocus( eToType, true );
1120 : : else
1121 : 0 : pWnd->GrabFocus();
1122 [ # # ]: 0 : if( eLastActiveType == TYPE_SELECT )
1123 : 0 : aWndSelect.SelectNext();
1124 : : }
1125 : : else
1126 : 0 : InitFocus();
1127 : 0 : }
1128 : :
1129 : : //----------------------------------------------------------------------------
1130 : :
1131 : 0 : void ScDPLayoutDlg::NotifyRemoveField( ScDPFieldType eType, size_t nFieldIndex )
1132 : : {
1133 [ # # ]: 0 : if( eType != TYPE_SELECT )
1134 : 0 : RemoveField( eType, nFieldIndex );
1135 : 0 : }
1136 : :
1137 : 0 : Size ScDPLayoutDlg::GetStdFieldBtnSize() const
1138 : : {
1139 : : // This size is static but is platform dependent. The field button size
1140 : : // is calculated relative to the size of the OK button.
1141 : 0 : double w = static_cast<double>(aBtnOk.GetSizePixel().Width()) * 0.70;
1142 : 0 : return Size(static_cast<long>(w), FIELD_BTN_HEIGHT);
1143 : : }
1144 : :
1145 : 0 : void ScDPLayoutDlg::Deactivate()
1146 : : {
1147 : : /* If the dialog has been deactivated (click into document), the LoseFocus
1148 : : event from field window disables Remove/Options buttons. Re-enable them here by
1149 : : simulating a GetFocus event. Event order of LoseFocus and Deactivate is not important.
1150 : : The last event will enable the buttons in both cases (see NotifyFieldFocus). */
1151 : 0 : NotifyFieldFocus( eLastActiveType, true );
1152 : 0 : }
1153 : :
1154 : : //----------------------------------------------------------------------------
1155 : :
1156 : 0 : bool ScDPLayoutDlg::Contains( ScDPFuncDataVec* pArr, const ScDPFuncData& rData, size_t& nAt )
1157 : : {
1158 [ # # ][ # # ]: 0 : if (!pArr || pArr->empty())
[ # # ]
1159 : 0 : return false;
1160 : :
1161 [ # # ][ # # ]: 0 : ScDPFuncDataVec::const_iterator itr, itrBeg = pArr->begin(), itrEnd = pArr->end();
[ # # ][ # # ]
[ # # ]
1162 [ # # ][ # # ]: 0 : for (itr = itrBeg; itr != itrEnd; ++itr)
[ # # ]
1163 : : {
1164 [ # # ][ # # ]: 0 : if (*itr == rData)
[ # # ]
1165 : : {
1166 : : // found!
1167 [ # # ]: 0 : nAt = ::std::distance(itrBeg, itr);
1168 : 0 : return true;
1169 : : }
1170 : : }
1171 : 0 : return false;
1172 : : }
1173 : :
1174 : : //----------------------------------------------------------------------------
1175 : :
1176 : 0 : void ScDPLayoutDlg::Remove( ScDPFuncDataVec* pArr, size_t nAt )
1177 : : {
1178 [ # # ][ # # ]: 0 : if ( !pArr || (nAt>=pArr->size()) )
[ # # ]
1179 : 0 : return;
1180 : :
1181 : 0 : pArr->erase( pArr->begin() + nAt );
1182 : : }
1183 : :
1184 : : //----------------------------------------------------------------------------
1185 : :
1186 : 0 : void ScDPLayoutDlg::Insert( ScDPFuncDataVec* pArr, const ScDPFuncData& rFData, size_t nAt )
1187 : : {
1188 [ # # ]: 0 : if (!pArr)
1189 : 0 : return;
1190 : :
1191 [ # # ]: 0 : std::auto_ptr<ScDPFuncData> p(new ScDPFuncData(rFData));
1192 [ # # ]: 0 : if (nAt >= pArr->size())
1193 [ # # ]: 0 : pArr->push_back(p);
1194 : : else
1195 [ # # ][ # # ]: 0 : pArr->insert(pArr->begin() + nAt, p);
[ # # ]
1196 : : }
1197 : :
1198 : : //----------------------------------------------------------------------------
1199 : :
1200 : 0 : ScDPLabelData* ScDPLayoutDlg::GetLabelData( SCsCOL nCol, size_t* pnPos )
1201 : : {
1202 : 0 : ScDPLabelData* pData = 0;
1203 [ # # ][ # # ]: 0 : for( ScDPLabelDataVec::iterator aIt = aLabelDataArr.begin(), aEnd = aLabelDataArr.end(); !pData && (aIt != aEnd); ++aIt )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1204 : : {
1205 [ # # ][ # # ]: 0 : if( aIt->mnCol == nCol )
1206 : : {
1207 [ # # ]: 0 : pData = &*aIt;
1208 [ # # ][ # # ]: 0 : if( pnPos ) *pnPos = aIt - aLabelDataArr.begin();
[ # # ]
1209 : : }
1210 : : }
1211 : 0 : return pData;
1212 : : }
1213 : :
1214 : : //----------------------------------------------------------------------------
1215 : :
1216 : 0 : rtl::OUString ScDPLayoutDlg::GetLabelString( SCsCOL nCol )
1217 : : {
1218 : 0 : ScDPLabelData* pData = GetLabelData( nCol );
1219 : : OSL_ENSURE( pData, "LabelData not found" );
1220 [ # # ]: 0 : if (pData)
1221 : 0 : return pData->getDisplayName();
1222 : 0 : return rtl::OUString();
1223 : : }
1224 : :
1225 : : //----------------------------------------------------------------------------
1226 : :
1227 : 0 : bool ScDPLayoutDlg::IsOrientationAllowed( SCsCOL nCol, ScDPFieldType eType )
1228 : : {
1229 : 0 : bool bAllowed = true;
1230 : 0 : ScDPLabelData* pData = GetLabelData( nCol );
1231 : : OSL_ENSURE( pData, "LabelData not found" );
1232 [ # # ]: 0 : if (pData)
1233 : : {
1234 : 0 : sheet::DataPilotFieldOrientation eOrient = sheet::DataPilotFieldOrientation_HIDDEN;
1235 [ # # # # : 0 : switch (eType)
# # ]
1236 : : {
1237 : 0 : case TYPE_PAGE: eOrient = sheet::DataPilotFieldOrientation_PAGE; break;
1238 : 0 : case TYPE_COL: eOrient = sheet::DataPilotFieldOrientation_COLUMN; break;
1239 : 0 : case TYPE_ROW: eOrient = sheet::DataPilotFieldOrientation_ROW; break;
1240 : 0 : case TYPE_DATA: eOrient = sheet::DataPilotFieldOrientation_DATA; break;
1241 : 0 : case TYPE_SELECT: eOrient = sheet::DataPilotFieldOrientation_HIDDEN; break;
1242 : : }
1243 : 0 : bAllowed = ScDPObject::IsOrientationAllowed( (sal_uInt16)eOrient, pData->mnFlags );
1244 : : }
1245 : 0 : return bAllowed;
1246 : : }
1247 : :
1248 : : //----------------------------------------------------------------------------
1249 : :
1250 : 0 : rtl::OUString ScDPLayoutDlg::GetFuncString( sal_uInt16& rFuncMask, bool bIsValue )
1251 : : {
1252 : 0 : rtl::OUStringBuffer aBuf;
1253 : :
1254 [ # # ][ # # ]: 0 : if ( rFuncMask == PIVOT_FUNC_NONE
1255 : : || rFuncMask == PIVOT_FUNC_AUTO )
1256 : : {
1257 [ # # ]: 0 : if ( bIsValue )
1258 : : {
1259 [ # # ]: 0 : aBuf.append(FSTR(PIVOTSTR_SUM));
1260 : 0 : rFuncMask = PIVOT_FUNC_SUM;
1261 : : }
1262 : : else
1263 : : {
1264 [ # # ]: 0 : aBuf.append(FSTR(PIVOTSTR_COUNT));
1265 : 0 : rFuncMask = PIVOT_FUNC_COUNT;
1266 : : }
1267 : : }
1268 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_SUM ) aBuf = FSTR(PIVOTSTR_SUM);
[ # # ]
1269 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_COUNT ) aBuf = FSTR(PIVOTSTR_COUNT);
[ # # ]
1270 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_AVERAGE ) aBuf = FSTR(PIVOTSTR_AVG);
[ # # ]
1271 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_MAX ) aBuf = FSTR(PIVOTSTR_MAX);
[ # # ]
1272 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_MIN ) aBuf = FSTR(PIVOTSTR_MIN);
[ # # ]
1273 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_PRODUCT ) aBuf = FSTR(PIVOTSTR_PROD);
[ # # ]
1274 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_COUNT_NUM ) aBuf = FSTR(PIVOTSTR_COUNT2);
[ # # ]
1275 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_STD_DEV ) aBuf = FSTR(PIVOTSTR_DEV);
[ # # ]
1276 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_STD_DEVP ) aBuf = FSTR(PIVOTSTR_DEV2);
[ # # ]
1277 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_STD_VAR ) aBuf = FSTR(PIVOTSTR_VAR);
[ # # ]
1278 [ # # ][ # # ]: 0 : else if ( rFuncMask == PIVOT_FUNC_STD_VARP ) aBuf = FSTR(PIVOTSTR_VAR2);
[ # # ]
1279 : : else
1280 : : {
1281 [ # # ][ # # ]: 0 : aBuf.append(ScGlobal::GetRscString(STR_TABLE_ERGEBNIS));
[ # # ]
1282 [ # # ]: 0 : aBuf.appendAscii(" - ");
1283 : : }
1284 : :
1285 [ # # ]: 0 : return aBuf.makeStringAndClear();
1286 : : }
1287 : :
1288 : : //----------------------------------------------------------------------------
1289 : :
1290 : 0 : Point ScDPLayoutDlg::DlgPos2WndPos( const Point& rPt, Window& rWnd )
1291 : : {
1292 : 0 : Point aWndPt( rPt );
1293 : 0 : aWndPt.X() = rPt.X()-rWnd.GetPosPixel().X();
1294 : 0 : aWndPt.Y() = rPt.Y()-rWnd.GetPosPixel().Y();
1295 : :
1296 : 0 : return aWndPt;
1297 : : }
1298 : :
1299 : : //----------------------------------------------------------------------------
1300 : :
1301 : 0 : void ScDPLayoutDlg::CalcWndSizes()
1302 : : {
1303 : : // The pivot.src file only specifies the positions of the controls. Here,
1304 : : // we calculate appropriate size of each control based on how they are
1305 : : // positioned relative to each other.
1306 : :
1307 : : // row/column/data area sizes
1308 : 0 : long nFldW = GetStdFieldBtnSize().Width();
1309 : 0 : long nFldH = GetStdFieldBtnSize().Height();
1310 : :
1311 : : aWndData.SetSizePixel(
1312 [ # # ]: 0 : Size(aWndSelect.GetPosPixel().X() - aWndData.GetPosPixel().X() - FIELD_AREA_GAP*4,
1313 [ # # ]: 0 : 185));
1314 : :
1315 : : aWndPage.SetSizePixel(
1316 [ # # ]: 0 : Size(aWndData.GetSizePixel().Width() + 85,
1317 [ # # ][ # # ]: 0 : aWndCol.GetPosPixel().Y() - aWndPage.GetPosPixel().Y() - FIELD_AREA_GAP));
1318 : : aWndRow.SetSizePixel(
1319 [ # # ][ # # ]: 0 : Size(aWndData.GetPosPixel().X()-aWndRow.GetPosPixel().X() - FIELD_AREA_GAP,
1320 [ # # ]: 0 : aWndData.GetSizePixel().Height()));
1321 : : aWndCol.SetSizePixel(
1322 [ # # ][ # # ]: 0 : Size(aWndData.GetPosPixel().X() - aWndCol.GetPosPixel().X() + aWndData.GetSizePixel().Width(),
[ # # ]
1323 [ # # ][ # # ]: 0 : aWndData.GetPosPixel().Y() - aWndCol.GetPosPixel().Y() - FIELD_AREA_GAP));
1324 : :
1325 : : // #i29203# align right border of page window with data window
1326 [ # # ]: 0 : long nDataPosX = aWndData.GetPosPixel().X() + aWndData.GetSizePixel().Width();
1327 : : aWndPage.SetPosPixel(
1328 [ # # ]: 0 : Point(nDataPosX - aWndPage.GetSizePixel().Width(),
1329 [ # # ]: 0 : aWndPage.GetPosPixel().Y()));
1330 : :
1331 : : // selection area
1332 : 0 : long nLineSize = 10; // number of fields per column.
1333 : 0 : long nH = OUTER_MARGIN_VER + nLineSize* nFldH + nLineSize * ROW_FIELD_BTN_GAP;
1334 : 0 : nH += ROW_FIELD_BTN_GAP;
1335 : 0 : nH += GetSettings().GetStyleSettings().GetScrollBarSize() + OUTER_MARGIN_VER;
1336 : : aWndSelect.SetSizePixel(
1337 [ # # ]: 0 : Size(2 * nFldW + ROW_FIELD_BTN_GAP + 10, nH));
1338 : :
1339 [ # # ][ # # ]: 0 : aRectPage = Rectangle( aWndPage.GetPosPixel(), aWndPage.GetSizePixel() );
1340 [ # # ][ # # ]: 0 : aRectRow = Rectangle( aWndRow.GetPosPixel(), aWndRow.GetSizePixel() );
1341 [ # # ][ # # ]: 0 : aRectCol = Rectangle( aWndCol.GetPosPixel(), aWndCol.GetSizePixel() );
1342 [ # # ][ # # ]: 0 : aRectData = Rectangle( aWndData.GetPosPixel(), aWndData.GetSizePixel() );
1343 [ # # ][ # # ]: 0 : aRectSelect = Rectangle( aWndSelect.GetPosPixel(), aWndSelect.GetSizePixel() );
1344 : :
1345 : 0 : aWndPage.CalcSize();
1346 : 0 : aWndRow.CalcSize();
1347 : 0 : aWndCol.CalcSize();
1348 : 0 : aWndData.CalcSize();
1349 : 0 : aWndSelect.CalcSize();
1350 : :
1351 : 0 : AdjustDlgSize();
1352 : 0 : }
1353 : :
1354 : : namespace {
1355 : :
1356 : : class MoveWndDown : public std::unary_function<Window*, void>
1357 : : {
1358 : : long mnDelta;
1359 : : public:
1360 : 0 : MoveWndDown(long nDelta) : mnDelta(nDelta) {}
1361 : 0 : void operator() (Window* p) const
1362 : : {
1363 [ # # ]: 0 : Point aPos = p->GetPosPixel();
1364 : 0 : aPos.Y() += mnDelta;
1365 [ # # ]: 0 : p->SetPosPixel(aPos);
1366 : 0 : }
1367 : : };
1368 : :
1369 : : }
1370 : :
1371 : 0 : void ScDPLayoutDlg::AdjustDlgSize()
1372 : : {
1373 : : // On some platforms such as Windows XP, the dialog is not large enough to
1374 : : // show the 'Drag the fields from the right...' text at the bottom. Check
1375 : : // if it overlaps, and if it does, make the dialog size larger.
1376 [ # # ]: 0 : Size aWndSize = GetSizePixel();
1377 : :
1378 [ # # ]: 0 : Point aPosText = aFtInfo.GetPosPixel();
1379 [ # # ]: 0 : Size aSizeText = aFtInfo.GetSizePixel();
1380 [ # # ][ # # ]: 0 : long nYRef = aWndData.GetPosPixel().Y() + aWndData.GetSizePixel().Height();
1381 [ # # ]: 0 : if (aPosText.Y() > nYRef)
1382 : : // This text is visible. No need to adjust.
1383 : : return;
1384 : :
1385 : : // Calculate the extra height necessary.
1386 : 0 : long nBottomMargin = aWndSize.Height() - (aPosText.Y() + aSizeText.Height());
1387 : 0 : long nHeightNeeded = nYRef + TEXT_INFO_GAP + aSizeText.Height() + nBottomMargin;
1388 : 0 : long nDelta = nHeightNeeded - aWndSize.Height();
1389 [ # # ]: 0 : if (nDelta <= 0)
1390 : : // This should never happen but just in case....
1391 : : return;
1392 : :
1393 : : // Make the main dialog taller.
1394 : 0 : aWndSize.Height() += nDelta;
1395 [ # # ]: 0 : SetSizePixel(aWndSize);
1396 : :
1397 : : // Move the relevant controls downward.
1398 [ # # ]: 0 : std::vector<Window*> aWndToMove;
1399 [ # # ]: 0 : aWndToMove.reserve(16);
1400 [ # # ]: 0 : aWndToMove.push_back(&aFtInfo);
1401 [ # # ]: 0 : aWndToMove.push_back(&aBtnMore);
1402 [ # # ]: 0 : aWndToMove.push_back(&aFlAreas);
1403 [ # # ]: 0 : aWndToMove.push_back(&aFtInArea);
1404 [ # # ]: 0 : aWndToMove.push_back(&aEdInPos);
1405 [ # # ]: 0 : aWndToMove.push_back(&aRbInPos);
1406 [ # # ]: 0 : aWndToMove.push_back(&aFtOutArea);
1407 [ # # ]: 0 : aWndToMove.push_back(&aLbOutPos);
1408 [ # # ]: 0 : aWndToMove.push_back(&aEdOutPos);
1409 [ # # ]: 0 : aWndToMove.push_back(&aRbOutPos);
1410 [ # # ]: 0 : aWndToMove.push_back(&aBtnIgnEmptyRows);
1411 [ # # ]: 0 : aWndToMove.push_back(&aBtnDetectCat);
1412 [ # # ]: 0 : aWndToMove.push_back(&aBtnTotalCol);
1413 [ # # ]: 0 : aWndToMove.push_back(&aBtnTotalRow);
1414 [ # # ]: 0 : aWndToMove.push_back(&aBtnFilter);
1415 [ # # ]: 0 : aWndToMove.push_back(&aBtnDrillDown);
1416 [ # # ]: 0 : std::for_each(aWndToMove.begin(), aWndToMove.end(), MoveWndDown(nDelta));
1417 : : }
1418 : :
1419 : : namespace {
1420 : :
1421 : : class PivotFieldInserter : public ::std::unary_function<ScDPFuncData, void>
1422 : : {
1423 : : vector<PivotField>& mrFields;
1424 : : public:
1425 : 0 : explicit PivotFieldInserter(vector<PivotField>& r, size_t nSize) : mrFields(r)
1426 : : {
1427 : 0 : mrFields.reserve(nSize);
1428 : 0 : }
1429 : :
1430 : 0 : PivotFieldInserter(const PivotFieldInserter& r) : mrFields(r.mrFields) {}
1431 : :
1432 : 0 : void operator() (const ScDPFuncData& r)
1433 : : {
1434 [ # # ]: 0 : PivotField aField;
1435 : 0 : aField.nCol = r.mnCol;
1436 : 0 : aField.mnOriginalDim = r.mnOriginalDim;
1437 : 0 : aField.mnDupCount = r.mnDupCount;
1438 : 0 : aField.nFuncMask = r.mnFuncMask;
1439 : 0 : aField.maFieldRef = r.maFieldRef;
1440 [ # # ]: 0 : mrFields.push_back(aField);
1441 : 0 : }
1442 : : };
1443 : :
1444 : : }
1445 : :
1446 : 0 : bool ScDPLayoutDlg::GetPivotArrays(
1447 : : vector<PivotField>& rPageFields, vector<PivotField>& rColFields,
1448 : : vector<PivotField>& rRowFields, vector<PivotField>& rDataFields )
1449 : : {
1450 [ # # ]: 0 : vector<PivotField> aPageFields;
1451 [ # # ][ # # ]: 0 : for_each(aPageArr.begin(), aPageArr.end(), PivotFieldInserter(aPageFields, aPageArr.size()));
[ # # ][ # # ]
1452 : :
1453 [ # # ]: 0 : vector<PivotField> aColFields;
1454 [ # # ][ # # ]: 0 : for_each(aColArr.begin(), aColArr.end(), PivotFieldInserter(aColFields, aColArr.size()+1));
[ # # ][ # # ]
1455 : :
1456 [ # # ]: 0 : vector<PivotField> aRowFields;
1457 [ # # ][ # # ]: 0 : for_each(aRowArr.begin(), aRowArr.end(), PivotFieldInserter(aRowFields, aRowArr.size()+1));
[ # # ][ # # ]
1458 : :
1459 [ # # ]: 0 : vector<PivotField> aDataFields;
1460 [ # # ][ # # ]: 0 : for_each(aDataArr.begin(), aDataArr.end(), PivotFieldInserter(aDataFields, aDataArr.size()));
[ # # ][ # # ]
1461 : :
1462 : 0 : sheet::DataPilotFieldOrientation eOrientDataLayout = sheet::DataPilotFieldOrientation_ROW;
1463 : 0 : ScDPSaveData* pSaveData = xDlgDPObject->GetSaveData();
1464 [ # # ]: 0 : if (pSaveData)
1465 : : {
1466 [ # # ]: 0 : const ScDPSaveDimension* p = pSaveData->GetExistingDataLayoutDimension();
1467 [ # # ]: 0 : if (p)
1468 : : // Try to preserve the orientation of existing data layout dimension.
1469 : 0 : eOrientDataLayout = static_cast<sheet::DataPilotFieldOrientation>(p->GetOrientation());
1470 : : }
1471 [ # # ]: 0 : switch (eOrientDataLayout)
1472 : : {
1473 : : case sheet::DataPilotFieldOrientation_COLUMN:
1474 [ # # ][ # # ]: 0 : aColFields.push_back(PivotField(PIVOT_DATA_FIELD, 0));
1475 : 0 : break;
1476 : : default:
1477 : : // data layout dimension can only be row or column.
1478 [ # # ][ # # ]: 0 : aRowFields.push_back(PivotField(PIVOT_DATA_FIELD, 0));
1479 : : }
1480 : :
1481 : 0 : rPageFields.swap(aPageFields);
1482 : 0 : rColFields.swap(aColFields);
1483 : 0 : rRowFields.swap(aRowFields);
1484 : 0 : rDataFields.swap(aDataFields);
1485 : :
1486 : 0 : return true;
1487 : : }
1488 : :
1489 : 0 : void ScDPLayoutDlg::UpdateSrcRange()
1490 : : {
1491 [ # # ][ # # ]: 0 : rtl::OUString aSrcStr = aEdInPos.GetText();
[ # # ]
1492 [ # # ][ # # ]: 0 : sal_uInt16 nResult = ScRange().Parse(aSrcStr, pDoc, pDoc->GetAddressConvention());
[ # # ][ # # ]
1493 : 0 : DataSrcType eSrcType = SRC_INVALID;
1494 : 0 : ScRange aNewRange;
1495 : :
1496 [ # # ]: 0 : if (SCA_VALID == (nResult & SCA_VALID))
1497 : : {
1498 : : // Valid source range. Take it.
1499 : 0 : ScRefAddress start, end;
1500 [ # # ][ # # ]: 0 : ConvertDoubleRef(pDoc, aSrcStr, 1, start, end, pDoc->GetAddressConvention());
[ # # ][ # # ]
1501 : 0 : aNewRange.aStart = start.GetAddress();
1502 : 0 : aNewRange.aEnd = end.GetAddress();
1503 [ # # ]: 0 : aEdInPos.SetRefValid(true);
1504 : 0 : eSrcType = SRC_REF;
1505 : : }
1506 : : else
1507 : : {
1508 : : // invalid source range. Check if this is a valid range name.
1509 : 0 : bool bValid = false;
1510 [ # # ]: 0 : ScRangeName* pRangeName = pDoc->GetRangeName();
1511 [ # # ]: 0 : if (pRangeName)
1512 : : {
1513 [ # # ]: 0 : OUString aUpper = ScGlobal::pCharClass->uppercase(aSrcStr);
1514 [ # # ]: 0 : const ScRangeData* pData = pRangeName->findByUpperName(aUpper);
1515 [ # # ]: 0 : if (pData)
1516 : : {
1517 : : // range name found. Check if this is a valid reference.
1518 [ # # ]: 0 : bValid = pData->IsReference(aNewRange);
1519 : 0 : }
1520 : : }
1521 : :
1522 [ # # ]: 0 : aEdInPos.SetRefValid(bValid);
1523 [ # # ]: 0 : if (!bValid)
1524 : : {
1525 : : // All attempts have failed. Give up.
1526 [ # # ]: 0 : aBtnOk.Disable();
1527 : : return;
1528 : : }
1529 : :
1530 : 0 : eSrcType = SRC_NAME;
1531 : : }
1532 : :
1533 [ # # ]: 0 : aBtnOk.Enable();
1534 : :
1535 : : // Now update the data src range or range name with the dp object.
1536 [ # # ]: 0 : ScSheetSourceDesc inSheet = *xDlgDPObject->GetSheetDesc();
1537 : :
1538 [ # # # ]: 0 : switch (eSrcType)
1539 : : {
1540 : : case SRC_REF:
1541 : : {
1542 : : // data source is a range reference.
1543 [ # # ][ # # ]: 0 : if (inSheet.GetSourceRange() == aNewRange)
1544 : : // new range is identical to the current range. Nothing to do.
1545 : : return;
1546 [ # # ]: 0 : inSheet.SetSourceRange(aNewRange);
1547 [ # # ]: 0 : sal_uLong nError = inSheet.CheckSourceRange();
1548 [ # # ]: 0 : if (nError)
1549 : : {
1550 : : // The error number corresponds with string ID for the error
1551 : : // message. In the future we should display the error message
1552 : : // somewhere in the dialog to let the user know of the reason
1553 : : // for error.
1554 [ # # ]: 0 : aEdInPos.SetRefValid(false);
1555 [ # # ]: 0 : aBtnOk.Disable();
1556 : : return;
1557 : : }
1558 : : }
1559 : 0 : break;
1560 : : case SRC_NAME:
1561 : : // data source is a range name.
1562 [ # # ]: 0 : inSheet.SetRangeName(aSrcStr);
1563 : 0 : break;
1564 : : default:
1565 : : OSL_FAIL( "Unknown source type.");
1566 : : return;
1567 : : }
1568 : :
1569 [ # # ]: 0 : xDlgDPObject->SetSheetDesc(inSheet);
1570 [ # # ]: 0 : xDlgDPObject->FillOldParam( thePivotData );
1571 [ # # ]: 0 : xDlgDPObject->FillLabelData(thePivotData);
1572 : :
1573 [ # # ]: 0 : aLabelDataArr.clear();
1574 [ # # ]: 0 : aWndSelect.ClearFields();
1575 [ # # ]: 0 : aWndData.ClearFields();
1576 [ # # ]: 0 : aWndRow.ClearFields();
1577 [ # # ]: 0 : aWndCol.ClearFields();
1578 [ # # ]: 0 : aWndPage.ClearFields();
1579 : :
1580 [ # # ]: 0 : aSelectArr.clear();
1581 [ # # ]: 0 : aRowArr.clear();
1582 [ # # ]: 0 : aColArr.clear();
1583 [ # # ]: 0 : aDataArr.clear();
1584 [ # # ]: 0 : aPageArr.clear();
1585 : :
1586 [ # # ]: 0 : InitFields();
1587 [ # # ][ # # ]: 0 : RepaintFieldWindows();
[ # # ][ # # ]
1588 : : }
1589 : :
1590 : 0 : void ScDPLayoutDlg::RepaintFieldWindows()
1591 : : {
1592 [ # # ]: 0 : Rectangle aRect; // currently has no effect whatsoever.
1593 [ # # ]: 0 : aWndPage.Paint(aRect);
1594 [ # # ]: 0 : aWndCol.Paint(aRect);
1595 [ # # ]: 0 : aWndRow.Paint(aRect);
1596 [ # # ]: 0 : aWndData.Paint(aRect);
1597 : 0 : }
1598 : :
1599 : 0 : ScDPFieldControlBase* ScDPLayoutDlg::GetFieldWindow(ScDPFieldType eType)
1600 : : {
1601 [ # # # # : 0 : switch (eType)
# # ]
1602 : : {
1603 : : case TYPE_PAGE:
1604 : 0 : return &aWndPage;
1605 : : case TYPE_COL:
1606 : 0 : return &aWndCol;
1607 : : case TYPE_ROW:
1608 : 0 : return &aWndRow;
1609 : : case TYPE_DATA:
1610 : 0 : return &aWndData;
1611 : : case TYPE_SELECT:
1612 : 0 : return &aWndSelect;
1613 : : default:
1614 : : ;
1615 : : }
1616 : 0 : return NULL;
1617 : : }
1618 : :
1619 : 0 : void ScDPLayoutDlg::GetOtherFieldWindows(ScDPFieldType eType, ScDPFieldControlBase*& rpWnd1, ScDPFieldControlBase*& rpWnd2)
1620 : : {
1621 : 0 : rpWnd1 = NULL;
1622 : 0 : rpWnd2 = NULL;
1623 [ # # # # ]: 0 : switch (eType)
1624 : : {
1625 : : case TYPE_PAGE:
1626 : 0 : rpWnd1 = &aWndRow;
1627 : 0 : rpWnd2 = &aWndCol;
1628 : 0 : break;
1629 : : case TYPE_COL:
1630 : 0 : rpWnd1 = &aWndPage;
1631 : 0 : rpWnd2 = &aWndRow;
1632 : 0 : break;
1633 : : case TYPE_ROW:
1634 : 0 : rpWnd1 = &aWndPage;
1635 : 0 : rpWnd2 = &aWndCol;
1636 : 0 : break;
1637 : : default:
1638 : : ;
1639 : : }
1640 : 0 : }
1641 : :
1642 : 0 : ScDPLayoutDlg::ScDPFuncDataVec* ScDPLayoutDlg::GetFieldDataArray(ScDPFieldType eType)
1643 : : {
1644 [ # # # # : 0 : switch (eType)
# # ]
1645 : : {
1646 : : case TYPE_PAGE:
1647 : 0 : return &aPageArr;
1648 : : case TYPE_COL:
1649 : 0 : return &aColArr;
1650 : : case TYPE_ROW:
1651 : 0 : return &aRowArr;
1652 : : case TYPE_DATA:
1653 : 0 : return &aDataArr;
1654 : : case TYPE_SELECT:
1655 : 0 : return &aSelectArr;
1656 : : default:
1657 : : ;
1658 : : }
1659 : 0 : return NULL;
1660 : : }
1661 : :
1662 : 0 : void ScDPLayoutDlg::GetOtherDataArrays(
1663 : : ScDPFieldType eType, ScDPFuncDataVec*& rpArr1, ScDPFuncDataVec*& rpArr2)
1664 : : {
1665 : 0 : rpArr1 = NULL;
1666 : 0 : rpArr2 = NULL;
1667 [ # # # # ]: 0 : switch (eType)
1668 : : {
1669 : : case TYPE_PAGE:
1670 : 0 : rpArr1 = &aRowArr;
1671 : 0 : rpArr2 = &aColArr;
1672 : 0 : break;
1673 : : case TYPE_COL:
1674 : 0 : rpArr1 = &aPageArr;
1675 : 0 : rpArr2 = &aRowArr;
1676 : 0 : break;
1677 : : case TYPE_ROW:
1678 : 0 : rpArr1 = &aPageArr;
1679 : 0 : rpArr2 = &aColArr;
1680 : 0 : break;
1681 : : default:
1682 : : ;
1683 : : }
1684 : 0 : }
1685 : :
1686 : 0 : sal_uInt8 ScDPLayoutDlg::GetNextDupCount(
1687 : : const ScDPFuncDataVec& rArr, const ScDPFuncData& rData, size_t nDataIndex) const
1688 : : {
1689 : 0 : sal_uInt8 nDupCount = 0;
1690 : 0 : bool bFound = false;
1691 [ # # ]: 0 : for (size_t i = 0, n = rArr.size(); i < n; ++i)
1692 : : {
1693 : 0 : const ScDPFuncData& r = rArr[i];
1694 [ # # ]: 0 : if (i == nDataIndex)
1695 : : // Skip itself.
1696 : 0 : continue;
1697 : :
1698 [ # # ][ # # ]: 0 : if (r.mnCol != rData.mnCol || r.mnFuncMask != rData.mnFuncMask)
1699 : 0 : continue;
1700 : :
1701 : 0 : bFound = true;
1702 [ # # ]: 0 : if (r.mnDupCount > nDupCount)
1703 : 0 : nDupCount = r.mnDupCount;
1704 : : }
1705 : :
1706 [ # # ]: 0 : return bFound ? nDupCount + 1 : 0;
1707 : : }
1708 : :
1709 : : //----------------------------------------------------------------------------
1710 : :
1711 : 0 : void ScDPLayoutDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
1712 : : {
1713 [ # # ][ # # ]: 0 : if ( !bRefInputMode || !pEditActive )
1714 : 0 : return;
1715 : :
1716 [ # # ]: 0 : if ( rRef.aStart != rRef.aEnd )
1717 : 0 : RefInputStart( pEditActive );
1718 : :
1719 [ # # ]: 0 : if ( pEditActive == &aEdInPos )
1720 : : {
1721 : 0 : rtl::OUString aRefStr;
1722 [ # # ][ # # ]: 0 : rRef.Format( aRefStr, SCR_ABS_3D, pDocP, pDocP->GetAddressConvention() );
1723 [ # # ][ # # ]: 0 : pEditActive->SetRefString( aRefStr );
[ # # ]
1724 : : }
1725 [ # # ]: 0 : else if ( pEditActive == &aEdOutPos )
1726 : : {
1727 : 0 : rtl::OUString aRefStr;
1728 [ # # ][ # # ]: 0 : rRef.aStart.Format( aRefStr, STD_FORMAT, pDocP, pDocP->GetAddressConvention() );
1729 [ # # ][ # # ]: 0 : pEditActive->SetRefString( aRefStr );
[ # # ]
1730 : : }
1731 : : }
1732 : :
1733 : : //----------------------------------------------------------------------------
1734 : :
1735 : 0 : void ScDPLayoutDlg::SetActive()
1736 : : {
1737 [ # # ]: 0 : if ( bRefInputMode )
1738 : : {
1739 [ # # ]: 0 : if ( pEditActive )
1740 : 0 : pEditActive->GrabFocus();
1741 : :
1742 [ # # ]: 0 : if ( pEditActive == &aEdInPos )
1743 : 0 : EdInModifyHdl( NULL );
1744 [ # # ]: 0 : else if ( pEditActive == &aEdOutPos )
1745 : 0 : EdModifyHdl( NULL );
1746 : : }
1747 : : else
1748 : : {
1749 : 0 : GrabFocus();
1750 : : }
1751 : :
1752 : 0 : RefInputDone();
1753 : 0 : }
1754 : :
1755 : : //----------------------------------------------------------------------------
1756 : : // Handler:
1757 : : //----------------------------------------------------------------------------
1758 : :
1759 : 0 : IMPL_LINK( ScDPLayoutDlg, ClickHdl, PushButton *, pBtn )
1760 : : {
1761 : 0 : ScDPFieldControlBase* pWnd = GetFieldWindow( eLastActiveType );
1762 [ # # ]: 0 : if (!pWnd)
1763 : 0 : return 0;
1764 : :
1765 [ # # ]: 0 : if( pBtn == &aBtnRemove )
1766 : : {
1767 : 0 : RemoveField( eLastActiveType, pWnd->GetSelectedField() );
1768 [ # # ]: 0 : if( !pWnd->IsEmpty() ) pWnd->GrabFocus();
1769 : : }
1770 [ # # ]: 0 : else if( pBtn == &aBtnOptions )
1771 : : {
1772 : 0 : NotifyDoubleClick( eLastActiveType, pWnd->GetSelectedField() );
1773 : 0 : pWnd->GrabFocus();
1774 : : }
1775 : 0 : return 0;
1776 : : }
1777 : :
1778 : : //----------------------------------------------------------------------------
1779 : :
1780 : 0 : IMPL_LINK_NOARG(ScDPLayoutDlg, OkHdl)
1781 : : {
1782 [ # # ][ # # ]: 0 : rtl::OUString aOutPosStr = aEdOutPos.GetText();
[ # # ]
1783 : 0 : ScAddress aAdrDest;
1784 [ # # ]: 0 : bool bToNewTable = (aLbOutPos.GetSelectEntryPos() == 1);
1785 [ # # ][ # # ]: 0 : sal_uInt16 nResult = !bToNewTable ? aAdrDest.Parse( aOutPosStr, pDoc, pDoc->GetAddressConvention() ) : 0;
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
[ # # # # ]
1786 : :
1787 [ # # ][ # # ]: 0 : if (!bToNewTable && (aOutPosStr.isEmpty() || (nResult & SCA_VALID) != SCA_VALID))
[ # # ][ # # ]
1788 : : {
1789 : : // Invalid reference. Bail out.
1790 [ # # ]: 0 : if ( !aBtnMore.GetState() )
1791 [ # # ]: 0 : aBtnMore.SetState(true);
1792 : :
1793 [ # # ][ # # ]: 0 : ErrorBox(this, WinBits(WB_OK | WB_DEF_OK), ScGlobal::GetRscString(STR_INVALID_TABREF)).Execute();
[ # # ][ # # ]
1794 [ # # ]: 0 : aEdOutPos.GrabFocus();
1795 : 0 : return 0;
1796 : : }
1797 : :
1798 [ # # ]: 0 : ScPivotParam theOutParam;
1799 [ # # ]: 0 : vector<PivotField> aPageFields;
1800 [ # # ]: 0 : vector<PivotField> aColFields;
1801 [ # # ]: 0 : vector<PivotField> aRowFields;
1802 [ # # ]: 0 : vector<PivotField> aDataFields;
1803 : :
1804 : : // Convert an array of function data into an array of pivot field data.
1805 [ # # ]: 0 : bool bFit = GetPivotArrays(aPageFields, aColFields, aRowFields, aDataFields);
1806 : :
1807 [ # # ]: 0 : if (!bFit)
1808 : : {
1809 : : // General data pilot table error. Bail out.
1810 [ # # ][ # # ]: 0 : ErrorBox(this, WinBits(WB_OK | WB_DEF_OK), ScGlobal::GetRscString(STR_PIVOT_ERROR)).Execute();
[ # # ][ # # ]
1811 : 0 : return 0;
1812 : : }
1813 : :
1814 : 0 : ScDPSaveData* pOldSaveData = xDlgDPObject->GetSaveData();
1815 : :
1816 : 0 : ScRange aOutRange( aAdrDest ); // bToNewTable is passed separately
1817 : :
1818 [ # # ]: 0 : ScDPSaveData aSaveData;
1819 [ # # ][ # # ]: 0 : aSaveData.SetIgnoreEmptyRows( aBtnIgnEmptyRows.IsChecked() );
1820 [ # # ][ # # ]: 0 : aSaveData.SetRepeatIfEmpty( aBtnDetectCat.IsChecked() );
1821 [ # # ][ # # ]: 0 : aSaveData.SetColumnGrand( aBtnTotalCol.IsChecked() );
1822 [ # # ][ # # ]: 0 : aSaveData.SetRowGrand( aBtnTotalRow.IsChecked() );
1823 [ # # ][ # # ]: 0 : aSaveData.SetFilterButton( aBtnFilter.IsChecked() );
1824 [ # # ][ # # ]: 0 : aSaveData.SetDrillDown( aBtnDrillDown.IsChecked() );
1825 : :
1826 [ # # ]: 0 : uno::Reference<sheet::XDimensionsSupplier> xSource = xDlgDPObject->GetSource();
1827 : :
1828 : : ScDPObject::ConvertOrientation(
1829 [ # # ]: 0 : aSaveData, aPageFields, sheet::DataPilotFieldOrientation_PAGE, xSource, aLabelDataArr);
1830 : : ScDPObject::ConvertOrientation(
1831 [ # # ]: 0 : aSaveData, aColFields, sheet::DataPilotFieldOrientation_COLUMN, xSource, aLabelDataArr);
1832 : : ScDPObject::ConvertOrientation(
1833 [ # # ]: 0 : aSaveData, aRowFields, sheet::DataPilotFieldOrientation_ROW, xSource, aLabelDataArr);
1834 : : ScDPObject::ConvertOrientation(
1835 : : aSaveData, aDataFields, sheet::DataPilotFieldOrientation_DATA, xSource, aLabelDataArr,
1836 [ # # ]: 0 : &aColFields, &aRowFields, &aPageFields );
1837 : :
1838 [ # # ][ # # ]: 0 : for( ScDPLabelDataVec::const_iterator aIt = aLabelDataArr.begin(), aEnd = aLabelDataArr.end(); aIt != aEnd; ++aIt )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1839 : : {
1840 [ # # ][ # # ]: 0 : ScDPSaveDimension* pDim = aSaveData.GetExistingDimensionByName(aIt->maName);
1841 : :
1842 [ # # ]: 0 : if (!pDim)
1843 : 0 : continue;
1844 : :
1845 [ # # ][ # # ]: 0 : pDim->SetUsedHierarchy( aIt->mnUsedHier );
1846 [ # # ][ # # ]: 0 : pDim->SetShowEmpty( aIt->mbShowAll );
1847 [ # # ][ # # ]: 0 : pDim->SetSortInfo( &aIt->maSortInfo );
1848 [ # # ][ # # ]: 0 : pDim->SetLayoutInfo( &aIt->maLayoutInfo );
1849 [ # # ][ # # ]: 0 : pDim->SetAutoShowInfo( &aIt->maShowInfo );
1850 : 0 : ScDPSaveDimension* pOldDim = NULL;
1851 : :
1852 [ # # ]: 0 : bool bManualSort = ( aIt->maSortInfo.Mode == sheet::DataPilotFieldSortMode::MANUAL );
1853 : :
1854 : : // visibility of members
1855 [ # # ][ # # ]: 0 : for (vector<ScDPLabelData::Member>::const_iterator itr = aIt->maMembers.begin(), itrEnd = aIt->maMembers.end();
[ # # ][ # # ]
1856 : : itr != itrEnd; ++itr)
1857 : : {
1858 [ # # ]: 0 : ScDPSaveMember* pMember = pDim->GetMemberByName(itr->maName);
1859 : :
1860 : : // #i40054# create/access members only if flags are not default
1861 : : // (or in manual sorting mode - to keep the order)
1862 [ # # ][ # # ]: 0 : if (bManualSort || !itr->mbVisible || !itr->mbShowDetails)
[ # # ][ # # ]
1863 : : {
1864 [ # # ]: 0 : pMember->SetIsVisible(itr->mbVisible);
1865 [ # # ]: 0 : pMember->SetShowDetails(itr->mbShowDetails);
1866 : : }
1867 : :
1868 [ # # ]: 0 : if (!pOldDim)
1869 : 0 : continue;
1870 : :
1871 : : // Transfer the existing layout name.
1872 [ # # ]: 0 : ScDPSaveMember* pOldMember = pOldDim->GetMemberByName(itr->maName);
1873 [ # # ]: 0 : if (pOldMember)
1874 : : {
1875 [ # # ]: 0 : const OUString* pLayoutName = pOldMember->GetLayoutName();
1876 [ # # ]: 0 : if (pLayoutName)
1877 [ # # ]: 0 : pMember->SetLayoutName(*pLayoutName);
1878 : : }
1879 : : }
1880 : : }
1881 [ # # ]: 0 : ScDPSaveDimension* pDim = aSaveData.GetDataLayoutDimension();
1882 [ # # ][ # # ]: 0 : if (pDim && pOldSaveData)
1883 : : {
1884 [ # # ]: 0 : ScDPSaveDimension* pOldDim = pOldSaveData->GetDataLayoutDimension();
1885 [ # # ]: 0 : if (pOldDim)
1886 : : {
1887 [ # # ]: 0 : const OUString* pLayoutName = pOldDim->GetLayoutName();
1888 [ # # ]: 0 : if (pLayoutName)
1889 [ # # ]: 0 : pDim->SetLayoutName(*pLayoutName);
1890 : : }
1891 : : }
1892 : :
1893 : : // also transfer grand total name
1894 [ # # ]: 0 : if (pOldSaveData)
1895 : : {
1896 [ # # ]: 0 : const OUString* pGrandTotalName = pOldSaveData->GetGrandTotalName();
1897 [ # # ]: 0 : if (pGrandTotalName)
1898 [ # # ]: 0 : aSaveData.SetGrandTotalName(*pGrandTotalName);
1899 : : }
1900 : :
1901 [ # # ][ # # ]: 0 : sal_uInt16 nWhichPivot = SC_MOD()->GetPool().GetWhich( SID_PIVOT_TABLE );
1902 [ # # ]: 0 : ScPivotItem aOutItem( nWhichPivot, &aSaveData, &aOutRange, bToNewTable );
1903 : :
1904 : 0 : bRefInputMode = false; // to allow deselecting when switching sheets
1905 : :
1906 [ # # ]: 0 : SetDispatcherLock( false );
1907 [ # # ]: 0 : SwitchToDocument();
1908 : :
1909 : 0 : ScTabViewShell* pTabViewShell = pViewData->GetViewShell();
1910 [ # # ]: 0 : pTabViewShell->SetDialogDPObject(xDlgDPObject.get());
1911 : :
1912 : : // don't hide the dialog before executing the slot, instead it is used as
1913 : : // parent for message boxes in ScTabViewShell::GetDialogParent
1914 : :
1915 : 0 : const SfxPoolItem* pRet = GetBindings().GetDispatcher()->Execute(
1916 [ # # ]: 0 : SID_PIVOT_TABLE, SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD, &aOutItem, 0L, 0L );
1917 : :
1918 : 0 : bool bSuccess = true;
1919 [ # # ]: 0 : if (pRet)
1920 : : {
1921 [ # # ]: 0 : const SfxBoolItem* pItem = dynamic_cast<const SfxBoolItem*>(pRet);
1922 [ # # ]: 0 : if (pItem)
1923 : 0 : bSuccess = pItem->GetValue();
1924 : : }
1925 [ # # ]: 0 : if (bSuccess)
1926 : : // Table successfully inserted.
1927 [ # # ]: 0 : Close();
1928 : : else
1929 : : {
1930 : : // Table insertion failed. Keep the dialog open.
1931 : 0 : bRefInputMode = true;
1932 [ # # ]: 0 : SetDispatcherLock(true);
1933 : : }
1934 : :
1935 [ # # ][ # # ]: 0 : return 0;
[ # # ]
1936 : : }
1937 : :
1938 : : //----------------------------------------------------------------------------
1939 : :
1940 : 0 : IMPL_LINK_NOARG(ScDPLayoutDlg, CancelHdl)
1941 : : {
1942 : 0 : Close();
1943 : 0 : return 0;
1944 : : }
1945 : :
1946 : : //----------------------------------------------------------------------------
1947 : :
1948 : 0 : IMPL_LINK_NOARG(ScDPLayoutDlg, MoreClickHdl)
1949 : : {
1950 [ # # ]: 0 : if ( aBtnMore.GetState() )
1951 : : {
1952 : 0 : bRefInputMode = true;
1953 : : //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
1954 : : //SFX_APPWINDOW->Enable();
1955 [ # # ]: 0 : if ( aEdInPos.IsEnabled() )
1956 : : {
1957 : 0 : aEdInPos.Enable();
1958 : 0 : aEdInPos.GrabFocus();
1959 : 0 : aEdInPos.Enable();
1960 : : }
1961 : : else
1962 : : {
1963 : 0 : aEdOutPos.Enable();
1964 : 0 : aEdOutPos.GrabFocus();
1965 : 0 : aEdOutPos.Enable();
1966 : : }
1967 : : }
1968 : : else
1969 : : {
1970 : 0 : bRefInputMode = false;
1971 : : //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
1972 : : //SFX_APPWINDOW->Disable(false); //! allgemeine Methode im ScAnyRefDlg
1973 : : }
1974 : 0 : return 0;
1975 : : }
1976 : :
1977 : : //----------------------------------------------------------------------------
1978 : :
1979 : 0 : IMPL_LINK_NOARG(ScDPLayoutDlg, EdModifyHdl)
1980 : : {
1981 [ # # ][ # # ]: 0 : rtl::OUString theCurPosStr = aEdOutPos.GetText();
[ # # ]
1982 [ # # ][ # # ]: 0 : sal_uInt16 nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
[ # # ][ # # ]
1983 : :
1984 [ # # ]: 0 : if ( SCA_VALID == (nResult & SCA_VALID) )
1985 : : {
1986 : 0 : rtl::OUString* pStr = NULL;
1987 : 0 : bool bFound = false;
1988 : 0 : sal_uInt16 i = 0;
1989 [ # # ]: 0 : sal_uInt16 nCount = aLbOutPos.GetEntryCount();
1990 : :
1991 [ # # ][ # # ]: 0 : for ( i=2; i<nCount && !bFound; i++ )
[ # # ]
1992 : : {
1993 [ # # ]: 0 : pStr = static_cast<rtl::OUString*>(aLbOutPos.GetEntryData(i));
1994 : 0 : bFound = (theCurPosStr == *pStr);
1995 : : }
1996 : :
1997 [ # # ]: 0 : if ( bFound )
1998 [ # # ]: 0 : aLbOutPos.SelectEntryPos( --i );
1999 : : else
2000 [ # # ]: 0 : aLbOutPos.SelectEntryPos( 0 );
2001 : : }
2002 : 0 : return 0;
2003 : : }
2004 : :
2005 : 0 : IMPL_LINK_NOARG(ScDPLayoutDlg, EdInModifyHdl)
2006 : : {
2007 : 0 : UpdateSrcRange();
2008 : 0 : return 0;
2009 : : }
2010 : :
2011 : : //----------------------------------------------------------------------------
2012 : :
2013 : 0 : IMPL_LINK_NOARG(ScDPLayoutDlg, SelAreaHdl)
2014 : : {
2015 : 0 : rtl::OUString aString;
2016 [ # # ]: 0 : sal_uInt16 nSelPos = aLbOutPos.GetSelectEntryPos();
2017 : :
2018 [ # # ]: 0 : if ( nSelPos > 1 )
2019 : : {
2020 [ # # ]: 0 : aString = *(rtl::OUString*)aLbOutPos.GetEntryData(nSelPos);
2021 : : }
2022 [ # # ][ # # ]: 0 : else if ( nSelPos == aLbOutPos.GetEntryCount()-1 ) // auf neue Tabelle?
2023 : : {
2024 [ # # ]: 0 : aEdOutPos.Disable();
2025 [ # # ]: 0 : aRbOutPos.Disable();
2026 : : }
2027 : : else
2028 : : {
2029 [ # # ]: 0 : aEdOutPos.Enable();
2030 [ # # ]: 0 : aRbOutPos.Enable();
2031 : : }
2032 : :
2033 [ # # ][ # # ]: 0 : aEdOutPos.SetText( aString );
[ # # ]
2034 : 0 : return 0;
2035 : : }
2036 : :
2037 : 0 : IMPL_LINK( ScDPLayoutDlg, GetFocusHdl, Control*, pCtrl )
2038 : : {
2039 : 0 : pEditActive = NULL;
2040 [ # # ]: 0 : if ( pCtrl == &aEdInPos )
2041 : 0 : pEditActive = &aEdInPos;
2042 [ # # ]: 0 : else if ( pCtrl == &aEdOutPos )
2043 : 0 : pEditActive = &aEdOutPos;
2044 : :
2045 : 0 : return 0;
2046 [ + - ][ + - ]: 153 : }
2047 : :
2048 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|