bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / window / settings.cxx
blobd7fee9b1b755aff26833e3f5560f89f33ec6d1ab
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <i18nlangtag/languagetag.hxx>
21 #include <i18nlangtag/mslangid.hxx>
23 #include <vcl/event.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/window.hxx>
26 #include <vcl/settings.hxx>
28 #include <unotools/configmgr.hxx>
29 #include <unotools/confignode.hxx>
31 #include <comphelper/processfactory.hxx>
33 #include <salframe.hxx>
34 #include <brdwin.hxx>
36 #include <window.h>
38 namespace vcl {
40 void Window::SetSettings( const AllSettings& rSettings )
42 SetSettings( rSettings, false );
45 void Window::SetSettings( const AllSettings& rSettings, bool bChild )
48 if ( mpWindowImpl->mpBorderWindow )
50 mpWindowImpl->mpBorderWindow->SetSettings( rSettings, false );
51 if ( (mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW) &&
52 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow )
53 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->SetSettings( rSettings, true );
56 AllSettings aOldSettings(*mxSettings);
57 OutputDevice::SetSettings( rSettings );
58 AllSettingsFlags nChangeFlags = aOldSettings.GetChangeFlags( rSettings );
60 // recalculate AppFont-resolution and DPI-resolution
61 ImplInitResolutionSettings();
63 if ( bool(nChangeFlags) )
65 DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
66 DataChanged( aDCEvt );
69 if ( bChild )
71 vcl::Window* pChild = mpWindowImpl->mpFirstChild;
72 while ( pChild )
74 pChild->SetSettings( rSettings, bChild );
75 pChild = pChild->mpWindowImpl->mpNext;
80 void Window::UpdateSettings( const AllSettings& rSettings, bool bChild )
83 if ( mpWindowImpl->mpBorderWindow )
85 mpWindowImpl->mpBorderWindow->UpdateSettings( rSettings );
86 if ( (mpWindowImpl->mpBorderWindow->GetType() == WindowType::BORDERWINDOW) &&
87 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow )
88 static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->UpdateSettings( rSettings, true );
91 AllSettings aOldSettings(*mxSettings);
92 AllSettingsFlags nChangeFlags = mxSettings->Update( AllSettings::GetWindowUpdate(), rSettings );
94 // recalculate AppFont-resolution and DPI-resolution
95 ImplInitResolutionSettings();
97 /* #i73785#
98 * do not overwrite a WheelBehavior with false
99 * this looks kind of a hack, but WheelBehavior
100 * is always a local change, not a system property,
101 * so we can spare all our users the hassle of reacting on
102 * this in their respective DataChanged.
104 MouseSettings aSet( mxSettings->GetMouseSettings() );
105 aSet.SetWheelBehavior( aOldSettings.GetMouseSettings().GetWheelBehavior() );
106 mxSettings->SetMouseSettings( aSet );
108 if( (nChangeFlags & AllSettingsFlags::STYLE) && IsBackground() )
110 Wallpaper aWallpaper = GetBackground();
111 if( !aWallpaper.IsBitmap() && !aWallpaper.IsGradient() )
113 if ( mpWindowImpl->mnStyle & WB_3DLOOK )
115 if (aOldSettings.GetStyleSettings().GetFaceColor() != rSettings.GetStyleSettings().GetFaceColor())
116 SetBackground( Wallpaper( rSettings.GetStyleSettings().GetFaceColor() ) );
118 else
120 if (aOldSettings.GetStyleSettings().GetWindowColor() != rSettings.GetStyleSettings().GetWindowColor())
121 SetBackground( Wallpaper( rSettings.GetStyleSettings().GetWindowColor() ) );
126 if ( bool(nChangeFlags) )
128 DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
129 DataChanged( aDCEvt );
130 // notify data change handler
131 CallEventListeners( VclEventId::WindowDataChanged, &aDCEvt);
134 if ( bChild )
136 vcl::Window* pChild = mpWindowImpl->mpFirstChild;
137 while ( pChild )
139 pChild->UpdateSettings( rSettings, bChild );
140 pChild = pChild->mpWindowImpl->mpNext;
145 void Window::ImplUpdateGlobalSettings( AllSettings& rSettings, bool bCallHdl ) const
147 StyleSettings aTmpSt( rSettings.GetStyleSettings() );
148 aTmpSt.SetHighContrastMode( false );
149 rSettings.SetStyleSettings( aTmpSt );
150 ImplGetFrame()->UpdateSettings( rSettings );
152 StyleSettings aStyleSettings = rSettings.GetStyleSettings();
154 vcl::Font aFont = aStyleSettings.GetMenuFont();
155 int defFontheight = aFont.GetFontHeight();
157 // if the UI is korean, chinese or another locale
158 // where the system font size is known to be often too small to
159 // generate readable fonts enforce a minimum font size of 9 points
160 bool bBrokenLangFontHeight = MsLangId::isCJK(Application::GetSettings().GetUILanguageTag().getLanguageType());
161 if (bBrokenLangFontHeight)
162 defFontheight = std::max(9, defFontheight);
164 // i22098, toolfont will be scaled differently to avoid bloated rulers and status bars for big fonts
165 int toolfontheight = defFontheight;
166 if( toolfontheight > 9 )
167 toolfontheight = (defFontheight+8) / 2;
169 aFont = aStyleSettings.GetAppFont();
170 aFont.SetFontHeight( defFontheight );
171 aStyleSettings.SetAppFont( aFont );
172 aFont = aStyleSettings.GetTitleFont();
173 aFont.SetFontHeight( defFontheight );
174 aStyleSettings.SetTitleFont( aFont );
175 aFont = aStyleSettings.GetFloatTitleFont();
176 aFont.SetFontHeight( defFontheight );
177 aStyleSettings.SetFloatTitleFont( aFont );
178 // keep menu and help font size from system unless in broken locale size
179 if( bBrokenLangFontHeight )
181 aFont = aStyleSettings.GetMenuFont();
182 if( aFont.GetFontHeight() < defFontheight )
184 aFont.SetFontHeight( defFontheight );
185 aStyleSettings.SetMenuFont( aFont );
187 aFont = aStyleSettings.GetHelpFont();
188 if( aFont.GetFontHeight() < defFontheight )
190 aFont.SetFontHeight( defFontheight );
191 aStyleSettings.SetHelpFont( aFont );
195 // use different height for toolfont
196 aFont = aStyleSettings.GetToolFont();
197 aFont.SetFontHeight( toolfontheight );
198 aStyleSettings.SetToolFont( aFont );
200 aFont = aStyleSettings.GetLabelFont();
201 aFont.SetFontHeight( defFontheight );
202 aStyleSettings.SetLabelFont( aFont );
203 aFont = aStyleSettings.GetRadioCheckFont();
204 aFont.SetFontHeight( defFontheight );
205 aStyleSettings.SetRadioCheckFont( aFont );
206 aFont = aStyleSettings.GetPushButtonFont();
207 aFont.SetFontHeight( defFontheight );
208 aStyleSettings.SetPushButtonFont( aFont );
209 aFont = aStyleSettings.GetFieldFont();
210 aFont.SetFontHeight( defFontheight );
211 aStyleSettings.SetFieldFont( aFont );
212 aFont = aStyleSettings.GetIconFont();
213 aFont.SetFontHeight( defFontheight );
214 aStyleSettings.SetIconFont( aFont );
215 aFont = aStyleSettings.GetTabFont();
216 aFont.SetFontHeight( defFontheight );
217 aStyleSettings.SetTabFont( aFont );
218 aFont = aStyleSettings.GetGroupFont();
219 aFont.SetFontHeight( defFontheight );
220 aStyleSettings.SetGroupFont( aFont );
222 rSettings.SetStyleSettings( aStyleSettings );
224 bool bForceHCMode = false;
226 // auto detect HC mode; if the system already set it to "yes"
227 // (see above) then accept that
228 if (!rSettings.GetStyleSettings().GetHighContrastMode() && !utl::ConfigManager::IsFuzzing())
230 bool bAutoHCMode = true;
231 utl::OConfigurationNode aNode = utl::OConfigurationTreeRoot::tryCreateWithComponentContext(
232 comphelper::getProcessComponentContext(),
233 "org.openoffice.Office.Common/Accessibility" ); // note: case sensitive !
234 if ( aNode.isValid() )
236 css::uno::Any aValue = aNode.getNodeValue( "AutoDetectSystemHC" );
237 bool bTmp = false;
238 if( aValue >>= bTmp )
239 bAutoHCMode = bTmp;
241 if( bAutoHCMode )
243 if( rSettings.GetStyleSettings().GetFaceColor().IsDark() ||
244 rSettings.GetStyleSettings().GetWindowColor().IsDark() )
245 bForceHCMode = true;
249 static const char* pEnvHC = getenv( "SAL_FORCE_HC" );
250 if( pEnvHC && *pEnvHC )
251 bForceHCMode = true;
253 if( bForceHCMode )
255 aStyleSettings = rSettings.GetStyleSettings();
256 aStyleSettings.SetHighContrastMode( true );
257 rSettings.SetStyleSettings( aStyleSettings );
260 if ( bCallHdl )
261 GetpApp()->OverrideSystemSettings( rSettings );
264 } /*namespace vcl*/
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */