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_cui.hxx"
26 
27 #include <optaccessibility.hxx>
28 #include <optaccessibility.hrc>
29 #include <dialmgr.hxx>
30 #include <cuires.hrc>
31 #include <svtools/accessibilityoptions.hxx>
32 #include <vcl/settings.hxx>
33 #include <vcl/svapp.hxx>
34 
MovePosY(Window & _rWin,long _nDelta)35 static void MovePosY( Window& _rWin, long _nDelta )
36 {
37 	Point	aPoint = _rWin.GetPosPixel();
38 	aPoint.Y() += _nDelta;
39 
40 	_rWin.SetPosPixel( aPoint );
41 }
42 
43 struct SvxAccessibilityOptionsTabPage_Impl
44 {
45 	SvtAccessibilityOptions 	m_aConfig;
SvxAccessibilityOptionsTabPage_ImplSvxAccessibilityOptionsTabPage_Impl46 	SvxAccessibilityOptionsTabPage_Impl()
47 			: m_aConfig(){}
48 };
49 
SvxAccessibilityOptionsTabPage(Window * pParent,const SfxItemSet & rSet)50 SvxAccessibilityOptionsTabPage::SvxAccessibilityOptionsTabPage( Window* pParent, const SfxItemSet& rSet )
51 	:SfxTabPage(pParent, CUI_RES( RID_SVXPAGE_ACCESSIBILITYCONFIG ), rSet)
52 	,m_aMiscellaneousLabel		(this, CUI_RES(FL_MISCELLANEOUS		))
53 	,m_aAccessibilityTool		(this, CUI_RES(CB_ACCESSIBILITY_TOOL	))
54     ,m_aTextSelectionInReadonly	(this, CUI_RES(CB_TEXTSELECTION		))
55 	,m_aAnimatedGraphics		(this, CUI_RES(CB_ANIMATED_GRAPHICS	))
56 	,m_aAnimatedTexts			(this, CUI_RES(CB_ANIMATED_TEXTS		))
57 	,m_aTipHelpCB				(this, CUI_RES(CB_TIPHELP				))
58 	,m_aTipHelpNF				(this, CUI_RES(NF_TIPHELP				))
59 	,m_aTipHelpFT				(this, CUI_RES(FT_TIPHELP				))
60 	,m_aHCOptionsLabel			(this, CUI_RES(FL_HC_OPTIONS			))
61 	,m_aAutoDetectHC			(this, CUI_RES(CB_AUTO_DETECT_HC		))
62 	,m_aAutomaticFontColor		(this, CUI_RES(CB_AUTOMATIC_FONT_COLOR))
63     ,m_aPagePreviews			(this, CUI_RES(CB_PAGE_PREVIEWS       ))
64 	,m_pImpl(new SvxAccessibilityOptionsTabPage_Impl)
65 {
66 	FreeResource();
67 	m_aTipHelpCB.SetClickHdl(LINK(this, SvxAccessibilityOptionsTabPage, TipHelpHdl));
68 
69 	long nHeightDelta = 0;		// to correct positions _under_ m_aAccessibilityTool
70 
71 #ifdef UNX
72 	{
73 		// UNIX: read the gconf2 setting instead to use the checkbox
74 		m_aAccessibilityTool.Hide();
75 		nHeightDelta = -( ROWA_2 - ROWA_1 );
76 	}
77 #else
78 	// calculate the height of the checkbox. Do we need two (default in resource) or only one line
79 	String aText = m_aAccessibilityTool.GetText();
80 	long nWidth = m_aAccessibilityTool.GetTextWidth( aText );
81 	long nCtrlWidth = m_aAccessibilityTool.GetSizePixel().Width() - ( COL2 - COL1 );
82 	if ( nWidth > nCtrlWidth )
83 	{
84 		long nDelta = 2 * RSC_CD_FIXEDLINE_HEIGHT + LINESPACE - RSC_CD_CHECKBOX_HEIGHT;
85 		nHeightDelta = nDelta;
86 		Size aSize = m_aAccessibilityTool.LogicToPixel( Size( 0, nDelta ), MAP_APPFONT );
87 		nDelta = aSize.Height();
88 		aSize = m_aAccessibilityTool.GetSizePixel();
89 		aSize.Height() += nDelta;
90 		m_aAccessibilityTool.SetSizePixel( aSize );
91 	}
92 #endif
93 
94 	if( nHeightDelta )
95 	{	//adjust positions of controls under m_aAccessibilityTool
96 		Size aSize = m_aAccessibilityTool.LogicToPixel( Size( 0, nHeightDelta ), MAP_APPFONT );
97 		nHeightDelta = aSize.Height();
98 
99 		MovePosY( m_aTextSelectionInReadonly, nHeightDelta );
100 		MovePosY( m_aAnimatedGraphics, nHeightDelta );
101 		MovePosY( m_aAnimatedTexts, nHeightDelta );
102 		MovePosY( m_aTipHelpCB, nHeightDelta );
103 		MovePosY( m_aTipHelpNF, nHeightDelta );
104 		MovePosY( m_aTipHelpFT, nHeightDelta );
105 		MovePosY( m_aHCOptionsLabel, nHeightDelta );
106 		MovePosY( m_aAutoDetectHC, nHeightDelta );
107 		MovePosY( m_aAutomaticFontColor, nHeightDelta );
108 		MovePosY( m_aPagePreviews, nHeightDelta );
109 	}
110 }
111 
~SvxAccessibilityOptionsTabPage()112 SvxAccessibilityOptionsTabPage::~SvxAccessibilityOptionsTabPage()
113 {
114 	delete m_pImpl;
115 }
116 
Create(Window * pParent,const SfxItemSet & rAttrSet)117 SfxTabPage*	SvxAccessibilityOptionsTabPage::Create( Window* pParent, const SfxItemSet& rAttrSet )
118 {
119 	return new SvxAccessibilityOptionsTabPage(pParent, rAttrSet);
120 }
121 
FillItemSet(SfxItemSet &)122 sal_Bool SvxAccessibilityOptionsTabPage::FillItemSet( SfxItemSet& )
123 {
124 	//aConfig.Set... from controls
125 
126     m_pImpl->m_aConfig.SetIsForPagePreviews( m_aPagePreviews.IsChecked() );
127 	m_pImpl->m_aConfig.SetIsHelpTipsDisappear( m_aTipHelpCB.IsChecked() );
128 	m_pImpl->m_aConfig.SetHelpTipSeconds( (short)m_aTipHelpNF.GetValue() );
129 	m_pImpl->m_aConfig.SetIsAllowAnimatedGraphics( m_aAnimatedGraphics.IsChecked() );
130 	m_pImpl->m_aConfig.SetIsAllowAnimatedText( m_aAnimatedTexts.IsChecked() );
131 	m_pImpl->m_aConfig.SetIsAutomaticFontColor(	m_aAutomaticFontColor.IsChecked() );
132     m_pImpl->m_aConfig.SetSelectionInReadonly( m_aTextSelectionInReadonly.IsChecked());
133     m_pImpl->m_aConfig.SetAutoDetectSystemHC( m_aAutoDetectHC.IsChecked());
134 
135 	if(m_pImpl->m_aConfig.IsModified())
136 		m_pImpl->m_aConfig.Commit();
137 
138     AllSettings aAllSettings = Application::GetSettings();
139     MiscSettings aMiscSettings = aAllSettings.GetMiscSettings();
140 #ifndef UNX
141     aMiscSettings.SetEnableATToolSupport( m_aAccessibilityTool.IsChecked() );
142 #endif
143     aAllSettings.SetMiscSettings(aMiscSettings);
144     Application::MergeSystemSettings( aAllSettings );
145     Application::SetSettings(aAllSettings);
146 
147 	return sal_False;
148 }
149 
Reset(const SfxItemSet &)150 void SvxAccessibilityOptionsTabPage::Reset( const SfxItemSet& )
151 {
152 	//set controls from aConfig.Get...
153 
154     m_aPagePreviews.Check(			  m_pImpl->m_aConfig.GetIsForPagePreviews() );
155 	EnableTipHelp(					  m_pImpl->m_aConfig.GetIsHelpTipsDisappear() );
156 	m_aTipHelpNF.SetValue(			  m_pImpl->m_aConfig.GetHelpTipSeconds() );
157 	m_aAnimatedGraphics.Check(		  m_pImpl->m_aConfig.GetIsAllowAnimatedGraphics() );
158 	m_aAnimatedTexts.Check(			  m_pImpl->m_aConfig.GetIsAllowAnimatedText() );
159 	m_aAutomaticFontColor.Check(	  m_pImpl->m_aConfig.GetIsAutomaticFontColor() );
160 //	m_aSystemFont.Check(			  m_pImpl->m_aConfig.GetIsSystemFont() );
161     m_aTextSelectionInReadonly.Check( m_pImpl->m_aConfig.IsSelectionInReadonly() );
162     m_aAutoDetectHC.Check(			  m_pImpl->m_aConfig.GetAutoDetectSystemHC() );
163 
164 
165     AllSettings aAllSettings = Application::GetSettings();
166     MiscSettings aMiscSettings = aAllSettings.GetMiscSettings();
167     m_aAccessibilityTool.Check( aMiscSettings.GetEnableATToolSupport() );
168 }
169 
IMPL_LINK(SvxAccessibilityOptionsTabPage,TipHelpHdl,CheckBox *,pBox)170 IMPL_LINK(SvxAccessibilityOptionsTabPage, TipHelpHdl, CheckBox*, pBox)
171 {
172 	sal_Bool bChecked = pBox->IsChecked();
173 	m_aTipHelpNF.Enable(bChecked);
174 	return 0;
175 }
176 
EnableTipHelp(sal_Bool bCheck)177 void SvxAccessibilityOptionsTabPage::EnableTipHelp(sal_Bool bCheck)
178 {
179 	m_aTipHelpCB.Check(bCheck);
180 	m_aTipHelpNF.Enable(bCheck);
181 }
182