1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: foptmgr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes ---------------------------------------------------------
38 // INCLUDE -------------------------------------------------------------------
40 #include <vcl/morebtn.hxx>
41 #include <svtools/stdctrl.hxx>
43 #include "anyrefdg.hxx"
44 #include "rangeutl.hxx"
45 #include "dbcolect.hxx"
46 #include "viewdata.hxx"
47 #include "document.hxx"
50 #include "foptmgr.hxx"
53 //----------------------------------------------------------------------------
55 ScFilterOptionsMgr::ScFilterOptionsMgr(
57 ScViewData
* ptrViewData
,
58 const ScQueryParam
& refQueryData
,
59 MoreButton
& refBtnMore
,
61 CheckBox
& refBtnRegExp
,
62 CheckBox
& refBtnHeader
,
63 CheckBox
& refBtnUnique
,
64 CheckBox
& refBtnCopyResult
,
65 CheckBox
& refBtnDestPers
,
66 ListBox
& refLbCopyArea
,
68 formula::RefButton
& refRbCopyArea
,
69 FixedText
& refFtDbAreaLabel
,
70 FixedInfo
& refFtDbArea
,
71 FixedLine
& refFlOptions
,
72 const String
& refStrNoName
,
73 const String
& refStrUndefined
)
76 pViewData ( ptrViewData
),
77 pDoc ( ptrViewData
? ptrViewData
->GetDocument() : NULL
),
78 rBtnMore ( refBtnMore
),
79 rBtnCase ( refBtnCase
),
80 rBtnRegExp ( refBtnRegExp
),
81 rBtnHeader ( refBtnHeader
),
82 rBtnUnique ( refBtnUnique
),
83 rBtnCopyResult ( refBtnCopyResult
),
84 rBtnDestPers ( refBtnDestPers
),
85 rLbCopyPos ( refLbCopyArea
),
86 rEdCopyPos ( refEdCopyArea
),
87 rRbCopyPos ( refRbCopyArea
),
88 rFtDbAreaLabel ( refFtDbAreaLabel
),
89 rFtDbArea ( refFtDbArea
),
90 rFlOptions ( refFlOptions
),
91 rStrNoName ( refStrNoName
),
92 rStrUndefined ( refStrUndefined
),
93 rQueryData ( refQueryData
)
99 //----------------------------------------------------------------------------
101 ScFilterOptionsMgr::~ScFilterOptionsMgr()
103 USHORT nEntries
= rLbCopyPos
.GetEntryCount();
106 for ( i
=2; i
<nEntries
; i
++ )
107 delete (String
*)rLbCopyPos
.GetEntryData( i
);
111 //----------------------------------------------------------------------------
113 void ScFilterOptionsMgr::Init()
115 DBG_ASSERT( pViewData
&& pDoc
, "Init failed :-/" );
117 rLbCopyPos
.SetSelectHdl ( LINK( this, ScFilterOptionsMgr
, LbPosSelHdl
) );
118 rEdCopyPos
.SetModifyHdl ( LINK( this, ScFilterOptionsMgr
, EdPosModifyHdl
) );
119 rBtnCopyResult
.SetClickHdl( LINK( this, ScFilterOptionsMgr
, BtnCopyResultHdl
) );
121 rBtnMore
.AddWindow( &rBtnCase
);
122 rBtnMore
.AddWindow( &rBtnRegExp
);
123 rBtnMore
.AddWindow( &rBtnHeader
);
124 rBtnMore
.AddWindow( &rBtnUnique
);
125 rBtnMore
.AddWindow( &rBtnCopyResult
);
126 rBtnMore
.AddWindow( &rBtnDestPers
);
127 rBtnMore
.AddWindow( &rLbCopyPos
);
128 rBtnMore
.AddWindow( &rEdCopyPos
);
129 rBtnMore
.AddWindow( &rRbCopyPos
);
130 rBtnMore
.AddWindow( &rFtDbAreaLabel
);
131 rBtnMore
.AddWindow( &rFtDbArea
);
132 rBtnMore
.AddWindow( &rFlOptions
);
134 rBtnCase
.Check( rQueryData
.bCaseSens
);
135 rBtnHeader
.Check( rQueryData
.bHasHeader
);
136 rBtnRegExp
.Check( rQueryData
.bRegExp
);
137 rBtnUnique
.Check( !rQueryData
.bDuplicate
);
139 if ( pViewData
&& pDoc
)
142 ScRange
theCurArea ( ScAddress( rQueryData
.nCol1
,
144 pViewData
->GetTabNo() ),
145 ScAddress( rQueryData
.nCol2
,
147 pViewData
->GetTabNo() ) );
148 ScDBCollection
* pDBColl
= pDoc
->GetDBCollection();
150 String theDbName
= rStrNoName
;
151 const formula::FormulaGrammar::AddressConvention eConv
= pDoc
->GetAddressConvention();
153 theCurArea
.Format( theAreaStr
, SCR_ABS_3D
, pDoc
, eConv
);
155 // Zielbereichsliste fuellen
158 rLbCopyPos
.InsertEntry( rStrUndefined
, 0 );
160 ScAreaNameIterator
aIter( pDoc
);
164 while ( aIter
.Next( aName
, aRange
) )
166 USHORT nInsert
= rLbCopyPos
.InsertEntry( aName
);
168 aRange
.aStart
.Format( aRefStr
, SCA_ABS_3D
, pDoc
, eConv
);
169 rLbCopyPos
.SetEntryData( nInsert
, new String( aRefStr
) );
172 rBtnDestPers
.Check( TRUE
); // beim Aufruf immer an
173 rLbCopyPos
.SelectEntryPos( 0 );
174 rEdCopyPos
.SetText( EMPTY_STRING
);
177 * Ueberpruefen, ob es sich bei dem uebergebenen
178 * Bereich um einen Datenbankbereich handelt:
181 theDbArea
= theAreaStr
;
185 ScAddress
& rStart
= theCurArea
.aStart
;
186 ScAddress
& rEnd
= theCurArea
.aEnd
;
187 ScDBData
* pDBData
= pDBColl
->GetDBAtArea( rStart
.Tab(),
188 rStart
.Col(), rStart
.Row(),
189 rEnd
.Col(), rEnd
.Row() );
192 rBtnHeader
.Check( pDBData
->HasHeader() );
193 pDBData
->GetName( theDbName
);
195 if ( theDbName
!= rStrNoName
)
197 rBtnHeader
.Disable();
202 theDbArea
.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
203 theDbArea
+= theDbName
;
205 rFtDbArea
.SetText( theDbArea
);
207 //------------------------------------------------------
210 if ( !rQueryData
.bInplace
)
214 ScAddress( rQueryData
.nDestCol
,
217 ).Format( aString
, SCA_ABS_3D
, pDoc
, eConv
);
219 rBtnCopyResult
.Check( TRUE
);
220 rEdCopyPos
.SetText( aString
);
221 EdPosModifyHdl( &rEdCopyPos
);
225 rBtnDestPers
.Enable();
229 rBtnCopyResult
.Check( FALSE
);
230 rEdCopyPos
.SetText( EMPTY_STRING
);
231 rLbCopyPos
.Disable();
232 rEdCopyPos
.Disable();
233 rRbCopyPos
.Disable();
234 rBtnDestPers
.Disable();
238 rEdCopyPos
.SetText( EMPTY_STRING
);
242 //----------------------------------------------------------------------------
244 BOOL
ScFilterOptionsMgr::VerifyPosStr( const String
& rPosStr
) const
246 String
aPosStr( rPosStr
);
247 xub_StrLen nColonPos
= aPosStr
.Search( ':' );
249 if ( STRING_NOTFOUND
!= nColonPos
)
250 aPosStr
.Erase( nColonPos
);
252 USHORT nResult
= ScAddress().Parse( aPosStr
, pDoc
, pDoc
->GetAddressConvention() );
254 return ( SCA_VALID
== (nResult
& SCA_VALID
) );
258 //----------------------------------------------------------------------------
261 //----------------------------------------------------------------------------
263 IMPL_LINK( ScFilterOptionsMgr
, LbPosSelHdl
, ListBox
*, pLb
)
265 if ( pLb
== &rLbCopyPos
)
268 USHORT nSelPos
= rLbCopyPos
.GetSelectEntryPos();
271 aString
= *(String
*)rLbCopyPos
.GetEntryData( nSelPos
);
273 rEdCopyPos
.SetText( aString
);
280 //----------------------------------------------------------------------------
282 IMPL_LINK( ScFilterOptionsMgr
, EdPosModifyHdl
, Edit
*, pEd
)
284 if ( pEd
== &rEdCopyPos
)
286 String theCurPosStr
= pEd
->GetText();
287 USHORT nResult
= ScAddress().Parse( theCurPosStr
, pDoc
, pDoc
->GetAddressConvention() );
289 if ( SCA_VALID
== (nResult
& SCA_VALID
) )
294 USHORT nCount
= rLbCopyPos
.GetEntryCount();
296 for ( i
=2; i
<nCount
&& !bFound
; i
++ )
298 pStr
= (String
*)rLbCopyPos
.GetEntryData( i
);
299 bFound
= (theCurPosStr
== *pStr
);
303 rLbCopyPos
.SelectEntryPos( --i
);
305 rLbCopyPos
.SelectEntryPos( 0 );
308 rLbCopyPos
.SelectEntryPos( 0 );
315 //----------------------------------------------------------------------------
317 IMPL_LINK( ScFilterOptionsMgr
, BtnCopyResultHdl
, CheckBox
*, pBox
)
319 if ( pBox
== &rBtnCopyResult
)
321 if ( pBox
->IsChecked() )
323 rBtnDestPers
.Enable();
327 rEdCopyPos
.GrabFocus();
331 rBtnDestPers
.Disable();
332 rLbCopyPos
.Disable();
333 rEdCopyPos
.Disable();
334 rRbCopyPos
.Disable();