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.extern@allotropia.de>
diff --git a/sd/source/ui/inc/NotesPanelView.hxx b/sd/source/ui/inc/NotesPanelView.hxx
index 810cddd..9f2b715 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 e79ac89..39901d6 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 85bc43e..6ee126d 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 2822a8d..a2ae58e 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 d4dd078..82f3133 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 c684bee..d409aeec 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 )