LCOV - code coverage report
Current view: top level - forms/source/component - ListBox.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 5 60.0 %
Date: 2012-08-25 Functions: 7 9 77.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 4 25.0 %

           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                 :            : #ifndef _FORMS_LISTBOX_HXX_
      30                 :            : #define _FORMS_LISTBOX_HXX_
      31                 :            : 
      32                 :            : #include "FormComponent.hxx"
      33                 :            : #include "cachedrowset.hxx"
      34                 :            : #include "errorbroadcaster.hxx"
      35                 :            : #include "entrylisthelper.hxx"
      36                 :            : 
      37                 :            : #include <com/sun/star/util/XNumberFormatter.hpp>
      38                 :            : #include <com/sun/star/sdb/XSQLErrorBroadcaster.hpp>
      39                 :            : #include <com/sun/star/form/ListSourceType.hpp>
      40                 :            : #include <com/sun/star/awt/XItemListener.hpp>
      41                 :            : #include <com/sun/star/awt/XFocusListener.hpp>
      42                 :            : #include <com/sun/star/awt/XListBox.hpp>
      43                 :            : #include <com/sun/star/form/XChangeBroadcaster.hpp>
      44                 :            : #include <com/sun/star/sdbc/DataType.hpp>
      45                 :            : 
      46                 :            : #include <comphelper/asyncnotification.hxx>
      47                 :            : #include <connectivity/FValue.hxx>
      48                 :            : #include <cppuhelper/interfacecontainer.hxx>
      49                 :            : #include <cppuhelper/implbase1.hxx>
      50                 :            : #include <vcl/timer.hxx>
      51                 :            : 
      52                 :            : #include <vector>
      53                 :            : 
      54                 :            : //.........................................................................
      55                 :            : namespace frm
      56                 :            : {
      57                 :            : 
      58                 :            : //==================================================================
      59                 :            : //= OListBoxModel
      60                 :            : //==================================================================
      61                 :            : typedef ::std::vector< ::connectivity::ORowSetValue >   ValueList;
      62                 :            : 
      63                 :            : class OListBoxModel :public OBoundControlModel
      64                 :            :                     ,public OEntryListHelper
      65                 :            :                     ,public OErrorBroadcaster
      66                 :            : {
      67                 :            : 
      68                 :            :     CachedRowSet                                m_aListRowSet;          // the row set to fill the list
      69                 :            :     ::connectivity::ORowSetValue                m_aSaveValue;
      70                 :            : 
      71                 :            :     // <properties>
      72                 :            :     ::com::sun::star::form::ListSourceType      m_eListSourceType;      // type der list source
      73                 :            :     ::com::sun::star::uno::Any                  m_aBoundColumn;
      74                 :            :     ValueList                                   m_aListSourceValues;
      75                 :            :     ValueList                                   m_aBoundValues;         // do not write directly; use setBoundValues()
      76                 :            :     mutable ValueList                           m_aConvertedBoundValues;
      77                 :            :     mutable sal_Int32                           m_nConvertedBoundValuesType;
      78                 :            :     ::com::sun::star::uno::Sequence<sal_Int16>  m_aDefaultSelectSeq;    // DefaultSelected
      79                 :            :     // </properties>
      80                 :            : 
      81                 :            :     sal_Int16                                   m_nNULLPos;             // position of the NULL value in our list
      82                 :            :     sal_Int32                                   m_nBoundColumnType;
      83                 :            : 
      84                 :            : private:
      85                 :            :     ::connectivity::ORowSetValue getFirstSelectedValue() const;
      86                 :            : 
      87                 :            :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>   _getTypes();
      88                 :            : 
      89                 :            : public:
      90                 :            :     DECLARE_DEFAULT_LEAF_XTOR( OListBoxModel );
      91                 :            : 
      92                 :            : // XServiceInfo
      93         [ +  - ]:         14 :     IMPLEMENTATION_NAME(OListBoxModel);
      94                 :            :     virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
      95                 :            : 
      96                 :            : // UNO Anbindung
      97                 :     181123 :     DECLARE_UNO3_AGG_DEFAULTS(OListBoxModel, OBoundControlModel);
      98                 :            :     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
      99                 :            : 
     100                 :            : // OComponentHelper
     101                 :            :     virtual void SAL_CALL disposing();
     102                 :            : 
     103                 :            : // OPropertySetHelper
     104                 :            :     virtual void SAL_CALL getFastPropertyValue(::com::sun::star::uno::Any& rValue, sal_Int32 nHandle) const;
     105                 :            :     virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue )
     106                 :            :                 throw (::com::sun::star::uno::Exception);
     107                 :            :     virtual sal_Bool SAL_CALL convertFastPropertyValue(
     108                 :            :                 ::com::sun::star::uno::Any& _rConvertedValue, ::com::sun::star::uno::Any& _rOldValue, sal_Int32 _nHandle, const ::com::sun::star::uno::Any& _rValue )
     109                 :            :                 throw (::com::sun::star::lang::IllegalArgumentException);
     110                 :            : 
     111                 :            : protected:
     112                 :            :     // XMultiPropertySet
     113                 :            :     virtual void SAL_CALL   setPropertyValues(const ::com::sun::star::uno::Sequence< ::rtl::OUString >& PropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
     114                 :            : 
     115                 :            :     // XPersistObject
     116                 :            :     virtual ::rtl::OUString SAL_CALL    getServiceName() throw(::com::sun::star::uno::RuntimeException);
     117                 :            :     virtual void SAL_CALL
     118                 :            :         write(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream>& _rxOutStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
     119                 :            :     virtual void SAL_CALL
     120                 :            :         read(const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream>& _rxInStream) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
     121                 :            : 
     122                 :            :     // OControlModel's property handling
     123                 :            :     virtual void describeFixedProperties(
     124                 :            :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rProps
     125                 :            :     ) const;
     126                 :            :     virtual void describeAggregateProperties(
     127                 :            :         ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property >& /* [out] */ _rAggregateProps
     128                 :            :     ) const;
     129                 :            : 
     130                 :            :     // XEventListener
     131                 :            :     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
     132                 :            : 
     133                 :            :     // OPropertyChangeListener
     134                 :            :     virtual void    _propertyChanged( const ::com::sun::star::beans::PropertyChangeEvent& _rEvt ) throw ( ::com::sun::star::uno::RuntimeException );
     135                 :            : 
     136                 :            :     // prevent method hiding
     137                 :            :     using OBoundControlModel::getFastPropertyValue;
     138                 :            :     using OBoundControlModel::setPropertyValues;
     139                 :            : 
     140                 :            : protected:
     141                 :            :     // OBoundControlModel overridables
     142                 :            :     virtual ::com::sun::star::uno::Any
     143                 :            :                             translateDbColumnToControlValue( );
     144                 :            :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type >
     145                 :            :                             getSupportedBindingTypes();
     146                 :            :     virtual ::com::sun::star::uno::Any
     147                 :            :                             translateExternalValueToControlValue( const ::com::sun::star::uno::Any& _rExternalValue ) const;
     148                 :            :     virtual ::com::sun::star::uno::Any
     149                 :            :                             translateControlValueToExternalValue( ) const;
     150                 :            :     virtual sal_Bool        commitControlValueToDbColumn( bool _bPostReset );
     151                 :            : 
     152                 :            :     virtual void            onConnectedDbColumn( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxForm );
     153                 :            :     virtual void            onDisconnectedDbColumn();
     154                 :            : 
     155                 :            :     virtual ::com::sun::star::uno::Any
     156                 :            :                             getDefaultForReset() const;
     157                 :            :     virtual void            resetNoBroadcast();
     158                 :            : 
     159                 :            :     virtual ::com::sun::star::uno::Any
     160                 :            :                             getCurrentFormComponentValue() const;
     161                 :            : 
     162                 :            :     // OEntryListHelper overriables
     163                 :            :     virtual void    stringItemListChanged( ControlModelLock& _rInstanceLock );
     164                 :            :     virtual void    connectedExternalListSource( );
     165                 :            :     virtual void    disconnectedExternalListSource( );
     166                 :            :     virtual void    refreshInternalEntryList();
     167                 :            : 
     168                 :            : protected:
     169                 :            :     DECLARE_XCLONEABLE();
     170                 :            : 
     171                 :            : private:
     172                 :            :     void        loadData( bool _bForce );
     173                 :            : 
     174                 :            :     /** refreshes the list boxes list data
     175                 :            :         @precond we don't actually have an external list source
     176                 :            :     */
     177                 :            :     void        impl_refreshDbEntryList( bool _bForce );
     178                 :            : 
     179                 :            :     void        setBoundValues(const ValueList&);
     180                 :            :     void        clearBoundValues();
     181                 :            : 
     182                 :            :     ValueList   impl_getValues() const;
     183                 :            : 
     184                 :            :     sal_Int32   getValueType() const;
     185                 :            : 
     186                 :            :     void        convertBoundValues(sal_Int32 nType) const;
     187                 :            : 
     188                 :          0 :     bool        impl_hasBoundComponent() const { return m_nBoundColumnType != ::com::sun::star::sdbc::DataType::SQLNULL; }
     189                 :            : };
     190                 :            : 
     191                 :            : //==================================================================
     192                 :            : //= OListBoxControl
     193                 :            : //==================================================================
     194                 :            : typedef ::cppu::ImplHelper4 <   ::com::sun::star::awt::XFocusListener
     195                 :            :                             ,   ::com::sun::star::awt::XItemListener
     196                 :            :                             ,   ::com::sun::star::awt::XListBox
     197                 :            :                             ,   ::com::sun::star::form::XChangeBroadcaster
     198                 :            :                             >   OListBoxControl_BASE;
     199                 :            : 
     200                 :            : class OListBoxControl   :public OBoundControl
     201                 :            :                         ,public OListBoxControl_BASE
     202                 :            :                         ,public IEventProcessor
     203                 :            : {
     204                 :            : private:
     205                 :            :     ::cppu::OInterfaceContainerHelper       m_aChangeListeners;
     206                 :            :     ::cppu::OInterfaceContainerHelper       m_aItemListeners;
     207                 :            : 
     208                 :            :     ::com::sun::star::uno::Any              m_aCurrentSelection;
     209                 :            :     Timer                                   m_aChangeTimer;
     210                 :            : 
     211                 :            :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XListBox >
     212                 :            :                                             m_xAggregateListBox;
     213                 :            : 
     214                 :            :     ::rtl::Reference< ::comphelper::AsyncEventNotifier >
     215                 :            :                                             m_pItemBroadcaster;
     216                 :            : 
     217                 :            : protected:
     218                 :            :     // UNO Anbindung
     219                 :            :     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type>   _getTypes();
     220                 :            : 
     221                 :            : public:
     222                 :            :     OListBoxControl(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory>& _rxFactory);
     223                 :            :     virtual ~OListBoxControl();
     224                 :            : 
     225                 :            :     // UNO Anbindung
     226                 :      74959 :     DECLARE_UNO3_AGG_DEFAULTS(OListBoxControl, OBoundControl);
     227                 :            :     virtual ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
     228                 :            : 
     229                 :            : // XServiceInfo
     230         [ #  # ]:          0 :     IMPLEMENTATION_NAME(OListBoxControl);
     231                 :            :     virtual StringSequence SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException);
     232                 :            : 
     233                 :            : // XChangeBroadcaster
     234                 :            :         virtual void SAL_CALL addChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XChangeListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
     235                 :            :     virtual void SAL_CALL removeChangeListener(const ::com::sun::star::uno::Reference< ::com::sun::star::form::XChangeListener>& _rxListener) throw(::com::sun::star::uno::RuntimeException);
     236                 :            : 
     237                 :            : // XFocusListener
     238                 :            :     virtual void SAL_CALL focusGained(const ::com::sun::star::awt::FocusEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
     239                 :            :     virtual void SAL_CALL focusLost(const ::com::sun::star::awt::FocusEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
     240                 :            : 
     241                 :            : // XItemListener
     242                 :            :     virtual void SAL_CALL itemStateChanged(const ::com::sun::star::awt::ItemEvent& _rEvent) throw(::com::sun::star::uno::RuntimeException);
     243                 :            : 
     244                 :            : // XEventListener
     245                 :            :     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& Source) throw (::com::sun::star::uno::RuntimeException);
     246                 :            : 
     247                 :            : // OComponentHelper
     248                 :            :     virtual void SAL_CALL disposing();
     249                 :            : 
     250                 :            : // XListBox
     251                 :            :     virtual void SAL_CALL addItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException);
     252                 :            :     virtual void SAL_CALL removeItemListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XItemListener >& l ) throw (::com::sun::star::uno::RuntimeException);
     253                 :            :     virtual void SAL_CALL addActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& l ) throw (::com::sun::star::uno::RuntimeException);
     254                 :            :     virtual void SAL_CALL removeActionListener( const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XActionListener >& l ) throw (::com::sun::star::uno::RuntimeException);
     255                 :            :     virtual void SAL_CALL addItem( const ::rtl::OUString& aItem, ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
     256                 :            :     virtual void SAL_CALL addItems( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& aItems, ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
     257                 :            :     virtual void SAL_CALL removeItems( ::sal_Int16 nPos, ::sal_Int16 nCount ) throw (::com::sun::star::uno::RuntimeException);
     258                 :            :     virtual ::sal_Int16 SAL_CALL getItemCount(  ) throw (::com::sun::star::uno::RuntimeException);
     259                 :            :     virtual ::rtl::OUString SAL_CALL getItem( ::sal_Int16 nPos ) throw (::com::sun::star::uno::RuntimeException);
     260                 :            :     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getItems(  ) throw (::com::sun::star::uno::RuntimeException);
     261                 :            :     virtual ::sal_Int16 SAL_CALL getSelectedItemPos(  ) throw (::com::sun::star::uno::RuntimeException);
     262                 :            :     virtual ::com::sun::star::uno::Sequence< ::sal_Int16 > SAL_CALL getSelectedItemsPos(  ) throw (::com::sun::star::uno::RuntimeException);
     263                 :            :     virtual ::rtl::OUString SAL_CALL getSelectedItem(  ) throw (::com::sun::star::uno::RuntimeException);
     264                 :            :     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSelectedItems(  ) throw (::com::sun::star::uno::RuntimeException);
     265                 :            :     virtual void SAL_CALL selectItemPos( ::sal_Int16 nPos, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
     266                 :            :     virtual void SAL_CALL selectItemsPos( const ::com::sun::star::uno::Sequence< ::sal_Int16 >& aPositions, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
     267                 :            :     virtual void SAL_CALL selectItem( const ::rtl::OUString& aItem, ::sal_Bool bSelect ) throw (::com::sun::star::uno::RuntimeException);
     268                 :            :     virtual ::sal_Bool SAL_CALL isMutipleMode(  ) throw (::com::sun::star::uno::RuntimeException);
     269                 :            :     virtual void SAL_CALL setMultipleMode( ::sal_Bool bMulti ) throw (::com::sun::star::uno::RuntimeException);
     270                 :            :     virtual ::sal_Int16 SAL_CALL getDropDownLineCount(  ) throw (::com::sun::star::uno::RuntimeException);
     271                 :            :     virtual void SAL_CALL setDropDownLineCount( ::sal_Int16 nLines ) throw (::com::sun::star::uno::RuntimeException);
     272                 :            :     virtual void SAL_CALL makeVisible( ::sal_Int16 nEntry ) throw (::com::sun::star::uno::RuntimeException);
     273                 :            : 
     274                 :            : protected:
     275                 :            :     // IEventProcessor
     276                 :            :     virtual void processEvent( const ::comphelper::AnyEvent& _rEvent );
     277                 :            : 
     278                 :            : private:
     279                 :            :     DECL_LINK( OnTimeout, void* );
     280                 :            : };
     281                 :            : 
     282                 :            : //.........................................................................
     283                 :            : }
     284                 :            : //.........................................................................
     285                 :            : 
     286                 :            : #endif // _FORMS_LISTBOX_HXX_
     287                 :            : 
     288                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10