1*f8e07b45SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f8e07b45SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f8e07b45SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f8e07b45SAndrew Rist * distributed with this work for additional information 6*f8e07b45SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f8e07b45SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f8e07b45SAndrew Rist * "License"); you may not use this file except in compliance 9*f8e07b45SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*f8e07b45SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*f8e07b45SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f8e07b45SAndrew Rist * software distributed under the License is distributed on an 15*f8e07b45SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f8e07b45SAndrew Rist * KIND, either express or implied. See the License for the 17*f8e07b45SAndrew Rist * specific language governing permissions and limitations 18*f8e07b45SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*f8e07b45SAndrew Rist *************************************************************/ 21*f8e07b45SAndrew Rist 22*f8e07b45SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef __FRAMEWORK_PATTERN_FRAME_HXX_ 25cdf0e10cSrcweir #define __FRAMEWORK_PATTERN_FRAME_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir //_______________________________________________ 28cdf0e10cSrcweir // own includes 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include <general.h> 31cdf0e10cSrcweir 32cdf0e10cSrcweir //_______________________________________________ 33cdf0e10cSrcweir // interface includes 34cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 35cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp> 36cdf0e10cSrcweir #include <com/sun/star/frame/XModel.hpp> 37cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 38cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 39cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 40cdf0e10cSrcweir 41cdf0e10cSrcweir //_______________________________________________ 42cdf0e10cSrcweir // other includes 43cdf0e10cSrcweir 44cdf0e10cSrcweir //_______________________________________________ 45cdf0e10cSrcweir // namespaces 46cdf0e10cSrcweir 47cdf0e10cSrcweir #ifndef css 48cdf0e10cSrcweir namespace css = ::com::sun::star; 49cdf0e10cSrcweir #endif 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace framework{ 52cdf0e10cSrcweir namespace pattern{ 53cdf0e10cSrcweir namespace frame{ 54cdf0e10cSrcweir 55cdf0e10cSrcweir //_______________________________________________ 56cdf0e10cSrcweir // definitions 57cdf0e10cSrcweir 58cdf0e10cSrcweir //----------------------------------------------- extractFrameModel(const css::uno::Reference<css::frame::XFrame> & xFrame)59cdf0e10cSrcweirinline css::uno::Reference< css::frame::XModel > extractFrameModel(const css::uno::Reference< css::frame::XFrame >& xFrame) 60cdf0e10cSrcweir { 61cdf0e10cSrcweir css::uno::Reference< css::frame::XModel > xModel; 62cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xController; 63cdf0e10cSrcweir if (xFrame.is()) 64cdf0e10cSrcweir xController = xFrame->getController(); 65cdf0e10cSrcweir if (xController.is()) 66cdf0e10cSrcweir xModel = xController->getModel(); 67cdf0e10cSrcweir return xModel; 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir //----------------------------------------------- 71cdf0e10cSrcweir /** @short close (or dispose) the given resource. 72cdf0e10cSrcweir 73cdf0e10cSrcweir @descr It try to close the given resource first. 74cdf0e10cSrcweir Delegating of the ownership can be influenced from 75cdf0e10cSrcweir outside. If closing isnt possible (because the 76cdf0e10cSrcweir needed interface isnt available) dispose() is tried instead. 77cdf0e10cSrcweir Al possible exception are handled inside. 78cdf0e10cSrcweir So the user of this method has to look for the return value only. 79cdf0e10cSrcweir 80cdf0e10cSrcweir @attention The given resource will not be cleared. 81cdf0e10cSrcweir But later using of it can produce an exception! 82cdf0e10cSrcweir 83cdf0e10cSrcweir @param xResource 84cdf0e10cSrcweir the object, which should be closed here. 85cdf0e10cSrcweir 86cdf0e10cSrcweir @param bDelegateOwnerShip 87cdf0e10cSrcweir used at the XCloseable->close() method to define 88cdf0e10cSrcweir the right owner in case closing failed. 89cdf0e10cSrcweir 90cdf0e10cSrcweir @return [bool] 91cdf0e10cSrcweir sal_True if closing failed. 92cdf0e10cSrcweir */ closeIt(const css::uno::Reference<css::uno::XInterface> & xResource,sal_Bool bDelegateOwnerShip)93cdf0e10cSrcweirinline sal_Bool closeIt(const css::uno::Reference< css::uno::XInterface >& xResource , 94cdf0e10cSrcweir sal_Bool bDelegateOwnerShip) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir css::uno::Reference< css::util::XCloseable > xClose (xResource, css::uno::UNO_QUERY); 97cdf0e10cSrcweir css::uno::Reference< css::lang::XComponent > xDispose(xResource, css::uno::UNO_QUERY); 98cdf0e10cSrcweir 99cdf0e10cSrcweir try 100cdf0e10cSrcweir { 101cdf0e10cSrcweir if (xClose.is()) 102cdf0e10cSrcweir xClose->close(bDelegateOwnerShip); 103cdf0e10cSrcweir else 104cdf0e10cSrcweir if (xDispose.is()) 105cdf0e10cSrcweir xDispose->dispose(); 106cdf0e10cSrcweir else 107cdf0e10cSrcweir return sal_False; 108cdf0e10cSrcweir } 109cdf0e10cSrcweir catch(const css::util::CloseVetoException&) 110cdf0e10cSrcweir { return sal_False; } 111cdf0e10cSrcweir catch(const css::lang::DisposedException&) 112cdf0e10cSrcweir {} // disposed is closed is ... 113cdf0e10cSrcweir catch(const css::uno::RuntimeException&) 114cdf0e10cSrcweir { throw; } // shouldnt be suppressed! 115cdf0e10cSrcweir catch(const css::uno::Exception&) 116cdf0e10cSrcweir { return sal_False; } // ??? We defined to return a boolen value instead of throwing exceptions ... 117cdf0e10cSrcweir // (OK: RuntimeExceptions shouldnt be catched inside the core ..) 118cdf0e10cSrcweir 119cdf0e10cSrcweir return sal_True; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir } // namespace frame 123cdf0e10cSrcweir } // namespace pattern 124cdf0e10cSrcweir } // namespace framework 125cdf0e10cSrcweir 126cdf0e10cSrcweir #endif // __FRAMEWORK_PATTERN_FRAME_HXX_ 127