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