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 <sal/log.hxx> 22 #include <tools/diagnose_ex.h> 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 namespace { 75 76 struct ControlModeSwitch 77 { 78 bool bDesign; ControlModeSwitchbib::__anon6367fe100111::ControlModeSwitch79 explicit ControlModeSwitch( bool _bDesign ) : bDesign( _bDesign ) { } 80 operator ()bib::__anon6367fe100111::ControlModeSwitch81 void operator() ( const Reference< XControl >& _rxControl ) const 82 { 83 if ( _rxControl.is() ) 84 _rxControl->setDesignMode( bDesign ); 85 } 86 }; 87 88 } 89 implSetDesignMode(bool _bDesign)90 void FormControlContainer::implSetDesignMode( bool _bDesign ) 91 { 92 try 93 { 94 Reference< XControlContainer > xControlCont = getControlContainer(); 95 Sequence< Reference< XControl > > aControls; 96 if ( xControlCont.is() ) 97 aControls = xControlCont->getControls(); 98 99 std::for_each( 100 aControls.begin(), 101 aControls.end(), 102 ControlModeSwitch( _bDesign ) 103 ); 104 } 105 catch( const Exception&) 106 { 107 TOOLS_WARN_EXCEPTION( "extensions.biblio", "FormControlContainer::implSetDesignMode" ); 108 } 109 } 110 _loaded(const css::lang::EventObject &)111 void FormControlContainer::_loaded( const css::lang::EventObject& /*_rEvent*/ ) 112 { 113 implSetDesignMode( false ); 114 } 115 _unloading(const css::lang::EventObject &)116 void FormControlContainer::_unloading( const css::lang::EventObject& /*_rEvent*/ ) 117 { 118 implSetDesignMode( true ); 119 } 120 _reloading(const css::lang::EventObject &)121 void FormControlContainer::_reloading( const css::lang::EventObject& /*_rEvent*/ ) 122 { 123 implSetDesignMode( true ); 124 } 125 _reloaded(const css::lang::EventObject &)126 void FormControlContainer::_reloaded( const css::lang::EventObject& /*_rEvent*/ ) 127 { 128 implSetDesignMode( false ); 129 } 130 131 132 } // namespace bib 133 134 135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 136