Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "Pattern.hxx"
30 : :
31 : : //.........................................................................
32 : : namespace frm
33 : : {
34 : : //.........................................................................
35 : :
36 : : /** === begin UNO using === **/
37 : : using ::com::sun::star::uno::Reference;
38 : : using ::com::sun::star::lang::XMultiServiceFactory;
39 : : using ::com::sun::star::uno::Sequence;
40 : : using ::com::sun::star::uno::Type;
41 : : using ::com::sun::star::beans::Property;
42 : : using ::com::sun::star::uno::Exception;
43 : : using ::com::sun::star::uno::XInterface;
44 : : using ::com::sun::star::uno::Any;
45 : : using ::com::sun::star::uno::makeAny;
46 : : using ::com::sun::star::sdbc::XRowSet;
47 : : using ::com::sun::star::uno::UNO_QUERY;
48 : : /** === end UNO using === **/
49 : : namespace FormComponentType = ::com::sun::star::form::FormComponentType;
50 : :
51 : : //==================================================================
52 : : // OPatternControl
53 : : //==================================================================
54 : : //------------------------------------------------------------------
55 : 12 : OPatternControl::OPatternControl(const Reference<XMultiServiceFactory>& _rxFactory)
56 [ + - ]: 12 : :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD)
57 : : {
58 : 12 : }
59 : :
60 : : //------------------------------------------------------------------
61 : 12 : InterfaceRef SAL_CALL OPatternControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
62 : : {
63 [ + - ]: 12 : return *(new OPatternControl(_rxFactory));
64 : : }
65 : :
66 : : //------------------------------------------------------------------------------
67 : 0 : Sequence<Type> OPatternControl::_getTypes()
68 : : {
69 : 0 : return OBoundControl::_getTypes();
70 : : }
71 : :
72 : : //------------------------------------------------------------------------------
73 : 0 : StringSequence OPatternControl::getSupportedServiceNames() throw()
74 : : {
75 : 0 : StringSequence aSupported = OBoundControl::getSupportedServiceNames();
76 [ # # ]: 0 : aSupported.realloc(aSupported.getLength() + 1);
77 : :
78 [ # # ]: 0 : ::rtl::OUString*pArray = aSupported.getArray();
79 [ # # ]: 0 : pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_PATTERNFIELD;
80 : 0 : return aSupported;
81 : : }
82 : :
83 : : //==================================================================
84 : : // OPatternModel
85 : : //==================================================================
86 : : //------------------------------------------------------------------
87 : 17 : InterfaceRef SAL_CALL OPatternModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
88 : : {
89 [ + - ]: 17 : return *(new OPatternModel(_rxFactory));
90 : : }
91 : :
92 : : //------------------------------------------------------------------------------
93 : 4 : Sequence<Type> OPatternModel::_getTypes()
94 : : {
95 : 4 : return OEditBaseModel::_getTypes();
96 : : }
97 : :
98 : : //------------------------------------------------------------------
99 : : DBG_NAME( OPatternModel )
100 : : //------------------------------------------------------------------
101 : 17 : OPatternModel::OPatternModel(const Reference<XMultiServiceFactory>& _rxFactory)
102 [ + - ][ + - ]: 17 : :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, sal_False, sal_False )
103 : : // use the old control name for compytibility reasons
104 : : {
105 : : DBG_CTOR( OPatternModel, NULL );
106 : :
107 : 17 : m_nClassId = FormComponentType::PATTERNFIELD;
108 [ + - ][ + - ]: 17 : initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
109 : 17 : }
110 : :
111 : : //------------------------------------------------------------------
112 : 2 : OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
113 : 2 : :OEditBaseModel( _pOriginal, _rxFactory )
114 : : {
115 : : DBG_CTOR( OPatternModel, NULL );
116 : 2 : }
117 : :
118 : : //------------------------------------------------------------------
119 [ + - ]: 19 : OPatternModel::~OPatternModel()
120 : : {
121 : : DBG_DTOR( OPatternModel, NULL );
122 [ - + ]: 38 : }
123 : :
124 : : // XCloneable
125 : : //------------------------------------------------------------------------------
126 [ + - ][ + - ]: 2 : IMPLEMENT_DEFAULT_CLONING( OPatternModel )
127 : :
128 : : // XServiceInfo
129 : : //------------------------------------------------------------------------------
130 : 16 : StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw()
131 : : {
132 : 16 : StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
133 [ + - ]: 16 : aSupported.realloc(aSupported.getLength() + 2);
134 : :
135 [ + - ]: 16 : ::rtl::OUString*pArray = aSupported.getArray();
136 [ + - ]: 16 : pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD;
137 [ + - ]: 16 : pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_PATTERNFIELD;
138 : 16 : return aSupported;
139 : : }
140 : :
141 : :
142 : : //------------------------------------------------------------------------------
143 : 21 : void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
144 : : {
145 : 21 : BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
146 [ + - ][ + - ]: 21 : DECL_PROP2(DEFAULT_TEXT, ::rtl::OUString, BOUND, MAYBEDEFAULT);
147 [ + - ]: 21 : DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND);
148 [ + - ]: 21 : DECL_PROP1(TABINDEX, sal_Int16, BOUND);
149 [ + - ][ + - ]: 21 : DECL_PROP2(FILTERPROPOSAL, sal_Bool, BOUND, MAYBEDEFAULT);
150 : : END_DESCRIBE_PROPERTIES();
151 : 21 : }
152 : :
153 : : //------------------------------------------------------------------------------
154 : 2 : ::rtl::OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
155 : : {
156 : 2 : return FRM_COMPONENT_PATTERNFIELD; // old (non-sun) name for compatibility !
157 : : }
158 : :
159 : : //------------------------------------------------------------------------------
160 : 0 : sal_Bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
161 : : {
162 [ # # ][ # # ]: 0 : Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
163 : :
164 [ # # ]: 0 : if ( aNewValue != m_aLastKnownValue )
165 : : {
166 : 0 : ::rtl::OUString sNewValue;
167 : 0 : aNewValue >>= sNewValue;
168 : :
169 [ # # ][ # # ]: 0 : if ( !aNewValue.hasValue()
[ # # # # ]
170 : 0 : || ( sNewValue.isEmpty() // an empty string
171 : : && m_bEmptyIsNull // which should be interpreted as NULL
172 : : )
173 : : )
174 : : {
175 [ # # ][ # # ]: 0 : m_xColumnUpdate->updateNull();
176 : : }
177 : : else
178 : : {
179 : : OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" );
180 [ # # ]: 0 : if ( !m_pFormattedValue.get() )
181 : 0 : return sal_False;
182 : :
183 [ # # ][ # # ]: 0 : if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
184 : 0 : return sal_False;
185 : : }
186 : :
187 [ # # ]: 0 : m_aLastKnownValue = aNewValue;
188 : : }
189 : :
190 : 0 : return sal_True;
191 : : }
192 : :
193 : : //------------------------------------------------------------------------------
194 : 0 : void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
195 : : {
196 [ # # ]: 0 : OEditBaseModel::onConnectedDbColumn( _rxForm );
197 : :
198 : 0 : Reference< XPropertySet > xField( getField() );
199 [ # # ]: 0 : if ( !xField.is() )
200 : 0 : return;
201 : :
202 [ # # ][ # # ]: 0 : m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
[ # # ][ # # ]
203 : : }
204 : :
205 : : //------------------------------------------------------------------------------
206 : 0 : void OPatternModel::onDisconnectedDbColumn()
207 : : {
208 : 0 : OEditBaseModel::onDisconnectedDbColumn();
209 : 0 : m_pFormattedValue.reset();
210 : 0 : }
211 : :
212 : : // XPropertyChangeListener
213 : : //------------------------------------------------------------------------------
214 : 0 : Any OPatternModel::translateDbColumnToControlValue()
215 : : {
216 : : OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" );
217 : :
218 [ # # ]: 0 : if ( m_pFormattedValue.get() )
219 : : {
220 [ # # ]: 0 : ::rtl::OUString sValue( m_pFormattedValue->getFormattedValue() );
221 [ # # # # ]: 0 : if ( sValue.isEmpty()
[ # # ][ # # ]
222 [ # # ]: 0 : && m_pFormattedValue->getColumn().is()
223 [ # # ][ # # ]: 0 : && m_pFormattedValue->getColumn()->wasNull()
[ # # ]
224 : : )
225 : : {
226 : 0 : m_aLastKnownValue.clear();
227 : : }
228 : : else
229 : : {
230 [ # # ]: 0 : m_aLastKnownValue <<= sValue;
231 : 0 : }
232 : : }
233 : : else
234 : 0 : m_aLastKnownValue.clear();
235 : :
236 [ # # ][ # # ]: 0 : return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( ::rtl::OUString() );
[ # # ][ # # ]
237 : : // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
238 : : }
239 : :
240 : : // XReset
241 : : //------------------------------------------------------------------------------
242 : 24 : Any OPatternModel::getDefaultForReset() const
243 : : {
244 : 24 : return makeAny( m_aDefaultText );
245 : : }
246 : :
247 : : //------------------------------------------------------------------------------
248 : 24 : void OPatternModel::resetNoBroadcast()
249 : : {
250 : 24 : OEditBaseModel::resetNoBroadcast();
251 : 24 : m_aLastKnownValue.clear();
252 : 24 : }
253 : :
254 : : //.........................................................................
255 : : } // namespace frm
256 : : //.........................................................................
257 : :
258 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|