1c82f2877SAndrew Rist /************************************************************** 2c82f2877SAndrew Rist * 3c82f2877SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4c82f2877SAndrew Rist * or more contributor license agreements. See the NOTICE file 5c82f2877SAndrew Rist * distributed with this work for additional information 6c82f2877SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7c82f2877SAndrew Rist * to you under the Apache License, Version 2.0 (the 8c82f2877SAndrew Rist * "License"); you may not use this file except in compliance 9c82f2877SAndrew Rist * with the License. You may obtain a copy of the License at 10c82f2877SAndrew Rist * 11c82f2877SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12c82f2877SAndrew Rist * 13c82f2877SAndrew Rist * Unless required by applicable law or agreed to in writing, 14c82f2877SAndrew Rist * software distributed under the License is distributed on an 15c82f2877SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16c82f2877SAndrew Rist * KIND, either express or implied. See the License for the 17c82f2877SAndrew Rist * specific language governing permissions and limitations 18c82f2877SAndrew Rist * under the License. 19c82f2877SAndrew Rist * 20c82f2877SAndrew Rist *************************************************************/ 21c82f2877SAndrew Rist 22c82f2877SAndrew Rist 23cdf0e10cSrcweir 24*b63233d8Sdamjan #include "precompiled_dbui.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "closeveto.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir /** === begin UNO includes === **/ 29cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp> 30cdf0e10cSrcweir /** === end UNO includes === **/ 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 33cdf0e10cSrcweir #include <rtl/ref.hxx> 34cdf0e10cSrcweir #include <tools/diagnose_ex.h> 35cdf0e10cSrcweir 36cdf0e10cSrcweir //...................................................................................................................... 37cdf0e10cSrcweir namespace dbaui 38cdf0e10cSrcweir { 39cdf0e10cSrcweir //...................................................................................................................... 40cdf0e10cSrcweir 41cdf0e10cSrcweir /** === begin UNO using === **/ 42cdf0e10cSrcweir using ::com::sun::star::uno::Reference; 43cdf0e10cSrcweir using ::com::sun::star::uno::XInterface; 44cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY; 45cdf0e10cSrcweir using ::com::sun::star::uno::UNO_QUERY_THROW; 46cdf0e10cSrcweir using ::com::sun::star::uno::UNO_SET_THROW; 47cdf0e10cSrcweir using ::com::sun::star::uno::Exception; 48cdf0e10cSrcweir using ::com::sun::star::uno::RuntimeException; 49cdf0e10cSrcweir using ::com::sun::star::uno::Any; 50cdf0e10cSrcweir using ::com::sun::star::uno::makeAny; 51cdf0e10cSrcweir using ::com::sun::star::uno::Sequence; 52cdf0e10cSrcweir using ::com::sun::star::uno::Type; 53cdf0e10cSrcweir using ::com::sun::star::util::XCloseable; 54cdf0e10cSrcweir using ::com::sun::star::util::XCloseListener; 55cdf0e10cSrcweir using ::com::sun::star::util::CloseVetoException; 56cdf0e10cSrcweir using ::com::sun::star::lang::EventObject; 57cdf0e10cSrcweir /** === end UNO using === **/ 58cdf0e10cSrcweir 59cdf0e10cSrcweir //================================================================================================================== 60cdf0e10cSrcweir //= CloseListener_Impl 61cdf0e10cSrcweir //================================================================================================================== 62cdf0e10cSrcweir typedef ::cppu::WeakImplHelper1 < XCloseListener 63cdf0e10cSrcweir > CloseListener_Base; 64cdf0e10cSrcweir class DBACCESS_DLLPRIVATE CloseListener_Impl : public CloseListener_Base 65cdf0e10cSrcweir { 66cdf0e10cSrcweir public: CloseListener_Impl()67cdf0e10cSrcweir CloseListener_Impl() 68cdf0e10cSrcweir :m_bHasOwnership( false ) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir // XCloseListener 73cdf0e10cSrcweir virtual void SAL_CALL queryClosing( const EventObject& Source, ::sal_Bool GetsOwnership ) throw (CloseVetoException, RuntimeException); 74cdf0e10cSrcweir virtual void SAL_CALL notifyClosing( const EventObject& Source ) throw (RuntimeException); 75cdf0e10cSrcweir 76cdf0e10cSrcweir // XEventListener 77cdf0e10cSrcweir virtual void SAL_CALL disposing( const EventObject& Source) throw (RuntimeException); 78cdf0e10cSrcweir hasOwnership() const79cdf0e10cSrcweir bool hasOwnership() const { return m_bHasOwnership; } 80cdf0e10cSrcweir 81cdf0e10cSrcweir protected: ~CloseListener_Impl()82cdf0e10cSrcweir ~CloseListener_Impl() 83cdf0e10cSrcweir { 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir private: 87cdf0e10cSrcweir bool m_bHasOwnership; 88cdf0e10cSrcweir }; 89cdf0e10cSrcweir 90cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ queryClosing(const EventObject & i_source,::sal_Bool i_deliverOwnership)91cdf0e10cSrcweir void SAL_CALL CloseListener_Impl::queryClosing( const EventObject& i_source, ::sal_Bool i_deliverOwnership ) throw (CloseVetoException, RuntimeException) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir (void)i_source; 94cdf0e10cSrcweir 95cdf0e10cSrcweir if ( !m_bHasOwnership ) 96cdf0e10cSrcweir m_bHasOwnership = i_deliverOwnership; 97cdf0e10cSrcweir 98cdf0e10cSrcweir throw CloseVetoException(); 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ notifyClosing(const EventObject & i_source)102cdf0e10cSrcweir void SAL_CALL CloseListener_Impl::notifyClosing( const EventObject& i_source ) throw (RuntimeException) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir (void)i_source; 105cdf0e10cSrcweir } 106cdf0e10cSrcweir 107cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ disposing(const EventObject & i_source)108cdf0e10cSrcweir void SAL_CALL CloseListener_Impl::disposing( const EventObject& i_source ) throw (RuntimeException) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir (void)i_source; 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir //================================================================================================================== 114cdf0e10cSrcweir //= CloseVeto_Data 115cdf0e10cSrcweir //================================================================================================================== 116cdf0e10cSrcweir struct DBACCESS_DLLPRIVATE CloseVeto_Data 117cdf0e10cSrcweir { 118cdf0e10cSrcweir Reference< XCloseable > xCloseable; 119cdf0e10cSrcweir ::rtl::Reference< CloseListener_Impl > pListener; 120cdf0e10cSrcweir }; 121cdf0e10cSrcweir 122cdf0e10cSrcweir //================================================================================================================== 123cdf0e10cSrcweir //= operations 124cdf0e10cSrcweir //================================================================================================================== 125cdf0e10cSrcweir namespace 126cdf0e10cSrcweir { 127cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------------------- lcl_init(CloseVeto_Data & i_data,const Reference<XInterface> & i_closeable)128cdf0e10cSrcweir void lcl_init( CloseVeto_Data& i_data, const Reference< XInterface >& i_closeable ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir i_data.xCloseable.set( i_closeable, UNO_QUERY ); 131cdf0e10cSrcweir ENSURE_OR_RETURN_VOID( i_data.xCloseable.is(), "CloseVeto: the component is not closeable!" ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir i_data.pListener = new CloseListener_Impl; 134cdf0e10cSrcweir i_data.xCloseable->addCloseListener( i_data.pListener.get() ); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir //-------------------------------------------------------------------------------------------------------------- lcl_deinit(CloseVeto_Data & i_data)138cdf0e10cSrcweir void lcl_deinit( CloseVeto_Data& i_data ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir if ( !i_data.xCloseable.is() ) 141cdf0e10cSrcweir return; 142cdf0e10cSrcweir 143cdf0e10cSrcweir i_data.xCloseable->removeCloseListener( i_data.pListener.get() ); 144cdf0e10cSrcweir if ( i_data.pListener->hasOwnership() ) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir try 147cdf0e10cSrcweir { 148cdf0e10cSrcweir i_data.xCloseable->close( sal_True ); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir catch( const CloseVetoException& ) { } 151cdf0e10cSrcweir catch( const Exception& ) 152cdf0e10cSrcweir { 153cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir } 156cdf0e10cSrcweir } 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir //================================================================================================================== 160cdf0e10cSrcweir //= CloseVeto 161cdf0e10cSrcweir //================================================================================================================== 162cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ CloseVeto(const Reference<XInterface> & i_closeable)163cdf0e10cSrcweir CloseVeto::CloseVeto( const Reference< XInterface >& i_closeable ) 164cdf0e10cSrcweir :m_pData( new CloseVeto_Data ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir lcl_init( *m_pData, i_closeable ); 167cdf0e10cSrcweir } 168cdf0e10cSrcweir 169cdf0e10cSrcweir //------------------------------------------------------------------------------------------------------------------ ~CloseVeto()170cdf0e10cSrcweir CloseVeto::~CloseVeto() 171cdf0e10cSrcweir { 172cdf0e10cSrcweir lcl_deinit( *m_pData ); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir //...................................................................................................................... 176cdf0e10cSrcweir } // namespace dbaui 177cdf0e10cSrcweir //...................................................................................................................... 178