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
, u
"modules/schart/ui/tp_Scale.ui"_ustr
, u
"tp_Scale"_ustr
, &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(u
"CBX_REVERSE"_ustr
))
71 , m_xCbxLogarithm(m_xBuilder
->weld_check_button(u
"CBX_LOGARITHM"_ustr
))
72 , m_xBxType(m_xBuilder
->weld_widget(u
"boxTYPE"_ustr
))
73 , m_xLB_AxisType(m_xBuilder
->weld_combo_box(u
"LB_AXIS_TYPE"_ustr
))
74 , m_xBxMinMax(m_xBuilder
->weld_widget(u
"gridMINMAX"_ustr
))
75 , m_xFmtFldMin(m_xBuilder
->weld_formatted_spin_button(u
"EDT_MIN"_ustr
))
76 , m_xCbxAutoMin(m_xBuilder
->weld_check_button(u
"CBX_AUTO_MIN"_ustr
))
77 , m_xFmtFldMax(m_xBuilder
->weld_formatted_spin_button(u
"EDT_MAX"_ustr
))
78 , m_xCbxAutoMax(m_xBuilder
->weld_check_button(u
"CBX_AUTO_MAX"_ustr
))
79 , m_xBxResolution(m_xBuilder
->weld_widget(u
"boxRESOLUTION"_ustr
))
80 , m_xLB_TimeResolution(m_xBuilder
->weld_combo_box(u
"LB_TIME_RESOLUTION"_ustr
))
81 , m_xCbx_AutoTimeResolution(m_xBuilder
->weld_check_button(u
"CBX_AUTO_TIME_RESOLUTION"_ustr
))
82 , m_xTxtMain(m_xBuilder
->weld_label(u
"TXT_STEP_MAIN"_ustr
))
83 , m_xFmtFldStepMain(m_xBuilder
->weld_formatted_spin_button(u
"EDT_STEP_MAIN"_ustr
))
84 , m_xMt_MainDateStep(m_xBuilder
->weld_spin_button(u
"MT_MAIN_DATE_STEP"_ustr
))
85 , m_xLB_MainTimeUnit(m_xBuilder
->weld_combo_box(u
"LB_MAIN_TIME_UNIT"_ustr
))
86 , m_xCbxAutoStepMain(m_xBuilder
->weld_check_button(u
"CBX_AUTO_STEP_MAIN"_ustr
))
87 , m_xTxtHelpCount(m_xBuilder
->weld_label(u
"TXT_STEP_HELP_COUNT"_ustr
))
88 , m_xTxtHelp(m_xBuilder
->weld_label(u
"TXT_STEP_HELP"_ustr
))
89 , m_xMtStepHelp(m_xBuilder
->weld_spin_button(u
"MT_STEPHELP"_ustr
))
90 , m_xLB_HelpTimeUnit(m_xBuilder
->weld_combo_box(u
"LB_HELP_TIME_UNIT"_ustr
))
91 , m_xCbxAutoStepHelp(m_xBuilder
->weld_check_button(u
"CBX_AUTO_STEP_HELP"_ustr
))
92 , m_xFmtFldOrigin(m_xBuilder
->weld_formatted_spin_button(u
"EDT_ORIGIN"_ustr
))
93 , m_xCbxAutoOrigin(m_xBuilder
->weld_check_button(u
"CBX_AUTO_ORIGIN"_ustr
))
94 , m_xBxOrigin(m_xBuilder
->weld_widget(u
"boxORIGIN"_ustr
))
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 if (const SfxBoolItem
* pDateAxisItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_ALLOW_DATEAXIS
))
276 m_bAllowDateAxis
= pDateAxisItem
->GetValue();
277 m_nAxisType
=chart2::AxisType::REALNUMBER
;
278 if (const SfxInt32Item
* pAxisTypeItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXISTYPE
))
279 m_nAxisType
= static_cast<int>(pAxisTypeItem
->GetValue());
280 if( m_nAxisType
==chart2::AxisType::DATE
&& !m_bAllowDateAxis
)
281 m_nAxisType
=chart2::AxisType::CATEGORY
;
282 if( m_bAllowDateAxis
)
284 bool bAutoDateAxis
= false;
285 if (const SfxBoolItem
* pDateAxisItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_AUTO_DATEAXIS
))
286 bAutoDateAxis
= pDateAxisItem
->GetValue();
289 if( m_nAxisType
==chart2::AxisType::DATE
)
291 else if( bAutoDateAxis
)
295 m_xLB_AxisType
->set_active( nPos
);
298 m_xCbxAutoMin
->set_active(true);
299 m_xCbxAutoMax
->set_active(true);
300 m_xCbxAutoStepMain
->set_active(true);
301 m_xCbxAutoStepHelp
->set_active(true);
302 m_xCbxAutoOrigin
->set_active(true);
303 m_xCbx_AutoTimeResolution
->set_active(true);
305 if (const SfxBoolItem
* pAutoMinItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_AUTO_MIN
))
306 m_xCbxAutoMin
->set_active(pAutoMinItem
->GetValue());
308 if (const SvxDoubleItem
* pAxisMinItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_MIN
))
310 fMin
= pAxisMinItem
->GetValue();
311 lcl_setValue( *m_xFmtFldMin
, fMin
);
312 m_xFmtFldMin
->save_value();
315 if (const SfxBoolItem
* pAutoMaxItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_AUTO_MAX
))
316 m_xCbxAutoMax
->set_active(pAutoMaxItem
->GetValue());
318 if (const SvxDoubleItem
* pAxisMaxItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_MAX
))
320 fMax
= pAxisMaxItem
->GetValue();
321 lcl_setValue( *m_xFmtFldMax
, fMax
);
322 m_xFmtFldMax
->save_value();
325 if (const SfxBoolItem
* pAutoStepMainItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_AUTO_STEP_MAIN
))
326 m_xCbxAutoStepMain
->set_active(pAutoStepMainItem
->GetValue());
328 if (const SvxDoubleItem
* pStepMainItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_STEP_MAIN
))
330 fStepMain
= pStepMainItem
->GetValue();
331 lcl_setValue( *m_xFmtFldStepMain
, fStepMain
);
332 m_xFmtFldStepMain
->save_value();
333 m_xMt_MainDateStep
->set_value( static_cast<sal_Int32
>(fStepMain
) );
334 m_xMt_MainDateStep
->save_value();
336 if (const SfxBoolItem
* pAutoStepHelpItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_AUTO_STEP_HELP
))
337 m_xCbxAutoStepHelp
->set_active(pAutoStepHelpItem
->GetValue());
338 if (const SfxBoolItem
* pLogItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_LOGARITHM
))
339 m_xCbxLogarithm
->set_active(pLogItem
->GetValue());
340 if (const SfxBoolItem
* pReverseItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_REVERSE
))
341 m_xCbxReverse
->set_active(pReverseItem
->GetValue());
342 if (const SfxInt32Item
* pStepHelpItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_STEP_HELP
))
344 nStepHelp
= pStepHelpItem
->GetValue();
345 m_xMtStepHelp
->set_value( nStepHelp
);
346 m_xMtStepHelp
->save_value();
348 if (const SfxBoolItem
* pOriginItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_AUTO_ORIGIN
))
349 m_xCbxAutoOrigin
->set_active(pOriginItem
->GetValue());
350 if (const SvxDoubleItem
* pOriginItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_ORIGIN
))
352 fOrigin
= pOriginItem
->GetValue();
353 lcl_setValue( *m_xFmtFldOrigin
, fOrigin
);
354 m_xFmtFldOrigin
->save_value();
357 if (const SfxBoolItem
* pAutoTimeResItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_AUTO_TIME_RESOLUTION
))
358 m_xCbx_AutoTimeResolution
->set_active(pAutoTimeResItem
->GetValue());
359 if (const SfxInt32Item
* pTimeResItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_TIME_RESOLUTION
))
361 m_nTimeResolution
= pTimeResItem
->GetValue();
362 m_xLB_TimeResolution
->set_active( m_nTimeResolution
);
365 if (const SfxInt32Item
* pMainTimeUnitItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_MAIN_TIME_UNIT
))
367 m_nMainTimeUnit
= pMainTimeUnitItem
->GetValue();
368 m_xLB_MainTimeUnit
->set_active( m_nMainTimeUnit
);
370 if (const SfxInt32Item
* pHelpTimeUnitItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_HELP_TIME_UNIT
))
372 m_nHelpTimeUnit
= pHelpTimeUnitItem
->GetValue();
373 m_xLB_HelpTimeUnit
->set_active( m_nHelpTimeUnit
);
380 DeactivateRC
ScaleTabPage::DeactivatePage(SfxItemSet
* pItemSet
)
384 OSL_FAIL( "No NumberFormatter available" );
385 return DeactivateRC::LeavePage
;
388 bool bDateAxis
= m_nAxisType
== chart2::AxisType::DATE
;
390 sal_uInt32 nMinMaxOriginFmt
= m_xFmtFldMax
->GetFormatter().GetFormatKey();
391 if (pNumFormatter
->GetType(nMinMaxOriginFmt
) == SvNumFormatType::TEXT
)
392 nMinMaxOriginFmt
= 0;
393 // numberformat_text cause numbers to fail being numbers... Shouldn't happen, but can.
394 sal_uInt32 nStepFmt
= m_xFmtFldStepMain
->GetFormatter().GetFormatKey();
395 if (pNumFormatter
->GetType(nStepFmt
) == SvNumFormatType::TEXT
)
398 weld::Widget
* pControl
= nullptr;
399 TranslateId pErrStrId
;
402 fMax
= m_xFmtFldMax
->GetFormatter().GetValue();
403 fMin
= m_xFmtFldMin
->GetFormatter().GetValue();
404 fOrigin
= m_xFmtFldOrigin
->GetFormatter().GetValue();
405 fStepMain
= bDateAxis
? m_xMt_MainDateStep
->get_value() : m_xFmtFldStepMain
->GetFormatter().GetValue();
406 nStepHelp
= m_xMtStepHelp
->get_value();
407 m_nTimeResolution
= m_xLB_TimeResolution
->get_active();
408 m_nMainTimeUnit
= m_xLB_MainTimeUnit
->get_active();
409 m_nHelpTimeUnit
= m_xLB_HelpTimeUnit
->get_active();
411 if( m_nAxisType
!= chart2::AxisType::REALNUMBER
)
412 m_xCbxLogarithm
->hide();
414 //check which entries need user action
416 if ( m_xCbxLogarithm
->get_active() &&
417 ( ( !m_xCbxAutoMin
->get_active() && fMin
<= 0.0 )
418 || ( !m_xCbxAutoMax
->get_active() && fMax
<= 0.0 ) ) )
420 pControl
= m_xFmtFldMin
.get();
421 pErrStrId
= STR_BAD_LOGARITHM
;
423 // check for entries that cannot be parsed for the current number format
424 else if ( m_xFmtFldMin
->get_value_changed_from_saved()
425 && !m_xCbxAutoMin
->get_active()
426 && !pNumFormatter
->IsNumberFormat( m_xFmtFldMin
->get_text(), nMinMaxOriginFmt
, fDummy
))
428 pControl
= m_xFmtFldMin
.get();
429 pErrStrId
= STR_INVALID_NUMBER
;
431 else if ( m_xFmtFldMax
->get_value_changed_from_saved()
432 && !m_xCbxAutoMax
->get_active()
433 && !pNumFormatter
->IsNumberFormat( m_xFmtFldMax
->get_text(), nMinMaxOriginFmt
, fDummy
))
435 pControl
= m_xFmtFldMax
.get();
436 pErrStrId
= STR_INVALID_NUMBER
;
438 else if ( !bDateAxis
&& m_xFmtFldStepMain
->get_value_changed_from_saved()
439 && !m_xCbxAutoStepMain
->get_active()
440 && !pNumFormatter
->IsNumberFormat( m_xFmtFldStepMain
->get_text(), nStepFmt
, fDummy
))
442 pControl
= m_xFmtFldStepMain
.get();
443 pErrStrId
= STR_INVALID_NUMBER
;
445 else if (m_xFmtFldOrigin
->get_value_changed_from_saved() && !m_xCbxAutoOrigin
->get_active() &&
446 !pNumFormatter
->IsNumberFormat( m_xFmtFldOrigin
->get_text(), nMinMaxOriginFmt
, fDummy
))
448 pControl
= m_xFmtFldOrigin
.get();
449 pErrStrId
= STR_INVALID_NUMBER
;
451 else if (!m_xCbxAutoStepMain
->get_active() && fStepMain
<= 0.0)
453 pControl
= m_xFmtFldStepMain
.get();
454 pErrStrId
= STR_STEP_GT_ZERO
;
456 else if (!m_xCbxAutoMax
->get_active() && !m_xCbxAutoMin
->get_active() &&
459 pControl
= m_xFmtFldMin
.get();
460 pErrStrId
= STR_MIN_GREATER_MAX
;
464 if( !m_xCbxAutoStepMain
->get_active() && !m_xCbxAutoStepHelp
->get_active() )
466 if( m_nHelpTimeUnit
> m_nMainTimeUnit
)
468 pControl
= m_xLB_MainTimeUnit
.get();
469 pErrStrId
= STR_INVALID_INTERVALS
;
471 else if( m_nHelpTimeUnit
== m_nMainTimeUnit
&& nStepHelp
> fStepMain
)
473 pControl
= m_xLB_MainTimeUnit
.get();
474 pErrStrId
= STR_INVALID_INTERVALS
;
477 if( !pErrStrId
&& !m_xCbx_AutoTimeResolution
->get_active() )
479 if( (!m_xCbxAutoStepMain
->get_active() && m_nTimeResolution
> m_nMainTimeUnit
)
481 (!m_xCbxAutoStepHelp
->get_active() && m_nTimeResolution
> m_nHelpTimeUnit
)
484 pControl
= m_xLB_TimeResolution
.get();
485 pErrStrId
= STR_INVALID_TIME_UNIT
;
490 if( ShowWarning( pErrStrId
, pControl
) )
491 return DeactivateRC::KeepPage
;
494 FillItemSet( pItemSet
);
496 return DeactivateRC::LeavePage
;
499 void ScaleTabPage::SetNumFormatter( SvNumberFormatter
* pFormatter
)
501 pNumFormatter
= pFormatter
;
503 Formatter
& rFmtFldMax
= m_xFmtFldMax
->GetFormatter();
504 Formatter
& rFmtFldMin
= m_xFmtFldMin
->GetFormatter();
505 Formatter
& rFmtFldStepMain
= m_xFmtFldStepMain
->GetFormatter();
506 Formatter
& rFmtFldOrigin
= m_xFmtFldOrigin
->GetFormatter();
508 rFmtFldMax
.SetFormatter( pNumFormatter
);
509 rFmtFldMin
.SetFormatter( pNumFormatter
);
510 rFmtFldStepMain
.SetFormatter( pNumFormatter
);
511 rFmtFldOrigin
.SetFormatter( pNumFormatter
);
513 // #i6278# allow more decimal places than the output format. As
514 // the numbers shown in the edit fields are used for input, it makes more
515 // sense to display the values in the input format rather than the output
517 rFmtFldMax
.UseInputStringForFormatting();
518 rFmtFldMin
.UseInputStringForFormatting();
519 rFmtFldStepMain
.UseInputStringForFormatting();
520 rFmtFldOrigin
.UseInputStringForFormatting();
525 void ScaleTabPage::SetNumFormat()
527 const SfxUInt32Item
*pNumFormatItem
= GetItemSet().GetItemIfSet( SID_ATTR_NUMBERFORMAT_VALUE
);
529 if( !pNumFormatItem
)
532 sal_uInt32 nFmt
= pNumFormatItem
->GetValue();
534 Formatter
& rFmtFldMax
= m_xFmtFldMax
->GetFormatter();
535 rFmtFldMax
.SetFormatKey(nFmt
);
536 Formatter
& rFmtFldMin
= m_xFmtFldMin
->GetFormatter();
537 rFmtFldMin
.SetFormatKey(nFmt
);
538 Formatter
& rFmtFldOrigin
= m_xFmtFldOrigin
->GetFormatter();
539 rFmtFldOrigin
.SetFormatKey(nFmt
);
543 SvNumFormatType eType
= pNumFormatter
->GetType( nFmt
);
544 if( eType
== SvNumFormatType::DATE
)
546 // for intervals use standard format for dates (so you can enter a number of days)
547 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
549 nFmt
= pNumFormatter
->GetStandardIndex( pFormat
->GetLanguage());
551 nFmt
= pNumFormatter
->GetStandardIndex();
553 else if( eType
== SvNumFormatType::DATETIME
)
555 // for intervals use time format for date times
556 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
558 nFmt
= pNumFormatter
->GetStandardFormat( SvNumFormatType::TIME
, pFormat
->GetLanguage() );
560 nFmt
= pNumFormatter
->GetStandardFormat( SvNumFormatType::TIME
);
562 // tdf#141625 give enough space to see full date+time
563 int nWidestTime(m_xFmtFldMin
->get_pixel_size(getWidestDateTime(Application::GetSettings().GetLocaleDataWrapper(), true)).Width());
564 int nWidthChars
= std::ceil(nWidestTime
/ m_xFmtFldMin
->get_approximate_digit_width()) + 1;
565 m_xFmtFldMin
->set_width_chars(nWidthChars
);
566 m_xFmtFldMax
->set_width_chars(nWidthChars
);
569 if( m_nAxisType
== chart2::AxisType::DATE
&& ( eType
!= SvNumFormatType::DATE
&& eType
!= SvNumFormatType::DATETIME
) )
571 const SvNumberformat
* pFormat
= pNumFormatter
->GetEntry( nFmt
);
573 nFmt
= pNumFormatter
->GetStandardFormat( SvNumFormatType::DATE
, pFormat
->GetLanguage() );
575 nFmt
= pNumFormatter
->GetStandardFormat( SvNumFormatType::DATE
);
577 rFmtFldMax
.SetFormatKey(nFmt
);
578 rFmtFldMin
.SetFormatKey(nFmt
);
579 rFmtFldOrigin
.SetFormatKey(nFmt
);
583 m_xFmtFldStepMain
->GetFormatter().SetFormatKey(nFmt
);
586 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin
)
588 m_bShowAxisOrigin
= bShowOrigin
;
589 if( !AxisHelper::isAxisPositioningEnabled() )
590 m_bShowAxisOrigin
= true;
593 bool ScaleTabPage::ShowWarning(TranslateId pResIdMessage
, weld::Widget
* pControl
/* = nullptr */)
598 std::unique_ptr
<weld::MessageDialog
> xWarn(Application::CreateMessageDialog(GetFrameWeld(),
599 VclMessageType::Warning
, VclButtonsType::Ok
,
600 SchResId(pResIdMessage
)));
604 pControl
->grab_focus();
605 weld::Entry
* pEdit
= dynamic_cast<weld::Entry
*>(pControl
);
607 pEdit
->select_region(0, -1);
612 void ScaleTabPage::HideAllControls()
614 // We need to set these controls invisible when the class is instantiated
615 // since some code in EnableControls() depends on that logic. The real
616 // visibility of these controls depend on axis data type, and are
617 // set in EnableControls().
620 m_xCbxLogarithm
->hide();
623 m_xFmtFldStepMain
->hide();
624 m_xMt_MainDateStep
->hide();
625 m_xLB_MainTimeUnit
->hide();
626 m_xCbxAutoStepMain
->hide();
627 m_xTxtHelpCount
->hide();
629 m_xMtStepHelp
->hide();
630 m_xCbxAutoStepHelp
->hide();
632 m_xBxResolution
->hide();
637 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */