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