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 #include "formcontrolcontainer.hxx" 21 #include <osl/diagnose.h> 22 #include <sal/log.hxx> 23 24 #include <algorithm> 25 26 namespace bib 27 { 28 29 30 using namespace ::com::sun::star::uno; 31 using namespace ::com::sun::star::form; 32 using namespace ::com::sun::star::lang; 33 using namespace ::com::sun::star::awt; 34 FormControlContainer()35 FormControlContainer::FormControlContainer( ) 36 :OLoadListener( m_aMutex ) 37 { 38 } 39 ~FormControlContainer()40 FormControlContainer::~FormControlContainer( ) 41 { 42 SAL_WARN_IF( isFormConnected(), "extensions.biblio", "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" ); 43 if ( isFormConnected() ) 44 disconnectForm(); 45 } 46 disconnectForm()47 void FormControlContainer::disconnectForm() 48 { 49 ::osl::MutexGuard aGuard( m_aMutex ); 50 SAL_WARN_IF( !isFormConnected(), "extensions.biblio", "FormControlContainer::connectForm: not connected!" ); 51 if ( isFormConnected() ) 52 { 53 m_xFormAdapter->dispose(); 54 m_xFormAdapter.clear(); 55 } 56 } 57 connectForm(const Reference<XLoadable> & _rxForm)58 void FormControlContainer::connectForm( const Reference< XLoadable >& _rxForm ) 59 { 60 SAL_WARN_IF( isFormConnected(), "extensions.biblio", "FormControlContainer::connectForm: already connected!" ); 61 62 SAL_WARN_IF( !_rxForm.is(), "extensions.biblio", "FormControlContainer::connectForm: invalid form!" ); 63 if ( !isFormConnected() && _rxForm.is() ) 64 { 65 m_xFormAdapter = new OLoadListenerAdapter( _rxForm ); 66 m_xFormAdapter->Init( this ); 67 68 implSetDesignMode( !m_xForm.is() || !m_xForm->isLoaded() ); 69 } 70 71 m_xForm = _rxForm; 72 } 73 74 struct ControlModeSwitch 75 { 76 bool bDesign; ControlModeSwitchbib::ControlModeSwitch77 explicit ControlModeSwitch( bool _bDesign ) : bDesign( _bDesign ) { } 78 operator ()bib::ControlModeSwitch79 void operator() ( const Reference< XControl >& _rxControl ) const 80 { 81 if ( _rxControl.is() ) 82 _rxControl->setDesignMode( bDesign ); 83 } 84 }; 85 implSetDesignMode(bool _bDesign)86 void FormControlContainer::implSetDesignMode( bool _bDesign ) 87 { 88 try 89 { 90 Reference< XControlContainer > xControlCont = getControlContainer(); 91 Sequence< Reference< XControl > > aControls; 92 if ( xControlCont.is() ) 93 aControls = xControlCont->getControls(); 94 95 std::for_each( 96 aControls.begin(), 97 aControls.end(), 98 ControlModeSwitch( _bDesign ) 99 ); 100 } 101 catch( const Exception&) 102 { 103 OSL_FAIL( "FormControlContainer::implSetDesignMode: caught an exception!" ); 104 } 105 } 106 _loaded(const css::lang::EventObject &)107 void FormControlContainer::_loaded( const css::lang::EventObject& /*_rEvent*/ ) 108 { 109 implSetDesignMode( false ); 110 } 111 _unloading(const css::lang::EventObject &)112 void FormControlContainer::_unloading( const css::lang::EventObject& /*_rEvent*/ ) 113 { 114 implSetDesignMode( true ); 115 } 116 _reloading(const css::lang::EventObject &)117 void FormControlContainer::_reloading( const css::lang::EventObject& /*_rEvent*/ ) 118 { 119 implSetDesignMode( true ); 120 } 121 _reloaded(const css::lang::EventObject &)122 void FormControlContainer::_reloaded( const css::lang::EventObject& /*_rEvent*/ ) 123 { 124 implSetDesignMode( false ); 125 } 126 127 128 } // namespace bib 129 130 131 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 132