1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <vcl/vclevent.hxx>
22 #include <vcl/wrkwin.hxx>
23 #include <o3tl/string_view.hxx>
24 #include <toolkit/helper/vclunohelper.hxx>
25 #include <com/sun/star/lang/IllegalArgumentException.hpp>
26 #include <com/sun/star/lang/XInitialization.hpp>
27 #include <com/sun/star/util/URL.hpp>
28 #include <com/sun/star/uno/XComponentContext.hpp>
29 #include <strings.hrc>
30 #include <sdresid.hxx>
31 #include <DrawDocShell.hxx>
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::uno
;
35 using namespace ::com::sun::star::drawing::framework
;
37 namespace sd::framework
{
39 FullScreenPane::FullScreenPane (
40 const Reference
<XComponentContext
>& rxComponentContext
,
41 const Reference
<XResourceId
>& rxPaneId
,
42 const vcl::Window
* pViewShellWindow
,
43 const DrawDocShell
* pDrawDocShell
)
44 : FrameWindowPane(rxPaneId
,nullptr),
45 mxComponentContext(rxComponentContext
)
47 sal_Int32 nScreenNumber
= 1;
48 bool bFullScreen
= true;
49 ExtractArguments(rxPaneId
, nScreenNumber
, bFullScreen
);
51 vcl::Window
* pParent
= nullptr;
52 WinBits nStyle
= bFullScreen
? 0 : (WB_BORDER
| WB_MOVEABLE
| WB_SIZEABLE
);
54 mpWorkWindow
.reset(VclPtr
<WorkWindow
>::Create(
56 nStyle
)); // For debugging (non-fullscreen) use WB_BORDER | WB_MOVEABLE | WB_SIZEABLE));
59 throw lang::IllegalArgumentException();
64 // Create a new top-level window that is displayed full screen.
66 mpWorkWindow
->ShowFullScreenMode(bFullScreen
, nScreenNumber
);
68 // For debugging (non-fullscreen) use mpWorkWindow->SetScreenNumber(nScreenNumber);
69 mpWorkWindow
->SetMenuBarMode(MenuBarMode::Hide
);
70 mpWorkWindow
->SetBorderStyle(WindowBorderStyle::REMOVEBORDER
);
71 mpWorkWindow
->SetBackground(Wallpaper());
72 // Don't show the window right now in order to allow the setting of an
73 // accessibility object: accessibility objects are typically
74 // requested by AT-tools when the window is shown. Chaining it
75 // afterwards may or may not work.
77 // Add resize listener at the work window.
78 Link
<VclWindowEvent
&,void> aWindowEventHandler (LINK(this, FullScreenPane
, WindowEventHandler
));
79 mpWorkWindow
->AddEventListener(aWindowEventHandler
);
81 // Set title and icon of the new window to those of the current window
83 if (pViewShellWindow
!= nullptr && pDrawDocShell
!= nullptr)
85 SystemWindow
* pSystemWindow
= pViewShellWindow
->GetSystemWindow();
86 OUString
Title(SdResId(STR_FULLSCREEN_CONSOLE
));
87 Title
= Title
.replaceFirst("%s", pDrawDocShell
->GetTitle(SFX_TITLE_DETECT
));
88 mpWorkWindow
->SetText(Title
);
89 mpWorkWindow
->SetIcon(pSystemWindow
->GetIcon());
92 // For some reason the VCL canvas can not paint into a WorkWindow.
93 // Therefore a child window is created that covers the WorkWindow
95 mpWindow
= VclPtr
<vcl::Window
>::Create(mpWorkWindow
.get());
96 mpWindow
->SetPosSizePixel(Point(0,0), mpWorkWindow
->GetSizePixel());
97 mpWindow
->SetBackground(Wallpaper());
98 mxWindow
= VCLUnoHelper::GetInterface(mpWindow
);
100 // Create the canvas.
101 mxCanvas
= CreateCanvas();
103 mpWindow
->GrabFocus();
106 FullScreenPane::~FullScreenPane() noexcept
110 void SAL_CALL
FullScreenPane::disposing()
112 mpWindow
.disposeAndClear();
116 Link
<VclWindowEvent
&,void> aWindowEventHandler (LINK(this, FullScreenPane
, WindowEventHandler
));
117 mpWorkWindow
->RemoveEventListener(aWindowEventHandler
);
118 mpWorkWindow
.disposeAndClear();
121 FrameWindowPane::disposing();
124 //----- XPane -----------------------------------------------------------------
126 sal_Bool SAL_CALL
FullScreenPane::isVisible()
130 if (mpWindow
!= nullptr)
131 return mpWindow
->IsReallyVisible();
136 void SAL_CALL
FullScreenPane::setVisible (const sal_Bool bIsVisible
)
140 if (mpWindow
!= nullptr)
141 mpWindow
->Show(bIsVisible
);
142 if (mpWorkWindow
!= nullptr)
143 mpWorkWindow
->Show(bIsVisible
);
146 Reference
<css::accessibility::XAccessible
> SAL_CALL
FullScreenPane::getAccessible()
150 if (mpWorkWindow
!= nullptr)
151 return mpWorkWindow
->GetAccessible(false);
156 void SAL_CALL
FullScreenPane::setAccessible (
157 const Reference
<css::accessibility::XAccessible
>& rxAccessible
)
161 if (mpWindow
== nullptr)
164 Reference
<lang::XInitialization
> xInitializable (rxAccessible
, UNO_QUERY
);
165 if (xInitializable
.is())
167 vcl::Window
* pParentWindow
= mpWindow
->GetParent();
168 Reference
<css::accessibility::XAccessible
> xAccessibleParent
;
169 if (pParentWindow
!= nullptr)
170 xAccessibleParent
= pParentWindow
->GetAccessible();
171 Sequence
<Any
> aArguments
{ Any(xAccessibleParent
) };
172 xInitializable
->initialize(aArguments
);
174 GetWindow()->SetAccessible(rxAccessible
);
177 IMPL_LINK(FullScreenPane
, WindowEventHandler
, VclWindowEvent
&, rEvent
, void)
179 switch (rEvent
.GetId())
181 case VclEventId::WindowResize
:
182 GetWindow()->SetPosPixel(Point(0,0));
183 GetWindow()->SetSizePixel(Size(
184 mpWorkWindow
->GetSizePixel().Width(),
185 mpWorkWindow
->GetSizePixel().Height()));
188 case VclEventId::ObjectDying
:
189 mpWorkWindow
.disposeAndClear();
196 Reference
<rendering::XCanvas
> FullScreenPane::CreateCanvas()
198 VclPtr
<vcl::Window
> pWindow
= VCLUnoHelper::GetWindow(mxWindow
);
200 throw RuntimeException();
202 Sequence
<Any
> aArg
{ // common: first any is VCL pointer to window (for VCL canvas)
203 Any(reinterpret_cast<sal_Int64
>(pWindow
.get())),
204 Any(css::awt::Rectangle()),
209 Reference
<lang::XMultiServiceFactory
> xFactory (
210 mxComponentContext
->getServiceManager(), UNO_QUERY_THROW
);
211 return Reference
<rendering::XCanvas
>(
212 xFactory
->createInstanceWithArguments(u
"com.sun.star.rendering.SpriteCanvas.VCL"_ustr
,
217 void FullScreenPane::ExtractArguments (
218 const Reference
<XResourceId
>& rxPaneId
,
219 sal_Int32
& rnScreenNumberReturnValue
,
222 // Extract arguments from the resource URL.
223 const util::URL aURL
= rxPaneId
->getFullResourceURL();
224 for (sal_Int32 nIndex
{ 0 }; nIndex
>= 0; )
226 const std::u16string_view aToken
= o3tl::getToken(aURL
.Arguments
, 0, '&', nIndex
);
227 std::u16string_view sValue
;
228 if (o3tl::starts_with(aToken
, u
"ScreenNumber=", &sValue
))
230 rnScreenNumberReturnValue
= o3tl::toInt32(sValue
);
232 if (o3tl::starts_with(aToken
, u
"FullScreen=", &sValue
))
234 rbFullScreen
= o3tl::equalsAscii(sValue
, "true");
239 } // end of namespace sd::framework
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */