[Libreoffice-commits] core.git: framework/inc framework/source solenv/sanitizers svtools/uiconfig svtools/UIConfig_svt.mk

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Wed Apr 22 18:11:35 UTC 2020


 framework/inc/uielement/edittoolbarcontroller.hxx    |    2 
 framework/source/uielement/edittoolbarcontroller.cxx |  102 ++++++++-----------
 solenv/sanitizers/ui/svt.suppr                       |    1 
 svtools/UIConfig_svt.mk                              |    1 
 svtools/uiconfig/ui/editcontrol.ui                   |   26 ++++
 5 files changed, 77 insertions(+), 55 deletions(-)

New commits:
commit 0ea8aab3ed9defd45de4b64d7bfbbd05b3053e0a
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Wed Apr 22 14:17:20 2020 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Wed Apr 22 20:10:56 2020 +0200

    weld EditControl
    
    as used by the LibreLogo toolbar
    
    Change-Id: Ice60d1f5146a58cab5bab44a12a2bdcf4dbd77ec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/92703
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/framework/inc/uielement/edittoolbarcontroller.hxx b/framework/inc/uielement/edittoolbarcontroller.hxx
index 3344ed1319f2..193af5920634 100644
--- a/framework/inc/uielement/edittoolbarcontroller.hxx
+++ b/framework/inc/uielement/edittoolbarcontroller.hxx
@@ -51,7 +51,7 @@ class EditToolbarController final : public ComplexToolbarController
         void Modify();
         void GetFocus();
         void LoseFocus();
-        bool PreNotify( NotifyEvent const & rNEvt );
+        void Activate();
 
     private:
         virtual void executeControlCommand( const css::frame::ControlCommand& rControlCommand ) override;
diff --git a/framework/source/uielement/edittoolbarcontroller.cxx b/framework/source/uielement/edittoolbarcontroller.cxx
index 5b6cd39cd45d..52c5164629db 100644
--- a/framework/source/uielement/edittoolbarcontroller.cxx
+++ b/framework/source/uielement/edittoolbarcontroller.cxx
@@ -20,12 +20,11 @@
 #include <uielement/edittoolbarcontroller.hxx>
 
 #include <com/sun/star/beans/PropertyValue.hpp>
-
+#include <svtools/InterimItemWindow.hxx>
 #include <svtools/toolboxcontroller.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/toolbox.hxx>
 #include <vcl/event.hxx>
-#include <vcl/edit.hxx>
 
 using namespace ::com::sun::star;
 using namespace css::uno;
@@ -41,26 +40,37 @@ namespace framework
 // Unfortunaltly the events are notified through virtual methods instead
 // of Listeners.
 
-class EditControl : public Edit
+class EditControl : public InterimItemWindow
 {
-    public:
-        EditControl( vcl::Window* pParent, WinBits nStyle, EditToolbarController* pEditToolbarController );
-        virtual ~EditControl() override;
-        virtual void dispose() override;
+public:
+    EditControl(vcl::Window* pParent, EditToolbarController* pEditToolbarController);
+    virtual ~EditControl() override;
+    virtual void dispose() override;
+
+    OUString get_text() const { return m_xWidget->get_text(); }
+    void set_text(const OUString& rText) { m_xWidget->set_text(rText); }
 
-        virtual void Modify() override;
-        virtual void GetFocus() override;
-        virtual void LoseFocus() override;
-        virtual bool PreNotify( NotifyEvent& rNEvt ) override;
+private:
+    std::unique_ptr<weld::Entry> m_xWidget;
+    EditToolbarController* m_pEditToolbarController;
 
-    private:
-        EditToolbarController* m_pEditToolbarController;
+    DECL_LINK(FocusInHdl, weld::Widget&, void);
+    DECL_LINK(FocusOutHdl, weld::Widget&, void);
+    DECL_LINK(ModifyHdl, weld::Entry&, void);
+    DECL_LINK(ActivateHdl, weld::Entry&, bool);
 };
 
-EditControl::EditControl( vcl::Window* pParent, WinBits nStyle, EditToolbarController* pEditToolbarController ) :
-    Edit( pParent, nStyle )
-    , m_pEditToolbarController( pEditToolbarController )
+EditControl::EditControl(vcl::Window* pParent, EditToolbarController* pEditToolbarController)
+    : InterimItemWindow(pParent, "svt/ui/editcontrol.ui", "EditControl")
+    , m_xWidget(m_xBuilder->weld_entry("entry"))
+    , m_pEditToolbarController(pEditToolbarController)
 {
+    m_xWidget->connect_focus_in(LINK(this, EditControl, FocusInHdl));
+    m_xWidget->connect_focus_out(LINK(this, EditControl, FocusOutHdl));
+    m_xWidget->connect_changed(LINK(this, EditControl, ModifyHdl));
+    m_xWidget->connect_activate(LINK(this, EditControl, ActivateHdl));
+
+    SetSizePixel(get_preferred_size());
 }
 
 EditControl::~EditControl()
@@ -71,39 +81,34 @@ EditControl::~EditControl()
 void EditControl::dispose()
 {
     m_pEditToolbarController = nullptr;
-    Edit::dispose();
+    m_xWidget.reset();
+    InterimItemWindow::dispose();
 }
 
-void EditControl::Modify()
+IMPL_LINK_NOARG(EditControl, ModifyHdl, weld::Entry&, void)
 {
-    Edit::Modify();
-    if ( m_pEditToolbarController )
+    if (m_pEditToolbarController)
         m_pEditToolbarController->Modify();
 }
 
-void EditControl::GetFocus()
+IMPL_LINK_NOARG(EditControl, FocusInHdl, weld::Widget&, void)
 {
-    Edit::GetFocus();
-    if ( m_pEditToolbarController )
+    if (m_pEditToolbarController)
         m_pEditToolbarController->GetFocus();
 }
 
-void EditControl::LoseFocus()
+IMPL_LINK_NOARG(EditControl, FocusOutHdl, weld::Widget&, void)
 {
-    Edit::LoseFocus();
     if ( m_pEditToolbarController )
         m_pEditToolbarController->LoseFocus();
 }
 
