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