LCOV - code coverage report
Current view: top level - sw/source/uibase/config - barcfg.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 47 52 90.4 %
Date: 2015-06-13 12:38:46 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         118 : SwToolbarConfigItem::SwToolbarConfigItem( bool bWeb ) :
      38             :     ConfigItem(bWeb ? OUString("Office.WriterWeb/ObjectBar") : OUString("Office.Writer/ObjectBar"),
      39         118 :         ConfigItemMode::DelayedUpdate|ConfigItemMode::ReleaseTree)
      40             : {
      41         708 :     for(int i = 0; i <= SEL_TYPE_GRAPHIC; ++i)
      42         590 :         aTbxIdArray[i] = -1;
      43             : 
      44         118 :     Sequence<OUString> aNames = GetPropertyNames();
      45         236 :     Sequence<Any> aValues = GetProperties(aNames);
      46         118 :     const Any* pValues = aValues.getConstArray();
      47             :     OSL_ENSURE(aValues.getLength() == aNames.getLength(), "GetProperties failed");
      48         118 :     if(aValues.getLength() == aNames.getLength())
      49             :     {
      50         708 :         for(int nProp = 0; nProp < aNames.getLength(); nProp++)
      51             :         {
      52         590 :             if(pValues[nProp].hasValue())
      53             :             {
      54         590 :                 sal_Int32 nVal = 0;
      55         590 :                 pValues[nProp] >>= nVal;
      56         590 :                 aTbxIdArray[nProp] = nVal;
      57             :             }
      58             :         }
      59         118 :     }
      60         118 : }
      61             : 
      62         104 : SwToolbarConfigItem::~SwToolbarConfigItem()
      63             : {
      64         104 : }
      65             : 
      66          23 : static sal_Int32 lcl_getArrayIndex(int nSelType)
      67             : {
      68          23 :     sal_Int32 nRet = -1;
      69          23 :     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          23 :     else if(nSelType & nsSelectionType::SEL_TBL)
      77           9 :         nRet = SEL_TYPE_TABLE_TEXT;
      78          14 :     else if(nSelType & nsSelectionType::SEL_BEZ)
      79           0 :         nRet = SEL_TYPE_BEZIER;
      80          14 :     else if(nSelType & nsSelectionType::SEL_GRF)
      81           0 :         nRet = SEL_TYPE_GRAPHIC;
      82          23 :     return nRet;
      83             : }
      84             : 
      85          23 : void SwToolbarConfigItem::SetTopToolbar( sal_Int32 nSelType, sal_Int32 nBarId )
      86             : {
      87          23 :     sal_Int32 nProp = lcl_getArrayIndex(nSelType);
      88          23 :     if(nProp >= 0)
      89             :     {
      90           9 :         aTbxIdArray[nProp] = nBarId;
      91           9 :         SetModified();
      92             :     }
      93          23 : }
      94             : 
      95         123 : 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         123 :     const int nCount = 5;
     106         123 :     Sequence<OUString> aNames(nCount);
     107         123 :     OUString* pNames = aNames.getArray();
     108         738 :     for(int i = 0; i < nCount; i++)
     109         615 :         pNames[i] = OUString::createFromAscii(aPropNames[i]);
     110         123 :     return aNames;
     111             : }
     112             : 
     113           5 : void SwToolbarConfigItem::ImplCommit()
     114             : {
     115           5 :     Sequence<OUString> aNames = GetPropertyNames();
     116             : 
     117          10 :     Sequence<Any> aValues(aNames.getLength());
     118           5 :     Any* pValues = aValues.getArray();
     119             : 
     120          30 :     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     121          25 :         pValues[nProp] <<= aTbxIdArray[nProp];
     122          10 :     PutProperties(aNames, aValues);
     123           5 : }
     124             : 
     125         177 : void SwToolbarConfigItem::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
     126             : 
     127             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11