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"
51 // ============================================================================
53 using namespace ::com::sun::star::sheet
;
55 using ::rtl::OUString
;
56 using ::com::sun::star::uno::Sequence
;
58 // ============================================================================
62 /** Appends all strings from the Sequence to the list box.
64 Empty strings are replaced by a localized "(empty)" entry and inserted at
65 the specified position.
67 @return true = The passed string list contains an empty string entry.
69 template< typename ListBoxType
>
70 bool lclFillListBox( ListBoxType
& rLBox
, const Sequence
< OUString
>& rStrings
, USHORT nEmptyPos
= LISTBOX_APPEND
)
73 if( const OUString
* pStr
= rStrings
.getConstArray() )
75 for( const OUString
* pEnd
= pStr
+ rStrings
.getLength(); pStr
!= pEnd
; ++pStr
)
77 if( pStr
->getLength() )
78 rLBox
.InsertEntry( *pStr
);
81 rLBox
.InsertEntry( ScGlobal::GetRscString( STR_EMPTYDATA
), nEmptyPos
);
89 /** Searches for a listbox entry, starts search at specified position. */
90 USHORT
lclFindListBoxEntry( const ListBox
& rLBox
, const String
& rEntry
, USHORT nStartPos
)
92 USHORT nPos
= nStartPos
;
93 while( (nPos
< rLBox
.GetEntryCount()) && (rLBox
.GetEntry( nPos
) != rEntry
) )
95 return (nPos
< rLBox
.GetEntryCount()) ? nPos
: LISTBOX_ENTRY_NOTFOUND
;
98 /** This table represents the order of the strings in the resource string array. */
99 static const USHORT spnFunctions
[] =
107 PIVOT_FUNC_COUNT_NUM
,
114 const USHORT SC_BASEITEM_PREV_POS
= 0;
115 const USHORT SC_BASEITEM_NEXT_POS
= 1;
116 const USHORT SC_BASEITEM_USER_POS
= 2;
118 const USHORT SC_SORTNAME_POS
= 0;
119 const USHORT 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 { 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 { LISTBOX_ENTRY_NOTFOUND
, DataPilotFieldLayoutMode::TABULAR_LAYOUT
}
145 static const ScDPListBoxWrapper::MapEntryType spShowFromMap
[] =
147 { 0, DataPilotFieldShowItemsMode::FROM_TOP
},
148 { 1, DataPilotFieldShowItemsMode::FROM_BOTTOM
},
149 { LISTBOX_ENTRY_NOTFOUND
, DataPilotFieldShowItemsMode::FROM_TOP
}
154 // ============================================================================
156 ScDPFunctionListBox::ScDPFunctionListBox( Window
* pParent
, const ResId
& rResId
) :
157 MultiListBox( pParent
, rResId
)
162 void ScDPFunctionListBox::SetSelection( USHORT nFuncMask
)
164 if( (nFuncMask
== PIVOT_FUNC_NONE
) || (nFuncMask
== PIVOT_FUNC_AUTO
) )
167 for( USHORT nEntry
= 0, nCount
= GetEntryCount(); nEntry
< nCount
; ++nEntry
)
168 SelectEntryPos( nEntry
, (nFuncMask
& spnFunctions
[ nEntry
]) != 0 );
171 USHORT
ScDPFunctionListBox::GetSelection() const
173 USHORT nFuncMask
= PIVOT_FUNC_NONE
;
174 for( USHORT nSel
= 0, nCount
= GetSelectEntryCount(); nSel
< nCount
; ++nSel
)
175 nFuncMask
|= spnFunctions
[ GetSelectEntryPos( nSel
) ];
179 void ScDPFunctionListBox::FillFunctionNames()
181 DBG_ASSERT( !GetEntryCount(), "ScDPFunctionListBox::FillFunctionNames - do not add texts to resource" );
183 ResStringArray
aArr( ScResId( SCSTR_DPFUNCLISTBOX
) );
184 for( USHORT nIndex
= 0, nCount
= sal::static_int_cast
<USHORT
>(aArr
.Count()); nIndex
< nCount
; ++nIndex
)
185 InsertEntry( aArr
.GetString( nIndex
) );
188 // ============================================================================
190 ScDPFunctionDlg::ScDPFunctionDlg(
191 Window
* pParent
, const ScDPLabelDataVec
& rLabelVec
,
192 const ScDPLabelData
& rLabelData
, const ScDPFuncData
& rFuncData
) :
193 ModalDialog ( pParent
, ScResId( RID_SCDLG_DPDATAFIELD
) ),
194 maFlFunc ( this, ScResId( FL_FUNC
) ),
195 maLbFunc ( this, ScResId( LB_FUNC
) ),
196 maFtNameLabel ( this, ScResId( FT_NAMELABEL
) ),
197 maFtName ( this, ScResId( FT_NAME
) ),
198 maFlDisplay ( this, ScResId( FL_DISPLAY
) ),
199 maFtType ( this, ScResId( FT_TYPE
) ),
200 maLbType ( this, ScResId( LB_TYPE
) ),
201 maFtBaseField ( this, ScResId( FT_BASEFIELD
) ),
202 maLbBaseField ( this, ScResId( LB_BASEFIELD
) ),
203 maFtBaseItem ( this, ScResId( FT_BASEITEM
) ),
204 maLbBaseItem ( this, ScResId( LB_BASEITEM
) ),
205 maBtnOk ( this, ScResId( BTN_OK
) ),
206 maBtnCancel ( this, ScResId( BTN_CANCEL
) ),
207 maBtnHelp ( this, ScResId( BTN_HELP
) ),
208 maBtnMore ( this, ScResId( BTN_MORE
) ),
209 maLbTypeWrp ( maLbType
, spRefTypeMap
),
210 mrLabelVec ( rLabelVec
),
211 mbEmptyItem ( false )
214 Init( rLabelData
, rFuncData
);
217 USHORT
ScDPFunctionDlg::GetFuncMask() const
219 return maLbFunc
.GetSelection();
222 DataPilotFieldReference
ScDPFunctionDlg::GetFieldRef() const
224 DataPilotFieldReference aRef
;
226 aRef
.ReferenceType
= maLbTypeWrp
.GetControlValue();
227 aRef
.ReferenceField
= maLbBaseField
.GetSelectEntry();
229 USHORT nBaseItemPos
= maLbBaseItem
.GetSelectEntryPos();
230 switch( nBaseItemPos
)
232 case SC_BASEITEM_PREV_POS
:
233 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::PREVIOUS
;
235 case SC_BASEITEM_NEXT_POS
:
236 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::NEXT
;
240 aRef
.ReferenceItemType
= DataPilotFieldReferenceItemType::NAMED
;
241 if( !mbEmptyItem
|| (nBaseItemPos
> SC_BASEITEM_USER_POS
) )
242 aRef
.ReferenceItemName
= maLbBaseItem
.GetSelectEntry();
249 void ScDPFunctionDlg::Init( const ScDPLabelData
& rLabelData
, const ScDPFuncData
& rFuncData
)
252 USHORT nFuncMask
= (rFuncData
.mnFuncMask
== PIVOT_FUNC_NONE
) ? PIVOT_FUNC_SUM
: rFuncData
.mnFuncMask
;
253 maLbFunc
.SetSelection( nFuncMask
);
256 maFtName
.SetText( rLabelData
.maName
);
258 // "More button" controls
259 maBtnMore
.AddWindow( &maFlDisplay
);
260 maBtnMore
.AddWindow( &maFtType
);
261 maBtnMore
.AddWindow( &maLbType
);
262 maBtnMore
.AddWindow( &maFtBaseField
);
263 maBtnMore
.AddWindow( &maLbBaseField
);
264 maBtnMore
.AddWindow( &maFtBaseItem
);
265 maBtnMore
.AddWindow( &maLbBaseItem
);
268 maLbFunc
.SetDoubleClickHdl( LINK( this, ScDPFunctionDlg
, DblClickHdl
) );
269 maLbType
.SetSelectHdl( LINK( this, ScDPFunctionDlg
, SelectHdl
) );
270 maLbBaseField
.SetSelectHdl( LINK( this, ScDPFunctionDlg
, SelectHdl
) );
272 // base field list box
273 for( ScDPLabelDataVec::const_iterator aIt
= mrLabelVec
.begin(), aEnd
= mrLabelVec
.end(); aIt
!= aEnd
; ++aIt
)
274 maLbBaseField
.InsertEntry( aIt
->maName
);
276 // base item list box
277 maLbBaseItem
.SetSeparatorPos( SC_BASEITEM_USER_POS
- 1 );
279 // select field reference type
280 maLbTypeWrp
.SetControlValue( rFuncData
.maFieldRef
.ReferenceType
);
281 SelectHdl( &maLbType
); // enables base field/item list boxes
284 maLbBaseField
.SelectEntry( rFuncData
.maFieldRef
.ReferenceField
);
285 if( maLbBaseField
.GetSelectEntryPos() >= maLbBaseField
.GetEntryCount() )
286 maLbBaseField
.SelectEntryPos( 0 );
287 SelectHdl( &maLbBaseField
); // fills base item list, selects base item
290 switch( rFuncData
.maFieldRef
.ReferenceItemType
)
292 case DataPilotFieldReferenceItemType::PREVIOUS
:
293 maLbBaseItem
.SelectEntryPos( SC_BASEITEM_PREV_POS
);
295 case DataPilotFieldReferenceItemType::NEXT
:
296 maLbBaseItem
.SelectEntryPos( SC_BASEITEM_NEXT_POS
);
300 if( mbEmptyItem
&& !rFuncData
.maFieldRef
.ReferenceItemName
.getLength() )
302 // select special "(empty)" entry added before other items
303 maLbBaseItem
.SelectEntryPos( SC_BASEITEM_USER_POS
);
307 USHORT nStartPos
= mbEmptyItem
? (SC_BASEITEM_USER_POS
+ 1) : SC_BASEITEM_USER_POS
;
308 USHORT nPos
= lclFindListBoxEntry( maLbBaseItem
, rFuncData
.maFieldRef
.ReferenceItemName
, nStartPos
);
309 if( nPos
>= maLbBaseItem
.GetEntryCount() )
310 nPos
= (maLbBaseItem
.GetEntryCount() > SC_BASEITEM_USER_POS
) ? SC_BASEITEM_USER_POS
: SC_BASEITEM_PREV_POS
;
311 maLbBaseItem
.SelectEntryPos( nPos
);
317 IMPL_LINK( ScDPFunctionDlg
, SelectHdl
, ListBox
*, pLBox
)
319 if( pLBox
== &maLbType
)
321 bool bEnableField
, bEnableItem
;
322 switch( maLbTypeWrp
.GetControlValue() )
324 case DataPilotFieldReferenceType::ITEM_DIFFERENCE
:
325 case DataPilotFieldReferenceType::ITEM_PERCENTAGE
:
326 case DataPilotFieldReferenceType::ITEM_PERCENTAGE_DIFFERENCE
:
327 bEnableField
= bEnableItem
= true;
330 case DataPilotFieldReferenceType::RUNNING_TOTAL
:
336 bEnableField
= bEnableItem
= false;
339 bEnableField
&= maLbBaseField
.GetEntryCount() > 0;
340 maFtBaseField
.Enable( bEnableField
);
341 maLbBaseField
.Enable( bEnableField
);
343 bEnableItem
&= bEnableField
;
344 maFtBaseItem
.Enable( bEnableItem
);
345 maLbBaseItem
.Enable( bEnableItem
);
347 else if( pLBox
== &maLbBaseField
)
349 // keep "previous" and "next" entries
350 while( maLbBaseItem
.GetEntryCount() > SC_BASEITEM_USER_POS
)
351 maLbBaseItem
.RemoveEntry( SC_BASEITEM_USER_POS
);
353 // update item list for current base field
355 size_t nBasePos
= maLbBaseField
.GetSelectEntryPos();
356 if( nBasePos
< mrLabelVec
.size() )
357 mbEmptyItem
= lclFillListBox( maLbBaseItem
, mrLabelVec
[ nBasePos
].maMembers
, SC_BASEITEM_USER_POS
);
360 USHORT nItemPos
= (maLbBaseItem
.GetEntryCount() > SC_BASEITEM_USER_POS
) ? SC_BASEITEM_USER_POS
: SC_BASEITEM_PREV_POS
;
361 maLbBaseItem
.SelectEntryPos( nItemPos
);
366 IMPL_LINK( ScDPFunctionDlg
, DblClickHdl
, MultiListBox
*, EMPTYARG
)
372 // ============================================================================
374 ScDPSubtotalDlg::ScDPSubtotalDlg( Window
* pParent
, ScDPObject
& rDPObj
,
375 const ScDPLabelData
& rLabelData
, const ScDPFuncData
& rFuncData
,
376 const ScDPNameVec
& rDataFields
, bool bEnableLayout
) :
377 ModalDialog ( pParent
, ScResId( RID_SCDLG_PIVOTSUBT
) ),
378 maFlSubt ( this, ScResId( FL_FUNC
) ),
379 maRbNone ( this, ScResId( RB_NONE
) ),
380 maRbAuto ( this, ScResId( RB_AUTO
) ),
381 maRbUser ( this, ScResId( RB_USER
) ),
382 maLbFunc ( this, ScResId( LB_FUNC
) ),
383 maFtNameLabel ( this, ScResId( FT_NAMELABEL
) ),
384 maFtName ( this, ScResId( FT_NAME
) ),
385 maCbShowAll ( this, ScResId( CB_SHOWALL
) ),
386 maBtnOk ( this, ScResId( BTN_OK
) ),
387 maBtnCancel ( this, ScResId( BTN_CANCEL
) ),
388 maBtnHelp ( this, ScResId( BTN_HELP
) ),
389 maBtnOptions ( this, ScResId( BTN_OPTIONS
) ),
391 mrDataFields ( rDataFields
),
392 maLabelData ( rLabelData
),
393 mbEnableLayout ( bEnableLayout
)
396 Init( rLabelData
, rFuncData
);
399 USHORT
ScDPSubtotalDlg::GetFuncMask() const
401 USHORT nFuncMask
= PIVOT_FUNC_NONE
;
403 if( maRbAuto
.IsChecked() )
404 nFuncMask
= PIVOT_FUNC_AUTO
;
405 else if( maRbUser
.IsChecked() )
406 nFuncMask
= maLbFunc
.GetSelection();
411 void ScDPSubtotalDlg::FillLabelData( ScDPLabelData
& rLabelData
) const
413 rLabelData
.mnFuncMask
= GetFuncMask();
414 rLabelData
.mnUsedHier
= maLabelData
.mnUsedHier
;
415 rLabelData
.mbShowAll
= maCbShowAll
.IsChecked();
416 rLabelData
.maMembers
= maLabelData
.maMembers
;
417 rLabelData
.maVisible
= maLabelData
.maVisible
;
418 rLabelData
.maShowDet
= maLabelData
.maShowDet
;
419 rLabelData
.maSortInfo
= maLabelData
.maSortInfo
;
420 rLabelData
.maLayoutInfo
= maLabelData
.maLayoutInfo
;
421 rLabelData
.maShowInfo
= maLabelData
.maShowInfo
;
424 void ScDPSubtotalDlg::Init( const ScDPLabelData
& rLabelData
, const ScDPFuncData
& rFuncData
)
427 maFtName
.SetText( rLabelData
.maName
);
430 maRbNone
.SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
431 maRbAuto
.SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
432 maRbUser
.SetClickHdl( LINK( this, ScDPSubtotalDlg
, RadioClickHdl
) );
434 RadioButton
* pRBtn
= 0;
435 switch( rFuncData
.mnFuncMask
)
437 case PIVOT_FUNC_NONE
: pRBtn
= &maRbNone
; break;
438 case PIVOT_FUNC_AUTO
: pRBtn
= &maRbAuto
; break;
439 default: pRBtn
= &maRbUser
;
442 RadioClickHdl( pRBtn
);
445 maLbFunc
.SetSelection( rFuncData
.mnFuncMask
);
446 maLbFunc
.SetDoubleClickHdl( LINK( this, ScDPSubtotalDlg
, DblClickHdl
) );
449 maCbShowAll
.Check( rLabelData
.mbShowAll
);
452 maBtnOptions
.SetClickHdl( LINK( this, ScDPSubtotalDlg
, ClickHdl
) );
455 // ----------------------------------------------------------------------------
457 IMPL_LINK( ScDPSubtotalDlg
, RadioClickHdl
, RadioButton
*, pBtn
)
459 maLbFunc
.Enable( pBtn
== &maRbUser
);
463 IMPL_LINK( ScDPSubtotalDlg
, DblClickHdl
, MultiListBox
*, EMPTYARG
)
469 IMPL_LINK( ScDPSubtotalDlg
, ClickHdl
, PushButton
*, pBtn
)
471 if( pBtn
== &maBtnOptions
)
473 ScDPSubtotalOptDlg
* pDlg
= new ScDPSubtotalOptDlg( this, mrDPObj
, maLabelData
, mrDataFields
, mbEnableLayout
);
474 if( pDlg
->Execute() == RET_OK
)
475 pDlg
->FillLabelData( maLabelData
);
481 // ============================================================================
483 ScDPSubtotalOptDlg::ScDPSubtotalOptDlg( Window
* pParent
, ScDPObject
& rDPObj
,
484 const ScDPLabelData
& rLabelData
, const ScDPNameVec
& rDataFields
,
485 bool bEnableLayout
) :
486 ModalDialog ( pParent
, ScResId( RID_SCDLG_DPSUBTOTAL_OPT
) ),
487 maFlSortBy ( this, ScResId( FL_SORT_BY
) ),
488 maLbSortBy ( this, ScResId( LB_SORT_BY
) ),
489 maRbSortAsc ( this, ScResId( RB_SORT_ASC
) ),
490 maRbSortDesc ( this, ScResId( RB_SORT_DESC
) ),
491 maRbSortMan ( this, ScResId( RB_SORT_MAN
) ),
492 maFlLayout ( this, ScResId( FL_LAYOUT
) ),
493 maFtLayout ( this, ScResId( FT_LAYOUT
) ),
494 maLbLayout ( this, ScResId( LB_LAYOUT
) ),
495 maCbLayoutEmpty ( this, ScResId( CB_LAYOUT_EMPTY
) ),
496 maFlAutoShow ( this, ScResId( FL_AUTOSHOW
) ),
497 maCbShow ( this, ScResId( CB_SHOW
) ),
498 maNfShow ( this, ScResId( NF_SHOW
) ),
499 maFtShow ( this, ScResId( FT_SHOW
) ),
500 maFtShowFrom ( this, ScResId( FT_SHOW_FROM
) ),
501 maLbShowFrom ( this, ScResId( LB_SHOW_FROM
) ),
502 maFtShowUsing ( this, ScResId( FT_SHOW_USING
) ),
503 maLbShowUsing ( this, ScResId( LB_SHOW_USING
) ),
504 maFlHide ( this, ScResId( FL_HIDE
) ),
505 maLbHide ( this, ScResId( CT_HIDE
) ),
506 maFtHierarchy ( this, ScResId( FT_HIERARCHY
) ),
507 maLbHierarchy ( this, ScResId( LB_HIERARCHY
) ),
508 maBtnOk ( this, ScResId( BTN_OK
) ),
509 maBtnCancel ( this, ScResId( BTN_CANCEL
) ),
510 maBtnHelp ( this, ScResId( BTN_HELP
) ),
511 maLbLayoutWrp ( maLbLayout
, spLayoutMap
),
512 maLbShowFromWrp ( maLbShowFrom
, spShowFromMap
),
514 maLabelData ( rLabelData
)
517 Init( rDataFields
, bEnableLayout
);
520 void ScDPSubtotalOptDlg::FillLabelData( ScDPLabelData
& rLabelData
) const
524 if( maRbSortMan
.IsChecked() )
525 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::MANUAL
;
526 else if( maLbSortBy
.GetSelectEntryPos() == SC_SORTNAME_POS
)
527 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::NAME
;
529 rLabelData
.maSortInfo
.Mode
= DataPilotFieldSortMode::DATA
;
531 rLabelData
.maSortInfo
.Field
= maLbSortBy
.GetSelectEntry();
532 rLabelData
.maSortInfo
.IsAscending
= maRbSortAsc
.IsChecked();
534 // *** LAYOUT MODE ***
536 rLabelData
.maLayoutInfo
.LayoutMode
= maLbLayoutWrp
.GetControlValue();
537 rLabelData
.maLayoutInfo
.AddEmptyLines
= maCbLayoutEmpty
.IsChecked();
541 rLabelData
.maShowInfo
.IsEnabled
= maCbShow
.IsChecked();
542 rLabelData
.maShowInfo
.ShowItemsMode
= maLbShowFromWrp
.GetControlValue();
543 rLabelData
.maShowInfo
.ItemCount
= sal::static_int_cast
<sal_Int32
>( maNfShow
.GetValue() );
544 rLabelData
.maShowInfo
.DataField
= maLbShowUsing
.GetSelectEntry();
546 // *** HIDDEN ITEMS ***
548 rLabelData
.maMembers
= maLabelData
.maMembers
;
549 ULONG nVisCount
= maLbHide
.GetEntryCount();
550 rLabelData
.maVisible
.realloc( nVisCount
);
551 for( USHORT nPos
= 0; nPos
< nVisCount
; ++nPos
)
552 rLabelData
.maVisible
[ nPos
] = !maLbHide
.IsChecked( nPos
);
556 rLabelData
.mnUsedHier
= maLbHierarchy
.GetSelectEntryCount() ? maLbHierarchy
.GetSelectEntryPos() : 0;
559 void ScDPSubtotalOptDlg::Init( const ScDPNameVec
& rDataFields
, bool bEnableLayout
)
563 sal_Int32 nSortMode
= maLabelData
.maSortInfo
.Mode
;
565 // sort fields list box
566 maLbSortBy
.InsertEntry( maLabelData
.maName
);
567 for( ScDPNameVec::const_iterator aIt
= rDataFields
.begin(), aEnd
= rDataFields
.end(); aIt
!= aEnd
; ++aIt
)
569 maLbSortBy
.InsertEntry( *aIt
);
570 maLbShowUsing
.InsertEntry( *aIt
); // for AutoShow
572 if( maLbSortBy
.GetEntryCount() > SC_SORTDATA_POS
)
573 maLbSortBy
.SetSeparatorPos( SC_SORTDATA_POS
- 1 );
575 USHORT nSortPos
= SC_SORTNAME_POS
;
576 if( nSortMode
== DataPilotFieldSortMode::DATA
)
578 nSortPos
= lclFindListBoxEntry( maLbSortBy
, maLabelData
.maSortInfo
.Field
, SC_SORTDATA_POS
);
579 if( nSortPos
>= maLbSortBy
.GetEntryCount() )
581 nSortPos
= SC_SORTNAME_POS
;
582 nSortMode
= DataPilotFieldSortMode::MANUAL
;
585 maLbSortBy
.SelectEntryPos( nSortPos
);
588 maRbSortAsc
.SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
589 maRbSortDesc
.SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
590 maRbSortMan
.SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, RadioClickHdl
) );
592 RadioButton
* pRBtn
= 0;
595 case DataPilotFieldSortMode::NONE
:
596 case DataPilotFieldSortMode::MANUAL
:
597 pRBtn
= &maRbSortMan
;
600 pRBtn
= maLabelData
.maSortInfo
.IsAscending
? &maRbSortAsc
: &maRbSortDesc
;
603 RadioClickHdl( pRBtn
);
605 // *** LAYOUT MODE ***
607 maFlLayout
.Enable( bEnableLayout
);
608 maFtLayout
.Enable( bEnableLayout
);
609 maLbLayout
.Enable( bEnableLayout
);
610 maCbLayoutEmpty
.Enable( bEnableLayout
);
612 maLbLayoutWrp
.SetControlValue( maLabelData
.maLayoutInfo
.LayoutMode
);
613 maCbLayoutEmpty
.Check( maLabelData
.maLayoutInfo
.AddEmptyLines
);
617 maCbShow
.Check( maLabelData
.maShowInfo
.IsEnabled
);
618 maCbShow
.SetClickHdl( LINK( this, ScDPSubtotalOptDlg
, CheckHdl
) );
620 maLbShowFromWrp
.SetControlValue( maLabelData
.maShowInfo
.ShowItemsMode
);
621 long nCount
= static_cast< long >( maLabelData
.maShowInfo
.ItemCount
);
623 nCount
= SC_SHOW_DEFAULT
;
624 maNfShow
.SetValue( nCount
);
626 // maLbShowUsing already filled above
627 maLbShowUsing
.SelectEntry( maLabelData
.maShowInfo
.DataField
);
628 if( maLbShowUsing
.GetSelectEntryPos() >= maLbShowUsing
.GetEntryCount() )
629 maLbShowUsing
.SelectEntryPos( 0 );
631 CheckHdl( &maCbShow
); // enable/disable dependent controls
633 // *** HIDDEN ITEMS ***
635 maLbHide
.SetHelpId( HID_SC_DPSUBT_HIDE
);
640 if( maLabelData
.maHiers
.getLength() > 1 )
642 lclFillListBox( maLbHierarchy
, maLabelData
.maHiers
);
643 sal_Int32 nHier
= maLabelData
.mnUsedHier
;
644 if( (nHier
< 0) || (nHier
>= maLabelData
.maHiers
.getLength()) ) nHier
= 0;
645 maLbHierarchy
.SelectEntryPos( static_cast< USHORT
>( nHier
) );
646 maLbHierarchy
.SetSelectHdl( LINK( this, ScDPSubtotalOptDlg
, SelectHdl
) );
650 maFtHierarchy
.Disable();
651 maLbHierarchy
.Disable();
655 void ScDPSubtotalOptDlg::InitHideListBox()
658 lclFillListBox( maLbHide
, maLabelData
.maMembers
);
659 for( sal_Int32 nVisIdx
= 0, nVisSize
= maLabelData
.maVisible
.getLength(); nVisIdx
< nVisSize
; ++nVisIdx
)
660 maLbHide
.CheckEntryPos( static_cast< USHORT
>( nVisIdx
), !maLabelData
.maVisible
[ nVisIdx
] );
661 bool bEnable
= maLbHide
.GetEntryCount() > 0;
662 maFlHide
.Enable( bEnable
);
663 maLbHide
.Enable( bEnable
);
666 IMPL_LINK( ScDPSubtotalOptDlg
, RadioClickHdl
, RadioButton
*, pBtn
)
668 maLbSortBy
.Enable( pBtn
!= &maRbSortMan
);
672 IMPL_LINK( ScDPSubtotalOptDlg
, CheckHdl
, CheckBox
*, pCBox
)
674 if( pCBox
== &maCbShow
)
676 bool bEnable
= maCbShow
.IsChecked();
677 maNfShow
.Enable( bEnable
);
678 maFtShow
.Enable( bEnable
);
679 maFtShowFrom
.Enable( bEnable
);
680 maLbShowFrom
.Enable( bEnable
);
682 bool bEnableUsing
= bEnable
&& (maLbShowUsing
.GetEntryCount() > 0);
683 maFtShowUsing
.Enable( bEnableUsing
);
684 maLbShowUsing
.Enable( bEnableUsing
);
689 IMPL_LINK( ScDPSubtotalOptDlg
, SelectHdl
, ListBox
*, pLBox
)
691 if( pLBox
== &maLbHierarchy
)
693 mrDPObj
.GetMembers( maLabelData
.mnCol
, maLbHierarchy
.GetSelectEntryPos(),
694 maLabelData
.maMembers
, &maLabelData
.maVisible
, &maLabelData
.maShowDet
);
700 // ============================================================================
702 ScDPShowDetailDlg::ScDPShowDetailDlg( Window
* pParent
, ScDPObject
& rDPObj
, USHORT nOrient
) :
703 ModalDialog ( pParent
, ScResId( RID_SCDLG_DPSHOWDETAIL
) ),
704 maFtDims ( this, ScResId( FT_DIMS
) ),
705 maLbDims ( this, ScResId( LB_DIMS
) ),
706 maBtnOk ( this, ScResId( BTN_OK
) ),
707 maBtnCancel ( this, ScResId( BTN_CANCEL
) ),
708 maBtnHelp ( this, ScResId( BTN_HELP
) ),
714 ScDPSaveData
* pSaveData
= rDPObj
.GetSaveData();
715 long nDimCount
= rDPObj
.GetDimCount();
716 for (long nDim
=0; nDim
<nDimCount
; nDim
++)
719 String aName
= rDPObj
.GetDimName( nDim
, bIsDataLayout
);
720 if ( !bIsDataLayout
&& !rDPObj
.IsDuplicated( nDim
) )
722 const ScDPSaveDimension
* pDimension
= pSaveData
? pSaveData
->GetExistingDimensionByName(aName
) : 0;
723 if ( !pDimension
|| (pDimension
->GetOrientation() != nOrient
) )
725 const OUString
* pLayoutName
= pDimension
->GetLayoutName();
727 aName
= *pLayoutName
;
728 maLbDims
.InsertEntry( aName
);
729 maNameIndexMap
.insert(DimNameIndexMap::value_type(aName
, nDim
));
733 if( maLbDims
.GetEntryCount() )
734 maLbDims
.SelectEntryPos( 0 );
736 maLbDims
.SetDoubleClickHdl( LINK( this, ScDPShowDetailDlg
, DblClickHdl
) );
739 short ScDPShowDetailDlg::Execute()
741 return maLbDims
.GetEntryCount() ? ModalDialog::Execute() : RET_CANCEL
;
744 String
ScDPShowDetailDlg::GetDimensionName() const
746 // Look up the internal dimension name which may be different from the
747 // displayed field name.
748 String aSelectedName
= maLbDims
.GetSelectEntry();
749 DimNameIndexMap::const_iterator itr
= maNameIndexMap
.find(aSelectedName
);
750 if (itr
== maNameIndexMap
.end())
751 // This should never happen!
752 return aSelectedName
;
754 long nDim
= itr
->second
;
755 BOOL bIsDataLayout
= false;
756 return mrDPObj
.GetDimName(nDim
, bIsDataLayout
);
759 IMPL_LINK( ScDPShowDetailDlg
, DblClickHdl
, ListBox
*, pLBox
)
761 if( pLBox
== &maLbDims
)
766 // ============================================================================