LCOV - code coverage report
Current view: top level - sw/source/uibase/config - barcfg.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 47 52 90.4 %
Date: 2014-11-03 Functions: 9 10 90.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 <osl/diagnose.h>
      21             : #include <com/sun/star/uno/Any.hxx>
      22             : #include <com/sun/star/uno/Sequence.hxx>
      23             : #include <wrtsh.hxx>
      24             : #include "barcfg.hxx"
      25             : 
      26             : #include <unomid.h>
      27             : 
      28             : using namespace utl;
      29             : using namespace com::sun::star::uno;
      30             : 
      31             : #define SEL_TYPE_TABLE_TEXT     0
      32             : #define SEL_TYPE_LIST_TEXT      1
      33             : #define SEL_TYPE_TABLE_LIST     2
      34             : #define SEL_TYPE_BEZIER         3
      35             : #define SEL_TYPE_GRAPHIC        4
      36             : 
      37         180 : SwToolbarConfigItem::SwToolbarConfigItem( bool bWeb ) :
      38             :     ConfigItem(bWeb ? OUString("Office.WriterWeb/ObjectBar") : OUString("Office.Writer/ObjectBar"),
      39         180 :         CONFIG_MODE_DELAYED_UPDATE|CONFIG_MODE_RELEASE_TREE)
      40             : {
      41        1080 :     for(sal_uInt16 i = 0; i <= SEL_TYPE_GRAPHIC; i++ )
      42         900 :         aTbxIdArray[i] = -1;
      43             : 
      44         180 :     Sequence<OUString> aNames = GetPropertyNames();
      45         360 :     Sequence<Any> aValues = GetProperties(aNames);
      46         180 :     const Any* pValues = aValues.getConstArray();
      47             :     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
      48         180 :     if(aValues.getLength() == aNames.getLength())
      49             :     {
      50        1080 :         for(int nProp = 0; nProp < aNames.getLength(); nProp++)
      51             :         {
      52         900 :             if(pValues[nProp].hasValue())
      53             :             {
      54         900 :                 sal_Int32 nVal = 0;
      55         900 :                 pValues[nProp] >>= nVal;
      56         900 :                 aTbxIdArray[nProp] = nVal;
      57             :             }
      58             :         }
      59         180 :     }
      60         180 : }
      61             : 
      62         144 : SwToolbarConfigItem::~SwToolbarConfigItem()
      63             : {
      64         144 : }
      65             : 
      66          46 : static sal_Int32 lcl_getArrayIndex(int nSelType)
      67             : {
      68          46 :     sal_Int32 nRet = -1;
      69          46 :     if(nSelType & nsSelectionType::SEL_NUM)
      70             :     {
      71           0 :         if(nSelType & nsSelectionType::SEL_TBL)
      72           0 :             nRet = SEL_TYPE_TABLE_LIST;
      73             :         else
      74           0 :             nRet = SEL_TYPE_LIST_TEXT;
      75             :     }
      76          46 :     else if(nSelType & nsSelectionType::SEL_TBL)
      77          20 :         nRet = SEL_TYPE_TABLE_TEXT;
      78          26 :     else if(nSelType & nsSelectionType::SEL_BEZ)
      79           0 :         nRet = SEL_TYPE_BEZIER;
      80          26 :     else if(nSelType & nsSelectionType::SEL_GRF)
      81           0 :         nRet = SEL_TYPE_GRAPHIC;
      82          46 :     return nRet;
      83             : }
      84             : 
      85          46 : void SwToolbarConfigItem::SetTopToolbar( sal_Int32 nSelType, sal_Int32 nBarId )
      86             : {
      87          46 :     sal_Int32 nProp = lcl_getArrayIndex(nSelType);
      88          46 :     if(nProp >= 0)
      89             :     {
      90          20 :         aTbxIdArray[nProp] = nBarId;
      91          20 :         SetModified();
      92             :     }
      93          46 : }
      94             : 
      95         192 : Sequence<OUString> SwToolbarConfigItem::GetPropertyNames()
      96             : {
      97             :     static const char* aPropNames[] =
      98             :     {
      99             :         "Selection/Table",                   //  SEL_TYPE_TABLE_TEXT
     100             :         "Selection/NumberedList",            //  SEL_TYPE_LIST_TEXT
     101             :         "Selection/NumberedList_InTable",     //  SEL_TYPE_TABLE_LIST
     102             :         "Selection/BezierObject",           //  SEL_TYPE_BEZIER
     103             :         "Selection/Graphic"                 //SEL_TYPE_GRAPHIC
     104             :     };
     105         192 :     const int nCount = 5;
     106         192 :     Sequence<OUString> aNames(nCount);
     107         192 :     OUString* pNames = aNames.getArray();
     108        1152 :     for(int i = 0; i < nCount; i++)
     109         960 :         pNames[i] = OUString::createFromAscii(aPropNames[i]);
     110         192 :     return aNames;
     111             : }
     112             : 
     113          12 : void SwToolbarConfigItem::Commit()
     114             : {
     115          12 :     Sequence<OUString> aNames = GetPropertyNames();
     116             : 
     117          24 :     Sequence<Any> aValues(aNames.getLength());
     118          12 :     Any* pValues = aValues.getArray();
     119             : 
     120          72 :     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     121          60 :         pValues[nProp] <<= aTbxIdArray[nProp];
     122          24 :     PutProperties(aNames, aValues);
     123          12 : }
     124             : 
     125         270 : void SwToolbarConfigItem::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10