fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svtools / source / misc / dialogcontrolling.cxx
blob52b8656fa6e1b6166da5d31f953f8a944106033f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <algorithm>
24 #include <functional>
26 //........................................................................
27 namespace svt
29 //........................................................................
31 //=====================================================================
32 //= IWindowOperator
33 //=====================================================================
34 //---------------------------------------------------------------------
35 IWindowOperator::~IWindowOperator()
39 //=====================================================================
40 //= IWindowEventFilter
41 //=====================================================================
42 //---------------------------------------------------------------------
43 IWindowEventFilter::~IWindowEventFilter()
47 //=====================================================================
48 //= DialogController_Data
49 //=====================================================================
50 struct DialogController_Data
52 Window& rInstigator;
53 ::std::vector< Window* > aConcernedWindows;
54 PWindowEventFilter pEventFilter;
55 PWindowOperator pOperator;
57 DialogController_Data( Window& _rInstigator, const PWindowEventFilter _pEventFilter, const PWindowOperator _pOperator )
58 :rInstigator( _rInstigator )
59 ,pEventFilter( _pEventFilter )
60 ,pOperator( _pOperator )
65 //=====================================================================
66 //= DialogController
67 //=====================================================================
68 //---------------------------------------------------------------------
69 DialogController::DialogController( Window& _rInstigator, const PWindowEventFilter& _pEventFilter,
70 const PWindowOperator& _pOperator )
71 :m_pImpl( new DialogController_Data( _rInstigator, _pEventFilter, _pOperator ) )
73 DBG_ASSERT( m_pImpl->pEventFilter.get() && m_pImpl->pOperator.get(),
74 "DialogController::DialogController: invalid filter and/or operator!" );
76 m_pImpl->rInstigator.AddEventListener( LINK( this, DialogController, OnWindowEvent ) );
79 //---------------------------------------------------------------------
80 DialogController::~DialogController()
82 reset();
85 //---------------------------------------------------------------------
86 void DialogController::reset()
88 m_pImpl->rInstigator.RemoveEventListener( LINK( this, DialogController, OnWindowEvent ) );
89 m_pImpl->aConcernedWindows.clear();
90 m_pImpl->pEventFilter.reset();
91 m_pImpl->pOperator.reset();
94 //---------------------------------------------------------------------
95 void DialogController::addDependentWindow( Window& _rWindow )
97 m_pImpl->aConcernedWindows.push_back( &_rWindow );
99 VclWindowEvent aEvent( &_rWindow, 0, NULL );
100 impl_update( aEvent, _rWindow );
103 //---------------------------------------------------------------------
104 IMPL_LINK( DialogController, OnWindowEvent, const VclWindowEvent*, _pEvent )
106 if ( m_pImpl->pEventFilter->payAttentionTo( *_pEvent ) )
107 impl_updateAll( *_pEvent );
108 return 0L;
111 //---------------------------------------------------------------------
112 void DialogController::impl_updateAll( const VclWindowEvent& _rTriggerEvent )
114 for ( ::std::vector< Window* >::iterator loop = m_pImpl->aConcernedWindows.begin();
115 loop != m_pImpl->aConcernedWindows.end();
116 ++loop
118 impl_update( _rTriggerEvent, *(*loop) );
121 //---------------------------------------------------------------------
122 void DialogController::impl_update( const VclWindowEvent& _rTriggerEvent, Window& _rWindow )
124 m_pImpl->pOperator->operateOn( _rTriggerEvent, _rWindow );
127 //=====================================================================
128 //= ControlDependencyManager_Data
129 //=====================================================================
130 struct ControlDependencyManager_Data
132 ::std::vector< PDialogController > aControllers;
135 //=====================================================================
136 //= ControlDependencyManager
137 //=====================================================================
138 //---------------------------------------------------------------------
139 ControlDependencyManager::ControlDependencyManager()
140 :m_pImpl( new ControlDependencyManager_Data )
144 //---------------------------------------------------------------------
145 ControlDependencyManager::~ControlDependencyManager()
149 //---------------------------------------------------------------------
150 namespace
152 struct ResetDialogController : public ::std::unary_function< const PDialogController&, void >
154 void operator()( const PDialogController& _pController )
156 _pController->reset();
161 //---------------------------------------------------------------------
162 void ControlDependencyManager::clear()
164 ::std::for_each( m_pImpl->aControllers.begin(), m_pImpl->aControllers.end(), ResetDialogController() );
165 m_pImpl->aControllers.clear();
168 //---------------------------------------------------------------------
169 void ControlDependencyManager::addController( const PDialogController& _pController )
171 OSL_ENSURE( _pController.get() != NULL, "ControlDependencyManager::addController: invalid controller, this will crash, sooner or later!" );
172 m_pImpl->aControllers.push_back( _pController );
175 //---------------------------------------------------------------------
176 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow )
178 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
179 pController->addDependentWindow( _rDependentWindow );
180 m_pImpl->aControllers.push_back( pController );
183 //---------------------------------------------------------------------
184 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3 )
186 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
187 pController->addDependentWindow( _rDependentWindow1 );
188 pController->addDependentWindow( _rDependentWindow2 );
189 pController->addDependentWindow( _rDependentWindow3 );
190 m_pImpl->aControllers.push_back( pController );
193 //---------------------------------------------------------------------
194 void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4, Window& _rDependentWindow5 )
196 PDialogController pController( new RadioDependentEnabler( _rRadio ) );
197 pController->addDependentWindow( _rDependentWindow1 );
198 pController->addDependentWindow( _rDependentWindow2 );
199 pController->addDependentWindow( _rDependentWindow3 );
200 pController->addDependentWindow( _rDependentWindow4 );
201 pController->addDependentWindow( _rDependentWindow5 );
202 m_pImpl->aControllers.push_back( pController );
205 //---------------------------------------------------------------------
206 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow )
208 PDialogController pController( new RadioDependentEnabler( _rBox ) );
209 pController->addDependentWindow( _rDependentWindow );
210 m_pImpl->aControllers.push_back( pController );
213 //---------------------------------------------------------------------
214 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2 )
216 PDialogController pController( new RadioDependentEnabler( _rBox ) );
217 pController->addDependentWindow( _rDependentWindow1 );
218 pController->addDependentWindow( _rDependentWindow2 );
219 m_pImpl->aControllers.push_back( pController );
222 //---------------------------------------------------------------------
223 void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, Window& _rDependentWindow1, Window& _rDependentWindow2, Window& _rDependentWindow3, Window& _rDependentWindow4 )
225 PDialogController pController( new RadioDependentEnabler( _rBox ) );
226 pController->addDependentWindow( _rDependentWindow1 );
227 pController->addDependentWindow( _rDependentWindow2 );
228 pController->addDependentWindow( _rDependentWindow3 );
229 pController->addDependentWindow( _rDependentWindow4 );
230 m_pImpl->aControllers.push_back( pController );
233 //........................................................................
234 } // namespace svt
235 //........................................................................
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */