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