LCOV - code coverage report
Current view: top level - xmloff/source/forms - formattributes.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 117 157 74.5 %
Date: 2014-04-11 Functions: 16 22 72.7 %
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 "formattributes.hxx"
      21             : 
      22             : #include <sax/tools/converter.hxx>
      23             : 
      24             : #include <xmloff/xmlnmspe.hxx>
      25             : #include <xmloff/xmluconv.hxx>
      26             : #include <rtl/ustrbuf.hxx>
      27             : namespace xmloff
      28             : {
      29             : 
      30             :     using namespace ::com::sun::star::uno;
      31             :     using namespace ::com::sun::star::lang;
      32             :     using namespace ::com::sun::star::beans;
      33             : 
      34             :     //= OAttributeMetaData
      35       11879 :     const sal_Char* OAttributeMetaData::getCommonControlAttributeName(sal_Int32 _nId)
      36             :     {
      37       11879 :         switch (_nId)
      38             :         {
      39         623 :             case CCA_NAME:              return "name";
      40           0 :             case CCA_SERVICE_NAME:      return "control-implementation";
      41         623 :             case CCA_BUTTON_TYPE:       return "button-type";
      42             : // disabled(AddAttributeIdLegacy)   case CCA_CONTROL_ID:        return "id";
      43         624 :             case CCA_CURRENT_SELECTED:  return "current-selected";
      44           5 :             case CCA_CURRENT_VALUE:     return "current-value";
      45         623 :             case CCA_DISABLED:          return "disabled";
      46           0 :             case CCA_ENABLEVISIBLE:     return "visible";
      47         623 :             case CCA_DROPDOWN:          return "dropdown";
      48           0 :             case CCA_FOR:               return "for";
      49         627 :             case CCA_IMAGE_DATA:        return "image-data";
      50         623 :             case CCA_LABEL:             return "label";
      51         623 :             case CCA_MAX_LENGTH:        return "max-length";
      52         623 :             case CCA_PRINTABLE:         return "printable";
      53         623 :             case CCA_READONLY:          return "readonly";
      54         624 :             case CCA_SELECTED:          return "selected";
      55         623 :             case CCA_SIZE:              return "size";
      56         623 :             case CCA_TAB_INDEX:         return "tab-index";
      57         645 :             case CCA_TARGET_FRAME:      return "target-frame";
      58         627 :             case CCA_TARGET_LOCATION:   return "href";      // the only special thing here: TargetLocation is represented by an xlink:href attribute
      59         623 :             case CCA_TAB_STOP:          return "tab-stop";
      60         623 :             case CCA_TITLE:             return "title";
      61           5 :             case CCA_VALUE:             return "value";
      62         623 :             case CCA_ORIENTATION:       return "orientation";
      63         623 :             case CCA_VISUAL_EFFECT:     return "visual-effect";
      64             :             default:
      65             :                 OSL_FAIL("OAttributeMetaData::getCommonControlAttributeName: invalid id (maybe you or-ed two flags?)!");
      66             :         }
      67           0 :         return "";
      68             :     }
      69             : 
      70           0 :     sal_uInt16 OAttributeMetaData::getCommonControlAttributeNamespace(sal_Int32 _nId)
      71             :     {
      72           0 :         if (CCA_TARGET_LOCATION == _nId)
      73           0 :             return XML_NAMESPACE_XLINK;
      74             : 
      75           0 :         if (CCA_TARGET_FRAME == _nId)
      76           0 :             return XML_NAMESPACE_OFFICE;
      77             : 
      78           0 :         return XML_NAMESPACE_FORM;
      79             :     }
      80             : 
      81        9355 :     const sal_Char* OAttributeMetaData::getFormAttributeName(FormAttributes _eAttrib)
      82             :     {
      83        9355 :         switch (_eAttrib)
      84             :         {
      85           0 :             case faName:                return "name";
      86           0 :             case faServiceName:         return "service-name";
      87           0 :             case faAction:              return "href";      // the only special thing here: Action is represented by an xlink:href attribute
      88         623 :             case faEnctype:             return "enctype";
      89         623 :             case faMethod:              return "method";
      90           0 :             case faTargetFrame:         return "target-frame";
      91         623 :             case faAllowDeletes:        return "allow-deletes";
      92         623 :             case faAllowInserts:        return "allow-inserts";
      93         623 :             case faAllowUpdates:        return "allow-updates";
      94         623 :             case faApplyFilter:         return "apply-filter";
      95         623 :             case faCommand:             return "command";
      96         623 :             case faCommandType:         return "command-type";
      97         623 :             case faEscapeProcessing:    return "escape-processing";
      98         623 :             case faDatasource:          return "datasource";
      99           0 :             case faConnectionResource:  return "connection-resource";
     100           5 :             case faDetailFiels:         return "detail-fields";
     101         623 :             case faFilter:              return "filter";
     102         623 :             case faIgnoreResult:        return "ignore-result";
     103           5 :             case faMasterFields:        return "master-fields";
     104         623 :             case faNavigationMode:      return "navigation-mode";
     105         623 :             case faOrder:               return "order";
     106         623 :             case faTabbingCycle:        return "tab-cycle";
     107             :             default:
     108             :                 OSL_FAIL("OAttributeMetaData::getFormAttributeName: invalid id!");
     109             :         }
     110           0 :         return "";
     111             :     }
     112             : 
     113           0 :     sal_uInt16 OAttributeMetaData::getFormAttributeNamespace(FormAttributes _eAttrib)
     114             :     {
     115           0 :         if (faAction == _eAttrib)
     116           0 :             return XML_NAMESPACE_XLINK;
     117             : 
     118           0 :         if (faTargetFrame == _eAttrib)
     119           0 :             return XML_NAMESPACE_OFFICE;
     120             : 
     121           0 :         return XML_NAMESPACE_FORM;
     122             :     }
     123             : 
     124        3121 :     const sal_Char* OAttributeMetaData::getDatabaseAttributeName(sal_Int32 _nId)
     125             :     {
     126        3121 :         switch (_nId)
     127             :         {
     128         623 :             case DA_BOUND_COLUMN:       return "bound-column";
     129         629 :             case DA_CONVERT_EMPTY:      return "convert-empty-to-null";
     130         623 :             case DA_DATA_FIELD:         return "data-field";
     131           0 :             case DA_LIST_SOURCE:        return "list-source";
     132         623 :             case DA_LIST_SOURCE_TYPE:   return "list-source-type";
     133         623 :             case DA_INPUT_REQUIRED:     return "input-required";
     134             :             default:
     135             :                 OSL_FAIL("OAttributeMetaData::getDatabaseAttributeName: invalid id (maybe you or-ed two flags?)!");
     136             :         }
     137           0 :         return "";
     138             :     }
     139             : 
     140           0 :     sal_uInt16 OAttributeMetaData::getDatabaseAttributeNamespace(sal_Int32 /*_nId*/)
     141             :     {
     142             :         // nothing special here
     143           0 :         return XML_NAMESPACE_FORM;
     144             :     }
     145             : 
     146           5 :     const sal_Char* OAttributeMetaData::getBindingAttributeName(sal_Int32 _nId)
     147             :     {
     148           5 :         switch (_nId)
     149             :         {
     150           5 :             case BA_LINKED_CELL:       return "linked-cell";
     151           0 :             case BA_LIST_LINKING_TYPE: return "list-linkage-type";
     152           0 :             case BA_LIST_CELL_RANGE:   return "source-cell-range";
     153             :             default:
     154             :                 OSL_FAIL("OAttributeMetaData::getBindingAttributeName: invalid id (maybe you or-ed two flags?)!");
     155             :         }
     156           0 :         return "";
     157             :     }
     158             : 
     159           0 :     sal_uInt16 OAttributeMetaData::getBindingAttributeNamespace(sal_Int32)
     160             :     {
     161             :         // nothing special here
     162           0 :         return XML_NAMESPACE_FORM;
     163             :     }
     164             : 
     165        7491 :     const sal_Char* OAttributeMetaData::getSpecialAttributeName(sal_Int32 _nId)
     166             :     {
     167        7491 :         switch (_nId)
     168             :         {
     169           0 :             case SCA_ECHO_CHAR:             return "echo-char";
     170           5 :             case SCA_MAX_VALUE:             return "max-value";
     171           5 :             case SCA_MIN_VALUE:             return "min-value";
     172         623 :             case SCA_VALIDATION:            return "validation";
     173         623 :             case SCA_GROUP_NAME:            return "group-name";
     174         623 :             case SCA_MULTI_LINE:            return "multi-line";
     175         623 :             case SCA_AUTOMATIC_COMPLETION:  return "auto-complete";
     176         623 :             case SCA_MULTIPLE:              return "multiple";
     177         623 :             case SCA_DEFAULT_BUTTON:        return "default-button";
     178         623 :             case SCA_CURRENT_STATE:         return "current-state";
     179         623 :             case SCA_IS_TRISTATE:           return "is-tristate";
     180         623 :             case SCA_STATE:                 return "state";
     181           0 :             case SCA_COLUMN_STYLE_NAME:     return "text-style-name";
     182           0 :             case SCA_STEP_SIZE:             return "step-size";
     183         623 :             case SCA_PAGE_STEP_SIZE:        return "page-step-size";
     184           5 :             case SCA_REPEAT_DELAY:          return "delay-for-repeat";
     185         623 :             case SCA_TOGGLE:                return "toggle";
     186         623 :             case SCA_FOCUS_ON_CLICK:        return "focus-on-click";
     187             :             default:
     188             :                 OSL_FAIL("OAttributeMetaData::getSpecialAttributeName: invalid id (maybe you or-ed two flags?)!");
     189             :         }
     190           0 :         return "";
     191             :     }
     192             : 
     193           0 :     sal_uInt16 OAttributeMetaData::getSpecialAttributeNamespace(sal_Int32 _nId)
     194             :     {
     195           0 :         switch( _nId )
     196             :         {
     197           0 :             case SCA_GROUP_NAME:            return XML_NAMESPACE_FORMX;
     198             :         }
     199           0 :         return XML_NAMESPACE_FORM;
     200             :     }
     201             : 
     202          86 :     const sal_Char* OAttributeMetaData::getOfficeFormsAttributeName(OfficeFormsAttributes _eAttrib)
     203             :     {
     204          86 :         switch (_eAttrib)
     205             :         {
     206          43 :             case ofaAutomaticFocus:     return "automatic-focus";
     207          43 :             case ofaApplyDesignMode:    return "apply-design-mode";
     208             :             default:
     209             :                 OSL_FAIL("OAttributeMetaData::getOfficeFormsAttributeName: invalid id!");
     210             :         }
     211           0 :         return "";
     212             :     }
     213             : 
     214          86 :     sal_uInt16 OAttributeMetaData::getOfficeFormsAttributeNamespace(OfficeFormsAttributes /* _eAttrib */)
     215             :     {
     216             :         // nothing special here
     217          86 :         return XML_NAMESPACE_FORM;
     218             :     }
     219             : 
     220             :     //= OAttribute2Property
     221         623 :     OAttribute2Property::OAttribute2Property()
     222             :     {
     223         623 :     }
     224             : 
     225         623 :     OAttribute2Property::~OAttribute2Property()
     226             :     {
     227         623 :     }
     228             : 
     229         102 :     const OAttribute2Property::AttributeAssignment* OAttribute2Property::getAttributeTranslation(
     230             :             const OUString& _rAttribName)
     231             :     {
     232         102 :         AttributeAssignments::const_iterator aPos = m_aKnownProperties.find(_rAttribName);
     233         102 :         if (m_aKnownProperties.end() != aPos)
     234          99 :             return &aPos->second;
     235           3 :         return NULL;
     236             :     }
     237             : 
     238        7476 :     void OAttribute2Property::addStringProperty(
     239             :         const sal_Char* _pAttributeName, const OUString& _rPropertyName,
     240             :         const sal_Char* _pAttributeDefault)
     241             :     {
     242        7476 :         implAdd(_pAttributeName, _rPropertyName, ::getCppuType( static_cast< OUString* >(NULL) ),
     243       14952 :             _pAttributeDefault ? OUString::createFromAscii(_pAttributeDefault) : OUString());
     244        7476 :     }
     245             : 
     246       14329 :     void OAttribute2Property::addBooleanProperty(
     247             :         const sal_Char* _pAttributeName, const OUString& _rPropertyName,
     248             :         const sal_Bool _bAttributeDefault, const sal_Bool _bInverseSemantics)
     249             :     {
     250       14329 :         OUStringBuffer aDefault;
     251       14329 :         ::sax::Converter::convertBool(aDefault, _bAttributeDefault);
     252       14329 :         AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName, ::getBooleanCppuType(), aDefault.makeStringAndClear());
     253       14329 :         aAssignment.bInverseSemantics = _bInverseSemantics;
     254       14329 :     }
     255             : 
     256        2492 :     void OAttribute2Property::addInt16Property(
     257             :         const sal_Char* _pAttributeName, const OUString& _rPropertyName,
     258             :         const sal_Int16 _nAttributeDefault)
     259             :     {
     260        2492 :         OUStringBuffer aDefault;
     261        2492 :         ::sax::Converter::convertNumber(aDefault, (sal_Int32)_nAttributeDefault);
     262        2492 :         implAdd(_pAttributeName, _rPropertyName, ::getCppuType( static_cast< sal_Int16* >(NULL) ), aDefault.makeStringAndClear());
     263        2492 :     }
     264             : 
     265         623 :     void OAttribute2Property::addInt32Property(
     266             :         const sal_Char* _pAttributeName, const OUString& _rPropertyName,
     267             :         const sal_Int32 _nAttributeDefault)
     268             :     {
     269         623 :         OUStringBuffer aDefault;
     270         623 :         ::sax::Converter::convertNumber( aDefault, _nAttributeDefault );
     271         623 :         implAdd( _pAttributeName, _rPropertyName, ::getCppuType( static_cast< sal_Int32* >(NULL) ), aDefault.makeStringAndClear() );
     272         623 :     }
     273             : 
     274        6853 :     void OAttribute2Property::addEnumProperty(
     275             :             const sal_Char* _pAttributeName, const OUString& _rPropertyName,
     276             :             const sal_uInt16 _nAttributeDefault, const SvXMLEnumMapEntry* _pValueMap,
     277             :             const ::com::sun::star::uno::Type* _pType)
     278             :     {
     279        6853 :         OUStringBuffer aDefault;
     280        6853 :         SvXMLUnitConverter::convertEnum(aDefault, _nAttributeDefault, _pValueMap);
     281             :         AttributeAssignment& aAssignment = implAdd(_pAttributeName, _rPropertyName,
     282             :             _pType ? *_pType : ::getCppuType( static_cast< sal_Int32* >(NULL) ),
     283             :                 // this assumes that the setPropertyValue for enums can handle int32's ....
     284        6853 :             aDefault.makeStringAndClear());
     285        6853 :         aAssignment.pEnumMap = _pValueMap;
     286        6853 :     }
     287             : 
     288       31773 :     OAttribute2Property::AttributeAssignment& OAttribute2Property::implAdd(
     289             :             const sal_Char* _pAttributeName, const OUString& _rPropertyName,
     290             :             const ::com::sun::star::uno::Type& _rType, const OUString& /*_rDefaultString*/)
     291             :     {
     292             :         OSL_ENSURE(m_aKnownProperties.end() == m_aKnownProperties.find(OUString::createFromAscii(_pAttributeName)),
     293             :             "OAttribute2Property::implAdd: already have this attribute!");
     294             : 
     295       31773 :         OUString sAttributeName = OUString::createFromAscii(_pAttributeName);
     296             : 
     297       63546 :         AttributeAssignment aAssignment;
     298       31773 :         aAssignment.sAttributeName = sAttributeName;
     299       31773 :         aAssignment.sPropertyName = _rPropertyName;
     300       31773 :         aAssignment.aPropertyType = _rType;
     301             : 
     302             :         // redundance, the accessor is stored in aAssignment.sAttributeName, too
     303       63546 :         return m_aKnownProperties[sAttributeName] = aAssignment;
     304             :     }
     305             : 
     306             : }   // namespace xmloff
     307             : 
     308             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10