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: pfiltdlg.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 #undef SC_DLLIMPLEMENTATION
39 #include <vcl/waitobj.hxx>
42 // INCLUDE ---------------------------------------------------------------
44 #include "viewdata.hxx"
45 #include "document.hxx"
46 #include "uiitems.hxx"
48 #include "dbcolect.hxx"
49 #include "scresid.hxx"
53 #include "globstr.hrc"
56 #include "pfiltdlg.hxx"
58 #include <svtools/zforlist.hxx>
60 //==================================================================
62 ScPivotFilterDlg::ScPivotFilterDlg( Window
* pParent
,
63 const SfxItemSet
& rArgSet
,
66 : ModalDialog ( pParent
, ScResId( RID_SCDLG_PIVOTFILTER
) ),
68 aFlCriteria ( this, ScResId( FL_CRITERIA
) ),
69 aLbField1 ( this, ScResId( LB_FIELD1
) ),
70 aLbCond1 ( this, ScResId( LB_COND1
) ),
71 aEdVal1 ( this, ScResId( ED_VAL1
) ),
72 aLbConnect1 ( this, ScResId( LB_OP1
) ),
73 aLbField2 ( this, ScResId( LB_FIELD2
) ),
74 aLbCond2 ( this, ScResId( LB_COND2
) ),
75 aEdVal2 ( this, ScResId( ED_VAL2
) ),
76 aLbConnect2 ( this, ScResId( LB_OP2
) ),
77 aLbField3 ( this, ScResId( LB_FIELD3
) ),
78 aLbCond3 ( this, ScResId( LB_COND3
) ),
79 aEdVal3 ( this, ScResId( ED_VAL3
) ),
80 aFtConnect ( this, ScResId( FT_OP
) ),
81 aFtField ( this, ScResId( FT_FIELD
) ),
82 aFtCond ( this, ScResId( FT_COND
) ),
83 aFtVal ( this, ScResId( FT_VAL
) ),
84 aFlOptions ( this, ScResId( FL_OPTIONS
) ),
85 aBtnCase ( this, ScResId( BTN_CASE
) ),
86 aBtnRegExp ( this, ScResId( BTN_REGEXP
) ),
87 aBtnUnique ( this, ScResId( BTN_UNIQUE
) ),
88 aFtDbAreaLabel ( this, ScResId( FT_DBAREA_LABEL
) ),
89 aFtDbArea ( this, ScResId( FT_DBAREA
) ),
90 aBtnOk ( this, ScResId( BTN_OK
) ),
91 aBtnCancel ( this, ScResId( BTN_CANCEL
) ),
92 aBtnHelp ( this, ScResId( BTN_HELP
) ),
93 aBtnMore ( this, ScResId( BTN_MORE
) ),
94 aStrUndefined ( ScResId( SCSTR_UNDEFINED
) ),
95 aStrNoName ( ScGlobal::GetRscString(STR_DB_NONAME
) ),
96 aStrNone ( ScResId( SCSTR_NONE
) ),
97 aStrEmpty ( ScResId( SCSTR_EMPTY
) ),
98 aStrNotEmpty ( ScResId( SCSTR_NOTEMPTY
) ),
99 aStrRow ( ScResId( SCSTR_ROW
) ),
100 aStrColumn ( ScResId( SCSTR_COLUMN
) ),
102 nWhichQuery ( rArgSet
.GetPool()->GetWhich( SID_QUERY
) ),
103 theQueryData ( ((const ScQueryItem
&)
104 rArgSet
.Get( nWhichQuery
)).GetQueryData() ),
108 nSrcTab ( nSourceTab
), // ist nicht im QueryParam
111 for (USHORT i
=0; i
<=MAXCOL
; i
++)
112 pEntryLists
[i
] = NULL
;
118 //------------------------------------------------------------------------
120 __EXPORT
ScPivotFilterDlg::~ScPivotFilterDlg()
122 for (USHORT i
=0; i
<=MAXCOL
; i
++)
123 delete pEntryLists
[i
];
129 //------------------------------------------------------------------------
131 void __EXPORT
ScPivotFilterDlg::Init( const SfxItemSet
& rArgSet
)
133 const ScQueryItem
& rQueryItem
= (const ScQueryItem
&)
134 rArgSet
.Get( nWhichQuery
);
136 aBtnCase
.SetClickHdl ( LINK( this, ScPivotFilterDlg
, CheckBoxHdl
) );
138 aLbField1
.SetSelectHdl ( LINK( this, ScPivotFilterDlg
, LbSelectHdl
) );
139 aLbField2
.SetSelectHdl ( LINK( this, ScPivotFilterDlg
, LbSelectHdl
) );
140 aLbField3
.SetSelectHdl ( LINK( this, ScPivotFilterDlg
, LbSelectHdl
) );
141 aLbConnect1
.SetSelectHdl( LINK( this, ScPivotFilterDlg
, LbSelectHdl
) );
142 aLbConnect2
.SetSelectHdl( LINK( this, ScPivotFilterDlg
, LbSelectHdl
) );
144 aBtnMore
.AddWindow( &aBtnCase
);
145 aBtnMore
.AddWindow( &aBtnRegExp
);
146 aBtnMore
.AddWindow( &aBtnUnique
);
147 aBtnMore
.AddWindow( &aFtDbAreaLabel
);
148 aBtnMore
.AddWindow( &aFtDbArea
);
149 aBtnMore
.AddWindow( &aFlOptions
);
151 aBtnCase
.Check( theQueryData
.bCaseSens
);
152 aBtnRegExp
.Check( theQueryData
.bRegExp
);
153 aBtnUnique
.Check( !theQueryData
.bDuplicate
);
155 pViewData
= rQueryItem
.GetViewData();
156 pDoc
= pViewData
? pViewData
->GetDocument() : NULL
;
158 // fuer leichteren Zugriff:
159 aFieldLbArr
[0] = &aLbField1
;
160 aFieldLbArr
[1] = &aLbField2
;
161 aFieldLbArr
[2] = &aLbField3
;
162 aValueEdArr
[0] = &aEdVal1
;
163 aValueEdArr
[1] = &aEdVal2
;
164 aValueEdArr
[2] = &aEdVal3
;
165 aCondLbArr
[0] = &aLbCond1
;
166 aCondLbArr
[1] = &aLbCond2
;
167 aCondLbArr
[2] = &aLbCond3
;
169 if ( pViewData
&& pDoc
)
172 ScRange
theCurArea ( ScAddress( theQueryData
.nCol1
,
175 ScAddress( theQueryData
.nCol2
,
178 ScDBCollection
* pDBColl
= pDoc
->GetDBCollection();
180 String theDbName
= aStrNoName
;
183 * Ueberpruefen, ob es sich bei dem uebergebenen
184 * Bereich um einen Datenbankbereich handelt:
187 theCurArea
.Format( theAreaStr
, SCR_ABS_3D
, pDoc
, pDoc
->GetAddressConvention() );
191 ScAddress
& rStart
= theCurArea
.aStart
;
192 ScAddress
& rEnd
= theCurArea
.aEnd
;
193 ScDBData
* pDBData
= pDBColl
->GetDBAtArea( rStart
.Tab(),
194 rStart
.Col(), rStart
.Row(),
195 rEnd
.Col(), rEnd
.Row() );
197 pDBData
->GetName( theDbName
);
200 theDbArea
.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
201 theDbArea
+= theDbName
;
203 aFtDbArea
.SetText( theDbArea
);
207 aFtDbArea
.SetText( EMPTY_STRING
);
210 // Feldlisten einlesen und Eintraege selektieren:
214 for ( SCSIZE i
=0; i
<3; i
++ )
216 if ( theQueryData
.GetEntry(i
).bDoQuery
)
218 ScQueryEntry
& rEntry
= theQueryData
.GetEntry(i
);
220 String aValStr
= *rEntry
.pStr
;
221 if (!rEntry
.bQueryByString
&& aValStr
== EMPTY_STRING
)
223 if (rEntry
.nVal
== SC_EMPTYFIELDS
)
225 else if (rEntry
.nVal
== SC_NONEMPTYFIELDS
)
226 aValStr
= aStrNotEmpty
;
228 USHORT nCondPos
= (USHORT
)rEntry
.eOp
;
229 USHORT nFieldSelPos
= GetFieldSelPos( static_cast<SCCOL
>(rEntry
.nField
) );
231 aFieldLbArr
[i
]->SelectEntryPos( nFieldSelPos
);
232 aCondLbArr
[i
]->SelectEntryPos( nCondPos
);
233 UpdateValueList( static_cast<USHORT
>(i
+1) );
234 aValueEdArr
[i
]->SetText( aValStr
);
235 if (aValStr
== aStrEmpty
|| aValStr
== aStrNotEmpty
)
236 aCondLbArr
[i
]->Disable();
240 aFieldLbArr
[i
]->SelectEntryPos( 0 ); // "keiner" selektieren
241 aCondLbArr
[i
]->SelectEntryPos( 0 ); // "=" selektieren
242 UpdateValueList( static_cast<USHORT
>(i
) );
243 aValueEdArr
[i
]->SetText( EMPTY_STRING
);
245 aValueEdArr
[i
]->SetModifyHdl( LINK( this, ScPivotFilterDlg
, ValModifyHdl
) );
248 // Disable/Enable Logik:
250 (aLbField1
.GetSelectEntryPos() != 0)
251 && (aLbField2
.GetSelectEntryPos() != 0)
252 ? aLbConnect1
.SelectEntryPos( (USHORT
)theQueryData
.GetEntry(1).eConnect
)
253 : aLbConnect1
.SetNoSelection();
255 (aLbField2
.GetSelectEntryPos() != 0)
256 && (aLbField3
.GetSelectEntryPos() != 0)
257 ? aLbConnect2
.SelectEntryPos( (USHORT
)theQueryData
.GetEntry(2).eConnect
)
258 : aLbConnect2
.SetNoSelection();
260 if ( aLbField1
.GetSelectEntryPos() == 0 )
262 aLbConnect1
.Disable();
267 else if ( aLbConnect1
.GetSelectEntryCount() == 0 )
274 if ( aLbField2
.GetSelectEntryPos() == 0 )
276 aLbConnect2
.Disable();
281 else if ( aLbConnect2
.GetSelectEntryCount() == 0 )
289 //------------------------------------------------------------------------
291 void ScPivotFilterDlg::FillFieldLists()
296 aLbField1
.InsertEntry( aStrNone
, 0 );
297 aLbField2
.InsertEntry( aStrNone
, 0 );
298 aLbField3
.InsertEntry( aStrNone
, 0 );
303 SCTAB nTab
= nSrcTab
;
304 SCCOL nFirstCol
= theQueryData
.nCol1
;
305 SCROW nFirstRow
= theQueryData
.nRow1
;
306 SCCOL nMaxCol
= theQueryData
.nCol2
;
310 for ( col
=nFirstCol
; col
<=nMaxCol
; col
++ )
312 pDoc
->GetString( col
, nFirstRow
, nTab
, aFieldName
);
313 if ( aFieldName
.Len() == 0 )
315 aFieldName
= aStrColumn
;
317 aFieldName
+= ScColToAlpha( col
);
319 aLbField1
.InsertEntry( aFieldName
, i
);
320 aLbField2
.InsertEntry( aFieldName
, i
);
321 aLbField3
.InsertEntry( aFieldName
, i
);
328 //------------------------------------------------------------------------
330 void ScPivotFilterDlg::UpdateValueList( USHORT nList
)
332 if ( pDoc
&& nList
>0 && nList
<=3 )
334 ComboBox
* pValList
= aValueEdArr
[nList
-1];
335 USHORT nFieldSelPos
= aFieldLbArr
[nList
-1]->GetSelectEntryPos();
337 String aCurValue
= pValList
->GetText();
340 pValList
->InsertEntry( aStrNotEmpty
, 0 );
341 pValList
->InsertEntry( aStrEmpty
, 1 );
344 if ( pDoc
&& nFieldSelPos
)
346 SCCOL nColumn
= theQueryData
.nCol1
+ static_cast<SCCOL
>(nFieldSelPos
) - 1;
347 if (!pEntryLists
[nColumn
])
349 WaitObject
aWaiter( this );
351 SCTAB nTab
= nSrcTab
;
352 SCROW nFirstRow
= theQueryData
.nRow1
;
353 SCROW nLastRow
= theQueryData
.nRow2
;
355 bool bHasDates
= false;
357 pEntryLists
[nColumn
] = new TypedScStrCollection( 128, 128 );
358 pEntryLists
[nColumn
]->SetCaseSensitive( aBtnCase
.IsChecked() );
359 pDoc
->GetFilterEntriesArea( nColumn
, nFirstRow
, nLastRow
,
360 nTab
, *pEntryLists
[nColumn
], bHasDates
);
363 TypedScStrCollection
* pColl
= pEntryLists
[nColumn
];
364 USHORT nValueCount
= pColl
->GetCount();
365 if ( nValueCount
> 0 )
367 for ( USHORT i
=0; i
<nValueCount
; i
++ )
369 pValList
->InsertEntry( (*pColl
)[i
]->GetString(), nListPos
);
374 pValList
->SetText( aCurValue
);
378 //------------------------------------------------------------------------
380 void ScPivotFilterDlg::ClearValueList( USHORT nList
)
382 if ( nList
>0 && nList
<=3 )
384 ComboBox
* pValList
= aValueEdArr
[nList
-1];
386 pValList
->InsertEntry( aStrNotEmpty
, 0 );
387 pValList
->InsertEntry( aStrEmpty
, 1 );
388 pValList
->SetText( EMPTY_STRING
);
392 //------------------------------------------------------------------------
394 USHORT
ScPivotFilterDlg::GetFieldSelPos( SCCOL nField
)
396 if ( nField
>= theQueryData
.nCol1
&& nField
<= theQueryData
.nCol2
)
397 return static_cast<USHORT
>(nField
- theQueryData
.nCol1
+ 1);
402 //------------------------------------------------------------------------
404 const ScQueryItem
& ScPivotFilterDlg::GetOutputItem()
406 ScQueryParam
theParam( theQueryData
);
407 USHORT nConnect1
= aLbConnect1
.GetSelectEntryPos();
408 USHORT nConnect2
= aLbConnect2
.GetSelectEntryPos();
410 for ( SCSIZE i
=0; i
<3; i
++ )
412 USHORT nField
= aFieldLbArr
[i
]->GetSelectEntryPos();
413 ScQueryOp eOp
= (ScQueryOp
)aCondLbArr
[i
]->GetSelectEntryPos();
415 BOOL bDoThis
= (aFieldLbArr
[i
]->GetSelectEntryPos() != 0);
416 theParam
.GetEntry(i
).bDoQuery
= bDoThis
;
420 ScQueryEntry
& rEntry
= theParam
.GetEntry(i
);
422 String
aStrVal( aValueEdArr
[i
]->GetText() );
425 * Dialog liefert die ausgezeichneten Feldwerte "leer"/"nicht leer"
426 * als Konstanten in nVal in Verbindung mit dem Schalter
427 * bQueryByString auf FALSE.
429 if ( aStrVal
== aStrEmpty
)
431 *rEntry
.pStr
= EMPTY_STRING
;
432 rEntry
.nVal
= SC_EMPTYFIELDS
;
433 rEntry
.bQueryByString
= FALSE
;
435 else if ( aStrVal
== aStrNotEmpty
)
437 *rEntry
.pStr
= EMPTY_STRING
;
438 rEntry
.nVal
= SC_NONEMPTYFIELDS
;
439 rEntry
.bQueryByString
= FALSE
;
443 *rEntry
.pStr
= aStrVal
;
445 rEntry
.bQueryByString
= TRUE
;
448 rEntry
.nField
= nField
? (theQueryData
.nCol1
+
449 static_cast<SCCOL
>(nField
) - 1) : static_cast<SCCOL
>(0);
454 theParam
.GetEntry(1).eConnect
= (nConnect1
!= LISTBOX_ENTRY_NOTFOUND
)
455 ? (ScQueryConnect
)nConnect1
457 theParam
.GetEntry(2).eConnect
= (nConnect2
!= LISTBOX_ENTRY_NOTFOUND
)
458 ? (ScQueryConnect
)nConnect2
461 theParam
.bInplace
= FALSE
;
462 theParam
.nDestTab
= 0; // Woher kommen diese Werte?
463 theParam
.nDestCol
= 0;
464 theParam
.nDestRow
= 0;
466 theParam
.bDuplicate
= !aBtnUnique
.IsChecked();
467 theParam
.bCaseSens
= aBtnCase
.IsChecked();
468 theParam
.bRegExp
= aBtnRegExp
.IsChecked();
470 if ( pOutItem
) DELETEZ( pOutItem
);
471 pOutItem
= new ScQueryItem( nWhichQuery
, &theParam
);
476 //------------------------------------------------------------------------
478 //------------------------------------------------------------------------
480 IMPL_LINK( ScPivotFilterDlg
, LbSelectHdl
, ListBox
*, pLb
)
483 * Behandlung der Enable/Disable-Logik,
484 * abhaengig davon, welche ListBox angefasst wurde:
487 if ( pLb
== &aLbConnect1
)
489 if ( !aLbField2
.IsEnabled() )
496 else if ( pLb
== &aLbConnect2
)
498 if ( !aLbField3
.IsEnabled() )
505 else if ( pLb
== &aLbField1
)
507 if ( aLbField1
.GetSelectEntryPos() == 0 )
509 aLbConnect1
.SetNoSelection();
510 aLbConnect2
.SetNoSelection();
511 aLbField2
.SelectEntryPos( 0 );
512 aLbField3
.SelectEntryPos( 0 );
513 aLbCond2
.SelectEntryPos( 0 );
514 aLbCond3
.SelectEntryPos( 0 );
519 aLbConnect1
.Disable();
520 aLbConnect2
.Disable();
530 UpdateValueList( 1 );
531 if ( !aLbConnect1
.IsEnabled() )
533 aLbConnect1
.Enable();
537 else if ( pLb
== &aLbField2
)
539 if ( aLbField2
.GetSelectEntryPos() == 0 )
541 aLbConnect2
.SetNoSelection();
542 aLbField3
.SelectEntryPos( 0 );
543 aLbCond3
.SelectEntryPos( 0 );
547 aLbConnect2
.Disable();
554 UpdateValueList( 2 );
555 if ( !aLbConnect2
.IsEnabled() )
557 aLbConnect2
.Enable();
561 else if ( pLb
== &aLbField3
)
563 ( aLbField3
.GetSelectEntryPos() == 0 )
564 ? ClearValueList( 3 )
565 : UpdateValueList( 3 );
571 //----------------------------------------------------------------------------
573 IMPL_LINK( ScPivotFilterDlg
, CheckBoxHdl
, CheckBox
*, pBox
)
575 // bei Gross-/Kleinschreibung die Werte-Listen aktualisieren
577 if ( pBox
== &aBtnCase
) // Wertlisten
579 for (USHORT i
=0; i
<=MAXCOL
; i
++)
580 DELETEZ( pEntryLists
[i
] );
582 String aCurVal1
= aEdVal1
.GetText();
583 String aCurVal2
= aEdVal2
.GetText();
584 String aCurVal3
= aEdVal3
.GetText();
585 UpdateValueList( 1 );
586 UpdateValueList( 2 );
587 UpdateValueList( 3 );
588 aEdVal1
.SetText( aCurVal1
);
589 aEdVal2
.SetText( aCurVal2
);
590 aEdVal3
.SetText( aCurVal3
);
596 //------------------------------------------------------------------------
598 IMPL_LINK( ScPivotFilterDlg
, ValModifyHdl
, ComboBox
*, pEd
)
602 String aStrVal
= pEd
->GetText();
603 ListBox
* pLb
= &aLbCond1
;
605 if ( pEd
== &aEdVal2
) pLb
= &aLbCond2
;
606 else if ( pEd
== &aEdVal3
) pLb
= &aLbCond3
;
608 // wenn einer der Sonderwerte leer/nicht-leer
609 // gewaehlt wird, so macht nur der =-Operator Sinn:
611 if ( aStrEmpty
== aStrVal
|| aStrNotEmpty
== aStrVal
)
613 pLb
->SelectEntry( '=' );