1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "svx/orienthelper.hxx"
25 #include <vcl/button.hxx>
26 #include "svx/dialcontrol.hxx"
32 struct OrientationHelper_Impl
34 typedef std::pair
< Window
*, TriState
> WindowPair
;
35 typedef std::vector
< WindowPair
> WindowVec
;
37 DialControl
& mrCtrlDial
;
38 CheckBox
& mrCbStacked
;
43 explicit OrientationHelper_Impl( DialControl
& rCtrlDial
, CheckBox
& rCbStacked
);
45 void AddDependentWindow( Window
& rWindow
, TriState eDisableIfStacked
);
47 void EnableDependentWindows();
48 void EnableWindow( Window
& rWindow
, TriState eDisableIfStacked
);
50 void ShowDependentWindows();
52 DECL_LINK( ClickHdl
, void* );
57 OrientationHelper_Impl::OrientationHelper_Impl( DialControl
& rCtrlDial
, CheckBox
& rCbStacked
) :
58 mrCtrlDial( rCtrlDial
),
59 mrCbStacked( rCbStacked
),
60 mbEnabled( rCtrlDial
.IsEnabled() ),
61 mbVisible( rCtrlDial
.IsVisible() )
63 maWinVec
.push_back( WindowPair( &mrCtrlDial
, TRISTATE_TRUE
) );
64 maWinVec
.push_back( WindowPair( &mrCbStacked
, TRISTATE_INDET
) );
65 mrCbStacked
.SetClickHdl( LINK( this, OrientationHelper_Impl
, ClickHdl
) );
68 void OrientationHelper_Impl::AddDependentWindow( Window
& rWindow
, TriState eDisableIfStacked
)
70 maWinVec
.push_back( std::make_pair( &rWindow
, eDisableIfStacked
) );
71 EnableWindow( rWindow
, eDisableIfStacked
);
74 void OrientationHelper_Impl::EnableDependentWindows()
76 for( WindowVec::iterator aIt
= maWinVec
.begin(), aEnd
= maWinVec
.end(); aIt
!= aEnd
; ++aIt
)
77 EnableWindow( *aIt
->first
, aIt
->second
);
80 void OrientationHelper_Impl::EnableWindow( Window
& rWindow
, TriState eDisableIfStacked
)
82 bool bDisableOnStacked
= false;
83 switch( eDisableIfStacked
)
85 // TRISTATE_TRUE: Disable window, if stacked text is turned on or "don't know".
86 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 case TRISTATE_FALSE
: bDisableOnStacked
= (mrCbStacked
.GetState() != TRISTATE_TRUE
); break;
89 default: ;//prevent warning
91 rWindow
.Enable( mbEnabled
&& !bDisableOnStacked
);
94 void OrientationHelper_Impl::ShowDependentWindows()
96 for( WindowVec::iterator aIt
= maWinVec
.begin(), aEnd
= maWinVec
.end(); aIt
!= aEnd
; ++aIt
)
97 aIt
->first
->Show( mbVisible
);
100 IMPL_LINK_NOARG(OrientationHelper_Impl
, ClickHdl
)
102 EnableDependentWindows();
108 OrientationHelper::OrientationHelper( DialControl
& rCtrlDial
, NumericField
& rNfRotation
, CheckBox
& rCbStacked
) :
109 mpImpl( new OrientationHelper_Impl( rCtrlDial
, rCbStacked
) )
111 rCtrlDial
.SetLinkedField( &rNfRotation
);
112 mpImpl
->EnableDependentWindows();
113 mpImpl
->ShowDependentWindows();
116 OrientationHelper::~OrientationHelper()
120 void OrientationHelper::AddDependentWindow( Window
& rWindow
, TriState eDisableIfStacked
)
122 mpImpl
->AddDependentWindow( rWindow
, eDisableIfStacked
);
125 void OrientationHelper::Enable( bool bEnable
)
127 mpImpl
->mbEnabled
= bEnable
;
128 mpImpl
->EnableDependentWindows();
131 void OrientationHelper::Show( bool bShow
)
133 mpImpl
->mbVisible
= bShow
;
134 mpImpl
->ShowDependentWindows();
137 void OrientationHelper::SetStackedState( TriState eState
)
139 if( eState
!= GetStackedState() )
141 mpImpl
->mrCbStacked
.SetState( eState
);
142 mpImpl
->EnableDependentWindows();
146 TriState
OrientationHelper::GetStackedState() const
148 return mpImpl
->mrCbStacked
.GetState();
151 void OrientationHelper::EnableStackedTriState( bool bEnable
)
153 mpImpl
->mrCbStacked
.EnableTriState( bEnable
);
158 OrientStackedWrapper::OrientStackedWrapper( OrientationHelper
& rOrientHlp
) :
159 SingleControlWrapperType( rOrientHlp
)
163 bool OrientStackedWrapper::IsControlDontKnow() const
165 return GetControl().GetStackedState() == TRISTATE_INDET
;
168 void OrientStackedWrapper::SetControlDontKnow( bool bSet
)
170 GetControl().EnableStackedTriState( bSet
);
171 GetControl().SetStackedState( bSet
? TRISTATE_INDET
: TRISTATE_FALSE
);
174 bool OrientStackedWrapper::GetControlValue() const
176 return GetControl().GetStackedState() == TRISTATE_TRUE
;
179 void OrientStackedWrapper::SetControlValue( bool bValue
)
181 GetControl().SetStackedState( bValue
? TRISTATE_TRUE
: TRISTATE_FALSE
);
188 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */