xref: /trunk/main/forms/source/component/Columns.hxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _FRM_COLUMNS_HXX
25 #define _FRM_COLUMNS_HXX
26 
27 #include "cloneable.hxx"
28 #include "frm_strings.hxx"
29 
30 /** === begin UNO includes === **/
31 #include <com/sun/star/io/XObjectInputStream.hpp>
32 #include <com/sun/star/io/XObjectOutputStream.hpp>
33 #include <com/sun/star/lang/XUnoTunnel.hpp>
34 #include <com/sun/star/util/XCloneable.hpp>
35 /** === end UNO includes === **/
36 
37 #include <comphelper/broadcasthelper.hxx>
38 #include <comphelper/componentcontext.hxx>
39 #include <comphelper/propagg.hxx>
40 #include <comphelper/proparrhlp.hxx>
41 #include <comphelper/uno3.hxx>
42 #include <cppuhelper/compbase2.hxx>
43 #include <cppuhelper/component.hxx>
44 
45 using namespace comphelper;
46 
47 //.........................................................................
48 namespace frm
49 {
50 //.........................................................................
51 
52 //==================================================================
53 // OGridColumn
54 //==================================================================
55 typedef ::cppu::WeakAggComponentImplHelper2 <   ::com::sun::star::lang::XUnoTunnel
56                                             ,   ::com::sun::star::util::XCloneable > OGridColumn_BASE;
57 class OGridColumn   :public ::comphelper::OBaseMutex
58                     ,public OGridColumn_BASE
59                     ,public OPropertySetAggregationHelper
60                     ,public OCloneableAggregation
61 {
62 protected:
63 // [properties]
64     ::com::sun::star::uno::Any  m_aWidth;                   // column width
65     ::com::sun::star::uno::Any  m_aAlign;                   // column alignment
66     ::com::sun::star::uno::Any  m_aHidden;                  // column hidden?
67 // [properties]
68 
69     ::comphelper::ComponentContext  m_aContext;
70     ::rtl::OUString                 m_aModelName;
71 
72 // [properties]
73     ::rtl::OUString             m_aLabel;                   // Name der Spalte
74 // [properties]
75 
76 public:
77     OGridColumn(const ::comphelper::ComponentContext& _rContext, const ::rtl::OUString& _sModelName = ::rtl::OUString());
78     OGridColumn(const OGridColumn* _pOriginal );
79     virtual ~OGridColumn();
80 
81     // UNO Anbindung
82     DECLARE_UNO3_AGG_DEFAULTS(OGridControlModel, OGridColumn_BASE);
83     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType );
84 
85     static const ::com::sun::star::uno::Sequence<sal_Int8>& getUnoTunnelImplementationId();
86     // XUnoTunnel
87     virtual sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence<sal_Int8>& _rIdentifier);
88 
89     // XTypeProvider
90     virtual ::com::sun::star::uno::Sequence<sal_Int8>           SAL_CALL getImplementationId();
91     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>   SAL_CALL getTypes();
92 
93     // OComponentHelper
94     virtual void SAL_CALL disposing();
95 
96     // XEventListener
97     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource);
98 
99     // XPersistObject
100     virtual void SAL_CALL write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream);
101     virtual void SAL_CALL read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream);
102 
103     // XPropertySet
104     virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper() = 0;
105     virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
106     virtual sal_Bool SAL_CALL convertFastPropertyValue(::com::sun::star::uno::Any& rConvertedValue, ::com::sun::star::uno::Any& rOldValue,
107                                           sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue );
108     virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue);
109 
110     using OPropertySetAggregationHelper::getFastPropertyValue;
111 
112     // ::com::sun::star::beans::XPropertyState
113     virtual ::com::sun::star::uno::Any getPropertyDefaultByHandle( sal_Int32 nHandle ) const;
114 
115     // XCloneable
116     virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone(  );
117 
getModelName() const118     const ::rtl::OUString& getModelName() const { return m_aModelName; }
119 
120 protected:
121     static void clearAggregateProperties(::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property>& seqProps, sal_Bool bAllowDropDown);
122     static void setOwnProperties(::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property>& seqProps);
123 
124     virtual OGridColumn* createCloneColumn() const = 0;
125 };
126 
127 #define DECL_COLUMN(ClassName)                                                                              \
128 class ClassName                                                                                             \
129     :public OGridColumn                                                                                     \
130     ,public OAggregationArrayUsageHelper< ClassName >                                                       \
131 {                                                                                                           \
132 public:                                                                                                     \
133     ClassName(const ::comphelper::ComponentContext& _rContext );                                            \
134     ClassName(const ClassName* _pCloneFrom);                                                                \
135                                                                                                             \
136     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo(); \
137     virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper();                                         \
138                                                                                                             \
139     virtual void fillProperties(                                                                            \
140         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps,          \
141         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps  \
142         ) const;                                                                                            \
143                                                                                                             \
144     virtual OGridColumn* createCloneColumn() const;                                                         \
145 };
146 
147 
148 #define IMPL_COLUMN(ClassName, Model, bAllowDropDown)                               \
149     ClassName::ClassName( const ::comphelper::ComponentContext& _rContext ) \
150     :OGridColumn(_rContext, Model) \
151 { \
152 } \
153 ClassName::ClassName( const ClassName* _pCloneFrom ) \
154     :OGridColumn( _pCloneFrom ) \
155 { \
156 } \
157 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo>  ClassName::getPropertySetInfo() \
158 { \
159     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo>  xInfo( createPropertySetInfo( getInfoHelper() ) ); \
160     return xInfo; \
161 } \
162 ::cppu::IPropertyArrayHelper& ClassName::getInfoHelper() \
163 { \
164     return *const_cast<ClassName*>(this)->getArrayHelper(); \
165 } \
166 void ClassName::fillProperties( \
167     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps, \
168     ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps \
169     ) const \
170 { \
171     if (m_xAggregateSet.is()) \
172     { \
173         _rAggregateProps = m_xAggregateSet->getPropertySetInfo()->getProperties(); \
174         clearAggregateProperties(_rAggregateProps, bAllowDropDown); \
175         setOwnProperties(_rProps); \
176     } \
177 } \
178 OGridColumn* ClassName::createCloneColumn() const \
179 { \
180     return new ClassName( this ); \
181 } \
182  \
183 // column type ids
184 #define TYPE_CHECKBOX       0
185 #define TYPE_COMBOBOX       1
186 #define TYPE_CURRENCYFIELD  2
187 #define TYPE_DATEFIELD      3
188 #define TYPE_FORMATTEDFIELD 4
189 #define TYPE_LISTBOX        5
190 #define TYPE_NUMERICFIELD   6
191 #define TYPE_PATTERNFIELD   7
192 #define TYPE_TEXTFIELD      8
193 #define TYPE_TIMEFIELD      9
194 
195 // liste aller bekannten columns
196 const StringSequence& getColumnTypes();
197 sal_Int32 getColumnTypeByModelName(const ::rtl::OUString& aModelName);
198 
199 // Columns
200 DECL_COLUMN(TextFieldColumn)
201 DECL_COLUMN(PatternFieldColumn)
202 DECL_COLUMN(DateFieldColumn)
203 DECL_COLUMN(TimeFieldColumn)
204 DECL_COLUMN(NumericFieldColumn)
205 DECL_COLUMN(CurrencyFieldColumn)
206 DECL_COLUMN(CheckBoxColumn)
207 DECL_COLUMN(ComboBoxColumn)
208 DECL_COLUMN(ListBoxColumn)
209 DECL_COLUMN(FormattedFieldColumn)
210 
211 #endif // _FRM_COLUMNS_HXX
212 
213 //.........................................................................
214 }   // namespace frm
215 //.........................................................................
216