sw/inc/view.hxx                        |    4 ++
 sw/qa/uibase/uiview/data/tdf146549.odt |binary
 sw/qa/uibase/uiview/uiview.cxx         |   49 +++++++++++++++++++++++++++++++++
 sw/source/uibase/uiview/view.cxx       |   24 ++++++++++++++--
 4 files changed, 73 insertions(+), 4 deletions(-)

New commits:
commit 5f81c84e9b5d4bc9eb5ba05aa1aad5eeaa4eb89a
Author:     Tibor Nagy <[email protected]>
AuthorDate: Wed Jan 29 11:46:56 2025 +0100
Commit:     Thorsten Behrens <[email protected]>
CommitDate: Fri Jan 31 13:38:39 2025 +0100

    tdf#146549 sw: Make the formatting toolbar visible
    
    when moving the cursor to an editable section in read-only mode.
    
    Change-Id: I7ed5837eb627a3db00b1b64516b790cc7a3aea01
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180890
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <[email protected]>

diff --git a/sw/inc/view.hxx b/sw/inc/view.hxx
index 47e6bc6bf8a4..a958e08bb3c9 100644
--- a/sw/inc/view.hxx
+++ b/sw/inc/view.hxx
@@ -692,8 +692,10 @@ public:
     void NotifyCursor(SfxViewShell* pViewShell) const override;
     /// See SfxViewShell::GetColorConfigColor().
     ::Color GetColorConfigColor(svtools::ColorConfigEntry nColorType) const 
override;
-    void ShowUIElement(const OUString& sElementURL) const;
 
+    void SetUIElementVisibility(const OUString& sElementURL, bool bShow) const;
+    void ShowUIElement(const OUString& sElementURL) const;
+    void HideUIElement(const OUString& sElementURL) const;
 
     enum CachedStringID
     {
diff --git a/sw/qa/uibase/uiview/data/tdf146549.odt 
b/sw/qa/uibase/uiview/data/tdf146549.odt
new file mode 100644
index 000000000000..1f67a15bea1e
Binary files /dev/null and b/sw/qa/uibase/uiview/data/tdf146549.odt differ
diff --git a/sw/qa/uibase/uiview/uiview.cxx b/sw/qa/uibase/uiview/uiview.cxx
index 5f41aa920c02..3733fcd5dc68 100644
--- a/sw/qa/uibase/uiview/uiview.cxx
+++ b/sw/qa/uibase/uiview/uiview.cxx
@@ -17,6 +17,7 @@
 #include <sfx2/viewfrm.hxx>
 #include <sfx2/dispatch.hxx>
 
+#include <com/sun/star/frame/XLayoutManager.hpp>
 #include <com/sun/star/frame/XDispatchHelper.hpp>
 #include <com/sun/star/frame/XDispatchProvider.hpp>
 #include <com/sun/star/frame/XComponentLoader.hpp>
@@ -354,6 +355,54 @@ CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, 
testEditInReadonly)
     //status default in editable section
     CPPUNIT_ASSERT_EQUAL(SfxItemState::DEFAULT, eState);
 }
