xref: /trunk/main/sc/source/ui/dbgui/tpsubt.cxx (revision a479921a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scui.hxx"
26 
27 
28 
29 
30 #include "scitems.hxx"
31 #include "uiitems.hxx"
32 #include "global.hxx"
33 #include "userlist.hxx"
34 #include "viewdata.hxx"
35 #include "document.hxx"
36 #include "scresid.hxx"
37 #include "sc.hrc"       // -> Slot IDs
38 
39 #include "subtdlg.hxx"
40 #include "subtdlg.hrc"
41 #include "tpsubt.hxx"
42 
43 // STATIC DATA -----------------------------------------------------------
44 
45 static sal_uInt16 pSubTotalsRanges[] =
46 {
47 	SID_SUBTOTALS,
48 	SID_SUBTOTALS,
49 	0
50 };
51 
52 //========================================================================
53 // Zwischenergebnisgruppen-Tabpage:
54 
ScTpSubTotalGroup(Window * pParent,sal_uInt16 nResId,const SfxItemSet & rArgSet)55 ScTpSubTotalGroup::ScTpSubTotalGroup( Window* pParent, sal_uInt16 nResId,
56 									  const SfxItemSet& rArgSet )
57 		:	SfxTabPage		( pParent,
58 							  ScResId( nResId ),
59 							  rArgSet ),
60 			//
61 			aFtGroup		( this, ScResId( FT_GROUP ) ),
62 			aLbGroup		( this, ScResId( LB_GROUP ) ),
63 			aFtColumns		( this, ScResId( FT_COLUMNS ) ),
64 			aLbColumns		( this, ScResId( WND_COLUMNS ) ),
65 			aFtFunctions	( this, ScResId( FT_FUNCTIONS ) ),
66 			aLbFunctions	( this, ScResId( LB_FUNCTIONS ) ),
67 			aStrNone		( ScResId( SCSTR_NONE ) ),
68 			aStrColumn		( ScResId( SCSTR_COLUMN ) ),
69 			//
70 			pViewData		( NULL ),
71 			pDoc			( NULL ),
72 			nWhichSubTotals ( rArgSet.GetPool()->GetWhich( SID_SUBTOTALS ) ),
73 			rSubTotalData	( ((const ScSubTotalItem&)
74 							  rArgSet.Get( nWhichSubTotals )).
75 								GetSubTotalData() ),
76 			nFieldCount 	( 0 )
77 {
78 	// Font is correctly initialized by SvTreeListBox ctor
79 	aLbColumns.SetSelectionMode( SINGLE_SELECTION );
80 	aLbColumns.SetDragDropMode( SV_DRAGDROP_NONE );
81 	aLbColumns.SetSpaceBetweenEntries( 0 );
82 	aLbColumns.Show();
83 
84 	Init ();
85 	FreeResource();
86 }
87 
88 // -----------------------------------------------------------------------
89 
~ScTpSubTotalGroup()90 __EXPORT ScTpSubTotalGroup::~ScTpSubTotalGroup()
91 {
92 	sal_uInt16	nCount = (sal_uInt16)aLbColumns.GetEntryCount();
93 
94 	if ( nCount > 0 )
95 	{
96 		sal_uInt16* pData = NULL;
97 
98 		for ( sal_uInt16 i=0; i<nCount; i++ )
99 		{
100 			pData = (sal_uInt16*)(aLbColumns.GetEntryData( i ));
101 			DBG_ASSERT( pData, "EntryData not found" );
102 
103 			delete pData;
104 		}
105 	}
106 }
107 
108 // -----------------------------------------------------------------------
109 
Init()110 void ScTpSubTotalGroup::Init()
111 {
112 	const ScSubTotalItem& rSubTotalItem = (const ScSubTotalItem&)
113 										  GetItemSet().Get( nWhichSubTotals );
114 
115 	pViewData	= rSubTotalItem.GetViewData();
116 	pDoc		= ( pViewData ) ? pViewData->GetDocument() : NULL;
117 
118 	DBG_ASSERT( pViewData && pDoc, "ViewData or Document not found :-(" );
119 
120 	aLbGroup.SetSelectHdl		( LINK( this, ScTpSubTotalGroup, SelectHdl ) );
121 	aLbColumns.SetSelectHdl		( LINK( this, ScTpSubTotalGroup, SelectHdl ) );
122 	aLbColumns.SetCheckButtonHdl	( LINK( this, ScTpSubTotalGroup, CheckHdl ) );
123 	aLbFunctions.SetSelectHdl	( LINK( this, ScTpSubTotalGroup, SelectHdl ) );
124 
125 	nFieldArr[0] = 0;
126 	FillListBoxes();
127 }
128 
129 //------------------------------------------------------------------------
130 
GetRanges()131 sal_uInt16* __EXPORT ScTpSubTotalGroup::GetRanges()
132 {
133 	return pSubTotalsRanges;
134 }
135 
136 // -----------------------------------------------------------------------
137 
DoReset(sal_uInt16 nGroupNo,const SfxItemSet & rArgSet)138 sal_Bool ScTpSubTotalGroup::DoReset( sal_uInt16 			nGroupNo,
139 								 const SfxItemSet&	rArgSet  )
140 {
141 	sal_uInt16 nGroupIdx = 0;
142 
143 	DBG_ASSERT( (nGroupNo<=3) && (nGroupNo>0), "Invalid group" );
144 
145 	if ( (nGroupNo > 3) || (nGroupNo == 0) )
146 		return sal_False;
147 	else
148 		nGroupIdx = nGroupNo-1;
149 
150 	//----------------------------------------------------------
151 
152     // #79058# first we have to clear the listboxes...
153     for ( sal_uInt16 nLbEntry = 0; nLbEntry < aLbColumns.GetEntryCount(); ++nLbEntry )
154     {
155         aLbColumns.CheckEntryPos( nLbEntry, sal_False );
156         *((sal_uInt16*)aLbColumns.GetEntryData( nLbEntry )) = 0;
157     }
158     aLbFunctions.SelectEntryPos( 0 );
159 
160 	ScSubTotalParam theSubTotalData( ((const ScSubTotalItem&)
161 									  rArgSet.Get( nWhichSubTotals )).
162 											GetSubTotalData() );
163 
164 	if ( theSubTotalData.bGroupActive[nGroupIdx] )
165 	{
166 		SCCOL			nField		= theSubTotalData.nField[nGroupIdx];
167 		SCCOL			nSubTotals	= theSubTotalData.nSubTotals[nGroupIdx];
168 		SCCOL* 		    pSubTotals	= theSubTotalData.pSubTotals[nGroupIdx];
169 		ScSubTotalFunc* pFunctions	= theSubTotalData.pFunctions[nGroupIdx];
170 
171 		aLbGroup.SelectEntryPos( GetFieldSelPos( nField )+1 );
172 
173 		for ( sal_uInt16 i=0; i<nSubTotals; i++ )
174 		{
175 			sal_uInt16	nCheckPos = GetFieldSelPos( pSubTotals[i] );
176 			sal_uInt16* pFunction = (sal_uInt16*)aLbColumns.GetEntryData( nCheckPos );
177 
178 			aLbColumns.CheckEntryPos( nCheckPos );
179 			*pFunction = FuncToLbPos( pFunctions[i] );
180 		}
181         aLbColumns.SelectEntryPos( 0 );
182 	}
183 	else
184 	{
185 		aLbGroup.SelectEntryPos( (nGroupNo == 1) ? 1 : 0 );
186 		aLbColumns.SelectEntryPos( 0 );
187 		aLbFunctions.SelectEntryPos( 0 );
188 	}
189 
190 	return sal_True;
191 }
192 
193 // -----------------------------------------------------------------------
194 
DoFillItemSet(sal_uInt16 nGroupNo,SfxItemSet & rArgSet)195 sal_Bool ScTpSubTotalGroup::DoFillItemSet( sal_uInt16		nGroupNo,
196 									   SfxItemSet&	rArgSet  )
197 {
198 	sal_uInt16 nGroupIdx = 0;
199 
200 	DBG_ASSERT( (nGroupNo<=3) && (nGroupNo>0), "Invalid group" );
201 	DBG_ASSERT(    (aLbGroup.GetEntryCount() > 0)
202 				&& (aLbColumns.GetEntryCount() > 0)
203 				&& (aLbFunctions.GetEntryCount() > 0),
204 				"Non-initialized Lists" );
205 
206 
207 	if (  (nGroupNo > 3) || (nGroupNo == 0)
208 		|| (aLbGroup.GetEntryCount() == 0)
209 		|| (aLbColumns.GetEntryCount() == 0)
210 		|| (aLbFunctions.GetEntryCount() == 0)
211 	   )
212 		return sal_False;
213 	else
214 		nGroupIdx = nGroupNo-1;
215 
216 	//----------------------------------------------------------
217 
218 	ScSubTotalParam theSubTotalData;			// auslesen, wenn schon teilweise gefuellt
219 	SfxTabDialog* pDlg = GetTabDialog();
220 	if ( pDlg )
221 	{
222 		const SfxItemSet* pExample = pDlg->GetExampleSet();
223 		const SfxPoolItem* pItem;
224 		if ( pExample && pExample->GetItemState( nWhichSubTotals, sal_True, &pItem ) == SFX_ITEM_SET )
225 			theSubTotalData = ((const ScSubTotalItem*)pItem)->GetSubTotalData();
226 	}
227 
228 	ScSubTotalFunc* pFunctions	= NULL;
229 	SCCOL* 		    pSubTotals	= NULL;
230 	sal_uInt16			nGroup		= aLbGroup.GetSelectEntryPos();
231 	sal_uInt16			nEntryCount = (sal_uInt16)aLbColumns.GetEntryCount();
232 	sal_uInt16			nCheckCount = aLbColumns.GetCheckedEntryCount();
233 
234 	theSubTotalData.nCol1					= rSubTotalData.nCol1;
235 	theSubTotalData.nRow1					= rSubTotalData.nRow1;
236 	theSubTotalData.nCol2					= rSubTotalData.nCol2;
237 	theSubTotalData.nRow2					= rSubTotalData.nRow2;
238 	theSubTotalData.bGroupActive[nGroupIdx] = (nGroup != 0);
239 	theSubTotalData.nField[nGroupIdx]		= (nGroup != 0)
240 												? nFieldArr[nGroup-1]
241 												: static_cast<SCCOL>(0);
242 
243 	if ( nEntryCount>0 && nCheckCount>0 && nGroup!=0 )
244 	{
245 		sal_uInt16 nFunction	= 0;
246 
247 		pSubTotals = new SCCOL  		[nCheckCount];
248 		pFunctions = new ScSubTotalFunc [nCheckCount];
249 
250 		for ( sal_uInt16 i=0, nCheck=0; i<nEntryCount; i++ )
251 		{
252 			if ( aLbColumns.IsChecked( i ) )
253 			{
254 				DBG_ASSERT( nCheck <= nCheckCount,
255 							"Range error :-(" );
256 				nFunction = *((sal_uInt16*)aLbColumns.GetEntryData( i ));
257 				pSubTotals[nCheck] = nFieldArr[i];
258 				pFunctions[nCheck] = LbPosToFunc( nFunction );
259 				nCheck++;
260 			}
261 		}
262 		theSubTotalData.SetSubTotals( nGroupNo, 	 // Gruppen-Nr.
263 									  pSubTotals,
264 									  pFunctions,
265 									  nCheckCount ); // Anzahl der Array-Elemente
266 
267 	}
268 
269 	rArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, &theSubTotalData ) );
270 
271 	if ( pSubTotals ) delete [] pSubTotals;
272 	if ( pFunctions ) delete [] pFunctions;
273 
274 	return sal_True;
275 }
276 
277 // -----------------------------------------------------------------------
278 
FillListBoxes()279 void ScTpSubTotalGroup::FillListBoxes()
280 {
281 	DBG_ASSERT( pViewData && pDoc, "ViewData or Document not found :-/" );
282 
283 	if ( pViewData && pDoc )
284 	{
285 		SCCOL	nFirstCol	= rSubTotalData.nCol1;
286 		SCROW	nFirstRow	= rSubTotalData.nRow1;
287 		SCTAB	nTab		= pViewData->GetTabNo();
288 		SCCOL	nMaxCol 	= rSubTotalData.nCol2;
289 		SCCOL	col;
290 		sal_uInt16	i=0;
291 		String	aFieldName;
292 
293 		aLbGroup.Clear();
294 		aLbColumns.Clear();
295 		aLbGroup.InsertEntry( aStrNone, 0 );
296 
297 		i=0;
298 		for ( col=nFirstCol; col<=nMaxCol && i<SC_MAXFIELDS; col++ )
299 		{
300 			pDoc->GetString( col, nFirstRow, nTab, aFieldName );
301 			if ( aFieldName.Len() == 0 )
302 			{
303                 aFieldName = aStrColumn;
304                 aFieldName += ' ';
305                 aFieldName += ::ScColToAlpha( col );  // from global.hxx
306 			}
307 			nFieldArr[i] = col;
308 			aLbGroup.InsertEntry( aFieldName, i+1 );
309 			aLbColumns.InsertEntry( aFieldName, i );
310 			aLbColumns.SetEntryData( i, new sal_uInt16(0) );
311 			i++;
312 		}
313 		// Nachtraegliche "Konstanteninitialisierung":
314 		(sal_uInt16&)nFieldCount = i;
315 	}
316 }
317 
318 // -----------------------------------------------------------------------
319 
GetFieldSelPos(SCCOL nField)320 sal_uInt16 ScTpSubTotalGroup::GetFieldSelPos( SCCOL nField )
321 {
322 	sal_uInt16	nFieldPos	= 0;
323 	sal_Bool	bFound		= sal_False;
324 
325 	for ( sal_uInt16 n=0; n<nFieldCount && !bFound; n++ )
326 	{
327 		if ( nFieldArr[n] == nField )
328 		{
329 			nFieldPos = n;
330 			bFound = sal_True;
331 		}
332 	}
333 
334 	return nFieldPos;
335 }
336 
337 // -----------------------------------------------------------------------
338 
LbPosToFunc(sal_uInt16 nPos)339 ScSubTotalFunc ScTpSubTotalGroup::LbPosToFunc( sal_uInt16 nPos )
340 {
341 	switch ( nPos )
342 	{
343 //		case  0:	return SUBTOTAL_FUNC_NONE;
344 		case  2:	return SUBTOTAL_FUNC_AVE;
345 		case  6:	return SUBTOTAL_FUNC_CNT;
346 		case  1:	return SUBTOTAL_FUNC_CNT2;
347 		case  3:	return SUBTOTAL_FUNC_MAX;
348 		case  4:	return SUBTOTAL_FUNC_MIN;
349 		case  5:	return SUBTOTAL_FUNC_PROD;
350 		case  7:	return SUBTOTAL_FUNC_STD;
351 		case  8:	return SUBTOTAL_FUNC_STDP;
352 		case  0:	return SUBTOTAL_FUNC_SUM;
353 		case  9:	return SUBTOTAL_FUNC_VAR;
354 		case 10:	return SUBTOTAL_FUNC_VARP;
355 		default:
356 			DBG_ERROR( "ScTpSubTotalGroup::LbPosToFunc" );
357 			return SUBTOTAL_FUNC_NONE;
358 	}
359 }
360 
361 // -----------------------------------------------------------------------
362 
FuncToLbPos(ScSubTotalFunc eFunc)363 sal_uInt16 ScTpSubTotalGroup::FuncToLbPos( ScSubTotalFunc eFunc )
364 {
365 	switch ( eFunc )
366 	{
367 //		case SUBTOTAL_FUNC_NONE:	return 0;
368 		case SUBTOTAL_FUNC_AVE: 	return 2;
369 		case SUBTOTAL_FUNC_CNT: 	return 6;
370 		case SUBTOTAL_FUNC_CNT2:	return 1;
371 		case SUBTOTAL_FUNC_MAX: 	return 3;
372 		case SUBTOTAL_FUNC_MIN: 	return 4;
373 		case SUBTOTAL_FUNC_PROD:	return 5;
374 		case SUBTOTAL_FUNC_STD: 	return 7;
375 		case SUBTOTAL_FUNC_STDP:	return 8;
376 		case SUBTOTAL_FUNC_SUM: 	return 0;
377 		case SUBTOTAL_FUNC_VAR: 	return 9;
378 		case SUBTOTAL_FUNC_VARP:	return 10;
379 		default:
380 			DBG_ERROR( "ScTpSubTotalGroup::FuncToLbPos" );
381 			return 0;
382 	}
383 }
384 
385 // -----------------------------------------------------------------------
386 // Handler:
387 //---------
388 
IMPL_LINK(ScTpSubTotalGroup,SelectHdl,ListBox *,pLb)389 IMPL_LINK( ScTpSubTotalGroup, SelectHdl, ListBox *, pLb )
390 {
391 	if (   (aLbColumns.GetEntryCount() > 0)
392 		&& (aLbColumns.GetSelectionCount() > 0) )
393 	{
394 		sal_uInt16		nFunction	= aLbFunctions.GetSelectEntryPos();
395 		sal_uInt16		nColumn 	= aLbColumns.GetSelectEntryPos();
396 		sal_uInt16* 	pFunction	= (sal_uInt16*)aLbColumns.GetEntryData( nColumn );
397 
398 		DBG_ASSERT( pFunction, "EntryData nicht gefunden!" );
399 		if ( !pFunction )
400 			return 0;
401 
402 		if ( ((SvxCheckListBox*)pLb) == &aLbColumns )
403 		{
404 			aLbFunctions.SelectEntryPos( *pFunction );
405 		}
406 		else if ( pLb == &aLbFunctions )
407 		{
408 			*pFunction = nFunction;
409 //			aLbColumns.CheckEntryPos( nColumn, (nFunction != 0) );//XXX
410 			aLbColumns.CheckEntryPos( nColumn, sal_True );
411 		}
412 	}
413 	return 0;
414 }
415 
416 // -----------------------------------------------------------------------
417 
IMPL_LINK(ScTpSubTotalGroup,CheckHdl,ListBox *,pLb)418 IMPL_LINK( ScTpSubTotalGroup, CheckHdl, ListBox *, pLb )
419 {
420 	if ( ((SvxCheckListBox*)pLb) == &aLbColumns )
421 	{
422 		SvLBoxEntry* pEntry = aLbColumns.GetHdlEntry();
423 
424 		if ( pEntry )
425 		{
426 			aLbColumns.SelectEntryPos( (sal_uInt16)aLbColumns.GetModel()->GetAbsPos( pEntry ) );
427 			SelectHdl( pLb );
428 		}
429 	}
430 	return 0;
431 }
432 
433 //========================================================================
434 // Abgeleitete Gruppen-TabPages:
435 
Create(Window * pParent,const SfxItemSet & rArgSet)436 SfxTabPage* __EXPORT ScTpSubTotalGroup1::Create( Window*			pParent,
437 												 const SfxItemSet&	rArgSet )
438 	{ return ( new ScTpSubTotalGroup1( pParent, rArgSet ) ); }
439 
440 // -----------------------------------------------------------------------
441 
Create(Window * pParent,const SfxItemSet & rArgSet)442 SfxTabPage* __EXPORT ScTpSubTotalGroup2::Create( Window*			 pParent,
443 									   const SfxItemSet&	rArgSet )
444 	{ return ( new ScTpSubTotalGroup2( pParent, rArgSet ) ); }
445 
446 // -----------------------------------------------------------------------
447 
Create(Window * pParent,const SfxItemSet & rArgSet)448 SfxTabPage* __EXPORT ScTpSubTotalGroup3::Create( Window*			 pParent,
449 									   const SfxItemSet&	rArgSet )
450 	{ return ( new ScTpSubTotalGroup3( pParent, rArgSet ) ); }
451 
452 // -----------------------------------------------------------------------
453 
ScTpSubTotalGroup1(Window * pParent,const SfxItemSet & rArgSet)454 ScTpSubTotalGroup1::ScTpSubTotalGroup1( Window* pParent, const SfxItemSet& rArgSet ) :
455 	ScTpSubTotalGroup( pParent, RID_SCPAGE_SUBT_GROUP1, rArgSet )
456 {}
457 
ScTpSubTotalGroup2(Window * pParent,const SfxItemSet & rArgSet)458 ScTpSubTotalGroup2::ScTpSubTotalGroup2( Window* pParent, const SfxItemSet& rArgSet ) :
459 	ScTpSubTotalGroup( pParent, RID_SCPAGE_SUBT_GROUP2, rArgSet )
460 {}
461 
ScTpSubTotalGroup3(Window * pParent,const SfxItemSet & rArgSet)462 ScTpSubTotalGroup3::ScTpSubTotalGroup3( Window* pParent, const SfxItemSet& rArgSet ) :
463 	ScTpSubTotalGroup( pParent, RID_SCPAGE_SUBT_GROUP3, rArgSet )
464 {}
465 
466 // -----------------------------------------------------------------------
467 
468 
469 #define RESET(i) (ScTpSubTotalGroup::DoReset( (i), rArgSet ))
470 
Reset(const SfxItemSet & rArgSet)471 void __EXPORT ScTpSubTotalGroup1::Reset( const SfxItemSet& rArgSet ) { RESET(1); }
472 
Reset(const SfxItemSet & rArgSet)473 void __EXPORT ScTpSubTotalGroup2::Reset( const SfxItemSet& rArgSet ) { RESET(2); }
474 
Reset(const SfxItemSet & rArgSet)475 void __EXPORT ScTpSubTotalGroup3::Reset( const SfxItemSet& rArgSet ) { RESET(3); }
476 
477 #undef RESET
478 
479 // -----------------------------------------------------------------------
480 
481 #define FILLSET(i) (ScTpSubTotalGroup::DoFillItemSet( (i), rArgSet ))
482 
FillItemSet(SfxItemSet & rArgSet)483 sal_Bool __EXPORT ScTpSubTotalGroup1::FillItemSet( SfxItemSet& rArgSet ) { return FILLSET(1); }
484 
FillItemSet(SfxItemSet & rArgSet)485 sal_Bool __EXPORT ScTpSubTotalGroup2::FillItemSet( SfxItemSet& rArgSet ) { return FILLSET(2); }
486 
FillItemSet(SfxItemSet & rArgSet)487 sal_Bool __EXPORT ScTpSubTotalGroup3::FillItemSet( SfxItemSet& rArgSet ) { return FILLSET(3); }
488 
489 #undef FILL
490 
491 //========================================================================
492 // Optionen-Tabpage:
493 
ScTpSubTotalOptions(Window * pParent,const SfxItemSet & rArgSet)494 ScTpSubTotalOptions::ScTpSubTotalOptions( Window*				pParent,
495 										  const SfxItemSet& 	rArgSet )
496 
497 		:	SfxTabPage		( pParent,
498 							  ScResId( RID_SCPAGE_SUBT_OPTIONS ),
499 							  rArgSet ),
500 			//
501             aFlGroup        ( this, ScResId( FL_GROUP ) ),
502 			aBtnPagebreak	( this, ScResId( BTN_PAGEBREAK ) ),
503 			aBtnCase		( this, ScResId( BTN_CASE ) ),
504 			aBtnSort		( this, ScResId( BTN_SORT ) ),
505             aFlSort         ( this, ScResId( FL_SORT ) ),
506 			aBtnAscending	( this, ScResId( BTN_ASCENDING ) ),
507 			aBtnDescending	( this, ScResId( BTN_DESCENDING ) ),
508 			aBtnFormats 	( this, ScResId( BTN_FORMATS ) ),
509 			aBtnUserDef 	( this, ScResId( BTN_USERDEF ) ),
510 			aLbUserDef		( this, ScResId( LB_USERDEF ) ),
511 			//
512 			pViewData		( NULL ),
513 			pDoc			( NULL ),
514 			nWhichSubTotals ( rArgSet.GetPool()->GetWhich( SID_SUBTOTALS ) ),
515 			rSubTotalData	( ((const ScSubTotalItem&)
516 							  rArgSet.Get( nWhichSubTotals )).
517 								GetSubTotalData() )
518 {
519 	Init();
520 	FreeResource();
521 
522 	aLbUserDef.SetAccessibleRelationLabeledBy(&aBtnUserDef);
523 	aLbUserDef.SetAccessibleName(aBtnUserDef.GetText());
524 }
525 
526 // -----------------------------------------------------------------------
527 
~ScTpSubTotalOptions()528 __EXPORT ScTpSubTotalOptions::~ScTpSubTotalOptions()
529 {
530 }
531 
532 // -----------------------------------------------------------------------
533 
Init()534 void ScTpSubTotalOptions::Init()
535 {
536 	const ScSubTotalItem& rSubTotalItem = (const ScSubTotalItem&)
537 										  GetItemSet().Get( nWhichSubTotals );
538 
539 	pViewData	= rSubTotalItem.GetViewData();
540 	pDoc		= ( pViewData ) ? pViewData->GetDocument() : NULL;
541 
542 	DBG_ASSERT( pViewData && pDoc, "ViewData oder Document nicht gefunden!" );
543 
544 	aBtnSort.SetClickHdl 	( LINK( this, ScTpSubTotalOptions, CheckHdl ) );
545 	aBtnUserDef.SetClickHdl	( LINK( this, ScTpSubTotalOptions, CheckHdl ) );
546 
547 	FillUserSortListBox();
548 }
549 
550 // -----------------------------------------------------------------------
551 
Create(Window * pParent,const SfxItemSet & rArgSet)552 SfxTabPage* __EXPORT ScTpSubTotalOptions::Create( Window*				 pParent,
553 										  const SfxItemSet& 	rArgSet )
554 {
555 	return ( new ScTpSubTotalOptions( pParent, rArgSet ) );
556 }
557 
558 // -----------------------------------------------------------------------
559 
Reset(const SfxItemSet &)560 void __EXPORT ScTpSubTotalOptions::Reset( const SfxItemSet& /* rArgSet */ )
561 {
562 	aBtnPagebreak.Check ( rSubTotalData.bPagebreak );
563 	aBtnCase.Check		( rSubTotalData.bCaseSens );
564 	aBtnFormats.Check	( rSubTotalData.bIncludePattern );
565 	aBtnSort.Check		( rSubTotalData.bDoSort );
566 	aBtnAscending.Check ( rSubTotalData.bAscending );
567 	aBtnDescending.Check( !rSubTotalData.bAscending );
568 
569 	if ( rSubTotalData.bUserDef )
570 	{
571 		aBtnUserDef.Check( sal_True );
572 		aLbUserDef.Enable();
573 		aLbUserDef.SelectEntryPos( rSubTotalData.nUserIndex );
574 	}
575 	else
576 	{
577 		aBtnUserDef.Check( sal_False );
578 		aLbUserDef.Disable();
579 		aLbUserDef.SelectEntryPos( 0 );
580 	}
581 
582 	CheckHdl( &aBtnSort );
583 }
584 
585 // -----------------------------------------------------------------------
586 
FillItemSet(SfxItemSet & rArgSet)587 sal_Bool __EXPORT ScTpSubTotalOptions::FillItemSet( SfxItemSet& rArgSet )
588 {
589 	ScSubTotalParam theSubTotalData;			// auslesen, wenn schon teilweise gefuellt
590 	SfxTabDialog* pDlg = GetTabDialog();
591 	if ( pDlg )
592 	{
593 		const SfxItemSet* pExample = pDlg->GetExampleSet();
594 		const SfxPoolItem* pItem;
595 		if ( pExample && pExample->GetItemState( nWhichSubTotals, sal_True, &pItem ) == SFX_ITEM_SET )
596 			theSubTotalData = ((const ScSubTotalItem*)pItem)->GetSubTotalData();
597 	}
598 
599 	theSubTotalData.bPagebreak		= aBtnPagebreak.IsChecked();
600 	theSubTotalData.bReplace		= sal_True;
601 	theSubTotalData.bCaseSens		= aBtnCase.IsChecked();
602 	theSubTotalData.bIncludePattern = aBtnFormats.IsChecked();
603 	theSubTotalData.bDoSort 		= aBtnSort.IsChecked();
604 	theSubTotalData.bAscending		= aBtnAscending.IsChecked();
605 	theSubTotalData.bUserDef		= aBtnUserDef.IsChecked();
606 	theSubTotalData.nUserIndex		= (aBtnUserDef.IsChecked())
607 									? aLbUserDef.GetSelectEntryPos()
608 									: 0;
609 
610 	rArgSet.Put( ScSubTotalItem( nWhichSubTotals, &theSubTotalData ) );
611 
612 	return sal_True;
613 }
614 
615 // -----------------------------------------------------------------------
616 
FillUserSortListBox()617 void ScTpSubTotalOptions::FillUserSortListBox()
618 {
619 	ScUserList* pUserLists = ScGlobal::GetUserList();
620 
621 	aLbUserDef.Clear();
622 	if ( pUserLists )
623 	{
624 		sal_uInt16 nCount = pUserLists->GetCount();
625 		if ( nCount > 0 )
626 			for ( sal_uInt16 i=0; i<nCount; i++ )
627 				aLbUserDef.InsertEntry( (*pUserLists)[i]->GetString() );
628 	}
629 }
630 
631 // -----------------------------------------------------------------------
632 // Handler:
633 
IMPL_LINK(ScTpSubTotalOptions,CheckHdl,CheckBox *,pBox)634 IMPL_LINK( ScTpSubTotalOptions, CheckHdl, CheckBox *, pBox )
635 {
636 	if ( pBox == &aBtnSort )
637 	{
638 		if ( aBtnSort.IsChecked() )
639 		{
640             aFlSort         .Enable();
641 			aBtnFormats 	.Enable();
642 			aBtnUserDef 	.Enable();
643 			aBtnAscending	.Enable();
644 			aBtnDescending	.Enable();
645 
646 			if ( aBtnUserDef.IsChecked() )
647 				aLbUserDef.Enable();
648 		}
649 		else
650 		{
651             aFlSort         .Disable();
652 			aBtnFormats 	.Disable();
653 			aBtnUserDef 	.Disable();
654 			aBtnAscending	.Disable();
655 			aBtnDescending	.Disable();
656 			aLbUserDef		.Disable();
657 		}
658 	}
659 	else if ( pBox == &aBtnUserDef )
660 	{
661 		if ( aBtnUserDef.IsChecked() )
662 		{
663 			aLbUserDef.Enable();
664 			aLbUserDef.GrabFocus();
665 		}
666 		else
667 			aLbUserDef.Disable();
668 	}
669 
670 	return 0;
671 }
672 
~ScTpSubTotalGroup1()673 __EXPORT ScTpSubTotalGroup1::~ScTpSubTotalGroup1()
674 {
675 }
676 
~ScTpSubTotalGroup2()677 __EXPORT ScTpSubTotalGroup2::~ScTpSubTotalGroup2()
678 {
679 }
680 
~ScTpSubTotalGroup3()681 __EXPORT ScTpSubTotalGroup3::~ScTpSubTotalGroup3()
682 {
683 }
684 
685