1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: frame.hxx,v $
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 //_______________________________________________
39 //_______________________________________________
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 //_______________________________________________
51 //_______________________________________________
55 namespace css
= ::com::sun::star
;
62 //_______________________________________________
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
;
71 xController
= xFrame
->getController();
73 xModel
= xController
->getModel();
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!
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.
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
);
109 xClose
->close(bDelegateOwnerShip
);
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 ..)
130 } // namespace pattern
131 } // namespace framework
133 #endif // __FRAMEWORK_PATTERN_FRAME_HXX_