1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 // System - Includes --------------------------------------------------------- 32 33 34 35 // INCLUDE ------------------------------------------------------------------- 36 37 #include <vcl/morebtn.hxx> 38 #include <svtools/stdctrl.hxx> 39 40 #include "anyrefdg.hxx" 41 #include "rangeutl.hxx" 42 #include "dbcolect.hxx" 43 #include "viewdata.hxx" 44 #include "document.hxx" 45 #include "queryparam.hxx" 46 47 #define _FOPTMGR_CXX 48 #include "foptmgr.hxx" 49 #undef _FOPTMGR_CXX 50 51 //---------------------------------------------------------------------------- 52 53 ScFilterOptionsMgr::ScFilterOptionsMgr( 54 Dialog* ptrDlg, 55 ScViewData* ptrViewData, 56 const ScQueryParam& refQueryData, 57 MoreButton& refBtnMore, 58 CheckBox& refBtnCase, 59 CheckBox& refBtnRegExp, 60 CheckBox& refBtnHeader, 61 CheckBox& refBtnUnique, 62 CheckBox& refBtnCopyResult, 63 CheckBox& refBtnDestPers, 64 ListBox& refLbCopyArea, 65 Edit& refEdCopyArea, 66 formula::RefButton& refRbCopyArea, 67 FixedText& refFtDbAreaLabel, 68 FixedInfo& refFtDbArea, 69 FixedLine& refFlOptions, 70 const String& refStrNoName, 71 const String& refStrUndefined ) 72 73 : pDlg ( ptrDlg ), 74 pViewData ( ptrViewData ), 75 pDoc ( ptrViewData ? ptrViewData->GetDocument() : NULL ), 76 rBtnMore ( refBtnMore ), 77 rBtnCase ( refBtnCase ), 78 rBtnRegExp ( refBtnRegExp ), 79 rBtnHeader ( refBtnHeader ), 80 rBtnUnique ( refBtnUnique ), 81 rBtnCopyResult ( refBtnCopyResult ), 82 rBtnDestPers ( refBtnDestPers ), 83 rLbCopyPos ( refLbCopyArea ), 84 rEdCopyPos ( refEdCopyArea ), 85 rRbCopyPos ( refRbCopyArea ), 86 rFtDbAreaLabel ( refFtDbAreaLabel ), 87 rFtDbArea ( refFtDbArea ), 88 rFlOptions ( refFlOptions ), 89 rStrNoName ( refStrNoName ), 90 rStrUndefined ( refStrUndefined ), 91 rQueryData ( refQueryData ) 92 { 93 Init(); 94 } 95 96 97 //---------------------------------------------------------------------------- 98 99 ScFilterOptionsMgr::~ScFilterOptionsMgr() 100 { 101 sal_uInt16 nEntries = rLbCopyPos.GetEntryCount(); 102 sal_uInt16 i; 103 104 for ( i=2; i<nEntries; i++ ) 105 delete (String*)rLbCopyPos.GetEntryData( i ); 106 } 107 108 109 //---------------------------------------------------------------------------- 110 111 void ScFilterOptionsMgr::Init() 112 { 113 DBG_ASSERT( pViewData && pDoc, "Init failed :-/" ); 114 115 rLbCopyPos.SetSelectHdl ( LINK( this, ScFilterOptionsMgr, LbPosSelHdl ) ); 116 rEdCopyPos.SetModifyHdl ( LINK( this, ScFilterOptionsMgr, EdPosModifyHdl ) ); 117 rBtnCopyResult.SetClickHdl( LINK( this, ScFilterOptionsMgr, BtnCopyResultHdl ) ); 118 119 rBtnMore.AddWindow( &rBtnCase ); 120 rBtnMore.AddWindow( &rBtnRegExp ); 121 rBtnMore.AddWindow( &rBtnHeader ); 122 rBtnMore.AddWindow( &rBtnUnique ); 123 rBtnMore.AddWindow( &rBtnCopyResult ); 124 rBtnMore.AddWindow( &rBtnDestPers ); 125 rBtnMore.AddWindow( &rLbCopyPos ); 126 rBtnMore.AddWindow( &rEdCopyPos ); 127 rBtnMore.AddWindow( &rRbCopyPos ); 128 rBtnMore.AddWindow( &rFtDbAreaLabel ); 129 rBtnMore.AddWindow( &rFtDbArea ); 130 rBtnMore.AddWindow( &rFlOptions ); 131 132 rBtnCase .Check( rQueryData.bCaseSens ); 133 rBtnHeader .Check( rQueryData.bHasHeader ); 134 rBtnRegExp .Check( rQueryData.bRegExp ); 135 rBtnUnique .Check( !rQueryData.bDuplicate ); 136 137 if ( pViewData && pDoc ) 138 { 139 String theAreaStr; 140 ScRange theCurArea ( ScAddress( rQueryData.nCol1, 141 rQueryData.nRow1, 142 pViewData->GetTabNo() ), 143 ScAddress( rQueryData.nCol2, 144 rQueryData.nRow2, 145 pViewData->GetTabNo() ) ); 146 ScDBCollection* pDBColl = pDoc->GetDBCollection(); 147 String theDbArea; 148 String theDbName = rStrNoName; 149 const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention(); 150 151 theCurArea.Format( theAreaStr, SCR_ABS_3D, pDoc, eConv ); 152 153 // Zielbereichsliste fuellen 154 155 rLbCopyPos.Clear(); 156 rLbCopyPos.InsertEntry( rStrUndefined, 0 ); 157 158 ScAreaNameIterator aIter( pDoc ); 159 String aName; 160 ScRange aRange; 161 String aRefStr; 162 while ( aIter.Next( aName, aRange ) ) 163 { 164 sal_uInt16 nInsert = rLbCopyPos.InsertEntry( aName ); 165 166 aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv ); 167 rLbCopyPos.SetEntryData( nInsert, new String( aRefStr ) ); 168 } 169 170 rBtnDestPers.Check( sal_True ); // beim Aufruf immer an 171 rLbCopyPos.SelectEntryPos( 0 ); 172 rEdCopyPos.SetText( EMPTY_STRING ); 173 174 /* 175 * Ueberpruefen, ob es sich bei dem uebergebenen 176 * Bereich um einen Datenbankbereich handelt: 177 */ 178 179 theDbArea = theAreaStr; 180 181 if ( pDBColl ) 182 { 183 ScAddress& rStart = theCurArea.aStart; 184 ScAddress& rEnd = theCurArea.aEnd; 185 ScDBData* pDBData = pDBColl->GetDBAtArea( rStart.Tab(), 186 rStart.Col(), rStart.Row(), 187 rEnd.Col(), rEnd.Row() ); 188 if ( pDBData ) 189 { 190 rBtnHeader.Check( pDBData->HasHeader() ); 191 pDBData->GetName( theDbName ); 192 193 if ( theDbName != rStrNoName ) 194 { 195 rBtnHeader.Disable(); 196 } 197 } 198 } 199 200 theDbArea.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" (")); 201 theDbArea += theDbName; 202 theDbArea += ')'; 203 rFtDbArea.SetText( theDbArea ); 204 205 //------------------------------------------------------ 206 // Kopierposition: 207 208 if ( !rQueryData.bInplace ) 209 { 210 String aString; 211 212 ScAddress( rQueryData.nDestCol, 213 rQueryData.nDestRow, 214 rQueryData.nDestTab 215 ).Format( aString, SCA_ABS_3D, pDoc, eConv ); 216 217 rBtnCopyResult.Check( sal_True ); 218 rEdCopyPos.SetText( aString ); 219 EdPosModifyHdl( &rEdCopyPos ); 220 rLbCopyPos.Enable(); 221 rEdCopyPos.Enable(); 222 rRbCopyPos.Enable(); 223 rBtnDestPers.Enable(); 224 } 225 else 226 { 227 rBtnCopyResult.Check( sal_False ); 228 rEdCopyPos.SetText( EMPTY_STRING ); 229 rLbCopyPos.Disable(); 230 rEdCopyPos.Disable(); 231 rRbCopyPos.Disable(); 232 rBtnDestPers.Disable(); 233 } 234 } 235 else 236 rEdCopyPos.SetText( EMPTY_STRING ); 237 } 238 239 240 //---------------------------------------------------------------------------- 241 242 sal_Bool ScFilterOptionsMgr::VerifyPosStr( const String& rPosStr ) const 243 { 244 String aPosStr( rPosStr ); 245 xub_StrLen nColonPos = aPosStr.Search( ':' ); 246 247 if ( STRING_NOTFOUND != nColonPos ) 248 aPosStr.Erase( nColonPos ); 249 250 sal_uInt16 nResult = ScAddress().Parse( aPosStr, pDoc, pDoc->GetAddressConvention() ); 251 252 return ( SCA_VALID == (nResult & SCA_VALID) ); 253 } 254 255 256 //---------------------------------------------------------------------------- 257 // Handler: 258 259 //---------------------------------------------------------------------------- 260 261 IMPL_LINK( ScFilterOptionsMgr, LbPosSelHdl, ListBox*, pLb ) 262 { 263 if ( pLb == &rLbCopyPos ) 264 { 265 String aString; 266 sal_uInt16 nSelPos = rLbCopyPos.GetSelectEntryPos(); 267 268 if ( nSelPos > 0 ) 269 aString = *(String*)rLbCopyPos.GetEntryData( nSelPos ); 270 271 rEdCopyPos.SetText( aString ); 272 } 273 274 return 0; 275 } 276 277 278 //---------------------------------------------------------------------------- 279 280 IMPL_LINK( ScFilterOptionsMgr, EdPosModifyHdl, Edit*, pEd ) 281 { 282 if ( pEd == &rEdCopyPos ) 283 { 284 String theCurPosStr = pEd->GetText(); 285 sal_uInt16 nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() ); 286 287 if ( SCA_VALID == (nResult & SCA_VALID) ) 288 { 289 String* pStr = NULL; 290 sal_Bool bFound = sal_False; 291 sal_uInt16 i = 0; 292 sal_uInt16 nCount = rLbCopyPos.GetEntryCount(); 293 294 for ( i=2; i<nCount && !bFound; i++ ) 295 { 296 pStr = (String*)rLbCopyPos.GetEntryData( i ); 297 bFound = (theCurPosStr == *pStr); 298 } 299 300 if ( bFound ) 301 rLbCopyPos.SelectEntryPos( --i ); 302 else 303 rLbCopyPos.SelectEntryPos( 0 ); 304 } 305 else 306 rLbCopyPos.SelectEntryPos( 0 ); 307 } 308 309 return 0; 310 } 311 312 313 //---------------------------------------------------------------------------- 314 315 IMPL_LINK( ScFilterOptionsMgr, BtnCopyResultHdl, CheckBox*, pBox ) 316 { 317 if ( pBox == &rBtnCopyResult ) 318 { 319 if ( pBox->IsChecked() ) 320 { 321 rBtnDestPers.Enable(); 322 rLbCopyPos.Enable(); 323 rEdCopyPos.Enable(); 324 rRbCopyPos.Enable(); 325 rEdCopyPos.GrabFocus(); 326 } 327 else 328 { 329 rBtnDestPers.Disable(); 330 rLbCopyPos.Disable(); 331 rEdCopyPos.Disable(); 332 rRbCopyPos.Disable(); 333 } 334 } 335 336 return 0; 337 } 338