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