1*6d739b60SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*6d739b60SAndrew Rist * distributed with this work for additional information
6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the
17*6d739b60SAndrew Rist * specific language governing permissions and limitations
18*6d739b60SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*6d739b60SAndrew Rist *************************************************************/
21*6d739b60SAndrew Rist
22*6d739b60SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_framework.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir // my own includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir #include <classes/taskcreator.hxx>
31cdf0e10cSrcweir #include "services/taskcreatorsrv.hxx"
32cdf0e10cSrcweir #include <threadhelp/readguard.hxx>
33cdf0e10cSrcweir #include <loadenv/targethelper.hxx>
34cdf0e10cSrcweir #include <services.h>
35cdf0e10cSrcweir
36cdf0e10cSrcweir //_________________________________________________________________________________________________________________
37cdf0e10cSrcweir // interface includes
38cdf0e10cSrcweir //_________________________________________________________________________________________________________________
39cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40cdf0e10cSrcweir #include <com/sun/star/beans/NamedValue.hpp>
41cdf0e10cSrcweir
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir // includes of other projects
44cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
46cdf0e10cSrcweir #include <vcl/svapp.hxx>
47cdf0e10cSrcweir
48cdf0e10cSrcweir //_________________________________________________________________________________________________________________
49cdf0e10cSrcweir // includes of my own project
50cdf0e10cSrcweir //_________________________________________________________________________________________________________________
51cdf0e10cSrcweir
52cdf0e10cSrcweir //_________________________________________________________________________________________________________________
53cdf0e10cSrcweir // namespace
54cdf0e10cSrcweir //_________________________________________________________________________________________________________________
55cdf0e10cSrcweir
56cdf0e10cSrcweir namespace framework{
57cdf0e10cSrcweir
58cdf0e10cSrcweir //_________________________________________________________________________________________________________________
59cdf0e10cSrcweir // non exported const
60cdf0e10cSrcweir //_________________________________________________________________________________________________________________
61cdf0e10cSrcweir
62cdf0e10cSrcweir //_________________________________________________________________________________________________________________
63cdf0e10cSrcweir // non exported definitions
64cdf0e10cSrcweir //_________________________________________________________________________________________________________________
65cdf0e10cSrcweir
66cdf0e10cSrcweir //_________________________________________________________________________________________________________________
67cdf0e10cSrcweir // declarations
68cdf0e10cSrcweir //_________________________________________________________________________________________________________________
69cdf0e10cSrcweir
70cdf0e10cSrcweir /*-****************************************************************************************************//**
71cdf0e10cSrcweir @short initialize instance with neccessary informations
72cdf0e10cSrcweir @descr We need a valid uno service manager to create or instanciate new services.
73cdf0e10cSrcweir All other informations to create frames or tasks come in on right interface methods.
74cdf0e10cSrcweir
75cdf0e10cSrcweir @param xSMGR
76cdf0e10cSrcweir points to the valid uno service manager
77cdf0e10cSrcweir
78cdf0e10cSrcweir @modified 16.05.2002 09:25, as96863
79cdf0e10cSrcweir *//*-*****************************************************************************************************/
TaskCreator(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)80cdf0e10cSrcweir TaskCreator::TaskCreator( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
81cdf0e10cSrcweir : ThreadHelpBase( )
82cdf0e10cSrcweir , m_xSMGR ( xSMGR )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
86cdf0e10cSrcweir /*-****************************************************************************************************//**
87cdf0e10cSrcweir @short deinitialize instance
88cdf0e10cSrcweir @descr We should release all used ressource which are not needed any longer.
89cdf0e10cSrcweir
90cdf0e10cSrcweir @modified 16.05.2002 09:33, as96863
91cdf0e10cSrcweir *//*-*****************************************************************************************************/
~TaskCreator()92cdf0e10cSrcweir TaskCreator::~TaskCreator()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir m_xSMGR.clear();
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
97cdf0e10cSrcweir /*-****************************************************************************************************//**
98cdf0e10cSrcweir TODO document me
99cdf0e10cSrcweir *//*-*****************************************************************************************************/
createTask(const::rtl::OUString & sName,sal_Bool bVisible)100cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > TaskCreator::createTask( const ::rtl::OUString& sName ,
101cdf0e10cSrcweir sal_Bool bVisible )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir static ::rtl::OUString PACKAGE = ::rtl::OUString::createFromAscii("org.openoffice.Office.TabBrowse");
104cdf0e10cSrcweir static ::rtl::OUString RELPATH = ::rtl::OUString::createFromAscii("TaskCreatorService" );
105cdf0e10cSrcweir static ::rtl::OUString KEY = ::rtl::OUString::createFromAscii("ImplementationName" );
106cdf0e10cSrcweir
107cdf0e10cSrcweir /* SAFE { */
108cdf0e10cSrcweir ReadGuard aReadLock( m_aLock );
109cdf0e10cSrcweir css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
110cdf0e10cSrcweir aReadLock.unlock();
111cdf0e10cSrcweir /* } SAFE */
112cdf0e10cSrcweir
113cdf0e10cSrcweir css::uno::Reference< css::lang::XSingleServiceFactory > xCreator;
114cdf0e10cSrcweir ::rtl::OUString sCreator = IMPLEMENTATIONNAME_FWK_TASKCREATOR;
115cdf0e10cSrcweir
116cdf0e10cSrcweir try
117cdf0e10cSrcweir {
118cdf0e10cSrcweir if (
119cdf0e10cSrcweir ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_BLANK ) ) ||
120cdf0e10cSrcweir ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_DEFAULT) )
121cdf0e10cSrcweir )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir ::comphelper::ConfigurationHelper::readDirectKey(xSMGR, PACKAGE, RELPATH, KEY, ::comphelper::ConfigurationHelper::E_READONLY) >>= sCreator;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir
126cdf0e10cSrcweir xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
127cdf0e10cSrcweir xSMGR->createInstance(sCreator), css::uno::UNO_QUERY_THROW);
128cdf0e10cSrcweir }
129cdf0e10cSrcweir catch(const css::uno::Exception&)
130cdf0e10cSrcweir {}
131cdf0e10cSrcweir
132cdf0e10cSrcweir // no catch here ... without an task creator service we cant open ANY document window within the office.
133cdf0e10cSrcweir // Thats IMHO not a good idea. Then we should accept the stacktrace showing us the real problem.
134cdf0e10cSrcweir // BTW: The used fallback creator service (IMPLEMENTATIONNAME_FWK_TASKCREATOR) is implemented in the same
135cdf0e10cSrcweir // library then these class here ... Why we should not be able to create it ?
136cdf0e10cSrcweir if ( ! xCreator.is())
137cdf0e10cSrcweir xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
138cdf0e10cSrcweir xSMGR->createInstance(IMPLEMENTATIONNAME_FWK_TASKCREATOR), css::uno::UNO_QUERY_THROW);
139cdf0e10cSrcweir
140cdf0e10cSrcweir css::uno::Sequence< css::uno::Any > lArgs(5);
141cdf0e10cSrcweir css::beans::NamedValue aArg ;
142cdf0e10cSrcweir
143cdf0e10cSrcweir aArg.Name = TaskCreatorService::ARGUMENT_PARENTFRAME;
144cdf0e10cSrcweir aArg.Value <<= css::uno::Reference< css::frame::XFrame >(xSMGR->createInstance(SERVICENAME_DESKTOP), css::uno::UNO_QUERY_THROW);
145cdf0e10cSrcweir lArgs[0] <<= aArg;
146cdf0e10cSrcweir
147cdf0e10cSrcweir aArg.Name = TaskCreatorService::ARGUMENT_CREATETOPWINDOW;
148cdf0e10cSrcweir aArg.Value <<= sal_True;
149cdf0e10cSrcweir lArgs[1] <<= aArg;
150cdf0e10cSrcweir
151cdf0e10cSrcweir aArg.Name = TaskCreatorService::ARGUMENT_MAKEVISIBLE;
152cdf0e10cSrcweir aArg.Value <<= bVisible;
153cdf0e10cSrcweir lArgs[2] <<= aArg;
154cdf0e10cSrcweir
155cdf0e10cSrcweir aArg.Name = TaskCreatorService::ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE;
156cdf0e10cSrcweir aArg.Value <<= sal_True;
157cdf0e10cSrcweir lArgs[3] <<= aArg;
158cdf0e10cSrcweir
159cdf0e10cSrcweir aArg.Name = TaskCreatorService::ARGUMENT_FRAMENAME;
160cdf0e10cSrcweir aArg.Value <<= sName;
161cdf0e10cSrcweir lArgs[4] <<= aArg;
162cdf0e10cSrcweir
163cdf0e10cSrcweir css::uno::Reference< css::frame::XFrame > xTask(xCreator->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
164cdf0e10cSrcweir return xTask;
165cdf0e10cSrcweir }
166cdf0e10cSrcweir
167cdf0e10cSrcweir } // namespace framework
168