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