merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / dbgui / foptmgr.cxx
bloba425836e72901186fceb9f759e63610a7f14507c
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"
48 #include "queryparam.hxx"
50 #define _FOPTMGR_CXX
51 #include "foptmgr.hxx"
52 #undef _FOPTMGR_CXX
54 //----------------------------------------------------------------------------
56 ScFilterOptionsMgr::ScFilterOptionsMgr(
57 Dialog* ptrDlg,
58 ScViewData* ptrViewData,
59 const ScQueryParam& refQueryData,
60 MoreButton& refBtnMore,
61 CheckBox& refBtnCase,
62 CheckBox& refBtnRegExp,
63 CheckBox& refBtnHeader,
64 CheckBox& refBtnUnique,
65 CheckBox& refBtnCopyResult,
66 CheckBox& refBtnDestPers,
67 ListBox& refLbCopyArea,
68 Edit& refEdCopyArea,
69 formula::RefButton& refRbCopyArea,
70 FixedText& refFtDbAreaLabel,
71 FixedInfo& refFtDbArea,
72 FixedLine& refFlOptions,
73 const String& refStrNoName,
74 const String& refStrUndefined )
76 : pDlg ( ptrDlg ),
77 pViewData ( ptrViewData ),
78 pDoc ( ptrViewData ? ptrViewData->GetDocument() : NULL ),
79 rBtnMore ( refBtnMore ),
80 rBtnCase ( refBtnCase ),
81 rBtnRegExp ( refBtnRegExp ),
82 rBtnHeader ( refBtnHeader ),
83 rBtnUnique ( refBtnUnique ),
84 rBtnCopyResult ( refBtnCopyResult ),
85 rBtnDestPers ( refBtnDestPers ),
86 rLbCopyPos ( refLbCopyArea ),
87 rEdCopyPos ( refEdCopyArea ),
88 rRbCopyPos ( refRbCopyArea ),
89 rFtDbAreaLabel ( refFtDbAreaLabel ),
90 rFtDbArea ( refFtDbArea ),
91 rFlOptions ( refFlOptions ),
92 rStrNoName ( refStrNoName ),
93 rStrUndefined ( refStrUndefined ),
94 rQueryData ( refQueryData )
96 Init();
100 //----------------------------------------------------------------------------
102 ScFilterOptionsMgr::~ScFilterOptionsMgr()
104 USHORT nEntries = rLbCopyPos.GetEntryCount();
105 USHORT i;
107 for ( i=2; i<nEntries; i++ )
108 delete (String*)rLbCopyPos.GetEntryData( i );
112 //----------------------------------------------------------------------------
114 void ScFilterOptionsMgr::Init()
116 DBG_ASSERT( pViewData && pDoc, "Init failed :-/" );
118 rLbCopyPos.SetSelectHdl ( LINK( this, ScFilterOptionsMgr, LbPosSelHdl ) );
119 rEdCopyPos.SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdPosModifyHdl ) );
120 rBtnCopyResult.SetClickHdl( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) );
122 rBtnMore.AddWindow( &rBtnCase );
123 rBtnMore.AddWindow( &rBtnRegExp );
124 rBtnMore.AddWindow( &rBtnHeader );
125 rBtnMore.AddWindow( &rBtnUnique );
126 rBtnMore.AddWindow( &rBtnCopyResult );
127 rBtnMore.AddWindow( &rBtnDestPers );
128 rBtnMore.AddWindow( &rLbCopyPos );
129 rBtnMore.AddWindow( &rEdCopyPos );
130 rBtnMore.AddWindow( &rRbCopyPos );
131 rBtnMore.AddWindow( &rFtDbAreaLabel );
132 rBtnMore.AddWindow( &rFtDbArea );
133 rBtnMore.AddWindow( &rFlOptions );
135 rBtnCase .Check( rQueryData.bCaseSens );
136 rBtnHeader .Check( rQueryData.bHasHeader );
137 rBtnRegExp .Check( rQueryData.bRegExp );
138 rBtnUnique .Check( !rQueryData.bDuplicate );
140 if ( pViewData && pDoc )
142 String theAreaStr;
143 ScRange theCurArea ( ScAddress( rQueryData.nCol1,
144 rQueryData.nRow1,
145 pViewData->GetTabNo() ),
146 ScAddress( rQueryData.nCol2,
147 rQueryData.nRow2,
148 pViewData->GetTabNo() ) );
149 ScDBCollection* pDBColl = pDoc->GetDBCollection();
150 String theDbArea;
151 String theDbName = rStrNoName;
152 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
154 theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, eConv );
156 // Zielbereichsliste fuellen
158 rLbCopyPos.Clear();
159 rLbCopyPos.InsertEntry( rStrUndefined, 0 );
161 ScAreaNameIterator aIter( pDoc );
162 String aName;
163 ScRange aRange;
164 String aRefStr;
165 while ( aIter.Next( aName, aRange ) )
167 USHORT nInsert = rLbCopyPos.InsertEntry( aName );
169 aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv );
170 rLbCopyPos.SetEntryData( nInsert, new String( aRefStr ) );
173 rBtnDestPers.Check( TRUE ); // beim Aufruf immer an
174 rLbCopyPos.SelectEntryPos( 0 );
175 rEdCopyPos.SetText( EMPTY_STRING );
178 * Ueberpruefen, ob es sich bei dem uebergebenen
179 * Bereich um einen Datenbankbereich handelt:
182 theDbArea = theAreaStr;
184 if ( pDBColl )
186 ScAddress& rStart = theCurArea.aStart;
187 ScAddress& rEnd = theCurArea.aEnd;
188 ScDBData* pDBData = pDBColl->GetDBAtArea( rStart.Tab(),
189 rStart.Col(), rStart.Row(),
190 rEnd.Col(), rEnd.Row() );
191 if ( pDBData )
193 rBtnHeader.Check( pDBData->HasHeader() );
194 pDBData->GetName( theDbName );
196 if ( theDbName != rStrNoName )
198 rBtnHeader.Disable();
203 theDbArea.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
204 theDbArea += theDbName;
205 theDbArea += ')';
206 rFtDbArea.SetText( theDbArea );
208 //------------------------------------------------------
209 // Kopierposition:
211 if ( !rQueryData.bInplace )
213 String aString;
215 ScAddress( rQueryData.nDestCol,
216 rQueryData.nDestRow,
217 rQueryData.nDestTab
218 ).Format( aString, SCA_ABS_3D, pDoc, eConv );
220 rBtnCopyResult.Check( TRUE );
221 rEdCopyPos.SetText( aString );
222 EdPosModifyHdl( &rEdCopyPos );
223 rLbCopyPos.Enable();
224 rEdCopyPos.Enable();
225 rRbCopyPos.Enable();
226 rBtnDestPers.Enable();
228 else
230 rBtnCopyResult.Check( FALSE );
231 rEdCopyPos.SetText( EMPTY_STRING );
232 rLbCopyPos.Disable();
233 rEdCopyPos.Disable();
234 rRbCopyPos.Disable();
235 rBtnDestPers.Disable();
238 else
239 rEdCopyPos.SetText( EMPTY_STRING );
243 //----------------------------------------------------------------------------
245 BOOL ScFilterOptionsMgr::VerifyPosStr( const String& rPosStr ) const
247 String aPosStr( rPosStr );
248 xub_StrLen nColonPos = aPosStr.Search( ':' );
250 if ( STRING_NOTFOUND != nColonPos )
251 aPosStr.Erase( nColonPos );
253 USHORT nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() );
255 return ( SCA_VALID == (nResult & SCA_VALID) );
259 //----------------------------------------------------------------------------
260 // Handler:
262 //----------------------------------------------------------------------------
264 IMPL_LINK( ScFilterOptionsMgr, LbPosSelHdl, ListBox*, pLb )
266 if ( pLb == &rLbCopyPos )
268 String aString;
269 USHORT nSelPos = rLbCopyPos.GetSelectEntryPos();
271 if ( nSelPos > 0 )
272 aString = *(String*)rLbCopyPos.GetEntryData( nSelPos );
274 rEdCopyPos.SetText( aString );
277 return 0;
281 //----------------------------------------------------------------------------
283 IMPL_LINK( ScFilterOptionsMgr, EdPosModifyHdl, Edit*, pEd )
285 if ( pEd == &rEdCopyPos )
287 String theCurPosStr = pEd->GetText();
288 USHORT nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
290 if ( SCA_VALID == (nResult & SCA_VALID) )
292 String* pStr = NULL;
293 BOOL bFound = FALSE;
294 USHORT i = 0;
295 USHORT nCount = rLbCopyPos.GetEntryCount();
297 for ( i=2; i<nCount && !bFound; i++ )
299 pStr = (String*)rLbCopyPos.GetEntryData( i );
300 bFound = (theCurPosStr == *pStr);
303 if ( bFound )
304 rLbCopyPos.SelectEntryPos( --i );
305 else
306 rLbCopyPos.SelectEntryPos( 0 );
308 else
309 rLbCopyPos.SelectEntryPos( 0 );
312 return 0;
316 //----------------------------------------------------------------------------
318 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox )
320 if ( pBox == &rBtnCopyResult )
322 if ( pBox->IsChecked() )
324 rBtnDestPers.Enable();
325 rLbCopyPos.Enable();
326 rEdCopyPos.Enable();
327 rRbCopyPos.Enable();
328 rEdCopyPos.GrabFocus();
330 else
332 rBtnDestPers.Disable();
333 rLbCopyPos.Disable();
334 rEdCopyPos.Disable();
335 rRbCopyPos.Disable();
339 return 0;