1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: taskcreator.cxx,v $
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 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
37 #include <classes/taskcreator.hxx>
38 #include "services/taskcreatorsrv.hxx"
39 #include <threadhelp/readguard.hxx>
40 #include <loadenv/targethelper.hxx>
43 //_________________________________________________________________________________________________________________
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 //_________________________________________________________________________________________________________________
61 //_________________________________________________________________________________________________________________
65 //_________________________________________________________________________________________________________________
67 //_________________________________________________________________________________________________________________
69 //_________________________________________________________________________________________________________________
70 // non exported definitions
71 //_________________________________________________________________________________________________________________
73 //_________________________________________________________________________________________________________________
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.
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
)
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()
104 /*-****************************************************************************************************//**
106 *//*-*****************************************************************************************************/
107 css::uno::Reference
< css::frame::XFrame
> TaskCreator::createTask( const ::rtl::OUString
& sName
,
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" );
115 ReadGuard
aReadLock( m_aLock
);
116 css::uno::Reference
< css::lang::XMultiServiceFactory
> xSMGR
= m_xSMGR
;
120 css::uno::Reference
< css::lang::XSingleServiceFactory
> xCreator
;
121 ::rtl::OUString sCreator
= IMPLEMENTATIONNAME_FWK_TASKCREATOR
;
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
);
154 aArg
.Name
= TaskCreatorService::ARGUMENT_CREATETOPWINDOW
;
155 aArg
.Value
<<= sal_True
;
158 aArg
.Name
= TaskCreatorService::ARGUMENT_MAKEVISIBLE
;
159 aArg
.Value
<<= bVisible
;
162 aArg
.Name
= TaskCreatorService::ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE
;
163 aArg
.Value
<<= sal_True
;
166 aArg
.Name
= TaskCreatorService::ARGUMENT_FRAMENAME
;
167 aArg
.Value
<<= sName
;
170 css::uno::Reference
< css::frame::XFrame
> xTask(xCreator
->createInstanceWithArguments(lArgs
), css::uno::UNO_QUERY_THROW
);
174 } // namespace framework