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 "res_DataLabel.hxx"
22 #include "chartview/ChartSfxItemIds.hxx"
23 #include "dlg_NumberFormat.hxx"
25 #include <svx/numinf.hxx>
26 #include <svl/eitem.hxx>
27 #include <svl/intitem.hxx>
28 #include <svl/stritem.hxx>
29 #include <svl/ilstitem.hxx>
30 #include <editeng/eeitem.hxx>
31 #include <editeng/frmdiritem.hxx>
32 #include <vcl/msgbox.hxx>
33 #include <svx/svxids.hrc>
34 #include <svl/zforlist.hxx>
35 #include <svtools/controldims.hrc>
43 bool lcl_ReadNumberFormatFromItemSet( const SfxItemSet
& rSet
, sal_uInt16 nValueWhich
, sal_uInt16 nSourceFormatWhich
, sal_uLong
& rnFormatKeyOut
, bool& rbSourceFormatOut
, bool& rbSourceFormatMixedStateOut
)
46 const SfxPoolItem
*pItem1
= NULL
;
47 if( rSet
.GetItemState( nValueWhich
, true, &pItem1
) == SfxItemState::SET
)
49 const SfxUInt32Item
* pNumItem
= dynamic_cast< const SfxUInt32Item
* >( pItem1
);
52 rnFormatKeyOut
= pNumItem
->GetValue();
57 rbSourceFormatMixedStateOut
=true;
58 const SfxPoolItem
*pItem2
= NULL
;
59 if( rSet
.GetItemState( nSourceFormatWhich
, true, &pItem2
) == SfxItemState::SET
)
61 const SfxBoolItem
* pBoolItem
= dynamic_cast< const SfxBoolItem
* >( pItem2
);
64 rbSourceFormatOut
= pBoolItem
->GetValue();
65 rbSourceFormatMixedStateOut
=false;
71 void lcl_setBoolItemToCheckBox( const SfxItemSet
& rInAttrs
, sal_uInt16 nWhichId
, CheckBox
& rCheckbox
)
73 rCheckbox
.EnableTriState( false );
75 const SfxPoolItem
*pPoolItem
= NULL
;
76 if( rInAttrs
.GetItemState(nWhichId
, true, &pPoolItem
) == SfxItemState::SET
)
77 rCheckbox
.Check( static_cast<const SfxBoolItem
*>(pPoolItem
)->GetValue() );
80 rCheckbox
.EnableTriState( true );
81 rCheckbox
.SetState( TRISTATE_INDET
);
85 }//end anonymous namespace
87 DataLabelResources::DataLabelResources(VclBuilderContainer
* pWindow
, vcl::Window
* pParent
, const SfxItemSet
& rInAttrs
)
89 m_pNumberFormatter(0),
90 m_bNumberFormatMixedState(true),
91 m_bPercentFormatMixedState(true),
92 m_nNumberFormatForValue(0),
93 m_nNumberFormatForPercent(11),
94 m_bSourceFormatMixedState(true),
95 m_bPercentSourceMixedState(true),
96 m_bSourceFormatForValue(true),
97 m_bSourceFormatForPercent(true),
99 m_pPool(rInAttrs
.GetPool())
101 pWindow
->get(m_pCBNumber
, "CB_VALUE_AS_NUMBER");
102 pWindow
->get(m_pPB_NumberFormatForValue
, "PB_NUMBERFORMAT");
103 pWindow
->get(m_pCBPercent
, "CB_VALUE_AS_PERCENTAGE");
104 pWindow
->get(m_pPB_NumberFormatForPercent
, "PB_PERCENT_NUMBERFORMAT");
105 pWindow
->get(m_pFT_NumberFormatForPercent
,"STR_DLG_NUMBERFORMAT_FOR_PERCENTAGE_VALUE");
106 pWindow
->get(m_pCBCategory
, "CB_CATEGORY");
107 pWindow
->get(m_pCBSymbol
, "CB_SYMBOL");
109 pWindow
->get(m_pBxLabelPlacement
, "boxPLACEMENT");
110 pWindow
->get(m_pLB_LabelPlacement
, "LB_LABEL_PLACEMENT");
112 pWindow
->get(m_pDC_Dial
, "CT_DIAL");
113 pWindow
->get(m_pFT_Dial
, "CT_LABEL_DIAL");
115 m_pDC_Dial
->SetText(m_pFT_Dial
->GetText());
117 pWindow
->get(m_pNF_Degrees
, "NF_LABEL_DEGREES");
118 pWindow
->get(m_pLB_TextDirection
, "LB_LABEL_TEXTDIR");
119 pWindow
->get(m_pBxTextDirection
, "boxTXT_DIRECTION");
120 pWindow
->get(m_pBxOrientation
, "boxORIENTATION");
122 pWindow
->get(m_pSeparatorResources
, "boxSEPARATOR");
123 pWindow
->get(m_pLB_Separator
, "LB_TEXT_SEPARATOR");
125 m_aEntryMap
[0] = " ";
126 m_aEntryMap
[1] = ", ";
127 m_aEntryMap
[2] = "; ";
128 m_aEntryMap
[3] = "\n" ;
130 //fill label placement list
131 std::map
< sal_Int32
, OUString
> aPlacementToStringMap
;
132 for( sal_Int32 nEnum
=0; nEnum
<m_pLB_LabelPlacement
->GetEntryCount(); ++nEnum
)
133 aPlacementToStringMap
[nEnum
] = m_pLB_LabelPlacement
->GetEntry(static_cast<sal_uInt16
>(nEnum
));
135 ::com::sun::star::uno::Sequence
< sal_Int32
> aAvailabelPlacementList
;
136 const SfxPoolItem
*pPoolItem
= NULL
;
137 if( rInAttrs
.GetItemState(SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS
, true, &pPoolItem
) == SfxItemState::SET
)
138 aAvailabelPlacementList
= static_cast<const SfxIntegerListItem
*>(pPoolItem
)->GetConstSequence();
140 m_pLB_LabelPlacement
->Clear();
141 for( sal_Int32 nN
=0; nN
<aAvailabelPlacementList
.getLength(); ++nN
)
143 sal_uInt16 nListBoxPos
= static_cast<sal_uInt16
>( nN
);
144 sal_Int32 nPlacement
= aAvailabelPlacementList
[nN
];
145 m_aPlacementToListBoxMap
[nPlacement
]=nListBoxPos
;
146 m_aListBoxToPlacementMap
[nListBoxPos
]=nPlacement
;
147 m_pLB_LabelPlacement
->InsertEntry( aPlacementToStringMap
[nPlacement
] );
149 m_pLB_LabelPlacement
->SetDropDownLineCount(m_pLB_LabelPlacement
->GetEntryCount());
152 m_pPB_NumberFormatForValue
->SetClickHdl( LINK( this, DataLabelResources
, NumberFormatDialogHdl
) );
153 m_pPB_NumberFormatForPercent
->SetClickHdl( LINK( this, DataLabelResources
, NumberFormatDialogHdl
) );
154 m_pCBNumber
->SetClickHdl( LINK( this, DataLabelResources
, CheckHdl
));
155 m_pCBPercent
->SetClickHdl( LINK( this, DataLabelResources
, CheckHdl
));
156 m_pCBCategory
->SetClickHdl( LINK( this, DataLabelResources
, CheckHdl
));
157 m_pCBSymbol
->SetClickHdl( LINK( this, DataLabelResources
, CheckHdl
));
159 m_bNumberFormatMixedState
= !lcl_ReadNumberFormatFromItemSet( rInAttrs
, SID_ATTR_NUMBERFORMAT_VALUE
, SID_ATTR_NUMBERFORMAT_SOURCE
, m_nNumberFormatForValue
, m_bSourceFormatForValue
, m_bSourceFormatMixedState
);
160 m_bPercentFormatMixedState
= !lcl_ReadNumberFormatFromItemSet( rInAttrs
, SCHATTR_PERCENT_NUMBERFORMAT_VALUE
, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE
, m_nNumberFormatForPercent
, m_bSourceFormatForPercent
, m_bPercentSourceMixedState
);
162 if( rInAttrs
.GetItemState(SCHATTR_DATADESCR_NO_PERCENTVALUE
, true, &pPoolItem
) == SfxItemState::SET
)
164 bool bForbidPercentValue
= (static_cast< const SfxBoolItem
& >( rInAttrs
.Get( SCHATTR_DATADESCR_NO_PERCENTVALUE
)).GetValue() );
165 if( bForbidPercentValue
)
166 m_pCBPercent
->Enable(false);
169 m_pDC_Dial
->SetLinkedField( m_pNF_Degrees
);
172 DataLabelResources::~DataLabelResources()
176 void DataLabelResources::SetNumberFormatter( SvNumberFormatter
* pFormatter
)
178 m_pNumberFormatter
= pFormatter
;
181 IMPL_LINK( DataLabelResources
, NumberFormatDialogHdl
, PushButton
*, pButton
)
183 if( !m_pPool
|| !m_pNumberFormatter
)
185 OSL_FAIL("Missing item pool or number formatter");
189 if( pButton
== m_pPB_NumberFormatForValue
&& !m_pCBNumber
->IsChecked())
190 m_pCBNumber
->Check();
191 else if( pButton
== m_pPB_NumberFormatForPercent
&& !m_pCBPercent
->IsChecked())
192 m_pCBPercent
->Check();
194 SfxItemSet aNumberSet
= NumberFormatDialog::CreateEmptyItemSetForNumberFormatDialog( *m_pPool
);
195 aNumberSet
.Put (SvxNumberInfoItem( m_pNumberFormatter
, (const sal_uInt16
)SID_ATTR_NUMBERFORMAT_INFO
));
197 bool bPercent
= ( pButton
== m_pPB_NumberFormatForPercent
);
199 sal_uLong
& rnFormatKey
= bPercent
? m_nNumberFormatForPercent
: m_nNumberFormatForValue
;
200 bool& rUseSourceFormat
= bPercent
? m_bSourceFormatForPercent
: m_bSourceFormatForValue
;
201 bool& rbMixedState
= bPercent
? m_bPercentFormatMixedState
: m_bNumberFormatMixedState
;
202 bool& rbSourceMixedState
= bPercent
? m_bPercentSourceMixedState
: m_bSourceFormatMixedState
;
205 aNumberSet
.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE
, rnFormatKey
));
206 aNumberSet
.Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE
, rUseSourceFormat
));
208 ScopedVclPtrInstance
< NumberFormatDialog
> aDlg(m_pWindow
, aNumberSet
);
210 aDlg
->SetText( m_pFT_NumberFormatForPercent
->GetText());
211 if( RET_OK
== aDlg
->Execute() )
213 const SfxItemSet
* pResult
= aDlg
->GetOutputItemSet();
216 bool bOldSource
= rUseSourceFormat
;
217 sal_uLong nOldFormat
= rnFormatKey
;
218 bool bOldMixedState
= rbMixedState
|| rbSourceMixedState
;
220 rbMixedState
= !lcl_ReadNumberFormatFromItemSet( *pResult
, SID_ATTR_NUMBERFORMAT_VALUE
, SID_ATTR_NUMBERFORMAT_SOURCE
, rnFormatKey
, rUseSourceFormat
, rbSourceMixedState
);
222 //todo this maybe can be removed when the numberformatter dialog does handle mixed state for source format correctly
223 if( bOldMixedState
&& bOldSource
== rUseSourceFormat
&& nOldFormat
== rnFormatKey
)
224 rbMixedState
= rbSourceMixedState
= true;
230 IMPL_LINK( DataLabelResources
, CheckHdl
, CheckBox
*, pBox
)
233 pBox
->EnableTriState( false );
238 void DataLabelResources::EnableControls()
240 m_pCBSymbol
->Enable( m_pCBNumber
->IsChecked() || (m_pCBPercent
->IsChecked() && m_pCBPercent
->IsEnabled())
241 || m_pCBCategory
->IsChecked() );
243 // Enable or disable separator, placement and direction based on the check
244 // box states. Note that the check boxes are tri-state.
246 long nNumberOfCheckedLabelParts
= 0;
247 if (m_pCBNumber
->GetState() != TRISTATE_FALSE
)
248 ++nNumberOfCheckedLabelParts
;
249 if (m_pCBPercent
->GetState() != TRISTATE_FALSE
&& m_pCBPercent
->IsEnabled())
250 ++nNumberOfCheckedLabelParts
;
251 if (m_pCBCategory
->GetState() != TRISTATE_FALSE
)
252 ++nNumberOfCheckedLabelParts
;
254 m_pSeparatorResources
->Enable( nNumberOfCheckedLabelParts
> 1 );
256 bool bEnableTextDir
= nNumberOfCheckedLabelParts
> 0;
257 m_pBxTextDirection
->Enable( bEnableTextDir
);
258 bool bEnablePlacement
= nNumberOfCheckedLabelParts
> 0 && m_pLB_LabelPlacement
->GetEntryCount()>1;
259 m_pBxLabelPlacement
->Enable( bEnablePlacement
);
262 m_pPB_NumberFormatForValue
->Enable( m_pNumberFormatter
&& m_pCBNumber
->IsChecked() );
263 m_pPB_NumberFormatForPercent
->Enable( m_pNumberFormatter
&& m_pCBPercent
->IsChecked() && m_pCBPercent
->IsEnabled() );
265 bool bEnableRotation
= ( m_pCBNumber
->IsChecked() || m_pCBPercent
->IsChecked() || m_pCBCategory
->IsChecked() );
266 m_pBxOrientation
->Enable( bEnableRotation
);
269 bool DataLabelResources::FillItemSet( SfxItemSet
* rOutAttrs
) const
271 if( m_pCBNumber
->IsChecked() )
273 if( !m_bNumberFormatMixedState
)
274 rOutAttrs
->Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE
, m_nNumberFormatForValue
));
275 if( !m_bSourceFormatMixedState
)
276 rOutAttrs
->Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE
, m_bSourceFormatForValue
));
278 if( m_pCBPercent
->IsChecked() )
280 if( !m_bPercentFormatMixedState
)
281 rOutAttrs
->Put( SfxUInt32Item( SCHATTR_PERCENT_NUMBERFORMAT_VALUE
, m_nNumberFormatForPercent
));
282 if( !m_bPercentSourceMixedState
)
283 rOutAttrs
->Put( SfxBoolItem( SCHATTR_PERCENT_NUMBERFORMAT_SOURCE
, m_bSourceFormatForPercent
));
286 if( m_pCBNumber
->GetState()!= TRISTATE_INDET
)
287 rOutAttrs
->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_NUMBER
, m_pCBNumber
->IsChecked() ) );
288 if( m_pCBPercent
->GetState()!= TRISTATE_INDET
)
289 rOutAttrs
->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_PERCENTAGE
, m_pCBPercent
->IsChecked() ) );
290 if( m_pCBCategory
->GetState()!= TRISTATE_INDET
)
291 rOutAttrs
->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_CATEGORY
, m_pCBCategory
->IsChecked() ) );
292 if( m_pCBSymbol
->GetState()!= TRISTATE_INDET
)
293 rOutAttrs
->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_SYMBOL
, m_pCBSymbol
->IsChecked()) );
295 OUString aSep
= m_aEntryMap
[m_pLB_Separator
->GetSelectEntryPos()];
296 rOutAttrs
->Put( SfxStringItem( SCHATTR_DATADESCR_SEPARATOR
, aSep
) );
298 ::std::map
< sal_uInt16
, sal_Int32
>::const_iterator
aIt( m_aListBoxToPlacementMap
.find(m_pLB_LabelPlacement
->GetSelectEntryPos()) );
299 if(aIt
!=m_aListBoxToPlacementMap
.end())
301 sal_Int32 nValue
= aIt
->second
;
302 rOutAttrs
->Put( SfxInt32Item( SCHATTR_DATADESCR_PLACEMENT
, nValue
) );
305 if( m_pLB_TextDirection
->GetSelectEntryCount() > 0 )
306 rOutAttrs
->Put( SvxFrameDirectionItem( m_pLB_TextDirection
->GetSelectEntryValue(), EE_PARA_WRITINGDIR
) );
308 if( m_pDC_Dial
->IsVisible() )
310 sal_Int32 nDegrees
= m_pDC_Dial
->GetRotation();
311 rOutAttrs
->Put(SfxInt32Item( SCHATTR_TEXT_DEGREES
, nDegrees
) );
317 void DataLabelResources::Reset(const SfxItemSet
& rInAttrs
)
320 m_pCBSymbol
->Enable( false );
322 lcl_setBoolItemToCheckBox( rInAttrs
, SCHATTR_DATADESCR_SHOW_NUMBER
, *m_pCBNumber
);
323 lcl_setBoolItemToCheckBox( rInAttrs
, SCHATTR_DATADESCR_SHOW_PERCENTAGE
, *m_pCBPercent
);
324 lcl_setBoolItemToCheckBox( rInAttrs
, SCHATTR_DATADESCR_SHOW_CATEGORY
, *m_pCBCategory
);
325 lcl_setBoolItemToCheckBox( rInAttrs
, SCHATTR_DATADESCR_SHOW_SYMBOL
, *m_pCBSymbol
);
327 m_bNumberFormatMixedState
= !lcl_ReadNumberFormatFromItemSet( rInAttrs
, SID_ATTR_NUMBERFORMAT_VALUE
, SID_ATTR_NUMBERFORMAT_SOURCE
, m_nNumberFormatForValue
, m_bSourceFormatForValue
, m_bSourceFormatMixedState
);
328 m_bPercentFormatMixedState
= !lcl_ReadNumberFormatFromItemSet( rInAttrs
, SCHATTR_PERCENT_NUMBERFORMAT_VALUE
, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE
, m_nNumberFormatForPercent
, m_bSourceFormatForPercent
, m_bPercentSourceMixedState
);
330 const SfxPoolItem
*pPoolItem
= NULL
;
331 if( rInAttrs
.GetItemState(SCHATTR_DATADESCR_SEPARATOR
, true, &pPoolItem
) == SfxItemState::SET
)
332 for(sal_Int32 i
=0; i
< NUMBER_SEPARATORS
; ++i
)
334 if( m_aEntryMap
[i
] == static_cast<const SfxStringItem
*>(pPoolItem
)->GetValue())
335 m_pLB_Separator
->SelectEntryPos( i
);
338 m_pLB_Separator
->SelectEntryPos( 0 );
340 if( rInAttrs
.GetItemState(SCHATTR_DATADESCR_PLACEMENT
, true, &pPoolItem
) == SfxItemState::SET
)
342 sal_Int32 nPlacement
= static_cast<const SfxInt32Item
*>(pPoolItem
)->GetValue();
343 ::std::map
< sal_Int32
, sal_uInt16
>::const_iterator
aIt( m_aPlacementToListBoxMap
.find(nPlacement
) );
344 if(aIt
!=m_aPlacementToListBoxMap
.end())
346 sal_uInt16 nPos
= aIt
->second
;
347 m_pLB_LabelPlacement
->SelectEntryPos( nPos
);
350 m_pLB_LabelPlacement
->SetNoSelection();
353 m_pLB_LabelPlacement
->SetNoSelection();
355 if( rInAttrs
.GetItemState(EE_PARA_WRITINGDIR
, true, &pPoolItem
) == SfxItemState::SET
)
356 m_pLB_TextDirection
->SelectEntryValue( SvxFrameDirection(static_cast<const SvxFrameDirectionItem
*>(pPoolItem
)->GetValue()) );
358 if( rInAttrs
.GetItemState( SCHATTR_TEXT_DEGREES
, true, &pPoolItem
) == SfxItemState::SET
)
360 sal_Int32 nDegrees
= static_cast< const SfxInt32Item
* >( pPoolItem
)->GetValue();
361 m_pDC_Dial
->SetRotation( nDegrees
);
364 m_pDC_Dial
->SetRotation( 0 );
371 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */