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 <sal/log.hxx>
22 #include <comphelper/diagnose_ex.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() );
76 struct ControlModeSwitch
79 explicit ControlModeSwitch( bool _bDesign
) : bDesign( _bDesign
) { }
81 void operator() ( const Reference
< XControl
>& _rxControl
) const
83 if ( _rxControl
.is() )
84 _rxControl
->setDesignMode( bDesign
);
90 void FormControlContainer::implSetDesignMode( bool _bDesign
)
94 Reference
< XControlContainer
> xControlCont
= getControlContainer();
95 if ( xControlCont
.is() )
97 const Sequence
<Reference
<XControl
>> aControls
= xControlCont
->getControls();
102 ControlModeSwitch( _bDesign
)
106 catch( const Exception
&)
108 TOOLS_WARN_EXCEPTION( "extensions.biblio", "FormControlContainer::implSetDesignMode" );
112 void FormControlContainer::_loaded( const css::lang::EventObject
& /*_rEvent*/ )
114 implSetDesignMode( false );
117 void FormControlContainer::_unloading( const css::lang::EventObject
& /*_rEvent*/ )
119 implSetDesignMode( true );
122 void FormControlContainer::_reloading( const css::lang::EventObject
& /*_rEvent*/ )
124 implSetDesignMode( true );
127 void FormControlContainer::_reloaded( const css::lang::EventObject
& /*_rEvent*/ )
129 implSetDesignMode( false );
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */