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/mslangid.hxx>
22 #include <vcl/event.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/window.hxx>
25 #include <vcl/virdev.hxx>
26 #include <vcl/settings.hxx>
28 #include <unotools/fontcfg.hxx>
29 #include <unotools/confignode.hxx>
31 #include <comphelper/processfactory.hxx>
33 #include <salframe.hxx>
36 #include <PhysicalFontCollection.hxx>
42 void Window::SetSettings( const AllSettings
& rSettings
)
44 SetSettings( rSettings
, false );
47 void Window::SetSettings( const AllSettings
& rSettings
, bool bChild
)
50 if ( mpWindowImpl
->mpBorderWindow
)
52 mpWindowImpl
->mpBorderWindow
->SetSettings( rSettings
, false );
53 if ( (mpWindowImpl
->mpBorderWindow
->GetType() == WINDOW_BORDERWINDOW
) &&
54 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->mpMenuBarWindow
)
55 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->mpMenuBarWindow
->SetSettings( rSettings
, true );
58 AllSettings
aOldSettings(*mxSettings
);
59 OutputDevice::SetSettings( rSettings
);
60 AllSettingsFlags nChangeFlags
= aOldSettings
.GetChangeFlags( rSettings
);
62 // recalculate AppFont-resolution and DPI-resolution
63 ImplInitResolutionSettings();
65 if ( bool(nChangeFlags
) )
67 DataChangedEvent
aDCEvt( DataChangedEventType::SETTINGS
, &aOldSettings
, nChangeFlags
);
68 DataChanged( aDCEvt
);
73 vcl::Window
* pChild
= mpWindowImpl
->mpFirstChild
;
76 pChild
->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() == WINDOW_BORDERWINDOW
) &&
89 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->mpMenuBarWindow
)
90 static_cast<ImplBorderWindow
*>(mpWindowImpl
->mpBorderWindow
.get())->mpMenuBarWindow
->UpdateSettings( rSettings
, true );
93 AllSettings
aOldSettings(*mxSettings
);
94 AllSettingsFlags nChangeFlags
= mxSettings
->Update( mxSettings
->GetWindowUpdate(), rSettings
);
96 // recalculate AppFont-resolution and DPI-resolution
97 ImplInitResolutionSettings();
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.
106 MouseSettings
aSet( mxSettings
->GetMouseSettings() );
107 aSet
.SetWheelBehavior( aOldSettings
.GetMouseSettings().GetWheelBehavior() );
108 mxSettings
->SetMouseSettings( aSet
);
110 if( (nChangeFlags
& AllSettingsFlags::STYLE
) && IsBackground() )
112 Wallpaper aWallpaper
= GetBackground();
113 if( !aWallpaper
.IsBitmap() && !aWallpaper
.IsGradient() )
115 if ( mpWindowImpl
->mnStyle
& WB_3DLOOK
)
117 if (aOldSettings
.GetStyleSettings().GetFaceColor() != rSettings
.GetStyleSettings().GetFaceColor())
118 SetBackground( Wallpaper( rSettings
.GetStyleSettings().GetFaceColor() ) );
122 if (aOldSettings
.GetStyleSettings().GetWindowColor() != rSettings
.GetStyleSettings().GetWindowColor())
123 SetBackground( Wallpaper( rSettings
.GetStyleSettings().GetWindowColor() ) );
128 if ( bool(nChangeFlags
) )
130 DataChangedEvent
aDCEvt( DataChangedEventType::SETTINGS
, &aOldSettings
, nChangeFlags
);
131 DataChanged( aDCEvt
);
132 // notify data change handler
133 CallEventListeners( VCLEVENT_WINDOW_DATACHANGED
, &aDCEvt
);
138 vcl::Window
* pChild
= mpWindowImpl
->mpFirstChild
;
141 pChild
->UpdateSettings( rSettings
, bChild
);
142 pChild
= pChild
->mpWindowImpl
->mpNext
;
147 void Window::ImplUpdateGlobalSettings( AllSettings
& rSettings
, bool bCallHdl
)
149 StyleSettings
aTmpSt( rSettings
.GetStyleSettings() );
150 aTmpSt
.SetHighContrastMode( false );
151 rSettings
.SetStyleSettings( aTmpSt
);
152 ImplGetFrame()->UpdateSettings( rSettings
);
154 StyleSettings aStyleSettings
= rSettings
.GetStyleSettings();
155 // #97047: Force all fonts except Menu and Help to a fixed height
156 // to avoid UI scaling due to large fonts
157 // - but allow bigger fonts on bigger screens (i16682, i21238)
158 // dialogs were designed to fit 800x600 with an 8pt font, so scale accordingly
159 int maxFontheight
= 9; // #107886#: 9 is default for some asian systems, so always allow if requested
160 if( GetDesktopRectPixel().getHeight() > 600 )
161 maxFontheight
= (int) ((( 8.0 * (double) GetDesktopRectPixel().getHeight()) / 600.0) + 1.5);
163 vcl::Font aFont
= aStyleSettings
.GetMenuFont();
164 int defFontheight
= aFont
.GetFontHeight();
165 if( defFontheight
> maxFontheight
)
166 defFontheight
= maxFontheight
;
168 // if the UI is korean, chinese or another locale
169 // where the system font size is known to be often too small to
170 // generate readable fonts enforce a minimum font size of 9 points
171 bool bBrokenLangFontHeight
= MsLangId::isCJK(Application::GetSettings().GetUILanguageTag().getLanguageType());
172 if (bBrokenLangFontHeight
)
173 defFontheight
= std::max(9, defFontheight
);
175 // i22098, toolfont will be scaled differently to avoid bloated rulers and status bars for big fonts
176 int toolfontheight
= defFontheight
;
177 if( toolfontheight
> 9 )
178 toolfontheight
= (defFontheight
+8) / 2;
180 aFont
= aStyleSettings
.GetAppFont();
181 aFont
.SetFontHeight( defFontheight
);
182 aStyleSettings
.SetAppFont( aFont
);
183 aFont
= aStyleSettings
.GetTitleFont();
184 aFont
.SetFontHeight( defFontheight
);
185 aStyleSettings
.SetTitleFont( aFont
);
186 aFont
= aStyleSettings
.GetFloatTitleFont();
187 aFont
.SetFontHeight( defFontheight
);
188 aStyleSettings
.SetFloatTitleFont( aFont
);
189 // keep menu and help font size from system unless in broken locale size
190 if( bBrokenLangFontHeight
)
192 aFont
= aStyleSettings
.GetMenuFont();
193 if( aFont
.GetFontHeight() < defFontheight
)
195 aFont
.SetFontHeight( defFontheight
);
196 aStyleSettings
.SetMenuFont( aFont
);
198 aFont
= aStyleSettings
.GetHelpFont();
199 if( aFont
.GetFontHeight() < defFontheight
)
201 aFont
.SetFontHeight( defFontheight
);
202 aStyleSettings
.SetHelpFont( aFont
);
206 // use different height for toolfont
207 aFont
= aStyleSettings
.GetToolFont();
208 aFont
.SetFontHeight( toolfontheight
);
209 aStyleSettings
.SetToolFont( aFont
);
211 aFont
= aStyleSettings
.GetLabelFont();
212 aFont
.SetFontHeight( defFontheight
);
213 aStyleSettings
.SetLabelFont( aFont
);
214 aFont
= aStyleSettings
.GetRadioCheckFont();
215 aFont
.SetFontHeight( defFontheight
);
216 aStyleSettings
.SetRadioCheckFont( aFont
);
217 aFont
= aStyleSettings
.GetPushButtonFont();
218 aFont
.SetFontHeight( defFontheight
);
219 aStyleSettings
.SetPushButtonFont( aFont
);
220 aFont
= aStyleSettings
.GetFieldFont();
221 aFont
.SetFontHeight( defFontheight
);
222 aStyleSettings
.SetFieldFont( aFont
);
223 aFont
= aStyleSettings
.GetIconFont();
224 aFont
.SetFontHeight( defFontheight
);
225 aStyleSettings
.SetIconFont( aFont
);
226 aFont
= aStyleSettings
.GetTabFont();
227 aFont
.SetFontHeight( defFontheight
);
228 aStyleSettings
.SetTabFont( aFont
);
229 aFont
= aStyleSettings
.GetGroupFont();
230 aFont
.SetFontHeight( defFontheight
);
231 aStyleSettings
.SetGroupFont( aFont
);
233 rSettings
.SetStyleSettings( aStyleSettings
);
235 bool bForceHCMode
= false;
237 // auto detect HC mode; if the system already set it to "yes"
238 // (see above) then accept that
239 if( !rSettings
.GetStyleSettings().GetHighContrastMode() )
241 bool bAutoHCMode
= true;
242 utl::OConfigurationNode aNode
= utl::OConfigurationTreeRoot::tryCreateWithComponentContext(
243 comphelper::getProcessComponentContext(),
244 "org.openoffice.Office.Common/Accessibility" ); // note: case sensitive !
245 if ( aNode
.isValid() )
247 css::uno::Any aValue
= aNode
.getNodeValue( OUString("AutoDetectSystemHC") );
249 if( aValue
>>= bTmp
)
254 if( rSettings
.GetStyleSettings().GetFaceColor().IsDark() ||
255 rSettings
.GetStyleSettings().GetWindowColor().IsDark() )
260 static const char* pEnvHC
= getenv( "SAL_FORCE_HC" );
261 if( pEnvHC
&& *pEnvHC
)
266 aStyleSettings
= rSettings
.GetStyleSettings();
267 aStyleSettings
.SetHighContrastMode( true );
268 rSettings
.SetStyleSettings( aStyleSettings
);
272 GetpApp()->OverrideSystemSettings( rSettings
);
277 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */