1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5f6e50924SAndrew Rist * distributed with this work for additional information
6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10f6e50924SAndrew Rist *
11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist *
13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist * software distributed under the License is distributed on an
15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17f6e50924SAndrew Rist * specific language governing permissions and limitations
18f6e50924SAndrew Rist * under the License.
19f6e50924SAndrew Rist *
20f6e50924SAndrew Rist *************************************************************/
21f6e50924SAndrew Rist
22f6e50924SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "fmprop.hrc"
29cdf0e10cSrcweir #include "svx/fmresids.hrc"
30cdf0e10cSrcweir #include "svx/fmtools.hxx"
31cdf0e10cSrcweir #include "gridcell.hxx"
32cdf0e10cSrcweir #include "gridcols.hxx"
33cdf0e10cSrcweir #include "sdbdatacolumn.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <com/sun/star/awt/LineEndFormat.hpp>
36cdf0e10cSrcweir #include <com/sun/star/awt/MouseWheelBehavior.hpp>
37cdf0e10cSrcweir #include <com/sun/star/awt/VisualEffect.hpp>
38cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
39cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
40cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp>
41cdf0e10cSrcweir #include <com/sun/star/form/XBoundComponent.hpp>
42cdf0e10cSrcweir #include <com/sun/star/script/XEventAttacherManager.hpp>
43cdf0e10cSrcweir #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
44cdf0e10cSrcweir #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
45cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
46cdf0e10cSrcweir #include <com/sun/star/sdbc/ColumnValue.hpp>
47cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp>
48cdf0e10cSrcweir #include <com/sun/star/sdbc/XStatement.hpp>
49cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
50cdf0e10cSrcweir #include <com/sun/star/util/NumberFormat.hpp>
51cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
52cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatter.hpp>
53cdf0e10cSrcweir
54cdf0e10cSrcweir #include <comphelper/extract.hxx>
55cdf0e10cSrcweir #include <comphelper/numbers.hxx>
56cdf0e10cSrcweir #include <comphelper/property.hxx>
57cdf0e10cSrcweir #include <connectivity/formattedcolumnvalue.hxx>
58cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
59cdf0e10cSrcweir #include <i18npool/lang.h>
60cdf0e10cSrcweir
61cdf0e10cSrcweir #include <rtl/math.hxx>
62cdf0e10cSrcweir #include <svtools/calendar.hxx>
63cdf0e10cSrcweir #include <svtools/fmtfield.hxx>
64cdf0e10cSrcweir #include <svl/numuno.hxx>
65cdf0e10cSrcweir #include <svtools/svmedit.hxx>
66cdf0e10cSrcweir #include <svx/dialmgr.hxx>
67cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
68cdf0e10cSrcweir #include <tools/diagnose_ex.h>
69cdf0e10cSrcweir #include <tools/shl.hxx>
70cdf0e10cSrcweir #include <vcl/longcurr.hxx>
71cdf0e10cSrcweir
72cdf0e10cSrcweir #include <math.h>
73cdf0e10cSrcweir #include <stdio.h>
74cdf0e10cSrcweir
75cdf0e10cSrcweir using namespace ::connectivity;
76cdf0e10cSrcweir using namespace ::connectivity::simple;
77cdf0e10cSrcweir using namespace ::svxform;
78cdf0e10cSrcweir using namespace ::comphelper;
79cdf0e10cSrcweir using namespace ::svt;
80cdf0e10cSrcweir using namespace ::com::sun::star;
81cdf0e10cSrcweir using namespace ::com::sun::star::uno;
82cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
83cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
84cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
85cdf0e10cSrcweir using namespace ::com::sun::star::beans;
86cdf0e10cSrcweir using namespace ::com::sun::star::form;
87cdf0e10cSrcweir
88cdf0e10cSrcweir using ::com::sun::star::util::XNumberFormatter;
89cdf0e10cSrcweir namespace MouseWheelBehavior = ::com::sun::star::awt::MouseWheelBehavior;
90cdf0e10cSrcweir
91cdf0e10cSrcweir String INVALIDTEXT = String::CreateFromAscii("###");
92cdf0e10cSrcweir String OBJECTTEXT = String::CreateFromAscii("<OBJECT>");
93cdf0e10cSrcweir // TODO: resource
94cdf0e10cSrcweir
95cdf0e10cSrcweir //==================================================================
96cdf0e10cSrcweir //= helper
97cdf0e10cSrcweir //==================================================================
98cdf0e10cSrcweir namespace
99cdf0e10cSrcweir {
getModelLineEndSetting(const Reference<XPropertySet> & _rxModel)100cdf0e10cSrcweir static LineEnd getModelLineEndSetting( const Reference< XPropertySet >& _rxModel )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir LineEnd eFormat = LINEEND_LF;
103cdf0e10cSrcweir
104cdf0e10cSrcweir try
105cdf0e10cSrcweir {
106cdf0e10cSrcweir sal_Int16 nLineEndFormat = awt::LineEndFormat::LINE_FEED;
107cdf0e10cSrcweir
108cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI;
109cdf0e10cSrcweir if ( _rxModel.is() )
110cdf0e10cSrcweir xPSI = _rxModel->getPropertySetInfo();
111cdf0e10cSrcweir
112cdf0e10cSrcweir OSL_ENSURE( xPSI.is(), "getModelLineEndSetting: invalid column model!" );
113cdf0e10cSrcweir if ( xPSI.is() && xPSI->hasPropertyByName( FM_PROP_LINEENDFORMAT ) )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir OSL_VERIFY( _rxModel->getPropertyValue( FM_PROP_LINEENDFORMAT ) >>= nLineEndFormat );
116cdf0e10cSrcweir
117cdf0e10cSrcweir switch ( nLineEndFormat )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir case awt::LineEndFormat::CARRIAGE_RETURN: eFormat = LINEEND_CR; break;
120cdf0e10cSrcweir case awt::LineEndFormat::LINE_FEED: eFormat = LINEEND_LF; break;
121cdf0e10cSrcweir case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED: eFormat = LINEEND_CRLF; break;
122cdf0e10cSrcweir default:
123cdf0e10cSrcweir OSL_ENSURE( sal_False, "getModelLineEndSetting: what's this?" );
124cdf0e10cSrcweir }
125cdf0e10cSrcweir }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir catch( const Exception& )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir OSL_ENSURE( sal_False, "getModelLineEndSetting: caught an exception!" );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir return eFormat;
132cdf0e10cSrcweir }
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
135cdf0e10cSrcweir //==================================================================
136cdf0e10cSrcweir //= DbGridColumn
137cdf0e10cSrcweir //==================================================================
138cdf0e10cSrcweir //------------------------------------------------------------------------------
139cdf0e10cSrcweir CellControllerRef DbGridColumn::s_xEmptyController;
140cdf0e10cSrcweir
141cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateControl(sal_Int32 _nFieldPos,const Reference<::com::sun::star::beans::XPropertySet> & xField,sal_Int32 nTypeId)142cdf0e10cSrcweir void DbGridColumn::CreateControl(sal_Int32 _nFieldPos, const Reference< ::com::sun::star::beans::XPropertySet >& xField, sal_Int32 nTypeId)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir Clear();
145cdf0e10cSrcweir
146cdf0e10cSrcweir m_nTypeId = (sal_Int16)nTypeId;
147cdf0e10cSrcweir if (xField != m_xField)
148cdf0e10cSrcweir {
149cdf0e10cSrcweir // Grundeinstellung
150cdf0e10cSrcweir m_xField = xField;
151cdf0e10cSrcweir xField->getPropertyValue(FM_PROP_FORMATKEY) >>= m_nFormatKey;
152cdf0e10cSrcweir m_nFieldPos = (sal_Int16)_nFieldPos;
153cdf0e10cSrcweir m_bReadOnly = ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_ISREADONLY));
154cdf0e10cSrcweir m_bAutoValue = ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_AUTOINCREMENT));
155cdf0e10cSrcweir m_nFieldType = (sal_Int16)::comphelper::getINT32(xField->getPropertyValue(FM_PROP_FIELDTYPE));
156cdf0e10cSrcweir
157cdf0e10cSrcweir switch (m_nFieldType)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir case DataType::DATE:
160cdf0e10cSrcweir case DataType::TIME:
161cdf0e10cSrcweir case DataType::TIMESTAMP:
162cdf0e10cSrcweir m_bDateTime = sal_True;
163cdf0e10cSrcweir
164cdf0e10cSrcweir case DataType::BIT:
165cdf0e10cSrcweir case DataType::BOOLEAN:
166cdf0e10cSrcweir case DataType::TINYINT:
167cdf0e10cSrcweir case DataType::SMALLINT:
168cdf0e10cSrcweir case DataType::INTEGER:
169cdf0e10cSrcweir case DataType::BIGINT:
170cdf0e10cSrcweir case DataType::FLOAT:
171cdf0e10cSrcweir case DataType::REAL:
172cdf0e10cSrcweir case DataType::DOUBLE:
173cdf0e10cSrcweir case DataType::NUMERIC:
174cdf0e10cSrcweir case DataType::DECIMAL:
175cdf0e10cSrcweir m_nAlign = ::com::sun::star::awt::TextAlign::RIGHT;
176cdf0e10cSrcweir m_bNumeric = sal_True;
177cdf0e10cSrcweir break;
178cdf0e10cSrcweir default:
179cdf0e10cSrcweir m_nAlign = ::com::sun::star::awt::TextAlign::LEFT;
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
184cdf0e10cSrcweir DbCellControl* pCellControl = NULL;
185cdf0e10cSrcweir if (m_rParent.IsFilterMode())
186cdf0e10cSrcweir {
187cdf0e10cSrcweir pCellControl = new DbFilterField(m_rParent.getServiceManager(),*this);
188cdf0e10cSrcweir }
189cdf0e10cSrcweir else
190cdf0e10cSrcweir {
191cdf0e10cSrcweir
192cdf0e10cSrcweir switch (nTypeId)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir case TYPE_CHECKBOX: pCellControl = new DbCheckBox(*this); break;
195cdf0e10cSrcweir case TYPE_COMBOBOX: pCellControl = new DbComboBox(*this); break;
196cdf0e10cSrcweir case TYPE_CURRENCYFIELD: pCellControl = new DbCurrencyField(*this); break;
197cdf0e10cSrcweir case TYPE_DATEFIELD: pCellControl = new DbDateField(*this); break;
198cdf0e10cSrcweir case TYPE_LISTBOX: pCellControl = new DbListBox(*this); break;
199cdf0e10cSrcweir case TYPE_NUMERICFIELD: pCellControl = new DbNumericField(*this); break;
200cdf0e10cSrcweir case TYPE_PATTERNFIELD: pCellControl = new DbPatternField( *this, ::comphelper::ComponentContext( m_rParent.getServiceManager() ) ); break;
201cdf0e10cSrcweir case TYPE_TEXTFIELD: pCellControl = new DbTextField(*this); break;
202cdf0e10cSrcweir case TYPE_TIMEFIELD: pCellControl = new DbTimeField(*this); break;
203cdf0e10cSrcweir case TYPE_FORMATTEDFIELD: pCellControl = new DbFormattedField(*this); break;
204cdf0e10cSrcweir default:
205cdf0e10cSrcweir DBG_ERROR("DbGridColumn::CreateControl: Unknown Column");
206cdf0e10cSrcweir return;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir }
210cdf0e10cSrcweir Reference< XRowSet > xCur;
211cdf0e10cSrcweir if (m_rParent.getDataSource())
212cdf0e10cSrcweir xCur = Reference< XRowSet > ((Reference< XInterface >)*m_rParent.getDataSource(), UNO_QUERY);
213cdf0e10cSrcweir // TODO : the cursor wrapper should use an XRowSet interface, too
214cdf0e10cSrcweir
215cdf0e10cSrcweir pCellControl->Init( m_rParent.GetDataWindow(), xCur );
216cdf0e10cSrcweir
217cdf0e10cSrcweir // now create the control wrapper
218cdf0e10cSrcweir if (m_rParent.IsFilterMode())
219cdf0e10cSrcweir m_pCell = new FmXFilterCell(this, pCellControl);
220cdf0e10cSrcweir else
221cdf0e10cSrcweir {
222cdf0e10cSrcweir switch (nTypeId)
223cdf0e10cSrcweir {
224cdf0e10cSrcweir case TYPE_CHECKBOX: m_pCell = new FmXCheckBoxCell( this, *pCellControl ); break;
225cdf0e10cSrcweir case TYPE_LISTBOX: m_pCell = new FmXListBoxCell( this, *pCellControl ); break;
226cdf0e10cSrcweir case TYPE_COMBOBOX: m_pCell = new FmXComboBoxCell( this, *pCellControl ); break;
227cdf0e10cSrcweir default:
228cdf0e10cSrcweir m_pCell = new FmXEditCell( this, *pCellControl );
229cdf0e10cSrcweir }
230cdf0e10cSrcweir }
231cdf0e10cSrcweir m_pCell->acquire();
232cdf0e10cSrcweir m_pCell->init();
233cdf0e10cSrcweir
234cdf0e10cSrcweir impl_toggleScriptManager_nothrow( true );
235cdf0e10cSrcweir
236cdf0e10cSrcweir // only if we use have a bound field, we use a a controller for displaying the
237cdf0e10cSrcweir // window in the grid
238cdf0e10cSrcweir if (m_xField.is())
239cdf0e10cSrcweir m_xController = pCellControl->CreateController();
240cdf0e10cSrcweir }
241cdf0e10cSrcweir
242cdf0e10cSrcweir //------------------------------------------------------------------------------
impl_toggleScriptManager_nothrow(bool _bAttach)243cdf0e10cSrcweir void DbGridColumn::impl_toggleScriptManager_nothrow( bool _bAttach )
244cdf0e10cSrcweir {
245cdf0e10cSrcweir try
246cdf0e10cSrcweir {
247cdf0e10cSrcweir Reference< container::XChild > xChild( m_xModel, UNO_QUERY_THROW );
248cdf0e10cSrcweir Reference< script::XEventAttacherManager > xManager( xChild->getParent(), UNO_QUERY_THROW );
249cdf0e10cSrcweir Reference< container::XIndexAccess > xContainer( xChild->getParent(), UNO_QUERY_THROW );
250cdf0e10cSrcweir
251cdf0e10cSrcweir sal_Int32 nIndexInParent( getElementPos( xContainer, m_xModel ) );
252cdf0e10cSrcweir
253cdf0e10cSrcweir Reference< XInterface > xCellInterface( *m_pCell, UNO_QUERY );
254cdf0e10cSrcweir if ( _bAttach )
255cdf0e10cSrcweir xManager->attach( nIndexInParent, xCellInterface, makeAny( xCellInterface ) );
256cdf0e10cSrcweir else
257cdf0e10cSrcweir xManager->detach( nIndexInParent, xCellInterface );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir catch( const Exception& )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
262cdf0e10cSrcweir }
263cdf0e10cSrcweir }
264cdf0e10cSrcweir
265cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const DbGridRow * pRow,const Reference<XNumberFormatter> & xFormatter)266cdf0e10cSrcweir void DbGridColumn::UpdateFromField(const DbGridRow* pRow, const Reference< XNumberFormatter >& xFormatter)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir if (m_pCell && m_pCell->ISA(FmXFilterCell))
269cdf0e10cSrcweir PTR_CAST(FmXFilterCell, m_pCell)->Update();
270cdf0e10cSrcweir else if (pRow && pRow->IsValid() && m_nFieldPos >= 0 && m_pCell && pRow->HasField(m_nFieldPos))
271cdf0e10cSrcweir {
272cdf0e10cSrcweir PTR_CAST(FmXDataCell, m_pCell)->UpdateFromField( pRow->GetField( m_nFieldPos ).getColumn(), xFormatter );
273cdf0e10cSrcweir }
274cdf0e10cSrcweir }
275cdf0e10cSrcweir
276cdf0e10cSrcweir //------------------------------------------------------------------------------
Commit()277cdf0e10cSrcweir sal_Bool DbGridColumn::Commit()
278cdf0e10cSrcweir {
279cdf0e10cSrcweir sal_Bool bResult = sal_True;
280cdf0e10cSrcweir if (!m_bInSave && m_pCell)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir m_bInSave = sal_True;
283cdf0e10cSrcweir bResult = m_pCell->Commit();
284cdf0e10cSrcweir
285cdf0e10cSrcweir // store the data into the model
286cdf0e10cSrcweir FmXDataCell* pDataCell = PTR_CAST(FmXDataCell, m_pCell);
287cdf0e10cSrcweir if (bResult && pDataCell)
288cdf0e10cSrcweir {
289cdf0e10cSrcweir Reference< ::com::sun::star::form::XBoundComponent > xComp(m_xModel, UNO_QUERY);
290cdf0e10cSrcweir if (xComp.is())
291cdf0e10cSrcweir bResult = xComp->commit();
292cdf0e10cSrcweir }
293cdf0e10cSrcweir m_bInSave = sal_False;
294cdf0e10cSrcweir }
295cdf0e10cSrcweir return bResult;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir
298cdf0e10cSrcweir //------------------------------------------------------------------------------
~DbGridColumn()299cdf0e10cSrcweir DbGridColumn::~DbGridColumn()
300cdf0e10cSrcweir {
301cdf0e10cSrcweir Clear();
302cdf0e10cSrcweir }
303cdf0e10cSrcweir
304cdf0e10cSrcweir //------------------------------------------------------------------------------
setModel(::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> _xModel)305cdf0e10cSrcweir void DbGridColumn::setModel(::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > _xModel)
306cdf0e10cSrcweir {
307cdf0e10cSrcweir if ( m_pCell )
308cdf0e10cSrcweir impl_toggleScriptManager_nothrow( false );
309cdf0e10cSrcweir
310cdf0e10cSrcweir m_xModel = _xModel;
311cdf0e10cSrcweir
312cdf0e10cSrcweir if ( m_pCell )
313cdf0e10cSrcweir impl_toggleScriptManager_nothrow( true );
314cdf0e10cSrcweir }
315cdf0e10cSrcweir
316cdf0e10cSrcweir //------------------------------------------------------------------------------
Clear()317cdf0e10cSrcweir void DbGridColumn::Clear()
318cdf0e10cSrcweir {
319cdf0e10cSrcweir if ( m_pCell )
320cdf0e10cSrcweir {
321cdf0e10cSrcweir impl_toggleScriptManager_nothrow( false );
322cdf0e10cSrcweir
323cdf0e10cSrcweir m_pCell->dispose();
324cdf0e10cSrcweir m_pCell->release();
325cdf0e10cSrcweir m_pCell = NULL;
326cdf0e10cSrcweir }
327cdf0e10cSrcweir
328cdf0e10cSrcweir m_xController = NULL;
329cdf0e10cSrcweir m_xField = NULL;
330cdf0e10cSrcweir
331cdf0e10cSrcweir m_nFormatKey = 0;
332cdf0e10cSrcweir m_nFieldPos = -1;
333cdf0e10cSrcweir m_bReadOnly = sal_True;
334cdf0e10cSrcweir m_bAutoValue = sal_False;
335cdf0e10cSrcweir m_nFieldType = DataType::OTHER;
336cdf0e10cSrcweir }
337cdf0e10cSrcweir
338cdf0e10cSrcweir //------------------------------------------------------------------------------
SetAlignment(sal_Int16 _nAlign)339cdf0e10cSrcweir sal_Int16 DbGridColumn::SetAlignment(sal_Int16 _nAlign)
340cdf0e10cSrcweir {
341cdf0e10cSrcweir if (_nAlign == -1)
342cdf0e10cSrcweir { // 'Standard'
343cdf0e10cSrcweir if (m_xField.is())
344cdf0e10cSrcweir {
345cdf0e10cSrcweir sal_Int32 nType = 0;
346cdf0e10cSrcweir m_xField->getPropertyValue(FM_PROP_FIELDTYPE) >>= nType;
347cdf0e10cSrcweir
348cdf0e10cSrcweir switch (nType)
349cdf0e10cSrcweir {
350cdf0e10cSrcweir case DataType::NUMERIC:
351cdf0e10cSrcweir case DataType::DECIMAL:
352cdf0e10cSrcweir case DataType::DOUBLE:
353cdf0e10cSrcweir case DataType::REAL:
354cdf0e10cSrcweir case DataType::BIGINT:
355cdf0e10cSrcweir case DataType::INTEGER:
356cdf0e10cSrcweir case DataType::SMALLINT:
357cdf0e10cSrcweir case DataType::TINYINT:
358cdf0e10cSrcweir case DataType::DATE:
359cdf0e10cSrcweir case DataType::TIME:
360cdf0e10cSrcweir case DataType::TIMESTAMP:
361cdf0e10cSrcweir _nAlign = ::com::sun::star::awt::TextAlign::RIGHT;
362cdf0e10cSrcweir break;
363cdf0e10cSrcweir case DataType::BIT:
364cdf0e10cSrcweir case DataType::BOOLEAN:
365cdf0e10cSrcweir _nAlign = ::com::sun::star::awt::TextAlign::CENTER;
366cdf0e10cSrcweir break;
367cdf0e10cSrcweir default:
368cdf0e10cSrcweir _nAlign = ::com::sun::star::awt::TextAlign::LEFT;
369cdf0e10cSrcweir break;
370cdf0e10cSrcweir }
371cdf0e10cSrcweir }
372cdf0e10cSrcweir else
373cdf0e10cSrcweir _nAlign = ::com::sun::star::awt::TextAlign::LEFT;
374cdf0e10cSrcweir }
375cdf0e10cSrcweir
376cdf0e10cSrcweir m_nAlign = _nAlign;
377cdf0e10cSrcweir if (m_pCell && m_pCell->isAlignedController())
378cdf0e10cSrcweir m_pCell->AlignControl(m_nAlign);
379cdf0e10cSrcweir
380cdf0e10cSrcweir return m_nAlign;
381cdf0e10cSrcweir }
382cdf0e10cSrcweir
383cdf0e10cSrcweir //------------------------------------------------------------------------------
SetAlignmentFromModel(sal_Int16 nStandardAlign)384cdf0e10cSrcweir sal_Int16 DbGridColumn::SetAlignmentFromModel(sal_Int16 nStandardAlign)
385cdf0e10cSrcweir {
386cdf0e10cSrcweir Any aAlign( m_xModel->getPropertyValue(FM_PROP_ALIGN));
387cdf0e10cSrcweir if (aAlign.hasValue())
388cdf0e10cSrcweir {
389cdf0e10cSrcweir sal_Int16 nTest = sal_Int16();
390cdf0e10cSrcweir if (aAlign >>= nTest)
391cdf0e10cSrcweir nStandardAlign = nTest;
392cdf0e10cSrcweir }
393cdf0e10cSrcweir return SetAlignment(nStandardAlign);
394cdf0e10cSrcweir }
395cdf0e10cSrcweir
396cdf0e10cSrcweir //------------------------------------------------------------------------------
setLock(sal_Bool _bLock)397cdf0e10cSrcweir void DbGridColumn::setLock(sal_Bool _bLock)
398cdf0e10cSrcweir {
399cdf0e10cSrcweir if (m_bLocked == _bLock)
400cdf0e10cSrcweir return;
401cdf0e10cSrcweir m_bLocked = _bLock;
402cdf0e10cSrcweir
403cdf0e10cSrcweir // is the column we represent active ?
404cdf0e10cSrcweir if (m_bHidden)
405cdf0e10cSrcweir return; // no, it isn't (or at least it shouldn't be ...)
406cdf0e10cSrcweir
407cdf0e10cSrcweir if (m_rParent.GetCurColumnId() == m_nId)
408cdf0e10cSrcweir {
409cdf0e10cSrcweir m_rParent.DeactivateCell();
410cdf0e10cSrcweir m_rParent.ActivateCell(m_rParent.GetCurRow(), m_rParent.GetCurColumnId());
411cdf0e10cSrcweir }
412cdf0e10cSrcweir }
413cdf0e10cSrcweir
414cdf0e10cSrcweir //------------------------------------------------------------------------------
GetCellText(const DbGridRow * pRow,const Reference<XNumberFormatter> & xFormatter) const415cdf0e10cSrcweir String DbGridColumn::GetCellText(const DbGridRow* pRow, const Reference< XNumberFormatter >& xFormatter) const
416cdf0e10cSrcweir {
417cdf0e10cSrcweir String aText;
418cdf0e10cSrcweir if (m_pCell && m_pCell->ISA(FmXFilterCell))
419cdf0e10cSrcweir return aText;
420cdf0e10cSrcweir
421cdf0e10cSrcweir if (!pRow || !pRow->IsValid())
422cdf0e10cSrcweir aText = INVALIDTEXT;
423cdf0e10cSrcweir else if (pRow->HasField(m_nFieldPos))
424cdf0e10cSrcweir {
425cdf0e10cSrcweir aText = GetCellText( pRow->GetField( m_nFieldPos ).getColumn(), xFormatter );
426cdf0e10cSrcweir }
427cdf0e10cSrcweir return aText;
428cdf0e10cSrcweir }
429cdf0e10cSrcweir
430cdf0e10cSrcweir //------------------------------------------------------------------------------
GetCellText(const Reference<::com::sun::star::sdb::XColumn> & xField,const Reference<XNumberFormatter> & xFormatter) const431cdf0e10cSrcweir String DbGridColumn::GetCellText(const Reference< ::com::sun::star::sdb::XColumn >& xField, const Reference< XNumberFormatter >& xFormatter) const
432cdf0e10cSrcweir {
433cdf0e10cSrcweir String aText;
434cdf0e10cSrcweir if (xField.is())
435cdf0e10cSrcweir {
436cdf0e10cSrcweir FmXTextCell* pTextCell = PTR_CAST(FmXTextCell, m_pCell);
437cdf0e10cSrcweir if (pTextCell)
438cdf0e10cSrcweir aText = pTextCell->GetText(xField, xFormatter);
439cdf0e10cSrcweir else if (m_bObject)
440cdf0e10cSrcweir aText = OBJECTTEXT;
441cdf0e10cSrcweir }
442cdf0e10cSrcweir return aText;
443cdf0e10cSrcweir }
444cdf0e10cSrcweir
445cdf0e10cSrcweir //------------------------------------------------------------------------------
GetCurrentFieldValue() const446cdf0e10cSrcweir Reference< ::com::sun::star::sdb::XColumn > DbGridColumn::GetCurrentFieldValue() const
447cdf0e10cSrcweir {
448cdf0e10cSrcweir Reference< ::com::sun::star::sdb::XColumn > xField;
449cdf0e10cSrcweir const DbGridRowRef xRow = m_rParent.GetCurrentRow();
450cdf0e10cSrcweir if (xRow.Is() && xRow->HasField(m_nFieldPos))
451cdf0e10cSrcweir {
452cdf0e10cSrcweir xField = xRow->GetField(m_nFieldPos).getColumn();
453cdf0e10cSrcweir }
454cdf0e10cSrcweir return xField;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir
457cdf0e10cSrcweir //------------------------------------------------------------------------------
Paint(OutputDevice & rDev,const Rectangle & rRect,const DbGridRow * pRow,const Reference<XNumberFormatter> & xFormatter)458cdf0e10cSrcweir void DbGridColumn::Paint(OutputDevice& rDev,
459cdf0e10cSrcweir const Rectangle& rRect,
460cdf0e10cSrcweir const DbGridRow* pRow,
461cdf0e10cSrcweir const Reference< XNumberFormatter >& xFormatter)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir bool bEnabled = ( rDev.GetOutDevType() != OUTDEV_WINDOW )
464cdf0e10cSrcweir || ( static_cast< Window& >( rDev ).IsEnabled() );
465cdf0e10cSrcweir
466cdf0e10cSrcweir FmXDataCell* pDataCell = PTR_CAST(FmXDataCell, m_pCell);
467cdf0e10cSrcweir if (pDataCell)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir if (!pRow || !pRow->IsValid())
470cdf0e10cSrcweir {
471cdf0e10cSrcweir sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER;
472cdf0e10cSrcweir if ( !bEnabled )
473cdf0e10cSrcweir nStyle |= TEXT_DRAW_DISABLE;
474cdf0e10cSrcweir
475cdf0e10cSrcweir rDev.DrawText(rRect, INVALIDTEXT, nStyle);
476cdf0e10cSrcweir }
477cdf0e10cSrcweir else if (m_bAutoValue && pRow->IsNew())
478cdf0e10cSrcweir {
479cdf0e10cSrcweir static String aAutoText(SVX_RES(RID_STR_AUTOFIELD));
480cdf0e10cSrcweir sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER;
481cdf0e10cSrcweir if ( !bEnabled )
482cdf0e10cSrcweir nStyle |= TEXT_DRAW_DISABLE;
483cdf0e10cSrcweir
484cdf0e10cSrcweir switch (GetAlignment())
485cdf0e10cSrcweir {
486cdf0e10cSrcweir case ::com::sun::star::awt::TextAlign::RIGHT:
487cdf0e10cSrcweir nStyle |= TEXT_DRAW_RIGHT;
488cdf0e10cSrcweir break;
489cdf0e10cSrcweir case ::com::sun::star::awt::TextAlign::CENTER:
490cdf0e10cSrcweir nStyle |= TEXT_DRAW_CENTER;
491cdf0e10cSrcweir break;
492cdf0e10cSrcweir default:
493cdf0e10cSrcweir nStyle |= TEXT_DRAW_LEFT;
494cdf0e10cSrcweir }
495cdf0e10cSrcweir
496cdf0e10cSrcweir rDev.DrawText(rRect, aAutoText , nStyle);
497cdf0e10cSrcweir }
498cdf0e10cSrcweir else if (pRow->HasField(m_nFieldPos))
499cdf0e10cSrcweir {
500cdf0e10cSrcweir pDataCell->PaintFieldToCell(rDev, rRect, pRow->GetField( m_nFieldPos ).getColumn(), xFormatter);
501cdf0e10cSrcweir }
502cdf0e10cSrcweir }
503cdf0e10cSrcweir else if (!m_pCell)
504cdf0e10cSrcweir {
505cdf0e10cSrcweir if (!pRow || !pRow->IsValid())
506cdf0e10cSrcweir {
507cdf0e10cSrcweir sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER;
508cdf0e10cSrcweir if ( !bEnabled )
509cdf0e10cSrcweir nStyle |= TEXT_DRAW_DISABLE;
510cdf0e10cSrcweir
511cdf0e10cSrcweir rDev.DrawText(rRect, INVALIDTEXT, nStyle);
512cdf0e10cSrcweir }
513cdf0e10cSrcweir else if (pRow->HasField(m_nFieldPos) && m_bObject)
514cdf0e10cSrcweir {
515cdf0e10cSrcweir sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER;
516cdf0e10cSrcweir if ( !bEnabled )
517cdf0e10cSrcweir nStyle |= TEXT_DRAW_DISABLE;
518cdf0e10cSrcweir rDev.DrawText(rRect, OBJECTTEXT, nStyle);
519cdf0e10cSrcweir }
520cdf0e10cSrcweir }
521cdf0e10cSrcweir else if ( m_pCell->ISA( FmXFilterCell ) )
522cdf0e10cSrcweir static_cast< FmXFilterCell* >( m_pCell )->PaintCell( rDev, rRect );
523cdf0e10cSrcweir }
524cdf0e10cSrcweir
525cdf0e10cSrcweir //------------------------------------------------------------------------------
ImplInitWindow(Window & rParent,const InitWindowFacet _eInitWhat)526cdf0e10cSrcweir void DbGridColumn::ImplInitWindow( Window& rParent, const InitWindowFacet _eInitWhat )
527cdf0e10cSrcweir {
528cdf0e10cSrcweir if ( m_pCell )
529cdf0e10cSrcweir m_pCell->ImplInitWindow( rParent, _eInitWhat );
530cdf0e10cSrcweir }
531cdf0e10cSrcweir
532cdf0e10cSrcweir //==============================================================================
533cdf0e10cSrcweir //= cell controls
534cdf0e10cSrcweir //==============================================================================
535cdf0e10cSrcweir TYPEINIT0( DbCellControl )
TYPEINIT1(DbLimitedLengthField,DbCellControl)536cdf0e10cSrcweir TYPEINIT1( DbLimitedLengthField, DbCellControl )
537cdf0e10cSrcweir TYPEINIT1( DbTextField, DbLimitedLengthField )
538cdf0e10cSrcweir TYPEINIT1( DbFormattedField, DbLimitedLengthField )
539cdf0e10cSrcweir TYPEINIT1( DbCheckBox, DbCellControl )
540cdf0e10cSrcweir TYPEINIT1( DbComboBox, DbCellControl )
541cdf0e10cSrcweir TYPEINIT1( DbListBox, DbCellControl )
542cdf0e10cSrcweir TYPEINIT1( DbPatternField, DbCellControl )
543cdf0e10cSrcweir TYPEINIT1( DbSpinField, DbCellControl )
544cdf0e10cSrcweir TYPEINIT1( DbDateField, DbSpinField )
545cdf0e10cSrcweir TYPEINIT1( DbTimeField, DbSpinField )
546cdf0e10cSrcweir TYPEINIT1( DbCurrencyField, DbSpinField )
547cdf0e10cSrcweir TYPEINIT1( DbNumericField, DbSpinField )
548cdf0e10cSrcweir TYPEINIT1( DbFilterField, DbCellControl )
549cdf0e10cSrcweir
550cdf0e10cSrcweir //------------------------------------------------------------------------------
551cdf0e10cSrcweir DbCellControl::DbCellControl( DbGridColumn& _rColumn, sal_Bool /*_bText*/ )
552cdf0e10cSrcweir :OPropertyChangeListener(m_aMutex)
553cdf0e10cSrcweir ,m_pFieldChangeBroadcaster(NULL)
554cdf0e10cSrcweir ,m_bTransparent( sal_False )
555cdf0e10cSrcweir ,m_bAlignedController( sal_True )
556cdf0e10cSrcweir ,m_bAccessingValueProperty( sal_False )
557cdf0e10cSrcweir ,m_rColumn( _rColumn )
558cdf0e10cSrcweir ,m_pPainter( NULL )
559cdf0e10cSrcweir ,m_pWindow( NULL )
560cdf0e10cSrcweir {
561cdf0e10cSrcweir Reference< XPropertySet > xColModelProps( _rColumn.getModel(), UNO_QUERY );
562cdf0e10cSrcweir if ( xColModelProps.is() )
563cdf0e10cSrcweir {
564cdf0e10cSrcweir // if our model's format key changes we want to propagate the new value to our windows
565cdf0e10cSrcweir m_pModelChangeBroadcaster = new ::comphelper::OPropertyChangeMultiplexer(this, Reference< ::com::sun::star::beans::XPropertySet > (_rColumn.getModel(), UNO_QUERY));
566cdf0e10cSrcweir m_pModelChangeBroadcaster->acquire();
567cdf0e10cSrcweir
568cdf0e10cSrcweir // be listener for some common properties
569cdf0e10cSrcweir implDoPropertyListening( FM_PROP_READONLY, sal_False );
570cdf0e10cSrcweir implDoPropertyListening( FM_PROP_ENABLED, sal_False );
571cdf0e10cSrcweir
572cdf0e10cSrcweir // add as listener for all know "value" properties
573cdf0e10cSrcweir implDoPropertyListening( FM_PROP_VALUE, sal_False );
574cdf0e10cSrcweir implDoPropertyListening( FM_PROP_STATE, sal_False );
575cdf0e10cSrcweir implDoPropertyListening( FM_PROP_TEXT, sal_False );
576cdf0e10cSrcweir implDoPropertyListening( FM_PROP_EFFECTIVE_VALUE, sal_False );
577cdf0e10cSrcweir
578cdf0e10cSrcweir // be listener at the bound field as well
579cdf0e10cSrcweir try
580cdf0e10cSrcweir {
581cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI( xColModelProps->getPropertySetInfo(), UNO_SET_THROW );
582cdf0e10cSrcweir if ( xPSI->hasPropertyByName( FM_PROP_BOUNDFIELD ) )
583cdf0e10cSrcweir {
584cdf0e10cSrcweir Reference< XPropertySet > xField;
585cdf0e10cSrcweir xColModelProps->getPropertyValue( FM_PROP_BOUNDFIELD ) >>= xField;
586cdf0e10cSrcweir if ( xField.is() )
587cdf0e10cSrcweir {
588cdf0e10cSrcweir m_pFieldChangeBroadcaster = new ::comphelper::OPropertyChangeMultiplexer(this, xField);
589cdf0e10cSrcweir m_pFieldChangeBroadcaster->acquire();
590cdf0e10cSrcweir m_pFieldChangeBroadcaster->addProperty( FM_PROP_ISREADONLY );
591cdf0e10cSrcweir }
592cdf0e10cSrcweir }
593cdf0e10cSrcweir }
594cdf0e10cSrcweir catch( const Exception& )
595cdf0e10cSrcweir {
596cdf0e10cSrcweir DBG_ERROR( "DbCellControl::doPropertyListening: caught an exception!" );
597cdf0e10cSrcweir }
598cdf0e10cSrcweir }
599cdf0e10cSrcweir }
600cdf0e10cSrcweir
601cdf0e10cSrcweir //------------------------------------------------------------------------------
implDoPropertyListening(const::rtl::OUString & _rPropertyName,sal_Bool _bWarnIfNotExistent)602cdf0e10cSrcweir void DbCellControl::implDoPropertyListening( const ::rtl::OUString& _rPropertyName, sal_Bool _bWarnIfNotExistent )
603cdf0e10cSrcweir {
604cdf0e10cSrcweir try
605cdf0e10cSrcweir {
606cdf0e10cSrcweir Reference< XPropertySet > xColModelProps( m_rColumn.getModel(), UNO_QUERY );
607cdf0e10cSrcweir Reference< XPropertySetInfo > xPSI;
608cdf0e10cSrcweir if ( xColModelProps.is() )
609cdf0e10cSrcweir xPSI = xColModelProps->getPropertySetInfo();
610cdf0e10cSrcweir
611cdf0e10cSrcweir DBG_ASSERT( !_bWarnIfNotExistent || ( xPSI.is() && xPSI->hasPropertyByName( _rPropertyName ) ),
612cdf0e10cSrcweir "DbCellControl::doPropertyListening: no property set info or non-existent property!" );
613cdf0e10cSrcweir (void)_bWarnIfNotExistent;
614cdf0e10cSrcweir
615cdf0e10cSrcweir if ( xPSI.is() && xPSI->hasPropertyByName( _rPropertyName ) )
616cdf0e10cSrcweir m_pModelChangeBroadcaster->addProperty( _rPropertyName );
617cdf0e10cSrcweir }
618cdf0e10cSrcweir catch( const Exception& )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir DBG_ERROR( "DbCellControl::doPropertyListening: caught an exception!" );
621cdf0e10cSrcweir }
622cdf0e10cSrcweir }
623cdf0e10cSrcweir
624cdf0e10cSrcweir //------------------------------------------------------------------------------
doPropertyListening(const::rtl::OUString & _rPropertyName)625cdf0e10cSrcweir void DbCellControl::doPropertyListening( const ::rtl::OUString& _rPropertyName )
626cdf0e10cSrcweir {
627cdf0e10cSrcweir implDoPropertyListening( _rPropertyName );
628cdf0e10cSrcweir }
629cdf0e10cSrcweir //------------------------------------------------------------------------------
lcl_clearBroadCaster(::comphelper::OPropertyChangeMultiplexer * & _pBroadcaster)630cdf0e10cSrcweir void lcl_clearBroadCaster(::comphelper::OPropertyChangeMultiplexer*& _pBroadcaster)
631cdf0e10cSrcweir {
632cdf0e10cSrcweir if ( _pBroadcaster )
633cdf0e10cSrcweir {
634cdf0e10cSrcweir _pBroadcaster->dispose();
635cdf0e10cSrcweir _pBroadcaster->release();
636cdf0e10cSrcweir _pBroadcaster = NULL;
637cdf0e10cSrcweir // no delete, this is done implicitly
638cdf0e10cSrcweir }
639cdf0e10cSrcweir }
640cdf0e10cSrcweir //------------------------------------------------------------------------------
~DbCellControl()641cdf0e10cSrcweir DbCellControl::~DbCellControl()
642cdf0e10cSrcweir {
643cdf0e10cSrcweir lcl_clearBroadCaster(m_pModelChangeBroadcaster);
644cdf0e10cSrcweir lcl_clearBroadCaster(m_pFieldChangeBroadcaster);
645cdf0e10cSrcweir
646cdf0e10cSrcweir delete m_pWindow;
647cdf0e10cSrcweir delete m_pPainter;
648cdf0e10cSrcweir }
649cdf0e10cSrcweir
650cdf0e10cSrcweir //------------------------------------------------------------------------------
implValuePropertyChanged()651cdf0e10cSrcweir void DbCellControl::implValuePropertyChanged( )
652cdf0e10cSrcweir {
653cdf0e10cSrcweir OSL_ENSURE( !isValuePropertyLocked(),
654cdf0e10cSrcweir "DbCellControl::implValuePropertyChanged: not to be called with the value property locked!" );
655cdf0e10cSrcweir
656cdf0e10cSrcweir if ( m_pWindow )
657cdf0e10cSrcweir {
658cdf0e10cSrcweir if ( m_rColumn.getModel().is() )
659cdf0e10cSrcweir updateFromModel( m_rColumn.getModel() );
660cdf0e10cSrcweir }
661cdf0e10cSrcweir }
662cdf0e10cSrcweir
663cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> &)664cdf0e10cSrcweir void DbCellControl::implAdjustGenericFieldSetting( const Reference< XPropertySet >& /*_rxModel*/ )
665cdf0e10cSrcweir {
666cdf0e10cSrcweir // nothing to to here
667cdf0e10cSrcweir }
668cdf0e10cSrcweir
669cdf0e10cSrcweir //------------------------------------------------------------------------------
_propertyChanged(const PropertyChangeEvent & _rEvent)670cdf0e10cSrcweir void DbCellControl::_propertyChanged(const PropertyChangeEvent& _rEvent) throw(RuntimeException)
671cdf0e10cSrcweir {
672cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() );
673cdf0e10cSrcweir
674cdf0e10cSrcweir Reference< XPropertySet > xSourceProps( _rEvent.Source, UNO_QUERY );
675cdf0e10cSrcweir
676cdf0e10cSrcweir if ( _rEvent.PropertyName.equals( FM_PROP_VALUE )
677cdf0e10cSrcweir || _rEvent.PropertyName.equals( FM_PROP_STATE )
678cdf0e10cSrcweir || _rEvent.PropertyName.equals( FM_PROP_TEXT )
679cdf0e10cSrcweir || _rEvent.PropertyName.equals( FM_PROP_EFFECTIVE_VALUE )
680cdf0e10cSrcweir )
681cdf0e10cSrcweir { // it was one of the known "value" properties
682cdf0e10cSrcweir if ( !isValuePropertyLocked() )
683cdf0e10cSrcweir {
684cdf0e10cSrcweir implValuePropertyChanged( );
685cdf0e10cSrcweir }
686cdf0e10cSrcweir }
687cdf0e10cSrcweir else if ( _rEvent.PropertyName.equals( FM_PROP_READONLY ) )
688cdf0e10cSrcweir {
689cdf0e10cSrcweir implAdjustReadOnly( xSourceProps, true);
690cdf0e10cSrcweir }
691cdf0e10cSrcweir else if ( _rEvent.PropertyName.equals( FM_PROP_ISREADONLY ) )
692cdf0e10cSrcweir {
693cdf0e10cSrcweir sal_Bool bReadOnly = sal_True;
694cdf0e10cSrcweir _rEvent.NewValue >>= bReadOnly;
695cdf0e10cSrcweir m_rColumn.SetReadOnly(bReadOnly);
696cdf0e10cSrcweir implAdjustReadOnly( xSourceProps, false);
697cdf0e10cSrcweir }
698cdf0e10cSrcweir else if ( _rEvent.PropertyName.equals( FM_PROP_ENABLED ) )
699cdf0e10cSrcweir {
700cdf0e10cSrcweir implAdjustEnabled( xSourceProps );
701cdf0e10cSrcweir }
702cdf0e10cSrcweir else
703cdf0e10cSrcweir implAdjustGenericFieldSetting( xSourceProps );
704cdf0e10cSrcweir }
705cdf0e10cSrcweir
706cdf0e10cSrcweir //------------------------------------------------------------------------------
Commit()707cdf0e10cSrcweir sal_Bool DbCellControl::Commit()
708cdf0e10cSrcweir {
709cdf0e10cSrcweir // lock the listening for value property changes
710cdf0e10cSrcweir lockValueProperty();
711cdf0e10cSrcweir // commit the content of the control into the model's value property
712cdf0e10cSrcweir sal_Bool bReturn = sal_False;
713cdf0e10cSrcweir try
714cdf0e10cSrcweir {
715cdf0e10cSrcweir bReturn = commitControl();
716cdf0e10cSrcweir }
717cdf0e10cSrcweir catch( const Exception& )
718cdf0e10cSrcweir {
719cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
720cdf0e10cSrcweir }
721cdf0e10cSrcweir // unlock the listening for value property changes
722cdf0e10cSrcweir unlockValueProperty();
723cdf0e10cSrcweir // outta here
724cdf0e10cSrcweir return bReturn;
725cdf0e10cSrcweir }
726cdf0e10cSrcweir
727cdf0e10cSrcweir //------------------------------------------------------------------------------
ImplInitWindow(Window & rParent,const InitWindowFacet _eInitWhat)728cdf0e10cSrcweir void DbCellControl::ImplInitWindow( Window& rParent, const InitWindowFacet _eInitWhat )
729cdf0e10cSrcweir {
730cdf0e10cSrcweir Window* pWindows[] = { m_pPainter, m_pWindow };
731cdf0e10cSrcweir
732cdf0e10cSrcweir if ( ( _eInitWhat & InitWritingMode ) != 0 )
733cdf0e10cSrcweir {
734cdf0e10cSrcweir for ( size_t i=0; i < sizeof( pWindows ) / sizeof( pWindows[0] ); ++i )
735cdf0e10cSrcweir {
736cdf0e10cSrcweir if ( pWindows[i] )
737cdf0e10cSrcweir pWindows[i]->EnableRTL( rParent.IsRTLEnabled() );
738cdf0e10cSrcweir }
739cdf0e10cSrcweir }
740cdf0e10cSrcweir
741cdf0e10cSrcweir if ( ( _eInitWhat & InitFont ) != 0 )
742cdf0e10cSrcweir {
743cdf0e10cSrcweir for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i)
744cdf0e10cSrcweir {
745cdf0e10cSrcweir if ( !pWindows[i] )
746cdf0e10cSrcweir continue;
747cdf0e10cSrcweir
748cdf0e10cSrcweir pWindows[i]->SetZoom( rParent.GetZoom() );
749cdf0e10cSrcweir
750cdf0e10cSrcweir const StyleSettings& rStyleSettings = pWindows[i]->GetSettings().GetStyleSettings();
751cdf0e10cSrcweir Font aFont = rStyleSettings.GetFieldFont();
752cdf0e10cSrcweir aFont.SetTransparent( isTransparent() );
753cdf0e10cSrcweir
754cdf0e10cSrcweir if ( rParent.IsControlFont() )
755cdf0e10cSrcweir {
756cdf0e10cSrcweir pWindows[i]->SetControlFont( rParent.GetControlFont() );
757cdf0e10cSrcweir aFont.Merge( rParent.GetControlFont() );
758cdf0e10cSrcweir }
759cdf0e10cSrcweir else
760cdf0e10cSrcweir pWindows[i]->SetControlFont();
761cdf0e10cSrcweir
762cdf0e10cSrcweir pWindows[i]->SetZoomedPointFont( aFont );
763cdf0e10cSrcweir }
764cdf0e10cSrcweir }
765cdf0e10cSrcweir
766cdf0e10cSrcweir if ( ( ( _eInitWhat & InitFont ) != 0 )
767cdf0e10cSrcweir || ( ( _eInitWhat & InitForeground ) != 0 )
768cdf0e10cSrcweir )
769cdf0e10cSrcweir {
770cdf0e10cSrcweir Color aTextColor( rParent.IsControlForeground() ? rParent.GetControlForeground() : rParent.GetTextColor() );
771cdf0e10cSrcweir
772cdf0e10cSrcweir sal_Bool bTextLineColor = rParent.IsTextLineColor();
773cdf0e10cSrcweir Color aTextLineColor( rParent.GetTextLineColor() );
774cdf0e10cSrcweir
775cdf0e10cSrcweir for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i)
776cdf0e10cSrcweir {
777cdf0e10cSrcweir if ( pWindows[i] )
778cdf0e10cSrcweir {
779cdf0e10cSrcweir pWindows[i]->SetTextColor(aTextColor);
780cdf0e10cSrcweir if (rParent.IsControlForeground())
781cdf0e10cSrcweir pWindows[i]->SetControlForeground(aTextColor);
782cdf0e10cSrcweir
783cdf0e10cSrcweir if (bTextLineColor)
784cdf0e10cSrcweir pWindows[i]->SetTextLineColor();
785cdf0e10cSrcweir else
786cdf0e10cSrcweir pWindows[i]->SetTextLineColor(aTextLineColor);
787cdf0e10cSrcweir }
788cdf0e10cSrcweir }
789cdf0e10cSrcweir }
790cdf0e10cSrcweir
791cdf0e10cSrcweir if ( ( _eInitWhat & InitBackground ) != 0 )
792cdf0e10cSrcweir {
793cdf0e10cSrcweir if (rParent.IsControlBackground())
794cdf0e10cSrcweir {
795cdf0e10cSrcweir Color aColor( rParent.GetControlBackground());
796cdf0e10cSrcweir for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i)
797cdf0e10cSrcweir {
798cdf0e10cSrcweir if ( pWindows[i] )
799cdf0e10cSrcweir {
800cdf0e10cSrcweir if ( isTransparent() )
801cdf0e10cSrcweir pWindows[i]->SetBackground();
802cdf0e10cSrcweir else
803cdf0e10cSrcweir {
804cdf0e10cSrcweir pWindows[i]->SetBackground(aColor);
805cdf0e10cSrcweir pWindows[i]->SetControlBackground(aColor);
806cdf0e10cSrcweir }
807cdf0e10cSrcweir pWindows[i]->SetFillColor(aColor);
808cdf0e10cSrcweir }
809cdf0e10cSrcweir }
810cdf0e10cSrcweir }
811cdf0e10cSrcweir else
812cdf0e10cSrcweir {
813cdf0e10cSrcweir if (m_pPainter)
814cdf0e10cSrcweir {
815cdf0e10cSrcweir if ( isTransparent() )
816cdf0e10cSrcweir m_pPainter->SetBackground();
817cdf0e10cSrcweir else
818cdf0e10cSrcweir m_pPainter->SetBackground(rParent.GetBackground());
819cdf0e10cSrcweir m_pPainter->SetFillColor(rParent.GetFillColor());
820cdf0e10cSrcweir }
821cdf0e10cSrcweir
822cdf0e10cSrcweir if (m_pWindow)
823cdf0e10cSrcweir {
824cdf0e10cSrcweir if ( isTransparent() )
825cdf0e10cSrcweir m_pWindow->SetBackground(rParent.GetBackground());
826cdf0e10cSrcweir else
827cdf0e10cSrcweir m_pWindow->SetFillColor(rParent.GetFillColor());
828cdf0e10cSrcweir }
829cdf0e10cSrcweir }
830cdf0e10cSrcweir }
831cdf0e10cSrcweir }
832cdf0e10cSrcweir
833cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustReadOnly(const Reference<XPropertySet> & _rxModel,bool i_bReadOnly)834cdf0e10cSrcweir void DbCellControl::implAdjustReadOnly( const Reference< XPropertySet >& _rxModel,bool i_bReadOnly )
835cdf0e10cSrcweir {
836cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbCellControl::implAdjustReadOnly: not to be called without window!" );
837cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbCellControl::implAdjustReadOnly: invalid model!" );
838cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
839cdf0e10cSrcweir {
840cdf0e10cSrcweir Edit* pEditWindow = dynamic_cast< Edit* >( m_pWindow );
841cdf0e10cSrcweir if ( pEditWindow )
842cdf0e10cSrcweir {
843cdf0e10cSrcweir sal_Bool bReadOnly = m_rColumn.IsReadOnly();
844cdf0e10cSrcweir if ( !bReadOnly )
845cdf0e10cSrcweir {
846cdf0e10cSrcweir _rxModel->getPropertyValue( i_bReadOnly ? FM_PROP_READONLY : FM_PROP_ISREADONLY) >>= bReadOnly;
847cdf0e10cSrcweir }
848cdf0e10cSrcweir static_cast< Edit* >( m_pWindow )->SetReadOnly( bReadOnly );
849cdf0e10cSrcweir }
850cdf0e10cSrcweir }
851cdf0e10cSrcweir }
852cdf0e10cSrcweir
853cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustEnabled(const Reference<XPropertySet> & _rxModel)854cdf0e10cSrcweir void DbCellControl::implAdjustEnabled( const Reference< XPropertySet >& _rxModel )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbCellControl::implAdjustEnabled: not to be called without window!" );
857cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbCellControl::implAdjustEnabled: invalid model!" );
858cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
859cdf0e10cSrcweir {
860cdf0e10cSrcweir sal_Bool bEnable = sal_True;
861cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_ENABLED ) >>= bEnable;
862cdf0e10cSrcweir m_pWindow->Enable( bEnable );
863cdf0e10cSrcweir }
864cdf0e10cSrcweir }
865cdf0e10cSrcweir
866cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & rParent,const Reference<XRowSet> & _rxCursor)867cdf0e10cSrcweir void DbCellControl::Init( Window& rParent, const Reference< XRowSet >& _rxCursor )
868cdf0e10cSrcweir {
869cdf0e10cSrcweir ImplInitWindow( rParent, InitAll );
870cdf0e10cSrcweir
871cdf0e10cSrcweir if ( m_pWindow )
872cdf0e10cSrcweir {
873cdf0e10cSrcweir // align the control
874cdf0e10cSrcweir if ( isAlignedController() )
875cdf0e10cSrcweir AlignControl( m_rColumn.GetAlignment() );
876cdf0e10cSrcweir
877cdf0e10cSrcweir try
878cdf0e10cSrcweir {
879cdf0e10cSrcweir // some other common properties
880cdf0e10cSrcweir Reference< XPropertySet > xModel( m_rColumn.getModel(), UNO_SET_THROW );
881cdf0e10cSrcweir Reference< XPropertySetInfo > xModelPSI( xModel->getPropertySetInfo(), UNO_SET_THROW );
882cdf0e10cSrcweir
883cdf0e10cSrcweir if ( xModelPSI->hasPropertyByName( FM_PROP_READONLY ) )
884cdf0e10cSrcweir {
885cdf0e10cSrcweir implAdjustReadOnly( xModel,true );
886cdf0e10cSrcweir }
887cdf0e10cSrcweir
888cdf0e10cSrcweir if ( xModelPSI->hasPropertyByName( FM_PROP_ENABLED ) )
889cdf0e10cSrcweir {
890cdf0e10cSrcweir implAdjustEnabled( xModel );
891cdf0e10cSrcweir }
892cdf0e10cSrcweir
893cdf0e10cSrcweir if ( xModelPSI->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) )
894cdf0e10cSrcweir {
895cdf0e10cSrcweir sal_Int16 nWheelBehavior = MouseWheelBehavior::SCROLL_FOCUS_ONLY;
896cdf0e10cSrcweir OSL_VERIFY( xModel->getPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) >>= nWheelBehavior );
897cdf0e10cSrcweir sal_uInt16 nVclSetting = MOUSE_WHEEL_FOCUS_ONLY;
898cdf0e10cSrcweir switch ( nWheelBehavior )
899cdf0e10cSrcweir {
900cdf0e10cSrcweir case MouseWheelBehavior::SCROLL_DISABLED: nVclSetting = MOUSE_WHEEL_DISABLE; break;
901cdf0e10cSrcweir case MouseWheelBehavior::SCROLL_FOCUS_ONLY: nVclSetting = MOUSE_WHEEL_FOCUS_ONLY; break;
902cdf0e10cSrcweir case MouseWheelBehavior::SCROLL_ALWAYS: nVclSetting = MOUSE_WHEEL_ALWAYS; break;
903cdf0e10cSrcweir default:
904cdf0e10cSrcweir OSL_ENSURE( false, "DbCellControl::Init: invalid MouseWheelBehavior!" );
905cdf0e10cSrcweir break;
906cdf0e10cSrcweir }
907cdf0e10cSrcweir
908cdf0e10cSrcweir AllSettings aSettings = m_pWindow->GetSettings();
909cdf0e10cSrcweir MouseSettings aMouseSettings = aSettings.GetMouseSettings();
910cdf0e10cSrcweir aMouseSettings.SetWheelBehavior( nVclSetting );
911cdf0e10cSrcweir aSettings.SetMouseSettings( aMouseSettings );
912cdf0e10cSrcweir m_pWindow->SetSettings( aSettings, sal_True );
913cdf0e10cSrcweir }
914cdf0e10cSrcweir }
915cdf0e10cSrcweir catch( const Exception& )
916cdf0e10cSrcweir {
917cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
918cdf0e10cSrcweir }
919cdf0e10cSrcweir }
920cdf0e10cSrcweir m_xCursor = _rxCursor;
921cdf0e10cSrcweir }
922cdf0e10cSrcweir
923cdf0e10cSrcweir //------------------------------------------------------------------------------
SetTextLineColor()924cdf0e10cSrcweir void DbCellControl::SetTextLineColor()
925cdf0e10cSrcweir {
926cdf0e10cSrcweir if (m_pWindow)
927cdf0e10cSrcweir m_pWindow->SetTextLineColor();
928cdf0e10cSrcweir if (m_pPainter)
929cdf0e10cSrcweir m_pPainter->SetTextLineColor();
930cdf0e10cSrcweir }
931cdf0e10cSrcweir
932cdf0e10cSrcweir //------------------------------------------------------------------------------
SetTextLineColor(const Color & _rColor)933cdf0e10cSrcweir void DbCellControl::SetTextLineColor(const Color& _rColor)
934cdf0e10cSrcweir {
935cdf0e10cSrcweir if (m_pWindow)
936cdf0e10cSrcweir m_pWindow->SetTextLineColor(_rColor);
937cdf0e10cSrcweir if (m_pPainter)
938cdf0e10cSrcweir m_pPainter->SetTextLineColor(_rColor);
939cdf0e10cSrcweir }
940cdf0e10cSrcweir
941cdf0e10cSrcweir namespace
942cdf0e10cSrcweir {
lcl_implAlign(Window * _pWindow,WinBits _nAlignmentBit)943cdf0e10cSrcweir static void lcl_implAlign( Window* _pWindow, WinBits _nAlignmentBit )
944cdf0e10cSrcweir {
945cdf0e10cSrcweir WinBits nStyle = _pWindow->GetStyle();
946cdf0e10cSrcweir nStyle &= ~(WB_LEFT | WB_RIGHT | WB_CENTER);
947cdf0e10cSrcweir _pWindow->SetStyle( nStyle | _nAlignmentBit );
948cdf0e10cSrcweir }
949cdf0e10cSrcweir }
950cdf0e10cSrcweir
951cdf0e10cSrcweir //------------------------------------------------------------------------------
AlignControl(sal_Int16 nAlignment)952cdf0e10cSrcweir void DbCellControl::AlignControl(sal_Int16 nAlignment)
953cdf0e10cSrcweir {
954cdf0e10cSrcweir WinBits nAlignmentBit = 0;
955cdf0e10cSrcweir switch (nAlignment)
956cdf0e10cSrcweir {
957cdf0e10cSrcweir case ::com::sun::star::awt::TextAlign::RIGHT:
958cdf0e10cSrcweir nAlignmentBit = WB_RIGHT;
959cdf0e10cSrcweir break;
960cdf0e10cSrcweir case ::com::sun::star::awt::TextAlign::CENTER:
961cdf0e10cSrcweir nAlignmentBit = WB_CENTER;
962cdf0e10cSrcweir break;
963cdf0e10cSrcweir default:
964cdf0e10cSrcweir nAlignmentBit = WB_LEFT;
965cdf0e10cSrcweir break;
966cdf0e10cSrcweir }
967cdf0e10cSrcweir lcl_implAlign( m_pWindow, nAlignmentBit );
968cdf0e10cSrcweir if ( m_pPainter )
969cdf0e10cSrcweir lcl_implAlign( m_pPainter, nAlignmentBit );
970cdf0e10cSrcweir }
971cdf0e10cSrcweir
972cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintCell(OutputDevice & _rDev,const Rectangle & _rRect)973cdf0e10cSrcweir void DbCellControl::PaintCell( OutputDevice& _rDev, const Rectangle& _rRect )
974cdf0e10cSrcweir {
975cdf0e10cSrcweir if ( m_pPainter->GetParent() == &_rDev )
976cdf0e10cSrcweir {
977cdf0e10cSrcweir m_pPainter->SetPaintTransparent( sal_True );
978cdf0e10cSrcweir m_pPainter->SetBackground( );
979cdf0e10cSrcweir m_pPainter->SetControlBackground( _rDev.GetFillColor() );
980cdf0e10cSrcweir m_pPainter->SetControlForeground( _rDev.GetTextColor() );
981cdf0e10cSrcweir m_pPainter->SetTextColor( _rDev.GetTextColor() );
982cdf0e10cSrcweir m_pPainter->SetTextFillColor( _rDev.GetTextColor() );
983cdf0e10cSrcweir
984cdf0e10cSrcweir Font aFont( _rDev.GetFont() );
985cdf0e10cSrcweir aFont.SetTransparent( sal_True );
986cdf0e10cSrcweir m_pPainter->SetFont( aFont );
987cdf0e10cSrcweir
988cdf0e10cSrcweir m_pPainter->SetPosSizePixel( _rRect.TopLeft(), _rRect.GetSize() );
989cdf0e10cSrcweir m_pPainter->Show();
990cdf0e10cSrcweir m_pPainter->Update();
991cdf0e10cSrcweir m_pPainter->SetParentUpdateMode( sal_False );
992cdf0e10cSrcweir m_pPainter->Hide();
993cdf0e10cSrcweir m_pPainter->SetParentUpdateMode( sal_True );
994cdf0e10cSrcweir }
995cdf0e10cSrcweir else
996cdf0e10cSrcweir m_pPainter->Draw( &_rDev, _rRect.TopLeft(), _rRect.GetSize(), 0 );
997cdf0e10cSrcweir }
998cdf0e10cSrcweir
999cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintFieldToCell(OutputDevice & _rDev,const Rectangle & _rRect,const Reference<XColumn> & _rxField,const Reference<XNumberFormatter> & _rxFormatter)1000cdf0e10cSrcweir void DbCellControl::PaintFieldToCell( OutputDevice& _rDev, const Rectangle& _rRect, const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
1001cdf0e10cSrcweir {
1002cdf0e10cSrcweir m_pPainter->SetText( GetFormatText( _rxField, _rxFormatter ) );
1003cdf0e10cSrcweir PaintCell( _rDev, _rRect );
1004cdf0e10cSrcweir }
1005cdf0e10cSrcweir
1006cdf0e10cSrcweir //------------------------------------------------------------------------------
GetValue(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter) const1007cdf0e10cSrcweir double DbCellControl::GetValue(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) const
1008cdf0e10cSrcweir {
1009cdf0e10cSrcweir double fValue = 0;
1010cdf0e10cSrcweir if (m_rColumn.IsNumeric())
1011cdf0e10cSrcweir {
1012cdf0e10cSrcweir try
1013cdf0e10cSrcweir {
1014cdf0e10cSrcweir fValue = _rxField->getDouble();
1015cdf0e10cSrcweir }
1016cdf0e10cSrcweir catch(const Exception&) { }
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir else
1019cdf0e10cSrcweir {
1020cdf0e10cSrcweir sal_Bool bSuccess = sal_False;
1021cdf0e10cSrcweir try
1022cdf0e10cSrcweir {
1023cdf0e10cSrcweir fValue = _rxField->getDouble();
1024cdf0e10cSrcweir bSuccess = sal_True;
1025cdf0e10cSrcweir }
1026cdf0e10cSrcweir catch(const Exception&) { }
1027cdf0e10cSrcweir if (!bSuccess)
1028cdf0e10cSrcweir {
1029cdf0e10cSrcweir try
1030cdf0e10cSrcweir {
1031cdf0e10cSrcweir fValue = xFormatter->convertStringToNumber(m_rColumn.GetKey(), _rxField->getString());
1032cdf0e10cSrcweir }
1033cdf0e10cSrcweir catch(const Exception&) { }
1034cdf0e10cSrcweir }
1035cdf0e10cSrcweir }
1036cdf0e10cSrcweir return fValue;
1037cdf0e10cSrcweir }
1038cdf0e10cSrcweir
1039cdf0e10cSrcweir //------------------------------------------------------------------------------
invalidatedController()1040cdf0e10cSrcweir void DbCellControl::invalidatedController()
1041cdf0e10cSrcweir {
1042cdf0e10cSrcweir m_rColumn.GetParent().refreshController(m_rColumn.GetId(), DbGridControl::GrantControlAccess());
1043cdf0e10cSrcweir }
1044cdf0e10cSrcweir
1045cdf0e10cSrcweir /*************************************************************************/
1046cdf0e10cSrcweir // CellModels
1047cdf0e10cSrcweir /*************************************************************************/
1048cdf0e10cSrcweir
1049cdf0e10cSrcweir //==============================================================================
1050cdf0e10cSrcweir //= DbLimitedLengthField
1051cdf0e10cSrcweir //==============================================================================
1052cdf0e10cSrcweir //------------------------------------------------------------------------------
DbLimitedLengthField(DbGridColumn & _rColumn)1053cdf0e10cSrcweir DbLimitedLengthField::DbLimitedLengthField( DbGridColumn& _rColumn )
1054cdf0e10cSrcweir :DbCellControl( _rColumn )
1055cdf0e10cSrcweir {
1056cdf0e10cSrcweir doPropertyListening( FM_PROP_MAXTEXTLEN );
1057cdf0e10cSrcweir }
1058cdf0e10cSrcweir
1059cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> & _rxModel)1060cdf0e10cSrcweir void DbLimitedLengthField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
1061cdf0e10cSrcweir {
1062cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbLimitedLengthField::implAdjustGenericFieldSetting: not to be called without window!" );
1063cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbLimitedLengthField::implAdjustGenericFieldSetting: invalid model!" );
1064cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
1065cdf0e10cSrcweir {
1066cdf0e10cSrcweir sal_Int16 nMaxLen = 0;
1067cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_MAXTEXTLEN ) >>= nMaxLen;
1068cdf0e10cSrcweir implSetMaxTextLen( nMaxLen );
1069cdf0e10cSrcweir }
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir
1072cdf0e10cSrcweir //------------------------------------------------------------------------------
implSetEffectiveMaxTextLen(sal_Int16 _nMaxLen)1073cdf0e10cSrcweir void DbLimitedLengthField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen )
1074cdf0e10cSrcweir {
1075cdf0e10cSrcweir dynamic_cast< Edit* >( m_pWindow )->SetMaxTextLen( _nMaxLen );
1076cdf0e10cSrcweir if ( m_pPainter )
1077cdf0e10cSrcweir dynamic_cast< Edit* >( m_pPainter )->SetMaxTextLen( _nMaxLen );
1078cdf0e10cSrcweir }
1079cdf0e10cSrcweir
1080cdf0e10cSrcweir //==============================================================================
1081cdf0e10cSrcweir //= DbTextField
1082cdf0e10cSrcweir //==============================================================================
1083cdf0e10cSrcweir //------------------------------------------------------------------------------
DbTextField(DbGridColumn & _rColumn)1084cdf0e10cSrcweir DbTextField::DbTextField(DbGridColumn& _rColumn)
1085cdf0e10cSrcweir :DbLimitedLengthField(_rColumn)
1086cdf0e10cSrcweir ,m_pEdit( NULL )
1087cdf0e10cSrcweir ,m_pPainterImplementation( NULL )
1088cdf0e10cSrcweir ,m_nKeyType(::com::sun::star::util::NumberFormat::TEXT)
1089cdf0e10cSrcweir ,m_bIsSimpleEdit( sal_True )
1090cdf0e10cSrcweir {
1091cdf0e10cSrcweir }
1092cdf0e10cSrcweir
1093cdf0e10cSrcweir //------------------------------------------------------------------------------
~DbTextField()1094cdf0e10cSrcweir DbTextField::~DbTextField( )
1095cdf0e10cSrcweir {
1096cdf0e10cSrcweir DELETEZ( m_pPainterImplementation );
1097cdf0e10cSrcweir DELETEZ( m_pEdit );
1098cdf0e10cSrcweir }
1099cdf0e10cSrcweir
1100cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & rParent,const Reference<XRowSet> & xCursor)1101cdf0e10cSrcweir void DbTextField::Init( Window& rParent, const Reference< XRowSet >& xCursor)
1102cdf0e10cSrcweir {
1103cdf0e10cSrcweir sal_Int16 nAlignment = m_rColumn.SetAlignmentFromModel(-1);
1104cdf0e10cSrcweir
1105cdf0e10cSrcweir Reference< XPropertySet > xModel( m_rColumn.getModel() );
1106cdf0e10cSrcweir
1107cdf0e10cSrcweir WinBits nStyle = WB_LEFT;
1108cdf0e10cSrcweir switch (nAlignment)
1109cdf0e10cSrcweir {
1110cdf0e10cSrcweir case awt::TextAlign::RIGHT:
1111cdf0e10cSrcweir nStyle = WB_RIGHT;
1112cdf0e10cSrcweir break;
1113cdf0e10cSrcweir
1114cdf0e10cSrcweir case awt::TextAlign::CENTER:
1115cdf0e10cSrcweir nStyle = WB_CENTER;
1116cdf0e10cSrcweir break;
1117cdf0e10cSrcweir }
1118cdf0e10cSrcweir
1119cdf0e10cSrcweir // is this a multi-line field?
1120cdf0e10cSrcweir sal_Bool bIsMultiLine = sal_False;
1121cdf0e10cSrcweir try
1122cdf0e10cSrcweir {
1123cdf0e10cSrcweir if ( xModel.is() )
1124cdf0e10cSrcweir {
1125cdf0e10cSrcweir OSL_VERIFY( xModel->getPropertyValue( FM_PROP_MULTILINE ) >>= bIsMultiLine );
1126cdf0e10cSrcweir }
1127cdf0e10cSrcweir }
1128cdf0e10cSrcweir catch( const Exception& )
1129cdf0e10cSrcweir {
1130cdf0e10cSrcweir OSL_ENSURE( sal_False, "DbTextField::Init: caught an exception while determining the multi-line capabilities!" );
1131cdf0e10cSrcweir }
1132cdf0e10cSrcweir
1133cdf0e10cSrcweir m_bIsSimpleEdit = !bIsMultiLine;
1134cdf0e10cSrcweir if ( bIsMultiLine )
1135cdf0e10cSrcweir {
1136cdf0e10cSrcweir m_pWindow = new MultiLineTextCell( &rParent, nStyle );
1137cdf0e10cSrcweir m_pEdit = new MultiLineEditImplementation( *static_cast< MultiLineTextCell* >( m_pWindow ) );
1138cdf0e10cSrcweir
1139cdf0e10cSrcweir m_pPainter = new MultiLineTextCell( &rParent, nStyle );
1140cdf0e10cSrcweir m_pPainterImplementation = new MultiLineEditImplementation( *static_cast< MultiLineTextCell* >( m_pPainter ) );
1141cdf0e10cSrcweir }
1142cdf0e10cSrcweir else
1143cdf0e10cSrcweir {
1144cdf0e10cSrcweir m_pWindow = new Edit( &rParent, nStyle );
1145cdf0e10cSrcweir m_pEdit = new EditImplementation( *static_cast< Edit* >( m_pWindow ) );
1146cdf0e10cSrcweir
1147cdf0e10cSrcweir m_pPainter = new Edit( &rParent, nStyle );
1148cdf0e10cSrcweir m_pPainterImplementation = new EditImplementation( *static_cast< Edit* >( m_pPainter ) );
1149cdf0e10cSrcweir }
1150cdf0e10cSrcweir
1151cdf0e10cSrcweir if ( WB_LEFT == nStyle )
1152cdf0e10cSrcweir {
1153cdf0e10cSrcweir // this is so that when getting the focus, the selection is oriented left-to-right
1154cdf0e10cSrcweir AllSettings aSettings = m_pWindow->GetSettings();
1155cdf0e10cSrcweir StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1156cdf0e10cSrcweir aStyleSettings.SetSelectionOptions(
1157cdf0e10cSrcweir aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
1158cdf0e10cSrcweir aSettings.SetStyleSettings(aStyleSettings);
1159cdf0e10cSrcweir m_pWindow->SetSettings(aSettings);
1160cdf0e10cSrcweir }
1161cdf0e10cSrcweir
1162cdf0e10cSrcweir implAdjustGenericFieldSetting( xModel );
1163cdf0e10cSrcweir
1164cdf0e10cSrcweir if (m_rColumn.GetParent().getNumberFormatter().is() && m_rColumn.GetKey())
1165cdf0e10cSrcweir m_nKeyType = comphelper::getNumberFormatType(m_rColumn.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn.GetKey());
1166cdf0e10cSrcweir
1167cdf0e10cSrcweir DbLimitedLengthField::Init( rParent, xCursor );
1168cdf0e10cSrcweir }
1169cdf0e10cSrcweir
1170cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateController() const1171cdf0e10cSrcweir CellControllerRef DbTextField::CreateController() const
1172cdf0e10cSrcweir {
1173cdf0e10cSrcweir return new EditCellController( m_pEdit );
1174cdf0e10cSrcweir }
1175cdf0e10cSrcweir
1176cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintFieldToCell(OutputDevice & _rDev,const Rectangle & _rRect,const Reference<XColumn> & _rxField,const Reference<XNumberFormatter> & _rxFormatter)1177cdf0e10cSrcweir void DbTextField::PaintFieldToCell( OutputDevice& _rDev, const Rectangle& _rRect, const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
1178cdf0e10cSrcweir {
1179cdf0e10cSrcweir if ( m_pPainterImplementation )
1180cdf0e10cSrcweir m_pPainterImplementation->SetText( GetFormatText( _rxField, _rxFormatter, NULL ) );
1181cdf0e10cSrcweir
1182cdf0e10cSrcweir DbLimitedLengthField::PaintFieldToCell( _rDev, _rRect, _rxField, _rxFormatter );
1183cdf0e10cSrcweir }
1184cdf0e10cSrcweir
1185cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter,Color **)1186cdf0e10cSrcweir String DbTextField::GetFormatText(const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter, Color** /*ppColor*/)
1187cdf0e10cSrcweir {
1188cdf0e10cSrcweir ::rtl::OUString aString;
1189cdf0e10cSrcweir if ( _rxField.is() )
1190cdf0e10cSrcweir try
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir aString = getFormattedValue( _rxField, xFormatter, m_rColumn.GetParent().getNullDate(), m_rColumn.GetKey(), m_nKeyType);
1193cdf0e10cSrcweir }
1194cdf0e10cSrcweir catch( const Exception& )
1195cdf0e10cSrcweir {
1196cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1197cdf0e10cSrcweir }
1198cdf0e10cSrcweir
1199cdf0e10cSrcweir return aString;
1200cdf0e10cSrcweir }
1201cdf0e10cSrcweir
1202cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter)1203cdf0e10cSrcweir void DbTextField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter)
1204cdf0e10cSrcweir {
1205cdf0e10cSrcweir m_pEdit->SetText( GetFormatText( _rxField, xFormatter ) );
1206cdf0e10cSrcweir m_pEdit->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1207cdf0e10cSrcweir }
1208cdf0e10cSrcweir
1209cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)1210cdf0e10cSrcweir void DbTextField::updateFromModel( Reference< XPropertySet > _rxModel )
1211cdf0e10cSrcweir {
1212cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbTextField::updateFromModel: invalid call!" );
1213cdf0e10cSrcweir
1214cdf0e10cSrcweir ::rtl::OUString sText;
1215cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText;
1216cdf0e10cSrcweir
1217cdf0e10cSrcweir xub_StrLen nMaxTextLen = m_pEdit->GetMaxTextLen();
1218cdf0e10cSrcweir if ( EDIT_NOLIMIT != nMaxTextLen && sText.getLength() > nMaxTextLen )
1219cdf0e10cSrcweir {
1220cdf0e10cSrcweir sal_Int32 nDiff = sText.getLength() - nMaxTextLen;
1221cdf0e10cSrcweir sText = sText.replaceAt(sText.getLength() - nDiff,nDiff,::rtl::OUString());
1222cdf0e10cSrcweir }
1223cdf0e10cSrcweir
1224cdf0e10cSrcweir
1225cdf0e10cSrcweir m_pEdit->SetText( sText );
1226cdf0e10cSrcweir m_pEdit->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1227cdf0e10cSrcweir }
1228cdf0e10cSrcweir
1229cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()1230cdf0e10cSrcweir sal_Bool DbTextField::commitControl()
1231cdf0e10cSrcweir {
1232cdf0e10cSrcweir ::rtl::OUString aText( m_pEdit->GetText( getModelLineEndSetting( m_rColumn.getModel() ) ) );
1233cdf0e10cSrcweir // we have to check if the length before we can decide if the value was modified
1234cdf0e10cSrcweir xub_StrLen nMaxTextLen = m_pEdit->GetMaxTextLen();
1235cdf0e10cSrcweir if ( EDIT_NOLIMIT != nMaxTextLen )
1236cdf0e10cSrcweir {
1237cdf0e10cSrcweir ::rtl::OUString sOldValue;
1238cdf0e10cSrcweir m_rColumn.getModel()->getPropertyValue( FM_PROP_TEXT ) >>= sOldValue;
1239cdf0e10cSrcweir // if the new value didn't change we must set the old long value again
1240cdf0e10cSrcweir if ( sOldValue.getLength() > nMaxTextLen && sOldValue.compareTo(aText,nMaxTextLen) == 0 )
1241cdf0e10cSrcweir aText = sOldValue;
1242cdf0e10cSrcweir }
1243cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue( FM_PROP_TEXT, makeAny( aText ) );
1244cdf0e10cSrcweir return sal_True;
1245cdf0e10cSrcweir }
1246cdf0e10cSrcweir
1247cdf0e10cSrcweir //------------------------------------------------------------------------------
implSetEffectiveMaxTextLen(sal_Int16 _nMaxLen)1248cdf0e10cSrcweir void DbTextField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen )
1249cdf0e10cSrcweir {
1250cdf0e10cSrcweir if ( m_pEdit )
1251cdf0e10cSrcweir m_pEdit->SetMaxTextLen( _nMaxLen );
1252cdf0e10cSrcweir if ( m_pPainterImplementation )
1253cdf0e10cSrcweir m_pPainterImplementation->SetMaxTextLen( _nMaxLen );
1254cdf0e10cSrcweir }
1255cdf0e10cSrcweir
1256cdf0e10cSrcweir //==============================================================================
1257cdf0e10cSrcweir //= DbFormattedField
1258cdf0e10cSrcweir //==============================================================================
1259cdf0e10cSrcweir DBG_NAME(DbFormattedField);
1260cdf0e10cSrcweir //------------------------------------------------------------------------------
DbFormattedField(DbGridColumn & _rColumn)1261cdf0e10cSrcweir DbFormattedField::DbFormattedField(DbGridColumn& _rColumn)
1262cdf0e10cSrcweir :DbLimitedLengthField(_rColumn)
1263cdf0e10cSrcweir ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED)
1264cdf0e10cSrcweir {
1265cdf0e10cSrcweir DBG_CTOR(DbFormattedField,NULL);
1266cdf0e10cSrcweir
1267cdf0e10cSrcweir // if our model's format key changes we want to propagate the new value to our windows
1268cdf0e10cSrcweir doPropertyListening( FM_PROP_FORMATKEY );
1269cdf0e10cSrcweir }
1270cdf0e10cSrcweir
1271cdf0e10cSrcweir //------------------------------------------------------------------------------
~DbFormattedField()1272cdf0e10cSrcweir DbFormattedField::~DbFormattedField()
1273cdf0e10cSrcweir {
1274cdf0e10cSrcweir DBG_DTOR(DbFormattedField,NULL);
1275cdf0e10cSrcweir }
1276cdf0e10cSrcweir
1277cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & rParent,const Reference<XRowSet> & xCursor)1278cdf0e10cSrcweir void DbFormattedField::Init( Window& rParent, const Reference< XRowSet >& xCursor)
1279cdf0e10cSrcweir {
1280cdf0e10cSrcweir sal_Int16 nAlignment = m_rColumn.SetAlignmentFromModel(-1);
1281cdf0e10cSrcweir
1282cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet > xUnoModel = m_rColumn.getModel();
1283cdf0e10cSrcweir
1284cdf0e10cSrcweir switch (nAlignment)
1285cdf0e10cSrcweir {
1286cdf0e10cSrcweir case ::com::sun::star::awt::TextAlign::RIGHT:
1287cdf0e10cSrcweir m_pWindow = new FormattedField( &rParent, WB_RIGHT );
1288cdf0e10cSrcweir m_pPainter = new FormattedField( &rParent, WB_RIGHT );
1289cdf0e10cSrcweir break;
1290cdf0e10cSrcweir
1291cdf0e10cSrcweir case ::com::sun::star::awt::TextAlign::CENTER:
1292cdf0e10cSrcweir m_pWindow = new FormattedField( &rParent, WB_CENTER );
1293cdf0e10cSrcweir m_pPainter = new FormattedField( &rParent, WB_CENTER );
1294cdf0e10cSrcweir break;
1295cdf0e10cSrcweir default:
1296cdf0e10cSrcweir m_pWindow = new FormattedField( &rParent, WB_LEFT );
1297cdf0e10cSrcweir m_pPainter = new FormattedField( &rParent, WB_LEFT );
1298cdf0e10cSrcweir
1299cdf0e10cSrcweir // Alles nur damit die Selektion bei Focuserhalt von rechts nach links geht
1300cdf0e10cSrcweir AllSettings aSettings = m_pWindow->GetSettings();
1301cdf0e10cSrcweir StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1302cdf0e10cSrcweir aStyleSettings.SetSelectionOptions(
1303cdf0e10cSrcweir aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
1304cdf0e10cSrcweir aSettings.SetStyleSettings(aStyleSettings);
1305cdf0e10cSrcweir m_pWindow->SetSettings(aSettings);
1306cdf0e10cSrcweir }
1307cdf0e10cSrcweir
1308cdf0e10cSrcweir implAdjustGenericFieldSetting( xUnoModel );
1309cdf0e10cSrcweir
1310cdf0e10cSrcweir static_cast< FormattedField* >( m_pWindow )->SetStrictFormat( sal_False );
1311cdf0e10cSrcweir static_cast< FormattedField* >( m_pPainter )->SetStrictFormat( sal_False );
1312cdf0e10cSrcweir // wenn man _irgendeine_ Formatierung zulaesst, kann man da sowieso keine Eingabe-Ueberpruefung
1313cdf0e10cSrcweir // machen (das FormattedField unterstuetzt das sowieso nicht, nur abgeleitete Klassen)
1314cdf0e10cSrcweir
1315cdf0e10cSrcweir // von dem Uno-Model den Formatter besorgen
1316cdf0e10cSrcweir // (Ich koennte theoretisch auch ueber den ::com::sun::star::util::NumberFormatter gehen, den mir der Cursor bestimmt
1317cdf0e10cSrcweir // liefern wuerde. Das Problem dabei ist, dass ich mich eigentlich nicht darauf verlassen
1318cdf0e10cSrcweir // kann, dass die beiden Formatter die selben sind, sauber ist das Ganze, wenn ich ueber das
1319cdf0e10cSrcweir // UNO-Model gehe.)
1320cdf0e10cSrcweir sal_Int32 nFormatKey = -1;
1321cdf0e10cSrcweir
1322cdf0e10cSrcweir // mal sehen, ob das Model einen hat ...
1323cdf0e10cSrcweir DBG_ASSERT(::comphelper::hasProperty(FM_PROP_FORMATSSUPPLIER, xUnoModel), "DbFormattedField::Init : invalid UNO model !");
1324cdf0e10cSrcweir Any aSupplier( xUnoModel->getPropertyValue(FM_PROP_FORMATSSUPPLIER));
1325cdf0e10cSrcweir if (aSupplier.hasValue())
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir ::cppu::extractInterface(m_xSupplier, aSupplier);
1328cdf0e10cSrcweir if (m_xSupplier.is())
1329cdf0e10cSrcweir {
1330cdf0e10cSrcweir // wenn wir den Supplier vom Model nehmen, dann auch den Key
1331cdf0e10cSrcweir Any aFmtKey( xUnoModel->getPropertyValue(FM_PROP_FORMATKEY));
1332cdf0e10cSrcweir if (aFmtKey.hasValue())
1333cdf0e10cSrcweir {
1334cdf0e10cSrcweir DBG_ASSERT(aFmtKey.getValueType().getTypeClass() == TypeClass_LONG, "DbFormattedField::Init : invalid format key property (no sal_Int32) !");
1335cdf0e10cSrcweir nFormatKey = ::comphelper::getINT32(aFmtKey);
1336cdf0e10cSrcweir }
1337cdf0e10cSrcweir else
1338cdf0e10cSrcweir {
1339cdf0e10cSrcweir DBG_WARNING("DbFormattedField::Init : my uno-model has no format-key, but a formats supplier !");
1340cdf0e10cSrcweir // the OFormattedModel which we usually are working with ensures that the model has a format key
1341cdf0e10cSrcweir // as soon as the form is loaded. Unfortunally this method here is called from within loaded, too.
1342cdf0e10cSrcweir // So if our LoadListener is called before the LoadListener of the model, this "else case" is
1343cdf0e10cSrcweir // allowed.
1344cdf0e10cSrcweir // Of course our property listener for the FormatKey property will notify us if the prop is changed,
1345cdf0e10cSrcweir // so this here isn't really bad ....
1346cdf0e10cSrcweir nFormatKey = 0;
1347cdf0e10cSrcweir }
1348cdf0e10cSrcweir }
1349cdf0e10cSrcweir }
1350cdf0e10cSrcweir
1351cdf0e10cSrcweir // nein ? vielleicht die ::com::sun::star::form::component::Form hinter dem Cursor ?
1352cdf0e10cSrcweir if (!m_xSupplier.is())
1353cdf0e10cSrcweir {
1354cdf0e10cSrcweir Reference< XRowSet > xCursorForm(xCursor, UNO_QUERY);
1355cdf0e10cSrcweir if (xCursorForm.is())
1356cdf0e10cSrcweir { // wenn wir vom Cursor den Formatter nehmen, dann auch den Key vom Feld, an das wir gebunden sind
1357cdf0e10cSrcweir m_xSupplier = getNumberFormats(getRowSetConnection(xCursorForm), sal_False);
1358cdf0e10cSrcweir
1359cdf0e10cSrcweir if (m_rColumn.GetField().is())
1360cdf0e10cSrcweir nFormatKey = ::comphelper::getINT32(m_rColumn.GetField()->getPropertyValue(FM_PROP_FORMATKEY));
1361cdf0e10cSrcweir }
1362cdf0e10cSrcweir }
1363cdf0e10cSrcweir
1364cdf0e10cSrcweir SvNumberFormatter* pFormatterUsed = NULL;
1365cdf0e10cSrcweir if (m_xSupplier.is())
1366cdf0e10cSrcweir {
1367cdf0e10cSrcweir SvNumberFormatsSupplierObj* pImplmentation = SvNumberFormatsSupplierObj::getImplementation(m_xSupplier);
1368cdf0e10cSrcweir if (pImplmentation)
1369cdf0e10cSrcweir pFormatterUsed = pImplmentation->GetNumberFormatter();
1370cdf0e10cSrcweir else
1371cdf0e10cSrcweir // alles hingfaellig : der Supplier ist vom falschen Typ, dann koennen wir uns auch nicht darauf verlassen, dass
1372cdf0e10cSrcweir // ein Standard-Formatter den (eventuell nicht-Standard-)Key kennt.
1373cdf0e10cSrcweir nFormatKey = -1;
1374cdf0e10cSrcweir }
1375cdf0e10cSrcweir
1376cdf0e10cSrcweir // einen Standard-Formatter ...
1377cdf0e10cSrcweir if (pFormatterUsed == NULL)
1378cdf0e10cSrcweir {
1379cdf0e10cSrcweir pFormatterUsed = ((FormattedField*)m_pWindow)->StandardFormatter();
1380cdf0e10cSrcweir DBG_ASSERT(pFormatterUsed != NULL, "DbFormattedField::Init : no standard formatter given by the numeric field !");
1381cdf0e10cSrcweir }
1382cdf0e10cSrcweir // ... und einen Standard-Key
1383cdf0e10cSrcweir if (nFormatKey == -1)
1384cdf0e10cSrcweir nFormatKey = 0;
1385cdf0e10cSrcweir
1386cdf0e10cSrcweir m_nKeyType = comphelper::getNumberFormatType(m_xSupplier->getNumberFormats(), nFormatKey);
1387cdf0e10cSrcweir
1388cdf0e10cSrcweir ((FormattedField*)m_pWindow)->SetFormatter(pFormatterUsed);
1389cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetFormatter(pFormatterUsed);
1390cdf0e10cSrcweir
1391cdf0e10cSrcweir ((FormattedField*)m_pWindow)->SetFormatKey(nFormatKey);
1392cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetFormatKey(nFormatKey);
1393cdf0e10cSrcweir
1394cdf0e10cSrcweir ((FormattedField*)m_pWindow)->TreatAsNumber(m_rColumn.IsNumeric());
1395cdf0e10cSrcweir ((FormattedField*)m_pPainter)->TreatAsNumber(m_rColumn.IsNumeric());
1396cdf0e10cSrcweir
1397cdf0e10cSrcweir // Min- und Max-Werte
1398cdf0e10cSrcweir if (m_rColumn.IsNumeric())
1399cdf0e10cSrcweir {
1400cdf0e10cSrcweir sal_Bool bClearMin = sal_True;
1401cdf0e10cSrcweir if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MIN, xUnoModel))
1402cdf0e10cSrcweir {
1403cdf0e10cSrcweir Any aMin( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_MIN));
1404cdf0e10cSrcweir if (aMin.getValueType().getTypeClass() != TypeClass_VOID)
1405cdf0e10cSrcweir {
1406cdf0e10cSrcweir DBG_ASSERT(aMin.getValueType().getTypeClass() == TypeClass_DOUBLE, "DbFormattedField::Init : the model has an invalid min value !");
1407cdf0e10cSrcweir double dMin = ::comphelper::getDouble(aMin);
1408cdf0e10cSrcweir ((FormattedField*)m_pWindow)->SetMinValue(dMin);
1409cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetMinValue(dMin);
1410cdf0e10cSrcweir bClearMin = sal_False;
1411cdf0e10cSrcweir }
1412cdf0e10cSrcweir }
1413cdf0e10cSrcweir if (bClearMin)
1414cdf0e10cSrcweir {
1415cdf0e10cSrcweir ((FormattedField*)m_pWindow)->ClearMinValue();
1416cdf0e10cSrcweir ((FormattedField*)m_pPainter)->ClearMinValue();
1417cdf0e10cSrcweir }
1418cdf0e10cSrcweir sal_Bool bClearMax = sal_True;
1419cdf0e10cSrcweir if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MAX, xUnoModel))
1420cdf0e10cSrcweir {
1421cdf0e10cSrcweir Any aMin( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_MAX));
1422cdf0e10cSrcweir if (aMin.getValueType().getTypeClass() != TypeClass_VOID)
1423cdf0e10cSrcweir {
1424cdf0e10cSrcweir DBG_ASSERT(aMin.getValueType().getTypeClass() == TypeClass_DOUBLE, "DbFormattedField::Init : the model has an invalid max value !");
1425cdf0e10cSrcweir double dMin = ::comphelper::getDouble(aMin);
1426cdf0e10cSrcweir ((FormattedField*)m_pWindow)->SetMaxValue(dMin);
1427cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetMaxValue(dMin);
1428cdf0e10cSrcweir bClearMax = sal_False;
1429cdf0e10cSrcweir }
1430cdf0e10cSrcweir }
1431cdf0e10cSrcweir if (bClearMax)
1432cdf0e10cSrcweir {
1433cdf0e10cSrcweir ((FormattedField*)m_pWindow)->ClearMaxValue();
1434cdf0e10cSrcweir ((FormattedField*)m_pPainter)->ClearMaxValue();
1435cdf0e10cSrcweir }
1436cdf0e10cSrcweir }
1437cdf0e10cSrcweir
1438cdf0e10cSrcweir // den Default-Wert
1439cdf0e10cSrcweir Any aDefault( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_DEFAULT));
1440cdf0e10cSrcweir if (aDefault.hasValue())
1441cdf0e10cSrcweir { // das Ding kann ein double oder ein String sein
1442cdf0e10cSrcweir switch (aDefault.getValueType().getTypeClass())
1443cdf0e10cSrcweir {
1444cdf0e10cSrcweir case TypeClass_DOUBLE:
1445cdf0e10cSrcweir if (m_rColumn.IsNumeric())
1446cdf0e10cSrcweir {
1447cdf0e10cSrcweir ((FormattedField*)m_pWindow)->SetDefaultValue(::comphelper::getDouble(aDefault));
1448cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetDefaultValue(::comphelper::getDouble(aDefault));
1449cdf0e10cSrcweir }
1450cdf0e10cSrcweir else
1451cdf0e10cSrcweir {
1452cdf0e10cSrcweir String sConverted;
1453cdf0e10cSrcweir Color* pDummy;
1454cdf0e10cSrcweir pFormatterUsed->GetOutputString(::comphelper::getDouble(aDefault), 0, sConverted, &pDummy);
1455cdf0e10cSrcweir ((FormattedField*)m_pWindow)->SetDefaultText(sConverted);
1456cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetDefaultText(sConverted);
1457cdf0e10cSrcweir }
1458cdf0e10cSrcweir break;
1459cdf0e10cSrcweir case TypeClass_STRING:
1460cdf0e10cSrcweir {
1461cdf0e10cSrcweir String sDefault( ::comphelper::getString(aDefault) );
1462cdf0e10cSrcweir if (m_rColumn.IsNumeric())
1463cdf0e10cSrcweir {
1464cdf0e10cSrcweir double dVal;
1465cdf0e10cSrcweir sal_uInt32 nTestFormat(0);
1466cdf0e10cSrcweir if (pFormatterUsed->IsNumberFormat(sDefault, nTestFormat, dVal))
1467cdf0e10cSrcweir {
1468cdf0e10cSrcweir ((FormattedField*)m_pWindow)->SetDefaultValue(dVal);
1469cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetDefaultValue(dVal);
1470cdf0e10cSrcweir }
1471cdf0e10cSrcweir }
1472cdf0e10cSrcweir else
1473cdf0e10cSrcweir {
1474cdf0e10cSrcweir ((FormattedField*)m_pWindow)->SetDefaultText(sDefault);
1475cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetDefaultText(sDefault);
1476cdf0e10cSrcweir }
1477cdf0e10cSrcweir }
1478cdf0e10cSrcweir default:
1479cdf0e10cSrcweir DBG_ERROR( "DbFormattedField::Init: unexpected value type!" );
1480cdf0e10cSrcweir break;
1481cdf0e10cSrcweir }
1482cdf0e10cSrcweir }
1483cdf0e10cSrcweir DbLimitedLengthField::Init( rParent, xCursor );
1484cdf0e10cSrcweir }
1485cdf0e10cSrcweir
1486cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateController() const1487cdf0e10cSrcweir CellControllerRef DbFormattedField::CreateController() const
1488cdf0e10cSrcweir {
1489cdf0e10cSrcweir return new ::svt::FormattedFieldCellController( static_cast< FormattedField* >( m_pWindow ) );
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir
1492cdf0e10cSrcweir //------------------------------------------------------------------------------
_propertyChanged(const PropertyChangeEvent & _rEvent)1493cdf0e10cSrcweir void DbFormattedField::_propertyChanged( const PropertyChangeEvent& _rEvent ) throw( RuntimeException )
1494cdf0e10cSrcweir {
1495cdf0e10cSrcweir if (_rEvent.PropertyName.compareTo(FM_PROP_FORMATKEY) == COMPARE_EQUAL)
1496cdf0e10cSrcweir {
1497cdf0e10cSrcweir sal_Int32 nNewKey = _rEvent.NewValue.hasValue() ? ::comphelper::getINT32(_rEvent.NewValue) : 0;
1498cdf0e10cSrcweir m_nKeyType = comphelper::getNumberFormatType(m_xSupplier->getNumberFormats(), nNewKey);
1499cdf0e10cSrcweir
1500cdf0e10cSrcweir DBG_ASSERT(m_pWindow && m_pPainter, "DbFormattedField::_propertyChanged : where are my windows ?");
1501cdf0e10cSrcweir if (m_pWindow)
1502cdf0e10cSrcweir static_cast< FormattedField* >( m_pWindow )->SetFormatKey( nNewKey );
1503cdf0e10cSrcweir if (m_pPainter)
1504cdf0e10cSrcweir static_cast< FormattedField* >( m_pPainter )->SetFormatKey( nNewKey );
1505cdf0e10cSrcweir }
1506cdf0e10cSrcweir else
1507cdf0e10cSrcweir {
1508cdf0e10cSrcweir DbLimitedLengthField::_propertyChanged( _rEvent );
1509cdf0e10cSrcweir }
1510cdf0e10cSrcweir }
1511cdf0e10cSrcweir
1512cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> &,Color ** ppColor)1513cdf0e10cSrcweir String DbFormattedField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** ppColor)
1514cdf0e10cSrcweir {
1515cdf0e10cSrcweir // defaultmaessig keine Farb-Angabe
1516cdf0e10cSrcweir if (ppColor != NULL)
1517cdf0e10cSrcweir *ppColor = NULL;
1518cdf0e10cSrcweir
1519cdf0e10cSrcweir // NULL-Wert -> leerer Text
1520cdf0e10cSrcweir if (!_rxField.is())
1521cdf0e10cSrcweir return String();
1522cdf0e10cSrcweir
1523cdf0e10cSrcweir String aText;
1524cdf0e10cSrcweir try
1525cdf0e10cSrcweir {
1526cdf0e10cSrcweir if (m_rColumn.IsNumeric())
1527cdf0e10cSrcweir {
1528cdf0e10cSrcweir // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern
1529cdf0e10cSrcweir // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an
1530cdf0e10cSrcweir // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst
1531cdf0e10cSrcweir // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann
1532cdf0e10cSrcweir // ich den Rest (die Formatierung) dem FormattedField ueberlassen.
1533cdf0e10cSrcweir double dValue = getValue( _rxField, m_rColumn.GetParent().getNullDate() );
1534cdf0e10cSrcweir if (_rxField->wasNull())
1535cdf0e10cSrcweir return aText;
1536cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetValue(dValue);
1537cdf0e10cSrcweir }
1538cdf0e10cSrcweir else
1539cdf0e10cSrcweir {
1540cdf0e10cSrcweir // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann.
1541cdf0e10cSrcweir // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen.
1542*24c56ab9SHerbert Dürr aText = _rxField->getString().getStr();
1543cdf0e10cSrcweir if (_rxField->wasNull())
1544cdf0e10cSrcweir return aText;
1545cdf0e10cSrcweir ((FormattedField*)m_pPainter)->SetTextFormatted(aText);
1546cdf0e10cSrcweir }
1547cdf0e10cSrcweir }
1548cdf0e10cSrcweir catch( const Exception& )
1549cdf0e10cSrcweir {
1550cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1551cdf0e10cSrcweir }
1552cdf0e10cSrcweir
1553cdf0e10cSrcweir aText = m_pPainter->GetText();
1554cdf0e10cSrcweir if (ppColor != NULL)
1555cdf0e10cSrcweir *ppColor = ((FormattedField*)m_pPainter)->GetLastOutputColor();
1556cdf0e10cSrcweir
1557cdf0e10cSrcweir return aText;
1558cdf0e10cSrcweir }
1559cdf0e10cSrcweir
1560cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> &)1561cdf0e10cSrcweir void DbFormattedField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/)
1562cdf0e10cSrcweir {
1563cdf0e10cSrcweir try
1564cdf0e10cSrcweir {
1565cdf0e10cSrcweir FormattedField* pFormattedWindow = static_cast<FormattedField*>(m_pWindow);
1566cdf0e10cSrcweir if (!_rxField.is())
1567cdf0e10cSrcweir { // NULL-Wert -> leerer Text
1568cdf0e10cSrcweir m_pWindow->SetText(String());
1569cdf0e10cSrcweir }
1570cdf0e10cSrcweir else if (m_rColumn.IsNumeric())
1571cdf0e10cSrcweir {
1572cdf0e10cSrcweir // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern
1573cdf0e10cSrcweir // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an
1574cdf0e10cSrcweir // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst
1575cdf0e10cSrcweir // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann
1576cdf0e10cSrcweir // ich den Rest (die Formatierung) dem FormattedField ueberlassen.
1577cdf0e10cSrcweir double dValue = getValue( _rxField, m_rColumn.GetParent().getNullDate() );
1578cdf0e10cSrcweir if (_rxField->wasNull())
1579cdf0e10cSrcweir m_pWindow->SetText(String());
1580cdf0e10cSrcweir else
1581cdf0e10cSrcweir pFormattedWindow->SetValue(dValue);
1582cdf0e10cSrcweir }
1583cdf0e10cSrcweir else
1584cdf0e10cSrcweir {
1585cdf0e10cSrcweir // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann.
1586cdf0e10cSrcweir // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen.
1587cdf0e10cSrcweir String sText( _rxField->getString());
1588cdf0e10cSrcweir
1589cdf0e10cSrcweir pFormattedWindow->SetTextFormatted( sText );
1590cdf0e10cSrcweir pFormattedWindow->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1591cdf0e10cSrcweir }
1592cdf0e10cSrcweir }
1593cdf0e10cSrcweir catch( const Exception& )
1594cdf0e10cSrcweir {
1595cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1596cdf0e10cSrcweir }
1597cdf0e10cSrcweir }
1598cdf0e10cSrcweir
1599cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)1600cdf0e10cSrcweir void DbFormattedField::updateFromModel( Reference< XPropertySet > _rxModel )
1601cdf0e10cSrcweir {
1602cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbFormattedField::updateFromModel: invalid call!" );
1603cdf0e10cSrcweir
1604cdf0e10cSrcweir FormattedField* pFormattedWindow = static_cast< FormattedField* >( m_pWindow );
1605cdf0e10cSrcweir
1606cdf0e10cSrcweir ::rtl::OUString sText;
1607cdf0e10cSrcweir Any aValue = _rxModel->getPropertyValue( FM_PROP_EFFECTIVE_VALUE );
1608cdf0e10cSrcweir if ( aValue >>= sText )
1609cdf0e10cSrcweir { // our effective value is transfered as string
1610cdf0e10cSrcweir pFormattedWindow->SetTextFormatted( sText );
1611cdf0e10cSrcweir pFormattedWindow->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1612cdf0e10cSrcweir }
1613cdf0e10cSrcweir else
1614cdf0e10cSrcweir {
1615cdf0e10cSrcweir double dValue = 0;
1616cdf0e10cSrcweir aValue >>= dValue;
1617cdf0e10cSrcweir pFormattedWindow->SetValue(dValue);
1618cdf0e10cSrcweir }
1619cdf0e10cSrcweir }
1620cdf0e10cSrcweir
1621cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()1622cdf0e10cSrcweir sal_Bool DbFormattedField::commitControl()
1623cdf0e10cSrcweir {
1624cdf0e10cSrcweir Any aNewVal;
1625cdf0e10cSrcweir FormattedField& rField = *(FormattedField*)m_pWindow;
1626cdf0e10cSrcweir DBG_ASSERT(&rField == m_pWindow, "DbFormattedField::commitControl : can't work with a window other than my own !");
1627cdf0e10cSrcweir if (m_rColumn.IsNumeric())
1628cdf0e10cSrcweir {
1629cdf0e10cSrcweir if (rField.GetText().Len() != 0)
1630cdf0e10cSrcweir aNewVal <<= rField.GetValue();
1631cdf0e10cSrcweir // ein LeerString wird erst mal standardmaessig als void weitergereicht
1632cdf0e10cSrcweir }
1633cdf0e10cSrcweir else
1634cdf0e10cSrcweir aNewVal <<= ::rtl::OUString(rField.GetTextValue());
1635cdf0e10cSrcweir
1636cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue(FM_PROP_EFFECTIVE_VALUE, aNewVal);
1637cdf0e10cSrcweir return sal_True;
1638cdf0e10cSrcweir }
1639cdf0e10cSrcweir
1640cdf0e10cSrcweir //==============================================================================
1641cdf0e10cSrcweir //= DbCheckBox
1642cdf0e10cSrcweir //==============================================================================
1643cdf0e10cSrcweir //------------------------------------------------------------------------------
DbCheckBox(DbGridColumn & _rColumn)1644cdf0e10cSrcweir DbCheckBox::DbCheckBox( DbGridColumn& _rColumn )
1645cdf0e10cSrcweir :DbCellControl( _rColumn, sal_True )
1646cdf0e10cSrcweir {
1647cdf0e10cSrcweir setAlignedController( sal_False );
1648cdf0e10cSrcweir }
1649cdf0e10cSrcweir
1650cdf0e10cSrcweir namespace
1651cdf0e10cSrcweir {
setCheckBoxStyle(Window * _pWindow,bool bMono)1652cdf0e10cSrcweir void setCheckBoxStyle( Window* _pWindow, bool bMono )
1653cdf0e10cSrcweir {
1654cdf0e10cSrcweir AllSettings aSettings = _pWindow->GetSettings();
1655cdf0e10cSrcweir StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1656cdf0e10cSrcweir if( bMono )
1657cdf0e10cSrcweir aStyleSettings.SetOptions( aStyleSettings.GetOptions() | STYLE_OPTION_MONO );
1658cdf0e10cSrcweir else
1659cdf0e10cSrcweir aStyleSettings.SetOptions( aStyleSettings.GetOptions() & (~STYLE_OPTION_MONO) );
1660cdf0e10cSrcweir aSettings.SetStyleSettings( aStyleSettings );
1661cdf0e10cSrcweir _pWindow->SetSettings( aSettings );
1662cdf0e10cSrcweir }
1663cdf0e10cSrcweir }
1664cdf0e10cSrcweir
1665cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & rParent,const Reference<XRowSet> & xCursor)1666cdf0e10cSrcweir void DbCheckBox::Init( Window& rParent, const Reference< XRowSet >& xCursor )
1667cdf0e10cSrcweir {
1668cdf0e10cSrcweir setTransparent( sal_True );
1669cdf0e10cSrcweir
1670cdf0e10cSrcweir m_pWindow = new CheckBoxControl( &rParent );
1671cdf0e10cSrcweir m_pPainter = new CheckBoxControl( &rParent );
1672cdf0e10cSrcweir
1673cdf0e10cSrcweir m_pWindow->SetPaintTransparent( sal_True );
1674cdf0e10cSrcweir m_pPainter->SetPaintTransparent( sal_True );
1675cdf0e10cSrcweir
1676cdf0e10cSrcweir m_pPainter->SetBackground();
1677cdf0e10cSrcweir
1678cdf0e10cSrcweir try
1679cdf0e10cSrcweir {
1680cdf0e10cSrcweir Reference< XPropertySet > xModel( m_rColumn.getModel(), UNO_SET_THROW );
1681cdf0e10cSrcweir
1682cdf0e10cSrcweir sal_Int16 nStyle = awt::VisualEffect::LOOK3D;
1683cdf0e10cSrcweir OSL_VERIFY( xModel->getPropertyValue( FM_PROP_VISUALEFFECT ) >>= nStyle );
1684cdf0e10cSrcweir
1685cdf0e10cSrcweir setCheckBoxStyle( m_pWindow, nStyle == awt::VisualEffect::FLAT );
1686cdf0e10cSrcweir setCheckBoxStyle( m_pPainter, nStyle == awt::VisualEffect::FLAT );
1687cdf0e10cSrcweir
1688cdf0e10cSrcweir sal_Bool bTristate = sal_True;
1689cdf0e10cSrcweir OSL_VERIFY( xModel->getPropertyValue( FM_PROP_TRISTATE ) >>= bTristate );
1690cdf0e10cSrcweir static_cast< CheckBoxControl* >( m_pWindow )->GetBox().EnableTriState( bTristate );
1691cdf0e10cSrcweir static_cast< CheckBoxControl* >( m_pPainter )->GetBox().EnableTriState( bTristate );
1692cdf0e10cSrcweir }
1693cdf0e10cSrcweir catch( const Exception& )
1694cdf0e10cSrcweir {
1695cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1696cdf0e10cSrcweir }
1697cdf0e10cSrcweir
1698cdf0e10cSrcweir DbCellControl::Init( rParent, xCursor );
1699cdf0e10cSrcweir }
1700cdf0e10cSrcweir
1701cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateController() const1702cdf0e10cSrcweir CellControllerRef DbCheckBox::CreateController() const
1703cdf0e10cSrcweir {
1704cdf0e10cSrcweir return new CheckBoxCellController((CheckBoxControl*)m_pWindow);
1705cdf0e10cSrcweir }
1706cdf0e10cSrcweir //------------------------------------------------------------------------------
lcl_setCheckBoxState(const Reference<::com::sun::star::sdb::XColumn> & _rxField,CheckBoxControl * _pCheckBoxControl)1707cdf0e10cSrcweir static void lcl_setCheckBoxState( const Reference< ::com::sun::star::sdb::XColumn >& _rxField,
1708cdf0e10cSrcweir CheckBoxControl* _pCheckBoxControl )
1709cdf0e10cSrcweir {
1710cdf0e10cSrcweir TriState eState = STATE_DONTKNOW;
1711cdf0e10cSrcweir if (_rxField.is())
1712cdf0e10cSrcweir {
1713cdf0e10cSrcweir try
1714cdf0e10cSrcweir {
1715cdf0e10cSrcweir sal_Bool bValue = _rxField->getBoolean();
1716cdf0e10cSrcweir if (!_rxField->wasNull())
1717cdf0e10cSrcweir eState = bValue ? STATE_CHECK : STATE_NOCHECK;
1718cdf0e10cSrcweir }
1719cdf0e10cSrcweir catch( const Exception& )
1720cdf0e10cSrcweir {
1721cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
1722cdf0e10cSrcweir }
1723cdf0e10cSrcweir }
1724cdf0e10cSrcweir _pCheckBoxControl->GetBox().SetState(eState);
1725cdf0e10cSrcweir }
1726cdf0e10cSrcweir
1727cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> &)1728cdf0e10cSrcweir void DbCheckBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/)
1729cdf0e10cSrcweir {
1730cdf0e10cSrcweir lcl_setCheckBoxState( _rxField, static_cast<CheckBoxControl*>(m_pWindow) );
1731cdf0e10cSrcweir }
1732cdf0e10cSrcweir
1733cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintFieldToCell(OutputDevice & rDev,const Rectangle & rRect,const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter)1734cdf0e10cSrcweir void DbCheckBox::PaintFieldToCell(OutputDevice& rDev, const Rectangle& rRect,
1735cdf0e10cSrcweir const Reference< ::com::sun::star::sdb::XColumn >& _rxField,
1736cdf0e10cSrcweir const Reference< XNumberFormatter >& xFormatter)
1737cdf0e10cSrcweir {
1738cdf0e10cSrcweir lcl_setCheckBoxState( _rxField, static_cast<CheckBoxControl*>(m_pPainter) );
1739cdf0e10cSrcweir DbCellControl::PaintFieldToCell( rDev, rRect, _rxField, xFormatter );
1740cdf0e10cSrcweir }
1741cdf0e10cSrcweir
1742cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)1743cdf0e10cSrcweir void DbCheckBox::updateFromModel( Reference< XPropertySet > _rxModel )
1744cdf0e10cSrcweir {
1745cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbCheckBox::updateFromModel: invalid call!" );
1746cdf0e10cSrcweir
1747cdf0e10cSrcweir sal_Int16 nState = STATE_DONTKNOW;
1748cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_STATE ) >>= nState;
1749cdf0e10cSrcweir static_cast< CheckBoxControl* >( m_pWindow )->GetBox().SetState( static_cast< TriState >( nState ) );
1750cdf0e10cSrcweir }
1751cdf0e10cSrcweir
1752cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()1753cdf0e10cSrcweir sal_Bool DbCheckBox::commitControl()
1754cdf0e10cSrcweir {
1755cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
1756cdf0e10cSrcweir Any aVal = makeAny( (sal_Int16)( static_cast< CheckBoxControl* >( m_pWindow )->GetBox().GetState() ) );
1757cdf0e10cSrcweir #endif
1758cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue( FM_PROP_STATE,
1759cdf0e10cSrcweir makeAny( (sal_Int16)( static_cast< CheckBoxControl* >( m_pWindow )->GetBox().GetState() ) ) );
1760cdf0e10cSrcweir return sal_True;
1761cdf0e10cSrcweir }
1762cdf0e10cSrcweir
1763cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<XColumn> &,const Reference<XNumberFormatter> &,Color **)1764cdf0e10cSrcweir XubString DbCheckBox::GetFormatText(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
1765cdf0e10cSrcweir {
1766cdf0e10cSrcweir return XubString();
1767cdf0e10cSrcweir }
1768cdf0e10cSrcweir
1769cdf0e10cSrcweir //==============================================================================
1770cdf0e10cSrcweir //= DbPatternField
1771cdf0e10cSrcweir //------------------------------------------------------------------------------
DbPatternField(DbGridColumn & _rColumn,const::comphelper::ComponentContext & _rContext)1772cdf0e10cSrcweir DbPatternField::DbPatternField( DbGridColumn& _rColumn, const ::comphelper::ComponentContext& _rContext )
1773cdf0e10cSrcweir :DbCellControl( _rColumn )
1774cdf0e10cSrcweir ,m_aContext( _rContext )
1775cdf0e10cSrcweir {
1776cdf0e10cSrcweir doPropertyListening( FM_PROP_LITERALMASK );
1777cdf0e10cSrcweir doPropertyListening( FM_PROP_EDITMASK );
1778cdf0e10cSrcweir doPropertyListening( FM_PROP_STRICTFORMAT );
1779cdf0e10cSrcweir }
1780cdf0e10cSrcweir
1781cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> & _rxModel)1782cdf0e10cSrcweir void DbPatternField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
1783cdf0e10cSrcweir {
1784cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbPatternField::implAdjustGenericFieldSetting: not to be called without window!" );
1785cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbPatternField::implAdjustGenericFieldSetting: invalid model!" );
1786cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
1787cdf0e10cSrcweir {
1788cdf0e10cSrcweir ::rtl::OUString aLitMask;
1789cdf0e10cSrcweir ::rtl::OUString aEditMask;
1790cdf0e10cSrcweir sal_Bool bStrict = sal_False;
1791cdf0e10cSrcweir
1792cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_LITERALMASK ) >>= aLitMask;
1793cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_EDITMASK ) >>= aEditMask;
1794cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) >>= bStrict;
1795cdf0e10cSrcweir
1796cdf0e10cSrcweir ByteString aAsciiEditMask( aEditMask.getStr(), RTL_TEXTENCODING_ASCII_US );
1797cdf0e10cSrcweir
1798cdf0e10cSrcweir static_cast< PatternField* >( m_pWindow )->SetMask( aAsciiEditMask, aLitMask );
1799cdf0e10cSrcweir static_cast< PatternField* >( m_pPainter )->SetMask( aAsciiEditMask, aLitMask );
1800cdf0e10cSrcweir static_cast< PatternField* >( m_pWindow )->SetStrictFormat( bStrict );
1801cdf0e10cSrcweir static_cast< PatternField* >( m_pPainter )->SetStrictFormat( bStrict );
1802cdf0e10cSrcweir }
1803cdf0e10cSrcweir }
1804cdf0e10cSrcweir
1805cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & rParent,const Reference<XRowSet> & xCursor)1806cdf0e10cSrcweir void DbPatternField::Init( Window& rParent, const Reference< XRowSet >& xCursor)
1807cdf0e10cSrcweir {
1808cdf0e10cSrcweir m_rColumn.SetAlignmentFromModel(-1);
1809cdf0e10cSrcweir
1810cdf0e10cSrcweir m_pWindow = new PatternField( &rParent, 0 );
1811cdf0e10cSrcweir m_pPainter= new PatternField( &rParent, 0 );
1812cdf0e10cSrcweir
1813cdf0e10cSrcweir Reference< XPropertySet > xModel( m_rColumn.getModel() );
1814cdf0e10cSrcweir implAdjustGenericFieldSetting( xModel );
1815cdf0e10cSrcweir
1816cdf0e10cSrcweir DbCellControl::Init( rParent, xCursor );
1817cdf0e10cSrcweir }
1818cdf0e10cSrcweir
1819cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateController() const1820cdf0e10cSrcweir CellControllerRef DbPatternField::CreateController() const
1821cdf0e10cSrcweir {
1822cdf0e10cSrcweir return new SpinCellController( static_cast< PatternField* >( m_pWindow ) );
1823cdf0e10cSrcweir }
1824cdf0e10cSrcweir
1825cdf0e10cSrcweir //------------------------------------------------------------------------------
impl_formatText(const String & _rText)1826cdf0e10cSrcweir String DbPatternField::impl_formatText( const String& _rText )
1827cdf0e10cSrcweir {
1828cdf0e10cSrcweir m_pPainter->SetText( _rText );
1829cdf0e10cSrcweir static_cast< PatternField* >( m_pPainter )->ReformatAll();
1830cdf0e10cSrcweir return m_pPainter->GetText();
1831cdf0e10cSrcweir }
1832cdf0e10cSrcweir
1833cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> &,Color **)1834cdf0e10cSrcweir String DbPatternField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
1835cdf0e10cSrcweir {
1836cdf0e10cSrcweir bool bIsForPaint = _rxField != m_rColumn.GetField();
1837cdf0e10cSrcweir ::std::auto_ptr< ::dbtools::FormattedColumnValue >& rpFormatter = bIsForPaint ? m_pPaintFormatter : m_pValueFormatter;
1838cdf0e10cSrcweir
1839cdf0e10cSrcweir if ( !rpFormatter.get() )
1840cdf0e10cSrcweir {
1841cdf0e10cSrcweir DBToolsObjectFactory aFactory;
1842cdf0e10cSrcweir rpFormatter = aFactory.createFormattedColumnValue(
1843cdf0e10cSrcweir m_aContext, getCursor(), Reference< XPropertySet >( _rxField, UNO_QUERY ) );
1844cdf0e10cSrcweir OSL_ENSURE( rpFormatter.get(), "DbPatternField::Init: no value formatter!" );
1845cdf0e10cSrcweir }
1846cdf0e10cSrcweir else
1847cdf0e10cSrcweir OSL_ENSURE( rpFormatter->getColumn() == _rxField, "DbPatternField::GetFormatText: my value formatter is working for another field ...!" );
1848cdf0e10cSrcweir // re-creating the value formatter here everytime would be quite expensive ...
1849cdf0e10cSrcweir
1850cdf0e10cSrcweir String sText;
1851cdf0e10cSrcweir if ( rpFormatter.get() )
1852cdf0e10cSrcweir sText = rpFormatter->getFormattedValue();
1853cdf0e10cSrcweir
1854cdf0e10cSrcweir return impl_formatText( sText );
1855cdf0e10cSrcweir }
1856cdf0e10cSrcweir
1857cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<XColumn> & _rxField,const Reference<XNumberFormatter> & _rxFormatter)1858cdf0e10cSrcweir void DbPatternField::UpdateFromField( const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
1859cdf0e10cSrcweir {
1860cdf0e10cSrcweir static_cast< Edit* >( m_pWindow )->SetText( GetFormatText( _rxField, _rxFormatter ) );
1861cdf0e10cSrcweir static_cast< Edit* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1862cdf0e10cSrcweir }
1863cdf0e10cSrcweir
1864cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)1865cdf0e10cSrcweir void DbPatternField::updateFromModel( Reference< XPropertySet > _rxModel )
1866cdf0e10cSrcweir {
1867cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbPatternField::updateFromModel: invalid call!" );
1868cdf0e10cSrcweir
1869cdf0e10cSrcweir ::rtl::OUString sText;
1870cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText;
1871cdf0e10cSrcweir
1872cdf0e10cSrcweir static_cast< Edit* >( m_pWindow )->SetText( impl_formatText( sText ) );
1873cdf0e10cSrcweir static_cast< Edit* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1874cdf0e10cSrcweir }
1875cdf0e10cSrcweir
1876cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()1877cdf0e10cSrcweir sal_Bool DbPatternField::commitControl()
1878cdf0e10cSrcweir {
1879cdf0e10cSrcweir String aText(m_pWindow->GetText());
1880cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue(FM_PROP_TEXT, makeAny(::rtl::OUString(aText)));
1881cdf0e10cSrcweir return sal_True;
1882cdf0e10cSrcweir }
1883cdf0e10cSrcweir
1884cdf0e10cSrcweir //==============================================================================
1885cdf0e10cSrcweir //= DbSpinField
1886cdf0e10cSrcweir //==============================================================================
1887cdf0e10cSrcweir //------------------------------------------------------------------------------
DbSpinField(DbGridColumn & _rColumn,sal_Int16 _nStandardAlign)1888cdf0e10cSrcweir DbSpinField::DbSpinField( DbGridColumn& _rColumn, sal_Int16 _nStandardAlign )
1889cdf0e10cSrcweir :DbCellControl( _rColumn )
1890cdf0e10cSrcweir ,m_nStandardAlign( _nStandardAlign )
1891cdf0e10cSrcweir {
1892cdf0e10cSrcweir }
1893cdf0e10cSrcweir
1894cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & _rParent,const Reference<XRowSet> & _rxCursor)1895cdf0e10cSrcweir void DbSpinField::Init( Window& _rParent, const Reference< XRowSet >& _rxCursor )
1896cdf0e10cSrcweir {
1897cdf0e10cSrcweir m_rColumn.SetAlignmentFromModel( m_nStandardAlign );
1898cdf0e10cSrcweir
1899cdf0e10cSrcweir Reference< XPropertySet > xModel( m_rColumn.getModel() );
1900cdf0e10cSrcweir
1901cdf0e10cSrcweir // determine the WinBits for the field
1902cdf0e10cSrcweir WinBits nFieldStyle = 0;
1903cdf0e10cSrcweir if ( ::comphelper::getBOOL( xModel->getPropertyValue( FM_PROP_SPIN ) ) )
1904cdf0e10cSrcweir nFieldStyle = WB_REPEAT | WB_SPIN;
1905cdf0e10cSrcweir // create the fields
1906cdf0e10cSrcweir m_pWindow = createField( &_rParent, nFieldStyle, xModel );
1907cdf0e10cSrcweir m_pPainter = createField( &_rParent, nFieldStyle, xModel );
1908cdf0e10cSrcweir
1909cdf0e10cSrcweir // adjust all other settings which depend on the property values
1910cdf0e10cSrcweir implAdjustGenericFieldSetting( xModel );
1911cdf0e10cSrcweir
1912cdf0e10cSrcweir // call the base class
1913cdf0e10cSrcweir DbCellControl::Init( _rParent, _rxCursor );
1914cdf0e10cSrcweir }
1915cdf0e10cSrcweir
1916cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateController() const1917cdf0e10cSrcweir CellControllerRef DbSpinField::CreateController() const
1918cdf0e10cSrcweir {
1919cdf0e10cSrcweir return new SpinCellController( static_cast< SpinField* >( m_pWindow ) );
1920cdf0e10cSrcweir }
1921cdf0e10cSrcweir
1922cdf0e10cSrcweir //==============================================================================
1923cdf0e10cSrcweir //= DbNumericField
1924cdf0e10cSrcweir //==============================================================================
1925cdf0e10cSrcweir //------------------------------------------------------------------------------
DbNumericField(DbGridColumn & _rColumn)1926cdf0e10cSrcweir DbNumericField::DbNumericField( DbGridColumn& _rColumn )
1927cdf0e10cSrcweir :DbSpinField( _rColumn )
1928cdf0e10cSrcweir {
1929cdf0e10cSrcweir doPropertyListening( FM_PROP_DECIMAL_ACCURACY );
1930cdf0e10cSrcweir doPropertyListening( FM_PROP_VALUEMIN );
1931cdf0e10cSrcweir doPropertyListening( FM_PROP_VALUEMAX );
1932cdf0e10cSrcweir doPropertyListening( FM_PROP_VALUESTEP );
1933cdf0e10cSrcweir doPropertyListening( FM_PROP_STRICTFORMAT );
1934cdf0e10cSrcweir doPropertyListening( FM_PROP_SHOWTHOUSANDSEP );
1935cdf0e10cSrcweir }
1936cdf0e10cSrcweir
1937cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> & _rxModel)1938cdf0e10cSrcweir void DbNumericField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
1939cdf0e10cSrcweir {
1940cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbNumericField::implAdjustGenericFieldSetting: not to be called without window!" );
1941cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbNumericField::implAdjustGenericFieldSetting: invalid model!" );
1942cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
1943cdf0e10cSrcweir {
1944cdf0e10cSrcweir sal_Int32 nMin = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMIN ) );
1945cdf0e10cSrcweir sal_Int32 nMax = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMAX ) );
1946cdf0e10cSrcweir sal_Int32 nStep = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUESTEP ) );
1947cdf0e10cSrcweir sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) );
1948cdf0e10cSrcweir sal_Int16 nScale = getINT16( _rxModel->getPropertyValue( FM_PROP_DECIMAL_ACCURACY ) );
1949cdf0e10cSrcweir sal_Bool bThousand = getBOOL( _rxModel->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP ) );
1950cdf0e10cSrcweir
1951cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pWindow )->SetMinValue(nMin);
1952cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pWindow )->SetMaxValue(nMax);
1953cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pWindow )->SetSpinSize(nStep);
1954cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pWindow )->SetStrictFormat(bStrict);
1955cdf0e10cSrcweir
1956cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pPainter )->SetMinValue(nMin);
1957cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pPainter )->SetMaxValue(nMax);
1958cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pPainter )->SetStrictFormat(bStrict);
1959cdf0e10cSrcweir
1960cdf0e10cSrcweir
1961cdf0e10cSrcweir // dem Field und dem Painter einen Formatter spendieren
1962cdf0e10cSrcweir // zuerst testen, ob ich von dem Service hinter einer Connection bekommen kann
1963cdf0e10cSrcweir Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier;
1964cdf0e10cSrcweir Reference< XRowSet > xForm;
1965cdf0e10cSrcweir if ( m_rColumn.GetParent().getDataSource() )
1966cdf0e10cSrcweir xForm = Reference< XRowSet >( ( Reference< XInterface > )*m_rColumn.GetParent().getDataSource(), UNO_QUERY );
1967cdf0e10cSrcweir if ( xForm.is() )
1968cdf0e10cSrcweir xSupplier = getNumberFormats( getRowSetConnection( xForm ), sal_True );
1969cdf0e10cSrcweir SvNumberFormatter* pFormatterUsed = NULL;
1970cdf0e10cSrcweir if ( xSupplier.is() )
1971cdf0e10cSrcweir {
1972cdf0e10cSrcweir SvNumberFormatsSupplierObj* pImplmentation = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
1973cdf0e10cSrcweir pFormatterUsed = pImplmentation ? pImplmentation->GetNumberFormatter() : NULL;
1974cdf0e10cSrcweir }
1975cdf0e10cSrcweir if ( NULL == pFormatterUsed )
1976cdf0e10cSrcweir { // der Cursor fuehrte nicht zum Erfolg -> Standard
1977cdf0e10cSrcweir pFormatterUsed = static_cast< DoubleNumericField* >( m_pWindow )->StandardFormatter();
1978cdf0e10cSrcweir DBG_ASSERT( pFormatterUsed != NULL, "DbNumericField::implAdjustGenericFieldSetting: no standard formatter given by the numeric field !" );
1979cdf0e10cSrcweir }
1980cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pWindow )->SetFormatter( pFormatterUsed );
1981cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pPainter )->SetFormatter( pFormatterUsed );
1982cdf0e10cSrcweir
1983cdf0e10cSrcweir // und dann ein Format generieren, dass die gewuenschten Nachkommastellen usw. hat
1984cdf0e10cSrcweir String sFormatString;
1985cdf0e10cSrcweir LanguageType aAppLanguage = Application::GetSettings().GetUILanguage();
1986cdf0e10cSrcweir pFormatterUsed->GenerateFormat( sFormatString, 0, aAppLanguage, bThousand, sal_False, nScale );
1987cdf0e10cSrcweir
1988cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pWindow )->SetFormat( sFormatString, aAppLanguage );
1989cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pPainter )->SetFormat( sFormatString, aAppLanguage );
1990cdf0e10cSrcweir }
1991cdf0e10cSrcweir }
1992cdf0e10cSrcweir
1993cdf0e10cSrcweir //------------------------------------------------------------------------------
createField(Window * _pParent,WinBits _nFieldStyle,const Reference<XPropertySet> &)1994cdf0e10cSrcweir SpinField* DbNumericField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ )
1995cdf0e10cSrcweir {
1996cdf0e10cSrcweir return new DoubleNumericField( _pParent, _nFieldStyle );
1997cdf0e10cSrcweir }
1998cdf0e10cSrcweir
1999cdf0e10cSrcweir namespace
2000cdf0e10cSrcweir {
2001cdf0e10cSrcweir //--------------------------------------------------------------------------
lcl_setFormattedNumeric_nothrow(DoubleNumericField & _rField,const DbCellControl & _rControl,const Reference<XColumn> & _rxField,const Reference<XNumberFormatter> & _rxFormatter)2002cdf0e10cSrcweir static String lcl_setFormattedNumeric_nothrow( DoubleNumericField& _rField, const DbCellControl& _rControl,
2003cdf0e10cSrcweir const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
2004cdf0e10cSrcweir {
2005cdf0e10cSrcweir String sValue;
2006cdf0e10cSrcweir if ( _rxField.is() )
2007cdf0e10cSrcweir {
2008cdf0e10cSrcweir try
2009cdf0e10cSrcweir {
2010cdf0e10cSrcweir double fValue = _rControl.GetValue( _rxField, _rxFormatter );
2011cdf0e10cSrcweir if ( !_rxField->wasNull() )
2012cdf0e10cSrcweir {
2013cdf0e10cSrcweir _rField.SetValue( fValue );
2014cdf0e10cSrcweir sValue = _rField.GetText();
2015cdf0e10cSrcweir }
2016cdf0e10cSrcweir }
2017cdf0e10cSrcweir catch( const Exception& )
2018cdf0e10cSrcweir {
2019cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
2020cdf0e10cSrcweir }
2021cdf0e10cSrcweir }
2022cdf0e10cSrcweir return sValue;
2023cdf0e10cSrcweir }
2024cdf0e10cSrcweir }
2025cdf0e10cSrcweir
2026cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<::com::sun::star::util::XNumberFormatter> & _rxFormatter,Color **)2027cdf0e10cSrcweir String DbNumericField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, Color** /*ppColor*/)
2028cdf0e10cSrcweir {
2029cdf0e10cSrcweir return lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField* >( m_pPainter ), *this, _rxField, _rxFormatter );
2030cdf0e10cSrcweir }
2031cdf0e10cSrcweir
2032cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<::com::sun::star::util::XNumberFormatter> & _rxFormatter)2033cdf0e10cSrcweir void DbNumericField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
2034cdf0e10cSrcweir {
2035cdf0e10cSrcweir lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField* >( m_pWindow ), *this, _rxField, _rxFormatter );
2036cdf0e10cSrcweir }
2037cdf0e10cSrcweir
2038cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)2039cdf0e10cSrcweir void DbNumericField::updateFromModel( Reference< XPropertySet > _rxModel )
2040cdf0e10cSrcweir {
2041cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbNumericField::updateFromModel: invalid call!" );
2042cdf0e10cSrcweir
2043cdf0e10cSrcweir double dValue = 0;
2044cdf0e10cSrcweir if ( _rxModel->getPropertyValue( FM_PROP_VALUE ) >>= dValue )
2045cdf0e10cSrcweir static_cast< DoubleNumericField* >( m_pWindow )->SetValue( dValue );
2046cdf0e10cSrcweir else
2047cdf0e10cSrcweir m_pWindow->SetText( String() );
2048cdf0e10cSrcweir }
2049cdf0e10cSrcweir
2050cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()2051cdf0e10cSrcweir sal_Bool DbNumericField::commitControl()
2052cdf0e10cSrcweir {
2053cdf0e10cSrcweir String aText( m_pWindow->GetText());
2054cdf0e10cSrcweir Any aVal;
2055cdf0e10cSrcweir
2056cdf0e10cSrcweir if (aText.Len() != 0) // nicht null
2057cdf0e10cSrcweir {
2058cdf0e10cSrcweir double fValue = ((DoubleNumericField*)m_pWindow)->GetValue();
2059cdf0e10cSrcweir aVal <<= (double)fValue;
2060cdf0e10cSrcweir }
2061cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue(FM_PROP_VALUE, aVal);
2062cdf0e10cSrcweir return sal_True;
2063cdf0e10cSrcweir }
2064cdf0e10cSrcweir
2065cdf0e10cSrcweir //==============================================================================
2066cdf0e10cSrcweir //= DbCurrencyField
2067cdf0e10cSrcweir //==============================================================================
2068cdf0e10cSrcweir //------------------------------------------------------------------------------
DbCurrencyField(DbGridColumn & _rColumn)2069cdf0e10cSrcweir DbCurrencyField::DbCurrencyField(DbGridColumn& _rColumn)
2070cdf0e10cSrcweir :DbSpinField( _rColumn )
2071cdf0e10cSrcweir ,m_nScale( 0 )
2072cdf0e10cSrcweir {
2073cdf0e10cSrcweir doPropertyListening( FM_PROP_DECIMAL_ACCURACY );
2074cdf0e10cSrcweir doPropertyListening( FM_PROP_VALUEMIN );
2075cdf0e10cSrcweir doPropertyListening( FM_PROP_VALUEMAX );
2076cdf0e10cSrcweir doPropertyListening( FM_PROP_VALUESTEP );
2077cdf0e10cSrcweir doPropertyListening( FM_PROP_STRICTFORMAT );
2078cdf0e10cSrcweir doPropertyListening( FM_PROP_SHOWTHOUSANDSEP );
2079cdf0e10cSrcweir doPropertyListening( FM_PROP_CURRENCYSYMBOL );
2080cdf0e10cSrcweir }
2081cdf0e10cSrcweir
2082cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> & _rxModel)2083cdf0e10cSrcweir void DbCurrencyField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2084cdf0e10cSrcweir {
2085cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbCurrencyField::implAdjustGenericFieldSetting: not to be called without window!" );
2086cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbCurrencyField::implAdjustGenericFieldSetting: invalid model!" );
2087cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
2088cdf0e10cSrcweir {
2089cdf0e10cSrcweir m_nScale = getINT16( _rxModel->getPropertyValue( FM_PROP_DECIMAL_ACCURACY ) );
2090cdf0e10cSrcweir double nMin = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMIN ) );
2091cdf0e10cSrcweir double nMax = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMAX ) );
2092cdf0e10cSrcweir double nStep = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUESTEP ) );
2093cdf0e10cSrcweir sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) );
2094cdf0e10cSrcweir sal_Bool bThousand = getBOOL( _rxModel->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP ) );
2095cdf0e10cSrcweir ::rtl::OUString aStr( getString( _rxModel->getPropertyValue(FM_PROP_CURRENCYSYMBOL ) ) );
2096cdf0e10cSrcweir
2097cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetUseThousandSep( bThousand );
2098cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetDecimalDigits( m_nScale );
2099cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetCurrencySymbol( aStr );
2100cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetFirst( nMin );
2101cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetLast( nMax );
2102cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetMin( nMin );
2103cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetMax( nMax );
2104cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetSpinSize( nStep );
2105cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetStrictFormat( bStrict );
2106cdf0e10cSrcweir
2107cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pPainter )->SetUseThousandSep( bThousand );
2108cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pPainter )->SetDecimalDigits( m_nScale );
2109cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pPainter )->SetCurrencySymbol( aStr );
2110cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pPainter )->SetFirst( nMin );
2111cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pPainter )->SetLast( nMax );
2112cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pPainter )->SetMin( nMin );
2113cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pPainter )->SetMax( nMax );
2114cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pPainter )->SetStrictFormat( bStrict );
2115cdf0e10cSrcweir }
2116cdf0e10cSrcweir }
2117cdf0e10cSrcweir
2118cdf0e10cSrcweir //------------------------------------------------------------------------------
createField(Window * _pParent,WinBits _nFieldStyle,const Reference<XPropertySet> &)2119cdf0e10cSrcweir SpinField* DbCurrencyField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ )
2120cdf0e10cSrcweir {
2121cdf0e10cSrcweir return new LongCurrencyField( _pParent, _nFieldStyle );
2122cdf0e10cSrcweir }
2123cdf0e10cSrcweir
2124cdf0e10cSrcweir //------------------------------------------------------------------------------
GetCurrency(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter) const2125cdf0e10cSrcweir double DbCurrencyField::GetCurrency(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) const
2126cdf0e10cSrcweir {
2127cdf0e10cSrcweir double fValue = GetValue(_rxField, xFormatter);
2128cdf0e10cSrcweir if (m_nScale)
2129cdf0e10cSrcweir {
2130cdf0e10cSrcweir // OSL_TRACE("double = %.64f ",fValue);
2131cdf0e10cSrcweir fValue = ::rtl::math::pow10Exp(fValue, m_nScale);
2132cdf0e10cSrcweir fValue = ::rtl::math::round(fValue, 0);
2133cdf0e10cSrcweir }
2134cdf0e10cSrcweir return fValue;
2135cdf0e10cSrcweir }
2136cdf0e10cSrcweir
2137cdf0e10cSrcweir namespace
2138cdf0e10cSrcweir {
2139cdf0e10cSrcweir //--------------------------------------------------------------------------
lcl_setFormattedCurrency_nothrow(LongCurrencyField & _rField,const DbCurrencyField & _rControl,const Reference<XColumn> & _rxField,const Reference<XNumberFormatter> & _rxFormatter)2140cdf0e10cSrcweir static String lcl_setFormattedCurrency_nothrow( LongCurrencyField& _rField, const DbCurrencyField& _rControl,
2141cdf0e10cSrcweir const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
2142cdf0e10cSrcweir {
2143cdf0e10cSrcweir String sValue;
2144cdf0e10cSrcweir if ( _rxField.is() )
2145cdf0e10cSrcweir {
2146cdf0e10cSrcweir try
2147cdf0e10cSrcweir {
2148cdf0e10cSrcweir double fValue = _rControl.GetCurrency( _rxField, _rxFormatter );
2149cdf0e10cSrcweir if ( !_rxField->wasNull() )
2150cdf0e10cSrcweir {
2151cdf0e10cSrcweir _rField.SetValue( fValue );
2152cdf0e10cSrcweir BigInt aValue = _rField.GetCorrectedValue();
2153cdf0e10cSrcweir sValue = aValue.GetString();
2154cdf0e10cSrcweir sValue = _rField.GetText();
2155cdf0e10cSrcweir }
2156cdf0e10cSrcweir }
2157cdf0e10cSrcweir catch( const Exception& )
2158cdf0e10cSrcweir {
2159cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
2160cdf0e10cSrcweir }
2161cdf0e10cSrcweir }
2162cdf0e10cSrcweir return sValue;
2163cdf0e10cSrcweir }
2164cdf0e10cSrcweir }
2165cdf0e10cSrcweir
2166cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<::com::sun::star::util::XNumberFormatter> & _rxFormatter,Color **)2167cdf0e10cSrcweir String DbCurrencyField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, Color** /*ppColor*/)
2168cdf0e10cSrcweir {
2169cdf0e10cSrcweir return lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField* >( m_pPainter ), *this, _rxField, _rxFormatter );
2170cdf0e10cSrcweir }
2171cdf0e10cSrcweir
2172cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<::com::sun::star::util::XNumberFormatter> & _rxFormatter)2173cdf0e10cSrcweir void DbCurrencyField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
2174cdf0e10cSrcweir {
2175cdf0e10cSrcweir lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField* >( m_pWindow ), *this, _rxField, _rxFormatter );
2176cdf0e10cSrcweir }
2177cdf0e10cSrcweir
2178cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)2179cdf0e10cSrcweir void DbCurrencyField::updateFromModel( Reference< XPropertySet > _rxModel )
2180cdf0e10cSrcweir {
2181cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbCurrencyField::updateFromModel: invalid call!" );
2182cdf0e10cSrcweir
2183cdf0e10cSrcweir double dValue = 0;
2184cdf0e10cSrcweir if ( _rxModel->getPropertyValue( FM_PROP_VALUE ) >>= dValue )
2185cdf0e10cSrcweir {
2186cdf0e10cSrcweir if ( m_nScale )
2187cdf0e10cSrcweir {
2188cdf0e10cSrcweir dValue = ::rtl::math::pow10Exp( dValue, m_nScale );
2189cdf0e10cSrcweir dValue = ::rtl::math::round(dValue, 0);
2190cdf0e10cSrcweir }
2191cdf0e10cSrcweir
2192cdf0e10cSrcweir static_cast< LongCurrencyField* >( m_pWindow )->SetValue( dValue );
2193cdf0e10cSrcweir }
2194cdf0e10cSrcweir else
2195cdf0e10cSrcweir m_pWindow->SetText( String() );
2196cdf0e10cSrcweir }
2197cdf0e10cSrcweir
2198cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()2199cdf0e10cSrcweir sal_Bool DbCurrencyField::commitControl()
2200cdf0e10cSrcweir {
2201cdf0e10cSrcweir String aText( m_pWindow->GetText());
2202cdf0e10cSrcweir Any aVal;
2203cdf0e10cSrcweir if (aText.Len() != 0) // nicht null
2204cdf0e10cSrcweir {
2205cdf0e10cSrcweir double fValue = ((LongCurrencyField*)m_pWindow)->GetValue();
2206cdf0e10cSrcweir if (m_nScale)
2207cdf0e10cSrcweir {
2208cdf0e10cSrcweir fValue /= ::rtl::math::pow10Exp(1.0, m_nScale);
2209cdf0e10cSrcweir //fValue = ::rtl::math::round(fValue, m_nScale);
2210cdf0e10cSrcweir }
2211cdf0e10cSrcweir aVal <<= (double)fValue;
2212cdf0e10cSrcweir }
2213cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue(FM_PROP_VALUE, aVal);
2214cdf0e10cSrcweir return sal_True;
2215cdf0e10cSrcweir }
2216cdf0e10cSrcweir
2217cdf0e10cSrcweir //==============================================================================
2218cdf0e10cSrcweir //= DbDateField
2219cdf0e10cSrcweir //==============================================================================
2220cdf0e10cSrcweir //------------------------------------------------------------------------------
DbDateField(DbGridColumn & _rColumn)2221cdf0e10cSrcweir DbDateField::DbDateField( DbGridColumn& _rColumn )
2222cdf0e10cSrcweir :DbSpinField( _rColumn )
2223cdf0e10cSrcweir {
2224cdf0e10cSrcweir doPropertyListening( FM_PROP_DATEFORMAT );
2225cdf0e10cSrcweir doPropertyListening( FM_PROP_DATEMIN );
2226cdf0e10cSrcweir doPropertyListening( FM_PROP_DATEMAX );
2227cdf0e10cSrcweir doPropertyListening( FM_PROP_STRICTFORMAT );
2228cdf0e10cSrcweir doPropertyListening( FM_PROP_DATE_SHOW_CENTURY );
2229cdf0e10cSrcweir }
2230cdf0e10cSrcweir
2231cdf0e10cSrcweir //------------------------------------------------------------------------------
createField(Window * _pParent,WinBits _nFieldStyle,const Reference<XPropertySet> & _rxModel)2232cdf0e10cSrcweir SpinField* DbDateField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& _rxModel )
2233cdf0e10cSrcweir {
2234cdf0e10cSrcweir // check if there is a DropDown property set to TRUE
2235cdf0e10cSrcweir sal_Bool bDropDown = !hasProperty( FM_PROP_DROPDOWN, _rxModel )
2236cdf0e10cSrcweir || getBOOL( _rxModel->getPropertyValue( FM_PROP_DROPDOWN ) );
2237cdf0e10cSrcweir if ( bDropDown )
2238cdf0e10cSrcweir _nFieldStyle |= WB_DROPDOWN;
2239cdf0e10cSrcweir
2240cdf0e10cSrcweir CalendarField* pField = new CalendarField( _pParent, _nFieldStyle );
2241cdf0e10cSrcweir
2242cdf0e10cSrcweir pField->EnableToday();
2243cdf0e10cSrcweir pField->EnableNone();
2244cdf0e10cSrcweir
2245cdf0e10cSrcweir return pField;
2246cdf0e10cSrcweir }
2247cdf0e10cSrcweir
2248cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> & _rxModel)2249cdf0e10cSrcweir void DbDateField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2250cdf0e10cSrcweir {
2251cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbDateField::implAdjustGenericFieldSetting: not to be called without window!" );
2252cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbDateField::implAdjustGenericFieldSetting: invalid model!" );
2253cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
2254cdf0e10cSrcweir {
2255cdf0e10cSrcweir sal_Int16 nFormat = getINT16( _rxModel->getPropertyValue( FM_PROP_DATEFORMAT ) );
2256cdf0e10cSrcweir sal_Int32 nMin = getINT32( _rxModel->getPropertyValue( FM_PROP_DATEMIN ) );
2257cdf0e10cSrcweir sal_Int32 nMax = getINT32( _rxModel->getPropertyValue( FM_PROP_DATEMAX ) );
2258cdf0e10cSrcweir sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) );
2259cdf0e10cSrcweir
2260cdf0e10cSrcweir Any aCentury = _rxModel->getPropertyValue( FM_PROP_DATE_SHOW_CENTURY );
2261cdf0e10cSrcweir if ( aCentury.getValueType().getTypeClass() != TypeClass_VOID )
2262cdf0e10cSrcweir {
2263cdf0e10cSrcweir sal_Bool bShowDateCentury = getBOOL( aCentury );
2264cdf0e10cSrcweir
2265cdf0e10cSrcweir static_cast<DateField*>( m_pWindow )->SetShowDateCentury( bShowDateCentury );
2266cdf0e10cSrcweir static_cast<DateField*>( m_pPainter )->SetShowDateCentury( bShowDateCentury );
2267cdf0e10cSrcweir }
2268cdf0e10cSrcweir
2269cdf0e10cSrcweir static_cast< DateField* >( m_pWindow )->SetExtDateFormat( (ExtDateFieldFormat)nFormat );
2270cdf0e10cSrcweir static_cast< DateField* >( m_pWindow )->SetMin( nMin );
2271cdf0e10cSrcweir static_cast< DateField* >( m_pWindow )->SetMax( nMax );
2272cdf0e10cSrcweir static_cast< DateField* >( m_pWindow )->SetStrictFormat( bStrict );
2273cdf0e10cSrcweir static_cast< DateField* >( m_pWindow )->EnableEmptyFieldValue( sal_True );
2274cdf0e10cSrcweir
2275cdf0e10cSrcweir static_cast< DateField* >( m_pPainter )->SetExtDateFormat( (ExtDateFieldFormat)nFormat );
2276cdf0e10cSrcweir static_cast< DateField* >( m_pPainter )->SetMin( nMin );
2277cdf0e10cSrcweir static_cast< DateField* >( m_pPainter )->SetMax( nMax );
2278cdf0e10cSrcweir static_cast< DateField* >( m_pPainter )->SetStrictFormat( bStrict );
2279cdf0e10cSrcweir static_cast< DateField* >( m_pPainter )->EnableEmptyFieldValue( sal_True );
2280cdf0e10cSrcweir }
2281cdf0e10cSrcweir }
2282cdf0e10cSrcweir
2283cdf0e10cSrcweir namespace
2284cdf0e10cSrcweir {
2285cdf0e10cSrcweir //--------------------------------------------------------------------------
lcl_setFormattedDate_nothrow(DateField & _rField,const Reference<XColumn> & _rxField)2286cdf0e10cSrcweir static String lcl_setFormattedDate_nothrow( DateField& _rField, const Reference< XColumn >& _rxField )
2287cdf0e10cSrcweir {
2288cdf0e10cSrcweir String sDate;
2289cdf0e10cSrcweir if ( _rxField.is() )
2290cdf0e10cSrcweir {
2291cdf0e10cSrcweir try
2292cdf0e10cSrcweir {
2293cdf0e10cSrcweir ::com::sun::star::util::Date aValue = _rxField->getDate();
2294cdf0e10cSrcweir if ( _rxField->wasNull() )
2295cdf0e10cSrcweir _rField.SetText( sDate );
2296cdf0e10cSrcweir else
2297cdf0e10cSrcweir {
2298cdf0e10cSrcweir _rField.SetDate( ::Date( aValue.Day, aValue.Month, aValue.Year ) );
2299cdf0e10cSrcweir sDate = _rField.GetText();
2300cdf0e10cSrcweir }
2301cdf0e10cSrcweir }
2302cdf0e10cSrcweir catch( const Exception& )
2303cdf0e10cSrcweir {
2304cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
2305cdf0e10cSrcweir }
2306cdf0e10cSrcweir }
2307cdf0e10cSrcweir return sDate;
2308cdf0e10cSrcweir }
2309cdf0e10cSrcweir }
2310cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<::com::sun::star::util::XNumberFormatter> &,Color **)2311cdf0e10cSrcweir String DbDateField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
2312cdf0e10cSrcweir {
2313cdf0e10cSrcweir return lcl_setFormattedDate_nothrow( *dynamic_cast< DateField* >( m_pPainter ), _rxField );
2314cdf0e10cSrcweir }
2315cdf0e10cSrcweir
2316cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> &)2317cdf0e10cSrcweir void DbDateField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/)
2318cdf0e10cSrcweir {
2319cdf0e10cSrcweir lcl_setFormattedDate_nothrow( *dynamic_cast< DateField* >( m_pWindow ), _rxField );
2320cdf0e10cSrcweir }
2321cdf0e10cSrcweir
2322cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)2323cdf0e10cSrcweir void DbDateField::updateFromModel( Reference< XPropertySet > _rxModel )
2324cdf0e10cSrcweir {
2325cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbDateField::updateFromModel: invalid call!" );
2326cdf0e10cSrcweir
2327cdf0e10cSrcweir sal_Int32 nDate = 0;
2328cdf0e10cSrcweir if ( _rxModel->getPropertyValue( FM_PROP_DATE ) >>= nDate )
2329cdf0e10cSrcweir static_cast< DateField* >( m_pWindow )->SetDate( ::Date( nDate ) );
2330cdf0e10cSrcweir else
2331cdf0e10cSrcweir static_cast< DateField* >( m_pWindow )->SetText( String() );
2332cdf0e10cSrcweir }
2333cdf0e10cSrcweir
2334cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()2335cdf0e10cSrcweir sal_Bool DbDateField::commitControl()
2336cdf0e10cSrcweir {
2337cdf0e10cSrcweir String aText( m_pWindow->GetText());
2338cdf0e10cSrcweir Any aVal;
2339cdf0e10cSrcweir if (aText.Len() != 0)
2340cdf0e10cSrcweir aVal <<= (sal_Int32)static_cast<DateField*>(m_pWindow)->GetDate().GetDate();
2341cdf0e10cSrcweir else
2342cdf0e10cSrcweir aVal.clear();
2343cdf0e10cSrcweir
2344cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue(FM_PROP_DATE, aVal);
2345cdf0e10cSrcweir return sal_True;
2346cdf0e10cSrcweir }
2347cdf0e10cSrcweir
2348cdf0e10cSrcweir //==============================================================================
2349cdf0e10cSrcweir //= DbTimeField
2350cdf0e10cSrcweir //==============================================================================
2351cdf0e10cSrcweir //------------------------------------------------------------------------------
DbTimeField(DbGridColumn & _rColumn)2352cdf0e10cSrcweir DbTimeField::DbTimeField( DbGridColumn& _rColumn )
2353cdf0e10cSrcweir :DbSpinField( _rColumn, ::com::sun::star::awt::TextAlign::LEFT )
2354cdf0e10cSrcweir {
2355cdf0e10cSrcweir doPropertyListening( FM_PROP_TIMEFORMAT );
2356cdf0e10cSrcweir doPropertyListening( FM_PROP_TIMEMIN );
2357cdf0e10cSrcweir doPropertyListening( FM_PROP_TIMEMAX );
2358cdf0e10cSrcweir doPropertyListening( FM_PROP_STRICTFORMAT );
2359cdf0e10cSrcweir }
2360cdf0e10cSrcweir
2361cdf0e10cSrcweir //------------------------------------------------------------------------------
createField(Window * _pParent,WinBits _nFieldStyle,const Reference<XPropertySet> &)2362cdf0e10cSrcweir SpinField* DbTimeField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ )
2363cdf0e10cSrcweir {
2364cdf0e10cSrcweir return new TimeField( _pParent, _nFieldStyle );
2365cdf0e10cSrcweir }
2366cdf0e10cSrcweir
2367cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> & _rxModel)2368cdf0e10cSrcweir void DbTimeField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2369cdf0e10cSrcweir {
2370cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbTimeField::implAdjustGenericFieldSetting: not to be called without window!" );
2371cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbTimeField::implAdjustGenericFieldSetting: invalid model!" );
2372cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
2373cdf0e10cSrcweir {
2374cdf0e10cSrcweir sal_Int16 nFormat = getINT16( _rxModel->getPropertyValue( FM_PROP_TIMEFORMAT ) );
2375cdf0e10cSrcweir sal_Int32 nMin = getINT32( _rxModel->getPropertyValue( FM_PROP_TIMEMIN ) );
2376cdf0e10cSrcweir sal_Int32 nMax = getINT32( _rxModel->getPropertyValue( FM_PROP_TIMEMAX ) );
2377cdf0e10cSrcweir sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) );
2378cdf0e10cSrcweir
2379cdf0e10cSrcweir static_cast< TimeField* >( m_pWindow )->SetExtFormat( (ExtTimeFieldFormat)nFormat );
2380cdf0e10cSrcweir static_cast< TimeField* >( m_pWindow )->SetMin( nMin );
2381cdf0e10cSrcweir static_cast< TimeField* >( m_pWindow )->SetMax( nMax );
2382cdf0e10cSrcweir static_cast< TimeField* >( m_pWindow )->SetStrictFormat( bStrict );
2383cdf0e10cSrcweir static_cast< TimeField* >( m_pWindow )->EnableEmptyFieldValue( sal_True );
2384cdf0e10cSrcweir
2385cdf0e10cSrcweir static_cast< TimeField* >( m_pPainter )->SetExtFormat( (ExtTimeFieldFormat)nFormat );
2386cdf0e10cSrcweir static_cast< TimeField* >( m_pPainter )->SetMin( nMin );
2387cdf0e10cSrcweir static_cast< TimeField* >( m_pPainter )->SetMax( nMax );
2388cdf0e10cSrcweir static_cast< TimeField* >( m_pPainter )->SetStrictFormat( bStrict );
2389cdf0e10cSrcweir static_cast< TimeField* >( m_pPainter )->EnableEmptyFieldValue( sal_True );
2390cdf0e10cSrcweir }
2391cdf0e10cSrcweir }
2392cdf0e10cSrcweir
2393cdf0e10cSrcweir namespace
2394cdf0e10cSrcweir {
2395cdf0e10cSrcweir //--------------------------------------------------------------------------
lcl_setFormattedTime_nothrow(TimeField & _rField,const Reference<XColumn> & _rxField)2396cdf0e10cSrcweir static String lcl_setFormattedTime_nothrow( TimeField& _rField, const Reference< XColumn >& _rxField )
2397cdf0e10cSrcweir {
2398cdf0e10cSrcweir String sTime;
2399cdf0e10cSrcweir if ( _rxField.is() )
2400cdf0e10cSrcweir {
2401cdf0e10cSrcweir try
2402cdf0e10cSrcweir {
2403cdf0e10cSrcweir ::com::sun::star::util::Time aValue = _rxField->getTime();
2404cdf0e10cSrcweir if ( _rxField->wasNull() )
2405cdf0e10cSrcweir _rField.SetText( sTime );
2406cdf0e10cSrcweir else
2407cdf0e10cSrcweir {
2408cdf0e10cSrcweir _rField.SetTime( ::Time( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.HundredthSeconds ) );
2409cdf0e10cSrcweir sTime = _rField.GetText();
2410cdf0e10cSrcweir }
2411cdf0e10cSrcweir }
2412cdf0e10cSrcweir catch( const Exception& )
2413cdf0e10cSrcweir {
2414cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
2415cdf0e10cSrcweir }
2416cdf0e10cSrcweir }
2417cdf0e10cSrcweir return sTime;
2418cdf0e10cSrcweir }
2419cdf0e10cSrcweir }
2420cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<::com::sun::star::util::XNumberFormatter> &,Color **)2421cdf0e10cSrcweir String DbTimeField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
2422cdf0e10cSrcweir {
2423cdf0e10cSrcweir return lcl_setFormattedTime_nothrow( *static_cast< TimeField* >( m_pPainter ), _rxField );
2424cdf0e10cSrcweir }
2425cdf0e10cSrcweir
2426cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> &)2427cdf0e10cSrcweir void DbTimeField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/)
2428cdf0e10cSrcweir {
2429cdf0e10cSrcweir lcl_setFormattedTime_nothrow( *static_cast< TimeField* >( m_pWindow ), _rxField );
2430cdf0e10cSrcweir }
2431cdf0e10cSrcweir
2432cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)2433cdf0e10cSrcweir void DbTimeField::updateFromModel( Reference< XPropertySet > _rxModel )
2434cdf0e10cSrcweir {
2435cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbTimeField::updateFromModel: invalid call!" );
2436cdf0e10cSrcweir
2437cdf0e10cSrcweir sal_Int32 nTime = 0;
2438cdf0e10cSrcweir if ( _rxModel->getPropertyValue( FM_PROP_DATE ) >>= nTime )
2439cdf0e10cSrcweir static_cast< TimeField* >( m_pWindow )->SetTime( ::Time( nTime ) );
2440cdf0e10cSrcweir else
2441cdf0e10cSrcweir static_cast< TimeField* >( m_pWindow )->SetText( String() );
2442cdf0e10cSrcweir }
2443cdf0e10cSrcweir
2444cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()2445cdf0e10cSrcweir sal_Bool DbTimeField::commitControl()
2446cdf0e10cSrcweir {
2447cdf0e10cSrcweir String aText( m_pWindow->GetText());
2448cdf0e10cSrcweir Any aVal;
2449cdf0e10cSrcweir if (aText.Len() != 0)
2450cdf0e10cSrcweir aVal <<= (sal_Int32)static_cast<TimeField*>(m_pWindow)->GetTime().GetTime();
2451cdf0e10cSrcweir else
2452cdf0e10cSrcweir aVal.clear();
2453cdf0e10cSrcweir
2454cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue(FM_PROP_TIME, aVal);
2455cdf0e10cSrcweir return sal_True;
2456cdf0e10cSrcweir }
2457cdf0e10cSrcweir
2458cdf0e10cSrcweir //==============================================================================
2459cdf0e10cSrcweir //= DbComboBox
2460cdf0e10cSrcweir //==============================================================================
2461cdf0e10cSrcweir //------------------------------------------------------------------------------
DbComboBox(DbGridColumn & _rColumn)2462cdf0e10cSrcweir DbComboBox::DbComboBox(DbGridColumn& _rColumn)
2463cdf0e10cSrcweir :DbCellControl(_rColumn)
2464cdf0e10cSrcweir ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED)
2465cdf0e10cSrcweir {
2466cdf0e10cSrcweir setAlignedController( sal_False );
2467cdf0e10cSrcweir
2468cdf0e10cSrcweir doPropertyListening( FM_PROP_STRINGITEMLIST );
2469cdf0e10cSrcweir doPropertyListening( FM_PROP_LINECOUNT );
2470cdf0e10cSrcweir }
2471cdf0e10cSrcweir
2472cdf0e10cSrcweir //------------------------------------------------------------------------------
_propertyChanged(const PropertyChangeEvent & _rEvent)2473cdf0e10cSrcweir void DbComboBox::_propertyChanged( const PropertyChangeEvent& _rEvent ) throw( RuntimeException )
2474cdf0e10cSrcweir {
2475cdf0e10cSrcweir if ( _rEvent.PropertyName.equals( FM_PROP_STRINGITEMLIST ) )
2476cdf0e10cSrcweir {
2477cdf0e10cSrcweir SetList(_rEvent.NewValue);
2478cdf0e10cSrcweir }
2479cdf0e10cSrcweir else
2480cdf0e10cSrcweir {
2481cdf0e10cSrcweir DbCellControl::_propertyChanged( _rEvent ) ;
2482cdf0e10cSrcweir }
2483cdf0e10cSrcweir }
2484cdf0e10cSrcweir
2485cdf0e10cSrcweir //------------------------------------------------------------------------------
SetList(const Any & rItems)2486cdf0e10cSrcweir void DbComboBox::SetList(const Any& rItems)
2487cdf0e10cSrcweir {
2488cdf0e10cSrcweir ComboBoxControl* pField = (ComboBoxControl*)m_pWindow;
2489cdf0e10cSrcweir pField->Clear();
2490cdf0e10cSrcweir
2491cdf0e10cSrcweir ::comphelper::StringSequence aTest;
2492cdf0e10cSrcweir if (rItems >>= aTest)
2493cdf0e10cSrcweir {
2494cdf0e10cSrcweir const ::rtl::OUString* pStrings = aTest.getConstArray();
2495cdf0e10cSrcweir sal_Int32 nItems = aTest.getLength();
2496cdf0e10cSrcweir for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings )
2497cdf0e10cSrcweir pField->InsertEntry(*pStrings, LISTBOX_APPEND);
2498cdf0e10cSrcweir
2499cdf0e10cSrcweir // tell the grid control that this controller is invalid and has to be re-initialized
2500cdf0e10cSrcweir invalidatedController();
2501cdf0e10cSrcweir }
2502cdf0e10cSrcweir }
2503cdf0e10cSrcweir
2504cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> & _rxModel)2505cdf0e10cSrcweir void DbComboBox::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2506cdf0e10cSrcweir {
2507cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbComboBox::implAdjustGenericFieldSetting: not to be called without window!" );
2508cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbComboBox::implAdjustGenericFieldSetting: invalid model!" );
2509cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
2510cdf0e10cSrcweir {
2511cdf0e10cSrcweir sal_Int16 nLines = getINT16( _rxModel->getPropertyValue( FM_PROP_LINECOUNT ) );
2512cdf0e10cSrcweir static_cast< ComboBoxControl* >( m_pWindow )->SetDropDownLineCount( nLines );
2513cdf0e10cSrcweir }
2514cdf0e10cSrcweir }
2515cdf0e10cSrcweir
2516cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & rParent,const Reference<XRowSet> & xCursor)2517cdf0e10cSrcweir void DbComboBox::Init( Window& rParent, const Reference< XRowSet >& xCursor )
2518cdf0e10cSrcweir {
2519cdf0e10cSrcweir m_rColumn.SetAlignmentFromModel(::com::sun::star::awt::TextAlign::LEFT);
2520cdf0e10cSrcweir
2521cdf0e10cSrcweir m_pWindow = new ComboBoxControl( &rParent );
2522cdf0e10cSrcweir
2523cdf0e10cSrcweir // selection von rechts nach links
2524cdf0e10cSrcweir AllSettings aSettings = m_pWindow->GetSettings();
2525cdf0e10cSrcweir StyleSettings aStyleSettings = aSettings.GetStyleSettings();
2526cdf0e10cSrcweir aStyleSettings.SetSelectionOptions(
2527cdf0e10cSrcweir aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
2528cdf0e10cSrcweir aSettings.SetStyleSettings(aStyleSettings);
2529cdf0e10cSrcweir m_pWindow->SetSettings(aSettings, sal_True);
2530cdf0e10cSrcweir
2531cdf0e10cSrcweir // some initial properties
2532cdf0e10cSrcweir Reference< XPropertySet > xModel(m_rColumn.getModel());
2533cdf0e10cSrcweir SetList( xModel->getPropertyValue( FM_PROP_STRINGITEMLIST ) );
2534cdf0e10cSrcweir implAdjustGenericFieldSetting( xModel );
2535cdf0e10cSrcweir
2536cdf0e10cSrcweir if (m_rColumn.GetParent().getNumberFormatter().is())
2537cdf0e10cSrcweir m_nKeyType = comphelper::getNumberFormatType(m_rColumn.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn.GetKey());
2538cdf0e10cSrcweir
2539cdf0e10cSrcweir DbCellControl::Init( rParent, xCursor );
2540cdf0e10cSrcweir }
2541cdf0e10cSrcweir
2542cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateController() const2543cdf0e10cSrcweir CellControllerRef DbComboBox::CreateController() const
2544cdf0e10cSrcweir {
2545cdf0e10cSrcweir return new ComboBoxCellController((ComboBoxControl*)m_pWindow);
2546cdf0e10cSrcweir }
2547cdf0e10cSrcweir
2548cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter,Color **)2549cdf0e10cSrcweir String DbComboBox::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter, Color** /*ppColor*/)
2550cdf0e10cSrcweir {
2551cdf0e10cSrcweir ::rtl::OUString aString;
2552cdf0e10cSrcweir if (_rxField.is())
2553cdf0e10cSrcweir try
2554cdf0e10cSrcweir {
2555cdf0e10cSrcweir aString = getFormattedValue( _rxField, xFormatter, m_rColumn.GetParent().getNullDate(), m_rColumn.GetKey(), m_nKeyType );
2556cdf0e10cSrcweir }
2557cdf0e10cSrcweir catch( const Exception& )
2558cdf0e10cSrcweir {
2559cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
2560cdf0e10cSrcweir }
2561cdf0e10cSrcweir return aString;
2562cdf0e10cSrcweir }
2563cdf0e10cSrcweir
2564cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter)2565cdf0e10cSrcweir void DbComboBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter)
2566cdf0e10cSrcweir {
2567cdf0e10cSrcweir m_pWindow->SetText(GetFormatText(_rxField, xFormatter));
2568cdf0e10cSrcweir }
2569cdf0e10cSrcweir
2570cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)2571cdf0e10cSrcweir void DbComboBox::updateFromModel( Reference< XPropertySet > _rxModel )
2572cdf0e10cSrcweir {
2573cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbComboBox::updateFromModel: invalid call!" );
2574cdf0e10cSrcweir
2575cdf0e10cSrcweir ::rtl::OUString sText;
2576cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText;
2577cdf0e10cSrcweir
2578cdf0e10cSrcweir static_cast< ComboBox* >( m_pWindow )->SetText( sText );
2579cdf0e10cSrcweir static_cast< ComboBox* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
2580cdf0e10cSrcweir }
2581cdf0e10cSrcweir
2582cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()2583cdf0e10cSrcweir sal_Bool DbComboBox::commitControl()
2584cdf0e10cSrcweir {
2585cdf0e10cSrcweir String aText( m_pWindow->GetText());
2586cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue(FM_PROP_TEXT, makeAny(::rtl::OUString(aText)));
2587cdf0e10cSrcweir return sal_True;
2588cdf0e10cSrcweir }
2589cdf0e10cSrcweir
2590cdf0e10cSrcweir //------------------------------------------------------------------------------
DbListBox(DbGridColumn & _rColumn)2591cdf0e10cSrcweir DbListBox::DbListBox(DbGridColumn& _rColumn)
2592cdf0e10cSrcweir :DbCellControl(_rColumn)
2593cdf0e10cSrcweir ,m_bBound(sal_False)
2594cdf0e10cSrcweir {
2595cdf0e10cSrcweir setAlignedController( sal_False );
2596cdf0e10cSrcweir
2597cdf0e10cSrcweir doPropertyListening( FM_PROP_STRINGITEMLIST );
2598cdf0e10cSrcweir doPropertyListening( FM_PROP_LINECOUNT );
2599cdf0e10cSrcweir }
2600cdf0e10cSrcweir
2601cdf0e10cSrcweir //------------------------------------------------------------------------------
_propertyChanged(const::com::sun::star::beans::PropertyChangeEvent & _rEvent)2602cdf0e10cSrcweir void DbListBox::_propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw( RuntimeException )
2603cdf0e10cSrcweir {
2604cdf0e10cSrcweir if ( _rEvent.PropertyName.equals( FM_PROP_STRINGITEMLIST ) )
2605cdf0e10cSrcweir {
2606cdf0e10cSrcweir SetList(_rEvent.NewValue);
2607cdf0e10cSrcweir }
2608cdf0e10cSrcweir else
2609cdf0e10cSrcweir {
2610cdf0e10cSrcweir DbCellControl::_propertyChanged( _rEvent ) ;
2611cdf0e10cSrcweir }
2612cdf0e10cSrcweir }
2613cdf0e10cSrcweir
2614cdf0e10cSrcweir //------------------------------------------------------------------------------
SetList(const Any & rItems)2615cdf0e10cSrcweir void DbListBox::SetList(const Any& rItems)
2616cdf0e10cSrcweir {
2617cdf0e10cSrcweir ListBoxControl* pField = (ListBoxControl*)m_pWindow;
2618cdf0e10cSrcweir
2619cdf0e10cSrcweir pField->Clear();
2620cdf0e10cSrcweir m_bBound = sal_False;
2621cdf0e10cSrcweir
2622cdf0e10cSrcweir ::comphelper::StringSequence aTest;
2623cdf0e10cSrcweir if (rItems >>= aTest)
2624cdf0e10cSrcweir {
2625cdf0e10cSrcweir const ::rtl::OUString* pStrings = aTest.getConstArray();
2626cdf0e10cSrcweir sal_Int32 nItems = aTest.getLength();
2627cdf0e10cSrcweir if (nItems)
2628cdf0e10cSrcweir {
2629cdf0e10cSrcweir for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings )
2630cdf0e10cSrcweir pField->InsertEntry(*pStrings, LISTBOX_APPEND);
2631cdf0e10cSrcweir
2632cdf0e10cSrcweir m_rColumn.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ) >>= m_aValueList;
2633cdf0e10cSrcweir m_bBound = m_aValueList.getLength() > 0;
2634cdf0e10cSrcweir
2635cdf0e10cSrcweir // tell the grid control that this controller is invalid and has to be re-initialized
2636cdf0e10cSrcweir invalidatedController();
2637cdf0e10cSrcweir }
2638cdf0e10cSrcweir }
2639cdf0e10cSrcweir }
2640cdf0e10cSrcweir
2641cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & rParent,const Reference<XRowSet> & xCursor)2642cdf0e10cSrcweir void DbListBox::Init( Window& rParent, const Reference< XRowSet >& xCursor)
2643cdf0e10cSrcweir {
2644cdf0e10cSrcweir m_rColumn.SetAlignment(::com::sun::star::awt::TextAlign::LEFT);
2645cdf0e10cSrcweir
2646cdf0e10cSrcweir m_pWindow = new ListBoxControl( &rParent );
2647cdf0e10cSrcweir
2648cdf0e10cSrcweir // some initial properties
2649cdf0e10cSrcweir Reference< XPropertySet > xModel( m_rColumn.getModel() );
2650cdf0e10cSrcweir SetList( xModel->getPropertyValue( FM_PROP_STRINGITEMLIST ) );
2651cdf0e10cSrcweir implAdjustGenericFieldSetting( xModel );
2652cdf0e10cSrcweir
2653cdf0e10cSrcweir DbCellControl::Init( rParent, xCursor );
2654cdf0e10cSrcweir }
2655cdf0e10cSrcweir
2656cdf0e10cSrcweir //------------------------------------------------------------------------------
implAdjustGenericFieldSetting(const Reference<XPropertySet> & _rxModel)2657cdf0e10cSrcweir void DbListBox::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2658cdf0e10cSrcweir {
2659cdf0e10cSrcweir DBG_ASSERT( m_pWindow, "DbListBox::implAdjustGenericFieldSetting: not to be called without window!" );
2660cdf0e10cSrcweir DBG_ASSERT( _rxModel.is(), "DbListBox::implAdjustGenericFieldSetting: invalid model!" );
2661cdf0e10cSrcweir if ( m_pWindow && _rxModel.is() )
2662cdf0e10cSrcweir {
2663cdf0e10cSrcweir sal_Int16 nLines = getINT16( _rxModel->getPropertyValue( FM_PROP_LINECOUNT ) );
2664cdf0e10cSrcweir static_cast< ListBoxControl* >( m_pWindow )->SetDropDownLineCount( nLines );
2665cdf0e10cSrcweir }
2666cdf0e10cSrcweir }
2667cdf0e10cSrcweir
2668cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateController() const2669cdf0e10cSrcweir CellControllerRef DbListBox::CreateController() const
2670cdf0e10cSrcweir {
2671cdf0e10cSrcweir return new ListBoxCellController((ListBoxControl*)m_pWindow);
2672cdf0e10cSrcweir }
2673cdf0e10cSrcweir
2674cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> &,Color **)2675cdf0e10cSrcweir String DbListBox::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
2676cdf0e10cSrcweir {
2677cdf0e10cSrcweir String sText;
2678cdf0e10cSrcweir if ( _rxField.is() )
2679cdf0e10cSrcweir {
2680cdf0e10cSrcweir try
2681cdf0e10cSrcweir {
2682cdf0e10cSrcweir sText = _rxField->getString();
2683cdf0e10cSrcweir if ( m_bBound )
2684cdf0e10cSrcweir {
2685cdf0e10cSrcweir Sequence< sal_Int16 > aPosSeq = ::comphelper::findValue( m_aValueList, sText, sal_True );
2686cdf0e10cSrcweir if ( aPosSeq.getLength() )
2687cdf0e10cSrcweir sText = static_cast<ListBox*>(m_pWindow)->GetEntry(aPosSeq.getConstArray()[0]);
2688cdf0e10cSrcweir else
2689cdf0e10cSrcweir sText = String();
2690cdf0e10cSrcweir }
2691cdf0e10cSrcweir }
2692cdf0e10cSrcweir catch( const Exception& )
2693cdf0e10cSrcweir {
2694cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION();
2695cdf0e10cSrcweir }
2696cdf0e10cSrcweir }
2697cdf0e10cSrcweir return sText;
2698cdf0e10cSrcweir }
2699cdf0e10cSrcweir
2700cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromField(const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter)2701cdf0e10cSrcweir void DbListBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter)
2702cdf0e10cSrcweir {
2703cdf0e10cSrcweir String sFormattedText( GetFormatText( _rxField, xFormatter ) );
2704cdf0e10cSrcweir if ( sFormattedText.Len() )
2705cdf0e10cSrcweir static_cast< ListBox* >( m_pWindow )->SelectEntry( sFormattedText );
2706cdf0e10cSrcweir else
2707cdf0e10cSrcweir static_cast< ListBox* >( m_pWindow )->SetNoSelection();
2708cdf0e10cSrcweir }
2709cdf0e10cSrcweir
2710cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)2711cdf0e10cSrcweir void DbListBox::updateFromModel( Reference< XPropertySet > _rxModel )
2712cdf0e10cSrcweir {
2713cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbListBox::updateFromModel: invalid call!" );
2714cdf0e10cSrcweir
2715cdf0e10cSrcweir Sequence< sal_Int16 > aSelection;
2716cdf0e10cSrcweir _rxModel->getPropertyValue( FM_PROP_SELECT_SEQ );
2717cdf0e10cSrcweir
2718cdf0e10cSrcweir sal_Int16 nSelection = -1;
2719cdf0e10cSrcweir if ( aSelection.getLength() > 0 )
2720cdf0e10cSrcweir nSelection = aSelection[ 0 ];
2721cdf0e10cSrcweir
2722cdf0e10cSrcweir ListBox* pListBox = static_cast< ListBox* >( m_pWindow );
2723cdf0e10cSrcweir
2724cdf0e10cSrcweir if ( ( nSelection >= 0 ) && ( nSelection < pListBox->GetEntryCount() ) )
2725cdf0e10cSrcweir pListBox->SelectEntryPos( nSelection );
2726cdf0e10cSrcweir else
2727cdf0e10cSrcweir pListBox->SetNoSelection( );
2728cdf0e10cSrcweir }
2729cdf0e10cSrcweir
2730cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()2731cdf0e10cSrcweir sal_Bool DbListBox::commitControl()
2732cdf0e10cSrcweir {
2733cdf0e10cSrcweir Any aVal;
2734cdf0e10cSrcweir Sequence<sal_Int16> aSelectSeq;
2735cdf0e10cSrcweir if (static_cast<ListBox*>(m_pWindow)->GetSelectEntryCount())
2736cdf0e10cSrcweir {
2737cdf0e10cSrcweir aSelectSeq.realloc(1);
2738cdf0e10cSrcweir *(sal_Int16 *)aSelectSeq.getArray() = (sal_Int16)static_cast<ListBox*>(m_pWindow)->GetSelectEntryPos();
2739cdf0e10cSrcweir }
2740cdf0e10cSrcweir aVal <<= aSelectSeq;
2741cdf0e10cSrcweir m_rColumn.getModel()->setPropertyValue(FM_PROP_SELECT_SEQ, aVal);
2742cdf0e10cSrcweir return sal_True;
2743cdf0e10cSrcweir }
2744cdf0e10cSrcweir
2745cdf0e10cSrcweir
2746cdf0e10cSrcweir DBG_NAME(DbFilterField);
2747cdf0e10cSrcweir /*************************************************************************/
DbFilterField(const Reference<::com::sun::star::lang::XMultiServiceFactory> & _rxORB,DbGridColumn & _rColumn)2748cdf0e10cSrcweir DbFilterField::DbFilterField(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,DbGridColumn& _rColumn)
2749cdf0e10cSrcweir :DbCellControl(_rColumn)
2750cdf0e10cSrcweir ,OSQLParserClient(_rxORB)
2751cdf0e10cSrcweir ,m_nControlClass(::com::sun::star::form::FormComponentType::TEXTFIELD)
2752cdf0e10cSrcweir ,m_bFilterList(sal_False)
2753cdf0e10cSrcweir ,m_bFilterListFilled(sal_False)
2754cdf0e10cSrcweir ,m_bBound(sal_False)
2755cdf0e10cSrcweir {
2756cdf0e10cSrcweir DBG_CTOR(DbFilterField,NULL);
2757cdf0e10cSrcweir
2758cdf0e10cSrcweir setAlignedController( sal_False );
2759cdf0e10cSrcweir }
2760cdf0e10cSrcweir
2761cdf0e10cSrcweir //------------------------------------------------------------------------------
~DbFilterField()2762cdf0e10cSrcweir DbFilterField::~DbFilterField()
2763cdf0e10cSrcweir {
2764cdf0e10cSrcweir if (m_nControlClass == ::com::sun::star::form::FormComponentType::CHECKBOX)
2765cdf0e10cSrcweir ((CheckBoxControl*)m_pWindow)->SetClickHdl( Link() );
2766cdf0e10cSrcweir
2767cdf0e10cSrcweir DBG_DTOR(DbFilterField,NULL);
2768cdf0e10cSrcweir }
2769cdf0e10cSrcweir
2770cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintCell(OutputDevice & rDev,const Rectangle & rRect)2771cdf0e10cSrcweir void DbFilterField::PaintCell(OutputDevice& rDev, const Rectangle& rRect)
2772cdf0e10cSrcweir {
2773cdf0e10cSrcweir static sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER | TEXT_DRAW_LEFT;
2774cdf0e10cSrcweir switch (m_nControlClass)
2775cdf0e10cSrcweir {
2776cdf0e10cSrcweir case FormComponentType::CHECKBOX:
2777cdf0e10cSrcweir DbCellControl::PaintCell( rDev, rRect );
2778cdf0e10cSrcweir break;
2779cdf0e10cSrcweir case FormComponentType::LISTBOX:
2780cdf0e10cSrcweir rDev.DrawText(rRect, static_cast<ListBox*>(m_pWindow)->GetSelectEntry(), nStyle);
2781cdf0e10cSrcweir break;
2782cdf0e10cSrcweir default:
2783cdf0e10cSrcweir rDev.DrawText(rRect, m_aText, nStyle);
2784cdf0e10cSrcweir }
2785cdf0e10cSrcweir }
2786cdf0e10cSrcweir
2787cdf0e10cSrcweir //------------------------------------------------------------------------------
SetList(const Any & rItems,sal_Bool bComboBox)2788cdf0e10cSrcweir void DbFilterField::SetList(const Any& rItems, sal_Bool bComboBox)
2789cdf0e10cSrcweir {
2790cdf0e10cSrcweir ::comphelper::StringSequence aTest;
2791cdf0e10cSrcweir rItems >>= aTest;
2792cdf0e10cSrcweir const ::rtl::OUString* pStrings = aTest.getConstArray();
2793cdf0e10cSrcweir sal_Int32 nItems = aTest.getLength();
2794cdf0e10cSrcweir if (nItems)
2795cdf0e10cSrcweir {
2796cdf0e10cSrcweir if (bComboBox)
2797cdf0e10cSrcweir {
2798cdf0e10cSrcweir ComboBox* pField = (ComboBox*)m_pWindow;
2799cdf0e10cSrcweir for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings )
2800cdf0e10cSrcweir pField->InsertEntry(*pStrings, LISTBOX_APPEND);
2801cdf0e10cSrcweir }
2802cdf0e10cSrcweir else
2803cdf0e10cSrcweir {
2804cdf0e10cSrcweir ListBox* pField = (ListBox*)m_pWindow;
2805cdf0e10cSrcweir for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings )
2806cdf0e10cSrcweir pField->InsertEntry(*pStrings, LISTBOX_APPEND);
2807cdf0e10cSrcweir
2808cdf0e10cSrcweir m_rColumn.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ) >>= m_aValueList;
2809cdf0e10cSrcweir m_bBound = m_aValueList.getLength() > 0;
2810cdf0e10cSrcweir }
2811cdf0e10cSrcweir }
2812cdf0e10cSrcweir }
2813cdf0e10cSrcweir
2814cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateControl(Window * pParent,const Reference<::com::sun::star::beans::XPropertySet> & xModel)2815cdf0e10cSrcweir void DbFilterField::CreateControl(Window* pParent, const Reference< ::com::sun::star::beans::XPropertySet >& xModel)
2816cdf0e10cSrcweir {
2817cdf0e10cSrcweir switch (m_nControlClass)
2818cdf0e10cSrcweir {
2819cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::CHECKBOX:
2820cdf0e10cSrcweir m_pWindow = new CheckBoxControl(pParent);
2821cdf0e10cSrcweir m_pWindow->SetPaintTransparent( sal_True );
2822cdf0e10cSrcweir ((CheckBoxControl*)m_pWindow)->SetClickHdl( LINK( this, DbFilterField, OnClick ) );
2823cdf0e10cSrcweir
2824cdf0e10cSrcweir m_pPainter = new CheckBoxControl(pParent);
2825cdf0e10cSrcweir m_pPainter->SetPaintTransparent( sal_True );
2826cdf0e10cSrcweir m_pPainter->SetBackground();
2827cdf0e10cSrcweir break;
2828cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::LISTBOX:
2829cdf0e10cSrcweir {
2830cdf0e10cSrcweir m_pWindow = new ListBoxControl(pParent);
2831cdf0e10cSrcweir sal_Int16 nLines = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_LINECOUNT));
2832cdf0e10cSrcweir Any aItems = xModel->getPropertyValue(FM_PROP_STRINGITEMLIST);
2833cdf0e10cSrcweir SetList(aItems, m_nControlClass == ::com::sun::star::form::FormComponentType::COMBOBOX);
2834cdf0e10cSrcweir static_cast<ListBox*>(m_pWindow)->SetDropDownLineCount(nLines);
2835cdf0e10cSrcweir } break;
2836cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::COMBOBOX:
2837cdf0e10cSrcweir {
2838cdf0e10cSrcweir m_pWindow = new ComboBoxControl(pParent);
2839cdf0e10cSrcweir
2840cdf0e10cSrcweir AllSettings aSettings = m_pWindow->GetSettings();
2841cdf0e10cSrcweir StyleSettings aStyleSettings = aSettings.GetStyleSettings();
2842cdf0e10cSrcweir aStyleSettings.SetSelectionOptions(
2843cdf0e10cSrcweir aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
2844cdf0e10cSrcweir aSettings.SetStyleSettings(aStyleSettings);
2845cdf0e10cSrcweir m_pWindow->SetSettings(aSettings, sal_True);
2846cdf0e10cSrcweir
2847cdf0e10cSrcweir if (!m_bFilterList)
2848cdf0e10cSrcweir {
2849cdf0e10cSrcweir sal_Int16 nLines = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_LINECOUNT));
2850cdf0e10cSrcweir Any aItems = xModel->getPropertyValue(FM_PROP_STRINGITEMLIST);
2851cdf0e10cSrcweir SetList(aItems, m_nControlClass == ::com::sun::star::form::FormComponentType::COMBOBOX);
2852cdf0e10cSrcweir ((ComboBox*)m_pWindow)->SetDropDownLineCount(nLines);
2853cdf0e10cSrcweir }
2854cdf0e10cSrcweir else
2855cdf0e10cSrcweir ((ComboBox*)m_pWindow)->SetDropDownLineCount(5);
2856cdf0e10cSrcweir
2857cdf0e10cSrcweir } break;
2858cdf0e10cSrcweir default:
2859cdf0e10cSrcweir {
2860cdf0e10cSrcweir m_pWindow = new Edit(pParent, WB_LEFT);
2861cdf0e10cSrcweir AllSettings aSettings = m_pWindow->GetSettings();
2862cdf0e10cSrcweir StyleSettings aStyleSettings = aSettings.GetStyleSettings();
2863cdf0e10cSrcweir aStyleSettings.SetSelectionOptions(
2864cdf0e10cSrcweir aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
2865cdf0e10cSrcweir aSettings.SetStyleSettings(aStyleSettings);
2866cdf0e10cSrcweir m_pWindow->SetSettings(aSettings, sal_True);
2867cdf0e10cSrcweir }
2868cdf0e10cSrcweir }
2869cdf0e10cSrcweir }
2870cdf0e10cSrcweir
2871cdf0e10cSrcweir //------------------------------------------------------------------------------
Init(Window & rParent,const Reference<XRowSet> & xCursor)2872cdf0e10cSrcweir void DbFilterField::Init( Window& rParent, const Reference< XRowSet >& xCursor )
2873cdf0e10cSrcweir {
2874cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet > xModel(m_rColumn.getModel());
2875cdf0e10cSrcweir m_rColumn.SetAlignment(::com::sun::star::awt::TextAlign::LEFT);
2876cdf0e10cSrcweir
2877cdf0e10cSrcweir if (xModel.is())
2878cdf0e10cSrcweir {
2879cdf0e10cSrcweir m_bFilterList = ::comphelper::hasProperty(FM_PROP_FILTERPROPOSAL, xModel) && ::comphelper::getBOOL(xModel->getPropertyValue(FM_PROP_FILTERPROPOSAL));
2880cdf0e10cSrcweir if (m_bFilterList)
2881cdf0e10cSrcweir m_nControlClass = ::com::sun::star::form::FormComponentType::COMBOBOX;
2882cdf0e10cSrcweir else
2883cdf0e10cSrcweir {
2884cdf0e10cSrcweir sal_Int16 nClassId = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_CLASSID));
2885cdf0e10cSrcweir switch (nClassId)
2886cdf0e10cSrcweir {
2887cdf0e10cSrcweir case FormComponentType::CHECKBOX:
2888cdf0e10cSrcweir case FormComponentType::LISTBOX:
2889cdf0e10cSrcweir case FormComponentType::COMBOBOX:
2890cdf0e10cSrcweir m_nControlClass = nClassId;
2891cdf0e10cSrcweir break;
2892cdf0e10cSrcweir default:
2893cdf0e10cSrcweir if (m_bFilterList)
2894cdf0e10cSrcweir m_nControlClass = FormComponentType::COMBOBOX;
2895cdf0e10cSrcweir else
2896cdf0e10cSrcweir m_nControlClass = FormComponentType::TEXTFIELD;
2897cdf0e10cSrcweir }
2898cdf0e10cSrcweir }
2899cdf0e10cSrcweir }
2900cdf0e10cSrcweir
2901cdf0e10cSrcweir CreateControl( &rParent, xModel );
2902cdf0e10cSrcweir DbCellControl::Init( rParent, xCursor );
2903cdf0e10cSrcweir
2904cdf0e10cSrcweir // filter cells are never readonly
2905cdf0e10cSrcweir // 31.07.2002 - 101584 - fs@openoffice.org
2906cdf0e10cSrcweir Edit* pAsEdit = dynamic_cast< Edit* >( m_pWindow );
2907cdf0e10cSrcweir if ( pAsEdit )
2908cdf0e10cSrcweir pAsEdit->SetReadOnly( sal_False );
2909cdf0e10cSrcweir }
2910cdf0e10cSrcweir
2911cdf0e10cSrcweir //------------------------------------------------------------------------------
CreateController() const2912cdf0e10cSrcweir CellControllerRef DbFilterField::CreateController() const
2913cdf0e10cSrcweir {
2914cdf0e10cSrcweir CellControllerRef xController;
2915cdf0e10cSrcweir switch (m_nControlClass)
2916cdf0e10cSrcweir {
2917cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::CHECKBOX:
2918cdf0e10cSrcweir xController = new CheckBoxCellController((CheckBoxControl*)m_pWindow);
2919cdf0e10cSrcweir break;
2920cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::LISTBOX:
2921cdf0e10cSrcweir xController = new ListBoxCellController((ListBoxControl*)m_pWindow);
2922cdf0e10cSrcweir break;
2923cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::COMBOBOX:
2924cdf0e10cSrcweir xController = new ComboBoxCellController((ComboBoxControl*)m_pWindow);
2925cdf0e10cSrcweir break;
2926cdf0e10cSrcweir default:
2927cdf0e10cSrcweir if (m_bFilterList)
2928cdf0e10cSrcweir xController = new ComboBoxCellController((ComboBoxControl*)m_pWindow);
2929cdf0e10cSrcweir else
2930cdf0e10cSrcweir xController = new EditCellController((Edit*)m_pWindow);
2931cdf0e10cSrcweir }
2932cdf0e10cSrcweir return xController;
2933cdf0e10cSrcweir }
2934cdf0e10cSrcweir
2935cdf0e10cSrcweir //------------------------------------------------------------------------------
updateFromModel(Reference<XPropertySet> _rxModel)2936cdf0e10cSrcweir void DbFilterField::updateFromModel( Reference< XPropertySet > _rxModel )
2937cdf0e10cSrcweir {
2938cdf0e10cSrcweir OSL_ENSURE( _rxModel.is() && m_pWindow, "DbFilterField::updateFromModel: invalid call!" );
2939cdf0e10cSrcweir (void)_rxModel;
2940cdf0e10cSrcweir
2941cdf0e10cSrcweir OSL_ENSURE( sal_False, "DbListBox::updateFromModel: not implemented yet (how the hell did you reach this?)!" );
2942cdf0e10cSrcweir // TODO: implement this.
2943cdf0e10cSrcweir // remember: updateFromModel should be some kind of opposite of commitControl
2944cdf0e10cSrcweir }
2945cdf0e10cSrcweir
2946cdf0e10cSrcweir //------------------------------------------------------------------------------
commitControl()2947cdf0e10cSrcweir sal_Bool DbFilterField::commitControl()
2948cdf0e10cSrcweir {
2949cdf0e10cSrcweir String aText(m_aText);
2950cdf0e10cSrcweir switch (m_nControlClass)
2951cdf0e10cSrcweir {
2952cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::CHECKBOX:
2953cdf0e10cSrcweir return sal_True;
2954cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::LISTBOX:
2955cdf0e10cSrcweir aText.Erase();
2956cdf0e10cSrcweir if (static_cast<ListBox*>(m_pWindow)->GetSelectEntryCount())
2957cdf0e10cSrcweir {
2958cdf0e10cSrcweir sal_Int16 nPos = (sal_Int16)static_cast<ListBox*>(m_pWindow)->GetSelectEntryPos();
2959cdf0e10cSrcweir if ( ( nPos >= 0 ) && ( nPos < m_aValueList.getLength() ) )
2960*24c56ab9SHerbert Dürr aText = m_aValueList.getConstArray()[nPos];
2961cdf0e10cSrcweir }
2962cdf0e10cSrcweir
2963cdf0e10cSrcweir if (m_aText != aText)
2964cdf0e10cSrcweir {
2965cdf0e10cSrcweir m_aText = aText;
2966cdf0e10cSrcweir m_aCommitLink.Call(this);
2967cdf0e10cSrcweir }
2968cdf0e10cSrcweir return sal_True;
2969cdf0e10cSrcweir default:
2970cdf0e10cSrcweir aText = m_pWindow->GetText();
2971cdf0e10cSrcweir }
2972cdf0e10cSrcweir
2973cdf0e10cSrcweir if (m_aText != aText)
2974cdf0e10cSrcweir {
2975cdf0e10cSrcweir // check the text with the SQL-Parser
2976cdf0e10cSrcweir String aNewText(aText);
2977cdf0e10cSrcweir aNewText.EraseTrailingChars();
2978cdf0e10cSrcweir if (aNewText.Len() != 0)
2979cdf0e10cSrcweir {
2980cdf0e10cSrcweir ::rtl::OUString aErrorMsg;
2981cdf0e10cSrcweir Reference< XNumberFormatter > xNumberFormatter(m_rColumn.GetParent().getNumberFormatter());
2982cdf0e10cSrcweir
2983cdf0e10cSrcweir ::rtl::Reference< ISQLParseNode > xParseNode = predicateTree(aErrorMsg, aNewText,xNumberFormatter, m_rColumn.GetField());
2984cdf0e10cSrcweir if (xParseNode.is())
2985cdf0e10cSrcweir {
2986cdf0e10cSrcweir ::rtl::OUString aPreparedText;
2987cdf0e10cSrcweir
2988cdf0e10cSrcweir ::com::sun::star::lang::Locale aAppLocale = Application::GetSettings().GetUILocale();
2989cdf0e10cSrcweir
2990cdf0e10cSrcweir Reference< XRowSet > xDataSourceRowSet(
2991cdf0e10cSrcweir (Reference< XInterface >)*m_rColumn.GetParent().getDataSource(), UNO_QUERY);
2992cdf0e10cSrcweir Reference< XConnection > xConnection(getRowSetConnection(xDataSourceRowSet));
2993cdf0e10cSrcweir
2994cdf0e10cSrcweir xParseNode->parseNodeToPredicateStr(aPreparedText,
2995cdf0e10cSrcweir xConnection,
2996cdf0e10cSrcweir xNumberFormatter,
2997cdf0e10cSrcweir m_rColumn.GetField(),aAppLocale,'.',
2998cdf0e10cSrcweir getParseContext());
2999cdf0e10cSrcweir m_aText = aPreparedText;
3000cdf0e10cSrcweir }
3001cdf0e10cSrcweir else
3002cdf0e10cSrcweir {
3003cdf0e10cSrcweir // display the error and return sal_False
3004cdf0e10cSrcweir String aTitle( SVX_RES(RID_STR_SYNTAXERROR) );
3005cdf0e10cSrcweir
3006cdf0e10cSrcweir SQLException aError;
3007cdf0e10cSrcweir aError.Message = aErrorMsg;
3008cdf0e10cSrcweir displayException(aError, m_pWindow->GetParent());
3009cdf0e10cSrcweir // TODO: transport the title
3010cdf0e10cSrcweir
3011cdf0e10cSrcweir return sal_False;
3012cdf0e10cSrcweir }
3013cdf0e10cSrcweir }
3014cdf0e10cSrcweir else
3015cdf0e10cSrcweir m_aText = aText;
3016cdf0e10cSrcweir
3017cdf0e10cSrcweir m_pWindow->SetText(m_aText);
3018cdf0e10cSrcweir m_aCommitLink.Call(this);
3019cdf0e10cSrcweir }
3020cdf0e10cSrcweir return sal_True;
3021cdf0e10cSrcweir }
3022cdf0e10cSrcweir
3023cdf0e10cSrcweir //------------------------------------------------------------------------------
SetText(const String & rText)3024cdf0e10cSrcweir void DbFilterField::SetText(const String& rText)
3025cdf0e10cSrcweir {
3026cdf0e10cSrcweir m_aText = rText;
3027cdf0e10cSrcweir switch (m_nControlClass)
3028cdf0e10cSrcweir {
3029cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::CHECKBOX:
3030cdf0e10cSrcweir {
3031cdf0e10cSrcweir TriState eState;
3032cdf0e10cSrcweir if (rText.EqualsAscii("1"))
3033cdf0e10cSrcweir eState = STATE_CHECK;
3034cdf0e10cSrcweir else if (rText.EqualsAscii("0"))
3035cdf0e10cSrcweir eState = STATE_NOCHECK;
3036cdf0e10cSrcweir else
3037cdf0e10cSrcweir eState = STATE_DONTKNOW;
3038cdf0e10cSrcweir
3039cdf0e10cSrcweir ((CheckBoxControl*)m_pWindow)->GetBox().SetState(eState);
3040cdf0e10cSrcweir ((CheckBoxControl*)m_pPainter)->GetBox().SetState(eState);
3041cdf0e10cSrcweir } break;
3042cdf0e10cSrcweir case ::com::sun::star::form::FormComponentType::LISTBOX:
3043cdf0e10cSrcweir {
3044cdf0e10cSrcweir String aText;
3045cdf0e10cSrcweir Sequence<sal_Int16> aPosSeq = ::comphelper::findValue(m_aValueList, m_aText, sal_True);
3046cdf0e10cSrcweir if (aPosSeq.getLength())
3047cdf0e10cSrcweir static_cast<ListBox*>(m_pWindow)->SelectEntryPos(aPosSeq.getConstArray()[0], sal_True);
3048cdf0e10cSrcweir else
3049cdf0e10cSrcweir static_cast<ListBox*>(m_pWindow)->SetNoSelection();
3050cdf0e10cSrcweir } break;
3051cdf0e10cSrcweir default:
3052cdf0e10cSrcweir m_pWindow->SetText(m_aText);
3053cdf0e10cSrcweir }
3054cdf0e10cSrcweir
3055cdf0e10cSrcweir // now force a repaint on the window
3056cdf0e10cSrcweir m_rColumn.GetParent().RowModified(0,m_rColumn.GetId());
3057cdf0e10cSrcweir }
3058cdf0e10cSrcweir
3059cdf0e10cSrcweir //------------------------------------------------------------------------------
Update()3060cdf0e10cSrcweir void DbFilterField::Update()
3061cdf0e10cSrcweir {
3062cdf0e10cSrcweir // should we fill the combobox with a filter proposal?
3063cdf0e10cSrcweir if (m_bFilterList && !m_bFilterListFilled)
3064cdf0e10cSrcweir {
3065cdf0e10cSrcweir m_bFilterListFilled = sal_True;
3066cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet > xField = m_rColumn.GetField();
3067cdf0e10cSrcweir if (!xField.is())
3068cdf0e10cSrcweir return;
3069cdf0e10cSrcweir
3070cdf0e10cSrcweir ::rtl::OUString aName;
3071cdf0e10cSrcweir xField->getPropertyValue(FM_PROP_NAME) >>= aName;
3072cdf0e10cSrcweir
3073cdf0e10cSrcweir // the columnmodel
3074cdf0e10cSrcweir Reference< ::com::sun::star::container::XChild > xModelAsChild(m_rColumn.getModel(), UNO_QUERY);
3075cdf0e10cSrcweir // the grid model
3076cdf0e10cSrcweir xModelAsChild = Reference< ::com::sun::star::container::XChild > (xModelAsChild->getParent(),UNO_QUERY);
3077cdf0e10cSrcweir Reference< XRowSet > xForm(xModelAsChild->getParent(), UNO_QUERY);
3078cdf0e10cSrcweir if (!xForm.is())
3079cdf0e10cSrcweir return;
3080cdf0e10cSrcweir
3081cdf0e10cSrcweir Reference<XPropertySet> xFormProp(xForm,UNO_QUERY);
3082cdf0e10cSrcweir Reference< XTablesSupplier > xSupTab;
3083cdf0e10cSrcweir xFormProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSupTab;
3084cdf0e10cSrcweir
3085cdf0e10cSrcweir Reference< XConnection > xConnection(getRowSetConnection(xForm));
3086cdf0e10cSrcweir if (!xSupTab.is())
3087cdf0e10cSrcweir return;
3088cdf0e10cSrcweir
3089cdf0e10cSrcweir // search the field
3090cdf0e10cSrcweir Reference< XColumnsSupplier > xSupCol(xSupTab,UNO_QUERY);
3091cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > xFieldNames = xSupCol->getColumns();
3092cdf0e10cSrcweir if (!xFieldNames->hasByName(aName))
3093cdf0e10cSrcweir return;
3094cdf0e10cSrcweir
3095cdf0e10cSrcweir Reference< ::com::sun::star::container::XNameAccess > xTablesNames = xSupTab->getTables();
3096cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet > xComposerFieldAsSet(xFieldNames->getByName(aName),UNO_QUERY);
3097cdf0e10cSrcweir
3098cdf0e10cSrcweir if (xComposerFieldAsSet.is() && ::comphelper::hasProperty(FM_PROP_TABLENAME, xComposerFieldAsSet) &&
3099cdf0e10cSrcweir ::comphelper::hasProperty(FM_PROP_FIELDSOURCE, xComposerFieldAsSet))
3100cdf0e10cSrcweir {
3101cdf0e10cSrcweir ::rtl::OUString aFieldName;
3102cdf0e10cSrcweir ::rtl::OUString aTableName;
3103cdf0e10cSrcweir xComposerFieldAsSet->getPropertyValue(FM_PROP_FIELDSOURCE) >>= aFieldName;
3104cdf0e10cSrcweir xComposerFieldAsSet->getPropertyValue(FM_PROP_TABLENAME) >>= aTableName;
3105cdf0e10cSrcweir
3106cdf0e10cSrcweir // no possibility to create a select statement
3107cdf0e10cSrcweir // looking for the complete table name
3108cdf0e10cSrcweir if (!xTablesNames->hasByName(aTableName))
3109cdf0e10cSrcweir return;
3110cdf0e10cSrcweir
3111cdf0e10cSrcweir // ein Statement aufbauen und abschicken als query
3112cdf0e10cSrcweir // Access to the connection
3113cdf0e10cSrcweir Reference< XStatement > xStatement;
3114cdf0e10cSrcweir Reference< XResultSet > xListCursor;
3115cdf0e10cSrcweir Reference< ::com::sun::star::sdb::XColumn > xDataField;
3116cdf0e10cSrcweir
3117cdf0e10cSrcweir try
3118cdf0e10cSrcweir {
3119cdf0e10cSrcweir Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData();
3120cdf0e10cSrcweir
3121cdf0e10cSrcweir String aQuote( xMeta->getIdentifierQuoteString());
3122cdf0e10cSrcweir String aStatement;
3123cdf0e10cSrcweir aStatement.AssignAscii("SELECT DISTINCT ");
3124cdf0e10cSrcweir
3125cdf0e10cSrcweir aStatement += String(quoteName(aQuote, aName));
3126cdf0e10cSrcweir if (aFieldName.getLength() && aName != aFieldName)
3127cdf0e10cSrcweir {
3128cdf0e10cSrcweir aStatement.AppendAscii(" AS ");
3129cdf0e10cSrcweir aStatement += quoteName(aQuote, aFieldName).getStr();
3130cdf0e10cSrcweir }
3131cdf0e10cSrcweir
3132cdf0e10cSrcweir aStatement.AppendAscii(" FROM ");
3133cdf0e10cSrcweir
3134cdf0e10cSrcweir Reference< XPropertySet > xTableNameAccess( xTablesNames->getByName(aTableName), UNO_QUERY_THROW );
3135cdf0e10cSrcweir aStatement += composeTableNameForSelect( xConnection, xTableNameAccess ).getStr();
3136cdf0e10cSrcweir
3137cdf0e10cSrcweir xStatement = xConnection->createStatement();
3138cdf0e10cSrcweir Reference< ::com::sun::star::beans::XPropertySet > xStatementProps(xStatement, UNO_QUERY);
3139cdf0e10cSrcweir xStatementProps->setPropertyValue(FM_PROP_ESCAPE_PROCESSING, makeAny((sal_Bool)sal_True));
3140cdf0e10cSrcweir
3141cdf0e10cSrcweir xListCursor = xStatement->executeQuery(aStatement);
3142cdf0e10cSrcweir
3143cdf0e10cSrcweir Reference< ::com::sun::star::sdbcx::XColumnsSupplier > xSupplyCols(xListCursor, UNO_QUERY);
3144cdf0e10cSrcweir Reference< ::com::sun::star::container::XIndexAccess > xFields(xSupplyCols->getColumns(), UNO_QUERY);
3145cdf0e10cSrcweir ::cppu::extractInterface(xDataField, xFields->getByIndex(0));
3146cdf0e10cSrcweir if (!xDataField.is())
3147cdf0e10cSrcweir return;
3148cdf0e10cSrcweir }
3149cdf0e10cSrcweir catch(const Exception&)
3150cdf0e10cSrcweir {
3151cdf0e10cSrcweir ::comphelper::disposeComponent(xStatement);
3152cdf0e10cSrcweir return;
3153cdf0e10cSrcweir }
3154cdf0e10cSrcweir
3155cdf0e10cSrcweir sal_Int16 i = 0;
3156cdf0e10cSrcweir ::std::vector< ::rtl::OUString > aStringList;
3157cdf0e10cSrcweir aStringList.reserve(16);
3158cdf0e10cSrcweir ::rtl::OUString aStr;
3159cdf0e10cSrcweir com::sun::star::util::Date aNullDate = m_rColumn.GetParent().getNullDate();
3160cdf0e10cSrcweir sal_Int32 nFormatKey = m_rColumn.GetKey();
3161cdf0e10cSrcweir Reference< XNumberFormatter > xFormatter = m_rColumn.GetParent().getNumberFormatter();
3162cdf0e10cSrcweir sal_Int16 nKeyType = ::comphelper::getNumberFormatType(xFormatter->getNumberFormatsSupplier()->getNumberFormats(), nFormatKey);
3163cdf0e10cSrcweir
3164cdf0e10cSrcweir while (!xListCursor->isAfterLast() && i++ < SHRT_MAX) // max anzahl eintraege
3165cdf0e10cSrcweir {
3166cdf0e10cSrcweir aStr = getFormattedValue(xDataField, xFormatter, aNullDate, nFormatKey, nKeyType);
3167cdf0e10cSrcweir aStringList.push_back(aStr);
3168cdf0e10cSrcweir xListCursor->next();
3169cdf0e10cSrcweir }
3170cdf0e10cSrcweir
3171cdf0e10cSrcweir // filling the entries for the combobox
3172cdf0e10cSrcweir for (::std::vector< ::rtl::OUString >::const_iterator iter = aStringList.begin();
3173cdf0e10cSrcweir iter != aStringList.end(); ++iter)
3174cdf0e10cSrcweir ((ComboBox*)m_pWindow)->InsertEntry(*iter, LISTBOX_APPEND);
3175cdf0e10cSrcweir }
3176cdf0e10cSrcweir }
3177cdf0e10cSrcweir }
3178cdf0e10cSrcweir
3179cdf0e10cSrcweir //------------------------------------------------------------------------------
GetFormatText(const Reference<XColumn> &,const Reference<XNumberFormatter> &,Color **)3180cdf0e10cSrcweir XubString DbFilterField::GetFormatText(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
3181cdf0e10cSrcweir {
3182cdf0e10cSrcweir return XubString();
3183cdf0e10cSrcweir }
3184cdf0e10cSrcweir
3185cdf0e10cSrcweir //------------------------------------------------------------------
UpdateFromField(const Reference<XColumn> &,const Reference<XNumberFormatter> &)3186cdf0e10cSrcweir void DbFilterField::UpdateFromField(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/)
3187cdf0e10cSrcweir {
3188cdf0e10cSrcweir DBG_ERROR( "DbFilterField::UpdateFromField: cannot update a filter control from a field!" );
3189cdf0e10cSrcweir }
3190cdf0e10cSrcweir
3191cdf0e10cSrcweir //------------------------------------------------------------------
IMPL_LINK(DbFilterField,OnClick,void *,EMPTYARG)3192cdf0e10cSrcweir IMPL_LINK( DbFilterField, OnClick, void*, EMPTYARG )
3193cdf0e10cSrcweir {
3194cdf0e10cSrcweir TriState eState = ((CheckBoxControl*)m_pWindow)->GetBox().GetState();
3195cdf0e10cSrcweir String aText;
3196cdf0e10cSrcweir
3197cdf0e10cSrcweir switch (eState)
3198cdf0e10cSrcweir {
3199cdf0e10cSrcweir case STATE_CHECK:
3200cdf0e10cSrcweir aText.AssignAscii("1");
3201cdf0e10cSrcweir break;
3202cdf0e10cSrcweir case STATE_NOCHECK:
3203cdf0e10cSrcweir aText.AssignAscii("0");
3204cdf0e10cSrcweir break;
3205cdf0e10cSrcweir case STATE_DONTKNOW:
3206cdf0e10cSrcweir aText = String();
3207cdf0e10cSrcweir break;
3208cdf0e10cSrcweir }
3209cdf0e10cSrcweir
3210cdf0e10cSrcweir if (m_aText != aText)
3211cdf0e10cSrcweir {
3212cdf0e10cSrcweir m_aText = aText;
3213cdf0e10cSrcweir m_aCommitLink.Call(this);
3214cdf0e10cSrcweir }
3215cdf0e10cSrcweir return 1;
3216cdf0e10cSrcweir }
3217cdf0e10cSrcweir
3218cdf0e10cSrcweir /*************************************************************************/
3219cdf0e10cSrcweir TYPEINIT0(FmXGridCell);
3220cdf0e10cSrcweir
3221cdf0e10cSrcweir
3222cdf0e10cSrcweir DBG_NAME(FmXGridCell);
3223cdf0e10cSrcweir //-----------------------------------------------------------------------------
FmXGridCell(DbGridColumn * pColumn,DbCellControl * _pControl)3224cdf0e10cSrcweir FmXGridCell::FmXGridCell( DbGridColumn* pColumn, DbCellControl* _pControl )
3225cdf0e10cSrcweir :OComponentHelper(m_aMutex)
3226cdf0e10cSrcweir ,m_pColumn(pColumn)
3227cdf0e10cSrcweir ,m_pCellControl( _pControl )
3228cdf0e10cSrcweir ,m_aWindowListeners( m_aMutex )
3229cdf0e10cSrcweir ,m_aFocusListeners( m_aMutex )
3230cdf0e10cSrcweir ,m_aKeyListeners( m_aMutex )
3231cdf0e10cSrcweir ,m_aMouseListeners( m_aMutex )
3232cdf0e10cSrcweir ,m_aMouseMotionListeners( m_aMutex )
3233cdf0e10cSrcweir {
3234cdf0e10cSrcweir DBG_CTOR(FmXGridCell,NULL);
3235cdf0e10cSrcweir }
3236cdf0e10cSrcweir
3237cdf0e10cSrcweir //-----------------------------------------------------------------------------
init()3238cdf0e10cSrcweir void FmXGridCell::init()
3239cdf0e10cSrcweir {
3240cdf0e10cSrcweir Window* pEventWindow( getEventWindow() );
3241cdf0e10cSrcweir if ( pEventWindow )
3242cdf0e10cSrcweir pEventWindow->AddEventListener( LINK( this, FmXGridCell, OnWindowEvent ) );
3243cdf0e10cSrcweir }
3244cdf0e10cSrcweir
3245cdf0e10cSrcweir //-----------------------------------------------------------------------------
getEventWindow() const3246cdf0e10cSrcweir Window* FmXGridCell::getEventWindow() const
3247cdf0e10cSrcweir {
3248cdf0e10cSrcweir if ( m_pCellControl )
3249cdf0e10cSrcweir return &m_pCellControl->GetWindow();
3250cdf0e10cSrcweir return NULL;
3251cdf0e10cSrcweir }
3252cdf0e10cSrcweir
3253cdf0e10cSrcweir //-----------------------------------------------------------------------------
~FmXGridCell()3254cdf0e10cSrcweir FmXGridCell::~FmXGridCell()
3255cdf0e10cSrcweir {
3256cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed)
3257cdf0e10cSrcweir {
3258cdf0e10cSrcweir acquire();
3259cdf0e10cSrcweir dispose();
3260cdf0e10cSrcweir }
3261cdf0e10cSrcweir
3262cdf0e10cSrcweir DBG_DTOR(FmXGridCell,NULL);
3263cdf0e10cSrcweir }
3264cdf0e10cSrcweir
3265cdf0e10cSrcweir //------------------------------------------------------------------
SetTextLineColor()3266cdf0e10cSrcweir void FmXGridCell::SetTextLineColor()
3267cdf0e10cSrcweir {
3268cdf0e10cSrcweir if (m_pCellControl)
3269cdf0e10cSrcweir m_pCellControl->SetTextLineColor();
3270cdf0e10cSrcweir }
3271cdf0e10cSrcweir
3272cdf0e10cSrcweir //------------------------------------------------------------------
SetTextLineColor(const Color & _rColor)3273cdf0e10cSrcweir void FmXGridCell::SetTextLineColor(const Color& _rColor)
3274cdf0e10cSrcweir {
3275cdf0e10cSrcweir if (m_pCellControl)
3276cdf0e10cSrcweir m_pCellControl->SetTextLineColor(_rColor);
3277cdf0e10cSrcweir }
3278cdf0e10cSrcweir
3279cdf0e10cSrcweir // XTypeProvider
3280cdf0e10cSrcweir //------------------------------------------------------------------
getTypes()3281cdf0e10cSrcweir Sequence< Type > SAL_CALL FmXGridCell::getTypes( ) throw (RuntimeException)
3282cdf0e10cSrcweir {
3283cdf0e10cSrcweir Sequence< uno::Type > aTypes = ::comphelper::concatSequences(
3284cdf0e10cSrcweir ::cppu::OComponentHelper::getTypes(),
3285cdf0e10cSrcweir FmXGridCell_Base::getTypes()
3286cdf0e10cSrcweir );
3287cdf0e10cSrcweir if ( m_pCellControl )
3288cdf0e10cSrcweir aTypes = ::comphelper::concatSequences(
3289cdf0e10cSrcweir aTypes,
3290cdf0e10cSrcweir FmXGridCell_WindowBase::getTypes()
3291cdf0e10cSrcweir );
3292cdf0e10cSrcweir return aTypes;
3293cdf0e10cSrcweir }
3294cdf0e10cSrcweir
3295cdf0e10cSrcweir //------------------------------------------------------------------
IMPLEMENT_GET_IMPLEMENTATION_ID(FmXGridCell)3296cdf0e10cSrcweir IMPLEMENT_GET_IMPLEMENTATION_ID( FmXGridCell )
3297cdf0e10cSrcweir
3298cdf0e10cSrcweir // OComponentHelper
3299cdf0e10cSrcweir //-----------------------------------------------------------------------------
3300cdf0e10cSrcweir void FmXGridCell::disposing()
3301cdf0e10cSrcweir {
3302cdf0e10cSrcweir lang::EventObject aEvent( *this );
3303cdf0e10cSrcweir m_aWindowListeners.disposeAndClear( aEvent );
3304cdf0e10cSrcweir m_aFocusListeners.disposeAndClear( aEvent );
3305cdf0e10cSrcweir m_aKeyListeners.disposeAndClear( aEvent );
3306cdf0e10cSrcweir m_aMouseListeners.disposeAndClear( aEvent );
3307cdf0e10cSrcweir m_aMouseMotionListeners.disposeAndClear( aEvent );
3308cdf0e10cSrcweir
3309cdf0e10cSrcweir OComponentHelper::disposing();
3310cdf0e10cSrcweir m_pColumn = NULL;
3311cdf0e10cSrcweir DELETEZ(m_pCellControl);
3312cdf0e10cSrcweir }
3313cdf0e10cSrcweir
3314cdf0e10cSrcweir //------------------------------------------------------------------
queryAggregation(const::com::sun::star::uno::Type & _rType)3315cdf0e10cSrcweir Any SAL_CALL FmXGridCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
3316cdf0e10cSrcweir {
3317cdf0e10cSrcweir Any aReturn = OComponentHelper::queryAggregation( _rType );
3318cdf0e10cSrcweir
3319cdf0e10cSrcweir if ( !aReturn.hasValue() )
3320cdf0e10cSrcweir aReturn = FmXGridCell_Base::queryInterface( _rType );
3321cdf0e10cSrcweir
3322cdf0e10cSrcweir if ( !aReturn.hasValue() && ( m_pCellControl != NULL ) )
3323cdf0e10cSrcweir aReturn = FmXGridCell_WindowBase::queryInterface( _rType );
3324cdf0e10cSrcweir
3325cdf0e10cSrcweir return aReturn;
3326cdf0e10cSrcweir }
3327cdf0e10cSrcweir
3328cdf0e10cSrcweir // ::com::sun::star::awt::XControl
3329cdf0e10cSrcweir //-----------------------------------------------------------------------------
getContext()3330cdf0e10cSrcweir Reference< XInterface > FmXGridCell::getContext() throw( RuntimeException )
3331cdf0e10cSrcweir {
3332cdf0e10cSrcweir return Reference< XInterface > ();
3333cdf0e10cSrcweir }
3334cdf0e10cSrcweir
3335cdf0e10cSrcweir //-----------------------------------------------------------------------------
getModel()3336cdf0e10cSrcweir Reference< ::com::sun::star::awt::XControlModel > FmXGridCell::getModel() throw( ::com::sun::star::uno::RuntimeException )
3337cdf0e10cSrcweir {
3338cdf0e10cSrcweir return Reference< ::com::sun::star::awt::XControlModel > (m_pColumn->getModel(), UNO_QUERY);
3339cdf0e10cSrcweir }
3340cdf0e10cSrcweir
3341cdf0e10cSrcweir // ::com::sun::star::form::XBoundControl
3342cdf0e10cSrcweir //------------------------------------------------------------------
getLock()3343cdf0e10cSrcweir sal_Bool FmXGridCell::getLock() throw( RuntimeException )
3344cdf0e10cSrcweir {
3345cdf0e10cSrcweir return m_pColumn->isLocked();
3346cdf0e10cSrcweir }
3347cdf0e10cSrcweir
3348cdf0e10cSrcweir //------------------------------------------------------------------
setLock(sal_Bool _bLock)3349cdf0e10cSrcweir void FmXGridCell::setLock(sal_Bool _bLock) throw( RuntimeException )
3350cdf0e10cSrcweir {
3351cdf0e10cSrcweir if (getLock() == _bLock)
3352cdf0e10cSrcweir return;
3353cdf0e10cSrcweir else
3354cdf0e10cSrcweir {
3355cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex);
3356cdf0e10cSrcweir m_pColumn->setLock(_bLock);
3357cdf0e10cSrcweir }
3358cdf0e10cSrcweir }
3359cdf0e10cSrcweir
3360cdf0e10cSrcweir //------------------------------------------------------------------
setPosSize(::sal_Int32 _XX,::sal_Int32 _Y,::sal_Int32 _Width,::sal_Int32 _Height,::sal_Int16 _Flags)3361cdf0e10cSrcweir void SAL_CALL FmXGridCell::setPosSize( ::sal_Int32 _XX, ::sal_Int32 _Y, ::sal_Int32 _Width, ::sal_Int32 _Height, ::sal_Int16 _Flags ) throw (RuntimeException)
3362cdf0e10cSrcweir {
3363cdf0e10cSrcweir OSL_ENSURE( false, "FmXGridCell::setPosSize: not implemented" );
3364cdf0e10cSrcweir (void)_XX;
3365cdf0e10cSrcweir (void)_Y;
3366cdf0e10cSrcweir (void)_Width;
3367cdf0e10cSrcweir (void)_Height;
3368cdf0e10cSrcweir (void)_Flags;
3369cdf0e10cSrcweir // not allowed to tamper with this for a grid cell
3370cdf0e10cSrcweir }
3371cdf0e10cSrcweir
3372cdf0e10cSrcweir //------------------------------------------------------------------
getPosSize()3373cdf0e10cSrcweir awt::Rectangle SAL_CALL FmXGridCell::getPosSize( ) throw (RuntimeException)
3374cdf0e10cSrcweir {
3375cdf0e10cSrcweir OSL_ENSURE( false, "FmXGridCell::getPosSize: not implemented" );
3376cdf0e10cSrcweir return awt::Rectangle();
3377cdf0e10cSrcweir }
3378cdf0e10cSrcweir
3379cdf0e10cSrcweir //------------------------------------------------------------------
setVisible(::sal_Bool _Visible)3380cdf0e10cSrcweir void SAL_CALL FmXGridCell::setVisible( ::sal_Bool _Visible ) throw (RuntimeException)
3381cdf0e10cSrcweir {
3382cdf0e10cSrcweir OSL_ENSURE( false, "FmXGridCell::setVisible: not implemented" );
3383cdf0e10cSrcweir (void)_Visible;
3384cdf0e10cSrcweir // not allowed to tamper with this for a grid cell
3385cdf0e10cSrcweir }
3386cdf0e10cSrcweir
3387cdf0e10cSrcweir //------------------------------------------------------------------
setEnable(::sal_Bool _Enable)3388cdf0e10cSrcweir void SAL_CALL FmXGridCell::setEnable( ::sal_Bool _Enable ) throw (RuntimeException)
3389cdf0e10cSrcweir {
3390cdf0e10cSrcweir OSL_ENSURE( false, "FmXGridCell::setEnable: not implemented" );
3391cdf0e10cSrcweir (void)_Enable;
3392cdf0e10cSrcweir // not allowed to tamper with this for a grid cell
3393cdf0e10cSrcweir }
3394cdf0e10cSrcweir
3395cdf0e10cSrcweir //------------------------------------------------------------------
setFocus()3396cdf0e10cSrcweir void SAL_CALL FmXGridCell::setFocus( ) throw (RuntimeException)
3397cdf0e10cSrcweir {
3398cdf0e10cSrcweir OSL_ENSURE( false, "FmXGridCell::setFocus: not implemented" );
3399cdf0e10cSrcweir // not allowed to tamper with this for a grid cell
3400cdf0e10cSrcweir }
3401cdf0e10cSrcweir
3402cdf0e10cSrcweir //------------------------------------------------------------------
addWindowListener(const Reference<awt::XWindowListener> & _rxListener)3403cdf0e10cSrcweir void SAL_CALL FmXGridCell::addWindowListener( const Reference< awt::XWindowListener >& _rxListener ) throw (RuntimeException)
3404cdf0e10cSrcweir {
3405cdf0e10cSrcweir m_aWindowListeners.addInterface( _rxListener );
3406cdf0e10cSrcweir }
3407cdf0e10cSrcweir
3408cdf0e10cSrcweir //------------------------------------------------------------------
removeWindowListener(const Reference<awt::XWindowListener> & _rxListener)3409cdf0e10cSrcweir void SAL_CALL FmXGridCell::removeWindowListener( const Reference< awt::XWindowListener >& _rxListener ) throw (RuntimeException)
3410cdf0e10cSrcweir {
3411cdf0e10cSrcweir m_aWindowListeners.removeInterface( _rxListener );
3412cdf0e10cSrcweir }
3413cdf0e10cSrcweir
3414cdf0e10cSrcweir //------------------------------------------------------------------
addFocusListener(const Reference<awt::XFocusListener> & _rxListener)3415cdf0e10cSrcweir void SAL_CALL FmXGridCell::addFocusListener( const Reference< awt::XFocusListener >& _rxListener ) throw (RuntimeException)
3416cdf0e10cSrcweir {
3417cdf0e10cSrcweir m_aFocusListeners.addInterface( _rxListener );
3418cdf0e10cSrcweir }
3419cdf0e10cSrcweir
3420cdf0e10cSrcweir //------------------------------------------------------------------
removeFocusListener(const Reference<awt::XFocusListener> & _rxListener)3421cdf0e10cSrcweir void SAL_CALL FmXGridCell::removeFocusListener( const Reference< awt::XFocusListener >& _rxListener ) throw (RuntimeException)
3422cdf0e10cSrcweir {
3423cdf0e10cSrcweir m_aFocusListeners.removeInterface( _rxListener );
3424cdf0e10cSrcweir }
3425cdf0e10cSrcweir
3426cdf0e10cSrcweir //------------------------------------------------------------------
addKeyListener(const Reference<awt::XKeyListener> & _rxListener)3427cdf0e10cSrcweir void SAL_CALL FmXGridCell::addKeyListener( const Reference< awt::XKeyListener >& _rxListener ) throw (RuntimeException)
3428cdf0e10cSrcweir {
3429cdf0e10cSrcweir m_aKeyListeners.addInterface( _rxListener );
3430cdf0e10cSrcweir }
3431cdf0e10cSrcweir
3432cdf0e10cSrcweir //------------------------------------------------------------------
removeKeyListener(const Reference<awt::XKeyListener> & _rxListener)3433cdf0e10cSrcweir void SAL_CALL FmXGridCell::removeKeyListener( const Reference< awt::XKeyListener >& _rxListener ) throw (RuntimeException)
3434cdf0e10cSrcweir {
3435cdf0e10cSrcweir m_aKeyListeners.removeInterface( _rxListener );
3436cdf0e10cSrcweir }
3437cdf0e10cSrcweir
3438cdf0e10cSrcweir //------------------------------------------------------------------
addMouseListener(const Reference<awt::XMouseListener> & _rxListener)3439cdf0e10cSrcweir void SAL_CALL FmXGridCell::addMouseListener( const Reference< awt::XMouseListener >& _rxListener ) throw (RuntimeException)
3440cdf0e10cSrcweir {
3441cdf0e10cSrcweir m_aMouseListeners.addInterface( _rxListener );
3442cdf0e10cSrcweir }
3443cdf0e10cSrcweir
3444cdf0e10cSrcweir //------------------------------------------------------------------
removeMouseListener(const Reference<awt::XMouseListener> & _rxListener)3445cdf0e10cSrcweir void SAL_CALL FmXGridCell::removeMouseListener( const Reference< awt::XMouseListener >& _rxListener ) throw (RuntimeException)
3446cdf0e10cSrcweir {
3447cdf0e10cSrcweir m_aMouseListeners.removeInterface( _rxListener );
3448cdf0e10cSrcweir }
3449cdf0e10cSrcweir
3450cdf0e10cSrcweir //------------------------------------------------------------------
addMouseMotionListener(const Reference<awt::XMouseMotionListener> & _rxListener)3451cdf0e10cSrcweir void SAL_CALL FmXGridCell::addMouseMotionListener( const Reference< awt::XMouseMotionListener >& _rxListener ) throw (RuntimeException)
3452cdf0e10cSrcweir {
3453cdf0e10cSrcweir m_aMouseMotionListeners.addInterface( _rxListener );
3454cdf0e10cSrcweir }
3455cdf0e10cSrcweir
3456cdf0e10cSrcweir //------------------------------------------------------------------
removeMouseMotionListener(const Reference<awt::XMouseMotionListener> & _rxListener)3457cdf0e10cSrcweir void SAL_CALL FmXGridCell::removeMouseMotionListener( const Reference< awt::XMouseMotionListener >& _rxListener ) throw (RuntimeException)
3458cdf0e10cSrcweir {
3459cdf0e10cSrcweir m_aMouseMotionListeners.removeInterface( _rxListener );
3460cdf0e10cSrcweir }
3461cdf0e10cSrcweir
3462cdf0e10cSrcweir //------------------------------------------------------------------
addPaintListener(const Reference<awt::XPaintListener> & _rxListener)3463cdf0e10cSrcweir void SAL_CALL FmXGridCell::addPaintListener( const Reference< awt::XPaintListener >& _rxListener ) throw (RuntimeException)
3464cdf0e10cSrcweir {
3465cdf0e10cSrcweir OSL_ENSURE( false, "FmXGridCell::addPaintListener: not implemented" );
3466cdf0e10cSrcweir (void)_rxListener;
3467cdf0e10cSrcweir }
3468cdf0e10cSrcweir
3469cdf0e10cSrcweir //------------------------------------------------------------------
removePaintListener(const Reference<awt::XPaintListener> & _rxListener)3470cdf0e10cSrcweir void SAL_CALL FmXGridCell::removePaintListener( const Reference< awt::XPaintListener >& _rxListener ) throw (RuntimeException)
3471cdf0e10cSrcweir {
3472cdf0e10cSrcweir OSL_ENSURE( false, "FmXGridCell::removePaintListener: not implemented" );
3473cdf0e10cSrcweir (void)_rxListener;
3474cdf0e10cSrcweir }
3475cdf0e10cSrcweir
3476cdf0e10cSrcweir //------------------------------------------------------------------
IMPL_LINK(FmXGridCell,OnWindowEvent,VclWindowEvent *,_pEvent)3477cdf0e10cSrcweir IMPL_LINK( FmXGridCell, OnWindowEvent, VclWindowEvent*, _pEvent )
3478cdf0e10cSrcweir {
3479cdf0e10cSrcweir ENSURE_OR_THROW( _pEvent, "illegal event pointer" );
3480cdf0e10cSrcweir ENSURE_OR_THROW( _pEvent->GetWindow(), "illegal window" );
3481cdf0e10cSrcweir onWindowEvent( _pEvent->GetId(), *_pEvent->GetWindow(), _pEvent->GetData() );
3482cdf0e10cSrcweir return 1L;
3483cdf0e10cSrcweir }
3484cdf0e10cSrcweir
3485cdf0e10cSrcweir //------------------------------------------------------------------------------
onFocusGained(const awt::FocusEvent & _rEvent)3486cdf0e10cSrcweir void FmXGridCell::onFocusGained( const awt::FocusEvent& _rEvent )
3487cdf0e10cSrcweir {
3488cdf0e10cSrcweir m_aFocusListeners.notifyEach( &awt::XFocusListener::focusGained, _rEvent );
3489cdf0e10cSrcweir }
3490cdf0e10cSrcweir
3491cdf0e10cSrcweir //------------------------------------------------------------------------------
onFocusLost(const awt::FocusEvent & _rEvent)3492cdf0e10cSrcweir void FmXGridCell::onFocusLost( const awt::FocusEvent& _rEvent )
3493cdf0e10cSrcweir {
3494cdf0e10cSrcweir m_aFocusListeners.notifyEach( &awt::XFocusListener::focusLost, _rEvent );
3495cdf0e10cSrcweir }
3496cdf0e10cSrcweir
3497cdf0e10cSrcweir //------------------------------------------------------------------------------
onWindowEvent(const sal_uIntPtr _nEventId,const Window & _rWindow,const void * _pEventData)3498cdf0e10cSrcweir void FmXGridCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData )
3499cdf0e10cSrcweir {
3500cdf0e10cSrcweir switch ( _nEventId )
3501cdf0e10cSrcweir {
3502cdf0e10cSrcweir case VCLEVENT_CONTROL_GETFOCUS:
3503cdf0e10cSrcweir case VCLEVENT_WINDOW_GETFOCUS:
3504cdf0e10cSrcweir case VCLEVENT_CONTROL_LOSEFOCUS:
3505cdf0e10cSrcweir case VCLEVENT_WINDOW_LOSEFOCUS:
3506cdf0e10cSrcweir {
3507cdf0e10cSrcweir if ( ( _rWindow.IsCompoundControl()
3508cdf0e10cSrcweir && ( _nEventId == VCLEVENT_CONTROL_GETFOCUS
3509cdf0e10cSrcweir || _nEventId == VCLEVENT_CONTROL_LOSEFOCUS
3510cdf0e10cSrcweir )
3511cdf0e10cSrcweir )
3512cdf0e10cSrcweir || ( !_rWindow.IsCompoundControl()
3513cdf0e10cSrcweir && ( _nEventId == VCLEVENT_WINDOW_GETFOCUS
3514cdf0e10cSrcweir || _nEventId == VCLEVENT_WINDOW_LOSEFOCUS
3515cdf0e10cSrcweir )
3516cdf0e10cSrcweir )
3517cdf0e10cSrcweir )
3518cdf0e10cSrcweir {
3519cdf0e10cSrcweir if ( !m_aFocusListeners.getLength() )
3520cdf0e10cSrcweir break;
3521cdf0e10cSrcweir
3522cdf0e10cSrcweir bool bFocusGained = ( _nEventId == VCLEVENT_CONTROL_GETFOCUS ) || ( _nEventId == VCLEVENT_WINDOW_GETFOCUS );
3523cdf0e10cSrcweir
3524cdf0e10cSrcweir awt::FocusEvent aEvent;
3525cdf0e10cSrcweir aEvent.Source = *this;
3526cdf0e10cSrcweir aEvent.FocusFlags = _rWindow.GetGetFocusFlags();
3527cdf0e10cSrcweir aEvent.Temporary = sal_False;
3528cdf0e10cSrcweir
3529cdf0e10cSrcweir if ( bFocusGained )
3530cdf0e10cSrcweir onFocusGained( aEvent );
3531cdf0e10cSrcweir else
3532cdf0e10cSrcweir onFocusLost( aEvent );
3533cdf0e10cSrcweir }
3534cdf0e10cSrcweir }
3535cdf0e10cSrcweir break;
3536cdf0e10cSrcweir case VCLEVENT_WINDOW_MOUSEBUTTONDOWN:
3537cdf0e10cSrcweir case VCLEVENT_WINDOW_MOUSEBUTTONUP:
3538cdf0e10cSrcweir {
3539cdf0e10cSrcweir if ( !m_aMouseListeners.getLength() )
3540cdf0e10cSrcweir break;
3541cdf0e10cSrcweir
3542cdf0e10cSrcweir const bool bButtonDown = ( _nEventId == VCLEVENT_WINDOW_MOUSEBUTTONDOWN );
3543cdf0e10cSrcweir
3544cdf0e10cSrcweir awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( *static_cast< const ::MouseEvent* >( _pEventData ), *this ) );
3545cdf0e10cSrcweir m_aMouseListeners.notifyEach( bButtonDown ? &awt::XMouseListener::mousePressed : &awt::XMouseListener::mouseReleased, aEvent );
3546cdf0e10cSrcweir }
3547cdf0e10cSrcweir break;
3548cdf0e10cSrcweir case VCLEVENT_WINDOW_MOUSEMOVE:
3549cdf0e10cSrcweir {
3550cdf0e10cSrcweir const MouseEvent& rMouseEvent = *static_cast< const ::MouseEvent* >( _pEventData );
3551cdf0e10cSrcweir if ( rMouseEvent.IsEnterWindow() || rMouseEvent.IsLeaveWindow() )
3552cdf0e10cSrcweir {
3553cdf0e10cSrcweir if ( m_aMouseListeners.getLength() != 0 )
3554cdf0e10cSrcweir {
3555cdf0e10cSrcweir awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( rMouseEvent, *this ) );
3556cdf0e10cSrcweir m_aMouseListeners.notifyEach( rMouseEvent.IsEnterWindow() ? &awt::XMouseListener::mouseEntered: &awt::XMouseListener::mouseExited, aEvent );
3557cdf0e10cSrcweir }
3558cdf0e10cSrcweir }
3559cdf0e10cSrcweir else if ( !rMouseEvent.IsEnterWindow() && !rMouseEvent.IsLeaveWindow() )
3560cdf0e10cSrcweir {
3561cdf0e10cSrcweir if ( m_aMouseMotionListeners.getLength() != 0 )
3562cdf0e10cSrcweir {
3563cdf0e10cSrcweir awt::MouseEvent aEvent( VCLUnoHelper::createMouseEvent( rMouseEvent, *this ) );
3564cdf0e10cSrcweir aEvent.ClickCount = 0;
3565cdf0e10cSrcweir const bool bSimpleMove = ( ( rMouseEvent.GetMode() & MOUSE_SIMPLEMOVE ) != 0 );
3566cdf0e10cSrcweir m_aMouseMotionListeners.notifyEach( bSimpleMove ? &awt::XMouseMotionListener::mouseMoved: &awt::XMouseMotionListener::mouseDragged, aEvent );
3567cdf0e10cSrcweir }
3568cdf0e10cSrcweir }
3569cdf0e10cSrcweir }
3570cdf0e10cSrcweir break;
3571cdf0e10cSrcweir case VCLEVENT_WINDOW_KEYINPUT:
3572cdf0e10cSrcweir case VCLEVENT_WINDOW_KEYUP:
3573cdf0e10cSrcweir {
3574cdf0e10cSrcweir if ( !m_aKeyListeners.getLength() )
3575cdf0e10cSrcweir break;
3576cdf0e10cSrcweir
3577cdf0e10cSrcweir const bool bKeyPressed = ( _nEventId == VCLEVENT_WINDOW_KEYINPUT );
3578cdf0e10cSrcweir awt::KeyEvent aEvent( VCLUnoHelper::createKeyEvent( *static_cast< const ::KeyEvent* >( _pEventData ), *this ) );
3579cdf0e10cSrcweir m_aKeyListeners.notifyEach( bKeyPressed ? &awt::XKeyListener::keyPressed: &awt::XKeyListener::keyReleased, aEvent );
3580cdf0e10cSrcweir }
3581cdf0e10cSrcweir break;
3582cdf0e10cSrcweir }
3583cdf0e10cSrcweir }
3584cdf0e10cSrcweir
3585cdf0e10cSrcweir /*************************************************************************/
3586cdf0e10cSrcweir TYPEINIT1(FmXDataCell, FmXGridCell);
3587cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintFieldToCell(OutputDevice & rDev,const Rectangle & rRect,const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter)3588cdf0e10cSrcweir void FmXDataCell::PaintFieldToCell(OutputDevice& rDev, const Rectangle& rRect,
3589cdf0e10cSrcweir const Reference< ::com::sun::star::sdb::XColumn >& _rxField,
3590cdf0e10cSrcweir const Reference< XNumberFormatter >& xFormatter)
3591cdf0e10cSrcweir {
3592cdf0e10cSrcweir m_pCellControl->PaintFieldToCell( rDev, rRect, _rxField, xFormatter );
3593cdf0e10cSrcweir }
3594cdf0e10cSrcweir
3595cdf0e10cSrcweir //------------------------------------------------------------------------------
UpdateFromColumn()3596cdf0e10cSrcweir void FmXDataCell::UpdateFromColumn()
3597cdf0e10cSrcweir {
3598cdf0e10cSrcweir Reference< ::com::sun::star::sdb::XColumn > xField(m_pColumn->GetCurrentFieldValue());
3599cdf0e10cSrcweir if (xField.is())
3600cdf0e10cSrcweir m_pCellControl->UpdateFromField(xField, m_pColumn->GetParent().getNumberFormatter());
3601cdf0e10cSrcweir }
3602cdf0e10cSrcweir
3603cdf0e10cSrcweir /*************************************************************************/
3604cdf0e10cSrcweir TYPEINIT1(FmXTextCell, FmXDataCell);
3605cdf0e10cSrcweir
FmXTextCell(DbGridColumn * pColumn,DbCellControl & _rControl)3606cdf0e10cSrcweir FmXTextCell::FmXTextCell( DbGridColumn* pColumn, DbCellControl& _rControl )
3607cdf0e10cSrcweir :FmXDataCell( pColumn, _rControl )
3608cdf0e10cSrcweir ,m_bFastPaint( sal_True )
3609cdf0e10cSrcweir {
3610cdf0e10cSrcweir }
3611cdf0e10cSrcweir
3612cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintFieldToCell(OutputDevice & rDev,const Rectangle & rRect,const Reference<::com::sun::star::sdb::XColumn> & _rxField,const Reference<XNumberFormatter> & xFormatter)3613cdf0e10cSrcweir void FmXTextCell::PaintFieldToCell(OutputDevice& rDev,
3614cdf0e10cSrcweir const Rectangle& rRect,
3615cdf0e10cSrcweir const Reference< ::com::sun::star::sdb::XColumn >& _rxField,
3616cdf0e10cSrcweir const Reference< XNumberFormatter >& xFormatter)
3617cdf0e10cSrcweir {
3618cdf0e10cSrcweir if ( !m_bFastPaint )
3619cdf0e10cSrcweir {
3620cdf0e10cSrcweir FmXDataCell::PaintFieldToCell( rDev, rRect, _rxField, xFormatter );
3621cdf0e10cSrcweir return;
3622cdf0e10cSrcweir }
3623cdf0e10cSrcweir
3624cdf0e10cSrcweir sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER;
3625cdf0e10cSrcweir if ( ( rDev.GetOutDevType() == OUTDEV_WINDOW ) && !static_cast< Window& >( rDev ).IsEnabled() )
3626cdf0e10cSrcweir nStyle |= TEXT_DRAW_DISABLE;
3627cdf0e10cSrcweir
3628cdf0e10cSrcweir switch (m_pColumn->GetAlignment())
3629cdf0e10cSrcweir {
3630cdf0e10cSrcweir case ::com::sun::star::awt::TextAlign::RIGHT:
3631cdf0e10cSrcweir nStyle |= TEXT_DRAW_RIGHT;
3632cdf0e10cSrcweir break;
3633cdf0e10cSrcweir case ::com::sun::star::awt::TextAlign::CENTER:
3634cdf0e10cSrcweir nStyle |= TEXT_DRAW_CENTER;
3635cdf0e10cSrcweir break;
3636cdf0e10cSrcweir default:
3637cdf0e10cSrcweir nStyle |= TEXT_DRAW_LEFT;
3638cdf0e10cSrcweir }
3639cdf0e10cSrcweir
3640cdf0e10cSrcweir Color* pColor = NULL;
3641cdf0e10cSrcweir String aText = GetText(_rxField, xFormatter, &pColor);
3642cdf0e10cSrcweir if (pColor != NULL)
3643cdf0e10cSrcweir {
3644cdf0e10cSrcweir Color aOldTextColor( rDev.GetTextColor() );
3645cdf0e10cSrcweir rDev.SetTextColor( *pColor );
3646cdf0e10cSrcweir rDev.DrawText(rRect, aText, nStyle);
3647cdf0e10cSrcweir rDev.SetTextColor( aOldTextColor );
3648cdf0e10cSrcweir }
3649cdf0e10cSrcweir else
3650cdf0e10cSrcweir rDev.DrawText(rRect, aText, nStyle);
3651cdf0e10cSrcweir }
3652cdf0e10cSrcweir
3653cdf0e10cSrcweir
3654cdf0e10cSrcweir /*************************************************************************/
3655cdf0e10cSrcweir
3656cdf0e10cSrcweir DBG_NAME(FmXEditCell);
3657cdf0e10cSrcweir //------------------------------------------------------------------------------
FmXEditCell(DbGridColumn * pColumn,DbCellControl & _rControl)3658cdf0e10cSrcweir FmXEditCell::FmXEditCell( DbGridColumn* pColumn, DbCellControl& _rControl )
3659cdf0e10cSrcweir :FmXTextCell( pColumn, _rControl )
3660cdf0e10cSrcweir ,m_aTextListeners(m_aMutex)
3661cdf0e10cSrcweir ,m_aChangeListeners( m_aMutex )
3662cdf0e10cSrcweir ,m_pEditImplementation( NULL )
3663cdf0e10cSrcweir ,m_bOwnEditImplementation( false )
3664cdf0e10cSrcweir {
3665cdf0e10cSrcweir DBG_CTOR(FmXEditCell,NULL);
3666cdf0e10cSrcweir
3667cdf0e10cSrcweir DbTextField* pTextField = PTR_CAST( DbTextField, &_rControl );
3668cdf0e10cSrcweir if ( pTextField )
3669cdf0e10cSrcweir {
3670cdf0e10cSrcweir
3671cdf0e10cSrcweir m_pEditImplementation = pTextField->GetEditImplementation();
3672cdf0e10cSrcweir if ( !pTextField->IsSimpleEdit() )
3673cdf0e10cSrcweir m_bFastPaint = sal_False;
3674cdf0e10cSrcweir }
3675cdf0e10cSrcweir else
3676cdf0e10cSrcweir {
3677cdf0e10cSrcweir m_pEditImplementation = new EditImplementation( static_cast< Edit& >( _rControl.GetWindow() ) );
3678cdf0e10cSrcweir m_bOwnEditImplementation = true;
3679cdf0e10cSrcweir }
3680cdf0e10cSrcweir }
3681cdf0e10cSrcweir
3682cdf0e10cSrcweir //------------------------------------------------------------------
~FmXEditCell()3683cdf0e10cSrcweir FmXEditCell::~FmXEditCell()
3684cdf0e10cSrcweir {
3685cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed)
3686cdf0e10cSrcweir {
3687cdf0e10cSrcweir acquire();
3688cdf0e10cSrcweir dispose();
3689cdf0e10cSrcweir }
3690cdf0e10cSrcweir
3691cdf0e10cSrcweir
3692cdf0e10cSrcweir DBG_DTOR(FmXEditCell,NULL);
3693cdf0e10cSrcweir }
3694cdf0e10cSrcweir
3695cdf0e10cSrcweir // OComponentHelper
3696cdf0e10cSrcweir //-----------------------------------------------------------------------------
disposing()3697cdf0e10cSrcweir void FmXEditCell::disposing()
3698cdf0e10cSrcweir {
3699cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt(*this);
3700cdf0e10cSrcweir m_aTextListeners.disposeAndClear(aEvt);
3701cdf0e10cSrcweir m_aChangeListeners.disposeAndClear(aEvt);
3702cdf0e10cSrcweir
3703cdf0e10cSrcweir m_pEditImplementation->SetModifyHdl( Link() );
3704cdf0e10cSrcweir if ( m_bOwnEditImplementation )
3705cdf0e10cSrcweir delete m_pEditImplementation;
3706cdf0e10cSrcweir m_pEditImplementation = NULL;
3707cdf0e10cSrcweir
3708cdf0e10cSrcweir FmXDataCell::disposing();
3709cdf0e10cSrcweir }
3710cdf0e10cSrcweir
3711cdf0e10cSrcweir //------------------------------------------------------------------
queryAggregation(const::com::sun::star::uno::Type & _rType)3712cdf0e10cSrcweir Any SAL_CALL FmXEditCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
3713cdf0e10cSrcweir {
3714cdf0e10cSrcweir Any aReturn = FmXTextCell::queryAggregation( _rType );
3715cdf0e10cSrcweir
3716cdf0e10cSrcweir if ( !aReturn.hasValue() )
3717cdf0e10cSrcweir aReturn = FmXEditCell_Base::queryInterface( _rType );
3718cdf0e10cSrcweir
3719cdf0e10cSrcweir return aReturn;
3720cdf0e10cSrcweir }
3721cdf0e10cSrcweir
3722cdf0e10cSrcweir //-------------------------------------------------------------------------
getTypes()3723cdf0e10cSrcweir Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXEditCell::getTypes( ) throw(RuntimeException)
3724cdf0e10cSrcweir {
3725cdf0e10cSrcweir return ::comphelper::concatSequences(
3726cdf0e10cSrcweir FmXTextCell::getTypes(),
3727cdf0e10cSrcweir FmXEditCell_Base::getTypes()
3728cdf0e10cSrcweir );
3729cdf0e10cSrcweir }
3730cdf0e10cSrcweir
3731cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_GET_IMPLEMENTATION_ID(FmXEditCell)3732cdf0e10cSrcweir IMPLEMENT_GET_IMPLEMENTATION_ID( FmXEditCell )
3733cdf0e10cSrcweir
3734cdf0e10cSrcweir // ::com::sun::star::awt::XTextComponent
3735cdf0e10cSrcweir //------------------------------------------------------------------------------
3736cdf0e10cSrcweir void SAL_CALL FmXEditCell::addTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException )
3737cdf0e10cSrcweir {
3738cdf0e10cSrcweir m_aTextListeners.addInterface( l );
3739cdf0e10cSrcweir }
3740cdf0e10cSrcweir
3741cdf0e10cSrcweir //------------------------------------------------------------------------------
removeTextListener(const Reference<::com::sun::star::awt::XTextListener> & l)3742cdf0e10cSrcweir void SAL_CALL FmXEditCell::removeTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException )
3743cdf0e10cSrcweir {
3744cdf0e10cSrcweir m_aTextListeners.removeInterface( l );
3745cdf0e10cSrcweir }
3746cdf0e10cSrcweir
3747cdf0e10cSrcweir //------------------------------------------------------------------------------
setText(const::rtl::OUString & aText)3748cdf0e10cSrcweir void SAL_CALL FmXEditCell::setText( const ::rtl::OUString& aText ) throw( RuntimeException )
3749cdf0e10cSrcweir {
3750cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3751cdf0e10cSrcweir
3752cdf0e10cSrcweir if ( m_pEditImplementation )
3753cdf0e10cSrcweir {
3754cdf0e10cSrcweir m_pEditImplementation->SetText( aText );
3755cdf0e10cSrcweir
3756cdf0e10cSrcweir // In JAVA wird auch ein textChanged ausgeloest, in VCL nicht.
3757cdf0e10cSrcweir // ::com::sun::star::awt::Toolkit soll JAVA-komform sein...
3758cdf0e10cSrcweir onTextChanged();
3759cdf0e10cSrcweir }
3760cdf0e10cSrcweir }
3761cdf0e10cSrcweir
3762cdf0e10cSrcweir //------------------------------------------------------------------------------
insertText(const::com::sun::star::awt::Selection & rSel,const::rtl::OUString & aText)3763cdf0e10cSrcweir void SAL_CALL FmXEditCell::insertText(const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText) throw(RuntimeException)
3764cdf0e10cSrcweir {
3765cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3766cdf0e10cSrcweir
3767cdf0e10cSrcweir if ( m_pEditImplementation )
3768cdf0e10cSrcweir {
3769cdf0e10cSrcweir m_pEditImplementation->SetSelection( Selection( rSel.Min, rSel.Max ) );
3770cdf0e10cSrcweir m_pEditImplementation->ReplaceSelected( aText );
3771cdf0e10cSrcweir }
3772cdf0e10cSrcweir }
3773cdf0e10cSrcweir
3774cdf0e10cSrcweir //------------------------------------------------------------------------------
getText()3775cdf0e10cSrcweir ::rtl::OUString SAL_CALL FmXEditCell::getText() throw( RuntimeException )
3776cdf0e10cSrcweir {
3777cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3778cdf0e10cSrcweir
3779cdf0e10cSrcweir ::rtl::OUString aText;
3780cdf0e10cSrcweir if ( m_pEditImplementation )
3781cdf0e10cSrcweir {
3782cdf0e10cSrcweir if ( m_pEditImplementation->GetControl().IsVisible() && m_pColumn->GetParent().getDisplaySynchron())
3783cdf0e10cSrcweir {
3784cdf0e10cSrcweir // if the display isn't sync with the cursor we can't ask the edit field
3785cdf0e10cSrcweir LineEnd eLineEndFormat = m_pColumn ? getModelLineEndSetting( m_pColumn->getModel() ) : LINEEND_LF;
3786cdf0e10cSrcweir aText = m_pEditImplementation->GetText( eLineEndFormat );
3787cdf0e10cSrcweir }
3788cdf0e10cSrcweir else
3789cdf0e10cSrcweir {
3790cdf0e10cSrcweir Reference< ::com::sun::star::sdb::XColumn > xField(m_pColumn->GetCurrentFieldValue());
3791cdf0e10cSrcweir if (xField.is())
3792cdf0e10cSrcweir aText = GetText(xField, m_pColumn->GetParent().getNumberFormatter());
3793cdf0e10cSrcweir }
3794cdf0e10cSrcweir }
3795cdf0e10cSrcweir return aText;
3796cdf0e10cSrcweir }
3797cdf0e10cSrcweir
3798cdf0e10cSrcweir //------------------------------------------------------------------------------
getSelectedText(void)3799cdf0e10cSrcweir ::rtl::OUString SAL_CALL FmXEditCell::getSelectedText( void ) throw( RuntimeException )
3800cdf0e10cSrcweir {
3801cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3802cdf0e10cSrcweir
3803cdf0e10cSrcweir ::rtl::OUString aText;
3804cdf0e10cSrcweir if ( m_pEditImplementation )
3805cdf0e10cSrcweir {
3806cdf0e10cSrcweir LineEnd eLineEndFormat = m_pColumn ? getModelLineEndSetting( m_pColumn->getModel() ) : LINEEND_LF;
3807cdf0e10cSrcweir aText = m_pEditImplementation->GetSelected( eLineEndFormat );
3808cdf0e10cSrcweir }
3809cdf0e10cSrcweir return aText;
3810cdf0e10cSrcweir }
3811cdf0e10cSrcweir
3812cdf0e10cSrcweir //------------------------------------------------------------------------------
setSelection(const::com::sun::star::awt::Selection & aSelection)3813cdf0e10cSrcweir void SAL_CALL FmXEditCell::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw( RuntimeException )
3814cdf0e10cSrcweir {
3815cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3816cdf0e10cSrcweir
3817cdf0e10cSrcweir if ( m_pEditImplementation )
3818cdf0e10cSrcweir m_pEditImplementation->SetSelection( Selection( aSelection.Min, aSelection.Max ) );
3819cdf0e10cSrcweir }
3820cdf0e10cSrcweir
3821cdf0e10cSrcweir //------------------------------------------------------------------------------
getSelection(void)3822cdf0e10cSrcweir ::com::sun::star::awt::Selection SAL_CALL FmXEditCell::getSelection( void ) throw( RuntimeException )
3823cdf0e10cSrcweir {
3824cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3825cdf0e10cSrcweir
3826cdf0e10cSrcweir Selection aSel;
3827cdf0e10cSrcweir if ( m_pEditImplementation )
3828cdf0e10cSrcweir aSel = m_pEditImplementation->GetSelection();
3829cdf0e10cSrcweir
3830cdf0e10cSrcweir return ::com::sun::star::awt::Selection(aSel.Min(), aSel.Max());
3831cdf0e10cSrcweir }
3832cdf0e10cSrcweir
3833cdf0e10cSrcweir //------------------------------------------------------------------------------
isEditable(void)3834cdf0e10cSrcweir sal_Bool SAL_CALL FmXEditCell::isEditable( void ) throw( RuntimeException )
3835cdf0e10cSrcweir {
3836cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3837cdf0e10cSrcweir
3838cdf0e10cSrcweir return ( m_pEditImplementation && !m_pEditImplementation->IsReadOnly() && m_pEditImplementation->GetControl().IsEnabled() ) ? sal_True : sal_False;
3839cdf0e10cSrcweir }
3840cdf0e10cSrcweir
3841cdf0e10cSrcweir //------------------------------------------------------------------------------
setEditable(sal_Bool bEditable)3842cdf0e10cSrcweir void SAL_CALL FmXEditCell::setEditable( sal_Bool bEditable ) throw( RuntimeException )
3843cdf0e10cSrcweir {
3844cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3845cdf0e10cSrcweir
3846cdf0e10cSrcweir if ( m_pEditImplementation )
3847cdf0e10cSrcweir m_pEditImplementation->SetReadOnly( !bEditable );
3848cdf0e10cSrcweir }
3849cdf0e10cSrcweir
3850cdf0e10cSrcweir //------------------------------------------------------------------------------
getMaxTextLen()3851cdf0e10cSrcweir sal_Int16 SAL_CALL FmXEditCell::getMaxTextLen() throw( RuntimeException )
3852cdf0e10cSrcweir {
3853cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3854cdf0e10cSrcweir
3855cdf0e10cSrcweir return m_pEditImplementation ? m_pEditImplementation->GetMaxTextLen() : 0;
3856cdf0e10cSrcweir }
3857cdf0e10cSrcweir
3858cdf0e10cSrcweir //------------------------------------------------------------------------------
setMaxTextLen(sal_Int16 nLen)3859cdf0e10cSrcweir void SAL_CALL FmXEditCell::setMaxTextLen( sal_Int16 nLen ) throw( RuntimeException )
3860cdf0e10cSrcweir {
3861cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3862cdf0e10cSrcweir
3863cdf0e10cSrcweir if ( m_pEditImplementation )
3864cdf0e10cSrcweir m_pEditImplementation->SetMaxTextLen( nLen );
3865cdf0e10cSrcweir }
3866cdf0e10cSrcweir
3867cdf0e10cSrcweir //------------------------------------------------------------------------------
addChangeListener(const Reference<form::XChangeListener> & _Listener)3868cdf0e10cSrcweir void SAL_CALL FmXEditCell::addChangeListener( const Reference< form::XChangeListener >& _Listener ) throw (RuntimeException)
3869cdf0e10cSrcweir {
3870cdf0e10cSrcweir m_aChangeListeners.addInterface( _Listener );
3871cdf0e10cSrcweir }
3872cdf0e10cSrcweir
3873cdf0e10cSrcweir //------------------------------------------------------------------------------
removeChangeListener(const Reference<form::XChangeListener> & _Listener)3874cdf0e10cSrcweir void SAL_CALL FmXEditCell::removeChangeListener( const Reference< form::XChangeListener >& _Listener ) throw (RuntimeException)
3875cdf0e10cSrcweir {
3876cdf0e10cSrcweir m_aChangeListeners.removeInterface( _Listener );
3877cdf0e10cSrcweir }
3878cdf0e10cSrcweir
3879cdf0e10cSrcweir //------------------------------------------------------------------------------
onTextChanged()3880cdf0e10cSrcweir void FmXEditCell::onTextChanged()
3881cdf0e10cSrcweir {
3882cdf0e10cSrcweir ::com::sun::star::awt::TextEvent aEvent;
3883cdf0e10cSrcweir aEvent.Source = *this;
3884cdf0e10cSrcweir m_aTextListeners.notifyEach( &awt::XTextListener::textChanged, aEvent );
3885cdf0e10cSrcweir }
3886cdf0e10cSrcweir
3887cdf0e10cSrcweir //------------------------------------------------------------------------------
onFocusGained(const awt::FocusEvent & _rEvent)3888cdf0e10cSrcweir void FmXEditCell::onFocusGained( const awt::FocusEvent& _rEvent )
3889cdf0e10cSrcweir {
3890cdf0e10cSrcweir FmXTextCell::onFocusGained( _rEvent );
3891cdf0e10cSrcweir m_sValueOnEnter = getText();
3892cdf0e10cSrcweir }
3893cdf0e10cSrcweir
3894cdf0e10cSrcweir //------------------------------------------------------------------------------
onFocusLost(const awt::FocusEvent & _rEvent)3895cdf0e10cSrcweir void FmXEditCell::onFocusLost( const awt::FocusEvent& _rEvent )
3896cdf0e10cSrcweir {
3897cdf0e10cSrcweir FmXTextCell::onFocusLost( _rEvent );
3898cdf0e10cSrcweir
3899cdf0e10cSrcweir if ( getText() != m_sValueOnEnter )
3900cdf0e10cSrcweir {
3901cdf0e10cSrcweir lang::EventObject aEvent( *this );
3902cdf0e10cSrcweir m_aChangeListeners.notifyEach( &XChangeListener::changed, aEvent );
3903cdf0e10cSrcweir }
3904cdf0e10cSrcweir }
3905cdf0e10cSrcweir
3906cdf0e10cSrcweir //------------------------------------------------------------------------------
onWindowEvent(const sal_uIntPtr _nEventId,const Window & _rWindow,const void * _pEventData)3907cdf0e10cSrcweir void FmXEditCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData )
3908cdf0e10cSrcweir {
3909cdf0e10cSrcweir switch ( _nEventId )
3910cdf0e10cSrcweir {
3911cdf0e10cSrcweir case VCLEVENT_EDIT_MODIFY:
3912cdf0e10cSrcweir {
3913cdf0e10cSrcweir if ( m_pEditImplementation && m_aTextListeners.getLength() )
3914cdf0e10cSrcweir onTextChanged();
3915cdf0e10cSrcweir return;
3916cdf0e10cSrcweir }
3917cdf0e10cSrcweir }
3918cdf0e10cSrcweir
3919cdf0e10cSrcweir FmXTextCell::onWindowEvent( _nEventId, _rWindow, _pEventData );
3920cdf0e10cSrcweir }
3921cdf0e10cSrcweir
3922cdf0e10cSrcweir /*************************************************************************/
3923cdf0e10cSrcweir DBG_NAME(FmXCheckBoxCell);
3924cdf0e10cSrcweir //------------------------------------------------------------------------------
FmXCheckBoxCell(DbGridColumn * pColumn,DbCellControl & _rControl)3925cdf0e10cSrcweir FmXCheckBoxCell::FmXCheckBoxCell( DbGridColumn* pColumn, DbCellControl& _rControl )
3926cdf0e10cSrcweir :FmXDataCell( pColumn, _rControl )
3927cdf0e10cSrcweir ,m_aItemListeners(m_aMutex)
3928cdf0e10cSrcweir ,m_aActionListeners( m_aMutex )
3929cdf0e10cSrcweir ,m_pBox( & static_cast< CheckBoxControl& >( _rControl.GetWindow() ).GetBox() )
3930cdf0e10cSrcweir {
3931cdf0e10cSrcweir DBG_CTOR(FmXCheckBoxCell,NULL);
3932cdf0e10cSrcweir }
3933cdf0e10cSrcweir
3934cdf0e10cSrcweir //------------------------------------------------------------------
~FmXCheckBoxCell()3935cdf0e10cSrcweir FmXCheckBoxCell::~FmXCheckBoxCell()
3936cdf0e10cSrcweir {
3937cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed)
3938cdf0e10cSrcweir {
3939cdf0e10cSrcweir acquire();
3940cdf0e10cSrcweir dispose();
3941cdf0e10cSrcweir }
3942cdf0e10cSrcweir
3943cdf0e10cSrcweir DBG_DTOR(FmXCheckBoxCell,NULL);
3944cdf0e10cSrcweir }
3945cdf0e10cSrcweir
3946cdf0e10cSrcweir // OComponentHelper
3947cdf0e10cSrcweir //-----------------------------------------------------------------------------
disposing()3948cdf0e10cSrcweir void FmXCheckBoxCell::disposing()
3949cdf0e10cSrcweir {
3950cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt(*this);
3951cdf0e10cSrcweir m_aItemListeners.disposeAndClear(aEvt);
3952cdf0e10cSrcweir m_aActionListeners.disposeAndClear(aEvt);
3953cdf0e10cSrcweir
3954cdf0e10cSrcweir static_cast< CheckBoxControl& >( m_pCellControl->GetWindow() ).SetClickHdl(Link());
3955cdf0e10cSrcweir m_pBox = NULL;
3956cdf0e10cSrcweir
3957cdf0e10cSrcweir FmXDataCell::disposing();
3958cdf0e10cSrcweir }
3959cdf0e10cSrcweir
3960cdf0e10cSrcweir //------------------------------------------------------------------
queryAggregation(const::com::sun::star::uno::Type & _rType)3961cdf0e10cSrcweir Any SAL_CALL FmXCheckBoxCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
3962cdf0e10cSrcweir {
3963cdf0e10cSrcweir Any aReturn = FmXDataCell::queryAggregation( _rType );
3964cdf0e10cSrcweir
3965cdf0e10cSrcweir if ( !aReturn.hasValue() )
3966cdf0e10cSrcweir aReturn = FmXCheckBoxCell_Base::queryInterface( _rType );
3967cdf0e10cSrcweir
3968cdf0e10cSrcweir return aReturn;
3969cdf0e10cSrcweir }
3970cdf0e10cSrcweir
3971cdf0e10cSrcweir //-------------------------------------------------------------------------
getTypes()3972cdf0e10cSrcweir Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXCheckBoxCell::getTypes( ) throw(RuntimeException)
3973cdf0e10cSrcweir {
3974cdf0e10cSrcweir return ::comphelper::concatSequences(
3975cdf0e10cSrcweir FmXDataCell::getTypes(),
3976cdf0e10cSrcweir FmXCheckBoxCell_Base::getTypes()
3977cdf0e10cSrcweir );
3978cdf0e10cSrcweir }
3979cdf0e10cSrcweir
3980cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_GET_IMPLEMENTATION_ID(FmXCheckBoxCell)3981cdf0e10cSrcweir IMPLEMENT_GET_IMPLEMENTATION_ID( FmXCheckBoxCell )
3982cdf0e10cSrcweir
3983cdf0e10cSrcweir //------------------------------------------------------------------
3984cdf0e10cSrcweir void SAL_CALL FmXCheckBoxCell::addItemListener( const Reference< ::com::sun::star::awt::XItemListener >& l ) throw( RuntimeException )
3985cdf0e10cSrcweir {
3986cdf0e10cSrcweir m_aItemListeners.addInterface( l );
3987cdf0e10cSrcweir }
3988cdf0e10cSrcweir
3989cdf0e10cSrcweir //------------------------------------------------------------------
removeItemListener(const Reference<::com::sun::star::awt::XItemListener> & l)3990cdf0e10cSrcweir void SAL_CALL FmXCheckBoxCell::removeItemListener( const Reference< ::com::sun::star::awt::XItemListener >& l ) throw( RuntimeException )
3991cdf0e10cSrcweir {
3992cdf0e10cSrcweir m_aItemListeners.removeInterface( l );
3993cdf0e10cSrcweir }
3994cdf0e10cSrcweir
3995cdf0e10cSrcweir //------------------------------------------------------------------
setState(short n)3996cdf0e10cSrcweir void SAL_CALL FmXCheckBoxCell::setState( short n ) throw( RuntimeException )
3997cdf0e10cSrcweir {
3998cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
3999cdf0e10cSrcweir
4000cdf0e10cSrcweir if (m_pBox)
4001cdf0e10cSrcweir {
4002cdf0e10cSrcweir UpdateFromColumn();
4003cdf0e10cSrcweir m_pBox->SetState( (TriState)n );
4004cdf0e10cSrcweir }
4005cdf0e10cSrcweir }
4006cdf0e10cSrcweir
4007cdf0e10cSrcweir //------------------------------------------------------------------
getState()4008cdf0e10cSrcweir short SAL_CALL FmXCheckBoxCell::getState() throw( RuntimeException )
4009cdf0e10cSrcweir {
4010cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4011cdf0e10cSrcweir
4012cdf0e10cSrcweir if (m_pBox)
4013cdf0e10cSrcweir {
4014cdf0e10cSrcweir UpdateFromColumn();
4015cdf0e10cSrcweir return (short)m_pBox->GetState();
4016cdf0e10cSrcweir }
4017cdf0e10cSrcweir return STATE_DONTKNOW;
4018cdf0e10cSrcweir }
4019cdf0e10cSrcweir
4020cdf0e10cSrcweir //------------------------------------------------------------------
enableTriState(sal_Bool b)4021cdf0e10cSrcweir void SAL_CALL FmXCheckBoxCell::enableTriState( sal_Bool b ) throw( RuntimeException )
4022cdf0e10cSrcweir {
4023cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4024cdf0e10cSrcweir
4025cdf0e10cSrcweir if (m_pBox)
4026cdf0e10cSrcweir m_pBox->EnableTriState( b );
4027cdf0e10cSrcweir }
4028cdf0e10cSrcweir
4029cdf0e10cSrcweir //------------------------------------------------------------------
addActionListener(const Reference<awt::XActionListener> & _Listener)4030cdf0e10cSrcweir void SAL_CALL FmXCheckBoxCell::addActionListener( const Reference< awt::XActionListener >& _Listener ) throw (RuntimeException)
4031cdf0e10cSrcweir {
4032cdf0e10cSrcweir m_aActionListeners.addInterface( _Listener );
4033cdf0e10cSrcweir }
4034cdf0e10cSrcweir
4035cdf0e10cSrcweir //------------------------------------------------------------------
removeActionListener(const Reference<awt::XActionListener> & _Listener)4036cdf0e10cSrcweir void SAL_CALL FmXCheckBoxCell::removeActionListener( const Reference< awt::XActionListener >& _Listener ) throw (RuntimeException)
4037cdf0e10cSrcweir {
4038cdf0e10cSrcweir m_aActionListeners.removeInterface( _Listener );
4039cdf0e10cSrcweir }
4040cdf0e10cSrcweir
4041cdf0e10cSrcweir //------------------------------------------------------------------
setLabel(const::rtl::OUString & _Label)4042cdf0e10cSrcweir void SAL_CALL FmXCheckBoxCell::setLabel( const ::rtl::OUString& _Label ) throw (RuntimeException)
4043cdf0e10cSrcweir {
4044cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() );
4045cdf0e10cSrcweir if ( m_pColumn )
4046cdf0e10cSrcweir {
4047cdf0e10cSrcweir DbGridControl& rGrid( m_pColumn->GetParent() );
4048cdf0e10cSrcweir rGrid.SetColumnTitle( rGrid.GetColumnId( m_pColumn->GetFieldPos() ), _Label );
4049cdf0e10cSrcweir }
4050cdf0e10cSrcweir }
4051cdf0e10cSrcweir
4052cdf0e10cSrcweir //------------------------------------------------------------------
setActionCommand(const::rtl::OUString & _Command)4053cdf0e10cSrcweir void SAL_CALL FmXCheckBoxCell::setActionCommand( const ::rtl::OUString& _Command ) throw (RuntimeException)
4054cdf0e10cSrcweir {
4055cdf0e10cSrcweir m_aActionCommand = _Command;
4056cdf0e10cSrcweir }
4057cdf0e10cSrcweir
4058cdf0e10cSrcweir //------------------------------------------------------------------
getEventWindow() const4059cdf0e10cSrcweir Window* FmXCheckBoxCell::getEventWindow() const
4060cdf0e10cSrcweir {
4061cdf0e10cSrcweir return m_pBox;
4062cdf0e10cSrcweir }
4063cdf0e10cSrcweir
4064cdf0e10cSrcweir //------------------------------------------------------------------
onWindowEvent(const sal_uIntPtr _nEventId,const Window & _rWindow,const void * _pEventData)4065cdf0e10cSrcweir void FmXCheckBoxCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData )
4066cdf0e10cSrcweir {
4067cdf0e10cSrcweir switch ( _nEventId )
4068cdf0e10cSrcweir {
4069cdf0e10cSrcweir case VCLEVENT_CHECKBOX_TOGGLE:
4070cdf0e10cSrcweir {
4071cdf0e10cSrcweir // check boxes are to be committed immediately (this holds for ordinary check box controls in
4072cdf0e10cSrcweir // documents, and this must hold for check boxes in grid columns, too
4073cdf0e10cSrcweir // 91210 - 22.08.2001 - frank.schoenheit@sun.com
4074cdf0e10cSrcweir m_pCellControl->Commit();
4075cdf0e10cSrcweir
4076cdf0e10cSrcweir Reference< XWindow > xKeepAlive( this );
4077cdf0e10cSrcweir if ( m_aItemListeners.getLength() && m_pBox )
4078cdf0e10cSrcweir {
4079cdf0e10cSrcweir awt::ItemEvent aEvent;
4080cdf0e10cSrcweir aEvent.Source = *this;
4081cdf0e10cSrcweir aEvent.Highlighted = sal_False;
4082cdf0e10cSrcweir aEvent.Selected = m_pBox->GetState();
4083cdf0e10cSrcweir m_aItemListeners.notifyEach( &awt::XItemListener::itemStateChanged, aEvent );
4084cdf0e10cSrcweir }
4085cdf0e10cSrcweir if ( m_aActionListeners.getLength() )
4086cdf0e10cSrcweir {
4087cdf0e10cSrcweir awt::ActionEvent aEvent;
4088cdf0e10cSrcweir aEvent.Source = *this;
4089cdf0e10cSrcweir aEvent.ActionCommand = m_aActionCommand;
4090cdf0e10cSrcweir m_aActionListeners.notifyEach( &awt::XActionListener::actionPerformed, aEvent );
4091cdf0e10cSrcweir }
4092cdf0e10cSrcweir }
4093cdf0e10cSrcweir break;
4094cdf0e10cSrcweir
4095cdf0e10cSrcweir default:
4096cdf0e10cSrcweir FmXDataCell::onWindowEvent( _nEventId, _rWindow, _pEventData );
4097cdf0e10cSrcweir break;
4098cdf0e10cSrcweir }
4099cdf0e10cSrcweir }
4100cdf0e10cSrcweir
4101cdf0e10cSrcweir /*************************************************************************/
4102cdf0e10cSrcweir
4103cdf0e10cSrcweir DBG_NAME(FmXListBoxCell);
4104cdf0e10cSrcweir //------------------------------------------------------------------------------
FmXListBoxCell(DbGridColumn * pColumn,DbCellControl & _rControl)4105cdf0e10cSrcweir FmXListBoxCell::FmXListBoxCell(DbGridColumn* pColumn, DbCellControl& _rControl)
4106cdf0e10cSrcweir :FmXTextCell( pColumn, _rControl )
4107cdf0e10cSrcweir ,m_aItemListeners(m_aMutex)
4108cdf0e10cSrcweir ,m_aActionListeners(m_aMutex)
4109cdf0e10cSrcweir ,m_pBox( &static_cast< ListBox& >( _rControl.GetWindow() ) )
4110cdf0e10cSrcweir {
4111cdf0e10cSrcweir DBG_CTOR(FmXListBoxCell,NULL);
4112cdf0e10cSrcweir
4113cdf0e10cSrcweir m_pBox->SetDoubleClickHdl( LINK( this, FmXListBoxCell, OnDoubleClick ) );
4114cdf0e10cSrcweir }
4115cdf0e10cSrcweir
4116cdf0e10cSrcweir //------------------------------------------------------------------
~FmXListBoxCell()4117cdf0e10cSrcweir FmXListBoxCell::~FmXListBoxCell()
4118cdf0e10cSrcweir {
4119cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed)
4120cdf0e10cSrcweir {
4121cdf0e10cSrcweir acquire();
4122cdf0e10cSrcweir dispose();
4123cdf0e10cSrcweir }
4124cdf0e10cSrcweir
4125cdf0e10cSrcweir DBG_DTOR(FmXListBoxCell,NULL);
4126cdf0e10cSrcweir }
4127cdf0e10cSrcweir
4128cdf0e10cSrcweir // OComponentHelper
4129cdf0e10cSrcweir //-----------------------------------------------------------------------------
disposing()4130cdf0e10cSrcweir void FmXListBoxCell::disposing()
4131cdf0e10cSrcweir {
4132cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt(*this);
4133cdf0e10cSrcweir m_aItemListeners.disposeAndClear(aEvt);
4134cdf0e10cSrcweir m_aActionListeners.disposeAndClear(aEvt);
4135cdf0e10cSrcweir
4136cdf0e10cSrcweir m_pBox->SetSelectHdl( Link() );
4137cdf0e10cSrcweir m_pBox->SetDoubleClickHdl( Link() );
4138cdf0e10cSrcweir m_pBox = NULL;
4139cdf0e10cSrcweir
4140cdf0e10cSrcweir FmXTextCell::disposing();
4141cdf0e10cSrcweir }
4142cdf0e10cSrcweir
4143cdf0e10cSrcweir //------------------------------------------------------------------
queryAggregation(const::com::sun::star::uno::Type & _rType)4144cdf0e10cSrcweir Any SAL_CALL FmXListBoxCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
4145cdf0e10cSrcweir {
4146cdf0e10cSrcweir Any aReturn = FmXTextCell::queryAggregation(_rType);
4147cdf0e10cSrcweir
4148cdf0e10cSrcweir if ( !aReturn.hasValue() )
4149cdf0e10cSrcweir aReturn = FmXListBoxCell_Base::queryInterface( _rType );
4150cdf0e10cSrcweir
4151cdf0e10cSrcweir return aReturn;
4152cdf0e10cSrcweir }
4153cdf0e10cSrcweir
4154cdf0e10cSrcweir //-------------------------------------------------------------------------
getTypes()4155cdf0e10cSrcweir Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXListBoxCell::getTypes( ) throw(RuntimeException)
4156cdf0e10cSrcweir {
4157cdf0e10cSrcweir return ::comphelper::concatSequences(
4158cdf0e10cSrcweir FmXTextCell::getTypes(),
4159cdf0e10cSrcweir FmXListBoxCell_Base::getTypes()
4160cdf0e10cSrcweir );
4161cdf0e10cSrcweir }
4162cdf0e10cSrcweir
4163cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_GET_IMPLEMENTATION_ID(FmXListBoxCell)4164cdf0e10cSrcweir IMPLEMENT_GET_IMPLEMENTATION_ID( FmXListBoxCell )
4165cdf0e10cSrcweir
4166cdf0e10cSrcweir //------------------------------------------------------------------
4167cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::addItemListener(const Reference< ::com::sun::star::awt::XItemListener >& l) throw( RuntimeException )
4168cdf0e10cSrcweir {
4169cdf0e10cSrcweir m_aItemListeners.addInterface( l );
4170cdf0e10cSrcweir }
4171cdf0e10cSrcweir
4172cdf0e10cSrcweir //------------------------------------------------------------------
removeItemListener(const Reference<::com::sun::star::awt::XItemListener> & l)4173cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::removeItemListener(const Reference< ::com::sun::star::awt::XItemListener >& l) throw( RuntimeException )
4174cdf0e10cSrcweir {
4175cdf0e10cSrcweir m_aItemListeners.removeInterface( l );
4176cdf0e10cSrcweir }
4177cdf0e10cSrcweir
4178cdf0e10cSrcweir //------------------------------------------------------------------
addActionListener(const Reference<::com::sun::star::awt::XActionListener> & l)4179cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::addActionListener(const Reference< ::com::sun::star::awt::XActionListener >& l) throw( RuntimeException )
4180cdf0e10cSrcweir {
4181cdf0e10cSrcweir m_aActionListeners.addInterface( l );
4182cdf0e10cSrcweir }
4183cdf0e10cSrcweir
4184cdf0e10cSrcweir //------------------------------------------------------------------
removeActionListener(const Reference<::com::sun::star::awt::XActionListener> & l)4185cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::removeActionListener(const Reference< ::com::sun::star::awt::XActionListener >& l) throw( RuntimeException )
4186cdf0e10cSrcweir {
4187cdf0e10cSrcweir m_aActionListeners.removeInterface( l );
4188cdf0e10cSrcweir }
4189cdf0e10cSrcweir
4190cdf0e10cSrcweir //------------------------------------------------------------------
addItem(const::rtl::OUString & aItem,sal_Int16 nPos)4191cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::addItem(const ::rtl::OUString& aItem, sal_Int16 nPos) throw( RuntimeException )
4192cdf0e10cSrcweir {
4193cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4194cdf0e10cSrcweir if (m_pBox)
4195cdf0e10cSrcweir m_pBox->InsertEntry( aItem, nPos );
4196cdf0e10cSrcweir }
4197cdf0e10cSrcweir
4198cdf0e10cSrcweir //------------------------------------------------------------------
addItems(const::comphelper::StringSequence & aItems,sal_Int16 nPos)4199cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::addItems(const ::comphelper::StringSequence& aItems, sal_Int16 nPos) throw( RuntimeException )
4200cdf0e10cSrcweir {
4201cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4202cdf0e10cSrcweir if (m_pBox)
4203cdf0e10cSrcweir {
4204cdf0e10cSrcweir sal_uInt16 nP = nPos;
4205cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < aItems.getLength(); n++ )
4206cdf0e10cSrcweir {
4207cdf0e10cSrcweir m_pBox->InsertEntry( aItems.getConstArray()[n], nP );
4208cdf0e10cSrcweir if ( nPos != -1 ) // Nicht wenn 0xFFFF, weil LIST_APPEND
4209cdf0e10cSrcweir nP++;
4210cdf0e10cSrcweir }
4211cdf0e10cSrcweir }
4212cdf0e10cSrcweir }
4213cdf0e10cSrcweir
4214cdf0e10cSrcweir //------------------------------------------------------------------
removeItems(sal_Int16 nPos,sal_Int16 nCount)4215cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::removeItems(sal_Int16 nPos, sal_Int16 nCount) throw( RuntimeException )
4216cdf0e10cSrcweir {
4217cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4218cdf0e10cSrcweir if ( m_pBox )
4219cdf0e10cSrcweir {
4220cdf0e10cSrcweir for ( sal_uInt16 n = nCount; n; )
4221cdf0e10cSrcweir m_pBox->RemoveEntry( nPos + (--n) );
4222cdf0e10cSrcweir }
4223cdf0e10cSrcweir }
4224cdf0e10cSrcweir
4225cdf0e10cSrcweir //------------------------------------------------------------------
getItemCount()4226cdf0e10cSrcweir sal_Int16 SAL_CALL FmXListBoxCell::getItemCount() throw( RuntimeException )
4227cdf0e10cSrcweir {
4228cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4229cdf0e10cSrcweir return m_pBox ? m_pBox->GetEntryCount() : 0;
4230cdf0e10cSrcweir }
4231cdf0e10cSrcweir
4232cdf0e10cSrcweir //------------------------------------------------------------------
getItem(sal_Int16 nPos)4233cdf0e10cSrcweir ::rtl::OUString SAL_CALL FmXListBoxCell::getItem(sal_Int16 nPos) throw( RuntimeException )
4234cdf0e10cSrcweir {
4235cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4236cdf0e10cSrcweir String aItem;
4237cdf0e10cSrcweir if (m_pBox)
4238cdf0e10cSrcweir aItem = m_pBox->GetEntry( nPos );
4239cdf0e10cSrcweir return aItem;
4240cdf0e10cSrcweir }
4241cdf0e10cSrcweir //------------------------------------------------------------------
getItems()4242cdf0e10cSrcweir ::comphelper::StringSequence SAL_CALL FmXListBoxCell::getItems() throw( RuntimeException )
4243cdf0e10cSrcweir {
4244cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4245cdf0e10cSrcweir
4246cdf0e10cSrcweir ::comphelper::StringSequence aSeq;
4247cdf0e10cSrcweir if (m_pBox)
4248cdf0e10cSrcweir {
4249cdf0e10cSrcweir sal_uInt16 nEntries = m_pBox ->GetEntryCount();
4250cdf0e10cSrcweir aSeq = ::comphelper::StringSequence( nEntries );
4251cdf0e10cSrcweir for ( sal_uInt16 n = nEntries; n; )
4252cdf0e10cSrcweir {
4253cdf0e10cSrcweir --n;
4254cdf0e10cSrcweir aSeq.getArray()[n] = m_pBox ->GetEntry( n );
4255cdf0e10cSrcweir }
4256cdf0e10cSrcweir }
4257cdf0e10cSrcweir return aSeq;
4258cdf0e10cSrcweir }
4259cdf0e10cSrcweir
4260cdf0e10cSrcweir //------------------------------------------------------------------
getSelectedItemPos()4261cdf0e10cSrcweir sal_Int16 SAL_CALL FmXListBoxCell::getSelectedItemPos() throw( RuntimeException )
4262cdf0e10cSrcweir {
4263cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4264cdf0e10cSrcweir if (m_pBox)
4265cdf0e10cSrcweir {
4266cdf0e10cSrcweir UpdateFromColumn();
4267cdf0e10cSrcweir return m_pBox->GetSelectEntryPos();
4268cdf0e10cSrcweir }
4269cdf0e10cSrcweir return 0;
4270cdf0e10cSrcweir }
4271cdf0e10cSrcweir
4272cdf0e10cSrcweir //------------------------------------------------------------------
getSelectedItemsPos()4273cdf0e10cSrcweir Sequence< sal_Int16 > SAL_CALL FmXListBoxCell::getSelectedItemsPos() throw( RuntimeException )
4274cdf0e10cSrcweir {
4275cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4276cdf0e10cSrcweir Sequence<sal_Int16> aSeq;
4277cdf0e10cSrcweir
4278cdf0e10cSrcweir if (m_pBox)
4279cdf0e10cSrcweir {
4280cdf0e10cSrcweir UpdateFromColumn();
4281cdf0e10cSrcweir sal_uInt16 nSelEntries = m_pBox->GetSelectEntryCount();
4282cdf0e10cSrcweir aSeq = Sequence<sal_Int16>( nSelEntries );
4283cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < nSelEntries; n++ )
4284cdf0e10cSrcweir aSeq.getArray()[n] = m_pBox->GetSelectEntryPos( n );
4285cdf0e10cSrcweir }
4286cdf0e10cSrcweir return aSeq;
4287cdf0e10cSrcweir }
4288cdf0e10cSrcweir //------------------------------------------------------------------
getSelectedItem()4289cdf0e10cSrcweir ::rtl::OUString SAL_CALL FmXListBoxCell::getSelectedItem() throw( RuntimeException )
4290cdf0e10cSrcweir {
4291cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4292cdf0e10cSrcweir
4293cdf0e10cSrcweir String aItem;
4294cdf0e10cSrcweir if (m_pBox)
4295cdf0e10cSrcweir {
4296cdf0e10cSrcweir UpdateFromColumn();
4297cdf0e10cSrcweir aItem = m_pBox->GetSelectEntry();
4298cdf0e10cSrcweir }
4299cdf0e10cSrcweir
4300cdf0e10cSrcweir return aItem;
4301cdf0e10cSrcweir }
4302cdf0e10cSrcweir
4303cdf0e10cSrcweir //------------------------------------------------------------------
getSelectedItems()4304cdf0e10cSrcweir ::comphelper::StringSequence SAL_CALL FmXListBoxCell::getSelectedItems() throw( RuntimeException )
4305cdf0e10cSrcweir {
4306cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4307cdf0e10cSrcweir
4308cdf0e10cSrcweir ::comphelper::StringSequence aSeq;
4309cdf0e10cSrcweir
4310cdf0e10cSrcweir if (m_pBox)
4311cdf0e10cSrcweir {
4312cdf0e10cSrcweir UpdateFromColumn();
4313cdf0e10cSrcweir sal_uInt16 nSelEntries = m_pBox->GetSelectEntryCount();
4314cdf0e10cSrcweir aSeq = ::comphelper::StringSequence( nSelEntries );
4315cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < nSelEntries; n++ )
4316cdf0e10cSrcweir aSeq.getArray()[n] = m_pBox->GetSelectEntry( n );
4317cdf0e10cSrcweir }
4318cdf0e10cSrcweir return aSeq;
4319cdf0e10cSrcweir }
4320cdf0e10cSrcweir
4321cdf0e10cSrcweir //------------------------------------------------------------------
selectItemPos(sal_Int16 nPos,sal_Bool bSelect)4322cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::selectItemPos(sal_Int16 nPos, sal_Bool bSelect) throw( RuntimeException )
4323cdf0e10cSrcweir {
4324cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4325cdf0e10cSrcweir
4326cdf0e10cSrcweir if (m_pBox)
4327cdf0e10cSrcweir m_pBox->SelectEntryPos( nPos, bSelect );
4328cdf0e10cSrcweir }
4329cdf0e10cSrcweir
4330cdf0e10cSrcweir //------------------------------------------------------------------
selectItemsPos(const Sequence<sal_Int16> & aPositions,sal_Bool bSelect)4331cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::selectItemsPos(const Sequence< sal_Int16 >& aPositions, sal_Bool bSelect) throw( RuntimeException )
4332cdf0e10cSrcweir {
4333cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4334cdf0e10cSrcweir
4335cdf0e10cSrcweir if (m_pBox)
4336cdf0e10cSrcweir {
4337cdf0e10cSrcweir for ( sal_uInt16 n = (sal_uInt16)aPositions.getLength(); n; )
4338cdf0e10cSrcweir m_pBox->SelectEntryPos( (sal_uInt16) aPositions.getConstArray()[--n], bSelect );
4339cdf0e10cSrcweir }
4340cdf0e10cSrcweir }
4341cdf0e10cSrcweir
4342cdf0e10cSrcweir //------------------------------------------------------------------
selectItem(const::rtl::OUString & aItem,sal_Bool bSelect)4343cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::selectItem(const ::rtl::OUString& aItem, sal_Bool bSelect) throw( RuntimeException )
4344cdf0e10cSrcweir {
4345cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4346cdf0e10cSrcweir
4347cdf0e10cSrcweir if (m_pBox)
4348cdf0e10cSrcweir m_pBox->SelectEntry( aItem, bSelect );
4349cdf0e10cSrcweir }
4350cdf0e10cSrcweir
4351cdf0e10cSrcweir //------------------------------------------------------------------
isMutipleMode()4352cdf0e10cSrcweir sal_Bool SAL_CALL FmXListBoxCell::isMutipleMode() throw( RuntimeException )
4353cdf0e10cSrcweir {
4354cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4355cdf0e10cSrcweir
4356cdf0e10cSrcweir sal_Bool bMulti = sal_False;
4357cdf0e10cSrcweir if (m_pBox)
4358cdf0e10cSrcweir bMulti = m_pBox->IsMultiSelectionEnabled();
4359cdf0e10cSrcweir return bMulti;
4360cdf0e10cSrcweir }
4361cdf0e10cSrcweir
4362cdf0e10cSrcweir //------------------------------------------------------------------
setMultipleMode(sal_Bool bMulti)4363cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::setMultipleMode(sal_Bool bMulti) throw( RuntimeException )
4364cdf0e10cSrcweir {
4365cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4366cdf0e10cSrcweir
4367cdf0e10cSrcweir if (m_pBox)
4368cdf0e10cSrcweir m_pBox->EnableMultiSelection( bMulti );
4369cdf0e10cSrcweir }
4370cdf0e10cSrcweir
4371cdf0e10cSrcweir //------------------------------------------------------------------
getDropDownLineCount()4372cdf0e10cSrcweir sal_Int16 SAL_CALL FmXListBoxCell::getDropDownLineCount() throw( RuntimeException )
4373cdf0e10cSrcweir {
4374cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4375cdf0e10cSrcweir
4376cdf0e10cSrcweir sal_Int16 nLines = 0;
4377cdf0e10cSrcweir if (m_pBox)
4378cdf0e10cSrcweir nLines = m_pBox->GetDropDownLineCount();
4379cdf0e10cSrcweir
4380cdf0e10cSrcweir return nLines;
4381cdf0e10cSrcweir }
4382cdf0e10cSrcweir
4383cdf0e10cSrcweir //------------------------------------------------------------------
setDropDownLineCount(sal_Int16 nLines)4384cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::setDropDownLineCount(sal_Int16 nLines) throw( RuntimeException )
4385cdf0e10cSrcweir {
4386cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4387cdf0e10cSrcweir
4388cdf0e10cSrcweir if (m_pBox)
4389cdf0e10cSrcweir m_pBox->SetDropDownLineCount( nLines );
4390cdf0e10cSrcweir }
4391cdf0e10cSrcweir
4392cdf0e10cSrcweir //------------------------------------------------------------------
makeVisible(sal_Int16 nEntry)4393cdf0e10cSrcweir void SAL_CALL FmXListBoxCell::makeVisible(sal_Int16 nEntry) throw( RuntimeException )
4394cdf0e10cSrcweir {
4395cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4396cdf0e10cSrcweir
4397cdf0e10cSrcweir if (m_pBox)
4398cdf0e10cSrcweir m_pBox->SetTopEntry( nEntry );
4399cdf0e10cSrcweir }
4400cdf0e10cSrcweir
4401cdf0e10cSrcweir //------------------------------------------------------------------
onWindowEvent(const sal_uIntPtr _nEventId,const Window & _rWindow,const void * _pEventData)4402cdf0e10cSrcweir void FmXListBoxCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData )
4403cdf0e10cSrcweir {
4404cdf0e10cSrcweir if ( ( &_rWindow == m_pBox )
4405cdf0e10cSrcweir && ( _nEventId == VCLEVENT_LISTBOX_SELECT )
4406cdf0e10cSrcweir )
4407cdf0e10cSrcweir {
4408cdf0e10cSrcweir OnDoubleClick( NULL );
4409cdf0e10cSrcweir
4410cdf0e10cSrcweir ::com::sun::star::awt::ItemEvent aEvent;
4411cdf0e10cSrcweir aEvent.Source = *this;
4412cdf0e10cSrcweir aEvent.Highlighted = sal_False;
4413cdf0e10cSrcweir
4414cdf0e10cSrcweir // Bei Mehrfachselektion 0xFFFF, sonst die ID
4415cdf0e10cSrcweir aEvent.Selected = (m_pBox->GetSelectEntryCount() == 1 )
4416cdf0e10cSrcweir ? m_pBox->GetSelectEntryPos() : 0xFFFF;
4417cdf0e10cSrcweir
4418cdf0e10cSrcweir m_aItemListeners.notifyEach( &awt::XItemListener::itemStateChanged, aEvent );
4419cdf0e10cSrcweir return;
4420cdf0e10cSrcweir }
4421cdf0e10cSrcweir
4422cdf0e10cSrcweir FmXTextCell::onWindowEvent( _nEventId, _rWindow, _pEventData );
4423cdf0e10cSrcweir }
4424cdf0e10cSrcweir
4425cdf0e10cSrcweir
4426cdf0e10cSrcweir //------------------------------------------------------------------
IMPL_LINK(FmXListBoxCell,OnDoubleClick,void *,EMPTYARG)4427cdf0e10cSrcweir IMPL_LINK( FmXListBoxCell, OnDoubleClick, void*, EMPTYARG )
4428cdf0e10cSrcweir {
4429cdf0e10cSrcweir if (m_pBox)
4430cdf0e10cSrcweir {
4431cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIt( m_aActionListeners );
4432cdf0e10cSrcweir
4433cdf0e10cSrcweir ::com::sun::star::awt::ActionEvent aEvent;
4434cdf0e10cSrcweir aEvent.Source = *this;
4435cdf0e10cSrcweir aEvent.ActionCommand = m_pBox->GetSelectEntry();
4436cdf0e10cSrcweir
4437cdf0e10cSrcweir while( aIt.hasMoreElements() )
4438cdf0e10cSrcweir ((::com::sun::star::awt::XActionListener *)aIt.next())->actionPerformed( aEvent );
4439cdf0e10cSrcweir }
4440cdf0e10cSrcweir return 1;
4441cdf0e10cSrcweir }
4442cdf0e10cSrcweir
4443cdf0e10cSrcweir
4444cdf0e10cSrcweir /*************************************************************************/
4445cdf0e10cSrcweir
4446cdf0e10cSrcweir DBG_NAME( FmXComboBoxCell );
4447cdf0e10cSrcweir
4448cdf0e10cSrcweir //------------------------------------------------------------------------------
FmXComboBoxCell(DbGridColumn * pColumn,DbCellControl & _rControl)4449cdf0e10cSrcweir FmXComboBoxCell::FmXComboBoxCell( DbGridColumn* pColumn, DbCellControl& _rControl )
4450cdf0e10cSrcweir :FmXTextCell( pColumn, _rControl )
4451cdf0e10cSrcweir ,m_aItemListeners( m_aMutex )
4452cdf0e10cSrcweir ,m_aActionListeners( m_aMutex )
4453cdf0e10cSrcweir ,m_pComboBox( &static_cast< ComboBox& >( _rControl.GetWindow() ) )
4454cdf0e10cSrcweir {
4455cdf0e10cSrcweir DBG_CTOR( FmXComboBoxCell, NULL );
4456cdf0e10cSrcweir }
4457cdf0e10cSrcweir
4458cdf0e10cSrcweir //------------------------------------------------------------------------------
~FmXComboBoxCell()4459cdf0e10cSrcweir FmXComboBoxCell::~FmXComboBoxCell()
4460cdf0e10cSrcweir {
4461cdf0e10cSrcweir if ( !OComponentHelper::rBHelper.bDisposed )
4462cdf0e10cSrcweir {
4463cdf0e10cSrcweir acquire();
4464cdf0e10cSrcweir dispose();
4465cdf0e10cSrcweir }
4466cdf0e10cSrcweir
4467cdf0e10cSrcweir DBG_DTOR( FmXComboBoxCell, NULL );
4468cdf0e10cSrcweir }
4469cdf0e10cSrcweir
4470cdf0e10cSrcweir //-----------------------------------------------------------------------------
disposing()4471cdf0e10cSrcweir void FmXComboBoxCell::disposing()
4472cdf0e10cSrcweir {
4473cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt(*this);
4474cdf0e10cSrcweir m_aItemListeners.disposeAndClear(aEvt);
4475cdf0e10cSrcweir m_aActionListeners.disposeAndClear(aEvt);
4476cdf0e10cSrcweir
4477cdf0e10cSrcweir FmXTextCell::disposing();
4478cdf0e10cSrcweir }
4479cdf0e10cSrcweir
4480cdf0e10cSrcweir //------------------------------------------------------------------
queryAggregation(const::com::sun::star::uno::Type & _rType)4481cdf0e10cSrcweir Any SAL_CALL FmXComboBoxCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
4482cdf0e10cSrcweir {
4483cdf0e10cSrcweir Any aReturn = FmXTextCell::queryAggregation(_rType);
4484cdf0e10cSrcweir
4485cdf0e10cSrcweir if ( !aReturn.hasValue() )
4486cdf0e10cSrcweir aReturn = FmXComboBoxCell_Base::queryInterface( _rType );
4487cdf0e10cSrcweir
4488cdf0e10cSrcweir return aReturn;
4489cdf0e10cSrcweir }
4490cdf0e10cSrcweir
4491cdf0e10cSrcweir //-------------------------------------------------------------------------
getTypes()4492cdf0e10cSrcweir Sequence< Type > SAL_CALL FmXComboBoxCell::getTypes( ) throw(RuntimeException)
4493cdf0e10cSrcweir {
4494cdf0e10cSrcweir return ::comphelper::concatSequences(
4495cdf0e10cSrcweir FmXTextCell::getTypes(),
4496cdf0e10cSrcweir FmXComboBoxCell_Base::getTypes()
4497cdf0e10cSrcweir );
4498cdf0e10cSrcweir }
4499cdf0e10cSrcweir
4500cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_GET_IMPLEMENTATION_ID(FmXComboBoxCell)4501cdf0e10cSrcweir IMPLEMENT_GET_IMPLEMENTATION_ID( FmXComboBoxCell )
4502cdf0e10cSrcweir
4503cdf0e10cSrcweir //------------------------------------------------------------------
4504cdf0e10cSrcweir void SAL_CALL FmXComboBoxCell::addItemListener(const Reference< awt::XItemListener >& l) throw( RuntimeException )
4505cdf0e10cSrcweir {
4506cdf0e10cSrcweir m_aItemListeners.addInterface( l );
4507cdf0e10cSrcweir }
4508cdf0e10cSrcweir
4509cdf0e10cSrcweir //------------------------------------------------------------------
removeItemListener(const Reference<awt::XItemListener> & l)4510cdf0e10cSrcweir void SAL_CALL FmXComboBoxCell::removeItemListener(const Reference< awt::XItemListener >& l) throw( RuntimeException )
4511cdf0e10cSrcweir {
4512cdf0e10cSrcweir m_aItemListeners.removeInterface( l );
4513cdf0e10cSrcweir }
4514cdf0e10cSrcweir
4515cdf0e10cSrcweir //------------------------------------------------------------------
addActionListener(const Reference<awt::XActionListener> & l)4516cdf0e10cSrcweir void SAL_CALL FmXComboBoxCell::addActionListener(const Reference< awt::XActionListener >& l) throw( RuntimeException )
4517cdf0e10cSrcweir {
4518cdf0e10cSrcweir m_aActionListeners.addInterface( l );
4519cdf0e10cSrcweir }
4520cdf0e10cSrcweir
4521cdf0e10cSrcweir //------------------------------------------------------------------
removeActionListener(const Reference<awt::XActionListener> & l)4522cdf0e10cSrcweir void SAL_CALL FmXComboBoxCell::removeActionListener(const Reference< awt::XActionListener >& l) throw( RuntimeException )
4523cdf0e10cSrcweir {
4524cdf0e10cSrcweir m_aActionListeners.removeInterface( l );
4525cdf0e10cSrcweir }
4526cdf0e10cSrcweir
4527cdf0e10cSrcweir //------------------------------------------------------------------
addItem(const::rtl::OUString & _Item,sal_Int16 _Pos)4528cdf0e10cSrcweir void SAL_CALL FmXComboBoxCell::addItem( const ::rtl::OUString& _Item, sal_Int16 _Pos ) throw( RuntimeException )
4529cdf0e10cSrcweir {
4530cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4531cdf0e10cSrcweir if ( m_pComboBox )
4532cdf0e10cSrcweir m_pComboBox->InsertEntry( _Item, _Pos );
4533cdf0e10cSrcweir }
4534cdf0e10cSrcweir
4535cdf0e10cSrcweir //------------------------------------------------------------------
addItems(const Sequence<::rtl::OUString> & _Items,sal_Int16 _Pos)4536cdf0e10cSrcweir void SAL_CALL FmXComboBoxCell::addItems( const Sequence< ::rtl::OUString >& _Items, sal_Int16 _Pos ) throw( RuntimeException )
4537cdf0e10cSrcweir {
4538cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4539cdf0e10cSrcweir if ( m_pComboBox )
4540cdf0e10cSrcweir {
4541cdf0e10cSrcweir sal_uInt16 nP = _Pos;
4542cdf0e10cSrcweir for ( sal_uInt16 n = 0; n < _Items.getLength(); n++ )
4543cdf0e10cSrcweir {
4544cdf0e10cSrcweir m_pComboBox->InsertEntry( _Items.getConstArray()[n], nP );
4545cdf0e10cSrcweir if ( _Pos != -1 )
4546cdf0e10cSrcweir nP++;
4547cdf0e10cSrcweir }
4548cdf0e10cSrcweir }
4549cdf0e10cSrcweir }
4550cdf0e10cSrcweir
4551cdf0e10cSrcweir //------------------------------------------------------------------
removeItems(sal_Int16 _Pos,sal_Int16 _Count)4552cdf0e10cSrcweir void SAL_CALL FmXComboBoxCell::removeItems( sal_Int16 _Pos, sal_Int16 _Count ) throw( RuntimeException )
4553cdf0e10cSrcweir {
4554cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4555cdf0e10cSrcweir if ( m_pComboBox )
4556cdf0e10cSrcweir {
4557cdf0e10cSrcweir for ( sal_uInt16 n = _Count; n; )
4558cdf0e10cSrcweir m_pComboBox->RemoveEntry( _Pos + (--n) );
4559cdf0e10cSrcweir }
4560cdf0e10cSrcweir }
4561cdf0e10cSrcweir
4562cdf0e10cSrcweir //------------------------------------------------------------------
getItemCount()4563cdf0e10cSrcweir sal_Int16 SAL_CALL FmXComboBoxCell::getItemCount() throw( RuntimeException )
4564cdf0e10cSrcweir {
4565cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4566cdf0e10cSrcweir return m_pComboBox ? m_pComboBox->GetEntryCount() : 0;
4567cdf0e10cSrcweir }
4568cdf0e10cSrcweir
4569cdf0e10cSrcweir //------------------------------------------------------------------
getItem(sal_Int16 _Pos)4570cdf0e10cSrcweir ::rtl::OUString SAL_CALL FmXComboBoxCell::getItem( sal_Int16 _Pos ) throw( RuntimeException )
4571cdf0e10cSrcweir {
4572cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4573cdf0e10cSrcweir String sItem;
4574cdf0e10cSrcweir if ( m_pComboBox )
4575cdf0e10cSrcweir sItem = m_pComboBox->GetEntry( _Pos );
4576cdf0e10cSrcweir return sItem;
4577cdf0e10cSrcweir }
4578cdf0e10cSrcweir //------------------------------------------------------------------
getItems()4579cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL FmXComboBoxCell::getItems() throw( RuntimeException )
4580cdf0e10cSrcweir {
4581cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4582cdf0e10cSrcweir
4583cdf0e10cSrcweir Sequence< ::rtl::OUString > aItems;
4584cdf0e10cSrcweir if ( m_pComboBox )
4585cdf0e10cSrcweir {
4586cdf0e10cSrcweir sal_uInt16 nEntries = m_pComboBox->GetEntryCount();
4587cdf0e10cSrcweir aItems.realloc( nEntries );
4588cdf0e10cSrcweir ::rtl::OUString* pItem = aItems.getArray();
4589cdf0e10cSrcweir for ( sal_uInt16 n=0; n<nEntries; ++n, ++pItem )
4590cdf0e10cSrcweir *pItem = m_pComboBox->GetEntry( n );
4591cdf0e10cSrcweir }
4592cdf0e10cSrcweir return aItems;
4593cdf0e10cSrcweir }
4594cdf0e10cSrcweir
4595cdf0e10cSrcweir //------------------------------------------------------------------
getDropDownLineCount()4596cdf0e10cSrcweir sal_Int16 SAL_CALL FmXComboBoxCell::getDropDownLineCount() throw( RuntimeException )
4597cdf0e10cSrcweir {
4598cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4599cdf0e10cSrcweir
4600cdf0e10cSrcweir sal_Int16 nLines = 0;
4601cdf0e10cSrcweir if ( m_pComboBox )
4602cdf0e10cSrcweir nLines = m_pComboBox->GetDropDownLineCount();
4603cdf0e10cSrcweir
4604cdf0e10cSrcweir return nLines;
4605cdf0e10cSrcweir }
4606cdf0e10cSrcweir
4607cdf0e10cSrcweir //------------------------------------------------------------------
setDropDownLineCount(sal_Int16 nLines)4608cdf0e10cSrcweir void SAL_CALL FmXComboBoxCell::setDropDownLineCount(sal_Int16 nLines) throw( RuntimeException )
4609cdf0e10cSrcweir {
4610cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4611cdf0e10cSrcweir if ( m_pComboBox )
4612cdf0e10cSrcweir m_pComboBox->SetDropDownLineCount( nLines );
4613cdf0e10cSrcweir }
4614cdf0e10cSrcweir
4615cdf0e10cSrcweir //------------------------------------------------------------------------------
onWindowEvent(const sal_uIntPtr _nEventId,const Window & _rWindow,const void * _pEventData)4616cdf0e10cSrcweir void FmXComboBoxCell::onWindowEvent( const sal_uIntPtr _nEventId, const Window& _rWindow, const void* _pEventData )
4617cdf0e10cSrcweir {
4618cdf0e10cSrcweir
4619cdf0e10cSrcweir switch ( _nEventId )
4620cdf0e10cSrcweir {
4621cdf0e10cSrcweir case VCLEVENT_COMBOBOX_SELECT:
4622cdf0e10cSrcweir {
4623cdf0e10cSrcweir awt::ItemEvent aEvent;
4624cdf0e10cSrcweir aEvent.Source = *this;
4625cdf0e10cSrcweir aEvent.Highlighted = sal_False;
4626cdf0e10cSrcweir
4627cdf0e10cSrcweir // Bei Mehrfachselektion 0xFFFF, sonst die ID
4628cdf0e10cSrcweir aEvent.Selected = ( m_pComboBox->GetSelectEntryCount() == 1 )
4629cdf0e10cSrcweir ? m_pComboBox->GetSelectEntryPos()
4630cdf0e10cSrcweir : 0xFFFF;
4631cdf0e10cSrcweir m_aItemListeners.notifyEach( &awt::XItemListener::itemStateChanged, aEvent );
4632cdf0e10cSrcweir }
4633cdf0e10cSrcweir break;
4634cdf0e10cSrcweir
4635cdf0e10cSrcweir default:
4636cdf0e10cSrcweir FmXTextCell::onWindowEvent( _nEventId, _rWindow, _pEventData );
4637cdf0e10cSrcweir break;
4638cdf0e10cSrcweir }
4639cdf0e10cSrcweir }
4640cdf0e10cSrcweir
4641cdf0e10cSrcweir /*************************************************************************/
4642cdf0e10cSrcweir TYPEINIT1(FmXFilterCell, FmXGridCell);
4643cdf0e10cSrcweir
4644cdf0e10cSrcweir //------------------------------------------------------------------------------
FmXFilterCell_CreateInstance(const Reference<::com::sun::star::lang::XMultiServiceFactory> &)4645cdf0e10cSrcweir Reference< XInterface > FmXFilterCell_CreateInstance(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& /*_rxFactory*/)
4646cdf0e10cSrcweir {
4647cdf0e10cSrcweir return *new FmXFilterCell();
4648cdf0e10cSrcweir }
4649cdf0e10cSrcweir
4650cdf0e10cSrcweir DBG_NAME(FmXFilterCell);
4651cdf0e10cSrcweir //------------------------------------------------------------------------------
FmXFilterCell(DbGridColumn * pColumn,DbCellControl * pControl)4652cdf0e10cSrcweir FmXFilterCell::FmXFilterCell(DbGridColumn* pColumn, DbCellControl* pControl )
4653cdf0e10cSrcweir :FmXGridCell( pColumn, pControl )
4654cdf0e10cSrcweir ,m_aTextListeners(m_aMutex)
4655cdf0e10cSrcweir {
4656cdf0e10cSrcweir DBG_CTOR(FmXFilterCell,NULL);
4657cdf0e10cSrcweir
4658cdf0e10cSrcweir DBG_ASSERT( m_pCellControl->ISA( DbFilterField ), "FmXFilterCell::FmXFilterCell: invalid cell control!" );
4659cdf0e10cSrcweir static_cast< DbFilterField* >( m_pCellControl )->SetCommitHdl( LINK( this, FmXFilterCell, OnCommit ) );
4660cdf0e10cSrcweir }
4661cdf0e10cSrcweir
4662cdf0e10cSrcweir //------------------------------------------------------------------
~FmXFilterCell()4663cdf0e10cSrcweir FmXFilterCell::~FmXFilterCell()
4664cdf0e10cSrcweir {
4665cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed)
4666cdf0e10cSrcweir {
4667cdf0e10cSrcweir acquire();
4668cdf0e10cSrcweir dispose();
4669cdf0e10cSrcweir }
4670cdf0e10cSrcweir
4671cdf0e10cSrcweir DBG_DTOR(FmXFilterCell,NULL);
4672cdf0e10cSrcweir }
4673cdf0e10cSrcweir
4674cdf0e10cSrcweir // XUnoTunnel
4675cdf0e10cSrcweir //------------------------------------------------------------------------------
getSomething(const Sequence<sal_Int8> & _rIdentifier)4676cdf0e10cSrcweir sal_Int64 SAL_CALL FmXFilterCell::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
4677cdf0e10cSrcweir {
4678cdf0e10cSrcweir sal_Int64 nReturn(0);
4679cdf0e10cSrcweir
4680cdf0e10cSrcweir if ( (_rIdentifier.getLength() == 16)
4681cdf0e10cSrcweir && (0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), _rIdentifier.getConstArray(), 16 ))
4682cdf0e10cSrcweir )
4683cdf0e10cSrcweir {
4684cdf0e10cSrcweir nReturn = reinterpret_cast<sal_Int64>(this);
4685cdf0e10cSrcweir }
4686cdf0e10cSrcweir
4687cdf0e10cSrcweir return nReturn;
4688cdf0e10cSrcweir }
4689cdf0e10cSrcweir
4690cdf0e10cSrcweir //------------------------------------------------------------------------------
getUnoTunnelId()4691cdf0e10cSrcweir const Sequence<sal_Int8>& FmXFilterCell::getUnoTunnelId()
4692cdf0e10cSrcweir {
4693cdf0e10cSrcweir static Sequence< sal_Int8 > * pSeq = 0;
4694cdf0e10cSrcweir if( !pSeq )
4695cdf0e10cSrcweir {
4696cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
4697cdf0e10cSrcweir if( !pSeq )
4698cdf0e10cSrcweir {
4699cdf0e10cSrcweir static Sequence< sal_Int8 > aSeq( 16 );
4700cdf0e10cSrcweir rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
4701cdf0e10cSrcweir pSeq = &aSeq;
4702cdf0e10cSrcweir }
4703cdf0e10cSrcweir }
4704cdf0e10cSrcweir return *pSeq;
4705cdf0e10cSrcweir }
4706cdf0e10cSrcweir
4707cdf0e10cSrcweir //------------------------------------------------------------------------------
getImplementation(const Reference<::com::sun::star::awt::XControl> & _rxObject)4708cdf0e10cSrcweir FmXFilterCell* FmXFilterCell::getImplementation(const Reference< ::com::sun::star::awt::XControl >& _rxObject)
4709cdf0e10cSrcweir {
4710cdf0e10cSrcweir Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel(
4711cdf0e10cSrcweir _rxObject, UNO_QUERY);
4712cdf0e10cSrcweir if (xTunnel.is())
4713cdf0e10cSrcweir return reinterpret_cast<FmXFilterCell*>(xTunnel->getSomething(getUnoTunnelId()));
4714cdf0e10cSrcweir return NULL;
4715cdf0e10cSrcweir }
4716cdf0e10cSrcweir
4717cdf0e10cSrcweir //------------------------------------------------------------------------------
PaintCell(OutputDevice & rDev,const Rectangle & rRect)4718cdf0e10cSrcweir void FmXFilterCell::PaintCell( OutputDevice& rDev, const Rectangle& rRect )
4719cdf0e10cSrcweir {
4720cdf0e10cSrcweir static_cast< DbFilterField* >( m_pCellControl )->PaintCell( rDev, rRect );
4721cdf0e10cSrcweir }
4722cdf0e10cSrcweir
4723cdf0e10cSrcweir // OComponentHelper
4724cdf0e10cSrcweir //-----------------------------------------------------------------------------
disposing()4725cdf0e10cSrcweir void FmXFilterCell::disposing()
4726cdf0e10cSrcweir {
4727cdf0e10cSrcweir ::com::sun::star::lang::EventObject aEvt(*this);
4728cdf0e10cSrcweir m_aTextListeners.disposeAndClear(aEvt);
4729cdf0e10cSrcweir
4730cdf0e10cSrcweir ((DbFilterField*)m_pCellControl)->SetCommitHdl(Link());
4731cdf0e10cSrcweir
4732cdf0e10cSrcweir FmXGridCell::disposing();
4733cdf0e10cSrcweir }
4734cdf0e10cSrcweir
4735cdf0e10cSrcweir //------------------------------------------------------------------
queryAggregation(const::com::sun::star::uno::Type & _rType)4736cdf0e10cSrcweir Any SAL_CALL FmXFilterCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
4737cdf0e10cSrcweir {
4738cdf0e10cSrcweir Any aReturn = FmXGridCell::queryAggregation(_rType);
4739cdf0e10cSrcweir
4740cdf0e10cSrcweir if ( !aReturn.hasValue() )
4741cdf0e10cSrcweir aReturn = FmXFilterCell_Base::queryInterface( _rType );
4742cdf0e10cSrcweir
4743cdf0e10cSrcweir return aReturn;
4744cdf0e10cSrcweir }
4745cdf0e10cSrcweir
4746cdf0e10cSrcweir //-------------------------------------------------------------------------
getTypes()4747cdf0e10cSrcweir Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXFilterCell::getTypes( ) throw(RuntimeException)
4748cdf0e10cSrcweir {
4749cdf0e10cSrcweir return ::comphelper::concatSequences(
4750cdf0e10cSrcweir FmXGridCell::getTypes(),
4751cdf0e10cSrcweir FmXFilterCell_Base::getTypes()
4752cdf0e10cSrcweir );
4753cdf0e10cSrcweir }
4754cdf0e10cSrcweir
4755cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_GET_IMPLEMENTATION_ID(FmXFilterCell)4756cdf0e10cSrcweir IMPLEMENT_GET_IMPLEMENTATION_ID( FmXFilterCell )
4757cdf0e10cSrcweir
4758cdf0e10cSrcweir // ::com::sun::star::awt::XTextComponent
4759cdf0e10cSrcweir //------------------------------------------------------------------------------
4760cdf0e10cSrcweir void SAL_CALL FmXFilterCell::addTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException )
4761cdf0e10cSrcweir {
4762cdf0e10cSrcweir m_aTextListeners.addInterface( l );
4763cdf0e10cSrcweir }
4764cdf0e10cSrcweir
4765cdf0e10cSrcweir //------------------------------------------------------------------------------
removeTextListener(const Reference<::com::sun::star::awt::XTextListener> & l)4766cdf0e10cSrcweir void SAL_CALL FmXFilterCell::removeTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException )
4767cdf0e10cSrcweir {
4768cdf0e10cSrcweir m_aTextListeners.removeInterface( l );
4769cdf0e10cSrcweir }
4770cdf0e10cSrcweir
4771cdf0e10cSrcweir //------------------------------------------------------------------------------
setText(const::rtl::OUString & aText)4772cdf0e10cSrcweir void SAL_CALL FmXFilterCell::setText( const ::rtl::OUString& aText ) throw( RuntimeException )
4773cdf0e10cSrcweir {
4774cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4775cdf0e10cSrcweir ((DbFilterField*)m_pCellControl)->SetText(aText);
4776cdf0e10cSrcweir }
4777cdf0e10cSrcweir
4778cdf0e10cSrcweir //------------------------------------------------------------------------------
insertText(const::com::sun::star::awt::Selection &,const::rtl::OUString &)4779cdf0e10cSrcweir void SAL_CALL FmXFilterCell::insertText( const ::com::sun::star::awt::Selection& /*rSel*/, const ::rtl::OUString& /*aText*/ ) throw( RuntimeException )
4780cdf0e10cSrcweir {
4781cdf0e10cSrcweir }
4782cdf0e10cSrcweir
4783cdf0e10cSrcweir //------------------------------------------------------------------------------
getText()4784cdf0e10cSrcweir ::rtl::OUString SAL_CALL FmXFilterCell::getText() throw( RuntimeException )
4785cdf0e10cSrcweir {
4786cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex );
4787cdf0e10cSrcweir return ((DbFilterField*)m_pCellControl)->GetText();
4788cdf0e10cSrcweir }
4789cdf0e10cSrcweir
4790cdf0e10cSrcweir //------------------------------------------------------------------------------
getSelectedText(void)4791cdf0e10cSrcweir ::rtl::OUString SAL_CALL FmXFilterCell::getSelectedText( void ) throw( RuntimeException )
4792cdf0e10cSrcweir {
4793cdf0e10cSrcweir return getText();
4794cdf0e10cSrcweir }
4795cdf0e10cSrcweir
4796cdf0e10cSrcweir //------------------------------------------------------------------------------
setSelection(const::com::sun::star::awt::Selection &)4797cdf0e10cSrcweir void SAL_CALL FmXFilterCell::setSelection( const ::com::sun::star::awt::Selection& /*aSelection*/ ) throw( RuntimeException )
4798cdf0e10cSrcweir {
4799cdf0e10cSrcweir }
4800cdf0e10cSrcweir
4801cdf0e10cSrcweir //------------------------------------------------------------------------------
getSelection(void)4802cdf0e10cSrcweir ::com::sun::star::awt::Selection SAL_CALL FmXFilterCell::getSelection( void ) throw( RuntimeException )
4803cdf0e10cSrcweir {
4804cdf0e10cSrcweir return ::com::sun::star::awt::Selection();
4805cdf0e10cSrcweir }
4806cdf0e10cSrcweir
4807cdf0e10cSrcweir //------------------------------------------------------------------------------
isEditable(void)4808cdf0e10cSrcweir sal_Bool SAL_CALL FmXFilterCell::isEditable( void ) throw( RuntimeException )
4809cdf0e10cSrcweir {
4810cdf0e10cSrcweir return sal_True;
4811cdf0e10cSrcweir }
4812cdf0e10cSrcweir
4813cdf0e10cSrcweir //------------------------------------------------------------------------------
setEditable(sal_Bool)4814cdf0e10cSrcweir void SAL_CALL FmXFilterCell::setEditable( sal_Bool /*bEditable*/ ) throw( RuntimeException )
4815cdf0e10cSrcweir {
4816cdf0e10cSrcweir }
4817cdf0e10cSrcweir
4818cdf0e10cSrcweir //------------------------------------------------------------------------------
getMaxTextLen()4819cdf0e10cSrcweir sal_Int16 SAL_CALL FmXFilterCell::getMaxTextLen() throw( RuntimeException )
4820cdf0e10cSrcweir {
4821cdf0e10cSrcweir return 0;
4822cdf0e10cSrcweir }
4823cdf0e10cSrcweir
4824cdf0e10cSrcweir //------------------------------------------------------------------------------
setMaxTextLen(sal_Int16)4825cdf0e10cSrcweir void SAL_CALL FmXFilterCell::setMaxTextLen( sal_Int16 /*nLen*/ ) throw( RuntimeException )
4826cdf0e10cSrcweir {
4827cdf0e10cSrcweir }
4828cdf0e10cSrcweir
4829cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPL_LINK(FmXFilterCell,OnCommit,void *,EMPTYARG)4830cdf0e10cSrcweir IMPL_LINK( FmXFilterCell, OnCommit, void*, EMPTYARG )
4831cdf0e10cSrcweir {
4832cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIt( m_aTextListeners );
4833cdf0e10cSrcweir ::com::sun::star::awt::TextEvent aEvt;
4834cdf0e10cSrcweir aEvt.Source = *this;
4835cdf0e10cSrcweir while( aIt.hasMoreElements() )
4836cdf0e10cSrcweir ((::com::sun::star::awt::XTextListener *)aIt.next())->textChanged( aEvt );
4837cdf0e10cSrcweir return 1;
4838cdf0e10cSrcweir }
4839cdf0e10cSrcweir
4840