-bool EditControl::PreNotify( NotifyEvent& rNEvt )
-{
-    bool bRet = false;
-    if ( m_pEditToolbarController )
-        bRet = m_pEditToolbarController->PreNotify( rNEvt );
-    if ( !bRet )
-        bRet = Edit::PreNotify( rNEvt );
 
-    return bRet;
+IMPL_LINK_NOARG(EditControl, ActivateHdl, weld::Entry&, bool)
+{
+    if (m_pEditToolbarController)
+        m_pEditToolbarController->Activate();
+    return true;
 }
 
 EditToolbarController::EditToolbarController(
@@ -116,12 +121,12 @@ EditToolbarController::EditToolbarController(
     ComplexToolbarController( rxContext, rFrame, pToolbar, nID, aCommand )
     ,   m_pEditControl( nullptr )
 {
-    m_pEditControl = VclPtr<EditControl>::Create( m_xToolbar, WB_BORDER, this );
+    m_pEditControl = VclPtr<EditControl>::Create(m_xToolbar, this);
     if ( nWidth == 0 )
         nWidth = 100;
 
-    // Calculate height of the edit field according to the application font height
-    sal_Int32 nHeight = getFontSizePixel( m_pEditControl ) + 6 + 1;
+    // EditControl ctor has set a suitable height already
+    auto nHeight = m_pEditControl->GetSizePixel().Height();
 
     m_pEditControl->SetSizePixel( ::Size( nWidth, nHeight ));
     m_xToolbar->SetItemWindow( m_nID, m_pEditControl );
@@ -144,7 +149,7 @@ void SAL_CALL EditToolbarController::dispose()
 Sequence<PropertyValue> EditToolbarController::getExecuteArgs(sal_Int16 KeyModifier) const
 {
     Sequence<PropertyValue> aArgs( 2 );
-    OUString aSelectedText = m_pEditControl->GetText();
+    OUString aSelectedText = m_pEditControl->get_text();
 
     // Add key modifier to argument list
     aArgs[0].Name = "KeyModifier";
@@ -156,7 +161,7 @@ Sequence<PropertyValue> EditToolbarController::getExecuteArgs(sal_Int16 KeyModif
 
 void EditToolbarController::Modify()
 {
-    notifyTextChanged( m_pEditControl->GetText() );
+    notifyTextChanged(m_pEditControl->get_text());
 }
 
 void EditToolbarController::GetFocus()
@@ -169,22 +174,11 @@ void EditToolbarController::LoseFocus()
     notifyFocusLost();
 }
 
-bool EditToolbarController::PreNotify( NotifyEvent const & rNEvt )
+void EditToolbarController::Activate()
 {
-    if( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
-    {
-        const ::KeyEvent* pKeyEvent = rNEvt.GetKeyEvent();
-        const vcl::KeyCode& rKeyCode = pKeyEvent->GetKeyCode();
-        if(( rKeyCode.GetModifier() | rKeyCode.GetCode()) == KEY_RETURN )
-        {
-            // Call execute only with non-empty text
-            if ( !m_pEditControl->GetText().isEmpty() )
-                execute( rKeyCode.GetModifier() );
-            return true;
-        }
-    }
-
-    return false;
+    // Call execute only with non-empty text
+    if (!m_pEditControl->get_text().isEmpty())
+        execute(0);
 }
 
 void EditToolbarController::executeControlCommand( const css::frame::ControlCommand& rControlCommand )
@@ -198,7 +192,7 @@ void EditToolbarController::executeControlCommand( const css::frame::ControlComm
         {
             OUString aText;
             rControlCommand.Arguments[i].Value >>= aText;
-            m_pEditControl->SetText( aText );
+            m_pEditControl->set_text(aText);
 
             // send notification
             notifyTextChanged( aText );
diff --git a/solenv/sanitizers/ui/svt.suppr b/solenv/sanitizers/ui/svt.suppr
index 4b1b491f93e4..cf9087586f97 100644
--- a/solenv/sanitizers/ui/svt.suppr
+++ b/solenv/sanitizers/ui/svt.suppr
@@ -1,3 +1,4 @@
+svtools/uiconfig/ui/editcontrol.ui://GtkEntry[@id='entry'] no-labelled-by
 svtools/uiconfig/ui/graphicexport.ui://GtkSpinButton[@id='compressionjpgnf'] no-labelled-by
 svtools/uiconfig/ui/graphicexport.ui://GtkScale[@id='compressionjpgsb'] no-labelled-by
 svtools/uiconfig/ui/graphicexport.ui://GtkSpinButton[@id='compressionpngnf'] no-labelled-by
diff --git a/svtools/UIConfig_svt.mk b/svtools/UIConfig_svt.mk
index dd4744f620b8..88078d2bf6a0 100644
--- a/svtools/UIConfig_svt.mk
+++ b/svtools/UIConfig_svt.mk
@@ -12,6 +12,7 @@ $(eval $(call gb_UIConfig_UIConfig,svt))
 $(eval $(call gb_UIConfig_add_uifiles,svt,\
 	svtools/uiconfig/ui/addresstemplatedialog \
 	svtools/uiconfig/ui/datewindow \
+	svtools/uiconfig/ui/editcontrol \
 	svtools/uiconfig/ui/emptypage \
 	svtools/uiconfig/ui/fileviewmenu \
 	svtools/uiconfig/ui/graphicexport \
diff --git a/svtools/uiconfig/ui/editcontrol.ui b/svtools/uiconfig/ui/editcontrol.ui
new file mode 100644
index 000000000000..3be2e248711d
--- /dev/null
+++ b/svtools/uiconfig/ui/editcontrol.ui
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface domain="svt">
+  <requires lib="gtk+" version="3.18"/>
+  <object class="GtkBox" id="EditControl">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="hexpand">True</property>
+    <property name="spacing">6</property>
+    <child>
+      <object class="GtkEntry" id="entry">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="activates_default">True</property>
+        <property name="width_chars">1</property>
+      </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