LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/dbgui - consdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 282 0.4 %
Date: 2012-12-17 Functions: 2 27 7.4 %
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 "consdlg.hrc"
      33             : 
      34             : #define _CONSDLG_CXX
      35             : #include "consdlg.hxx"
      36             : #undef _CONSDLG_CXX
      37             : #include <vcl/msgbox.hxx>
      38             : 
      39             : #define INFOBOX(id) InfoBox(this, ScGlobal::GetRscString(id)).Execute()
      40             : 
      41             : //============================================================================
      42             : //  class ScAreaData
      43             : 
      44             : class ScAreaData
      45             : {
      46             : public:
      47           0 :     ScAreaData()  {}
      48           0 :     ~ScAreaData() {}
      49             : 
      50           0 :     void Set( const String& rName, const String& rArea, sal_Bool bDb )
      51             :                 {
      52           0 :                     aStrName  = rName;
      53           0 :                     aStrArea  = rArea;
      54           0 :                     bIsDbArea = bDb;
      55           0 :                 }
      56             : 
      57             :     String  aStrName;
      58             :     String  aStrArea;
      59             :     sal_Bool    bIsDbArea;
      60             : };
      61             : 
      62             : 
      63             : //============================================================================
      64             : //  class ScConsolidateDialog
      65             : 
      66             : 
      67           0 : ScConsolidateDlg::ScConsolidateDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
      68             :                                     const SfxItemSet&   rArgSet )
      69             : 
      70             :     :   ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_CONSOLIDATE ),
      71             :         //
      72             :         aFtFunc         ( this, ScResId( FT_FUNC ) ),
      73             :         aLbFunc         ( this, ScResId( LB_FUNC ) ),
      74             : 
      75             :         aFtConsAreas    ( this, ScResId( FT_CONSAREAS ) ),
      76             :         aLbConsAreas    ( this, ScResId( LB_CONSAREAS ) ),
      77             : 
      78             :         aLbDataArea     ( this, ScResId( LB_DATA_AREA ) ),
      79             :         aFtDataArea     ( this, ScResId( FT_DATA_AREA ) ),
      80             :         aEdDataArea     ( this, this, ScResId( ED_DATA_AREA ) ),
      81             :         aRbDataArea     ( this, ScResId( RB_DATA_AREA ), &aEdDataArea, this ),
      82             : 
      83             :         aLbDestArea     ( this, ScResId( LB_DEST_AREA ) ),
      84             :         aFtDestArea     ( this, ScResId( FT_DEST_AREA ) ),
      85             :         aEdDestArea     ( this, this, ScResId( ED_DEST_AREA ) ),
      86             :         aRbDestArea     ( this, ScResId( RB_DEST_AREA ), &aEdDestArea, this),
      87             : 
      88             :         aFlConsBy       ( this, ScResId( FL_CONSBY ) ),
      89             :         aBtnByRow       ( this, ScResId( BTN_BYROW ) ),
      90             :         aBtnByCol       ( this, ScResId( BTN_BYCOL) ),
      91             : 
      92             :         aFlSep          ( this, ScResId( FL_SEP ) ),
      93             :         aFlOptions      ( this, ScResId( FL_OPTIONS ) ),
      94             :         aBtnRefs        ( this, ScResId( BTN_REFS ) ),
      95             : 
      96             :         aBtnOk          ( this, ScResId( BTN_OK ) ),
      97             :         aBtnCancel      ( this, ScResId( BTN_CANCEL ) ),
      98             :         aBtnHelp        ( this, ScResId( BTN_HELP ) ),
      99             :         aBtnAdd         ( this, ScResId( BTN_ADD ) ),
     100             :         aBtnRemove      ( this, ScResId( BTN_REMOVE ) ),
     101             :         aBtnMore        ( this, ScResId( BTN_MORE ) ),
     102             : 
     103             :         aStrUndefined   ( ScResId( SCSTR_UNDEFINED ) ),
     104             :         //
     105             :         theConsData     ( ((const ScConsolidateItem&)
     106             :                            rArgSet.Get( rArgSet.GetPool()->
     107           0 :                                             GetWhich( SID_CONSOLIDATE ) )
     108           0 :                                       ).GetData() ),
     109           0 :         pViewData       ( ((ScTabViewShell*)SfxViewShell::Current())->
     110           0 :                                 GetViewData() ),
     111           0 :         pDoc            ( ((ScTabViewShell*)SfxViewShell::Current())->
     112           0 :                                 GetViewData()->GetDocument() ),
     113           0 :         pRangeUtil      ( new ScRangeUtil ),
     114             :         pAreaData       ( NULL ),
     115             :         nAreaDataCount  ( 0 ),
     116           0 :         nWhichCons      ( rArgSet.GetPool()->GetWhich( SID_CONSOLIDATE ) ),
     117             : 
     118           0 :         pRefInputEdit   ( &aEdDataArea )
     119             : {
     120           0 :     Init();
     121           0 :     FreeResource();
     122           0 : }
     123             : 
     124             : 
     125             : //----------------------------------------------------------------------------
     126             : 
     127           0 : ScConsolidateDlg::~ScConsolidateDlg()
     128             : {
     129           0 :     delete [] pAreaData;
     130           0 :     delete pRangeUtil;
     131           0 : }
     132             : 
     133             : 
     134             : //----------------------------------------------------------------------------
     135             : 
     136           0 : void ScConsolidateDlg::Init()
     137             : {
     138             :     OSL_ENSURE( pViewData && pDoc && pRangeUtil, "Error in Ctor" );
     139             : 
     140           0 :     String aStr;
     141           0 :     sal_uInt16 i=0;
     142             : 
     143           0 :     aEdDataArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
     144           0 :     aEdDestArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
     145           0 :     aLbDataArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
     146           0 :     aLbDestArea .SetGetFocusHdl( LINK( this, ScConsolidateDlg, GetFocusHdl ) );
     147           0 :     aEdDataArea .SetModifyHdl   ( LINK( this, ScConsolidateDlg, ModifyHdl ) );
     148           0 :     aEdDestArea .SetModifyHdl   ( LINK( this, ScConsolidateDlg, ModifyHdl ) );
     149           0 :     aLbConsAreas.SetSelectHdl   ( LINK( this, ScConsolidateDlg, SelectHdl ) );
     150           0 :     aLbDataArea .SetSelectHdl   ( LINK( this, ScConsolidateDlg, SelectHdl ) );
     151           0 :     aLbDestArea .SetSelectHdl   ( LINK( this, ScConsolidateDlg, SelectHdl ) );
     152           0 :     aBtnOk      .SetClickHdl    ( LINK( this, ScConsolidateDlg, OkHdl ) );
     153           0 :     aBtnCancel  .SetClickHdl    ( LINK( this, ScConsolidateDlg, ClickHdl ) );
     154           0 :     aBtnAdd     .SetClickHdl    ( LINK( this, ScConsolidateDlg, ClickHdl ) );
     155           0 :     aBtnRemove  .SetClickHdl    ( LINK( this, ScConsolidateDlg, ClickHdl ) );
     156             : 
     157           0 :     aBtnMore.AddWindow( &aFlConsBy );
     158           0 :     aBtnMore.AddWindow( &aBtnByRow );
     159           0 :     aBtnMore.AddWindow( &aBtnByCol );
     160           0 :     aBtnMore.AddWindow( &aFlSep );
     161           0 :     aBtnMore.AddWindow( &aFlOptions );
     162           0 :     aBtnMore.AddWindow( &aBtnRefs );
     163             : 
     164           0 :     aBtnAdd.Disable();
     165           0 :     aBtnRemove.Disable();
     166             : 
     167           0 :     aBtnByRow.Check( theConsData.bByRow );
     168           0 :     aBtnByCol.Check( theConsData.bByCol );
     169           0 :     aBtnRefs .Check( theConsData.bReferenceData );
     170             : 
     171           0 :     aLbFunc.SelectEntryPos( FuncToLbPos( theConsData.eFunction ) );
     172             : 
     173             :     // Einlesen der Konsolidierungsbereiche
     174           0 :     aLbConsAreas.Clear();
     175           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     176           0 :     for ( i=0; i<theConsData.nDataAreaCount; i++ )
     177             :     {
     178           0 :         const ScArea& rArea = *(theConsData.ppDataAreas[i] );
     179           0 :         if ( rArea.nTab < pDoc->GetTableCount() )
     180             :         {
     181             :             ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
     182             :                     rArea.nColEnd, rArea.nRowEnd, rArea.nTab ).Format( aStr,
     183           0 :                         SCR_ABS_3D, pDoc, eConv );
     184           0 :             aLbConsAreas.InsertEntry( aStr );
     185             :         }
     186             :     }
     187             : 
     188           0 :     if ( theConsData.nTab < pDoc->GetTableCount() )
     189             :     {
     190             :         ScAddress( theConsData.nCol, theConsData.nRow, theConsData.nTab
     191           0 :                 ).Format( aStr, SCA_ABS_3D, pDoc, eConv );
     192           0 :         aEdDestArea.SetText( aStr );
     193             :     }
     194             :     else
     195           0 :         aEdDestArea.SetText( EMPTY_STRING );
     196             : 
     197             :     //----------------------------------------------------------
     198             : 
     199             :     /*
     200             :      * Aus den RangeNames und Datenbankbereichen werden sich
     201             :      * in der Hilfsklasse ScAreaData die Bereichsnamen gemerkt,
     202             :      * die in den ListBoxen erscheinen.
     203             :      */
     204             : 
     205           0 :     ScRangeName*    pRangeNames  = pDoc->GetRangeName();
     206           0 :     ScDBCollection* pDbNames     = pDoc->GetDBCollection();
     207           0 :     size_t nRangeCount = pRangeNames ? pRangeNames->size() : 0;
     208           0 :     size_t nDbCount = pDbNames ? pDbNames->getNamedDBs().size() : 0;
     209             : 
     210           0 :     nAreaDataCount = nRangeCount+nDbCount;
     211           0 :     pAreaData      = NULL;
     212             : 
     213           0 :     if ( nAreaDataCount > 0 )
     214             :     {
     215           0 :         pAreaData = new ScAreaData[nAreaDataCount];
     216             : 
     217           0 :         String aStrName;
     218           0 :         String aStrArea;
     219           0 :         sal_uInt16 nAt = 0;
     220           0 :         ScRange aRange;
     221           0 :         ScAreaNameIterator aIter( pDoc );
     222           0 :         while ( aIter.Next( aStrName, aRange ) )
     223             :         {
     224           0 :             aRange.Format( aStrArea, SCA_ABS_3D, pDoc, eConv );
     225           0 :             pAreaData[nAt++].Set( aStrName, aStrArea, aIter.WasDBName() );
     226           0 :         }
     227             :     }
     228             : 
     229           0 :     FillAreaLists();
     230           0 :     ModifyHdl( &aEdDestArea );
     231           0 :     aLbDataArea.SelectEntryPos( 0 );
     232           0 :     aEdDataArea.SetText( EMPTY_STRING );
     233           0 :     aEdDataArea.GrabFocus();
     234             : 
     235           0 :     aFlSep.SetStyle( aFlSep.GetStyle() | WB_VERT );
     236             : 
     237             :     //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
     238             :     //SFX_APPWINDOW->Enable();
     239           0 : }
     240             : 
     241             : 
     242             : //----------------------------------------------------------------------------
     243           0 : void ScConsolidateDlg::FillAreaLists()
     244             : {
     245           0 :     aLbDataArea.Clear();
     246           0 :     aLbDestArea.Clear();
     247           0 :     aLbDataArea.InsertEntry( aStrUndefined );
     248           0 :     aLbDestArea.InsertEntry( aStrUndefined );
     249             : 
     250           0 :     if ( pRangeUtil && pAreaData && (nAreaDataCount > 0) )
     251             :     {
     252           0 :         String aString;
     253             : 
     254           0 :         for ( size_t i=0;
     255           0 :               (i<nAreaDataCount) && (pAreaData[i].aStrName.Len()>0);
     256             :               i++ )
     257             :         {
     258           0 :             aLbDataArea.InsertEntry( pAreaData[i].aStrName, i+1 );
     259             : 
     260             : //          if ( !pAreaData[i].bIsDbArea )
     261           0 :                 aLbDestArea.InsertEntry( pAreaData[i].aStrName, i+1 );
     262           0 :         }
     263             :     }
     264           0 : }
     265             : 
     266             : 
     267             : //----------------------------------------------------------------------------
     268             : // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
     269             : //  neue Selektion im Referenz-Fenster angezeigt wird.
     270             : 
     271             : 
     272           0 : void ScConsolidateDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
     273             : {
     274           0 :     if ( pRefInputEdit )
     275             :     {
     276           0 :         if ( rRef.aStart != rRef.aEnd )
     277           0 :             RefInputStart( pRefInputEdit );
     278             : 
     279           0 :         String      aStr;
     280           0 :         sal_uInt16      nFmt = SCR_ABS_3D;       //!!! nCurTab fehlt noch
     281           0 :         const formula::FormulaGrammar::AddressConvention eConv = pDocP->GetAddressConvention();
     282             : 
     283           0 :         if ( rRef.aStart.Tab() != rRef.aEnd.Tab() )
     284           0 :             nFmt |= SCA_TAB2_3D;
     285             : 
     286           0 :         if ( pRefInputEdit == &aEdDataArea)
     287           0 :             rRef.Format( aStr, nFmt, pDocP, eConv );
     288           0 :         else if ( pRefInputEdit == &aEdDestArea )
     289           0 :             rRef.aStart.Format( aStr, nFmt, pDocP, eConv );
     290             : 
     291           0 :         pRefInputEdit->SetRefString( aStr );
     292             :     }
     293             : 
     294           0 :     ModifyHdl( pRefInputEdit );
     295           0 : }
     296             : 
     297             : 
     298             : //----------------------------------------------------------------------------
     299             : 
     300           0 : sal_Bool ScConsolidateDlg::Close()
     301             : {
     302           0 :     return DoClose( ScConsolidateDlgWrapper::GetChildWindowId() );
     303             : }
     304             : 
     305             : 
     306             : //----------------------------------------------------------------------------
     307             : 
     308           0 : void ScConsolidateDlg::SetActive()
     309             : {
     310           0 :     if ( bDlgLostFocus )
     311             :     {
     312           0 :         bDlgLostFocus = false;
     313             : 
     314           0 :         if ( pRefInputEdit )
     315             :         {
     316           0 :             pRefInputEdit->GrabFocus();
     317           0 :             ModifyHdl( pRefInputEdit );
     318             :         }
     319             :     }
     320             :     else
     321           0 :         GrabFocus();
     322             : 
     323           0 :     RefInputDone();
     324           0 : }
     325             : 
     326             : 
     327             : //----------------------------------------------------------------------------
     328             : 
     329           0 : void ScConsolidateDlg::Deactivate()
     330             : {
     331           0 :     bDlgLostFocus = sal_True;
     332           0 : }
     333             : 
     334             : 
     335             : //----------------------------------------------------------------------------
     336             : 
     337           0 : sal_Bool ScConsolidateDlg::VerifyEdit( formula::RefEdit* pEd )
     338             : {
     339           0 :     if ( !pRangeUtil || !pDoc || !pViewData ||
     340             :          ((pEd != &aEdDataArea) && (pEd != &aEdDestArea)) )
     341           0 :         return false;
     342             : 
     343           0 :     SCTAB   nTab    = pViewData->GetTabNo();
     344           0 :     sal_Bool    bEditOk = false;
     345           0 :     String  theCompleteStr;
     346           0 :     const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     347             : 
     348           0 :     if ( pEd == &aEdDataArea )
     349             :     {
     350           0 :         bEditOk = pRangeUtil->IsAbsArea( pEd->GetText(), pDoc,
     351           0 :                                          nTab, &theCompleteStr, NULL, NULL, eConv );
     352             :     }
     353           0 :     else if ( pEd == &aEdDestArea )
     354             :     {
     355           0 :         String aPosStr;
     356             : 
     357           0 :         pRangeUtil->CutPosString( pEd->GetText(), aPosStr );
     358             :         bEditOk = pRangeUtil->IsAbsPos( aPosStr, pDoc,
     359           0 :                                         nTab, &theCompleteStr, NULL, eConv );
     360             :     }
     361             : 
     362           0 :     if ( bEditOk )
     363           0 :         pEd->SetText( theCompleteStr );
     364             : 
     365           0 :     return bEditOk;
     366             : }
     367             : 
     368             : 
     369             : //----------------------------------------------------------------------------
     370             : // Handler:
     371             : // ========
     372             : 
     373           0 : IMPL_LINK( ScConsolidateDlg, GetFocusHdl, Control*, pCtr )
     374             : {
     375           0 :     if ( pCtr ==(Control*)&aEdDataArea ||
     376             :          pCtr ==(Control*)&aEdDestArea)
     377             :     {
     378           0 :         pRefInputEdit = (formula::RefEdit*)pCtr;
     379             :     }
     380           0 :     else if(pCtr ==(Control*)&aLbDataArea )
     381             :     {
     382           0 :         pRefInputEdit = &aEdDataArea;
     383             :     }
     384           0 :     else if(pCtr ==(Control*)&aLbDestArea )
     385             :     {
     386           0 :         pRefInputEdit = &aEdDestArea;
     387             :     }
     388           0 :     return 0;
     389             : }
     390             : 
     391             : 
     392             : //----------------------------------------------------------------------------
     393             : 
     394           0 : IMPL_LINK_NOARG(ScConsolidateDlg, OkHdl)
     395             : {
     396           0 :     sal_uInt16 nDataAreaCount = aLbConsAreas.GetEntryCount();
     397             : 
     398           0 :     if ( nDataAreaCount > 0 )
     399             :     {
     400           0 :         ScRefAddress aDestAddress;
     401           0 :         SCTAB       nTab = pViewData->GetTabNo();
     402           0 :         String      aDestPosStr( aEdDestArea.GetText() );
     403           0 :         const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     404             : 
     405           0 :         if ( pRangeUtil->IsAbsPos( aDestPosStr, pDoc, nTab, NULL, &aDestAddress, eConv ) )
     406             :         {
     407           0 :             ScConsolidateParam  theOutParam( theConsData );
     408           0 :             ScArea**            ppDataAreas = new ScArea*[nDataAreaCount];
     409             :             ScArea*             pArea;
     410           0 :             sal_uInt16              i=0;
     411             : 
     412           0 :             for ( i=0; i<nDataAreaCount; i++ )
     413             :             {
     414           0 :                 pArea = new ScArea;
     415             :                 pRangeUtil->MakeArea( aLbConsAreas.GetEntry( i ),
     416           0 :                                       *pArea, pDoc, nTab, eConv );
     417           0 :                 ppDataAreas[i] = pArea;
     418             :             }
     419             : 
     420           0 :             theOutParam.nCol            = aDestAddress.Col();
     421           0 :             theOutParam.nRow            = aDestAddress.Row();
     422           0 :             theOutParam.nTab            = aDestAddress.Tab();
     423           0 :             theOutParam.eFunction       = LbPosToFunc( aLbFunc.GetSelectEntryPos() );
     424           0 :             theOutParam.bByCol          = aBtnByCol.IsChecked();
     425           0 :             theOutParam.bByRow          = aBtnByRow.IsChecked();
     426           0 :             theOutParam.bReferenceData  = aBtnRefs.IsChecked();
     427           0 :             theOutParam.SetAreas( ppDataAreas, nDataAreaCount );
     428             : 
     429           0 :             for ( i=0; i<nDataAreaCount; i++ )
     430           0 :                 delete ppDataAreas[i];
     431           0 :             delete [] ppDataAreas;
     432             : 
     433           0 :             ScConsolidateItem aOutItem( nWhichCons, &theOutParam );
     434             : 
     435           0 :             SetDispatcherLock( false );
     436           0 :             SwitchToDocument();
     437           0 :             GetBindings().GetDispatcher()->Execute( SID_CONSOLIDATE,
     438             :                                       SFX_CALLMODE_SLOT | SFX_CALLMODE_RECORD,
     439           0 :                                       &aOutItem, 0L, 0L );
     440           0 :             Close();
     441             :         }
     442             :         else
     443             :         {
     444           0 :             INFOBOX( STR_INVALID_TABREF );
     445           0 :             aEdDestArea.GrabFocus();
     446           0 :         }
     447             :     }
     448             :     else
     449           0 :         Close(); // keine Datenbereiche definiert -> Cancel
     450           0 :     return 0;
     451             : }
     452             : 
     453             : 
     454             : //----------------------------------------------------------------------------
     455             : 
     456           0 : IMPL_LINK( ScConsolidateDlg, ClickHdl, PushButton*, pBtn )
     457             : {
     458           0 :     if ( pBtn == &aBtnCancel )
     459           0 :         Close();
     460           0 :     else if ( pBtn == &aBtnAdd )
     461             :     {
     462           0 :         if ( aEdDataArea.GetText().Len() > 0 )
     463             :         {
     464           0 :             String      aNewEntry( aEdDataArea.GetText() );
     465           0 :             ScArea**    ppAreas = NULL;
     466           0 :             sal_uInt16      nAreaCount = 0;
     467           0 :             const formula::FormulaGrammar::AddressConvention eConv = pDoc->GetAddressConvention();
     468             : 
     469           0 :             if ( pRangeUtil->IsAbsTabArea( aNewEntry, pDoc, &ppAreas, &nAreaCount, sal_True, eConv ) )
     470             :             {
     471             :                 // IsAbsTabArea() legt ein Array von ScArea-Zeigern an,
     472             :                 // welche ebenfalls dynamisch erzeugt wurden.
     473             :                 // Diese Objekte muessen hier abgeraeumt werden.
     474             : 
     475           0 :                 for ( sal_uInt16 i=0; i<nAreaCount; i++ )
     476             :                 {
     477           0 :                     String aNewArea;
     478             : 
     479           0 :                     if ( ppAreas[i] )
     480             :                     {
     481           0 :                         const ScArea& rArea = *(ppAreas[i]);
     482             :                         ScRange( rArea.nColStart, rArea.nRowStart, rArea.nTab,
     483             :                                 rArea.nColEnd, rArea.nRowEnd, rArea.nTab
     484           0 :                                 ).Format( aNewArea, SCR_ABS_3D, pDoc, eConv );
     485             : 
     486           0 :                         if ( aLbConsAreas.GetEntryPos( aNewArea )
     487             :                              == LISTBOX_ENTRY_NOTFOUND )
     488             :                         {
     489           0 :                             aLbConsAreas.InsertEntry( aNewArea );
     490             :                         }
     491           0 :                         delete ppAreas[i];
     492             :                     }
     493           0 :                 }
     494           0 :                 delete [] ppAreas;
     495             :             }
     496           0 :             else if ( VerifyEdit( &aEdDataArea ) )
     497             :             {
     498           0 :                 String aNewArea( aEdDataArea.GetText() );
     499             : 
     500           0 :                 if ( aLbConsAreas.GetEntryPos( aNewArea ) == LISTBOX_ENTRY_NOTFOUND )
     501           0 :                     aLbConsAreas.InsertEntry( aNewArea );
     502             :                 else
     503           0 :                     INFOBOX( STR_AREA_ALREADY_INSERTED );
     504             :             }
     505             :             else
     506             :             {
     507           0 :                 INFOBOX( STR_INVALID_TABREF );
     508           0 :                 aEdDataArea.GrabFocus();
     509           0 :             }
     510             :         }
     511             :     }
     512           0 :     else if ( pBtn == &aBtnRemove )
     513             :     {
     514           0 :         while ( aLbConsAreas.GetSelectEntryCount() )
     515           0 :             aLbConsAreas.RemoveEntry( aLbConsAreas.GetSelectEntryPos() );
     516           0 :         aBtnRemove.Disable();
     517             :     }
     518           0 :     return 0;
     519             : }
     520             : 
     521             : 
     522             : //----------------------------------------------------------------------------
     523             : 
     524           0 : IMPL_LINK( ScConsolidateDlg, SelectHdl, ListBox*, pLb )
     525             : {
     526           0 :     if ( pLb == &aLbConsAreas )
     527             :     {
     528           0 :         if ( aLbConsAreas.GetSelectEntryCount() > 0 )
     529           0 :             aBtnRemove.Enable();
     530             :         else
     531           0 :             aBtnRemove.Disable();
     532             :     }
     533           0 :     else if ( (pLb == &aLbDataArea) || (pLb == &aLbDestArea) )
     534             :     {
     535           0 :         Edit*   pEd = (pLb == &aLbDataArea) ? &aEdDataArea : &aEdDestArea;
     536           0 :         sal_uInt16  nSelPos = pLb->GetSelectEntryPos();
     537             : 
     538           0 :         if (    pRangeUtil
     539             :             && (nSelPos > 0)
     540             :             && (nAreaDataCount > 0)
     541             :             && (pAreaData != NULL) )
     542             :         {
     543           0 :             if ( static_cast<size_t>(nSelPos) <= nAreaDataCount )
     544             :             {
     545           0 :                 String aString( pAreaData[nSelPos-1].aStrArea );
     546             : 
     547           0 :                 if ( pLb == &aLbDestArea )
     548           0 :                     pRangeUtil->CutPosString( aString, aString );
     549             : 
     550           0 :                 pEd->SetText( aString );
     551             : 
     552           0 :                 if ( pEd == &aEdDataArea )
     553           0 :                     aBtnAdd.Enable();
     554           0 :             }
     555             :         }
     556             :         else
     557             :         {
     558           0 :             pEd->SetText( EMPTY_STRING );
     559           0 :             if ( pEd == &aEdDataArea )
     560           0 :                 aBtnAdd.Enable();
     561             :         }
     562             :     }
     563           0 :     return 0;
     564             : }
     565             : 
     566             : 
     567             : //----------------------------------------------------------------------------
     568             : 
     569           0 : IMPL_LINK( ScConsolidateDlg, ModifyHdl, formula::RefEdit*, pEd )
     570             : {
     571           0 :     if ( pEd == &aEdDataArea )
     572             :     {
     573           0 :         String aAreaStr( pEd->GetText() );
     574           0 :         if ( aAreaStr.Len() > 0 )
     575             :         {
     576           0 :             aBtnAdd.Enable();
     577             :         }
     578             :         else
     579           0 :             aBtnAdd.Disable();
     580             :     }
     581           0 :     else if ( pEd == &aEdDestArea )
     582             :     {
     583           0 :         aLbDestArea.SelectEntryPos(0);
     584             :     }
     585           0 :     return 0;
     586             : }
     587             : 
     588             : 
     589             : //----------------------------------------------------------------------------
     590             : // Verallgemeinern!!! :
     591             : // Resource der ListBox und diese beiden Umrechnungsmethoden gibt es
     592             : // auch noch in tpsubt bzw. ueberall, wo StarCalc-Funktionen
     593             : // auswaehlbar sind.
     594             : 
     595           0 : ScSubTotalFunc ScConsolidateDlg::LbPosToFunc( sal_uInt16 nPos )
     596             : {
     597           0 :     switch ( nPos )
     598             :     {
     599           0 :         case  2:    return SUBTOTAL_FUNC_AVE;
     600           0 :         case  6:    return SUBTOTAL_FUNC_CNT;
     601           0 :         case  1:    return SUBTOTAL_FUNC_CNT2;
     602           0 :         case  3:    return SUBTOTAL_FUNC_MAX;
     603           0 :         case  4:    return SUBTOTAL_FUNC_MIN;
     604           0 :         case  5:    return SUBTOTAL_FUNC_PROD;
     605           0 :         case  7:    return SUBTOTAL_FUNC_STD;
     606           0 :         case  8:    return SUBTOTAL_FUNC_STDP;
     607           0 :         case  9:    return SUBTOTAL_FUNC_VAR;
     608           0 :         case 10:    return SUBTOTAL_FUNC_VARP;
     609             :         case  0:
     610             :         default:
     611           0 :             return SUBTOTAL_FUNC_SUM;
     612             :     }
     613             : }
     614             : 
     615             : 
     616             : //----------------------------------------------------------------------------
     617             : 
     618           0 : sal_uInt16 ScConsolidateDlg::FuncToLbPos( ScSubTotalFunc eFunc )
     619             : {
     620           0 :     switch ( eFunc )
     621             :     {
     622           0 :         case SUBTOTAL_FUNC_AVE:     return 2;
     623           0 :         case SUBTOTAL_FUNC_CNT:     return 6;
     624           0 :         case SUBTOTAL_FUNC_CNT2:    return 1;
     625           0 :         case SUBTOTAL_FUNC_MAX:     return 3;
     626           0 :         case SUBTOTAL_FUNC_MIN:     return 4;
     627           0 :         case SUBTOTAL_FUNC_PROD:    return 5;
     628           0 :         case SUBTOTAL_FUNC_STD:     return 7;
     629           0 :         case SUBTOTAL_FUNC_STDP:    return 8;
     630           0 :         case SUBTOTAL_FUNC_VAR:     return 9;
     631           0 :         case SUBTOTAL_FUNC_VARP:    return 10;
     632             :         case SUBTOTAL_FUNC_NONE:
     633             :         case SUBTOTAL_FUNC_SUM:
     634             :         default:
     635           0 :             return 0;
     636             :     }
     637         102 : }
     638             : 
     639             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10