LibreOffice Module framework (master) 1
taskcreator.cxx
Go to the documentation of this file.
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
21#include <services.h>
22#include <taskcreatordefs.hxx>
23
24#include <com/sun/star/frame/Desktop.hpp>
25#include <com/sun/star/frame/TaskCreator.hpp>
26#include <com/sun/star/lang/XSingleServiceFactory.hpp>
27#include <com/sun/star/beans/NamedValue.hpp>
28#include <utility>
29
30namespace framework{
31
32/*-****************************************************************************************************
33 @short initialize instance with necessary information
34 @descr We need a valid uno service manager to create or instantiate new services.
35 All other information to create frames or tasks come in on right interface methods.
36
37 @param xContext
38 points to the valid uno service manager
39*//*-*****************************************************************************************************/
40TaskCreator::TaskCreator( css::uno::Reference< css::uno::XComponentContext > xContext )
41 : m_xContext (std::move( xContext ))
42{
43}
44
45/*-****************************************************************************************************
46 @short deinitialize instance
47 @descr We should release all used resource which are not needed any longer.
48*//*-*****************************************************************************************************/
50{
51}
52
53/*-****************************************************************************************************
54 TODO document me
55*//*-*****************************************************************************************************/
56css::uno::Reference< css::frame::XFrame > TaskCreator::createTask( const OUString& sName, const utl::MediaDescriptor& rDescriptor )
57{
58 css::uno::Reference< css::lang::XSingleServiceFactory > xCreator;
59
60 try
61 {
62 xCreator.set( m_xContext->getServiceManager()->createInstanceWithContext(IMPLEMENTATIONNAME_FWK_TASKCREATOR, m_xContext), css::uno::UNO_QUERY_THROW);
63 }
64 catch(const css::uno::Exception&)
65 {}
66
67 // no catch here ... without a task creator service we can't open ANY document window within the office.
68 // That's IMHO not a good idea. Then we should accept the stacktrace showing us the real problem.
69 // BTW: The used fallback creator service (IMPLEMENTATIONNAME_FWK_TASKCREATOR) is implemented in the same
70 // library then these class here ... Why we should not be able to create it ?
71 if ( ! xCreator.is())
72 xCreator = css::frame::TaskCreator::create(m_xContext);
73
74 css::uno::Sequence< css::uno::Any > lArgs
75 {
76 css::uno::Any(css::beans::NamedValue(ARGUMENT_PARENTFRAME, css::uno::Any(css::uno::Reference< css::frame::XFrame >( css::frame::Desktop::create( m_xContext ), css::uno::UNO_QUERY_THROW)))) ,
77 css::uno::Any(css::beans::NamedValue(ARGUMENT_CREATETOPWINDOW, css::uno::Any(true))),
78 css::uno::Any(css::beans::NamedValue(ARGUMENT_MAKEVISIBLE, css::uno::Any(false))),
79 css::uno::Any(css::beans::NamedValue(ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE, css::uno::Any(true))),
80 css::uno::Any(css::beans::NamedValue(ARGUMENT_FRAMENAME, css::uno::Any(sName))),
81 css::uno::Any(css::beans::NamedValue(ARGUMENT_HIDDENFORCONVERSION, css::uno::Any(rDescriptor.getUnpackedValueOrDefault(ARGUMENT_HIDDENFORCONVERSION, false))))
82 };
83 css::uno::Reference< css::frame::XFrame > xTask(xCreator->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
84 return xTask;
85}
86
87} // namespace framework
88
89/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::frame::XFrame > createTask(const OUString &sName, const utl::MediaDescriptor &rDescriptor)
Definition: taskcreator.cxx:56
css::uno::Reference< css::uno::XComponentContext > m_xContext
Definition: taskcreator.hxx:46
TaskCreator(css::uno::Reference< css::uno::XComponentContext > xContext)
Definition: taskcreator.cxx:40
OUString sName
css::uno::Reference< css::uno::XComponentContext > m_xContext
constexpr OUStringLiteral IMPLEMENTATIONNAME_FWK_TASKCREATOR
Definition: services.h:38
constexpr OUStringLiteral ARGUMENT_PARENTFRAME
[XFrame] if it's set, it will be used as parent frame for the new created frame.
constexpr OUStringLiteral ARGUMENT_FRAMENAME
[OUString] if it's not a special name (beginning with "_" ... which are not allowed here!...
constexpr OUStringLiteral ARGUMENT_CREATETOPWINDOW
[bool] If not "ContainerWindow" property is set it force creation of a top level window as new contai...
constexpr OUStringLiteral ARGUMENT_HIDDENFORCONVERSION
[bool] enable/disable if the frame is explicitly requested to be hidden Default = OFF !
constexpr OUStringLiteral ARGUMENT_MAKEVISIBLE
[bool] If it's set to true we will make the new created frame visible.
constexpr OUStringLiteral ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE
[bool] enable/disable special mode, where this frame will be part of the persistent window state feat...