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