LCOV - code coverage report
Current view: top level - framework/source/classes - taskcreator.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 35 37 94.6 %
Date: 2014-04-11 Functions: 3 4 75.0 %
Legend: Lines: hit not hit

          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 <loadenv/targethelper.hxx>
      22             : #include <services.h>
      23             : #include <taskcreatordefs.hxx>
      24             : 
      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>
      29             : 
      30             : #include <vcl/svapp.hxx>
      31             : 
      32             : #include <officecfg/Office/TabBrowse.hxx>
      33             : 
      34             : namespace framework{
      35             : 
      36             : /*-****************************************************************************************************
      37             :     @short      initialize instance with necessary information
      38             :     @descr      We need a valid uno service manager to create or instanciate new services.
      39             :                 All other information to create frames or tasks come in on right interface methods.
      40             : 
      41             :     @param      xContext
      42             :                     points to the valid uno service manager
      43             : *//*-*****************************************************************************************************/
      44        2075 : TaskCreator::TaskCreator( const css::uno::Reference< css::uno::XComponentContext >& xContext )
      45        2075 :     : m_xContext    ( xContext )
      46             : {
      47        2075 : }
      48             : 
      49             : /*-****************************************************************************************************
      50             :     @short      deinitialize instance
      51             :     @descr      We should release all used resource which are not needed any longer.
      52             : *//*-*****************************************************************************************************/
      53        2073 : TaskCreator::~TaskCreator()
      54             : {
      55        2073 : }
      56             : 
      57             : /*-****************************************************************************************************
      58             :     TODO document me
      59             : *//*-*****************************************************************************************************/
      60        2075 : css::uno::Reference< css::frame::XFrame > TaskCreator::createTask( const OUString& sName    ,
      61             :                                                                          bool         bVisible )
      62             : {
      63        2075 :     css::uno::Reference< css::lang::XSingleServiceFactory > xCreator;
      64        4148 :     OUString sCreator = IMPLEMENTATIONNAME_FWK_TASKCREATOR;
      65             : 
      66             :     try
      67             :     {
      68        2075 :         if (
      69        2079 :             ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_BLANK  ) ) ||
      70           4 :             ( TargetHelper::matchSpecialTarget(sName, TargetHelper::E_DEFAULT) )
      71             :            )
      72             :         {
      73             : 
      74        2071 :             boost::optional<OUString> x(officecfg::Office::TabBrowse::TaskCreatorService::ImplementationName::get(m_xContext));
      75        2071 :             if (x) sCreator = x.get();
      76             :         }
      77             : 
      78        4150 :         xCreator = css::uno::Reference< css::lang::XSingleServiceFactory >(
      79        6225 :                     m_xContext->getServiceManager()->createInstanceWithContext(sCreator, m_xContext), css::uno::UNO_QUERY_THROW);
      80             :     }
      81           0 :     catch(const css::uno::Exception&)
      82             :     {}
      83             : 
      84             :     // no catch here ... without an task creator service we cant open ANY document window within the office.
      85             :     // Thats IMHO not a good idea. Then we should accept the stacktrace showing us the real problem.
      86             :     // BTW: The used fallback creator service (IMPLEMENTATIONNAME_FWK_TASKCREATOR) is implemented in the same
      87             :     // library then these class here ... Why we should not be able to create it ?
      88        2075 :     if ( ! xCreator.is())
      89           0 :         xCreator = css::frame::TaskCreator::create(m_xContext);
      90             : 
      91        4148 :     css::uno::Sequence< css::uno::Any > lArgs(5);
      92        4148 :     css::beans::NamedValue              aArg;
      93             : 
      94        2075 :     aArg.Name    = OUString(ARGUMENT_PARENTFRAME);
      95        2075 :     aArg.Value <<= css::uno::Reference< css::frame::XFrame >( css::frame::Desktop::create( m_xContext ), css::uno::UNO_QUERY_THROW);
      96        2075 :     lArgs[0]   <<= aArg;
      97             : 
      98        2075 :     aArg.Name    = OUString(ARGUMENT_CREATETOPWINDOW);
      99        2075 :     aArg.Value <<= sal_True;
     100        2075 :     lArgs[1]   <<= aArg;
     101             : 
     102        2075 :     aArg.Name    = OUString(ARGUMENT_MAKEVISIBLE);
     103        2075 :     aArg.Value <<= bVisible;
     104        2075 :     lArgs[2]   <<= aArg;
     105             : 
     106        2075 :     aArg.Name    = OUString(ARGUMENT_SUPPORTPERSISTENTWINDOWSTATE);
     107        2075 :     aArg.Value <<= sal_True;
     108        2075 :     lArgs[3]   <<= aArg;
     109             : 
     110        2075 :     aArg.Name    = OUString(ARGUMENT_FRAMENAME);
     111        2075 :     aArg.Value <<= sName;
     112        2075 :     lArgs[4]   <<= aArg;
     113             : 
     114        2075 :     css::uno::Reference< css::frame::XFrame > xTask(xCreator->createInstanceWithArguments(lArgs), css::uno::UNO_QUERY_THROW);
     115        4146 :     return xTask;
     116             : }
     117             : 
     118             : } // namespace framework
     119             : 
     120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10