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