+
+CPPUNIT_TEST_FIXTURE(SwUibaseUiviewTest, testShowTextobjectbarInReadonly)
+{
+    createSwDoc("tdf146549.odt");
+
+    SwDocShell* pDocShell = getSwDocShell();
+    SwView* pView = pDocShell->GetView();
+
+    pView->GetViewFrame().GetDispatcher()->Execute(SID_EDITDOC, 
SfxCallMode::SYNCHRON);
+
+    uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY);
+    uno::Reference<text::XTextDocument> xTextDocument(mxComponent, 
uno::UNO_QUERY);
+    uno::Reference<text::XParagraphCursor> 
xParaCursor(xTextDocument->getText()->createTextCursor(),
+                                                       uno::UNO_QUERY);
+
+    uno::Reference<view::XSelectionSupplier> 
xSelSupplier(xModel->getCurrentController(),
+                                                          
uno::UNO_QUERY_THROW);
+
+    SwWrtShell* pWrtShell = getSwDocShell()->GetWrtShell();
+    CPPUNIT_ASSERT(pWrtShell);
+
+    SfxViewFrame& rViewFrame = pWrtShell->GetView().GetViewFrame();
+    uno::Reference<com::sun::star::frame::XLayoutManager> xLayoutManager;
+    uno::Reference<beans::XPropertySet> 
xPropSet(rViewFrame.GetFrame().GetFrameInterface(),
+                                                 uno::UNO_QUERY);
+    xLayoutManager.set(xPropSet->getPropertyValue(u"LayoutManager"_ustr), 
uno::UNO_QUERY);
+
+    // move the cursor to the non-editable section
+    xSelSupplier->select(css::uno::Any(xParaCursor));
+
+    bool bShow;
+    bShow = 
xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
+    CPPUNIT_ASSERT_EQUAL(false, bShow); // the formatting toolbar should be 
hidden
+
+    // move the cursor to the editable section
+    xParaCursor->gotoNextParagraph(false);
+    xSelSupplier->select(css::uno::Any(xParaCursor));
+
+    bShow = 
xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
+    CPPUNIT_ASSERT_EQUAL(true, bShow); // the formatting toolbar should be 
shown
+
+    // move the cursor to the non-editable section
+    xParaCursor->gotoPreviousParagraph(false);
+    xSelSupplier->select(css::uno::Any(xParaCursor));
+
+    bShow = 
xLayoutManager->isElementVisible(u"private:resource/toolbar/drawtextobjectbar"_ustr);
+    CPPUNIT_ASSERT_EQUAL(false, bShow); // the formatting toolbar should be 
hidden
+}
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/uibase/uiview/view.cxx b/sw/source/uibase/uiview/view.cxx
index ac755dd4fc45..c4fbbd4afac4 100644
--- a/sw/source/uibase/uiview/view.cxx
+++ b/sw/source/uibase/uiview/view.cxx
@@ -253,18 +253,30 @@ uno::Reference<frame::XLayoutManager> 
getLayoutManager(const SfxViewFrame& rView
 }
 }
 
-void SwView::ShowUIElement(const OUString& sElementURL) const
+void SwView::SetUIElementVisibility(const OUString& sElementURL, bool bShow) 
const
 {
     if (auto xLayoutManager = getLayoutManager(GetViewFrame()))
     {
         if (!xLayoutManager->getElement(sElementURL).is())
-        {
             xLayoutManager->createElement(sElementURL);
+
+        if (bShow)
             xLayoutManager->showElement(sElementURL);
-        }
+        else
+            xLayoutManager->hideElement(sElementURL);
     }
 }
 
+void SwView::ShowUIElement(const OUString& sElementURL) const
+{
+    SetUIElementVisibility(sElementURL, true);
+}
+
+void SwView::HideUIElement(const OUString& sElementURL) const
+{
+    SetUIElementVisibility(sElementURL, false);
+}
+
 void SwView::SelectShell()
 {
     // Attention: Maintain the SelectShell for the WebView additionally
@@ -681,6 +693,9 @@ void SwView::CheckReadonlyState()
         }
         if ( SfxItemState::DISABLED == eStateRO )
         {
+            if (m_pWrtShell->GetViewOptions()->IsReadonly())
+                
ShowUIElement(u"private:resource/toolbar/drawtextobjectbar"_ustr);
+
             rDis.SetSlotFilter( SfxSlotFilterState::ENABLED_READONLY, aROIds );
             bChgd = true;
         }
@@ -703,6 +718,9 @@ void SwView::CheckReadonlyState()
     else if ( SfxItemState::DISABLED != eStateRO ||
                 SfxItemState::DISABLED != eStateProtAll )
     {
+        if (m_pWrtShell->GetViewOptions()->IsReadonly())
+            HideUIElement(u"private:resource/toolbar/drawtextobjectbar"_ustr);
+
         bChgd = true;
         rDis.SetSlotFilter();
     }

Reply via email to