1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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
,
38 CheckBox
* refBtnRegExp
,
39 CheckBox
* refBtnHeader
,
40 CheckBox
* refBtnUnique
,
41 CheckBox
* refBtnCopyResult
,
42 CheckBox
* refBtnDestPers
,
43 ListBox
* refLbCopyArea
,
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
)
69 ScFilterOptionsMgr::~ScFilterOptionsMgr()
71 sal_uInt16 nEntries
= pLbCopyArea
->GetEntryCount();
74 for ( i
=2; i
<nEntries
; i
++ )
75 delete static_cast<OUString
*>(pLbCopyArea
->GetEntryData( i
));
78 void ScFilterOptionsMgr::Init()
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
)
95 ScRange
theCurArea ( ScAddress( rQueryData
.nCol1
,
97 pViewData
->GetTabNo() ),
98 ScAddress( rQueryData
.nCol2
,
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
);
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
;
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());
144 pBtnHeader
->Check( pDBData
->HasHeader() );
145 theDbName
= pDBData
->GetName();
147 if ( theDbName
== STR_DB_LOCAL_NONAME
)
148 pBtnHeader
->Enable();
150 pBtnHeader
->Disable();
154 if ( theDbName
!= STR_DB_LOCAL_NONAME
)
156 theDbArea
.append(" (");
157 theDbArea
.append(theDbName
).append(')');
158 pFtDbArea
->SetText( theDbArea
.makeStringAndClear() );
162 pFtDbAreaLabel
->SetText( OUString() );
163 pFtDbArea
->SetText( OUString() );
168 if ( !rQueryData
.bInplace
)
171 ScAddress( rQueryData
.nDestCol
,
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();
186 pBtnCopyResult
->Check( false );
187 pEdCopyArea
->SetText( EMPTY_OUSTRING
);
188 pLbCopyArea
->Disable();
189 pEdCopyArea
->Disable();
190 pRbCopyArea
->Disable();
191 pBtnDestPers
->Disable();
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
) );
213 IMPL_LINK( ScFilterOptionsMgr
, LbAreaSelHdl
, ListBox
*, pLb
)
215 if ( pLb
== pLbCopyArea
)
218 sal_uInt16 nSelPos
= pLbCopyArea
->GetSelectEntryPos();
221 aString
= *static_cast<OUString
*>(pLbCopyArea
->GetEntryData( nSelPos
));
223 pEdCopyArea
->SetText( aString
);
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
) )
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
);
249 pLbCopyArea
->SelectEntryPos( --i
);
251 pLbCopyArea
->SelectEntryPos( 0 );
254 pLbCopyArea
->SelectEntryPos( 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();
274 pBtnDestPers
->Disable();
275 pLbCopyArea
->Disable();
276 pEdCopyArea
->Disable();
277 pRbCopyArea
->Disable();
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */