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 "TabPageIds.h"
23 #include <chartview/ChartSfxItemIds.hxx>
24 #include <AxisHelper.hxx>
26 #include <svx/svxids.hrc>
27 #include <rtl/math.hxx>
28 #include <svx/chrtitem.hxx>
29 #include <svl/eitem.hxx>
30 #include <svl/intitem.hxx>
31 #include <svl/zformat.hxx>
32 #include <svtools/controldims.hxx>
34 #include <com/sun/star/chart/ChartAxisPosition.hpp>
35 #include <com/sun/star/chart2/AxisType.hpp>
37 using namespace ::com::sun::star
;
42 AxisPositionsTabPage::AxisPositionsTabPage(vcl::Window
* pWindow
,const SfxItemSet
& rInAttrs
)
45 ,"modules/schart/ui/tp_AxisPositions.ui"
47 , m_pNumFormatter(nullptr)
48 , m_bCrossingAxisIsCategoryAxis(false)
50 , m_bSupportAxisPositioning(false)
52 get(m_pFL_AxisLine
, "FL_AXIS_LINE");
53 get(m_pLB_CrossesAt
,"LB_CROSSES_OTHER_AXIS_AT");
54 get(m_pED_CrossesAt
,"EDT_CROSSES_OTHER_AXIS_AT");
55 get(m_pED_CrossesAtCategory
, "EDT_CROSSES_OTHER_AXIS_AT_CATEGORY");
56 get(m_pCB_AxisBetweenCategories
, "CB_AXIS_BETWEEN_CATEGORIES");
58 get(m_pFL_Labels
, "FL_LABELS");
59 get(m_pLB_PlaceLabels
,"LB_PLACE_LABELS");
60 get(m_pED_LabelDistance
,"EDT_AXIS_LABEL_DISTANCE");
62 get(m_pCB_TicksInner
, "CB_TICKS_INNER");
63 get(m_pCB_TicksOuter
, "CB_TICKS_OUTER");
64 get(m_pCB_MinorInner
, "CB_MINOR_INNER");
65 get(m_pCB_MinorOuter
, "CB_MINOR_OUTER");
67 get(m_pBxPlaceTicks
, "boxPLACE_TICKS");
68 get(m_pLB_PlaceTicks
, "LB_PLACE_TICKS");
70 // these are not used/implemented
71 // get(m_pCB_MajorGrid, "CB_MAJOR_GRID");
72 // get(m_pPB_MajorGrid, "PB_MAJOR_GRID");
73 // get(m_pCB_MinorGrid, "CB_MINOR_GRID");
74 // get(m_pPB_MinorGrid, "PB_MINOR_GRID");
76 m_pLB_CrossesAt
->SetSelectHdl( LINK( this, AxisPositionsTabPage
, CrossesAtSelectHdl
) );
77 m_pLB_CrossesAt
->SetDropDownLineCount( m_pLB_CrossesAt
->GetEntryCount() );
79 m_pLB_PlaceLabels
->SetSelectHdl( LINK( this, AxisPositionsTabPage
, PlaceLabelsSelectHdl
) );
80 m_pLB_PlaceLabels
->SetDropDownLineCount( m_pLB_PlaceLabels
->GetEntryCount() );
81 m_pLB_PlaceTicks
->SetDropDownLineCount( m_pLB_PlaceTicks
->GetEntryCount() );
84 AxisPositionsTabPage::~AxisPositionsTabPage()
89 void AxisPositionsTabPage::dispose()
91 m_pFL_AxisLine
.clear();
92 m_pLB_CrossesAt
.clear();
93 m_pED_CrossesAt
.clear();
94 m_pED_CrossesAtCategory
.clear();
95 m_pCB_AxisBetweenCategories
.clear();
97 m_pLB_PlaceLabels
.clear();
98 m_pED_LabelDistance
.clear();
99 m_pCB_TicksInner
.clear();
100 m_pCB_TicksOuter
.clear();
101 m_pCB_MinorInner
.clear();
102 m_pCB_MinorOuter
.clear();
103 m_pBxPlaceTicks
.clear();
104 m_pLB_PlaceTicks
.clear();
105 SfxTabPage::dispose();
108 VclPtr
<SfxTabPage
> AxisPositionsTabPage::Create(TabPageParent pWindow
,const SfxItemSet
* rOutAttrs
)
110 return VclPtr
<AxisPositionsTabPage
>::Create(pWindow
.pParent
, *rOutAttrs
);
113 bool AxisPositionsTabPage::FillItemSet(SfxItemSet
* rOutAttrs
)
116 sal_Int32 nPos
= m_pLB_CrossesAt
->GetSelectedEntryPos();
117 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_POSITION
, nPos
+1 ));
120 double fCrossover
= m_pED_CrossesAt
->GetValue();
121 if( m_bCrossingAxisIsCategoryAxis
)
122 fCrossover
= m_pED_CrossesAtCategory
->GetSelectedEntryPos()+1;
123 rOutAttrs
->Put(SvxDoubleItem(fCrossover
,SCHATTR_AXIS_POSITION_VALUE
));
127 sal_Int32 nLabelPos
= m_pLB_PlaceLabels
->GetSelectedEntryPos();
128 if( nLabelPos
!= LISTBOX_ENTRY_NOTFOUND
)
129 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION
, nLabelPos
));
135 if(m_pCB_MinorInner
->IsChecked())
136 nMinorTicks
|=CHAXIS_MARK_INNER
;
137 if(m_pCB_MinorOuter
->IsChecked())
138 nMinorTicks
|=CHAXIS_MARK_OUTER
;
139 if(m_pCB_TicksInner
->IsChecked())
140 nTicks
|=CHAXIS_MARK_INNER
;
141 if(m_pCB_TicksOuter
->IsChecked())
142 nTicks
|=CHAXIS_MARK_OUTER
;
144 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_TICKS
,nTicks
));
145 rOutAttrs
->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS
,nMinorTicks
));
147 sal_Int32 nMarkPos
= m_pLB_PlaceTicks
->GetSelectedEntryPos();
148 if( nMarkPos
!= LISTBOX_ENTRY_NOTFOUND
)
149 rOutAttrs
->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION
, nMarkPos
));
154 void AxisPositionsTabPage::Reset(const SfxItemSet
* rInAttrs
)
156 //init and enable controls
157 m_pED_CrossesAt
->Show( !m_bCrossingAxisIsCategoryAxis
);
158 m_pED_CrossesAtCategory
->Show( m_bCrossingAxisIsCategoryAxis
);
159 const sal_Int32 nMaxCount
= LISTBOX_ENTRY_NOTFOUND
;
160 if( m_bCrossingAxisIsCategoryAxis
)
162 for( sal_Int32 nN
=0; nN
<m_aCategories
.getLength() && nN
<nMaxCount
; nN
++ )
163 m_pED_CrossesAtCategory
->InsertEntry( m_aCategories
[nN
] );
165 sal_Int32 nCount
= m_pED_CrossesAtCategory
->GetEntryCount();
168 m_pED_CrossesAtCategory
->SetDropDownLineCount( nCount
);
171 if( m_pLB_CrossesAt
->GetEntryCount() > 3 )
173 if( m_bCrossingAxisIsCategoryAxis
)
174 m_pLB_CrossesAt
->RemoveEntry(2);
176 m_pLB_CrossesAt
->RemoveEntry(3);
180 const SfxPoolItem
*pPoolItem
= nullptr;
183 if(rInAttrs
->GetItemState(SCHATTR_AXIS_POSITION
,true, &pPoolItem
)== SfxItemState::SET
)
186 sal_Int32 nPos
= static_cast< const SfxInt32Item
* >( pPoolItem
)->GetValue();
196 if( nPos
< m_pLB_CrossesAt
->GetEntryCount() )
197 m_pLB_CrossesAt
->SelectEntryPos( nPos
);
198 CrossesAtSelectHdl( *m_pLB_CrossesAt
);
200 if( rInAttrs
->GetItemState(SCHATTR_AXIS_POSITION_VALUE
,true, &pPoolItem
)== SfxItemState::SET
|| bZero
)
202 double fCrossover
= 0.0;
204 fCrossover
= static_cast<const SvxDoubleItem
*>(pPoolItem
)->GetValue();
205 if( m_bCrossingAxisIsCategoryAxis
)
206 m_pED_CrossesAtCategory
->SelectEntryPos( static_cast<sal_uInt16
>(::rtl::math::round(fCrossover
-1.0)) );
208 m_pED_CrossesAt
->SetValue(fCrossover
);
212 m_pED_CrossesAtCategory
->SetNoSelection();
213 m_pED_CrossesAt
->SetTextValue("");
218 m_pLB_CrossesAt
->SetNoSelection();
219 m_pED_CrossesAt
->Enable( false );
223 if( rInAttrs
->GetItemState( SCHATTR_AXIS_LABEL_POSITION
, false, &pPoolItem
) == SfxItemState::SET
)
225 sal_Int32 nPos
= static_cast< const SfxInt32Item
* >( pPoolItem
)->GetValue();
226 if( nPos
< m_pLB_PlaceLabels
->GetEntryCount() )
227 m_pLB_PlaceLabels
->SelectEntryPos( nPos
);
230 m_pLB_PlaceLabels
->SetNoSelection();
231 PlaceLabelsSelectHdl( *m_pLB_PlaceLabels
);
234 long nTicks
= 0, nMinorTicks
= 0;
235 if(rInAttrs
->GetItemState(SCHATTR_AXIS_TICKS
,true, &pPoolItem
)== SfxItemState::SET
)
236 nTicks
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
237 if(rInAttrs
->GetItemState(SCHATTR_AXIS_HELPTICKS
,true, &pPoolItem
)== SfxItemState::SET
)
238 nMinorTicks
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
240 m_pCB_TicksInner
->Check(bool(nTicks
&CHAXIS_MARK_INNER
));
241 m_pCB_TicksOuter
->Check(bool(nTicks
&CHAXIS_MARK_OUTER
));
242 m_pCB_MinorInner
->Check(bool(nMinorTicks
&CHAXIS_MARK_INNER
));
243 m_pCB_MinorOuter
->Check(bool(nMinorTicks
&CHAXIS_MARK_OUTER
));
246 if( rInAttrs
->GetItemState( SCHATTR_AXIS_MARK_POSITION
, false, &pPoolItem
) == SfxItemState::SET
)
248 sal_Int32 nPos
= static_cast< const SfxInt32Item
* >( pPoolItem
)->GetValue();
249 if( nPos
< m_pLB_PlaceTicks
->GetEntryCount() )
250 m_pLB_PlaceTicks
->SelectEntryPos( nPos
);
253 m_pLB_PlaceTicks
->SetNoSelection();
255 if( !m_bSupportAxisPositioning
)
257 m_pFL_AxisLine
->Show(false);
259 m_pFL_Labels
->Show(false);
261 m_pBxPlaceTicks
->Show(false);
263 else if( !AxisHelper::isAxisPositioningEnabled() )
266 m_pFL_AxisLine
->Enable(false);
268 m_pFL_Labels
->Enable(false);
270 m_pBxPlaceTicks
->Enable(false);
272 //todo: maybe set a special help id to all those controls
276 DeactivateRC
AxisPositionsTabPage::DeactivatePage(SfxItemSet
* pItemSet
)
279 FillItemSet( pItemSet
);
281 return DeactivateRC::LeavePage
;
284 void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter
* pFormatter
)
286 m_pNumFormatter
= pFormatter
;
287 m_pED_CrossesAt
->SetFormatter( m_pNumFormatter
);
288 m_pED_CrossesAt
->UseInputStringForFormatting();
290 const SfxPoolItem
*pPoolItem
= nullptr;
291 if( GetItemSet().GetItemState( SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT
, true, &pPoolItem
) == SfxItemState::SET
)
293 sal_uLong nFmt
= static_cast<sal_uLong
>(static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue());
294 m_pED_CrossesAt
->SetFormatKey( nFmt
);
298 void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis
)
300 m_bCrossingAxisIsCategoryAxis
= bCrossingAxisIsCategoryAxis
;
303 void AxisPositionsTabPage::SetCategories( const css::uno::Sequence
< OUString
>& rCategories
)
305 m_aCategories
= rCategories
;
308 void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning
)
310 m_bSupportAxisPositioning
= bSupportAxisPositioning
;
313 IMPL_LINK_NOARG(AxisPositionsTabPage
, CrossesAtSelectHdl
, ListBox
&, void)
315 sal_Int32 nPos
= m_pLB_CrossesAt
->GetSelectedEntryPos();
316 m_pED_CrossesAt
->Show( (nPos
==2) && !m_bCrossingAxisIsCategoryAxis
);
317 m_pED_CrossesAtCategory
->Show( (nPos
==2) && m_bCrossingAxisIsCategoryAxis
);
319 if( m_pED_CrossesAt
->GetText().isEmpty() )
320 m_pED_CrossesAt
->SetValue(0.0);
321 if( m_pED_CrossesAtCategory
->GetSelectedEntryCount() == 0 )
322 m_pED_CrossesAtCategory
->SelectEntryPos(0);
324 PlaceLabelsSelectHdl( *m_pLB_PlaceLabels
);
327 IMPL_LINK_NOARG(AxisPositionsTabPage
, PlaceLabelsSelectHdl
, ListBox
&, void)
329 sal_Int32 nLabelPos
= m_pLB_PlaceLabels
->GetSelectedEntryPos();
331 bool bEnableTickmarkPlacement
= (nLabelPos
>1);
332 if( bEnableTickmarkPlacement
)
334 sal_Int32 nAxisPos
= m_pLB_CrossesAt
->GetSelectedEntryPos();
335 if( nLabelPos
-2 == nAxisPos
)
336 bEnableTickmarkPlacement
=false;
338 m_pBxPlaceTicks
->Enable(bEnableTickmarkPlacement
);
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */