1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dialogcontrolling.cxx,v $
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>
39 //........................................................................
42 //........................................................................
44 //=====================================================================
46 //=====================================================================
47 //---------------------------------------------------------------------
48 IWindowOperator::~IWindowOperator()
52 //=====================================================================
53 //= IWindowEventFilter
54 //=====================================================================
55 //---------------------------------------------------------------------
56 IWindowEventFilter::~IWindowEventFilter()
60 //=====================================================================
61 //= DialogController_Data
62 //=====================================================================
63 struct DialogController_Data
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 //=====================================================================
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()
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
);
112 VclWindowEvent
aEvent( &_rWindow
, 0, NULL
);
113 impl_update( aEvent
, _rWindow
);
116 //---------------------------------------------------------------------
117 IMPL_LINK( DialogController
, OnWindowEvent
, const VclWindowEvent
*, _pEvent
)
119 if ( m_pImpl
->pEventFilter
->payAttentionTo( *_pEvent
) )
120 impl_updateAll( *_pEvent
);
124 //---------------------------------------------------------------------
125 void DialogController::impl_updateAll( const VclWindowEvent
& _rTriggerEvent
)
127 for ( ::std::vector
< Window
* >::iterator loop
= m_pImpl
->aConcernedWindows
.begin();
128 loop
!= m_pImpl
->aConcernedWindows
.end();
131 impl_update( _rTriggerEvent
, *(*loop
) );
134 //---------------------------------------------------------------------
135 void DialogController::impl_update( const VclWindowEvent
& _rTriggerEvent
, Window
& _rWindow
)
137 m_pImpl
->pOperator
->operateOn( _rTriggerEvent
, _rWindow
);
140 //=====================================================================
141 //= ControlDependencyManager_Data
142 //=====================================================================
143 struct ControlDependencyManager_Data
145 ::std::vector
< PDialogController
> aControllers
;
148 //=====================================================================
149 //= ControlDependencyManager
150 //=====================================================================
151 //---------------------------------------------------------------------
152 ControlDependencyManager::ControlDependencyManager()
153 :m_pImpl( new ControlDependencyManager_Data
)
157 //---------------------------------------------------------------------
158 ControlDependencyManager::~ControlDependencyManager()
162 //---------------------------------------------------------------------
165 struct ResetDialogController
: public ::std::unary_function
< const PDialogController
&, void >
167 void operator()( const PDialogController
& _pController
)
169 _pController
->reset();
174 //---------------------------------------------------------------------
175 void ControlDependencyManager::clear()
177 ::std::for_each( m_pImpl
->aControllers
.begin(), m_pImpl
->aControllers
.end(), ResetDialogController() );
178 m_pImpl
->aControllers
.clear();
181 //---------------------------------------------------------------------
182 void ControlDependencyManager::addController( const PDialogController
& _pController
)
184 OSL_ENSURE( _pController
.get() != NULL
, "ControlDependencyManager::addController: invalid controller, this will crash, sooner or later!" );
185 m_pImpl
->aControllers
.push_back( _pController
);
188 //---------------------------------------------------------------------
189 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow
)
191 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
192 pController
->addDependentWindow( _rDependentWindow
);
193 m_pImpl
->aControllers
.push_back( pController
);
196 //---------------------------------------------------------------------
197 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
)
199 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
200 pController
->addDependentWindow( _rDependentWindow1
);
201 pController
->addDependentWindow( _rDependentWindow2
);
202 m_pImpl
->aControllers
.push_back( pController
);
205 //---------------------------------------------------------------------
206 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
)
208 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
209 pController
->addDependentWindow( _rDependentWindow1
);
210 pController
->addDependentWindow( _rDependentWindow2
);
211 pController
->addDependentWindow( _rDependentWindow3
);
212 m_pImpl
->aControllers
.push_back( pController
);
215 //---------------------------------------------------------------------
216 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
, Window
& _rDependentWindow4
)
218 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
219 pController
->addDependentWindow( _rDependentWindow1
);
220 pController
->addDependentWindow( _rDependentWindow2
);
221 pController
->addDependentWindow( _rDependentWindow3
);
222 pController
->addDependentWindow( _rDependentWindow4
);
223 m_pImpl
->aControllers
.push_back( pController
);
226 //---------------------------------------------------------------------
227 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
, Window
& _rDependentWindow4
, Window
& _rDependentWindow5
)
229 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
230 pController
->addDependentWindow( _rDependentWindow1
);
231 pController
->addDependentWindow( _rDependentWindow2
);
232 pController
->addDependentWindow( _rDependentWindow3
);
233 pController
->addDependentWindow( _rDependentWindow4
);
234 pController
->addDependentWindow( _rDependentWindow5
);
235 m_pImpl
->aControllers
.push_back( pController
);
238 //---------------------------------------------------------------------
239 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
, Window
& _rDependentWindow4
, Window
& _rDependentWindow5
, Window
& _rDependentWindow6
)
241 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
242 pController
->addDependentWindow( _rDependentWindow1
);
243 pController
->addDependentWindow( _rDependentWindow2
);
244 pController
->addDependentWindow( _rDependentWindow3
);
245 pController
->addDependentWindow( _rDependentWindow4
);
246 pController
->addDependentWindow( _rDependentWindow5
);
247 pController
->addDependentWindow( _rDependentWindow6
);
248 m_pImpl
->aControllers
.push_back( pController
);
251 //---------------------------------------------------------------------
252 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow
)
254 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
255 pController
->addDependentWindow( _rDependentWindow
);
256 m_pImpl
->aControllers
.push_back( pController
);
259 //---------------------------------------------------------------------
260 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
)
262 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
263 pController
->addDependentWindow( _rDependentWindow1
);
264 pController
->addDependentWindow( _rDependentWindow2
);
265 m_pImpl
->aControllers
.push_back( pController
);
268 //---------------------------------------------------------------------
269 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
)
271 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
272 pController
->addDependentWindow( _rDependentWindow1
);
273 pController
->addDependentWindow( _rDependentWindow2
);
274 pController
->addDependentWindow( _rDependentWindow3
);
275 m_pImpl
->aControllers
.push_back( pController
);
278 //---------------------------------------------------------------------
279 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
, Window
& _rDependentWindow4
)
281 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
282 pController
->addDependentWindow( _rDependentWindow1
);
283 pController
->addDependentWindow( _rDependentWindow2
);
284 pController
->addDependentWindow( _rDependentWindow3
);
285 pController
->addDependentWindow( _rDependentWindow4
);
286 m_pImpl
->aControllers
.push_back( pController
);
289 //---------------------------------------------------------------------
290 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
, Window
& _rDependentWindow4
, Window
& _rDependentWindow5
)
292 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
293 pController
->addDependentWindow( _rDependentWindow1
);
294 pController
->addDependentWindow( _rDependentWindow2
);
295 pController
->addDependentWindow( _rDependentWindow3
);
296 pController
->addDependentWindow( _rDependentWindow4
);
297 pController
->addDependentWindow( _rDependentWindow5
);
298 m_pImpl
->aControllers
.push_back( pController
);
301 //---------------------------------------------------------------------
302 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, Window
& _rDependentWindow1
, Window
& _rDependentWindow2
, Window
& _rDependentWindow3
, Window
& _rDependentWindow4
, Window
& _rDependentWindow5
, Window
& _rDependentWindow6
)
304 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
305 pController
->addDependentWindow( _rDependentWindow1
);
306 pController
->addDependentWindow( _rDependentWindow2
);
307 pController
->addDependentWindow( _rDependentWindow3
);
308 pController
->addDependentWindow( _rDependentWindow4
);
309 pController
->addDependentWindow( _rDependentWindow5
);
310 pController
->addDependentWindow( _rDependentWindow6
);
311 m_pImpl
->aControllers
.push_back( pController
);
314 //........................................................................
316 //........................................................................