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