LCOV - code coverage report
Current view: top level - sw/source/core/uibase/config - barcfg.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 38 52 73.1 %
Date: 2014-04-11 Functions: 6 8 75.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          74 : SwToolbarConfigItem::SwToolbarConfigItem( bool bWeb ) :
      38             :     ConfigItem(bWeb ? OUString("Office.WriterWeb/ObjectBar") : OUString("Office.Writer/ObjectBar"),
      39          74 :         CONFIG_MODE_DELAYED_UPDATE|CONFIG_MODE_RELEASE_TREE)
      40             : {
      41         444 :     for(sal_uInt16 i = 0; i <= SEL_TYPE_GRAPHIC; i++ )
      42         370 :         aTbxIdArray[i] = -1;
      43             : 
      44          74 :     Sequence<OUString> aNames = GetPropertyNames();
      45         148 :     Sequence<Any> aValues = GetProperties(aNames);
      46          74 :     const Any* pValues = aValues.getConstArray();
      47             :     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
      48          74 :     if(aValues.getLength() == aNames.getLength())
      49             :     {
      50         444 :         for(int nProp = 0; nProp < aNames.getLength(); nProp++)
      51             :         {
      52         370 :             if(pValues[nProp].hasValue())
      53             :             {
      54         370 :                 sal_Int32 nVal = 0;
      55         370 :                 pValues[nProp] >>= nVal;
      56         370 :                 aTbxIdArray[nProp] = nVal;
      57             :             }
      58             :         }
      59          74 :     }
      60          74 : }
      61             : 
      62          72 : SwToolbarConfigItem::~SwToolbarConfigItem()
      63             : {
      64          72 : }
      65             : 
      66          22 : static sal_Int32 lcl_getArrayIndex(int nSelType)
      67             : {
      68          22 :     sal_Int32 nRet = -1;
      69          22 :     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          22 :     else if(nSelType & nsSelectionType::SEL_TBL)
      77          10 :         nRet = SEL_TYPE_TABLE_TEXT;
      78          12 :     else if(nSelType & nsSelectionType::SEL_BEZ)
      79           0 :         nRet = SEL_TYPE_BEZIER;
      80          12 :     else if(nSelType & nsSelectionType::SEL_GRF)
      81           0 :         nRet = SEL_TYPE_GRAPHIC;
      82          22 :     return nRet;
      83             : }
      84             : 
      85          22 : void SwToolbarConfigItem::SetTopToolbar( sal_Int32 nSelType, sal_Int32 nBarId )
      86             : {
      87          22 :     sal_Int32 nProp = lcl_getArrayIndex(nSelType);
      88          22 :     if(nProp >= 0)
      89             :     {
      90          10 :         aTbxIdArray[nProp] = nBarId;
      91          10 :         SetModified();
      92             :     }
      93          22 : }
      94             : 
      95          74 : 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          74 :     const int nCount = 5;
     106          74 :     Sequence<OUString> aNames(nCount);
     107          74 :     OUString* pNames = aNames.getArray();
     108         444 :     for(int i = 0; i < nCount; i++)
     109         370 :         pNames[i] = OUString::createFromAscii(aPropNames[i]);
     110          74 :     return aNames;
     111             : }
     112             : 
     113           0 : void SwToolbarConfigItem::Commit()
     114             : {
     115           0 :     Sequence<OUString> aNames = GetPropertyNames();
     116             : 
     117           0 :     Sequence<Any> aValues(aNames.getLength());
     118           0 :     Any* pValues = aValues.getArray();
     119             : 
     120           0 :     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     121           0 :         pValues[nProp] <<= aTbxIdArray[nProp];
     122           0 :     PutProperties(aNames, aValues);
     123           0 : }
     124             : 
     125           0 : 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