/src/libreoffice/chart2/source/controller/dialogs/tp_AxisPositions.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_AxisPositions.hxx" |
21 | | |
22 | | #include <chartview/ChartSfxItemIds.hxx> |
23 | | #include <AxisHelper.hxx> |
24 | | |
25 | | #include <rtl/math.hxx> |
26 | | #include <svx/chrtitem.hxx> |
27 | | #include <svl/intitem.hxx> |
28 | | #include <vcl/formatter.hxx> |
29 | | #include <vcl/weld/Builder.hxx> |
30 | | |
31 | | using namespace ::com::sun::star; |
32 | | |
33 | | namespace chart |
34 | | { |
35 | | |
36 | | AxisPositionsTabPage::AxisPositionsTabPage(weld::Container* pPage, weld::DialogController* pController,const SfxItemSet& rInAttrs) |
37 | 0 | : SfxTabPage(pPage, pController, u"modules/schart/ui/tp_AxisPositions.ui"_ustr, u"tp_AxisPositions"_ustr, &rInAttrs) |
38 | 0 | , m_pNumFormatter(nullptr) |
39 | 0 | , m_bCrossingAxisIsCategoryAxis(false) |
40 | 0 | , m_bSupportAxisPositioning(false) |
41 | 0 | , m_bSupportCategoryPositioning(false) |
42 | 0 | , m_xFL_AxisLine(m_xBuilder->weld_frame(u"FL_AXIS_LINE"_ustr)) |
43 | 0 | , m_xLB_CrossesAt(m_xBuilder->weld_combo_box(u"LB_CROSSES_OTHER_AXIS_AT"_ustr)) |
44 | 0 | , m_xED_CrossesAt(m_xBuilder->weld_formatted_spin_button(u"EDT_CROSSES_OTHER_AXIS_AT"_ustr)) |
45 | 0 | , m_xED_CrossesAtCategory(m_xBuilder->weld_combo_box( u"EDT_CROSSES_OTHER_AXIS_AT_CATEGORY"_ustr)) |
46 | 0 | , m_xFL_Position(m_xBuilder->weld_frame(u"FL_POSITION"_ustr)) |
47 | 0 | , m_xRB_On(m_xBuilder->weld_radio_button(u"RB_ON"_ustr)) |
48 | 0 | , m_xRB_Between(m_xBuilder->weld_radio_button(u"RB_BETWEEN"_ustr)) |
49 | 0 | , m_xFL_Labels(m_xBuilder->weld_frame(u"FL_LABELS"_ustr)) |
50 | 0 | , m_xLB_PlaceLabels(m_xBuilder->weld_combo_box(u"LB_PLACE_LABELS"_ustr)) |
51 | 0 | , m_xCB_TicksInner(m_xBuilder->weld_check_button(u"CB_TICKS_INNER"_ustr)) |
52 | 0 | , m_xCB_TicksOuter(m_xBuilder->weld_check_button(u"CB_TICKS_OUTER"_ustr)) |
53 | 0 | , m_xCB_MinorInner(m_xBuilder->weld_check_button(u"CB_MINOR_INNER"_ustr)) |
54 | 0 | , m_xCB_MinorOuter(m_xBuilder->weld_check_button(u"CB_MINOR_OUTER"_ustr)) |
55 | 0 | , m_xBxPlaceTicks(m_xBuilder->weld_widget(u"boxPLACE_TICKS"_ustr)) |
56 | 0 | , m_xLB_PlaceTicks(m_xBuilder->weld_combo_box(u"LB_PLACE_TICKS"_ustr)) |
57 | 0 | { |
58 | 0 | m_xLB_CrossesAt->connect_changed(LINK(this, AxisPositionsTabPage, CrossesAtSelectHdl)); |
59 | 0 | m_xLB_PlaceLabels->connect_changed(LINK(this, AxisPositionsTabPage, PlaceLabelsSelectHdl)); |
60 | |
|
61 | 0 | Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter(); |
62 | 0 | rCrossFormatter.ClearMinValue(); |
63 | 0 | rCrossFormatter.ClearMaxValue(); |
64 | 0 | Formatter& rDistanceFormatter = m_xED_CrossesAt->GetFormatter(); |
65 | 0 | rDistanceFormatter.ClearMinValue(); |
66 | 0 | rDistanceFormatter.ClearMaxValue(); |
67 | 0 | } |
68 | | |
69 | | AxisPositionsTabPage::~AxisPositionsTabPage() |
70 | 0 | { |
71 | 0 | } |
72 | | |
73 | | std::unique_ptr<SfxTabPage> AxisPositionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rOutAttrs) |
74 | 0 | { |
75 | 0 | return std::make_unique<AxisPositionsTabPage>(pPage, pController, *rOutAttrs); |
76 | 0 | } |
77 | | |
78 | | bool AxisPositionsTabPage::FillItemSet(SfxItemSet* rOutAttrs) |
79 | 0 | { |
80 | | // axis line |
81 | 0 | sal_Int32 nPos = m_xLB_CrossesAt->get_active(); |
82 | 0 | rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_POSITION, nPos+1 )); |
83 | 0 | if( nPos==2 ) |
84 | 0 | { |
85 | 0 | Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter(); |
86 | 0 | double fCrossover = rCrossFormatter.GetValue(); |
87 | 0 | if( m_bCrossingAxisIsCategoryAxis ) |
88 | 0 | fCrossover = m_xED_CrossesAtCategory->get_active()+1; |
89 | 0 | rOutAttrs->Put(SvxDoubleItem(fCrossover,SCHATTR_AXIS_POSITION_VALUE)); |
90 | 0 | } |
91 | | |
92 | | // shifted category position |
93 | 0 | if (m_xFL_Position->get_visible()) |
94 | 0 | rOutAttrs->Put(SfxBoolItem(SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION, m_xRB_Between->get_active())); |
95 | | |
96 | | // labels |
97 | 0 | sal_Int32 nLabelPos = m_xLB_PlaceLabels->get_active(); |
98 | 0 | if (nLabelPos != -1) |
99 | 0 | rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION, nLabelPos )); |
100 | | |
101 | | // tick marks |
102 | 0 | sal_Int32 nTicks=0; |
103 | 0 | sal_Int32 nMinorTicks=0; |
104 | |
|
105 | 0 | if(m_xCB_MinorInner->get_active()) |
106 | 0 | AFTicks::setFlagFor(nMinorTicks, AxisTicksAtr::Inner); |
107 | 0 | if(m_xCB_MinorOuter->get_active()) |
108 | 0 | AFTicks::setFlagFor(nMinorTicks, AxisTicksAtr::Outer); |
109 | 0 | if(m_xCB_TicksInner->get_active()) |
110 | 0 | AFTicks::setFlagFor(nTicks, AxisTicksAtr::Inner); |
111 | 0 | if(m_xCB_TicksOuter->get_active()) |
112 | 0 | AFTicks::setFlagFor(nTicks, AxisTicksAtr::Outer); |
113 | |
|
114 | 0 | rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TICKS,nTicks)); |
115 | 0 | rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS,nMinorTicks)); |
116 | |
|
117 | 0 | sal_Int32 nMarkPos = m_xLB_PlaceTicks->get_active(); |
118 | 0 | if (nMarkPos != -1) |
119 | 0 | rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION, nMarkPos )); |
120 | |
|
121 | 0 | return true; |
122 | 0 | } |
123 | | |
124 | | void AxisPositionsTabPage::Reset(const SfxItemSet* rInAttrs) |
125 | 0 | { |
126 | | //init and enable controls |
127 | 0 | m_xED_CrossesAt->set_visible( !m_bCrossingAxisIsCategoryAxis ); |
128 | 0 | m_xED_CrossesAtCategory->set_visible( m_bCrossingAxisIsCategoryAxis ); |
129 | 0 | if (m_bCrossingAxisIsCategoryAxis) |
130 | 0 | { |
131 | 0 | for (auto const& cat : m_aCategories) |
132 | 0 | m_xED_CrossesAtCategory->append_text(cat); |
133 | 0 | } |
134 | |
|
135 | 0 | if( m_xLB_CrossesAt->get_count() > 3 ) |
136 | 0 | { |
137 | 0 | if( m_bCrossingAxisIsCategoryAxis ) |
138 | 0 | m_xLB_CrossesAt->remove(2); |
139 | 0 | else |
140 | 0 | m_xLB_CrossesAt->remove(3); |
141 | 0 | } |
142 | | |
143 | | //fill controls |
144 | | |
145 | | //axis line |
146 | 0 | if(SfxInt32Item const * pPositionItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_POSITION)) |
147 | 0 | { |
148 | 0 | bool bZero = false; |
149 | 0 | sal_Int32 nPos = pPositionItem->GetValue(); |
150 | 0 | if(nPos==0) |
151 | 0 | { |
152 | | //switch to value |
153 | 0 | bZero = true; |
154 | 0 | nPos = 2; |
155 | 0 | } |
156 | 0 | else |
157 | 0 | nPos--; |
158 | |
|
159 | 0 | if( nPos < m_xLB_CrossesAt->get_count() ) |
160 | 0 | m_xLB_CrossesAt->set_active( nPos ); |
161 | 0 | CrossesAtSelectHdl( *m_xLB_CrossesAt ); |
162 | |
|
163 | 0 | const SvxDoubleItem* pPosValueItem; |
164 | 0 | if( (pPosValueItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_POSITION_VALUE)) || bZero ) |
165 | 0 | { |
166 | 0 | double fCrossover = 0.0; |
167 | 0 | if( !bZero ) |
168 | 0 | fCrossover = pPosValueItem->GetValue(); |
169 | 0 | if( m_bCrossingAxisIsCategoryAxis ) |
170 | 0 | m_xED_CrossesAtCategory->set_active( static_cast<sal_uInt16>(::rtl::math::round(fCrossover-1.0)) ); |
171 | 0 | else |
172 | 0 | { |
173 | 0 | Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter(); |
174 | 0 | rCrossFormatter.SetValue(fCrossover); |
175 | 0 | } |
176 | 0 | } |
177 | 0 | else |
178 | 0 | { |
179 | 0 | m_xED_CrossesAtCategory->set_active(-1); |
180 | 0 | m_xED_CrossesAt->set_text(u""_ustr); |
181 | 0 | } |
182 | 0 | } |
183 | 0 | else |
184 | 0 | { |
185 | 0 | m_xLB_CrossesAt->set_active(-1); |
186 | 0 | m_xED_CrossesAt->set_sensitive( false ); |
187 | 0 | } |
188 | | |
189 | | // shifted category position |
190 | 0 | const SfxBoolItem* pCatPosItem; |
191 | 0 | if (m_bSupportCategoryPositioning && (pCatPosItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION))) |
192 | 0 | { |
193 | 0 | if (pCatPosItem->GetValue()) |
194 | 0 | m_xRB_Between->set_active(true); |
195 | 0 | else |
196 | 0 | m_xRB_On->set_active(true); |
197 | 0 | } |
198 | 0 | else |
199 | 0 | m_xFL_Position->hide(); |
200 | | |
201 | | // Labels |
202 | 0 | if( const SfxInt32Item* pLabelPosItem = rInAttrs->GetItemIfSet( SCHATTR_AXIS_LABEL_POSITION, false) ) |
203 | 0 | { |
204 | 0 | sal_Int32 nPos = pLabelPosItem->GetValue(); |
205 | 0 | if( nPos < m_xLB_PlaceLabels->get_count() ) |
206 | 0 | m_xLB_PlaceLabels->set_active( nPos ); |
207 | 0 | } |
208 | 0 | else |
209 | 0 | m_xLB_PlaceLabels->set_active(-1); |
210 | 0 | PlaceLabelsSelectHdl( *m_xLB_PlaceLabels ); |
211 | | |
212 | | // Tick marks |
213 | 0 | sal_Int32 nTicks = 0, nMinorTicks = 0; |
214 | 0 | if (const SfxInt32Item* pTicksItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_TICKS)) |
215 | 0 | nTicks = pTicksItem->GetValue(); |
216 | 0 | if (const SfxInt32Item* pHelpTicksItem = rInAttrs->GetItemIfSet(SCHATTR_AXIS_HELPTICKS)) |
217 | 0 | nMinorTicks = pHelpTicksItem->GetValue(); |
218 | 0 | m_xCB_TicksInner->set_active(AFTicks::checkFlagFor(nTicks, AxisTicksAtr::Inner)); |
219 | 0 | m_xCB_TicksOuter->set_active(AFTicks::checkFlagFor(nTicks, AxisTicksAtr::Outer)); |
220 | 0 | m_xCB_MinorInner->set_active(AFTicks::checkFlagFor(nMinorTicks, AxisTicksAtr::Inner)); |
221 | 0 | m_xCB_MinorOuter->set_active(AFTicks::checkFlagFor(nMinorTicks, AxisTicksAtr::Outer)); |
222 | | |
223 | | // Tick position |
224 | 0 | if( const SfxInt32Item* pMarkPosItem = rInAttrs->GetItemIfSet( SCHATTR_AXIS_MARK_POSITION, false) ) |
225 | 0 | { |
226 | 0 | sal_Int32 nPos = pMarkPosItem->GetValue(); |
227 | 0 | if( nPos < m_xLB_PlaceTicks->get_count() ) |
228 | 0 | m_xLB_PlaceTicks->set_active( nPos ); |
229 | 0 | } |
230 | 0 | else |
231 | 0 | m_xLB_PlaceTicks->set_active(-1); |
232 | |
|
233 | 0 | if( !m_bSupportAxisPositioning ) |
234 | 0 | { |
235 | 0 | m_xFL_AxisLine->hide(); |
236 | 0 | m_xFL_Labels->hide(); |
237 | 0 | m_xBxPlaceTicks->hide(); |
238 | 0 | } |
239 | 0 | else if( !AxisHelper::isAxisPositioningEnabled() ) |
240 | 0 | { |
241 | 0 | m_xFL_AxisLine->set_sensitive(false); |
242 | 0 | m_xFL_Labels->set_sensitive(false); |
243 | 0 | m_xBxPlaceTicks->set_sensitive(false); |
244 | | //todo: maybe set a special help id to all those controls |
245 | 0 | } |
246 | 0 | } |
247 | | |
248 | | DeactivateRC AxisPositionsTabPage::DeactivatePage(SfxItemSet* pItemSet) |
249 | 0 | { |
250 | 0 | if( pItemSet ) |
251 | 0 | FillItemSet( pItemSet ); |
252 | |
|
253 | 0 | return DeactivateRC::LeavePage; |
254 | 0 | } |
255 | | |
256 | | void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter* pFormatter ) |
257 | 0 | { |
258 | 0 | m_pNumFormatter = pFormatter; |
259 | 0 | Formatter& rCrossFormatter = m_xED_CrossesAt->GetFormatter(); |
260 | 0 | rCrossFormatter.SetFormatter(m_pNumFormatter); |
261 | 0 | rCrossFormatter.UseInputStringForFormatting(); |
262 | |
|
263 | 0 | if( const SfxUInt32Item* pNumFormatItem = GetItemSet().GetItemIfSet(SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT) ) |
264 | 0 | { |
265 | 0 | sal_uInt32 nFmt = pNumFormatItem->GetValue(); |
266 | 0 | rCrossFormatter.SetFormatKey(nFmt); |
267 | 0 | } |
268 | 0 | } |
269 | | |
270 | | void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis ) |
271 | 0 | { |
272 | 0 | m_bCrossingAxisIsCategoryAxis = bCrossingAxisIsCategoryAxis; |
273 | 0 | } |
274 | | |
275 | | void AxisPositionsTabPage::SetCategories( const css::uno::Sequence< OUString >& rCategories ) |
276 | 0 | { |
277 | 0 | m_aCategories = rCategories; |
278 | 0 | } |
279 | | |
280 | | void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning ) |
281 | 0 | { |
282 | 0 | m_bSupportAxisPositioning = bSupportAxisPositioning; |
283 | 0 | } |
284 | | |
285 | | void AxisPositionsTabPage::SupportCategoryPositioning( bool bSupportCategoryPositioning ) |
286 | 0 | { |
287 | 0 | m_bSupportCategoryPositioning = bSupportCategoryPositioning; |
288 | 0 | } |
289 | | |
290 | | IMPL_LINK_NOARG(AxisPositionsTabPage, CrossesAtSelectHdl, weld::ComboBox&, void) |
291 | 0 | { |
292 | 0 | sal_Int32 nPos = m_xLB_CrossesAt->get_active(); |
293 | 0 | m_xED_CrossesAt->set_visible( (nPos==2) && !m_bCrossingAxisIsCategoryAxis ); |
294 | 0 | m_xED_CrossesAtCategory->set_visible( (nPos==2) && m_bCrossingAxisIsCategoryAxis ); |
295 | |
|
296 | 0 | if (m_xED_CrossesAt->get_text().isEmpty()) |
297 | 0 | m_xED_CrossesAt->GetFormatter().SetValue(0.0); |
298 | 0 | if (m_xED_CrossesAtCategory->get_active() == -1 && m_xED_CrossesAtCategory->get_count()) |
299 | 0 | m_xED_CrossesAtCategory->set_active(0); |
300 | |
|
301 | 0 | PlaceLabelsSelectHdl(*m_xLB_PlaceLabels); |
302 | 0 | } |
303 | | |
304 | | IMPL_LINK_NOARG(AxisPositionsTabPage, PlaceLabelsSelectHdl, weld::ComboBox&, void) |
305 | 0 | { |
306 | 0 | sal_Int32 nLabelPos = m_xLB_PlaceLabels->get_active(); |
307 | |
|
308 | 0 | bool bEnableTickmarkPlacement = (nLabelPos>1); |
309 | 0 | if( bEnableTickmarkPlacement ) |
310 | 0 | { |
311 | 0 | sal_Int32 nAxisPos = m_xLB_CrossesAt->get_active(); |
312 | 0 | if( nLabelPos-2 == nAxisPos ) |
313 | 0 | bEnableTickmarkPlacement=false; |
314 | 0 | } |
315 | 0 | m_xBxPlaceTicks->set_sensitive(bEnableTickmarkPlacement); |
316 | 0 | } |
317 | | |
318 | | } //namespace chart |
319 | | |
320 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |