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 "framework/Pane.hxx" 27 28 #include <rtl/uuid.h> 29 #include <vcl/svapp.hxx> 30 #include <vos/mutex.hxx> 31 #include <toolkit/helper/vclunohelper.hxx> 32 #include <vcl/window.hxx> 33 #include <cppcanvas/vclfactory.hxx> 34 35 using namespace ::com::sun::star; 36 using namespace ::com::sun::star::uno; 37 using namespace ::com::sun::star::drawing::framework; 38 39 using ::rtl::OUString; 40 41 namespace sd { namespace framework { 42 43 Pane::Pane ( 44 const Reference<XResourceId>& rxPaneId, 45 ::Window* pWindow) 46 throw () 47 : PaneInterfaceBase(MutexOwner::maMutex), 48 mxPaneId(rxPaneId), 49 mpWindow(pWindow), 50 mxWindow(VCLUnoHelper::GetInterface(pWindow)) 51 { 52 } 53 54 55 56 57 Pane::~Pane (void) throw() 58 { 59 } 60 61 62 63 64 void Pane::disposing (void) 65 { 66 mxWindow = NULL; 67 mpWindow = NULL; 68 } 69 70 71 72 73 ::Window* Pane::GetWindow (void) 74 { 75 if (mxWindow.is()) 76 return mpWindow; 77 else 78 return NULL; 79 } 80 81 82 83 84 void Pane::SetWindow (::Window* pWindow) 85 { 86 OSL_TRACE("setting Pane::mpWindow to %x", pWindow); 87 mpWindow = pWindow; 88 mxWindow = VCLUnoHelper::GetInterface(mpWindow); 89 } 90 91 92 93 94 //----- XPane ----------------------------------------------------------------- 95 96 Reference<awt::XWindow> SAL_CALL Pane::getWindow (void) 97 { 98 ThrowIfDisposed(); 99 100 return mxWindow; 101 } 102 103 104 105 106 Reference<rendering::XCanvas> SAL_CALL Pane::getCanvas (void) 107 { 108 ::osl::MutexGuard aGuard (maMutex); 109 ThrowIfDisposed(); 110 111 if ( ! mxCanvas.is()) 112 mxCanvas = CreateCanvas(); 113 114 return mxCanvas; 115 } 116 117 118 119 120 //----- XPane2 ---------------------------------------------------------------- 121 122 sal_Bool SAL_CALL Pane::isVisible (void) 123 { 124 ThrowIfDisposed(); 125 126 const ::Window* pWindow = GetWindow(); 127 if (pWindow != NULL) 128 return pWindow->IsVisible(); 129 else 130 return false; 131 } 132 133 134 135 136 void SAL_CALL Pane::setVisible (sal_Bool bIsVisible) 137 { 138 ThrowIfDisposed(); 139 140 ::Window* pWindow = GetWindow(); 141 if (pWindow != NULL) 142 pWindow->Show(bIsVisible); 143 } 144 145 146 147 148 Reference<accessibility::XAccessible> SAL_CALL Pane::getAccessible (void) 149 { 150 ThrowIfDisposed(); 151 ::Window* pWindow = GetWindow(); 152 if (pWindow != NULL) 153 return pWindow->GetAccessible(sal_False); 154 else 155 return NULL; 156 } 157 158 159 160 161 void SAL_CALL Pane::setAccessible ( 162 const Reference<accessibility::XAccessible>& rxAccessible) 163 { 164 ThrowIfDisposed(); 165 ::Window* pWindow = GetWindow(); 166 if (pWindow != NULL) 167 pWindow->SetAccessible(rxAccessible); 168 } 169 170 171 172 173 //----- XResource ------------------------------------------------------------- 174 175 Reference<XResourceId> SAL_CALL Pane::getResourceId (void) 176 { 177 ThrowIfDisposed(); 178 179 return mxPaneId; 180 } 181 182 183 184 185 sal_Bool SAL_CALL Pane::isAnchorOnly (void) 186 { 187 return true; 188 } 189 190 191 192 193 //----- XUnoTunnel ------------------------------------------------------------ 194 195 const Sequence<sal_Int8>& Pane::getUnoTunnelId (void) 196 { 197 static Sequence<sal_Int8>* pSequence = NULL; 198 if (pSequence == NULL) 199 { 200 const ::vos::OGuard aSolarGuard (Application::GetSolarMutex()); 201 if (pSequence == NULL) 202 { 203 static ::com::sun::star::uno::Sequence<sal_Int8> aSequence (16); 204 rtl_createUuid((sal_uInt8*)aSequence.getArray(), 0, sal_True); 205 pSequence = &aSequence; 206 } 207 } 208 return *pSequence; 209 } 210 211 212 213 214 sal_Int64 SAL_CALL Pane::getSomething (const Sequence<sal_Int8>& rId) 215 { 216 sal_Int64 nResult = 0; 217 218 if (rId.getLength() == 16 219 && rtl_compareMemory(getUnoTunnelId().getConstArray(), rId.getConstArray(), 16) == 0) 220 { 221 nResult = reinterpret_cast<sal_Int64>(this); 222 } 223 224 return nResult; 225 } 226 227 228 229 230 //----------------------------------------------------------------------------- 231 232 Reference<rendering::XCanvas> Pane::CreateCanvas (void) 233 { 234 Reference<rendering::XCanvas> xCanvas; 235 236 if (mpWindow != NULL) 237 { 238 ::cppcanvas::SpriteCanvasSharedPtr pCanvas ( 239 ::cppcanvas::VCLFactory::getInstance().createSpriteCanvas(*mpWindow)); 240 if (pCanvas.get() != NULL) 241 xCanvas = Reference<rendering::XCanvas>(pCanvas->getUNOSpriteCanvas(), UNO_QUERY); 242 } 243 244 return xCanvas; 245 } 246 247 248 249 250 void Pane::ThrowIfDisposed (void) const 251 { 252 if (rBHelper.bDisposed || rBHelper.bInDispose) 253 { 254 throw lang::DisposedException ( 255 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 256 "Pane object has already been disposed")), 257 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this))); 258 } 259 } 260 261 262 } } // end of namespace sd::framework 263