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