xref: /trunk/main/sc/source/ui/dbgui/sfiltdlg.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // System - Includes ---------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // INCLUDE -------------------------------------------------------------------
32cdf0e10cSrcweir #include <sfx2/dispatch.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "uiitems.hxx"
35cdf0e10cSrcweir #include "rangenam.hxx"
36cdf0e10cSrcweir #include "dbcolect.hxx"
37cdf0e10cSrcweir #include "reffact.hxx"
38cdf0e10cSrcweir #include "viewdata.hxx"
39cdf0e10cSrcweir #include "document.hxx"
40cdf0e10cSrcweir #include "docsh.hxx"
41cdf0e10cSrcweir #include "scresid.hxx"
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include "foptmgr.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include "globstr.hrc"
46cdf0e10cSrcweir #include "filter.hrc"
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #define _SFILTDLG_CXX
49cdf0e10cSrcweir #include "filtdlg.hxx"
50cdf0e10cSrcweir #undef _SFILTDLG_CXX
51cdf0e10cSrcweir #include <vcl/msgbox.hxx>
52cdf0e10cSrcweir 
53cdf0e10cSrcweir // DEFINE --------------------------------------------------------------------
54cdf0e10cSrcweir 
55cdf0e10cSrcweir #define ERRORBOX(rid) ErrorBox( this, WinBits( WB_OK|WB_DEF_OK),\
56cdf0e10cSrcweir                                 ScGlobal::GetRscString(rid) ).Execute()
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //============================================================================
60cdf0e10cSrcweir //  class ScSpecialFilterDialog
61cdf0e10cSrcweir 
62cdf0e10cSrcweir //----------------------------------------------------------------------------
63cdf0e10cSrcweir 
ScSpecialFilterDlg(SfxBindings * pB,SfxChildWindow * pCW,Window * pParent,const SfxItemSet & rArgSet)64cdf0e10cSrcweir ScSpecialFilterDlg::ScSpecialFilterDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
65cdf0e10cSrcweir                                         const SfxItemSet&   rArgSet )
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     :   ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_SPEC_FILTER ),
68cdf0e10cSrcweir         //
69cdf0e10cSrcweir         aFtFilterArea   ( this, ScResId( FT_CRITERIA_AREA ) ),
70cdf0e10cSrcweir         aLbFilterArea   ( this, ScResId( LB_CRITERIA_AREA ) ),
71cdf0e10cSrcweir         aEdFilterArea   ( this, this, ScResId( ED_CRITERIA_AREA ) ),
72cdf0e10cSrcweir         aRbFilterArea   ( this, ScResId( RB_CRITERIA_AREA ), &aEdFilterArea, this ),
73cdf0e10cSrcweir         //
74cdf0e10cSrcweir         aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
75cdf0e10cSrcweir         _INIT_COMMON_FILTER_RSCOBJS
76cdf0e10cSrcweir         aBtnOk          ( this, ScResId( BTN_OK ) ),
77cdf0e10cSrcweir         aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
78cdf0e10cSrcweir         aBtnHelp        ( this, ScResId( BTN_HELP ) ),
79cdf0e10cSrcweir         aBtnMore        ( this, ScResId( BTN_MORE ) ),
80cdf0e10cSrcweir         //
81cdf0e10cSrcweir         pOptionsMgr     ( NULL ),
82cdf0e10cSrcweir         nWhichQuery     ( rArgSet.GetPool()->GetWhich( SID_QUERY ) ),
83cdf0e10cSrcweir         theQueryData    ( ((const ScQueryItem&)
84cdf0e10cSrcweir                            rArgSet.Get( nWhichQuery )).GetQueryData() ),
85cdf0e10cSrcweir         pOutItem        ( NULL ),
86cdf0e10cSrcweir         pViewData       ( NULL ),
87cdf0e10cSrcweir         pDoc            ( NULL ),
88cdf0e10cSrcweir         pRefInputEdit   ( NULL ),
89cdf0e10cSrcweir         bRefInputMode   ( sal_False ),
90cdf0e10cSrcweir         pTimer          ( NULL )
91cdf0e10cSrcweir {
92cdf0e10cSrcweir     Init( rArgSet );
93cdf0e10cSrcweir     aEdFilterArea.GrabFocus();
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     FreeResource();
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     // Hack: RefInput-Kontrolle
98cdf0e10cSrcweir     pTimer = new Timer;
99cdf0e10cSrcweir     pTimer->SetTimeout( 50 ); // 50ms warten
100cdf0e10cSrcweir     pTimer->SetTimeoutHdl( LINK( this, ScSpecialFilterDlg, TimeOutHdl ) );
101cdf0e10cSrcweir     pTimer->Start();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     aLbCopyArea.SetAccessibleName(aBtnCopyResult.GetText());
104cdf0e10cSrcweir     aEdCopyArea.SetAccessibleName(aBtnCopyResult.GetText());
105cdf0e10cSrcweir     aLbCopyArea.SetAccessibleRelationLabeledBy(&aBtnCopyResult);
106cdf0e10cSrcweir     aEdCopyArea.SetAccessibleRelationLabeledBy(&aBtnCopyResult);
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //----------------------------------------------------------------------------
111cdf0e10cSrcweir 
~ScSpecialFilterDlg()112cdf0e10cSrcweir __EXPORT ScSpecialFilterDlg::~ScSpecialFilterDlg()
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     sal_uInt16 nEntries = aLbFilterArea.GetEntryCount();
115cdf0e10cSrcweir     sal_uInt16 i;
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     for ( i=1; i<nEntries; i++ )
118cdf0e10cSrcweir         delete (String*)aLbFilterArea.GetEntryData( i );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     delete pOptionsMgr;
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     if ( pOutItem )
123cdf0e10cSrcweir         delete pOutItem;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     // Hack: RefInput-Kontrolle
126cdf0e10cSrcweir     pTimer->Stop();
127cdf0e10cSrcweir     delete pTimer;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 
131cdf0e10cSrcweir //----------------------------------------------------------------------------
132cdf0e10cSrcweir 
Init(const SfxItemSet & rArgSet)133cdf0e10cSrcweir void __EXPORT ScSpecialFilterDlg::Init( const SfxItemSet& rArgSet )
134cdf0e10cSrcweir {
135cdf0e10cSrcweir     const ScQueryItem& rQueryItem = (const ScQueryItem&)
136cdf0e10cSrcweir                                     rArgSet.Get( nWhichQuery );
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     aBtnOk.SetClickHdl          ( LINK( this, ScSpecialFilterDlg, EndDlgHdl ) );
139cdf0e10cSrcweir     aBtnCancel.SetClickHdl      ( LINK( this, ScSpecialFilterDlg, EndDlgHdl ) );
140cdf0e10cSrcweir     aLbFilterArea.SetSelectHdl  ( LINK( this, ScSpecialFilterDlg, FilterAreaSelHdl ) );
141cdf0e10cSrcweir     aEdFilterArea.SetModifyHdl  ( LINK( this, ScSpecialFilterDlg, FilterAreaModHdl ) );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     pViewData   = rQueryItem.GetViewData();
144cdf0e10cSrcweir     pDoc        = pViewData ? pViewData->GetDocument()  : NULL;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     aEdFilterArea.SetText( EMPTY_STRING );      // may be overwritten below
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     if ( pViewData && pDoc )
149cdf0e10cSrcweir     {
150cdf0e10cSrcweir         if(pDoc->GetChangeTrack()!=NULL) aBtnCopyResult.Disable();
151cdf0e10cSrcweir 
152cdf0e10cSrcweir         ScRangeName*    pRangeNames = pDoc->GetRangeName();
153cdf0e10cSrcweir         const sal_uInt16    nCount      = pRangeNames ? pRangeNames->GetCount() : 0;
154cdf0e10cSrcweir 
155cdf0e10cSrcweir         /*
156cdf0e10cSrcweir          * Aus den RangeNames des Dokumentes werden nun die
157cdf0e10cSrcweir          * gemerkt, bei denen es sich um Filter-Bereiche handelt
158cdf0e10cSrcweir          */
159cdf0e10cSrcweir 
160cdf0e10cSrcweir         aLbFilterArea.Clear();
161cdf0e10cSrcweir         aLbFilterArea.InsertEntry( aStrUndefined, 0 );
162cdf0e10cSrcweir 
163cdf0e10cSrcweir         if ( nCount > 0 )
164cdf0e10cSrcweir         {
165cdf0e10cSrcweir             String       aString;
166cdf0e10cSrcweir             ScRangeData* pData = NULL;
167cdf0e10cSrcweir             sal_uInt16       nInsert = 0;
168cdf0e10cSrcweir 
169cdf0e10cSrcweir             for ( sal_uInt16 i=0; i<nCount; i++ )
170cdf0e10cSrcweir             {
171cdf0e10cSrcweir                 pData = (ScRangeData*)(pRangeNames->At( i ));
172cdf0e10cSrcweir                 if ( pData )
173cdf0e10cSrcweir                 {
174cdf0e10cSrcweir                     if ( pData->HasType( RT_CRITERIA ) )
175cdf0e10cSrcweir                     {
176cdf0e10cSrcweir                         pData->GetName( aString );
177cdf0e10cSrcweir                         nInsert = aLbFilterArea.InsertEntry( aString );
178cdf0e10cSrcweir                         pData->GetSymbol( aString );
179cdf0e10cSrcweir                         aLbFilterArea.SetEntryData( nInsert,
180cdf0e10cSrcweir                                                     new String( aString ) );
181cdf0e10cSrcweir                     }
182cdf0e10cSrcweir                 }
183cdf0e10cSrcweir             }
184cdf0e10cSrcweir         }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         //  is there a stored source range?
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         ScRange aAdvSource;
189cdf0e10cSrcweir         if (rQueryItem.GetAdvancedQuerySource(aAdvSource))
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             String aRefStr;
192cdf0e10cSrcweir             aAdvSource.Format( aRefStr, SCR_ABS_3D, pDoc, pDoc->GetAddressConvention() );
193cdf0e10cSrcweir             aEdFilterArea.SetRefString( aRefStr );
194cdf0e10cSrcweir         }
195cdf0e10cSrcweir     }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     aLbFilterArea.SelectEntryPos( 0 );
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     // Optionen initialisieren lassen:
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     pOptionsMgr  = new ScFilterOptionsMgr(
202cdf0e10cSrcweir                             this,
203cdf0e10cSrcweir                             pViewData,
204cdf0e10cSrcweir                             theQueryData,
205cdf0e10cSrcweir                             aBtnMore,
206cdf0e10cSrcweir                             aBtnCase,
207cdf0e10cSrcweir                             aBtnRegExp,
208cdf0e10cSrcweir                             aBtnHeader,
209cdf0e10cSrcweir                             aBtnUnique,
210cdf0e10cSrcweir                             aBtnCopyResult,
211cdf0e10cSrcweir                             aBtnDestPers,
212cdf0e10cSrcweir                             aLbCopyArea,
213cdf0e10cSrcweir                             aEdCopyArea,
214cdf0e10cSrcweir                             aRbCopyArea,
215cdf0e10cSrcweir                             aFtDbAreaLabel,
216cdf0e10cSrcweir                             aFtDbArea,
217cdf0e10cSrcweir                             aFlOptions,
218cdf0e10cSrcweir                             aStrNoName,
219cdf0e10cSrcweir                             aStrUndefined );
220cdf0e10cSrcweir 
221cdf0e10cSrcweir     //  #35206# Spezialfilter braucht immer Spaltenkoepfe
222cdf0e10cSrcweir     aBtnHeader.Check(sal_True);
223cdf0e10cSrcweir     aBtnHeader.Disable();
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     // Modal-Modus einschalten
226cdf0e10cSrcweir //  SetDispatcherLock( sal_True );
227cdf0e10cSrcweir     //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
228cdf0e10cSrcweir     //SFX_APPWINDOW->Disable(sal_False);        //! allgemeine Methode im ScAnyRefDlg
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir 
232cdf0e10cSrcweir //----------------------------------------------------------------------------
233cdf0e10cSrcweir 
Close()234cdf0e10cSrcweir sal_Bool __EXPORT ScSpecialFilterDlg::Close()
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     if (pViewData)
237cdf0e10cSrcweir         pViewData->GetDocShell()->CancelAutoDBRange();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     return DoClose( ScSpecialFilterDlgWrapper::GetChildWindowId() );
240cdf0e10cSrcweir }
241cdf0e10cSrcweir 
242cdf0e10cSrcweir 
243cdf0e10cSrcweir //----------------------------------------------------------------------------
244cdf0e10cSrcweir // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
245cdf0e10cSrcweir // neue Selektion im Referenz-Edit angezeigt wird.
246cdf0e10cSrcweir 
SetReference(const ScRange & rRef,ScDocument * pDocP)247cdf0e10cSrcweir void ScSpecialFilterDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir     if ( bRefInputMode && pRefInputEdit )       // Nur moeglich, wenn im Referenz-Editmodus
250cdf0e10cSrcweir     {
251cdf0e10cSrcweir         if ( rRef.aStart != rRef.aEnd )
252cdf0e10cSrcweir             RefInputStart( pRefInputEdit );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir         String aRefStr;
255cdf0e10cSrcweir         const formula::FormulaGrammar::AddressConvention eConv = pDocP->GetAddressConvention();
256cdf0e10cSrcweir 
257cdf0e10cSrcweir         if ( pRefInputEdit == &aEdCopyArea)
258cdf0e10cSrcweir             rRef.aStart.Format( aRefStr, SCA_ABS_3D, pDocP, eConv );
259cdf0e10cSrcweir         else if ( pRefInputEdit == &aEdFilterArea)
260cdf0e10cSrcweir             rRef.Format( aRefStr, SCR_ABS_3D, pDocP, eConv );
261cdf0e10cSrcweir 
262cdf0e10cSrcweir         pRefInputEdit->SetRefString( aRefStr );
263cdf0e10cSrcweir     }
264cdf0e10cSrcweir }
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 
267cdf0e10cSrcweir //----------------------------------------------------------------------------
268cdf0e10cSrcweir 
SetActive()269cdf0e10cSrcweir void ScSpecialFilterDlg::SetActive()
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     if ( bRefInputMode )
272cdf0e10cSrcweir     {
273cdf0e10cSrcweir         if ( pRefInputEdit == &aEdCopyArea )
274cdf0e10cSrcweir         {
275cdf0e10cSrcweir             aEdCopyArea.GrabFocus();
276cdf0e10cSrcweir             if ( aEdCopyArea.GetModifyHdl().IsSet() )
277cdf0e10cSrcweir                 ((Link&)aEdCopyArea.GetModifyHdl()).Call( &aEdCopyArea );
278cdf0e10cSrcweir         }
279cdf0e10cSrcweir         else if ( pRefInputEdit == &aEdFilterArea )
280cdf0e10cSrcweir         {
281cdf0e10cSrcweir             aEdFilterArea.GrabFocus();
282cdf0e10cSrcweir             FilterAreaModHdl( &aEdFilterArea );
283cdf0e10cSrcweir         }
284cdf0e10cSrcweir     }
285cdf0e10cSrcweir     else
286cdf0e10cSrcweir         GrabFocus();
287cdf0e10cSrcweir 
288cdf0e10cSrcweir     RefInputDone();
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 
292cdf0e10cSrcweir //----------------------------------------------------------------------------
293cdf0e10cSrcweir 
GetOutputItem(const ScQueryParam & rParam,const ScRange & rSource)294cdf0e10cSrcweir ScQueryItem* ScSpecialFilterDlg::GetOutputItem( const ScQueryParam& rParam,
295cdf0e10cSrcweir                                                 const ScRange& rSource )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir     if ( pOutItem ) DELETEZ( pOutItem );
298cdf0e10cSrcweir     pOutItem = new ScQueryItem( nWhichQuery, &rParam );
299cdf0e10cSrcweir     pOutItem->SetAdvancedQuerySource( &rSource );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir     return pOutItem;
302cdf0e10cSrcweir }
303cdf0e10cSrcweir 
304cdf0e10cSrcweir 
305cdf0e10cSrcweir //----------------------------------------------------------------------------
306cdf0e10cSrcweir 
IsRefInputMode() const307cdf0e10cSrcweir sal_Bool ScSpecialFilterDlg::IsRefInputMode() const
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     return bRefInputMode;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 
313cdf0e10cSrcweir //----------------------------------------------------------------------------
314cdf0e10cSrcweir // Handler:
315cdf0e10cSrcweir // ========
316cdf0e10cSrcweir 
IMPL_LINK(ScSpecialFilterDlg,EndDlgHdl,Button *,pBtn)317cdf0e10cSrcweir IMPL_LINK( ScSpecialFilterDlg, EndDlgHdl, Button*, pBtn )
318cdf0e10cSrcweir {
319cdf0e10cSrcweir     DBG_ASSERT( pDoc && pViewData, "Document or ViewData not found. :-/" );
320cdf0e10cSrcweir 
321cdf0e10cSrcweir     if ( (pBtn == &aBtnOk) && pDoc && pViewData )
322cdf0e10cSrcweir     {
323cdf0e10cSrcweir         String          theCopyStr( aEdCopyArea.GetText() );
324cdf0e10cSrcweir         String          theAreaStr( aEdFilterArea.GetText() );
325cdf0e10cSrcweir         ScQueryParam    theOutParam( theQueryData );
326cdf0e10cSrcweir         ScAddress       theAdrCopy;
327cdf0e10cSrcweir         sal_Bool            bEditInputOk    = sal_True;
328cdf0e10cSrcweir         sal_Bool            bQueryOk        = sal_False;
329cdf0e10cSrcweir         ScRange         theFilterArea;
330cdf0e10cSrcweir         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
331cdf0e10cSrcweir 
332cdf0e10cSrcweir         if ( aBtnCopyResult.IsChecked() )
333cdf0e10cSrcweir         {
334cdf0e10cSrcweir             xub_StrLen nColonPos = theCopyStr.Search( ':' );
335cdf0e10cSrcweir 
336cdf0e10cSrcweir             if ( STRING_NOTFOUND != nColonPos )
337cdf0e10cSrcweir                 theCopyStr.Erase( nColonPos );
338cdf0e10cSrcweir 
339cdf0e10cSrcweir             sal_uInt16 nResult = theAdrCopy.Parse( theCopyStr, pDoc, eConv );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir             if ( SCA_VALID != (nResult & SCA_VALID) )
342cdf0e10cSrcweir             {
343cdf0e10cSrcweir                 if ( !aBtnMore.GetState() )
344cdf0e10cSrcweir                     aBtnMore.SetState( sal_True );
345cdf0e10cSrcweir 
346cdf0e10cSrcweir                 ERRORBOX( STR_INVALID_TABREF );
347cdf0e10cSrcweir                 aEdCopyArea.GrabFocus();
348cdf0e10cSrcweir                 bEditInputOk = sal_False;
349cdf0e10cSrcweir             }
350cdf0e10cSrcweir         }
351cdf0e10cSrcweir 
352cdf0e10cSrcweir         if ( bEditInputOk )
353cdf0e10cSrcweir         {
354cdf0e10cSrcweir             sal_uInt16 nResult = ScRange().Parse( theAreaStr, pDoc, eConv );
355cdf0e10cSrcweir 
356cdf0e10cSrcweir             if ( SCA_VALID != (nResult & SCA_VALID) )
357cdf0e10cSrcweir             {
358cdf0e10cSrcweir                 ERRORBOX( STR_INVALID_TABREF );
359cdf0e10cSrcweir                 aEdFilterArea.GrabFocus();
360cdf0e10cSrcweir                 bEditInputOk = sal_False;
361cdf0e10cSrcweir             }
362cdf0e10cSrcweir         }
363cdf0e10cSrcweir 
364cdf0e10cSrcweir         if ( bEditInputOk )
365cdf0e10cSrcweir         {
366cdf0e10cSrcweir             /*
367cdf0e10cSrcweir              * Alle Edit-Felder enthalten gueltige Bereiche.
368cdf0e10cSrcweir              * Nun wird versucht aus dem Filterbereich
369cdf0e10cSrcweir              * ein ScQueryParam zu erzeugen:
370cdf0e10cSrcweir              */
371cdf0e10cSrcweir 
372cdf0e10cSrcweir             sal_uInt16  nResult = theFilterArea.Parse( theAreaStr, pDoc, eConv );
373cdf0e10cSrcweir 
374cdf0e10cSrcweir             if ( SCA_VALID == (nResult & SCA_VALID) )
375cdf0e10cSrcweir             {
376cdf0e10cSrcweir                 ScAddress& rStart = theFilterArea.aStart;
377cdf0e10cSrcweir                 ScAddress& rEnd   = theFilterArea.aEnd;
378cdf0e10cSrcweir 
379cdf0e10cSrcweir                 if ( aBtnCopyResult.IsChecked() )
380cdf0e10cSrcweir                 {
381cdf0e10cSrcweir                     theOutParam.bInplace    = sal_False;
382cdf0e10cSrcweir                     theOutParam.nDestTab    = theAdrCopy.Tab();
383cdf0e10cSrcweir                     theOutParam.nDestCol    = theAdrCopy.Col();
384cdf0e10cSrcweir                     theOutParam.nDestRow    = theAdrCopy.Row();
385cdf0e10cSrcweir                 }
386cdf0e10cSrcweir                 else
387cdf0e10cSrcweir                 {
388cdf0e10cSrcweir                     theOutParam.bInplace    = sal_True;
389cdf0e10cSrcweir                     theOutParam.nDestTab    = 0;
390cdf0e10cSrcweir                     theOutParam.nDestCol    = 0;
391cdf0e10cSrcweir                     theOutParam.nDestRow    = 0;
392cdf0e10cSrcweir                 }
393cdf0e10cSrcweir 
394cdf0e10cSrcweir                 theOutParam.bHasHeader = aBtnHeader.IsChecked();
395cdf0e10cSrcweir                 theOutParam.bByRow     = sal_True;
396cdf0e10cSrcweir                 theOutParam.bCaseSens  = aBtnCase.IsChecked();
397cdf0e10cSrcweir                 theOutParam.bRegExp    = aBtnRegExp.IsChecked();
398cdf0e10cSrcweir                 theOutParam.bDuplicate = !aBtnUnique.IsChecked();
399cdf0e10cSrcweir                 theOutParam.bDestPers  = aBtnDestPers.IsChecked();
400cdf0e10cSrcweir 
401cdf0e10cSrcweir                 bQueryOk =
402cdf0e10cSrcweir                     pDoc->CreateQueryParam( rStart.Col(),
403cdf0e10cSrcweir                                             rStart.Row(),
404cdf0e10cSrcweir                                             rEnd.Col(),
405cdf0e10cSrcweir                                             rEnd.Row(),
406cdf0e10cSrcweir                                             rStart.Tab(),
407cdf0e10cSrcweir                                             theOutParam );
408cdf0e10cSrcweir 
409cdf0e10cSrcweir                 //  an der DB-Collection koennen nur MAXQUERY Filter-Eintraege
410cdf0e10cSrcweir                 //  gespeichert werden
411cdf0e10cSrcweir 
412cdf0e10cSrcweir                 if ( bQueryOk && theOutParam.GetEntryCount() > MAXQUERY &&
413cdf0e10cSrcweir                      theOutParam.GetEntry(MAXQUERY).bDoQuery )
414cdf0e10cSrcweir                 {
415cdf0e10cSrcweir                     bQueryOk = sal_False;       // zu viele
416cdf0e10cSrcweir                                             //! andere Fehlermeldung ??
417cdf0e10cSrcweir                 }
418cdf0e10cSrcweir             }
419cdf0e10cSrcweir         }
420cdf0e10cSrcweir 
421cdf0e10cSrcweir         if ( bQueryOk )
422cdf0e10cSrcweir         {
423cdf0e10cSrcweir             SetDispatcherLock( sal_False );
424cdf0e10cSrcweir             SwitchToDocument();
425cdf0e10cSrcweir             GetBindings().GetDispatcher()->Execute( FID_FILTER_OK,
426cdf0e10cSrcweir                                       SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
427cdf0e10cSrcweir                                       GetOutputItem( theOutParam, theFilterArea ), 0L, 0L );
428cdf0e10cSrcweir             Close();
429cdf0e10cSrcweir         }
430cdf0e10cSrcweir         else
431cdf0e10cSrcweir         {
432cdf0e10cSrcweir             ERRORBOX( STR_INVALID_QUERYAREA );
433cdf0e10cSrcweir             aEdFilterArea.GrabFocus();
434cdf0e10cSrcweir         }
435cdf0e10cSrcweir     }
436cdf0e10cSrcweir     else if ( pBtn == &aBtnCancel )
437cdf0e10cSrcweir     {
438cdf0e10cSrcweir         Close();
439cdf0e10cSrcweir     }
440cdf0e10cSrcweir     return 0;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir 
443cdf0e10cSrcweir 
444cdf0e10cSrcweir //----------------------------------------------------------------------------
445cdf0e10cSrcweir 
IMPL_LINK(ScSpecialFilterDlg,TimeOutHdl,Timer *,_pTimer)446cdf0e10cSrcweir IMPL_LINK( ScSpecialFilterDlg, TimeOutHdl, Timer*, _pTimer )
447cdf0e10cSrcweir {
448cdf0e10cSrcweir     // alle 50ms nachschauen, ob RefInputMode noch stimmt
449cdf0e10cSrcweir 
450cdf0e10cSrcweir     if( (_pTimer == pTimer) && IsActive() )
451cdf0e10cSrcweir     {
452cdf0e10cSrcweir         if( aEdCopyArea.HasFocus() || aRbCopyArea.HasFocus() )
453cdf0e10cSrcweir         {
454cdf0e10cSrcweir             pRefInputEdit = &aEdCopyArea;
455cdf0e10cSrcweir             bRefInputMode = sal_True;
456cdf0e10cSrcweir         }
457cdf0e10cSrcweir         else if( aEdFilterArea.HasFocus() || aRbFilterArea.HasFocus() )
458cdf0e10cSrcweir         {
459cdf0e10cSrcweir             pRefInputEdit = &aEdFilterArea;
460cdf0e10cSrcweir             bRefInputMode = sal_True;
461cdf0e10cSrcweir         }
462cdf0e10cSrcweir         else if( bRefInputMode )
463cdf0e10cSrcweir         {
464cdf0e10cSrcweir             pRefInputEdit = NULL;
465cdf0e10cSrcweir             bRefInputMode = sal_False;
466cdf0e10cSrcweir         }
467cdf0e10cSrcweir     }
468cdf0e10cSrcweir 
469cdf0e10cSrcweir     pTimer->Start();
470cdf0e10cSrcweir 
471cdf0e10cSrcweir     return 0;
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir 
475cdf0e10cSrcweir //----------------------------------------------------------------------------
476cdf0e10cSrcweir 
IMPL_LINK(ScSpecialFilterDlg,FilterAreaSelHdl,ListBox *,pLb)477cdf0e10cSrcweir IMPL_LINK( ScSpecialFilterDlg, FilterAreaSelHdl, ListBox*, pLb )
478cdf0e10cSrcweir {
479cdf0e10cSrcweir     if ( pLb == &aLbFilterArea )
480cdf0e10cSrcweir     {
481cdf0e10cSrcweir         String  aString;
482cdf0e10cSrcweir         sal_uInt16  nSelPos = aLbFilterArea.GetSelectEntryPos();
483cdf0e10cSrcweir 
484cdf0e10cSrcweir         if ( nSelPos > 0 )
485cdf0e10cSrcweir             aString = *(String*)aLbFilterArea.GetEntryData( nSelPos );
486cdf0e10cSrcweir 
487cdf0e10cSrcweir         aEdFilterArea.SetText( aString );
488cdf0e10cSrcweir     }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir     return 0;
491cdf0e10cSrcweir }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir 
494cdf0e10cSrcweir //----------------------------------------------------------------------------
495cdf0e10cSrcweir 
IMPL_LINK(ScSpecialFilterDlg,FilterAreaModHdl,formula::RefEdit *,pEd)496cdf0e10cSrcweir IMPL_LINK( ScSpecialFilterDlg, FilterAreaModHdl, formula::RefEdit*, pEd )
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     if ( pEd == &aEdFilterArea )
499cdf0e10cSrcweir     {
500cdf0e10cSrcweir         if ( pDoc && pViewData )
501cdf0e10cSrcweir         {
502cdf0e10cSrcweir             String  theCurAreaStr = pEd->GetText();
503cdf0e10cSrcweir             sal_uInt16  nResult = ScRange().Parse( theCurAreaStr, pDoc );
504cdf0e10cSrcweir 
505cdf0e10cSrcweir             if ( SCA_VALID == (nResult & SCA_VALID) )
506cdf0e10cSrcweir             {
507cdf0e10cSrcweir                 String* pStr    = NULL;
508cdf0e10cSrcweir                 sal_Bool    bFound  = sal_False;
509cdf0e10cSrcweir                 sal_uInt16  i       = 0;
510cdf0e10cSrcweir                 sal_uInt16  nCount  = aLbFilterArea.GetEntryCount();
511cdf0e10cSrcweir 
512cdf0e10cSrcweir                 for ( i=1; i<nCount && !bFound; i++ )
513cdf0e10cSrcweir                 {
514cdf0e10cSrcweir                     pStr = (String*)aLbFilterArea.GetEntryData( i );
515cdf0e10cSrcweir                     bFound = (theCurAreaStr == *pStr);
516cdf0e10cSrcweir                 }
517cdf0e10cSrcweir 
518cdf0e10cSrcweir                 if ( bFound )
519cdf0e10cSrcweir                     aLbFilterArea.SelectEntryPos( --i );
520cdf0e10cSrcweir                 else
521cdf0e10cSrcweir                     aLbFilterArea.SelectEntryPos( 0 );
522cdf0e10cSrcweir             }
523cdf0e10cSrcweir         }
524cdf0e10cSrcweir         else
525cdf0e10cSrcweir             aLbFilterArea.SelectEntryPos( 0 );
526cdf0e10cSrcweir     }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir     return 0;
529cdf0e10cSrcweir }
530