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

Generated by: LCOV version 1.10