summaryrefslogtreecommitdiffstats
path: root/sw/source/uibase/docvw/FrameControlsManager.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sw/source/uibase/docvw/FrameControlsManager.cxx
parentInitial commit. (diff)
downloadlibreoffice-upstream.tar.xz
libreoffice-upstream.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sw/source/uibase/docvw/FrameControlsManager.cxx')
-rw-r--r--sw/source/uibase/docvw/FrameControlsManager.cxx269
1 files changed, 269 insertions, 0 deletions
diff --git a/sw/source/uibase/docvw/FrameControlsManager.cxx b/sw/source/uibase/docvw/FrameControlsManager.cxx
new file mode 100644
index 000000000..03252faa1
--- /dev/null
+++ b/sw/source/uibase/docvw/FrameControlsManager.cxx
@@ -0,0 +1,269 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include <edtwin.hxx>
+#include <cntfrm.hxx>
+#include <FrameControlsManager.hxx>
+#include <HeaderFooterWin.hxx>
+#include <PageBreakWin.hxx>
+#include <UnfloatTableButton.hxx>
+#include <pagefrm.hxx>
+#include <flyfrm.hxx>
+#include <viewopt.hxx>
+#include <view.hxx>
+#include <wrtsh.hxx>
+#include <OutlineContentVisibilityWin.hxx>
+#include <vcl/settings.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/weldutils.hxx>
+
+SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
+ m_pEditWin( pEditWin )
+{
+}
+
+SwFrameControlsManager::~SwFrameControlsManager()
+{
+}
+
+void SwFrameControlsManager::dispose()
+{
+ m_aControls.clear();
+}
+
+SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrame* pFrame )
+{
+ SwFrameControlPtrMap& rControls = m_aControls[eType];
+
+ SwFrameControlPtrMap::iterator aIt = rControls.find(pFrame);
+
+ if (aIt != rControls.end())
+ return aIt->second;
+
+ return SwFrameControlPtr();
+}
+
+void SwFrameControlsManager::RemoveControls( const SwFrame* pFrame )
+{
+ for ( auto& rEntry : m_aControls )
+ {
+ SwFrameControlPtrMap& rMap = rEntry.second;
+ rMap.erase(pFrame);
+ }
+}
+
+void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType, const SwFrame* pFrame )
+{
+ SwFrameControlPtrMap& rMap = m_aControls[eType];
+ rMap.erase(pFrame);
+}
+
+void SwFrameControlsManager::HideControls( FrameControlType eType )
+{
+ for ( const auto& rCtrl : m_aControls[eType] )
+ rCtrl.second->ShowAll( false );
+}
+
+void SwFrameControlsManager::SetReadonlyControls( bool bReadonly )
+{
+ for ( auto& rEntry : m_aControls )
+ for ( auto& rCtrl : rEntry.second )
+ rCtrl.second->SetReadonly( bReadonly );
+}
+
+void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrame* pPageFrame, FrameControlType eType, Point aOffset )
+{
+ assert( eType == FrameControlType::Header || eType == FrameControlType::Footer );
+
+ // Check if we already have the control
+ SwFrameControlPtr pControl;
+ const bool bHeader = ( eType == FrameControlType::Header );
+
+ SwFrameControlPtrMap& rControls = m_aControls[eType];
+
+ SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
+ if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
+ pControl = lb->second;
+ else
+ {
+ SwFrameControlPtr pNewControl =
+ std::make_shared<SwFrameControl>( VclPtr<SwHeaderFooterDashedLine>::Create(
+ m_pEditWin, pPageFrame, bHeader ).get() );
+ const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
+ pNewControl->SetReadonly( pViewOpt->IsReadonly() );
+ rControls.insert(lb, make_pair(pPageFrame, pNewControl));
+ pControl.swap( pNewControl );
+ }
+
+ tools::Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrame->getFrameArea().SVRect() );
+
+ SwHeaderFooterDashedLine* pWin = dynamic_cast<SwHeaderFooterDashedLine*>(pControl->GetWindow());
+ assert( pWin != nullptr) ;
+ assert( pWin->IsHeader() == bHeader );
+ pWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
+
+ if (!pWin->IsVisible())
+ pControl->ShowAll( true );
+}
+
+void SwFrameControlsManager::SetPageBreakControl( const SwPageFrame* pPageFrame )
+{
+ // Check if we already have the control
+ SwFrameControlPtr pControl;
+
+ SwFrameControlPtrMap& rControls = m_aControls[FrameControlType::PageBreak];
+
+ SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
+ if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
+ pControl = lb->second;
+ else
+ {
+ SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
+ VclPtr<SwBreakDashedLine>::Create( m_pEditWin, pPageFrame ).get() );
+ const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
+ pNewControl->SetReadonly( pViewOpt->IsReadonly() );
+
+ rControls.insert(lb, make_pair(pPageFrame, pNewControl));
+
+ pControl.swap( pNewControl );
+ }
+
+ SwBreakDashedLine* pWin = static_cast<SwBreakDashedLine*>(pControl->GetWindow());
+ assert (pWin != nullptr);
+ pWin->UpdatePosition();
+ if (!pWin->IsVisible())
+ pControl->ShowAll( true );
+}
+
+void SwFrameControlsManager::SetUnfloatTableButton( const SwFlyFrame* pFlyFrame, bool bShow, Point aTopRightPixel )
+{
+ if(pFlyFrame == nullptr)
+ return;
+
+ // Check if we already have the control
+ SwFrameControlPtr pControl;
+
+ SwFrameControlPtrMap& rControls = m_aControls[FrameControlType::FloatingTable];
+
+ SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pFlyFrame);
+ if (lb != rControls.end() && !(rControls.key_comp()(pFlyFrame, lb->first)))
+ pControl = lb->second;
+ else if (!bShow) // Do not create the control when it's not shown
+ return;
+ else
+ {
+ SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
+ VclPtr<UnfloatTableButton>::Create( m_pEditWin, pFlyFrame ).get() );
+ const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
+ pNewControl->SetReadonly( pViewOpt->IsReadonly() );
+
+ rControls.insert(lb, make_pair(pFlyFrame, pNewControl));
+
+ pControl.swap( pNewControl );
+ }
+
+ UnfloatTableButton* pButton = dynamic_cast<UnfloatTableButton*>(pControl->GetWindow());
+ assert(pButton != nullptr);
+ pButton->SetOffset(aTopRightPixel);
+ pControl->ShowAll( bShow );
+}
+
+SwFrameMenuButtonBase::SwFrameMenuButtonBase(SwEditWin* pEditWin, const SwFrame* pFrame,
+ const OUString& rUIXMLDescription, const OString& rID)
+ : InterimItemWindow(pEditWin, rUIXMLDescription, rID)
+ , m_pEditWin(pEditWin)
+ , m_pFrame(pFrame)
+{
+}
+
+void SwFrameControlsManager::SetOutlineContentVisibilityButton(const SwContentFrame* pContentFrame)
+{
+ // Check if we already have the control
+ SwFrameControlPtr pControl;
+
+ SwFrameControlPtrMap& rControls = m_aControls[FrameControlType::Outline];
+
+ SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pContentFrame);
+ if (lb != rControls.end() && !(rControls.key_comp()(pContentFrame, lb->first)))
+ {
+ pControl = lb->second;
+ }
+ else
+ {
+ SwFrameControlPtr pNewControl =
+ std::make_shared<SwFrameControl>(VclPtr<SwOutlineContentVisibilityWin>::Create(
+ m_pEditWin, pContentFrame).get());
+ rControls.insert(lb, make_pair(pContentFrame, pNewControl));
+ pControl.swap(pNewControl);
+ }
+
+ SwOutlineContentVisibilityWin* pWin = dynamic_cast<SwOutlineContentVisibilityWin *>(pControl->GetWindow());
+ assert(pWin != nullptr);
+ pWin->Set();
+
+ if (pWin->GetSymbol() == ButtonSymbol::SHOW)
+ pWin->Show(); // show the SHOW button immediately
+ else if (!pWin->IsVisible() && pWin->GetSymbol() == ButtonSymbol::HIDE)
+ pWin->ShowAll(true);
+}
+
+const SwPageFrame* SwFrameMenuButtonBase::GetPageFrame(const SwFrame* pFrame)
+{
+ if (pFrame->IsPageFrame())
+ return static_cast<const SwPageFrame*>(pFrame);
+
+ if (pFrame->IsFlyFrame())
+ return static_cast<const SwFlyFrame*>(pFrame)->GetAnchorFrame()->FindPageFrame();
+
+ return pFrame->FindPageFrame();
+}
+
+const SwPageFrame* SwFrameMenuButtonBase::GetPageFrame() const
+{
+ return SwFrameMenuButtonBase::GetPageFrame(m_pFrame);
+}
+
+void SwFrameMenuButtonBase::dispose()
+{
+ m_pEditWin.clear();
+ m_pFrame = nullptr;
+ m_xVirDev.disposeAndClear();
+ InterimItemWindow::dispose();
+}
+
+void SwFrameMenuButtonBase::SetVirDevFont(OutputDevice& rVirDev)
+{
+ // Get the font and configure it
+ vcl::Font aFont = Application::GetSettings().GetStyleSettings().GetToolFont();
+ weld::SetPointFont(rVirDev, aFont);
+}
+
+void SwFrameMenuButtonBase::SetVirDevFont()
+{
+ SetVirDevFont(*m_xVirDev);
+}
+
+SwFrameControl::SwFrameControl( const VclPtr<vcl::Window> &pWindow )
+{
+ assert(static_cast<bool>(pWindow));
+ mxWindow.reset( pWindow );
+ mpIFace = dynamic_cast<ISwFrameControl *>( pWindow.get() );
+}
+
+SwFrameControl::~SwFrameControl()
+{
+ mpIFace = nullptr;
+ mxWindow.disposeAndClear();
+}
+
+ISwFrameControl::~ISwFrameControl()
+{
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */