1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "columnsettings.hxx"
28cdf0e10cSrcweir #include "dbastrings.hrc"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir /** === begin UNO includes === **/
31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
32cdf0e10cSrcweir /** === end UNO includes === **/
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
35cdf0e10cSrcweir #include <comphelper/property.hxx>
36cdf0e10cSrcweir #include <tools/debug.hxx>
37cdf0e10cSrcweir #include <tools/diagnose_ex.h>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //........................................................................
40cdf0e10cSrcweir namespace dbaccess
41cdf0e10cSrcweir {
42cdf0e10cSrcweir //........................................................................
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	/** === begin UNO using === **/
45cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
46cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
47cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
48cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
49cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
50cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
51cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
52cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
53cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
54cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
55cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
56cdf0e10cSrcweir     using ::com::sun::star::lang::IllegalArgumentException;
57cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySet;
58cdf0e10cSrcweir     using ::com::sun::star::beans::XPropertySetInfo;
59cdf0e10cSrcweir 	/** === end UNO using === **/
60cdf0e10cSrcweir     namespace PropertyAttribute = ::com::sun::star::beans::PropertyAttribute;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir     //==============================================================================
63cdf0e10cSrcweir     //= OColumnSettings
64cdf0e10cSrcweir     //==============================================================================
DBG_NAME(OColumnSettings)65cdf0e10cSrcweir     DBG_NAME( OColumnSettings )
66cdf0e10cSrcweir     //------------------------------------------------------------------------------
67cdf0e10cSrcweir     OColumnSettings::OColumnSettings()
68cdf0e10cSrcweir 	    :m_bHidden(sal_False)
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir 	    DBG_CTOR( OColumnSettings, NULL );
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     //------------------------------------------------------------------------------
~OColumnSettings()74cdf0e10cSrcweir     OColumnSettings::~OColumnSettings()
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir 	    DBG_DTOR( OColumnSettings, NULL );
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     //------------------------------------------------------------------------------
registerProperties(IPropertyContainer & _rPropertyContainer)80cdf0e10cSrcweir     void OColumnSettings::registerProperties( IPropertyContainer& _rPropertyContainer )
81cdf0e10cSrcweir     {
82cdf0e10cSrcweir         const sal_Int32 nBoundAttr = PropertyAttribute::BOUND;
83cdf0e10cSrcweir         const sal_Int32 nMayBeVoidAttr = PropertyAttribute::MAYBEVOID | nBoundAttr;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir         const Type& rSalInt32Type = ::getCppuType( static_cast< sal_Int32* >( NULL ) );
86cdf0e10cSrcweir         const Type& rStringType = ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_ALIGN, PROPERTY_ID_ALIGN, nMayBeVoidAttr, &m_aAlignment, rSalInt32Type );
89cdf0e10cSrcweir         _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_NUMBERFORMAT, PROPERTY_ID_NUMBERFORMAT, nMayBeVoidAttr, &m_aFormatKey, rSalInt32Type );
90cdf0e10cSrcweir         _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_RELATIVEPOSITION, PROPERTY_ID_RELATIVEPOSITION, nMayBeVoidAttr, &m_aRelativePosition, rSalInt32Type );
91cdf0e10cSrcweir         _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_WIDTH, PROPERTY_ID_WIDTH, nMayBeVoidAttr, &m_aWidth, rSalInt32Type );
92cdf0e10cSrcweir         _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_HELPTEXT, PROPERTY_ID_HELPTEXT, nMayBeVoidAttr, &m_aHelpText, rStringType );
93cdf0e10cSrcweir         _rPropertyContainer.registerMayBeVoidProperty( PROPERTY_CONTROLDEFAULT, PROPERTY_ID_CONTROLDEFAULT, nMayBeVoidAttr, &m_aControlDefault, rStringType );
94cdf0e10cSrcweir         _rPropertyContainer.registerProperty( PROPERTY_CONTROLMODEL, PROPERTY_ID_CONTROLMODEL, nBoundAttr, &m_xControlModel, ::getCppuType( &m_xControlModel ) );
95cdf0e10cSrcweir         _rPropertyContainer.registerProperty( PROPERTY_HIDDEN, PROPERTY_ID_HIDDEN, nBoundAttr, &m_bHidden, ::getCppuType( &m_bHidden ) );
96cdf0e10cSrcweir     }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir     //------------------------------------------------------------------------------
isColumnSettingProperty(const sal_Int32 _nPropertyHandle)99cdf0e10cSrcweir     bool OColumnSettings::isColumnSettingProperty( const sal_Int32 _nPropertyHandle )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         return  ( _nPropertyHandle == PROPERTY_ID_ALIGN )
102cdf0e10cSrcweir             ||  ( _nPropertyHandle == PROPERTY_ID_NUMBERFORMAT )
103cdf0e10cSrcweir             ||  ( _nPropertyHandle == PROPERTY_ID_RELATIVEPOSITION )
104cdf0e10cSrcweir             ||  ( _nPropertyHandle == PROPERTY_ID_WIDTH )
105cdf0e10cSrcweir             ||  ( _nPropertyHandle == PROPERTY_ID_HELPTEXT )
106cdf0e10cSrcweir             ||  ( _nPropertyHandle == PROPERTY_ID_CONTROLDEFAULT )
107cdf0e10cSrcweir             ||  ( _nPropertyHandle == PROPERTY_ID_CONTROLMODEL )
108cdf0e10cSrcweir             ||  ( _nPropertyHandle == PROPERTY_ID_HIDDEN );
109cdf0e10cSrcweir     }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     //------------------------------------------------------------------------------
isDefaulted(const sal_Int32 _nPropertyHandle,const Any & _rPropertyValue)112cdf0e10cSrcweir     bool OColumnSettings::isDefaulted( const sal_Int32 _nPropertyHandle, const Any& _rPropertyValue )
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         switch ( _nPropertyHandle )
115cdf0e10cSrcweir         {
116cdf0e10cSrcweir         case PROPERTY_ID_ALIGN:
117cdf0e10cSrcweir         case PROPERTY_ID_NUMBERFORMAT:
118cdf0e10cSrcweir         case PROPERTY_ID_RELATIVEPOSITION:
119cdf0e10cSrcweir         case PROPERTY_ID_WIDTH:
120cdf0e10cSrcweir         case PROPERTY_ID_HELPTEXT:
121cdf0e10cSrcweir         case PROPERTY_ID_CONTROLDEFAULT:
122cdf0e10cSrcweir             return !_rPropertyValue.hasValue();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         case PROPERTY_ID_CONTROLMODEL:
125cdf0e10cSrcweir             return !Reference< XPropertySet >( _rPropertyValue, UNO_QUERY ).is();
126cdf0e10cSrcweir 
127cdf0e10cSrcweir         case PROPERTY_ID_HIDDEN:
128cdf0e10cSrcweir             {
129cdf0e10cSrcweir                 sal_Bool bHidden = sal_False;
130cdf0e10cSrcweir                 OSL_VERIFY( _rPropertyValue >>= bHidden );
131cdf0e10cSrcweir                 return !bHidden;
132cdf0e10cSrcweir             }
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir         OSL_ENSURE( false, "OColumnSettings::isDefaulted: illegal property handle!" );
135cdf0e10cSrcweir         return sal_False;
136cdf0e10cSrcweir     }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir     //------------------------------------------------------------------------------
hasDefaultSettings(const Reference<XPropertySet> & _rxColumn)139cdf0e10cSrcweir     bool OColumnSettings::hasDefaultSettings( const Reference< XPropertySet >& _rxColumn )
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         ENSURE_OR_THROW( _rxColumn.is(), "illegal column" );
142cdf0e10cSrcweir         try
143cdf0e10cSrcweir         {
144cdf0e10cSrcweir             Reference< XPropertySetInfo > xPSI( _rxColumn->getPropertySetInfo(), UNO_SET_THROW );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir             struct PropertyDescriptor
147cdf0e10cSrcweir             {
148cdf0e10cSrcweir                 ::rtl::OUString sName;
149cdf0e10cSrcweir                 sal_Int32       nHandle;
150cdf0e10cSrcweir             };
151cdf0e10cSrcweir             PropertyDescriptor aProps[] =
152cdf0e10cSrcweir             {
153cdf0e10cSrcweir                 { PROPERTY_ALIGN,            PROPERTY_ID_ALIGN },
154cdf0e10cSrcweir                 { PROPERTY_NUMBERFORMAT,     PROPERTY_ID_NUMBERFORMAT },
155cdf0e10cSrcweir                 { PROPERTY_RELATIVEPOSITION, PROPERTY_ID_RELATIVEPOSITION },
156cdf0e10cSrcweir                 { PROPERTY_WIDTH,            PROPERTY_ID_WIDTH },
157cdf0e10cSrcweir                 { PROPERTY_HELPTEXT,         PROPERTY_ID_HELPTEXT },
158cdf0e10cSrcweir                 { PROPERTY_CONTROLDEFAULT,   PROPERTY_ID_CONTROLDEFAULT },
159cdf0e10cSrcweir                 { PROPERTY_CONTROLMODEL,     PROPERTY_ID_CONTROLMODEL },
160cdf0e10cSrcweir                 { PROPERTY_HIDDEN,           PROPERTY_ID_HIDDEN }
161cdf0e10cSrcweir             };
162cdf0e10cSrcweir 
163cdf0e10cSrcweir             for ( size_t i=0; i < sizeof( aProps ) / sizeof( aProps[0] ); ++i )
164cdf0e10cSrcweir             {
165cdf0e10cSrcweir                 if ( xPSI->hasPropertyByName( aProps[i].sName ) )
166cdf0e10cSrcweir                     if ( !isDefaulted( aProps[i].nHandle, _rxColumn->getPropertyValue( aProps[i].sName ) ) )
167cdf0e10cSrcweir                         return false;
168cdf0e10cSrcweir             }
169cdf0e10cSrcweir         }
170cdf0e10cSrcweir         catch( const Exception& )
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
173cdf0e10cSrcweir         }
174cdf0e10cSrcweir         return true;
175cdf0e10cSrcweir     }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir //........................................................................
178cdf0e10cSrcweir } // namespace dbaccess
179cdf0e10cSrcweir //........................................................................
180