xref: /aoo41x/main/svx/source/dialog/orienthelper.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 #include "svx/orienthelper.hxx"
27 
28 #include <vector>
29 #include <utility>
30 
31 #ifndef _SV_BUTTON_HXX
32 #include <vcl/button.hxx>
33 #endif
34 #include "svx/dialcontrol.hxx"
35 
36 namespace svx {
37 
38 // ============================================================================
39 
40 struct OrientationHelper_Impl
41 {
42     typedef std::pair< Window*, TriState >  WindowPair;
43     typedef std::vector< WindowPair >       WindowVec;
44 
45     DialControl&        mrCtrlDial;
46     CheckBox&           mrCbStacked;
47     WindowVec           maWinVec;
48     bool                mbEnabled;
49     bool                mbVisible;
50 
51     explicit            OrientationHelper_Impl( DialControl& rCtrlDial, CheckBox& rCbStacked );
52 
53     void                AddDependentWindow( Window& rWindow, TriState eDisableIfStacked );
54 
55     void                EnableDependentWindows();
56     void                EnableWindow( Window& rWindow, TriState eDisableIfStacked );
57 
58     void                ShowDependentWindows();
59 
60     DECL_LINK( ClickHdl, void* );
61 };
62 
63 // ----------------------------------------------------------------------------
64 
OrientationHelper_Impl(DialControl & rCtrlDial,CheckBox & rCbStacked)65 OrientationHelper_Impl::OrientationHelper_Impl( DialControl& rCtrlDial, CheckBox& rCbStacked ) :
66     mrCtrlDial( rCtrlDial ),
67     mrCbStacked( rCbStacked ),
68     mbEnabled( rCtrlDial.IsEnabled() ),
69     mbVisible( rCtrlDial.IsVisible() )
70 {
71     maWinVec.push_back( WindowPair( &mrCtrlDial, STATE_CHECK ) );
72     maWinVec.push_back( WindowPair( &mrCbStacked, STATE_DONTKNOW ) );
73     mrCbStacked.SetClickHdl( LINK( this, OrientationHelper_Impl, ClickHdl ) );
74 }
75 
AddDependentWindow(Window & rWindow,TriState eDisableIfStacked)76 void OrientationHelper_Impl::AddDependentWindow( Window& rWindow, TriState eDisableIfStacked )
77 {
78     maWinVec.push_back( std::make_pair( &rWindow, eDisableIfStacked ) );
79     EnableWindow( rWindow, eDisableIfStacked );
80 }
81 
EnableDependentWindows()82 void OrientationHelper_Impl::EnableDependentWindows()
83 {
84     for( WindowVec::iterator aIt = maWinVec.begin(), aEnd = maWinVec.end(); aIt != aEnd; ++aIt )
85         EnableWindow( *aIt->first, aIt->second );
86 }
87 
EnableWindow(Window & rWindow,TriState eDisableIfStacked)88 void OrientationHelper_Impl::EnableWindow( Window& rWindow, TriState eDisableIfStacked )
89 {
90     bool bDisableOnStacked = false;
91     switch( eDisableIfStacked )
92     {
93         // STATE_CHECK: Disable window, if stacked text is turned on or "don't know".
94         case STATE_CHECK:   bDisableOnStacked = (mrCbStacked.GetState() != STATE_NOCHECK);  break;
95         // STATE_NOCHECK: Disable window, if stacked text is turned off or "don't know".
96         case STATE_NOCHECK: bDisableOnStacked = (mrCbStacked.GetState() != STATE_CHECK);    break;
97         default: ;//prevent warning
98     }
99     rWindow.Enable( mbEnabled && !bDisableOnStacked );
100 }
101 
ShowDependentWindows()102 void OrientationHelper_Impl::ShowDependentWindows()
103 {
104     for( WindowVec::iterator aIt = maWinVec.begin(), aEnd = maWinVec.end(); aIt != aEnd; ++aIt )
105         aIt->first->Show( mbVisible );
106 }
107 
IMPL_LINK(OrientationHelper_Impl,ClickHdl,void *,EMPTYARG)108 IMPL_LINK( OrientationHelper_Impl, ClickHdl, void*, EMPTYARG )
109 {
110     EnableDependentWindows();
111 	return 0L;
112 }
113 
114 // ============================================================================
115 
OrientationHelper(DialControl & rCtrlDial,CheckBox & rCbStacked)116 OrientationHelper::OrientationHelper( DialControl& rCtrlDial, CheckBox& rCbStacked ) :
117     mpImpl( new OrientationHelper_Impl( rCtrlDial, rCbStacked ) )
118 {
119     mpImpl->EnableDependentWindows();
120     mpImpl->ShowDependentWindows();
121 }
122 
OrientationHelper(DialControl & rCtrlDial,NumericField & rNfRotation,CheckBox & rCbStacked)123 OrientationHelper::OrientationHelper( DialControl& rCtrlDial, NumericField& rNfRotation, CheckBox& rCbStacked ) :
124     mpImpl( new OrientationHelper_Impl( rCtrlDial, rCbStacked ) )
125 {
126     rCtrlDial.SetLinkedField( &rNfRotation );
127     mpImpl->EnableDependentWindows();
128     mpImpl->ShowDependentWindows();
129 }
130 
~OrientationHelper()131 OrientationHelper::~OrientationHelper()
132 {
133 }
134 
AddDependentWindow(Window & rWindow,TriState eDisableIfStacked)135 void OrientationHelper::AddDependentWindow( Window& rWindow, TriState eDisableIfStacked )
136 {
137     mpImpl->AddDependentWindow( rWindow, eDisableIfStacked );
138 }
139 
Enable(bool bEnable)140 void OrientationHelper::Enable( bool bEnable )
141 {
142     mpImpl->mbEnabled = bEnable;
143     mpImpl->EnableDependentWindows();
144 }
145 
Show(bool bShow)146 void OrientationHelper::Show( bool bShow )
147 {
148     mpImpl->mbVisible = bShow;
149     mpImpl->ShowDependentWindows();
150 }
151 
SetStackedState(TriState eState)152 void OrientationHelper::SetStackedState( TriState eState )
153 {
154     if( eState != GetStackedState() )
155     {
156         mpImpl->mrCbStacked.SetState( eState );
157         mpImpl->EnableDependentWindows();
158     }
159 }
160 
GetStackedState() const161 TriState OrientationHelper::GetStackedState() const
162 {
163     return mpImpl->mrCbStacked.GetState();
164 }
165 
EnableStackedTriState(bool bEnable)166 void OrientationHelper::EnableStackedTriState( bool bEnable )
167 {
168     mpImpl->mrCbStacked.EnableTriState( bEnable );
169 }
170 
171 // ============================================================================
172 
OrientStackedWrapper(OrientationHelper & rOrientHlp)173 OrientStackedWrapper::OrientStackedWrapper( OrientationHelper& rOrientHlp ) :
174     SingleControlWrapperType( rOrientHlp )
175 {
176 }
177 
IsControlDontKnow() const178 bool OrientStackedWrapper::IsControlDontKnow() const
179 {
180     return GetControl().GetStackedState() == STATE_DONTKNOW;
181 }
182 
SetControlDontKnow(bool bSet)183 void OrientStackedWrapper::SetControlDontKnow( bool bSet )
184 {
185     GetControl().EnableStackedTriState( bSet );
186     GetControl().SetStackedState( bSet ? STATE_DONTKNOW : STATE_NOCHECK );
187 }
188 
GetControlValue() const189 bool OrientStackedWrapper::GetControlValue() const
190 {
191     return GetControl().GetStackedState() == STATE_CHECK;
192 }
193 
SetControlValue(bool bValue)194 void OrientStackedWrapper::SetControlValue( bool bValue )
195 {
196     GetControl().SetStackedState( bValue ? STATE_CHECK : STATE_NOCHECK );
197 }
198 
199 // ============================================================================
200 
201 } // namespace svx
202 
203