fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / dbgui / foptmgr.cxx
blobf17ae254715e8c2f8363b4ddb4ba8b778d61bea6
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 <svtools/stdctrl.hxx>
22 #include "anyrefdg.hxx"
23 #include "rangeutl.hxx"
24 #include "dbdata.hxx"
25 #include "viewdata.hxx"
26 #include "document.hxx"
27 #include "queryparam.hxx"
28 #include "globalnames.hxx"
30 #include "foptmgr.hxx"
32 // ScFilterOptionsMgr (.ui's option helper)
34 ScFilterOptionsMgr::ScFilterOptionsMgr(
35 ScViewData* ptrViewData,
36 const ScQueryParam& refQueryData,
37 CheckBox* refBtnCase,
38 CheckBox* refBtnRegExp,
39 CheckBox* refBtnHeader,
40 CheckBox* refBtnUnique,
41 CheckBox* refBtnCopyResult,
42 CheckBox* refBtnDestPers,
43 ListBox* refLbCopyArea,
44 Edit* refEdCopyArea,
45 formula::RefButton* refRbCopyArea,
46 FixedText* refFtDbAreaLabel,
47 FixedText* refFtDbArea,
48 const OUString& refStrUndefined )
50 : pViewData ( ptrViewData ),
51 pDoc ( ptrViewData ? ptrViewData->GetDocument() : NULL ),
52 pBtnCase ( refBtnCase ),
53 pBtnRegExp ( refBtnRegExp ),
54 pBtnHeader ( refBtnHeader ),
55 pBtnUnique ( refBtnUnique ),
56 pBtnCopyResult ( refBtnCopyResult ),
57 pBtnDestPers ( refBtnDestPers ),
58 pLbCopyArea ( refLbCopyArea ),
59 pEdCopyArea ( refEdCopyArea ),
60 pRbCopyArea ( refRbCopyArea ),
61 pFtDbAreaLabel ( refFtDbAreaLabel ),
62 pFtDbArea ( refFtDbArea ),
63 rStrUndefined ( refStrUndefined ),
64 rQueryData ( refQueryData )
66 Init();
69 ScFilterOptionsMgr::~ScFilterOptionsMgr()
71 sal_uInt16 nEntries = pLbCopyArea->GetEntryCount();
72 sal_uInt16 i;
74 for ( i=2; i<nEntries; i++ )
75 delete static_cast<OUString*>(pLbCopyArea->GetEntryData( i ));
78 void ScFilterOptionsMgr::Init()
80 //moggi:TODO
81 OSL_ENSURE( pViewData && pDoc, "Init failed :-/" );
83 pLbCopyArea->SetSelectHdl ( LINK( this, ScFilterOptionsMgr, LbAreaSelHdl ) );
84 pEdCopyArea->SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdAreaModifyHdl ) );
85 pBtnCopyResult->SetToggleHdl ( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
87 pBtnCase ->Check( rQueryData.bCaseSens );
88 pBtnHeader ->Check( rQueryData.bHasHeader );
89 pBtnRegExp ->Check( rQueryData.bRegExp );
90 pBtnUnique ->Check( !rQueryData.bDuplicate );
92 if ( pViewData && pDoc )
94 OUString theAreaStr;
95 ScRange theCurArea ( ScAddress( rQueryData.nCol1,
96 rQueryData.nRow1,
97 pViewData->GetTabNo() ),
98 ScAddress( rQueryData.nCol2,
99 rQueryData.nRow2,
100 pViewData->GetTabNo() ) );
101 ScDBCollection* pDBColl = pDoc->GetDBCollection();
102 OUStringBuffer theDbArea;
103 OUString theDbName(STR_DB_LOCAL_NONAME);
104 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
106 theAreaStr = theCurArea.Format(SCR_ABS_3D, pDoc, eConv);
108 // Zielbereichsliste fuellen
110 pLbCopyArea->Clear();
111 pLbCopyArea->InsertEntry( rStrUndefined, 0 );
113 ScAreaNameIterator aIter( pDoc );
114 OUString aName;
115 ScRange aRange;
116 while ( aIter.Next( aName, aRange ) )
118 sal_uInt16 nInsert = pLbCopyArea->InsertEntry( aName );
120 OUString aRefStr(aRange.aStart.Format(SCA_ABS_3D, pDoc, eConv));
121 pLbCopyArea->SetEntryData( nInsert, new OUString( aRefStr ) );
124 pBtnDestPers->Check( true ); // beim Aufruf immer an
125 pLbCopyArea->SelectEntryPos( 0 );
126 pEdCopyArea->SetText( EMPTY_OUSTRING );
129 * Ueberpruefen, ob es sich bei dem uebergebenen
130 * Bereich um einen Datenbankbereich handelt:
133 theDbArea = theAreaStr;
135 if ( pDBColl )
137 ScAddress& rStart = theCurArea.aStart;
138 ScAddress& rEnd = theCurArea.aEnd;
139 const ScDBData* pDBData = pDBColl->GetDBAtArea(
140 rStart.Tab(), rStart.Col(), rStart.Row(), rEnd.Col(), rEnd.Row());
142 if ( pDBData )
144 pBtnHeader->Check( pDBData->HasHeader() );
145 theDbName = pDBData->GetName();
147 if ( theDbName == STR_DB_LOCAL_NONAME )
148 pBtnHeader->Enable();
149 else
150 pBtnHeader->Disable();
154 if ( theDbName != STR_DB_LOCAL_NONAME )
156 theDbArea.append(" (");
157 theDbArea.append(theDbName).append(')');
158 pFtDbArea->SetText( theDbArea.makeStringAndClear() );
160 else
162 pFtDbAreaLabel->SetText( OUString() );
163 pFtDbArea->SetText( OUString() );
166 // Kopierposition:
168 if ( !rQueryData.bInplace )
170 OUString aString =
171 ScAddress( rQueryData.nDestCol,
172 rQueryData.nDestRow,
173 rQueryData.nDestTab
174 ).Format(SCA_ABS_3D, pDoc, eConv);
176 pBtnCopyResult->Check( true );
177 pEdCopyArea->SetText( aString );
178 EdAreaModifyHdl( pEdCopyArea );
179 pLbCopyArea->Enable();
180 pEdCopyArea->Enable();
181 pRbCopyArea->Enable();
182 pBtnDestPers->Enable();
184 else
186 pBtnCopyResult->Check( false );
187 pEdCopyArea->SetText( EMPTY_OUSTRING );
188 pLbCopyArea->Disable();
189 pEdCopyArea->Disable();
190 pRbCopyArea->Disable();
191 pBtnDestPers->Disable();
194 else
195 pEdCopyArea->SetText( EMPTY_OUSTRING );
198 bool ScFilterOptionsMgr::VerifyPosStr( const OUString& rPosStr ) const
200 OUString aPosStr( rPosStr );
201 sal_Int32 nColonPos = aPosStr.indexOf( ':' );
203 if ( -1 != nColonPos )
204 aPosStr = aPosStr.copy( 0, nColonPos );
206 sal_uInt16 nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() );
208 return ( SCA_VALID == (nResult & SCA_VALID) );
211 // Handler:
213 IMPL_LINK( ScFilterOptionsMgr, LbAreaSelHdl, ListBox*, pLb )
215 if ( pLb == pLbCopyArea )
217 OUString aString;
218 sal_uInt16 nSelPos = pLbCopyArea->GetSelectEntryPos();
220 if ( nSelPos > 0 )
221 aString = *static_cast<OUString*>(pLbCopyArea->GetEntryData( nSelPos ));
223 pEdCopyArea->SetText( aString );
226 return 0;
229 IMPL_LINK( ScFilterOptionsMgr, EdAreaModifyHdl, Edit*, pEd )
231 if ( pEd == pEdCopyArea )
233 OUString theCurPosStr = pEd->GetText();
234 sal_uInt16 nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
236 if ( SCA_VALID == (nResult & SCA_VALID) )
238 bool bFound = false;
239 sal_uInt16 i = 0;
240 sal_uInt16 nCount = pLbCopyArea->GetEntryCount();
242 for ( i=2; i<nCount && !bFound; i++ )
244 OUString* pStr = static_cast<OUString*>(pLbCopyArea->GetEntryData( i ));
245 bFound = (theCurPosStr == *pStr);
248 if ( bFound )
249 pLbCopyArea->SelectEntryPos( --i );
250 else
251 pLbCopyArea->SelectEntryPos( 0 );
253 else
254 pLbCopyArea->SelectEntryPos( 0 );
257 return 0;
260 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox )
262 if ( pBox == pBtnCopyResult )
264 if ( pBox->IsChecked() )
266 pBtnDestPers->Enable();
267 pLbCopyArea->Enable();
268 pEdCopyArea->Enable();
269 pRbCopyArea->Enable();
270 pEdCopyArea->GrabFocus();
272 else
274 pBtnDestPers->Disable();
275 pLbCopyArea->Disable();
276 pEdCopyArea->Disable();
277 pRbCopyArea->Disable();
281 return 0;
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */