tdf#127802 support tristate for hidden/unhidden text

Change-Id: I9a8ad72ae3ee45ac2521e662b17d3d22d98aa055
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101168
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/cui/source/inc/chardlg.hxx b/cui/source/inc/chardlg.hxx
index 0600784..e81284c 100644
--- a/cui/source/inc/chardlg.hxx
+++ b/cui/source/inc/chardlg.hxx
@@ -168,6 +168,11 @@ private:
    sal_uInt16                 m_nHtmlMode;
    bool                       m_bUnderlineColorDisabled;

    weld::TriStateEnabled m_aOutlineState;
    weld::TriStateEnabled m_aShadowState;
    weld::TriStateEnabled m_aHiddenState;
    weld::TriStateEnabled m_aIndividualWordsState;

    std::unique_ptr<weld::Label> m_xFontColorFT;
    std::unique_ptr<ColorListBox> m_xFontColorLB;
    std::unique_ptr<weld::Label> m_xFontTransparencyFT;
@@ -203,8 +208,10 @@ private:

    void SelectHdl_Impl(const weld::ComboBox*);
    DECL_LINK(SelectListBoxHdl_Impl, weld::ComboBox&, void);
    DECL_LINK(OutlineBtnClickHdl, weld::ToggleButton&, void);
    DECL_LINK(ShadowBtnClickHdl, weld::ToggleButton&, void);
    DECL_LINK(HiddenBtnClickHdl, weld::ToggleButton&, void);
    DECL_LINK(CbClickHdl_Impl, weld::ToggleButton&, void);
    DECL_LINK(TristClickHdl_Impl, weld::ToggleButton&, void);
    DECL_LINK(ColorBoxSelectHdl_Impl, ColorListBox&, void);
    DECL_LINK(ModifyFontTransparencyHdl_Impl, weld::MetricSpinButton&, void);

diff --git a/cui/source/tabpages/chardlg.cxx b/cui/source/tabpages/chardlg.cxx
index 307be4f..077a62a 100644
--- a/cui/source/tabpages/chardlg.cxx
+++ b/cui/source/tabpages/chardlg.cxx
@@ -1419,10 +1419,10 @@ void SvxCharEffectsPage::Initialize()

    m_xEffectsLB->set_active( 0 );

    m_xHiddenBtn->connect_toggled(LINK(this, SvxCharEffectsPage, HiddenBtnClickHdl));
    m_xIndividualWordsBtn->connect_toggled(LINK(this, SvxCharEffectsPage, CbClickHdl_Impl));
    Link<weld::ToggleButton&,void> aLink2 = LINK(this, SvxCharEffectsPage, TristClickHdl_Impl);
    m_xOutlineBtn->connect_toggled(aLink2);
    m_xShadowBtn->connect_toggled(aLink2);
    m_xOutlineBtn->connect_toggled(LINK(this, SvxCharEffectsPage, OutlineBtnClickHdl));
    m_xShadowBtn->connect_toggled(LINK(this, SvxCharEffectsPage, ShadowBtnClickHdl));

    if ( !SvtLanguageOptions().IsAsianTypographyEnabled() )
    {
@@ -1498,7 +1498,7 @@ void SvxCharEffectsPage::UpdatePreview_Impl()
        rCTLFont.SetCaseMap( eCaps == SvxCaseMap::SmallCaps ? SvxCaseMap::NotMapped : eCaps );
    }

    bool bWordLine = m_xIndividualWordsBtn->get_active();
    bool bWordLine = StateToAttr( m_xIndividualWordsBtn->get_state() );
    rFont.SetWordLineMode( bWordLine );
    rCJKFont.SetWordLineMode( bWordLine );
    rCTLFont.SetWordLineMode( bWordLine );
@@ -1658,13 +1658,10 @@ void SvxCharEffectsPage::SelectHdl_Impl(const weld::ComboBox* pBox)
    UpdatePreview_Impl();
}

IMPL_LINK_NOARG(SvxCharEffectsPage, CbClickHdl_Impl, weld::ToggleButton&, void)
IMPL_LINK(SvxCharEffectsPage, CbClickHdl_Impl, weld::ToggleButton&, rToggle, void)
{
    m_aIndividualWordsState.ButtonToggled(rToggle);
    UpdatePreview_Impl();
}

IMPL_LINK_NOARG(SvxCharEffectsPage, TristClickHdl_Impl, weld::ToggleButton&, void)
{
    UpdatePreview_Impl();
}

@@ -1820,15 +1817,18 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
    switch ( eState )
    {
        case SfxItemState::UNKNOWN:
            m_aIndividualWordsState.bTriStateEnabled = false;
            m_xIndividualWordsBtn->hide();
            break;

        case SfxItemState::DISABLED:
        case SfxItemState::READONLY:
            m_aIndividualWordsState.bTriStateEnabled = false;
            m_xIndividualWordsBtn->set_sensitive(false);
            break;

        case SfxItemState::DONTCARE:
            m_aIndividualWordsState.bTriStateEnabled = true;
            m_xIndividualWordsBtn->set_state( TRISTATE_INDET );
            break;

@@ -1840,6 +1840,7 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
            rCJKFont.SetWordLineMode( rItem.GetValue() );
            rCTLFont.SetWordLineMode( rItem.GetValue() );

            m_aIndividualWordsState.bTriStateEnabled = false;
            m_xIndividualWordsBtn->set_active(rItem.GetValue());
            m_xIndividualWordsBtn->set_sensitive(bEnable);
            break;
@@ -1954,15 +1955,18 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
    switch ( eState )
    {
        case SfxItemState::UNKNOWN:
            m_aOutlineState.bTriStateEnabled = false;
            m_xOutlineBtn->hide();
            break;

        case SfxItemState::DISABLED:
        case SfxItemState::READONLY:
            m_aOutlineState.bTriStateEnabled = false;
            m_xOutlineBtn->set_sensitive(false);
            break;

        case SfxItemState::DONTCARE:
            m_aOutlineState.bTriStateEnabled = true;
            m_xOutlineBtn->set_state(TRISTATE_INDET);
            break;

@@ -1970,6 +1974,7 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
        case SfxItemState::SET:
        {
            const SvxContourItem& rItem = static_cast<const SvxContourItem&>(rSet->Get( nWhich ));
            m_aOutlineState.bTriStateEnabled = false;
            m_xOutlineBtn->set_state(static_cast<TriState>(rItem.GetValue()));
            break;
        }
@@ -1982,15 +1987,18 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
    switch ( eState )
    {
        case SfxItemState::UNKNOWN:
            m_aShadowState.bTriStateEnabled = false;
            m_xShadowBtn->hide();
            break;

        case SfxItemState::DISABLED:
        case SfxItemState::READONLY:
            m_aShadowState.bTriStateEnabled = false;
            m_xShadowBtn->set_sensitive(false);
            break;

        case SfxItemState::DONTCARE:
            m_aShadowState.bTriStateEnabled = true;
            m_xShadowBtn->set_state( TRISTATE_INDET );
            break;

@@ -1998,6 +2006,7 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
        case SfxItemState::SET:
        {
            const SvxShadowedItem& rItem = static_cast<const SvxShadowedItem&>(rSet->Get( nWhich ));
            m_aShadowState.bTriStateEnabled = false;
            m_xShadowBtn->set_state( static_cast<TriState>(rItem.GetValue()) );
            break;
        }
@@ -2010,15 +2019,18 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
    switch ( eState )
    {
        case SfxItemState::UNKNOWN:
            m_aHiddenState.bTriStateEnabled = false;
            m_xHiddenBtn->hide();
            break;

        case SfxItemState::DISABLED:
        case SfxItemState::READONLY:
            m_aHiddenState.bTriStateEnabled = false;
            m_xHiddenBtn->set_sensitive(false);
            break;

        case SfxItemState::DONTCARE:
            m_aHiddenState.bTriStateEnabled = true;
            m_xHiddenBtn->set_state(TRISTATE_INDET);
            break;

@@ -2026,6 +2038,7 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
        case SfxItemState::SET:
        {
            const SvxCharHiddenItem& rItem = static_cast<const SvxCharHiddenItem&>(rSet->Get( nWhich ));
            m_aHiddenState.bTriStateEnabled = false;
            m_xHiddenBtn->set_state(static_cast<TriState>(rItem.GetValue()));
            break;
        }
@@ -2041,6 +2054,23 @@ void SvxCharEffectsPage::Reset( const SfxItemSet* rSet )
    ChangesApplied();
}

IMPL_LINK(SvxCharEffectsPage, HiddenBtnClickHdl, weld::ToggleButton&, rToggle, void)
{
    m_aHiddenState.ButtonToggled(rToggle);
}

IMPL_LINK(SvxCharEffectsPage, OutlineBtnClickHdl, weld::ToggleButton&, rToggle, void)
{
    m_aOutlineState.ButtonToggled(rToggle);
    UpdatePreview_Impl();
}

IMPL_LINK(SvxCharEffectsPage, ShadowBtnClickHdl, weld::ToggleButton&, rToggle, void)
{
    m_aShadowState.ButtonToggled(rToggle);
    UpdatePreview_Impl();
}

void SvxCharEffectsPage::ChangesApplied()
{
    m_xUnderlineLB->save_value();
@@ -2164,23 +2194,26 @@ bool SvxCharEffectsPage::FillItemSet( SfxItemSet* rSet )
    bChanged = true;

    // Individual words
    const SfxItemSet* pExampleSet = GetDialogExampleSet();
    nWhich = GetWhich( SID_ATTR_CHAR_WORDLINEMODE );
    pOld = GetOldItem( *rSet, SID_ATTR_CHAR_WORDLINEMODE );
    TriState eState = m_xIndividualWordsBtn->get_state();
    const SfxPoolItem* pItem;

    if ( pOld )
    {
        const SvxWordLineModeItem& rItem = *static_cast<const SvxWordLineModeItem*>(pOld);
        if ( rItem.GetValue() == m_xIndividualWordsBtn->get_active() )
        if ( rItem.GetValue() == StateToAttr( eState ) && m_xIndividualWordsBtn->get_saved_state() == eState )
            bChanged = false;
    }

    if ( rOldSet.GetItemState( nWhich ) == SfxItemState::DONTCARE &&
         ! m_xIndividualWordsBtn->get_state_changed_from_saved() )
        bChanged = false;
    if ( !bChanged && pExampleSet && pExampleSet->GetItemState( nWhich, false, &pItem ) == SfxItemState::SET &&
         !StateToAttr( eState ) && static_cast<const SvxWordLineModeItem*>(pItem)->GetValue() )
        bChanged = true;

    if ( bChanged )
    if ( bChanged && eState != TRISTATE_INDET )
    {
        rSet->Put( SvxWordLineModeItem( m_xIndividualWordsBtn->get_active(), nWhich ) );
        rSet->Put( SvxWordLineModeItem( StateToAttr( eState ), nWhich ) );
        bModified = true;
    }
    else if ( SfxItemState::DEFAULT == rOldSet.GetItemState( nWhich, false ) )
@@ -2273,11 +2306,9 @@ bool SvxCharEffectsPage::FillItemSet( SfxItemSet* rSet )
    }

    // Outline
    const SfxItemSet* pExampleSet = GetDialogExampleSet();
    nWhich = GetWhich( SID_ATTR_CHAR_CONTOUR );
    pOld = GetOldItem( *rSet, SID_ATTR_CHAR_CONTOUR );
    TriState eState = m_xOutlineBtn->get_state();
    const SfxPoolItem* pItem;
    eState = m_xOutlineBtn->get_state();

    if ( pOld )
    {