xref: /trunk/main/forms/source/component/FormattedField.hxx (revision 9d37da743abb7db0a497688391f6e55a19f27c44)
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 _FORMS_FORMATTEDFIELD_HXX_
25 #define _FORMS_FORMATTEDFIELD_HXX_
26 
27 #include "EditBase.hxx"
28 #include <comphelper/propmultiplex.hxx>
29 #include <cppuhelper/implbase1.hxx>
30 #include "errorbroadcaster.hxx"
31 
32 //.........................................................................
33 namespace frm
34 {
35 
36     //==================================================================
37     //= OFormattedModel
38     //==================================================================
39 
40     class OFormattedModel
41                     :public OEditBaseModel
42                     ,public OErrorBroadcaster
43     {
44         // das Original, falls ich die Format-Properties meines aggregierten Models gefaket, d.h. von dem Feld, an das
45         // ich gebunden bin, weitergereicht habe (nur gueltig wenn loaded)
46         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier>   m_xOriginalFormatter;
47         ::com::sun::star::util::Date        m_aNullDate;
48         ::com::sun::star::uno::Any          m_aSaveValue;
49 
50         sal_Int32                           m_nFieldType;
51         sal_Int16                           m_nKeyType;
52         sal_Bool                            m_bOriginalNumeric      : 1,
53                                             m_bNumeric              : 1;    // analog fuer TreatAsNumeric-Property
54 
55     protected:
56         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier>  calcDefaultFormatsSupplier() const;
57         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier>  calcFormFormatsSupplier() const;
58         ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier>  calcFormatsSupplier() const;
59 
60         DECLARE_DEFAULT_LEAF_XTOR( OFormattedModel );
61 
62         friend class OFormattedFieldWrapper;
63 
64     protected:
65     // XInterface
66         DECLARE_UNO3_AGG_DEFAULTS( OFormattedModel, OEditBaseModel );
67 
68     // XTypeProvider
69         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
70 
71     // XAggregation
72         virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType);
73 
74     // OComponentHelper
75         virtual void SAL_CALL disposing();
76 
77     // XServiceInfo
78         IMPLEMENTATION_NAME(OFormattedModel);
79         virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
80 
81     // XPersistObject
82         virtual void SAL_CALL write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream);
83         virtual void SAL_CALL read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream);
84         virtual ::rtl::OUString SAL_CALL getServiceName();
85 
86     // XPropertySet
87         virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const;
88         virtual sal_Bool SAL_CALL convertFastPropertyValue(::com::sun::star::uno::Any& rConvertedValue, ::com::sun::star::uno::Any& rOldValue,
89                                               sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue );
90         virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue);
91 
92     // XLoadListener
93         virtual void SAL_CALL loaded(const ::com::sun::star::lang::EventObject& rEvent);
94 
95     // XPropertyState
96         void setPropertyToDefaultByHandle(sal_Int32 nHandle);
97         ::com::sun::star::uno::Any getPropertyDefaultByHandle(sal_Int32 nHandle) const;
98 
99         void SAL_CALL setPropertyToDefault(const ::rtl::OUString& aPropertyName);
100         ::com::sun::star::uno::Any SAL_CALL getPropertyDefault( const ::rtl::OUString& aPropertyName );
101 
102         // OControlModel's property handling
103         virtual void describeFixedProperties(
104             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
105         ) const;
106         virtual void describeAggregateProperties(
107             ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
108         ) const;
109 
110     // XPropertyChangeListener
111         virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent& evt);
112 
113     // prevent method hiding
114         using OEditBaseModel::disposing;
115         using OEditBaseModel::getFastPropertyValue;
116 
117     protected:
118         virtual sal_uInt16 getPersistenceFlags() const;
119             // as we have an own version handling for persistence
120 
121         // OBoundControlModel overridables
122         virtual ::com::sun::star::uno::Any
123                             translateDbColumnToControlValue( );
124         virtual sal_Bool    commitControlValueToDbColumn( bool _bPostReset );
125 
126         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
127                             getSupportedBindingTypes();
128         virtual ::com::sun::star::uno::Any
129                             translateExternalValueToControlValue( const ::com::sun::star::uno::Any& _rExternalValue ) const;
130         virtual ::com::sun::star::uno::Any
131                             translateControlValueToExternalValue( ) const;
132         virtual void onConnectedExternalValue( );
133 
134         virtual ::com::sun::star::uno::Any
135                             getDefaultForReset() const;
136         virtual void        resetNoBroadcast();
137 
138         virtual void        onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
139         virtual void        onDisconnectedDbColumn();
140 
141     private:
142         DECLARE_XCLONEABLE();
143 
144         void implConstruct();
145 
146         void    updateFormatterNullDate();
147     };
148 
149     //==================================================================
150     //= OFormattedControl
151     //==================================================================
152     typedef ::cppu::ImplHelper1< ::com::sun::star::awt::XKeyListener> OFormattedControl_BASE;
153     class OFormattedControl :    public OBoundControl
154                                 ,public OFormattedControl_BASE
155     {
156         sal_uInt32              m_nKeyEvent;
157 
158     public:
159         OFormattedControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
160         virtual ~OFormattedControl();
161 
162         DECLARE_UNO3_AGG_DEFAULTS(OFormattedControl, OBoundControl);
163         virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation(const ::com::sun::star::uno::Type& _rType);
164 
165         virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> _getTypes();
166 
167     // ::com::sun::star::lang::XServiceInfo
168         IMPLEMENTATION_NAME(OFormattedControl);
169         virtual StringSequence SAL_CALL getSupportedServiceNames() throw();
170 
171     // ::com::sun::star::lang::XEventListener
172         virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource);
173 
174     // ::com::sun::star::awt::XKeyListener
175         virtual void SAL_CALL keyPressed(const ::com::sun::star::awt::KeyEvent& e);
176         virtual void SAL_CALL keyReleased(const ::com::sun::star::awt::KeyEvent& e);
177 
178     // ::com::sun::star::awt::XControl
179         virtual void SAL_CALL setDesignMode(sal_Bool bOn);
180 
181     // disambiguation
182         using OBoundControl::disposing;
183 
184     private:
185         DECL_LINK( OnKeyPressed, void* );
186     };
187 
188 //.........................................................................
189 }
190 //.........................................................................
191 
192 #endif // _FORMS_FORMATTEDFIELD_HXX_
193