Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "res_DataLabel.hxx"
21 :
22 : #include "chartview/ChartSfxItemIds.hxx"
23 : #include "dlg_NumberFormat.hxx"
24 :
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>
36 :
37 : namespace chart
38 : {
39 :
40 : namespace
41 : {
42 :
43 0 : bool lcl_ReadNumberFormatFromItemSet( const SfxItemSet& rSet, sal_uInt16 nValueWhich, sal_uInt16 nSourceFormatWhich, sal_uLong& rnFormatKeyOut, bool& rbSourceFormatOut, bool& rbSourceFormatMixedStateOut )
44 : {
45 0 : bool bSet = false;
46 0 : const SfxPoolItem *pItem1 = NULL;
47 0 : if( rSet.GetItemState( nValueWhich, true, &pItem1 ) == SfxItemState::SET )
48 : {
49 0 : const SfxUInt32Item * pNumItem = dynamic_cast< const SfxUInt32Item * >( pItem1 );
50 0 : if( pNumItem )
51 : {
52 0 : rnFormatKeyOut = pNumItem->GetValue();
53 0 : bSet = true;
54 : }
55 : }
56 :
57 0 : rbSourceFormatMixedStateOut=true;
58 0 : const SfxPoolItem *pItem2 = NULL;
59 0 : if( rSet.GetItemState( nSourceFormatWhich, true, &pItem2 ) == SfxItemState::SET )
60 : {
61 0 : const SfxBoolItem * pBoolItem = dynamic_cast< const SfxBoolItem * >( pItem2 );
62 0 : if( pBoolItem )
63 : {
64 0 : rbSourceFormatOut = pBoolItem->GetValue();
65 0 : rbSourceFormatMixedStateOut=false;
66 : }
67 : }
68 0 : return bSet;
69 : }
70 :
71 0 : void lcl_setBoolItemToCheckBox( const SfxItemSet& rInAttrs, sal_uInt16 nWhichId, CheckBox& rCheckbox )
72 : {
73 0 : rCheckbox.EnableTriState( false );
74 :
75 0 : const SfxPoolItem *pPoolItem = NULL;
76 0 : if( rInAttrs.GetItemState(nWhichId, true, &pPoolItem) == SfxItemState::SET )
77 0 : rCheckbox.Check( static_cast<const SfxBoolItem*>(pPoolItem)->GetValue() );
78 : else
79 : {
80 0 : rCheckbox.EnableTriState( true );
81 0 : rCheckbox.SetState( TRISTATE_INDET );
82 : }
83 0 : }
84 :
85 : }//end anonymous namespace
86 :
87 0 : DataLabelResources::DataLabelResources(VclBuilderContainer* pWindow, vcl::Window* pParent, const SfxItemSet& rInAttrs )
88 : :
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),
98 : m_pWindow(pParent),
99 0 : m_pPool(rInAttrs.GetPool())
100 : {
101 0 : pWindow->get(m_pCBNumber, "CB_VALUE_AS_NUMBER");
102 0 : pWindow->get(m_pPB_NumberFormatForValue, "PB_NUMBERFORMAT");
103 0 : pWindow->get(m_pCBPercent, "CB_VALUE_AS_PERCENTAGE");
104 0 : pWindow->get(m_pPB_NumberFormatForPercent, "PB_PERCENT_NUMBERFORMAT");
105 0 : pWindow->get(m_pFT_NumberFormatForPercent,"STR_DLG_NUMBERFORMAT_FOR_PERCENTAGE_VALUE");
106 0 : pWindow->get(m_pCBCategory, "CB_CATEGORY");
107 0 : pWindow->get(m_pCBSymbol, "CB_SYMBOL");
108 :
109 0 : pWindow->get(m_pBxLabelPlacement, "boxPLACEMENT");
110 0 : pWindow->get(m_pLB_LabelPlacement, "LB_LABEL_PLACEMENT");
111 :
112 0 : pWindow->get(m_pDC_Dial, "CT_DIAL");
113 0 : pWindow->get(m_pFT_Dial, "CT_LABEL_DIAL");
114 :
115 0 : m_pDC_Dial->SetText(m_pFT_Dial->GetText());
116 :
117 0 : pWindow->get(m_pNF_Degrees, "NF_LABEL_DEGREES");
118 0 : pWindow->get(m_pLB_TextDirection, "LB_LABEL_TEXTDIR");
119 0 : pWindow->get(m_pBxTextDirection, "boxTXT_DIRECTION");
120 0 : pWindow->get(m_pBxOrientation, "boxORIENTATION");
121 :
122 0 : pWindow->get(m_pSeparatorResources, "boxSEPARATOR");
123 0 : pWindow->get(m_pLB_Separator, "LB_TEXT_SEPARATOR");
124 :
125 0 : m_aEntryMap[0] = " ";
126 0 : m_aEntryMap[1] = ", ";
127 0 : m_aEntryMap[2] = "; ";
128 0 : m_aEntryMap[3] = "\n" ;
129 :
130 : //fill label placement list
131 0 : std::map< sal_Int32, OUString > aPlacementToStringMap;
132 0 : for( sal_Int32 nEnum=0; nEnum<m_pLB_LabelPlacement->GetEntryCount(); ++nEnum )
133 0 : aPlacementToStringMap[nEnum] = m_pLB_LabelPlacement->GetEntry(static_cast<sal_uInt16>(nEnum));
134 :
135 0 : ::com::sun::star::uno::Sequence < sal_Int32 > aAvailabelPlacementList;
136 0 : const SfxPoolItem *pPoolItem = NULL;
137 0 : if( rInAttrs.GetItemState(SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS, true, &pPoolItem) == SfxItemState::SET )
138 0 : aAvailabelPlacementList = static_cast<const SfxIntegerListItem*>(pPoolItem)->GetConstSequence();
139 :
140 0 : m_pLB_LabelPlacement->Clear();
141 0 : for( sal_Int32 nN=0; nN<aAvailabelPlacementList.getLength(); ++nN )
142 : {
143 0 : sal_uInt16 nListBoxPos = static_cast<sal_uInt16>( nN );
144 0 : sal_Int32 nPlacement = aAvailabelPlacementList[nN];
145 0 : m_aPlacementToListBoxMap[nPlacement]=nListBoxPos;
146 0 : m_aListBoxToPlacementMap[nListBoxPos]=nPlacement;
147 0 : m_pLB_LabelPlacement->InsertEntry( aPlacementToStringMap[nPlacement] );
148 : }
149 0 : m_pLB_LabelPlacement->SetDropDownLineCount(m_pLB_LabelPlacement->GetEntryCount());
150 :
151 : //some click handler
152 0 : m_pPB_NumberFormatForValue->SetClickHdl( LINK( this, DataLabelResources, NumberFormatDialogHdl ) );
153 0 : m_pPB_NumberFormatForPercent->SetClickHdl( LINK( this, DataLabelResources, NumberFormatDialogHdl ) );
154 0 : m_pCBNumber->SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
155 0 : m_pCBPercent->SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
156 0 : m_pCBCategory->SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
157 0 : m_pCBSymbol->SetClickHdl( LINK( this, DataLabelResources, CheckHdl ));
158 :
159 0 : m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState );
160 0 : m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState);
161 :
162 0 : if( rInAttrs.GetItemState(SCHATTR_DATADESCR_NO_PERCENTVALUE, true, &pPoolItem) == SfxItemState::SET )
163 : {
164 0 : bool bForbidPercentValue = (static_cast< const SfxBoolItem & >( rInAttrs.Get( SCHATTR_DATADESCR_NO_PERCENTVALUE )).GetValue() );
165 0 : if( bForbidPercentValue )
166 0 : m_pCBPercent->Enable(false);
167 : }
168 :
169 0 : m_pDC_Dial->SetLinkedField( m_pNF_Degrees );
170 0 : }
171 :
172 0 : DataLabelResources::~DataLabelResources()
173 : {
174 0 : }
175 :
176 0 : void DataLabelResources::SetNumberFormatter( SvNumberFormatter* pFormatter )
177 : {
178 0 : m_pNumberFormatter = pFormatter;
179 0 : }
180 :
181 0 : IMPL_LINK( DataLabelResources, NumberFormatDialogHdl, PushButton *, pButton )
182 : {
183 0 : if( !m_pPool || !m_pNumberFormatter )
184 : {
185 : OSL_FAIL("Missing item pool or number formatter");
186 0 : return 1;
187 : }
188 :
189 0 : if( pButton == m_pPB_NumberFormatForValue && !m_pCBNumber->IsChecked())
190 0 : m_pCBNumber->Check();
191 0 : else if( pButton == m_pPB_NumberFormatForPercent && !m_pCBPercent->IsChecked())
192 0 : m_pCBPercent->Check();
193 :
194 0 : SfxItemSet aNumberSet = NumberFormatDialog::CreateEmptyItemSetForNumberFormatDialog( *m_pPool );
195 0 : aNumberSet.Put (SvxNumberInfoItem( m_pNumberFormatter, (const sal_uInt16)SID_ATTR_NUMBERFORMAT_INFO));
196 :
197 0 : bool bPercent = ( pButton == m_pPB_NumberFormatForPercent );
198 :
199 0 : sal_uLong& rnFormatKey = bPercent ? m_nNumberFormatForPercent : m_nNumberFormatForValue;
200 0 : bool& rUseSourceFormat = bPercent ? m_bSourceFormatForPercent : m_bSourceFormatForValue;
201 0 : bool& rbMixedState = bPercent ? m_bPercentFormatMixedState : m_bNumberFormatMixedState;
202 0 : bool& rbSourceMixedState = bPercent ? m_bPercentSourceMixedState : m_bSourceFormatMixedState;
203 :
204 0 : if(!rbMixedState)
205 0 : aNumberSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, rnFormatKey ));
206 0 : aNumberSet.Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE, rUseSourceFormat ));
207 :
208 0 : ScopedVclPtrInstance< NumberFormatDialog > aDlg(m_pWindow, aNumberSet);
209 0 : if( bPercent )
210 0 : aDlg->SetText( m_pFT_NumberFormatForPercent->GetText());
211 0 : if( RET_OK == aDlg->Execute() )
212 : {
213 0 : const SfxItemSet* pResult = aDlg->GetOutputItemSet();
214 0 : if( pResult )
215 : {
216 0 : bool bOldSource = rUseSourceFormat;
217 0 : sal_uLong nOldFormat = rnFormatKey;
218 0 : bool bOldMixedState = rbMixedState || rbSourceMixedState;
219 :
220 0 : rbMixedState = !lcl_ReadNumberFormatFromItemSet( *pResult, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, rnFormatKey, rUseSourceFormat, rbSourceMixedState );
221 :
222 : //todo this maybe can be removed when the numberformatter dialog does handle mixed state for source format correctly
223 0 : if( bOldMixedState && bOldSource == rUseSourceFormat && nOldFormat == rnFormatKey )
224 0 : rbMixedState = rbSourceMixedState = true;
225 : }
226 : }
227 0 : return 0;
228 : }
229 :
230 0 : IMPL_LINK( DataLabelResources, CheckHdl, CheckBox*, pBox )
231 : {
232 0 : if( pBox )
233 0 : pBox->EnableTriState( false );
234 0 : EnableControls();
235 0 : return 0;
236 : }
237 :
238 0 : void DataLabelResources::EnableControls()
239 : {
240 0 : m_pCBSymbol->Enable( m_pCBNumber->IsChecked() || (m_pCBPercent->IsChecked() && m_pCBPercent->IsEnabled())
241 0 : || m_pCBCategory->IsChecked() );
242 :
243 : // Enable or disable separator, placement and direction based on the check
244 : // box states. Note that the check boxes are tri-state.
245 : {
246 0 : long nNumberOfCheckedLabelParts = 0;
247 0 : if (m_pCBNumber->GetState() != TRISTATE_FALSE)
248 0 : ++nNumberOfCheckedLabelParts;
249 0 : if (m_pCBPercent->GetState() != TRISTATE_FALSE && m_pCBPercent->IsEnabled())
250 0 : ++nNumberOfCheckedLabelParts;
251 0 : if (m_pCBCategory->GetState() != TRISTATE_FALSE)
252 0 : ++nNumberOfCheckedLabelParts;
253 :
254 0 : m_pSeparatorResources->Enable( nNumberOfCheckedLabelParts > 1 );
255 :
256 0 : bool bEnableTextDir = nNumberOfCheckedLabelParts > 0;
257 0 : m_pBxTextDirection->Enable( bEnableTextDir );
258 0 : bool bEnablePlacement = nNumberOfCheckedLabelParts > 0 && m_pLB_LabelPlacement->GetEntryCount()>1;
259 0 : m_pBxLabelPlacement->Enable( bEnablePlacement );
260 : }
261 :
262 0 : m_pPB_NumberFormatForValue->Enable( m_pNumberFormatter && m_pCBNumber->IsChecked() );
263 0 : m_pPB_NumberFormatForPercent->Enable( m_pNumberFormatter && m_pCBPercent->IsChecked() && m_pCBPercent->IsEnabled() );
264 :
265 0 : bool bEnableRotation = ( m_pCBNumber->IsChecked() || m_pCBPercent->IsChecked() || m_pCBCategory->IsChecked() );
266 0 : m_pBxOrientation->Enable( bEnableRotation );
267 0 : }
268 :
269 0 : bool DataLabelResources::FillItemSet( SfxItemSet* rOutAttrs ) const
270 : {
271 0 : if( m_pCBNumber->IsChecked() )
272 : {
273 0 : if( !m_bNumberFormatMixedState )
274 0 : rOutAttrs->Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, m_nNumberFormatForValue ));
275 0 : if( !m_bSourceFormatMixedState )
276 0 : rOutAttrs->Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE, m_bSourceFormatForValue ));
277 : }
278 0 : if( m_pCBPercent->IsChecked() )
279 : {
280 0 : if( !m_bPercentFormatMixedState )
281 0 : rOutAttrs->Put( SfxUInt32Item( SCHATTR_PERCENT_NUMBERFORMAT_VALUE, m_nNumberFormatForPercent ));
282 0 : if( !m_bPercentSourceMixedState )
283 0 : rOutAttrs->Put( SfxBoolItem( SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_bSourceFormatForPercent ));
284 : }
285 :
286 0 : if( m_pCBNumber->GetState()!= TRISTATE_INDET )
287 0 : rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_NUMBER, m_pCBNumber->IsChecked() ) );
288 0 : if( m_pCBPercent->GetState()!= TRISTATE_INDET )
289 0 : rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_PERCENTAGE, m_pCBPercent->IsChecked() ) );
290 0 : if( m_pCBCategory->GetState()!= TRISTATE_INDET )
291 0 : rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_CATEGORY, m_pCBCategory->IsChecked() ) );
292 0 : if( m_pCBSymbol->GetState()!= TRISTATE_INDET )
293 0 : rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_SYMBOL, m_pCBSymbol->IsChecked()) );
294 :
295 0 : OUString aSep = m_aEntryMap[m_pLB_Separator->GetSelectEntryPos()];
296 0 : rOutAttrs->Put( SfxStringItem( SCHATTR_DATADESCR_SEPARATOR, aSep) );
297 :
298 0 : ::std::map< sal_uInt16, sal_Int32 >::const_iterator aIt( m_aListBoxToPlacementMap.find(m_pLB_LabelPlacement->GetSelectEntryPos()) );
299 0 : if(aIt!=m_aListBoxToPlacementMap.end())
300 : {
301 0 : sal_Int32 nValue = aIt->second;
302 0 : rOutAttrs->Put( SfxInt32Item( SCHATTR_DATADESCR_PLACEMENT, nValue ) );
303 : }
304 :
305 0 : if( m_pLB_TextDirection->GetSelectEntryCount() > 0 )
306 0 : rOutAttrs->Put( SvxFrameDirectionItem( m_pLB_TextDirection->GetSelectEntryValue(), EE_PARA_WRITINGDIR ) );
307 :
308 0 : if( m_pDC_Dial->IsVisible() )
309 : {
310 0 : sal_Int32 nDegrees = m_pDC_Dial->GetRotation();
311 0 : rOutAttrs->Put(SfxInt32Item( SCHATTR_TEXT_DEGREES, nDegrees ) );
312 : }
313 :
314 0 : return true;
315 : }
316 :
317 0 : void DataLabelResources::Reset(const SfxItemSet& rInAttrs)
318 : {
319 : // default state
320 0 : m_pCBSymbol->Enable( false );
321 :
322 0 : lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_NUMBER, *m_pCBNumber );
323 0 : lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_PERCENTAGE, *m_pCBPercent );
324 0 : lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_CATEGORY, *m_pCBCategory );
325 0 : lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_SYMBOL, *m_pCBSymbol );
326 :
327 0 : m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState );
328 0 : m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState);
329 :
330 0 : const SfxPoolItem *pPoolItem = NULL;
331 0 : if( rInAttrs.GetItemState(SCHATTR_DATADESCR_SEPARATOR, true, &pPoolItem) == SfxItemState::SET )
332 0 : for(sal_Int32 i=0; i < NUMBER_SEPARATORS; ++i )
333 : {
334 0 : if( m_aEntryMap[i] == static_cast<const SfxStringItem*>(pPoolItem)->GetValue())
335 0 : m_pLB_Separator->SelectEntryPos( i );
336 : }
337 : else
338 0 : m_pLB_Separator->SelectEntryPos( 0 );
339 :
340 0 : if( rInAttrs.GetItemState(SCHATTR_DATADESCR_PLACEMENT, true, &pPoolItem) == SfxItemState::SET )
341 : {
342 0 : sal_Int32 nPlacement = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
343 0 : ::std::map< sal_Int32, sal_uInt16 >::const_iterator aIt( m_aPlacementToListBoxMap.find(nPlacement) );
344 0 : if(aIt!=m_aPlacementToListBoxMap.end())
345 : {
346 0 : sal_uInt16 nPos = aIt->second;
347 0 : m_pLB_LabelPlacement->SelectEntryPos( nPos );
348 : }
349 : else
350 0 : m_pLB_LabelPlacement->SetNoSelection();
351 : }
352 : else
353 0 : m_pLB_LabelPlacement->SetNoSelection();
354 :
355 0 : if( rInAttrs.GetItemState(EE_PARA_WRITINGDIR, true, &pPoolItem ) == SfxItemState::SET )
356 0 : m_pLB_TextDirection->SelectEntryValue( SvxFrameDirection(static_cast<const SvxFrameDirectionItem*>(pPoolItem)->GetValue()) );
357 :
358 0 : if( rInAttrs.GetItemState( SCHATTR_TEXT_DEGREES, true, &pPoolItem ) == SfxItemState::SET )
359 : {
360 0 : sal_Int32 nDegrees = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
361 0 : m_pDC_Dial->SetRotation( nDegrees );
362 : }
363 : else
364 0 : m_pDC_Dial->SetRotation( 0 );
365 :
366 0 : EnableControls();
367 0 : }
368 :
369 57 : } //namespace chart
370 :
371 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|