Files
libreoffice/chart2/source/controller/dialogs/tp_Scale.cxx
Vladimir Glazounov 7d76b7ef41 INTEGRATION: CWS chart2mst3 (1.2.4); FILE MERGED
2007/05/18 16:12:16 bm 1.2.4.13: #i74635# ResMgr cleanup ResId -> SchResId
2007/05/14 20:03:33 bm 1.2.4.12: RESYNC: (1.5-1.7); FILE MERGED
2007/05/03 08:07:36 iha 1.2.4.11: #i76842# warning for scale tabpage when min > max
2007/03/19 15:01:38 iha 1.2.4.10: #i73605#, #i75389# use correct numberformat for scale tabpage and numbers tabpage
2007/03/04 14:44:44 iha 1.2.4.9: changes according to Scales and Intervals Spec
2007/02/06 12:07:58 iha 1.2.4.8: warning for major interval <=0
2006/10/27 18:42:09 iha 1.2.4.7: added warnings STR_STEP_GT_ZERO and STR_BAD_LOGARITHM tp scale tab page + remove unused code
2006/10/18 17:04:59 bm 1.2.4.6: RESYNC: (1.4-1.5); FILE MERGED
2006/02/20 14:45:46 iha 1.2.4.5: move SchItemPool from controller to view lib -> ChartItemPool
2006/01/25 09:59:39 bm 1.2.4.4: RESYNC: (1.3-1.4); FILE MERGED
2005/10/07 11:20:56 bm 1.2.4.3: RESYNC: (1.2-1.3); FILE MERGED
2004/05/17 17:33:52 iha 1.2.4.2: provide object naming; resource cleanup
2004/04/27 15:00:38 iha 1.2.4.1: warnings removed
2007-05-22 16:48:21 +00:00

435 lines
15 KiB
C++

