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

Generated by: LCOV version 1.10