1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filtdlg.cxx,v $
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"
49 #include "scresid.hxx"
51 #include "foptmgr.hxx"
53 #include "globstr.hrc"
57 #include "filtdlg.hxx"
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 //============================================================================
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() ),
120 bRefInputMode ( FALSE
),
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
)) );
134 // Hack: RefInput-Kontrolle
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
];
151 // Hack: RefInput-Kontrolle
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(
228 // Feldlisten einlesen und Eintraege selektieren:
232 for ( SCSIZE i
=0; i
<4; i
++ )
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
)
246 aCondLbArr
[i
]->Disable();
248 else if ( rEntry
.nVal
== SC_NONEMPTYFIELDS
&& !rEntry
.bQueryByString
&& *rEntry
.pStr
== EMPTY_STRING
)
250 aValStr
= aStrNotEmpty
;
251 aCondLbArr
[i
]->Disable();
254 aValStr
= *rEntry
.pStr
;
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 );
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();
301 else if ( aLbConnect2
.GetSelectEntryCount() == 0 )
308 if ( aLbField2
.GetSelectEntryPos() == 0 )
310 aLbConnect3
.Disable();
315 else if ( aLbConnect3
.GetSelectEntryCount() == 0 )
321 if ( aLbField3
.GetSelectEntryPos() == 0 )
323 aLbConnect4
.Disable();
328 else if ( aLbConnect4
.GetSelectEntryCount() == 0 )
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()
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
);
366 rRef
.aStart
.Format( aRefStr
, SCA_ABS_3D
, pDocP
, pDocP
->GetAddressConvention() );
367 aEdCopyArea
.SetRefString( aRefStr
);
372 //----------------------------------------------------------------------------
374 void ScFilterDlg::SetActive()
378 aEdCopyArea
.GrabFocus();
379 if ( aEdCopyArea
.GetModifyHdl().IsSet() )
380 ((Link
&)aEdCopyArea
.GetModifyHdl()).Call( &aEdCopyArea
);
388 //----------------------------------------------------------------------------
390 void ScFilterDlg::FillFieldLists()
396 aLbField1
.InsertEntry( aStrNone
, 0 );
397 aLbField2
.InsertEntry( aStrNone
, 0 );
398 aLbField3
.InsertEntry( aStrNone
, 0 );
399 aLbField4
.InsertEntry( aStrNone
, 0 );
404 SCTAB nTab
= nSrcTab
;
405 SCCOL nFirstCol
= theQueryData
.nCol1
;
406 SCROW nFirstRow
= theQueryData
.nRow1
;
407 SCCOL nMaxCol
= theQueryData
.nCol2
;
411 for ( col
=nFirstCol
; col
<=nMaxCol
; col
++ )
413 pDoc
->GetString( col
, nFirstRow
, nTab
, aFieldName
);
414 if ( !aBtnHeader
.IsChecked() || (aFieldName
.Len() == 0) )
416 aFieldName
= aStrColumn
;
418 aFieldName
+= ScColToAlpha( col
);
420 aLbField1
.InsertEntry( aFieldName
, i
);
421 aLbField2
.InsertEntry( aFieldName
, i
);
422 aLbField3
.InsertEntry( aFieldName
, i
);
423 aLbField4
.InsertEntry( aFieldName
, 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();
440 String aCurValue
= pValList
->GetText();
443 pValList
->InsertEntry( aStrNotEmpty
, 0 );
444 pValList
->InsertEntry( aStrEmpty
, 1 );
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
,
472 TypedStrData
* pHdrEntry
= aHdrColl
[0];
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" );
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
);
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();
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
];
525 String aHdrStr
= pHdrEntry
->GetString();
526 BOOL bWasThere
= ( pValList
->GetEntry(nListPos
) == aHdrStr
);
527 BOOL bInclude
= !aBtnHeader
.IsChecked();
529 if (bInclude
) // Eintrag aufnehmen
532 pValList
->InsertEntry(aHdrStr
, nListPos
);
534 else // Eintrag weglassen
537 pValList
->RemoveEntry(nListPos
);
542 DBG_ERROR("Eintag in Liste nicht gefunden");
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];
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);
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();
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
624 pOutItem
= new ScQueryItem( nWhichQuery
, &theParam
);
630 //----------------------------------------------------------------------------
632 BOOL
ScFilterDlg::IsRefInputMode() const
634 return bRefInputMode
;
638 //----------------------------------------------------------------------------
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
;
663 SetDispatcherLock( FALSE
);
665 GetBindings().GetDispatcher()->Execute( FID_FILTER_OK
,
666 SFX_CALLMODE_SLOT
| SFX_CALLMODE_RECORD
,
667 GetOutputItem(), 0L, 0L );
671 else if ( pBtn
== &aBtnCancel
)
680 //----------------------------------------------------------------------------
682 IMPL_LINK( ScFilterDlg
, MoreClickHdl
, MoreButton
*, EMPTYARG
)
684 if ( aBtnMore
.GetState() )
689 bRefInputMode
= FALSE
;
690 //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
691 //SFX_APPWINDOW->Disable(FALSE); //! allgemeine Methode im ScAnyRefDlg
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() )
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
)
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
)
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
)
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
)
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 );
788 aLbConnect2
.Disable();
789 aLbConnect3
.Disable();
790 aLbConnect4
.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
;
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 );
834 aLbConnect3
.Disable();
835 aLbConnect4
.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
;
854 UpdateValueList( 2 );
855 if ( !aLbConnect3
.IsEnabled() )
857 aLbConnect3
.Enable();
859 USHORT nField
= pLb
->GetSelectEntryPos();
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 );
875 aLbConnect4
.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
;
891 UpdateValueList( 3 );
892 if ( !aLbConnect4
.IsEnabled() )
894 aLbConnect4
.Enable();
897 USHORT nField
= pLb
->GetSelectEntryPos();
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 )
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
;
920 UpdateValueList( 4 );
921 USHORT nField
= pLb
->GetSelectEntryPos();
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
)
935 theQueryData
.GetEntry(nQ
).eOp
=(ScQueryOp
)pLb
->GetSelectEntryPos();
937 else if ( pLb
== &aLbCond3
)
940 theQueryData
.GetEntry(nQ
).eOp
=(ScQueryOp
)pLb
->GetSelectEntryPos();
945 theQueryData
.GetEntry(nQ
).eOp
=(ScQueryOp
)pLb
->GetSelectEntryPos();
952 //----------------------------------------------------------------------------
954 IMPL_LINK( ScFilterDlg
, CheckBoxHdl
, CheckBox
*, pBox
)
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();
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 );
995 //----------------------------------------------------------------------------
997 IMPL_LINK( ScFilterDlg
, ValModifyHdl
, ComboBox
*, pEd
)
999 USHORT nOffset
= GetSliderPos();
1001 USHORT nQE
=i
+ nOffset
;
1004 String aStrVal
= pEd
->GetText();
1005 ListBox
* pLbCond
= &aLbCond1
;
1006 ListBox
* pLbField
= &aLbField1
;
1007 if ( pEd
== &aEdVal2
)
1009 pLbCond
= &aLbCond2
;
1010 pLbField
= &aLbField2
;
1014 if ( pEd
== &aEdVal3
)
1016 pLbCond
= &aLbCond3
;
1017 pLbField
= &aLbField3
;
1021 if ( pEd
== &aEdVal4
)
1023 pLbCond
= &aLbCond4
;
1024 pLbField
= &aLbField4
;
1029 if ( aStrEmpty
== aStrVal
|| aStrNotEmpty
== aStrVal
)
1031 pLbCond
->SelectEntry( '=' );
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
;
1057 *rEntry
.pStr
= aStrVal
;
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();
1074 //----------------------------------------------------------------------------
1075 IMPL_LINK( ScFilterDlg
, ScrollHdl
, ScrollBar
*, EMPTYARG
)
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
)
1093 aConnLbArr
[0]->Hide();
1095 aConnLbArr
[0]->Show();
1097 for ( USHORT i
=0; i
<4; i
++ )
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
;
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();
1123 aValStr
= *rEntry
.pStr
;
1124 aCondLbArr
[i
]->Enable();
1126 aFieldLbArr
[i
]->Enable();
1127 aValueEdArr
[i
]->Enable();
1134 aConnLbArr
[i
+1]->Enable();
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
);
1141 aConnLbArr
[i
+1]->SetNoSelection();
1146 if(theQueryData
.GetEntry( nQE
-1).bDoQuery
)
1147 aConnLbArr
[i
]->Enable();
1149 aConnLbArr
[i
]->Disable();
1151 if(rEntry
.bDoQuery
|| bRefreshExceptQuery
[nQE
])
1152 aConnLbArr
[i
]->SelectEntryPos( (USHORT
) rEntry
.eConnect
);
1154 aConnLbArr
[i
]->SetNoSelection();
1164 aConnLbArr
[i
+1]->SetNoSelection();
1165 aConnLbArr
[i
+1]->Disable();
1170 if(theQueryData
.GetEntry( nQE
-1).bDoQuery
)
1171 aConnLbArr
[i
]->Enable();
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) );