LibreOffice Module vcl (master) 1
window/settings.cxx
Go to the documentation of this file.
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
22
23#include <vcl/event.hxx>
24#include <vcl/svapp.hxx>
25#include <vcl/window.hxx>
26#include <vcl/settings.hxx>
27
28#include <officecfg/Office/Common.hxx>
29
32
34
35#include <salframe.hxx>
36#include <brdwin.hxx>
37
38#include <window.h>
39
40namespace vcl {
41
43{
44 SetSettings( rSettings, false );
45}
46
47void WindowOutputDevice::SetSettings( const AllSettings& rSettings, bool bChild )
48{
49
50 if ( auto pBorderWindow = mxOwnerWindow->mpWindowImpl->mpBorderWindow.get() )
51 {
52 static_cast<vcl::WindowOutputDevice*>(pBorderWindow->GetOutDev())->SetSettings( rSettings, false );
53 if ( (pBorderWindow->GetType() == WindowType::BORDERWINDOW) &&
54 static_cast<ImplBorderWindow*>(pBorderWindow)->mpMenuBarWindow )
55 static_cast<vcl::WindowOutputDevice*>(static_cast<ImplBorderWindow*>(pBorderWindow)->mpMenuBarWindow->GetOutDev())->SetSettings( rSettings, true );
56 }
57
58 AllSettings aOldSettings(*moSettings);
59 OutputDevice::SetSettings( rSettings );
60 AllSettingsFlags nChangeFlags = aOldSettings.GetChangeFlags( rSettings );
61
62 // recalculate AppFont-resolution and DPI-resolution
64
65 if ( bool(nChangeFlags) )
66 {
67 DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
68 mxOwnerWindow->DataChanged( aDCEvt );
69 }
70
71 if ( bChild )
72 {
73 vcl::Window* pChild = mxOwnerWindow->mpWindowImpl->mpFirstChild;
74 while ( pChild )
75 {
76 static_cast<vcl::WindowOutputDevice*>(pChild->GetOutDev())->SetSettings( rSettings, bChild );
77 pChild = pChild->mpWindowImpl->mpNext;
78 }
79 }
80}
81
82void Window::UpdateSettings( const AllSettings& rSettings, bool bChild )
83{
84
85 if ( mpWindowImpl->mpBorderWindow )
86 {
87 mpWindowImpl->mpBorderWindow->UpdateSettings( rSettings );
88 if (mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW)
89 {
90 ImplBorderWindow* pImpl = static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get());
91 if (pImpl->mpMenuBarWindow)
92 pImpl->mpMenuBarWindow->UpdateSettings(rSettings, true);
93 if (pImpl->mpNotebookBar)
94 pImpl->mpNotebookBar->UpdateSettings(rSettings, true);
95 }
96 }
97
98 AllSettings aOldSettings(*mpWindowImpl->mxOutDev->moSettings);
99 AllSettingsFlags nChangeFlags = mpWindowImpl->mxOutDev->moSettings->Update( AllSettings::GetWindowUpdate(), rSettings );
100
101 // recalculate AppFont-resolution and DPI-resolution
103
104 /* #i73785#
105 * do not overwrite a WheelBehavior with false
106 * this looks kind of a hack, but WheelBehavior
107 * is always a local change, not a system property,
108 * so we can spare all our users the hassle of reacting on
109 * this in their respective DataChanged.
110 */
111 MouseSettings aSet( mpWindowImpl->mxOutDev->moSettings->GetMouseSettings() );
112 aSet.SetWheelBehavior( aOldSettings.GetMouseSettings().GetWheelBehavior() );
113 mpWindowImpl->mxOutDev->moSettings->SetMouseSettings( aSet );
114
115 if( (nChangeFlags & AllSettingsFlags::STYLE) && IsBackground() )
116 {
117 Wallpaper aWallpaper = GetBackground();
118 if( !aWallpaper.IsBitmap() && !aWallpaper.IsGradient() )
119 {
120 if ( mpWindowImpl->mnStyle & WB_3DLOOK )
121 {
122 if (aOldSettings.GetStyleSettings().GetFaceColor() != rSettings.GetStyleSettings().GetFaceColor())
124 }
125 else
126 {
127 if (aOldSettings.GetStyleSettings().GetWindowColor() != rSettings.GetStyleSettings().GetWindowColor())
129 }
130 }
131 }
132
133 if ( bool(nChangeFlags) )
134 {
135 DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
136 DataChanged( aDCEvt );
137 // notify data change handler
139 }
140
141 if ( bChild )
142 {
143 vcl::Window* pChild = mpWindowImpl->mpFirstChild;
144 while ( pChild )
145 {
146 pChild->UpdateSettings( rSettings, bChild );
147 pChild = pChild->mpWindowImpl->mpNext;
148 }
149 }
150}
151
152void Window::ImplUpdateGlobalSettings( AllSettings& rSettings, bool bCallHdl ) const
153{
154 StyleSettings aTmpSt( rSettings.GetStyleSettings() );
155 aTmpSt.SetHighContrastMode( false );
156 rSettings.SetStyleSettings( aTmpSt );
157 ImplGetFrame()->UpdateSettings( rSettings );
158
159 StyleSettings aStyleSettings = rSettings.GetStyleSettings();
160
161 vcl::Font aFont = aStyleSettings.GetMenuFont();
162 int defFontheight = aFont.GetFontHeight();
163
164 // if the UI is korean, chinese or another locale
165 // where the system font size is known to be often too small to
166 // generate readable fonts enforce a minimum font size of 9 points
167 bool bBrokenLangFontHeight = MsLangId::isCJK(Application::GetSettings().GetUILanguageTag().getLanguageType());
168 if (bBrokenLangFontHeight)
169 defFontheight = std::max(9, defFontheight);
170
171 // i22098, toolfont will be scaled differently to avoid bloated rulers and status bars for big fonts
172 int toolfontheight = defFontheight;
173 if( toolfontheight > 9 )
174 toolfontheight = (defFontheight+8) / 2;
175
176 aFont = aStyleSettings.GetAppFont();
177 aFont.SetFontHeight( defFontheight );
178 aStyleSettings.SetAppFont( aFont );
179 aFont = aStyleSettings.GetTitleFont();
180 aFont.SetFontHeight( defFontheight );
181 aStyleSettings.SetTitleFont( aFont );
182 aFont = aStyleSettings.GetFloatTitleFont();
183 aFont.SetFontHeight( defFontheight );
184 aStyleSettings.SetFloatTitleFont( aFont );
185 // keep menu and help font size from system unless in broken locale size
186 if( bBrokenLangFontHeight )
187 {
188 aFont = aStyleSettings.GetMenuFont();
189 if( aFont.GetFontHeight() < defFontheight )
190 {
191 aFont.SetFontHeight( defFontheight );
192 aStyleSettings.SetMenuFont( aFont );
193 }
194 aFont = aStyleSettings.GetHelpFont();
195 if( aFont.GetFontHeight() < defFontheight )
196 {
197 aFont.SetFontHeight( defFontheight );
198 aStyleSettings.SetHelpFont( aFont );
199 }
200 }
201
202 // use different height for toolfont
203 aFont = aStyleSettings.GetToolFont();
204 aFont.SetFontHeight( toolfontheight );
205 aStyleSettings.SetToolFont( aFont );
206
207 aFont = aStyleSettings.GetLabelFont();
208 aFont.SetFontHeight( defFontheight );
209 aStyleSettings.SetLabelFont( aFont );
210 aFont = aStyleSettings.GetRadioCheckFont();
211 aFont.SetFontHeight( defFontheight );
212 aStyleSettings.SetRadioCheckFont( aFont );
213 aFont = aStyleSettings.GetPushButtonFont();
214 aFont.SetFontHeight( defFontheight );
215 aStyleSettings.SetPushButtonFont( aFont );
216 aFont = aStyleSettings.GetFieldFont();
217 aFont.SetFontHeight( defFontheight );
218 aStyleSettings.SetFieldFont( aFont );
219 aFont = aStyleSettings.GetIconFont();
220 aFont.SetFontHeight( defFontheight );
221 aStyleSettings.SetIconFont( aFont );
222 aFont = aStyleSettings.GetTabFont();
223 aFont.SetFontHeight( defFontheight );
224 aStyleSettings.SetTabFont( aFont );
225 aFont = aStyleSettings.GetGroupFont();
226 aFont.SetFontHeight( defFontheight );
227 aStyleSettings.SetGroupFont( aFont );
228
229 static const bool bFuzzing = utl::ConfigManager::IsFuzzing();
230 if (!bFuzzing)
231 {
232 static const char* pEnvHC = getenv( "SAL_FORCE_HC" );
233 const bool bForceHCMode = pEnvHC && *pEnvHC;
234 if (bForceHCMode)
235 aStyleSettings.SetHighContrastMode( true );
236 else
237 {
238 sal_Int32 nHighContrastMode = officecfg::Office::Common::Accessibility::HighContrast::get();
239 if (nHighContrastMode != 0) // 0 Automatic, 1 Disable, 2 Enable
240 {
241 const bool bEnable = nHighContrastMode == 2;
242 aStyleSettings.SetHighContrastMode(bEnable);
243 }
244 }
245 }
246
247 rSettings.SetStyleSettings( aStyleSettings );
248
249 if ( bCallHdl )
250 GetpApp()->OverrideSystemSettings( rSettings );
251}
252
253} /*namespace vcl*/
254
255/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SAL_DLLPRIVATE AllSettingsFlags GetWindowUpdate()
Definition: settings.hxx:732
const MouseSettings & GetMouseSettings() const
SAL_DLLPRIVATE AllSettingsFlags GetChangeFlags(const AllSettings &rSettings) const
const StyleSettings & GetStyleSettings() const
void SetStyleSettings(const StyleSettings &rSet)
virtual void OverrideSystemSettings(AllSettings &rSettings)
Sets user settings in settings object to override system settings.
Definition: svapp.cxx:521
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:638
VclPtr< NotebookBar > mpNotebookBar
Definition: brdwin.hxx:87
VclPtr< vcl::Window > mpMenuBarWindow
Definition: brdwin.hxx:86
void SetWheelBehavior(MouseWheelBehaviour nBehavior)
MouseWheelBehaviour GetWheelBehavior() const
static bool isCJK(LanguageType nLang)
virtual void SetSettings(const AllSettings &rSettings)
Definition: outdev.cxx:215
std::optional< AllSettings > moSettings
Definition: outdev.hxx:234
virtual void UpdateSettings(AllSettings &rSettings)=0
void SetLabelFont(const vcl::Font &rFont)
void SetRadioCheckFont(const vcl::Font &rFont)
void SetFloatTitleFont(const vcl::Font &rFont)
const vcl::Font & GetHelpFont() const
const Color & GetWindowColor() const
void SetHelpFont(const vcl::Font &rFont)
void SetToolFont(const vcl::Font &rFont)
void SetPushButtonFont(const vcl::Font &rFont)
const vcl::Font & GetMenuFont() const
const vcl::Font & GetRadioCheckFont() const
const vcl::Font & GetTabFont() const
const vcl::Font & GetFieldFont() const
const vcl::Font & GetFloatTitleFont() const
void SetTabFont(const vcl::Font &rFont)
const vcl::Font & GetLabelFont() const
void SetGroupFont(const vcl::Font &rFont)
const vcl::Font & GetGroupFont() const
const vcl::Font & GetPushButtonFont() const
void SetHighContrastMode(bool bHighContrast)
void SetAppFont(const vcl::Font &rFont)
const vcl::Font & GetToolFont() const
void SetTitleFont(const vcl::Font &rFont)
void SetFieldFont(const vcl::Font &rFont)
void SetIconFont(const vcl::Font &rFont)
const vcl::Font & GetIconFont() const
const Color & GetFaceColor() const
const vcl::Font & GetAppFont() const
const vcl::Font & GetTitleFont() const
void SetMenuFont(const vcl::Font &rFont)
bool IsBitmap() const
Definition: wall.cxx:189
bool IsGradient() const
Definition: wall.cxx:213
static bool IsFuzzing()
tools::Long GetFontHeight() const
Definition: font/font.cxx:909
void SetFontHeight(tools::Long nHeight)
Definition: font/font.cxx:908
virtual void SetSettings(const AllSettings &rSettings) override
VclPtr< vcl::Window > mxOwnerWindow
Definition: windowdev.hxx:77
const Wallpaper & GetBackground() const
Definition: window3.cxx:63
bool IsBackground() const
Definition: window3.cxx:64
void UpdateSettings(const AllSettings &rSettings, bool bChild=false)
::OutputDevice const * GetOutDev() const
Definition: window.cxx:567
SAL_DLLPRIVATE void ImplInitResolutionSettings()
Definition: window.cxx:1347
std::unique_ptr< WindowImpl > mpWindowImpl
Definition: window.hxx:484
SalFrame * ImplGetFrame() const
Definition: window2.cxx:879
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:36
void CallEventListeners(VclEventId nEvent, void *pData=nullptr)
Definition: event.cxx:219
SAL_DLLPRIVATE void ImplUpdateGlobalSettings(AllSettings &rSettings, bool bCallHdl=true) const
void SetBackground()
Definition: window3.cxx:100
AllSettingsFlags
Definition: settings.hxx:682
Application * GetpApp()
Definition: svapp.cxx:154
WinBits const WB_3DLOOK
Definition: wintypes.hxx:118