1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svtools.hxx" 26 #include <svtools/dialogcontrolling.hxx> 27 #include <vcl/window.hxx> 28 29 #include <algorithm> 30 #include <functional> 31 32 //........................................................................ 33 namespace svt 34 { 35 //........................................................................ 36 37 //===================================================================== 38 //= IWindowOperator 39 //===================================================================== 40 //--------------------------------------------------------------------- ~IWindowOperator()41 IWindowOperator::~IWindowOperator() 42 { 43 } 44 45 //===================================================================== 46 //= IWindowEventFilter 47 //===================================================================== 48 //--------------------------------------------------------------------- ~IWindowEventFilter()49 IWindowEventFilter::~IWindowEventFilter() 50 { 51 } 52 53 //===================================================================== 54 //= DialogController_Data 55 //===================================================================== 56 struct DialogController_Data 57 { 58 Window& rInstigator; 59 ::std::vector< Window* > aConcernedWindows; 60 PWindowEventFilter pEventFilter; 61 PWindowOperator pOperator; 62 DialogController_Datasvt::DialogController_Data63 DialogController_Data( Window& _rInstigator, const PWindowEventFilter _pEventFilter, const PWindowOperator _pOperator ) 64 :rInstigator( _rInstigator ) 65 ,pEventFilter( _pEventFilter ) 66 ,pOperator( _pOperator ) 67 { 68 } 69 }; 70 71 //===================================================================== 72 //= DialogController 73 //===================================================================== 74 //--------------------------------------------------------------------- DialogController(Window & _rInstigator,const PWindowEventFilter & _pEventFilter,const PWindowOperator & _pOperator)75 DialogController::DialogController( Window& _rInstigator, const PWindowEventFilter& _pEventFilter, 76 const PWindowOperator& _pOperator ) 77 :m_pImpl( new DialogController_Data( _rInstigator, _pEventFilter, _pOperator ) ) 78 { 79 DBG_ASSERT( m_pImpl->pEventFilter.get() && m_pImpl->pOperator.get(), 80 "DialogController::DialogController: invalid filter and/or operator!" ); 81 82 m_pImpl->rInstigator.AddEventListener( LINK( this, DialogController, OnWindowEvent ) ); 83 } 84 85 //--------------------------------------------------------------------- ~DialogController()86 DialogController::~DialogController() 87 { 88 reset(); 89 } 90 91 //--------------------------------------------------------------------- reset()92 void DialogController::reset() 93 { 94 m_pImpl->rInstigator.RemoveEventListener( LINK( this, DialogController, OnWindowEvent ) ); 95 m_pImpl->aConcernedWindows.clear(); 96 m_pImpl->pEventFilter.reset(); 97 m_pImpl->pOperator.reset(); 98 } 99 100 //--------------------------------------------------------------------- addDependentWindow(Window & _rWindow)101 void DialogController::addDependentWindow( Window& _rWindow ) 102 { 103 m_pImpl->aConcernedWindows.push_back( &_rWindow ); 104 105 VclWindowEvent aEvent( &_rWindow, 0, NULL ); 106 impl_update( aEvent, _rWindow ); 107 } 108 109 //--------------------------------------------------------------------- IMPL_LINK(DialogController,OnWindowEvent,const VclWindowEvent *,_pEvent)110 IMPL_LINK( DialogController, OnWindowEvent, const VclWindowEvent*, _pEvent ) 111 { 112 if ( m_pImpl->pEventFilter->payAttentionTo( *_pEvent ) ) 113 impl_updateAll( *_pEvent ); 114 return 0L; 115 } 116 117 //--------------------------------------------------------------------- impl_updateAll(const VclWindowEvent & _rTriggerEvent)118 void DialogController::impl_updateAll( const VclWindowEvent& _rTriggerEvent ) 119 { 120 for ( ::std::vector< Window* >::iterator loop = m_pImpl->aConcernedWindows.begin(); 121 loop != m_pImpl->aConcernedWindows.end(); 122 ++loop 123 ) 124 impl_update( _rTriggerEvent, *(*loop) ); 125 } 126 127 //--------------------------------------------------------------------- impl_update(const VclWindowEvent & _rTriggerEvent,Window & _rWindow)128 void DialogController::impl_update( const VclWindowEvent& _rTriggerEvent, Window& _rWindow ) 129 { 130 m_pImpl->pOperator->operateOn( _rTriggerEvent, _rWindow ); 131 } 132 133 //===================================================================== 134 //= ControlDependencyManager_Data 135 //===================================================================== 136 struct ControlDependencyManager_Data 137 { 138 ::std::vector< PDialogController > aControllers; 139 }; 140 141 //===================================================================== 142 //= ControlDependencyManager 143 //===================================================================== 144 //--------------------------------------------------------------------- ControlDependencyManager()145 ControlDependencyManager::ControlDependencyManager() 146 :m_pImpl( new ControlDependencyManager_Data ) 147 { 148 } 149 150 //--------------------------------------------------------------------- ~ControlDependencyManager()151 ControlDependencyManager::~ControlDependencyManager() 152 { 153 } 154 155 //--------------------------------------------------------------------- 156 namespace 157 { 158 struct ResetDialogController : public ::std::unary_function< const PDialogController&, void > 159 { operator ()svt::__anon744cd62e0111::ResetDialogController160 void operator()( const PDialogController& _pController ) 161 { 162 _pController->reset(); 163 } 164 }; 165 } 166 167 //--------------------------------------------------------------------- clear()168 void ControlDependencyManager::clear() 169 { 170 ::std::for_each( m_pImpl->aControllers.begin(), m_pImpl->aControllers.end(), ResetDialogController() ); 171 m_pImpl->aControllers.clear(); 172 } 173 174 //--------------------------------------------------------------------- addController(const PDialogController & _pController)175 void ControlDependencyManager::addController( const PDialogController& _pController ) 176 { 177 OSL_ENSURE( _pController.get() != NULL, "ControlDependencyManager::addController: invalid controller, this will crash, sooner or later!" ); 178 m_pImpl->aControllers.push_back( _pController ); 179 } 180 181 //--------------------------------------------------------------------- enableOnRadioCheck(RadioButton & _rRadio,Window & _rDependentWindow)182 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow ) 183 { 184 PDialogController pController( new RadioDependentEnabler( _rRadio ) ); 185 pController->addDependentWindow( _rDependentWindow ); 186 m_pImpl->aControllers.push_back( pController ); 187 } 188 189 //--------------------------------------------------------------------- enableOnRadioCheck(RadioButton & _rRadio,Window & _rDependentWindow1,Window & _rDependentWindow2)190 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2 ) 191 { 192 PDialogController pController( new RadioDependentEnabler( _rRadio ) ); 193 pController->addDependentWindow( _rDependentWindow1 ); 194 pController->addDependentWindow( _rDependentWindow2 ); 195 m_pImpl->aControllers.push_back( pController ); 196 } 197 198 //--------------------------------------------------------------------- enableOnRadioCheck(RadioButton & _rRadio,Window & _rDependentWindow1,Window & _rDependentWindow2,Window & _rDependentWindow3)199 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3 ) 200 { 201 PDialogController pController( new RadioDependentEnabler( _rRadio ) ); 202 pController->addDependentWindow( _rDependentWindow1 ); 203 pController->addDependentWindow( _rDependentWindow2 ); 204 pController->addDependentWindow( _rDependentWindow3 ); 205 m_pImpl->aControllers.push_back( pController ); 206 } 207 208 //--------------------------------------------------------------------- enableOnRadioCheck(RadioButton & _rRadio,Window & _rDependentWindow1,Window & _rDependentWindow2,Window & _rDependentWindow3,Window & _rDependentWindow4)209 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4 ) 210 { 211 PDialogController pController( new RadioDependentEnabler( _rRadio ) ); 212 pController->addDependentWindow( _rDependentWindow1 ); 213 pController->addDependentWindow( _rDependentWindow2 ); 214 pController->addDependentWindow( _rDependentWindow3 ); 215 pController->addDependentWindow( _rDependentWindow4 ); 216 m_pImpl->aControllers.push_back( pController ); 217 } 218 219 //--------------------------------------------------------------------- enableOnRadioCheck(RadioButton & _rRadio,Window & _rDependentWindow1,Window & _rDependentWindow2,Window & _rDependentWindow3,Window & _rDependentWindow4,Window & _rDependentWindow5)220 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5 ) 221 { 222 PDialogController pController( new RadioDependentEnabler( _rRadio ) ); 223 pController->addDependentWindow( _rDependentWindow1 ); 224 pController->addDependentWindow( _rDependentWindow2 ); 225 pController->addDependentWindow( _rDependentWindow3 ); 226 pController->addDependentWindow( _rDependentWindow4 ); 227 pController->addDependentWindow( _rDependentWindow5 ); 228 m_pImpl->aControllers.push_back( pController ); 229 } 230 231 //--------------------------------------------------------------------- enableOnRadioCheck(RadioButton & _rRadio,Window & _rDependentWindow1,Window & _rDependentWindow2,Window & _rDependentWindow3,Window & _rDependentWindow4,Window & _rDependentWindow5,Window & _rDependentWindow6)232 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5, Window& _rDependentWindow6 ) 233 { 234 PDialogController pController( new RadioDependentEnabler( _rRadio ) ); 235 pController->addDependentWindow( _rDependentWindow1 ); 236 pController->addDependentWindow( _rDependentWindow2 ); 237 pController->addDependentWindow( _rDependentWindow3 ); 238 pController->addDependentWindow( _rDependentWindow4 ); 239 pController->addDependentWindow( _rDependentWindow5 ); 240 pController->addDependentWindow( _rDependentWindow6 ); 241 m_pImpl->aControllers.push_back( pController ); 242 } 243 244 //--------------------------------------------------------------------- enableOnCheckMark(CheckBox & _rBox,Window & _rDependentWindow)245 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow ) 246 { 247 PDialogController pController( new RadioDependentEnabler( _rBox ) ); 248 pController->addDependentWindow( _rDependentWindow ); 249 m_pImpl->aControllers.push_back( pController ); 250 } 251 252 //--------------------------------------------------------------------- enableOnCheckMark(CheckBox & _rBox,Window & _rDependentWindow1,Window & _rDependentWindow2)253 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2 ) 254 { 255 PDialogController pController( new RadioDependentEnabler( _rBox ) ); 256 pController->addDependentWindow( _rDependentWindow1 ); 257 pController->addDependentWindow( _rDependentWindow2 ); 258 m_pImpl->aControllers.push_back( pController ); 259 } 260 261 //--------------------------------------------------------------------- enableOnCheckMark(CheckBox & _rBox,Window & _rDependentWindow1,Window & _rDependentWindow2,Window & _rDependentWindow3)262 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3 ) 263 { 264 PDialogController pController( new RadioDependentEnabler( _rBox ) ); 265 pController->addDependentWindow( _rDependentWindow1 ); 266 pController->addDependentWindow( _rDependentWindow2 ); 267 pController->addDependentWindow( _rDependentWindow3 ); 268 m_pImpl->aControllers.push_back( pController ); 269 } 270 271 //--------------------------------------------------------------------- enableOnCheckMark(CheckBox & _rBox,Window & _rDependentWindow1,Window & _rDependentWindow2,Window & _rDependentWindow3,Window & _rDependentWindow4)272 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4 ) 273 { 274 PDialogController pController( new RadioDependentEnabler( _rBox ) ); 275 pController->addDependentWindow( _rDependentWindow1 ); 276 pController->addDependentWindow( _rDependentWindow2 ); 277 pController->addDependentWindow( _rDependentWindow3 ); 278 pController->addDependentWindow( _rDependentWindow4 ); 279 m_pImpl->aControllers.push_back( pController ); 280 } 281 282 //--------------------------------------------------------------------- enableOnCheckMark(CheckBox & _rBox,Window & _rDependentWindow1,Window & _rDependentWindow2,Window & _rDependentWindow3,Window & _rDependentWindow4,Window & _rDependentWindow5)283 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5 ) 284 { 285 PDialogController pController( new RadioDependentEnabler( _rBox ) ); 286 pController->addDependentWindow( _rDependentWindow1 ); 287 pController->addDependentWindow( _rDependentWindow2 ); 288 pController->addDependentWindow( _rDependentWindow3 ); 289 pController->addDependentWindow( _rDependentWindow4 ); 290 pController->addDependentWindow( _rDependentWindow5 ); 291 m_pImpl->aControllers.push_back( pController ); 292 } 293 294 //--------------------------------------------------------------------- enableOnCheckMark(CheckBox & _rBox,Window & _rDependentWindow1,Window & _rDependentWindow2,Window & _rDependentWindow3,Window & _rDependentWindow4,Window & _rDependentWindow5,Window & _rDependentWindow6)295 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5, Window& _rDependentWindow6 ) 296 { 297 PDialogController pController( new RadioDependentEnabler( _rBox ) ); 298 pController->addDependentWindow( _rDependentWindow1 ); 299 pController->addDependentWindow( _rDependentWindow2 ); 300 pController->addDependentWindow( _rDependentWindow3 ); 301 pController->addDependentWindow( _rDependentWindow4 ); 302 pController->addDependentWindow( _rDependentWindow5 ); 303 pController->addDependentWindow( _rDependentWindow6 ); 304 m_pImpl->aControllers.push_back( pController ); 305 } 306 307 //........................................................................ 308 } // namespace svt 309 //........................................................................ 310 311