1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "tp_AxisPositions.hxx"
22 #include <chartview/ChartSfxItemIds.hxx>
23 #include <AxisHelper.hxx>
25 #include <rtl/math.hxx>
26 #include <svx/chrtitem.hxx>
27 #include <svl/intitem.hxx>
28 #include <vcl/formatter.hxx>
30 using namespace ::com::sun::star
;
35 AxisPositionsTabPage::AxisPositionsTabPage(weld::Container
* pPage
, weld::DialogController
* pController
,const SfxItemSet
& rInAttrs
)
36 : SfxTabPage(pPage
, pController
, u
"modules/schart/ui/tp_AxisPositions.ui"_ustr
, u
"tp_AxisPositions"_ustr
, &rInAttrs
)
37 , m_pNumFormatter(nullptr)
38 , m_bCrossingAxisIsCategoryAxis(false)
39 , m_bSupportAxisPositioning(false)
40 , m_bSupportCategoryPositioning(false)
41 , m_xFL_AxisLine(m_xBuilder
->weld_frame(u
"FL_AXIS_LINE"_ustr
))
42 , m_xLB_CrossesAt(m_xBuilder
->weld_combo_box(u
"LB_CROSSES_OTHER_AXIS_AT"_ustr
))
43 , m_xED_CrossesAt(m_xBuilder
->weld_formatted_spin_button(u
"EDT_CROSSES_OTHER_AXIS_AT"_ustr
))
44 , m_xED_CrossesAtCategory(m_xBuilder
->weld_combo_box( u
"EDT_CROSSES_OTHER_AXIS_AT_CATEGORY"_ustr
))
45 , m_xFL_Position(m_xBuilder
->weld_frame(u
"FL_POSITION"_ustr
))
46 , m_xRB_On(m_xBuilder
->weld_radio_button(u
"RB_ON"_ustr
))
47 , m_xRB_Between(m_xBuilder
->weld_radio_button(u
"RB_BETWEEN"_ustr
))
48 , m_xFL_Labels(m_xBuilder
->weld_frame(u
"FL_LABELS"_ustr
))
49 , m_xLB_PlaceLabels(m_xBuilder
->weld_combo_box(u
"LB_PLACE_LABELS"_ustr
))
50 , m_xCB_TicksInner(m_xBuilder
->weld_check_button(u
"CB_TICKS_INNER"_ustr
))
51 , m_xCB_TicksOuter(m_xBuilder
->weld_check_button(u
"CB_TICKS_OUTER"_ustr
))
52 , m_xCB_MinorInner(m_xBuilder
->weld_check_button(u
"CB_MINOR_INNER"_ustr
))
53 , m_xCB_MinorOuter(m_xBuilder
->weld_check_button(u
"CB_MINOR_OUTER"_ustr
))
54 , m_xBxPlaceTicks(m_xBuilder
->weld_widget(u
"boxPLACE_TICKS"_ustr
))
55 , m_xLB_PlaceTicks(m_xBuilder
->weld_combo_box(u
"LB_PLACE_TICKS"_ustr
))
57 m_xLB_CrossesAt
->connect_changed(LINK(this, AxisPositionsTabPage
, CrossesAtSelectHdl
));
58 m_xLB_PlaceLabels
->connect_changed(LINK(this, AxisPositionsTabPage
, PlaceLabelsSelectHdl
));
60 Formatter
& rCrossFormatter
= m_xED_CrossesAt
->GetFormatter();
61 rCrossFormatter
.ClearMinValue();
62 rCrossFormatter
.ClearMaxValue();
63 Formatter
& rDistanceFormatter
= m_xED_CrossesAt
->GetFormatter();
64 rDistanceFormatter
.ClearMinValue();
65 rDistanceFormatter
.ClearMaxValue();
68 AxisPositionsTabPage::~AxisPositionsTabPage()
72 std::unique_ptr
<SfxTabPage
> AxisPositionsTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rOutAttrs
)
74 return std::make_unique
<AxisPositionsTabPage
>(pPage
, pController
, *rOutAttrs
);
77 bool AxisPositionsTabPage::FillItemSet(SfxItemSet
* rOutAttrs
)
80 sal_Int32 nPos
= m_xLB_CrossesAt
->get_active();
81 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_POSITION
, nPos
+1 ));
84 Formatter
& rCrossFormatter
= m_xED_CrossesAt
->GetFormatter();
85 double fCrossover
= rCrossFormatter
.GetValue();
86 if( m_bCrossingAxisIsCategoryAxis
)
87 fCrossover
= m_xED_CrossesAtCategory
->get_active()+1;
88 rOutAttrs
->Put(SvxDoubleItem(fCrossover
,SCHATTR_AXIS_POSITION_VALUE
));
91 // shifted category position
92 if (m_xFL_Position
->get_visible())
93 rOutAttrs
->Put(SfxBoolItem(SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION
, m_xRB_Between
->get_active()));
96 sal_Int32 nLabelPos
= m_xLB_PlaceLabels
->get_active();
98 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION
, nLabelPos
));
102 sal_Int32 nMinorTicks
=0;
104 if(m_xCB_MinorInner
->get_active())
105 nMinorTicks
|=CHAXIS_MARK_INNER
;
106 if(m_xCB_MinorOuter
->get_active())
107 nMinorTicks
|=CHAXIS_MARK_OUTER
;
108 if(m_xCB_TicksInner
->get_active())
109 nTicks
|=CHAXIS_MARK_INNER
;
110 if(m_xCB_TicksOuter
->get_active())
111 nTicks
|=CHAXIS_MARK_OUTER
;
113 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_TICKS
,nTicks
));
114 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS
,nMinorTicks
));
116 sal_Int32 nMarkPos
= m_xLB_PlaceTicks
->get_active();
118 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION
, nMarkPos
));
123 void AxisPositionsTabPage::Reset(const SfxItemSet
* rInAttrs
)
125 //init and enable controls
126 m_xED_CrossesAt
->set_visible( !m_bCrossingAxisIsCategoryAxis
);
127 m_xED_CrossesAtCategory
->set_visible( m_bCrossingAxisIsCategoryAxis
);
128 if (m_bCrossingAxisIsCategoryAxis
)
130 for (auto const& cat
: m_aCategories
)
131 m_xED_CrossesAtCategory
->append_text(cat
);
134 if( m_xLB_CrossesAt
->get_count() > 3 )
136 if( m_bCrossingAxisIsCategoryAxis
)
137 m_xLB_CrossesAt
->remove(2);
139 m_xLB_CrossesAt
->remove(3);
145 if(SfxInt32Item
const * pPositionItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_POSITION
))
148 sal_Int32 nPos
= pPositionItem
->GetValue();
158 if( nPos
< m_xLB_CrossesAt
->get_count() )
159 m_xLB_CrossesAt
->set_active( nPos
);
160 CrossesAtSelectHdl( *m_xLB_CrossesAt
);
162 const SvxDoubleItem
* pPosValueItem
;
163 if( (pPosValueItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_POSITION_VALUE
)) || bZero
)
165 double fCrossover
= 0.0;
167 fCrossover
= pPosValueItem
->GetValue();
168 if( m_bCrossingAxisIsCategoryAxis
)
169 m_xED_CrossesAtCategory
->set_active( static_cast<sal_uInt16
>(::rtl::math::round(fCrossover
-1.0)) );
172 Formatter
& rCrossFormatter
= m_xED_CrossesAt
->GetFormatter();
173 rCrossFormatter
.SetValue(fCrossover
);
178 m_xED_CrossesAtCategory
->set_active(-1);
179 m_xED_CrossesAt
->set_text(u
""_ustr
);
184 m_xLB_CrossesAt
->set_active(-1);
185 m_xED_CrossesAt
->set_sensitive( false );
188 // shifted category position
189 const SfxBoolItem
* pCatPosItem
;
190 if (m_bSupportCategoryPositioning
&& (pCatPosItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_SHIFTED_CATEGORY_POSITION
)))
192 if (pCatPosItem
->GetValue())
193 m_xRB_Between
->set_active(true);
195 m_xRB_On
->set_active(true);
198 m_xFL_Position
->hide();
201 if( const SfxInt32Item
* pLabelPosItem
= rInAttrs
->GetItemIfSet( SCHATTR_AXIS_LABEL_POSITION
, false) )
203 sal_Int32 nPos
= pLabelPosItem
->GetValue();
204 if( nPos
< m_xLB_PlaceLabels
->get_count() )
205 m_xLB_PlaceLabels
->set_active( nPos
);
208 m_xLB_PlaceLabels
->set_active(-1);
209 PlaceLabelsSelectHdl( *m_xLB_PlaceLabels
);
212 tools::Long nTicks
= 0, nMinorTicks
= 0;
213 if (const SfxInt32Item
* pTicksItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_TICKS
))
214 nTicks
= pTicksItem
->GetValue();
215 if (const SfxInt32Item
* pHelpTicksItem
= rInAttrs
->GetItemIfSet(SCHATTR_AXIS_HELPTICKS
))
216 nMinorTicks
= pHelpTicksItem
->GetValue();
218 m_xCB_TicksInner
->set_active(bool(nTicks
&CHAXIS_MARK_INNER
));
219 m_xCB_TicksOuter
->set_active(bool(nTicks
&CHAXIS_MARK_OUTER
));
220 m_xCB_MinorInner
->set_active(bool(nMinorTicks
&CHAXIS_MARK_INNER
));
221 m_xCB_MinorOuter
->set_active(bool(nMinorTicks
&CHAXIS_MARK_OUTER
));
224 if( const SfxInt32Item
* pMarkPosItem
= rInAttrs
->GetItemIfSet( SCHATTR_AXIS_MARK_POSITION
, false) )
226 sal_Int32 nPos
= pMarkPosItem
->GetValue();
227 if( nPos
< m_xLB_PlaceTicks
->get_count() )
228 m_xLB_PlaceTicks
->set_active( nPos
);
231 m_xLB_PlaceTicks
->set_active(-1);
233 if( !m_bSupportAxisPositioning
)
235 m_xFL_AxisLine
->hide();
236 m_xFL_Labels
->hide();
237 m_xBxPlaceTicks
->hide();
239 else if( !AxisHelper::isAxisPositioningEnabled() )
241 m_xFL_AxisLine
->set_sensitive(false);
242 m_xFL_Labels
->set_sensitive(false);
243 m_xBxPlaceTicks
->set_sensitive(false);
244 //todo: maybe set a special help id to all those controls
248 DeactivateRC
AxisPositionsTabPage::DeactivatePage(SfxItemSet
* pItemSet
)
251 FillItemSet( pItemSet
);
253 return DeactivateRC::LeavePage
;
256 void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter
* pFormatter
)
258 m_pNumFormatter
= pFormatter
;
259 Formatter
& rCrossFormatter
= m_xED_CrossesAt
->GetFormatter();
260 rCrossFormatter
.SetFormatter(m_pNumFormatter
);
261 rCrossFormatter
.UseInputStringForFormatting();
263 if( const SfxUInt32Item
* pNumFormatItem
= GetItemSet().GetItemIfSet(SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT
) )
265 sal_uInt32 nFmt
= pNumFormatItem
->GetValue();
266 rCrossFormatter
.SetFormatKey(nFmt
);
270 void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis
)
272 m_bCrossingAxisIsCategoryAxis
= bCrossingAxisIsCategoryAxis
;
275 void AxisPositionsTabPage::SetCategories( const css::uno::Sequence
< OUString
>& rCategories
)
277 m_aCategories
= rCategories
;
280 void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning
)
282 m_bSupportAxisPositioning
= bSupportAxisPositioning
;
285 void AxisPositionsTabPage::SupportCategoryPositioning( bool bSupportCategoryPositioning
)
287 m_bSupportCategoryPositioning
= bSupportCategoryPositioning
;
290 IMPL_LINK_NOARG(AxisPositionsTabPage
, CrossesAtSelectHdl
, weld::ComboBox
&, void)
292 sal_Int32 nPos
= m_xLB_CrossesAt
->get_active();
293 m_xED_CrossesAt
->set_visible( (nPos
==2) && !m_bCrossingAxisIsCategoryAxis
);
294 m_xED_CrossesAtCategory
->set_visible( (nPos
==2) && m_bCrossingAxisIsCategoryAxis
);
296 if (m_xED_CrossesAt
->get_text().isEmpty())
297 m_xED_CrossesAt
->GetFormatter().SetValue(0.0);
298 if (m_xED_CrossesAtCategory
->get_active() == -1 && m_xED_CrossesAtCategory
->get_count())
299 m_xED_CrossesAtCategory
->set_active(0);
301 PlaceLabelsSelectHdl(*m_xLB_PlaceLabels
);
304 IMPL_LINK_NOARG(AxisPositionsTabPage
, PlaceLabelsSelectHdl
, weld::ComboBox
&, void)
306 sal_Int32 nLabelPos
= m_xLB_PlaceLabels
->get_active();
308 bool bEnableTickmarkPlacement
= (nLabelPos
>1);
309 if( bEnableTickmarkPlacement
)
311 sal_Int32 nAxisPos
= m_xLB_CrossesAt
->get_active();
312 if( nLabelPos
-2 == nAxisPos
)
313 bEnableTickmarkPlacement
=false;
315 m_xBxPlaceTicks
->set_sensitive(bEnableTickmarkPlacement
);
320 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */