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