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