update dev300-m58
[ooovba.git] / chart2 / source / controller / dialogs / tp_AxisPositions.cxx
blob7c67bee4659ff4d48f78a49020f5b27571b47c8c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tp_AxisPositions.cxx,v $
10 * $Revision: 1.1.4.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "tp_AxisPositions.hxx"
35 #include "ResId.hxx"
36 #include "TabPages.hrc"
37 #include "Strings.hrc"
38 #include "chartview/ChartSfxItemIds.hxx"
39 #include "NoWarningThisInCTOR.hxx"
40 #include "AxisHelper.hxx"
42 #ifndef _SVX_SVXIDS_HRC
43 #include <svx/svxids.hrc>
44 #endif
45 #include <rtl/math.hxx>
46 // header for class SvxDoubleItem
47 #include <svx/chrtitem.hxx>
48 // header for class SfxBoolItem
49 #include <svtools/eitem.hxx>
50 // header for SfxInt32Item
51 #include <svtools/intitem.hxx>
53 // header for class WarningBox
54 #include <vcl/msgbox.hxx>
56 // header for class SvNumberformat
57 #ifndef _ZFORMAT_HXX
58 #ifndef _ZFORLIST_DECLARE_TABLE
59 #define _ZFORLIST_DECLARE_TABLE
60 #endif
61 #include <svtools/zformat.hxx>
62 #endif
64 #include <svtools/controldims.hrc>
66 #include <com/sun/star/chart/ChartAxisPosition.hpp>
67 #include <com/sun/star/chart2/AxisType.hpp>
69 using namespace ::com::sun::star;
71 //.............................................................................
72 namespace chart
74 //.............................................................................
76 namespace
78 void lcl_newXPos( Control& rControl, long nXPos )
80 Point aPos( rControl.GetPosPixel() );
81 aPos.X() = nXPos;
82 rControl.SetPosPixel(aPos);
85 void lcl_shiftY( Control& rControl, long nYDiff )
87 Point aPos( rControl.GetPosPixel() );
88 aPos.Y() += nYDiff;
89 rControl.SetPosPixel(aPos);
94 AxisPositionsTabPage::AxisPositionsTabPage(Window* pWindow,const SfxItemSet& rInAttrs)
95 : SfxTabPage(pWindow, SchResId(TP_AXIS_POSITIONS), rInAttrs)
97 , m_aFL_AxisLine(this,SchResId(FL_AXIS_LINE))
98 , m_aFT_CrossesAt(this,SchResId(FT_CROSSES_OTHER_AXIS_AT))
99 , m_aLB_CrossesAt(this,SchResId(LB_CROSSES_OTHER_AXIS_AT))
100 , m_aED_CrossesAt(this,SchResId(EDT_CROSSES_OTHER_AXIS_AT))
101 , m_aED_CrossesAtCategory(this,SchResId(EDT_CROSSES_OTHER_AXIS_AT_CATEGORY))
102 , m_aCB_AxisBetweenCategories(this, SchResId(CB_AXIS_BETWEEN_CATEGORIES))
104 , m_aFL_Labels(this,SchResId(FL_LABELS))
105 , m_aFT_PlaceLabels( this, SchResId( FT_PLACE_LABELS ) )
106 , m_aLB_PlaceLabels( this, SchResId( LB_PLACE_LABELS ) )
107 , m_aFT_LabelDistance( this, SchResId( FT_AXIS_LABEL_DISTANCE ) )
108 , m_aED_LabelDistance( this, SchResId( EDT_AXIS_LABEL_DISTANCE ) )
110 , m_aFL_Ticks(this,SchResId(FL_TICKS))
111 , m_aFT_Major(this,SchResId(FT_MAJOR))
112 , m_aCB_TicksInner(this,SchResId(CB_TICKS_INNER))
113 , m_aCB_TicksOuter(this,SchResId(CB_TICKS_OUTER))
114 , m_aFT_Minor(this,SchResId(FT_MINOR))
115 , m_aCB_MinorInner(this,SchResId(CB_MINOR_INNER))
116 , m_aCB_MinorOuter(this,SchResId(CB_MINOR_OUTER))
118 , m_aFL_Vertical(this,SchResId(FL_VERTICAL))
119 , m_aFT_PlaceTicks(this,SchResId(FT_PLACE_TICKS))
120 , m_aLB_PlaceTicks(this,SchResId(LB_PLACE_TICKS))
122 , m_aFL_Grids(this,SchResId(FL_GRIDS))
123 , m_aCB_MajorGrid(this,SchResId(CB_MAJOR_GRID))
124 , m_aPB_MajorGrid(this,SchResId(PB_MAJOR_GRID))
125 , m_aCB_MinorGrid(this,SchResId(CB_MINOR_GRID))
126 , m_aPB_MinorGrid(this,SchResId(PB_MINOR_GRID))
128 , m_pNumFormatter(NULL)
129 , m_bCrossingAxisIsCategoryAxis(false)
130 , m_aCategories()
132 FreeResource();
133 SetExchangeSupport();
135 const long nDialogWidth = GetSizePixel().Width();
136 const long nDistance = LogicToPixel( Size(RSC_SP_CTRL_X, 0), MapMode(MAP_APPFONT) ).Width();
138 //axis line controls
140 if( m_aFT_CrossesAt.CalcMinimumSize().Width() < m_aFT_CrossesAt.GetSizePixel().Width() )
142 m_aFT_CrossesAt.SetSizePixel(m_aFT_CrossesAt.CalcMinimumSize());
143 long nXPos = m_aFT_CrossesAt.GetPosPixel().X() + m_aFT_CrossesAt.GetSizePixel().Width() + nDistance;
144 lcl_newXPos( m_aLB_CrossesAt, nXPos );
146 nXPos += m_aLB_CrossesAt.GetSizePixel().Width() + nDistance;
147 lcl_newXPos( m_aED_CrossesAt, nXPos );
148 lcl_newXPos( m_aED_CrossesAtCategory, nXPos );
152 long nFixTextHeight = m_aFT_PlaceLabels.GetSizePixel().Height();
153 long nLabelPlacementWidth = m_aFT_PlaceLabels.CalcMinimumSize().Width();
154 long nMarkPlacementWidth = m_aFT_PlaceTicks.CalcMinimumSize().Width();
157 long nWidth_0 = ::std::max( m_aFT_Major.CalcMinimumSize().Width(), m_aFT_Minor.CalcMinimumSize().Width() );
158 nWidth_0 = ::std::max( nWidth_0, nLabelPlacementWidth );
159 nWidth_0 = ::std::max( nWidth_0, nMarkPlacementWidth );
160 nLabelPlacementWidth = nMarkPlacementWidth = nWidth_0;
162 //label placement
164 m_aFT_PlaceLabels.SetSizePixel( Size( nLabelPlacementWidth, nFixTextHeight ) );
165 long nXPos = m_aFT_PlaceLabels.GetPosPixel().X() + nLabelPlacementWidth + nDistance;
166 lcl_newXPos( m_aLB_PlaceLabels, nXPos );
167 m_aLB_PlaceLabels.SetSizePixel(m_aLB_PlaceLabels.CalcMinimumSize());
170 //tickmark placement
172 m_aFT_PlaceTicks.SetSizePixel( Size( nMarkPlacementWidth, nFixTextHeight ) );
173 long nXPos = m_aFT_PlaceTicks.GetPosPixel().X() + nMarkPlacementWidth + nDistance;
174 lcl_newXPos( m_aLB_PlaceTicks, nXPos );
175 m_aLB_PlaceTicks.SetSizePixel( m_aLB_PlaceTicks.CalcMinimumSize() );
178 //tickmark controls
180 long nWidth_1 = ::std::max( m_aCB_TicksInner.CalcMinimumSize().Width(), m_aCB_MinorInner.CalcMinimumSize().Width() );
181 long nWidth_2 = ::std::max( m_aCB_TicksOuter.CalcMinimumSize().Width(), m_aCB_MinorOuter.CalcMinimumSize().Width() );
183 long nLeftSpace = nDialogWidth - nWidth_0 - nWidth_1 - nWidth_2 - 3*nDistance;
185 if(nLeftSpace>=0)
187 m_aFT_Major.SetSizePixel(m_aFT_Major.CalcMinimumSize());
188 m_aFT_Minor.SetSizePixel(m_aFT_Minor.CalcMinimumSize());
190 m_aCB_TicksInner.SetSizePixel( m_aCB_TicksInner.CalcMinimumSize() );
191 m_aCB_MinorInner.SetSizePixel( m_aCB_MinorInner.CalcMinimumSize() );
193 m_aCB_TicksOuter.SetSizePixel( m_aCB_TicksOuter.CalcMinimumSize() );
194 m_aCB_MinorOuter.SetSizePixel( m_aCB_MinorOuter.CalcMinimumSize() );
196 long nXPos = m_aFT_Major.GetPosPixel().X() + nWidth_0 + nDistance;
197 lcl_newXPos( m_aCB_TicksInner, nXPos );
198 lcl_newXPos( m_aCB_MinorInner, nXPos );
200 nXPos += nWidth_1 + nDistance;
201 lcl_newXPos( m_aCB_TicksOuter, nXPos );
202 lcl_newXPos( m_aCB_MinorOuter, nXPos );
204 nXPos += nWidth_2 + nDistance;
205 lcl_newXPos( m_aFL_Vertical, nXPos );
209 //right alignement of listboxes:
211 long nLabelRightBorder = m_aLB_PlaceLabels.GetPosPixel().X() + m_aLB_PlaceLabels.GetSizePixel().Width();
212 long nTickmarksRightBorder = m_aLB_PlaceTicks.GetPosPixel().X() + m_aLB_PlaceTicks.GetSizePixel().Width();
214 long nNewRightBorder = ::std::max( m_aLB_CrossesAt.GetPosPixel().X() + m_aLB_CrossesAt.GetSizePixel().Width(), nLabelRightBorder);
215 nNewRightBorder = ::std::max( nTickmarksRightBorder, nNewRightBorder );
217 long nListBoxHeight = m_aLB_PlaceLabels.GetSizePixel().Height();
218 m_aLB_PlaceLabels.SetSizePixel( Size( m_aLB_PlaceLabels.GetSizePixel().Width()+nNewRightBorder-nLabelRightBorder, nListBoxHeight ) );
219 m_aLB_PlaceTicks.SetSizePixel( Size( m_aLB_PlaceTicks.GetSizePixel().Width()+nNewRightBorder-nTickmarksRightBorder, nListBoxHeight ) );
222 m_aLB_CrossesAt.SetSelectHdl( LINK( this, AxisPositionsTabPage, CrossesAtSelectHdl ) );
223 m_aLB_CrossesAt.SetDropDownLineCount( m_aLB_CrossesAt.GetEntryCount() );
225 m_aLB_PlaceLabels.SetSelectHdl( LINK( this, AxisPositionsTabPage, PlaceLabelsSelectHdl ) );
226 m_aLB_PlaceLabels.SetDropDownLineCount( m_aLB_PlaceLabels.GetEntryCount() );
227 m_aLB_PlaceTicks.SetDropDownLineCount( m_aLB_PlaceTicks.GetEntryCount() );
230 SfxTabPage* AxisPositionsTabPage::Create(Window* pWindow,const SfxItemSet& rOutAttrs)
232 return new AxisPositionsTabPage(pWindow, rOutAttrs);
235 BOOL AxisPositionsTabPage::FillItemSet(SfxItemSet& rOutAttrs)
237 // axis line
238 USHORT nPos = m_aLB_CrossesAt.GetSelectEntryPos();
239 rOutAttrs.Put( SfxInt32Item( SCHATTR_AXIS_POSITION, nPos+1 ));
240 if( 2==nPos )
242 double fCrossover = m_aED_CrossesAt.GetValue();
243 if( m_bCrossingAxisIsCategoryAxis )
244 fCrossover = m_aED_CrossesAtCategory.GetSelectEntryPos()+1;
245 rOutAttrs.Put(SvxDoubleItem(fCrossover,SCHATTR_AXIS_POSITION_VALUE));
248 // labels
249 USHORT nLabelPos = m_aLB_PlaceLabels.GetSelectEntryPos();
250 if( nLabelPos != LISTBOX_ENTRY_NOTFOUND )
251 rOutAttrs.Put( SfxInt32Item( SCHATTR_AXIS_LABEL_POSITION, nLabelPos ));
253 // tick marks
254 long nTicks=0;
255 long nMinorTicks=0;
257 if(m_aCB_MinorInner.IsChecked())
258 nMinorTicks|=CHAXIS_MARK_INNER;
259 if(m_aCB_MinorOuter.IsChecked())
260 nMinorTicks|=CHAXIS_MARK_OUTER;
261 if(m_aCB_TicksInner.IsChecked())
262 nTicks|=CHAXIS_MARK_INNER;
263 if(m_aCB_TicksOuter.IsChecked())
264 nTicks|=CHAXIS_MARK_OUTER;
266 rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_TICKS,nTicks));
267 rOutAttrs.Put(SfxInt32Item(SCHATTR_AXIS_HELPTICKS,nMinorTicks));
269 USHORT nMarkPos = m_aLB_PlaceTicks.GetSelectEntryPos();
270 if( nMarkPos != LISTBOX_ENTRY_NOTFOUND )
271 rOutAttrs.Put( SfxInt32Item( SCHATTR_AXIS_MARK_POSITION, nMarkPos ));
273 return TRUE;
276 void AxisPositionsTabPage::Reset(const SfxItemSet& rInAttrs)
278 //init and enable controls
279 m_aED_CrossesAt.Show( !m_bCrossingAxisIsCategoryAxis );
280 m_aED_CrossesAtCategory.Show( m_bCrossingAxisIsCategoryAxis );
281 const sal_Int32 nMaxCount = LISTBOX_ENTRY_NOTFOUND;
282 if( m_bCrossingAxisIsCategoryAxis )
284 for( sal_Int32 nN=0; nN<m_aCategories.getLength() && nN<nMaxCount; nN++ )
285 m_aED_CrossesAtCategory.InsertEntry( m_aCategories[nN] );
287 USHORT nCount = m_aED_CrossesAtCategory.GetEntryCount();
288 if( nCount>30 )
289 nCount=30;
290 m_aED_CrossesAtCategory.SetDropDownLineCount( nCount );
293 if( m_aLB_CrossesAt.GetEntryCount() > 3 )
295 if( m_bCrossingAxisIsCategoryAxis )
296 m_aLB_CrossesAt.RemoveEntry(2);
297 else
298 m_aLB_CrossesAt.RemoveEntry(3);
301 //fill controls
302 const SfxPoolItem *pPoolItem = NULL;
304 //axis line
305 if(rInAttrs.GetItemState(SCHATTR_AXIS_POSITION,TRUE, &pPoolItem)== SFX_ITEM_SET)
307 bool bZero = false;
308 USHORT nPos = (USHORT)static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
309 if(nPos==0)
311 //switch to value
312 bZero = true;
313 nPos = 2;
315 else
316 nPos--;
318 if( nPos < m_aLB_CrossesAt.GetEntryCount() )
319 m_aLB_CrossesAt.SelectEntryPos( nPos );
320 CrossesAtSelectHdl( (void*)0 );
322 if( rInAttrs.GetItemState(SCHATTR_AXIS_POSITION_VALUE,TRUE, &pPoolItem)== SFX_ITEM_SET || bZero )
324 double fCrossover = 0.0;
325 if( !bZero )
326 fCrossover = (((const SvxDoubleItem*)pPoolItem)->GetValue());
327 if( m_bCrossingAxisIsCategoryAxis )
328 m_aED_CrossesAtCategory.SelectEntryPos( static_cast<USHORT>(::rtl::math::round(fCrossover-1.0)) );
329 else
330 m_aED_CrossesAt.SetValue(fCrossover);
332 else
334 m_aED_CrossesAtCategory.SetNoSelection();
335 m_aED_CrossesAt.SetTextValue(XubString());
338 else
340 m_aLB_CrossesAt.SetNoSelection();
341 m_aED_CrossesAt.Enable( FALSE );
344 // Labels
345 if( rInAttrs.GetItemState( SCHATTR_AXIS_LABEL_POSITION, FALSE, &pPoolItem ) == SFX_ITEM_SET )
347 USHORT nPos = (USHORT)static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
348 if( nPos < m_aLB_PlaceLabels.GetEntryCount() )
349 m_aLB_PlaceLabels.SelectEntryPos( nPos );
351 else
352 m_aLB_PlaceLabels.SetNoSelection();
353 PlaceLabelsSelectHdl( (void*)0 );
355 // Tick marks
356 long nTicks=0,nMinorTicks=0;
357 if(rInAttrs.GetItemState(SCHATTR_AXIS_TICKS,TRUE, &pPoolItem)== SFX_ITEM_SET)
358 nTicks=((const SfxInt32Item*)pPoolItem)->GetValue();
359 if(rInAttrs.GetItemState(SCHATTR_AXIS_HELPTICKS,TRUE, &pPoolItem)== SFX_ITEM_SET)
360 nMinorTicks=((const SfxInt32Item*)pPoolItem)->GetValue();
362 m_aCB_TicksInner.Check(BOOL(nTicks&CHAXIS_MARK_INNER));
363 m_aCB_TicksOuter.Check(BOOL(nTicks&CHAXIS_MARK_OUTER));
364 m_aCB_MinorInner.Check(BOOL(nMinorTicks&CHAXIS_MARK_INNER));
365 m_aCB_MinorOuter.Check(BOOL(nMinorTicks&CHAXIS_MARK_OUTER));
367 // Tick position
368 if( rInAttrs.GetItemState( SCHATTR_AXIS_MARK_POSITION, FALSE, &pPoolItem ) == SFX_ITEM_SET )
370 USHORT nPos = (USHORT)static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
371 if( nPos < m_aLB_PlaceTicks.GetEntryCount() )
372 m_aLB_PlaceTicks.SelectEntryPos( nPos );
374 else
375 m_aLB_PlaceTicks.SetNoSelection();
378 if( !m_bSupportAxisPositioning )
380 m_aFL_AxisLine.Show(false);
381 m_aFT_CrossesAt.Show(false);
382 m_aLB_CrossesAt.Show(false);
383 m_aED_CrossesAt.Show(false);
384 m_aED_CrossesAtCategory.Show(false);
385 m_aCB_AxisBetweenCategories.Show(false);
387 m_aFL_Labels.Show(false);
388 m_aFT_PlaceLabels.Show(false);
389 m_aLB_PlaceLabels.Show(false);
390 m_aFT_LabelDistance.Show(false);
391 m_aED_LabelDistance.Show(false);
393 m_aFL_Vertical.Show(false);
394 m_aFT_PlaceTicks.Show(false);
395 m_aLB_PlaceTicks.Show(false);
397 long nYDiff = m_aFL_AxisLine.GetPosPixel().Y() - m_aFL_Ticks.GetPosPixel().Y();
398 lcl_shiftY( m_aFL_Ticks, nYDiff );
399 lcl_shiftY( m_aFT_Major, nYDiff );
400 lcl_shiftY( m_aCB_TicksInner, nYDiff );
401 lcl_shiftY( m_aCB_TicksOuter, nYDiff );
403 lcl_shiftY( m_aFT_Minor, nYDiff );
404 lcl_shiftY( m_aCB_MinorInner, nYDiff );
405 lcl_shiftY( m_aCB_MinorOuter, nYDiff );
407 else if( !AxisHelper::isAxisPositioningEnabled() )
409 m_aFL_AxisLine.Enable(false);
410 m_aFT_CrossesAt.Enable(false);
411 m_aLB_CrossesAt.Enable(false);
412 m_aED_CrossesAt.Enable(false);
413 m_aED_CrossesAtCategory.Enable(false);
414 m_aCB_AxisBetweenCategories.Enable(false);
416 m_aFL_Labels.Enable(false);
417 m_aFT_PlaceLabels.Enable(false);
418 m_aLB_PlaceLabels.Enable(false);
419 m_aFT_LabelDistance.Enable(false);
420 m_aED_LabelDistance.Enable(false);
422 m_aFL_Vertical.Enable(false);
423 m_aFT_PlaceTicks.Enable(false);
424 m_aLB_PlaceTicks.Enable(false);
426 //todo: maybe set a special help id to all those controls
430 int AxisPositionsTabPage::DeactivatePage(SfxItemSet* pItemSet)
432 if( pItemSet )
433 FillItemSet( *pItemSet );
435 return LEAVE_PAGE;
438 void AxisPositionsTabPage::SetNumFormatter( SvNumberFormatter* pFormatter )
440 m_pNumFormatter = pFormatter;
441 m_aED_CrossesAt.SetFormatter( m_pNumFormatter );
442 m_aED_CrossesAt.UseInputStringForFormatting();
444 const SfxPoolItem *pPoolItem = NULL;
445 if( GetItemSet().GetItemState( SCHATTR_AXIS_CROSSING_MAIN_AXIS_NUMBERFORMAT, TRUE, &pPoolItem ) == SFX_ITEM_SET )
447 ULONG nFmt = (ULONG)((const SfxInt32Item*)pPoolItem)->GetValue();
448 m_aED_CrossesAt.SetFormatKey( nFmt );
452 void AxisPositionsTabPage::SetCrossingAxisIsCategoryAxis( bool bCrossingAxisIsCategoryAxis )
454 m_bCrossingAxisIsCategoryAxis = bCrossingAxisIsCategoryAxis;
457 void AxisPositionsTabPage::SetCategories( const ::com::sun::star::uno::Sequence< rtl::OUString >& rCategories )
459 m_aCategories = rCategories;
462 void AxisPositionsTabPage::SupportAxisPositioning( bool bSupportAxisPositioning )
464 m_bSupportAxisPositioning = bSupportAxisPositioning;
467 IMPL_LINK ( AxisPositionsTabPage, CrossesAtSelectHdl, void *, EMPTYARG )
469 USHORT nPos = m_aLB_CrossesAt.GetSelectEntryPos();
470 m_aED_CrossesAt.Show( (2==nPos) && !m_bCrossingAxisIsCategoryAxis );
471 m_aED_CrossesAtCategory.Show( (2==nPos) && m_bCrossingAxisIsCategoryAxis );
473 if(! m_aED_CrossesAt.GetText().Len() )
474 m_aED_CrossesAt.SetValue(0.0);
475 if( 0 == m_aED_CrossesAtCategory.GetSelectEntryCount() )
476 m_aED_CrossesAtCategory.SelectEntryPos(0);
478 PlaceLabelsSelectHdl( (void*)0 );
479 return 0;
482 IMPL_LINK ( AxisPositionsTabPage, PlaceLabelsSelectHdl, void *, EMPTYARG )
484 USHORT nLabelPos = m_aLB_PlaceLabels.GetSelectEntryPos();
486 bool bEnableTickmarkPlacement = (nLabelPos>1);
487 if( bEnableTickmarkPlacement )
489 USHORT nAxisPos = m_aLB_CrossesAt.GetSelectEntryPos();
490 if( nLabelPos-2 == nAxisPos )
491 bEnableTickmarkPlacement=false;
493 m_aFT_PlaceTicks.Enable(bEnableTickmarkPlacement);
494 m_aLB_PlaceTicks.Enable(bEnableTickmarkPlacement);
496 return 0;
499 //.............................................................................
500 } //namespace chart
501 //.............................................................................