LCOV - code coverage report
Current view: top level - sc/source/ui/dbgui - dpgroupdlg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 161 0.0 %
Date: 2014-04-14 Functions: 0 23 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #ifdef SC_DLLIMPLEMENTATION
      22             : #undef SC_DLLIMPLEMENTATION
      23             : #endif
      24             : 
      25             : 
      26             : #include "dpgroupdlg.hxx"
      27             : #include "scresid.hxx"
      28             : #include "sc.hrc"
      29             : #include "globstr.hrc"
      30             : 
      31             : #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
      32             : 
      33             : namespace {
      34             : 
      35             : /** Date part flags in order of the list box entries. */
      36             : static const sal_Int32 spnDateParts[] =
      37             : {
      38             :     com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS,
      39             :     com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES,
      40             :     com::sun::star::sheet::DataPilotFieldGroupBy::HOURS,
      41             :     com::sun::star::sheet::DataPilotFieldGroupBy::DAYS,
      42             :     com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS,
      43             :     com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS,
      44             :     com::sun::star::sheet::DataPilotFieldGroupBy::YEARS
      45             : };
      46             : 
      47             : static const sal_uInt16 nDatePartResIds[] =
      48             : {
      49             :     STR_DPFIELD_GROUP_BY_SECONDS,
      50             :     STR_DPFIELD_GROUP_BY_MINUTES,
      51             :     STR_DPFIELD_GROUP_BY_HOURS,
      52             :     STR_DPFIELD_GROUP_BY_DAYS,
      53             :     STR_DPFIELD_GROUP_BY_MONTHS,
      54             :     STR_DPFIELD_GROUP_BY_QUARTERS,
      55             :     STR_DPFIELD_GROUP_BY_YEARS
      56             : };
      57             : 
      58             : } // namespace
      59             : 
      60           0 : ScDPGroupEditHelper::ScDPGroupEditHelper( RadioButton* pRbAuto, RadioButton* pRbMan, Edit* pEdValue ) :
      61             :     mpRbAuto( pRbAuto ),
      62             :     mpRbMan( pRbMan ),
      63           0 :     mpEdValue( pEdValue )
      64             : {
      65           0 :     mpRbAuto->SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
      66           0 :     mpRbMan->SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
      67           0 : }
      68             : 
      69           0 : bool ScDPGroupEditHelper::IsAuto() const
      70             : {
      71           0 :     return mpRbAuto->IsChecked();
      72             : }
      73             : 
      74           0 : double ScDPGroupEditHelper::GetValue() const
      75             : {
      76             :     double fValue;
      77           0 :     if( !ImplGetValue( fValue ) )
      78           0 :         fValue = 0.0;
      79           0 :     return fValue;
      80             : }
      81             : 
      82           0 : void ScDPGroupEditHelper::SetValue( bool bAuto, double fValue )
      83             : {
      84           0 :     if( bAuto )
      85             :     {
      86           0 :         mpRbAuto->Check();
      87           0 :         ClickHdl( mpRbAuto );
      88             :     }
      89             :     else
      90             :     {
      91           0 :         mpRbMan->Check();
      92           0 :         ClickHdl( mpRbMan );
      93             :     }
      94           0 :     ImplSetValue( fValue );
      95           0 : }
      96             : 
      97           0 : IMPL_LINK( ScDPGroupEditHelper, ClickHdl, RadioButton*, pButton )
      98             : {
      99           0 :     if( pButton == mpRbAuto )
     100             :     {
     101             :         // disable edit field on clicking "automatic" radio button
     102           0 :         mpEdValue->Disable();
     103             :     }
     104           0 :     else if( pButton == mpRbMan )
     105             :     {
     106             :         // enable and set focus to edit field on clicking "manual" radio button
     107           0 :         mpEdValue->Enable();
     108           0 :         mpEdValue->GrabFocus();
     109             :     }
     110           0 :     return 0;
     111             : }
     112             : 
     113           0 : ScDPNumGroupEditHelper::ScDPNumGroupEditHelper(
     114             :         RadioButton* pRbAuto, RadioButton* pRbMan, ScDoubleField* pEdValue ) :
     115             :     ScDPGroupEditHelper( pRbAuto, pRbMan, pEdValue ),
     116           0 :     mpEdValue( pEdValue )
     117             : {
     118           0 : }
     119             : 
     120           0 : bool ScDPNumGroupEditHelper::ImplGetValue( double& rfValue ) const
     121             : {
     122           0 :     return mpEdValue->GetValue( rfValue );
     123             : }
     124             : 
     125           0 : void ScDPNumGroupEditHelper::ImplSetValue( double fValue )
     126             : {
     127           0 :     mpEdValue->SetValue( fValue );
     128           0 : }
     129             : 
     130           0 : ScDPDateGroupEditHelper::ScDPDateGroupEditHelper(
     131             :         RadioButton* pRbAuto, RadioButton* pRbMan, DateField* pEdValue, const Date& rNullDate ) :
     132             :     ScDPGroupEditHelper( pRbAuto, pRbMan, pEdValue ),
     133             :     mpEdValue( pEdValue ),
     134           0 :     maNullDate( rNullDate )
     135             : {
     136           0 : }
     137             : 
     138           0 : bool ScDPDateGroupEditHelper::ImplGetValue( double& rfValue ) const
     139             : {
     140           0 :     rfValue = mpEdValue->GetDate() - maNullDate;
     141           0 :     return true;
     142             : }
     143             : 
     144           0 : void ScDPDateGroupEditHelper::ImplSetValue( double fValue )
     145             : {
     146           0 :     Date aDate( maNullDate );
     147           0 :     aDate += static_cast< sal_Int32 >( fValue );
     148           0 :     mpEdValue->SetDate( aDate );
     149           0 : }
     150             : 
     151             : 
     152           0 : ScDPNumGroupDlg::ScDPNumGroupDlg( Window* pParent, const ScDPNumGroupInfo& rInfo ) :
     153             :     ModalDialog     ( pParent, "PivotTableGroupByNumber", "modules/scalc/ui/groupbynumber.ui" ),
     154           0 :     mpRbAutoStart   ( get<RadioButton>("auto_start") ),
     155           0 :     mpRbManStart    ( get<RadioButton>("manual_start") ),
     156           0 :     mpEdStart       ( get<ScDoubleField> ("edit_start") ),
     157           0 :     mpRbAutoEnd     ( get<RadioButton> ( "auto_end" ) ),
     158           0 :     mpRbManEnd      ( get<RadioButton> ("manual_end") ),
     159           0 :     mpEdEnd         ( get<ScDoubleField>( "edit_end") ),
     160           0 :     mpEdBy          ( get<ScDoubleField> ("edit_by") ),
     161           0 :     mpBtnOk         ( get<OKButton> ("ok" ) ),
     162             :     maStartHelper   ( mpRbAutoStart, mpRbManStart, mpEdStart ),
     163           0 :     maEndHelper     ( mpRbAutoEnd, mpRbManEnd, mpEdEnd )
     164             : {
     165             : 
     166           0 :     maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
     167           0 :     maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
     168           0 :     mpEdBy->SetValue( (rInfo.mfStep <= 0.0) ? 1.0 : rInfo.mfStep );
     169             : 
     170             :     /*  Set the initial focus, currently it is somewhere after calling all the radio
     171             :         button click handlers. Now the first enabled editable control is focused. */
     172           0 :     if( mpEdStart->IsEnabled() )
     173           0 :         mpEdStart->GrabFocus();
     174           0 :     else if( mpEdEnd->IsEnabled() )
     175           0 :         mpEdEnd->GrabFocus();
     176             :     else
     177           0 :         mpEdBy->GrabFocus();
     178           0 : }
     179             : 
     180           0 : ScDPNumGroupInfo ScDPNumGroupDlg::GetGroupInfo() const
     181             : {
     182           0 :     ScDPNumGroupInfo aInfo;
     183           0 :     aInfo.mbEnable = true;
     184           0 :     aInfo.mbDateValues = false;
     185           0 :     aInfo.mbAutoStart = maStartHelper.IsAuto();
     186           0 :     aInfo.mbAutoEnd = maEndHelper.IsAuto();
     187             : 
     188             :     // get values and silently auto-correct them, if they are not valid
     189             :     // TODO: error messages in OK event?
     190           0 :     aInfo.mfStart = maStartHelper.GetValue();
     191           0 :     aInfo.mfEnd = maEndHelper.GetValue();
     192           0 :     if( !mpEdBy->GetValue( aInfo.mfStep ) || (aInfo.mfStep <= 0.0) )
     193           0 :         aInfo.mfStep = 1.0;
     194           0 :     if( aInfo.mfEnd <= aInfo.mfStart )
     195           0 :         aInfo.mfEnd = aInfo.mfStart + aInfo.mfStep;
     196             : 
     197           0 :     return aInfo;
     198             : }
     199             : 
     200           0 : ScDPDateGroupDlg::ScDPDateGroupDlg( Window* pParent,
     201             :         const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart, const Date& rNullDate ) :
     202             :     ModalDialog( pParent, "PivotTableGroupByDate", "modules/scalc/ui/groupbydate.ui" ),
     203           0 :     mpRbAutoStart   ( get<RadioButton>("auto_start") ),
     204           0 :     mpRbManStart    ( get<RadioButton>("manual_start") ),
     205           0 :     mpEdStart       ( get<DateField>("start_date") ),
     206           0 :     mpRbAutoEnd     ( get<RadioButton>("auto_end") ),
     207           0 :     mpRbManEnd      ( get<RadioButton>("manual_end") ),
     208           0 :     mpEdEnd         ( get<DateField>("end_date") ),
     209           0 :     mpRbNumDays     ( get<RadioButton>("days") ),
     210           0 :     mpRbUnits       ( get<RadioButton>("intervals") ),
     211           0 :     mpEdNumDays     ( get<NumericField>("days_value") ),
     212           0 :     mpLbUnits       ( get<SvxCheckListBox>("interval_list") ),
     213           0 :     mpBtnOk         ( get<OKButton>("ok") ),
     214             :     maStartHelper   ( mpRbAutoStart, mpRbManStart, mpEdStart, rNullDate ),
     215           0 :     maEndHelper     ( mpRbAutoEnd, mpRbManEnd, mpEdEnd, rNullDate )
     216             : {
     217             :     static const size_t nCount = sizeof( nDatePartResIds ) / sizeof( nDatePartResIds[0] );
     218           0 :     for( size_t nIdx = 0 ; nIdx < nCount; ++nIdx )
     219           0 :         mpLbUnits->InsertEntry( ScGlobal::GetRscString( nDatePartResIds[nIdx] ) );
     220             : 
     221           0 :     mpEdStart->SetShowDateCentury( true );
     222           0 :     mpEdEnd->SetShowDateCentury( true );
     223             : 
     224           0 :     maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
     225           0 :     maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
     226             : 
     227           0 :     if( nDatePart == 0 )
     228           0 :         nDatePart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
     229           0 :     for( size_t nIdx = 0; nIdx < nCount; ++nIdx )
     230           0 :         mpLbUnits->CheckEntryPos( static_cast< sal_uInt16 >( nIdx ), (nDatePart & spnDateParts[ nIdx ]) != 0 );
     231             : 
     232           0 :     if( rInfo.mbDateValues )
     233             :     {
     234           0 :         mpRbNumDays->Check();
     235           0 :         ClickHdl( mpRbNumDays );
     236             : 
     237           0 :         double fNumDays = rInfo.mfStep;
     238           0 :         if( fNumDays < 1.0 )
     239           0 :             fNumDays = 1.0;
     240           0 :         else if( fNumDays > 32767.0 )
     241           0 :             fNumDays = 32767.0;
     242           0 :         mpEdNumDays->SetValue( static_cast< long >( fNumDays ) );
     243             :     }
     244             :     else
     245             :     {
     246           0 :         mpRbUnits->Check();
     247           0 :         ClickHdl( mpRbUnits );
     248             :     }
     249             : 
     250             :     /*  Set the initial focus, currently it is somewhere after calling all the radio
     251             :         button click handlers. Now the first enabled editable control is focused. */
     252           0 :     if( mpEdStart->IsEnabled() )
     253           0 :         mpEdStart->GrabFocus();
     254           0 :     else if( mpEdEnd->IsEnabled() )
     255           0 :         mpEdEnd->GrabFocus();
     256           0 :     else if( mpEdNumDays->IsEnabled() )
     257           0 :         mpEdNumDays->GrabFocus();
     258           0 :     else if( mpLbUnits->IsEnabled() )
     259           0 :         mpLbUnits->GrabFocus();
     260             : 
     261           0 :     mpRbNumDays->SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
     262           0 :     mpRbUnits->SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
     263           0 :     mpLbUnits->SetCheckButtonHdl( LINK( this, ScDPDateGroupDlg, CheckHdl ) );
     264           0 : }
     265             : 
     266           0 : ScDPNumGroupInfo ScDPDateGroupDlg::GetGroupInfo() const
     267             : {
     268           0 :     ScDPNumGroupInfo aInfo;
     269           0 :     aInfo.mbEnable = true;
     270           0 :     aInfo.mbDateValues = mpRbNumDays->IsChecked();
     271           0 :     aInfo.mbAutoStart = maStartHelper.IsAuto();
     272           0 :     aInfo.mbAutoEnd = maEndHelper.IsAuto();
     273             : 
     274             :     // get values and silently auto-correct them, if they are not valid
     275             :     // TODO: error messages in OK event?
     276           0 :     aInfo.mfStart = maStartHelper.GetValue();
     277           0 :     aInfo.mfEnd = maEndHelper.GetValue();
     278           0 :     sal_Int64 nNumDays = mpEdNumDays->GetValue();
     279           0 :     aInfo.mfStep = static_cast<double>( aInfo.mbDateValues ? nNumDays : 0L );
     280           0 :     if( aInfo.mfEnd <= aInfo.mfStart )
     281           0 :         aInfo.mfEnd = aInfo.mfStart + nNumDays;
     282             : 
     283           0 :     return aInfo;
     284             : }
     285             : 
     286           0 : sal_Int32 ScDPDateGroupDlg::GetDatePart() const
     287             : {
     288             :     // return DAYS for special "number of days" mode
     289           0 :     if( mpRbNumDays->IsChecked() )
     290           0 :         return com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
     291             : 
     292             :     // return listbox contents for "units" mode
     293           0 :     sal_Int32 nDatePart = 0;
     294           0 :     for( sal_uLong nIdx = 0, nCount = mpLbUnits->GetEntryCount(); nIdx < nCount; ++nIdx )
     295           0 :         if( mpLbUnits->IsChecked( static_cast< sal_uInt16 >( nIdx ) ) )
     296           0 :             nDatePart |= spnDateParts[ nIdx ];
     297           0 :     return nDatePart;
     298             : }
     299             : 
     300           0 : IMPL_LINK( ScDPDateGroupDlg, ClickHdl, RadioButton*, pButton )
     301             : {
     302           0 :     if( pButton == mpRbNumDays )
     303             :     {
     304           0 :         mpLbUnits->Disable();
     305             :         // enable and set focus to edit field on clicking "num of days" radio button
     306           0 :         mpEdNumDays->Enable();
     307           0 :         mpEdNumDays->GrabFocus();
     308           0 :         mpBtnOk->Enable();
     309             :     }
     310           0 :     else if( pButton == mpRbUnits )
     311             :     {
     312           0 :         mpEdNumDays->Disable();
     313             :         // enable and set focus to listbox on clicking "units" radio button
     314           0 :         mpLbUnits->Enable();
     315           0 :         mpLbUnits->GrabFocus();
     316             :         // disable OK button if no date part selected
     317           0 :         CheckHdl( mpLbUnits );
     318             :     }
     319           0 :     return 0;
     320             : }
     321             : 
     322           0 : IMPL_LINK( ScDPDateGroupDlg, CheckHdl, SvxCheckListBox*, pListBox )
     323             : {
     324             :     // enable/disable OK button on modifying check list box
     325           0 :     if( pListBox == mpLbUnits )
     326           0 :         mpBtnOk->Enable( mpLbUnits->GetCheckedEntryCount() > 0 );
     327           0 :     return 0;
     328           0 : }
     329             : 
     330             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10