diff options
Diffstat (limited to 'chart2/source/controller/dialogs/res_DataLabel.cxx')
-rw-r--r-- | chart2/source/controller/dialogs/res_DataLabel.cxx | 165 |
1 files changed, 92 insertions, 73 deletions
diff --git a/chart2/source/controller/dialogs/res_DataLabel.cxx b/chart2/source/controller/dialogs/res_DataLabel.cxx index 7934e90871dc..98db10ff1873 100644 --- a/chart2/source/controller/dialogs/res_DataLabel.cxx +++ b/chart2/source/controller/dialogs/res_DataLabel.cxx @@ -46,41 +46,36 @@ namespace const std::u16string_view our_aLBEntryMap[] = {u" ", u", ", u"; ", u"\n", u". "}; -bool lcl_ReadNumberFormatFromItemSet( const SfxItemSet& rSet, sal_uInt16 nValueWhich, sal_uInt16 nSourceFormatWhich, sal_uLong& rnFormatKeyOut, bool& rbSourceFormatOut, bool& rbSourceFormatMixedStateOut ) +bool lcl_ReadNumberFormatFromItemSet( const SfxItemSet& rSet, TypedWhichId<SfxUInt32Item> nValueWhich, TypedWhichId<SfxBoolItem> nSourceFormatWhich, sal_uInt32& rnFormatKeyOut, bool& rbSourceFormatOut, bool& rbSourceFormatMixedStateOut ) { bool bSet = false; - const SfxPoolItem *pItem1 = nullptr; - if( rSet.GetItemState( nValueWhich, true, &pItem1 ) == SfxItemState::SET ) + if( const SfxUInt32Item* pNumItem = rSet.GetItemIfSet( nValueWhich ) ) { - const SfxUInt32Item * pNumItem = dynamic_cast< const SfxUInt32Item * >( pItem1 ); - if( pNumItem ) - { - rnFormatKeyOut = pNumItem->GetValue(); - bSet = true; - } + rnFormatKeyOut = pNumItem->GetValue(); + bSet = true; } rbSourceFormatMixedStateOut=true; - const SfxPoolItem *pItem2 = nullptr; - if( rSet.GetItemState( nSourceFormatWhich, true, &pItem2 ) == SfxItemState::SET ) + if( const SfxBoolItem * pBoolItem = rSet.GetItemIfSet( nSourceFormatWhich ) ) { - const SfxBoolItem * pBoolItem = dynamic_cast< const SfxBoolItem * >( pItem2 ); - if( pBoolItem ) - { - rbSourceFormatOut = pBoolItem->GetValue(); - rbSourceFormatMixedStateOut=false; - } + rbSourceFormatOut = pBoolItem->GetValue(); + rbSourceFormatMixedStateOut=false; } return bSet; } -void lcl_setBoolItemToCheckBox(const SfxItemSet& rInAttrs, sal_uInt16 nWhichId, weld::CheckButton& rCheckbox) +void lcl_setBoolItemToCheckBox(const SfxItemSet& rInAttrs, TypedWhichId<SfxBoolItem> nWhichId, weld::CheckButton& rCheckbox, weld::TriStateEnabled& rTriState) { - const SfxPoolItem *pPoolItem = nullptr; - if( rInAttrs.GetItemState(nWhichId, true, &pPoolItem) == SfxItemState::SET ) - rCheckbox.set_active(static_cast<const SfxBoolItem*>(pPoolItem)->GetValue()); + if( const SfxBoolItem* pPoolItem = rInAttrs.GetItemIfSet(nWhichId) ) + { + rCheckbox.set_active(pPoolItem->GetValue()); + rTriState.bTriStateEnabled = false; + } else + { rCheckbox.set_state(TRISTATE_INDET); + rTriState.bTriStateEnabled = true; + } } }//end anonymous namespace @@ -97,26 +92,25 @@ DataLabelResources::DataLabelResources(weld::Builder* pBuilder, weld::Window* pP , m_bSourceFormatForPercent(true) , m_pWindow(pParent) , m_pPool(rInAttrs.GetPool()) - , m_xCBNumber(pBuilder->weld_check_button("CB_VALUE_AS_NUMBER")) - , m_xPB_NumberFormatForValue(pBuilder->weld_button("PB_NUMBERFORMAT")) - , m_xCBPercent(pBuilder->weld_check_button("CB_VALUE_AS_PERCENTAGE")) - , m_xPB_NumberFormatForPercent(pBuilder->weld_button("PB_PERCENT_NUMBERFORMAT")) - , m_xFT_NumberFormatForPercent(pBuilder->weld_label("STR_DLG_NUMBERFORMAT_FOR_PERCENTAGE_VALUE")) - , m_xCBCategory(pBuilder->weld_check_button("CB_CATEGORY")) - , m_xCBSymbol(pBuilder->weld_check_button("CB_SYMBOL")) - , m_xCBWrapText(pBuilder->weld_check_button("CB_WRAP_TEXT")) - , m_xSeparatorResources(pBuilder->weld_widget("boxSEPARATOR")) - , m_xLB_Separator(pBuilder->weld_combo_box("LB_TEXT_SEPARATOR")) - , m_xBxLabelPlacement(pBuilder->weld_widget("boxPLACEMENT")) - , m_xLB_LabelPlacement(pBuilder->weld_combo_box("LB_LABEL_PLACEMENT")) - , m_xBxOrientation(pBuilder->weld_widget("boxORIENTATION")) - , m_xFT_Dial(pBuilder->weld_label("CT_LABEL_DIAL")) - , m_xNF_Degrees(pBuilder->weld_metric_spin_button("NF_LABEL_DEGREES", FieldUnit::DEGREE)) - , m_xBxTextDirection(pBuilder->weld_widget("boxTXT_DIRECTION")) - , m_xLB_TextDirection(new TextDirectionListBox(pBuilder->weld_combo_box("LB_LABEL_TEXTDIR"))) + , m_xCBNumber(pBuilder->weld_check_button(u"CB_VALUE_AS_NUMBER"_ustr)) + , m_xPB_NumberFormatForValue(pBuilder->weld_button(u"PB_NUMBERFORMAT"_ustr)) + , m_xCBPercent(pBuilder->weld_check_button(u"CB_VALUE_AS_PERCENTAGE"_ustr)) + , m_xPB_NumberFormatForPercent(pBuilder->weld_button(u"PB_PERCENT_NUMBERFORMAT"_ustr)) + , m_xFT_NumberFormatForPercent(pBuilder->weld_label(u"STR_DLG_NUMBERFORMAT_FOR_PERCENTAGE_VALUE"_ustr)) + , m_xCBCategory(pBuilder->weld_check_button(u"CB_CATEGORY"_ustr)) + , m_xCBSymbol(pBuilder->weld_check_button(u"CB_SYMBOL"_ustr)) + , m_xCBDataSeries(pBuilder->weld_check_button(u"CB_DATA_SERIES_NAME"_ustr)) + , m_xCBWrapText(pBuilder->weld_check_button(u"CB_WRAP_TEXT"_ustr)) + , m_xLB_Separator(pBuilder->weld_combo_box(u"LB_TEXT_SEPARATOR"_ustr)) + , m_xLB_LabelPlacement(pBuilder->weld_combo_box(u"LB_LABEL_PLACEMENT"_ustr)) + , m_xBxOrientation(pBuilder->weld_widget(u"boxORIENTATION"_ustr)) + , m_xFT_Dial(pBuilder->weld_label(u"CT_LABEL_DIAL"_ustr)) + , m_xNF_Degrees(pBuilder->weld_metric_spin_button(u"NF_LABEL_DEGREES"_ustr, FieldUnit::DEGREE)) + , m_xBxTextDirection(pBuilder->weld_widget(u"boxTXT_DIRECTION"_ustr)) + , m_aLB_TextDirection(pBuilder->weld_combo_box(u"LB_LABEL_TEXTDIR"_ustr)) , m_xDC_Dial(new svx::DialControl) - , m_xDC_DialWin(new weld::CustomWeld(*pBuilder, "CT_DIAL", *m_xDC_Dial)) - , m_xCBCustomLeaderLines(pBuilder->weld_check_button("CB_CUSTOM_LEADER_LINES")) + , m_xDC_DialWin(new weld::CustomWeld(*pBuilder, u"CT_DIAL"_ustr, *m_xDC_Dial)) + , m_xCBCustomLeaderLines(pBuilder->weld_check_button(u"CB_CUSTOM_LEADER_LINES"_ustr)) { m_xDC_Dial->SetText(m_xFT_Dial->get_label()); @@ -127,9 +121,8 @@ DataLabelResources::DataLabelResources(weld::Builder* pBuilder, weld::Window* pP std::vector< sal_Int32 > aAvailablePlacementList; - const SfxPoolItem *pPoolItem = nullptr; - if( rInAttrs.GetItemState(SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS, true, &pPoolItem) == SfxItemState::SET ) - aAvailablePlacementList = static_cast<const SfxIntegerListItem*>(pPoolItem)->GetList(); + if( const SfxIntegerListItem* pPlacementsItem = rInAttrs.GetItemIfSet(SCHATTR_DATADESCR_AVAILABLE_PLACEMENTS) ) + aAvailablePlacementList = pPlacementsItem->GetList(); m_xLB_LabelPlacement->clear(); for( size_t nN=0; nN<aAvailablePlacementList.size(); ++nN ) @@ -148,15 +141,16 @@ DataLabelResources::DataLabelResources(weld::Builder* pBuilder, weld::Window* pP m_xCBPercent->connect_toggled( LINK( this, DataLabelResources, CheckHdl )); m_xCBCategory->connect_toggled( LINK( this, DataLabelResources, CheckHdl )); m_xCBSymbol->connect_toggled( LINK( this, DataLabelResources, CheckHdl )); + m_xCBDataSeries->connect_toggled( LINK( this, DataLabelResources, CheckHdl )); m_xCBWrapText->connect_toggled( LINK( this, DataLabelResources, CheckHdl )); m_xCBCustomLeaderLines->connect_toggled( LINK( this, DataLabelResources, CheckHdl )); m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState ); m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState); - if( rInAttrs.GetItemState(SCHATTR_DATADESCR_NO_PERCENTVALUE, true, &pPoolItem) == SfxItemState::SET ) + if( const SfxBoolItem* pNoPercentValueItem = rInAttrs.GetItemIfSet(SCHATTR_DATADESCR_NO_PERCENTVALUE) ) { - bool bForbidPercentValue = rInAttrs.Get( SCHATTR_DATADESCR_NO_PERCENTVALUE ).GetValue(); + bool bForbidPercentValue = pNoPercentValueItem->GetValue(); if( bForbidPercentValue ) m_xCBPercent->set_sensitive(false); } @@ -182,16 +176,22 @@ IMPL_LINK(DataLabelResources, NumberFormatDialogHdl, weld::Button&, rButton, voi } if (&rButton == m_xPB_NumberFormatForValue.get() && !m_xCBNumber->get_active()) + { m_xCBNumber->set_active(true); + m_aNumberState.bTriStateEnabled = false; + } else if (&rButton == m_xPB_NumberFormatForPercent.get() && !m_xCBPercent->get_active()) + { m_xCBPercent->set_active(true); + m_aPercentState.bTriStateEnabled = false; + } SfxItemSet aNumberSet = NumberFormatDialog::CreateEmptyItemSetForNumberFormatDialog( *m_pPool ); - aNumberSet.Put (SvxNumberInfoItem( m_pNumberFormatter, static_cast<sal_uInt16>(SID_ATTR_NUMBERFORMAT_INFO))); + aNumberSet.Put (SvxNumberInfoItem( m_pNumberFormatter, SID_ATTR_NUMBERFORMAT_INFO)); bool bPercent = (&rButton == m_xPB_NumberFormatForPercent.get()); - sal_uLong& rnFormatKey = bPercent ? m_nNumberFormatForPercent : m_nNumberFormatForValue; + sal_uInt32& rnFormatKey = bPercent ? m_nNumberFormatForPercent : m_nNumberFormatForValue; bool& rUseSourceFormat = bPercent ? m_bSourceFormatForPercent : m_bSourceFormatForValue; bool& rbMixedState = bPercent ? m_bPercentFormatMixedState : m_bNumberFormatMixedState; bool& rbSourceMixedState = bPercent ? m_bPercentSourceMixedState : m_bSourceFormatMixedState; @@ -210,7 +210,7 @@ IMPL_LINK(DataLabelResources, NumberFormatDialogHdl, weld::Button&, rButton, voi if( pResult ) { bool bOldSource = rUseSourceFormat; - sal_uLong nOldFormat = rnFormatKey; + sal_uInt32 nOldFormat = rnFormatKey; bool bOldMixedState = rbMixedState || rbSourceMixedState; rbMixedState = !lcl_ReadNumberFormatFromItemSet( *pResult, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, rnFormatKey, rUseSourceFormat, rbSourceMixedState ); @@ -221,18 +221,32 @@ IMPL_LINK(DataLabelResources, NumberFormatDialogHdl, weld::Button&, rButton, voi } } -IMPL_LINK_NOARG(DataLabelResources, CheckHdl, weld::ToggleButton&, void) +IMPL_LINK(DataLabelResources, CheckHdl, weld::Toggleable&, rToggle, void) { + if (&rToggle == m_xCBNumber.get()) + m_aNumberState.ButtonToggled(rToggle); + else if (&rToggle == m_xCBPercent.get()) + m_aPercentState.ButtonToggled(rToggle); + else if (&rToggle == m_xCBCategory.get()) + m_aCategoryState.ButtonToggled(rToggle); + else if (&rToggle == m_xCBSymbol.get()) + m_aSymbolState.ButtonToggled(rToggle); + else if (&rToggle == m_xCBDataSeries.get()) + m_aDataSeriesState.ButtonToggled(rToggle); + else if (&rToggle == m_xCBWrapText.get()) + m_aWrapTextState.ButtonToggled(rToggle); + else if (&rToggle == m_xCBCustomLeaderLines.get()) + m_aCustomLeaderLinesState.ButtonToggled(rToggle); EnableControls(); } void DataLabelResources::EnableControls() { m_xCBSymbol->set_sensitive( m_xCBNumber->get_active() || (m_xCBPercent->get_active() && m_xCBPercent->get_sensitive()) - || m_xCBCategory->get_active() ); + || m_xCBCategory->get_active() || m_xCBDataSeries->get_active()); m_xCBWrapText->set_sensitive( m_xCBNumber->get_active() || (m_xCBPercent->get_active() && m_xCBPercent->get_sensitive()) - || m_xCBCategory->get_active() ); + || m_xCBCategory->get_active() || m_xCBDataSeries->get_active() ); // Enable or disable separator, placement and direction based on the check // box states. Note that the check boxes are tri-state. @@ -244,20 +258,23 @@ void DataLabelResources::EnableControls() ++nNumberOfCheckedLabelParts; if (m_xCBCategory->get_state() != TRISTATE_FALSE) ++nNumberOfCheckedLabelParts; + if (m_xCBDataSeries->get_state() != TRISTATE_FALSE) + ++nNumberOfCheckedLabelParts; - m_xSeparatorResources->set_sensitive( nNumberOfCheckedLabelParts > 1 ); + m_xLB_Separator->set_sensitive( nNumberOfCheckedLabelParts > 1 ); bool bEnableTextDir = nNumberOfCheckedLabelParts > 0; m_xBxTextDirection->set_sensitive( bEnableTextDir ); bool bEnablePlacement = nNumberOfCheckedLabelParts > 0 && m_xLB_LabelPlacement->get_count()>1; - m_xBxLabelPlacement->set_sensitive( bEnablePlacement ); + m_xLB_LabelPlacement->set_sensitive( bEnablePlacement ); } m_xPB_NumberFormatForValue->set_sensitive( m_pNumberFormatter && m_xCBNumber->get_active() ); m_xPB_NumberFormatForPercent->set_sensitive( m_pNumberFormatter && m_xCBPercent->get_active() && m_xCBPercent->get_sensitive() ); - bool bEnableRotation = ( m_xCBNumber->get_active() || m_xCBPercent->get_active() || m_xCBCategory->get_active() ); - m_xBxOrientation->set_sensitive( bEnableRotation ); + bool bEnableRotation = (m_xCBNumber->get_active() || m_xCBPercent->get_active() + || m_xCBCategory->get_active() || m_xCBDataSeries->get_active()); + m_xBxOrientation->set_sensitive(bEnableRotation); } void DataLabelResources::FillItemSet( SfxItemSet* rOutAttrs ) const @@ -285,6 +302,8 @@ void DataLabelResources::FillItemSet( SfxItemSet* rOutAttrs ) const rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_CATEGORY, m_xCBCategory->get_active() ) ); if( m_xCBSymbol->get_state()!= TRISTATE_INDET ) rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_SYMBOL, m_xCBSymbol->get_active()) ); + if( m_xCBDataSeries->get_state()!= TRISTATE_INDET ) + rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME, m_xCBDataSeries->get_active()) ); if( m_xCBWrapText->get_state()!= TRISTATE_INDET ) rOutAttrs->Put( SfxBoolItem( SCHATTR_DATADESCR_WRAP_TEXT, m_xCBWrapText->get_active()) ); if( m_xCBCustomLeaderLines->get_state() != TRISTATE_INDET ) @@ -300,8 +319,8 @@ void DataLabelResources::FillItemSet( SfxItemSet* rOutAttrs ) const rOutAttrs->Put( SfxInt32Item( SCHATTR_DATADESCR_PLACEMENT, nValue ) ); } - if (m_xLB_TextDirection->get_active() != -1) - rOutAttrs->Put( SvxFrameDirectionItem( m_xLB_TextDirection->get_active_id(), EE_PARA_WRITINGDIR ) ); + if (m_aLB_TextDirection.get_active() != -1) + rOutAttrs->Put( SvxFrameDirectionItem( m_aLB_TextDirection.get_active_id(), EE_PARA_WRITINGDIR ) ); if( m_xDC_Dial->IsVisible() ) { @@ -315,29 +334,29 @@ void DataLabelResources::Reset(const SfxItemSet& rInAttrs) // default state m_xCBSymbol->set_sensitive( false ); - lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_NUMBER, *m_xCBNumber ); - lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_PERCENTAGE, *m_xCBPercent ); - lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_CATEGORY, *m_xCBCategory ); - lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_SYMBOL, *m_xCBSymbol ); - lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_WRAP_TEXT, *m_xCBWrapText ); - lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_CUSTOM_LEADER_LINES, *m_xCBCustomLeaderLines ); + lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_NUMBER, *m_xCBNumber, m_aNumberState ); + lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_PERCENTAGE, *m_xCBPercent, m_aPercentState ); + lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_CATEGORY, *m_xCBCategory, m_aCategoryState ); + lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_SYMBOL, *m_xCBSymbol, m_aSymbolState ); + lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_SHOW_DATA_SERIES_NAME, *m_xCBDataSeries, m_aDataSeriesState ); + lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_WRAP_TEXT, *m_xCBWrapText, m_aWrapTextState ); + lcl_setBoolItemToCheckBox( rInAttrs, SCHATTR_DATADESCR_CUSTOM_LEADER_LINES, *m_xCBCustomLeaderLines, m_aCustomLeaderLinesState ); m_bNumberFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SID_ATTR_NUMBERFORMAT_VALUE, SID_ATTR_NUMBERFORMAT_SOURCE, m_nNumberFormatForValue, m_bSourceFormatForValue, m_bSourceFormatMixedState ); m_bPercentFormatMixedState = !lcl_ReadNumberFormatFromItemSet( rInAttrs, SCHATTR_PERCENT_NUMBERFORMAT_VALUE, SCHATTR_PERCENT_NUMBERFORMAT_SOURCE, m_nNumberFormatForPercent, m_bSourceFormatForPercent , m_bPercentSourceMixedState); - const SfxPoolItem *pPoolItem = nullptr; - if( rInAttrs.GetItemState(SCHATTR_DATADESCR_SEPARATOR, true, &pPoolItem) == SfxItemState::SET ) - for(size_t i=0; i < SAL_N_ELEMENTS(our_aLBEntryMap); ++i ) + if( const SfxStringItem* pSeparatorItem = rInAttrs.GetItemIfSet(SCHATTR_DATADESCR_SEPARATOR) ) + for(size_t i=0; i < std::size(our_aLBEntryMap); ++i ) { - if( our_aLBEntryMap[i] == static_cast<const SfxStringItem*>(pPoolItem)->GetValue()) + if( our_aLBEntryMap[i] == pSeparatorItem->GetValue()) m_xLB_Separator->set_active( i ); } else m_xLB_Separator->set_active( 0 ); - if( rInAttrs.GetItemState(SCHATTR_DATADESCR_PLACEMENT, true, &pPoolItem) == SfxItemState::SET ) + if( const SfxInt32Item* pPlacementItem = rInAttrs.GetItemIfSet(SCHATTR_DATADESCR_PLACEMENT) ) { - sal_Int32 nPlacement = static_cast<const SfxInt32Item*>(pPoolItem)->GetValue(); + sal_Int32 nPlacement = pPlacementItem->GetValue(); std::map< sal_Int32, sal_uInt16 >::const_iterator aIt( m_aPlacementToListBoxMap.find(nPlacement) ); if(aIt!=m_aPlacementToListBoxMap.end()) { @@ -350,12 +369,12 @@ void DataLabelResources::Reset(const SfxItemSet& rInAttrs) else m_xLB_LabelPlacement->set_active(-1); - if( rInAttrs.GetItemState(EE_PARA_WRITINGDIR, true, &pPoolItem ) == SfxItemState::SET ) - m_xLB_TextDirection->set_active_id( static_cast<const SvxFrameDirectionItem*>(pPoolItem)->GetValue() ); + if( const SvxFrameDirectionItem* pDirectionItem = rInAttrs.GetItemIfSet(EE_PARA_WRITINGDIR) ) + m_aLB_TextDirection.set_active_id( pDirectionItem->GetValue() ); - if( rInAttrs.GetItemState( SCHATTR_TEXT_DEGREES, true, &pPoolItem ) == SfxItemState::SET ) + if( const SdrAngleItem* pAngleItem = rInAttrs.GetItemIfSet( SCHATTR_TEXT_DEGREES ) ) { - Degree100 nDegrees = static_cast< const SdrAngleItem * >( pPoolItem )->GetValue(); + Degree100 nDegrees = pAngleItem->GetValue(); m_xDC_Dial->SetRotation( nDegrees ); } else |