Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / core / api / columnsettings.cxx
blob9395b224ded72895a02d1638c1a86bd0c406dc4c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "columnsettings.hxx"
21 #include "dbastrings.hrc"
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <cppuhelper/typeprovider.hxx>
26 #include <comphelper/property.hxx>
27 #include <tools/debug.hxx>
28 #include <tools/diagnose_ex.h>
30 namespace dbaccess
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::XInterface;
35 using ::com::sun::star::uno::UNO_QUERY;
36 using ::com::sun::star::uno::UNO_QUERY_THROW;
37 using ::com::sun::star::uno::UNO_SET_THROW;
38 using ::com::sun::star::uno::Exception;
39 using ::com::sun::star::uno::RuntimeException;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::makeAny;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Type;
44 using ::com::sun::star::lang::IllegalArgumentException;
45 using ::com::sun::star::beans::XPropertySet;
46 using ::com::sun::star::beans::XPropertySetInfo;
48 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
50 // OColumnSettings
52 OColumnSettings::OColumnSettings()
53 :m_bHidden(false)
57 OColumnSettings::~OColumnSettings()
61 void OColumnSettings::registerProperties( IPropertyContainer& _rPropertyContainer )
63 const sal_Int32 nBoundAttr = PropertyAttribute::BOUND;
64 const sal_Int32 nMayBeVoidAttr = PropertyAttribute::MAYBEVOID | nBoundAttr;
66 const Type& rSalInt32Type = ::cppu::UnoType<sal_Int32>::get();
67 const Type& rStringType = ::cppu::UnoType<OUString>::get();
69 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_ALIGN, PROPERTY_ID_ALIGN, nMayBeVoidAttr, &m_aAlignment, rSalInt32Type );
70 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_NUMBERFORMAT, PROPERTY_ID_NUMBERFORMAT, nMayBeVoidAttr, &m_aFormatKey, rSalInt32Type );
71 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_RELATIVEPOSITION, PROPERTY_ID_RELATIVEPOSITION, nMayBeVoidAttr, &m_aRelativePosition, rSalInt32Type );
72 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_WIDTH, PROPERTY_ID_WIDTH, nMayBeVoidAttr, &m_aWidth, rSalInt32Type );
73 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_HELPTEXT, PROPERTY_ID_HELPTEXT, nMayBeVoidAttr, &m_aHelpText, rStringType );
74 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_CONTROLDEFAULT, PROPERTY_ID_CONTROLDEFAULT, nMayBeVoidAttr, &m_aControlDefault, rStringType );
75 _rPropertyContainer.registerProperty( PROPERTY_CONTROLMODEL, PROPERTY_ID_CONTROLMODEL, nBoundAttr, &m_xControlModel, cppu::UnoType<decltype(m_xControlModel)>::get() );
76 _rPropertyContainer.registerProperty( PROPERTY_HIDDEN, PROPERTY_ID_HIDDEN, nBoundAttr, &m_bHidden, cppu::UnoType<decltype(m_bHidden)>::get() );
79 bool OColumnSettings::isColumnSettingProperty( const sal_Int32 _nPropertyHandle )
81 return ( _nPropertyHandle == PROPERTY_ID_ALIGN )
82 || ( _nPropertyHandle == PROPERTY_ID_NUMBERFORMAT )
83 || ( _nPropertyHandle == PROPERTY_ID_RELATIVEPOSITION )
84 || ( _nPropertyHandle == PROPERTY_ID_WIDTH )
85 || ( _nPropertyHandle == PROPERTY_ID_HELPTEXT )
86 || ( _nPropertyHandle == PROPERTY_ID_CONTROLDEFAULT )
87 || ( _nPropertyHandle == PROPERTY_ID_CONTROLMODEL )
88 || ( _nPropertyHandle == PROPERTY_ID_HIDDEN );
91 bool OColumnSettings::isDefaulted( const sal_Int32 _nPropertyHandle, const Any& _rPropertyValue )
93 switch ( _nPropertyHandle )
95 case PROPERTY_ID_ALIGN:
96 case PROPERTY_ID_NUMBERFORMAT:
97 case PROPERTY_ID_RELATIVEPOSITION:
98 case PROPERTY_ID_WIDTH:
99 case PROPERTY_ID_HELPTEXT:
100 case PROPERTY_ID_CONTROLDEFAULT:
101 return !_rPropertyValue.hasValue();
103 case PROPERTY_ID_CONTROLMODEL:
104 return !Reference< XPropertySet >( _rPropertyValue, UNO_QUERY ).is();
106 case PROPERTY_ID_HIDDEN:
108 bool bHidden = false;
109 OSL_VERIFY( _rPropertyValue >>= bHidden );
110 return !bHidden;
113 OSL_FAIL( "OColumnSettings::isDefaulted: illegal property handle!" );
114 return false;
117 bool OColumnSettings::hasDefaultSettings( const Reference< XPropertySet >& _rxColumn )
119 ENSURE_OR_THROW( _rxColumn.is(), "illegal column" );
122 Reference< XPropertySetInfo > xPSI( _rxColumn->getPropertySetInfo(), UNO_SET_THROW );
124 struct PropertyDescriptor
126 OUString sName;
127 sal_Int32 nHandle;
129 PropertyDescriptor aProps[] =
131 { OUString(PROPERTY_ALIGN), PROPERTY_ID_ALIGN },
132 { OUString(PROPERTY_NUMBERFORMAT), PROPERTY_ID_NUMBERFORMAT },
133 { OUString(PROPERTY_RELATIVEPOSITION), PROPERTY_ID_RELATIVEPOSITION },
134 { OUString(PROPERTY_WIDTH), PROPERTY_ID_WIDTH },
135 { OUString(PROPERTY_HELPTEXT), PROPERTY_ID_HELPTEXT },
136 { OUString(PROPERTY_CONTROLDEFAULT), PROPERTY_ID_CONTROLDEFAULT },
137 { OUString(PROPERTY_CONTROLMODEL), PROPERTY_ID_CONTROLMODEL },
138 { OUString(PROPERTY_HIDDEN), PROPERTY_ID_HIDDEN }
141 for ( size_t i=0; i < sizeof( aProps ) / sizeof( aProps[0] ); ++i )
143 if ( xPSI->hasPropertyByName( aProps[i].sName ) )
144 if ( !isDefaulted( aProps[i].nHandle, _rxColumn->getPropertyValue( aProps[i].sName ) ) )
145 return false;
148 catch( const Exception& )
150 DBG_UNHANDLED_EXCEPTION();
152 return true;
155 } // namespace dbaccess
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */