sd/source/ui/inc/NotesPanelView.hxx       |    3 ++
 sd/source/ui/inc/NotesPanelViewShell.hxx  |    2 +
 sd/source/ui/inc/ViewShell.hxx            |   14 ++++++++++++
 sd/source/ui/view/NotesPanelView.cxx      |   34 ++++++++++++++++++++++++++++++
 sd/source/ui/view/NotesPanelViewShell.cxx |    4 +++
 sd/source/ui/view/sdwindow.cxx            |    2 +
 6 files changed, 59 insertions(+)

New commits:
commit efef507cfd480cc6f1efc964ac2f9e033e18ad87
Author:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
AuthorDate: Tue Apr 16 17:09:28 2024 +0200
Commit:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
CommitDate: Thu Apr 18 13:48:28 2024 +0200

    tdf#33603: make the notes pane handle placeholder text on focus
    
    Change-Id: Id2bca2b8a8bafa9da44a5f97a8e763b512078ef7
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166152
    Tested-by: Jenkins
    Reviewed-by: Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>

diff --git a/sd/source/ui/inc/NotesPanelView.hxx 
b/sd/source/ui/inc/NotesPanelView.hxx
index 810cddd6af71..9f2b71523c09 100644
--- a/sd/source/ui/inc/NotesPanelView.hxx
+++ b/sd/source/ui/inc/NotesPanelView.hxx
@@ -39,6 +39,7 @@ class NotesPanelView final : public ::sd::SimpleOutlinerView
 
     SdrTextObj* mpTextObj = nullptr;
     bool mbIgnoreNotifications = false;
+    bool mbInFocus = false;
 
     /** stores the last used document color.
         this is changed in onUpdateStyleSettings()
@@ -61,6 +62,8 @@ public:
 
     void Paint(const ::tools::Rectangle& rRect, ::sd::Window const* pWin);
     void onResize();
+    void onGrabFocus();
+    void onLoseFocus();
 
     OutlinerView* GetOutlinerView();
     OutlinerView* GetViewByWindow(vcl::Window const* pWin) const override;
diff --git a/sd/source/ui/inc/NotesPanelViewShell.hxx 
b/sd/source/ui/inc/NotesPanelViewShell.hxx
index e79ac899fe30..39901d6e4faa 100644
--- a/sd/source/ui/inc/NotesPanelViewShell.hxx
+++ b/sd/source/ui/inc/NotesPanelViewShell.hxx
@@ -49,6 +49,8 @@ public:
     virtual void Activate(bool IsMDIActivate) override;
     /** this method is called when the visible area of the view from this 
viewshell is changed */
     virtual void VisAreaChanged(const ::tools::Rectangle& rRect) override;
+    virtual void onGrabFocus() override;
+    virtual void onLoseFocus() override;
 
     virtual void ArrangeGUIElements() override;
     virtual SdPage* GetActualPage() override;
diff --git a/sd/source/ui/inc/ViewShell.hxx b/sd/source/ui/inc/ViewShell.hxx
index 85bc43e86c09..6ee126db9027 100644
--- a/sd/source/ui/inc/ViewShell.hxx
+++ b/sd/source/ui/inc/ViewShell.hxx
@@ -412,6 +412,20 @@ public:
         SdPage* pPage,
         const sal_Int32 nInsertPosition = -1);
 
+    /** Called by sd::Window::LoseFocus to enable sd::ViewShell to take action
+        when focus is lost.
+
+        e.g. overriden by NotesPanelViewShell
+     */
+    virtual void onLoseFocus(){};
+
+    /** Called by sd::Window::GrabFocus to enable sd::ViewShell to take action
+        when focus is grabbed.
+
+        e.g. overriden by NotesPanelViewShell
+     */
+    virtual void onGrabFocus(){};
+
     /// Allows adjusting the point or mark of the selection to a document 
coordinate.
     void SetCursorMm100Position(const Point& rPosition, bool bPoint, bool 
bClearMark);
     /// Gets the current selection
diff --git a/sd/source/ui/view/NotesPanelView.cxx 
b/sd/source/ui/view/NotesPanelView.cxx
index 2822a8df4c02..a2ae58e48331 100644
--- a/sd/source/ui/view/NotesPanelView.cxx
+++ b/sd/source/ui/view/NotesPanelView.cxx
@@ -224,6 +224,40 @@ void NotesPanelView::onResize()
     }
 }
 
+void NotesPanelView::onGrabFocus()
+{
+    if (mbInFocus)
+        return;
+    mbInFocus = true;
+
+    if (mpTextObj && mpTextObj->IsEmptyPresObj())
+    {
+        // clear the "Click to add Notes" text on entering the window.
+        maOutliner.SetToEmptyText();
+    }
+}
+
+void NotesPanelView::onLoseFocus()
+{
+    if (!mbInFocus)
+        return;
+    mbInFocus = false;
+
+    aModifyIdle.Stop();
+    if (mpTextObj)
+    {
+        if (maOutliner.GetEditEngine().GetText().getLength() == 0)
+        {
+            // if the notes are empty restore the placeholder text and state.
+            SdPage* pPage = 
dynamic_cast<SdPage*>(mpTextObj->getSdrPageFromSdrObject());
+            if (pPage)
+                pPage->RestoreDefaultText(mpTextObj);
+        }
+        else
+            setNotesToDoc();
+    }
+}
+
 /**
  * Handler for StatusEvents
  */
diff --git a/sd/source/ui/view/NotesPanelViewShell.cxx 
b/sd/source/ui/view/NotesPanelViewShell.cxx
index d4dd078dfc4d..82f3133dad75 100644
--- a/sd/source/ui/view/NotesPanelViewShell.cxx
+++ b/sd/source/ui/view/NotesPanelViewShell.cxx
@@ -233,6 +233,10 @@ void NotesPanelViewShell::VisAreaChanged(const 
::tools::Rectangle& rRect)
     GetViewShellBase().GetDrawController()->FireVisAreaChanged(rRect);
 }
 
+void NotesPanelViewShell::onGrabFocus() { mpNotesPanelView->onGrabFocus(); }
+
+void NotesPanelViewShell::onLoseFocus() { mpNotesPanelView->onLoseFocus(); }
+
 void NotesPanelViewShell::ArrangeGUIElements()
 {
     // Retrieve the current size (thickness) of the scroll bars.  That is
diff --git a/sd/source/ui/view/sdwindow.cxx b/sd/source/ui/view/sdwindow.cxx
index c684bee2caa8..d409aeec1304 100644
--- a/sd/source/ui/view/sdwindow.cxx
+++ b/sd/source/ui/view/sdwindow.cxx
@@ -742,6 +742,7 @@ void Window::LoseFocus()
 {
     mnTicks = 0;
     vcl::Window::LoseFocus ();
+    GetViewShell()->onLoseFocus();
 }
 
 /**
@@ -751,6 +752,7 @@ void Window::GrabFocus()
 {
     mnTicks      = 0;
     vcl::Window::GrabFocus ();
+    GetViewShell()->onGrabFocus();
 }
 
 void Window::DataChanged( const DataChangedEvent& rDCEvt )

Reply via email to