sd/source/ui/dlg/NotesChildWindow.cxx |   66 ++++++++++++++++++++++++++++++++++
 sd/source/ui/inc/NotesChildWindow.hxx |    4 ++
 2 files changed, 70 insertions(+)

New commits:
commit 9c131e19183fe3ae596b5f9947fc23311b4f66d5
Author:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
AuthorDate: Tue Apr 16 10:59:50 2024 +0200
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Tue Apr 16 12:03:01 2024 +0200

    related tdf#33603: improve clipboard/paste handling for noteseditwindow
    
    Similar to sd::View behavior, BeginPasteOrDropHdl &
    EndPasteOrDropHdl are used to format the pasted content.
    
    Specifically for the notes edit window, EndPasteOrDropHdl
    enforces the default Notes placeholder font size for pasted text.
    
    In general for better handling of key inputs - including paste,
    now NotesEditWindow uses the OutlinerView implementation of
    PostKeyEvent instead of EditView. Getting it behave more like
    sd::View.
    
    Change-Id: If0591db9c63e43bf702911fcca3e1981d851fd10
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166144
    Tested-by: allotropia jenkins <jenk...@allotropia.de>
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/sd/source/ui/dlg/NotesChildWindow.cxx 
b/sd/source/ui/dlg/NotesChildWindow.cxx
index 0ab856da55ef..436c4c5ff1bf 100644
--- a/sd/source/ui/dlg/NotesChildWindow.cxx
+++ b/sd/source/ui/dlg/NotesChildWindow.cxx
@@ -69,6 +69,9 @@ NotesChildDockingWindow::NotesChildDockingWindow(SfxBindings* 
_pBindings,
     mpOutliner = 
std::make_unique<Outliner>(&mpViewShellBase->GetDocShell()->GetPool(),
                                             OutlinerMode::TextObject);
 
+    mpOutliner->SetStyleSheetPool(
+        
static_cast<SfxStyleSheetPool*>(mpViewShellBase->GetDocShell()->GetStyleSheetPool()));
+
     mpOutlinerView = std::make_unique<OutlinerView>(mpOutliner.get(), nullptr);
     mpOutliner->InsertView(mpOutlinerView.get());
 
@@ -132,6 +135,51 @@ IMPL_LINK(NotesEditWindow, EventMultiplexerListener, 
tools::EventMultiplexerEven
     }
 }
 
+IMPL_LINK(NotesEditWindow, EndPasteOrDropHdl, PasteOrDropInfos*, pInfo, void)
+{
+    /* Style Sheet handling */
+    if (!mrParentWindow.GetOutliner() || !mpTextObj)
+        return;
+
+    SdPage* pPage = static_cast<SdPage*>(mpTextObj->getSdrPageFromSdrObject());
+    if (!pPage)
+        return;
+
+    SfxStyleSheet* pStyleSheet = 
pPage->GetStyleSheetForPresObj(PresObjKind::Notes);
+    if (!pStyleSheet)
+        return;
+
+    for (sal_Int32 nPara = pInfo->nStartPara; nPara <= pInfo->nEndPara; 
nPara++)
+    {
+        SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
+        mrParentWindow.GetOutliner()->SetStyleSheet(nPara, pStyleSheet);
+
+        // force the pasted paragraph font height to the notes placeholder 
default.
+        SfxItemSet aFontHeightSet(*rItemSet.GetPool(),
+                                  WhichRangesContainer(EE_CHAR_START, 
EE_CHAR_END));
+
+        for (auto& rWhich : { EE_CHAR_FONTHEIGHT, EE_CHAR_FONTHEIGHT_CJK, 
EE_CHAR_FONTHEIGHT_CTL })
+        {
+            if (auto pFontHeightItem = rItemSet.GetItemIfSet(rWhich))
+                aFontHeightSet.Put(*pFontHeightItem);
+        }
+
+        mrParentWindow.GetOutliner()->SetCharAttribs(nPara, aFontHeightSet);
+    }
+}
+
+IMPL_LINK(NotesEditWindow, BeginPasteOrDropHdl, PasteOrDropInfos*, pInfo, void)
+{
+    if (!mrParentWindow.GetOutliner() || !mpTextObj || 
!mpTextObj->getSdrPageFromSdrObject())
+        return;
+
+    // Turn character attributes of the paragraph of the insert position into
+    // character-level attributes, so they are not lost when OnEndPasteOrDrop()
+    // sets the paragraph stylesheet.
+    SfxItemSet 
aSet(mrParentWindow.GetOutliner()->GetParaAttribs(pInfo->nStartPara));
+    mrParentWindow.GetOutliner()->SetCharAttribs(pInfo->nStartPara, aSet);
+}
+
 void NotesEditWindow::SetDrawingArea(weld::DrawingArea* pDrawingArea)
 {
     Size aSize(pDrawingArea->get_size_request());
@@ -185,6 +233,11 @@ void NotesEditWindow::SetDrawingArea(weld::DrawingArea* 
pDrawingArea)
 
     provideNoteText();
 
+    mrParentWindow.GetOutliner()->SetEndPasteOrDropHdl(
+        LINK(this, NotesEditWindow, EndPasteOrDropHdl));
+    mrParentWindow.GetOutliner()->SetBeginPasteOrDropHdl(
+        LINK(this, NotesEditWindow, BeginPasteOrDropHdl));
+
     GetEditEngine()->SetStatusEventHdl(LINK(this, NotesEditWindow, 
EditStatusHdl));
 }
 
@@ -599,6 +652,19 @@ void NotesEditWindow::Notify(SfxBroadcaster&, const 
SfxHint& rHint)
     }
 }
 
+bool NotesEditWindow::KeyInput(const KeyEvent& rKEvt)
+{
+    bool bDone = false;
+
+    if (::OutlinerView* pOutlinerView = mrParentWindow.GetOutlinerView())
+        bDone = pOutlinerView->PostKeyEvent(rKEvt);
+
+    if (!bDone)
+        bDone = WeldEditView::KeyInput(rKEvt);
+
+    return bDone;
+}
+
 IMPL_LINK_NOARG(NotesEditWindow, EditStatusHdl, EditStatus&, void) { Resize(); 
}
 
 IMPL_LINK_NOARG(NotesEditWindow, EditModifiedHdl, LinkParamNone*, void)
diff --git a/sd/source/ui/inc/NotesChildWindow.hxx 
b/sd/source/ui/inc/NotesChildWindow.hxx
index 5242595bcb24..c94e35c20a2e 100644
--- a/sd/source/ui/inc/NotesChildWindow.hxx
+++ b/sd/source/ui/inc/NotesChildWindow.hxx
@@ -47,6 +47,9 @@ class NotesEditWindow : public WeldEditView, public 
SfxListener
     DECL_LINK(ModifyTimerHdl, Timer*, void);
     DECL_LINK(EventMultiplexerListener, tools::EventMultiplexerEvent&, void);
 
+    DECL_LINK(BeginPasteOrDropHdl, PasteOrDropInfos*, void);
+    DECL_LINK(EndPasteOrDropHdl, PasteOrDropInfos*, void);
+
     void removeListener();
     void addListener();
 
@@ -73,6 +76,7 @@ public:
     virtual void LoseFocus() override;
     virtual bool Command(const CommandEvent& rCEvt) override;
     virtual void Notify(SfxBroadcaster& rBC, const SfxHint& rHint) override;
+    virtual bool KeyInput(const KeyEvent& rKEvt) override;
 };
 
 class NotesChildDockingWindow final : public SfxDockingWindow

Reply via email to