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 : using ::com::sun::star::uno::Reference;
24 : using ::com::sun::star::lang::XMultiServiceFactory;
25 : using ::com::sun::star::uno::Sequence;
26 : using ::com::sun::star::uno::Type;
27 : using ::com::sun::star::uno::XComponentContext;
28 : using ::com::sun::star::beans::Property;
29 : using ::com::sun::star::uno::Exception;
30 : using ::com::sun::star::uno::XInterface;
31 : using ::com::sun::star::uno::Any;
32 : using ::com::sun::star::uno::makeAny;
33 : using ::com::sun::star::sdbc::XRowSet;
34 : using ::com::sun::star::uno::UNO_QUERY;
35 :
36 : namespace FormComponentType = ::com::sun::star::form::FormComponentType;
37 :
38 : namespace frm
39 : {
40 :
41 7 : OPatternControl::OPatternControl(const Reference<XComponentContext>& _rxFactory)
42 7 : :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD)
43 : {
44 7 : }
45 :
46 :
47 0 : Sequence<Type> OPatternControl::_getTypes()
48 : {
49 0 : return OBoundControl::_getTypes();
50 : }
51 :
52 :
53 1 : StringSequence OPatternControl::getSupportedServiceNames() throw(std::exception)
54 : {
55 1 : StringSequence aSupported = OBoundControl::getSupportedServiceNames();
56 1 : aSupported.realloc(aSupported.getLength() + 2);
57 :
58 1 : OUString*pArray = aSupported.getArray();
59 1 : pArray[aSupported.getLength()-2] = FRM_SUN_CONTROL_PATTERNFIELD;
60 1 : pArray[aSupported.getLength()-1] = STARDIV_ONE_FORM_CONTROL_PATTERNFIELD;
61 1 : return aSupported;
62 : }
63 :
64 :
65 : // OPatternModel
66 :
67 :
68 0 : Sequence<Type> OPatternModel::_getTypes()
69 : {
70 0 : return OEditBaseModel::_getTypes();
71 : }
72 :
73 :
74 :
75 10 : OPatternModel::OPatternModel(const Reference<XComponentContext>& _rxFactory)
76 10 : :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, false, false )
77 : // use the old control name for compytibility reasons
78 : {
79 :
80 10 : m_nClassId = FormComponentType::PATTERNFIELD;
81 10 : initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
82 10 : }
83 :
84 :
85 1 : OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
86 1 : :OEditBaseModel( _pOriginal, _rxFactory )
87 : {
88 1 : }
89 :
90 :
91 22 : OPatternModel::~OPatternModel()
92 : {
93 22 : }
94 :
95 : // XCloneable
96 :
97 1 : IMPLEMENT_DEFAULT_CLONING( OPatternModel )
98 :
99 : // XServiceInfo
100 :
101 9 : StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw(std::exception)
102 : {
103 9 : StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
104 9 : aSupported.realloc(aSupported.getLength() + 3);
105 :
106 9 : OUString*pArray = aSupported.getArray();
107 9 : pArray[aSupported.getLength()-3] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD;
108 9 : pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_PATTERNFIELD;
109 9 : pArray[aSupported.getLength()-1] = FRM_COMPONENT_PATTERNFIELD;
110 9 : return aSupported;
111 : }
112 :
113 :
114 :
115 12 : void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
116 : {
117 12 : BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
118 12 : DECL_PROP2(DEFAULT_TEXT, OUString, BOUND, MAYBEDEFAULT);
119 12 : DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND);
120 12 : DECL_PROP1(TABINDEX, sal_Int16, BOUND);
121 12 : DECL_PROP2(FILTERPROPOSAL, sal_Bool, BOUND, MAYBEDEFAULT);
122 : END_DESCRIBE_PROPERTIES();
123 12 : }
124 :
125 :
126 1 : OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException, std::exception)
127 : {
128 1 : return OUString(FRM_COMPONENT_PATTERNFIELD); // old (non-sun) name for compatibility !
129 : }
130 :
131 :
132 0 : bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
133 : {
134 0 : Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
135 :
136 0 : if ( aNewValue != m_aLastKnownValue )
137 : {
138 0 : OUString sNewValue;
139 0 : aNewValue >>= sNewValue;
140 :
141 0 : if ( !aNewValue.hasValue()
142 0 : || ( sNewValue.isEmpty() // an empty string
143 0 : && m_bEmptyIsNull // which should be interpreted as NULL
144 : )
145 : )
146 : {
147 0 : m_xColumnUpdate->updateNull();
148 : }
149 : else
150 : {
151 : OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" );
152 0 : if ( !m_pFormattedValue.get() )
153 0 : return false;
154 :
155 0 : if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
156 0 : return false;
157 : }
158 :
159 0 : m_aLastKnownValue = aNewValue;
160 : }
161 :
162 0 : return true;
163 : }
164 :
165 :
166 0 : void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
167 : {
168 0 : OEditBaseModel::onConnectedDbColumn( _rxForm );
169 :
170 0 : Reference< XPropertySet > xField( getField() );
171 0 : if ( !xField.is() )
172 0 : return;
173 :
174 0 : m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
175 : }
176 :
177 :
178 0 : void OPatternModel::onDisconnectedDbColumn()
179 : {
180 0 : OEditBaseModel::onDisconnectedDbColumn();
181 0 : m_pFormattedValue.reset();
182 0 : }
183 :
184 : // XPropertyChangeListener
185 :
186 0 : Any OPatternModel::translateDbColumnToControlValue()
187 : {
188 : OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" );
189 :
190 0 : if ( m_pFormattedValue.get() )
191 : {
192 0 : OUString sValue( m_pFormattedValue->getFormattedValue() );
193 0 : if ( sValue.isEmpty()
194 0 : && m_pFormattedValue->getColumn().is()
195 0 : && m_pFormattedValue->getColumn()->wasNull()
196 : )
197 : {
198 0 : m_aLastKnownValue.clear();
199 : }
200 : else
201 : {
202 0 : m_aLastKnownValue <<= sValue;
203 0 : }
204 : }
205 : else
206 0 : m_aLastKnownValue.clear();
207 :
208 0 : return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( OUString() );
209 : // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
210 : }
211 :
212 : // XReset
213 :
214 13 : Any OPatternModel::getDefaultForReset() const
215 : {
216 13 : return makeAny( m_aDefaultText );
217 : }
218 :
219 13 : void OPatternModel::resetNoBroadcast()
220 : {
221 13 : OEditBaseModel::resetNoBroadcast();
222 13 : m_aLastKnownValue.clear();
223 13 : }
224 :
225 : } // namespace frm
226 :
227 : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
228 10 : com_sun_star_form_OPatternModel_get_implementation(::com::sun::star::uno::XComponentContext* component,
229 : ::com::sun::star::uno::Sequence<css::uno::Any> const &)
230 : {
231 10 : return cppu::acquire(new frm::OPatternModel(component));
232 : }
233 :
234 : extern "C" SAL_DLLPUBLIC_EXPORT ::com::sun::star::uno::XInterface* SAL_CALL
235 7 : com_sun_star_form_OPatternControl_get_implementation(::com::sun::star::uno::XComponentContext* component,
236 : ::com::sun::star::uno::Sequence<css::uno::Any> const &)
237 : {
238 7 : return cppu::acquire(new frm::OPatternControl(component));
239 : }
240 :
241 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|