LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/dbgui - dpgroupdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 145 0.0 %
Date: 2013-07-09 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 "dpgroupdlg.hrc"
      28             : #include "scresid.hxx"
      29             : #include "sc.hrc"
      30             : #include "globstr.hrc"
      31             : 
      32             : #include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
      33             : 
      34             : // ============================================================================
      35             : 
      36             : namespace {
      37             : 
      38             : /** Date part flags in order of the list box entries. */
      39             : static const sal_Int32 spnDateParts[] =
      40             : {
      41             :     com::sun::star::sheet::DataPilotFieldGroupBy::SECONDS,
      42             :     com::sun::star::sheet::DataPilotFieldGroupBy::MINUTES,
      43             :     com::sun::star::sheet::DataPilotFieldGroupBy::HOURS,
      44             :     com::sun::star::sheet::DataPilotFieldGroupBy::DAYS,
      45             :     com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS,
      46             :     com::sun::star::sheet::DataPilotFieldGroupBy::QUARTERS,
      47             :     com::sun::star::sheet::DataPilotFieldGroupBy::YEARS
      48             : };
      49             : 
      50             : static const sal_uInt16 nDatePartResIds[] =
      51             : {
      52             :     STR_DPFIELD_GROUP_BY_SECONDS,
      53             :     STR_DPFIELD_GROUP_BY_MINUTES,
      54             :     STR_DPFIELD_GROUP_BY_HOURS,
      55             :     STR_DPFIELD_GROUP_BY_DAYS,
      56             :     STR_DPFIELD_GROUP_BY_MONTHS,
      57             :     STR_DPFIELD_GROUP_BY_QUARTERS,
      58             :     STR_DPFIELD_GROUP_BY_YEARS
      59             : };
      60             : 
      61             : } // namespace
      62             : 
      63             : // ============================================================================
      64             : 
      65           0 : ScDPGroupEditHelper::ScDPGroupEditHelper( RadioButton& rRbAuto, RadioButton& rRbMan, Edit& rEdValue ) :
      66             :     mrRbAuto( rRbAuto ),
      67             :     mrRbMan( rRbMan ),
      68           0 :     mrEdValue( rEdValue )
      69             : {
      70           0 :     mrRbAuto.SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
      71           0 :     mrRbMan.SetClickHdl( LINK( this, ScDPGroupEditHelper, ClickHdl ) );
      72           0 : }
      73             : 
      74           0 : bool ScDPGroupEditHelper::IsAuto() const
      75             : {
      76           0 :     return mrRbAuto.IsChecked();
      77             : }
      78             : 
      79           0 : double ScDPGroupEditHelper::GetValue() const
      80             : {
      81             :     double fValue;
      82           0 :     if( !ImplGetValue( fValue ) )
      83           0 :         fValue = 0.0;
      84           0 :     return fValue;
      85             : }
      86             : 
      87           0 : void ScDPGroupEditHelper::SetValue( bool bAuto, double fValue )
      88             : {
      89           0 :     if( bAuto )
      90             :     {
      91           0 :         mrRbAuto.Check();
      92           0 :         ClickHdl( &mrRbAuto );
      93             :     }
      94             :     else
      95             :     {
      96           0 :         mrRbMan.Check();
      97           0 :         ClickHdl( &mrRbMan );
      98             :     }
      99           0 :     ImplSetValue( fValue );
     100           0 : }
     101             : 
     102           0 : IMPL_LINK( ScDPGroupEditHelper, ClickHdl, RadioButton*, pButton )
     103             : {
     104           0 :     if( pButton == &mrRbAuto )
     105             :     {
     106             :         // disable edit field on clicking "automatic" radio button
     107           0 :         mrEdValue.Disable();
     108             :     }
     109           0 :     else if( pButton == &mrRbMan )
     110             :     {
     111             :         // enable and set focus to edit field on clicking "manual" radio button
     112           0 :         mrEdValue.Enable();
     113           0 :         mrEdValue.GrabFocus();
     114             :     }
     115           0 :     return 0;
     116             : }
     117             : 
     118             : // ----------------------------------------------------------------------------
     119             : 
     120           0 : ScDPNumGroupEditHelper::ScDPNumGroupEditHelper(
     121             :         RadioButton& rRbAuto, RadioButton& rRbMan, ScDoubleField& rEdValue ) :
     122             :     ScDPGroupEditHelper( rRbAuto, rRbMan, rEdValue ),
     123           0 :     mrEdValue( rEdValue )
     124             : {
     125           0 : }
     126             : 
     127           0 : bool ScDPNumGroupEditHelper::ImplGetValue( double& rfValue ) const
     128             : {
     129           0 :     return mrEdValue.GetValue( rfValue );
     130             : }
     131             : 
     132           0 : void ScDPNumGroupEditHelper::ImplSetValue( double fValue )
     133             : {
     134           0 :     mrEdValue.SetValue( fValue );
     135           0 : }
     136             : 
     137             : // ----------------------------------------------------------------------------
     138             : 
     139           0 : ScDPDateGroupEditHelper::ScDPDateGroupEditHelper(
     140             :         RadioButton& rRbAuto, RadioButton& rRbMan, DateField& rEdValue, const Date& rNullDate ) :
     141             :     ScDPGroupEditHelper( rRbAuto, rRbMan, rEdValue ),
     142             :     mrEdValue( rEdValue ),
     143           0 :     maNullDate( rNullDate )
     144             : {
     145           0 : }
     146             : 
     147           0 : bool ScDPDateGroupEditHelper::ImplGetValue( double& rfValue ) const
     148             : {
     149           0 :     rfValue = mrEdValue.GetDate() - maNullDate;
     150           0 :     return true;
     151             : }
     152             : 
     153           0 : void ScDPDateGroupEditHelper::ImplSetValue( double fValue )
     154             : {
     155           0 :     Date aDate( maNullDate );
     156           0 :     aDate += static_cast< sal_Int32 >( fValue );
     157           0 :     mrEdValue.SetDate( aDate );
     158           0 : }
     159             : 
     160             : // ============================================================================
     161             : // ============================================================================
     162             : 
     163           0 : ScDPNumGroupDlg::ScDPNumGroupDlg( Window* pParent, const ScDPNumGroupInfo& rInfo ) :
     164             :     ModalDialog     ( pParent, ScResId( RID_SCDLG_DPNUMGROUP ) ),
     165             :     maFlStart       ( this, ScResId( FL_START ) ),
     166             :     maRbAutoStart   ( this, ScResId( RB_AUTOSTART ) ),
     167             :     maRbManStart    ( this, ScResId( RB_MANSTART ) ),
     168             :     maEdStart       ( this, ScResId( ED_START ) ),
     169             :     maFlEnd         ( this, ScResId( FL_END ) ),
     170             :     maRbAutoEnd     ( this, ScResId( RB_AUTOEND ) ),
     171             :     maRbManEnd      ( this, ScResId( RB_MANEND ) ),
     172             :     maEdEnd         ( this, ScResId( ED_END ) ),
     173             :     maFlBy          ( this, ScResId( FL_BY ) ),
     174             :     maEdBy          ( this, ScResId( ED_BY ) ),
     175             :     maBtnOk         ( this, ScResId( BTN_OK ) ),
     176             :     maBtnCancel     ( this, ScResId( BTN_CANCEL ) ),
     177             :     maBtnHelp       ( this, ScResId( BTN_HELP ) ),
     178             :     maStartHelper   ( maRbAutoStart, maRbManStart, maEdStart ),
     179           0 :     maEndHelper     ( maRbAutoEnd, maRbManEnd, maEdEnd )
     180             : {
     181           0 :     FreeResource();
     182             : 
     183           0 :     maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
     184           0 :     maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
     185           0 :     maEdBy.SetValue( (rInfo.mfStep <= 0.0) ? 1.0 : rInfo.mfStep );
     186             : 
     187             :     /*  Set the initial focus, currently it is somewhere after calling all the radio
     188             :         button click handlers. Now the first enabled editable control is focused. */
     189           0 :     if( maEdStart.IsEnabled() )
     190           0 :         maEdStart.GrabFocus();
     191           0 :     else if( maEdEnd.IsEnabled() )
     192           0 :         maEdEnd.GrabFocus();
     193             :     else
     194           0 :         maEdBy.GrabFocus();
     195           0 : }
     196             : 
     197           0 : ScDPNumGroupInfo ScDPNumGroupDlg::GetGroupInfo() const
     198             : {
     199           0 :     ScDPNumGroupInfo aInfo;
     200           0 :     aInfo.mbEnable = sal_True;
     201           0 :     aInfo.mbDateValues = false;
     202           0 :     aInfo.mbAutoStart = maStartHelper.IsAuto();
     203           0 :     aInfo.mbAutoEnd = maEndHelper.IsAuto();
     204             : 
     205             :     // get values and silently auto-correct them, if they are not valid
     206             :     // TODO: error messages in OK event?
     207           0 :     aInfo.mfStart = maStartHelper.GetValue();
     208           0 :     aInfo.mfEnd = maEndHelper.GetValue();
     209           0 :     if( !maEdBy.GetValue( aInfo.mfStep ) || (aInfo.mfStep <= 0.0) )
     210           0 :         aInfo.mfStep = 1.0;
     211           0 :     if( aInfo.mfEnd <= aInfo.mfStart )
     212           0 :         aInfo.mfEnd = aInfo.mfStart + aInfo.mfStep;
     213             : 
     214           0 :     return aInfo;
     215             : }
     216             : 
     217             : // ============================================================================
     218             : 
     219           0 : ScDPDateGroupDlg::ScDPDateGroupDlg( Window* pParent,
     220             :         const ScDPNumGroupInfo& rInfo, sal_Int32 nDatePart, const Date& rNullDate ) :
     221             :     ModalDialog     ( pParent, ScResId( RID_SCDLG_DPDATEGROUP ) ),
     222             :     maFlStart       ( this, ScResId( FL_START ) ),
     223             :     maRbAutoStart   ( this, ScResId( RB_AUTOSTART ) ),
     224             :     maRbManStart    ( this, ScResId( RB_MANSTART ) ),
     225             :     maEdStart       ( this, ScResId( ED_START ) ),
     226             :     maFlEnd         ( this, ScResId( FL_END ) ),
     227             :     maRbAutoEnd     ( this, ScResId( RB_AUTOEND ) ),
     228             :     maRbManEnd      ( this, ScResId( RB_MANEND ) ),
     229             :     maEdEnd         ( this, ScResId( ED_END ) ),
     230             :     maFlBy          ( this, ScResId( FL_BY ) ),
     231             :     maRbNumDays     ( this, ScResId( RB_NUMDAYS ) ),
     232             :     maRbUnits       ( this, ScResId( RB_UNITS ) ),
     233             :     maEdNumDays     ( this, ScResId( ED_NUMDAYS ) ),
     234             :     maLbUnits       ( this, ScResId( LB_UNITS ) ),
     235             :     maBtnOk         ( this, ScResId( BTN_OK ) ),
     236             :     maBtnCancel     ( this, ScResId( BTN_CANCEL ) ),
     237             :     maBtnHelp       ( this, ScResId( BTN_HELP ) ),
     238             :     maStartHelper   ( maRbAutoStart, maRbManStart, maEdStart, rNullDate ),
     239           0 :     maEndHelper     ( maRbAutoEnd, maRbManEnd, maEdEnd, rNullDate )
     240             : {
     241           0 :     FreeResource();
     242             : 
     243           0 :     maLbUnits.SetHelpId( HID_SC_DPDATEGROUP_LB );
     244             : 
     245             :     static const size_t nCount = sizeof( nDatePartResIds ) / sizeof( nDatePartResIds[0] );
     246           0 :     for( size_t nIdx = 0 ; nIdx < nCount; ++nIdx )
     247           0 :         maLbUnits.InsertEntry( ScGlobal::GetRscString( nDatePartResIds[nIdx] ) );
     248             : 
     249           0 :     maEdStart.SetShowDateCentury( sal_True );
     250           0 :     maEdEnd.SetShowDateCentury( sal_True );
     251             : 
     252           0 :     maStartHelper.SetValue( rInfo.mbAutoStart, rInfo.mfStart );
     253           0 :     maEndHelper.SetValue( rInfo.mbAutoEnd, rInfo.mfEnd );
     254             : 
     255           0 :     if( nDatePart == 0 )
     256           0 :         nDatePart = com::sun::star::sheet::DataPilotFieldGroupBy::MONTHS;
     257           0 :     for( size_t nIdx = 0; nIdx < nCount; ++nIdx )
     258           0 :         maLbUnits.CheckEntryPos( static_cast< sal_uInt16 >( nIdx ), (nDatePart & spnDateParts[ nIdx ]) != 0 );
     259             : 
     260           0 :     if( rInfo.mbDateValues )
     261             :     {
     262           0 :         maRbNumDays.Check();
     263           0 :         ClickHdl( &maRbNumDays );
     264             : 
     265           0 :         double fNumDays = rInfo.mfStep;
     266           0 :         if( fNumDays < 1.0 )
     267           0 :             fNumDays = 1.0;
     268           0 :         else if( fNumDays > 32767.0 )
     269           0 :             fNumDays = 32767.0;
     270           0 :         maEdNumDays.SetValue( static_cast< long >( fNumDays ) );
     271             :     }
     272             :     else
     273             :     {
     274           0 :         maRbUnits.Check();
     275           0 :         ClickHdl( &maRbUnits );
     276             :     }
     277             : 
     278             :     /*  Set the initial focus, currently it is somewhere after calling all the radio
     279             :         button click handlers. Now the first enabled editable control is focused. */
     280           0 :     if( maEdStart.IsEnabled() )
     281           0 :         maEdStart.GrabFocus();
     282           0 :     else if( maEdEnd.IsEnabled() )
     283           0 :         maEdEnd.GrabFocus();
     284           0 :     else if( maEdNumDays.IsEnabled() )
     285           0 :         maEdNumDays.GrabFocus();
     286           0 :     else if( maLbUnits.IsEnabled() )
     287           0 :         maLbUnits.GrabFocus();
     288             : 
     289           0 :     maRbNumDays.SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
     290           0 :     maRbUnits.SetClickHdl( LINK( this, ScDPDateGroupDlg, ClickHdl ) );
     291           0 :     maLbUnits.SetCheckButtonHdl( LINK( this, ScDPDateGroupDlg, CheckHdl ) );
     292           0 : }
     293             : 
     294           0 : ScDPNumGroupInfo ScDPDateGroupDlg::GetGroupInfo() const
     295             : {
     296           0 :     ScDPNumGroupInfo aInfo;
     297           0 :     aInfo.mbEnable = sal_True;
     298           0 :     aInfo.mbDateValues = maRbNumDays.IsChecked();
     299           0 :     aInfo.mbAutoStart = maStartHelper.IsAuto();
     300           0 :     aInfo.mbAutoEnd = maEndHelper.IsAuto();
     301             : 
     302             :     // get values and silently auto-correct them, if they are not valid
     303             :     // TODO: error messages in OK event?
     304           0 :     aInfo.mfStart = maStartHelper.GetValue();
     305           0 :     aInfo.mfEnd = maEndHelper.GetValue();
     306           0 :     sal_Int64 nNumDays = maEdNumDays.GetValue();
     307           0 :     aInfo.mfStep = static_cast<double>( aInfo.mbDateValues ? nNumDays : 0L );
     308           0 :     if( aInfo.mfEnd <= aInfo.mfStart )
     309           0 :         aInfo.mfEnd = aInfo.mfStart + nNumDays;
     310             : 
     311           0 :     return aInfo;
     312             : }
     313             : 
     314           0 : sal_Int32 ScDPDateGroupDlg::GetDatePart() const
     315             : {
     316             :     // return DAYS for special "number of days" mode
     317           0 :     if( maRbNumDays.IsChecked() )
     318           0 :         return com::sun::star::sheet::DataPilotFieldGroupBy::DAYS;
     319             : 
     320             :     // return listbox contents for "units" mode
     321           0 :     sal_Int32 nDatePart = 0;
     322           0 :     for( sal_uLong nIdx = 0, nCount = maLbUnits.GetEntryCount(); nIdx < nCount; ++nIdx )
     323           0 :         if( maLbUnits.IsChecked( static_cast< sal_uInt16 >( nIdx ) ) )
     324           0 :             nDatePart |= spnDateParts[ nIdx ];
     325           0 :     return nDatePart;
     326             : }
     327             : 
     328           0 : IMPL_LINK( ScDPDateGroupDlg, ClickHdl, RadioButton*, pButton )
     329             : {
     330           0 :     if( pButton == &maRbNumDays )
     331             :     {
     332           0 :         maLbUnits.Disable();
     333             :         // enable and set focus to edit field on clicking "num of days" radio button
     334           0 :         maEdNumDays.Enable();
     335           0 :         maEdNumDays.GrabFocus();
     336           0 :         maBtnOk.Enable();
     337             :     }
     338           0 :     else if( pButton == &maRbUnits )
     339             :     {
     340           0 :         maEdNumDays.Disable();
     341             :         // enable and set focus to listbox on clicking "units" radio button
     342           0 :         maLbUnits.Enable();
     343           0 :         maLbUnits.GrabFocus();
     344             :         // disable OK button if no date part selected
     345           0 :         CheckHdl( &maLbUnits );
     346             :     }
     347           0 :     return 0;
     348             : }
     349             : 
     350           0 : IMPL_LINK( ScDPDateGroupDlg, CheckHdl, SvxCheckListBox*, pListBox )
     351             : {
     352             :     // enable/disable OK button on modifying check list box
     353           0 :     if( pListBox == &maLbUnits )
     354           0 :         maBtnOk.Enable( maLbUnits.GetCheckedEntryCount() > 0 );
     355           0 :     return 0;
     356           0 : }
     357             : 
     358             : // ============================================================================
     359             : 
     360             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10