1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/macros.h>
23 #include "svx/fmresids.hrc"
24 #include "svx/fmtools.hxx"
25 #include "gridcell.hxx"
26 #include "gridcols.hxx"
27 #include "sdbdatacolumn.hxx"
29 #include <com/sun/star/awt/LineEndFormat.hpp>
30 #include <com/sun/star/awt/MouseWheelBehavior.hpp>
31 #include <com/sun/star/awt/VisualEffect.hpp>
32 #include <com/sun/star/container/XChild.hpp>
33 #include <com/sun/star/container/XNamed.hpp>
34 #include <com/sun/star/form/FormComponentType.hpp>
35 #include <com/sun/star/form/XBoundComponent.hpp>
36 #include <com/sun/star/script/XEventAttacherManager.hpp>
37 #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
38 #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
39 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
40 #include <com/sun/star/sdbc/ColumnValue.hpp>
41 #include <com/sun/star/sdbc/DataType.hpp>
42 #include <com/sun/star/sdbc/XStatement.hpp>
43 #include <com/sun/star/util/NumberFormat.hpp>
44 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
45 #include <com/sun/star/util/Time.hpp>
46 #include <com/sun/star/util/Date.hpp>
48 #include <comphelper/extract.hxx>
49 #include <comphelper/numbers.hxx>
50 #include <comphelper/property.hxx>
51 #include <comphelper/servicehelper.hxx>
52 #include <comphelper/string.hxx>
53 #include <connectivity/formattedcolumnvalue.hxx>
54 #include <cppuhelper/typeprovider.hxx>
55 #include <i18nlangtag/lang.h>
57 #include <rtl/math.hxx>
58 #include <svtools/calendar.hxx>
59 #include <svtools/fmtfield.hxx>
60 #include <svl/numuno.hxx>
61 #include <svtools/svmedit.hxx>
62 #include <svx/dialmgr.hxx>
63 #include <toolkit/helper/vclunohelper.hxx>
64 #include <tools/diagnose_ex.h>
65 #include <tools/shl.hxx>
66 #include <vcl/longcurr.hxx>
71 using namespace ::connectivity
;
72 using namespace ::connectivity::simple
;
73 using namespace ::svxform
;
74 using namespace ::comphelper
;
75 using namespace ::svt
;
76 using namespace ::com::sun::star
;
77 using namespace ::com::sun::star::uno
;
78 using namespace ::com::sun::star::sdbc
;
79 using namespace ::com::sun::star::sdbcx
;
80 using namespace ::com::sun::star::sdb
;
81 using namespace ::com::sun::star::beans
;
82 using namespace ::com::sun::star::form
;
84 using ::com::sun::star::util::XNumberFormatter
;
85 namespace MouseWheelBehavior
= ::com::sun::star::awt::MouseWheelBehavior
;
87 const char INVALIDTEXT
[] = "###";
88 const char OBJECTTEXT
[] = "<OBJECT>";
90 //==================================================================
92 //==================================================================
95 static LineEnd
getModelLineEndSetting( const Reference
< XPropertySet
>& _rxModel
)
97 LineEnd eFormat
= LINEEND_LF
;
101 sal_Int16 nLineEndFormat
= awt::LineEndFormat::LINE_FEED
;
103 Reference
< XPropertySetInfo
> xPSI
;
105 xPSI
= _rxModel
->getPropertySetInfo();
107 OSL_ENSURE( xPSI
.is(), "getModelLineEndSetting: invalid column model!" );
108 if ( xPSI
.is() && xPSI
->hasPropertyByName( FM_PROP_LINEENDFORMAT
) )
110 OSL_VERIFY( _rxModel
->getPropertyValue( FM_PROP_LINEENDFORMAT
) >>= nLineEndFormat
);
112 switch ( nLineEndFormat
)
114 case awt::LineEndFormat::CARRIAGE_RETURN
: eFormat
= LINEEND_CR
; break;
115 case awt::LineEndFormat::LINE_FEED
: eFormat
= LINEEND_LF
; break;
116 case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED
: eFormat
= LINEEND_CRLF
; break;
118 OSL_FAIL( "getModelLineEndSetting: what's this?" );
122 catch( const Exception
& )
124 OSL_FAIL( "getModelLineEndSetting: caught an exception!" );
130 //==================================================================
132 //==================================================================
133 //------------------------------------------------------------------------------
134 CellControllerRef
DbGridColumn::s_xEmptyController
;
136 //------------------------------------------------------------------------------
137 void DbGridColumn::CreateControl(sal_Int32 _nFieldPos
, const Reference
< ::com::sun::star::beans::XPropertySet
>& xField
, sal_Int32 nTypeId
)
141 m_nTypeId
= (sal_Int16
)nTypeId
;
142 if (xField
!= m_xField
)
146 xField
->getPropertyValue(FM_PROP_FORMATKEY
) >>= m_nFormatKey
;
147 m_nFieldPos
= (sal_Int16
)_nFieldPos
;
148 m_bReadOnly
= ::comphelper::getBOOL(xField
->getPropertyValue(FM_PROP_ISREADONLY
));
149 m_bAutoValue
= ::comphelper::getBOOL(xField
->getPropertyValue(FM_PROP_AUTOINCREMENT
));
150 m_nFieldType
= (sal_Int16
)::comphelper::getINT32(xField
->getPropertyValue(FM_PROP_FIELDTYPE
));
152 switch (m_nFieldType
)
156 case DataType::TIMESTAMP
:
157 m_bDateTime
= sal_True
;
160 case DataType::BOOLEAN
:
161 case DataType::TINYINT
:
162 case DataType::SMALLINT
:
163 case DataType::INTEGER
:
164 case DataType::BIGINT
:
165 case DataType::FLOAT
:
167 case DataType::DOUBLE
:
168 case DataType::NUMERIC
:
169 case DataType::DECIMAL
:
170 m_nAlign
= ::com::sun::star::awt::TextAlign::RIGHT
;
171 m_bNumeric
= sal_True
;
174 m_nAlign
= ::com::sun::star::awt::TextAlign::LEFT
;
179 DbCellControl
* pCellControl
= NULL
;
180 if (m_rParent
.IsFilterMode())
182 pCellControl
= new DbFilterField(m_rParent
.getContext(),*this);
189 case TYPE_CHECKBOX
: pCellControl
= new DbCheckBox(*this); break;
190 case TYPE_COMBOBOX
: pCellControl
= new DbComboBox(*this); break;
191 case TYPE_CURRENCYFIELD
: pCellControl
= new DbCurrencyField(*this); break;
192 case TYPE_DATEFIELD
: pCellControl
= new DbDateField(*this); break;
193 case TYPE_LISTBOX
: pCellControl
= new DbListBox(*this); break;
194 case TYPE_NUMERICFIELD
: pCellControl
= new DbNumericField(*this); break;
195 case TYPE_PATTERNFIELD
: pCellControl
= new DbPatternField( *this, m_rParent
.getContext() ); break;
196 case TYPE_TEXTFIELD
: pCellControl
= new DbTextField(*this); break;
197 case TYPE_TIMEFIELD
: pCellControl
= new DbTimeField(*this); break;
198 case TYPE_FORMATTEDFIELD
: pCellControl
= new DbFormattedField(*this); break;
200 OSL_FAIL("DbGridColumn::CreateControl: Unknown Column");
205 Reference
< XRowSet
> xCur
;
206 if (m_rParent
.getDataSource())
207 xCur
= Reference
< XRowSet
> ((Reference
< XInterface
>)*m_rParent
.getDataSource(), UNO_QUERY
);
208 // TODO : the cursor wrapper should use an XRowSet interface, too
210 pCellControl
->Init( m_rParent
.GetDataWindow(), xCur
);
212 // now create the control wrapper
213 if (m_rParent
.IsFilterMode())
214 m_pCell
= new FmXFilterCell(this, pCellControl
);
219 case TYPE_CHECKBOX
: m_pCell
= new FmXCheckBoxCell( this, *pCellControl
); break;
220 case TYPE_LISTBOX
: m_pCell
= new FmXListBoxCell( this, *pCellControl
); break;
221 case TYPE_COMBOBOX
: m_pCell
= new FmXComboBoxCell( this, *pCellControl
); break;
223 m_pCell
= new FmXEditCell( this, *pCellControl
);
229 impl_toggleScriptManager_nothrow( true );
231 // only if we use have a bound field, we use a a controller for displaying the
232 // window in the grid
234 m_xController
= pCellControl
->CreateController();
237 //------------------------------------------------------------------------------
238 void DbGridColumn::impl_toggleScriptManager_nothrow( bool _bAttach
)
242 Reference
< container::XChild
> xChild( m_xModel
, UNO_QUERY_THROW
);
243 Reference
< script::XEventAttacherManager
> xManager( xChild
->getParent(), UNO_QUERY_THROW
);
244 Reference
< container::XIndexAccess
> xContainer( xChild
->getParent(), UNO_QUERY_THROW
);
246 sal_Int32
nIndexInParent( getElementPos( xContainer
, m_xModel
) );
248 Reference
< XInterface
> xCellInterface( *m_pCell
, UNO_QUERY
);
250 xManager
->attach( nIndexInParent
, xCellInterface
, makeAny( xCellInterface
) );
252 xManager
->detach( nIndexInParent
, xCellInterface
);
254 catch( const Exception
& )
256 DBG_UNHANDLED_EXCEPTION();
260 //------------------------------------------------------------------------------
261 void DbGridColumn::UpdateFromField(const DbGridRow
* pRow
, const Reference
< XNumberFormatter
>& xFormatter
)
263 if (m_pCell
&& m_pCell
->ISA(FmXFilterCell
))
264 PTR_CAST(FmXFilterCell
, m_pCell
)->Update();
265 else if (pRow
&& pRow
->IsValid() && m_nFieldPos
>= 0 && m_pCell
&& pRow
->HasField(m_nFieldPos
))
267 PTR_CAST(FmXDataCell
, m_pCell
)->UpdateFromField( pRow
->GetField( m_nFieldPos
).getColumn(), xFormatter
);
271 //------------------------------------------------------------------------------
272 sal_Bool
DbGridColumn::Commit()
274 sal_Bool bResult
= sal_True
;
275 if (!m_bInSave
&& m_pCell
)
277 m_bInSave
= sal_True
;
278 bResult
= m_pCell
->Commit();
280 // store the data into the model
281 FmXDataCell
* pDataCell
= PTR_CAST(FmXDataCell
, m_pCell
);
282 if (bResult
&& pDataCell
)
284 Reference
< ::com::sun::star::form::XBoundComponent
> xComp(m_xModel
, UNO_QUERY
);
286 bResult
= xComp
->commit();
288 m_bInSave
= sal_False
;
293 //------------------------------------------------------------------------------
294 DbGridColumn::~DbGridColumn()
299 //------------------------------------------------------------------------------
300 void DbGridColumn::setModel(::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySet
> _xModel
)
303 impl_toggleScriptManager_nothrow( false );
308 impl_toggleScriptManager_nothrow( true );
311 //------------------------------------------------------------------------------
312 void DbGridColumn::Clear()
316 impl_toggleScriptManager_nothrow( false );
323 m_xController
= NULL
;
328 m_bReadOnly
= sal_True
;
329 m_bAutoValue
= sal_False
;
330 m_nFieldType
= DataType::OTHER
;
333 //------------------------------------------------------------------------------
334 sal_Int16
DbGridColumn::SetAlignment(sal_Int16 _nAlign
)
341 m_xField
->getPropertyValue(FM_PROP_FIELDTYPE
) >>= nType
;
345 case DataType::NUMERIC
:
346 case DataType::DECIMAL
:
347 case DataType::DOUBLE
:
349 case DataType::BIGINT
:
350 case DataType::INTEGER
:
351 case DataType::SMALLINT
:
352 case DataType::TINYINT
:
355 case DataType::TIMESTAMP
:
356 _nAlign
= ::com::sun::star::awt::TextAlign::RIGHT
;
359 case DataType::BOOLEAN
:
360 _nAlign
= ::com::sun::star::awt::TextAlign::CENTER
;
363 _nAlign
= ::com::sun::star::awt::TextAlign::LEFT
;
368 _nAlign
= ::com::sun::star::awt::TextAlign::LEFT
;
372 if (m_pCell
&& m_pCell
->isAlignedController())
373 m_pCell
->AlignControl(m_nAlign
);
378 //------------------------------------------------------------------------------
379 sal_Int16
DbGridColumn::SetAlignmentFromModel(sal_Int16 nStandardAlign
)
381 Any
aAlign( m_xModel
->getPropertyValue(FM_PROP_ALIGN
));
382 if (aAlign
.hasValue())
384 sal_Int16 nTest
= sal_Int16();
385 if (aAlign
>>= nTest
)
386 nStandardAlign
= nTest
;
388 return SetAlignment(nStandardAlign
);
391 //------------------------------------------------------------------------------
392 void DbGridColumn::setLock(sal_Bool _bLock
)
394 if (m_bLocked
== _bLock
)
398 // is the column we represent active ?
400 return; // no, it isn't (or at least it shouldn't be ...)
402 if (m_rParent
.GetCurColumnId() == m_nId
)
404 m_rParent
.DeactivateCell();
405 m_rParent
.ActivateCell(m_rParent
.GetCurRow(), m_rParent
.GetCurColumnId());
409 //------------------------------------------------------------------------------
410 OUString
DbGridColumn::GetCellText(const DbGridRow
* pRow
, const Reference
< XNumberFormatter
>& xFormatter
) const
413 if (m_pCell
&& m_pCell
->ISA(FmXFilterCell
))
416 if (!pRow
|| !pRow
->IsValid())
417 aText
= OUString(INVALIDTEXT
);
418 else if (pRow
->HasField(m_nFieldPos
))
420 aText
= GetCellText( pRow
->GetField( m_nFieldPos
).getColumn(), xFormatter
);
425 //------------------------------------------------------------------------------
426 OUString
DbGridColumn::GetCellText(const Reference
< ::com::sun::star::sdb::XColumn
>& xField
, const Reference
< XNumberFormatter
>& xFormatter
) const
431 FmXTextCell
* pTextCell
= PTR_CAST(FmXTextCell
, m_pCell
);
433 aText
= pTextCell
->GetText(xField
, xFormatter
);
435 aText
= OUString(OBJECTTEXT
);
440 //------------------------------------------------------------------------------
441 Reference
< ::com::sun::star::sdb::XColumn
> DbGridColumn::GetCurrentFieldValue() const
443 Reference
< ::com::sun::star::sdb::XColumn
> xField
;
444 const DbGridRowRef xRow
= m_rParent
.GetCurrentRow();
445 if (xRow
.Is() && xRow
->HasField(m_nFieldPos
))
447 xField
= xRow
->GetField(m_nFieldPos
).getColumn();
452 //------------------------------------------------------------------------------
453 void DbGridColumn::Paint(OutputDevice
& rDev
,
454 const Rectangle
& rRect
,
455 const DbGridRow
* pRow
,
456 const Reference
< XNumberFormatter
>& xFormatter
)
458 bool bEnabled
= ( rDev
.GetOutDevType() != OUTDEV_WINDOW
)
459 || ( static_cast< Window
& >( rDev
).IsEnabled() );
461 FmXDataCell
* pDataCell
= PTR_CAST(FmXDataCell
, m_pCell
);
464 if (!pRow
|| !pRow
->IsValid())
466 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_CENTER
;
468 nStyle
|= TEXT_DRAW_DISABLE
;
470 rDev
.DrawText(rRect
, OUString(INVALIDTEXT
), nStyle
);
472 else if (m_bAutoValue
&& pRow
->IsNew())
474 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_VCENTER
;
476 nStyle
|= TEXT_DRAW_DISABLE
;
478 switch (GetAlignment())
480 case ::com::sun::star::awt::TextAlign::RIGHT
:
481 nStyle
|= TEXT_DRAW_RIGHT
;
483 case ::com::sun::star::awt::TextAlign::CENTER
:
484 nStyle
|= TEXT_DRAW_CENTER
;
487 nStyle
|= TEXT_DRAW_LEFT
;
490 rDev
.DrawText(rRect
, SVX_RESSTR(RID_STR_AUTOFIELD
), nStyle
);
492 else if (pRow
->HasField(m_nFieldPos
))
494 pDataCell
->PaintFieldToCell(rDev
, rRect
, pRow
->GetField( m_nFieldPos
).getColumn(), xFormatter
);
499 if (!pRow
|| !pRow
->IsValid())
501 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_CENTER
;
503 nStyle
|= TEXT_DRAW_DISABLE
;
505 rDev
.DrawText(rRect
, OUString(INVALIDTEXT
), nStyle
);
507 else if (pRow
->HasField(m_nFieldPos
) && m_bObject
)
509 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_CENTER
;
511 nStyle
|= TEXT_DRAW_DISABLE
;
512 rDev
.DrawText(rRect
, OUString(OBJECTTEXT
), nStyle
);
515 else if ( m_pCell
->ISA( FmXFilterCell
) )
516 static_cast< FmXFilterCell
* >( m_pCell
)->PaintCell( rDev
, rRect
);
519 //------------------------------------------------------------------------------
520 void DbGridColumn::ImplInitWindow( Window
& rParent
, const InitWindowFacet _eInitWhat
)
523 m_pCell
->ImplInitWindow( rParent
, _eInitWhat
);
526 //==============================================================================
528 //==============================================================================
529 TYPEINIT0( DbCellControl
)
530 TYPEINIT1( DbLimitedLengthField
, DbCellControl
)
531 TYPEINIT1( DbTextField
, DbLimitedLengthField
)
532 TYPEINIT1( DbFormattedField
, DbLimitedLengthField
)
533 TYPEINIT1( DbCheckBox
, DbCellControl
)
534 TYPEINIT1( DbComboBox
, DbCellControl
)
535 TYPEINIT1( DbListBox
, DbCellControl
)
536 TYPEINIT1( DbPatternField
, DbCellControl
)
537 TYPEINIT1( DbSpinField
, DbCellControl
)
538 TYPEINIT1( DbDateField
, DbSpinField
)
539 TYPEINIT1( DbTimeField
, DbSpinField
)
540 TYPEINIT1( DbCurrencyField
, DbSpinField
)
541 TYPEINIT1( DbNumericField
, DbSpinField
)
542 TYPEINIT1( DbFilterField
, DbCellControl
)
544 //------------------------------------------------------------------------------
545 DbCellControl::DbCellControl( DbGridColumn
& _rColumn
, sal_Bool
/*_bText*/ )
546 :OPropertyChangeListener(m_aMutex
)
547 ,m_pFieldChangeBroadcaster(NULL
)
548 ,m_bTransparent( sal_False
)
549 ,m_bAlignedController( sal_True
)
550 ,m_bAccessingValueProperty( sal_False
)
551 ,m_rColumn( _rColumn
)
555 Reference
< XPropertySet
> xColModelProps( _rColumn
.getModel(), UNO_QUERY
);
556 if ( xColModelProps
.is() )
558 // if our model's format key changes we want to propagate the new value to our windows
559 m_pModelChangeBroadcaster
= new ::comphelper::OPropertyChangeMultiplexer(this, Reference
< ::com::sun::star::beans::XPropertySet
> (_rColumn
.getModel(), UNO_QUERY
));
560 m_pModelChangeBroadcaster
->acquire();
562 // be listener for some common properties
563 implDoPropertyListening( FM_PROP_READONLY
, sal_False
);
564 implDoPropertyListening( FM_PROP_ENABLED
, sal_False
);
566 // add as listener for all know "value" properties
567 implDoPropertyListening( FM_PROP_VALUE
, sal_False
);
568 implDoPropertyListening( FM_PROP_STATE
, sal_False
);
569 implDoPropertyListening( FM_PROP_TEXT
, sal_False
);
570 implDoPropertyListening( FM_PROP_EFFECTIVE_VALUE
, sal_False
);
572 // be listener at the bound field as well
575 Reference
< XPropertySetInfo
> xPSI( xColModelProps
->getPropertySetInfo(), UNO_SET_THROW
);
576 if ( xPSI
->hasPropertyByName( FM_PROP_BOUNDFIELD
) )
578 Reference
< XPropertySet
> xField
;
579 xColModelProps
->getPropertyValue( FM_PROP_BOUNDFIELD
) >>= xField
;
582 m_pFieldChangeBroadcaster
= new ::comphelper::OPropertyChangeMultiplexer(this, xField
);
583 m_pFieldChangeBroadcaster
->acquire();
584 m_pFieldChangeBroadcaster
->addProperty( FM_PROP_ISREADONLY
);
588 catch( const Exception
& )
590 OSL_FAIL( "DbCellControl::doPropertyListening: caught an exception!" );
595 //------------------------------------------------------------------------------
596 void DbCellControl::implDoPropertyListening(const OUString
& _rPropertyName
, sal_Bool _bWarnIfNotExistent
)
600 Reference
< XPropertySet
> xColModelProps( m_rColumn
.getModel(), UNO_QUERY
);
601 Reference
< XPropertySetInfo
> xPSI
;
602 if ( xColModelProps
.is() )
603 xPSI
= xColModelProps
->getPropertySetInfo();
605 DBG_ASSERT( !_bWarnIfNotExistent
|| ( xPSI
.is() && xPSI
->hasPropertyByName( _rPropertyName
) ),
606 "DbCellControl::doPropertyListening: no property set info or non-existent property!" );
607 (void)_bWarnIfNotExistent
;
609 if ( xPSI
.is() && xPSI
->hasPropertyByName( _rPropertyName
) )
610 m_pModelChangeBroadcaster
->addProperty( _rPropertyName
);
612 catch( const Exception
& )
614 OSL_FAIL( "DbCellControl::doPropertyListening: caught an exception!" );
618 //------------------------------------------------------------------------------
619 void DbCellControl::doPropertyListening(const OUString
& _rPropertyName
)
621 implDoPropertyListening( _rPropertyName
);
623 //------------------------------------------------------------------------------
624 static void lcl_clearBroadCaster(::comphelper::OPropertyChangeMultiplexer
*& _pBroadcaster
)
628 _pBroadcaster
->dispose();
629 _pBroadcaster
->release();
630 _pBroadcaster
= NULL
;
631 // no delete, this is done implicitly
634 //------------------------------------------------------------------------------
635 DbCellControl::~DbCellControl()
637 lcl_clearBroadCaster(m_pModelChangeBroadcaster
);
638 lcl_clearBroadCaster(m_pFieldChangeBroadcaster
);
644 //------------------------------------------------------------------------------
645 void DbCellControl::implValuePropertyChanged( )
647 OSL_ENSURE( !isValuePropertyLocked(),
648 "DbCellControl::implValuePropertyChanged: not to be called with the value property locked!" );
652 if ( m_rColumn
.getModel().is() )
653 updateFromModel( m_rColumn
.getModel() );
657 //------------------------------------------------------------------------------
658 void DbCellControl::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& /*_rxModel*/ )
660 // nothing to to here
663 //------------------------------------------------------------------------------
664 void DbCellControl::_propertyChanged(const PropertyChangeEvent
& _rEvent
) throw(RuntimeException
)
666 SolarMutexGuard aGuard
;
668 Reference
< XPropertySet
> xSourceProps( _rEvent
.Source
, UNO_QUERY
);
670 if ( _rEvent
.PropertyName
.equals( FM_PROP_VALUE
)
671 || _rEvent
.PropertyName
.equals( FM_PROP_STATE
)
672 || _rEvent
.PropertyName
.equals( FM_PROP_TEXT
)
673 || _rEvent
.PropertyName
.equals( FM_PROP_EFFECTIVE_VALUE
)
675 { // it was one of the known "value" properties
676 if ( !isValuePropertyLocked() )
678 implValuePropertyChanged( );
681 else if ( _rEvent
.PropertyName
.equals( FM_PROP_READONLY
) )
683 implAdjustReadOnly( xSourceProps
, true);
685 else if ( _rEvent
.PropertyName
.equals( FM_PROP_ISREADONLY
) )
687 sal_Bool bReadOnly
= sal_True
;
688 _rEvent
.NewValue
>>= bReadOnly
;
689 m_rColumn
.SetReadOnly(bReadOnly
);
690 implAdjustReadOnly( xSourceProps
, false);
692 else if ( _rEvent
.PropertyName
.equals( FM_PROP_ENABLED
) )
694 implAdjustEnabled( xSourceProps
);
697 implAdjustGenericFieldSetting( xSourceProps
);
700 //------------------------------------------------------------------------------
701 sal_Bool
DbCellControl::Commit()
703 // lock the listening for value property changes
705 // commit the content of the control into the model's value property
706 sal_Bool bReturn
= sal_False
;
709 bReturn
= commitControl();
711 catch( const Exception
& )
713 DBG_UNHANDLED_EXCEPTION();
715 // unlock the listening for value property changes
716 unlockValueProperty();
721 //------------------------------------------------------------------------------
722 void DbCellControl::ImplInitWindow( Window
& rParent
, const InitWindowFacet _eInitWhat
)
724 Window
* pWindows
[] = { m_pPainter
, m_pWindow
};
726 if ( ( _eInitWhat
& InitWritingMode
) != 0 )
728 for ( size_t i
=0; i
< sizeof( pWindows
) / sizeof( pWindows
[0] ); ++i
)
731 pWindows
[i
]->EnableRTL( rParent
.IsRTLEnabled() );
735 if ( ( _eInitWhat
& InitFont
) != 0 )
737 for (size_t i
=0; i
< sizeof(pWindows
)/sizeof(pWindows
[0]); ++i
)
742 pWindows
[i
]->SetZoom( rParent
.GetZoom() );
744 const StyleSettings
& rStyleSettings
= pWindows
[i
]->GetSettings().GetStyleSettings();
745 Font aFont
= rStyleSettings
.GetFieldFont();
746 aFont
.SetTransparent( isTransparent() );
748 if ( rParent
.IsControlFont() )
750 pWindows
[i
]->SetControlFont( rParent
.GetControlFont() );
751 aFont
.Merge( rParent
.GetControlFont() );
754 pWindows
[i
]->SetControlFont();
756 pWindows
[i
]->SetZoomedPointFont( aFont
);
760 if ( ( ( _eInitWhat
& InitFont
) != 0 )
761 || ( ( _eInitWhat
& InitForeground
) != 0 )
764 Color
aTextColor( rParent
.IsControlForeground() ? rParent
.GetControlForeground() : rParent
.GetTextColor() );
766 sal_Bool bTextLineColor
= rParent
.IsTextLineColor();
767 Color
aTextLineColor( rParent
.GetTextLineColor() );
769 for (size_t i
=0; i
< sizeof(pWindows
)/sizeof(pWindows
[0]); ++i
)
773 pWindows
[i
]->SetTextColor(aTextColor
);
774 if (rParent
.IsControlForeground())
775 pWindows
[i
]->SetControlForeground(aTextColor
);
778 pWindows
[i
]->SetTextLineColor();
780 pWindows
[i
]->SetTextLineColor(aTextLineColor
);
785 if ( ( _eInitWhat
& InitBackground
) != 0 )
787 if (rParent
.IsControlBackground())
789 Color
aColor( rParent
.GetControlBackground());
790 for (size_t i
=0; i
< sizeof(pWindows
)/sizeof(pWindows
[0]); ++i
)
794 if ( isTransparent() )
795 pWindows
[i
]->SetBackground();
798 pWindows
[i
]->SetBackground(aColor
);
799 pWindows
[i
]->SetControlBackground(aColor
);
801 pWindows
[i
]->SetFillColor(aColor
);
809 if ( isTransparent() )
810 m_pPainter
->SetBackground();
812 m_pPainter
->SetBackground(rParent
.GetBackground());
813 m_pPainter
->SetFillColor(rParent
.GetFillColor());
818 if ( isTransparent() )
819 m_pWindow
->SetBackground(rParent
.GetBackground());
821 m_pWindow
->SetFillColor(rParent
.GetFillColor());
827 //------------------------------------------------------------------------------
828 void DbCellControl::implAdjustReadOnly( const Reference
< XPropertySet
>& _rxModel
,bool i_bReadOnly
)
830 DBG_ASSERT( m_pWindow
, "DbCellControl::implAdjustReadOnly: not to be called without window!" );
831 DBG_ASSERT( _rxModel
.is(), "DbCellControl::implAdjustReadOnly: invalid model!" );
832 if ( m_pWindow
&& _rxModel
.is() )
834 Edit
* pEditWindow
= dynamic_cast< Edit
* >( m_pWindow
);
837 sal_Bool bReadOnly
= m_rColumn
.IsReadOnly();
840 _rxModel
->getPropertyValue( i_bReadOnly
? OUString(FM_PROP_READONLY
) : OUString(FM_PROP_ISREADONLY
)) >>= bReadOnly
;
842 static_cast< Edit
* >( m_pWindow
)->SetReadOnly( bReadOnly
);
847 //------------------------------------------------------------------------------
848 void DbCellControl::implAdjustEnabled( const Reference
< XPropertySet
>& _rxModel
)
850 DBG_ASSERT( m_pWindow
, "DbCellControl::implAdjustEnabled: not to be called without window!" );
851 DBG_ASSERT( _rxModel
.is(), "DbCellControl::implAdjustEnabled: invalid model!" );
852 if ( m_pWindow
&& _rxModel
.is() )
854 sal_Bool bEnable
= sal_True
;
855 _rxModel
->getPropertyValue( FM_PROP_ENABLED
) >>= bEnable
;
856 m_pWindow
->Enable( bEnable
);
860 //------------------------------------------------------------------------------
861 void DbCellControl::Init( Window
& rParent
, const Reference
< XRowSet
>& _rxCursor
)
863 ImplInitWindow( rParent
, InitAll
);
868 if ( isAlignedController() )
869 AlignControl( m_rColumn
.GetAlignment() );
873 // some other common properties
874 Reference
< XPropertySet
> xModel( m_rColumn
.getModel(), UNO_SET_THROW
);
875 Reference
< XPropertySetInfo
> xModelPSI( xModel
->getPropertySetInfo(), UNO_SET_THROW
);
877 if ( xModelPSI
->hasPropertyByName( FM_PROP_READONLY
) )
879 implAdjustReadOnly( xModel
,true );
882 if ( xModelPSI
->hasPropertyByName( FM_PROP_ENABLED
) )
884 implAdjustEnabled( xModel
);
887 if ( xModelPSI
->hasPropertyByName( FM_PROP_MOUSE_WHEEL_BEHAVIOR
) )
889 sal_Int16 nWheelBehavior
= MouseWheelBehavior::SCROLL_FOCUS_ONLY
;
890 OSL_VERIFY( xModel
->getPropertyValue( FM_PROP_MOUSE_WHEEL_BEHAVIOR
) >>= nWheelBehavior
);
891 sal_uInt16 nVclSetting
= MOUSE_WHEEL_FOCUS_ONLY
;
892 switch ( nWheelBehavior
)
894 case MouseWheelBehavior::SCROLL_DISABLED
: nVclSetting
= MOUSE_WHEEL_DISABLE
; break;
895 case MouseWheelBehavior::SCROLL_FOCUS_ONLY
: nVclSetting
= MOUSE_WHEEL_FOCUS_ONLY
; break;
896 case MouseWheelBehavior::SCROLL_ALWAYS
: nVclSetting
= MOUSE_WHEEL_ALWAYS
; break;
898 OSL_FAIL( "DbCellControl::Init: invalid MouseWheelBehavior!" );
902 AllSettings aSettings
= m_pWindow
->GetSettings();
903 MouseSettings aMouseSettings
= aSettings
.GetMouseSettings();
904 aMouseSettings
.SetWheelBehavior( nVclSetting
);
905 aSettings
.SetMouseSettings( aMouseSettings
);
906 m_pWindow
->SetSettings( aSettings
, sal_True
);
909 catch( const Exception
& )
911 DBG_UNHANDLED_EXCEPTION();
914 m_xCursor
= _rxCursor
;
917 //------------------------------------------------------------------------------
918 void DbCellControl::SetTextLineColor()
921 m_pWindow
->SetTextLineColor();
923 m_pPainter
->SetTextLineColor();
926 //------------------------------------------------------------------------------
927 void DbCellControl::SetTextLineColor(const Color
& _rColor
)
930 m_pWindow
->SetTextLineColor(_rColor
);
932 m_pPainter
->SetTextLineColor(_rColor
);
937 static void lcl_implAlign( Window
* _pWindow
, WinBits _nAlignmentBit
)
939 WinBits nStyle
= _pWindow
->GetStyle();
940 nStyle
&= ~(WB_LEFT
| WB_RIGHT
| WB_CENTER
);
941 _pWindow
->SetStyle( nStyle
| _nAlignmentBit
);
945 //------------------------------------------------------------------------------
946 void DbCellControl::AlignControl(sal_Int16 nAlignment
)
948 WinBits nAlignmentBit
= 0;
951 case ::com::sun::star::awt::TextAlign::RIGHT
:
952 nAlignmentBit
= WB_RIGHT
;
954 case ::com::sun::star::awt::TextAlign::CENTER
:
955 nAlignmentBit
= WB_CENTER
;
958 nAlignmentBit
= WB_LEFT
;
961 lcl_implAlign( m_pWindow
, nAlignmentBit
);
963 lcl_implAlign( m_pPainter
, nAlignmentBit
);
966 //------------------------------------------------------------------------------
967 void DbCellControl::PaintCell( OutputDevice
& _rDev
, const Rectangle
& _rRect
)
969 if ( m_pPainter
->GetParent() == &_rDev
)
971 m_pPainter
->SetPaintTransparent( sal_True
);
972 m_pPainter
->SetBackground( );
973 m_pPainter
->SetControlBackground( _rDev
.GetFillColor() );
974 m_pPainter
->SetControlForeground( _rDev
.GetTextColor() );
975 m_pPainter
->SetTextColor( _rDev
.GetTextColor() );
976 m_pPainter
->SetTextFillColor( _rDev
.GetTextColor() );
978 Font
aFont( _rDev
.GetFont() );
979 aFont
.SetTransparent( sal_True
);
980 m_pPainter
->SetFont( aFont
);
982 m_pPainter
->SetPosSizePixel( _rRect
.TopLeft(), _rRect
.GetSize() );
984 m_pPainter
->Update();
985 m_pPainter
->SetParentUpdateMode( sal_False
);
987 m_pPainter
->SetParentUpdateMode( sal_True
);
990 m_pPainter
->Draw( &_rDev
, _rRect
.TopLeft(), _rRect
.GetSize(), 0 );
993 //------------------------------------------------------------------------------
994 void DbCellControl::PaintFieldToCell( OutputDevice
& _rDev
, const Rectangle
& _rRect
, const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
996 m_pPainter
->SetText( GetFormatText( _rxField
, _rxFormatter
) );
997 PaintCell( _rDev
, _rRect
);
1000 //------------------------------------------------------------------------------
1001 double DbCellControl::GetValue(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
) const
1004 if (m_rColumn
.IsNumeric())
1008 fValue
= _rxField
->getDouble();
1010 catch(const Exception
&) { }
1014 sal_Bool bSuccess
= sal_False
;
1017 fValue
= _rxField
->getDouble();
1018 bSuccess
= sal_True
;
1020 catch(const Exception
&) { }
1025 fValue
= xFormatter
->convertStringToNumber(m_rColumn
.GetKey(), _rxField
->getString());
1027 catch(const Exception
&) { }
1033 //------------------------------------------------------------------------------
1034 void DbCellControl::invalidatedController()
1036 m_rColumn
.GetParent().refreshController(m_rColumn
.GetId(), DbGridControl::GrantControlAccess());
1039 /*************************************************************************/
1041 /*************************************************************************/
1043 //==============================================================================
1044 //= DbLimitedLengthField
1045 //==============================================================================
1046 //------------------------------------------------------------------------------
1047 DbLimitedLengthField::DbLimitedLengthField( DbGridColumn
& _rColumn
)
1048 :DbCellControl( _rColumn
)
1050 doPropertyListening( FM_PROP_MAXTEXTLEN
);
1053 //------------------------------------------------------------------------------
1054 void DbLimitedLengthField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
1056 DBG_ASSERT( m_pWindow
, "DbLimitedLengthField::implAdjustGenericFieldSetting: not to be called without window!" );
1057 DBG_ASSERT( _rxModel
.is(), "DbLimitedLengthField::implAdjustGenericFieldSetting: invalid model!" );
1058 if ( m_pWindow
&& _rxModel
.is() )
1060 sal_Int16 nMaxLen
= 0;
1061 _rxModel
->getPropertyValue( FM_PROP_MAXTEXTLEN
) >>= nMaxLen
;
1062 implSetMaxTextLen( nMaxLen
);
1066 //------------------------------------------------------------------------------
1067 void DbLimitedLengthField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen
)
1069 dynamic_cast< Edit
* >( m_pWindow
)->SetMaxTextLen( _nMaxLen
);
1071 dynamic_cast< Edit
* >( m_pPainter
)->SetMaxTextLen( _nMaxLen
);
1074 //==============================================================================
1076 //==============================================================================
1077 //------------------------------------------------------------------------------
1078 DbTextField::DbTextField(DbGridColumn
& _rColumn
)
1079 :DbLimitedLengthField(_rColumn
)
1081 ,m_pPainterImplementation( NULL
)
1082 ,m_nKeyType(::com::sun::star::util::NumberFormat::TEXT
)
1083 ,m_bIsSimpleEdit( sal_True
)
1087 //------------------------------------------------------------------------------
1088 DbTextField::~DbTextField( )
1090 DELETEZ( m_pPainterImplementation
);
1094 //------------------------------------------------------------------------------
1095 void DbTextField::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
1097 sal_Int16 nAlignment
= m_rColumn
.SetAlignmentFromModel(-1);
1099 Reference
< XPropertySet
> xModel( m_rColumn
.getModel() );
1101 WinBits nStyle
= WB_LEFT
;
1104 case awt::TextAlign::RIGHT
:
1108 case awt::TextAlign::CENTER
:
1113 // is this a multi-line field?
1114 sal_Bool bIsMultiLine
= sal_False
;
1119 OSL_VERIFY( xModel
->getPropertyValue( FM_PROP_MULTILINE
) >>= bIsMultiLine
);
1122 catch( const Exception
& )
1124 OSL_FAIL( "DbTextField::Init: caught an exception while determining the multi-line capabilities!" );
1127 m_bIsSimpleEdit
= !bIsMultiLine
;
1130 m_pWindow
= new MultiLineTextCell( &rParent
, nStyle
);
1131 m_pEdit
= new MultiLineEditImplementation( *static_cast< MultiLineTextCell
* >( m_pWindow
) );
1133 m_pPainter
= new MultiLineTextCell( &rParent
, nStyle
);
1134 m_pPainterImplementation
= new MultiLineEditImplementation( *static_cast< MultiLineTextCell
* >( m_pPainter
) );
1138 m_pWindow
= new Edit( &rParent
, nStyle
);
1139 m_pEdit
= new EditImplementation( *static_cast< Edit
* >( m_pWindow
) );
1141 m_pPainter
= new Edit( &rParent
, nStyle
);
1142 m_pPainterImplementation
= new EditImplementation( *static_cast< Edit
* >( m_pPainter
) );
1145 if ( WB_LEFT
== nStyle
)
1147 // this is so that when getting the focus, the selection is oriented left-to-right
1148 AllSettings aSettings
= m_pWindow
->GetSettings();
1149 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
1150 aStyleSettings
.SetSelectionOptions(
1151 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
1152 aSettings
.SetStyleSettings(aStyleSettings
);
1153 m_pWindow
->SetSettings(aSettings
);
1156 implAdjustGenericFieldSetting( xModel
);
1158 if (m_rColumn
.GetParent().getNumberFormatter().is() && m_rColumn
.GetKey())
1159 m_nKeyType
= comphelper::getNumberFormatType(m_rColumn
.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn
.GetKey());
1161 DbLimitedLengthField::Init( rParent
, xCursor
);
1164 //------------------------------------------------------------------------------
1165 CellControllerRef
DbTextField::CreateController() const
1167 return new EditCellController( m_pEdit
);
1170 //------------------------------------------------------------------------------
1171 void DbTextField::PaintFieldToCell( OutputDevice
& _rDev
, const Rectangle
& _rRect
, const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
1173 if ( m_pPainterImplementation
)
1174 m_pPainterImplementation
->SetText( GetFormatText( _rxField
, _rxFormatter
, NULL
) );
1176 DbLimitedLengthField::PaintFieldToCell( _rDev
, _rRect
, _rxField
, _rxFormatter
);
1179 //------------------------------------------------------------------------------
1180 OUString
DbTextField::GetFormatText(const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
, Color
** /*ppColor*/)
1183 if ( _rxField
.is() )
1186 aString
= getFormattedValue( _rxField
, xFormatter
, m_rColumn
.GetParent().getNullDate(), m_rColumn
.GetKey(), m_nKeyType
);
1188 catch( const Exception
& )
1190 DBG_UNHANDLED_EXCEPTION();
1196 //------------------------------------------------------------------------------
1197 void DbTextField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
)
1199 m_pEdit
->SetText( GetFormatText( _rxField
, xFormatter
) );
1200 m_pEdit
->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1203 //------------------------------------------------------------------------------
1204 void DbTextField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1206 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbTextField::updateFromModel: invalid call!" );
1209 _rxModel
->getPropertyValue( FM_PROP_TEXT
) >>= sText
;
1211 xub_StrLen nMaxTextLen
= m_pEdit
->GetMaxTextLen();
1212 if ( EDIT_NOLIMIT
!= nMaxTextLen
&& sText
.getLength() > nMaxTextLen
)
1214 sal_Int32 nDiff
= sText
.getLength() - nMaxTextLen
;
1215 sText
= sText
.replaceAt(sText
.getLength() - nDiff
,nDiff
, OUString());
1219 m_pEdit
->SetText( sText
);
1220 m_pEdit
->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1223 //------------------------------------------------------------------------------
1224 sal_Bool
DbTextField::commitControl()
1226 OUString
aText( m_pEdit
->GetText( getModelLineEndSetting( m_rColumn
.getModel() ) ) );
1227 // we have to check if the length before we can decide if the value was modified
1228 xub_StrLen nMaxTextLen
= m_pEdit
->GetMaxTextLen();
1229 if ( EDIT_NOLIMIT
!= nMaxTextLen
)
1232 m_rColumn
.getModel()->getPropertyValue( FM_PROP_TEXT
) >>= sOldValue
;
1233 // if the new value didn't change we must set the old long value again
1234 if ( sOldValue
.getLength() > nMaxTextLen
&& sOldValue
.compareTo(aText
,nMaxTextLen
) == 0 )
1237 m_rColumn
.getModel()->setPropertyValue( FM_PROP_TEXT
, makeAny( aText
) );
1241 //------------------------------------------------------------------------------
1242 void DbTextField::implSetEffectiveMaxTextLen( sal_Int16 _nMaxLen
)
1245 m_pEdit
->SetMaxTextLen( _nMaxLen
);
1246 if ( m_pPainterImplementation
)
1247 m_pPainterImplementation
->SetMaxTextLen( _nMaxLen
);
1250 //==============================================================================
1251 //= DbFormattedField
1252 //==============================================================================
1253 DBG_NAME(DbFormattedField
);
1254 //------------------------------------------------------------------------------
1255 DbFormattedField::DbFormattedField(DbGridColumn
& _rColumn
)
1256 :DbLimitedLengthField(_rColumn
)
1257 ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED
)
1259 DBG_CTOR(DbFormattedField
,NULL
);
1261 // if our model's format key changes we want to propagate the new value to our windows
1262 doPropertyListening( FM_PROP_FORMATKEY
);
1265 //------------------------------------------------------------------------------
1266 DbFormattedField::~DbFormattedField()
1268 DBG_DTOR(DbFormattedField
,NULL
);
1271 //------------------------------------------------------------------------------
1272 void DbFormattedField::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
1274 sal_Int16 nAlignment
= m_rColumn
.SetAlignmentFromModel(-1);
1276 Reference
< ::com::sun::star::beans::XPropertySet
> xUnoModel
= m_rColumn
.getModel();
1280 case ::com::sun::star::awt::TextAlign::RIGHT
:
1281 m_pWindow
= new FormattedField( &rParent
, WB_RIGHT
);
1282 m_pPainter
= new FormattedField( &rParent
, WB_RIGHT
);
1285 case ::com::sun::star::awt::TextAlign::CENTER
:
1286 m_pWindow
= new FormattedField( &rParent
, WB_CENTER
);
1287 m_pPainter
= new FormattedField( &rParent
, WB_CENTER
);
1290 m_pWindow
= new FormattedField( &rParent
, WB_LEFT
);
1291 m_pPainter
= new FormattedField( &rParent
, WB_LEFT
);
1293 // Alles nur damit die Selektion bei Focuserhalt von rechts nach links geht
1294 AllSettings aSettings
= m_pWindow
->GetSettings();
1295 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
1296 aStyleSettings
.SetSelectionOptions(
1297 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
1298 aSettings
.SetStyleSettings(aStyleSettings
);
1299 m_pWindow
->SetSettings(aSettings
);
1302 implAdjustGenericFieldSetting( xUnoModel
);
1304 static_cast< FormattedField
* >( m_pWindow
)->SetStrictFormat( sal_False
);
1305 static_cast< FormattedField
* >( m_pPainter
)->SetStrictFormat( sal_False
);
1306 // wenn man _irgendeine_ Formatierung zulaesst, kann man da sowieso keine Eingabe-Ueberpruefung
1307 // machen (das FormattedField unterstuetzt das sowieso nicht, nur abgeleitete Klassen)
1309 // von dem Uno-Model den Formatter besorgen
1310 // (Ich koennte theoretisch auch ueber den ::com::sun::star::util::NumberFormatter gehen, den mir der Cursor bestimmt
1311 // liefern wuerde. Das Problem dabei ist, dass ich mich eigentlich nicht darauf verlassen
1312 // kann, dass die beiden Formatter die selben sind, sauber ist das Ganze, wenn ich ueber das
1314 sal_Int32 nFormatKey
= -1;
1316 // mal sehen, ob das Model einen hat ...
1317 DBG_ASSERT(::comphelper::hasProperty(FM_PROP_FORMATSSUPPLIER
, xUnoModel
), "DbFormattedField::Init : invalid UNO model !");
1318 Any
aSupplier( xUnoModel
->getPropertyValue(FM_PROP_FORMATSSUPPLIER
));
1319 if (aSupplier
.hasValue())
1321 ::cppu::extractInterface(m_xSupplier
, aSupplier
);
1322 if (m_xSupplier
.is())
1324 // wenn wir den Supplier vom Model nehmen, dann auch den Key
1325 Any
aFmtKey( xUnoModel
->getPropertyValue(FM_PROP_FORMATKEY
));
1326 if (aFmtKey
.hasValue())
1328 DBG_ASSERT(aFmtKey
.getValueType().getTypeClass() == TypeClass_LONG
, "DbFormattedField::Init : invalid format key property (no sal_Int32) !");
1329 nFormatKey
= ::comphelper::getINT32(aFmtKey
);
1333 DBG_WARNING("DbFormattedField::Init : my uno-model has no format-key, but a formats supplier !");
1334 // the OFormattedModel which we usually are working with ensures that the model has a format key
1335 // as soon as the form is loaded. Unfortunally this method here is called from within loaded, too.
1336 // So if our LoadListener is called before the LoadListener of the model, this "else case" is
1338 // Of course our property listener for the FormatKey property will notify us if the prop is changed,
1339 // so this here isn't really bad ....
1345 // nein ? vielleicht die ::com::sun::star::form::component::Form hinter dem Cursor ?
1346 if (!m_xSupplier
.is())
1348 Reference
< XRowSet
> xCursorForm(xCursor
, UNO_QUERY
);
1349 if (xCursorForm
.is())
1350 { // wenn wir vom Cursor den Formatter nehmen, dann auch den Key vom Feld, an das wir gebunden sind
1351 m_xSupplier
= getNumberFormats(getRowSetConnection(xCursorForm
), sal_False
);
1353 if (m_rColumn
.GetField().is())
1354 nFormatKey
= ::comphelper::getINT32(m_rColumn
.GetField()->getPropertyValue(FM_PROP_FORMATKEY
));
1358 SvNumberFormatter
* pFormatterUsed
= NULL
;
1359 if (m_xSupplier
.is())
1361 SvNumberFormatsSupplierObj
* pImplmentation
= SvNumberFormatsSupplierObj::getImplementation(m_xSupplier
);
1363 pFormatterUsed
= pImplmentation
->GetNumberFormatter();
1365 // alles hingfaellig : der Supplier ist vom falschen Typ, dann koennen wir uns auch nicht darauf verlassen, dass
1366 // ein Standard-Formatter den (eventuell nicht-Standard-)Key kennt.
1370 // einen Standard-Formatter ...
1371 if (pFormatterUsed
== NULL
)
1373 pFormatterUsed
= ((FormattedField
*)m_pWindow
)->StandardFormatter();
1374 DBG_ASSERT(pFormatterUsed
!= NULL
, "DbFormattedField::Init : no standard formatter given by the numeric field !");
1376 // ... und einen Standard-Key
1377 if (nFormatKey
== -1)
1380 m_nKeyType
= comphelper::getNumberFormatType(m_xSupplier
->getNumberFormats(), nFormatKey
);
1382 ((FormattedField
*)m_pWindow
)->SetFormatter(pFormatterUsed
);
1383 ((FormattedField
*)m_pPainter
)->SetFormatter(pFormatterUsed
);
1385 ((FormattedField
*)m_pWindow
)->SetFormatKey(nFormatKey
);
1386 ((FormattedField
*)m_pPainter
)->SetFormatKey(nFormatKey
);
1388 ((FormattedField
*)m_pWindow
)->TreatAsNumber(m_rColumn
.IsNumeric());
1389 ((FormattedField
*)m_pPainter
)->TreatAsNumber(m_rColumn
.IsNumeric());
1391 // Min- und Max-Werte
1392 if (m_rColumn
.IsNumeric())
1394 sal_Bool bClearMin
= sal_True
;
1395 if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MIN
, xUnoModel
))
1397 Any
aMin( xUnoModel
->getPropertyValue(FM_PROP_EFFECTIVE_MIN
));
1398 if (aMin
.getValueType().getTypeClass() != TypeClass_VOID
)
1400 DBG_ASSERT(aMin
.getValueType().getTypeClass() == TypeClass_DOUBLE
, "DbFormattedField::Init : the model has an invalid min value !");
1401 double dMin
= ::comphelper::getDouble(aMin
);
1402 ((FormattedField
*)m_pWindow
)->SetMinValue(dMin
);
1403 ((FormattedField
*)m_pPainter
)->SetMinValue(dMin
);
1404 bClearMin
= sal_False
;
1409 ((FormattedField
*)m_pWindow
)->ClearMinValue();
1410 ((FormattedField
*)m_pPainter
)->ClearMinValue();
1412 sal_Bool bClearMax
= sal_True
;
1413 if (::comphelper::hasProperty(FM_PROP_EFFECTIVE_MAX
, xUnoModel
))
1415 Any
aMin( xUnoModel
->getPropertyValue(FM_PROP_EFFECTIVE_MAX
));
1416 if (aMin
.getValueType().getTypeClass() != TypeClass_VOID
)
1418 DBG_ASSERT(aMin
.getValueType().getTypeClass() == TypeClass_DOUBLE
, "DbFormattedField::Init : the model has an invalid max value !");
1419 double dMin
= ::comphelper::getDouble(aMin
);
1420 ((FormattedField
*)m_pWindow
)->SetMaxValue(dMin
);
1421 ((FormattedField
*)m_pPainter
)->SetMaxValue(dMin
);
1422 bClearMax
= sal_False
;
1427 ((FormattedField
*)m_pWindow
)->ClearMaxValue();
1428 ((FormattedField
*)m_pPainter
)->ClearMaxValue();
1433 Any
aDefault( xUnoModel
->getPropertyValue(FM_PROP_EFFECTIVE_DEFAULT
));
1434 if (aDefault
.hasValue())
1435 { // das Ding kann ein double oder ein String sein
1436 switch (aDefault
.getValueType().getTypeClass())
1438 case TypeClass_DOUBLE
:
1439 if (m_rColumn
.IsNumeric())
1441 ((FormattedField
*)m_pWindow
)->SetDefaultValue(::comphelper::getDouble(aDefault
));
1442 ((FormattedField
*)m_pPainter
)->SetDefaultValue(::comphelper::getDouble(aDefault
));
1448 pFormatterUsed
->GetOutputString(::comphelper::getDouble(aDefault
), 0, sConverted
, &pDummy
);
1449 ((FormattedField
*)m_pWindow
)->SetDefaultText(sConverted
);
1450 ((FormattedField
*)m_pPainter
)->SetDefaultText(sConverted
);
1453 case TypeClass_STRING
:
1455 OUString
sDefault( ::comphelper::getString(aDefault
) );
1456 if (m_rColumn
.IsNumeric())
1459 sal_uInt32
nTestFormat(0);
1460 if (pFormatterUsed
->IsNumberFormat(sDefault
, nTestFormat
, dVal
))
1462 ((FormattedField
*)m_pWindow
)->SetDefaultValue(dVal
);
1463 ((FormattedField
*)m_pPainter
)->SetDefaultValue(dVal
);
1468 ((FormattedField
*)m_pWindow
)->SetDefaultText(sDefault
);
1469 ((FormattedField
*)m_pPainter
)->SetDefaultText(sDefault
);
1473 OSL_FAIL( "DbFormattedField::Init: unexpected value type!" );
1477 DbLimitedLengthField::Init( rParent
, xCursor
);
1480 //------------------------------------------------------------------------------
1481 CellControllerRef
DbFormattedField::CreateController() const
1483 return new ::svt::FormattedFieldCellController( static_cast< FormattedField
* >( m_pWindow
) );
1486 //------------------------------------------------------------------------------
1487 void DbFormattedField::_propertyChanged( const PropertyChangeEvent
& _rEvent
) throw( RuntimeException
)
1489 if (_rEvent
.PropertyName
== FM_PROP_FORMATKEY
)
1491 sal_Int32 nNewKey
= _rEvent
.NewValue
.hasValue() ? ::comphelper::getINT32(_rEvent
.NewValue
) : 0;
1492 m_nKeyType
= comphelper::getNumberFormatType(m_xSupplier
->getNumberFormats(), nNewKey
);
1494 DBG_ASSERT(m_pWindow
&& m_pPainter
, "DbFormattedField::_propertyChanged : where are my windows ?");
1496 static_cast< FormattedField
* >( m_pWindow
)->SetFormatKey( nNewKey
);
1498 static_cast< FormattedField
* >( m_pPainter
)->SetFormatKey( nNewKey
);
1502 DbLimitedLengthField::_propertyChanged( _rEvent
);
1506 //------------------------------------------------------------------------------
1507 OUString
DbFormattedField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** ppColor
)
1509 // defaultmaessig keine Farb-Angabe
1510 if (ppColor
!= NULL
)
1513 // NULL-Wert -> leerer Text
1520 if (m_rColumn
.IsNumeric())
1522 // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern
1523 // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an
1524 // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst
1525 // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann
1526 // ich den Rest (die Formatierung) dem FormattedField ueberlassen.
1527 double dValue
= getValue( _rxField
, m_rColumn
.GetParent().getNullDate() );
1528 if (_rxField
->wasNull())
1530 ((FormattedField
*)m_pPainter
)->SetValue(dValue
);
1534 // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann.
1535 // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen.
1536 aText
= _rxField
->getString();
1537 if (_rxField
->wasNull())
1539 ((FormattedField
*)m_pPainter
)->SetTextFormatted(aText
);
1542 catch( const Exception
& )
1544 DBG_UNHANDLED_EXCEPTION();
1547 aText
= m_pPainter
->GetText();
1548 if (ppColor
!= NULL
)
1549 *ppColor
= ((FormattedField
*)m_pPainter
)->GetLastOutputColor();
1554 //------------------------------------------------------------------------------
1555 void DbFormattedField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/)
1559 FormattedField
* pFormattedWindow
= static_cast<FormattedField
*>(m_pWindow
);
1561 { // NULL-Wert -> leerer Text
1562 m_pWindow
->SetText(OUString());
1564 else if (m_rColumn
.IsNumeric())
1566 // das IsNumeric an der Column sagt nichts aus ueber die Klasse des benutzen Formates, sondern
1567 // ueber die des an die Column gebundenen Feldes. Wenn man also eine FormattedField-Spalte an
1568 // ein double-Feld bindet und als Text formatiert, liefert m_rColumn.IsNumeric() sal_True. Das heisst
1569 // also einfach, dass ich den Inhalt der Variant mittels getDouble abfragen kann, und dann kann
1570 // ich den Rest (die Formatierung) dem FormattedField ueberlassen.
1571 double dValue
= getValue( _rxField
, m_rColumn
.GetParent().getNullDate() );
1572 if (_rxField
->wasNull())
1573 m_pWindow
->SetText(OUString());
1575 pFormattedWindow
->SetValue(dValue
);
1579 // Hier kann ich nicht mit einem double arbeiten, da das Feld mir keines liefern kann.
1580 // Also einfach den Text vom ::com::sun::star::util::NumberFormatter in die richtige ::com::sun::star::form::component::Form brinden lassen.
1581 OUString
sText( _rxField
->getString());
1583 pFormattedWindow
->SetTextFormatted( sText
);
1584 pFormattedWindow
->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1587 catch( const Exception
& )
1589 DBG_UNHANDLED_EXCEPTION();
1593 //------------------------------------------------------------------------------
1594 void DbFormattedField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1596 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbFormattedField::updateFromModel: invalid call!" );
1598 FormattedField
* pFormattedWindow
= static_cast< FormattedField
* >( m_pWindow
);
1601 Any aValue
= _rxModel
->getPropertyValue( FM_PROP_EFFECTIVE_VALUE
);
1602 if ( aValue
>>= sText
)
1603 { // our effective value is transferred as string
1604 pFormattedWindow
->SetTextFormatted( sText
);
1605 pFormattedWindow
->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1611 pFormattedWindow
->SetValue(dValue
);
1615 //------------------------------------------------------------------------------
1616 sal_Bool
DbFormattedField::commitControl()
1619 FormattedField
& rField
= *(FormattedField
*)m_pWindow
;
1620 DBG_ASSERT(&rField
== m_pWindow
, "DbFormattedField::commitControl : can't work with a window other than my own !");
1621 if (m_rColumn
.IsNumeric())
1623 if (!rField
.GetText().isEmpty())
1624 aNewVal
<<= rField
.GetValue();
1625 // ein LeerString wird erst mal standardmaessig als void weitergereicht
1628 aNewVal
<<= OUString(rField
.GetTextValue());
1630 m_rColumn
.getModel()->setPropertyValue(FM_PROP_EFFECTIVE_VALUE
, aNewVal
);
1634 //==============================================================================
1636 //==============================================================================
1637 //------------------------------------------------------------------------------
1638 DbCheckBox::DbCheckBox( DbGridColumn
& _rColumn
)
1639 :DbCellControl( _rColumn
, sal_True
)
1641 setAlignedController( sal_False
);
1646 void setCheckBoxStyle( Window
* _pWindow
, bool bMono
)
1648 AllSettings aSettings
= _pWindow
->GetSettings();
1649 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
1651 aStyleSettings
.SetOptions( aStyleSettings
.GetOptions() | STYLE_OPTION_MONO
);
1653 aStyleSettings
.SetOptions( aStyleSettings
.GetOptions() & (~STYLE_OPTION_MONO
) );
1654 aSettings
.SetStyleSettings( aStyleSettings
);
1655 _pWindow
->SetSettings( aSettings
);
1659 //------------------------------------------------------------------------------
1660 void DbCheckBox::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
1662 setTransparent( sal_True
);
1664 m_pWindow
= new CheckBoxControl( &rParent
);
1665 m_pPainter
= new CheckBoxControl( &rParent
);
1667 m_pWindow
->SetPaintTransparent( sal_True
);
1668 m_pPainter
->SetPaintTransparent( sal_True
);
1670 m_pPainter
->SetBackground();
1674 Reference
< XPropertySet
> xModel( m_rColumn
.getModel(), UNO_SET_THROW
);
1676 sal_Int16 nStyle
= awt::VisualEffect::LOOK3D
;
1677 OSL_VERIFY( xModel
->getPropertyValue( FM_PROP_VISUALEFFECT
) >>= nStyle
);
1679 setCheckBoxStyle( m_pWindow
, nStyle
== awt::VisualEffect::FLAT
);
1680 setCheckBoxStyle( m_pPainter
, nStyle
== awt::VisualEffect::FLAT
);
1682 sal_Bool bTristate
= sal_True
;
1683 OSL_VERIFY( xModel
->getPropertyValue( FM_PROP_TRISTATE
) >>= bTristate
);
1684 static_cast< CheckBoxControl
* >( m_pWindow
)->GetBox().EnableTriState( bTristate
);
1685 static_cast< CheckBoxControl
* >( m_pPainter
)->GetBox().EnableTriState( bTristate
);
1687 catch( const Exception
& )
1689 DBG_UNHANDLED_EXCEPTION();
1692 DbCellControl::Init( rParent
, xCursor
);
1695 //------------------------------------------------------------------------------
1696 CellControllerRef
DbCheckBox::CreateController() const
1698 return new CheckBoxCellController((CheckBoxControl
*)m_pWindow
);
1700 //------------------------------------------------------------------------------
1701 static void lcl_setCheckBoxState( const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
,
1702 CheckBoxControl
* _pCheckBoxControl
)
1704 TriState eState
= STATE_DONTKNOW
;
1709 sal_Bool bValue
= _rxField
->getBoolean();
1710 if (!_rxField
->wasNull())
1711 eState
= bValue
? STATE_CHECK
: STATE_NOCHECK
;
1713 catch( const Exception
& )
1715 DBG_UNHANDLED_EXCEPTION();
1718 _pCheckBoxControl
->GetBox().SetState(eState
);
1721 //------------------------------------------------------------------------------
1722 void DbCheckBox::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/)
1724 lcl_setCheckBoxState( _rxField
, static_cast<CheckBoxControl
*>(m_pWindow
) );
1727 //------------------------------------------------------------------------------
1728 void DbCheckBox::PaintFieldToCell(OutputDevice
& rDev
, const Rectangle
& rRect
,
1729 const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
,
1730 const Reference
< XNumberFormatter
>& xFormatter
)
1732 lcl_setCheckBoxState( _rxField
, static_cast<CheckBoxControl
*>(m_pPainter
) );
1733 DbCellControl::PaintFieldToCell( rDev
, rRect
, _rxField
, xFormatter
);
1736 //------------------------------------------------------------------------------
1737 void DbCheckBox::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1739 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbCheckBox::updateFromModel: invalid call!" );
1741 sal_Int16 nState
= STATE_DONTKNOW
;
1742 _rxModel
->getPropertyValue( FM_PROP_STATE
) >>= nState
;
1743 static_cast< CheckBoxControl
* >( m_pWindow
)->GetBox().SetState( static_cast< TriState
>( nState
) );
1746 //------------------------------------------------------------------------------
1747 sal_Bool
DbCheckBox::commitControl()
1749 #if OSL_DEBUG_LEVEL > 0
1750 Any aVal
= makeAny( (sal_Int16
)( static_cast< CheckBoxControl
* >( m_pWindow
)->GetBox().GetState() ) );
1752 m_rColumn
.getModel()->setPropertyValue( FM_PROP_STATE
,
1753 makeAny( (sal_Int16
)( static_cast< CheckBoxControl
* >( m_pWindow
)->GetBox().GetState() ) ) );
1757 //------------------------------------------------------------------------------
1758 OUString
DbCheckBox::GetFormatText(const Reference
< XColumn
>& /*_rxField*/, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
1763 //==============================================================================
1765 //------------------------------------------------------------------------------
1766 DbPatternField::DbPatternField( DbGridColumn
& _rColumn
, const ::comphelper::ComponentContext
& _rContext
)
1767 :DbCellControl( _rColumn
)
1768 ,m_aContext( _rContext
)
1770 doPropertyListening( FM_PROP_LITERALMASK
);
1771 doPropertyListening( FM_PROP_EDITMASK
);
1772 doPropertyListening( FM_PROP_STRICTFORMAT
);
1775 //------------------------------------------------------------------------------
1776 void DbPatternField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
1778 DBG_ASSERT( m_pWindow
, "DbPatternField::implAdjustGenericFieldSetting: not to be called without window!" );
1779 DBG_ASSERT( _rxModel
.is(), "DbPatternField::implAdjustGenericFieldSetting: invalid model!" );
1780 if ( m_pWindow
&& _rxModel
.is() )
1784 sal_Bool bStrict
= sal_False
;
1786 _rxModel
->getPropertyValue( FM_PROP_LITERALMASK
) >>= aLitMask
;
1787 _rxModel
->getPropertyValue( FM_PROP_EDITMASK
) >>= aEditMask
;
1788 _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) >>= bStrict
;
1790 OString
aAsciiEditMask(OUStringToOString(aEditMask
, RTL_TEXTENCODING_ASCII_US
));
1792 static_cast< PatternField
* >( m_pWindow
)->SetMask( aAsciiEditMask
, aLitMask
);
1793 static_cast< PatternField
* >( m_pPainter
)->SetMask( aAsciiEditMask
, aLitMask
);
1794 static_cast< PatternField
* >( m_pWindow
)->SetStrictFormat( bStrict
);
1795 static_cast< PatternField
* >( m_pPainter
)->SetStrictFormat( bStrict
);
1799 //------------------------------------------------------------------------------
1800 void DbPatternField::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
1802 m_rColumn
.SetAlignmentFromModel(-1);
1804 m_pWindow
= new PatternField( &rParent
, 0 );
1805 m_pPainter
= new PatternField( &rParent
, 0 );
1807 Reference
< XPropertySet
> xModel( m_rColumn
.getModel() );
1808 implAdjustGenericFieldSetting( xModel
);
1810 DbCellControl::Init( rParent
, xCursor
);
1813 //------------------------------------------------------------------------------
1814 CellControllerRef
DbPatternField::CreateController() const
1816 return new SpinCellController( static_cast< PatternField
* >( m_pWindow
) );
1819 //------------------------------------------------------------------------------
1820 OUString
DbPatternField::impl_formatText( const OUString
& _rText
)
1822 m_pPainter
->SetText( _rText
);
1823 static_cast< PatternField
* >( m_pPainter
)->ReformatAll();
1824 return m_pPainter
->GetText();
1827 //------------------------------------------------------------------------------
1828 OUString
DbPatternField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
1830 bool bIsForPaint
= _rxField
!= m_rColumn
.GetField();
1831 SAL_WNODEPRECATED_DECLARATIONS_PUSH
1832 ::std::auto_ptr
< ::dbtools::FormattedColumnValue
>& rpFormatter
= bIsForPaint
? m_pPaintFormatter
: m_pValueFormatter
;
1833 SAL_WNODEPRECATED_DECLARATIONS_POP
1835 if ( !rpFormatter
.get() )
1837 DBToolsObjectFactory aFactory
;
1838 rpFormatter
= aFactory
.createFormattedColumnValue(
1839 m_aContext
, getCursor(), Reference
< XPropertySet
>( _rxField
, UNO_QUERY
) );
1840 OSL_ENSURE( rpFormatter
.get(), "DbPatternField::Init: no value formatter!" );
1843 OSL_ENSURE( rpFormatter
->getColumn() == _rxField
, "DbPatternField::GetFormatText: my value formatter is working for another field ...!" );
1844 // re-creating the value formatter here everytime would be quite expensive ...
1847 if ( rpFormatter
.get() )
1848 sText
= rpFormatter
->getFormattedValue();
1850 return impl_formatText( sText
);
1853 //------------------------------------------------------------------------------
1854 void DbPatternField::UpdateFromField( const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
1856 static_cast< Edit
* >( m_pWindow
)->SetText( GetFormatText( _rxField
, _rxFormatter
) );
1857 static_cast< Edit
* >( m_pWindow
)->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1860 //------------------------------------------------------------------------------
1861 void DbPatternField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
1863 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbPatternField::updateFromModel: invalid call!" );
1866 _rxModel
->getPropertyValue( FM_PROP_TEXT
) >>= sText
;
1868 static_cast< Edit
* >( m_pWindow
)->SetText( impl_formatText( sText
) );
1869 static_cast< Edit
* >( m_pWindow
)->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
1872 //------------------------------------------------------------------------------
1873 sal_Bool
DbPatternField::commitControl()
1875 OUString
aText(m_pWindow
->GetText());
1876 m_rColumn
.getModel()->setPropertyValue(FM_PROP_TEXT
, makeAny(aText
));
1880 //==============================================================================
1882 //==============================================================================
1883 //------------------------------------------------------------------------------
1884 DbSpinField::DbSpinField( DbGridColumn
& _rColumn
, sal_Int16 _nStandardAlign
)
1885 :DbCellControl( _rColumn
)
1886 ,m_nStandardAlign( _nStandardAlign
)
1890 //------------------------------------------------------------------------------
1891 void DbSpinField::Init( Window
& _rParent
, const Reference
< XRowSet
>& _rxCursor
)
1893 m_rColumn
.SetAlignmentFromModel( m_nStandardAlign
);
1895 Reference
< XPropertySet
> xModel( m_rColumn
.getModel() );
1897 // determine the WinBits for the field
1898 WinBits nFieldStyle
= 0;
1899 if ( ::comphelper::getBOOL( xModel
->getPropertyValue( FM_PROP_SPIN
) ) )
1900 nFieldStyle
= WB_REPEAT
| WB_SPIN
;
1901 // create the fields
1902 m_pWindow
= createField( &_rParent
, nFieldStyle
, xModel
);
1903 m_pPainter
= createField( &_rParent
, nFieldStyle
, xModel
);
1905 // adjust all other settings which depend on the property values
1906 implAdjustGenericFieldSetting( xModel
);
1908 // call the base class
1909 DbCellControl::Init( _rParent
, _rxCursor
);
1912 //------------------------------------------------------------------------------
1913 CellControllerRef
DbSpinField::CreateController() const
1915 return new SpinCellController( static_cast< SpinField
* >( m_pWindow
) );
1918 //==============================================================================
1920 //==============================================================================
1921 //------------------------------------------------------------------------------
1922 DbNumericField::DbNumericField( DbGridColumn
& _rColumn
)
1923 :DbSpinField( _rColumn
)
1925 doPropertyListening( FM_PROP_DECIMAL_ACCURACY
);
1926 doPropertyListening( FM_PROP_VALUEMIN
);
1927 doPropertyListening( FM_PROP_VALUEMAX
);
1928 doPropertyListening( FM_PROP_VALUESTEP
);
1929 doPropertyListening( FM_PROP_STRICTFORMAT
);
1930 doPropertyListening( FM_PROP_SHOWTHOUSANDSEP
);
1933 //------------------------------------------------------------------------------
1934 void DbNumericField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
1936 DBG_ASSERT( m_pWindow
, "DbNumericField::implAdjustGenericFieldSetting: not to be called without window!" );
1937 DBG_ASSERT( _rxModel
.is(), "DbNumericField::implAdjustGenericFieldSetting: invalid model!" );
1938 if ( m_pWindow
&& _rxModel
.is() )
1940 sal_Int32 nMin
= (sal_Int32
)getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUEMIN
) );
1941 sal_Int32 nMax
= (sal_Int32
)getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUEMAX
) );
1942 sal_Int32 nStep
= (sal_Int32
)getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUESTEP
) );
1943 sal_Bool bStrict
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) );
1944 sal_Int16 nScale
= getINT16( _rxModel
->getPropertyValue( FM_PROP_DECIMAL_ACCURACY
) );
1945 sal_Bool bThousand
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP
) );
1947 static_cast< DoubleNumericField
* >( m_pWindow
)->SetMinValue(nMin
);
1948 static_cast< DoubleNumericField
* >( m_pWindow
)->SetMaxValue(nMax
);
1949 static_cast< DoubleNumericField
* >( m_pWindow
)->SetSpinSize(nStep
);
1950 static_cast< DoubleNumericField
* >( m_pWindow
)->SetStrictFormat(bStrict
);
1952 static_cast< DoubleNumericField
* >( m_pPainter
)->SetMinValue(nMin
);
1953 static_cast< DoubleNumericField
* >( m_pPainter
)->SetMaxValue(nMax
);
1954 static_cast< DoubleNumericField
* >( m_pPainter
)->SetStrictFormat(bStrict
);
1957 // dem Field und dem Painter einen Formatter spendieren
1958 // zuerst testen, ob ich von dem Service hinter einer Connection bekommen kann
1959 Reference
< ::com::sun::star::util::XNumberFormatsSupplier
> xSupplier
;
1960 Reference
< XRowSet
> xForm
;
1961 if ( m_rColumn
.GetParent().getDataSource() )
1962 xForm
= Reference
< XRowSet
>( ( Reference
< XInterface
> )*m_rColumn
.GetParent().getDataSource(), UNO_QUERY
);
1964 xSupplier
= getNumberFormats( getRowSetConnection( xForm
), sal_True
);
1965 SvNumberFormatter
* pFormatterUsed
= NULL
;
1966 if ( xSupplier
.is() )
1968 SvNumberFormatsSupplierObj
* pImplmentation
= SvNumberFormatsSupplierObj::getImplementation( xSupplier
);
1969 pFormatterUsed
= pImplmentation
? pImplmentation
->GetNumberFormatter() : NULL
;
1971 if ( NULL
== pFormatterUsed
)
1972 { // der Cursor fuehrte nicht zum Erfolg -> Standard
1973 pFormatterUsed
= static_cast< DoubleNumericField
* >( m_pWindow
)->StandardFormatter();
1974 DBG_ASSERT( pFormatterUsed
!= NULL
, "DbNumericField::implAdjustGenericFieldSetting: no standard formatter given by the numeric field !" );
1976 static_cast< DoubleNumericField
* >( m_pWindow
)->SetFormatter( pFormatterUsed
);
1977 static_cast< DoubleNumericField
* >( m_pPainter
)->SetFormatter( pFormatterUsed
);
1979 // und dann ein Format generieren, dass die gewuenschten Nachkommastellen usw. hat
1980 LanguageType aAppLanguage
= Application::GetSettings().GetUILanguageTag().getLanguageType();
1981 OUString sFormatString
= pFormatterUsed
->GenerateFormat(0, aAppLanguage
, bThousand
, sal_False
, nScale
);
1983 static_cast< DoubleNumericField
* >( m_pWindow
)->SetFormat( sFormatString
, aAppLanguage
);
1984 static_cast< DoubleNumericField
* >( m_pPainter
)->SetFormat( sFormatString
, aAppLanguage
);
1988 //------------------------------------------------------------------------------
1989 SpinField
* DbNumericField::createField( Window
* _pParent
, WinBits _nFieldStyle
, const Reference
< XPropertySet
>& /*_rxModel*/ )
1991 return new DoubleNumericField( _pParent
, _nFieldStyle
);
1996 //--------------------------------------------------------------------------
1997 static OUString
lcl_setFormattedNumeric_nothrow( DoubleNumericField
& _rField
, const DbCellControl
& _rControl
,
1998 const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
2001 if ( _rxField
.is() )
2005 double fValue
= _rControl
.GetValue( _rxField
, _rxFormatter
);
2006 if ( !_rxField
->wasNull() )
2008 _rField
.SetValue( fValue
);
2009 sValue
= _rField
.GetText();
2012 catch( const Exception
& )
2014 DBG_UNHANDLED_EXCEPTION();
2021 //------------------------------------------------------------------------------
2022 OUString
DbNumericField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
, Color
** /*ppColor*/)
2024 return lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField
* >( m_pPainter
), *this, _rxField
, _rxFormatter
);
2027 //------------------------------------------------------------------------------
2028 void DbNumericField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
)
2030 lcl_setFormattedNumeric_nothrow( *dynamic_cast< DoubleNumericField
* >( m_pWindow
), *this, _rxField
, _rxFormatter
);
2033 //------------------------------------------------------------------------------
2034 void DbNumericField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2036 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbNumericField::updateFromModel: invalid call!" );
2039 if ( _rxModel
->getPropertyValue( FM_PROP_VALUE
) >>= dValue
)
2040 static_cast< DoubleNumericField
* >( m_pWindow
)->SetValue( dValue
);
2042 m_pWindow
->SetText( OUString() );
2045 //------------------------------------------------------------------------------
2046 sal_Bool
DbNumericField::commitControl()
2048 OUString
aText( m_pWindow
->GetText());
2051 if (!aText
.isEmpty()) // not empty
2053 double fValue
= ((DoubleNumericField
*)m_pWindow
)->GetValue();
2054 aVal
<<= (double)fValue
;
2056 m_rColumn
.getModel()->setPropertyValue(FM_PROP_VALUE
, aVal
);
2060 //==============================================================================
2062 //==============================================================================
2063 //------------------------------------------------------------------------------
2064 DbCurrencyField::DbCurrencyField(DbGridColumn
& _rColumn
)
2065 :DbSpinField( _rColumn
)
2068 doPropertyListening( FM_PROP_DECIMAL_ACCURACY
);
2069 doPropertyListening( FM_PROP_VALUEMIN
);
2070 doPropertyListening( FM_PROP_VALUEMAX
);
2071 doPropertyListening( FM_PROP_VALUESTEP
);
2072 doPropertyListening( FM_PROP_STRICTFORMAT
);
2073 doPropertyListening( FM_PROP_SHOWTHOUSANDSEP
);
2074 doPropertyListening( FM_PROP_CURRENCYSYMBOL
);
2077 //------------------------------------------------------------------------------
2078 void DbCurrencyField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2080 DBG_ASSERT( m_pWindow
, "DbCurrencyField::implAdjustGenericFieldSetting: not to be called without window!" );
2081 DBG_ASSERT( _rxModel
.is(), "DbCurrencyField::implAdjustGenericFieldSetting: invalid model!" );
2082 if ( m_pWindow
&& _rxModel
.is() )
2084 m_nScale
= getINT16( _rxModel
->getPropertyValue( FM_PROP_DECIMAL_ACCURACY
) );
2085 double nMin
= getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUEMIN
) );
2086 double nMax
= getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUEMAX
) );
2087 double nStep
= getDouble( _rxModel
->getPropertyValue( FM_PROP_VALUESTEP
) );
2088 sal_Bool bStrict
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) );
2089 sal_Bool bThousand
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_SHOWTHOUSANDSEP
) );
2090 OUString
aStr( getString( _rxModel
->getPropertyValue(FM_PROP_CURRENCYSYMBOL
) ) );
2092 static_cast< LongCurrencyField
* >( m_pWindow
)->SetUseThousandSep( bThousand
);
2093 static_cast< LongCurrencyField
* >( m_pWindow
)->SetDecimalDigits( m_nScale
);
2094 static_cast< LongCurrencyField
* >( m_pWindow
)->SetCurrencySymbol( aStr
);
2095 static_cast< LongCurrencyField
* >( m_pWindow
)->SetFirst( nMin
);
2096 static_cast< LongCurrencyField
* >( m_pWindow
)->SetLast( nMax
);
2097 static_cast< LongCurrencyField
* >( m_pWindow
)->SetMin( nMin
);
2098 static_cast< LongCurrencyField
* >( m_pWindow
)->SetMax( nMax
);
2099 static_cast< LongCurrencyField
* >( m_pWindow
)->SetSpinSize( nStep
);
2100 static_cast< LongCurrencyField
* >( m_pWindow
)->SetStrictFormat( bStrict
);
2102 static_cast< LongCurrencyField
* >( m_pPainter
)->SetUseThousandSep( bThousand
);
2103 static_cast< LongCurrencyField
* >( m_pPainter
)->SetDecimalDigits( m_nScale
);
2104 static_cast< LongCurrencyField
* >( m_pPainter
)->SetCurrencySymbol( aStr
);
2105 static_cast< LongCurrencyField
* >( m_pPainter
)->SetFirst( nMin
);
2106 static_cast< LongCurrencyField
* >( m_pPainter
)->SetLast( nMax
);
2107 static_cast< LongCurrencyField
* >( m_pPainter
)->SetMin( nMin
);
2108 static_cast< LongCurrencyField
* >( m_pPainter
)->SetMax( nMax
);
2109 static_cast< LongCurrencyField
* >( m_pPainter
)->SetStrictFormat( bStrict
);
2113 //------------------------------------------------------------------------------
2114 SpinField
* DbCurrencyField::createField( Window
* _pParent
, WinBits _nFieldStyle
, const Reference
< XPropertySet
>& /*_rxModel*/ )
2116 return new LongCurrencyField( _pParent
, _nFieldStyle
);
2119 //------------------------------------------------------------------------------
2120 double DbCurrencyField::GetCurrency(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
) const
2122 double fValue
= GetValue(_rxField
, xFormatter
);
2125 // OSL_TRACE("double = %.64f ",fValue);
2126 fValue
= ::rtl::math::pow10Exp(fValue
, m_nScale
);
2127 fValue
= ::rtl::math::round(fValue
, 0);
2134 //--------------------------------------------------------------------------
2135 static OUString
lcl_setFormattedCurrency_nothrow( LongCurrencyField
& _rField
, const DbCurrencyField
& _rControl
,
2136 const Reference
< XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& _rxFormatter
)
2139 if ( _rxField
.is() )
2143 double fValue
= _rControl
.GetCurrency( _rxField
, _rxFormatter
);
2144 if ( !_rxField
->wasNull() )
2146 _rField
.SetValue( fValue
);
2147 BigInt aValue
= _rField
.GetCorrectedValue();
2148 sValue
= aValue
.GetString();
2149 sValue
= _rField
.GetText();
2152 catch( const Exception
& )
2154 DBG_UNHANDLED_EXCEPTION();
2161 //------------------------------------------------------------------------------
2162 OUString
DbCurrencyField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
, Color
** /*ppColor*/)
2164 return lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField
* >( m_pPainter
), *this, _rxField
, _rxFormatter
);
2167 //------------------------------------------------------------------------------
2168 void DbCurrencyField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& _rxFormatter
)
2170 lcl_setFormattedCurrency_nothrow( *dynamic_cast< LongCurrencyField
* >( m_pWindow
), *this, _rxField
, _rxFormatter
);
2173 //------------------------------------------------------------------------------
2174 void DbCurrencyField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2176 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbCurrencyField::updateFromModel: invalid call!" );
2179 if ( _rxModel
->getPropertyValue( FM_PROP_VALUE
) >>= dValue
)
2183 dValue
= ::rtl::math::pow10Exp( dValue
, m_nScale
);
2184 dValue
= ::rtl::math::round(dValue
, 0);
2187 static_cast< LongCurrencyField
* >( m_pWindow
)->SetValue( dValue
);
2190 m_pWindow
->SetText( OUString() );
2193 //------------------------------------------------------------------------------
2194 sal_Bool
DbCurrencyField::commitControl()
2196 OUString
aText(m_pWindow
->GetText());
2198 if (!aText
.isEmpty()) // not empty
2200 double fValue
= ((LongCurrencyField
*)m_pWindow
)->GetValue();
2203 fValue
/= ::rtl::math::pow10Exp(1.0, m_nScale
);
2205 aVal
<<= (double)fValue
;
2207 m_rColumn
.getModel()->setPropertyValue(FM_PROP_VALUE
, aVal
);
2211 //==============================================================================
2213 //==============================================================================
2214 //------------------------------------------------------------------------------
2215 DbDateField::DbDateField( DbGridColumn
& _rColumn
)
2216 :DbSpinField( _rColumn
)
2218 doPropertyListening( FM_PROP_DATEFORMAT
);
2219 doPropertyListening( FM_PROP_DATEMIN
);
2220 doPropertyListening( FM_PROP_DATEMAX
);
2221 doPropertyListening( FM_PROP_STRICTFORMAT
);
2222 doPropertyListening( FM_PROP_DATE_SHOW_CENTURY
);
2225 //------------------------------------------------------------------------------
2226 SpinField
* DbDateField::createField( Window
* _pParent
, WinBits _nFieldStyle
, const Reference
< XPropertySet
>& _rxModel
)
2228 // check if there is a DropDown property set to TRUE
2229 sal_Bool bDropDown
= !hasProperty( FM_PROP_DROPDOWN
, _rxModel
)
2230 || getBOOL( _rxModel
->getPropertyValue( FM_PROP_DROPDOWN
) );
2232 _nFieldStyle
|= WB_DROPDOWN
;
2234 CalendarField
* pField
= new CalendarField( _pParent
, _nFieldStyle
);
2236 pField
->EnableToday();
2237 pField
->EnableNone();
2242 //------------------------------------------------------------------------------
2243 void DbDateField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2245 DBG_ASSERT( m_pWindow
, "DbDateField::implAdjustGenericFieldSetting: not to be called without window!" );
2246 DBG_ASSERT( _rxModel
.is(), "DbDateField::implAdjustGenericFieldSetting: invalid model!" );
2247 if ( m_pWindow
&& _rxModel
.is() )
2249 sal_Int16 nFormat
= getINT16( _rxModel
->getPropertyValue( FM_PROP_DATEFORMAT
) );
2251 OSL_VERIFY( _rxModel
->getPropertyValue( FM_PROP_DATEMIN
) >>= aMin
);
2253 OSL_VERIFY( _rxModel
->getPropertyValue( FM_PROP_DATEMAX
) >>= aMax
);
2254 sal_Bool bStrict
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) );
2256 Any aCentury
= _rxModel
->getPropertyValue( FM_PROP_DATE_SHOW_CENTURY
);
2257 if ( aCentury
.getValueType().getTypeClass() != TypeClass_VOID
)
2259 sal_Bool bShowDateCentury
= getBOOL( aCentury
);
2261 static_cast<DateField
*>( m_pWindow
)->SetShowDateCentury( bShowDateCentury
);
2262 static_cast<DateField
*>( m_pPainter
)->SetShowDateCentury( bShowDateCentury
);
2265 static_cast< DateField
* >( m_pWindow
)->SetExtDateFormat( (ExtDateFieldFormat
)nFormat
);
2266 static_cast< DateField
* >( m_pWindow
)->SetMin( aMin
);
2267 static_cast< DateField
* >( m_pWindow
)->SetMax( aMax
);
2268 static_cast< DateField
* >( m_pWindow
)->SetStrictFormat( bStrict
);
2269 static_cast< DateField
* >( m_pWindow
)->EnableEmptyFieldValue( sal_True
);
2271 static_cast< DateField
* >( m_pPainter
)->SetExtDateFormat( (ExtDateFieldFormat
)nFormat
);
2272 static_cast< DateField
* >( m_pPainter
)->SetMin( aMin
);
2273 static_cast< DateField
* >( m_pPainter
)->SetMax( aMax
);
2274 static_cast< DateField
* >( m_pPainter
)->SetStrictFormat( bStrict
);
2275 static_cast< DateField
* >( m_pPainter
)->EnableEmptyFieldValue( sal_True
);
2281 //--------------------------------------------------------------------------
2282 static OUString
lcl_setFormattedDate_nothrow( DateField
& _rField
, const Reference
< XColumn
>& _rxField
)
2285 if ( _rxField
.is() )
2289 ::com::sun::star::util::Date aValue
= _rxField
->getDate();
2290 if ( _rxField
->wasNull() )
2291 _rField
.SetText( sDate
);
2294 _rField
.SetDate( ::Date( aValue
.Day
, aValue
.Month
, aValue
.Year
) );
2295 sDate
= _rField
.GetText();
2298 catch( const Exception
& )
2300 DBG_UNHANDLED_EXCEPTION();
2306 //------------------------------------------------------------------------------
2307 OUString
DbDateField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
2309 return lcl_setFormattedDate_nothrow( *dynamic_cast< DateField
* >( m_pPainter
), _rxField
);
2312 //------------------------------------------------------------------------------
2313 void DbDateField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/)
2315 lcl_setFormattedDate_nothrow( *dynamic_cast< DateField
* >( m_pWindow
), _rxField
);
2318 //------------------------------------------------------------------------------
2319 void DbDateField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2321 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbDateField::updateFromModel: invalid call!" );
2324 if ( _rxModel
->getPropertyValue( FM_PROP_DATE
) >>= aDate
)
2325 static_cast< DateField
* >( m_pWindow
)->SetDate( ::Date( aDate
) );
2327 static_cast< DateField
* >( m_pWindow
)->SetText( OUString() );
2330 //------------------------------------------------------------------------------
2331 sal_Bool
DbDateField::commitControl()
2333 OUString
aText(m_pWindow
->GetText());
2335 if (!aText
.isEmpty())
2336 aVal
<<= static_cast<DateField
*>(m_pWindow
)->GetDate().GetUNODate();
2340 m_rColumn
.getModel()->setPropertyValue(FM_PROP_DATE
, aVal
);
2344 //==============================================================================
2346 //==============================================================================
2347 //------------------------------------------------------------------------------
2348 DbTimeField::DbTimeField( DbGridColumn
& _rColumn
)
2349 :DbSpinField( _rColumn
, ::com::sun::star::awt::TextAlign::LEFT
)
2351 doPropertyListening( FM_PROP_TIMEFORMAT
);
2352 doPropertyListening( FM_PROP_TIMEMIN
);
2353 doPropertyListening( FM_PROP_TIMEMAX
);
2354 doPropertyListening( FM_PROP_STRICTFORMAT
);
2357 //------------------------------------------------------------------------------
2358 SpinField
* DbTimeField::createField( Window
* _pParent
, WinBits _nFieldStyle
, const Reference
< XPropertySet
>& /*_rxModel*/ )
2360 return new TimeField( _pParent
, _nFieldStyle
);
2363 //------------------------------------------------------------------------------
2364 void DbTimeField::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2366 DBG_ASSERT( m_pWindow
, "DbTimeField::implAdjustGenericFieldSetting: not to be called without window!" );
2367 DBG_ASSERT( _rxModel
.is(), "DbTimeField::implAdjustGenericFieldSetting: invalid model!" );
2368 if ( m_pWindow
&& _rxModel
.is() )
2370 sal_Int16 nFormat
= getINT16( _rxModel
->getPropertyValue( FM_PROP_TIMEFORMAT
) );
2372 OSL_VERIFY( _rxModel
->getPropertyValue( FM_PROP_TIMEMIN
) >>= aMin
);
2374 OSL_VERIFY( _rxModel
->getPropertyValue( FM_PROP_TIMEMAX
) >>= aMax
);
2375 sal_Bool bStrict
= getBOOL( _rxModel
->getPropertyValue( FM_PROP_STRICTFORMAT
) );
2377 static_cast< TimeField
* >( m_pWindow
)->SetExtFormat( (ExtTimeFieldFormat
)nFormat
);
2378 static_cast< TimeField
* >( m_pWindow
)->SetMin( aMin
);
2379 static_cast< TimeField
* >( m_pWindow
)->SetMax( aMax
);
2380 static_cast< TimeField
* >( m_pWindow
)->SetStrictFormat( bStrict
);
2381 static_cast< TimeField
* >( m_pWindow
)->EnableEmptyFieldValue( sal_True
);
2383 static_cast< TimeField
* >( m_pPainter
)->SetExtFormat( (ExtTimeFieldFormat
)nFormat
);
2384 static_cast< TimeField
* >( m_pPainter
)->SetMin( aMin
);
2385 static_cast< TimeField
* >( m_pPainter
)->SetMax( aMax
);
2386 static_cast< TimeField
* >( m_pPainter
)->SetStrictFormat( bStrict
);
2387 static_cast< TimeField
* >( m_pPainter
)->EnableEmptyFieldValue( sal_True
);
2393 //--------------------------------------------------------------------------
2394 static OUString
lcl_setFormattedTime_nothrow( TimeField
& _rField
, const Reference
< XColumn
>& _rxField
)
2397 if ( _rxField
.is() )
2401 ::com::sun::star::util::Time aValue
= _rxField
->getTime();
2402 if ( _rxField
->wasNull() )
2403 _rField
.SetText( sTime
);
2406 _rField
.SetTime( ::Time( aValue
.Hours
, aValue
.Minutes
, aValue
.Seconds
, aValue
.NanoSeconds
) );
2407 sTime
= _rField
.GetText();
2410 catch( const Exception
& )
2412 DBG_UNHANDLED_EXCEPTION();
2418 //------------------------------------------------------------------------------
2419 OUString
DbTimeField::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< ::com::sun::star::util::XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
2421 return lcl_setFormattedTime_nothrow( *static_cast< TimeField
* >( m_pPainter
), _rxField
);
2424 //------------------------------------------------------------------------------
2425 void DbTimeField::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/)
2427 lcl_setFormattedTime_nothrow( *static_cast< TimeField
* >( m_pWindow
), _rxField
);
2430 //------------------------------------------------------------------------------
2431 void DbTimeField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2433 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbTimeField::updateFromModel: invalid call!" );
2436 if ( _rxModel
->getPropertyValue( FM_PROP_DATE
) >>= aTime
)
2437 static_cast< TimeField
* >( m_pWindow
)->SetTime( ::Time( aTime
) );
2439 static_cast< TimeField
* >( m_pWindow
)->SetText( OUString() );
2442 //------------------------------------------------------------------------------
2443 sal_Bool
DbTimeField::commitControl()
2445 OUString
aText(m_pWindow
->GetText());
2447 if (!aText
.isEmpty())
2448 aVal
<<= static_cast<TimeField
*>(m_pWindow
)->GetTime().GetUNOTime();
2452 m_rColumn
.getModel()->setPropertyValue(FM_PROP_TIME
, aVal
);
2456 //==============================================================================
2458 //==============================================================================
2459 //------------------------------------------------------------------------------
2460 DbComboBox::DbComboBox(DbGridColumn
& _rColumn
)
2461 :DbCellControl(_rColumn
)
2462 ,m_nKeyType(::com::sun::star::util::NumberFormat::UNDEFINED
)
2464 setAlignedController( sal_False
);
2466 doPropertyListening( FM_PROP_STRINGITEMLIST
);
2467 doPropertyListening( FM_PROP_LINECOUNT
);
2470 //------------------------------------------------------------------------------
2471 void DbComboBox::_propertyChanged( const PropertyChangeEvent
& _rEvent
) throw( RuntimeException
)
2473 if ( _rEvent
.PropertyName
.equals( FM_PROP_STRINGITEMLIST
) )
2475 SetList(_rEvent
.NewValue
);
2479 DbCellControl::_propertyChanged( _rEvent
) ;
2483 //------------------------------------------------------------------------------
2484 void DbComboBox::SetList(const Any
& rItems
)
2486 ComboBoxControl
* pField
= (ComboBoxControl
*)m_pWindow
;
2489 ::comphelper::StringSequence aTest
;
2490 if (rItems
>>= aTest
)
2492 const OUString
* pStrings
= aTest
.getConstArray();
2493 sal_Int32 nItems
= aTest
.getLength();
2494 for (sal_Int32 i
= 0; i
< nItems
; ++i
, ++pStrings
)
2495 pField
->InsertEntry(*pStrings
, LISTBOX_APPEND
);
2497 // tell the grid control that this controller is invalid and has to be re-initialized
2498 invalidatedController();
2502 //------------------------------------------------------------------------------
2503 void DbComboBox::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2505 DBG_ASSERT( m_pWindow
, "DbComboBox::implAdjustGenericFieldSetting: not to be called without window!" );
2506 DBG_ASSERT( _rxModel
.is(), "DbComboBox::implAdjustGenericFieldSetting: invalid model!" );
2507 if ( m_pWindow
&& _rxModel
.is() )
2509 sal_Int16 nLines
= getINT16( _rxModel
->getPropertyValue( FM_PROP_LINECOUNT
) );
2510 static_cast< ComboBoxControl
* >( m_pWindow
)->SetDropDownLineCount( nLines
);
2514 //------------------------------------------------------------------------------
2515 void DbComboBox::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
2517 m_rColumn
.SetAlignmentFromModel(::com::sun::star::awt::TextAlign::LEFT
);
2519 m_pWindow
= new ComboBoxControl( &rParent
);
2521 // selection von rechts nach links
2522 AllSettings aSettings
= m_pWindow
->GetSettings();
2523 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
2524 aStyleSettings
.SetSelectionOptions(
2525 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
2526 aSettings
.SetStyleSettings(aStyleSettings
);
2527 m_pWindow
->SetSettings(aSettings
, sal_True
);
2529 // some initial properties
2530 Reference
< XPropertySet
> xModel(m_rColumn
.getModel());
2531 SetList( xModel
->getPropertyValue( FM_PROP_STRINGITEMLIST
) );
2532 implAdjustGenericFieldSetting( xModel
);
2534 if (m_rColumn
.GetParent().getNumberFormatter().is())
2535 m_nKeyType
= comphelper::getNumberFormatType(m_rColumn
.GetParent().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(), m_rColumn
.GetKey());
2537 DbCellControl::Init( rParent
, xCursor
);
2540 //------------------------------------------------------------------------------
2541 CellControllerRef
DbComboBox::CreateController() const
2543 return new ComboBoxCellController((ComboBoxControl
*)m_pWindow
);
2546 //------------------------------------------------------------------------------
2547 OUString
DbComboBox::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
, Color
** /*ppColor*/)
2553 aString
= getFormattedValue( _rxField
, xFormatter
, m_rColumn
.GetParent().getNullDate(), m_rColumn
.GetKey(), m_nKeyType
);
2555 catch( const Exception
& )
2557 DBG_UNHANDLED_EXCEPTION();
2562 //------------------------------------------------------------------------------
2563 void DbComboBox::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
)
2565 m_pWindow
->SetText(GetFormatText(_rxField
, xFormatter
));
2568 //------------------------------------------------------------------------------
2569 void DbComboBox::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2571 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbComboBox::updateFromModel: invalid call!" );
2574 _rxModel
->getPropertyValue( FM_PROP_TEXT
) >>= sText
;
2576 static_cast< ComboBox
* >( m_pWindow
)->SetText( sText
);
2577 static_cast< ComboBox
* >( m_pWindow
)->SetSelection( Selection( SELECTION_MAX
, SELECTION_MIN
) );
2580 //------------------------------------------------------------------------------
2581 sal_Bool
DbComboBox::commitControl()
2583 OUString
aText( m_pWindow
->GetText());
2584 m_rColumn
.getModel()->setPropertyValue(FM_PROP_TEXT
, makeAny(aText
));
2588 //------------------------------------------------------------------------------
2589 DbListBox::DbListBox(DbGridColumn
& _rColumn
)
2590 :DbCellControl(_rColumn
)
2591 ,m_bBound(sal_False
)
2593 setAlignedController( sal_False
);
2595 doPropertyListening( FM_PROP_STRINGITEMLIST
);
2596 doPropertyListening( FM_PROP_LINECOUNT
);
2599 //------------------------------------------------------------------------------
2600 void DbListBox::_propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent
& _rEvent
) throw( RuntimeException
)
2602 if ( _rEvent
.PropertyName
.equals( FM_PROP_STRINGITEMLIST
) )
2604 SetList(_rEvent
.NewValue
);
2608 DbCellControl::_propertyChanged( _rEvent
) ;
2612 //------------------------------------------------------------------------------
2613 void DbListBox::SetList(const Any
& rItems
)
2615 ListBoxControl
* pField
= (ListBoxControl
*)m_pWindow
;
2618 m_bBound
= sal_False
;
2620 ::comphelper::StringSequence aTest
;
2621 if (rItems
>>= aTest
)
2623 const OUString
* pStrings
= aTest
.getConstArray();
2624 sal_Int32 nItems
= aTest
.getLength();
2627 for (sal_Int32 i
= 0; i
< nItems
; ++i
, ++pStrings
)
2628 pField
->InsertEntry(*pStrings
, LISTBOX_APPEND
);
2630 m_rColumn
.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ
) >>= m_aValueList
;
2631 m_bBound
= m_aValueList
.getLength() > 0;
2633 // tell the grid control that this controller is invalid and has to be re-initialized
2634 invalidatedController();
2639 //------------------------------------------------------------------------------
2640 void DbListBox::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
2642 m_rColumn
.SetAlignment(::com::sun::star::awt::TextAlign::LEFT
);
2644 m_pWindow
= new ListBoxControl( &rParent
);
2646 // some initial properties
2647 Reference
< XPropertySet
> xModel( m_rColumn
.getModel() );
2648 SetList( xModel
->getPropertyValue( FM_PROP_STRINGITEMLIST
) );
2649 implAdjustGenericFieldSetting( xModel
);
2651 DbCellControl::Init( rParent
, xCursor
);
2654 //------------------------------------------------------------------------------
2655 void DbListBox::implAdjustGenericFieldSetting( const Reference
< XPropertySet
>& _rxModel
)
2657 DBG_ASSERT( m_pWindow
, "DbListBox::implAdjustGenericFieldSetting: not to be called without window!" );
2658 DBG_ASSERT( _rxModel
.is(), "DbListBox::implAdjustGenericFieldSetting: invalid model!" );
2659 if ( m_pWindow
&& _rxModel
.is() )
2661 sal_Int16 nLines
= getINT16( _rxModel
->getPropertyValue( FM_PROP_LINECOUNT
) );
2662 static_cast< ListBoxControl
* >( m_pWindow
)->SetDropDownLineCount( nLines
);
2666 //------------------------------------------------------------------------------
2667 CellControllerRef
DbListBox::CreateController() const
2669 return new ListBoxCellController((ListBoxControl
*)m_pWindow
);
2672 //------------------------------------------------------------------------------
2673 OUString
DbListBox::GetFormatText(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
2676 if ( _rxField
.is() )
2680 sText
= _rxField
->getString();
2683 Sequence
< sal_Int16
> aPosSeq
= ::comphelper::findValue( m_aValueList
, sText
, sal_True
);
2684 if ( aPosSeq
.getLength() )
2685 sText
= static_cast<ListBox
*>(m_pWindow
)->GetEntry(aPosSeq
.getConstArray()[0]);
2690 catch( const Exception
& )
2692 DBG_UNHANDLED_EXCEPTION();
2698 //------------------------------------------------------------------------------
2699 void DbListBox::UpdateFromField(const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
, const Reference
< XNumberFormatter
>& xFormatter
)
2701 OUString
sFormattedText( GetFormatText( _rxField
, xFormatter
) );
2702 if (!sFormattedText
.isEmpty())
2703 static_cast< ListBox
* >( m_pWindow
)->SelectEntry( sFormattedText
);
2705 static_cast< ListBox
* >( m_pWindow
)->SetNoSelection();
2708 //------------------------------------------------------------------------------
2709 void DbListBox::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2711 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbListBox::updateFromModel: invalid call!" );
2713 Sequence
< sal_Int16
> aSelection
;
2714 _rxModel
->getPropertyValue( FM_PROP_SELECT_SEQ
);
2716 sal_Int16 nSelection
= -1;
2717 if ( aSelection
.getLength() > 0 )
2718 nSelection
= aSelection
[ 0 ];
2720 ListBox
* pListBox
= static_cast< ListBox
* >( m_pWindow
);
2722 if ( ( nSelection
>= 0 ) && ( nSelection
< pListBox
->GetEntryCount() ) )
2723 pListBox
->SelectEntryPos( nSelection
);
2725 pListBox
->SetNoSelection( );
2728 //------------------------------------------------------------------------------
2729 sal_Bool
DbListBox::commitControl()
2732 Sequence
<sal_Int16
> aSelectSeq
;
2733 if (static_cast<ListBox
*>(m_pWindow
)->GetSelectEntryCount())
2735 aSelectSeq
.realloc(1);
2736 *(sal_Int16
*)aSelectSeq
.getArray() = (sal_Int16
)static_cast<ListBox
*>(m_pWindow
)->GetSelectEntryPos();
2738 aVal
<<= aSelectSeq
;
2739 m_rColumn
.getModel()->setPropertyValue(FM_PROP_SELECT_SEQ
, aVal
);
2744 DBG_NAME(DbFilterField
);
2745 /*************************************************************************/
2746 DbFilterField::DbFilterField(const Reference
< ::com::sun::star::uno::XComponentContext
>& rxContext
,DbGridColumn
& _rColumn
)
2747 :DbCellControl(_rColumn
)
2748 ,OSQLParserClient(rxContext
)
2749 ,m_nControlClass(::com::sun::star::form::FormComponentType::TEXTFIELD
)
2750 ,m_bFilterList(sal_False
)
2751 ,m_bFilterListFilled(sal_False
)
2752 ,m_bBound(sal_False
)
2754 DBG_CTOR(DbFilterField
,NULL
);
2756 setAlignedController( sal_False
);
2759 //------------------------------------------------------------------------------
2760 DbFilterField::~DbFilterField()
2762 if (m_nControlClass
== ::com::sun::star::form::FormComponentType::CHECKBOX
)
2763 ((CheckBoxControl
*)m_pWindow
)->SetClickHdl( Link() );
2765 DBG_DTOR(DbFilterField
,NULL
);
2768 //------------------------------------------------------------------------------
2769 void DbFilterField::PaintCell(OutputDevice
& rDev
, const Rectangle
& rRect
)
2771 static sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_VCENTER
| TEXT_DRAW_LEFT
;
2772 switch (m_nControlClass
)
2774 case FormComponentType::CHECKBOX
:
2775 DbCellControl::PaintCell( rDev
, rRect
);
2777 case FormComponentType::LISTBOX
:
2778 rDev
.DrawText(rRect
, static_cast<ListBox
*>(m_pWindow
)->GetSelectEntry(), nStyle
);
2781 rDev
.DrawText(rRect
, m_aText
, nStyle
);
2785 //------------------------------------------------------------------------------
2786 void DbFilterField::SetList(const Any
& rItems
, sal_Bool bComboBox
)
2788 ::comphelper::StringSequence aTest
;
2790 const OUString
* pStrings
= aTest
.getConstArray();
2791 sal_Int32 nItems
= aTest
.getLength();
2796 ComboBox
* pField
= (ComboBox
*)m_pWindow
;
2797 for (sal_Int32 i
= 0; i
< nItems
; ++i
, ++pStrings
)
2798 pField
->InsertEntry(*pStrings
, LISTBOX_APPEND
);
2802 ListBox
* pField
= (ListBox
*)m_pWindow
;
2803 for (sal_Int32 i
= 0; i
< nItems
; ++i
, ++pStrings
)
2804 pField
->InsertEntry(*pStrings
, LISTBOX_APPEND
);
2806 m_rColumn
.getModel()->getPropertyValue(FM_PROP_VALUE_SEQ
) >>= m_aValueList
;
2807 m_bBound
= m_aValueList
.getLength() > 0;
2812 //------------------------------------------------------------------------------
2813 void DbFilterField::CreateControl(Window
* pParent
, const Reference
< ::com::sun::star::beans::XPropertySet
>& xModel
)
2815 switch (m_nControlClass
)
2817 case ::com::sun::star::form::FormComponentType::CHECKBOX
:
2818 m_pWindow
= new CheckBoxControl(pParent
);
2819 m_pWindow
->SetPaintTransparent( sal_True
);
2820 ((CheckBoxControl
*)m_pWindow
)->SetClickHdl( LINK( this, DbFilterField
, OnClick
) );
2822 m_pPainter
= new CheckBoxControl(pParent
);
2823 m_pPainter
->SetPaintTransparent( sal_True
);
2824 m_pPainter
->SetBackground();
2826 case ::com::sun::star::form::FormComponentType::LISTBOX
:
2828 m_pWindow
= new ListBoxControl(pParent
);
2829 sal_Int16 nLines
= ::comphelper::getINT16(xModel
->getPropertyValue(FM_PROP_LINECOUNT
));
2830 Any aItems
= xModel
->getPropertyValue(FM_PROP_STRINGITEMLIST
);
2831 SetList(aItems
, m_nControlClass
== ::com::sun::star::form::FormComponentType::COMBOBOX
);
2832 static_cast<ListBox
*>(m_pWindow
)->SetDropDownLineCount(nLines
);
2834 case ::com::sun::star::form::FormComponentType::COMBOBOX
:
2836 m_pWindow
= new ComboBoxControl(pParent
);
2838 AllSettings aSettings
= m_pWindow
->GetSettings();
2839 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
2840 aStyleSettings
.SetSelectionOptions(
2841 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
2842 aSettings
.SetStyleSettings(aStyleSettings
);
2843 m_pWindow
->SetSettings(aSettings
, sal_True
);
2847 sal_Int16 nLines
= ::comphelper::getINT16(xModel
->getPropertyValue(FM_PROP_LINECOUNT
));
2848 Any aItems
= xModel
->getPropertyValue(FM_PROP_STRINGITEMLIST
);
2849 SetList(aItems
, m_nControlClass
== ::com::sun::star::form::FormComponentType::COMBOBOX
);
2850 ((ComboBox
*)m_pWindow
)->SetDropDownLineCount(nLines
);
2853 ((ComboBox
*)m_pWindow
)->SetDropDownLineCount(5);
2858 m_pWindow
= new Edit(pParent
, WB_LEFT
);
2859 AllSettings aSettings
= m_pWindow
->GetSettings();
2860 StyleSettings aStyleSettings
= aSettings
.GetStyleSettings();
2861 aStyleSettings
.SetSelectionOptions(
2862 aStyleSettings
.GetSelectionOptions() | SELECTION_OPTION_SHOWFIRST
);
2863 aSettings
.SetStyleSettings(aStyleSettings
);
2864 m_pWindow
->SetSettings(aSettings
, sal_True
);
2869 //------------------------------------------------------------------------------
2870 void DbFilterField::Init( Window
& rParent
, const Reference
< XRowSet
>& xCursor
)
2872 Reference
< ::com::sun::star::beans::XPropertySet
> xModel(m_rColumn
.getModel());
2873 m_rColumn
.SetAlignment(::com::sun::star::awt::TextAlign::LEFT
);
2877 m_bFilterList
= ::comphelper::hasProperty(FM_PROP_FILTERPROPOSAL
, xModel
) && ::comphelper::getBOOL(xModel
->getPropertyValue(FM_PROP_FILTERPROPOSAL
));
2879 m_nControlClass
= ::com::sun::star::form::FormComponentType::COMBOBOX
;
2882 sal_Int16 nClassId
= ::comphelper::getINT16(xModel
->getPropertyValue(FM_PROP_CLASSID
));
2885 case FormComponentType::CHECKBOX
:
2886 case FormComponentType::LISTBOX
:
2887 case FormComponentType::COMBOBOX
:
2888 m_nControlClass
= nClassId
;
2892 m_nControlClass
= FormComponentType::COMBOBOX
;
2894 m_nControlClass
= FormComponentType::TEXTFIELD
;
2899 CreateControl( &rParent
, xModel
);
2900 DbCellControl::Init( rParent
, xCursor
);
2902 // filter cells are never readonly
2903 Edit
* pAsEdit
= dynamic_cast< Edit
* >( m_pWindow
);
2905 pAsEdit
->SetReadOnly( sal_False
);
2908 //------------------------------------------------------------------------------
2909 CellControllerRef
DbFilterField::CreateController() const
2911 CellControllerRef xController
;
2912 switch (m_nControlClass
)
2914 case ::com::sun::star::form::FormComponentType::CHECKBOX
:
2915 xController
= new CheckBoxCellController((CheckBoxControl
*)m_pWindow
);
2917 case ::com::sun::star::form::FormComponentType::LISTBOX
:
2918 xController
= new ListBoxCellController((ListBoxControl
*)m_pWindow
);
2920 case ::com::sun::star::form::FormComponentType::COMBOBOX
:
2921 xController
= new ComboBoxCellController((ComboBoxControl
*)m_pWindow
);
2925 xController
= new ComboBoxCellController((ComboBoxControl
*)m_pWindow
);
2927 xController
= new EditCellController((Edit
*)m_pWindow
);
2932 //------------------------------------------------------------------------------
2933 void DbFilterField::updateFromModel( Reference
< XPropertySet
> _rxModel
)
2935 OSL_ENSURE( _rxModel
.is() && m_pWindow
, "DbFilterField::updateFromModel: invalid call!" );
2938 OSL_FAIL( "DbListBox::updateFromModel: not implemented yet (how the hell did you reach this?)!" );
2939 // TODO: implement this.
2940 // remember: updateFromModel should be some kind of opposite of commitControl
2943 //------------------------------------------------------------------------------
2944 sal_Bool
DbFilterField::commitControl()
2946 OUString
aText(m_aText
);
2947 switch (m_nControlClass
)
2949 case ::com::sun::star::form::FormComponentType::CHECKBOX
:
2951 case ::com::sun::star::form::FormComponentType::LISTBOX
:
2953 if (static_cast<ListBox
*>(m_pWindow
)->GetSelectEntryCount())
2955 sal_Int16 nPos
= (sal_Int16
)static_cast<ListBox
*>(m_pWindow
)->GetSelectEntryPos();
2956 if ( ( nPos
>= 0 ) && ( nPos
< m_aValueList
.getLength() ) )
2957 aText
= m_aValueList
.getConstArray()[nPos
];
2960 if (m_aText
!= aText
)
2963 m_aCommitLink
.Call(this);
2967 aText
= m_pWindow
->GetText();
2970 if (m_aText
!= aText
)
2972 // check the text with the SQL-Parser
2973 OUString
aNewText(comphelper::string::stripEnd(aText
, ' '));
2974 if (!aNewText
.isEmpty())
2977 Reference
< XNumberFormatter
> xNumberFormatter(m_rColumn
.GetParent().getNumberFormatter());
2979 ::rtl::Reference
< ISQLParseNode
> xParseNode
= predicateTree(aErrorMsg
, aNewText
,xNumberFormatter
, m_rColumn
.GetField());
2980 if (xParseNode
.is())
2982 OUString aPreparedText
;
2984 ::com::sun::star::lang::Locale aAppLocale
= Application::GetSettings().GetUILanguageTag().getLocale();
2986 Reference
< XRowSet
> xDataSourceRowSet(
2987 (Reference
< XInterface
>)*m_rColumn
.GetParent().getDataSource(), UNO_QUERY
);
2988 Reference
< XConnection
> xConnection(getRowSetConnection(xDataSourceRowSet
));
2990 xParseNode
->parseNodeToPredicateStr(aPreparedText
,
2993 m_rColumn
.GetField(),
2998 m_aText
= aPreparedText
;
3003 SQLException aError
;
3004 aError
.Message
= aErrorMsg
;
3005 displayException(aError
, m_pWindow
->GetParent());
3006 // TODO: transport the title
3014 m_pWindow
->SetText(m_aText
);
3015 m_aCommitLink
.Call(this);
3020 //------------------------------------------------------------------------------
3021 void DbFilterField::SetText(const OUString
& rText
)
3024 switch (m_nControlClass
)
3026 case ::com::sun::star::form::FormComponentType::CHECKBOX
:
3030 eState
= STATE_CHECK
;
3031 else if (rText
== "0")
3032 eState
= STATE_NOCHECK
;
3034 eState
= STATE_DONTKNOW
;
3036 ((CheckBoxControl
*)m_pWindow
)->GetBox().SetState(eState
);
3037 ((CheckBoxControl
*)m_pPainter
)->GetBox().SetState(eState
);
3039 case ::com::sun::star::form::FormComponentType::LISTBOX
:
3041 Sequence
<sal_Int16
> aPosSeq
= ::comphelper::findValue(m_aValueList
, m_aText
, sal_True
);
3042 if (aPosSeq
.getLength())
3043 static_cast<ListBox
*>(m_pWindow
)->SelectEntryPos(aPosSeq
.getConstArray()[0], sal_True
);
3045 static_cast<ListBox
*>(m_pWindow
)->SetNoSelection();
3048 m_pWindow
->SetText(m_aText
);
3051 // now force a repaint on the window
3052 m_rColumn
.GetParent().RowModified(0,m_rColumn
.GetId());
3055 //------------------------------------------------------------------------------
3056 void DbFilterField::Update()
3058 // should we fill the combobox with a filter proposal?
3059 if (m_bFilterList
&& !m_bFilterListFilled
)
3061 m_bFilterListFilled
= sal_True
;
3062 Reference
< ::com::sun::star::beans::XPropertySet
> xField
= m_rColumn
.GetField();
3067 xField
->getPropertyValue(FM_PROP_NAME
) >>= aName
;
3070 Reference
< ::com::sun::star::container::XChild
> xModelAsChild(m_rColumn
.getModel(), UNO_QUERY
);
3072 xModelAsChild
= Reference
< ::com::sun::star::container::XChild
> (xModelAsChild
->getParent(),UNO_QUERY
);
3073 Reference
< XRowSet
> xForm(xModelAsChild
->getParent(), UNO_QUERY
);
3077 Reference
<XPropertySet
> xFormProp(xForm
,UNO_QUERY
);
3078 Reference
< XTablesSupplier
> xSupTab
;
3079 xFormProp
->getPropertyValue(OUString("SingleSelectQueryComposer")) >>= xSupTab
;
3081 Reference
< XConnection
> xConnection(getRowSetConnection(xForm
));
3086 Reference
< XColumnsSupplier
> xSupCol(xSupTab
,UNO_QUERY
);
3087 Reference
< ::com::sun::star::container::XNameAccess
> xFieldNames
= xSupCol
->getColumns();
3088 if (!xFieldNames
->hasByName(aName
))
3091 Reference
< ::com::sun::star::container::XNameAccess
> xTablesNames
= xSupTab
->getTables();
3092 Reference
< ::com::sun::star::beans::XPropertySet
> xComposerFieldAsSet(xFieldNames
->getByName(aName
),UNO_QUERY
);
3094 if (xComposerFieldAsSet
.is() && ::comphelper::hasProperty(FM_PROP_TABLENAME
, xComposerFieldAsSet
) &&
3095 ::comphelper::hasProperty(FM_PROP_FIELDSOURCE
, xComposerFieldAsSet
))
3097 OUString aFieldName
;
3098 OUString aTableName
;
3099 xComposerFieldAsSet
->getPropertyValue(FM_PROP_FIELDSOURCE
) >>= aFieldName
;
3100 xComposerFieldAsSet
->getPropertyValue(FM_PROP_TABLENAME
) >>= aTableName
;
3102 // no possibility to create a select statement
3103 // looking for the complete table name
3104 if (!xTablesNames
->hasByName(aTableName
))
3107 // ein Statement aufbauen und abschicken als query
3108 // Access to the connection
3109 Reference
< XStatement
> xStatement
;
3110 Reference
< XResultSet
> xListCursor
;
3111 Reference
< ::com::sun::star::sdb::XColumn
> xDataField
;
3115 Reference
< XDatabaseMetaData
> xMeta
= xConnection
->getMetaData();
3117 OUString
aQuote(xMeta
->getIdentifierQuoteString());
3118 OUStringBuffer
aStatement("SELECT DISTINCT ");
3119 aStatement
.append(quoteName(aQuote
, aName
));
3120 if (!aFieldName
.isEmpty() && aName
!= aFieldName
)
3122 aStatement
.append(" AS ");
3123 aStatement
.append(quoteName(aQuote
, aFieldName
));
3126 aStatement
.append(" FROM ");
3128 Reference
< XPropertySet
> xTableNameAccess(xTablesNames
->getByName(aTableName
), UNO_QUERY_THROW
);
3129 aStatement
.append(composeTableNameForSelect(xConnection
, xTableNameAccess
));
3131 xStatement
= xConnection
->createStatement();
3132 Reference
< ::com::sun::star::beans::XPropertySet
> xStatementProps(xStatement
, UNO_QUERY
);
3133 xStatementProps
->setPropertyValue(FM_PROP_ESCAPE_PROCESSING
, makeAny((sal_Bool
)sal_True
));
3135 xListCursor
= xStatement
->executeQuery(aStatement
.makeStringAndClear());
3137 Reference
< ::com::sun::star::sdbcx::XColumnsSupplier
> xSupplyCols(xListCursor
, UNO_QUERY
);
3138 Reference
< ::com::sun::star::container::XIndexAccess
> xFields(xSupplyCols
->getColumns(), UNO_QUERY
);
3139 ::cppu::extractInterface(xDataField
, xFields
->getByIndex(0));
3140 if (!xDataField
.is())
3143 catch(const Exception
&)
3145 ::comphelper::disposeComponent(xStatement
);
3150 ::std::vector
< OUString
> aStringList
;
3151 aStringList
.reserve(16);
3153 com::sun::star::util::Date aNullDate
= m_rColumn
.GetParent().getNullDate();
3154 sal_Int32 nFormatKey
= m_rColumn
.GetKey();
3155 Reference
< XNumberFormatter
> xFormatter
= m_rColumn
.GetParent().getNumberFormatter();
3156 sal_Int16 nKeyType
= ::comphelper::getNumberFormatType(xFormatter
->getNumberFormatsSupplier()->getNumberFormats(), nFormatKey
);
3158 while (!xListCursor
->isAfterLast() && i
++ < SHRT_MAX
) // max anzahl eintraege
3160 aStr
= getFormattedValue(xDataField
, xFormatter
, aNullDate
, nFormatKey
, nKeyType
);
3161 aStringList
.push_back(aStr
);
3162 xListCursor
->next();
3165 // filling the entries for the combobox
3166 for (::std::vector
< OUString
>::const_iterator iter
= aStringList
.begin();
3167 iter
!= aStringList
.end(); ++iter
)
3168 ((ComboBox
*)m_pWindow
)->InsertEntry(*iter
, LISTBOX_APPEND
);
3173 //------------------------------------------------------------------------------
3174 OUString
DbFilterField::GetFormatText(const Reference
< XColumn
>& /*_rxField*/, const Reference
< XNumberFormatter
>& /*xFormatter*/, Color
** /*ppColor*/)
3179 //------------------------------------------------------------------
3180 void DbFilterField::UpdateFromField(const Reference
< XColumn
>& /*_rxField*/, const Reference
< XNumberFormatter
>& /*xFormatter*/)
3182 OSL_FAIL( "DbFilterField::UpdateFromField: cannot update a filter control from a field!" );
3185 //------------------------------------------------------------------
3186 IMPL_LINK_NOARG(DbFilterField
, OnClick
)
3188 TriState eState
= ((CheckBoxControl
*)m_pWindow
)->GetBox().GetState();
3199 case STATE_DONTKNOW
:
3203 if (m_aText
!= aText
)
3206 m_aCommitLink
.Call(this);
3211 /*************************************************************************/
3212 TYPEINIT0(FmXGridCell
);
3215 DBG_NAME(FmXGridCell
);
3216 //-----------------------------------------------------------------------------
3217 FmXGridCell::FmXGridCell( DbGridColumn
* pColumn
, DbCellControl
* _pControl
)
3218 :OComponentHelper(m_aMutex
)
3220 ,m_pCellControl( _pControl
)
3221 ,m_aWindowListeners( m_aMutex
)
3222 ,m_aFocusListeners( m_aMutex
)
3223 ,m_aKeyListeners( m_aMutex
)
3224 ,m_aMouseListeners( m_aMutex
)
3225 ,m_aMouseMotionListeners( m_aMutex
)
3227 DBG_CTOR(FmXGridCell
,NULL
);
3230 //-----------------------------------------------------------------------------
3231 void FmXGridCell::init()
3233 Window
* pEventWindow( getEventWindow() );
3235 pEventWindow
->AddEventListener( LINK( this, FmXGridCell
, OnWindowEvent
) );
3238 //-----------------------------------------------------------------------------
3239 Window
* FmXGridCell::getEventWindow() const
3241 if ( m_pCellControl
)
3242 return &m_pCellControl
->GetWindow();
3246 //-----------------------------------------------------------------------------
3247 FmXGridCell::~FmXGridCell()
3249 if (!OComponentHelper::rBHelper
.bDisposed
)
3255 DBG_DTOR(FmXGridCell
,NULL
);
3258 //------------------------------------------------------------------
3259 void FmXGridCell::SetTextLineColor()
3262 m_pCellControl
->SetTextLineColor();
3265 //------------------------------------------------------------------
3266 void FmXGridCell::SetTextLineColor(const Color
& _rColor
)
3269 m_pCellControl
->SetTextLineColor(_rColor
);
3273 //------------------------------------------------------------------
3274 Sequence
< Type
> SAL_CALL
FmXGridCell::getTypes( ) throw (RuntimeException
)
3276 Sequence
< uno::Type
> aTypes
= ::comphelper::concatSequences(
3277 ::cppu::OComponentHelper::getTypes(),
3278 FmXGridCell_Base::getTypes()
3280 if ( m_pCellControl
)
3281 aTypes
= ::comphelper::concatSequences(
3283 FmXGridCell_WindowBase::getTypes()
3288 //------------------------------------------------------------------
3289 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXGridCell
)
3292 //-----------------------------------------------------------------------------
3293 void FmXGridCell::disposing()
3295 lang::EventObject
aEvent( *this );
3296 m_aWindowListeners
.disposeAndClear( aEvent
);
3297 m_aFocusListeners
.disposeAndClear( aEvent
);
3298 m_aKeyListeners
.disposeAndClear( aEvent
);
3299 m_aMouseListeners
.disposeAndClear( aEvent
);
3300 m_aMouseMotionListeners
.disposeAndClear( aEvent
);
3302 OComponentHelper::disposing();
3304 DELETEZ(m_pCellControl
);
3307 //------------------------------------------------------------------
3308 Any SAL_CALL
FmXGridCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
3310 Any aReturn
= OComponentHelper::queryAggregation( _rType
);
3312 if ( !aReturn
.hasValue() )
3313 aReturn
= FmXGridCell_Base::queryInterface( _rType
);
3315 if ( !aReturn
.hasValue() && ( m_pCellControl
!= NULL
) )
3316 aReturn
= FmXGridCell_WindowBase::queryInterface( _rType
);
3321 // ::com::sun::star::awt::XControl
3322 //-----------------------------------------------------------------------------
3323 Reference
< XInterface
> FmXGridCell::getContext() throw( RuntimeException
)
3325 return Reference
< XInterface
> ();
3328 //-----------------------------------------------------------------------------
3329 Reference
< ::com::sun::star::awt::XControlModel
> FmXGridCell::getModel() throw( ::com::sun::star::uno::RuntimeException
)
3331 return Reference
< ::com::sun::star::awt::XControlModel
> (m_pColumn
->getModel(), UNO_QUERY
);
3334 // ::com::sun::star::form::XBoundControl
3335 //------------------------------------------------------------------
3336 sal_Bool
FmXGridCell::getLock() throw( RuntimeException
)
3338 return m_pColumn
->isLocked();
3341 //------------------------------------------------------------------
3342 void FmXGridCell::setLock(sal_Bool _bLock
) throw( RuntimeException
)
3344 if (getLock() == _bLock
)
3348 ::osl::MutexGuard
aGuard(m_aMutex
);
3349 m_pColumn
->setLock(_bLock
);
3353 //------------------------------------------------------------------
3354 void SAL_CALL
FmXGridCell::setPosSize( ::sal_Int32 _XX
, ::sal_Int32 _Y
, ::sal_Int32 _Width
, ::sal_Int32 _Height
, ::sal_Int16 _Flags
) throw (RuntimeException
)
3356 OSL_FAIL( "FmXGridCell::setPosSize: not implemented" );
3362 // not allowed to tamper with this for a grid cell
3365 //------------------------------------------------------------------
3366 awt::Rectangle SAL_CALL
FmXGridCell::getPosSize( ) throw (RuntimeException
)
3368 OSL_FAIL( "FmXGridCell::getPosSize: not implemented" );
3369 return awt::Rectangle();
3372 //------------------------------------------------------------------
3373 void SAL_CALL
FmXGridCell::setVisible( ::sal_Bool _Visible
) throw (RuntimeException
)
3375 OSL_FAIL( "FmXGridCell::setVisible: not implemented" );
3377 // not allowed to tamper with this for a grid cell
3380 //------------------------------------------------------------------
3381 void SAL_CALL
FmXGridCell::setEnable( ::sal_Bool _Enable
) throw (RuntimeException
)
3383 OSL_FAIL( "FmXGridCell::setEnable: not implemented" );
3385 // not allowed to tamper with this for a grid cell
3388 //------------------------------------------------------------------
3389 void SAL_CALL
FmXGridCell::setFocus( ) throw (RuntimeException
)
3391 OSL_FAIL( "FmXGridCell::setFocus: not implemented" );
3392 // not allowed to tamper with this for a grid cell
3395 //------------------------------------------------------------------
3396 void SAL_CALL
FmXGridCell::addWindowListener( const Reference
< awt::XWindowListener
>& _rxListener
) throw (RuntimeException
)
3398 m_aWindowListeners
.addInterface( _rxListener
);
3401 //------------------------------------------------------------------
3402 void SAL_CALL
FmXGridCell::removeWindowListener( const Reference
< awt::XWindowListener
>& _rxListener
) throw (RuntimeException
)
3404 m_aWindowListeners
.removeInterface( _rxListener
);
3407 //------------------------------------------------------------------
3408 void SAL_CALL
FmXGridCell::addFocusListener( const Reference
< awt::XFocusListener
>& _rxListener
) throw (RuntimeException
)
3410 m_aFocusListeners
.addInterface( _rxListener
);
3413 //------------------------------------------------------------------
3414 void SAL_CALL
FmXGridCell::removeFocusListener( const Reference
< awt::XFocusListener
>& _rxListener
) throw (RuntimeException
)
3416 m_aFocusListeners
.removeInterface( _rxListener
);
3419 //------------------------------------------------------------------
3420 void SAL_CALL
FmXGridCell::addKeyListener( const Reference
< awt::XKeyListener
>& _rxListener
) throw (RuntimeException
)
3422 m_aKeyListeners
.addInterface( _rxListener
);
3425 //------------------------------------------------------------------
3426 void SAL_CALL
FmXGridCell::removeKeyListener( const Reference
< awt::XKeyListener
>& _rxListener
) throw (RuntimeException
)
3428 m_aKeyListeners
.removeInterface( _rxListener
);
3431 //------------------------------------------------------------------
3432 void SAL_CALL
FmXGridCell::addMouseListener( const Reference
< awt::XMouseListener
>& _rxListener
) throw (RuntimeException
)
3434 m_aMouseListeners
.addInterface( _rxListener
);
3437 //------------------------------------------------------------------
3438 void SAL_CALL
FmXGridCell::removeMouseListener( const Reference
< awt::XMouseListener
>& _rxListener
) throw (RuntimeException
)
3440 m_aMouseListeners
.removeInterface( _rxListener
);
3443 //------------------------------------------------------------------
3444 void SAL_CALL
FmXGridCell::addMouseMotionListener( const Reference
< awt::XMouseMotionListener
>& _rxListener
) throw (RuntimeException
)
3446 m_aMouseMotionListeners
.addInterface( _rxListener
);
3449 //------------------------------------------------------------------
3450 void SAL_CALL
FmXGridCell::removeMouseMotionListener( const Reference
< awt::XMouseMotionListener
>& _rxListener
) throw (RuntimeException
)
3452 m_aMouseMotionListeners
.removeInterface( _rxListener
);
3455 //------------------------------------------------------------------
3456 void SAL_CALL
FmXGridCell::addPaintListener( const Reference
< awt::XPaintListener
>& _rxListener
) throw (RuntimeException
)
3458 OSL_FAIL( "FmXGridCell::addPaintListener: not implemented" );
3462 //------------------------------------------------------------------
3463 void SAL_CALL
FmXGridCell::removePaintListener( const Reference
< awt::XPaintListener
>& _rxListener
) throw (RuntimeException
)
3465 OSL_FAIL( "FmXGridCell::removePaintListener: not implemented" );
3469 //------------------------------------------------------------------
3470 IMPL_LINK( FmXGridCell
, OnWindowEvent
, VclWindowEvent
*, _pEvent
)
3472 ENSURE_OR_THROW( _pEvent
, "illegal event pointer" );
3473 ENSURE_OR_THROW( _pEvent
->GetWindow(), "illegal window" );
3474 onWindowEvent( _pEvent
->GetId(), *_pEvent
->GetWindow(), _pEvent
->GetData() );
3478 //------------------------------------------------------------------------------
3479 void FmXGridCell::onFocusGained( const awt::FocusEvent
& _rEvent
)
3481 m_aFocusListeners
.notifyEach( &awt::XFocusListener::focusGained
, _rEvent
);
3484 //------------------------------------------------------------------------------
3485 void FmXGridCell::onFocusLost( const awt::FocusEvent
& _rEvent
)
3487 m_aFocusListeners
.notifyEach( &awt::XFocusListener::focusLost
, _rEvent
);
3490 //------------------------------------------------------------------------------
3491 void FmXGridCell::onWindowEvent( const sal_uIntPtr _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
3493 switch ( _nEventId
)
3495 case VCLEVENT_CONTROL_GETFOCUS
:
3496 case VCLEVENT_WINDOW_GETFOCUS
:
3497 case VCLEVENT_CONTROL_LOSEFOCUS
:
3498 case VCLEVENT_WINDOW_LOSEFOCUS
:
3500 if ( ( _rWindow
.IsCompoundControl()
3501 && ( _nEventId
== VCLEVENT_CONTROL_GETFOCUS
3502 || _nEventId
== VCLEVENT_CONTROL_LOSEFOCUS
3505 || ( !_rWindow
.IsCompoundControl()
3506 && ( _nEventId
== VCLEVENT_WINDOW_GETFOCUS
3507 || _nEventId
== VCLEVENT_WINDOW_LOSEFOCUS
3512 if ( !m_aFocusListeners
.getLength() )
3515 bool bFocusGained
= ( _nEventId
== VCLEVENT_CONTROL_GETFOCUS
) || ( _nEventId
== VCLEVENT_WINDOW_GETFOCUS
);
3517 awt::FocusEvent aEvent
;
3518 aEvent
.Source
= *this;
3519 aEvent
.FocusFlags
= _rWindow
.GetGetFocusFlags();
3520 aEvent
.Temporary
= sal_False
;
3523 onFocusGained( aEvent
);
3525 onFocusLost( aEvent
);
3529 case VCLEVENT_WINDOW_MOUSEBUTTONDOWN
:
3530 case VCLEVENT_WINDOW_MOUSEBUTTONUP
:
3532 if ( !m_aMouseListeners
.getLength() )
3535 const bool bButtonDown
= ( _nEventId
== VCLEVENT_WINDOW_MOUSEBUTTONDOWN
);
3537 awt::MouseEvent
aEvent( VCLUnoHelper::createMouseEvent( *static_cast< const ::MouseEvent
* >( _pEventData
), *this ) );
3538 m_aMouseListeners
.notifyEach( bButtonDown
? &awt::XMouseListener::mousePressed
: &awt::XMouseListener::mouseReleased
, aEvent
);
3541 case VCLEVENT_WINDOW_MOUSEMOVE
:
3543 const MouseEvent
& rMouseEvent
= *static_cast< const ::MouseEvent
* >( _pEventData
);
3544 if ( rMouseEvent
.IsEnterWindow() || rMouseEvent
.IsLeaveWindow() )
3546 if ( m_aMouseListeners
.getLength() != 0 )
3548 awt::MouseEvent
aEvent( VCLUnoHelper::createMouseEvent( rMouseEvent
, *this ) );
3549 m_aMouseListeners
.notifyEach( rMouseEvent
.IsEnterWindow() ? &awt::XMouseListener::mouseEntered
: &awt::XMouseListener::mouseExited
, aEvent
);
3552 else if ( !rMouseEvent
.IsEnterWindow() && !rMouseEvent
.IsLeaveWindow() )
3554 if ( m_aMouseMotionListeners
.getLength() != 0 )
3556 awt::MouseEvent
aEvent( VCLUnoHelper::createMouseEvent( rMouseEvent
, *this ) );
3557 aEvent
.ClickCount
= 0;
3558 const bool bSimpleMove
= ( ( rMouseEvent
.GetMode() & MOUSE_SIMPLEMOVE
) != 0 );
3559 m_aMouseMotionListeners
.notifyEach( bSimpleMove
? &awt::XMouseMotionListener::mouseMoved
: &awt::XMouseMotionListener::mouseDragged
, aEvent
);
3564 case VCLEVENT_WINDOW_KEYINPUT
:
3565 case VCLEVENT_WINDOW_KEYUP
:
3567 if ( !m_aKeyListeners
.getLength() )
3570 const bool bKeyPressed
= ( _nEventId
== VCLEVENT_WINDOW_KEYINPUT
);
3571 awt::KeyEvent
aEvent( VCLUnoHelper::createKeyEvent( *static_cast< const ::KeyEvent
* >( _pEventData
), *this ) );
3572 m_aKeyListeners
.notifyEach( bKeyPressed
? &awt::XKeyListener::keyPressed
: &awt::XKeyListener::keyReleased
, aEvent
);
3578 /*************************************************************************/
3579 TYPEINIT1(FmXDataCell
, FmXGridCell
);
3580 //------------------------------------------------------------------------------
3581 void FmXDataCell::PaintFieldToCell(OutputDevice
& rDev
, const Rectangle
& rRect
,
3582 const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
,
3583 const Reference
< XNumberFormatter
>& xFormatter
)
3585 m_pCellControl
->PaintFieldToCell( rDev
, rRect
, _rxField
, xFormatter
);
3588 //------------------------------------------------------------------------------
3589 void FmXDataCell::UpdateFromColumn()
3591 Reference
< ::com::sun::star::sdb::XColumn
> xField(m_pColumn
->GetCurrentFieldValue());
3593 m_pCellControl
->UpdateFromField(xField
, m_pColumn
->GetParent().getNumberFormatter());
3596 /*************************************************************************/
3597 TYPEINIT1(FmXTextCell
, FmXDataCell
);
3599 FmXTextCell::FmXTextCell( DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
3600 :FmXDataCell( pColumn
, _rControl
)
3601 ,m_bFastPaint( sal_True
)
3605 //------------------------------------------------------------------------------
3606 void FmXTextCell::PaintFieldToCell(OutputDevice
& rDev
,
3607 const Rectangle
& rRect
,
3608 const Reference
< ::com::sun::star::sdb::XColumn
>& _rxField
,
3609 const Reference
< XNumberFormatter
>& xFormatter
)
3611 if ( !m_bFastPaint
)
3613 FmXDataCell::PaintFieldToCell( rDev
, rRect
, _rxField
, xFormatter
);
3617 sal_uInt16 nStyle
= TEXT_DRAW_CLIP
| TEXT_DRAW_VCENTER
;
3618 if ( ( rDev
.GetOutDevType() == OUTDEV_WINDOW
) && !static_cast< Window
& >( rDev
).IsEnabled() )
3619 nStyle
|= TEXT_DRAW_DISABLE
;
3621 switch (m_pColumn
->GetAlignment())
3623 case ::com::sun::star::awt::TextAlign::RIGHT
:
3624 nStyle
|= TEXT_DRAW_RIGHT
;
3626 case ::com::sun::star::awt::TextAlign::CENTER
:
3627 nStyle
|= TEXT_DRAW_CENTER
;
3630 nStyle
|= TEXT_DRAW_LEFT
;
3633 Color
* pColor
= NULL
;
3634 OUString aText
= GetText(_rxField
, xFormatter
, &pColor
);
3637 Color
aOldTextColor( rDev
.GetTextColor() );
3638 rDev
.SetTextColor( *pColor
);
3639 rDev
.DrawText(rRect
, aText
, nStyle
);
3640 rDev
.SetTextColor( aOldTextColor
);
3643 rDev
.DrawText(rRect
, aText
, nStyle
);
3647 /*************************************************************************/
3649 DBG_NAME(FmXEditCell
);
3650 //------------------------------------------------------------------------------
3651 FmXEditCell::FmXEditCell( DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
3652 :FmXTextCell( pColumn
, _rControl
)
3653 ,m_aTextListeners(m_aMutex
)
3654 ,m_aChangeListeners( m_aMutex
)
3655 ,m_pEditImplementation( NULL
)
3656 ,m_bOwnEditImplementation( false )
3658 DBG_CTOR(FmXEditCell
,NULL
);
3660 DbTextField
* pTextField
= PTR_CAST( DbTextField
, &_rControl
);
3664 m_pEditImplementation
= pTextField
->GetEditImplementation();
3665 if ( !pTextField
->IsSimpleEdit() )
3666 m_bFastPaint
= sal_False
;
3670 m_pEditImplementation
= new EditImplementation( static_cast< Edit
& >( _rControl
.GetWindow() ) );
3671 m_bOwnEditImplementation
= true;
3675 //------------------------------------------------------------------
3676 FmXEditCell::~FmXEditCell()
3678 if (!OComponentHelper::rBHelper
.bDisposed
)
3685 DBG_DTOR(FmXEditCell
,NULL
);
3689 //-----------------------------------------------------------------------------
3690 void FmXEditCell::disposing()
3692 ::com::sun::star::lang::EventObject
aEvt(*this);
3693 m_aTextListeners
.disposeAndClear(aEvt
);
3694 m_aChangeListeners
.disposeAndClear(aEvt
);
3696 m_pEditImplementation
->SetModifyHdl( Link() );
3697 if ( m_bOwnEditImplementation
)
3698 delete m_pEditImplementation
;
3699 m_pEditImplementation
= NULL
;
3701 FmXDataCell::disposing();
3704 //------------------------------------------------------------------
3705 Any SAL_CALL
FmXEditCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
3707 Any aReturn
= FmXTextCell::queryAggregation( _rType
);
3709 if ( !aReturn
.hasValue() )
3710 aReturn
= FmXEditCell_Base::queryInterface( _rType
);
3715 //-------------------------------------------------------------------------
3716 Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
FmXEditCell::getTypes( ) throw(RuntimeException
)
3718 return ::comphelper::concatSequences(
3719 FmXTextCell::getTypes(),
3720 FmXEditCell_Base::getTypes()
3724 //------------------------------------------------------------------------------
3725 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXEditCell
)
3727 // ::com::sun::star::awt::XTextComponent
3728 //------------------------------------------------------------------------------
3729 void SAL_CALL
FmXEditCell::addTextListener(const Reference
< ::com::sun::star::awt::XTextListener
>& l
) throw( RuntimeException
)
3731 m_aTextListeners
.addInterface( l
);
3734 //------------------------------------------------------------------------------
3735 void SAL_CALL
FmXEditCell::removeTextListener(const Reference
< ::com::sun::star::awt::XTextListener
>& l
) throw( RuntimeException
)
3737 m_aTextListeners
.removeInterface( l
);
3740 //------------------------------------------------------------------------------
3741 void SAL_CALL
FmXEditCell::setText( const OUString
& aText
) throw( RuntimeException
)
3743 ::osl::MutexGuard
aGuard( m_aMutex
);
3745 if ( m_pEditImplementation
)
3747 m_pEditImplementation
->SetText( aText
);
3749 // In JAVA wird auch ein textChanged ausgeloest, in VCL nicht.
3750 // ::com::sun::star::awt::Toolkit soll JAVA-komform sein...
3755 //------------------------------------------------------------------------------
3756 void SAL_CALL
FmXEditCell::insertText(const ::com::sun::star::awt::Selection
& rSel
, const OUString
& aText
) throw(RuntimeException
)
3758 ::osl::MutexGuard
aGuard( m_aMutex
);
3760 if ( m_pEditImplementation
)
3762 m_pEditImplementation
->SetSelection( Selection( rSel
.Min
, rSel
.Max
) );
3763 m_pEditImplementation
->ReplaceSelected( aText
);
3767 //------------------------------------------------------------------------------
3768 OUString SAL_CALL
FmXEditCell::getText() throw( RuntimeException
)
3770 ::osl::MutexGuard
aGuard( m_aMutex
);
3773 if ( m_pEditImplementation
)
3775 if ( m_pEditImplementation
->GetControl().IsVisible() && m_pColumn
->GetParent().getDisplaySynchron())
3777 // if the display isn't sync with the cursor we can't ask the edit field
3778 LineEnd eLineEndFormat
= m_pColumn
? getModelLineEndSetting( m_pColumn
->getModel() ) : LINEEND_LF
;
3779 aText
= m_pEditImplementation
->GetText( eLineEndFormat
);
3783 Reference
< ::com::sun::star::sdb::XColumn
> xField(m_pColumn
->GetCurrentFieldValue());
3785 aText
= GetText(xField
, m_pColumn
->GetParent().getNumberFormatter());
3791 //------------------------------------------------------------------------------
3792 OUString SAL_CALL
FmXEditCell::getSelectedText( void ) throw( RuntimeException
)
3794 ::osl::MutexGuard
aGuard( m_aMutex
);
3797 if ( m_pEditImplementation
)
3799 LineEnd eLineEndFormat
= m_pColumn
? getModelLineEndSetting( m_pColumn
->getModel() ) : LINEEND_LF
;
3800 aText
= m_pEditImplementation
->GetSelected( eLineEndFormat
);
3805 //------------------------------------------------------------------------------
3806 void SAL_CALL
FmXEditCell::setSelection( const ::com::sun::star::awt::Selection
& aSelection
) throw( RuntimeException
)
3808 ::osl::MutexGuard
aGuard( m_aMutex
);
3810 if ( m_pEditImplementation
)
3811 m_pEditImplementation
->SetSelection( Selection( aSelection
.Min
, aSelection
.Max
) );
3814 //------------------------------------------------------------------------------
3815 ::com::sun::star::awt::Selection SAL_CALL
FmXEditCell::getSelection( void ) throw( RuntimeException
)
3817 ::osl::MutexGuard
aGuard( m_aMutex
);
3820 if ( m_pEditImplementation
)
3821 aSel
= m_pEditImplementation
->GetSelection();
3823 return ::com::sun::star::awt::Selection(aSel
.Min(), aSel
.Max());
3826 //------------------------------------------------------------------------------
3827 sal_Bool SAL_CALL
FmXEditCell::isEditable( void ) throw( RuntimeException
)
3829 ::osl::MutexGuard
aGuard( m_aMutex
);
3831 return ( m_pEditImplementation
&& !m_pEditImplementation
->IsReadOnly() && m_pEditImplementation
->GetControl().IsEnabled() ) ? sal_True
: sal_False
;
3834 //------------------------------------------------------------------------------
3835 void SAL_CALL
FmXEditCell::setEditable( sal_Bool bEditable
) throw( RuntimeException
)
3837 ::osl::MutexGuard
aGuard( m_aMutex
);
3839 if ( m_pEditImplementation
)
3840 m_pEditImplementation
->SetReadOnly( !bEditable
);
3843 //------------------------------------------------------------------------------
3844 sal_Int16 SAL_CALL
FmXEditCell::getMaxTextLen() throw( RuntimeException
)
3846 ::osl::MutexGuard
aGuard( m_aMutex
);
3848 return m_pEditImplementation
? m_pEditImplementation
->GetMaxTextLen() : 0;
3851 //------------------------------------------------------------------------------
3852 void SAL_CALL
FmXEditCell::setMaxTextLen( sal_Int16 nLen
) throw( RuntimeException
)
3854 ::osl::MutexGuard
aGuard( m_aMutex
);
3856 if ( m_pEditImplementation
)
3857 m_pEditImplementation
->SetMaxTextLen( nLen
);
3860 //------------------------------------------------------------------------------
3861 void SAL_CALL
FmXEditCell::addChangeListener( const Reference
< form::XChangeListener
>& _Listener
) throw (RuntimeException
)
3863 m_aChangeListeners
.addInterface( _Listener
);
3866 //------------------------------------------------------------------------------
3867 void SAL_CALL
FmXEditCell::removeChangeListener( const Reference
< form::XChangeListener
>& _Listener
) throw (RuntimeException
)
3869 m_aChangeListeners
.removeInterface( _Listener
);
3872 //------------------------------------------------------------------------------
3873 void FmXEditCell::onTextChanged()
3875 ::com::sun::star::awt::TextEvent aEvent
;
3876 aEvent
.Source
= *this;
3877 m_aTextListeners
.notifyEach( &awt::XTextListener::textChanged
, aEvent
);
3880 //------------------------------------------------------------------------------
3881 void FmXEditCell::onFocusGained( const awt::FocusEvent
& _rEvent
)
3883 FmXTextCell::onFocusGained( _rEvent
);
3884 m_sValueOnEnter
= getText();
3887 //------------------------------------------------------------------------------
3888 void FmXEditCell::onFocusLost( const awt::FocusEvent
& _rEvent
)
3890 FmXTextCell::onFocusLost( _rEvent
);
3892 if ( getText() != m_sValueOnEnter
)
3894 lang::EventObject
aEvent( *this );
3895 m_aChangeListeners
.notifyEach( &XChangeListener::changed
, aEvent
);
3899 //------------------------------------------------------------------------------
3900 void FmXEditCell::onWindowEvent( const sal_uIntPtr _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
3902 switch ( _nEventId
)
3904 case VCLEVENT_EDIT_MODIFY
:
3906 if ( m_pEditImplementation
&& m_aTextListeners
.getLength() )
3912 FmXTextCell::onWindowEvent( _nEventId
, _rWindow
, _pEventData
);
3915 /*************************************************************************/
3916 DBG_NAME(FmXCheckBoxCell
);
3917 //------------------------------------------------------------------------------
3918 FmXCheckBoxCell::FmXCheckBoxCell( DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
3919 :FmXDataCell( pColumn
, _rControl
)
3920 ,m_aItemListeners(m_aMutex
)
3921 ,m_aActionListeners( m_aMutex
)
3922 ,m_pBox( & static_cast< CheckBoxControl
& >( _rControl
.GetWindow() ).GetBox() )
3924 DBG_CTOR(FmXCheckBoxCell
,NULL
);
3927 //------------------------------------------------------------------
3928 FmXCheckBoxCell::~FmXCheckBoxCell()
3930 if (!OComponentHelper::rBHelper
.bDisposed
)
3936 DBG_DTOR(FmXCheckBoxCell
,NULL
);
3940 //-----------------------------------------------------------------------------
3941 void FmXCheckBoxCell::disposing()
3943 ::com::sun::star::lang::EventObject
aEvt(*this);
3944 m_aItemListeners
.disposeAndClear(aEvt
);
3945 m_aActionListeners
.disposeAndClear(aEvt
);
3947 static_cast< CheckBoxControl
& >( m_pCellControl
->GetWindow() ).SetClickHdl(Link());
3950 FmXDataCell::disposing();
3953 //------------------------------------------------------------------
3954 Any SAL_CALL
FmXCheckBoxCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
3956 Any aReturn
= FmXDataCell::queryAggregation( _rType
);
3958 if ( !aReturn
.hasValue() )
3959 aReturn
= FmXCheckBoxCell_Base::queryInterface( _rType
);
3964 //-------------------------------------------------------------------------
3965 Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
FmXCheckBoxCell::getTypes( ) throw(RuntimeException
)
3967 return ::comphelper::concatSequences(
3968 FmXDataCell::getTypes(),
3969 FmXCheckBoxCell_Base::getTypes()
3973 //------------------------------------------------------------------------------
3974 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXCheckBoxCell
)
3976 //------------------------------------------------------------------
3977 void SAL_CALL
FmXCheckBoxCell::addItemListener( const Reference
< ::com::sun::star::awt::XItemListener
>& l
) throw( RuntimeException
)
3979 m_aItemListeners
.addInterface( l
);
3982 //------------------------------------------------------------------
3983 void SAL_CALL
FmXCheckBoxCell::removeItemListener( const Reference
< ::com::sun::star::awt::XItemListener
>& l
) throw( RuntimeException
)
3985 m_aItemListeners
.removeInterface( l
);
3988 //------------------------------------------------------------------
3989 void SAL_CALL
FmXCheckBoxCell::setState( short n
) throw( RuntimeException
)
3991 ::osl::MutexGuard
aGuard( m_aMutex
);
3996 m_pBox
->SetState( (TriState
)n
);
4000 //------------------------------------------------------------------
4001 short SAL_CALL
FmXCheckBoxCell::getState() throw( RuntimeException
)
4003 ::osl::MutexGuard
aGuard( m_aMutex
);
4008 return (short)m_pBox
->GetState();
4010 return STATE_DONTKNOW
;
4013 //------------------------------------------------------------------
4014 void SAL_CALL
FmXCheckBoxCell::enableTriState( sal_Bool b
) throw( RuntimeException
)
4016 ::osl::MutexGuard
aGuard( m_aMutex
);
4019 m_pBox
->EnableTriState( b
);
4022 //------------------------------------------------------------------
4023 void SAL_CALL
FmXCheckBoxCell::addActionListener( const Reference
< awt::XActionListener
>& _Listener
) throw (RuntimeException
)
4025 m_aActionListeners
.addInterface( _Listener
);
4028 //------------------------------------------------------------------
4029 void SAL_CALL
FmXCheckBoxCell::removeActionListener( const Reference
< awt::XActionListener
>& _Listener
) throw (RuntimeException
)
4031 m_aActionListeners
.removeInterface( _Listener
);
4034 //------------------------------------------------------------------
4035 void SAL_CALL
FmXCheckBoxCell::setLabel( const OUString
& _Label
) throw (RuntimeException
)
4037 SolarMutexGuard aGuard
;
4040 DbGridControl
& rGrid( m_pColumn
->GetParent() );
4041 rGrid
.SetColumnTitle( rGrid
.GetColumnId( m_pColumn
->GetFieldPos() ), _Label
);
4045 //------------------------------------------------------------------
4046 void SAL_CALL
FmXCheckBoxCell::setActionCommand( const OUString
& _Command
) throw (RuntimeException
)
4048 m_aActionCommand
= _Command
;
4051 //------------------------------------------------------------------
4052 Window
* FmXCheckBoxCell::getEventWindow() const
4057 //------------------------------------------------------------------
4058 void FmXCheckBoxCell::onWindowEvent( const sal_uIntPtr _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
4060 switch ( _nEventId
)
4062 case VCLEVENT_CHECKBOX_TOGGLE
:
4064 // check boxes are to be committed immediately (this holds for ordinary check box controls in
4065 // documents, and this must hold for check boxes in grid columns, too
4066 // 91210 - 22.08.2001 - frank.schoenheit@sun.com
4067 m_pCellControl
->Commit();
4069 Reference
< XWindow
> xKeepAlive( this );
4070 if ( m_aItemListeners
.getLength() && m_pBox
)
4072 awt::ItemEvent aEvent
;
4073 aEvent
.Source
= *this;
4074 aEvent
.Highlighted
= sal_False
;
4075 aEvent
.Selected
= m_pBox
->GetState();
4076 m_aItemListeners
.notifyEach( &awt::XItemListener::itemStateChanged
, aEvent
);
4078 if ( m_aActionListeners
.getLength() )
4080 awt::ActionEvent aEvent
;
4081 aEvent
.Source
= *this;
4082 aEvent
.ActionCommand
= m_aActionCommand
;
4083 m_aActionListeners
.notifyEach( &awt::XActionListener::actionPerformed
, aEvent
);
4089 FmXDataCell::onWindowEvent( _nEventId
, _rWindow
, _pEventData
);
4094 /*************************************************************************/
4096 DBG_NAME(FmXListBoxCell
);
4097 //------------------------------------------------------------------------------
4098 FmXListBoxCell::FmXListBoxCell(DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
4099 :FmXTextCell( pColumn
, _rControl
)
4100 ,m_aItemListeners(m_aMutex
)
4101 ,m_aActionListeners(m_aMutex
)
4102 ,m_pBox( &static_cast< ListBox
& >( _rControl
.GetWindow() ) )
4104 DBG_CTOR(FmXListBoxCell
,NULL
);
4106 m_pBox
->SetDoubleClickHdl( LINK( this, FmXListBoxCell
, OnDoubleClick
) );
4109 //------------------------------------------------------------------
4110 FmXListBoxCell::~FmXListBoxCell()
4112 if (!OComponentHelper::rBHelper
.bDisposed
)
4118 DBG_DTOR(FmXListBoxCell
,NULL
);
4122 //-----------------------------------------------------------------------------
4123 void FmXListBoxCell::disposing()
4125 ::com::sun::star::lang::EventObject
aEvt(*this);
4126 m_aItemListeners
.disposeAndClear(aEvt
);
4127 m_aActionListeners
.disposeAndClear(aEvt
);
4129 m_pBox
->SetSelectHdl( Link() );
4130 m_pBox
->SetDoubleClickHdl( Link() );
4133 FmXTextCell::disposing();
4136 //------------------------------------------------------------------
4137 Any SAL_CALL
FmXListBoxCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
4139 Any aReturn
= FmXTextCell::queryAggregation(_rType
);
4141 if ( !aReturn
.hasValue() )
4142 aReturn
= FmXListBoxCell_Base::queryInterface( _rType
);
4147 //-------------------------------------------------------------------------
4148 Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
FmXListBoxCell::getTypes( ) throw(RuntimeException
)
4150 return ::comphelper::concatSequences(
4151 FmXTextCell::getTypes(),
4152 FmXListBoxCell_Base::getTypes()
4156 //------------------------------------------------------------------------------
4157 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXListBoxCell
)
4159 //------------------------------------------------------------------
4160 void SAL_CALL
FmXListBoxCell::addItemListener(const Reference
< ::com::sun::star::awt::XItemListener
>& l
) throw( RuntimeException
)
4162 m_aItemListeners
.addInterface( l
);
4165 //------------------------------------------------------------------
4166 void SAL_CALL
FmXListBoxCell::removeItemListener(const Reference
< ::com::sun::star::awt::XItemListener
>& l
) throw( RuntimeException
)
4168 m_aItemListeners
.removeInterface( l
);
4171 //------------------------------------------------------------------
4172 void SAL_CALL
FmXListBoxCell::addActionListener(const Reference
< ::com::sun::star::awt::XActionListener
>& l
) throw( RuntimeException
)
4174 m_aActionListeners
.addInterface( l
);
4177 //------------------------------------------------------------------
4178 void SAL_CALL
FmXListBoxCell::removeActionListener(const Reference
< ::com::sun::star::awt::XActionListener
>& l
) throw( RuntimeException
)
4180 m_aActionListeners
.removeInterface( l
);
4183 //------------------------------------------------------------------
4184 void SAL_CALL
FmXListBoxCell::addItem(const OUString
& aItem
, sal_Int16 nPos
) throw( RuntimeException
)
4186 ::osl::MutexGuard
aGuard( m_aMutex
);
4188 m_pBox
->InsertEntry( aItem
, nPos
);
4191 //------------------------------------------------------------------
4192 void SAL_CALL
FmXListBoxCell::addItems(const ::comphelper::StringSequence
& aItems
, sal_Int16 nPos
) throw( RuntimeException
)
4194 ::osl::MutexGuard
aGuard( m_aMutex
);
4197 sal_uInt16 nP
= nPos
;
4198 for ( sal_uInt16 n
= 0; n
< aItems
.getLength(); n
++ )
4200 m_pBox
->InsertEntry( aItems
.getConstArray()[n
], nP
);
4201 if ( nPos
!= -1 ) // Nicht wenn 0xFFFF, weil LIST_APPEND
4207 //------------------------------------------------------------------
4208 void SAL_CALL
FmXListBoxCell::removeItems(sal_Int16 nPos
, sal_Int16 nCount
) throw( RuntimeException
)
4210 ::osl::MutexGuard
aGuard( m_aMutex
);
4213 for ( sal_uInt16 n
= nCount
; n
; )
4214 m_pBox
->RemoveEntry( nPos
+ (--n
) );
4218 //------------------------------------------------------------------
4219 sal_Int16 SAL_CALL
FmXListBoxCell::getItemCount() throw( RuntimeException
)
4221 ::osl::MutexGuard
aGuard( m_aMutex
);
4222 return m_pBox
? m_pBox
->GetEntryCount() : 0;
4225 //------------------------------------------------------------------
4226 OUString SAL_CALL
FmXListBoxCell::getItem(sal_Int16 nPos
) throw( RuntimeException
)
4228 ::osl::MutexGuard
aGuard( m_aMutex
);
4229 return m_pBox
? OUString(m_pBox
->GetEntry(nPos
)) : OUString();
4231 //------------------------------------------------------------------
4232 ::comphelper::StringSequence SAL_CALL
FmXListBoxCell::getItems() throw( RuntimeException
)
4234 ::osl::MutexGuard
aGuard( m_aMutex
);
4236 ::comphelper::StringSequence aSeq
;
4239 sal_uInt16 nEntries
= m_pBox
->GetEntryCount();
4240 aSeq
= ::comphelper::StringSequence( nEntries
);
4241 for ( sal_uInt16 n
= nEntries
; n
; )
4244 aSeq
.getArray()[n
] = m_pBox
->GetEntry( n
);
4250 //------------------------------------------------------------------
4251 sal_Int16 SAL_CALL
FmXListBoxCell::getSelectedItemPos() throw( RuntimeException
)
4253 ::osl::MutexGuard
aGuard( m_aMutex
);
4257 return m_pBox
->GetSelectEntryPos();
4262 //------------------------------------------------------------------
4263 Sequence
< sal_Int16
> SAL_CALL
FmXListBoxCell::getSelectedItemsPos() throw( RuntimeException
)
4265 ::osl::MutexGuard
aGuard( m_aMutex
);
4266 Sequence
<sal_Int16
> aSeq
;
4271 sal_uInt16 nSelEntries
= m_pBox
->GetSelectEntryCount();
4272 aSeq
= Sequence
<sal_Int16
>( nSelEntries
);
4273 for ( sal_uInt16 n
= 0; n
< nSelEntries
; n
++ )
4274 aSeq
.getArray()[n
] = m_pBox
->GetSelectEntryPos( n
);
4278 //------------------------------------------------------------------
4279 OUString SAL_CALL
FmXListBoxCell::getSelectedItem() throw( RuntimeException
)
4281 ::osl::MutexGuard
aGuard( m_aMutex
);
4288 aItem
= m_pBox
->GetSelectEntry();
4294 //------------------------------------------------------------------
4295 ::comphelper::StringSequence SAL_CALL
FmXListBoxCell::getSelectedItems() throw( RuntimeException
)
4297 ::osl::MutexGuard
aGuard( m_aMutex
);
4299 ::comphelper::StringSequence aSeq
;
4304 sal_uInt16 nSelEntries
= m_pBox
->GetSelectEntryCount();
4305 aSeq
= ::comphelper::StringSequence( nSelEntries
);
4306 for ( sal_uInt16 n
= 0; n
< nSelEntries
; n
++ )
4307 aSeq
.getArray()[n
] = m_pBox
->GetSelectEntry( n
);
4312 //------------------------------------------------------------------
4313 void SAL_CALL
FmXListBoxCell::selectItemPos(sal_Int16 nPos
, sal_Bool bSelect
) throw( RuntimeException
)
4315 ::osl::MutexGuard
aGuard( m_aMutex
);
4318 m_pBox
->SelectEntryPos( nPos
, bSelect
);
4321 //------------------------------------------------------------------
4322 void SAL_CALL
FmXListBoxCell::selectItemsPos(const Sequence
< sal_Int16
>& aPositions
, sal_Bool bSelect
) throw( RuntimeException
)
4324 ::osl::MutexGuard
aGuard( m_aMutex
);
4328 for ( sal_uInt16 n
= (sal_uInt16
)aPositions
.getLength(); n
; )
4329 m_pBox
->SelectEntryPos( (sal_uInt16
) aPositions
.getConstArray()[--n
], bSelect
);
4333 //------------------------------------------------------------------
4334 void SAL_CALL
FmXListBoxCell::selectItem(const OUString
& aItem
, sal_Bool bSelect
) throw( RuntimeException
)
4336 ::osl::MutexGuard
aGuard( m_aMutex
);
4339 m_pBox
->SelectEntry( aItem
, bSelect
);
4342 //------------------------------------------------------------------
4343 sal_Bool SAL_CALL
FmXListBoxCell::isMutipleMode() throw( RuntimeException
)
4345 ::osl::MutexGuard
aGuard( m_aMutex
);
4347 sal_Bool bMulti
= sal_False
;
4349 bMulti
= m_pBox
->IsMultiSelectionEnabled();
4353 //------------------------------------------------------------------
4354 void SAL_CALL
FmXListBoxCell::setMultipleMode(sal_Bool bMulti
) throw( RuntimeException
)
4356 ::osl::MutexGuard
aGuard( m_aMutex
);
4359 m_pBox
->EnableMultiSelection( bMulti
);
4362 //------------------------------------------------------------------
4363 sal_Int16 SAL_CALL
FmXListBoxCell::getDropDownLineCount() throw( RuntimeException
)
4365 ::osl::MutexGuard
aGuard( m_aMutex
);
4367 sal_Int16 nLines
= 0;
4369 nLines
= m_pBox
->GetDropDownLineCount();
4374 //------------------------------------------------------------------
4375 void SAL_CALL
FmXListBoxCell::setDropDownLineCount(sal_Int16 nLines
) throw( RuntimeException
)
4377 ::osl::MutexGuard
aGuard( m_aMutex
);
4380 m_pBox
->SetDropDownLineCount( nLines
);
4383 //------------------------------------------------------------------
4384 void SAL_CALL
FmXListBoxCell::makeVisible(sal_Int16 nEntry
) throw( RuntimeException
)
4386 ::osl::MutexGuard
aGuard( m_aMutex
);
4389 m_pBox
->SetTopEntry( nEntry
);
4392 //------------------------------------------------------------------
4393 void FmXListBoxCell::onWindowEvent( const sal_uIntPtr _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
4395 if ( ( &_rWindow
== m_pBox
)
4396 && ( _nEventId
== VCLEVENT_LISTBOX_SELECT
)
4399 OnDoubleClick( NULL
);
4401 ::com::sun::star::awt::ItemEvent aEvent
;
4402 aEvent
.Source
= *this;
4403 aEvent
.Highlighted
= sal_False
;
4405 // Bei Mehrfachselektion 0xFFFF, sonst die ID
4406 aEvent
.Selected
= (m_pBox
->GetSelectEntryCount() == 1 )
4407 ? m_pBox
->GetSelectEntryPos() : 0xFFFF;
4409 m_aItemListeners
.notifyEach( &awt::XItemListener::itemStateChanged
, aEvent
);
4413 FmXTextCell::onWindowEvent( _nEventId
, _rWindow
, _pEventData
);
4417 //------------------------------------------------------------------
4418 IMPL_LINK_NOARG(FmXListBoxCell
, OnDoubleClick
)
4422 ::cppu::OInterfaceIteratorHelper
aIt( m_aActionListeners
);
4424 ::com::sun::star::awt::ActionEvent aEvent
;
4425 aEvent
.Source
= *this;
4426 aEvent
.ActionCommand
= m_pBox
->GetSelectEntry();
4428 while( aIt
.hasMoreElements() )
4429 ((::com::sun::star::awt::XActionListener
*)aIt
.next())->actionPerformed( aEvent
);
4435 /*************************************************************************/
4437 DBG_NAME( FmXComboBoxCell
);
4439 //------------------------------------------------------------------------------
4440 FmXComboBoxCell::FmXComboBoxCell( DbGridColumn
* pColumn
, DbCellControl
& _rControl
)
4441 :FmXTextCell( pColumn
, _rControl
)
4442 ,m_aItemListeners( m_aMutex
)
4443 ,m_aActionListeners( m_aMutex
)
4444 ,m_pComboBox( &static_cast< ComboBox
& >( _rControl
.GetWindow() ) )
4446 DBG_CTOR( FmXComboBoxCell
, NULL
);
4449 //------------------------------------------------------------------------------
4450 FmXComboBoxCell::~FmXComboBoxCell()
4452 if ( !OComponentHelper::rBHelper
.bDisposed
)
4458 DBG_DTOR( FmXComboBoxCell
, NULL
);
4461 //-----------------------------------------------------------------------------
4462 void FmXComboBoxCell::disposing()
4464 ::com::sun::star::lang::EventObject
aEvt(*this);
4465 m_aItemListeners
.disposeAndClear(aEvt
);
4466 m_aActionListeners
.disposeAndClear(aEvt
);
4468 FmXTextCell::disposing();
4471 //------------------------------------------------------------------
4472 Any SAL_CALL
FmXComboBoxCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
4474 Any aReturn
= FmXTextCell::queryAggregation(_rType
);
4476 if ( !aReturn
.hasValue() )
4477 aReturn
= FmXComboBoxCell_Base::queryInterface( _rType
);
4482 //-------------------------------------------------------------------------
4483 Sequence
< Type
> SAL_CALL
FmXComboBoxCell::getTypes( ) throw(RuntimeException
)
4485 return ::comphelper::concatSequences(
4486 FmXTextCell::getTypes(),
4487 FmXComboBoxCell_Base::getTypes()
4491 //------------------------------------------------------------------------------
4492 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXComboBoxCell
)
4494 //------------------------------------------------------------------
4495 void SAL_CALL
FmXComboBoxCell::addItemListener(const Reference
< awt::XItemListener
>& l
) throw( RuntimeException
)
4497 m_aItemListeners
.addInterface( l
);
4500 //------------------------------------------------------------------
4501 void SAL_CALL
FmXComboBoxCell::removeItemListener(const Reference
< awt::XItemListener
>& l
) throw( RuntimeException
)
4503 m_aItemListeners
.removeInterface( l
);
4506 //------------------------------------------------------------------
4507 void SAL_CALL
FmXComboBoxCell::addActionListener(const Reference
< awt::XActionListener
>& l
) throw( RuntimeException
)
4509 m_aActionListeners
.addInterface( l
);
4512 //------------------------------------------------------------------
4513 void SAL_CALL
FmXComboBoxCell::removeActionListener(const Reference
< awt::XActionListener
>& l
) throw( RuntimeException
)
4515 m_aActionListeners
.removeInterface( l
);
4518 //------------------------------------------------------------------
4519 void SAL_CALL
FmXComboBoxCell::addItem( const OUString
& _Item
, sal_Int16 _Pos
) throw( RuntimeException
)
4521 ::osl::MutexGuard
aGuard( m_aMutex
);
4523 m_pComboBox
->InsertEntry( _Item
, _Pos
);
4526 //------------------------------------------------------------------
4527 void SAL_CALL
FmXComboBoxCell::addItems( const Sequence
< OUString
>& _Items
, sal_Int16 _Pos
) throw( RuntimeException
)
4529 ::osl::MutexGuard
aGuard( m_aMutex
);
4532 sal_uInt16 nP
= _Pos
;
4533 for ( sal_uInt16 n
= 0; n
< _Items
.getLength(); n
++ )
4535 m_pComboBox
->InsertEntry( _Items
.getConstArray()[n
], nP
);
4542 //------------------------------------------------------------------
4543 void SAL_CALL
FmXComboBoxCell::removeItems( sal_Int16 _Pos
, sal_Int16 _Count
) throw( RuntimeException
)
4545 ::osl::MutexGuard
aGuard( m_aMutex
);
4548 for ( sal_uInt16 n
= _Count
; n
; )
4549 m_pComboBox
->RemoveEntry( _Pos
+ (--n
) );
4553 //------------------------------------------------------------------
4554 sal_Int16 SAL_CALL
FmXComboBoxCell::getItemCount() throw( RuntimeException
)
4556 ::osl::MutexGuard
aGuard( m_aMutex
);
4557 return m_pComboBox
? m_pComboBox
->GetEntryCount() : 0;
4560 //------------------------------------------------------------------
4561 OUString SAL_CALL
FmXComboBoxCell::getItem( sal_Int16 _Pos
) throw( RuntimeException
)
4563 ::osl::MutexGuard
aGuard( m_aMutex
);
4564 return m_pComboBox
? OUString(m_pComboBox
->GetEntry(_Pos
)) : OUString();
4566 //------------------------------------------------------------------
4567 Sequence
< OUString
> SAL_CALL
FmXComboBoxCell::getItems() throw( RuntimeException
)
4569 ::osl::MutexGuard
aGuard( m_aMutex
);
4571 Sequence
< OUString
> aItems
;
4574 sal_uInt16 nEntries
= m_pComboBox
->GetEntryCount();
4575 aItems
.realloc( nEntries
);
4576 OUString
* pItem
= aItems
.getArray();
4577 for ( sal_uInt16 n
=0; n
<nEntries
; ++n
, ++pItem
)
4578 *pItem
= m_pComboBox
->GetEntry( n
);
4583 //------------------------------------------------------------------
4584 sal_Int16 SAL_CALL
FmXComboBoxCell::getDropDownLineCount() throw( RuntimeException
)
4586 ::osl::MutexGuard
aGuard( m_aMutex
);
4588 sal_Int16 nLines
= 0;
4590 nLines
= m_pComboBox
->GetDropDownLineCount();
4595 //------------------------------------------------------------------
4596 void SAL_CALL
FmXComboBoxCell::setDropDownLineCount(sal_Int16 nLines
) throw( RuntimeException
)
4598 ::osl::MutexGuard
aGuard( m_aMutex
);
4600 m_pComboBox
->SetDropDownLineCount( nLines
);
4603 //------------------------------------------------------------------------------
4604 void FmXComboBoxCell::onWindowEvent( const sal_uIntPtr _nEventId
, const Window
& _rWindow
, const void* _pEventData
)
4607 switch ( _nEventId
)
4609 case VCLEVENT_COMBOBOX_SELECT
:
4611 awt::ItemEvent aEvent
;
4612 aEvent
.Source
= *this;
4613 aEvent
.Highlighted
= sal_False
;
4615 // Bei Mehrfachselektion 0xFFFF, sonst die ID
4616 aEvent
.Selected
= ( m_pComboBox
->GetSelectEntryCount() == 1 )
4617 ? m_pComboBox
->GetSelectEntryPos()
4619 m_aItemListeners
.notifyEach( &awt::XItemListener::itemStateChanged
, aEvent
);
4624 FmXTextCell::onWindowEvent( _nEventId
, _rWindow
, _pEventData
);
4629 /*************************************************************************/
4630 TYPEINIT1(FmXFilterCell
, FmXGridCell
);
4632 //------------------------------------------------------------------------------
4633 Reference
< XInterface
> FmXFilterCell_CreateInstance(const Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& /*_rxFactory*/)
4635 return *new FmXFilterCell();
4638 DBG_NAME(FmXFilterCell
);
4639 //------------------------------------------------------------------------------
4640 FmXFilterCell::FmXFilterCell(DbGridColumn
* pColumn
, DbCellControl
* pControl
)
4641 :FmXGridCell( pColumn
, pControl
)
4642 ,m_aTextListeners(m_aMutex
)
4644 DBG_CTOR(FmXFilterCell
,NULL
);
4646 DBG_ASSERT( m_pCellControl
->ISA( DbFilterField
), "FmXFilterCell::FmXFilterCell: invalid cell control!" );
4647 static_cast< DbFilterField
* >( m_pCellControl
)->SetCommitHdl( LINK( this, FmXFilterCell
, OnCommit
) );
4650 //------------------------------------------------------------------
4651 FmXFilterCell::~FmXFilterCell()
4653 if (!OComponentHelper::rBHelper
.bDisposed
)
4659 DBG_DTOR(FmXFilterCell
,NULL
);
4663 //------------------------------------------------------------------------------
4664 sal_Int64 SAL_CALL
FmXFilterCell::getSomething( const Sequence
< sal_Int8
>& _rIdentifier
) throw(RuntimeException
)
4666 sal_Int64
nReturn(0);
4668 if ( (_rIdentifier
.getLength() == 16)
4669 && (0 == memcmp( getUnoTunnelId().getConstArray(), _rIdentifier
.getConstArray(), 16 ))
4672 nReturn
= reinterpret_cast<sal_Int64
>(this);
4680 class theFmXFilterCellUnoTunnelId
: public rtl::Static
< UnoTunnelIdInit
, theFmXFilterCellUnoTunnelId
> {};
4683 const Sequence
<sal_Int8
>& FmXFilterCell::getUnoTunnelId()
4685 return theFmXFilterCellUnoTunnelId::get().getSeq();
4688 //------------------------------------------------------------------------------
4689 void FmXFilterCell::PaintCell( OutputDevice
& rDev
, const Rectangle
& rRect
)
4691 static_cast< DbFilterField
* >( m_pCellControl
)->PaintCell( rDev
, rRect
);
4695 //-----------------------------------------------------------------------------
4696 void FmXFilterCell::disposing()
4698 ::com::sun::star::lang::EventObject
aEvt(*this);
4699 m_aTextListeners
.disposeAndClear(aEvt
);
4701 ((DbFilterField
*)m_pCellControl
)->SetCommitHdl(Link());
4703 FmXGridCell::disposing();
4706 //------------------------------------------------------------------
4707 Any SAL_CALL
FmXFilterCell::queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw(RuntimeException
)
4709 Any aReturn
= FmXGridCell::queryAggregation(_rType
);
4711 if ( !aReturn
.hasValue() )
4712 aReturn
= FmXFilterCell_Base::queryInterface( _rType
);
4717 //-------------------------------------------------------------------------
4718 Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
FmXFilterCell::getTypes( ) throw(RuntimeException
)
4720 return ::comphelper::concatSequences(
4721 FmXGridCell::getTypes(),
4722 FmXFilterCell_Base::getTypes()
4726 //------------------------------------------------------------------------------
4727 IMPLEMENT_GET_IMPLEMENTATION_ID( FmXFilterCell
)
4729 // ::com::sun::star::awt::XTextComponent
4730 //------------------------------------------------------------------------------
4731 void SAL_CALL
FmXFilterCell::addTextListener(const Reference
< ::com::sun::star::awt::XTextListener
>& l
) throw( RuntimeException
)
4733 m_aTextListeners
.addInterface( l
);
4736 //------------------------------------------------------------------------------
4737 void SAL_CALL
FmXFilterCell::removeTextListener(const Reference
< ::com::sun::star::awt::XTextListener
>& l
) throw( RuntimeException
)
4739 m_aTextListeners
.removeInterface( l
);
4742 //------------------------------------------------------------------------------
4743 void SAL_CALL
FmXFilterCell::setText( const OUString
& aText
) throw( RuntimeException
)
4745 ::osl::MutexGuard
aGuard( m_aMutex
);
4746 ((DbFilterField
*)m_pCellControl
)->SetText(aText
);
4749 //------------------------------------------------------------------------------
4750 void SAL_CALL
FmXFilterCell::insertText( const ::com::sun::star::awt::Selection
& /*rSel*/, const OUString
& /*aText*/ ) throw( RuntimeException
)
4754 //------------------------------------------------------------------------------
4755 OUString SAL_CALL
FmXFilterCell::getText() throw( RuntimeException
)
4757 ::osl::MutexGuard
aGuard( m_aMutex
);
4758 return ((DbFilterField
*)m_pCellControl
)->GetText();
4761 //------------------------------------------------------------------------------
4762 OUString SAL_CALL
FmXFilterCell::getSelectedText( void ) throw( RuntimeException
)
4767 //------------------------------------------------------------------------------
4768 void SAL_CALL
FmXFilterCell::setSelection( const ::com::sun::star::awt::Selection
& /*aSelection*/ ) throw( RuntimeException
)
4772 //------------------------------------------------------------------------------
4773 ::com::sun::star::awt::Selection SAL_CALL
FmXFilterCell::getSelection( void ) throw( RuntimeException
)
4775 return ::com::sun::star::awt::Selection();
4778 //------------------------------------------------------------------------------
4779 sal_Bool SAL_CALL
FmXFilterCell::isEditable( void ) throw( RuntimeException
)
4784 //------------------------------------------------------------------------------
4785 void SAL_CALL
FmXFilterCell::setEditable( sal_Bool
/*bEditable*/ ) throw( RuntimeException
)
4789 //------------------------------------------------------------------------------
4790 sal_Int16 SAL_CALL
FmXFilterCell::getMaxTextLen() throw( RuntimeException
)
4795 //------------------------------------------------------------------------------
4796 void SAL_CALL
FmXFilterCell::setMaxTextLen( sal_Int16
/*nLen*/ ) throw( RuntimeException
)
4800 //------------------------------------------------------------------------------
4801 IMPL_LINK_NOARG(FmXFilterCell
, OnCommit
)
4803 ::cppu::OInterfaceIteratorHelper
aIt( m_aTextListeners
);
4804 ::com::sun::star::awt::TextEvent aEvt
;
4805 aEvt
.Source
= *this;
4806 while( aIt
.hasMoreElements() )
4807 ((::com::sun::star::awt::XTextListener
*)aIt
.next())->textChanged( aEvt
);
4811 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */