xref: /aoo41x/main/sc/source/ui/dbgui/consdlg.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 // System - Includes ---------------------------------------------------------
32 
33 
34 
35 #include <sfx2/dispatch.hxx>
36 
37 // INCLUDE -------------------------------------------------------------------
38 
39 #include "tabvwsh.hxx"
40 #include "uiitems.hxx"
41 #include "dbcolect.hxx"
42 #include "rangenam.hxx"
43 #include "rangeutl.hxx"
44 #include "reffact.hxx"
45 #include "document.hxx"
46 #include "scresid.hxx"
47 
48 #include "globstr.hrc"
49 #include "consdlg.hrc"
50 
51 #define _CONSDLG_CXX
52 #include "consdlg.hxx"
53 #undef _CONSDLG_CXX
54 #include <vcl/msgbox.hxx>
55 
56 #define INFOBOX(id) InfoBox(this, ScGlobal::GetRscString(id)).Execute()
57 
58 //============================================================================
59 //	class ScAreaData
60 
61 class ScAreaData
62 {
63 public:
64 	ScAreaData()  {}
65 	~ScAreaData() {}
66 
67 	void Set( const String& rName, const String& rArea, sal_Bool bDb )
68 				{
69 					aStrName  = rName;
70 					aStrArea  = rArea;
71 					bIsDbArea = bDb;
72 				}
73 
74 	String	aStrName;
75 	String	aStrArea;
76 	sal_Bool	bIsDbArea;
77 };
78 
79 
80 //============================================================================
81 //	class ScConsolidateDialog
82 
83 
84 ScConsolidateDlg::ScConsolidateDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
85 									const SfxItemSet&	rArgSet )
86 
87 	:	ScAnyRefDlg	( pB, pCW, pParent, RID_SCDLG_CONSOLIDATE ),
88 		//
89 		aFtFunc			( this, ScResId( FT_FUNC ) ),
90 		aLbFunc			( this, ScResId( LB_FUNC ) ),
91 
92 		aFtConsAreas	( this, ScResId( FT_CONSAREAS ) ),
93 		aLbConsAreas	( this, ScResId( LB_CONSAREAS ) ),
94 
95 		aLbDataArea		( this, ScResId( LB_DATA_AREA ) ),
96 		aFtDataArea		( this, ScResId( FT_DATA_AREA ) ),
97         aEdDataArea     ( this, this, ScResId( ED_DATA_AREA ) ),
98 		aRbDataArea		( this, ScResId( RB_DATA_AREA ), &aEdDataArea, this ),
99 
100 		aLbDestArea		( this, ScResId( LB_DEST_AREA ) ),
101 		aFtDestArea		( this, ScResId( FT_DEST_AREA ) ),
102         aEdDestArea     ( this, this, ScResId( ED_DEST_AREA ) ),
103 		aRbDestArea		( this, ScResId( RB_DEST_AREA ), &aEdDestArea, this),
104 
105         aFlConsBy       ( this, ScResId( FL_CONSBY ) ),
106 		aBtnByRow		( this, ScResId( BTN_BYROW ) ),
107 		aBtnByCol		( this, ScResId( BTN_BYCOL) ),
108 
109         aFlSep          ( this, ScResId( FL_SEP ) ),
110         aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
111 		aBtnRefs		( this, ScResId( BTN_REFS ) ),
112 
113 		aBtnOk			( this, ScResId( BTN_OK ) ),
114 		aBtnCancel		( this, ScResId( BTN_CANCEL ) ),
115 		aBtnHelp		( this, ScResId( BTN_HELP ) ),
116 		aBtnAdd			( this, ScResId( BTN_ADD ) ),
117 		aBtnRemove		( this, ScResId( BTN_REMOVE ) ),
118 		aBtnMore		( this, ScResId( BTN_MORE ) ),
119 
120 		aStrUndefined	( ScResId( SCSTR_UNDEFINED ) ),
121 		//
122 		theConsData		( ((const ScConsolidateItem&)
123 						   rArgSet.Get( rArgSet.GetPool()->
124 											GetWhich( SID_CONSOLIDATE ) )
125 									  ).GetData() ),
126 		pViewData		( ((ScTabViewShell*)SfxViewShell::Current())->
127 								GetViewData() ),
128 		pDoc			( ((ScTabViewShell*)SfxViewShell::Current())->
129 								GetViewData()->GetDocument() ),
130 		pRangeUtil		( new ScRangeUtil ),
131 		pAreaData		( NULL ),
132 		nAreaDataCount	( 0 ),
133 		nWhichCons		( rArgSet.GetPool()->GetWhich( SID_CONSOLIDATE ) ),
134 
135 		pRefInputEdit	( &aEdDataArea )
136 {
137 	Init();
138 	FreeResource();
139 }
140 
141 
142 //----------------------------------------------------------------------------
143 
144 __EXPORT ScConsolidateDlg::~ScConsolidateDlg()
145 {
146 	delete [] pAreaData;
147 	delete pRangeUtil;
148 }
149 
150 
151 //----------------------------------------------------------------------------
152 
153 void ScConsolidateDlg::Init()
154 {
155 	DBG_ASSERT( pViewData && pDoc && pRangeUtil, "Error in Ctor" );
156 
157 	String aStr;
158 	sal_uInt16 i=0;
159 
160 	aEdDataArea	.SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
161 	aEdDestArea	.SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
162 	aLbDataArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
163 	aLbDestArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
164 	aEdDataArea	.SetModifyHdl	( LINK( this, ScConsolidateDlg, ModifyHdl ) );
165 	aEdDestArea	.SetModifyHdl	( LINK( this, ScConsolidateDlg, ModifyHdl ) );
166 	aLbConsAreas.SetSelectHdl	( LINK( this, ScConsolidateDlg, SelectHdl ) );
167 	aLbDataArea .SetSelectHdl	( LINK( this, ScConsolidateDlg, SelectHdl ) );
168 	aLbDestArea .SetSelectHdl	( LINK( this, ScConsolidateDlg, SelectHdl ) );
169 	aBtnOk		.SetClickHdl	( LINK( this, ScConsolidateDlg, OkHdl ) );
170 	aBtnCancel	.SetClickHdl	( LINK( this, ScConsolidateDlg, ClickHdl ) );
171 	aBtnAdd		.SetClickHdl	( LINK( this, ScConsolidateDlg, ClickHdl ) );
172 	aBtnRemove	.SetClickHdl	( LINK( this, ScConsolidateDlg, ClickHdl ) );
173 
174     aBtnMore.AddWindow( &aFlConsBy );
175 	aBtnMore.AddWindow( &aBtnByRow );
176 	aBtnMore.AddWindow( &aBtnByCol );
177     aBtnMore.AddWindow( &aFlSep );
178     aBtnMore.AddWindow( &aFlOptions );
179 	aBtnMore.AddWindow( &aBtnRefs );
180 
181 	aBtnAdd.Disable();
182 	aBtnRemove.Disable();
183 
184 	aBtnByRow.Check( theConsData.bByRow );
185 	aBtnByCol.Check( theConsData.bByCol );
186 	aBtnRefs .Check( theConsData.bReferenceData );
187 
188 	aLbFunc.SelectEntryPos( FuncToLbPos( theConsData.eFunction ) );
189 
190 	// Einlesen der Konsolidierungsbereiche
191 	aLbConsAreas.Clear();
192     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
193 	for ( i=0; i<theConsData.nDataAreaCount; i++ )
194 	{
195 		const ScArea& rArea = *(theConsData.ppDataAreas[i] );
196 		if ( rArea.nTab < pDoc->GetTableCount() )
197 		{
198             ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
199                     rArea.nColEnd, rArea.nRowEnd, rArea.nTab ).Format( aStr,
200                         SCR_ABS_3D, pDoc, eConv );
201             aLbConsAreas.InsertEntry( aStr );
202         }
203     }
204 
205 	if ( theConsData.nTab < pDoc->GetTableCount() )
206     {
207         ScAddress( theConsData.nCol, theConsData.nRow, theConsData.nTab
208                 ).Format( aStr, SCA_ABS_3D, pDoc, eConv );
209         aEdDestArea.SetText( aStr );
210     }
211 	else
212 		aEdDestArea.SetText( EMPTY_STRING );
213 
214 	//----------------------------------------------------------
215 
216 	/*
217 	 * Aus den RangeNames und Datenbankbereichen werden sich
218 	 * in der Hilfsklasse ScAreaData die Bereichsnamen gemerkt,
219 	 * die in den ListBoxen erscheinen.
220 	 */
221 
222 	ScRangeName*    pRangeNames  = pDoc->GetRangeName();
223 	ScDBCollection* pDbNames     = pDoc->GetDBCollection();
224 	const sal_uInt16    nRangeCount  = pRangeNames ? pRangeNames->GetCount() : 0;
225 	const sal_uInt16    nDbCount	 = pDbNames	   ? pDbNames   ->GetCount() : 0;
226 
227 	nAreaDataCount = nRangeCount+nDbCount;
228 	pAreaData	   = NULL;
229 
230 	if ( nAreaDataCount > 0 )
231 	{
232 		pAreaData = new ScAreaData[nAreaDataCount];
233 
234 		String aStrName;
235 		String aStrArea;
236 		sal_uInt16 nAt = 0;
237 		ScRange aRange;
238 		ScAreaNameIterator aIter( pDoc );
239 		while ( aIter.Next( aStrName, aRange ) )
240 		{
241 			aRange.Format( aStrArea, SCA_ABS_3D, pDoc, eConv );
242 			pAreaData[nAt++].Set( aStrName, aStrArea, aIter.WasDBName() );
243 		}
244 	}
245 
246 	FillAreaLists();
247 	ModifyHdl( &aEdDestArea );
248 	aLbDataArea.SelectEntryPos( 0 );
249 	aEdDataArea.SetText( EMPTY_STRING );
250 	aEdDataArea.GrabFocus();
251 
252     aFlSep.SetStyle( aFlSep.GetStyle() | WB_VERT );
253 
254 	//@BugID 54702 Enablen/Disablen nur noch in Basisklasse
255 	//SFX_APPWINDOW->Enable();
256 }
257 
258 
259 //----------------------------------------------------------------------------
260 void ScConsolidateDlg::FillAreaLists()
261 {
262 	aLbDataArea.Clear();
263 	aLbDestArea.Clear();
264 	aLbDataArea.InsertEntry( aStrUndefined );
265 	aLbDestArea.InsertEntry( aStrUndefined );
266 
267 	if ( pRangeUtil && pAreaData && (nAreaDataCount > 0) )
268 	{
269 		String aString;
270 
271 		for ( sal_uInt16 i=0;
272 			  (i<nAreaDataCount) && (pAreaData[i].aStrName.Len()>0);
273 			  i++ )
274 		{
275 			aLbDataArea.InsertEntry( pAreaData[i].aStrName, i+1 );
276 
277 //			if ( !pAreaData[i].bIsDbArea )
278 				aLbDestArea.InsertEntry( pAreaData[i].aStrName, i+1 );
279 		}
280 	}
281 }
282 
283 
284 //----------------------------------------------------------------------------
285 // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
286 //  neue Selektion im Referenz-Fenster angezeigt wird.
287 
288 
289 void ScConsolidateDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
290 {
291 	if ( pRefInputEdit )
292 	{
293 		if ( rRef.aStart != rRef.aEnd )
294 			RefInputStart( pRefInputEdit );
295 
296 		String		aStr;
297 		sal_uInt16	 	nFmt = SCR_ABS_3D;		 //!!! nCurTab fehlt noch
298         const formula::FormulaGrammar::AddressConvention eConv = pDocP->GetAddressConvention();
299 
300 		if ( rRef.aStart.Tab() != rRef.aEnd.Tab() )
301 			nFmt |= SCA_TAB2_3D;
302 
303 		if ( pRefInputEdit == &aEdDataArea)
304             rRef.Format( aStr, nFmt, pDocP, eConv );
305 		else if ( pRefInputEdit == &aEdDestArea )
306             rRef.aStart.Format( aStr, nFmt, pDocP, eConv );
307 
308 		pRefInputEdit->SetRefString( aStr );
309 	}
310 
311 	ModifyHdl( pRefInputEdit );
312 }
313 
314 
315 //----------------------------------------------------------------------------
316 
317 sal_Bool __EXPORT ScConsolidateDlg::Close()
318 {
319 	return DoClose( ScConsolidateDlgWrapper::GetChildWindowId() );
320 }
321 
322 
323 //----------------------------------------------------------------------------
324 
325 void ScConsolidateDlg::SetActive()
326 {
327 	if ( bDlgLostFocus )
328 	{
329 		bDlgLostFocus = sal_False;
330 
331 		if ( pRefInputEdit )
332 		{
333 			pRefInputEdit->GrabFocus();
334 			ModifyHdl( pRefInputEdit );
335 		}
336 	}
337 	else
338 		GrabFocus();
339 
340 	RefInputDone();
341 }
342 
343 
344 //----------------------------------------------------------------------------
345 
346 void __EXPORT ScConsolidateDlg::Deactivate()
347 {
348 	bDlgLostFocus = sal_True;
349 }
350 
351 
352 //----------------------------------------------------------------------------
353 
354 sal_Bool ScConsolidateDlg::VerifyEdit( formula::RefEdit* pEd )
355 {
356 	if ( !pRangeUtil || !pDoc || !pViewData ||
357 		 ((pEd != &aEdDataArea) && (pEd != &aEdDestArea)) )
358 		return sal_False;
359 
360 	SCTAB	nTab	= pViewData->GetTabNo();
361 	sal_Bool	bEditOk = sal_False;
362 	String	theCompleteStr;
363     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
364 
365 	if ( pEd == &aEdDataArea )
366 	{
367 		bEditOk = pRangeUtil->IsAbsArea( pEd->GetText(), pDoc,
368 										 nTab, &theCompleteStr, NULL, NULL, eConv );
369 	}
370 	else if ( pEd == &aEdDestArea )
371 	{
372 		String aPosStr;
373 
374 		pRangeUtil->CutPosString( pEd->GetText(), aPosStr );
375 		bEditOk = pRangeUtil->IsAbsPos( aPosStr, pDoc,
376 										nTab, &theCompleteStr, NULL, eConv );
377 	}
378 
379 	if ( bEditOk )
380 		pEd->SetText( theCompleteStr );
381 
382 	return bEditOk;
383 }
384 
385 
386 //----------------------------------------------------------------------------
387 // Handler:
388 // ========
389 
390 IMPL_LINK( ScConsolidateDlg, GetFocusHdl, Control*, pCtr )
391 {
392 	if ( pCtr ==(Control*)&aEdDataArea ||
393 		 pCtr ==(Control*)&aEdDestArea)
394 	{
395 		pRefInputEdit = (formula::RefEdit*)pCtr;
396 	}
397 	else if(pCtr ==(Control*)&aLbDataArea )
398 	{
399 		pRefInputEdit = &aEdDataArea;
400 	}
401 	else if(pCtr ==(Control*)&aLbDestArea )
402 	{
403 		pRefInputEdit = &aEdDestArea;
404 	}
405 	return 0;
406 }
407 
408 
409 //----------------------------------------------------------------------------
410 
411 IMPL_LINK( ScConsolidateDlg, OkHdl, void*, EMPTYARG )
412 {
413 	sal_uInt16 nDataAreaCount = aLbConsAreas.GetEntryCount();
414 
415 	if ( nDataAreaCount > 0 )
416 	{
417 		ScRefAddress aDestAddress;
418 		SCTAB		nTab = pViewData->GetTabNo();
419 		String		aDestPosStr( aEdDestArea.GetText() );
420         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
421 
422 		if ( pRangeUtil->IsAbsPos( aDestPosStr, pDoc, nTab, NULL, &aDestAddress, eConv ) )
423 		{
424 			ScConsolidateParam	theOutParam( theConsData );
425 			ScArea**			ppDataAreas = new ScArea*[nDataAreaCount];
426 			ScArea*				pArea;
427 			sal_uInt16				i=0;
428 
429 			for ( i=0; i<nDataAreaCount; i++ )
430 			{
431 				pArea = new ScArea;
432 				pRangeUtil->MakeArea( aLbConsAreas.GetEntry( i ),
433 									  *pArea, pDoc, nTab, eConv );
434 				ppDataAreas[i] = pArea;
435 			}
436 
437 			theOutParam.nCol			= aDestAddress.Col();
438 			theOutParam.nRow			= aDestAddress.Row();
439 			theOutParam.nTab			= aDestAddress.Tab();
440 			theOutParam.eFunction		= LbPosToFunc( aLbFunc.GetSelectEntryPos() );
441 			theOutParam.bByCol			= aBtnByCol.IsChecked();
442 			theOutParam.bByRow			= aBtnByRow.IsChecked();
443 			theOutParam.bReferenceData	= aBtnRefs.IsChecked();
444 			theOutParam.SetAreas( ppDataAreas, nDataAreaCount );
445 
446 			for ( i=0; i<nDataAreaCount; i++ )
447 				delete ppDataAreas[i];
448 			delete [] ppDataAreas;
449 
450 			ScConsolidateItem aOutItem( nWhichCons, &theOutParam );
451 
452 			SetDispatcherLock( sal_False );
453 			SwitchToDocument();
454 			GetBindings().GetDispatcher()->Execute( SID_CONSOLIDATE,
455 									  SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
456 									  &aOutItem, 0L, 0L );
457 			Close();
458 		}
459 		else
460 		{
461 			INFOBOX( STR_INVALID_TABREF );
462 			aEdDestArea.GrabFocus();
463 		}
464 	}
465 	else
466 		Close(); // keine Datenbereiche definiert -> Cancel
467 	return 0;
468 }
469 
470 
471 //----------------------------------------------------------------------------
472 
473 IMPL_LINK( ScConsolidateDlg, ClickHdl, PushButton*, pBtn )
474 {
475 	if ( pBtn == &aBtnCancel )
476 		Close();
477 	else if ( pBtn == &aBtnAdd )
478 	{
479 		if ( aEdDataArea.GetText().Len() > 0 )
480 		{
481 			String		aNewEntry( aEdDataArea.GetText() );
482 			ScArea**	ppAreas = NULL;
483 			sal_uInt16		nAreaCount = 0;
484             const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
485 
486 			if ( pRangeUtil->IsAbsTabArea( aNewEntry, pDoc, &ppAreas, &nAreaCount, sal_True, eConv ) )
487 			{
488 				// IsAbsTabArea() legt ein Array von ScArea-Zeigern an,
489 				// welche ebenfalls dynamisch erzeugt wurden.
490 				// Diese Objekte muessen hier abgeraeumt werden.
491 
492 				for ( sal_uInt16 i=0; i<nAreaCount; i++ )
493 				{
494 					String aNewArea;
495 
496 					if ( ppAreas[i] )
497 					{
498                         const ScArea& rArea = *(ppAreas[i]);
499                         ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
500                                 rArea.nColEnd, rArea.nRowEnd, rArea.nTab
501                                 ).Format( aNewArea, SCR_ABS_3D, pDoc, eConv );
502 
503 						if ( aLbConsAreas.GetEntryPos( aNewArea )
504 							 == LISTBOX_ENTRY_NOTFOUND )
505 						{
506 							aLbConsAreas.InsertEntry( aNewArea );
507 						}
508 						delete ppAreas[i];
509 					}
510 				}
511 				delete [] ppAreas;
512 			}
513 			else if ( VerifyEdit( &aEdDataArea ) )
514 			{
515 				String aNewArea( aEdDataArea.GetText() );
516 
517 				if ( aLbConsAreas.GetEntryPos( aNewArea ) == LISTBOX_ENTRY_NOTFOUND )
518 					aLbConsAreas.InsertEntry( aNewArea );
519 				else
520 					INFOBOX( STR_AREA_ALREADY_INSERTED );
521 			}
522 			else
523 			{
524 				INFOBOX( STR_INVALID_TABREF );
525 				aEdDataArea.GrabFocus();
526 			}
527 		}
528 	}
529 	else if ( pBtn == &aBtnRemove )
530 	{
531 		while ( aLbConsAreas.GetSelectEntryCount() )
532 			aLbConsAreas.RemoveEntry( aLbConsAreas.GetSelectEntryPos() );
533 		aBtnRemove.Disable();
534 	}
535 	return 0;
536 }
537 
538 
539 //----------------------------------------------------------------------------
540 
541 IMPL_LINK( ScConsolidateDlg, SelectHdl, ListBox*, pLb )
542 {
543 	if ( pLb == &aLbConsAreas )
544 	{
545 		if ( aLbConsAreas.GetSelectEntryCount() > 0 )
546 			aBtnRemove.Enable();
547 		else
548 			aBtnRemove.Disable();
549 	}
550 	else if ( (pLb == &aLbDataArea) || (pLb == &aLbDestArea) )
551 	{
552 		Edit*	pEd = (pLb == &aLbDataArea) ? &aEdDataArea : &aEdDestArea;
553 		sal_uInt16	nSelPos = pLb->GetSelectEntryPos();
554 
555 		if (    pRangeUtil
556 			&& (nSelPos > 0)
557 			&& (nAreaDataCount > 0)
558 			&& (pAreaData != NULL) )
559 		{
560 			if ( nSelPos <= nAreaDataCount )
561 			{
562 				String aString( pAreaData[nSelPos-1].aStrArea );
563 
564 				if ( pLb == &aLbDestArea )
565 					pRangeUtil->CutPosString( aString, aString );
566 
567 				pEd->SetText( aString );
568 
569 				if ( pEd == &aEdDataArea )
570 					aBtnAdd.Enable();
571 			}
572 		}
573 		else
574 		{
575 			pEd->SetText( EMPTY_STRING );
576 			if ( pEd == &aEdDataArea )
577 				aBtnAdd.Enable();
578 		}
579 	}
580 	return 0;
581 }
582 
583 
584 //----------------------------------------------------------------------------
585 
586 IMPL_LINK( ScConsolidateDlg, ModifyHdl, formula::RefEdit*, pEd )
587 {
588 	if ( pEd == &aEdDataArea )
589 	{
590 		String aAreaStr( pEd->GetText() );
591 		if ( aAreaStr.Len() > 0 )
592 		{
593 			aBtnAdd.Enable();
594 		}
595 		else
596 			aBtnAdd.Disable();
597 	}
598 	else if ( pEd == &aEdDestArea )
599 	{
600 		aLbDestArea.SelectEntryPos(0);
601 	}
602 	return 0;
603 }
604 
605 
606 //----------------------------------------------------------------------------
607 // Verallgemeinern!!! :
608 // Resource der ListBox und diese beiden Umrechnungsmethoden gibt es
609 // auch noch in tpsubt bzw. ueberall, wo StarCalc-Funktionen
610 // auswaehlbar sind.
611 
612 ScSubTotalFunc ScConsolidateDlg::LbPosToFunc( sal_uInt16 nPos )
613 {
614 	switch ( nPos )
615 	{
616 		case  2:	return SUBTOTAL_FUNC_AVE;
617 		case  6:	return SUBTOTAL_FUNC_CNT;
618 		case  1:	return SUBTOTAL_FUNC_CNT2;
619 		case  3:	return SUBTOTAL_FUNC_MAX;
620 		case  4:	return SUBTOTAL_FUNC_MIN;
621 		case  5:	return SUBTOTAL_FUNC_PROD;
622 		case  7:	return SUBTOTAL_FUNC_STD;
623 		case  8:	return SUBTOTAL_FUNC_STDP;
624 		case  9:	return SUBTOTAL_FUNC_VAR;
625 		case 10:	return SUBTOTAL_FUNC_VARP;
626 		case  0:
627 		default:
628 			return SUBTOTAL_FUNC_SUM;
629 	}
630 }
631 
632 
633 //----------------------------------------------------------------------------
634 
635 sal_uInt16 ScConsolidateDlg::FuncToLbPos( ScSubTotalFunc eFunc )
636 {
637 	switch ( eFunc )
638 	{
639 		case SUBTOTAL_FUNC_AVE:		return 2;
640 		case SUBTOTAL_FUNC_CNT:		return 6;
641 		case SUBTOTAL_FUNC_CNT2:	return 1;
642 		case SUBTOTAL_FUNC_MAX:		return 3;
643 		case SUBTOTAL_FUNC_MIN:		return 4;
644 		case SUBTOTAL_FUNC_PROD:	return 5;
645 		case SUBTOTAL_FUNC_STD:		return 7;
646 		case SUBTOTAL_FUNC_STDP:	return 8;
647 		case SUBTOTAL_FUNC_VAR:		return 9;
648 		case SUBTOTAL_FUNC_VARP:	return 10;
649 		case SUBTOTAL_FUNC_NONE:
650 		case SUBTOTAL_FUNC_SUM:
651 		default:
652 			return 0;
653 	}
654 }
655 
656