xref: /trunk/main/forms/source/component/ComboBox.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 _FORMS_COMBOBOX_HXX_
25 #define _FORMS_COMBOBOX_HXX_
26 
27 #include "FormComponent.hxx"
28 #include "errorbroadcaster.hxx"
29 #include "entrylisthelper.hxx"
30 #include "cachedrowset.hxx"
31 
32 /** === begin UNO includes === **/
33 #include <com/sun/star/util/XNumberFormatter.hpp>
34 #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
35 #include <com/sun/star/form/ListSourceType.hpp>
36 #include <com/sun/star/awt/XItemListener.hpp>
37 #include <com/sun/star/awt/XFocusListener.hpp>
38 /** === end UNO includes === **/
39 
40 #include <connectivity/formattedcolumnvalue.hxx>
41 
42 #include <cppuhelper/interfacecontainer.hxx>
43 
44 #include <vcl/timer.hxx>
45 
46 #include <tools/date.hxx>
47 
48 //.........................................................................
49 namespace frm
50 {
51 
52 //==================================================================
53 // OComboBoxModel
54 //==================================================================
55 class OComboBoxModel
56             :public OBoundControlModel
57             ,public OEntryListHelper
58             ,public OErrorBroadcaster
59 {
60     CachedRowSet                            m_aListRowSet;          // the row set to fill the list
61     ::com::sun::star::uno::Any              m_aBoundColumn;         // obsolet
62     ::rtl::OUString                         m_aListSource;          //
63     ::rtl::OUString                         m_aDefaultText;         // DefaultText
64     ::com::sun::star::uno::Any              m_aLastKnownValue;
65 
66     StringSequence                          m_aDesignModeStringItems;
67         // upon loading, in some cases we reset fill our string item list ourself. We don't want
68         // to lose the user's items then, so we remember them here.
69 
70 
71     ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter> m_xFormatter;
72 
73     ::com::sun::star::form::ListSourceType  m_eListSourceType;      // type der list source
74     sal_Bool                                m_bEmptyIsNull;         // LeerString wird als NULL interpretiert
75 
76     ::std::auto_ptr< ::dbtools::FormattedColumnValue >
77                                             m_pValueFormatter;
78 
79 
80 
81 protected:
82     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>   _getTypes();
83 
84 public:
85     DECLARE_DEFAULT_LEAF_XTOR( OComboBoxModel );
86 
87     virtual void SAL_CALL disposing();
88 
89     // OPropertySetHelper
90     virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const;
91     virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue );
92     virtual sal_Bool SAL_CALL convertFastPropertyValue(
93                 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue );
94 
95     // XLoadListener
96     virtual void SAL_CALL reloaded( const ::com::sun::star::lang::EventObject& aEvent );
97 
98     // XServiceInfo
99     IMPLEMENTATION_NAME(OComboBoxModel);
100     virtual StringSequence SAL_CALL getSupportedServiceNames();
101 
102     // UNO
103     DECLARE_UNO3_AGG_DEFAULTS(OComboBoxModel, OBoundControlModel);
104     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType );
105 
106     // XPersistObject
107     virtual ::rtl::OUString SAL_CALL    getServiceName();
108     virtual void SAL_CALL
109         write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream);
110     virtual void SAL_CALL
111         read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream);
112 
113     // OControlModel's property handling
114     virtual void describeFixedProperties(
115         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
116     ) const;
117     virtual void describeAggregateProperties(
118         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
119     ) const;
120 
121     // XEventListener
122     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source);
123 
124     // prevent method hiding
125     using OBoundControlModel::getFastPropertyValue;
126 
127 protected:
128     // OBoundControlModel overridables
129     virtual ::com::sun::star::uno::Any
130                             translateDbColumnToControlValue( );
131     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
132 
133     virtual void            onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
134     virtual void            onDisconnectedDbColumn();
135 
136     virtual ::com::sun::star::uno::Any
137                             getDefaultForReset() const;
138 
139     virtual void            resetNoBroadcast();
140 
141     // OEntryListHelper overriables
142     virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock );
143     virtual void    connectedExternalListSource( );
144     virtual void    disconnectedExternalListSource( );
145     virtual void    refreshInternalEntryList();
146 
147 protected:
148     void loadData( bool _bForce );
149 
150     DECLARE_XCLONEABLE();
151 };
152 
153 //==================================================================
154 // OComboBoxControl
155 //==================================================================
156 
157 class OComboBoxControl : public OBoundControl
158 {
159 public:
160     OComboBoxControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
161 
162     // XServiceInfo
163     IMPLEMENTATION_NAME(OComboBoxControl);
164     virtual StringSequence SAL_CALL getSupportedServiceNames();
165 };
166 
167 //.........................................................................
168 }
169 //.........................................................................
170 
171 #endif // _FORMS_COMBOBOX_HXX_
172