1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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 <sfx2/dialoghelper.hxx>
30 #include <svx/chrtitem.hxx>
31 #include <svl/eitem.hxx>
32 #include <svl/intitem.hxx>
33 #include <svl/numformat.hxx>
34 #include <vcl/formatter.hxx>
35 #include <vcl/weld.hxx>
36 #include <svl/zformat.hxx>
37 #include <vcl/svapp.hxx>
39 #include <com/sun/star/chart2/AxisType.hpp>
41 using namespace ::com::sun::star
;
49 void lcl_setValue(weld::FormattedSpinButton
& rFmtField
, double fValue
)
51 rFmtField
.GetFormatter().SetValue(fValue
);
56 ScaleTabPage::ScaleTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rInAttrs
)
57 : SfxTabPage(pPage
, pController
, "modules/schart/ui/tp_Scale.ui", "tp_Scale", &rInAttrs
)
63 , m_nTimeResolution(1)
66 , m_nAxisType(chart2::AxisType::REALNUMBER
)
67 , m_bAllowDateAxis(false)
68 , pNumFormatter(nullptr)
69 , m_bShowAxisOrigin(false)
70 , m_xCbxReverse(m_xBuilder
->weld_check_button("CBX_REVERSE"))
71 , m_xCbxLogarithm(m_xBuilder
->weld_check_button("CBX_LOGARITHM"))
72 , m_xBxType(m_xBuilder
->weld_widget("boxTYPE"))
73 , m_xLB_AxisType(m_xBuilder
->weld_combo_box("LB_AXIS_TYPE"))
74 , m_xBxMinMax(m_xBuilder
->weld_widget("gridMINMAX"))
75 , m_xFmtFldMin(m_xBuilder
->weld_formatted_spin_button("EDT_MIN"))
76 , m_xCbxAutoMin(m_xBuilder
->weld_check_button("CBX_AUTO_MIN"))
77 , m_xFmtFldMax(m_xBuilder
->weld_formatted_spin_button("EDT_MAX"))
78 , m_xCbxAutoMax(m_xBuilder
->weld_check_button("CBX_AUTO_MAX"))
79 , m_xBxResolution(m_xBuilder
->weld_widget("boxRESOLUTION"))
80 , m_xLB_TimeResolution(m_xBuilder
->weld_combo_box("LB_TIME_RESOLUTION"))
81 , m_xCbx_AutoTimeResolution(m_xBuilder
->weld_check_button("CBX_AUTO_TIME_RESOLUTION"))
82 , m_xTxtMain(m_xBuilder
->weld_label("TXT_STEP_MAIN"))
83 , m_xFmtFldStepMain(m_xBuilder
->weld_formatted_spin_button("EDT_STEP_MAIN"))
84 , m_xMt_MainDateStep(m_xBuilder
->weld_spin_button("MT_MAIN_DATE_STEP"))
85 , m_xLB_MainTimeUnit(m_xBuilder
->weld_combo_box("LB_MAIN_TIME_UNIT"))
86 , m_xCbxAutoStepMain(m_xBuilder
->weld_check_button("CBX_AUTO_STEP_MAIN"))
87 , m_xTxtHelpCount(m_xBuilder
->weld_label("TXT_STEP_HELP_COUNT"))
88 , m_xTxtHelp(m_xBuilder
->weld_label("TXT_STEP_HELP"))
89 , m_xMtStepHelp(m_xBuilder
->weld_spin_button("MT_STEPHELP"))
90 , m_xLB_HelpTimeUnit(m_xBuilder
->weld_combo_box("LB_HELP_TIME_UNIT"))
91 , m_xCbxAutoStepHelp(m_xBuilder
->weld_check_button("CBX_AUTO_STEP_HELP"))
92 , m_xFmtFldOrigin(m_xBuilder
->weld_formatted_spin_button("EDT_ORIGIN"))
93 , m_xCbxAutoOrigin(m_xBuilder
->weld_check_button("CBX_AUTO_ORIGIN"))
94 , m_xBxOrigin(m_xBuilder
->weld_widget("boxORIGIN"))
96 m_xCbxAutoMin
->connect_toggled(LINK(this, ScaleTabPage
, EnableValueHdl
));
97 m_xCbxAutoMax
->connect_toggled(LINK(this, ScaleTabPage
, EnableValueHdl
));
98 m_xCbxAutoStepMain
->connect_toggled(LINK(this, ScaleTabPage
, EnableValueHdl
));
99 m_xCbxAutoStepHelp
->connect_toggled(LINK(this, ScaleTabPage
, EnableValueHdl
));
100 m_xCbxAutoOrigin
->connect_toggled(LINK(this, ScaleTabPage
, EnableValueHdl
));
101 m_xCbx_AutoTimeResolution
->connect_toggled(LINK(this, ScaleTabPage
, EnableValueHdl
));
103 Formatter
& rFmtFldMax
= m_xFmtFldMax
->GetFormatter();
104 rFmtFldMax
.ClearMinValue();
105 rFmtFldMax
.ClearMaxValue();
106 Formatter
& rFmtFldMin
= m_xFmtFldMin
->GetFormatter();
107 rFmtFldMin
.ClearMinValue();
108 rFmtFldMin
.ClearMaxValue();
109 Formatter
& rFmtFldStepMain
= m_xFmtFldStepMain
->GetFormatter();
110 rFmtFldStepMain
.ClearMinValue();
111 rFmtFldStepMain
.ClearMaxValue();
112 Formatter
& rFmtFldOrigin
= m_xFmtFldOrigin
->GetFormatter();
113 rFmtFldOrigin
.ClearMinValue();
114 rFmtFldOrigin
.ClearMaxValue();
116 m_xLB_AxisType
->connect_changed(LINK(this, ScaleTabPage
, SelectAxisTypeHdl
));
121 ScaleTabPage::~ScaleTabPage()
125 void ScaleTabPage::EnableControls()
127 bool bValueAxis
= m_nAxisType
== chart2::AxisType::REALNUMBER
128 || m_nAxisType
== chart2::AxisType::PERCENT
129 || m_nAxisType
== chart2::AxisType::DATE
;
130 bool bDateAxis
= m_nAxisType
== chart2::AxisType::DATE
;
132 m_xBxType
->set_visible(m_bAllowDateAxis
);
134 m_xCbxLogarithm
->set_visible( bValueAxis
&& !bDateAxis
);
136 m_xBxMinMax
->set_visible(bValueAxis
);
138 m_xTxtMain
->set_visible( bValueAxis
);
139 m_xCbxAutoStepMain
->set_visible( bValueAxis
);
141 m_xTxtHelpCount
->set_visible( bValueAxis
&& !bDateAxis
);
142 m_xTxtHelp
->set_visible( bDateAxis
);
143 m_xMtStepHelp
->set_visible( bValueAxis
);
144 m_xCbxAutoStepHelp
->set_visible( bValueAxis
);
146 m_xBxOrigin
->set_visible( m_bShowAxisOrigin
&& bValueAxis
);
147 m_xBxResolution
->set_visible( bDateAxis
);
149 bool bWasDateAxis
= m_xMt_MainDateStep
->get_visible();
150 if( bWasDateAxis
!= bDateAxis
)
152 //transport value from one to other control
154 lcl_setValue( *m_xFmtFldStepMain
, m_xMt_MainDateStep
->get_value() );
156 m_xMt_MainDateStep
->set_value(m_xFmtFldStepMain
->GetFormatter().GetValue());
159 m_xFmtFldStepMain
->set_visible( bValueAxis
&& !bDateAxis
);
160 m_xMt_MainDateStep
->set_visible( bDateAxis
);
162 m_xLB_MainTimeUnit
->set_visible( bDateAxis
);
163 m_xLB_HelpTimeUnit
->set_visible( bDateAxis
);
165 EnableValueHdl(*m_xCbxAutoMin
);
166 EnableValueHdl(*m_xCbxAutoMax
);
167 EnableValueHdl(*m_xCbxAutoStepMain
);
168 EnableValueHdl(*m_xCbxAutoStepHelp
);
169 EnableValueHdl(*m_xCbxAutoOrigin
);
170 EnableValueHdl(*m_xCbx_AutoTimeResolution
);
173 IMPL_LINK( ScaleTabPage
, EnableValueHdl
, weld::Toggleable
&, rCbx
, void )
175 bool bEnable
= !rCbx
.get_active() && rCbx
.get_sensitive();
176 if (&rCbx
== m_xCbxAutoMin
.get())
178 m_xFmtFldMin
->set_sensitive( bEnable
);
180 else if (&rCbx
== m_xCbxAutoMax
.get())
182 m_xFmtFldMax
->set_sensitive( bEnable
);
184 else if (&rCbx
== m_xCbxAutoStepMain
.get())
186 m_xFmtFldStepMain
->set_sensitive( bEnable
);
187 m_xMt_MainDateStep
->set_sensitive( bEnable
);
188 m_xLB_MainTimeUnit
->set_sensitive( bEnable
);
190 else if (&rCbx
== m_xCbxAutoStepHelp
.get())
192 m_xMtStepHelp
->set_sensitive( bEnable
);
193 m_xLB_HelpTimeUnit
->set_sensitive( bEnable
);
195 else if (&rCbx
== m_xCbx_AutoTimeResolution
.get())
197 m_xLB_TimeResolution
->set_sensitive( bEnable
);
199 else if (&rCbx
== m_xCbxAutoOrigin
.get())
201 m_xFmtFldOrigin
->set_sensitive( bEnable
);
207 enum AxisTypeListBoxEntry
216 IMPL_LINK_NOARG(ScaleTabPage
, SelectAxisTypeHdl
, weld::ComboBox
&, void)
218 const sal_Int32 nPos
= m_xLB_AxisType
->get_active();
219 if( nPos
==TYPE_DATE
)
220 m_nAxisType
= chart2::AxisType::DATE
;
222 m_nAxisType
= chart2::AxisType::CATEGORY
;
223 if( m_nAxisType
== chart2::AxisType::DATE
)
224 m_xCbxLogarithm
->set_active(false);
229 std::unique_ptr
<SfxTabPage
> ScaleTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rOutAttrs
)
231 return std::make_unique
<ScaleTabPage
>(pPage
, pController
, *rOutAttrs
);
234 bool ScaleTabPage::FillItemSet(SfxItemSet
* rOutAttrs
)
236 OSL_PRECOND( pNumFormatter
, "No NumberFormatter available" );
238 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXISTYPE
, m_nAxisType
));
240 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS
, m_xLB_AxisType
->get_active()==TYPE_AUTO
));
242 bool bAutoScale
= false;
243 if( m_nAxisType
==chart2::AxisType::CATEGORY
)
244 bAutoScale
= true;//reset scaling for category charts
246 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN
,bAutoScale
|| m_xCbxAutoMin
->get_active()));
247 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX
,bAutoScale
|| m_xCbxAutoMax
->get_active()));
248 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP
,bAutoScale
|| m_xCbxAutoStepHelp
->get_active()));
249 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN
,bAutoScale
|| m_xCbxAutoOrigin
->get_active()));
250 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM
,m_xCbxLogarithm
->get_active()));
251 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_REVERSE
,m_xCbxReverse
->get_active()));
252 rOutAttrs
->Put(SvxDoubleItem(fMax
, SCHATTR_AXIS_MAX
));
253 rOutAttrs
->Put(SvxDoubleItem(fMin
, SCHATTR_AXIS_MIN
));
254 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP
, nStepHelp
));
255 rOutAttrs
->Put(SvxDoubleItem(fOrigin
, SCHATTR_AXIS_ORIGIN
));
257 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN
,bAutoScale
|| m_xCbxAutoStepMain
->get_active()));
258 rOutAttrs
->Put(SvxDoubleItem(fStepMain
,SCHATTR_AXIS_STEP_MAIN
));
260 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION
,bAutoScale
|| m_xCbx_AutoTimeResolution
->get_active()));
261 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION
,m_nTimeResolution
));
263 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT
,m_nMainTimeUnit
));
264 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT
,m_nHelpTimeUnit
));
269 void ScaleTabPage::Reset(const SfxItemSet
* rInAttrs
)
271 OSL_PRECOND( pNumFormatter
, "No NumberFormatter available" );
275 const SfxPoolItem
*pPoolItem
= nullptr;
276 if (rInAttrs
->GetItemState(SCHATTR_AXIS_ALLOW_DATEAXIS
, true, &pPoolItem
) == SfxItemState::SET
)
277 m_bAllowDateAxis
= static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue();
278 m_nAxisType
=chart2::AxisType::REALNUMBER
;
279 if (rInAttrs
->GetItemState(SCHATTR_AXISTYPE
, true, &pPoolItem
) == SfxItemState::SET
)
280 m_nAxisType
= static_cast<int>(static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue());
281 if( m_nAxisType
==chart2::AxisType::DATE
&& !m_bAllowDateAxis
)
282 m_nAxisType
=chart2::AxisType::CATEGORY
;
283 if( m_bAllowDateAxis
)
285 bool bAutoDateAxis
= false;
286 if (rInAttrs
->GetItemState(SCHATTR_AXIS_AUTO_DATEAXIS
, true, &pPoolItem
) == SfxItemState::SET
)
287 bAutoDateAxis
= static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue();
290 if( m_nAxisType
==chart2::AxisType::DATE
)
292 else if( bAutoDateAxis
)
296 m_xLB_AxisType
->set_active( nPos
);
299 m_xCbxAutoMin
->set_active(true);
300 m_xCbxAutoMax
->set_active(true);
301 m_xCbxAutoStepMain
->set_active(true);
302 m_xCbxAutoStepHelp
->set_active(true);
303 m_xCbxAutoOrigin
->set_active(true);
304 m_xCbx_AutoTimeResolution
->set_active(true);
306 if (rInAttrs
->GetItemState(SCHATTR_AXIS_AUTO_MIN
,true,&pPoolItem
) == SfxItemState::SET
)
307 m_xCbxAutoMin
->set_active(static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue());
309 if (rInAttrs
->GetItemState(SCHATTR_AXIS_MIN
,true, &pPoolItem
) == SfxItemState::SET
)
311 fMin
= static_cast<const SvxDoubleItem
*>(pPoolItem
)->GetValue();
312 lcl_setValue( *m_xFmtFldMin
, fMin
);
313 m_xFmtFldMin
->save_value();
316 if (rInAttrs
->GetItemState(SCHATTR_AXIS_AUTO_MAX
,true, &pPoolItem
) == SfxItemState::SET
)
317 m_xCbxAutoMax
->set_active(static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue());
319 if (rInAttrs
->GetItemState(SCHATTR_AXIS_MAX
,true, &pPoolItem
) == SfxItemState::SET
)
321 fMax
= static_cast<const SvxDoubleItem
*>(pPoolItem
)->GetValue();
322 lcl_setValue( *m_xFmtFldMax
, fMax
);
323 m_xFmtFldMax
->save_value();
326 if (rInAttrs
->GetItemState(SCHATTR_AXIS_AUTO_STEP_MAIN
,true, &pPoolItem
) == SfxItemState::SET
)
327 m_xCbxAutoStepMain
->set_active(static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue());
329 if (rInAttrs
->GetItemState(SCHATTR_AXIS_STEP_MAIN
,true, &pPoolItem
) == SfxItemState::SET
)
331 fStepMain
= static_cast<const SvxDoubleItem
*>(pPoolItem
)->GetValue();
332 lcl_setValue( *m_xFmtFldStepMain
, fStepMain
);
333 m_xFmtFldStepMain
->save_value();
334 m_xMt_MainDateStep
->set_value( static_cast<sal_Int32
>(fStepMain
) );
335 m_xMt_MainDateStep
->save_value();
337 if (rInAttrs
->GetItemState(SCHATTR_AXIS_AUTO_STEP_HELP
,true, &pPoolItem
) == SfxItemState::SET
)
338 m_xCbxAutoStepHelp
->set_active(static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue());
339 if (rInAttrs
->GetItemState(SCHATTR_AXIS_LOGARITHM
,true, &pPoolItem
) == SfxItemState::SET
)
340 m_xCbxLogarithm
->set_active(static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue());
341 if (rInAttrs
->GetItemState(SCHATTR_AXIS_REVERSE
,true, &pPoolItem
) == SfxItemState::SET
)
342 m_xCbxReverse
->set_active(static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue());
343 if (rInAttrs
->GetItemState(SCHATTR_AXIS_STEP_HELP
,true, &pPoolItem
) == SfxItemState::SET
)
345 nStepHelp
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
346 m_xMtStepHelp
->set_value( nStepHelp
);
347 m_xMtStepHelp
->save_value();
349 if (rInAttrs
->GetItemState(SCHATTR_AXIS_AUTO_ORIGIN
,true, &pPoolItem
) == SfxItemState::SET
)
350 m_xCbxAutoOrigin
->set_active(static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue());
351 if (rInAttrs
->GetItemState(SCHATTR_AXIS_ORIGIN
,true, &pPoolItem
) == SfxItemState::SET
)
353 fOrigin
= static_cast<const SvxDoubleItem
*>(pPoolItem
)->GetValue();
354 lcl_setValue( *m_xFmtFldOrigin
, fOrigin
);
355 m_xFmtFldOrigin
->save_value();
358 if (rInAttrs
->GetItemState(SCHATTR_AXIS_AUTO_TIME_RESOLUTION
,true, &pPoolItem
) == SfxItemState::SET
)
359 m_xCbx_AutoTimeResolution
->set_active(static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue());
360 if (rInAttrs
->GetItemState(SCHATTR_AXIS_TIME_RESOLUTION
,true, &pPoolItem
) == SfxItemState::SET
)
362 m_nTimeResolution
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
363 m_xLB_TimeResolution
->set_active( m_nTimeResolution
);
366 if (rInAttrs
->GetItemState(SCHATTR_AXIS_MAIN_TIME_UNIT
,true, &pPoolItem
) == SfxItemState::SET
)
368 m_nMainTimeUnit
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
369 m_xLB_MainTimeUnit
->set_active( m_nMainTimeUnit
);
371 if (rInAttrs
->GetItemState(SCHATTR_AXIS_HELP_TIME_UNIT
,true, &pPoolItem
) == SfxItemState::SET
)
373 m_nHelpTimeUnit
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
374 m_xLB_HelpTimeUnit
->set_active( m_nHelpTimeUnit
);
381 DeactivateRC
ScaleTabPage::DeactivatePage(SfxItemSet
* pItemSet
)
385 OSL_FAIL( "No NumberFormatter available" );
386 return DeactivateRC::LeavePage
;
389 bool bDateAxis
= m_nAxisType
== chart2::AxisType::DATE
;
391 sal_uInt32 nMinMaxOriginFmt
= m_xFmtFldMax
->GetFormatter().GetFormatKey();
392 if (pNumFormatter
->GetType(nMinMaxOriginFmt
) == SvNumFormatType::TEXT
)
393 nMinMaxOriginFmt
= 0;
394 // numberformat_text cause numbers to fail being numbers... Shouldn't happen, but can.
395 sal_uInt32 nStepFmt
= m_xFmtFldStepMain
->GetFormatter().GetFormatKey();
396 if (pNumFormatter
->GetType(nStepFmt
) == SvNumFormatType::TEXT
)
399 weld::Widget
* pControl
= nullptr;
400 TranslateId pErrStrId
;
403 fMax
= m_xFmtFldMax
->GetFormatter().GetValue();
404 fMin
= m_xFmtFldMin
->GetFormatter().GetValue();
405 fOrigin
= m_xFmtFldOrigin
->GetFormatter().GetValue();
406 fStepMain
= bDateAxis
? m_xMt_MainDateStep
->get_value() : m_xFmtFldStepMain
->GetFormatter().GetValue();
407 nStepHelp
= m_xMtStepHelp
->get_value();
408 m_nTimeResolution
= m_xLB_TimeResolution
->get_active();
409 m_nMainTimeUnit
= m_xLB_MainTimeUnit
->get_active();
410 m_nHelpTimeUnit
= m_xLB_HelpTimeUnit
->get_active();
412 if( m_nAxisType
!= chart2::AxisType::REALNUMBER
)
413 m_xCbxLogarithm
->hide();
415 //check which entries need user action
417 if ( m_xCbxLogarithm
->get_active() &&
418 ( ( !m_xCbxAutoMin
->get_active() && fMin
<= 0.0 )
419 || ( !m_xCbxAutoMax
->get_active() && fMax
<= 0.0 ) ) )
421 pControl
= m_xFmtFldMin
.get();
422 pErrStrId
= STR_BAD_LOGARITHM
;
424 // check for entries that cannot be parsed for the current number format
425 else if ( m_xFmtFldMin
->get_value_changed_from_saved()
426 && !m_xCbxAutoMin
->get_active()
427 && !pNumFormatter
->IsNumberFormat( m_xFmtFldMin
->get_text(), nMinMaxOriginFmt
, fDummy
))
429 pControl
= m_xFmtFldMin
.get();
430 pErrStrId
= STR_INVALID_NUMBER
;
432 else if ( m_xFmtFldMax
->get_value_changed_from_saved()
433 && !m_xCbxAutoMax
->get_active()
434 && !pNumFormatter
->IsNumberFormat( m_xFmtFldMax
->get_text(), nMinMaxOriginFmt
, fDummy
))
436 pControl
= m_xFmtFldMax
.get();
437 pErrStrId
= STR_INVALID_NUMBER
;
439 else if ( !bDateAxis
&& m_xFmtFldStepMain
->get_value_changed_from_saved()
440 && !m_xCbxAutoStepMain
->get_active()
441 && !pNumFormatter
->IsNumberFormat( m_xFmtFldStepMain
->get_text(), nStepFmt
, fDummy
))
443 pControl
= m_xFmtFldStepMain
.get();
444 pErrStrId
= STR_INVALID_NUMBER
;
446 else if (m_xFmtFldOrigin
->get_value_changed_from_saved() && !m_xCbxAutoOrigin
->get_active() &&
447 !pNumFormatter
->IsNumberFormat( m_xFmtFldOrigin
->get_text(), nMinMaxOriginFmt
, fDummy
))
449 pControl
= m_xFmtFldOrigin
.get();
450 pErrStrId
= STR_INVALID_NUMBER
;
452 else if (!m_xCbxAutoStepMain
->get_active() && fStepMain
<= 0.0)
454 pControl
= m_xFmtFldStepMain
.get();
455 pErrStrId
= STR_STEP_GT_ZERO
;
457 else if (!m_xCbxAutoMax
->get_active() && !m_xCbxAutoMin
->get_active() &&
460 pControl
= m_xFmtFldMin
.get();
461 pErrStrId
= STR_MIN_GREATER_MAX
;
465 if( !m_xCbxAutoStepMain
->get_active() && !m_xCbxAutoStepHelp
->get_active() )
467 if( m_nHelpTimeUnit
> m_nMainTimeUnit
)
469 pControl
= m_xLB_MainTimeUnit
.get();
470 pErrStrId
= STR_INVALID_INTERVALS
;
472 else if( m_nHelpTimeUnit
== m_nMainTimeUnit
&& nStepHelp
> fStepMain
)
474 pControl
= m_xLB_MainTimeUnit
.get();
475 pErrStrId
= STR_INVALID_INTERVALS
;
478 if( !pErrStrId
&& !m_xCbx_AutoTimeResolution
->get_active() )
480 if( (!m_xCbxAutoStepMain
->get_active() && m_nTimeResolution
> m_nMainTimeUnit
)
482 (!m_xCbxAutoStepHelp
->get_active() && m_nTimeResolution
> m_nHelpTimeUnit
)
485 pControl
= m_xLB_TimeResolution
.get();
486 pErrStrId
= STR_INVALID_TIME_UNIT
;
491 if( ShowWarning( pErrStrId
, pControl
) )
492 return DeactivateRC::KeepPage
;
495 FillItemSet( pItemSet
);
497 return DeactivateRC::LeavePage
;
500 void ScaleTabPage::SetNumFormatter( SvNumberFormatter
* pFormatter
)
502 pNumFormatter
= pFormatter
;
504 Formatter
& rFmtFldMax
= m_xFmtFldMax
->GetFormatter();
505 Formatter
& rFmtFldMin
= m_xFmtFldMin
->GetFormatter();
506 Formatter
& rFmtFldStepMain
= m_xFmtFldStepMain
->GetFormatter();
507 Formatter
& rFmtFldOrigin
= m_xFmtFldOrigin
->GetFormatter();
509 rFmtFldMax
.SetFormatter( pNumFormatter
);
510 rFmtFldMin
.SetFormatter( pNumFormatter
);
511 rFmtFldStepMain
.SetFormatter( pNumFormatter
);
512 rFmtFldOrigin
.SetFormatter( pNumFormatter
);
514 // #i6278# allow more decimal places than the output format. As
515 // the numbers shown in the edit fields are used for input, it makes more
516 // sense to display the values in the input format rather than the output
518 rFmtFldMax
.UseInputStringForFormatting();
519 rFmtFldMin
.UseInputStringForFormatting();
520 rFmtFldStepMain
.UseInputStringForFormatting();
521 rFmtFldOrigin
.UseInputStringForFormatting();
526 void ScaleTabPage::SetNumFormat()
528 const SfxPoolItem
*pPoolItem
= nullptr;
530 if( GetItemSet().GetItemState( SID_ATTR_NUMBERFORMAT_VALUE
, true, &pPoolItem
) != SfxItemState::SET
)
533 sal_uLong nFmt
= static_cast<const SfxUInt32Item
*>(pPoolItem
)->GetValue();
535 Formatter
& rFmtFldMax
= m_xFmtFldMax
->GetFormatter();
536 rFmtFldMax
.SetFormatKey(nFmt
);
537 Formatter
& rFmtFldMin
= m_xFmtFldMin
->GetFormatter();
538 rFmtFldMin
.SetFormatKey(nFmt
);
539 Formatter
& rFmtFldOrigin
= m_xFmtFldOrigin
->GetFormatter();
540 rFmtFldOrigin
.SetFormatKey(nFmt
);
544 SvNumFormatType eType
= pNumFormatter
->GetType( nFmt
);
545 if( eType
== SvNumFormatType::DATE
)
547 // for intervals use standard format for dates (so you can enter a number of days)
548 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
550 nFmt
= pNumFormatter
->GetStandardIndex( pFormat
->GetLanguage());
552 nFmt
= pNumFormatter
->GetStandardIndex();
554 else if( eType
== SvNumFormatType::DATETIME
)
556 // for intervals use time format for date times
557 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
559 nFmt
= pNumFormatter
->GetStandardFormat( SvNumFormatType::TIME
, pFormat
->GetLanguage() );
561 nFmt
= pNumFormatter
->GetStandardFormat( SvNumFormatType::TIME
);
563 // tdf#141625 give enough space to see full date+time
564 int nWidestTime(m_xFmtFldMin
->get_pixel_size(getWidestDateTime(Application::GetSettings().GetLocaleDataWrapper(), true)).Width());
565 int nWidthChars
= std::ceil(nWidestTime
/ m_xFmtFldMin
->get_approximate_digit_width()) + 1;
566 m_xFmtFldMin
->set_width_chars(nWidthChars
);
567 m_xFmtFldMax
->set_width_chars(nWidthChars
);
570 if( m_nAxisType
== chart2::AxisType::DATE
&& ( eType
!= SvNumFormatType::DATE
&& eType
!= SvNumFormatType::DATETIME
) )
572 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
574 nFmt
= pNumFormatter
->GetStandardFormat( SvNumFormatType::DATE
, pFormat
->GetLanguage() );
576 nFmt
= pNumFormatter
->GetStandardFormat( SvNumFormatType::DATE
);
578 rFmtFldMax
.SetFormatKey(nFmt
);
579 rFmtFldMin
.SetFormatKey(nFmt
);
580 rFmtFldOrigin
.SetFormatKey(nFmt
);
584 m_xFmtFldStepMain
->GetFormatter().SetFormatKey(nFmt
);
587 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin
)
589 m_bShowAxisOrigin
= bShowOrigin
;
590 if( !AxisHelper::isAxisPositioningEnabled() )
591 m_bShowAxisOrigin
= true;
594 bool ScaleTabPage::ShowWarning(TranslateId pResIdMessage
, weld::Widget
* pControl
/* = nullptr */)
599 std::unique_ptr
<weld::MessageDialog
> xWarn(Application::CreateMessageDialog(GetFrameWeld(),
600 VclMessageType::Warning
, VclButtonsType::Ok
,
601 SchResId(pResIdMessage
)));
605 pControl
->grab_focus();
606 weld::Entry
* pEdit
= dynamic_cast<weld::Entry
*>(pControl
);
608 pEdit
->select_region(0, -1);
613 void ScaleTabPage::HideAllControls()
615 // We need to set these controls invisible when the class is instantiated
616 // since some code in EnableControls() depends on that logic. The real
617 // visibility of these controls depend on axis data type, and are
618 // set in EnableControls().
621 m_xCbxLogarithm
->hide();
624 m_xFmtFldStepMain
->hide();
625 m_xMt_MainDateStep
->hide();
626 m_xLB_MainTimeUnit
->hide();
627 m_xCbxAutoStepMain
->hide();
628 m_xTxtHelpCount
->hide();
630 m_xMtStepHelp
->hide();
631 m_xCbxAutoStepHelp
->hide();
633 m_xBxResolution
->hide();
638 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */