update dev300-m57
[ooovba.git] / sc / source / ui / dbgui / filtdlg.cxx
blob9d3baa17224019c9f5fb65f6a5831d43103cecc9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filtdlg.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes ---------------------------------------------------------
38 // INCLUDE -------------------------------------------------------------------
39 #include <rangelst.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <vcl/waitobj.hxx>
43 #include "uiitems.hxx"
44 #include "dbcolect.hxx"
45 #include "reffact.hxx"
46 #include "viewdata.hxx"
47 #include "document.hxx"
48 #include "docsh.hxx"
49 #include "scresid.hxx"
51 #include "foptmgr.hxx"
53 #include "globstr.hrc"
54 #include "filter.hrc"
56 #define _FILTDLG_CXX
57 #include "filtdlg.hxx"
58 #undef _FILTDLG_CXX
59 #include <vcl/msgbox.hxx>
61 // DEFINE --------------------------------------------------------------------
63 #define ERRORBOX(rid) ErrorBox( this, WinBits( WB_OK|WB_DEF_OK), \
64 ScGlobal::GetRscString(rid) ).Execute()
67 //============================================================================
68 // class ScFilterDlg
70 //----------------------------------------------------------------------------
72 ScFilterDlg::ScFilterDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
73 const SfxItemSet& rArgSet )
75 : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_FILTER ),
77 aFlCriteria ( this, ScResId( FL_CRITERIA ) ),
78 aLbConnect1 ( this, ScResId( LB_OP1 ) ),
79 aLbField1 ( this, ScResId( LB_FIELD1 ) ),
80 aLbCond1 ( this, ScResId( LB_COND1 ) ),
81 aEdVal1 ( this, ScResId( ED_VAL1 ) ),
82 aLbConnect2 ( this, ScResId( LB_OP2 ) ),
83 aLbField2 ( this, ScResId( LB_FIELD2 ) ),
84 aLbCond2 ( this, ScResId( LB_COND2 ) ),
85 aEdVal2 ( this, ScResId( ED_VAL2 ) ),
86 aLbConnect3 ( this, ScResId( LB_OP3 ) ),
87 aLbField3 ( this, ScResId( LB_FIELD3 ) ),
88 aLbCond3 ( this, ScResId( LB_COND3 ) ),
89 aEdVal3 ( this, ScResId( ED_VAL3 ) ),
90 aLbConnect4 ( this, ScResId( LB_OP4 ) ),
91 aLbField4 ( this, ScResId( LB_FIELD4 ) ),
92 aLbCond4 ( this, ScResId( LB_COND4 ) ),
93 aEdVal4 ( this, ScResId( ED_VAL4 ) ),
94 aFtConnect ( this, ScResId( FT_OP ) ),
95 aFtField ( this, ScResId( FT_FIELD ) ),
96 aFtCond ( this, ScResId( FT_COND ) ),
97 aFtVal ( this, ScResId( FT_VAL ) ),
98 aFlSeparator ( this, ScResId( FL_SEPARATOR ) ),
99 aScrollBar ( this, ScResId( LB_SCROLL ) ),
100 aFlOptions ( this, ScResId( FL_OPTIONS ) ),
101 aBtnMore ( this, ScResId( BTN_MORE ) ),
102 aBtnHelp ( this, ScResId( BTN_HELP ) ),
103 aBtnOk ( this, ScResId( BTN_OK ) ),
104 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
105 _INIT_COMMON_FILTER_RSCOBJS
106 aStrEmpty ( ScResId( SCSTR_EMPTY ) ),
107 aStrNotEmpty ( ScResId( SCSTR_NOTEMPTY ) ),
108 aStrRow ( ScResId( SCSTR_ROW ) ),
109 aStrColumn ( ScResId( SCSTR_COLUMN ) ),
111 pOptionsMgr ( NULL ),
112 nWhichQuery ( rArgSet.GetPool()->GetWhich( SID_QUERY ) ),
113 theQueryData ( ((const ScQueryItem&)
114 rArgSet.Get( nWhichQuery )).GetQueryData() ),
115 pOutItem ( NULL ),
116 pViewData ( NULL ),
117 pDoc ( NULL ),
118 nSrcTab ( 0 ),
119 nFieldCount ( 0 ),
120 bRefInputMode ( FALSE ),
121 pTimer ( NULL )
123 for (USHORT i=0; i<=MAXCOL; i++)
124 pEntryLists[i] = NULL;
125 for (SCSIZE i=0;i<MAXQUERY;i++)
127 bRefreshExceptQuery[i]=FALSE;
129 aBtnMore.SetMoreText( String(ScResId( SCSTR_MOREBTN_MOREOPTIONS )) );
130 aBtnMore.SetLessText( String(ScResId( SCSTR_MOREBTN_FEWEROPTIONS )) );
131 Init( rArgSet );
132 FreeResource();
134 // Hack: RefInput-Kontrolle
135 pTimer = new Timer;
136 pTimer->SetTimeout( 50 ); // 50ms warten
137 pTimer->SetTimeoutHdl( LINK( this, ScFilterDlg, TimeOutHdl ) );
141 //----------------------------------------------------------------------------
143 __EXPORT ScFilterDlg::~ScFilterDlg()
145 for (USHORT i=0; i<=MAXCOL; i++)
146 delete pEntryLists[i];
148 delete pOptionsMgr;
149 delete pOutItem;
151 // Hack: RefInput-Kontrolle
152 pTimer->Stop();
153 delete pTimer;
157 //----------------------------------------------------------------------------
159 void __EXPORT ScFilterDlg::Init( const SfxItemSet& rArgSet )
161 const ScQueryItem& rQueryItem = (const ScQueryItem&)
162 rArgSet.Get( nWhichQuery );
164 aBtnOk.SetClickHdl ( LINK( this, ScFilterDlg, EndDlgHdl ) );
165 aBtnCancel.SetClickHdl ( LINK( this, ScFilterDlg, EndDlgHdl ) );
166 aBtnMore.SetClickHdl ( LINK( this, ScFilterDlg, MoreClickHdl ) );
167 aBtnHeader.SetClickHdl ( LINK( this, ScFilterDlg, CheckBoxHdl ) );
168 aBtnCase.SetClickHdl ( LINK( this, ScFilterDlg, CheckBoxHdl ) );
170 aLbField1.SetSelectHdl ( LINK( this, ScFilterDlg, LbSelectHdl ) );
171 aLbField2.SetSelectHdl ( LINK( this, ScFilterDlg, LbSelectHdl ) );
172 aLbField3.SetSelectHdl ( LINK( this, ScFilterDlg, LbSelectHdl ) );
173 aLbField4.SetSelectHdl ( LINK( this, ScFilterDlg, LbSelectHdl ) );
174 aLbConnect1.SetSelectHdl( LINK( this, ScFilterDlg, LbSelectHdl ) );
175 aLbConnect2.SetSelectHdl( LINK( this, ScFilterDlg, LbSelectHdl ) );
176 aLbConnect3.SetSelectHdl( LINK( this, ScFilterDlg, LbSelectHdl ) );
177 aLbConnect4.SetSelectHdl( LINK( this, ScFilterDlg, LbSelectHdl ) );
179 aLbCond1.SetSelectHdl( LINK( this, ScFilterDlg, LbSelectHdl ) );
180 aLbCond2.SetSelectHdl( LINK( this, ScFilterDlg, LbSelectHdl ) );
181 aLbCond3.SetSelectHdl( LINK( this, ScFilterDlg, LbSelectHdl ) );
182 aLbCond4.SetSelectHdl( LINK( this, ScFilterDlg, LbSelectHdl ) );
184 pViewData = rQueryItem.GetViewData();
185 pDoc = pViewData ? pViewData->GetDocument() : NULL;
186 nSrcTab = pViewData ? pViewData->GetTabNo() : static_cast<SCTAB>(0);
188 // fuer leichteren Zugriff:
189 aFieldLbArr [0] = &aLbField1;
190 aFieldLbArr [1] = &aLbField2;
191 aFieldLbArr [2] = &aLbField3;
192 aFieldLbArr [3] = &aLbField4;
193 aValueEdArr [0] = &aEdVal1;
194 aValueEdArr [1] = &aEdVal2;
195 aValueEdArr [2] = &aEdVal3;
196 aValueEdArr [3] = &aEdVal4;
197 aCondLbArr [0] = &aLbCond1;
198 aCondLbArr [1] = &aLbCond2;
199 aCondLbArr [2] = &aLbCond3;
200 aCondLbArr [3] = &aLbCond4;
201 aConnLbArr [0] = &aLbConnect1;
202 aConnLbArr [1] = &aLbConnect2;
203 aConnLbArr [2] = &aLbConnect3;
204 aConnLbArr [3] = &aLbConnect4;
206 // Optionen initialisieren lassen:
208 pOptionsMgr = new ScFilterOptionsMgr(
209 this,
210 pViewData,
211 theQueryData,
212 aBtnMore,
213 aBtnCase,
214 aBtnRegExp,
215 aBtnHeader,
216 aBtnUnique,
217 aBtnCopyResult,
218 aBtnDestPers,
219 aLbCopyArea,
220 aEdCopyArea,
221 aRbCopyArea,
222 aFtDbAreaLabel,
223 aFtDbArea,
224 aFlOptions,
225 aStrNoName,
226 aStrUndefined );
228 // Feldlisten einlesen und Eintraege selektieren:
230 FillFieldLists();
232 for ( SCSIZE i=0; i<4; i++ )
234 String aValStr;
235 USHORT nCondPos = 0;
236 USHORT nFieldSelPos = 0;
238 ScQueryEntry& rEntry = theQueryData.GetEntry(i);
239 if ( rEntry.bDoQuery )
241 nCondPos = (USHORT)rEntry.eOp;
242 nFieldSelPos = GetFieldSelPos( static_cast<SCCOL>(rEntry.nField) );
243 if ( rEntry.nVal == SC_EMPTYFIELDS && !rEntry.bQueryByString && *rEntry.pStr == EMPTY_STRING )
245 aValStr = aStrEmpty;
246 aCondLbArr[i]->Disable();
248 else if ( rEntry.nVal == SC_NONEMPTYFIELDS && !rEntry.bQueryByString && *rEntry.pStr == EMPTY_STRING )
250 aValStr = aStrNotEmpty;
251 aCondLbArr[i]->Disable();
253 else
254 aValStr = *rEntry.pStr;
256 else if ( i == 0 )
258 nFieldSelPos = GetFieldSelPos( pViewData->GetCurX() );
259 rEntry.nField = nFieldSelPos ? (theQueryData.nCol1 +
260 static_cast<SCCOL>(nFieldSelPos) - 1) : static_cast<SCCOL>(0);
261 rEntry.bDoQuery=TRUE;
262 bRefreshExceptQuery[i]=TRUE;
265 aFieldLbArr[i]->SelectEntryPos( nFieldSelPos );
266 aCondLbArr [i]->SelectEntryPos( nCondPos );
267 aValueEdArr[i]->SetText( aValStr );
268 aValueEdArr[i]->SetModifyHdl( LINK( this, ScFilterDlg, ValModifyHdl ) );
269 UpdateValueList( static_cast<USHORT>(i+1) );
272 aScrollBar.SetEndScrollHdl( LINK( this, ScFilterDlg, ScrollHdl ) );
273 aScrollBar.SetScrollHdl( LINK( this, ScFilterDlg, ScrollHdl ) );
275 aScrollBar.SetRange( Range( 0, 4 ) );
276 aScrollBar.SetLineSize( 1 );
277 aLbConnect1.Hide();
278 // Disable/Enable Logik:
280 (aLbField1.GetSelectEntryPos() != 0)
281 && (aLbField2.GetSelectEntryPos() != 0)
282 ? aLbConnect2.SelectEntryPos( (USHORT)theQueryData.GetEntry(1).eConnect )
283 : aLbConnect2.SetNoSelection();
285 (aLbField2.GetSelectEntryPos() != 0)
286 && (aLbField3.GetSelectEntryPos() != 0)
287 ? aLbConnect3.SelectEntryPos( (USHORT)theQueryData.GetEntry(2).eConnect )
288 : aLbConnect3.SetNoSelection();
290 (aLbField3.GetSelectEntryPos() != 0)
291 && (aLbField4.GetSelectEntryPos() != 0)
292 ? aLbConnect4.SelectEntryPos( (USHORT)theQueryData.GetEntry(3).eConnect )
293 : aLbConnect4.SetNoSelection();
294 if ( aLbField1.GetSelectEntryPos() == 0 )
296 aLbConnect2.Disable();
297 aLbField2.Disable();
298 aLbCond2.Disable();
299 aEdVal2.Disable();
301 else if ( aLbConnect2.GetSelectEntryCount() == 0 )
303 aLbField2.Disable();
304 aLbCond2.Disable();
305 aEdVal2.Disable();
308 if ( aLbField2.GetSelectEntryPos() == 0 )
310 aLbConnect3.Disable();
311 aLbField3.Disable();
312 aLbCond3.Disable();
313 aEdVal3.Disable();
315 else if ( aLbConnect3.GetSelectEntryCount() == 0 )
317 aLbField3.Disable();
318 aLbCond3.Disable();
319 aEdVal3.Disable();
321 if ( aLbField3.GetSelectEntryPos() == 0 )
323 aLbConnect4.Disable();
324 aLbField4.Disable();
325 aLbCond4.Disable();
326 aEdVal4.Disable();
328 else if ( aLbConnect4.GetSelectEntryCount() == 0 )
330 aLbField4.Disable();
331 aLbCond4.Disable();
332 aEdVal4.Disable();
335 if(pDoc!=NULL &&
336 pDoc->GetChangeTrack()!=NULL) aBtnCopyResult.Disable();
337 // Modal-Modus einschalten
338 // SetDispatcherLock( TRUE );
339 //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
340 // SFX_APPWINDOW->Disable(FALSE); //! allgemeine Methode im ScAnyRefDlg
344 //----------------------------------------------------------------------------
346 BOOL __EXPORT ScFilterDlg::Close()
348 if (pViewData)
349 pViewData->GetDocShell()->CancelAutoDBRange();
351 return DoClose( ScFilterDlgWrapper::GetChildWindowId() );
355 //----------------------------------------------------------------------------
356 // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
357 // neue Selektion im Referenz-Edit angezeigt wird.
359 void ScFilterDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
361 if ( bRefInputMode ) // Nur moeglich, wenn im Referenz-Editmodus
363 if ( rRef.aStart != rRef.aEnd )
364 RefInputStart( &aEdCopyArea );
365 String aRefStr;
366 rRef.aStart.Format( aRefStr, SCA_ABS_3D, pDocP, pDocP->GetAddressConvention() );
367 aEdCopyArea.SetRefString( aRefStr );
372 //----------------------------------------------------------------------------
374 void ScFilterDlg::SetActive()
376 if ( bRefInputMode )
378 aEdCopyArea.GrabFocus();
379 if ( aEdCopyArea.GetModifyHdl().IsSet() )
380 ((Link&)aEdCopyArea.GetModifyHdl()).Call( &aEdCopyArea );
382 else
383 GrabFocus();
385 RefInputDone();
388 //----------------------------------------------------------------------------
390 void ScFilterDlg::FillFieldLists()
392 aLbField1.Clear();
393 aLbField2.Clear();
394 aLbField3.Clear();
395 aLbField4.Clear();
396 aLbField1.InsertEntry( aStrNone, 0 );
397 aLbField2.InsertEntry( aStrNone, 0 );
398 aLbField3.InsertEntry( aStrNone, 0 );
399 aLbField4.InsertEntry( aStrNone, 0 );
401 if ( pDoc )
403 String aFieldName;
404 SCTAB nTab = nSrcTab;
405 SCCOL nFirstCol = theQueryData.nCol1;
406 SCROW nFirstRow = theQueryData.nRow1;
407 SCCOL nMaxCol = theQueryData.nCol2;
408 SCCOL col = 0;
409 USHORT i=1;
411 for ( col=nFirstCol; col<=nMaxCol; col++ )
413 pDoc->GetString( col, nFirstRow, nTab, aFieldName );
414 if ( !aBtnHeader.IsChecked() || (aFieldName.Len() == 0) )
416 aFieldName = aStrColumn;
417 aFieldName += ' ';
418 aFieldName += ScColToAlpha( col );
420 aLbField1.InsertEntry( aFieldName, i );
421 aLbField2.InsertEntry( aFieldName, i );
422 aLbField3.InsertEntry( aFieldName, i );
423 aLbField4.InsertEntry( aFieldName, i );
424 i++;
426 nFieldCount = i;
431 //----------------------------------------------------------------------------
433 void ScFilterDlg::UpdateValueList( USHORT nList )
435 if ( pDoc && nList>0 && nList<=4 )
437 ComboBox* pValList = aValueEdArr[nList-1];
438 USHORT nFieldSelPos = aFieldLbArr[nList-1]->GetSelectEntryPos();
439 USHORT nListPos = 0;
440 String aCurValue = pValList->GetText();
442 pValList->Clear();
443 pValList->InsertEntry( aStrNotEmpty, 0 );
444 pValList->InsertEntry( aStrEmpty, 1 );
445 nListPos = 2;
447 if ( nFieldSelPos )
449 WaitObject aWaiter( this ); // auch wenn nur die ListBox gefuellt wird
451 SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1;
452 if (!pEntryLists[nColumn])
454 SCTAB nTab = nSrcTab;
455 SCROW nFirstRow = theQueryData.nRow1;
456 SCROW nLastRow = theQueryData.bUseDynamicRange ? theQueryData.nDynamicEndRow : theQueryData.nRow2;
458 // erstmal ohne die erste Zeile
460 pEntryLists[nColumn] = new TypedScStrCollection( 128, 128 );
461 pEntryLists[nColumn]->SetCaseSensitive( aBtnCase.IsChecked() );
462 pDoc->GetFilterEntriesArea( nColumn, nFirstRow+1, nLastRow,
463 nTab, *pEntryLists[nColumn] );
465 // Eintrag fuer die erste Zeile
466 //! Eintrag (pHdrEntry) ohne Collection erzeugen?
468 nHeaderPos[nColumn] = USHRT_MAX;
469 TypedScStrCollection aHdrColl( 1, 1 );
470 pDoc->GetFilterEntriesArea( nColumn, nFirstRow, nFirstRow,
471 nTab, aHdrColl );
472 TypedStrData* pHdrEntry = aHdrColl[0];
473 if ( pHdrEntry )
475 TypedStrData* pNewEntry = new TypedStrData(*pHdrEntry);
476 if ( pEntryLists[nColumn]->Insert( pNewEntry ) )
478 nHeaderPos[nColumn] = pEntryLists[nColumn]->IndexOf( pNewEntry );
479 DBG_ASSERT( nHeaderPos[nColumn] != USHRT_MAX,
480 "Header-Eintrag nicht wiedergefunden" );
482 else
483 delete pNewEntry; // war schon drin
487 TypedScStrCollection* pColl = pEntryLists[nColumn];
488 USHORT nValueCount = pColl->GetCount();
489 if ( nValueCount > 0 )
491 for ( USHORT i=0; i<nValueCount; i++ )
493 pValList->InsertEntry( (*pColl)[i]->GetString(), nListPos );
494 nListPos++;
498 pValList->SetText( aCurValue );
501 UpdateHdrInValueList( nList );
504 void ScFilterDlg::UpdateHdrInValueList( USHORT nList )
506 //! GetText / SetText ??
508 if ( pDoc && nList>0 && nList<=4 )
510 USHORT nFieldSelPos = aFieldLbArr[nList-1]->GetSelectEntryPos();
511 if ( nFieldSelPos )
513 SCCOL nColumn = theQueryData.nCol1 + static_cast<SCCOL>(nFieldSelPos) - 1;
514 if ( pEntryLists[nColumn] )
516 USHORT nPos = nHeaderPos[nColumn];
517 if ( nPos != USHRT_MAX )
519 ComboBox* pValList = aValueEdArr[nList-1];
520 USHORT nListPos = nPos + 2; // nach "leer" und "nicht leer"
522 TypedStrData* pHdrEntry = (*pEntryLists[nColumn])[nPos];
523 if ( pHdrEntry )
525 String aHdrStr = pHdrEntry->GetString();
526 BOOL bWasThere = ( pValList->GetEntry(nListPos) == aHdrStr );
527 BOOL bInclude = !aBtnHeader.IsChecked();
529 if (bInclude) // Eintrag aufnehmen
531 if (!bWasThere)
532 pValList->InsertEntry(aHdrStr, nListPos);
534 else // Eintrag weglassen
536 if (bWasThere)
537 pValList->RemoveEntry(nListPos);
540 else
542 DBG_ERROR("Eintag in Liste nicht gefunden");
546 else
548 DBG_ERROR("Spalte noch nicht initialisiert");
554 //----------------------------------------------------------------------------
556 void ScFilterDlg::ClearValueList( USHORT nList )
558 if ( nList>0 && nList<=4 )
560 ComboBox* pValList = aValueEdArr[nList-1];
561 pValList->Clear();
562 pValList->InsertEntry( aStrNotEmpty, 0 );
563 pValList->InsertEntry( aStrEmpty, 1 );
564 pValList->SetText( EMPTY_STRING );
569 //----------------------------------------------------------------------------
571 USHORT ScFilterDlg::GetFieldSelPos( SCCOL nField )
573 if ( nField >= theQueryData.nCol1 && nField <= theQueryData.nCol2 )
574 return static_cast<USHORT>(nField - theQueryData.nCol1 + 1);
575 else
576 return 0;
579 //----------------------------------------------------------------------------
581 ScQueryItem* ScFilterDlg::GetOutputItem()
583 ScAddress theCopyPos;
584 ScQueryParam theParam( theQueryData );
585 BOOL bCopyPosOk = FALSE;
587 if ( aBtnCopyResult.IsChecked() )
589 String theCopyStr( aEdCopyArea.GetText() );
590 xub_StrLen nColonPos = theCopyStr.Search( ':' );
592 if ( STRING_NOTFOUND != nColonPos )
593 theCopyStr.Erase( nColonPos );
595 USHORT nResult = theCopyPos.Parse( theCopyStr, pDoc, pDoc->GetAddressConvention() );
596 bCopyPosOk = ( SCA_VALID == (nResult & SCA_VALID) );
599 if ( aBtnCopyResult.IsChecked() && bCopyPosOk )
601 theParam.bInplace = FALSE;
602 theParam.nDestTab = theCopyPos.Tab();
603 theParam.nDestCol = theCopyPos.Col();
604 theParam.nDestRow = theCopyPos.Row();
606 else
608 theParam.bInplace = TRUE;
609 theParam.nDestTab = 0;
610 theParam.nDestCol = 0;
611 theParam.nDestRow = 0;
614 theParam.bHasHeader = aBtnHeader.IsChecked();
615 theParam.bByRow = TRUE;
616 theParam.bDuplicate = !aBtnUnique.IsChecked();
617 theParam.bCaseSens = aBtnCase.IsChecked();
618 theParam.bRegExp = aBtnRegExp.IsChecked();
619 theParam.bDestPers = aBtnDestPers.IsChecked();
621 // nur die drei eingestellten - alles andere zuruecksetzen
623 DELETEZ( pOutItem );
624 pOutItem = new ScQueryItem( nWhichQuery, &theParam );
626 return pOutItem;
630 //----------------------------------------------------------------------------
632 BOOL ScFilterDlg::IsRefInputMode() const
634 return bRefInputMode;
638 //----------------------------------------------------------------------------
639 // Handler:
640 // ========
642 IMPL_LINK( ScFilterDlg, EndDlgHdl, Button*, pBtn )
644 if ( pBtn == &aBtnOk )
646 BOOL bAreaInputOk = TRUE;
648 if ( aBtnCopyResult.IsChecked() )
650 if ( !pOptionsMgr->VerifyPosStr( aEdCopyArea.GetText() ) )
652 if ( !aBtnMore.GetState() )
653 aBtnMore.SetState( TRUE );
655 ERRORBOX( STR_INVALID_TABREF );
656 aEdCopyArea.GrabFocus();
657 bAreaInputOk = FALSE;
661 if ( bAreaInputOk )
663 SetDispatcherLock( FALSE );
664 SwitchToDocument();
665 GetBindings().GetDispatcher()->Execute( FID_FILTER_OK,
666 SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
667 GetOutputItem(), 0L, 0L );
668 Close();
671 else if ( pBtn == &aBtnCancel )
673 Close();
676 return 0;
680 //----------------------------------------------------------------------------
682 IMPL_LINK( ScFilterDlg, MoreClickHdl, MoreButton*, EMPTYARG )
684 if ( aBtnMore.GetState() )
685 pTimer->Start();
686 else
688 pTimer->Stop();
689 bRefInputMode = FALSE;
690 //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
691 //SFX_APPWINDOW->Disable(FALSE); //! allgemeine Methode im ScAnyRefDlg
693 return 0;
697 //----------------------------------------------------------------------------
699 IMPL_LINK( ScFilterDlg, TimeOutHdl, Timer*, _pTimer )
701 // alle 50ms nachschauen, ob RefInputMode noch stimmt
703 if( _pTimer == pTimer && IsActive() )
704 bRefInputMode = (aEdCopyArea.HasFocus() || aRbCopyArea.HasFocus());
706 if ( aBtnMore.GetState() )
707 pTimer->Start();
709 return 0;
713 //----------------------------------------------------------------------------
715 IMPL_LINK( ScFilterDlg, LbSelectHdl, ListBox*, pLb )
718 * Behandlung der Enable/Disable-Logik,
719 * abhaengig davon, welche ListBox angefasst wurde:
721 USHORT nOffset = GetSliderPos();
723 if ( pLb == &aLbConnect1 )
725 aLbField1.Enable();
726 aLbCond1.Enable();
727 aEdVal1.Enable();
729 USHORT nConnect1 = aLbConnect1.GetSelectEntryPos();
730 USHORT nQE = nOffset;
731 theQueryData.GetEntry(nQE).eConnect =(ScQueryConnect)nConnect1;
732 bRefreshExceptQuery[nQE]=TRUE;
735 else if ( pLb == &aLbConnect2 )
737 aLbField2.Enable();
738 aLbCond2.Enable();
739 aEdVal2.Enable();
741 USHORT nConnect2 = aLbConnect2.GetSelectEntryPos();
742 USHORT nQE = 1+nOffset;
743 theQueryData.GetEntry(nQE).eConnect =(ScQueryConnect)nConnect2;
744 bRefreshExceptQuery[nQE]=TRUE;
746 else if ( pLb == &aLbConnect3 )
748 aLbField3.Enable();
749 aLbCond3.Enable();
750 aEdVal3.Enable();
752 USHORT nConnect3 = aLbConnect3.GetSelectEntryPos();
753 USHORT nQE = 2+nOffset;
754 theQueryData.GetEntry(nQE).eConnect = (ScQueryConnect)nConnect3;
755 bRefreshExceptQuery[nQE]=TRUE;
758 else if ( pLb == &aLbConnect4 )
760 aLbField4.Enable();
761 aLbCond4.Enable();
762 aEdVal4.Enable();
764 USHORT nConnect4 = aLbConnect4.GetSelectEntryPos();
765 USHORT nQE = 3+nOffset;
766 theQueryData.GetEntry(nQE).eConnect = (ScQueryConnect)nConnect4;
767 bRefreshExceptQuery[nQE]=TRUE;
770 else if ( pLb == &aLbField1 )
772 if ( aLbField1.GetSelectEntryPos() == 0 )
774 aLbConnect2.SetNoSelection();
775 aLbConnect3.SetNoSelection();
776 aLbConnect4.SetNoSelection();
777 aLbField2.SelectEntryPos( 0 );
778 aLbField3.SelectEntryPos( 0 );
779 aLbField4.SelectEntryPos( 0 );
780 aLbCond2.SelectEntryPos( 0 );
781 aLbCond3.SelectEntryPos( 0 );
782 aLbCond4.SelectEntryPos( 0 );
783 ClearValueList( 1 );
784 ClearValueList( 2 );
785 ClearValueList( 3 );
786 ClearValueList( 4 );
788 aLbConnect2.Disable();
789 aLbConnect3.Disable();
790 aLbConnect4.Disable();
791 aLbField2.Disable();
792 aLbField3.Disable();
793 aLbField4.Disable();
794 aLbCond2.Disable();
795 aLbCond3.Disable();
796 aLbCond4.Disable();
797 aEdVal2.Disable();
798 aEdVal3.Disable();
799 aEdVal4.Disable();
800 for (USHORT i= nOffset; i< MAXQUERY; i++)
802 theQueryData.GetEntry(i).bDoQuery = FALSE;
803 bRefreshExceptQuery[i]=FALSE;
804 theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0);
806 bRefreshExceptQuery[nOffset] =TRUE;
808 else
810 UpdateValueList( 1 );
811 if ( !aLbConnect2.IsEnabled() )
813 aLbConnect2.Enable();
815 theQueryData.GetEntry(nOffset).bDoQuery = TRUE;
816 USHORT nField = pLb->GetSelectEntryPos();
817 theQueryData.GetEntry(nOffset).nField = theQueryData.nCol1 + static_cast<SCCOL>(nField) - 1 ;
820 else if ( pLb == &aLbField2 )
822 if ( aLbField2.GetSelectEntryPos() == 0 )
824 aLbConnect3.SetNoSelection();
825 aLbConnect4.SetNoSelection();
826 aLbField3.SelectEntryPos( 0 );
827 aLbField4.SelectEntryPos( 0 );
828 aLbCond3.SelectEntryPos( 0 );
829 aLbCond4.SelectEntryPos( 0 );
830 ClearValueList( 2 );
831 ClearValueList( 3 );
832 ClearValueList( 4 );
834 aLbConnect3.Disable();
835 aLbConnect4.Disable();
836 aLbField3.Disable();
837 aLbField4.Disable();
838 aLbCond3.Disable();
839 aLbCond4.Disable();
840 aEdVal3.Disable();
841 aEdVal4.Disable();
843 USHORT nTemp=nOffset+1;
844 for (USHORT i= nTemp; i< MAXQUERY; i++)
846 theQueryData.GetEntry(i).bDoQuery = FALSE;
847 bRefreshExceptQuery[i]=FALSE;
848 theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0);
850 bRefreshExceptQuery[nTemp]=TRUE;
852 else
854 UpdateValueList( 2 );
855 if ( !aLbConnect3.IsEnabled() )
857 aLbConnect3.Enable();
859 USHORT nField = pLb->GetSelectEntryPos();
860 USHORT nQ=1+nOffset;
861 theQueryData.GetEntry(nQ).bDoQuery = TRUE;
862 theQueryData.GetEntry(nQ).nField = theQueryData.nCol1 + static_cast<SCCOL>(nField) - 1 ;
865 else if ( pLb == &aLbField3 )
867 if ( aLbField3.GetSelectEntryPos() == 0 )
869 aLbConnect4.SetNoSelection();
870 aLbField4.SelectEntryPos( 0 );
871 aLbCond4.SelectEntryPos( 0 );
872 ClearValueList( 3 );
873 ClearValueList( 4 );
875 aLbConnect4.Disable();
876 aLbField4.Disable();
877 aLbCond4.Disable();
878 aEdVal4.Disable();
880 USHORT nTemp=nOffset+2;
881 for (USHORT i= nTemp; i< MAXQUERY; i++)
883 theQueryData.GetEntry(i).bDoQuery = FALSE;
884 bRefreshExceptQuery[i]=FALSE;
885 theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0);
887 bRefreshExceptQuery[nTemp]=TRUE;
889 else
891 UpdateValueList( 3 );
892 if ( !aLbConnect4.IsEnabled() )
894 aLbConnect4.Enable();
897 USHORT nField = pLb->GetSelectEntryPos();
898 USHORT nQ=2+nOffset;
899 theQueryData.GetEntry(nQ).bDoQuery = TRUE;
900 theQueryData.GetEntry(nQ).nField = theQueryData.nCol1 + static_cast<SCCOL>(nField) - 1 ;
904 else if ( pLb == &aLbField4 )
906 if ( aLbField4.GetSelectEntryPos() == 0 )
908 ClearValueList( 4 );
909 USHORT nTemp=nOffset+3;
910 for (USHORT i= nTemp; i< MAXQUERY; i++)
912 theQueryData.GetEntry(i).bDoQuery = FALSE;
913 bRefreshExceptQuery[i]=FALSE;
914 theQueryData.GetEntry(i).nField = static_cast<SCCOL>(0);
916 bRefreshExceptQuery[nTemp]=TRUE;
918 else
920 UpdateValueList( 4 );
921 USHORT nField = pLb->GetSelectEntryPos();
922 USHORT nQ=3+nOffset;
923 theQueryData.GetEntry(nQ).bDoQuery = TRUE;
924 theQueryData.GetEntry(nQ).nField = theQueryData.nCol1 + static_cast<SCCOL>(nField) - 1 ;
928 else if ( pLb == &aLbCond1)
930 theQueryData.GetEntry(nOffset).eOp=(ScQueryOp)pLb->GetSelectEntryPos();
932 else if ( pLb == &aLbCond2)
934 USHORT nQ=1+nOffset;
935 theQueryData.GetEntry(nQ).eOp=(ScQueryOp)pLb->GetSelectEntryPos();
937 else if ( pLb == &aLbCond3)
939 USHORT nQ=2+nOffset;
940 theQueryData.GetEntry(nQ).eOp=(ScQueryOp)pLb->GetSelectEntryPos();
942 else
944 USHORT nQ=3+nOffset;
945 theQueryData.GetEntry(nQ).eOp=(ScQueryOp)pLb->GetSelectEntryPos();
948 return 0;
952 //----------------------------------------------------------------------------
954 IMPL_LINK( ScFilterDlg, CheckBoxHdl, CheckBox*, pBox )
956 // Spaltenkoepfe:
957 // FeldListen: Spaltexx <-> Spaltenkopf-String
958 // WertListen: Spaltenkopf-Wert entfaellt.
959 // Gross-/Kleinschreibung:
960 // WertListen: komplett neu
962 if ( pBox == &aBtnHeader ) // Feldlisten und Wertlisten
964 USHORT nCurSel1 = aLbField1.GetSelectEntryPos();
965 USHORT nCurSel2 = aLbField2.GetSelectEntryPos();
966 USHORT nCurSel3 = aLbField3.GetSelectEntryPos();
967 USHORT nCurSel4 = aLbField4.GetSelectEntryPos();
968 FillFieldLists();
969 aLbField1.SelectEntryPos( nCurSel1 );
970 aLbField2.SelectEntryPos( nCurSel2 );
971 aLbField3.SelectEntryPos( nCurSel3 );
972 aLbField4.SelectEntryPos( nCurSel4 );
974 UpdateHdrInValueList( 1 );
975 UpdateHdrInValueList( 2 );
976 UpdateHdrInValueList( 3 );
977 UpdateHdrInValueList( 4 );
980 if ( pBox == &aBtnCase ) // Wertlisten komplett
982 for (USHORT i=0; i<=MAXCOL; i++)
983 DELETEZ( pEntryLists[i] );
985 UpdateValueList( 1 ); // aktueller Text wird gemerkt
986 UpdateValueList( 2 );
987 UpdateValueList( 3 );
988 UpdateValueList( 4 );
991 return 0;
995 //----------------------------------------------------------------------------
997 IMPL_LINK( ScFilterDlg, ValModifyHdl, ComboBox*, pEd )
999 USHORT nOffset = GetSliderPos();
1000 USHORT i=0;
1001 USHORT nQE =i + nOffset;
1002 if ( pEd )
1004 String aStrVal = pEd->GetText();
1005 ListBox* pLbCond = &aLbCond1;
1006 ListBox* pLbField = &aLbField1;
1007 if ( pEd == &aEdVal2 )
1009 pLbCond = &aLbCond2;
1010 pLbField = &aLbField2;
1011 i=1;
1012 nQE=i+nOffset;
1014 if ( pEd == &aEdVal3 )
1016 pLbCond = &aLbCond3;
1017 pLbField = &aLbField3;
1018 i=2;
1019 nQE=i+nOffset;
1021 if ( pEd == &aEdVal4 )
1023 pLbCond = &aLbCond4;
1024 pLbField = &aLbField4;
1025 i=3;
1026 nQE=i+nOffset;
1029 if ( aStrEmpty == aStrVal || aStrNotEmpty == aStrVal )
1031 pLbCond->SelectEntry( '=' );
1032 pLbCond->Disable();
1034 else
1035 pLbCond->Enable();
1037 ScQueryEntry& rEntry = theQueryData.GetEntry( nQE );
1038 BOOL bDoThis = (pLbField->GetSelectEntryPos() != 0);
1039 rEntry.bDoQuery = bDoThis;
1041 if ( rEntry.bDoQuery || bRefreshExceptQuery[nQE] )
1043 if ( aStrVal == aStrEmpty )
1045 rEntry.pStr->Erase();
1046 rEntry.nVal = SC_EMPTYFIELDS;
1047 rEntry.bQueryByString = FALSE;
1049 else if ( aStrVal == aStrNotEmpty )
1051 rEntry.pStr->Erase();
1052 rEntry.nVal = SC_NONEMPTYFIELDS;
1053 rEntry.bQueryByString = FALSE;
1055 else
1057 *rEntry.pStr = aStrVal;
1058 rEntry.nVal = 0;
1059 rEntry.bQueryByString = TRUE;
1062 USHORT nField = pLbField->GetSelectEntryPos();
1063 rEntry.nField = nField ? (theQueryData.nCol1 +
1064 static_cast<SCCOL>(nField) - 1) : static_cast<SCCOL>(0);
1066 ScQueryOp eOp = (ScQueryOp)pLbCond->GetSelectEntryPos();
1067 rEntry.eOp = eOp;
1071 return 0;
1074 //----------------------------------------------------------------------------
1075 IMPL_LINK( ScFilterDlg, ScrollHdl, ScrollBar*, EMPTYARG )
1077 SliderMoved();
1078 return 0;
1081 void ScFilterDlg::SliderMoved()
1083 USHORT nOffset = GetSliderPos();
1084 RefreshEditRow( nOffset);
1086 USHORT ScFilterDlg::GetSliderPos()
1088 return (USHORT) aScrollBar.GetThumbPos();
1090 void ScFilterDlg::RefreshEditRow( USHORT nOffset )
1092 if (nOffset==0)
1093 aConnLbArr[0]->Hide();
1094 else
1095 aConnLbArr[0]->Show();
1097 for ( USHORT i=0; i<4; i++ )
1099 String aValStr;
1100 USHORT nCondPos = 0;
1101 USHORT nFieldSelPos = 0;
1102 USHORT nQE = i+nOffset;
1104 ScQueryEntry& rEntry = theQueryData.GetEntry( nQE);
1105 if ( rEntry.bDoQuery || bRefreshExceptQuery[nQE] )
1107 nCondPos = (USHORT)rEntry.eOp;
1108 if(rEntry.bDoQuery)
1109 nFieldSelPos = GetFieldSelPos( static_cast<SCCOL>(rEntry.nField) );
1111 if ( rEntry.nVal == SC_EMPTYFIELDS && !rEntry.bQueryByString && *rEntry.pStr == EMPTY_STRING )
1113 aValStr = aStrEmpty;
1114 aCondLbArr[i]->Disable();
1116 else if ( rEntry.nVal == SC_NONEMPTYFIELDS && !rEntry.bQueryByString && *rEntry.pStr == EMPTY_STRING )
1118 aValStr = aStrNotEmpty;
1119 aCondLbArr[i]->Disable();
1121 else
1123 aValStr = *rEntry.pStr;
1124 aCondLbArr[i]->Enable();
1126 aFieldLbArr[i]->Enable();
1127 aValueEdArr[i]->Enable();
1129 if (nOffset==0)
1131 if (i<3)
1133 if(rEntry.bDoQuery)
1134 aConnLbArr[i+1]->Enable();
1135 else
1136 aConnLbArr[i+1]->Disable();
1137 USHORT nQENext = nQE+1;
1138 if(theQueryData.GetEntry(nQENext).bDoQuery || bRefreshExceptQuery[nQENext])
1139 aConnLbArr[i+1]->SelectEntryPos( (USHORT) theQueryData.GetEntry(nQENext).eConnect );
1140 else
1141 aConnLbArr[i+1]->SetNoSelection();
1144 else
1146 if(theQueryData.GetEntry( nQE-1).bDoQuery)
1147 aConnLbArr[i]->Enable();
1148 else
1149 aConnLbArr[i]->Disable();
1151 if(rEntry.bDoQuery || bRefreshExceptQuery[nQE])
1152 aConnLbArr[i]->SelectEntryPos( (USHORT) rEntry.eConnect );
1153 else
1154 aConnLbArr[i]->SetNoSelection();
1158 else
1160 if (nOffset==0)
1162 if(i<3)
1164 aConnLbArr[i+1]->SetNoSelection();
1165 aConnLbArr[i+1]->Disable();
1168 else
1170 if(theQueryData.GetEntry( nQE-1).bDoQuery)
1171 aConnLbArr[i]->Enable();
1172 else
1173 aConnLbArr[i]->Disable();
1174 aConnLbArr[i]->SetNoSelection();
1176 aFieldLbArr[i]->Disable();
1177 aCondLbArr[i]->Disable();
1178 aValueEdArr[i]->Disable();
1180 aFieldLbArr[i]->SelectEntryPos( nFieldSelPos );
1181 aCondLbArr [i]->SelectEntryPos( nCondPos );
1182 aValueEdArr[i]->SetText( aValStr );
1183 UpdateValueList( static_cast<USHORT>(i+1) );