fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / dialogs / tp_AxisPositions.cxx
blob83fa72fa21f1293a7f21f3749f68beee1ee9bc2c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "ResId.hxx"
23 #include "ResourceIds.hrc"
24 #include "Strings.hrc"
25 #include "chartview/ChartSfxItemIds.hxx"
26 #include "AxisHelper.hxx"
28 #include <svx/svxids.hrc>
29 #include <rtl/math.hxx>
30 #include <svx/chrtitem.hxx>
31 #include <svl/eitem.hxx>
32 #include <svl/intitem.hxx>
33 #include <vcl/msgbox.hxx>
34 #include <svl/zformat.hxx>
35 #include <svtools/controldims.hrc>
37 #include <com/sun/star/chart/ChartAxisPosition.hpp>
38 #include <com/sun/star/chart2/AxisType.hpp>
40 using namespace ::com::sun::star;
42 namespace chart
45 AxisPositionsTabPage::AxisPositionsTabPage(vcl::Window* pWindow,const SfxItemSet& rInAttrs)
46 : SfxTabPage(pWindow
47 ,"tp_AxisPositions"
48 ,"modules/schart/ui/tp_AxisPositions.ui"
49 , &rInAttrs)
50 , m_pNumFormatter(NULL)
51 , m_bCrossingAxisIsCategoryAxis(false)
52 , m_aCategories()
53 , m_bSupportAxisPositioning(false)
55 get(m_pFL_AxisLine, "FL_AXIS_LINE");
56 get(m_pLB_CrossesAt,"LB_CROSSES_OTHER_AXIS_AT");
57 get(m_pED_CrossesAt,"EDT_CROSSES_OTHER_AXIS_AT");
58 get(m_pED_CrossesAtCategory, "EDT_CROSSES_OTHER_AXIS_AT_CATEGORY");
59 get(m_pCB_AxisBetweenCategories, "CB_AXIS_BETWEEN_CATEGORIES");
61 get(m_pFL_Labels, "FL_LABELS");
62 get(m_pLB_PlaceLabels,"LB_PLACE_LABELS");
63 get(m_pED_LabelDistance,"EDT_AXIS_LABEL_DISTANCE");
65 get(m_pCB_TicksInner, "CB_TICKS_INNER");
66 get(m_pCB_TicksOuter, "CB_TICKS_OUTER");
67 get(m_pCB_MinorInner, "CB_MINOR_INNER");
68 get(m_pCB_MinorOuter, "CB_MINOR_OUTER");
70 get(m_pBxPlaceTicks, "boxPLACE_TICKS");
71 get(m_pLB_PlaceTicks, "LB_PLACE_TICKS");
73 // these are not used/implemented
74 // get(m_pCB_MajorGrid, "CB_MAJOR_GRID");
75 // get(m_pPB_MajorGrid, "PB_MAJOR_GRID");
76 // get(m_pCB_MinorGrid, "CB_MINOR_GRID");
77 // get(m_pPB_MinorGrid, "PB_MINOR_GRID");
79 m_pLB_CrossesAt->SetSelectHdl( LINK( this, AxisPositionsTabPage, CrossesAtSelectHdl ) );
80 m_pLB_CrossesAt->SetDropDownLineCount( m_pLB_CrossesAt->GetEntryCount() );
82 m_pLB_PlaceLabels->SetSelectHdl( LINK( this, AxisPositionsTabPage, PlaceLabelsSelectHdl ) );
83 m_pLB_PlaceLabels->SetDropDownLineCount( m_pLB_PlaceLabels->GetEntryCount() );
84 m_pLB_PlaceTicks->SetDropDownLineCount( m_pLB_PlaceTicks->GetEntryCount() );
87 AxisPositionsTabPage::~AxisPositionsTabPage()
89 disposeOnce();
92 void AxisPositionsTabPage::dispose()
94 m_pFL_AxisLine.clear();
95 m_pLB_CrossesAt.clear();
96 m_pED_CrossesAt.clear();
97 m_pED_CrossesAtCategory.clear();
98 m_pCB_AxisBetweenCategories.clear();
99 m_pFL_Labels.clear();
100 m_pLB_PlaceLabels.clear();
101 m_pED_LabelDistance.clear();
102 m_pCB_TicksInner.clear();
103 m_pCB_TicksOuter.clear();
104 m_pCB_MinorInner.clear();
105 m_pCB_MinorOuter.clear();
106 m_pBxPlaceTicks.clear();
107 m_pLB_PlaceTicks.clear();
108 SfxTabPage::dispose();
111 VclPtr<SfxTabPage> AxisPositionsTabPage::Create(vcl::Window* pWindow,const SfxItemSet* rOutAttrs)
113 return VclPtr<AxisPositionsTabPage>::Create(pWindow, *rOutAttrs);
116 bool AxisPositionsTabPage::FillItemSet(SfxItemSet* rOutAttrs)
118 // axis line
119 sal_Int32 nPos = m_pLB_CrossesAt->GetSelectEntryPos();
120 rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_POSITION, nPos+1 ));
121 if( 2==nPos )
123 double fCrossover = m_pED_CrossesAt->GetValue();
124 if( m_bCrossingAxisIsCategoryAxis )
125 fCrossover = m_pED_CrossesAtCategory->GetSelectEntryPos()+1;
126 rOutAttrs->Put(SvxDoubleItem(fCrossover,SCHATTR_AXIS_POSITION_VALUE));
129 // labels
130 sal_Int32 nLabelPos = m_pLB_PlaceLabels->GetSelectEntryPos();
131 if( nLabelPos != LISTBOX_ENTRY_NOTFOUND )
132 rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION, nLabelPos ));
134 // tick marks
135 long nTicks=0;
136 long nMinorTicks=0;
138 if(m_pCB_MinorInner->IsChecked())
139 nMinorTicks|=CHAXIS_MARK_INNER;
140 if(m_pCB_MinorOuter->IsChecked())
141 nMinorTicks|=CHAXIS_MARK_OUTER;
142 if(m_pCB_TicksInner->IsChecked())
143 nTicks|=CHAXIS_MARK_INNER;
144 if(m_pCB_TicksOuter->IsChecked())
145 nTicks|=CHAXIS_MARK_OUTER;
147 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_TICKS,nTicks));
148 rOutAttrs->Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS,nMinorTicks));
150 sal_Int32 nMarkPos = m_pLB_PlaceTicks->GetSelectEntryPos();
151 if( nMarkPos != LISTBOX_ENTRY_NOTFOUND )
152 rOutAttrs->Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION, nMarkPos ));
154 return true;
157 void AxisPositionsTabPage::Reset(const SfxItemSet* rInAttrs)
159 //init and enable controls
160 m_pED_CrossesAt->Show( !m_bCrossingAxisIsCategoryAxis );
161 m_pED_CrossesAtCategory->Show( m_bCrossingAxisIsCategoryAxis );
162 const sal_Int32 nMaxCount = LISTBOX_ENTRY_NOTFOUND;
163 if( m_bCrossingAxisIsCategoryAxis )
165 for( sal_Int32 nN=0; nN<m_aCategories.getLength() && nN<nMaxCount; nN++ )
166 m_pED_CrossesAtCategory->InsertEntry( m_aCategories[nN] );
168 sal_uInt16 nCount = m_pED_CrossesAtCategory->GetEntryCount();
169 if( nCount>30 )
170 nCount=30;
171 m_pED_CrossesAtCategory->SetDropDownLineCount( nCount );
174 if( m_pLB_CrossesAt->GetEntryCount() > 3 )
176 if( m_bCrossingAxisIsCategoryAxis )
177 m_pLB_CrossesAt->RemoveEntry(2);
178 else
179 m_pLB_CrossesAt->RemoveEntry(3);
182 //fill controls
183 const SfxPoolItem *pPoolItem = NULL;
185 //axis line
186 if(rInAttrs->GetItemState(SCHATTR_AXIS_POSITION,true, &pPoolItem)== SfxItemState::SET)
188 bool bZero = false;
189 sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
190 if(nPos==0)
192 //switch to value
193 bZero = true;
194 nPos = 2;
196 else
197 nPos--;
199 if( nPos < m_pLB_CrossesAt->GetEntryCount() )
200 m_pLB_CrossesAt->SelectEntryPos( nPos );
201 CrossesAtSelectHdl( (void*)0 );
203 if( rInAttrs->GetItemState(SCHATTR_AXIS_POSITION_VALUE,true, &pPoolItem)== SfxItemState::SET || bZero )
205 double fCrossover = 0.0;
206 if( !bZero )
207 fCrossover = static_cast<const SvxDoubleItem*>(pPoolItem)->GetValue();
208 if( m_bCrossingAxisIsCategoryAxis )
209 m_pED_CrossesAtCategory->SelectEntryPos( static_cast<sal_uInt16>(::rtl::math::round(fCrossover-1.0)) );
210 else
211 m_pED_CrossesAt->SetValue(fCrossover);
213 else
215 m_pED_CrossesAtCategory->SetNoSelection();
216 m_pED_CrossesAt->SetTextValue("");
219 else
221 m_pLB_CrossesAt->SetNoSelection();
222 m_pED_CrossesAt->Enable( false );
225 // Labels
226 if( rInAttrs->GetItemState( SCHATTR_AXIS_LABEL_POSITION, false, &pPoolItem ) == SfxItemState::SET )
228 sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
229 if( nPos < m_pLB_PlaceLabels->GetEntryCount() )
230 m_pLB_PlaceLabels->SelectEntryPos( nPos );
232 else
233 m_pLB_PlaceLabels->SetNoSelection();
234 PlaceLabelsSelectHdl( (void*)0 );
236 // Tick marks
237 long nTicks = 0, nMinorTicks = 0;
238 if(rInAttrs->GetItemState(SCHATTR_AXIS_TICKS,true, &pPoolItem)== SfxItemState::SET)
239 nTicks = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
240 if(rInAttrs->GetItemState(SCHATTR_AXIS_HELPTICKS,true, &pPoolItem)== SfxItemState::SET)
241 nMinorTicks = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
243 m_pCB_TicksInner->Check(bool(nTicks&CHAXIS_MARK_INNER));
244 m_pCB_TicksOuter->Check(bool(nTicks&CHAXIS_MARK_OUTER));
245 m_pCB_MinorInner->Check(bool(nMinorTicks&CHAXIS_MARK_INNER));
246 m_pCB_MinorOuter->Check(bool(nMinorTicks&CHAXIS_MARK_OUTER));
248 // Tick position
249 if( rInAttrs->GetItemState( SCHATTR_AXIS_MARK_POSITION, false, &pPoolItem ) == SfxItemState::SET )
251 sal_Int32 nPos = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
252 if( nPos < m_pLB_PlaceTicks->GetEntryCount() )
253 m_pLB_PlaceTicks->SelectEntryPos( nPos );
255 else
256 m_pLB_PlaceTicks->SetNoSelection();
258 if( !m_bSupportAxisPositioning )
260 m_pFL_AxisLine->Show(false);
262 m_pFL_Labels->Show(false);
264 m_pBxPlaceTicks->Show(false);
266 else if( !AxisHelper::isAxisPositioningEnabled() )
269 m_pFL_AxisLine->Enable(false);
271 m_pFL_Labels->Enable(false);
273 m_pBxPlaceTicks->Enable(false);
275 //todo: maybe set a special help id to all those controls
279 SfxTabPage::sfxpg AxisPositionsTabPage::DeactivatePage(SfxItemSet* pItemSet)
281 if( pItemSet )
282 FillItemSet( pItemSet );
284 return LEAVE_PAGE;
287 void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
289 m_pNumFormatter = pFormatter;
290 m_pED_CrossesAt->SetFormatter( m_pNumFormatter );
291 m_pED_CrossesAt->UseInputStringForFormatting();
293 const SfxPoolItem *pPoolItem = NULL;
294 if( GetItemSet().GetItemState( SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT, true, &pPoolItem ) == SfxItemState::SET )
296 sal_uLong nFmt = (sal_uLong)static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
297 m_pED_CrossesAt->SetFormatKey( nFmt );
301 void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis )
303 m_bCrossingAxisIsCategoryAxis = bCrossingAxisIsCategoryAxis;
306 void AxisPositionsTabPage::SetCategories( const ::com::sun::star::uno::Sequence< OUString >& rCategories )
308 m_aCategories = rCategories;
311 void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning )
313 m_bSupportAxisPositioning = bSupportAxisPositioning;
316 IMPL_LINK_NOARG(AxisPositionsTabPage, CrossesAtSelectHdl)
318 sal_Int32 nPos = m_pLB_CrossesAt->GetSelectEntryPos();
319 m_pED_CrossesAt->Show( (2==nPos) && !m_bCrossingAxisIsCategoryAxis );
320 m_pED_CrossesAtCategory->Show( (2==nPos) && m_bCrossingAxisIsCategoryAxis );
322 if( m_pED_CrossesAt->GetText().isEmpty() )
323 m_pED_CrossesAt->SetValue(0.0);
324 if( 0 == m_pED_CrossesAtCategory->GetSelectEntryCount() )
325 m_pED_CrossesAtCategory->SelectEntryPos(0);
327 PlaceLabelsSelectHdl( (void*)0 );
328 return 0;
331 IMPL_LINK_NOARG(AxisPositionsTabPage, PlaceLabelsSelectHdl)
333 sal_Int32 nLabelPos = m_pLB_PlaceLabels->GetSelectEntryPos();
335 bool bEnableTickmarkPlacement = (nLabelPos>1);
336 if( bEnableTickmarkPlacement )
338 sal_Int32 nAxisPos = m_pLB_CrossesAt->GetSelectEntryPos();
339 if( nLabelPos-2 == nAxisPos )
340 bEnableTickmarkPlacement=false;
342 m_pBxPlaceTicks->Enable(bEnableTickmarkPlacement);
344 return 0;
347 } //namespace chart
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */