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>
29 using namespace ::com::sun::star
;
34 AxisPositionsTabPage::AxisPositionsTabPage(weld::Container
* pPage
, weld::DialogController
* pController
,const SfxItemSet
& rInAttrs
)
35 : SfxTabPage(pPage
, pController
, "modules/schart/ui/tp_AxisPositions.ui", "tp_AxisPositions", &rInAttrs
)
36 , m_pNumFormatter(nullptr)
37 , m_bCrossingAxisIsCategoryAxis(false)
39 , m_bSupportAxisPositioning(false)
40 , m_xFL_AxisLine(m_xBuilder
->weld_frame("FL_AXIS_LINE"))
41 , m_xLB_CrossesAt(m_xBuilder
->weld_combo_box("LB_CROSSES_OTHER_AXIS_AT"))
42 , m_xED_CrossesAt(m_xBuilder
->weld_formatted_spin_button("EDT_CROSSES_OTHER_AXIS_AT"))
43 , m_xED_CrossesAtCategory(m_xBuilder
->weld_combo_box( "EDT_CROSSES_OTHER_AXIS_AT_CATEGORY"))
44 , m_xCB_AxisBetweenCategories(m_xBuilder
->weld_check_button("CB_AXIS_BETWEEN_CATEGORIES"))
45 , m_xFL_Labels(m_xBuilder
->weld_frame("FL_LABELS"))
46 , m_xLB_PlaceLabels(m_xBuilder
->weld_combo_box("LB_PLACE_LABELS"))
47 , m_xED_LabelDistance(m_xBuilder
->weld_formatted_spin_button("EDT_AXIS_LABEL_DISTANCE"))
48 , m_xCB_TicksInner(m_xBuilder
->weld_check_button("CB_TICKS_INNER"))
49 , m_xCB_TicksOuter(m_xBuilder
->weld_check_button("CB_TICKS_OUTER"))
50 , m_xCB_MinorInner(m_xBuilder
->weld_check_button("CB_MINOR_INNER"))
51 , m_xCB_MinorOuter(m_xBuilder
->weld_check_button("CB_MINOR_OUTER"))
52 , m_xBxPlaceTicks(m_xBuilder
->weld_widget("boxPLACE_TICKS"))
53 , m_xLB_PlaceTicks(m_xBuilder
->weld_combo_box("LB_PLACE_TICKS"))
55 m_xLB_CrossesAt
->connect_changed(LINK(this, AxisPositionsTabPage
, CrossesAtSelectHdl
));
56 m_xLB_PlaceLabels
->connect_changed(LINK(this, AxisPositionsTabPage
, PlaceLabelsSelectHdl
));
58 const double nMin
= static_cast<double>(SAL_MIN_INT64
);
59 const double nMax
= static_cast<double>(SAL_MAX_INT64
);
60 m_xED_CrossesAt
->set_range(nMin
, nMax
);
61 m_xED_LabelDistance
->set_range(nMin
, nMax
);
64 AxisPositionsTabPage::~AxisPositionsTabPage()
68 std::unique_ptr
<SfxTabPage
> AxisPositionsTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
* rOutAttrs
)
70 return std::make_unique
<AxisPositionsTabPage
>(pPage
, pController
, *rOutAttrs
);
73 bool AxisPositionsTabPage::FillItemSet(SfxItemSet
* rOutAttrs
)
76 sal_Int32 nPos
= m_xLB_CrossesAt
->get_active();
77 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_POSITION
, nPos
+1 ));
80 double fCrossover
= m_xED_CrossesAt
->get_value();
81 if( m_bCrossingAxisIsCategoryAxis
)
82 fCrossover
= m_xED_CrossesAtCategory
->get_active()+1;
83 rOutAttrs
->Put(SvxDoubleItem(fCrossover
,SCHATTR_AXIS_POSITION_VALUE
));
87 sal_Int32 nLabelPos
= m_xLB_PlaceLabels
->get_active();
89 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION
, nLabelPos
));
95 if(m_xCB_MinorInner
->get_active())
96 nMinorTicks
|=CHAXIS_MARK_INNER
;
97 if(m_xCB_MinorOuter
->get_active())
98 nMinorTicks
|=CHAXIS_MARK_OUTER
;
99 if(m_xCB_TicksInner
->get_active())
100 nTicks
|=CHAXIS_MARK_INNER
;
101 if(m_xCB_TicksOuter
->get_active())
102 nTicks
|=CHAXIS_MARK_OUTER
;
104 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_TICKS
,nTicks
));
105 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS
,nMinorTicks
));
107 sal_Int32 nMarkPos
= m_xLB_PlaceTicks
->get_active();
109 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION
, nMarkPos
));
114 void AxisPositionsTabPage::Reset(const SfxItemSet
* rInAttrs
)
116 //init and enable controls
117 m_xED_CrossesAt
->set_visible( !m_bCrossingAxisIsCategoryAxis
);
118 m_xED_CrossesAtCategory
->set_visible( m_bCrossingAxisIsCategoryAxis
);
119 if (m_bCrossingAxisIsCategoryAxis
)
121 for( sal_Int32 nN
=0; nN
<m_aCategories
.getLength(); nN
++ )
122 m_xED_CrossesAtCategory
->append_text(m_aCategories
[nN
]);
124 sal_Int32 nCount
= m_xED_CrossesAtCategory
->get_count();
129 if( m_xLB_CrossesAt
->get_count() > 3 )
131 if( m_bCrossingAxisIsCategoryAxis
)
132 m_xLB_CrossesAt
->remove(2);
134 m_xLB_CrossesAt
->remove(3);
138 const SfxPoolItem
*pPoolItem
= nullptr;
141 if(rInAttrs
->GetItemState(SCHATTR_AXIS_POSITION
,true, &pPoolItem
)== SfxItemState::SET
)
144 sal_Int32 nPos
= static_cast< const SfxInt32Item
* >( pPoolItem
)->GetValue();
154 if( nPos
< m_xLB_CrossesAt
->get_count() )
155 m_xLB_CrossesAt
->set_active( nPos
);
156 CrossesAtSelectHdl( *m_xLB_CrossesAt
);
158 if( rInAttrs
->GetItemState(SCHATTR_AXIS_POSITION_VALUE
,true, &pPoolItem
)== SfxItemState::SET
|| bZero
)
160 double fCrossover
= 0.0;
162 fCrossover
= static_cast<const SvxDoubleItem
*>(pPoolItem
)->GetValue();
163 if( m_bCrossingAxisIsCategoryAxis
)
164 m_xED_CrossesAtCategory
->set_active( static_cast<sal_uInt16
>(::rtl::math::round(fCrossover
-1.0)) );
166 m_xED_CrossesAt
->set_value(fCrossover
);
170 m_xED_CrossesAtCategory
->set_active(-1);
171 m_xED_CrossesAt
->set_text("");
176 m_xLB_CrossesAt
->set_active(-1);
177 m_xED_CrossesAt
->set_sensitive( false );
181 if( rInAttrs
->GetItemState( SCHATTR_AXIS_LABEL_POSITION
, false, &pPoolItem
) == SfxItemState::SET
)
183 sal_Int32 nPos
= static_cast< const SfxInt32Item
* >( pPoolItem
)->GetValue();
184 if( nPos
< m_xLB_PlaceLabels
->get_count() )
185 m_xLB_PlaceLabels
->set_active( nPos
);
188 m_xLB_PlaceLabels
->set_active(-1);
189 PlaceLabelsSelectHdl( *m_xLB_PlaceLabels
);
192 long nTicks
= 0, nMinorTicks
= 0;
193 if (rInAttrs
->GetItemState(SCHATTR_AXIS_TICKS
,true, &pPoolItem
)== SfxItemState::SET
)
194 nTicks
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
195 if (rInAttrs
->GetItemState(SCHATTR_AXIS_HELPTICKS
,true, &pPoolItem
)== SfxItemState::SET
)
196 nMinorTicks
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
198 m_xCB_TicksInner
->set_active(bool(nTicks
&CHAXIS_MARK_INNER
));
199 m_xCB_TicksOuter
->set_active(bool(nTicks
&CHAXIS_MARK_OUTER
));
200 m_xCB_MinorInner
->set_active(bool(nMinorTicks
&CHAXIS_MARK_INNER
));
201 m_xCB_MinorOuter
->set_active(bool(nMinorTicks
&CHAXIS_MARK_OUTER
));
204 if( rInAttrs
->GetItemState( SCHATTR_AXIS_MARK_POSITION
, false, &pPoolItem
) == SfxItemState::SET
)
206 sal_Int32 nPos
= static_cast< const SfxInt32Item
* >( pPoolItem
)->GetValue();
207 if( nPos
< m_xLB_PlaceTicks
->get_count() )
208 m_xLB_PlaceTicks
->set_active( nPos
);
211 m_xLB_PlaceTicks
->set_active(-1);
213 if( !m_bSupportAxisPositioning
)
215 m_xFL_AxisLine
->hide();
216 m_xFL_Labels
->hide();
217 m_xBxPlaceTicks
->hide();
219 else if( !AxisHelper::isAxisPositioningEnabled() )
221 m_xFL_AxisLine
->set_sensitive(false);
222 m_xFL_Labels
->set_sensitive(false);
223 m_xBxPlaceTicks
->set_sensitive(false);
224 //todo: maybe set a special help id to all those controls
228 DeactivateRC
AxisPositionsTabPage::DeactivatePage(SfxItemSet
* pItemSet
)
231 FillItemSet( pItemSet
);
233 return DeactivateRC::LeavePage
;
236 void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter
* pFormatter
)
238 m_pNumFormatter
= pFormatter
;
239 m_xED_CrossesAt
->set_formatter(m_pNumFormatter
);
241 const SfxPoolItem
*pPoolItem
= nullptr;
242 if( GetItemSet().GetItemState( SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT
, true, &pPoolItem
) == SfxItemState::SET
)
244 sal_uLong nFmt
= static_cast<const SfxUInt32Item
*>(pPoolItem
)->GetValue();
245 m_xED_CrossesAt
->set_format_key( nFmt
);
249 void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis
)
251 m_bCrossingAxisIsCategoryAxis
= bCrossingAxisIsCategoryAxis
;
254 void AxisPositionsTabPage::SetCategories( const css::uno::Sequence
< OUString
>& rCategories
)
256 m_aCategories
= rCategories
;
259 void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning
)
261 m_bSupportAxisPositioning
= bSupportAxisPositioning
;
264 IMPL_LINK_NOARG(AxisPositionsTabPage
, CrossesAtSelectHdl
, weld::ComboBox
&, void)
266 sal_Int32 nPos
= m_xLB_CrossesAt
->get_active();
267 m_xED_CrossesAt
->set_visible( (nPos
==2) && !m_bCrossingAxisIsCategoryAxis
);
268 m_xED_CrossesAtCategory
->set_visible( (nPos
==2) && m_bCrossingAxisIsCategoryAxis
);
270 if (m_xED_CrossesAt
->get_text().isEmpty())
271 m_xED_CrossesAt
->set_value(0.0);
272 if (m_xED_CrossesAtCategory
->get_active() == -1)
273 m_xED_CrossesAtCategory
->set_active(0);
275 PlaceLabelsSelectHdl(*m_xLB_PlaceLabels
);
278 IMPL_LINK_NOARG(AxisPositionsTabPage
, PlaceLabelsSelectHdl
, weld::ComboBox
&, void)
280 sal_Int32 nLabelPos
= m_xLB_PlaceLabels
->get_active();
282 bool bEnableTickmarkPlacement
= (nLabelPos
>1);
283 if( bEnableTickmarkPlacement
)
285 sal_Int32 nAxisPos
= m_xLB_CrossesAt
->get_active();
286 if( nLabelPos
-2 == nAxisPos
)
287 bEnableTickmarkPlacement
=false;
289 m_xBxPlaceTicks
->set_sensitive(bEnableTickmarkPlacement
);
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */