LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - tpsubt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 298 0.0 %
Date: 2012-08-25 Functions: 0 42 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #undef SC_DLLIMPLEMENTATION
      30                 :            : 
      31                 :            : #include "scitems.hxx"
      32                 :            : #include "uiitems.hxx"
      33                 :            : #include "global.hxx"
      34                 :            : #include "userlist.hxx"
      35                 :            : #include "viewdata.hxx"
      36                 :            : #include "document.hxx"
      37                 :            : #include "scresid.hxx"
      38                 :            : #include "sc.hrc"       // -> Slot IDs
      39                 :            : 
      40                 :            : #include "subtdlg.hxx"
      41                 :            : #include "subtdlg.hrc"
      42                 :            : #include "tpsubt.hxx"
      43                 :            : 
      44                 :            : //========================================================================
      45                 :            : // Zwischenergebnisgruppen-Tabpage:
      46                 :            : 
      47                 :          0 : ScTpSubTotalGroup::ScTpSubTotalGroup( Window* pParent, sal_uInt16 nResId,
      48                 :            :                                       const SfxItemSet& rArgSet )
      49                 :            :         :   SfxTabPage      ( pParent,
      50                 :            :                               ScResId( nResId ),
      51                 :            :                               rArgSet ),
      52                 :            :             aFtGroup        ( this, ScResId( FT_GROUP ) ),
      53                 :            :             aLbGroup        ( this, ScResId( LB_GROUP ) ),
      54                 :            :             aFtColumns      ( this, ScResId( FT_COLUMNS ) ),
      55                 :            :             aLbColumns      ( this, ScResId( WND_COLUMNS ) ),
      56                 :            :             aFtFunctions    ( this, ScResId( FT_FUNCTIONS ) ),
      57                 :            :             aLbFunctions    ( this, ScResId( LB_FUNCTIONS ) ),
      58                 :            :             aStrNone        ( SC_RESSTR( SCSTR_NONE ) ),
      59                 :            :             aStrColumn      ( SC_RESSTR( SCSTR_COLUMN ) ),
      60                 :            :             pViewData       ( NULL ),
      61                 :            :             pDoc            ( NULL ),
      62                 :          0 :             nWhichSubTotals ( rArgSet.GetPool()->GetWhich( SID_SUBTOTALS ) ),
      63                 :            :             rSubTotalData   ( ((const ScSubTotalItem&)
      64                 :          0 :                               rArgSet.Get( nWhichSubTotals )).
      65                 :          0 :                                 GetSubTotalData() ),
      66                 :          0 :             nFieldCount     ( 0 )
      67                 :            : {
      68                 :            :     // Font is correctly initialized by SvTreeListBox ctor
      69                 :          0 :     aLbColumns.SetSelectionMode( SINGLE_SELECTION );
      70                 :          0 :     aLbColumns.SetDragDropMode( SV_DRAGDROP_NONE );
      71                 :          0 :     aLbColumns.SetSpaceBetweenEntries( 0 );
      72                 :          0 :     aLbColumns.Show();
      73                 :            : 
      74                 :          0 :     Init ();
      75                 :          0 :     FreeResource();
      76                 :          0 : }
      77                 :            : 
      78                 :            : // -----------------------------------------------------------------------
      79                 :            : 
      80                 :          0 : ScTpSubTotalGroup::~ScTpSubTotalGroup()
      81                 :            : {
      82                 :          0 :     sal_uInt16  nCount = (sal_uInt16)aLbColumns.GetEntryCount();
      83                 :            : 
      84                 :          0 :     if ( nCount > 0 )
      85                 :            :     {
      86                 :          0 :         sal_uInt16* pData = NULL;
      87                 :            : 
      88                 :          0 :         for ( sal_uInt16 i=0; i<nCount; i++ )
      89                 :            :         {
      90                 :          0 :             pData = (sal_uInt16*)(aLbColumns.GetEntryData( i ));
      91                 :            :             OSL_ENSURE( pData, "EntryData not found" );
      92                 :            : 
      93                 :          0 :             delete pData;
      94                 :            :         }
      95                 :            :     }
      96                 :          0 : }
      97                 :            : 
      98                 :            : // -----------------------------------------------------------------------
      99                 :            : 
     100                 :          0 : void ScTpSubTotalGroup::Init()
     101                 :            : {
     102                 :            :     const ScSubTotalItem& rSubTotalItem = (const ScSubTotalItem&)
     103                 :          0 :                                           GetItemSet().Get( nWhichSubTotals );
     104                 :            : 
     105                 :          0 :     pViewData   = rSubTotalItem.GetViewData();
     106                 :          0 :     pDoc        = ( pViewData ) ? pViewData->GetDocument() : NULL;
     107                 :            : 
     108                 :            :     OSL_ENSURE( pViewData && pDoc, "ViewData or Document not found :-(" );
     109                 :            : 
     110                 :          0 :     aLbGroup.SetSelectHdl       ( LINK( this, ScTpSubTotalGroup, SelectHdl ) );
     111                 :          0 :     aLbColumns.SetSelectHdl     ( LINK( this, ScTpSubTotalGroup, SelectHdl ) );
     112                 :          0 :     aLbColumns.SetCheckButtonHdl    ( LINK( this, ScTpSubTotalGroup, CheckHdl ) );
     113                 :          0 :     aLbFunctions.SetSelectHdl   ( LINK( this, ScTpSubTotalGroup, SelectHdl ) );
     114                 :            : 
     115                 :          0 :     nFieldArr[0] = 0;
     116                 :          0 :     FillListBoxes();
     117                 :          0 : }
     118                 :            : 
     119                 :            : // -----------------------------------------------------------------------
     120                 :            : 
     121                 :          0 : bool ScTpSubTotalGroup::DoReset( sal_uInt16             nGroupNo,
     122                 :            :                                  const SfxItemSet&  rArgSet  )
     123                 :            : {
     124                 :          0 :     sal_uInt16 nGroupIdx = 0;
     125                 :            : 
     126                 :            :     OSL_ENSURE( (nGroupNo<=3) && (nGroupNo>0), "Invalid group" );
     127                 :            : 
     128                 :          0 :     if ( (nGroupNo > 3) || (nGroupNo == 0) )
     129                 :          0 :         return false;
     130                 :            :     else
     131                 :          0 :         nGroupIdx = nGroupNo-1;
     132                 :            : 
     133                 :            :     //----------------------------------------------------------
     134                 :            : 
     135                 :            :     // first we have to clear the listboxes...
     136                 :          0 :     for ( sal_uInt16 nLbEntry = 0; nLbEntry < aLbColumns.GetEntryCount(); ++nLbEntry )
     137                 :            :     {
     138                 :          0 :         aLbColumns.CheckEntryPos( nLbEntry, false );
     139                 :          0 :         *((sal_uInt16*)aLbColumns.GetEntryData( nLbEntry )) = 0;
     140                 :            :     }
     141                 :          0 :     aLbFunctions.SelectEntryPos( 0 );
     142                 :            : 
     143                 :            :     ScSubTotalParam theSubTotalData( ((const ScSubTotalItem&)
     144                 :          0 :                                       rArgSet.Get( nWhichSubTotals )).
     145                 :          0 :                                             GetSubTotalData() );
     146                 :            : 
     147                 :          0 :     if ( theSubTotalData.bGroupActive[nGroupIdx] )
     148                 :            :     {
     149                 :          0 :         SCCOL           nField      = theSubTotalData.nField[nGroupIdx];
     150                 :          0 :         SCCOL           nSubTotals  = theSubTotalData.nSubTotals[nGroupIdx];
     151                 :          0 :         SCCOL*          pSubTotals  = theSubTotalData.pSubTotals[nGroupIdx];
     152                 :          0 :         ScSubTotalFunc* pFunctions  = theSubTotalData.pFunctions[nGroupIdx];
     153                 :            : 
     154                 :          0 :         aLbGroup.SelectEntryPos( GetFieldSelPos( nField )+1 );
     155                 :            : 
     156                 :          0 :         sal_uInt16 nFirstChecked = 0;
     157                 :          0 :         for ( sal_uInt16 i=0; i<nSubTotals; i++ )
     158                 :            :         {
     159                 :          0 :             sal_uInt16  nCheckPos = GetFieldSelPos( pSubTotals[i] );
     160                 :          0 :             sal_uInt16* pFunction = (sal_uInt16*)aLbColumns.GetEntryData( nCheckPos );
     161                 :            : 
     162                 :          0 :             aLbColumns.CheckEntryPos( nCheckPos );
     163                 :          0 :             *pFunction = FuncToLbPos( pFunctions[i] );
     164                 :            : 
     165                 :          0 :             if (i == 0 || (i > 0 && nCheckPos < nFirstChecked))
     166                 :          0 :                 nFirstChecked = nCheckPos;
     167                 :            :         }
     168                 :            :         // Select the first checked field from the top.
     169                 :          0 :         aLbColumns.SelectEntryPos(nFirstChecked);
     170                 :            :     }
     171                 :            :     else
     172                 :            :     {
     173                 :          0 :         aLbGroup.SelectEntryPos( (nGroupNo == 1) ? 1 : 0 );
     174                 :          0 :         aLbColumns.SelectEntryPos( 0 );
     175                 :          0 :         aLbFunctions.SelectEntryPos( 0 );
     176                 :            :     }
     177                 :            : 
     178                 :          0 :     return true;
     179                 :            : }
     180                 :            : 
     181                 :            : // -----------------------------------------------------------------------
     182                 :            : 
     183                 :          0 : bool ScTpSubTotalGroup::DoFillItemSet( sal_uInt16       nGroupNo,
     184                 :            :                                        SfxItemSet&  rArgSet  )
     185                 :            : {
     186                 :          0 :     sal_uInt16 nGroupIdx = 0;
     187                 :            : 
     188                 :            :     OSL_ENSURE( (nGroupNo<=3) && (nGroupNo>0), "Invalid group" );
     189                 :            :     OSL_ENSURE(    (aLbGroup.GetEntryCount() > 0)
     190                 :            :                 && (aLbColumns.GetEntryCount() > 0)
     191                 :            :                 && (aLbFunctions.GetEntryCount() > 0),
     192                 :            :                 "Non-initialized Lists" );
     193                 :            : 
     194                 :            : 
     195                 :          0 :     if (  (nGroupNo > 3) || (nGroupNo == 0)
     196                 :          0 :         || (aLbGroup.GetEntryCount() == 0)
     197                 :          0 :         || (aLbColumns.GetEntryCount() == 0)
     198                 :          0 :         || (aLbFunctions.GetEntryCount() == 0)
     199                 :            :        )
     200                 :          0 :         return false;
     201                 :            :     else
     202                 :          0 :         nGroupIdx = nGroupNo-1;
     203                 :            : 
     204                 :            :     //----------------------------------------------------------
     205                 :            : 
     206                 :          0 :     ScSubTotalParam theSubTotalData;            // auslesen, wenn schon teilweise gefuellt
     207                 :          0 :     SfxTabDialog* pDlg = GetTabDialog();
     208                 :          0 :     if ( pDlg )
     209                 :            :     {
     210                 :          0 :         const SfxItemSet* pExample = pDlg->GetExampleSet();
     211                 :            :         const SfxPoolItem* pItem;
     212                 :          0 :         if ( pExample && pExample->GetItemState( nWhichSubTotals, true, &pItem ) == SFX_ITEM_SET )
     213                 :          0 :             theSubTotalData = ((const ScSubTotalItem*)pItem)->GetSubTotalData();
     214                 :            :     }
     215                 :            : 
     216                 :          0 :     ScSubTotalFunc* pFunctions  = NULL;
     217                 :          0 :     SCCOL*          pSubTotals  = NULL;
     218                 :          0 :     sal_uInt16          nGroup      = aLbGroup.GetSelectEntryPos();
     219                 :          0 :     sal_uInt16          nEntryCount = (sal_uInt16)aLbColumns.GetEntryCount();
     220                 :          0 :     sal_uInt16          nCheckCount = aLbColumns.GetCheckedEntryCount();
     221                 :            : 
     222                 :          0 :     theSubTotalData.nCol1                   = rSubTotalData.nCol1;
     223                 :          0 :     theSubTotalData.nRow1                   = rSubTotalData.nRow1;
     224                 :          0 :     theSubTotalData.nCol2                   = rSubTotalData.nCol2;
     225                 :          0 :     theSubTotalData.nRow2                   = rSubTotalData.nRow2;
     226                 :          0 :     theSubTotalData.bGroupActive[nGroupIdx] = (nGroup != 0);
     227                 :          0 :     theSubTotalData.nField[nGroupIdx]       = (nGroup != 0)
     228                 :          0 :                                                 ? nFieldArr[nGroup-1]
     229                 :          0 :                                                 : static_cast<SCCOL>(0);
     230                 :            : 
     231                 :          0 :     if ( nEntryCount>0 && nCheckCount>0 && nGroup!=0 )
     232                 :            :     {
     233                 :          0 :         sal_uInt16 nFunction    = 0;
     234                 :            : 
     235                 :          0 :         pSubTotals = new SCCOL          [nCheckCount];
     236                 :          0 :         pFunctions = new ScSubTotalFunc [nCheckCount];
     237                 :            : 
     238                 :          0 :         for ( sal_uInt16 i=0, nCheck=0; i<nEntryCount; i++ )
     239                 :            :         {
     240                 :          0 :             if ( aLbColumns.IsChecked( i ) )
     241                 :            :             {
     242                 :            :                 OSL_ENSURE( nCheck <= nCheckCount,
     243                 :            :                             "Range error :-(" );
     244                 :          0 :                 nFunction = *((sal_uInt16*)aLbColumns.GetEntryData( i ));
     245                 :          0 :                 pSubTotals[nCheck] = nFieldArr[i];
     246                 :          0 :                 pFunctions[nCheck] = LbPosToFunc( nFunction );
     247                 :          0 :                 nCheck++;
     248                 :            :             }
     249                 :            :         }
     250                 :            :         theSubTotalData.SetSubTotals( nGroupNo,      // Gruppen-Nr.
     251                 :            :                                       pSubTotals,
     252                 :            :                                       pFunctions,
     253                 :          0 :                                       nCheckCount ); // Anzahl der Array-Elemente
     254                 :            : 
     255                 :            :     }
     256                 :            : 
     257                 :          0 :     rArgSet.Put( ScSubTotalItem( SCITEM_SUBTDATA, &theSubTotalData ) );
     258                 :            : 
     259                 :          0 :     if ( pSubTotals ) delete [] pSubTotals;
     260                 :          0 :     if ( pFunctions ) delete [] pFunctions;
     261                 :            : 
     262                 :          0 :     return true;
     263                 :            : }
     264                 :            : 
     265                 :            : // -----------------------------------------------------------------------
     266                 :            : 
     267                 :          0 : void ScTpSubTotalGroup::FillListBoxes()
     268                 :            : {
     269                 :            :     OSL_ENSURE( pViewData && pDoc, "ViewData or Document not found :-/" );
     270                 :            : 
     271                 :          0 :     if ( pViewData && pDoc )
     272                 :            :     {
     273                 :          0 :         SCCOL   nFirstCol   = rSubTotalData.nCol1;
     274                 :          0 :         SCROW   nFirstRow   = rSubTotalData.nRow1;
     275                 :          0 :         SCTAB   nTab        = pViewData->GetTabNo();
     276                 :          0 :         SCCOL   nMaxCol     = rSubTotalData.nCol2;
     277                 :            :         SCCOL   col;
     278                 :          0 :         sal_uInt16  i=0;
     279                 :          0 :         rtl::OUString  aFieldName;
     280                 :            : 
     281                 :          0 :         aLbGroup.Clear();
     282                 :          0 :         aLbColumns.Clear();
     283                 :          0 :         aLbGroup.InsertEntry( aStrNone, 0 );
     284                 :            : 
     285                 :          0 :         i=0;
     286                 :          0 :         for ( col=nFirstCol; col<=nMaxCol && i<SC_MAXFIELDS; col++ )
     287                 :            :         {
     288                 :          0 :             pDoc->GetString( col, nFirstRow, nTab, aFieldName );
     289                 :          0 :             if ( aFieldName.isEmpty() )
     290                 :            :             {
     291                 :          0 :                rtl::OUStringBuffer aBuf;
     292                 :          0 :                 aBuf.append(aStrColumn);
     293                 :          0 :                 aFieldName = aBuf.makeStringAndClear().replaceAll("%1", ScColToAlpha( col ));
     294                 :            :             }
     295                 :          0 :             nFieldArr[i] = col;
     296                 :          0 :             aLbGroup.InsertEntry( aFieldName, i+1 );
     297                 :          0 :             aLbColumns.InsertEntry( aFieldName, i );
     298                 :          0 :             aLbColumns.SetEntryData( i, new sal_uInt16(0) );
     299                 :          0 :             i++;
     300                 :            :         }
     301                 :            :         // Nachtraegliche "Konstanteninitialisierung":
     302                 :          0 :         (sal_uInt16&)nFieldCount = i;
     303                 :            :     }
     304                 :          0 : }
     305                 :            : 
     306                 :            : // -----------------------------------------------------------------------
     307                 :            : 
     308                 :          0 : sal_uInt16 ScTpSubTotalGroup::GetFieldSelPos( SCCOL nField )
     309                 :            : {
     310                 :          0 :     sal_uInt16  nFieldPos   = 0;
     311                 :          0 :     bool    bFound      = false;
     312                 :            : 
     313                 :          0 :     for ( sal_uInt16 n=0; n<nFieldCount && !bFound; n++ )
     314                 :            :     {
     315                 :          0 :         if ( nFieldArr[n] == nField )
     316                 :            :         {
     317                 :          0 :             nFieldPos = n;
     318                 :          0 :             bFound = true;
     319                 :            :         }
     320                 :            :     }
     321                 :            : 
     322                 :          0 :     return nFieldPos;
     323                 :            : }
     324                 :            : 
     325                 :            : // -----------------------------------------------------------------------
     326                 :            : 
     327                 :          0 : ScSubTotalFunc ScTpSubTotalGroup::LbPosToFunc( sal_uInt16 nPos )
     328                 :            : {
     329                 :          0 :     switch ( nPos )
     330                 :            :     {
     331                 :            : //      case  0:    return SUBTOTAL_FUNC_NONE;
     332                 :          0 :         case  2:    return SUBTOTAL_FUNC_AVE;
     333                 :          0 :         case  6:    return SUBTOTAL_FUNC_CNT;
     334                 :          0 :         case  1:    return SUBTOTAL_FUNC_CNT2;
     335                 :          0 :         case  3:    return SUBTOTAL_FUNC_MAX;
     336                 :          0 :         case  4:    return SUBTOTAL_FUNC_MIN;
     337                 :          0 :         case  5:    return SUBTOTAL_FUNC_PROD;
     338                 :          0 :         case  7:    return SUBTOTAL_FUNC_STD;
     339                 :          0 :         case  8:    return SUBTOTAL_FUNC_STDP;
     340                 :          0 :         case  0:    return SUBTOTAL_FUNC_SUM;
     341                 :          0 :         case  9:    return SUBTOTAL_FUNC_VAR;
     342                 :          0 :         case 10:    return SUBTOTAL_FUNC_VARP;
     343                 :            :         default:
     344                 :            :             OSL_FAIL( "ScTpSubTotalGroup::LbPosToFunc" );
     345                 :          0 :             return SUBTOTAL_FUNC_NONE;
     346                 :            :     }
     347                 :            : }
     348                 :            : 
     349                 :            : // -----------------------------------------------------------------------
     350                 :            : 
     351                 :          0 : sal_uInt16 ScTpSubTotalGroup::FuncToLbPos( ScSubTotalFunc eFunc )
     352                 :            : {
     353                 :          0 :     switch ( eFunc )
     354                 :            :     {
     355                 :            : //      case SUBTOTAL_FUNC_NONE:    return 0;
     356                 :          0 :         case SUBTOTAL_FUNC_AVE:     return 2;
     357                 :          0 :         case SUBTOTAL_FUNC_CNT:     return 6;
     358                 :          0 :         case SUBTOTAL_FUNC_CNT2:    return 1;
     359                 :          0 :         case SUBTOTAL_FUNC_MAX:     return 3;
     360                 :          0 :         case SUBTOTAL_FUNC_MIN:     return 4;
     361                 :          0 :         case SUBTOTAL_FUNC_PROD:    return 5;
     362                 :          0 :         case SUBTOTAL_FUNC_STD:     return 7;
     363                 :          0 :         case SUBTOTAL_FUNC_STDP:    return 8;
     364                 :          0 :         case SUBTOTAL_FUNC_SUM:     return 0;
     365                 :          0 :         case SUBTOTAL_FUNC_VAR:     return 9;
     366                 :          0 :         case SUBTOTAL_FUNC_VARP:    return 10;
     367                 :            :         default:
     368                 :            :             OSL_FAIL( "ScTpSubTotalGroup::FuncToLbPos" );
     369                 :          0 :             return 0;
     370                 :            :     }
     371                 :            : }
     372                 :            : 
     373                 :            : // -----------------------------------------------------------------------
     374                 :            : // Handler:
     375                 :            : //---------
     376                 :            : 
     377                 :          0 : IMPL_LINK( ScTpSubTotalGroup, SelectHdl, ListBox *, pLb )
     378                 :            : {
     379                 :          0 :     if (   (aLbColumns.GetEntryCount() > 0)
     380                 :          0 :         && (aLbColumns.GetSelectionCount() > 0) )
     381                 :            :     {
     382                 :          0 :         sal_uInt16      nFunction   = aLbFunctions.GetSelectEntryPos();
     383                 :          0 :         sal_uInt16      nColumn     = aLbColumns.GetSelectEntryPos();
     384                 :          0 :         sal_uInt16*     pFunction   = (sal_uInt16*)aLbColumns.GetEntryData( nColumn );
     385                 :            : 
     386                 :            :         OSL_ENSURE( pFunction, "EntryData nicht gefunden!" );
     387                 :          0 :         if ( !pFunction )
     388                 :          0 :             return 0;
     389                 :            : 
     390                 :          0 :         if ( ((SvxCheckListBox*)pLb) == &aLbColumns )
     391                 :            :         {
     392                 :          0 :             aLbFunctions.SelectEntryPos( *pFunction );
     393                 :            :         }
     394                 :          0 :         else if ( pLb == &aLbFunctions )
     395                 :            :         {
     396                 :          0 :             *pFunction = nFunction;
     397                 :          0 :             aLbColumns.CheckEntryPos( nColumn, true );
     398                 :            :         }
     399                 :            :     }
     400                 :          0 :     return 0;
     401                 :            : }
     402                 :            : 
     403                 :            : // -----------------------------------------------------------------------
     404                 :            : 
     405                 :          0 : IMPL_LINK( ScTpSubTotalGroup, CheckHdl, ListBox *, pLb )
     406                 :            : {
     407                 :          0 :     if ( ((SvxCheckListBox*)pLb) == &aLbColumns )
     408                 :            :     {
     409                 :          0 :         SvLBoxEntry* pEntry = aLbColumns.GetHdlEntry();
     410                 :            : 
     411                 :          0 :         if ( pEntry )
     412                 :            :         {
     413                 :          0 :             aLbColumns.SelectEntryPos( (sal_uInt16)aLbColumns.GetModel()->GetAbsPos( pEntry ) );
     414                 :          0 :             SelectHdl( pLb );
     415                 :            :         }
     416                 :            :     }
     417                 :          0 :     return 0;
     418                 :            : }
     419                 :            : 
     420                 :            : //========================================================================
     421                 :            : // Abgeleitete Gruppen-TabPages:
     422                 :            : 
     423                 :          0 : SfxTabPage* ScTpSubTotalGroup1::Create( Window*         pParent,
     424                 :            :                                                  const SfxItemSet&  rArgSet )
     425                 :          0 :     { return ( new ScTpSubTotalGroup1( pParent, rArgSet ) ); }
     426                 :            : 
     427                 :            : // -----------------------------------------------------------------------
     428                 :            : 
     429                 :          0 : SfxTabPage* ScTpSubTotalGroup2::Create( Window*          pParent,
     430                 :            :                                        const SfxItemSet&    rArgSet )
     431                 :          0 :     { return ( new ScTpSubTotalGroup2( pParent, rArgSet ) ); }
     432                 :            : 
     433                 :            : // -----------------------------------------------------------------------
     434                 :            : 
     435                 :          0 : SfxTabPage* ScTpSubTotalGroup3::Create( Window*          pParent,
     436                 :            :                                        const SfxItemSet&    rArgSet )
     437                 :          0 :     { return ( new ScTpSubTotalGroup3( pParent, rArgSet ) ); }
     438                 :            : 
     439                 :            : // -----------------------------------------------------------------------
     440                 :            : 
     441                 :          0 : ScTpSubTotalGroup1::ScTpSubTotalGroup1( Window* pParent, const SfxItemSet& rArgSet ) :
     442                 :          0 :     ScTpSubTotalGroup( pParent, RID_SCPAGE_SUBT_GROUP1, rArgSet )
     443                 :          0 : {}
     444                 :            : 
     445                 :          0 : ScTpSubTotalGroup2::ScTpSubTotalGroup2( Window* pParent, const SfxItemSet& rArgSet ) :
     446                 :          0 :     ScTpSubTotalGroup( pParent, RID_SCPAGE_SUBT_GROUP2, rArgSet )
     447                 :          0 : {}
     448                 :            : 
     449                 :          0 : ScTpSubTotalGroup3::ScTpSubTotalGroup3( Window* pParent, const SfxItemSet& rArgSet ) :
     450                 :          0 :     ScTpSubTotalGroup( pParent, RID_SCPAGE_SUBT_GROUP3, rArgSet )
     451                 :          0 : {}
     452                 :            : 
     453                 :            : // -----------------------------------------------------------------------
     454                 :            : 
     455                 :            : 
     456                 :            : #define RESET(i) (ScTpSubTotalGroup::DoReset( (i), rArgSet ))
     457                 :          0 : void ScTpSubTotalGroup1::Reset( const SfxItemSet& rArgSet ) { RESET(1); }
     458                 :          0 : void ScTpSubTotalGroup2::Reset( const SfxItemSet& rArgSet ) { RESET(2); }
     459                 :          0 : void ScTpSubTotalGroup3::Reset( const SfxItemSet& rArgSet ) { RESET(3); }
     460                 :            : #undef RESET
     461                 :            : 
     462                 :            : // -----------------------------------------------------------------------
     463                 :            : 
     464                 :            : #define FILLSET(i) (ScTpSubTotalGroup::DoFillItemSet( (i), rArgSet ))
     465                 :          0 : sal_Bool ScTpSubTotalGroup1::FillItemSet( SfxItemSet& rArgSet ) { return FILLSET(1); }
     466                 :          0 : sal_Bool ScTpSubTotalGroup2::FillItemSet( SfxItemSet& rArgSet ) { return FILLSET(2); }
     467                 :          0 : sal_Bool ScTpSubTotalGroup3::FillItemSet( SfxItemSet& rArgSet ) { return FILLSET(3); }
     468                 :            : #undef FILL
     469                 :            : 
     470                 :            : //========================================================================
     471                 :            : // Optionen-Tabpage:
     472                 :            : 
     473                 :          0 : ScTpSubTotalOptions::ScTpSubTotalOptions( Window*               pParent,
     474                 :            :                                           const SfxItemSet&     rArgSet )
     475                 :            : 
     476                 :            :         :   SfxTabPage      ( pParent,
     477                 :            :                               ScResId( RID_SCPAGE_SUBT_OPTIONS ),
     478                 :            :                               rArgSet ),
     479                 :            :             aFlGroup        ( this, ScResId( FL_GROUP ) ),
     480                 :            :             aBtnPagebreak   ( this, ScResId( BTN_PAGEBREAK ) ),
     481                 :            :             aBtnCase        ( this, ScResId( BTN_CASE ) ),
     482                 :            :             aBtnSort        ( this, ScResId( BTN_SORT ) ),
     483                 :            :             aFlSort         ( this, ScResId( FL_SORT ) ),
     484                 :            :             aBtnAscending   ( this, ScResId( BTN_ASCENDING ) ),
     485                 :            :             aBtnDescending  ( this, ScResId( BTN_DESCENDING ) ),
     486                 :            :             aBtnFormats     ( this, ScResId( BTN_FORMATS ) ),
     487                 :            :             aBtnUserDef     ( this, ScResId( BTN_USERDEF ) ),
     488                 :            :             aLbUserDef      ( this, ScResId( LB_USERDEF ) ),
     489                 :            :             pViewData       ( NULL ),
     490                 :            :             pDoc            ( NULL ),
     491                 :          0 :             nWhichSubTotals ( rArgSet.GetPool()->GetWhich( SID_SUBTOTALS ) ),
     492                 :            :             rSubTotalData   ( ((const ScSubTotalItem&)
     493                 :          0 :                               rArgSet.Get( nWhichSubTotals )).
     494                 :          0 :                                 GetSubTotalData() )
     495                 :            : {
     496                 :          0 :     Init();
     497                 :          0 :     FreeResource();
     498                 :            : 
     499                 :          0 :     aLbUserDef.SetAccessibleRelationLabeledBy(&aBtnUserDef);
     500                 :          0 :     aLbUserDef.SetAccessibleName(aBtnUserDef.GetText());
     501                 :          0 : }
     502                 :            : 
     503                 :            : // -----------------------------------------------------------------------
     504                 :            : 
     505                 :          0 : ScTpSubTotalOptions::~ScTpSubTotalOptions()
     506                 :            : {
     507                 :          0 : }
     508                 :            : 
     509                 :            : // -----------------------------------------------------------------------
     510                 :            : 
     511                 :          0 : void ScTpSubTotalOptions::Init()
     512                 :            : {
     513                 :            :     const ScSubTotalItem& rSubTotalItem = (const ScSubTotalItem&)
     514                 :          0 :                                           GetItemSet().Get( nWhichSubTotals );
     515                 :            : 
     516                 :          0 :     pViewData   = rSubTotalItem.GetViewData();
     517                 :          0 :     pDoc        = ( pViewData ) ? pViewData->GetDocument() : NULL;
     518                 :            : 
     519                 :            :     OSL_ENSURE( pViewData && pDoc, "ViewData oder Document nicht gefunden!" );
     520                 :            : 
     521                 :          0 :     aBtnSort.SetClickHdl    ( LINK( this, ScTpSubTotalOptions, CheckHdl ) );
     522                 :          0 :     aBtnUserDef.SetClickHdl ( LINK( this, ScTpSubTotalOptions, CheckHdl ) );
     523                 :            : 
     524                 :          0 :     FillUserSortListBox();
     525                 :          0 : }
     526                 :            : 
     527                 :            : // -----------------------------------------------------------------------
     528                 :            : 
     529                 :          0 : SfxTabPage* ScTpSubTotalOptions::Create( Window*                 pParent,
     530                 :            :                                           const SfxItemSet&     rArgSet )
     531                 :            : {
     532                 :          0 :     return ( new ScTpSubTotalOptions( pParent, rArgSet ) );
     533                 :            : }
     534                 :            : 
     535                 :            : // -----------------------------------------------------------------------
     536                 :            : 
     537                 :          0 : void ScTpSubTotalOptions::Reset( const SfxItemSet& /* rArgSet */ )
     538                 :            : {
     539                 :          0 :     aBtnPagebreak.Check ( rSubTotalData.bPagebreak );
     540                 :          0 :     aBtnCase.Check      ( rSubTotalData.bCaseSens );
     541                 :          0 :     aBtnFormats.Check   ( rSubTotalData.bIncludePattern );
     542                 :          0 :     aBtnSort.Check      ( rSubTotalData.bDoSort );
     543                 :          0 :     aBtnAscending.Check ( rSubTotalData.bAscending );
     544                 :          0 :     aBtnDescending.Check( !rSubTotalData.bAscending );
     545                 :            : 
     546                 :          0 :     if ( rSubTotalData.bUserDef )
     547                 :            :     {
     548                 :          0 :         aBtnUserDef.Check( true );
     549                 :          0 :         aLbUserDef.Enable();
     550                 :          0 :         aLbUserDef.SelectEntryPos( rSubTotalData.nUserIndex );
     551                 :            :     }
     552                 :            :     else
     553                 :            :     {
     554                 :          0 :         aBtnUserDef.Check( false );
     555                 :          0 :         aLbUserDef.Disable();
     556                 :          0 :         aLbUserDef.SelectEntryPos( 0 );
     557                 :            :     }
     558                 :            : 
     559                 :          0 :     CheckHdl( &aBtnSort );
     560                 :          0 : }
     561                 :            : 
     562                 :            : // -----------------------------------------------------------------------
     563                 :            : 
     564                 :          0 : sal_Bool ScTpSubTotalOptions::FillItemSet( SfxItemSet& rArgSet )
     565                 :            : {
     566                 :          0 :     ScSubTotalParam theSubTotalData;            // auslesen, wenn schon teilweise gefuellt
     567                 :          0 :     SfxTabDialog* pDlg = GetTabDialog();
     568                 :          0 :     if ( pDlg )
     569                 :            :     {
     570                 :          0 :         const SfxItemSet* pExample = pDlg->GetExampleSet();
     571                 :            :         const SfxPoolItem* pItem;
     572                 :          0 :         if ( pExample && pExample->GetItemState( nWhichSubTotals, true, &pItem ) == SFX_ITEM_SET )
     573                 :          0 :             theSubTotalData = ((const ScSubTotalItem*)pItem)->GetSubTotalData();
     574                 :            :     }
     575                 :            : 
     576                 :          0 :     theSubTotalData.bPagebreak      = aBtnPagebreak.IsChecked();
     577                 :          0 :     theSubTotalData.bReplace        = true;
     578                 :          0 :     theSubTotalData.bCaseSens       = aBtnCase.IsChecked();
     579                 :          0 :     theSubTotalData.bIncludePattern = aBtnFormats.IsChecked();
     580                 :          0 :     theSubTotalData.bDoSort         = aBtnSort.IsChecked();
     581                 :          0 :     theSubTotalData.bAscending      = aBtnAscending.IsChecked();
     582                 :          0 :     theSubTotalData.bUserDef        = aBtnUserDef.IsChecked();
     583                 :          0 :     theSubTotalData.nUserIndex      = (aBtnUserDef.IsChecked())
     584                 :          0 :                                     ? aLbUserDef.GetSelectEntryPos()
     585                 :          0 :                                     : 0;
     586                 :            : 
     587                 :          0 :     rArgSet.Put( ScSubTotalItem( nWhichSubTotals, &theSubTotalData ) );
     588                 :            : 
     589                 :          0 :     return true;
     590                 :            : }
     591                 :            : 
     592                 :            : // -----------------------------------------------------------------------
     593                 :            : 
     594                 :          0 : void ScTpSubTotalOptions::FillUserSortListBox()
     595                 :            : {
     596                 :          0 :     ScUserList* pUserLists = ScGlobal::GetUserList();
     597                 :            : 
     598                 :          0 :     aLbUserDef.Clear();
     599                 :          0 :     if ( pUserLists )
     600                 :            :     {
     601                 :          0 :         size_t nCount = pUserLists->size();
     602                 :          0 :         for ( size_t i=0; i<nCount; ++i )
     603                 :          0 :             aLbUserDef.InsertEntry( (*pUserLists)[i]->GetString() );
     604                 :            :     }
     605                 :          0 : }
     606                 :            : 
     607                 :            : // -----------------------------------------------------------------------
     608                 :            : // Handler:
     609                 :            : 
     610                 :          0 : IMPL_LINK( ScTpSubTotalOptions, CheckHdl, CheckBox *, pBox )
     611                 :            : {
     612                 :          0 :     if ( pBox == &aBtnSort )
     613                 :            :     {
     614                 :          0 :         if ( aBtnSort.IsChecked() )
     615                 :            :         {
     616                 :          0 :             aFlSort         .Enable();
     617                 :          0 :             aBtnFormats     .Enable();
     618                 :          0 :             aBtnUserDef     .Enable();
     619                 :          0 :             aBtnAscending   .Enable();
     620                 :          0 :             aBtnDescending  .Enable();
     621                 :            : 
     622                 :          0 :             if ( aBtnUserDef.IsChecked() )
     623                 :          0 :                 aLbUserDef.Enable();
     624                 :            :         }
     625                 :            :         else
     626                 :            :         {
     627                 :          0 :             aFlSort         .Disable();
     628                 :          0 :             aBtnFormats     .Disable();
     629                 :          0 :             aBtnUserDef     .Disable();
     630                 :          0 :             aBtnAscending   .Disable();
     631                 :          0 :             aBtnDescending  .Disable();
     632                 :          0 :             aLbUserDef      .Disable();
     633                 :            :         }
     634                 :            :     }
     635                 :          0 :     else if ( pBox == &aBtnUserDef )
     636                 :            :     {
     637                 :          0 :         if ( aBtnUserDef.IsChecked() )
     638                 :            :         {
     639                 :          0 :             aLbUserDef.Enable();
     640                 :          0 :             aLbUserDef.GrabFocus();
     641                 :            :         }
     642                 :            :         else
     643                 :          0 :             aLbUserDef.Disable();
     644                 :            :     }
     645                 :            : 
     646                 :          0 :     return 0;
     647                 :            : }
     648                 :            : 
     649                 :          0 : ScTpSubTotalGroup1::~ScTpSubTotalGroup1()
     650                 :            : {
     651                 :          0 : }
     652                 :            : 
     653                 :          0 : ScTpSubTotalGroup2::~ScTpSubTotalGroup2()
     654                 :            : {
     655                 :          0 : }
     656                 :            : 
     657                 :          0 : ScTpSubTotalGroup3::~ScTpSubTotalGroup3()
     658                 :            : {
     659                 :          0 : }
     660                 :            : 
     661                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10