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