xref: /trunk/main/sd/source/ui/framework/factories/FullScreenPane.cxx (revision 31bbceb0f9d64c0c2c3b22a794a1666c1f33396e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sd.hxx"
23 
24 #include "FullScreenPane.hxx"
25 #include "ViewShellBase.hxx"
26 #include <cppcanvas/vclfactory.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <vcl/wrkwin.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/dialog.hxx>
31 #include <toolkit/helper/vclunohelper.hxx>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/frame/XLayoutManager.hpp>
34 #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <com/sun/star/util/URL.hpp>
37 
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using namespace ::com::sun::star::drawing::framework;
41 using ::rtl::OUString;
42 
43 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
44 
45 namespace sd { namespace framework {
46 
47 FullScreenPane::FullScreenPane (
48     const Reference<XComponentContext>& rxComponentContext,
49     const Reference<XResourceId>& rxPaneId,
50     const ::Window* pViewShellWindow)
51     :FrameWindowPane(rxPaneId,NULL),
52      mxComponentContext(rxComponentContext),
53      mpWorkWindow(NULL)
54 {
55     ::Window* pParent = NULL;
56     mpWorkWindow.reset(new WorkWindow(
57         pParent,
58         0)); // For debugging (non-fullscreen) use WB_BORDER | WB_MOVEABLE | WB_SIZEABLE));
59 
60     if ( ! rxPaneId.is())
61         throw lang::IllegalArgumentException();
62 
63     sal_Int32 nScreenNumber = 1;
64     ExtractArguments(rxPaneId, nScreenNumber);
65 
66     if (mpWorkWindow.get() == NULL)
67         return;
68 
69     // Create a new top-level window that is displayed full screen.
70     mpWorkWindow->ShowFullScreenMode(sal_True, nScreenNumber);
71     // For debugging (non-fullscreen) use mpWorkWindow->SetScreenNumber(nScreenNumber);
72     mpWorkWindow->SetMenuBarMode(MENUBAR_MODE_HIDE);
73     mpWorkWindow->SetBorderStyle(WINDOW_BORDER_REMOVEBORDER);
74     mpWorkWindow->SetBackground(Wallpaper());
75     // Don't show the window right now in order to allow the setting of an
76     // accessibility object: accessibility objects are typically
77     // requested by AT-tools when the window is shown. Changing it
78     // afterwards may or may not work.
79 
80     // Add resize listener at the work window.
81     Link aWindowEventHandler (LINK(this, FullScreenPane, WindowEventHandler));
82     mpWorkWindow->AddEventListener(aWindowEventHandler);
83 
84     // Set title and icon of the new window to those of the current window
85     // of the view shell.
86     if (pViewShellWindow != NULL)
87     {
88         const SystemWindow* pSystemWindow = pViewShellWindow->GetSystemWindow();
89         mpWorkWindow->SetText(pSystemWindow->GetText());
90         mpWorkWindow->SetIcon(pSystemWindow->GetIcon());
91     }
92 
93     // For some reason the VCL canvas can not paint into a WorkWindow.
94     // Therefore a child window is created that covers the WorkWindow
95     // completely.
96     mpWindow = new ::Window(mpWorkWindow.get());
97     mpWindow->SetPosSizePixel(Point(0,0), mpWorkWindow->GetSizePixel());
98     mpWindow->SetBackground(Wallpaper());
99     mxWindow = VCLUnoHelper::GetInterface(mpWindow);
100 
101     // Create the canvas.
102     mxCanvas = CreateCanvas();
103 
104     mpWindow->GrabFocus();
105 }
106 
107 
108 FullScreenPane::~FullScreenPane (void) throw()
109 {
110 }
111 
112 
113 void SAL_CALL FullScreenPane::disposing (void)
114 {
115     // We have created the window pointed to by mpWindow, we delete it.
116     if (mpWindow != NULL)
117     {
118         delete mpWindow;
119     }
120 
121     if (mpWorkWindow.get() != NULL)
122     {
123         Link aWindowEventHandler (LINK(this, FullScreenPane, WindowEventHandler));
124         mpWorkWindow->RemoveEventListener(aWindowEventHandler);
125         mpWorkWindow.reset();
126     }
127 
128 
129     FrameWindowPane::disposing();
130 }
131 
132 
133 //----- XPane -----------------------------------------------------------------
134 
135 sal_Bool SAL_CALL FullScreenPane::isVisible (void)
136     throw (RuntimeException)
137 {
138     ThrowIfDisposed();
139 
140     if (mpWindow != NULL)
141         return mpWindow->IsReallyVisible();
142     else
143         return false;
144 }
145 
146 
147 void SAL_CALL FullScreenPane::setVisible (const sal_Bool bIsVisible)
148     throw (RuntimeException)
149 {
150     ThrowIfDisposed();
151 
152     if (mpWindow != NULL)
153         mpWindow->Show(bIsVisible);
154     if( bool(mpWorkWindow))
155         mpWorkWindow->Show(bIsVisible);
156 }
157 
158 
159 Reference<accessibility::XAccessible> SAL_CALL FullScreenPane::getAccessible (void)
160     throw (RuntimeException)
161 {
162     ThrowIfDisposed();
163 
164     if( bool(mpWorkWindow))
165         return mpWorkWindow->GetAccessible(sal_False);
166     else
167         return NULL;
168 }
169 
170 
171 void SAL_CALL FullScreenPane::setAccessible (
172     const Reference<accessibility::XAccessible>& rxAccessible)
173     throw (RuntimeException)
174 {
175     ThrowIfDisposed();
176 
177     if (mpWindow != NULL)
178     {
179         Reference<lang::XInitialization> xInitializable (rxAccessible, UNO_QUERY);
180         if (xInitializable.is())
181         {
182             ::Window* pParentWindow = mpWindow->GetParent();
183             Reference<accessibility::XAccessible> xAccessibleParent;
184             if (pParentWindow != NULL)
185                 xAccessibleParent = pParentWindow->GetAccessible();
186             Sequence<Any> aArguments (1);
187             aArguments[0] = Any(xAccessibleParent);
188             xInitializable->initialize(aArguments);
189         }
190         GetWindow()->SetAccessible(rxAccessible);
191     }
192 }
193 
194 
195 //-----------------------------------------------------------------------------
196 
197 IMPL_LINK(FullScreenPane, WindowEventHandler, VclWindowEvent*, pEvent)
198 {
199     switch (pEvent->GetId())
200     {
201         case VCLEVENT_WINDOW_RESIZE:
202             GetWindow()->SetPosPixel(Point(0,0));
203             GetWindow()->SetSizePixel(Size(
204                 mpWorkWindow->GetSizePixel().Width(),
205                 mpWorkWindow->GetSizePixel().Height()));
206             break;
207 
208         case VCLEVENT_OBJECT_DYING:
209             mpWorkWindow.reset();
210             break;
211     }
212     return 1;
213 }
214 
215 
216 Reference<rendering::XCanvas> FullScreenPane::CreateCanvas (void)
217     throw (RuntimeException)
218 {
219     ::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow);
220     if (pWindow != NULL)
221     {
222         Sequence<Any> aArg (5);
223 
224         // common: first any is VCL pointer to window (for VCL canvas)
225         aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow));
226         aArg[1] = Any();
227         aArg[2] = makeAny(::com::sun::star::awt::Rectangle());
228         aArg[3] = makeAny(sal_False);
229         aArg[4] = makeAny(mxWindow);
230 
231         Reference<lang::XMultiServiceFactory> xFactory (
232             mxComponentContext->getServiceManager(), UNO_QUERY_THROW);
233         return Reference<rendering::XCanvas>(
234             xFactory->createInstanceWithArguments(
235                 OUString::createFromAscii("com.sun.star.rendering.SpriteCanvas.VCL"),
236                 aArg),
237             UNO_QUERY);
238     }
239     else
240         throw RuntimeException();
241 }
242 
243 
244 void FullScreenPane::ExtractArguments (
245     const Reference<XResourceId>& rxPaneId,
246     sal_Int32& rnScreenNumberReturnValue)
247 {
248     // Extract arguments from the resource URL.
249     const util::URL aURL = rxPaneId->getFullResourceURL();
250     sal_Int32 nIndex = 0;
251     while (nIndex >= 0)
252     {
253         const OUString aToken = aURL.Arguments.getToken(0, '&', nIndex);
254         if (aToken.getLength() > 0)
255         {
256             // Split at the first '='.
257             const sal_Int32 nAssign = aToken.indexOf('=');
258             const OUString sKey = aToken.copy(0, nAssign);
259             const OUString sValue = aToken.copy(nAssign+1);
260 
261             if (sKey.compareToAscii("ScreenNumber") == 0)
262             {
263                 rnScreenNumberReturnValue = sValue.toInt32();
264             }
265         }
266     }
267 }
268 
269 } } // end of namespace sd::framework
270 
271 /* vim: set noet sw=4 ts=4: */
272