update dev300-m58
[ooovba.git] / framework / source / classes / taskcreator.cxx
blob2ab4e33b50f7e3bd04a1c2433a017a387918f9f1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: taskcreator.cxx,v $
10 * $Revision: 1.21 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_framework.hxx"
34 //_________________________________________________________________________________________________________________
35 // my own includes
36 //_________________________________________________________________________________________________________________
37 #include <classes/taskcreator.hxx>
38 #include "services/taskcreatorsrv.hxx"
39 #include <threadhelp/readguard.hxx>
40 #include <loadenv/targethelper.hxx>
41 #include <services.h>
43 //_________________________________________________________________________________________________________________
44 // interface includes
45 //_________________________________________________________________________________________________________________
46 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
47 #include <com/sun/star/beans/NamedValue.hpp>
49 //_________________________________________________________________________________________________________________
50 // includes of other projects
51 //_________________________________________________________________________________________________________________
52 #include <comphelper/configurationhelper.hxx>
53 #include <vcl/svapp.hxx>
55 //_________________________________________________________________________________________________________________
56 // includes of my own project
57 //_________________________________________________________________________________________________________________
59 //_________________________________________________________________________________________________________________
60 // namespace
61 //_________________________________________________________________________________________________________________
63 namespace framework{
65 //_________________________________________________________________________________________________________________
66 // non exported const
67 //_________________________________________________________________________________________________________________
69 //_________________________________________________________________________________________________________________
70 // non exported definitions
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
74 // declarations
75 //_________________________________________________________________________________________________________________
77 /*-****************************************************************************************************//**
78 @short initialize instance with neccessary informations
79 @descr We need a valid uno service manager to create or instanciate new services.
80 All other informations to create frames or tasks come in on right interface methods.
82 @param xSMGR
83 points to the valid uno service manager
85 @modified 16.05.2002 09:25, as96863
86 *//*-*****************************************************************************************************/
87 TaskCreator::TaskCreator( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
88 : ThreadHelpBase( )
89 , m_xSMGR ( xSMGR )
93 /*-****************************************************************************************************//**
94 @short deinitialize instance
95 @descr We should release all used ressource which are not needed any longer.
97 @modified 16.05.2002 09:33, as96863
98 *//*-*****************************************************************************************************/
99 TaskCreator::~TaskCreator()
101 m_xSMGR.clear();
104 /*-****************************************************************************************************//**
105 TODO document me
106 *//*-*****************************************************************************************************/
107 css::uno::Reference< css::frame::XFrame > TaskCreator::createTask( const ::rtl::OUString& sName ,
108 sal_Bool bVisible )
110 static ::rtl::OUString PACKAGE = ::rtl::OUString::createFromAscii("org.openoffice.Office.TabBrowse");
111 static ::rtl::OUString RELPATH = ::rtl::OUString::createFromAscii("TaskCreatorService" );
112 static ::rtl::OUString KEY = ::rtl::OUString::createFromAscii("ImplementationName" );
114 /* SAFE { */
115 ReadGuard aReadLock( m_aLock );
116 css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
117 aReadLock.unlock();
118 /* } SAFE */
120 css::uno::Reference< css::lang::XSingleServiceFactory > xCreator;
121 ::rtl::OUString sCreator = IMPLEMENTATIONNAME_FWK_TASKCREATOR;
125 if (
126 ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_BLANK ) ) ||
127 ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_DEFAULT) )
130 ::comphelper::ConfigurationHelper::readDirectKey(xSMGR, PACKAGE, RELPATH, KEY, ::comphelper::ConfigurationHelper::E_READONLY) >>= sCreator;
133 xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
134 xSMGR->createInstance(sCreator), css::uno::UNO_QUERY_THROW);
136 catch(const css::uno::Exception&)
139 // no catch here ... without an task creator service we cant open ANY document window within the office.
140 // Thats IMHO not a good idea. Then we should accept the stacktrace showing us the real problem.
141 // BTW: The used fallback creator service (IMPLEMENTATIONNAME_FWK_TASKCREATOR) is implemented in the same
142 // library then these class here ... Why we should not be able to create it ?
143 if ( ! xCreator.is())
144 xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
145 xSMGR->createInstance(IMPLEMENTATIONNAME_FWK_TASKCREATOR), css::uno::UNO_QUERY_THROW);
147 css::uno::Sequence< css::uno::Any > lArgs(5);
148 css::beans::NamedValue aArg ;
150 aArg.Name = TaskCreatorService::ARGUMENT_PARENTFRAME;
151 aArg.Value <<= css::uno::Reference< css::frame::XFrame >(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
152 lArgs[0] <<= aArg;
154 aArg.Name = TaskCreatorService::ARGUMENT_CREATETOPWINDOW;
155 aArg.Value <<= sal_True;
156 lArgs[1] <<= aArg;
158 aArg.Name = TaskCreatorService::ARGUMENT_MAKEVISIBLE;
159 aArg.Value <<= bVisible;
160 lArgs[2] <<= aArg;
162 aArg.Name = TaskCreatorService::ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE;
163 aArg.Value <<= sal_True;
164 lArgs[3] <<= aArg;
166 aArg.Name = TaskCreatorService::ARGUMENT_FRAMENAME;
167 aArg.Value <<= sName;
168 lArgs[4] <<= aArg;
170 css::uno::Reference< css::frame::XFrame > xTask(xCreator->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
171 return xTask;
174 } // namespace framework