Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "formcontrolcontainer.hxx"
30 : : #include <tools/debug.hxx>
31 : :
32 : : #include <algorithm>
33 : : #include <functional>
34 : :
35 : : //.........................................................................
36 : : namespace bib
37 : : {
38 : : //.........................................................................
39 : :
40 : : using namespace ::com::sun::star::uno;
41 : : using namespace ::com::sun::star::form;
42 : : using namespace ::com::sun::star::lang;
43 : : using namespace ::com::sun::star::awt;
44 : :
45 : : //=====================================================================
46 : : //= FormControlContainer
47 : : //=====================================================================
48 : : //---------------------------------------------------------------------
49 : 0 : FormControlContainer::FormControlContainer( )
50 : : :OLoadListener( m_aMutex )
51 [ # # ]: 0 : ,m_pFormAdapter( NULL )
52 : : {
53 : 0 : }
54 : :
55 [ # # ]: 0 : FormControlContainer::~FormControlContainer( )
56 : : {
57 : : DBG_ASSERT( !isFormConnected(), "FormControlContainer::~FormControlContainer: you should disconnect in your derived class!" );
58 [ # # ]: 0 : if ( isFormConnected() )
59 [ # # ]: 0 : disconnectForm();
60 [ # # ]: 0 : }
61 : :
62 : 0 : void FormControlContainer::disconnectForm()
63 : : {
64 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
65 : : DBG_ASSERT( isFormConnected(), "FormControlContainer::connectForm: not connected!" );
66 [ # # ]: 0 : if ( isFormConnected() )
67 : : {
68 [ # # ]: 0 : m_pFormAdapter->dispose();
69 : 0 : m_pFormAdapter->release();
70 : 0 : m_pFormAdapter = NULL;
71 [ # # ]: 0 : }
72 : 0 : }
73 : :
74 : 0 : void FormControlContainer::connectForm( const Reference< XLoadable >& _rxForm )
75 : : {
76 : : DBG_ASSERT( !isFormConnected(), "FormControlContainer::connectForm: already connected!" );
77 : :
78 : : DBG_ASSERT( _rxForm.is(), "FormControlContainer::connectForm: invalid form!" );
79 [ # # ][ # # ]: 0 : if ( !isFormConnected() && _rxForm.is() )
[ # # ]
80 : : {
81 [ # # ]: 0 : m_pFormAdapter = new OLoadListenerAdapter( _rxForm );
82 : 0 : m_pFormAdapter->acquire();
83 : 0 : m_pFormAdapter->Init( this );
84 : :
85 : 0 : ensureDesignMode();
86 : : }
87 : :
88 : 0 : m_xForm = _rxForm;
89 : 0 : }
90 : :
91 : : struct ControlModeSwitch : public ::std::unary_function< Reference< XControl >, void >
92 : : {
93 : : sal_Bool bDesign;
94 : 0 : ControlModeSwitch( sal_Bool _bDesign ) : bDesign( _bDesign ) { }
95 : :
96 : 0 : void operator() ( const Reference< XControl >& _rxControl ) const
97 : : {
98 [ # # ]: 0 : if ( _rxControl.is() )
99 : 0 : _rxControl->setDesignMode( bDesign );
100 : 0 : }
101 : : };
102 : :
103 : 0 : void FormControlContainer::implSetDesignMode( sal_Bool _bDesign )
104 : : {
105 : : try
106 : : {
107 [ # # ]: 0 : Reference< XControlContainer > xControlCont = getControlContainer();
108 [ # # ]: 0 : Sequence< Reference< XControl > > aControls;
109 [ # # ]: 0 : if ( xControlCont.is() )
110 [ # # ][ # # ]: 0 : aControls = xControlCont->getControls();
[ # # ][ # # ]
111 : :
112 : : ::std::for_each(
113 : : aControls.getConstArray(),
114 : 0 : aControls.getConstArray() + aControls.getLength(),
115 : : ControlModeSwitch( _bDesign )
116 [ # # ][ # # ]: 0 : );
[ # # ]
117 : : }
118 : 0 : catch( const Exception& e)
119 : : {
120 : : (void) e; // make compiler happy
121 : : OSL_FAIL( "FormControlContainer::implSetDesignMode: caught an exception!" );
122 : : }
123 : 0 : }
124 : :
125 : 0 : void FormControlContainer::ensureDesignMode()
126 : : {
127 [ # # ][ # # ]: 0 : implSetDesignMode( !m_xForm.is() || !m_xForm->isLoaded() );
128 : 0 : }
129 : :
130 : 0 : void FormControlContainer::_loaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
131 : : {
132 : 0 : implSetDesignMode( sal_False );
133 : 0 : }
134 : :
135 : 0 : void FormControlContainer::_unloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
136 : : {
137 : 0 : implSetDesignMode( sal_True );
138 : 0 : }
139 : :
140 : 0 : void FormControlContainer::_unloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
141 : : {
142 : 0 : }
143 : :
144 : 0 : void FormControlContainer::_reloading( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
145 : : {
146 : 0 : implSetDesignMode( sal_True );
147 : 0 : }
148 : :
149 : 0 : void FormControlContainer::_reloaded( const ::com::sun::star::lang::EventObject& /*_rEvent*/ )
150 : : {
151 : 0 : implSetDesignMode( sal_False );
152 : 0 : }
153 : :
154 : : //.........................................................................
155 : : } // namespace bib
156 : : //.........................................................................
157 : :
158 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|