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 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow )
90 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->UpdateSettings( rSettings, true );
91 }
92
93 AllSettings aOldSettings(*mpWindowImpl->mxOutDev->moSettings);
94 AllSettingsFlags nChangeFlags = mpWindowImpl->mxOutDev->moSettings->Update( AllSettings::GetWindowUpdate(), rSettings );
95
96 // recalculate AppFont-resolution and DPI-resolution
98
99 /* #i73785#
100 * do not overwrite a WheelBehavior with false
101 * this looks kind of a hack, but WheelBehavior
102 * is always a local change, not a system property,
103 * so we can spare all our users the hassle of reacting on
104 * this in their respective DataChanged.
105 */
106 MouseSettings aSet( mpWindowImpl->mxOutDev->moSettings->GetMouseSettings() );
107 aSet.SetWheelBehavior( aOldSettings.GetMouseSettings().GetWheelBehavior() );
108 mpWindowImpl->mxOutDev->moSettings->SetMouseSettings( aSet );
109
110 if( (nChangeFlags & AllSettingsFlags::STYLE) && IsBackground() )
111 {
112 Wallpaper aWallpaper = GetBackground();
113 if( !aWallpaper.IsBitmap() && !aWallpaper.IsGradient() )
114 {
115 if ( mpWindowImpl->mnStyle & WB_3DLOOK )
116 {
117 if (aOldSettings.GetStyleSettings().GetFaceColor() != rSettings.GetStyleSettings().GetFaceColor())
119 }
120 else
121 {
122 if (aOldSettings.GetStyleSettings().GetWindowColor() != rSettings.GetStyleSettings().GetWindowColor())
124 }
125 }
126 }
127
128 if ( bool(nChangeFlags) )
129 {
130 DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
131 DataChanged( aDCEvt );
132 // notify data change handler
134 }
135
136 if ( bChild )
137 {
138 vcl::Window* pChild = mpWindowImpl->mpFirstChild;
139 while ( pChild )
140 {
141 pChild->UpdateSettings( rSettings, bChild );
142 pChild = pChild->mpWindowImpl->mpNext;
143 }
144 }
145}
146
147void Window::ImplUpdateGlobalSettings( AllSettings& rSettings, bool bCallHdl ) const
148{
149 StyleSettings aTmpSt( rSettings.GetStyleSettings() );
150 aTmpSt.SetHighContrastMode( false );
151 rSettings.SetStyleSettings( aTmpSt );
152 ImplGetFrame()->UpdateSettings( rSettings );
153
154 StyleSettings aStyleSettings = rSettings.GetStyleSettings();
155
156 vcl::Font aFont = aStyleSettings.GetMenuFont();
157 int defFontheight = aFont.GetFontHeight();
158
159 // if the UI is korean, chinese or another locale
160 // where the system font size is known to be often too small to
161 // generate readable fonts enforce a minimum font size of 9 points
162 bool bBrokenLangFontHeight = MsLangId::isCJK(Application::GetSettings().GetUILanguageTag().getLanguageType());
163 if (bBrokenLangFontHeight)
164 defFontheight = std::max(9, defFontheight);
165
166 // i22098, toolfont will be scaled differently to avoid bloated rulers and status bars for big fonts
167 int toolfontheight = defFontheight;
168 if( toolfontheight > 9 )
169 toolfontheight = (defFontheight+8) / 2;
170
171 aFont = aStyleSettings.GetAppFont();
172 aFont.SetFontHeight( defFontheight );
173 aStyleSettings.SetAppFont( aFont );
174 aFont = aStyleSettings.GetTitleFont();
175 aFont.SetFontHeight( defFontheight );
176 aStyleSettings.SetTitleFont( aFont );
177 aFont = aStyleSettings.GetFloatTitleFont();
178 aFont.SetFontHeight( defFontheight );
179 aStyleSettings.SetFloatTitleFont( aFont );
180 // keep menu and help font size from system unless in broken locale size
181 if( bBrokenLangFontHeight )
182 {
183 aFont = aStyleSettings.GetMenuFont();
184 if( aFont.GetFontHeight() < defFontheight )
185 {
186 aFont.SetFontHeight( defFontheight );
187 aStyleSettings.SetMenuFont( aFont );
188 }
189 aFont = aStyleSettings.GetHelpFont();
190 if( aFont.GetFontHeight() < defFontheight )
191 {
192 aFont.SetFontHeight( defFontheight );
193 aStyleSettings.SetHelpFont( aFont );
194 }
195 }
196
197 // use different height for toolfont
198 aFont = aStyleSettings.GetToolFont();
199 aFont.SetFontHeight( toolfontheight );
200 aStyleSettings.SetToolFont( aFont );
201
202 aFont = aStyleSettings.GetLabelFont();
203 aFont.SetFontHeight( defFontheight );
204 aStyleSettings.SetLabelFont( aFont );
205 aFont = aStyleSettings.GetRadioCheckFont();
206 aFont.SetFontHeight( defFontheight );
207 aStyleSettings.SetRadioCheckFont( aFont );
208 aFont = aStyleSettings.GetPushButtonFont();
209 aFont.SetFontHeight( defFontheight );
210 aStyleSettings.SetPushButtonFont( aFont );
211 aFont = aStyleSettings.GetFieldFont();
212 aFont.SetFontHeight( defFontheight );
213 aStyleSettings.SetFieldFont( aFont );
214 aFont = aStyleSettings.GetIconFont();
215 aFont.SetFontHeight( defFontheight );
216 aStyleSettings.SetIconFont( aFont );
217 aFont = aStyleSettings.GetTabFont();
218 aFont.SetFontHeight( defFontheight );
219 aStyleSettings.SetTabFont( aFont );
220 aFont = aStyleSettings.GetGroupFont();
221 aFont.SetFontHeight( defFontheight );
222 aStyleSettings.SetGroupFont( aFont );
223
224 static const char* pEnvHC = getenv( "SAL_FORCE_HC" );
225 const bool bForceHCMode = pEnvHC && *pEnvHC;
226 if (bForceHCMode)
227 aStyleSettings.SetHighContrastMode( true );
228 else
229 {
230 sal_Int32 nHighContrastMode = officecfg::Office::Common::Accessibility::HighContrast::get();
231 if (nHighContrastMode != 0) // 0 Automatic, 1 Disable, 2 Enable
232 {
233 const bool bEnable = nHighContrastMode == 2;
234 aStyleSettings.SetHighContrastMode(bEnable);
235 }
236 }
237
238 rSettings.SetStyleSettings( aStyleSettings );
239
240 if ( bCallHdl )
241 GetpApp()->OverrideSystemSettings( rSettings );
242}
243
244} /*namespace vcl*/
245
246/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static SAL_DLLPRIVATE AllSettingsFlags GetWindowUpdate()
Definition: settings.hxx:721
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:644
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:761
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
tools::Long GetFontHeight() const
Definition: font/font.cxx:908
void SetFontHeight(tools::Long nHeight)
Definition: font/font.cxx:907
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:1348
std::unique_ptr< WindowImpl > mpWindowImpl
Definition: window.hxx:484
SalFrame * ImplGetFrame() const
Definition: window2.cxx:874
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:671
Application * GetpApp()
Definition: svapp.cxx:152
WinBits const WB_3DLOOK
Definition: wintypes.hxx:118