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