1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterHelper.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "PresenterHelper.hxx"
35 #include "CanvasUpdateRequester.hxx"
36 #include "PresenterCanvas.hxx"
37 #include <cppcanvas/vclfactory.hxx>
38 #include <com/sun/star/awt/WindowAttribute.hpp>
39 #include <com/sun/star/awt/WindowClass.hpp>
40 #include <com/sun/star/awt/WindowDescriptor.hpp>
41 #include <osl/file.hxx>
42 #include <toolkit/helper/vclunohelper.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vcl/window.hxx>
45 #include <vcl/wrkwin.hxx>
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::uno
;
49 using ::rtl::OUString
;
51 namespace sd
{ namespace presenter
{
53 //===== Service ===============================================================
55 Reference
<XInterface
> SAL_CALL
PresenterHelperService_createInstance (
56 const Reference
<XComponentContext
>& rxContext
)
58 return Reference
<XInterface
>(static_cast<XWeak
*>(new PresenterHelper(rxContext
)));
64 ::rtl::OUString
PresenterHelperService_getImplementationName (void)
65 throw(RuntimeException
)
67 return OUString::createFromAscii("com.sun.star.comp.Draw.PresenterHelper");
73 Sequence
<rtl::OUString
> SAL_CALL
PresenterHelperService_getSupportedServiceNames (void)
74 throw (RuntimeException
)
76 static const ::rtl::OUString
sServiceName(
77 ::rtl::OUString::createFromAscii("com.sun.star.drawing.PresenterHelper"));
78 return Sequence
<rtl::OUString
>(&sServiceName
, 1);
84 //===== PresenterHelper =======================================================
86 PresenterHelper::PresenterHelper (
87 const Reference
<XComponentContext
>& rxContext
)
88 : PresenterHelperInterfaceBase(m_aMutex
),
89 mxComponentContext(rxContext
)
95 PresenterHelper::~PresenterHelper (void)
102 //----- XInitialize -----------------------------------------------------------
104 void SAL_CALL
PresenterHelper::initialize (const Sequence
<Any
>& rArguments
)
105 throw(Exception
,RuntimeException
)
113 //----- XPaneHelper ----------------------------------------------------
115 Reference
<awt::XWindow
> SAL_CALL
PresenterHelper::createWindow (
116 const Reference
<awt::XWindow
>& rxParentWindow
,
117 sal_Bool bCreateSystemChildWindow
,
118 sal_Bool bInitiallyVisible
,
119 sal_Bool bEnableChildTransparentMode
,
120 sal_Bool bEnableParentClip
)
121 throw (css::uno::RuntimeException
)
123 ::Window
* pParentWindow
= VCLUnoHelper::GetWindow(rxParentWindow
);
125 // Create a new window.
126 ::Window
* pWindow
= NULL
;
127 if (bCreateSystemChildWindow
)
129 pWindow
= new WorkWindow(pParentWindow
, WB_SYSTEMCHILDWINDOW
);
133 pWindow
= new ::Window(pParentWindow
);
135 Reference
<awt::XWindow
> xWindow (pWindow
->GetComponentInterface(), UNO_QUERY
);
137 if (bEnableChildTransparentMode
)
139 // Make the frame window transparent and make the parent able to
141 if (pParentWindow
!= NULL
)
142 pParentWindow
->EnableChildTransparentMode(TRUE
);
147 pWindow
->Show(bInitiallyVisible
);
149 pWindow
->SetMapMode(MAP_PIXEL
);
150 pWindow
->SetBackground();
151 if ( ! bEnableParentClip
)
153 pWindow
->SetParentClipMode(PARENTCLIPMODE_NOCLIP
);
154 pWindow
->SetPaintTransparent(TRUE
);
158 pWindow
->SetParentClipMode(PARENTCLIPMODE_CLIP
);
159 pWindow
->SetPaintTransparent(FALSE
);
170 Reference
<rendering::XCanvas
> SAL_CALL
PresenterHelper::createSharedCanvas (
171 const Reference
<rendering::XSpriteCanvas
>& rxUpdateCanvas
,
172 const Reference
<awt::XWindow
>& rxUpdateWindow
,
173 const Reference
<rendering::XCanvas
>& rxSharedCanvas
,
174 const Reference
<awt::XWindow
>& rxSharedWindow
,
175 const Reference
<awt::XWindow
>& rxWindow
)
176 throw (css::uno::RuntimeException
)
178 if ( ! rxSharedCanvas
.is()
179 || ! rxSharedWindow
.is()
182 throw RuntimeException(
183 OUString::createFromAscii("illegal argument"),
184 Reference
<XInterface
>(static_cast<XWeak
*>(this)));
187 if (rxWindow
== rxSharedWindow
)
188 return rxSharedCanvas
;
190 return new PresenterCanvas(
201 Reference
<rendering::XCanvas
> SAL_CALL
PresenterHelper::createCanvas (
202 const Reference
<awt::XWindow
>& rxWindow
,
203 sal_Int16 nRequestedCanvasFeatures
,
204 const OUString
& rsOptionalCanvasServiceName
)
205 throw (css::uno::RuntimeException
)
207 (void)nRequestedCanvasFeatures
;
209 // No shared window is given or an explicit canvas service name is
210 // specified. Create a new canvas.
211 ::Window
* pWindow
= VCLUnoHelper::GetWindow(rxWindow
);
214 Sequence
<Any
> aArg (5);
216 // common: first any is VCL pointer to window (for VCL canvas)
217 aArg
[0] = makeAny(reinterpret_cast<sal_Int64
>(pWindow
));
219 aArg
[2] = makeAny(::com::sun::star::awt::Rectangle());
220 aArg
[3] = makeAny(sal_False
);
221 aArg
[4] = makeAny(rxWindow
);
223 Reference
<lang::XMultiServiceFactory
> xFactory (
224 mxComponentContext
->getServiceManager(), UNO_QUERY_THROW
);
225 return Reference
<rendering::XCanvas
>(
226 xFactory
->createInstanceWithArguments(
227 rsOptionalCanvasServiceName
.getLength()>0
228 ? rsOptionalCanvasServiceName
229 : OUString::createFromAscii("com.sun.star.rendering.VCLCanvas"),
234 throw RuntimeException();
240 void SAL_CALL
PresenterHelper::toTop (
241 const Reference
<awt::XWindow
>& rxWindow
)
242 throw (css::uno::RuntimeException
)
244 ::Window
* pWindow
= VCLUnoHelper::GetWindow(rxWindow
);
248 pWindow
->SetZOrder(NULL
, WINDOW_ZORDER_LAST
);
255 Reference
<rendering::XBitmap
> SAL_CALL
PresenterHelper::loadBitmap (
256 const OUString
& rsURL
,
257 const Reference
<rendering::XCanvas
>& rxCanvas
)
258 throw (RuntimeException
)
260 if ( ! rxCanvas
.is())
263 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
265 if (mpGraphicFilter
.get() == NULL
)
266 mpGraphicFilter
.reset(new GraphicFilter(sal_False
));
268 const cppcanvas::CanvasSharedPtr
pCanvas (
269 cppcanvas::VCLFactory::getInstance().createCanvas(
270 Reference
<css::rendering::XBitmapCanvas
>(rxCanvas
,UNO_QUERY
)));
272 if (pCanvas
.get()!=NULL
&& rsURL
.getLength()>0 && mpGraphicFilter
.get()!=NULL
)
276 if (osl::FileBase::getSystemPathFromFileURL(rsURL
, sFileName
)
277 == osl::FileBase::E_None
)
279 if (mpGraphicFilter
->ImportGraphic(aGraphic
, rsURL
) == GRFILTER_OK
)
281 BitmapEx
aBitmapEx (aGraphic
.GetBitmapEx());
282 return cppcanvas::VCLFactory::getInstance().createBitmap(
284 aBitmapEx
)->getUNOBitmap();
296 void SAL_CALL
PresenterHelper::captureMouse (
297 const Reference
<awt::XWindow
>& rxWindow
)
298 throw (RuntimeException
)
300 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
302 // Capture the mouse (if not already done.)
303 ::Window
* pWindow
= VCLUnoHelper::GetWindow(rxWindow
);
304 if (pWindow
!= NULL
&& ! pWindow
->IsMouseCaptured())
306 pWindow
->CaptureMouse();
313 void SAL_CALL
PresenterHelper::releaseMouse (const Reference
<awt::XWindow
>& rxWindow
)
314 throw (RuntimeException
)
316 ::osl::MutexGuard
aGuard (::osl::Mutex::getGlobalMutex());
318 // Release the mouse (if not already done.)
319 ::Window
* pWindow
= VCLUnoHelper::GetWindow(rxWindow
);
320 if (pWindow
!= NULL
&& pWindow
->IsMouseCaptured())
322 pWindow
->ReleaseMouse();
329 awt::Rectangle
PresenterHelper::getWindowExtentsRelative (
330 const Reference
<awt::XWindow
>& rxChildWindow
,
331 const Reference
<awt::XWindow
>& rxParentWindow
)
332 throw (RuntimeException
)
334 ::Window
* pChildWindow
= VCLUnoHelper::GetWindow(rxChildWindow
);
335 ::Window
* pParentWindow
= VCLUnoHelper::GetWindow(rxParentWindow
);
336 if (pChildWindow
!=NULL
&& pParentWindow
!=NULL
)
338 Rectangle
aBox (pChildWindow
->GetWindowExtentsRelative(pParentWindow
));
339 return awt::Rectangle(aBox
.Left(),aBox
.Top(),aBox
.GetWidth(),aBox
.GetHeight());
342 return awt::Rectangle();
347 } } // end of namespace ::sd::presenter