1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <svtools/apearcfg.hxx>
22 #include <com/sun/star/uno/Any.hxx>
24 #include <tools/debug.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/svapp.hxx>
27 #include <sal/macros.h>
29 #define DEFAULT_DRAGMODE 2
30 #define DEFAULT_SNAPMODE 0
31 #define DEFAULT_SCALEFACTOR 100
33 #define DEFAULT_AAMINHEIGHT 8
36 using namespace ::com::sun::star::uno
;
38 bool SvtTabAppearanceCfg::bInitialized
= false;
40 SvtTabAppearanceCfg::SvtTabAppearanceCfg()
41 :ConfigItem(OUString("Office.Common/View"))
42 ,nDragMode ( DEFAULT_DRAGMODE
)
43 ,nScaleFactor ( DEFAULT_SCALEFACTOR
)
44 ,nSnapMode ( DEFAULT_SNAPMODE
)
45 ,nMiddleMouse ( MouseMiddleButtonAction::AutoScroll
)
47 ,nAAMinPixelHeight ( DEFAULT_AAMINHEIGHT
)
49 ,bMenuMouseFollow ( false )
51 ,bFontAntialiasing ( true )
54 const Sequence
<OUString
>& rNames
= GetPropertyNames();
55 Sequence
<Any
> aValues
= GetProperties(rNames
);
56 const Any
* pValues
= aValues
.getConstArray();
57 DBG_ASSERT(aValues
.getLength() == rNames
.getLength(), "GetProperties failed");
59 if(aValues
.getLength() == rNames
.getLength())
61 for(int nProp
= 0; nProp
< rNames
.getLength(); ++nProp
, ++pValues
)
63 if(pValues
->hasValue())
67 case 0: *pValues
>>= nScaleFactor
; break; //"FontScaling",
68 case 1: *pValues
>>= nDragMode
; break; //"Window/Drag",
69 case 2: bMenuMouseFollow
= *static_cast<sal_Bool
const *>(pValues
->getValue()); break; //"Menu/FollowMouse",
70 case 3: *pValues
>>= nSnapMode
; break; //"Dialog/MousePositioning",
71 case 4: { short nTmp
= 0; *pValues
>>= nTmp
; nMiddleMouse
= static_cast<MouseMiddleButtonAction
>(nTmp
); break; } //"Dialog/MiddleMouseButton",
73 case 5: bFontAntialiasing
= *static_cast<sal_Bool
const *>(pValues
->getValue()); break; // "FontAntialising/Enabled",
74 case 6: *pValues
>>= nAAMinPixelHeight
; break; // "FontAntialising/MinPixelHeight",
82 SvtTabAppearanceCfg::~SvtTabAppearanceCfg( )
86 const Sequence
<OUString
>& SvtTabAppearanceCfg::GetPropertyNames()
88 static Sequence
<OUString
> aNames
;
89 if(!aNames
.getLength())
91 static const sal_Char
* aPropNames
[] =
95 ,"Menu/FollowMouse" // 2
96 ,"Dialog/MousePositioning" // 3
97 ,"Dialog/MiddleMouseButton" // 4
99 ,"FontAntiAliasing/Enabled" // 5
100 ,"FontAntiAliasing/MinPixelHeight" // 6
103 const int nCount
= SAL_N_ELEMENTS( aPropNames
);
104 aNames
.realloc(nCount
);
106 const sal_Char
** pAsciiNames
= aPropNames
;
107 OUString
* pNames
= aNames
.getArray();
108 for(int i
= 0; i
< nCount
; ++i
, ++pNames
, ++pAsciiNames
)
109 *pNames
= OUString::createFromAscii( *pAsciiNames
);
114 void SvtTabAppearanceCfg::ImplCommit()
116 const Sequence
<OUString
>& rNames
= GetPropertyNames();
117 Sequence
<Any
> aValues(rNames
.getLength());
118 Any
* pValues
= aValues
.getArray();
120 const Type
& rType
= cppu::UnoType
<bool>::get();
121 for(int nProp
= 0; nProp
< rNames
.getLength(); nProp
++)
125 case 0: pValues
[nProp
] <<= nScaleFactor
; break; // "FontScaling",
126 case 1: pValues
[nProp
] <<= nDragMode
; break; //"Window/Drag",
127 case 2: pValues
[nProp
].setValue(&bMenuMouseFollow
, rType
); break; //"Menu/FollowMouse",
128 case 3: pValues
[nProp
] <<= nSnapMode
; break; //"Dialog/MousePositioning",
129 case 4: pValues
[nProp
] <<= static_cast<short>(nMiddleMouse
); break; //"Dialog/MiddleMouseButton",
131 case 5: pValues
[nProp
].setValue(&bFontAntialiasing
, rType
); break; // "FontAntialising/Enabled",
132 case 6: pValues
[nProp
] <<= nAAMinPixelHeight
; break; // "FontAntialising/MinPixelHeight",
136 PutProperties(rNames
, aValues
);
139 void SvtTabAppearanceCfg::Notify( const com::sun::star::uno::Sequence
< OUString
>& )
143 void SvtTabAppearanceCfg::SetScaleFactor ( sal_uInt16 nSet
)
149 void SvtTabAppearanceCfg::SetSnapMode ( sal_uInt16 nSet
)
155 void SvtTabAppearanceCfg::SetMiddleMouseButton ( MouseMiddleButtonAction nSet
)
161 void SvtTabAppearanceCfg::SetApplicationDefaults ( Application
* pApp
)
163 AllSettings hAppSettings
= Application::GetSettings();
164 StyleSettings hAppStyle
= hAppSettings
.GetStyleSettings();
168 // SetStandard...Styles() resets the UseSystemUIFonts flag,
169 // but we don't want to change it now, so save the flag before ...
170 bool bUseSystemUIFonts
= hAppStyle
.GetUseSystemUIFonts();
171 hAppStyle
.SetStandardStyles();
173 hAppStyle
.SetUseSystemUIFonts( bUseSystemUIFonts
);
175 // Screen and ScreenFont Scaling
177 hAppStyle
.SetScreenZoom( nScaleFactor
);
178 hAppStyle
.SetScreenFontZoom( nScaleFactor
);
181 // font anti aliasing
182 hAppStyle
.SetAntialiasingMinPixelHeight( nAAMinPixelHeight
);
183 hAppStyle
.SetDisplayOptions( bFontAntialiasing
? DisplayOptions::NONE
: DisplayOptions::AADisable
);
188 MouseSettings hMouseSettings
= hAppSettings
.GetMouseSettings();
189 MouseSettingsOptions nMouseOptions
= hMouseSettings
.GetOptions();
191 nMouseOptions
&= ~ MouseSettingsOptions(MouseSettingsOptions::AutoCenterPos
| MouseSettingsOptions::AutoDefBtnPos
);
196 nMouseOptions
|= MouseSettingsOptions::AutoDefBtnPos
;
199 nMouseOptions
|= MouseSettingsOptions::AutoCenterPos
;
205 hMouseSettings
.SetOptions(nMouseOptions
);
206 hMouseSettings
.SetMiddleButtonAction(nMiddleMouse
);
208 // Merge and Publish Settings
210 MouseFollowFlags nFollow
= hMouseSettings
.GetFollow();
212 nFollow
|= MouseFollowFlags::Menu
;
214 nFollow
&= ~MouseFollowFlags::Menu
;
215 hMouseSettings
.SetFollow( nFollow
);
217 hAppSettings
.SetMouseSettings( hMouseSettings
);
219 hAppSettings
.SetStyleSettings( hAppStyle
);
220 Application::MergeSystemSettings ( hAppSettings
); // Allow system-settings to apply
221 pApp
->OverrideSystemSettings ( hAppSettings
);
223 Application::SetSettings ( hAppSettings
);
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */