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

Generated by: LCOV version 1.10