LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - tp_Scale.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 349 0.3 %
Date: 2014-04-11 Functions: 2 21 9.5 %
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             : #include "tp_Scale.hxx"
      21             : 
      22             : #include "ResId.hxx"
      23             : #include "Strings.hrc"
      24             : #include "chartview/ChartSfxItemIds.hxx"
      25             : #include "AxisHelper.hxx"
      26             : 
      27             : #include <svx/svxids.hrc>
      28             : #include <rtl/math.hxx>
      29             : // header for class SvxDoubleItem
      30             : #include <svx/chrtitem.hxx>
      31             : // header for class SfxBoolItem
      32             : #include <svl/eitem.hxx>
      33             : // header for SfxInt32Item
      34             : #include <svl/intitem.hxx>
      35             : 
      36             : // header for class WarningBox
      37             : #include <vcl/msgbox.hxx>
      38             : 
      39             : // header for class SvNumberformat
      40             : #include <svl/zformat.hxx>
      41             : 
      42             : #include <svtools/controldims.hrc>
      43             : 
      44             : #include <com/sun/star/chart2/AxisType.hpp>
      45             : 
      46             : using namespace ::com::sun::star;
      47             : 
      48             : namespace chart
      49             : {
      50             : 
      51             : namespace
      52             : {
      53             : 
      54           0 : void lcl_setValue( FormattedField& rFmtField, double fValue )
      55             : {
      56           0 :     rFmtField.SetValue( fValue );
      57           0 :     rFmtField.SetDefaultValue( fValue );
      58           0 : }
      59             : 
      60             : }
      61             : 
      62           0 : ScaleTabPage::ScaleTabPage(Window* pWindow,const SfxItemSet& rInAttrs) :
      63             :     SfxTabPage(pWindow
      64             :                , "tp_Scale"
      65             :                , "modules/schart/ui/tp_Scale.ui"
      66             :                , rInAttrs),
      67             :     fMin(0.0),
      68             :     fMax(0.0),
      69             :     fStepMain(0.0),
      70             :     nStepHelp(0),
      71             :     fOrigin(0.0),
      72             :     m_nTimeResolution(1),
      73             :     m_nMainTimeUnit(1),
      74             :     m_nHelpTimeUnit(1),
      75             :     m_nAxisType(chart2::AxisType::REALNUMBER),
      76             :     m_bAllowDateAxis(false),
      77             :     pNumFormatter(NULL),
      78           0 :     m_bShowAxisOrigin(false)
      79             : {
      80           0 :     get(m_pCbxReverse, "CBX_REVERSE");
      81           0 :     get(m_pCbxLogarithm, "CBX_LOGARITHM");
      82           0 :     get(m_pLB_AxisType, "LB_AXIS_TYPE");
      83           0 :     get(m_pBxType,"boxTYPE");
      84             : 
      85           0 :     get(m_pBxMinMax, "gridMINMAX");
      86           0 :     get(m_pFmtFldMin, "EDT_MIN");
      87           0 :     get(m_pCbxAutoMin, "CBX_AUTO_MIN");
      88           0 :     get(m_pFmtFldMax, "EDT_MAX");
      89           0 :     get(m_pCbxAutoMax, "CBX_AUTO_MAX");
      90             : 
      91           0 :     get(m_pBxResolution, "boxRESOLUTION");
      92           0 :     get(m_pLB_TimeResolution, "LB_TIME_RESOLUTION");
      93           0 :     get(m_pCbx_AutoTimeResolution, "CBX_AUTO_TIME_RESOLUTION");
      94             : 
      95           0 :     get(m_pBxMain, "boxMAIN");
      96           0 :     get(m_pFmtFldStepMain, "EDT_STEP_MAIN");
      97           0 :     get(m_pMt_MainDateStep, "MT_MAIN_DATE_STEP");
      98           0 :     get(m_pLB_MainTimeUnit, "LB_MAIN_TIME_UNIT");
      99           0 :     get(m_pCbxAutoStepMain, "CBX_AUTO_STEP_MAIN");
     100             : 
     101           0 :     get(m_pBxMinor, "boxMINOR");
     102           0 :     get(m_pMtStepHelp, "MT_STEPHELP");
     103           0 :     get(m_pLB_HelpTimeUnit, "LB_HELP_TIME_UNIT");
     104           0 :     get(m_pCbxAutoStepHelp, "CBX_AUTO_STEP_HELP");
     105           0 :     get(m_pTxtHelpCount,"TXT_STEP_HELP_COUNT");
     106           0 :     get(m_pTxtHelp,"TXT_STEP_HELP");
     107             : 
     108           0 :     get(m_pBxOrigin,"boxORIGIN");
     109           0 :     get(m_pFmtFldOrigin, "EDT_ORIGIN");
     110           0 :     get(m_pCbxAutoOrigin, "CBX_AUTO_ORIGIN");
     111             : 
     112           0 :     m_pCbxAutoMin->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
     113           0 :     m_pCbxAutoMax->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
     114           0 :     m_pCbxAutoStepMain->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
     115           0 :     m_pCbxAutoStepHelp->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
     116           0 :     m_pCbxAutoOrigin->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
     117           0 :     m_pCbx_AutoTimeResolution->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
     118             : 
     119           0 :     m_pLB_AxisType->SetDropDownLineCount(3);
     120           0 :     m_pLB_AxisType->SetSelectHdl(LINK(this, ScaleTabPage, SelectAxisTypeHdl));
     121             : 
     122           0 :     m_pLB_TimeResolution->SetDropDownLineCount(3);
     123           0 :     m_pLB_MainTimeUnit->SetDropDownLineCount(3);
     124           0 :     m_pLB_HelpTimeUnit->SetDropDownLineCount(3);
     125             : 
     126           0 :     m_pFmtFldMin->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
     127           0 :     m_pFmtFldMax->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
     128           0 :     m_pFmtFldStepMain->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
     129           0 :     m_pFmtFldOrigin->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
     130             : 
     131           0 :     HideAllControls();
     132           0 : }
     133             : 
     134           0 : IMPL_LINK( ScaleTabPage, FmtFieldModifiedHdl, FormattedField*, pFmtFied )
     135             : {
     136           0 :     if( pFmtFied )
     137           0 :         pFmtFied->SetDefaultValue( pFmtFied->GetValue() );
     138           0 :     return 0;
     139             : }
     140             : 
     141           0 : void ScaleTabPage::StateChanged( StateChangedType nType )
     142             : {
     143           0 :     TabPage::StateChanged( nType );
     144           0 : }
     145             : 
     146           0 : void ScaleTabPage::EnableControls()
     147             : {
     148           0 :     bool bValueAxis = chart2::AxisType::REALNUMBER == m_nAxisType
     149           0 :                    || chart2::AxisType::PERCENT == m_nAxisType
     150           0 :                    || chart2::AxisType::DATE == m_nAxisType;
     151           0 :     bool bDateAxis = chart2::AxisType::DATE == m_nAxisType;
     152             : 
     153           0 :     m_pBxType->Show(m_bAllowDateAxis);
     154             : 
     155           0 :     m_pCbxLogarithm->Show( bValueAxis && !bDateAxis );
     156             : 
     157           0 :     m_pBxMinMax->Show(bValueAxis);
     158           0 :     m_pBxMain->Show( bValueAxis );
     159           0 :     m_pBxMinor->Show( bValueAxis );
     160           0 :     m_pBxOrigin->Show( m_bShowAxisOrigin && bValueAxis );
     161             : 
     162           0 :     m_pTxtHelpCount->Show( bValueAxis && !bDateAxis );
     163           0 :     m_pTxtHelp->Show( bDateAxis );
     164             : 
     165           0 :     m_pBxResolution->Show( bDateAxis );
     166             : 
     167           0 :     bool bWasDateAxis = m_pMt_MainDateStep->IsVisible();
     168           0 :     if( bWasDateAxis != bDateAxis )
     169             :     {
     170             :         //transport value from one to other control
     171           0 :         if( bWasDateAxis )
     172           0 :             lcl_setValue( *m_pFmtFldStepMain, m_pMt_MainDateStep->GetValue() );
     173             :         else
     174           0 :             m_pMt_MainDateStep->SetValue( static_cast<sal_Int32>(m_pFmtFldStepMain->GetValue()) );
     175             :     }
     176           0 :     m_pFmtFldStepMain->Show( bValueAxis && !bDateAxis );
     177           0 :     m_pMt_MainDateStep->Show( bDateAxis );
     178             : 
     179           0 :     m_pLB_MainTimeUnit->Show( bDateAxis );
     180           0 :     m_pLB_HelpTimeUnit->Show( bDateAxis );
     181             : 
     182           0 :     EnableValueHdl(m_pCbxAutoMin);
     183           0 :     EnableValueHdl(m_pCbxAutoMax);
     184           0 :     EnableValueHdl(m_pCbxAutoStepMain);
     185           0 :     EnableValueHdl(m_pCbxAutoStepHelp);
     186           0 :     EnableValueHdl(m_pCbxAutoOrigin);
     187           0 :     EnableValueHdl(m_pCbx_AutoTimeResolution);
     188           0 : }
     189             : 
     190           0 : IMPL_LINK( ScaleTabPage, EnableValueHdl, CheckBox *, pCbx )
     191             : {
     192           0 :     bool bEnable = pCbx && !pCbx->IsChecked() && pCbx->IsEnabled();
     193           0 :     if (pCbx == m_pCbxAutoMin)
     194             :     {
     195           0 :         m_pFmtFldMin->Enable( bEnable );
     196             :     }
     197           0 :     else if (pCbx == m_pCbxAutoMax)
     198             :     {
     199           0 :         m_pFmtFldMax->Enable( bEnable );
     200             :     }
     201           0 :     else if (pCbx == m_pCbxAutoStepMain)
     202             :     {
     203           0 :         m_pFmtFldStepMain->Enable( bEnable );
     204           0 :         m_pMt_MainDateStep->Enable( bEnable );
     205           0 :         m_pLB_MainTimeUnit->Enable( bEnable );
     206             :     }
     207           0 :     else if (pCbx == m_pCbxAutoStepHelp)
     208             :     {
     209           0 :         m_pMtStepHelp->Enable( bEnable );
     210           0 :         m_pLB_HelpTimeUnit->Enable( bEnable );
     211             :     }
     212           0 :     else if (pCbx == m_pCbx_AutoTimeResolution)
     213             :     {
     214           0 :         m_pLB_TimeResolution->Enable( bEnable );
     215             :     }
     216           0 :     else if (pCbx == m_pCbxAutoOrigin)
     217             :     {
     218           0 :         m_pFmtFldOrigin->Enable( bEnable );
     219             :     }
     220           0 :     return 0;
     221             : }
     222             : 
     223             : enum AxisTypeListBoxEntry
     224             : {
     225             :     TYPE_AUTO=0,
     226             :     TYPE_TEXT=1,
     227             :     TYPE_DATE=2
     228             : };
     229             : 
     230           0 : IMPL_LINK_NOARG(ScaleTabPage, SelectAxisTypeHdl)
     231             : {
     232           0 :     sal_uInt16 nPos = m_pLB_AxisType->GetSelectEntryPos();
     233           0 :     if( nPos==TYPE_DATE )
     234           0 :         m_nAxisType = chart2::AxisType::DATE;
     235             :     else
     236           0 :         m_nAxisType = chart2::AxisType::CATEGORY;
     237           0 :     if( chart2::AxisType::DATE == m_nAxisType )
     238           0 :         m_pCbxLogarithm->Check(false);
     239           0 :     EnableControls();
     240           0 :     SetNumFormat();
     241           0 :     return 0;
     242             : }
     243             : 
     244           0 : SfxTabPage* ScaleTabPage::Create(Window* pWindow,const SfxItemSet& rOutAttrs)
     245             : {
     246           0 :     return new ScaleTabPage(pWindow, rOutAttrs);
     247             : }
     248             : 
     249           0 : bool ScaleTabPage::FillItemSet(SfxItemSet& rOutAttrs)
     250             : {
     251             :     OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
     252             : 
     253           0 :     rOutAttrs.Put(SfxInt32Item(SCHATTR_AXISTYPE, m_nAxisType));
     254           0 :     if(m_bAllowDateAxis)
     255           0 :         rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, TYPE_AUTO==m_pLB_AxisType->GetSelectEntryPos()));
     256             : 
     257           0 :     bool bAutoScale = false;
     258           0 :     if( m_nAxisType==chart2::AxisType::CATEGORY )
     259           0 :         bAutoScale = true;//reset scaling for category charts
     260             : 
     261           0 :     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN      ,bAutoScale || m_pCbxAutoMin->IsChecked()));
     262           0 :     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX      ,bAutoScale || m_pCbxAutoMax->IsChecked()));
     263           0 :     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,bAutoScale || m_pCbxAutoStepHelp->IsChecked()));
     264           0 :     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN   ,bAutoScale || m_pCbxAutoOrigin->IsChecked()));
     265           0 :     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM     ,m_pCbxLogarithm->IsChecked()));
     266           0 :     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_REVERSE       ,m_pCbxReverse->IsChecked()));
     267           0 :     rOutAttrs.Put(SvxDoubleItem(fMax     , SCHATTR_AXIS_MAX));
     268           0 :     rOutAttrs.Put(SvxDoubleItem(fMin     , SCHATTR_AXIS_MIN));
     269           0 :     rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP, nStepHelp));
     270           0 :     rOutAttrs.Put(SvxDoubleItem(fOrigin  , SCHATTR_AXIS_ORIGIN));
     271             : 
     272           0 :     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || m_pCbxAutoStepMain->IsChecked()));
     273           0 :     rOutAttrs.Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN));
     274             : 
     275           0 :     rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,bAutoScale || m_pCbx_AutoTimeResolution->IsChecked()));
     276           0 :     rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION,m_nTimeResolution));
     277             : 
     278           0 :     rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,m_nMainTimeUnit));
     279           0 :     rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,m_nHelpTimeUnit));
     280             : 
     281           0 :     return true;
     282             : }
     283             : 
     284           0 : void ScaleTabPage::Reset(const SfxItemSet& rInAttrs)
     285             : {
     286             :     OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
     287           0 :     if(!pNumFormatter)
     288           0 :         return;
     289             : 
     290           0 :     const SfxPoolItem *pPoolItem = NULL;
     291           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_ALLOW_DATEAXIS, true, &pPoolItem) == SFX_ITEM_SET)
     292           0 :         m_bAllowDateAxis = (bool) ((const SfxBoolItem*)pPoolItem)->GetValue();
     293           0 :     m_nAxisType=chart2::AxisType::REALNUMBER;
     294           0 :     if (rInAttrs.GetItemState(SCHATTR_AXISTYPE, true, &pPoolItem) == SFX_ITEM_SET)
     295           0 :         m_nAxisType = (int) ((const SfxInt32Item*)pPoolItem)->GetValue();
     296           0 :     if( m_nAxisType==chart2::AxisType::DATE && !m_bAllowDateAxis )
     297           0 :         m_nAxisType=chart2::AxisType::CATEGORY;
     298           0 :     if( m_bAllowDateAxis )
     299             :     {
     300           0 :         bool bAutoDateAxis = false;
     301           0 :         if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_DATEAXIS, true, &pPoolItem) == SFX_ITEM_SET)
     302           0 :             bAutoDateAxis = (bool) ((const SfxBoolItem*)pPoolItem)->GetValue();
     303             : 
     304           0 :         sal_uInt16 nPos = 0;
     305           0 :         if( m_nAxisType==chart2::AxisType::DATE )
     306           0 :             nPos=TYPE_DATE;
     307           0 :         else if( bAutoDateAxis )
     308           0 :             nPos=TYPE_AUTO;
     309             :         else
     310           0 :             nPos=TYPE_TEXT;
     311           0 :         m_pLB_AxisType->SelectEntryPos( nPos );
     312             :     }
     313             : 
     314           0 :     m_pCbxAutoMin->Check( true );
     315           0 :     m_pCbxAutoMax->Check( true );
     316           0 :     m_pCbxAutoStepMain->Check( true );
     317           0 :     m_pCbxAutoStepHelp->Check( true );
     318           0 :     m_pCbxAutoOrigin->Check( true );
     319           0 :     m_pCbx_AutoTimeResolution->Check( true );
     320             : 
     321           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_MIN,true,&pPoolItem) == SFX_ITEM_SET)
     322           0 :         m_pCbxAutoMin->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
     323             : 
     324           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_MIN,true, &pPoolItem) == SFX_ITEM_SET)
     325             :     {
     326           0 :         fMin = ((const SvxDoubleItem*)pPoolItem)->GetValue();
     327           0 :         lcl_setValue( *m_pFmtFldMin, fMin );
     328             :     }
     329             : 
     330           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_MAX,true, &pPoolItem) == SFX_ITEM_SET)
     331           0 :         m_pCbxAutoMax->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
     332             : 
     333           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_MAX,true, &pPoolItem) == SFX_ITEM_SET)
     334             :     {
     335           0 :         fMax = ((const SvxDoubleItem*)pPoolItem)->GetValue();
     336           0 :         lcl_setValue( *m_pFmtFldMax, fMax );
     337             :     }
     338             : 
     339           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN,true, &pPoolItem) == SFX_ITEM_SET)
     340           0 :         m_pCbxAutoStepMain->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
     341             : 
     342           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_STEP_MAIN,true, &pPoolItem) == SFX_ITEM_SET)
     343             :     {
     344           0 :         fStepMain = ((const SvxDoubleItem*)pPoolItem)->GetValue();
     345           0 :         lcl_setValue( *m_pFmtFldStepMain, fStepMain );
     346           0 :         m_pMt_MainDateStep->SetValue( static_cast<sal_Int32>(fStepMain) );
     347             :     }
     348           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP,true, &pPoolItem) == SFX_ITEM_SET)
     349           0 :         m_pCbxAutoStepHelp->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
     350           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_LOGARITHM,true, &pPoolItem) == SFX_ITEM_SET)
     351           0 :         m_pCbxLogarithm->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
     352           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_REVERSE,true, &pPoolItem) == SFX_ITEM_SET)
     353           0 :         m_pCbxReverse->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
     354           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_STEP_HELP,true, &pPoolItem) == SFX_ITEM_SET)
     355             :     {
     356           0 :         nStepHelp = ((const SfxInt32Item*)pPoolItem)->GetValue();
     357           0 :         m_pMtStepHelp->SetValue( nStepHelp );
     358             :     }
     359           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_ORIGIN,true, &pPoolItem) == SFX_ITEM_SET)
     360           0 :         m_pCbxAutoOrigin->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
     361           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_ORIGIN,true, &pPoolItem) == SFX_ITEM_SET)
     362             :     {
     363           0 :         fOrigin = ((const SvxDoubleItem*)pPoolItem)->GetValue();
     364           0 :         lcl_setValue( *m_pFmtFldOrigin, fOrigin );
     365             :     }
     366             : 
     367           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,true, &pPoolItem) == SFX_ITEM_SET)
     368           0 :         m_pCbx_AutoTimeResolution->Check(((const SfxBoolItem*)pPoolItem)->GetValue());
     369           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_TIME_RESOLUTION,true, &pPoolItem) == SFX_ITEM_SET)
     370             :     {
     371           0 :         m_nTimeResolution = ((const SfxInt32Item*)pPoolItem)->GetValue();
     372           0 :         m_pLB_TimeResolution->SelectEntryPos( m_nTimeResolution );
     373             :     }
     374             : 
     375           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_MAIN_TIME_UNIT,true, &pPoolItem) == SFX_ITEM_SET)
     376             :     {
     377           0 :         m_nMainTimeUnit = ((const SfxInt32Item*)pPoolItem)->GetValue();
     378           0 :         m_pLB_MainTimeUnit->SelectEntryPos( m_nMainTimeUnit );
     379             :     }
     380           0 :     if (rInAttrs.GetItemState(SCHATTR_AXIS_HELP_TIME_UNIT,true, &pPoolItem) == SFX_ITEM_SET)
     381             :     {
     382           0 :         m_nHelpTimeUnit = ((const SfxInt32Item*)pPoolItem)->GetValue();
     383           0 :         m_pLB_HelpTimeUnit->SelectEntryPos( m_nHelpTimeUnit );
     384             :     }
     385             : 
     386           0 :     EnableControls();
     387           0 :     SetNumFormat();
     388             : }
     389             : 
     390           0 : int ScaleTabPage::DeactivatePage(SfxItemSet* pItemSet)
     391             : {
     392           0 :     if( !pNumFormatter )
     393             :     {
     394             :         OSL_FAIL( "No NumberFormatter available" );
     395           0 :         return LEAVE_PAGE;
     396             :     }
     397             : 
     398           0 :     bool bDateAxis = chart2::AxisType::DATE == m_nAxisType;
     399             : 
     400           0 :     sal_uInt32 nMinMaxOriginFmt = m_pFmtFldMax->GetFormatKey();
     401           0 :     if ((pNumFormatter->GetType(nMinMaxOriginFmt) &~ NUMBERFORMAT_DEFINED) == NUMBERFORMAT_TEXT)
     402           0 :         nMinMaxOriginFmt = 0;
     403             :     // numberformat_text cause numbers to fail being numbers...  Shouldn't happen, but can.
     404           0 :     sal_uInt32 nStepFmt = m_pFmtFldStepMain->GetFormatKey();
     405           0 :     if ((pNumFormatter->GetType(nStepFmt) &~NUMBERFORMAT_DEFINED) == NUMBERFORMAT_TEXT)
     406           0 :         nStepFmt = 0;
     407             : 
     408           0 :     Control* pControl = NULL;
     409           0 :     sal_uInt16 nErrStrId = 0;
     410             :     double fDummy;
     411             : 
     412           0 :     fMax = m_pFmtFldMax->GetValue();
     413           0 :     fMin = m_pFmtFldMin->GetValue();
     414           0 :     fOrigin = m_pFmtFldOrigin->GetValue();
     415           0 :     fStepMain = bDateAxis ? m_pMt_MainDateStep->GetValue() : m_pFmtFldStepMain->GetValue();
     416           0 :     nStepHelp = static_cast< sal_Int32 >( m_pMtStepHelp->GetValue());
     417           0 :     m_nTimeResolution = m_pLB_TimeResolution->GetSelectEntryPos();
     418           0 :     m_nMainTimeUnit = m_pLB_MainTimeUnit->GetSelectEntryPos();
     419           0 :     m_nHelpTimeUnit = m_pLB_HelpTimeUnit->GetSelectEntryPos();
     420             : 
     421           0 :     if( chart2::AxisType::REALNUMBER != m_nAxisType )
     422           0 :         m_pCbxLogarithm->Show( false );
     423             : 
     424             :     //check which entries need user action
     425             : 
     426           0 :     if ( m_pCbxLogarithm->IsChecked() &&
     427           0 :             ( ( !m_pCbxAutoMin->IsChecked() && fMin <= 0.0 )
     428           0 :              || ( !m_pCbxAutoMax->IsChecked() && fMax <= 0.0 ) ) )
     429             :     {
     430           0 :         pControl = m_pFmtFldMin;
     431           0 :         nErrStrId = STR_BAD_LOGARITHM;
     432             :     }
     433             :     // check for entries that cannot be parsed for the current number format
     434           0 :     else if ( m_pFmtFldMin->IsModified()
     435           0 :               && !m_pCbxAutoMin->IsChecked()
     436           0 :               && !pNumFormatter->IsNumberFormat( m_pFmtFldMin->GetText(), nMinMaxOriginFmt, fDummy))
     437             :     {
     438           0 :         pControl = m_pFmtFldMin;
     439           0 :         nErrStrId = STR_INVALID_NUMBER;
     440             :     }
     441           0 :     else if ( m_pFmtFldMax->IsModified()
     442           0 :               && !m_pCbxAutoMax->IsChecked()
     443           0 :               && !pNumFormatter->IsNumberFormat( m_pFmtFldMax->GetText(), nMinMaxOriginFmt, fDummy))
     444             :     {
     445           0 :         pControl = m_pFmtFldMax;
     446           0 :         nErrStrId = STR_INVALID_NUMBER;
     447             :     }
     448           0 :     else if ( !bDateAxis && m_pFmtFldStepMain->IsModified()
     449           0 :               && !m_pCbxAutoStepMain->IsChecked()
     450           0 :               && !pNumFormatter->IsNumberFormat( m_pFmtFldStepMain->GetText(), nStepFmt, fDummy))
     451             :     {
     452           0 :         pControl = m_pFmtFldStepMain;
     453           0 :         nErrStrId = STR_INVALID_NUMBER;
     454             :     }
     455           0 :     else if (m_pFmtFldOrigin->IsModified() && !m_pCbxAutoOrigin->IsChecked() &&
     456           0 :              !pNumFormatter->IsNumberFormat( m_pFmtFldOrigin->GetText(), nMinMaxOriginFmt, fDummy))
     457             :     {
     458           0 :         pControl = m_pFmtFldOrigin;
     459           0 :         nErrStrId = STR_INVALID_NUMBER;
     460             :     }
     461           0 :     else if (!m_pCbxAutoStepMain->IsChecked() && fStepMain <= 0.0)
     462             :     {
     463           0 :         pControl = m_pFmtFldStepMain;
     464           0 :         nErrStrId = STR_STEP_GT_ZERO;
     465             :     }
     466           0 :     else if (!m_pCbxAutoMax->IsChecked() && !m_pCbxAutoMin->IsChecked() &&
     467           0 :              fMin >= fMax)
     468             :     {
     469           0 :         pControl = m_pFmtFldMin;
     470           0 :         nErrStrId = STR_MIN_GREATER_MAX;
     471             :     }
     472           0 :     else if( bDateAxis )
     473             :     {
     474           0 :         if( !m_pCbxAutoStepMain->IsChecked() && !m_pCbxAutoStepHelp->IsChecked() )
     475             :         {
     476           0 :             if( m_nHelpTimeUnit > m_nMainTimeUnit )
     477             :             {
     478           0 :                 pControl = m_pLB_MainTimeUnit;
     479           0 :                 nErrStrId = STR_INVALID_INTERVALS;
     480             :             }
     481           0 :             else if( m_nHelpTimeUnit == m_nMainTimeUnit && nStepHelp > fStepMain )
     482             :             {
     483           0 :                 pControl = m_pLB_MainTimeUnit;
     484           0 :                 nErrStrId = STR_INVALID_INTERVALS;
     485             :             }
     486             :         }
     487           0 :         if( !nErrStrId && !m_pCbx_AutoTimeResolution->IsChecked() )
     488             :         {
     489           0 :             if( (!m_pCbxAutoStepMain->IsChecked() && m_nTimeResolution > m_nMainTimeUnit )
     490           0 :                 ||
     491           0 :                 (!m_pCbxAutoStepHelp->IsChecked() && m_nTimeResolution > m_nHelpTimeUnit )
     492             :                 )
     493             :             {
     494           0 :                 pControl = m_pLB_TimeResolution;
     495           0 :                 nErrStrId = STR_INVALID_TIME_UNIT;
     496             :             }
     497             :         }
     498             :     }
     499             : 
     500           0 :     if( ShowWarning( nErrStrId, pControl ) )
     501           0 :         return KEEP_PAGE;
     502             : 
     503           0 :     if( pItemSet )
     504           0 :         FillItemSet( *pItemSet );
     505             : 
     506           0 :     return LEAVE_PAGE;
     507             : }
     508             : 
     509           0 : void ScaleTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
     510             : {
     511           0 :     pNumFormatter = pFormatter;
     512           0 :     m_pFmtFldMax->SetFormatter( pNumFormatter );
     513           0 :     m_pFmtFldMin->SetFormatter( pNumFormatter );
     514           0 :     m_pFmtFldStepMain->SetFormatter( pNumFormatter );
     515           0 :     m_pFmtFldOrigin->SetFormatter( pNumFormatter );
     516             : 
     517             :     // #i6278# allow more decimal places than the output format.  As
     518             :     // the numbers shown in the edit fields are used for input, it makes more
     519             :     // sense to display the values in the input format rather than the output
     520             :     // format.
     521           0 :     m_pFmtFldMax->UseInputStringForFormatting();
     522           0 :     m_pFmtFldMin->UseInputStringForFormatting();
     523           0 :     m_pFmtFldStepMain->UseInputStringForFormatting();
     524           0 :     m_pFmtFldOrigin->UseInputStringForFormatting();
     525             : 
     526           0 :     SetNumFormat();
     527           0 : }
     528             : 
     529           0 : void ScaleTabPage::SetNumFormat()
     530             : {
     531           0 :     const SfxPoolItem *pPoolItem = NULL;
     532             : 
     533           0 :     if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, true, &pPoolItem ) == SFX_ITEM_SET )
     534             :     {
     535           0 :         sal_uLong nFmt = (sal_uLong)((const SfxInt32Item*)pPoolItem)->GetValue();
     536             : 
     537           0 :         m_pFmtFldMax->SetFormatKey( nFmt );
     538           0 :         m_pFmtFldMin->SetFormatKey( nFmt );
     539           0 :         m_pFmtFldOrigin->SetFormatKey( nFmt );
     540             : 
     541           0 :         if( pNumFormatter )
     542             :         {
     543           0 :             short eType = pNumFormatter->GetType( nFmt );
     544           0 :             if( eType == NUMBERFORMAT_DATE )
     545             :             {
     546             :                 // for intervals use standard format for dates (so you can enter a number of days)
     547           0 :                 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
     548           0 :                 if( pFormat )
     549           0 :                     nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage());
     550             :                 else
     551           0 :                     nFmt = pNumFormatter->GetStandardIndex();
     552             :             }
     553           0 :             else if( eType == NUMBERFORMAT_DATETIME )
     554             :             {
     555             :                 // for intervals use time format for date times
     556           0 :                 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
     557           0 :                 if( pFormat )
     558           0 :                     nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_TIME, pFormat->GetLanguage() );
     559             :                 else
     560           0 :                     nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_TIME );
     561             :             }
     562             : 
     563           0 :             if( chart2::AxisType::DATE == m_nAxisType && ( eType != NUMBERFORMAT_DATE && eType != NUMBERFORMAT_DATETIME) )
     564             :             {
     565           0 :                 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
     566           0 :                 if( pFormat )
     567           0 :                     nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_DATE, pFormat->GetLanguage() );
     568             :                 else
     569           0 :                     nFmt = pNumFormatter->GetStandardFormat( NUMBERFORMAT_DATE );
     570             : 
     571           0 :                 m_pFmtFldMax->SetFormatKey( nFmt );
     572           0 :                 m_pFmtFldMin->SetFormatKey( nFmt );
     573           0 :                 m_pFmtFldOrigin->SetFormatKey( nFmt );
     574             :             }
     575             :         }
     576             : 
     577           0 :         m_pFmtFldStepMain->SetFormatKey( nFmt );
     578             :     }
     579           0 : }
     580             : 
     581           0 : void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin )
     582             : {
     583           0 :     m_bShowAxisOrigin = bShowOrigin;
     584           0 :     if( !AxisHelper::isAxisPositioningEnabled() )
     585           0 :         m_bShowAxisOrigin = true;
     586           0 : }
     587             : 
     588           0 : bool ScaleTabPage::ShowWarning( sal_uInt16 nResIdMessage, Control* pControl /* = NULL */ )
     589             : {
     590           0 :     if( nResIdMessage == 0 )
     591           0 :         return false;
     592             : 
     593           0 :     WarningBox( this, WinBits( WB_OK ), SCH_RESSTR( nResIdMessage ) ).Execute();
     594           0 :     if( pControl )
     595             :     {
     596           0 :         pControl->GrabFocus();
     597           0 :         Edit* pEdit = dynamic_cast<Edit*>(pControl);
     598           0 :         if(pEdit)
     599           0 :             pEdit->SetSelection( Selection( 0, SELECTION_MAX ));
     600             :     }
     601           0 :     return true;
     602             : }
     603             : 
     604           0 : void ScaleTabPage::HideAllControls()
     605             : {
     606             :     // We need to set these controls invisible when the class is instantiated
     607             :     // since some code in EnableControls() depends on that logic. The real
     608             :     // visibility of these controls depend on axis data type, and are
     609             :     // set in EnableControls().
     610             : 
     611           0 :     m_pBxType->Hide();
     612           0 :     m_pCbxLogarithm->Hide();
     613           0 :     m_pBxMinMax->Hide();
     614           0 :     m_pBxMain->Hide();
     615           0 :     m_pBxMinor->Hide();
     616           0 :     m_pBxOrigin->Hide();
     617           0 :     m_pBxResolution->Hide();
     618           0 : }
     619             : 
     620          45 : } //namespace chart
     621             : 
     622             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10