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