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 #undef SC_DLLIMPLEMENTATION 32 33 34 35 //------------------------------------------------------------------ 36 37 #include <vcl/msgbox.hxx> 38 39 #include "global.hxx" 40 #include "document.hxx" 41 #include "tabvwsh.hxx" 42 #include "viewdata.hxx" 43 #include "uiitems.hxx" 44 #include "userlist.hxx" 45 #include "rangeutl.hxx" 46 #include "crdlg.hxx" 47 #include "scresid.hxx" 48 #include "sc.hrc" // -> Slot-IDs 49 #include "optdlg.hrc" 50 #include "globstr.hrc" 51 52 #define _TPUSRLST_CXX 53 #include "tpusrlst.hxx" 54 #undef _TPUSRLST_CXX 55 56 //CHINA001 #include "scui_def.hxx" //CHINA001 57 //CHINA001 #include "scresid.hxx" //add by CHINA001 58 //CHINA001 #include "miscdlgs.hrc" //add by CHINA001 59 //CHINA001 60 //CHINA001 #include "scabstdlg.hxx" //CHINA001 61 // STATIC DATA ----------------------------------------------------------- 62 63 #define CR (sal_Unicode)13 64 #define LF (sal_Unicode)10 65 66 static sal_uInt16 pUserListsRanges[] = 67 { 68 SID_SCUSERLISTS, 69 SID_SCUSERLISTS, 70 0 71 }; 72 73 static const sal_Unicode cDelimiter = ','; 74 75 76 //======================================================================== 77 // Benutzerdefinierte Listen: 78 79 80 ScTpUserLists::ScTpUserLists( Window* pParent, 81 const SfxItemSet& rCoreAttrs ) 82 83 : SfxTabPage ( pParent, 84 ScResId( RID_SCPAGE_USERLISTS ), 85 rCoreAttrs ), 86 aFtLists ( this, ScResId( FT_LISTS ) ), 87 aLbLists ( this, ScResId( LB_LISTS ) ), 88 aFtEntries ( this, ScResId( FT_ENTRIES ) ), 89 aEdEntries ( this, ScResId( ED_ENTRIES ) ), 90 aFtCopyFrom ( this, ScResId( FT_COPYFROM ) ), 91 aEdCopyFrom ( this, ScResId( ED_COPYFROM ) ), 92 aBtnNew ( this, ScResId( BTN_NEW ) ), 93 aBtnAdd ( this, ScResId( BTN_ADD ) ), 94 aBtnRemove ( this, ScResId( BTN_REMOVE ) ), 95 aBtnCopy ( this, ScResId( BTN_COPY ) ), 96 aStrQueryRemove ( ScResId( STR_QUERYREMOVE ) ), 97 aStrNew ( aBtnNew.GetText() ), 98 aStrCancel ( ScResId( STR_DISMISS ) ), 99 aStrAdd ( ScResId( SCSTR_ADD ) ), 100 aStrModify ( ScResId( SCSTR_MODIFY ) ), 101 aStrCopyList ( ScResId( STR_COPYLIST ) ), 102 aStrCopyFrom ( ScResId( STR_COPYFROM ) ), 103 aStrCopyErr ( ScResId( STR_COPYERR ) ), 104 // 105 nWhichUserLists ( GetWhich( SID_SCUSERLISTS ) ), 106 pUserLists ( NULL ), 107 pDoc ( NULL ), 108 pViewData ( NULL ), 109 pRangeUtil ( new ScRangeUtil ), 110 bModifyMode ( sal_False ), 111 bCancelMode ( sal_False ), 112 bCopyDone ( sal_False ), 113 nCancelPos ( 0 ) 114 { 115 SetExchangeSupport(); 116 Init(); 117 FreeResource(); 118 } 119 120 // ----------------------------------------------------------------------- 121 122 __EXPORT ScTpUserLists::~ScTpUserLists() 123 { 124 delete pUserLists; 125 delete pRangeUtil; 126 } 127 128 // ----------------------------------------------------------------------- 129 130 void ScTpUserLists::Init() 131 { 132 SfxViewShell* pSh = SfxViewShell::Current(); 133 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, pSh); 134 135 aLbLists.SetSelectHdl ( LINK( this, ScTpUserLists, LbSelectHdl ) ); 136 aBtnNew.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) ); 137 aBtnNew.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) ); 138 aBtnAdd.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) ); 139 aBtnRemove.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) ); 140 aEdEntries.SetModifyHdl ( LINK( this, ScTpUserLists, EdEntriesModHdl ) ); 141 142 143 if ( pViewSh ) 144 { 145 SCTAB nStartTab = 0; 146 SCTAB nEndTab = 0; 147 SCCOL nStartCol = 0; 148 SCROW nStartRow = 0; 149 SCCOL nEndCol = 0; 150 SCROW nEndRow = 0; 151 152 pViewData = pViewSh->GetViewData(); 153 pDoc = pViewData->GetDocument(); 154 155 pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab, 156 nEndCol, nEndRow, nEndTab ); 157 158 PutInOrder( nStartCol, nEndCol ); 159 PutInOrder( nStartRow, nEndRow ); 160 PutInOrder( nStartTab, nEndTab ); 161 162 ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab 163 ).Format( aStrSelectedArea, SCR_ABS_3D, pDoc ); 164 165 aBtnCopy.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) ); 166 aBtnCopy.Enable(); 167 } 168 else 169 { 170 aBtnCopy.Disable(); 171 aFtCopyFrom.Disable(); 172 aEdCopyFrom.Disable(); 173 } 174 175 // aLbLists.GrabFocus(); 176 } 177 178 // ----------------------------------------------------------------------- 179 180 sal_uInt16* __EXPORT ScTpUserLists::GetRanges() 181 { 182 return pUserListsRanges; 183 } 184 185 // ----------------------------------------------------------------------- 186 187 SfxTabPage* __EXPORT ScTpUserLists::Create( Window* pParent, const SfxItemSet& rAttrSet ) 188 { 189 return ( new ScTpUserLists( pParent, rAttrSet ) ); 190 } 191 192 // ----------------------------------------------------------------------- 193 194 void __EXPORT ScTpUserLists::Reset( const SfxItemSet& rCoreAttrs ) 195 { 196 const ScUserListItem& rUserListItem = (const ScUserListItem&) 197 rCoreAttrs.Get( nWhichUserLists ); 198 const ScUserList* pCoreList = rUserListItem.GetUserList(); 199 200 DBG_ASSERT( pCoreList, "UserList not found :-/" ); 201 202 if ( pCoreList ) 203 { 204 if ( !pUserLists ) 205 pUserLists = new ScUserList( *pCoreList ); 206 else 207 *pUserLists = *pCoreList; 208 209 if ( UpdateUserListBox() > 0 ) 210 { 211 aLbLists.SelectEntryPos( 0 ); 212 UpdateEntries( 0 ); 213 } 214 } 215 else if ( !pUserLists ) 216 pUserLists = new ScUserList; 217 218 aEdCopyFrom.SetText( aStrSelectedArea ); 219 220 if ( aLbLists.GetEntryCount() == 0 ) 221 { 222 aFtLists .Disable(); 223 aLbLists .Disable(); 224 aFtEntries .Disable(); 225 aEdEntries .Disable(); 226 aBtnRemove .Disable(); 227 } 228 229 aBtnNew.SetText( aStrNew ); 230 aBtnAdd.SetText( aStrAdd ); 231 aBtnAdd.Disable(); 232 233 if ( !bCopyDone && pViewData ) 234 { 235 aFtCopyFrom .Enable(); 236 aEdCopyFrom .Enable(); 237 aBtnCopy .Enable(); 238 } 239 240 // aLbLists.GrabFocus(); 241 } 242 243 // ----------------------------------------------------------------------- 244 245 sal_Bool __EXPORT ScTpUserLists::FillItemSet( SfxItemSet& rCoreAttrs ) 246 { 247 // Modifikationen noch nicht uebernommen? 248 // -> Click auf Add-Button simulieren 249 250 if ( bModifyMode || bCancelMode ) 251 BtnClickHdl( &aBtnAdd ); 252 253 const ScUserListItem& rUserListItem = (const ScUserListItem&) 254 GetItemSet().Get( nWhichUserLists ); 255 256 ScUserList* pCoreList = rUserListItem.GetUserList(); 257 sal_Bool bDataModified = sal_False; 258 259 if ( (pUserLists == NULL) && (pCoreList == NULL) ) 260 { 261 bDataModified = sal_False; 262 } 263 else if ( pUserLists != NULL ) 264 { 265 if ( pCoreList != NULL ) 266 bDataModified = (*pUserLists != *pCoreList); 267 else 268 bDataModified = sal_True; 269 } 270 271 if ( bDataModified ) 272 { 273 ScUserListItem aULItem( nWhichUserLists ); 274 275 if ( pUserLists ) 276 aULItem.SetUserList( *pUserLists ); 277 278 rCoreAttrs.Put( aULItem ); 279 } 280 281 return bDataModified; 282 } 283 284 // ----------------------------------------------------------------------- 285 286 int __EXPORT ScTpUserLists::DeactivatePage( SfxItemSet* pSetP ) 287 { 288 if ( pSetP ) 289 FillItemSet( *pSetP ); 290 291 return LEAVE_PAGE; 292 } 293 294 // ----------------------------------------------------------------------- 295 296 sal_uInt16 ScTpUserLists::UpdateUserListBox() 297 { 298 aLbLists.Clear(); 299 300 if ( !pUserLists ) return 0; 301 302 //---------------------------------------------------------- 303 304 sal_uInt16 nCount = pUserLists->GetCount(); 305 String aEntry; 306 307 if ( nCount > 0 ) 308 { 309 for ( sal_uInt16 i=0; i<nCount; i++ ) 310 { 311 aEntry = (*pUserLists)[i]->GetString(); 312 DBG_ASSERT( aEntry.Len() > 0, "Empty UserList-entry :-/" ); 313 aLbLists.InsertEntry( aEntry ); 314 } 315 } 316 317 return nCount; 318 } 319 320 // ----------------------------------------------------------------------- 321 322 void ScTpUserLists::UpdateEntries( sal_uInt16 nList ) 323 { 324 if ( !pUserLists ) return; 325 326 //---------------------------------------------------------- 327 328 if ( nList < pUserLists->GetCount() ) 329 { 330 ScUserListData* pList = (*pUserLists)[nList]; 331 sal_uInt16 nSubCount = pList->GetSubCount(); 332 String aEntryListStr; 333 334 for ( sal_uInt16 i=0; i<nSubCount; i++ ) 335 { 336 if ( i!=0 ) 337 aEntryListStr += CR; 338 aEntryListStr += pList->GetSubStr( i ); 339 } 340 341 aEntryListStr.ConvertLineEnd(); 342 aEdEntries.SetText( aEntryListStr ); 343 } 344 else 345 { 346 DBG_ERROR( "Invalid ListIndex :-/" ); 347 } 348 } 349 350 // ----------------------------------------------------------------------- 351 352 void ScTpUserLists::MakeListStr( String& rListStr ) 353 { 354 String aInputStr(rListStr); 355 String aStr; 356 357 xub_StrLen nLen = aStr.Len(); 358 xub_StrLen c = 0; 359 360 aInputStr.ConvertLineEnd( LINEEND_LF ); 361 //aStr.EraseAllChars( ' ' ); 362 363 xub_StrLen nToken=rListStr.GetTokenCount(LF); 364 365 for(xub_StrLen i=0;i<nToken;i++) 366 { 367 String aString=rListStr.GetToken(i,LF); 368 aString.EraseLeadingChars(' '); 369 aString.EraseTrailingChars(' '); 370 aStr+=aString; 371 aStr+=cDelimiter; 372 } 373 374 /* 375 // '\n' durch cDelimiter ersetzen: 376 for ( c=0; 377 (c < nLen) && (nFound != STRING_NOTFOUND); 378 c++ ) 379 { 380 nFound = aStr.Search( LF, nFound ); 381 if ( nFound != STRING_NOTFOUND ) 382 aStr[nFound] = cDelimiter; 383 } 384 */ 385 386 aStr.EraseLeadingChars( cDelimiter ); 387 aStr.EraseTrailingChars( cDelimiter ); 388 nLen = aStr.Len(); 389 390 rListStr.Erase(); 391 392 // Alle Doppelten cDelimiter entfernen: 393 c=0; 394 while ( c < nLen ) 395 { 396 rListStr += aStr.GetChar(c); 397 c++; 398 399 if ( aStr.GetChar(c) == cDelimiter ) 400 { 401 rListStr += aStr.GetChar(c); 402 403 while ( (aStr.GetChar(c) == cDelimiter) && (c < nLen) ) 404 c++; 405 } 406 } 407 408 } 409 410 // ----------------------------------------------------------------------- 411 412 void ScTpUserLists::AddNewList( const String& rEntriesStr ) 413 { 414 String theEntriesStr( rEntriesStr ); 415 416 if ( !pUserLists ) 417 pUserLists = new ScUserList; 418 419 MakeListStr( theEntriesStr ); 420 421 if ( !pUserLists->Insert( new ScUserListData( theEntriesStr ) ) ) 422 { 423 DBG_ERROR( "Entry could not be inserted :-/" ); 424 } 425 } 426 427 // ----------------------------------------------------------------------- 428 429 void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos, 430 const ScRefAddress& rEndPos ) 431 { 432 if ( bCopyDone ) return; 433 434 //---------------------------------------------------------- 435 436 SCTAB nTab = rStartPos.Tab(); 437 SCCOL nStartCol = rStartPos.Col(); 438 SCROW nStartRow = rStartPos.Row(); 439 SCCOL nEndCol = rEndPos.Col(); 440 SCROW nEndRow = rEndPos.Row(); 441 sal_uInt16 nCellDir = SCRET_COLS; 442 sal_Bool bValueIgnored = sal_False; 443 444 if ( (nStartCol != nEndCol) && (nStartRow != nEndRow) ) 445 { 446 nCellDir = ScColOrRowDlg( this, aStrCopyList, aStrCopyFrom ).Execute(); 447 //CHINA001 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); 448 //CHINA001 DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001 449 //CHINA001 450 //CHINA001 VclAbstractDialog* pDlg = pFact->CreateScColOrRowDlg( this, aStrCopyList, aStrCopyFrom,ResId(RID_SCDLG_COLORROW) ); 451 //CHINA001 DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001 452 //CHINA001 nCellDir = pDlg->Execute(); 453 //CHINA001 delete pDlg; //CHINA001 454 } 455 else if ( nStartCol != nEndCol ) 456 nCellDir = SCRET_ROWS; 457 else 458 nCellDir = SCRET_COLS; 459 460 if ( nCellDir != RET_CANCEL ) 461 { 462 String aStrList; 463 String aStrField; 464 465 if ( nCellDir == SCRET_COLS ) 466 { 467 for ( SCCOL col=nStartCol; col<=nEndCol; col++ ) 468 { 469 for ( SCROW row=nStartRow; row<=nEndRow; row++ ) 470 { 471 if ( pDoc->HasStringData( col, row, nTab ) ) 472 { 473 pDoc->GetString( col, row, nTab, aStrField ); 474 475 if ( aStrField.Len() > 0 ) 476 { 477 aStrList += aStrField; 478 aStrList += '\n'; 479 } 480 } 481 else 482 bValueIgnored = sal_True; 483 } 484 if ( aStrList.Len() > 0 ) 485 AddNewList( aStrList ); 486 aStrList.Erase(); 487 } 488 } 489 else 490 { 491 for ( SCROW row=nStartRow; row<=nEndRow; row++ ) 492 { 493 for ( SCCOL col=nStartCol; col<=nEndCol; col++ ) 494 { 495 if ( pDoc->HasStringData( col, row, nTab ) ) 496 { 497 pDoc->GetString( col, row, nTab, aStrField ); 498 499 if ( aStrField.Len() > 0 ) 500 { 501 aStrList += aStrField; 502 aStrList += '\n'; 503 } 504 } 505 else 506 bValueIgnored = sal_True; 507 } 508 if ( aStrList.Len() > 0 ) 509 AddNewList( aStrList ); 510 aStrList.Erase(); 511 } 512 } 513 514 if ( bValueIgnored ) 515 { 516 InfoBox( this, aStrCopyErr ).Execute(); 517 } 518 } 519 520 //---------------------------------------------------------- 521 522 bCopyDone = sal_True; 523 524 } 525 526 // ----------------------------------------------------------------------- 527 528 void ScTpUserLists::ModifyList( sal_uInt16 nSelList, 529 const String& rEntriesStr ) 530 { 531 if ( !pUserLists ) return; 532 533 //---------------------------------------------------------- 534 535 String theEntriesStr( rEntriesStr ); 536 537 MakeListStr( theEntriesStr ); 538 539 (*pUserLists)[nSelList]->SetString( theEntriesStr ); 540 } 541 542 // ----------------------------------------------------------------------- 543 544 void ScTpUserLists::RemoveList( sal_uInt16 nList ) 545 { 546 if ( pUserLists ) pUserLists->AtFree( nList ); 547 } 548 549 //----------------------------------------------------------------------- 550 // Handler: 551 //--------- 552 553 IMPL_LINK( ScTpUserLists, LbSelectHdl, ListBox*, pLb ) 554 { 555 if ( pLb == &aLbLists ) 556 { 557 sal_uInt16 nSelPos = aLbLists.GetSelectEntryPos(); 558 if ( nSelPos != LISTBOX_ENTRY_NOTFOUND ) 559 { 560 if ( !aFtEntries.IsEnabled() ) aFtEntries.Enable(); 561 if ( !aEdEntries.IsEnabled() ) aEdEntries.Enable(); 562 if ( !aBtnRemove.IsEnabled() ) aBtnRemove.Enable(); 563 if ( aBtnAdd.IsEnabled() ) aBtnAdd.Disable(); 564 565 UpdateEntries( nSelPos ); 566 } 567 } 568 569 return 0; 570 } 571 572 // ----------------------------------------------------------------------- 573 574 IMPL_LINK( ScTpUserLists, BtnClickHdl, PushButton*, pBtn ) 575 { 576 if ( pBtn == &aBtnNew ) 577 { 578 if ( !bCancelMode ) 579 { 580 nCancelPos = ( aLbLists.GetEntryCount() > 0 ) 581 ? aLbLists.GetSelectEntryPos() 582 : 0; 583 aLbLists.SetNoSelection(); 584 aFtLists.Disable(); 585 aLbLists.Disable(); 586 aFtEntries.Enable(); 587 aEdEntries.Enable(); 588 aEdEntries.SetText( EMPTY_STRING ); 589 aEdEntries.GrabFocus(); 590 aBtnAdd.Disable(); 591 aBtnRemove.Disable(); 592 //----------------------------- 593 if ( aBtnCopy.IsEnabled() ) 594 { 595 aBtnCopy.Disable(); 596 aFtCopyFrom.Disable(); 597 aEdCopyFrom.Disable(); 598 } 599 aBtnNew.SetText( aStrCancel ); 600 bCancelMode = sal_True; 601 } 602 else // if ( bCancelMode ) 603 { 604 if ( aLbLists.GetEntryCount() > 0 ) 605 { 606 aLbLists.SelectEntryPos( nCancelPos ); 607 LbSelectHdl( &aLbLists ); 608 aFtLists.Enable(); 609 aLbLists.Enable(); 610 } 611 else 612 { 613 aFtEntries.Disable(); 614 aEdEntries.Disable(); 615 aEdEntries.SetText( EMPTY_STRING ); 616 aBtnRemove.Disable(); 617 } 618 aBtnAdd.Disable(); 619 //----------------------------- 620 if ( pViewData && !bCopyDone ) 621 { 622 aBtnCopy.Enable(); 623 aFtCopyFrom.Enable(); 624 aEdCopyFrom.Enable(); 625 } 626 aBtnNew.SetText( aStrNew ); 627 bCancelMode = sal_False; 628 bModifyMode = sal_False; 629 } 630 } 631 else if ( pBtn == &aBtnAdd ) 632 { 633 String theEntriesStr( aEdEntries.GetText() ); 634 635 if ( !bModifyMode ) 636 { 637 if ( theEntriesStr.Len() > 0 ) 638 { 639 AddNewList( theEntriesStr ); 640 UpdateUserListBox(); 641 aLbLists.SelectEntryPos( aLbLists.GetEntryCount()-1 ); 642 LbSelectHdl( &aLbLists ); 643 aFtLists.Enable(); 644 aLbLists.Enable(); 645 } 646 else 647 { 648 if ( aLbLists.GetEntryCount() > 0 ) 649 { 650 aLbLists.SelectEntryPos( nCancelPos ); 651 LbSelectHdl( &aLbLists ); 652 aLbLists.Enable(); 653 aLbLists.Enable(); 654 } 655 } 656 657 aBtnAdd.Disable(); 658 aBtnRemove.Enable(); 659 aBtnNew.SetText( aStrNew ); 660 bCancelMode = sal_False; 661 } 662 else // if ( bModifyMode ) 663 { 664 sal_uInt16 nSelList = aLbLists.GetSelectEntryPos(); 665 666 DBG_ASSERT( nSelList != LISTBOX_ENTRY_NOTFOUND, "Modify without List :-/" ); 667 668 if ( theEntriesStr.Len() > 0 ) 669 { 670 ModifyList( nSelList, theEntriesStr ); 671 UpdateUserListBox(); 672 aLbLists.SelectEntryPos( nSelList ); 673 } 674 else 675 { 676 aLbLists.SelectEntryPos( 0 ); 677 LbSelectHdl( &aLbLists ); 678 } 679 680 aBtnNew.SetText( aStrNew ); bCancelMode = sal_False; 681 aBtnAdd.SetText( aStrAdd ); bModifyMode = sal_False; 682 aBtnAdd.Disable(); 683 aBtnRemove.Enable(); 684 aFtLists.Enable(); 685 aLbLists.Enable(); 686 } 687 688 if ( pViewData && !bCopyDone ) 689 { 690 aBtnCopy.Enable(); 691 aFtCopyFrom.Enable(); 692 aEdCopyFrom.Enable(); 693 } 694 } 695 else if ( pBtn == &aBtnRemove ) 696 { 697 if ( aLbLists.GetEntryCount() > 0 ) 698 { 699 sal_uInt16 nRemovePos = aLbLists.GetSelectEntryPos(); 700 String aMsg ( aStrQueryRemove.GetToken( 0, '#' ) ); 701 702 aMsg += aLbLists.GetEntry( nRemovePos ); 703 aMsg += aStrQueryRemove.GetToken( 1, '#' ); 704 705 706 if ( RET_YES == QueryBox( this, 707 WinBits( WB_YES_NO | WB_DEF_YES ), 708 aMsg 709 ).Execute() ) 710 { 711 RemoveList( nRemovePos ); 712 UpdateUserListBox(); 713 714 if ( aLbLists.GetEntryCount() > 0 ) 715 { 716 aLbLists.SelectEntryPos( 717 ( nRemovePos >= aLbLists.GetEntryCount() ) 718 ? aLbLists.GetEntryCount()-1 719 : nRemovePos ); 720 LbSelectHdl( &aLbLists ); 721 } 722 else 723 { 724 aFtLists.Disable(); 725 aLbLists.Disable(); 726 aFtEntries.Disable(); 727 aEdEntries.Disable(); 728 aEdEntries.SetText( EMPTY_STRING ); 729 aBtnRemove.Disable(); 730 } 731 } 732 733 if ( pViewData && !bCopyDone && !aBtnCopy.IsEnabled() ) 734 { 735 aBtnCopy.Enable(); 736 aFtCopyFrom.Enable(); 737 aEdCopyFrom.Enable(); 738 } 739 } 740 } 741 else if ( pViewData && (pBtn == &aBtnCopy) ) 742 { 743 if ( bCopyDone ) 744 return 0; 745 746 //----------------------------------------------------------- 747 748 ScRefAddress theStartPos; 749 ScRefAddress theEndPos; 750 String theAreaStr( aEdCopyFrom.GetText() ); 751 sal_Bool bAreaOk = sal_False; 752 753 if ( theAreaStr.Len() > 0 ) 754 { 755 bAreaOk = pRangeUtil->IsAbsArea( theAreaStr, 756 pDoc, 757 pViewData->GetTabNo(), 758 &theAreaStr, 759 &theStartPos, 760 &theEndPos, 761 pDoc->GetAddressConvention() ); 762 if ( !bAreaOk ) 763 { 764 bAreaOk = pRangeUtil->IsAbsPos( theAreaStr, 765 pDoc, 766 pViewData->GetTabNo(), 767 &theAreaStr, 768 &theStartPos, 769 pDoc->GetAddressConvention() ); 770 theEndPos = theStartPos; 771 } 772 } 773 774 if ( bAreaOk ) 775 { 776 CopyListFromArea( theStartPos, theEndPos ); 777 UpdateUserListBox(); 778 aLbLists.SelectEntryPos( aLbLists.GetEntryCount()-1 ); 779 LbSelectHdl( &aLbLists ); 780 aEdCopyFrom .SetText( theAreaStr ); 781 aEdCopyFrom .Disable(); 782 aBtnCopy .Disable(); 783 aFtCopyFrom .Disable(); 784 } 785 else 786 { 787 ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ), 788 ScGlobal::GetRscString( STR_INVALID_TABREF ) 789 ).Execute(); 790 aEdCopyFrom.GrabFocus(); 791 aEdCopyFrom.SetSelection( Selection( 0, SELECTION_MAX ) ); 792 } 793 } 794 795 return 0; 796 } 797 798 // ----------------------------------------------------------------------- 799 800 IMPL_LINK( ScTpUserLists, EdEntriesModHdl, MultiLineEdit*, pEd ) 801 { 802 if ( pEd != &aEdEntries ) 803 return 0; 804 805 //----------------------------------------------------------- 806 807 if ( aBtnCopy.IsEnabled() ) 808 { 809 aBtnCopy .Disable(); 810 aFtCopyFrom .Disable(); 811 aEdCopyFrom .Disable(); 812 } 813 814 if ( aEdEntries.GetText().Len() > 0 ) 815 { 816 if ( !bCancelMode && !bModifyMode ) 817 { 818 aBtnNew.SetText( aStrCancel ); bCancelMode = sal_True; 819 aBtnAdd.SetText( aStrModify ); bModifyMode = sal_True; 820 aBtnAdd.Enable(); 821 aBtnRemove.Disable(); 822 aFtLists.Disable(); 823 aLbLists.Disable(); 824 } 825 else // if ( bCancelMode || bModifyMode ) 826 { 827 if ( !aBtnAdd.IsEnabled() ) aBtnAdd.Enable(); 828 } 829 } 830 else 831 { 832 if ( aBtnAdd.IsEnabled() ) aBtnAdd.Disable(); 833 } 834 835 return 0; 836 } 837 838 839 840