1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include "PresenterPaintManager.hxx"
32 
33 #include "PresenterPaneContainer.hxx"
34 #include <com/sun/star/awt/InvalidateStyle.hpp>
35 #include <com/sun/star/awt/XWindowPeer.hpp>
36 #include <boost/bind.hpp>
37 
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 
41 namespace sdext { namespace presenter {
42 
43 PresenterPaintManager::PresenterPaintManager (
44     const css::uno::Reference<css::awt::XWindow>& rxParentWindow,
45     const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
46     const rtl::Reference<PresenterPaneContainer>& rpPaneContainer)
47     : mxParentWindow(rxParentWindow),
48       mxParentWindowPeer(rxParentWindow, UNO_QUERY),
49       mxPresenterHelper(rxPresenterHelper),
50       mpPaneContainer(rpPaneContainer)
51 {
52 }
53 
54 
55 
56 
57 ::boost::function<void(const css::awt::Rectangle& rRepaintBox)>
58     PresenterPaintManager::GetInvalidator (
59         const css::uno::Reference<css::awt::XWindow>& rxWindow,
60         const bool bSynchronous)
61 {
62     return ::boost::bind(
63         static_cast<void (PresenterPaintManager::*)(
64             const css::uno::Reference<css::awt::XWindow>&,
65             const css::awt::Rectangle&,
66             const bool)>(&PresenterPaintManager::Invalidate),
67         this,
68         rxWindow,
69         _1,
70         bSynchronous);
71 }
72 
73 
74 
75 
76 void PresenterPaintManager::Invalidate (
77     const css::uno::Reference<css::awt::XWindow>& rxWindow,
78     const bool bSynchronous)
79 {
80     sal_Int16 nInvalidateMode (awt::InvalidateStyle::CHILDREN);
81     if (bSynchronous)
82         nInvalidateMode |= awt::InvalidateStyle::UPDATE;
83 
84     PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
85         mpPaneContainer->FindContentWindow(rxWindow));
86     if (pDescriptor.get()==NULL || ! pDescriptor->mbIsOpaque)
87         nInvalidateMode |= awt::InvalidateStyle::TRANSPARENT;
88     else
89         nInvalidateMode |= awt::InvalidateStyle::NOTRANSPARENT;
90 
91     Invalidate(rxWindow, nInvalidateMode);
92 }
93 
94 
95 
96 
97 void PresenterPaintManager::Invalidate (
98     const css::uno::Reference<css::awt::XWindow>& rxWindow,
99     const sal_Int16 nInvalidateFlags)
100 {
101     if ((nInvalidateFlags & awt::InvalidateStyle::TRANSPARENT) != 0)
102     {
103         // Window is transparent and parent window(s) have to be painted as
104         // well.  Invalidate the parent explicitly.
105         if (mxPresenterHelper.is() && mxParentWindowPeer.is())
106         {
107             const awt::Rectangle aBBox (
108                 mxPresenterHelper->getWindowExtentsRelative(rxWindow, mxParentWindow));
109             mxParentWindowPeer->invalidateRect(aBBox, nInvalidateFlags);
110         }
111     }
112     else
113     {
114         Reference<awt::XWindowPeer> xPeer (rxWindow, UNO_QUERY);
115         if (xPeer.is())
116             xPeer->invalidate(nInvalidateFlags);
117     }
118 }
119 
120 
121 
122 
123 void PresenterPaintManager::Invalidate (
124     const css::uno::Reference<css::awt::XWindow>& rxWindow,
125     const css::awt::Rectangle& rRepaintBox,
126     const bool bSynchronous)
127 {
128     sal_Int16 nInvalidateMode (awt::InvalidateStyle::CHILDREN);
129     if (bSynchronous)
130         nInvalidateMode |= awt::InvalidateStyle::UPDATE;
131 
132     PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
133         mpPaneContainer->FindContentWindow(rxWindow));
134     if (pDescriptor.get()==NULL || ! pDescriptor->mbIsOpaque)
135         nInvalidateMode |= awt::InvalidateStyle::TRANSPARENT;
136     else
137         nInvalidateMode |= awt::InvalidateStyle::NOTRANSPARENT;
138 
139     Invalidate(rxWindow, rRepaintBox, nInvalidateMode);
140 }
141 
142 
143 
144 
145 void PresenterPaintManager::Invalidate (
146     const css::uno::Reference<css::awt::XWindow>& rxWindow,
147     const css::awt::Rectangle& rRepaintBox,
148     const sal_Int16 nInvalidateFlags)
149 {
150     if ((nInvalidateFlags & awt::InvalidateStyle::TRANSPARENT) != 0)
151     {
152         // Window is transparent and parent window(s) have to be painted as
153         // well.  Invalidate the parent explicitly.
154         if (mxPresenterHelper.is() && mxParentWindowPeer.is())
155         {
156             const awt::Rectangle aBBox (
157                 mxPresenterHelper->getWindowExtentsRelative(rxWindow, mxParentWindow));
158             mxParentWindowPeer->invalidateRect(
159                 awt::Rectangle(
160                     rRepaintBox.X + aBBox.X,
161                     rRepaintBox.Y + aBBox.Y,
162                     rRepaintBox.Width,
163                     rRepaintBox.Height),
164                 nInvalidateFlags);
165         }
166     }
167     else
168     {
169         Reference<awt::XWindowPeer> xPeer (rxWindow, UNO_QUERY);
170         if (xPeer.is())
171             xPeer->invalidateRect(rRepaintBox, nInvalidateFlags);
172     }
173 }
174 
175 } }
176