1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "columnsettings.hxx"
22 #include "dbastrings.hrc"
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <cppuhelper/typeprovider.hxx>
27 #include <comphelper/property.hxx>
28 #include <tools/debug.hxx>
29 #include <tools/diagnose_ex.h>
31 //........................................................................
34 //........................................................................
36 /** === begin UNO using === **/
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::uno::XInterface
;
39 using ::com::sun::star::uno::UNO_QUERY
;
40 using ::com::sun::star::uno::UNO_QUERY_THROW
;
41 using ::com::sun::star::uno::UNO_SET_THROW
;
42 using ::com::sun::star::uno::Exception
;
43 using ::com::sun::star::uno::RuntimeException
;
44 using ::com::sun::star::uno::Any
;
45 using ::com::sun::star::uno::makeAny
;
46 using ::com::sun::star::uno::Sequence
;
47 using ::com::sun::star::uno::Type
;
48 using ::com::sun::star::lang::IllegalArgumentException
;
49 using ::com::sun::star::beans::XPropertySet
;
50 using ::com::sun::star::beans::XPropertySetInfo
;
51 /** === end UNO using === **/
52 namespace PropertyAttribute
= ::com::sun::star::beans::PropertyAttribute
;
54 //==============================================================================
56 //==============================================================================
57 DBG_NAME( OColumnSettings
)
59 OColumnSettings::OColumnSettings()
62 DBG_CTOR( OColumnSettings
, NULL
);
65 OColumnSettings::~OColumnSettings()
67 DBG_DTOR( OColumnSettings
, NULL
);
70 void OColumnSettings::registerProperties( IPropertyContainer
& _rPropertyContainer
)
72 const sal_Int32 nBoundAttr
= PropertyAttribute::BOUND
;
73 const sal_Int32 nMayBeVoidAttr
= PropertyAttribute::MAYBEVOID
| nBoundAttr
;
75 const Type
& rSalInt32Type
= ::getCppuType( static_cast< sal_Int32
* >( NULL
) );
76 const Type
& rStringType
= ::getCppuType( static_cast< ::rtl::OUString
* >( NULL
) );
78 _rPropertyContainer
.registerMayBeVoidProperty( PROPERTY_ALIGN
, PROPERTY_ID_ALIGN
, nMayBeVoidAttr
, &m_aAlignment
, rSalInt32Type
);
79 _rPropertyContainer
.registerMayBeVoidProperty( PROPERTY_NUMBERFORMAT
, PROPERTY_ID_NUMBERFORMAT
, nMayBeVoidAttr
, &m_aFormatKey
, rSalInt32Type
);
80 _rPropertyContainer
.registerMayBeVoidProperty( PROPERTY_RELATIVEPOSITION
, PROPERTY_ID_RELATIVEPOSITION
, nMayBeVoidAttr
, &m_aRelativePosition
, rSalInt32Type
);
81 _rPropertyContainer
.registerMayBeVoidProperty( PROPERTY_WIDTH
, PROPERTY_ID_WIDTH
, nMayBeVoidAttr
, &m_aWidth
, rSalInt32Type
);
82 _rPropertyContainer
.registerMayBeVoidProperty( PROPERTY_HELPTEXT
, PROPERTY_ID_HELPTEXT
, nMayBeVoidAttr
, &m_aHelpText
, rStringType
);
83 _rPropertyContainer
.registerMayBeVoidProperty( PROPERTY_CONTROLDEFAULT
, PROPERTY_ID_CONTROLDEFAULT
, nMayBeVoidAttr
, &m_aControlDefault
, rStringType
);
84 _rPropertyContainer
.registerProperty( PROPERTY_CONTROLMODEL
, PROPERTY_ID_CONTROLMODEL
, nBoundAttr
, &m_xControlModel
, ::getCppuType( &m_xControlModel
) );
85 _rPropertyContainer
.registerProperty( PROPERTY_HIDDEN
, PROPERTY_ID_HIDDEN
, nBoundAttr
, &m_bHidden
, ::getCppuType( &m_bHidden
) );
88 bool OColumnSettings::isColumnSettingProperty( const sal_Int32 _nPropertyHandle
)
90 return ( _nPropertyHandle
== PROPERTY_ID_ALIGN
)
91 || ( _nPropertyHandle
== PROPERTY_ID_NUMBERFORMAT
)
92 || ( _nPropertyHandle
== PROPERTY_ID_RELATIVEPOSITION
)
93 || ( _nPropertyHandle
== PROPERTY_ID_WIDTH
)
94 || ( _nPropertyHandle
== PROPERTY_ID_HELPTEXT
)
95 || ( _nPropertyHandle
== PROPERTY_ID_CONTROLDEFAULT
)
96 || ( _nPropertyHandle
== PROPERTY_ID_CONTROLMODEL
)
97 || ( _nPropertyHandle
== PROPERTY_ID_HIDDEN
);
100 bool OColumnSettings::isDefaulted( const sal_Int32 _nPropertyHandle
, const Any
& _rPropertyValue
)
102 switch ( _nPropertyHandle
)
104 case PROPERTY_ID_ALIGN
:
105 case PROPERTY_ID_NUMBERFORMAT
:
106 case PROPERTY_ID_RELATIVEPOSITION
:
107 case PROPERTY_ID_WIDTH
:
108 case PROPERTY_ID_HELPTEXT
:
109 case PROPERTY_ID_CONTROLDEFAULT
:
110 return !_rPropertyValue
.hasValue();
112 case PROPERTY_ID_CONTROLMODEL
:
113 return !Reference
< XPropertySet
>( _rPropertyValue
, UNO_QUERY
).is();
115 case PROPERTY_ID_HIDDEN
:
117 sal_Bool bHidden
= sal_False
;
118 OSL_VERIFY( _rPropertyValue
>>= bHidden
);
122 OSL_FAIL( "OColumnSettings::isDefaulted: illegal property handle!" );
126 bool OColumnSettings::hasDefaultSettings( const Reference
< XPropertySet
>& _rxColumn
)
128 ENSURE_OR_THROW( _rxColumn
.is(), "illegal column" );
131 Reference
< XPropertySetInfo
> xPSI( _rxColumn
->getPropertySetInfo(), UNO_SET_THROW
);
133 struct PropertyDescriptor
135 ::rtl::OUString sName
;
138 PropertyDescriptor aProps
[] =
140 { PROPERTY_ALIGN
, PROPERTY_ID_ALIGN
},
141 { PROPERTY_NUMBERFORMAT
, PROPERTY_ID_NUMBERFORMAT
},
142 { PROPERTY_RELATIVEPOSITION
, PROPERTY_ID_RELATIVEPOSITION
},
143 { PROPERTY_WIDTH
, PROPERTY_ID_WIDTH
},
144 { PROPERTY_HELPTEXT
, PROPERTY_ID_HELPTEXT
},
145 { PROPERTY_CONTROLDEFAULT
, PROPERTY_ID_CONTROLDEFAULT
},
146 { PROPERTY_CONTROLMODEL
, PROPERTY_ID_CONTROLMODEL
},
147 { PROPERTY_HIDDEN
, PROPERTY_ID_HIDDEN
}
150 for ( size_t i
=0; i
< sizeof( aProps
) / sizeof( aProps
[0] ); ++i
)
152 if ( xPSI
->hasPropertyByName( aProps
[i
].sName
) )
153 if ( !isDefaulted( aProps
[i
].nHandle
, _rxColumn
->getPropertyValue( aProps
[i
].sName
) ) )
157 catch( const Exception
& )
159 DBG_UNHANDLED_EXCEPTION();
164 //........................................................................
165 } // namespace dbaccess
166 //........................................................................
168 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */