1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_sd.hxx" 29 30 #include "BasicToolBarFactory.hxx" 31 32 #include "ViewTabBar.hxx" 33 #include "framework/FrameworkHelper.hxx" 34 #include <comphelper/mediadescriptor.hxx> 35 36 #include <com/sun/star/lang/IllegalArgumentException.hpp> 37 #include "DrawController.hxx" 38 39 using namespace ::com::sun::star; 40 using namespace ::com::sun::star::uno; 41 using namespace ::com::sun::star::lang; 42 using namespace ::com::sun::star::drawing::framework; 43 44 namespace sd { namespace framework { 45 46 47 Reference<XInterface> SAL_CALL BasicToolBarFactory_createInstance ( 48 const Reference<XComponentContext>& rxContext) 49 { 50 return static_cast<XWeak*>(new BasicToolBarFactory(rxContext)); 51 } 52 53 54 55 56 ::rtl::OUString BasicToolBarFactory_getImplementationName (void) throw(RuntimeException) 57 { 58 return ::rtl::OUString( 59 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Draw.framework.BasicToolBarFactory")); 60 } 61 62 63 64 65 Sequence<rtl::OUString> SAL_CALL BasicToolBarFactory_getSupportedServiceNames (void) 66 throw (RuntimeException) 67 { 68 static const ::rtl::OUString sServiceName( 69 ::rtl::OUString::createFromAscii("com.sun.star.drawing.framework.BasicToolBarFactory")); 70 return Sequence<rtl::OUString>(&sServiceName, 1); 71 } 72 73 74 75 76 77 //===== BasicToolBarFactory =================================================== 78 79 BasicToolBarFactory::BasicToolBarFactory ( 80 const Reference<XComponentContext>& rxContext) 81 : BasicToolBarFactoryInterfaceBase(m_aMutex), 82 mxConfigurationController(), 83 mxController(), 84 mpViewShellBase(NULL) 85 { 86 (void)rxContext; 87 } 88 89 90 91 92 BasicToolBarFactory::~BasicToolBarFactory (void) 93 { 94 } 95 96 97 98 99 void SAL_CALL BasicToolBarFactory::disposing (void) 100 { 101 Shutdown(); 102 } 103 104 105 106 107 void BasicToolBarFactory::Shutdown (void) 108 { 109 mpViewShellBase = NULL; 110 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY); 111 if (xComponent.is()) 112 xComponent->removeEventListener(static_cast<lang::XEventListener*>(this)); 113 if (mxConfigurationController.is()) 114 { 115 mxConfigurationController->removeResourceFactoryForReference(this); 116 mxConfigurationController = NULL; 117 } 118 } 119 120 121 122 123 //----- XInitialization ------------------------------------------------------- 124 125 void SAL_CALL BasicToolBarFactory::initialize (const Sequence<Any>& aArguments) 126 throw (Exception, RuntimeException) 127 { 128 if (aArguments.getLength() > 0) 129 { 130 try 131 { 132 // Get the XController from the first argument. 133 mxController = Reference<frame::XController>(aArguments[0], UNO_QUERY_THROW); 134 135 // Tunnel through the controller to obtain a ViewShellBase. 136 Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW); 137 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( 138 xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); 139 if (pController != NULL) 140 mpViewShellBase = pController->GetViewShellBase(); 141 142 ::comphelper::MediaDescriptor aDescriptor (mxController->getModel()->getArgs()); 143 if ( ! aDescriptor.getUnpackedValueOrDefault( 144 ::comphelper::MediaDescriptor::PROP_PREVIEW(), 145 sal_False)) 146 { 147 // Register the factory for its supported tool bars. 148 Reference<XControllerManager> xControllerManager(mxController, UNO_QUERY_THROW); 149 mxConfigurationController = xControllerManager->getConfigurationController(); 150 if (mxConfigurationController.is()) 151 { 152 mxConfigurationController->addResourceFactory( 153 FrameworkHelper::msViewTabBarURL, this); 154 } 155 156 Reference<lang::XComponent> xComponent (mxConfigurationController, UNO_QUERY); 157 if (xComponent.is()) 158 xComponent->addEventListener(static_cast<lang::XEventListener*>(this)); 159 } 160 else 161 { 162 // The view shell is in preview mode and thus does not need 163 // the view tab bar. 164 mxConfigurationController = NULL; 165 } 166 } 167 catch (RuntimeException&) 168 { 169 Shutdown(); 170 throw; 171 } 172 } 173 } 174 175 176 177 178 //----- lang::XEventListener -------------------------------------------------- 179 180 void SAL_CALL BasicToolBarFactory::disposing ( 181 const lang::EventObject& rEventObject) 182 throw (RuntimeException) 183 { 184 if (rEventObject.Source == mxConfigurationController) 185 mxConfigurationController = NULL; 186 } 187 188 189 190 191 //===== XPaneFactory ========================================================== 192 193 Reference<XResource> SAL_CALL BasicToolBarFactory::createResource ( 194 const Reference<XResourceId>& rxToolBarId) 195 throw (RuntimeException, IllegalArgumentException, WrappedTargetException) 196 { 197 ThrowIfDisposed(); 198 199 Reference<XResource> xToolBar; 200 201 if (rxToolBarId->getResourceURL().equals(FrameworkHelper::msViewTabBarURL)) 202 { 203 xToolBar = new ViewTabBar(rxToolBarId, mxController); 204 } 205 else 206 throw lang::IllegalArgumentException(); 207 208 209 return xToolBar; 210 } 211 212 213 214 215 216 void SAL_CALL BasicToolBarFactory::releaseResource ( 217 const Reference<XResource>& rxToolBar) 218 throw (RuntimeException) 219 { 220 ThrowIfDisposed(); 221 222 Reference<XComponent> xComponent (rxToolBar, UNO_QUERY); 223 if (xComponent.is()) 224 xComponent->dispose(); 225 } 226 227 228 229 230 void BasicToolBarFactory::ThrowIfDisposed (void) const 231 throw (lang::DisposedException) 232 { 233 if (rBHelper.bDisposed || rBHelper.bInDispose) 234 { 235 throw lang::DisposedException ( 236 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( 237 "BasicToolBarFactory object has already been disposed")), 238 const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this))); 239 } 240 } 241 242 243 244 245 } } // end of namespace sd::framework 246