xref: /AOO41X/main/sc/source/ui/dbgui/foptmgr.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir // System - Includes ---------------------------------------------------------
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // INCLUDE -------------------------------------------------------------------
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include <vcl/morebtn.hxx>
38*cdf0e10cSrcweir #include <svtools/stdctrl.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir #include "anyrefdg.hxx"
41*cdf0e10cSrcweir #include "rangeutl.hxx"
42*cdf0e10cSrcweir #include "dbcolect.hxx"
43*cdf0e10cSrcweir #include "viewdata.hxx"
44*cdf0e10cSrcweir #include "document.hxx"
45*cdf0e10cSrcweir #include "queryparam.hxx"
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir #define _FOPTMGR_CXX
48*cdf0e10cSrcweir #include "foptmgr.hxx"
49*cdf0e10cSrcweir #undef _FOPTMGR_CXX
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir //----------------------------------------------------------------------------
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir ScFilterOptionsMgr::ScFilterOptionsMgr(
54*cdf0e10cSrcweir 								Dialog*				ptrDlg,
55*cdf0e10cSrcweir 								ScViewData*			ptrViewData,
56*cdf0e10cSrcweir 								const ScQueryParam&	refQueryData,
57*cdf0e10cSrcweir 								MoreButton&			refBtnMore,
58*cdf0e10cSrcweir 								CheckBox&			refBtnCase,
59*cdf0e10cSrcweir 								CheckBox&			refBtnRegExp,
60*cdf0e10cSrcweir 								CheckBox&			refBtnHeader,
61*cdf0e10cSrcweir 								CheckBox&			refBtnUnique,
62*cdf0e10cSrcweir 								CheckBox&			refBtnCopyResult,
63*cdf0e10cSrcweir 								CheckBox&			refBtnDestPers,
64*cdf0e10cSrcweir 								ListBox&			refLbCopyArea,
65*cdf0e10cSrcweir 								Edit&				refEdCopyArea,
66*cdf0e10cSrcweir 								formula::RefButton&		refRbCopyArea,
67*cdf0e10cSrcweir 								FixedText&			refFtDbAreaLabel,
68*cdf0e10cSrcweir 								FixedInfo&			refFtDbArea,
69*cdf0e10cSrcweir                                 FixedLine&          refFlOptions,
70*cdf0e10cSrcweir 								const String&		refStrNoName,
71*cdf0e10cSrcweir 								const String&		refStrUndefined )
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	:	pDlg			( ptrDlg ),
74*cdf0e10cSrcweir 		pViewData		( ptrViewData ),
75*cdf0e10cSrcweir 		pDoc			( ptrViewData ? ptrViewData->GetDocument() : NULL ),
76*cdf0e10cSrcweir 		rBtnMore		( refBtnMore ),
77*cdf0e10cSrcweir 		rBtnCase		( refBtnCase ),
78*cdf0e10cSrcweir 		rBtnRegExp		( refBtnRegExp ),
79*cdf0e10cSrcweir 		rBtnHeader		( refBtnHeader ),
80*cdf0e10cSrcweir 		rBtnUnique		( refBtnUnique ),
81*cdf0e10cSrcweir 		rBtnCopyResult	( refBtnCopyResult ),
82*cdf0e10cSrcweir 		rBtnDestPers	( refBtnDestPers ),
83*cdf0e10cSrcweir 		rLbCopyPos		( refLbCopyArea ),
84*cdf0e10cSrcweir 		rEdCopyPos		( refEdCopyArea ),
85*cdf0e10cSrcweir 		rRbCopyPos		( refRbCopyArea ),
86*cdf0e10cSrcweir 		rFtDbAreaLabel	( refFtDbAreaLabel ),
87*cdf0e10cSrcweir 		rFtDbArea		( refFtDbArea ),
88*cdf0e10cSrcweir         rFlOptions      ( refFlOptions ),
89*cdf0e10cSrcweir 		rStrNoName		( refStrNoName ),
90*cdf0e10cSrcweir 		rStrUndefined	( refStrUndefined ),
91*cdf0e10cSrcweir 		rQueryData		( refQueryData )
92*cdf0e10cSrcweir {
93*cdf0e10cSrcweir 	Init();
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir //----------------------------------------------------------------------------
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir ScFilterOptionsMgr::~ScFilterOptionsMgr()
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir 	sal_uInt16 nEntries = rLbCopyPos.GetEntryCount();
102*cdf0e10cSrcweir 	sal_uInt16 i;
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir 	for ( i=2; i<nEntries; i++ )
105*cdf0e10cSrcweir 		delete (String*)rLbCopyPos.GetEntryData( i );
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir //----------------------------------------------------------------------------
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir void ScFilterOptionsMgr::Init()
112*cdf0e10cSrcweir {
113*cdf0e10cSrcweir 	DBG_ASSERT( pViewData && pDoc, "Init failed :-/" );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 	rLbCopyPos.SetSelectHdl	 ( LINK( this, ScFilterOptionsMgr, LbPosSelHdl ) );
116*cdf0e10cSrcweir 	rEdCopyPos.SetModifyHdl	 ( LINK( this, ScFilterOptionsMgr, EdPosModifyHdl ) );
117*cdf0e10cSrcweir 	rBtnCopyResult.SetClickHdl( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rBtnCase );
120*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rBtnRegExp );
121*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rBtnHeader );
122*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rBtnUnique );
123*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rBtnCopyResult );
124*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rBtnDestPers );
125*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rLbCopyPos );
126*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rEdCopyPos );
127*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rRbCopyPos );
128*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rFtDbAreaLabel );
129*cdf0e10cSrcweir 	rBtnMore.AddWindow( &rFtDbArea );
130*cdf0e10cSrcweir     rBtnMore.AddWindow( &rFlOptions );
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 	rBtnCase	.Check( rQueryData.bCaseSens );
133*cdf0e10cSrcweir 	rBtnHeader	.Check( rQueryData.bHasHeader );
134*cdf0e10cSrcweir 	rBtnRegExp	.Check( rQueryData.bRegExp );
135*cdf0e10cSrcweir 	rBtnUnique	.Check( !rQueryData.bDuplicate );
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 	if ( pViewData && pDoc )
138*cdf0e10cSrcweir 	{
139*cdf0e10cSrcweir 		String			theAreaStr;
140*cdf0e10cSrcweir 		ScRange			theCurArea ( ScAddress( rQueryData.nCol1,
141*cdf0e10cSrcweir 												rQueryData.nRow1,
142*cdf0e10cSrcweir 												pViewData->GetTabNo() ),
143*cdf0e10cSrcweir 									 ScAddress( rQueryData.nCol2,
144*cdf0e10cSrcweir 												rQueryData.nRow2,
145*cdf0e10cSrcweir 												pViewData->GetTabNo() ) );
146*cdf0e10cSrcweir 		ScDBCollection*	pDBColl		= pDoc->GetDBCollection();
147*cdf0e10cSrcweir 		String			theDbArea;
148*cdf0e10cSrcweir 		String			theDbName	= rStrNoName;
149*cdf0e10cSrcweir         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 		theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, eConv );
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 		// Zielbereichsliste fuellen
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir 		rLbCopyPos.Clear();
156*cdf0e10cSrcweir 		rLbCopyPos.InsertEntry( rStrUndefined, 0 );
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 		ScAreaNameIterator aIter( pDoc );
159*cdf0e10cSrcweir 		String aName;
160*cdf0e10cSrcweir 		ScRange aRange;
161*cdf0e10cSrcweir 		String aRefStr;
162*cdf0e10cSrcweir 		while ( aIter.Next( aName, aRange ) )
163*cdf0e10cSrcweir 		{
164*cdf0e10cSrcweir 			sal_uInt16 nInsert = rLbCopyPos.InsertEntry( aName );
165*cdf0e10cSrcweir 
166*cdf0e10cSrcweir 			aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv );
167*cdf0e10cSrcweir 			rLbCopyPos.SetEntryData( nInsert, new String( aRefStr ) );
168*cdf0e10cSrcweir 		}
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 		rBtnDestPers.Check( sal_True );			// beim Aufruf immer an
171*cdf0e10cSrcweir 		rLbCopyPos.SelectEntryPos( 0 );
172*cdf0e10cSrcweir 		rEdCopyPos.SetText( EMPTY_STRING );
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir 		/*
175*cdf0e10cSrcweir 		 * Ueberpruefen, ob es sich bei dem uebergebenen
176*cdf0e10cSrcweir 		 * Bereich um einen Datenbankbereich handelt:
177*cdf0e10cSrcweir 		 */
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir 		theDbArea = theAreaStr;
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir 		if ( pDBColl )
182*cdf0e10cSrcweir 		{
183*cdf0e10cSrcweir 			ScAddress&	rStart	= theCurArea.aStart;
184*cdf0e10cSrcweir 			ScAddress&	rEnd	= theCurArea.aEnd;
185*cdf0e10cSrcweir 			ScDBData*	pDBData = pDBColl->GetDBAtArea(	rStart.Tab(),
186*cdf0e10cSrcweir 														rStart.Col(), rStart.Row(),
187*cdf0e10cSrcweir 														rEnd.Col(),   rEnd.Row() );
188*cdf0e10cSrcweir 			if ( pDBData )
189*cdf0e10cSrcweir 			{
190*cdf0e10cSrcweir 				rBtnHeader.Check( pDBData->HasHeader() );
191*cdf0e10cSrcweir 				pDBData->GetName( theDbName );
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir 				if ( theDbName != rStrNoName )
194*cdf0e10cSrcweir 				{
195*cdf0e10cSrcweir 					rBtnHeader.Disable();
196*cdf0e10cSrcweir 				}
197*cdf0e10cSrcweir 			}
198*cdf0e10cSrcweir 		}
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 		theDbArea.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
201*cdf0e10cSrcweir 		theDbArea += theDbName;
202*cdf0e10cSrcweir 		theDbArea += ')';
203*cdf0e10cSrcweir 		rFtDbArea.SetText( theDbArea );
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir 		//------------------------------------------------------
206*cdf0e10cSrcweir 		// Kopierposition:
207*cdf0e10cSrcweir 
208*cdf0e10cSrcweir 		if ( !rQueryData.bInplace )
209*cdf0e10cSrcweir 		{
210*cdf0e10cSrcweir 			String aString;
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir 			ScAddress( rQueryData.nDestCol,
213*cdf0e10cSrcweir 					   rQueryData.nDestRow,
214*cdf0e10cSrcweir 					   rQueryData.nDestTab
215*cdf0e10cSrcweir 					 ).Format( aString, SCA_ABS_3D, pDoc, eConv );
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 			rBtnCopyResult.Check( sal_True );
218*cdf0e10cSrcweir 			rEdCopyPos.SetText( aString );
219*cdf0e10cSrcweir 			EdPosModifyHdl( &rEdCopyPos );
220*cdf0e10cSrcweir 			rLbCopyPos.Enable();
221*cdf0e10cSrcweir 			rEdCopyPos.Enable();
222*cdf0e10cSrcweir 			rRbCopyPos.Enable();
223*cdf0e10cSrcweir 			rBtnDestPers.Enable();
224*cdf0e10cSrcweir 		}
225*cdf0e10cSrcweir 		else
226*cdf0e10cSrcweir 		{
227*cdf0e10cSrcweir 			rBtnCopyResult.Check( sal_False );
228*cdf0e10cSrcweir 			rEdCopyPos.SetText( EMPTY_STRING );
229*cdf0e10cSrcweir 			rLbCopyPos.Disable();
230*cdf0e10cSrcweir 			rEdCopyPos.Disable();
231*cdf0e10cSrcweir 			rRbCopyPos.Disable();
232*cdf0e10cSrcweir 			rBtnDestPers.Disable();
233*cdf0e10cSrcweir 		}
234*cdf0e10cSrcweir 	}
235*cdf0e10cSrcweir 	else
236*cdf0e10cSrcweir 		rEdCopyPos.SetText( EMPTY_STRING );
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir //----------------------------------------------------------------------------
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir sal_Bool ScFilterOptionsMgr::VerifyPosStr( const String& rPosStr ) const
243*cdf0e10cSrcweir {
244*cdf0e10cSrcweir 	String aPosStr( rPosStr );
245*cdf0e10cSrcweir 	xub_StrLen nColonPos = aPosStr.Search( ':' );
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir 	if ( STRING_NOTFOUND != nColonPos )
248*cdf0e10cSrcweir 		aPosStr.Erase( nColonPos );
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 	sal_uInt16 nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() );
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 	return ( SCA_VALID == (nResult & SCA_VALID) );
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir //----------------------------------------------------------------------------
257*cdf0e10cSrcweir // Handler:
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir //----------------------------------------------------------------------------
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir IMPL_LINK( ScFilterOptionsMgr, LbPosSelHdl, ListBox*, pLb )
262*cdf0e10cSrcweir {
263*cdf0e10cSrcweir 	if ( pLb == &rLbCopyPos )
264*cdf0e10cSrcweir 	{
265*cdf0e10cSrcweir 		String aString;
266*cdf0e10cSrcweir 		sal_uInt16 nSelPos = rLbCopyPos.GetSelectEntryPos();
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 		if ( nSelPos > 0 )
269*cdf0e10cSrcweir 			aString = *(String*)rLbCopyPos.GetEntryData( nSelPos );
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir 		rEdCopyPos.SetText( aString );
272*cdf0e10cSrcweir 	}
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir 	return 0;
275*cdf0e10cSrcweir }
276*cdf0e10cSrcweir 
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir //----------------------------------------------------------------------------
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir IMPL_LINK( ScFilterOptionsMgr, EdPosModifyHdl, Edit*, pEd )
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	if ( pEd == &rEdCopyPos )
283*cdf0e10cSrcweir 	{
284*cdf0e10cSrcweir 		String	theCurPosStr = pEd->GetText();
285*cdf0e10cSrcweir 		sal_uInt16	nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir 		if ( SCA_VALID == (nResult & SCA_VALID) )
288*cdf0e10cSrcweir 		{
289*cdf0e10cSrcweir 			String*	pStr	= NULL;
290*cdf0e10cSrcweir 			sal_Bool	bFound	= sal_False;
291*cdf0e10cSrcweir 			sal_uInt16	i		= 0;
292*cdf0e10cSrcweir 			sal_uInt16	nCount	= rLbCopyPos.GetEntryCount();
293*cdf0e10cSrcweir 
294*cdf0e10cSrcweir 			for ( i=2; i<nCount && !bFound; i++ )
295*cdf0e10cSrcweir 			{
296*cdf0e10cSrcweir 				pStr = (String*)rLbCopyPos.GetEntryData( i );
297*cdf0e10cSrcweir 				bFound = (theCurPosStr == *pStr);
298*cdf0e10cSrcweir 			}
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir 			if ( bFound )
301*cdf0e10cSrcweir 				rLbCopyPos.SelectEntryPos( --i );
302*cdf0e10cSrcweir 			else
303*cdf0e10cSrcweir 				rLbCopyPos.SelectEntryPos( 0 );
304*cdf0e10cSrcweir 		}
305*cdf0e10cSrcweir 		else
306*cdf0e10cSrcweir 			rLbCopyPos.SelectEntryPos( 0 );
307*cdf0e10cSrcweir 	}
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir 	return 0;
310*cdf0e10cSrcweir }
311*cdf0e10cSrcweir 
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir //----------------------------------------------------------------------------
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox )
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir 	if ( pBox == &rBtnCopyResult )
318*cdf0e10cSrcweir 	{
319*cdf0e10cSrcweir 		if ( pBox->IsChecked() )
320*cdf0e10cSrcweir 		{
321*cdf0e10cSrcweir 			rBtnDestPers.Enable();
322*cdf0e10cSrcweir 			rLbCopyPos.Enable();
323*cdf0e10cSrcweir 			rEdCopyPos.Enable();
324*cdf0e10cSrcweir 			rRbCopyPos.Enable();
325*cdf0e10cSrcweir 			rEdCopyPos.GrabFocus();
326*cdf0e10cSrcweir 		}
327*cdf0e10cSrcweir 		else
328*cdf0e10cSrcweir 		{
329*cdf0e10cSrcweir 			rBtnDestPers.Disable();
330*cdf0e10cSrcweir 			rLbCopyPos.Disable();
331*cdf0e10cSrcweir 			rEdCopyPos.Disable();
332*cdf0e10cSrcweir 			rRbCopyPos.Disable();
333*cdf0e10cSrcweir 		}
334*cdf0e10cSrcweir 	}
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir 	return 0;
337*cdf0e10cSrcweir }
338