LCOV - code coverage report
Current view: top level - svtools/source/misc - dialogcontrolling.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 100 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 29 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <svtools/dialogcontrolling.hxx>
      21             : #include <vcl/window.hxx>
      22             : 
      23             : #include <algorithm>
      24             : #include <functional>
      25             : 
      26             : 
      27             : namespace svt
      28             : {
      29             : 
      30             : 
      31             : 
      32             :     //= IWindowOperator
      33             : 
      34             : 
      35           0 :     IWindowOperator::~IWindowOperator()
      36             :     {
      37           0 :     }
      38             : 
      39             : 
      40             :     //= IWindowEventFilter
      41             : 
      42             : 
      43           0 :     IWindowEventFilter::~IWindowEventFilter()
      44             :     {
      45           0 :     }
      46             : 
      47             : 
      48             :     //= DialogController_Data
      49             : 
      50           0 :     struct DialogController_Data
      51             :     {
      52             :         vcl::Window&                     rInstigator;
      53             :         ::std::vector< VclPtr<vcl::Window> >    aConcernedWindows;
      54             :         PWindowEventFilter          pEventFilter;
      55             :         PWindowOperator             pOperator;
      56             : 
      57           0 :         DialogController_Data( vcl::Window& _rInstigator, const PWindowEventFilter _pEventFilter, const PWindowOperator _pOperator )
      58             :             :rInstigator( _rInstigator )
      59             :             ,pEventFilter( _pEventFilter )
      60           0 :             ,pOperator( _pOperator )
      61             :         {
      62           0 :         }
      63             :     };
      64             : 
      65             : 
      66             :     //= DialogController
      67             : 
      68             : 
      69           0 :     DialogController::DialogController( vcl::Window& _rInstigator, const PWindowEventFilter& _pEventFilter,
      70             :             const PWindowOperator& _pOperator )
      71           0 :         :m_pImpl( new DialogController_Data( _rInstigator, _pEventFilter, _pOperator ) )
      72             :     {
      73             :         DBG_ASSERT( m_pImpl->pEventFilter.get() && m_pImpl->pOperator.get(),
      74             :             "DialogController::DialogController: invalid filter and/or operator!" );
      75             : 
      76           0 :         m_pImpl->rInstigator.AddEventListener( LINK( this, DialogController, OnWindowEvent ) );
      77           0 :     }
      78             : 
      79             : 
      80           0 :     DialogController::~DialogController()
      81             :     {
      82           0 :         reset();
      83           0 :     }
      84             : 
      85             : 
      86           0 :     void DialogController::reset()
      87             :     {
      88           0 :         m_pImpl->rInstigator.RemoveEventListener( LINK( this, DialogController, OnWindowEvent ) );
      89           0 :         m_pImpl->aConcernedWindows.clear();
      90           0 :         m_pImpl->pEventFilter.reset();
      91           0 :         m_pImpl->pOperator.reset();
      92           0 :     }
      93             : 
      94             : 
      95           0 :     void DialogController::addDependentWindow( vcl::Window& _rWindow )
      96             :     {
      97           0 :         m_pImpl->aConcernedWindows.push_back( &_rWindow );
      98             : 
      99           0 :         VclWindowEvent aEvent( &_rWindow, 0, NULL );
     100           0 :         impl_update( aEvent, _rWindow );
     101           0 :     }
     102             : 
     103             : 
     104           0 :     IMPL_LINK( DialogController, OnWindowEvent, const VclWindowEvent*, _pEvent )
     105             :     {
     106           0 :         if ( m_pImpl->pEventFilter->payAttentionTo( *_pEvent ) )
     107           0 :             impl_updateAll( *_pEvent );
     108           0 :         return 0L;
     109             :     }
     110             : 
     111             : 
     112           0 :     void DialogController::impl_updateAll( const VclWindowEvent& _rTriggerEvent )
     113             :     {
     114           0 :         for ( auto loop = m_pImpl->aConcernedWindows.begin();
     115           0 :                 loop != m_pImpl->aConcernedWindows.end();
     116             :                 ++loop
     117             :             )
     118           0 :             impl_update( _rTriggerEvent, *(*loop) );
     119           0 :     }
     120             : 
     121             : 
     122           0 :     void DialogController::impl_update( const VclWindowEvent& _rTriggerEvent, vcl::Window& _rWindow )
     123             :     {
     124           0 :         m_pImpl->pOperator->operateOn( _rTriggerEvent, _rWindow );
     125           0 :     }
     126             : 
     127             : 
     128             :     //= ControlDependencyManager_Data
     129             : 
     130           0 :     struct ControlDependencyManager_Data
     131             :     {
     132             :         ::std::vector< PDialogController >  aControllers;
     133             :     };
     134             : 
     135             : 
     136             :     //= ControlDependencyManager
     137             : 
     138             : 
     139           0 :     ControlDependencyManager::ControlDependencyManager()
     140           0 :         :m_pImpl( new ControlDependencyManager_Data )
     141             :     {
     142           0 :     }
     143             : 
     144             : 
     145           0 :     ControlDependencyManager::~ControlDependencyManager()
     146             :     {
     147           0 :     }
     148             : 
     149             : 
     150             :     namespace
     151             :     {
     152             :         struct ResetDialogController : public ::std::unary_function< const PDialogController&, void >
     153             :         {
     154           0 :             void operator()( const PDialogController& _pController )
     155             :             {
     156           0 :                 _pController->reset();
     157           0 :             }
     158             :         };
     159             :     }
     160             : 
     161             : 
     162           0 :     void ControlDependencyManager::clear()
     163             :     {
     164           0 :         ::std::for_each( m_pImpl->aControllers.begin(), m_pImpl->aControllers.end(), ResetDialogController() );
     165           0 :         m_pImpl->aControllers.clear();
     166           0 :     }
     167             : 
     168             : 
     169           0 :     void ControlDependencyManager::addController( const PDialogController& _pController )
     170             :     {
     171             :         OSL_ENSURE( _pController.get() != NULL, "ControlDependencyManager::addController: invalid controller, this will crash, sooner or later!" );
     172           0 :         m_pImpl->aControllers.push_back( _pController );
     173           0 :     }
     174             : 
     175             : 
     176           0 :     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, vcl::Window& _rDependentWindow )
     177             :     {
     178           0 :         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
     179           0 :         pController->addDependentWindow( _rDependentWindow );
     180           0 :         m_pImpl->aControllers.push_back( pController );
     181           0 :     }
     182             : 
     183             : 
     184           0 :     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, vcl::Window& _rDependentWindow1, vcl::Window& _rDependentWindow2 )
     185             :     {
     186           0 :         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
     187           0 :         pController->addDependentWindow( _rDependentWindow1 );
     188           0 :         pController->addDependentWindow( _rDependentWindow2 );
     189           0 :         m_pImpl->aControllers.push_back( pController );
     190           0 :     }
     191             : 
     192             : 
     193           0 :     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, vcl::Window& _rDependentWindow1, vcl::Window& _rDependentWindow2, vcl::Window& _rDependentWindow3 )
     194             :     {
     195           0 :         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
     196           0 :         pController->addDependentWindow( _rDependentWindow1 );
     197           0 :         pController->addDependentWindow( _rDependentWindow2 );
     198           0 :         pController->addDependentWindow( _rDependentWindow3 );
     199           0 :         m_pImpl->aControllers.push_back( pController );
     200           0 :     }
     201             : 
     202             : 
     203           0 :     void ControlDependencyManager::enableOnRadioCheck( RadioButton& _rRadio, vcl::Window& _rDependentWindow1, vcl::Window& _rDependentWindow2, vcl::Window& _rDependentWindow3, vcl::Window& _rDependentWindow4, vcl::Window& _rDependentWindow5 )
     204             :     {
     205           0 :         PDialogController pController( new RadioDependentEnabler( _rRadio ) );
     206           0 :         pController->addDependentWindow( _rDependentWindow1 );
     207           0 :         pController->addDependentWindow( _rDependentWindow2 );
     208           0 :         pController->addDependentWindow( _rDependentWindow3 );
     209           0 :         pController->addDependentWindow( _rDependentWindow4 );
     210           0 :         pController->addDependentWindow( _rDependentWindow5 );
     211           0 :         m_pImpl->aControllers.push_back( pController );
     212           0 :     }
     213             : 
     214             : 
     215           0 :     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, vcl::Window& _rDependentWindow )
     216             :     {
     217           0 :         PDialogController pController( new RadioDependentEnabler( _rBox ) );
     218           0 :         pController->addDependentWindow( _rDependentWindow );
     219           0 :         m_pImpl->aControllers.push_back( pController );
     220           0 :     }
     221             : 
     222             : 
     223           0 :     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, vcl::Window& _rDependentWindow1, vcl::Window& _rDependentWindow2 )
     224             :     {
     225           0 :         PDialogController pController( new RadioDependentEnabler( _rBox ) );
     226           0 :         pController->addDependentWindow( _rDependentWindow1 );
     227           0 :         pController->addDependentWindow( _rDependentWindow2 );
     228           0 :         m_pImpl->aControllers.push_back( pController );
     229           0 :     }
     230             : 
     231             : 
     232           0 :     void ControlDependencyManager::enableOnCheckMark( CheckBox& _rBox, vcl::Window& _rDependentWindow1, vcl::Window& _rDependentWindow2, vcl::Window& _rDependentWindow3, vcl::Window& _rDependentWindow4 )
     233             :     {
     234           0 :         PDialogController pController( new RadioDependentEnabler( _rBox ) );
     235           0 :         pController->addDependentWindow( _rDependentWindow1 );
     236           0 :         pController->addDependentWindow( _rDependentWindow2 );
     237           0 :         pController->addDependentWindow( _rDependentWindow3 );
     238           0 :         pController->addDependentWindow( _rDependentWindow4 );
     239           0 :         m_pImpl->aControllers.push_back( pController );
     240           0 :     }
     241             : 
     242             : 
     243             : } // namespace svt
     244             : 
     245             : 
     246             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11