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 
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 <unotools/configmgr.hxx>
29 #include <unotools/confignode.hxx>
30 
32 
33 #include <salframe.hxx>
34 #include <brdwin.hxx>
35 
36 #include <window.h>
37 
38 namespace vcl {
39 
40 void Window::SetSettings( const AllSettings& rSettings )
41 {
42  SetSettings( rSettings, false );
43 }
44 
45 void Window::SetSettings( const AllSettings& rSettings, bool bChild )
46 {
47 
48  if ( mpWindowImpl->mpBorderWindow )
49  {
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 );
54  }
55 
56  AllSettings aOldSettings(*mxSettings);
57  OutputDevice::SetSettings( rSettings );
58  AllSettingsFlags nChangeFlags = aOldSettings.GetChangeFlags( rSettings );
59 
60  // recalculate AppFont-resolution and DPI-resolution
62 
63  if ( bool(nChangeFlags) )
64  {
65  DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
66  DataChanged( aDCEvt );
67  }
68 
69  if ( bChild )
70  {
71  vcl::Window* pChild = mpWindowImpl->mpFirstChild;
72  while ( pChild )
73  {
74  pChild->SetSettings( rSettings, bChild );
75  pChild = pChild->mpWindowImpl->mpNext;
76  }
77  }
78 }
79 
80 void Window::UpdateSettings( const AllSettings& rSettings, bool bChild )
81 {
82 
83  if ( mpWindowImpl->mpBorderWindow )
84  {
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 );
89  }
90 
91  AllSettings aOldSettings(*mxSettings);
92  AllSettingsFlags nChangeFlags = mxSettings->Update( AllSettings::GetWindowUpdate(), rSettings );
93 
94  // recalculate AppFont-resolution and DPI-resolution
96 
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.
103  */
104  MouseSettings aSet( mxSettings->GetMouseSettings() );
105  aSet.SetWheelBehavior( aOldSettings.GetMouseSettings().GetWheelBehavior() );
106  mxSettings->SetMouseSettings( aSet );
107 
108  if( (nChangeFlags & AllSettingsFlags::STYLE) && IsBackground() )
109  {
110  Wallpaper aWallpaper = GetBackground();
111  if( !aWallpaper.IsBitmap() && !aWallpaper.IsGradient() )
112  {
113  if ( mpWindowImpl->mnStyle & WB_3DLOOK )
114  {
115  if (aOldSettings.GetStyleSettings().GetFaceColor() != rSettings.GetStyleSettings().GetFaceColor())
117  }
118  else
119  {
120  if (aOldSettings.GetStyleSettings().GetWindowColor() != rSettings.GetStyleSettings().GetWindowColor())
122  }
123  }
124  }
125 
126  if ( bool(nChangeFlags) )
127  {
128  DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
129  DataChanged( aDCEvt );
130  // notify data change handler
132  }
133 
134  if ( bChild )
135  {
136  vcl::Window* pChild = mpWindowImpl->mpFirstChild;
137  while ( pChild )
138  {
139  pChild->UpdateSettings( rSettings, bChild );
140  pChild = pChild->mpWindowImpl->mpNext;
141  }
142  }
143 }
144 
145 void Window::ImplUpdateGlobalSettings( AllSettings& rSettings, bool bCallHdl ) const
146 {
147  StyleSettings aTmpSt( rSettings.GetStyleSettings() );
148  aTmpSt.SetHighContrastMode( false );
149  rSettings.SetStyleSettings( aTmpSt );
150  ImplGetFrame()->UpdateSettings( rSettings );
151 
152  StyleSettings aStyleSettings = rSettings.GetStyleSettings();
153 
154  vcl::Font aFont = aStyleSettings.GetMenuFont();
155  int defFontheight = aFont.GetFontHeight();
156 
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);
163 
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;
168 
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 )
180  {
181  aFont = aStyleSettings.GetMenuFont();
182  if( aFont.GetFontHeight() < defFontheight )
183  {
184  aFont.SetFontHeight( defFontheight );
185  aStyleSettings.SetMenuFont( aFont );
186  }
187  aFont = aStyleSettings.GetHelpFont();
188  if( aFont.GetFontHeight() < defFontheight )
189  {
190  aFont.SetFontHeight( defFontheight );
191  aStyleSettings.SetHelpFont( aFont );
192  }
193  }
194 
195  // use different height for toolfont
196  aFont = aStyleSettings.GetToolFont();
197  aFont.SetFontHeight( toolfontheight );
198  aStyleSettings.SetToolFont( aFont );
199 
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 );
221 
222  rSettings.SetStyleSettings( aStyleSettings );
223 
224  bool bForceHCMode = false;
225 
226  // auto detect HC mode; if the system already set it to "yes"
227  // (see above) then accept that
229  {
230  bool bAutoHCMode = true;
233  "org.openoffice.Office.Common/Accessibility" ); // note: case sensitive !
234  if ( aNode.isValid() )
235  {
236  css::uno::Any aValue = aNode.getNodeValue( "AutoDetectSystemHC" );
237  bool bTmp = false;
238  if( aValue >>= bTmp )
239  bAutoHCMode = bTmp;
240  }
241  if( bAutoHCMode )
242  {
243  if( rSettings.GetStyleSettings().GetFaceColor().IsDark() ||
244  rSettings.GetStyleSettings().GetWindowColor().IsDark() )
245  bForceHCMode = true;
246  }
247  }
248 
249  static const char* pEnvHC = getenv( "SAL_FORCE_HC" );
250  if( pEnvHC && *pEnvHC )
251  bForceHCMode = true;
252 
253  if( bForceHCMode )
254  {
255  aStyleSettings = rSettings.GetStyleSettings();
256  aStyleSettings.SetHighContrastMode( true );
257  rSettings.SetStyleSettings( aStyleSettings );
258  }
259 
260  if ( bCallHdl )
261  GetpApp()->OverrideSystemSettings( rSettings );
262 }
263 
264 } /*namespace vcl*/
265 
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMenuFont(const vcl::Font &rFont)
void SetHelpFont(const vcl::Font &rFont)
const Wallpaper & GetBackground() const
Definition: outdev.hxx:631
long GetFontHeight() const
Definition: font/font.cxx:675
void SetFieldFont(const vcl::Font &rFont)
const vcl::Font & GetMenuFont() const
void SetStyleSettings(const StyleSettings &rSet)
bool IsBackground() const
Definition: outdev.hxx:634
SAL_DLLPRIVATE void ImplInitResolutionSettings()
Definition: window.cxx:1304
void SetIconFont(const vcl::Font &rFont)
void SetRadioCheckFont(const vcl::Font &rFont)
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:704
const Color & GetFaceColor() const
const vcl::Font & GetRadioCheckFont() const
void SetHighContrastMode(bool bHighContrast)
virtual void SetSettings(const AllSettings &rSettings)
Definition: outdev.cxx:213
virtual void SetSettings(const AllSettings &rSettings) override
const vcl::Font & GetFieldFont() const
AllSettingsFlags
Definition: settings.hxx:644
void SetBackground()
const vcl::Font & GetLabelFont() const
static bool IsFuzzing()
bool GetHighContrastMode() const
Application * GetpApp()
Definition: svapp.cxx:147
std::unique_ptr< AllSettings > mxSettings
Definition: outdev.hxx:370
static bool isCJK(LanguageType nLang)
MouseWheelBehaviour GetWheelBehavior() const
const vcl::Font & GetPushButtonFont() const
const vcl::Font & GetGroupFont() const
const vcl::Font & GetToolFont() const
bool IsDark() const
const vcl::Font & GetTabFont() const
const vcl::Font & GetHelpFont() const
std::unique_ptr< WindowImpl > mpWindowImpl
Definition: window.hxx:511
static OConfigurationTreeRoot tryCreateWithComponentContext(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const OUString &_rPath, sal_Int32 _nDepth=-1, CREATION_MODE _eMode=CM_UPDATABLE)
virtual void UpdateSettings(AllSettings &rSettings)=0
void SetAppFont(const vcl::Font &rFont)
void SetToolFont(const vcl::Font &rFont)
void SetFloatTitleFont(const vcl::Font &rFont)
WinBits const WB_3DLOOK
SalFrame * ImplGetFrame() const
Definition: window2.cxx:848
void SetGroupFont(const vcl::Font &rFont)
void SetPushButtonFont(const vcl::Font &rFont)
bool IsGradient() const
Definition: wall.cxx:283
void SetTitleFont(const vcl::Font &rFont)
const vcl::Font & GetTitleFont() const
void SetLabelFont(const vcl::Font &rFont)
const vcl::Font & GetIconFont() const
void SetWheelBehavior(MouseWheelBehaviour nBehavior)
void SetFontHeight(long nHeight)
Definition: font/font.cxx:674
css::uno::Any getNodeValue(const OUString &_rPath) const
Reference< XComponentContext > getProcessComponentContext()
const MouseSettings & GetMouseSettings() const
const vcl::Font & GetFloatTitleFont() const
const Color & GetWindowColor() const
virtual void OverrideSystemSettings(AllSettings &rSettings)
Sets user settings in settings object to override system settings.
Definition: svapp.cxx:587
SAL_DLLPRIVATE void ImplUpdateGlobalSettings(AllSettings &rSettings, bool bCallHdl=true) const
const vcl::Font & GetAppFont() const
bool IsBitmap() const
Definition: wall.cxx:255
void SetTabFont(const vcl::Font &rFont)
void CallEventListeners(VclEventId nEvent, void *pData=nullptr)
Definition: event.cxx:213
AllSettingsFlags GetChangeFlags(const AllSettings &rSettings) const
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
static AllSettingsFlags GetWindowUpdate()
Definition: settings.hxx:688
void UpdateSettings(const AllSettings &rSettings, bool bChild=false)