1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pvfundlg.cxx,v $
10 * $Revision: 1.12.32.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include "pvfundlg.hxx"
36 #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
37 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
38 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp>
39 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp>
40 #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp>
42 #include <tools/resary.hxx>
43 #include <vcl/msgbox.hxx>
45 #include "scresid.hxx"
46 #include "dpobject.hxx"
48 #include "pvfundlg.hrc"
49 #include "globstr.hrc"
53 // ============================================================================
55 using namespace ::com::sun::star::sheet
;
57 using ::rtl::OUString
;
58 using ::com::sun::star::uno::Sequence
;
61 // ============================================================================
65 /** Appends all strings from the Sequence to the list box.
67 Empty strings are replaced by a localized "(empty)" entry and inserted at
68 the specified position.
70 @return true = The passed string list contains an empty string entry.
72 template< typename ListBoxType
>
73 bool lclFillListBox( ListBoxType
& rLBox
, const Sequence
< OUString
>& rStrings
, USHORT nEmptyPos
= LISTBOX_APPEND
)
76 if( const OUString
* pStr
= rStrings
.getConstArray() )
78 for( const OUString
* pEnd
= pStr
+ rStrings
.getLength(); pStr
!= pEnd
; ++pStr
)
80 if( pStr
->getLength() )
81 rLBox
.InsertEntry( *pStr
);
84 rLBox
.InsertEntry( ScGlobal::GetRscString( STR_EMPTYDATA
), nEmptyPos
);
92 template< typename ListBoxType
>
93 bool lclFillListBox( ListBoxType
& rLBox
, const vector
<ScDPLabelData::Member
>& rMembers
, USHORT nEmptyPos
= LISTBOX_APPEND
)
96 vector
<ScDPLabelData::Member
>::const_iterator itr
= rMembers
.begin(), itrEnd
= rMembers
.end();
97 for (; itr
!= itrEnd
; ++itr
)
99 OUString aName
= itr
->getDisplayName();
100 if (aName
.getLength())
101 rLBox
.InsertEntry(aName
);
104 rLBox
.InsertEntry(ScGlobal::GetRscString(STR_EMPTYDATA
), nEmptyPos
);
111 /** Searches for a listbox entry, starts search at specified position. */
112 USHORT
lclFindListBoxEntry( const ListBox
& rLBox
, const String
& rEntry
, USHORT nStartPos
)
114 USHORT nPos
= nStartPos
;
115 while( (nPos
< rLBox
.GetEntryCount()) && (rLBox
.GetEntry( nPos
) != rEntry
) )
117 return (nPos
< rLBox
.GetEntryCount()) ? nPos
: LISTBOX_ENTRY_NOTFOUND
;
120 /** This table represents the order of the strings in the resource string array. */
121 static const USHORT spnFunctions
[] =
129 PIVOT_FUNC_COUNT_NUM
,
136 const USHORT SC_BASEITEM_PREV_POS
= 0;
137 const USHORT SC_BASEITEM_NEXT_POS
= 1;
138 const USHORT SC_BASEITEM_USER_POS
= 2;
140 const USHORT SC_SORTNAME_POS
= 0;
141 const USHORT SC_SORTDATA_POS
= 1;
143 const long SC_SHOW_DEFAULT
= 10;
145 static const ScDPListBoxWrapper::MapEntryType spRefTypeMap
[] =
147 { 0, DataPilotFieldReferenceType::NONE
},
148 { 1, DataPilotFieldReferenceType::ITEM_DIFFERENCE
},
149 { 2, DataPilotFieldReferenceType::ITEM_PERCENTAGE
},
150 { 3, DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE
},
151 { 4, DataPilotFieldReferenceType::RUNNING_TOTAL
},
152 { 5, DataPilotFieldReferenceType::ROW_PERCENTAGE
},
153 { 6, DataPilotFieldReferenceType::COLUMN_PERCENTAGE
},
154 { 7, DataPilotFieldReferenceType::TOTAL_PERCENTAGE
},
155 { 8, DataPilotFieldReferenceType::INDEX
},
156 { LISTBOX_ENTRY_NOTFOUND
, DataPilotFieldReferenceType::NONE
}
159 static const ScDPListBoxWrapper::MapEntryType spLayoutMap
[] =
161 { 0, DataPilotFieldLayoutMode::TABULAR_LAYOUT
},
162 { 1, DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP
},
163 { 2, DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM
},
164 { LISTBOX_ENTRY_NOTFOUND
, DataPilotFieldLayoutMode::TABULAR_LAYOUT
}
167 static const ScDPListBoxWrapper::MapEntryType spShowFromMap
[] =
169 { 0, DataPilotFieldShowItemsMode::FROM_TOP
},
170 { 1, DataPilotFieldShowItemsMode::FROM_BOTTOM
},
171 { LISTBOX_ENTRY_NOTFOUND
, DataPilotFieldShowItemsMode::FROM_TOP
}
176 // ============================================================================
178 ScDPFunctionListBox::ScDPFunctionListBox( Window
* pParent
, const ResId
& rResId
) :
179 MultiListBox( pParent
, rResId
)
184 void ScDPFunctionListBox::SetSelection( USHORT nFuncMask
)
186 if( (nFuncMask
== PIVOT_FUNC_NONE
) || (nFuncMask
== PIVOT_FUNC_AUTO
) )
189 for( USHORT nEntry
= 0, nCount
= GetEntryCount(); nEntry
< nCount
; ++nEntry
)
190 SelectEntryPos( nEntry
, (nFuncMask
& spnFunctions
[ nEntry
]) != 0 );
193 USHORT
ScDPFunctionListBox::GetSelection() const
195 USHORT nFuncMask
= PIVOT_FUNC_NONE
;
196 for( USHORT nSel
= 0, nCount
= GetSelectEntryCount(); nSel
< nCount
; ++nSel
)
197 nFuncMask
|= spnFunctions
[ GetSelectEntryPos( nSel
) ];
201 void ScDPFunctionListBox::FillFunctionNames()
203 DBG_ASSERT( !GetEntryCount(), "ScDPFunctionListBox::FillFunctionNames - do not add texts to resource" );
205 ResStringArray
aArr( ScResId( SCSTR_DPFUNCLISTBOX
) );
206 for( USHORT nIndex
= 0, nCount
= sal::static_int_cast
<USHORT
>(aArr
.Count()); nIndex
< nCount
; ++nIndex
)
207 InsertEntry( aArr
.GetString( nIndex
) );
210 // ============================================================================
212 ScDPFunctionDlg::ScDPFunctionDlg(
213 Window
* pParent
, const ScDPLabelDataVec
& rLabelVec
,
214 const ScDPLabelData
& rLabelData
, const ScDPFuncData
& rFuncData
) :
215 ModalDialog ( pParent
, ScResId( RID_SCDLG_DPDATAFIELD
) ),
216 maFlFunc ( this, ScResId( FL_FUNC
) ),
217 maLbFunc ( this, ScResId( LB_FUNC
) ),
218 maFtNameLabel ( this, ScResId( FT_NAMELABEL
) ),
219 maFtName ( this, ScResId( FT_NAME
) ),
220 maFlDisplay ( this, ScResId( FL_DISPLAY
) ),
221 maFtType ( this, ScResId( FT_TYPE
) ),
222 maLbType ( this, ScResId( LB_TYPE
) ),
223 maFtBaseField ( this, ScResId( FT_BASEFIELD
) ),
224 maLbBaseField ( this, ScResId( LB_BASEFIELD
) ),
225 maFtBaseItem ( this, ScResId( FT_BASEITEM
) ),
226 maLbBaseItem ( this, ScResId( LB_BASEITEM
) ),
227 maBtnOk ( this, ScResId( BTN_OK
) ),
228 maBtnCancel ( this, ScResId( BTN_CANCEL
) ),
229 maBtnHelp ( this, ScResId( BTN_HELP
) ),
230 maBtnMore ( this, ScResId( BTN_MORE
) ),
231 maLbTypeWrp ( maLbType
, spRefTypeMap
),
232 mrLabelVec ( rLabelVec
),
233 mbEmptyItem ( false )
236 Init( rLabelData
, rFuncData
);
239 USHORT
ScDPFunctionDlg::GetFuncMask() const
241 return maLbFunc
.GetSelection();
244 DataPilotFieldReference
ScDPFunctionDlg::GetFieldRef() const
246 DataPilotFieldReference aRef
;
248 aRef
.ReferenceType
= maLbTypeWrp
.GetControlValue();
249 aRef
.ReferenceField
= maLbBaseField
.GetSelectEntry();
251 USHORT nBaseItemPos
= maLbBaseItem
.GetSelectEntryPos();
252 switch( nBaseItemPos
)
254 case SC_BASEITEM_PREV_POS
:
255 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::PREVIOUS
;
257 case SC_BASEITEM_NEXT_POS
:
258 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::NEXT
;
262 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::NAMED
;
263 if( !mbEmptyItem
|| (nBaseItemPos
> SC_BASEITEM_USER_POS
) )
264 aRef
.ReferenceItemName
= maLbBaseItem
.GetSelectEntry();
271 void ScDPFunctionDlg::Init( const ScDPLabelData
& rLabelData
, const ScDPFuncData
& rFuncData
)
274 USHORT nFuncMask
= (rFuncData
.mnFuncMask
== PIVOT_FUNC_NONE
) ? PIVOT_FUNC_SUM
: rFuncData
.mnFuncMask
;
275 maLbFunc
.SetSelection( nFuncMask
);
278 maFtName
.SetText(rLabelData
.getDisplayName());
280 // "More button" controls
281 maBtnMore
.AddWindow( &maFlDisplay
);
282 maBtnMore
.AddWindow( &maFtType
);
283 maBtnMore
.AddWindow( &maLbType
);
284 maBtnMore
.AddWindow( &maFtBaseField
);
285 maBtnMore
.AddWindow( &maLbBaseField
);
286 maBtnMore
.AddWindow( &maFtBaseItem
);
287 maBtnMore
.AddWindow( &maLbBaseItem
);
290 maLbFunc
.SetDoubleClickHdl( LINK( this, ScDPFunctionDlg
, DblClickHdl
) );
291 maLbType
.SetSelectHdl( LINK( this, ScDPFunctionDlg
, SelectHdl
) );
292 maLbBaseField
.SetSelectHdl( LINK( this, ScDPFunctionDlg
, SelectHdl
) );
294 // base field list box
295 for( ScDPLabelDataVec::const_iterator aIt
= mrLabelVec
.begin(), aEnd
= mrLabelVec
.end(); aIt
!= aEnd
; ++aIt
)
296 maLbBaseField
.InsertEntry(aIt
->getDisplayName());
298 // base item list box
299 maLbBaseItem
.SetSeparatorPos( SC_BASEITEM_USER_POS
- 1 );
301 // select field reference type
302 maLbTypeWrp
.SetControlValue( rFuncData
.maFieldRef
.ReferenceType
);
303 SelectHdl( &maLbType
); // enables base field/item list boxes
306 maLbBaseField
.SelectEntry( rFuncData
.maFieldRef
.ReferenceField
);
307 if( maLbBaseField
.GetSelectEntryPos() >= maLbBaseField
.GetEntryCount() )
308 maLbBaseField
.SelectEntryPos( 0 );
309 SelectHdl( &maLbBaseField
); // fills base item list, selects base item
312 switch( rFuncData
.maFieldRef
.ReferenceItemType
)
314 case DataPilotFieldReferenceItemType::PREVIOUS
:
315 maLbBaseItem
.SelectEntryPos( SC_BASEITEM_PREV_POS
);
317 case DataPilotFieldReferenceItemType::NEXT
:
318 maLbBaseItem
.SelectEntryPos( SC_BASEITEM_NEXT_POS
);
322 if( mbEmptyItem
&& !rFuncData
.maFieldRef
.ReferenceItemName
.getLength() )
324 // select special "(empty)" entry added before other items
325 maLbBaseItem
.SelectEntryPos( SC_BASEITEM_USER_POS
);
329 USHORT nStartPos
= mbEmptyItem
? (SC_BASEITEM_USER_POS
+ 1) : SC_BASEITEM_USER_POS
;
330 USHORT nPos
= lclFindListBoxEntry( maLbBaseItem
, rFuncData
.maFieldRef
.ReferenceItemName
, nStartPos
);
331 if( nPos
>= maLbBaseItem
.GetEntryCount() )
332 nPos
= (maLbBaseItem
.GetEntryCount() > SC_BASEITEM_USER_POS
) ? SC_BASEITEM_USER_POS
: SC_BASEITEM_PREV_POS
;
333 maLbBaseItem
.SelectEntryPos( nPos
);
339 IMPL_LINK( ScDPFunctionDlg
, SelectHdl
, ListBox
*, pLBox
)
341 if( pLBox
== &maLbType
)
343 bool bEnableField
, bEnableItem
;
344 switch( maLbTypeWrp
.GetControlValue() )
346 case DataPilotFieldReferenceType::ITEM_DIFFERENCE
:
347 case DataPilotFieldReferenceType::ITEM_PERCENTAGE
:
348 case DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE
:
349 bEnableField
= bEnableItem
= true;
352 case DataPilotFieldReferenceType::RUNNING_TOTAL
:
358 bEnableField
= bEnableItem
= false;
361 bEnableField
&= maLbBaseField
.GetEntryCount() > 0;
362 maFtBaseField
.Enable( bEnableField
);
363 maLbBaseField
.Enable( bEnableField
);
365 bEnableItem
&= bEnableField
;
366 maFtBaseItem
.Enable( bEnableItem
);
367 maLbBaseItem
.Enable( bEnableItem
);
369 else if( pLBox
== &maLbBaseField
)
371 // keep "previous" and "next" entries
372 while( maLbBaseItem
.GetEntryCount() > SC_BASEITEM_USER_POS
)
373 maLbBaseItem
.RemoveEntry( SC_BASEITEM_USER_POS
);
375 // update item list for current base field
377 size_t nBasePos
= maLbBaseField
.GetSelectEntryPos();
378 if( nBasePos
< mrLabelVec
.size() )
379 mbEmptyItem
= lclFillListBox( maLbBaseItem
, mrLabelVec
[ nBasePos
].maMembers
, SC_BASEITEM_USER_POS
);
382 USHORT nItemPos
= (maLbBaseItem
.GetEntryCount() > SC_BASEITEM_USER_POS
) ? SC_BASEITEM_USER_POS
: SC_BASEITEM_PREV_POS
;
383 maLbBaseItem
.SelectEntryPos( nItemPos
);
388 IMPL_LINK( ScDPFunctionDlg
, DblClickHdl
, MultiListBox
*, EMPTYARG
)
394 // ============================================================================
396 ScDPSubtotalDlg::ScDPSubtotalDlg( Window
* pParent
, ScDPObject
& rDPObj
,
397 const ScDPLabelData
& rLabelData
, const ScDPFuncData
& rFuncData
,
398 const ScDPNameVec
& rDataFields
, bool bEnableLayout
) :
399 ModalDialog ( pParent
, ScResId( RID_SCDLG_PIVOTSUBT
) ),
400 maFlSubt ( this, ScResId( FL_FUNC
) ),
401 maRbNone ( this, ScResId( RB_NONE
) ),
402 maRbAuto ( this, ScResId( RB_AUTO
) ),
403 maRbUser ( this, ScResId( RB_USER
) ),
404 maLbFunc ( this, ScResId( LB_FUNC
) ),
405 maFtNameLabel ( this, ScResId( FT_NAMELABEL
) ),
406 maFtName ( this, ScResId( FT_NAME
) ),
407 maCbShowAll ( this, ScResId( CB_SHOWALL
) ),
408 maBtnOk ( this, ScResId( BTN_OK
) ),
409 maBtnCancel ( this, ScResId( BTN_CANCEL
) ),
410 maBtnHelp ( this, ScResId( BTN_HELP
) ),
411 maBtnOptions ( this, ScResId( BTN_OPTIONS
) ),
413 mrDataFields ( rDataFields
),
414 maLabelData ( rLabelData
),
415 mbEnableLayout ( bEnableLayout
)
418 Init( rLabelData
, rFuncData
);
421 USHORT
ScDPSubtotalDlg::GetFuncMask() const
423 USHORT nFuncMask
= PIVOT_FUNC_NONE
;
425 if( maRbAuto
.IsChecked() )
426 nFuncMask
= PIVOT_FUNC_AUTO
;
427 else if( maRbUser
.IsChecked() )
428 nFuncMask
= maLbFunc
.GetSelection();
433 void ScDPSubtotalDlg::FillLabelData( ScDPLabelData
& rLabelData
) const
435 rLabelData
.mnFuncMask
= GetFuncMask();
436 rLabelData
.mnUsedHier
= maLabelData
.mnUsedHier
;
437 rLabelData
.mbShowAll
= maCbShowAll
.IsChecked();
438 rLabelData
.maMembers
= maLabelData
.maMembers
;
439 rLabelData
.maSortInfo
= maLabelData
.maSortInfo
;
440 rLabelData
.maLayoutInfo
= maLabelData
.maLayoutInfo
;
441 rLabelData
.maShowInfo
= maLabelData
.maShowInfo
;
444 void ScDPSubtotalDlg::Init( const ScDPLabelData
& rLabelData
, const ScDPFuncData
& rFuncData
)
447 maFtName
.SetText(rLabelData
.getDisplayName());
450 maRbNone
.SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
451 maRbAuto
.SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
452 maRbUser
.SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
454 RadioButton
* pRBtn
= 0;
455 switch( rFuncData
.mnFuncMask
)
457 case PIVOT_FUNC_NONE
: pRBtn
= &maRbNone
; break;
458 case PIVOT_FUNC_AUTO
: pRBtn
= &maRbAuto
; break;
459 default: pRBtn
= &maRbUser
;
462 RadioClickHdl( pRBtn
);
465 maLbFunc
.SetSelection( rFuncData
.mnFuncMask
);
466 maLbFunc
.SetDoubleClickHdl( LINK( this, ScDPSubtotalDlg
, DblClickHdl
) );
469 maCbShowAll
.Check( rLabelData
.mbShowAll
);
472 maBtnOptions
.SetClickHdl( LINK( this, ScDPSubtotalDlg
, ClickHdl
) );
475 // ----------------------------------------------------------------------------
477 IMPL_LINK( ScDPSubtotalDlg
, RadioClickHdl
, RadioButton
*, pBtn
)
479 maLbFunc
.Enable( pBtn
== &maRbUser
);
483 IMPL_LINK( ScDPSubtotalDlg
, DblClickHdl
, MultiListBox
*, EMPTYARG
)
489 IMPL_LINK( ScDPSubtotalDlg
, ClickHdl
, PushButton
*, pBtn
)
491 if( pBtn
== &maBtnOptions
)
493 ScDPSubtotalOptDlg
* pDlg
= new ScDPSubtotalOptDlg( this, mrDPObj
, maLabelData
, mrDataFields
, mbEnableLayout
);
494 if( pDlg
->Execute() == RET_OK
)
495 pDlg
->FillLabelData( maLabelData
);
501 // ============================================================================
503 ScDPSubtotalOptDlg::ScDPSubtotalOptDlg( Window
* pParent
, ScDPObject
& rDPObj
,
504 const ScDPLabelData
& rLabelData
, const ScDPNameVec
& rDataFields
,
505 bool bEnableLayout
) :
506 ModalDialog ( pParent
, ScResId( RID_SCDLG_DPSUBTOTAL_OPT
) ),
507 maFlSortBy ( this, ScResId( FL_SORT_BY
) ),
508 maLbSortBy ( this, ScResId( LB_SORT_BY
) ),
509 maRbSortAsc ( this, ScResId( RB_SORT_ASC
) ),
510 maRbSortDesc ( this, ScResId( RB_SORT_DESC
) ),
511 maRbSortMan ( this, ScResId( RB_SORT_MAN
) ),
512 maFlLayout ( this, ScResId( FL_LAYOUT
) ),
513 maFtLayout ( this, ScResId( FT_LAYOUT
) ),
514 maLbLayout ( this, ScResId( LB_LAYOUT
) ),
515 maCbLayoutEmpty ( this, ScResId( CB_LAYOUT_EMPTY
) ),
516 maFlAutoShow ( this, ScResId( FL_AUTOSHOW
) ),
517 maCbShow ( this, ScResId( CB_SHOW
) ),
518 maNfShow ( this, ScResId( NF_SHOW
) ),
519 maFtShow ( this, ScResId( FT_SHOW
) ),
520 maFtShowFrom ( this, ScResId( FT_SHOW_FROM
) ),
521 maLbShowFrom ( this, ScResId( LB_SHOW_FROM
) ),
522 maFtShowUsing ( this, ScResId( FT_SHOW_USING
) ),
523 maLbShowUsing ( this, ScResId( LB_SHOW_USING
) ),
524 maFlHide ( this, ScResId( FL_HIDE
) ),
525 maLbHide ( this, ScResId( CT_HIDE
) ),
526 maFtHierarchy ( this, ScResId( FT_HIERARCHY
) ),
527 maLbHierarchy ( this, ScResId( LB_HIERARCHY
) ),
528 maBtnOk ( this, ScResId( BTN_OK
) ),
529 maBtnCancel ( this, ScResId( BTN_CANCEL
) ),
530 maBtnHelp ( this, ScResId( BTN_HELP
) ),
531 maLbLayoutWrp ( maLbLayout
, spLayoutMap
),
532 maLbShowFromWrp ( maLbShowFrom
, spShowFromMap
),
534 maLabelData ( rLabelData
)
537 Init( rDataFields
, bEnableLayout
);
540 void ScDPSubtotalOptDlg::FillLabelData( ScDPLabelData
& rLabelData
) const
544 if( maRbSortMan
.IsChecked() )
545 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::MANUAL
;
546 else if( maLbSortBy
.GetSelectEntryPos() == SC_SORTNAME_POS
)
547 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::NAME
;
549 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::DATA
;
551 rLabelData
.maSortInfo
.Field
= maLbSortBy
.GetSelectEntry();
552 rLabelData
.maSortInfo
.IsAscending
= maRbSortAsc
.IsChecked();
554 // *** LAYOUT MODE ***
556 rLabelData
.maLayoutInfo
.LayoutMode
= maLbLayoutWrp
.GetControlValue();
557 rLabelData
.maLayoutInfo
.AddEmptyLines
= maCbLayoutEmpty
.IsChecked();
561 rLabelData
.maShowInfo
.IsEnabled
= maCbShow
.IsChecked();
562 rLabelData
.maShowInfo
.ShowItemsMode
= maLbShowFromWrp
.GetControlValue();
563 rLabelData
.maShowInfo
.ItemCount
= sal::static_int_cast
<sal_Int32
>( maNfShow
.GetValue() );
564 rLabelData
.maShowInfo
.DataField
= maLbShowUsing
.GetSelectEntry();
566 // *** HIDDEN ITEMS ***
568 rLabelData
.maMembers
= maLabelData
.maMembers
;
569 ULONG nVisCount
= maLbHide
.GetEntryCount();
570 for( USHORT nPos
= 0; nPos
< nVisCount
; ++nPos
)
571 rLabelData
.maMembers
[nPos
].mbVisible
= !maLbHide
.IsChecked(nPos
);
575 rLabelData
.mnUsedHier
= maLbHierarchy
.GetSelectEntryCount() ? maLbHierarchy
.GetSelectEntryPos() : 0;
578 void ScDPSubtotalOptDlg::Init( const ScDPNameVec
& rDataFields
, bool bEnableLayout
)
582 sal_Int32 nSortMode
= maLabelData
.maSortInfo
.Mode
;
584 // sort fields list box
585 maLbSortBy
.InsertEntry(maLabelData
.getDisplayName());
587 for( ScDPNameVec::const_iterator aIt
= rDataFields
.begin(), aEnd
= rDataFields
.end(); aIt
!= aEnd
; ++aIt
)
589 maLbSortBy
.InsertEntry( *aIt
);
590 maLbShowUsing
.InsertEntry( *aIt
); // for AutoShow
592 if( maLbSortBy
.GetEntryCount() > SC_SORTDATA_POS
)
593 maLbSortBy
.SetSeparatorPos( SC_SORTDATA_POS
- 1 );
595 USHORT nSortPos
= SC_SORTNAME_POS
;
596 if( nSortMode
== DataPilotFieldSortMode::DATA
)
598 nSortPos
= lclFindListBoxEntry( maLbSortBy
, maLabelData
.maSortInfo
.Field
, SC_SORTDATA_POS
);
599 if( nSortPos
>= maLbSortBy
.GetEntryCount() )
601 nSortPos
= SC_SORTNAME_POS
;
602 nSortMode
= DataPilotFieldSortMode::MANUAL
;
605 maLbSortBy
.SelectEntryPos( nSortPos
);
608 maRbSortAsc
.SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
609 maRbSortDesc
.SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
610 maRbSortMan
.SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
612 RadioButton
* pRBtn
= 0;
615 case DataPilotFieldSortMode::NONE
:
616 case DataPilotFieldSortMode::MANUAL
:
617 pRBtn
= &maRbSortMan
;
620 pRBtn
= maLabelData
.maSortInfo
.IsAscending
? &maRbSortAsc
: &maRbSortDesc
;
623 RadioClickHdl( pRBtn
);
625 // *** LAYOUT MODE ***
627 maFlLayout
.Enable( bEnableLayout
);
628 maFtLayout
.Enable( bEnableLayout
);
629 maLbLayout
.Enable( bEnableLayout
);
630 maCbLayoutEmpty
.Enable( bEnableLayout
);
632 maLbLayoutWrp
.SetControlValue( maLabelData
.maLayoutInfo
.LayoutMode
);
633 maCbLayoutEmpty
.Check( maLabelData
.maLayoutInfo
.AddEmptyLines
);
637 maCbShow
.Check( maLabelData
.maShowInfo
.IsEnabled
);
638 maCbShow
.SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, CheckHdl
) );
640 maLbShowFromWrp
.SetControlValue( maLabelData
.maShowInfo
.ShowItemsMode
);
641 long nCount
= static_cast< long >( maLabelData
.maShowInfo
.ItemCount
);
643 nCount
= SC_SHOW_DEFAULT
;
644 maNfShow
.SetValue( nCount
);
646 // maLbShowUsing already filled above
647 maLbShowUsing
.SelectEntry( maLabelData
.maShowInfo
.DataField
);
648 if( maLbShowUsing
.GetSelectEntryPos() >= maLbShowUsing
.GetEntryCount() )
649 maLbShowUsing
.SelectEntryPos( 0 );
651 CheckHdl( &maCbShow
); // enable/disable dependent controls
653 // *** HIDDEN ITEMS ***
655 maLbHide
.SetHelpId( HID_SC_DPSUBT_HIDE
);
660 if( maLabelData
.maHiers
.getLength() > 1 )
662 lclFillListBox( maLbHierarchy
, maLabelData
.maHiers
);
663 sal_Int32 nHier
= maLabelData
.mnUsedHier
;
664 if( (nHier
< 0) || (nHier
>= maLabelData
.maHiers
.getLength()) ) nHier
= 0;
665 maLbHierarchy
.SelectEntryPos( static_cast< USHORT
>( nHier
) );
666 maLbHierarchy
.SetSelectHdl( LINK( this, ScDPSubtotalOptDlg
, SelectHdl
) );
670 maFtHierarchy
.Disable();
671 maLbHierarchy
.Disable();
675 void ScDPSubtotalOptDlg::InitHideListBox()
678 lclFillListBox( maLbHide
, maLabelData
.maMembers
);
679 size_t n
= maLabelData
.maMembers
.size();
680 for (size_t i
= 0; i
< n
; ++i
)
681 maLbHide
.CheckEntryPos(static_cast<USHORT
>(i
), !maLabelData
.maMembers
[i
].mbVisible
);
682 bool bEnable
= maLbHide
.GetEntryCount() > 0;
683 maFlHide
.Enable( bEnable
);
684 maLbHide
.Enable( bEnable
);
687 IMPL_LINK( ScDPSubtotalOptDlg
, RadioClickHdl
, RadioButton
*, pBtn
)
689 maLbSortBy
.Enable( pBtn
!= &maRbSortMan
);
693 IMPL_LINK( ScDPSubtotalOptDlg
, CheckHdl
, CheckBox
*, pCBox
)
695 if( pCBox
== &maCbShow
)
697 bool bEnable
= maCbShow
.IsChecked();
698 maNfShow
.Enable( bEnable
);
699 maFtShow
.Enable( bEnable
);
700 maFtShowFrom
.Enable( bEnable
);
701 maLbShowFrom
.Enable( bEnable
);
703 bool bEnableUsing
= bEnable
&& (maLbShowUsing
.GetEntryCount() > 0);
704 maFtShowUsing
.Enable( bEnableUsing
);
705 maLbShowUsing
.Enable( bEnableUsing
);
710 IMPL_LINK( ScDPSubtotalOptDlg
, SelectHdl
, ListBox
*, pLBox
)
712 if( pLBox
== &maLbHierarchy
)
714 mrDPObj
.GetMembers(maLabelData
.mnCol
, maLbHierarchy
.GetSelectEntryPos(), maLabelData
.maMembers
);
720 // ============================================================================
722 ScDPShowDetailDlg::ScDPShowDetailDlg( Window
* pParent
, ScDPObject
& rDPObj
, USHORT nOrient
) :
723 ModalDialog ( pParent
, ScResId( RID_SCDLG_DPSHOWDETAIL
) ),
724 maFtDims ( this, ScResId( FT_DIMS
) ),
725 maLbDims ( this, ScResId( LB_DIMS
) ),
726 maBtnOk ( this, ScResId( BTN_OK
) ),
727 maBtnCancel ( this, ScResId( BTN_CANCEL
) ),
728 maBtnHelp ( this, ScResId( BTN_HELP
) ),
734 ScDPSaveData
* pSaveData
= rDPObj
.GetSaveData();
735 long nDimCount
= rDPObj
.GetDimCount();
736 for (long nDim
=0; nDim
<nDimCount
; nDim
++)
739 String aName
= rDPObj
.GetDimName( nDim
, bIsDataLayout
);
740 if ( !bIsDataLayout
&& !rDPObj
.IsDuplicated( nDim
) )
742 const ScDPSaveDimension
* pDimension
= pSaveData
? pSaveData
->GetExistingDimensionByName(aName
) : 0;
743 if ( !pDimension
|| (pDimension
->GetOrientation() != nOrient
) )
745 const OUString
* pLayoutName
= pDimension
->GetLayoutName();
747 aName
= *pLayoutName
;
748 maLbDims
.InsertEntry( aName
);
749 maNameIndexMap
.insert(DimNameIndexMap::value_type(aName
, nDim
));
753 if( maLbDims
.GetEntryCount() )
754 maLbDims
.SelectEntryPos( 0 );
756 maLbDims
.SetDoubleClickHdl( LINK( this, ScDPShowDetailDlg
, DblClickHdl
) );
759 short ScDPShowDetailDlg::Execute()
761 return maLbDims
.GetEntryCount() ? ModalDialog::Execute() : RET_CANCEL
;
764 String
ScDPShowDetailDlg::GetDimensionName() const
766 // Look up the internal dimension name which may be different from the
767 // displayed field name.
768 String aSelectedName
= maLbDims
.GetSelectEntry();
769 DimNameIndexMap::const_iterator itr
= maNameIndexMap
.find(aSelectedName
);
770 if (itr
== maNameIndexMap
.end())
771 // This should never happen!
772 return aSelectedName
;
774 long nDim
= itr
->second
;
775 BOOL bIsDataLayout
= false;
776 return mrDPObj
.GetDimName(nDim
, bIsDataLayout
);
779 IMPL_LINK( ScDPShowDetailDlg
, DblClickHdl
, ListBox
*, pLBox
)
781 if( pLBox
== &maLbDims
)
786 // ============================================================================