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 6 : OPatternControl::OPatternControl(const Reference<XComponentContext>& _rxFactory)
48 6 : :OBoundControl(_rxFactory, VCL_CONTROL_PATTERNFIELD)
49 : {
50 6 : }
51 :
52 : //------------------------------------------------------------------
53 6 : InterfaceRef SAL_CALL OPatternControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
54 : {
55 6 : 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()
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 9 : InterfaceRef SAL_CALL OPatternModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
80 : {
81 9 : return *(new OPatternModel( comphelper::getComponentContext(_rxFactory) ));
82 : }
83 :
84 : //------------------------------------------------------------------------------
85 2 : Sequence<Type> OPatternModel::_getTypes()
86 : {
87 2 : return OEditBaseModel::_getTypes();
88 : }
89 :
90 : //------------------------------------------------------------------
91 : DBG_NAME( OPatternModel )
92 : //------------------------------------------------------------------
93 9 : OPatternModel::OPatternModel(const Reference<XComponentContext>& _rxFactory)
94 9 : :OEditBaseModel( _rxFactory, VCL_CONTROLMODEL_PATTERNFIELD, FRM_SUN_CONTROL_PATTERNFIELD, sal_False, sal_False )
95 : // use the old control name for compytibility reasons
96 : {
97 : DBG_CTOR( OPatternModel, NULL );
98 :
99 9 : m_nClassId = FormComponentType::PATTERNFIELD;
100 9 : initValueProperty( PROPERTY_TEXT, PROPERTY_ID_TEXT );
101 9 : }
102 :
103 : //------------------------------------------------------------------
104 1 : OPatternModel::OPatternModel( const OPatternModel* _pOriginal, const Reference<XComponentContext>& _rxFactory )
105 1 : :OEditBaseModel( _pOriginal, _rxFactory )
106 : {
107 : DBG_CTOR( OPatternModel, NULL );
108 1 : }
109 :
110 : //------------------------------------------------------------------
111 20 : OPatternModel::~OPatternModel()
112 : {
113 : DBG_DTOR( OPatternModel, NULL );
114 20 : }
115 :
116 : // XCloneable
117 : //------------------------------------------------------------------------------
118 1 : IMPLEMENT_DEFAULT_CLONING( OPatternModel )
119 :
120 : // XServiceInfo
121 : //------------------------------------------------------------------------------
122 8 : StringSequence SAL_CALL OPatternModel::getSupportedServiceNames() throw()
123 : {
124 8 : StringSequence aSupported = OBoundControlModel::getSupportedServiceNames();
125 8 : aSupported.realloc(aSupported.getLength() + 2);
126 :
127 8 : OUString*pArray = aSupported.getArray();
128 8 : pArray[aSupported.getLength()-2] = FRM_SUN_COMPONENT_DATABASE_PATTERNFIELD;
129 8 : pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_PATTERNFIELD;
130 8 : return aSupported;
131 : }
132 :
133 :
134 : //------------------------------------------------------------------------------
135 11 : void OPatternModel::describeFixedProperties( Sequence< Property >& _rProps ) const
136 : {
137 11 : BEGIN_DESCRIBE_PROPERTIES( 4, OEditBaseModel )
138 11 : DECL_PROP2(DEFAULT_TEXT, OUString, BOUND, MAYBEDEFAULT);
139 11 : DECL_BOOL_PROP1(EMPTY_IS_NULL, BOUND);
140 11 : DECL_PROP1(TABINDEX, sal_Int16, BOUND);
141 11 : DECL_PROP2(FILTERPROPOSAL, sal_Bool, BOUND, MAYBEDEFAULT);
142 : END_DESCRIBE_PROPERTIES();
143 11 : }
144 :
145 : //------------------------------------------------------------------------------
146 1 : OUString SAL_CALL OPatternModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
147 : {
148 1 : return OUString(FRM_COMPONENT_PATTERNFIELD); // old (non-sun) name for compatibility !
149 : }
150 :
151 : //------------------------------------------------------------------------------
152 0 : sal_Bool OPatternModel::commitControlValueToDbColumn( bool /*_bPostReset*/ )
153 : {
154 0 : Any aNewValue( m_xAggregateFastSet->getFastPropertyValue( getValuePropertyAggHandle() ) );
155 :
156 0 : if ( aNewValue != m_aLastKnownValue )
157 : {
158 0 : OUString sNewValue;
159 0 : aNewValue >>= sNewValue;
160 :
161 0 : if ( !aNewValue.hasValue()
162 0 : || ( sNewValue.isEmpty() // an empty string
163 0 : && m_bEmptyIsNull // which should be interpreted as NULL
164 : )
165 : )
166 : {
167 0 : m_xColumnUpdate->updateNull();
168 : }
169 : else
170 : {
171 : OSL_ENSURE( m_pFormattedValue.get(), "OPatternModel::commitControlValueToDbColumn: no value helper!" );
172 0 : if ( !m_pFormattedValue.get() )
173 0 : return sal_False;
174 :
175 0 : if ( !m_pFormattedValue->setFormattedValue( sNewValue ) )
176 0 : return sal_False;
177 : }
178 :
179 0 : m_aLastKnownValue = aNewValue;
180 : }
181 :
182 0 : return sal_True;
183 : }
184 :
185 : //------------------------------------------------------------------------------
186 0 : void OPatternModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm )
187 : {
188 0 : OEditBaseModel::onConnectedDbColumn( _rxForm );
189 :
190 0 : Reference< XPropertySet > xField( getField() );
191 0 : if ( !xField.is() )
192 0 : return;
193 :
194 0 : m_pFormattedValue.reset( new ::dbtools::FormattedColumnValue( getContext(), Reference< XRowSet >( _rxForm, UNO_QUERY ), xField ) );
195 : }
196 :
197 : //------------------------------------------------------------------------------
198 0 : void OPatternModel::onDisconnectedDbColumn()
199 : {
200 0 : OEditBaseModel::onDisconnectedDbColumn();
201 0 : m_pFormattedValue.reset();
202 0 : }
203 :
204 : // XPropertyChangeListener
205 : //------------------------------------------------------------------------------
206 0 : Any OPatternModel::translateDbColumnToControlValue()
207 : {
208 : OSL_PRECOND( m_pFormattedValue.get(), "OPatternModel::translateDbColumnToControlValue: no value helper!" );
209 :
210 0 : if ( m_pFormattedValue.get() )
211 : {
212 0 : OUString sValue( m_pFormattedValue->getFormattedValue() );
213 0 : if ( sValue.isEmpty()
214 0 : && m_pFormattedValue->getColumn().is()
215 0 : && m_pFormattedValue->getColumn()->wasNull()
216 : )
217 : {
218 0 : m_aLastKnownValue.clear();
219 : }
220 : else
221 : {
222 0 : m_aLastKnownValue <<= sValue;
223 0 : }
224 : }
225 : else
226 0 : m_aLastKnownValue.clear();
227 :
228 0 : return m_aLastKnownValue.hasValue() ? m_aLastKnownValue : makeAny( OUString() );
229 : // (m_aLastKnownValue is alllowed to be VOID, the control value isn't)
230 : }
231 :
232 : // XReset
233 : //------------------------------------------------------------------------------
234 12 : Any OPatternModel::getDefaultForReset() const
235 : {
236 12 : return makeAny( m_aDefaultText );
237 : }
238 :
239 : //------------------------------------------------------------------------------
240 12 : void OPatternModel::resetNoBroadcast()
241 : {
242 12 : OEditBaseModel::resetNoBroadcast();
243 12 : m_aLastKnownValue.clear();
244 12 : }
245 :
246 : //.........................................................................
247 : } // namespace frm
248 : //.........................................................................
249 :
250 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|