/src/libreoffice/chart2/source/controller/dialogs/tp_Scale.cxx
Line | Count | Source (jump to first uncovered line) |
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 | | |
49 | | void lcl_setValue(weld::FormattedSpinButton& rFmtField, double fValue) |
50 | 0 | { |
51 | 0 | rFmtField.GetFormatter().SetValue(fValue); |
52 | 0 | } |
53 | | |
54 | | } |
55 | | |
56 | | ScaleTabPage::ScaleTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rInAttrs) |
57 | 0 | : SfxTabPage(pPage, pController, u"modules/schart/ui/tp_Scale.ui"_ustr, u"tp_Scale"_ustr, &rInAttrs) |
58 | 0 | , fMin(0.0) |
59 | 0 | , fMax(0.0) |
60 | 0 | , fStepMain(0.0) |
61 | 0 | , nStepHelp(0) |
62 | 0 | , fOrigin(0.0) |
63 | 0 | , m_nTimeResolution(1) |
64 | 0 | , m_nMainTimeUnit(1) |
65 | 0 | , m_nHelpTimeUnit(1) |
66 | 0 | , m_nAxisType(chart2::AxisType::REALNUMBER) |
67 | 0 | , m_bAllowDateAxis(false) |
68 | 0 | , pNumFormatter(nullptr) |
69 | 0 | , m_bShowAxisOrigin(false) |
70 | 0 | , m_xCbxReverse(m_xBuilder->weld_check_button(u"CBX_REVERSE"_ustr)) |
71 | 0 | , m_xCbxLogarithm(m_xBuilder->weld_check_button(u"CBX_LOGARITHM"_ustr)) |
72 | 0 | , m_xBxType(m_xBuilder->weld_widget(u"boxTYPE"_ustr)) |
73 | 0 | , m_xLB_AxisType(m_xBuilder->weld_combo_box(u"LB_AXIS_TYPE"_ustr)) |
74 | 0 | , m_xBxMinMax(m_xBuilder->weld_widget(u"gridMINMAX"_ustr)) |
75 | 0 | , m_xFmtFldMin(m_xBuilder->weld_formatted_spin_button(u"EDT_MIN"_ustr)) |
76 | 0 | , m_xCbxAutoMin(m_xBuilder->weld_check_button(u"CBX_AUTO_MIN"_ustr)) |
77 | 0 | , m_xFmtFldMax(m_xBuilder->weld_formatted_spin_button(u"EDT_MAX"_ustr)) |
78 | 0 | , m_xCbxAutoMax(m_xBuilder->weld_check_button(u"CBX_AUTO_MAX"_ustr)) |
79 | 0 | , m_xBxResolution(m_xBuilder->weld_widget(u"boxRESOLUTION"_ustr)) |
80 | 0 | , m_xLB_TimeResolution(m_xBuilder->weld_combo_box(u"LB_TIME_RESOLUTION"_ustr)) |
81 | 0 | , m_xCbx_AutoTimeResolution(m_xBuilder->weld_check_button(u"CBX_AUTO_TIME_RESOLUTION"_ustr)) |
82 | 0 | , m_xTxtMain(m_xBuilder->weld_label(u"TXT_STEP_MAIN"_ustr)) |
83 | 0 | , m_xFmtFldStepMain(m_xBuilder->weld_formatted_spin_button(u"EDT_STEP_MAIN"_ustr)) |
84 | 0 | , m_xMt_MainDateStep(m_xBuilder->weld_spin_button(u"MT_MAIN_DATE_STEP"_ustr)) |
85 | 0 | , m_xLB_MainTimeUnit(m_xBuilder->weld_combo_box(u"LB_MAIN_TIME_UNIT"_ustr)) |
86 | 0 | , m_xCbxAutoStepMain(m_xBuilder->weld_check_button(u"CBX_AUTO_STEP_MAIN"_ustr)) |
87 | 0 | , m_xTxtHelpCount(m_xBuilder->weld_label(u"TXT_STEP_HELP_COUNT"_ustr)) |
88 | 0 | , m_xTxtHelp(m_xBuilder->weld_label(u"TXT_STEP_HELP"_ustr)) |
89 | 0 | , m_xMtStepHelp(m_xBuilder->weld_spin_button(u"MT_STEPHELP"_ustr)) |
90 | 0 | , m_xLB_HelpTimeUnit(m_xBuilder->weld_combo_box(u"LB_HELP_TIME_UNIT"_ustr)) |
91 | 0 | , m_xCbxAutoStepHelp(m_xBuilder->weld_check_button(u"CBX_AUTO_STEP_HELP"_ustr)) |
92 | 0 | , m_xFmtFldOrigin(m_xBuilder->weld_formatted_spin_button(u"EDT_ORIGIN"_ustr)) |
93 | 0 | , m_xCbxAutoOrigin(m_xBuilder->weld_check_button(u"CBX_AUTO_ORIGIN"_ustr)) |
94 | 0 | , m_xBxOrigin(m_xBuilder->weld_widget(u"boxORIGIN"_ustr)) |
95 | 0 | { |
96 | 0 | m_xCbxAutoMin->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl)); |
97 | 0 | m_xCbxAutoMax->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl)); |
98 | 0 | m_xCbxAutoStepMain->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl)); |
99 | 0 | m_xCbxAutoStepHelp->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl)); |
100 | 0 | m_xCbxAutoOrigin->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl)); |
101 | 0 | m_xCbx_AutoTimeResolution->connect_toggled(LINK(this, ScaleTabPage, EnableValueHdl)); |
102 | |
|
103 | 0 | Formatter& rFmtFldMax = m_xFmtFldMax->GetFormatter(); |
104 | 0 | rFmtFldMax.ClearMinValue(); |
105 | 0 | rFmtFldMax.ClearMaxValue(); |
106 | 0 | Formatter& rFmtFldMin = m_xFmtFldMin->GetFormatter(); |
107 | 0 | rFmtFldMin.ClearMinValue(); |
108 | 0 | rFmtFldMin.ClearMaxValue(); |
109 | 0 | Formatter& rFmtFldStepMain = m_xFmtFldStepMain->GetFormatter(); |
110 | 0 | rFmtFldStepMain.ClearMinValue(); |
111 | 0 | rFmtFldStepMain.ClearMaxValue(); |
112 | 0 | Formatter& rFmtFldOrigin = m_xFmtFldOrigin->GetFormatter(); |
113 | 0 | rFmtFldOrigin.ClearMinValue(); |
114 | 0 | rFmtFldOrigin.ClearMaxValue(); |
115 | |
|
116 | 0 | m_xLB_AxisType->connect_changed(LINK(this, ScaleTabPage, SelectAxisTypeHdl)); |
117 | |
|
118 | 0 | HideAllControls(); |
119 | 0 | } |
120 | | |
121 | | ScaleTabPage::~ScaleTabPage() |
122 | 0 | { |
123 | 0 | } |
124 | | |
125 | | void ScaleTabPage::EnableControls() |
126 | 0 | { |
127 | 0 | bool bValueAxis = m_nAxisType == chart2::AxisType::REALNUMBER |
128 | 0 | || m_nAxisType == chart2::AxisType::PERCENT |
129 | 0 | || m_nAxisType == chart2::AxisType::DATE; |
130 | 0 | bool bDateAxis = m_nAxisType == chart2::AxisType::DATE; |
131 | |
|
132 | 0 | m_xBxType->set_visible(m_bAllowDateAxis); |
133 | |
|
134 | 0 | m_xCbxLogarithm->set_visible( bValueAxis && !bDateAxis ); |
135 | |
|
136 | 0 | m_xBxMinMax->set_visible(bValueAxis); |
137 | |
|
138 | 0 | m_xTxtMain->set_visible( bValueAxis ); |
139 | 0 | m_xCbxAutoStepMain->set_visible( bValueAxis ); |
140 | |
|
141 | 0 | m_xTxtHelpCount->set_visible( bValueAxis && !bDateAxis ); |
142 | 0 | m_xTxtHelp->set_visible( bDateAxis ); |
143 | 0 | m_xMtStepHelp->set_visible( bValueAxis ); |
144 | 0 | m_xCbxAutoStepHelp->set_visible( bValueAxis ); |
145 | |
|
146 | 0 | m_xBxOrigin->set_visible( m_bShowAxisOrigin && bValueAxis ); |
147 | 0 | m_xBxResolution->set_visible( bDateAxis ); |
148 | |
|
149 | 0 | bool bWasDateAxis = m_xMt_MainDateStep->get_visible(); |
150 | 0 | if( bWasDateAxis != bDateAxis ) |
151 | 0 | { |
152 | | //transport value from one to other control |
153 | 0 | if( bWasDateAxis ) |
154 | 0 | lcl_setValue( *m_xFmtFldStepMain, m_xMt_MainDateStep->get_value() ); |
155 | 0 | else |
156 | 0 | m_xMt_MainDateStep->set_value(m_xFmtFldStepMain->GetFormatter().GetValue()); |
157 | 0 | } |
158 | |
|
159 | 0 | m_xFmtFldStepMain->set_visible( bValueAxis && !bDateAxis ); |
160 | 0 | m_xMt_MainDateStep->set_visible( bDateAxis ); |
161 | |
|
162 | 0 | m_xLB_MainTimeUnit->set_visible( bDateAxis ); |
163 | 0 | m_xLB_HelpTimeUnit->set_visible( bDateAxis ); |
164 | |
|
165 | 0 | EnableValueHdl(*m_xCbxAutoMin); |
166 | 0 | EnableValueHdl(*m_xCbxAutoMax); |
167 | 0 | EnableValueHdl(*m_xCbxAutoStepMain); |
168 | 0 | EnableValueHdl(*m_xCbxAutoStepHelp); |
169 | 0 | EnableValueHdl(*m_xCbxAutoOrigin); |
170 | 0 | EnableValueHdl(*m_xCbx_AutoTimeResolution); |
171 | 0 | } |
172 | | |
173 | | IMPL_LINK( ScaleTabPage, EnableValueHdl, weld::Toggleable&, rCbx, void ) |
174 | 0 | { |
175 | 0 | bool bEnable = !rCbx.get_active() && rCbx.get_sensitive(); |
176 | 0 | if (&rCbx == m_xCbxAutoMin.get()) |
177 | 0 | { |
178 | 0 | m_xFmtFldMin->set_sensitive( bEnable ); |
179 | 0 | } |
180 | 0 | else if (&rCbx == m_xCbxAutoMax.get()) |
181 | 0 | { |
182 | 0 | m_xFmtFldMax->set_sensitive( bEnable ); |
183 | 0 | } |
184 | 0 | else if (&rCbx == m_xCbxAutoStepMain.get()) |
185 | 0 | { |
186 | 0 | m_xFmtFldStepMain->set_sensitive( bEnable ); |
187 | 0 | m_xMt_MainDateStep->set_sensitive( bEnable ); |
188 | 0 | m_xLB_MainTimeUnit->set_sensitive( bEnable ); |
189 | 0 | } |
190 | 0 | else if (&rCbx == m_xCbxAutoStepHelp.get()) |
191 | 0 | { |
192 | 0 | m_xMtStepHelp->set_sensitive( bEnable ); |
193 | 0 | m_xLB_HelpTimeUnit->set_sensitive( bEnable ); |
194 | 0 | } |
195 | 0 | else if (&rCbx == m_xCbx_AutoTimeResolution.get()) |
196 | 0 | { |
197 | 0 | m_xLB_TimeResolution->set_sensitive( bEnable ); |
198 | 0 | } |
199 | 0 | else if (&rCbx == m_xCbxAutoOrigin.get()) |
200 | 0 | { |
201 | 0 | m_xFmtFldOrigin->set_sensitive( bEnable ); |
202 | 0 | } |
203 | 0 | } |
204 | | |
205 | | namespace { |
206 | | |
207 | | enum AxisTypeListBoxEntry |
208 | | { |
209 | | TYPE_AUTO=0, |
210 | | TYPE_TEXT=1, |
211 | | TYPE_DATE=2 |
212 | | }; |
213 | | |
214 | | } |
215 | | |
216 | | IMPL_LINK_NOARG(ScaleTabPage, SelectAxisTypeHdl, weld::ComboBox&, void) |
217 | 0 | { |
218 | 0 | const sal_Int32 nPos = m_xLB_AxisType->get_active(); |
219 | 0 | if( nPos==TYPE_DATE ) |
220 | 0 | m_nAxisType = chart2::AxisType::DATE; |
221 | 0 | else |
222 | 0 | m_nAxisType = chart2::AxisType::CATEGORY; |
223 | 0 | if( m_nAxisType == chart2::AxisType::DATE ) |
224 | 0 | m_xCbxLogarithm->set_active(false); |
225 | 0 | EnableControls(); |
226 | 0 | SetNumFormat(); |
227 | 0 | } |
228 | | |
229 | | std::unique_ptr<SfxTabPage> ScaleTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs) |
230 | 0 | { |
231 | 0 | return std::make_unique<ScaleTabPage>(pPage, pController, *rOutAttrs); |
232 | 0 | } |
233 | | |
234 | | bool ScaleTabPage::FillItemSet(SfxItemSet* rOutAttrs) |
235 | 0 | { |
236 | 0 | OSL_PRECOND( pNumFormatter, "No NumberFormatter available" ); |
237 | |
|
238 | 0 | rOutAttrs->Put(SfxInt32Item(SCHATTR_AXISTYPE, m_nAxisType)); |
239 | 0 | if(m_bAllowDateAxis) |
240 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_DATEAXIS, m_xLB_AxisType->get_active()==TYPE_AUTO)); |
241 | |
|
242 | 0 | bool bAutoScale = false; |
243 | 0 | if( m_nAxisType==chart2::AxisType::CATEGORY ) |
244 | 0 | bAutoScale = true;//reset scaling for category charts |
245 | |
|
246 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MIN ,bAutoScale || m_xCbxAutoMin->get_active())); |
247 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_MAX ,bAutoScale || m_xCbxAutoMax->get_active())); |
248 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_HELP,bAutoScale || m_xCbxAutoStepHelp->get_active())); |
249 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_ORIGIN ,bAutoScale || m_xCbxAutoOrigin->get_active())); |
250 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_LOGARITHM ,m_xCbxLogarithm->get_active())); |
251 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_REVERSE ,m_xCbxReverse->get_active())); |
252 | 0 | rOutAttrs->Put(SvxDoubleItem(fMax , SCHATTR_AXIS_MAX)); |
253 | 0 | rOutAttrs->Put(SvxDoubleItem(fMin , SCHATTR_AXIS_MIN)); |
254 | 0 | rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_STEP_HELP, nStepHelp)); |
255 | 0 | rOutAttrs->Put(SvxDoubleItem(fOrigin , SCHATTR_AXIS_ORIGIN)); |
256 | |
|
257 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_STEP_MAIN,bAutoScale || m_xCbxAutoStepMain->get_active())); |
258 | 0 | rOutAttrs->Put(SvxDoubleItem(fStepMain,SCHATTR_AXIS_STEP_MAIN)); |
259 | |
|
260 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_AUTO_TIME_RESOLUTION,bAutoScale || m_xCbx_AutoTimeResolution->get_active())); |
261 | 0 | rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TIME_RESOLUTION,m_nTimeResolution)); |
262 | |
|
263 | 0 | rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_MAIN_TIME_UNIT,m_nMainTimeUnit)); |
264 | 0 | rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELP_TIME_UNIT,m_nHelpTimeUnit)); |
265 | |
|
266 | 0 | return true; |
267 | 0 | } |
268 | | |
269 | | void ScaleTabPage::Reset(const SfxItemSet* rInAttrs) |
270 | 0 | { |
271 | 0 | OSL_PRECOND( pNumFormatter, "No NumberFormatter available" ); |
272 | 0 | if(!pNumFormatter) |
273 | 0 | return; |
274 | | |
275 | 0 | if (const SfxBoolItem* pDateAxisItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_ALLOW_DATEAXIS)) |
276 | 0 | m_bAllowDateAxis = pDateAxisItem->GetValue(); |
277 | 0 | m_nAxisType=chart2::AxisType::REALNUMBER; |
278 | 0 | if (const SfxInt32Item* pAxisTypeItem = rInAttrs->GetItemIfSet(SCHATTR_AXISTYPE)) |
279 | 0 | m_nAxisType = static_cast<int>(pAxisTypeItem->GetValue()); |
280 | 0 | if( m_nAxisType==chart2::AxisType::DATE && !m_bAllowDateAxis ) |
281 | 0 | m_nAxisType=chart2::AxisType::CATEGORY; |
282 | 0 | if( m_bAllowDateAxis ) |
283 | 0 | { |
284 | 0 | bool bAutoDateAxis = false; |
285 | 0 | if (const SfxBoolItem* pDateAxisItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_DATEAXIS)) |
286 | 0 | bAutoDateAxis = pDateAxisItem->GetValue(); |
287 | |
|
288 | 0 | sal_uInt16 nPos = 0; |
289 | 0 | if( m_nAxisType==chart2::AxisType::DATE ) |
290 | 0 | nPos=TYPE_DATE; |
291 | 0 | else if( bAutoDateAxis ) |
292 | 0 | nPos=TYPE_AUTO; |
293 | 0 | else |
294 | 0 | nPos=TYPE_TEXT; |
295 | 0 | m_xLB_AxisType->set_active( nPos ); |
296 | 0 | } |
297 | |
|
298 | 0 | m_xCbxAutoMin->set_active(true); |
299 | 0 | m_xCbxAutoMax->set_active(true); |
300 | 0 | m_xCbxAutoStepMain->set_active(true); |
301 | 0 | m_xCbxAutoStepHelp->set_active(true); |
302 | 0 | m_xCbxAutoOrigin->set_active(true); |
303 | 0 | m_xCbx_AutoTimeResolution->set_active(true); |
304 | |
|
305 | 0 | if (const SfxBoolItem* pAutoMinItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_MIN)) |
306 | 0 | m_xCbxAutoMin->set_active(pAutoMinItem->GetValue()); |
307 | |
|
308 | 0 | if (const SvxDoubleItem* pAxisMinItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MIN)) |
309 | 0 | { |
310 | 0 | fMin = pAxisMinItem->GetValue(); |
311 | 0 | lcl_setValue( *m_xFmtFldMin, fMin ); |
312 | 0 | m_xFmtFldMin->save_value(); |
313 | 0 | } |
314 | |
|
315 | 0 | if (const SfxBoolItem* pAutoMaxItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_MAX)) |
316 | 0 | m_xCbxAutoMax->set_active(pAutoMaxItem->GetValue()); |
317 | |
|
318 | 0 | if (const SvxDoubleItem* pAxisMaxItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MAX)) |
319 | 0 | { |
320 | 0 | fMax = pAxisMaxItem->GetValue(); |
321 | 0 | lcl_setValue( *m_xFmtFldMax, fMax ); |
322 | 0 | m_xFmtFldMax->save_value(); |
323 | 0 | } |
324 | |
|
325 | 0 | if (const SfxBoolItem* pAutoStepMainItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_STEP_MAIN)) |
326 | 0 | m_xCbxAutoStepMain->set_active(pAutoStepMainItem->GetValue()); |
327 | |
|
328 | 0 | if (const SvxDoubleItem* pStepMainItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_STEP_MAIN)) |
329 | 0 | { |
330 | 0 | fStepMain = pStepMainItem->GetValue(); |
331 | 0 | lcl_setValue( *m_xFmtFldStepMain, fStepMain ); |
332 | 0 | m_xFmtFldStepMain->save_value(); |
333 | 0 | m_xMt_MainDateStep->set_value( static_cast<sal_Int32>(fStepMain) ); |
334 | 0 | m_xMt_MainDateStep->save_value(); |
335 | 0 | } |
336 | 0 | if (const SfxBoolItem* pAutoStepHelpItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_STEP_HELP)) |
337 | 0 | m_xCbxAutoStepHelp->set_active(pAutoStepHelpItem->GetValue()); |
338 | 0 | if (const SfxBoolItem* pLogItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_LOGARITHM)) |
339 | 0 | m_xCbxLogarithm->set_active(pLogItem->GetValue()); |
340 | 0 | if (const SfxBoolItem* pReverseItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_REVERSE)) |
341 | 0 | m_xCbxReverse->set_active(pReverseItem->GetValue()); |
342 | 0 | if (const SfxInt32Item* pStepHelpItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_STEP_HELP)) |
343 | 0 | { |
344 | 0 | nStepHelp = pStepHelpItem->GetValue(); |
345 | 0 | m_xMtStepHelp->set_value( nStepHelp ); |
346 | 0 | m_xMtStepHelp->save_value(); |
347 | 0 | } |
348 | 0 | if (const SfxBoolItem* pOriginItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_ORIGIN)) |
349 | 0 | m_xCbxAutoOrigin->set_active(pOriginItem->GetValue()); |
350 | 0 | if (const SvxDoubleItem* pOriginItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_ORIGIN)) |
351 | 0 | { |
352 | 0 | fOrigin = pOriginItem->GetValue(); |
353 | 0 | lcl_setValue( *m_xFmtFldOrigin, fOrigin ); |
354 | 0 | m_xFmtFldOrigin->save_value(); |
355 | 0 | } |
356 | |
|
357 | 0 | if (const SfxBoolItem* pAutoTimeResItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_AUTO_TIME_RESOLUTION)) |
358 | 0 | m_xCbx_AutoTimeResolution->set_active(pAutoTimeResItem->GetValue()); |
359 | 0 | if (const SfxInt32Item* pTimeResItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_TIME_RESOLUTION)) |
360 | 0 | { |
361 | 0 | m_nTimeResolution = pTimeResItem->GetValue(); |
362 | 0 | m_xLB_TimeResolution->set_active( m_nTimeResolution ); |
363 | 0 | } |
364 | |
|
365 | 0 | if (const SfxInt32Item* pMainTimeUnitItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_MAIN_TIME_UNIT)) |
366 | 0 | { |
367 | 0 | m_nMainTimeUnit = pMainTimeUnitItem->GetValue(); |
368 | 0 | m_xLB_MainTimeUnit->set_active( m_nMainTimeUnit ); |
369 | 0 | } |
370 | 0 | if (const SfxInt32Item* pHelpTimeUnitItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_HELP_TIME_UNIT)) |
371 | 0 | { |
372 | 0 | m_nHelpTimeUnit = pHelpTimeUnitItem->GetValue(); |
373 | 0 | m_xLB_HelpTimeUnit->set_active( m_nHelpTimeUnit ); |
374 | 0 | } |
375 | |
|
376 | 0 | EnableControls(); |
377 | 0 | SetNumFormat(); |
378 | 0 | } |
379 | | |
380 | | DeactivateRC ScaleTabPage::DeactivatePage(SfxItemSet* pItemSet) |
381 | 0 | { |
382 | 0 | if( !pNumFormatter ) |
383 | 0 | { |
384 | 0 | OSL_FAIL( "No NumberFormatter available" ); |
385 | 0 | return DeactivateRC::LeavePage; |
386 | 0 | } |
387 | | |
388 | 0 | bool bDateAxis = m_nAxisType == chart2::AxisType::DATE; |
389 | |
|
390 | 0 | sal_uInt32 nMinMaxOriginFmt = m_xFmtFldMax->GetFormatter().GetFormatKey(); |
391 | 0 | if (pNumFormatter->GetType(nMinMaxOriginFmt) == SvNumFormatType::TEXT) |
392 | 0 | nMinMaxOriginFmt = 0; |
393 | | // numberformat_text cause numbers to fail being numbers... Shouldn't happen, but can. |
394 | 0 | sal_uInt32 nStepFmt = m_xFmtFldStepMain->GetFormatter().GetFormatKey(); |
395 | 0 | if (pNumFormatter->GetType(nStepFmt) == SvNumFormatType::TEXT) |
396 | 0 | nStepFmt = 0; |
397 | |
|
398 | 0 | weld::Widget* pControl = nullptr; |
399 | 0 | TranslateId pErrStrId; |
400 | 0 | double fDummy; |
401 | |
|
402 | 0 | fMax = m_xFmtFldMax->GetFormatter().GetValue(); |
403 | 0 | fMin = m_xFmtFldMin->GetFormatter().GetValue(); |
404 | 0 | fOrigin = m_xFmtFldOrigin->GetFormatter().GetValue(); |
405 | 0 | fStepMain = bDateAxis ? m_xMt_MainDateStep->get_value() : m_xFmtFldStepMain->GetFormatter().GetValue(); |
406 | 0 | nStepHelp = m_xMtStepHelp->get_value(); |
407 | 0 | m_nTimeResolution = m_xLB_TimeResolution->get_active(); |
408 | 0 | m_nMainTimeUnit = m_xLB_MainTimeUnit->get_active(); |
409 | 0 | m_nHelpTimeUnit = m_xLB_HelpTimeUnit->get_active(); |
410 | |
|
411 | 0 | if( m_nAxisType != chart2::AxisType::REALNUMBER ) |
412 | 0 | m_xCbxLogarithm->hide(); |
413 | | |
414 | | //check which entries need user action |
415 | |
|
416 | 0 | if ( m_xCbxLogarithm->get_active() && |
417 | 0 | ( ( !m_xCbxAutoMin->get_active() && fMin <= 0.0 ) |
418 | 0 | || ( !m_xCbxAutoMax->get_active() && fMax <= 0.0 ) ) ) |
419 | 0 | { |
420 | 0 | pControl = m_xFmtFldMin.get(); |
421 | 0 | pErrStrId = STR_BAD_LOGARITHM; |
422 | 0 | } |
423 | | // check for entries that cannot be parsed for the current number format |
424 | 0 | else if ( m_xFmtFldMin->get_value_changed_from_saved() |
425 | 0 | && !m_xCbxAutoMin->get_active() |
426 | 0 | && !pNumFormatter->IsNumberFormat( m_xFmtFldMin->get_text(), nMinMaxOriginFmt, fDummy)) |
427 | 0 | { |
428 | 0 | pControl = m_xFmtFldMin.get(); |
429 | 0 | pErrStrId = STR_INVALID_NUMBER; |
430 | 0 | } |
431 | 0 | else if ( m_xFmtFldMax->get_value_changed_from_saved() |
432 | 0 | && !m_xCbxAutoMax->get_active() |
433 | 0 | && !pNumFormatter->IsNumberFormat( m_xFmtFldMax->get_text(), nMinMaxOriginFmt, fDummy)) |
434 | 0 | { |
435 | 0 | pControl = m_xFmtFldMax.get(); |
436 | 0 | pErrStrId = STR_INVALID_NUMBER; |
437 | 0 | } |
438 | 0 | else if ( !bDateAxis && m_xFmtFldStepMain->get_value_changed_from_saved() |
439 | 0 | && !m_xCbxAutoStepMain->get_active() |
440 | 0 | && !pNumFormatter->IsNumberFormat( m_xFmtFldStepMain->get_text(), nStepFmt, fDummy)) |
441 | 0 | { |
442 | 0 | pControl = m_xFmtFldStepMain.get(); |
443 | 0 | pErrStrId = STR_INVALID_NUMBER; |
444 | 0 | } |
445 | 0 | else if (m_xFmtFldOrigin->get_value_changed_from_saved() && !m_xCbxAutoOrigin->get_active() && |
446 | 0 | !pNumFormatter->IsNumberFormat( m_xFmtFldOrigin->get_text(), nMinMaxOriginFmt, fDummy)) |
447 | 0 | { |
448 | 0 | pControl = m_xFmtFldOrigin.get(); |
449 | 0 | pErrStrId = STR_INVALID_NUMBER; |
450 | 0 | } |
451 | 0 | else if (!m_xCbxAutoStepMain->get_active() && fStepMain <= 0.0) |
452 | 0 | { |
453 | 0 | pControl = m_xFmtFldStepMain.get(); |
454 | 0 | pErrStrId = STR_STEP_GT_ZERO; |
455 | 0 | } |
456 | 0 | else if (!m_xCbxAutoMax->get_active() && !m_xCbxAutoMin->get_active() && |
457 | 0 | fMin >= fMax) |
458 | 0 | { |
459 | 0 | pControl = m_xFmtFldMin.get(); |
460 | 0 | pErrStrId = STR_MIN_GREATER_MAX; |
461 | 0 | } |
462 | 0 | else if( bDateAxis ) |
463 | 0 | { |
464 | 0 | if( !m_xCbxAutoStepMain->get_active() && !m_xCbxAutoStepHelp->get_active() ) |
465 | 0 | { |
466 | 0 | if( m_nHelpTimeUnit > m_nMainTimeUnit ) |
467 | 0 | { |
468 | 0 | pControl = m_xLB_MainTimeUnit.get(); |
469 | 0 | pErrStrId = STR_INVALID_INTERVALS; |
470 | 0 | } |
471 | 0 | else if( m_nHelpTimeUnit == m_nMainTimeUnit && nStepHelp > fStepMain ) |
472 | 0 | { |
473 | 0 | pControl = m_xLB_MainTimeUnit.get(); |
474 | 0 | pErrStrId = STR_INVALID_INTERVALS; |
475 | 0 | } |
476 | 0 | } |
477 | 0 | if( !pErrStrId && !m_xCbx_AutoTimeResolution->get_active() ) |
478 | 0 | { |
479 | 0 | if( (!m_xCbxAutoStepMain->get_active() && m_nTimeResolution > m_nMainTimeUnit ) |
480 | 0 | || |
481 | 0 | (!m_xCbxAutoStepHelp->get_active() && m_nTimeResolution > m_nHelpTimeUnit ) |
482 | 0 | ) |
483 | 0 | { |
484 | 0 | pControl = m_xLB_TimeResolution.get(); |
485 | 0 | pErrStrId = STR_INVALID_TIME_UNIT; |
486 | 0 | } |
487 | 0 | } |
488 | 0 | } |
489 | |
|
490 | 0 | if( ShowWarning( pErrStrId, pControl ) ) |
491 | 0 | return DeactivateRC::KeepPage; |
492 | | |
493 | 0 | if( pItemSet ) |
494 | 0 | FillItemSet( pItemSet ); |
495 | |
|
496 | 0 | return DeactivateRC::LeavePage; |
497 | 0 | } |
498 | | |
499 | | void ScaleTabPage::SetNumFormatter( SvNumberFormatter* pFormatter ) |
500 | 0 | { |
501 | 0 | pNumFormatter = pFormatter; |
502 | |
|
503 | 0 | Formatter& rFmtFldMax = m_xFmtFldMax->GetFormatter(); |
504 | 0 | Formatter& rFmtFldMin = m_xFmtFldMin->GetFormatter(); |
505 | 0 | Formatter& rFmtFldStepMain = m_xFmtFldStepMain->GetFormatter(); |
506 | 0 | Formatter& rFmtFldOrigin = m_xFmtFldOrigin->GetFormatter(); |
507 | |
|
508 | 0 | rFmtFldMax.SetFormatter( pNumFormatter ); |
509 | 0 | rFmtFldMin.SetFormatter( pNumFormatter ); |
510 | 0 | rFmtFldStepMain.SetFormatter( pNumFormatter ); |
511 | 0 | 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 | 0 | rFmtFldMax.UseInputStringForFormatting(); |
518 | 0 | rFmtFldMin.UseInputStringForFormatting(); |
519 | 0 | rFmtFldStepMain.UseInputStringForFormatting(); |
520 | 0 | rFmtFldOrigin.UseInputStringForFormatting(); |
521 | |
|
522 | 0 | SetNumFormat(); |
523 | 0 | } |
524 | | |
525 | | void ScaleTabPage::SetNumFormat() |
526 | 0 | { |
527 | 0 | const SfxUInt32Item *pNumFormatItem = GetItemSet().GetItemIfSet( SID_ATTR_NUMBERFORMAT_VALUE ); |
528 | |
|
529 | 0 | if( !pNumFormatItem ) |
530 | 0 | return; |
531 | | |
532 | 0 | sal_uInt32 nFmt = pNumFormatItem->GetValue(); |
533 | |
|
534 | 0 | Formatter& rFmtFldMax = m_xFmtFldMax->GetFormatter(); |
535 | 0 | rFmtFldMax.SetFormatKey(nFmt); |
536 | 0 | Formatter& rFmtFldMin = m_xFmtFldMin->GetFormatter(); |
537 | 0 | rFmtFldMin.SetFormatKey(nFmt); |
538 | 0 | Formatter& rFmtFldOrigin = m_xFmtFldOrigin->GetFormatter(); |
539 | 0 | rFmtFldOrigin.SetFormatKey(nFmt); |
540 | |
|
541 | 0 | if( pNumFormatter ) |
542 | 0 | { |
543 | 0 | SvNumFormatType eType = pNumFormatter->GetType( nFmt ); |
544 | 0 | if( eType == SvNumFormatType::DATE ) |
545 | 0 | { |
546 | | // for intervals use standard format for dates (so you can enter a number of days) |
547 | 0 | const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt ); |
548 | 0 | if( pFormat ) |
549 | 0 | nFmt = pNumFormatter->GetStandardIndex( pFormat->GetLanguage()); |
550 | 0 | else |
551 | 0 | nFmt = pNumFormatter->GetStandardIndex(); |
552 | 0 | } |
553 | 0 | else if( eType == SvNumFormatType::DATETIME ) |
554 | 0 | { |
555 | | // for intervals use time format for date times |
556 | 0 | const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt ); |
557 | 0 | if( pFormat ) |
558 | 0 | nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME, pFormat->GetLanguage() ); |
559 | 0 | else |
560 | 0 | nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::TIME ); |
561 | | |
562 | | // tdf#141625 give enough space to see full date+time |
563 | 0 | int nWidestTime(m_xFmtFldMin->get_pixel_size(getWidestDateTime(Application::GetSettings().GetLocaleDataWrapper(), true)).Width()); |
564 | 0 | int nWidthChars = std::ceil(nWidestTime / m_xFmtFldMin->get_approximate_digit_width()) + 1; |
565 | 0 | m_xFmtFldMin->set_width_chars(nWidthChars); |
566 | 0 | m_xFmtFldMax->set_width_chars(nWidthChars); |
567 | 0 | } |
568 | |
|
569 | 0 | if( m_nAxisType == chart2::AxisType::DATE && ( eType != SvNumFormatType::DATE && eType != SvNumFormatType::DATETIME) ) |
570 | 0 | { |
571 | 0 | const SvNumberformat* pFormat = pNumFormatter->GetEntry( nFmt ); |
572 | 0 | if( pFormat ) |
573 | 0 | nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE, pFormat->GetLanguage() ); |
574 | 0 | else |
575 | 0 | nFmt = pNumFormatter->GetStandardFormat( SvNumFormatType::DATE ); |
576 | |
|
577 | 0 | rFmtFldMax.SetFormatKey(nFmt); |
578 | 0 | rFmtFldMin.SetFormatKey(nFmt); |
579 | 0 | rFmtFldOrigin.SetFormatKey(nFmt); |
580 | 0 | } |
581 | 0 | } |
582 | |
|
583 | 0 | m_xFmtFldStepMain->GetFormatter().SetFormatKey(nFmt); |
584 | 0 | } |
585 | | |
586 | | void ScaleTabPage::ShowAxisOrigin( bool bShowOrigin ) |
587 | 0 | { |
588 | 0 | m_bShowAxisOrigin = bShowOrigin; |
589 | 0 | if( !AxisHelper::isAxisPositioningEnabled() ) |
590 | 0 | m_bShowAxisOrigin = true; |
591 | 0 | } |
592 | | |
593 | | bool ScaleTabPage::ShowWarning(TranslateId pResIdMessage, weld::Widget* pControl /* = nullptr */) |
594 | 0 | { |
595 | 0 | if (!pResIdMessage) |
596 | 0 | return false; |
597 | | |
598 | 0 | std::unique_ptr<weld::MessageDialog> xWarn(Application::CreateMessageDialog(GetFrameWeld(), |
599 | 0 | VclMessageType::Warning, VclButtonsType::Ok, |
600 | 0 | SchResId(pResIdMessage))); |
601 | 0 | xWarn->run(); |
602 | 0 | if (pControl) |
603 | 0 | { |
604 | 0 | pControl->grab_focus(); |
605 | 0 | weld::Entry* pEdit = dynamic_cast<weld::Entry*>(pControl); |
606 | 0 | if (pEdit) |
607 | 0 | pEdit->select_region(0, -1); |
608 | 0 | } |
609 | 0 | return true; |
610 | 0 | } |
611 | | |
612 | | void ScaleTabPage::HideAllControls() |
613 | 0 | { |
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 | 0 | m_xBxType->hide(); |
620 | 0 | m_xCbxLogarithm->hide(); |
621 | 0 | m_xBxMinMax->hide(); |
622 | 0 | m_xTxtMain->hide(); |
623 | 0 | m_xFmtFldStepMain->hide(); |
624 | 0 | m_xMt_MainDateStep->hide(); |
625 | 0 | m_xLB_MainTimeUnit->hide(); |
626 | 0 | m_xCbxAutoStepMain->hide(); |
627 | 0 | m_xTxtHelpCount->hide(); |
628 | 0 | m_xTxtHelp->hide(); |
629 | 0 | m_xMtStepHelp->hide(); |
630 | 0 | m_xCbxAutoStepHelp->hide(); |
631 | 0 | m_xBxOrigin->hide(); |
632 | 0 | m_xBxResolution->hide(); |
633 | 0 | } |
634 | | |
635 | | } //namespace chart |
636 | | |
637 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |