bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / bibliography / formcontrolcontainer.cxx
blobffd71e099ee2634d60e4b76c029d5d6e8165f0ac
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "formcontrolcontainer.hxx"
21 #include <tools/debug.hxx>
23 #include <algorithm>
24 #include <functional>
27 namespace bib
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::form;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::awt;
36 FormControlContainer::FormControlContainer( )
37 :OLoadListener( m_aMutex )
38 ,m_pFormAdapter( NULL )
42 FormControlContainer::~FormControlContainer( )
44 DBG_ASSERT( !isFormConnected(), "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" );
45 if ( isFormConnected() )
46 disconnectForm();
49 void FormControlContainer::disconnectForm()
51 ::osl::MutexGuard aGuard( m_aMutex );
52 DBG_ASSERT( isFormConnected(), "FormControlContainer::connectForm: not connected!" );
53 if ( isFormConnected() )
55 m_pFormAdapter->dispose();
56 m_pFormAdapter->release();
57 m_pFormAdapter = NULL;
61 void FormControlContainer::connectForm( const Reference< XLoadable >& _rxForm )
63 DBG_ASSERT( !isFormConnected(), "FormControlContainer::connectForm: already connected!" );
65 DBG_ASSERT( _rxForm.is(), "FormControlContainer::connectForm: invalid form!" );
66 if ( !isFormConnected() && _rxForm.is() )
68 m_pFormAdapter = new OLoadListenerAdapter( _rxForm );
69 m_pFormAdapter->acquire();
70 m_pFormAdapter->Init( this );
72 ensureDesignMode();
75 m_xForm = _rxForm;
78 struct ControlModeSwitch : public ::std::unary_function< Reference< XControl >, void >
80 bool bDesign;
81 ControlModeSwitch( bool _bDesign ) : bDesign( _bDesign ) { }
83 void operator() ( const Reference< XControl >& _rxControl ) const
85 if ( _rxControl.is() )
86 _rxControl->setDesignMode( bDesign );
90 void FormControlContainer::implSetDesignMode( bool _bDesign )
92 try
94 Reference< XControlContainer > xControlCont = getControlContainer();
95 Sequence< Reference< XControl > > aControls;
96 if ( xControlCont.is() )
97 aControls = xControlCont->getControls();
99 ::std::for_each(
100 aControls.getConstArray(),
101 aControls.getConstArray() + aControls.getLength(),
102 ControlModeSwitch( _bDesign )
105 catch( const Exception& e)
107 (void) e; // make compiler happy
108 OSL_FAIL( "FormControlContainer::implSetDesignMode: caught an exception!" );
112 void FormControlContainer::ensureDesignMode()
114 implSetDesignMode( !m_xForm.is() || !m_xForm->isLoaded() );
117 void FormControlContainer::_loaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
119 implSetDesignMode( false );
122 void FormControlContainer::_unloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
124 implSetDesignMode( true );
127 void FormControlContainer::_unloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
131 void FormControlContainer::_reloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
133 implSetDesignMode( true );
136 void FormControlContainer::_reloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
138 implSetDesignMode( false );
142 } // namespace bib
145 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */