xref: /aoo42x/main/sc/source/ui/dbgui/pfiltdlg.cxx (revision b77af630)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #undef SC_DLLIMPLEMENTATION
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef PCH
32cdf0e10cSrcweir #include <vcl/waitobj.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include "viewdata.hxx"
38cdf0e10cSrcweir #include "document.hxx"
39cdf0e10cSrcweir #include "uiitems.hxx"
40cdf0e10cSrcweir #include "global.hxx"
41cdf0e10cSrcweir #include "dbcolect.hxx"
42cdf0e10cSrcweir #include "scresid.hxx"
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include "sc.hrc"
45cdf0e10cSrcweir #include "filter.hrc"
46cdf0e10cSrcweir #include "globstr.hrc"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #define _PFILTDLG_CXX
49cdf0e10cSrcweir #include "pfiltdlg.hxx"
50cdf0e10cSrcweir #undef _PFILTDLG_CXX
51cdf0e10cSrcweir #include <svl/zforlist.hxx>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir //==================================================================
54cdf0e10cSrcweir 
55cdf0e10cSrcweir ScPivotFilterDlg::ScPivotFilterDlg( Window*				pParent,
56cdf0e10cSrcweir 									const SfxItemSet&	rArgSet,
57cdf0e10cSrcweir 									SCTAB 				nSourceTab )
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	:	ModalDialog	( pParent, ScResId( RID_SCDLG_PIVOTFILTER ) ),
60cdf0e10cSrcweir 		//
61cdf0e10cSrcweir         aFlCriteria     ( this, ScResId( FL_CRITERIA ) ),
62cdf0e10cSrcweir 		aLbField1		( this, ScResId( LB_FIELD1 ) ),
63cdf0e10cSrcweir 		aLbCond1		( this, ScResId( LB_COND1 ) ),
64cdf0e10cSrcweir 		aEdVal1			( this, ScResId( ED_VAL1 ) ),
65cdf0e10cSrcweir 		aLbConnect1		( this, ScResId( LB_OP1 ) ),
66cdf0e10cSrcweir 		aLbField2		( this, ScResId( LB_FIELD2 ) ),
67cdf0e10cSrcweir 		aLbCond2		( this, ScResId( LB_COND2 ) ),
68cdf0e10cSrcweir 		aEdVal2			( this, ScResId( ED_VAL2 ) ),
69cdf0e10cSrcweir 		aLbConnect2		( this, ScResId( LB_OP2 ) ),
70cdf0e10cSrcweir 		aLbField3		( this, ScResId( LB_FIELD3 ) ),
71cdf0e10cSrcweir 		aLbCond3		( this, ScResId( LB_COND3 ) ),
72cdf0e10cSrcweir 		aEdVal3			( this, ScResId( ED_VAL3 ) ),
73cdf0e10cSrcweir 		aFtConnect		( this, ScResId( FT_OP ) ),
74cdf0e10cSrcweir 		aFtField		( this, ScResId( FT_FIELD ) ),
75cdf0e10cSrcweir 		aFtCond			( this, ScResId( FT_COND ) ),
76cdf0e10cSrcweir 		aFtVal			( this, ScResId( FT_VAL ) ),
77cdf0e10cSrcweir         aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
78cdf0e10cSrcweir 		aBtnCase		( this, ScResId( BTN_CASE ) ),
79cdf0e10cSrcweir 		aBtnRegExp		( this, ScResId( BTN_REGEXP ) ),
80cdf0e10cSrcweir 		aBtnUnique		( this, ScResId( BTN_UNIQUE ) ),
81cdf0e10cSrcweir 		aFtDbAreaLabel	( this, ScResId( FT_DBAREA_LABEL ) ),
82cdf0e10cSrcweir 		aFtDbArea		( this, ScResId( FT_DBAREA ) ),
83cdf0e10cSrcweir 		aBtnOk			( this, ScResId( BTN_OK ) ),
84cdf0e10cSrcweir 		aBtnCancel		( this, ScResId( BTN_CANCEL ) ),
85cdf0e10cSrcweir 		aBtnHelp		( this, ScResId( BTN_HELP ) ),
86cdf0e10cSrcweir 		aBtnMore		( this, ScResId( BTN_MORE ) ),
87cdf0e10cSrcweir 		aStrUndefined	( ScResId( SCSTR_UNDEFINED ) ),
88cdf0e10cSrcweir 		aStrNoName		( ScGlobal::GetRscString(STR_DB_NONAME) ),
89cdf0e10cSrcweir 		aStrNone		( ScResId( SCSTR_NONE ) ),
90cdf0e10cSrcweir 		aStrEmpty		( ScResId( SCSTR_EMPTY ) ),
91cdf0e10cSrcweir 		aStrNotEmpty	( ScResId( SCSTR_NOTEMPTY ) ),
92cdf0e10cSrcweir 		aStrRow			( ScResId( SCSTR_ROW ) ),
93cdf0e10cSrcweir 		aStrColumn		( ScResId( SCSTR_COLUMN ) ),
94cdf0e10cSrcweir 		//
95cdf0e10cSrcweir 		nWhichQuery		( rArgSet.GetPool()->GetWhich( SID_QUERY ) ),
96cdf0e10cSrcweir 		theQueryData	( ((const ScQueryItem&)
97cdf0e10cSrcweir 						   rArgSet.Get( nWhichQuery )).GetQueryData() ),
98cdf0e10cSrcweir 		pOutItem		( NULL ),
99cdf0e10cSrcweir 		pViewData		( NULL ),
100cdf0e10cSrcweir 		pDoc			( NULL ),
101cdf0e10cSrcweir 		nSrcTab			( nSourceTab ),		// ist nicht im QueryParam
102cdf0e10cSrcweir 		nFieldCount		( 0 )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<=MAXCOL; i++)
105cdf0e10cSrcweir 		pEntryLists[i] = NULL;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	Init( rArgSet );
108cdf0e10cSrcweir 	FreeResource();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir //------------------------------------------------------------------------
112cdf0e10cSrcweir 
113cdf0e10cSrcweir __EXPORT ScPivotFilterDlg::~ScPivotFilterDlg()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<=MAXCOL; i++)
116cdf0e10cSrcweir 		delete pEntryLists[i];
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 	if ( pOutItem )
119cdf0e10cSrcweir 		delete pOutItem;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //------------------------------------------------------------------------
123cdf0e10cSrcweir 
124cdf0e10cSrcweir void __EXPORT ScPivotFilterDlg::Init( const SfxItemSet& rArgSet )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	const ScQueryItem& rQueryItem = (const ScQueryItem&)
127cdf0e10cSrcweir 									rArgSet.Get( nWhichQuery );
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	aBtnCase.SetClickHdl	( LINK( this, ScPivotFilterDlg, CheckBoxHdl ) );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	aLbField1.SetSelectHdl	( LINK( this, ScPivotFilterDlg, LbSelectHdl ) );
132cdf0e10cSrcweir 	aLbField2.SetSelectHdl	( LINK( this, ScPivotFilterDlg, LbSelectHdl ) );
133cdf0e10cSrcweir 	aLbField3.SetSelectHdl	( LINK( this, ScPivotFilterDlg, LbSelectHdl ) );
134cdf0e10cSrcweir 	aLbConnect1.SetSelectHdl( LINK( this, ScPivotFilterDlg, LbSelectHdl ) );
135cdf0e10cSrcweir 	aLbConnect2.SetSelectHdl( LINK( this, ScPivotFilterDlg, LbSelectHdl ) );
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnCase );
138cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnRegExp );
139cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnUnique );
140cdf0e10cSrcweir 	aBtnMore.AddWindow( &aFtDbAreaLabel );
141cdf0e10cSrcweir 	aBtnMore.AddWindow( &aFtDbArea );
142cdf0e10cSrcweir     aBtnMore.AddWindow( &aFlOptions );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	aBtnCase	.Check( theQueryData.bCaseSens );
145cdf0e10cSrcweir 	aBtnRegExp	.Check( theQueryData.bRegExp );
146cdf0e10cSrcweir 	aBtnUnique	.Check( !theQueryData.bDuplicate );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	pViewData 	= rQueryItem.GetViewData();
149cdf0e10cSrcweir 	pDoc	  	= pViewData ? pViewData->GetDocument() : NULL;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 	// fuer leichteren Zugriff:
152cdf0e10cSrcweir 	aFieldLbArr	 [0] = &aLbField1;
153cdf0e10cSrcweir 	aFieldLbArr	 [1] = &aLbField2;
154cdf0e10cSrcweir 	aFieldLbArr	 [2] = &aLbField3;
155cdf0e10cSrcweir 	aValueEdArr	 [0] = &aEdVal1;
156cdf0e10cSrcweir 	aValueEdArr	 [1] = &aEdVal2;
157cdf0e10cSrcweir 	aValueEdArr	 [2] = &aEdVal3;
158cdf0e10cSrcweir 	aCondLbArr	 [0] = &aLbCond1;
159cdf0e10cSrcweir 	aCondLbArr	 [1] = &aLbCond2;
160cdf0e10cSrcweir 	aCondLbArr 	 [2] = &aLbCond3;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	if ( pViewData && pDoc )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		String			theAreaStr;
165cdf0e10cSrcweir 		ScRange			theCurArea ( ScAddress( theQueryData.nCol1,
166cdf0e10cSrcweir 												theQueryData.nRow1,
167cdf0e10cSrcweir 												nSrcTab ),
168cdf0e10cSrcweir 									 ScAddress( theQueryData.nCol2,
169cdf0e10cSrcweir 												theQueryData.nRow2,
170cdf0e10cSrcweir 												nSrcTab ) );
171cdf0e10cSrcweir 		ScDBCollection*	pDBColl		= pDoc->GetDBCollection();
172cdf0e10cSrcweir 		String			theDbArea;
173cdf0e10cSrcweir 		String			theDbName	= aStrNoName;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 		/*
176cdf0e10cSrcweir 		 * Ueberpruefen, ob es sich bei dem uebergebenen
177cdf0e10cSrcweir 		 * Bereich um einen Datenbankbereich handelt:
178cdf0e10cSrcweir 		 */
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 		theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
181cdf0e10cSrcweir 
182cdf0e10cSrcweir 		if ( pDBColl )
183cdf0e10cSrcweir 		{
184cdf0e10cSrcweir 			ScAddress&	rStart	= theCurArea.aStart;
185cdf0e10cSrcweir 			ScAddress&	rEnd	= theCurArea.aEnd;
186cdf0e10cSrcweir 			ScDBData*	pDBData = pDBColl->GetDBAtArea(	rStart.Tab(),
187cdf0e10cSrcweir 														rStart.Col(), rStart.Row(),
188cdf0e10cSrcweir 														rEnd.Col(),   rEnd.Row() );
189cdf0e10cSrcweir 			if ( pDBData )
190cdf0e10cSrcweir 				pDBData->GetName( theDbName );
191cdf0e10cSrcweir 		}
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 		theDbArea.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
194cdf0e10cSrcweir 		theDbArea += theDbName;
195cdf0e10cSrcweir 		theDbArea += ')';
196cdf0e10cSrcweir 		aFtDbArea.SetText( theDbArea );
197cdf0e10cSrcweir 	}
198cdf0e10cSrcweir 	else
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir 		aFtDbArea.SetText( EMPTY_STRING );
201cdf0e10cSrcweir 	}
202cdf0e10cSrcweir 
203cdf0e10cSrcweir 	// Feldlisten einlesen und Eintraege selektieren:
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	FillFieldLists();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	for ( SCSIZE i=0; i<3; i++ )
208cdf0e10cSrcweir 	{
209cdf0e10cSrcweir 		if ( theQueryData.GetEntry(i).bDoQuery )
210cdf0e10cSrcweir 		{
211cdf0e10cSrcweir 			ScQueryEntry& rEntry = theQueryData.GetEntry(i);
212cdf0e10cSrcweir 
213cdf0e10cSrcweir             String	aValStr		 = *rEntry.pStr;
214cdf0e10cSrcweir             if (!rEntry.bQueryByString && aValStr == EMPTY_STRING)
215cdf0e10cSrcweir             {
216cdf0e10cSrcweir                 if (rEntry.nVal == SC_EMPTYFIELDS)
217cdf0e10cSrcweir                     aValStr = aStrEmpty;
218cdf0e10cSrcweir                 else if (rEntry.nVal == SC_NONEMPTYFIELDS)
219cdf0e10cSrcweir                     aValStr = aStrNotEmpty;
220cdf0e10cSrcweir             }
221cdf0e10cSrcweir 			sal_uInt16	nCondPos	 = (sal_uInt16)rEntry.eOp;
222cdf0e10cSrcweir 			sal_uInt16	nFieldSelPos = GetFieldSelPos( static_cast<SCCOL>(rEntry.nField) );
223cdf0e10cSrcweir 
224cdf0e10cSrcweir 			aFieldLbArr[i]->SelectEntryPos( nFieldSelPos );
225cdf0e10cSrcweir 			aCondLbArr [i]->SelectEntryPos( nCondPos );
226cdf0e10cSrcweir 			UpdateValueList( static_cast<sal_uInt16>(i+1) );
227cdf0e10cSrcweir 			aValueEdArr[i]->SetText( aValStr );
228cdf0e10cSrcweir             if (aValStr == aStrEmpty || aValStr == aStrNotEmpty)
229cdf0e10cSrcweir                 aCondLbArr[i]->Disable();
230cdf0e10cSrcweir 		}
231cdf0e10cSrcweir 		else
232cdf0e10cSrcweir 		{
233cdf0e10cSrcweir 			aFieldLbArr[i]->SelectEntryPos( 0 ); // "keiner" selektieren
234cdf0e10cSrcweir 			aCondLbArr [i]->SelectEntryPos( 0 ); // "=" selektieren
235cdf0e10cSrcweir 			UpdateValueList( static_cast<sal_uInt16>(i) );
236cdf0e10cSrcweir 			aValueEdArr[i]->SetText( EMPTY_STRING );
237cdf0e10cSrcweir 		}
238cdf0e10cSrcweir 		aValueEdArr[i]->SetModifyHdl( LINK( this, ScPivotFilterDlg, ValModifyHdl ) );
239cdf0e10cSrcweir 	}
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 	// Disable/Enable Logik:
242cdf0e10cSrcweir 
243cdf0e10cSrcweir 	   (aLbField1.GetSelectEntryPos() != 0)
244cdf0e10cSrcweir 	&& (aLbField2.GetSelectEntryPos() != 0)
245cdf0e10cSrcweir 		? aLbConnect1.SelectEntryPos( (sal_uInt16)theQueryData.GetEntry(1).eConnect )
246cdf0e10cSrcweir 		: aLbConnect1.SetNoSelection();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir 	   (aLbField2.GetSelectEntryPos() != 0)
249cdf0e10cSrcweir 	&& (aLbField3.GetSelectEntryPos() != 0)
250cdf0e10cSrcweir 		? aLbConnect2.SelectEntryPos( (sal_uInt16)theQueryData.GetEntry(2).eConnect )
251cdf0e10cSrcweir 		: aLbConnect2.SetNoSelection();
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 	if ( aLbField1.GetSelectEntryPos() == 0 )
254cdf0e10cSrcweir 	{
255cdf0e10cSrcweir 		aLbConnect1.Disable();
256cdf0e10cSrcweir 		aLbField2.Disable();
257cdf0e10cSrcweir 		aLbCond2.Disable();
258cdf0e10cSrcweir 		aEdVal2.Disable();
259cdf0e10cSrcweir 	}
260cdf0e10cSrcweir 	else if ( aLbConnect1.GetSelectEntryCount() == 0 )
261cdf0e10cSrcweir 	{
262cdf0e10cSrcweir 		aLbField2.Disable();
263cdf0e10cSrcweir 		aLbCond2.Disable();
264cdf0e10cSrcweir 		aEdVal2.Disable();
265cdf0e10cSrcweir 	}
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	if ( aLbField2.GetSelectEntryPos() == 0 )
268cdf0e10cSrcweir 	{
269cdf0e10cSrcweir 		aLbConnect2.Disable();
270cdf0e10cSrcweir 		aLbField3.Disable();
271cdf0e10cSrcweir 		aLbCond3.Disable();
272cdf0e10cSrcweir 		aEdVal3.Disable();
273cdf0e10cSrcweir 	}
274cdf0e10cSrcweir 	else if ( aLbConnect2.GetSelectEntryCount() == 0 )
275cdf0e10cSrcweir 	{
276cdf0e10cSrcweir 		aLbField3.Disable();
277cdf0e10cSrcweir 		aLbCond3.Disable();
278cdf0e10cSrcweir 		aEdVal3.Disable();
279cdf0e10cSrcweir 	}
280cdf0e10cSrcweir }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir //------------------------------------------------------------------------
283cdf0e10cSrcweir 
284cdf0e10cSrcweir void ScPivotFilterDlg::FillFieldLists()
285cdf0e10cSrcweir {
286cdf0e10cSrcweir 	aLbField1.Clear();
287cdf0e10cSrcweir 	aLbField2.Clear();
288cdf0e10cSrcweir 	aLbField3.Clear();
289cdf0e10cSrcweir 	aLbField1.InsertEntry( aStrNone, 0 );
290cdf0e10cSrcweir 	aLbField2.InsertEntry( aStrNone, 0 );
291cdf0e10cSrcweir 	aLbField3.InsertEntry( aStrNone, 0 );
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 	if ( pDoc )
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		String	aFieldName;
296cdf0e10cSrcweir 		SCTAB	nTab		= nSrcTab;
297cdf0e10cSrcweir 		SCCOL	nFirstCol	= theQueryData.nCol1;
298cdf0e10cSrcweir 		SCROW	nFirstRow	= theQueryData.nRow1;
299cdf0e10cSrcweir 		SCCOL	nMaxCol		= theQueryData.nCol2;
300cdf0e10cSrcweir 		SCCOL	col = 0;
301cdf0e10cSrcweir 		sal_uInt16	i=1;
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 		for ( col=nFirstCol; col<=nMaxCol; col++ )
304cdf0e10cSrcweir 		{
305cdf0e10cSrcweir 			pDoc->GetString( col, nFirstRow, nTab, aFieldName );
306cdf0e10cSrcweir 			if ( aFieldName.Len() == 0 )
307cdf0e10cSrcweir 			{
308cdf0e10cSrcweir 				aFieldName  = aStrColumn;
309cdf0e10cSrcweir 				aFieldName += ' ';
310cdf0e10cSrcweir                 aFieldName += ScColToAlpha( col );
311cdf0e10cSrcweir 			}
312cdf0e10cSrcweir 			aLbField1.InsertEntry( aFieldName, i );
313cdf0e10cSrcweir 			aLbField2.InsertEntry( aFieldName, i );
314cdf0e10cSrcweir 			aLbField3.InsertEntry( aFieldName, i );
315cdf0e10cSrcweir 			i++;
316cdf0e10cSrcweir 		}
317cdf0e10cSrcweir 		nFieldCount = i;
318cdf0e10cSrcweir 	}
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir //------------------------------------------------------------------------
322cdf0e10cSrcweir 
323cdf0e10cSrcweir void ScPivotFilterDlg::UpdateValueList( sal_uInt16 nList )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir 	if ( pDoc && nList>0 && nList<=3 )
326cdf0e10cSrcweir 	{
327cdf0e10cSrcweir 		ComboBox*	pValList		= aValueEdArr[nList-1];
328cdf0e10cSrcweir 		sal_uInt16		nFieldSelPos	= aFieldLbArr[nList-1]->GetSelectEntryPos();
329cdf0e10cSrcweir 		sal_uInt16		nListPos		= 0;
330cdf0e10cSrcweir 		String		aCurValue  		= pValList->GetText();
331cdf0e10cSrcweir 
332cdf0e10cSrcweir 		pValList->Clear();
333cdf0e10cSrcweir 		pValList->InsertEntry( aStrNotEmpty, 0 );
334cdf0e10cSrcweir 		pValList->InsertEntry( aStrEmpty, 1 );
335cdf0e10cSrcweir 		nListPos = 2;
336cdf0e10cSrcweir 
337cdf0e10cSrcweir 		if ( pDoc && nFieldSelPos )
338cdf0e10cSrcweir 		{
339cdf0e10cSrcweir 			SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1;
340cdf0e10cSrcweir 			if (!pEntryLists[nColumn])
341cdf0e10cSrcweir 			{
342cdf0e10cSrcweir 				WaitObject aWaiter( this );
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 				SCTAB	nTab		= nSrcTab;
345cdf0e10cSrcweir 				SCROW	nFirstRow	= theQueryData.nRow1;
346cdf0e10cSrcweir 				SCROW	nLastRow	= theQueryData.nRow2;
347cdf0e10cSrcweir 				nFirstRow++;
348cdf0e10cSrcweir                 bool bHasDates = false;
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 				pEntryLists[nColumn] = new TypedScStrCollection( 128, 128 );
351cdf0e10cSrcweir 				pEntryLists[nColumn]->SetCaseSensitive( aBtnCase.IsChecked() );
352cdf0e10cSrcweir 				pDoc->GetFilterEntriesArea( nColumn, nFirstRow, nLastRow,
353cdf0e10cSrcweir                                             nTab, *pEntryLists[nColumn], bHasDates );
354cdf0e10cSrcweir 			}
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 			TypedScStrCollection* pColl = pEntryLists[nColumn];
357cdf0e10cSrcweir 			sal_uInt16 nValueCount = pColl->GetCount();
358cdf0e10cSrcweir 			if ( nValueCount > 0 )
359cdf0e10cSrcweir 			{
360cdf0e10cSrcweir 				for ( sal_uInt16 i=0; i<nValueCount; i++ )
361cdf0e10cSrcweir 				{
362cdf0e10cSrcweir 					pValList->InsertEntry( (*pColl)[i]->GetString(), nListPos );
363cdf0e10cSrcweir 					nListPos++;
364cdf0e10cSrcweir 				}
365cdf0e10cSrcweir 			}
366cdf0e10cSrcweir 		}
367cdf0e10cSrcweir 		pValList->SetText( aCurValue );
368cdf0e10cSrcweir 	}
369cdf0e10cSrcweir }
370cdf0e10cSrcweir 
371cdf0e10cSrcweir //------------------------------------------------------------------------
372cdf0e10cSrcweir 
373cdf0e10cSrcweir void ScPivotFilterDlg::ClearValueList( sal_uInt16 nList )
374cdf0e10cSrcweir {
375cdf0e10cSrcweir 	if ( nList>0 && nList<=3 )
376cdf0e10cSrcweir 	{
377cdf0e10cSrcweir 		ComboBox* pValList = aValueEdArr[nList-1];
378cdf0e10cSrcweir 		pValList->Clear();
379cdf0e10cSrcweir 		pValList->InsertEntry( aStrNotEmpty, 0 );
380cdf0e10cSrcweir 		pValList->InsertEntry( aStrEmpty, 1 );
381cdf0e10cSrcweir 		pValList->SetText( EMPTY_STRING );
382cdf0e10cSrcweir 	}
383cdf0e10cSrcweir }
384cdf0e10cSrcweir 
385cdf0e10cSrcweir //------------------------------------------------------------------------
386cdf0e10cSrcweir 
387cdf0e10cSrcweir sal_uInt16 ScPivotFilterDlg::GetFieldSelPos( SCCOL nField )
388cdf0e10cSrcweir {
389cdf0e10cSrcweir 	if ( nField >= theQueryData.nCol1 && nField <= theQueryData.nCol2 )
390cdf0e10cSrcweir 		return static_cast<sal_uInt16>(nField - theQueryData.nCol1 + 1);
391cdf0e10cSrcweir 	else
392cdf0e10cSrcweir 		return 0;
393cdf0e10cSrcweir }
394cdf0e10cSrcweir 
395cdf0e10cSrcweir //------------------------------------------------------------------------
396cdf0e10cSrcweir 
397cdf0e10cSrcweir const ScQueryItem& ScPivotFilterDlg::GetOutputItem()
398cdf0e10cSrcweir {
399cdf0e10cSrcweir 	ScQueryParam 	theParam( theQueryData );
400cdf0e10cSrcweir 	sal_uInt16			nConnect1 = aLbConnect1.GetSelectEntryPos();
401cdf0e10cSrcweir 	sal_uInt16 			nConnect2 = aLbConnect2.GetSelectEntryPos();
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 	for ( SCSIZE i=0; i<3; i++ )
404cdf0e10cSrcweir 	{
405cdf0e10cSrcweir 		sal_uInt16 		nField	= aFieldLbArr[i]->GetSelectEntryPos();
406cdf0e10cSrcweir 		ScQueryOp	eOp		= (ScQueryOp)aCondLbArr[i]->GetSelectEntryPos();
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 		sal_Bool bDoThis = (aFieldLbArr[i]->GetSelectEntryPos() != 0);
409cdf0e10cSrcweir 		theParam.GetEntry(i).bDoQuery = bDoThis;
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 		if ( bDoThis )
412cdf0e10cSrcweir 		{
413cdf0e10cSrcweir 			ScQueryEntry& rEntry = theParam.GetEntry(i);
414cdf0e10cSrcweir 
415cdf0e10cSrcweir 			String aStrVal( aValueEdArr[i]->GetText() );
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 			/*
418cdf0e10cSrcweir 			 * Dialog liefert die ausgezeichneten Feldwerte "leer"/"nicht leer"
419cdf0e10cSrcweir 			 * als Konstanten in nVal in Verbindung mit dem Schalter
420cdf0e10cSrcweir 			 * bQueryByString auf FALSE.
421cdf0e10cSrcweir 			 */
422cdf0e10cSrcweir 			if ( aStrVal == aStrEmpty )
423cdf0e10cSrcweir 			{
424cdf0e10cSrcweir 				*rEntry.pStr	= EMPTY_STRING;
425cdf0e10cSrcweir 				rEntry.nVal 	= SC_EMPTYFIELDS;
426cdf0e10cSrcweir 				rEntry.bQueryByString = sal_False;
427cdf0e10cSrcweir 			}
428cdf0e10cSrcweir 			else if ( aStrVal == aStrNotEmpty )
429cdf0e10cSrcweir 			{
430cdf0e10cSrcweir 				*rEntry.pStr	= EMPTY_STRING;
431cdf0e10cSrcweir 				rEntry.nVal		= SC_NONEMPTYFIELDS;
432cdf0e10cSrcweir 				rEntry.bQueryByString = sal_False;
433cdf0e10cSrcweir 			}
434cdf0e10cSrcweir 			else
435cdf0e10cSrcweir 			{
436cdf0e10cSrcweir 				*rEntry.pStr	= aStrVal;
437cdf0e10cSrcweir 				rEntry.nVal		= 0;
438cdf0e10cSrcweir 				rEntry.bQueryByString = sal_True;
439cdf0e10cSrcweir 			}
440cdf0e10cSrcweir 
441cdf0e10cSrcweir             rEntry.nField	= nField ? (theQueryData.nCol1 +
442cdf0e10cSrcweir                     static_cast<SCCOL>(nField) - 1) : static_cast<SCCOL>(0);
443cdf0e10cSrcweir 			rEntry.eOp	  	= eOp;
444cdf0e10cSrcweir 		}
445cdf0e10cSrcweir 	}
446cdf0e10cSrcweir 
447cdf0e10cSrcweir 	theParam.GetEntry(1).eConnect = (nConnect1 != LISTBOX_ENTRY_NOTFOUND)
448cdf0e10cSrcweir 									? (ScQueryConnect)nConnect1
449cdf0e10cSrcweir 									: SC_AND;
450cdf0e10cSrcweir 	theParam.GetEntry(2).eConnect = (nConnect2 != LISTBOX_ENTRY_NOTFOUND)
451cdf0e10cSrcweir 									? (ScQueryConnect)nConnect2
452cdf0e10cSrcweir 									: SC_AND;
453cdf0e10cSrcweir 
454cdf0e10cSrcweir 	theParam.bInplace   = sal_False;
455cdf0e10cSrcweir 	theParam.nDestTab	= 0;	// Woher kommen diese Werte?
456cdf0e10cSrcweir 	theParam.nDestCol	= 0;
457cdf0e10cSrcweir 	theParam.nDestRow	= 0;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 	theParam.bDuplicate		= !aBtnUnique.IsChecked();
460cdf0e10cSrcweir 	theParam.bCaseSens 		= aBtnCase.IsChecked();
461cdf0e10cSrcweir 	theParam.bRegExp		= aBtnRegExp.IsChecked();
462cdf0e10cSrcweir 
463cdf0e10cSrcweir 	if ( pOutItem ) DELETEZ( pOutItem );
464cdf0e10cSrcweir 	pOutItem = new ScQueryItem( nWhichQuery, &theParam );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	return *pOutItem;
467cdf0e10cSrcweir }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir //------------------------------------------------------------------------
470cdf0e10cSrcweir // Handler:
471cdf0e10cSrcweir //------------------------------------------------------------------------
472cdf0e10cSrcweir 
473cdf0e10cSrcweir IMPL_LINK( ScPivotFilterDlg, LbSelectHdl, ListBox*, pLb )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir 	/*
476cdf0e10cSrcweir 	 * Behandlung der Enable/Disable-Logik,
477cdf0e10cSrcweir 	 * abhaengig davon, welche ListBox angefasst wurde:
478cdf0e10cSrcweir 	 */
479cdf0e10cSrcweir 
480cdf0e10cSrcweir 	if ( pLb == &aLbConnect1 )
481cdf0e10cSrcweir 	{
482cdf0e10cSrcweir 		if ( !aLbField2.IsEnabled() )
483cdf0e10cSrcweir 		{
484cdf0e10cSrcweir 			aLbField2.Enable();
485cdf0e10cSrcweir 			aLbCond2.Enable();
486cdf0e10cSrcweir 			aEdVal2.Enable();
487cdf0e10cSrcweir 		}
488cdf0e10cSrcweir 	}
489cdf0e10cSrcweir 	else if ( pLb == &aLbConnect2 )
490cdf0e10cSrcweir 	{
491cdf0e10cSrcweir 		if ( !aLbField3.IsEnabled() )
492cdf0e10cSrcweir 		{
493cdf0e10cSrcweir 			aLbField3.Enable();
494cdf0e10cSrcweir 			aLbCond3.Enable();
495cdf0e10cSrcweir 			aEdVal3.Enable();
496cdf0e10cSrcweir 		}
497cdf0e10cSrcweir 	}
498cdf0e10cSrcweir 	else if ( pLb == &aLbField1 )
499cdf0e10cSrcweir 	{
500cdf0e10cSrcweir 		if ( aLbField1.GetSelectEntryPos() == 0 )
501cdf0e10cSrcweir 		{
502cdf0e10cSrcweir 			aLbConnect1.SetNoSelection();
503cdf0e10cSrcweir 			aLbConnect2.SetNoSelection();
504cdf0e10cSrcweir 			aLbField2.SelectEntryPos( 0 );
505cdf0e10cSrcweir 			aLbField3.SelectEntryPos( 0 );
506cdf0e10cSrcweir 			aLbCond2.SelectEntryPos( 0 );
507cdf0e10cSrcweir 			aLbCond3.SelectEntryPos( 0 );
508cdf0e10cSrcweir 			ClearValueList( 1 );
509cdf0e10cSrcweir 			ClearValueList( 2 );
510cdf0e10cSrcweir 			ClearValueList( 3 );
511cdf0e10cSrcweir 
512cdf0e10cSrcweir 			aLbConnect1.Disable();
513cdf0e10cSrcweir 			aLbConnect2.Disable();
514cdf0e10cSrcweir 			aLbField2.Disable();
515cdf0e10cSrcweir 			aLbField3.Disable();
516cdf0e10cSrcweir 			aLbCond2.Disable();
517cdf0e10cSrcweir 			aLbCond3.Disable();
518cdf0e10cSrcweir 			aEdVal2.Disable();
519cdf0e10cSrcweir 			aEdVal3.Disable();
520cdf0e10cSrcweir 		}
521cdf0e10cSrcweir 		else
522cdf0e10cSrcweir 		{
523cdf0e10cSrcweir 			UpdateValueList( 1 );
524cdf0e10cSrcweir 			if ( !aLbConnect1.IsEnabled() )
525cdf0e10cSrcweir 			{
526cdf0e10cSrcweir 				aLbConnect1.Enable();
527cdf0e10cSrcweir 			}
528cdf0e10cSrcweir 		}
529cdf0e10cSrcweir 	}
530cdf0e10cSrcweir 	else if ( pLb == &aLbField2 )
531cdf0e10cSrcweir 	{
532cdf0e10cSrcweir 		if ( aLbField2.GetSelectEntryPos() == 0 )
533cdf0e10cSrcweir 		{
534cdf0e10cSrcweir 			aLbConnect2.SetNoSelection();
535cdf0e10cSrcweir 			aLbField3.SelectEntryPos( 0 );
536cdf0e10cSrcweir 			aLbCond3.SelectEntryPos( 0 );
537cdf0e10cSrcweir 			ClearValueList( 2 );
538cdf0e10cSrcweir 			ClearValueList( 3 );
539cdf0e10cSrcweir 
540cdf0e10cSrcweir 			aLbConnect2.Disable();
541cdf0e10cSrcweir 			aLbField3.Disable();
542cdf0e10cSrcweir 			aLbCond3.Disable();
543cdf0e10cSrcweir 			aEdVal3.Disable();
544cdf0e10cSrcweir 		}
545cdf0e10cSrcweir 		else
546cdf0e10cSrcweir 		{
547cdf0e10cSrcweir 			UpdateValueList( 2 );
548cdf0e10cSrcweir 			if ( !aLbConnect2.IsEnabled() )
549cdf0e10cSrcweir 			{
550cdf0e10cSrcweir 				aLbConnect2.Enable();
551cdf0e10cSrcweir 			}
552cdf0e10cSrcweir 		}
553cdf0e10cSrcweir 	}
554cdf0e10cSrcweir 	else if ( pLb == &aLbField3 )
555cdf0e10cSrcweir 	{
556cdf0e10cSrcweir 		( aLbField3.GetSelectEntryPos() == 0 )
557cdf0e10cSrcweir 			? ClearValueList( 3 )
558cdf0e10cSrcweir 			: UpdateValueList( 3 );
559cdf0e10cSrcweir 	}
560cdf0e10cSrcweir 
561cdf0e10cSrcweir 	return 0;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir 
564cdf0e10cSrcweir //----------------------------------------------------------------------------
565cdf0e10cSrcweir 
566cdf0e10cSrcweir IMPL_LINK( ScPivotFilterDlg, CheckBoxHdl, CheckBox*, pBox )
567cdf0e10cSrcweir {
568cdf0e10cSrcweir 	//	bei Gross-/Kleinschreibung die Werte-Listen aktualisieren
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 	if ( pBox == &aBtnCase )					// Wertlisten
571cdf0e10cSrcweir 	{
572cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<=MAXCOL; i++)
573cdf0e10cSrcweir 			DELETEZ( pEntryLists[i] );
574cdf0e10cSrcweir 
575cdf0e10cSrcweir 		String aCurVal1 = aEdVal1.GetText();
576cdf0e10cSrcweir 		String aCurVal2 = aEdVal2.GetText();
577cdf0e10cSrcweir 		String aCurVal3 = aEdVal3.GetText();
578cdf0e10cSrcweir 		UpdateValueList( 1 );
579cdf0e10cSrcweir 		UpdateValueList( 2 );
580cdf0e10cSrcweir 		UpdateValueList( 3 );
581cdf0e10cSrcweir 		aEdVal1.SetText( aCurVal1 );
582cdf0e10cSrcweir 		aEdVal2.SetText( aCurVal2 );
583cdf0e10cSrcweir 		aEdVal3.SetText( aCurVal3 );
584cdf0e10cSrcweir 	}
585cdf0e10cSrcweir 
586cdf0e10cSrcweir 	return 0;
587cdf0e10cSrcweir }
588cdf0e10cSrcweir 
589cdf0e10cSrcweir //------------------------------------------------------------------------
590cdf0e10cSrcweir 
591cdf0e10cSrcweir IMPL_LINK( ScPivotFilterDlg, ValModifyHdl, ComboBox*, pEd )
592cdf0e10cSrcweir {
593cdf0e10cSrcweir 	if ( pEd )
594cdf0e10cSrcweir 	{
595cdf0e10cSrcweir 		String aStrVal	= pEd->GetText();
596cdf0e10cSrcweir 		ListBox* pLb	= &aLbCond1;
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 			 if ( pEd == &aEdVal2 ) pLb = &aLbCond2;
599cdf0e10cSrcweir 		else if ( pEd == &aEdVal3 )	pLb = &aLbCond3;
600cdf0e10cSrcweir 
601cdf0e10cSrcweir 		// wenn einer der Sonderwerte leer/nicht-leer
602cdf0e10cSrcweir 		// gewaehlt wird, so macht nur der =-Operator Sinn:
603cdf0e10cSrcweir 
604cdf0e10cSrcweir 		if ( aStrEmpty == aStrVal || aStrNotEmpty == aStrVal )
605cdf0e10cSrcweir 		{
606cdf0e10cSrcweir 			pLb->SelectEntry( '=' );
607cdf0e10cSrcweir 			pLb->Disable();
608cdf0e10cSrcweir 		}
609cdf0e10cSrcweir 		else
610cdf0e10cSrcweir 			pLb->Enable();
611cdf0e10cSrcweir 	}
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 	return 0;
614cdf0e10cSrcweir }
615cdf0e10cSrcweir 
616cdf0e10cSrcweir 
617