Coverage Report

Created: 2026-03-31 11:00

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