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>
23 #include <o3tl/any.hxx>
24 #include <tools/debug.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/svapp.hxx>
28 #include <com/sun/star/uno/Sequence.hxx>
30 #define DEFAULT_DRAGMODE DragMode::SystemDep
31 #define DEFAULT_SNAPMODE SnapType::ToButton
32 #define DEFAULT_AAMINHEIGHT 8
34 using namespace ::com::sun::star::uno
;
36 bool SvtTabAppearanceCfg::bInitialized
= false;
38 SvtTabAppearanceCfg::SvtTabAppearanceCfg()
39 :ConfigItem("Office.Common/View")
40 ,nDragMode ( DEFAULT_DRAGMODE
)
41 ,nSnapMode ( DEFAULT_SNAPMODE
)
42 ,nMiddleMouse ( MouseMiddleButtonAction::AutoScroll
)
43 ,nAAMinPixelHeight ( DEFAULT_AAMINHEIGHT
)
44 ,bFontAntialiasing ( true )
45 ,bMenuMouseFollow ( false )
47 const Sequence
<OUString
>& rNames
= GetPropertyNames();
48 Sequence
<Any
> aValues
= GetProperties(rNames
);
49 const Any
* pValues
= aValues
.getConstArray();
50 DBG_ASSERT(aValues
.getLength() == rNames
.getLength(), "GetProperties failed");
52 if(aValues
.getLength() != rNames
.getLength())
55 for(int nProp
= 0; nProp
< rNames
.getLength(); ++nProp
, ++pValues
)
57 if(pValues
->hasValue())
61 case 0: //"Window/Drag"
64 if (*pValues
>>= nTmp
)
65 nDragMode
= static_cast<DragMode
>(nTmp
);
68 case 1: bMenuMouseFollow
= *o3tl::doAccess
<bool>(*pValues
); break; //"Menu/FollowMouse",
72 if (*pValues
>>= nTmp
)
73 nSnapMode
= static_cast<SnapType
>(nTmp
); //"Dialog/MousePositioning",
76 case 3: { short nTmp
= 0; *pValues
>>= nTmp
; nMiddleMouse
= static_cast<MouseMiddleButtonAction
>(nTmp
); break; } //"Dialog/MiddleMouseButton",
77 case 4: bFontAntialiasing
= *o3tl::doAccess
<bool>(*pValues
); break; // "FontAntialiasing/Enabled",
78 case 5: *pValues
>>= nAAMinPixelHeight
; break; // "FontAntialiasing/MinPixelHeight",
84 SvtTabAppearanceCfg::~SvtTabAppearanceCfg( )
88 const Sequence
<OUString
>& SvtTabAppearanceCfg::GetPropertyNames()
90 static Sequence
<OUString
> const aNames
93 ,"Menu/FollowMouse" // 1
94 ,"Dialog/MousePositioning" // 2
95 ,"Dialog/MiddleMouseButton" // 3
96 ,"FontAntiAliasing/Enabled" // 4
97 ,"FontAntiAliasing/MinPixelHeight" // 5
102 void SvtTabAppearanceCfg::ImplCommit()
104 const Sequence
<OUString
>& rNames
= GetPropertyNames();
105 Sequence
<Any
> aValues(rNames
.getLength());
106 Any
* pValues
= aValues
.getArray();
108 for(int nProp
= 0; nProp
< rNames
.getLength(); nProp
++)
112 case 0: pValues
[nProp
] <<= static_cast<short>(nDragMode
); break; // "Window/Drag",
113 case 1: pValues
[nProp
] <<= bMenuMouseFollow
; break; // "Menu/FollowMouse",
114 case 2: pValues
[nProp
] <<= static_cast<short>(nSnapMode
); break; // "Dialog/MousePositioning",
115 case 3: pValues
[nProp
] <<= static_cast<short>(nMiddleMouse
); break; // "Dialog/MiddleMouseButton",
116 case 4: pValues
[nProp
] <<= bFontAntialiasing
; break; // "FontAntialiasing/Enabled",
117 case 5: pValues
[nProp
] <<= nAAMinPixelHeight
; break; // "FontAntialiasing/MinPixelHeight",
120 PutProperties(rNames
, aValues
);
123 void SvtTabAppearanceCfg::Notify( const css::uno::Sequence
< OUString
>& )
127 void SvtTabAppearanceCfg::SetSnapMode ( SnapType nSet
)
133 void SvtTabAppearanceCfg::SetMiddleMouseButton ( MouseMiddleButtonAction nSet
)
139 void SvtTabAppearanceCfg::SetApplicationDefaults ( Application
* pApp
)
141 AllSettings hAppSettings
= Application::GetSettings();
142 StyleSettings hAppStyle
= hAppSettings
.GetStyleSettings();
146 // SetStandard...Styles() resets the UseSystemUIFonts flag,
147 // but we don't want to change it now, so save the flag before ...
148 bool bUseSystemUIFonts
= hAppStyle
.GetUseSystemUIFonts();
149 hAppStyle
.SetStandardStyles();
151 hAppStyle
.SetUseSystemUIFonts( bUseSystemUIFonts
);
153 // font anti aliasing
154 hAppStyle
.SetAntialiasingMinPixelHeight( nAAMinPixelHeight
);
155 hAppStyle
.SetDisplayOptions( bFontAntialiasing
? DisplayOptions::NONE
: DisplayOptions::AADisable
);
159 MouseSettings hMouseSettings
= hAppSettings
.GetMouseSettings();
160 MouseSettingsOptions nMouseOptions
= hMouseSettings
.GetOptions();
162 nMouseOptions
&= ~ MouseSettingsOptions(MouseSettingsOptions::AutoCenterPos
| MouseSettingsOptions::AutoDefBtnPos
);
166 case SnapType::ToButton
:
167 nMouseOptions
|= MouseSettingsOptions::AutoDefBtnPos
;
169 case SnapType::ToMiddle
:
170 nMouseOptions
|= MouseSettingsOptions::AutoCenterPos
;
176 hMouseSettings
.SetOptions(nMouseOptions
);
177 hMouseSettings
.SetMiddleButtonAction(nMiddleMouse
);
179 // Merge and Publish Settings
181 MouseFollowFlags nFollow
= hMouseSettings
.GetFollow();
183 nFollow
|= MouseFollowFlags::Menu
;
185 nFollow
&= ~MouseFollowFlags::Menu
;
186 hMouseSettings
.SetFollow( nFollow
);
188 hAppSettings
.SetMouseSettings( hMouseSettings
);
190 hAppSettings
.SetStyleSettings( hAppStyle
);
191 Application::MergeSystemSettings ( hAppSettings
); // Allow system-settings to apply
192 pApp
->OverrideSystemSettings ( hAppSettings
);
194 Application::SetSettings ( hAppSettings
);
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */