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