Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "Pattern.hxx"
21 : #include "comphelper/processfactory.hxx"
22 :
23 :
24 : namespace frm
25 : {
26 :
27 :
28 : using ::com::sun::star::uno::Reference;
29 : using ::com::sun::star::lang::XMultiServiceFactory;
30 : using ::com::sun::star::uno::Sequence;
31 : using ::com::sun::star::uno::Type;
32 : using ::com::sun::star::uno::XComponentContext;
33 : using ::com::sun::star::beans::Property;
34 : using ::com::sun::star::uno::Exception;
35 : using ::com::sun::star::uno::XInterface;
36 : using ::com::sun::star::uno::Any;
37 : using ::com::sun::star::uno::makeAny;
38 : using ::com::sun::star::sdbc::XRowSet;
39 : using ::com::sun::star::uno::UNO_QUERY;
40 :
41 : namespace FormComponentType = ::com::sun::star::form::FormComponentType;
42 :
43 :
44 : // OPatternControl
45 :
46 :
47 0 : OPatternControl::OPatternControl(const Reference<XComponentContext>& _rxFactory)
48 0 : :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD)
49 : {
50 0 : }
51 :
52 :
53 0 : InterfaceRef SAL_CALL OPatternControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
54 : {
55 0 : return *(new OPatternControl( comphelper::getComponentContext(_rxFactory) ));
56 : }
57 :
58 :
59 0 : Sequence<Type> OPatternControl::_getTypes()
60 : {
61 0 : return OBoundControl::_getTypes();
62 : }
63 :
64 :
65 0 : StringSequence OPatternControl::getSupportedServiceNames() throw(std::exception)
66 : {
67 0 : StringSequence aSupported = OBoundControl::getSupportedServiceNames();
68 0 : aSupported.realloc(aSupported.getLength() + 1);
69 :
70 0 : OUString*pArray = aSupported.getArray();
71 0 : pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_PATTERNFIELD;
72 0 : return aSupported;
73 : }
74 :
75 :
76 : // OPatternModel
77 :
78 :
79 0 : InterfaceRef SAL_CALL OPatternModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
80 : {
81 0 : return *(new OPatternModel( comphelper::getComponentContext(_rxFactory) ));
82 : }
83 :
84 :
85 0 : Sequence<Type> OPatternModel::_getTypes()
86 : {
87 0 : return OEditBaseModel::_getTypes();
88 : }
89 :
90 :
91 :
92 0 : OPatternModel::OPatternModel(const Reference<XComponentContext>& _rxFactory)
93 0 : :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, sal_False, sal_False )
94 : // use the old control name for compytibility reasons
95 : {
96 :
97 0 : m_nClassId = FormComponentType::PATTERNFIELD;
98 0 : initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
99 0 : }
100 :
101 :
102 0 : OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
103 0 : :OEditBaseModel( _pOriginal, _rxFactory )
104 : {
105 0 : }
106 :
107 :
108 0 : OPatternModel::~OPatternModel()
109 : {
110 0 : }
111 :
112 : // XCloneable
113 :
114 0 : IMPLEMENT_DEFAULT_CLONING( OPatternModel )
115 :
116 : // XServiceInfo
117 :
118 0 : StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw(std::exception)
119 : {
120 0 : StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
121 0 : aSupported.realloc(aSupported.getLength() + 2);
122 :
123 0 : OUString*pArray = aSupported.getArray();
124 0 : pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD;
125 0 : pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_PATTERNFIELD;
126 0 : return aSupported;
127 : }
128 :
129 :
130 :
131 0 : void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
132 : {
133 0 : BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
134 0 : DECL_PROP2(DEFAULT_TEXT, OUString, BOUND, MAYBEDEFAULT);
135 0 : DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND);
136 0 : DECL_PROP1(TABINDEX, sal_Int16, BOUND);
137 0 : DECL_PROP2(FILTERPROPOSAL, sal_Bool, BOUND, MAYBEDEFAULT);
138 : END_DESCRIBE_PROPERTIES();
139 0 : }
140 :
141 :
142 0 : OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
143 : {
144 0 : return OUString(FRM_COMPONENT_PATTERNFIELD); // old (non-sun) name for compatibility !
145 : }
146 :
147 :
148 0 : sal_Bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
149 : {
150 0 : Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
151 :
152 0 : if ( aNewValue != m_aLastKnownValue )
153 : {
154 0 : OUString sNewValue;
155 0 : aNewValue >>= sNewValue;
156 :
157 0 : if ( !aNewValue.hasValue()
158 0 : || ( sNewValue.isEmpty() // an empty string
159 0 : && m_bEmptyIsNull // which should be interpreted as NULL
160 : )
161 : )
162 : {
163 0 : m_xColumnUpdate->updateNull();
164 : }
165 : else
166 : {
167 : OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" );
168 0 : if ( !m_pFormattedValue.get() )
169 0 : return sal_False;
170 :
171 0 : if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
172 0 : return sal_False;
173 : }
174 :
175 0 : m_aLastKnownValue = aNewValue;
176 : }
177 :
178 0 : return sal_True;
179 : }
180 :
181 :
182 0 : void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
183 : {
184 0 : OEditBaseModel::onConnectedDbColumn( _rxForm );
185 :
186 0 : Reference< XPropertySet > xField( getField() );
187 0 : if ( !xField.is() )
188 0 : return;
189 :
190 0 : m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
191 : }
192 :
193 :
194 0 : void OPatternModel::onDisconnectedDbColumn()
195 : {
196 0 : OEditBaseModel::onDisconnectedDbColumn();
197 0 : m_pFormattedValue.reset();
198 0 : }
199 :
200 : // XPropertyChangeListener
201 :
202 0 : Any OPatternModel::translateDbColumnToControlValue()
203 : {
204 : OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" );
205 :
206 0 : if ( m_pFormattedValue.get() )
207 : {
208 0 : OUString sValue( m_pFormattedValue->getFormattedValue() );
209 0 : if ( sValue.isEmpty()
210 0 : && m_pFormattedValue->getColumn().is()
211 0 : && m_pFormattedValue->getColumn()->wasNull()
212 : )
213 : {
214 0 : m_aLastKnownValue.clear();
215 : }
216 : else
217 : {
218 0 : m_aLastKnownValue <<= sValue;
219 0 : }
220 : }
221 : else
222 0 : m_aLastKnownValue.clear();
223 :
224 0 : return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( OUString() );
225 : // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
226 : }
227 :
228 : // XReset
229 :
230 0 : Any OPatternModel::getDefaultForReset() const
231 : {
232 0 : return makeAny( m_aDefaultText );
233 : }
234 :
235 :
236 0 : void OPatternModel::resetNoBroadcast()
237 : {
238 0 : OEditBaseModel::resetNoBroadcast();
239 0 : m_aLastKnownValue.clear();
240 0 : }
241 :
242 :
243 : } // namespace frm
244 :
245 :
246 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|