Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sd / source / console / PresenterWindowManager.cxx
blob11db88ce52b64238e2b40bf136932c8c9aaa44e5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <utility>
21 #include <vcl/settings.hxx>
22 #include "PresenterWindowManager.hxx"
23 #include "PresenterController.hxx"
24 #include "PresenterGeometryHelper.hxx"
25 #include "PresenterPaintManager.hxx"
26 #include "PresenterPaneBorderPainter.hxx"
27 #include "PresenterPaneContainer.hxx"
28 #include "PresenterPaneFactory.hxx"
29 #include "PresenterToolBar.hxx"
30 #include "PresenterViewFactory.hxx"
31 #include "PresenterTheme.hxx"
32 #include <com/sun/star/awt/InvalidateStyle.hpp>
33 #include <com/sun/star/awt/PosSize.hpp>
34 #include <com/sun/star/awt/XWindow2.hpp>
35 #include <com/sun/star/awt/XWindowPeer.hpp>
36 #include <com/sun/star/rendering/CompositeOperation.hpp>
37 #include <com/sun/star/rendering/FillRule.hpp>
38 #include <com/sun/star/rendering/Texture.hpp>
39 #include <com/sun/star/rendering/TexturingMode.hpp>
40 #include <math.h>
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::drawing::framework;
46 namespace sdext::presenter {
48 //===== PresenterWindowManager ================================================
50 PresenterWindowManager::PresenterWindowManager (
51 const Reference<XComponentContext>& rxContext,
52 ::rtl::Reference<PresenterPaneContainer> pPaneContainer,
53 ::rtl::Reference<PresenterController> pPresenterController)
54 : PresenterWindowManagerInterfaceBase(m_aMutex),
55 mxComponentContext(rxContext),
56 mpPresenterController(std::move(pPresenterController)),
57 mpPaneContainer(std::move(pPaneContainer)),
58 mbIsLayoutPending(true),
59 mbIsLayouting(false),
60 meLayoutMode(LM_Generic),
61 mbIsSlideSorterActive(false),
62 mbIsHelpViewActive(false),
63 mbisPaused(false),
64 mbIsMouseClickPending(false)
69 PresenterWindowManager::~PresenterWindowManager()
73 void SAL_CALL PresenterWindowManager::disposing()
75 NotifyDisposing();
77 SetParentPane(nullptr);
79 Reference<lang::XComponent> xComponent (mxPaneBorderManager, UNO_QUERY);
80 if (xComponent.is())
81 xComponent->dispose();
82 mxPaneBorderManager = nullptr;
84 for (const auto& rxPane : mpPaneContainer->maPanes)
86 if (rxPane->mxBorderWindow.is())
88 rxPane->mxBorderWindow->removeWindowListener(this);
89 rxPane->mxBorderWindow->removeFocusListener(this);
90 rxPane->mxBorderWindow->removeMouseListener(this);
95 void PresenterWindowManager::SetParentPane (
96 const Reference<drawing::framework::XPane>& rxPane)
98 if (mxParentWindow.is())
100 mxParentWindow->removeWindowListener(this);
101 mxParentWindow->removePaintListener(this);
102 mxParentWindow->removeMouseListener(this);
103 mxParentWindow->removeFocusListener(this);
105 mxParentWindow = nullptr;
106 mxParentCanvas = nullptr;
108 if (rxPane.is())
110 mxParentWindow = rxPane->getWindow();
111 mxParentCanvas = rxPane->getCanvas();
113 else
115 mxParentWindow = nullptr;
118 if (mxParentWindow.is())
120 mxParentWindow->addWindowListener(this);
121 mxParentWindow->addPaintListener(this);
122 mxParentWindow->addMouseListener(this);
123 mxParentWindow->addFocusListener(this);
125 // We paint our own background, make that of the parent window transparent.
126 Reference<awt::XWindowPeer> xPeer (mxParentWindow, UNO_QUERY);
127 if (xPeer.is())
128 xPeer->setBackground(util::Color(0xff000000));
132 void PresenterWindowManager::SetTheme (const std::shared_ptr<PresenterTheme>& rpTheme)
134 mpTheme = rpTheme;
136 // Get background bitmap or background color from the theme.
138 if (mpTheme != nullptr)
140 mpBackgroundBitmap = mpTheme->GetBitmap(OUString(), "Background");
144 void PresenterWindowManager::NotifyViewCreation (const Reference<XView>& rxView)
146 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
147 mpPaneContainer->FindPaneId(rxView->getResourceId()->getAnchor()));
148 OSL_ASSERT(pDescriptor);
149 if (pDescriptor)
151 Layout();
153 mpPresenterController->GetPaintManager()->Invalidate(
154 pDescriptor->mxContentWindow,
155 sal_Int16(awt::InvalidateStyle::TRANSPARENT
156 | awt::InvalidateStyle::CHILDREN));
160 void PresenterWindowManager::SetPanePosSizeAbsolute (
161 const OUString& rsPaneURL,
162 const double nX,
163 const double nY,
164 const double nWidth,
165 const double nHeight)
167 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
168 mpPaneContainer->FindPaneURL(rsPaneURL));
169 if (pDescriptor)
171 if (pDescriptor->mxBorderWindow.is())
172 pDescriptor->mxBorderWindow->setPosSize(
173 ::sal::static_int_cast<sal_Int32>(nX),
174 ::sal::static_int_cast<sal_Int32>(nY),
175 ::sal::static_int_cast<sal_Int32>(nWidth),
176 ::sal::static_int_cast<sal_Int32>(nHeight),
177 awt::PosSize::POSSIZE);
181 void PresenterWindowManager::SetPaneBorderPainter (
182 const ::rtl::Reference<PresenterPaneBorderPainter>& rPainter)
184 mpPaneBorderPainter = rPainter;
187 //----- XWindowListener -------------------------------------------------------
189 void SAL_CALL PresenterWindowManager::windowResized (const awt::WindowEvent& rEvent)
191 ThrowIfDisposed();
192 if (rEvent.Source == mxParentWindow)
194 Layout();
196 else
198 Reference<awt::XWindow> xWindow (rEvent.Source,UNO_QUERY);
199 if (xWindow.is())
201 UpdateWindowSize(xWindow);
203 // Make sure the background of a transparent window is painted.
204 mpPresenterController->GetPaintManager()->Invalidate(mxParentWindow);
209 void SAL_CALL PresenterWindowManager::windowMoved (const awt::WindowEvent& rEvent)
211 ThrowIfDisposed();
212 if (rEvent.Source != mxParentWindow)
214 Reference<awt::XWindow> xWindow (rEvent.Source,UNO_QUERY);
215 UpdateWindowSize(xWindow);
217 // Make sure the background of a transparent window is painted.
218 mpPresenterController->GetPaintManager()->Invalidate(xWindow);
222 void SAL_CALL PresenterWindowManager::windowShown (const lang::EventObject&) {}
224 void SAL_CALL PresenterWindowManager::windowHidden (const lang::EventObject&) {}
226 //----- XPaintListener --------------------------------------------------------
228 void SAL_CALL PresenterWindowManager::windowPaint (const awt::PaintEvent& rEvent)
230 ThrowIfDisposed();
232 if ( ! mxParentWindow.is())
233 return;
234 if ( ! mxParentCanvas.is())
235 return;
237 if (mpTheme == nullptr)
238 return;
242 if (mbIsLayoutPending)
243 Layout();
244 PaintBackground(rEvent.UpdateRect);
245 PaintChildren(rEvent);
247 catch (RuntimeException&)
249 OSL_FAIL("paint failed!");
253 //----- XMouseListener --------------------------------------------------------
255 void SAL_CALL PresenterWindowManager::mousePressed (const css::awt::MouseEvent&)
257 if (!mbIsSlideSorterActive) // tdf#127921
258 mbIsMouseClickPending = true;
261 void SAL_CALL PresenterWindowManager::mouseReleased (const css::awt::MouseEvent& rEvent)
263 if (mbIsMouseClickPending)
265 mbIsMouseClickPending = false;
266 mpPresenterController->HandleMouseClick(rEvent);
270 void SAL_CALL PresenterWindowManager::mouseEntered (const css::awt::MouseEvent&)
272 mbIsMouseClickPending = false;
275 void SAL_CALL PresenterWindowManager::mouseExited (const css::awt::MouseEvent&)
277 mbIsMouseClickPending = false;
280 //----- XFocusListener --------------------------------------------------------
282 void SAL_CALL PresenterWindowManager::focusGained (const css::awt::FocusEvent& /*rEvent*/)
284 ThrowIfDisposed();
287 void SAL_CALL PresenterWindowManager::focusLost (const css::awt::FocusEvent&)
289 ThrowIfDisposed();
292 //----- XEventListener --------------------------------------------------------
294 void SAL_CALL PresenterWindowManager::disposing (const lang::EventObject& rEvent)
296 if (rEvent.Source == mxParentWindow)
297 mxParentWindow = nullptr;
301 void PresenterWindowManager::PaintChildren (const awt::PaintEvent& rEvent) const
303 // Call windowPaint on all children that lie in or touch the
304 // update rectangle.
305 for (const auto& rxPane : mpPaneContainer->maPanes)
309 // Make sure that the pane shall and can be painted.
310 if ( ! rxPane->mbIsActive)
311 continue;
312 if (rxPane->mbIsSprite)
313 continue;
314 if ( ! rxPane->mxPane.is())
315 continue;
316 if ( ! rxPane->mxBorderWindow.is())
317 continue;
318 Reference<awt::XWindow> xBorderWindow (rxPane->mxBorderWindow);
319 if ( ! xBorderWindow.is())
320 continue;
322 // Get the area in which the border of the pane has to be painted.
323 const awt::Rectangle aBorderBox (xBorderWindow->getPosSize());
324 const awt::Rectangle aBorderUpdateBox(
325 PresenterGeometryHelper::Intersection(
326 rEvent.UpdateRect,
327 aBorderBox));
328 if (aBorderUpdateBox.Width<=0 || aBorderUpdateBox.Height<=0)
329 continue;
331 const awt::Rectangle aLocalBorderUpdateBox(
332 PresenterGeometryHelper::TranslateRectangle(
333 aBorderUpdateBox,
334 -aBorderBox.X,
335 -aBorderBox.Y));
337 // Invalidate the area of the content window.
338 mpPresenterController->GetPaintManager()->Invalidate(
339 xBorderWindow,
340 aLocalBorderUpdateBox,
341 sal_Int16(awt::InvalidateStyle::CHILDREN
342 | awt::InvalidateStyle::NOTRANSPARENT));
344 catch (RuntimeException&)
346 OSL_FAIL("paint children failed!");
351 void PresenterWindowManager::SetLayoutMode (const LayoutMode eMode)
353 OSL_ASSERT(mpPresenterController);
355 if (meLayoutMode == eMode
356 && !mbIsSlideSorterActive
357 && !mbIsHelpViewActive)
358 return;
360 meLayoutMode = eMode;
361 mbIsSlideSorterActive = false;
362 mbIsHelpViewActive = false;
364 mpPresenterController->RequestViews(
365 mbIsSlideSorterActive,
366 meLayoutMode==LM_Notes,
367 mbIsHelpViewActive);
368 Layout();
369 NotifyLayoutModeChange();
372 void PresenterWindowManager::SetSlideSorterState (bool bIsActive)
374 if (mbIsSlideSorterActive == bIsActive)
375 return;
377 mbIsSlideSorterActive = bIsActive;
378 if (mbIsSlideSorterActive)
379 mbIsHelpViewActive = false;
380 StoreViewMode(GetViewMode());
382 mpPresenterController->RequestViews(
383 mbIsSlideSorterActive,
384 meLayoutMode==LM_Notes,
385 mbIsHelpViewActive);
386 Layout();
387 NotifyLayoutModeChange();
390 void PresenterWindowManager::SetHelpViewState (bool bIsActive)
392 if (mbIsHelpViewActive == bIsActive)
393 return;
395 mbIsHelpViewActive = bIsActive;
396 if (mbIsHelpViewActive)
397 mbIsSlideSorterActive = false;
398 StoreViewMode(GetViewMode());
400 mpPresenterController->RequestViews(
401 mbIsSlideSorterActive,
402 meLayoutMode==LM_Notes,
403 mbIsHelpViewActive);
404 Layout();
405 NotifyLayoutModeChange();
408 void PresenterWindowManager::SetPauseState (bool bIsPaused)
410 if (mbisPaused == bIsPaused)
411 return;
413 mbisPaused = bIsPaused;
415 NotifyLayoutModeChange();
418 void PresenterWindowManager::SetViewMode (const ViewMode eMode)
420 switch (eMode)
422 case VM_Standard:
423 SetSlideSorterState(false);
424 SetHelpViewState(false);
425 SetLayoutMode(LM_Standard);
426 break;
428 case VM_Notes:
429 SetSlideSorterState(false);
430 SetHelpViewState(false);
431 SetLayoutMode(LM_Notes);
432 break;
434 case VM_SlideOverview:
435 SetHelpViewState(false);
436 SetSlideSorterState(true);
437 break;
439 case VM_Help:
440 SetHelpViewState(true);
441 SetSlideSorterState(false);
442 break;
445 StoreViewMode(eMode);
448 PresenterWindowManager::ViewMode PresenterWindowManager::GetViewMode() const
450 if (mbIsHelpViewActive)
451 return VM_Help;
452 else if (mbIsSlideSorterActive)
453 return VM_SlideOverview;
454 else if (meLayoutMode == LM_Notes)
455 return VM_Notes;
456 else
457 return VM_Standard;
460 void PresenterWindowManager::RestoreViewMode()
462 sal_Int32 nMode (0);
463 PresenterConfigurationAccess aConfiguration (
464 mxComponentContext,
465 "/org.openoffice.Office.PresenterScreen/",
466 PresenterConfigurationAccess::READ_ONLY);
467 aConfiguration.GetConfigurationNode("Presenter/InitialViewMode") >>= nMode;
468 switch (nMode)
470 default:
471 case 0:
472 SetViewMode(VM_Standard);
473 break;
475 case 1:
476 SetViewMode(VM_Notes);
477 break;
479 case 2:
480 SetViewMode(VM_SlideOverview);
481 break;
485 void PresenterWindowManager::StoreViewMode (const ViewMode eViewMode)
489 PresenterConfigurationAccess aConfiguration (
490 mxComponentContext,
491 "/org.openoffice.Office.PresenterScreen/",
492 PresenterConfigurationAccess::READ_WRITE);
493 aConfiguration.GoToChild("Presenter");
494 Any aValue;
495 switch (eViewMode)
497 default:
498 case VM_Standard:
499 aValue <<= sal_Int32(0);
500 break;
502 case VM_Notes:
503 aValue <<= sal_Int32(1);
504 break;
506 case VM_SlideOverview:
507 aValue <<= sal_Int32(2);
508 break;
511 aConfiguration.SetProperty ("InitialViewMode", aValue);
512 aConfiguration.CommitChanges();
514 catch (Exception&)
519 void PresenterWindowManager::AddLayoutListener (
520 const Reference<document::XEventListener>& rxListener)
522 maLayoutListeners.push_back(rxListener);
525 void PresenterWindowManager::RemoveLayoutListener (
526 const Reference<document::XEventListener>& rxListener)
528 // Assume that there are no multiple entries.
529 auto iListener = std::find(maLayoutListeners.begin(), maLayoutListeners.end(), rxListener);
530 if (iListener != maLayoutListeners.end())
531 maLayoutListeners.erase(iListener);
534 void PresenterWindowManager::Layout()
536 if (!mxParentWindow.is() || mbIsLayouting)
537 return;
539 mbIsLayoutPending = false;
540 mbIsLayouting = true;
541 mxScaledBackgroundBitmap = nullptr;
542 mxClipPolygon = nullptr;
546 if (mbIsSlideSorterActive)
547 LayoutSlideSorterMode();
548 else if (mbIsHelpViewActive)
549 LayoutHelpMode();
550 else
551 switch (meLayoutMode)
553 case LM_Standard:
554 default:
555 LayoutStandardMode();
556 break;
558 case LM_Notes:
559 LayoutNotesMode();
560 break;
563 catch (Exception&)
565 OSL_ASSERT(false);
566 throw;
569 mbIsLayouting = false;
572 void PresenterWindowManager::LayoutStandardMode()
574 awt::Rectangle aBox = mxParentWindow->getPosSize();
576 const double nGoldenRatio ((1 + sqrt(5.0)) / 2);
577 const double nGap (20);
578 const double nHorizontalSlideDivide (aBox.Width / nGoldenRatio);
579 double nSlidePreviewTop (0);
582 // For the current slide view calculate the outer height from the outer
583 // width. This takes into account the slide aspect ratio and thus has to
584 // go over the inner pane size.
585 PresenterPaneContainer::SharedPaneDescriptor pPane (
586 mpPaneContainer->FindPaneURL(PresenterPaneFactory::msCurrentSlidePreviewPaneURL));
587 if (pPane)
589 const awt::Size aCurrentSlideOuterBox(CalculatePaneSize(
590 nHorizontalSlideDivide - 1.5*nGap,
591 PresenterPaneFactory::msCurrentSlidePreviewPaneURL));
592 nSlidePreviewTop = (aBox.Height - aCurrentSlideOuterBox.Height) / 2;
593 double Temp=nGap;
594 /// check whether RTL interface or not
595 if(AllSettings::GetLayoutRTL())
596 Temp=aBox.Width - aCurrentSlideOuterBox.Width - nGap;
597 SetPanePosSizeAbsolute (
598 PresenterPaneFactory::msCurrentSlidePreviewPaneURL,
599 Temp,
600 nSlidePreviewTop,
601 aCurrentSlideOuterBox.Width,
602 aCurrentSlideOuterBox.Height);
605 // For the next slide view calculate the outer height from the outer
606 // width. This takes into account the slide aspect ratio and thus has to
607 // go over the inner pane size.
608 pPane = mpPaneContainer->FindPaneURL(PresenterPaneFactory::msNextSlidePreviewPaneURL);
609 if (pPane)
611 const awt::Size aNextSlideOuterBox (CalculatePaneSize(
612 aBox.Width - nHorizontalSlideDivide - 1.5*nGap,
613 PresenterPaneFactory::msNextSlidePreviewPaneURL));
614 double Temp=aBox.Width - aNextSlideOuterBox.Width - nGap;
615 /// check whether RTL interface or not
616 if(AllSettings::GetLayoutRTL())
617 Temp=nGap;
618 SetPanePosSizeAbsolute (
619 PresenterPaneFactory::msNextSlidePreviewPaneURL,
620 Temp,
621 nSlidePreviewTop,
622 aNextSlideOuterBox.Width,
623 aNextSlideOuterBox.Height);
626 LayoutToolBar();
629 void PresenterWindowManager::LayoutNotesMode()
631 awt::Rectangle aBox = mxParentWindow->getPosSize();
633 const geometry::RealRectangle2D aToolBarBox (LayoutToolBar());
635 const double nGoldenRatio ((1 + sqrt(5.0)) / 2);
636 const double nGap (20);
637 const double nPrimaryWidth (aBox.Width / nGoldenRatio);
638 const double nSecondaryWidth (aBox.Width - nPrimaryWidth);
639 const double nTertiaryWidth (nSecondaryWidth / nGoldenRatio);
640 double nSlidePreviewTop (0);
641 double nNotesViewBottom (aToolBarBox.Y1 - nGap);
642 /// check whether RTL interface or not
645 // The notes view has no fixed aspect ratio.
646 PresenterPaneContainer::SharedPaneDescriptor pPane (
647 mpPaneContainer->FindPaneURL(PresenterPaneFactory::msNotesPaneURL));
648 if (pPane)
650 const geometry::RealSize2D aNotesViewOuterSize(
651 nPrimaryWidth - 1.5*nGap + 0.5,
652 nNotesViewBottom);
653 nSlidePreviewTop = (aBox.Height
654 - aToolBarBox.Y2 + aToolBarBox.Y1 - aNotesViewOuterSize.Height) / 2;
655 /// check whether RTL interface or not
656 double Temp=aBox.Width - aNotesViewOuterSize.Width - nGap;
657 if(AllSettings::GetLayoutRTL())
658 Temp=nGap;
659 SetPanePosSizeAbsolute (
660 PresenterPaneFactory::msNotesPaneURL,
661 Temp,
662 nSlidePreviewTop,
663 aNotesViewOuterSize.Width,
664 aNotesViewOuterSize.Height);
665 nNotesViewBottom = nSlidePreviewTop + aNotesViewOuterSize.Height;
668 // For the current slide view calculate the outer height from the outer
669 // width. This takes into account the slide aspect ratio and thus has to
670 // go over the inner pane size.
671 pPane = mpPaneContainer->FindPaneURL(PresenterPaneFactory::msCurrentSlidePreviewPaneURL);
672 if (pPane)
674 const awt::Size aCurrentSlideOuterBox(CalculatePaneSize(
675 nSecondaryWidth - 1.5*nGap,
676 PresenterPaneFactory::msCurrentSlidePreviewPaneURL));
677 /// check whether RTL interface or not
678 double Temp=nGap;
679 if(AllSettings::GetLayoutRTL())
680 Temp=aBox.Width - aCurrentSlideOuterBox.Width - nGap;
681 SetPanePosSizeAbsolute (
682 PresenterPaneFactory::msCurrentSlidePreviewPaneURL,
683 Temp,
684 nSlidePreviewTop,
685 aCurrentSlideOuterBox.Width,
686 aCurrentSlideOuterBox.Height);
689 // For the next slide view calculate the outer height from the outer
690 // width. This takes into account the slide aspect ratio and thus has to
691 // go over the inner pane size.
692 pPane = mpPaneContainer->FindPaneURL(PresenterPaneFactory::msNextSlidePreviewPaneURL);
693 if (!pPane)
694 return;
696 const awt::Size aNextSlideOuterBox (CalculatePaneSize(
697 nTertiaryWidth,
698 PresenterPaneFactory::msNextSlidePreviewPaneURL));
699 /// check whether RTL interface or not
700 double Temp=nGap;
701 if(AllSettings::GetLayoutRTL())
702 Temp=aBox.Width - aNextSlideOuterBox.Width - nGap;
703 SetPanePosSizeAbsolute (
704 PresenterPaneFactory::msNextSlidePreviewPaneURL,
705 Temp,
706 nNotesViewBottom - aNextSlideOuterBox.Height,
707 aNextSlideOuterBox.Width,
708 aNextSlideOuterBox.Height);
713 void PresenterWindowManager::LayoutSlideSorterMode()
715 const geometry::RealRectangle2D aToolBarBox (LayoutToolBar());
717 awt::Rectangle aWindowBox = mxParentWindow->getPosSize();
718 const double nGap (20);
719 SetPanePosSizeAbsolute(
720 mpPaneContainer->GetPaneURLForViewURL(PresenterViewFactory::msSlideSorterURL),
721 nGap,
722 nGap,
723 aWindowBox.Width - 2*nGap,
724 aToolBarBox.Y1 - 2*nGap);
727 void PresenterWindowManager::LayoutHelpMode()
729 const geometry::RealRectangle2D aToolBarBox (LayoutToolBar());
731 awt::Rectangle aWindowBox = mxParentWindow->getPosSize();
732 const double nGap (20);
733 const double nGoldenRatio ((1 + sqrt(5.0)) / 2);
734 const double nWidth = ::std::min(aWindowBox.Width - 2*nGap, aWindowBox.Width/nGoldenRatio);
735 SetPanePosSizeAbsolute(
736 mpPaneContainer->GetPaneURLForViewURL(PresenterViewFactory::msHelpViewURL),
737 (aWindowBox.Width - nWidth)/2,
738 nGap,
739 nWidth,
740 aToolBarBox.Y1 - 2*nGap);
743 geometry::RealRectangle2D PresenterWindowManager::LayoutToolBar()
745 double nToolBarWidth (400);
746 double nToolBarHeight (80);
748 // Get access to the tool bar.
749 PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
750 mpPaneContainer->FindPaneURL(PresenterPaneFactory::msToolBarPaneURL));
751 if (pDescriptor)
753 PresenterToolBarView* pToolBarView
754 = dynamic_cast<PresenterToolBarView*>(pDescriptor->mxView.get());
755 if (pToolBarView != nullptr && pToolBarView->GetPresenterToolBar().is())
757 geometry::RealSize2D aSize (pToolBarView->GetPresenterToolBar()->GetMinimalSize());
759 if (mpPaneBorderPainter.is())
761 const awt::Rectangle aBox (mpPaneBorderPainter->addBorder (
762 PresenterPaneFactory::msToolBarPaneURL,
763 awt::Rectangle(
766 PresenterGeometryHelper::Round(aSize.Width),
767 PresenterGeometryHelper::Round(aSize.Height)),
768 css::drawing::framework::BorderType_TOTAL_BORDER));
770 nToolBarWidth = aBox.Width;
771 nToolBarHeight = aBox.Height;
773 else
775 nToolBarWidth = aSize.Width + 20;
776 nToolBarHeight = aSize.Height + 10;
781 const awt::Rectangle aBox = mxParentWindow->getPosSize();
782 const double nToolBarX ((aBox.Width - nToolBarWidth) / 2);
783 const double nToolBarY (aBox.Height - nToolBarHeight);
784 SetPanePosSizeAbsolute(
785 PresenterPaneFactory::msToolBarPaneURL,
786 nToolBarX,
787 nToolBarY,
788 nToolBarWidth,
789 nToolBarHeight);
791 return geometry::RealRectangle2D(
792 nToolBarX,
793 nToolBarY,
794 nToolBarX + nToolBarWidth - 1,
795 nToolBarY + nToolBarHeight - 1);
798 awt::Size PresenterWindowManager::CalculatePaneSize (
799 const double nOuterWidth,
800 const OUString& rsPaneURL)
802 // Calculate the inner width by removing the pane border.
803 awt::Rectangle aInnerBox (mpPaneBorderPainter->RemoveBorder (
804 rsPaneURL,
805 awt::Rectangle(0,0,
806 sal_Int32(nOuterWidth+0.5),sal_Int32(nOuterWidth)),
807 drawing::framework::BorderType_TOTAL_BORDER));
809 // Calculate the inner height with the help of the slide aspect ratio.
810 const double nCurrentSlideInnerHeight (
811 aInnerBox.Width / mpPresenterController->GetSlideAspectRatio());
813 // Add the pane border to get the outer box.
814 awt::Rectangle aOuterBox (mpPaneBorderPainter->AddBorder (
815 rsPaneURL,
816 awt::Rectangle(0,0,
817 aInnerBox.Width,sal_Int32(nCurrentSlideInnerHeight+0.5)),
818 drawing::framework::BorderType_TOTAL_BORDER));
820 return awt::Size(aOuterBox.Width, aOuterBox.Height);
823 void PresenterWindowManager::NotifyLayoutModeChange()
825 document::EventObject aEvent;
826 aEvent.Source = Reference<XInterface>(static_cast<XWeak*>(this));
828 LayoutListenerContainer aContainerCopy (maLayoutListeners);
829 for (const auto& rxListener : aContainerCopy)
831 if (rxListener.is())
835 rxListener->notifyEvent(aEvent);
837 catch (lang::DisposedException&)
839 RemoveLayoutListener(rxListener);
841 catch (RuntimeException&)
848 void PresenterWindowManager::NotifyDisposing()
850 lang::EventObject aEvent;
851 aEvent.Source = static_cast<XWeak*>(this);
853 LayoutListenerContainer aContainer;
854 aContainer.swap(maLayoutListeners);
855 for (auto& rxListener : aContainer)
857 if (rxListener.is())
861 rxListener->disposing(aEvent);
863 catch (lang::DisposedException&)
866 catch (RuntimeException&)
873 void PresenterWindowManager::UpdateWindowSize (const Reference<awt::XWindow>& rxBorderWindow)
875 PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
876 mpPaneContainer->FindBorderWindow(rxBorderWindow));
877 if (pDescriptor)
879 mxClipPolygon = nullptr;
881 // ToTop is called last because it may invalidate the iterator.
882 if ( ! mbIsLayouting)
883 mpPaneContainer->ToTop(pDescriptor);
887 void PresenterWindowManager::PaintBackground (const awt::Rectangle& rUpdateBox)
889 if ( ! mxParentWindow.is())
890 return;
892 Reference<rendering::XGraphicDevice> xDevice (mxParentCanvas->getDevice());
893 if ( ! xDevice.is())
894 return;
896 // Create a polygon for the background and for clipping.
897 Reference<rendering::XPolyPolygon2D> xBackgroundPolygon (
898 PresenterGeometryHelper::CreatePolygon(mxParentWindow->getPosSize(), xDevice));
899 if ( ! mxClipPolygon.is())
900 mxClipPolygon = CreateClipPolyPolygon();
902 // Create View- and RenderState structs.
903 const rendering::ViewState aViewState(
904 geometry::AffineMatrix2D(1,0,0, 0,1,0),
905 PresenterGeometryHelper::CreatePolygon(rUpdateBox, xDevice));
906 rendering::RenderState aRenderState (
907 geometry::AffineMatrix2D(1,0,0, 0,1,0),
908 mxClipPolygon,
909 Sequence<double>(4),
910 rendering::CompositeOperation::SOURCE);
912 // Paint the background.
913 if (!mpBackgroundBitmap)
914 return;
916 ProvideBackgroundBitmap();
918 if (mxScaledBackgroundBitmap.is())
920 const geometry::IntegerSize2D aBitmapSize(mxScaledBackgroundBitmap->getSize());
921 Sequence<rendering::Texture> aTextures
924 geometry::AffineMatrix2D( aBitmapSize.Width,0,0, 0,aBitmapSize.Height,0),
927 mxScaledBackgroundBitmap,
928 nullptr,
929 nullptr,
930 rendering::StrokeAttributes(),
931 rendering::TexturingMode::REPEAT,
932 rendering::TexturingMode::REPEAT
936 mxParentCanvas->fillTexturedPolyPolygon(
937 xBackgroundPolygon,
938 aViewState,
939 aRenderState,
940 aTextures);
942 else
944 const util::Color aBackgroundColor (mpBackgroundBitmap->maReplacementColor);
945 auto pDeviceColor = aRenderState.DeviceColor.getArray();
946 pDeviceColor[0] = ((aBackgroundColor >> 16) & 0x0ff) / 255.0;
947 pDeviceColor[1] = ((aBackgroundColor >> 8) & 0x0ff) / 255.0;
948 pDeviceColor[2] = ((aBackgroundColor >> 0) & 0x0ff) / 255.0;
949 pDeviceColor[3] = ((aBackgroundColor >> 24) & 0x0ff) / 255.0;
950 mxParentCanvas->fillPolyPolygon(
951 xBackgroundPolygon,
952 aViewState,
953 aRenderState);
957 void PresenterWindowManager::ProvideBackgroundBitmap()
959 if ( mxScaledBackgroundBitmap.is())
960 return;
962 Reference<rendering::XBitmap> xBitmap (mpBackgroundBitmap->GetNormalBitmap());
963 if (!xBitmap.is())
964 return;
966 const bool bStretchVertical (mpBackgroundBitmap->meVerticalTexturingMode
967 == PresenterBitmapDescriptor::Stretch);
968 const bool bStretchHorizontal (mpBackgroundBitmap->meHorizontalTexturingMode
969 == PresenterBitmapDescriptor::Stretch);
970 if (bStretchHorizontal || bStretchVertical)
972 geometry::RealSize2D aSize;
973 if (bStretchVertical)
974 aSize.Height = mxParentWindow->getPosSize().Height;
975 else
976 aSize.Height = xBitmap->getSize().Height;
977 if (bStretchHorizontal)
978 aSize.Width = mxParentWindow->getPosSize().Width;
979 else
980 aSize.Width = xBitmap->getSize().Width;
981 mxScaledBackgroundBitmap = xBitmap->getScaledBitmap(aSize, false);
983 else
985 mxScaledBackgroundBitmap = xBitmap;
989 Reference<rendering::XPolyPolygon2D> PresenterWindowManager::CreateClipPolyPolygon() const
991 // Create a clip polygon that includes the whole update area but has the
992 // content windows as holes.
993 const sal_Int32 nPaneCount (mpPaneContainer->maPanes.size());
994 ::std::vector<awt::Rectangle> aRectangles;
995 aRectangles.reserve(1+nPaneCount);
996 aRectangles.push_back(mxParentWindow->getPosSize());
997 for (const auto& pDescriptor : mpPaneContainer->maPanes)
999 if ( ! pDescriptor->mbIsActive)
1000 continue;
1001 if ( ! pDescriptor->mbIsOpaque)
1002 continue;
1003 if ( ! pDescriptor->mxBorderWindow.is() || ! pDescriptor->mxContentWindow.is())
1004 continue;
1005 Reference<awt::XWindow2> xWindow (pDescriptor->mxBorderWindow, UNO_QUERY);
1006 if (xWindow.is() && ! xWindow->isVisible())
1007 continue;
1009 const awt::Rectangle aOuterBorderBox (pDescriptor->mxBorderWindow->getPosSize());
1010 awt::Rectangle aInnerBorderBox (pDescriptor->mxContentWindow->getPosSize());
1011 aInnerBorderBox.X += aOuterBorderBox.X;
1012 aInnerBorderBox.Y += aOuterBorderBox.Y;
1013 aRectangles.push_back(aInnerBorderBox);
1015 Reference<rendering::XPolyPolygon2D> xPolyPolygon (
1016 PresenterGeometryHelper::CreatePolygon(
1017 aRectangles,
1018 mxParentCanvas->getDevice()));
1019 if (xPolyPolygon.is())
1020 xPolyPolygon->setFillRule(rendering::FillRule_EVEN_ODD);
1021 return xPolyPolygon;
1024 void PresenterWindowManager::Update()
1026 mxClipPolygon = nullptr;
1027 mbIsLayoutPending = true;
1029 mpPresenterController->GetPaintManager()->Invalidate(mxParentWindow);
1032 void PresenterWindowManager::ThrowIfDisposed() const
1034 if (rBHelper.bDisposed || rBHelper.bInDispose)
1036 throw lang::DisposedException (
1037 "PresenterWindowManager has already been disposed",
1038 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
1042 } // end of namespace ::sdext::presenter
1044 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */