LCOV - code coverage report
Current view: top level - forms/source/component - GroupManager.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 24 0.0 %
Date: 2014-04-14 Functions: 0 20 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_FORMS_SOURCE_COMPONENT_GROUPMANAGER_HXX
      21             : #define INCLUDED_FORMS_SOURCE_COMPONENT_GROUPMANAGER_HXX
      22             : 
      23             : #include <com/sun/star/sdbc/XRowSet.hpp>
      24             : #include <com/sun/star/awt/XControlModel.hpp>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : #include <com/sun/star/beans/XPropertyChangeListener.hpp>
      27             : #include <com/sun/star/container/XContainerListener.hpp>
      28             : #include <com/sun/star/container/XContainer.hpp>
      29             : #include <cppuhelper/implbase2.hxx>
      30             : #include <comphelper/types.hxx>
      31             : 
      32             : #include <algorithm>
      33             : #include <map>
      34             : #include <vector>
      35             : 
      36             : using namespace comphelper;
      37             : 
      38             : /*========================================================================
      39             : Funktionsweise GroupManager:
      40             : 
      41             : Der GroupManager horcht an der starform, ob FormComponents eingefuegt oder entfernt
      42             : werden. Zusaetzlich horcht er bei den FormComponents an den Properties
      43             : "Name" und "TabIndex". Mit diesen Infos aktualisiert er seine Gruppen.
      44             : 
      45             : Der GroupManager verwaltet eine Gruppe, in der alle Controls nach TabIndex
      46             : geordnet sind, und ein Array von Gruppen, in dem jede FormComponent noch
      47             : einmal einer Gruppe dem Namen nach zugeordnet wird.
      48             : Die einzelnen Gruppen werden ueber eine Map aktiviert, wenn sie mehr als
      49             : ein Element besitzen.
      50             : 
      51             : Die Gruppen verwalten intern die FormComponents in zwei Arrays. In dem
      52             : GroupCompArray werden die Components nach TabIndex und Einfuegepostion
      53             : sortiert. Da auf dieses Array ueber die FormComponent zugegriffen
      54             : wird, gibt es noch das GroupCompAccessArray, in dem die FormComponents
      55             : nach ihrer Speicheradresse sortiert sind. Jedes Element des
      56             : GroupCompAccessArrays ist mit einem Element des GroupCompArrays verpointert.
      57             : 
      58             : ========================================================================*/
      59             : 
      60             : 
      61             : namespace frm
      62             : {
      63             : 
      64             : 
      65             : 
      66             :     template <class ELEMENT, class LESS_COMPARE>
      67           0 :     sal_Int32 insert_sorted(::std::vector<ELEMENT>& _rArray, const ELEMENT& _rNewElement, const LESS_COMPARE& _rCompareOp)
      68             :     {
      69             :         typename ::std::vector<ELEMENT>::iterator aInsertPos = ::std::lower_bound(
      70             :             _rArray.begin(),
      71             :             _rArray.end(),
      72             :             _rNewElement,
      73             :             _rCompareOp
      74           0 :         );
      75           0 :         aInsertPos = _rArray.insert(aInsertPos, _rNewElement);
      76           0 :         return aInsertPos - _rArray.begin();
      77             :     }
      78             : 
      79             :     template <class ELEMENT, class LESS_COMPARE>
      80           0 :     sal_Bool seek_entry(const ::std::vector<ELEMENT>& _rArray, const ELEMENT& _rNewElement, sal_Int32& nPos, const LESS_COMPARE& _rCompareOp)
      81             :     {
      82             :         typename ::std::vector<ELEMENT>::const_iterator aExistentPos = ::std::lower_bound(
      83             :             _rArray.begin(),
      84             :             _rArray.end(),
      85             :             _rNewElement,
      86             :             _rCompareOp
      87           0 :         );
      88           0 :         if ((aExistentPos != _rArray.end()) && (*aExistentPos == _rNewElement))
      89             :         {   // we have a valid "lower or equal" element and it's really "equal"
      90           0 :             nPos = aExistentPos - _rArray.begin();
      91           0 :             return sal_True;
      92             :         }
      93           0 :         nPos = -1;
      94           0 :         return sal_False;
      95             :     }
      96             : 
      97             : 
      98           0 : class OGroupComp
      99             : {
     100             :     OUString m_aName;
     101             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>    m_xComponent;
     102             :     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>     m_xControlModel;
     103             :     sal_Int32   m_nPos;
     104             :     sal_Int16   m_nTabIndex;
     105             : 
     106             :     friend class OGroupCompLess;
     107             : 
     108             : public:
     109             :     OGroupComp(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement, sal_Int32 nInsertPos );
     110             :     OGroupComp(const OGroupComp& _rSource);
     111             :     OGroupComp();
     112             : 
     113             :     sal_Bool operator==( const OGroupComp& rComp ) const;
     114             : 
     115           0 :     inline const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& GetComponent() const { return m_xComponent; }
     116           0 :     inline const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>&   GetControlModel() const { return m_xControlModel; }
     117             : 
     118           0 :     sal_Int32   GetPos() const { return m_nPos; }
     119           0 :     sal_Int16   GetTabIndex() const { return m_nTabIndex; }
     120             :     OUString GetName() const { return m_aName; }
     121             : };
     122             : 
     123             : typedef std::vector<OGroupComp> OGroupCompArr;
     124             : 
     125             : 
     126             : class OGroupComp;
     127           0 : class OGroupCompAcc
     128             : {
     129             :     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>    m_xComponent;
     130             : 
     131             :     OGroupComp                                      m_aGroupComp;
     132             : 
     133             :     friend class OGroupCompAccLess;
     134             : 
     135             : public:
     136             :     OGroupCompAcc(const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement, const OGroupComp& _rGroupComp );
     137             : 
     138             :     sal_Bool operator==( const OGroupCompAcc& rCompAcc ) const;
     139             : 
     140           0 :     inline const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>&  GetComponent() const { return m_xComponent; }
     141           0 :     const OGroupComp&   GetGroupComponent() const { return m_aGroupComp; }
     142             : };
     143             : 
     144             : typedef std::vector<OGroupCompAcc> OGroupCompAccArr;
     145             : 
     146             : 
     147           0 : class OGroup
     148             : {
     149             :     OGroupCompArr       m_aCompArray;
     150             :     OGroupCompAccArr    m_aCompAccArray;
     151             : 
     152             :     OUString m_aGroupName;
     153             :     sal_uInt16  m_nInsertPos;               // Die Einfugeposition der GroupComps wird von der Gruppe bestimmt.
     154             : 
     155             :     friend class OGroupLess;
     156             : 
     157             : public:
     158             :     OGroup( const OUString& rGroupName );
     159             :     virtual ~OGroup();
     160             : 
     161             :     sal_Bool operator==( const OGroup& rGroup ) const;
     162             : 
     163           0 :     OUString GetGroupName() const { return m_aGroupName; }
     164             :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>  > GetControlModels() const;
     165             : 
     166             :     void InsertComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement );
     167             :     void RemoveComponent( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement );
     168           0 :     sal_uInt16 Count() const { return sal::static_int_cast< sal_uInt16 >(m_aCompArray.size()); }
     169           0 :     const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& GetObject( sal_uInt16 nP ) const
     170           0 :         { return m_aCompArray[nP].GetComponent(); }
     171             : };
     172             : 
     173             : typedef std::map<OUString, OGroup> OGroupArr;
     174             : typedef std::vector<OGroupArr::iterator> OActiveGroups;
     175             : 
     176             : 
     177             : class OGroupManager : public ::cppu::WeakImplHelper2< ::com::sun::star::beans::XPropertyChangeListener, ::com::sun::star::container::XContainerListener>
     178             : {
     179             :     OGroup*         m_pCompGroup;           // Alle Components nach TabIndices sortiert
     180             :     OGroupArr       m_aGroupArr;            // Alle Components nach Gruppen sortiert
     181             :     OActiveGroups   m_aActiveGroupMap;      // In dieser Map werden die Indices aller Gruppen gehalten,
     182             :                                         // die mehr als 1 Element haben
     183             : 
     184             :     ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >
     185             :                     m_xContainer;
     186             : 
     187             :     // Helper functions
     188             :     void InsertElement( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement );
     189             :     void RemoveElement( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& rxElement );
     190             :     void removeFromGroupMap(const OUString& _sGroupName,const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _xSet);
     191             : 
     192             : public:
     193             :     OGroupManager(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& _rxContainer);
     194             :     virtual ~OGroupManager();
     195             : 
     196             : // ::com::sun::star::lang::XEventListener
     197             :     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     198             : 
     199             : // ::com::sun::star::beans::XPropertyChangeListener
     200             :     virtual void SAL_CALL propertyChange(const ::com::sun::star::beans::PropertyChangeEvent& evt) throw ( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     201             : 
     202             : // ::com::sun::star::container::XContainerListener
     203             :     virtual void SAL_CALL elementInserted(const ::com::sun::star::container::ContainerEvent& _rEvent) throw ( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     204             :     virtual void SAL_CALL elementRemoved(const ::com::sun::star::container::ContainerEvent& _rEvent) throw ( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     205             :     virtual void SAL_CALL elementReplaced(const ::com::sun::star::container::ContainerEvent& _rEvent) throw ( ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     206             : 
     207             : // Other functions
     208             :     sal_Int32 getGroupCount();
     209             :     void getGroup(sal_Int32 nGroup, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> >& _rGroup, OUString& Name);
     210             :     void getGroupByName(const OUString& Name, ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> >& _rGroup);
     211             :     ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel> > getControlModels();
     212             : 
     213             :     static OUString GetGroupName( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> xComponent );
     214             : };
     215             : 
     216             : 
     217             : 
     218             : }   // namespace frm
     219             : 
     220             : 
     221             : #endif // INCLUDED_FORMS_SOURCE_COMPONENT_GROUPMANAGER_HXX
     222             : 
     223             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10