Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #undef SC_DLLIMPLEMENTATION
21 :
22 : #include "pvfundlg.hxx"
23 :
24 : #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
25 : #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
26 : #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
27 : #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
28 : #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
29 :
30 : #include <tools/resary.hxx>
31 : #include <vcl/msgbox.hxx>
32 :
33 : #include "scresid.hxx"
34 : #include "dpobject.hxx"
35 : #include "dpsave.hxx"
36 : #include "pvfundlg.hrc"
37 : #include "globstr.hrc"
38 :
39 : #include <vector>
40 :
41 : // ============================================================================
42 :
43 : using namespace ::com::sun::star::sheet;
44 :
45 : using ::rtl::OUString;
46 : using ::com::sun::star::uno::Sequence;
47 : using ::std::vector;
48 :
49 : // ============================================================================
50 :
51 : namespace {
52 :
53 : /** Appends all strings from the Sequence to the list box.
54 :
55 : Empty strings are replaced by a localized "(empty)" entry and inserted at
56 : the specified position.
57 :
58 : @return true = The passed string list contains an empty string entry.
59 : */
60 : template< typename ListBoxType >
61 0 : bool lclFillListBox( ListBoxType& rLBox, const Sequence< OUString >& rStrings, sal_uInt16 nEmptyPos = LISTBOX_APPEND )
62 : {
63 0 : bool bEmpty = false;
64 0 : const OUString* pStr = rStrings.getConstArray();
65 0 : if( pStr )
66 : {
67 0 : for( const OUString* pEnd = pStr + rStrings.getLength(); pStr != pEnd; ++pStr )
68 : {
69 0 : if( !pStr->isEmpty() )
70 0 : rLBox.InsertEntry( *pStr );
71 : else
72 : {
73 0 : rLBox.InsertEntry( ScGlobal::GetRscString( STR_EMPTYDATA ), nEmptyPos );
74 0 : bEmpty = true;
75 : }
76 : }
77 : }
78 0 : return bEmpty;
79 : }
80 :
81 : template< typename ListBoxType >
82 0 : bool lclFillListBox( ListBoxType& rLBox, const vector<ScDPLabelData::Member>& rMembers, sal_uInt16 nEmptyPos = LISTBOX_APPEND )
83 : {
84 0 : bool bEmpty = false;
85 0 : vector<ScDPLabelData::Member>::const_iterator itr = rMembers.begin(), itrEnd = rMembers.end();
86 0 : for (; itr != itrEnd; ++itr)
87 : {
88 0 : OUString aName = itr->getDisplayName();
89 0 : if (!aName.isEmpty())
90 0 : rLBox.InsertEntry(aName);
91 : else
92 : {
93 0 : rLBox.InsertEntry(ScGlobal::GetRscString(STR_EMPTYDATA), nEmptyPos);
94 0 : bEmpty = true;
95 : }
96 : }
97 0 : return bEmpty;
98 : }
99 :
100 : /** This table represents the order of the strings in the resource string array. */
101 : static const sal_uInt16 spnFunctions[] =
102 : {
103 : PIVOT_FUNC_SUM,
104 : PIVOT_FUNC_COUNT,
105 : PIVOT_FUNC_AVERAGE,
106 : PIVOT_FUNC_MAX,
107 : PIVOT_FUNC_MIN,
108 : PIVOT_FUNC_PRODUCT,
109 : PIVOT_FUNC_COUNT_NUM,
110 : PIVOT_FUNC_STD_DEV,
111 : PIVOT_FUNC_STD_DEVP,
112 : PIVOT_FUNC_STD_VAR,
113 : PIVOT_FUNC_STD_VARP
114 : };
115 :
116 : const sal_uInt16 SC_BASEITEM_PREV_POS = 0;
117 : const sal_uInt16 SC_BASEITEM_NEXT_POS = 1;
118 : const sal_uInt16 SC_BASEITEM_USER_POS = 2;
119 :
120 : const sal_uInt16 SC_SORTNAME_POS = 0;
121 : const sal_uInt16 SC_SORTDATA_POS = 1;
122 :
123 : const long SC_SHOW_DEFAULT = 10;
124 :
125 : static const ScDPListBoxWrapper::MapEntryType spRefTypeMap[] =
126 : {
127 : { 0, DataPilotFieldReferenceType::NONE },
128 : { 1, DataPilotFieldReferenceType::ITEM_DIFFERENCE },
129 : { 2, DataPilotFieldReferenceType::ITEM_PERCENTAGE },
130 : { 3, DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE },
131 : { 4, DataPilotFieldReferenceType::RUNNING_TOTAL },
132 : { 5, DataPilotFieldReferenceType::ROW_PERCENTAGE },
133 : { 6, DataPilotFieldReferenceType::COLUMN_PERCENTAGE },
134 : { 7, DataPilotFieldReferenceType::TOTAL_PERCENTAGE },
135 : { 8, DataPilotFieldReferenceType::INDEX },
136 : { LISTBOX_ENTRY_NOTFOUND, DataPilotFieldReferenceType::NONE }
137 : };
138 :
139 : static const ScDPListBoxWrapper::MapEntryType spLayoutMap[] =
140 : {
141 : { 0, DataPilotFieldLayoutMode::TABULAR_LAYOUT },
142 : { 1, DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP },
143 : { 2, DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM },
144 : { LISTBOX_ENTRY_NOTFOUND, DataPilotFieldLayoutMode::TABULAR_LAYOUT }
145 : };
146 :
147 : static const ScDPListBoxWrapper::MapEntryType spShowFromMap[] =
148 : {
149 : { 0, DataPilotFieldShowItemsMode::FROM_TOP },
150 : { 1, DataPilotFieldShowItemsMode::FROM_BOTTOM },
151 : { LISTBOX_ENTRY_NOTFOUND, DataPilotFieldShowItemsMode::FROM_TOP }
152 : };
153 :
154 : } // namespace
155 :
156 : // ============================================================================
157 :
158 0 : ScDPFunctionListBox::ScDPFunctionListBox( Window* pParent, const ResId& rResId ) :
159 0 : MultiListBox( pParent, rResId )
160 : {
161 0 : FillFunctionNames();
162 0 : }
163 :
164 0 : void ScDPFunctionListBox::SetSelection( sal_uInt16 nFuncMask )
165 : {
166 0 : if( (nFuncMask == PIVOT_FUNC_NONE) || (nFuncMask == PIVOT_FUNC_AUTO) )
167 0 : SetNoSelection();
168 : else
169 0 : for( sal_uInt16 nEntry = 0, nCount = GetEntryCount(); nEntry < nCount; ++nEntry )
170 0 : SelectEntryPos( nEntry, (nFuncMask & spnFunctions[ nEntry ]) != 0 );
171 0 : }
172 :
173 0 : sal_uInt16 ScDPFunctionListBox::GetSelection() const
174 : {
175 0 : sal_uInt16 nFuncMask = PIVOT_FUNC_NONE;
176 0 : for( sal_uInt16 nSel = 0, nCount = GetSelectEntryCount(); nSel < nCount; ++nSel )
177 0 : nFuncMask |= spnFunctions[ GetSelectEntryPos( nSel ) ];
178 0 : return nFuncMask;
179 : }
180 :
181 0 : void ScDPFunctionListBox::FillFunctionNames()
182 : {
183 : OSL_ENSURE( !GetEntryCount(), "ScDPMultiFuncListBox::FillFunctionNames - do not add texts to resource" );
184 0 : Clear();
185 0 : ResStringArray aArr( ScResId( SCSTR_DPFUNCLISTBOX ) );
186 0 : for( sal_uInt16 nIndex = 0, nCount = sal::static_int_cast<sal_uInt16>(aArr.Count()); nIndex < nCount; ++nIndex )
187 0 : InsertEntry( aArr.GetString( nIndex ) );
188 0 : }
189 :
190 : // ============================================================================
191 :
192 0 : ScDPFunctionDlg::ScDPFunctionDlg(
193 : Window* pParent, const ScDPLabelDataVector& rLabelVec,
194 : const ScDPLabelData& rLabelData, const ScPivotFuncData& rFuncData ) :
195 : ModalDialog ( pParent, ScResId( RID_SCDLG_DPDATAFIELD ) ),
196 : maFlFunc ( this, ScResId( FL_FUNC ) ),
197 : maLbFunc ( this, ScResId( LB_FUNC ) ),
198 : maFtNameLabel ( this, ScResId( FT_NAMELABEL ) ),
199 : maFtName ( this, ScResId( FT_NAME ) ),
200 : maFlDisplay ( this, ScResId( FL_DISPLAY ) ),
201 : maFtType ( this, ScResId( FT_TYPE ) ),
202 : maLbType ( this, ScResId( LB_TYPE ) ),
203 : maFtBaseField ( this, ScResId( FT_BASEFIELD ) ),
204 : maLbBaseField ( this, ScResId( LB_BASEFIELD ) ),
205 : maFtBaseItem ( this, ScResId( FT_BASEITEM ) ),
206 : maLbBaseItem ( this, ScResId( LB_BASEITEM ) ),
207 : maBtnOk ( this, ScResId( BTN_OK ) ),
208 : maBtnCancel ( this, ScResId( BTN_CANCEL ) ),
209 : maBtnHelp ( this, ScResId( BTN_HELP ) ),
210 : maBtnMore ( this, ScResId( BTN_MORE ) ),
211 : maLbTypeWrp ( maLbType, spRefTypeMap ),
212 : mrLabelVec ( rLabelVec ),
213 0 : mbEmptyItem ( false )
214 : {
215 0 : FreeResource();
216 0 : Init( rLabelData, rFuncData );
217 0 : maLbFunc.EnableMultiSelection(false);
218 0 : }
219 :
220 0 : sal_uInt16 ScDPFunctionDlg::GetFuncMask() const
221 : {
222 0 : return maLbFunc.GetSelection();
223 : }
224 :
225 0 : DataPilotFieldReference ScDPFunctionDlg::GetFieldRef() const
226 : {
227 0 : DataPilotFieldReference aRef;
228 :
229 0 : aRef.ReferenceType = maLbTypeWrp.GetControlValue();
230 0 : aRef.ReferenceField = GetBaseFieldName(maLbBaseField.GetSelectEntry());
231 :
232 0 : sal_uInt16 nBaseItemPos = maLbBaseItem.GetSelectEntryPos();
233 0 : switch( nBaseItemPos )
234 : {
235 : case SC_BASEITEM_PREV_POS:
236 0 : aRef.ReferenceItemType = DataPilotFieldReferenceItemType::PREVIOUS;
237 0 : break;
238 : case SC_BASEITEM_NEXT_POS:
239 0 : aRef.ReferenceItemType = DataPilotFieldReferenceItemType::NEXT;
240 0 : break;
241 : default:
242 : {
243 0 : aRef.ReferenceItemType = DataPilotFieldReferenceItemType::NAMED;
244 0 : if( !mbEmptyItem || (nBaseItemPos > SC_BASEITEM_USER_POS) )
245 0 : aRef.ReferenceItemName = GetBaseItemName(maLbBaseItem.GetSelectEntry());
246 : }
247 : }
248 :
249 0 : return aRef;
250 : }
251 :
252 0 : void ScDPFunctionDlg::Init( const ScDPLabelData& rLabelData, const ScPivotFuncData& rFuncData )
253 : {
254 : // list box
255 0 : sal_uInt16 nFuncMask = (rFuncData.mnFuncMask == PIVOT_FUNC_NONE) ? PIVOT_FUNC_SUM : rFuncData.mnFuncMask;
256 0 : maLbFunc.SetSelection( nFuncMask );
257 :
258 : // field name
259 0 : maFtName.SetText(rLabelData.getDisplayName());
260 :
261 : // "More button" controls
262 0 : maBtnMore.AddWindow( &maFlDisplay );
263 0 : maBtnMore.AddWindow( &maFtType );
264 0 : maBtnMore.AddWindow( &maLbType );
265 0 : maBtnMore.AddWindow( &maFtBaseField );
266 0 : maBtnMore.AddWindow( &maLbBaseField );
267 0 : maBtnMore.AddWindow( &maFtBaseItem );
268 0 : maBtnMore.AddWindow( &maLbBaseItem );
269 :
270 : // handlers
271 0 : maLbFunc.SetDoubleClickHdl( LINK( this, ScDPFunctionDlg, DblClickHdl ) );
272 0 : maLbType.SetSelectHdl( LINK( this, ScDPFunctionDlg, SelectHdl ) );
273 0 : maLbBaseField.SetSelectHdl( LINK( this, ScDPFunctionDlg, SelectHdl ) );
274 :
275 : // base field list box
276 0 : OUString aSelectedEntry;
277 0 : for( ScDPLabelDataVector::const_iterator aIt = mrLabelVec.begin(), aEnd = mrLabelVec.end(); aIt != aEnd; ++aIt )
278 : {
279 0 : maLbBaseField.InsertEntry(aIt->getDisplayName());
280 : maBaseFieldNameMap.insert(
281 0 : NameMapType::value_type(aIt->getDisplayName(), aIt->maName));
282 0 : if (aIt->maName == rFuncData.maFieldRef.ReferenceField)
283 0 : aSelectedEntry = aIt->getDisplayName();
284 : }
285 :
286 : // base item list box
287 0 : maLbBaseItem.SetSeparatorPos( SC_BASEITEM_USER_POS - 1 );
288 :
289 : // select field reference type
290 0 : maLbTypeWrp.SetControlValue( rFuncData.maFieldRef.ReferenceType );
291 0 : SelectHdl( &maLbType ); // enables base field/item list boxes
292 :
293 : // select base field
294 0 : maLbBaseField.SelectEntry(aSelectedEntry);
295 0 : if( maLbBaseField.GetSelectEntryPos() >= maLbBaseField.GetEntryCount() )
296 0 : maLbBaseField.SelectEntryPos( 0 );
297 0 : SelectHdl( &maLbBaseField ); // fills base item list, selects base item
298 :
299 : // select base item
300 0 : switch( rFuncData.maFieldRef.ReferenceItemType )
301 : {
302 : case DataPilotFieldReferenceItemType::PREVIOUS:
303 0 : maLbBaseItem.SelectEntryPos( SC_BASEITEM_PREV_POS );
304 0 : break;
305 : case DataPilotFieldReferenceItemType::NEXT:
306 0 : maLbBaseItem.SelectEntryPos( SC_BASEITEM_NEXT_POS );
307 0 : break;
308 : default:
309 : {
310 0 : if( mbEmptyItem && rFuncData.maFieldRef.ReferenceItemName.isEmpty() )
311 : {
312 : // select special "(empty)" entry added before other items
313 0 : maLbBaseItem.SelectEntryPos( SC_BASEITEM_USER_POS );
314 : }
315 : else
316 : {
317 0 : sal_uInt16 nStartPos = mbEmptyItem ? (SC_BASEITEM_USER_POS + 1) : SC_BASEITEM_USER_POS;
318 0 : sal_uInt16 nPos = FindBaseItemPos( rFuncData.maFieldRef.ReferenceItemName, nStartPos );
319 0 : if( nPos >= maLbBaseItem.GetEntryCount() )
320 0 : nPos = (maLbBaseItem.GetEntryCount() > SC_BASEITEM_USER_POS) ? SC_BASEITEM_USER_POS : SC_BASEITEM_PREV_POS;
321 0 : maLbBaseItem.SelectEntryPos( nPos );
322 : }
323 : }
324 0 : }
325 0 : }
326 :
327 0 : const OUString& ScDPFunctionDlg::GetBaseFieldName(const OUString& rLayoutName) const
328 : {
329 0 : NameMapType::const_iterator itr = maBaseFieldNameMap.find(rLayoutName);
330 0 : return itr == maBaseFieldNameMap.end() ? rLayoutName : itr->second;
331 : }
332 :
333 0 : const OUString& ScDPFunctionDlg::GetBaseItemName(const OUString& rLayoutName) const
334 : {
335 0 : NameMapType::const_iterator itr = maBaseItemNameMap.find(rLayoutName);
336 0 : return itr == maBaseItemNameMap.end() ? rLayoutName : itr->second;
337 : }
338 :
339 0 : sal_uInt16 ScDPFunctionDlg::FindBaseItemPos( const String& rEntry, sal_uInt16 nStartPos ) const
340 : {
341 0 : sal_uInt16 nPos = nStartPos;
342 0 : bool bFound = false;
343 0 : while (nPos < maLbBaseItem.GetEntryCount())
344 : {
345 : // translate the displayed field name back to its original field name.
346 0 : const OUString& rName = GetBaseItemName(maLbBaseItem.GetEntry(nPos));
347 0 : if (rName.equals(rEntry))
348 : {
349 0 : bFound = true;
350 0 : break;
351 : }
352 0 : ++nPos;
353 : }
354 0 : return bFound ? nPos : LISTBOX_ENTRY_NOTFOUND;
355 : }
356 :
357 0 : IMPL_LINK( ScDPFunctionDlg, SelectHdl, ListBox*, pLBox )
358 : {
359 0 : if( pLBox == &maLbType )
360 : {
361 : bool bEnableField, bEnableItem;
362 0 : switch( maLbTypeWrp.GetControlValue() )
363 : {
364 : case DataPilotFieldReferenceType::ITEM_DIFFERENCE:
365 : case DataPilotFieldReferenceType::ITEM_PERCENTAGE:
366 : case DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE:
367 0 : bEnableField = bEnableItem = true;
368 0 : break;
369 :
370 : case DataPilotFieldReferenceType::RUNNING_TOTAL:
371 0 : bEnableField = true;
372 0 : bEnableItem = false;
373 0 : break;
374 :
375 : default:
376 0 : bEnableField = bEnableItem = false;
377 : }
378 :
379 0 : bEnableField &= maLbBaseField.GetEntryCount() > 0;
380 0 : maFtBaseField.Enable( bEnableField );
381 0 : maLbBaseField.Enable( bEnableField );
382 :
383 0 : bEnableItem &= bEnableField;
384 0 : maFtBaseItem.Enable( bEnableItem );
385 0 : maLbBaseItem.Enable( bEnableItem );
386 : }
387 0 : else if( pLBox == &maLbBaseField )
388 : {
389 : // keep "previous" and "next" entries
390 0 : while( maLbBaseItem.GetEntryCount() > SC_BASEITEM_USER_POS )
391 0 : maLbBaseItem.RemoveEntry( SC_BASEITEM_USER_POS );
392 :
393 : // update item list for current base field
394 0 : mbEmptyItem = false;
395 0 : size_t nBasePos = maLbBaseField.GetSelectEntryPos();
396 0 : if( nBasePos < mrLabelVec.size() )
397 : {
398 0 : const vector<ScDPLabelData::Member>& rMembers = mrLabelVec[nBasePos].maMembers;
399 0 : mbEmptyItem = lclFillListBox( maLbBaseItem, rMembers, SC_BASEITEM_USER_POS );
400 : // build cache for base names.
401 0 : NameMapType aMap;
402 0 : vector<ScDPLabelData::Member>::const_iterator itr = rMembers.begin(), itrEnd = rMembers.end();
403 0 : for (; itr != itrEnd; ++itr)
404 0 : aMap.insert(NameMapType::value_type(itr->getDisplayName(), itr->maName));
405 0 : maBaseItemNameMap.swap(aMap);
406 : }
407 :
408 : // select base item
409 0 : sal_uInt16 nItemPos = (maLbBaseItem.GetEntryCount() > SC_BASEITEM_USER_POS) ? SC_BASEITEM_USER_POS : SC_BASEITEM_PREV_POS;
410 0 : maLbBaseItem.SelectEntryPos( nItemPos );
411 : }
412 0 : return 0;
413 : }
414 :
415 0 : IMPL_LINK_NOARG(ScDPFunctionDlg, DblClickHdl)
416 : {
417 0 : maBtnOk.Click();
418 0 : return 0;
419 : }
420 :
421 : // ============================================================================
422 :
423 0 : ScDPSubtotalDlg::ScDPSubtotalDlg( Window* pParent, ScDPObject& rDPObj,
424 : const ScDPLabelData& rLabelData, const ScPivotFuncData& rFuncData,
425 : const ScDPNameVec& rDataFields, bool bEnableLayout ) :
426 : ModalDialog ( pParent, ScResId( RID_SCDLG_PIVOTSUBT ) ),
427 : maFlSubt ( this, ScResId( FL_FUNC ) ),
428 : maRbNone ( this, ScResId( RB_NONE ) ),
429 : maRbAuto ( this, ScResId( RB_AUTO ) ),
430 : maRbUser ( this, ScResId( RB_USER ) ),
431 : maLbFunc ( this, ScResId( LB_FUNC ) ),
432 : maFtNameLabel ( this, ScResId( FT_NAMELABEL ) ),
433 : maFtName ( this, ScResId( FT_NAME ) ),
434 : maCbShowAll ( this, ScResId( CB_SHOWALL ) ),
435 : maBtnOk ( this, ScResId( BTN_OK ) ),
436 : maBtnCancel ( this, ScResId( BTN_CANCEL ) ),
437 : maBtnHelp ( this, ScResId( BTN_HELP ) ),
438 : maBtnOptions ( this, ScResId( BTN_OPTIONS ) ),
439 : mrDPObj ( rDPObj ),
440 : mrDataFields ( rDataFields ),
441 : maLabelData ( rLabelData ),
442 0 : mbEnableLayout ( bEnableLayout )
443 : {
444 0 : FreeResource();
445 0 : Init( rLabelData, rFuncData );
446 0 : }
447 :
448 0 : sal_uInt16 ScDPSubtotalDlg::GetFuncMask() const
449 : {
450 0 : sal_uInt16 nFuncMask = PIVOT_FUNC_NONE;
451 :
452 0 : if( maRbAuto.IsChecked() )
453 0 : nFuncMask = PIVOT_FUNC_AUTO;
454 0 : else if( maRbUser.IsChecked() )
455 0 : nFuncMask = maLbFunc.GetSelection();
456 :
457 0 : return nFuncMask;
458 : }
459 :
460 0 : void ScDPSubtotalDlg::FillLabelData( ScDPLabelData& rLabelData ) const
461 : {
462 0 : rLabelData.mnFuncMask = GetFuncMask();
463 0 : rLabelData.mnUsedHier = maLabelData.mnUsedHier;
464 0 : rLabelData.mbShowAll = maCbShowAll.IsChecked();
465 0 : rLabelData.maMembers = maLabelData.maMembers;
466 0 : rLabelData.maSortInfo = maLabelData.maSortInfo;
467 0 : rLabelData.maLayoutInfo = maLabelData.maLayoutInfo;
468 0 : rLabelData.maShowInfo = maLabelData.maShowInfo;
469 0 : }
470 :
471 0 : void ScDPSubtotalDlg::Init( const ScDPLabelData& rLabelData, const ScPivotFuncData& rFuncData )
472 : {
473 : // field name
474 0 : maFtName.SetText(rLabelData.getDisplayName());
475 :
476 : // radio buttons
477 0 : maRbNone.SetClickHdl( LINK( this, ScDPSubtotalDlg, RadioClickHdl ) );
478 0 : maRbAuto.SetClickHdl( LINK( this, ScDPSubtotalDlg, RadioClickHdl ) );
479 0 : maRbUser.SetClickHdl( LINK( this, ScDPSubtotalDlg, RadioClickHdl ) );
480 :
481 0 : RadioButton* pRBtn = 0;
482 0 : switch( rFuncData.mnFuncMask )
483 : {
484 0 : case PIVOT_FUNC_NONE: pRBtn = &maRbNone; break;
485 0 : case PIVOT_FUNC_AUTO: pRBtn = &maRbAuto; break;
486 0 : default: pRBtn = &maRbUser;
487 : }
488 0 : pRBtn->Check();
489 0 : RadioClickHdl( pRBtn );
490 :
491 : // list box
492 0 : maLbFunc.SetSelection( rFuncData.mnFuncMask );
493 0 : maLbFunc.SetDoubleClickHdl( LINK( this, ScDPSubtotalDlg, DblClickHdl ) );
494 :
495 : // show all
496 0 : maCbShowAll.Check( rLabelData.mbShowAll );
497 :
498 : // options
499 0 : maBtnOptions.SetClickHdl( LINK( this, ScDPSubtotalDlg, ClickHdl ) );
500 0 : }
501 :
502 : // ----------------------------------------------------------------------------
503 :
504 0 : IMPL_LINK( ScDPSubtotalDlg, RadioClickHdl, RadioButton*, pBtn )
505 : {
506 0 : maLbFunc.Enable( pBtn == &maRbUser );
507 0 : return 0;
508 : }
509 :
510 0 : IMPL_LINK_NOARG(ScDPSubtotalDlg, DblClickHdl)
511 : {
512 0 : maBtnOk.Click();
513 0 : return 0;
514 : }
515 :
516 0 : IMPL_LINK( ScDPSubtotalDlg, ClickHdl, PushButton*, pBtn )
517 : {
518 0 : if( pBtn == &maBtnOptions )
519 : {
520 0 : ScDPSubtotalOptDlg* pDlg = new ScDPSubtotalOptDlg( this, mrDPObj, maLabelData, mrDataFields, mbEnableLayout );
521 0 : if( pDlg->Execute() == RET_OK )
522 0 : pDlg->FillLabelData( maLabelData );
523 0 : delete pDlg;
524 : }
525 0 : return 0;
526 : }
527 :
528 : // ============================================================================
529 :
530 0 : ScDPSubtotalOptDlg::ScDPSubtotalOptDlg( Window* pParent, ScDPObject& rDPObj,
531 : const ScDPLabelData& rLabelData, const ScDPNameVec& rDataFields,
532 : bool bEnableLayout ) :
533 : ModalDialog ( pParent, ScResId( RID_SCDLG_DPSUBTOTAL_OPT ) ),
534 : maFlSortBy ( this, ScResId( FL_SORT_BY ) ),
535 : maLbSortBy ( this, ScResId( LB_SORT_BY ) ),
536 : maRbSortAsc ( this, ScResId( RB_SORT_ASC ) ),
537 : maRbSortDesc ( this, ScResId( RB_SORT_DESC ) ),
538 : maRbSortMan ( this, ScResId( RB_SORT_MAN ) ),
539 : maFlLayout ( this, ScResId( FL_LAYOUT ) ),
540 : maFtLayout ( this, ScResId( FT_LAYOUT ) ),
541 : maLbLayout ( this, ScResId( LB_LAYOUT ) ),
542 : maCbLayoutEmpty ( this, ScResId( CB_LAYOUT_EMPTY ) ),
543 : maFlAutoShow ( this, ScResId( FL_AUTOSHOW ) ),
544 : maCbShow ( this, ScResId( CB_SHOW ) ),
545 : maNfShow ( this, ScResId( NF_SHOW ) ),
546 : maFtShow ( this, ScResId( FT_SHOW ) ),
547 : maFtShowFrom ( this, ScResId( FT_SHOW_FROM ) ),
548 : maLbShowFrom ( this, ScResId( LB_SHOW_FROM ) ),
549 : maFtShowUsing ( this, ScResId( FT_SHOW_USING ) ),
550 : maLbShowUsing ( this, ScResId( LB_SHOW_USING ) ),
551 : maFlHide ( this, ScResId( FL_HIDE ) ),
552 : maLbHide ( this, ScResId( CT_HIDE ) ),
553 : maFtHierarchy ( this, ScResId( FT_HIERARCHY ) ),
554 : maLbHierarchy ( this, ScResId( LB_HIERARCHY ) ),
555 : maBtnOk ( this, ScResId( BTN_OK ) ),
556 : maBtnCancel ( this, ScResId( BTN_CANCEL ) ),
557 : maBtnHelp ( this, ScResId( BTN_HELP ) ),
558 : maLbLayoutWrp ( maLbLayout, spLayoutMap ),
559 : maLbShowFromWrp ( maLbShowFrom, spShowFromMap ),
560 : mrDPObj ( rDPObj ),
561 0 : maLabelData ( rLabelData )
562 : {
563 0 : FreeResource();
564 0 : Init( rDataFields, bEnableLayout );
565 0 : }
566 :
567 0 : void ScDPSubtotalOptDlg::FillLabelData( ScDPLabelData& rLabelData ) const
568 : {
569 : // *** SORTING ***
570 :
571 0 : if( maRbSortMan.IsChecked() )
572 0 : rLabelData.maSortInfo.Mode = DataPilotFieldSortMode::MANUAL;
573 0 : else if( maLbSortBy.GetSelectEntryPos() == SC_SORTNAME_POS )
574 0 : rLabelData.maSortInfo.Mode = DataPilotFieldSortMode::NAME;
575 : else
576 0 : rLabelData.maSortInfo.Mode = DataPilotFieldSortMode::DATA;
577 :
578 0 : rLabelData.maSortInfo.Field = GetFieldName(maLbSortBy.GetSelectEntry());
579 0 : rLabelData.maSortInfo.IsAscending = maRbSortAsc.IsChecked();
580 :
581 : // *** LAYOUT MODE ***
582 :
583 0 : rLabelData.maLayoutInfo.LayoutMode = maLbLayoutWrp.GetControlValue();
584 0 : rLabelData.maLayoutInfo.AddEmptyLines = maCbLayoutEmpty.IsChecked();
585 :
586 : // *** AUTO SHOW ***
587 :
588 0 : rLabelData.maShowInfo.IsEnabled = maCbShow.IsChecked();
589 0 : rLabelData.maShowInfo.ShowItemsMode = maLbShowFromWrp.GetControlValue();
590 0 : rLabelData.maShowInfo.ItemCount = sal::static_int_cast<sal_Int32>( maNfShow.GetValue() );
591 0 : rLabelData.maShowInfo.DataField = GetFieldName(maLbShowUsing.GetSelectEntry());
592 :
593 : // *** HIDDEN ITEMS ***
594 :
595 0 : rLabelData.maMembers = maLabelData.maMembers;
596 0 : sal_uLong nVisCount = maLbHide.GetEntryCount();
597 0 : for( sal_uInt16 nPos = 0; nPos < nVisCount; ++nPos )
598 0 : rLabelData.maMembers[nPos].mbVisible = !maLbHide.IsChecked(nPos);
599 :
600 : // *** HIERARCHY ***
601 :
602 0 : rLabelData.mnUsedHier = maLbHierarchy.GetSelectEntryCount() ? maLbHierarchy.GetSelectEntryPos() : 0;
603 0 : }
604 :
605 0 : void ScDPSubtotalOptDlg::Init( const ScDPNameVec& rDataFields, bool bEnableLayout )
606 : {
607 : // *** SORTING ***
608 :
609 0 : sal_Int32 nSortMode = maLabelData.maSortInfo.Mode;
610 :
611 : // sort fields list box
612 0 : maLbSortBy.InsertEntry(maLabelData.getDisplayName());
613 :
614 0 : for( ScDPNameVec::const_iterator aIt = rDataFields.begin(), aEnd = rDataFields.end(); aIt != aEnd; ++aIt )
615 : {
616 : // Cache names for later lookup.
617 0 : maDataFieldNameMap.insert(NameMapType::value_type(aIt->maLayoutName, aIt->maName));
618 :
619 0 : maLbSortBy.InsertEntry( aIt->maLayoutName );
620 0 : maLbShowUsing.InsertEntry( aIt->maLayoutName ); // for AutoShow
621 : }
622 :
623 0 : if( maLbSortBy.GetEntryCount() > SC_SORTDATA_POS )
624 0 : maLbSortBy.SetSeparatorPos( SC_SORTDATA_POS - 1 );
625 :
626 0 : sal_uInt16 nSortPos = SC_SORTNAME_POS;
627 0 : if( nSortMode == DataPilotFieldSortMode::DATA )
628 : {
629 0 : nSortPos = FindListBoxEntry( maLbSortBy, maLabelData.maSortInfo.Field, SC_SORTDATA_POS );
630 0 : if( nSortPos >= maLbSortBy.GetEntryCount() )
631 : {
632 0 : nSortPos = SC_SORTNAME_POS;
633 0 : nSortMode = DataPilotFieldSortMode::MANUAL;
634 : }
635 : }
636 0 : maLbSortBy.SelectEntryPos( nSortPos );
637 :
638 : // sorting mode
639 0 : maRbSortAsc.SetClickHdl( LINK( this, ScDPSubtotalOptDlg, RadioClickHdl ) );
640 0 : maRbSortDesc.SetClickHdl( LINK( this, ScDPSubtotalOptDlg, RadioClickHdl ) );
641 0 : maRbSortMan.SetClickHdl( LINK( this, ScDPSubtotalOptDlg, RadioClickHdl ) );
642 :
643 0 : RadioButton* pRBtn = 0;
644 0 : switch( nSortMode )
645 : {
646 : case DataPilotFieldSortMode::NONE:
647 : case DataPilotFieldSortMode::MANUAL:
648 0 : pRBtn = &maRbSortMan;
649 0 : break;
650 : default:
651 0 : pRBtn = maLabelData.maSortInfo.IsAscending ? &maRbSortAsc : &maRbSortDesc;
652 : }
653 0 : pRBtn->Check();
654 0 : RadioClickHdl( pRBtn );
655 :
656 : // *** LAYOUT MODE ***
657 :
658 0 : maFlLayout.Enable( bEnableLayout );
659 0 : maFtLayout.Enable( bEnableLayout );
660 0 : maLbLayout.Enable( bEnableLayout );
661 0 : maCbLayoutEmpty.Enable( bEnableLayout );
662 :
663 0 : maLbLayoutWrp.SetControlValue( maLabelData.maLayoutInfo.LayoutMode );
664 0 : maCbLayoutEmpty.Check( maLabelData.maLayoutInfo.AddEmptyLines );
665 :
666 : // *** AUTO SHOW ***
667 :
668 0 : maCbShow.Check( maLabelData.maShowInfo.IsEnabled );
669 0 : maCbShow.SetClickHdl( LINK( this, ScDPSubtotalOptDlg, CheckHdl ) );
670 :
671 0 : maLbShowFromWrp.SetControlValue( maLabelData.maShowInfo.ShowItemsMode );
672 0 : long nCount = static_cast< long >( maLabelData.maShowInfo.ItemCount );
673 0 : if( nCount < 1 )
674 0 : nCount = SC_SHOW_DEFAULT;
675 0 : maNfShow.SetValue( nCount );
676 :
677 : // maLbShowUsing already filled above
678 0 : maLbShowUsing.SelectEntry( maLabelData.maShowInfo.DataField );
679 0 : if( maLbShowUsing.GetSelectEntryPos() >= maLbShowUsing.GetEntryCount() )
680 0 : maLbShowUsing.SelectEntryPos( 0 );
681 :
682 0 : CheckHdl( &maCbShow ); // enable/disable dependent controls
683 :
684 : // *** HIDDEN ITEMS ***
685 :
686 0 : maLbHide.SetHelpId( HID_SC_DPSUBT_HIDE );
687 0 : InitHideListBox();
688 :
689 : // *** HIERARCHY ***
690 :
691 0 : if( maLabelData.maHiers.getLength() > 1 )
692 : {
693 0 : lclFillListBox( maLbHierarchy, maLabelData.maHiers );
694 0 : sal_Int32 nHier = maLabelData.mnUsedHier;
695 0 : if( (nHier < 0) || (nHier >= maLabelData.maHiers.getLength()) ) nHier = 0;
696 0 : maLbHierarchy.SelectEntryPos( static_cast< sal_uInt16 >( nHier ) );
697 0 : maLbHierarchy.SetSelectHdl( LINK( this, ScDPSubtotalOptDlg, SelectHdl ) );
698 : }
699 : else
700 : {
701 0 : maFtHierarchy.Disable();
702 0 : maLbHierarchy.Disable();
703 : }
704 0 : }
705 :
706 0 : void ScDPSubtotalOptDlg::InitHideListBox()
707 : {
708 0 : maLbHide.Clear();
709 0 : lclFillListBox( maLbHide, maLabelData.maMembers );
710 0 : size_t n = maLabelData.maMembers.size();
711 0 : for (size_t i = 0; i < n; ++i)
712 0 : maLbHide.CheckEntryPos(static_cast<sal_uInt16>(i), !maLabelData.maMembers[i].mbVisible);
713 0 : bool bEnable = maLbHide.GetEntryCount() > 0;
714 0 : maFlHide.Enable( bEnable );
715 0 : maLbHide.Enable( bEnable );
716 0 : }
717 :
718 0 : const OUString& ScDPSubtotalOptDlg::GetFieldName(const OUString& rLayoutName) const
719 : {
720 0 : NameMapType::const_iterator itr = maDataFieldNameMap.find(rLayoutName);
721 0 : return itr == maDataFieldNameMap.end() ? rLayoutName : itr->second;
722 : }
723 :
724 0 : sal_uInt16 ScDPSubtotalOptDlg::FindListBoxEntry(
725 : const ListBox& rLBox, const String& rEntry, sal_uInt16 nStartPos ) const
726 : {
727 0 : sal_uInt16 nPos = nStartPos;
728 0 : bool bFound = false;
729 0 : while (nPos < rLBox.GetEntryCount())
730 : {
731 : // translate the displayed field name back to its original field name.
732 0 : const OUString& rName = GetFieldName(rLBox.GetEntry(nPos));
733 0 : if (rName.equals(rEntry))
734 : {
735 0 : bFound = true;
736 0 : break;
737 : }
738 0 : ++nPos;
739 : }
740 0 : return bFound ? nPos : LISTBOX_ENTRY_NOTFOUND;
741 : }
742 :
743 0 : IMPL_LINK( ScDPSubtotalOptDlg, RadioClickHdl, RadioButton*, pBtn )
744 : {
745 0 : maLbSortBy.Enable( pBtn != &maRbSortMan );
746 0 : return 0;
747 : }
748 :
749 0 : IMPL_LINK( ScDPSubtotalOptDlg, CheckHdl, CheckBox*, pCBox )
750 : {
751 0 : if( pCBox == &maCbShow )
752 : {
753 0 : bool bEnable = maCbShow.IsChecked();
754 0 : maNfShow.Enable( bEnable );
755 0 : maFtShow.Enable( bEnable );
756 0 : maFtShowFrom.Enable( bEnable );
757 0 : maLbShowFrom.Enable( bEnable );
758 :
759 0 : bool bEnableUsing = bEnable && (maLbShowUsing.GetEntryCount() > 0);
760 0 : maFtShowUsing.Enable( bEnableUsing );
761 0 : maLbShowUsing.Enable( bEnableUsing );
762 : }
763 0 : return 0;
764 : }
765 :
766 0 : IMPL_LINK( ScDPSubtotalOptDlg, SelectHdl, ListBox*, pLBox )
767 : {
768 0 : if( pLBox == &maLbHierarchy )
769 : {
770 0 : mrDPObj.GetMembers(maLabelData.mnCol, maLbHierarchy.GetSelectEntryPos(), maLabelData.maMembers);
771 0 : InitHideListBox();
772 : }
773 0 : return 0;
774 : }
775 :
776 : // ============================================================================
777 :
778 0 : ScDPShowDetailDlg::ScDPShowDetailDlg( Window* pParent, ScDPObject& rDPObj, sal_uInt16 nOrient ) :
779 : ModalDialog ( pParent, ScResId( RID_SCDLG_DPSHOWDETAIL ) ),
780 : maFtDims ( this, ScResId( FT_DIMS ) ),
781 : maLbDims ( this, ScResId( LB_DIMS ) ),
782 : maBtnOk ( this, ScResId( BTN_OK ) ),
783 : maBtnCancel ( this, ScResId( BTN_CANCEL ) ),
784 : maBtnHelp ( this, ScResId( BTN_HELP ) ),
785 :
786 0 : mrDPObj(rDPObj)
787 : {
788 0 : FreeResource();
789 :
790 0 : ScDPSaveData* pSaveData = rDPObj.GetSaveData();
791 0 : long nDimCount = rDPObj.GetDimCount();
792 0 : for (long nDim=0; nDim<nDimCount; nDim++)
793 : {
794 : bool bIsDataLayout;
795 0 : sal_Int32 nDimFlags = 0;
796 0 : OUString aName = rDPObj.GetDimName( nDim, bIsDataLayout, &nDimFlags );
797 0 : if ( !bIsDataLayout && !rDPObj.IsDuplicated( nDim ) && ScDPObject::IsOrientationAllowed( nOrient, nDimFlags ) )
798 : {
799 0 : const ScDPSaveDimension* pDimension = pSaveData ? pSaveData->GetExistingDimensionByName(aName) : 0;
800 0 : if ( !pDimension || (pDimension->GetOrientation() != nOrient) )
801 : {
802 0 : if (pDimension)
803 : {
804 0 : const OUString* pLayoutName = pDimension->GetLayoutName();
805 0 : if (pLayoutName)
806 0 : aName = *pLayoutName;
807 : }
808 0 : maLbDims.InsertEntry( aName );
809 0 : maNameIndexMap.insert(DimNameIndexMap::value_type(aName, nDim));
810 : }
811 : }
812 0 : }
813 0 : if( maLbDims.GetEntryCount() )
814 0 : maLbDims.SelectEntryPos( 0 );
815 :
816 0 : maLbDims.SetDoubleClickHdl( LINK( this, ScDPShowDetailDlg, DblClickHdl ) );
817 0 : }
818 :
819 0 : short ScDPShowDetailDlg::Execute()
820 : {
821 0 : return maLbDims.GetEntryCount() ? ModalDialog::Execute() : RET_CANCEL;
822 : }
823 :
824 0 : OUString ScDPShowDetailDlg::GetDimensionName() const
825 : {
826 : // Look up the internal dimension name which may be different from the
827 : // displayed field name.
828 0 : String aSelectedName = maLbDims.GetSelectEntry();
829 0 : DimNameIndexMap::const_iterator itr = maNameIndexMap.find(aSelectedName);
830 0 : if (itr == maNameIndexMap.end())
831 : // This should never happen!
832 0 : return aSelectedName;
833 :
834 0 : long nDim = itr->second;
835 0 : bool bIsDataLayout = false;
836 0 : return mrDPObj.GetDimName(nDim, bIsDataLayout);
837 : }
838 :
839 0 : IMPL_LINK( ScDPShowDetailDlg, DblClickHdl, ListBox*, pLBox )
840 : {
841 0 : if( pLBox == &maLbDims )
842 0 : maBtnOk.Click();
843 0 : return 0;
844 0 : }
845 :
846 : // ============================================================================
847 :
848 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|