update dev300-m58
[ooovba.git] / chart2 / source / controller / dialogs / res_DataLabel.cxx
blobca891aacae7ac252ad454ddb062aa9ba5dd5ca84
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: res_DataLabel.cxx,v $
10 * $Revision: 1.5.72.1 $
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"
34 #include "res_DataLabel.hxx"
35 #include "res_DataLabel_IDs.hrc"
37 #include "Strings.hrc"
38 #include "ResId.hxx"
39 #include "chartview/ChartSfxItemIds.hxx"
40 #include "NoWarningThisInCTOR.hxx"
41 #include "dlg_NumberFormat.hxx"
43 // header for class SvxNumberInfoItem
44 #include <svx/numinf.hxx>
45 #include <svtools/eitem.hxx>
46 // for SfxUInt32Item
47 #include <svtools/intitem.hxx>
48 // header for class SfxStringItem
49 #include <svtools/stritem.hxx>
50 //SfxIntegerListItem
51 #include <svtools/ilstitem.hxx>
52 #include <svx/eeitem.hxx>
53 #include <svx/frmdiritem.hxx>
55 // header for define RET_OK
56 #include <vcl/msgbox.hxx>
57 #include <svx/svxids.hrc>
58 // header for SvNumberFormatter
59 #include <svtools/zforlist.hxx>
60 #include <svtools/controldims.hrc>
63 //.............................................................................
64 namespace chart
66 //.............................................................................
68 namespace
71 bool lcl_ReadNumberFormatFromItemSet( const SfxItemSet& rSet, USHORT nValueWhich, USHORT nSourceFormatWhich, ULONG& rnFormatKeyOut, bool& rbSourceFormatOut, bool& rbSourceFormatMixedStateOut )
73 bool bSet = false;
74 const SfxPoolItem *pItem1 = NULL;
75 if( rSet.GetItemState( nValueWhich, TRUE, &pItem1 ) == SFX_ITEM_SET )
77 const SfxUInt32Item * pNumItem = dynamic_cast< const SfxUInt32Item * >( pItem1 );
78 if( pNumItem )
80 rnFormatKeyOut = pNumItem->GetValue();
81 bSet = true;
85 rbSourceFormatMixedStateOut=true;
86 const SfxPoolItem *pItem2 = NULL;
87 if( rSet.GetItemState( nSourceFormatWhich, TRUE, &pItem2 ) == SFX_ITEM_SET )
89 const SfxBoolItem * pBoolItem = dynamic_cast< const SfxBoolItem * >( pItem2 );
90 if( pBoolItem )
92 rbSourceFormatOut = pBoolItem->GetValue();
93 rbSourceFormatMixedStateOut=false;
96 return bSet;
99 void lcl_setBoolItemToCheckBox( const SfxItemSet& rInAttrs, USHORT nWhichId, CheckBox& rCheckbox )
101 rCheckbox.EnableTriState( FALSE );
103 const SfxPoolItem *pPoolItem = NULL;
104 if( rInAttrs.GetItemState(nWhichId, TRUE, &pPoolItem) == SFX_ITEM_SET )
105 rCheckbox.Check( ((const SfxBoolItem*)pPoolItem)->GetValue() );
106 else
108 rCheckbox.EnableTriState( TRUE );
109 rCheckbox.SetState( STATE_DONTKNOW );
113 }//end anonymous namespace
115 DataLabelResources::DataLabelResources( Window* pWindow, const SfxItemSet& rInAttrs )
116 : m_aCBNumber(pWindow, SchResId(CB_VALUE_AS_NUMBER)),
117 m_aPB_NumberFormatForValue(pWindow, SchResId(PB_NUMBERFORMAT)),
118 m_aCBPercent(pWindow, SchResId(CB_VALUE_AS_PERCENTAGE)),
119 m_aPB_NumberFormatForPercent(pWindow, SchResId(PB_PERCENT_NUMBERFORMAT)),
120 m_aCBCategory(pWindow, SchResId(CB_CATEGORY)),
121 m_aCBSymbol(pWindow, SchResId(CB_SYMBOL)),
122 m_aSeparatorResources(pWindow),
123 m_aFT_LabelPlacement(pWindow, SchResId(FT_LABEL_PLACEMENT)),
124 m_aLB_LabelPlacement(pWindow, SchResId(LB_LABEL_PLACEMENT)),
125 m_aFL_Rotate(pWindow, SchResId(FL_LABEL_ROTATE)),
126 m_aDC_Dial(pWindow, SchResId(CT_LABEL_DIAL)),
127 m_aFT_Degrees(pWindow, SchResId(FT_LABEL_DEGREES)),
128 m_aNF_Degrees(pWindow, SchResId(NF_LABEL_DEGREES)),
129 m_aFT_TextDirection(pWindow, SchResId(FT_LABEL_TEXTDIR)),
130 m_aLB_TextDirection(pWindow, SchResId(LB_LABEL_TEXTDIR), &m_aFT_TextDirection),
131 m_pNumberFormatter(0),
132 m_bNumberFormatMixedState(true),
133 m_bPercentFormatMixedState(true),
134 m_nNumberFormatForValue(0),
135 m_nNumberFormatForPercent(11),
136 m_bSourceFormatMixedState(true),
137 m_bPercentSourceMixedState(true),
138 m_bSourceFormatForValue(true),
139 m_bSourceFormatForPercent(true),
140 m_pWindow(pWindow),
141 m_pPool(rInAttrs.GetPool())
143 //fill label placement list
144 std::map< sal_Int32, XubString > aPlacementToStringMap;
145 for( sal_Int32 nEnum=0; nEnum<m_aLB_LabelPlacement.GetEntryCount(); ++nEnum )
146 aPlacementToStringMap[nEnum]=m_aLB_LabelPlacement.GetEntry(static_cast<USHORT>(nEnum));
148 ::com::sun::star::uno::Sequence < sal_Int32 > aAvailabelPlacementList;
149 const SfxPoolItem *pPoolItem = NULL;
150 if( rInAttrs.GetItemState(SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS, TRUE, &pPoolItem) == SFX_ITEM_SET )
151 aAvailabelPlacementList =((const SfxIntegerListItem*)pPoolItem)->GetConstSequence();
153 m_aLB_LabelPlacement.Clear();
154 for( sal_Int32 nN=0; nN<aAvailabelPlacementList.getLength(); ++nN )
156 USHORT nListBoxPos = static_cast<USHORT>( nN );
157 sal_Int32 nPlacement = aAvailabelPlacementList[nN];
158 m_aPlacementToListBoxMap[nPlacement]=nListBoxPos;
159 m_aListBoxToPlacementMap[nListBoxPos]=nPlacement;
160 m_aLB_LabelPlacement.InsertEntry( aPlacementToStringMap[nPlacement] );
162 m_aLB_LabelPlacement.SetDropDownLineCount(m_aLB_LabelPlacement.GetEntryCount());
164 //replace&resize push buttons and resize checkboxes
165 Size aControlDistance( pWindow->LogicToPixel( Size(RSC_SP_CTRL_DESC_X,RSC_SP_CTRL_GROUP_Y), MapMode(MAP_APPFONT) ) );
166 long nPBWidth = ::std::max( m_aPB_NumberFormatForPercent.CalcMinimumSize().getWidth(), m_aPB_NumberFormatForValue.CalcMinimumSize().getWidth() )
167 + 20; //the min with is to small to fit, hm... so add alittle
168 long nCBXWidth = ::std::max( m_aCBNumber.CalcMinimumSize().getWidth(), m_aCBPercent.CalcMinimumSize().getWidth() );
169 long nNewPBXPos = m_aCBNumber.GetPosPixel().X() + nCBXWidth + aControlDistance.Width();
170 long nPageWidth = pWindow->LogicToPixel( Size(260,185), MapMode(MAP_APPFONT) ).getWidth();
171 if( nNewPBXPos + nPBWidth > nPageWidth )
173 if( nPBWidth > nPageWidth/2 )
174 nPBWidth = nPageWidth/2;
175 nNewPBXPos = nPageWidth-nPBWidth;
176 nCBXWidth = nPageWidth-m_aCBNumber.GetPosPixel().X()-nPBWidth-aControlDistance.Width();
178 m_aPB_NumberFormatForValue.SetPosPixel( Point( nNewPBXPos, m_aPB_NumberFormatForValue.GetPosPixel().Y() ) );
179 m_aPB_NumberFormatForPercent.SetPosPixel( Point( nNewPBXPos, m_aPB_NumberFormatForPercent.GetPosPixel().Y() ) );
181 Size aPBSize( m_aPB_NumberFormatForPercent.GetSizePixel() );
182 aPBSize.setWidth( nPBWidth );
183 m_aPB_NumberFormatForValue.SetSizePixel( aPBSize );
184 m_aPB_NumberFormatForPercent.SetSizePixel( aPBSize );
186 Size aCBSize( m_aCBNumber.GetSizePixel() );
187 aCBSize.setWidth(nCBXWidth);
188 m_aCBNumber.SetSizePixel( aCBSize );
189 m_aCBPercent.SetSizePixel( aCBSize );
191 //place and align separator and label placement listboxes
192 Size aSize( m_aFT_LabelPlacement.GetSizePixel() );
193 aSize.setWidth( m_aFT_LabelPlacement.CalcMinimumSize().getWidth() );
194 m_aFT_LabelPlacement.SetSizePixel(aSize);
196 long nWantedMinLeftBorder = m_aFT_LabelPlacement.GetPosPixel().X() + aSize.getWidth () + aControlDistance.Width();
198 m_aSeparatorResources.PositionBelowControl(m_aCBSymbol);
199 m_aSeparatorResources.AlignListBoxWidthAndXPos( nWantedMinLeftBorder, -1, m_aLB_LabelPlacement.CalcMinimumSize().getWidth() );
200 m_aSeparatorResources.Show(true);
202 aSize = m_aLB_LabelPlacement.GetSizePixel();
203 aSize.setWidth( m_aSeparatorResources.GetCurrentListBoxSize().getWidth() );
204 m_aLB_LabelPlacement.SetSizePixel(aSize);
205 m_aLB_LabelPlacement.SetPosPixel( Point( m_aSeparatorResources.GetCurrentListBoxPosition().X(), m_aLB_LabelPlacement.GetPosPixel().Y() ) );
207 //some click handler
208 m_aPB_NumberFormatForValue.SetClickHdl( LINK( this, DataLabelResources, NumberFormatDialogHdl ) );
209 m_aPB_NumberFormatForPercent.SetClickHdl( LINK( this, DataLabelResources, NumberFormatDialogHdl ) );
210 m_aCBNumber.SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
211 m_aCBPercent.SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
212 m_aCBCategory.SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
213 m_aCBSymbol.SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
215 m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState );
216 m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState);
218 if( rInAttrs.GetItemState(SCHATTR_DATADESCR_NO_PERCENTVALUE, TRUE, &pPoolItem) == SFX_ITEM_SET )
220 bool bForbidPercentValue = (static_cast< const SfxBoolItem & >( rInAttrs.Get( SCHATTR_DATADESCR_NO_PERCENTVALUE )).GetValue() );
221 if( bForbidPercentValue )
222 m_aCBPercent.Enable(false);
225 m_aDC_Dial.SetLinkedField( &m_aNF_Degrees );
228 DataLabelResources::~DataLabelResources()
232 void DataLabelResources::SetNumberFormatter( SvNumberFormatter* pFormatter )
234 m_pNumberFormatter = pFormatter;
237 IMPL_LINK( DataLabelResources, NumberFormatDialogHdl, PushButton *, pButton )
239 if( !m_pPool || !m_pNumberFormatter )
241 DBG_ERROR("Missing item pool or number formatter");
242 return 1;
245 if( pButton == &m_aPB_NumberFormatForValue && !m_aCBNumber.IsChecked())
246 m_aCBNumber.Check();
247 else if( pButton == &m_aPB_NumberFormatForPercent && !m_aCBPercent.IsChecked())
248 m_aCBPercent.Check();
250 SfxItemSet aNumberSet = NumberFormatDialog::CreateEmptyItemSetForNumberFormatDialog( *m_pPool );
251 aNumberSet.Put (SvxNumberInfoItem( m_pNumberFormatter, (const USHORT)SID_ATTR_NUMBERFORMAT_INFO));
253 bool bPercent = ( pButton == &m_aPB_NumberFormatForPercent );
255 ULONG& rnFormatKey = bPercent ? m_nNumberFormatForPercent : m_nNumberFormatForValue;
256 bool& rUseSourceFormat = bPercent ? m_bSourceFormatForPercent : m_bSourceFormatForValue;
257 bool& rbMixedState = bPercent ? m_bPercentFormatMixedState : m_bNumberFormatMixedState;
258 bool& rbSourceMixedState = bPercent ? m_bPercentSourceMixedState : m_bSourceFormatMixedState;
260 if(!rbMixedState)
261 aNumberSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, rnFormatKey ));
262 aNumberSet.Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE, rUseSourceFormat ));
264 NumberFormatDialog aDlg(m_pWindow, aNumberSet);
265 if( bPercent )
266 aDlg.SetText( String( SchResId( STR_DLG_NUMBERFORMAT_FOR_PERCENTAGE_VALUE ) ) );
267 if( RET_OK == aDlg.Execute() )
269 const SfxItemSet* pResult = aDlg.GetOutputItemSet();
270 if( pResult )
272 bool bOldSource = rUseSourceFormat;
273 ULONG nOldFormat = rnFormatKey;
274 bool bOldMixedState = rbMixedState || rbSourceMixedState;
276 rbMixedState = !lcl_ReadNumberFormatFromItemSet( *pResult, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, rnFormatKey, rUseSourceFormat, rbSourceMixedState );
278 //todo this maybe can be removed when the numberformatter dialog does handle mixed state for source format correctly
279 if( bOldMixedState && bOldSource == rUseSourceFormat && nOldFormat == rnFormatKey )
280 rbMixedState = rbSourceMixedState = true;
283 return 0;
286 IMPL_LINK( DataLabelResources, CheckHdl, CheckBox*, pBox )
288 if( pBox )
289 pBox->EnableTriState( FALSE );
290 EnableControls();
291 return 0;
294 void DataLabelResources::EnableControls()
296 m_aCBSymbol.Enable( m_aCBNumber.IsChecked() || (m_aCBPercent.IsChecked() && m_aCBPercent.IsEnabled()) || m_aCBCategory.IsChecked() );
298 //enable separator
300 long nNumberOfCheckedLabelParts = 0;
301 if( m_aCBNumber.IsChecked() )
302 ++nNumberOfCheckedLabelParts;
303 if( m_aCBPercent.IsChecked() && m_aCBPercent.IsEnabled() )
304 ++nNumberOfCheckedLabelParts;
305 if( m_aCBCategory.IsChecked() )
306 ++nNumberOfCheckedLabelParts;
307 m_aSeparatorResources.Enable( nNumberOfCheckedLabelParts > 1 );
308 bool bEnableTextDir = nNumberOfCheckedLabelParts > 0;
309 m_aFT_TextDirection.Enable( bEnableTextDir );
310 m_aLB_TextDirection.Enable( bEnableTextDir );
311 bool bEnablePlacement = nNumberOfCheckedLabelParts > 0 && m_aLB_LabelPlacement.GetEntryCount()>1;
312 m_aFT_LabelPlacement.Enable( bEnablePlacement );
313 m_aLB_LabelPlacement.Enable( bEnablePlacement );
316 m_aPB_NumberFormatForValue.Enable( m_pNumberFormatter && m_aCBNumber.IsChecked() );
317 m_aPB_NumberFormatForPercent.Enable( m_pNumberFormatter && m_aCBPercent.IsChecked() && m_aCBPercent.IsEnabled() );
319 bool bEnableRotation = ( m_aCBNumber.IsChecked() || m_aCBPercent.IsChecked() || m_aCBCategory.IsChecked() );
320 m_aFL_Rotate.Enable( bEnableRotation );
321 m_aDC_Dial.Enable( bEnableRotation );
322 m_aFT_Degrees.Enable( bEnableRotation );
323 m_aNF_Degrees.Enable( bEnableRotation );
326 BOOL DataLabelResources::FillItemSet( SfxItemSet& rOutAttrs ) const
328 if( m_aCBNumber.IsChecked() )
330 if( !m_bNumberFormatMixedState )
331 rOutAttrs.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, m_nNumberFormatForValue ));
332 if( !m_bSourceFormatMixedState )
333 rOutAttrs.Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE, m_bSourceFormatForValue ));
335 if( m_aCBPercent.IsChecked() )
337 if( !m_bPercentFormatMixedState )
338 rOutAttrs.Put( SfxUInt32Item( SCHATTR_PERCENT_NUMBERFORMAT_VALUE, m_nNumberFormatForPercent ));
339 if( !m_bPercentSourceMixedState )
340 rOutAttrs.Put( SfxBoolItem( SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_bSourceFormatForPercent ));
343 if( m_aCBNumber.GetState()!= STATE_DONTKNOW )
344 rOutAttrs.Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_NUMBER, m_aCBNumber.IsChecked() ) );
345 if( m_aCBPercent.GetState()!= STATE_DONTKNOW )
346 rOutAttrs.Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_PERCENTAGE, m_aCBPercent.IsChecked() ) );
347 if( m_aCBCategory.GetState()!= STATE_DONTKNOW )
348 rOutAttrs.Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_CATEGORY, m_aCBCategory.IsChecked() ) );
349 if( m_aCBSymbol.GetState()!= STATE_DONTKNOW )
350 rOutAttrs.Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_SYMBOL, m_aCBSymbol.IsChecked()) );
352 rOutAttrs.Put( SfxStringItem( SCHATTR_DATADESCR_SEPARATOR, m_aSeparatorResources.GetValue() ) );
353 ::std::map< USHORT, sal_Int32 >::const_iterator aIt( m_aListBoxToPlacementMap.find(m_aLB_LabelPlacement.GetSelectEntryPos()) );
354 if(aIt!=m_aListBoxToPlacementMap.end())
356 sal_Int32 nValue = aIt->second;
357 rOutAttrs.Put( SfxInt32Item( SCHATTR_DATADESCR_PLACEMENT, nValue ) );
360 if( m_aLB_TextDirection.GetSelectEntryCount() > 0 )
361 rOutAttrs.Put( SfxInt32Item( EE_PARA_WRITINGDIR, m_aLB_TextDirection.GetSelectEntryValue() ) );
363 if( m_aDC_Dial.IsVisible() )
365 sal_Int32 nDegrees = m_aDC_Dial.GetRotation();
366 rOutAttrs.Put(SfxInt32Item( SCHATTR_TEXT_DEGREES, nDegrees ) );
369 return TRUE;
372 void DataLabelResources::Reset(const SfxItemSet& rInAttrs)
374 // default state
375 m_aCBSymbol.Enable( FALSE );
377 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_NUMBER, m_aCBNumber );
378 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_PERCENTAGE, m_aCBPercent );
379 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_CATEGORY, m_aCBCategory );
380 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_SYMBOL, m_aCBSymbol );
382 m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState );
383 m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState);
385 const SfxPoolItem *pPoolItem = NULL;
386 if( rInAttrs.GetItemState(SCHATTR_DATADESCR_SEPARATOR, TRUE, &pPoolItem) == SFX_ITEM_SET )
387 m_aSeparatorResources.SetValue( ((const SfxStringItem*)pPoolItem)->GetValue() );
388 else
389 m_aSeparatorResources.SetDefault();
391 if( rInAttrs.GetItemState(SCHATTR_DATADESCR_PLACEMENT, TRUE, &pPoolItem) == SFX_ITEM_SET )
393 sal_Int32 nPlacement = ((const SfxInt32Item*)pPoolItem)->GetValue();
394 ::std::map< sal_Int32, USHORT >::const_iterator aIt( m_aPlacementToListBoxMap.find(nPlacement) );
395 if(aIt!=m_aPlacementToListBoxMap.end())
397 USHORT nPos = aIt->second;
398 m_aLB_LabelPlacement.SelectEntryPos( nPos );
400 else
401 m_aLB_LabelPlacement.SetNoSelection();
403 else
404 m_aLB_LabelPlacement.SetNoSelection();
406 if( rInAttrs.GetItemState(EE_PARA_WRITINGDIR, TRUE, &pPoolItem ) == SFX_ITEM_SET )
407 m_aLB_TextDirection.SelectEntryValue( SvxFrameDirection(((const SvxFrameDirectionItem*)pPoolItem)->GetValue()) );
409 if( rInAttrs.GetItemState( SCHATTR_TEXT_DEGREES, TRUE, &pPoolItem ) == SFX_ITEM_SET )
411 sal_Int32 nDegrees = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
412 m_aDC_Dial.SetRotation( nDegrees );
414 else
415 m_aDC_Dial.SetRotation( 0 );
417 EnableControls();
420 //.............................................................................
421 } //namespace chart
422 //.............................................................................