update dev300-m58
[ooovba.git] / svx / source / fmcomp / gridcell.cxx
blob0442a5e1e83b8a7e0576cece321c5ded032c864e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gridcell.cxx,v $
10 * $Revision: 1.66 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include "gridcell.hxx"
34 #include "fmtools.hxx"
35 #include <stdio.h>
36 #ifndef _SVX_FMPROP_HRC
37 #include "fmprop.hrc"
38 #endif
39 #include "gridcols.hxx"
40 #include "sdbdatacolumn.hxx"
41 #include <com/sun/star/awt/VisualEffect.hpp>
42 #include <com/sun/star/sdbc/XStatement.hpp>
43 #include <com/sun/star/script/XEventAttacherManager.hpp>
44 #ifndef _COM_SUN_STAR_SDDB_XCOLUMNSSUPPLIER_HPP_
45 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
46 #endif
47 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
48 #include <com/sun/star/sdbc/DataType.hpp>
49 #include <com/sun/star/sdbc/ColumnValue.hpp>
50 #include <com/sun/star/form/XBoundComponent.hpp>
51 #include <com/sun/star/container/XChild.hpp>
52 #include <com/sun/star/form/FormComponentType.hpp>
53 #include <com/sun/star/util/XNumberFormatter.hpp>
54 #include <com/sun/star/util/NumberFormat.hpp>
55 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
56 #include <com/sun/star/container/XNamed.hpp>
57 #include <com/sun/star/awt/LineEndFormat.hpp>
58 #include <com/sun/star/awt/MouseWheelBehavior.hpp>
59 #ifndef _COM_SUN_STAR_SCRTIP_XEVENTATTACHERMANAGER_HPP_
60 #include <com/sun/star/script/XEventAttacherManager.hpp>
61 #endif
62 #include <svtools/fmtfield.hxx>
63 #include <svtools/numuno.hxx>
64 #include <svtools/calendar.hxx>
65 #include <vcl/longcurr.hxx>
66 #include <svx/dialmgr.hxx>
67 #ifndef _SVX_FMRESIDS_HRC
68 #include "fmresids.hrc"
69 #endif
70 #include <tools/shl.hxx>
71 #include <tools/diagnose_ex.h>
72 #include <comphelper/numbers.hxx>
73 #include <comphelper/property.hxx>
74 #include <comphelper/extract.hxx>
75 #include <cppuhelper/typeprovider.hxx>
76 #include <i18npool/lang.h>
77 #include <connectivity/formattedcolumnvalue.hxx>
79 #include <math.h>
80 #include <rtl/math.hxx>
81 #include <svtools/svmedit.hxx>
83 using namespace ::connectivity;
84 using namespace ::connectivity::simple;
85 using namespace ::svxform;
86 using namespace ::comphelper;
87 using namespace ::svt;
88 using namespace ::com::sun::star;
89 using namespace ::com::sun::star::uno;
90 using namespace ::com::sun::star::sdbc;
91 using namespace ::com::sun::star::sdb;
92 using namespace ::com::sun::star::beans;
93 using namespace ::com::sun::star::form;
95 using ::com::sun::star::util::XNumberFormatter;
96 namespace MouseWheelBehavior = ::com::sun::star::awt::MouseWheelBehavior;
98 String INVALIDTEXT = String::CreateFromAscii("###");
99 String OBJECTTEXT = String::CreateFromAscii("<OBJECT>");
100 // TODO: resource
102 //==================================================================
103 //= helper
104 //==================================================================
105 namespace
107 static LineEnd getModelLineEndSetting( const Reference< XPropertySet >& _rxModel )
109 LineEnd eFormat = LINEEND_LF;
113 sal_Int16 nLineEndFormat = awt::LineEndFormat::LINE_FEED;
115 Reference< XPropertySetInfo > xPSI;
116 if ( _rxModel.is() )
117 xPSI = _rxModel->getPropertySetInfo();
119 OSL_ENSURE( xPSI.is(), "getModelLineEndSetting: invalid column model!" );
120 if ( xPSI.is() && xPSI->hasPropertyByName( FM_PROP_LINEENDFORMAT ) )
122 OSL_VERIFY( _rxModel->getPropertyValue( FM_PROP_LINEENDFORMAT ) >>= nLineEndFormat );
124 switch ( nLineEndFormat )
126 case awt::LineEndFormat::CARRIAGE_RETURN: eFormat = LINEEND_CR; break;
127 case awt::LineEndFormat::LINE_FEED: eFormat = LINEEND_LF; break;
128 case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED: eFormat = LINEEND_CRLF; break;
129 default:
130 OSL_ENSURE( sal_False, "getModelLineEndSetting: what's this?" );
134 catch( const Exception& )
136 OSL_ENSURE( sal_False, "getModelLineEndSetting: caught an exception!" );
138 return eFormat;
142 //==================================================================
143 //= DbGridColumn
144 //==================================================================
145 //------------------------------------------------------------------------------
146 CellControllerRef DbGridColumn::s_xEmptyController;
148 //------------------------------------------------------------------------------
149 void DbGridColumn::CreateControl(sal_Int32 _nFieldPos, const Reference< ::com::sun::star::beans::XPropertySet >& xField, sal_Int32 nTypeId)
151 Clear();
153 m_nTypeId = (sal_Int16)nTypeId;
154 if (xField != m_xField)
156 // Grundeinstellung
157 m_xField = xField;
158 xField->getPropertyValue(FM_PROP_FORMATKEY) >>= m_nFormatKey;
159 m_nFieldPos = (sal_Int16)_nFieldPos;
160 m_bReadOnly = ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_ISREADONLY));
161 m_bAutoValue = ::comphelper::getBOOL(xField->getPropertyValue(FM_PROP_AUTOINCREMENT));
162 m_nFieldType = (sal_Int16)::comphelper::getINT32(xField->getPropertyValue(FM_PROP_FIELDTYPE));
164 switch (m_nFieldType)
166 case DataType::DATE:
167 case DataType::TIME:
168 case DataType::TIMESTAMP:
169 m_bDateTime = sal_True;
171 case DataType::BIT:
172 case DataType::BOOLEAN:
173 case DataType::TINYINT:
174 case DataType::SMALLINT:
175 case DataType::INTEGER:
176 case DataType::BIGINT:
177 case DataType::FLOAT:
178 case DataType::REAL:
179 case DataType::DOUBLE:
180 case DataType::NUMERIC:
181 case DataType::DECIMAL:
182 m_nAlign = ::com::sun::star::awt::TextAlign::RIGHT;
183 m_bNumeric = sal_True;
184 break;
185 default:
186 m_nAlign = ::com::sun::star::awt::TextAlign::LEFT;
187 break;
191 DbCellControl* pCellControl = NULL;
192 if (m_rParent.IsFilterMode())
194 pCellControl = new DbFilterField(m_rParent.getServiceManager(),*this);
196 else
199 switch (nTypeId)
201 case TYPE_CHECKBOX: pCellControl = new DbCheckBox(*this); break;
202 case TYPE_COMBOBOX: pCellControl = new DbComboBox(*this); break;
203 case TYPE_CURRENCYFIELD: pCellControl = new DbCurrencyField(*this); break;
204 case TYPE_DATEFIELD: pCellControl = new DbDateField(*this); break;
205 case TYPE_LISTBOX: pCellControl = new DbListBox(*this); break;
206 case TYPE_NUMERICFIELD: pCellControl = new DbNumericField(*this); break;
207 case TYPE_PATTERNFIELD: pCellControl = new DbPatternField( *this, ::comphelper::ComponentContext( m_rParent.getServiceManager() ) ); break;
208 case TYPE_TEXTFIELD: pCellControl = new DbTextField(*this); break;
209 case TYPE_TIMEFIELD: pCellControl = new DbTimeField(*this); break;
210 case TYPE_FORMATTEDFIELD: pCellControl = new DbFormattedField(*this); break;
211 default:
212 DBG_ERROR("DbGridColumn::CreateControl: Unknown Column");
213 return;
217 Reference< XRowSet > xCur;
218 if (m_rParent.getDataSource())
219 xCur = Reference< XRowSet > ((Reference< XInterface >)*m_rParent.getDataSource(), UNO_QUERY);
220 // TODO : the cursor wrapper should use an XRowSet interface, too
222 pCellControl->Init( m_rParent.GetDataWindow(), xCur );
224 // now create the control wrapper
225 if (m_rParent.IsFilterMode())
226 m_pCell = new FmXFilterCell(this, pCellControl);
227 else
229 switch (nTypeId)
231 case TYPE_CHECKBOX: m_pCell = new FmXCheckBoxCell(this, pCellControl); break;
232 case TYPE_LISTBOX: m_pCell = new FmXListBoxCell(this, pCellControl); break;
233 default:
234 m_pCell = new FmXEditCell(this, pCellControl);
237 m_pCell->acquire();
239 impl_toggleScriptManager_nothrow( true );
241 // only if we use have a bound field, we use a a controller for displaying the
242 // window in the grid
243 if (m_xField.is())
244 m_xController = pCellControl->CreateController();
247 //------------------------------------------------------------------------------
248 void DbGridColumn::impl_toggleScriptManager_nothrow( bool _bAttach )
252 Reference< container::XChild > xChild( m_xModel, UNO_QUERY_THROW );
253 Reference< script::XEventAttacherManager > xManager( xChild->getParent(), UNO_QUERY_THROW );
254 Reference< container::XIndexAccess > xContainer( xChild->getParent(), UNO_QUERY_THROW );
256 sal_Int32 nIndexInParent( getElementPos( xContainer, m_xModel ) );
258 Reference< XInterface > xCellInterface( *m_pCell, UNO_QUERY );
259 if ( _bAttach )
260 xManager->attach( nIndexInParent, xCellInterface, makeAny( xCellInterface ) );
261 else
262 xManager->detach( nIndexInParent, xCellInterface );
264 catch( const Exception& )
266 DBG_UNHANDLED_EXCEPTION();
270 //------------------------------------------------------------------------------
271 void DbGridColumn::UpdateFromField(const DbGridRow* pRow, const Reference< XNumberFormatter >& xFormatter)
273 if (m_pCell && m_pCell->ISA(FmXFilterCell))
274 PTR_CAST(FmXFilterCell, m_pCell)->Update();
275 else if (pRow && pRow->IsValid() && m_nFieldPos >= 0 && m_pCell && pRow->HasField(m_nFieldPos))
277 PTR_CAST(FmXDataCell, m_pCell)->UpdateFromField( pRow->GetField( m_nFieldPos ).getColumn(), xFormatter );
281 //------------------------------------------------------------------------------
282 sal_Bool DbGridColumn::Commit()
284 sal_Bool bResult = sal_True;
285 if (!m_bInSave && m_pCell)
287 m_bInSave = sal_True;
288 bResult = m_pCell->Commit();
290 // store the data into the model
291 FmXDataCell* pDataCell = PTR_CAST(FmXDataCell, m_pCell);
292 if (bResult && pDataCell)
294 Reference< ::com::sun::star::form::XBoundComponent > xComp(m_xModel, UNO_QUERY);
295 if (xComp.is())
296 bResult = xComp->commit();
298 m_bInSave = sal_False;
300 return bResult;
303 //------------------------------------------------------------------------------
304 DbGridColumn::~DbGridColumn()
306 Clear();
309 //------------------------------------------------------------------------------
310 void DbGridColumn::setModel(::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > _xModel)
312 if ( m_pCell )
313 impl_toggleScriptManager_nothrow( false );
315 m_xModel = _xModel;
317 if ( m_pCell )
318 impl_toggleScriptManager_nothrow( true );
321 //------------------------------------------------------------------------------
322 void DbGridColumn::Clear()
324 if ( m_pCell )
326 impl_toggleScriptManager_nothrow( false );
328 m_pCell->dispose();
329 m_pCell->release();
330 m_pCell = NULL;
333 m_xController = NULL;
334 m_xField = NULL;
336 m_nFormatKey = 0;
337 m_nFieldPos = -1;
338 m_bReadOnly = sal_True;
339 m_bAutoValue = sal_False;
340 m_nFieldType = DataType::OTHER;
343 //------------------------------------------------------------------------------
344 sal_Int16 DbGridColumn::SetAlignment(sal_Int16 _nAlign)
346 if (_nAlign == -1)
347 { // 'Standard'
348 if (m_xField.is())
350 sal_Int32 nType = 0;
351 m_xField->getPropertyValue(FM_PROP_FIELDTYPE) >>= nType;
353 switch (nType)
355 case DataType::NUMERIC:
356 case DataType::DECIMAL:
357 case DataType::DOUBLE:
358 case DataType::REAL:
359 case DataType::BIGINT:
360 case DataType::INTEGER:
361 case DataType::SMALLINT:
362 case DataType::TINYINT:
363 case DataType::DATE:
364 case DataType::TIME:
365 case DataType::TIMESTAMP:
366 _nAlign = ::com::sun::star::awt::TextAlign::RIGHT;
367 break;
368 case DataType::BIT:
369 case DataType::BOOLEAN:
370 _nAlign = ::com::sun::star::awt::TextAlign::CENTER;
371 break;
372 default:
373 _nAlign = ::com::sun::star::awt::TextAlign::LEFT;
374 break;
377 else
378 _nAlign = ::com::sun::star::awt::TextAlign::LEFT;
381 m_nAlign = _nAlign;
382 if (m_pCell && m_pCell->isAlignedController())
383 m_pCell->AlignControl(m_nAlign);
385 return m_nAlign;
388 //------------------------------------------------------------------------------
389 sal_Int16 DbGridColumn::SetAlignmentFromModel(sal_Int16 nStandardAlign)
391 Any aAlign( m_xModel->getPropertyValue(FM_PROP_ALIGN));
392 if (aAlign.hasValue())
394 sal_Int16 nTest = sal_Int16();
395 if (aAlign >>= nTest)
396 nStandardAlign = nTest;
398 return SetAlignment(nStandardAlign);
401 //------------------------------------------------------------------------------
402 void DbGridColumn::setLock(sal_Bool _bLock)
404 if (m_bLocked == _bLock)
405 return;
406 m_bLocked = _bLock;
408 // is the column we represent active ?
409 if (m_bHidden)
410 return; // no, it isn't (or at least it shouldn't be ...)
412 if (m_rParent.GetCurColumnId() == m_nId)
414 m_rParent.DeactivateCell();
415 m_rParent.ActivateCell(m_rParent.GetCurRow(), m_rParent.GetCurColumnId());
419 //------------------------------------------------------------------------------
420 String DbGridColumn::GetCellText(const DbGridRow* pRow, const Reference< XNumberFormatter >& xFormatter) const
422 String aText;
423 if (m_pCell && m_pCell->ISA(FmXFilterCell))
424 return aText;
426 if (!pRow || !pRow->IsValid())
427 aText = INVALIDTEXT;
428 else if (pRow->HasField(m_nFieldPos))
430 aText = GetCellText( pRow->GetField( m_nFieldPos ).getColumn(), xFormatter );
432 return aText;
435 //------------------------------------------------------------------------------
436 String DbGridColumn::GetCellText(const Reference< ::com::sun::star::sdb::XColumn >& xField, const Reference< XNumberFormatter >& xFormatter) const
438 String aText;
439 if (xField.is())
441 FmXTextCell* pTextCell = PTR_CAST(FmXTextCell, m_pCell);
442 if (pTextCell)
443 aText = pTextCell->GetText(xField, xFormatter);
444 else if (m_bObject)
445 aText = OBJECTTEXT;
447 return aText;
450 //------------------------------------------------------------------------------
451 Reference< ::com::sun::star::sdb::XColumn > DbGridColumn::GetCurrentFieldValue() const
453 Reference< ::com::sun::star::sdb::XColumn > xField;
454 const DbGridRowRef xRow = m_rParent.GetCurrentRow();
455 if (xRow.Is() && xRow->HasField(m_nFieldPos))
457 xField = xRow->GetField(m_nFieldPos).getColumn();
459 return xField;
462 //------------------------------------------------------------------------------
463 void DbGridColumn::Paint(OutputDevice& rDev,
464 const Rectangle& rRect,
465 const DbGridRow* pRow,
466 const Reference< XNumberFormatter >& xFormatter)
468 bool bEnabled = ( rDev.GetOutDevType() != OUTDEV_WINDOW )
469 || ( static_cast< Window& >( rDev ).IsEnabled() );
471 FmXDataCell* pDataCell = PTR_CAST(FmXDataCell, m_pCell);
472 if (pDataCell)
474 if (!pRow || !pRow->IsValid())
476 sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER;
477 if ( !bEnabled )
478 nStyle |= TEXT_DRAW_DISABLE;
480 rDev.DrawText(rRect, INVALIDTEXT, nStyle);
482 else if (m_bAutoValue && pRow->IsNew())
484 static String aAutoText(SVX_RES(RID_STR_AUTOFIELD));
485 sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER;
486 if ( !bEnabled )
487 nStyle |= TEXT_DRAW_DISABLE;
489 switch (GetAlignment())
491 case ::com::sun::star::awt::TextAlign::RIGHT:
492 nStyle |= TEXT_DRAW_RIGHT;
493 break;
494 case ::com::sun::star::awt::TextAlign::CENTER:
495 nStyle |= TEXT_DRAW_CENTER;
496 break;
497 default:
498 nStyle |= TEXT_DRAW_LEFT;
501 rDev.DrawText(rRect, aAutoText , nStyle);
503 else if (pRow->HasField(m_nFieldPos))
505 pDataCell->PaintFieldToCell(rDev, rRect, pRow->GetField( m_nFieldPos ).getColumn(), xFormatter);
508 else if (!m_pCell)
510 if (!pRow || !pRow->IsValid())
512 sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER;
513 if ( !bEnabled )
514 nStyle |= TEXT_DRAW_DISABLE;
516 rDev.DrawText(rRect, INVALIDTEXT, nStyle);
518 else if (pRow->HasField(m_nFieldPos) && m_bObject)
520 sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_CENTER;
521 if ( !bEnabled )
522 nStyle |= TEXT_DRAW_DISABLE;
523 rDev.DrawText(rRect, OBJECTTEXT, nStyle);
526 else if ( m_pCell->ISA( FmXFilterCell ) )
527 static_cast< FmXFilterCell* >( m_pCell )->PaintCell( rDev, rRect );
530 //------------------------------------------------------------------------------
531 void DbGridColumn::ImplInitWindow( Window& rParent, const InitWindowFacet _eInitWhat )
533 if ( m_pCell )
534 m_pCell->ImplInitWindow( rParent, _eInitWhat );
537 //==============================================================================
538 //= cell controls
539 //==============================================================================
540 TYPEINIT0( DbCellControl )
541 TYPEINIT1( DbLimitedLengthField, DbCellControl )
542 TYPEINIT1( DbTextField, DbLimitedLengthField )
543 TYPEINIT1( DbFormattedField, DbLimitedLengthField )
544 TYPEINIT1( DbCheckBox, DbCellControl )
545 TYPEINIT1( DbComboBox, DbCellControl )
546 TYPEINIT1( DbListBox, DbCellControl )
547 TYPEINIT1( DbPatternField, DbCellControl )
548 TYPEINIT1( DbSpinField, DbCellControl )
549 TYPEINIT1( DbDateField, DbSpinField )
550 TYPEINIT1( DbTimeField, DbSpinField )
551 TYPEINIT1( DbCurrencyField, DbSpinField )
552 TYPEINIT1( DbNumericField, DbSpinField )
553 TYPEINIT1( DbFilterField, DbCellControl )
555 //------------------------------------------------------------------------------
556 DbCellControl::DbCellControl( DbGridColumn& _rColumn, sal_Bool /*_bText*/ )
557 :OPropertyChangeListener(m_aMutex)
558 ,m_bTransparent( sal_False )
559 ,m_bAlignedController( sal_True )
560 ,m_bAccessingValueProperty( sal_False )
561 ,m_rColumn( _rColumn )
562 ,m_pPainter( NULL )
563 ,m_pWindow( NULL )
565 Reference< XPropertySet > xColModelProps( _rColumn.getModel(), UNO_QUERY );
566 if ( xColModelProps.is() )
568 // if our model's format key changes we want to propagate the new value to our windows
569 m_pModelChangeBroadcaster = new ::comphelper::OPropertyChangeMultiplexer(this, Reference< ::com::sun::star::beans::XPropertySet > (_rColumn.getModel(), UNO_QUERY));
570 m_pModelChangeBroadcaster->acquire();
572 // be listener for some common properties
573 implDoPropertyListening( FM_PROP_READONLY, sal_False );
574 implDoPropertyListening( FM_PROP_ENABLED, sal_False );
576 // add as listener for all know "value" properties
577 implDoPropertyListening( FM_PROP_VALUE, sal_False );
578 implDoPropertyListening( FM_PROP_STATE, sal_False );
579 implDoPropertyListening( FM_PROP_TEXT, sal_False );
580 implDoPropertyListening( FM_PROP_EFFECTIVE_VALUE, sal_False );
584 //------------------------------------------------------------------------------
585 void DbCellControl::implDoPropertyListening( const ::rtl::OUString& _rPropertyName, sal_Bool _bWarnIfNotExistent )
589 Reference< XPropertySet > xColModelProps( m_rColumn.getModel(), UNO_QUERY );
590 Reference< XPropertySetInfo > xPSI;
591 if ( xColModelProps.is() )
592 xPSI = xColModelProps->getPropertySetInfo();
594 DBG_ASSERT( !_bWarnIfNotExistent || ( xPSI.is() && xPSI->hasPropertyByName( _rPropertyName ) ),
595 "DbCellControl::doPropertyListening: no property set info or non-existent property!" );
596 (void)_bWarnIfNotExistent;
598 if ( xPSI.is() && xPSI->hasPropertyByName( _rPropertyName ) )
599 m_pModelChangeBroadcaster->addProperty( _rPropertyName );
601 catch( const Exception& )
603 DBG_ERROR( "DbCellControl::doPropertyListening: caught an exception!" );
607 //------------------------------------------------------------------------------
608 void DbCellControl::doPropertyListening( const ::rtl::OUString& _rPropertyName )
610 implDoPropertyListening( _rPropertyName );
613 //------------------------------------------------------------------------------
614 DbCellControl::~DbCellControl()
616 if ( m_pModelChangeBroadcaster )
618 m_pModelChangeBroadcaster->dispose();
619 m_pModelChangeBroadcaster->release();
620 m_pModelChangeBroadcaster = NULL;
621 // no delete, this is done implicitly
624 delete m_pWindow;
625 delete m_pPainter;
628 //------------------------------------------------------------------------------
629 void DbCellControl::implValuePropertyChanged( )
631 OSL_ENSURE( !isValuePropertyLocked(),
632 "DbCellControl::implValuePropertyChanged: not to be called with the value property locked!" );
634 if ( m_pWindow )
636 if ( m_rColumn.getModel().is() )
637 updateFromModel( m_rColumn.getModel() );
641 //------------------------------------------------------------------------------
642 void DbCellControl::implAdjustGenericFieldSetting( const Reference< XPropertySet >& /*_rxModel*/ )
644 // nothing to to here
647 //------------------------------------------------------------------------------
648 void DbCellControl::_propertyChanged(const PropertyChangeEvent& _rEvent) throw(RuntimeException)
650 ::vos::OGuard aGuard( Application::GetSolarMutex() );
652 Reference< XPropertySet > xSourceProps( _rEvent.Source, UNO_QUERY );
654 if ( _rEvent.PropertyName.equals( FM_PROP_VALUE )
655 || _rEvent.PropertyName.equals( FM_PROP_STATE )
656 || _rEvent.PropertyName.equals( FM_PROP_TEXT )
657 || _rEvent.PropertyName.equals( FM_PROP_EFFECTIVE_VALUE )
659 { // it was one of the known "value" properties
660 if ( !isValuePropertyLocked() )
662 implValuePropertyChanged( );
665 else if ( _rEvent.PropertyName.equals( FM_PROP_READONLY ) )
667 implAdjustReadOnly( xSourceProps );
669 else if ( _rEvent.PropertyName.equals( FM_PROP_ENABLED ) )
671 implAdjustEnabled( xSourceProps );
673 else
674 implAdjustGenericFieldSetting( xSourceProps );
677 //------------------------------------------------------------------------------
678 sal_Bool DbCellControl::Commit()
680 // lock the listening for value property changes
681 lockValueProperty();
682 // commit the content of the control into the model's value property
683 sal_Bool bReturn = commitControl();
684 // unlock the listening for value property changes
685 unlockValueProperty();
686 // outta here
687 return bReturn;
690 //------------------------------------------------------------------------------
691 void DbCellControl::ImplInitWindow( Window& rParent, const InitWindowFacet _eInitWhat )
693 Window* pWindows[] = { m_pPainter, m_pWindow };
695 if ( ( _eInitWhat & InitWritingMode ) != 0 )
697 for ( size_t i=0; i < sizeof( pWindows ) / sizeof( pWindows[0] ); ++i )
699 if ( pWindows[i] )
700 pWindows[i]->EnableRTL( rParent.IsRTLEnabled() );
704 if ( ( _eInitWhat & InitFont ) != 0 )
706 for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i)
708 if ( !pWindows[i] )
709 continue;
711 pWindows[i]->SetZoom( rParent.GetZoom() );
713 const StyleSettings& rStyleSettings = pWindows[i]->GetSettings().GetStyleSettings();
714 Font aFont = rStyleSettings.GetFieldFont();
715 aFont.SetTransparent( isTransparent() );
717 if ( rParent.IsControlFont() )
719 pWindows[i]->SetControlFont( rParent.GetControlFont() );
720 aFont.Merge( rParent.GetControlFont() );
722 else
723 pWindows[i]->SetControlFont();
725 pWindows[i]->SetZoomedPointFont( aFont );
729 if ( ( ( _eInitWhat & InitFont ) != 0 )
730 || ( ( _eInitWhat & InitForeground ) != 0 )
733 Color aTextColor( rParent.IsControlForeground() ? rParent.GetControlForeground() : rParent.GetTextColor() );
735 sal_Bool bTextLineColor = rParent.IsTextLineColor();
736 Color aTextLineColor( rParent.GetTextLineColor() );
738 for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i)
740 if ( pWindows[i] )
742 pWindows[i]->SetTextColor(aTextColor);
743 if (rParent.IsControlForeground())
744 pWindows[i]->SetControlForeground(aTextColor);
746 if (bTextLineColor)
747 pWindows[i]->SetTextLineColor();
748 else
749 pWindows[i]->SetTextLineColor(aTextLineColor);
754 if ( ( _eInitWhat & InitBackground ) != 0 )
756 if (rParent.IsControlBackground())
758 Color aColor( rParent.GetControlBackground());
759 for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i)
761 if ( pWindows[i] )
763 if ( isTransparent() )
764 pWindows[i]->SetBackground();
765 else
767 pWindows[i]->SetBackground(aColor);
768 pWindows[i]->SetControlBackground(aColor);
770 pWindows[i]->SetFillColor(aColor);
774 else
776 if (m_pPainter)
778 if ( isTransparent() )
779 m_pPainter->SetBackground();
780 else
781 m_pPainter->SetBackground(rParent.GetBackground());
782 m_pPainter->SetFillColor(rParent.GetFillColor());
785 if (m_pWindow)
787 if ( isTransparent() )
788 m_pWindow->SetBackground(rParent.GetBackground());
789 else
790 m_pWindow->SetFillColor(rParent.GetFillColor());
796 //------------------------------------------------------------------------------
797 void DbCellControl::implAdjustReadOnly( const Reference< XPropertySet >& _rxModel )
799 DBG_ASSERT( m_pWindow, "DbCellControl::implAdjustReadOnly: not to be called without window!" );
800 DBG_ASSERT( _rxModel.is(), "DbCellControl::implAdjustReadOnly: invalid model!" );
801 if ( m_pWindow && _rxModel.is() )
803 Edit* pEditWindow = dynamic_cast< Edit* >( m_pWindow );
804 if ( pEditWindow )
806 sal_Bool bReadOnly = sal_True;
807 _rxModel->getPropertyValue( FM_PROP_READONLY ) >>= bReadOnly;
808 static_cast< Edit* >( m_pWindow )->SetReadOnly( m_rColumn.IsReadOnly() || bReadOnly );
813 //------------------------------------------------------------------------------
814 void DbCellControl::implAdjustEnabled( const Reference< XPropertySet >& _rxModel )
816 DBG_ASSERT( m_pWindow, "DbCellControl::implAdjustEnabled: not to be called without window!" );
817 DBG_ASSERT( _rxModel.is(), "DbCellControl::implAdjustEnabled: invalid model!" );
818 if ( m_pWindow && _rxModel.is() )
820 sal_Bool bEnable = sal_True;
821 _rxModel->getPropertyValue( FM_PROP_ENABLED ) >>= bEnable;
822 m_pWindow->Enable( bEnable );
826 //------------------------------------------------------------------------------
827 void DbCellControl::Init( Window& rParent, const Reference< XRowSet >& _rxCursor )
829 ImplInitWindow( rParent, InitAll );
831 if ( m_pWindow )
833 // align the control
834 if ( isAlignedController() )
835 AlignControl( m_rColumn.GetAlignment() );
839 // some other common properties
840 Reference< XPropertySet > xModel( m_rColumn.getModel(), UNO_SET_THROW );
841 Reference< XPropertySetInfo > xModelPSI( xModel->getPropertySetInfo(), UNO_SET_THROW );
843 if ( xModelPSI->hasPropertyByName( FM_PROP_READONLY ) )
845 implAdjustReadOnly( xModel );
848 if ( xModelPSI->hasPropertyByName( FM_PROP_ENABLED ) )
850 implAdjustEnabled( xModel );
853 if ( xModelPSI->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) )
855 sal_Int16 nWheelBehavior = MouseWheelBehavior::SCROLL_FOCUS_ONLY;
856 OSL_VERIFY( xModel->getPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR ) >>= nWheelBehavior );
857 USHORT nVclSetting = MOUSE_WHEEL_FOCUS_ONLY;
858 switch ( nWheelBehavior )
860 case MouseWheelBehavior::SCROLL_DISABLED: nVclSetting = MOUSE_WHEEL_DISABLE; break;
861 case MouseWheelBehavior::SCROLL_FOCUS_ONLY: nVclSetting = MOUSE_WHEEL_FOCUS_ONLY; break;
862 case MouseWheelBehavior::SCROLL_ALWAYS: nVclSetting = MOUSE_WHEEL_ALWAYS; break;
863 default:
864 OSL_ENSURE( false, "DbCellControl::Init: invalid MouseWheelBehavior!" );
865 break;
868 AllSettings aSettings = m_pWindow->GetSettings();
869 MouseSettings aMouseSettings = aSettings.GetMouseSettings();
870 aMouseSettings.SetWheelBehavior( nVclSetting );
871 aSettings.SetMouseSettings( aMouseSettings );
872 m_pWindow->SetSettings( aSettings, TRUE );
875 catch( const Exception& )
877 DBG_UNHANDLED_EXCEPTION();
880 m_xCursor = _rxCursor;
883 //------------------------------------------------------------------------------
884 void DbCellControl::SetTextLineColor()
886 if (m_pWindow)
887 m_pWindow->SetTextLineColor();
888 if (m_pPainter)
889 m_pPainter->SetTextLineColor();
892 //------------------------------------------------------------------------------
893 void DbCellControl::SetTextLineColor(const Color& _rColor)
895 if (m_pWindow)
896 m_pWindow->SetTextLineColor(_rColor);
897 if (m_pPainter)
898 m_pPainter->SetTextLineColor(_rColor);
901 namespace
903 static void lcl_implAlign( Window* _pWindow, WinBits _nAlignmentBit )
905 WinBits nStyle = _pWindow->GetStyle();
906 nStyle &= ~(WB_LEFT | WB_RIGHT | WB_CENTER);
907 _pWindow->SetStyle( nStyle | _nAlignmentBit );
911 //------------------------------------------------------------------------------
912 void DbCellControl::AlignControl(sal_Int16 nAlignment)
914 WinBits nAlignmentBit = 0;
915 switch (nAlignment)
917 case ::com::sun::star::awt::TextAlign::RIGHT:
918 nAlignmentBit = WB_RIGHT;
919 break;
920 case ::com::sun::star::awt::TextAlign::CENTER:
921 nAlignmentBit = WB_CENTER;
922 break;
923 default:
924 nAlignmentBit = WB_LEFT;
925 break;
927 lcl_implAlign( m_pWindow, nAlignmentBit );
928 if ( m_pPainter )
929 lcl_implAlign( m_pPainter, nAlignmentBit );
932 //------------------------------------------------------------------------------
933 void DbCellControl::PaintCell( OutputDevice& _rDev, const Rectangle& _rRect )
935 if ( m_pPainter->GetParent() == &_rDev )
937 m_pPainter->SetPaintTransparent( sal_True );
938 m_pPainter->SetBackground( );
939 m_pPainter->SetControlBackground( _rDev.GetFillColor() );
940 m_pPainter->SetControlForeground( _rDev.GetTextColor() );
941 m_pPainter->SetTextColor( _rDev.GetTextColor() );
942 m_pPainter->SetTextFillColor( _rDev.GetTextColor() );
944 Font aFont( _rDev.GetFont() );
945 aFont.SetTransparent( TRUE );
946 m_pPainter->SetFont( aFont );
948 m_pPainter->SetPosSizePixel( _rRect.TopLeft(), _rRect.GetSize() );
949 m_pPainter->Show();
950 m_pPainter->Update();
951 m_pPainter->SetParentUpdateMode( sal_False );
952 m_pPainter->Hide();
953 m_pPainter->SetParentUpdateMode( sal_True );
955 else
956 m_pPainter->Draw( &_rDev, _rRect.TopLeft(), _rRect.GetSize(), 0 );
959 //------------------------------------------------------------------------------
960 void DbCellControl::PaintFieldToCell( OutputDevice& _rDev, const Rectangle& _rRect, const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
962 m_pPainter->SetText( GetFormatText( _rxField, _rxFormatter ) );
963 PaintCell( _rDev, _rRect );
966 //------------------------------------------------------------------------------
967 double DbCellControl::GetValue(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) const
969 double fValue = 0;
970 if (m_rColumn.IsNumeric())
974 fValue = _rxField->getDouble();
976 catch(const Exception&) { }
978 else
980 sal_Bool bSuccess = sal_False;
983 fValue = _rxField->getDouble();
984 bSuccess = sal_True;
986 catch(const Exception&) { }
987 if (!bSuccess)
991 fValue = xFormatter->convertStringToNumber(m_rColumn.GetKey(), _rxField->getString());
993 catch(const Exception&) { }
996 return fValue;
999 //------------------------------------------------------------------------------
1000 void DbCellControl::invalidatedController()
1002 m_rColumn.GetParent().refreshController(m_rColumn.GetId(), DbGridControl::GrantCellControlAccess());
1005 /*************************************************************************/
1006 // CellModels
1007 /*************************************************************************/
1009 //==============================================================================
1010 //= DbLimitedLengthField
1011 //==============================================================================
1012 //------------------------------------------------------------------------------
1013 DbLimitedLengthField::DbLimitedLengthField( DbGridColumn& _rColumn )
1014 :DbCellControl( _rColumn )
1016 doPropertyListening( FM_PROP_MAXTEXTLEN );
1019 //------------------------------------------------------------------------------
1020 void DbLimitedLengthField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
1022 DBG_ASSERT( m_pWindow, "DbLimitedLengthField::implAdjustGenericFieldSetting: not to be called without window!" );
1023 DBG_ASSERT( _rxModel.is(), "DbLimitedLengthField::implAdjustGenericFieldSetting: invalid model!" );
1024 if ( m_pWindow && _rxModel.is() )
1026 sal_Int16 nMaxLen = 0;
1027 _rxModel->getPropertyValue( FM_PROP_MAXTEXTLEN ) >>= nMaxLen;
1028 implSetMaxTextLen( nMaxLen );
1032 //------------------------------------------------------------------------------
1033 void DbLimitedLengthField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen )
1035 dynamic_cast< Edit* >( m_pWindow )->SetMaxTextLen( _nMaxLen );
1036 if ( m_pPainter )
1037 dynamic_cast< Edit* >( m_pPainter )->SetMaxTextLen( _nMaxLen );
1040 //==============================================================================
1041 //= DbTextField
1042 //==============================================================================
1043 //------------------------------------------------------------------------------
1044 DbTextField::DbTextField(DbGridColumn& _rColumn)
1045 :DbLimitedLengthField(_rColumn)
1046 ,m_pEdit( NULL )
1047 ,m_pPainterImplementation( NULL )
1048 ,m_nKeyType(::com::sun::star::util::NumberFormat::TEXT)
1049 ,m_bIsSimpleEdit( sal_True )
1053 //------------------------------------------------------------------------------
1054 DbTextField::~DbTextField( )
1056 DELETEZ( m_pPainterImplementation );
1057 DELETEZ( m_pEdit );
1060 //------------------------------------------------------------------------------
1061 void DbTextField::Init( Window& rParent, const Reference< XRowSet >& xCursor)
1063 sal_Int16 nAlignment = m_rColumn.SetAlignmentFromModel(-1);
1065 Reference< XPropertySet > xModel( m_rColumn.getModel() );
1067 WinBits nStyle = WB_LEFT;
1068 switch (nAlignment)
1070 case awt::TextAlign::RIGHT:
1071 nStyle = WB_RIGHT;
1072 break;
1074 case awt::TextAlign::CENTER:
1075 nStyle = WB_CENTER;
1076 break;
1079 // is this a multi-line field?
1080 sal_Bool bIsMultiLine = sal_False;
1083 if ( xModel.is() )
1085 OSL_VERIFY( xModel->getPropertyValue( FM_PROP_MULTILINE ) >>= bIsMultiLine );
1088 catch( const Exception& )
1090 OSL_ENSURE( sal_False, "DbTextField::Init: caught an exception while determining the multi-line capabilities!" );
1093 m_bIsSimpleEdit = !bIsMultiLine;
1094 if ( bIsMultiLine )
1096 m_pWindow = new MultiLineTextCell( &rParent, nStyle );
1097 m_pEdit = new MultiLineEditImplementation( *static_cast< MultiLineTextCell* >( m_pWindow ) );
1099 m_pPainter = new MultiLineTextCell( &rParent, nStyle );
1100 m_pPainterImplementation = new MultiLineEditImplementation( *static_cast< MultiLineTextCell* >( m_pPainter ) );
1102 else
1104 m_pWindow = new Edit( &rParent, nStyle );
1105 m_pEdit = new EditImplementation( *static_cast< Edit* >( m_pWindow ) );
1107 m_pPainter = new Edit( &rParent, nStyle );
1108 m_pPainterImplementation = new EditImplementation( *static_cast< Edit* >( m_pPainter ) );
1111 if ( WB_LEFT == nStyle )
1113 // this is so that when getting the focus, the selection is oriented left-to-right
1114 AllSettings aSettings = m_pWindow->GetSettings();
1115 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1116 aStyleSettings.SetSelectionOptions(
1117 aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
1118 aSettings.SetStyleSettings(aStyleSettings);
1119 m_pWindow->SetSettings(aSettings);
1122 implAdjustGenericFieldSetting( xModel );
1124 if (m_rColumn.GetParent().getNumberFormatter().is() && m_rColumn.GetKey())
1125 m_nKeyType = comphelper::getNumberFormatType(m_rColumn.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn.GetKey());
1127 DbLimitedLengthField::Init( rParent, xCursor );
1130 //------------------------------------------------------------------------------
1131 CellControllerRef DbTextField::CreateController() const
1133 return new EditCellController( m_pEdit );
1136 //------------------------------------------------------------------------------
1137 void DbTextField::PaintFieldToCell( OutputDevice& _rDev, const Rectangle& _rRect, const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
1139 if ( m_pPainterImplementation )
1140 m_pPainterImplementation->SetText( GetFormatText( _rxField, _rxFormatter, NULL ) );
1142 DbLimitedLengthField::PaintFieldToCell( _rDev, _rRect, _rxField, _rxFormatter );
1145 //------------------------------------------------------------------------------
1146 String DbTextField::GetFormatText(const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter, Color** /*ppColor*/)
1148 ::rtl::OUString aString;
1149 if ( _rxField.is() )
1152 aString = getValue( _rxField, xFormatter, m_rColumn.GetParent().getNullDate(), m_rColumn.GetKey(), m_nKeyType);
1154 catch( const Exception& )
1156 DBG_UNHANDLED_EXCEPTION();
1159 return aString;
1162 //------------------------------------------------------------------------------
1163 void DbTextField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter)
1165 m_pEdit->SetText( GetFormatText( _rxField, xFormatter ) );
1166 m_pEdit->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1169 //------------------------------------------------------------------------------
1170 void DbTextField::updateFromModel( Reference< XPropertySet > _rxModel )
1172 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbTextField::updateFromModel: invalid call!" );
1174 ::rtl::OUString sText;
1175 _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText;
1177 xub_StrLen nMaxTextLen = m_pEdit->GetMaxTextLen();
1178 if ( EDIT_NOLIMIT != nMaxTextLen && sText.getLength() > nMaxTextLen )
1180 sal_Int32 nDiff = sText.getLength() - nMaxTextLen;
1181 sText = sText.replaceAt(sText.getLength() - nDiff,nDiff,::rtl::OUString());
1185 m_pEdit->SetText( sText );
1186 m_pEdit->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1189 //------------------------------------------------------------------------------
1190 sal_Bool DbTextField::commitControl()
1192 ::rtl::OUString aText( m_pEdit->GetText( getModelLineEndSetting( m_rColumn.getModel() ) ) );
1193 // we have to check if the length before we can decide if the value was modified
1194 xub_StrLen nMaxTextLen = m_pEdit->GetMaxTextLen();
1195 if ( EDIT_NOLIMIT != nMaxTextLen )
1197 ::rtl::OUString sOldValue;
1198 m_rColumn.getModel()->getPropertyValue( FM_PROP_TEXT ) >>= sOldValue;
1199 // if the new value didn't change we must set the old long value again
1200 if ( sOldValue.getLength() > nMaxTextLen && sOldValue.compareTo(aText,nMaxTextLen) == 0 )
1201 aText = sOldValue;
1203 m_rColumn.getModel()->setPropertyValue( FM_PROP_TEXT, makeAny( aText ) );
1204 return sal_True;
1207 //------------------------------------------------------------------------------
1208 void DbTextField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen )
1210 if ( m_pEdit )
1211 m_pEdit->SetMaxTextLen( _nMaxLen );
1212 if ( m_pPainterImplementation )
1213 m_pPainterImplementation->SetMaxTextLen( _nMaxLen );
1216 //==============================================================================
1217 //= DbFormattedField
1218 //==============================================================================
1219 DBG_NAME(DbFormattedField);
1220 //------------------------------------------------------------------------------
1221 DbFormattedField::DbFormattedField(DbGridColumn& _rColumn)
1222 :DbLimitedLengthField(_rColumn)
1223 ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED)
1225 DBG_CTOR(DbFormattedField,NULL);
1227 // if our model's format key changes we want to propagate the new value to our windows
1228 doPropertyListening( FM_PROP_FORMATKEY );
1231 //------------------------------------------------------------------------------
1232 DbFormattedField::~DbFormattedField()
1234 DBG_DTOR(DbFormattedField,NULL);
1237 //------------------------------------------------------------------------------
1238 void DbFormattedField::Init( Window& rParent, const Reference< XRowSet >& xCursor)
1240 sal_Int16 nAlignment = m_rColumn.SetAlignmentFromModel(-1);
1242 Reference< ::com::sun::star::beans::XPropertySet > xUnoModel = m_rColumn.getModel();
1244 switch (nAlignment)
1246 case ::com::sun::star::awt::TextAlign::RIGHT:
1247 m_pWindow = new FormattedField( &rParent, WB_RIGHT );
1248 m_pPainter = new FormattedField( &rParent, WB_RIGHT );
1249 break;
1251 case ::com::sun::star::awt::TextAlign::CENTER:
1252 m_pWindow = new FormattedField( &rParent, WB_CENTER );
1253 m_pPainter = new FormattedField( &rParent, WB_CENTER );
1254 break;
1255 default:
1256 m_pWindow = new FormattedField( &rParent, WB_LEFT );
1257 m_pPainter = new FormattedField( &rParent, WB_LEFT );
1259 // Alles nur damit die Selektion bei Focuserhalt von rechts nach links geht
1260 AllSettings aSettings = m_pWindow->GetSettings();
1261 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1262 aStyleSettings.SetSelectionOptions(
1263 aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
1264 aSettings.SetStyleSettings(aStyleSettings);
1265 m_pWindow->SetSettings(aSettings);
1268 implAdjustGenericFieldSetting( xUnoModel );
1270 static_cast< FormattedField* >( m_pWindow )->SetStrictFormat( sal_False );
1271 static_cast< FormattedField* >( m_pPainter )->SetStrictFormat( sal_False );
1272 // wenn man _irgendeine_ Formatierung zulaesst, kann man da sowieso keine Eingabe-Ueberpruefung
1273 // machen (das FormattedField unterstuetzt das sowieso nicht, nur abgeleitete Klassen)
1275 // von dem Uno-Model den Formatter besorgen
1276 // (Ich koennte theoretisch auch ueber den ::com::sun::star::util::NumberFormatter gehen, den mir der Cursor bestimmt
1277 // liefern wuerde. Das Problem dabei ist, dass ich mich eigentlich nicht darauf verlassen
1278 // kann, dass die beiden Formatter die selben sind, sauber ist das Ganze, wenn ich ueber das
1279 // UNO-Model gehe.)
1280 sal_Int32 nFormatKey = -1;
1282 // mal sehen, ob das Model einen hat ...
1283 DBG_ASSERT(::comphelper::hasProperty(FM_PROP_FORMATSSUPPLIER, xUnoModel), "DbFormattedField::Init : invalid UNO model !");
1284 Any aSupplier( xUnoModel->getPropertyValue(FM_PROP_FORMATSSUPPLIER));
1285 if (aSupplier.hasValue())
1287 ::cppu::extractInterface(m_xSupplier, aSupplier);
1288 if (m_xSupplier.is())
1290 // wenn wir den Supplier vom Model nehmen, dann auch den Key
1291 Any aFmtKey( xUnoModel->getPropertyValue(FM_PROP_FORMATKEY));
1292 if (aFmtKey.hasValue())
1294 DBG_ASSERT(aFmtKey.getValueType().getTypeClass() == TypeClass_LONG, "DbFormattedField::Init : invalid format key property (no sal_Int32) !");
1295 nFormatKey = ::comphelper::getINT32(aFmtKey);
1297 else
1299 DBG_WARNING("DbFormattedField::Init : my uno-model has no format-key, but a formats supplier !");
1300 // the OFormattedModel which we usually are working with ensures that the model has a format key
1301 // as soon as the form is loaded. Unfortunally this method here is called from within loaded, too.
1302 // So if our LoadListener is called before the LoadListener of the model, this "else case" is
1303 // allowed.
1304 // Of course our property listener for the FormatKey property will notify us if the prop is changed,
1305 // so this here isn't really bad ....
1306 nFormatKey = 0;
1311 // nein ? vielleicht die ::com::sun::star::form::component::Form hinter dem Cursor ?
1312 if (!m_xSupplier.is())
1314 Reference< XRowSet > xCursorForm(xCursor, UNO_QUERY);
1315 if (xCursorForm.is())
1316 { // wenn wir vom Cursor den Formatter nehmen, dann auch den Key vom Feld, an das wir gebunden sind
1317 m_xSupplier = getNumberFormats(getRowSetConnection(xCursorForm), sal_False);
1319 if (m_rColumn.GetField().is())
1320 nFormatKey = ::comphelper::getINT32(m_rColumn.GetField()->getPropertyValue(FM_PROP_FORMATKEY));
1324 SvNumberFormatter* pFormatterUsed = NULL;
1325 if (m_xSupplier.is())
1327 SvNumberFormatsSupplierObj* pImplmentation = SvNumberFormatsSupplierObj::getImplementation(m_xSupplier);
1328 if (pImplmentation)
1329 pFormatterUsed = pImplmentation->GetNumberFormatter();
1330 else
1331 // alles hingfaellig : der Supplier ist vom falschen Typ, dann koennen wir uns auch nicht darauf verlassen, dass
1332 // ein Standard-Formatter den (eventuell nicht-Standard-)Key kennt.
1333 nFormatKey = -1;
1336 // einen Standard-Formatter ...
1337 if (pFormatterUsed == NULL)
1339 pFormatterUsed = ((FormattedField*)m_pWindow)->StandardFormatter();
1340 DBG_ASSERT(pFormatterUsed != NULL, "DbFormattedField::Init : no standard formatter given by the numeric field !");
1342 // ... und einen Standard-Key
1343 if (nFormatKey == -1)
1344 nFormatKey = 0;
1346 m_nKeyType = comphelper::getNumberFormatType(m_xSupplier->getNumberFormats(), nFormatKey);
1348 ((FormattedField*)m_pWindow)->SetFormatter(pFormatterUsed);
1349 ((FormattedField*)m_pPainter)->SetFormatter(pFormatterUsed);
1351 ((FormattedField*)m_pWindow)->SetFormatKey(nFormatKey);
1352 ((FormattedField*)m_pPainter)->SetFormatKey(nFormatKey);
1354 ((FormattedField*)m_pWindow)->TreatAsNumber(m_rColumn.IsNumeric());
1355 ((FormattedField*)m_pPainter)->TreatAsNumber(m_rColumn.IsNumeric());
1357 // Min- und Max-Werte
1358 if (m_rColumn.IsNumeric())
1360 sal_Bool bClearMin = sal_True;
1361 if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MIN, xUnoModel))
1363 Any aMin( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_MIN));
1364 if (aMin.getValueType().getTypeClass() != TypeClass_VOID)
1366 DBG_ASSERT(aMin.getValueType().getTypeClass() == TypeClass_DOUBLE, "DbFormattedField::Init : the model has an invalid min value !");
1367 double dMin = ::comphelper::getDouble(aMin);
1368 ((FormattedField*)m_pWindow)->SetMinValue(dMin);
1369 ((FormattedField*)m_pPainter)->SetMinValue(dMin);
1370 bClearMin = sal_False;
1373 if (bClearMin)
1375 ((FormattedField*)m_pWindow)->ClearMinValue();
1376 ((FormattedField*)m_pPainter)->ClearMinValue();
1378 sal_Bool bClearMax = sal_True;
1379 if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MAX, xUnoModel))
1381 Any aMin( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_MAX));
1382 if (aMin.getValueType().getTypeClass() != TypeClass_VOID)
1384 DBG_ASSERT(aMin.getValueType().getTypeClass() == TypeClass_DOUBLE, "DbFormattedField::Init : the model has an invalid max value !");
1385 double dMin = ::comphelper::getDouble(aMin);
1386 ((FormattedField*)m_pWindow)->SetMaxValue(dMin);
1387 ((FormattedField*)m_pPainter)->SetMaxValue(dMin);
1388 bClearMax = sal_False;
1391 if (bClearMax)
1393 ((FormattedField*)m_pWindow)->ClearMaxValue();
1394 ((FormattedField*)m_pPainter)->ClearMaxValue();
1398 // den Default-Wert
1399 Any aDefault( xUnoModel->getPropertyValue(FM_PROP_EFFECTIVE_DEFAULT));
1400 if (aDefault.hasValue())
1401 { // das Ding kann ein double oder ein String sein
1402 switch (aDefault.getValueType().getTypeClass())
1404 case TypeClass_DOUBLE:
1405 if (m_rColumn.IsNumeric())
1407 ((FormattedField*)m_pWindow)->SetDefaultValue(::comphelper::getDouble(aDefault));
1408 ((FormattedField*)m_pPainter)->SetDefaultValue(::comphelper::getDouble(aDefault));
1410 else
1412 String sConverted;
1413 Color* pDummy;
1414 pFormatterUsed->GetOutputString(::comphelper::getDouble(aDefault), 0, sConverted, &pDummy);
1415 ((FormattedField*)m_pWindow)->SetDefaultText(sConverted);
1416 ((FormattedField*)m_pPainter)->SetDefaultText(sConverted);
1418 break;
1419 case TypeClass_STRING:
1421 String sDefault( ::comphelper::getString(aDefault) );
1422 if (m_rColumn.IsNumeric())
1424 double dVal;
1425 sal_uInt32 nTestFormat(0);
1426 if (pFormatterUsed->IsNumberFormat(sDefault, nTestFormat, dVal))
1428 ((FormattedField*)m_pWindow)->SetDefaultValue(dVal);
1429 ((FormattedField*)m_pPainter)->SetDefaultValue(dVal);
1432 else
1434 ((FormattedField*)m_pWindow)->SetDefaultText(sDefault);
1435 ((FormattedField*)m_pPainter)->SetDefaultText(sDefault);
1438 default:
1439 DBG_ERROR( "DbFormattedField::Init: unexpected value type!" );
1440 break;
1443 DbLimitedLengthField::Init( rParent, xCursor );
1446 //------------------------------------------------------------------------------
1447 CellControllerRef DbFormattedField::CreateController() const
1449 return new ::svt::FormattedFieldCellController( static_cast< FormattedField* >( m_pWindow ) );
1452 //------------------------------------------------------------------------------
1453 void DbFormattedField::_propertyChanged( const PropertyChangeEvent& _rEvent ) throw( RuntimeException )
1455 if (_rEvent.PropertyName.compareTo(FM_PROP_FORMATKEY) == COMPARE_EQUAL)
1457 sal_Int32 nNewKey = _rEvent.NewValue.hasValue() ? ::comphelper::getINT32(_rEvent.NewValue) : 0;
1458 m_nKeyType = comphelper::getNumberFormatType(m_xSupplier->getNumberFormats(), nNewKey);
1460 DBG_ASSERT(m_pWindow && m_pPainter, "DbFormattedField::_propertyChanged : where are my windows ?");
1461 if (m_pWindow)
1462 static_cast< FormattedField* >( m_pWindow )->SetFormatKey( nNewKey );
1463 if (m_pPainter)
1464 static_cast< FormattedField* >( m_pPainter )->SetFormatKey( nNewKey );
1466 else
1468 DbLimitedLengthField::_propertyChanged( _rEvent );
1472 //------------------------------------------------------------------------------
1473 String DbFormattedField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** ppColor)
1475 // defaultmaessig keine Farb-Angabe
1476 if (ppColor != NULL)
1477 *ppColor = NULL;
1479 // NULL-Wert -> leerer Text
1480 if (!_rxField.is())
1481 return String();
1483 String aText;
1486 if (m_rColumn.IsNumeric())
1488 // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern
1489 // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an
1490 // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst
1491 // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann
1492 // ich den Rest (die Formatierung) dem FormattedField ueberlassen.
1493 double dValue = getValue(_rxField, m_rColumn.GetParent().getNullDate(), m_nKeyType);
1494 if (_rxField->wasNull())
1495 return aText;
1496 ((FormattedField*)m_pPainter)->SetValue(dValue);
1498 else
1500 // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann.
1501 // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen.
1502 aText = (const sal_Unicode*)_rxField->getString();
1503 if (_rxField->wasNull())
1504 return aText;
1505 ((FormattedField*)m_pPainter)->SetTextFormatted(aText);
1508 catch( const Exception& )
1510 DBG_UNHANDLED_EXCEPTION();
1513 aText = m_pPainter->GetText();
1514 if (ppColor != NULL)
1515 *ppColor = ((FormattedField*)m_pPainter)->GetLastOutputColor();
1517 return aText;
1520 //------------------------------------------------------------------------------
1521 void DbFormattedField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/)
1525 FormattedField* pFormattedWindow = static_cast<FormattedField*>(m_pWindow);
1526 if (!_rxField.is())
1527 { // NULL-Wert -> leerer Text
1528 m_pWindow->SetText(String());
1530 else if (m_rColumn.IsNumeric())
1532 // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern
1533 // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an
1534 // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst
1535 // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann
1536 // ich den Rest (die Formatierung) dem FormattedField ueberlassen.
1537 double dValue = getValue(_rxField, m_rColumn.GetParent().getNullDate(), m_nKeyType);
1538 if (_rxField->wasNull())
1539 m_pWindow->SetText(String());
1540 else
1541 pFormattedWindow->SetValue(dValue);
1543 else
1545 // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann.
1546 // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen.
1547 String sText( _rxField->getString());
1549 pFormattedWindow->SetTextFormatted( sText );
1550 pFormattedWindow->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1553 catch( const Exception& )
1555 DBG_UNHANDLED_EXCEPTION();
1559 //------------------------------------------------------------------------------
1560 void DbFormattedField::updateFromModel( Reference< XPropertySet > _rxModel )
1562 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbFormattedField::updateFromModel: invalid call!" );
1564 FormattedField* pFormattedWindow = static_cast< FormattedField* >( m_pWindow );
1566 ::rtl::OUString sText;
1567 Any aValue = _rxModel->getPropertyValue( FM_PROP_EFFECTIVE_VALUE );
1568 if ( aValue >>= sText )
1569 { // our effective value is transfered as string
1570 pFormattedWindow->SetTextFormatted( sText );
1571 pFormattedWindow->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1573 else
1575 double dValue = 0;
1576 aValue >>= dValue;
1577 pFormattedWindow->SetValue(dValue);
1581 //------------------------------------------------------------------------------
1582 sal_Bool DbFormattedField::commitControl()
1584 Any aNewVal;
1585 FormattedField& rField = *(FormattedField*)m_pWindow;
1586 DBG_ASSERT(&rField == m_pWindow, "DbFormattedField::commitControl : can't work with a window other than my own !");
1587 if (m_rColumn.IsNumeric())
1589 if (rField.GetText().Len() != 0)
1590 aNewVal <<= rField.GetValue();
1591 // ein LeerString wird erst mal standardmaessig als void weitergereicht
1593 else
1594 aNewVal <<= ::rtl::OUString(rField.GetTextValue());
1596 m_rColumn.getModel()->setPropertyValue(FM_PROP_EFFECTIVE_VALUE, aNewVal);
1597 return sal_True;
1600 //==============================================================================
1601 //= DbCheckBox
1602 //==============================================================================
1603 //------------------------------------------------------------------------------
1604 DbCheckBox::DbCheckBox( DbGridColumn& _rColumn )
1605 :DbCellControl( _rColumn, sal_True )
1607 setAlignedController( sal_False );
1610 namespace
1612 void setCheckBoxStyle( Window* _pWindow, USHORT nStyle )
1614 AllSettings aSettings = _pWindow->GetSettings();
1615 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
1616 aStyleSettings.SetCheckBoxStyle( nStyle );
1617 aSettings.SetStyleSettings( aStyleSettings );
1618 _pWindow->SetSettings( aSettings );
1622 //------------------------------------------------------------------------------
1623 void DbCheckBox::Init( Window& rParent, const Reference< XRowSet >& xCursor )
1625 setTransparent( sal_True );
1627 m_pWindow = new CheckBoxControl( &rParent );
1628 m_pPainter = new CheckBoxControl( &rParent );
1630 m_pWindow->SetPaintTransparent( sal_True );
1631 m_pPainter->SetPaintTransparent( sal_True );
1633 m_pPainter->SetBackground();
1637 Reference< XPropertySet > xModel( m_rColumn.getModel(), UNO_SET_THROW );
1639 sal_Int16 nStyle = awt::VisualEffect::LOOK3D;
1640 OSL_VERIFY( xModel->getPropertyValue( FM_PROP_VISUALEFFECT ) >>= nStyle );
1642 setCheckBoxStyle( m_pWindow, nStyle == awt::VisualEffect::FLAT ? STYLE_CHECKBOX_MONO : STYLE_CHECKBOX_WIN );
1643 setCheckBoxStyle( m_pPainter, nStyle == awt::VisualEffect::FLAT ? STYLE_CHECKBOX_MONO : STYLE_CHECKBOX_WIN );
1645 sal_Bool bTristate = sal_True;
1646 OSL_VERIFY( xModel->getPropertyValue( FM_PROP_TRISTATE ) >>= bTristate );
1647 static_cast< CheckBoxControl* >( m_pWindow )->GetBox().EnableTriState( bTristate );
1648 static_cast< CheckBoxControl* >( m_pPainter )->GetBox().EnableTriState( bTristate );
1650 catch( const Exception& )
1652 DBG_UNHANDLED_EXCEPTION();
1655 DbCellControl::Init( rParent, xCursor );
1658 //------------------------------------------------------------------------------
1659 CellControllerRef DbCheckBox::CreateController() const
1661 return new CheckBoxCellController((CheckBoxControl*)m_pWindow);
1663 //------------------------------------------------------------------------------
1664 static void lcl_setCheckBoxState( const Reference< ::com::sun::star::sdb::XColumn >& _rxField,
1665 CheckBoxControl* _pCheckBoxControl )
1667 TriState eState = STATE_DONTKNOW;
1668 if (_rxField.is())
1672 sal_Bool bValue = _rxField->getBoolean();
1673 if (!_rxField->wasNull())
1674 eState = bValue ? STATE_CHECK : STATE_NOCHECK;
1676 catch( const Exception& )
1678 DBG_UNHANDLED_EXCEPTION();
1681 _pCheckBoxControl->GetBox().SetState(eState);
1684 //------------------------------------------------------------------------------
1685 void DbCheckBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/)
1687 lcl_setCheckBoxState( _rxField, static_cast<CheckBoxControl*>(m_pWindow) );
1690 //------------------------------------------------------------------------------
1691 void DbCheckBox::PaintFieldToCell(OutputDevice& rDev, const Rectangle& rRect,
1692 const Reference< ::com::sun::star::sdb::XColumn >& _rxField,
1693 const Reference< XNumberFormatter >& xFormatter)
1695 lcl_setCheckBoxState( _rxField, static_cast<CheckBoxControl*>(m_pPainter) );
1696 DbCellControl::PaintFieldToCell( rDev, rRect, _rxField, xFormatter );
1699 //------------------------------------------------------------------------------
1700 void DbCheckBox::updateFromModel( Reference< XPropertySet > _rxModel )
1702 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbCheckBox::updateFromModel: invalid call!" );
1704 sal_Int16 nState = STATE_DONTKNOW;
1705 _rxModel->getPropertyValue( FM_PROP_STATE ) >>= nState;
1706 static_cast< CheckBoxControl* >( m_pWindow )->GetBox().SetState( static_cast< TriState >( nState ) );
1709 //------------------------------------------------------------------------------
1710 sal_Bool DbCheckBox::commitControl()
1712 #if OSL_DEBUG_LEVEL > 0
1713 Any aVal = makeAny( (sal_Int16)( static_cast< CheckBoxControl* >( m_pWindow )->GetBox().GetState() ) );
1714 #endif
1715 m_rColumn.getModel()->setPropertyValue( FM_PROP_STATE,
1716 makeAny( (sal_Int16)( static_cast< CheckBoxControl* >( m_pWindow )->GetBox().GetState() ) ) );
1717 return sal_True;
1720 //------------------------------------------------------------------------------
1721 XubString DbCheckBox::GetFormatText(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
1723 return XubString();
1726 //==============================================================================
1727 //= DbPatternField
1728 //------------------------------------------------------------------------------
1729 DbPatternField::DbPatternField( DbGridColumn& _rColumn, const ::comphelper::ComponentContext& _rContext )
1730 :DbCellControl( _rColumn )
1731 ,m_aContext( _rContext )
1733 doPropertyListening( FM_PROP_LITERALMASK );
1734 doPropertyListening( FM_PROP_EDITMASK );
1735 doPropertyListening( FM_PROP_STRICTFORMAT );
1738 //------------------------------------------------------------------------------
1739 void DbPatternField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
1741 DBG_ASSERT( m_pWindow, "DbPatternField::implAdjustGenericFieldSetting: not to be called without window!" );
1742 DBG_ASSERT( _rxModel.is(), "DbPatternField::implAdjustGenericFieldSetting: invalid model!" );
1743 if ( m_pWindow && _rxModel.is() )
1745 ::rtl::OUString aLitMask;
1746 ::rtl::OUString aEditMask;
1747 sal_Bool bStrict = sal_False;
1749 _rxModel->getPropertyValue( FM_PROP_LITERALMASK ) >>= aLitMask;
1750 _rxModel->getPropertyValue( FM_PROP_EDITMASK ) >>= aEditMask;
1751 _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) >>= bStrict;
1753 ByteString aAsciiEditMask( aEditMask.getStr(), RTL_TEXTENCODING_ASCII_US );
1755 static_cast< PatternField* >( m_pWindow )->SetMask( aAsciiEditMask, aLitMask );
1756 static_cast< PatternField* >( m_pPainter )->SetMask( aAsciiEditMask, aLitMask );
1757 static_cast< PatternField* >( m_pWindow )->SetStrictFormat( bStrict );
1758 static_cast< PatternField* >( m_pPainter )->SetStrictFormat( bStrict );
1762 //------------------------------------------------------------------------------
1763 void DbPatternField::Init( Window& rParent, const Reference< XRowSet >& xCursor)
1765 m_rColumn.SetAlignmentFromModel(-1);
1767 m_pWindow = new PatternField( &rParent, 0 );
1768 m_pPainter= new PatternField( &rParent, 0 );
1770 Reference< XPropertySet > xModel( m_rColumn.getModel() );
1771 implAdjustGenericFieldSetting( xModel );
1773 DbCellControl::Init( rParent, xCursor );
1776 //------------------------------------------------------------------------------
1777 CellControllerRef DbPatternField::CreateController() const
1779 return new SpinCellController( static_cast< PatternField* >( m_pWindow ) );
1782 //------------------------------------------------------------------------------
1783 String DbPatternField::impl_formatText( const String& _rText )
1785 m_pPainter->SetText( _rText );
1786 static_cast< PatternField* >( m_pPainter )->ReformatAll();
1787 return m_pPainter->GetText();
1790 //------------------------------------------------------------------------------
1791 String DbPatternField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
1793 bool bIsForPaint = _rxField != m_rColumn.GetField();
1794 ::std::auto_ptr< ::dbtools::FormattedColumnValue >& rpFormatter = bIsForPaint ? m_pPaintFormatter : m_pValueFormatter;
1796 if ( !rpFormatter.get() )
1798 DBToolsObjectFactory aFactory;
1799 rpFormatter = aFactory.createFormattedColumnValue(
1800 m_aContext, getCursor(), Reference< XPropertySet >( _rxField, UNO_QUERY ) );
1801 OSL_ENSURE( rpFormatter.get(), "DbPatternField::Init: no value formatter!" );
1803 else
1804 OSL_ENSURE( rpFormatter->getColumn() == _rxField, "DbPatternField::GetFormatText: my value formatter is working for another field ...!" );
1805 // re-creating the value formatter here everytime would be quite expensive ...
1807 String sText;
1808 if ( rpFormatter.get() )
1809 sText = rpFormatter->getFormattedValue();
1811 return impl_formatText( sText );
1814 //------------------------------------------------------------------------------
1815 void DbPatternField::UpdateFromField( const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
1817 static_cast< Edit* >( m_pWindow )->SetText( GetFormatText( _rxField, _rxFormatter ) );
1818 static_cast< Edit* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1821 //------------------------------------------------------------------------------
1822 void DbPatternField::updateFromModel( Reference< XPropertySet > _rxModel )
1824 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbPatternField::updateFromModel: invalid call!" );
1826 ::rtl::OUString sText;
1827 _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText;
1829 static_cast< Edit* >( m_pWindow )->SetText( impl_formatText( sText ) );
1830 static_cast< Edit* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
1833 //------------------------------------------------------------------------------
1834 sal_Bool DbPatternField::commitControl()
1836 String aText(m_pWindow->GetText());
1837 m_rColumn.getModel()->setPropertyValue(FM_PROP_TEXT, makeAny(::rtl::OUString(aText)));
1838 return sal_True;
1841 //==============================================================================
1842 //= DbSpinField
1843 //==============================================================================
1844 //------------------------------------------------------------------------------
1845 DbSpinField::DbSpinField( DbGridColumn& _rColumn, sal_Int16 _nStandardAlign )
1846 :DbCellControl( _rColumn )
1847 ,m_nStandardAlign( _nStandardAlign )
1851 //------------------------------------------------------------------------------
1852 void DbSpinField::Init( Window& _rParent, const Reference< XRowSet >& _rxCursor )
1854 m_rColumn.SetAlignmentFromModel( m_nStandardAlign );
1856 Reference< XPropertySet > xModel( m_rColumn.getModel() );
1858 // determine the WinBits for the field
1859 WinBits nFieldStyle = 0;
1860 if ( ::comphelper::getBOOL( xModel->getPropertyValue( FM_PROP_SPIN ) ) )
1861 nFieldStyle = WB_REPEAT | WB_SPIN;
1862 // create the fields
1863 m_pWindow = createField( &_rParent, nFieldStyle, xModel );
1864 m_pPainter = createField( &_rParent, nFieldStyle, xModel );
1866 // adjust all other settings which depend on the property values
1867 implAdjustGenericFieldSetting( xModel );
1869 // call the base class
1870 DbCellControl::Init( _rParent, _rxCursor );
1873 //------------------------------------------------------------------------------
1874 CellControllerRef DbSpinField::CreateController() const
1876 return new SpinCellController( static_cast< SpinField* >( m_pWindow ) );
1879 //==============================================================================
1880 //= DbNumericField
1881 //==============================================================================
1882 //------------------------------------------------------------------------------
1883 DbNumericField::DbNumericField( DbGridColumn& _rColumn )
1884 :DbSpinField( _rColumn )
1886 doPropertyListening( FM_PROP_DECIMAL_ACCURACY );
1887 doPropertyListening( FM_PROP_VALUEMIN );
1888 doPropertyListening( FM_PROP_VALUEMAX );
1889 doPropertyListening( FM_PROP_VALUESTEP );
1890 doPropertyListening( FM_PROP_STRICTFORMAT );
1891 doPropertyListening( FM_PROP_SHOWTHOUSANDSEP );
1894 //------------------------------------------------------------------------------
1895 void DbNumericField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
1897 DBG_ASSERT( m_pWindow, "DbNumericField::implAdjustGenericFieldSetting: not to be called without window!" );
1898 DBG_ASSERT( _rxModel.is(), "DbNumericField::implAdjustGenericFieldSetting: invalid model!" );
1899 if ( m_pWindow && _rxModel.is() )
1901 sal_Int32 nMin = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMIN ) );
1902 sal_Int32 nMax = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMAX ) );
1903 sal_Int32 nStep = (sal_Int32)getDouble( _rxModel->getPropertyValue( FM_PROP_VALUESTEP ) );
1904 sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) );
1905 sal_Int16 nScale = getINT16( _rxModel->getPropertyValue( FM_PROP_DECIMAL_ACCURACY ) );
1906 sal_Bool bThousand = getBOOL( _rxModel->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP ) );
1908 static_cast< DoubleNumericField* >( m_pWindow )->SetMinValue(nMin);
1909 static_cast< DoubleNumericField* >( m_pWindow )->SetMaxValue(nMax);
1910 static_cast< DoubleNumericField* >( m_pWindow )->SetSpinSize(nStep);
1911 static_cast< DoubleNumericField* >( m_pWindow )->SetStrictFormat(bStrict);
1913 static_cast< DoubleNumericField* >( m_pPainter )->SetMinValue(nMin);
1914 static_cast< DoubleNumericField* >( m_pPainter )->SetMaxValue(nMax);
1915 static_cast< DoubleNumericField* >( m_pPainter )->SetStrictFormat(bStrict);
1918 // dem Field und dem Painter einen Formatter spendieren
1919 // zuerst testen, ob ich von dem Service hinter einer Connection bekommen kann
1920 Reference< ::com::sun::star::util::XNumberFormatsSupplier > xSupplier;
1921 Reference< XRowSet > xForm;
1922 if ( m_rColumn.GetParent().getDataSource() )
1923 xForm = Reference< XRowSet >( ( Reference< XInterface > )*m_rColumn.GetParent().getDataSource(), UNO_QUERY );
1924 if ( xForm.is() )
1925 xSupplier = getNumberFormats( getRowSetConnection( xForm ), sal_True );
1926 SvNumberFormatter* pFormatterUsed = NULL;
1927 if ( xSupplier.is() )
1929 SvNumberFormatsSupplierObj* pImplmentation = SvNumberFormatsSupplierObj::getImplementation( xSupplier );
1930 pFormatterUsed = pImplmentation ? pImplmentation->GetNumberFormatter() : NULL;
1932 if ( NULL == pFormatterUsed )
1933 { // der Cursor fuehrte nicht zum Erfolg -> Standard
1934 pFormatterUsed = static_cast< DoubleNumericField* >( m_pWindow )->StandardFormatter();
1935 DBG_ASSERT( pFormatterUsed != NULL, "DbNumericField::implAdjustGenericFieldSetting: no standard formatter given by the numeric field !" );
1937 static_cast< DoubleNumericField* >( m_pWindow )->SetFormatter( pFormatterUsed );
1938 static_cast< DoubleNumericField* >( m_pPainter )->SetFormatter( pFormatterUsed );
1940 // und dann ein Format generieren, dass die gewuenschten Nachkommastellen usw. hat
1941 String sFormatString;
1942 LanguageType aAppLanguage = Application::GetSettings().GetUILanguage();
1943 pFormatterUsed->GenerateFormat( sFormatString, 0, aAppLanguage, bThousand, sal_False, nScale );
1945 static_cast< DoubleNumericField* >( m_pWindow )->SetFormat( sFormatString, aAppLanguage );
1946 static_cast< DoubleNumericField* >( m_pPainter )->SetFormat( sFormatString, aAppLanguage );
1950 //------------------------------------------------------------------------------
1951 SpinField* DbNumericField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ )
1953 return new DoubleNumericField( _pParent, _nFieldStyle );
1956 namespace
1958 //--------------------------------------------------------------------------
1959 static String lcl_setFormattedNumeric_nothrow( DoubleNumericField& _rField, const DbCellControl& _rControl,
1960 const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
1962 String sValue;
1963 if ( _rxField.is() )
1967 double fValue = _rControl.GetValue( _rxField, _rxFormatter );
1968 if ( !_rxField->wasNull() )
1970 _rField.SetValue( fValue );
1971 sValue = _rField.GetText();
1974 catch( const Exception& )
1976 DBG_UNHANDLED_EXCEPTION();
1979 return sValue;
1983 //------------------------------------------------------------------------------
1984 String DbNumericField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, Color** /*ppColor*/)
1986 return lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField* >( m_pPainter ), *this, _rxField, _rxFormatter );
1989 //------------------------------------------------------------------------------
1990 void DbNumericField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
1992 lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField* >( m_pWindow ), *this, _rxField, _rxFormatter );
1995 //------------------------------------------------------------------------------
1996 void DbNumericField::updateFromModel( Reference< XPropertySet > _rxModel )
1998 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbNumericField::updateFromModel: invalid call!" );
2000 double dValue = 0;
2001 if ( _rxModel->getPropertyValue( FM_PROP_VALUE ) >>= dValue )
2002 static_cast< DoubleNumericField* >( m_pWindow )->SetValue( dValue );
2003 else
2004 m_pWindow->SetText( String() );
2007 //------------------------------------------------------------------------------
2008 sal_Bool DbNumericField::commitControl()
2010 String aText( m_pWindow->GetText());
2011 Any aVal;
2013 if (aText.Len() != 0) // nicht null
2015 double fValue = ((DoubleNumericField*)m_pWindow)->GetValue();
2016 aVal <<= (double)fValue;
2018 m_rColumn.getModel()->setPropertyValue(FM_PROP_VALUE, aVal);
2019 return sal_True;
2022 //==============================================================================
2023 //= DbCurrencyField
2024 //==============================================================================
2025 //------------------------------------------------------------------------------
2026 DbCurrencyField::DbCurrencyField(DbGridColumn& _rColumn)
2027 :DbSpinField( _rColumn )
2028 ,m_nScale( 0 )
2030 doPropertyListening( FM_PROP_DECIMAL_ACCURACY );
2031 doPropertyListening( FM_PROP_VALUEMIN );
2032 doPropertyListening( FM_PROP_VALUEMAX );
2033 doPropertyListening( FM_PROP_VALUESTEP );
2034 doPropertyListening( FM_PROP_STRICTFORMAT );
2035 doPropertyListening( FM_PROP_SHOWTHOUSANDSEP );
2036 doPropertyListening( FM_PROP_CURRENCYSYMBOL );
2039 //------------------------------------------------------------------------------
2040 void DbCurrencyField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2042 DBG_ASSERT( m_pWindow, "DbCurrencyField::implAdjustGenericFieldSetting: not to be called without window!" );
2043 DBG_ASSERT( _rxModel.is(), "DbCurrencyField::implAdjustGenericFieldSetting: invalid model!" );
2044 if ( m_pWindow && _rxModel.is() )
2046 m_nScale = getINT16( _rxModel->getPropertyValue( FM_PROP_DECIMAL_ACCURACY ) );
2047 double nMin = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMIN ) );
2048 double nMax = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUEMAX ) );
2049 double nStep = getDouble( _rxModel->getPropertyValue( FM_PROP_VALUESTEP ) );
2050 sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) );
2051 sal_Bool bThousand = getBOOL( _rxModel->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP ) );
2052 ::rtl::OUString aStr( getString( _rxModel->getPropertyValue(FM_PROP_CURRENCYSYMBOL ) ) );
2054 static_cast< LongCurrencyField* >( m_pWindow )->SetUseThousandSep( bThousand );
2055 static_cast< LongCurrencyField* >( m_pWindow )->SetDecimalDigits( m_nScale );
2056 static_cast< LongCurrencyField* >( m_pWindow )->SetCurrencySymbol( aStr );
2057 static_cast< LongCurrencyField* >( m_pWindow )->SetFirst( nMin );
2058 static_cast< LongCurrencyField* >( m_pWindow )->SetLast( nMax );
2059 static_cast< LongCurrencyField* >( m_pWindow )->SetMin( nMin );
2060 static_cast< LongCurrencyField* >( m_pWindow )->SetMax( nMax );
2061 static_cast< LongCurrencyField* >( m_pWindow )->SetSpinSize( nStep );
2062 static_cast< LongCurrencyField* >( m_pWindow )->SetStrictFormat( bStrict );
2064 static_cast< LongCurrencyField* >( m_pPainter )->SetUseThousandSep( bThousand );
2065 static_cast< LongCurrencyField* >( m_pPainter )->SetDecimalDigits( m_nScale );
2066 static_cast< LongCurrencyField* >( m_pPainter )->SetCurrencySymbol( aStr );
2067 static_cast< LongCurrencyField* >( m_pPainter )->SetFirst( nMin );
2068 static_cast< LongCurrencyField* >( m_pPainter )->SetLast( nMax );
2069 static_cast< LongCurrencyField* >( m_pPainter )->SetMin( nMin );
2070 static_cast< LongCurrencyField* >( m_pPainter )->SetMax( nMax );
2071 static_cast< LongCurrencyField* >( m_pPainter )->SetStrictFormat( bStrict );
2075 //------------------------------------------------------------------------------
2076 SpinField* DbCurrencyField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ )
2078 return new LongCurrencyField( _pParent, _nFieldStyle );
2081 //------------------------------------------------------------------------------
2082 double DbCurrencyField::GetCurrency(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter) const
2084 volatile double fValue = GetValue(_rxField, xFormatter);
2085 if (m_nScale)
2087 // OSL_TRACE("double = %.64f ",fValue);
2088 fValue = ::rtl::math::pow10Exp(fValue, m_nScale);
2089 fValue = ::rtl::math::round(fValue, 0);
2091 return fValue;
2094 namespace
2096 //--------------------------------------------------------------------------
2097 static String lcl_setFormattedCurrency_nothrow( LongCurrencyField& _rField, const DbCurrencyField& _rControl,
2098 const Reference< XColumn >& _rxField, const Reference< XNumberFormatter >& _rxFormatter )
2100 String sValue;
2101 if ( _rxField.is() )
2105 double fValue = _rControl.GetCurrency( _rxField, _rxFormatter );
2106 if ( !_rxField->wasNull() )
2108 _rField.SetValue( fValue );
2109 BigInt aValue = _rField.GetCorrectedValue();
2110 sValue = aValue.GetString();
2111 sValue = _rField.GetText();
2114 catch( const Exception& )
2116 DBG_UNHANDLED_EXCEPTION();
2119 return sValue;
2123 //------------------------------------------------------------------------------
2124 String DbCurrencyField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter, Color** /*ppColor*/)
2126 return lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField* >( m_pPainter ), *this, _rxField, _rxFormatter );
2129 //------------------------------------------------------------------------------
2130 void DbCurrencyField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& _rxFormatter)
2132 lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField* >( m_pWindow ), *this, _rxField, _rxFormatter );
2135 //------------------------------------------------------------------------------
2136 void DbCurrencyField::updateFromModel( Reference< XPropertySet > _rxModel )
2138 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbCurrencyField::updateFromModel: invalid call!" );
2140 double dValue = 0;
2141 if ( _rxModel->getPropertyValue( FM_PROP_VALUE ) >>= dValue )
2143 if ( m_nScale )
2145 dValue = ::rtl::math::pow10Exp( dValue, m_nScale );
2146 dValue = ::rtl::math::round(dValue, 0);
2149 static_cast< LongCurrencyField* >( m_pWindow )->SetValue( dValue );
2151 else
2152 m_pWindow->SetText( String() );
2155 //------------------------------------------------------------------------------
2156 sal_Bool DbCurrencyField::commitControl()
2158 String aText( m_pWindow->GetText());
2159 Any aVal;
2160 if (aText.Len() != 0) // nicht null
2162 volatile double fValue = ((LongCurrencyField*)m_pWindow)->GetValue();
2163 if (m_nScale)
2165 fValue /= ::rtl::math::pow10Exp(1.0, m_nScale);
2166 //fValue = ::rtl::math::round(fValue, m_nScale);
2168 aVal <<= (double)fValue;
2170 m_rColumn.getModel()->setPropertyValue(FM_PROP_VALUE, aVal);
2171 return sal_True;
2174 //==============================================================================
2175 //= DbDateField
2176 //==============================================================================
2177 //------------------------------------------------------------------------------
2178 DbDateField::DbDateField( DbGridColumn& _rColumn )
2179 :DbSpinField( _rColumn )
2181 doPropertyListening( FM_PROP_DATEFORMAT );
2182 doPropertyListening( FM_PROP_DATEMIN );
2183 doPropertyListening( FM_PROP_DATEMAX );
2184 doPropertyListening( FM_PROP_STRICTFORMAT );
2185 doPropertyListening( FM_PROP_DATE_SHOW_CENTURY );
2188 //------------------------------------------------------------------------------
2189 SpinField* DbDateField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& _rxModel )
2191 // check if there is a DropDown property set to TRUE
2192 sal_Bool bDropDown = !hasProperty( FM_PROP_DROPDOWN, _rxModel )
2193 || getBOOL( _rxModel->getPropertyValue( FM_PROP_DROPDOWN ) );
2194 if ( bDropDown )
2195 _nFieldStyle |= WB_DROPDOWN;
2197 CalendarField* pField = new CalendarField( _pParent, _nFieldStyle );
2199 pField->EnableToday();
2200 pField->EnableNone();
2202 return pField;
2205 //------------------------------------------------------------------------------
2206 void DbDateField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2208 DBG_ASSERT( m_pWindow, "DbDateField::implAdjustGenericFieldSetting: not to be called without window!" );
2209 DBG_ASSERT( _rxModel.is(), "DbDateField::implAdjustGenericFieldSetting: invalid model!" );
2210 if ( m_pWindow && _rxModel.is() )
2212 sal_Int16 nFormat = getINT16( _rxModel->getPropertyValue( FM_PROP_DATEFORMAT ) );
2213 sal_Int32 nMin = getINT32( _rxModel->getPropertyValue( FM_PROP_DATEMIN ) );
2214 sal_Int32 nMax = getINT32( _rxModel->getPropertyValue( FM_PROP_DATEMAX ) );
2215 sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) );
2217 Any aCentury = _rxModel->getPropertyValue( FM_PROP_DATE_SHOW_CENTURY );
2218 if ( aCentury.getValueType().getTypeClass() != TypeClass_VOID )
2220 sal_Bool bShowDateCentury = getBOOL( aCentury );
2222 static_cast<DateField*>( m_pWindow )->SetShowDateCentury( bShowDateCentury );
2223 static_cast<DateField*>( m_pPainter )->SetShowDateCentury( bShowDateCentury );
2226 static_cast< DateField* >( m_pWindow )->SetExtDateFormat( (ExtDateFieldFormat)nFormat );
2227 static_cast< DateField* >( m_pWindow )->SetMin( nMin );
2228 static_cast< DateField* >( m_pWindow )->SetMax( nMax );
2229 static_cast< DateField* >( m_pWindow )->SetStrictFormat( bStrict );
2230 static_cast< DateField* >( m_pWindow )->EnableEmptyFieldValue( TRUE );
2232 static_cast< DateField* >( m_pPainter )->SetExtDateFormat( (ExtDateFieldFormat)nFormat );
2233 static_cast< DateField* >( m_pPainter )->SetMin( nMin );
2234 static_cast< DateField* >( m_pPainter )->SetMax( nMax );
2235 static_cast< DateField* >( m_pPainter )->SetStrictFormat( bStrict );
2236 static_cast< DateField* >( m_pPainter )->EnableEmptyFieldValue( TRUE );
2240 namespace
2242 //--------------------------------------------------------------------------
2243 static String lcl_setFormattedDate_nothrow( DateField& _rField, const Reference< XColumn >& _rxField )
2245 String sDate;
2246 if ( _rxField.is() )
2250 ::com::sun::star::util::Date aValue = _rxField->getDate();
2251 if ( _rxField->wasNull() )
2252 _rField.SetText( sDate );
2253 else
2255 _rField.SetDate( ::Date( aValue.Day, aValue.Month, aValue.Year ) );
2256 sDate = _rField.GetText();
2259 catch( const Exception& )
2261 DBG_UNHANDLED_EXCEPTION();
2264 return sDate;
2267 //------------------------------------------------------------------------------
2268 String DbDateField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
2270 return lcl_setFormattedDate_nothrow( *dynamic_cast< DateField* >( m_pPainter ), _rxField );
2273 //------------------------------------------------------------------------------
2274 void DbDateField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/)
2276 lcl_setFormattedDate_nothrow( *dynamic_cast< DateField* >( m_pWindow ), _rxField );
2279 //------------------------------------------------------------------------------
2280 void DbDateField::updateFromModel( Reference< XPropertySet > _rxModel )
2282 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbDateField::updateFromModel: invalid call!" );
2284 sal_Int32 nDate = 0;
2285 if ( _rxModel->getPropertyValue( FM_PROP_DATE ) >>= nDate )
2286 static_cast< DateField* >( m_pWindow )->SetDate( ::Date( nDate ) );
2287 else
2288 static_cast< DateField* >( m_pWindow )->SetText( String() );
2291 //------------------------------------------------------------------------------
2292 sal_Bool DbDateField::commitControl()
2294 String aText( m_pWindow->GetText());
2295 Any aVal;
2296 if (aText.Len() != 0)
2297 aVal <<= (sal_Int32)static_cast<DateField*>(m_pWindow)->GetDate().GetDate();
2298 else
2299 aVal.clear();
2301 m_rColumn.getModel()->setPropertyValue(FM_PROP_DATE, aVal);
2302 return sal_True;
2305 //==============================================================================
2306 //= DbTimeField
2307 //==============================================================================
2308 //------------------------------------------------------------------------------
2309 DbTimeField::DbTimeField( DbGridColumn& _rColumn )
2310 :DbSpinField( _rColumn, ::com::sun::star::awt::TextAlign::LEFT )
2312 doPropertyListening( FM_PROP_TIMEFORMAT );
2313 doPropertyListening( FM_PROP_TIMEMIN );
2314 doPropertyListening( FM_PROP_TIMEMAX );
2315 doPropertyListening( FM_PROP_STRICTFORMAT );
2318 //------------------------------------------------------------------------------
2319 SpinField* DbTimeField::createField( Window* _pParent, WinBits _nFieldStyle, const Reference< XPropertySet >& /*_rxModel*/ )
2321 return new TimeField( _pParent, _nFieldStyle );
2324 //------------------------------------------------------------------------------
2325 void DbTimeField::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2327 DBG_ASSERT( m_pWindow, "DbTimeField::implAdjustGenericFieldSetting: not to be called without window!" );
2328 DBG_ASSERT( _rxModel.is(), "DbTimeField::implAdjustGenericFieldSetting: invalid model!" );
2329 if ( m_pWindow && _rxModel.is() )
2331 sal_Int16 nFormat = getINT16( _rxModel->getPropertyValue( FM_PROP_TIMEFORMAT ) );
2332 sal_Int32 nMin = getINT32( _rxModel->getPropertyValue( FM_PROP_TIMEMIN ) );
2333 sal_Int32 nMax = getINT32( _rxModel->getPropertyValue( FM_PROP_TIMEMAX ) );
2334 sal_Bool bStrict = getBOOL( _rxModel->getPropertyValue( FM_PROP_STRICTFORMAT ) );
2336 static_cast< TimeField* >( m_pWindow )->SetExtFormat( (ExtTimeFieldFormat)nFormat );
2337 static_cast< TimeField* >( m_pWindow )->SetMin( nMin );
2338 static_cast< TimeField* >( m_pWindow )->SetMax( nMax );
2339 static_cast< TimeField* >( m_pWindow )->SetStrictFormat( bStrict );
2340 static_cast< TimeField* >( m_pWindow )->EnableEmptyFieldValue( TRUE );
2342 static_cast< TimeField* >( m_pPainter )->SetExtFormat( (ExtTimeFieldFormat)nFormat );
2343 static_cast< TimeField* >( m_pPainter )->SetMin( nMin );
2344 static_cast< TimeField* >( m_pPainter )->SetMax( nMax );
2345 static_cast< TimeField* >( m_pPainter )->SetStrictFormat( bStrict );
2346 static_cast< TimeField* >( m_pPainter )->EnableEmptyFieldValue( TRUE );
2350 namespace
2352 //--------------------------------------------------------------------------
2353 static String lcl_setFormattedTime_nothrow( TimeField& _rField, const Reference< XColumn >& _rxField )
2355 String sTime;
2356 if ( _rxField.is() )
2360 ::com::sun::star::util::Time aValue = _rxField->getTime();
2361 if ( _rxField->wasNull() )
2362 _rField.SetText( sTime );
2363 else
2365 _rField.SetTime( ::Time( aValue.Hours, aValue.Minutes, aValue.Seconds, aValue.HundredthSeconds ) );
2366 sTime = _rField.GetText();
2369 catch( const Exception& )
2371 DBG_UNHANDLED_EXCEPTION();
2374 return sTime;
2377 //------------------------------------------------------------------------------
2378 String DbTimeField::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< ::com::sun::star::util::XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
2380 return lcl_setFormattedTime_nothrow( *static_cast< TimeField* >( m_pPainter ), _rxField );
2383 //------------------------------------------------------------------------------
2384 void DbTimeField::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/)
2386 lcl_setFormattedTime_nothrow( *static_cast< TimeField* >( m_pWindow ), _rxField );
2389 //------------------------------------------------------------------------------
2390 void DbTimeField::updateFromModel( Reference< XPropertySet > _rxModel )
2392 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbTimeField::updateFromModel: invalid call!" );
2394 sal_Int32 nTime = 0;
2395 if ( _rxModel->getPropertyValue( FM_PROP_DATE ) >>= nTime )
2396 static_cast< TimeField* >( m_pWindow )->SetTime( ::Time( nTime ) );
2397 else
2398 static_cast< TimeField* >( m_pWindow )->SetText( String() );
2401 //------------------------------------------------------------------------------
2402 sal_Bool DbTimeField::commitControl()
2404 String aText( m_pWindow->GetText());
2405 Any aVal;
2406 if (aText.Len() != 0)
2407 aVal <<= (sal_Int32)static_cast<TimeField*>(m_pWindow)->GetTime().GetTime();
2408 else
2409 aVal.clear();
2411 m_rColumn.getModel()->setPropertyValue(FM_PROP_TIME, aVal);
2412 return sal_True;
2415 //==============================================================================
2416 //= DbComboBox
2417 //==============================================================================
2418 //------------------------------------------------------------------------------
2419 DbComboBox::DbComboBox(DbGridColumn& _rColumn)
2420 :DbCellControl(_rColumn)
2421 ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED)
2423 setAlignedController( sal_False );
2425 doPropertyListening( FM_PROP_STRINGITEMLIST );
2426 doPropertyListening( FM_PROP_LINECOUNT );
2429 //------------------------------------------------------------------------------
2430 void DbComboBox::_propertyChanged( const PropertyChangeEvent& _rEvent ) throw( RuntimeException )
2432 if ( _rEvent.PropertyName.equals( FM_PROP_STRINGITEMLIST ) )
2434 SetList(_rEvent.NewValue);
2436 else
2438 DbCellControl::_propertyChanged( _rEvent ) ;
2442 //------------------------------------------------------------------------------
2443 void DbComboBox::SetList(const Any& rItems)
2445 ComboBoxControl* pField = (ComboBoxControl*)m_pWindow;
2446 pField->Clear();
2448 ::comphelper::StringSequence aTest;
2449 if (rItems >>= aTest)
2451 const ::rtl::OUString* pStrings = aTest.getConstArray();
2452 sal_Int32 nItems = aTest.getLength();
2453 for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings )
2454 pField->InsertEntry(*pStrings, LISTBOX_APPEND);
2456 // tell the grid control that this controller is invalid and has to be re-initialized
2457 invalidatedController();
2461 //------------------------------------------------------------------------------
2462 void DbComboBox::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2464 DBG_ASSERT( m_pWindow, "DbComboBox::implAdjustGenericFieldSetting: not to be called without window!" );
2465 DBG_ASSERT( _rxModel.is(), "DbComboBox::implAdjustGenericFieldSetting: invalid model!" );
2466 if ( m_pWindow && _rxModel.is() )
2468 sal_Int16 nLines = getINT16( _rxModel->getPropertyValue( FM_PROP_LINECOUNT ) );
2469 static_cast< ComboBoxControl* >( m_pWindow )->SetDropDownLineCount( nLines );
2473 //------------------------------------------------------------------------------
2474 void DbComboBox::Init( Window& rParent, const Reference< XRowSet >& xCursor )
2476 m_rColumn.SetAlignmentFromModel(::com::sun::star::awt::TextAlign::LEFT);
2478 m_pWindow = new ComboBoxControl( &rParent );
2480 // selection von rechts nach links
2481 AllSettings aSettings = m_pWindow->GetSettings();
2482 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
2483 aStyleSettings.SetSelectionOptions(
2484 aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
2485 aSettings.SetStyleSettings(aStyleSettings);
2486 m_pWindow->SetSettings(aSettings, sal_True);
2488 // some initial properties
2489 Reference< XPropertySet > xModel(m_rColumn.getModel());
2490 SetList( xModel->getPropertyValue( FM_PROP_STRINGITEMLIST ) );
2491 implAdjustGenericFieldSetting( xModel );
2493 if (m_rColumn.GetParent().getNumberFormatter().is())
2494 m_nKeyType = comphelper::getNumberFormatType(m_rColumn.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn.GetKey());
2496 DbCellControl::Init( rParent, xCursor );
2499 //------------------------------------------------------------------------------
2500 CellControllerRef DbComboBox::CreateController() const
2502 return new ComboBoxCellController((ComboBoxControl*)m_pWindow);
2505 //------------------------------------------------------------------------------
2506 String DbComboBox::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter, Color** /*ppColor*/)
2508 ::rtl::OUString aString;
2509 if (_rxField.is())
2512 aString = getValue( _rxField, xFormatter, m_rColumn.GetParent().getNullDate(), m_rColumn.GetKey(), m_nKeyType );
2514 catch( const Exception& )
2516 DBG_UNHANDLED_EXCEPTION();
2518 return aString;
2521 //------------------------------------------------------------------------------
2522 void DbComboBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter)
2524 m_pWindow->SetText(GetFormatText(_rxField, xFormatter));
2527 //------------------------------------------------------------------------------
2528 void DbComboBox::updateFromModel( Reference< XPropertySet > _rxModel )
2530 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbComboBox::updateFromModel: invalid call!" );
2532 ::rtl::OUString sText;
2533 _rxModel->getPropertyValue( FM_PROP_TEXT ) >>= sText;
2535 static_cast< ComboBox* >( m_pWindow )->SetText( sText );
2536 static_cast< ComboBox* >( m_pWindow )->SetSelection( Selection( SELECTION_MAX, SELECTION_MIN ) );
2539 //------------------------------------------------------------------------------
2540 sal_Bool DbComboBox::commitControl()
2542 String aText( m_pWindow->GetText());
2543 m_rColumn.getModel()->setPropertyValue(FM_PROP_TEXT, makeAny(::rtl::OUString(aText)));
2544 return sal_True;
2547 //------------------------------------------------------------------------------
2548 DbListBox::DbListBox(DbGridColumn& _rColumn)
2549 :DbCellControl(_rColumn)
2550 ,m_bBound(sal_False)
2552 setAlignedController( sal_False );
2554 doPropertyListening( FM_PROP_STRINGITEMLIST );
2555 doPropertyListening( FM_PROP_LINECOUNT );
2558 //------------------------------------------------------------------------------
2559 void DbListBox::_propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent& _rEvent ) throw( RuntimeException )
2561 if ( _rEvent.PropertyName.equals( FM_PROP_STRINGITEMLIST ) )
2563 SetList(_rEvent.NewValue);
2565 else
2567 DbCellControl::_propertyChanged( _rEvent ) ;
2571 //------------------------------------------------------------------------------
2572 void DbListBox::SetList(const Any& rItems)
2574 ListBoxControl* pField = (ListBoxControl*)m_pWindow;
2576 pField->Clear();
2577 m_bBound = sal_False;
2579 ::comphelper::StringSequence aTest;
2580 if (rItems >>= aTest)
2582 const ::rtl::OUString* pStrings = aTest.getConstArray();
2583 sal_Int32 nItems = aTest.getLength();
2584 if (nItems)
2586 for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings )
2587 pField->InsertEntry(*pStrings, LISTBOX_APPEND);
2589 m_rColumn.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ) >>= m_aValueList;
2590 m_bBound = m_aValueList.getLength() > 0;
2592 // tell the grid control that this controller is invalid and has to be re-initialized
2593 invalidatedController();
2598 //------------------------------------------------------------------------------
2599 void DbListBox::Init( Window& rParent, const Reference< XRowSet >& xCursor)
2601 m_rColumn.SetAlignment(::com::sun::star::awt::TextAlign::LEFT);
2603 m_pWindow = new ListBoxControl( &rParent );
2605 // some initial properties
2606 Reference< XPropertySet > xModel( m_rColumn.getModel() );
2607 SetList( xModel->getPropertyValue( FM_PROP_STRINGITEMLIST ) );
2608 implAdjustGenericFieldSetting( xModel );
2610 DbCellControl::Init( rParent, xCursor );
2613 //------------------------------------------------------------------------------
2614 void DbListBox::implAdjustGenericFieldSetting( const Reference< XPropertySet >& _rxModel )
2616 DBG_ASSERT( m_pWindow, "DbListBox::implAdjustGenericFieldSetting: not to be called without window!" );
2617 DBG_ASSERT( _rxModel.is(), "DbListBox::implAdjustGenericFieldSetting: invalid model!" );
2618 if ( m_pWindow && _rxModel.is() )
2620 sal_Int16 nLines = getINT16( _rxModel->getPropertyValue( FM_PROP_LINECOUNT ) );
2621 static_cast< ListBoxControl* >( m_pWindow )->SetDropDownLineCount( nLines );
2625 //------------------------------------------------------------------------------
2626 CellControllerRef DbListBox::CreateController() const
2628 return new ListBoxCellController((ListBoxControl*)m_pWindow);
2631 //------------------------------------------------------------------------------
2632 String DbListBox::GetFormatText(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
2634 String sText;
2635 if ( _rxField.is() )
2639 sText = _rxField->getString();
2640 if ( m_bBound )
2642 Sequence< sal_Int16 > aPosSeq = ::comphelper::findValue( m_aValueList, sText, sal_True );
2643 if ( aPosSeq.getLength() )
2644 sText = static_cast<ListBox*>(m_pWindow)->GetEntry(aPosSeq.getConstArray()[0]);
2645 else
2646 sText = String();
2649 catch( const Exception& )
2651 DBG_UNHANDLED_EXCEPTION();
2654 return sText;
2657 //------------------------------------------------------------------------------
2658 void DbListBox::UpdateFromField(const Reference< ::com::sun::star::sdb::XColumn >& _rxField, const Reference< XNumberFormatter >& xFormatter)
2660 String sFormattedText( GetFormatText( _rxField, xFormatter ) );
2661 if ( sFormattedText.Len() )
2662 static_cast< ListBox* >( m_pWindow )->SelectEntry( sFormattedText );
2663 else
2664 static_cast< ListBox* >( m_pWindow )->SetNoSelection();
2667 //------------------------------------------------------------------------------
2668 void DbListBox::updateFromModel( Reference< XPropertySet > _rxModel )
2670 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbListBox::updateFromModel: invalid call!" );
2672 Sequence< sal_Int16 > aSelection;
2673 _rxModel->getPropertyValue( FM_PROP_SELECT_SEQ );
2675 sal_Int16 nSelection = -1;
2676 if ( aSelection.getLength() > 0 )
2677 nSelection = aSelection[ 0 ];
2679 ListBox* pListBox = static_cast< ListBox* >( m_pWindow );
2681 if ( ( nSelection >= 0 ) && ( nSelection < pListBox->GetEntryCount() ) )
2682 pListBox->SelectEntryPos( nSelection );
2683 else
2684 pListBox->SetNoSelection( );
2687 //------------------------------------------------------------------------------
2688 sal_Bool DbListBox::commitControl()
2690 Any aVal;
2691 Sequence<sal_Int16> aSelectSeq;
2692 if (static_cast<ListBox*>(m_pWindow)->GetSelectEntryCount())
2694 aSelectSeq.realloc(1);
2695 *(sal_Int16 *)aSelectSeq.getArray() = (sal_Int16)static_cast<ListBox*>(m_pWindow)->GetSelectEntryPos();
2697 aVal <<= aSelectSeq;
2698 m_rColumn.getModel()->setPropertyValue(FM_PROP_SELECT_SEQ, aVal);
2699 return sal_True;
2703 DBG_NAME(DbFilterField);
2704 /*************************************************************************/
2705 DbFilterField::DbFilterField(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB,DbGridColumn& _rColumn)
2706 :DbCellControl(_rColumn)
2707 ,OSQLParserClient(_rxORB)
2708 ,m_nControlClass(::com::sun::star::form::FormComponentType::TEXTFIELD)
2709 ,m_bFilterList(sal_False)
2710 ,m_bFilterListFilled(sal_False)
2711 ,m_bBound(sal_False)
2713 DBG_CTOR(DbFilterField,NULL);
2715 setAlignedController( sal_False );
2718 //------------------------------------------------------------------------------
2719 DbFilterField::~DbFilterField()
2721 if (m_nControlClass == ::com::sun::star::form::FormComponentType::CHECKBOX)
2722 ((CheckBoxControl*)m_pWindow)->SetClickHdl( Link() );
2724 DBG_DTOR(DbFilterField,NULL);
2727 //------------------------------------------------------------------------------
2728 void DbFilterField::PaintCell(OutputDevice& rDev, const Rectangle& rRect)
2730 static sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER | TEXT_DRAW_LEFT;
2731 switch (m_nControlClass)
2733 case FormComponentType::CHECKBOX:
2734 DbCellControl::PaintCell( rDev, rRect );
2735 break;
2736 case FormComponentType::LISTBOX:
2737 rDev.DrawText(rRect, static_cast<ListBox*>(m_pWindow)->GetSelectEntry(), nStyle);
2738 break;
2739 default:
2740 rDev.DrawText(rRect, m_aText, nStyle);
2744 //------------------------------------------------------------------------------
2745 void DbFilterField::SetList(const Any& rItems, sal_Bool bComboBox)
2747 ::comphelper::StringSequence aTest;
2748 rItems >>= aTest;
2749 const ::rtl::OUString* pStrings = aTest.getConstArray();
2750 sal_Int32 nItems = aTest.getLength();
2751 if (nItems)
2753 if (bComboBox)
2755 ComboBox* pField = (ComboBox*)m_pWindow;
2756 for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings )
2757 pField->InsertEntry(*pStrings, LISTBOX_APPEND);
2759 else
2761 ListBox* pField = (ListBox*)m_pWindow;
2762 for (sal_Int32 i = 0; i < nItems; ++i, ++pStrings )
2763 pField->InsertEntry(*pStrings, LISTBOX_APPEND);
2765 m_rColumn.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ) >>= m_aValueList;
2766 m_bBound = m_aValueList.getLength() > 0;
2771 //------------------------------------------------------------------------------
2772 void DbFilterField::CreateControl(Window* pParent, const Reference< ::com::sun::star::beans::XPropertySet >& xModel)
2774 switch (m_nControlClass)
2776 case ::com::sun::star::form::FormComponentType::CHECKBOX:
2777 m_pWindow = new CheckBoxControl(pParent);
2778 m_pWindow->SetPaintTransparent( sal_True );
2779 ((CheckBoxControl*)m_pWindow)->SetClickHdl( LINK( this, DbFilterField, OnClick ) );
2781 m_pPainter = new CheckBoxControl(pParent);
2782 m_pPainter->SetPaintTransparent( sal_True );
2783 m_pPainter->SetBackground();
2784 break;
2785 case ::com::sun::star::form::FormComponentType::LISTBOX:
2787 m_pWindow = new ListBoxControl(pParent);
2788 sal_Int16 nLines = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_LINECOUNT));
2789 Any aItems = xModel->getPropertyValue(FM_PROP_STRINGITEMLIST);
2790 SetList(aItems, m_nControlClass == ::com::sun::star::form::FormComponentType::COMBOBOX);
2791 static_cast<ListBox*>(m_pWindow)->SetDropDownLineCount(nLines);
2792 } break;
2793 case ::com::sun::star::form::FormComponentType::COMBOBOX:
2795 m_pWindow = new ComboBoxControl(pParent);
2797 AllSettings aSettings = m_pWindow->GetSettings();
2798 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
2799 aStyleSettings.SetSelectionOptions(
2800 aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
2801 aSettings.SetStyleSettings(aStyleSettings);
2802 m_pWindow->SetSettings(aSettings, sal_True);
2804 if (!m_bFilterList)
2806 sal_Int16 nLines = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_LINECOUNT));
2807 Any aItems = xModel->getPropertyValue(FM_PROP_STRINGITEMLIST);
2808 SetList(aItems, m_nControlClass == ::com::sun::star::form::FormComponentType::COMBOBOX);
2809 ((ComboBox*)m_pWindow)->SetDropDownLineCount(nLines);
2811 else
2812 ((ComboBox*)m_pWindow)->SetDropDownLineCount(5);
2814 } break;
2815 default:
2817 m_pWindow = new Edit(pParent, WB_LEFT);
2818 AllSettings aSettings = m_pWindow->GetSettings();
2819 StyleSettings aStyleSettings = aSettings.GetStyleSettings();
2820 aStyleSettings.SetSelectionOptions(
2821 aStyleSettings.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST);
2822 aSettings.SetStyleSettings(aStyleSettings);
2823 m_pWindow->SetSettings(aSettings, sal_True);
2828 //------------------------------------------------------------------------------
2829 void DbFilterField::Init( Window& rParent, const Reference< XRowSet >& xCursor )
2831 Reference< ::com::sun::star::beans::XPropertySet > xModel(m_rColumn.getModel());
2832 m_rColumn.SetAlignment(::com::sun::star::awt::TextAlign::LEFT);
2834 if (xModel.is())
2836 m_bFilterList = ::comphelper::hasProperty(FM_PROP_FILTERPROPOSAL, xModel) && ::comphelper::getBOOL(xModel->getPropertyValue(FM_PROP_FILTERPROPOSAL));
2837 if (m_bFilterList)
2838 m_nControlClass = ::com::sun::star::form::FormComponentType::COMBOBOX;
2839 else
2841 sal_Int16 nClassId = ::comphelper::getINT16(xModel->getPropertyValue(FM_PROP_CLASSID));
2842 switch (nClassId)
2844 case FormComponentType::CHECKBOX:
2845 case FormComponentType::LISTBOX:
2846 case FormComponentType::COMBOBOX:
2847 m_nControlClass = nClassId;
2848 break;
2849 default:
2850 if (m_bFilterList)
2851 m_nControlClass = FormComponentType::COMBOBOX;
2852 else
2853 m_nControlClass = FormComponentType::TEXTFIELD;
2858 CreateControl( &rParent, xModel );
2859 DbCellControl::Init( rParent, xCursor );
2861 // filter cells are never readonly
2862 // 31.07.2002 - 101584 - fs@openoffice.org
2863 Edit* pAsEdit = dynamic_cast< Edit* >( m_pWindow );
2864 if ( pAsEdit )
2865 pAsEdit->SetReadOnly( sal_False );
2868 //------------------------------------------------------------------------------
2869 CellControllerRef DbFilterField::CreateController() const
2871 CellControllerRef xController;
2872 switch (m_nControlClass)
2874 case ::com::sun::star::form::FormComponentType::CHECKBOX:
2875 xController = new CheckBoxCellController((CheckBoxControl*)m_pWindow);
2876 break;
2877 case ::com::sun::star::form::FormComponentType::LISTBOX:
2878 xController = new ListBoxCellController((ListBoxControl*)m_pWindow);
2879 break;
2880 case ::com::sun::star::form::FormComponentType::COMBOBOX:
2881 xController = new ComboBoxCellController((ComboBoxControl*)m_pWindow);
2882 break;
2883 default:
2884 if (m_bFilterList)
2885 xController = new ComboBoxCellController((ComboBoxControl*)m_pWindow);
2886 else
2887 xController = new EditCellController((Edit*)m_pWindow);
2889 return xController;
2892 //------------------------------------------------------------------------------
2893 void DbFilterField::updateFromModel( Reference< XPropertySet > _rxModel )
2895 OSL_ENSURE( _rxModel.is() && m_pWindow, "DbFilterField::updateFromModel: invalid call!" );
2896 (void)_rxModel;
2898 OSL_ENSURE( sal_False, "DbListBox::updateFromModel: not implemented yet (how the hell did you reach this?)!" );
2899 // TODO: implement this.
2900 // remember: updateFromModel should be some kind of opposite of commitControl
2903 //------------------------------------------------------------------------------
2904 sal_Bool DbFilterField::commitControl()
2906 String aText(m_aText);
2907 switch (m_nControlClass)
2909 case ::com::sun::star::form::FormComponentType::CHECKBOX:
2910 return sal_True;
2911 case ::com::sun::star::form::FormComponentType::LISTBOX:
2912 if (static_cast<ListBox*>(m_pWindow)->GetSelectEntryCount())
2914 sal_Int16 nPos = (sal_Int16)static_cast<ListBox*>(m_pWindow)->GetSelectEntryPos();
2915 aText = (const sal_Unicode*)m_aValueList.getConstArray()[nPos];
2917 else
2918 aText.Erase();
2920 if (m_aText != aText)
2922 m_aText = aText;
2923 m_aCommitLink.Call(this);
2925 return sal_True;
2926 default:
2927 aText = m_pWindow->GetText();
2930 if (m_aText != aText)
2932 // check the text with the SQL-Parser
2933 String aNewText(aText);
2934 aNewText.EraseTrailingChars();
2935 if (aNewText.Len() != 0)
2937 ::rtl::OUString aErrorMsg;
2938 Reference< XNumberFormatter > xNumberFormatter(m_rColumn.GetParent().getNumberFormatter());
2940 ::rtl::Reference< ISQLParseNode > xParseNode = predicateTree(aErrorMsg, aNewText,xNumberFormatter, m_rColumn.GetField());
2941 if (xParseNode.is())
2943 ::rtl::OUString aPreparedText;
2945 ::com::sun::star::lang::Locale aAppLocale = Application::GetSettings().GetUILocale();
2947 Reference< XRowSet > xDataSourceRowSet(
2948 (Reference< XInterface >)*m_rColumn.GetParent().getDataSource(), UNO_QUERY);
2949 Reference< XConnection > xConnection(getRowSetConnection(xDataSourceRowSet));
2951 xParseNode->parseNodeToPredicateStr(aPreparedText,
2952 xConnection,
2953 xNumberFormatter,
2954 m_rColumn.GetField(),aAppLocale,'.',
2955 getParseContext());
2956 m_aText = aPreparedText;
2958 else
2960 // display the error and return sal_False
2961 String aTitle( SVX_RES(RID_STR_SYNTAXERROR) );
2963 SQLException aError;
2964 aError.Message = aErrorMsg;
2965 displayException(aError, m_pWindow->GetParent());
2966 // TODO: transport the title
2968 return sal_False;
2971 else
2972 m_aText = aText;
2974 m_pWindow->SetText(m_aText);
2975 m_aCommitLink.Call(this);
2977 return sal_True;
2980 //------------------------------------------------------------------------------
2981 void DbFilterField::SetText(const String& rText)
2983 m_aText = rText;
2984 switch (m_nControlClass)
2986 case ::com::sun::star::form::FormComponentType::CHECKBOX:
2988 TriState eState;
2989 if (rText.EqualsAscii("1"))
2990 eState = STATE_CHECK;
2991 else if (rText.EqualsAscii("0"))
2992 eState = STATE_NOCHECK;
2993 else
2994 eState = STATE_DONTKNOW;
2996 ((CheckBoxControl*)m_pWindow)->GetBox().SetState(eState);
2997 ((CheckBoxControl*)m_pPainter)->GetBox().SetState(eState);
2998 } break;
2999 case ::com::sun::star::form::FormComponentType::LISTBOX:
3001 String aText;
3002 Sequence<sal_Int16> aPosSeq = ::comphelper::findValue(m_aValueList, m_aText, sal_True);
3003 if (aPosSeq.getLength())
3004 static_cast<ListBox*>(m_pWindow)->SelectEntryPos(aPosSeq.getConstArray()[0], sal_True);
3005 else
3006 static_cast<ListBox*>(m_pWindow)->SetNoSelection();
3007 } break;
3008 default:
3009 m_pWindow->SetText(m_aText);
3012 // now force a repaint on the window
3013 m_rColumn.GetParent().RowModified(0,m_rColumn.GetId());
3016 //------------------------------------------------------------------------------
3017 void DbFilterField::Update()
3019 // should we fill the combobox with a filter proposal?
3020 if (m_bFilterList && !m_bFilterListFilled)
3022 m_bFilterListFilled = sal_True;
3023 Reference< ::com::sun::star::beans::XPropertySet > xField = m_rColumn.GetField();
3024 if (!xField.is())
3025 return;
3027 ::rtl::OUString aName;
3028 xField->getPropertyValue(FM_PROP_NAME) >>= aName;
3030 // the columnmodel
3031 Reference< ::com::sun::star::container::XChild > xModelAsChild(m_rColumn.getModel(), UNO_QUERY);
3032 // the grid model
3033 xModelAsChild = Reference< ::com::sun::star::container::XChild > (xModelAsChild->getParent(),UNO_QUERY);
3034 Reference< XRowSet > xForm(xModelAsChild->getParent(), UNO_QUERY);
3035 if (!xForm.is())
3036 return;
3038 Reference< XConnection > xConnection(getRowSetConnection(xForm));
3039 if (!xConnection.is())
3040 return;
3042 Reference< ::com::sun::star::sdb::XSQLQueryComposerFactory > xFactory(xConnection, UNO_QUERY);
3043 if (!xFactory.is())
3045 DBG_ERROR("DbFilterField::Update : used the right place to request the ::com::sun::star::sdb::XSQLQueryComposerFactory interface ?");
3046 return;
3049 Reference< ::com::sun::star::sdb::XSQLQueryComposer > xComposer = xFactory->createQueryComposer();
3052 Reference< ::com::sun::star::beans::XPropertySet > xFormAsSet(xForm, UNO_QUERY);
3053 ::rtl::OUString sStatement;
3054 xFormAsSet->getPropertyValue(FM_PROP_ACTIVECOMMAND) >>= sStatement;
3055 xComposer->setQuery(sStatement);
3057 catch(const Exception&)
3059 ::comphelper::disposeComponent(xComposer);
3060 return;
3063 Reference< ::com::sun::star::beans::XPropertySet > xComposerAsSet(xComposer, UNO_QUERY);
3064 if (!xComposerAsSet.is())
3065 return;
3067 // search the field
3068 Reference< ::com::sun::star::container::XNameAccess > xFieldNames;
3069 Reference< ::com::sun::star::container::XNameAccess > xTablesNames;
3070 Reference< ::com::sun::star::beans::XPropertySet > xComposerFieldAsSet;
3072 ::cppu::extractInterface(xFieldNames, xComposerAsSet->getPropertyValue(FM_PROP_SELECTED_FIELDS));
3073 ::cppu::extractInterface(xTablesNames, xComposerAsSet->getPropertyValue(FM_PROP_SELECTED_TABLES));
3074 ::cppu::extractInterface(xComposerFieldAsSet, xFieldNames->getByName(aName));
3076 if (xComposerFieldAsSet.is() && ::comphelper::hasProperty(FM_PROP_TABLENAME, xComposerFieldAsSet) &&
3077 ::comphelper::hasProperty(FM_PROP_FIELDSOURCE, xComposerFieldAsSet))
3079 ::rtl::OUString aFieldName;
3080 ::rtl::OUString aTableName;
3081 xComposerFieldAsSet->getPropertyValue(FM_PROP_FIELDSOURCE) >>= aFieldName;
3082 xComposerFieldAsSet->getPropertyValue(FM_PROP_TABLENAME) >>= aTableName;
3084 // no possibility to create a select statement
3085 // looking for the complete table name
3086 if (!xTablesNames->hasByName(aTableName))
3087 return;
3089 // ein Statement aufbauen und abschicken als query
3090 // Access to the connection
3091 Reference< XStatement > xStatement;
3092 Reference< XResultSet > xListCursor;
3093 Reference< ::com::sun::star::sdb::XColumn > xDataField;
3097 Reference< XDatabaseMetaData > xMeta = xConnection->getMetaData();
3099 String aQuote( xMeta->getIdentifierQuoteString());
3100 String aStatement;
3101 aStatement.AssignAscii("SELECT DISTINCT ");
3103 aStatement += String(quoteName(aQuote, aName));
3104 if (aFieldName.getLength() && aName != aFieldName)
3106 aStatement.AppendAscii(" AS ");
3107 aStatement += quoteName(aQuote, aFieldName).getStr();
3110 aStatement.AppendAscii(" FROM ");
3112 Reference< XPropertySet > xTableNameAccess( xTablesNames->getByName(aTableName), UNO_QUERY_THROW );
3113 aStatement += composeTableNameForSelect( xConnection, xTableNameAccess ).getStr();
3115 xStatement = xConnection->createStatement();
3116 Reference< ::com::sun::star::beans::XPropertySet > xStatementProps(xStatement, UNO_QUERY);
3117 xStatementProps->setPropertyValue(FM_PROP_ESCAPE_PROCESSING, makeAny((sal_Bool)sal_True));
3119 xListCursor = xStatement->executeQuery(aStatement);
3121 Reference< ::com::sun::star::sdbcx::XColumnsSupplier > xSupplyCols(xListCursor, UNO_QUERY);
3122 Reference< ::com::sun::star::container::XIndexAccess > xFields(xSupplyCols->getColumns(), UNO_QUERY);
3123 ::cppu::extractInterface(xDataField, xFields->getByIndex(0));
3124 if (!xDataField.is())
3125 return;
3127 catch(const Exception&)
3129 ::comphelper::disposeComponent(xStatement);
3130 return;
3133 sal_Int16 i = 0;
3134 ::std::vector< ::rtl::OUString > aStringList;
3135 aStringList.reserve(16);
3136 ::rtl::OUString aStr;
3137 com::sun::star::util::Date aNullDate = m_rColumn.GetParent().getNullDate();
3138 sal_Int32 nFormatKey = m_rColumn.GetKey();
3139 Reference< XNumberFormatter > xFormatter = m_rColumn.GetParent().getNumberFormatter();
3140 sal_Int16 nKeyType = ::comphelper::getNumberFormatType(xFormatter->getNumberFormatsSupplier()->getNumberFormats(), nFormatKey);
3142 while (!xListCursor->isAfterLast() && i++ < SHRT_MAX) // max anzahl eintraege
3144 aStr = getValue(xDataField, xFormatter, aNullDate, nFormatKey, nKeyType);
3145 aStringList.push_back(aStr);
3146 xListCursor->next();
3149 // filling the entries for the combobox
3150 for (::std::vector< ::rtl::OUString >::const_iterator iter = aStringList.begin();
3151 iter != aStringList.end(); ++iter)
3152 ((ComboBox*)m_pWindow)->InsertEntry(*iter, LISTBOX_APPEND);
3157 //------------------------------------------------------------------------------
3158 XubString DbFilterField::GetFormatText(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/, Color** /*ppColor*/)
3160 return XubString();
3163 //------------------------------------------------------------------
3164 void DbFilterField::UpdateFromField(const Reference< XColumn >& /*_rxField*/, const Reference< XNumberFormatter >& /*xFormatter*/)
3166 DBG_ERROR( "DbFilterField::UpdateFromField: cannot update a filter control from a field!" );
3169 //------------------------------------------------------------------
3170 IMPL_LINK( DbFilterField, OnClick, void*, EMPTYARG )
3172 TriState eState = ((CheckBoxControl*)m_pWindow)->GetBox().GetState();
3173 String aText;
3175 switch (eState)
3177 case STATE_CHECK:
3178 aText.AssignAscii("1");
3179 break;
3180 case STATE_NOCHECK:
3181 aText.AssignAscii("0");
3182 break;
3183 case STATE_DONTKNOW:
3184 aText = String();
3185 break;
3188 if (m_aText != aText)
3190 m_aText = aText;
3191 m_aCommitLink.Call(this);
3193 return 1;
3196 /*************************************************************************/
3197 TYPEINIT0(FmXGridCell);
3200 DBG_NAME(FmXGridCell);
3201 //-----------------------------------------------------------------------------
3202 FmXGridCell::FmXGridCell(DbGridColumn* pColumn, DbCellControl* pControl)
3203 :OComponentHelper(m_aMutex)
3204 ,m_pColumn(pColumn)
3205 ,m_pCellControl(pControl)
3207 DBG_CTOR(FmXGridCell,NULL);
3211 //-----------------------------------------------------------------------------
3212 FmXGridCell::~FmXGridCell()
3214 if (!OComponentHelper::rBHelper.bDisposed)
3216 acquire();
3217 dispose();
3220 DBG_DTOR(FmXGridCell,NULL);
3223 //------------------------------------------------------------------
3224 void FmXGridCell::SetTextLineColor()
3226 if (m_pCellControl)
3227 m_pCellControl->SetTextLineColor();
3230 //------------------------------------------------------------------
3231 void FmXGridCell::SetTextLineColor(const Color& _rColor)
3233 if (m_pCellControl)
3234 m_pCellControl->SetTextLineColor(_rColor);
3237 // XTypeProvider
3238 //------------------------------------------------------------------
3239 Sequence< sal_Int8 > SAL_CALL FmXGridCell::getImplementationId() throw(RuntimeException)
3241 static ::cppu::OImplementationId* pId = 0;
3242 if (! pId)
3244 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
3245 if (! pId)
3247 static ::cppu::OImplementationId aId;
3248 pId = &aId;
3251 return pId->getImplementationId();
3254 // OComponentHelper
3255 //-----------------------------------------------------------------------------
3256 void FmXGridCell::disposing()
3258 OComponentHelper::disposing();
3259 m_pColumn = NULL;
3260 DELETEZ(m_pCellControl);
3263 //------------------------------------------------------------------
3264 Any SAL_CALL FmXGridCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
3266 Any aReturn = OComponentHelper::queryAggregation(_rType);
3267 if (!aReturn.hasValue())
3268 aReturn = ::cppu::queryInterface(_rType,
3269 static_cast< ::com::sun::star::awt::XControl* >(this),
3270 static_cast< ::com::sun::star::form::XBoundControl* >(this)
3273 return aReturn;
3276 // ::com::sun::star::awt::XControl
3277 //-----------------------------------------------------------------------------
3278 Reference< XInterface > FmXGridCell::getContext() throw( RuntimeException )
3280 return Reference< XInterface > ();
3283 //-----------------------------------------------------------------------------
3284 Reference< ::com::sun::star::awt::XControlModel > FmXGridCell::getModel() throw( ::com::sun::star::uno::RuntimeException )
3286 return Reference< ::com::sun::star::awt::XControlModel > (m_pColumn->getModel(), UNO_QUERY);
3289 // ::com::sun::star::form::XBoundControl
3290 //------------------------------------------------------------------
3291 sal_Bool FmXGridCell::getLock() throw( RuntimeException )
3293 return m_pColumn->isLocked();
3296 //------------------------------------------------------------------
3297 void FmXGridCell::setLock(sal_Bool _bLock) throw( RuntimeException )
3299 if (getLock() == _bLock)
3300 return;
3301 else
3303 ::osl::MutexGuard aGuard(m_aMutex);
3304 m_pColumn->setLock(_bLock);
3308 /*************************************************************************/
3309 TYPEINIT1(FmXDataCell, FmXGridCell);
3310 //------------------------------------------------------------------------------
3311 void FmXDataCell::PaintFieldToCell(OutputDevice& rDev, const Rectangle& rRect,
3312 const Reference< ::com::sun::star::sdb::XColumn >& _rxField,
3313 const Reference< XNumberFormatter >& xFormatter)
3315 m_pCellControl->PaintFieldToCell( rDev, rRect, _rxField, xFormatter );
3318 //------------------------------------------------------------------------------
3319 void FmXDataCell::UpdateFromColumn()
3321 Reference< ::com::sun::star::sdb::XColumn > xField(m_pColumn->GetCurrentFieldValue());
3322 if (xField.is())
3323 m_pCellControl->UpdateFromField(xField, m_pColumn->GetParent().getNumberFormatter());
3326 /*************************************************************************/
3327 TYPEINIT1(FmXTextCell, FmXDataCell);
3329 //------------------------------------------------------------------------------
3330 void FmXTextCell::PaintFieldToCell(OutputDevice& rDev,
3331 const Rectangle& rRect,
3332 const Reference< ::com::sun::star::sdb::XColumn >& _rxField,
3333 const Reference< XNumberFormatter >& xFormatter)
3335 if ( !m_bFastPaint )
3337 FmXDataCell::PaintFieldToCell( rDev, rRect, _rxField, xFormatter );
3338 return;
3341 sal_uInt16 nStyle = TEXT_DRAW_CLIP | TEXT_DRAW_VCENTER;
3342 if ( ( rDev.GetOutDevType() == OUTDEV_WINDOW ) && !static_cast< Window& >( rDev ).IsEnabled() )
3343 nStyle |= TEXT_DRAW_DISABLE;
3345 switch (m_pColumn->GetAlignment())
3347 case ::com::sun::star::awt::TextAlign::RIGHT:
3348 nStyle |= TEXT_DRAW_RIGHT;
3349 break;
3350 case ::com::sun::star::awt::TextAlign::CENTER:
3351 nStyle |= TEXT_DRAW_CENTER;
3352 break;
3353 default:
3354 nStyle |= TEXT_DRAW_LEFT;
3357 Color* pColor = NULL;
3358 String aText = GetText(_rxField, xFormatter, &pColor);
3359 if (pColor != NULL)
3361 Color aOldTextColor( rDev.GetTextColor() );
3362 rDev.SetTextColor( *pColor );
3363 rDev.DrawText(rRect, aText, nStyle);
3364 rDev.SetTextColor( aOldTextColor );
3366 else
3367 rDev.DrawText(rRect, aText, nStyle);
3371 /*************************************************************************/
3373 DBG_NAME(FmXEditCell);
3374 //------------------------------------------------------------------------------
3375 FmXEditCell::FmXEditCell(DbGridColumn* pColumn, DbCellControl* pControl)
3376 :FmXTextCell(pColumn, pControl)
3377 ,m_aTextListeners(m_aMutex)
3378 ,m_pEditImplementation( NULL )
3379 ,m_bOwnEditImplementation( false )
3381 DBG_CTOR(FmXEditCell,NULL);
3383 DbTextField* pTextField = PTR_CAST( DbTextField, pControl );
3384 if ( pTextField )
3387 m_pEditImplementation = pTextField->GetEditImplementation();
3388 if ( !pTextField->IsSimpleEdit() )
3389 m_bFastPaint = sal_False;
3391 else
3393 m_pEditImplementation = new EditImplementation( *static_cast< Edit* >( pControl->GetControl() ) );
3394 m_bOwnEditImplementation = true;
3397 m_pEditImplementation->SetModifyHdl( LINK( this, FmXEditCell, OnTextChanged ) );
3400 //------------------------------------------------------------------
3401 FmXEditCell::~FmXEditCell()
3403 if (!OComponentHelper::rBHelper.bDisposed)
3405 acquire();
3406 dispose();
3410 DBG_DTOR(FmXEditCell,NULL);
3413 // OComponentHelper
3414 //-----------------------------------------------------------------------------
3415 void FmXEditCell::disposing()
3417 ::com::sun::star::lang::EventObject aEvt(*this);
3418 m_aTextListeners.disposeAndClear(aEvt);
3420 m_pEditImplementation->SetModifyHdl( Link() );
3421 if ( m_bOwnEditImplementation )
3422 delete m_pEditImplementation;
3423 m_pEditImplementation = NULL;
3425 FmXDataCell::disposing();
3428 //------------------------------------------------------------------
3429 Any SAL_CALL FmXEditCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
3431 Any aReturn = FmXDataCell::queryAggregation(_rType);
3432 if (!aReturn.hasValue())
3433 aReturn = ::cppu::queryInterface(_rType,
3434 static_cast< ::com::sun::star::awt::XTextComponent* >(this)
3436 return aReturn;
3439 //-------------------------------------------------------------------------
3440 Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXEditCell::getTypes( ) throw(RuntimeException)
3442 Sequence< ::com::sun::star::uno::Type > aTypes = OComponentHelper::getTypes();
3444 sal_Int32 nLen = aTypes.getLength();
3445 aTypes.realloc(nLen + 2);
3446 aTypes.getArray()[nLen++] = ::getCppuType(static_cast< Reference< ::com::sun::star::awt::XControl >* >(NULL));
3447 aTypes.getArray()[nLen++] = ::getCppuType(static_cast< Reference< ::com::sun::star::awt::XTextComponent >* >(NULL));
3449 return aTypes;
3452 // ::com::sun::star::awt::XTextComponent
3453 //------------------------------------------------------------------------------
3454 void SAL_CALL FmXEditCell::addTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException )
3456 m_aTextListeners.addInterface( l );
3459 //------------------------------------------------------------------------------
3460 void SAL_CALL FmXEditCell::removeTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException )
3462 m_aTextListeners.removeInterface( l );
3465 //------------------------------------------------------------------------------
3466 void SAL_CALL FmXEditCell::setText( const ::rtl::OUString& aText ) throw( RuntimeException )
3468 ::osl::MutexGuard aGuard( m_aMutex );
3470 if ( m_pEditImplementation )
3472 m_pEditImplementation->SetText( aText );
3474 // In JAVA wird auch ein textChanged ausgeloest, in VCL nicht.
3475 // ::com::sun::star::awt::Toolkit soll JAVA-komform sein...
3476 OnTextChanged( NULL );
3480 //------------------------------------------------------------------------------
3481 void SAL_CALL FmXEditCell::insertText(const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText) throw(RuntimeException)
3483 ::osl::MutexGuard aGuard( m_aMutex );
3485 if ( m_pEditImplementation )
3487 m_pEditImplementation->SetSelection( Selection( rSel.Min, rSel.Max ) );
3488 m_pEditImplementation->ReplaceSelected( aText );
3492 //------------------------------------------------------------------------------
3493 ::rtl::OUString SAL_CALL FmXEditCell::getText() throw( RuntimeException )
3495 ::osl::MutexGuard aGuard( m_aMutex );
3497 ::rtl::OUString aText;
3498 if ( m_pEditImplementation )
3500 if ( m_pEditImplementation->GetControl().IsVisible() && m_pColumn->GetParent().getDisplaySynchron())
3502 // if the display isn't sync with the cursor we can't ask the edit field
3503 LineEnd eLineEndFormat = m_pColumn ? getModelLineEndSetting( m_pColumn->getModel() ) : LINEEND_LF;
3504 aText = m_pEditImplementation->GetText( eLineEndFormat );
3506 else
3508 Reference< ::com::sun::star::sdb::XColumn > xField(m_pColumn->GetCurrentFieldValue());
3509 if (xField.is())
3510 aText = GetText(xField, m_pColumn->GetParent().getNumberFormatter());
3513 return aText;
3516 //------------------------------------------------------------------------------
3517 ::rtl::OUString SAL_CALL FmXEditCell::getSelectedText( void ) throw( RuntimeException )
3519 ::osl::MutexGuard aGuard( m_aMutex );
3521 ::rtl::OUString aText;
3522 if ( m_pEditImplementation )
3524 LineEnd eLineEndFormat = m_pColumn ? getModelLineEndSetting( m_pColumn->getModel() ) : LINEEND_LF;
3525 aText = m_pEditImplementation->GetSelected( eLineEndFormat );
3527 return aText;
3530 //------------------------------------------------------------------------------
3531 void SAL_CALL FmXEditCell::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw( RuntimeException )
3533 ::osl::MutexGuard aGuard( m_aMutex );
3535 if ( m_pEditImplementation )
3536 m_pEditImplementation->SetSelection( Selection( aSelection.Min, aSelection.Max ) );
3539 //------------------------------------------------------------------------------
3540 ::com::sun::star::awt::Selection SAL_CALL FmXEditCell::getSelection( void ) throw( RuntimeException )
3542 ::osl::MutexGuard aGuard( m_aMutex );
3544 Selection aSel;
3545 if ( m_pEditImplementation )
3546 aSel = m_pEditImplementation->GetSelection();
3548 return ::com::sun::star::awt::Selection(aSel.Min(), aSel.Max());
3551 //------------------------------------------------------------------------------
3552 sal_Bool SAL_CALL FmXEditCell::isEditable( void ) throw( RuntimeException )
3554 ::osl::MutexGuard aGuard( m_aMutex );
3556 return ( m_pEditImplementation && !m_pEditImplementation->IsReadOnly() && m_pEditImplementation->GetControl().IsEnabled() ) ? sal_True : sal_False;
3559 //------------------------------------------------------------------------------
3560 void SAL_CALL FmXEditCell::setEditable( sal_Bool bEditable ) throw( RuntimeException )
3562 ::osl::MutexGuard aGuard( m_aMutex );
3564 if ( m_pEditImplementation )
3565 m_pEditImplementation->SetReadOnly( !bEditable );
3568 //------------------------------------------------------------------------------
3569 sal_Int16 SAL_CALL FmXEditCell::getMaxTextLen() throw( RuntimeException )
3571 ::osl::MutexGuard aGuard( m_aMutex );
3573 return m_pEditImplementation ? m_pEditImplementation->GetMaxTextLen() : 0;
3576 //------------------------------------------------------------------------------
3577 void SAL_CALL FmXEditCell::setMaxTextLen( sal_Int16 nLen ) throw( RuntimeException )
3579 ::osl::MutexGuard aGuard( m_aMutex );
3581 if ( m_pEditImplementation )
3582 m_pEditImplementation->SetMaxTextLen( nLen );
3585 //------------------------------------------------------------------------------
3586 IMPL_LINK( FmXEditCell, OnTextChanged, void*, EMPTYARG )
3588 if ( m_pEditImplementation )
3590 ::cppu::OInterfaceIteratorHelper aIt( m_aTextListeners );
3591 ::com::sun::star::awt::TextEvent aEvt;
3592 aEvt.Source = *this;
3593 while( aIt.hasMoreElements() )
3594 ((::com::sun::star::awt::XTextListener *)aIt.next())->textChanged( aEvt );
3596 return 1;
3599 /*************************************************************************/
3600 DBG_NAME(FmXCheckBoxCell);
3601 //------------------------------------------------------------------------------
3602 FmXCheckBoxCell::FmXCheckBoxCell(DbGridColumn* pColumn, DbCellControl* pControl)
3603 :FmXDataCell(pColumn, pControl)
3604 ,m_aItemListeners(m_aMutex)
3605 ,m_pBox(&((CheckBoxControl*)pControl->GetControl())->GetBox())
3607 DBG_CTOR(FmXCheckBoxCell,NULL);
3609 ((CheckBoxControl*)pControl->GetControl())->SetClickHdl( LINK( this, FmXCheckBoxCell, OnClick ) );
3612 //------------------------------------------------------------------
3613 FmXCheckBoxCell::~FmXCheckBoxCell()
3615 if (!OComponentHelper::rBHelper.bDisposed)
3617 acquire();
3618 dispose();
3621 DBG_DTOR(FmXCheckBoxCell,NULL);
3624 // OComponentHelper
3625 //-----------------------------------------------------------------------------
3626 void FmXCheckBoxCell::disposing()
3628 ::com::sun::star::lang::EventObject aEvt(*this);
3629 m_aItemListeners.disposeAndClear(aEvt);
3631 ((CheckBoxControl*)m_pCellControl->GetControl())->SetClickHdl(Link());
3632 m_pBox = NULL;
3634 FmXDataCell::disposing();
3637 //------------------------------------------------------------------
3638 Any SAL_CALL FmXCheckBoxCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
3640 Any aReturn = FmXDataCell::queryAggregation(_rType);
3641 if (!aReturn.hasValue())
3642 aReturn = ::cppu::queryInterface(_rType,
3643 static_cast< ::com::sun::star::awt::XCheckBox* >(this)
3645 return aReturn;
3648 //-------------------------------------------------------------------------
3649 Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXCheckBoxCell::getTypes( ) throw(RuntimeException)
3651 Sequence< ::com::sun::star::uno::Type > aTypes = OComponentHelper::getTypes();
3653 sal_Int32 nLen = aTypes.getLength();
3654 aTypes.realloc(nLen + 2);
3655 aTypes.getArray()[nLen++] = ::getCppuType(static_cast< Reference< ::com::sun::star::awt::XControl >* >(NULL));
3656 aTypes.getArray()[nLen++] = ::getCppuType(static_cast< Reference< ::com::sun::star::awt::XCheckBox >* >(NULL));
3658 return aTypes;
3661 //------------------------------------------------------------------
3662 void SAL_CALL FmXCheckBoxCell::addItemListener( const Reference< ::com::sun::star::awt::XItemListener >& l ) throw( RuntimeException )
3664 m_aItemListeners.addInterface( l );
3667 //------------------------------------------------------------------
3668 void SAL_CALL FmXCheckBoxCell::removeItemListener( const Reference< ::com::sun::star::awt::XItemListener >& l ) throw( RuntimeException )
3670 m_aItemListeners.removeInterface( l );
3673 //------------------------------------------------------------------
3674 void SAL_CALL FmXCheckBoxCell::setLabel( const ::rtl::OUString& rLabel ) throw( RuntimeException )
3676 ::osl::MutexGuard aGuard( m_aMutex );
3677 if (m_pBox)
3679 UpdateFromColumn();
3680 m_pBox->SetText( rLabel );
3684 //------------------------------------------------------------------
3685 void SAL_CALL FmXCheckBoxCell::setState( short n ) throw( RuntimeException )
3687 ::osl::MutexGuard aGuard( m_aMutex );
3689 if (m_pBox)
3691 UpdateFromColumn();
3692 m_pBox->SetState( (TriState)n );
3696 //------------------------------------------------------------------
3697 short SAL_CALL FmXCheckBoxCell::getState() throw( RuntimeException )
3699 ::osl::MutexGuard aGuard( m_aMutex );
3701 if (m_pBox)
3703 UpdateFromColumn();
3704 return (short)m_pBox->GetState();
3706 return STATE_DONTKNOW;
3709 //------------------------------------------------------------------
3710 void SAL_CALL FmXCheckBoxCell::enableTriState( sal_Bool b ) throw( RuntimeException )
3712 ::osl::MutexGuard aGuard( m_aMutex );
3714 if (m_pBox)
3715 m_pBox->EnableTriState( b );
3718 //------------------------------------------------------------------
3719 IMPL_LINK( FmXCheckBoxCell, OnClick, void*, EMPTYARG )
3721 if (m_pBox)
3723 // check boxes are to be committed immediately (this holds for ordinary check box controls in
3724 // documents, and this must hold for check boxes in grid columns, too
3725 // 91210 - 22.08.2001 - frank.schoenheit@sun.com
3726 m_pCellControl->Commit();
3728 // notify our listeners
3729 ::cppu::OInterfaceIteratorHelper aIt( m_aItemListeners );
3731 ::com::sun::star::awt::ItemEvent aEvent;
3732 aEvent.Source = *this;
3733 aEvent.Highlighted = sal_False;
3734 aEvent.Selected = m_pBox->GetState();
3736 while ( aIt.hasMoreElements() )
3737 static_cast< awt::XItemListener* >( aIt.next() )->itemStateChanged( aEvent );
3739 return 1;
3742 /*************************************************************************/
3744 DBG_NAME(FmXListBoxCell);
3745 //------------------------------------------------------------------------------
3746 FmXListBoxCell::FmXListBoxCell(DbGridColumn* pColumn, DbCellControl* pControl)
3747 :FmXTextCell(pColumn, pControl)
3748 ,m_aItemListeners(m_aMutex)
3749 ,m_aActionListeners(m_aMutex)
3750 ,m_pBox((ListBox*)pControl->GetControl())
3752 DBG_CTOR(FmXListBoxCell,NULL);
3754 m_pBox->AddEventListener( LINK( this, FmXListBoxCell, OnSelect ) );
3755 m_pBox->SetDoubleClickHdl( LINK( this, FmXListBoxCell, OnDoubleClick ) );
3758 //------------------------------------------------------------------
3759 FmXListBoxCell::~FmXListBoxCell()
3761 if (!OComponentHelper::rBHelper.bDisposed)
3763 acquire();
3764 dispose();
3767 DBG_DTOR(FmXListBoxCell,NULL);
3770 // OComponentHelper
3771 //-----------------------------------------------------------------------------
3772 void FmXListBoxCell::disposing()
3774 ::com::sun::star::lang::EventObject aEvt(*this);
3775 m_aItemListeners.disposeAndClear(aEvt);
3776 m_aActionListeners.disposeAndClear(aEvt);
3778 m_pBox->SetSelectHdl( Link() );
3779 m_pBox->SetDoubleClickHdl( Link() );
3780 m_pBox = NULL;
3782 FmXTextCell::disposing();
3785 //------------------------------------------------------------------
3786 Any SAL_CALL FmXListBoxCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
3788 Any aReturn = FmXTextCell::queryAggregation(_rType);
3789 if (!aReturn.hasValue())
3790 aReturn = ::cppu::queryInterface(_rType,
3791 static_cast< ::com::sun::star::awt::XListBox* >(this)
3793 return aReturn;
3796 //-------------------------------------------------------------------------
3797 Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXListBoxCell::getTypes( ) throw(RuntimeException)
3799 Sequence< ::com::sun::star::uno::Type > aTypes = OComponentHelper::getTypes();
3801 sal_Int32 nLen = aTypes.getLength();
3802 aTypes.realloc(nLen + 2);
3803 aTypes.getArray()[nLen++] = ::getCppuType(static_cast< Reference< ::com::sun::star::awt::XControl >* >(NULL));
3804 aTypes.getArray()[nLen++] = ::getCppuType(static_cast< Reference< ::com::sun::star::awt::XListBox >* >(NULL));
3806 return aTypes;
3809 //------------------------------------------------------------------
3810 void SAL_CALL FmXListBoxCell::addItemListener(const Reference< ::com::sun::star::awt::XItemListener >& l) throw( RuntimeException )
3812 m_aItemListeners.addInterface( l );
3815 //------------------------------------------------------------------
3816 void SAL_CALL FmXListBoxCell::removeItemListener(const Reference< ::com::sun::star::awt::XItemListener >& l) throw( RuntimeException )
3818 m_aItemListeners.removeInterface( l );
3821 //------------------------------------------------------------------
3822 void SAL_CALL FmXListBoxCell::addActionListener(const Reference< ::com::sun::star::awt::XActionListener >& l) throw( RuntimeException )
3824 m_aActionListeners.addInterface( l );
3827 //------------------------------------------------------------------
3828 void SAL_CALL FmXListBoxCell::removeActionListener(const Reference< ::com::sun::star::awt::XActionListener >& l) throw( RuntimeException )
3830 m_aActionListeners.removeInterface( l );
3833 //------------------------------------------------------------------
3834 void SAL_CALL FmXListBoxCell::addItem(const ::rtl::OUString& aItem, sal_Int16 nPos) throw( RuntimeException )
3836 ::osl::MutexGuard aGuard( m_aMutex );
3837 if (m_pBox)
3838 m_pBox->InsertEntry( aItem, nPos );
3841 //------------------------------------------------------------------
3842 void SAL_CALL FmXListBoxCell::addItems(const ::comphelper::StringSequence& aItems, sal_Int16 nPos) throw( RuntimeException )
3844 ::osl::MutexGuard aGuard( m_aMutex );
3845 if (m_pBox)
3847 sal_uInt16 nP = nPos;
3848 for ( sal_uInt16 n = 0; n < aItems.getLength(); n++ )
3850 m_pBox->InsertEntry( aItems.getConstArray()[n], nP );
3851 if ( nPos != -1 ) // Nicht wenn 0xFFFF, weil LIST_APPEND
3852 nP++;
3857 //------------------------------------------------------------------
3858 void SAL_CALL FmXListBoxCell::removeItems(sal_Int16 nPos, sal_Int16 nCount) throw( RuntimeException )
3860 ::osl::MutexGuard aGuard( m_aMutex );
3861 if ( m_pBox )
3863 for ( sal_uInt16 n = nCount; n; )
3864 m_pBox->RemoveEntry( nPos + (--n) );
3868 //------------------------------------------------------------------
3869 sal_Int16 SAL_CALL FmXListBoxCell::getItemCount() throw( RuntimeException )
3871 ::osl::MutexGuard aGuard( m_aMutex );
3872 return m_pBox ? m_pBox->GetEntryCount() : 0;
3875 //------------------------------------------------------------------
3876 ::rtl::OUString SAL_CALL FmXListBoxCell::getItem(sal_Int16 nPos) throw( RuntimeException )
3878 ::osl::MutexGuard aGuard( m_aMutex );
3879 String aItem;
3880 if (m_pBox)
3881 aItem = m_pBox->GetEntry( nPos );
3882 return aItem;
3884 //------------------------------------------------------------------
3885 ::comphelper::StringSequence SAL_CALL FmXListBoxCell::getItems() throw( RuntimeException )
3887 ::osl::MutexGuard aGuard( m_aMutex );
3889 ::comphelper::StringSequence aSeq;
3890 if (m_pBox)
3892 sal_uInt16 nEntries = m_pBox ->GetEntryCount();
3893 aSeq = ::comphelper::StringSequence( nEntries );
3894 for ( sal_uInt16 n = nEntries; n; )
3896 --n;
3897 aSeq.getArray()[n] = m_pBox ->GetEntry( n );
3900 return aSeq;
3903 //------------------------------------------------------------------
3904 sal_Int16 SAL_CALL FmXListBoxCell::getSelectedItemPos() throw( RuntimeException )
3906 ::osl::MutexGuard aGuard( m_aMutex );
3907 if (m_pBox)
3909 UpdateFromColumn();
3910 return m_pBox->GetSelectEntryPos();
3912 return 0;
3915 //------------------------------------------------------------------
3916 Sequence< sal_Int16 > SAL_CALL FmXListBoxCell::getSelectedItemsPos() throw( RuntimeException )
3918 ::osl::MutexGuard aGuard( m_aMutex );
3919 Sequence<sal_Int16> aSeq;
3921 if (m_pBox)
3923 UpdateFromColumn();
3924 sal_uInt16 nSelEntries = m_pBox->GetSelectEntryCount();
3925 aSeq = Sequence<sal_Int16>( nSelEntries );
3926 for ( sal_uInt16 n = 0; n < nSelEntries; n++ )
3927 aSeq.getArray()[n] = m_pBox->GetSelectEntryPos( n );
3929 return aSeq;
3931 //------------------------------------------------------------------
3932 ::rtl::OUString SAL_CALL FmXListBoxCell::getSelectedItem() throw( RuntimeException )
3934 ::osl::MutexGuard aGuard( m_aMutex );
3936 String aItem;
3937 if (m_pBox)
3939 UpdateFromColumn();
3940 aItem = m_pBox->GetSelectEntry();
3943 return aItem;
3946 //------------------------------------------------------------------
3947 ::comphelper::StringSequence SAL_CALL FmXListBoxCell::getSelectedItems() throw( RuntimeException )
3949 ::osl::MutexGuard aGuard( m_aMutex );
3951 ::comphelper::StringSequence aSeq;
3953 if (m_pBox)
3955 UpdateFromColumn();
3956 sal_uInt16 nSelEntries = m_pBox->GetSelectEntryCount();
3957 aSeq = ::comphelper::StringSequence( nSelEntries );
3958 for ( sal_uInt16 n = 0; n < nSelEntries; n++ )
3959 aSeq.getArray()[n] = m_pBox->GetSelectEntry( n );
3961 return aSeq;
3964 //------------------------------------------------------------------
3965 void SAL_CALL FmXListBoxCell::selectItemPos(sal_Int16 nPos, sal_Bool bSelect) throw( RuntimeException )
3967 ::osl::MutexGuard aGuard( m_aMutex );
3969 if (m_pBox)
3970 m_pBox->SelectEntryPos( nPos, bSelect );
3973 //------------------------------------------------------------------
3974 void SAL_CALL FmXListBoxCell::selectItemsPos(const Sequence< sal_Int16 >& aPositions, sal_Bool bSelect) throw( RuntimeException )
3976 ::osl::MutexGuard aGuard( m_aMutex );
3978 if (m_pBox)
3980 for ( sal_uInt16 n = (sal_uInt16)aPositions.getLength(); n; )
3981 m_pBox->SelectEntryPos( (sal_uInt16) aPositions.getConstArray()[--n], bSelect );
3985 //------------------------------------------------------------------
3986 void SAL_CALL FmXListBoxCell::selectItem(const ::rtl::OUString& aItem, sal_Bool bSelect) throw( RuntimeException )
3988 ::osl::MutexGuard aGuard( m_aMutex );
3990 if (m_pBox)
3991 m_pBox->SelectEntry( aItem, bSelect );
3994 //------------------------------------------------------------------
3995 sal_Bool SAL_CALL FmXListBoxCell::isMutipleMode() throw( RuntimeException )
3997 ::osl::MutexGuard aGuard( m_aMutex );
3999 sal_Bool bMulti = sal_False;
4000 if (m_pBox)
4001 bMulti = m_pBox->IsMultiSelectionEnabled();
4002 return bMulti;
4005 //------------------------------------------------------------------
4006 void SAL_CALL FmXListBoxCell::setMultipleMode(sal_Bool bMulti) throw( RuntimeException )
4008 ::osl::MutexGuard aGuard( m_aMutex );
4010 if (m_pBox)
4011 m_pBox->EnableMultiSelection( bMulti );
4014 //------------------------------------------------------------------
4015 sal_Int16 SAL_CALL FmXListBoxCell::getDropDownLineCount() throw( RuntimeException )
4017 ::osl::MutexGuard aGuard( m_aMutex );
4019 sal_Int16 nLines = 0;
4020 if (m_pBox)
4021 nLines = m_pBox->GetDropDownLineCount();
4023 return nLines;
4026 //------------------------------------------------------------------
4027 void SAL_CALL FmXListBoxCell::setDropDownLineCount(sal_Int16 nLines) throw( RuntimeException )
4029 ::osl::MutexGuard aGuard( m_aMutex );
4031 if (m_pBox)
4032 m_pBox->SetDropDownLineCount( nLines );
4035 //------------------------------------------------------------------
4036 void SAL_CALL FmXListBoxCell::makeVisible(sal_Int16 nEntry) throw( RuntimeException )
4038 ::osl::MutexGuard aGuard( m_aMutex );
4040 if (m_pBox)
4041 m_pBox->SetTopEntry( nEntry );
4044 //------------------------------------------------------------------
4045 IMPL_LINK(FmXListBoxCell, OnSelect, VclWindowEvent*, _pEvent )
4047 if ( ( _pEvent->GetWindow() == m_pBox )
4048 && ( _pEvent->GetId() == VCLEVENT_LISTBOX_SELECT )
4051 OnDoubleClick( NULL );
4053 ::com::sun::star::awt::ItemEvent aEvent;
4054 aEvent.Source = *this;
4055 aEvent.Highlighted = sal_False;
4057 // Bei Mehrfachselektion 0xFFFF, sonst die ID
4058 aEvent.Selected = (m_pBox->GetSelectEntryCount() == 1 )
4059 ? m_pBox->GetSelectEntryPos() : 0xFFFF;
4061 m_aItemListeners.notifyEach( &awt::XItemListener::itemStateChanged, aEvent );
4063 return 1;
4067 //------------------------------------------------------------------
4068 IMPL_LINK( FmXListBoxCell, OnDoubleClick, void*, EMPTYARG )
4070 if (m_pBox)
4072 ::cppu::OInterfaceIteratorHelper aIt( m_aActionListeners );
4074 ::com::sun::star::awt::ActionEvent aEvent;
4075 aEvent.Source = *this;
4076 aEvent.ActionCommand = m_pBox->GetSelectEntry();
4078 while( aIt.hasMoreElements() )
4079 ((::com::sun::star::awt::XActionListener *)aIt.next())->actionPerformed( aEvent );
4081 return 1;
4085 /*************************************************************************/
4086 TYPEINIT1(FmXFilterCell, FmXGridCell);
4088 //------------------------------------------------------------------------------
4089 Reference< XInterface > FmXFilterCell_CreateInstance(const Reference< ::com::sun::star::lang::XMultiServiceFactory >& /*_rxFactory*/)
4091 return *new FmXFilterCell();
4094 DBG_NAME(FmXFilterCell);
4095 //------------------------------------------------------------------------------
4096 FmXFilterCell::FmXFilterCell(DbGridColumn* pColumn, DbCellControl* pControl)
4097 :FmXGridCell(pColumn, pControl)
4098 ,m_aTextListeners(m_aMutex)
4100 DBG_CTOR(FmXFilterCell,NULL);
4102 DBG_ASSERT( m_pCellControl->ISA( DbFilterField ), "FmXFilterCell::FmXFilterCell: invalid cell control!" );
4103 static_cast< DbFilterField* >( m_pCellControl )->SetCommitHdl( LINK( this, FmXFilterCell, OnCommit ) );
4106 //------------------------------------------------------------------
4107 FmXFilterCell::~FmXFilterCell()
4109 if (!OComponentHelper::rBHelper.bDisposed)
4111 acquire();
4112 dispose();
4115 DBG_DTOR(FmXFilterCell,NULL);
4118 // XUnoTunnel
4119 //------------------------------------------------------------------------------
4120 sal_Int64 SAL_CALL FmXFilterCell::getSomething( const Sequence< sal_Int8 >& _rIdentifier ) throw(RuntimeException)
4122 sal_Int64 nReturn(0);
4124 if ( (_rIdentifier.getLength() == 16)
4125 && (0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), _rIdentifier.getConstArray(), 16 ))
4128 nReturn = reinterpret_cast<sal_Int64>(this);
4131 return nReturn;
4134 //------------------------------------------------------------------------------
4135 const Sequence<sal_Int8>& FmXFilterCell::getUnoTunnelId()
4137 static Sequence< sal_Int8 > * pSeq = 0;
4138 if( !pSeq )
4140 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
4141 if( !pSeq )
4143 static Sequence< sal_Int8 > aSeq( 16 );
4144 rtl_createUuid( (sal_uInt8*)aSeq.getArray(), 0, sal_True );
4145 pSeq = &aSeq;
4148 return *pSeq;
4151 //------------------------------------------------------------------------------
4152 FmXFilterCell* FmXFilterCell::getImplementation(const Reference< ::com::sun::star::awt::XControl >& _rxObject)
4154 Reference< ::com::sun::star::lang::XUnoTunnel > xTunnel(
4155 _rxObject, UNO_QUERY);
4156 if (xTunnel.is())
4157 return reinterpret_cast<FmXFilterCell*>(xTunnel->getSomething(getUnoTunnelId()));
4158 return NULL;
4161 //------------------------------------------------------------------------------
4162 void FmXFilterCell::PaintCell( OutputDevice& rDev, const Rectangle& rRect )
4164 static_cast< DbFilterField* >( m_pCellControl )->PaintCell( rDev, rRect );
4167 // OComponentHelper
4168 //-----------------------------------------------------------------------------
4169 void FmXFilterCell::disposing()
4171 ::com::sun::star::lang::EventObject aEvt(*this);
4172 m_aTextListeners.disposeAndClear(aEvt);
4174 ((DbFilterField*)m_pCellControl)->SetCommitHdl(Link());
4176 FmXGridCell::disposing();
4179 //------------------------------------------------------------------
4180 Any SAL_CALL FmXFilterCell::queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw(RuntimeException)
4182 Any aReturn = FmXGridCell::queryAggregation(_rType);
4183 if (!aReturn.hasValue())
4184 aReturn = ::cppu::queryInterface(_rType,
4185 static_cast< ::com::sun::star::awt::XTextComponent* >(this)
4187 return aReturn;
4190 //-------------------------------------------------------------------------
4191 Sequence< ::com::sun::star::uno::Type > SAL_CALL FmXFilterCell::getTypes( ) throw(RuntimeException)
4193 Sequence< ::com::sun::star::uno::Type > aTypes = OComponentHelper::getTypes();
4195 sal_Int32 nLen = aTypes.getLength();
4196 aTypes.realloc(nLen + 2);
4197 aTypes.getArray()[nLen++] = ::getCppuType(static_cast< Reference< ::com::sun::star::awt::XControl >* >(NULL));
4198 aTypes.getArray()[nLen++] = ::getCppuType(static_cast< Reference< ::com::sun::star::awt::XTextComponent >* >(NULL));
4200 return aTypes;
4203 // ::com::sun::star::awt::XTextComponent
4204 //------------------------------------------------------------------------------
4205 void SAL_CALL FmXFilterCell::addTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException )
4207 m_aTextListeners.addInterface( l );
4210 //------------------------------------------------------------------------------
4211 void SAL_CALL FmXFilterCell::removeTextListener(const Reference< ::com::sun::star::awt::XTextListener >& l) throw( RuntimeException )
4213 m_aTextListeners.removeInterface( l );
4216 //------------------------------------------------------------------------------
4217 void SAL_CALL FmXFilterCell::setText( const ::rtl::OUString& aText ) throw( RuntimeException )
4219 ::osl::MutexGuard aGuard( m_aMutex );
4220 ((DbFilterField*)m_pCellControl)->SetText(aText);
4223 //------------------------------------------------------------------------------
4224 void SAL_CALL FmXFilterCell::insertText( const ::com::sun::star::awt::Selection& /*rSel*/, const ::rtl::OUString& /*aText*/ ) throw( RuntimeException )
4228 //------------------------------------------------------------------------------
4229 ::rtl::OUString SAL_CALL FmXFilterCell::getText() throw( RuntimeException )
4231 ::osl::MutexGuard aGuard( m_aMutex );
4232 return ((DbFilterField*)m_pCellControl)->GetText();
4235 //------------------------------------------------------------------------------
4236 ::rtl::OUString SAL_CALL FmXFilterCell::getSelectedText( void ) throw( RuntimeException )
4238 return getText();
4241 //------------------------------------------------------------------------------
4242 void SAL_CALL FmXFilterCell::setSelection( const ::com::sun::star::awt::Selection& /*aSelection*/ ) throw( RuntimeException )
4246 //------------------------------------------------------------------------------
4247 ::com::sun::star::awt::Selection SAL_CALL FmXFilterCell::getSelection( void ) throw( RuntimeException )
4249 return ::com::sun::star::awt::Selection();
4252 //------------------------------------------------------------------------------
4253 sal_Bool SAL_CALL FmXFilterCell::isEditable( void ) throw( RuntimeException )
4255 return sal_True;
4258 //------------------------------------------------------------------------------
4259 void SAL_CALL FmXFilterCell::setEditable( sal_Bool /*bEditable*/ ) throw( RuntimeException )
4263 //------------------------------------------------------------------------------
4264 sal_Int16 SAL_CALL FmXFilterCell::getMaxTextLen() throw( RuntimeException )
4266 return 0;
4269 //------------------------------------------------------------------------------
4270 void SAL_CALL FmXFilterCell::setMaxTextLen( sal_Int16 /*nLen*/ ) throw( RuntimeException )
4274 //------------------------------------------------------------------------------
4275 IMPL_LINK( FmXFilterCell, OnCommit, void*, EMPTYARG )
4277 ::cppu::OInterfaceIteratorHelper aIt( m_aTextListeners );
4278 ::com::sun::star::awt::TextEvent aEvt;
4279 aEvt.Source = *this;
4280 while( aIt.hasMoreElements() )
4281 ((::com::sun::star::awt::XTextListener *)aIt.next())->textChanged( aEvt );
4282 return 1;