vcl: allow for overriding the default PDF rendering resolution
[LibreOffice.git] / chart2 / source / controller / dialogs / res_DataLabel.cxx
blob2889bdb74f13614d8188c0c72b7d2074054e9316
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <TextDirectionListBox.hxx>
23 #include <chartview/ChartSfxItemIds.hxx>
24 #include "dlg_NumberFormat.hxx"
26 #include <svx/numinf.hxx>
27 #include <svl/eitem.hxx>
28 #include <svl/intitem.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/ilstitem.hxx>
31 #include <editeng/eeitem.hxx>
32 #include <editeng/frmdiritem.hxx>
33 #include <svx/svxids.hrc>
34 #include <osl/diagnose.h>
36 namespace chart
39 namespace
42 const OUStringLiteral our_aLBEntryMap[] = {" ", ", ", "; ", "\n"};
44 bool lcl_ReadNumberFormatFromItemSet( const SfxItemSet& rSet, sal_uInt16 nValueWhich, sal_uInt16 nSourceFormatWhich, sal_uLong& rnFormatKeyOut, bool& rbSourceFormatOut, bool& rbSourceFormatMixedStateOut )
46 bool bSet = false;
47 const SfxPoolItem *pItem1 = nullptr;
48 if( rSet.GetItemState( nValueWhich, true, &pItem1 ) == SfxItemState::SET )
50 const SfxUInt32Item * pNumItem = dynamic_cast< const SfxUInt32Item * >( pItem1 );
51 if( pNumItem )
53 rnFormatKeyOut = pNumItem->GetValue();
54 bSet = true;
58 rbSourceFormatMixedStateOut=true;
59 const SfxPoolItem *pItem2 = nullptr;
60 if( rSet.GetItemState( nSourceFormatWhich, true, &pItem2 ) == SfxItemState::SET )
62 const SfxBoolItem * pBoolItem = dynamic_cast< const SfxBoolItem * >( pItem2 );
63 if( pBoolItem )
65 rbSourceFormatOut = pBoolItem->GetValue();
66 rbSourceFormatMixedStateOut=false;
69 return bSet;
72 void lcl_setBoolItemToCheckBox(const SfxItemSet& rInAttrs, sal_uInt16 nWhichId, weld::CheckButton& rCheckbox)
74 const SfxPoolItem *pPoolItem = nullptr;
75 if( rInAttrs.GetItemState(nWhichId, true, &pPoolItem) == SfxItemState::SET )
76 rCheckbox.set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue());
77 else
78 rCheckbox.set_state(TRISTATE_INDET);
81 }//end anonymous namespace
83 DataLabelResources::DataLabelResources(weld::Builder* pBuilder, weld::Window* pParent, const SfxItemSet& rInAttrs)
84 : m_pNumberFormatter(nullptr)
85 , m_bNumberFormatMixedState(true)
86 , m_bPercentFormatMixedState(true)
87 , m_nNumberFormatForValue(0)
88 , m_nNumberFormatForPercent(11)
89 , m_bSourceFormatMixedState(true)
90 , m_bPercentSourceMixedState(true)
91 , m_bSourceFormatForValue(true)
92 , m_bSourceFormatForPercent(true)
93 , m_pWindow(pParent)
94 , m_pPool(rInAttrs.GetPool())
95 , m_xCBNumber(pBuilder->weld_check_button("CB_VALUE_AS_NUMBER"))
96 , m_xPB_NumberFormatForValue(pBuilder->weld_button("PB_NUMBERFORMAT"))
97 , m_xCBPercent(pBuilder->weld_check_button("CB_VALUE_AS_PERCENTAGE"))
98 , m_xPB_NumberFormatForPercent(pBuilder->weld_button("PB_PERCENT_NUMBERFORMAT"))
99 , m_xFT_NumberFormatForPercent(pBuilder->weld_label("STR_DLG_NUMBERFORMAT_FOR_PERCENTAGE_VALUE"))
100 , m_xCBCategory(pBuilder->weld_check_button("CB_CATEGORY"))
101 , m_xCBSymbol(pBuilder->weld_check_button("CB_SYMBOL"))
102 , m_xCBWrapText(pBuilder->weld_check_button("CB_WRAP_TEXT"))
103 , m_xSeparatorResources(pBuilder->weld_widget("boxSEPARATOR"))
104 , m_xLB_Separator(pBuilder->weld_combo_box("LB_TEXT_SEPARATOR"))
105 , m_xBxLabelPlacement(pBuilder->weld_widget("boxPLACEMENT"))
106 , m_xLB_LabelPlacement(pBuilder->weld_combo_box("LB_LABEL_PLACEMENT"))
107 , m_xBxOrientation(pBuilder->weld_widget("boxORIENTATION"))
108 , m_xFT_Dial(pBuilder->weld_label("CT_LABEL_DIAL"))
109 , m_xNF_Degrees(pBuilder->weld_spin_button("NF_LABEL_DEGREES"))
110 , m_xBxTextDirection(pBuilder->weld_widget("boxTXT_DIRECTION"))
111 , m_xLB_TextDirection(new TextDirectionListBox(pBuilder->weld_combo_box("LB_LABEL_TEXTDIR")))
112 , m_xDC_Dial(new weld::CustomWeld(*pBuilder, "CT_DIAL", m_aDC_Dial))
114 m_aDC_Dial.SetText(m_xFT_Dial->get_label());
116 //fill label placement list
117 std::map< sal_Int32, OUString > aPlacementToStringMap;
118 for( sal_Int32 nEnum=0; nEnum<m_xLB_LabelPlacement->get_count(); ++nEnum )
119 aPlacementToStringMap[nEnum] = m_xLB_LabelPlacement->get_text(static_cast<sal_uInt16>(nEnum));
122 std::vector< sal_Int32 > aAvailablePlacementList;
123 const SfxPoolItem *pPoolItem = nullptr;
124 if( rInAttrs.GetItemState(SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS, true, &pPoolItem) == SfxItemState::SET )
125 aAvailablePlacementList = static_cast<const SfxIntegerListItem*>(pPoolItem)->GetList();
127 m_xLB_LabelPlacement->clear();
128 for( size_t nN=0; nN<aAvailablePlacementList.size(); ++nN )
130 sal_uInt16 nListBoxPos = static_cast<sal_uInt16>( nN );
131 sal_Int32 nPlacement = aAvailablePlacementList[nN];
132 m_aPlacementToListBoxMap[nPlacement]=nListBoxPos;
133 m_aListBoxToPlacementMap[nListBoxPos]=nPlacement;
134 m_xLB_LabelPlacement->append_text( aPlacementToStringMap[nPlacement] );
137 //some click handler
138 m_xPB_NumberFormatForValue->connect_clicked( LINK( this, DataLabelResources, NumberFormatDialogHdl ) );
139 m_xPB_NumberFormatForPercent->connect_clicked( LINK( this, DataLabelResources, NumberFormatDialogHdl ) );
140 m_xCBNumber->connect_toggled( LINK( this, DataLabelResources, CheckHdl ));
141 m_xCBPercent->connect_toggled( LINK( this, DataLabelResources, CheckHdl ));
142 m_xCBCategory->connect_toggled( LINK( this, DataLabelResources, CheckHdl ));
143 m_xCBSymbol->connect_toggled( LINK( this, DataLabelResources, CheckHdl ));
144 m_xCBWrapText->connect_toggled( LINK( this, DataLabelResources, CheckHdl ));
146 m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState );
147 m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState);
149 if( rInAttrs.GetItemState(SCHATTR_DATADESCR_NO_PERCENTVALUE, true, &pPoolItem) == SfxItemState::SET )
151 bool bForbidPercentValue = rInAttrs.Get( SCHATTR_DATADESCR_NO_PERCENTVALUE ).GetValue();
152 if( bForbidPercentValue )
153 m_xCBPercent->set_sensitive(false);
156 m_aDC_Dial.SetLinkedField(m_xNF_Degrees.get());
159 DataLabelResources::~DataLabelResources()
163 void DataLabelResources::SetNumberFormatter( SvNumberFormatter* pFormatter )
165 m_pNumberFormatter = pFormatter;
168 IMPL_LINK(DataLabelResources, NumberFormatDialogHdl, weld::Button&, rButton, void)
170 if( !m_pPool || !m_pNumberFormatter )
172 OSL_FAIL("Missing item pool or number formatter");
173 return;
176 if (&rButton == m_xPB_NumberFormatForValue.get() && !m_xCBNumber->get_active())
177 m_xCBNumber->set_active(true);
178 else if (&rButton == m_xPB_NumberFormatForPercent.get() && !m_xCBPercent->get_active())
179 m_xCBPercent->set_active(true);
181 SfxItemSet aNumberSet = NumberFormatDialog::CreateEmptyItemSetForNumberFormatDialog( *m_pPool );
182 aNumberSet.Put (SvxNumberInfoItem( m_pNumberFormatter, static_cast<sal_uInt16>(SID_ATTR_NUMBERFORMAT_INFO)));
184 bool bPercent = (&rButton == m_xPB_NumberFormatForPercent.get());
186 sal_uLong& rnFormatKey = bPercent ? m_nNumberFormatForPercent : m_nNumberFormatForValue;
187 bool& rUseSourceFormat = bPercent ? m_bSourceFormatForPercent : m_bSourceFormatForValue;
188 bool& rbMixedState = bPercent ? m_bPercentFormatMixedState : m_bNumberFormatMixedState;
189 bool& rbSourceMixedState = bPercent ? m_bPercentSourceMixedState : m_bSourceFormatMixedState;
191 if(!rbMixedState)
192 aNumberSet.Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, rnFormatKey ));
193 aNumberSet.Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE, rUseSourceFormat ));
195 NumberFormatDialog aDlg(m_pWindow, aNumberSet);
196 if( bPercent )
197 aDlg.set_title(m_xFT_NumberFormatForPercent->get_label());
198 if (aDlg.run() == RET_OK)
200 const SfxItemSet* pResult = aDlg.GetOutputItemSet();
201 if( pResult )
203 bool bOldSource = rUseSourceFormat;
204 sal_uLong nOldFormat = rnFormatKey;
205 bool bOldMixedState = rbMixedState || rbSourceMixedState;
207 rbMixedState = !lcl_ReadNumberFormatFromItemSet( *pResult, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, rnFormatKey, rUseSourceFormat, rbSourceMixedState );
209 //todo this maybe can be removed when the numberformatter dialog does handle mixed state for source format correctly
210 if( bOldMixedState && bOldSource == rUseSourceFormat && nOldFormat == rnFormatKey )
211 rbMixedState = rbSourceMixedState = true;
216 IMPL_LINK_NOARG(DataLabelResources, CheckHdl, weld::ToggleButton&, void)
218 EnableControls();
221 void DataLabelResources::EnableControls()
223 m_xCBSymbol->set_sensitive( m_xCBNumber->get_active() || (m_xCBPercent->get_active() && m_xCBPercent->get_sensitive())
224 || m_xCBCategory->get_active() );
226 m_xCBWrapText->set_sensitive( m_xCBNumber->get_active() || (m_xCBPercent->get_active() && m_xCBPercent->get_sensitive())
227 || m_xCBCategory->get_active() );
229 // Enable or disable separator, placement and direction based on the check
230 // box states. Note that the check boxes are tri-state.
232 long nNumberOfCheckedLabelParts = 0;
233 if (m_xCBNumber->get_state() != TRISTATE_FALSE)
234 ++nNumberOfCheckedLabelParts;
235 if (m_xCBPercent->get_state() != TRISTATE_FALSE && m_xCBPercent->get_sensitive())
236 ++nNumberOfCheckedLabelParts;
237 if (m_xCBCategory->get_state() != TRISTATE_FALSE)
238 ++nNumberOfCheckedLabelParts;
240 m_xSeparatorResources->set_sensitive( nNumberOfCheckedLabelParts > 1 );
242 bool bEnableTextDir = nNumberOfCheckedLabelParts > 0;
243 m_xBxTextDirection->set_sensitive( bEnableTextDir );
244 bool bEnablePlacement = nNumberOfCheckedLabelParts > 0 && m_xLB_LabelPlacement->get_count()>1;
245 m_xBxLabelPlacement->set_sensitive( bEnablePlacement );
248 m_xPB_NumberFormatForValue->set_sensitive( m_pNumberFormatter && m_xCBNumber->get_active() );
249 m_xPB_NumberFormatForPercent->set_sensitive( m_pNumberFormatter && m_xCBPercent->get_active() && m_xCBPercent->get_sensitive() );
251 bool bEnableRotation = ( m_xCBNumber->get_active() || m_xCBPercent->get_active() || m_xCBCategory->get_active() );
252 m_xBxOrientation->set_sensitive( bEnableRotation );
255 void DataLabelResources::FillItemSet( SfxItemSet* rOutAttrs ) const
257 if( m_xCBNumber->get_active() )
259 if( !m_bNumberFormatMixedState )
260 rOutAttrs->Put( SfxUInt32Item( SID_ATTR_NUMBERFORMAT_VALUE, m_nNumberFormatForValue ));
261 if( !m_bSourceFormatMixedState )
262 rOutAttrs->Put( SfxBoolItem( SID_ATTR_NUMBERFORMAT_SOURCE, m_bSourceFormatForValue ));
264 if( m_xCBPercent->get_active() )
266 if( !m_bPercentFormatMixedState )
267 rOutAttrs->Put( SfxUInt32Item( SCHATTR_PERCENT_NUMBERFORMAT_VALUE, m_nNumberFormatForPercent ));
268 if( !m_bPercentSourceMixedState )
269 rOutAttrs->Put( SfxBoolItem( SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_bSourceFormatForPercent ));
272 if( m_xCBNumber->get_state()!= TRISTATE_INDET )
273 rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_NUMBER, m_xCBNumber->get_active() ) );
274 if( m_xCBPercent->get_state()!= TRISTATE_INDET )
275 rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_PERCENTAGE, m_xCBPercent->get_active() ) );
276 if( m_xCBCategory->get_state()!= TRISTATE_INDET )
277 rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_CATEGORY, m_xCBCategory->get_active() ) );
278 if( m_xCBSymbol->get_state()!= TRISTATE_INDET )
279 rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_SYMBOL, m_xCBSymbol->get_active()) );
280 if( m_xCBWrapText->get_state()!= TRISTATE_INDET )
281 rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_WRAP_TEXT, m_xCBWrapText->get_active()) );
283 OUString aSep = our_aLBEntryMap[m_xLB_Separator->get_active()];
284 rOutAttrs->Put( SfxStringItem( SCHATTR_DATADESCR_SEPARATOR, aSep) );
286 std::map< sal_uInt16, sal_Int32 >::const_iterator aIt( m_aListBoxToPlacementMap.find(m_xLB_LabelPlacement->get_active()) );
287 if(aIt!=m_aListBoxToPlacementMap.end())
289 sal_Int32 nValue = aIt->second;
290 rOutAttrs->Put( SfxInt32Item( SCHATTR_DATADESCR_PLACEMENT, nValue ) );
293 if (m_xLB_TextDirection->get_active() != -1)
294 rOutAttrs->Put( SvxFrameDirectionItem( m_xLB_TextDirection->get_active_id(), EE_PARA_WRITINGDIR ) );
296 if( m_aDC_Dial.IsVisible() )
298 sal_Int32 nDegrees = m_aDC_Dial.GetRotation();
299 rOutAttrs->Put(SfxInt32Item( SCHATTR_TEXT_DEGREES, nDegrees ) );
303 void DataLabelResources::Reset(const SfxItemSet& rInAttrs)
305 // default state
306 m_xCBSymbol->set_sensitive( false );
308 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_NUMBER, *m_xCBNumber );
309 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_PERCENTAGE, *m_xCBPercent );
310 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_CATEGORY, *m_xCBCategory );
311 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_SYMBOL, *m_xCBSymbol );
312 lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_WRAP_TEXT, *m_xCBWrapText );
314 m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState );
315 m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState);
317 const SfxPoolItem *pPoolItem = nullptr;
318 if( rInAttrs.GetItemState(SCHATTR_DATADESCR_SEPARATOR, true, &pPoolItem) == SfxItemState::SET )
319 for(size_t i=0; i < SAL_N_ELEMENTS(our_aLBEntryMap); ++i )
321 if( our_aLBEntryMap[i] == static_cast<const SfxStringItem*>(pPoolItem)->GetValue())
322 m_xLB_Separator->set_active( i );
324 else
325 m_xLB_Separator->set_active( 0 );
327 if( rInAttrs.GetItemState(SCHATTR_DATADESCR_PLACEMENT, true, &pPoolItem) == SfxItemState::SET )
329 sal_Int32 nPlacement = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue();
330 std::map< sal_Int32, sal_uInt16 >::const_iterator aIt( m_aPlacementToListBoxMap.find(nPlacement) );
331 if(aIt!=m_aPlacementToListBoxMap.end())
333 sal_uInt16 nPos = aIt->second;
334 m_xLB_LabelPlacement->set_active( nPos );
336 else
337 m_xLB_LabelPlacement->set_active(-1);
339 else
340 m_xLB_LabelPlacement->set_active(-1);
342 if( rInAttrs.GetItemState(EE_PARA_WRITINGDIR, true, &pPoolItem ) == SfxItemState::SET )
343 m_xLB_TextDirection->set_active_id( static_cast<const SvxFrameDirectionItem*>(pPoolItem)->GetValue() );
345 if( rInAttrs.GetItemState( SCHATTR_TEXT_DEGREES, true, &pPoolItem ) == SfxItemState::SET )
347 sal_Int32 nDegrees = static_cast< const SfxInt32Item * >( pPoolItem )->GetValue();
348 m_aDC_Dial.SetRotation( nDegrees );
350 else
351 m_aDC_Dial.SetRotation( 0 );
353 EnableControls();
356 } //namespace chart
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */