Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_Scale.cxx
blobfccdf87c900f7ced168fd38adfe90a894271b6dc
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 <osl/diagnose.h>
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 <vcl/svapp.hxx>
36 #include <com/sun/star/chart2/AxisType.hpp>
38 using namespace ::com::sun::star;
40 namespace chart
43 namespace
46 void lcl_setValue(weld::FormattedSpinButton& rFmtField, double fValue)
48 rFmtField.set_value(fValue);
53 ScaleTabPage::ScaleTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs)
54 : SfxTabPage(pPage, pController, "modules/schart/ui/tp_Scale.ui", "tp_Scale", &rInAttrs)
55 , fMin(0.0)
56 , fMax(0.0)
57 , fStepMain(0.0)
58 , nStepHelp(0)
59 , fOrigin(0.0)
60 , m_nTimeResolution(1)
61 , m_nMainTimeUnit(1)
62 , m_nHelpTimeUnit(1)
63 , m_nAxisType(chart2::AxisType::REALNUMBER)
64 , m_bAllowDateAxis(false)
65 , pNumFormatter(nullptr)
66 , m_bShowAxisOrigin(false)
67 , m_xCbxReverse(m_xBuilder->weld_check_button("CBX_REVERSE"))
68 , m_xCbxLogarithm(m_xBuilder->weld_check_button("CBX_LOGARITHM"))
69 , m_xBxType(m_xBuilder->weld_widget("boxTYPE"))
70 , m_xLB_AxisType(m_xBuilder->weld_combo_box("LB_AXIS_TYPE"))
71 , m_xBxMinMax(m_xBuilder->weld_widget("gridMINMAX"))
72 , m_xFmtFldMin(m_xBuilder->weld_formatted_spin_button("EDT_MIN"))
73 , m_xCbxAutoMin(m_xBuilder->weld_check_button("CBX_AUTO_MIN"))
74 , m_xFmtFldMax(m_xBuilder->weld_formatted_spin_button("EDT_MAX"))
75 , m_xCbxAutoMax(m_xBuilder->weld_check_button("CBX_AUTO_MAX"))
76 , m_xBxResolution(m_xBuilder->weld_widget("boxRESOLUTION"))
77 , m_xLB_TimeResolution(m_xBuilder->weld_combo_box("LB_TIME_RESOLUTION"))
78 , m_xCbx_AutoTimeResolution(m_xBuilder->weld_check_button("CBX_AUTO_TIME_RESOLUTION"))
79 , m_xTxtMain(m_xBuilder->weld_label("TXT_STEP_MAIN"))
80 , m_xFmtFldStepMain(m_xBuilder->weld_formatted_spin_button("EDT_STEP_MAIN"))
81 , m_xMt_MainDateStep(m_xBuilder->weld_spin_button("MT_MAIN_DATE_STEP"))
82 , m_xLB_MainTimeUnit(m_xBuilder->weld_combo_box("LB_MAIN_TIME_UNIT"))
83 , m_xCbxAutoStepMain(m_xBuilder->weld_check_button("CBX_AUTO_STEP_MAIN"))
84 , m_xTxtHelpCount(m_xBuilder->weld_label("TXT_STEP_HELP_COUNT"))
85 , m_xTxtHelp(m_xBuilder->weld_label("TXT_STEP_HELP"))
86 , m_xMtStepHelp(m_xBuilder->weld_spin_button("MT_STEPHELP"))
87 , m_xLB_HelpTimeUnit(m_xBuilder->weld_combo_box("LB_HELP_TIME_UNIT"))
88 , m_xCbxAutoStepHelp(m_xBuilder->weld_check_button("CBX_AUTO_STEP_HELP"))
89 , m_xFmtFldOrigin(m_xBuilder->weld_formatted_spin_button("EDT_ORIGIN"))
90 , m_xCbxAutoOrigin(m_xBuilder->weld_check_button("CBX_AUTO_ORIGIN"))
91 , m_xBxOrigin(m_xBuilder->weld_widget("boxORIGIN"))
93 m_xCbxAutoMin->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
94 m_xCbxAutoMax->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
95 m_xCbxAutoStepMain->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
96 m_xCbxAutoStepHelp->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
97 m_xCbxAutoOrigin->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
98 m_xCbx_AutoTimeResolution->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl));
100 const double nMin = static_cast<double>(SAL_MIN_INT64);
101 const double nMax = static_cast<double>(SAL_MAX_INT64);
102 m_xFmtFldMin->set_range(nMin, nMax);
103 m_xFmtFldMax->set_range(nMin, nMax);
104 m_xFmtFldStepMain->set_range(nMin, nMax);
105 m_xFmtFldOrigin->set_range(nMin, nMax);
107 m_xLB_AxisType->connect_changed(LINK(this, ScaleTabPage, SelectAxisTypeHdl));
109 HideAllControls();
112 ScaleTabPage::~ScaleTabPage()
116 void ScaleTabPage::EnableControls()
118 bool bValueAxis = m_nAxisType == chart2::AxisType::REALNUMBER
119 || m_nAxisType == chart2::AxisType::PERCENT
120 || m_nAxisType == chart2::AxisType::DATE;
121 bool bDateAxis = m_nAxisType == chart2::AxisType::DATE;
123 m_xBxType->set_visible(m_bAllowDateAxis);
125 m_xCbxLogarithm->set_visible( bValueAxis && !bDateAxis );
127 m_xBxMinMax->set_visible(bValueAxis);
129 m_xTxtMain->set_visible( bValueAxis );
130 m_xCbxAutoStepMain->set_visible( bValueAxis );
132 m_xTxtHelpCount->set_visible( bValueAxis && !bDateAxis );
133 m_xTxtHelp->set_visible( bDateAxis );
134 m_xMtStepHelp->set_visible( bValueAxis );
135 m_xCbxAutoStepHelp->set_visible( bValueAxis );
137 m_xBxOrigin->set_visible( m_bShowAxisOrigin && bValueAxis );
138 m_xBxResolution->set_visible( bDateAxis );
140 bool bWasDateAxis = m_xMt_MainDateStep->get_visible();
141 if( bWasDateAxis != bDateAxis )
143 //transport value from one to other control
144 if( bWasDateAxis )
145 lcl_setValue( *m_xFmtFldStepMain, m_xMt_MainDateStep->get_value() );
146 else
147 m_xMt_MainDateStep->set_value(m_xFmtFldStepMain->get_value());
150 m_xFmtFldStepMain->set_visible( bValueAxis && !bDateAxis );
151 m_xMt_MainDateStep->set_visible( bDateAxis );
153 m_xLB_MainTimeUnit->set_visible( bDateAxis );
154 m_xLB_HelpTimeUnit->set_visible( bDateAxis );
156 EnableValueHdl(*m_xCbxAutoMin);
157 EnableValueHdl(*m_xCbxAutoMax);
158 EnableValueHdl(*m_xCbxAutoStepMain);
159 EnableValueHdl(*m_xCbxAutoStepHelp);
160 EnableValueHdl(*m_xCbxAutoOrigin);
161 EnableValueHdl(*m_xCbx_AutoTimeResolution);
164 IMPL_LINK( ScaleTabPage, EnableValueHdl, weld::ToggleButton&, rCbx, void )
166 bool bEnable = !rCbx.get_active() && rCbx.get_sensitive();
167 if (&rCbx == m_xCbxAutoMin.get())
169 m_xFmtFldMin->set_sensitive( bEnable );
171 else if (&rCbx == m_xCbxAutoMax.get())
173 m_xFmtFldMax->set_sensitive( bEnable );
175 else if (&rCbx == m_xCbxAutoStepMain.get())
177 m_xFmtFldStepMain->set_sensitive( bEnable );
178 m_xMt_MainDateStep->set_sensitive( bEnable );
179 m_xLB_MainTimeUnit->set_sensitive( bEnable );
181 else if (&rCbx == m_xCbxAutoStepHelp.get())
183 m_xMtStepHelp->set_sensitive( bEnable );
184 m_xLB_HelpTimeUnit->set_sensitive( bEnable );
186 else if (&rCbx == m_xCbx_AutoTimeResolution.get())
188 m_xLB_TimeResolution->set_sensitive( bEnable );
190 else if (&rCbx == m_xCbxAutoOrigin.get())
192 m_xFmtFldOrigin->set_sensitive( bEnable );
196 enum AxisTypeListBoxEntry
198 TYPE_AUTO=0,
199 TYPE_TEXT=1,
200 TYPE_DATE=2
203 IMPL_LINK_NOARG(ScaleTabPage, SelectAxisTypeHdl, weld::ComboBox&, void)
205 const sal_Int32 nPos = m_xLB_AxisType->get_active();
206 if( nPos==TYPE_DATE )
207 m_nAxisType = chart2::AxisType::DATE;
208 else
209 m_nAxisType = chart2::AxisType::CATEGORY;
210 if( m_nAxisType == chart2::AxisType::DATE )
211 m_xCbxLogarithm->set_active(false);
212 EnableControls();
213 SetNumFormat();
216 std::unique_ptr<SfxTabPage> ScaleTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs)
218 return std::make_unique<ScaleTabPage>(pPage, pController, *rOutAttrs);
221 bool ScaleTabPage::FillItemSet(SfxItemSet* rOutAttrs)
223 OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
225 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXISTYPE, m_nAxisType));
226 if(m_bAllowDateAxis)
227 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, m_xLB_AxisType->get_active()==TYPE_AUTO));
229 bool bAutoScale = false;
230 if( m_nAxisType==chart2::AxisType::CATEGORY )
231 bAutoScale = true;//reset scaling for category charts
233 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN ,bAutoScale || m_xCbxAutoMin->get_active()));
234 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX ,bAutoScale || m_xCbxAutoMax->get_active()));
235 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,bAutoScale || m_xCbxAutoStepHelp->get_active()));
236 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN ,bAutoScale || m_xCbxAutoOrigin->get_active()));
237 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM ,m_xCbxLogarithm->get_active()));
238 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_REVERSE ,m_xCbxReverse->get_active()));
239 rOutAttrs->Put(SvxDoubleItem(fMax , SCHATTR_AXIS_MAX));
240 rOutAttrs->Put(SvxDoubleItem(fMin , SCHATTR_AXIS_MIN));
241 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP, nStepHelp));
242 rOutAttrs->Put(SvxDoubleItem(fOrigin , SCHATTR_AXIS_ORIGIN));
244 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || m_xCbxAutoStepMain->get_active()));
245 rOutAttrs->Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN));
247 rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,bAutoScale || m_xCbx_AutoTimeResolution->get_active()));
248 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION,m_nTimeResolution));
250 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,m_nMainTimeUnit));
251 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,m_nHelpTimeUnit));
253 return true;
256 void ScaleTabPage::Reset(const SfxItemSet* rInAttrs)
258 OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
259 if(!pNumFormatter)
260 return;
262 const SfxPoolItem *pPoolItem = nullptr;
263 if (rInAttrs->GetItemState(SCHATTR_AXIS_ALLOW_DATEAXIS, true, &pPoolItem) == SfxItemState::SET)
264 m_bAllowDateAxis = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
265 m_nAxisType=chart2::AxisType::REALNUMBER;
266 if (rInAttrs->GetItemState(SCHATTR_AXISTYPE, true, &pPoolItem) == SfxItemState::SET)
267 m_nAxisType = static_cast<int>(static_cast<const SfxInt32Item*>(pPoolItem)->GetValue());
268 if( m_nAxisType==chart2::AxisType::DATE && !m_bAllowDateAxis )
269 m_nAxisType=chart2::AxisType::CATEGORY;
270 if( m_bAllowDateAxis )
272 bool bAutoDateAxis = false;
273 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_DATEAXIS, true, &pPoolItem) == SfxItemState::SET)
274 bAutoDateAxis = static_cast<const SfxBoolItem*>(pPoolItem)->GetValue();
276 sal_uInt16 nPos = 0;
277 if( m_nAxisType==chart2::AxisType::DATE )
278 nPos=TYPE_DATE;
279 else if( bAutoDateAxis )
280 nPos=TYPE_AUTO;
281 else
282 nPos=TYPE_TEXT;
283 m_xLB_AxisType->set_active( nPos );
286 m_xCbxAutoMin->set_active(true);
287 m_xCbxAutoMax->set_active(true);
288 m_xCbxAutoStepMain->set_active(true);
289 m_xCbxAutoStepHelp->set_active(true);
290 m_xCbxAutoOrigin->set_active(true);
291 m_xCbx_AutoTimeResolution->set_active(true);
293 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_MIN,true,&pPoolItem) == SfxItemState::SET)
294 m_xCbxAutoMin->set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
296 if (rInAttrs->GetItemState(SCHATTR_AXIS_MIN,true, &pPoolItem) == SfxItemState::SET)
298 fMin = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
299 lcl_setValue( *m_xFmtFldMin, fMin );
300 m_xFmtFldMin->save_value();
303 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_MAX,true, &pPoolItem) == SfxItemState::SET)
304 m_xCbxAutoMax->set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
306 if (rInAttrs->GetItemState(SCHATTR_AXIS_MAX,true, &pPoolItem) == SfxItemState::SET)
308 fMax = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
309 lcl_setValue( *m_xFmtFldMax, fMax );
310 m_xFmtFldMax->save_value();
313 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN,true, &pPoolItem) == SfxItemState::SET)
314 m_xCbxAutoStepMain->set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
316 if (rInAttrs->GetItemState(SCHATTR_AXIS_STEP_MAIN,true, &pPoolItem) == SfxItemState::SET)
318 fStepMain = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
319 lcl_setValue( *m_xFmtFldStepMain, fStepMain );
320 m_xFmtFldStepMain->save_value();
321 m_xMt_MainDateStep->set_value( static_cast<sal_Int32>(fStepMain) );
322 m_xMt_MainDateStep->save_value();
324 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP,true, &pPoolItem) == SfxItemState::SET)
325 m_xCbxAutoStepHelp->set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
326 if (rInAttrs->GetItemState(SCHATTR_AXIS_LOGARITHM,true, &pPoolItem) == SfxItemState::SET)
327 m_xCbxLogarithm->set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
328 if (rInAttrs->GetItemState(SCHATTR_AXIS_REVERSE,true, &pPoolItem) == SfxItemState::SET)
329 m_xCbxReverse->set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
330 if (rInAttrs->GetItemState(SCHATTR_AXIS_STEP_HELP,true, &pPoolItem) == SfxItemState::SET)
332 nStepHelp = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
333 m_xMtStepHelp->set_value( nStepHelp );
334 m_xMtStepHelp->save_value();
336 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_ORIGIN,true, &pPoolItem) == SfxItemState::SET)
337 m_xCbxAutoOrigin->set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
338 if (rInAttrs->GetItemState(SCHATTR_AXIS_ORIGIN,true, &pPoolItem) == SfxItemState::SET)
340 fOrigin = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
341 lcl_setValue( *m_xFmtFldOrigin, fOrigin );
342 m_xFmtFldOrigin->save_value();
345 if (rInAttrs->GetItemState(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,true, &pPoolItem) == SfxItemState::SET)
346 m_xCbx_AutoTimeResolution->set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
347 if (rInAttrs->GetItemState(SCHATTR_AXIS_TIME_RESOLUTION,true, &pPoolItem) == SfxItemState::SET)
349 m_nTimeResolution = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
350 m_xLB_TimeResolution->set_active( m_nTimeResolution );
353 if (rInAttrs->GetItemState(SCHATTR_AXIS_MAIN_TIME_UNIT,true, &pPoolItem) == SfxItemState::SET)
355 m_nMainTimeUnit = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
356 m_xLB_MainTimeUnit->set_active( m_nMainTimeUnit );
358 if (rInAttrs->GetItemState(SCHATTR_AXIS_HELP_TIME_UNIT,true, &pPoolItem) == SfxItemState::SET)
360 m_nHelpTimeUnit = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
361 m_xLB_HelpTimeUnit->set_active( m_nHelpTimeUnit );
364 EnableControls();
365 SetNumFormat();
368 DeactivateRC ScaleTabPage::DeactivatePage(SfxItemSet* pItemSet)
370 if( !pNumFormatter )
372 OSL_FAIL( "No NumberFormatter available" );
373 return DeactivateRC::LeavePage;
376 bool bDateAxis = m_nAxisType == chart2::AxisType::DATE;
378 sal_uInt32 nMinMaxOriginFmt = m_xFmtFldMax->get_format_key();
379 if (pNumFormatter->GetType(nMinMaxOriginFmt) == SvNumFormatType::TEXT)
380 nMinMaxOriginFmt = 0;
381 // numberformat_text cause numbers to fail being numbers... Shouldn't happen, but can.
382 sal_uInt32 nStepFmt = m_xFmtFldStepMain->get_format_key();
383 if (pNumFormatter->GetType(nStepFmt) == SvNumFormatType::TEXT)
384 nStepFmt = 0;
386 weld::Widget* pControl = nullptr;
387 const char* pErrStrId = nullptr;
388 double fDummy;
390 fMax = m_xFmtFldMax->get_value();
391 fMin = m_xFmtFldMin->get_value();
392 fOrigin = m_xFmtFldOrigin->get_value();
393 fStepMain = bDateAxis ? m_xMt_MainDateStep->get_value() : m_xFmtFldStepMain->get_value();
394 nStepHelp = m_xMtStepHelp->get_value();
395 m_nTimeResolution = m_xLB_TimeResolution->get_active();
396 m_nMainTimeUnit = m_xLB_MainTimeUnit->get_active();
397 m_nHelpTimeUnit = m_xLB_HelpTimeUnit->get_active();
399 if( m_nAxisType != chart2::AxisType::REALNUMBER )
400 m_xCbxLogarithm->hide();
402 //check which entries need user action
404 if ( m_xCbxLogarithm->get_active() &&
405 ( ( !m_xCbxAutoMin->get_active() && fMin <= 0.0 )
406 || ( !m_xCbxAutoMax->get_active() && fMax <= 0.0 ) ) )
408 pControl = m_xFmtFldMin.get();
409 pErrStrId = STR_BAD_LOGARITHM;
411 // check for entries that cannot be parsed for the current number format
412 else if ( m_xFmtFldMin->get_value_changed_from_saved()
413 && !m_xCbxAutoMin->get_active()
414 && !pNumFormatter->IsNumberFormat( m_xFmtFldMin->get_text(), nMinMaxOriginFmt, fDummy))
416 pControl = m_xFmtFldMin.get();
417 pErrStrId = STR_INVALID_NUMBER;
419 else if ( m_xFmtFldMax->get_value_changed_from_saved()
420 && !m_xCbxAutoMax->get_active()
421 && !pNumFormatter->IsNumberFormat( m_xFmtFldMax->get_text(), nMinMaxOriginFmt, fDummy))
423 pControl = m_xFmtFldMax.get();
424 pErrStrId = STR_INVALID_NUMBER;
426 else if ( !bDateAxis && m_xFmtFldStepMain->get_value_changed_from_saved()
427 && !m_xCbxAutoStepMain->get_active()
428 && !pNumFormatter->IsNumberFormat( m_xFmtFldStepMain->get_text(), nStepFmt, fDummy))
430 pControl = m_xFmtFldStepMain.get();
431 pErrStrId = STR_INVALID_NUMBER;
433 else if (m_xFmtFldOrigin->get_value_changed_from_saved() && !m_xCbxAutoOrigin->get_active() &&
434 !pNumFormatter->IsNumberFormat( m_xFmtFldOrigin->get_text(), nMinMaxOriginFmt, fDummy))
436 pControl = m_xFmtFldOrigin.get();
437 pErrStrId = STR_INVALID_NUMBER;
439 else if (!m_xCbxAutoStepMain->get_active() && fStepMain <= 0.0)
441 pControl = m_xFmtFldStepMain.get();
442 pErrStrId = STR_STEP_GT_ZERO;
444 else if (!m_xCbxAutoMax->get_active() && !m_xCbxAutoMin->get_active() &&
445 fMin >= fMax)
447 pControl = m_xFmtFldMin.get();
448 pErrStrId = STR_MIN_GREATER_MAX;
450 else if( bDateAxis )
452 if( !m_xCbxAutoStepMain->get_active() && !m_xCbxAutoStepHelp->get_active() )
454 if( m_nHelpTimeUnit > m_nMainTimeUnit )
456 pControl = m_xLB_MainTimeUnit.get();
457 pErrStrId = STR_INVALID_INTERVALS;
459 else if( m_nHelpTimeUnit == m_nMainTimeUnit && nStepHelp > fStepMain )
461 pControl = m_xLB_MainTimeUnit.get();
462 pErrStrId = STR_INVALID_INTERVALS;
465 if( !pErrStrId && !m_xCbx_AutoTimeResolution->get_active() )
467 if( (!m_xCbxAutoStepMain->get_active() && m_nTimeResolution > m_nMainTimeUnit )
469 (!m_xCbxAutoStepHelp->get_active() && m_nTimeResolution > m_nHelpTimeUnit )
472 pControl = m_xLB_TimeResolution.get();
473 pErrStrId = STR_INVALID_TIME_UNIT;
478 if( ShowWarning( pErrStrId, pControl ) )
479 return DeactivateRC::KeepPage;
481 if( pItemSet )
482 FillItemSet( pItemSet );
484 return DeactivateRC::LeavePage;
487 void ScaleTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
489 pNumFormatter = pFormatter;
490 m_xFmtFldMax->set_formatter( pNumFormatter );
491 m_xFmtFldMin->set_formatter( pNumFormatter );
492 m_xFmtFldStepMain->set_formatter( pNumFormatter );
493 m_xFmtFldOrigin->set_formatter( pNumFormatter );
494 SetNumFormat();
497 void ScaleTabPage::SetNumFormat()
499 const SfxPoolItem *pPoolItem = nullptr;
501 if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE, true, &pPoolItem ) == SfxItemState::SET )
503 sal_uLong nFmt = static_cast<const SfxUInt32Item*>(pPoolItem)->GetValue();
505 m_xFmtFldMax->set_format_key(nFmt);
506 m_xFmtFldMin->set_format_key(nFmt);
507 m_xFmtFldOrigin->set_format_key(nFmt);
509 if( pNumFormatter )
511 SvNumFormatType eType = pNumFormatter->GetType( nFmt );
512 if( eType == SvNumFormatType::DATE )
514 // for intervals use standard format for dates (so you can enter a number of days)
515 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
516 if( pFormat )
517 nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage());
518 else
519 nFmt = pNumFormatter->GetStandardIndex();
521 else if( eType == SvNumFormatType::DATETIME )
523 // for intervals use time format for date times
524 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
525 if( pFormat )
526 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME, pFormat->GetLanguage() );
527 else
528 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME );
531 if( m_nAxisType == chart2::AxisType::DATE && ( eType != SvNumFormatType::DATE && eType != SvNumFormatType::DATETIME) )
533 const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
534 if( pFormat )
535 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE, pFormat->GetLanguage() );
536 else
537 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE );
539 m_xFmtFldMax->set_format_key(nFmt);
540 m_xFmtFldMin->set_format_key(nFmt);
541 m_xFmtFldOrigin->set_format_key(nFmt);
545 m_xFmtFldStepMain->set_format_key(nFmt);
549 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin )
551 m_bShowAxisOrigin = bShowOrigin;
552 if( !AxisHelper::isAxisPositioningEnabled() )
553 m_bShowAxisOrigin = true;
556 bool ScaleTabPage::ShowWarning(const char* pResIdMessage, weld::Widget* pControl /* = nullptr */)
558 if (pResIdMessage == nullptr)
559 return false;
561 std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(),
562 VclMessageType::Warning, VclButtonsType::Ok,
563 SchResId(pResIdMessage)));
564 xWarn->run();
565 if (pControl)
567 pControl->grab_focus();
568 weld::Entry* pEdit = dynamic_cast<weld::Entry*>(pControl);
569 if (pEdit)
570 pEdit->select_region(0, -1);
572 return true;
575 void ScaleTabPage::HideAllControls()
577 // We need to set these controls invisible when the class is instantiated
578 // since some code in EnableControls() depends on that logic. The real
579 // visibility of these controls depend on axis data type, and are
580 // set in EnableControls().
582 m_xBxType->hide();
583 m_xCbxLogarithm->hide();
584 m_xBxMinMax->hide();
585 m_xTxtMain->hide();
586 m_xFmtFldStepMain->hide();
587 m_xMt_MainDateStep->hide();
588 m_xLB_MainTimeUnit->hide();
589 m_xCbxAutoStepMain->hide();
590 m_xTxtHelpCount->hide();
591 m_xTxtHelp->hide();
592 m_xMtStepHelp->hide();
593 m_xCbxAutoStepHelp->hide();
594 m_xBxOrigin->hide();
595 m_xBxResolution->hide();
598 } //namespace chart
600 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */