Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <classes/taskcreator.hxx>
21 : #include "services/taskcreatorsrv.hxx"
22 : #include <threadhelp/readguard.hxx>
23 : #include <loadenv/targethelper.hxx>
24 : #include <services.h>
25 :
26 : #include <com/sun/star/frame/Desktop.hpp>
27 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
28 : #include <com/sun/star/beans/NamedValue.hpp>
29 :
30 : #include <comphelper/configurationhelper.hxx>
31 : #include <vcl/svapp.hxx>
32 :
33 : namespace framework{
34 :
35 : /*-****************************************************************************************************//**
36 : @short initialize instance with neccessary informations
37 : @descr We need a valid uno service manager to create or instanciate new services.
38 : All other informations to create frames or tasks come in on right interface methods.
39 :
40 : @param xSMGR
41 : points to the valid uno service manager
42 : *//*-*****************************************************************************************************/
43 240 : TaskCreator::TaskCreator( const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR )
44 : : ThreadHelpBase( )
45 240 : , m_xSMGR ( xSMGR )
46 : {
47 240 : }
48 :
49 : /*-****************************************************************************************************//**
50 : @short deinitialize instance
51 : @descr We should release all used resource which are not needed any longer.
52 : *//*-*****************************************************************************************************/
53 480 : TaskCreator::~TaskCreator()
54 : {
55 240 : m_xSMGR.clear();
56 240 : }
57 :
58 : /*-****************************************************************************************************//**
59 : TODO document me
60 : *//*-*****************************************************************************************************/
61 240 : css::uno::Reference< css::frame::XFrame > TaskCreator::createTask( const ::rtl::OUString& sName ,
62 : sal_Bool bVisible )
63 : {
64 : /* SAFE { */
65 240 : ReadGuard aReadLock( m_aLock );
66 240 : css::uno::Reference< css::lang::XMultiServiceFactory > xSMGR = m_xSMGR;
67 240 : aReadLock.unlock();
68 : /* } SAFE */
69 :
70 240 : css::uno::Reference< css::lang::XSingleServiceFactory > xCreator;
71 240 : ::rtl::OUString sCreator = IMPLEMENTATIONNAME_FWK_TASKCREATOR;
72 :
73 : try
74 : {
75 240 : if (
76 240 : ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_BLANK ) ) ||
77 0 : ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_DEFAULT) )
78 : )
79 : {
80 : ::comphelper::ConfigurationHelper::readDirectKey(
81 : comphelper::getComponentContext(xSMGR),
82 : "org.openoffice.Office.TabBrowse",
83 : "TaskCreatorService",
84 : "ImplementationName",
85 240 : ::comphelper::ConfigurationHelper::E_READONLY) >>= sCreator;
86 : }
87 :
88 : xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
89 240 : xSMGR->createInstance(sCreator), css::uno::UNO_QUERY_THROW);
90 : }
91 0 : catch(const css::uno::Exception&)
92 : {}
93 :
94 : // no catch here ... without an task creator service we cant open ANY document window within the office.
95 : // Thats IMHO not a good idea. Then we should accept the stacktrace showing us the real problem.
96 : // BTW: The used fallback creator service (IMPLEMENTATIONNAME_FWK_TASKCREATOR) is implemented in the same
97 : // library then these class here ... Why we should not be able to create it ?
98 240 : if ( ! xCreator.is())
99 : xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
100 0 : xSMGR->createInstance(IMPLEMENTATIONNAME_FWK_TASKCREATOR), css::uno::UNO_QUERY_THROW);
101 :
102 240 : css::uno::Sequence< css::uno::Any > lArgs(5);
103 240 : css::beans::NamedValue aArg ;
104 :
105 240 : aArg.Name = rtl::OUString(ARGUMENT_PARENTFRAME);
106 240 : aArg.Value <<= css::uno::Reference< css::frame::XFrame >( css::frame::Desktop::create( comphelper::getComponentContext(xSMGR) ), css::uno::UNO_QUERY_THROW);
107 240 : lArgs[0] <<= aArg;
108 :
109 240 : aArg.Name = rtl::OUString(ARGUMENT_CREATETOPWINDOW);
110 240 : aArg.Value <<= sal_True;
111 240 : lArgs[1] <<= aArg;
112 :
113 240 : aArg.Name = rtl::OUString(ARGUMENT_MAKEVISIBLE);
114 240 : aArg.Value <<= bVisible;
115 240 : lArgs[2] <<= aArg;
116 :
117 240 : aArg.Name = rtl::OUString(ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE);
118 240 : aArg.Value <<= sal_True;
119 240 : lArgs[3] <<= aArg;
120 :
121 240 : aArg.Name = rtl::OUString(ARGUMENT_FRAMENAME);
122 240 : aArg.Value <<= sName;
123 240 : lArgs[4] <<= aArg;
124 :
125 240 : css::uno::Reference< css::frame::XFrame > xTask(xCreator->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
126 240 : return xTask;
127 : }
128 :
129 : } // namespace framework
130 :
131 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|