formula/source/ui/dlg/funcutl.cxx   |   72 +++++++++++++++++++++---------------
 include/formula/funcutl.hxx         |   33 +++++++---------
 sc/source/ui/miscdlgs/anyrefdg.cxx  |   11 ++---
 sc/source/ui/miscdlgs/optsolver.cxx |    4 +-
 4 files changed, 63 insertions(+), 57 deletions(-)

New commits:
commit 0c5099377dbd35c9f627307be81771055b741d5a
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Aug 9 00:31:58 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Aug 9 08:08:28 2025 +0200

    tdf#130857 formula: No longer remember the reference label widget in RefEdit
    
    No longer store the weld::Label* passed to
    RefEdit::SetReferences as a class member RefEdit::mpLabelWidget,
    but instead have a std::function that returns the
    label's label/text.
    
    No change in behavior intended yet, but this prepares
    for allowing non-weld::Label widgets to be used in
    the future.
    
    See also previous commit
    
        Change-Id: I3b987a052fe4ba72a6793671a7a81142b12afe95
        Author: Michael Weghorn <m.wegh...@posteo.de>
        Date:   Fri Aug 8 10:54:27 2025 +0200
    
            tdf#130857 formula: Don't have getter for Label, but text
    
    for more background.
    
    Change-Id: I45f6c328b7da134ca0d4fcb4b078a50056c6564a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189219
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/formula/source/ui/dlg/funcutl.cxx 
b/formula/source/ui/dlg/funcutl.cxx
index 0e762c9998f0..4170ecc3c6d6 100644
--- a/formula/source/ui/dlg/funcutl.cxx
+++ b/formula/source/ui/dlg/funcutl.cxx
@@ -265,7 +265,6 @@ RefEdit::RefEdit(std::unique_ptr<weld::Entry> xControl)
     : mxEntry(std::move(xControl))
     , maIdle("formula RefEdit Idle")
     , mpAnyRefDlg(nullptr)
-    , mpLabelWidget(nullptr)
     , mpFocusInEvent(nullptr)
     , mpFocusOutEvent(nullptr)
 {
@@ -314,7 +313,10 @@ void RefEdit::StartUpdateData()
 void RefEdit::SetReferences(IControlReferenceHandler* pDlg, weld::Label* 
pLabel)
 {
     mpAnyRefDlg = pDlg;
-    mpLabelWidget = pLabel;
+    if (pLabel)
+        maGetLabelTextForShrinkModeFunc = [pLabel] { return 
pLabel->get_label(); };
+    else
+        maGetLabelTextForShrinkModeFunc = nullptr;
 
     if( pDlg )
     {
@@ -327,6 +329,15 @@ void RefEdit::SetReferences(IControlReferenceHandler* 
pDlg, weld::Label* pLabel)
     }
 }
 
+
+OUString RefEdit::GetLabelTextForShrinkMode()
+{
+    if (maGetLabelTextForShrinkModeFunc)
+        return maGetLabelTextForShrinkModeFunc();
+
+    return OUString();
+}
+
 IMPL_LINK_NOARG(RefEdit, Modify, weld::Entry&, void)
 {
     maModifyHdl.Call(*this);
diff --git a/include/formula/funcutl.hxx b/include/formula/funcutl.hxx
index 82f091d32eb8..e17ce1358f75 100644
--- a/include/formula/funcutl.hxx
+++ b/include/formula/funcutl.hxx
@@ -41,7 +41,7 @@ protected:
 private:
     Idle maIdle;
     IControlReferenceHandler* mpAnyRefDlg; // parent dialog
-    weld::Label* mpLabelWidget;
+    std::function<OUString()> maGetLabelTextForShrinkModeFunc;
     ImplSVEvent* mpFocusInEvent;
     ImplSVEvent* mpFocusOutEvent;
 
@@ -120,13 +120,7 @@ public:
         return Selection(nStartPos, nEndPos);
     }
 
-    OUString GetLabelTextForShrinkMode()
-    {
-        if (mpLabelWidget)
-            return mpLabelWidget->get_label();
-
-        return OUString();
-    }
+    OUString GetLabelTextForShrinkMode();
 
     void SaveValue()
     {
commit a61d53d6ea02f0f77f83ecae51d828e29d1c6f80
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Aug 9 00:17:01 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Aug 9 08:08:21 2025 +0200

    formula: Prefix RefEdit members with "m"
    
    Some class members already had an "m" prefix, others
    didn't. Add it for those who didn't, to make it easier
    to distinguish local variables from class members at
    first sight.
    
    Change-Id: Iadf6550a803eff3f6fd0d9b7e0c63bca283425be
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189218
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>
    Tested-by: Jenkins

diff --git a/formula/source/ui/dlg/funcutl.cxx 
b/formula/source/ui/dlg/funcutl.cxx
index 58c2492c5505..0e762c9998f0 100644
--- a/formula/source/ui/dlg/funcutl.cxx
+++ b/formula/source/ui/dlg/funcutl.cxx
@@ -262,18 +262,18 @@ IMPL_LINK( ArgInput, EdModifyHdl, RefEdit&, rEdit, void )
 }
 
 RefEdit::RefEdit(std::unique_ptr<weld::Entry> xControl)
-    : xEntry(std::move(xControl))
-    , aIdle("formula RefEdit Idle")
-    , pAnyRefDlg(nullptr)
-    , pLabelWidget(nullptr)
+    : mxEntry(std::move(xControl))
+    , maIdle("formula RefEdit Idle")
+    , mpAnyRefDlg(nullptr)
+    , mpLabelWidget(nullptr)
     , mpFocusInEvent(nullptr)
     , mpFocusOutEvent(nullptr)
 {
-    xEntry->connect_focus_in(LINK(this, RefEdit, GetFocusHdl));
-    xEntry->connect_focus_out(LINK(this, RefEdit, LoseFocusHdl));
-    xEntry->connect_key_press(LINK(this, RefEdit, KeyInputHdl));
-    xEntry->connect_changed(LINK(this, RefEdit, Modify));
-    aIdle.SetInvokeHandler( LINK( this, RefEdit, UpdateHdl ) );
+    mxEntry->connect_focus_in(LINK(this, RefEdit, GetFocusHdl));
+    mxEntry->connect_focus_out(LINK(this, RefEdit, LoseFocusHdl));
+    mxEntry->connect_key_press(LINK(this, RefEdit, KeyInputHdl));
+    mxEntry->connect_changed(LINK(this, RefEdit, Modify));
+    maIdle.SetInvokeHandler(LINK(this, RefEdit, UpdateHdl));
 }
 
 RefEdit::~RefEdit()
@@ -282,55 +282,56 @@ RefEdit::~RefEdit()
         Application::RemoveUserEvent(mpFocusInEvent);
     if (mpFocusOutEvent)
         Application::RemoveUserEvent(mpFocusOutEvent);
-    aIdle.ClearInvokeHandler();
-    aIdle.Stop();
+    maIdle.ClearInvokeHandler();
+    maIdle.Stop();
 }
 
 void RefEdit::SetRefString( const OUString& rStr )
 {
     // Prevent unwanted side effects by setting only a differing string.
     // See commit message for reasons.
-    if (xEntry->get_text() != rStr)
-        xEntry->set_text(rStr);
+    if (mxEntry->get_text() != rStr)
+        mxEntry->set_text(rStr);
 }
 
 void RefEdit::SetRefValid(bool bValid)
 {
-    xEntry->set_message_type(bValid ? weld::EntryMessageType::Normal : 
weld::EntryMessageType::Error);
+    mxEntry->set_message_type(bValid ? weld::EntryMessageType::Normal
+                                     : weld::EntryMessageType::Error);
 }
 
 void RefEdit::SetText(const OUString& rStr)
 {
-    xEntry->set_text(rStr);
-    UpdateHdl( &aIdle );
+    mxEntry->set_text(rStr);
+    UpdateHdl(&maIdle);
 }
 
 void RefEdit::StartUpdateData()
 {
-    aIdle.Start();
+    maIdle.Start();
 }
 
 void RefEdit::SetReferences(IControlReferenceHandler* pDlg, weld::Label* 
pLabel)
 {
-    pAnyRefDlg = pDlg;
-    pLabelWidget = pLabel;
+    mpAnyRefDlg = pDlg;
+    mpLabelWidget = pLabel;
 
     if( pDlg )
     {
-        aIdle.SetInvokeHandler(LINK(this, RefEdit, UpdateHdl));
+        maIdle.SetInvokeHandler(LINK(this, RefEdit, UpdateHdl));
     }
     else
     {
-        aIdle.ClearInvokeHandler();
-        aIdle.Stop();
+        maIdle.ClearInvokeHandler();
+        maIdle.Stop();
     }
 }
 
 IMPL_LINK_NOARG(RefEdit, Modify, weld::Entry&, void)
 {
     maModifyHdl.Call(*this);
-    if (pAnyRefDlg)
-        pAnyRefDlg->HideReference();
+    if (mpAnyRefDlg)
+        mpAnyRefDlg->HideReference();
 }
 
 IMPL_LINK(RefEdit, KeyInputHdl, const KeyEvent&, rKEvt, bool)
@@ -341,9 +342,9 @@ IMPL_LINK(RefEdit, KeyInputHdl, const KeyEvent&, rKEvt, 
bool)
 bool RefEdit::KeyInput(const KeyEvent& rKEvt)
 {
     const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
-    if (pAnyRefDlg && !rKeyCode.GetModifier() && rKeyCode.GetCode() == KEY_F2)
+    if (mpAnyRefDlg && !rKeyCode.GetModifier() && rKeyCode.GetCode() == KEY_F2)
     {
-        pAnyRefDlg->ReleaseFocus( this );
+        mpAnyRefDlg->ReleaseFocus(this);
         return true;
     }
 
@@ -366,8 +367,8 @@ void RefEdit::GetFocus()
 void RefEdit::LoseFocus()
 {
     maLoseFocusHdl.Call(*this);
-    if( pAnyRefDlg )
-        pAnyRefDlg->HideReference();
+    if (mpAnyRefDlg)
+        mpAnyRefDlg->HideReference();
 }
 
 IMPL_LINK_NOARG(RefEdit, GetFocusHdl, weld::Widget&, void)
@@ -403,8 +404,8 @@ IMPL_LINK_NOARG(RefEdit, AsyncFocusOutHdl, void*, void)
 
 IMPL_LINK_NOARG(RefEdit, UpdateHdl, Timer *, void)
 {
-    if( pAnyRefDlg )
-        pAnyRefDlg->ShowReference(xEntry->get_text());
+    if (mpAnyRefDlg)
+        mpAnyRefDlg->ShowReference(mxEntry->get_text());
 }
 
 RefButton::RefButton(std::unique_ptr<weld::Button> xControl)
diff --git a/include/formula/funcutl.hxx b/include/formula/funcutl.hxx
index 30a09f4eb9df..82f091d32eb8 100644
--- a/include/formula/funcutl.hxx
+++ b/include/formula/funcutl.hxx
@@ -36,12 +36,12 @@ class IControlReferenceHandler;
 class FORMULA_DLLPUBLIC RefEdit
 {
 protected:
-    std::unique_ptr<weld::Entry> xEntry;
+    std::unique_ptr<weld::Entry> mxEntry;
 
 private:
-    Idle aIdle;
-    IControlReferenceHandler* pAnyRefDlg; // parent dialog
-    weld::Label* pLabelWidget;
+    Idle maIdle;
+    IControlReferenceHandler* mpAnyRefDlg; // parent dialog
+    weld::Label* mpLabelWidget;
     ImplSVEvent* mpFocusInEvent;
     ImplSVEvent* mpFocusOutEvent;
 
@@ -67,7 +67,7 @@ protected:
 
 public:
     RefEdit(std::unique_ptr<weld::Entry> xControl);
-    weld::Entry* GetWidget() const { return xEntry.get(); }
+    weld::Entry* GetWidget() const { return mxEntry.get(); }
     virtual ~RefEdit();
 
     void SetRefString( const OUString& rStr );
@@ -81,7 +81,7 @@ public:
     void SetText(const OUString& rStr);
     OUString GetText() const
     {
-        return xEntry->get_text();
+        return mxEntry->get_text();
     }
 
     void StartUpdateData();
@@ -90,52 +90,52 @@ public:
 
     void DoModify()
     {
-        Modify(*xEntry);
+        Modify(*mxEntry);
     }
 
     void GrabFocus()
     {
-        xEntry->grab_focus();
+        mxEntry->grab_focus();
     }
 
     void SelectAll()
     {
-        xEntry->select_region(0, -1);
+        mxEntry->select_region(0, -1);
     }
 
     void SetSelection(const Selection& rSelection)
     {
-        xEntry->select_region(rSelection.Min(), rSelection.Max());
+        mxEntry->select_region(rSelection.Min(), rSelection.Max());
     }
 
     void SetCursorAtLast()
     {
-        xEntry->set_position(-1);
+        mxEntry->set_position(-1);
     }
 
     Selection GetSelection() const
     {
         int nStartPos, nEndPos;
-        xEntry->get_selection_bounds(nStartPos, nEndPos);
+        mxEntry->get_selection_bounds(nStartPos, nEndPos);
         return Selection(nStartPos, nEndPos);
     }
 
     OUString GetLabelTextForShrinkMode()
     {
-        if (pLabelWidget)
-            return pLabelWidget->get_label();
+        if (mpLabelWidget)
+            return mpLabelWidget->get_label();
 
         return OUString();
     }
 
     void SaveValue()
     {
-        xEntry->save_value();
+        mxEntry->save_value();
     }
 
     bool IsValueChangedFromSaved() const
     {
-        return xEntry->get_value_changed_from_saved();
+        return mxEntry->get_value_changed_from_saved();
     }
 
     void SetGetFocusHdl(const Link<RefEdit&,void>& rLink) { maGetFocusHdl = 
rLink; }
diff --git a/sc/source/ui/miscdlgs/optsolver.cxx 
b/sc/source/ui/miscdlgs/optsolver.cxx
index ef7832d38fa7..fa0f00f54aac 100644
--- a/sc/source/ui/miscdlgs/optsolver.cxx
+++ b/sc/source/ui/miscdlgs/optsolver.cxx
@@ -111,8 +111,8 @@ IMPL_LINK(ScSolverSuccessDialog, ClickHdl, weld::Button&, 
rBtn, void)
 ScCursorRefEdit::ScCursorRefEdit(std::unique_ptr<weld::Entry> xControl)
     : formula::RefEdit(std::move(xControl))
 {
-    xEntry->connect_key_press(Link<const KeyEvent&, bool>()); //acknowledge we 
first remove the old one
-    xEntry->connect_key_press(LINK(this, ScCursorRefEdit, KeyInputHdl));
+    mxEntry->connect_key_press(Link<const KeyEvent&, bool>()); //acknowledge 
we first remove the old one
+    mxEntry->connect_key_press(LINK(this, ScCursorRefEdit, KeyInputHdl));
 }
 
 void ScCursorRefEdit::SetCursorLinks( const Link<ScCursorRefEdit&,void>& rUp, 
const Link<ScCursorRefEdit&,void>& rDown )
commit 20e2b3696f3f1576ee00087d217cd5096128bbf8
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Fri Aug 8 10:54:27 2025 +0200
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sat Aug 9 08:08:16 2025 +0200

    tdf#130857 formula: Don't have getter for Label, but text
    
    Replace RefEdit::GetLabelWidgetForShrinkMode that
    returns a weld::Label with RefEdit::GetLabelTextForShrinkMode
    that only returns the label's text.
    
    This is the only information of interest in the caller, and
    for the case where the label is actually the label child of
    a frame (as in the example mentioned below) instead of an
    independent label, there will be no actual label for the
    native Qt implementation, as the QGroupBox used in
    QtInstanceFrame handles its title/text itself.
    
    This is one step towards getting rid of
    weld::Frame::weld_label_widget for the above reason.
    
    One way to trigger this code path:
    
    * start Calc
    * select some cells
    * "Data" -> "Define Range"
    * type "foobar" into the name field
    * click on the "Shrink" button
    
    Change-Id: I3b987a052fe4ba72a6793671a7a81142b12afe95
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189217
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/formula/funcutl.hxx b/include/formula/funcutl.hxx
index a41f9c09a60a..30a09f4eb9df 100644
--- a/include/formula/funcutl.hxx
+++ b/include/formula/funcutl.hxx
@@ -120,9 +120,12 @@ public:
         return Selection(nStartPos, nEndPos);
     }
 
-    weld::Label* GetLabelWidgetForShrinkMode()
+    OUString GetLabelTextForShrinkMode()
     {
-        return pLabelWidget;
+        if (pLabelWidget)
+            return pLabelWidget->get_label();
+
+        return OUString();
     }
 
     void SaveValue()
diff --git a/sc/source/ui/miscdlgs/anyrefdg.cxx 
b/sc/source/ui/miscdlgs/anyrefdg.cxx
index 6676b996ea69..06fec4bb8cb9 100644
--- a/sc/source/ui/miscdlgs/anyrefdg.cxx
+++ b/sc/source/ui/miscdlgs/anyrefdg.cxx
@@ -375,14 +375,11 @@ void ScFormulaReferenceHelper::RefInputStart( 
formula::RefEdit* pEdit, formula::
 
     // Save and adjust window title
     m_sOldDialogText = m_pDialog->get_title();
-    if (weld::Label *pLabel = m_pRefEdit->GetLabelWidgetForShrinkMode())
+    const OUString sLabel = m_pRefEdit->GetLabelTextForShrinkMode();
+    if (!sLabel.isEmpty())
     {
-        const OUString sLabel = pLabel->get_label();
-        if (!sLabel.isEmpty())
-        {
-            const OUString sNewDialogText = m_sOldDialogText + ": " + 
comphelper::string::stripEnd(sLabel, ':');
-            m_pDialog->set_title(pLabel->strip_mnemonic(sNewDialogText));
-        }
+        const OUString sNewDialogText = m_sOldDialogText + ": " + 
comphelper::string::stripEnd(sLabel, ':');
+        m_pDialog->set_title(m_pDialog->strip_mnemonic(sNewDialogText));
     }
 
     m_pDialog->collapse(pEdit->GetWidget(), pButton ? pButton->GetWidget() : 
nullptr);

Reply via email to