cui/source/dialogs/FontFeaturesDialog.cxx |   30 ++++++++++++++++++++++++------
 cui/source/inc/FontFeaturesDialog.hxx     |    8 +++++++-
 cui/uiconfig/ui/fontfragment.ui           |    1 +
 3 files changed, 32 insertions(+), 7 deletions(-)

New commits:
commit 23d303779440e8201ffc6fbcc08f9cffa5b585c9
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Apr 24 12:52:22 2023 +0100
Commit:     خالد حسني <kha...@aliftype.com>
CommitDate: Tue Apr 25 01:44:55 2023 +0200

    Resolves: tdf#153441 use a TriStateEnabled helper
    
    Change-Id: I976e4271a072bfb53c676091509e1d4ef7dbcccb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150915
    Tested-by: Jenkins
    Reviewed-by: خالد حسني <kha...@aliftype.com>

diff --git a/cui/source/dialogs/FontFeaturesDialog.cxx 
b/cui/source/dialogs/FontFeaturesDialog.cxx
index ab6063c9b6c3..b394495b3ae3 100644
--- a/cui/source/dialogs/FontFeaturesDialog.cxx
+++ b/cui/source/dialogs/FontFeaturesDialog.cxx
@@ -109,19 +109,21 @@ int 
FontFeaturesDialog::fillGrid(std::vector<vcl::font::Feature> const& rFontFea
         {
             nIdx = nStylisticSets++;
             m_xStylisticSetsBox->set_visible(true);
-            m_aFeatureItems.emplace_back(m_xStylisticSetsGrid.get());
+            m_aFeatureItems.emplace_back(
+                std::make_unique<FontFeatureItem>(m_xStylisticSetsGrid.get()));
         }
         else if (rFontFeature.isCharacterVariant())
         {
             nIdx = nCharacterVariants++;
             m_xCharacterVariantsBox->set_visible(true);
-            m_aFeatureItems.emplace_back(m_xCharacterVariantsGrid.get());
+            m_aFeatureItems.emplace_back(
+                
std::make_unique<FontFeatureItem>(m_xCharacterVariantsGrid.get()));
         }
         else
         {
             nIdx = nOtherFeatures++;
             m_xContentBox->set_visible(true);
-            m_aFeatureItems.emplace_back(m_xContentGrid.get());
+            
m_aFeatureItems.emplace_back(std::make_unique<FontFeatureItem>(m_xContentGrid.get()));
         }
 
         int32_t nValue = 0;
@@ -130,7 +132,7 @@ int 
FontFeaturesDialog::fillGrid(std::vector<vcl::font::Feature> const& rFontFea
         else
             nValue = aDefinition.getDefault();
 
-        FontFeatureItem& aCurrentItem = m_aFeatureItems.back();
+        FontFeatureItem& aCurrentItem = *m_aFeatureItems.back();
         aCurrentItem.m_aFeatureCode = nFontFeatureCode;
         aCurrentItem.m_nDefault = aDefinition.getDefault();
 
@@ -158,11 +160,19 @@ int 
FontFeaturesDialog::fillGrid(std::vector<vcl::font::Feature> const& rFontFea
         else
         {
             if (nValue < 0)
+            {
                 aCurrentItem.m_xCheck->set_state(TRISTATE_INDET);
+                aCurrentItem.m_aTriStateEnabled.bTriStateEnabled = true;
+                aCurrentItem.m_aTriStateEnabled.eState = TRISTATE_INDET;
+            }
             else
+            {
                 aCurrentItem.m_xCheck->set_state(nValue > 0 ? TRISTATE_TRUE : 
TRISTATE_FALSE);
+                aCurrentItem.m_aTriStateEnabled.bTriStateEnabled = false;
+                aCurrentItem.m_aTriStateEnabled.eState = 
aCurrentItem.m_xCheck->get_state();
+            }
             aCurrentItem.m_xCheck->set_label(aDefinition.getDescription());
-            aCurrentItem.m_xCheck->connect_toggled(aCheckBoxToggleHandler);
+            aCurrentItem.m_aToggleHdl = aCheckBoxToggleHandler;
             aCurrentItem.m_xCheck->show();
         }
 
@@ -188,6 +198,13 @@ void FontFeaturesDialog::updateFontPreview()
     m_aPreviewWindow.SetFont(rPreviewFont, rPreviewFontCJK, rPreviewFontCTL);
 }
 
+IMPL_LINK(FontFeatureItem, CheckBoxToggledHdl, weld::Toggleable&, rToggle, 
void)
+{
+    m_aTriStateEnabled.ButtonToggled(rToggle);
+    m_aTriStateEnabled.bTriStateEnabled = false;
+    m_aToggleHdl.Call(rToggle);
+}
+
 IMPL_LINK_NOARG(FontFeaturesDialog, CheckBoxToggledHdl, weld::Toggleable&, 
void)
 {
     updateFontPreview();
@@ -204,8 +221,9 @@ OUString FontFeaturesDialog::createFontNameWithFeatures()
     OUStringBuffer sNameSuffix;
     bool bFirst = true;
 
-    for (const FontFeatureItem& rItem : m_aFeatureItems)
+    for (const auto& rEntry : m_aFeatureItems)
     {
+        const FontFeatureItem& rItem(*rEntry);
         if (rItem.m_xCheck->get_visible())
         {
             if (rItem.m_xCheck->get_state() != TRISTATE_INDET)
diff --git a/cui/source/inc/FontFeaturesDialog.hxx 
b/cui/source/inc/FontFeaturesDialog.hxx
index c4eb43b79e98..93ba0cb9f80d 100644
--- a/cui/source/inc/FontFeaturesDialog.hxx
+++ b/cui/source/inc/FontFeaturesDialog.hxx
@@ -29,21 +29,27 @@ struct FontFeatureItem
         , m_xCombo(m_xBuilder->weld_combo_box("combo"))
         , m_xCheck(m_xBuilder->weld_check_button("check"))
     {
+        m_xCheck->connect_toggled(LINK(this, FontFeatureItem, 
CheckBoxToggledHdl));
     }
 
     sal_uInt32 m_aFeatureCode;
     sal_Int32 m_nDefault;
+    weld::TriStateEnabled m_aTriStateEnabled;
+    Link<weld::Toggleable&, void> m_aToggleHdl;
     std::unique_ptr<weld::Builder> m_xBuilder;
     std::unique_ptr<weld::Widget> m_xContainer;
     std::unique_ptr<weld::Label> m_xText;
     std::unique_ptr<weld::ComboBox> m_xCombo;
     std::unique_ptr<weld::CheckButton> m_xCheck;
+
+private:
+    DECL_LINK(CheckBoxToggledHdl, weld::Toggleable&, void);
 };
 
 class FontFeaturesDialog : public weld::GenericDialogController
 {
 private:
-    std::vector<FontFeatureItem> m_aFeatureItems;
+    std::vector<std::unique_ptr<FontFeatureItem>> m_aFeatureItems;
     OUString m_sFontName;
     OUString m_sResultFontName;
 
diff --git a/cui/uiconfig/ui/fontfragment.ui b/cui/uiconfig/ui/fontfragment.ui
index e66cd71b7ba6..dca735e5fe1e 100644
--- a/cui/uiconfig/ui/fontfragment.ui
+++ b/cui/uiconfig/ui/fontfragment.ui
@@ -30,6 +30,7 @@
         <property name="can_focus">True</property>
         <property name="receives_default">False</property>
         <property name="no_show_all">True</property>
+        <property name="inconsistent">True</property>
         <property name="draw_indicator">True</property>
       </object>
       <packing>

Reply via email to