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 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_framework.hxx" 30 31 //_________________________________________________________________________________________________________________ 32 // my own includes 33 //_________________________________________________________________________________________________________________ 34 #include <classes/taskcreator.hxx> 35 #include "services/taskcreatorsrv.hxx" 36 #include <threadhelp/readguard.hxx> 37 #include <loadenv/targethelper.hxx> 38 #include <services.h> 39 40 //_________________________________________________________________________________________________________________ 41 // interface includes 42 //_________________________________________________________________________________________________________________ 43 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 44 #include <com/sun/star/beans/NamedValue.hpp> 45 46 //_________________________________________________________________________________________________________________ 47 // includes of other projects 48 //_________________________________________________________________________________________________________________ 49 #include <comphelper/configurationhelper.hxx> 50 #include <vcl/svapp.hxx> 51 52 //_________________________________________________________________________________________________________________ 53 // includes of my own project 54 //_________________________________________________________________________________________________________________ 55 56 //_________________________________________________________________________________________________________________ 57 // namespace 58 //_________________________________________________________________________________________________________________ 59 60 namespace framework{ 61 62 //_________________________________________________________________________________________________________________ 63 // non exported const 64 //_________________________________________________________________________________________________________________ 65 66 //_________________________________________________________________________________________________________________ 67 // non exported definitions 68 //_________________________________________________________________________________________________________________ 69 70 //_________________________________________________________________________________________________________________ 71 // declarations 72 //_________________________________________________________________________________________________________________ 73 74 /*-****************************************************************************************************//** 75 @short initialize instance with neccessary informations 76 @descr We need a valid uno service manager to create or instanciate new services. 77 All other informations to create frames or tasks come in on right interface methods. 78 79 @param xSMGR 80 points to the valid uno service manager 81 82 @modified 16.05.2002 09:25, as96863 83 *//*-*****************************************************************************************************/ 84 TaskCreator::TaskCreator( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ) 85 : ThreadHelpBase( ) 86 , m_xSMGR ( xSMGR ) 87 { 88 } 89 90 /*-****************************************************************************************************//** 91 @short deinitialize instance 92 @descr We should release all used ressource which are not needed any longer. 93 94 @modified 16.05.2002 09:33, as96863 95 *//*-*****************************************************************************************************/ 96 TaskCreator::~TaskCreator() 97 { 98 m_xSMGR.clear(); 99 } 100 101 /*-****************************************************************************************************//** 102 TODO document me 103 *//*-*****************************************************************************************************/ 104 css::uno::Reference< css::frame::XFrame > TaskCreator::createTask( const ::rtl::OUString& sName , 105 sal_Bool bVisible ) 106 { 107 static ::rtl::OUString PACKAGE = ::rtl::OUString::createFromAscii("org.openoffice.Office.TabBrowse"); 108 static ::rtl::OUString RELPATH = ::rtl::OUString::createFromAscii("TaskCreatorService" ); 109 static ::rtl::OUString KEY = ::rtl::OUString::createFromAscii("ImplementationName" ); 110 111 /* SAFE { */ 112 ReadGuard aReadLock( m_aLock ); 113 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR; 114 aReadLock.unlock(); 115 /* } SAFE */ 116 117 css::uno::Reference< css::lang::XSingleServiceFactory > xCreator; 118 ::rtl::OUString sCreator = IMPLEMENTATIONNAME_FWK_TASKCREATOR; 119 120 try 121 { 122 if ( 123 ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_BLANK ) ) || 124 ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_DEFAULT) ) 125 ) 126 { 127 ::comphelper::ConfigurationHelper::readDirectKey(xSMGR, PACKAGE, RELPATH, KEY, ::comphelper::ConfigurationHelper::E_READONLY) >>= sCreator; 128 } 129 130 xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >( 131 xSMGR->createInstance(sCreator), css::uno::UNO_QUERY_THROW); 132 } 133 catch(const css::uno::Exception&) 134 {} 135 136 // no catch here ... without an task creator service we cant open ANY document window within the office. 137 // Thats IMHO not a good idea. Then we should accept the stacktrace showing us the real problem. 138 // BTW: The used fallback creator service (IMPLEMENTATIONNAME_FWK_TASKCREATOR) is implemented in the same 139 // library then these class here ... Why we should not be able to create it ? 140 if ( ! xCreator.is()) 141 xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >( 142 xSMGR->createInstance(IMPLEMENTATIONNAME_FWK_TASKCREATOR), css::uno::UNO_QUERY_THROW); 143 144 css::uno::Sequence< css::uno::Any > lArgs(5); 145 css::beans::NamedValue aArg ; 146 147 aArg.Name = TaskCreatorService::ARGUMENT_PARENTFRAME; 148 aArg.Value <<= css::uno::Reference< css::frame::XFrame >(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW); 149 lArgs[0] <<= aArg; 150 151 aArg.Name = TaskCreatorService::ARGUMENT_CREATETOPWINDOW; 152 aArg.Value <<= sal_True; 153 lArgs[1] <<= aArg; 154 155 aArg.Name = TaskCreatorService::ARGUMENT_MAKEVISIBLE; 156 aArg.Value <<= bVisible; 157 lArgs[2] <<= aArg; 158 159 aArg.Name = TaskCreatorService::ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE; 160 aArg.Value <<= sal_True; 161 lArgs[3] <<= aArg; 162 163 aArg.Name = TaskCreatorService::ARGUMENT_FRAMENAME; 164 aArg.Value <<= sName; 165 lArgs[4] <<= aArg; 166 167 css::uno::Reference< css::frame::XFrame > xTask(xCreator->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW); 168 return xTask; 169 } 170 171 } // namespace framework 172