bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / framework / factories / FullScreenPane.cxx
blobb1540bca15e09343b927fbc2b3adbf16eb47509a
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 "FullScreenPane.hxx"
21 #include "ViewShellBase.hxx"
22 #include <cppcanvas/vclfactory.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <vcl/wrkwin.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/dialog.hxx>
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/frame/XLayoutManager.hpp>
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/util/URL.hpp>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::uno;
36 using namespace ::com::sun::star::drawing::framework;
38 namespace sd { namespace framework {
40 FullScreenPane::FullScreenPane (
41 const Reference<XComponentContext>& rxComponentContext,
42 const Reference<XResourceId>& rxPaneId,
43 const vcl::Window* pViewShellWindow)
44 : FrameWindowPane(rxPaneId,NULL),
45 mxComponentContext(rxComponentContext)
47 vcl::Window* pParent = NULL;
48 mpWorkWindow.reset(VclPtr<WorkWindow>::Create(
50 pParent,
51 0)); // For debugging (non-fullscreen) use WB_BORDER | WB_MOVEABLE | WB_SIZEABLE));
53 if ( ! rxPaneId.is())
54 throw lang::IllegalArgumentException();
56 sal_Int32 nScreenNumber = 1;
57 ExtractArguments(rxPaneId, nScreenNumber);
59 if (mpWorkWindow.get() == NULL)
60 return;
62 // Create a new top-leve window that is displayed full screen.
63 mpWorkWindow->ShowFullScreenMode(true, nScreenNumber);
64 // For debugging (non-fullscreen) use mpWorkWindow->SetScreenNumber(nScreenNumber);
65 mpWorkWindow->SetMenuBarMode(MENUBAR_MODE_HIDE);
66 mpWorkWindow->SetBorderStyle(WindowBorderStyle::REMOVEBORDER);
67 mpWorkWindow->SetBackground(Wallpaper());
68 // Don't show the window right now in order to allow the setting of an
69 // accessibility object: accessibility objects are typically
70 // requested by AT-tools when the window is shown. Chaning it
71 // afterwards may or may not work.
73 // Add resize listener at the work window.
74 Link<> aWindowEventHandler (LINK(this, FullScreenPane, WindowEventHandler));
75 mpWorkWindow->AddEventListener(aWindowEventHandler);
77 // Set title and icon of the new window to those of the current window
78 // of the view shell.
79 if (pViewShellWindow != NULL)
81 const SystemWindow* pSystemWindow = pViewShellWindow->GetSystemWindow();
82 mpWorkWindow->SetText(pSystemWindow->GetText());
83 mpWorkWindow->SetIcon(pSystemWindow->GetIcon());
86 // For some reason the VCL canvas can not paint into a WorkWindow.
87 // Therefore a child window is created that covers the WorkWindow
88 // completely.
89 mpWindow = VclPtr<vcl::Window>::Create(mpWorkWindow.get());
90 mpWindow->SetPosSizePixel(Point(0,0), mpWorkWindow->GetSizePixel());
91 mpWindow->SetBackground(Wallpaper());
92 mxWindow = VCLUnoHelper::GetInterface(mpWindow);
94 // Create the canvas.
95 mxCanvas = CreateCanvas();
97 mpWindow->GrabFocus();
100 FullScreenPane::~FullScreenPane() throw()
104 void SAL_CALL FullScreenPane::disposing()
106 mpWindow.disposeAndClear();
108 if (mpWorkWindow.get() != NULL)
110 Link<> aWindowEventHandler (LINK(this, FullScreenPane, WindowEventHandler));
111 mpWorkWindow->RemoveEventListener(aWindowEventHandler);
112 mpWorkWindow.disposeAndClear();
115 FrameWindowPane::disposing();
118 //----- XPane -----------------------------------------------------------------
120 sal_Bool SAL_CALL FullScreenPane::isVisible()
121 throw (RuntimeException, std::exception)
123 ThrowIfDisposed();
125 if (mpWindow != nullptr)
126 return mpWindow->IsReallyVisible();
127 else
128 return false;
131 void SAL_CALL FullScreenPane::setVisible (const sal_Bool bIsVisible)
132 throw (RuntimeException, std::exception)
134 ThrowIfDisposed();
136 if (mpWindow != nullptr)
137 mpWindow->Show(bIsVisible);
138 if (mpWorkWindow != nullptr)
139 mpWorkWindow->Show(bIsVisible);
142 Reference<css::accessibility::XAccessible> SAL_CALL FullScreenPane::getAccessible()
143 throw (RuntimeException, std::exception)
145 ThrowIfDisposed();
147 if (mpWorkWindow != nullptr)
148 return mpWorkWindow->GetAccessible(false);
149 else
150 return NULL;
153 void SAL_CALL FullScreenPane::setAccessible (
154 const Reference<css::accessibility::XAccessible>& rxAccessible)
155 throw (RuntimeException, std::exception)
157 ThrowIfDisposed();
159 if (mpWindow != nullptr)
161 Reference<lang::XInitialization> xInitializable (rxAccessible, UNO_QUERY);
162 if (xInitializable.is())
164 vcl::Window* pParentWindow = mpWindow->GetParent();
165 Reference<css::accessibility::XAccessible> xAccessibleParent;
166 if (pParentWindow != NULL)
167 xAccessibleParent = pParentWindow->GetAccessible();
168 Sequence<Any> aArguments (1);
169 aArguments[0] = Any(xAccessibleParent);
170 xInitializable->initialize(aArguments);
172 GetWindow()->SetAccessible(rxAccessible);
176 IMPL_LINK(FullScreenPane, WindowEventHandler, VclWindowEvent*, pEvent)
178 switch (pEvent->GetId())
180 case VCLEVENT_WINDOW_RESIZE:
181 GetWindow()->SetPosPixel(Point(0,0));
182 GetWindow()->SetSizePixel(Size(
183 mpWorkWindow->GetSizePixel().Width(),
184 mpWorkWindow->GetSizePixel().Height()));
185 break;
187 case VCLEVENT_OBJECT_DYING:
188 mpWorkWindow.disposeAndClear();
189 break;
191 return 1;
194 Reference<rendering::XCanvas> FullScreenPane::CreateCanvas()
195 throw (RuntimeException)
197 vcl::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
198 if (pWindow != NULL)
200 Sequence<Any> aArg (5);
202 // common: first any is VCL pointer to window (for VCL canvas)
203 aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow));
204 aArg[1] = Any();
205 aArg[2] = makeAny(::com::sun::star::awt::Rectangle());
206 aArg[3] = makeAny(sal_False);
207 aArg[4] = makeAny(mxWindow);
209 Reference<lang::XMultiServiceFactory> xFactory (
210 mxComponentContext->getServiceManager(), UNO_QUERY_THROW);
211 return Reference<rendering::XCanvas>(
212 xFactory->createInstanceWithArguments("com.sun.star.rendering.SpriteCanvas.VCL",
213 aArg),
214 UNO_QUERY);
216 else
217 throw RuntimeException();
220 void FullScreenPane::ExtractArguments (
221 const Reference<XResourceId>& rxPaneId,
222 sal_Int32& rnScreenNumberReturnValue)
224 // Extract arguments from the resource URL.
225 const util::URL aURL = rxPaneId->getFullResourceURL();
226 sal_Int32 nIndex = 0;
227 while (nIndex >= 0)
229 const OUString aToken = aURL.Arguments.getToken(0, '&', nIndex);
230 if (!aToken.isEmpty())
232 // Split at the first '='.
233 const sal_Int32 nAssign = aToken.indexOf('=');
234 const OUString sKey = aToken.copy(0, nAssign);
235 const OUString sValue = aToken.copy(nAssign+1);
237 if (sKey == "ScreenNumber")
239 rnScreenNumberReturnValue = sValue.toInt32();
245 } } // end of namespace sd::framework
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */