LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - consdlg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 326 0.3 %
Date: 2015-06-13 12:38:46 Functions: 2 28 7.1 %
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             : #include <sfx2/dispatch.hxx>
      21             : 
      22             : #include "tabvwsh.hxx"
      23             : #include "uiitems.hxx"
      24             : #include "dbdata.hxx"
      25             : #include "rangenam.hxx"
      26             : #include "rangeutl.hxx"
      27             : #include "reffact.hxx"
      28             : #include "document.hxx"
      29             : #include "scresid.hxx"
      30             : 
      31             : #include "globstr.hrc"
      32             : #include "sc.hrc"
      33             : 
      34             : #include "consdlg.hxx"
      35             : #include <vcl/msgbox.hxx>
      36             : 
      37             : #define INFOBOX(id) ScopedVclPtr<InfoBox>::Create(this, ScGlobal::GetRscString(id))->Execute()
      38             : 
      39             : class ScAreaData
      40             : {
      41             : public:
      42           0 :     ScAreaData()
      43           0 :         : bIsDbArea(false)
      44             :     {
      45           0 :     }
      46             : 
      47           0 :     ~ScAreaData() {}
      48             : 
      49           0 :     void Set( const OUString& rName, const OUString& rArea, bool bDb )
      50             :                 {
      51           0 :                     aStrName  = rName;
      52           0 :                     aStrArea  = rArea;
      53           0 :                     bIsDbArea = bDb;
      54           0 :                 }
      55             : 
      56             :     OUString  aStrName;
      57             :     OUString  aStrArea;
      58             :     bool  bIsDbArea;
      59             : };
      60             : 
      61           0 : ScConsolidateDlg::ScConsolidateDlg( SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* pParent,
      62             :                                     const SfxItemSet&   rArgSet )
      63             : 
      64             :     :   ScAnyRefDlg ( pB, pCW, pParent, "ConsolidateDialog" , "modules/scalc/ui/consolidatedialog.ui" ),
      65             :         aStrUndefined   ( ScResId( SCSTR_UNDEFINED ) ),
      66             :         theConsData     ( static_cast<const ScConsolidateItem&>(
      67             :                            rArgSet.Get( rArgSet.GetPool()->
      68           0 :                                             GetWhich( SID_CONSOLIDATE ) )
      69           0 :                                       ).GetData() ),
      70           0 :         rViewData       ( static_cast<ScTabViewShell*>(SfxViewShell::Current())->
      71           0 :                                 GetViewData() ),
      72           0 :         pDoc            ( static_cast<ScTabViewShell*>(SfxViewShell::Current())->
      73           0 :                                 GetViewData().GetDocument() ),
      74           0 :         pRangeUtil      ( new ScRangeUtil ),
      75             :         pAreaData       ( NULL ),
      76             :         nAreaDataCount  ( 0 ),
      77           0 :         nWhichCons      ( rArgSet.GetPool()->GetWhich( SID_CONSOLIDATE ) ),
      78           0 :         bDlgLostFocus   ( false )
      79             : {
      80           0 :     get(pLbFunc,"func");
      81           0 :     get(pLbConsAreas,"consareas");
      82             : 
      83           0 :     get(pLbDataArea,"lbdataarea");
      84           0 :     get(pEdDataArea,"eddataarea");
      85           0 :     get(pRbDataArea,"rbdataarea");
      86             : 
      87           0 :     pRefInputEdit = pEdDataArea;
      88             : 
      89           0 :     get(pLbDestArea,"lbdestarea");
      90           0 :     get(pEdDestArea,"eddestarea");
      91           0 :     get(pRbDestArea,"rbdestarea");
      92             : 
      93           0 :     get(pExpander,"more");
      94           0 :     get(pBtnByRow,"byrow");
      95           0 :     get(pBtnByCol,"bycol");
      96           0 :     get(pBtnRefs,"refs");
      97             : 
      98           0 :     get(pBtnOk,"ok");
      99           0 :     get(pBtnCancel,"cancel");
     100           0 :     get(pBtnAdd,"add");
     101           0 :     get(pBtnRemove,"delete");
     102             : 
     103           0 :     Init();
     104           0 : }
     105             : 
     106           0 : ScConsolidateDlg::~ScConsolidateDlg()
     107             : {
     108           0 :     disposeOnce();
     109           0 : }
     110             : 
     111           0 : void ScConsolidateDlg::dispose()
     112             : {
     113           0 :     delete [] pAreaData;
     114           0 :     delete pRangeUtil;
     115           0 :     pLbFunc.clear();
     116           0 :     pLbConsAreas.clear();
     117           0 :     pLbDataArea.clear();
     118           0 :     pEdDataArea.clear();
     119           0 :     pRbDataArea.clear();
     120           0 :     pLbDestArea.clear();
     121           0 :     pEdDestArea.clear();
     122           0 :     pRbDestArea.clear();
     123           0 :     pExpander.clear();
     124           0 :     pBtnByRow.clear();
     125           0 :     pBtnByCol.clear();
     126           0 :     pBtnRefs.clear();
     127           0 :     pBtnOk.clear();
     128           0 :     pBtnCancel.clear();
     129           0 :     pBtnAdd.clear();
     130           0 :     pBtnRemove.clear();
     131           0 :     pRefInputEdit.clear();
     132           0 :     ScAnyRefDlg::dispose();
     133           0 : }
     134             : 
     135           0 : void ScConsolidateDlg::Init()
     136             : {
     137             :     OSL_ENSURE( pDoc && pRangeUtil, "Error in Ctor" );
     138             : 
     139           0 :     OUString aStr;
     140           0 :     sal_uInt16 i=0;
     141             : 
     142           0 :     pRbDataArea->SetReferences(this, pEdDataArea);
     143           0 :     pEdDataArea->SetReferences(this, get<FixedText>("ftdataarea"));
     144           0 :     pRbDestArea->SetReferences(this, pEdDestArea);
     145           0 :     pEdDestArea->SetReferences(this, get<FixedText>("ftdestarea"));
     146             : 
     147           0 :     pEdDataArea ->SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
     148           0 :     pEdDestArea ->SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
     149           0 :     pLbDataArea ->SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
     150           0 :     pLbDestArea ->SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
     151           0 :     pEdDataArea ->SetModifyHdl   ( LINK( this, ScConsolidateDlg, ModifyHdl ) );
     152           0 :     pEdDestArea ->SetModifyHdl   ( LINK( this, ScConsolidateDlg, ModifyHdl ) );
     153           0 :     pLbConsAreas->SetSelectHdl   ( LINK( this, ScConsolidateDlg, SelectHdl ) );
     154           0 :     pLbDataArea ->SetSelectHdl   ( LINK( this, ScConsolidateDlg, SelectHdl ) );
     155           0 :     pLbDestArea ->SetSelectHdl   ( LINK( this, ScConsolidateDlg, SelectHdl ) );
     156           0 :     pBtnOk      ->SetClickHdl    ( LINK( this, ScConsolidateDlg, OkHdl ) );
     157           0 :     pBtnCancel  ->SetClickHdl    ( LINK( this, ScConsolidateDlg, ClickHdl ) );
     158           0 :     pBtnAdd     ->SetClickHdl    ( LINK( this, ScConsolidateDlg, ClickHdl ) );
     159           0 :     pBtnRemove  ->SetClickHdl    ( LINK( this, ScConsolidateDlg, ClickHdl ) );
     160             : 
     161           0 :     pBtnAdd->Disable();
     162           0 :     pBtnRemove->Disable();
     163             : 
     164           0 :     pBtnByRow->Check( theConsData.bByRow );
     165           0 :     pBtnByCol->Check( theConsData.bByCol );
     166           0 :     pBtnRefs->Check( theConsData.bReferenceData );
     167             : 
     168           0 :     pLbFunc->SelectEntryPos( FuncToLbPos( theConsData.eFunction ) );
     169             : 
     170             :     // Hack: pLbConsAreas used to be MultiLB. We don't have VCL builder equivalent
     171             :     // of it yet. So enable selecting multiple items here
     172           0 :     pLbConsAreas->EnableMultiSelection( true );
     173             : 
     174           0 :     pLbConsAreas->set_width_request(pLbConsAreas->approximate_char_width() * 16);
     175           0 :     pLbConsAreas->SetDropDownLineCount(5);
     176             : 
     177             :     // read consolidation areas
     178           0 :     pLbConsAreas->Clear();
     179           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     180           0 :     for ( i=0; i<theConsData.nDataAreaCount; i++ )
     181             :     {
     182           0 :         const ScArea& rArea = *(theConsData.ppDataAreas[i] );
     183           0 :         if ( rArea.nTab < pDoc->GetTableCount() )
     184             :         {
     185           0 :             aStr = ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
     186             :                     rArea.nColEnd, rArea.nRowEnd, rArea.nTab ).Format(
     187           0 :                         SCR_ABS_3D, pDoc, eConv );
     188           0 :             pLbConsAreas->InsertEntry( aStr );
     189             :         }
     190             :     }
     191             : 
     192           0 :     if ( theConsData.nTab < pDoc->GetTableCount() )
     193             :     {
     194           0 :         aStr = ScAddress( theConsData.nCol, theConsData.nRow, theConsData.nTab
     195           0 :                 ).Format( SCA_ABS_3D, pDoc, eConv );
     196           0 :         pEdDestArea->SetText( aStr );
     197             :     }
     198             :     else
     199           0 :         pEdDestArea->SetText(OUString());
     200             : 
     201             :     // Use the ScAreaData helper class to save those range names from the
     202             :     // RangeNames and database ranges that appear in the ListBoxes.
     203             : 
     204           0 :     ScRangeName*    pRangeNames  = pDoc->GetRangeName();
     205           0 :     ScDBCollection* pDbNames     = pDoc->GetDBCollection();
     206           0 :     size_t nRangeCount = pRangeNames ? pRangeNames->size() : 0;
     207           0 :     size_t nDbCount = pDbNames ? pDbNames->getNamedDBs().size() : 0;
     208             : 
     209           0 :     nAreaDataCount = nRangeCount+nDbCount;
     210           0 :     pAreaData      = NULL;
     211             : 
     212           0 :     if ( nAreaDataCount > 0 )
     213             :     {
     214           0 :         pAreaData = new ScAreaData[nAreaDataCount];
     215             : 
     216           0 :         OUString aStrName;
     217           0 :         sal_uInt16 nAt = 0;
     218           0 :         ScRange aRange;
     219           0 :         ScAreaNameIterator aIter( pDoc );
     220           0 :         while ( aIter.Next( aStrName, aRange ) )
     221             :         {
     222           0 :             OUString aStrArea(aRange.Format(SCA_ABS_3D, pDoc, eConv));
     223           0 :             pAreaData[nAt++].Set( aStrName, aStrArea, aIter.WasDBName() );
     224           0 :         }
     225             :     }
     226             : 
     227           0 :     FillAreaLists();
     228           0 :     ModifyHdl( pEdDestArea );
     229           0 :     pLbDataArea->SelectEntryPos( 0 );
     230           0 :     pEdDataArea->SetText(OUString());
     231           0 :     pEdDataArea->GrabFocus();
     232             : 
     233             :     //aFlSep.SetStyle( aFlSep.GetStyle() | WB_VERT );
     234             : 
     235             :     //@BugID 54702 enable/disable only in base class
     236             :     //SFX_APPWINDOW->Enable();
     237           0 : }
     238             : 
     239           0 : void ScConsolidateDlg::FillAreaLists()
     240             : {
     241           0 :     pLbDataArea->Clear();
     242           0 :     pLbDestArea->Clear();
     243           0 :     pLbDataArea->InsertEntry( aStrUndefined );
     244           0 :     pLbDestArea->InsertEntry( aStrUndefined );
     245             : 
     246           0 :     if ( pRangeUtil && pAreaData && (nAreaDataCount > 0) )
     247             :     {
     248           0 :         for ( size_t i=0;
     249           0 :               (i<nAreaDataCount) && (!pAreaData[i].aStrName.isEmpty());
     250             :               i++ )
     251             :         {
     252           0 :             pLbDataArea->InsertEntry( pAreaData[i].aStrName, i+1 );
     253             : 
     254             : //          if ( !pAreaData[i].bIsDbArea )
     255           0 :                 pLbDestArea->InsertEntry( pAreaData[i].aStrName, i+1 );
     256             :         }
     257             :     }
     258           0 : }
     259             : 
     260             : // Handover of a range within a table that has been selected by the mouse.
     261             : // This range is then shown in the reference window as new selection.
     262             : 
     263           0 : void ScConsolidateDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
     264             : {
     265           0 :     if ( pRefInputEdit )
     266             :     {
     267           0 :         if ( rRef.aStart != rRef.aEnd )
     268           0 :             RefInputStart( pRefInputEdit );
     269             : 
     270           0 :         OUString      aStr;
     271           0 :         sal_uInt16      nFmt = SCR_ABS_3D;       //!!! nCurTab is still missing
     272           0 :         const formula::FormulaGrammar::AddressConvention eConv = pDocP->GetAddressConvention();
     273             : 
     274           0 :         if ( rRef.aStart.Tab() != rRef.aEnd.Tab() )
     275           0 :             nFmt |= SCA_TAB2_3D;
     276             : 
     277           0 :         if ( pRefInputEdit == pEdDataArea)
     278           0 :             aStr = rRef.Format(nFmt, pDocP, eConv);
     279           0 :         else if ( pRefInputEdit == pEdDestArea )
     280           0 :             aStr = rRef.aStart.Format(nFmt, pDocP, eConv);
     281             : 
     282           0 :         pRefInputEdit->SetRefString( aStr );
     283           0 :         ModifyHdl( pRefInputEdit );
     284             :     }
     285           0 : }
     286             : 
     287           0 : bool ScConsolidateDlg::Close()
     288             : {
     289           0 :     return DoClose( ScConsolidateDlgWrapper::GetChildWindowId() );
     290             : }
     291             : 
     292           0 : void ScConsolidateDlg::SetActive()
     293             : {
     294           0 :     if ( bDlgLostFocus )
     295             :     {
     296           0 :         bDlgLostFocus = false;
     297             : 
     298           0 :         if ( pRefInputEdit )
     299             :         {
     300           0 :             pRefInputEdit->GrabFocus();
     301           0 :             ModifyHdl( pRefInputEdit );
     302             :         }
     303             :     }
     304             :     else
     305           0 :         GrabFocus();
     306             : 
     307           0 :     RefInputDone();
     308           0 : }
     309             : 
     310           0 : void ScConsolidateDlg::Deactivate()
     311             : {
     312           0 :     bDlgLostFocus = true;
     313           0 : }
     314             : 
     315           0 : bool ScConsolidateDlg::VerifyEdit( formula::RefEdit* pEd )
     316             : {
     317           0 :     if ( !pRangeUtil || !pDoc ||
     318           0 :          ((pEd != pEdDataArea) && (pEd != pEdDestArea)) )
     319           0 :         return false;
     320             : 
     321           0 :     SCTAB    nTab    = rViewData.GetTabNo();
     322           0 :     bool bEditOk = false;
     323           0 :     OUString theCompleteStr;
     324           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     325             : 
     326           0 :     if ( pEd == pEdDataArea )
     327             :     {
     328           0 :         bEditOk = ScRangeUtil::IsAbsArea( pEd->GetText(), pDoc,
     329           0 :                                          nTab, &theCompleteStr, NULL, NULL, eConv );
     330             :     }
     331           0 :     else if ( pEd == pEdDestArea )
     332             :     {
     333           0 :         OUString aPosStr;
     334             : 
     335           0 :         ScRangeUtil::CutPosString( pEd->GetText(), aPosStr );
     336             :         bEditOk = ScRangeUtil::IsAbsPos( aPosStr, pDoc,
     337           0 :                                         nTab, &theCompleteStr, NULL, eConv );
     338             :     }
     339             : 
     340           0 :     if ( bEditOk )
     341           0 :         pEd->SetText( theCompleteStr );
     342             : 
     343           0 :     return bEditOk;
     344             : }
     345             : 
     346             : // Handler:
     347             : 
     348           0 : IMPL_LINK( ScConsolidateDlg, GetFocusHdl, Control*, pCtr )
     349             : {
     350           0 :     if ( pCtr ==static_cast<Control*>(pEdDataArea) ||
     351           0 :          pCtr ==static_cast<Control*>(pEdDestArea))
     352             :     {
     353           0 :         pRefInputEdit = static_cast<formula::RefEdit*>(pCtr);
     354             :     }
     355           0 :     else if(pCtr ==static_cast<Control*>(pLbDataArea) )
     356             :     {
     357           0 :         pRefInputEdit = pEdDataArea;
     358             :     }
     359           0 :     else if(pCtr ==static_cast<Control*>(pLbDestArea) )
     360             :     {
     361           0 :         pRefInputEdit = pEdDestArea;
     362             :     }
     363           0 :     return 0;
     364             : }
     365             : 
     366           0 : IMPL_LINK_NOARG(ScConsolidateDlg, OkHdl)
     367             : {
     368           0 :     sal_uInt16 nDataAreaCount = pLbConsAreas->GetEntryCount();
     369             : 
     370           0 :     if ( nDataAreaCount > 0 )
     371             :     {
     372           0 :         ScRefAddress aDestAddress;
     373           0 :         SCTAB       nTab = rViewData.GetTabNo();
     374           0 :         OUString    aDestPosStr( pEdDestArea->GetText() );
     375           0 :         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     376             : 
     377           0 :         if ( ScRangeUtil::IsAbsPos( aDestPosStr, pDoc, nTab, NULL, &aDestAddress, eConv ) )
     378             :         {
     379           0 :             ScConsolidateParam  theOutParam( theConsData );
     380           0 :             ScArea**            ppDataAreas = new ScArea*[nDataAreaCount];
     381             :             ScArea*             pArea;
     382           0 :             sal_uInt16              i=0;
     383             : 
     384           0 :             for ( i=0; i<nDataAreaCount; i++ )
     385             :             {
     386           0 :                 pArea = new ScArea;
     387             :                 ScRangeUtil::MakeArea( pLbConsAreas->GetEntry( i ),
     388           0 :                                       *pArea, pDoc, nTab, eConv );
     389           0 :                 ppDataAreas[i] = pArea;
     390             :             }
     391             : 
     392           0 :             theOutParam.nCol            = aDestAddress.Col();
     393           0 :             theOutParam.nRow            = aDestAddress.Row();
     394           0 :             theOutParam.nTab            = aDestAddress.Tab();
     395           0 :             theOutParam.eFunction       = LbPosToFunc( pLbFunc->GetSelectEntryPos() );
     396           0 :             theOutParam.bByCol          = pBtnByCol->IsChecked();
     397           0 :             theOutParam.bByRow          = pBtnByRow->IsChecked();
     398           0 :             theOutParam.bReferenceData  = pBtnRefs->IsChecked();
     399           0 :             theOutParam.SetAreas( ppDataAreas, nDataAreaCount );
     400             : 
     401           0 :             for ( i=0; i<nDataAreaCount; i++ )
     402           0 :                 delete ppDataAreas[i];
     403           0 :             delete [] ppDataAreas;
     404             : 
     405           0 :             ScConsolidateItem aOutItem( nWhichCons, &theOutParam );
     406             : 
     407           0 :             SetDispatcherLock( false );
     408           0 :             SwitchToDocument();
     409           0 :             GetBindings().GetDispatcher()->Execute( SID_CONSOLIDATE,
     410             :                                       SfxCallMode::SLOT | SfxCallMode::RECORD,
     411           0 :                                       &aOutItem, 0L, 0L );
     412           0 :             Close();
     413             :         }
     414             :         else
     415             :         {
     416           0 :             INFOBOX( STR_INVALID_TABREF );
     417           0 :             pEdDestArea->GrabFocus();
     418           0 :         }
     419             :     }
     420             :     else
     421           0 :         Close(); // no area defined -> Cancel
     422           0 :     return 0;
     423             : }
     424             : 
     425           0 : IMPL_LINK( ScConsolidateDlg, ClickHdl, PushButton*, pBtn )
     426             : {
     427           0 :     if ( pBtn == pBtnCancel )
     428           0 :         Close();
     429           0 :     else if ( pBtn == pBtnAdd )
     430             :     {
     431           0 :         if ( !pEdDataArea->GetText().isEmpty() )
     432             :         {
     433           0 :             OUString    aNewEntry( pEdDataArea->GetText() );
     434           0 :             ScArea**    ppAreas = NULL;
     435           0 :             sal_uInt16      nAreaCount = 0;
     436           0 :             const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     437             : 
     438           0 :             if ( ScRangeUtil::IsAbsTabArea( aNewEntry, pDoc, &ppAreas, &nAreaCount, true, eConv ) )
     439             :             {
     440             :                 // IsAbsTabArea() creates an array of ScArea pointers,
     441             :                 // which have been created dynamically as well.
     442             :                 // These objects need to be deleted here.
     443             : 
     444           0 :                 for ( sal_uInt16 i=0; i<nAreaCount; i++ )
     445             :                 {
     446           0 :                     OUString aNewArea;
     447             : 
     448           0 :                     if ( ppAreas[i] )
     449             :                     {
     450           0 :                         const ScArea& rArea = *(ppAreas[i]);
     451           0 :                         aNewArea = ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
     452             :                                 rArea.nColEnd, rArea.nRowEnd, rArea.nTab
     453           0 :                                 ).Format(SCR_ABS_3D, pDoc, eConv);
     454             : 
     455           0 :                         if ( pLbConsAreas->GetEntryPos( aNewArea )
     456             :                              == LISTBOX_ENTRY_NOTFOUND )
     457             :                         {
     458           0 :                             pLbConsAreas->InsertEntry( aNewArea );
     459             :                         }
     460           0 :                         delete ppAreas[i];
     461             :                     }
     462           0 :                 }
     463           0 :                 delete [] ppAreas;
     464             :             }
     465           0 :             else if ( VerifyEdit( pEdDataArea ) )
     466             :             {
     467           0 :                 OUString aNewArea( pEdDataArea->GetText() );
     468             : 
     469           0 :                 if ( pLbConsAreas->GetEntryPos( aNewArea ) == LISTBOX_ENTRY_NOTFOUND )
     470           0 :                     pLbConsAreas->InsertEntry( aNewArea );
     471             :                 else
     472           0 :                     INFOBOX( STR_AREA_ALREADY_INSERTED );
     473             :             }
     474             :             else
     475             :             {
     476           0 :                 INFOBOX( STR_INVALID_TABREF );
     477           0 :                 pEdDataArea->GrabFocus();
     478           0 :             }
     479             :         }
     480             :     }
     481           0 :     else if ( pBtn == pBtnRemove )
     482             :     {
     483           0 :         while ( pLbConsAreas->GetSelectEntryCount() )
     484           0 :             pLbConsAreas->RemoveEntry( pLbConsAreas->GetSelectEntryPos() );
     485           0 :         pBtnRemove->Disable();
     486             :     }
     487           0 :     return 0;
     488             : }
     489             : 
     490           0 : IMPL_LINK( ScConsolidateDlg, SelectHdl, ListBox*, pLb )
     491             : {
     492           0 :     if ( pLb == pLbConsAreas )
     493             :     {
     494           0 :         if ( pLbConsAreas->GetSelectEntryCount() > 0 )
     495           0 :             pBtnRemove->Enable();
     496             :         else
     497           0 :             pBtnRemove->Disable();
     498             :     }
     499           0 :     else if ( (pLb == pLbDataArea) || (pLb == pLbDestArea) )
     500             :     {
     501           0 :         Edit*   pEd = (pLb == pLbDataArea) ? pEdDataArea : pEdDestArea;
     502           0 :         sal_uInt16  nSelPos = pLb->GetSelectEntryPos();
     503             : 
     504           0 :         if (    pRangeUtil
     505           0 :             && (nSelPos > 0)
     506           0 :             && (nAreaDataCount > 0)
     507           0 :             && (pAreaData != NULL) )
     508             :         {
     509           0 :             if ( static_cast<size_t>(nSelPos) <= nAreaDataCount )
     510             :             {
     511           0 :                 OUString aString( pAreaData[nSelPos-1].aStrArea );
     512             : 
     513           0 :                 if ( pLb == pLbDestArea )
     514           0 :                     ScRangeUtil::CutPosString( aString, aString );
     515             : 
     516           0 :                 pEd->SetText( aString );
     517             : 
     518           0 :                 if ( pEd == pEdDataArea )
     519           0 :                     pBtnAdd->Enable();
     520           0 :             }
     521             :         }
     522             :         else
     523             :         {
     524           0 :             pEd->SetText( EMPTY_OUSTRING );
     525           0 :             if ( pEd == pEdDataArea )
     526           0 :                 pBtnAdd->Enable();
     527             :         }
     528             :     }
     529           0 :     return 0;
     530             : }
     531             : 
     532           0 : IMPL_LINK( ScConsolidateDlg, ModifyHdl, formula::RefEdit*, pEd )
     533             : {
     534           0 :     if ( pEd == pEdDataArea )
     535             :     {
     536           0 :         OUString aAreaStr( pEd->GetText() );
     537           0 :         if ( !aAreaStr.isEmpty() )
     538             :         {
     539           0 :             pBtnAdd->Enable();
     540             :         }
     541             :         else
     542           0 :             pBtnAdd->Disable();
     543             :     }
     544           0 :     else if ( pEd == pEdDestArea )
     545             :     {
     546           0 :         pLbDestArea->SelectEntryPos(0);
     547             :     }
     548           0 :     return 0;
     549             : }
     550             : 
     551             : // TODO: generalize!
     552             : // Resource of the ListBox and these two conversion methods are also in
     553             : // tpsubt and everywhere, where StarCalc functions are selectable.
     554             : 
     555           0 : ScSubTotalFunc ScConsolidateDlg::LbPosToFunc( sal_uInt16 nPos )
     556             : {
     557           0 :     switch ( nPos )
     558             :     {
     559           0 :         case  2:    return SUBTOTAL_FUNC_AVE;
     560           0 :         case  6:    return SUBTOTAL_FUNC_CNT;
     561           0 :         case  1:    return SUBTOTAL_FUNC_CNT2;
     562           0 :         case  3:    return SUBTOTAL_FUNC_MAX;
     563           0 :         case  4:    return SUBTOTAL_FUNC_MIN;
     564           0 :         case  5:    return SUBTOTAL_FUNC_PROD;
     565           0 :         case  7:    return SUBTOTAL_FUNC_STD;
     566           0 :         case  8:    return SUBTOTAL_FUNC_STDP;
     567           0 :         case  9:    return SUBTOTAL_FUNC_VAR;
     568           0 :         case 10:    return SUBTOTAL_FUNC_VARP;
     569             :         case  0:
     570             :         default:
     571           0 :             return SUBTOTAL_FUNC_SUM;
     572             :     }
     573             : }
     574             : 
     575           0 : sal_uInt16 ScConsolidateDlg::FuncToLbPos( ScSubTotalFunc eFunc )
     576             : {
     577           0 :     switch ( eFunc )
     578             :     {
     579           0 :         case SUBTOTAL_FUNC_AVE:     return 2;
     580           0 :         case SUBTOTAL_FUNC_CNT:     return 6;
     581           0 :         case SUBTOTAL_FUNC_CNT2:    return 1;
     582           0 :         case SUBTOTAL_FUNC_MAX:     return 3;
     583           0 :         case SUBTOTAL_FUNC_MIN:     return 4;
     584           0 :         case SUBTOTAL_FUNC_PROD:    return 5;
     585           0 :         case SUBTOTAL_FUNC_STD:     return 7;
     586           0 :         case SUBTOTAL_FUNC_STDP:    return 8;
     587           0 :         case SUBTOTAL_FUNC_VAR:     return 9;
     588           0 :         case SUBTOTAL_FUNC_VARP:    return 10;
     589             :         case SUBTOTAL_FUNC_NONE:
     590             :         case SUBTOTAL_FUNC_SUM:
     591             :         default:
     592           0 :             return 0;
     593             :     }
     594         156 : }
     595             : 
     596             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11