1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <svtools/dialogcontrolling.hxx>
21 #include <vcl/window.hxx>
35 IWindowOperator::~IWindowOperator()
40 //= IWindowEventFilter
43 IWindowEventFilter::~IWindowEventFilter()
48 //= DialogController_Data
50 struct DialogController_Data
52 VclPtr
<vcl::Window
> xInstigator
;
53 ::std::vector
< VclPtr
<vcl::Window
> > aConcernedWindows
;
54 PWindowEventFilter pEventFilter
;
55 PWindowOperator pOperator
;
57 DialogController_Data( vcl::Window
& _xInstigator
, const PWindowEventFilter _pEventFilter
, const PWindowOperator _pOperator
)
58 :xInstigator( &_xInstigator
)
59 ,pEventFilter( _pEventFilter
)
60 ,pOperator( _pOperator
)
69 DialogController::DialogController( vcl::Window
& _xInstigator
, const PWindowEventFilter
& _pEventFilter
,
70 const PWindowOperator
& _pOperator
)
71 :m_pImpl( new DialogController_Data( _xInstigator
, _pEventFilter
, _pOperator
) )
73 DBG_ASSERT( m_pImpl
->pEventFilter
.get() && m_pImpl
->pOperator
.get(),
74 "DialogController::DialogController: invalid filter and/or operator!" );
76 m_pImpl
->xInstigator
->AddEventListener( LINK( this, DialogController
, OnWindowEvent
) );
80 DialogController::~DialogController()
86 void DialogController::reset()
88 if (m_pImpl
->xInstigator
)
89 m_pImpl
->xInstigator
->RemoveEventListener( LINK( this, DialogController
, OnWindowEvent
) );
90 m_pImpl
->xInstigator
.clear();
91 m_pImpl
->aConcernedWindows
.clear();
92 m_pImpl
->pEventFilter
.reset();
93 m_pImpl
->pOperator
.reset();
97 void DialogController::addDependentWindow( vcl::Window
& _rWindow
)
99 m_pImpl
->aConcernedWindows
.push_back( &_rWindow
);
101 VclWindowEvent
aEvent( &_rWindow
, 0, NULL
);
102 impl_update( aEvent
, _rWindow
);
106 IMPL_LINK( DialogController
, OnWindowEvent
, const VclWindowEvent
*, _pEvent
)
108 if ( m_pImpl
->pEventFilter
->payAttentionTo( *_pEvent
) )
109 impl_updateAll( *_pEvent
);
114 void DialogController::impl_updateAll( const VclWindowEvent
& _rTriggerEvent
)
116 for ( auto loop
= m_pImpl
->aConcernedWindows
.begin();
117 loop
!= m_pImpl
->aConcernedWindows
.end();
120 impl_update( _rTriggerEvent
, *(*loop
) );
124 void DialogController::impl_update( const VclWindowEvent
& _rTriggerEvent
, vcl::Window
& _rWindow
)
126 m_pImpl
->pOperator
->operateOn( _rTriggerEvent
, _rWindow
);
130 //= ControlDependencyManager_Data
132 struct ControlDependencyManager_Data
134 ::std::vector
< PDialogController
> aControllers
;
138 //= ControlDependencyManager
141 ControlDependencyManager::ControlDependencyManager()
142 :m_pImpl( new ControlDependencyManager_Data
)
147 ControlDependencyManager::~ControlDependencyManager()
154 struct ResetDialogController
: public ::std::unary_function
< const PDialogController
&, void >
156 void operator()( const PDialogController
& _pController
)
158 _pController
->reset();
164 void ControlDependencyManager::clear()
166 ::std::for_each( m_pImpl
->aControllers
.begin(), m_pImpl
->aControllers
.end(), ResetDialogController() );
167 m_pImpl
->aControllers
.clear();
171 void ControlDependencyManager::addController( const PDialogController
& _pController
)
173 OSL_ENSURE( _pController
.get() != NULL
, "ControlDependencyManager::addController: invalid controller, this will crash, sooner or later!" );
174 m_pImpl
->aControllers
.push_back( _pController
);
178 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, vcl::Window
& _rDependentWindow
)
180 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
181 pController
->addDependentWindow( _rDependentWindow
);
182 m_pImpl
->aControllers
.push_back( pController
);
186 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, vcl::Window
& _rDependentWindow1
, vcl::Window
& _rDependentWindow2
)
188 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
189 pController
->addDependentWindow( _rDependentWindow1
);
190 pController
->addDependentWindow( _rDependentWindow2
);
191 m_pImpl
->aControllers
.push_back( pController
);
195 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, vcl::Window
& _rDependentWindow1
, vcl::Window
& _rDependentWindow2
, vcl::Window
& _rDependentWindow3
)
197 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
198 pController
->addDependentWindow( _rDependentWindow1
);
199 pController
->addDependentWindow( _rDependentWindow2
);
200 pController
->addDependentWindow( _rDependentWindow3
);
201 m_pImpl
->aControllers
.push_back( pController
);
205 void ControlDependencyManager::enableOnRadioCheck( RadioButton
& _rRadio
, vcl::Window
& _rDependentWindow1
, vcl::Window
& _rDependentWindow2
, vcl::Window
& _rDependentWindow3
, vcl::Window
& _rDependentWindow4
, vcl::Window
& _rDependentWindow5
)
207 PDialogController
pController( new RadioDependentEnabler( _rRadio
) );
208 pController
->addDependentWindow( _rDependentWindow1
);
209 pController
->addDependentWindow( _rDependentWindow2
);
210 pController
->addDependentWindow( _rDependentWindow3
);
211 pController
->addDependentWindow( _rDependentWindow4
);
212 pController
->addDependentWindow( _rDependentWindow5
);
213 m_pImpl
->aControllers
.push_back( pController
);
217 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, vcl::Window
& _rDependentWindow
)
219 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
220 pController
->addDependentWindow( _rDependentWindow
);
221 m_pImpl
->aControllers
.push_back( pController
);
225 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, vcl::Window
& _rDependentWindow1
, vcl::Window
& _rDependentWindow2
)
227 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
228 pController
->addDependentWindow( _rDependentWindow1
);
229 pController
->addDependentWindow( _rDependentWindow2
);
230 m_pImpl
->aControllers
.push_back( pController
);
234 void ControlDependencyManager::enableOnCheckMark( CheckBox
& _rBox
, vcl::Window
& _rDependentWindow1
, vcl::Window
& _rDependentWindow2
, vcl::Window
& _rDependentWindow3
, vcl::Window
& _rDependentWindow4
)
236 PDialogController
pController( new RadioDependentEnabler( _rBox
) );
237 pController
->addDependentWindow( _rDependentWindow1
);
238 pController
->addDependentWindow( _rDependentWindow2
);
239 pController
->addDependentWindow( _rDependentWindow3
);
240 pController
->addDependentWindow( _rDependentWindow4
);
241 m_pImpl
->aControllers
.push_back( pController
);
248 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */