LCOV - code coverage report
Current view: top level - sc/source/ui/optdlg - tpusrlst.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 397 0.0 %
Date: 2014-04-11 Functions: 0 23 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #undef SC_DLLIMPLEMENTATION
      22             : 
      23             : #include <comphelper/string.hxx>
      24             : #include <vcl/msgbox.hxx>
      25             : 
      26             : #include "global.hxx"
      27             : #include "document.hxx"
      28             : #include "tabvwsh.hxx"
      29             : #include "viewdata.hxx"
      30             : #include "uiitems.hxx"
      31             : #include "userlist.hxx"
      32             : #include "rangeutl.hxx"
      33             : #include "crdlg.hxx"
      34             : #include "scresid.hxx"
      35             : #include "sc.hrc"
      36             : #include "optdlg.hrc"
      37             : #include "globstr.hrc"
      38             : 
      39             : #define _TPUSRLST_CXX
      40             : #include "tpusrlst.hxx"
      41             : #undef _TPUSRLST_CXX
      42             : 
      43             : // STATIC DATA -----------------------------------------------------------
      44             : 
      45             : #define CR  (sal_Unicode)13
      46             : #define LF  (sal_Unicode)10
      47             : 
      48             : static const sal_Unicode cDelimiter = ',';
      49             : 
      50             : 
      51             : // Benutzerdefinierte Listen:
      52             : 
      53             : 
      54           0 : ScTpUserLists::ScTpUserLists( Window*               pParent,
      55             :                               const SfxItemSet&     rCoreAttrs )
      56             : 
      57             :     :   SfxTabPage      ( pParent,
      58             :                           "OptSortLists", "modules/scalc/ui/optsortlists.ui",
      59             :                           rCoreAttrs ),
      60           0 :         aStrQueryRemove ( ScGlobal::GetRscString( STR_QUERYREMOVE ) ),
      61           0 :         aStrCopyList    ( ScGlobal::GetRscString( STR_COPYLIST ) ),
      62           0 :         aStrCopyFrom    ( ScGlobal::GetRscString( STR_COPYFROM ) ),
      63           0 :         aStrCopyErr     ( ScGlobal::GetRscString( STR_COPYERR ) ),
      64           0 :         nWhichUserLists ( GetWhich( SID_SCUSERLISTS ) ),
      65             :         pUserLists      ( NULL ),
      66             :         pDoc            ( NULL ),
      67             :         pViewData       ( NULL ),
      68           0 :         pRangeUtil      ( new ScRangeUtil ),
      69             :         bModifyMode     ( false ),
      70             :         bCancelMode     ( false ),
      71             :         bCopyDone       ( false ),
      72           0 :         nCancelPos      ( 0 )
      73             : {
      74           0 :     get(mpFtLists, "listslabel");
      75           0 :     get(mpLbLists, "lists");
      76           0 :     get(mpFtEntries, "entrieslabel");
      77           0 :     get(mpEdEntries, "entries");
      78           0 :     get(mpFtCopyFrom, "copyfromlabel");
      79           0 :     get(mpEdCopyFrom, "copyfrom");
      80           0 :     get(mpBtnNew, "new");
      81           0 :     get(mpBtnDiscard, "discard");
      82           0 :     get(mpBtnAdd, "add");
      83           0 :     get(mpBtnModify, "modify");
      84           0 :     get(mpBtnRemove, "delete");
      85           0 :     get(mpBtnCopy, "copy");
      86             : 
      87           0 :     SetExchangeSupport();
      88           0 :     Init();
      89           0 :     Reset(rCoreAttrs);
      90           0 : }
      91             : 
      92           0 : ScTpUserLists::~ScTpUserLists()
      93             : {
      94           0 :     delete pUserLists;
      95           0 :     delete pRangeUtil;
      96           0 : }
      97             : 
      98           0 : void ScTpUserLists::Init()
      99             : {
     100           0 :     SfxViewShell*   pSh = SfxViewShell::Current();
     101           0 :     ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, pSh);
     102             : 
     103           0 :     mpLbLists->SetSelectHdl   ( LINK( this, ScTpUserLists, LbSelectHdl ) );
     104           0 :     mpBtnNew->SetClickHdl     ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     105           0 :     mpBtnDiscard->SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     106           0 :     mpBtnAdd->SetClickHdl     ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     107           0 :     mpBtnModify->SetClickHdl  ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     108           0 :     mpBtnRemove->SetClickHdl  ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     109           0 :     mpEdEntries->SetModifyHdl ( LINK( this, ScTpUserLists, EdEntriesModHdl ) );
     110             : 
     111           0 :     if ( pViewSh )
     112             :     {
     113           0 :         SCTAB   nStartTab   = 0;
     114           0 :         SCTAB   nEndTab     = 0;
     115           0 :         SCCOL   nStartCol   = 0;
     116           0 :         SCROW   nStartRow   = 0;
     117           0 :         SCCOL   nEndCol     = 0;
     118           0 :         SCROW   nEndRow     = 0;
     119             : 
     120           0 :         pViewData = pViewSh->GetViewData();
     121           0 :         pDoc = pViewData->GetDocument();
     122             : 
     123             :         pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
     124           0 :                                   nEndCol,   nEndRow,  nEndTab );
     125             : 
     126           0 :         PutInOrder( nStartCol, nEndCol );
     127           0 :         PutInOrder( nStartRow, nEndRow );
     128           0 :         PutInOrder( nStartTab, nEndTab );
     129             : 
     130           0 :         aStrSelectedArea = ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab
     131           0 :                 ).Format(SCR_ABS_3D, pDoc);
     132             : 
     133           0 :         mpBtnCopy->SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     134           0 :         mpBtnCopy->Enable();
     135             :     }
     136             :     else
     137             :     {
     138           0 :         mpBtnCopy->Disable();
     139           0 :         mpFtCopyFrom->Disable();
     140           0 :         mpEdCopyFrom->Disable();
     141             :     }
     142             : 
     143           0 : }
     144             : 
     145           0 : SfxTabPage* ScTpUserLists::Create( Window* pParent, const SfxItemSet& rAttrSet )
     146             : {
     147           0 :     return ( new ScTpUserLists( pParent, rAttrSet ) );
     148             : }
     149             : 
     150           0 : void ScTpUserLists::Reset( const SfxItemSet& rCoreAttrs )
     151             : {
     152             :     const ScUserListItem& rUserListItem = (const ScUserListItem&)
     153           0 :                                            rCoreAttrs.Get( nWhichUserLists );
     154           0 :     const ScUserList*     pCoreList     = rUserListItem.GetUserList();
     155             : 
     156             :     OSL_ENSURE( pCoreList, "UserList not found :-/" );
     157             : 
     158           0 :     if ( pCoreList )
     159             :     {
     160           0 :         if ( !pUserLists )
     161           0 :             pUserLists = new ScUserList( *pCoreList );
     162             :         else
     163           0 :             *pUserLists = *pCoreList;
     164             : 
     165           0 :         if ( UpdateUserListBox() > 0 )
     166             :         {
     167           0 :             mpLbLists->SelectEntryPos( 0 );
     168           0 :             UpdateEntries( 0 );
     169             :         }
     170             :     }
     171           0 :     else if ( !pUserLists )
     172           0 :         pUserLists = new ScUserList;
     173             : 
     174           0 :     mpEdCopyFrom->SetText( aStrSelectedArea );
     175             : 
     176           0 :     if ( mpLbLists->GetEntryCount() == 0 )
     177             :     {
     178           0 :         mpFtLists->Disable();
     179           0 :         mpLbLists->Disable();
     180           0 :         mpFtEntries->Disable();
     181           0 :         mpEdEntries->Disable();
     182           0 :         mpBtnRemove->Disable();
     183             :     }
     184             : 
     185           0 :     mpBtnNew->Show();
     186           0 :     mpBtnDiscard->Hide();
     187           0 :     mpBtnAdd->Show();
     188           0 :     mpBtnModify->Hide();
     189           0 :     mpBtnAdd->Disable();
     190           0 :     mpBtnModify->Disable();
     191             : 
     192           0 :     if ( !bCopyDone && pViewData )
     193             :     {
     194           0 :         mpFtCopyFrom->Enable();
     195           0 :         mpEdCopyFrom->Enable();
     196           0 :         mpBtnCopy->Enable();
     197             :     }
     198           0 : }
     199             : 
     200           0 : bool ScTpUserLists::FillItemSet( SfxItemSet& rCoreAttrs )
     201             : {
     202             :     // Modifikationen noch nicht uebernommen?
     203             :     // -> Click auf Add-Button simulieren
     204             : 
     205           0 :     if ( bModifyMode || bCancelMode )
     206           0 :         BtnClickHdl( mpBtnAdd );
     207             : 
     208             :     const ScUserListItem& rUserListItem = (const ScUserListItem&)
     209           0 :                                            GetItemSet().Get( nWhichUserLists );
     210             : 
     211           0 :     ScUserList* pCoreList       = rUserListItem.GetUserList();
     212           0 :     sal_Bool        bDataModified   = false;
     213             : 
     214           0 :     if ( (pUserLists == NULL) && (pCoreList == NULL) )
     215             :     {
     216           0 :         bDataModified = false;
     217             :     }
     218           0 :     else if ( pUserLists != NULL )
     219             :     {
     220           0 :         if ( pCoreList != NULL )
     221           0 :             bDataModified = (*pUserLists != *pCoreList);
     222             :         else
     223           0 :             bDataModified = sal_True;
     224             :     }
     225             : 
     226           0 :     if ( bDataModified )
     227             :     {
     228           0 :         ScUserListItem aULItem( nWhichUserLists );
     229             : 
     230           0 :         if ( pUserLists )
     231           0 :             aULItem.SetUserList( *pUserLists );
     232             : 
     233           0 :         rCoreAttrs.Put( aULItem );
     234             :     }
     235             : 
     236           0 :     return bDataModified;
     237             : }
     238             : 
     239           0 : int ScTpUserLists::DeactivatePage( SfxItemSet* pSetP )
     240             : {
     241           0 :     if ( pSetP )
     242           0 :         FillItemSet( *pSetP );
     243             : 
     244           0 :     return LEAVE_PAGE;
     245             : }
     246             : 
     247           0 : size_t ScTpUserLists::UpdateUserListBox()
     248             : {
     249           0 :     mpLbLists->Clear();
     250             : 
     251           0 :     if ( !pUserLists ) return 0;
     252             : 
     253           0 :     size_t nCount = pUserLists->size();
     254           0 :     OUString  aEntry;
     255             : 
     256           0 :     for ( size_t i=0; i<nCount; ++i )
     257             :     {
     258           0 :         aEntry = (*pUserLists)[i]->GetString();
     259             :         OSL_ENSURE( !aEntry.isEmpty(), "Empty UserList-entry :-/" );
     260           0 :         mpLbLists->InsertEntry( aEntry );
     261             :     }
     262             : 
     263           0 :     return nCount;
     264             : }
     265             : 
     266           0 : void ScTpUserLists::UpdateEntries( size_t nList )
     267             : {
     268           0 :     if ( !pUserLists ) return;
     269             : 
     270           0 :     if ( nList < pUserLists->size() )
     271             :     {
     272           0 :         const ScUserListData* pList = (*pUserLists)[nList];
     273           0 :         sal_uInt16          nSubCount = pList->GetSubCount();
     274           0 :         OUString          aEntryListStr;
     275             : 
     276           0 :         for ( sal_uInt16 i=0; i<nSubCount; i++ )
     277             :         {
     278           0 :             if ( i!=0 )
     279           0 :                 aEntryListStr += OUString(CR);
     280           0 :             aEntryListStr += pList->GetSubStr(i);
     281             :         }
     282             : 
     283           0 :         mpEdEntries->SetText(convertLineEnd(aEntryListStr, GetSystemLineEnd()));
     284             :     }
     285             :     else
     286             :     {
     287             :         OSL_FAIL( "Invalid ListIndex :-/" );
     288             :     }
     289             : }
     290             : 
     291           0 : void ScTpUserLists::MakeListStr( OUString& rListStr )
     292             : {
     293           0 :     OUString  aStr;
     294             : 
     295           0 :     sal_Int32 nToken = comphelper::string::getTokenCount(rListStr, LF);
     296             : 
     297           0 :     for(sal_Int32 i=0; i<nToken; i++)
     298             :     {
     299           0 :         OUString aString = comphelper::string::strip(rListStr.getToken(i, LF), ' ');
     300           0 :         aStr += aString;
     301           0 :         aStr += OUString(cDelimiter);
     302           0 :     }
     303             : 
     304           0 :     aStr = comphelper::string::strip(aStr, cDelimiter);
     305           0 :     sal_Int32 nLen = aStr.getLength();
     306             : 
     307           0 :     rListStr = "";
     308             : 
     309             :     // Alle Doppelten cDelimiter entfernen:
     310           0 :     sal_Int32 c = 0;
     311           0 :     while ( c < nLen )
     312             :     {
     313           0 :         rListStr += OUString(aStr[c]);
     314           0 :         ++c;
     315             : 
     316           0 :         if ((c < nLen) && (aStr[c] == cDelimiter))
     317             :         {
     318           0 :             rListStr += OUString(aStr[c]);
     319             : 
     320           0 :             while ((c < nLen) && (aStr[c] == cDelimiter))
     321           0 :                 ++c;
     322             :         }
     323           0 :     }
     324             : 
     325           0 : }
     326             : 
     327           0 : void ScTpUserLists::AddNewList( const OUString& rEntriesStr )
     328             : {
     329           0 :     OUString theEntriesStr( rEntriesStr );
     330             : 
     331           0 :     if ( !pUserLists )
     332           0 :         pUserLists = new ScUserList;
     333             : 
     334           0 :     MakeListStr( theEntriesStr );
     335             : 
     336           0 :     pUserLists->push_back(new ScUserListData(theEntriesStr));
     337           0 : }
     338             : 
     339           0 : void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos,
     340             :                                       const ScRefAddress& rEndPos )
     341             : {
     342           0 :     if ( bCopyDone ) return;
     343             : 
     344           0 :     SCTAB   nTab            = rStartPos.Tab();
     345           0 :     SCCOL   nStartCol       = rStartPos.Col();
     346           0 :     SCROW   nStartRow       = rStartPos.Row();
     347           0 :     SCCOL   nEndCol         = rEndPos.Col();
     348           0 :     SCROW   nEndRow         = rEndPos.Row();
     349           0 :     sal_uInt16  nCellDir        = SCRET_COLS;
     350           0 :     sal_Bool    bValueIgnored   = false;
     351             : 
     352           0 :     if ( (nStartCol != nEndCol) && (nStartRow != nEndRow) )
     353             :     {
     354           0 :         nCellDir = ScColOrRowDlg( this, aStrCopyList, aStrCopyFrom ).Execute();
     355             :     }
     356           0 :     else if ( nStartCol != nEndCol )
     357           0 :         nCellDir = SCRET_ROWS;
     358             :     else
     359           0 :         nCellDir = SCRET_COLS;
     360             : 
     361           0 :     if ( nCellDir != RET_CANCEL )
     362             :     {
     363           0 :         OUString  aStrList;
     364           0 :         OUString  aStrField;
     365             : 
     366           0 :         if ( nCellDir == SCRET_COLS )
     367             :         {
     368           0 :             for ( SCCOL col=nStartCol; col<=nEndCol; col++ )
     369             :             {
     370           0 :                 for ( SCROW row=nStartRow; row<=nEndRow; row++ )
     371             :                 {
     372           0 :                     if ( pDoc->HasStringData( col, row, nTab ) )
     373             :                     {
     374           0 :                         aStrField = pDoc->GetString(col, row, nTab);
     375             : 
     376           0 :                         if ( !aStrField.isEmpty() )
     377             :                         {
     378           0 :                             aStrList += aStrField;
     379           0 :                             aStrList += "\n";
     380             :                         }
     381             :                     }
     382             :                     else
     383           0 :                         bValueIgnored = sal_True;
     384             :                 }
     385           0 :                 if ( !aStrList.isEmpty() )
     386           0 :                     AddNewList( aStrList );
     387           0 :                 aStrList = "";
     388             :             }
     389             :         }
     390             :         else
     391             :         {
     392           0 :             for ( SCROW row=nStartRow; row<=nEndRow; row++ )
     393             :             {
     394           0 :                 for ( SCCOL col=nStartCol; col<=nEndCol; col++ )
     395             :                 {
     396           0 :                     if ( pDoc->HasStringData( col, row, nTab ) )
     397             :                     {
     398           0 :                         aStrField = pDoc->GetString(col, row, nTab);
     399             : 
     400           0 :                         if ( !aStrField.isEmpty() )
     401             :                         {
     402           0 :                             aStrList += aStrField;
     403           0 :                             aStrList += "\n";
     404             :                         }
     405             :                     }
     406             :                     else
     407           0 :                         bValueIgnored = sal_True;
     408             :                 }
     409           0 :                 if ( !aStrList.isEmpty() )
     410           0 :                     AddNewList( aStrList );
     411           0 :                 aStrList = "";
     412             :             }
     413             :         }
     414             : 
     415           0 :         if ( bValueIgnored )
     416             :         {
     417           0 :             InfoBox( this, aStrCopyErr ).Execute();
     418           0 :         }
     419             :     }
     420             : 
     421           0 :     bCopyDone = true;
     422             : 
     423             : }
     424             : 
     425           0 : void ScTpUserLists::ModifyList( size_t            nSelList,
     426             :                                 const OUString&   rEntriesStr )
     427             : {
     428           0 :     if ( !pUserLists ) return;
     429             : 
     430           0 :     OUString theEntriesStr( rEntriesStr );
     431             : 
     432           0 :     MakeListStr( theEntriesStr );
     433             : 
     434           0 :     (*pUserLists)[nSelList]->SetString( theEntriesStr );
     435             : }
     436             : 
     437           0 : void ScTpUserLists::RemoveList( size_t nList )
     438             : {
     439           0 :     if (pUserLists && nList < pUserLists->size())
     440             :     {
     441           0 :         ScUserList::iterator itr = pUserLists->begin();
     442           0 :         ::std::advance(itr, nList);
     443           0 :         pUserLists->erase(itr);
     444             :     }
     445           0 : }
     446             : 
     447             : 
     448             : // Handler:
     449             : 
     450             : 
     451           0 : IMPL_LINK( ScTpUserLists, LbSelectHdl, ListBox*, pLb )
     452             : {
     453           0 :     if ( pLb == mpLbLists )
     454             :     {
     455           0 :         sal_Int32 nSelPos = mpLbLists->GetSelectEntryPos();
     456           0 :         if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
     457             :         {
     458           0 :             if ( !mpFtEntries->IsEnabled() )  mpFtEntries->Enable();
     459           0 :             if ( !mpEdEntries->IsEnabled() )  mpEdEntries->Enable();
     460           0 :             if ( !mpBtnRemove->IsEnabled() )  mpBtnRemove->Enable();
     461           0 :             if ( mpBtnAdd->IsEnabled() )
     462             :             {
     463           0 :                 mpBtnAdd->Disable();
     464           0 :                 mpBtnModify->Disable();
     465             :             }
     466             : 
     467           0 :             UpdateEntries( nSelPos );
     468             :         }
     469             :     }
     470             : 
     471           0 :     return 0;
     472             : }
     473             : 
     474           0 : IMPL_LINK( ScTpUserLists, BtnClickHdl, PushButton*, pBtn )
     475             : {
     476           0 :     if ( pBtn == mpBtnNew || pBtn == mpBtnDiscard )
     477             :     {
     478           0 :         if ( !bCancelMode )
     479             :         {
     480           0 :             nCancelPos = ( mpLbLists->GetEntryCount() > 0 )
     481           0 :                             ? mpLbLists->GetSelectEntryPos()
     482           0 :                             : 0;
     483           0 :             mpLbLists->SetNoSelection();
     484           0 :             mpFtLists->Disable();
     485           0 :             mpLbLists->Disable();
     486           0 :             mpFtEntries->Enable();
     487           0 :             mpEdEntries->Enable();
     488           0 :             mpEdEntries->SetText( EMPTY_OUSTRING );
     489           0 :             mpEdEntries->GrabFocus();
     490           0 :             mpBtnAdd->Disable();
     491           0 :             mpBtnModify->Disable();
     492           0 :             mpBtnRemove->Disable();
     493             : 
     494           0 :             if ( mpBtnCopy->IsEnabled() )
     495             :             {
     496           0 :                 mpBtnCopy->Disable();
     497           0 :                 mpFtCopyFrom->Disable();
     498           0 :                 mpEdCopyFrom->Disable();
     499             :             }
     500           0 :             mpBtnNew->Hide();
     501           0 :             mpBtnDiscard->Show();
     502           0 :             bCancelMode = true;
     503             :         }
     504             :         else // if ( bCancelMode )
     505             :         {
     506           0 :             if ( mpLbLists->GetEntryCount() > 0 )
     507             :             {
     508           0 :                 mpLbLists->SelectEntryPos( nCancelPos );
     509           0 :                 LbSelectHdl( mpLbLists );
     510           0 :                 mpFtLists->Enable();
     511           0 :                 mpLbLists->Enable();
     512             :             }
     513             :             else
     514             :             {
     515           0 :                 mpFtEntries->Disable();
     516           0 :                 mpEdEntries->Disable();
     517           0 :                 mpEdEntries->SetText( EMPTY_OUSTRING );
     518           0 :                 mpBtnRemove->Disable();
     519             :             }
     520           0 :             mpBtnAdd->Disable();
     521           0 :             mpBtnModify->Disable();
     522             : 
     523           0 :             if ( pViewData && !bCopyDone )
     524             :             {
     525           0 :                 mpBtnCopy->Enable();
     526           0 :                 mpFtCopyFrom->Enable();
     527           0 :                 mpEdCopyFrom->Enable();
     528             :             }
     529           0 :             mpBtnNew->Show();
     530           0 :             mpBtnDiscard->Hide();
     531           0 :             bCancelMode = false;
     532           0 :             bModifyMode = false;
     533             :         }
     534             :     }
     535           0 :     else if (pBtn == mpBtnAdd || pBtn == mpBtnModify)
     536             :     {
     537           0 :         OUString theEntriesStr( mpEdEntries->GetText() );
     538             : 
     539           0 :         if ( !bModifyMode )
     540             :         {
     541           0 :             if ( !theEntriesStr.isEmpty() )
     542             :             {
     543           0 :                 AddNewList( theEntriesStr );
     544           0 :                 UpdateUserListBox();
     545           0 :                 mpLbLists->SelectEntryPos( mpLbLists->GetEntryCount()-1 );
     546           0 :                 LbSelectHdl( mpLbLists );
     547           0 :                 mpFtLists->Enable();
     548           0 :                 mpLbLists->Enable();
     549             :             }
     550             :             else
     551             :             {
     552           0 :                 if ( mpLbLists->GetEntryCount() > 0 )
     553             :                 {
     554           0 :                     mpLbLists->SelectEntryPos( nCancelPos );
     555           0 :                     LbSelectHdl( mpLbLists );
     556           0 :                     mpLbLists->Enable();
     557           0 :                     mpLbLists->Enable();
     558             :                 }
     559             :             }
     560             : 
     561           0 :             mpBtnAdd->Disable();
     562           0 :             mpBtnModify->Disable();
     563           0 :             mpBtnRemove->Enable();
     564           0 :             mpBtnNew->Show();
     565           0 :             mpBtnDiscard->Hide();
     566           0 :             bCancelMode = false;
     567             :         }
     568             :         else // if ( bModifyMode )
     569             :         {
     570           0 :             sal_Int32 nSelList = mpLbLists->GetSelectEntryPos();
     571             : 
     572             :             OSL_ENSURE( nSelList != LISTBOX_ENTRY_NOTFOUND, "Modify without List :-/" );
     573             : 
     574           0 :             if ( !theEntriesStr.isEmpty() )
     575             :             {
     576           0 :                 ModifyList( nSelList, theEntriesStr );
     577           0 :                 UpdateUserListBox();
     578           0 :                 mpLbLists->SelectEntryPos( nSelList );
     579             :             }
     580             :             else
     581             :             {
     582           0 :                 mpLbLists->SelectEntryPos( 0 );
     583           0 :                 LbSelectHdl( mpLbLists );
     584             :             }
     585             : 
     586           0 :             mpBtnNew->Show();
     587           0 :             mpBtnDiscard->Hide();
     588           0 :             bCancelMode = false;
     589           0 :             mpBtnAdd->Show();
     590           0 :             mpBtnModify->Show();
     591           0 :             mpBtnAdd->Disable();
     592           0 :             mpBtnModify->Disable();
     593           0 :             bModifyMode = false;
     594           0 :             mpBtnRemove->Enable();
     595           0 :             mpFtLists->Enable();
     596           0 :             mpLbLists->Enable();
     597             :         }
     598             : 
     599           0 :         if ( pViewData && !bCopyDone )
     600             :         {
     601           0 :             mpBtnCopy->Enable();
     602           0 :             mpFtCopyFrom->Enable();
     603           0 :             mpEdCopyFrom->Enable();
     604           0 :         }
     605             :     }
     606           0 :     else if ( pBtn == mpBtnRemove )
     607             :     {
     608           0 :         if ( mpLbLists->GetEntryCount() > 0 )
     609             :         {
     610           0 :             sal_Int32 nRemovePos   = mpLbLists->GetSelectEntryPos();
     611           0 :             OUString aMsg         ( aStrQueryRemove.getToken( 0, '#' ) );
     612             : 
     613           0 :             aMsg += mpLbLists->GetEntry( nRemovePos );
     614           0 :             aMsg += aStrQueryRemove.getToken( 1, '#' );
     615             : 
     616             : 
     617           0 :             if ( RET_YES == QueryBox( this,
     618             :                                       WinBits( WB_YES_NO | WB_DEF_YES ),
     619             :                                       aMsg
     620           0 :                                      ).Execute() )
     621             :             {
     622           0 :                 RemoveList( nRemovePos );
     623           0 :                 UpdateUserListBox();
     624             : 
     625           0 :                 if ( mpLbLists->GetEntryCount() > 0 )
     626             :                 {
     627             :                     mpLbLists->SelectEntryPos(
     628           0 :                         ( nRemovePos >= mpLbLists->GetEntryCount() )
     629           0 :                             ? mpLbLists->GetEntryCount()-1
     630           0 :                             : nRemovePos );
     631           0 :                     LbSelectHdl( mpLbLists );
     632             :                 }
     633             :                 else
     634             :                 {
     635           0 :                     mpFtLists->Disable();
     636           0 :                     mpLbLists->Disable();
     637           0 :                     mpFtEntries->Disable();
     638           0 :                     mpEdEntries->Disable();
     639           0 :                     mpEdEntries->SetText( EMPTY_OUSTRING );
     640           0 :                     mpBtnRemove->Disable();
     641             :                 }
     642             :             }
     643             : 
     644           0 :             if ( pViewData && !bCopyDone && !mpBtnCopy->IsEnabled() )
     645             :             {
     646           0 :                 mpBtnCopy->Enable();
     647           0 :                 mpFtCopyFrom->Enable();
     648           0 :                 mpEdCopyFrom->Enable();
     649           0 :             }
     650             :         }
     651             :     }
     652           0 :     else if ( pViewData && (pBtn == mpBtnCopy) )
     653             :     {
     654           0 :         if ( bCopyDone )
     655           0 :             return 0;
     656             : 
     657           0 :         ScRefAddress theStartPos;
     658           0 :         ScRefAddress theEndPos;
     659           0 :         OUString     theAreaStr( mpEdCopyFrom->GetText() );
     660           0 :         sal_Bool     bAreaOk = false;
     661             : 
     662           0 :         if ( !theAreaStr.isEmpty() )
     663             :         {
     664             :             bAreaOk = pRangeUtil->IsAbsArea( theAreaStr,
     665             :                                              pDoc,
     666           0 :                                              pViewData->GetTabNo(),
     667             :                                              &theAreaStr,
     668             :                                              &theStartPos,
     669             :                                              &theEndPos,
     670           0 :                                              pDoc->GetAddressConvention() );
     671           0 :             if ( !bAreaOk )
     672             :             {
     673             :                 bAreaOk = pRangeUtil->IsAbsPos(  theAreaStr,
     674             :                                                  pDoc,
     675           0 :                                                  pViewData->GetTabNo(),
     676             :                                                  &theAreaStr,
     677             :                                                  &theStartPos,
     678           0 :                                                  pDoc->GetAddressConvention() );
     679           0 :                 theEndPos = theStartPos;
     680             :             }
     681             :         }
     682             : 
     683           0 :         if ( bAreaOk )
     684             :         {
     685           0 :             CopyListFromArea( theStartPos, theEndPos );
     686           0 :             UpdateUserListBox();
     687           0 :             mpLbLists->SelectEntryPos( mpLbLists->GetEntryCount()-1 );
     688           0 :             LbSelectHdl( mpLbLists );
     689           0 :             mpEdCopyFrom->SetText( theAreaStr );
     690           0 :             mpEdCopyFrom->Disable();
     691           0 :             mpBtnCopy->Disable();
     692           0 :             mpFtCopyFrom->Disable();
     693             :         }
     694             :         else
     695             :         {
     696             :             ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ),
     697           0 :                       ScGlobal::GetRscString( STR_INVALID_TABREF )
     698           0 :                     ).Execute();
     699           0 :             mpEdCopyFrom->GrabFocus();
     700           0 :             mpEdCopyFrom->SetSelection( Selection( 0, SELECTION_MAX ) );
     701           0 :         }
     702             :     }
     703             : 
     704           0 :     return 0;
     705             : }
     706             : 
     707           0 : IMPL_LINK( ScTpUserLists, EdEntriesModHdl, VclMultiLineEdit*, pEd )
     708             : {
     709           0 :     if ( pEd != mpEdEntries )
     710           0 :         return 0;
     711             : 
     712           0 :     if ( mpBtnCopy->IsEnabled() )
     713             :     {
     714           0 :         mpBtnCopy->Disable();
     715           0 :         mpFtCopyFrom->Disable();
     716           0 :         mpEdCopyFrom->Disable();
     717             :     }
     718             : 
     719           0 :     if ( !mpEdEntries->GetText().isEmpty() )
     720             :     {
     721           0 :         if ( !bCancelMode && !bModifyMode )
     722             :         {
     723           0 :             mpBtnNew->Hide();
     724           0 :             mpBtnDiscard->Show();
     725           0 :             bCancelMode = true;
     726           0 :             mpBtnAdd->Hide();
     727           0 :             mpBtnAdd->Enable();
     728           0 :             mpBtnModify->Show();
     729           0 :             mpBtnModify->Enable();
     730           0 :             bModifyMode = true;
     731           0 :             mpBtnRemove->Disable();
     732           0 :             mpFtLists->Disable();
     733           0 :             mpLbLists->Disable();
     734             :         }
     735             :         else // if ( bCancelMode || bModifyMode )
     736             :         {
     737           0 :             if ( !mpBtnAdd->IsEnabled() )
     738             :             {
     739           0 :                 mpBtnAdd->Enable();
     740           0 :                 mpBtnModify->Enable();
     741             :             }
     742             :         }
     743             :     }
     744             :     else
     745             :     {
     746           0 :         if ( mpBtnAdd->IsEnabled() )
     747             :         {
     748           0 :             mpBtnAdd->Disable();
     749           0 :             mpBtnModify->Disable();
     750             :         }
     751             :     }
     752             : 
     753           0 :     return 0;
     754           0 : }
     755             : 
     756             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10