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