From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- sdext/source/presenter/PresenterPaneBase.cxx | 351 +++++++++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 sdext/source/presenter/PresenterPaneBase.cxx (limited to 'sdext/source/presenter/PresenterPaneBase.cxx') diff --git a/sdext/source/presenter/PresenterPaneBase.cxx b/sdext/source/presenter/PresenterPaneBase.cxx new file mode 100644 index 000000000..29e7e4b04 --- /dev/null +++ b/sdext/source/presenter/PresenterPaneBase.cxx @@ -0,0 +1,351 @@ +/* -*- 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/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include "PresenterPaneBase.hxx" +#include "PresenterController.hxx" +#include "PresenterPaintManager.hxx" +#include +#include + +using namespace css; +using namespace css::uno; +using namespace css::drawing::framework; + +namespace sdext::presenter { + +//===== PresenterPaneBase ===================================================== + +PresenterPaneBase::PresenterPaneBase ( + const Reference& rxContext, + const ::rtl::Reference& rpPresenterController) + : PresenterPaneBaseInterfaceBase(m_aMutex), + mpPresenterController(rpPresenterController), + mxParentWindow(), + mxBorderWindow(), + mxBorderCanvas(), + mxContentWindow(), + mxContentCanvas(), + mxPaneId(), + mxBorderPainter(), + mxPresenterHelper(), + msTitle(), + mxComponentContext(rxContext) +{ + if (mpPresenterController.get() != nullptr) + mxPresenterHelper = mpPresenterController->GetPresenterHelper(); +} + +PresenterPaneBase::~PresenterPaneBase() +{ +} + +void PresenterPaneBase::disposing() +{ + if (mxBorderWindow.is()) + { + mxBorderWindow->removeWindowListener(this); + mxBorderWindow->removePaintListener(this); + } + + { + Reference xComponent (mxContentCanvas, UNO_QUERY); + mxContentCanvas = nullptr; + if (xComponent.is()) + xComponent->dispose(); + } + + { + Reference xComponent = mxContentWindow; + mxContentWindow = nullptr; + if (xComponent.is()) + xComponent->dispose(); + } + + { + Reference xComponent (mxBorderCanvas, UNO_QUERY); + mxBorderCanvas = nullptr; + if (xComponent.is()) + xComponent->dispose(); + } + + { + Reference xComponent = mxBorderWindow; + mxBorderWindow = nullptr; + if (xComponent.is()) + xComponent->dispose(); + } + + mxComponentContext = nullptr; +} + +void PresenterPaneBase::SetTitle (const OUString& rsTitle) +{ + msTitle = rsTitle; + + OSL_ASSERT(mpPresenterController.get()!=nullptr); + OSL_ASSERT(mpPresenterController->GetPaintManager() != nullptr); + + mpPresenterController->GetPaintManager()->Invalidate(mxBorderWindow); +} + +const OUString& PresenterPaneBase::GetTitle() const +{ + return msTitle; +} + +const Reference& + PresenterPaneBase::GetPaneBorderPainter() const +{ + return mxBorderPainter; +} + +//----- XInitialization ------------------------------------------------------- + +void SAL_CALL PresenterPaneBase::initialize (const Sequence& rArguments) +{ + ThrowIfDisposed(); + + if ( ! mxComponentContext.is()) + { + throw RuntimeException( + "PresenterSpritePane: missing component context", + static_cast(this)); + } + + if (rArguments.getLength() != 5 && rArguments.getLength() != 6) + { + throw RuntimeException( + "PresenterSpritePane: invalid number of arguments", + static_cast(this)); + } + + try + { + // Get the resource id from the first argument. + if ( ! (rArguments[0] >>= mxPaneId)) + { + throw lang::IllegalArgumentException( + "PresenterPane: invalid pane id", + static_cast(this), + 0); + } + + if ( ! (rArguments[1] >>= mxParentWindow)) + { + throw lang::IllegalArgumentException( + "PresenterPane: invalid parent window", + static_cast(this), + 1); + } + + Reference xParentCanvas; + if ( ! (rArguments[2] >>= xParentCanvas)) + { + throw lang::IllegalArgumentException( + "PresenterPane: invalid parent canvas", + static_cast(this), + 2); + } + + if ( ! (rArguments[3] >>= msTitle)) + { + throw lang::IllegalArgumentException( + "PresenterPane: invalid title", + static_cast(this), + 3); + } + + if ( ! (rArguments[4] >>= mxBorderPainter)) + { + throw lang::IllegalArgumentException( + "PresenterPane: invalid border painter", + static_cast(this), + 4); + } + + bool bIsWindowVisibleOnCreation (true); + if (rArguments.getLength()>5 && ! (rArguments[5] >>= bIsWindowVisibleOnCreation)) + { + throw lang::IllegalArgumentException( + "PresenterPane: invalid window visibility flag", + static_cast(this), + 5); + } + + CreateWindows(bIsWindowVisibleOnCreation); + + if (mxBorderWindow.is()) + { + mxBorderWindow->addWindowListener(this); + mxBorderWindow->addPaintListener(this); + } + + CreateCanvases(xParentCanvas); + + // Raise new windows. + ToTop(); + } + catch (Exception&) + { + mxContentWindow = nullptr; + mxComponentContext = nullptr; + throw; + } +} + +//----- XResourceId ----------------------------------------------------------- + +Reference SAL_CALL PresenterPaneBase::getResourceId() +{ + ThrowIfDisposed(); + return mxPaneId; +} + +sal_Bool SAL_CALL PresenterPaneBase::isAnchorOnly() +{ + return true; +} + +//----- XWindowListener ------------------------------------------------------- + +void SAL_CALL PresenterPaneBase::windowResized (const awt::WindowEvent&) +{ + ThrowIfDisposed(); +} + +void SAL_CALL PresenterPaneBase::windowMoved (const awt::WindowEvent&) +{ + ThrowIfDisposed(); +} + +void SAL_CALL PresenterPaneBase::windowShown (const lang::EventObject&) +{ + ThrowIfDisposed(); +} + +void SAL_CALL PresenterPaneBase::windowHidden (const lang::EventObject&) +{ + ThrowIfDisposed(); +} + +//----- lang::XEventListener -------------------------------------------------- + +void SAL_CALL PresenterPaneBase::disposing (const lang::EventObject& rEvent) +{ + if (rEvent.Source == mxBorderWindow) + { + mxBorderWindow = nullptr; + } +} + + +void PresenterPaneBase::CreateWindows ( + const bool bIsWindowVisibleOnCreation) +{ + if (!(mxPresenterHelper.is() && mxParentWindow.is())) + return; + + mxBorderWindow = mxPresenterHelper->createWindow( + mxParentWindow, + false, + bIsWindowVisibleOnCreation, + false, + false); + mxContentWindow = mxPresenterHelper->createWindow( + mxBorderWindow, + false, + bIsWindowVisibleOnCreation, + false, + false); +} + +const Reference& PresenterPaneBase::GetBorderWindow() const +{ + return mxBorderWindow; +} + +void PresenterPaneBase::ToTop() +{ + if (mxPresenterHelper.is()) + mxPresenterHelper->toTop(mxContentWindow); +} + +void PresenterPaneBase::PaintBorder (const awt::Rectangle& rUpdateBox) +{ + OSL_ASSERT(mxPaneId.is()); + + if (!(mxBorderPainter.is() && mxBorderWindow.is() && mxBorderCanvas.is())) + return; + + awt::Rectangle aBorderBox (mxBorderWindow->getPosSize()); + awt::Rectangle aLocalBorderBox (0,0, aBorderBox.Width, aBorderBox.Height); + + //TODO: paint border background? + + mxBorderPainter->paintBorder( + mxPaneId->getResourceURL(), + mxBorderCanvas, + aLocalBorderBox, + rUpdateBox, + msTitle); +} + +void PresenterPaneBase::LayoutContextWindow() +{ + OSL_ASSERT(mxPaneId.is()); + OSL_ASSERT(mxBorderWindow.is()); + OSL_ASSERT(mxContentWindow.is()); + if (!(mxBorderPainter.is() && mxPaneId.is() && mxBorderWindow.is() && mxContentWindow.is())) + return; + + const awt::Rectangle aBorderBox (mxBorderWindow->getPosSize()); + const awt::Rectangle aInnerBox (mxBorderPainter->removeBorder( + mxPaneId->getResourceURL(), + aBorderBox, + drawing::framework::BorderType_TOTAL_BORDER)); + mxContentWindow->setPosSize( + aInnerBox.X - aBorderBox.X, + aInnerBox.Y - aBorderBox.Y, + aInnerBox.Width, + aInnerBox.Height, + awt::PosSize::POSSIZE); +} + +bool PresenterPaneBase::IsVisible() const +{ + Reference xWindow2 (mxBorderPainter, UNO_QUERY); + if (xWindow2.is()) + return xWindow2->isVisible(); + + return false; +} + +void PresenterPaneBase::ThrowIfDisposed() +{ + if (rBHelper.bDisposed || rBHelper.bInDispose) + { + throw lang::DisposedException ( + "PresenterPane object has already been disposed", + static_cast(this)); + } +} + +} // end of namespace ::sdext::presenter + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3