LCOV - code coverage report
Current view: top level - forms/source/component - Filter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 410 2.4 %
Date: 2012-08-25 Functions: 3 35 8.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 1054 0.7 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "Filter.hxx"
      30                 :            : #include "FormComponent.hxx"
      31                 :            : #include "frm_module.hxx"
      32                 :            : #include "frm_resource.hrc"
      33                 :            : #include "frm_resource.hxx"
      34                 :            : #include "property.hrc"
      35                 :            : #include "property.hxx"
      36                 :            : 
      37                 :            : #include <com/sun/star/awt/VclWindowPeerAttribute.hpp>
      38                 :            : #include <com/sun/star/awt/XCheckBox.hpp>
      39                 :            : #include <com/sun/star/awt/XComboBox.hpp>
      40                 :            : #include <com/sun/star/awt/XListBox.hpp>
      41                 :            : #include <com/sun/star/awt/XRadioButton.hpp>
      42                 :            : #include <com/sun/star/awt/XVclWindowPeer.hpp>
      43                 :            : #include <com/sun/star/beans/NamedValue.hpp>
      44                 :            : #include <com/sun/star/container/XChild.hpp>
      45                 :            : #include <com/sun/star/container/XIndexAccess.hpp>
      46                 :            : #include <com/sun/star/container/XNamed.hpp>
      47                 :            : #include <com/sun/star/form/FormComponentType.hpp>
      48                 :            : #include <com/sun/star/sdb/BooleanComparisonMode.hpp>
      49                 :            : #include <com/sun/star/sdb/XColumn.hpp>
      50                 :            : #include <com/sun/star/sdb/XSQLQueryComposerFactory.hpp>
      51                 :            : #include <com/sun/star/sdbc/DataType.hpp>
      52                 :            : #include <com/sun/star/sdbc/XRowSet.hpp>
      53                 :            : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      54                 :            : #include <com/sun/star/sdbcx/XTablesSupplier.hpp>
      55                 :            : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
      56                 :            : #include <com/sun/star/awt/XItemList.hpp>
      57                 :            : 
      58                 :            : #include <comphelper/numbers.hxx>
      59                 :            : #include <comphelper/property.hxx>
      60                 :            : #include <connectivity/dbconversion.hxx>
      61                 :            : #include <connectivity/dbtools.hxx>
      62                 :            : #include <connectivity/formattedcolumnvalue.hxx>
      63                 :            : #include <connectivity/predicateinput.hxx>
      64                 :            : #include <rtl/ustrbuf.hxx>
      65                 :            : #include <toolkit/helper/vclunohelper.hxx>
      66                 :            : #include <tools/diagnose_ex.h>
      67                 :            : #include <unotools/localedatawrapper.hxx>
      68                 :            : #include <vcl/stdtext.hxx>
      69                 :            : #include <vcl/svapp.hxx>
      70                 :            : #include <tools/wintypes.hxx>
      71                 :            : 
      72                 :            : //--------------------------------------------------------------------------
      73                 :         30 : extern "C" void SAL_CALL createRegistryInfo_OFilterControl()
      74                 :            : {
      75 [ +  - ][ +  - ]:         30 :     static ::frm::OMultiInstanceAutoRegistration< ::frm::OFilterControl > aAutoRegistration;
         [ +  - ][ #  # ]
      76                 :         30 : }
      77                 :            : 
      78                 :            : //.........................................................................
      79                 :            : namespace frm
      80                 :            : {
      81                 :            : //.........................................................................
      82                 :            : 
      83                 :            :     using namespace ::com::sun::star::uno;
      84                 :            :     using namespace ::com::sun::star::awt;
      85                 :            :     using namespace ::com::sun::star::lang;
      86                 :            :     using namespace ::com::sun::star::beans;
      87                 :            :     using namespace ::com::sun::star::sdb;
      88                 :            :     using namespace ::com::sun::star::sdbc;
      89                 :            :     using namespace ::com::sun::star::sdbcx;
      90                 :            :     using namespace ::com::sun::star::util;
      91                 :            :     using namespace ::com::sun::star::form;
      92                 :            :     using namespace ::com::sun::star::container;
      93                 :            :     using namespace ::com::sun::star::ui::dialogs;
      94                 :            : 
      95                 :            :     using namespace ::connectivity;
      96                 :            : 
      97                 :            :     //=====================================================================
      98                 :            :     // OFilterControl
      99                 :            :     //=====================================================================
     100                 :            :     //---------------------------------------------------------------------
     101                 :          0 :     OFilterControl::OFilterControl( const Reference< XMultiServiceFactory >& _rxORB )
     102                 :            :         :UnoControl( _rxORB )
     103                 :            :         ,m_aTextListeners( *this )
     104                 :            :         ,m_aParser( _rxORB )
     105                 :            :         ,m_nControlClass( FormComponentType::TEXTFIELD )
     106                 :            :         ,m_bFilterList( sal_False )
     107                 :            :         ,m_bMultiLine( sal_False )
     108 [ #  # ][ #  # ]:          0 :         ,m_bFilterListFilled( sal_False )
         [ #  # ][ #  # ]
     109                 :            :     {
     110                 :          0 :     }
     111                 :            : 
     112                 :            :     //---------------------------------------------------------------------
     113                 :          0 :     sal_Bool OFilterControl::ensureInitialized( )
     114                 :            :     {
     115         [ #  # ]:          0 :         if ( !m_xField.is() )
     116                 :            :         {
     117                 :            :             OSL_FAIL( "OFilterControl::ensureInitialized: improperly initialized: no field!" );
     118                 :          0 :             return sal_False;
     119                 :            :         }
     120                 :            : 
     121         [ #  # ]:          0 :         if ( !m_xConnection.is() )
     122                 :            :         {
     123                 :            :             OSL_FAIL( "OFilterControl::ensureInitialized: improperly initialized: no connection!" );
     124                 :          0 :             return sal_False;
     125                 :            :         }
     126                 :            : 
     127         [ #  # ]:          0 :         if ( !m_xFormatter.is() )
     128                 :            :         {
     129                 :            :             // we can create one from the connection, if it's an SDB connection
     130 [ #  # ][ #  # ]:          0 :             Reference< XNumberFormatsSupplier > xFormatSupplier = ::dbtools::getNumberFormats( m_xConnection, sal_True, maContext.getLegacyServiceFactory() );
     131                 :            : 
     132         [ #  # ]:          0 :             if ( xFormatSupplier.is() )
     133                 :            :             {
     134         [ #  # ]:          0 :                 maContext.createComponent( "com.sun.star.util.NumberFormatter", m_xFormatter );
     135         [ #  # ]:          0 :                 if ( m_xFormatter.is() )
     136 [ #  # ][ #  # ]:          0 :                     m_xFormatter->attachNumberFormatsSupplier( xFormatSupplier );
     137                 :          0 :             }
     138                 :            :         }
     139         [ #  # ]:          0 :         if ( !m_xFormatter.is() )
     140                 :            :         {
     141                 :            :             OSL_FAIL( "OFilterControl::ensureInitialized: no number formatter!" );
     142                 :            :             // no fallback anymore
     143                 :          0 :             return sal_False;
     144                 :            :         }
     145                 :            : 
     146                 :          0 :         return sal_True;
     147                 :            :     }
     148                 :            : 
     149                 :            :     //---------------------------------------------------------------------
     150                 :          0 :     Any SAL_CALL OFilterControl::queryAggregation( const Type & rType ) throw(RuntimeException)
     151                 :            :     {
     152                 :          0 :         Any aRet = UnoControl::queryAggregation( rType);
     153         [ #  # ]:          0 :         if(!aRet.hasValue())
     154         [ #  # ]:          0 :             aRet = OFilterControl_BASE::queryInterface(rType);
     155                 :            : 
     156                 :          0 :         return aRet;
     157                 :            :     }
     158                 :            : 
     159                 :            :     //------------------------------------------------------------------
     160                 :          0 :     ::rtl::OUString OFilterControl::GetComponentServiceName()
     161                 :            :     {
     162                 :          0 :         ::rtl::OUString aServiceName;
     163   [ #  #  #  #  :          0 :         switch (m_nControlClass)
                      # ]
     164                 :            :         {
     165                 :            :             case FormComponentType::RADIOBUTTON:
     166         [ #  # ]:          0 :                 aServiceName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("radiobutton") );
     167                 :          0 :                 break;
     168                 :            :             case FormComponentType::CHECKBOX:
     169         [ #  # ]:          0 :                 aServiceName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("checkbox") );
     170                 :          0 :                 break;
     171                 :            :             case FormComponentType::COMBOBOX:
     172         [ #  # ]:          0 :                 aServiceName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("combobox") );
     173                 :          0 :                 break;
     174                 :            :             case FormComponentType::LISTBOX:
     175         [ #  # ]:          0 :                 aServiceName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("listbox") );
     176                 :          0 :                 break;
     177                 :            :             default:
     178         [ #  # ]:          0 :                 if (m_bMultiLine)
     179         [ #  # ]:          0 :                     aServiceName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MultiLineEdit") );
     180                 :            :                 else
     181         [ #  # ]:          0 :                     aServiceName = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Edit") );
     182                 :            :         }
     183                 :          0 :         return aServiceName;
     184                 :            :     }
     185                 :            : 
     186                 :            :     // XComponent
     187                 :            :     //---------------------------------------------------------------------
     188                 :          0 :     void OFilterControl::dispose() throw( RuntimeException  )
     189                 :            :     {
     190 [ #  # ][ #  # ]:          0 :         EventObject aEvt(*this);
     191         [ #  # ]:          0 :         m_aTextListeners.disposeAndClear( aEvt );
     192 [ #  # ][ #  # ]:          0 :         UnoControl::dispose();
     193                 :          0 :     }
     194                 :            : 
     195                 :            :     //---------------------------------------------------------------------
     196                 :          0 :     void OFilterControl::createPeer( const Reference< XToolkit > & rxToolkit, const Reference< XWindowPeer >  & rParentPeer ) throw(RuntimeException)
     197                 :            :     {
     198                 :          0 :         UnoControl::createPeer( rxToolkit, rParentPeer );
     199                 :            : 
     200                 :            :         try
     201                 :            :         {
     202 [ #  # ][ #  # ]:          0 :             Reference< XVclWindowPeer >  xVclWindow( getPeer(), UNO_QUERY_THROW );
     203   [ #  #  #  #  :          0 :             switch ( m_nControlClass )
                      # ]
     204                 :            :             {
     205                 :            :                 case FormComponentType::CHECKBOX:
     206                 :            :                 {
     207                 :            :                     // checkboxes always have a tristate-mode
     208 [ #  # ][ #  # ]:          0 :                     xVclWindow->setProperty( PROPERTY_TRISTATE, makeAny( sal_Bool( sal_True ) ) );
         [ #  # ][ #  # ]
     209 [ #  # ][ #  # ]:          0 :                     xVclWindow->setProperty( PROPERTY_STATE, makeAny( sal_Int32( STATE_DONTKNOW ) ) );
         [ #  # ][ #  # ]
     210                 :            : 
     211 [ #  # ][ #  # ]:          0 :                     Reference< XCheckBox >  xBox( getPeer(), UNO_QUERY_THROW );
     212 [ #  # ][ #  # ]:          0 :                     xBox->addItemListener( this );
                 [ #  # ]
     213                 :            : 
     214                 :            :                 }
     215                 :          0 :                 break;
     216                 :            : 
     217                 :            :                 case FormComponentType::RADIOBUTTON:
     218                 :            :                 {
     219 [ #  # ][ #  # ]:          0 :                     xVclWindow->setProperty( PROPERTY_STATE, makeAny( sal_Int32( STATE_NOCHECK ) ) );
         [ #  # ][ #  # ]
     220                 :            : 
     221 [ #  # ][ #  # ]:          0 :                     Reference< XRadioButton >  xRadio( getPeer(), UNO_QUERY_THROW );
     222 [ #  # ][ #  # ]:          0 :                     xRadio->addItemListener( this );
                 [ #  # ]
     223                 :            :                 }
     224                 :          0 :                 break;
     225                 :            : 
     226                 :            :                 case FormComponentType::LISTBOX:
     227                 :            :                 {
     228 [ #  # ][ #  # ]:          0 :                     Reference< XListBox >  xListBox( getPeer(), UNO_QUERY_THROW );
     229 [ #  # ][ #  # ]:          0 :                     xListBox->addItemListener( this );
                 [ #  # ]
     230                 :            :                 }
     231                 :            :                 // no break
     232                 :            : 
     233                 :            :                 case FormComponentType::COMBOBOX:
     234                 :            :                 {
     235 [ #  # ][ #  # ]:          0 :                     xVclWindow->setProperty(PROPERTY_AUTOCOMPLETE, makeAny( sal_Bool( sal_True ) ) );
         [ #  # ][ #  # ]
     236                 :            :                 }
     237                 :            :                 // no break
     238                 :            : 
     239                 :            :                 default:
     240                 :            :                 {
     241 [ #  # ][ #  # ]:          0 :                     Reference< XWindow >  xWindow( getPeer(), UNO_QUERY );
     242 [ #  # ][ #  # ]:          0 :                     xWindow->addFocusListener( this );
                 [ #  # ]
     243                 :            : 
     244 [ #  # ][ #  # ]:          0 :                     Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     245         [ #  # ]:          0 :                     if (xText.is())
     246 [ #  # ][ #  # ]:          0 :                         xText->setMaxTextLen(0);
     247                 :            :                 }
     248                 :          0 :                 break;
     249                 :            :             }
     250                 :            : 
     251 [ #  # ][ #  # ]:          0 :             OControl::initFormControlPeer( getPeer() );
     252                 :            : 
     253                 :            :             // filter controls are _never_ readonly
     254 [ #  # ][ #  # ]:          0 :             Reference< XPropertySet > xModel( getModel(), UNO_QUERY_THROW );
     255 [ #  # ][ #  # ]:          0 :             Reference< XPropertySetInfo > xModelPSI( xModel->getPropertySetInfo(), UNO_SET_THROW );
                 [ #  # ]
     256 [ #  # ][ #  # ]:          0 :             if ( xModelPSI->hasPropertyByName( PROPERTY_READONLY ) )
         [ #  # ][ #  # ]
     257 [ #  # ][ #  # ]:          0 :                 xVclWindow->setProperty( PROPERTY_READONLY, makeAny( sal_Bool( sal_False ) ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     258                 :            :         }
     259                 :          0 :         catch( const Exception& )
     260                 :            :         {
     261                 :            :             DBG_UNHANDLED_EXCEPTION();
     262                 :            :         }
     263                 :            : 
     264         [ #  # ]:          0 :         if (m_bFilterList)
     265                 :          0 :             m_bFilterListFilled = sal_False;
     266                 :          0 :     }
     267                 :            : 
     268                 :            :     //---------------------------------------------------------------------
     269                 :          0 :     void OFilterControl::PrepareWindowDescriptor( WindowDescriptor& rDescr )
     270                 :            :     {
     271         [ #  # ]:          0 :         if (m_bFilterList)
     272                 :          0 :             rDescr.WindowAttributes |= VclWindowPeerAttribute::DROPDOWN;
     273                 :          0 :     }
     274                 :            : 
     275                 :            :     //---------------------------------------------------------------------
     276                 :          0 :     void OFilterControl::ImplSetPeerProperty( const ::rtl::OUString& rPropName, const Any& rVal )
     277                 :            :     {
     278                 :            :         // these properties are ignored
     279         [ #  # ]:          0 :         if (rPropName == PROPERTY_TEXT ||
           [ #  #  #  # ]
                 [ #  # ]
           [ #  #  #  # ]
     280 [ #  # ][ #  # ]:          0 :             rPropName == PROPERTY_STATE)
                 [ #  # ]
     281                 :          0 :             return;
     282                 :            : 
     283                 :          0 :         UnoControl::ImplSetPeerProperty( rPropName, rVal );
     284                 :            :     }
     285                 :            : 
     286                 :            :     // XEventListener
     287                 :            :     //---------------------------------------------------------------------
     288                 :          0 :     void SAL_CALL OFilterControl::disposing(const EventObject& Source) throw( RuntimeException )
     289                 :            :     {
     290                 :          0 :         UnoControl::disposing(Source);
     291                 :          0 :     }
     292                 :            : 
     293                 :            :     // XItemListener
     294                 :            :     //---------------------------------------------------------------------
     295                 :          0 :     void SAL_CALL OFilterControl::itemStateChanged( const ItemEvent& rEvent ) throw(RuntimeException)
     296                 :            :     {
     297                 :          0 :         ::rtl::OUStringBuffer aText;
     298   [ #  #  #  # ]:          0 :         switch (m_nControlClass)
     299                 :            :         {
     300                 :            :             case FormComponentType::CHECKBOX:
     301                 :            :             {
     302 [ #  # ][ #  # ]:          0 :                 if ( ( rEvent.Selected == STATE_CHECK ) || ( rEvent.Selected == STATE_NOCHECK ) )
     303                 :            :                 {
     304 [ #  # ][ #  # ]:          0 :                     sal_Int32 nBooleanComparisonMode = ::dbtools::DatabaseMetaData( m_xConnection ).getBooleanComparisonMode();
                 [ #  # ]
     305                 :            : 
     306                 :          0 :                     bool bSelected = ( rEvent.Selected == STATE_CHECK );
     307                 :            : 
     308         [ #  # ]:          0 :                     ::rtl::OUString sExpressionMarker( RTL_CONSTASCII_USTRINGPARAM( "$expression$" ) );
     309                 :            :                     ::dbtools::getBoleanComparisonPredicate(
     310                 :            :                         sExpressionMarker,
     311                 :            :                         bSelected,
     312                 :            :                         nBooleanComparisonMode,
     313                 :            :                         aText
     314         [ #  # ]:          0 :                     );
     315                 :            : 
     316         [ #  # ]:          0 :                     ::rtl::OUString sText( aText.makeStringAndClear() );
     317                 :          0 :                     sal_Int32 nMarkerPos( sText.indexOf( sExpressionMarker ) );
     318                 :            :                     OSL_ENSURE( nMarkerPos == 0, "OFilterControl::itemStateChanged: unsupported boolean comparison mode!" );
     319                 :            :                     // If this assertion fails, then getBoleanComparisonPredicate created a predicate which
     320                 :            :                     // does not start with the expression we gave it. The only known case is when
     321                 :            :                     // the comparison mode is ACCESS_COMPAT, and the value is TRUE. In this case,
     322                 :            :                     // the expression is rather complex.
     323                 :            :                     // Well, so this is a known issue - the filter controls (and thus the form based filter)
     324                 :            :                     // do not work with boolean MS Access fields.
     325                 :            :                     // To fix this, we would probably have to revert here to always return "1" or "0" as normalized
     326                 :            :                     // filter, and change our client code to properly translate this (which could be some effort).
     327         [ #  # ]:          0 :                     if ( nMarkerPos == 0 )
     328         [ #  # ]:          0 :                         aText.append( sText.copy( sExpressionMarker.getLength() ) );
     329                 :            :                     else
     330                 :            :                     {
     331                 :            :                         // fallback
     332 [ #  # ][ #  # ]:          0 :                         aText.appendAscii( bSelected ? "1" : "0" );
     333                 :          0 :                     }
     334                 :            :                 }
     335                 :            :             }
     336                 :          0 :             break;
     337                 :            : 
     338                 :            :             case FormComponentType::LISTBOX:
     339                 :            :             {
     340                 :            :                 try
     341                 :            :                 {
     342 [ #  # ][ #  # ]:          0 :                     const Reference< XItemList > xItemList( getModel(), UNO_QUERY_THROW );
     343 [ #  # ][ #  # ]:          0 :                     ::rtl::OUString sItemText( xItemList->getItemText( rEvent.Selected ) );
     344                 :            : 
     345         [ #  # ]:          0 :                     const MapString2String::const_iterator itemPos = m_aDisplayItemToValueItem.find( sItemText );
     346 [ #  # ][ #  # ]:          0 :                     if ( itemPos != m_aDisplayItemToValueItem.end() )
     347                 :            :                     {
     348         [ #  # ]:          0 :                         sItemText = itemPos->second;
     349         [ #  # ]:          0 :                         if ( !sItemText.isEmpty() )
     350                 :            :                         {
     351 [ #  # ][ #  # ]:          0 :                             ::dbtools::OPredicateInputController aPredicateInput( maContext.getLegacyServiceFactory(), m_xConnection, getParseContext() );
                 [ #  # ]
     352                 :          0 :                             ::rtl::OUString sErrorMessage;
     353 [ #  # ][ #  # ]:          0 :                             OSL_VERIFY( aPredicateInput.normalizePredicateString( sItemText, m_xField, &sErrorMessage ) );
     354                 :            :                         }
     355                 :            :                     }
     356 [ #  # ][ #  # ]:          0 :                     aText.append( sItemText );
     357                 :            :                 }
     358         [ #  # ]:          0 :                 catch( const Exception& )
     359                 :            :                 {
     360                 :            :                     DBG_UNHANDLED_EXCEPTION();
     361                 :            :                 }
     362                 :            :             }
     363                 :          0 :             break;
     364                 :            : 
     365                 :            :             case FormComponentType::RADIOBUTTON:
     366                 :            :             {
     367         [ #  # ]:          0 :                 if ( rEvent.Selected == STATE_CHECK )
     368 [ #  # ][ #  # ]:          0 :                     aText.append( ::comphelper::getString( Reference< XPropertySet >( getModel(), UNO_QUERY )->getPropertyValue( PROPERTY_REFVALUE ) ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     369                 :            :             }
     370                 :          0 :             break;
     371                 :            :         }
     372                 :            : 
     373         [ #  # ]:          0 :         ::rtl::OUString sText( aText.makeStringAndClear() );
     374         [ #  # ]:          0 :         if ( m_aText.compareTo( sText ) )
     375                 :            :         {
     376                 :          0 :             m_aText = sText;
     377         [ #  # ]:          0 :             TextEvent aEvt;
     378 [ #  # ][ #  # ]:          0 :             aEvt.Source = *this;
     379         [ #  # ]:          0 :             ::cppu::OInterfaceIteratorHelper aIt( m_aTextListeners );
     380         [ #  # ]:          0 :             while( aIt.hasMoreElements() )
     381 [ #  # ][ #  # ]:          0 :                 ((XTextListener *)aIt.next())->textChanged( aEvt );
         [ #  # ][ #  # ]
     382                 :          0 :         }
     383                 :          0 :     }
     384                 :            : 
     385                 :            :     //---------------------------------------------------------------------
     386                 :          0 :     void OFilterControl::implInitFilterList()
     387                 :            :     {
     388 [ #  # ][ #  # ]:          0 :         if ( !ensureInitialized( ) )
     389                 :            :             // already asserted in ensureInitialized
     390                 :            :             return;
     391                 :            : 
     392                 :            :         // ensure the cursor and the statement are disposed as soon as we leave
     393         [ #  # ]:          0 :         ::utl::SharedUNOComponent< XResultSet > xListCursor;
     394         [ #  # ]:          0 :         ::utl::SharedUNOComponent< XStatement > xStatement;
     395                 :            : 
     396                 :            :         try
     397                 :            :         {
     398                 :          0 :             m_bFilterListFilled = sal_True;
     399                 :            : 
     400         [ #  # ]:          0 :             if ( !m_xField.is() )
     401                 :            :                 return;
     402                 :            : 
     403                 :          0 :             ::rtl::OUString sFieldName;
     404 [ #  # ][ #  # ]:          0 :             m_xField->getPropertyValue( PROPERTY_NAME ) >>= sFieldName;
                 [ #  # ]
     405                 :            : 
     406                 :            :             // here we need a table to which the field belongs to
     407 [ #  # ][ #  # ]:          0 :             const Reference< XChild > xModelAsChild( getModel(), UNO_QUERY_THROW );
     408 [ #  # ][ #  # ]:          0 :             const Reference< XRowSet > xForm( xModelAsChild->getParent(), UNO_QUERY_THROW );
                 [ #  # ]
     409         [ #  # ]:          0 :             const Reference< XPropertySet > xFormProps( xForm, UNO_QUERY_THROW );
     410                 :            : 
     411                 :            :             // create a query composer
     412                 :          0 :             Reference< XColumnsSupplier > xSuppColumns;
     413 [ #  # ][ #  # ]:          0 :             xFormProps->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SingleSelectQueryComposer"))) >>= xSuppColumns;
         [ #  # ][ #  # ]
     414                 :            : 
     415 [ #  # ][ #  # ]:          0 :             const Reference< XConnection > xConnection( ::dbtools::getConnection( xForm ), UNO_SET_THROW );
     416 [ #  # ][ #  # ]:          0 :             const Reference< XNameAccess > xFieldNames( xSuppColumns->getColumns(), UNO_SET_THROW );
                 [ #  # ]
     417 [ #  # ][ #  # ]:          0 :             if ( !xFieldNames->hasByName( sFieldName ) )
                 [ #  # ]
     418                 :            :                 return;
     419                 :          0 :             ::rtl::OUString sRealFieldName, sTableName;
     420 [ #  # ][ #  # ]:          0 :             const Reference< XPropertySet > xComposerFieldProps( xFieldNames->getByName( sFieldName ), UNO_QUERY_THROW );
                 [ #  # ]
     421 [ #  # ][ #  # ]:          0 :             xComposerFieldProps->getPropertyValue( PROPERTY_REALNAME ) >>= sRealFieldName;
                 [ #  # ]
     422 [ #  # ][ #  # ]:          0 :             xComposerFieldProps->getPropertyValue( PROPERTY_TABLENAME ) >>= sTableName;
                 [ #  # ]
     423                 :            : 
     424                 :            :             // obtain the table of the field
     425         [ #  # ]:          0 :             const Reference< XTablesSupplier > xSuppTables( xSuppColumns, UNO_QUERY_THROW );
     426 [ #  # ][ #  # ]:          0 :             const Reference< XNameAccess > xTablesNames( xSuppTables->getTables(), UNO_SET_THROW );
                 [ #  # ]
     427 [ #  # ][ #  # ]:          0 :             const Reference< XNamed > xNamedTable( xTablesNames->getByName( sTableName ), UNO_QUERY_THROW );
                 [ #  # ]
     428 [ #  # ][ #  # ]:          0 :             sTableName = xNamedTable->getName();
     429                 :            : 
     430                 :            :             // create a statement selecting all values for the given field
     431                 :          0 :             ::rtl::OUStringBuffer aStatement;
     432                 :            : 
     433 [ #  # ][ #  # ]:          0 :             const Reference< XDatabaseMetaData >  xMeta( xConnection->getMetaData(), UNO_SET_THROW );
                 [ #  # ]
     434 [ #  # ][ #  # ]:          0 :             const ::rtl::OUString sQuoteChar = xMeta->getIdentifierQuoteString();
     435                 :            : 
     436         [ #  # ]:          0 :             aStatement.appendAscii( "SELECT DISTINCT " );
     437         [ #  # ]:          0 :             aStatement.append( sQuoteChar );
     438         [ #  # ]:          0 :             aStatement.append( sRealFieldName );
     439         [ #  # ]:          0 :             aStatement.append( sQuoteChar );
     440                 :            : 
     441                 :            :             // if the field had an alias in our form's statement, give it this alias in the new statement, too
     442 [ #  # ][ #  # ]:          0 :             if ( !sFieldName.isEmpty() && ( sFieldName != sRealFieldName ) )
                 [ #  # ]
     443                 :            :             {
     444         [ #  # ]:          0 :                 aStatement.appendAscii(" AS ");
     445         [ #  # ]:          0 :                 aStatement.append( sQuoteChar );
     446         [ #  # ]:          0 :                 aStatement.append( sFieldName );
     447         [ #  # ]:          0 :                 aStatement.append( sQuoteChar );
     448                 :            :             }
     449                 :            : 
     450         [ #  # ]:          0 :             aStatement.appendAscii( " FROM " );
     451                 :            : 
     452                 :          0 :             ::rtl::OUString sCatalog, sSchema, sTable;
     453         [ #  # ]:          0 :             ::dbtools::qualifiedNameComponents( xMeta, sTableName, sCatalog, sSchema, sTable, ::dbtools::eInDataManipulation );
     454 [ #  # ][ #  # ]:          0 :             aStatement.append( ::dbtools::composeTableNameForSelect( xConnection, sCatalog, sSchema, sTable ) );
     455                 :            : 
     456                 :            :             // execute the statement
     457 [ #  # ][ #  # ]:          0 :             xStatement.reset( xConnection->createStatement() );
                 [ #  # ]
     458         [ #  # ]:          0 :             const ::rtl::OUString sSelectStatement( aStatement.makeStringAndClear( ) );
     459 [ #  # ][ #  # ]:          0 :             xListCursor.reset( xStatement->executeQuery( sSelectStatement ) );
                 [ #  # ]
     460                 :            : 
     461                 :            :             // retrieve the one column which we take the values from
     462         [ #  # ]:          0 :             const Reference< XColumnsSupplier > xSupplyCols( xListCursor, UNO_QUERY_THROW );
     463 [ #  # ][ #  # ]:          0 :             const Reference< XIndexAccess > xFields( xSupplyCols->getColumns(), UNO_QUERY_THROW );
                 [ #  # ]
     464 [ #  # ][ #  # ]:          0 :             const Reference< XPropertySet > xDataField( xFields->getByIndex(0), UNO_QUERY_THROW );
                 [ #  # ]
     465                 :            : 
     466                 :            :             // ensure the values will be  formatted according to the field format
     467         [ #  # ]:          0 :             const ::dbtools::FormattedColumnValue aFormatter( m_xFormatter, xDataField );
     468                 :            : 
     469         [ #  # ]:          0 :             ::std::vector< ::rtl::OUString > aProposals;
     470         [ #  # ]:          0 :             aProposals.reserve(16);
     471                 :            : 
     472 [ #  # ][ #  # ]:          0 :             while ( xListCursor->next() && ( aProposals.size() < size_t( SHRT_MAX ) ) )
         [ #  # ][ #  # ]
                 [ #  # ]
     473                 :            :             {
     474         [ #  # ]:          0 :                 const ::rtl::OUString sCurrentValue = aFormatter.getFormattedValue();
     475         [ #  # ]:          0 :                 aProposals.push_back( sCurrentValue );
     476                 :          0 :             }
     477                 :            : 
     478                 :            :             // fill the list items into our peer
     479         [ #  # ]:          0 :             Sequence< ::rtl::OUString> aStringSeq( aProposals.size() );
     480 [ #  # ][ #  # ]:          0 :             ::std::copy( aProposals.begin(), aProposals.end(), aStringSeq.getArray() );
     481                 :            : 
     482 [ #  # ][ #  # ]:          0 :             const Reference< XComboBox >  xComboBox( getPeer(), UNO_QUERY_THROW );
     483 [ #  # ][ #  # ]:          0 :             xComboBox->addItems( aStringSeq, 0 );
     484                 :            : 
     485                 :            :             // set the drop down line count to something reasonable
     486         [ #  # ]:          0 :             const sal_Int16 nLineCount = ::std::min( sal_Int16( 16 ), sal_Int16( aStringSeq.getLength() ) );
     487 [ #  # ][ #  # ]:          0 :             xComboBox->setDropDownLineCount( nLineCount );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     488                 :            :         }
     489         [ #  # ]:          0 :         catch( const Exception& )
     490                 :            :         {
     491                 :            :             DBG_UNHANDLED_EXCEPTION();
     492 [ #  # ][ #  # ]:          0 :         }
         [ #  # ][ #  # ]
     493                 :            :     }
     494                 :            : 
     495                 :            :     // XFocusListener
     496                 :            :     //---------------------------------------------------------------------
     497                 :          0 :     void SAL_CALL OFilterControl::focusGained(const FocusEvent& /*e*/)  throw( RuntimeException  )
     498                 :            :     {
     499                 :            :         // should we fill the combobox?
     500 [ #  # ][ #  # ]:          0 :         if (m_bFilterList && !m_bFilterListFilled)
     501                 :          0 :             implInitFilterList();
     502                 :          0 :     }
     503                 :            : 
     504                 :            :     //---------------------------------------------------------------------
     505                 :          0 :     void SAL_CALL OFilterControl::focusLost(const FocusEvent& /*e*/) throw( RuntimeException )
     506                 :            :     {
     507                 :          0 :     }
     508                 :            : 
     509                 :            :     //---------------------------------------------------------------------
     510                 :          0 :     sal_Bool SAL_CALL OFilterControl::commit() throw(RuntimeException)
     511                 :            :     {
     512 [ #  # ][ #  # ]:          0 :         if ( !ensureInitialized( ) )
     513                 :            :             // already asserted in ensureInitialized
     514                 :          0 :             return sal_True;
     515                 :            : 
     516                 :          0 :         ::rtl::OUString aText;
     517         [ #  # ]:          0 :         switch (m_nControlClass)
     518                 :            :         {
     519                 :            :             case FormComponentType::TEXTFIELD:
     520                 :            :             case FormComponentType::COMBOBOX:
     521                 :            :             {
     522 [ #  # ][ #  # ]:          0 :                 Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     523         [ #  # ]:          0 :                 if (xText.is())
     524 [ #  # ][ #  # ]:          0 :                     aText = xText->getText();
     525                 :          0 :             }   break;
     526                 :            :             default:
     527                 :          0 :                 return sal_True;
     528                 :            :         }
     529         [ #  # ]:          0 :         if (m_aText.compareTo(aText))
     530                 :            :         {
     531                 :            :             // check the text with the SQL-Parser
     532                 :          0 :             ::rtl::OUString aNewText(aText);
     533                 :          0 :             aNewText.trim();
     534         [ #  # ]:          0 :             if ( !aNewText.isEmpty() )
     535                 :            :             {
     536 [ #  # ][ #  # ]:          0 :                 ::dbtools::OPredicateInputController aPredicateInput( maContext.getLegacyServiceFactory(), m_xConnection, getParseContext() );
                 [ #  # ]
     537                 :          0 :                 ::rtl::OUString sErrorMessage;
     538 [ #  # ][ #  # ]:          0 :                 if ( !aPredicateInput.normalizePredicateString( aNewText, m_xField, &sErrorMessage ) )
     539                 :            :                 {
     540                 :            :                     // display the error and outta here
     541         [ #  # ]:          0 :                     SQLContext aError;
     542 [ #  # ][ #  # ]:          0 :                     aError.Message = String( FRM_RES_STRING( RID_STR_SYNTAXERROR ) );
         [ #  # ][ #  # ]
     543                 :          0 :                     aError.Details = sErrorMessage;
     544         [ #  # ]:          0 :                     displayException( aError );
     545         [ #  # ]:          0 :                     return sal_False;
     546 [ #  # ][ #  # ]:          0 :                 }
                 [ #  # ]
     547                 :            :             }
     548                 :            : 
     549         [ #  # ]:          0 :             setText(aNewText);
     550         [ #  # ]:          0 :             TextEvent aEvt;
     551 [ #  # ][ #  # ]:          0 :             aEvt.Source = *this;
     552         [ #  # ]:          0 :             ::cppu::OInterfaceIteratorHelper aIt( m_aTextListeners );
     553         [ #  # ]:          0 :             while( aIt.hasMoreElements() )
     554 [ #  # ][ #  # ]:          0 :                 static_cast< XTextListener* >( aIt.next() )->textChanged( aEvt );
         [ #  # ][ #  # ]
                 [ #  # ]
     555                 :            :         }
     556                 :          0 :         return sal_True;
     557                 :            :     }
     558                 :            : 
     559                 :            :     // XTextComponent
     560                 :            :     //---------------------------------------------------------------------
     561                 :          0 :     void SAL_CALL OFilterControl::addTextListener(const Reference< XTextListener > & l) throw(RuntimeException)
     562                 :            :     {
     563                 :          0 :         m_aTextListeners.addInterface( l );
     564                 :          0 :     }
     565                 :            : 
     566                 :            :     //---------------------------------------------------------------------
     567                 :          0 :     void SAL_CALL OFilterControl::removeTextListener(const Reference< XTextListener > & l) throw(RuntimeException)
     568                 :            :     {
     569                 :          0 :         m_aTextListeners.removeInterface( l );
     570                 :          0 :     }
     571                 :            : 
     572                 :            :     //---------------------------------------------------------------------
     573                 :          0 :     void SAL_CALL OFilterControl::setText( const ::rtl::OUString& aText ) throw(RuntimeException)
     574                 :            :     {
     575         [ #  # ]:          0 :         if ( !ensureInitialized( ) )
     576                 :            :             // already asserted in ensureInitialized
     577                 :          0 :             return;
     578                 :            : 
     579   [ #  #  #  # ]:          0 :         switch (m_nControlClass)
     580                 :            :         {
     581                 :            :             case FormComponentType::CHECKBOX:
     582                 :            :             {
     583 [ #  # ][ #  # ]:          0 :                 Reference< XVclWindowPeer >  xVclWindow( getPeer(), UNO_QUERY );
     584         [ #  # ]:          0 :                 if (xVclWindow.is())
     585                 :            :                 {
     586                 :          0 :                     Any aValue;
     587 [ #  # ][ #  #  :          0 :                     if  (   aText == "1"
             #  #  #  # ]
     588                 :          0 :                         ||  aText.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("TRUE"))
     589                 :          0 :                         ||  aText.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("IS TRUE"))
     590                 :            :                         )
     591                 :            :                     {
     592         [ #  # ]:          0 :                         aValue <<= (sal_Int32)STATE_CHECK;
     593                 :            :                     }
     594 [ #  # ][ #  # ]:          0 :                     else if ( aText == "0" || aText.equalsIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM("FALSE")) )
                 [ #  # ]
     595                 :            :                     {
     596         [ #  # ]:          0 :                         aValue <<= (sal_Int32)STATE_NOCHECK;
     597                 :            :                     }
     598                 :            :                     else
     599         [ #  # ]:          0 :                         aValue <<= (sal_Int32)STATE_DONTKNOW;
     600                 :            : 
     601                 :          0 :                     m_aText = aText;
     602 [ #  # ][ #  # ]:          0 :                     xVclWindow->setProperty( PROPERTY_STATE, aValue );
                 [ #  # ]
     603                 :          0 :                 }
     604                 :          0 :             }   break;
     605                 :            :             case FormComponentType::RADIOBUTTON:
     606                 :            :             {
     607 [ #  # ][ #  # ]:          0 :                 Reference< XVclWindowPeer >  xVclWindow( getPeer(), UNO_QUERY );
     608         [ #  # ]:          0 :                 if (xVclWindow.is())
     609                 :            :                 {
     610 [ #  # ][ #  # ]:          0 :                     ::rtl::OUString aRefText = ::comphelper::getString(com::sun::star::uno::Reference< XPropertySet > (getModel(), UNO_QUERY)->getPropertyValue(PROPERTY_REFVALUE));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     611                 :          0 :                     Any aValue;
     612         [ #  # ]:          0 :                     if (aText == aRefText)
     613         [ #  # ]:          0 :                         aValue <<= (sal_Int32)STATE_CHECK;
     614                 :            :                     else
     615         [ #  # ]:          0 :                         aValue <<= (sal_Int32)STATE_NOCHECK;
     616                 :          0 :                     m_aText = aText;
     617 [ #  # ][ #  # ]:          0 :                     xVclWindow->setProperty(PROPERTY_STATE, aValue);
                 [ #  # ]
     618                 :          0 :                 }
     619                 :          0 :             }   break;
     620                 :            :             case FormComponentType::LISTBOX:
     621                 :            :             {
     622 [ #  # ][ #  # ]:          0 :                 Reference< XListBox >  xListBox( getPeer(), UNO_QUERY );
     623         [ #  # ]:          0 :                 if (xListBox.is())
     624                 :            :                 {
     625                 :          0 :                     m_aText = aText;
     626         [ #  # ]:          0 :                     MapString2String::const_iterator itemPos = m_aDisplayItemToValueItem.find( m_aText );
     627 [ #  # ][ #  # ]:          0 :                     if ( itemPos == m_aDisplayItemToValueItem.end() )
     628                 :            :                     {
     629                 :          0 :                         const bool isQuoted =   ( m_aText.getLength() > 1 )
     630                 :          0 :                                             &&  ( m_aText[0] == '\'' )
     631         [ #  # ]:          0 :                                             &&  ( m_aText[ m_aText.getLength() - 1 ] == '\'' );
           [ #  #  #  # ]
     632         [ #  # ]:          0 :                         if ( isQuoted )
     633                 :            :                         {
     634                 :          0 :                             m_aText = m_aText.copy( 1, m_aText.getLength() - 2 );
     635         [ #  # ]:          0 :                             itemPos = m_aDisplayItemToValueItem.find( m_aText );
     636                 :            :                         }
     637                 :            :                     }
     638                 :            : 
     639                 :            :                     OSL_ENSURE( ( itemPos != m_aDisplayItemToValueItem.end() ) || m_aText.isEmpty(),
     640                 :            :                         "OFilterControl::setText: this text is not in my display list!" );
     641 [ #  # ][ #  # ]:          0 :                     if ( itemPos == m_aDisplayItemToValueItem.end() )
     642                 :          0 :                         m_aText = ::rtl::OUString();
     643                 :            : 
     644         [ #  # ]:          0 :                     if ( m_aText.isEmpty() )
     645                 :            :                     {
     646 [ #  # ][ #  # ]:          0 :                         while ( xListBox->getSelectedItemPos() >= 0 )
                 [ #  # ]
     647                 :            :                         {
     648 [ #  # ][ #  # ]:          0 :                             xListBox->selectItemPos( xListBox->getSelectedItemPos(), sal_False );
         [ #  # ][ #  # ]
     649                 :            :                         }
     650                 :            :                     }
     651                 :            :                     else
     652                 :            :                     {
     653 [ #  # ][ #  # ]:          0 :                         xListBox->selectItem( m_aText, sal_True );
     654                 :            :                     }
     655                 :          0 :                 }
     656                 :            :             }
     657                 :          0 :             break;
     658                 :            : 
     659                 :            :             default:
     660                 :            :             {
     661 [ #  # ][ #  # ]:          0 :                 Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     662         [ #  # ]:          0 :                 if (xText.is())
     663                 :            :                 {
     664                 :          0 :                     m_aText = aText;
     665 [ #  # ][ #  # ]:          0 :                     xText->setText(aText);
     666                 :          0 :                 }
     667                 :            :             }
     668                 :            :         }
     669                 :            :     }
     670                 :            : 
     671                 :            :     //---------------------------------------------------------------------
     672                 :          0 :     void SAL_CALL OFilterControl::insertText( const ::com::sun::star::awt::Selection& rSel, const ::rtl::OUString& aText ) throw(::com::sun::star::uno::RuntimeException)
     673                 :            :     {
     674 [ #  # ][ #  # ]:          0 :         Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     675         [ #  # ]:          0 :         if (xText.is())
     676                 :            :         {
     677 [ #  # ][ #  # ]:          0 :             xText->insertText(rSel, aText);
     678 [ #  # ][ #  # ]:          0 :             m_aText = xText->getText();
     679                 :          0 :         }
     680                 :          0 :     }
     681                 :            : 
     682                 :            :     //---------------------------------------------------------------------
     683                 :          0 :     ::rtl::OUString SAL_CALL OFilterControl::getText() throw(RuntimeException)
     684                 :            :     {
     685                 :          0 :         return m_aText;
     686                 :            :     }
     687                 :            : 
     688                 :            :     //---------------------------------------------------------------------
     689                 :          0 :     ::rtl::OUString SAL_CALL OFilterControl::getSelectedText( void ) throw(RuntimeException)
     690                 :            :     {
     691                 :          0 :         ::rtl::OUString aSelected;
     692 [ #  # ][ #  # ]:          0 :         Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     693         [ #  # ]:          0 :         if (xText.is())
     694 [ #  # ][ #  # ]:          0 :             aSelected = xText->getSelectedText();
     695                 :            : 
     696                 :          0 :         return aSelected;
     697                 :            :     }
     698                 :            : 
     699                 :            :     //---------------------------------------------------------------------
     700                 :          0 :     void SAL_CALL OFilterControl::setSelection( const ::com::sun::star::awt::Selection& aSelection ) throw(::com::sun::star::uno::RuntimeException)
     701                 :            :     {
     702 [ #  # ][ #  # ]:          0 :         Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     703         [ #  # ]:          0 :         if (xText.is())
     704 [ #  # ][ #  # ]:          0 :             xText->setSelection( aSelection );
     705                 :          0 :     }
     706                 :            : 
     707                 :            :     //---------------------------------------------------------------------
     708                 :          0 :     ::com::sun::star::awt::Selection SAL_CALL OFilterControl::getSelection( void ) throw(::com::sun::star::uno::RuntimeException)
     709                 :            :     {
     710                 :          0 :         ::com::sun::star::awt::Selection aSel;
     711 [ #  # ][ #  # ]:          0 :         Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     712         [ #  # ]:          0 :         if (xText.is())
     713 [ #  # ][ #  # ]:          0 :             aSel = xText->getSelection();
     714                 :          0 :         return aSel;
     715                 :            :     }
     716                 :            : 
     717                 :            :     //---------------------------------------------------------------------
     718                 :          0 :     sal_Bool SAL_CALL OFilterControl::isEditable( void ) throw(RuntimeException)
     719                 :            :     {
     720 [ #  # ][ #  # ]:          0 :         Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     721 [ #  # ][ #  # ]:          0 :         return xText.is() && xText->isEditable();
         [ #  # ][ #  # ]
     722                 :            :     }
     723                 :            : 
     724                 :            :     //---------------------------------------------------------------------
     725                 :          0 :     void SAL_CALL OFilterControl::setEditable( sal_Bool bEditable ) throw(RuntimeException)
     726                 :            :     {
     727 [ #  # ][ #  # ]:          0 :         Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     728         [ #  # ]:          0 :         if (xText.is())
     729 [ #  # ][ #  # ]:          0 :             xText->setEditable(bEditable);
     730                 :          0 :     }
     731                 :            : 
     732                 :            :     //---------------------------------------------------------------------
     733                 :          0 :     sal_Int16 SAL_CALL OFilterControl::getMaxTextLen() throw(RuntimeException)
     734                 :            :     {
     735 [ #  # ][ #  # ]:          0 :         Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     736 [ #  # ][ #  # ]:          0 :         return xText.is() ? xText->getMaxTextLen() : 0;
                 [ #  # ]
     737                 :            :     }
     738                 :            : 
     739                 :            :     //---------------------------------------------------------------------
     740                 :          0 :     void SAL_CALL OFilterControl::setMaxTextLen( sal_Int16 nLength ) throw(RuntimeException)
     741                 :            :     {
     742 [ #  # ][ #  # ]:          0 :         Reference< XTextComponent >  xText( getPeer(), UNO_QUERY );
     743         [ #  # ]:          0 :         if (xText.is())
     744 [ #  # ][ #  # ]:          0 :             xText->setMaxTextLen(nLength);
     745                 :          0 :     }
     746                 :            : 
     747                 :            :     //---------------------------------------------------------------------
     748                 :          0 :     void OFilterControl::displayException( const ::com::sun::star::sdb::SQLContext& _rExcept )
     749                 :            :     {
     750                 :            :         try
     751                 :            :         {
     752         [ #  # ]:          0 :             Sequence< Any > aArgs(2);
     753 [ #  # ][ #  # ]:          0 :             aArgs[0] <<= PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SQLException") ), 0, makeAny( _rExcept ), PropertyState_DIRECT_VALUE);
         [ #  # ][ #  # ]
     754 [ #  # ][ #  # ]:          0 :             aArgs[1] <<= PropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow") ), 0, makeAny( m_xMessageParent ), PropertyState_DIRECT_VALUE);
         [ #  # ][ #  # ]
     755                 :            : 
     756 [ #  # ][ #  # ]:          0 :             static ::rtl::OUString s_sDialogServiceName (RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.ErrorMessageDialog") );
         [ #  # ][ #  # ]
     757                 :            : 
     758 [ #  # ][ #  # ]:          0 :             Reference< XExecutableDialog > xErrorDialog( maContext.createComponentWithArguments( s_sDialogServiceName, aArgs ), UNO_QUERY );
     759         [ #  # ]:          0 :             if ( xErrorDialog.is() )
     760 [ #  # ][ #  # ]:          0 :                 xErrorDialog->execute();
     761                 :            :             else
     762                 :            :             {
     763         [ #  # ]:          0 :                 Window* pMessageParent = VCLUnoHelper::GetWindow( m_xMessageParent );
     764 [ #  # ][ #  # ]:          0 :                 ShowServiceNotAvailableError( pMessageParent, s_sDialogServiceName, sal_True );
                 [ #  # ]
     765 [ #  # ][ #  # ]:          0 :             }
     766                 :            :         }
     767                 :          0 :         catch( const Exception& )
     768                 :            :         {
     769                 :            :             DBG_UNHANDLED_EXCEPTION();
     770                 :            :         }
     771                 :          0 :     }
     772                 :            : 
     773                 :            :     //---------------------------------------------------------------------
     774                 :          0 :     void SAL_CALL OFilterControl::initialize( const Sequence< Any >& aArguments ) throw (Exception, RuntimeException)
     775                 :            :     {
     776                 :          0 :         const Any* pArguments = aArguments.getConstArray();
     777                 :          0 :         const Any* pArgumentsEnd = pArguments + aArguments.getLength();
     778                 :            : 
     779                 :          0 :         PropertyValue aProp;
     780                 :          0 :         NamedValue aValue;
     781                 :          0 :         const ::rtl::OUString* pName = NULL;
     782                 :          0 :         const Any* pValue = NULL;
     783                 :            : 
     784         [ #  # ]:          0 :         for ( ; pArguments != pArgumentsEnd; ++pArguments )
     785                 :            :         {
     786                 :            :             // we recognize PropertyValues and NamedValues
     787 [ #  # ][ #  # ]:          0 :             if ( *pArguments >>= aProp )
     788                 :            :             {
     789                 :          0 :                 pName = &aProp.Name;
     790                 :          0 :                 pValue = &aProp.Value;
     791                 :            :             }
     792 [ #  # ][ #  # ]:          0 :             else if ( *pArguments >>= aValue )
     793                 :            :             {
     794                 :          0 :                 pName = &aValue.Name;
     795                 :          0 :                 pValue = &aValue.Value;
     796                 :            :             }
     797                 :            :             else
     798                 :            :             {
     799                 :            :                 OSL_FAIL( "OFilterControl::initialize: unrecognized argument!" );
     800                 :          0 :                 continue;
     801                 :            :             }
     802                 :            : 
     803         [ #  # ]:          0 :             if ( 0 == pName->compareToAscii( "MessageParent" ) )
     804                 :            :             {
     805                 :            :                 // the message parent
     806         [ #  # ]:          0 :                 *pValue >>= m_xMessageParent;
     807                 :            :                 OSL_ENSURE( m_xMessageParent.is(), "OFilterControl::initialize: invalid MessageParent!" );
     808                 :            :             }
     809         [ #  # ]:          0 :             else if ( 0 == pName->compareToAscii( "NumberFormatter" ) )
     810                 :            :             {
     811                 :            :                 // the number format. This argument is optional.
     812         [ #  # ]:          0 :                 *pValue >>= m_xFormatter;
     813                 :            :                 OSL_ENSURE( m_xFormatter.is(), "OFilterControl::initialize: invalid NumberFormatter!" );
     814                 :            :             }
     815         [ #  # ]:          0 :             else if ( 0 == pName->compareToAscii( "ControlModel" ) )
     816                 :            :             {
     817                 :            :                 // the control model for which we act as filter control
     818                 :          0 :                 Reference< XPropertySet > xControlModel;
     819 [ #  # ][ #  # ]:          0 :                 if ( !(*pValue >>= xControlModel ) || !xControlModel.is() )
         [ #  # ][ #  # ]
     820                 :            :                 {
     821                 :            :                     OSL_FAIL( "OFilterControl::initialize: invalid control model argument!" );
     822                 :          0 :                     continue;
     823                 :            :                 }
     824                 :            : 
     825                 :            :                 // some properties which are "derived" from the control model we're working for
     826                 :            :                 // ...................................................
     827                 :            :                 // the field
     828                 :          0 :                 m_xField.clear();
     829                 :            :                 OSL_ENSURE( ::comphelper::hasProperty( PROPERTY_BOUNDFIELD, xControlModel ), "OFilterControl::initialize: control model needs a bound field property!" );
     830 [ #  # ][ #  # ]:          0 :                 xControlModel->getPropertyValue( PROPERTY_BOUNDFIELD ) >>= m_xField;
         [ #  # ][ #  # ]
     831                 :            : 
     832                 :            :                 // ...................................................
     833                 :            :                 // filter list and control class
     834 [ #  # ][ #  # ]:          0 :                 m_bFilterList = ::comphelper::hasProperty( PROPERTY_FILTERPROPOSAL, xControlModel ) && ::comphelper::getBOOL( xControlModel->getPropertyValue( PROPERTY_FILTERPROPOSAL ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
           [ #  #  #  #  
           #  # ][ #  # ]
     835         [ #  # ]:          0 :                 if ( m_bFilterList )
     836                 :          0 :                     m_nControlClass = FormComponentType::COMBOBOX;
     837                 :            :                 else
     838                 :            :                 {
     839 [ #  # ][ #  # ]:          0 :                     sal_Int16 nClassId = ::comphelper::getINT16( xControlModel->getPropertyValue( PROPERTY_CLASSID ) );
         [ #  # ][ #  # ]
     840         [ #  # ]:          0 :                     switch (nClassId)
     841                 :            :                     {
     842                 :            :                         case FormComponentType::CHECKBOX:
     843                 :            :                         case FormComponentType::RADIOBUTTON:
     844                 :            :                         case FormComponentType::LISTBOX:
     845                 :            :                         case FormComponentType::COMBOBOX:
     846                 :          0 :                             m_nControlClass = nClassId;
     847         [ #  # ]:          0 :                             if ( FormComponentType::LISTBOX == nClassId )
     848                 :            :                             {
     849         [ #  # ]:          0 :                                 Sequence< ::rtl::OUString > aDisplayItems;
     850 [ #  # ][ #  # ]:          0 :                                 OSL_VERIFY( xControlModel->getPropertyValue( PROPERTY_STRINGITEMLIST ) >>= aDisplayItems );
         [ #  # ][ #  # ]
     851         [ #  # ]:          0 :                                 Sequence< ::rtl::OUString > aValueItems;
     852 [ #  # ][ #  # ]:          0 :                                 OSL_VERIFY( xControlModel->getPropertyValue( PROPERTY_VALUE_SEQ ) >>= aValueItems );
         [ #  # ][ #  # ]
     853                 :            :                                 OSL_ENSURE( aDisplayItems.getLength() == aValueItems.getLength(), "OFilterControl::initialize: inconsistent item lists!" );
     854 [ #  # ][ #  # ]:          0 :                                 for ( sal_Int32 i=0; i < ::std::min( aDisplayItems.getLength(), aValueItems.getLength() ); ++i )
     855 [ #  # ][ #  # ]:          0 :                                     m_aDisplayItemToValueItem[ aDisplayItems[i] ] = aValueItems[i];
         [ #  # ][ #  # ]
                 [ #  # ]
     856                 :            :                             }
     857                 :          0 :                             break;
     858                 :            :                         default:
     859 [ #  # ][ #  # ]:          0 :                             m_bMultiLine = ::comphelper::hasProperty( PROPERTY_MULTILINE, xControlModel ) && ::comphelper::getBOOL( xControlModel->getPropertyValue( PROPERTY_MULTILINE ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
     860                 :          0 :                             m_nControlClass = FormComponentType::TEXTFIELD;
     861                 :          0 :                             break;
     862                 :            :                     }
     863                 :            :                 }
     864                 :            : 
     865                 :            :                 // ...................................................
     866                 :            :                 // the connection meta data for the form which we're working for
     867         [ #  # ]:          0 :                 Reference< XChild > xModel( xControlModel, UNO_QUERY );
     868                 :          0 :                 Reference< XRowSet > xForm;
     869         [ #  # ]:          0 :                 if ( xModel.is() )
     870 [ #  # ][ #  # ]:          0 :                     xForm = xForm.query( xModel->getParent() );
         [ #  # ][ #  # ]
     871 [ #  # ][ #  # ]:          0 :                 m_xConnection = ::dbtools::getConnection( xForm );
     872         [ #  # ]:          0 :                 OSL_ENSURE( m_xConnection.is(), "OFilterControl::initialize: unable to determine the form's connection!" );
     873                 :            :             }
     874                 :          0 :         }
     875                 :          0 :     }
     876                 :            : 
     877                 :            :     //---------------------------------------------------------------------
     878                 :          0 :     ::rtl::OUString SAL_CALL OFilterControl::getImplementationName(  ) throw (RuntimeException)
     879                 :            :     {
     880                 :          0 :         return getImplementationName_Static();
     881                 :            :     }
     882                 :            : 
     883                 :            :     //---------------------------------------------------------------------
     884                 :          0 :     sal_Bool SAL_CALL OFilterControl::supportsService( const ::rtl::OUString& ServiceName ) throw (RuntimeException)
     885                 :            :     {
     886         [ #  # ]:          0 :         Sequence< ::rtl::OUString > aSupported( getSupportedServiceNames() );
     887                 :          0 :         const ::rtl::OUString* pArray = aSupported.getConstArray();
     888         [ #  # ]:          0 :         for( sal_Int32 i = 0; i < aSupported.getLength(); ++i, ++pArray )
     889         [ #  # ]:          0 :             if( pArray->equals( ServiceName ) )
     890                 :          0 :                 return sal_True;
     891         [ #  # ]:          0 :         return sal_False;
     892                 :            :     }
     893                 :            : 
     894                 :            :     //---------------------------------------------------------------------
     895                 :          0 :     Sequence< ::rtl::OUString > SAL_CALL OFilterControl::getSupportedServiceNames(  ) throw (RuntimeException)
     896                 :            :     {
     897                 :          0 :         return getSupportedServiceNames_Static();
     898                 :            :     }
     899                 :            : 
     900                 :            :     //---------------------------------------------------------------------
     901                 :         60 :     ::rtl::OUString SAL_CALL OFilterControl::getImplementationName_Static()
     902                 :            :     {
     903                 :         60 :         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.forms.OFilterControl" ) );
     904                 :            :     }
     905                 :            : 
     906                 :            :     //---------------------------------------------------------------------
     907                 :         30 :     Sequence< ::rtl::OUString > SAL_CALL OFilterControl::getSupportedServiceNames_Static()
     908                 :            :     {
     909                 :         30 :         Sequence< ::rtl::OUString > aNames( 2 );
     910 [ +  - ][ +  - ]:         30 :         aNames[ 0 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.control.FilterControl" ) );
     911 [ +  - ][ +  - ]:         30 :         aNames[ 1 ] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControl" ) );
     912                 :         30 :         return aNames;
     913                 :            :     }
     914                 :            : 
     915                 :            :     //---------------------------------------------------------------------
     916                 :          0 :     Reference< XInterface > SAL_CALL OFilterControl::Create( const Reference< XMultiServiceFactory >& _rxFactory )
     917                 :            :     {
     918 [ #  # ][ #  # ]:          0 :         return static_cast< XServiceInfo* >( new OFilterControl( _rxFactory ) );
     919                 :            :     }
     920                 :            : 
     921                 :            : //.........................................................................
     922                 :            : }   // namespace frm
     923                 :            : //.........................................................................
     924                 :            : 
     925                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10