xref: /aoo42x/main/svx/source/dialog/orienthelper.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 #include "svx/orienthelper.hxx"
31 
32 #include <vector>
33 #include <utility>
34 
35 #ifndef _SV_BUTTON_HXX
36 #include <vcl/button.hxx>
37 #endif
38 #include "svx/dialcontrol.hxx"
39 
40 namespace svx {
41 
42 // ============================================================================
43 
44 struct OrientationHelper_Impl
45 {
46     typedef std::pair< Window*, TriState >  WindowPair;
47     typedef std::vector< WindowPair >       WindowVec;
48 
49     DialControl&        mrCtrlDial;
50     CheckBox&           mrCbStacked;
51     WindowVec           maWinVec;
52     bool                mbEnabled;
53     bool                mbVisible;
54 
55     explicit            OrientationHelper_Impl( DialControl& rCtrlDial, CheckBox& rCbStacked );
56 
57     void                AddDependentWindow( Window& rWindow, TriState eDisableIfStacked );
58 
59     void                EnableDependentWindows();
60     void                EnableWindow( Window& rWindow, TriState eDisableIfStacked );
61 
62     void                ShowDependentWindows();
63 
64     DECL_LINK( ClickHdl, void* );
65 };
66 
67 // ----------------------------------------------------------------------------
68 
69 OrientationHelper_Impl::OrientationHelper_Impl( DialControl& rCtrlDial, CheckBox& rCbStacked ) :
70     mrCtrlDial( rCtrlDial ),
71     mrCbStacked( rCbStacked ),
72     mbEnabled( rCtrlDial.IsEnabled() ),
73     mbVisible( rCtrlDial.IsVisible() )
74 {
75     maWinVec.push_back( WindowPair( &mrCtrlDial, STATE_CHECK ) );
76     maWinVec.push_back( WindowPair( &mrCbStacked, STATE_DONTKNOW ) );
77     mrCbStacked.SetClickHdl( LINK( this, OrientationHelper_Impl, ClickHdl ) );
78 }
79 
80 void OrientationHelper_Impl::AddDependentWindow( Window& rWindow, TriState eDisableIfStacked )
81 {
82     maWinVec.push_back( std::make_pair( &rWindow, eDisableIfStacked ) );
83     EnableWindow( rWindow, eDisableIfStacked );
84 }
85 
86 void OrientationHelper_Impl::EnableDependentWindows()
87 {
88     for( WindowVec::iterator aIt = maWinVec.begin(), aEnd = maWinVec.end(); aIt != aEnd; ++aIt )
89         EnableWindow( *aIt->first, aIt->second );
90 }
91 
92 void OrientationHelper_Impl::EnableWindow( Window& rWindow, TriState eDisableIfStacked )
93 {
94     bool bDisableOnStacked = false;
95     switch( eDisableIfStacked )
96     {
97         // STATE_CHECK: Disable window, if stacked text is turned on or "don't know".
98         case STATE_CHECK:   bDisableOnStacked = (mrCbStacked.GetState() != STATE_NOCHECK);  break;
99         // STATE_NOCHECK: Disable window, if stacked text is turned off or "don't know".
100         case STATE_NOCHECK: bDisableOnStacked = (mrCbStacked.GetState() != STATE_CHECK);    break;
101         default: ;//prevent warning
102     }
103     rWindow.Enable( mbEnabled && !bDisableOnStacked );
104 }
105 
106 void OrientationHelper_Impl::ShowDependentWindows()
107 {
108     for( WindowVec::iterator aIt = maWinVec.begin(), aEnd = maWinVec.end(); aIt != aEnd; ++aIt )
109         aIt->first->Show( mbVisible );
110 }
111 
112 IMPL_LINK( OrientationHelper_Impl, ClickHdl, void*, EMPTYARG )
113 {
114     EnableDependentWindows();
115 	return 0L;
116 }
117 
118 // ============================================================================
119 
120 OrientationHelper::OrientationHelper( DialControl& rCtrlDial, CheckBox& rCbStacked ) :
121     mpImpl( new OrientationHelper_Impl( rCtrlDial, rCbStacked ) )
122 {
123     mpImpl->EnableDependentWindows();
124     mpImpl->ShowDependentWindows();
125 }
126 
127 OrientationHelper::OrientationHelper( DialControl& rCtrlDial, NumericField& rNfRotation, CheckBox& rCbStacked ) :
128     mpImpl( new OrientationHelper_Impl( rCtrlDial, rCbStacked ) )
129 {
130     rCtrlDial.SetLinkedField( &rNfRotation );
131     mpImpl->EnableDependentWindows();
132     mpImpl->ShowDependentWindows();
133 }
134 
135 OrientationHelper::~OrientationHelper()
136 {
137 }
138 
139 void OrientationHelper::AddDependentWindow( Window& rWindow, TriState eDisableIfStacked )
140 {
141     mpImpl->AddDependentWindow( rWindow, eDisableIfStacked );
142 }
143 
144 void OrientationHelper::Enable( bool bEnable )
145 {
146     mpImpl->mbEnabled = bEnable;
147     mpImpl->EnableDependentWindows();
148 }
149 
150 void OrientationHelper::Show( bool bShow )
151 {
152     mpImpl->mbVisible = bShow;
153     mpImpl->ShowDependentWindows();
154 }
155 
156 void OrientationHelper::SetStackedState( TriState eState )
157 {
158     if( eState != GetStackedState() )
159     {
160         mpImpl->mrCbStacked.SetState( eState );
161         mpImpl->EnableDependentWindows();
162     }
163 }
164 
165 TriState OrientationHelper::GetStackedState() const
166 {
167     return mpImpl->mrCbStacked.GetState();
168 }
169 
170 void OrientationHelper::EnableStackedTriState( bool bEnable )
171 {
172     mpImpl->mrCbStacked.EnableTriState( bEnable );
173 }
174 
175 // ============================================================================
176 
177 OrientStackedWrapper::OrientStackedWrapper( OrientationHelper& rOrientHlp ) :
178     SingleControlWrapperType( rOrientHlp )
179 {
180 }
181 
182 bool OrientStackedWrapper::IsControlDontKnow() const
183 {
184     return GetControl().GetStackedState() == STATE_DONTKNOW;
185 }
186 
187 void OrientStackedWrapper::SetControlDontKnow( bool bSet )
188 {
189     GetControl().EnableStackedTriState( bSet );
190     GetControl().SetStackedState( bSet ? STATE_DONTKNOW : STATE_NOCHECK );
191 }
192 
193 bool OrientStackedWrapper::GetControlValue() const
194 {
195     return GetControl().GetStackedState() == STATE_CHECK;
196 }
197 
198 void OrientStackedWrapper::SetControlValue( bool bValue )
199 {
200     GetControl().SetStackedState( bValue ? STATE_CHECK : STATE_NOCHECK );
201 }
202 
203 // ============================================================================
204 
205 } // namespace svx
206 
207