LCOV - code coverage report
Current view: top level - vcl/source/window - settings.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 123 143 86.0 %
Date: 2015-06-13 12:38:46 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/mslangid.hxx>
      21             : 
      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>
      27             : 
      28             : #include <unotools/fontcfg.hxx>
      29             : #include <unotools/confignode.hxx>
      30             : 
      31             : #include <comphelper/processfactory.hxx>
      32             : 
      33             : #include <salframe.hxx>
      34             : #include <svdata.hxx>
      35             : #include <brdwin.hxx>
      36             : #include <PhysicalFontCollection.hxx>
      37             : 
      38             : #include <window.h>
      39             : 
      40             : namespace vcl {
      41             : 
      42       48937 : void Window::SetSettings( const AllSettings& rSettings )
      43             : {
      44       48937 :     SetSettings( rSettings, false );
      45       48937 : }
      46             : 
      47       51721 : void Window::SetSettings( const AllSettings& rSettings, bool bChild )
      48             : {
      49             : 
      50       51721 :     if ( mpWindowImpl->mpBorderWindow )
      51             :     {
      52         738 :         mpWindowImpl->mpBorderWindow->SetSettings( rSettings, false );
      53        1476 :         if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) &&
      54         738 :              static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow )
      55           0 :             static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->SetSettings( rSettings, true );
      56             :     }
      57             : 
      58       51721 :     AllSettings aOldSettings(*mxSettings);
      59       51721 :     OutputDevice::SetSettings( rSettings );
      60       51721 :     AllSettingsFlags nChangeFlags = aOldSettings.GetChangeFlags( rSettings );
      61             : 
      62             :     // recalculate AppFont-resolution and DPI-resolution
      63       51721 :     ImplInitResolutionSettings();
      64             : 
      65       51721 :     if ( bool(nChangeFlags) )
      66             :     {
      67        4593 :         DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
      68        4593 :         DataChanged( aDCEvt );
      69             :     }
      70             : 
      71       51721 :     if ( bChild || mpWindowImpl->mbChildNotify )
      72             :     {
      73        2046 :         vcl::Window* pChild = mpWindowImpl->mpFirstChild;
      74        5404 :         while ( pChild )
      75             :         {
      76        1312 :             pChild->SetSettings( rSettings, bChild );
      77        1312 :             pChild = pChild->mpWindowImpl->mpNext;
      78             :         }
      79       51721 :     }
      80       51721 : }
      81             : 
      82        2856 : void Window::UpdateSettings( const AllSettings& rSettings, bool bChild )
      83             : {
      84             : 
      85        2856 :     if ( mpWindowImpl->mpBorderWindow )
      86             :     {
      87         444 :         mpWindowImpl->mpBorderWindow->UpdateSettings( rSettings, false );
      88         888 :         if ( (mpWindowImpl->mpBorderWindow->GetType() == WINDOW_BORDERWINDOW) &&
      89         444 :              static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow )
      90           3 :             static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->mpMenuBarWindow->UpdateSettings( rSettings, true );
      91             :     }
      92             : 
      93        2856 :     AllSettings aOldSettings(*mxSettings);
      94        2856 :     AllSettingsFlags nChangeFlags = mxSettings->Update( mxSettings->GetWindowUpdate(), rSettings );
      95             : 
      96             :     // recalculate AppFont-resolution and DPI-resolution
      97        2856 :     ImplInitResolutionSettings();
      98             : 
      99             :     /* #i73785#
     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.
     105             :     */
     106        5712 :     MouseSettings aSet( mxSettings->GetMouseSettings() );
     107        2856 :     aSet.SetWheelBehavior( aOldSettings.GetMouseSettings().GetWheelBehavior() );
     108        2856 :     mxSettings->SetMouseSettings( aSet );
     109             : 
     110        2856 :     if( (nChangeFlags & AllSettingsFlags::STYLE) && IsBackground() )
     111             :     {
     112        1981 :         Wallpaper aWallpaper = GetBackground();
     113        1981 :         if( !aWallpaper.IsBitmap() && !aWallpaper.IsGradient() )
     114             :         {
     115        1981 :             if ( mpWindowImpl->mnStyle & WB_3DLOOK )
     116             :             {
     117        1611 :                 if (aOldSettings.GetStyleSettings().GetFaceColor() != rSettings.GetStyleSettings().GetFaceColor())
     118           0 :                     SetBackground( Wallpaper( rSettings.GetStyleSettings().GetFaceColor() ) );
     119             :             }
     120             :             else
     121             :             {
     122         370 :                 if (aOldSettings.GetStyleSettings().GetWindowColor() != rSettings.GetStyleSettings().GetWindowColor())
     123           0 :                     SetBackground( Wallpaper( rSettings.GetStyleSettings().GetWindowColor() ) );
     124             :             }
     125        1981 :         }
     126             :     }
     127             : 
     128        2856 :     if ( bool(nChangeFlags) )
     129             :     {
     130        2785 :         DataChangedEvent aDCEvt( DataChangedEventType::SETTINGS, &aOldSettings, nChangeFlags );
     131        2785 :         DataChanged( aDCEvt );
     132             :         // notify data change handler
     133        2785 :         CallEventListeners( VCLEVENT_WINDOW_DATACHANGED, &aDCEvt);
     134             :     }
     135             : 
     136        2856 :     if ( bChild || mpWindowImpl->mbChildNotify )
     137             :     {
     138        2406 :         vcl::Window* pChild = mpWindowImpl->mpFirstChild;
     139        6836 :         while ( pChild )
     140             :         {
     141        2024 :             pChild->UpdateSettings( rSettings, bChild );
     142        2024 :             pChild = pChild->mpWindowImpl->mpNext;
     143             :         }
     144        2856 :     }
     145        2856 : }
     146             : 
     147         675 : void Window::ImplUpdateGlobalSettings( AllSettings& rSettings, bool bCallHdl )
     148             : {
     149         675 :     StyleSettings aTmpSt( rSettings.GetStyleSettings() );
     150         675 :     aTmpSt.SetHighContrastMode( false );
     151         675 :     rSettings.SetStyleSettings( aTmpSt );
     152         675 :     ImplGetFrame()->UpdateSettings( rSettings );
     153             : 
     154        1350 :     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         675 :     int maxFontheight = 9; // #107886#: 9 is default for some asian systems, so always allow if requested
     160         675 :     if( GetDesktopRectPixel().getHeight() > 600 )
     161         675 :         maxFontheight = (int) ((( 8.0 * (double) GetDesktopRectPixel().getHeight()) / 600.0) + 1.5);
     162             : 
     163        1350 :     vcl::Font aFont = aStyleSettings.GetMenuFont();
     164         675 :     int defFontheight = aFont.GetHeight();
     165         675 :     if( defFontheight > maxFontheight )
     166           0 :         defFontheight = maxFontheight;
     167             : 
     168             :     // if the UI is korean, chinese or another locale
     169             :     // where the system font size is kown to be often too small to
     170             :     // generate readable fonts enforce a minimum font size of 9 points
     171         675 :     bool bBrokenLangFontHeight = MsLangId::isCJK(Application::GetSettings().GetUILanguageTag().getLanguageType());
     172         675 :     if (bBrokenLangFontHeight)
     173           0 :         defFontheight = std::max(9, defFontheight);
     174             : 
     175             :     // i22098, toolfont will be scaled differently to avoid bloated rulers and status bars for big fonts
     176         675 :     int toolfontheight = defFontheight;
     177         675 :     if( toolfontheight > 9 )
     178           9 :         toolfontheight = (defFontheight+8) / 2;
     179             : 
     180         675 :     aFont = aStyleSettings.GetAppFont();
     181         675 :     aFont.SetHeight( defFontheight );
     182         675 :     aStyleSettings.SetAppFont( aFont );
     183         675 :     aFont = aStyleSettings.GetTitleFont();
     184         675 :     aFont.SetHeight( defFontheight );
     185         675 :     aStyleSettings.SetTitleFont( aFont );
     186         675 :     aFont = aStyleSettings.GetFloatTitleFont();
     187         675 :     aFont.SetHeight( defFontheight );
     188         675 :     aStyleSettings.SetFloatTitleFont( aFont );
     189             :     // keep menu and help font size from system unless in broken locale size
     190         675 :     if( bBrokenLangFontHeight )
     191             :     {
     192           0 :         aFont = aStyleSettings.GetMenuFont();
     193           0 :         if( aFont.GetHeight() < defFontheight )
     194             :         {
     195           0 :             aFont.SetHeight( defFontheight );
     196           0 :             aStyleSettings.SetMenuFont( aFont );
     197             :         }
     198           0 :         aFont = aStyleSettings.GetHelpFont();
     199           0 :         if( aFont.GetHeight() < defFontheight )
     200             :         {
     201           0 :             aFont.SetHeight( defFontheight );
     202           0 :             aStyleSettings.SetHelpFont( aFont );
     203             :         }
     204             :     }
     205             : 
     206             :     // use different height for toolfont
     207         675 :     aFont = aStyleSettings.GetToolFont();
     208         675 :     aFont.SetHeight( toolfontheight );
     209         675 :     aStyleSettings.SetToolFont( aFont );
     210             : 
     211         675 :     aFont = aStyleSettings.GetLabelFont();
     212         675 :     aFont.SetHeight( defFontheight );
     213         675 :     aStyleSettings.SetLabelFont( aFont );
     214         675 :     aFont = aStyleSettings.GetInfoFont();
     215         675 :     aFont.SetHeight( defFontheight );
     216         675 :     aStyleSettings.SetInfoFont( aFont );
     217         675 :     aFont = aStyleSettings.GetRadioCheckFont();
     218         675 :     aFont.SetHeight( defFontheight );
     219         675 :     aStyleSettings.SetRadioCheckFont( aFont );
     220         675 :     aFont = aStyleSettings.GetPushButtonFont();
     221         675 :     aFont.SetHeight( defFontheight );
     222         675 :     aStyleSettings.SetPushButtonFont( aFont );
     223         675 :     aFont = aStyleSettings.GetFieldFont();
     224         675 :     aFont.SetHeight( defFontheight );
     225         675 :     aStyleSettings.SetFieldFont( aFont );
     226         675 :     aFont = aStyleSettings.GetIconFont();
     227         675 :     aFont.SetHeight( defFontheight );
     228         675 :     aStyleSettings.SetIconFont( aFont );
     229         675 :     aFont = aStyleSettings.GetTabFont();
     230         675 :     aFont.SetHeight( defFontheight );
     231         675 :     aStyleSettings.SetTabFont( aFont );
     232         675 :     aFont = aStyleSettings.GetGroupFont();
     233         675 :     aFont.SetHeight( defFontheight );
     234         675 :     aStyleSettings.SetGroupFont( aFont );
     235             : 
     236         675 :     rSettings.SetStyleSettings( aStyleSettings );
     237             : 
     238         675 :     bool bForceHCMode = false;
     239             : 
     240             :     // auto detect HC mode; if the system already set it to "yes"
     241             :     // (see above) then accept that
     242         675 :     if( !rSettings.GetStyleSettings().GetHighContrastMode() )
     243             :     {
     244         675 :         bool bTmp = false, bAutoHCMode = true;
     245             :         utl::OConfigurationNode aNode = utl::OConfigurationTreeRoot::tryCreateWithComponentContext(
     246             :             comphelper::getProcessComponentContext(),
     247         675 :             OUString("org.openoffice.Office.Common/Accessibility") );    // note: case sensitive !
     248         675 :         if ( aNode.isValid() )
     249             :         {
     250         675 :             ::com::sun::star::uno::Any aValue = aNode.getNodeValue( OUString("AutoDetectSystemHC") );
     251         675 :             if( aValue >>= bTmp )
     252         675 :                 bAutoHCMode = bTmp;
     253             :         }
     254         675 :         if( bAutoHCMode )
     255             :         {
     256           0 :             if( rSettings.GetStyleSettings().GetFaceColor().IsDark() ||
     257           0 :                 rSettings.GetStyleSettings().GetWindowColor().IsDark() )
     258           0 :                 bForceHCMode = true;
     259         675 :         }
     260             :     }
     261             : 
     262         675 :     static const char* pEnvHC = getenv( "SAL_FORCE_HC" );
     263         675 :     if( pEnvHC && *pEnvHC )
     264           0 :         bForceHCMode = true;
     265             : 
     266         675 :     if( bForceHCMode )
     267             :     {
     268           0 :         aStyleSettings = rSettings.GetStyleSettings();
     269           0 :         aStyleSettings.SetHighContrastMode( true );
     270           0 :         rSettings.SetStyleSettings( aStyleSettings );
     271             :     }
     272             : 
     273             : #if defined(DBG_UTIL)
     274             :     // If needed, set AppFont to bold, in order to check
     275             :     // if there is enough space available for texts on other systems
     276             :     if ( DbgIsBoldAppFont() )
     277             :     {
     278             :         aStyleSettings = rSettings.GetStyleSettings();
     279             :         aFont = aStyleSettings.GetAppFont();
     280             :         aFont.SetWeight( WEIGHT_BOLD );
     281             :         aStyleSettings.SetAppFont( aFont );
     282             :         aFont = aStyleSettings.GetGroupFont();
     283             :         aFont.SetWeight( WEIGHT_BOLD );
     284             :         aStyleSettings.SetGroupFont( aFont );
     285             :         aFont = aStyleSettings.GetLabelFont();
     286             :         aFont.SetWeight( WEIGHT_BOLD );
     287             :         aStyleSettings.SetLabelFont( aFont );
     288             :         aFont = aStyleSettings.GetRadioCheckFont();
     289             :         aFont.SetWeight( WEIGHT_BOLD );
     290             :         aStyleSettings.SetRadioCheckFont( aFont );
     291             :         aFont = aStyleSettings.GetPushButtonFont();
     292             :         aFont.SetWeight( WEIGHT_BOLD );
     293             :         aStyleSettings.SetPushButtonFont( aFont );
     294             :         aFont = aStyleSettings.GetFieldFont();
     295             :         aFont.SetWeight( WEIGHT_BOLD );
     296             :         aStyleSettings.SetFieldFont( aFont );
     297             :         aFont = aStyleSettings.GetIconFont();
     298             :         aFont.SetWeight( WEIGHT_BOLD );
     299             :         aStyleSettings.SetIconFont( aFont );
     300             :         aFont = aStyleSettings.GetTabFont();
     301             :         aFont.SetWeight( WEIGHT_BOLD );
     302             :         aStyleSettings.SetTabFont( aFont );
     303             :         rSettings.SetStyleSettings( aStyleSettings );
     304             :     }
     305             : #endif
     306             : 
     307         675 :     if ( bCallHdl )
     308         864 :         GetpApp()->OverrideSystemSettings( rSettings );
     309         675 : }
     310             : 
     311             : } /*namespace vcl*/
     312             : 
     313             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11