1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _FORMS_COMBOBOX_HXX_
29 #define _FORMS_COMBOBOX_HXX_
30 
31 #include "FormComponent.hxx"
32 #include "errorbroadcaster.hxx"
33 #include "entrylisthelper.hxx"
34 #include "cachedrowset.hxx"
35 
36 /** === begin UNO includes === **/
37 #include <com/sun/star/util/XNumberFormatter.hpp>
38 #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
39 #include <com/sun/star/form/ListSourceType.hpp>
40 #include <com/sun/star/awt/XItemListener.hpp>
41 #include <com/sun/star/awt/XFocusListener.hpp>
42 /** === end UNO includes === **/
43 
44 #include <connectivity/formattedcolumnvalue.hxx>
45 
46 #include <cppuhelper/interfacecontainer.hxx>
47 
48 #include <vcl/timer.hxx>
49 
50 #include <tools/date.hxx>
51 
52 //.........................................................................
53 namespace frm
54 {
55 
56 //==================================================================
57 // OComboBoxModel
58 //==================================================================
59 class OComboBoxModel
60 			:public OBoundControlModel
61             ,public OEntryListHelper
62 			,public OErrorBroadcaster
63 {
64     CachedRowSet                            m_aListRowSet;          // the row set to fill the list
65 	::com::sun::star::uno::Any				m_aBoundColumn; 		// obsolet
66 	::rtl::OUString 						m_aListSource;			//
67 	::rtl::OUString 						m_aDefaultText; 		// DefaultText
68     ::com::sun::star::uno::Any              m_aLastKnownValue;
69 
70 	StringSequence							m_aDesignModeStringItems;
71 		// upon loading, in some cases we reset fill our string item list ourself. We don't want
72 		// to lose the user's items then, so we remember them here.
73 
74 
75 	::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatter> m_xFormatter;
76 
77 	::com::sun::star::form::ListSourceType	m_eListSourceType;		// type der list source
78 	sal_Bool								m_bEmptyIsNull; 		// LeerString wird als NULL interpretiert
79 
80     ::std::auto_ptr< ::dbtools::FormattedColumnValue >
81                                             m_pValueFormatter;
82 
83 
84 
85 protected:
86 	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>	_getTypes();
87 
88 public:
89 	DECLARE_DEFAULT_LEAF_XTOR( OComboBoxModel );
90 
91 	virtual void SAL_CALL disposing();
92 
93 	// OPropertySetHelper
94 	virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const;
95 	virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
96 				throw (::com::sun::star::uno::Exception);
97 	virtual sal_Bool SAL_CALL convertFastPropertyValue(
98 				::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
99 				throw (::com::sun::star::lang::IllegalArgumentException);
100 
101 	// XLoadListener
102 	virtual void SAL_CALL reloaded( const ::com::sun::star::lang::EventObject& aEvent ) throw(::com::sun::star::uno::RuntimeException);
103 
104 	// XServiceInfo
105 	IMPLEMENTATION_NAME(OComboBoxModel);
106 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
107 
108 	// UNO
109 	DECLARE_UNO3_AGG_DEFAULTS(OComboBoxModel, OBoundControlModel);
110 	virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
111 
112 	// XPersistObject
113 	virtual ::rtl::OUString SAL_CALL	getServiceName() throw(::com::sun::star::uno::RuntimeException);
114 	virtual void SAL_CALL
115 		write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
116 	virtual void SAL_CALL
117 		read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
118 
119     // OControlModel's property handling
120 	virtual void describeFixedProperties(
121 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
122     ) const;
123     virtual void describeAggregateProperties(
124 		::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
125     ) const;
126 
127     // XEventListener
128 	virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
129 
130     // prevent method hiding
131     using OBoundControlModel::getFastPropertyValue;
132 
133 protected:
134     // OBoundControlModel overridables
135     virtual ::com::sun::star::uno::Any
136                             translateDbColumnToControlValue( );
137     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
138 
139 	virtual void		    onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
140 	virtual void		    onDisconnectedDbColumn();
141 
142     virtual ::com::sun::star::uno::Any
143                             getDefaultForReset() const;
144 
145 	virtual void            resetNoBroadcast();
146 
147     // OEntryListHelper overriables
148     virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock );
149     virtual void    connectedExternalListSource( );
150     virtual void    disconnectedExternalListSource( );
151     virtual void    refreshInternalEntryList();
152 
153 protected:
154     void loadData( bool _bForce );
155 
156 	DECLARE_XCLONEABLE();
157 };
158 
159 //==================================================================
160 // OComboBoxControl
161 //==================================================================
162 
163 class OComboBoxControl : public OBoundControl
164 {
165 public:
166 	OComboBoxControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
167 
168 	// XServiceInfo
169 	IMPLEMENTATION_NAME(OComboBoxControl);
170 	virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
171 };
172 
173 //.........................................................................
174 }
175 //.........................................................................
176 
177 #endif // _FORMS_COMBOBOX_HXX_
178 
179