1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <officecfg/Office/Common.hxx>
30 #include <unotools/configmgr.hxx>
31 #include <unotools/confignode.hxx>
33 #include <comphelper/processfactory.hxx>
35 #include <salframe.hxx>
42 void WindowOutputDevice::SetSettings( const AllSettings
& rSettings
)
44 SetSettings( rSettings
, false );
47 void WindowOutputDevice::SetSettings( const AllSettings
& rSettings
, bool bChild
)
50 if ( auto pBorderWindow
= mxOwnerWindow
->mpWindowImpl
->mpBorderWindow
.get() )
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 );
58 AllSettings
aOldSettings(*moSettings
);
59 OutputDevice::SetSettings( rSettings
);
60 AllSettingsFlags nChangeFlags
= aOldSettings
.GetChangeFlags( rSettings
);
62 // recalculate AppFont-resolution and DPI-resolution
63 mxOwnerWindow
->ImplInitResolutionSettings();
65 if ( bool(nChangeFlags
) )
67 DataChangedEvent
aDCEvt( DataChangedEventType::SETTINGS
, &aOldSettings
, nChangeFlags
);
68 mxOwnerWindow
->DataChanged( aDCEvt
);
73 vcl::Window
* pChild
= mxOwnerWindow
->mpWindowImpl
->mpFirstChild
;
76 static_cast<vcl::WindowOutputDevice
*>(pChild
->GetOutDev())->SetSettings( rSettings
, bChild
);
77 pChild
= pChild
->mpWindowImpl
->mpNext
;
82 void Window::UpdateSettings( const AllSettings
& rSettings
, bool bChild
)
85 if ( mpWindowImpl
->mpBorderWindow
)
87 mpWindowImpl
->mpBorderWindow
->UpdateSettings( rSettings
);
88 if (mpWindowImpl
->mpBorderWindow
->GetType() == WindowType::BORDERWINDOW
)
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);
98 AllSettings
aOldSettings(*mpWindowImpl
->mxOutDev
->moSettings
);
99 AllSettingsFlags nChangeFlags
= mpWindowImpl
->mxOutDev
->moSettings
->Update( AllSettings::GetWindowUpdate(), rSettings
);
101 // recalculate AppFont-resolution and DPI-resolution
102 ImplInitResolutionSettings();
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.
111 MouseSettings
aSet( mpWindowImpl
->mxOutDev
->moSettings
->GetMouseSettings() );
112 aSet
.SetWheelBehavior( aOldSettings
.GetMouseSettings().GetWheelBehavior() );
113 mpWindowImpl
->mxOutDev
->moSettings
->SetMouseSettings( aSet
);
115 if( (nChangeFlags
& AllSettingsFlags::STYLE
) && IsBackground() )
117 Wallpaper aWallpaper
= GetBackground();
118 if( !aWallpaper
.IsBitmap() && !aWallpaper
.IsGradient() )
120 if ( mpWindowImpl
->mnStyle
& WB_3DLOOK
)
122 if (aOldSettings
.GetStyleSettings().GetFaceColor() != rSettings
.GetStyleSettings().GetFaceColor())
123 SetBackground( Wallpaper( rSettings
.GetStyleSettings().GetFaceColor() ) );
127 if (aOldSettings
.GetStyleSettings().GetWindowColor() != rSettings
.GetStyleSettings().GetWindowColor())
128 SetBackground( Wallpaper( rSettings
.GetStyleSettings().GetWindowColor() ) );
133 if ( bool(nChangeFlags
) )
135 DataChangedEvent
aDCEvt( DataChangedEventType::SETTINGS
, &aOldSettings
, nChangeFlags
);
136 DataChanged( aDCEvt
);
137 // notify data change handler
138 CallEventListeners( VclEventId::WindowDataChanged
, &aDCEvt
);
143 vcl::Window
* pChild
= mpWindowImpl
->mpFirstChild
;
146 pChild
->UpdateSettings( rSettings
, bChild
);
147 pChild
= pChild
->mpWindowImpl
->mpNext
;
152 void Window::ImplUpdateGlobalSettings( AllSettings
& rSettings
, bool bCallHdl
) const
154 StyleSettings
aTmpSt( rSettings
.GetStyleSettings() );
155 aTmpSt
.SetHighContrastMode( false );
156 rSettings
.SetStyleSettings( aTmpSt
);
157 ImplGetFrame()->UpdateSettings( rSettings
);
159 StyleSettings aStyleSettings
= rSettings
.GetStyleSettings();
161 vcl::Font aFont
= aStyleSettings
.GetMenuFont();
162 int defFontheight
= aFont
.GetFontHeight();
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
);
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;
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
)
188 aFont
= aStyleSettings
.GetMenuFont();
189 if( aFont
.GetFontHeight() < defFontheight
)
191 aFont
.SetFontHeight( defFontheight
);
192 aStyleSettings
.SetMenuFont( aFont
);
194 aFont
= aStyleSettings
.GetHelpFont();
195 if( aFont
.GetFontHeight() < defFontheight
)
197 aFont
.SetFontHeight( defFontheight
);
198 aStyleSettings
.SetHelpFont( aFont
);
202 // use different height for toolfont
203 aFont
= aStyleSettings
.GetToolFont();
204 aFont
.SetFontHeight( toolfontheight
);
205 aStyleSettings
.SetToolFont( aFont
);
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
);
229 static const bool bFuzzing
= comphelper::IsFuzzing();
232 static const char* pEnvHC
= getenv( "SAL_FORCE_HC" );
233 const bool bForceHCMode
= pEnvHC
&& *pEnvHC
;
235 aStyleSettings
.SetHighContrastMode( true );
238 sal_Int32 nHighContrastMode
= officecfg::Office::Common::Accessibility::HighContrast::get();
239 if (nHighContrastMode
!= 0) // 0 Automatic, 1 Disable, 2 Enable
241 const bool bEnable
= nHighContrastMode
== 2;
242 aStyleSettings
.SetHighContrastMode(bEnable
);
247 rSettings
.SetStyleSettings( aStyleSettings
);
250 GetpApp()->OverrideSystemSettings( rSettings
);
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */