1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sc.hxx" 26 27 28 29 //------------------------------------------------------------------ 30 31 // INCLUDE --------------------------------------------------------------- 32 33 #include "scitems.hxx" 34 #include <sfx2/viewfrm.hxx> 35 #include <sfx2/app.hxx> 36 #include <sfx2/request.hxx> 37 #include <svl/aeitem.hxx> 38 #include <basic/sbxcore.hxx> 39 #include <svl/whiter.hxx> 40 #include <svl/zforlist.hxx> 41 #include <vcl/msgbox.hxx> 42 #include <svl/stritem.hxx> 43 #include <svl/visitem.hxx> 44 #include <unotools/moduleoptions.hxx> 45 46 #include <com/sun/star/frame/FrameSearchFlag.hpp> 47 #include <com/sun/star/sdbc/XResultSet.hpp> 48 49 #include "cellsh.hxx" 50 #include "tabvwsh.hxx" 51 #include "sc.hrc" 52 #include "globstr.hrc" 53 #include "global.hxx" 54 #include "scmod.hxx" 55 #include "docsh.hxx" 56 #include "document.hxx" 57 #include "uiitems.hxx" 58 #include "dbfunc.hxx" 59 #include "dbdocfun.hxx" 60 //CHINA001 #include "lbseldlg.hxx" 61 //CHINA001 #include "sortdlg.hxx" 62 #include "filtdlg.hxx" 63 #include "dbnamdlg.hxx" 64 //CHINA001 #include "subtdlg.hxx" 65 #include "reffact.hxx" 66 #include "pvlaydlg.hxx" 67 #include "validat.hxx" 68 #include "scresid.hxx" 69 //CHINA001 #include "validate.hxx" 70 #include "pivot.hxx" 71 #include "dpobject.hxx" 72 //CHINA001 #include "dapitype.hxx" 73 //CHINA001 #include "dapidata.hxx" 74 #include "dpsdbtab.hxx" // ScImportSourceDesc 75 #include "dpshttab.hxx" // ScSheetSourceDesc 76 77 #include "validate.hrc" //CHINA001 add for ScValidationDlg 78 #include "scui_def.hxx" //CHINA001 79 #include "scabstdlg.hxx" //CHINA001 80 #include "impex.hxx" 81 #include "asciiopt.hxx" 82 using namespace com::sun::star; 83 84 //#include "strindlg.hxx" //! Test !!!!! 85 86 //static ScArea aPivotSource; //! wohin? (ueber den Dialog retten) 87 88 89 #define IS_AVAILABLE(WhichId,ppItem) \ 90 (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET) 91 92 //------------------------------------------------------------------ 93 94 bool lcl_GetTextToColumnsRange( const ScViewData* pData, ScRange& rRange ) 95 { 96 DBG_ASSERT( pData, "lcl_GetTextToColumnsRange: pData is null!" ); 97 98 bool bRet = false; 99 const ScMarkData& rMark = pData->GetMarkData(); 100 101 if ( rMark.IsMarked() ) 102 { 103 if ( !rMark.IsMultiMarked() ) 104 { 105 rMark.GetMarkArea( rRange ); 106 if ( rRange.aStart.Col() == rRange.aEnd.Col() ) 107 { 108 bRet = true; 109 } 110 } 111 } 112 else 113 { 114 const SCCOL nCol = pData->GetCurX(); 115 const SCROW nRow = pData->GetCurY(); 116 const SCTAB nTab = pData->GetTabNo(); 117 rRange = ScRange( nCol, nRow, nTab, nCol, nRow, nTab ); 118 bRet = true; 119 } 120 121 const ScDocument* pDoc = pData->GetDocument(); 122 DBG_ASSERT( pDoc, "lcl_GetTextToColumnsRange: pDoc is null!" ); 123 124 if ( bRet && pDoc->IsBlockEmpty( rRange.aStart.Tab(), rRange.aStart.Col(), 125 rRange.aStart.Row(), rRange.aEnd.Col(), 126 rRange.aEnd.Row() ) ) 127 { 128 bRet = false; 129 } 130 131 return bRet; 132 } 133 134 sal_Bool lcl_GetSortParam( const ScViewData* pData, ScSortParam& rSortParam ) 135 { 136 ScTabViewShell* pTabViewShell = pData->GetViewShell(); 137 ScDBData* pDBData = pTabViewShell->GetDBData(); 138 ScDocument* pDoc = pData->GetDocument(); 139 SCTAB nTab = pData->GetTabNo(); 140 ScDirection eFillDir = DIR_TOP; 141 sal_Bool bSort = sal_True; 142 ScRange aExternalRange; 143 144 if( rSortParam.nCol1 != rSortParam.nCol2 ) 145 eFillDir = DIR_LEFT; 146 if( rSortParam.nRow1 != rSortParam.nRow2 ) 147 eFillDir = DIR_TOP; 148 149 SCSIZE nCount = pDoc->GetEmptyLinesInBlock( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab, eFillDir ); 150 151 if( rSortParam.nRow2 == MAXROW ) 152 aExternalRange = ScRange( rSortParam.nCol1,sal::static_int_cast<SCROW>( nCount ), nTab ); 153 else 154 aExternalRange = ScRange( pData->GetCurX(), pData->GetCurY(), nTab ); 155 156 SCROW nStartRow = aExternalRange.aStart.Row(); 157 SCCOL nStartCol = aExternalRange.aStart.Col(); 158 SCROW nEndRow = aExternalRange.aEnd.Row(); 159 SCCOL nEndCol = aExternalRange.aEnd.Col(); 160 pDoc->GetDataArea( aExternalRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow, sal_False, false ); 161 aExternalRange.aStart.SetRow( nStartRow ); 162 aExternalRange.aStart.SetCol( nStartCol ); 163 aExternalRange.aEnd.SetRow( nEndRow ); 164 aExternalRange.aEnd.SetCol( nEndCol ); 165 166 if(( rSortParam.nCol1 == rSortParam.nCol2 && aExternalRange.aStart.Col() != aExternalRange.aEnd.Col() ) || 167 ( rSortParam.nRow1 == rSortParam.nRow2 && aExternalRange.aStart.Row() != aExternalRange.aEnd.Row() ) ) 168 { 169 sal_uInt16 nFmt = SCA_VALID; 170 String aExtendStr,aCurrentStr; 171 172 pTabViewShell->AddHighlightRange( aExternalRange,Color( COL_LIGHTBLUE ) ); 173 ScRange rExtendRange( aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), nTab, aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row(), nTab ); 174 rExtendRange.Format( aExtendStr, nFmt, pDoc ); 175 176 ScRange rCurrentRange( rSortParam.nCol1, rSortParam.nRow1, nTab, rSortParam.nCol2, rSortParam.nRow2, nTab ); 177 rCurrentRange.Format( aCurrentStr, nFmt, pDoc ); 178 179 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 180 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 181 182 VclAbstractDialog* pWarningDlg = pFact->CreateScSortWarningDlg( pTabViewShell->GetDialogParent(),aExtendStr,aCurrentStr,RID_SCDLG_SORT_WARNING ); 183 DBG_ASSERT(pWarningDlg, "Dialog create fail!");//CHINA001 184 short bResult = pWarningDlg->Execute(); 185 if( bResult == BTN_EXTEND_RANGE || bResult == BTN_CURRENT_SELECTION ) 186 { 187 if( bResult == BTN_EXTEND_RANGE ) 188 { 189 pTabViewShell->MarkRange( aExternalRange, sal_False ); 190 pDBData->SetArea( nTab, aExternalRange.aStart.Col(), aExternalRange.aStart.Row(), aExternalRange.aEnd.Col(), aExternalRange.aEnd.Row() ); 191 } 192 } 193 else 194 { 195 bSort = sal_False; 196 pData->GetDocShell()->CancelAutoDBRange(); 197 } 198 199 delete pWarningDlg; 200 pTabViewShell->ClearHighlightRanges(); 201 } 202 return bSort; 203 } 204 205 //<!-- Added by PengYunQuan for Validity Cell Range Picker 206 //after end execute from !IsModalInputMode, it is safer to delay deleting 207 namespace 208 { 209 long DelayDeleteAbstractDialog( void *pAbstractDialog, void * /*pArg*/ ) 210 { 211 delete reinterpret_cast<VclAbstractDialog*>( pAbstractDialog ); 212 return 0; 213 } 214 } 215 //--> Added by PengYunQuan for Validity Cell Range Picker 216 217 void ScCellShell::ExecuteDB( SfxRequest& rReq ) 218 { 219 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); 220 sal_uInt16 nSlotId = rReq.GetSlot(); 221 const SfxItemSet* pReqArgs = rReq.GetArgs(); 222 ScModule* pScMod = SC_MOD(); 223 224 pTabViewShell->HideListBox(); // Autofilter-DropDown-Listbox 225 226 if ( GetViewData()->HasEditView( GetViewData()->GetActivePart() ) ) 227 { 228 pScMod->InputEnterHandler(); 229 pTabViewShell->UpdateInputHandler(); 230 } 231 232 switch ( nSlotId ) 233 { 234 case SID_VIEW_DATA_SOURCE_BROWSER: 235 { 236 // check if database beamer is open 237 238 SfxViewFrame* pViewFrame = pTabViewShell->GetViewFrame(); 239 sal_Bool bWasOpen = sal_False; 240 { 241 uno::Reference<frame::XFrame> xFrame = pViewFrame->GetFrame().GetFrameInterface(); 242 uno::Reference<frame::XFrame> xBeamerFrame = xFrame->findFrame( 243 rtl::OUString::createFromAscii("_beamer"), 244 frame::FrameSearchFlag::CHILDREN); 245 if ( xBeamerFrame.is() ) 246 bWasOpen = sal_True; 247 } 248 249 if ( bWasOpen ) 250 { 251 // close database beamer: just forward to SfxViewFrame 252 253 pViewFrame->ExecuteSlot( rReq ); 254 } 255 else 256 { 257 // show database beamer: SfxViewFrame call must be synchronous 258 259 pViewFrame->ExecuteSlot( rReq, (sal_Bool) sal_False ); // sal_False = synchronous 260 261 // select current database in database beamer 262 263 ScImportParam aImportParam; 264 ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD); // don't create if none found 265 if (pDBData) 266 pDBData->GetImportParam( aImportParam ); 267 268 ScDBDocFunc::ShowInBeamer( aImportParam, pTabViewShell->GetViewFrame() ); 269 } 270 rReq.Done(); // needed because it's a toggle slot 271 } 272 break; 273 274 case SID_REIMPORT_DATA: 275 { 276 sal_Bool bOk = sal_False; 277 ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD); 278 if (pDBData) 279 { 280 ScImportParam aImportParam; 281 pDBData->GetImportParam( aImportParam ); 282 if (aImportParam.bImport && !pDBData->HasImportSelection()) 283 { 284 pTabViewShell->ImportData( aImportParam ); 285 pDBData->SetImportParam( aImportParam ); //! Undo ?? 286 bOk = sal_True; 287 } 288 } 289 290 if (!bOk && ! rReq.IsAPI() ) 291 pTabViewShell->ErrorMessage(STR_REIMPORT_EMPTY); 292 293 if( bOk ) 294 rReq.Done(); 295 } 296 break; 297 298 case SID_REFRESH_DBAREA: 299 { 300 ScDBData* pDBData = pTabViewShell->GetDBData(sal_True,SC_DB_OLD); 301 if (pDBData) 302 { 303 // Import wiederholen wie SID_REIMPORT_DATA 304 305 sal_Bool bContinue = sal_True; 306 ScImportParam aImportParam; 307 pDBData->GetImportParam( aImportParam ); 308 if (aImportParam.bImport && !pDBData->HasImportSelection()) 309 { 310 bContinue = pTabViewShell->ImportData( aImportParam ); 311 pDBData->SetImportParam( aImportParam ); //! Undo ?? 312 313 // markieren (Groesse kann sich geaendert haben) 314 ScRange aNewRange; 315 pDBData->GetArea(aNewRange); 316 pTabViewShell->MarkRange(aNewRange); 317 } 318 319 if ( bContinue ) // #41905# Fehler beim Import -> Abbruch 320 { 321 // interne Operationen, wenn welche gespeichert 322 323 if ( pDBData->HasQueryParam() || pDBData->HasSortParam() || 324 pDBData->HasSubTotalParam() ) 325 pTabViewShell->RepeatDB(); 326 327 // Pivottabellen die den Bereich als Quelldaten haben 328 329 ScRange aRange; 330 pDBData->GetArea(aRange); 331 GetViewData()->GetDocShell()->RefreshPivotTables(aRange); 332 } 333 } 334 rReq.Done(); 335 } 336 break; 337 338 case SID_SBA_BRW_INSERT: 339 { 340 DBG_ERROR( "Deprecated Slot" ); 341 } 342 break; 343 344 case SID_SUBTOTALS: 345 { 346 const SfxItemSet* pArgs = rReq.GetArgs(); 347 if ( pArgs ) 348 { 349 pTabViewShell->DoSubTotals( ((const ScSubTotalItem&) pArgs->Get( SCITEM_SUBTDATA )). 350 GetSubTotalData() ); 351 rReq.Done(); 352 } 353 else 354 { 355 //CHINA001 ScSubTotalDlg* pDlg = NULL; 356 SfxAbstractTabDialog * pDlg = NULL; 357 ScSubTotalParam aSubTotalParam; 358 SfxItemSet aArgSet( GetPool(), SCITEM_SUBTDATA, SCITEM_SUBTDATA ); 359 360 //ScDBData* pDBData = pTabViewShell->GetDBData(); 361 ScDBData* pDBData = pTabViewShell->GetDBData(sal_True, SC_DB_MAKE_SUBTOTAL); 362 pDBData->GetSubTotalParam( aSubTotalParam ); 363 aSubTotalParam.bRemoveOnly = sal_False; 364 365 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, GetViewData(), &aSubTotalParam ) ); 366 //CHINA001 pDlg = new ScSubTotalDlg( pTabViewShell->GetDialogParent(), &aArgSet ); 367 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 368 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 369 370 pDlg = pFact->CreateScSubTotalDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SUBTOTALS ); 371 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 372 pDlg->SetCurPageId(1); 373 374 short bResult = pDlg->Execute(); 375 376 if ( (bResult == RET_OK) || (bResult == SCRET_REMOVE) ) 377 { 378 const SfxItemSet* pOutSet = NULL; 379 380 if ( bResult == RET_OK ) 381 { 382 pOutSet = pDlg->GetOutputItemSet(); 383 aSubTotalParam = 384 ((const ScSubTotalItem&) 385 pOutSet->Get( SCITEM_SUBTDATA )). 386 GetSubTotalData(); 387 } 388 else // if (bResult == SCRET_REMOVE) 389 { 390 pOutSet = &aArgSet; 391 aSubTotalParam.bRemoveOnly = sal_True; 392 aSubTotalParam.bReplace = sal_True; 393 aArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, 394 GetViewData(), 395 &aSubTotalParam ) ); 396 } 397 398 pTabViewShell->DoSubTotals( aSubTotalParam ); 399 rReq.Done( *pOutSet ); 400 } 401 else 402 GetViewData()->GetDocShell()->CancelAutoDBRange(); 403 404 delete pDlg; 405 } 406 } 407 break; 408 409 case SID_SORT_DESCENDING: 410 case SID_SORT_ASCENDING: 411 { 412 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data 413 //the patch comes from maoyg 414 ScSortParam aSortParam; 415 ScDBData* pDBData = pTabViewShell->GetDBData(sal_True, SC_DB_MAKE_SORT); 416 ScViewData* pData = GetViewData(); 417 418 pDBData->GetSortParam( aSortParam ); 419 420 if( lcl_GetSortParam( pData, aSortParam ) ) 421 { 422 SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA ); 423 SCCOL nCol = GetViewData()->GetCurX(); 424 SCCOL nTab = GetViewData()->GetTabNo(); 425 ScDocument* pDoc = GetViewData()->GetDocument(); 426 427 pDBData->GetSortParam( aSortParam ); 428 sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, nTab ); 429 430 if( nCol < aSortParam.nCol1 ) 431 nCol = aSortParam.nCol1; 432 else if( nCol > aSortParam.nCol2 ) 433 nCol = aSortParam.nCol2; 434 435 aSortParam.bHasHeader = bHasHeader; 436 aSortParam.bByRow = sal_True; 437 aSortParam.bCaseSens = sal_False; 438 aSortParam.bIncludePattern = sal_True; 439 aSortParam.bInplace = sal_True; 440 aSortParam.bDoSort[0] = sal_True; 441 aSortParam.nField[0] = nCol; 442 aSortParam.bAscending[0] = (nSlotId == SID_SORT_ASCENDING); 443 444 for ( sal_uInt16 i=1; i<MAXSORT; i++ ) 445 aSortParam.bDoSort[i] = sal_False; 446 447 aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) ); 448 449 pTabViewShell->UISort( aSortParam ); // Teilergebnisse bei Bedarf neu 450 451 rReq.Done(); 452 } 453 } 454 break; 455 456 case SID_SORT: 457 { 458 const SfxItemSet* pArgs = rReq.GetArgs(); 459 460 //#i60401 ux-ctest: Calc does not support all users' strategies regarding sorting data 461 //the patch comes from maoyg 462 463 if ( pArgs ) // Basic 464 { 465 ScSortParam aSortParam; 466 ScDBData* pDBData = pTabViewShell->GetDBData(sal_True, SC_DB_MAKE_SORT); 467 ScViewData* pData = GetViewData(); 468 469 pDBData->GetSortParam( aSortParam ); 470 471 if( lcl_GetSortParam( pData, aSortParam ) ) 472 { 473 ScDocument* pDoc = GetViewData()->GetDocument(); 474 475 pDBData->GetSortParam( aSortParam ); 476 sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() ); 477 if( bHasHeader ) 478 aSortParam.bHasHeader = bHasHeader; 479 480 aSortParam.bInplace = sal_True; // von Basic immer 481 482 const SfxPoolItem* pItem; 483 if ( pArgs->GetItemState( SID_SORT_BYROW, sal_True, &pItem ) == SFX_ITEM_SET ) 484 aSortParam.bByRow = ((const SfxBoolItem*)pItem)->GetValue(); 485 if ( pArgs->GetItemState( SID_SORT_HASHEADER, sal_True, &pItem ) == SFX_ITEM_SET ) 486 aSortParam.bHasHeader = ((const SfxBoolItem*)pItem)->GetValue(); 487 if ( pArgs->GetItemState( SID_SORT_CASESENS, sal_True, &pItem ) == SFX_ITEM_SET ) 488 aSortParam.bCaseSens = ((const SfxBoolItem*)pItem)->GetValue(); 489 if ( pArgs->GetItemState( SID_SORT_ATTRIBS, sal_True, &pItem ) == SFX_ITEM_SET ) 490 aSortParam.bIncludePattern = ((const SfxBoolItem*)pItem)->GetValue(); 491 if ( pArgs->GetItemState( SID_SORT_USERDEF, sal_True, &pItem ) == SFX_ITEM_SET ) 492 { 493 sal_uInt16 nUserIndex = ((const SfxUInt16Item*)pItem)->GetValue(); 494 aSortParam.bUserDef = ( nUserIndex != 0 ); 495 if ( nUserIndex ) 496 aSortParam.nUserIndex = nUserIndex - 1; // Basic: 1-basiert 497 } 498 499 SCCOLROW nField0 = 0; 500 if ( pArgs->GetItemState( FN_PARAM_1, sal_True, &pItem ) == SFX_ITEM_SET ) 501 nField0 = ((const SfxInt32Item*)pItem)->GetValue(); 502 aSortParam.bDoSort[0] = ( nField0 != 0 ); 503 aSortParam.nField[0] = nField0 > 0 ? (nField0-1) : 0; 504 if ( pArgs->GetItemState( FN_PARAM_2, sal_True, &pItem ) == SFX_ITEM_SET ) 505 aSortParam.bAscending[0] = ((const SfxBoolItem*)pItem)->GetValue(); 506 SCCOLROW nField1 = 0; 507 if ( pArgs->GetItemState( FN_PARAM_3, sal_True, &pItem ) == SFX_ITEM_SET ) 508 nField1 = ((const SfxInt32Item*)pItem)->GetValue(); 509 aSortParam.bDoSort[1] = ( nField1 != 0 ); 510 aSortParam.nField[1] = nField1 > 0 ? (nField1-1) : 0; 511 if ( pArgs->GetItemState( FN_PARAM_4, sal_True, &pItem ) == SFX_ITEM_SET ) 512 aSortParam.bAscending[1] = ((const SfxBoolItem*)pItem)->GetValue(); 513 SCCOLROW nField2 = 0; 514 if ( pArgs->GetItemState( FN_PARAM_5, sal_True, &pItem ) == SFX_ITEM_SET ) 515 nField2 = ((const SfxInt32Item*)pItem)->GetValue(); 516 aSortParam.bDoSort[2] = ( nField2 != 0 ); 517 aSortParam.nField[2] = nField2 > 0 ? (nField2-1) : 0; 518 if ( pArgs->GetItemState( FN_PARAM_6, sal_True, &pItem ) == SFX_ITEM_SET ) 519 aSortParam.bAscending[2] = ((const SfxBoolItem*)pItem)->GetValue(); 520 521 // Teilergebnisse bei Bedarf neu 522 pTabViewShell->UISort( aSortParam ); 523 rReq.Done(); 524 } 525 } 526 else 527 { 528 ScSortParam aSortParam; 529 ScDBData* pDBData = pTabViewShell->GetDBData(sal_True, SC_DB_MAKE_SORT); 530 ScViewData* pData = GetViewData(); 531 532 pDBData->GetSortParam( aSortParam ); 533 534 if( lcl_GetSortParam( pData, aSortParam ) ) 535 { 536 SfxAbstractTabDialog* pDlg = NULL; 537 ScDocument* pDoc = GetViewData()->GetDocument(); 538 SfxItemSet aArgSet( GetPool(), SCITEM_SORTDATA, SCITEM_SORTDATA ); 539 540 pDBData->GetSortParam( aSortParam ); 541 sal_Bool bHasHeader = pDoc->HasColHeader( aSortParam.nCol1, aSortParam.nRow1, aSortParam.nCol2, aSortParam.nRow2, pData->GetTabNo() ); 542 if( bHasHeader ) 543 aSortParam.bHasHeader = bHasHeader; 544 545 aArgSet.Put( ScSortItem( SCITEM_SORTDATA, GetViewData(), &aSortParam ) ); 546 547 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 548 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 549 550 pDlg = pFact->CreateScSortDlg( pTabViewShell->GetDialogParent(), &aArgSet, RID_SCDLG_SORT ); 551 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 552 pDlg->SetCurPageId(1); 553 554 if ( pDlg->Execute() == RET_OK ) 555 { 556 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); 557 const ScSortParam& rOutParam = ((const ScSortItem&) 558 pOutSet->Get( SCITEM_SORTDATA )).GetSortData(); 559 560 // Teilergebnisse bei Bedarf neu 561 pTabViewShell->UISort( rOutParam ); 562 563 if ( rOutParam.bInplace ) 564 { 565 rReq.AppendItem( SfxBoolItem( SID_SORT_BYROW, 566 rOutParam.bByRow ) ); 567 rReq.AppendItem( SfxBoolItem( SID_SORT_HASHEADER, 568 rOutParam.bHasHeader ) ); 569 rReq.AppendItem( SfxBoolItem( SID_SORT_CASESENS, 570 rOutParam.bCaseSens ) ); 571 rReq.AppendItem( SfxBoolItem( SID_SORT_ATTRIBS, 572 rOutParam.bIncludePattern ) ); 573 sal_uInt16 nUser = rOutParam.bUserDef ? ( rOutParam.nUserIndex + 1 ) : 0; 574 rReq.AppendItem( SfxUInt16Item( SID_SORT_USERDEF, nUser ) ); 575 if ( rOutParam.bDoSort[0] ) 576 { 577 rReq.AppendItem( SfxInt32Item( FN_PARAM_1, 578 rOutParam.nField[0] + 1 ) ); 579 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, 580 rOutParam.bAscending[0] ) ); 581 } 582 if ( rOutParam.bDoSort[1] ) 583 { 584 rReq.AppendItem( SfxInt32Item( FN_PARAM_3, 585 rOutParam.nField[1] + 1 ) ); 586 rReq.AppendItem( SfxBoolItem( FN_PARAM_4, 587 rOutParam.bAscending[1] ) ); 588 } 589 if ( rOutParam.bDoSort[2] ) 590 { 591 rReq.AppendItem( SfxInt32Item( FN_PARAM_5, 592 rOutParam.nField[2] + 1 ) ); 593 rReq.AppendItem( SfxBoolItem( FN_PARAM_6, 594 rOutParam.bAscending[2] ) ); 595 } 596 } 597 598 rReq.Done(); 599 } 600 else 601 GetViewData()->GetDocShell()->CancelAutoDBRange(); 602 603 delete pDlg; 604 } 605 } 606 } 607 break; 608 609 case SID_FILTER: 610 { 611 const SfxItemSet* pArgs = rReq.GetArgs(); 612 if ( pArgs ) 613 { 614 DBG_ERROR("SID_FILTER with arguments?"); 615 pTabViewShell->Query( ((const ScQueryItem&) 616 pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), NULL, sal_True ); 617 rReq.Done(); 618 } 619 else 620 { 621 sal_uInt16 nId = ScFilterDlgWrapper::GetChildWindowId(); 622 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); 623 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); 624 625 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True ); 626 } 627 } 628 break; 629 630 case SID_SPECIAL_FILTER: 631 { 632 const SfxItemSet* pArgs = rReq.GetArgs(); 633 if ( pArgs ) 634 { 635 DBG_ERROR("SID_SPECIAL_FILTER with arguments?"); 636 pTabViewShell->Query( ((const ScQueryItem&) 637 pArgs->Get( SCITEM_QUERYDATA )).GetQueryData(), NULL, sal_True ); 638 rReq.Done(); 639 } 640 else 641 { 642 sal_uInt16 nId = ScSpecialFilterDlgWrapper::GetChildWindowId(); 643 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); 644 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); 645 646 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True ); 647 } 648 } 649 break; 650 651 case FID_FILTER_OK: 652 { 653 const SfxPoolItem* pItem; 654 if ( pReqArgs && SFX_ITEM_SET == 655 pReqArgs->GetItemState( SCITEM_QUERYDATA, sal_True, &pItem ) ) 656 { 657 const ScQueryItem& rQueryItem = static_cast<const ScQueryItem&>(*pItem); 658 659 SCTAB nCurTab = GetViewData()->GetTabNo(); 660 SCTAB nRefTab = GetViewData()->GetRefTabNo(); 661 662 // If RefInput switched to a different sheet from the data sheet, 663 // switch back: 664 665 if ( nCurTab != nRefTab ) 666 { 667 pTabViewShell->SetTabNo( nRefTab ); 668 pTabViewShell->PaintExtras(); 669 } 670 671 ScRange aAdvSource; 672 if (rQueryItem.GetAdvancedQuerySource(aAdvSource)) 673 pTabViewShell->Query( rQueryItem.GetQueryData(), &aAdvSource, sal_True ); 674 else 675 pTabViewShell->Query( rQueryItem.GetQueryData(), NULL, sal_True ); 676 rReq.Done( *pReqArgs ); 677 } 678 } 679 break; 680 681 case SID_UNFILTER: 682 { 683 ScQueryParam aParam; 684 ScDBData* pDBData = pTabViewShell->GetDBData(sal_True, SC_DB_OLD_FILTER); 685 686 pDBData->GetQueryParam( aParam ); 687 SCSIZE nEC = aParam.GetEntryCount(); 688 for (SCSIZE i=0; i<nEC; i++) 689 aParam.GetEntry(i).bDoQuery = sal_False; 690 aParam.bDuplicate = sal_True; 691 pTabViewShell->Query( aParam, NULL, sal_True ); 692 rReq.Done(); 693 } 694 break; 695 696 case SID_AUTO_FILTER: 697 pTabViewShell->ToggleAutoFilter(); 698 rReq.Done(); 699 break; 700 701 case SID_AUTOFILTER_HIDE: 702 pTabViewShell->HideAutoFilter(); 703 rReq.Done(); 704 break; 705 706 case SID_PIVOT_TABLE: 707 { 708 const SfxPoolItem* pItem; 709 if ( pReqArgs && SFX_ITEM_SET == 710 pReqArgs->GetItemState( SCITEM_PIVOTDATA, sal_True, &pItem ) ) 711 { 712 SCTAB nCurTab = GetViewData()->GetTabNo(); 713 SCTAB nRefTab = GetViewData()->GetRefTabNo(); 714 715 // Wenn RefInput auf andere Tabelle als Datentabelle umgeschaltet 716 // hat wieder zurueckschalten: 717 718 if ( nCurTab != nRefTab ) 719 { 720 pTabViewShell->SetTabNo( nRefTab ); 721 pTabViewShell->PaintExtras(); 722 } 723 724 const ScDPObject* pDPObject = pTabViewShell->GetDialogDPObject(); 725 if ( pDPObject ) 726 { 727 const ScPivotItem* pPItem = (const ScPivotItem*)pItem; 728 bool bSuccess = pTabViewShell->MakePivotTable( 729 pPItem->GetData(), pPItem->GetDestRange(), pPItem->IsNewSheet(), *pDPObject ); 730 SfxBoolItem aRet(0, bSuccess); 731 rReq.SetReturnValue(aRet); 732 } 733 rReq.Done(); 734 } 735 else if (rReq.IsAPI()) 736 SbxBase::SetError(SbxERR_BAD_PARAMETER); 737 } 738 break; 739 740 case SID_OPENDLG_PIVOTTABLE: 741 { 742 ScViewData* pData = GetViewData(); 743 ScDocument* pDoc = pData->GetDocument(); 744 745 ScDPObject* pNewDPObject = NULL; 746 747 // ScPivot is no longer used... 748 ScDPObject* pDPObj = pDoc->GetDPAtCursor( 749 pData->GetCurX(), pData->GetCurY(), 750 pData->GetTabNo() ); 751 if ( pDPObj ) // on an existing table? 752 { 753 pNewDPObject = new ScDPObject( *pDPObj ); 754 } 755 else // create new table 756 { 757 // select database range or data 758 pTabViewShell->GetDBData( sal_True, SC_DB_OLD ); 759 ScMarkData& rMark = GetViewData()->GetMarkData(); 760 if ( !rMark.IsMarked() && !rMark.IsMultiMarked() ) 761 pTabViewShell->MarkDataArea( sal_False ); 762 763 // output to cursor position for non-sheet data 764 ScAddress aDestPos( pData->GetCurX(), pData->GetCurY(), 765 pData->GetTabNo() ); 766 767 // first select type of source data 768 769 sal_Bool bEnableExt = ScDPObject::HasRegisteredSources(); 770 //CHINA001 ScDataPilotSourceTypeDlg* pTypeDlg = new ScDataPilotSourceTypeDlg( 771 //CHINA001 pTabViewShell->GetDialogParent(), bEnableExt ); 772 773 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 774 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 775 776 AbstractScDataPilotSourceTypeDlg* pTypeDlg = pFact->CreateScDataPilotSourceTypeDlg( pTabViewShell->GetDialogParent(), bEnableExt, RID_SCDLG_DAPITYPE ); 777 DBG_ASSERT(pTypeDlg, "Dialog create fail!");//CHINA001 778 if ( pTypeDlg->Execute() == RET_OK ) 779 { 780 if ( pTypeDlg->IsExternal() ) 781 { 782 uno::Sequence<rtl::OUString> aSources = ScDPObject::GetRegisteredSources(); 783 //CHINA001 ScDataPilotServiceDlg* pServDlg = new ScDataPilotServiceDlg( 784 //CHINA001 pTabViewShell->GetDialogParent(), aSources ); 785 AbstractScDataPilotServiceDlg* pServDlg = pFact->CreateScDataPilotServiceDlg( pTabViewShell->GetDialogParent(), aSources, RID_SCDLG_DAPISERVICE ); 786 DBG_ASSERT(pServDlg, "Dialog create fail!");//CHINA001 787 if ( pServDlg->Execute() == RET_OK ) 788 { 789 ScDPServiceDesc aServDesc( 790 pServDlg->GetServiceName(), 791 pServDlg->GetParSource(), 792 pServDlg->GetParName(), 793 pServDlg->GetParUser(), 794 pServDlg->GetParPass() ); 795 pNewDPObject = new ScDPObject( pDoc ); 796 pNewDPObject->SetServiceData( aServDesc ); 797 } 798 delete pServDlg; 799 } 800 else if ( pTypeDlg->IsDatabase() ) 801 { 802 //CHINA001 ScDataPilotDatabaseDlg* pDataDlg = new ScDataPilotDatabaseDlg( 803 //CHINA001 pTabViewShell->GetDialogParent() ); 804 //ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 805 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 806 807 AbstractScDataPilotDatabaseDlg* pDataDlg = pFact->CreateScDataPilotDatabaseDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_DAPIDATA); 808 DBG_ASSERT(pDataDlg, "Dialog create fail!");//CHINA001 809 if ( pDataDlg->Execute() == RET_OK ) 810 { 811 ScImportSourceDesc aImpDesc; 812 pDataDlg->GetValues( aImpDesc ); 813 pNewDPObject = new ScDPObject( pDoc ); 814 pNewDPObject->SetImportDesc( aImpDesc ); 815 } 816 delete pDataDlg; 817 } 818 else // selection 819 { 820 //! use database ranges (select before type dialog?) 821 ScRange aRange; 822 ScMarkType eType = GetViewData()->GetSimpleArea(aRange); 823 if ( (eType & SC_MARK_SIMPLE) == SC_MARK_SIMPLE ) 824 { 825 // Shrink the range to the data area. 826 SCCOL nStartCol = aRange.aStart.Col(), nEndCol = aRange.aEnd.Col(); 827 SCROW nStartRow = aRange.aStart.Row(), nEndRow = aRange.aEnd.Row(); 828 if (pDoc->ShrinkToDataArea(aRange.aStart.Tab(), nStartCol, nStartRow, nEndCol, nEndRow)) 829 { 830 aRange.aStart.SetCol(nStartCol); 831 aRange.aStart.SetRow(nStartRow); 832 aRange.aEnd.SetCol(nEndCol); 833 aRange.aEnd.SetRow(nEndRow); 834 rMark.SetMarkArea(aRange); 835 pTabViewShell->MarkRange(aRange); 836 } 837 838 sal_Bool bOK = sal_True; 839 if ( pDoc->HasSubTotalCells( aRange ) ) 840 { 841 // confirm selection if it contains SubTotal cells 842 843 QueryBox aBox( pTabViewShell->GetDialogParent(), 844 WinBits(WB_YES_NO | WB_DEF_YES), 845 ScGlobal::GetRscString(STR_DATAPILOT_SUBTOTAL) ); 846 if (aBox.Execute() == RET_NO) 847 bOK = sal_False; 848 } 849 if (bOK) 850 { 851 ScSheetSourceDesc aShtDesc; 852 aShtDesc.aSourceRange = aRange; 853 pNewDPObject = new ScDPObject( pDoc ); 854 pNewDPObject->SetSheetDesc( aShtDesc ); 855 856 // output below source data 857 if ( aRange.aEnd.Row()+2 <= MAXROW - 4 ) 858 aDestPos = ScAddress( aRange.aStart.Col(), 859 aRange.aEnd.Row()+2, 860 aRange.aStart.Tab() ); 861 } 862 } 863 } 864 } 865 delete pTypeDlg; 866 867 if ( pNewDPObject ) 868 pNewDPObject->SetOutRange( aDestPos ); 869 870 #if 0 871 ScDBData* pDBData = pTabViewShell->GetDBData(); 872 String aErrMsg; 873 874 pDBData->GetArea( nTab, nCol1, nRow1, nCol2, nRow2 ); 875 876 bAreaOk = sal_True; 877 if ( nRow2-nRow1 < 1 ) 878 { 879 // "mindestens eine Datenzeile" 880 pTabViewShell->ErrorMessage(STR_PIVOT_INVALID_DBAREA); 881 bAreaOk = sal_False; 882 } 883 else if (!pDBData->HasHeader()) 884 { 885 if ( MessBox( pTabViewShell->GetDialogParent(), WinBits(WB_YES_NO | WB_DEF_YES), 886 ScGlobal::GetRscString( STR_MSSG_DOSUBTOTALS_0 ), // "StarCalc" 887 ScGlobal::GetRscString( STR_MSSG_MAKEAUTOFILTER_0 ) // Koepfe aus erster Zeile? 888 ).Execute() == RET_YES ) 889 { 890 pDBData->SetHeader( sal_True ); //! Undo ?? 891 } 892 else 893 bAreaOk = sal_False; 894 } 895 #endif 896 } 897 898 pTabViewShell->SetDialogDPObject( pNewDPObject ); // is copied 899 if ( pNewDPObject ) 900 { 901 // start layout dialog 902 903 sal_uInt16 nId = ScPivotLayoutWrapper::GetChildWindowId(); 904 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); 905 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); 906 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True ); 907 } 908 delete pNewDPObject; 909 } 910 break; 911 912 case SID_DEFINE_DBNAME: 913 { 914 915 sal_uInt16 nId = ScDbNameDlgWrapper::GetChildWindowId(); 916 SfxViewFrame* pViewFrm = pTabViewShell->GetViewFrame(); 917 SfxChildWindow* pWnd = pViewFrm->GetChildWindow( nId ); 918 919 pScMod->SetRefDialog( nId, pWnd ? sal_False : sal_True ); 920 921 } 922 break; 923 924 case SID_SELECT_DB: 925 { 926 if ( pReqArgs ) 927 { 928 const SfxStringItem* pItem = 929 (const SfxStringItem*)&pReqArgs->Get( SID_SELECT_DB ); 930 931 if( pItem ) 932 { 933 pTabViewShell->GotoDBArea( pItem->GetValue() ); 934 rReq.Done(); 935 } 936 else 937 { 938 DBG_ERROR("NULL"); 939 } 940 } 941 else 942 { 943 ScDocument* pDoc = GetViewData()->GetDocument(); 944 ScDBCollection* pDBCol = pDoc->GetDBCollection(); 945 946 if ( pDBCol ) 947 { 948 const String aStrNoName( ScGlobal::GetRscString(STR_DB_NONAME) ); 949 List aList; 950 sal_uInt16 nDBCount = pDBCol->GetCount(); 951 ScDBData* pDbData = NULL; 952 String* pDBName = NULL; 953 954 for ( sal_uInt16 i=0; i < nDBCount; i++ ) 955 { 956 pDbData = (ScDBData*)(pDBCol->At( i )); 957 if ( pDbData ) 958 { 959 pDBName = new String; 960 pDbData->GetName( *pDBName ); 961 962 if ( *pDBName != aStrNoName ) 963 aList.Insert( pDBName ); 964 else 965 DELETEZ(pDBName); 966 } 967 } 968 969 //CHINA001 ScSelEntryDlg* pDlg = 970 //CHINA001 new ScSelEntryDlg( pTabViewShell->GetDialogParent(), RID_SCDLG_SELECTDB, 971 //CHINA001 String(ScResId(SCSTR_SELECTDB)), 972 //CHINA001 String(ScResId(SCSTR_AREAS)), 973 //CHINA001 aList ); 974 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 975 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 976 977 AbstractScSelEntryDlg* pDlg = pFact->CreateScSelEntryDlg( pTabViewShell->GetDialogParent(), 978 RID_SCDLG_SELECTDB, 979 String(ScResId(SCSTR_SELECTDB)), 980 String(ScResId(SCSTR_AREAS)), 981 aList, 982 RID_SCDLG_SELECTDB); 983 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 984 if ( pDlg->Execute() == RET_OK ) 985 { 986 String aName = pDlg->GetSelectEntry(); 987 pTabViewShell->GotoDBArea( aName ); 988 rReq.AppendItem( SfxStringItem( SID_SELECT_DB, aName ) ); 989 rReq.Done(); 990 } 991 992 delete pDlg; 993 994 void* pEntry = aList.First(); 995 while ( pEntry ) 996 { 997 delete (String*) aList.Remove( pEntry ); 998 pEntry = aList.Next(); 999 } 1000 } 1001 } 1002 } 1003 break; 1004 1005 case FID_VALIDATION: 1006 { 1007 const SfxPoolItem* pItem; 1008 const SfxItemSet* pArgs = rReq.GetArgs(); 1009 if ( pArgs ) 1010 { 1011 DBG_ERROR("spaeter..."); 1012 } 1013 else 1014 { 1015 //CHINA001 SfxItemSet aArgSet( GetPool(), ScTPValidationValue::GetRanges() ); 1016 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 1017 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 1018 ::GetTabPageRanges ScTPValidationValueGetRanges = pFact->GetTabPageRangesFunc(TP_VALIDATION_VALUES); 1019 DBG_ASSERT(ScTPValidationValueGetRanges, "TabPage create fail!");//CHINA001 1020 SfxItemSet aArgSet( GetPool(), (*ScTPValidationValueGetRanges)() );//CHINA001 1021 ScValidationMode eMode = SC_VALID_ANY; 1022 ScConditionMode eOper = SC_COND_EQUAL; 1023 String aExpr1, aExpr2; 1024 sal_Bool bBlank = sal_True; 1025 sal_Int16 nListType = ValidListType::UNSORTED; 1026 sal_Bool bShowHelp = sal_False; 1027 String aHelpTitle, aHelpText; 1028 sal_Bool bShowError = sal_False; 1029 ScValidErrorStyle eErrStyle = SC_VALERR_STOP; 1030 String aErrTitle, aErrText; 1031 1032 ScDocument* pDoc = GetViewData()->GetDocument(); 1033 SCCOL nCurX = GetViewData()->GetCurX(); 1034 SCROW nCurY = GetViewData()->GetCurY(); 1035 SCTAB nTab = GetViewData()->GetTabNo(); 1036 ScAddress aCursorPos( nCurX, nCurY, nTab ); 1037 sal_uLong nIndex = ((SfxUInt32Item*)pDoc->GetAttr( 1038 nCurX, nCurY, nTab, ATTR_VALIDDATA ))->GetValue(); 1039 if ( nIndex ) 1040 { 1041 const ScValidationData* pOldData = pDoc->GetValidationEntry( nIndex ); 1042 if ( pOldData ) 1043 { 1044 eMode = pOldData->GetDataMode(); 1045 eOper = pOldData->GetOperation(); 1046 sal_uLong nNumFmt = 0; 1047 if ( eMode == SC_VALID_DATE || eMode == SC_VALID_TIME ) 1048 { 1049 short nType = ( eMode == SC_VALID_DATE ) ? NUMBERFORMAT_DATE 1050 : NUMBERFORMAT_TIME; 1051 nNumFmt = pDoc->GetFormatTable()->GetStandardFormat( 1052 nType, ScGlobal::eLnge ); 1053 } 1054 aExpr1 = pOldData->GetExpression( aCursorPos, 0, nNumFmt ); 1055 aExpr2 = pOldData->GetExpression( aCursorPos, 1, nNumFmt ); 1056 bBlank = pOldData->IsIgnoreBlank(); 1057 nListType = pOldData->GetListType(); 1058 1059 bShowHelp = pOldData->GetInput( aHelpTitle, aHelpText ); 1060 bShowError = pOldData->GetErrMsg( aErrTitle, aErrText, eErrStyle ); 1061 1062 aArgSet.Put( SfxAllEnumItem( FID_VALID_MODE, sal::static_int_cast<sal_uInt16>(eMode) ) ); 1063 aArgSet.Put( SfxAllEnumItem( FID_VALID_CONDMODE, sal::static_int_cast<sal_uInt16>(eOper) ) ); 1064 aArgSet.Put( SfxStringItem( FID_VALID_VALUE1, aExpr1 ) ); 1065 aArgSet.Put( SfxStringItem( FID_VALID_VALUE2, aExpr2 ) ); 1066 aArgSet.Put( SfxBoolItem( FID_VALID_BLANK, bBlank ) ); 1067 aArgSet.Put( SfxInt16Item( FID_VALID_LISTTYPE, nListType ) ); 1068 aArgSet.Put( SfxBoolItem( FID_VALID_SHOWHELP, bShowHelp ) ); 1069 aArgSet.Put( SfxStringItem( FID_VALID_HELPTITLE, aHelpTitle ) ); 1070 aArgSet.Put( SfxStringItem( FID_VALID_HELPTEXT, aHelpText ) ); 1071 aArgSet.Put( SfxBoolItem( FID_VALID_SHOWERR, bShowError ) ); 1072 aArgSet.Put( SfxAllEnumItem( FID_VALID_ERRSTYLE, sal::static_int_cast<sal_uInt16>(eErrStyle) ) ); 1073 aArgSet.Put( SfxStringItem( FID_VALID_ERRTITLE, aErrTitle ) ); 1074 aArgSet.Put( SfxStringItem( FID_VALID_ERRTEXT, aErrText ) ); 1075 } 1076 } 1077 1078 //CHINA001 ScValidationDlg* pDlg = new ScValidationDlg( NULL, &aArgSet ); 1079 //CHINA001 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 1080 //CHINA001 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 1081 1082 //<!--Modified by PengYunQuan for Validity Cell Range Picker 1083 //SfxAbstractTabDialog* pDlg = pFact->CreateScValidationDlg( NULL, &aArgSet, TAB_DLG_VALIDATION ); 1084 SfxAbstractTabDialog* pDlg = pFact->CreateScValidationDlg( NULL, &aArgSet, TAB_DLG_VALIDATION, pTabViewShell ); 1085 //-->Modified by PengYunQuan for Validity Cell Range Picker 1086 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 1087 1088 //<!--Modified by PengYunQuan for Validity Cell Range Picker 1089 //if ( pDlg->Execute() == RET_OK ) 1090 short nResult = pDlg->Execute(); 1091 pTabViewShell->SetTabNo( nTab );//When picking Cell Range ,other Tab may be switched. Need restore the correct tab 1092 if ( nResult == RET_OK ) 1093 //-->Modified by PengYunQuan for Validity Cell Range Picker 1094 { 1095 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet(); 1096 1097 if ( pOutSet->GetItemState( FID_VALID_MODE, sal_True, &pItem ) == SFX_ITEM_SET ) 1098 eMode = (ScValidationMode) ((const SfxAllEnumItem*)pItem)->GetValue(); 1099 if ( pOutSet->GetItemState( FID_VALID_CONDMODE, sal_True, &pItem ) == SFX_ITEM_SET ) 1100 eOper = (ScConditionMode) ((const SfxAllEnumItem*)pItem)->GetValue(); 1101 if ( pOutSet->GetItemState( FID_VALID_VALUE1, sal_True, &pItem ) == SFX_ITEM_SET ) 1102 { 1103 String aTemp1 = ((const SfxStringItem*)pItem)->GetValue(); 1104 if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME) 1105 { 1106 sal_uInt32 nNumIndex = 0; 1107 double nVal; 1108 if (pDoc->GetFormatTable()->IsNumberFormat(aTemp1, nNumIndex, nVal)) 1109 aExpr1 =String( ::rtl::math::doubleToUString( nVal, 1110 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, 1111 ScGlobal::pLocaleData->getNumDecimalSep().GetChar(0), sal_True)); 1112 else 1113 aExpr1 = aTemp1; 1114 } 1115 else 1116 aExpr1 = aTemp1; 1117 } 1118 if ( pOutSet->GetItemState( FID_VALID_VALUE2, sal_True, &pItem ) == SFX_ITEM_SET ) 1119 { 1120 String aTemp2 = ((const SfxStringItem*)pItem)->GetValue(); 1121 if (eMode == SC_VALID_DATE || eMode == SC_VALID_TIME) 1122 { 1123 sal_uInt32 nNumIndex = 0; 1124 double nVal; 1125 if (pDoc->GetFormatTable()->IsNumberFormat(aTemp2, nNumIndex, nVal)) 1126 aExpr2 =String( ::rtl::math::doubleToUString( nVal, 1127 rtl_math_StringFormat_Automatic, rtl_math_DecimalPlaces_Max, 1128 ScGlobal::pLocaleData->getNumDecimalSep().GetChar(0), sal_True)); 1129 else 1130 aExpr2 = aTemp2; 1131 } 1132 else 1133 aExpr2 = aTemp2; 1134 } 1135 1136 if ( pOutSet->GetItemState( FID_VALID_BLANK, sal_True, &pItem ) == SFX_ITEM_SET ) 1137 bBlank = ((const SfxBoolItem*)pItem)->GetValue(); 1138 if ( pOutSet->GetItemState( FID_VALID_LISTTYPE, sal_True, &pItem ) == SFX_ITEM_SET ) 1139 nListType = ((const SfxInt16Item*)pItem)->GetValue(); 1140 1141 if ( pOutSet->GetItemState( FID_VALID_SHOWHELP, sal_True, &pItem ) == SFX_ITEM_SET ) 1142 bShowHelp = ((const SfxBoolItem*)pItem)->GetValue(); 1143 if ( pOutSet->GetItemState( FID_VALID_HELPTITLE, sal_True, &pItem ) == SFX_ITEM_SET ) 1144 aHelpTitle = ((const SfxStringItem*)pItem)->GetValue(); 1145 if ( pOutSet->GetItemState( FID_VALID_HELPTEXT, sal_True, &pItem ) == SFX_ITEM_SET ) 1146 aHelpText = ((const SfxStringItem*)pItem)->GetValue(); 1147 1148 if ( pOutSet->GetItemState( FID_VALID_SHOWERR, sal_True, &pItem ) == SFX_ITEM_SET ) 1149 bShowError = ((const SfxBoolItem*)pItem)->GetValue(); 1150 if ( pOutSet->GetItemState( FID_VALID_ERRSTYLE, sal_True, &pItem ) == SFX_ITEM_SET ) 1151 eErrStyle = (ScValidErrorStyle) ((const SfxAllEnumItem*)pItem)->GetValue(); 1152 if ( pOutSet->GetItemState( FID_VALID_ERRTITLE, sal_True, &pItem ) == SFX_ITEM_SET ) 1153 aErrTitle = ((const SfxStringItem*)pItem)->GetValue(); 1154 if ( pOutSet->GetItemState( FID_VALID_ERRTEXT, sal_True, &pItem ) == SFX_ITEM_SET ) 1155 aErrText = ((const SfxStringItem*)pItem)->GetValue(); 1156 1157 ScValidationData aData( eMode, eOper, aExpr1, aExpr2, pDoc, aCursorPos ); 1158 aData.SetIgnoreBlank( bBlank ); 1159 aData.SetListType( nListType ); 1160 1161 aData.SetInput(aHelpTitle, aHelpText); // sets bShowInput to TRUE 1162 if (!bShowHelp) 1163 aData.ResetInput(); // reset only bShowInput 1164 1165 aData.SetError(aErrTitle, aErrText, eErrStyle); // sets bShowError to TRUE 1166 if (!bShowError) 1167 aData.ResetError(); // reset only bShowError 1168 1169 pTabViewShell->SetValidation( aData ); 1170 rReq.Done( *pOutSet ); 1171 } 1172 //<!-- Modified by PengYunQuan for Validity Cell Range Picker 1173 //after end execute from !IsModalInputMode, it is safer to delay deleting 1174 //delete pDlg; 1175 Application::PostUserEvent( Link( pDlg, &DelayDeleteAbstractDialog ) ); 1176 //--> Modified by PengYunQuan for Validity Cell Range Picker 1177 } 1178 } 1179 break; 1180 1181 case SID_TEXT_TO_COLUMNS: 1182 { 1183 ScViewData* pData = GetViewData(); 1184 DBG_ASSERT( pData, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pData is null!" ); 1185 ScRange aRange; 1186 1187 if ( lcl_GetTextToColumnsRange( pData, aRange ) ) 1188 { 1189 ScDocument* pDoc = pData->GetDocument(); 1190 DBG_ASSERT( pDoc, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDoc is null!" ); 1191 1192 ScImportExport aExport( pDoc, aRange ); 1193 aExport.SetExportTextOptions( ScExportTextOptions( ScExportTextOptions::None, 0, false ) ); 1194 1195 // #i87703# text to columns fails with tab separator 1196 aExport.SetDelimiter( static_cast< sal_Unicode >( 0 ) ); 1197 1198 SvMemoryStream aStream; 1199 aStream.SetStreamCharSet( RTL_TEXTENCODING_UNICODE ); 1200 ScImportExport::SetNoEndianSwap( aStream ); 1201 aExport.ExportStream( aStream, String(), FORMAT_STRING ); 1202 1203 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 1204 DBG_ASSERT( pFact, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pFact is null!" ); 1205 AbstractScImportAsciiDlg *pDlg = pFact->CreateScImportAsciiDlg( 1206 NULL, String(), &aStream, RID_SCDLG_ASCII ); 1207 DBG_ASSERT( pDlg, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDlg is null!" ); 1208 pDlg->SetTextToColumnsMode(); 1209 1210 if ( pDlg->Execute() == RET_OK ) 1211 { 1212 ScDocShell* pDocSh = pData->GetDocShell(); 1213 DBG_ASSERT( pDocSh, "ScCellShell::ExecuteDB: SID_TEXT_TO_COLUMNS - pDocSh is null!" ); 1214 1215 String aUndo = ScGlobal::GetRscString( STR_UNDO_TEXTTOCOLUMNS ); 1216 pDocSh->GetUndoManager()->EnterListAction( aUndo, aUndo ); 1217 1218 ScImportExport aImport( pDoc, aRange.aStart ); 1219 ScAsciiOptions aOptions; 1220 pDlg->GetOptions( aOptions ); 1221 aImport.SetExtOptions( aOptions ); 1222 aImport.SetApi( false ); 1223 aStream.Seek( 0 ); 1224 aImport.ImportStream( aStream, String(), FORMAT_STRING ); 1225 1226 pDocSh->GetUndoManager()->LeaveListAction(); 1227 } 1228 delete pDlg; 1229 } 1230 } 1231 break; 1232 } 1233 } 1234 1235 void __EXPORT ScCellShell::GetDBState( SfxItemSet& rSet ) 1236 { 1237 ScTabViewShell* pTabViewShell = GetViewData()->GetViewShell(); 1238 ScViewData* pData = GetViewData(); 1239 ScDocShell* pDocSh = pData->GetDocShell(); 1240 ScDocument* pDoc = pDocSh->GetDocument(); 1241 SCCOL nPosX = pData->GetCurX(); 1242 SCROW nPosY = pData->GetCurY(); 1243 SCTAB nTab = pData->GetTabNo(); 1244 1245 sal_Bool bAutoFilter = sal_False; 1246 sal_Bool bAutoFilterTested = sal_False; 1247 1248 SfxWhichIter aIter(rSet); 1249 sal_uInt16 nWhich = aIter.FirstWhich(); 1250 while (nWhich) 1251 { 1252 switch (nWhich) 1253 { 1254 case SID_REFRESH_DBAREA: 1255 { 1256 // importierte Daten ohne Selektion 1257 // oder Filter,Sortierung,Teilergebis (auch ohne Import) 1258 sal_Bool bOk = sal_False; 1259 ScDBData* pDBData = pTabViewShell->GetDBData(sal_False,SC_DB_OLD); 1260 if (pDBData && pDoc->GetChangeTrack() == NULL) 1261 { 1262 if ( pDBData->HasImportParam() ) 1263 bOk = !pDBData->HasImportSelection(); 1264 else 1265 { 1266 bOk = pDBData->HasQueryParam() || 1267 pDBData->HasSortParam() || 1268 pDBData->HasSubTotalParam(); 1269 } 1270 } 1271 if (!bOk) 1272 rSet.DisableItem( nWhich ); 1273 } 1274 break; 1275 1276 case SID_FILTER: 1277 case SID_SPECIAL_FILTER: 1278 { 1279 ScRange aDummy; 1280 ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy); 1281 if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED) 1282 { 1283 rSet.DisableItem( nWhich ); 1284 } 1285 } 1286 break; 1287 1288 1289 //Bei Redlining und Multiselektion Disablen 1290 case SID_SORT_ASCENDING: 1291 case SID_SORT_DESCENDING: 1292 case SCITEM_SORTDATA: 1293 case SCITEM_SUBTDATA: 1294 case SID_OPENDLG_PIVOTTABLE: 1295 { 1296 //! move ReadOnly check to idl flags 1297 1298 if ( pDocSh->IsReadOnly() || pDoc->GetChangeTrack()!=NULL || 1299 GetViewData()->IsMultiMarked() ) 1300 { 1301 rSet.DisableItem( nWhich ); 1302 } 1303 } 1304 break; 1305 1306 case SID_REIMPORT_DATA: 1307 { 1308 // nur importierte Daten ohne Selektion 1309 ScDBData* pDBData = pTabViewShell->GetDBData(sal_False,SC_DB_OLD); 1310 if (!pDBData || !pDBData->HasImportParam() || pDBData->HasImportSelection() || 1311 pDoc->GetChangeTrack()!=NULL) 1312 { 1313 rSet.DisableItem( nWhich ); 1314 } 1315 } 1316 break; 1317 1318 case SID_VIEW_DATA_SOURCE_BROWSER: 1319 { 1320 if (!SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::E_SDATABASE)) 1321 rSet.Put(SfxVisibilityItem(nWhich, sal_False)); 1322 else 1323 // get state (BoolItem) from SfxViewFrame 1324 pTabViewShell->GetViewFrame()->GetSlotState( nWhich, NULL, &rSet ); 1325 } 1326 break; 1327 case SID_SBA_BRW_INSERT: 1328 { 1329 // SBA will ein sal_Bool-Item, damit ueberhaupt enabled 1330 1331 sal_Bool bEnable = sal_True; 1332 rSet.Put(SfxBoolItem(nWhich, bEnable)); 1333 } 1334 break; 1335 1336 case SID_AUTO_FILTER: 1337 case SID_AUTOFILTER_HIDE: 1338 { 1339 if (!bAutoFilterTested) 1340 { 1341 bAutoFilter = pDoc->HasAutoFilter( nPosX, nPosY, nTab ); 1342 bAutoFilterTested = sal_True; 1343 } 1344 if ( nWhich == SID_AUTO_FILTER ) 1345 { 1346 ScRange aDummy; 1347 ScMarkType eMarkType = GetViewData()->GetSimpleArea( aDummy); 1348 if (eMarkType != SC_MARK_SIMPLE && eMarkType != SC_MARK_SIMPLE_FILTERED) 1349 { 1350 rSet.DisableItem( nWhich ); 1351 } 1352 else if (pDoc->GetDPAtBlock(aDummy)) 1353 { 1354 rSet.DisableItem( nWhich ); 1355 } 1356 else 1357 rSet.Put( SfxBoolItem( nWhich, bAutoFilter ) ); 1358 } 1359 else 1360 if (!bAutoFilter) 1361 rSet.DisableItem( nWhich ); 1362 } 1363 break; 1364 1365 case SID_UNFILTER: 1366 { 1367 SCCOL nStartCol, nEndCol; 1368 SCROW nStartRow, nEndRow; 1369 SCTAB nStartTab, nEndTab; 1370 sal_Bool bAnyQuery = sal_False; 1371 1372 sal_Bool bSelected = (GetViewData()->GetSimpleArea( 1373 nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab ) 1374 == SC_MARK_SIMPLE); 1375 1376 if ( bSelected ) 1377 { 1378 if (nStartCol==nEndCol && nStartRow==nEndRow) 1379 bSelected = sal_False; 1380 } 1381 else 1382 { 1383 nStartCol = GetViewData()->GetCurX(); 1384 nStartRow = GetViewData()->GetCurY(); 1385 nStartTab = GetViewData()->GetTabNo(); 1386 } 1387 1388 ScDBData* pDBData = bSelected 1389 ? pDoc->GetDBAtArea( nStartTab, nStartCol, nStartRow, nEndCol, nEndRow ) 1390 : pDoc->GetDBAtCursor( nStartCol, nStartRow, nStartTab ); 1391 1392 if ( pDBData ) 1393 { 1394 ScQueryParam aParam; 1395 pDBData->GetQueryParam( aParam ); 1396 if ( aParam.GetEntry(0).bDoQuery ) 1397 bAnyQuery = sal_True; 1398 } 1399 1400 if ( !bAnyQuery ) 1401 rSet.DisableItem( nWhich ); 1402 } 1403 break; 1404 1405 case SID_DEFINE_DBNAME: 1406 { 1407 if ( pDocSh && pDocSh->IsDocShared() ) 1408 { 1409 rSet.DisableItem( nWhich ); 1410 } 1411 } 1412 break; 1413 1414 case SID_TEXT_TO_COLUMNS: 1415 { 1416 ScRange aRange; 1417 if ( !lcl_GetTextToColumnsRange( pData, aRange ) ) 1418 { 1419 rSet.DisableItem( nWhich ); 1420 } 1421 } 1422 break; 1423 } 1424 nWhich = aIter.NextWhich(); 1425 } 1426 } 1427 1428 1429 1430