LibreOffice Module dbaccess (master) 1
columnsettings.cxx
Go to the documentation of this file.
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 <columnsettings.hxx>
21#include <stringconstants.hxx>
22#include <strings.hxx>
23
24#include <com/sun/star/beans/PropertyAttribute.hpp>
25
28
29namespace dbaccess
30{
31
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::uno::UNO_QUERY;
34 using ::com::sun::star::uno::UNO_SET_THROW;
35 using ::com::sun::star::uno::Exception;
36 using ::com::sun::star::uno::Any;
37 using ::com::sun::star::uno::Type;
38 using ::com::sun::star::beans::XPropertySet;
39 using ::com::sun::star::beans::XPropertySetInfo;
40
41 namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
42
43 // OColumnSettings
44
46 :m_bHidden(false)
47 {
48 }
49
51 {
52 }
53
55 {
56 const sal_Int32 nBoundAttr = PropertyAttribute::BOUND;
57 const sal_Int32 nMayBeVoidAttr = PropertyAttribute::MAYBEVOID | nBoundAttr;
58
59 const Type& rSalInt32Type = ::cppu::UnoType<sal_Int32>::get();
60 const Type& rStringType = ::cppu::UnoType<OUString>::get();
61
62 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_ALIGN, PROPERTY_ID_ALIGN, nMayBeVoidAttr, &m_aAlignment, rSalInt32Type );
63 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_NUMBERFORMAT, PROPERTY_ID_NUMBERFORMAT, nMayBeVoidAttr, &m_aFormatKey, rSalInt32Type );
64 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_RELATIVEPOSITION, PROPERTY_ID_RELATIVEPOSITION, nMayBeVoidAttr, &m_aRelativePosition, rSalInt32Type );
65 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_WIDTH, PROPERTY_ID_WIDTH, nMayBeVoidAttr, &m_aWidth, rSalInt32Type );
66 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_HELPTEXT, PROPERTY_ID_HELPTEXT, nMayBeVoidAttr, &m_aHelpText, rStringType );
67 _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_CONTROLDEFAULT, PROPERTY_ID_CONTROLDEFAULT, nMayBeVoidAttr, &m_aControlDefault, rStringType );
69 _rPropertyContainer.registerProperty( PROPERTY_HIDDEN, PROPERTY_ID_HIDDEN, nBoundAttr, &m_bHidden, cppu::UnoType<decltype(m_bHidden)>::get() );
70 }
71
72 bool OColumnSettings::isColumnSettingProperty( const sal_Int32 _nPropertyHandle )
73 {
74 return ( _nPropertyHandle == PROPERTY_ID_ALIGN )
75 || ( _nPropertyHandle == PROPERTY_ID_NUMBERFORMAT )
76 || ( _nPropertyHandle == PROPERTY_ID_RELATIVEPOSITION )
77 || ( _nPropertyHandle == PROPERTY_ID_WIDTH )
78 || ( _nPropertyHandle == PROPERTY_ID_HELPTEXT )
79 || ( _nPropertyHandle == PROPERTY_ID_CONTROLDEFAULT )
80 || ( _nPropertyHandle == PROPERTY_ID_CONTROLMODEL )
81 || ( _nPropertyHandle == PROPERTY_ID_HIDDEN );
82 }
83
84 bool OColumnSettings::isDefaulted( const sal_Int32 _nPropertyHandle, const Any& _rPropertyValue )
85 {
86 switch ( _nPropertyHandle )
87 {
94 return !_rPropertyValue.hasValue();
95
97 return !Reference< XPropertySet >( _rPropertyValue, UNO_QUERY ).is();
98
100 {
101 bool bHidden = false;
102 OSL_VERIFY( _rPropertyValue >>= bHidden );
103 return !bHidden;
104 }
105 }
106 OSL_FAIL( "OColumnSettings::isDefaulted: illegal property handle!" );
107 return false;
108 }
109
110 bool OColumnSettings::hasDefaultSettings( const Reference< XPropertySet >& _rxColumn )
111 {
112 ENSURE_OR_THROW( _rxColumn.is(), "illegal column" );
113 try
114 {
115 Reference< XPropertySetInfo > xPSI( _rxColumn->getPropertySetInfo(), UNO_SET_THROW );
116
117 struct PropertyDescriptor
118 {
119 OUString sName;
120 sal_Int32 nHandle;
121 };
122 const PropertyDescriptor aProps[] =
123 {
124 { OUString(PROPERTY_ALIGN), PROPERTY_ID_ALIGN },
127 { OUString(PROPERTY_WIDTH), PROPERTY_ID_WIDTH },
132 };
133
134 for (const auto & aProp : aProps)
135 {
136 if ( xPSI->hasPropertyByName( aProp.sName ) )
137 if ( !isDefaulted( aProp.nHandle, _rxColumn->getPropertyValue( aProp.sName ) ) )
138 return false;
139 }
140 }
141 catch( const Exception& )
142 {
143 DBG_UNHANDLED_EXCEPTION("dbaccess");
144 }
145 return true;
146 }
147
148} // namespace dbaccess
149
150/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OptionalString sName
css::uno::Type const & get()
virtual void registerMayBeVoidProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, css::uno::Any *_pPointerToMember, const css::uno::Type &_rExpectedType)=0
virtual void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)=0
css::uno::Reference< css::beans::XPropertySet > m_xControlModel
void registerProperties(IPropertyContainer &_rPropertyContainer)
css::uno::Any m_aRelativePosition
static bool isDefaulted(const sal_Int32 _nPropertyHandle, const css::uno::Any &_rPropertyValue)
static bool hasDefaultSettings(const css::uno::Reference< css::beans::XPropertySet > &_rxColumn)
check if the persistent settings have their default value
static bool isColumnSettingProperty(const sal_Int32 _nPropertyHandle)
determines whether the property with the given handle is handled by the class
#define ENSURE_OR_THROW(c, m)
#define DBG_UNHANDLED_EXCEPTION(...)
@ Exception
Type
sal_Int32 nHandle
#define PROPERTY_ID_CONTROLMODEL
#define PROPERTY_ID_RELATIVEPOSITION
#define PROPERTY_ID_HELPTEXT
#define PROPERTY_ID_WIDTH
#define PROPERTY_ID_HIDDEN
#define PROPERTY_ID_ALIGN
#define PROPERTY_ID_CONTROLDEFAULT
#define PROPERTY_ID_NUMBERFORMAT
constexpr OUStringLiteral PROPERTY_WIDTH(u"Width")
constexpr OUStringLiteral PROPERTY_CONTROLDEFAULT(u"ControlDefault")
constexpr OUStringLiteral PROPERTY_RELATIVEPOSITION(u"RelativePosition")
constexpr OUStringLiteral PROPERTY_NUMBERFORMAT(u"FormatKey")
constexpr OUStringLiteral PROPERTY_HELPTEXT(u"HelpText")
constexpr OUStringLiteral PROPERTY_CONTROLMODEL(u"ControlModel")
constexpr OUStringLiteral PROPERTY_HIDDEN(u"Hidden")
constexpr OUStringLiteral PROPERTY_ALIGN(u"Align")