1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include "tp_Scale.hxx"
21 
22 #include <ResId.hxx>
23 #include <strings.hrc>
24 #include <chartview/ChartSfxItemIds.hxx>
25 #include <AxisHelper.hxx>
26 
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>
38 
39 #include <com/sun/star/chart2/AxisType.hpp>
40 
41 using namespace ::com::sun::star;
42 
43 namespace chart
44 {
45 
46 namespace
47 {
48 
lcl_setValue(weld::FormattedSpinButton & rFmtField,double fValue)49 void lcl_setValue(weld::FormattedSpinButton& rFmtField, double fValue)
50 {
51     rFmtField.GetFormatter().SetValue(fValue);
52 }
53 
54 }
55 
ScaleTabPage(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet & rInAttrs)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)
58     , fMin(0.0)
59     , fMax(0.0)
60     , fStepMain(0.0)
61     , nStepHelp(0)
62     , fOrigin(0.0)
63     , m_nTimeResolution(1)
64     , m_nMainTimeUnit(1)
65     , m_nHelpTimeUnit(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))
95 {
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));
102 
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();
115 
116     m_xLB_AxisType->connect_changed(LINK(this, ScaleTabPage, SelectAxisTypeHdl));
117 
118     HideAllControls();
119 }
120 
~ScaleTabPage()121 ScaleTabPage::~ScaleTabPage()
122 {
123 }
124 
EnableControls()125 void ScaleTabPage::EnableControls()
126 {
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;
131 
132     m_xBxType->set_visible(m_bAllowDateAxis);
133 
134     m_xCbxLogarithm->set_visible( bValueAxis && !bDateAxis );
135 
136     m_xBxMinMax->set_visible(bValueAxis);
137 
138     m_xTxtMain->set_visible( bValueAxis );
139     m_xCbxAutoStepMain->set_visible( bValueAxis );
140 
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 );
145 
146     m_xBxOrigin->set_visible( m_bShowAxisOrigin && bValueAxis );
147     m_xBxResolution->set_visible( bDateAxis );
148 
149     bool bWasDateAxis = m_xMt_MainDateStep->get_visible();
150     if( bWasDateAxis != bDateAxis )
151     {
152         //transport value from one to other control
153         if( bWasDateAxis )
154             lcl_setValue( *m_xFmtFldStepMain, m_xMt_MainDateStep->get_value() );
155         else
156             m_xMt_MainDateStep->set_value(m_xFmtFldStepMain->GetFormatter().GetValue());
157     }
158 
159     m_xFmtFldStepMain->set_visible( bValueAxis && !bDateAxis );
160     m_xMt_MainDateStep->set_visible( bDateAxis );
161 
162     m_xLB_MainTimeUnit->set_visible( bDateAxis );
163     m_xLB_HelpTimeUnit->set_visible( bDateAxis );
164 
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);
171 }
172 
IMPL_LINK(ScaleTabPage,EnableValueHdl,weld::Toggleable &,rCbx,void)173 IMPL_LINK( ScaleTabPage, EnableValueHdl, weld::Toggleable&, rCbx, void )
174 {
175     bool bEnable = !rCbx.get_active() && rCbx.get_sensitive();
176     if (&rCbx == m_xCbxAutoMin.get())
177     {
178         m_xFmtFldMin->set_sensitive( bEnable );
179     }
180     else if (&rCbx == m_xCbxAutoMax.get())
181     {
182         m_xFmtFldMax->set_sensitive( bEnable );
183     }
184     else if (&rCbx == m_xCbxAutoStepMain.get())
185     {
186         m_xFmtFldStepMain->set_sensitive( bEnable );
187         m_xMt_MainDateStep->set_sensitive( bEnable );
188         m_xLB_MainTimeUnit->set_sensitive( bEnable );
189     }
190     else if (&rCbx == m_xCbxAutoStepHelp.get())
191     {
192         m_xMtStepHelp->set_sensitive( bEnable );
193         m_xLB_HelpTimeUnit->set_sensitive( bEnable );
194     }
195     else if (&rCbx == m_xCbx_AutoTimeResolution.get())
196     {
197         m_xLB_TimeResolution->set_sensitive( bEnable );
198     }
199     else if (&rCbx == m_xCbxAutoOrigin.get())
200     {
201         m_xFmtFldOrigin->set_sensitive( bEnable );
202     }
203 }
204 
205 namespace {
206 
207 enum AxisTypeListBoxEntry
208 {
209     TYPE_AUTO=0,
210     TYPE_TEXT=1,
211     TYPE_DATE=2
212 };
213 
214 }
215 
IMPL_LINK_NOARG(ScaleTabPage,SelectAxisTypeHdl,weld::ComboBox &,void)216 IMPL_LINK_NOARG(ScaleTabPage, SelectAxisTypeHdl, weld::ComboBox&, void)
217 {
218     const sal_Int32 nPos = m_xLB_AxisType->get_active();
219     if( nPos==TYPE_DATE )
220         m_nAxisType = chart2::AxisType::DATE;
221     else
222         m_nAxisType = chart2::AxisType::CATEGORY;
223     if( m_nAxisType == chart2::AxisType::DATE )
224         m_xCbxLogarithm->set_active(false);
225     EnableControls();
226     SetNumFormat();
227 }
228 
Create(weld::Container * pPage,weld::DialogController * pController,const SfxItemSet * rOutAttrs)229 std::unique_ptr<SfxTabPage> ScaleTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs)
230 {
231     return std::make_unique<ScaleTabPage>(pPage, pController, *rOutAttrs);
232 }
233 
FillItemSet(SfxItemSet * rOutAttrs)234 bool ScaleTabPage::FillItemSet(SfxItemSet* rOutAttrs)
235 {
236     OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
237 
238     rOutAttrs->Put(SfxInt32Item(SCHATTR_AXISTYPE, m_nAxisType));
239     if(m_bAllowDateAxis)
240         rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, m_xLB_AxisType->get_active()==TYPE_AUTO));
241 
242     bool bAutoScale = false;
243     if( m_nAxisType==chart2::AxisType::CATEGORY )
244         bAutoScale = true;//reset scaling for category charts
245 
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));
256 
257     rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || m_xCbxAutoStepMain->get_active()));
258     rOutAttrs->Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN));
259 
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));
262 
263     rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,m_nMainTimeUnit));
264     rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,m_nHelpTimeUnit));
265 
266     return true;
267 }
268 
Reset(const SfxItemSet * rInAttrs)269 void ScaleTabPage::Reset(const SfxItemSet* rInAttrs)
270 {
271     OSL_PRECOND( pNumFormatter, "No NumberFormatter available" );
272     if(!pNumFormatter)
273         return;
274 
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 )
283     {
284         bool bAutoDateAxis = false;
285         if (const SfxBoolItem* pDateAxisItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_DATEAXIS))
286             bAutoDateAxis = pDateAxisItem->GetValue();
287 
288         sal_uInt16 nPos = 0;
289         if( m_nAxisType==chart2::AxisType::DATE )
290             nPos=TYPE_DATE;
291         else if( bAutoDateAxis )
292             nPos=TYPE_AUTO;
293         else
294             nPos=TYPE_TEXT;
295         m_xLB_AxisType->set_active( nPos );
296     }
297 
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);
304 
305     if (const SfxBoolItem* pAutoMinItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_MIN))
306         m_xCbxAutoMin->set_active(pAutoMinItem->GetValue());
307 
308     if (const SvxDoubleItem* pAxisMinItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MIN))
309     {
310         fMin = pAxisMinItem->GetValue();
311         lcl_setValue( *m_xFmtFldMin, fMin );
312         m_xFmtFldMin->save_value();
313     }
314 
315     if (const SfxBoolItem* pAutoMaxItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_MAX))
316         m_xCbxAutoMax->set_active(pAutoMaxItem->GetValue());
317 
318     if (const SvxDoubleItem* pAxisMaxItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MAX))
319     {
320         fMax = pAxisMaxItem->GetValue();
321         lcl_setValue( *m_xFmtFldMax, fMax );
322         m_xFmtFldMax->save_value();
323     }
324 
325     if (const SfxBoolItem* pAutoStepMainItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_STEP_MAIN))
326         m_xCbxAutoStepMain->set_active(pAutoStepMainItem->GetValue());
327 
328     if (const SvxDoubleItem* pStepMainItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_STEP_MAIN))
329     {
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();
335     }
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))
343     {
344         nStepHelp = pStepHelpItem->GetValue();
345         m_xMtStepHelp->set_value( nStepHelp );
346         m_xMtStepHelp->save_value();
347     }
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))
351     {
352         fOrigin = pOriginItem->GetValue();
353         lcl_setValue( *m_xFmtFldOrigin, fOrigin );
354         m_xFmtFldOrigin->save_value();
355     }
356 
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))
360     {
361         m_nTimeResolution = pTimeResItem->GetValue();
362         m_xLB_TimeResolution->set_active( m_nTimeResolution );
363     }
364 
365     if (const SfxInt32Item* pMainTimeUnitItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MAIN_TIME_UNIT))
366     {
367         m_nMainTimeUnit = pMainTimeUnitItem->GetValue();
368         m_xLB_MainTimeUnit->set_active( m_nMainTimeUnit );
369     }
370     if (const SfxInt32Item* pHelpTimeUnitItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_HELP_TIME_UNIT))
371     {
372         m_nHelpTimeUnit = pHelpTimeUnitItem->GetValue();
373         m_xLB_HelpTimeUnit->set_active( m_nHelpTimeUnit );
374     }
375 
376     EnableControls();
377     SetNumFormat();
378 }
379 
DeactivatePage(SfxItemSet * pItemSet)380 DeactivateRC ScaleTabPage::DeactivatePage(SfxItemSet* pItemSet)
381 {
382     if( !pNumFormatter )
383     {
384         OSL_FAIL( "No NumberFormatter available" );
385         return DeactivateRC::LeavePage;
386     }
387 
388     bool bDateAxis = m_nAxisType == chart2::AxisType::DATE;
389 
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)
396         nStepFmt = 0;
397 
398     weld::Widget* pControl = nullptr;
399     TranslateId pErrStrId;
400     double fDummy;
401 
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();
410 
411     if( m_nAxisType != chart2::AxisType::REALNUMBER )
412         m_xCbxLogarithm->hide();
413 
414     //check which entries need user action
415 
416     if ( m_xCbxLogarithm->get_active() &&
417             ( ( !m_xCbxAutoMin->get_active() && fMin <= 0.0 )
418              || ( !m_xCbxAutoMax->get_active() && fMax <= 0.0 ) ) )
419     {
420         pControl = m_xFmtFldMin.get();
421         pErrStrId = STR_BAD_LOGARITHM;
422     }
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))
427     {
428         pControl = m_xFmtFldMin.get();
429         pErrStrId = STR_INVALID_NUMBER;
430     }
431     else if ( m_xFmtFldMax->get_value_changed_from_saved()
432               && !m_xCbxAutoMax->get_active()
433               && !pNumFormatter->IsNumberFormat( m_xFmtFldMax->get_text(), nMinMaxOriginFmt, fDummy))
434     {
435         pControl = m_xFmtFldMax.get();
436         pErrStrId = STR_INVALID_NUMBER;
437     }
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))
441     {
442         pControl = m_xFmtFldStepMain.get();
443         pErrStrId = STR_INVALID_NUMBER;
444     }
445     else if (m_xFmtFldOrigin->get_value_changed_from_saved() && !m_xCbxAutoOrigin->get_active() &&
446              !pNumFormatter->IsNumberFormat( m_xFmtFldOrigin->get_text(), nMinMaxOriginFmt, fDummy))
447     {
448         pControl = m_xFmtFldOrigin.get();
449         pErrStrId = STR_INVALID_NUMBER;
450     }
451     else if (!m_xCbxAutoStepMain->get_active() && fStepMain <= 0.0)
452     {
453         pControl = m_xFmtFldStepMain.get();
454         pErrStrId = STR_STEP_GT_ZERO;
455     }
456     else if (!m_xCbxAutoMax->get_active() && !m_xCbxAutoMin->get_active() &&
457              fMin >= fMax)
458     {
459         pControl = m_xFmtFldMin.get();
460         pErrStrId = STR_MIN_GREATER_MAX;
461     }
462     else if( bDateAxis )
463     {
464         if( !m_xCbxAutoStepMain->get_active() && !m_xCbxAutoStepHelp->get_active() )
465         {
466             if( m_nHelpTimeUnit > m_nMainTimeUnit )
467             {
468                 pControl = m_xLB_MainTimeUnit.get();
469                 pErrStrId = STR_INVALID_INTERVALS;
470             }
471             else if( m_nHelpTimeUnit == m_nMainTimeUnit && nStepHelp > fStepMain )
472             {
473                 pControl = m_xLB_MainTimeUnit.get();
474                 pErrStrId = STR_INVALID_INTERVALS;
475             }
476         }
477         if( !pErrStrId && !m_xCbx_AutoTimeResolution->get_active() )
478         {
479             if( (!m_xCbxAutoStepMain->get_active() && m_nTimeResolution > m_nMainTimeUnit )
480                 ||
481                 (!m_xCbxAutoStepHelp->get_active() && m_nTimeResolution > m_nHelpTimeUnit )
482                 )
483             {
484                 pControl = m_xLB_TimeResolution.get();
485                 pErrStrId = STR_INVALID_TIME_UNIT;
486             }
487         }
488     }
489 
490     if( ShowWarning( pErrStrId, pControl ) )
491         return DeactivateRC::KeepPage;
492 
493     if( pItemSet )
494         FillItemSet( pItemSet );
495 
496     return DeactivateRC::LeavePage;
497 }
498 
SetNumFormatter(SvNumberFormatter * pFormatter)499 void ScaleTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
500 {
501     pNumFormatter = pFormatter;
502 
503     Formatter& rFmtFldMax = m_xFmtFldMax->GetFormatter();
504     Formatter& rFmtFldMin = m_xFmtFldMin->GetFormatter();
505     Formatter& rFmtFldStepMain = m_xFmtFldStepMain->GetFormatter();
506     Formatter& rFmtFldOrigin = m_xFmtFldOrigin->GetFormatter();
507 
508     rFmtFldMax.SetFormatter( pNumFormatter );
509     rFmtFldMin.SetFormatter( pNumFormatter );
510     rFmtFldStepMain.SetFormatter( pNumFormatter );
511     rFmtFldOrigin.SetFormatter( pNumFormatter );
512 
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
516     // format.
517     rFmtFldMax.UseInputStringForFormatting();
518     rFmtFldMin.UseInputStringForFormatting();
519     rFmtFldStepMain.UseInputStringForFormatting();
520     rFmtFldOrigin.UseInputStringForFormatting();
521 
522     SetNumFormat();
523 }
524 
SetNumFormat()525 void ScaleTabPage::SetNumFormat()
526 {
527     const SfxUInt32Item *pNumFormatItem = GetItemSet().GetItemIfSet( SID_ATTR_NUMBERFORMAT_VALUE );
528 
529     if( !pNumFormatItem )
530         return;
531 
532     sal_uInt32 nFmt = pNumFormatItem->GetValue();
533 
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);
540 
541     if( pNumFormatter )
542     {
543         SvNumFormatType eType = pNumFormatter->GetType( nFmt );
544         if( eType == SvNumFormatType::DATE )
545         {
546             // for intervals use standard format for dates (so you can enter a number of days)
547             const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
548             if( pFormat )
549                 nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage());
550             else
551                 nFmt = pNumFormatter->GetStandardIndex();
552         }
553         else if( eType == SvNumFormatType::DATETIME )
554         {
555             // for intervals use time format for date times
556             const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
557             if( pFormat )
558                 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME, pFormat->GetLanguage() );
559             else
560                 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME );
561 
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);
567         }
568 
569         if( m_nAxisType == chart2::AxisType::DATE && ( eType != SvNumFormatType::DATE && eType != SvNumFormatType::DATETIME) )
570         {
571             const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt );
572             if( pFormat )
573                 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE, pFormat->GetLanguage() );
574             else
575                 nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE );
576 
577             rFmtFldMax.SetFormatKey(nFmt);
578             rFmtFldMin.SetFormatKey(nFmt);
579             rFmtFldOrigin.SetFormatKey(nFmt);
580         }
581     }
582 
583     m_xFmtFldStepMain->GetFormatter().SetFormatKey(nFmt);
584 }
585 
ShowAxisOrigin(bool bShowOrigin)586 void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin )
587 {
588     m_bShowAxisOrigin = bShowOrigin;
589     if( !AxisHelper::isAxisPositioningEnabled() )
590         m_bShowAxisOrigin = true;
591 }
592 
ShowWarning(TranslateId pResIdMessage,weld::Widget * pControl)593 bool ScaleTabPage::ShowWarning(TranslateId pResIdMessage, weld::Widget* pControl /* = nullptr */)
594 {
595     if (!pResIdMessage)
596         return false;
597 
598     std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(),
599                                                VclMessageType::Warning, VclButtonsType::Ok,
600                                                SchResId(pResIdMessage)));
601     xWarn->run();
602     if (pControl)
603     {
604         pControl->grab_focus();
605         weld::Entry* pEdit = dynamic_cast<weld::Entry*>(pControl);
606         if (pEdit)
607             pEdit->select_region(0, -1);
608     }
609     return true;
610 }
611 
HideAllControls()612 void ScaleTabPage::HideAllControls()
613 {
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().
618 
619     m_xBxType->hide();
620     m_xCbxLogarithm->hide();
621     m_xBxMinMax->hide();
622     m_xTxtMain->hide();
623     m_xFmtFldStepMain->hide();
624     m_xMt_MainDateStep->hide();
625     m_xLB_MainTimeUnit->hide();
626     m_xCbxAutoStepMain->hide();
627     m_xTxtHelpCount->hide();
628     m_xTxtHelp->hide();
629     m_xMtStepHelp->hide();
630     m_xCbxAutoStepHelp->hide();
631     m_xBxOrigin->hide();
632     m_xBxResolution->hide();
633 }
634 
635 } //namespace chart
636 
637 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
638