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 <vcl/morebtn.hxx>
21 #include <svtools/stdctrl.hxx>
23 #include "anyrefdg.hxx"
24 #include "rangeutl.hxx"
26 #include "viewdata.hxx"
27 #include "document.hxx"
28 #include "queryparam.hxx"
29 #include "globalnames.hxx"
32 #include "foptmgr.hxx"
35 //----------------------------------------------------------------------------
37 ScFilterOptionsMgr::ScFilterOptionsMgr(
38 ScViewData
* ptrViewData
,
39 const ScQueryParam
& refQueryData
,
40 MoreButton
& refBtnMore
,
42 CheckBox
& refBtnRegExp
,
43 CheckBox
& refBtnHeader
,
44 CheckBox
& refBtnUnique
,
45 CheckBox
& refBtnCopyResult
,
46 CheckBox
& refBtnDestPers
,
47 ListBox
& refLbCopyArea
,
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
)
77 //----------------------------------------------------------------------------
79 ScFilterOptionsMgr::~ScFilterOptionsMgr()
81 sal_uInt16 nEntries
= rLbCopyPos
.GetEntryCount();
84 for ( i
=2; i
<nEntries
; i
++ )
85 delete (String
*)rLbCopyPos
.GetEntryData( i
);
89 //----------------------------------------------------------------------------
91 void ScFilterOptionsMgr::Init()
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
)
121 ScRange
theCurArea ( ScAddress( rQueryData
.nCol1
,
123 pViewData
->GetTabNo() ),
124 ScAddress( rQueryData
.nCol2
,
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
137 rLbCopyPos
.InsertEntry( rStrUndefined
, 0 );
139 ScAreaNameIterator
aIter( pDoc
);
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
;
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());
171 rBtnHeader
.Check( pDBData
->HasHeader() );
172 theDbName
= pDBData
->GetName();
174 if ( theDbName
== STR_DB_LOCAL_NONAME
)
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() );
189 rFtDbAreaLabel
.SetText( OUString() );
190 rFtDbArea
.SetText( OUString() );
193 //------------------------------------------------------
196 if ( !rQueryData
.bInplace
)
200 ScAddress( rQueryData
.nDestCol
,
203 ).Format( aString
, SCA_ABS_3D
, pDoc
, eConv
);
205 rBtnCopyResult
.Check( sal_True
);
206 rEdCopyPos
.SetText( aString
);
207 EdPosModifyHdl( &rEdCopyPos
);
211 rBtnDestPers
.Enable();
215 rBtnCopyResult
.Check( false );
216 rEdCopyPos
.SetText( EMPTY_STRING
);
217 rLbCopyPos
.Disable();
218 rEdCopyPos
.Disable();
219 rRbCopyPos
.Disable();
220 rBtnDestPers
.Disable();
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 //----------------------------------------------------------------------------
247 //----------------------------------------------------------------------------
249 IMPL_LINK( ScFilterOptionsMgr
, LbPosSelHdl
, ListBox
*, pLb
)
251 if ( pLb
== &rLbCopyPos
)
254 sal_uInt16 nSelPos
= rLbCopyPos
.GetSelectEntryPos();
257 aString
= *(String
*)rLbCopyPos
.GetEntryData( nSelPos
);
259 rEdCopyPos
.SetText( aString
);
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
) )
278 sal_Bool bFound
= false;
280 sal_uInt16 nCount
= rLbCopyPos
.GetEntryCount();
282 for ( i
=2; i
<nCount
&& !bFound
; i
++ )
284 pStr
= (String
*)rLbCopyPos
.GetEntryData( i
);
285 bFound
= (theCurPosStr
== *pStr
);
289 rLbCopyPos
.SelectEntryPos( --i
);
291 rLbCopyPos
.SelectEntryPos( 0 );
294 rLbCopyPos
.SelectEntryPos( 0 );
301 //----------------------------------------------------------------------------
303 IMPL_LINK( ScFilterOptionsMgr
, BtnCopyResultHdl
, CheckBox
*, pBox
)
305 if ( pBox
== &rBtnCopyResult
)
307 if ( pBox
->IsChecked() )
309 rBtnDestPers
.Enable();
313 rEdCopyPos
.GrabFocus();
317 rBtnDestPers
.Disable();
318 rLbCopyPos
.Disable();
319 rEdCopyPos
.Disable();
320 rRbCopyPos
.Disable();
327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */