1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27 // System - Includes ---------------------------------------------------------
28
29
30
31 // INCLUDE -------------------------------------------------------------------
32
33 #include <vcl/morebtn.hxx>
34 #include <svtools/stdctrl.hxx>
35
36 #include "anyrefdg.hxx"
37 #include "rangeutl.hxx"
38 #include "dbcolect.hxx"
39 #include "viewdata.hxx"
40 #include "document.hxx"
41 #include "queryparam.hxx"
42
43 #define _FOPTMGR_CXX
44 #include "foptmgr.hxx"
45 #undef _FOPTMGR_CXX
46
47 //----------------------------------------------------------------------------
48
ScFilterOptionsMgr(Dialog * ptrDlg,ScViewData * ptrViewData,const ScQueryParam & refQueryData,MoreButton & refBtnMore,CheckBox & refBtnCase,CheckBox & refBtnRegExp,CheckBox & refBtnHeader,CheckBox & refBtnUnique,CheckBox & refBtnCopyResult,CheckBox & refBtnDestPers,ListBox & refLbCopyArea,Edit & refEdCopyArea,formula::RefButton & refRbCopyArea,FixedText & refFtDbAreaLabel,FixedInfo & refFtDbArea,FixedLine & refFlOptions,const String & refStrNoName,const String & refStrUndefined)49 ScFilterOptionsMgr::ScFilterOptionsMgr(
50 Dialog* ptrDlg,
51 ScViewData* ptrViewData,
52 const ScQueryParam& refQueryData,
53 MoreButton& refBtnMore,
54 CheckBox& refBtnCase,
55 CheckBox& refBtnRegExp,
56 CheckBox& refBtnHeader,
57 CheckBox& refBtnUnique,
58 CheckBox& refBtnCopyResult,
59 CheckBox& refBtnDestPers,
60 ListBox& refLbCopyArea,
61 Edit& refEdCopyArea,
62 formula::RefButton& refRbCopyArea,
63 FixedText& refFtDbAreaLabel,
64 FixedInfo& refFtDbArea,
65 FixedLine& refFlOptions,
66 const String& refStrNoName,
67 const String& refStrUndefined )
68
69 : pDlg ( ptrDlg ),
70 pViewData ( ptrViewData ),
71 pDoc ( ptrViewData ? ptrViewData->GetDocument() : NULL ),
72 rBtnMore ( refBtnMore ),
73 rBtnCase ( refBtnCase ),
74 rBtnRegExp ( refBtnRegExp ),
75 rBtnHeader ( refBtnHeader ),
76 rBtnUnique ( refBtnUnique ),
77 rBtnCopyResult ( refBtnCopyResult ),
78 rBtnDestPers ( refBtnDestPers ),
79 rLbCopyPos ( refLbCopyArea ),
80 rEdCopyPos ( refEdCopyArea ),
81 rRbCopyPos ( refRbCopyArea ),
82 rFtDbAreaLabel ( refFtDbAreaLabel ),
83 rFtDbArea ( refFtDbArea ),
84 rFlOptions ( refFlOptions ),
85 rStrNoName ( refStrNoName ),
86 rStrUndefined ( refStrUndefined ),
87 rQueryData ( refQueryData )
88 {
89 Init();
90 }
91
92
93 //----------------------------------------------------------------------------
94
~ScFilterOptionsMgr()95 ScFilterOptionsMgr::~ScFilterOptionsMgr()
96 {
97 sal_uInt16 nEntries = rLbCopyPos.GetEntryCount();
98 sal_uInt16 i;
99
100 for ( i=2; i<nEntries; i++ )
101 delete (String*)rLbCopyPos.GetEntryData( i );
102 }
103
104
105 //----------------------------------------------------------------------------
106
Init()107 void ScFilterOptionsMgr::Init()
108 {
109 DBG_ASSERT( pViewData && pDoc, "Init failed :-/" );
110
111 rLbCopyPos.SetSelectHdl ( LINK( this, ScFilterOptionsMgr, LbPosSelHdl ) );
112 rEdCopyPos.SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdPosModifyHdl ) );
113 rBtnCopyResult.SetClickHdl( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
114
115 rBtnMore.AddWindow( &rBtnCase );
116 rBtnMore.AddWindow( &rBtnRegExp );
117 rBtnMore.AddWindow( &rBtnHeader );
118 rBtnMore.AddWindow( &rBtnUnique );
119 rBtnMore.AddWindow( &rBtnCopyResult );
120 rBtnMore.AddWindow( &rBtnDestPers );
121 rBtnMore.AddWindow( &rLbCopyPos );
122 rBtnMore.AddWindow( &rEdCopyPos );
123 rBtnMore.AddWindow( &rRbCopyPos );
124 rBtnMore.AddWindow( &rFtDbAreaLabel );
125 rBtnMore.AddWindow( &rFtDbArea );
126 rBtnMore.AddWindow( &rFlOptions );
127
128 rBtnCase .Check( rQueryData.bCaseSens );
129 rBtnHeader .Check( rQueryData.bHasHeader );
130 rBtnRegExp .Check( rQueryData.bRegExp );
131 rBtnUnique .Check( !rQueryData.bDuplicate );
132
133 if ( pViewData && pDoc )
134 {
135 String theAreaStr;
136 ScRange theCurArea ( ScAddress( rQueryData.nCol1,
137 rQueryData.nRow1,
138 pViewData->GetTabNo() ),
139 ScAddress( rQueryData.nCol2,
140 rQueryData.nRow2,
141 pViewData->GetTabNo() ) );
142 ScDBCollection* pDBColl = pDoc->GetDBCollection();
143 String theDbArea;
144 String theDbName = rStrNoName;
145 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
146
147 theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, eConv );
148
149 // Zielbereichsliste fuellen
150
151 rLbCopyPos.Clear();
152 rLbCopyPos.InsertEntry( rStrUndefined, 0 );
153
154 ScAreaNameIterator aIter( pDoc );
155 String aName;
156 ScRange aRange;
157 String aRefStr;
158 while ( aIter.Next( aName, aRange ) )
159 {
160 sal_uInt16 nInsert = rLbCopyPos.InsertEntry( aName );
161
162 aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv );
163 rLbCopyPos.SetEntryData( nInsert, new String( aRefStr ) );
164 }
165
166 rBtnDestPers.Check( sal_True ); // beim Aufruf immer an
167 rLbCopyPos.SelectEntryPos( 0 );
168 rEdCopyPos.SetText( EMPTY_STRING );
169
170 /*
171 * Ueberpruefen, ob es sich bei dem uebergebenen
172 * Bereich um einen Datenbankbereich handelt:
173 */
174
175 theDbArea = theAreaStr;
176
177 if ( pDBColl )
178 {
179 ScAddress& rStart = theCurArea.aStart;
180 ScAddress& rEnd = theCurArea.aEnd;
181 ScDBData* pDBData = pDBColl->GetDBAtArea(
182 rStart.Tab(), rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row() );
183 if ( pDBData )
184 {
185 rBtnHeader.Check( pDBData->HasHeader() );
186 pDBData->GetName( theDbName );
187
188 if ( !pDBData->IsInternalUnnamed()
189 && !pDBData->IsInternalForAutoFilter() )
190 {
191 rBtnHeader.Disable();
192 }
193 }
194 }
195
196 theDbArea.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
197 theDbArea += theDbName;
198 theDbArea += ')';
199 rFtDbArea.SetText( theDbArea );
200
201 //------------------------------------------------------
202 // Kopierposition:
203
204 if ( !rQueryData.bInplace )
205 {
206 String aString;
207
208 ScAddress( rQueryData.nDestCol,
209 rQueryData.nDestRow,
210 rQueryData.nDestTab
211 ).Format( aString, SCA_ABS_3D, pDoc, eConv );
212
213 rBtnCopyResult.Check( sal_True );
214 rEdCopyPos.SetText( aString );
215 EdPosModifyHdl( &rEdCopyPos );
216 rLbCopyPos.Enable();
217 rEdCopyPos.Enable();
218 rRbCopyPos.Enable();
219 rBtnDestPers.Enable();
220 }
221 else
222 {
223 rBtnCopyResult.Check( sal_False );
224 rEdCopyPos.SetText( EMPTY_STRING );
225 rLbCopyPos.Disable();
226 rEdCopyPos.Disable();
227 rRbCopyPos.Disable();
228 rBtnDestPers.Disable();
229 }
230 }
231 else
232 rEdCopyPos.SetText( EMPTY_STRING );
233 }
234
235
236 //----------------------------------------------------------------------------
237
VerifyPosStr(const String & rPosStr) const238 sal_Bool ScFilterOptionsMgr::VerifyPosStr( const String& rPosStr ) const
239 {
240 String aPosStr( rPosStr );
241 xub_StrLen nColonPos = aPosStr.Search( ':' );
242
243 if ( STRING_NOTFOUND != nColonPos )
244 aPosStr.Erase( nColonPos );
245
246 sal_uInt16 nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() );
247
248 return ( SCA_VALID == (nResult & SCA_VALID) );
249 }
250
251
252 //----------------------------------------------------------------------------
253 // Handler:
254
255 //----------------------------------------------------------------------------
256
IMPL_LINK(ScFilterOptionsMgr,LbPosSelHdl,ListBox *,pLb)257 IMPL_LINK( ScFilterOptionsMgr, LbPosSelHdl, ListBox*, pLb )
258 {
259 if ( pLb == &rLbCopyPos )
260 {
261 String aString;
262 sal_uInt16 nSelPos = rLbCopyPos.GetSelectEntryPos();
263
264 if ( nSelPos > 0 )
265 aString = *(String*)rLbCopyPos.GetEntryData( nSelPos );
266
267 rEdCopyPos.SetText( aString );
268 }
269
270 return 0;
271 }
272
273
274 //----------------------------------------------------------------------------
275
IMPL_LINK(ScFilterOptionsMgr,EdPosModifyHdl,Edit *,pEd)276 IMPL_LINK( ScFilterOptionsMgr, EdPosModifyHdl, Edit*, pEd )
277 {
278 if ( pEd == &rEdCopyPos )
279 {
280 String theCurPosStr = pEd->GetText();
281 sal_uInt16 nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
282
283 if ( SCA_VALID == (nResult & SCA_VALID) )
284 {
285 String* pStr = NULL;
286 sal_Bool bFound = sal_False;
287 sal_uInt16 i = 0;
288 sal_uInt16 nCount = rLbCopyPos.GetEntryCount();
289
290 for ( i=2; i<nCount && !bFound; i++ )
291 {
292 pStr = (String*)rLbCopyPos.GetEntryData( i );
293 bFound = (theCurPosStr == *pStr);
294 }
295
296 if ( bFound )
297 rLbCopyPos.SelectEntryPos( --i );
298 else
299 rLbCopyPos.SelectEntryPos( 0 );
300 }
301 else
302 rLbCopyPos.SelectEntryPos( 0 );
303 }
304
305 return 0;
306 }
307
308
309 //----------------------------------------------------------------------------
310
IMPL_LINK(ScFilterOptionsMgr,BtnCopyResultHdl,CheckBox *,pBox)311 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox )
312 {
313 if ( pBox == &rBtnCopyResult )
314 {
315 if ( pBox->IsChecked() )
316 {
317 rBtnDestPers.Enable();
318 rLbCopyPos.Enable();
319 rEdCopyPos.Enable();
320 rRbCopyPos.Enable();
321 rEdCopyPos.GrabFocus();
322 }
323 else
324 {
325 rBtnDestPers.Disable();
326 rLbCopyPos.Disable();
327 rEdCopyPos.Disable();
328 rRbCopyPos.Disable();
329 }
330 }
331
332 return 0;
333 }
334