Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <vcl/morebtn.hxx>
30 : : #include <svtools/stdctrl.hxx>
31 : :
32 : : #include "anyrefdg.hxx"
33 : : #include "rangeutl.hxx"
34 : : #include "dbdata.hxx"
35 : : #include "viewdata.hxx"
36 : : #include "document.hxx"
37 : : #include "queryparam.hxx"
38 : : #include "globalnames.hxx"
39 : :
40 : : #define _FOPTMGR_CXX
41 : : #include "foptmgr.hxx"
42 : : #undef _FOPTMGR_CXX
43 : :
44 : : //----------------------------------------------------------------------------
45 : :
46 : 0 : ScFilterOptionsMgr::ScFilterOptionsMgr(
47 : : Dialog* ptrDlg,
48 : : ScViewData* ptrViewData,
49 : : const ScQueryParam& refQueryData,
50 : : MoreButton& refBtnMore,
51 : : CheckBox& refBtnCase,
52 : : CheckBox& refBtnRegExp,
53 : : CheckBox& refBtnHeader,
54 : : CheckBox& refBtnUnique,
55 : : CheckBox& refBtnCopyResult,
56 : : CheckBox& refBtnDestPers,
57 : : ListBox& refLbCopyArea,
58 : : Edit& refEdCopyArea,
59 : : formula::RefButton& refRbCopyArea,
60 : : FixedText& refFtDbAreaLabel,
61 : : FixedInfo& refFtDbArea,
62 : : FixedLine& refFlOptions,
63 : : const String& refStrUndefined )
64 : :
65 : : : pDlg ( ptrDlg ),
66 : : pViewData ( ptrViewData ),
67 : : pDoc ( ptrViewData ? ptrViewData->GetDocument() : NULL ),
68 : : rBtnMore ( refBtnMore ),
69 : : rBtnCase ( refBtnCase ),
70 : : rBtnRegExp ( refBtnRegExp ),
71 : : rBtnHeader ( refBtnHeader ),
72 : : rBtnUnique ( refBtnUnique ),
73 : : rBtnCopyResult ( refBtnCopyResult ),
74 : : rBtnDestPers ( refBtnDestPers ),
75 : : rLbCopyPos ( refLbCopyArea ),
76 : : rEdCopyPos ( refEdCopyArea ),
77 : : rRbCopyPos ( refRbCopyArea ),
78 : : rFtDbAreaLabel ( refFtDbAreaLabel ),
79 : : rFtDbArea ( refFtDbArea ),
80 : : rFlOptions ( refFlOptions ),
81 : : rStrUndefined ( refStrUndefined ),
82 [ # # ]: 0 : rQueryData ( refQueryData )
83 : : {
84 : 0 : Init();
85 : 0 : }
86 : :
87 : :
88 : : //----------------------------------------------------------------------------
89 : :
90 : 0 : ScFilterOptionsMgr::~ScFilterOptionsMgr()
91 : : {
92 : 0 : sal_uInt16 nEntries = rLbCopyPos.GetEntryCount();
93 : : sal_uInt16 i;
94 : :
95 [ # # ]: 0 : for ( i=2; i<nEntries; i++ )
96 [ # # ]: 0 : delete (String*)rLbCopyPos.GetEntryData( i );
97 : 0 : }
98 : :
99 : :
100 : : //----------------------------------------------------------------------------
101 : :
102 : 0 : void ScFilterOptionsMgr::Init()
103 : : {
104 : : //moggi:TODO
105 : : OSL_ENSURE( pViewData && pDoc, "Init failed :-/" );
106 : :
107 : 0 : rLbCopyPos.SetSelectHdl ( LINK( this, ScFilterOptionsMgr, LbPosSelHdl ) );
108 [ # # ]: 0 : rEdCopyPos.SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdPosModifyHdl ) );
109 : 0 : rBtnCopyResult.SetClickHdl( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
110 : :
111 : 0 : rBtnMore.AddWindow( &rBtnCase );
112 : 0 : rBtnMore.AddWindow( &rBtnRegExp );
113 : 0 : rBtnMore.AddWindow( &rBtnHeader );
114 : 0 : rBtnMore.AddWindow( &rBtnUnique );
115 : 0 : rBtnMore.AddWindow( &rBtnCopyResult );
116 : 0 : rBtnMore.AddWindow( &rBtnDestPers );
117 : 0 : rBtnMore.AddWindow( &rLbCopyPos );
118 : 0 : rBtnMore.AddWindow( &rEdCopyPos );
119 : 0 : rBtnMore.AddWindow( &rRbCopyPos );
120 : 0 : rBtnMore.AddWindow( &rFtDbAreaLabel );
121 : 0 : rBtnMore.AddWindow( &rFtDbArea );
122 : 0 : rBtnMore.AddWindow( &rFlOptions );
123 : :
124 : 0 : rBtnCase .Check( rQueryData.bCaseSens );
125 : 0 : rBtnHeader .Check( rQueryData.bHasHeader );
126 : 0 : rBtnRegExp .Check( rQueryData.bRegExp );
127 : 0 : rBtnUnique .Check( !rQueryData.bDuplicate );
128 : :
129 [ # # ][ # # ]: 0 : if ( pViewData && pDoc )
130 : : {
131 : 0 : rtl::OUString theAreaStr;
132 : : ScRange theCurArea ( ScAddress( rQueryData.nCol1,
133 : : rQueryData.nRow1,
134 : 0 : pViewData->GetTabNo() ),
135 : : ScAddress( rQueryData.nCol2,
136 : : rQueryData.nRow2,
137 : 0 : pViewData->GetTabNo() ) );
138 [ # # ]: 0 : ScDBCollection* pDBColl = pDoc->GetDBCollection();
139 : 0 : rtl::OUStringBuffer theDbArea;
140 [ # # ]: 0 : rtl::OUString theDbName(RTL_CONSTASCII_USTRINGPARAM(STR_DB_LOCAL_NONAME));
141 [ # # ]: 0 : const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
142 : :
143 [ # # ]: 0 : theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, eConv );
144 : :
145 : : // Zielbereichsliste fuellen
146 : :
147 [ # # ]: 0 : rLbCopyPos.Clear();
148 [ # # ]: 0 : rLbCopyPos.InsertEntry( rStrUndefined, 0 );
149 : :
150 [ # # ]: 0 : ScAreaNameIterator aIter( pDoc );
151 [ # # ]: 0 : String aName;
152 : 0 : ScRange aRange;
153 [ # # ]: 0 : String aRefStr;
154 [ # # ][ # # ]: 0 : while ( aIter.Next( aName, aRange ) )
155 : : {
156 [ # # ]: 0 : sal_uInt16 nInsert = rLbCopyPos.InsertEntry( aName );
157 : :
158 [ # # ]: 0 : aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv );
159 [ # # ][ # # ]: 0 : rLbCopyPos.SetEntryData( nInsert, new String( aRefStr ) );
[ # # ]
160 : : }
161 : :
162 [ # # ]: 0 : rBtnDestPers.Check( sal_True ); // beim Aufruf immer an
163 [ # # ]: 0 : rLbCopyPos.SelectEntryPos( 0 );
164 [ # # ][ # # ]: 0 : rEdCopyPos.SetText( EMPTY_STRING );
165 : :
166 : : /*
167 : : * Ueberpruefen, ob es sich bei dem uebergebenen
168 : : * Bereich um einen Datenbankbereich handelt:
169 : : */
170 : :
171 [ # # ][ # # ]: 0 : theDbArea = theAreaStr;
172 : :
173 [ # # ]: 0 : if ( pDBColl )
174 : : {
175 : 0 : ScAddress& rStart = theCurArea.aStart;
176 : 0 : ScAddress& rEnd = theCurArea.aEnd;
177 : : const ScDBData* pDBData = pDBColl->GetDBAtArea(
178 [ # # ]: 0 : rStart.Tab(), rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row());
179 : :
180 [ # # ]: 0 : if ( pDBData )
181 : : {
182 [ # # ]: 0 : rBtnHeader.Check( pDBData->HasHeader() );
183 : 0 : theDbName = pDBData->GetName();
184 : :
185 [ # # ]: 0 : if ( theDbName == STR_DB_LOCAL_NONAME )
186 [ # # ]: 0 : rBtnHeader.Enable();
187 : : else
188 [ # # ]: 0 : rBtnHeader.Disable();
189 : : }
190 : : }
191 : :
192 [ # # ]: 0 : if ( !theDbName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(STR_DB_LOCAL_NONAME)) )
193 : : {
194 [ # # ]: 0 : theDbArea.appendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
195 [ # # ][ # # ]: 0 : theDbArea.append(theDbName).append(')');
196 [ # # ][ # # ]: 0 : rFtDbArea.SetText( theDbArea.makeStringAndClear() );
[ # # ][ # # ]
197 : : }
198 : : else
199 : : {
200 [ # # ][ # # ]: 0 : rFtDbAreaLabel.SetText( rtl::OUString() );
[ # # ]
201 [ # # ][ # # ]: 0 : rFtDbArea.SetText( rtl::OUString() );
[ # # ]
202 : : }
203 : :
204 : : //------------------------------------------------------
205 : : // Kopierposition:
206 : :
207 [ # # ]: 0 : if ( !rQueryData.bInplace )
208 : : {
209 [ # # ]: 0 : String aString;
210 : :
211 : : ScAddress( rQueryData.nDestCol,
212 : : rQueryData.nDestRow,
213 : : rQueryData.nDestTab
214 [ # # ]: 0 : ).Format( aString, SCA_ABS_3D, pDoc, eConv );
215 : :
216 [ # # ]: 0 : rBtnCopyResult.Check( sal_True );
217 [ # # ]: 0 : rEdCopyPos.SetText( aString );
218 [ # # ]: 0 : EdPosModifyHdl( &rEdCopyPos );
219 [ # # ]: 0 : rLbCopyPos.Enable();
220 [ # # ]: 0 : rEdCopyPos.Enable();
221 [ # # ]: 0 : rRbCopyPos.Enable();
222 [ # # ][ # # ]: 0 : rBtnDestPers.Enable();
223 : : }
224 : : else
225 : : {
226 [ # # ]: 0 : rBtnCopyResult.Check( false );
227 [ # # ][ # # ]: 0 : rEdCopyPos.SetText( EMPTY_STRING );
228 [ # # ]: 0 : rLbCopyPos.Disable();
229 [ # # ]: 0 : rEdCopyPos.Disable();
230 [ # # ]: 0 : rRbCopyPos.Disable();
231 [ # # ]: 0 : rBtnDestPers.Disable();
232 [ # # ][ # # ]: 0 : }
233 : : }
234 : : else
235 : 0 : rEdCopyPos.SetText( EMPTY_STRING );
236 : 0 : }
237 : :
238 : :
239 : : //----------------------------------------------------------------------------
240 : :
241 : 0 : sal_Bool ScFilterOptionsMgr::VerifyPosStr( const String& rPosStr ) const
242 : : {
243 [ # # ]: 0 : String aPosStr( rPosStr );
244 [ # # ]: 0 : xub_StrLen nColonPos = aPosStr.Search( ':' );
245 : :
246 [ # # ]: 0 : if ( STRING_NOTFOUND != nColonPos )
247 [ # # ]: 0 : aPosStr.Erase( nColonPos );
248 : :
249 [ # # ][ # # ]: 0 : sal_uInt16 nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() );
250 : :
251 [ # # ]: 0 : return ( SCA_VALID == (nResult & SCA_VALID) );
252 : : }
253 : :
254 : :
255 : : //----------------------------------------------------------------------------
256 : : // Handler:
257 : :
258 : : //----------------------------------------------------------------------------
259 : :
260 : 0 : IMPL_LINK( ScFilterOptionsMgr, LbPosSelHdl, ListBox*, pLb )
261 : : {
262 [ # # ]: 0 : if ( pLb == &rLbCopyPos )
263 : : {
264 [ # # ]: 0 : String aString;
265 [ # # ]: 0 : sal_uInt16 nSelPos = rLbCopyPos.GetSelectEntryPos();
266 : :
267 [ # # ]: 0 : if ( nSelPos > 0 )
268 [ # # ][ # # ]: 0 : aString = *(String*)rLbCopyPos.GetEntryData( nSelPos );
269 : :
270 [ # # ][ # # ]: 0 : rEdCopyPos.SetText( aString );
271 : : }
272 : :
273 : 0 : return 0;
274 : : }
275 : :
276 : :
277 : : //----------------------------------------------------------------------------
278 : :
279 : 0 : IMPL_LINK( ScFilterOptionsMgr, EdPosModifyHdl, Edit*, pEd )
280 : : {
281 [ # # ]: 0 : if ( pEd == &rEdCopyPos )
282 : : {
283 [ # # ]: 0 : String theCurPosStr = pEd->GetText();
284 [ # # ][ # # ]: 0 : sal_uInt16 nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
285 : :
286 [ # # ]: 0 : if ( SCA_VALID == (nResult & SCA_VALID) )
287 : : {
288 : 0 : String* pStr = NULL;
289 : 0 : sal_Bool bFound = false;
290 : 0 : sal_uInt16 i = 0;
291 [ # # ]: 0 : sal_uInt16 nCount = rLbCopyPos.GetEntryCount();
292 : :
293 [ # # ][ # # ]: 0 : for ( i=2; i<nCount && !bFound; i++ )
[ # # ]
294 : : {
295 [ # # ]: 0 : pStr = (String*)rLbCopyPos.GetEntryData( i );
296 [ # # ]: 0 : bFound = (theCurPosStr == *pStr);
297 : : }
298 : :
299 [ # # ]: 0 : if ( bFound )
300 [ # # ]: 0 : rLbCopyPos.SelectEntryPos( --i );
301 : : else
302 [ # # ]: 0 : rLbCopyPos.SelectEntryPos( 0 );
303 : : }
304 : : else
305 [ # # ][ # # ]: 0 : rLbCopyPos.SelectEntryPos( 0 );
306 : : }
307 : :
308 : 0 : return 0;
309 : : }
310 : :
311 : :
312 : : //----------------------------------------------------------------------------
313 : :
314 : 0 : IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox )
315 : : {
316 [ # # ]: 0 : if ( pBox == &rBtnCopyResult )
317 : : {
318 [ # # ]: 0 : if ( pBox->IsChecked() )
319 : : {
320 : 0 : rBtnDestPers.Enable();
321 : 0 : rLbCopyPos.Enable();
322 : 0 : rEdCopyPos.Enable();
323 : 0 : rRbCopyPos.Enable();
324 : 0 : rEdCopyPos.GrabFocus();
325 : : }
326 : : else
327 : : {
328 : 0 : rBtnDestPers.Disable();
329 : 0 : rLbCopyPos.Disable();
330 : 0 : rEdCopyPos.Disable();
331 : 0 : rRbCopyPos.Disable();
332 : : }
333 : : }
334 : :
335 : 0 : return 0;
336 : : }
337 : :
338 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|