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 { 137 ThrowIfDisposed(); 138 139 if (mpWindow != NULL) 140 return mpWindow->IsReallyVisible(); 141 else 142 return false; 143 } 144 145 146 void SAL_CALL FullScreenPane::setVisible (const sal_Bool bIsVisible) 147 { 148 ThrowIfDisposed(); 149 150 if (mpWindow != NULL) 151 mpWindow->Show(bIsVisible); 152 if( bool(mpWorkWindow)) 153 mpWorkWindow->Show(bIsVisible); 154 } 155 156 157 Reference<accessibility::XAccessible> SAL_CALL FullScreenPane::getAccessible (void) 158 { 159 ThrowIfDisposed(); 160 161 if( bool(mpWorkWindow)) 162 return mpWorkWindow->GetAccessible(sal_False); 163 else 164 return NULL; 165 } 166 167 168 void SAL_CALL FullScreenPane::setAccessible ( 169 const Reference<accessibility::XAccessible>& rxAccessible) 170 { 171 ThrowIfDisposed(); 172 173 if (mpWindow != NULL) 174 { 175 Reference<lang::XInitialization> xInitializable (rxAccessible, UNO_QUERY); 176 if (xInitializable.is()) 177 { 178 ::Window* pParentWindow = mpWindow->GetParent(); 179 Reference<accessibility::XAccessible> xAccessibleParent; 180 if (pParentWindow != NULL) 181 xAccessibleParent = pParentWindow->GetAccessible(); 182 Sequence<Any> aArguments (1); 183 aArguments[0] = Any(xAccessibleParent); 184 xInitializable->initialize(aArguments); 185 } 186 GetWindow()->SetAccessible(rxAccessible); 187 } 188 } 189 190 191 //----------------------------------------------------------------------------- 192 193 IMPL_LINK(FullScreenPane, WindowEventHandler, VclWindowEvent*, pEvent) 194 { 195 switch (pEvent->GetId()) 196 { 197 case VCLEVENT_WINDOW_RESIZE: 198 GetWindow()->SetPosPixel(Point(0,0)); 199 GetWindow()->SetSizePixel(Size( 200 mpWorkWindow->GetSizePixel().Width(), 201 mpWorkWindow->GetSizePixel().Height())); 202 break; 203 204 case VCLEVENT_OBJECT_DYING: 205 mpWorkWindow.reset(); 206 break; 207 } 208 return 1; 209 } 210 211 212 Reference<rendering::XCanvas> FullScreenPane::CreateCanvas (void) 213 { 214 ::Window* pWindow = VCLUnoHelper::GetWindow(mxWindow); 215 if (pWindow != NULL) 216 { 217 Sequence<Any> aArg (5); 218 219 // common: first any is VCL pointer to window (for VCL canvas) 220 aArg[0] = makeAny(reinterpret_cast<sal_Int64>(pWindow)); 221 aArg[1] = Any(); 222 aArg[2] = makeAny(::com::sun::star::awt::Rectangle()); 223 aArg[3] = makeAny(sal_False); 224 aArg[4] = makeAny(mxWindow); 225 226 Reference<lang::XMultiServiceFactory> xFactory ( 227 mxComponentContext->getServiceManager(), UNO_QUERY_THROW); 228 return Reference<rendering::XCanvas>( 229 xFactory->createInstanceWithArguments( 230 OUString::createFromAscii("com.sun.star.rendering.SpriteCanvas.VCL"), 231 aArg), 232 UNO_QUERY); 233 } 234 else 235 throw RuntimeException(); 236 } 237 238 239 void FullScreenPane::ExtractArguments ( 240 const Reference<XResourceId>& rxPaneId, 241 sal_Int32& rnScreenNumberReturnValue) 242 { 243 // Extract arguments from the resource URL. 244 const util::URL aURL = rxPaneId->getFullResourceURL(); 245 sal_Int32 nIndex = 0; 246 while (nIndex >= 0) 247 { 248 const OUString aToken = aURL.Arguments.getToken(0, '&', nIndex); 249 if (aToken.getLength() > 0) 250 { 251 // Split at the first '='. 252 const sal_Int32 nAssign = aToken.indexOf('='); 253 const OUString sKey = aToken.copy(0, nAssign); 254 const OUString sValue = aToken.copy(nAssign+1); 255 256 if (sKey.compareToAscii("ScreenNumber") == 0) 257 { 258 rnScreenNumberReturnValue = sValue.toInt32(); 259 } 260 } 261 } 262 } 263 264 } } // end of namespace sd::framework 265 266 /* vim: set noet sw=4 ts=4: */ 267