Update ooo320-m1
[ooovba.git] / svx / source / dialog / orienthelper.cxx
blobd61923324651b87db01bad5ac4e90654665ef079
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: orienthelper.cxx,v $
10 * $Revision: 1.6.274.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include "orienthelper.hxx"
35 #include <vector>
36 #include <utility>
38 #ifndef _SV_BUTTON_HXX
39 #include <vcl/button.hxx>
40 #endif
41 #include "dialcontrol.hxx"
43 namespace svx {
45 // ============================================================================
47 struct OrientationHelper_Impl
49 typedef std::pair< Window*, TriState > WindowPair;
50 typedef std::vector< WindowPair > WindowVec;
52 DialControl& mrCtrlDial;
53 CheckBox& mrCbStacked;
54 WindowVec maWinVec;
55 bool mbEnabled;
56 bool mbVisible;
58 explicit OrientationHelper_Impl( DialControl& rCtrlDial, CheckBox& rCbStacked );
60 void AddDependentWindow( Window& rWindow, TriState eDisableIfStacked );
62 void EnableDependentWindows();
63 void EnableWindow( Window& rWindow, TriState eDisableIfStacked );
65 void ShowDependentWindows();
67 DECL_LINK( ClickHdl, void* );
70 // ----------------------------------------------------------------------------
72 OrientationHelper_Impl::OrientationHelper_Impl( DialControl& rCtrlDial, CheckBox& rCbStacked ) :
73 mrCtrlDial( rCtrlDial ),
74 mrCbStacked( rCbStacked ),
75 mbEnabled( rCtrlDial.IsEnabled() ),
76 mbVisible( rCtrlDial.IsVisible() )
78 maWinVec.push_back( WindowPair( &mrCtrlDial, STATE_CHECK ) );
79 maWinVec.push_back( WindowPair( &mrCbStacked, STATE_DONTKNOW ) );
80 mrCbStacked.SetClickHdl( LINK( this, OrientationHelper_Impl, ClickHdl ) );
83 void OrientationHelper_Impl::AddDependentWindow( Window& rWindow, TriState eDisableIfStacked )
85 maWinVec.push_back( std::make_pair( &rWindow, eDisableIfStacked ) );
86 EnableWindow( rWindow, eDisableIfStacked );
89 void OrientationHelper_Impl::EnableDependentWindows()
91 for( WindowVec::iterator aIt = maWinVec.begin(), aEnd = maWinVec.end(); aIt != aEnd; ++aIt )
92 EnableWindow( *aIt->first, aIt->second );
95 void OrientationHelper_Impl::EnableWindow( Window& rWindow, TriState eDisableIfStacked )
97 bool bDisableOnStacked = false;
98 switch( eDisableIfStacked )
100 // STATE_CHECK: Disable window, if stacked text is turned on or "don't know".
101 case STATE_CHECK: bDisableOnStacked = (mrCbStacked.GetState() != STATE_NOCHECK); break;
102 // STATE_NOCHECK: Disable window, if stacked text is turned off or "don't know".
103 case STATE_NOCHECK: bDisableOnStacked = (mrCbStacked.GetState() != STATE_CHECK); break;
104 default: ;//prevent warning
106 rWindow.Enable( mbEnabled && !bDisableOnStacked );
109 void OrientationHelper_Impl::ShowDependentWindows()
111 for( WindowVec::iterator aIt = maWinVec.begin(), aEnd = maWinVec.end(); aIt != aEnd; ++aIt )
112 aIt->first->Show( mbVisible );
115 IMPL_LINK( OrientationHelper_Impl, ClickHdl, void*, EMPTYARG )
117 EnableDependentWindows();
118 return 0L;
121 // ============================================================================
123 OrientationHelper::OrientationHelper( DialControl& rCtrlDial, CheckBox& rCbStacked ) :
124 mpImpl( new OrientationHelper_Impl( rCtrlDial, rCbStacked ) )
126 mpImpl->EnableDependentWindows();
127 mpImpl->ShowDependentWindows();
130 OrientationHelper::OrientationHelper( DialControl& rCtrlDial, NumericField& rNfRotation, CheckBox& rCbStacked ) :
131 mpImpl( new OrientationHelper_Impl( rCtrlDial, rCbStacked ) )
133 rCtrlDial.SetLinkedField( &rNfRotation );
134 mpImpl->EnableDependentWindows();
135 mpImpl->ShowDependentWindows();
138 OrientationHelper::~OrientationHelper()
142 void OrientationHelper::AddDependentWindow( Window& rWindow, TriState eDisableIfStacked )
144 mpImpl->AddDependentWindow( rWindow, eDisableIfStacked );
147 void OrientationHelper::Enable( bool bEnable )
149 mpImpl->mbEnabled = bEnable;
150 mpImpl->EnableDependentWindows();
153 void OrientationHelper::Show( bool bShow )
155 mpImpl->mbVisible = bShow;
156 mpImpl->ShowDependentWindows();
159 void OrientationHelper::SetStackedState( TriState eState )
161 if( eState != GetStackedState() )
163 mpImpl->mrCbStacked.SetState( eState );
164 mpImpl->EnableDependentWindows();
168 TriState OrientationHelper::GetStackedState() const
170 return mpImpl->mrCbStacked.GetState();
173 void OrientationHelper::EnableStackedTriState( bool bEnable )
175 mpImpl->mrCbStacked.EnableTriState( bEnable );
178 // ============================================================================
180 OrientStackedWrapper::OrientStackedWrapper( OrientationHelper& rOrientHlp ) :
181 SingleControlWrapperType( rOrientHlp )
185 bool OrientStackedWrapper::IsControlDontKnow() const
187 return GetControl().GetStackedState() == STATE_DONTKNOW;
190 void OrientStackedWrapper::SetControlDontKnow( bool bSet )
192 GetControl().EnableStackedTriState( bSet );
193 GetControl().SetStackedState( bSet ? STATE_DONTKNOW : STATE_NOCHECK );
196 bool OrientStackedWrapper::GetControlValue() const
198 return GetControl().GetStackedState() == STATE_CHECK;
201 void OrientStackedWrapper::SetControlValue( bool bValue )
203 GetControl().SetStackedState( bValue ? STATE_CHECK : STATE_NOCHECK );
206 // ============================================================================
208 } // namespace svx