1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gridcell.cxx,v $
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"
36 #include "fmresids.hrc"
37 #include "fmtools.hxx"
38 #include "gridcell.hxx"
39 #include "gridcols.hxx"
40 #include "sdbdatacolumn.hxx"
42 #include <com/sun/star/awt/LineEndFormat.hpp>
43 #include <com/sun/star/awt/MouseWheelBehavior.hpp>
44 #include <com/sun/star/awt/VisualEffect.hpp>
45 #include <com/sun/star/container/XChild.hpp>
46 #include <com/sun/star/container/XNamed.hpp>
47 #include <com/sun/star/form/FormComponentType.hpp>
48 #include <com/sun/star/form/XBoundComponent.hpp>
49 #include <com/sun/star/script/XEventAttacherManager.hpp>
50 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
51 #include <com/sun/star/sdbc/ColumnValue.hpp>
52 #include <com/sun/star/sdbc/DataType.hpp>
53 #include <com/sun/star/sdbc/XStatement.hpp>
54 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
55 #include <com/sun/star/util/NumberFormat.hpp>
56 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
57 #include <com/sun/star/util/XNumberFormatter.hpp>
59 #include <comphelper/extract.hxx>
60 #include <comphelper/numbers.hxx>
61 #include <comphelper/property.hxx>
62 #include <connectivity/formattedcolumnvalue.hxx>
63 #include <cppuhelper/typeprovider.hxx>
64 #include <i18npool/lang.h>
66 #include <rtl/math.hxx>
67 #include <svtools/calendar.hxx>
68 #include <svtools/fmtfield.hxx>
69 #include <svtools/numuno.hxx>
70 #include <svtools/svmedit.hxx>
71 #include <svx/dialmgr.hxx>
72 #include <toolkit/helper/vclunohelper.hxx>
73 #include <tools/diagnose_ex.h>
74 #include <tools/shl.hxx>
75 #include <vcl/longcurr.hxx>
80 using namespace ::connectivity
;
81 using namespace ::connectivity::simple
;
82 using namespace ::svxform
;
83 using namespace ::comphelper
;
84 using namespace ::svt
;
85 using namespace ::com::sun::star
;
86 using namespace ::com::sun::star::uno
;
87 using namespace ::com::sun::star::sdbc
;
88 using namespace ::com::sun::star::sdb
;
89 using namespace ::com::sun::star::beans
;
90 using namespace ::com::sun::star::form
;
92 using ::com::sun::star::util::XNumberFormatter
;
93 namespace MouseWheelBehavior
= ::com::sun::star::awt::MouseWheelBehavior
;
95 String INVALIDTEXT
= String::CreateFromAscii("###");
96 String OBJECTTEXT
= String::CreateFromAscii("<OBJECT>");
99 //==================================================================
101 //==================================================================
104 static LineEnd
getModelLineEndSetting( const Reference
< XPropertySet
>& _rxModel
)
106 LineEnd eFormat
= LINEEND_LF
;
110 sal_Int16 nLineEndFormat
= awt::LineEndFormat::LINE_FEED
;
112 Reference
< XPropertySetInfo
> xPSI
;
114 xPSI
= _rxModel
->getPropertySetInfo();
116 OSL_ENSURE( xPSI
.is(), "getModelLineEndSetting: invalid column model!" );
117 if ( xPSI
.is() && xPSI
->hasPropertyByName( FM_PROP_LINEENDFORMAT
) )
119 OSL_VERIFY( _rxModel
->getPropertyValue( FM_PROP_LINEENDFORMAT
) >>= nLineEndFormat
);
121 switch ( nLineEndFormat
)
123 case awt::LineEndFormat::CARRIAGE_RETURN
: eFormat
= LINEEND_CR
; break;
124 case awt::LineEndFormat::LINE_FEED
: eFormat
= LINEEND_LF
; break;
125 case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED
: eFormat
= LINEEND_CRLF
; break;
127 OSL_ENSURE( sal_False
, "getModelLineEndSetting: what's this?" );
131 catch( const Exception
& )
133 OSL_ENSURE( sal_False
, "getModelLineEndSetting: caught an exception!" );
139 //==================================================================
141 //==================================================================
142 //------------------------------------------------------------------------------
143 CellControllerRef
DbGridColumn::s_xEmptyController
;
145 //------------------------------------------------------------------------------
146 void DbGridColumn::CreateControl(sal_Int32 _nFieldPos
, const Reference
< ::com::sun::star::beans::XPropertySet
>& xField
, sal_Int32 nTypeId
)
150 m_nTypeId
= (sal_Int16
)nTypeId
;
151 if (xField
!= m_xField
)
155 xField
->getPropertyValue(FM_PROP_FORMATKEY
) >>= m_nFormatKey
;
156 m_nFieldPos
= (sal_Int16
)_nFieldPos
;
157 m_bReadOnly
= ::comphelper::getBOOL(xField
->getPropertyValue(FM_PROP_ISREADONLY
));
158 m_bAutoValue
= ::comphelper::getBOOL(xField
->getPropertyValue(FM_PROP_AUTOINCREMENT
));
159 m_nFieldType
= (sal_Int16
)::comphelper::getINT32(xField
->getPropertyValue(FM_PROP_FIELDTYPE
));
161 switch (m_nFieldType
)
165 case DataType::TIMESTAMP
:
166 m_bDateTime
= sal_True
;
169 case DataType::BOOLEAN
:
170 case DataType::TINYINT
:
171 case DataType::SMALLINT
:
172 case DataType::INTEGER
:
173 case DataType::BIGINT
:
174 case DataType::FLOAT
:
176 case DataType::DOUBLE
:
177 case DataType::NUMERIC
:
178 case DataType::DECIMAL
:
179 m_nAlign
= ::com::sun::star::awt::TextAlign::RIGHT
;
180 m_bNumeric
= sal_True
;
183 m_nAlign
= ::com::sun::star::awt::TextAlign::LEFT
;
188 DbCellControl
* pCellControl
= NULL
;
189 if (m_rParent
.IsFilterMode())
191 pCellControl
= new DbFilterField(m_rParent
.getServiceManager(),*this);
198 case TYPE_CHECKBOX
: pCellControl
= new DbCheckBox(*this); break;
199 case TYPE_COMBOBOX
: pCellControl
= new DbComboBox(*this); break;
200 case TYPE_CURRENCYFIELD
: pCellControl
= new DbCurrencyField(*this); break;
201 case TYPE_DATEFIELD
: pCellControl
= new DbDateField(*this); break;
202 case TYPE_LISTBOX
: pCellControl
= new DbListBox(*this); break;
203 case TYPE_NUMERICFIELD
: pCellControl
= new DbNumericField(*this); break;
204 case TYPE_PATTERNFIELD
: pCellControl
= new DbPatternField( *this, ::comphelper::ComponentContext( m_rParent
.getServiceManager() ) ); break;
205 case TYPE_TEXTFIELD
: pCellControl
= new DbTextField(*this); break;
206 case TYPE_TIMEFIELD
: pCellControl
= new DbTimeField(*this); break;
207 case TYPE_FORMATTEDFIELD
: pCellControl
= new DbFormattedField(*this); break;
209 DBG_ERROR("DbGridColumn::CreateControl: Unknown Column");
214 Reference
< XRowSet
> xCur
;
215 if (m_rParent
.getDataSource())
216 xCur
= Reference
< XRowSet
> ((Reference
< XInterface
>)*m_rParent
.getDataSource(), UNO_QUERY
);
217 // TODO : the cursor wrapper should use an XRowSet interface, too
219 pCellControl
->Init( m_rParent
.GetDataWindow(), xCur
);
221 // now create the control wrapper
222 if (m_rParent
.IsFilterMode())
223 m_pCell
= new FmXFilterCell(this, pCellControl
);
228 case TYPE_CHECKBOX
: m_pCell
= new FmXCheckBoxCell( this, *pCellControl
); break;
229 case TYPE_LISTBOX
: m_pCell
= new FmXListBoxCell( this, *pCellControl
); break;
230 case TYPE_COMBOBOX
: m_pCell
= new FmXComboBoxCell( this, *pCellControl
); break;
232 m_pCell
= new FmXEditCell( this, *pCellControl
);
238 impl_toggleScriptManager_nothrow( true );
240 // only if we use have a bound field, we use a a controller for displaying the
241 // window in the grid
243 m_xController
= pCellControl
->CreateController();
246 //------------------------------------------------------------------------------
247 void DbGridColumn::impl_toggleScriptManager_nothrow( bool _bAttach
)
251 Reference
< container::XChild
> xChild( m_xModel
, UNO_QUERY_THROW
);
252 Reference
< script::XEventAttacherManager
> xManager( xChild
->getParent(), UNO_QUERY_THROW
);
253 Reference
< container::XIndexAccess
> xContainer( xChild
->getParent(), UNO_QUERY_THROW
);
255 sal_Int32
nIndexInParent( getElementPos( xContainer
, m_xModel
) );
257 Reference
< XInterface
> xCellInterface( *m_pCell
, UNO_QUERY
);
259 xManager
->attach( nIndexInParent
, xCellInterface
, makeAny( xCellInterface
) );
261 xManager
->detach( nIndexInParent
, xCellInterface
);
263 catch( const Exception
& )
265 DBG_UNHANDLED_EXCEPTION();
269 //------------------------------------------------------------------------------
270 void DbGridColumn::UpdateFromField(const DbGridRow
* pRow
, const Reference
< XNumberFormatter
>& xFormatter
)
272 if (m_pCell
&& m_pCell
->ISA(FmXFilterCell
))
273 PTR_CAST(FmXFilterCell
, m_pCell
)->Update();
274 else if (pRow
&& pRow
->IsValid() && m_nFieldPos
>= 0 && m_pCell
&& pRow
->HasField(m_nFieldPos
))
276 PTR_CAST(FmXDataCell
, m_pCell
)->UpdateFromField( pRow
->GetField( m_nFieldPos
).getColumn(), xFormatter
);
280 //------------------------------------------------------------------------------
281 sal_Bool
DbGridColumn::Commit()
283 sal_Bool bResult
= sal_True
;
284 if (!m_bInSave
&& m_pCell
)
286 m_bInSave
= sal_True
;
287 bResult
= m_pCell
->Commit();
289 // store the data into the model
290 FmXDataCell
* pDataCell
= PTR_CAST(FmXDataCell
, m_pCell
);
291 if (bResult
&& pDataCell
)
293 Reference
< ::com::sun::star::form::XBoundComponent
> xComp(m_xModel
, UNO_QUERY
);
295 bResult
= xComp
->commit();
297 m_bInSave
= sal_False
;
302 //------------------------------------------------------------------------------
303 DbGridColumn::~DbGridColumn()
308 //------------------------------------------------------------------------------
309 void DbGridColumn::setModel(::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> _xModel
)
312 impl_toggleScriptManager_nothrow( false );
317 impl_toggleScriptManager_nothrow( true );
320 //------------------------------------------------------------------------------
321 void DbGridColumn::Clear()
325 impl_toggleScriptManager_nothrow( false );
332 m_xController
= NULL
;
337 m_bReadOnly
= sal_True
;
338 m_bAutoValue
= sal_False
;
339 m_nFieldType
= DataType::OTHER
;
342 //------------------------------------------------------------------------------
343 sal_Int16
DbGridColumn::SetAlignment(sal_Int16 _nAlign
)
350 m_xField
->getPropertyValue(FM_PROP_FIELDTYPE
) >>= nType
;
354 case DataType::NUMERIC
:
355 case DataType::DECIMAL
:
356 case DataType::DOUBLE
:
358 case DataType::BIGINT
:
359 case DataType::INTEGER
:
360 case DataType::SMALLINT
:
361 case DataType::TINYINT
:
364 case DataType::TIMESTAMP
:
365 _nAlign
= ::com::sun::star::awt::TextAlign::RIGHT
;
368 case DataType::BOOLEAN
:
369 _nAlign
= ::com::sun::star::awt::TextAlign::CENTER
;
372 _nAlign
= ::com::sun::star::awt::TextAlign::LEFT
;
377 _nAlign
= ::com::sun::star::awt::TextAlign::LEFT
;
381 if (m_pCell
&& m_pCell
->isAlignedController())
382 m_pCell
->AlignControl(m_nAlign
);
387 //------------------------------------------------------------------------------
388 sal_Int16
DbGridColumn::SetAlignmentFromModel(sal_Int16 nStandardAlign
)
390 Any
aAlign( m_xModel
->getPropertyValue(FM_PROP_ALIGN
));
391 if (aAlign
.hasValue())
393 sal_Int16 nTest
= sal_Int16();
394 if (aAlign
>>= nTest
)
395 nStandardAlign
= nTest
;
397 return SetAlignment(nStandardAlign
);
400 //------------------------------------------------------------------------------
401 void DbGridColumn::setLock(sal_Bool _bLock
)
403 if (m_bLocked
== _bLock
)
407 // is the column we represent active ?
409 return; // no, it isn't (or at least it shouldn't be ...)
411 if (m_rParent
.GetCurColumnId() == m_nId
)
413 m_rParent
.DeactivateCell();
414 m_rParent
.ActivateCell(m_rParent
.GetCurRow(), m_rParent
.GetCurColumnId());
418 //------------------------------------------------------------------------------
419 String
DbGridColumn::GetCellText(const DbGridRow
* pRow
, const Reference
< XNumberFormatter
>& xFormatter
) const
422 if (m_pCell
&& m_pCell
->ISA(FmXFilterCell
))
425 if (!pRow
|| !pRow
->IsValid())
427 else if (pRow
->HasField(m_nFieldPos
))
429 aText
= GetCellText( pRow
->GetField( m_nFieldPos
).getColumn(), xFormatter
);
434 //------------------------------------------------------------------------------
435 String
DbGridColumn::GetCellText(const Reference
< ::com::sun::star::sdb::XColumn
>& xField
, const Reference
< XNumberFormatter
>& xFormatter
) const
440 FmXTextCell
* pTextCell
= PTR_CAST(FmXTextCell
, m_pCell
);
442 aText
= pTextCell
->GetText(xField
, xFormatter
);
449 //------------------------------------------------------------------------------
450 Reference
< ::com::sun::star::sdb::XColumn
> DbGridColumn::GetCurrentFieldValue() const
452 Reference
< ::com::sun::star::sdb::XColumn
> xField
;
453 const DbGridRowRef xRow
= m_rParent
.GetCurrentRow();
454 if (xRow
.Is() && xRow
->HasField(m_nFieldPos
))
456 xField
= xRow
->GetField(m_nFieldPos
).getColumn();
461 //------------------------------------------------------------------------------
462 void DbGridColumn::Paint(OutputDevice
& rDev
,
463 const Rectangle
& rRect
,
464 const DbGridRow
* pRow
,
465 const Reference
< XNumberFormatter
>& xFormatter
)
467 bool bEnabled
= ( rDev
.GetOutDevType() != OUTDEV_WINDOW
)
468 || ( static_cast< Window
& >( rDev
).IsEnabled() );
470 FmXDataCell
* pDataCell
= PTR_CAST(FmXDataCell
, m_pCell
);
473 if (!pRow
|| !pRow
->IsValid())
475 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_CENTER
;
477 nStyle
|= TEXT_DRAW_DISABLE
;
479 rDev
.DrawText(rRect
, INVALIDTEXT
, nStyle
);
481 else if (m_bAutoValue
&& pRow
->IsNew())
483 static String
aAutoText(SVX_RES(RID_STR_AUTOFIELD
));
484 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_VCENTER
;
486 nStyle
|= TEXT_DRAW_DISABLE
;
488 switch (GetAlignment())
490 case ::com::sun::star::awt::TextAlign::RIGHT
:
491 nStyle
|= TEXT_DRAW_RIGHT
;
493 case ::com::sun::star::awt::TextAlign::CENTER
:
494 nStyle
|= TEXT_DRAW_CENTER
;
497 nStyle
|= TEXT_DRAW_LEFT
;
500 rDev
.DrawText(rRect
, aAutoText
, nStyle
);
502 else if (pRow
->HasField(m_nFieldPos
))
504 pDataCell
->PaintFieldToCell(rDev
, rRect
, pRow
->GetField( m_nFieldPos
).getColumn(), xFormatter
);
509 if (!pRow
|| !pRow
->IsValid())
511 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_CENTER
;
513 nStyle
|= TEXT_DRAW_DISABLE
;
515 rDev
.DrawText(rRect
, INVALIDTEXT
, nStyle
);
517 else if (pRow
->HasField(m_nFieldPos
) && m_bObject
)
519 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_CENTER
;
521 nStyle
|= TEXT_DRAW_DISABLE
;
522 rDev
.DrawText(rRect
, OBJECTTEXT
, nStyle
);
525 else if ( m_pCell
->ISA( FmXFilterCell
) )
526 static_cast< FmXFilterCell
* >( m_pCell
)->PaintCell( rDev
, rRect
);
529 //------------------------------------------------------------------------------
530 void DbGridColumn::ImplInitWindow( Window
& rParent
, const InitWindowFacet _eInitWhat
)
533 m_pCell
->ImplInitWindow( rParent
, _eInitWhat
);
536 //==============================================================================
538 //==============================================================================
539 TYPEINIT0( DbCellControl
)
540 TYPEINIT1( DbLimitedLengthField
, DbCellControl
)
541 TYPEINIT1( DbTextField
, DbLimitedLengthField
)
542 TYPEINIT1( DbFormattedField
, DbLimitedLengthField
)
543 TYPEINIT1( DbCheckBox
, DbCellControl
)
544 TYPEINIT1( DbComboBox
, DbCellControl
)
545 TYPEINIT1( DbListBox
, DbCellControl
)
546 TYPEINIT1( DbPatternField
, DbCellControl
)
547 TYPEINIT1( DbSpinField
, DbCellControl
)
548 TYPEINIT1( DbDateField
, DbSpinField
)
549 TYPEINIT1( DbTimeField
, DbSpinField
)
550 TYPEINIT1( DbCurrencyField
, DbSpinField
)
551 TYPEINIT1( DbNumericField
, DbSpinField
)
552 TYPEINIT1( DbFilterField
, DbCellControl
)
554 //------------------------------------------------------------------------------
555 DbCellControl::DbCellControl( DbGridColumn
& _rColumn
, sal_Bool
/*_bText*/ )
556 :OPropertyChangeListener(m_aMutex
)
557 ,m_bTransparent( sal_False
)
558 ,m_bAlignedController( sal_True
)
559 ,m_bAccessingValueProperty( sal_False
)
560 ,m_rColumn( _rColumn
)
564 Reference
< XPropertySet
> xColModelProps( _rColumn
.getModel(), UNO_QUERY
);
565 if ( xColModelProps
.is() )
567 // if our model's format key changes we want to propagate the new value to our windows
568 m_pModelChangeBroadcaster
= new ::comphelper::OPropertyChangeMultiplexer(this, Reference
< ::com::sun::star::beans::XPropertySet
> (_rColumn
.getModel(), UNO_QUERY
));
569 m_pModelChangeBroadcaster
->acquire();
571 // be listener for some common properties
572 implDoPropertyListening( FM_PROP_READONLY
, sal_False
);
573 implDoPropertyListening( FM_PROP_ENABLED
, sal_False
);
575 // add as listener for all know "value" properties
576 implDoPropertyListening( FM_PROP_VALUE
, sal_False
);
577 implDoPropertyListening( FM_PROP_STATE
, sal_False
);
578 implDoPropertyListening( FM_PROP_TEXT
, sal_False
);
579 implDoPropertyListening( FM_PROP_EFFECTIVE_VALUE
, sal_False
);
583 //------------------------------------------------------------------------------
584 void DbCellControl::implDoPropertyListening( const ::rtl::OUString
& _rPropertyName
, sal_Bool _bWarnIfNotExistent
)
588 Reference
< XPropertySet
> xColModelProps( m_rColumn
.getModel(), UNO_QUERY
);
589 Reference
< XPropertySetInfo
> xPSI
;
590 if ( xColModelProps
.is() )
591 xPSI
= xColModelProps
->getPropertySetInfo();
593 DBG_ASSERT( !_bWarnIfNotExistent
|| ( xPSI
.is() && xPSI
->hasPropertyByName( _rPropertyName
) ),
594 "DbCellControl::doPropertyListening: no property set info or non-existent property!" );
595 (void)_bWarnIfNotExistent
;
597 if ( xPSI
.is() && xPSI
->hasPropertyByName( _rPropertyName
) )
598 m_pModelChangeBroadcaster
->addProperty( _rPropertyName
);
600 catch( const Exception
& )
602 DBG_ERROR( "DbCellControl::doPropertyListening: caught an exception!" );
606 //------------------------------------------------------------------------------
607 void DbCellControl::doPropertyListening( const ::rtl::OUString
& _rPropertyName
)
609 implDoPropertyListening( _rPropertyName
);
612 //------------------------------------------------------------------------------
613 DbCellControl::~DbCellControl()
615 if ( m_pModelChangeBroadcaster
)
617 m_pModelChangeBroadcaster
->dispose();
618 m_pModelChangeBroadcaster
->release();
619 m_pModelChangeBroadcaster
= NULL
;
620 // no delete, this is done implicitly
627 //------------------------------------------------------------------------------
628 void DbCellControl::implValuePropertyChanged( )
630 OSL_ENSURE( !isValuePropertyLocked(),
631 "DbCellControl::implValuePropertyChanged: not to be called with the value property locked!" );
635 if ( m_rColumn
.getModel().is() )
636 updateFromModel( m_rColumn
.getModel() );
640 //------------------------------------------------------------------------------
641 void DbCellControl::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& /*_rxModel*/ )
643 // nothing to to here
646 //------------------------------------------------------------------------------
647 void DbCellControl::_propertyChanged(const PropertyChangeEvent
& _rEvent
) throw(RuntimeException
)
649 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
651 Reference
< XPropertySet
> xSourceProps( _rEvent
.Source
, UNO_QUERY
);
653 if ( _rEvent
.PropertyName
.equals( FM_PROP_VALUE
)
654 || _rEvent
.PropertyName
.equals( FM_PROP_STATE
)
655 || _rEvent
.PropertyName
.equals( FM_PROP_TEXT
)
656 || _rEvent
.PropertyName
.equals( FM_PROP_EFFECTIVE_VALUE
)
658 { // it was one of the known "value" properties
659 if ( !isValuePropertyLocked() )
661 implValuePropertyChanged( );
664 else if ( _rEvent
.PropertyName
.equals( FM_PROP_READONLY
) )
666 implAdjustReadOnly( xSourceProps
);
668 else if ( _rEvent
.PropertyName
.equals( FM_PROP_ENABLED
) )
670 implAdjustEnabled( xSourceProps
);
673 implAdjustGenericFieldSetting( xSourceProps
);
676 //------------------------------------------------------------------------------
677 sal_Bool
DbCellControl::Commit()
679 // lock the listening for value property changes
681 // commit the content of the control into the model's value property
682 sal_Bool bReturn
= commitControl();
683 // unlock the listening for value property changes
684 unlockValueProperty();
689 //------------------------------------------------------------------------------
690 void DbCellControl::ImplInitWindow( Window
& rParent
, const InitWindowFacet _eInitWhat
)
692 Window
* pWindows
[] = { m_pPainter
, m_pWindow
};
694 if ( ( _eInitWhat
& InitWritingMode
) != 0 )
696 for ( size_t i
=0; i
< sizeof( pWindows
) / sizeof( pWindows
[0] ); ++i
)
699 pWindows
[i
]->EnableRTL( rParent
.IsRTLEnabled() );
703 if ( ( _eInitWhat
& InitFont
) != 0 )
705 for (size_t i
=0; i
< sizeof(pWindows
)/sizeof(pWindows
[0]); ++i
)
710 pWindows
[i
]->SetZoom( rParent
.GetZoom() );
712 const StyleSettings
& rStyleSettings
= pWindows
[i
]->GetSettings().GetStyleSettings();
713 Font aFont
= rStyleSettings
.GetFieldFont();
714 aFont
.SetTransparent( isTransparent() );
716 if ( rParent
.IsControlFont() )
718 pWindows
[i
]->SetControlFont( rParent
.GetControlFont() );
719 aFont
.Merge( rParent
.GetControlFont() );
722 pWindows
[i
]->SetControlFont();
724 pWindows
[i
]->SetZoomedPointFont( aFont
);
728 if ( ( ( _eInitWhat
& InitFont
) != 0 )
729 || ( ( _eInitWhat
& InitForeground
) != 0 )
732 Color
aTextColor( rParent
.IsControlForeground() ? rParent
.GetControlForeground() : rParent
.GetTextColor() );
734 sal_Bool bTextLineColor
= rParent
.IsTextLineColor();
735 Color
aTextLineColor( rParent
.GetTextLineColor() );
737 for (size_t i
=0; i
< sizeof(pWindows
)/sizeof(pWindows
[0]); ++i
)
741 pWindows
[i
]->SetTextColor(aTextColor
);
742 if (rParent
.IsControlForeground())
743 pWindows
[i
]->SetControlForeground(aTextColor
);
746 pWindows
[i
]->SetTextLineColor();
748 pWindows
[i
]->SetTextLineColor(aTextLineColor
);
753 if ( ( _eInitWhat
& InitBackground
) != 0 )
755 if (rParent
.IsControlBackground())
757 Color
aColor( rParent
.GetControlBackground());
758 for (size_t i
=0; i
< sizeof(pWindows
)/sizeof(pWindows
[0]); ++i
)
762 if ( isTransparent() )
763 pWindows
[i
]->SetBackground();
766 pWindows
[i
]->SetBackground(aColor
);
767 pWindows
[i
]->SetControlBackground(aColor
);
769 pWindows
[i
]->SetFillColor(aColor
);
777 if ( isTransparent() )
778 m_pPainter
->SetBackground();
780 m_pPainter
->SetBackground(rParent
.GetBackground());
781 m_pPainter
->SetFillColor(rParent
.GetFillColor());
786 if ( isTransparent() )
787 m_pWindow
->SetBackground(rParent
.GetBackground());
789 m_pWindow
->SetFillColor(rParent
.GetFillColor());
795 //------------------------------------------------------------------------------
796 void DbCellControl::implAdjustReadOnly( const Reference
< XPropertySet
>& _rxModel
)
798 DBG_ASSERT( m_pWindow
, "DbCellControl::implAdjustReadOnly: not to be called without window!" );
799 DBG_ASSERT( _rxModel
.is(), "DbCellControl::implAdjustReadOnly: invalid model!" );
800 if ( m_pWindow
&& _rxModel
.is() )
802 Edit
* pEditWindow
= dynamic_cast< Edit
* >( m_pWindow
);
805 sal_Bool bReadOnly
= sal_True
;
806 _rxModel
->getPropertyValue( FM_PROP_READONLY
) >>= bReadOnly
;
807 static_cast< Edit
* >( m_pWindow
)->SetReadOnly( m_rColumn
.IsReadOnly() || bReadOnly
);
812 //------------------------------------------------------------------------------
813 void DbCellControl::implAdjustEnabled( const Reference
< XPropertySet
>& _rxModel
)
815 DBG_ASSERT( m_pWindow
, "DbCellControl::implAdjustEnabled: not to be called without window!" );
816 DBG_ASSERT( _rxModel
.is(), "DbCellControl::implAdjustEnabled: invalid model!" );
817 if ( m_pWindow
&& _rxModel
.is() )
819 sal_Bool bEnable
= sal_True
;
820 _rxModel
->getPropertyValue( FM_PROP_ENABLED
) >>= bEnable
;
821 m_pWindow
->Enable( bEnable
);
825 //------------------------------------------------------------------------------
826 void DbCellControl::Init( Window
& rParent
, const Reference
< XRowSet
>& _rxCursor
)
828 ImplInitWindow( rParent
, InitAll
);
833 if ( isAlignedController() )
834 AlignControl( m_rColumn
.GetAlignment() );
838 // some other common properties
839 Reference
< XPropertySet
> xModel( m_rColumn
.getModel(), UNO_SET_THROW
);
840 Reference
< XPropertySetInfo
> xModelPSI( xModel
->getPropertySetInfo(), UNO_SET_THROW
);
842 if ( xModelPSI
->hasPropertyByName( FM_PROP_READONLY
) )
844 implAdjustReadOnly( xModel
);
847 if ( xModelPSI
->hasPropertyByName( FM_PROP_ENABLED
) )
849 implAdjustEnabled( xModel
);
852 if ( xModelPSI
->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR
) )
854 sal_Int16 nWheelBehavior
= MouseWheelBehavior::SCROLL_FOCUS_ONLY
;
855 OSL_VERIFY( xModel
->getPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR
) >>= nWheelBehavior
);
856 USHORT nVclSetting
= MOUSE_WHEEL_FOCUS_ONLY
;
857 switch ( nWheelBehavior
)
859 case MouseWheelBehavior::SCROLL_DISABLED
: nVclSetting
= MOUSE_WHEEL_DISABLE
; break;
860 case MouseWheelBehavior::SCROLL_FOCUS_ONLY
: nVclSetting
= MOUSE_WHEEL_FOCUS_ONLY
; break;
861 case MouseWheelBehavior::SCROLL_ALWAYS
: nVclSetting
= MOUSE_WHEEL_ALWAYS
; break;
863 OSL_ENSURE( false, "DbCellControl::Init: invalid MouseWheelBehavior!" );
867 AllSettings aSettings
= m_pWindow
->GetSettings();
868 MouseSettings aMouseSettings
= aSettings
.GetMouseSettings();
869 aMouseSettings
.SetWheelBehavior( nVclSetting
);
870 aSettings
.SetMouseSettings( aMouseSettings
);
871 m_pWindow
->SetSettings( aSettings
, TRUE
);
874 catch( const Exception
& )
876 DBG_UNHANDLED_EXCEPTION();
879 m_xCursor
= _rxCursor
;
882 //------------------------------------------------------------------------------
883 void DbCellControl::SetTextLineColor()
886 m_pWindow
->SetTextLineColor();
888 m_pPainter
->SetTextLineColor();
891 //------------------------------------------------------------------------------
892 void DbCellControl::SetTextLineColor(const Color
& _rColor
)
895 m_pWindow
->SetTextLineColor(_rColor
);
897 m_pPainter
->SetTextLineColor(_rColor
);
902 static void lcl_implAlign( Window
* _pWindow
, WinBits _nAlignmentBit
)
904 WinBits nStyle
= _pWindow
->GetStyle();
905 nStyle
&= ~(WB_LEFT
| WB_RIGHT
| WB_CENTER
);
906 _pWindow
->SetStyle( nStyle
| _nAlignmentBit
);
910 //------------------------------------------------------------------------------
911 void DbCellControl::AlignControl(sal_Int16 nAlignment
)
913 WinBits nAlignmentBit
= 0;
916 case ::com::sun::star::awt::TextAlign::RIGHT
:
917 nAlignmentBit
= WB_RIGHT
;
919 case ::com::sun::star::awt::TextAlign::CENTER
:
920 nAlignmentBit
= WB_CENTER
;
923 nAlignmentBit
= WB_LEFT
;
926 lcl_implAlign( m_pWindow
, nAlignmentBit
);
928 lcl_implAlign( m_pPainter
, nAlignmentBit
);
931 //------------------------------------------------------------------------------
932 void DbCellControl::PaintCell( OutputDevice
& _rDev
, const Rectangle
& _rRect
)
934 if ( m_pPainter
->GetParent() == &_rDev
)
936 m_pPainter
->SetPaintTransparent( sal_True
);
937 m_pPainter
->SetBackground( );
938 m_pPainter
->SetControlBackground( _rDev
.GetFillColor() );
939 m_pPainter
->SetControlForeground( _rDev
.GetTextColor() );
940 m_pPainter
->SetTextColor( _rDev
.GetTextColor() );
941 m_pPainter
->SetTextFillColor( _rDev
.GetTextColor() );
943 Font
aFont( _rDev
.GetFont() );
944 aFont
.SetTransparent( TRUE
);
945 m_pPainter
->SetFont( aFont
);
947 m_pPainter
->SetPosSizePixel( _rRect
.TopLeft(), _rRect
.GetSize() );
949 m_pPainter
->Update();
950 m_pPainter
->SetParentUpdateMode( sal_False
);
952 m_pPainter
->SetParentUpdateMode( sal_True
);
955 m_pPainter
->Draw( &_rDev
, _rRect
.TopLeft(), _rRect
.GetSize(), 0 );
958 //------------------------------------------------------------------------------
959 void DbCellControl::PaintFieldToCell( OutputDevice
& _rDev
, const Rectangle
& _rRect
, const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
961 m_pPainter
->SetText( GetFormatText( _rxField
, _rxFormatter
) );
962 PaintCell( _rDev
, _rRect
);
965 //------------------------------------------------------------------------------
966 double DbCellControl::GetValue(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
) const
969 if (m_rColumn
.IsNumeric())
973 fValue
= _rxField
->getDouble();
975 catch(const Exception
&) { }
979 sal_Bool bSuccess
= sal_False
;
982 fValue
= _rxField
->getDouble();
985 catch(const Exception
&) { }
990 fValue
= xFormatter
->convertStringToNumber(m_rColumn
.GetKey(), _rxField
->getString());
992 catch(const Exception
&) { }
998 //------------------------------------------------------------------------------
999 void DbCellControl::invalidatedController()
1001 m_rColumn
.GetParent().refreshController(m_rColumn
.GetId(), DbGridControl::GrantCellControlAccess());
1004 /*************************************************************************/
1006 /*************************************************************************/
1008 //==============================================================================
1009 //= DbLimitedLengthField
1010 //==============================================================================
1011 //------------------------------------------------------------------------------
1012 DbLimitedLengthField::DbLimitedLengthField( DbGridColumn
& _rColumn
)
1013 :DbCellControl( _rColumn
)
1015 doPropertyListening( FM_PROP_MAXTEXTLEN
);
1018 //------------------------------------------------------------------------------
1019 void DbLimitedLengthField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
1021 DBG_ASSERT( m_pWindow
, "DbLimitedLengthField::implAdjustGenericFieldSetting: not to be called without window!" );
1022 DBG_ASSERT( _rxModel
.is(), "DbLimitedLengthField::implAdjustGenericFieldSetting: invalid model!" );
1023 if ( m_pWindow
&& _rxModel
.is() )
1025 sal_Int16 nMaxLen
= 0;
1026 _rxModel
->getPropertyValue( FM_PROP_MAXTEXTLEN
) >>= nMaxLen
;
1027 implSetMaxTextLen( nMaxLen
);
1031 //------------------------------------------------------------------------------
1032 void DbLimitedLengthField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen
)
1034 dynamic_cast< Edit
* >( m_pWindow
)->SetMaxTextLen( _nMaxLen
);
1036 dynamic_cast< Edit
* >( m_pPainter
)->SetMaxTextLen( _nMaxLen
);
1039 //==============================================================================
1041 //==============================================================================
1042 //------------------------------------------------------------------------------
1043 DbTextField::DbTextField(DbGridColumn
& _rColumn
)
1044 :DbLimitedLengthField(_rColumn
)
1046 ,m_pPainterImplementation( NULL
)
1047 ,m_nKeyType(::com::sun::star::util::NumberFormat::TEXT
)
1048 ,m_bIsSimpleEdit( sal_True
)
1052 //------------------------------------------------------------------------------
1053 DbTextField::~DbTextField( )
1055 DELETEZ( m_pPainterImplementation
);
1059 //------------------------------------------------------------------------------
1060 void DbTextField::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
1062 sal_Int16 nAlignment
= m_rColumn
.SetAlignmentFromModel(-1);
1064 Reference
< XPropertySet
> xModel( m_rColumn
.getModel() );
1066 WinBits nStyle
= WB_LEFT
;
1069 case awt::TextAlign::RIGHT
:
1073 case awt::TextAlign::CENTER
:
1078 // is this a multi-line field?
1079 sal_Bool bIsMultiLine
= sal_False
;
1084 OSL_VERIFY( xModel
->getPropertyValue( FM_PROP_MULTILINE
) >>= bIsMultiLine
);
1087 catch( const Exception
& )
1089 OSL_ENSURE( sal_False
, "DbTextField::Init: caught an exception while determining the multi-line capabilities!" );
1092 m_bIsSimpleEdit
= !bIsMultiLine
;
1095 m_pWindow
= new MultiLineTextCell( &rParent
, nStyle
);
1096 m_pEdit
= new MultiLineEditImplementation( *static_cast< MultiLineTextCell
* >( m_pWindow
) );
1098 m_pPainter
= new MultiLineTextCell( &rParent
, nStyle
);
1099 m_pPainterImplementation
= new MultiLineEditImplementation( *static_cast< MultiLineTextCell
* >( m_pPainter
) );
1103 m_pWindow
= new Edit( &rParent
, nStyle
);
1104 m_pEdit
= new EditImplementation( *static_cast< Edit
* >( m_pWindow
) );
1106 m_pPainter
= new Edit( &rParent
, nStyle
);
1107 m_pPainterImplementation
= new EditImplementation( *static_cast< Edit
* >( m_pPainter
) );
1110 if ( WB_LEFT
== nStyle
)
1112 // this is so that when getting the focus, the selection is oriented left-to-right
1113 AllSettings aSettings
= m_pWindow
->GetSettings();
1114 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
1115 aStyleSettings
.SetSelectionOptions(
1116 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
1117 aSettings
.SetStyleSettings(aStyleSettings
);
1118 m_pWindow
->SetSettings(aSettings
);
1121 implAdjustGenericFieldSetting( xModel
);
1123 if (m_rColumn
.GetParent().getNumberFormatter().is() && m_rColumn
.GetKey())
1124 m_nKeyType
= comphelper::getNumberFormatType(m_rColumn
.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn
.GetKey());
1126 DbLimitedLengthField::Init( rParent
, xCursor
);
1129 //------------------------------------------------------------------------------
1130 CellControllerRef
DbTextField::CreateController() const
1132 return new EditCellController( m_pEdit
);
1135 //------------------------------------------------------------------------------
1136 void DbTextField::PaintFieldToCell( OutputDevice
& _rDev
, const Rectangle
& _rRect
, const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
1138 if ( m_pPainterImplementation
)
1139 m_pPainterImplementation
->SetText( GetFormatText( _rxField
, _rxFormatter
, NULL
) );
1141 DbLimitedLengthField::PaintFieldToCell( _rDev
, _rRect
, _rxField
, _rxFormatter
);
1144 //------------------------------------------------------------------------------
1145 String
DbTextField::GetFormatText(const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
, Color
** /*ppColor*/)
1147 ::rtl::OUString aString
;
1148 if ( _rxField
.is() )
1151 aString
= getValue( _rxField
, xFormatter
, m_rColumn
.GetParent().getNullDate(), m_rColumn
.GetKey(), m_nKeyType
);
1153 catch( const Exception
& )
1155 DBG_UNHANDLED_EXCEPTION();
1161 //------------------------------------------------------------------------------
1162 void DbTextField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
)
1164 m_pEdit
->SetText( GetFormatText( _rxField
, xFormatter
) );
1165 m_pEdit
->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1168 //------------------------------------------------------------------------------
1169 void DbTextField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1171 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbTextField::updateFromModel: invalid call!" );
1173 ::rtl::OUString sText
;
1174 _rxModel
->getPropertyValue( FM_PROP_TEXT
) >>= sText
;
1176 xub_StrLen nMaxTextLen
= m_pEdit
->GetMaxTextLen();
1177 if ( EDIT_NOLIMIT
!= nMaxTextLen
&& sText
.getLength() > nMaxTextLen
)
1179 sal_Int32 nDiff
= sText
.getLength() - nMaxTextLen
;
1180 sText
= sText
.replaceAt(sText
.getLength() - nDiff
,nDiff
,::rtl::OUString());
1184 m_pEdit
->SetText( sText
);
1185 m_pEdit
->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1188 //------------------------------------------------------------------------------
1189 sal_Bool
DbTextField::commitControl()
1191 ::rtl::OUString
aText( m_pEdit
->GetText( getModelLineEndSetting( m_rColumn
.getModel() ) ) );
1192 // we have to check if the length before we can decide if the value was modified
1193 xub_StrLen nMaxTextLen
= m_pEdit
->GetMaxTextLen();
1194 if ( EDIT_NOLIMIT
!= nMaxTextLen
)
1196 ::rtl::OUString sOldValue
;
1197 m_rColumn
.getModel()->getPropertyValue( FM_PROP_TEXT
) >>= sOldValue
;
1198 // if the new value didn't change we must set the old long value again
1199 if ( sOldValue
.getLength() > nMaxTextLen
&& sOldValue
.compareTo(aText
,nMaxTextLen
) == 0 )
1202 m_rColumn
.getModel()->setPropertyValue( FM_PROP_TEXT
, makeAny( aText
) );
1206 //------------------------------------------------------------------------------
1207 void DbTextField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen
)
1210 m_pEdit
->SetMaxTextLen( _nMaxLen
);
1211 if ( m_pPainterImplementation
)
1212 m_pPainterImplementation
->SetMaxTextLen( _nMaxLen
);
1215 //==============================================================================
1216 //= DbFormattedField
1217 //==============================================================================
1218 DBG_NAME(DbFormattedField
);
1219 //------------------------------------------------------------------------------
1220 DbFormattedField::DbFormattedField(DbGridColumn
& _rColumn
)
1221 :DbLimitedLengthField(_rColumn
)
1222 ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED
)
1224 DBG_CTOR(DbFormattedField
,NULL
);
1226 // if our model's format key changes we want to propagate the new value to our windows
1227 doPropertyListening( FM_PROP_FORMATKEY
);
1230 //------------------------------------------------------------------------------
1231 DbFormattedField::~DbFormattedField()
1233 DBG_DTOR(DbFormattedField
,NULL
);
1236 //------------------------------------------------------------------------------
1237 void DbFormattedField::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
1239 sal_Int16 nAlignment
= m_rColumn
.SetAlignmentFromModel(-1);
1241 Reference
< ::com::sun::star::beans::XPropertySet
> xUnoModel
= m_rColumn
.getModel();
1245 case ::com::sun::star::awt::TextAlign::RIGHT
:
1246 m_pWindow
= new FormattedField( &rParent
, WB_RIGHT
);
1247 m_pPainter
= new FormattedField( &rParent
, WB_RIGHT
);
1250 case ::com::sun::star::awt::TextAlign::CENTER
:
1251 m_pWindow
= new FormattedField( &rParent
, WB_CENTER
);
1252 m_pPainter
= new FormattedField( &rParent
, WB_CENTER
);
1255 m_pWindow
= new FormattedField( &rParent
, WB_LEFT
);
1256 m_pPainter
= new FormattedField( &rParent
, WB_LEFT
);
1258 // Alles nur damit die Selektion bei Focuserhalt von rechts nach links geht
1259 AllSettings aSettings
= m_pWindow
->GetSettings();
1260 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
1261 aStyleSettings
.SetSelectionOptions(
1262 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
1263 aSettings
.SetStyleSettings(aStyleSettings
);
1264 m_pWindow
->SetSettings(aSettings
);
1267 implAdjustGenericFieldSetting( xUnoModel
);
1269 static_cast< FormattedField
* >( m_pWindow
)->SetStrictFormat( sal_False
);
1270 static_cast< FormattedField
* >( m_pPainter
)->SetStrictFormat( sal_False
);
1271 // wenn man _irgendeine_ Formatierung zulaesst, kann man da sowieso keine Eingabe-Ueberpruefung
1272 // machen (das FormattedField unterstuetzt das sowieso nicht, nur abgeleitete Klassen)
1274 // von dem Uno-Model den Formatter besorgen
1275 // (Ich koennte theoretisch auch ueber den ::com::sun::star::util::NumberFormatter gehen, den mir der Cursor bestimmt
1276 // liefern wuerde. Das Problem dabei ist, dass ich mich eigentlich nicht darauf verlassen
1277 // kann, dass die beiden Formatter die selben sind, sauber ist das Ganze, wenn ich ueber das
1279 sal_Int32 nFormatKey
= -1;
1281 // mal sehen, ob das Model einen hat ...
1282 DBG_ASSERT(::comphelper::hasProperty(FM_PROP_FORMATSSUPPLIER
, xUnoModel
), "DbFormattedField::Init : invalid UNO model !");
1283 Any
aSupplier( xUnoModel
->getPropertyValue(FM_PROP_FORMATSSUPPLIER
));
1284 if (aSupplier
.hasValue())
1286 ::cppu::extractInterface(m_xSupplier
, aSupplier
);
1287 if (m_xSupplier
.is())
1289 // wenn wir den Supplier vom Model nehmen, dann auch den Key
1290 Any
aFmtKey( xUnoModel
->getPropertyValue(FM_PROP_FORMATKEY
));
1291 if (aFmtKey
.hasValue())
1293 DBG_ASSERT(aFmtKey
.getValueType().getTypeClass() == TypeClass_LONG
, "DbFormattedField::Init : invalid format key property (no sal_Int32) !");
1294 nFormatKey
= ::comphelper::getINT32(aFmtKey
);
1298 DBG_WARNING("DbFormattedField::Init : my uno-model has no format-key, but a formats supplier !");
1299 // the OFormattedModel which we usually are working with ensures that the model has a format key
1300 // as soon as the form is loaded. Unfortunally this method here is called from within loaded, too.
1301 // So if our LoadListener is called before the LoadListener of the model, this "else case" is
1303 // Of course our property listener for the FormatKey property will notify us if the prop is changed,
1304 // so this here isn't really bad ....
1310 // nein ? vielleicht die ::com::sun::star::form::component::Form hinter dem Cursor ?
1311 if (!m_xSupplier
.is())
1313 Reference
< XRowSet
> xCursorForm(xCursor
, UNO_QUERY
);
1314 if (xCursorForm
.is())
1315 { // wenn wir vom Cursor den Formatter nehmen, dann auch den Key vom Feld, an das wir gebunden sind
1316 m_xSupplier
= getNumberFormats(getRowSetConnection(xCursorForm
), sal_False
);
1318 if (m_rColumn
.GetField().is())
1319 nFormatKey
= ::comphelper::getINT32(m_rColumn
.GetField()->getPropertyValue(FM_PROP_FORMATKEY
));
1323 SvNumberFormatter
* pFormatterUsed
= NULL
;
1324 if (m_xSupplier
.is())
1326 SvNumberFormatsSupplierObj
* pImplmentation
= SvNumberFormatsSupplierObj::getImplementation(m_xSupplier
);
1328 pFormatterUsed
= pImplmentation
->GetNumberFormatter();
1330 // alles hingfaellig : der Supplier ist vom falschen Typ, dann koennen wir uns auch nicht darauf verlassen, dass
1331 // ein Standard-Formatter den (eventuell nicht-Standard-)Key kennt.
1335 // einen Standard-Formatter ...
1336 if (pFormatterUsed
== NULL
)
1338 pFormatterUsed
= ((FormattedField
*)m_pWindow
)->StandardFormatter();
1339 DBG_ASSERT(pFormatterUsed
!= NULL
, "DbFormattedField::Init : no standard formatter given by the numeric field !");
1341 // ... und einen Standard-Key
1342 if (nFormatKey
== -1)
1345 m_nKeyType
= comphelper::getNumberFormatType(m_xSupplier
->getNumberFormats(), nFormatKey
);
1347 ((FormattedField
*)m_pWindow
)->SetFormatter(pFormatterUsed
);
1348 ((FormattedField
*)m_pPainter
)->SetFormatter(pFormatterUsed
);
1350 ((FormattedField
*)m_pWindow
)->SetFormatKey(nFormatKey
);
1351 ((FormattedField
*)m_pPainter
)->SetFormatKey(nFormatKey
);
1353 ((FormattedField
*)m_pWindow
)->TreatAsNumber(m_rColumn
.IsNumeric());
1354 ((FormattedField
*)m_pPainter
)->TreatAsNumber(m_rColumn
.IsNumeric());
1356 // Min- und Max-Werte
1357 if (m_rColumn
.IsNumeric())
1359 sal_Bool bClearMin
= sal_True
;
1360 if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MIN
, xUnoModel
))
1362 Any
aMin( xUnoModel
->getPropertyValue(FM_PROP_EFFECTIVE_MIN
));
1363 if (aMin
.getValueType().getTypeClass() != TypeClass_VOID
)
1365 DBG_ASSERT(aMin
.getValueType().getTypeClass() == TypeClass_DOUBLE
, "DbFormattedField::Init : the model has an invalid min value !");
1366 double dMin
= ::comphelper::getDouble(aMin
);
1367 ((FormattedField
*)m_pWindow
)->SetMinValue(dMin
);
1368 ((FormattedField
*)m_pPainter
)->SetMinValue(dMin
);
1369 bClearMin
= sal_False
;
1374 ((FormattedField
*)m_pWindow
)->ClearMinValue();
1375 ((FormattedField
*)m_pPainter
)->ClearMinValue();
1377 sal_Bool bClearMax
= sal_True
;
1378 if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MAX
, xUnoModel
))
1380 Any
aMin( xUnoModel
->getPropertyValue(FM_PROP_EFFECTIVE_MAX
));
1381 if (aMin
.getValueType().getTypeClass() != TypeClass_VOID
)
1383 DBG_ASSERT(aMin
.getValueType().getTypeClass() == TypeClass_DOUBLE
, "DbFormattedField::Init : the model has an invalid max value !");
1384 double dMin
= ::comphelper::getDouble(aMin
);
1385 ((FormattedField
*)m_pWindow
)->SetMaxValue(dMin
);
1386 ((FormattedField
*)m_pPainter
)->SetMaxValue(dMin
);
1387 bClearMax
= sal_False
;
1392 ((FormattedField
*)m_pWindow
)->ClearMaxValue();
1393 ((FormattedField
*)m_pPainter
)->ClearMaxValue();
1398 Any
aDefault( xUnoModel
->getPropertyValue(FM_PROP_EFFECTIVE_DEFAULT
));
1399 if (aDefault
.hasValue())
1400 { // das Ding kann ein double oder ein String sein
1401 switch (aDefault
.getValueType().getTypeClass())
1403 case TypeClass_DOUBLE
:
1404 if (m_rColumn
.IsNumeric())
1406 ((FormattedField
*)m_pWindow
)->SetDefaultValue(::comphelper::getDouble(aDefault
));
1407 ((FormattedField
*)m_pPainter
)->SetDefaultValue(::comphelper::getDouble(aDefault
));
1413 pFormatterUsed
->GetOutputString(::comphelper::getDouble(aDefault
), 0, sConverted
, &pDummy
);
1414 ((FormattedField
*)m_pWindow
)->SetDefaultText(sConverted
);
1415 ((FormattedField
*)m_pPainter
)->SetDefaultText(sConverted
);
1418 case TypeClass_STRING
:
1420 String
sDefault( ::comphelper::getString(aDefault
) );
1421 if (m_rColumn
.IsNumeric())
1424 sal_uInt32
nTestFormat(0);
1425 if (pFormatterUsed
->IsNumberFormat(sDefault
, nTestFormat
, dVal
))
1427 ((FormattedField
*)m_pWindow
)->SetDefaultValue(dVal
);
1428 ((FormattedField
*)m_pPainter
)->SetDefaultValue(dVal
);
1433 ((FormattedField
*)m_pWindow
)->SetDefaultText(sDefault
);
1434 ((FormattedField
*)m_pPainter
)->SetDefaultText(sDefault
);
1438 DBG_ERROR( "DbFormattedField::Init: unexpected value type!" );
1442 DbLimitedLengthField::Init( rParent
, xCursor
);
1445 //------------------------------------------------------------------------------
1446 CellControllerRef
DbFormattedField::CreateController() const
1448 return new ::svt::FormattedFieldCellController( static_cast< FormattedField
* >( m_pWindow
) );
1451 //------------------------------------------------------------------------------
1452 void DbFormattedField::_propertyChanged( const PropertyChangeEvent
& _rEvent
) throw( RuntimeException
)
1454 if (_rEvent
.PropertyName
.compareTo(FM_PROP_FORMATKEY
) == COMPARE_EQUAL
)
1456 sal_Int32 nNewKey
= _rEvent
.NewValue
.hasValue() ? ::comphelper::getINT32(_rEvent
.NewValue
) : 0;
1457 m_nKeyType
= comphelper::getNumberFormatType(m_xSupplier
->getNumberFormats(), nNewKey
);
1459 DBG_ASSERT(m_pWindow
&& m_pPainter
, "DbFormattedField::_propertyChanged : where are my windows ?");
1461 static_cast< FormattedField
* >( m_pWindow
)->SetFormatKey( nNewKey
);
1463 static_cast< FormattedField
* >( m_pPainter
)->SetFormatKey( nNewKey
);
1467 DbLimitedLengthField::_propertyChanged( _rEvent
);
1471 //------------------------------------------------------------------------------
1472 String
DbFormattedField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** ppColor
)
1474 // defaultmaessig keine Farb-Angabe
1475 if (ppColor
!= NULL
)
1478 // NULL-Wert -> leerer Text
1485 if (m_rColumn
.IsNumeric())
1487 // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern
1488 // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an
1489 // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst
1490 // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann
1491 // ich den Rest (die Formatierung) dem FormattedField ueberlassen.
1492 double dValue
= getValue(_rxField
, m_rColumn
.GetParent().getNullDate(), m_nKeyType
);
1493 if (_rxField
->wasNull())
1495 ((FormattedField
*)m_pPainter
)->SetValue(dValue
);
1499 // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann.
1500 // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen.
1501 aText
= (const sal_Unicode
*)_rxField
->getString();
1502 if (_rxField
->wasNull())
1504 ((FormattedField
*)m_pPainter
)->SetTextFormatted(aText
);
1507 catch( const Exception
& )
1509 DBG_UNHANDLED_EXCEPTION();
1512 aText
= m_pPainter
->GetText();
1513 if (ppColor
!= NULL
)
1514 *ppColor
= ((FormattedField
*)m_pPainter
)->GetLastOutputColor();
1519 //------------------------------------------------------------------------------
1520 void DbFormattedField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/)
1524 FormattedField
* pFormattedWindow
= static_cast<FormattedField
*>(m_pWindow
);
1526 { // NULL-Wert -> leerer Text
1527 m_pWindow
->SetText(String());
1529 else if (m_rColumn
.IsNumeric())
1531 // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern
1532 // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an
1533 // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst
1534 // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann
1535 // ich den Rest (die Formatierung) dem FormattedField ueberlassen.
1536 double dValue
= getValue(_rxField
, m_rColumn
.GetParent().getNullDate(), m_nKeyType
);
1537 if (_rxField
->wasNull())
1538 m_pWindow
->SetText(String());
1540 pFormattedWindow
->SetValue(dValue
);
1544 // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann.
1545 // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen.
1546 String
sText( _rxField
->getString());
1548 pFormattedWindow
->SetTextFormatted( sText
);
1549 pFormattedWindow
->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1552 catch( const Exception
& )
1554 DBG_UNHANDLED_EXCEPTION();
1558 //------------------------------------------------------------------------------
1559 void DbFormattedField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1561 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbFormattedField::updateFromModel: invalid call!" );
1563 FormattedField
* pFormattedWindow
= static_cast< FormattedField
* >( m_pWindow
);
1565 ::rtl::OUString sText
;
1566 Any aValue
= _rxModel
->getPropertyValue( FM_PROP_EFFECTIVE_VALUE
);
1567 if ( aValue
>>= sText
)
1568 { // our effective value is transfered as string
1569 pFormattedWindow
->SetTextFormatted( sText
);
1570 pFormattedWindow
->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1576 pFormattedWindow
->SetValue(dValue
);
1580 //------------------------------------------------------------------------------
1581 sal_Bool
DbFormattedField::commitControl()
1584 FormattedField
& rField
= *(FormattedField
*)m_pWindow
;
1585 DBG_ASSERT(&rField
== m_pWindow
, "DbFormattedField::commitControl : can't work with a window other than my own !");
1586 if (m_rColumn
.IsNumeric())
1588 if (rField
.GetText().Len() != 0)
1589 aNewVal
<<= rField
.GetValue();
1590 // ein LeerString wird erst mal standardmaessig als void weitergereicht
1593 aNewVal
<<= ::rtl::OUString(rField
.GetTextValue());
1595 m_rColumn
.getModel()->setPropertyValue(FM_PROP_EFFECTIVE_VALUE
, aNewVal
);
1599 //==============================================================================
1601 //==============================================================================
1602 //------------------------------------------------------------------------------
1603 DbCheckBox::DbCheckBox( DbGridColumn
& _rColumn
)
1604 :DbCellControl( _rColumn
, sal_True
)
1606 setAlignedController( sal_False
);
1611 void setCheckBoxStyle( Window
* _pWindow
, USHORT nStyle
)
1613 AllSettings aSettings
= _pWindow
->GetSettings();
1614 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
1615 aStyleSettings
.SetCheckBoxStyle( nStyle
);
1616 aSettings
.SetStyleSettings( aStyleSettings
);
1617 _pWindow
->SetSettings( aSettings
);
1621 //------------------------------------------------------------------------------
1622 void DbCheckBox::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
1624 setTransparent( sal_True
);
1626 m_pWindow
= new CheckBoxControl( &rParent
);
1627 m_pPainter
= new CheckBoxControl( &rParent
);
1629 m_pWindow
->SetPaintTransparent( sal_True
);
1630 m_pPainter
->SetPaintTransparent( sal_True
);
1632 m_pPainter
->SetBackground();
1636 Reference
< XPropertySet
> xModel( m_rColumn
.getModel(), UNO_SET_THROW
);
1638 sal_Int16 nStyle
= awt::VisualEffect::LOOK3D
;
1639 OSL_VERIFY( xModel
->getPropertyValue( FM_PROP_VISUALEFFECT
) >>= nStyle
);
1641 setCheckBoxStyle( m_pWindow
, nStyle
== awt::VisualEffect::FLAT
? STYLE_CHECKBOX_MONO
: STYLE_CHECKBOX_WIN
);
1642 setCheckBoxStyle( m_pPainter
, nStyle
== awt::VisualEffect::FLAT
? STYLE_CHECKBOX_MONO
: STYLE_CHECKBOX_WIN
);
1644 sal_Bool bTristate
= sal_True
;
1645 OSL_VERIFY( xModel
->getPropertyValue( FM_PROP_TRISTATE
) >>= bTristate
);
1646 static_cast< CheckBoxControl
* >( m_pWindow
)->GetBox().EnableTriState( bTristate
);
1647 static_cast< CheckBoxControl
* >( m_pPainter
)->GetBox().EnableTriState( bTristate
);
1649 catch( const Exception
& )
1651 DBG_UNHANDLED_EXCEPTION();
1654 DbCellControl::Init( rParent
, xCursor
);
1657 //------------------------------------------------------------------------------
1658 CellControllerRef
DbCheckBox::CreateController() const
1660 return new CheckBoxCellController((CheckBoxControl
*)m_pWindow
);
1662 //------------------------------------------------------------------------------
1663 static void lcl_setCheckBoxState( const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
,
1664 CheckBoxControl
* _pCheckBoxControl
)
1666 TriState eState
= STATE_DONTKNOW
;
1671 sal_Bool bValue
= _rxField
->getBoolean();
1672 if (!_rxField
->wasNull())
1673 eState
= bValue
? STATE_CHECK
: STATE_NOCHECK
;
1675 catch( const Exception
& )
1677 DBG_UNHANDLED_EXCEPTION();
1680 _pCheckBoxControl
->GetBox().SetState(eState
);
1683 //------------------------------------------------------------------------------
1684 void DbCheckBox::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/)
1686 lcl_setCheckBoxState( _rxField
, static_cast<CheckBoxControl
*>(m_pWindow
) );
1689 //------------------------------------------------------------------------------
1690 void DbCheckBox::PaintFieldToCell(OutputDevice
& rDev
, const Rectangle
& rRect
,
1691 const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
,
1692 const Reference
< XNumberFormatter
>& xFormatter
)
1694 lcl_setCheckBoxState( _rxField
, static_cast<CheckBoxControl
*>(m_pPainter
) );
1695 DbCellControl::PaintFieldToCell( rDev
, rRect
, _rxField
, xFormatter
);
1698 //------------------------------------------------------------------------------
1699 void DbCheckBox::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1701 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbCheckBox::updateFromModel: invalid call!" );
1703 sal_Int16 nState
= STATE_DONTKNOW
;
1704 _rxModel
->getPropertyValue( FM_PROP_STATE
) >>= nState
;
1705 static_cast< CheckBoxControl
* >( m_pWindow
)->GetBox().SetState( static_cast< TriState
>( nState
) );
1708 //------------------------------------------------------------------------------
1709 sal_Bool
DbCheckBox::commitControl()
1711 #if OSL_DEBUG_LEVEL > 0
1712 Any aVal
= makeAny( (sal_Int16
)( static_cast< CheckBoxControl
* >( m_pWindow
)->GetBox().GetState() ) );
1714 m_rColumn
.getModel()->setPropertyValue( FM_PROP_STATE
,
1715 makeAny( (sal_Int16
)( static_cast< CheckBoxControl
* >( m_pWindow
)->GetBox().GetState() ) ) );
1719 //------------------------------------------------------------------------------
1720 XubString
DbCheckBox::GetFormatText(const Reference
< XColumn
>& /*_rxField*/, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
1725 //==============================================================================
1727 //------------------------------------------------------------------------------
1728 DbPatternField::DbPatternField( DbGridColumn
& _rColumn
, const ::comphelper::ComponentContext
& _rContext
)
1729 :DbCellControl( _rColumn
)
1730 ,m_aContext( _rContext
)
1732 doPropertyListening( FM_PROP_LITERALMASK
);
1733 doPropertyListening( FM_PROP_EDITMASK
);
1734 doPropertyListening( FM_PROP_STRICTFORMAT
);
1737 //------------------------------------------------------------------------------
1738 void DbPatternField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
1740 DBG_ASSERT( m_pWindow
, "DbPatternField::implAdjustGenericFieldSetting: not to be called without window!" );
1741 DBG_ASSERT( _rxModel
.is(), "DbPatternField::implAdjustGenericFieldSetting: invalid model!" );
1742 if ( m_pWindow
&& _rxModel
.is() )
1744 ::rtl::OUString aLitMask
;
1745 ::rtl::OUString aEditMask
;
1746 sal_Bool bStrict
= sal_False
;
1748 _rxModel
->getPropertyValue( FM_PROP_LITERALMASK
) >>= aLitMask
;
1749 _rxModel
->getPropertyValue( FM_PROP_EDITMASK
) >>= aEditMask
;
1750 _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) >>= bStrict
;
1752 ByteString
aAsciiEditMask( aEditMask
.getStr(), RTL_TEXTENCODING_ASCII_US
);
1754 static_cast< PatternField
* >( m_pWindow
)->SetMask( aAsciiEditMask
, aLitMask
);
1755 static_cast< PatternField
* >( m_pPainter
)->SetMask( aAsciiEditMask
, aLitMask
);
1756 static_cast< PatternField
* >( m_pWindow
)->SetStrictFormat( bStrict
);
1757 static_cast< PatternField
* >( m_pPainter
)->SetStrictFormat( bStrict
);
1761 //------------------------------------------------------------------------------
1762 void DbPatternField::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
1764 m_rColumn
.SetAlignmentFromModel(-1);
1766 m_pWindow
= new PatternField( &rParent
, 0 );
1767 m_pPainter
= new PatternField( &rParent
, 0 );
1769 Reference
< XPropertySet
> xModel( m_rColumn
.getModel() );
1770 implAdjustGenericFieldSetting( xModel
);
1772 DbCellControl::Init( rParent
, xCursor
);
1775 //------------------------------------------------------------------------------
1776 CellControllerRef
DbPatternField::CreateController() const
1778 return new SpinCellController( static_cast< PatternField
* >( m_pWindow
) );
1781 //------------------------------------------------------------------------------
1782 String
DbPatternField::impl_formatText( const String
& _rText
)
1784 m_pPainter
->SetText( _rText
);
1785 static_cast< PatternField
* >( m_pPainter
)->ReformatAll();
1786 return m_pPainter
->GetText();
1789 //------------------------------------------------------------------------------
1790 String
DbPatternField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
1792 bool bIsForPaint
= _rxField
!= m_rColumn
.GetField();
1793 ::std::auto_ptr
< ::dbtools::FormattedColumnValue
>& rpFormatter
= bIsForPaint
? m_pPaintFormatter
: m_pValueFormatter
;
1795 if ( !rpFormatter
.get() )
1797 DBToolsObjectFactory aFactory
;
1798 rpFormatter
= aFactory
.createFormattedColumnValue(
1799 m_aContext
, getCursor(), Reference
< XPropertySet
>( _rxField
, UNO_QUERY
) );
1800 OSL_ENSURE( rpFormatter
.get(), "DbPatternField::Init: no value formatter!" );
1803 OSL_ENSURE( rpFormatter
->getColumn() == _rxField
, "DbPatternField::GetFormatText: my value formatter is working for another field ...!" );
1804 // re-creating the value formatter here everytime would be quite expensive ...
1807 if ( rpFormatter
.get() )
1808 sText
= rpFormatter
->getFormattedValue();
1810 return impl_formatText( sText
);
1813 //------------------------------------------------------------------------------
1814 void DbPatternField::UpdateFromField( const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
1816 static_cast< Edit
* >( m_pWindow
)->SetText( GetFormatText( _rxField
, _rxFormatter
) );
1817 static_cast< Edit
* >( m_pWindow
)->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1820 //------------------------------------------------------------------------------
1821 void DbPatternField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1823 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbPatternField::updateFromModel: invalid call!" );
1825 ::rtl::OUString sText
;
1826 _rxModel
->getPropertyValue( FM_PROP_TEXT
) >>= sText
;
1828 static_cast< Edit
* >( m_pWindow
)->SetText( impl_formatText( sText
) );
1829 static_cast< Edit
* >( m_pWindow
)->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1832 //------------------------------------------------------------------------------
1833 sal_Bool
DbPatternField::commitControl()
1835 String
aText(m_pWindow
->GetText());
1836 m_rColumn
.getModel()->setPropertyValue(FM_PROP_TEXT
, makeAny(::rtl::OUString(aText
)));
1840 //==============================================================================
1842 //==============================================================================
1843 //------------------------------------------------------------------------------
1844 DbSpinField::DbSpinField( DbGridColumn
& _rColumn
, sal_Int16 _nStandardAlign
)
1845 :DbCellControl( _rColumn
)
1846 ,m_nStandardAlign( _nStandardAlign
)
1850 //------------------------------------------------------------------------------
1851 void DbSpinField::Init( Window
& _rParent
, const Reference
< XRowSet
>& _rxCursor
)
1853 m_rColumn
.SetAlignmentFromModel( m_nStandardAlign
);
1855 Reference
< XPropertySet
> xModel( m_rColumn
.getModel() );
1857 // determine the WinBits for the field
1858 WinBits nFieldStyle
= 0;
1859 if ( ::comphelper::getBOOL( xModel
->getPropertyValue( FM_PROP_SPIN
) ) )
1860 nFieldStyle
= WB_REPEAT
| WB_SPIN
;
1861 // create the fields
1862 m_pWindow
= createField( &_rParent
, nFieldStyle
, xModel
);
1863 m_pPainter
= createField( &_rParent
, nFieldStyle
, xModel
);
1865 // adjust all other settings which depend on the property values
1866 implAdjustGenericFieldSetting( xModel
);
1868 // call the base class
1869 DbCellControl::Init( _rParent
, _rxCursor
);
1872 //------------------------------------------------------------------------------
1873 CellControllerRef
DbSpinField::CreateController() const
1875 return new SpinCellController( static_cast< SpinField
* >( m_pWindow
) );
1878 //==============================================================================
1880 //==============================================================================
1881 //------------------------------------------------------------------------------
1882 DbNumericField::DbNumericField( DbGridColumn
& _rColumn
)
1883 :DbSpinField( _rColumn
)
1885 doPropertyListening( FM_PROP_DECIMAL_ACCURACY
);
1886 doPropertyListening( FM_PROP_VALUEMIN
);
1887 doPropertyListening( FM_PROP_VALUEMAX
);
1888 doPropertyListening( FM_PROP_VALUESTEP
);
1889 doPropertyListening( FM_PROP_STRICTFORMAT
);
1890 doPropertyListening( FM_PROP_SHOWTHOUSANDSEP
);
1893 //------------------------------------------------------------------------------
1894 void DbNumericField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
1896 DBG_ASSERT( m_pWindow
, "DbNumericField::implAdjustGenericFieldSetting: not to be called without window!" );
1897 DBG_ASSERT( _rxModel
.is(), "DbNumericField::implAdjustGenericFieldSetting: invalid model!" );
1898 if ( m_pWindow
&& _rxModel
.is() )
1900 sal_Int32 nMin
= (sal_Int32
)getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUEMIN
) );
1901 sal_Int32 nMax
= (sal_Int32
)getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUEMAX
) );
1902 sal_Int32 nStep
= (sal_Int32
)getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUESTEP
) );
1903 sal_Bool bStrict
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) );
1904 sal_Int16 nScale
= getINT16( _rxModel
->getPropertyValue( FM_PROP_DECIMAL_ACCURACY
) );
1905 sal_Bool bThousand
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP
) );
1907 static_cast< DoubleNumericField
* >( m_pWindow
)->SetMinValue(nMin
);
1908 static_cast< DoubleNumericField
* >( m_pWindow
)->SetMaxValue(nMax
);
1909 static_cast< DoubleNumericField
* >( m_pWindow
)->SetSpinSize(nStep
);
1910 static_cast< DoubleNumericField
* >( m_pWindow
)->SetStrictFormat(bStrict
);
1912 static_cast< DoubleNumericField
* >( m_pPainter
)->SetMinValue(nMin
);
1913 static_cast< DoubleNumericField
* >( m_pPainter
)->SetMaxValue(nMax
);
1914 static_cast< DoubleNumericField
* >( m_pPainter
)->SetStrictFormat(bStrict
);
1917 // dem Field und dem Painter einen Formatter spendieren
1918 // zuerst testen, ob ich von dem Service hinter einer Connection bekommen kann
1919 Reference
< ::com::sun::star::util::XNumberFormatsSupplier
> xSupplier
;
1920 Reference
< XRowSet
> xForm
;
1921 if ( m_rColumn
.GetParent().getDataSource() )
1922 xForm
= Reference
< XRowSet
>( ( Reference
< XInterface
> )*m_rColumn
.GetParent().getDataSource(), UNO_QUERY
);
1924 xSupplier
= getNumberFormats( getRowSetConnection( xForm
), sal_True
);
1925 SvNumberFormatter
* pFormatterUsed
= NULL
;
1926 if ( xSupplier
.is() )
1928 SvNumberFormatsSupplierObj
* pImplmentation
= SvNumberFormatsSupplierObj::getImplementation( xSupplier
);
1929 pFormatterUsed
= pImplmentation
? pImplmentation
->GetNumberFormatter() : NULL
;
1931 if ( NULL
== pFormatterUsed
)
1932 { // der Cursor fuehrte nicht zum Erfolg -> Standard
1933 pFormatterUsed
= static_cast< DoubleNumericField
* >( m_pWindow
)->StandardFormatter();
1934 DBG_ASSERT( pFormatterUsed
!= NULL
, "DbNumericField::implAdjustGenericFieldSetting: no standard formatter given by the numeric field !" );
1936 static_cast< DoubleNumericField
* >( m_pWindow
)->SetFormatter( pFormatterUsed
);
1937 static_cast< DoubleNumericField
* >( m_pPainter
)->SetFormatter( pFormatterUsed
);
1939 // und dann ein Format generieren, dass die gewuenschten Nachkommastellen usw. hat
1940 String sFormatString
;
1941 LanguageType aAppLanguage
= Application::GetSettings().GetUILanguage();
1942 pFormatterUsed
->GenerateFormat( sFormatString
, 0, aAppLanguage
, bThousand
, sal_False
, nScale
);
1944 static_cast< DoubleNumericField
* >( m_pWindow
)->SetFormat( sFormatString
, aAppLanguage
);
1945 static_cast< DoubleNumericField
* >( m_pPainter
)->SetFormat( sFormatString
, aAppLanguage
);
1949 //------------------------------------------------------------------------------
1950 SpinField
* DbNumericField::createField( Window
* _pParent
, WinBits _nFieldStyle
, const Reference
< XPropertySet
>& /*_rxModel*/ )
1952 return new DoubleNumericField( _pParent
, _nFieldStyle
);
1957 //--------------------------------------------------------------------------
1958 static String
lcl_setFormattedNumeric_nothrow( DoubleNumericField
& _rField
, const DbCellControl
& _rControl
,
1959 const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
1962 if ( _rxField
.is() )
1966 double fValue
= _rControl
.GetValue( _rxField
, _rxFormatter
);
1967 if ( !_rxField
->wasNull() )
1969 _rField
.SetValue( fValue
);
1970 sValue
= _rField
.GetText();
1973 catch( const Exception
& )
1975 DBG_UNHANDLED_EXCEPTION();
1982 //------------------------------------------------------------------------------
1983 String
DbNumericField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
, Color
** /*ppColor*/)
1985 return lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField
* >( m_pPainter
), *this, _rxField
, _rxFormatter
);
1988 //------------------------------------------------------------------------------
1989 void DbNumericField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
)
1991 lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField
* >( m_pWindow
), *this, _rxField
, _rxFormatter
);
1994 //------------------------------------------------------------------------------
1995 void DbNumericField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1997 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbNumericField::updateFromModel: invalid call!" );
2000 if ( _rxModel
->getPropertyValue( FM_PROP_VALUE
) >>= dValue
)
2001 static_cast< DoubleNumericField
* >( m_pWindow
)->SetValue( dValue
);
2003 m_pWindow
->SetText( String() );
2006 //------------------------------------------------------------------------------
2007 sal_Bool
DbNumericField::commitControl()
2009 String
aText( m_pWindow
->GetText());
2012 if (aText
.Len() != 0) // nicht null
2014 double fValue
= ((DoubleNumericField
*)m_pWindow
)->GetValue();
2015 aVal
<<= (double)fValue
;
2017 m_rColumn
.getModel()->setPropertyValue(FM_PROP_VALUE
, aVal
);
2021 //==============================================================================
2023 //==============================================================================
2024 //------------------------------------------------------------------------------
2025 DbCurrencyField::DbCurrencyField(DbGridColumn
& _rColumn
)
2026 :DbSpinField( _rColumn
)
2029 doPropertyListening( FM_PROP_DECIMAL_ACCURACY
);
2030 doPropertyListening( FM_PROP_VALUEMIN
);
2031 doPropertyListening( FM_PROP_VALUEMAX
);
2032 doPropertyListening( FM_PROP_VALUESTEP
);
2033 doPropertyListening( FM_PROP_STRICTFORMAT
);
2034 doPropertyListening( FM_PROP_SHOWTHOUSANDSEP
);
2035 doPropertyListening( FM_PROP_CURRENCYSYMBOL
);
2038 //------------------------------------------------------------------------------
2039 void DbCurrencyField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2041 DBG_ASSERT( m_pWindow
, "DbCurrencyField::implAdjustGenericFieldSetting: not to be called without window!" );
2042 DBG_ASSERT( _rxModel
.is(), "DbCurrencyField::implAdjustGenericFieldSetting: invalid model!" );
2043 if ( m_pWindow
&& _rxModel
.is() )
2045 m_nScale
= getINT16( _rxModel
->getPropertyValue( FM_PROP_DECIMAL_ACCURACY
) );
2046 double nMin
= getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUEMIN
) );
2047 double nMax
= getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUEMAX
) );
2048 double nStep
= getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUESTEP
) );
2049 sal_Bool bStrict
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) );
2050 sal_Bool bThousand
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP
) );
2051 ::rtl::OUString
aStr( getString( _rxModel
->getPropertyValue(FM_PROP_CURRENCYSYMBOL
) ) );
2053 static_cast< LongCurrencyField
* >( m_pWindow
)->SetUseThousandSep( bThousand
);
2054 static_cast< LongCurrencyField
* >( m_pWindow
)->SetDecimalDigits( m_nScale
);
2055 static_cast< LongCurrencyField
* >( m_pWindow
)->SetCurrencySymbol( aStr
);
2056 static_cast< LongCurrencyField
* >( m_pWindow
)->SetFirst( nMin
);
2057 static_cast< LongCurrencyField
* >( m_pWindow
)->SetLast( nMax
);
2058 static_cast< LongCurrencyField
* >( m_pWindow
)->SetMin( nMin
);
2059 static_cast< LongCurrencyField
* >( m_pWindow
)->SetMax( nMax
);
2060 static_cast< LongCurrencyField
* >( m_pWindow
)->SetSpinSize( nStep
);
2061 static_cast< LongCurrencyField
* >( m_pWindow
)->SetStrictFormat( bStrict
);
2063 static_cast< LongCurrencyField
* >( m_pPainter
)->SetUseThousandSep( bThousand
);
2064 static_cast< LongCurrencyField
* >( m_pPainter
)->SetDecimalDigits( m_nScale
);
2065 static_cast< LongCurrencyField
* >( m_pPainter
)->SetCurrencySymbol( aStr
);
2066 static_cast< LongCurrencyField
* >( m_pPainter
)->SetFirst( nMin
);
2067 static_cast< LongCurrencyField
* >( m_pPainter
)->SetLast( nMax
);
2068 static_cast< LongCurrencyField
* >( m_pPainter
)->SetMin( nMin
);
2069 static_cast< LongCurrencyField
* >( m_pPainter
)->SetMax( nMax
);
2070 static_cast< LongCurrencyField
* >( m_pPainter
)->SetStrictFormat( bStrict
);
2074 //------------------------------------------------------------------------------
2075 SpinField
* DbCurrencyField::createField( Window
* _pParent
, WinBits _nFieldStyle
, const Reference
< XPropertySet
>& /*_rxModel*/ )
2077 return new LongCurrencyField( _pParent
, _nFieldStyle
);
2080 //------------------------------------------------------------------------------
2081 double DbCurrencyField::GetCurrency(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
) const
2083 volatile double fValue
= GetValue(_rxField
, xFormatter
);
2086 // OSL_TRACE("double = %.64f ",fValue);
2087 fValue
= ::rtl::math::pow10Exp(fValue
, m_nScale
);
2088 fValue
= ::rtl::math::round(fValue
, 0);
2095 //--------------------------------------------------------------------------
2096 static String
lcl_setFormattedCurrency_nothrow( LongCurrencyField
& _rField
, const DbCurrencyField
& _rControl
,
2097 const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
2100 if ( _rxField
.is() )
2104 double fValue
= _rControl
.GetCurrency( _rxField
, _rxFormatter
);
2105 if ( !_rxField
->wasNull() )
2107 _rField
.SetValue( fValue
);
2108 BigInt aValue
= _rField
.GetCorrectedValue();
2109 sValue
= aValue
.GetString();
2110 sValue
= _rField
.GetText();
2113 catch( const Exception
& )
2115 DBG_UNHANDLED_EXCEPTION();
2122 //------------------------------------------------------------------------------
2123 String
DbCurrencyField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
, Color
** /*ppColor*/)
2125 return lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField
* >( m_pPainter
), *this, _rxField
, _rxFormatter
);
2128 //------------------------------------------------------------------------------
2129 void DbCurrencyField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
)
2131 lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField
* >( m_pWindow
), *this, _rxField
, _rxFormatter
);
2134 //------------------------------------------------------------------------------
2135 void DbCurrencyField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2137 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbCurrencyField::updateFromModel: invalid call!" );
2140 if ( _rxModel
->getPropertyValue( FM_PROP_VALUE
) >>= dValue
)
2144 dValue
= ::rtl::math::pow10Exp( dValue
, m_nScale
);
2145 dValue
= ::rtl::math::round(dValue
, 0);
2148 static_cast< LongCurrencyField
* >( m_pWindow
)->SetValue( dValue
);
2151 m_pWindow
->SetText( String() );
2154 //------------------------------------------------------------------------------
2155 sal_Bool
DbCurrencyField::commitControl()
2157 String
aText( m_pWindow
->GetText());
2159 if (aText
.Len() != 0) // nicht null
2161 volatile double fValue
= ((LongCurrencyField
*)m_pWindow
)->GetValue();
2164 fValue
/= ::rtl::math::pow10Exp(1.0, m_nScale
);
2165 //fValue = ::rtl::math::round(fValue, m_nScale);
2167 aVal
<<= (double)fValue
;
2169 m_rColumn
.getModel()->setPropertyValue(FM_PROP_VALUE
, aVal
);
2173 //==============================================================================
2175 //==============================================================================
2176 //------------------------------------------------------------------------------
2177 DbDateField::DbDateField( DbGridColumn
& _rColumn
)
2178 :DbSpinField( _rColumn
)
2180 doPropertyListening( FM_PROP_DATEFORMAT
);
2181 doPropertyListening( FM_PROP_DATEMIN
);
2182 doPropertyListening( FM_PROP_DATEMAX
);
2183 doPropertyListening( FM_PROP_STRICTFORMAT
);
2184 doPropertyListening( FM_PROP_DATE_SHOW_CENTURY
);
2187 //------------------------------------------------------------------------------
2188 SpinField
* DbDateField::createField( Window
* _pParent
, WinBits _nFieldStyle
, const Reference
< XPropertySet
>& _rxModel
)
2190 // check if there is a DropDown property set to TRUE
2191 sal_Bool bDropDown
= !hasProperty( FM_PROP_DROPDOWN
, _rxModel
)
2192 || getBOOL( _rxModel
->getPropertyValue( FM_PROP_DROPDOWN
) );
2194 _nFieldStyle
|= WB_DROPDOWN
;
2196 CalendarField
* pField
= new CalendarField( _pParent
, _nFieldStyle
);
2198 pField
->EnableToday();
2199 pField
->EnableNone();
2204 //------------------------------------------------------------------------------
2205 void DbDateField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2207 DBG_ASSERT( m_pWindow
, "DbDateField::implAdjustGenericFieldSetting: not to be called without window!" );
2208 DBG_ASSERT( _rxModel
.is(), "DbDateField::implAdjustGenericFieldSetting: invalid model!" );
2209 if ( m_pWindow
&& _rxModel
.is() )
2211 sal_Int16 nFormat
= getINT16( _rxModel
->getPropertyValue( FM_PROP_DATEFORMAT
) );
2212 sal_Int32 nMin
= getINT32( _rxModel
->getPropertyValue( FM_PROP_DATEMIN
) );
2213 sal_Int32 nMax
= getINT32( _rxModel
->getPropertyValue( FM_PROP_DATEMAX
) );
2214 sal_Bool bStrict
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) );
2216 Any aCentury
= _rxModel
->getPropertyValue( FM_PROP_DATE_SHOW_CENTURY
);
2217 if ( aCentury
.getValueType().getTypeClass() != TypeClass_VOID
)
2219 sal_Bool bShowDateCentury
= getBOOL( aCentury
);
2221 static_cast<DateField
*>( m_pWindow
)->SetShowDateCentury( bShowDateCentury
);
2222 static_cast<DateField
*>( m_pPainter
)->SetShowDateCentury( bShowDateCentury
);
2225 static_cast< DateField
* >( m_pWindow
)->SetExtDateFormat( (ExtDateFieldFormat
)nFormat
);
2226 static_cast< DateField
* >( m_pWindow
)->SetMin( nMin
);
2227 static_cast< DateField
* >( m_pWindow
)->SetMax( nMax
);
2228 static_cast< DateField
* >( m_pWindow
)->SetStrictFormat( bStrict
);
2229 static_cast< DateField
* >( m_pWindow
)->EnableEmptyFieldValue( TRUE
);
2231 static_cast< DateField
* >( m_pPainter
)->SetExtDateFormat( (ExtDateFieldFormat
)nFormat
);
2232 static_cast< DateField
* >( m_pPainter
)->SetMin( nMin
);
2233 static_cast< DateField
* >( m_pPainter
)->SetMax( nMax
);
2234 static_cast< DateField
* >( m_pPainter
)->SetStrictFormat( bStrict
);
2235 static_cast< DateField
* >( m_pPainter
)->EnableEmptyFieldValue( TRUE
);
2241 //--------------------------------------------------------------------------
2242 static String
lcl_setFormattedDate_nothrow( DateField
& _rField
, const Reference
< XColumn
>& _rxField
)
2245 if ( _rxField
.is() )
2249 ::com::sun::star::util::Date aValue
= _rxField
->getDate();
2250 if ( _rxField
->wasNull() )
2251 _rField
.SetText( sDate
);
2254 _rField
.SetDate( ::Date( aValue
.Day
, aValue
.Month
, aValue
.Year
) );
2255 sDate
= _rField
.GetText();
2258 catch( const Exception
& )
2260 DBG_UNHANDLED_EXCEPTION();
2266 //------------------------------------------------------------------------------
2267 String
DbDateField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
2269 return lcl_setFormattedDate_nothrow( *dynamic_cast< DateField
* >( m_pPainter
), _rxField
);
2272 //------------------------------------------------------------------------------
2273 void DbDateField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/)
2275 lcl_setFormattedDate_nothrow( *dynamic_cast< DateField
* >( m_pWindow
), _rxField
);
2278 //------------------------------------------------------------------------------
2279 void DbDateField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2281 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbDateField::updateFromModel: invalid call!" );
2283 sal_Int32 nDate
= 0;
2284 if ( _rxModel
->getPropertyValue( FM_PROP_DATE
) >>= nDate
)
2285 static_cast< DateField
* >( m_pWindow
)->SetDate( ::Date( nDate
) );
2287 static_cast< DateField
* >( m_pWindow
)->SetText( String() );
2290 //------------------------------------------------------------------------------
2291 sal_Bool
DbDateField::commitControl()
2293 String
aText( m_pWindow
->GetText());
2295 if (aText
.Len() != 0)
2296 aVal
<<= (sal_Int32
)static_cast<DateField
*>(m_pWindow
)->GetDate().GetDate();
2300 m_rColumn
.getModel()->setPropertyValue(FM_PROP_DATE
, aVal
);
2304 //==============================================================================
2306 //==============================================================================
2307 //------------------------------------------------------------------------------
2308 DbTimeField::DbTimeField( DbGridColumn
& _rColumn
)
2309 :DbSpinField( _rColumn
, ::com::sun::star::awt::TextAlign::LEFT
)
2311 doPropertyListening( FM_PROP_TIMEFORMAT
);
2312 doPropertyListening( FM_PROP_TIMEMIN
);
2313 doPropertyListening( FM_PROP_TIMEMAX
);
2314 doPropertyListening( FM_PROP_STRICTFORMAT
);
2317 //------------------------------------------------------------------------------
2318 SpinField
* DbTimeField::createField( Window
* _pParent
, WinBits _nFieldStyle
, const Reference
< XPropertySet
>& /*_rxModel*/ )
2320 return new TimeField( _pParent
, _nFieldStyle
);
2323 //------------------------------------------------------------------------------
2324 void DbTimeField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2326 DBG_ASSERT( m_pWindow
, "DbTimeField::implAdjustGenericFieldSetting: not to be called without window!" );
2327 DBG_ASSERT( _rxModel
.is(), "DbTimeField::implAdjustGenericFieldSetting: invalid model!" );
2328 if ( m_pWindow
&& _rxModel
.is() )
2330 sal_Int16 nFormat
= getINT16( _rxModel
->getPropertyValue( FM_PROP_TIMEFORMAT
) );
2331 sal_Int32 nMin
= getINT32( _rxModel
->getPropertyValue( FM_PROP_TIMEMIN
) );
2332 sal_Int32 nMax
= getINT32( _rxModel
->getPropertyValue( FM_PROP_TIMEMAX
) );
2333 sal_Bool bStrict
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) );
2335 static_cast< TimeField
* >( m_pWindow
)->SetExtFormat( (ExtTimeFieldFormat
)nFormat
);
2336 static_cast< TimeField
* >( m_pWindow
)->SetMin( nMin
);
2337 static_cast< TimeField
* >( m_pWindow
)->SetMax( nMax
);
2338 static_cast< TimeField
* >( m_pWindow
)->SetStrictFormat( bStrict
);
2339 static_cast< TimeField
* >( m_pWindow
)->EnableEmptyFieldValue( TRUE
);
2341 static_cast< TimeField
* >( m_pPainter
)->SetExtFormat( (ExtTimeFieldFormat
)nFormat
);
2342 static_cast< TimeField
* >( m_pPainter
)->SetMin( nMin
);
2343 static_cast< TimeField
* >( m_pPainter
)->SetMax( nMax
);
2344 static_cast< TimeField
* >( m_pPainter
)->SetStrictFormat( bStrict
);
2345 static_cast< TimeField
* >( m_pPainter
)->EnableEmptyFieldValue( TRUE
);
2351 //--------------------------------------------------------------------------
2352 static String
lcl_setFormattedTime_nothrow( TimeField
& _rField
, const Reference
< XColumn
>& _rxField
)
2355 if ( _rxField
.is() )
2359 ::com::sun::star::util::Time aValue
= _rxField
->getTime();
2360 if ( _rxField
->wasNull() )
2361 _rField
.SetText( sTime
);
2364 _rField
.SetTime( ::Time( aValue
.Hours
, aValue
.Minutes
, aValue
.Seconds
, aValue
.HundredthSeconds
) );
2365 sTime
= _rField
.GetText();
2368 catch( const Exception
& )
2370 DBG_UNHANDLED_EXCEPTION();
2376 //------------------------------------------------------------------------------
2377 String
DbTimeField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
2379 return lcl_setFormattedTime_nothrow( *static_cast< TimeField
* >( m_pPainter
), _rxField
);
2382 //------------------------------------------------------------------------------
2383 void DbTimeField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/)
2385 lcl_setFormattedTime_nothrow( *static_cast< TimeField
* >( m_pWindow
), _rxField
);
2388 //------------------------------------------------------------------------------
2389 void DbTimeField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2391 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbTimeField::updateFromModel: invalid call!" );
2393 sal_Int32 nTime
= 0;
2394 if ( _rxModel
->getPropertyValue( FM_PROP_DATE
) >>= nTime
)
2395 static_cast< TimeField
* >( m_pWindow
)->SetTime( ::Time( nTime
) );
2397 static_cast< TimeField
* >( m_pWindow
)->SetText( String() );
2400 //------------------------------------------------------------------------------
2401 sal_Bool
DbTimeField::commitControl()
2403 String
aText( m_pWindow
->GetText());
2405 if (aText
.Len() != 0)
2406 aVal
<<= (sal_Int32
)static_cast<TimeField
*>(m_pWindow
)->GetTime().GetTime();
2410 m_rColumn
.getModel()->setPropertyValue(FM_PROP_TIME
, aVal
);
2414 //==============================================================================
2416 //==============================================================================
2417 //------------------------------------------------------------------------------
2418 DbComboBox::DbComboBox(DbGridColumn
& _rColumn
)
2419 :DbCellControl(_rColumn
)
2420 ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED
)
2422 setAlignedController( sal_False
);
2424 doPropertyListening( FM_PROP_STRINGITEMLIST
);
2425 doPropertyListening( FM_PROP_LINECOUNT
);
2428 //------------------------------------------------------------------------------
2429 void DbComboBox::_propertyChanged( const PropertyChangeEvent
& _rEvent
) throw( RuntimeException
)
2431 if ( _rEvent
.PropertyName
.equals( FM_PROP_STRINGITEMLIST
) )
2433 SetList(_rEvent
.NewValue
);
2437 DbCellControl::_propertyChanged( _rEvent
) ;
2441 //------------------------------------------------------------------------------
2442 void DbComboBox::SetList(const Any
& rItems
)
2444 ComboBoxControl
* pField
= (ComboBoxControl
*)m_pWindow
;
2447 ::comphelper::StringSequence aTest
;
2448 if (rItems
>>= aTest
)
2450 const ::rtl::OUString
* pStrings
= aTest
.getConstArray();
2451 sal_Int32 nItems
= aTest
.getLength();
2452 for (sal_Int32 i
= 0; i
< nItems
; ++i
, ++pStrings
)
2453 pField
->InsertEntry(*pStrings
, LISTBOX_APPEND
);
2455 // tell the grid control that this controller is invalid and has to be re-initialized
2456 invalidatedController();
2460 //------------------------------------------------------------------------------
2461 void DbComboBox::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2463 DBG_ASSERT( m_pWindow
, "DbComboBox::implAdjustGenericFieldSetting: not to be called without window!" );
2464 DBG_ASSERT( _rxModel
.is(), "DbComboBox::implAdjustGenericFieldSetting: invalid model!" );
2465 if ( m_pWindow
&& _rxModel
.is() )
2467 sal_Int16 nLines
= getINT16( _rxModel
->getPropertyValue( FM_PROP_LINECOUNT
) );
2468 static_cast< ComboBoxControl
* >( m_pWindow
)->SetDropDownLineCount( nLines
);
2472 //------------------------------------------------------------------------------
2473 void DbComboBox::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
2475 m_rColumn
.SetAlignmentFromModel(::com::sun::star::awt::TextAlign::LEFT
);
2477 m_pWindow
= new ComboBoxControl( &rParent
);
2479 // selection von rechts nach links
2480 AllSettings aSettings
= m_pWindow
->GetSettings();
2481 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
2482 aStyleSettings
.SetSelectionOptions(
2483 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
2484 aSettings
.SetStyleSettings(aStyleSettings
);
2485 m_pWindow
->SetSettings(aSettings
, sal_True
);
2487 // some initial properties
2488 Reference
< XPropertySet
> xModel(m_rColumn
.getModel());
2489 SetList( xModel
->getPropertyValue( FM_PROP_STRINGITEMLIST
) );
2490 implAdjustGenericFieldSetting( xModel
);
2492 if (m_rColumn
.GetParent().getNumberFormatter().is())
2493 m_nKeyType
= comphelper::getNumberFormatType(m_rColumn
.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn
.GetKey());
2495 DbCellControl::Init( rParent
, xCursor
);
2498 //------------------------------------------------------------------------------
2499 CellControllerRef
DbComboBox::CreateController() const
2501 return new ComboBoxCellController((ComboBoxControl
*)m_pWindow
);
2504 //------------------------------------------------------------------------------
2505 String
DbComboBox::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
, Color
** /*ppColor*/)
2507 ::rtl::OUString aString
;
2511 aString
= getValue( _rxField
, xFormatter
, m_rColumn
.GetParent().getNullDate(), m_rColumn
.GetKey(), m_nKeyType
);
2513 catch( const Exception
& )
2515 DBG_UNHANDLED_EXCEPTION();
2520 //------------------------------------------------------------------------------
2521 void DbComboBox::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
)
2523 m_pWindow
->SetText(GetFormatText(_rxField
, xFormatter
));
2526 //------------------------------------------------------------------------------
2527 void DbComboBox::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2529 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbComboBox::updateFromModel: invalid call!" );
2531 ::rtl::OUString sText
;
2532 _rxModel
->getPropertyValue( FM_PROP_TEXT
) >>= sText
;
2534 static_cast< ComboBox
* >( m_pWindow
)->SetText( sText
);
2535 static_cast< ComboBox
* >( m_pWindow
)->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
2538 //------------------------------------------------------------------------------
2539 sal_Bool
DbComboBox::commitControl()
2541 String
aText( m_pWindow
->GetText());
2542 m_rColumn
.getModel()->setPropertyValue(FM_PROP_TEXT
, makeAny(::rtl::OUString(aText
)));
2546 //------------------------------------------------------------------------------
2547 DbListBox::DbListBox(DbGridColumn
& _rColumn
)
2548 :DbCellControl(_rColumn
)
2549 ,m_bBound(sal_False
)
2551 setAlignedController( sal_False
);
2553 doPropertyListening( FM_PROP_STRINGITEMLIST
);
2554 doPropertyListening( FM_PROP_LINECOUNT
);
2557 //------------------------------------------------------------------------------
2558 void DbListBox::_propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent
& _rEvent
) throw( RuntimeException
)
2560 if ( _rEvent
.PropertyName
.equals( FM_PROP_STRINGITEMLIST
) )
2562 SetList(_rEvent
.NewValue
);
2566 DbCellControl::_propertyChanged( _rEvent
) ;
2570 //------------------------------------------------------------------------------
2571 void DbListBox::SetList(const Any
& rItems
)
2573 ListBoxControl
* pField
= (ListBoxControl
*)m_pWindow
;
2576 m_bBound
= sal_False
;
2578 ::comphelper::StringSequence aTest
;
2579 if (rItems
>>= aTest
)
2581 const ::rtl::OUString
* pStrings
= aTest
.getConstArray();
2582 sal_Int32 nItems
= aTest
.getLength();
2585 for (sal_Int32 i
= 0; i
< nItems
; ++i
, ++pStrings
)
2586 pField
->InsertEntry(*pStrings
, LISTBOX_APPEND
);
2588 m_rColumn
.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ
) >>= m_aValueList
;
2589 m_bBound
= m_aValueList
.getLength() > 0;
2591 // tell the grid control that this controller is invalid and has to be re-initialized
2592 invalidatedController();
2597 //------------------------------------------------------------------------------
2598 void DbListBox::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
2600 m_rColumn
.SetAlignment(::com::sun::star::awt::TextAlign::LEFT
);
2602 m_pWindow
= new ListBoxControl( &rParent
);
2604 // some initial properties
2605 Reference
< XPropertySet
> xModel( m_rColumn
.getModel() );
2606 SetList( xModel
->getPropertyValue( FM_PROP_STRINGITEMLIST
) );
2607 implAdjustGenericFieldSetting( xModel
);
2609 DbCellControl::Init( rParent
, xCursor
);
2612 //------------------------------------------------------------------------------
2613 void DbListBox::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2615 DBG_ASSERT( m_pWindow
, "DbListBox::implAdjustGenericFieldSetting: not to be called without window!" );
2616 DBG_ASSERT( _rxModel
.is(), "DbListBox::implAdjustGenericFieldSetting: invalid model!" );
2617 if ( m_pWindow
&& _rxModel
.is() )
2619 sal_Int16 nLines
= getINT16( _rxModel
->getPropertyValue( FM_PROP_LINECOUNT
) );
2620 static_cast< ListBoxControl
* >( m_pWindow
)->SetDropDownLineCount( nLines
);
2624 //------------------------------------------------------------------------------
2625 CellControllerRef
DbListBox::CreateController() const
2627 return new ListBoxCellController((ListBoxControl
*)m_pWindow
);
2630 //------------------------------------------------------------------------------
2631 String
DbListBox::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
2634 if ( _rxField
.is() )
2638 sText
= _rxField
->getString();
2641 Sequence
< sal_Int16
> aPosSeq
= ::comphelper::findValue( m_aValueList
, sText
, sal_True
);
2642 if ( aPosSeq
.getLength() )
2643 sText
= static_cast<ListBox
*>(m_pWindow
)->GetEntry(aPosSeq
.getConstArray()[0]);
2648 catch( const Exception
& )
2650 DBG_UNHANDLED_EXCEPTION();
2656 //------------------------------------------------------------------------------
2657 void DbListBox::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
)
2659 String
sFormattedText( GetFormatText( _rxField
, xFormatter
) );
2660 if ( sFormattedText
.Len() )
2661 static_cast< ListBox
* >( m_pWindow
)->SelectEntry( sFormattedText
);
2663 static_cast< ListBox
* >( m_pWindow
)->SetNoSelection();
2666 //------------------------------------------------------------------------------
2667 void DbListBox::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2669 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbListBox::updateFromModel: invalid call!" );
2671 Sequence
< sal_Int16
> aSelection
;
2672 _rxModel
->getPropertyValue( FM_PROP_SELECT_SEQ
);
2674 sal_Int16 nSelection
= -1;
2675 if ( aSelection
.getLength() > 0 )
2676 nSelection
= aSelection
[ 0 ];
2678 ListBox
* pListBox
= static_cast< ListBox
* >( m_pWindow
);
2680 if ( ( nSelection
>= 0 ) && ( nSelection
< pListBox
->GetEntryCount() ) )
2681 pListBox
->SelectEntryPos( nSelection
);
2683 pListBox
->SetNoSelection( );
2686 //------------------------------------------------------------------------------
2687 sal_Bool
DbListBox::commitControl()
2690 Sequence
<sal_Int16
> aSelectSeq
;
2691 if (static_cast<ListBox
*>(m_pWindow
)->GetSelectEntryCount())
2693 aSelectSeq
.realloc(1);
2694 *(sal_Int16
*)aSelectSeq
.getArray() = (sal_Int16
)static_cast<ListBox
*>(m_pWindow
)->GetSelectEntryPos();
2696 aVal
<<= aSelectSeq
;
2697 m_rColumn
.getModel()->setPropertyValue(FM_PROP_SELECT_SEQ
, aVal
);
2702 DBG_NAME(DbFilterField
);
2703 /*************************************************************************/
2704 DbFilterField::DbFilterField(const Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxORB
,DbGridColumn
& _rColumn
)
2705 :DbCellControl(_rColumn
)
2706 ,OSQLParserClient(_rxORB
)
2707 ,m_nControlClass(::com::sun::star::form::FormComponentType::TEXTFIELD
)
2708 ,m_bFilterList(sal_False
)
2709 ,m_bFilterListFilled(sal_False
)
2710 ,m_bBound(sal_False
)
2712 DBG_CTOR(DbFilterField
,NULL
);
2714 setAlignedController( sal_False
);
2717 //------------------------------------------------------------------------------
2718 DbFilterField::~DbFilterField()
2720 if (m_nControlClass
== ::com::sun::star::form::FormComponentType::CHECKBOX
)
2721 ((CheckBoxControl
*)m_pWindow
)->SetClickHdl( Link() );
2723 DBG_DTOR(DbFilterField
,NULL
);
2726 //------------------------------------------------------------------------------
2727 void DbFilterField::PaintCell(OutputDevice
& rDev
, const Rectangle
& rRect
)
2729 static sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_VCENTER
| TEXT_DRAW_LEFT
;
2730 switch (m_nControlClass
)
2732 case FormComponentType::CHECKBOX
:
2733 DbCellControl::PaintCell( rDev
, rRect
);
2735 case FormComponentType::LISTBOX
:
2736 rDev
.DrawText(rRect
, static_cast<ListBox
*>(m_pWindow
)->GetSelectEntry(), nStyle
);
2739 rDev
.DrawText(rRect
, m_aText
, nStyle
);
2743 //------------------------------------------------------------------------------
2744 void DbFilterField::SetList(const Any
& rItems
, sal_Bool bComboBox
)
2746 ::comphelper::StringSequence aTest
;
2748 const ::rtl::OUString
* pStrings
= aTest
.getConstArray();
2749 sal_Int32 nItems
= aTest
.getLength();
2754 ComboBox
* pField
= (ComboBox
*)m_pWindow
;
2755 for (sal_Int32 i
= 0; i
< nItems
; ++i
, ++pStrings
)
2756 pField
->InsertEntry(*pStrings
, LISTBOX_APPEND
);
2760 ListBox
* pField
= (ListBox
*)m_pWindow
;
2761 for (sal_Int32 i
= 0; i
< nItems
; ++i
, ++pStrings
)
2762 pField
->InsertEntry(*pStrings
, LISTBOX_APPEND
);
2764 m_rColumn
.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ
) >>= m_aValueList
;
2765 m_bBound
= m_aValueList
.getLength() > 0;
2770 //------------------------------------------------------------------------------
2771 void DbFilterField::CreateControl(Window
* pParent
, const Reference
< ::com::sun::star::beans::XPropertySet
>& xModel
)
2773 switch (m_nControlClass
)
2775 case ::com::sun::star::form::FormComponentType::CHECKBOX
:
2776 m_pWindow
= new CheckBoxControl(pParent
);
2777 m_pWindow
->SetPaintTransparent( sal_True
);
2778 ((CheckBoxControl
*)m_pWindow
)->SetClickHdl( LINK( this, DbFilterField
, OnClick
) );
2780 m_pPainter
= new CheckBoxControl(pParent
);
2781 m_pPainter
->SetPaintTransparent( sal_True
);
2782 m_pPainter
->SetBackground();
2784 case ::com::sun::star::form::FormComponentType::LISTBOX
:
2786 m_pWindow
= new ListBoxControl(pParent
);
2787 sal_Int16 nLines
= ::comphelper::getINT16(xModel
->getPropertyValue(FM_PROP_LINECOUNT
));
2788 Any aItems
= xModel
->getPropertyValue(FM_PROP_STRINGITEMLIST
);
2789 SetList(aItems
, m_nControlClass
== ::com::sun::star::form::FormComponentType::COMBOBOX
);
2790 static_cast<ListBox
*>(m_pWindow
)->SetDropDownLineCount(nLines
);
2792 case ::com::sun::star::form::FormComponentType::COMBOBOX
:
2794 m_pWindow
= new ComboBoxControl(pParent
);
2796 AllSettings aSettings
= m_pWindow
->GetSettings();
2797 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
2798 aStyleSettings
.SetSelectionOptions(
2799 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
2800 aSettings
.SetStyleSettings(aStyleSettings
);
2801 m_pWindow
->SetSettings(aSettings
, sal_True
);
2805 sal_Int16 nLines
= ::comphelper::getINT16(xModel
->getPropertyValue(FM_PROP_LINECOUNT
));
2806 Any aItems
= xModel
->getPropertyValue(FM_PROP_STRINGITEMLIST
);
2807 SetList(aItems
, m_nControlClass
== ::com::sun::star::form::FormComponentType::COMBOBOX
);
2808 ((ComboBox
*)m_pWindow
)->SetDropDownLineCount(nLines
);
2811 ((ComboBox
*)m_pWindow
)->SetDropDownLineCount(5);
2816 m_pWindow
= new Edit(pParent
, WB_LEFT
);
2817 AllSettings aSettings
= m_pWindow
->GetSettings();
2818 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
2819 aStyleSettings
.SetSelectionOptions(
2820 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
2821 aSettings
.SetStyleSettings(aStyleSettings
);
2822 m_pWindow
->SetSettings(aSettings
, sal_True
);
2827 //------------------------------------------------------------------------------
2828 void DbFilterField::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
2830 Reference
< ::com::sun::star::beans::XPropertySet
> xModel(m_rColumn
.getModel());
2831 m_rColumn
.SetAlignment(::com::sun::star::awt::TextAlign::LEFT
);
2835 m_bFilterList
= ::comphelper::hasProperty(FM_PROP_FILTERPROPOSAL
, xModel
) && ::comphelper::getBOOL(xModel
->getPropertyValue(FM_PROP_FILTERPROPOSAL
));
2837 m_nControlClass
= ::com::sun::star::form::FormComponentType::COMBOBOX
;
2840 sal_Int16 nClassId
= ::comphelper::getINT16(xModel
->getPropertyValue(FM_PROP_CLASSID
));
2843 case FormComponentType::CHECKBOX
:
2844 case FormComponentType::LISTBOX
:
2845 case FormComponentType::COMBOBOX
:
2846 m_nControlClass
= nClassId
;
2850 m_nControlClass
= FormComponentType::COMBOBOX
;
2852 m_nControlClass
= FormComponentType::TEXTFIELD
;
2857 CreateControl( &rParent
, xModel
);
2858 DbCellControl::Init( rParent
, xCursor
);
2860 // filter cells are never readonly
2861 // 31.07.2002 - 101584 - fs@openoffice.org
2862 Edit
* pAsEdit
= dynamic_cast< Edit
* >( m_pWindow
);
2864 pAsEdit
->SetReadOnly( sal_False
);
2867 //------------------------------------------------------------------------------
2868 CellControllerRef
DbFilterField::CreateController() const
2870 CellControllerRef xController
;
2871 switch (m_nControlClass
)
2873 case ::com::sun::star::form::FormComponentType::CHECKBOX
:
2874 xController
= new CheckBoxCellController((CheckBoxControl
*)m_pWindow
);
2876 case ::com::sun::star::form::FormComponentType::LISTBOX
:
2877 xController
= new ListBoxCellController((ListBoxControl
*)m_pWindow
);
2879 case ::com::sun::star::form::FormComponentType::COMBOBOX
:
2880 xController
= new ComboBoxCellController((ComboBoxControl
*)m_pWindow
);
2884 xController
= new ComboBoxCellController((ComboBoxControl
*)m_pWindow
);
2886 xController
= new EditCellController((Edit
*)m_pWindow
);
2891 //------------------------------------------------------------------------------
2892 void DbFilterField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2894 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbFilterField::updateFromModel: invalid call!" );
2897 OSL_ENSURE( sal_False
, "DbListBox::updateFromModel: not implemented yet (how the hell did you reach this?)!" );
2898 // TODO: implement this.
2899 // remember: updateFromModel should be some kind of opposite of commitControl
2902 //------------------------------------------------------------------------------
2903 sal_Bool
DbFilterField::commitControl()
2905 String
aText(m_aText
);
2906 switch (m_nControlClass
)
2908 case ::com::sun::star::form::FormComponentType::CHECKBOX
:
2910 case ::com::sun::star::form::FormComponentType::LISTBOX
:
2911 if (static_cast<ListBox
*>(m_pWindow
)->GetSelectEntryCount())
2913 sal_Int16 nPos
= (sal_Int16
)static_cast<ListBox
*>(m_pWindow
)->GetSelectEntryPos();
2914 aText
= (const sal_Unicode
*)m_aValueList
.getConstArray()[nPos
];
2919 if (m_aText
!= aText
)
2922 m_aCommitLink
.Call(this);
2926 aText
= m_pWindow
->GetText();
2929 if (m_aText
!= aText
)
2931 // check the text with the SQL-Parser
2932 String
aNewText(aText
);
2933 aNewText
.EraseTrailingChars();
2934 if (aNewText
.Len() != 0)
2936 ::rtl::OUString aErrorMsg
;
2937 Reference
< XNumberFormatter
> xNumberFormatter(m_rColumn
.GetParent().getNumberFormatter());
2939 ::rtl::Reference
< ISQLParseNode
> xParseNode
= predicateTree(aErrorMsg
, aNewText
,xNumberFormatter
, m_rColumn
.GetField());
2940 if (xParseNode
.is())
2942 ::rtl::OUString aPreparedText
;
2944 ::com::sun::star::lang::Locale aAppLocale
= Application::GetSettings().GetUILocale();
2946 Reference
< XRowSet
> xDataSourceRowSet(
2947 (Reference
< XInterface
>)*m_rColumn
.GetParent().getDataSource(), UNO_QUERY
);
2948 Reference
< XConnection
> xConnection(getRowSetConnection(xDataSourceRowSet
));
2950 xParseNode
->parseNodeToPredicateStr(aPreparedText
,
2953 m_rColumn
.GetField(),aAppLocale
,'.',
2955 m_aText
= aPreparedText
;
2959 // display the error and return sal_False
2960 String
aTitle( SVX_RES(RID_STR_SYNTAXERROR
) );
2962 SQLException aError
;
2963 aError
.Message
= aErrorMsg
;
2964 displayException(aError
, m_pWindow
->GetParent());
2965 // TODO: transport the title
2973 m_pWindow
->SetText(m_aText
);
2974 m_aCommitLink
.Call(this);
2979 //------------------------------------------------------------------------------
2980 void DbFilterField::SetText(const String
& rText
)
2983 switch (m_nControlClass
)
2985 case ::com::sun::star::form::FormComponentType::CHECKBOX
:
2988 if (rText
.EqualsAscii("1"))
2989 eState
= STATE_CHECK
;
2990 else if (rText
.EqualsAscii("0"))
2991 eState
= STATE_NOCHECK
;
2993 eState
= STATE_DONTKNOW
;
2995 ((CheckBoxControl
*)m_pWindow
)->GetBox().SetState(eState
);
2996 ((CheckBoxControl
*)m_pPainter
)->GetBox().SetState(eState
);
2998 case ::com::sun::star::form::FormComponentType::LISTBOX
:
3001 Sequence
<sal_Int16
> aPosSeq
= ::comphelper::findValue(m_aValueList
, m_aText
, sal_True
);
3002 if (aPosSeq
.getLength())
3003 static_cast<ListBox
*>(m_pWindow
)->SelectEntryPos(aPosSeq
.getConstArray()[0], sal_True
);
3005 static_cast<ListBox
*>(m_pWindow
)->SetNoSelection();
3008 m_pWindow
->SetText(m_aText
);
3011 // now force a repaint on the window
3012 m_rColumn
.GetParent().RowModified(0,m_rColumn
.GetId());
3015 //------------------------------------------------------------------------------
3016 void DbFilterField::Update()
3018 // should we fill the combobox with a filter proposal?
3019 if (m_bFilterList
&& !m_bFilterListFilled
)
3021 m_bFilterListFilled
= sal_True
;
3022 Reference
< ::com::sun::star::beans::XPropertySet
> xField
= m_rColumn
.GetField();
3026 ::rtl::OUString aName
;
3027 xField
->getPropertyValue(FM_PROP_NAME
) >>= aName
;
3030 Reference
< ::com::sun::star::container::XChild
> xModelAsChild(m_rColumn
.getModel(), UNO_QUERY
);
3032 xModelAsChild
= Reference
< ::com::sun::star::container::XChild
> (xModelAsChild
->getParent(),UNO_QUERY
);
3033 Reference
< XRowSet
> xForm(xModelAsChild
->getParent(), UNO_QUERY
);
3037 Reference
< XConnection
> xConnection(getRowSetConnection(xForm
));
3038 if (!xConnection
.is())
3041 Reference
< ::com::sun::star::sdb::XSQLQueryComposerFactory
> xFactory(xConnection
, UNO_QUERY
);
3044 DBG_ERROR("DbFilterField::Update : used the right place to request the ::com::sun::star::sdb::XSQLQueryComposerFactory interface ?");
3048 Reference
< ::com::sun::star::sdb::XSQLQueryComposer
> xComposer
= xFactory
->createQueryComposer();
3051 Reference
< ::com::sun::star::beans::XPropertySet
> xFormAsSet(xForm
, UNO_QUERY
);
3052 ::rtl::OUString sStatement
;
3053 xFormAsSet
->getPropertyValue(FM_PROP_ACTIVECOMMAND
) >>= sStatement
;
3054 xComposer
->setQuery(sStatement
);
3056 catch(const Exception
&)
3058 ::comphelper::disposeComponent(xComposer
);
3062 Reference
< ::com::sun::star::beans::XPropertySet
> xComposerAsSet(xComposer
, UNO_QUERY
);
3063 if (!xComposerAsSet
.is())
3067 Reference
< ::com::sun::star::container::XNameAccess
> xFieldNames
;
3068 Reference
< ::com::sun::star::container::XNameAccess
> xTablesNames
;
3069 Reference
< ::com::sun::star::beans::XPropertySet
> xComposerFieldAsSet
;
3071 ::cppu::extractInterface(xFieldNames
, xComposerAsSet
->getPropertyValue(FM_PROP_SELECTED_FIELDS
));
3072 ::cppu::extractInterface(xTablesNames
, xComposerAsSet
->getPropertyValue(FM_PROP_SELECTED_TABLES
));
3073 ::cppu::extractInterface(xComposerFieldAsSet
, xFieldNames
->getByName(aName
));
3075 if (xComposerFieldAsSet
.is() && ::comphelper::hasProperty(FM_PROP_TABLENAME
, xComposerFieldAsSet
) &&
3076 ::comphelper::hasProperty(FM_PROP_FIELDSOURCE
, xComposerFieldAsSet
))
3078 ::rtl::OUString aFieldName
;
3079 ::rtl::OUString aTableName
;
3080 xComposerFieldAsSet
->getPropertyValue(FM_PROP_FIELDSOURCE
) >>= aFieldName
;
3081 xComposerFieldAsSet
->getPropertyValue(FM_PROP_TABLENAME
) >>= aTableName
;
3083 // no possibility to create a select statement
3084 // looking for the complete table name
3085 if (!xTablesNames
->hasByName(aTableName
))
3088 // ein Statement aufbauen und abschicken als query
3089 // Access to the connection
3090 Reference
< XStatement
> xStatement
;
3091 Reference
< XResultSet
> xListCursor
;
3092 Reference
< ::com::sun::star::sdb::XColumn
> xDataField
;
3096 Reference
< XDatabaseMetaData
> xMeta
= xConnection
->getMetaData();
3098 String
aQuote( xMeta
->getIdentifierQuoteString());
3100 aStatement
.AssignAscii("SELECT DISTINCT ");
3102 aStatement
+= String(quoteName(aQuote
, aName
));
3103 if (aFieldName
.getLength() && aName
!= aFieldName
)
3105 aStatement
.AppendAscii(" AS ");
3106 aStatement
+= quoteName(aQuote
, aFieldName
).getStr();
3109 aStatement
.AppendAscii(" FROM ");
3111 Reference
< XPropertySet
> xTableNameAccess( xTablesNames
->getByName(aTableName
), UNO_QUERY_THROW
);
3112 aStatement
+= composeTableNameForSelect( xConnection
, xTableNameAccess
).getStr();
3114 xStatement
= xConnection
->createStatement();
3115 Reference
< ::com::sun::star::beans::XPropertySet
> xStatementProps(xStatement
, UNO_QUERY
);
3116 xStatementProps
->setPropertyValue(FM_PROP_ESCAPE_PROCESSING
, makeAny((sal_Bool
)sal_True
));
3118 xListCursor
= xStatement
->executeQuery(aStatement
);
3120 Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
> xSupplyCols(xListCursor
, UNO_QUERY
);
3121 Reference
< ::com::sun::star::container::XIndexAccess
> xFields(xSupplyCols
->getColumns(), UNO_QUERY
);
3122 ::cppu::extractInterface(xDataField
, xFields
->getByIndex(0));
3123 if (!xDataField
.is())
3126 catch(const Exception
&)
3128 ::comphelper::disposeComponent(xStatement
);
3133 ::std::vector
< ::rtl::OUString
> aStringList
;
3134 aStringList
.reserve(16);
3135 ::rtl::OUString aStr
;
3136 com::sun::star::util::Date aNullDate
= m_rColumn
.GetParent().getNullDate();
3137 sal_Int32 nFormatKey
= m_rColumn
.GetKey();
3138 Reference
< XNumberFormatter
> xFormatter
= m_rColumn
.GetParent().getNumberFormatter();
3139 sal_Int16 nKeyType
= ::comphelper::getNumberFormatType(xFormatter
->getNumberFormatsSupplier()->getNumberFormats(), nFormatKey
);
3141 while (!xListCursor
->isAfterLast() && i
++ < SHRT_MAX
) // max anzahl eintraege
3143 aStr
= getValue(xDataField
, xFormatter
, aNullDate
, nFormatKey
, nKeyType
);
3144 aStringList
.push_back(aStr
);
3145 xListCursor
->next();
3148 // filling the entries for the combobox
3149 for (::std::vector
< ::rtl::OUString
>::const_iterator iter
= aStringList
.begin();
3150 iter
!= aStringList
.end(); ++iter
)
3151 ((ComboBox
*)m_pWindow
)->InsertEntry(*iter
, LISTBOX_APPEND
);
3156 //------------------------------------------------------------------------------
3157 XubString
DbFilterField::GetFormatText(const Reference
< XColumn
>& /*_rxField*/, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
3162 //------------------------------------------------------------------
3163 void DbFilterField::UpdateFromField(const Reference
< XColumn
>& /*_rxField*/, const Reference
< XNumberFormatter
>& /*xFormatter*/)
3165 DBG_ERROR( "DbFilterField::UpdateFromField: cannot update a filter control from a field!" );
3168 //------------------------------------------------------------------
3169 IMPL_LINK( DbFilterField
, OnClick
, void*, EMPTYARG
)
3171 TriState eState
= ((CheckBoxControl
*)m_pWindow
)->GetBox().GetState();
3177 aText
.AssignAscii("1");
3180 aText
.AssignAscii("0");
3182 case STATE_DONTKNOW
:
3187 if (m_aText
!= aText
)
3190 m_aCommitLink
.Call(this);
3195 /*************************************************************************/
3196 TYPEINIT0(FmXGridCell
);
3199 DBG_NAME(FmXGridCell
);
3200 //-----------------------------------------------------------------------------
3201 FmXGridCell::FmXGridCell( DbGridColumn
* pColumn
, DbCellControl
* _pControl
)
3202 :OComponentHelper(m_aMutex
)
3204 ,m_pCellControl( _pControl
)
3205 ,m_aWindowListeners( m_aMutex
)
3206 ,m_aFocusListeners( m_aMutex
)
3207 ,m_aKeyListeners( m_aMutex
)
3208 ,m_aMouseListeners( m_aMutex
)
3209 ,m_aMouseMotionListeners( m_aMutex
)
3211 DBG_CTOR(FmXGridCell
,NULL
);
3214 //-----------------------------------------------------------------------------
3215 void FmXGridCell::init()
3217 Window
* pEventWindow( getEventWindow() );
3219 pEventWindow
->AddEventListener( LINK( this, FmXGridCell
, OnWindowEvent
) );
3222 //-----------------------------------------------------------------------------
3223 Window
* FmXGridCell::getEventWindow() const
3225 if ( m_pCellControl
)
3226 return &m_pCellControl
->GetWindow();
3230 //-----------------------------------------------------------------------------
3231 FmXGridCell::~FmXGridCell()
3233 if (!OComponentHelper::rBHelper
.bDisposed
)
3239 DBG_DTOR(FmXGridCell
,NULL
);
3242 //------------------------------------------------------------------
3243 void FmXGridCell::SetTextLineColor()
3246 m_pCellControl
->SetTextLineColor();
3249 //------------------------------------------------------------------
3250 void FmXGridCell::SetTextLineColor(const Color
& _rColor
)
3253 m_pCellControl
->SetTextLineColor(_rColor
);
3257 //------------------------------------------------------------------
3258 Sequence
< Type
> SAL_CALL
FmXGridCell::getTypes( ) throw (RuntimeException
)
3260 Sequence
< uno::Type
> aTypes
= ::comphelper::concatSequences(
3261 ::cppu::OComponentHelper::getTypes(),
3262 FmXGridCell_Base::getTypes()
3264 if ( m_pCellControl
)
3265 aTypes
= ::comphelper::concatSequences(
3267 FmXGridCell_WindowBase::getTypes()
3272 //------------------------------------------------------------------
3273 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXGridCell
)
3276 //-----------------------------------------------------------------------------
3277 void FmXGridCell::disposing()
3279 lang::EventObject
aEvent( *this );
3280 m_aWindowListeners
.disposeAndClear( aEvent
);
3281 m_aFocusListeners
.disposeAndClear( aEvent
);
3282 m_aKeyListeners
.disposeAndClear( aEvent
);
3283 m_aMouseListeners
.disposeAndClear( aEvent
);
3284 m_aMouseMotionListeners
.disposeAndClear( aEvent
);
3286 OComponentHelper::disposing();
3288 DELETEZ(m_pCellControl
);
3291 //------------------------------------------------------------------
3292 Any SAL_CALL
FmXGridCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
3294 Any aReturn
= OComponentHelper::queryAggregation( _rType
);
3296 if ( !aReturn
.hasValue() )
3297 aReturn
= FmXGridCell_Base::queryInterface( _rType
);
3299 if ( !aReturn
.hasValue() && ( m_pCellControl
!= NULL
) )
3300 aReturn
= FmXGridCell_WindowBase::queryInterface( _rType
);
3305 // ::com::sun::star::awt::XControl
3306 //-----------------------------------------------------------------------------
3307 Reference
< XInterface
> FmXGridCell::getContext() throw( RuntimeException
)
3309 return Reference
< XInterface
> ();
3312 //-----------------------------------------------------------------------------
3313 Reference
< ::com::sun::star::awt::XControlModel
> FmXGridCell::getModel() throw( ::com::sun::star::uno::RuntimeException
)
3315 return Reference
< ::com::sun::star::awt::XControlModel
> (m_pColumn
->getModel(), UNO_QUERY
);
3318 // ::com::sun::star::form::XBoundControl
3319 //------------------------------------------------------------------
3320 sal_Bool
FmXGridCell::getLock() throw( RuntimeException
)
3322 return m_pColumn
->isLocked();
3325 //------------------------------------------------------------------
3326 void FmXGridCell::setLock(sal_Bool _bLock
) throw( RuntimeException
)
3328 if (getLock() == _bLock
)
3332 ::osl::MutexGuard
aGuard(m_aMutex
);
3333 m_pColumn
->setLock(_bLock
);
3337 //------------------------------------------------------------------
3338 void SAL_CALL
FmXGridCell::setPosSize( ::sal_Int32 _XX
, ::sal_Int32 _Y
, ::sal_Int32 _Width
, ::sal_Int32 _Height
, ::sal_Int16 _Flags
) throw (RuntimeException
)
3340 OSL_ENSURE( false, "FmXGridCell::setPosSize: not implemented" );
3346 // not allowed to tamper with this for a grid cell
3349 //------------------------------------------------------------------
3350 awt::Rectangle SAL_CALL
FmXGridCell::getPosSize( ) throw (RuntimeException
)
3352 OSL_ENSURE( false, "FmXGridCell::getPosSize: not implemented" );
3353 return awt::Rectangle();
3356 //------------------------------------------------------------------
3357 void SAL_CALL
FmXGridCell::setVisible( ::sal_Bool _Visible
) throw (RuntimeException
)
3359 OSL_ENSURE( false, "FmXGridCell::setVisible: not implemented" );
3361 // not allowed to tamper with this for a grid cell
3364 //------------------------------------------------------------------
3365 void SAL_CALL
FmXGridCell::setEnable( ::sal_Bool _Enable
) throw (RuntimeException
)
3367 OSL_ENSURE( false, "FmXGridCell::setEnable: not implemented" );
3369 // not allowed to tamper with this for a grid cell
3372 //------------------------------------------------------------------
3373 void SAL_CALL
FmXGridCell::setFocus( ) throw (RuntimeException
)
3375 OSL_ENSURE( false, "FmXGridCell::setFocus: not implemented" );
3376 // not allowed to tamper with this for a grid cell
3379 //------------------------------------------------------------------
3380 void SAL_CALL
FmXGridCell::addWindowListener( const Reference
< awt::XWindowListener
>& _rxListener
) throw (RuntimeException
)
3382 m_aWindowListeners
.addInterface( _rxListener
);
3385 //------------------------------------------------------------------
3386 void SAL_CALL
FmXGridCell::removeWindowListener( const Reference
< awt::XWindowListener
>& _rxListener
) throw (RuntimeException
)
3388 m_aWindowListeners
.removeInterface( _rxListener
);
3391 //------------------------------------------------------------------
3392 void SAL_CALL
FmXGridCell::addFocusListener( const Reference
< awt::XFocusListener
>& _rxListener
) throw (RuntimeException
)
3394 m_aFocusListeners
.addInterface( _rxListener
);
3397 //------------------------------------------------------------------
3398 void SAL_CALL
FmXGridCell::removeFocusListener( const Reference
< awt::XFocusListener
>& _rxListener
) throw (RuntimeException
)
3400 m_aFocusListeners
.removeInterface( _rxListener
);
3403 //------------------------------------------------------------------
3404 void SAL_CALL
FmXGridCell::addKeyListener( const Reference
< awt::XKeyListener
>& _rxListener
) throw (RuntimeException
)
3406 m_aKeyListeners
.addInterface( _rxListener
);
3409 //------------------------------------------------------------------
3410 void SAL_CALL
FmXGridCell::removeKeyListener( const Reference
< awt::XKeyListener
>& _rxListener
) throw (RuntimeException
)
3412 m_aKeyListeners
.removeInterface( _rxListener
);
3415 //------------------------------------------------------------------
3416 void SAL_CALL
FmXGridCell::addMouseListener( const Reference
< awt::XMouseListener
>& _rxListener
) throw (RuntimeException
)
3418 m_aMouseListeners
.addInterface( _rxListener
);
3421 //------------------------------------------------------------------
3422 void SAL_CALL
FmXGridCell::removeMouseListener( const Reference
< awt::XMouseListener
>& _rxListener
) throw (RuntimeException
)
3424 m_aMouseListeners
.removeInterface( _rxListener
);
3427 //------------------------------------------------------------------
3428 void SAL_CALL
FmXGridCell::addMouseMotionListener( const Reference
< awt::XMouseMotionListener
>& _rxListener
) throw (RuntimeException
)
3430 m_aMouseMotionListeners
.addInterface( _rxListener
);
3433 //------------------------------------------------------------------
3434 void SAL_CALL
FmXGridCell::removeMouseMotionListener( const Reference
< awt::XMouseMotionListener
>& _rxListener
) throw (RuntimeException
)
3436 m_aMouseMotionListeners
.removeInterface( _rxListener
);
3439 //------------------------------------------------------------------
3440 void SAL_CALL
FmXGridCell::addPaintListener( const Reference
< awt::XPaintListener
>& _rxListener
) throw (RuntimeException
)
3442 OSL_ENSURE( false, "FmXGridCell::addPaintListener: not implemented" );
3446 //------------------------------------------------------------------
3447 void SAL_CALL
FmXGridCell::removePaintListener( const Reference
< awt::XPaintListener
>& _rxListener
) throw (RuntimeException
)
3449 OSL_ENSURE( false, "FmXGridCell::removePaintListener: not implemented" );
3453 //------------------------------------------------------------------
3454 IMPL_LINK( FmXGridCell
, OnWindowEvent
, VclWindowEvent
*, _pEvent
)
3456 ENSURE_OR_THROW( _pEvent
, "illegal event pointer" );
3457 ENSURE_OR_THROW( _pEvent
->GetWindow(), "illegal window" );
3458 onWindowEvent( _pEvent
->GetId(), *_pEvent
->GetWindow(), _pEvent
->GetData() );
3462 //------------------------------------------------------------------------------
3463 void FmXGridCell::onFocusGained( const awt::FocusEvent
& _rEvent
)
3465 m_aFocusListeners
.notifyEach( &awt::XFocusListener::focusGained
, _rEvent
);
3468 //------------------------------------------------------------------------------
3469 void FmXGridCell::onFocusLost( const awt::FocusEvent
& _rEvent
)
3471 m_aFocusListeners
.notifyEach( &awt::XFocusListener::focusLost
, _rEvent
);
3474 //------------------------------------------------------------------------------
3475 void FmXGridCell::onWindowEvent( const ULONG _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
3477 switch ( _nEventId
)
3479 case VCLEVENT_CONTROL_GETFOCUS
:
3480 case VCLEVENT_WINDOW_GETFOCUS
:
3481 case VCLEVENT_CONTROL_LOSEFOCUS
:
3482 case VCLEVENT_WINDOW_LOSEFOCUS
:
3484 if ( ( _rWindow
.IsCompoundControl()
3485 && ( _nEventId
== VCLEVENT_CONTROL_GETFOCUS
3486 || _nEventId
== VCLEVENT_CONTROL_LOSEFOCUS
3489 || ( !_rWindow
.IsCompoundControl()
3490 && ( _nEventId
== VCLEVENT_WINDOW_GETFOCUS
3491 || _nEventId
== VCLEVENT_WINDOW_LOSEFOCUS
3496 if ( !m_aFocusListeners
.getLength() )
3499 bool bFocusGained
= ( _nEventId
== VCLEVENT_CONTROL_GETFOCUS
) || ( _nEventId
== VCLEVENT_WINDOW_GETFOCUS
);
3501 awt::FocusEvent aEvent
;
3502 aEvent
.Source
= *this;
3503 aEvent
.FocusFlags
= _rWindow
.GetGetFocusFlags();
3504 aEvent
.Temporary
= sal_False
;
3507 onFocusGained( aEvent
);
3509 onFocusLost( aEvent
);
3513 case VCLEVENT_WINDOW_MOUSEBUTTONDOWN
:
3514 case VCLEVENT_WINDOW_MOUSEBUTTONUP
:
3516 if ( !m_aMouseListeners
.getLength() )
3519 const bool bButtonDown
= ( _nEventId
== VCLEVENT_WINDOW_MOUSEBUTTONDOWN
);
3521 awt::MouseEvent
aEvent( VCLUnoHelper::createMouseEvent( *static_cast< const ::MouseEvent
* >( _pEventData
), *this ) );
3522 m_aMouseListeners
.notifyEach( bButtonDown
? &awt::XMouseListener::mousePressed
: &awt::XMouseListener::mouseReleased
, aEvent
);
3525 case VCLEVENT_WINDOW_MOUSEMOVE
:
3527 const MouseEvent
& rMouseEvent
= *static_cast< const ::MouseEvent
* >( _pEventData
);
3528 if ( rMouseEvent
.IsEnterWindow() || rMouseEvent
.IsLeaveWindow() )
3530 if ( m_aMouseListeners
.getLength() != 0 )
3532 awt::MouseEvent
aEvent( VCLUnoHelper::createMouseEvent( rMouseEvent
, *this ) );
3533 m_aMouseListeners
.notifyEach( rMouseEvent
.IsEnterWindow() ? &awt::XMouseListener::mouseEntered
: &awt::XMouseListener::mouseExited
, aEvent
);
3536 else if ( !rMouseEvent
.IsEnterWindow() && !rMouseEvent
.IsLeaveWindow() )
3538 if ( m_aMouseMotionListeners
.getLength() != 0 )
3540 awt::MouseEvent
aEvent( VCLUnoHelper::createMouseEvent( rMouseEvent
, *this ) );
3541 aEvent
.ClickCount
= 0;
3542 const bool bSimpleMove
= ( ( rMouseEvent
.GetMode() & MOUSE_SIMPLEMOVE
) != 0 );
3543 m_aMouseMotionListeners
.notifyEach( bSimpleMove
? &awt::XMouseMotionListener::mouseMoved
: &awt::XMouseMotionListener::mouseDragged
, aEvent
);
3548 case VCLEVENT_WINDOW_KEYINPUT
:
3549 case VCLEVENT_WINDOW_KEYUP
:
3551 if ( !m_aKeyListeners
.getLength() )
3554 const bool bKeyPressed
= ( _nEventId
== VCLEVENT_WINDOW_KEYINPUT
);
3555 awt::KeyEvent
aEvent( VCLUnoHelper::createKeyEvent( *static_cast< const ::KeyEvent
* >( _pEventData
), *this ) );
3556 m_aKeyListeners
.notifyEach( bKeyPressed
? &awt::XKeyListener::keyPressed
: &awt::XKeyListener::keyReleased
, aEvent
);
3562 /*************************************************************************/
3563 TYPEINIT1(FmXDataCell
, FmXGridCell
);
3564 //------------------------------------------------------------------------------
3565 void FmXDataCell::PaintFieldToCell(OutputDevice
& rDev
, const Rectangle
& rRect
,
3566 const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
,
3567 const Reference
< XNumberFormatter
>& xFormatter
)
3569 m_pCellControl
->PaintFieldToCell( rDev
, rRect
, _rxField
, xFormatter
);
3572 //------------------------------------------------------------------------------
3573 void FmXDataCell::UpdateFromColumn()
3575 Reference
< ::com::sun::star::sdb::XColumn
> xField(m_pColumn
->GetCurrentFieldValue());
3577 m_pCellControl
->UpdateFromField(xField
, m_pColumn
->GetParent().getNumberFormatter());
3580 /*************************************************************************/
3581 TYPEINIT1(FmXTextCell
, FmXDataCell
);
3583 FmXTextCell::FmXTextCell( DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
3584 :FmXDataCell( pColumn
, _rControl
)
3585 ,m_bFastPaint( sal_True
)
3589 //------------------------------------------------------------------------------
3590 void FmXTextCell::PaintFieldToCell(OutputDevice
& rDev
,
3591 const Rectangle
& rRect
,
3592 const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
,
3593 const Reference
< XNumberFormatter
>& xFormatter
)
3595 if ( !m_bFastPaint
)
3597 FmXDataCell::PaintFieldToCell( rDev
, rRect
, _rxField
, xFormatter
);
3601 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_VCENTER
;
3602 if ( ( rDev
.GetOutDevType() == OUTDEV_WINDOW
) && !static_cast< Window
& >( rDev
).IsEnabled() )
3603 nStyle
|= TEXT_DRAW_DISABLE
;
3605 switch (m_pColumn
->GetAlignment())
3607 case ::com::sun::star::awt::TextAlign::RIGHT
:
3608 nStyle
|= TEXT_DRAW_RIGHT
;
3610 case ::com::sun::star::awt::TextAlign::CENTER
:
3611 nStyle
|= TEXT_DRAW_CENTER
;
3614 nStyle
|= TEXT_DRAW_LEFT
;
3617 Color
* pColor
= NULL
;
3618 String aText
= GetText(_rxField
, xFormatter
, &pColor
);
3621 Color
aOldTextColor( rDev
.GetTextColor() );
3622 rDev
.SetTextColor( *pColor
);
3623 rDev
.DrawText(rRect
, aText
, nStyle
);
3624 rDev
.SetTextColor( aOldTextColor
);
3627 rDev
.DrawText(rRect
, aText
, nStyle
);
3631 /*************************************************************************/
3633 DBG_NAME(FmXEditCell
);
3634 //------------------------------------------------------------------------------
3635 FmXEditCell::FmXEditCell( DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
3636 :FmXTextCell( pColumn
, _rControl
)
3637 ,m_aTextListeners(m_aMutex
)
3638 ,m_aChangeListeners( m_aMutex
)
3639 ,m_pEditImplementation( NULL
)
3640 ,m_bOwnEditImplementation( false )
3642 DBG_CTOR(FmXEditCell
,NULL
);
3644 DbTextField
* pTextField
= PTR_CAST( DbTextField
, &_rControl
);
3648 m_pEditImplementation
= pTextField
->GetEditImplementation();
3649 if ( !pTextField
->IsSimpleEdit() )
3650 m_bFastPaint
= sal_False
;
3654 m_pEditImplementation
= new EditImplementation( static_cast< Edit
& >( _rControl
.GetWindow() ) );
3655 m_bOwnEditImplementation
= true;
3659 //------------------------------------------------------------------
3660 FmXEditCell::~FmXEditCell()
3662 if (!OComponentHelper::rBHelper
.bDisposed
)
3669 DBG_DTOR(FmXEditCell
,NULL
);
3673 //-----------------------------------------------------------------------------
3674 void FmXEditCell::disposing()
3676 ::com::sun::star::lang::EventObject
aEvt(*this);
3677 m_aTextListeners
.disposeAndClear(aEvt
);
3678 m_aChangeListeners
.disposeAndClear(aEvt
);
3680 m_pEditImplementation
->SetModifyHdl( Link() );
3681 if ( m_bOwnEditImplementation
)
3682 delete m_pEditImplementation
;
3683 m_pEditImplementation
= NULL
;
3685 FmXDataCell::disposing();
3688 //------------------------------------------------------------------
3689 Any SAL_CALL
FmXEditCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
3691 Any aReturn
= FmXTextCell::queryAggregation( _rType
);
3693 if ( !aReturn
.hasValue() )
3694 aReturn
= FmXEditCell_Base::queryInterface( _rType
);
3699 //-------------------------------------------------------------------------
3700 Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
FmXEditCell::getTypes( ) throw(RuntimeException
)
3702 return ::comphelper::concatSequences(
3703 FmXTextCell::getTypes(),
3704 FmXEditCell_Base::getTypes()
3708 //------------------------------------------------------------------------------
3709 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXEditCell
)
3711 // ::com::sun::star::awt::XTextComponent
3712 //------------------------------------------------------------------------------
3713 void SAL_CALL
FmXEditCell::addTextListener(const Reference
< ::com::sun::star::awt::XTextListener
>& l
) throw( RuntimeException
)
3715 m_aTextListeners
.addInterface( l
);
3718 //------------------------------------------------------------------------------
3719 void SAL_CALL
FmXEditCell::removeTextListener(const Reference
< ::com::sun::star::awt::XTextListener
>& l
) throw( RuntimeException
)
3721 m_aTextListeners
.removeInterface( l
);
3724 //------------------------------------------------------------------------------
3725 void SAL_CALL
FmXEditCell::setText( const ::rtl::OUString
& aText
) throw( RuntimeException
)
3727 ::osl::MutexGuard
aGuard( m_aMutex
);
3729 if ( m_pEditImplementation
)
3731 m_pEditImplementation
->SetText( aText
);
3733 // In JAVA wird auch ein textChanged ausgeloest, in VCL nicht.
3734 // ::com::sun::star::awt::Toolkit soll JAVA-komform sein...
3739 //------------------------------------------------------------------------------
3740 void SAL_CALL
FmXEditCell::insertText(const ::com::sun::star::awt::Selection
& rSel
, const ::rtl::OUString
& aText
) throw(RuntimeException
)
3742 ::osl::MutexGuard
aGuard( m_aMutex
);
3744 if ( m_pEditImplementation
)
3746 m_pEditImplementation
->SetSelection( Selection( rSel
.Min
, rSel
.Max
) );
3747 m_pEditImplementation
->ReplaceSelected( aText
);
3751 //------------------------------------------------------------------------------
3752 ::rtl::OUString SAL_CALL
FmXEditCell::getText() throw( RuntimeException
)
3754 ::osl::MutexGuard
aGuard( m_aMutex
);
3756 ::rtl::OUString aText
;
3757 if ( m_pEditImplementation
)
3759 if ( m_pEditImplementation
->GetControl().IsVisible() && m_pColumn
->GetParent().getDisplaySynchron())
3761 // if the display isn't sync with the cursor we can't ask the edit field
3762 LineEnd eLineEndFormat
= m_pColumn
? getModelLineEndSetting( m_pColumn
->getModel() ) : LINEEND_LF
;
3763 aText
= m_pEditImplementation
->GetText( eLineEndFormat
);
3767 Reference
< ::com::sun::star::sdb::XColumn
> xField(m_pColumn
->GetCurrentFieldValue());
3769 aText
= GetText(xField
, m_pColumn
->GetParent().getNumberFormatter());
3775 //------------------------------------------------------------------------------
3776 ::rtl::OUString SAL_CALL
FmXEditCell::getSelectedText( void ) throw( RuntimeException
)
3778 ::osl::MutexGuard
aGuard( m_aMutex
);
3780 ::rtl::OUString aText
;
3781 if ( m_pEditImplementation
)
3783 LineEnd eLineEndFormat
= m_pColumn
? getModelLineEndSetting( m_pColumn
->getModel() ) : LINEEND_LF
;
3784 aText
= m_pEditImplementation
->GetSelected( eLineEndFormat
);
3789 //------------------------------------------------------------------------------
3790 void SAL_CALL
FmXEditCell::setSelection( const ::com::sun::star::awt::Selection
& aSelection
) throw( RuntimeException
)
3792 ::osl::MutexGuard
aGuard( m_aMutex
);
3794 if ( m_pEditImplementation
)
3795 m_pEditImplementation
->SetSelection( Selection( aSelection
.Min
, aSelection
.Max
) );
3798 //------------------------------------------------------------------------------
3799 ::com::sun::star::awt::Selection SAL_CALL
FmXEditCell::getSelection( void ) throw( RuntimeException
)
3801 ::osl::MutexGuard
aGuard( m_aMutex
);
3804 if ( m_pEditImplementation
)
3805 aSel
= m_pEditImplementation
->GetSelection();
3807 return ::com::sun::star::awt::Selection(aSel
.Min(), aSel
.Max());
3810 //------------------------------------------------------------------------------
3811 sal_Bool SAL_CALL
FmXEditCell::isEditable( void ) throw( RuntimeException
)
3813 ::osl::MutexGuard
aGuard( m_aMutex
);
3815 return ( m_pEditImplementation
&& !m_pEditImplementation
->IsReadOnly() && m_pEditImplementation
->GetControl().IsEnabled() ) ? sal_True
: sal_False
;
3818 //------------------------------------------------------------------------------
3819 void SAL_CALL
FmXEditCell::setEditable( sal_Bool bEditable
) throw( RuntimeException
)
3821 ::osl::MutexGuard
aGuard( m_aMutex
);
3823 if ( m_pEditImplementation
)
3824 m_pEditImplementation
->SetReadOnly( !bEditable
);
3827 //------------------------------------------------------------------------------
3828 sal_Int16 SAL_CALL
FmXEditCell::getMaxTextLen() throw( RuntimeException
)
3830 ::osl::MutexGuard
aGuard( m_aMutex
);
3832 return m_pEditImplementation
? m_pEditImplementation
->GetMaxTextLen() : 0;
3835 //------------------------------------------------------------------------------
3836 void SAL_CALL
FmXEditCell::setMaxTextLen( sal_Int16 nLen
) throw( RuntimeException
)
3838 ::osl::MutexGuard
aGuard( m_aMutex
);
3840 if ( m_pEditImplementation
)
3841 m_pEditImplementation
->SetMaxTextLen( nLen
);
3844 //------------------------------------------------------------------------------
3845 void SAL_CALL
FmXEditCell::addChangeListener( const Reference
< form::XChangeListener
>& _Listener
) throw (RuntimeException
)
3847 m_aChangeListeners
.addInterface( _Listener
);
3850 //------------------------------------------------------------------------------
3851 void SAL_CALL
FmXEditCell::removeChangeListener( const Reference
< form::XChangeListener
>& _Listener
) throw (RuntimeException
)
3853 m_aChangeListeners
.removeInterface( _Listener
);
3856 //------------------------------------------------------------------------------
3857 void FmXEditCell::onTextChanged()
3859 ::com::sun::star::awt::TextEvent aEvent
;
3860 aEvent
.Source
= *this;
3861 m_aTextListeners
.notifyEach( &awt::XTextListener::textChanged
, aEvent
);
3864 //------------------------------------------------------------------------------
3865 void FmXEditCell::onFocusGained( const awt::FocusEvent
& _rEvent
)
3867 FmXTextCell::onFocusGained( _rEvent
);
3868 m_sValueOnEnter
= getText();
3871 //------------------------------------------------------------------------------
3872 void FmXEditCell::onFocusLost( const awt::FocusEvent
& _rEvent
)
3874 FmXTextCell::onFocusLost( _rEvent
);
3876 if ( getText() != m_sValueOnEnter
)
3878 lang::EventObject
aEvent( *this );
3879 m_aChangeListeners
.notifyEach( &XChangeListener::changed
, aEvent
);
3883 //------------------------------------------------------------------------------
3884 void FmXEditCell::onWindowEvent( const ULONG _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
3886 switch ( _nEventId
)
3888 case VCLEVENT_EDIT_MODIFY
:
3890 if ( m_pEditImplementation
&& m_aTextListeners
.getLength() )
3896 FmXTextCell::onWindowEvent( _nEventId
, _rWindow
, _pEventData
);
3899 /*************************************************************************/
3900 DBG_NAME(FmXCheckBoxCell
);
3901 //------------------------------------------------------------------------------
3902 FmXCheckBoxCell::FmXCheckBoxCell( DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
3903 :FmXDataCell( pColumn
, _rControl
)
3904 ,m_aItemListeners(m_aMutex
)
3905 ,m_aActionListeners( m_aMutex
)
3906 ,m_pBox( & static_cast< CheckBoxControl
& >( _rControl
.GetWindow() ).GetBox() )
3908 DBG_CTOR(FmXCheckBoxCell
,NULL
);
3911 //------------------------------------------------------------------
3912 FmXCheckBoxCell::~FmXCheckBoxCell()
3914 if (!OComponentHelper::rBHelper
.bDisposed
)
3920 DBG_DTOR(FmXCheckBoxCell
,NULL
);
3924 //-----------------------------------------------------------------------------
3925 void FmXCheckBoxCell::disposing()
3927 ::com::sun::star::lang::EventObject
aEvt(*this);
3928 m_aItemListeners
.disposeAndClear(aEvt
);
3929 m_aActionListeners
.disposeAndClear(aEvt
);
3931 static_cast< CheckBoxControl
& >( m_pCellControl
->GetWindow() ).SetClickHdl(Link());
3934 FmXDataCell::disposing();
3937 //------------------------------------------------------------------
3938 Any SAL_CALL
FmXCheckBoxCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
3940 Any aReturn
= FmXDataCell::queryAggregation( _rType
);
3942 if ( !aReturn
.hasValue() )
3943 aReturn
= FmXCheckBoxCell_Base::queryInterface( _rType
);
3948 //-------------------------------------------------------------------------
3949 Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
FmXCheckBoxCell::getTypes( ) throw(RuntimeException
)
3951 return ::comphelper::concatSequences(
3952 FmXDataCell::getTypes(),
3953 FmXCheckBoxCell_Base::getTypes()
3957 //------------------------------------------------------------------------------
3958 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXCheckBoxCell
)
3960 //------------------------------------------------------------------
3961 void SAL_CALL
FmXCheckBoxCell::addItemListener( const Reference
< ::com::sun::star::awt::XItemListener
>& l
) throw( RuntimeException
)
3963 m_aItemListeners
.addInterface( l
);
3966 //------------------------------------------------------------------
3967 void SAL_CALL
FmXCheckBoxCell::removeItemListener( const Reference
< ::com::sun::star::awt::XItemListener
>& l
) throw( RuntimeException
)
3969 m_aItemListeners
.removeInterface( l
);
3972 //------------------------------------------------------------------
3973 void SAL_CALL
FmXCheckBoxCell::setState( short n
) throw( RuntimeException
)
3975 ::osl::MutexGuard
aGuard( m_aMutex
);
3980 m_pBox
->SetState( (TriState
)n
);
3984 //------------------------------------------------------------------
3985 short SAL_CALL
FmXCheckBoxCell::getState() throw( RuntimeException
)
3987 ::osl::MutexGuard
aGuard( m_aMutex
);
3992 return (short)m_pBox
->GetState();
3994 return STATE_DONTKNOW
;
3997 //------------------------------------------------------------------
3998 void SAL_CALL
FmXCheckBoxCell::enableTriState( sal_Bool b
) throw( RuntimeException
)
4000 ::osl::MutexGuard
aGuard( m_aMutex
);
4003 m_pBox
->EnableTriState( b
);
4006 //------------------------------------------------------------------
4007 void SAL_CALL
FmXCheckBoxCell::addActionListener( const Reference
< awt::XActionListener
>& _Listener
) throw (RuntimeException
)
4009 m_aActionListeners
.addInterface( _Listener
);
4012 //------------------------------------------------------------------
4013 void SAL_CALL
FmXCheckBoxCell::removeActionListener( const Reference
< awt::XActionListener
>& _Listener
) throw (RuntimeException
)
4015 m_aActionListeners
.removeInterface( _Listener
);
4018 //------------------------------------------------------------------
4019 void SAL_CALL
FmXCheckBoxCell::setLabel( const ::rtl::OUString
& _Label
) throw (RuntimeException
)
4021 ::vos::OGuard
aGuard( Application::GetSolarMutex() );
4024 DbGridControl
& rGrid( m_pColumn
->GetParent() );
4025 rGrid
.SetColumnTitle( rGrid
.GetColumnId( m_pColumn
->GetFieldPos() ), _Label
);
4029 //------------------------------------------------------------------
4030 void SAL_CALL
FmXCheckBoxCell::setActionCommand( const ::rtl::OUString
& _Command
) throw (RuntimeException
)
4032 m_aActionCommand
= _Command
;
4035 //------------------------------------------------------------------
4036 Window
* FmXCheckBoxCell::getEventWindow() const
4041 //------------------------------------------------------------------
4042 void FmXCheckBoxCell::onWindowEvent( const ULONG _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
4044 switch ( _nEventId
)
4046 case VCLEVENT_CHECKBOX_TOGGLE
:
4048 // check boxes are to be committed immediately (this holds for ordinary check box controls in
4049 // documents, and this must hold for check boxes in grid columns, too
4050 // 91210 - 22.08.2001 - frank.schoenheit@sun.com
4051 m_pCellControl
->Commit();
4053 Reference
< XWindow
> xKeepAlive( this );
4054 if ( m_aItemListeners
.getLength() && m_pBox
)
4056 awt::ItemEvent aEvent
;
4057 aEvent
.Source
= *this;
4058 aEvent
.Highlighted
= sal_False
;
4059 aEvent
.Selected
= m_pBox
->GetState();
4060 m_aItemListeners
.notifyEach( &awt::XItemListener::itemStateChanged
, aEvent
);
4062 if ( m_aActionListeners
.getLength() )
4064 awt::ActionEvent aEvent
;
4065 aEvent
.Source
= *this;
4066 aEvent
.ActionCommand
= m_aActionCommand
;
4067 m_aActionListeners
.notifyEach( &awt::XActionListener::actionPerformed
, aEvent
);
4073 FmXDataCell::onWindowEvent( _nEventId
, _rWindow
, _pEventData
);
4078 /*************************************************************************/
4080 DBG_NAME(FmXListBoxCell
);
4081 //------------------------------------------------------------------------------
4082 FmXListBoxCell::FmXListBoxCell(DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
4083 :FmXTextCell( pColumn
, _rControl
)
4084 ,m_aItemListeners(m_aMutex
)
4085 ,m_aActionListeners(m_aMutex
)
4086 ,m_pBox( &static_cast< ListBox
& >( _rControl
.GetWindow() ) )
4088 DBG_CTOR(FmXListBoxCell
,NULL
);
4090 m_pBox
->SetDoubleClickHdl( LINK( this, FmXListBoxCell
, OnDoubleClick
) );
4093 //------------------------------------------------------------------
4094 FmXListBoxCell::~FmXListBoxCell()
4096 if (!OComponentHelper::rBHelper
.bDisposed
)
4102 DBG_DTOR(FmXListBoxCell
,NULL
);
4106 //-----------------------------------------------------------------------------
4107 void FmXListBoxCell::disposing()
4109 ::com::sun::star::lang::EventObject
aEvt(*this);
4110 m_aItemListeners
.disposeAndClear(aEvt
);
4111 m_aActionListeners
.disposeAndClear(aEvt
);
4113 m_pBox
->SetSelectHdl( Link() );
4114 m_pBox
->SetDoubleClickHdl( Link() );
4117 FmXTextCell::disposing();
4120 //------------------------------------------------------------------
4121 Any SAL_CALL
FmXListBoxCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
4123 Any aReturn
= FmXTextCell::queryAggregation(_rType
);
4125 if ( !aReturn
.hasValue() )
4126 aReturn
= FmXListBoxCell_Base::queryInterface( _rType
);
4131 //-------------------------------------------------------------------------
4132 Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
FmXListBoxCell::getTypes( ) throw(RuntimeException
)
4134 return ::comphelper::concatSequences(
4135 FmXTextCell::getTypes(),
4136 FmXListBoxCell_Base::getTypes()
4140 //------------------------------------------------------------------------------
4141 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXListBoxCell
)
4143 //------------------------------------------------------------------
4144 void SAL_CALL
FmXListBoxCell::addItemListener(const Reference
< ::com::sun::star::awt::XItemListener
>& l
) throw( RuntimeException
)
4146 m_aItemListeners
.addInterface( l
);
4149 //------------------------------------------------------------------
4150 void SAL_CALL
FmXListBoxCell::removeItemListener(const Reference
< ::com::sun::star::awt::XItemListener
>& l
) throw( RuntimeException
)
4152 m_aItemListeners
.removeInterface( l
);
4155 //------------------------------------------------------------------
4156 void SAL_CALL
FmXListBoxCell::addActionListener(const Reference
< ::com::sun::star::awt::XActionListener
>& l
) throw( RuntimeException
)
4158 m_aActionListeners
.addInterface( l
);
4161 //------------------------------------------------------------------
4162 void SAL_CALL
FmXListBoxCell::removeActionListener(const Reference
< ::com::sun::star::awt::XActionListener
>& l
) throw( RuntimeException
)
4164 m_aActionListeners
.removeInterface( l
);
4167 //------------------------------------------------------------------
4168 void SAL_CALL
FmXListBoxCell::addItem(const ::rtl::OUString
& aItem
, sal_Int16 nPos
) throw( RuntimeException
)
4170 ::osl::MutexGuard
aGuard( m_aMutex
);
4172 m_pBox
->InsertEntry( aItem
, nPos
);
4175 //------------------------------------------------------------------
4176 void SAL_CALL
FmXListBoxCell::addItems(const ::comphelper::StringSequence
& aItems
, sal_Int16 nPos
) throw( RuntimeException
)
4178 ::osl::MutexGuard
aGuard( m_aMutex
);
4181 sal_uInt16 nP
= nPos
;
4182 for ( sal_uInt16 n
= 0; n
< aItems
.getLength(); n
++ )
4184 m_pBox
->InsertEntry( aItems
.getConstArray()[n
], nP
);
4185 if ( nPos
!= -1 ) // Nicht wenn 0xFFFF, weil LIST_APPEND
4191 //------------------------------------------------------------------
4192 void SAL_CALL
FmXListBoxCell::removeItems(sal_Int16 nPos
, sal_Int16 nCount
) throw( RuntimeException
)
4194 ::osl::MutexGuard
aGuard( m_aMutex
);
4197 for ( sal_uInt16 n
= nCount
; n
; )
4198 m_pBox
->RemoveEntry( nPos
+ (--n
) );
4202 //------------------------------------------------------------------
4203 sal_Int16 SAL_CALL
FmXListBoxCell::getItemCount() throw( RuntimeException
)
4205 ::osl::MutexGuard
aGuard( m_aMutex
);
4206 return m_pBox
? m_pBox
->GetEntryCount() : 0;
4209 //------------------------------------------------------------------
4210 ::rtl::OUString SAL_CALL
FmXListBoxCell::getItem(sal_Int16 nPos
) throw( RuntimeException
)
4212 ::osl::MutexGuard
aGuard( m_aMutex
);
4215 aItem
= m_pBox
->GetEntry( nPos
);
4218 //------------------------------------------------------------------
4219 ::comphelper::StringSequence SAL_CALL
FmXListBoxCell::getItems() throw( RuntimeException
)
4221 ::osl::MutexGuard
aGuard( m_aMutex
);
4223 ::comphelper::StringSequence aSeq
;
4226 sal_uInt16 nEntries
= m_pBox
->GetEntryCount();
4227 aSeq
= ::comphelper::StringSequence( nEntries
);
4228 for ( sal_uInt16 n
= nEntries
; n
; )
4231 aSeq
.getArray()[n
] = m_pBox
->GetEntry( n
);
4237 //------------------------------------------------------------------
4238 sal_Int16 SAL_CALL
FmXListBoxCell::getSelectedItemPos() throw( RuntimeException
)
4240 ::osl::MutexGuard
aGuard( m_aMutex
);
4244 return m_pBox
->GetSelectEntryPos();
4249 //------------------------------------------------------------------
4250 Sequence
< sal_Int16
> SAL_CALL
FmXListBoxCell::getSelectedItemsPos() throw( RuntimeException
)
4252 ::osl::MutexGuard
aGuard( m_aMutex
);
4253 Sequence
<sal_Int16
> aSeq
;
4258 sal_uInt16 nSelEntries
= m_pBox
->GetSelectEntryCount();
4259 aSeq
= Sequence
<sal_Int16
>( nSelEntries
);
4260 for ( sal_uInt16 n
= 0; n
< nSelEntries
; n
++ )
4261 aSeq
.getArray()[n
] = m_pBox
->GetSelectEntryPos( n
);
4265 //------------------------------------------------------------------
4266 ::rtl::OUString SAL_CALL
FmXListBoxCell::getSelectedItem() throw( RuntimeException
)
4268 ::osl::MutexGuard
aGuard( m_aMutex
);
4274 aItem
= m_pBox
->GetSelectEntry();
4280 //------------------------------------------------------------------
4281 ::comphelper::StringSequence SAL_CALL
FmXListBoxCell::getSelectedItems() throw( RuntimeException
)
4283 ::osl::MutexGuard
aGuard( m_aMutex
);
4285 ::comphelper::StringSequence aSeq
;
4290 sal_uInt16 nSelEntries
= m_pBox
->GetSelectEntryCount();
4291 aSeq
= ::comphelper::StringSequence( nSelEntries
);
4292 for ( sal_uInt16 n
= 0; n
< nSelEntries
; n
++ )
4293 aSeq
.getArray()[n
] = m_pBox
->GetSelectEntry( n
);
4298 //------------------------------------------------------------------
4299 void SAL_CALL
FmXListBoxCell::selectItemPos(sal_Int16 nPos
, sal_Bool bSelect
) throw( RuntimeException
)
4301 ::osl::MutexGuard
aGuard( m_aMutex
);
4304 m_pBox
->SelectEntryPos( nPos
, bSelect
);
4307 //------------------------------------------------------------------
4308 void SAL_CALL
FmXListBoxCell::selectItemsPos(const Sequence
< sal_Int16
>& aPositions
, sal_Bool bSelect
) throw( RuntimeException
)
4310 ::osl::MutexGuard
aGuard( m_aMutex
);
4314 for ( sal_uInt16 n
= (sal_uInt16
)aPositions
.getLength(); n
; )
4315 m_pBox
->SelectEntryPos( (sal_uInt16
) aPositions
.getConstArray()[--n
], bSelect
);
4319 //------------------------------------------------------------------
4320 void SAL_CALL
FmXListBoxCell::selectItem(const ::rtl::OUString
& aItem
, sal_Bool bSelect
) throw( RuntimeException
)
4322 ::osl::MutexGuard
aGuard( m_aMutex
);
4325 m_pBox
->SelectEntry( aItem
, bSelect
);
4328 //------------------------------------------------------------------
4329 sal_Bool SAL_CALL
FmXListBoxCell::isMutipleMode() throw( RuntimeException
)
4331 ::osl::MutexGuard
aGuard( m_aMutex
);
4333 sal_Bool bMulti
= sal_False
;
4335 bMulti
= m_pBox
->IsMultiSelectionEnabled();
4339 //------------------------------------------------------------------
4340 void SAL_CALL
FmXListBoxCell::setMultipleMode(sal_Bool bMulti
) throw( RuntimeException
)
4342 ::osl::MutexGuard
aGuard( m_aMutex
);
4345 m_pBox
->EnableMultiSelection( bMulti
);
4348 //------------------------------------------------------------------
4349 sal_Int16 SAL_CALL
FmXListBoxCell::getDropDownLineCount() throw( RuntimeException
)
4351 ::osl::MutexGuard
aGuard( m_aMutex
);
4353 sal_Int16 nLines
= 0;
4355 nLines
= m_pBox
->GetDropDownLineCount();
4360 //------------------------------------------------------------------
4361 void SAL_CALL
FmXListBoxCell::setDropDownLineCount(sal_Int16 nLines
) throw( RuntimeException
)
4363 ::osl::MutexGuard
aGuard( m_aMutex
);
4366 m_pBox
->SetDropDownLineCount( nLines
);
4369 //------------------------------------------------------------------
4370 void SAL_CALL
FmXListBoxCell::makeVisible(sal_Int16 nEntry
) throw( RuntimeException
)
4372 ::osl::MutexGuard
aGuard( m_aMutex
);
4375 m_pBox
->SetTopEntry( nEntry
);
4378 //------------------------------------------------------------------
4379 void FmXListBoxCell::onWindowEvent( const ULONG _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
4381 if ( ( &_rWindow
== m_pBox
)
4382 && ( _nEventId
== VCLEVENT_LISTBOX_SELECT
)
4385 OnDoubleClick( NULL
);
4387 ::com::sun::star::awt::ItemEvent aEvent
;
4388 aEvent
.Source
= *this;
4389 aEvent
.Highlighted
= sal_False
;
4391 // Bei Mehrfachselektion 0xFFFF, sonst die ID
4392 aEvent
.Selected
= (m_pBox
->GetSelectEntryCount() == 1 )
4393 ? m_pBox
->GetSelectEntryPos() : 0xFFFF;
4395 m_aItemListeners
.notifyEach( &awt::XItemListener::itemStateChanged
, aEvent
);
4399 FmXTextCell::onWindowEvent( _nEventId
, _rWindow
, _pEventData
);
4403 //------------------------------------------------------------------
4404 IMPL_LINK( FmXListBoxCell
, OnDoubleClick
, void*, EMPTYARG
)
4408 ::cppu::OInterfaceIteratorHelper
aIt( m_aActionListeners
);
4410 ::com::sun::star::awt::ActionEvent aEvent
;
4411 aEvent
.Source
= *this;
4412 aEvent
.ActionCommand
= m_pBox
->GetSelectEntry();
4414 while( aIt
.hasMoreElements() )
4415 ((::com::sun::star::awt::XActionListener
*)aIt
.next())->actionPerformed( aEvent
);
4421 /*************************************************************************/
4423 DBG_NAME( FmXComboBoxCell
);
4425 //------------------------------------------------------------------------------
4426 FmXComboBoxCell::FmXComboBoxCell( DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
4427 :FmXTextCell( pColumn
, _rControl
)
4428 ,m_aItemListeners( m_aMutex
)
4429 ,m_aActionListeners( m_aMutex
)
4430 ,m_pComboBox( &static_cast< ComboBox
& >( _rControl
.GetWindow() ) )
4432 DBG_CTOR( FmXComboBoxCell
, NULL
);
4435 //------------------------------------------------------------------------------
4436 FmXComboBoxCell::~FmXComboBoxCell()
4438 if ( !OComponentHelper::rBHelper
.bDisposed
)
4444 DBG_DTOR( FmXComboBoxCell
, NULL
);
4447 //-----------------------------------------------------------------------------
4448 void FmXComboBoxCell::disposing()
4450 ::com::sun::star::lang::EventObject
aEvt(*this);
4451 m_aItemListeners
.disposeAndClear(aEvt
);
4452 m_aActionListeners
.disposeAndClear(aEvt
);
4454 FmXTextCell::disposing();
4457 //------------------------------------------------------------------
4458 Any SAL_CALL
FmXComboBoxCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
4460 Any aReturn
= FmXTextCell::queryAggregation(_rType
);
4462 if ( !aReturn
.hasValue() )
4463 aReturn
= FmXComboBoxCell_Base::queryInterface( _rType
);
4468 //-------------------------------------------------------------------------
4469 Sequence
< Type
> SAL_CALL
FmXComboBoxCell::getTypes( ) throw(RuntimeException
)
4471 return ::comphelper::concatSequences(
4472 FmXTextCell::getTypes(),
4473 FmXComboBoxCell_Base::getTypes()
4477 //------------------------------------------------------------------------------
4478 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXComboBoxCell
)
4480 //------------------------------------------------------------------
4481 void SAL_CALL
FmXComboBoxCell::addItemListener(const Reference
< awt::XItemListener
>& l
) throw( RuntimeException
)
4483 m_aItemListeners
.addInterface( l
);
4486 //------------------------------------------------------------------
4487 void SAL_CALL
FmXComboBoxCell::removeItemListener(const Reference
< awt::XItemListener
>& l
) throw( RuntimeException
)
4489 m_aItemListeners
.removeInterface( l
);
4492 //------------------------------------------------------------------
4493 void SAL_CALL
FmXComboBoxCell::addActionListener(const Reference
< awt::XActionListener
>& l
) throw( RuntimeException
)
4495 m_aActionListeners
.addInterface( l
);
4498 //------------------------------------------------------------------
4499 void SAL_CALL
FmXComboBoxCell::removeActionListener(const Reference
< awt::XActionListener
>& l
) throw( RuntimeException
)
4501 m_aActionListeners
.removeInterface( l
);
4504 //------------------------------------------------------------------
4505 void SAL_CALL
FmXComboBoxCell::addItem( const ::rtl::OUString
& _Item
, sal_Int16 _Pos
) throw( RuntimeException
)
4507 ::osl::MutexGuard
aGuard( m_aMutex
);
4509 m_pComboBox
->InsertEntry( _Item
, _Pos
);
4512 //------------------------------------------------------------------
4513 void SAL_CALL
FmXComboBoxCell::addItems( const Sequence
< ::rtl::OUString
>& _Items
, sal_Int16 _Pos
) throw( RuntimeException
)
4515 ::osl::MutexGuard
aGuard( m_aMutex
);
4518 sal_uInt16 nP
= _Pos
;
4519 for ( sal_uInt16 n
= 0; n
< _Items
.getLength(); n
++ )
4521 m_pComboBox
->InsertEntry( _Items
.getConstArray()[n
], nP
);
4528 //------------------------------------------------------------------
4529 void SAL_CALL
FmXComboBoxCell::removeItems( sal_Int16 _Pos
, sal_Int16 _Count
) throw( RuntimeException
)
4531 ::osl::MutexGuard
aGuard( m_aMutex
);
4534 for ( sal_uInt16 n
= _Count
; n
; )
4535 m_pComboBox
->RemoveEntry( _Pos
+ (--n
) );
4539 //------------------------------------------------------------------
4540 sal_Int16 SAL_CALL
FmXComboBoxCell::getItemCount() throw( RuntimeException
)
4542 ::osl::MutexGuard
aGuard( m_aMutex
);
4543 return m_pComboBox
? m_pComboBox
->GetEntryCount() : 0;
4546 //------------------------------------------------------------------
4547 ::rtl::OUString SAL_CALL
FmXComboBoxCell::getItem( sal_Int16 _Pos
) throw( RuntimeException
)
4549 ::osl::MutexGuard
aGuard( m_aMutex
);
4552 sItem
= m_pComboBox
->GetEntry( _Pos
);
4555 //------------------------------------------------------------------
4556 Sequence
< ::rtl::OUString
> SAL_CALL
FmXComboBoxCell::getItems() throw( RuntimeException
)
4558 ::osl::MutexGuard
aGuard( m_aMutex
);
4560 Sequence
< ::rtl::OUString
> aItems
;
4563 sal_uInt16 nEntries
= m_pComboBox
->GetEntryCount();
4564 aItems
.realloc( nEntries
);
4565 ::rtl::OUString
* pItem
= aItems
.getArray();
4566 for ( sal_uInt16 n
=0; n
<nEntries
; ++n
, ++pItem
)
4567 *pItem
= m_pComboBox
->GetEntry( n
);
4572 //------------------------------------------------------------------
4573 sal_Int16 SAL_CALL
FmXComboBoxCell::getDropDownLineCount() throw( RuntimeException
)
4575 ::osl::MutexGuard
aGuard( m_aMutex
);
4577 sal_Int16 nLines
= 0;
4579 nLines
= m_pComboBox
->GetDropDownLineCount();
4584 //------------------------------------------------------------------
4585 void SAL_CALL
FmXComboBoxCell::setDropDownLineCount(sal_Int16 nLines
) throw( RuntimeException
)
4587 ::osl::MutexGuard
aGuard( m_aMutex
);
4589 m_pComboBox
->SetDropDownLineCount( nLines
);
4592 //------------------------------------------------------------------------------
4593 void FmXComboBoxCell::onWindowEvent( const ULONG _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
4596 switch ( _nEventId
)
4598 case VCLEVENT_COMBOBOX_SELECT
:
4600 awt::ItemEvent aEvent
;
4601 aEvent
.Source
= *this;
4602 aEvent
.Highlighted
= sal_False
;
4604 // Bei Mehrfachselektion 0xFFFF, sonst die ID
4605 aEvent
.Selected
= ( m_pComboBox
->GetSelectEntryCount() == 1 )
4606 ? m_pComboBox
->GetSelectEntryPos()
4608 m_aItemListeners
.notifyEach( &awt::XItemListener::itemStateChanged
, aEvent
);
4613 FmXTextCell::onWindowEvent( _nEventId
, _rWindow
, _pEventData
);
4618 /*************************************************************************/
4619 TYPEINIT1(FmXFilterCell
, FmXGridCell
);
4621 //------------------------------------------------------------------------------
4622 Reference
< XInterface
> FmXFilterCell_CreateInstance(const Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& /*_rxFactory*/)
4624 return *new FmXFilterCell();
4627 DBG_NAME(FmXFilterCell
);
4628 //------------------------------------------------------------------------------
4629 FmXFilterCell::FmXFilterCell(DbGridColumn
* pColumn
, DbCellControl
* pControl
)
4630 :FmXGridCell( pColumn
, pControl
)
4631 ,m_aTextListeners(m_aMutex
)
4633 DBG_CTOR(FmXFilterCell
,NULL
);
4635 DBG_ASSERT( m_pCellControl
->ISA( DbFilterField
), "FmXFilterCell::FmXFilterCell: invalid cell control!" );
4636 static_cast< DbFilterField
* >( m_pCellControl
)->SetCommitHdl( LINK( this, FmXFilterCell
, OnCommit
) );
4639 //------------------------------------------------------------------
4640 FmXFilterCell::~FmXFilterCell()
4642 if (!OComponentHelper::rBHelper
.bDisposed
)
4648 DBG_DTOR(FmXFilterCell
,NULL
);
4652 //------------------------------------------------------------------------------
4653 sal_Int64 SAL_CALL
FmXFilterCell::getSomething( const Sequence
< sal_Int8
>& _rIdentifier
) throw(RuntimeException
)
4655 sal_Int64
nReturn(0);
4657 if ( (_rIdentifier
.getLength() == 16)
4658 && (0 == rtl_compareMemory( getUnoTunnelId().getConstArray(), _rIdentifier
.getConstArray(), 16 ))
4661 nReturn
= reinterpret_cast<sal_Int64
>(this);
4667 //------------------------------------------------------------------------------
4668 const Sequence
<sal_Int8
>& FmXFilterCell::getUnoTunnelId()
4670 static Sequence
< sal_Int8
> * pSeq
= 0;
4673 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
4676 static Sequence
< sal_Int8
> aSeq( 16 );
4677 rtl_createUuid( (sal_uInt8
*)aSeq
.getArray(), 0, sal_True
);
4684 //------------------------------------------------------------------------------
4685 FmXFilterCell
* FmXFilterCell::getImplementation(const Reference
< ::com::sun::star::awt::XControl
>& _rxObject
)
4687 Reference
< ::com::sun::star::lang::XUnoTunnel
> xTunnel(
4688 _rxObject
, UNO_QUERY
);
4690 return reinterpret_cast<FmXFilterCell
*>(xTunnel
->getSomething(getUnoTunnelId()));
4694 //------------------------------------------------------------------------------
4695 void FmXFilterCell::PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
)
4697 static_cast< DbFilterField
* >( m_pCellControl
)->PaintCell( rDev
, rRect
);
4701 //-----------------------------------------------------------------------------
4702 void FmXFilterCell::disposing()
4704 ::com::sun::star::lang::EventObject
aEvt(*this);
4705 m_aTextListeners
.disposeAndClear(aEvt
);
4707 ((DbFilterField
*)m_pCellControl
)->SetCommitHdl(Link());
4709 FmXGridCell::disposing();
4712 //------------------------------------------------------------------
4713 Any SAL_CALL
FmXFilterCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
4715 Any aReturn
= FmXGridCell::queryAggregation(_rType
);
4717 if ( !aReturn
.hasValue() )
4718 aReturn
= FmXFilterCell_Base::queryInterface( _rType
);
4723 //-------------------------------------------------------------------------
4724 Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
FmXFilterCell::getTypes( ) throw(RuntimeException
)
4726 return ::comphelper::concatSequences(
4727 FmXGridCell::getTypes(),
4728 FmXFilterCell_Base::getTypes()
4732 //------------------------------------------------------------------------------
4733 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXFilterCell
)
4735 // ::com::sun::star::awt::XTextComponent
4736 //------------------------------------------------------------------------------
4737 void SAL_CALL
FmXFilterCell::addTextListener(const Reference
< ::com::sun::star::awt::XTextListener
>& l
) throw( RuntimeException
)
4739 m_aTextListeners
.addInterface( l
);
4742 //------------------------------------------------------------------------------
4743 void SAL_CALL
FmXFilterCell::removeTextListener(const Reference
< ::com::sun::star::awt::XTextListener
>& l
) throw( RuntimeException
)
4745 m_aTextListeners
.removeInterface( l
);
4748 //------------------------------------------------------------------------------
4749 void SAL_CALL
FmXFilterCell::setText( const ::rtl::OUString
& aText
) throw( RuntimeException
)
4751 ::osl::MutexGuard
aGuard( m_aMutex
);
4752 ((DbFilterField
*)m_pCellControl
)->SetText(aText
);
4755 //------------------------------------------------------------------------------
4756 void SAL_CALL
FmXFilterCell::insertText( const ::com::sun::star::awt::Selection
& /*rSel*/, const ::rtl::OUString
& /*aText*/ ) throw( RuntimeException
)
4760 //------------------------------------------------------------------------------
4761 ::rtl::OUString SAL_CALL
FmXFilterCell::getText() throw( RuntimeException
)
4763 ::osl::MutexGuard
aGuard( m_aMutex
);
4764 return ((DbFilterField
*)m_pCellControl
)->GetText();
4767 //------------------------------------------------------------------------------
4768 ::rtl::OUString SAL_CALL
FmXFilterCell::getSelectedText( void ) throw( RuntimeException
)
4773 //------------------------------------------------------------------------------
4774 void SAL_CALL
FmXFilterCell::setSelection( const ::com::sun::star::awt::Selection
& /*aSelection*/ ) throw( RuntimeException
)
4778 //------------------------------------------------------------------------------
4779 ::com::sun::star::awt::Selection SAL_CALL
FmXFilterCell::getSelection( void ) throw( RuntimeException
)
4781 return ::com::sun::star::awt::Selection();
4784 //------------------------------------------------------------------------------
4785 sal_Bool SAL_CALL
FmXFilterCell::isEditable( void ) throw( RuntimeException
)
4790 //------------------------------------------------------------------------------
4791 void SAL_CALL
FmXFilterCell::setEditable( sal_Bool
/*bEditable*/ ) throw( RuntimeException
)
4795 //------------------------------------------------------------------------------
4796 sal_Int16 SAL_CALL
FmXFilterCell::getMaxTextLen() throw( RuntimeException
)
4801 //------------------------------------------------------------------------------
4802 void SAL_CALL
FmXFilterCell::setMaxTextLen( sal_Int16
/*nLen*/ ) throw( RuntimeException
)
4806 //------------------------------------------------------------------------------
4807 IMPL_LINK( FmXFilterCell
, OnCommit
, void*, EMPTYARG
)
4809 ::cppu::OInterfaceIteratorHelper
aIt( m_aTextListeners
);
4810 ::com::sun::star::awt::TextEvent aEvt
;
4811 aEvt
.Source
= *this;
4812 while( aIt
.hasMoreElements() )
4813 ((::com::sun::star::awt::XTextListener
*)aIt
.next())->textChanged( aEvt
);