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

Generated by: LCOV version 1.10