merge the formfield patch from ooo-build
[ooovba.git] / framework / source / inc / pattern / frame.hxx
blob16167e39ce5c83f3916ba2353f00e41c61a4e59c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: frame.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_PATTERN_FRAME_HXX_
32 #define __FRAMEWORK_PATTERN_FRAME_HXX_
34 //_______________________________________________
35 // own includes
37 #include <general.h>
39 //_______________________________________________
40 // interface includes
41 #include <com/sun/star/frame/XFrame.hpp>
42 #include <com/sun/star/frame/XController.hpp>
43 #include <com/sun/star/frame/XModel.hpp>
44 #include <com/sun/star/lang/XComponent.hpp>
45 #include <com/sun/star/lang/DisposedException.hpp>
46 #include <com/sun/star/util/XCloseable.hpp>
48 //_______________________________________________
49 // other includes
51 //_______________________________________________
52 // namespaces
54 #ifndef css
55 namespace css = ::com::sun::star;
56 #endif
58 namespace framework{
59 namespace pattern{
60 namespace frame{
62 //_______________________________________________
63 // definitions
65 //-----------------------------------------------
66 inline css::uno::Reference< css::frame::XModel > extractFrameModel(const css::uno::Reference< css::frame::XFrame >& xFrame)
68 css::uno::Reference< css::frame::XModel > xModel;
69 css::uno::Reference< css::frame::XController > xController;
70 if (xFrame.is())
71 xController = xFrame->getController();
72 if (xController.is())
73 xModel = xController->getModel();
74 return xModel;
77 //-----------------------------------------------
78 /** @short close (or dispose) the given resource.
80 @descr It try to close the given resource first.
81 Delegating of the ownership can be influenced from
82 outside. If closing isnt possible (because the
83 needed interface isnt available) dispose() is tried instead.
84 Al possible exception are handled inside.
85 So the user of this method has to look for the return value only.
87 @attention The given resource will not be cleared.
88 But later using of it can produce an exception!
90 @param xResource
91 the object, which should be closed here.
93 @param bDelegateOwnerShip
94 used at the XCloseable->close() method to define
95 the right owner in case closing failed.
97 @return [bool]
98 TRUE if closing failed.
100 inline sal_Bool closeIt(const css::uno::Reference< css::uno::XInterface >& xResource ,
101 sal_Bool bDelegateOwnerShip)
103 css::uno::Reference< css::util::XCloseable > xClose (xResource, css::uno::UNO_QUERY);
104 css::uno::Reference< css::lang::XComponent > xDispose(xResource, css::uno::UNO_QUERY);
108 if (xClose.is())
109 xClose->close(bDelegateOwnerShip);
110 else
111 if (xDispose.is())
112 xDispose->dispose();
113 else
114 return sal_False;
116 catch(const css::util::CloseVetoException&)
117 { return sal_False; }
118 catch(const css::lang::DisposedException&)
119 {} // disposed is closed is ...
120 catch(const css::uno::RuntimeException&)
121 { throw; } // shouldnt be suppressed!
122 catch(const css::uno::Exception&)
123 { return sal_False; } // ??? We defined to return a boolen value instead of throwing exceptions ...
124 // (OK: RuntimeExceptions shouldnt be catched inside the core ..)
126 return sal_True;
129 } // namespace frame
130 } // namespace pattern
131 } // namespace framework
133 #endif // __FRAMEWORK_PATTERN_FRAME_HXX_