[Libreoffice-commits] core.git: sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Jan 4 00:01:37 UTC 2019


 sw/source/core/frmedt/fefly1.cxx   |    3 +
 sw/source/core/frmedt/feshview.cxx |   11 ++++
 sw/source/core/inc/flyfrm.hxx      |    9 +++
 sw/source/core/layout/fly.cxx      |   96 +++++++++++++++++++++++++++++++++++++
 sw/source/core/layout/paintfrm.cxx |   12 ++++
 5 files changed, 131 insertions(+)

New commits:
commit 6e5c4001c7b5cab2b2cc6419072acbe5fa7cb04a
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Wed Jan 2 17:57:22 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Fri Jan 4 01:01:13 2019 +0100

    Unfloat: Handle unfloat button visibility
    
    We need to update the state of the button every time
    when the frame's layout changes or when the selection
    changes.
    Show the button if the text frame is selected and it's
    a floating table which would hang out of the actual page
    after unfloating.
    
    Change-Id: I6b64affb063f552921915a0735e80889e5fd8124
    Reviewed-on: https://gerrit.libreoffice.org/65819
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/sw/source/core/frmedt/fefly1.cxx b/sw/source/core/frmedt/fefly1.cxx
index 2af6a32efbce..9f9f12bec56a 100644
--- a/sw/source/core/frmedt/fefly1.cxx
+++ b/sw/source/core/frmedt/fefly1.cxx
@@ -266,6 +266,9 @@ void SwFEShell::SelectFlyFrame( SwFlyFrame& rFrame )
 
         pImpl->GetDrawView()->MarkObj( rFrame.GetVirtDrawObj(),
                                       pImpl->GetPageView() );
+
+        rFrame.SelectionHasChanged(this);
+
         KillPams();
         ClearMark();
         SelFlyGrabCursor();
diff --git a/sw/source/core/frmedt/feshview.cxx b/sw/source/core/frmedt/feshview.cxx
index 57e61b18aee1..81631f659f96 100644
--- a/sw/source/core/frmedt/feshview.cxx
+++ b/sw/source/core/frmedt/feshview.cxx
@@ -235,7 +235,11 @@ bool SwFEShell::SelectObj( const Point& rPt, sal_uInt8 nFlag, SdrObject *pObj )
             }
         }
         if ( bUnmark )
+        {
             pDView->UnmarkAll();
+            if (pOldSelFly)
+                pOldSelFly->SelectionHasChanged(this);
+        }
     }
     else
     {
@@ -275,6 +279,13 @@ bool SwFEShell::SelectObj( const Point& rPt, sal_uInt8 nFlag, SdrObject *pObj )
         }
     }
 
+    if ( rMrkList.GetMarkCount() == 1 )
+    {
+        SwFlyFrame *pSelFly = ::GetFlyFromMarked( &rMrkList, this );
+        if (pSelFly)
+            pSelFly->SelectionHasChanged(this);
+    }
+
     if (!(nFlag & SW_ALLOW_TEXTBOX))
     {
         // If the fly frame is a textbox of a shape, then select the shape instead.
diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx
old mode 100644
new mode 100755
index c28dcd98b882..6501ab592510
--- a/sw/source/core/inc/flyfrm.hxx
+++ b/sw/source/core/inc/flyfrm.hxx
@@ -37,6 +37,8 @@ namespace tools { class PolyPolygon; }
 class SwFlyDrawContact;
 class SwFormat;
 class SwViewShell;
+class SwFEShell;
+class SwWrtShell;
 
 
 /** search an anchor for paragraph bound frames starting from pOldAnch
@@ -267,6 +269,13 @@ public:
     Point& ContentPos() { return m_aContentPos; }
 
     void InvalidateContentPos();
+
+    void SelectionHasChanged(SwFEShell* pShell);
+
+private:
+    bool IsShowUnfloatButton(SwWrtShell* pWrtSh) const;
+    void UpdateUnfloatButton(SwWrtShell* pWrtSh, bool bShow) const;
+    void PaintDecorators() const;
 };
 #endif
 
diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx
old mode 100644
new mode 100755
index c4b2732b4413..5cf16541ee9b
--- a/sw/source/core/layout/fly.cxx
+++ b/sw/source/core/layout/fly.cxx
@@ -68,6 +68,12 @@
 #include <basegfx/polygon/b2dpolygontools.hxx>
 #include <basegfx/matrix/b2dhommatrixtools.hxx>
 
+#include <wrtsh.hxx>
+#include <view.hxx>
+#include <edtwin.hxx>
+#include <bodyfrm.hxx>
+#include <FrameControlsManager.hxx>
+
 using namespace ::com::sun::star;
 
 static SwTwips lcl_CalcAutoWidth( const SwLayoutFrame& rFrame );
@@ -279,6 +285,9 @@ void SwFlyFrame::DestroyImpl()
     FinitDrawObj();
 
     SwLayoutFrame::DestroyImpl();
+
+    SwWrtShell* pWrtSh = dynamic_cast<SwWrtShell*>(getRootFrame()->GetCurrShell());
+    UpdateUnfloatButton(pWrtSh, false);
 }
 
 SwFlyFrame::~SwFlyFrame()
@@ -1764,6 +1773,93 @@ void SwFlyFrame::InvalidateContentPos()
     Invalidate_();
 }
 
+void SwFlyFrame::SelectionHasChanged(SwFEShell* pShell)
+{
+    SwWrtShell* pWrtSh = dynamic_cast< SwWrtShell* >(pShell);
+    if (pWrtSh == nullptr)
+        return;
+
+    UpdateUnfloatButton(pWrtSh, IsShowUnfloatButton(pWrtSh));
+}
+
+bool SwFlyFrame::IsShowUnfloatButton(SwWrtShell* pWrtSh) const
+{
+    if (pWrtSh == nullptr)
+        return false;
+
+    // In read only mode we don't allow unfloat operation
+    if (pWrtSh->GetViewOptions()->IsReadonly())
+        return false;
+
+    const SdrObject *pObj = GetFrameFormat().FindRealSdrObject();
+    if (pObj == nullptr)
+        return false;
+
+    // SwFlyFrame itself can mean images, ole objects, etc, but we interested in actual text frames
+    if (SwFEShell::GetObjCntType(*pObj) != OBJCNT_FLY)
+        return false;
+
+    // We show the button only for the selected text frame
+    SwDrawView *pView = pWrtSh->Imp()->GetDrawView();
+    if (pView == nullptr)
+        return false;
+
+    // Fly frame can be selected only alone
+    if (pView->GetMarkedObjectList().GetMarkCount() != 1)
+        return false;
+
+    if(!pView->IsObjMarked(pObj))
+        return false;
+
+    // A frame is a floating table if there is only one table (and maybe some whitespaces) inside it
+    int nTableCount = 0;
+    const SwFrame* pLower = GetLower();
+    const SwTabFrame* pTable = nullptr;
+    while (pLower)
+    {
+        if (pLower->IsTabFrame())
+        {
+            pTable = static_cast<const SwTabFrame*>(pLower);
+            ++nTableCount;
+            if (nTableCount > 1 || pTable == nullptr)
+                return false;
+        }
+
+        if (pLower->IsTextFrame())
+        {
+            const SwTextFrame* pTextFrame = static_cast<const SwTextFrame*>(pLower);
+            if (!pTextFrame->GetText().trim().isEmpty())
+                return false;
+        }
+        pLower = pLower->GetNext();
+    }
+
+    if (nTableCount != 1 || pTable == nullptr)
+        return false;
+
+    // Show the unfold button only for multipage tables
+    const SwBodyFrame *pBody = GetAnchorFrame()->FindBodyFrame();
+    if (pBody == nullptr)
+        return false;
+
+    long nBodyHeight = pBody->getFrameArea().Height();
+    long nTableHeight = pTable->getFrameArea().Height();
+    long nFrameOffset = std::abs(GetAnchorFrame()->getFrameArea().Top() - pBody->getFrameArea().Top());
+
+    return nBodyHeight < nTableHeight + nFrameOffset;
+}
+
+void SwFlyFrame::UpdateUnfloatButton(SwWrtShell* pWrtSh, bool bShow) const
+{
+    if (pWrtSh == nullptr)
+        return;
+
+    SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin();
+    SwFrameControlsManager& rMngr = rEditWin.GetFrameControlsManager();
+    Point aBottomRightPixel = rEditWin.LogicToPixel( getFrameArea().BottomRight() );
+    rMngr.SetFloatingTableButton(this, bShow,  aBottomRightPixel);
+}
+
 SwTwips SwFlyFrame::Grow_( SwTwips nDist, bool bTst )
 {
     SwRectFnSet aRectFnSet(this);
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
old mode 100644
new mode 100755
index b3c1c8b0cc63..815497059439
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -4088,12 +4088,24 @@ void SwFlyFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const&
     // have to paint frame borders added in heaven layer here...
     ProcessPrimitives(gProp.pBLines->GetBorderLines_Clear());
 
+    PaintDecorators();
+
     rRenderContext.Pop();
 
     if ( gProp.pSProgress && pNoText )
         SfxProgress::Reschedule();
 }
 
+void SwFlyFrame::PaintDecorators() const
+{
+    // Show the un-float button
+    SwWrtShell* pWrtSh = dynamic_cast< SwWrtShell* >( gProp.pSGlobalShell );
+    if ( pWrtSh )
+    {
+        UpdateUnfloatButton(pWrtSh, IsShowUnfloatButton(pWrtSh));
+    }
+}
+
 void SwTabFrame::PaintSwFrame(vcl::RenderContext& rRenderContext, SwRect const& rRect, SwPrintData const*const) const
 {
     const SwViewOption* pViewOption = gProp.pSGlobalShell->GetViewOptions();


More information about the Libreoffice-commits mailing list