LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/svx/source/fmcomp - gridcell.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 473 2309 20.5 %
Date: 2013-07-09 Functions: 74 406 18.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10