Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_Scale.cxx
blobb785414e7a7f8d60982e4c348cd3578cd4a66865
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/weld.hxx>
33 #include <svl/zformat.hxx>
34 #include <svtools/controldims.hxx>
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(nullptr),
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, Edit&, rEdit, void )
163 FormattedField& rFmtField = static_cast<FormattedField&>(rEdit);
164 rFmtField.SetDefaultValue( rFmtField.GetValue() );
167 void ScaleTabPage::EnableControls()
169 bool bValueAxis = m_nAxisType == chart2::AxisType::REALNUMBER
170 || m_nAxisType == chart2::AxisType::PERCENT
171 || m_nAxisType == chart2::AxisType::DATE;
172 bool bDateAxis = m_nAxisType == chart2::AxisType::DATE;
174 m_pBxType->Show(m_bAllowDateAxis);
176 m_pCbxLogarithm->Show( bValueAxis && !bDateAxis );
178 m_pBxMinMax->Show(bValueAxis);
180 m_pTxtMain->Show( bValueAxis );
181 m_pCbxAutoStepMain->Show( bValueAxis );
183 m_pTxtHelpCount->Show( bValueAxis && !bDateAxis );
184 m_pTxtHelp->Show( bDateAxis );
185 m_pMtStepHelp->Show( bValueAxis );
186 m_pCbxAutoStepHelp->Show( bValueAxis );
188 m_pBxOrigin->Show( m_bShowAxisOrigin && bValueAxis );
189 m_pBxResolution->Show( bDateAxis );
191 bool bWasDateAxis = m_pMt_MainDateStep->IsVisible();
192 if( bWasDateAxis != bDateAxis )
194 //transport value from one to other control
195 if( bWasDateAxis )
196 lcl_setValue( *m_pFmtFldStepMain, m_pMt_MainDateStep->GetValue() );
197 else
198 m_pMt_MainDateStep->SetValue( static_cast<sal_Int32>(m_pFmtFldStepMain->GetValue()) );
201 m_pFmtFldStepMain->Show( bValueAxis && !bDateAxis );
202 m_pMt_MainDateStep->Show( bDateAxis );
204 m_pLB_MainTimeUnit->Show( bDateAxis );
205 m_pLB_HelpTimeUnit->Show( bDateAxis );
207 EnableValueHdl(m_pCbxAutoMin);
208 EnableValueHdl(m_pCbxAutoMax);
209 EnableValueHdl(m_pCbxAutoStepMain);
210 EnableValueHdl(m_pCbxAutoStepHelp);
211 EnableValueHdl(m_pCbxAutoOrigin);
212 EnableValueHdl(m_pCbx_AutoTimeResolution);
215 IMPL_LINK( ScaleTabPage, EnableValueHdl, Button *, pButton, void )
217 CheckBox * pCbx = static_cast<CheckBox*>(pButton);
218 bool bEnable = pCbx && !pCbx->IsChecked() && pCbx->IsEnabled();
219 if (pCbx == m_pCbxAutoMin)
221 m_pFmtFldMin->Enable( bEnable );
223 else if (pCbx == m_pCbxAutoMax)
225 m_pFmtFldMax->Enable( bEnable );
227 else if (pCbx == m_pCbxAutoStepMain)
229 m_pFmtFldStepMain->Enable( bEnable );
230 m_pMt_MainDateStep->Enable( bEnable );
231 m_pLB_MainTimeUnit->Enable( bEnable );
233 else if (pCbx == m_pCbxAutoStepHelp)
235 m_pMtStepHelp->Enable( bEnable );
236 m_pLB_HelpTimeUnit->Enable( bEnable );
238 else if (pCbx == m_pCbx_AutoTimeResolution)
240 m_pLB_TimeResolution->Enable( bEnable );
242 else if (pCbx == m_pCbxAutoOrigin)
244 m_pFmtFldOrigin->Enable( bEnable );
248 enum AxisTypeListBoxEntry
250 TYPE_AUTO=0,
251 TYPE_TEXT=1,
252 TYPE_DATE=2
255 IMPL_LINK_NOARG(ScaleTabPage, SelectAxisTypeHdl, ListBox&, void)
257 const sal_Int32 nPos = m_pLB_AxisType->GetSelectedEntryPos();
258 if( nPos==TYPE_DATE )
259 m_nAxisType = chart2::AxisType::DATE;
260 else
261 m_nAxisType = chart2::AxisType::CATEGORY;
262 if( m_nAxisType == chart2::AxisType::DATE )
263 m_pCbxLogarithm->Check(false);
264 EnableControls();
265 SetNumFormat();
268 VclPtr<SfxTabPage> ScaleTabPage::Create(TabPageParent pWindow,const SfxItemSet* rOutAttrs)
270 return VclPtr<ScaleTabPage>::Create(pWindow.pParent, *rOutAttrs);
273 bool ScaleTabPage::FillItemSet(SfxItemSet* rOutAttrs)
275 OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
277 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXISTYPE, m_nAxisType));
278 if(m_bAllowDateAxis)
279 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, m_pLB_AxisType->GetSelectedEntryPos()==TYPE_AUTO));
281 bool bAutoScale = false;
282 if( m_nAxisType==chart2::AxisType::CATEGORY )
283 bAutoScale = true;//reset scaling for category charts
285 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN ,bAutoScale || m_pCbxAutoMin->IsChecked()));
286 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX ,bAutoScale || m_pCbxAutoMax->IsChecked()));
287 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,bAutoScale || m_pCbxAutoStepHelp->IsChecked()));
288 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN ,bAutoScale || m_pCbxAutoOrigin->IsChecked()));
289 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM ,m_pCbxLogarithm->IsChecked()));
290 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_REVERSE ,m_pCbxReverse->IsChecked()));
291 rOutAttrs->Put(SvxDoubleItem(fMax , SCHATTR_AXIS_MAX));
292 rOutAttrs->Put(SvxDoubleItem(fMin , SCHATTR_AXIS_MIN));
293 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP, nStepHelp));
294 rOutAttrs->Put(SvxDoubleItem(fOrigin , SCHATTR_AXIS_ORIGIN));
296 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || m_pCbxAutoStepMain->IsChecked()));
297 rOutAttrs->Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN));
299 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,bAutoScale || m_pCbx_AutoTimeResolution->IsChecked()));
300 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION,m_nTimeResolution));
302 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,m_nMainTimeUnit));
303 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,m_nHelpTimeUnit));
305 return true;
308 void ScaleTabPage::Reset(const SfxItemSet* rInAttrs)
310 OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
311 if(!pNumFormatter)
312 return;
314 const SfxPoolItem *pPoolItem = nullptr;
315 if (rInAttrs->GetItemState(SCHATTR_AXIS_ALLOW_DATEAXIS, true, &pPoolItem) == SfxItemState::SET)
316 m_bAllowDateAxis = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
317 m_nAxisType=chart2::AxisType::REALNUMBER;
318 if (rInAttrs->GetItemState(SCHATTR_AXISTYPE, true, &pPoolItem) == SfxItemState::SET)
319 m_nAxisType = static_cast<int>(static_cast<const SfxInt32Item*>(pPoolItem)->GetValue());
320 if( m_nAxisType==chart2::AxisType::DATE && !m_bAllowDateAxis )
321 m_nAxisType=chart2::AxisType::CATEGORY;
322 if( m_bAllowDateAxis )
324 bool bAutoDateAxis = false;
325 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_DATEAXIS, true, &pPoolItem) == SfxItemState::SET)
326 bAutoDateAxis = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
328 sal_uInt16 nPos = 0;
329 if( m_nAxisType==chart2::AxisType::DATE )
330 nPos=TYPE_DATE;
331 else if( bAutoDateAxis )
332 nPos=TYPE_AUTO;
333 else
334 nPos=TYPE_TEXT;
335 m_pLB_AxisType->SelectEntryPos( nPos );
338 m_pCbxAutoMin->Check();
339 m_pCbxAutoMax->Check();
340 m_pCbxAutoStepMain->Check();
341 m_pCbxAutoStepHelp->Check();
342 m_pCbxAutoOrigin->Check();
343 m_pCbx_AutoTimeResolution->Check();
345 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_MIN,true,&pPoolItem) == SfxItemState::SET)
346 m_pCbxAutoMin->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
348 if (rInAttrs->GetItemState(SCHATTR_AXIS_MIN,true, &pPoolItem) == SfxItemState::SET)
350 fMin = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
351 lcl_setValue( *m_pFmtFldMin, fMin );
354 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_MAX,true, &pPoolItem) == SfxItemState::SET)
355 m_pCbxAutoMax->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
357 if (rInAttrs->GetItemState(SCHATTR_AXIS_MAX,true, &pPoolItem) == SfxItemState::SET)
359 fMax = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
360 lcl_setValue( *m_pFmtFldMax, fMax );
363 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN,true, &pPoolItem) == SfxItemState::SET)
364 m_pCbxAutoStepMain->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
366 if (rInAttrs->GetItemState(SCHATTR_AXIS_STEP_MAIN,true, &pPoolItem) == SfxItemState::SET)
368 fStepMain = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
369 lcl_setValue( *m_pFmtFldStepMain, fStepMain );
370 m_pMt_MainDateStep->SetValue( static_cast<sal_Int32>(fStepMain) );
372 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP,true, &pPoolItem) == SfxItemState::SET)
373 m_pCbxAutoStepHelp->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
374 if (rInAttrs->GetItemState(SCHATTR_AXIS_LOGARITHM,true, &pPoolItem) == SfxItemState::SET)
375 m_pCbxLogarithm->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
376 if (rInAttrs->GetItemState(SCHATTR_AXIS_REVERSE,true, &pPoolItem) == SfxItemState::SET)
377 m_pCbxReverse->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
378 if (rInAttrs->GetItemState(SCHATTR_AXIS_STEP_HELP,true, &pPoolItem) == SfxItemState::SET)
380 nStepHelp = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
381 m_pMtStepHelp->SetValue( nStepHelp );
383 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_ORIGIN,true, &pPoolItem) == SfxItemState::SET)
384 m_pCbxAutoOrigin->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
385 if (rInAttrs->GetItemState(SCHATTR_AXIS_ORIGIN,true, &pPoolItem) == SfxItemState::SET)
387 fOrigin = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
388 lcl_setValue( *m_pFmtFldOrigin, fOrigin );
391 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,true, &pPoolItem) == SfxItemState::SET)
392 m_pCbx_AutoTimeResolution->Check(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
393 if (rInAttrs->GetItemState(SCHATTR_AXIS_TIME_RESOLUTION,true, &pPoolItem) == SfxItemState::SET)
395 m_nTimeResolution = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
396 m_pLB_TimeResolution->SelectEntryPos( m_nTimeResolution );
399 if (rInAttrs->GetItemState(SCHATTR_AXIS_MAIN_TIME_UNIT,true, &pPoolItem) == SfxItemState::SET)
401 m_nMainTimeUnit = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
402 m_pLB_MainTimeUnit->SelectEntryPos( m_nMainTimeUnit );
404 if (rInAttrs->GetItemState(SCHATTR_AXIS_HELP_TIME_UNIT,true, &pPoolItem) == SfxItemState::SET)
406 m_nHelpTimeUnit = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
407 m_pLB_HelpTimeUnit->SelectEntryPos( m_nHelpTimeUnit );
410 EnableControls();
411 SetNumFormat();
414 DeactivateRC ScaleTabPage::DeactivatePage(SfxItemSet* pItemSet)
416 if( !pNumFormatter )
418 OSL_FAIL( "No NumberFormatter available" );
419 return DeactivateRC::LeavePage;
422 bool bDateAxis = m_nAxisType == chart2::AxisType::DATE;
424 sal_uInt32 nMinMaxOriginFmt = m_pFmtFldMax->GetFormatKey();
425 if (pNumFormatter->GetType(nMinMaxOriginFmt) == SvNumFormatType::TEXT)
426 nMinMaxOriginFmt = 0;
427 // numberformat_text cause numbers to fail being numbers... Shouldn't happen, but can.
428 sal_uInt32 nStepFmt = m_pFmtFldStepMain->GetFormatKey();
429 if (pNumFormatter->GetType(nStepFmt) == SvNumFormatType::TEXT)
430 nStepFmt = 0;
432 Control* pControl = nullptr;
433 const char* pErrStrId = nullptr;
434 double fDummy;
436 fMax = m_pFmtFldMax->GetValue();
437 fMin = m_pFmtFldMin->GetValue();
438 fOrigin = m_pFmtFldOrigin->GetValue();
439 fStepMain = bDateAxis ? m_pMt_MainDateStep->GetValue() : m_pFmtFldStepMain->GetValue();
440 nStepHelp = static_cast< sal_Int32 >( m_pMtStepHelp->GetValue());
441 m_nTimeResolution = m_pLB_TimeResolution->GetSelectedEntryPos();
442 m_nMainTimeUnit = m_pLB_MainTimeUnit->GetSelectedEntryPos();
443 m_nHelpTimeUnit = m_pLB_HelpTimeUnit->GetSelectedEntryPos();
445 if( m_nAxisType != chart2::AxisType::REALNUMBER )
446 m_pCbxLogarithm->Show( false );
448 //check which entries need user action
450 if ( m_pCbxLogarithm->IsChecked() &&
451 ( ( !m_pCbxAutoMin->IsChecked() && fMin <= 0.0 )
452 || ( !m_pCbxAutoMax->IsChecked() && fMax <= 0.0 ) ) )
454 pControl = m_pFmtFldMin;
455 pErrStrId = STR_BAD_LOGARITHM;
457 // check for entries that cannot be parsed for the current number format
458 else if ( m_pFmtFldMin->IsModified()
459 && !m_pCbxAutoMin->IsChecked()
460 && !pNumFormatter->IsNumberFormat( m_pFmtFldMin->GetText(), nMinMaxOriginFmt, fDummy))
462 pControl = m_pFmtFldMin;
463 pErrStrId = STR_INVALID_NUMBER;
465 else if ( m_pFmtFldMax->IsModified()
466 && !m_pCbxAutoMax->IsChecked()
467 && !pNumFormatter->IsNumberFormat( m_pFmtFldMax->GetText(), nMinMaxOriginFmt, fDummy))
469 pControl = m_pFmtFldMax;
470 pErrStrId = STR_INVALID_NUMBER;
472 else if ( !bDateAxis && m_pFmtFldStepMain->IsModified()
473 && !m_pCbxAutoStepMain->IsChecked()
474 && !pNumFormatter->IsNumberFormat( m_pFmtFldStepMain->GetText(), nStepFmt, fDummy))
476 pControl = m_pFmtFldStepMain;
477 pErrStrId = STR_INVALID_NUMBER;
479 else if (m_pFmtFldOrigin->IsModified() && !m_pCbxAutoOrigin->IsChecked() &&
480 !pNumFormatter->IsNumberFormat( m_pFmtFldOrigin->GetText(), nMinMaxOriginFmt, fDummy))
482 pControl = m_pFmtFldOrigin;
483 pErrStrId = STR_INVALID_NUMBER;
485 else if (!m_pCbxAutoStepMain->IsChecked() && fStepMain <= 0.0)
487 pControl = m_pFmtFldStepMain;
488 pErrStrId = STR_STEP_GT_ZERO;
490 else if (!m_pCbxAutoMax->IsChecked() && !m_pCbxAutoMin->IsChecked() &&
491 fMin >= fMax)
493 pControl = m_pFmtFldMin;
494 pErrStrId = STR_MIN_GREATER_MAX;
496 else if( bDateAxis )
498 if( !m_pCbxAutoStepMain->IsChecked() && !m_pCbxAutoStepHelp->IsChecked() )
500 if( m_nHelpTimeUnit > m_nMainTimeUnit )
502 pControl = m_pLB_MainTimeUnit;
503 pErrStrId = STR_INVALID_INTERVALS;
505 else if( m_nHelpTimeUnit == m_nMainTimeUnit && nStepHelp > fStepMain )
507 pControl = m_pLB_MainTimeUnit;
508 pErrStrId = STR_INVALID_INTERVALS;
511 if( !pErrStrId && !m_pCbx_AutoTimeResolution->IsChecked() )
513 if( (!m_pCbxAutoStepMain->IsChecked() && m_nTimeResolution > m_nMainTimeUnit )
515 (!m_pCbxAutoStepHelp->IsChecked() && m_nTimeResolution > m_nHelpTimeUnit )
518 pControl = m_pLB_TimeResolution;
519 pErrStrId = STR_INVALID_TIME_UNIT;
524 if( ShowWarning( pErrStrId, pControl ) )
525 return DeactivateRC::KeepPage;
527 if( pItemSet )
528 FillItemSet( pItemSet );
530 return DeactivateRC::LeavePage;
533 void ScaleTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
535 pNumFormatter = pFormatter;
536 m_pFmtFldMax->SetFormatter( pNumFormatter );
537 m_pFmtFldMin->SetFormatter( pNumFormatter );
538 m_pFmtFldStepMain->SetFormatter( pNumFormatter );
539 m_pFmtFldOrigin->SetFormatter( pNumFormatter );
541 // #i6278# allow more decimal places than the output format. As
542 // the numbers shown in the edit fields are used for input, it makes more
543 // sense to display the values in the input format rather than the output
544 // format.
545 m_pFmtFldMax->UseInputStringForFormatting();
546 m_pFmtFldMin->UseInputStringForFormatting();
547 m_pFmtFldStepMain->UseInputStringForFormatting();
548 m_pFmtFldOrigin->UseInputStringForFormatting();
550 SetNumFormat();
553 void ScaleTabPage::SetNumFormat()
555 const SfxPoolItem *pPoolItem = nullptr;
557 if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, true, &pPoolItem ) == SfxItemState::SET )
559 sal_uLong nFmt = static_cast<sal_uLong>(static_cast<const SfxInt32Item*>(pPoolItem)->GetValue());
561 m_pFmtFldMax->SetFormatKey( nFmt );
562 m_pFmtFldMin->SetFormatKey( nFmt );
563 m_pFmtFldOrigin->SetFormatKey( nFmt );
565 if( pNumFormatter )
567 SvNumFormatType eType = pNumFormatter->GetType( nFmt );
568 if( eType == SvNumFormatType::DATE )
570 // for intervals use standard format for dates (so you can enter a number of days)
571 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
572 if( pFormat )
573 nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage());
574 else
575 nFmt = pNumFormatter->GetStandardIndex();
577 else if( eType == SvNumFormatType::DATETIME )
579 // for intervals use time format for date times
580 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
581 if( pFormat )
582 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME, pFormat->GetLanguage() );
583 else
584 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME );
587 if( m_nAxisType == chart2::AxisType::DATE && ( eType != SvNumFormatType::DATE && eType != SvNumFormatType::DATETIME) )
589 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
590 if( pFormat )
591 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE, pFormat->GetLanguage() );
592 else
593 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE );
595 m_pFmtFldMax->SetFormatKey( nFmt );
596 m_pFmtFldMin->SetFormatKey( nFmt );
597 m_pFmtFldOrigin->SetFormatKey( nFmt );
601 m_pFmtFldStepMain->SetFormatKey( nFmt );
605 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin )
607 m_bShowAxisOrigin = bShowOrigin;
608 if( !AxisHelper::isAxisPositioningEnabled() )
609 m_bShowAxisOrigin = true;
612 bool ScaleTabPage::ShowWarning(const char* pResIdMessage, Control* pControl /* = NULL */ )
614 if (pResIdMessage == nullptr)
615 return false;
617 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(),
618 VclMessageType::Warning, VclButtonsType::Ok,
619 SchResId(pResIdMessage)));
620 xWarn->run();
621 if( pControl )
623 pControl->GrabFocus();
624 Edit* pEdit = dynamic_cast<Edit*>(pControl);
625 if(pEdit)
626 pEdit->SetSelection( Selection( 0, SELECTION_MAX ));
628 return true;
631 void ScaleTabPage::HideAllControls()
633 // We need to set these controls invisible when the class is instantiated
634 // since some code in EnableControls() depends on that logic. The real
635 // visibility of these controls depend on axis data type, and are
636 // set in EnableControls().
638 m_pBxType->Hide();
639 m_pCbxLogarithm->Hide();
640 m_pBxMinMax->Hide();
641 m_pTxtMain->Hide();
642 m_pFmtFldStepMain->Hide();
643 m_pMt_MainDateStep->Hide();
644 m_pLB_MainTimeUnit->Hide();
645 m_pCbxAutoStepMain->Hide();
646 m_pTxtHelpCount->Hide();
647 m_pTxtHelp->Hide();
648 m_pMtStepHelp->Hide();
649 m_pCbxAutoStepHelp->Hide();
650 m_pBxOrigin->Hide();
651 m_pBxResolution->Hide();
654 } //namespace chart
656 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */