1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
30 #include "formcontrolcontainer.hxx"
31 #include <tools/debug.hxx>
36 //.........................................................................
39 //.........................................................................
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::form
;
43 using namespace ::com::sun::star::lang
;
44 using namespace ::com::sun::star::awt
;
46 //=====================================================================
47 //= FormControlContainer
48 //=====================================================================
49 //---------------------------------------------------------------------
50 FormControlContainer::FormControlContainer( )
51 :OLoadListener( m_aMutex
)
52 ,m_pFormAdapter( NULL
)
56 //---------------------------------------------------------------------
57 //--- 18.10.01 18:54:57 -----------------------------------------------
58 FormControlContainer::~FormControlContainer( )
60 DBG_ASSERT( !isFormConnected(), "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" );
61 if ( isFormConnected() )
65 //---------------------------------------------------------------------
66 //--- 18.10.01 17:03:14 -----------------------------------------------
67 void FormControlContainer::disconnectForm()
69 ::osl::MutexGuard
aGuard( m_aMutex
);
70 DBG_ASSERT( isFormConnected(), "FormControlContainer::connectForm: not connected!" );
71 if ( isFormConnected() )
73 m_pFormAdapter
->dispose();
74 m_pFormAdapter
->release();
75 m_pFormAdapter
= NULL
;
79 //---------------------------------------------------------------------
80 //--- 18.10.01 16:56:01 -----------------------------------------------
81 void FormControlContainer::connectForm( const Reference
< XLoadable
>& _rxForm
)
83 DBG_ASSERT( !isFormConnected(), "FormControlContainer::connectForm: already connected!" );
85 DBG_ASSERT( _rxForm
.is(), "FormControlContainer::connectForm: invalid form!" );
86 if ( !isFormConnected() && _rxForm
.is() )
88 m_pFormAdapter
= new OLoadListenerAdapter( _rxForm
);
89 m_pFormAdapter
->acquire();
90 m_pFormAdapter
->Init( this );
98 //---------------------------------------------------------------------
99 //--- 18.10.01 18:50:14 -----------------------------------------------
100 struct ControlModeSwitch
: public ::std::unary_function
< Reference
< XControl
>, void >
103 ControlModeSwitch( sal_Bool _bDesign
) : bDesign( _bDesign
) { }
105 void operator() ( const Reference
< XControl
>& _rxControl
) const
107 if ( _rxControl
.is() )
108 _rxControl
->setDesignMode( bDesign
);
112 //---------------------------------------------------------------------
113 //--- 18.10.01 18:49:57 -----------------------------------------------
114 void FormControlContainer::implSetDesignMode( sal_Bool _bDesign
)
118 Reference
< XControlContainer
> xControlCont
= getControlContainer();
119 Sequence
< Reference
< XControl
> > aControls
;
120 if ( xControlCont
.is() )
121 aControls
= xControlCont
->getControls();
124 aControls
.getConstArray(),
125 aControls
.getConstArray() + aControls
.getLength(),
126 ControlModeSwitch( _bDesign
)
129 catch( const Exception
& e
)
131 (void) e
; // make compiler happy
132 DBG_ERROR( "FormControlContainer::implSetDesignMode: caught an exception!" );
136 //---------------------------------------------------------------------
137 //--- 18.10.01 18:16:54 -----------------------------------------------
138 void FormControlContainer::ensureDesignMode()
140 implSetDesignMode( !m_xForm
.is() || !m_xForm
->isLoaded() );
143 //---------------------------------------------------------------------
144 //--- 18.10.01 16:45:33 -----------------------------------------------
145 void FormControlContainer::_loaded( const ::com::sun::star::lang::EventObject
& /*_rEvent*/ )
147 implSetDesignMode( sal_False
);
150 //---------------------------------------------------------------------
151 //--- 18.10.01 16:45:35 -----------------------------------------------
152 void FormControlContainer::_unloading( const ::com::sun::star::lang::EventObject
& /*_rEvent*/ )
154 implSetDesignMode( sal_True
);
157 //---------------------------------------------------------------------
158 //--- 18.10.01 16:45:36 -----------------------------------------------
159 void FormControlContainer::_unloaded( const ::com::sun::star::lang::EventObject
& /*_rEvent*/ )
163 //---------------------------------------------------------------------
164 //--- 18.10.01 16:45:36 -----------------------------------------------
165 void FormControlContainer::_reloading( const ::com::sun::star::lang::EventObject
& /*_rEvent*/ )
167 implSetDesignMode( sal_True
);
170 //---------------------------------------------------------------------
171 //--- 18.10.01 16:45:37 -----------------------------------------------
172 void FormControlContainer::_reloaded( const ::com::sun::star::lang::EventObject
& /*_rEvent*/ )
174 implSetDesignMode( sal_False
);
177 //.........................................................................
179 //.........................................................................