[Libreoffice-commits] core.git: starmath/inc starmath/source

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Fri May 7 07:47:51 UTC 2021


 starmath/inc/edit.hxx    |   30 ++++++++------
 starmath/inc/view.hxx    |   16 +++----
 starmath/source/edit.cxx |   99 ++++++++++++++++-------------------------------
 starmath/source/view.cxx |   99 ++++++++++++++++++++++-------------------------
 4 files changed, 106 insertions(+), 138 deletions(-)

New commits:
commit 148ad7cf92b216351fce464528af8db0111157f4
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu May 6 16:28:12 2021 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri May 7 09:47:09 2021 +0200

    remove an intermediate layer of widgets
    
    Change-Id: I4fe23f87d997057a2cb061110c8e325c8322b95e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115187
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/starmath/inc/edit.hxx b/starmath/inc/edit.hxx
index 773355cfff14..0bed0b169a2f 100644
--- a/starmath/inc/edit.hxx
+++ b/starmath/inc/edit.hxx
@@ -20,7 +20,6 @@
 #pragma once
 
 #include <svx/weldeditview.hxx>
-#include <vcl/InterimItemWindow.hxx>
 #include <vcl/idle.hxx>
 #include <vcl/transfer.hxx>
 
@@ -72,6 +71,7 @@ public:
     virtual bool Command(const CommandEvent& rCEvt) override;
     virtual void GetFocus() override;
     virtual void LoseFocus() override;
+    virtual void StyleUpdated() override;
 
     void SetText(const OUString& rText);
     void InsertText(const OUString& rText);
@@ -83,34 +83,38 @@ public:
     void StartCursorMove();
 };
 
-class SmEditWindow final : public InterimItemWindow
+class SmEditWindow final
 {
     SmCmdBoxWindow& rCmdBox;
     std::unique_ptr<weld::ScrolledWindow> mxScrolledWindow;
     std::unique_ptr<SmEditTextWindow> mxTextControl;
     std::unique_ptr<weld::CustomWeld> mxTextControlWin;
 
-    virtual void ApplySettings(vcl::RenderContext&) override;
-    virtual void DataChanged(const DataChangedEvent&) override;
-
     DECL_LINK(ScrollHdl, weld::ScrolledWindow&, void);
 
-    void CreateEditView();
+    void CreateEditView(weld::Builder& rBuilder);
 
 public:
-    explicit SmEditWindow(SmCmdBoxWindow& rMyCmdBoxWin);
-    virtual ~SmEditWindow() override;
-    virtual void dispose() override;
+    SmEditWindow(SmCmdBoxWindow& rMyCmdBoxWin, weld::Builder& rBuilder);
+    ~SmEditWindow();
+
+    weld::Window* GetFrameWeld() const;
 
     SmDocShell* GetDoc();
     SmViewShell* GetView();
     EditView* GetEditView() const;
     EditEngine* GetEditEngine();
+    SmCmdBoxWindow& GetCmdBox() const { return rCmdBox; }
+
+    void SetText(const OUString& rText);
+    OUString GetText() const;
+    void Flush();
+    void GrabFocus();
 
-    // Window
-    virtual void SetText(const OUString& rText) override;
-    virtual OUString GetText() const override;
-    virtual void Command(const CommandEvent& rCEvt) override;
+    css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const
+    {
+        return mxTextControl->GetClipboard();
+    }
 
     ESelection GetSelection() const;
     void SetSelection(const ESelection& rSel);
diff --git a/starmath/inc/view.hxx b/starmath/inc/view.hxx
index 94733e251cf5..320a3b065863 100644
--- a/starmath/inc/view.hxx
+++ b/starmath/inc/view.hxx
@@ -27,6 +27,7 @@
 #include <sfx2/ctrlitem.hxx>
 #include <sfx2/shell.hxx>
 #include <sfx2/viewfrm.hxx>
+#include <vcl/InterimItemWindow.hxx>
 #include <vcl/timer.hxx>
 #include "document.hxx"
 #include "edit.hxx"
@@ -182,7 +183,7 @@ public:
 
 class SmCmdBoxWindow : public SfxDockingWindow
 {
-    VclPtr<SmEditWindow>        aEdit;
+    std::unique_ptr<SmEditWindow> m_xEdit;
     SmEditController    aController;
     bool                bExiting;
 
@@ -192,12 +193,6 @@ class SmCmdBoxWindow : public SfxDockingWindow
 
 protected:
 
-    // Window
-    virtual void    GetFocus() override;
-    virtual void Resize() override;
-    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
-    virtual void StateChanged( StateChangedType nStateChange ) override;
-
     virtual Size CalcDockingSize(SfxChildAlignment eAlign) override;
     virtual SfxChildAlignment CheckAlignment(SfxChildAlignment eActual,
                                              SfxChildAlignment eWish) override;
@@ -212,11 +207,16 @@ public:
     virtual ~SmCmdBoxWindow () override;
     virtual void dispose() override;
 
+    // Window
+    virtual void GetFocus() override;
+    virtual void StateChanged( StateChangedType nStateChange ) override;
+    virtual void Command(const CommandEvent& rCEvt) override;
+
     void AdjustPosition();
 
     SmEditWindow& GetEditWindow()
     {
-        return *aEdit;
+        return *m_xEdit;
     }
     SmViewShell* GetView();
 };
diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx
index 2a23122d395a..52c86a3b3f5e 100644
--- a/starmath/source/edit.cxx
+++ b/starmath/source/edit.cxx
@@ -100,6 +100,8 @@ void SmEditTextWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
 {
     weld::CustomWidgetController::SetDrawingArea(pDrawingArea);
 
+    SetHelpId(HID_SMA_COMMAND_WIN_EDIT);
+
     EnableRTL(false);
 
     EditEngine* pEditEngine = GetEditEngine();
@@ -118,42 +120,24 @@ void SmEditTextWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
     InitAccessible();
 }
 
-SmEditWindow::SmEditWindow(SmCmdBoxWindow &rMyCmdBoxWin)
-    : InterimItemWindow(&rMyCmdBoxWin, "modules/smath/ui/editwindow.ui", "EditWindow")
-    , rCmdBox(rMyCmdBoxWin)
-    , mxScrolledWindow(m_xBuilder->weld_scrolled_window("scrolledwindow", true))
+SmEditWindow::SmEditWindow(SmCmdBoxWindow &rMyCmdBoxWin, weld::Builder& rBuilder)
+    : rCmdBox(rMyCmdBoxWin)
+    , mxScrolledWindow(rBuilder.weld_scrolled_window("scrolledwindow", true))
 {
-    set_id("math_edit");
-    SetHelpId(HID_SMA_COMMAND_WIN_EDIT);
-    SetMapMode(MapMode(MapUnit::MapPixel));
-
-    // Even RTL languages don't use RTL for math
-    EnableRTL( false );
-
-    // compare DataChanged
-    SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
-
     mxScrolledWindow->connect_vadjustment_changed(LINK(this, SmEditWindow, ScrollHdl));
 
-    CreateEditView();
-
-    // if not called explicitly the this edit window within the
-    // command window will just show an empty gray panel.
-    Show();
+    CreateEditView(rBuilder);
 }
 
 SmEditWindow::~SmEditWindow()
-{
-    disposeOnce();
-}
-
-void SmEditWindow::dispose()
 {
     DeleteEditView();
-
     mxScrolledWindow.reset();
+}
 
-    InterimItemWindow::dispose();
+weld::Window* SmEditWindow::GetFrameWeld() const
+{
+    return rCmdBox.GetFrameWeld();
 }
 
 void SmEditTextWindow::StartCursorMove()
@@ -193,31 +177,18 @@ EditEngine * SmEditWindow::GetEditEngine()
     return nullptr;
 }
 
-void SmEditWindow::ApplySettings(vcl::RenderContext& rRenderContext)
-{
-    const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
-    rRenderContext.SetBackground(rStyleSettings.GetWindowColor());
-}
-
-void SmEditWindow::DataChanged( const DataChangedEvent& rDCEvt )
+void SmEditTextWindow::StyleUpdated()
 {
-    InterimItemWindow::DataChanged( rDCEvt );
-
-    if (!((rDCEvt.GetType() == DataChangedEventType::FONTS) ||
-          (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
-          ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
-           (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))))
-        return;
-
+    WeldEditView::StyleUpdated();
     EditEngine *pEditEngine = GetEditEngine();
-    SmDocShell *pDoc = GetDoc();
+    SmDocShell *pDoc = mrEditWindow.GetDoc();
 
     if (pEditEngine && pDoc)
     {
         //!
         //! see also SmDocShell::GetEditEngine() !
         //!
-        const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
+        const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
 
         pDoc->UpdateEditEngineDefaultFonts(rStyleSettings.GetFieldTextColor());
         pEditEngine->SetBackgroundColor(rStyleSettings.GetFieldColor());
@@ -230,7 +201,7 @@ void SmEditWindow::DataChanged( const DataChangedEvent& rDCEvt )
         pEditEngine->Clear();   //incorrect font size
         pEditEngine->SetText( aTxt );
 
-        mxTextControl->Resize();
+        Resize();
     }
 }
 
@@ -274,21 +245,6 @@ bool SmEditTextWindow::MouseButtonUp(const MouseEvent &rEvt)
     return bRet;
 }
 
-void SmEditWindow::Command(const CommandEvent& rCEvt)
-{
-    if (rCEvt.GetCommand() == CommandEventId::ContextMenu)
-    {
-        GetParent()->ToTop();
-        Point aPoint = rCEvt.GetMousePosPixel();
-        SmViewShell *pViewSh = GetView();
-        if (pViewSh)
-            pViewSh->GetViewFrame()->GetDispatcher()->ExecutePopup("edit", this, &aPoint);
-        return;
-    }
-
-    InterimItemWindow::Command(rCEvt);
-}
-
 bool SmEditTextWindow::Command(const CommandEvent& rCEvt)
 {
     // no zooming in Command window
@@ -305,7 +261,8 @@ bool SmEditTextWindow::Command(const CommandEvent& rCEvt)
         // purely for "ExecutePopup" taking a vcl::Window and
         // we assume SmEditTextWindow 0,0 is at SmEditWindow 0,0
         ReleaseMouse();
-        mrEditWindow.Command(rCEvt);
+        mrEditWindow.GetCmdBox().Command(rCEvt);
+        GrabFocus();
         return true;
     }
 
@@ -437,7 +394,7 @@ void SmEditTextWindow::UserPossiblyChangedText()
     aModifyIdle.Start();
 }
 
-void SmEditWindow::CreateEditView()
+void SmEditWindow::CreateEditView(weld::Builder& rBuilder)
 {
     assert(!mxTextControl);
 
@@ -448,8 +405,7 @@ void SmEditWindow::CreateEditView()
         return;
 
     mxTextControl.reset(new SmEditTextWindow(*this));
-    mxTextControlWin.reset(new weld::CustomWeld(*m_xBuilder, "editview", *mxTextControl));
-    InitControlBase(mxTextControl->GetDrawingArea());
+    mxTextControlWin.reset(new weld::CustomWeld(rBuilder, "editview", *mxTextControl));
 
     SetScrollBarRanges();
 }
@@ -473,7 +429,7 @@ IMPL_LINK(SmEditWindow, ScrollHdl, weld::ScrolledWindow&, rScrolledWindow, void)
 
 tools::Rectangle SmEditWindow::AdjustScrollBars()
 {
-    tools::Rectangle aRect(Point(), GetOutputSizePixel());
+    tools::Rectangle aRect(Point(), rCmdBox.GetOutputSizePixel());
 
     if (mxScrolledWindow)
     {
@@ -535,6 +491,20 @@ void SmEditWindow::SetText(const OUString& rText)
     mxTextControl->SetText(rText);
 }
 
+void SmEditWindow::Flush()
+{
+    if (!mxTextControl)
+        return;
+    mxTextControl->Flush();
+}
+
+void SmEditWindow::GrabFocus()
+{
+    if (!mxTextControl)
+        return;
+    mxTextControl->GrabFocus();
+}
+
 void SmEditTextWindow::SetText(const OUString& rText)
 {
     EditEngine *pEditEngine = GetEditEngine();
@@ -860,7 +830,6 @@ void SmEditWindow::DeleteEditView()
             pEditEngine->SetStatusEventHdl( Link<EditStatus&,void>() );
             pEditEngine->RemoveView(pEditView);
         }
-        InitControlBase(nullptr);
         mxTextControlWin.reset();
         mxTextControl.reset();
     }
diff --git a/starmath/source/view.cxx b/starmath/source/view.cxx
index 7a1a8e91465e..59ab4bcfc3b8 100644
--- a/starmath/source/view.cxx
+++ b/starmath/source/view.cxx
@@ -54,7 +54,6 @@
 #include <sfx2/zoomitem.hxx>
 #include <vcl/commandevent.hxx>
 #include <vcl/event.hxx>
-#include <vcl/decoview.hxx>
 #include <vcl/settings.hxx>
 #include <vcl/virdev.hxx>
 #include <sal/log.hxx>
@@ -82,8 +81,8 @@
 // space around the edit window, in pixels
 // fdo#69111: Increased border on the top so that the window is
 // easier to tear off.
-#define CMD_BOX_PADDING 4
-#define CMD_BOX_PADDING_TOP 10
+#define CMD_BOX_PADDING 3
+#define CMD_BOX_PADDING_TOP 11
 
 #define ShellClass_SmViewShell
 #include <smslots.hxx>
@@ -810,12 +809,14 @@ void SmEditController::StateChanged(sal_uInt16 nSID, SfxItemState eState, const
 
 /**************************************************************************/
 SmCmdBoxWindow::SmCmdBoxWindow(SfxBindings *pBindings_, SfxChildWindow *pChildWindow,
-                               vcl::Window *pParent) :
-    SfxDockingWindow(pBindings_, pChildWindow, pParent, WB_MOVEABLE|WB_CLOSEABLE|WB_SIZEABLE|WB_DOCKABLE),
-    aEdit       (VclPtr<SmEditWindow>::Create(*this)),
-    aController (*aEdit, SID_TEXT, *pBindings_),
-    bExiting    (false)
+                               vcl::Window *pParent)
+    : SfxDockingWindow(pBindings_, pChildWindow, pParent, "EditWindow", "modules/smath/ui/editwindow.ui")
+    , m_xEdit(std::make_unique<SmEditWindow>(*this, *m_xBuilder))
+    , aController(*m_xEdit, SID_TEXT, *pBindings_)
+    , bExiting(false)
 {
+    set_id("math_edit");
+
     SetHelpId( HID_SMA_COMMAND_WIN );
     SetSizePixel(LogicToPixel(Size(292 , 94), MapMode(MapUnit::MapAppFont)));
     SetText(SmResId(STR_CMDBOXWINDOW));
@@ -826,6 +827,21 @@ SmCmdBoxWindow::SmCmdBoxWindow(SfxBindings *pBindings_, SfxChildWindow *pChildWi
     aInitialFocusTimer.SetTimeout(100);
 }
 
+void SmCmdBoxWindow::Command(const CommandEvent& rCEvt)
+{
+    if (rCEvt.GetCommand() == CommandEventId::ContextMenu)
+    {
+        ToTop();
+        Point aPoint = rCEvt.GetMousePosPixel();
+        SmViewShell *pViewSh = GetView();
+        if (pViewSh)
+            pViewSh->GetViewFrame()->GetDispatcher()->ExecutePopup("edit", this, &aPoint);
+        return;
+    }
+
+    SfxDockingWindow::Command(rCEvt);
+}
+
 SmCmdBoxWindow::~SmCmdBoxWindow ()
 {
     disposeOnce();
@@ -836,7 +852,7 @@ void SmCmdBoxWindow::dispose()
     aInitialFocusTimer.Stop();
     bExiting = true;
     aController.dispose();
-    aEdit.disposeAndClear();
+    m_xEdit.reset();
     SfxDockingWindow::dispose();
 }
 
@@ -847,36 +863,6 @@ SmViewShell * SmCmdBoxWindow::GetView()
     return  dynamic_cast<SmViewShell*>( pView);
 }
 
-void SmCmdBoxWindow::Resize()
-{
-    tools::Rectangle aRect(Point(0, 0), GetOutputSizePixel());
-    aRect.AdjustLeft(CMD_BOX_PADDING );
-    aRect.AdjustTop(CMD_BOX_PADDING_TOP );
-    aRect.AdjustRight( -(CMD_BOX_PADDING) );
-    aRect.AdjustBottom( -(CMD_BOX_PADDING) );
-
-    DecorationView aView(this);
-    aRect = aView.DrawFrame(aRect, DrawFrameStyle::In, DrawFrameFlags::NoDraw);
-
-    aEdit->SetPosSizePixel(aRect.TopLeft(), aRect.GetSize());
-    SfxDockingWindow::Resize();
-    Invalidate();
-}
-
-void SmCmdBoxWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
-{
-    tools::Rectangle aRect(Point(0, 0), GetOutputSizePixel());
-    aRect.AdjustLeft(CMD_BOX_PADDING );
-    aRect.AdjustTop(CMD_BOX_PADDING_TOP );
-    aRect.AdjustRight( -(CMD_BOX_PADDING) );
-    aRect.AdjustBottom( -(CMD_BOX_PADDING) );
-
-    aEdit->SetPosSizePixel(aRect.TopLeft(), aRect.GetSize());
-
-    DecorationView aView(&rRenderContext);
-    aView.DrawFrame( aRect, DrawFrameStyle::In );
-}
-
 Size SmCmdBoxWindow::CalcDockingSize(SfxChildAlignment eAlign)
 {
     switch (eAlign)
@@ -938,7 +924,7 @@ IMPL_LINK_NOARG( SmCmdBoxWindow, InitialFocusTimerHdl, Timer *, void )
     {
         uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create( comphelper::getProcessComponentContext() );
 
-        aEdit->GrabFocus();
+        m_xEdit->GrabFocus();
 
         SmViewShell* pView = GetView();
         assert(pView);
@@ -988,7 +974,7 @@ void SmCmdBoxWindow::ToggleFloatingMode()
 void SmCmdBoxWindow::GetFocus()
 {
     if (!bExiting)
-        aEdit->GrabFocus();
+        m_xEdit->GrabFocus();
 }
 
 SFX_IMPL_DOCKINGWINDOW_WITHID(SmCmdBoxWrapper, SID_CMDBOXWINDOW);
@@ -998,11 +984,14 @@ SmCmdBoxWrapper::SmCmdBoxWrapper(vcl::Window *pParentWindow, sal_uInt16 nId,
                                  SfxChildWinInfo *pInfo) :
     SfxChildWindow(pParentWindow, nId)
 {
-    SetWindow(VclPtr<SmCmdBoxWindow>::Create(pBindings, this, pParentWindow));
-
+    VclPtrInstance<SmCmdBoxWindow> pDialog(pBindings, this, pParentWindow);
+    SetWindow(pDialog);
     // make window docked to the bottom initially (after first start)
     SetAlignment(SfxChildAlignment::BOTTOM);
-    static_cast<SfxDockingWindow *>(GetWindow())->Initialize(pInfo);
+    pDialog->setDeferredProperties();
+    pDialog->set_border_width(CMD_BOX_PADDING);
+    pDialog->set_margin_top(CMD_BOX_PADDING_TOP);
+    pDialog->Initialize(pInfo);
 }
 
 SFX_IMPL_SUPERCLASS_INTERFACE(SmViewShell, SfxViewShell)
@@ -1597,15 +1586,19 @@ void SmViewShell::Execute(SfxRequest& rReq)
             if( xTrans.is() )
             {
                 auto pTrans = comphelper::getUnoTunnelImplementation<TransferableHelper>(xTrans);
-                if( pTrans )
-                    pTrans->CopyToClipboard(GetEditWindow());
+                if (pTrans)
+                {
+                    SmEditWindow *pEditWin = GetEditWindow();
+                    pTrans->CopyToClipboard(pEditWin->GetClipboard());
+                }
             }
         }
         break;
 
         case SID_PASTEOBJECT:
         {
-            TransferableDataHelper aData( TransferableDataHelper::CreateFromSystemClipboard(GetEditWindow()) );
+            SmEditWindow *pEditWin = GetEditWindow();
+            TransferableDataHelper aData(TransferableDataHelper::CreateFromClipboard(pEditWin->GetClipboard()));
             uno::Reference < io::XInputStream > xStrm;
             SotClipboardFormatId nId;
             if( aData.GetTransferable().is() &&
@@ -1657,9 +1650,10 @@ void SmViewShell::Execute(SfxRequest& rReq)
                 bool bCallExec = nullptr == pWin;
                 if( !bCallExec )
                 {
+                    SmEditWindow *pEditWin = GetEditWindow();
                     TransferableDataHelper aDataHelper(
-                        TransferableDataHelper::CreateFromSystemClipboard(
-                                                    GetEditWindow()) );
+                        TransferableDataHelper::CreateFromClipboard(
+                                                    pEditWin->GetClipboard()));
 
                     if( aDataHelper.GetTransferable().is() &&
                         aDataHelper.HasFormat( SotClipboardFormatId::STRING ))
@@ -1726,7 +1720,8 @@ void SmViewShell::Execute(SfxRequest& rReq)
 
         case SID_IMPORT_MATHML_CLIPBOARD:
         {
-            TransferableDataHelper aDataHelper( TransferableDataHelper::CreateFromSystemClipboard(GetEditWindow()) );
+            SmEditWindow *pEditWin = GetEditWindow();
+            TransferableDataHelper aDataHelper(TransferableDataHelper::CreateFromClipboard(pEditWin->GetClipboard()));
             uno::Reference < io::XInputStream > xStrm;
             if  ( aDataHelper.GetTransferable().is() )
             {
@@ -1976,8 +1971,8 @@ void SmViewShell::GetState(SfxItemSet &rSet)
             if (pEditWin)
             {
                 TransferableDataHelper aDataHelper(
-                        TransferableDataHelper::CreateFromSystemClipboard(
-                                                        pEditWin) );
+                        TransferableDataHelper::CreateFromClipboard(
+                                                        pEditWin->GetClipboard()) );
 
                 mbPasteState = aDataHelper.GetTransferable().is() &&
                  ( aDataHelper.HasFormat( SotClipboardFormatId::STRING ) ||


More information about the Libreoffice-commits mailing list