LCOV - code coverage report
Current view: top level - svx/source/dialog - orienthelper.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 74 1.4 %
Date: 2014-11-03 Functions: 2 24 8.3 %
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 "svx/orienthelper.hxx"
      21             : 
      22             : #include <vector>
      23             : #include <utility>
      24             : 
      25             : #include <vcl/button.hxx>
      26             : #include "svx/dialcontrol.hxx"
      27             : 
      28             : namespace svx {
      29             : 
      30             : 
      31             : 
      32           0 : struct OrientationHelper_Impl
      33             : {
      34             :     typedef std::pair< vcl::Window*, TriState >  WindowPair;
      35             :     typedef std::vector< WindowPair >       WindowVec;
      36             : 
      37             :     DialControl&        mrCtrlDial;
      38             :     CheckBox&           mrCbStacked;
      39             :     WindowVec           maWinVec;
      40             :     bool                mbEnabled;
      41             :     bool                mbVisible;
      42             : 
      43             :     explicit            OrientationHelper_Impl( DialControl& rCtrlDial, CheckBox& rCbStacked );
      44             : 
      45             :     void                AddDependentWindow( vcl::Window& rWindow, TriState eDisableIfStacked );
      46             : 
      47             :     void                EnableDependentWindows();
      48             :     void                EnableWindow( vcl::Window& rWindow, TriState eDisableIfStacked );
      49             : 
      50             :     void                ShowDependentWindows();
      51             : 
      52             :     DECL_LINK( ClickHdl, void* );
      53             : };
      54             : 
      55             : 
      56             : 
      57           0 : OrientationHelper_Impl::OrientationHelper_Impl( DialControl& rCtrlDial, CheckBox& rCbStacked ) :
      58             :     mrCtrlDial( rCtrlDial ),
      59             :     mrCbStacked( rCbStacked ),
      60           0 :     mbEnabled( rCtrlDial.IsEnabled() ),
      61           0 :     mbVisible( rCtrlDial.IsVisible() )
      62             : {
      63           0 :     maWinVec.push_back( WindowPair( &mrCtrlDial, TRISTATE_TRUE ) );
      64           0 :     maWinVec.push_back( WindowPair( &mrCbStacked, TRISTATE_INDET ) );
      65           0 :     mrCbStacked.SetClickHdl( LINK( this, OrientationHelper_Impl, ClickHdl ) );
      66           0 : }
      67             : 
      68           0 : void OrientationHelper_Impl::AddDependentWindow( vcl::Window& rWindow, TriState eDisableIfStacked )
      69             : {
      70           0 :     maWinVec.push_back( std::make_pair( &rWindow, eDisableIfStacked ) );
      71           0 :     EnableWindow( rWindow, eDisableIfStacked );
      72           0 : }
      73             : 
      74           0 : void OrientationHelper_Impl::EnableDependentWindows()
      75             : {
      76           0 :     for( WindowVec::iterator aIt = maWinVec.begin(), aEnd = maWinVec.end(); aIt != aEnd; ++aIt )
      77           0 :         EnableWindow( *aIt->first, aIt->second );
      78           0 : }
      79             : 
      80           0 : void OrientationHelper_Impl::EnableWindow( vcl::Window& rWindow, TriState eDisableIfStacked )
      81             : {
      82           0 :     bool bDisableOnStacked = false;
      83           0 :     switch( eDisableIfStacked )
      84             :     {
      85             :         // TRISTATE_TRUE: Disable window, if stacked text is turned on or "don't know".
      86           0 :         case TRISTATE_TRUE:   bDisableOnStacked = (mrCbStacked.GetState() != TRISTATE_FALSE);  break;
      87             :         // TRISTATE_FALSE: Disable window, if stacked text is turned off or "don't know".
      88           0 :         case TRISTATE_FALSE: bDisableOnStacked = (mrCbStacked.GetState() != TRISTATE_TRUE);    break;
      89             :         default: ;//prevent warning
      90             :     }
      91           0 :     rWindow.Enable( mbEnabled && !bDisableOnStacked );
      92           0 : }
      93             : 
      94           0 : void OrientationHelper_Impl::ShowDependentWindows()
      95             : {
      96           0 :     for( WindowVec::iterator aIt = maWinVec.begin(), aEnd = maWinVec.end(); aIt != aEnd; ++aIt )
      97           0 :         aIt->first->Show( mbVisible );
      98           0 : }
      99             : 
     100           0 : IMPL_LINK_NOARG(OrientationHelper_Impl, ClickHdl)
     101             : {
     102           0 :     EnableDependentWindows();
     103           0 :     return 0L;
     104             : }
     105             : 
     106             : 
     107             : 
     108           0 : OrientationHelper::OrientationHelper( DialControl& rCtrlDial, NumericField& rNfRotation, CheckBox& rCbStacked ) :
     109           0 :     mpImpl( new OrientationHelper_Impl( rCtrlDial, rCbStacked ) )
     110             : {
     111           0 :     rCtrlDial.SetLinkedField( &rNfRotation );
     112           0 :     mpImpl->EnableDependentWindows();
     113           0 :     mpImpl->ShowDependentWindows();
     114           0 : }
     115             : 
     116           0 : OrientationHelper::~OrientationHelper()
     117             : {
     118           0 : }
     119             : 
     120           0 : void OrientationHelper::AddDependentWindow( vcl::Window& rWindow, TriState eDisableIfStacked )
     121             : {
     122           0 :     mpImpl->AddDependentWindow( rWindow, eDisableIfStacked );
     123           0 : }
     124             : 
     125           0 : void OrientationHelper::Enable( bool bEnable )
     126             : {
     127           0 :     mpImpl->mbEnabled = bEnable;
     128           0 :     mpImpl->EnableDependentWindows();
     129           0 : }
     130             : 
     131           0 : void OrientationHelper::Show( bool bShow )
     132             : {
     133           0 :     mpImpl->mbVisible = bShow;
     134           0 :     mpImpl->ShowDependentWindows();
     135           0 : }
     136             : 
     137           0 : void OrientationHelper::SetStackedState( TriState eState )
     138             : {
     139           0 :     if( eState != GetStackedState() )
     140             :     {
     141           0 :         mpImpl->mrCbStacked.SetState( eState );
     142           0 :         mpImpl->EnableDependentWindows();
     143             :     }
     144           0 : }
     145             : 
     146           0 : TriState OrientationHelper::GetStackedState() const
     147             : {
     148           0 :     return mpImpl->mrCbStacked.GetState();
     149             : }
     150             : 
     151           0 : void OrientationHelper::EnableStackedTriState( bool bEnable )
     152             : {
     153           0 :     mpImpl->mrCbStacked.EnableTriState( bEnable );
     154           0 : }
     155             : 
     156             : 
     157             : 
     158           0 : OrientStackedWrapper::OrientStackedWrapper( OrientationHelper& rOrientHlp ) :
     159           0 :     SingleControlWrapperType( rOrientHlp )
     160             : {
     161           0 : }
     162             : 
     163           0 : bool OrientStackedWrapper::IsControlDontKnow() const
     164             : {
     165           0 :     return GetControl().GetStackedState() == TRISTATE_INDET;
     166             : }
     167             : 
     168           0 : void OrientStackedWrapper::SetControlDontKnow( bool bSet )
     169             : {
     170           0 :     GetControl().EnableStackedTriState( bSet );
     171           0 :     GetControl().SetStackedState( bSet ? TRISTATE_INDET : TRISTATE_FALSE );
     172           0 : }
     173             : 
     174           0 : bool OrientStackedWrapper::GetControlValue() const
     175             : {
     176           0 :     return GetControl().GetStackedState() == TRISTATE_TRUE;
     177             : }
     178             : 
     179           0 : void OrientStackedWrapper::SetControlValue( bool bValue )
     180             : {
     181           0 :     GetControl().SetStackedState( bValue ? TRISTATE_TRUE : TRISTATE_FALSE );
     182           0 : }
     183             : 
     184             : 
     185             : 
     186         594 : } // namespace svx
     187             : 
     188             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10