update dev300-m57
[ooovba.git] / sc / source / ui / dbgui / foptmgr.cxx
blobee5f03954bdd2258273ef7fda28e3f7be024dd3f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: foptmgr.cxx,v $
10 * $Revision: 1.8 $
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"
49 #define _FOPTMGR_CXX
50 #include "foptmgr.hxx"
51 #undef _FOPTMGR_CXX
53 //----------------------------------------------------------------------------
55 ScFilterOptionsMgr::ScFilterOptionsMgr(
56 Dialog* ptrDlg,
57 ScViewData* ptrViewData,
58 const ScQueryParam& refQueryData,
59 MoreButton& refBtnMore,
60 CheckBox& refBtnCase,
61 CheckBox& refBtnRegExp,
62 CheckBox& refBtnHeader,
63 CheckBox& refBtnUnique,
64 CheckBox& refBtnCopyResult,
65 CheckBox& refBtnDestPers,
66 ListBox& refLbCopyArea,
67 Edit& refEdCopyArea,
68 formula::RefButton& refRbCopyArea,
69 FixedText& refFtDbAreaLabel,
70 FixedInfo& refFtDbArea,
71 FixedLine& refFlOptions,
72 const String& refStrNoName,
73 const String& refStrUndefined )
75 : pDlg ( ptrDlg ),
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 )
95 Init();
99 //----------------------------------------------------------------------------
101 ScFilterOptionsMgr::~ScFilterOptionsMgr()
103 USHORT nEntries = rLbCopyPos.GetEntryCount();
104 USHORT i;
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 )
141 String theAreaStr;
142 ScRange theCurArea ( ScAddress( rQueryData.nCol1,
143 rQueryData.nRow1,
144 pViewData->GetTabNo() ),
145 ScAddress( rQueryData.nCol2,
146 rQueryData.nRow2,
147 pViewData->GetTabNo() ) );
148 ScDBCollection* pDBColl = pDoc->GetDBCollection();
149 String theDbArea;
150 String theDbName = rStrNoName;
151 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
153 theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, eConv );
155 // Zielbereichsliste fuellen
157 rLbCopyPos.Clear();
158 rLbCopyPos.InsertEntry( rStrUndefined, 0 );
160 ScAreaNameIterator aIter( pDoc );
161 String aName;
162 ScRange aRange;
163 String aRefStr;
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;
183 if ( pDBColl )
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() );
190 if ( pDBData )
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;
204 theDbArea += ')';
205 rFtDbArea.SetText( theDbArea );
207 //------------------------------------------------------
208 // Kopierposition:
210 if ( !rQueryData.bInplace )
212 String aString;
214 ScAddress( rQueryData.nDestCol,
215 rQueryData.nDestRow,
216 rQueryData.nDestTab
217 ).Format( aString, SCA_ABS_3D, pDoc, eConv );
219 rBtnCopyResult.Check( TRUE );
220 rEdCopyPos.SetText( aString );
221 EdPosModifyHdl( &rEdCopyPos );
222 rLbCopyPos.Enable();
223 rEdCopyPos.Enable();
224 rRbCopyPos.Enable();
225 rBtnDestPers.Enable();
227 else
229 rBtnCopyResult.Check( FALSE );
230 rEdCopyPos.SetText( EMPTY_STRING );
231 rLbCopyPos.Disable();
232 rEdCopyPos.Disable();
233 rRbCopyPos.Disable();
234 rBtnDestPers.Disable();
237 else
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 //----------------------------------------------------------------------------
259 // Handler:
261 //----------------------------------------------------------------------------
263 IMPL_LINK( ScFilterOptionsMgr, LbPosSelHdl, ListBox*, pLb )
265 if ( pLb == &rLbCopyPos )
267 String aString;
268 USHORT nSelPos = rLbCopyPos.GetSelectEntryPos();
270 if ( nSelPos > 0 )
271 aString = *(String*)rLbCopyPos.GetEntryData( nSelPos );
273 rEdCopyPos.SetText( aString );
276 return 0;
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) )
291 String* pStr = NULL;
292 BOOL bFound = FALSE;
293 USHORT i = 0;
294 USHORT nCount = rLbCopyPos.GetEntryCount();
296 for ( i=2; i<nCount && !bFound; i++ )
298 pStr = (String*)rLbCopyPos.GetEntryData( i );
299 bFound = (theCurPosStr == *pStr);
302 if ( bFound )
303 rLbCopyPos.SelectEntryPos( --i );
304 else
305 rLbCopyPos.SelectEntryPos( 0 );
307 else
308 rLbCopyPos.SelectEntryPos( 0 );
311 return 0;
315 //----------------------------------------------------------------------------
317 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox )
319 if ( pBox == &rBtnCopyResult )
321 if ( pBox->IsChecked() )
323 rBtnDestPers.Enable();
324 rLbCopyPos.Enable();
325 rEdCopyPos.Enable();
326 rRbCopyPos.Enable();
327 rEdCopyPos.GrabFocus();
329 else
331 rBtnDestPers.Disable();
332 rLbCopyPos.Disable();
333 rEdCopyPos.Disable();
334 rRbCopyPos.Disable();
338 return 0;