cui/source/customize/acccfg.cxx |   50 +++++++++++++++++++++-------------------
 cui/source/inc/acccfg.hxx       |   16 ++++--------
 2 files changed, 33 insertions(+), 33 deletions(-)

New commits:
commit 94ede0085ee545c9b88033bc80e4f82005df2eca
Author:     Neil Roberts <[email protected]>
AuthorDate: Sun Mar 1 02:04:44 2026 +0100
Commit:     Neil Roberts <[email protected]>
CommitDate: Sun Mar 8 08:43:26 2026 +0100

    acccfg: Remove nListPos from TAccInfo
    
    This doesn’t seem to be used anywhere and it was always set to zero.
    
    Change-Id: If2a38cc9619bb57b6b6675b9f7895d72e5ea2629
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200695
    Reviewed-by: Neil Roberts <[email protected]>
    Tested-by: Jenkins

diff --git a/cui/source/customize/acccfg.cxx b/cui/source/customize/acccfg.cxx
index 4ca820595800..1f1d1fa6159f 100644
--- a/cui/source/customize/acccfg.cxx
+++ b/cui/source/customize/acccfg.cxx
@@ -1145,7 +1145,7 @@ void SfxAcceleratorConfigPage::Init(const 
uno::Reference<ui::XAcceleratorConfigu
         OUString sKey = aKey.GetName();
         if (sKey.isEmpty())
             continue;
-        TAccInfo* pEntry = new TAccInfo(i1, 0 /*nListPos*/, aKey);
+        TAccInfo* pEntry = new TAccInfo(i1, aKey);
         m_xEntriesBox->append(weld::toId(pEntry), sKey);
         int nPos = m_xEntriesBox->n_children() - 1;
         m_xEntriesBox->set_text(nPos, OUString(), 1);
diff --git a/cui/source/inc/acccfg.hxx b/cui/source/inc/acccfg.hxx
index 1dc69b91f79c..11051f350bb2 100644
--- a/cui/source/inc/acccfg.hxx
+++ b/cui/source/inc/acccfg.hxx
@@ -42,21 +42,16 @@ class SfxMacroInfoItem;
 struct TAccInfo
 {
 public:
-    TAccInfo(sal_Int32 nKeyPos, sal_Int32 nListPos, const vcl::KeyCode& aKey)
+    TAccInfo(sal_Int32 nKeyPos, const vcl::KeyCode& aKey)
         : m_nKeyPos(nKeyPos)
-        , m_nListPos(nListPos)
         , m_sCommand()
         , m_aKey(aKey)
     {
     }
 
-    bool isConfigured() const
-    {
-        return (m_nKeyPos > -1 && m_nListPos > -1 && !m_sCommand.isEmpty());
-    }
+    bool isConfigured() const { return (m_nKeyPos > -1 && 
!m_sCommand.isEmpty()); }
 
     sal_Int32 m_nKeyPos;
-    sal_Int32 m_nListPos;
     OUString m_sCommand;
     vcl::KeyCode m_aKey;
 };
commit 181a79db28f4c3ff608961b8c2ddcad5b74f2513
Author:     Neil Roberts <[email protected]>
AuthorDate: Sun Mar 1 01:58:18 2026 +0100
Commit:     Neil Roberts <[email protected]>
CommitDate: Sun Mar 8 08:43:15 2026 +0100

    acccfg: Look up reserved keys instead of storing m_bIsConfigurable
    
    Previously the accelerator config dialog was storing a boolean in the
    data for each entry in the key list to mark whether it is configurable.
    The only time a key can become unconfigurable if it is a reserved key
    code. This patch makes the accelerator config page instead store a
    sorted array of reserved key codes and then whenever we need to know if
    a key is configurable we can just quickly look it up in this array with
    a binary chop. The main reason to do this is to make it easier to remove
    the TAccInfo in a later patch.
    
    Change-Id: Iaac9a5deb07ae5bbf55e784a80b7193dad5e041a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/200694
    Tested-by: Jenkins
    Reviewed-by: Neil Roberts <[email protected]>

diff --git a/cui/source/customize/acccfg.cxx b/cui/source/customize/acccfg.cxx
index e29b6e9fb253..4ca820595800 100644
--- a/cui/source/customize/acccfg.cxx
+++ b/cui/source/customize/acccfg.cxx
@@ -951,6 +951,7 @@ 
SfxAcceleratorConfigPage::SfxAcceleratorConfigPage(weld::Container* pPage,
     , aFilterAllStr(SfxResId(STR_SFX_FILTERNAME_ALL))
     , aFilterCfgStr(CuiResId(RID_CUISTR_FILTERNAME_CFG))
     , m_bStylesInfoInitialized(false)
+    , m_aReservedKeyCodes(GetReservedKeyCodes())
     , m_aUpdateDataTimer("SfxAcceleratorConfigPage UpdateDataTimer")
     , m_xEntriesBox(m_xBuilder->weld_tree_view(u"shortcuts"_ustr))
     , m_xOfficeButton(m_xBuilder->weld_radio_button(u"office"_ustr))
@@ -1028,6 +1029,28 @@ 
SfxAcceleratorConfigPage::SfxAcceleratorConfigPage(weld::Container* pPage,
     m_aUpdateDataTimer.SetTimeout(EDIT_UPDATEDATA_TIMEOUT);
 }
 
+std::vector<sal_uInt16> SfxAcceleratorConfigPage::GetReservedKeyCodes()
+{
+    std::vector<sal_uInt16> aReservedKeyCodes;
+    size_t nKeyCodes = Application::GetReservedKeyCodeCount();
+
+    aReservedKeyCodes.reserve(nKeyCodes);
+
+    for (size_t i = 0; i < nKeyCodes; ++i)
+        
aReservedKeyCodes.push_back(Application::GetReservedKeyCode(i)->GetFullCode());
+
+    // Sort the key codes so we can do a binary chop on it
+    std::sort(aReservedKeyCodes.begin(), aReservedKeyCodes.end());
+
+    return aReservedKeyCodes;
+}
+
+bool SfxAcceleratorConfigPage::IsReservedKeyCode(const vcl::KeyCode& rKeyCode) 
const
+{
+    return std::binary_search(m_aReservedKeyCodes.begin(), 
m_aReservedKeyCodes.end(),
+                              rKeyCode.GetFullCode());
+}
+
 SfxAcceleratorConfigPage::~SfxAcceleratorConfigPage()
 {
     // free memory - remove all dynamic user data
@@ -1126,7 +1149,7 @@ void SfxAcceleratorConfigPage::Init(const 
uno::Reference<ui::XAcceleratorConfigu
         m_xEntriesBox->append(weld::toId(pEntry), sKey);
         int nPos = m_xEntriesBox->n_children() - 1;
         m_xEntriesBox->set_text(nPos, OUString(), 1);
-        m_xEntriesBox->set_sensitive(nPos, true);
+        m_xEntriesBox->set_sensitive(nPos, !IsReservedKeyCode(aKey));
     }
 
     // Assign all commands to its shortcuts - reading the accelerator config.
@@ -1148,28 +1171,9 @@ void SfxAcceleratorConfigPage::Init(const 
uno::Reference<ui::XAcceleratorConfigu
         m_xEntriesBox->set_text(nPos, sLabel, 1);
 
         TAccInfo* pEntry = 
weld::fromId<TAccInfo*>(m_xEntriesBox->get_id(nPos));
-        pEntry->m_bIsConfigurable = true;
 
         pEntry->m_sCommand = sCommand;
     }
-
-    // Map the VCL hardcoded key codes and mark them as not changeable
-    size_t c3 = Application::GetReservedKeyCodeCount();
-    size_t i3 = 0;
-    for (i3 = 0; i3 < c3; ++i3)
-    {
-        const vcl::KeyCode* pKeyCode = Application::GetReservedKeyCode(i3);
-        sal_Int32 nPos = MapKeyCodeToPos(*pKeyCode);
-
-        if (nPos == -1)
-            continue;
-
-        // Hardcoded function mapped so no ID possible and mark entry as not 
changeable
-        TAccInfo* pEntry = 
weld::fromId<TAccInfo*>(m_xEntriesBox->get_id(nPos));
-        pEntry->m_bIsConfigurable = false;
-
-        m_xEntriesBox->set_sensitive(nPos, false);
-    }
 }
 
 void SfxAcceleratorConfigPage::Apply(const 
uno::Reference<ui::XAcceleratorConfiguration>& xAccMgr)
@@ -1304,7 +1308,7 @@ IMPL_LINK(SfxAcceleratorConfigPage, SelectHdl, 
weld::TreeView&, rListBox, void)
         m_xRemoveButton->set_sensitive(false);
         m_xChangeButton->set_sensitive(false);
 
-        if (pEntry && pEntry->m_bIsConfigurable)
+        if (pEntry && !IsReservedKeyCode(pEntry->m_aKey))
         {
             if (pEntry->isConfigured())
                 m_xRemoveButton->set_sensitive(true);
@@ -1344,7 +1348,7 @@ IMPL_LINK(SfxAcceleratorConfigPage, SelectHdl, 
weld::TreeView&, rListBox, void)
         {
             OUString sPossibleNewCommand = m_xFunctionBox->GetCurCommand();
 
-            if (pEntry->m_bIsConfigurable)
+            if (!IsReservedKeyCode(pEntry->m_aKey))
             {
                 if (pEntry->isConfigured())
                     m_xRemoveButton->set_sensitive(true);
diff --git a/cui/source/inc/acccfg.hxx b/cui/source/inc/acccfg.hxx
index 9e444c2615e0..1dc69b91f79c 100644
--- a/cui/source/inc/acccfg.hxx
+++ b/cui/source/inc/acccfg.hxx
@@ -45,8 +45,6 @@ public:
     TAccInfo(sal_Int32 nKeyPos, sal_Int32 nListPos, const vcl::KeyCode& aKey)
         : m_nKeyPos(nKeyPos)
         , m_nListPos(nListPos)
-        , m_bIsConfigurable(true) /**< it's important to set true as default -
-                                                because only fix entries will 
be disabled later... */
         , m_sCommand()
         , m_aKey(aKey)
     {
@@ -59,7 +57,6 @@ public:
 
     sal_Int32 m_nKeyPos;
     sal_Int32 m_nListPos;
-    bool m_bIsConfigurable;
     OUString m_sCommand;
     vcl::KeyCode m_aKey;
 };
@@ -91,6 +88,8 @@ private:
     OUString aFilterCfgStr;
     SfxStylesInfo_Impl m_aStylesInfo;
     bool m_bStylesInfoInitialized;
+    // Array of reserved key codes in sorted order
+    std::vector<sal_uInt16> m_aReservedKeyCodes;
 
     css::uno::Reference<css::uno::XComponentContext> m_xContext;
     css::uno::Reference<css::ui::XAcceleratorConfiguration> m_xGlobal;
@@ -155,6 +154,8 @@ private:
     void AddFrameToSaveInComboBox(const 
css::uno::Reference<css::frame::XFrame>& xFrame);
     void FillSaveInComboBox();
     void HandleScopeChanged();
+    bool IsReservedKeyCode(const vcl::KeyCode& rCode) const;
+    static std::vector<sal_uInt16> GetReservedKeyCodes();
 
 public:
     SfxAcceleratorConfigPage(weld::Container* pPage, weld::DialogController* 
pController,

Reply via email to