/*************************************************************************
*
* OpenOffice.org - a multi-platform office productivity suite
*
* $RCSfile: tp_Scale.cxx,v $
*
* $Revision: 1.8 $
*
* last change: $Author: vg $ $Date: 2007-05-22 17:48:21 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
*
*
* GNU Lesser General Public License Version 2.1
* =============================================
* Copyright 2005 by Sun Microsystems, Inc.
* 901 San Antonio Road, Palo Alto, CA 94303, USA
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307 USA
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_chart2.hxx"
#include "tp_Scale.hxx"
#include "ResId.hxx"
#include "TabPages.hrc"
#include "Strings.hrc"
#include "chartview/ChartSfxItemIds.hxx"
#include "NoWarningThisInCTOR.hxx"
#ifndef _SVX_SVXIDS_HRC
#include <svx/svxids.hrc>
#endif
#ifndef INCLUDED_RTL_MATH_HXX
#include <rtl/math.hxx>
#endif
// header for class SvxDoubleItem
#ifndef _SVX_CHRTITEM_HXX
#include <svx/chrtitem.hxx>
#endif
// header for class SfxBoolItem
#ifndef _SFXENUMITEM_HXX
#include <svtools/eitem.hxx>
#endif
// header for SfxInt32Item
#ifndef _SFXINTITEM_HXX
#include <svtools/intitem.hxx>
#endif
// header for class WarningBox
#ifndef _SV_MSGBOX_HXX
#include <vcl/msgbox.hxx>
#endif
// header for class SvNumberformat
#ifndef _ZFORMAT_HXX
#ifndef _ZFORLIST_DECLARE_TABLE
#define _ZFORLIST_DECLARE_TABLE
#endif
#include <svtools/zformat.hxx>
#endif
//.............................................................................
namespace chart
{
//.............................................................................
SchScaleYAxisTabPage::SchScaleYAxisTabPage(Window* pWindow,const SfxItemSet& rInAttrs) :
SfxTabPage(pWindow, SchResId(TP_SCALE_Y), rInAttrs),
aFlScale(this, SchResId(FL_SCALE_Y)),
aTxtMin (this, SchResId (TXT_MIN)),
aFmtFldMin(this, SchResId(EDT_MIN)),
aCbxAutoMin(this, SchResId(CBX_AUTO_MIN)),
aTxtMax(this, SchResId (TXT_MAX)),
aFmtFldMax(this, SchResId(EDT_MAX)),
aCbxAutoMax(this, SchResId(CBX_AUTO_MAX)),
aTxtMain (this, SchResId (TXT_STEP_MAIN)),
aFmtFldStepMain(this, SchResId(EDT_STEP_MAIN)),
aCbxAutoStepMain(this, SchResId(CBX_AUTO_STEP_MAIN)),
aTxtHelp (this, SchResId (TXT_STEP_HELP)),
aMtStepHelp (this, SchResId (MT_STEPHELP)),
aCbxAutoStepHelp(this, SchResId(CBX_AUTO_STEP_HELP)),
aTxtOrigin (this, SchResId (TXT_ORIGIN)),
aFmtFldOrigin(this, SchResId(EDT_ORIGIN)),
aCbxAutoOrigin(this, SchResId(CBX_AUTO_ORIGIN)),
aCbxLogarithm(this, SchResId(CBX_LOGARITHM)),
aFlTicks(this,SchResId(FL_TICKS)),
aCbxTicksInner(this, SchResId(CBX_TICKS_INNER)),
aCbxTicksOuter(this, SchResId(CBX_TICKS_OUTER)),
aFlHelpTicks(this,SchResId(FL_HELPTICKS)),
aCbxHelpTicksInner(this, SchResId(CBX_HELPTICKS_INNER)),
aCbxHelpTicksOuter(this, SchResId(CBX_HELPTICKS_OUTER)),
fMin(0.0),
fMax(0.0),
fStepMain(0.0),
nStepHelp(0),
fOrigin(0.0),
nAxisType(0),
pNumFormatter(NULL)
{
FreeResource();
SetExchangeSupport();
aCbxAutoMin.SetClickHdl(LINK(this, SchScaleYAxisTabPage, EnableValueHdl));
aCbxAutoMax.SetClickHdl(LINK(this, SchScaleYAxisTabPage, EnableValueHdl));
aCbxAutoStepMain.SetClickHdl(LINK(this, SchScaleYAxisTabPage, EnableValueHdl));
aCbxAutoStepHelp.SetClickHdl(LINK(this, SchScaleYAxisTabPage, EnableValueHdl));
aCbxAutoOrigin.SetClickHdl(LINK(this, SchScaleYAxisTabPage, EnableValueHdl));
const SfxPoolItem *pPoolItem = NULL;
if (rInAttrs.GetItemState(SCHATTR_AXISTYPE, TRUE, &pPoolItem) == SFX_ITEM_SET)
nAxisType = (int) ((const SfxInt32Item*)pPoolItem)->GetValue();
}
IMPL_LINK( SchScaleYAxisTabPage, EnableValueHdl, CheckBox *, pCbx )
{
if (pCbx == &aCbxAutoMin)
{
aFmtFldMin.Enable(!aCbxAutoMin.IsChecked());
}
else if (pCbx == &aCbxAutoMax)
{
aFmtFldMax.Enable(!aCbxAutoMax.IsChecked());
}
else if (pCbx == &aCbxAutoStepMain)
{
aFmtFldStepMain.Enable(!aCbxAutoStepMain.IsChecked());
}
else if (pCbx == &aCbxAutoStepHelp)
{
aMtStepHelp.Show ();
aMtStepHelp.Enable( ! aCbxAutoStepHelp.IsChecked() );
}
else if (pCbx == &aCbxAutoOrigin)
{
aFmtFldOrigin.Enable(!aCbxAutoOrigin.IsChecked());
}
return 0;
}
SfxTabPage* SchScaleYAxisTabPage::Create(Window* pWindow,const SfxItemSet& rOutAttrs)
{
return new SchScaleYAxisTabPage(pWindow, rOutAttrs);
}
BOOL SchScaleYAxisTabPage::FillItemSet(SfxItemSet& rOutAttrs)
{
DBG_ASSERT( pNumFormatter, "No NumberFormatter available" );
long nTicks=0;
long nHelpTicks=0;
if(aCbxHelpTicksInner.IsChecked())
nHelpTicks|=CHAXIS_MARK_INNER;
if(aCbxHelpTicksOuter.IsChecked())
nHelpTicks|=CHAXIS_MARK_OUTER;
if(aCbxTicksInner.IsChecked())
nTicks|=CHAXIS_MARK_INNER;
if(aCbxTicksOuter.IsChecked())
nTicks|=CHAXIS_MARK_OUTER;
rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_TICKS,nTicks));
rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS,nHelpTicks));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN ,aCbxAutoMin.IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX ,aCbxAutoMax.IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,aCbxAutoStepHelp.IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN ,aCbxAutoOrigin.IsChecked()));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM ,aCbxLogarithm.IsChecked()));
rOutAttrs.Put(SvxDoubleItem(fMax , SCHATTR_AXIS_MAX));
rOutAttrs.Put(SvxDoubleItem(fMin , SCHATTR_AXIS_MIN));
rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP, nStepHelp));
rOutAttrs.Put(SvxDoubleItem(fOrigin , SCHATTR_AXIS_ORIGIN));
rOutAttrs.Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,aCbxAutoStepMain.IsChecked()));
rOutAttrs.Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN));
return TRUE;
}
void SchScaleYAxisTabPage::Reset(const SfxItemSet& rInAttrs)
{
DBG_ASSERT( pNumFormatter, "No NumberFormatter available" );
if(!pNumFormatter)
return;
const SfxPoolItem *pPoolItem = NULL;
long nTicks=0,nHelpTicks=0;
if(rInAttrs.GetItemState(SCHATTR_AXIS_TICKS,TRUE, &pPoolItem)== SFX_ITEM_SET)
nTicks=((const SfxInt32Item*)pPoolItem)->GetValue();
if(rInAttrs.GetItemState(SCHATTR_AXIS_HELPTICKS,TRUE, &pPoolItem)== SFX_ITEM_SET)
nHelpTicks=((const SfxInt32Item*)pPoolItem)->GetValue();
aCbxHelpTicksInner.Check(BOOL(nHelpTicks&CHAXIS_MARK_INNER));
aCbxHelpTicksOuter.Check(BOOL(nHelpTicks&CHAXIS_MARK_OUTER));
aCbxTicksInner.Check(BOOL(nTicks&CHAXIS_MARK_INNER));
aCbxTicksOuter.Check(BOOL(nTicks&CHAXIS_MARK_OUTER));
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_MIN,TRUE,&pPoolItem) == SFX_ITEM_SET)
aCbxAutoMin.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_MIN,TRUE, &pPoolItem) == SFX_ITEM_SET)
{
fMin = ((const SvxDoubleItem*)pPoolItem)->GetValue();
aFmtFldMin.SetValue( fMin );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_MAX,TRUE, &pPoolItem) == SFX_ITEM_SET)
aCbxAutoMax.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_MAX,TRUE, &pPoolItem) == SFX_ITEM_SET)
{
fMax = ((const SvxDoubleItem*)pPoolItem)->GetValue();
aFmtFldMax.SetValue( fMax );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN,TRUE, &pPoolItem) == SFX_ITEM_SET)
aCbxAutoStepMain.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_STEP_MAIN,TRUE, &pPoolItem) == SFX_ITEM_SET)
{
fStepMain = ((const SvxDoubleItem*)pPoolItem)->GetValue();
aFmtFldStepMain.SetValue( fStepMain );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP,TRUE, &pPoolItem) == SFX_ITEM_SET)
aCbxAutoStepHelp.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_LOGARITHM,TRUE, &pPoolItem) == SFX_ITEM_SET)
aCbxLogarithm.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_STEP_HELP,TRUE, &pPoolItem) == SFX_ITEM_SET)
{
nStepHelp = ((const SfxInt32Item*)pPoolItem)->GetValue();
aMtStepHelp.SetValue( nStepHelp );
}
if (rInAttrs.GetItemState(SCHATTR_AXIS_AUTO_ORIGIN,TRUE, &pPoolItem) == SFX_ITEM_SET)
aCbxAutoOrigin.Check(((const SfxBoolItem*)pPoolItem)->GetValue());
if (rInAttrs.GetItemState(SCHATTR_AXIS_ORIGIN,TRUE, &pPoolItem) == SFX_ITEM_SET)
{
fOrigin = ((const SvxDoubleItem*)pPoolItem)->GetValue();
aFmtFldOrigin.SetValue( fOrigin );
}
EnableValueHdl(&aCbxAutoMin);
EnableValueHdl(&aCbxAutoMax);
EnableValueHdl(&aCbxAutoStepMain);
EnableValueHdl(&aCbxAutoStepHelp);
EnableValueHdl(&aCbxAutoOrigin);
}
int SchScaleYAxisTabPage::DeactivatePage(SfxItemSet* pItemSet)
{
if( !pNumFormatter )
{
DBG_ERROR( "No NumberFormatter available" );
return LEAVE_PAGE;
}
sal_uInt32 nIndex = pNumFormatter->GetStandardIndex(LANGUAGE_SYSTEM);
Edit* pEdit = NULL;
USHORT nErrStrId = 0;
double fDummy;
fMax = aFmtFldMax.GetValue();
fMin = aFmtFldMin.GetValue();
fOrigin = aFmtFldOrigin.GetValue();
fStepMain = aFmtFldStepMain.GetValue();
nStepHelp = aMtStepHelp.GetValue();
//do some reasonable automatic correction of user input if necessary
if (!aCbxAutoMax.IsChecked() && !aCbxAutoMin.IsChecked() &&
fMin >= fMax)
{
pEdit = &aFmtFldMin;
nErrStrId = STR_MIN_GREATER_MAX;
}
// check for entries in invalid ranges
if ( aCbxLogarithm.IsChecked() &&
( ( !aCbxAutoMin.IsChecked() && fMin <= 0.0 )
|| ( !aCbxAutoMax.IsChecked() && fMax <= 0.0 ) ) )
{
pEdit = &aFmtFldMin;
nErrStrId = STR_BAD_LOGARITHM;
}
if (!aCbxAutoStepMain.IsChecked() && fStepMain <= 0)
{
pEdit = &aFmtFldStepMain;
nErrStrId = STR_STEP_GT_ZERO;
}
//user often forgets to switch visibility of help tickmarks on
if( !aCbxAutoStepHelp.IsChecked() && aMtStepHelp.IsModified() && nStepHelp > 1
&& !aCbxHelpTicksInner.IsChecked() && !aCbxHelpTicksOuter.IsChecked() )
//&& !aCbxHelpTicksInner.IsModified() && !aCbxHelpTicksOuter.IsModified() )
{
//check help ticks like main ticks
if(aCbxTicksInner.IsChecked())
aCbxHelpTicksInner.Check();
if(aCbxTicksOuter.IsChecked())
aCbxHelpTicksOuter.Check();
}
//check wich entries need user action
// check for entries that cannot be parsed for the current number format
if ( aFmtFldMin.IsModified()
&& !aCbxAutoMin.IsChecked()
&& !pNumFormatter->IsNumberFormat(aFmtFldMin.GetText(), nIndex, fDummy))
{
pEdit = &aFmtFldMin;
nErrStrId = STR_INVALID_NUMBER;
}
else if (aFmtFldMax.IsModified() && !aCbxAutoMax.IsChecked() &&
!pNumFormatter->IsNumberFormat(aFmtFldMax.GetText(),
nIndex, fDummy))
{
pEdit = &aFmtFldMax;
nErrStrId = STR_INVALID_NUMBER;
}
else if (aFmtFldStepMain.IsModified() && !aCbxAutoStepMain.IsChecked() &&
!pNumFormatter->IsNumberFormat(aFmtFldStepMain.GetText(),
nIndex, fDummy))
{
pEdit = &aFmtFldStepMain;
nErrStrId = STR_STEP_GT_ZERO;
}
else if (aFmtFldOrigin.IsModified() && !aCbxAutoOrigin.IsChecked() &&
!pNumFormatter->IsNumberFormat(aFmtFldOrigin.GetText(),
nIndex, fDummy))
{
pEdit = &aFmtFldOrigin;
nErrStrId = STR_INVALID_NUMBER;
}
else if (!aCbxAutoStepMain.IsChecked() && fStepMain <= 0.0)
{
pEdit = &aFmtFldStepMain;
nErrStrId = STR_STEP_GT_ZERO;
}
if( ShowWarning( nErrStrId, pEdit ) )
return KEEP_PAGE;
if( pItemSet )
FillItemSet( *pItemSet );
return LEAVE_PAGE;
}
void SchScaleYAxisTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
{
pNumFormatter = pFormatter;
aFmtFldMax.SetFormatter( pNumFormatter );
aFmtFldMin.SetFormatter( pNumFormatter );
aFmtFldStepMain.SetFormatter( pNumFormatter );
aFmtFldOrigin.SetFormatter( pNumFormatter );
SetNumFormat();
}
void SchScaleYAxisTabPage::SetNumFormat()
{
const SfxPoolItem *pPoolItem = NULL;
if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, TRUE, &pPoolItem ) == SFX_ITEM_SET )
{
ULONG nFmt = (ULONG)((const SfxInt32Item*)pPoolItem)->GetValue();
short eType = pNumFormatter->GetType( nFmt );
// change nFmt to an editable format (without loss of information)
if( eType == NUMBERFORMAT_CURRENCY ) // for currencies just display decimals
{
nFmt = pNumFormatter->GetStandardIndex();
}
else
{
const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
if( pFormat )
{
LanguageType eLanguage = pFormat->GetLanguage();
nFmt = pNumFormatter->GetStandardFormat( nFmt, eType, eLanguage );
}
// else: format is 'standard'
}
aFmtFldMax.SetFormatKey( nFmt );
aFmtFldMin.SetFormatKey( nFmt );
aFmtFldOrigin.SetFormatKey( nFmt );
// for steps use standard format if date or time format is chosen
if( pNumFormatter &&
( eType == NUMBERFORMAT_DATE ||
eType == NUMBERFORMAT_TIME ||
eType == NUMBERFORMAT_DATETIME ) )
{
nFmt = pNumFormatter->GetStandardIndex();
}
aFmtFldStepMain.SetFormatKey( nFmt );
}
}
bool SchScaleYAxisTabPage::ShowWarning( USHORT nResIdMessage, Edit * pControl /* = NULL */ )
{
if( nResIdMessage == 0 )
return false;
WarningBox( this, WinBits( WB_OK ), String( SchResId( nResIdMessage ))).Execute();
if( pControl )
{
pControl->GrabFocus();
pControl->SetSelection( Selection( 0, SELECTION_MAX ));
}
return true;
}
//.............................................................................
} //namespace chart
//.............................................................................