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 "columnsettings.hxx"
21 : #include "dbastrings.hrc"
22 :
23 : #include <com/sun/star/beans/PropertyAttribute.hpp>
24 :
25 : #include <cppuhelper/typeprovider.hxx>
26 : #include <comphelper/property.hxx>
27 : #include <tools/debug.hxx>
28 : #include <tools/diagnose_ex.h>
29 :
30 : namespace dbaccess
31 : {
32 :
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;
47 :
48 : namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
49 :
50 : // OColumnSettings
51 :
52 0 : OColumnSettings::OColumnSettings()
53 0 : :m_bHidden(sal_False)
54 : {
55 0 : }
56 :
57 0 : OColumnSettings::~OColumnSettings()
58 : {
59 0 : }
60 :
61 0 : void OColumnSettings::registerProperties( IPropertyContainer& _rPropertyContainer )
62 : {
63 0 : const sal_Int32 nBoundAttr = PropertyAttribute::BOUND;
64 0 : const sal_Int32 nMayBeVoidAttr = PropertyAttribute::MAYBEVOID | nBoundAttr;
65 :
66 0 : const Type& rSalInt32Type = ::getCppuType( static_cast< sal_Int32* >( NULL ) );
67 0 : const Type& rStringType = ::getCppuType( static_cast< OUString* >( NULL ) );
68 :
69 0 : _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_ALIGN, PROPERTY_ID_ALIGN, nMayBeVoidAttr, &m_aAlignment, rSalInt32Type );
70 0 : _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_NUMBERFORMAT, PROPERTY_ID_NUMBERFORMAT, nMayBeVoidAttr, &m_aFormatKey, rSalInt32Type );
71 0 : _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_RELATIVEPOSITION, PROPERTY_ID_RELATIVEPOSITION, nMayBeVoidAttr, &m_aRelativePosition, rSalInt32Type );
72 0 : _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_WIDTH, PROPERTY_ID_WIDTH, nMayBeVoidAttr, &m_aWidth, rSalInt32Type );
73 0 : _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_HELPTEXT, PROPERTY_ID_HELPTEXT, nMayBeVoidAttr, &m_aHelpText, rStringType );
74 0 : _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_CONTROLDEFAULT, PROPERTY_ID_CONTROLDEFAULT, nMayBeVoidAttr, &m_aControlDefault, rStringType );
75 0 : _rPropertyContainer.registerProperty( PROPERTY_CONTROLMODEL, PROPERTY_ID_CONTROLMODEL, nBoundAttr, &m_xControlModel, ::getCppuType( &m_xControlModel ) );
76 0 : _rPropertyContainer.registerProperty( PROPERTY_HIDDEN, PROPERTY_ID_HIDDEN, nBoundAttr, &m_bHidden, ::getCppuType( &m_bHidden ) );
77 0 : }
78 :
79 0 : bool OColumnSettings::isColumnSettingProperty( const sal_Int32 _nPropertyHandle )
80 : {
81 : return ( _nPropertyHandle == PROPERTY_ID_ALIGN )
82 0 : || ( _nPropertyHandle == PROPERTY_ID_NUMBERFORMAT )
83 0 : || ( _nPropertyHandle == PROPERTY_ID_RELATIVEPOSITION )
84 0 : || ( _nPropertyHandle == PROPERTY_ID_WIDTH )
85 0 : || ( _nPropertyHandle == PROPERTY_ID_HELPTEXT )
86 0 : || ( _nPropertyHandle == PROPERTY_ID_CONTROLDEFAULT )
87 0 : || ( _nPropertyHandle == PROPERTY_ID_CONTROLMODEL )
88 0 : || ( _nPropertyHandle == PROPERTY_ID_HIDDEN );
89 : }
90 :
91 0 : bool OColumnSettings::isDefaulted( const sal_Int32 _nPropertyHandle, const Any& _rPropertyValue )
92 : {
93 0 : switch ( _nPropertyHandle )
94 : {
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 0 : return !_rPropertyValue.hasValue();
102 :
103 : case PROPERTY_ID_CONTROLMODEL:
104 0 : return !Reference< XPropertySet >( _rPropertyValue, UNO_QUERY ).is();
105 :
106 : case PROPERTY_ID_HIDDEN:
107 : {
108 0 : sal_Bool bHidden = sal_False;
109 0 : OSL_VERIFY( _rPropertyValue >>= bHidden );
110 0 : return !bHidden;
111 : }
112 : }
113 : OSL_FAIL( "OColumnSettings::isDefaulted: illegal property handle!" );
114 0 : return false;
115 : }
116 :
117 0 : bool OColumnSettings::hasDefaultSettings( const Reference< XPropertySet >& _rxColumn )
118 : {
119 0 : ENSURE_OR_THROW( _rxColumn.is(), "illegal column" );
120 : try
121 : {
122 0 : Reference< XPropertySetInfo > xPSI( _rxColumn->getPropertySetInfo(), UNO_SET_THROW );
123 :
124 0 : struct PropertyDescriptor
125 : {
126 : OUString sName;
127 : sal_Int32 nHandle;
128 : };
129 : PropertyDescriptor aProps[] =
130 : {
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 }
139 0 : };
140 :
141 0 : for ( size_t i=0; i < sizeof( aProps ) / sizeof( aProps[0] ); ++i )
142 : {
143 0 : if ( xPSI->hasPropertyByName( aProps[i].sName ) )
144 0 : if ( !isDefaulted( aProps[i].nHandle, _rxColumn->getPropertyValue( aProps[i].sName ) ) )
145 0 : return false;
146 0 : }
147 : }
148 0 : catch( const Exception& )
149 : {
150 : DBG_UNHANDLED_EXCEPTION();
151 : }
152 0 : return true;
153 : }
154 :
155 : } // namespace dbaccess
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|