1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "res_DataLabel.hxx"
28cdf0e10cSrcweir #include "res_DataLabel_IDs.hrc"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include "Strings.hrc"
31cdf0e10cSrcweir #include "ResId.hxx"
32cdf0e10cSrcweir #include "chartview/ChartSfxItemIds.hxx"
33cdf0e10cSrcweir #include "NoWarningThisInCTOR.hxx"
34cdf0e10cSrcweir #include "dlg_NumberFormat.hxx"
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // header for class SvxNumberInfoItem
37cdf0e10cSrcweir #include <svx/numinf.hxx>
38cdf0e10cSrcweir #include <svl/eitem.hxx>
39cdf0e10cSrcweir // for SfxUInt32Item
40cdf0e10cSrcweir #include <svl/intitem.hxx>
41cdf0e10cSrcweir // header for class SfxStringItem
42cdf0e10cSrcweir #include <svl/stritem.hxx>
43cdf0e10cSrcweir //SfxIntegerListItem
44cdf0e10cSrcweir #include <svl/ilstitem.hxx>
45cdf0e10cSrcweir #include <editeng/eeitem.hxx>
46cdf0e10cSrcweir #include <editeng/frmdiritem.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // header for define RET_OK
49cdf0e10cSrcweir #include <vcl/msgbox.hxx>
50cdf0e10cSrcweir #include <svx/svxids.hrc>
51cdf0e10cSrcweir // header for SvNumberFormatter
52cdf0e10cSrcweir #include <svl/zforlist.hxx>
53cdf0e10cSrcweir #include <svtools/controldims.hrc>
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //.............................................................................
57cdf0e10cSrcweir namespace chart
58cdf0e10cSrcweir {
59cdf0e10cSrcweir //.............................................................................
60cdf0e10cSrcweir 
61cdf0e10cSrcweir namespace
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 
lcl_ReadNumberFormatFromItemSet(const SfxItemSet & rSet,sal_uInt16 nValueWhich,sal_uInt16 nSourceFormatWhich,sal_uLong & rnFormatKeyOut,bool & rbSourceFormatOut,bool & rbSourceFormatMixedStateOut)64cdf0e10cSrcweir bool lcl_ReadNumberFormatFromItemSet( const SfxItemSet& rSet, sal_uInt16 nValueWhich, sal_uInt16 nSourceFormatWhich, sal_uLong& rnFormatKeyOut, bool& rbSourceFormatOut, bool& rbSourceFormatMixedStateOut )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     bool bSet = false;
67cdf0e10cSrcweir     const SfxPoolItem *pItem1 = NULL;
68cdf0e10cSrcweir     if( rSet.GetItemState( nValueWhich, sal_True, &pItem1 ) == SFX_ITEM_SET )
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir         const SfxUInt32Item * pNumItem = dynamic_cast< const SfxUInt32Item * >( pItem1 );
71cdf0e10cSrcweir         if( pNumItem )
72cdf0e10cSrcweir         {
73cdf0e10cSrcweir             rnFormatKeyOut = pNumItem->GetValue();
74cdf0e10cSrcweir             bSet = true;
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     rbSourceFormatMixedStateOut=true;
79cdf0e10cSrcweir     const SfxPoolItem *pItem2 = NULL;
80cdf0e10cSrcweir     if( rSet.GetItemState( nSourceFormatWhich, sal_True, &pItem2 ) == SFX_ITEM_SET )
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         const SfxBoolItem * pBoolItem = dynamic_cast< const SfxBoolItem * >( pItem2 );
83cdf0e10cSrcweir         if( pBoolItem )
84cdf0e10cSrcweir         {
85cdf0e10cSrcweir             rbSourceFormatOut = pBoolItem->GetValue();
86cdf0e10cSrcweir             rbSourceFormatMixedStateOut=false;
87cdf0e10cSrcweir         }
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir     return bSet;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
lcl_setBoolItemToCheckBox(const SfxItemSet & rInAttrs,sal_uInt16 nWhichId,CheckBox & rCheckbox)92cdf0e10cSrcweir void lcl_setBoolItemToCheckBox( const SfxItemSet& rInAttrs, sal_uInt16 nWhichId, CheckBox& rCheckbox )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     rCheckbox.EnableTriState( sal_False );
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     const SfxPoolItem *pPoolItem = NULL;
97cdf0e10cSrcweir     if( rInAttrs.GetItemState(nWhichId, sal_True, &pPoolItem) == SFX_ITEM_SET )
98cdf0e10cSrcweir         rCheckbox.Check( ((const SfxBoolItem*)pPoolItem)->GetValue() );
99cdf0e10cSrcweir     else
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         rCheckbox.EnableTriState( sal_True );
102cdf0e10cSrcweir         rCheckbox.SetState( STATE_DONTKNOW );
103cdf0e10cSrcweir     }
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir }//end anonymous namespace
107cdf0e10cSrcweir 
DataLabelResources(Window * pWindow,const SfxItemSet & rInAttrs)108cdf0e10cSrcweir DataLabelResources::DataLabelResources( Window* pWindow, const SfxItemSet& rInAttrs )
109cdf0e10cSrcweir     : m_aCBNumber(pWindow, SchResId(CB_VALUE_AS_NUMBER)),
110cdf0e10cSrcweir     m_aPB_NumberFormatForValue(pWindow, SchResId(PB_NUMBERFORMAT)),
111cdf0e10cSrcweir     m_aCBPercent(pWindow, SchResId(CB_VALUE_AS_PERCENTAGE)),
112cdf0e10cSrcweir     m_aPB_NumberFormatForPercent(pWindow, SchResId(PB_PERCENT_NUMBERFORMAT)),
113cdf0e10cSrcweir     m_aCBCategory(pWindow, SchResId(CB_CATEGORY)),
114cdf0e10cSrcweir     m_aCBSymbol(pWindow, SchResId(CB_SYMBOL)),
115cdf0e10cSrcweir     m_aSeparatorResources(pWindow),
116cdf0e10cSrcweir     m_aFT_LabelPlacement(pWindow, SchResId(FT_LABEL_PLACEMENT)),
117cdf0e10cSrcweir     m_aLB_LabelPlacement(pWindow, SchResId(LB_LABEL_PLACEMENT)),
118cdf0e10cSrcweir     m_aFL_Rotate(pWindow, SchResId(FL_LABEL_ROTATE)),
119cdf0e10cSrcweir     m_aDC_Dial(pWindow, SchResId(CT_LABEL_DIAL)),
120cdf0e10cSrcweir     m_aFT_Degrees(pWindow, SchResId(FT_LABEL_DEGREES)),
121cdf0e10cSrcweir     m_aNF_Degrees(pWindow, SchResId(NF_LABEL_DEGREES)),
122cdf0e10cSrcweir     m_aFT_TextDirection(pWindow, SchResId(FT_LABEL_TEXTDIR)),
123cdf0e10cSrcweir     m_aLB_TextDirection(pWindow, SchResId(LB_LABEL_TEXTDIR), &m_aFT_TextDirection),
124cdf0e10cSrcweir     m_pNumberFormatter(0),
125cdf0e10cSrcweir     m_bNumberFormatMixedState(true),
126cdf0e10cSrcweir     m_bPercentFormatMixedState(true),
127cdf0e10cSrcweir     m_nNumberFormatForValue(0),
128cdf0e10cSrcweir     m_nNumberFormatForPercent(11),
129cdf0e10cSrcweir     m_bSourceFormatMixedState(true),
130cdf0e10cSrcweir     m_bPercentSourceMixedState(true),
131cdf0e10cSrcweir     m_bSourceFormatForValue(true),
132cdf0e10cSrcweir     m_bSourceFormatForPercent(true),
133cdf0e10cSrcweir     m_pWindow(pWindow),
134cdf0e10cSrcweir     m_pPool(rInAttrs.GetPool())
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     //fill label placement list
137cdf0e10cSrcweir     std::map< sal_Int32, XubString > aPlacementToStringMap;
138cdf0e10cSrcweir     for( sal_Int32 nEnum=0; nEnum<m_aLB_LabelPlacement.GetEntryCount(); ++nEnum )
139cdf0e10cSrcweir         aPlacementToStringMap[nEnum]=m_aLB_LabelPlacement.GetEntry(static_cast<sal_uInt16>(nEnum));
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     ::com::sun::star::uno::Sequence < sal_Int32 > aAvailabelPlacementList;
142cdf0e10cSrcweir     const SfxPoolItem *pPoolItem = NULL;
143cdf0e10cSrcweir     if( rInAttrs.GetItemState(SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS, sal_True, &pPoolItem) == SFX_ITEM_SET )
144cdf0e10cSrcweir         aAvailabelPlacementList =((const SfxIntegerListItem*)pPoolItem)->GetConstSequence();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     m_aLB_LabelPlacement.Clear();
147cdf0e10cSrcweir     for( sal_Int32 nN=0; nN<aAvailabelPlacementList.getLength(); ++nN )
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         sal_uInt16 nListBoxPos = static_cast<sal_uInt16>( nN );
150cdf0e10cSrcweir         sal_Int32 nPlacement = aAvailabelPlacementList[nN];
151cdf0e10cSrcweir         m_aPlacementToListBoxMap[nPlacement]=nListBoxPos;
152cdf0e10cSrcweir         m_aListBoxToPlacementMap[nListBoxPos]=nPlacement;
153cdf0e10cSrcweir         m_aLB_LabelPlacement.InsertEntry( aPlacementToStringMap[nPlacement] );
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir     m_aLB_LabelPlacement.SetDropDownLineCount(m_aLB_LabelPlacement.GetEntryCount());
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     //replace&resize push buttons and resize checkboxes
158cdf0e10cSrcweir     Size aControlDistance( pWindow->LogicToPixel( Size(RSC_SP_CTRL_DESC_X,RSC_SP_CTRL_GROUP_Y), MapMode(MAP_APPFONT) ) );
159cdf0e10cSrcweir     long nPBWidth = ::std::max( m_aPB_NumberFormatForPercent.CalcMinimumSize().getWidth(), m_aPB_NumberFormatForValue.CalcMinimumSize().getWidth() )
160cdf0e10cSrcweir         + 20; //the min with is to small to fit, hm... so add alittle
161cdf0e10cSrcweir     long nCBXWidth = ::std::max( m_aCBNumber.CalcMinimumSize().getWidth(), m_aCBPercent.CalcMinimumSize().getWidth() );
162cdf0e10cSrcweir     long nNewPBXPos = m_aCBNumber.GetPosPixel().X() + nCBXWidth + aControlDistance.Width();
163cdf0e10cSrcweir     long nPageWidth = pWindow->LogicToPixel( Size(260,185), MapMode(MAP_APPFONT) ).getWidth();
164cdf0e10cSrcweir     if( nNewPBXPos + nPBWidth > nPageWidth )
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         if( nPBWidth > nPageWidth/2 )
167cdf0e10cSrcweir             nPBWidth = nPageWidth/2;
168cdf0e10cSrcweir         nNewPBXPos = nPageWidth-nPBWidth;
169cdf0e10cSrcweir         nCBXWidth = nPageWidth-m_aCBNumber.GetPosPixel().X()-nPBWidth-aControlDistance.Width();
170cdf0e10cSrcweir     }
171cdf0e10cSrcweir     m_aPB_NumberFormatForValue.SetPosPixel( Point( nNewPBXPos, m_aPB_NumberFormatForValue.GetPosPixel().Y() ) );
172cdf0e10cSrcweir     m_aPB_NumberFormatForPercent.SetPosPixel( Point( nNewPBXPos, m_aPB_NumberFormatForPercent.GetPosPixel().Y() ) );
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     Size aPBSize( m_aPB_NumberFormatForPercent.GetSizePixel() );
175cdf0e10cSrcweir     aPBSize.setWidth( nPBWidth );
176cdf0e10cSrcweir     m_aPB_NumberFormatForValue.SetSizePixel( aPBSize );
177cdf0e10cSrcweir     m_aPB_NumberFormatForPercent.SetSizePixel( aPBSize );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     Size aCBSize( m_aCBNumber.GetSizePixel() );
180cdf0e10cSrcweir     aCBSize.setWidth(nCBXWidth);
181cdf0e10cSrcweir     m_aCBNumber.SetSizePixel( aCBSize );
182cdf0e10cSrcweir     m_aCBPercent.SetSizePixel( aCBSize );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     //place and align separator and label placement listboxes
185cdf0e10cSrcweir     Size aSize( m_aFT_LabelPlacement.GetSizePixel() );
186cdf0e10cSrcweir     aSize.setWidth( m_aFT_LabelPlacement.CalcMinimumSize().getWidth() );
187cdf0e10cSrcweir     m_aFT_LabelPlacement.SetSizePixel(aSize);
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     long nWantedMinLeftBorder = m_aFT_LabelPlacement.GetPosPixel().X() + aSize.getWidth () + aControlDistance.Width();
190cdf0e10cSrcweir 
191cdf0e10cSrcweir     m_aSeparatorResources.PositionBelowControl(m_aCBSymbol);
192cdf0e10cSrcweir     m_aSeparatorResources.AlignListBoxWidthAndXPos( nWantedMinLeftBorder, -1, m_aLB_LabelPlacement.CalcMinimumSize().getWidth() );
193cdf0e10cSrcweir     m_aSeparatorResources.Show(true);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir     aSize = m_aLB_LabelPlacement.GetSizePixel();
196cdf0e10cSrcweir     aSize.setWidth( m_aSeparatorResources.GetCurrentListBoxSize().getWidth() );
197cdf0e10cSrcweir     m_aLB_LabelPlacement.SetSizePixel(aSize);
198cdf0e10cSrcweir     m_aLB_LabelPlacement.SetPosPixel( Point( m_aSeparatorResources.GetCurrentListBoxPosition().X(), m_aLB_LabelPlacement.GetPosPixel().Y() ) );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     //some click handler
201cdf0e10cSrcweir     m_aPB_NumberFormatForValue.SetClickHdl( LINK( this, DataLabelResources, NumberFormatDialogHdl ) );
202cdf0e10cSrcweir     m_aPB_NumberFormatForPercent.SetClickHdl( LINK( this, DataLabelResources, NumberFormatDialogHdl ) );
203cdf0e10cSrcweir     m_aCBNumber.SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
204cdf0e10cSrcweir     m_aCBPercent.SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
205cdf0e10cSrcweir     m_aCBCategory.SetClickHdl(  LINK( this, DataLabelResources, CheckHdl ));
206cdf0e10cSrcweir     m_aCBSymbol.SetClickHdl(  LINK( this, DataLabelResources, CheckHdl ));
207cdf0e10cSrcweir 
208cdf0e10cSrcweir     m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState );
209cdf0e10cSrcweir     m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState);
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     if( rInAttrs.GetItemState(SCHATTR_DATADESCR_NO_PERCENTVALUE, sal_True, &pPoolItem) == SFX_ITEM_SET )
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         bool bForbidPercentValue = (static_cast< const SfxBoolItem & >( rInAttrs.Get( SCHATTR_DATADESCR_NO_PERCENTVALUE )).GetValue() );
214cdf0e10cSrcweir         if( bForbidPercentValue )
215cdf0e10cSrcweir             m_aCBPercent.Enable(false);
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     m_aDC_Dial.SetLinkedField( &m_aNF_Degrees );
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
~DataLabelResources()221cdf0e10cSrcweir DataLabelResources::~DataLabelResources()
222cdf0e10cSrcweir {
223cdf0e10cSrcweir }
224cdf0e10cSrcweir 
SetNumberFormatter(SvNumberFormatter * pFormatter)225cdf0e10cSrcweir void DataLabelResources::SetNumberFormatter( SvNumberFormatter* pFormatter )
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     m_pNumberFormatter = pFormatter;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
IMPL_LINK(DataLabelResources,NumberFormatDialogHdl,PushButton *,pButton)230cdf0e10cSrcweir IMPL_LINK( DataLabelResources, NumberFormatDialogHdl, PushButton *, pButton )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir     if( !m_pPool || !m_pNumberFormatter )
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         DBG_ERROR("Missing item pool or number formatter");
235cdf0e10cSrcweir         return 1;
236cdf0e10cSrcweir     }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     if( pButton == &m_aPB_NumberFormatForValue && !m_aCBNumber.IsChecked())
239cdf0e10cSrcweir         m_aCBNumber.Check();
240cdf0e10cSrcweir     else if( pButton == &m_aPB_NumberFormatForPercent && !m_aCBPercent.IsChecked())
241cdf0e10cSrcweir         m_aCBPercent.Check();
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     SfxItemSet aNumberSet = NumberFormatDialog::CreateEmptyItemSetForNumberFormatDialog( *m_pPool );
244cdf0e10cSrcweir     aNumberSet.Put (SvxNumberInfoItem( m_pNumberFormatter, (const sal_uInt16)SID_ATTR_NUMBERFORMAT_INFO));
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     bool bPercent = ( pButton == &m_aPB_NumberFormatForPercent );
247cdf0e10cSrcweir 
248cdf0e10cSrcweir     sal_uLong& rnFormatKey = bPercent ? m_nNumberFormatForPercent : m_nNumberFormatForValue;
249cdf0e10cSrcweir     bool& rUseSourceFormat = bPercent ? m_bSourceFormatForPercent : m_bSourceFormatForValue;
250cdf0e10cSrcweir     bool& rbMixedState = bPercent ? m_bPercentFormatMixedState : m_bNumberFormatMixedState;
251cdf0e10cSrcweir     bool& rbSourceMixedState = bPercent ? m_bPercentSourceMixedState : m_bSourceFormatMixedState;
252cdf0e10cSrcweir 
253cdf0e10cSrcweir     if(!rbMixedState)
254cdf0e10cSrcweir         aNumberSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, rnFormatKey ));
255cdf0e10cSrcweir     aNumberSet.Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE, rUseSourceFormat ));
256cdf0e10cSrcweir 
257cdf0e10cSrcweir     NumberFormatDialog aDlg(m_pWindow, aNumberSet);
258cdf0e10cSrcweir     if( bPercent )
259cdf0e10cSrcweir         aDlg.SetText( String( SchResId( STR_DLG_NUMBERFORMAT_FOR_PERCENTAGE_VALUE ) ) );
260cdf0e10cSrcweir     if( RET_OK == aDlg.Execute() )
261cdf0e10cSrcweir     {
262cdf0e10cSrcweir         const SfxItemSet* pResult = aDlg.GetOutputItemSet();
263cdf0e10cSrcweir         if( pResult )
264cdf0e10cSrcweir         {
265cdf0e10cSrcweir             bool bOldSource = rUseSourceFormat;
266cdf0e10cSrcweir             sal_uLong nOldFormat = rnFormatKey;
267cdf0e10cSrcweir             bool bOldMixedState = rbMixedState || rbSourceMixedState;
268cdf0e10cSrcweir 
269cdf0e10cSrcweir             rbMixedState = !lcl_ReadNumberFormatFromItemSet( *pResult, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, rnFormatKey, rUseSourceFormat, rbSourceMixedState );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir             //todo this maybe can be removed when the numberformatter dialog does handle mixed state for source format correctly
272cdf0e10cSrcweir             if( bOldMixedState && bOldSource == rUseSourceFormat && nOldFormat == rnFormatKey )
273cdf0e10cSrcweir                 rbMixedState = rbSourceMixedState = true;
274cdf0e10cSrcweir         }
275cdf0e10cSrcweir     }
276cdf0e10cSrcweir     return 0;
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
IMPL_LINK(DataLabelResources,CheckHdl,CheckBox *,pBox)279cdf0e10cSrcweir IMPL_LINK( DataLabelResources, CheckHdl, CheckBox*, pBox )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir     if( pBox )
282cdf0e10cSrcweir         pBox->EnableTriState( sal_False );
283cdf0e10cSrcweir     EnableControls();
284cdf0e10cSrcweir     return 0;
285cdf0e10cSrcweir }
286cdf0e10cSrcweir 
EnableControls()287cdf0e10cSrcweir void DataLabelResources::EnableControls()
288cdf0e10cSrcweir {
289cdf0e10cSrcweir     m_aCBSymbol.Enable( m_aCBNumber.IsChecked() || (m_aCBPercent.IsChecked() && m_aCBPercent.IsEnabled()) || m_aCBCategory.IsChecked() );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     //enable separator
292cdf0e10cSrcweir     {
293cdf0e10cSrcweir         long nNumberOfCheckedLabelParts = 0;
294cdf0e10cSrcweir         if( m_aCBNumber.IsChecked() )
295cdf0e10cSrcweir             ++nNumberOfCheckedLabelParts;
296cdf0e10cSrcweir         if( m_aCBPercent.IsChecked() && m_aCBPercent.IsEnabled() )
297cdf0e10cSrcweir             ++nNumberOfCheckedLabelParts;
298cdf0e10cSrcweir         if( m_aCBCategory.IsChecked() )
299cdf0e10cSrcweir             ++nNumberOfCheckedLabelParts;
300cdf0e10cSrcweir         m_aSeparatorResources.Enable( nNumberOfCheckedLabelParts > 1 );
301cdf0e10cSrcweir         bool bEnableTextDir = nNumberOfCheckedLabelParts > 0;
302cdf0e10cSrcweir         m_aFT_TextDirection.Enable( bEnableTextDir );
303cdf0e10cSrcweir         m_aLB_TextDirection.Enable( bEnableTextDir );
304cdf0e10cSrcweir         bool bEnablePlacement = nNumberOfCheckedLabelParts > 0 && m_aLB_LabelPlacement.GetEntryCount()>1;
305cdf0e10cSrcweir         m_aFT_LabelPlacement.Enable( bEnablePlacement );
306cdf0e10cSrcweir         m_aLB_LabelPlacement.Enable( bEnablePlacement );
307cdf0e10cSrcweir     }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir     m_aPB_NumberFormatForValue.Enable( m_pNumberFormatter && m_aCBNumber.IsChecked() );
310cdf0e10cSrcweir     m_aPB_NumberFormatForPercent.Enable( m_pNumberFormatter && m_aCBPercent.IsChecked() && m_aCBPercent.IsEnabled() );
311cdf0e10cSrcweir 
312cdf0e10cSrcweir     bool bEnableRotation = ( m_aCBNumber.IsChecked() || m_aCBPercent.IsChecked() || m_aCBCategory.IsChecked() );
313cdf0e10cSrcweir     m_aFL_Rotate.Enable( bEnableRotation );
314cdf0e10cSrcweir     m_aDC_Dial.Enable( bEnableRotation );
315cdf0e10cSrcweir     m_aFT_Degrees.Enable( bEnableRotation );
316cdf0e10cSrcweir     m_aNF_Degrees.Enable( bEnableRotation );
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
FillItemSet(SfxItemSet & rOutAttrs) const319cdf0e10cSrcweir sal_Bool DataLabelResources::FillItemSet( SfxItemSet& rOutAttrs ) const
320cdf0e10cSrcweir {
321cdf0e10cSrcweir     if( m_aCBNumber.IsChecked() )
322cdf0e10cSrcweir     {
323cdf0e10cSrcweir         if( !m_bNumberFormatMixedState )
324cdf0e10cSrcweir             rOutAttrs.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, m_nNumberFormatForValue ));
325cdf0e10cSrcweir         if( !m_bSourceFormatMixedState )
326cdf0e10cSrcweir             rOutAttrs.Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE, m_bSourceFormatForValue ));
327cdf0e10cSrcweir     }
328cdf0e10cSrcweir     if( m_aCBPercent.IsChecked() )
329cdf0e10cSrcweir     {
330cdf0e10cSrcweir         if( !m_bPercentFormatMixedState )
331cdf0e10cSrcweir             rOutAttrs.Put( SfxUInt32Item( SCHATTR_PERCENT_NUMBERFORMAT_VALUE, m_nNumberFormatForPercent ));
332cdf0e10cSrcweir         if( !m_bPercentSourceMixedState )
333cdf0e10cSrcweir             rOutAttrs.Put( SfxBoolItem( SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_bSourceFormatForPercent ));
334cdf0e10cSrcweir     }
335cdf0e10cSrcweir 
336cdf0e10cSrcweir     if( m_aCBNumber.GetState()!= STATE_DONTKNOW )
337cdf0e10cSrcweir         rOutAttrs.Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_NUMBER, m_aCBNumber.IsChecked() ) );
338cdf0e10cSrcweir     if( m_aCBPercent.GetState()!= STATE_DONTKNOW )
339cdf0e10cSrcweir         rOutAttrs.Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_PERCENTAGE, m_aCBPercent.IsChecked() ) );
340cdf0e10cSrcweir     if( m_aCBCategory.GetState()!= STATE_DONTKNOW )
341cdf0e10cSrcweir         rOutAttrs.Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_CATEGORY, m_aCBCategory.IsChecked() ) );
342cdf0e10cSrcweir     if( m_aCBSymbol.GetState()!= STATE_DONTKNOW )
343cdf0e10cSrcweir         rOutAttrs.Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_SYMBOL, m_aCBSymbol.IsChecked()) );
344cdf0e10cSrcweir 
345cdf0e10cSrcweir     rOutAttrs.Put( SfxStringItem( SCHATTR_DATADESCR_SEPARATOR, m_aSeparatorResources.GetValue() ) );
346cdf0e10cSrcweir     ::std::map< sal_uInt16, sal_Int32 >::const_iterator aIt( m_aListBoxToPlacementMap.find(m_aLB_LabelPlacement.GetSelectEntryPos()) );
347cdf0e10cSrcweir     if(aIt!=m_aListBoxToPlacementMap.end())
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         sal_Int32 nValue = aIt->second;
350cdf0e10cSrcweir         rOutAttrs.Put( SfxInt32Item( SCHATTR_DATADESCR_PLACEMENT, nValue ) );
351cdf0e10cSrcweir     }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir     if( m_aLB_TextDirection.GetSelectEntryCount() > 0 )
354cdf0e10cSrcweir         rOutAttrs.Put( SfxInt32Item( EE_PARA_WRITINGDIR, m_aLB_TextDirection.GetSelectEntryValue() ) );
355cdf0e10cSrcweir 
356cdf0e10cSrcweir     if( m_aDC_Dial.IsVisible() )
357cdf0e10cSrcweir     {
358cdf0e10cSrcweir         sal_Int32 nDegrees = m_aDC_Dial.GetRotation();
359cdf0e10cSrcweir         rOutAttrs.Put(SfxInt32Item( SCHATTR_TEXT_DEGREES, nDegrees ) );
360cdf0e10cSrcweir     }
361cdf0e10cSrcweir 
362cdf0e10cSrcweir     return sal_True;
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
Reset(const SfxItemSet & rInAttrs)365cdf0e10cSrcweir void DataLabelResources::Reset(const SfxItemSet& rInAttrs)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     // default state
368cdf0e10cSrcweir     m_aCBSymbol.Enable( sal_False );
369cdf0e10cSrcweir 
370cdf0e10cSrcweir     lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_NUMBER, m_aCBNumber );
371cdf0e10cSrcweir     lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_PERCENTAGE, m_aCBPercent );
372cdf0e10cSrcweir     lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_CATEGORY, m_aCBCategory );
373cdf0e10cSrcweir     lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_SYMBOL, m_aCBSymbol );
374cdf0e10cSrcweir 
375cdf0e10cSrcweir     m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState );
376cdf0e10cSrcweir     m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent ,  m_bPercentSourceMixedState);
377cdf0e10cSrcweir 
378cdf0e10cSrcweir     const SfxPoolItem *pPoolItem = NULL;
379cdf0e10cSrcweir     if( rInAttrs.GetItemState(SCHATTR_DATADESCR_SEPARATOR, sal_True, &pPoolItem) == SFX_ITEM_SET )
380cdf0e10cSrcweir         m_aSeparatorResources.SetValue( ((const SfxStringItem*)pPoolItem)->GetValue() );
381cdf0e10cSrcweir     else
382cdf0e10cSrcweir         m_aSeparatorResources.SetDefault();
383cdf0e10cSrcweir 
384cdf0e10cSrcweir     if( rInAttrs.GetItemState(SCHATTR_DATADESCR_PLACEMENT, sal_True, &pPoolItem) == SFX_ITEM_SET )
385cdf0e10cSrcweir     {
386cdf0e10cSrcweir         sal_Int32 nPlacement = ((const SfxInt32Item*)pPoolItem)->GetValue();
387cdf0e10cSrcweir         ::std::map< sal_Int32, sal_uInt16 >::const_iterator aIt( m_aPlacementToListBoxMap.find(nPlacement) );
388cdf0e10cSrcweir         if(aIt!=m_aPlacementToListBoxMap.end())
389cdf0e10cSrcweir         {
390cdf0e10cSrcweir             sal_uInt16 nPos = aIt->second;
391cdf0e10cSrcweir             m_aLB_LabelPlacement.SelectEntryPos( nPos );
392cdf0e10cSrcweir         }
393cdf0e10cSrcweir         else
394cdf0e10cSrcweir             m_aLB_LabelPlacement.SetNoSelection();
395cdf0e10cSrcweir     }
396cdf0e10cSrcweir     else
397cdf0e10cSrcweir         m_aLB_LabelPlacement.SetNoSelection();
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     if( rInAttrs.GetItemState(EE_PARA_WRITINGDIR, sal_True, &pPoolItem ) == SFX_ITEM_SET )
400cdf0e10cSrcweir         m_aLB_TextDirection.SelectEntryValue( SvxFrameDirection(((const SvxFrameDirectionItem*)pPoolItem)->GetValue()) );
401cdf0e10cSrcweir 
402cdf0e10cSrcweir     if( rInAttrs.GetItemState( SCHATTR_TEXT_DEGREES, sal_True, &pPoolItem ) == SFX_ITEM_SET )
403cdf0e10cSrcweir     {
404cdf0e10cSrcweir         sal_Int32 nDegrees = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
405cdf0e10cSrcweir         m_aDC_Dial.SetRotation( nDegrees );
406cdf0e10cSrcweir     }
407cdf0e10cSrcweir     else
408cdf0e10cSrcweir     m_aDC_Dial.SetRotation( 0 );
409cdf0e10cSrcweir 
410cdf0e10cSrcweir     EnableControls();
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir //.............................................................................
414cdf0e10cSrcweir } //namespace chart
415cdf0e10cSrcweir //.............................................................................
416