1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20 #include "PresenterPaintManager.hxx"
21
22 #include "PresenterPaneContainer.hxx"
23 #include <com/sun/star/awt/InvalidateStyle.hpp>
24 #include <com/sun/star/awt/XWindowPeer.hpp>
25
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::uno;
28
29 namespace sdext::presenter {
30
PresenterPaintManager(const css::uno::Reference<css::awt::XWindow> & rxParentWindow,const css::uno::Reference<css::drawing::XPresenterHelper> & rxPresenterHelper,const rtl::Reference<PresenterPaneContainer> & rpPaneContainer)31 PresenterPaintManager::PresenterPaintManager (
32 const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
33 const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
34 const rtl::Reference<PresenterPaneContainer>& rpPaneContainer)
35 : mxParentWindow(rxParentWindow),
36 mxParentWindowPeer(rxParentWindow, UNO_QUERY),
37 mxPresenterHelper(rxPresenterHelper),
38 mpPaneContainer(rpPaneContainer)
39 {
40 }
41
42 ::std::function<void (const css::awt::Rectangle& rRepaintBox)>
GetInvalidator(const css::uno::Reference<css::awt::XWindow> & rxWindow)43 PresenterPaintManager::GetInvalidator (
44 const css::uno::Reference<css::awt::XWindow>& rxWindow)
45 {
46 return [this, rxWindow] (css::awt::Rectangle const& rRepaintBox)
47 {
48 return this->Invalidate(rxWindow, rRepaintBox /* , bSynchronous=false */);
49 };
50 }
51
Invalidate(const css::uno::Reference<css::awt::XWindow> & rxWindow)52 void PresenterPaintManager::Invalidate (
53 const css::uno::Reference<css::awt::XWindow>& rxWindow)
54 {
55 sal_Int16 nInvalidateMode (awt::InvalidateStyle::CHILDREN);
56
57 PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
58 mpPaneContainer->FindContentWindow(rxWindow));
59 if (!pDescriptor || ! pDescriptor->mbIsOpaque)
60 nInvalidateMode |= awt::InvalidateStyle::TRANSPARENT;
61 else
62 nInvalidateMode |= awt::InvalidateStyle::NOTRANSPARENT;
63
64 Invalidate(rxWindow, nInvalidateMode);
65 }
66
Invalidate(const css::uno::Reference<css::awt::XWindow> & rxWindow,const sal_Int16 nInvalidateFlags)67 void PresenterPaintManager::Invalidate (
68 const css::uno::Reference<css::awt::XWindow>& rxWindow,
69 const sal_Int16 nInvalidateFlags)
70 {
71 if ((nInvalidateFlags & awt::InvalidateStyle::TRANSPARENT) != 0)
72 {
73 // Window is transparent and parent window(s) have to be painted as
74 // well. Invalidate the parent explicitly.
75 if (mxPresenterHelper.is() && mxParentWindowPeer.is())
76 {
77 const awt::Rectangle aBBox (
78 mxPresenterHelper->getWindowExtentsRelative(rxWindow, mxParentWindow));
79 mxParentWindowPeer->invalidateRect(aBBox, nInvalidateFlags);
80 }
81 }
82 else
83 {
84 Reference<awt::XWindowPeer> xPeer (rxWindow, UNO_QUERY);
85 if (xPeer.is())
86 xPeer->invalidate(nInvalidateFlags);
87 }
88 }
89
Invalidate(const css::uno::Reference<css::awt::XWindow> & rxWindow,const css::awt::Rectangle & rRepaintBox,const bool bSynchronous)90 void PresenterPaintManager::Invalidate (
91 const css::uno::Reference<css::awt::XWindow>& rxWindow,
92 const css::awt::Rectangle& rRepaintBox,
93 const bool bSynchronous)
94 {
95 sal_Int16 nInvalidateMode (awt::InvalidateStyle::CHILDREN);
96 if (bSynchronous)
97 nInvalidateMode |= awt::InvalidateStyle::UPDATE;
98
99 PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
100 mpPaneContainer->FindContentWindow(rxWindow));
101 if (!pDescriptor || ! pDescriptor->mbIsOpaque)
102 nInvalidateMode |= awt::InvalidateStyle::TRANSPARENT;
103 else
104 nInvalidateMode |= awt::InvalidateStyle::NOTRANSPARENT;
105
106 Invalidate(rxWindow, rRepaintBox, nInvalidateMode);
107 }
108
Invalidate(const css::uno::Reference<css::awt::XWindow> & rxWindow,const css::awt::Rectangle & rRepaintBox,const sal_Int16 nInvalidateFlags)109 void PresenterPaintManager::Invalidate (
110 const css::uno::Reference<css::awt::XWindow>& rxWindow,
111 const css::awt::Rectangle& rRepaintBox,
112 const sal_Int16 nInvalidateFlags)
113 {
114 if ((nInvalidateFlags & awt::InvalidateStyle::TRANSPARENT) != 0)
115 {
116 // Window is transparent and parent window(s) have to be painted as
117 // well. Invalidate the parent explicitly.
118 if (mxPresenterHelper.is() && mxParentWindowPeer.is())
119 {
120 const awt::Rectangle aBBox (
121 mxPresenterHelper->getWindowExtentsRelative(rxWindow, mxParentWindow));
122 mxParentWindowPeer->invalidateRect(
123 awt::Rectangle(
124 rRepaintBox.X + aBBox.X,
125 rRepaintBox.Y + aBBox.Y,
126 rRepaintBox.Width,
127 rRepaintBox.Height),
128 nInvalidateFlags);
129 }
130 }
131 else
132 {
133 Reference<awt::XWindowPeer> xPeer (rxWindow, UNO_QUERY);
134 if (xPeer.is())
135 xPeer->invalidateRect(rRepaintBox, nInvalidateFlags);
136 }
137 }
138
139 }
140
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
142