xref: /AOO41X/main/svtools/source/misc/dialogcontrolling.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svtools.hxx"
30*cdf0e10cSrcweir #include <svtools/dialogcontrolling.hxx>
31*cdf0e10cSrcweir #include <vcl/window.hxx>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include <algorithm>
34*cdf0e10cSrcweir #include <functional>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir //........................................................................
37*cdf0e10cSrcweir namespace svt
38*cdf0e10cSrcweir {
39*cdf0e10cSrcweir //........................................................................
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir     //=====================================================================
42*cdf0e10cSrcweir     //= IWindowOperator
43*cdf0e10cSrcweir     //=====================================================================
44*cdf0e10cSrcweir 	//---------------------------------------------------------------------
45*cdf0e10cSrcweir     IWindowOperator::~IWindowOperator()
46*cdf0e10cSrcweir     {
47*cdf0e10cSrcweir     }
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir     //=====================================================================
50*cdf0e10cSrcweir     //= IWindowEventFilter
51*cdf0e10cSrcweir     //=====================================================================
52*cdf0e10cSrcweir 	//---------------------------------------------------------------------
53*cdf0e10cSrcweir     IWindowEventFilter::~IWindowEventFilter()
54*cdf0e10cSrcweir     {
55*cdf0e10cSrcweir     }
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     //=====================================================================
58*cdf0e10cSrcweir     //= DialogController_Data
59*cdf0e10cSrcweir     //=====================================================================
60*cdf0e10cSrcweir     struct DialogController_Data
61*cdf0e10cSrcweir     {
62*cdf0e10cSrcweir         Window&                     rInstigator;
63*cdf0e10cSrcweir         ::std::vector< Window* >    aConcernedWindows;
64*cdf0e10cSrcweir         PWindowEventFilter          pEventFilter;
65*cdf0e10cSrcweir         PWindowOperator             pOperator;
66*cdf0e10cSrcweir 
67*cdf0e10cSrcweir         DialogController_Data( Window& _rInstigator, const PWindowEventFilter _pEventFilter, const PWindowOperator _pOperator )
68*cdf0e10cSrcweir             :rInstigator( _rInstigator )
69*cdf0e10cSrcweir             ,pEventFilter( _pEventFilter )
70*cdf0e10cSrcweir             ,pOperator( _pOperator )
71*cdf0e10cSrcweir         {
72*cdf0e10cSrcweir         }
73*cdf0e10cSrcweir     };
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     //=====================================================================
76*cdf0e10cSrcweir     //= DialogController
77*cdf0e10cSrcweir     //=====================================================================
78*cdf0e10cSrcweir 	//---------------------------------------------------------------------
79*cdf0e10cSrcweir     DialogController::DialogController( Window& _rInstigator, const PWindowEventFilter& _pEventFilter,
80*cdf0e10cSrcweir             const PWindowOperator& _pOperator )
81*cdf0e10cSrcweir         :m_pImpl( new DialogController_Data( _rInstigator, _pEventFilter, _pOperator ) )
82*cdf0e10cSrcweir     {
83*cdf0e10cSrcweir         DBG_ASSERT( m_pImpl->pEventFilter.get() && m_pImpl->pOperator.get(),
84*cdf0e10cSrcweir             "DialogController::DialogController: invalid filter and/or operator!" );
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir         m_pImpl->rInstigator.AddEventListener( LINK( this, DialogController, OnWindowEvent ) );
87*cdf0e10cSrcweir     }
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     //---------------------------------------------------------------------
90*cdf0e10cSrcweir     DialogController::~DialogController()
91*cdf0e10cSrcweir     {
92*cdf0e10cSrcweir         reset();
93*cdf0e10cSrcweir     }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir     //---------------------------------------------------------------------
96*cdf0e10cSrcweir     void DialogController::reset()
97*cdf0e10cSrcweir     {
98*cdf0e10cSrcweir         m_pImpl->rInstigator.RemoveEventListener( LINK( this, DialogController, OnWindowEvent ) );
99*cdf0e10cSrcweir         m_pImpl->aConcernedWindows.clear();
100*cdf0e10cSrcweir         m_pImpl->pEventFilter.reset();
101*cdf0e10cSrcweir         m_pImpl->pOperator.reset();
102*cdf0e10cSrcweir     }
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir     //---------------------------------------------------------------------
105*cdf0e10cSrcweir     void DialogController::addDependentWindow( Window& _rWindow )
106*cdf0e10cSrcweir     {
107*cdf0e10cSrcweir         m_pImpl->aConcernedWindows.push_back( &_rWindow );
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir         VclWindowEvent aEvent( &_rWindow, 0, NULL );
110*cdf0e10cSrcweir         impl_update( aEvent, _rWindow );
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     //---------------------------------------------------------------------
114*cdf0e10cSrcweir     IMPL_LINK( DialogController, OnWindowEvent, const VclWindowEvent*, _pEvent )
115*cdf0e10cSrcweir     {
116*cdf0e10cSrcweir         if ( m_pImpl->pEventFilter->payAttentionTo( *_pEvent ) )
117*cdf0e10cSrcweir             impl_updateAll( *_pEvent );
118*cdf0e10cSrcweir         return 0L;
119*cdf0e10cSrcweir     }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir     //---------------------------------------------------------------------
122*cdf0e10cSrcweir     void DialogController::impl_updateAll( const VclWindowEvent& _rTriggerEvent )
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         for ( ::std::vector< Window* >::iterator loop = m_pImpl->aConcernedWindows.begin();
125*cdf0e10cSrcweir                 loop != m_pImpl->aConcernedWindows.end();
126*cdf0e10cSrcweir                 ++loop
127*cdf0e10cSrcweir             )
128*cdf0e10cSrcweir             impl_update( _rTriggerEvent, *(*loop) );
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     //---------------------------------------------------------------------
132*cdf0e10cSrcweir     void DialogController::impl_update( const VclWindowEvent& _rTriggerEvent, Window& _rWindow )
133*cdf0e10cSrcweir     {
134*cdf0e10cSrcweir         m_pImpl->pOperator->operateOn( _rTriggerEvent, _rWindow );
135*cdf0e10cSrcweir     }
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir     //=====================================================================
138*cdf0e10cSrcweir     //= ControlDependencyManager_Data
139*cdf0e10cSrcweir 	//=====================================================================
140*cdf0e10cSrcweir     struct ControlDependencyManager_Data
141*cdf0e10cSrcweir     {
142*cdf0e10cSrcweir         ::std::vector< PDialogController >  aControllers;
143*cdf0e10cSrcweir     };
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir     //=====================================================================
146*cdf0e10cSrcweir     //= ControlDependencyManager
147*cdf0e10cSrcweir 	//=====================================================================
148*cdf0e10cSrcweir     //---------------------------------------------------------------------
149*cdf0e10cSrcweir     ControlDependencyManager::ControlDependencyManager()
150*cdf0e10cSrcweir         :m_pImpl( new ControlDependencyManager_Data )
151*cdf0e10cSrcweir     {
152*cdf0e10cSrcweir     }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir     //---------------------------------------------------------------------
155*cdf0e10cSrcweir     ControlDependencyManager::~ControlDependencyManager()
156*cdf0e10cSrcweir     {
157*cdf0e10cSrcweir     }
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir     //---------------------------------------------------------------------
160*cdf0e10cSrcweir     namespace
161*cdf0e10cSrcweir     {
162*cdf0e10cSrcweir         struct ResetDialogController : public ::std::unary_function< const PDialogController&, void >
163*cdf0e10cSrcweir         {
164*cdf0e10cSrcweir             void operator()( const PDialogController& _pController )
165*cdf0e10cSrcweir             {
166*cdf0e10cSrcweir                 _pController->reset();
167*cdf0e10cSrcweir             }
168*cdf0e10cSrcweir         };
169*cdf0e10cSrcweir     }
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     //---------------------------------------------------------------------
172*cdf0e10cSrcweir     void ControlDependencyManager::clear()
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         ::std::for_each( m_pImpl->aControllers.begin(), m_pImpl->aControllers.end(), ResetDialogController() );
175*cdf0e10cSrcweir         m_pImpl->aControllers.clear();
176*cdf0e10cSrcweir     }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir     //---------------------------------------------------------------------
179*cdf0e10cSrcweir     void ControlDependencyManager::addController( const PDialogController& _pController )
180*cdf0e10cSrcweir     {
181*cdf0e10cSrcweir         OSL_ENSURE( _pController.get() != NULL, "ControlDependencyManager::addController: invalid controller, this will crash, sooner or later!" );
182*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( _pController );
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir     //---------------------------------------------------------------------
186*cdf0e10cSrcweir     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow )
187*cdf0e10cSrcweir     {
188*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
189*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow );
190*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
191*cdf0e10cSrcweir     }
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     //---------------------------------------------------------------------
194*cdf0e10cSrcweir     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2 )
195*cdf0e10cSrcweir     {
196*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
197*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
198*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
199*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
200*cdf0e10cSrcweir     }
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir     //---------------------------------------------------------------------
203*cdf0e10cSrcweir     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3 )
204*cdf0e10cSrcweir     {
205*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
206*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
207*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
208*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow3 );
209*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
210*cdf0e10cSrcweir     }
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     //---------------------------------------------------------------------
213*cdf0e10cSrcweir     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4 )
214*cdf0e10cSrcweir     {
215*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
216*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
217*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
218*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow3 );
219*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow4 );
220*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
221*cdf0e10cSrcweir     }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir     //---------------------------------------------------------------------
224*cdf0e10cSrcweir     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5 )
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
227*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
228*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
229*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow3 );
230*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow4 );
231*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow5 );
232*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir     //---------------------------------------------------------------------
236*cdf0e10cSrcweir     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5, Window& _rDependentWindow6 )
237*cdf0e10cSrcweir     {
238*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
239*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
240*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
241*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow3 );
242*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow4 );
243*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow5 );
244*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow6 );
245*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     //---------------------------------------------------------------------
249*cdf0e10cSrcweir     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow )
250*cdf0e10cSrcweir     {
251*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rBox ) );
252*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow );
253*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir     //---------------------------------------------------------------------
257*cdf0e10cSrcweir     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2 )
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rBox ) );
260*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
261*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
262*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
263*cdf0e10cSrcweir     }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir     //---------------------------------------------------------------------
266*cdf0e10cSrcweir     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3 )
267*cdf0e10cSrcweir     {
268*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rBox ) );
269*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
270*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
271*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow3 );
272*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
273*cdf0e10cSrcweir     }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir     //---------------------------------------------------------------------
276*cdf0e10cSrcweir     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4 )
277*cdf0e10cSrcweir     {
278*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rBox ) );
279*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
280*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
281*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow3 );
282*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow4 );
283*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
284*cdf0e10cSrcweir     }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir     //---------------------------------------------------------------------
287*cdf0e10cSrcweir     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5 )
288*cdf0e10cSrcweir     {
289*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rBox ) );
290*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
291*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
292*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow3 );
293*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow4 );
294*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow5 );
295*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
296*cdf0e10cSrcweir     }
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir     //---------------------------------------------------------------------
299*cdf0e10cSrcweir     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5, Window& _rDependentWindow6 )
300*cdf0e10cSrcweir     {
301*cdf0e10cSrcweir         PDialogController pController( new RadioDependentEnabler( _rBox ) );
302*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow1 );
303*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow2 );
304*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow3 );
305*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow4 );
306*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow5 );
307*cdf0e10cSrcweir         pController->addDependentWindow( _rDependentWindow6 );
308*cdf0e10cSrcweir         m_pImpl->aControllers.push_back( pController );
309*cdf0e10cSrcweir     }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir //........................................................................
312*cdf0e10cSrcweir } // namespace svt
313*cdf0e10cSrcweir //........................................................................
314*cdf0e10cSrcweir 
315