update dev300-m57
[ooovba.git] / svtools / source / misc / dialogcontrolling.cxx
blobab25489bdd6d3aeea22ffcabe84c8f0d0c164de5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dialogcontrolling.cxx,v $
10 * $Revision: 1.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include "dialogcontrolling.hxx"
34 #include <vcl/window.hxx>
36 #include <algorithm>
37 #include <functional>
39 //........................................................................
40 namespace svt
42 //........................................................................
44 //=====================================================================
45 //= IWindowOperator
46 //=====================================================================
47 //---------------------------------------------------------------------
48 IWindowOperator::~IWindowOperator()
52 //=====================================================================
53 //= IWindowEventFilter
54 //=====================================================================
55 //---------------------------------------------------------------------
56 IWindowEventFilter::~IWindowEventFilter()
60 //=====================================================================
61 //= DialogController_Data
62 //=====================================================================
63 struct DialogController_Data
65 Window& rInstigator;
66 ::std::vector< Window* > aConcernedWindows;
67 PWindowEventFilter pEventFilter;
68 PWindowOperator pOperator;
70 DialogController_Data( Window& _rInstigator, const PWindowEventFilter _pEventFilter, const PWindowOperator _pOperator )
71 :rInstigator( _rInstigator )
72 ,pEventFilter( _pEventFilter )
73 ,pOperator( _pOperator )
78 //=====================================================================
79 //= DialogController
80 //=====================================================================
81 //---------------------------------------------------------------------
82 DialogController::DialogController( Window& _rInstigator, const PWindowEventFilter _pEventFilter,
83 const PWindowOperator _pOperator )
84 :m_pImpl( new DialogController_Data( _rInstigator, _pEventFilter, _pOperator ) )
86 DBG_ASSERT( m_pImpl->pEventFilter.get() && m_pImpl->pOperator.get(),
87 "DialogController::DialogController: invalid filter and/or operator!" );
89 m_pImpl->rInstigator.AddEventListener( LINK( this, DialogController, OnWindowEvent ) );
92 //---------------------------------------------------------------------
93 DialogController::~DialogController()
95 reset();
98 //---------------------------------------------------------------------
99 void DialogController::reset()
101 m_pImpl->rInstigator.RemoveEventListener( LINK( this, DialogController, OnWindowEvent ) );
102 m_pImpl->aConcernedWindows.clear();
103 m_pImpl->pEventFilter.reset();
104 m_pImpl->pOperator.reset();
107 //---------------------------------------------------------------------
108 void DialogController::addDependentWindow( Window& _rWindow )
110 m_pImpl->aConcernedWindows.push_back( &_rWindow );
111 impl_update( _rWindow );
114 //---------------------------------------------------------------------
115 IMPL_LINK( DialogController, OnWindowEvent, const VclSimpleEvent*, _pEvent )
117 if ( m_pImpl->pEventFilter->payAttentionTo( *_pEvent ) )
118 impl_updateAll();
119 return 0L;
122 //---------------------------------------------------------------------
123 void DialogController::impl_updateAll()
125 for ( ::std::vector< Window* >::iterator loop = m_pImpl->aConcernedWindows.begin();
126 loop != m_pImpl->aConcernedWindows.end();
127 ++loop
129 impl_update( *(*loop) );
132 //---------------------------------------------------------------------
133 void DialogController::impl_update( Window& _rWindow )
135 m_pImpl->pOperator->operateOn( _rWindow );
138 //=====================================================================
139 //= ControlDependencyManager_Data
140 //=====================================================================
141 struct ControlDependencyManager_Data
143 ::std::vector< PDialogController > aControllers;
146 //=====================================================================
147 //= ControlDependencyManager
148 //=====================================================================
149 //---------------------------------------------------------------------
150 ControlDependencyManager::ControlDependencyManager()
151 :m_pImpl( new ControlDependencyManager_Data )
155 //---------------------------------------------------------------------
156 ControlDependencyManager::~ControlDependencyManager()
160 //---------------------------------------------------------------------
161 namespace
163 struct ResetDialogController : public ::std::unary_function< const PDialogController&, void >
165 void operator()( const PDialogController& _pController )
167 _pController->reset();
172 //---------------------------------------------------------------------
173 void ControlDependencyManager::clear()
175 ::std::for_each( m_pImpl->aControllers.begin(), m_pImpl->aControllers.end(), ResetDialogController() );
176 m_pImpl->aControllers.clear();
179 //---------------------------------------------------------------------
180 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow )
182 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
183 pController->addDependentWindow( _rDependentWindow );
184 m_pImpl->aControllers.push_back( pController );
187 //---------------------------------------------------------------------
188 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2 )
190 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
191 pController->addDependentWindow( _rDependentWindow1 );
192 pController->addDependentWindow( _rDependentWindow2 );
193 m_pImpl->aControllers.push_back( pController );
196 //---------------------------------------------------------------------
197 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3 )
199 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
200 pController->addDependentWindow( _rDependentWindow1 );
201 pController->addDependentWindow( _rDependentWindow2 );
202 pController->addDependentWindow( _rDependentWindow3 );
203 m_pImpl->aControllers.push_back( pController );
206 //---------------------------------------------------------------------
207 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4 )
209 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
210 pController->addDependentWindow( _rDependentWindow1 );
211 pController->addDependentWindow( _rDependentWindow2 );
212 pController->addDependentWindow( _rDependentWindow3 );
213 pController->addDependentWindow( _rDependentWindow4 );
214 m_pImpl->aControllers.push_back( pController );
217 //---------------------------------------------------------------------
218 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5 )
220 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
221 pController->addDependentWindow( _rDependentWindow1 );
222 pController->addDependentWindow( _rDependentWindow2 );
223 pController->addDependentWindow( _rDependentWindow3 );
224 pController->addDependentWindow( _rDependentWindow4 );
225 pController->addDependentWindow( _rDependentWindow5 );
226 m_pImpl->aControllers.push_back( pController );
229 //---------------------------------------------------------------------
230 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5, Window& _rDependentWindow6 )
232 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
233 pController->addDependentWindow( _rDependentWindow1 );
234 pController->addDependentWindow( _rDependentWindow2 );
235 pController->addDependentWindow( _rDependentWindow3 );
236 pController->addDependentWindow( _rDependentWindow4 );
237 pController->addDependentWindow( _rDependentWindow5 );
238 pController->addDependentWindow( _rDependentWindow6 );
239 m_pImpl->aControllers.push_back( pController );
242 //---------------------------------------------------------------------
243 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow )
245 PDialogController pController( new RadioDependentEnabler( _rBox ) );
246 pController->addDependentWindow( _rDependentWindow );
247 m_pImpl->aControllers.push_back( pController );
250 //---------------------------------------------------------------------
251 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2 )
253 PDialogController pController( new RadioDependentEnabler( _rBox ) );
254 pController->addDependentWindow( _rDependentWindow1 );
255 pController->addDependentWindow( _rDependentWindow2 );
256 m_pImpl->aControllers.push_back( pController );
259 //---------------------------------------------------------------------
260 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3 )
262 PDialogController pController( new RadioDependentEnabler( _rBox ) );
263 pController->addDependentWindow( _rDependentWindow1 );
264 pController->addDependentWindow( _rDependentWindow2 );
265 pController->addDependentWindow( _rDependentWindow3 );
266 m_pImpl->aControllers.push_back( pController );
269 //---------------------------------------------------------------------
270 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4 )
272 PDialogController pController( new RadioDependentEnabler( _rBox ) );
273 pController->addDependentWindow( _rDependentWindow1 );
274 pController->addDependentWindow( _rDependentWindow2 );
275 pController->addDependentWindow( _rDependentWindow3 );
276 pController->addDependentWindow( _rDependentWindow4 );
277 m_pImpl->aControllers.push_back( pController );
280 //---------------------------------------------------------------------
281 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5 )
283 PDialogController pController( new RadioDependentEnabler( _rBox ) );
284 pController->addDependentWindow( _rDependentWindow1 );
285 pController->addDependentWindow( _rDependentWindow2 );
286 pController->addDependentWindow( _rDependentWindow3 );
287 pController->addDependentWindow( _rDependentWindow4 );
288 pController->addDependentWindow( _rDependentWindow5 );
289 m_pImpl->aControllers.push_back( pController );
292 //---------------------------------------------------------------------
293 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5, Window& _rDependentWindow6 )
295 PDialogController pController( new RadioDependentEnabler( _rBox ) );
296 pController->addDependentWindow( _rDependentWindow1 );
297 pController->addDependentWindow( _rDependentWindow2 );
298 pController->addDependentWindow( _rDependentWindow3 );
299 pController->addDependentWindow( _rDependentWindow4 );
300 pController->addDependentWindow( _rDependentWindow5 );
301 pController->addDependentWindow( _rDependentWindow6 );
302 m_pImpl->aControllers.push_back( pController );
305 //........................................................................
306 } // namespace svt
307 //........................................................................