Update ooo320-m1
[ooovba.git] / sd / source / ui / framework / factories / FullScreenPane.cxx
blob65c83903d4e95ec3d1fe413f5b35b310b306d434
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FullScreenPane.cxx,v $
11 * $Revision: 1.4 $
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 "FullScreenPane.hxx"
35 #include "ViewShellBase.hxx"
36 #include <cppcanvas/vclfactory.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <sfx2/topfrm.hxx>
39 #include <vcl/svapp.hxx>
40 #include <vcl/dialog.hxx>
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/frame/XLayoutManager.hpp>
44 #include <com/sun/star/lang/IllegalArgumentException.hpp>
45 #include <com/sun/star/lang/XInitialization.hpp>
46 #include <com/sun/star/util/URL.hpp>
48 using namespace ::com::sun::star;
49 using namespace ::com::sun::star::uno;
50 using namespace ::com::sun::star::drawing::framework;
51 using ::rtl::OUString;
53 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
55 namespace sd { namespace framework {
57 FullScreenPane::FullScreenPane (
58 const Reference<XComponentContext>& rxComponentContext,
59 const Reference<XResourceId>& rxPaneId,
60 const ::Window* pViewShellWindow)
61 : FrameWindowPane(rxPaneId,NULL),
62 mxComponentContext(rxComponentContext),
63 mpWorkWindow(NULL)
65 ::Window* pParent = NULL;
66 mpWorkWindow.reset(new WorkWindow(
67 pParent,
68 0)); // For debugging (non-fullscreen) use WB_BORDER | WB_MOVEABLE | WB_SIZEABLE));
70 if ( ! rxPaneId.is())
71 throw lang::IllegalArgumentException();
73 sal_Int32 nScreenNumber = 1;
74 ExtractArguments(rxPaneId, nScreenNumber);
76 if (mpWorkWindow.get() == NULL)
77 return;
79 // Create a new top-leve window that is displayed full screen.
80 mpWorkWindow->ShowFullScreenMode(TRUE, nScreenNumber);
81 // For debugging (non-fullscreen) use mpWorkWindow->SetScreenNumber(nScreenNumber);
82 mpWorkWindow->SetMenuBarMode(MENUBAR_MODE_HIDE);
83 mpWorkWindow->SetBorderStyle(WINDOW_BORDER_REMOVEBORDER);
84 mpWorkWindow->SetBackground(Wallpaper());
85 // Don't show the window right now in order to allow the setting of an
86 // accessibility object: accessibility objects are typically
87 // requested by AT-tools when the window is shown. Chaning it
88 // afterwards may or may not work.
90 // Add resize listener at the work window.
91 Link aWindowEventHandler (LINK(this, FullScreenPane, WindowEventHandler));
92 mpWorkWindow->AddEventListener(aWindowEventHandler);
94 // Set title and icon of the new window to those of the current window
95 // of the view shell.
96 if (pViewShellWindow != NULL)
98 const SystemWindow* pSystemWindow = pViewShellWindow->GetSystemWindow();
99 mpWorkWindow->SetText(pSystemWindow->GetText());
100 mpWorkWindow->SetIcon(pSystemWindow->GetIcon());
103 // For some reason the VCL canvas can not paint into a WorkWindow.
104 // Therefore a child window is created that covers the WorkWindow
105 // completely.
106 mpWindow = new ::Window(mpWorkWindow.get());
107 mpWindow->SetPosSizePixel(Point(0,0), mpWorkWindow->GetSizePixel());
108 mpWindow->SetBackground(Wallpaper());
109 mxWindow = VCLUnoHelper::GetInterface(mpWindow);
111 // Create the canvas.
112 mxCanvas = CreateCanvas();
114 mpWindow->GrabFocus();
120 FullScreenPane::~FullScreenPane (void) throw()
127 void SAL_CALL FullScreenPane::disposing (void)
129 // We have created the window pointed to by mpWindow, we delete it.
130 if (mpWindow != NULL)
132 delete mpWindow;
135 if (mpWorkWindow.get() != NULL)
137 Link aWindowEventHandler (LINK(this, FullScreenPane, WindowEventHandler));
138 mpWorkWindow->RemoveEventListener(aWindowEventHandler);
139 mpWorkWindow.reset();
143 FrameWindowPane::disposing();
149 //----- XPane -----------------------------------------------------------------
151 sal_Bool SAL_CALL FullScreenPane::isVisible (void)
152 throw (RuntimeException)
154 ThrowIfDisposed();
156 if (mpWindow != NULL)
157 return mpWindow->IsReallyVisible();
158 else
159 return false;
165 void SAL_CALL FullScreenPane::setVisible (const sal_Bool bIsVisible)
166 throw (RuntimeException)
168 ThrowIfDisposed();
170 if (mpWindow != NULL)
171 mpWindow->Show(bIsVisible);
172 if (mpWorkWindow != NULL)
173 mpWorkWindow->Show(bIsVisible);
179 Reference<accessibility::XAccessible> SAL_CALL FullScreenPane::getAccessible (void)
180 throw (RuntimeException)
182 ThrowIfDisposed();
184 if (mpWorkWindow != NULL)
185 return mpWorkWindow->GetAccessible(FALSE);
186 else
187 return NULL;
193 void SAL_CALL FullScreenPane::setAccessible (
194 const Reference<accessibility::XAccessible>& rxAccessible)
195 throw (RuntimeException)
197 ThrowIfDisposed();
199 if (mpWindow != NULL)
201 Reference<lang::XInitialization> xInitializable (rxAccessible, UNO_QUERY);
202 if (xInitializable.is())
204 ::Window* pParentWindow = mpWindow->GetParent();
205 Reference<accessibility::XAccessible> xAccessibleParent;
206 if (pParentWindow != NULL)
207 xAccessibleParent = pParentWindow->GetAccessible();
208 Sequence<Any> aArguments (1);
209 aArguments[0] = Any(xAccessibleParent);
210 xInitializable->initialize(aArguments);
212 GetWindow()->SetAccessible(rxAccessible);
219 //-----------------------------------------------------------------------------
221 IMPL_LINK(FullScreenPane, WindowEventHandler, VclWindowEvent*, pEvent)
223 switch (pEvent->GetId())
225 case VCLEVENT_WINDOW_RESIZE:
226 GetWindow()->SetPosPixel(Point(0,0));
227 GetWindow()->SetSizePixel(Size(
228 mpWorkWindow->GetSizePixel().Width(),
229 mpWorkWindow->GetSizePixel().Height()));
230 break;
232 case VCLEVENT_OBJECT_DYING:
233 mpWorkWindow.reset();
234 break;
236 return 1;
242 Reference<rendering::XCanvas> FullScreenPane::CreateCanvas (void)
243 throw (RuntimeException)
245 ::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
246 if (pWindow != NULL)
248 Sequence<Any> aArg (5);
250 // common: first any is VCL pointer to window (for VCL canvas)
251 aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow));
252 aArg[1] = Any();
253 aArg[2] = makeAny(::com::sun::star::awt::Rectangle());
254 aArg[3] = makeAny(sal_False);
255 aArg[4] = makeAny(mxWindow);
257 Reference<lang::XMultiServiceFactory> xFactory (
258 mxComponentContext->getServiceManager(), UNO_QUERY_THROW);
259 return Reference<rendering::XCanvas>(
260 xFactory->createInstanceWithArguments(
261 OUString::createFromAscii("com.sun.star.rendering.SpriteCanvas.VCL"),
262 aArg),
263 UNO_QUERY);
265 else
266 throw RuntimeException();
272 void FullScreenPane::ExtractArguments (
273 const Reference<XResourceId>& rxPaneId,
274 sal_Int32& rnScreenNumberReturnValue)
276 // Extract arguments from the resource URL.
277 const util::URL aURL = rxPaneId->getFullResourceURL();
278 sal_Int32 nIndex = 0;
279 while (nIndex >= 0)
281 const OUString aToken = aURL.Arguments.getToken(0, '&', nIndex);
282 if (aToken.getLength() > 0)
284 // Split at the first '='.
285 const sal_Int32 nAssign = aToken.indexOf('=');
286 const OUString sKey = aToken.copy(0, nAssign);
287 const OUString sValue = aToken.copy(nAssign+1);
289 if (sKey.compareToAscii("ScreenNumber") == 0)
291 rnScreenNumberReturnValue = sValue.toInt32();
298 } } // end of namespace sd::framework