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