1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <osl/diagnose.h>
22 #include <sal/log.hxx>
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
;
35 FormControlContainer::FormControlContainer( )
36 :OLoadListener( m_aMutex
)
40 FormControlContainer::~FormControlContainer( )
42 SAL_WARN_IF( isFormConnected(), "extensions.biblio", "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" );
43 if ( isFormConnected() )
47 void FormControlContainer::disconnectForm()
49 ::osl::MutexGuard
aGuard( m_aMutex
);
50 SAL_WARN_IF( !isFormConnected(), "extensions.biblio", "FormControlContainer::connectForm: not connected!" );
51 if ( isFormConnected() )
53 m_xFormAdapter
->dispose();
54 m_xFormAdapter
.clear();
58 void FormControlContainer::connectForm( const Reference
< XLoadable
>& _rxForm
)
60 SAL_WARN_IF( isFormConnected(), "extensions.biblio", "FormControlContainer::connectForm: already connected!" );
62 SAL_WARN_IF( !_rxForm
.is(), "extensions.biblio", "FormControlContainer::connectForm: invalid form!" );
63 if ( !isFormConnected() && _rxForm
.is() )
65 m_xFormAdapter
= new OLoadListenerAdapter( _rxForm
);
66 m_xFormAdapter
->Init( this );
68 implSetDesignMode( !m_xForm
.is() || !m_xForm
->isLoaded() );
74 struct ControlModeSwitch
77 explicit ControlModeSwitch( bool _bDesign
) : bDesign( _bDesign
) { }
79 void operator() ( const Reference
< XControl
>& _rxControl
) const
81 if ( _rxControl
.is() )
82 _rxControl
->setDesignMode( bDesign
);
86 void FormControlContainer::implSetDesignMode( bool _bDesign
)
90 Reference
< XControlContainer
> xControlCont
= getControlContainer();
91 Sequence
< Reference
< XControl
> > aControls
;
92 if ( xControlCont
.is() )
93 aControls
= xControlCont
->getControls();
98 ControlModeSwitch( _bDesign
)
101 catch( const Exception
&)
103 OSL_FAIL( "FormControlContainer::implSetDesignMode: caught an exception!" );
107 void FormControlContainer::_loaded( const css::lang::EventObject
& /*_rEvent*/ )
109 implSetDesignMode( false );
112 void FormControlContainer::_unloading( const css::lang::EventObject
& /*_rEvent*/ )
114 implSetDesignMode( true );
117 void FormControlContainer::_unloaded( const css::lang::EventObject
& /*_rEvent*/ )
121 void FormControlContainer::_reloading( const css::lang::EventObject
& /*_rEvent*/ )
123 implSetDesignMode( true );
126 void FormControlContainer::_reloaded( const css::lang::EventObject
& /*_rEvent*/ )
128 implSetDesignMode( false );
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */