Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / framework / source / classes / taskcreator.cxx
blob3ff36e0e9734138829bcbce8e440d21fda4d9160
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <classes/taskcreator.hxx>
21 #include <loadenv/targethelper.hxx>
22 #include <services.h>
23 #include <taskcreatordefs.hxx>
25 #include <com/sun/star/frame/Desktop.hpp>
26 #include <com/sun/star/frame/TaskCreator.hpp>
27 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
28 #include <com/sun/star/beans/NamedValue.hpp>
30 #include <vcl/svapp.hxx>
32 #include <officecfg/Office/TabBrowse.hxx>
34 namespace framework{
36 /*-****************************************************************************************************
37 @short initialize instance with necessary information
38 @descr We need a valid uno service manager to create or instantiate new services.
39 All other information to create frames or tasks come in on right interface methods.
41 @param xContext
42 points to the valid uno service manager
43 *//*-*****************************************************************************************************/
44 TaskCreator::TaskCreator( const css::uno::Reference< css::uno::XComponentContext >& xContext )
45 : m_xContext ( xContext )
49 /*-****************************************************************************************************
50 @short deinitialize instance
51 @descr We should release all used resource which are not needed any longer.
52 *//*-*****************************************************************************************************/
53 TaskCreator::~TaskCreator()
57 /*-****************************************************************************************************
58 TODO document me
59 *//*-*****************************************************************************************************/
60 css::uno::Reference< css::frame::XFrame > TaskCreator::createTask( const OUString& sName, const utl::MediaDescriptor& rDescriptor )
62 css::uno::Reference< css::lang::XSingleServiceFactory > xCreator;
63 OUString sCreator = IMPLEMENTATIONNAME_FWK_TASKCREATOR;
65 try
67 if (
68 ( TargetHelper::matchSpecialTarget(sName, TargetHelper::ESpecialTarget::Blank ) ) ||
69 ( TargetHelper::matchSpecialTarget(sName, TargetHelper::ESpecialTarget::Default) )
73 boost::optional<OUString> x(officecfg::Office::TabBrowse::TaskCreatorService::ImplementationName::get(m_xContext));
74 if (x) sCreator = x.get();
77 xCreator.set( m_xContext->getServiceManager()->createInstanceWithContext(sCreator, m_xContext), css::uno::UNO_QUERY_THROW);
79 catch(const css::uno::Exception&)
82 // no catch here ... without a task creator service we can't open ANY document window within the office.
83 // That's IMHO not a good idea. Then we should accept the stacktrace showing us the real problem.
84 // BTW: The used fallback creator service (IMPLEMENTATIONNAME_FWK_TASKCREATOR) is implemented in the same
85 // library then these class here ... Why we should not be able to create it ?
86 if ( ! xCreator.is())
87 xCreator = css::frame::TaskCreator::create(m_xContext);
89 css::uno::Sequence< css::uno::Any > lArgs(6);
90 css::beans::NamedValue aArg;
92 aArg.Name = ARGUMENT_PARENTFRAME;
93 aArg.Value <<= css::uno::Reference< css::frame::XFrame >( css::frame::Desktop::create( m_xContext ), css::uno::UNO_QUERY_THROW);
94 lArgs[0] <<= aArg;
96 aArg.Name = ARGUMENT_CREATETOPWINDOW;
97 aArg.Value <<= true;
98 lArgs[1] <<= aArg;
100 aArg.Name = ARGUMENT_MAKEVISIBLE;
101 aArg.Value <<= false;
102 lArgs[2] <<= aArg;
104 aArg.Name = ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE;
105 aArg.Value <<= true;
106 lArgs[3] <<= aArg;
108 aArg.Name = ARGUMENT_FRAMENAME;
109 aArg.Value <<= sName;
110 lArgs[4] <<= aArg;
112 bool bHidden
113 = rDescriptor.getUnpackedValueOrDefault("HiddenForConversion", false);
114 aArg.Name = "HiddenForConversion";
115 aArg.Value <<= bHidden;
116 lArgs[5] <<= aArg;
118 css::uno::Reference< css::frame::XFrame > xTask(xCreator->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
119 return xTask;
122 } // namespace framework
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */