LCOV - code coverage report
Current view: top level - svtools/source/config - apearcfg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 57 92 62.0 %
Date: 2014-11-03 Functions: 6 12 50.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         320 : SvtTabAppearanceCfg::SvtTabAppearanceCfg()
      41             :     :ConfigItem(OUString("Office.Common/View"))
      42             :     ,nDragMode          ( DEFAULT_DRAGMODE )
      43             :     ,nScaleFactor       ( DEFAULT_SCALEFACTOR )
      44             :     ,nSnapMode          ( DEFAULT_SNAPMODE )
      45             :     ,nMiddleMouse       ( MOUSE_MIDDLE_AUTOSCROLL )
      46             : #if defined( UNX )
      47             :     ,nAAMinPixelHeight  ( DEFAULT_AAMINHEIGHT )
      48             : #endif
      49             :     ,bMenuMouseFollow   ( false )
      50             : #if defined( UNX )
      51         320 :     ,bFontAntialiasing  ( true )
      52             : #endif
      53             : {
      54         320 :     const Sequence<OUString>& rNames = GetPropertyNames();
      55         320 :     Sequence<Any> aValues = GetProperties(rNames);
      56         320 :     const Any* pValues = aValues.getConstArray();
      57             :     DBG_ASSERT(aValues.getLength() == rNames.getLength(), "GetProperties failed");
      58             : 
      59         320 :     if(aValues.getLength() == rNames.getLength())
      60             :     {
      61        2560 :         for(int nProp = 0; nProp < rNames.getLength(); ++nProp, ++pValues)
      62             :         {
      63        2240 :             if(pValues->hasValue())
      64             :             {
      65        2240 :                 switch(nProp)
      66             :                 {
      67         320 :                     case  0: *pValues >>= nScaleFactor; break; //"FontScaling",
      68         320 :                     case  1: *pValues >>= nDragMode; break;   //"Window/Drag",
      69         320 :                     case  2: bMenuMouseFollow = *(sal_Bool*)pValues->getValue(); break; //"Menu/FollowMouse",
      70         320 :                     case  3: *pValues >>= nSnapMode; break; //"Dialog/MousePositioning",
      71         320 :                     case  4: *pValues >>= nMiddleMouse; break; //"Dialog/MiddleMouseButton",
      72             : #if defined( UNX )
      73         320 :                     case  5: bFontAntialiasing = *(sal_Bool*)pValues->getValue(); break;    // "FontAntialising/Enabled",
      74         320 :                     case  6: *pValues >>= nAAMinPixelHeight; break;                         // "FontAntialising/MinPixelHeight",
      75             : #endif
      76             :                 }
      77             :             }
      78             :         }
      79         320 :     }
      80         320 : }
      81             : 
      82         320 : SvtTabAppearanceCfg::~SvtTabAppearanceCfg( )
      83             : {
      84         320 : }
      85             : 
      86         320 : const Sequence<OUString>& SvtTabAppearanceCfg::GetPropertyNames()
      87             : {
      88         320 :     static Sequence<OUString> aNames;
      89         320 :     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         160 :         const int nCount = SAL_N_ELEMENTS( aPropNames );
     104         160 :         aNames.realloc(nCount);
     105             : 
     106         160 :         const sal_Char** pAsciiNames = aPropNames;
     107         160 :         OUString* pNames = aNames.getArray();
     108        1280 :         for(int i = 0; i < nCount; ++i, ++pNames, ++pAsciiNames)
     109        1120 :             *pNames = OUString::createFromAscii( *pAsciiNames );
     110             :     }
     111         320 :     return aNames;
     112             : }
     113             : 
     114           0 : void  SvtTabAppearanceCfg::Commit()
     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 = ::getBooleanCppuType();
     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] <<= 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 ( sal_uInt16 nSet )
     156             : {
     157           0 :     nMiddleMouse = nSet;
     158           0 :     SetModified();
     159           0 : }
     160             : 
     161         160 : void SvtTabAppearanceCfg::SetApplicationDefaults ( Application* pApp )
     162             : {
     163         160 :     AllSettings   hAppSettings = Application::GetSettings();
     164         320 :     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         160 :     bool bUseSystemUIFonts = hAppStyle.GetUseSystemUIFonts();
     171         160 :     hAppStyle.SetStandardStyles();
     172             :     // and set it here
     173         160 :     hAppStyle.SetUseSystemUIFonts( bUseSystemUIFonts );
     174             : 
     175             :     // Screen and ScreenFont Scaling
     176             : 
     177         160 :     hAppStyle.SetScreenZoom( nScaleFactor );
     178         160 :     hAppStyle.SetScreenFontZoom( nScaleFactor );
     179             : 
     180             : #if defined( UNX )
     181             :     // font anti aliasing
     182         160 :     hAppStyle.SetAntialiasingMinPixelHeight( nAAMinPixelHeight );
     183         160 :     hAppStyle.SetDisplayOptions( bFontAntialiasing ? 0 : DISPLAY_OPTION_AA_DISABLE );
     184             : #endif
     185             : 
     186             :     // Mouse Snap
     187             : 
     188         320 :     MouseSettings hMouseSettings = hAppSettings.GetMouseSettings();
     189         160 :     sal_uLong         nMouseOptions  = hMouseSettings.GetOptions();
     190             : 
     191         160 :     nMouseOptions &=  ~ (MOUSE_OPTION_AUTOCENTERPOS | MOUSE_OPTION_AUTODEFBTNPOS);
     192             : 
     193         160 :     switch ( nSnapMode )
     194             :     {
     195             :     case SnapToButton:
     196           0 :         nMouseOptions |= MOUSE_OPTION_AUTODEFBTNPOS;
     197           0 :         break;
     198             :     case SnapToMiddle:
     199           0 :         nMouseOptions |= MOUSE_OPTION_AUTOCENTERPOS;
     200           0 :         break;
     201             :     case NoSnap:
     202             :     default:
     203         160 :         break;
     204             :     }
     205         160 :     hMouseSettings.SetOptions(nMouseOptions);
     206         160 :     hMouseSettings.SetMiddleButtonAction(nMiddleMouse);
     207             : 
     208             :     // Merge and Publish Settings
     209             : 
     210         160 :     sal_uLong nFollow = hMouseSettings.GetFollow();
     211         160 :     if(bMenuMouseFollow)
     212         160 :         nFollow |= MOUSE_FOLLOW_MENU;
     213             :     else
     214           0 :         nFollow &= ~MOUSE_FOLLOW_MENU;
     215         160 :     hMouseSettings.SetFollow( nFollow );
     216             : 
     217         160 :     hAppSettings.SetMouseSettings( hMouseSettings );
     218             : 
     219         160 :     hAppSettings.SetStyleSettings( hAppStyle );
     220         160 :     Application::MergeSystemSettings    ( hAppSettings );      // Allow system-settings to apply
     221         160 :     pApp->OverrideSystemSettings ( hAppSettings );
     222             : 
     223         320 :     Application::SetSettings ( hAppSettings );
     224        1387 : }
     225             : 
     226             : 
     227             : 
     228             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10