1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #undef SC_DLLIMPLEMENTATION
22 #include "pvfundlg.hxx"
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>
30 #include <tools/resary.hxx>
31 #include <vcl/builderfactory.hxx>
32 #include <vcl/msgbox.hxx>
34 #include "scresid.hxx"
35 #include "dpobject.hxx"
38 #include "globstr.hrc"
42 #include <boost/scoped_ptr.hpp>
44 using namespace ::com::sun::star::sheet
;
46 using ::com::sun::star::uno::Sequence
;
51 /** Appends all strings from the Sequence to the list box.
53 Empty strings are replaced by a localized "(empty)" entry and inserted at
54 the specified position.
56 @return true = The passed string list contains an empty string entry.
58 template< typename ListBoxType
>
59 bool lclFillListBox( ListBoxType
& rLBox
, const Sequence
< OUString
>& rStrings
, sal_Int32 nEmptyPos
= LISTBOX_APPEND
)
62 const OUString
* pStr
= rStrings
.getConstArray();
65 for( const OUString
* pEnd
= pStr
+ rStrings
.getLength(); pStr
!= pEnd
; ++pStr
)
67 if( !pStr
->isEmpty() )
68 rLBox
.InsertEntry( *pStr
);
71 rLBox
.InsertEntry( ScGlobal::GetRscString( STR_EMPTYDATA
), nEmptyPos
);
79 template< typename ListBoxType
>
80 bool lclFillListBox( ListBoxType
& rLBox
, const vector
<ScDPLabelData::Member
>& rMembers
, sal_Int32 nEmptyPos
= LISTBOX_APPEND
)
83 vector
<ScDPLabelData::Member
>::const_iterator itr
= rMembers
.begin(), itrEnd
= rMembers
.end();
84 for (; itr
!= itrEnd
; ++itr
)
86 OUString aName
= itr
->getDisplayName();
88 rLBox
.InsertEntry(aName
);
91 rLBox
.InsertEntry(ScGlobal::GetRscString(STR_EMPTYDATA
), nEmptyPos
);
98 /** This table represents the order of the strings in the resource string array. */
99 static const sal_uInt16 spnFunctions
[] =
107 PIVOT_FUNC_COUNT_NUM
,
114 const sal_uInt16 SC_BASEITEM_PREV_POS
= 0;
115 const sal_uInt16 SC_BASEITEM_NEXT_POS
= 1;
116 const sal_uInt16 SC_BASEITEM_USER_POS
= 2;
118 const sal_uInt16 SC_SORTNAME_POS
= 0;
119 const sal_uInt16 SC_SORTDATA_POS
= 1;
121 const long SC_SHOW_DEFAULT
= 10;
123 static const ScDPListBoxWrapper::MapEntryType spRefTypeMap
[] =
125 { 0, DataPilotFieldReferenceType::NONE
},
126 { 1, DataPilotFieldReferenceType::ITEM_DIFFERENCE
},
127 { 2, DataPilotFieldReferenceType::ITEM_PERCENTAGE
},
128 { 3, DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE
},
129 { 4, DataPilotFieldReferenceType::RUNNING_TOTAL
},
130 { 5, DataPilotFieldReferenceType::ROW_PERCENTAGE
},
131 { 6, DataPilotFieldReferenceType::COLUMN_PERCENTAGE
},
132 { 7, DataPilotFieldReferenceType::TOTAL_PERCENTAGE
},
133 { 8, DataPilotFieldReferenceType::INDEX
},
134 { WRAPPER_LISTBOX_ENTRY_NOTFOUND
, DataPilotFieldReferenceType::NONE
}
137 static const ScDPListBoxWrapper::MapEntryType spLayoutMap
[] =
139 { 0, DataPilotFieldLayoutMode::TABULAR_LAYOUT
},
140 { 1, DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP
},
141 { 2, DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM
},
142 { WRAPPER_LISTBOX_ENTRY_NOTFOUND
, DataPilotFieldLayoutMode::TABULAR_LAYOUT
}
145 static const ScDPListBoxWrapper::MapEntryType spShowFromMap
[] =
147 { 0, DataPilotFieldShowItemsMode::FROM_TOP
},
148 { 1, DataPilotFieldShowItemsMode::FROM_BOTTOM
},
149 { WRAPPER_LISTBOX_ENTRY_NOTFOUND
, DataPilotFieldShowItemsMode::FROM_TOP
}
154 ScDPFunctionListBox::ScDPFunctionListBox(vcl::Window
* pParent
, WinBits nStyle
)
155 : ListBox(pParent
, nStyle
)
160 VCL_BUILDER_DECL_FACTORY(ScDPFunctionListBox
)
162 WinBits nWinStyle
= WB_LEFT
|WB_VCENTER
|WB_3DLOOK
|WB_SIMPLEMODE
;
163 OString sBorder
= VclBuilder::extractCustomProperty(rMap
);
164 if (!sBorder
.isEmpty())
165 nWinStyle
|= WB_BORDER
;
166 rRet
= VclPtr
<ScDPFunctionListBox
>::Create(pParent
, nWinStyle
);
169 void ScDPFunctionListBox::SetSelection( sal_uInt16 nFuncMask
)
171 if( (nFuncMask
== PIVOT_FUNC_NONE
) || (nFuncMask
== PIVOT_FUNC_AUTO
) )
174 for( sal_Int32 nEntry
= 0, nCount
= GetEntryCount(); nEntry
< nCount
; ++nEntry
)
175 SelectEntryPos( nEntry
, (nFuncMask
& spnFunctions
[ nEntry
]) != 0 );
178 sal_uInt16
ScDPFunctionListBox::GetSelection() const
180 sal_uInt16 nFuncMask
= PIVOT_FUNC_NONE
;
181 for( sal_Int32 nSel
= 0, nCount
= GetSelectEntryCount(); nSel
< nCount
; ++nSel
)
182 nFuncMask
|= spnFunctions
[ GetSelectEntryPos( nSel
) ];
186 void ScDPFunctionListBox::FillFunctionNames()
188 OSL_ENSURE( !GetEntryCount(), "ScDPMultiFuncListBox::FillFunctionNames - do not add texts to resource" );
190 ResStringArray
aArr( ScResId( SCSTR_DPFUNCLISTBOX
) );
191 for( sal_uInt16 nIndex
= 0, nCount
= sal::static_int_cast
<sal_uInt16
>(aArr
.Count()); nIndex
< nCount
; ++nIndex
)
192 InsertEntry( aArr
.GetString( nIndex
) );
195 ScDPFunctionDlg::ScDPFunctionDlg(
196 vcl::Window
* pParent
, const ScDPLabelDataVector
& rLabelVec
,
197 const ScDPLabelData
& rLabelData
, const ScPivotFuncData
& rFuncData
)
198 : ModalDialog(pParent
, "DataFieldDialog",
199 "modules/scalc/ui/datafielddialog.ui")
200 , mrLabelVec(rLabelVec
)
203 get(mpFtName
, "name");
204 get(mpLbType
, "type");
205 mxLbTypeWrp
.reset(new ScDPListBoxWrapper(*mpLbType
, spRefTypeMap
));
206 get(mpLbFunc
, "functions");
207 mpLbFunc
->set_height_request(mpLbFunc
->GetTextHeight() * 8);
208 get(mpFtBaseField
, "basefieldft");
209 get(mpLbBaseField
, "basefield");
210 get(mpFtBaseItem
, "baseitemft");
211 get(mpLbBaseItem
, "baseitem");
214 Init( rLabelData
, rFuncData
);
217 ScDPFunctionDlg::~ScDPFunctionDlg()
222 void ScDPFunctionDlg::dispose()
227 mpFtBaseField
.clear();
228 mpLbBaseField
.clear();
229 mpFtBaseItem
.clear();
230 mpLbBaseItem
.clear();
232 ModalDialog::dispose();
236 sal_uInt16
ScDPFunctionDlg::GetFuncMask() const
238 return mpLbFunc
->GetSelection();
241 DataPilotFieldReference
ScDPFunctionDlg::GetFieldRef() const
243 DataPilotFieldReference aRef
;
245 aRef
.ReferenceType
= mxLbTypeWrp
->GetControlValue();
246 aRef
.ReferenceField
= GetBaseFieldName(mpLbBaseField
->GetSelectEntry());
248 sal_Int32 nBaseItemPos
= mpLbBaseItem
->GetSelectEntryPos();
249 switch( nBaseItemPos
)
251 case SC_BASEITEM_PREV_POS
:
252 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::PREVIOUS
;
254 case SC_BASEITEM_NEXT_POS
:
255 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::NEXT
;
259 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::NAMED
;
260 if( !mbEmptyItem
|| (nBaseItemPos
> SC_BASEITEM_USER_POS
) )
261 aRef
.ReferenceItemName
= GetBaseItemName(mpLbBaseItem
->GetSelectEntry());
268 void ScDPFunctionDlg::Init( const ScDPLabelData
& rLabelData
, const ScPivotFuncData
& rFuncData
)
271 sal_uInt16 nFuncMask
= (rFuncData
.mnFuncMask
== PIVOT_FUNC_NONE
) ? PIVOT_FUNC_SUM
: rFuncData
.mnFuncMask
;
272 mpLbFunc
->SetSelection( nFuncMask
);
275 mpFtName
->SetText(rLabelData
.getDisplayName());
278 mpLbFunc
->SetDoubleClickHdl( LINK( this, ScDPFunctionDlg
, DblClickHdl
) );
279 mpLbType
->SetSelectHdl( LINK( this, ScDPFunctionDlg
, SelectHdl
) );
280 mpLbBaseField
->SetSelectHdl( LINK( this, ScDPFunctionDlg
, SelectHdl
) );
282 // base field list box
283 OUString aSelectedEntry
;
284 for( ScDPLabelDataVector::const_iterator aIt
= mrLabelVec
.begin(), aEnd
= mrLabelVec
.end(); aIt
!= aEnd
; ++aIt
)
286 mpLbBaseField
->InsertEntry(aIt
->getDisplayName());
287 maBaseFieldNameMap
.insert(
288 NameMapType::value_type(aIt
->getDisplayName(), aIt
->maName
));
289 if (aIt
->maName
== rFuncData
.maFieldRef
.ReferenceField
)
290 aSelectedEntry
= aIt
->getDisplayName();
293 // base item list box
294 mpLbBaseItem
->SetSeparatorPos( SC_BASEITEM_USER_POS
- 1 );
296 // select field reference type
297 mxLbTypeWrp
->SetControlValue( rFuncData
.maFieldRef
.ReferenceType
);
298 SelectHdl( mpLbType
); // enables base field/item list boxes
301 mpLbBaseField
->SelectEntry(aSelectedEntry
);
302 if( mpLbBaseField
->GetSelectEntryPos() >= mpLbBaseField
->GetEntryCount() )
303 mpLbBaseField
->SelectEntryPos( 0 );
304 SelectHdl( mpLbBaseField
); // fills base item list, selects base item
307 switch( rFuncData
.maFieldRef
.ReferenceItemType
)
309 case DataPilotFieldReferenceItemType::PREVIOUS
:
310 mpLbBaseItem
->SelectEntryPos( SC_BASEITEM_PREV_POS
);
312 case DataPilotFieldReferenceItemType::NEXT
:
313 mpLbBaseItem
->SelectEntryPos( SC_BASEITEM_NEXT_POS
);
317 if( mbEmptyItem
&& rFuncData
.maFieldRef
.ReferenceItemName
.isEmpty() )
319 // select special "(empty)" entry added before other items
320 mpLbBaseItem
->SelectEntryPos( SC_BASEITEM_USER_POS
);
324 sal_Int32 nStartPos
= mbEmptyItem
? (SC_BASEITEM_USER_POS
+ 1) : SC_BASEITEM_USER_POS
;
325 sal_Int32 nPos
= FindBaseItemPos( rFuncData
.maFieldRef
.ReferenceItemName
, nStartPos
);
326 if( nPos
>= mpLbBaseItem
->GetEntryCount() )
327 nPos
= (mpLbBaseItem
->GetEntryCount() > SC_BASEITEM_USER_POS
) ? SC_BASEITEM_USER_POS
: SC_BASEITEM_PREV_POS
;
328 mpLbBaseItem
->SelectEntryPos( nPos
);
334 const OUString
& ScDPFunctionDlg::GetBaseFieldName(const OUString
& rLayoutName
) const
336 NameMapType::const_iterator itr
= maBaseFieldNameMap
.find(rLayoutName
);
337 return itr
== maBaseFieldNameMap
.end() ? rLayoutName
: itr
->second
;
340 const OUString
& ScDPFunctionDlg::GetBaseItemName(const OUString
& rLayoutName
) const
342 NameMapType::const_iterator itr
= maBaseItemNameMap
.find(rLayoutName
);
343 return itr
== maBaseItemNameMap
.end() ? rLayoutName
: itr
->second
;
346 sal_Int32
ScDPFunctionDlg::FindBaseItemPos( const OUString
& rEntry
, sal_Int32 nStartPos
) const
348 sal_Int32 nPos
= nStartPos
;
350 while (nPos
< mpLbBaseItem
->GetEntryCount())
352 // translate the displayed field name back to its original field name.
353 const OUString
& rInName
= mpLbBaseItem
->GetEntry(nPos
);
354 const OUString
& rName
= GetBaseItemName(rInName
);
355 if (rName
.equals(rEntry
))
362 return bFound
? nPos
: LISTBOX_ENTRY_NOTFOUND
;
365 IMPL_LINK( ScDPFunctionDlg
, SelectHdl
, ListBox
*, pLBox
)
367 if( pLBox
== mpLbType
)
369 bool bEnableField
, bEnableItem
;
370 switch( mxLbTypeWrp
->GetControlValue() )
372 case DataPilotFieldReferenceType::ITEM_DIFFERENCE
:
373 case DataPilotFieldReferenceType::ITEM_PERCENTAGE
:
374 case DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE
:
375 bEnableField
= bEnableItem
= true;
378 case DataPilotFieldReferenceType::RUNNING_TOTAL
:
384 bEnableField
= bEnableItem
= false;
387 bEnableField
&= mpLbBaseField
->GetEntryCount() > 0;
388 mpFtBaseField
->Enable( bEnableField
);
389 mpLbBaseField
->Enable( bEnableField
);
391 bEnableItem
&= bEnableField
;
392 mpFtBaseItem
->Enable( bEnableItem
);
393 mpLbBaseItem
->Enable( bEnableItem
);
395 else if( pLBox
== mpLbBaseField
)
397 // keep "previous" and "next" entries
398 while( mpLbBaseItem
->GetEntryCount() > SC_BASEITEM_USER_POS
)
399 mpLbBaseItem
->RemoveEntry( SC_BASEITEM_USER_POS
);
401 // update item list for current base field
403 size_t nBasePos
= mpLbBaseField
->GetSelectEntryPos();
404 if( nBasePos
< mrLabelVec
.size() )
406 const vector
<ScDPLabelData::Member
>& rMembers
= mrLabelVec
[nBasePos
].maMembers
;
407 mbEmptyItem
= lclFillListBox(*mpLbBaseItem
, rMembers
, SC_BASEITEM_USER_POS
);
408 // build cache for base names.
410 vector
<ScDPLabelData::Member
>::const_iterator itr
= rMembers
.begin(), itrEnd
= rMembers
.end();
411 for (; itr
!= itrEnd
; ++itr
)
412 aMap
.insert(NameMapType::value_type(itr
->getDisplayName(), itr
->maName
));
413 maBaseItemNameMap
.swap(aMap
);
417 sal_uInt16 nItemPos
= (mpLbBaseItem
->GetEntryCount() > SC_BASEITEM_USER_POS
) ? SC_BASEITEM_USER_POS
: SC_BASEITEM_PREV_POS
;
418 mpLbBaseItem
->SelectEntryPos( nItemPos
);
423 IMPL_LINK_NOARG(ScDPFunctionDlg
, DblClickHdl
)
429 ScDPSubtotalDlg::ScDPSubtotalDlg( vcl::Window
* pParent
, ScDPObject
& rDPObj
,
430 const ScDPLabelData
& rLabelData
, const ScPivotFuncData
& rFuncData
,
431 const ScDPNameVec
& rDataFields
, bool bEnableLayout
)
432 : ModalDialog(pParent
, "PivotFieldDialog",
433 "modules/scalc/ui/pivotfielddialog.ui")
435 , mrDataFields(rDataFields
)
436 , maLabelData(rLabelData
)
437 , mbEnableLayout(bEnableLayout
)
440 get(mpBtnOptions
, "options");
441 get(mpCbShowAll
, "showall");
442 get(mpFtName
, "name");
443 get(mpLbFunc
, "functions");
444 mpLbFunc
->EnableMultiSelection(true);
445 mpLbFunc
->set_height_request(mpLbFunc
->GetTextHeight() * 8);
446 get(mpRbNone
, "none");
447 get(mpRbAuto
, "auto");
448 get(mpRbUser
, "user");
450 Init( rLabelData
, rFuncData
);
453 ScDPSubtotalDlg::~ScDPSubtotalDlg()
458 void ScDPSubtotalDlg::dispose()
467 mpBtnOptions
.clear();
468 ModalDialog::dispose();
471 sal_uInt16
ScDPSubtotalDlg::GetFuncMask() const
473 sal_uInt16 nFuncMask
= PIVOT_FUNC_NONE
;
475 if( mpRbAuto
->IsChecked() )
476 nFuncMask
= PIVOT_FUNC_AUTO
;
477 else if( mpRbUser
->IsChecked() )
478 nFuncMask
= mpLbFunc
->GetSelection();
483 void ScDPSubtotalDlg::FillLabelData( ScDPLabelData
& rLabelData
) const
485 rLabelData
.mnFuncMask
= GetFuncMask();
486 rLabelData
.mnUsedHier
= maLabelData
.mnUsedHier
;
487 rLabelData
.mbShowAll
= mpCbShowAll
->IsChecked();
488 rLabelData
.maMembers
= maLabelData
.maMembers
;
489 rLabelData
.maSortInfo
= maLabelData
.maSortInfo
;
490 rLabelData
.maLayoutInfo
= maLabelData
.maLayoutInfo
;
491 rLabelData
.maShowInfo
= maLabelData
.maShowInfo
;
492 rLabelData
.mbRepeatItemLabels
= maLabelData
.mbRepeatItemLabels
;
495 void ScDPSubtotalDlg::Init( const ScDPLabelData
& rLabelData
, const ScPivotFuncData
& rFuncData
)
498 mpFtName
->SetText(rLabelData
.getDisplayName());
501 mpRbNone
->SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
502 mpRbAuto
->SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
503 mpRbUser
->SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
505 RadioButton
* pRBtn
= 0;
506 switch( rFuncData
.mnFuncMask
)
508 case PIVOT_FUNC_NONE
: pRBtn
= mpRbNone
; break;
509 case PIVOT_FUNC_AUTO
: pRBtn
= mpRbAuto
; break;
510 default: pRBtn
= mpRbUser
;
513 RadioClickHdl( pRBtn
);
516 mpLbFunc
->SetSelection( rFuncData
.mnFuncMask
);
517 mpLbFunc
->SetDoubleClickHdl( LINK( this, ScDPSubtotalDlg
, DblClickHdl
) );
520 mpCbShowAll
->Check( rLabelData
.mbShowAll
);
523 mpBtnOptions
->SetClickHdl( LINK( this, ScDPSubtotalDlg
, ClickHdl
) );
526 IMPL_LINK( ScDPSubtotalDlg
, RadioClickHdl
, RadioButton
*, pBtn
)
528 mpLbFunc
->Enable( pBtn
== mpRbUser
);
532 IMPL_LINK_NOARG(ScDPSubtotalDlg
, DblClickHdl
)
538 IMPL_LINK( ScDPSubtotalDlg
, ClickHdl
, PushButton
*, pBtn
)
540 if (pBtn
== mpBtnOptions
)
542 VclPtrInstance
< ScDPSubtotalOptDlg
> pDlg( this, mrDPObj
, maLabelData
, mrDataFields
, mbEnableLayout
);
543 if( pDlg
->Execute() == RET_OK
)
544 pDlg
->FillLabelData( maLabelData
);
549 ScDPSubtotalOptDlg::ScDPSubtotalOptDlg( vcl::Window
* pParent
, ScDPObject
& rDPObj
,
550 const ScDPLabelData
& rLabelData
, const ScDPNameVec
& rDataFields
,
552 : ModalDialog(pParent
, "DataFieldOptionsDialog",
553 "modules/scalc/ui/datafieldoptionsdialog.ui")
555 , maLabelData(rLabelData
)
557 get(m_pLbSortBy
, "sortby");
558 m_pLbSortBy
->set_width_request(m_pLbSortBy
->approximate_char_width() * 20);
559 get(m_pRbSortAsc
, "ascending");
560 get(m_pRbSortDesc
, "descending");
561 get(m_pRbSortMan
, "manual");
562 get(m_pLayoutFrame
, "layoutframe");
563 get(m_pLbLayout
, "layout");
564 get(m_pCbLayoutEmpty
, "emptyline");
565 get(m_pCbRepeatItemLabels
, "repeatitemlabels");
566 get(m_pCbShow
, "show");
567 get(m_pNfShow
, "items");
568 get(m_pFtShow
, "showft");
569 get(m_pFtShowFrom
, "showfromft");
570 get(m_pLbShowFrom
, "from");
571 get(m_pFtShowUsing
, "usingft");
572 get(m_pLbShowUsing
, "using");
573 get(m_pHideFrame
, "hideframe");
574 get(m_pLbHide
, "hideitems");
575 m_pLbHide
->set_height_request(GetTextHeight() * 5);
576 get(m_pFtHierarchy
, "hierarchyft");
577 get(m_pLbHierarchy
, "hierarchy");
579 m_xLbLayoutWrp
.reset(new ScDPListBoxWrapper(*m_pLbLayout
, spLayoutMap
));
580 m_xLbShowFromWrp
.reset(new ScDPListBoxWrapper(*m_pLbShowFrom
, spShowFromMap
));
582 Init( rDataFields
, bEnableLayout
);
585 ScDPSubtotalOptDlg::~ScDPSubtotalOptDlg()
590 void ScDPSubtotalOptDlg::dispose()
593 m_pRbSortAsc
.clear();
594 m_pRbSortDesc
.clear();
595 m_pRbSortMan
.clear();
596 m_pLayoutFrame
.clear();
598 m_pCbLayoutEmpty
.clear();
599 m_pCbRepeatItemLabels
.clear();
603 m_pFtShowFrom
.clear();
604 m_pLbShowFrom
.clear();
605 m_pFtShowUsing
.clear();
606 m_pLbShowUsing
.clear();
607 m_pHideFrame
.clear();
609 m_pFtHierarchy
.clear();
610 m_pLbHierarchy
.clear();
611 ModalDialog::dispose();
614 void ScDPSubtotalOptDlg::FillLabelData( ScDPLabelData
& rLabelData
) const
618 if( m_pRbSortMan
->IsChecked() )
619 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::MANUAL
;
620 else if( m_pLbSortBy
->GetSelectEntryPos() == SC_SORTNAME_POS
)
621 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::NAME
;
623 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::DATA
;
625 ScDPName aFieldName
= GetFieldName(m_pLbSortBy
->GetSelectEntry());
626 if (!aFieldName
.maName
.isEmpty())
628 rLabelData
.maSortInfo
.Field
=
629 ScDPUtil::createDuplicateDimensionName(aFieldName
.maName
, aFieldName
.mnDupCount
);
630 rLabelData
.maSortInfo
.IsAscending
= m_pRbSortAsc
->IsChecked();
633 // *** LAYOUT MODE ***
635 rLabelData
.maLayoutInfo
.LayoutMode
= m_xLbLayoutWrp
->GetControlValue();
636 rLabelData
.maLayoutInfo
.AddEmptyLines
= m_pCbLayoutEmpty
->IsChecked();
637 rLabelData
.mbRepeatItemLabels
= m_pCbRepeatItemLabels
->IsChecked();
641 aFieldName
= GetFieldName(m_pLbShowUsing
->GetSelectEntry());
642 if (!aFieldName
.maName
.isEmpty())
644 rLabelData
.maShowInfo
.IsEnabled
= m_pCbShow
->IsChecked();
645 rLabelData
.maShowInfo
.ShowItemsMode
= m_xLbShowFromWrp
->GetControlValue();
646 rLabelData
.maShowInfo
.ItemCount
= sal::static_int_cast
<sal_Int32
>( m_pNfShow
->GetValue() );
647 rLabelData
.maShowInfo
.DataField
=
648 ScDPUtil::createDuplicateDimensionName(aFieldName
.maName
, aFieldName
.mnDupCount
);
651 // *** HIDDEN ITEMS ***
653 rLabelData
.maMembers
= maLabelData
.maMembers
;
654 sal_uLong nVisCount
= m_pLbHide
->GetEntryCount();
655 for( sal_uInt16 nPos
= 0; nPos
< nVisCount
; ++nPos
)
656 rLabelData
.maMembers
[nPos
].mbVisible
= !m_pLbHide
->IsChecked(nPos
);
660 rLabelData
.mnUsedHier
= m_pLbHierarchy
->GetSelectEntryCount() ? m_pLbHierarchy
->GetSelectEntryPos() : 0;
663 void ScDPSubtotalOptDlg::Init( const ScDPNameVec
& rDataFields
, bool bEnableLayout
)
667 sal_Int32 nSortMode
= maLabelData
.maSortInfo
.Mode
;
669 // sort fields list box
670 m_pLbSortBy
->InsertEntry(maLabelData
.getDisplayName());
672 for( ScDPNameVec::const_iterator aIt
= rDataFields
.begin(), aEnd
= rDataFields
.end(); aIt
!= aEnd
; ++aIt
)
674 // Cache names for later lookup.
675 maDataFieldNameMap
.insert(NameMapType::value_type(aIt
->maLayoutName
, *aIt
));
677 m_pLbSortBy
->InsertEntry( aIt
->maLayoutName
);
678 m_pLbShowUsing
->InsertEntry( aIt
->maLayoutName
); // for AutoShow
681 if( m_pLbSortBy
->GetEntryCount() > SC_SORTDATA_POS
)
682 m_pLbSortBy
->SetSeparatorPos( SC_SORTDATA_POS
- 1 );
684 sal_Int32 nSortPos
= SC_SORTNAME_POS
;
685 if( nSortMode
== DataPilotFieldSortMode::DATA
)
687 nSortPos
= FindListBoxEntry( *m_pLbSortBy
, maLabelData
.maSortInfo
.Field
, SC_SORTDATA_POS
);
688 if( nSortPos
>= m_pLbSortBy
->GetEntryCount() )
690 nSortPos
= SC_SORTNAME_POS
;
691 nSortMode
= DataPilotFieldSortMode::MANUAL
;
694 m_pLbSortBy
->SelectEntryPos( nSortPos
);
697 m_pRbSortAsc
->SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
698 m_pRbSortDesc
->SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
699 m_pRbSortMan
->SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
701 RadioButton
* pRBtn
= 0;
704 case DataPilotFieldSortMode::NONE
:
705 case DataPilotFieldSortMode::MANUAL
:
706 pRBtn
= m_pRbSortMan
;
709 pRBtn
= maLabelData
.maSortInfo
.IsAscending
? m_pRbSortAsc
: m_pRbSortDesc
;
712 RadioClickHdl( pRBtn
);
714 // *** LAYOUT MODE ***
716 m_pLayoutFrame
->Enable(bEnableLayout
);
718 m_xLbLayoutWrp
->SetControlValue( maLabelData
.maLayoutInfo
.LayoutMode
);
719 m_pCbLayoutEmpty
->Check( maLabelData
.maLayoutInfo
.AddEmptyLines
);
720 m_pCbRepeatItemLabels
->Check( maLabelData
.mbRepeatItemLabels
);
724 m_pCbShow
->Check( maLabelData
.maShowInfo
.IsEnabled
);
725 m_pCbShow
->SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, CheckHdl
) );
727 m_xLbShowFromWrp
->SetControlValue( maLabelData
.maShowInfo
.ShowItemsMode
);
728 long nCount
= static_cast< long >( maLabelData
.maShowInfo
.ItemCount
);
730 nCount
= SC_SHOW_DEFAULT
;
731 m_pNfShow
->SetValue( nCount
);
733 // m_pLbShowUsing already filled above
734 m_pLbShowUsing
->SelectEntry( maLabelData
.maShowInfo
.DataField
);
735 if( m_pLbShowUsing
->GetSelectEntryPos() >= m_pLbShowUsing
->GetEntryCount() )
736 m_pLbShowUsing
->SelectEntryPos( 0 );
738 CheckHdl(m_pCbShow
); // enable/disable dependent controls
740 // *** HIDDEN ITEMS ***
746 if( maLabelData
.maHiers
.getLength() > 1 )
748 lclFillListBox( *m_pLbHierarchy
, maLabelData
.maHiers
);
749 sal_Int32 nHier
= maLabelData
.mnUsedHier
;
750 if( (nHier
< 0) || (nHier
>= maLabelData
.maHiers
.getLength()) ) nHier
= 0;
751 m_pLbHierarchy
->SelectEntryPos( static_cast< sal_Int32
>( nHier
) );
752 m_pLbHierarchy
->SetSelectHdl( LINK( this, ScDPSubtotalOptDlg
, SelectHdl
) );
756 m_pFtHierarchy
->Disable();
757 m_pLbHierarchy
->Disable();
761 void ScDPSubtotalOptDlg::InitHideListBox()
764 lclFillListBox( *m_pLbHide
, maLabelData
.maMembers
);
765 size_t n
= maLabelData
.maMembers
.size();
766 for (sal_uLong i
= 0; i
< n
; ++i
)
767 m_pLbHide
->CheckEntryPos(i
, !maLabelData
.maMembers
[i
].mbVisible
);
768 bool bEnable
= m_pLbHide
->GetEntryCount() > 0;
769 m_pHideFrame
->Enable(bEnable
);
772 ScDPName
ScDPSubtotalOptDlg::GetFieldName(const OUString
& rLayoutName
) const
774 NameMapType::const_iterator itr
= maDataFieldNameMap
.find(rLayoutName
);
775 return itr
== maDataFieldNameMap
.end() ? ScDPName() : itr
->second
;
778 sal_Int32
ScDPSubtotalOptDlg::FindListBoxEntry(
779 const ListBox
& rLBox
, const OUString
& rEntry
, sal_Int32 nStartPos
) const
781 sal_Int32 nPos
= nStartPos
;
783 while (nPos
< rLBox
.GetEntryCount())
785 // translate the displayed field name back to its original field name.
786 ScDPName aName
= GetFieldName(rLBox
.GetEntry(nPos
));
787 OUString aUnoName
= ScDPUtil::createDuplicateDimensionName(aName
.maName
, aName
.mnDupCount
);
788 if (aUnoName
.equals(rEntry
))
795 return bFound
? nPos
: LISTBOX_ENTRY_NOTFOUND
;
798 IMPL_LINK( ScDPSubtotalOptDlg
, RadioClickHdl
, RadioButton
*, pBtn
)
800 m_pLbSortBy
->Enable( pBtn
!= m_pRbSortMan
);
804 IMPL_LINK( ScDPSubtotalOptDlg
, CheckHdl
, CheckBox
*, pCBox
)
806 if (pCBox
== m_pCbShow
)
808 bool bEnable
= m_pCbShow
->IsChecked();
809 m_pNfShow
->Enable( bEnable
);
810 m_pFtShow
->Enable( bEnable
);
811 m_pFtShowFrom
->Enable( bEnable
);
812 m_pLbShowFrom
->Enable( bEnable
);
814 bool bEnableUsing
= bEnable
&& (m_pLbShowUsing
->GetEntryCount() > 0);
815 m_pFtShowUsing
->Enable(bEnableUsing
);
816 m_pLbShowUsing
->Enable(bEnableUsing
);
821 IMPL_LINK( ScDPSubtotalOptDlg
, SelectHdl
, ListBox
*, pLBox
)
823 if (pLBox
== m_pLbHierarchy
)
825 mrDPObj
.GetMembers(maLabelData
.mnCol
, m_pLbHierarchy
->GetSelectEntryPos(), maLabelData
.maMembers
);
831 ScDPShowDetailDlg::ScDPShowDetailDlg( vcl::Window
* pParent
, ScDPObject
& rDPObj
, sal_uInt16 nOrient
) :
832 ModalDialog ( pParent
, "ShowDetail", "modules/scalc/ui/showdetaildialog.ui" ),
835 get(mpLbDims
, "dimsTreeview");
838 ScDPSaveData
* pSaveData
= rDPObj
.GetSaveData();
839 long nDimCount
= rDPObj
.GetDimCount();
840 for (long nDim
=0; nDim
<nDimCount
; nDim
++)
843 sal_Int32 nDimFlags
= 0;
844 OUString aName
= rDPObj
.GetDimName( nDim
, bIsDataLayout
, &nDimFlags
);
845 if ( !bIsDataLayout
&& !rDPObj
.IsDuplicated( nDim
) && ScDPObject::IsOrientationAllowed( nOrient
, nDimFlags
) )
847 const ScDPSaveDimension
* pDimension
= pSaveData
? pSaveData
->GetExistingDimensionByName(aName
) : 0;
848 if ( !pDimension
|| (pDimension
->GetOrientation() != nOrient
) )
852 const OUString
* pLayoutName
= pDimension
->GetLayoutName();
854 aName
= *pLayoutName
;
856 mpLbDims
->InsertEntry( aName
);
857 maNameIndexMap
.insert(DimNameIndexMap::value_type(aName
, nDim
));
861 if( mpLbDims
->GetEntryCount() )
862 mpLbDims
->SelectEntryPos( 0 );
864 mpLbDims
->SetDoubleClickHdl( LINK( this, ScDPShowDetailDlg
, DblClickHdl
) );
867 ScDPShowDetailDlg::~ScDPShowDetailDlg()
872 void ScDPShowDetailDlg::dispose()
876 ModalDialog::dispose();
879 short ScDPShowDetailDlg::Execute()
881 return mpLbDims
->GetEntryCount() ? ModalDialog::Execute() : static_cast<short>(RET_CANCEL
);
884 OUString
ScDPShowDetailDlg::GetDimensionName() const
886 // Look up the internal dimension name which may be different from the
887 // displayed field name.
888 OUString aSelectedName
= mpLbDims
->GetSelectEntry();
889 DimNameIndexMap::const_iterator itr
= maNameIndexMap
.find(aSelectedName
);
890 if (itr
== maNameIndexMap
.end())
891 // This should never happen!
892 return aSelectedName
;
894 long nDim
= itr
->second
;
895 bool bIsDataLayout
= false;
896 return mrDPObj
.GetDimName(nDim
, bIsDataLayout
);
899 IMPL_LINK( ScDPShowDetailDlg
, DblClickHdl
, ListBox
*, pLBox
)
901 if( pLBox
== mpLbDims
)
906 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */