[Libreoffice-commits] core.git: sc/source sc/uiconfig sc/UIConfig_scalc.mk

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Mon Feb 17 12:40:44 UTC 2020


 sc/UIConfig_scalc.mk           |    1 
 sc/source/ui/app/inputwin.cxx  |  204 +++++++++++++++++++++--------------------
 sc/source/ui/inc/inputwin.hxx  |   20 ++--
 sc/uiconfig/scalc/ui/posbox.ui |   29 +++++
 4 files changed, 153 insertions(+), 101 deletions(-)

New commits:
commit 6407eb952efae074850c4e8c52c630397914a145
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Mon Feb 17 10:49:59 2020 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Mon Feb 17 13:39:58 2020 +0100

    weld ScPosWnd Item Window
    
    Change-Id: I63eb8511a91a631be760b8ae62465c2dc3a05efc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88856
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/sc/UIConfig_scalc.mk b/sc/UIConfig_scalc.mk
index 7268ec8013f7..3035aa28e2bb 100644
--- a/sc/UIConfig_scalc.mk
+++ b/sc/UIConfig_scalc.mk
@@ -186,6 +186,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/scalc,\
 	sc/uiconfig/scalc/ui/pivotfielddialog \
 	sc/uiconfig/scalc/ui/pivotfilterdialog \
 	sc/uiconfig/scalc/ui/pivottablelayoutdialog \
+	sc/uiconfig/scalc/ui/posbox \
 	sc/uiconfig/scalc/ui/printareasdialog \
 	sc/uiconfig/scalc/ui/printeroptions \
 	sc/uiconfig/scalc/ui/protectsheetdlg \
diff --git a/sc/source/ui/app/inputwin.cxx b/sc/source/ui/app/inputwin.cxx
index 8117330bf114..bf80fc89b07f 100644
--- a/sc/source/ui/app/inputwin.cxx
+++ b/sc/source/ui/app/inputwin.cxx
@@ -1979,21 +1979,32 @@ void ScTextWnd::TextGrabFocus()
 
 // Position window
 
-ScPosWnd::ScPosWnd( vcl::Window* pParent ) :
-    ComboBox    ( pParent, WinBits(WB_HIDE | WB_DROPDOWN) ),
-    nTipVisible ( nullptr ),
-    bFormulaMode( false )
-{
-    set_id("pos_window");
-    Size aSize( GetTextWidth( "GW99999:GW99999" ),
-                GetTextHeight() );
-    aSize.AdjustWidth(25 );    // FIXME: ??
-    aSize.setHeight( CalcWindowSizePixel(21) ); // Functions: 20 MRU + "others..."
-    SetSizePixel( aSize );
+ScPosWnd::ScPosWnd(vcl::Window* pParent)
+    : InterimItemWindow(pParent, "modules/scalc/ui/posbox.ui", "PosBox")
+    , m_xWidget(m_xBuilder->weld_combo_box("pos_window"))
+    , m_nAsyncGetFocusId(nullptr)
+    , nTipVisible(nullptr)
+    , bFormulaMode(false)
+{
+    m_xWidget->set_entry_width_chars(15);
+    SetSizePixel(m_xContainer->get_preferred_size());
 
     FillRangeNames();
 
     StartListening( *SfxGetpApp() ); // For Navigator rangename updates
+
+    m_xWidget->connect_key_press(LINK(this, ScPosWnd, KeyInputHdl));
+    m_xWidget->connect_entry_activate(LINK(this, ScPosWnd, ActivateHdl));
+    m_xWidget->connect_changed(LINK(this, ScPosWnd, ModifyHdl));
+    m_xWidget->connect_focus_in(LINK(this, ScPosWnd, FocusInHdl));
+    m_xWidget->connect_focus_out(LINK(this, ScPosWnd, FocusOutHdl));
+}
+
+void ScPosWnd::GetFocus()
+{
+    if (m_xWidget)
+        m_xWidget->grab_focus();
+    InterimItemWindow::GetFocus();
 }
 
 ScPosWnd::~ScPosWnd()
@@ -2007,7 +2018,14 @@ void ScPosWnd::dispose()
 
     HideTip();
 
-    ComboBox::dispose();
+    if (m_nAsyncGetFocusId)
+    {
+        Application::RemoveUserEvent(m_nAsyncGetFocusId);
+        m_nAsyncGetFocusId = nullptr;
+    }
+    m_xWidget.reset();
+
+    InterimItemWindow::dispose();
 }
 
 void ScPosWnd::SetFormulaMode( bool bSet )
@@ -2030,7 +2048,7 @@ void ScPosWnd::SetPos( const OUString& rPosStr )
     if ( aPosStr != rPosStr )
     {
         aPosStr = rPosStr;
-        SetText(aPosStr);
+        m_xWidget->set_entry_text(aPosStr);
     }
 }
 
@@ -2045,15 +2063,16 @@ OUString createLocalRangeName(const OUString& rName, const OUString& rTableName)
 
 void ScPosWnd::FillRangeNames()
 {
-    Clear();
+    m_xWidget->clear();
+    m_xWidget->freeze();
 
     SfxObjectShell* pObjSh = SfxObjectShell::Current();
     if ( auto pDocShell = dynamic_cast<ScDocShell*>( pObjSh) )
     {
         ScDocument& rDoc = pDocShell->GetDocument();
 
-        InsertEntry(ScResId( STR_MANAGE_NAMES ));
-        SetSeparatorPos(0);
+        m_xWidget->append_text(ScResId(STR_MANAGE_NAMES));
+        m_xWidget->append_separator("separator");
 
         ScRange aDummy;
         std::set<OUString> aSet;
@@ -2080,15 +2099,17 @@ void ScPosWnd::FillRangeNames()
 
         for (const auto& rItem : aSet)
         {
-            InsertEntry(rItem);
+            m_xWidget->append_text(rItem);
         }
     }
-    SetText(aPosStr);
+    m_xWidget->thaw();
+    m_xWidget->set_entry_text(aPosStr);
 }
 
 void ScPosWnd::FillFunctions()
 {
-    Clear();
+    m_xWidget->clear();
+    m_xWidget->freeze();
 
     OUString aFirstName;
     const ScAppOptions& rOpt = SC_MOD()->GetAppOptions();
@@ -2106,7 +2127,7 @@ void ScPosWnd::FillFunctions()
                 const ScFuncDesc* pDesc = pFuncList->GetFunction( j );
                 if ( pDesc->nFIndex == nId && pDesc->mxFuncName )
                 {
-                    InsertEntry( *pDesc->mxFuncName );
+                    m_xWidget->append_text(*pDesc->mxFuncName);
                     if (aFirstName.isEmpty())
                         aFirstName = *pDesc->mxFuncName;
                     break; // Stop searching
@@ -2118,9 +2139,10 @@ void ScPosWnd::FillFunctions()
     //! Re-add entry "Other..." for Function AutoPilot if it can work with text that
     // has been entered so far
 
-    //  InsertEntry( ScResId(STR_FUNCTIONLIST_MORE) );
+    //  m_xWidget->append_text(ScResId(STR_FUNCTIONLIST_MORE));
 
-    SetText(aFirstName);
+    m_xWidget->thaw();
+    m_xWidget->set_entry_text(aFirstName);
 }
 
 void ScPosWnd::Notify( SfxBroadcaster&, const SfxHint& rHint )
@@ -2145,12 +2167,9 @@ void ScPosWnd::Notify( SfxBroadcaster&, const SfxHint& rHint )
 
 void ScPosWnd::HideTip()
 {
-    if ( nTipVisible )
+    if (nTipVisible)
     {
-        vcl::Window* pWin = GetSubEdit();
-        if (!pWin)
-            pWin = this;
-        Help::HidePopover(pWin, nTipVisible);
+        Help::HidePopover(this, nTipVisible);
         nTipVisible = nullptr;
     }
 }
@@ -2203,17 +2222,21 @@ static ScNameInputType lcl_GetInputType( const OUString& rText )
     return eRet;
 }
 
-void ScPosWnd::Modify()
+IMPL_LINK_NOARG(ScPosWnd, ModifyHdl, weld::ComboBox&, void)
 {
-    ComboBox::Modify();
-
     HideTip();
 
-    if ( !IsTravelSelect() && !bFormulaMode )
+    if (m_xWidget->changed_by_direct_pick())
+    {
+        DoEnter();
+        return;
+    }
+
+    if (!bFormulaMode)
     {
         // determine the action that would be taken for the current input
 
-        ScNameInputType eType = lcl_GetInputType( GetText() );      // uses current view
+        ScNameInputType eType = lcl_GetInputType(m_xWidget->get_active_text());      // uses current view
         const char* pStrId = nullptr;
         switch ( eType )
         {
@@ -2244,36 +2267,23 @@ void ScPosWnd::Modify()
         if (pStrId)
         {
             // show the help tip at the text cursor position
-            vcl::Window* pWin = GetSubEdit();
-            if (!pWin)
-                pWin = this;
             Point aPos;
-            vcl::Cursor* pCur = pWin->GetCursor();
+            vcl::Cursor* pCur = GetCursor();
             if (pCur)
-                aPos = pWin->LogicToPixel( pCur->GetPos() );
-            aPos = pWin->OutputToScreenPixel( aPos );
+                aPos = LogicToPixel( pCur->GetPos() );
+            aPos = OutputToScreenPixel( aPos );
             tools::Rectangle aRect( aPos, aPos );
 
             OUString aText = ScResId(pStrId);
             QuickHelpFlags const nAlign = QuickHelpFlags::Left|QuickHelpFlags::Bottom;
-            nTipVisible = Help::ShowPopover(pWin, aRect, aText, nAlign);
+            nTipVisible = Help::ShowPopover(this, aRect, aText, nAlign);
         }
     }
 }
 
-void ScPosWnd::Select()
-{
-    ComboBox::Select(); //  In VCL GetText() only return the selected entry afterwards
-
-    HideTip();
-
-    if (!IsTravelSelect())
-        DoEnter();
-}
-
 void ScPosWnd::DoEnter()
 {
-    OUString aText = GetText();
+    OUString aText = m_xWidget->get_active_text();
     if ( !aText.isEmpty() )
     {
         if ( bFormulaMode )
@@ -2364,66 +2374,70 @@ void ScPosWnd::DoEnter()
         }
     }
     else
-        SetText( aPosStr );
+        m_xWidget->set_entry_text(aPosStr);
 
     ReleaseFocus_Impl();
 }
 
-bool ScPosWnd::EventNotify( NotifyEvent& rNEvt )
+IMPL_LINK_NOARG(ScPosWnd, ActivateHdl, weld::ComboBox&, bool)
+{
+    DoEnter();
+    return true;
+}
+
+IMPL_LINK(ScPosWnd, KeyInputHdl, const KeyEvent&, rKEvt, bool)
 {
     bool bHandled = true;
 
-    switch (rNEvt.GetType())
+    switch (rKEvt.GetKeyCode().GetCode())
     {
-        case MouseNotifyEvent::KEYINPUT:
-        {
-            const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
-
-            switch ( pKEvt->GetKeyCode().GetCode() )
+        case KEY_RETURN:
+            bHandled = ActivateHdl(*m_xWidget);
+            break;
+        case KEY_ESCAPE:
+            if (nTipVisible)
             {
-                case KEY_RETURN:
-                    DoEnter();
-                    break;
-
-                case KEY_ESCAPE:
-                    if (nTipVisible)
-                    {
-                        // escape when the tip help is shown: only hide the tip
-                        HideTip();
-                    }
-                    else
-                    {
-                        if (!bFormulaMode)
-                            SetText( aPosStr );
-                        ReleaseFocus_Impl();
-                    }
-                    break;
-
-                default:
-                    bHandled = false;
-                    break;
+                // escape when the tip help is shown: only hide the tip
+                HideTip();
             }
-        }
-        break;
-        case MouseNotifyEvent::GETFOCUS:
-        {
-            // Select the whole text upon focus.
-            OUString aStr = GetText();
-            SetSelection(Selection(0, aStr.getLength()));
-        }
-        break;
-        case MouseNotifyEvent::LOSEFOCUS:
-            HideTip();
-            bHandled = false;
-        break;
+            else
+            {
+                if (!bFormulaMode)
+                    m_xWidget->set_entry_text(aPosStr);
+                ReleaseFocus_Impl();
+            }
+            break;
         default:
             bHandled = false;
+            break;
     }
 
-    if (!bHandled)
-        bHandled = ComboBox::EventNotify(rNEvt);
+    return bHandled || ChildKeyInput(rKEvt);
+}
+
+IMPL_LINK_NOARG(ScPosWnd, OnAsyncGetFocus, void*, void)
+{
+    m_nAsyncGetFocusId = nullptr;
+    m_xWidget->select_entry_region(0, -1);
+}
 
-    return bHandled;
+IMPL_LINK_NOARG(ScPosWnd, FocusInHdl, weld::Widget&, void)
+{
+    if (m_nAsyncGetFocusId)
+        return;
+    // do it async to defeat entry in combobox having its own ideas about the focus
+    m_nAsyncGetFocusId = Application::PostUserEvent(LINK(this, ScPosWnd, OnAsyncGetFocus));
+}
+
+IMPL_LINK_NOARG(ScPosWnd, FocusOutHdl, weld::Widget&, void)
+{
+    if (m_nAsyncGetFocusId)
+    {
+        Application::RemoveUserEvent(m_nAsyncGetFocusId);
+        m_nAsyncGetFocusId = nullptr;
+    }
+
+    HideTip();
 }
 
 void ScPosWnd::ReleaseFocus_Impl()
diff --git a/sc/source/ui/inc/inputwin.hxx b/sc/source/ui/inc/inputwin.hxx
index a60d879cb091..a04e87e529a9 100644
--- a/sc/source/ui/inc/inputwin.hxx
+++ b/sc/source/ui/inc/inputwin.hxx
@@ -23,6 +23,7 @@
 #include <vector>
 #include <memory>
 #include <vcl/toolbox.hxx>
+#include <sfx2/InterimItemWindow.hxx>
 #include <sfx2/childwin.hxx>
 #include <svl/lstner.hxx>
 #include <vcl/button.hxx>
@@ -149,9 +150,13 @@ private:
     bool mbInvalidate;
 };
 
-class ScPosWnd : public ComboBox, public SfxListener        // Display position
+class ScPosWnd final : public InterimItemWindow, public SfxListener        // Display position
 {
 private:
+    std::unique_ptr<weld::ComboBox> m_xWidget;
+
+    ImplSVEvent* m_nAsyncGetFocusId;
+
     OUString        aPosStr;
     void*           nTipVisible;
     bool            bFormulaMode;
@@ -160,15 +165,18 @@ public:
                     ScPosWnd( vcl::Window* pParent );
     virtual         ~ScPosWnd() override;
     virtual void    dispose() override;
+    virtual void    GetFocus() override;
 
     void            SetPos( const OUString& rPosStr );        // Displayed Text
     void            SetFormulaMode( bool bSet );
 
-protected:
-    virtual void    Select() override;
-    virtual void    Modify() override;
-
-    virtual bool    EventNotify( NotifyEvent& rNEvt ) override;
+private:
+    DECL_LINK(OnAsyncGetFocus, void*, void);
+    DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
+    DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
+    DECL_LINK(ModifyHdl, weld::ComboBox&, void);
+    DECL_LINK(FocusInHdl, weld::Widget&, void);
+    DECL_LINK(FocusOutHdl, weld::Widget&, void);
 
     virtual void    Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
 
diff --git a/sc/uiconfig/scalc/ui/posbox.ui b/sc/uiconfig/scalc/ui/posbox.ui
new file mode 100644
index 000000000000..a474a251702c
--- /dev/null
+++ b/sc/uiconfig/scalc/ui/posbox.ui
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface domain="sc">
+  <requires lib="gtk+" version="3.18"/>
+  <object class="GtkBox" id="PosBox">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="orientation">vertical</property>
+    <child>
+      <object class="GtkComboBoxText" id="pos_window">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="has_entry">True</property>
+        <child internal-child="entry">
+          <object class="GtkEntry">
+            <property name="can_focus">True</property>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="expand">False</property>
+        <property name="fill">True</property>
+        <property name="position">0</property>
+      </packing>
+    </child>
+  </object>
+</interface>


More information about the Libreoffice-commits mailing list