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 #include <boost/scoped_ptr.hpp> 28 29 #include "scitems.hxx" 30 #include <sfx2/request.hxx> 31 #include <sfx2/viewfrm.hxx> 32 #include <basic/sbstar.hxx> 33 #include <layout/layout.hxx> 34 #include <svl/languageoptions.hxx> 35 #include <svl/stritem.hxx> 36 #include <svl/whiter.hxx> 37 #include <vcl/msgbox.hxx> 38 #include <sfx2/objface.hxx> 39 #include <svx/svxdlg.hxx> 40 #include <editeng/colritem.hxx> 41 42 #include "tabvwsh.hxx" 43 #include "sc.hrc" 44 #include "docsh.hxx" 45 #include "document.hxx" 46 #include "shtabdlg.hxx" 47 #include "scresid.hxx" 48 //CHINA001 #include "instbdlg.hxx" 49 #include "globstr.hrc" 50 //CHINA001 #include "strindlg.hxx" 51 //CHINA001 #include "mvtabdlg.hxx" 52 #include "docfunc.hxx" 53 #include "eventuno.hxx" 54 55 #include "scabstdlg.hxx" //CHINA001 56 57 #include "tabbgcolor.hxx" 58 #include "tabbgcolordlg.hxx" 59 #include "sccommands.h" 60 61 using ::boost::scoped_ptr; 62 using namespace com::sun::star; 63 64 #define IS_AVAILABLE(WhichId,ppItem) \ 65 (pReqArgs->GetItemState((WhichId), sal_True, ppItem ) == SFX_ITEM_SET) 66 67 //------------------------------------------------------------------ 68 69 void ScTabViewShell::ExecuteTable( SfxRequest& rReq ) 70 { 71 ScViewData* pViewData = GetViewData(); 72 ScDocument* pDoc = pViewData->GetDocument(); 73 74 SCTAB nCurrentTab = pViewData->GetTabNo(); 75 SCTAB nTabCount = pDoc->GetTableCount(); 76 sal_uInt16 nSlot = rReq.GetSlot(); 77 const SfxItemSet* pReqArgs = rReq.GetArgs(); 78 79 HideListBox(); // Autofilter-DropDown-Listbox 80 81 switch ( nSlot ) 82 { 83 case FID_TABLE_VISIBLE: 84 { 85 String aName; 86 pDoc->GetName( nCurrentTab, aName ); 87 88 sal_Bool bVisible=sal_True; 89 if( pReqArgs != NULL ) 90 { 91 const SfxPoolItem* pItem; 92 if( IS_AVAILABLE( FID_TABLE_VISIBLE, &pItem ) ) 93 bVisible = ((const SfxBoolItem*)pItem)->GetValue(); 94 } 95 96 if( ! bVisible ) // ausblenden 97 { 98 ScMarkData& rMark = pViewData->GetMarkData(); 99 SCTAB nTabSelCount = rMark.GetSelectCount(); 100 sal_uInt16 nVis = 0; 101 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ ) 102 if (pDoc->IsVisible(i)) 103 ++nVis; 104 if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 ) 105 break; 106 107 SCTAB nHideTab; 108 if (pDoc->GetTable( aName, nHideTab )) 109 HideTable( nHideTab ); 110 } 111 else // einblenden 112 { 113 ShowTable( aName ); 114 } 115 } 116 break; 117 118 case FID_TABLE_HIDE: 119 { 120 ScMarkData& rMark = pViewData->GetMarkData(); 121 SCTAB nTabSelCount = rMark.GetSelectCount(); 122 sal_uInt16 nVis = 0; 123 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ ) 124 if (pDoc->IsVisible(i)) 125 ++nVis; 126 if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 ) 127 break; 128 129 130 String aName; 131 if( pReqArgs != NULL ) 132 { 133 const SfxPoolItem* pItem; 134 if( IS_AVAILABLE( FID_TABLE_HIDE, &pItem ) ) 135 aName = ((const SfxStringItem*)pItem)->GetValue(); 136 } 137 138 if (!aName.Len()) 139 { 140 pDoc->GetName( nCurrentTab, aName ); // aktuelle Tabelle 141 rReq.AppendItem( SfxStringItem( FID_TABLE_HIDE, aName ) ); 142 } 143 144 SCTAB nHideTab; 145 if (pDoc->GetTable( aName, nHideTab )) 146 HideTable( nHideTab ); 147 148 if( ! rReq.IsAPI() ) 149 rReq.Done(); 150 } 151 break; 152 153 case FID_TABLE_SHOW: 154 { 155 String aName; 156 if ( pReqArgs ) 157 { 158 const SfxPoolItem* pItem; 159 if( IS_AVAILABLE( FID_TABLE_SHOW, &pItem ) ) 160 { 161 aName = ((const SfxStringItem*)pItem)->GetValue(); 162 163 ShowTable( aName ); 164 165 if( ! rReq.IsAPI() ) 166 rReq.Done(); 167 } 168 } 169 else 170 { 171 //CHINA001 ScShowTabDlg* pDlg = new ScShowTabDlg( GetDialogParent() ); 172 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 173 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 174 175 AbstractScShowTabDlg* pDlg = pFact->CreateScShowTabDlg( GetDialogParent(), RID_SCDLG_SHOW_TAB); 176 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 177 178 String aTabName; 179 sal_Bool bFirst = sal_True; 180 for ( SCTAB i=0; i != nTabCount; i++ ) 181 { 182 if (!pDoc->IsVisible(i)) 183 { 184 pDoc->GetName( i, aTabName ); 185 pDlg->Insert( aTabName, bFirst ); 186 bFirst = sal_False; 187 } 188 } 189 190 if ( pDlg->Execute() == RET_OK ) 191 { 192 sal_uInt16 nCount = pDlg->GetSelectEntryCount(); 193 for (sal_uInt16 nPos=0; nPos<nCount; nPos++) 194 { 195 aName = pDlg->GetSelectEntry(nPos); 196 ShowTable( aName ); 197 } 198 rReq.AppendItem( SfxStringItem( FID_TABLE_SHOW, aName ) ); 199 rReq.Done(); 200 } 201 delete pDlg; 202 } 203 } 204 break; 205 206 case FID_INS_TABLE: 207 case FID_INS_TABLE_EXT: 208 { 209 ScMarkData& rMark = pViewData->GetMarkData(); 210 SCTAB nTabSelCount = rMark.GetSelectCount(); 211 SCTAB nTabNr = nCurrentTab; 212 213 if ( !pDoc->IsDocEditable() ) 214 break; // gesperrt 215 216 if ( pReqArgs != NULL ) // von Basic 217 { 218 sal_Bool bOk = sal_False; 219 const SfxPoolItem* pTabItem; 220 const SfxPoolItem* pNameItem; 221 String aName; 222 223 if ( IS_AVAILABLE( FN_PARAM_1, &pTabItem ) && 224 IS_AVAILABLE( nSlot, &pNameItem ) ) 225 { 226 // Tabellennr. von Basic: 1-basiert 227 228 aName = ((const SfxStringItem*)pNameItem)->GetValue(); 229 nTabNr = ((const SfxUInt16Item*)pTabItem)->GetValue() - 1; 230 if ( nTabNr < nTabCount ) 231 bOk = InsertTable( aName, nTabNr ); 232 } 233 234 if (bOk) 235 rReq.Done( *pReqArgs ); 236 //! sonst Fehler setzen 237 } 238 else // Dialog 239 { 240 //CHINA001 ScInsertTableDlg* pDlg = new ScInsertTableDlg( 241 //CHINA001 GetDialogParent(), 242 //CHINA001 *pViewData,nTabSelCount); 243 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 244 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 245 246 AbstractScInsertTableDlg* pDlg = pFact->CreateScInsertTableDlg( GetDialogParent(), *pViewData, 247 nTabSelCount, nSlot == FID_INS_TABLE_EXT, 248 RID_SCDLG_INSERT_TABLE); 249 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 250 if ( RET_OK == pDlg->Execute() ) 251 { 252 if (pDlg->GetTablesFromFile()) 253 { 254 SCTAB nTabs[MAXTABCOUNT]; 255 SCTAB nCount = 0; 256 sal_uInt16 n = 0; 257 const String* pStr = pDlg->GetFirstTable( &n ); 258 while ( pStr ) 259 { 260 nTabs[nCount++] = static_cast<SCTAB>(n); 261 pStr = pDlg->GetNextTable( &n ); 262 } 263 sal_Bool bLink = pDlg->GetTablesAsLink(); 264 if (nCount != 0) 265 { 266 if(pDlg->IsTableBefore()) 267 { 268 ImportTables( pDlg->GetDocShellTables(), nCount, nTabs, 269 bLink,nTabNr ); 270 } 271 else 272 { 273 SCTAB nTabAfter = nTabNr+1; 274 275 for(SCTAB j=nCurrentTab+1;j<nTabCount;j++) 276 { 277 if(!pDoc->IsScenario(j)) 278 { 279 nTabAfter=j; 280 break; 281 } 282 } 283 284 ImportTables( pDlg->GetDocShellTables(), nCount, nTabs, 285 bLink,nTabAfter ); 286 } 287 } 288 } 289 else 290 { 291 SCTAB nCount=pDlg->GetTableCount(); 292 if(pDlg->IsTableBefore()) 293 { 294 if(nCount==1 && pDlg->GetFirstTable()->Len()>0) 295 { 296 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) ); 297 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabNr) + 1 ) ); // 1-based 298 rReq.Done(); 299 300 InsertTable( *pDlg->GetFirstTable(), nTabNr ); 301 } 302 else 303 InsertTables( NULL, nTabNr,nCount ); 304 } 305 else 306 { 307 SCTAB nTabAfter = nTabNr+1; 308 SCTAB nSelHigh=0; 309 310 for(SCTAB i=0;i<nTabCount;i++) 311 { 312 if(rMark.GetTableSelect(i)) 313 { 314 nSelHigh=i; 315 } 316 } 317 318 for(SCTAB j=nSelHigh+1;j<nTabCount;j++) 319 { 320 if(!pDoc->IsScenario(j)) 321 { 322 nTabAfter=j; 323 break; 324 } 325 else // #101672#; increase nTabAfter, because it is possible that the scenario tables are the last 326 nTabAfter = j + 1; 327 } 328 329 if(nCount==1 && pDlg->GetFirstTable()->Len()>0) 330 { 331 rReq.AppendItem( SfxStringItem( FID_INS_TABLE, *pDlg->GetFirstTable() ) ); 332 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nTabAfter) + 1 ) ); // 1-based 333 rReq.Done(); 334 335 InsertTable( *pDlg->GetFirstTable(), nTabAfter); 336 } 337 else 338 { 339 InsertTables( NULL, nTabAfter,nCount); 340 } 341 } 342 } 343 } 344 345 delete pDlg; 346 } 347 } 348 break; 349 350 case FID_TAB_APPEND: 351 case FID_TAB_RENAME: 352 case FID_TAB_MENU_RENAME: 353 { 354 // FID_TAB_MENU_RENAME - "umbenennen" im Menu 355 // FID_TAB_RENAME - "Name"-Property fuer Basic 356 // Execute ist gleich, aber im GetState wird MENU_RENAME evtl. disabled 357 358 if ( nSlot == FID_TAB_MENU_RENAME ) 359 nSlot = FID_TAB_RENAME; // Execute ist gleich 360 361 SCTAB nTabNr = pViewData->GetTabNo(); 362 ScMarkData& rMark = pViewData->GetMarkData(); 363 SCTAB nTabSelCount = rMark.GetSelectCount(); 364 365 if ( !pDoc->IsDocEditable() ) 366 break; // alles gesperrt 367 368 if ( nSlot != FID_TAB_APPEND && 369 ( pDoc->IsTabProtected( nTabNr ) || nTabSelCount > 1 ) ) 370 break; // kein Rename 371 372 #if 0 373 // ScSbxObject wird nicht mehr benutzt, stattdessen aus dem 374 // ScSbxTable::Notify die richtige Tabelle an der Basic-View eingestellt 375 if( rReq.IsAPI() ) 376 { 377 SbxObject* pObj = GetScSbxObject(); 378 ScSbxTable* pSbxTab = PTR_CAST( ScSbxTable, pObj ); 379 DBG_ASSERT( pSbxTab, "pSbxTab???" ); 380 381 if( pSbxTab ) 382 nTabNr = pSbxTab->GetTableNr(); 383 } 384 #endif 385 386 if( pReqArgs != NULL ) 387 { 388 sal_Bool bDone = sal_False; 389 const SfxPoolItem* pItem; 390 String aName; 391 392 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) ) 393 nTabNr = ((const SfxUInt16Item*)pItem)->GetValue(); 394 395 if( IS_AVAILABLE( nSlot, &pItem ) ) 396 aName = ((const SfxStringItem*)pItem)->GetValue(); 397 398 switch ( nSlot ) 399 { 400 case FID_TAB_APPEND: 401 bDone = AppendTable( aName ); 402 break; 403 case FID_TAB_RENAME: 404 bDone = RenameTable( aName, nTabNr ); 405 break; 406 } 407 408 if( bDone ) 409 { 410 rReq.Done( *pReqArgs ); 411 } 412 } 413 else 414 { 415 sal_uInt16 nRet = RET_OK; 416 sal_Bool bDone = sal_False; 417 String aErrMsg ( ScGlobal::GetRscString( STR_INVALIDTABNAME ) ); 418 String aName; 419 String aDlgTitle; 420 const sal_Char* pHelpId = 0; 421 422 switch ( nSlot ) 423 { 424 case FID_TAB_APPEND: 425 aDlgTitle = String(ScResId(SCSTR_APDTABLE)); 426 pDoc->CreateValidTabName( aName ); 427 pHelpId = HID_SC_APPEND_NAME; 428 break; 429 430 case FID_TAB_RENAME: 431 aDlgTitle = String(ScResId(SCSTR_RENAMETAB)); 432 pDoc->GetName( pViewData->GetTabNo(), aName ); 433 pHelpId = HID_SC_RENAME_NAME; 434 break; 435 } 436 437 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 438 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 439 440 AbstractScStringInputDlg* pDlg = pFact->CreateScStringInputDlg( GetDialogParent(), 441 aDlgTitle, 442 String(ScResId(SCSTR_NAME)), 443 aName, 444 GetStaticInterface()->GetSlot(nSlot)->GetCommand(), pHelpId, RID_SCDLG_STRINPUT); 445 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 446 447 while ( !bDone && nRet == RET_OK ) 448 { 449 nRet = pDlg->Execute(); 450 451 if ( nRet == RET_OK ) 452 { 453 pDlg->GetInputString( aName ); 454 455 456 switch ( nSlot ) 457 { 458 case FID_TAB_APPEND: 459 bDone = AppendTable( aName ); 460 break; 461 case FID_TAB_RENAME: 462 bDone = RenameTable( aName, nTabNr ); 463 break; 464 } 465 466 if ( bDone ) 467 { 468 rReq.AppendItem( SfxStringItem( nSlot, aName ) ); 469 rReq.Done(); 470 } 471 else 472 { 473 if( rReq.IsAPI() ) 474 { 475 StarBASIC::Error( SbERR_SETPROP_FAILED ); // XXX Fehlerbehandlung??? 476 } 477 else 478 { 479 nRet = ErrorBox( GetDialogParent(), 480 WinBits( WB_OK | WB_DEF_OK ), 481 aErrMsg 482 ).Execute(); 483 } 484 } 485 } 486 } 487 delete pDlg; 488 } 489 } 490 break; 491 492 case FID_TAB_MOVE: 493 { 494 if ( pDoc->GetChangeTrack() != NULL ) 495 break; // bei aktiviertem ChangeTracking kein TabMove 496 497 sal_Bool bDoIt = sal_False; 498 sal_uInt16 nDoc = 0; 499 SCTAB nTab = pViewData->GetTabNo(); 500 sal_Bool bCpy = sal_False; 501 String aDocName; 502 503 if( pReqArgs != NULL ) 504 { 505 SCTAB nTableCount = pDoc->GetTableCount(); 506 const SfxPoolItem* pItem; 507 508 if( IS_AVAILABLE( FID_TAB_MOVE, &pItem ) ) 509 aDocName = ((const SfxStringItem*)pItem)->GetValue(); 510 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) ) 511 { 512 // Tabelle ist 1-basiert 513 nTab = ((const SfxUInt16Item*)pItem)->GetValue() - 1; 514 if ( nTab >= nTableCount ) 515 nTab = SC_TAB_APPEND; 516 } 517 if( IS_AVAILABLE( FN_PARAM_2, &pItem ) ) 518 bCpy = ((const SfxBoolItem*)pItem)->GetValue(); 519 520 if( aDocName.Len() ) 521 { 522 SfxObjectShell* pSh = SfxObjectShell::GetFirst(); 523 ScDocShell* pScSh = NULL; 524 sal_uInt16 i=0; 525 526 while ( pSh ) 527 { 528 pScSh = PTR_CAST( ScDocShell, pSh ); 529 530 if( pScSh ) 531 { 532 pScSh->GetTitle(); 533 534 if( pScSh->GetTitle() == aDocName ) 535 { 536 nDoc = i; 537 ScDocument* pDestDoc = pScSh->GetDocument(); 538 nTableCount = pDestDoc->GetTableCount(); 539 bDoIt = pDestDoc->IsDocEditable(); 540 break; 541 } 542 543 i++; // nur die ScDocShell's zaehlen 544 } 545 pSh = SfxObjectShell::GetNext( *pSh ); 546 } 547 } 548 else // Kein Dokumentname -> neues Dokument 549 { 550 nDoc = SC_DOC_NEW; 551 bDoIt = sal_True; 552 } 553 554 if ( bDoIt && nTab >= nTableCount ) // ggf. anhaengen 555 nTab = SC_TAB_APPEND; 556 } 557 else 558 { 559 //CHINA001 ScMoveTableDlg* pDlg = new ScMoveTableDlg( GetDialogParent() ); 560 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 561 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 562 563 AbstractScMoveTableDlg* pDlg = pFact->CreateScMoveTableDlg( GetDialogParent(), RID_SCDLG_MOVETAB ); 564 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 565 566 SCTAB nTableCount = pDoc->GetTableCount(); 567 ScMarkData& rMark = GetViewData()->GetMarkData(); 568 SCTAB nTabSelCount = rMark.GetSelectCount(); 569 570 571 if(nTableCount==nTabSelCount) 572 { 573 pDlg->SetCopyTable(); 574 pDlg->EnableCopyTable(sal_False); 575 } 576 if ( pDlg->Execute() == RET_OK ) 577 { 578 nDoc = pDlg->GetSelectedDocument(); 579 nTab = pDlg->GetSelectedTable(); 580 bCpy = pDlg->GetCopyTable(); 581 bDoIt = sal_True; 582 583 String aFoundDocName; 584 if ( nDoc != SC_DOC_NEW ) 585 { 586 ScDocShell* pSh = ScDocShell::GetShellByNum( nDoc ); 587 if (pSh) 588 { 589 aFoundDocName = pSh->GetTitle(); 590 if ( !pSh->GetDocument()->IsDocEditable() ) 591 { 592 ErrorMessage(STR_READONLYERR); 593 bDoIt = sal_False; 594 } 595 } 596 } 597 rReq.AppendItem( SfxStringItem( FID_TAB_MOVE, aFoundDocName ) ); 598 // Tabelle ist 1-basiert, wenn nicht APPEND 599 SCTAB nBasicTab = ( nTab <= MAXTAB ) ? (nTab+1) : nTab; 600 rReq.AppendItem( SfxUInt16Item( FN_PARAM_1, static_cast<sal_uInt16>(nBasicTab) ) ); 601 rReq.AppendItem( SfxBoolItem( FN_PARAM_2, bCpy ) ); 602 } 603 delete pDlg; 604 } 605 606 if( bDoIt ) 607 { 608 rReq.Done(); // aufzeichnen, solange das Dokument noch aktiv ist 609 610 MoveTable( nDoc, nTab, bCpy ); 611 } 612 } 613 break; 614 615 case FID_DELETE_TABLE: 616 { 617 // Parameter war ueberfluessig, weil die Methode an der Table haengt 618 619 sal_Bool bDoIt = rReq.IsAPI(); 620 if( !bDoIt ) 621 { 622 // wenn's nicht von Basic kommt, nochmal nachfragen: 623 624 #if ENABLE_LAYOUT 625 // Using layout::QueryBox without client code modification is 626 // deprecated, rather add HIG-complient buttons with verbs. 627 #define QueryBox( parent, winbits, question ) layout::QueryBox (parent, question, ScGlobal::GetRscString (STR_UNDO_DELETE_TAB)) 628 #endif /* ENABLE_LAYOUT */ 629 630 bDoIt = ( RET_YES == 631 QueryBox( GetDialogParent(), 632 WinBits( WB_YES_NO | WB_DEF_YES ), 633 ScGlobal::GetRscString(STR_QUERY_DELTAB) 634 ).Execute() ); 635 } 636 if( bDoIt ) 637 { 638 SCTAB nNewTab = nCurrentTab; 639 SCTAB nFirstTab=0; 640 sal_Bool bTabFlag=sal_False; 641 ScMarkData& rMark = pViewData->GetMarkData(); 642 SvShorts TheTabs; 643 for(SCTAB i=0;i<nTabCount;i++) 644 { 645 if(rMark.GetTableSelect(i) &&!pDoc->IsTabProtected(i)) 646 { 647 TheTabs.push_back(i); 648 bTabFlag=sal_True; 649 if(nNewTab==i) nNewTab++; 650 } 651 if(!bTabFlag) nFirstTab=i; 652 } 653 if(nNewTab>=nTabCount) nNewTab=nFirstTab; 654 655 pViewData->SetTabNo(nNewTab); 656 DeleteTables(TheTabs); 657 TheTabs.clear(); 658 rReq.Done(); 659 } 660 } 661 break; 662 663 case FID_TAB_RTL: 664 { 665 ScDocShell* pDocSh = pViewData->GetDocShell(); 666 ScDocFunc aFunc(*pDocSh); 667 sal_Bool bSet = !pDoc->IsLayoutRTL( nCurrentTab ); 668 669 const ScMarkData& rMark = pViewData->GetMarkData(); 670 if ( rMark.GetSelectCount() != 0 ) 671 { 672 // handle several sheets 673 674 ::svl::IUndoManager* pUndoManager = pDocSh->GetUndoManager(); 675 String aUndo = ScGlobal::GetRscString( STR_UNDO_TAB_RTL ); 676 pUndoManager->EnterListAction( aUndo, aUndo ); 677 678 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 679 if ( rMark.GetTableSelect(nTab) ) 680 aFunc.SetLayoutRTL( nTab, bSet, sal_False ); 681 682 pUndoManager->LeaveListAction(); 683 } 684 else 685 aFunc.SetLayoutRTL( nCurrentTab, bSet, sal_False ); 686 } 687 break; 688 689 case FID_TAB_SET_TAB_BG_COLOR: 690 case FID_TAB_MENU_SET_TAB_BG_COLOR: 691 { 692 if ( nSlot == FID_TAB_MENU_SET_TAB_BG_COLOR ) 693 nSlot = FID_TAB_SET_TAB_BG_COLOR; 694 SCTAB nTabNr = pViewData->GetTabNo(); 695 ScMarkData& rMark = pViewData->GetMarkData(); 696 SCTAB nTabSelCount = rMark.GetSelectCount(); 697 if ( !pDoc->IsDocEditable() ) 698 break; 699 700 if ( pDoc->IsTabProtected( nTabNr ) ) // ||nTabSelCount > 1 701 break; 702 703 if( pReqArgs != NULL ) 704 { 705 sal_Bool bDone = sal_False; 706 const SfxPoolItem* pItem; 707 Color aColor; 708 if( IS_AVAILABLE( FN_PARAM_1, &pItem ) ) 709 nTabNr = ((const SfxUInt16Item*)pItem)->GetValue(); 710 711 if( IS_AVAILABLE( nSlot, &pItem ) ) 712 aColor = ((const SvxColorItem*)pItem)->GetValue(); 713 714 if ( nTabSelCount > 1 ) 715 { 716 scoped_ptr<ScUndoTabColorInfo::List> 717 pTabColorList(new ScUndoTabColorInfo::List); 718 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 719 { 720 if ( rMark.GetTableSelect(nTab) && !pDoc->IsTabProtected(nTab) ) 721 { 722 ScUndoTabColorInfo aTabColorInfo(nTab); 723 aTabColorInfo.maNewTabBgColor = aColor; 724 pTabColorList->push_back(aTabColorInfo); 725 } 726 } 727 bDone = SetTabBgColor( *pTabColorList ); 728 } 729 else 730 { 731 bDone = SetTabBgColor( aColor, nCurrentTab ); //ScViewFunc.SetTabBgColor 732 } 733 if( bDone ) 734 { 735 rReq.Done( *pReqArgs ); 736 } 737 } 738 else 739 { 740 sal_uInt16 nRet = RET_OK; /// temp 741 sal_Bool bDone = sal_False; /// temp 742 Color aTabBgColor; 743 Color aNewTabBgColor; 744 745 aTabBgColor = pDoc->GetTabBgColor( nCurrentTab ); 746 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 747 DBG_ASSERT(pFact, "ScAbstractFactory create fail!"); 748 AbstractScTabBgColorDlg* pDlg = pFact->CreateScTabBgColorDlg( 749 GetDialogParent(), 750 String(ScResId(SCSTR_SET_TAB_BG_COLOR)), 751 String(ScResId(SCSTR_NO_TAB_BG_COLOR)), 752 aTabBgColor, 753 CMD_FID_TAB_SET_TAB_BG_COLOR, 754 RID_SCDLG_TAB_BG_COLOR); 755 while ( !bDone && nRet == RET_OK ) 756 { 757 nRet = pDlg->Execute(); 758 if( nRet == RET_OK ) 759 { 760 Color aSelectedColor; 761 pDlg->GetSelectedColor(aSelectedColor); 762 scoped_ptr<ScUndoTabColorInfo::List> 763 pTabColorList(new ScUndoTabColorInfo::List); 764 if ( nTabSelCount > 1 ) 765 { 766 for (SCTAB nTab=0; nTab<nTabCount; nTab++) 767 { 768 if ( rMark.GetTableSelect(nTab) && !pDoc->IsTabProtected(nTab) ) 769 { 770 ScUndoTabColorInfo aTabColorInfo(nTab); 771 aTabColorInfo.maNewTabBgColor = aSelectedColor; 772 pTabColorList->push_back(aTabColorInfo); 773 } 774 } 775 bDone = SetTabBgColor( *pTabColorList ); 776 } 777 else 778 { 779 bDone = SetTabBgColor( aSelectedColor, nCurrentTab ); //ScViewFunc.SetTabBgColor 780 } 781 if ( bDone ) 782 { 783 rReq.AppendItem( SvxColorItem( aTabBgColor, nSlot ) ); 784 rReq.Done(); 785 } 786 else 787 { 788 if( rReq.IsAPI() ) 789 { 790 StarBASIC::Error( SbERR_SETPROP_FAILED ); 791 } 792 } 793 } 794 } 795 delete( pDlg ); 796 } 797 } 798 break; 799 800 case FID_TAB_EVENTS: 801 { 802 ScDocShell* pDocSh = pViewData->GetDocShell(); 803 uno::Reference<container::XNameReplace> xEvents( new ScSheetEventsObj( pDocSh, nCurrentTab ) ); 804 uno::Reference<frame::XFrame> xFrame = GetViewFrame()->GetFrame().GetFrameInterface(); 805 SvxAbstractDialogFactory* pDlgFactory = SvxAbstractDialogFactory::Create(); 806 if (pDlgFactory) 807 { 808 std::auto_ptr<VclAbstractDialog> pDialog( pDlgFactory->CreateSvxMacroAssignDlg( 809 GetDialogParent(), xFrame, false, xEvents, 0 ) ); 810 if ( pDialog.get() && pDialog->Execute() == RET_OK ) 811 { 812 // the dialog modifies the settings directly 813 } 814 } 815 } 816 break; 817 818 default: 819 DBG_ERROR("Unbekannte Message bei ViewShell"); 820 break; 821 } 822 } 823 824 //------------------------------------------------------------------ 825 826 void ScTabViewShell::GetStateTable( SfxItemSet& rSet ) 827 { 828 ScViewData* pViewData = GetViewData(); 829 ScDocument* pDoc = pViewData->GetDocument(); 830 ScDocShell* pDocShell = pViewData->GetDocShell(); 831 ScMarkData& rMark = GetViewData()->GetMarkData(); 832 SCTAB nTab = pViewData->GetTabNo(); 833 834 SCTAB nTabCount = pDoc->GetTableCount(); 835 SCTAB nTabSelCount = rMark.GetSelectCount(); 836 837 SfxWhichIter aIter(rSet); 838 sal_uInt16 nWhich = aIter.FirstWhich(); 839 840 while ( nWhich ) 841 { 842 switch ( nWhich ) 843 { 844 845 case FID_TABLE_VISIBLE: 846 rSet.Put( SfxBoolItem( nWhich, pDoc->IsVisible(nTab) )); 847 break; 848 849 case FID_TABLE_HIDE: 850 { 851 sal_uInt16 nVis = 0; 852 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ ) 853 if (pDoc->IsVisible(i)) 854 ++nVis; 855 856 if ( nVis<2 || !pDoc->IsDocEditable() || nTabSelCount > 1 ) 857 rSet.DisableItem( nWhich ); 858 } 859 break; 860 861 case FID_TABLE_SHOW: 862 { 863 sal_Bool bHasHidden = sal_False; 864 for ( SCTAB i=0; i < nTabCount && !bHasHidden; i++ ) 865 if (!pDoc->IsVisible(i)) 866 bHasHidden = sal_True; 867 if ( !bHasHidden || pDoc->IsDocProtected() || nTabSelCount > 1 ) 868 rSet.DisableItem( nWhich ); 869 } 870 break; 871 872 case FID_DELETE_TABLE: 873 { 874 if ( pDoc->GetChangeTrack() ) 875 rSet.DisableItem( nWhich ); 876 else 877 { 878 sal_uInt16 nVis = 0; 879 for ( SCTAB i=0; i < nTabCount && nVis<2; i++ ) 880 if (pDoc->IsVisible(i)) 881 ++nVis; 882 if ( pDoc->IsTabProtected(nTab) 883 || !pDoc->IsDocEditable() 884 || nVis < 2 885 || nTabSelCount == nTabCount) 886 rSet.DisableItem( nWhich ); 887 } 888 } 889 break; 890 891 case FID_INS_TABLE: 892 case FID_INS_TABLE_EXT: 893 case FID_TAB_APPEND: 894 if ( !pDoc->IsDocEditable() || 895 nTabCount > MAXTAB || 896 ( nWhich == FID_INS_TABLE_EXT && pDocShell && pDocShell->IsDocShared() ) ) 897 rSet.DisableItem( nWhich ); 898 break; 899 900 case FID_TAB_MOVE: 901 if ( !pDoc->IsDocEditable() 902 || pDoc->GetChangeTrack() != NULL 903 || nTabCount > MAXTAB) 904 rSet.DisableItem( nWhich ); 905 break; 906 907 // FID_TAB_MENU_RENAME - "umbenennen" im Menu 908 // FID_TAB_RENAME - "Name"-Property fuer Basic 909 910 case FID_TAB_MENU_RENAME: 911 if ( !pDoc->IsDocEditable() || 912 pDoc->IsTabProtected(nTab) ||nTabSelCount > 1 || 913 ( pDocShell && pDocShell->IsDocShared() ) ) 914 rSet.DisableItem( nWhich ); 915 break; 916 917 case FID_TAB_RENAME: 918 { 919 String aTabName; 920 pDoc->GetName( nTab, aTabName ); 921 922 rSet.Put( SfxStringItem( nWhich, aTabName )); 923 924 } 925 break; 926 927 case FID_TAB_RTL: 928 { 929 SvtLanguageOptions aLangOpt; 930 if ( !aLangOpt.IsCTLFontEnabled() ) 931 rSet.DisableItem( nWhich ); 932 else 933 rSet.Put( SfxBoolItem( nWhich, pDoc->IsLayoutRTL( nTab ) ) ); 934 } 935 break; 936 937 case FID_TAB_MENU_SET_TAB_BG_COLOR: 938 { 939 if ( !pDoc->IsDocEditable() 940 || ( pDocShell && pDocShell->IsDocShared() ) 941 || pDoc->IsTabProtected(nTab) ) 942 rSet.DisableItem( nWhich ); 943 } 944 break; 945 946 case FID_TAB_SET_TAB_BG_COLOR: 947 { 948 Color aColor; 949 aColor = pDoc->GetTabBgColor( nTab ); 950 rSet.Put( SvxColorItem( aColor, nWhich ) ); 951 } 952 break; 953 } 954 nWhich = aIter.NextWhich(); 955 } 956 } 957 958 959 960 961