fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_Scale.cxx
blobf27f8e8cf64cdf3e49589f3dc53b692722d0a7a0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "tp_Scale.hxx"
22 #include "ResId.hxx"
23 #include "Strings.hrc"
24 #include "chartview/ChartSfxItemIds.hxx"
25 #include "AxisHelper.hxx"
27 #include <svx/svxids.hrc>
28 #include <rtl/math.hxx>
29 #include <svx/chrtitem.hxx>
30 #include <svl/eitem.hxx>
31 #include <svl/intitem.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <svl/zformat.hxx>
34 #include <svtools/controldims.hrc>
36 #include <com/sun/star/chart2/AxisType.hpp>
38 using namespace ::com::sun::star;
40 namespace chart
43 namespace
46 void lcl_setValue( FormattedField& rFmtField, double fValue )
48 rFmtField.SetValue( fValue );
49 rFmtField.SetDefaultValue( fValue );
54 ScaleTabPage::ScaleTabPage(vcl::Window* pWindow,const SfxItemSet& rInAttrs) :
55 SfxTabPage(pWindow
56 , "tp_Scale"
57 , "modules/schart/ui/tp_Scale.ui"
58 , &rInAttrs),
59 fMin(0.0),
60 fMax(0.0),
61 fStepMain(0.0),
62 nStepHelp(0),
63 fOrigin(0.0),
64 m_nTimeResolution(1),
65 m_nMainTimeUnit(1),
66 m_nHelpTimeUnit(1),
67 m_nAxisType(chart2::AxisType::REALNUMBER),
68 m_bAllowDateAxis(false),
69 pNumFormatter(NULL),
70 m_bShowAxisOrigin(false)
72 get(m_pCbxReverse, "CBX_REVERSE");
73 get(m_pCbxLogarithm, "CBX_LOGARITHM");
74 get(m_pLB_AxisType, "LB_AXIS_TYPE");
75 get(m_pBxType,"boxTYPE");
77 get(m_pBxMinMax, "gridMINMAX");
78 get(m_pFmtFldMin, "EDT_MIN");
79 get(m_pCbxAutoMin, "CBX_AUTO_MIN");
80 get(m_pFmtFldMax, "EDT_MAX");
81 get(m_pCbxAutoMax, "CBX_AUTO_MAX");
83 get(m_pBxResolution, "boxRESOLUTION");
84 get(m_pLB_TimeResolution, "LB_TIME_RESOLUTION");
85 get(m_pCbx_AutoTimeResolution, "CBX_AUTO_TIME_RESOLUTION");
87 get(m_pTxtMain, "TXT_STEP_MAIN");
88 get(m_pFmtFldStepMain, "EDT_STEP_MAIN");
89 get(m_pMt_MainDateStep, "MT_MAIN_DATE_STEP");
90 get(m_pLB_MainTimeUnit, "LB_MAIN_TIME_UNIT");
91 get(m_pCbxAutoStepMain, "CBX_AUTO_STEP_MAIN");
93 get(m_pMtStepHelp, "MT_STEPHELP");
94 get(m_pLB_HelpTimeUnit, "LB_HELP_TIME_UNIT");
95 get(m_pCbxAutoStepHelp, "CBX_AUTO_STEP_HELP");
96 get(m_pTxtHelpCount,"TXT_STEP_HELP_COUNT");
97 get(m_pTxtHelp,"TXT_STEP_HELP");
99 get(m_pBxOrigin,"boxORIGIN");
100 get(m_pFmtFldOrigin, "EDT_ORIGIN");
101 get(m_pCbxAutoOrigin, "CBX_AUTO_ORIGIN");
103 m_pCbxAutoMin->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
104 m_pCbxAutoMax->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
105 m_pCbxAutoStepMain->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
106 m_pCbxAutoStepHelp->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
107 m_pCbxAutoOrigin->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
108 m_pCbx_AutoTimeResolution->SetClickHdl(LINK(this, ScaleTabPage, EnableValueHdl));
110 m_pLB_AxisType->SetDropDownLineCount(3);
111 m_pLB_AxisType->SetSelectHdl(LINK(this, ScaleTabPage, SelectAxisTypeHdl));
113 m_pLB_TimeResolution->SetDropDownLineCount(3);
114 m_pLB_MainTimeUnit->SetDropDownLineCount(3);
115 m_pLB_HelpTimeUnit->SetDropDownLineCount(3);
117 m_pFmtFldMin->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
118 m_pFmtFldMax->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
119 m_pFmtFldStepMain->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
120 m_pFmtFldOrigin->SetModifyHdl(LINK(this, ScaleTabPage, FmtFieldModifiedHdl));
122 HideAllControls();
125 ScaleTabPage::~ScaleTabPage()
127 disposeOnce();
130 void ScaleTabPage::dispose()
132 m_pCbxReverse.clear();
133 m_pCbxLogarithm.clear();
134 m_pBxType.clear();
135 m_pLB_AxisType.clear();
136 m_pBxMinMax.clear();
137 m_pFmtFldMin.clear();
138 m_pCbxAutoMin.clear();
139 m_pFmtFldMax.clear();
140 m_pCbxAutoMax.clear();
141 m_pBxResolution.clear();
142 m_pLB_TimeResolution.clear();
143 m_pCbx_AutoTimeResolution.clear();
144 m_pTxtMain.clear();
145 m_pFmtFldStepMain.clear();
146 m_pMt_MainDateStep.clear();
147 m_pLB_MainTimeUnit.clear();
148 m_pCbxAutoStepMain.clear();
149 m_pTxtHelpCount.clear();
150 m_pTxtHelp.clear();
151 m_pMtStepHelp.clear();
152 m_pLB_HelpTimeUnit.clear();
153 m_pCbxAutoStepHelp.clear();
154 m_pFmtFldOrigin.clear();
155 m_pCbxAutoOrigin.clear();
156 m_pBxOrigin.clear();
157 SfxTabPage::dispose();
160 IMPL_STATIC_LINK(
161 ScaleTabPage, FmtFieldModifiedHdl, FormattedField*, pFmtFied )
163 if( pFmtFied )
164 pFmtFied->SetDefaultValue( pFmtFied->GetValue() );
165 return 0;
168 void ScaleTabPage::StateChanged( StateChangedType nType )
170 TabPage::StateChanged( nType );
173 void ScaleTabPage::EnableControls()
175 bool bValueAxis = chart2::AxisType::REALNUMBER == m_nAxisType
176 || chart2::AxisType::PERCENT == m_nAxisType
177 || chart2::AxisType::DATE == m_nAxisType;
178 bool bDateAxis = chart2::AxisType::DATE == m_nAxisType;
180 m_pBxType->Show(m_bAllowDateAxis);
182 m_pCbxLogarithm->Show( bValueAxis && !bDateAxis );
184 m_pBxMinMax->Show(bValueAxis);
186 m_pTxtMain->Show( bValueAxis );
187 m_pCbxAutoStepMain->Show( bValueAxis );
189 m_pTxtHelpCount->Show( bValueAxis && !bDateAxis );
190 m_pTxtHelp->Show( bDateAxis );
191 m_pMtStepHelp->Show( bValueAxis );
192 m_pCbxAutoStepHelp->Show( bValueAxis );
194 m_pBxOrigin->Show( m_bShowAxisOrigin && bValueAxis );
195 m_pBxResolution->Show( bDateAxis );
197 bool bWasDateAxis = m_pMt_MainDateStep->IsVisible();
198 if( bWasDateAxis != bDateAxis )
200 //transport value from one to other control
201 if( bWasDateAxis )
202 lcl_setValue( *m_pFmtFldStepMain, m_pMt_MainDateStep->GetValue() );
203 else
204 m_pMt_MainDateStep->SetValue( static_cast<sal_Int32>(m_pFmtFldStepMain->GetValue()) );
207 m_pFmtFldStepMain->Show( bValueAxis && !bDateAxis );
208 m_pMt_MainDateStep->Show( bDateAxis );
210 m_pLB_MainTimeUnit->Show( bDateAxis );
211 m_pLB_HelpTimeUnit->Show( bDateAxis );
213 EnableValueHdl(m_pCbxAutoMin);
214 EnableValueHdl(m_pCbxAutoMax);
215 EnableValueHdl(m_pCbxAutoStepMain);
216 EnableValueHdl(m_pCbxAutoStepHelp);
217 EnableValueHdl(m_pCbxAutoOrigin);
218 EnableValueHdl(m_pCbx_AutoTimeResolution);
221 IMPL_LINK( ScaleTabPage, EnableValueHdl, CheckBox *, pCbx )
223 bool bEnable = pCbx && !pCbx->IsChecked() && pCbx->IsEnabled();
224 if (pCbx == m_pCbxAutoMin)
226 m_pFmtFldMin->Enable( bEnable );
228 else if (pCbx == m_pCbxAutoMax)
230 m_pFmtFldMax->Enable( bEnable );
232 else if (pCbx == m_pCbxAutoStepMain)
234 m_pFmtFldStepMain->Enable( bEnable );
235 m_pMt_MainDateStep->Enable( bEnable );
236 m_pLB_MainTimeUnit->Enable( bEnable );
238 else if (pCbx == m_pCbxAutoStepHelp)
240 m_pMtStepHelp->Enable( bEnable );
241 m_pLB_HelpTimeUnit->Enable( bEnable );
243 else if (pCbx == m_pCbx_AutoTimeResolution)
245 m_pLB_TimeResolution->Enable( bEnable );
247 else if (pCbx == m_pCbxAutoOrigin)
249 m_pFmtFldOrigin->Enable( bEnable );
251 return 0;
254 enum AxisTypeListBoxEntry
256 TYPE_AUTO=0,
257 TYPE_TEXT=1,
258 TYPE_DATE=2
261 IMPL_LINK_NOARG(ScaleTabPage, SelectAxisTypeHdl)
263 sal_uInt16 nPos = m_pLB_AxisType->GetSelectEntryPos();
264 if( nPos==TYPE_DATE )
265 m_nAxisType = chart2::AxisType::DATE;
266 else
267 m_nAxisType = chart2::AxisType::CATEGORY;
268 if( chart2::AxisType::DATE == m_nAxisType )
269 m_pCbxLogarithm->Check(false);
270 EnableControls();
271 SetNumFormat();
272 return 0;
275 VclPtr<SfxTabPage> ScaleTabPage::Create(vcl::Window* pWindow,const SfxItemSet* rOutAttrs)
277 return VclPtr<ScaleTabPage>::Create(pWindow, *rOutAttrs);
280 bool ScaleTabPage::FillItemSet(SfxItemSet* rOutAttrs)
282 OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
284 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXISTYPE, m_nAxisType));
285 if(m_bAllowDateAxis)
286 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, TYPE_AUTO==m_pLB_AxisType->GetSelectEntryPos()));
288 bool bAutoScale = false;
289 if( m_nAxisType==chart2::AxisType::CATEGORY )
290 bAutoScale = true;//reset scaling for category charts
292 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN ,bAutoScale || m_pCbxAutoMin->IsChecked()));
293 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX ,bAutoScale || m_pCbxAutoMax->IsChecked()));
294 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,bAutoScale || m_pCbxAutoStepHelp->IsChecked()));
295 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN ,bAutoScale || m_pCbxAutoOrigin->IsChecked()));
296 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM ,m_pCbxLogarithm->IsChecked()));
297 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_REVERSE ,m_pCbxReverse->IsChecked()));
298 rOutAttrs->Put(SvxDoubleItem(fMax , SCHATTR_AXIS_MAX));
299 rOutAttrs->Put(SvxDoubleItem(fMin , SCHATTR_AXIS_MIN));
300 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP, nStepHelp));
301 rOutAttrs->Put(SvxDoubleItem(fOrigin , SCHATTR_AXIS_ORIGIN));
303 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || m_pCbxAutoStepMain->IsChecked()));
304 rOutAttrs->Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN));
306 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,bAutoScale || m_pCbx_AutoTimeResolution->IsChecked()));
307 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION,m_nTimeResolution));
309 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,m_nMainTimeUnit));
310 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,m_nHelpTimeUnit));
312 return true;
315 void ScaleTabPage::Reset(const SfxItemSet* rInAttrs)
317 OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
318 if(!pNumFormatter)
319 return;
321 const SfxPoolItem *pPoolItem = NULL;
322 if (rInAttrs->GetItemState(SCHATTR_AXIS_ALLOW_DATEAXIS, true, &pPoolItem) == SfxItemState::SET)
323 m_bAllowDateAxis = (bool) static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
324 m_nAxisType=chart2::AxisType::REALNUMBER;
325 if (rInAttrs->GetItemState(SCHATTR_AXISTYPE, true, &pPoolItem) == SfxItemState::SET)
326 m_nAxisType = (int) static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
327 if( m_nAxisType==chart2::AxisType::DATE && !m_bAllowDateAxis )
328 m_nAxisType=chart2::AxisType::CATEGORY;
329 if( m_bAllowDateAxis )
331 bool bAutoDateAxis = false;
332 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_DATEAXIS, true, &pPoolItem) == SfxItemState::SET)
333 bAutoDateAxis = (bool) static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
335 sal_uInt16 nPos = 0;
336 if( m_nAxisType==chart2::AxisType::DATE )
337 nPos=TYPE_DATE;
338 else if( bAutoDateAxis )
339 nPos=TYPE_AUTO;
340 else
341 nPos=TYPE_TEXT;
342 m_pLB_AxisType->SelectEntryPos( nPos );
345 m_pCbxAutoMin->Check( true );
346 m_pCbxAutoMax->Check( true );
347 m_pCbxAutoStepMain->Check( true );
348 m_pCbxAutoStepHelp->Check( true );
349 m_pCbxAutoOrigin->Check( true );
350 m_pCbx_AutoTimeResolution->Check( true );
352 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_MIN,true,&pPoolItem) == SfxItemState::SET)
353 m_pCbxAutoMin->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
355 if (rInAttrs->GetItemState(SCHATTR_AXIS_MIN,true, &pPoolItem) == SfxItemState::SET)
357 fMin = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
358 lcl_setValue( *m_pFmtFldMin, fMin );
361 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_MAX,true, &pPoolItem) == SfxItemState::SET)
362 m_pCbxAutoMax->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
364 if (rInAttrs->GetItemState(SCHATTR_AXIS_MAX,true, &pPoolItem) == SfxItemState::SET)
366 fMax = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
367 lcl_setValue( *m_pFmtFldMax, fMax );
370 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN,true, &pPoolItem) == SfxItemState::SET)
371 m_pCbxAutoStepMain->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
373 if (rInAttrs->GetItemState(SCHATTR_AXIS_STEP_MAIN,true, &pPoolItem) == SfxItemState::SET)
375 fStepMain = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
376 lcl_setValue( *m_pFmtFldStepMain, fStepMain );
377 m_pMt_MainDateStep->SetValue( static_cast<sal_Int32>(fStepMain) );
379 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP,true, &pPoolItem) == SfxItemState::SET)
380 m_pCbxAutoStepHelp->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
381 if (rInAttrs->GetItemState(SCHATTR_AXIS_LOGARITHM,true, &pPoolItem) == SfxItemState::SET)
382 m_pCbxLogarithm->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
383 if (rInAttrs->GetItemState(SCHATTR_AXIS_REVERSE,true, &pPoolItem) == SfxItemState::SET)
384 m_pCbxReverse->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
385 if (rInAttrs->GetItemState(SCHATTR_AXIS_STEP_HELP,true, &pPoolItem) == SfxItemState::SET)
387 nStepHelp = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
388 m_pMtStepHelp->SetValue( nStepHelp );
390 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_ORIGIN,true, &pPoolItem) == SfxItemState::SET)
391 m_pCbxAutoOrigin->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
392 if (rInAttrs->GetItemState(SCHATTR_AXIS_ORIGIN,true, &pPoolItem) == SfxItemState::SET)
394 fOrigin = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
395 lcl_setValue( *m_pFmtFldOrigin, fOrigin );
398 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,true, &pPoolItem) == SfxItemState::SET)
399 m_pCbx_AutoTimeResolution->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
400 if (rInAttrs->GetItemState(SCHATTR_AXIS_TIME_RESOLUTION,true, &pPoolItem) == SfxItemState::SET)
402 m_nTimeResolution = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
403 m_pLB_TimeResolution->SelectEntryPos( m_nTimeResolution );
406 if (rInAttrs->GetItemState(SCHATTR_AXIS_MAIN_TIME_UNIT,true, &pPoolItem) == SfxItemState::SET)
408 m_nMainTimeUnit = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
409 m_pLB_MainTimeUnit->SelectEntryPos( m_nMainTimeUnit );
411 if (rInAttrs->GetItemState(SCHATTR_AXIS_HELP_TIME_UNIT,true, &pPoolItem) == SfxItemState::SET)
413 m_nHelpTimeUnit = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
414 m_pLB_HelpTimeUnit->SelectEntryPos( m_nHelpTimeUnit );
417 EnableControls();
418 SetNumFormat();
421 SfxTabPage::sfxpg ScaleTabPage::DeactivatePage(SfxItemSet* pItemSet)
423 if( !pNumFormatter )
425 OSL_FAIL( "No NumberFormatter available" );
426 return LEAVE_PAGE;
429 bool bDateAxis = chart2::AxisType::DATE == m_nAxisType;
431 sal_uInt32 nMinMaxOriginFmt = m_pFmtFldMax->GetFormatKey();
432 if ((pNumFormatter->GetType(nMinMaxOriginFmt) & ~css::util::NumberFormat::DEFINED) == css::util::NumberFormat::TEXT)
433 nMinMaxOriginFmt = 0;
434 // numberformat_text cause numbers to fail being numbers... Shouldn't happen, but can.
435 sal_uInt32 nStepFmt = m_pFmtFldStepMain->GetFormatKey();
436 if ((pNumFormatter->GetType(nStepFmt) & ~css::util::NumberFormat::DEFINED) == css::util::NumberFormat::TEXT)
437 nStepFmt = 0;
439 Control* pControl = NULL;
440 sal_uInt16 nErrStrId = 0;
441 double fDummy;
443 fMax = m_pFmtFldMax->GetValue();
444 fMin = m_pFmtFldMin->GetValue();
445 fOrigin = m_pFmtFldOrigin->GetValue();
446 fStepMain = bDateAxis ? m_pMt_MainDateStep->GetValue() : m_pFmtFldStepMain->GetValue();
447 nStepHelp = static_cast< sal_Int32 >( m_pMtStepHelp->GetValue());
448 m_nTimeResolution = m_pLB_TimeResolution->GetSelectEntryPos();
449 m_nMainTimeUnit = m_pLB_MainTimeUnit->GetSelectEntryPos();
450 m_nHelpTimeUnit = m_pLB_HelpTimeUnit->GetSelectEntryPos();
452 if( chart2::AxisType::REALNUMBER != m_nAxisType )
453 m_pCbxLogarithm->Show( false );
455 //check which entries need user action
457 if ( m_pCbxLogarithm->IsChecked() &&
458 ( ( !m_pCbxAutoMin->IsChecked() && fMin <= 0.0 )
459 || ( !m_pCbxAutoMax->IsChecked() && fMax <= 0.0 ) ) )
461 pControl = m_pFmtFldMin;
462 nErrStrId = STR_BAD_LOGARITHM;
464 // check for entries that cannot be parsed for the current number format
465 else if ( m_pFmtFldMin->IsModified()
466 && !m_pCbxAutoMin->IsChecked()
467 && !pNumFormatter->IsNumberFormat( m_pFmtFldMin->GetText(), nMinMaxOriginFmt, fDummy))
469 pControl = m_pFmtFldMin;
470 nErrStrId = STR_INVALID_NUMBER;
472 else if ( m_pFmtFldMax->IsModified()
473 && !m_pCbxAutoMax->IsChecked()
474 && !pNumFormatter->IsNumberFormat( m_pFmtFldMax->GetText(), nMinMaxOriginFmt, fDummy))
476 pControl = m_pFmtFldMax;
477 nErrStrId = STR_INVALID_NUMBER;
479 else if ( !bDateAxis && m_pFmtFldStepMain->IsModified()
480 && !m_pCbxAutoStepMain->IsChecked()
481 && !pNumFormatter->IsNumberFormat( m_pFmtFldStepMain->GetText(), nStepFmt, fDummy))
483 pControl = m_pFmtFldStepMain;
484 nErrStrId = STR_INVALID_NUMBER;
486 else if (m_pFmtFldOrigin->IsModified() && !m_pCbxAutoOrigin->IsChecked() &&
487 !pNumFormatter->IsNumberFormat( m_pFmtFldOrigin->GetText(), nMinMaxOriginFmt, fDummy))
489 pControl = m_pFmtFldOrigin;
490 nErrStrId = STR_INVALID_NUMBER;
492 else if (!m_pCbxAutoStepMain->IsChecked() && fStepMain <= 0.0)
494 pControl = m_pFmtFldStepMain;
495 nErrStrId = STR_STEP_GT_ZERO;
497 else if (!m_pCbxAutoMax->IsChecked() && !m_pCbxAutoMin->IsChecked() &&
498 fMin >= fMax)
500 pControl = m_pFmtFldMin;
501 nErrStrId = STR_MIN_GREATER_MAX;
503 else if( bDateAxis )
505 if( !m_pCbxAutoStepMain->IsChecked() && !m_pCbxAutoStepHelp->IsChecked() )
507 if( m_nHelpTimeUnit > m_nMainTimeUnit )
509 pControl = m_pLB_MainTimeUnit;
510 nErrStrId = STR_INVALID_INTERVALS;
512 else if( m_nHelpTimeUnit == m_nMainTimeUnit && nStepHelp > fStepMain )
514 pControl = m_pLB_MainTimeUnit;
515 nErrStrId = STR_INVALID_INTERVALS;
518 if( !nErrStrId && !m_pCbx_AutoTimeResolution->IsChecked() )
520 if( (!m_pCbxAutoStepMain->IsChecked() && m_nTimeResolution > m_nMainTimeUnit )
522 (!m_pCbxAutoStepHelp->IsChecked() && m_nTimeResolution > m_nHelpTimeUnit )
525 pControl = m_pLB_TimeResolution;
526 nErrStrId = STR_INVALID_TIME_UNIT;
531 if( ShowWarning( nErrStrId, pControl ) )
532 return KEEP_PAGE;
534 if( pItemSet )
535 FillItemSet( pItemSet );
537 return LEAVE_PAGE;
540 void ScaleTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
542 pNumFormatter = pFormatter;
543 m_pFmtFldMax->SetFormatter( pNumFormatter );
544 m_pFmtFldMin->SetFormatter( pNumFormatter );
545 m_pFmtFldStepMain->SetFormatter( pNumFormatter );
546 m_pFmtFldOrigin->SetFormatter( pNumFormatter );
548 // #i6278# allow more decimal places than the output format. As
549 // the numbers shown in the edit fields are used for input, it makes more
550 // sense to display the values in the input format rather than the output
551 // format.
552 m_pFmtFldMax->UseInputStringForFormatting();
553 m_pFmtFldMin->UseInputStringForFormatting();
554 m_pFmtFldStepMain->UseInputStringForFormatting();
555 m_pFmtFldOrigin->UseInputStringForFormatting();
557 SetNumFormat();
560 void ScaleTabPage::SetNumFormat()
562 const SfxPoolItem *pPoolItem = NULL;
564 if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, true, &pPoolItem ) == SfxItemState::SET )
566 sal_uLong nFmt = (sal_uLong)static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
568 m_pFmtFldMax->SetFormatKey( nFmt );
569 m_pFmtFldMin->SetFormatKey( nFmt );
570 m_pFmtFldOrigin->SetFormatKey( nFmt );
572 if( pNumFormatter )
574 short eType = pNumFormatter->GetType( nFmt );
575 if( eType == css::util::NumberFormat::DATE )
577 // for intervals use standard format for dates (so you can enter a number of days)
578 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
579 if( pFormat )
580 nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage());
581 else
582 nFmt = pNumFormatter->GetStandardIndex();
584 else if( eType == css::util::NumberFormat::DATETIME )
586 // for intervals use time format for date times
587 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
588 if( pFormat )
589 nFmt = pNumFormatter->GetStandardFormat( css::util::NumberFormat::TIME, pFormat->GetLanguage() );
590 else
591 nFmt = pNumFormatter->GetStandardFormat( css::util::NumberFormat::TIME );
594 if( chart2::AxisType::DATE == m_nAxisType && ( eType != css::util::NumberFormat::DATE && eType != css::util::NumberFormat::DATETIME) )
596 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
597 if( pFormat )
598 nFmt = pNumFormatter->GetStandardFormat( css::util::NumberFormat::DATE, pFormat->GetLanguage() );
599 else
600 nFmt = pNumFormatter->GetStandardFormat( css::util::NumberFormat::DATE );
602 m_pFmtFldMax->SetFormatKey( nFmt );
603 m_pFmtFldMin->SetFormatKey( nFmt );
604 m_pFmtFldOrigin->SetFormatKey( nFmt );
608 m_pFmtFldStepMain->SetFormatKey( nFmt );
612 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin )
614 m_bShowAxisOrigin = bShowOrigin;
615 if( !AxisHelper::isAxisPositioningEnabled() )
616 m_bShowAxisOrigin = true;
619 bool ScaleTabPage::ShowWarning( sal_uInt16 nResIdMessage, Control* pControl /* = NULL */ )
621 if( nResIdMessage == 0 )
622 return false;
624 ScopedVclPtr<WarningBox>::Create( this, WinBits( WB_OK ), SCH_RESSTR( nResIdMessage ) )->Execute();
625 if( pControl )
627 pControl->GrabFocus();
628 Edit* pEdit = dynamic_cast<Edit*>(pControl);
629 if(pEdit)
630 pEdit->SetSelection( Selection( 0, SELECTION_MAX ));
632 return true;
635 void ScaleTabPage::HideAllControls()
637 // We need to set these controls invisible when the class is instantiated
638 // since some code in EnableControls() depends on that logic. The real
639 // visibility of these controls depend on axis data type, and are
640 // set in EnableControls().
642 m_pBxType->Hide();
643 m_pCbxLogarithm->Hide();
644 m_pBxMinMax->Hide();
645 m_pTxtMain->Hide();
646 m_pFmtFldStepMain->Hide();
647 m_pMt_MainDateStep->Hide();
648 m_pLB_MainTimeUnit->Hide();
649 m_pCbxAutoStepMain->Hide();
650 m_pTxtHelpCount->Hide();
651 m_pTxtHelp->Hide();
652 m_pMtStepHelp->Hide();
653 m_pCbxAutoStepHelp->Hide();
654 m_pBxOrigin->Hide();
655 m_pBxResolution->Hide();
658 } //namespace chart
660 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */