xref: /AOO41X/main/svtools/source/config/apearcfg.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_svtools.hxx"
30 
31 #include <svtools/apearcfg.hxx>
32 #include "com/sun/star/uno/Any.hxx"
33 
34 #include "tools/debug.hxx"
35 #include "vcl/settings.hxx"
36 #include "vcl/svapp.hxx"
37 #include <rtl/logfile.hxx>
38 
39 #define DEFAULT_LOOKNFEEL   0
40 #define DEFAULT_DRAGMODE    2
41 #define DEFAULT_SNAPMODE    0
42 #define DEFAULT_SCALEFACTOR 100
43 #define DEFAULT_AAMINHEIGHT	8
44 
45 using namespace ::rtl;
46 using namespace ::com::sun::star::uno;
47 
48 sal_Bool SvtTabAppearanceCfg::bInitialized = sal_False;
49 
50 /*--------------------------------------------------------------------
51 	 Beschreibung:
52  --------------------------------------------------------------------*/
53 SvtTabAppearanceCfg::SvtTabAppearanceCfg()
54 	:ConfigItem(OUString::createFromAscii("Office.Common/View"))
55 	,nDragMode			( DEFAULT_DRAGMODE )
56 	,nScaleFactor       ( DEFAULT_SCALEFACTOR )
57 	,nSnapMode			( DEFAULT_SNAPMODE )
58     ,nMiddleMouse       ( MOUSE_MIDDLE_AUTOSCROLL )
59 #if defined( UNX ) || defined ( FS_PRIV_DEBUG )
60 	,nAAMinPixelHeight	( DEFAULT_AAMINHEIGHT )
61 #endif
62 	,bMenuMouseFollow(sal_False)
63 #if defined( UNX ) || defined ( FS_PRIV_DEBUG )
64 	,bFontAntialiasing	( sal_True )
65 #endif
66 {
67 	RTL_LOGFILE_CONTEXT(aLog, "svtools SvtTabAppearanceCfg::SvtTabAppearanceCfg()");
68 
69     const Sequence<OUString>& rNames = GetPropertyNames();
70     Sequence<Any> aValues = GetProperties(rNames);
71 	const Any* pValues = aValues.getConstArray();
72     DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
73 
74 	if(aValues.getLength() == rNames.getLength())
75 	{
76         for(int nProp = 0; nProp < rNames.getLength(); ++nProp, ++pValues)
77 		{
78 			if(pValues->hasValue())
79 			{
80 				switch(nProp)
81 				{
82                     case  0: *pValues >>= nScaleFactor; break; //"FontScaling",
83                     case  1: *pValues >>= nDragMode; break;   //"Window/Drag",
84                     case  2: bMenuMouseFollow = *(sal_Bool*)pValues->getValue(); break; //"Menu/FollowMouse",
85                     case  3: *pValues >>= nSnapMode; break; //"Dialog/MousePositioning",
86                     case  4: *pValues >>= nMiddleMouse; break; //"Dialog/MiddleMouseButton",
87 #if defined( UNX ) || defined ( FS_PRIV_DEBUG )
88                     case  5: bFontAntialiasing = *(sal_Bool*)pValues->getValue(); break;    // "FontAntialising/Enabled",
89                     case  6: *pValues >>= nAAMinPixelHeight; break;                         // "FontAntialising/MinPixelHeight",
90 #endif
91                 }
92 			}
93 		}
94     }
95 }
96 /* -----------------------------22.05.01 11:53--------------------------------
97 
98  ---------------------------------------------------------------------------*/
99 SvtTabAppearanceCfg::~SvtTabAppearanceCfg( )
100 {
101 }
102 /* -----------------------------22.05.01 11:54--------------------------------
103 
104  ---------------------------------------------------------------------------*/
105 const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames()
106 {
107     static Sequence<OUString> aNames;
108     if(!aNames.getLength())
109     {
110         static const sal_Char* aPropNames[] =
111         {
112              "FontScaling"                       //  0
113             ,"Window/Drag"                       //  1
114             ,"Menu/FollowMouse"                  //  2
115             ,"Dialog/MousePositioning"           //  3
116             ,"Dialog/MiddleMouseButton"          //  4
117 #if defined( UNX ) || defined ( FS_PRIV_DEBUG )
118             ,"FontAntiAliasing/Enabled"         //  5
119             ,"FontAntiAliasing/MinPixelHeight"  //  6
120 #endif
121         };
122         const int nCount = sizeof( aPropNames ) / sizeof( aPropNames[0] );
123         aNames.realloc(nCount);
124 
125 		const sal_Char** pAsciiNames = aPropNames;
126         OUString* pNames = aNames.getArray();
127         for(int i = 0; i < nCount; ++i, ++pNames, ++pAsciiNames)
128             *pNames = OUString::createFromAscii( *pAsciiNames );
129     }
130     return aNames;
131 }
132 /* -----------------------------22.05.01 11:54--------------------------------
133 
134  ---------------------------------------------------------------------------*/
135 void  SvtTabAppearanceCfg::Commit()
136 {
137     const Sequence<OUString>& rNames = GetPropertyNames();
138     Sequence<Any> aValues(rNames.getLength());
139 	Any* pValues = aValues.getArray();
140 
141 	const Type& rType = ::getBooleanCppuType();
142     for(int nProp = 0; nProp < rNames.getLength(); nProp++)
143 	{
144 		switch(nProp)
145 		{
146             case  0: pValues[nProp] <<= nScaleFactor; break;            // "FontScaling",
147             case  1: pValues[nProp] <<= nDragMode; break;               //"Window/Drag",
148             case  2: pValues[nProp].setValue(&bMenuMouseFollow, rType); break; //"Menu/FollowMouse",
149             case  3: pValues[nProp] <<= nSnapMode; break;               //"Dialog/MousePositioning",
150             case  4: pValues[nProp] <<= nMiddleMouse; break;               //"Dialog/MiddleMouseButton",
151 #if defined( UNX ) || defined ( FS_PRIV_DEBUG )
152             case  5: pValues[nProp].setValue(&bFontAntialiasing, rType); break; // "FontAntialising/Enabled",
153             case  6: pValues[nProp] <<= nAAMinPixelHeight; break;               // "FontAntialising/MinPixelHeight",
154 #endif
155         }
156 	}
157     PutProperties(rNames, aValues);
158 }
159 
160 void SvtTabAppearanceCfg::Notify( const com::sun::star::uno::Sequence< rtl::OUString >& )
161 {
162 }
163 
164 /*--------------------------------------------------------------------
165 	 Beschreibung:
166  --------------------------------------------------------------------*/
167 
168 void SvtTabAppearanceCfg::SetDragMode  ( sal_uInt16 nSet )
169 {
170 	nDragMode = nSet;
171     SetModified();
172 }
173 
174 /*--------------------------------------------------------------------
175 	 Beschreibung:
176  --------------------------------------------------------------------*/
177 
178 void SvtTabAppearanceCfg::SetScaleFactor ( sal_uInt16 nSet )
179 {
180 	nScaleFactor = nSet;
181     SetModified();
182 }
183 
184 /*--------------------------------------------------------------------
185 	 Beschreibung:
186  --------------------------------------------------------------------*/
187 
188 void SvtTabAppearanceCfg::SetSnapMode ( sal_uInt16 nSet )
189 {
190 	nSnapMode = nSet;
191     SetModified();
192 }
193 /*--------------------------------------------------------------------
194 	 Beschreibung:
195  --------------------------------------------------------------------*/
196 void SvtTabAppearanceCfg::SetMiddleMouseButton ( sal_uInt16 nSet )
197 {
198     nMiddleMouse = nSet;
199     SetModified();
200 }
201 /*--------------------------------------------------------------------
202 	 Beschreibung:
203  --------------------------------------------------------------------*/
204 
205 void SvtTabAppearanceCfg::SetApplicationDefaults ( Application* pApp )
206 {
207 	AllSettings   hAppSettings = pApp->GetSettings();
208 	StyleSettings hAppStyle    = hAppSettings.GetStyleSettings();
209 
210 	// Look & Feel
211 
212 	// SetStandard...Styles() resets the UseSystemUIFonts flag,
213 	// but we don't want to change it now, so save the flag before ...
214 	sal_Bool bUseSystemUIFonts = hAppStyle.GetUseSystemUIFonts();
215 	hAppStyle.SetStandardStyles();
216 	// and set it here
217 	hAppStyle.SetUseSystemUIFonts( bUseSystemUIFonts );
218 
219 	// Screen and ScreenFont Scaling
220 
221 	hAppStyle.SetScreenZoom( nScaleFactor );
222 	hAppStyle.SetScreenFontZoom( nScaleFactor );
223 
224 #if defined( UNX ) || defined ( FS_PRIV_DEBUG )
225 	// font anti aliasing
226 	hAppStyle.SetAntialiasingMinPixelHeight( nAAMinPixelHeight );
227 	hAppStyle.SetDisplayOptions( bFontAntialiasing ? 0 : DISPLAY_OPTION_AA_DISABLE );
228 #endif
229 
230 	// Mouse Snap
231 
232 	MouseSettings hMouseSettings = hAppSettings.GetMouseSettings();
233 	sal_uLong         nMouseOptions  = hMouseSettings.GetOptions();
234 
235 	nMouseOptions &=  ! (MOUSE_OPTION_AUTOCENTERPOS | MOUSE_OPTION_AUTODEFBTNPOS);
236 
237 	switch ( nSnapMode )
238 	{
239 	case SnapToButton:
240 		nMouseOptions |= MOUSE_OPTION_AUTODEFBTNPOS;
241 		break;
242 	case SnapToMiddle:
243 		nMouseOptions |= MOUSE_OPTION_AUTOCENTERPOS;
244 		break;
245 	case NoSnap:
246 	default:
247 		break;
248 	}
249     hMouseSettings.SetOptions(nMouseOptions);
250     hMouseSettings.SetMiddleButtonAction(nMiddleMouse);
251 
252     // Merge and Publish Settings
253 
254     sal_uLong nFollow = hMouseSettings.GetFollow();
255     if(bMenuMouseFollow)
256         nFollow |= MOUSE_FOLLOW_MENU;
257     else
258         nFollow &= ~MOUSE_FOLLOW_MENU;
259     hMouseSettings.SetFollow( nFollow );
260 
261     hAppSettings.SetMouseSettings( hMouseSettings );
262 
263 	hAppSettings.SetStyleSettings( hAppStyle );
264 	pApp->MergeSystemSettings    ( hAppSettings );      // Allow system-settings to apply
265 	pApp->SystemSettingsChanging ( hAppSettings, NULL );// Allow overruling of system-settings
266 														//is concerned with window drag
267 
268 	pApp->SetSettings ( hAppSettings );
269 }
270 
271 
272 
273