LCOV - code coverage report
Current view: top level - framework/source/inc/pattern - frame.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 6 16 37.5 %
Date: 2014-04-11 Functions: 1 1 100.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             : #ifndef INCLUDED_FRAMEWORK_SOURCE_INC_PATTERN_FRAME_HXX
      21             : #define INCLUDED_FRAMEWORK_SOURCE_INC_PATTERN_FRAME_HXX
      22             : 
      23             : #include <general.h>
      24             : 
      25             : #include <com/sun/star/frame/XFrame.hpp>
      26             : #include <com/sun/star/frame/XController.hpp>
      27             : #include <com/sun/star/frame/XModel.hpp>
      28             : #include <com/sun/star/lang/XComponent.hpp>
      29             : #include <com/sun/star/lang/DisposedException.hpp>
      30             : #include <com/sun/star/util/XCloseable.hpp>
      31             : 
      32             : // namespaces
      33             : 
      34             : namespace framework{
      35             :     namespace pattern{
      36             :         namespace frame{
      37             : 
      38             : inline css::uno::Reference< css::frame::XModel > extractFrameModel(const css::uno::Reference< css::frame::XFrame >& xFrame)
      39             : {
      40             :     css::uno::Reference< css::frame::XModel >      xModel;
      41             :     css::uno::Reference< css::frame::XController > xController;
      42             :     if (xFrame.is())
      43             :         xController = xFrame->getController();
      44             :     if (xController.is())
      45             :         xModel = xController->getModel();
      46             :     return xModel;
      47             : }
      48             : 
      49             : /** @short  close (or dispose) the given resource.
      50             : 
      51             :     @descr  It try to close the given resource first.
      52             :             Delegating of the ownership can be influenced from
      53             :             outside. If closing isnt possible (because the
      54             :             needed interface isnt available) dispose() is tried instead.
      55             :             Al possible exception are handled inside.
      56             :             So the user of this method has to look for the return value only.
      57             : 
      58             :     @attention  The given resource will not be cleared.
      59             :                 But later using of it can produce an exception!
      60             : 
      61             :     @param  xResource
      62             :             the object, which should be closed here.
      63             : 
      64             :     @param  bDelegateOwnership
      65             :             used at the XCloseable->close() method to define
      66             :             the right owner in case closing failed.
      67             : 
      68             :     @return [bool]
      69             :             sal_True if closing failed.
      70             :  */
      71           1 : inline bool closeIt(const css::uno::Reference< css::uno::XInterface >& xResource         ,
      72             :                        bool                                     bDelegateOwnership)
      73             : {
      74           1 :     css::uno::Reference< css::util::XCloseable > xClose  (xResource, css::uno::UNO_QUERY);
      75           2 :     css::uno::Reference< css::lang::XComponent > xDispose(xResource, css::uno::UNO_QUERY);
      76             : 
      77             :     try
      78             :     {
      79           1 :         if (xClose.is())
      80           1 :             xClose->close(bDelegateOwnership);
      81             :         else
      82           0 :         if (xDispose.is())
      83           0 :             xDispose->dispose();
      84             :         else
      85           0 :             return false;
      86             :     }
      87           0 :     catch(const css::util::CloseVetoException&)
      88           0 :         { return false; }
      89           0 :     catch(const css::lang::DisposedException&)
      90             :         {} // disposed is closed is ...
      91           0 :     catch(const css::uno::RuntimeException&)
      92           0 :         { throw; } // should not be suppressed!
      93           0 :     catch(const css::uno::Exception&)
      94           0 :         { return false;  } // ??? We defined to return a boolen value instead of throwing exceptions ...
      95             :                                // (OK: RuntimeExceptions should not be catched inside the core ..)
      96             : 
      97           2 :     return true;
      98             : }
      99             : 
     100             :         } // namespace frame
     101             :     } // namespace pattern
     102             : } // namespace framework
     103             : 
     104             : #endif // INCLUDED_FRAMEWORK_SOURCE_INC_PATTERN_FRAME_HXX
     105             : 
     106             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10