dbaccess/source/ui/control/FieldControls.cxx    |   16 ---
 dbaccess/source/ui/control/FieldDescControl.cxx |  109 +++++-------------------
 dbaccess/source/ui/control/SqlNameEdit.cxx      |    9 +
 dbaccess/source/ui/inc/FieldControls.hxx        |   20 ----
 dbaccess/source/ui/inc/FieldDescControl.hxx     |   11 ++
 dbaccess/source/ui/inc/SqlNameEdit.hxx          |   17 ++-
 6 files changed, 59 insertions(+), 123 deletions(-)

New commits:
commit cd407a66fd9f270a065ef5aad1062357309fcda8
Author:     Neil Roberts <[email protected]>
AuthorDate: Tue Oct 21 00:32:29 2025 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Sat Oct 25 22:32:24 2025 +0200

    Make the got/lose focus handlers use an iterator to access controls
    
    Instead of having two long if-chains to handle the focus for the
    controls, there is now an inline helper method that calls a function on
    each of the controls. This is then used by the two handler methods to
    check all of the controls. This should make it a bit easier to handle
    the list of controls that need similar code.
    
    Change-Id: I9787b92156dee39479a260d029cbd382fbef9394
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192975
    Reviewed-by: Noel Grandin <[email protected]>
    Tested-by: Jenkins

diff --git a/dbaccess/source/ui/control/FieldDescControl.cxx 
b/dbaccess/source/ui/control/FieldDescControl.cxx
index ba2bf000d712..fabba657313f 100644
--- a/dbaccess/source/ui/control/FieldDescControl.cxx
+++ b/dbaccess/source/ui/control/FieldDescControl.cxx
@@ -996,67 +996,19 @@ IMPL_LINK(OFieldDescControl, OnControlFocusGot, 
weld::Widget&, rControl, void )
 {
     OUString strHelpText;
 
-    if (m_xTextLen && &rControl == m_xTextLen->GetWidget())
+    bool bFoundControl = iterateControls([&](OWidgetBase* pWidget)
     {
-        m_xTextLen->save_value();
-        strHelpText = m_xTextLen->GetHelp();
-    }
-    else if (m_xLength && &rControl == m_xLength->GetWidget())
-    {
-        m_xLength->save_value();
-        strHelpText = m_xLength->GetHelp();
-    }
-    else if (m_xScale && &rControl == m_xScale->GetWidget())
-    {
-        m_xScale->save_value();
-        strHelpText = m_xScale->GetHelp();
-    }
-    else if (m_xColumnName && &rControl == m_xColumnName->GetWidget())
-    {
-        m_xColumnName->save_value();
-        strHelpText = m_xColumnName->GetHelp();
-    }
-    else if (m_xDefault && &rControl == m_xDefault->GetWidget())
-    {
-        m_xDefault->save_value();
-        strHelpText = m_xDefault->GetHelp();
-    }
-    else if (m_xFormatSample && &rControl == m_xFormatSample->GetWidget())
-    {
-        m_xFormatSample->save_value();
-        strHelpText = m_xFormatSample->GetHelp();
-    }
-    else if (m_xAutoIncrementValue && &rControl == 
m_xAutoIncrementValue->GetWidget())
-    {
-        m_xAutoIncrementValue->save_value();
-        strHelpText = m_xAutoIncrementValue->GetHelp();
-    }
-    else if (m_xRequired && &rControl == m_xRequired->GetWidget())
-    {
-        m_xRequired->save_value();
-        strHelpText = m_xRequired->GetHelp();
-    }
-    else if (m_xNumType && &rControl == m_xNumType->GetWidget())
-    {
-        m_xNumType->save_value();
-        strHelpText = m_xNumType->GetHelp();
-    }
-    else if (m_xAutoIncrement && &rControl == m_xAutoIncrement->GetWidget())
-    {
-        m_xAutoIncrement->save_value();
-        strHelpText = m_xAutoIncrement->GetHelp();
-    }
-    else if (m_xBoolDefault && &rControl == m_xBoolDefault->GetWidget())
-    {
-        m_xBoolDefault->save_value();
-        strHelpText = m_xBoolDefault->GetHelp();
-    }
-    else if (m_xType && &rControl == m_xType->GetWidget())
-    {
-        m_xType->save_value();
-        strHelpText = m_xType->GetHelp();
-    }
-    else if (m_xFormat && &rControl == m_xFormat.get())
+        if (pWidget && &rControl == pWidget->GetWidget())
+        {
+            pWidget->save_value();
+            strHelpText = pWidget->GetHelp();
+            return true;
+        }
+        else
+            return false;
+    });
+
+    if (!bFoundControl && m_xFormat && &rControl == m_xFormat.get())
         strHelpText = DBA_RES(STR_HELP_FORMAT_BUTTON);
 
     if (!strHelpText.isEmpty() && m_pHelp)
@@ -1069,33 +1021,20 @@ IMPL_LINK(OFieldDescControl, OnControlFocusGot, 
weld::Widget&, rControl, void )
 
 IMPL_LINK(OFieldDescControl, OnControlFocusLost, weld::Widget&, rControl, void 
)
 {
-    if (m_xLength && &rControl == m_xLength->GetWidget() && 
m_xLength->get_value_changed_from_saved())
-        CellModified(-1, m_xLength->GetPos());
-    else if (m_xTextLen && &rControl == m_xTextLen->GetWidget() && 
m_xTextLen->get_value_changed_from_saved())
-        CellModified(-1, m_xTextLen->GetPos());
-    else if (m_xScale && &rControl == m_xScale->GetWidget() && 
m_xScale->get_value_changed_from_saved())
-        CellModified(-1, m_xScale->GetPos());
-    else if (m_xColumnName && &rControl == m_xColumnName->GetWidget() && 
m_xColumnName->get_value_changed_from_saved())
-        CellModified(-1, m_xColumnName->GetPos());
-    else if (m_xDefault && &rControl == m_xDefault->GetWidget() && 
m_xDefault->get_value_changed_from_saved())
+    bool bFoundControl = iterateControls([&](OWidgetBase* pWidget)
     {
-        CellModified(-1, m_xDefault->GetPos());
+        if (pWidget && &rControl == pWidget->GetWidget())
+        {
+            if (pWidget->get_value_changed_from_saved())
+                CellModified(-1, pWidget->GetPos());
+            return true;
+        }
+        else
+            return false;
+    });
+
+    if (bFoundControl && m_xDefault && &rControl == m_xDefault->GetWidget())
         UpdateFormatSample(pActFieldDescr);
-    }
-    else if (m_xFormatSample && &rControl == m_xFormatSample->GetWidget() && 
m_xFormatSample->get_value_changed_from_saved())
-        CellModified(-1, m_xFormatSample->GetPos());
-    else if (m_xAutoIncrementValue && &rControl == 
m_xAutoIncrementValue->GetWidget() && 
m_xAutoIncrementValue->get_value_changed_from_saved())
-        CellModified(-1, m_xAutoIncrementValue->GetPos());
-    else if (m_xRequired && &rControl == m_xRequired->GetWidget() && 
m_xRequired->get_value_changed_from_saved())
-        CellModified(-1, m_xRequired->GetPos());
-    else if (m_xNumType && &rControl == m_xNumType->GetWidget() && 
m_xNumType->get_value_changed_from_saved())
-        CellModified(-1, m_xNumType->GetPos());
-    else if (m_xAutoIncrement && &rControl == m_xAutoIncrement->GetWidget() && 
m_xAutoIncrement->get_value_changed_from_saved())
-        CellModified(-1, m_xAutoIncrement->GetPos());
-    else if (m_xBoolDefault && &rControl == m_xBoolDefault->GetWidget() && 
m_xBoolDefault->get_value_changed_from_saved())
-        CellModified(-1, m_xBoolDefault->GetPos());
-    else if (m_xType && &rControl == m_xType->GetWidget() && 
m_xType->get_value_changed_from_saved())
-        CellModified(-1, m_xType->GetPos());
 
     implFocusLost(&rControl);
 }
diff --git a/dbaccess/source/ui/inc/FieldDescControl.hxx 
b/dbaccess/source/ui/inc/FieldDescControl.hxx
index 410e086116fe..254f47422fe0 100644
--- a/dbaccess/source/ui/inc/FieldDescControl.hxx
+++ b/dbaccess/source/ui/inc/FieldDescControl.hxx
@@ -124,6 +124,17 @@ namespace dbaui
         bool                IsFocusInEditableWidget() const;
 
         void                dispose();
+
+        // Call func on all of the controls or stop early if one of them 
returns true
+        template <class Func> bool iterateControls(Func func)
+        {
+            return func(m_xAutoIncrement.get()) || 
func(m_xAutoIncrementValue.get())
+                || func(m_xBoolDefault.get()) || func(m_xColumnName.get()) || 
func(m_xDefault.get())
+                || func(m_xFormatSample.get()) || func(m_xLength.get()) || 
func(m_xNumType.get())
+                || func(m_xRequired.get()) || func(m_xScale.get()) || 
func(m_xTextLen.get())
+                || func(m_xType.get());
+        }
+
     protected:
         void                saveCurrentFieldDescData() { SaveData( 
pActFieldDescr ); }
         OFieldDescription*  getCurrentFieldDescData() { return pActFieldDescr; 
}
commit 38d173a7e9373684b1fd0fb533965f93d97bd0d3
Author:     Neil Roberts <[email protected]>
AuthorDate: Tue Oct 21 00:20:49 2025 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Sat Oct 25 22:32:12 2025 +0200

    Move help text and pos into OWidgetBase
    
    All of the subclasses of OWidgetBase have a help text and a position so
    we might as well move them into the base class.
    
    Change-Id: Icfca13fd1d8e92cce99d835adb9f9478ed8c5502
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/192974
    Reviewed-by: Noel Grandin <[email protected]>
    Tested-by: Jenkins

diff --git a/dbaccess/source/ui/control/FieldControls.cxx 
b/dbaccess/source/ui/control/FieldControls.cxx
index 3f3553d56ee9..6ffd5d587c03 100644
--- a/dbaccess/source/ui/control/FieldControls.cxx
+++ b/dbaccess/source/ui/control/FieldControls.cxx
@@ -27,34 +27,26 @@ 
OPropColumnEditCtrl::OPropColumnEditCtrl(std::unique_ptr<weld::Entry> xEntry,
                                          OUString const & _rAllowedChars,
                                          TranslateId pHelpId,
                                          short nPosition)
-    : OSQLNameEntry(std::move(xEntry), _rAllowedChars)
-    , m_nPos(nPosition)
+    : OSQLNameEntry(std::move(xEntry), _rAllowedChars, pHelpId, nPosition)
 {
-    m_strHelpText = DBA_RES(pHelpId);
 }
 
 OPropEditCtrl::OPropEditCtrl(std::unique_ptr<weld::Entry> xEntry, TranslateId 
pHelpId, short nPosition)
-    : OWidgetBase(xEntry.get())
+    : OWidgetBase(xEntry.get(), pHelpId, nPosition)
     , m_xEntry(std::move(xEntry))
-    , m_nPos(nPosition)
 {
-    m_strHelpText = DBA_RES(pHelpId);
 }
 
 OPropNumericEditCtrl::OPropNumericEditCtrl(std::unique_ptr<weld::SpinButton> 
xSpinButton, TranslateId pHelpId, short nPosition)
-    : OWidgetBase(xSpinButton.get())
+    : OWidgetBase(xSpinButton.get(), pHelpId, nPosition)
     , m_xSpinButton(std::move(xSpinButton))
-    , m_nPos(nPosition)
 {
-    m_strHelpText = DBA_RES(pHelpId);
 }
 
 OPropListBoxCtrl::OPropListBoxCtrl(std::unique_ptr<weld::ComboBox> xComboBox, 
TranslateId pHelpId, short nPosition)
-    : OWidgetBase(xComboBox.get())
+    : OWidgetBase(xComboBox.get(), pHelpId, nPosition)
     , m_xComboBox(std::move(xComboBox))
-    , m_nPos(nPosition)
 {
-    m_strHelpText = DBA_RES(pHelpId);
 }
 
 } // end namespace dbaui
diff --git a/dbaccess/source/ui/control/SqlNameEdit.cxx 
b/dbaccess/source/ui/control/SqlNameEdit.cxx
index 9ac58cfda851..bdd2df56540b 100644
--- a/dbaccess/source/ui/control/SqlNameEdit.cxx
+++ b/dbaccess/source/ui/control/SqlNameEdit.cxx
@@ -19,8 +19,17 @@
 
 #include <SqlNameEdit.hxx>
 
+#include <core_resource.hxx>
+
 namespace dbaui
 {
+    OWidgetBase::OWidgetBase(weld::Widget *pWidget, TranslateId pHelpId, short 
nPosition)
+        : m_pWidget(pWidget)
+        , m_strHelpText(DBA_RES(pHelpId))
+        , m_nPos(nPosition)
+    {
+    }
+
     static bool isCharOk(sal_Unicode _cChar,bool _bFirstChar, 
std::u16string_view _sAllowedChars)
     {
         return  (
diff --git a/dbaccess/source/ui/inc/FieldControls.hxx 
b/dbaccess/source/ui/inc/FieldControls.hxx
index 7eb88ec4e077..e3137189c3cf 100644
--- a/dbaccess/source/ui/inc/FieldControls.hxx
+++ b/dbaccess/source/ui/inc/FieldControls.hxx
@@ -26,20 +26,13 @@ namespace dbaui
 
     class OPropColumnEditCtrl : public OSQLNameEntry
     {
-        short                m_nPos;
-        OUString             m_strHelpText;
     public:
         OPropColumnEditCtrl(std::unique_ptr<weld::Entry> xEntry, OUString 
const & _rAllowedChars, TranslateId pHelpId, short nPosition);
-
-        short GetPos() const { return m_nPos; }
-        const OUString& GetHelp() const { return m_strHelpText; }
     };
 
     class OPropEditCtrl : public OWidgetBase
     {
         std::unique_ptr<weld::Entry> m_xEntry;
-        short                m_nPos;
-        OUString             m_strHelpText;
 
     public:
         OPropEditCtrl(std::unique_ptr<weld::Entry> xEntry, TranslateId 
pHelpId, short nPosition);
@@ -50,16 +43,11 @@ namespace dbaui
 
         virtual void save_value() override { m_xEntry->save_value(); }
         virtual bool get_value_changed_from_saved() const override { return 
m_xEntry->get_value_changed_from_saved(); }
-
-        short GetPos() const { return m_nPos; }
-        const OUString& GetHelp() const { return m_strHelpText; }
     };
 
     class OPropNumericEditCtrl : public OWidgetBase
     {
         std::unique_ptr<weld::SpinButton> m_xSpinButton;
-        short     m_nPos;
-        OUString  m_strHelpText;
 
     public:
         OPropNumericEditCtrl(std::unique_ptr<weld::SpinButton> xSpinButton, 
TranslateId pHelpId, short nPosition);
@@ -75,17 +63,12 @@ namespace dbaui
         void set_range(int nMin, int nMax) { m_xSpinButton->set_range(nMin, 
nMax); }
         int get_value() const { return m_xSpinButton->get_value(); }
 
-        short GetPos() const { return m_nPos; }
-        const OUString& GetHelp() const { return m_strHelpText; }
-
         void set_editable(bool bEditable) { 
m_xSpinButton->set_editable(bEditable); }
     };
 
     class OPropListBoxCtrl : public OWidgetBase
     {
         std::unique_ptr<weld::ComboBox> m_xComboBox;
-        short     m_nPos;
-        OUString  m_strHelpText;
 
     public:
         OPropListBoxCtrl(std::unique_ptr<weld::ComboBox> xComboBox, 
TranslateId pHelpId, short nPosition);
@@ -110,9 +93,6 @@ namespace dbaui
         void append_text(const OUString &rText) { 
m_xComboBox->append_text(rText); }
         void remove_text(const OUString &rText) { 
m_xComboBox->remove_text(rText); }
         int find_text(const OUString &rText) const { return 
m_xComboBox->find_text(rText); }
-
-        short GetPos() const { return m_nPos; }
-        const OUString& GetHelp() const { return m_strHelpText; }
     };
 
 }
diff --git a/dbaccess/source/ui/inc/SqlNameEdit.hxx 
b/dbaccess/source/ui/inc/SqlNameEdit.hxx
index 14d845b4b17c..3f40cd265e0b 100644
--- a/dbaccess/source/ui/inc/SqlNameEdit.hxx
+++ b/dbaccess/source/ui/inc/SqlNameEdit.hxx
@@ -19,6 +19,7 @@
 #pragma once
 
 #include <svtools/editbrowsebox.hxx>
+#include <unotools/resmgr.hxx>
 #include <utility>
 #include <vcl/weld.hxx>
 
@@ -72,11 +73,11 @@ namespace dbaui
     {
     private:
         weld::Widget* m_pWidget;
+        OUString m_strHelpText;
+        short m_nPos;
+
     public:
-        OWidgetBase(weld::Widget *pWidget)
-            : m_pWidget(pWidget)
-        {
-        }
+        OWidgetBase(weld::Widget *pWidget, TranslateId pHelpId, short 
nPosition);
 
         void hide() { m_pWidget->hide(); }
         void show() { m_pWidget->show(); }
@@ -84,6 +85,9 @@ namespace dbaui
 
         weld::Widget* GetWidget() { return m_pWidget; }
 
+        short GetPos() const { return m_nPos; }
+        const OUString& GetHelp() const { return m_strHelpText; }
+
         virtual bool get_value_changed_from_saved() const = 0;
         virtual void save_value() = 0;
 
@@ -99,8 +103,9 @@ namespace dbaui
         DECL_LINK(ModifyHdl, weld::Entry&, void);
 
     public:
-        OSQLNameEntry(std::unique_ptr<weld::Entry> xEntry, const OUString& 
_rAllowedChars = OUString())
-            : OWidgetBase(xEntry.get())
+        OSQLNameEntry(std::unique_ptr<weld::Entry> xEntry, const OUString& 
_rAllowedChars,
+                      TranslateId pHelpId, short nPosition)
+            : OWidgetBase(xEntry.get(), pHelpId, nPosition)
             , OSQLNameChecker(_rAllowedChars)
             , m_xEntry(std::move(xEntry))
         {

Reply via email to