bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / dbgui / foptmgr.cxx
blob5d31d1da530f2c9485de4c60381c3fdd9a02f2be
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/morebtn.hxx>
21 #include <svtools/stdctrl.hxx>
23 #include "anyrefdg.hxx"
24 #include "rangeutl.hxx"
25 #include "dbdata.hxx"
26 #include "viewdata.hxx"
27 #include "document.hxx"
28 #include "queryparam.hxx"
29 #include "globalnames.hxx"
31 #define _FOPTMGR_CXX
32 #include "foptmgr.hxx"
33 #undef _FOPTMGR_CXX
35 //----------------------------------------------------------------------------
37 ScFilterOptionsMgr::ScFilterOptionsMgr(
38 ScViewData* ptrViewData,
39 const ScQueryParam& refQueryData,
40 MoreButton& refBtnMore,
41 CheckBox& refBtnCase,
42 CheckBox& refBtnRegExp,
43 CheckBox& refBtnHeader,
44 CheckBox& refBtnUnique,
45 CheckBox& refBtnCopyResult,
46 CheckBox& refBtnDestPers,
47 ListBox& refLbCopyArea,
48 Edit& refEdCopyArea,
49 formula::RefButton& refRbCopyArea,
50 FixedText& refFtDbAreaLabel,
51 FixedInfo& refFtDbArea,
52 FixedLine& refFlOptions,
53 const String& refStrUndefined )
55 : pViewData ( ptrViewData ),
56 pDoc ( ptrViewData ? ptrViewData->GetDocument() : NULL ),
57 rBtnMore ( refBtnMore ),
58 rBtnCase ( refBtnCase ),
59 rBtnRegExp ( refBtnRegExp ),
60 rBtnHeader ( refBtnHeader ),
61 rBtnUnique ( refBtnUnique ),
62 rBtnCopyResult ( refBtnCopyResult ),
63 rBtnDestPers ( refBtnDestPers ),
64 rLbCopyPos ( refLbCopyArea ),
65 rEdCopyPos ( refEdCopyArea ),
66 rRbCopyPos ( refRbCopyArea ),
67 rFtDbAreaLabel ( refFtDbAreaLabel ),
68 rFtDbArea ( refFtDbArea ),
69 rFlOptions ( refFlOptions ),
70 rStrUndefined ( refStrUndefined ),
71 rQueryData ( refQueryData )
73 Init();
77 //----------------------------------------------------------------------------
79 ScFilterOptionsMgr::~ScFilterOptionsMgr()
81 sal_uInt16 nEntries = rLbCopyPos.GetEntryCount();
82 sal_uInt16 i;
84 for ( i=2; i<nEntries; i++ )
85 delete (String*)rLbCopyPos.GetEntryData( i );
89 //----------------------------------------------------------------------------
91 void ScFilterOptionsMgr::Init()
93 //moggi:TODO
94 OSL_ENSURE( pViewData && pDoc, "Init failed :-/" );
96 rLbCopyPos.SetSelectHdl ( LINK( this, ScFilterOptionsMgr, LbPosSelHdl ) );
97 rEdCopyPos.SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdPosModifyHdl ) );
98 rBtnCopyResult.SetClickHdl( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
100 rBtnMore.AddWindow( &rBtnCase );
101 rBtnMore.AddWindow( &rBtnRegExp );
102 rBtnMore.AddWindow( &rBtnHeader );
103 rBtnMore.AddWindow( &rBtnUnique );
104 rBtnMore.AddWindow( &rBtnCopyResult );
105 rBtnMore.AddWindow( &rBtnDestPers );
106 rBtnMore.AddWindow( &rLbCopyPos );
107 rBtnMore.AddWindow( &rEdCopyPos );
108 rBtnMore.AddWindow( &rRbCopyPos );
109 rBtnMore.AddWindow( &rFtDbAreaLabel );
110 rBtnMore.AddWindow( &rFtDbArea );
111 rBtnMore.AddWindow( &rFlOptions );
113 rBtnCase .Check( rQueryData.bCaseSens );
114 rBtnHeader .Check( rQueryData.bHasHeader );
115 rBtnRegExp .Check( rQueryData.bRegExp );
116 rBtnUnique .Check( !rQueryData.bDuplicate );
118 if ( pViewData && pDoc )
120 OUString theAreaStr;
121 ScRange theCurArea ( ScAddress( rQueryData.nCol1,
122 rQueryData.nRow1,
123 pViewData->GetTabNo() ),
124 ScAddress( rQueryData.nCol2,
125 rQueryData.nRow2,
126 pViewData->GetTabNo() ) );
127 ScDBCollection* pDBColl = pDoc->GetDBCollection();
128 OUStringBuffer theDbArea;
129 OUString theDbName(STR_DB_LOCAL_NONAME);
130 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
132 theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, eConv );
134 // Zielbereichsliste fuellen
136 rLbCopyPos.Clear();
137 rLbCopyPos.InsertEntry( rStrUndefined, 0 );
139 ScAreaNameIterator aIter( pDoc );
140 String aName;
141 ScRange aRange;
142 String aRefStr;
143 while ( aIter.Next( aName, aRange ) )
145 sal_uInt16 nInsert = rLbCopyPos.InsertEntry( aName );
147 aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv );
148 rLbCopyPos.SetEntryData( nInsert, new String( aRefStr ) );
151 rBtnDestPers.Check( sal_True ); // beim Aufruf immer an
152 rLbCopyPos.SelectEntryPos( 0 );
153 rEdCopyPos.SetText( EMPTY_STRING );
156 * Ueberpruefen, ob es sich bei dem uebergebenen
157 * Bereich um einen Datenbankbereich handelt:
160 theDbArea = theAreaStr;
162 if ( pDBColl )
164 ScAddress& rStart = theCurArea.aStart;
165 ScAddress& rEnd = theCurArea.aEnd;
166 const ScDBData* pDBData = pDBColl->GetDBAtArea(
167 rStart.Tab(), rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row());
169 if ( pDBData )
171 rBtnHeader.Check( pDBData->HasHeader() );
172 theDbName = pDBData->GetName();
174 if ( theDbName == STR_DB_LOCAL_NONAME )
175 rBtnHeader.Enable();
176 else
177 rBtnHeader.Disable();
181 if ( !theDbName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM(STR_DB_LOCAL_NONAME)) )
183 theDbArea.appendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
184 theDbArea.append(theDbName).append(')');
185 rFtDbArea.SetText( theDbArea.makeStringAndClear() );
187 else
189 rFtDbAreaLabel.SetText( OUString() );
190 rFtDbArea.SetText( OUString() );
193 //------------------------------------------------------
194 // Kopierposition:
196 if ( !rQueryData.bInplace )
198 String aString;
200 ScAddress( rQueryData.nDestCol,
201 rQueryData.nDestRow,
202 rQueryData.nDestTab
203 ).Format( aString, SCA_ABS_3D, pDoc, eConv );
205 rBtnCopyResult.Check( sal_True );
206 rEdCopyPos.SetText( aString );
207 EdPosModifyHdl( &rEdCopyPos );
208 rLbCopyPos.Enable();
209 rEdCopyPos.Enable();
210 rRbCopyPos.Enable();
211 rBtnDestPers.Enable();
213 else
215 rBtnCopyResult.Check( false );
216 rEdCopyPos.SetText( EMPTY_STRING );
217 rLbCopyPos.Disable();
218 rEdCopyPos.Disable();
219 rRbCopyPos.Disable();
220 rBtnDestPers.Disable();
223 else
224 rEdCopyPos.SetText( EMPTY_STRING );
228 //----------------------------------------------------------------------------
230 sal_Bool ScFilterOptionsMgr::VerifyPosStr( const String& rPosStr ) const
232 String aPosStr( rPosStr );
233 xub_StrLen nColonPos = aPosStr.Search( ':' );
235 if ( STRING_NOTFOUND != nColonPos )
236 aPosStr.Erase( nColonPos );
238 sal_uInt16 nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() );
240 return ( SCA_VALID == (nResult & SCA_VALID) );
244 //----------------------------------------------------------------------------
245 // Handler:
247 //----------------------------------------------------------------------------
249 IMPL_LINK( ScFilterOptionsMgr, LbPosSelHdl, ListBox*, pLb )
251 if ( pLb == &rLbCopyPos )
253 String aString;
254 sal_uInt16 nSelPos = rLbCopyPos.GetSelectEntryPos();
256 if ( nSelPos > 0 )
257 aString = *(String*)rLbCopyPos.GetEntryData( nSelPos );
259 rEdCopyPos.SetText( aString );
262 return 0;
266 //----------------------------------------------------------------------------
268 IMPL_LINK( ScFilterOptionsMgr, EdPosModifyHdl, Edit*, pEd )
270 if ( pEd == &rEdCopyPos )
272 String theCurPosStr = pEd->GetText();
273 sal_uInt16 nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
275 if ( SCA_VALID == (nResult & SCA_VALID) )
277 String* pStr = NULL;
278 sal_Bool bFound = false;
279 sal_uInt16 i = 0;
280 sal_uInt16 nCount = rLbCopyPos.GetEntryCount();
282 for ( i=2; i<nCount && !bFound; i++ )
284 pStr = (String*)rLbCopyPos.GetEntryData( i );
285 bFound = (theCurPosStr == *pStr);
288 if ( bFound )
289 rLbCopyPos.SelectEntryPos( --i );
290 else
291 rLbCopyPos.SelectEntryPos( 0 );
293 else
294 rLbCopyPos.SelectEntryPos( 0 );
297 return 0;
301 //----------------------------------------------------------------------------
303 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox )
305 if ( pBox == &rBtnCopyResult )
307 if ( pBox->IsChecked() )
309 rBtnDestPers.Enable();
310 rLbCopyPos.Enable();
311 rEdCopyPos.Enable();
312 rRbCopyPos.Enable();
313 rEdCopyPos.GrabFocus();
315 else
317 rBtnDestPers.Disable();
318 rLbCopyPos.Disable();
319 rEdCopyPos.Disable();
320 rRbCopyPos.Disable();
324 return 0;
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */