LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/optdlg - tpusrlst.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 396 0.0 %
Date: 2013-07-09 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"       // -> Slot-IDs
      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             : // -----------------------------------------------------------------------
      93             : 
      94           0 : ScTpUserLists::~ScTpUserLists()
      95             : {
      96           0 :     delete pUserLists;
      97           0 :     delete pRangeUtil;
      98           0 : }
      99             : 
     100             : // -----------------------------------------------------------------------
     101             : 
     102           0 : void ScTpUserLists::Init()
     103             : {
     104           0 :     SfxViewShell*   pSh = SfxViewShell::Current();
     105           0 :     ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, pSh);
     106             : 
     107           0 :     mpLbLists->SetSelectHdl   ( LINK( this, ScTpUserLists, LbSelectHdl ) );
     108           0 :     mpBtnNew->SetClickHdl     ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     109           0 :     mpBtnDiscard->SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     110           0 :     mpBtnAdd->SetClickHdl     ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     111           0 :     mpBtnModify->SetClickHdl  ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     112           0 :     mpBtnRemove->SetClickHdl  ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     113           0 :     mpEdEntries->SetModifyHdl ( LINK( this, ScTpUserLists, EdEntriesModHdl ) );
     114             : 
     115           0 :     if ( pViewSh )
     116             :     {
     117           0 :         SCTAB   nStartTab   = 0;
     118           0 :         SCTAB   nEndTab     = 0;
     119           0 :         SCCOL   nStartCol   = 0;
     120           0 :         SCROW   nStartRow   = 0;
     121           0 :         SCCOL   nEndCol     = 0;
     122           0 :         SCROW   nEndRow     = 0;
     123             : 
     124           0 :         pViewData = pViewSh->GetViewData();
     125           0 :         pDoc = pViewData->GetDocument();
     126             : 
     127             :         pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
     128           0 :                                   nEndCol,   nEndRow,  nEndTab );
     129             : 
     130           0 :         PutInOrder( nStartCol, nEndCol );
     131           0 :         PutInOrder( nStartRow, nEndRow );
     132           0 :         PutInOrder( nStartTab, nEndTab );
     133             : 
     134             :         ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab
     135           0 :                 ).Format( aStrSelectedArea, SCR_ABS_3D, pDoc );
     136             : 
     137           0 :         mpBtnCopy->SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
     138           0 :         mpBtnCopy->Enable();
     139             :     }
     140             :     else
     141             :     {
     142           0 :         mpBtnCopy->Disable();
     143           0 :         mpFtCopyFrom->Disable();
     144           0 :         mpEdCopyFrom->Disable();
     145             :     }
     146             : 
     147           0 : }
     148             : 
     149             : // -----------------------------------------------------------------------
     150             : 
     151           0 : SfxTabPage* ScTpUserLists::Create( Window* pParent, const SfxItemSet& rAttrSet )
     152             : {
     153           0 :     return ( new ScTpUserLists( pParent, rAttrSet ) );
     154             : }
     155             : 
     156             : // -----------------------------------------------------------------------
     157             : 
     158           0 : void ScTpUserLists::Reset( const SfxItemSet& rCoreAttrs )
     159             : {
     160             :     const ScUserListItem& rUserListItem = (const ScUserListItem&)
     161           0 :                                            rCoreAttrs.Get( nWhichUserLists );
     162           0 :     const ScUserList*     pCoreList     = rUserListItem.GetUserList();
     163             : 
     164             :     OSL_ENSURE( pCoreList, "UserList not found :-/" );
     165             : 
     166           0 :     if ( pCoreList )
     167             :     {
     168           0 :         if ( !pUserLists )
     169           0 :             pUserLists = new ScUserList( *pCoreList );
     170             :         else
     171           0 :             *pUserLists = *pCoreList;
     172             : 
     173           0 :         if ( UpdateUserListBox() > 0 )
     174             :         {
     175           0 :             mpLbLists->SelectEntryPos( 0 );
     176           0 :             UpdateEntries( 0 );
     177             :         }
     178             :     }
     179           0 :     else if ( !pUserLists )
     180           0 :         pUserLists = new ScUserList;
     181             : 
     182           0 :     mpEdCopyFrom->SetText( aStrSelectedArea );
     183             : 
     184           0 :     if ( mpLbLists->GetEntryCount() == 0 )
     185             :     {
     186           0 :         mpFtLists->Disable();
     187           0 :         mpLbLists->Disable();
     188           0 :         mpFtEntries->Disable();
     189           0 :         mpEdEntries->Disable();
     190           0 :         mpBtnRemove->Disable();
     191             :     }
     192             : 
     193           0 :     mpBtnNew->Show();
     194           0 :     mpBtnDiscard->Hide();
     195           0 :     mpBtnAdd->Show();
     196           0 :     mpBtnModify->Hide();
     197           0 :     mpBtnAdd->Disable();
     198           0 :     mpBtnModify->Disable();
     199             : 
     200           0 :     if ( !bCopyDone && pViewData )
     201             :     {
     202           0 :         mpFtCopyFrom->Enable();
     203           0 :         mpEdCopyFrom->Enable();
     204           0 :         mpBtnCopy->Enable();
     205             :     }
     206           0 : }
     207             : 
     208             : // -----------------------------------------------------------------------
     209             : 
     210           0 : sal_Bool ScTpUserLists::FillItemSet( SfxItemSet& rCoreAttrs )
     211             : {
     212             :     // Modifikationen noch nicht uebernommen?
     213             :     // -> Click auf Add-Button simulieren
     214             : 
     215           0 :     if ( bModifyMode || bCancelMode )
     216           0 :         BtnClickHdl( mpBtnAdd );
     217             : 
     218             :     const ScUserListItem& rUserListItem = (const ScUserListItem&)
     219           0 :                                            GetItemSet().Get( nWhichUserLists );
     220             : 
     221           0 :     ScUserList* pCoreList       = rUserListItem.GetUserList();
     222           0 :     sal_Bool        bDataModified   = false;
     223             : 
     224           0 :     if ( (pUserLists == NULL) && (pCoreList == NULL) )
     225             :     {
     226           0 :         bDataModified = false;
     227             :     }
     228           0 :     else if ( pUserLists != NULL )
     229             :     {
     230           0 :         if ( pCoreList != NULL )
     231           0 :             bDataModified = (*pUserLists != *pCoreList);
     232             :         else
     233           0 :             bDataModified = sal_True;
     234             :     }
     235             : 
     236           0 :     if ( bDataModified )
     237             :     {
     238           0 :         ScUserListItem aULItem( nWhichUserLists );
     239             : 
     240           0 :         if ( pUserLists )
     241           0 :             aULItem.SetUserList( *pUserLists );
     242             : 
     243           0 :         rCoreAttrs.Put( aULItem );
     244             :     }
     245             : 
     246           0 :     return bDataModified;
     247             : }
     248             : 
     249             : // -----------------------------------------------------------------------
     250             : 
     251           0 : int ScTpUserLists::DeactivatePage( SfxItemSet* pSetP )
     252             : {
     253           0 :     if ( pSetP )
     254           0 :         FillItemSet( *pSetP );
     255             : 
     256           0 :     return LEAVE_PAGE;
     257             : }
     258             : 
     259             : // -----------------------------------------------------------------------
     260             : 
     261           0 : sal_uInt16 ScTpUserLists::UpdateUserListBox()
     262             : {
     263           0 :     mpLbLists->Clear();
     264             : 
     265           0 :     if ( !pUserLists ) return 0;
     266             : 
     267             :     //----------------------------------------------------------
     268             : 
     269           0 :     size_t nCount = pUserLists->size();
     270           0 :     String  aEntry;
     271             : 
     272           0 :     for ( size_t i=0; i<nCount; ++i )
     273             :     {
     274           0 :         aEntry = (*pUserLists)[i]->GetString();
     275             :         OSL_ENSURE( aEntry.Len() > 0, "Empty UserList-entry :-/" );
     276           0 :         mpLbLists->InsertEntry( aEntry );
     277             :     }
     278             : 
     279           0 :     return nCount;
     280             : }
     281             : 
     282             : // -----------------------------------------------------------------------
     283             : 
     284           0 : void ScTpUserLists::UpdateEntries( size_t nList )
     285             : {
     286           0 :     if ( !pUserLists ) return;
     287             : 
     288             :     //----------------------------------------------------------
     289             : 
     290           0 :     if ( nList < pUserLists->size() )
     291             :     {
     292           0 :         const ScUserListData* pList = (*pUserLists)[nList];
     293           0 :         sal_uInt16          nSubCount = pList->GetSubCount();
     294           0 :         String          aEntryListStr;
     295             : 
     296           0 :         for ( sal_uInt16 i=0; i<nSubCount; i++ )
     297             :         {
     298           0 :             if ( i!=0 )
     299           0 :                 aEntryListStr += CR;
     300           0 :             aEntryListStr += String(pList->GetSubStr(i));
     301             :         }
     302             : 
     303           0 :         mpEdEntries->SetText(convertLineEnd(aEntryListStr, GetSystemLineEnd()));
     304             :     }
     305             :     else
     306             :     {
     307             :         OSL_FAIL( "Invalid ListIndex :-/" );
     308             :     }
     309             : }
     310             : 
     311             : // -----------------------------------------------------------------------
     312             : 
     313           0 : void ScTpUserLists::MakeListStr( String& rListStr )
     314             : {
     315           0 :     String  aStr;
     316             : 
     317           0 :     xub_StrLen nToken = comphelper::string::getTokenCount(rListStr, LF);
     318             : 
     319           0 :     for(xub_StrLen i=0;i<nToken;i++)
     320             :     {
     321           0 :         OUString aString = comphelper::string::strip(rListStr.GetToken(i, LF), ' ');
     322           0 :         aStr+=aString;
     323           0 :         aStr+=cDelimiter;
     324           0 :     }
     325             : 
     326           0 :     aStr = comphelper::string::strip(aStr, cDelimiter);
     327           0 :     xub_StrLen nLen = aStr.Len();
     328             : 
     329           0 :     rListStr.Erase();
     330             : 
     331             :     // Alle Doppelten cDelimiter entfernen:
     332           0 :     xub_StrLen c = 0;
     333           0 :     while ( c < nLen )
     334             :     {
     335           0 :         rListStr += aStr.GetChar(c);
     336           0 :         c++;
     337             : 
     338           0 :         if ( aStr.GetChar(c) == cDelimiter )
     339             :         {
     340           0 :             rListStr += aStr.GetChar(c);
     341             : 
     342           0 :             while ( (aStr.GetChar(c) == cDelimiter) && (c < nLen) )
     343           0 :                 c++;
     344             :         }
     345           0 :     }
     346             : 
     347           0 : }
     348             : 
     349             : // -----------------------------------------------------------------------
     350             : 
     351           0 : void ScTpUserLists::AddNewList( const String& rEntriesStr )
     352             : {
     353           0 :     String theEntriesStr( rEntriesStr );
     354             : 
     355           0 :     if ( !pUserLists )
     356           0 :         pUserLists = new ScUserList;
     357             : 
     358           0 :     MakeListStr( theEntriesStr );
     359             : 
     360           0 :     pUserLists->push_back(new ScUserListData(theEntriesStr));
     361           0 : }
     362             : 
     363             : // -----------------------------------------------------------------------
     364             : 
     365           0 : void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos,
     366             :                                       const ScRefAddress& rEndPos )
     367             : {
     368           0 :     if ( bCopyDone ) return;
     369             : 
     370             :     //----------------------------------------------------------
     371             : 
     372           0 :     SCTAB   nTab            = rStartPos.Tab();
     373           0 :     SCCOL   nStartCol       = rStartPos.Col();
     374           0 :     SCROW   nStartRow       = rStartPos.Row();
     375           0 :     SCCOL   nEndCol         = rEndPos.Col();
     376           0 :     SCROW   nEndRow         = rEndPos.Row();
     377           0 :     sal_uInt16  nCellDir        = SCRET_COLS;
     378           0 :     sal_Bool    bValueIgnored   = false;
     379             : 
     380           0 :     if ( (nStartCol != nEndCol) && (nStartRow != nEndRow) )
     381             :     {
     382           0 :         nCellDir = ScColOrRowDlg( this, aStrCopyList, aStrCopyFrom ).Execute();
     383             :     }
     384           0 :     else if ( nStartCol != nEndCol )
     385           0 :         nCellDir = SCRET_ROWS;
     386             :     else
     387           0 :         nCellDir = SCRET_COLS;
     388             : 
     389           0 :     if ( nCellDir != RET_CANCEL )
     390             :     {
     391           0 :         String  aStrList;
     392           0 :         String  aStrField;
     393             : 
     394           0 :         if ( nCellDir == SCRET_COLS )
     395             :         {
     396           0 :             for ( SCCOL col=nStartCol; col<=nEndCol; col++ )
     397             :             {
     398           0 :                 for ( SCROW row=nStartRow; row<=nEndRow; row++ )
     399             :                 {
     400           0 :                     if ( pDoc->HasStringData( col, row, nTab ) )
     401             :                     {
     402           0 :                         aStrField = pDoc->GetString(col, row, nTab);
     403             : 
     404           0 :                         if ( aStrField.Len() > 0 )
     405             :                         {
     406           0 :                             aStrList += aStrField;
     407           0 :                             aStrList += '\n';
     408             :                         }
     409             :                     }
     410             :                     else
     411           0 :                         bValueIgnored = sal_True;
     412             :                 }
     413           0 :                 if ( aStrList.Len() > 0 )
     414           0 :                     AddNewList( aStrList );
     415           0 :                 aStrList.Erase();
     416             :             }
     417             :         }
     418             :         else
     419             :         {
     420           0 :             for ( SCROW row=nStartRow; row<=nEndRow; row++ )
     421             :             {
     422           0 :                 for ( SCCOL col=nStartCol; col<=nEndCol; col++ )
     423             :                 {
     424           0 :                     if ( pDoc->HasStringData( col, row, nTab ) )
     425             :                     {
     426           0 :                         aStrField = pDoc->GetString(col, row, nTab);
     427             : 
     428           0 :                         if ( aStrField.Len() > 0 )
     429             :                         {
     430           0 :                             aStrList += aStrField;
     431           0 :                             aStrList += '\n';
     432             :                         }
     433             :                     }
     434             :                     else
     435           0 :                         bValueIgnored = sal_True;
     436             :                 }
     437           0 :                 if ( aStrList.Len() > 0 )
     438           0 :                     AddNewList( aStrList );
     439           0 :                 aStrList.Erase();
     440             :             }
     441             :         }
     442             : 
     443           0 :         if ( bValueIgnored )
     444             :         {
     445           0 :             InfoBox( this, aStrCopyErr ).Execute();
     446           0 :         }
     447             :     }
     448             : 
     449             :     //----------------------------------------------------------
     450             : 
     451           0 :     bCopyDone = sal_True;
     452             : 
     453             : }
     454             : 
     455             : // -----------------------------------------------------------------------
     456             : 
     457           0 : void ScTpUserLists::ModifyList( sal_uInt16          nSelList,
     458             :                                 const String&   rEntriesStr )
     459             : {
     460           0 :     if ( !pUserLists ) return;
     461             : 
     462             :     //----------------------------------------------------------
     463             : 
     464           0 :     String theEntriesStr( rEntriesStr );
     465             : 
     466           0 :     MakeListStr( theEntriesStr );
     467             : 
     468           0 :     (*pUserLists)[nSelList]->SetString( theEntriesStr );
     469             : }
     470             : 
     471             : // -----------------------------------------------------------------------
     472             : 
     473           0 : void ScTpUserLists::RemoveList( size_t nList )
     474             : {
     475           0 :     if (pUserLists && nList < pUserLists->size())
     476             :     {
     477           0 :         ScUserList::iterator itr = pUserLists->begin();
     478           0 :         ::std::advance(itr, nList);
     479           0 :         pUserLists->erase(itr);
     480             :     }
     481           0 : }
     482             : 
     483             : //-----------------------------------------------------------------------
     484             : // Handler:
     485             : //---------
     486             : 
     487           0 : IMPL_LINK( ScTpUserLists, LbSelectHdl, ListBox*, pLb )
     488             : {
     489           0 :     if ( pLb == mpLbLists )
     490             :     {
     491           0 :         sal_uInt16 nSelPos = mpLbLists->GetSelectEntryPos();
     492           0 :         if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
     493             :         {
     494           0 :             if ( !mpFtEntries->IsEnabled() )  mpFtEntries->Enable();
     495           0 :             if ( !mpEdEntries->IsEnabled() )  mpEdEntries->Enable();
     496           0 :             if ( !mpBtnRemove->IsEnabled() )  mpBtnRemove->Enable();
     497           0 :             if ( mpBtnAdd->IsEnabled() )
     498             :             {
     499           0 :                 mpBtnAdd->Disable();
     500           0 :                 mpBtnModify->Disable();
     501             :             }
     502             : 
     503           0 :             UpdateEntries( nSelPos );
     504             :         }
     505             :     }
     506             : 
     507           0 :     return 0;
     508             : }
     509             : 
     510             : // -----------------------------------------------------------------------
     511             : 
     512           0 : IMPL_LINK( ScTpUserLists, BtnClickHdl, PushButton*, pBtn )
     513             : {
     514           0 :     if ( pBtn == mpBtnNew || pBtn == mpBtnDiscard )
     515             :     {
     516           0 :         if ( !bCancelMode )
     517             :         {
     518           0 :             nCancelPos = ( mpLbLists->GetEntryCount() > 0 )
     519           0 :                             ? mpLbLists->GetSelectEntryPos()
     520           0 :                             : 0;
     521           0 :             mpLbLists->SetNoSelection();
     522           0 :             mpFtLists->Disable();
     523           0 :             mpLbLists->Disable();
     524           0 :             mpFtEntries->Enable();
     525           0 :             mpEdEntries->Enable();
     526           0 :             mpEdEntries->SetText( EMPTY_STRING );
     527           0 :             mpEdEntries->GrabFocus();
     528           0 :             mpBtnAdd->Disable();
     529           0 :             mpBtnModify->Disable();
     530           0 :             mpBtnRemove->Disable();
     531             :             //-----------------------------
     532           0 :             if ( mpBtnCopy->IsEnabled() )
     533             :             {
     534           0 :                 mpBtnCopy->Disable();
     535           0 :                 mpFtCopyFrom->Disable();
     536           0 :                 mpEdCopyFrom->Disable();
     537             :             }
     538           0 :             mpBtnNew->Hide();
     539           0 :             mpBtnDiscard->Show();
     540           0 :             bCancelMode = sal_True;
     541             :         }
     542             :         else // if ( bCancelMode )
     543             :         {
     544           0 :             if ( mpLbLists->GetEntryCount() > 0 )
     545             :             {
     546           0 :                 mpLbLists->SelectEntryPos( nCancelPos );
     547           0 :                 LbSelectHdl( mpLbLists );
     548           0 :                 mpFtLists->Enable();
     549           0 :                 mpLbLists->Enable();
     550             :             }
     551             :             else
     552             :             {
     553           0 :                 mpFtEntries->Disable();
     554           0 :                 mpEdEntries->Disable();
     555           0 :                 mpEdEntries->SetText( EMPTY_STRING );
     556           0 :                 mpBtnRemove->Disable();
     557             :             }
     558           0 :             mpBtnAdd->Disable();
     559           0 :             mpBtnModify->Disable();
     560             :             //-----------------------------
     561           0 :             if ( pViewData && !bCopyDone )
     562             :             {
     563           0 :                 mpBtnCopy->Enable();
     564           0 :                 mpFtCopyFrom->Enable();
     565           0 :                 mpEdCopyFrom->Enable();
     566             :             }
     567           0 :             mpBtnNew->Show();
     568           0 :             mpBtnDiscard->Hide();
     569           0 :             bCancelMode = false;
     570           0 :             bModifyMode = false;
     571             :         }
     572             :     }
     573           0 :     else if (pBtn == mpBtnAdd || pBtn == mpBtnModify)
     574             :     {
     575           0 :         String theEntriesStr( mpEdEntries->GetText() );
     576             : 
     577           0 :         if ( !bModifyMode )
     578             :         {
     579           0 :             if ( theEntriesStr.Len() > 0 )
     580             :             {
     581           0 :                 AddNewList( theEntriesStr );
     582           0 :                 UpdateUserListBox();
     583           0 :                 mpLbLists->SelectEntryPos( mpLbLists->GetEntryCount()-1 );
     584           0 :                 LbSelectHdl( mpLbLists );
     585           0 :                 mpFtLists->Enable();
     586           0 :                 mpLbLists->Enable();
     587             :             }
     588             :             else
     589             :             {
     590           0 :                 if ( mpLbLists->GetEntryCount() > 0 )
     591             :                 {
     592           0 :                     mpLbLists->SelectEntryPos( nCancelPos );
     593           0 :                     LbSelectHdl( mpLbLists );
     594           0 :                     mpLbLists->Enable();
     595           0 :                     mpLbLists->Enable();
     596             :                 }
     597             :             }
     598             : 
     599           0 :             mpBtnAdd->Disable();
     600           0 :             mpBtnModify->Disable();
     601           0 :             mpBtnRemove->Enable();
     602           0 :             mpBtnNew->Show();
     603           0 :             mpBtnDiscard->Hide();
     604           0 :             bCancelMode = false;
     605             :         }
     606             :         else // if ( bModifyMode )
     607             :         {
     608           0 :             sal_uInt16 nSelList = mpLbLists->GetSelectEntryPos();
     609             : 
     610             :             OSL_ENSURE( nSelList != LISTBOX_ENTRY_NOTFOUND, "Modify without List :-/" );
     611             : 
     612           0 :             if ( theEntriesStr.Len() > 0 )
     613             :             {
     614           0 :                 ModifyList( nSelList, theEntriesStr );
     615           0 :                 UpdateUserListBox();
     616           0 :                 mpLbLists->SelectEntryPos( nSelList );
     617             :             }
     618             :             else
     619             :             {
     620           0 :                 mpLbLists->SelectEntryPos( 0 );
     621           0 :                 LbSelectHdl( mpLbLists );
     622             :             }
     623             : 
     624           0 :             mpBtnNew->Show();
     625           0 :             mpBtnDiscard->Hide();
     626           0 :             bCancelMode = false;
     627           0 :             mpBtnAdd->Show();
     628           0 :             mpBtnModify->Show();
     629           0 :             mpBtnAdd->Disable();
     630           0 :             mpBtnModify->Disable();
     631           0 :             bModifyMode = false;
     632           0 :             mpBtnRemove->Enable();
     633           0 :             mpFtLists->Enable();
     634           0 :             mpLbLists->Enable();
     635             :         }
     636             : 
     637           0 :         if ( pViewData && !bCopyDone )
     638             :         {
     639           0 :             mpBtnCopy->Enable();
     640           0 :             mpFtCopyFrom->Enable();
     641           0 :             mpEdCopyFrom->Enable();
     642           0 :         }
     643             :     }
     644           0 :     else if ( pBtn == mpBtnRemove )
     645             :     {
     646           0 :         if ( mpLbLists->GetEntryCount() > 0 )
     647             :         {
     648           0 :             sal_uInt16 nRemovePos   = mpLbLists->GetSelectEntryPos();
     649           0 :             String aMsg         ( aStrQueryRemove.GetToken( 0, '#' ) );
     650             : 
     651           0 :             aMsg += mpLbLists->GetEntry( nRemovePos );
     652           0 :             aMsg += aStrQueryRemove.GetToken( 1, '#' );
     653             : 
     654             : 
     655           0 :             if ( RET_YES == QueryBox( this,
     656             :                                       WinBits( WB_YES_NO | WB_DEF_YES ),
     657             :                                       aMsg
     658           0 :                                      ).Execute() )
     659             :             {
     660           0 :                 RemoveList( nRemovePos );
     661           0 :                 UpdateUserListBox();
     662             : 
     663           0 :                 if ( mpLbLists->GetEntryCount() > 0 )
     664             :                 {
     665             :                     mpLbLists->SelectEntryPos(
     666           0 :                         ( nRemovePos >= mpLbLists->GetEntryCount() )
     667           0 :                             ? mpLbLists->GetEntryCount()-1
     668           0 :                             : nRemovePos );
     669           0 :                     LbSelectHdl( mpLbLists );
     670             :                 }
     671             :                 else
     672             :                 {
     673           0 :                     mpFtLists->Disable();
     674           0 :                     mpLbLists->Disable();
     675           0 :                     mpFtEntries->Disable();
     676           0 :                     mpEdEntries->Disable();
     677           0 :                     mpEdEntries->SetText( EMPTY_STRING );
     678           0 :                     mpBtnRemove->Disable();
     679             :                 }
     680             :             }
     681             : 
     682           0 :             if ( pViewData && !bCopyDone && !mpBtnCopy->IsEnabled() )
     683             :             {
     684           0 :                 mpBtnCopy->Enable();
     685           0 :                 mpFtCopyFrom->Enable();
     686           0 :                 mpEdCopyFrom->Enable();
     687           0 :             }
     688             :         }
     689             :     }
     690           0 :     else if ( pViewData && (pBtn == mpBtnCopy) )
     691             :     {
     692           0 :         if ( bCopyDone )
     693           0 :             return 0;
     694             : 
     695             :         //-----------------------------------------------------------
     696             : 
     697           0 :         ScRefAddress theStartPos;
     698           0 :         ScRefAddress theEndPos;
     699           0 :         String       theAreaStr( mpEdCopyFrom->GetText() );
     700           0 :         sal_Bool        bAreaOk = false;
     701             : 
     702           0 :         if ( theAreaStr.Len() > 0 )
     703             :         {
     704             :             bAreaOk = pRangeUtil->IsAbsArea( theAreaStr,
     705             :                                              pDoc,
     706           0 :                                              pViewData->GetTabNo(),
     707             :                                              &theAreaStr,
     708             :                                              &theStartPos,
     709             :                                              &theEndPos,
     710           0 :                                              pDoc->GetAddressConvention() );
     711           0 :             if ( !bAreaOk )
     712             :             {
     713             :                 bAreaOk = pRangeUtil->IsAbsPos(  theAreaStr,
     714             :                                                  pDoc,
     715           0 :                                                  pViewData->GetTabNo(),
     716             :                                                  &theAreaStr,
     717             :                                                  &theStartPos,
     718           0 :                                                  pDoc->GetAddressConvention() );
     719           0 :                 theEndPos = theStartPos;
     720             :             }
     721             :         }
     722             : 
     723           0 :         if ( bAreaOk )
     724             :         {
     725           0 :             CopyListFromArea( theStartPos, theEndPos );
     726           0 :             UpdateUserListBox();
     727           0 :             mpLbLists->SelectEntryPos( mpLbLists->GetEntryCount()-1 );
     728           0 :             LbSelectHdl( mpLbLists );
     729           0 :             mpEdCopyFrom->SetText( theAreaStr );
     730           0 :             mpEdCopyFrom->Disable();
     731           0 :             mpBtnCopy->Disable();
     732           0 :             mpFtCopyFrom->Disable();
     733             :         }
     734             :         else
     735             :         {
     736             :             ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ),
     737           0 :                       ScGlobal::GetRscString( STR_INVALID_TABREF )
     738           0 :                     ).Execute();
     739           0 :             mpEdCopyFrom->GrabFocus();
     740           0 :             mpEdCopyFrom->SetSelection( Selection( 0, SELECTION_MAX ) );
     741           0 :         }
     742             :     }
     743             : 
     744           0 :     return 0;
     745             : }
     746             : 
     747             : // -----------------------------------------------------------------------
     748             : 
     749           0 : IMPL_LINK( ScTpUserLists, EdEntriesModHdl, VclMultiLineEdit*, pEd )
     750             : {
     751           0 :     if ( pEd != mpEdEntries )
     752           0 :         return 0;
     753             : 
     754             :     //-----------------------------------------------------------
     755             : 
     756           0 :     if ( mpBtnCopy->IsEnabled() )
     757             :     {
     758           0 :         mpBtnCopy->Disable();
     759           0 :         mpFtCopyFrom->Disable();
     760           0 :         mpEdCopyFrom->Disable();
     761             :     }
     762             : 
     763           0 :     if ( !mpEdEntries->GetText().isEmpty() )
     764             :     {
     765           0 :         if ( !bCancelMode && !bModifyMode )
     766             :         {
     767           0 :             mpBtnNew->Hide();
     768           0 :             mpBtnDiscard->Show();
     769           0 :             bCancelMode = sal_True;
     770           0 :             mpBtnAdd->Hide();
     771           0 :             mpBtnAdd->Enable();
     772           0 :             mpBtnModify->Show();
     773           0 :             mpBtnModify->Enable();
     774           0 :             bModifyMode = sal_True;
     775           0 :             mpBtnRemove->Disable();
     776           0 :             mpFtLists->Disable();
     777           0 :             mpLbLists->Disable();
     778             :         }
     779             :         else // if ( bCancelMode || bModifyMode )
     780             :         {
     781           0 :             if ( !mpBtnAdd->IsEnabled() )
     782             :             {
     783           0 :                 mpBtnAdd->Enable();
     784           0 :                 mpBtnModify->Enable();
     785             :             }
     786             :         }
     787             :     }
     788             :     else
     789             :     {
     790           0 :         if ( mpBtnAdd->IsEnabled() )
     791             :         {
     792           0 :             mpBtnAdd->Disable();
     793           0 :             mpBtnModify->Disable();
     794             :         }
     795             :     }
     796             : 
     797           0 :     return 0;
     798           0 : }
     799             : 
     800             : 
     801             : 
     802             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10