/src/libreoffice/vcl/source/window/settings.cxx
Line | Count | Source |
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 | | #include <i18nlangtag/languagetag.hxx> |
21 | | #include <i18nlangtag/mslangid.hxx> |
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 | | |
30 | | #include <unotools/configmgr.hxx> |
31 | | #include <unotools/confignode.hxx> |
32 | | |
33 | | #include <comphelper/processfactory.hxx> |
34 | | |
35 | | #include <salframe.hxx> |
36 | | #include <brdwin.hxx> |
37 | | |
38 | | #include <window.h> |
39 | | |
40 | | namespace vcl { |
41 | | |
42 | | void WindowOutputDevice::SetSettings( const AllSettings& rSettings ) |
43 | 39.8k | { |
44 | 39.8k | SetSettings( rSettings, false ); |
45 | 39.8k | } |
46 | | |
47 | | void WindowOutputDevice::SetSettings( const AllSettings& rSettings, bool bChild ) |
48 | 39.8k | { |
49 | | |
50 | 39.8k | if ( auto pBorderWindow = mxOwnerWindow->mpWindowImpl->mpBorderWindow.get() ) |
51 | 0 | { |
52 | 0 | static_cast<vcl::WindowOutputDevice*>(pBorderWindow->GetOutDev())->SetSettings( rSettings, false ); |
53 | 0 | if ( (pBorderWindow->GetType() == WindowType::BORDERWINDOW) && |
54 | 0 | static_cast<ImplBorderWindow*>(pBorderWindow)->mpMenuBarWindow ) |
55 | 0 | static_cast<vcl::WindowOutputDevice*>(static_cast<ImplBorderWindow*>(pBorderWindow)->mpMenuBarWindow->GetOutDev())->SetSettings( rSettings, true ); |
56 | 0 | } |
57 | | |
58 | 39.8k | AllSettings aOldSettings(*moSettings); |
59 | 39.8k | OutputDevice::SetSettings( rSettings ); |
60 | 39.8k | AllSettingsFlags nChangeFlags = aOldSettings.GetChangeFlags( rSettings ); |
61 | | |
62 | | // recalculate AppFont-resolution and DPI-resolution |
63 | 39.8k | mxOwnerWindow->ImplInitResolutionSettings(); |
64 | | |
65 | 39.8k | if ( bool(nChangeFlags) ) |
66 | 2 | { |
67 | 2 | DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags ); |
68 | 2 | mxOwnerWindow->DataChanged( aDCEvt ); |
69 | 2 | } |
70 | | |
71 | 39.8k | if ( bChild ) |
72 | 0 | { |
73 | 0 | vcl::Window* pChild = mxOwnerWindow->mpWindowImpl->mpFirstChild; |
74 | 0 | while ( pChild ) |
75 | 0 | { |
76 | 0 | static_cast<vcl::WindowOutputDevice*>(pChild->GetOutDev())->SetSettings( rSettings, bChild ); |
77 | 0 | pChild = pChild->mpWindowImpl->mpNext; |
78 | 0 | } |
79 | 0 | } |
80 | 39.8k | } |
81 | | |
82 | | void Window::UpdateSettings( const AllSettings& rSettings, bool bChild ) |
83 | 0 | { |
84 | |
|
85 | 0 | if ( mpWindowImpl->mpBorderWindow ) |
86 | 0 | { |
87 | 0 | mpWindowImpl->mpBorderWindow->UpdateSettings( rSettings ); |
88 | 0 | if (mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW) |
89 | 0 | { |
90 | 0 | ImplBorderWindow* pImpl = static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get()); |
91 | 0 | if (pImpl->mpMenuBarWindow) |
92 | 0 | pImpl->mpMenuBarWindow->UpdateSettings(rSettings, true); |
93 | 0 | if (pImpl->mpNotebookBar) |
94 | 0 | pImpl->mpNotebookBar->UpdateSettings(rSettings, true); |
95 | 0 | } |
96 | 0 | } |
97 | |
|
98 | 0 | AllSettings aOldSettings(*mpWindowImpl->mxOutDev->moSettings); |
99 | 0 | AllSettingsFlags nChangeFlags = mpWindowImpl->mxOutDev->moSettings->Update( AllSettings::GetWindowUpdate(), rSettings ); |
100 | | |
101 | | // recalculate AppFont-resolution and DPI-resolution |
102 | 0 | ImplInitResolutionSettings(); |
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 | 0 | MouseSettings aSet( mpWindowImpl->mxOutDev->moSettings->GetMouseSettings() ); |
112 | 0 | aSet.SetWheelBehavior( aOldSettings.GetMouseSettings().GetWheelBehavior() ); |
113 | 0 | mpWindowImpl->mxOutDev->moSettings->SetMouseSettings( aSet ); |
114 | |
|
115 | 0 | if( (nChangeFlags & AllSettingsFlags::STYLE) && IsBackground() ) |
116 | 0 | { |
117 | 0 | Wallpaper aWallpaper = GetBackground(); |
118 | 0 | if( !aWallpaper.IsBitmap() && !aWallpaper.IsGradient() ) |
119 | 0 | { |
120 | 0 | if ( mpWindowImpl->mnStyle & WB_3DLOOK ) |
121 | 0 | { |
122 | 0 | if (aOldSettings.GetStyleSettings().GetFaceColor() != rSettings.GetStyleSettings().GetFaceColor()) |
123 | 0 | SetBackground( Wallpaper( rSettings.GetStyleSettings().GetFaceColor() ) ); |
124 | 0 | } |
125 | 0 | else |
126 | 0 | { |
127 | 0 | if (aOldSettings.GetStyleSettings().GetWindowColor() != rSettings.GetStyleSettings().GetWindowColor()) |
128 | 0 | SetBackground( Wallpaper( rSettings.GetStyleSettings().GetWindowColor() ) ); |
129 | 0 | } |
130 | 0 | } |
131 | 0 | } |
132 | |
|
133 | 0 | if ( bool(nChangeFlags) ) |
134 | 0 | { |
135 | 0 | DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags ); |
136 | 0 | DataChanged( aDCEvt ); |
137 | | // notify data change handler |
138 | 0 | CallEventListeners( VclEventId::WindowDataChanged, &aDCEvt); |
139 | 0 | } |
140 | |
|
141 | 0 | if ( bChild ) |
142 | 0 | { |
143 | 0 | vcl::Window* pChild = mpWindowImpl->mpFirstChild; |
144 | 0 | while ( pChild ) |
145 | 0 | { |
146 | 0 | pChild->UpdateSettings( rSettings, bChild ); |
147 | 0 | pChild = pChild->mpWindowImpl->mpNext; |
148 | 0 | } |
149 | 0 | } |
150 | 0 | } |
151 | | |
152 | | void Window::ImplUpdateGlobalSettings( AllSettings& rSettings, bool bCallHdl ) const |
153 | 2 | { |
154 | 2 | StyleSettings aTmpSt( rSettings.GetStyleSettings() ); |
155 | 2 | aTmpSt.SetHighContrastMode( false ); |
156 | 2 | rSettings.SetStyleSettings( aTmpSt ); |
157 | 2 | ImplGetFrame()->UpdateSettings( rSettings ); |
158 | | |
159 | 2 | StyleSettings aStyleSettings = rSettings.GetStyleSettings(); |
160 | | |
161 | 2 | vcl::Font aFont = aStyleSettings.GetMenuFont(); |
162 | 2 | 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 | 2 | bool bBrokenLangFontHeight = MsLangId::isCJK(Application::GetSettings().GetUILanguageTag().getLanguageType()); |
168 | 2 | if (bBrokenLangFontHeight) |
169 | 0 | defFontheight = std::max(9, defFontheight); |
170 | | |
171 | | // i22098, toolfont will be scaled differently to avoid bloated rulers and status bars for big fonts |
172 | 2 | int toolfontheight = defFontheight; |
173 | 2 | if( toolfontheight > 9 ) |
174 | 0 | toolfontheight = (defFontheight+8) / 2; |
175 | | |
176 | 2 | aFont = aStyleSettings.GetAppFont(); |
177 | 2 | aFont.SetFontHeight( defFontheight ); |
178 | 2 | aStyleSettings.SetAppFont( aFont ); |
179 | 2 | aFont = aStyleSettings.GetTitleFont(); |
180 | 2 | aFont.SetFontHeight( defFontheight ); |
181 | 2 | aStyleSettings.SetTitleFont( aFont ); |
182 | 2 | aFont = aStyleSettings.GetFloatTitleFont(); |
183 | 2 | aFont.SetFontHeight( defFontheight ); |
184 | 2 | aStyleSettings.SetFloatTitleFont( aFont ); |
185 | | // keep menu and help font size from system unless in broken locale size |
186 | 2 | if( bBrokenLangFontHeight ) |
187 | 0 | { |
188 | 0 | aFont = aStyleSettings.GetMenuFont(); |
189 | 0 | if( aFont.GetFontHeight() < defFontheight ) |
190 | 0 | { |
191 | 0 | aFont.SetFontHeight( defFontheight ); |
192 | 0 | aStyleSettings.SetMenuFont( aFont ); |
193 | 0 | } |
194 | 0 | aFont = aStyleSettings.GetHelpFont(); |
195 | 0 | if( aFont.GetFontHeight() < defFontheight ) |
196 | 0 | { |
197 | 0 | aFont.SetFontHeight( defFontheight ); |
198 | 0 | aStyleSettings.SetHelpFont( aFont ); |
199 | 0 | } |
200 | 0 | } |
201 | | |
202 | | // use different height for toolfont |
203 | 2 | aFont = aStyleSettings.GetToolFont(); |
204 | 2 | aFont.SetFontHeight( toolfontheight ); |
205 | 2 | aStyleSettings.SetToolFont( aFont ); |
206 | | |
207 | 2 | aFont = aStyleSettings.GetLabelFont(); |
208 | 2 | aFont.SetFontHeight( defFontheight ); |
209 | 2 | aStyleSettings.SetLabelFont( aFont ); |
210 | 2 | aFont = aStyleSettings.GetRadioCheckFont(); |
211 | 2 | aFont.SetFontHeight( defFontheight ); |
212 | 2 | aStyleSettings.SetRadioCheckFont( aFont ); |
213 | 2 | aFont = aStyleSettings.GetPushButtonFont(); |
214 | 2 | aFont.SetFontHeight( defFontheight ); |
215 | 2 | aStyleSettings.SetPushButtonFont( aFont ); |
216 | 2 | aFont = aStyleSettings.GetFieldFont(); |
217 | 2 | aFont.SetFontHeight( defFontheight ); |
218 | 2 | aStyleSettings.SetFieldFont( aFont ); |
219 | 2 | aFont = aStyleSettings.GetIconFont(); |
220 | 2 | aFont.SetFontHeight( defFontheight ); |
221 | 2 | aStyleSettings.SetIconFont( aFont ); |
222 | 2 | aFont = aStyleSettings.GetTabFont(); |
223 | 2 | aFont.SetFontHeight( defFontheight ); |
224 | 2 | aStyleSettings.SetTabFont( aFont ); |
225 | 2 | aFont = aStyleSettings.GetGroupFont(); |
226 | 2 | aFont.SetFontHeight( defFontheight ); |
227 | 2 | aStyleSettings.SetGroupFont( aFont ); |
228 | | |
229 | 2 | static const bool bFuzzing = comphelper::IsFuzzing(); |
230 | 2 | if (!bFuzzing) |
231 | 0 | { |
232 | 0 | static const char* pEnvHC = getenv( "SAL_FORCE_HC" ); |
233 | 0 | const bool bForceHCMode = pEnvHC && *pEnvHC; |
234 | 0 | if (bForceHCMode) |
235 | 0 | aStyleSettings.SetHighContrastMode( true ); |
236 | 0 | else |
237 | 0 | { |
238 | 0 | sal_Int32 nHighContrastMode = officecfg::Office::Common::Accessibility::HighContrast::get(); |
239 | 0 | if (nHighContrastMode != 0) // 0 Automatic, 1 Disable, 2 Enable |
240 | 0 | { |
241 | 0 | const bool bEnable = nHighContrastMode == 2; |
242 | 0 | aStyleSettings.SetHighContrastMode(bEnable); |
243 | 0 | } |
244 | 0 | } |
245 | 0 | } |
246 | | |
247 | 2 | rSettings.SetStyleSettings( aStyleSettings ); |
248 | | |
249 | 2 | if ( bCallHdl ) |
250 | 2 | GetpApp()->OverrideSystemSettings( rSettings ); |
251 | 2 | } |
252 | | |
253 | | } /*namespace vcl*/ |
254 | | |
255 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |