LCOV - code coverage report
Current view: top level - svtools/source/config - apearcfg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 57 92 62.0 %
Date: 2015-06-13 12:38:46 Functions: 4 10 40.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             : 
      21             : #include <svtools/apearcfg.hxx>
      22             : #include <com/sun/star/uno/Any.hxx>
      23             : 
      24             : #include <tools/debug.hxx>
      25             : #include <vcl/settings.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : #include <sal/macros.h>
      28             : 
      29             : #define DEFAULT_DRAGMODE    2
      30             : #define DEFAULT_SNAPMODE    0
      31             : #define DEFAULT_SCALEFACTOR 100
      32             : #if defined UNX
      33             : #define DEFAULT_AAMINHEIGHT 8
      34             : #endif
      35             : 
      36             : using namespace ::com::sun::star::uno;
      37             : 
      38             : bool SvtTabAppearanceCfg::bInitialized = false;
      39             : 
      40         232 : SvtTabAppearanceCfg::SvtTabAppearanceCfg()
      41             :     :ConfigItem(OUString("Office.Common/View"))
      42             :     ,nDragMode          ( DEFAULT_DRAGMODE )
      43             :     ,nScaleFactor       ( DEFAULT_SCALEFACTOR )
      44             :     ,nSnapMode          ( DEFAULT_SNAPMODE )
      45             :     ,nMiddleMouse       ( MouseMiddleButtonAction::AutoScroll )
      46             : #if defined( UNX )
      47             :     ,nAAMinPixelHeight  ( DEFAULT_AAMINHEIGHT )
      48             : #endif
      49             :     ,bMenuMouseFollow   ( false )
      50             : #if defined( UNX )
      51         232 :     ,bFontAntialiasing  ( true )
      52             : #endif
      53             : {
      54         232 :     const Sequence<OUString>& rNames = GetPropertyNames();
      55         232 :     Sequence<Any> aValues = GetProperties(rNames);
      56         232 :     const Any* pValues = aValues.getConstArray();
      57             :     DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
      58             : 
      59         232 :     if(aValues.getLength() == rNames.getLength())
      60             :     {
      61        1856 :         for(int nProp = 0; nProp < rNames.getLength(); ++nProp, ++pValues)
      62             :         {
      63        1624 :             if(pValues->hasValue())
      64             :             {
      65        1624 :                 switch(nProp)
      66             :                 {
      67         232 :                     case  0: *pValues >>= nScaleFactor; break; //"FontScaling",
      68         232 :                     case  1: *pValues >>= nDragMode; break;   //"Window/Drag",
      69         232 :                     case  2: bMenuMouseFollow = *static_cast<sal_Bool const *>(pValues->getValue()); break; //"Menu/FollowMouse",
      70         232 :                     case  3: *pValues >>= nSnapMode; break; //"Dialog/MousePositioning",
      71         232 :                     case  4: { short nTmp = 0; *pValues >>= nTmp; nMiddleMouse = static_cast<MouseMiddleButtonAction>(nTmp); break; } //"Dialog/MiddleMouseButton",
      72             : #if defined( UNX )
      73         232 :                     case  5: bFontAntialiasing = *static_cast<sal_Bool const *>(pValues->getValue()); break;    // "FontAntialising/Enabled",
      74         232 :                     case  6: *pValues >>= nAAMinPixelHeight; break;                         // "FontAntialising/MinPixelHeight",
      75             : #endif
      76             :                 }
      77             :             }
      78             :         }
      79         232 :     }
      80         232 : }
      81             : 
      82         232 : SvtTabAppearanceCfg::~SvtTabAppearanceCfg( )
      83             : {
      84         232 : }
      85             : 
      86         232 : const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames()
      87             : {
      88         232 :     static Sequence<OUString> aNames;
      89         232 :     if(!aNames.getLength())
      90             :     {
      91             :         static const sal_Char* aPropNames[] =
      92             :         {
      93             :              "FontScaling"                       //  0
      94             :             ,"Window/Drag"                       //  1
      95             :             ,"Menu/FollowMouse"                  //  2
      96             :             ,"Dialog/MousePositioning"           //  3
      97             :             ,"Dialog/MiddleMouseButton"          //  4
      98             : #if defined( UNX )
      99             :             ,"FontAntiAliasing/Enabled"         //  5
     100             :             ,"FontAntiAliasing/MinPixelHeight"  //  6
     101             : #endif
     102             :         };
     103         116 :         const int nCount = SAL_N_ELEMENTS( aPropNames );
     104         116 :         aNames.realloc(nCount);
     105             : 
     106         116 :         const sal_Char** pAsciiNames = aPropNames;
     107         116 :         OUString* pNames = aNames.getArray();
     108         928 :         for(int i = 0; i < nCount; ++i, ++pNames, ++pAsciiNames)
     109         812 :             *pNames = OUString::createFromAscii( *pAsciiNames );
     110             :     }
     111         232 :     return aNames;
     112             : }
     113             : 
     114           0 : void  SvtTabAppearanceCfg::ImplCommit()
     115             : {
     116           0 :     const Sequence<OUString>& rNames = GetPropertyNames();
     117           0 :     Sequence<Any> aValues(rNames.getLength());
     118           0 :     Any* pValues = aValues.getArray();
     119             : 
     120           0 :     const Type& rType = cppu::UnoType<bool>::get();
     121           0 :     for(int nProp = 0; nProp < rNames.getLength(); nProp++)
     122             :     {
     123           0 :         switch(nProp)
     124             :         {
     125           0 :             case  0: pValues[nProp] <<= nScaleFactor; break;            // "FontScaling",
     126           0 :             case  1: pValues[nProp] <<= nDragMode; break;               //"Window/Drag",
     127           0 :             case  2: pValues[nProp].setValue(&bMenuMouseFollow, rType); break; //"Menu/FollowMouse",
     128           0 :             case  3: pValues[nProp] <<= nSnapMode; break;               //"Dialog/MousePositioning",
     129           0 :             case  4: pValues[nProp] <<= static_cast<short>(nMiddleMouse); break;               //"Dialog/MiddleMouseButton",
     130             : #if defined( UNX )
     131           0 :             case  5: pValues[nProp].setValue(&bFontAntialiasing, rType); break; // "FontAntialising/Enabled",
     132           0 :             case  6: pValues[nProp] <<= nAAMinPixelHeight; break;               // "FontAntialising/MinPixelHeight",
     133             : #endif
     134             :         }
     135             :     }
     136           0 :     PutProperties(rNames, aValues);
     137           0 : }
     138             : 
     139           0 : void SvtTabAppearanceCfg::Notify( const com::sun::star::uno::Sequence< OUString >& )
     140             : {
     141           0 : }
     142             : 
     143           0 : void SvtTabAppearanceCfg::SetScaleFactor ( sal_uInt16 nSet )
     144             : {
     145           0 :     nScaleFactor = nSet;
     146           0 :     SetModified();
     147           0 : }
     148             : 
     149           0 : void SvtTabAppearanceCfg::SetSnapMode ( sal_uInt16 nSet )
     150             : {
     151           0 :     nSnapMode = nSet;
     152           0 :     SetModified();
     153           0 : }
     154             : 
     155           0 : void SvtTabAppearanceCfg::SetMiddleMouseButton ( MouseMiddleButtonAction nSet )
     156             : {
     157           0 :     nMiddleMouse = nSet;
     158           0 :     SetModified();
     159           0 : }
     160             : 
     161         116 : void SvtTabAppearanceCfg::SetApplicationDefaults ( Application* pApp )
     162             : {
     163         116 :     AllSettings   hAppSettings = Application::GetSettings();
     164         232 :     StyleSettings hAppStyle    = hAppSettings.GetStyleSettings();
     165             : 
     166             :     // Look & Feel
     167             : 
     168             :     // SetStandard...Styles() resets the UseSystemUIFonts flag,
     169             :     // but we don't want to change it now, so save the flag before ...
     170         116 :     bool bUseSystemUIFonts = hAppStyle.GetUseSystemUIFonts();
     171         116 :     hAppStyle.SetStandardStyles();
     172             :     // and set it here
     173         116 :     hAppStyle.SetUseSystemUIFonts( bUseSystemUIFonts );
     174             : 
     175             :     // Screen and ScreenFont Scaling
     176             : 
     177         116 :     hAppStyle.SetScreenZoom( nScaleFactor );
     178         116 :     hAppStyle.SetScreenFontZoom( nScaleFactor );
     179             : 
     180             : #if defined( UNX )
     181             :     // font anti aliasing
     182         116 :     hAppStyle.SetAntialiasingMinPixelHeight( nAAMinPixelHeight );
     183         116 :     hAppStyle.SetDisplayOptions( bFontAntialiasing ? DisplayOptions::NONE : DisplayOptions::AADisable );
     184             : #endif
     185             : 
     186             :     // Mouse Snap
     187             : 
     188         232 :     MouseSettings hMouseSettings = hAppSettings.GetMouseSettings();
     189         116 :     MouseSettingsOptions nMouseOptions  = hMouseSettings.GetOptions();
     190             : 
     191         116 :     nMouseOptions &=  ~ MouseSettingsOptions(MouseSettingsOptions::AutoCenterPos | MouseSettingsOptions::AutoDefBtnPos);
     192             : 
     193         116 :     switch ( nSnapMode )
     194             :     {
     195             :     case SnapToButton:
     196           0 :         nMouseOptions |= MouseSettingsOptions::AutoDefBtnPos;
     197           0 :         break;
     198             :     case SnapToMiddle:
     199           0 :         nMouseOptions |= MouseSettingsOptions::AutoCenterPos;
     200           0 :         break;
     201             :     case NoSnap:
     202             :     default:
     203         116 :         break;
     204             :     }
     205         116 :     hMouseSettings.SetOptions(nMouseOptions);
     206         116 :     hMouseSettings.SetMiddleButtonAction(nMiddleMouse);
     207             : 
     208             :     // Merge and Publish Settings
     209             : 
     210         116 :     MouseFollowFlags nFollow = hMouseSettings.GetFollow();
     211         116 :     if(bMenuMouseFollow)
     212         116 :         nFollow |= MouseFollowFlags::Menu;
     213             :     else
     214           0 :         nFollow &= ~MouseFollowFlags::Menu;
     215         116 :     hMouseSettings.SetFollow( nFollow );
     216             : 
     217         116 :     hAppSettings.SetMouseSettings( hMouseSettings );
     218             : 
     219         116 :     hAppSettings.SetStyleSettings( hAppStyle );
     220         116 :     Application::MergeSystemSettings    ( hAppSettings );      // Allow system-settings to apply
     221         116 :     pApp->OverrideSystemSettings ( hAppSettings );
     222             : 
     223         232 :     Application::SetSettings ( hAppSettings );
     224         116 : }
     225             : 
     226             : 
     227             : 
     228             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11