LCOV - code coverage report
Current view: top level - desktop/source/deployment/gui - dp_gui_extlistbox.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 7 0.0 %
Date: 2014-04-14 Functions: 0 7 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             : #include "rtl/ustring.hxx"
      21             : #include "vcl/scrbar.hxx"
      22             : #include "vcl/fixed.hxx"
      23             : #include "vcl/fixedhyper.hxx"
      24             : #include "vcl/dialog.hxx"
      25             : 
      26             : #include "svtools/extensionlistbox.hxx"
      27             : #include "cppuhelper/implbase1.hxx"
      28             : #include "unotools/collatorwrapper.hxx"
      29             : 
      30             : #include "com/sun/star/lang/Locale.hpp"
      31             : #include "com/sun/star/lang/XEventListener.hpp"
      32             : #include "com/sun/star/deployment/XPackage.hpp"
      33             : 
      34             : #include <boost/shared_ptr.hpp>
      35             : 
      36             : namespace dp_gui {
      37             : 
      38             : #define SMALL_ICON_SIZE     16
      39             : #define TOP_OFFSET           5
      40             : #define ICON_HEIGHT         42
      41             : #define ICON_WIDTH          47
      42             : #define ICON_OFFSET         72
      43             : #define RIGHT_ICON_OFFSET    5
      44             : #define SPACE_BETWEEN        3
      45             : 
      46             : class TheExtensionManager;
      47             : 
      48             : typedef ::boost::shared_ptr< FixedHyperlink > TFixedHyperlink;
      49             : 
      50             : 
      51             : //                          struct Entry_Impl
      52             : 
      53             : struct Entry_Impl;
      54             : 
      55             : typedef ::boost::shared_ptr< Entry_Impl > TEntry_Impl;
      56             : 
      57             : struct Entry_Impl
      58             : {
      59             :     bool            m_bActive       :1;
      60             :     bool            m_bLocked       :1;
      61             :     bool            m_bHasOptions   :1;
      62             :     bool            m_bUser         :1;
      63             :     bool            m_bShared       :1;
      64             :     bool            m_bNew          :1;
      65             :     bool            m_bChecked      :1;
      66             :     bool            m_bMissingDeps  :1;
      67             :     bool            m_bHasButtons   :1;
      68             :     bool            m_bMissingLic   :1;
      69             :     PackageState    m_eState;
      70             :     OUString        m_sTitle;
      71             :     OUString        m_sVersion;
      72             :     OUString        m_sDescription;
      73             :     OUString        m_sPublisher;
      74             :     OUString        m_sPublisherURL;
      75             :     OUString        m_sErrorText;
      76             :     OUString        m_sLicenseText;
      77             :     Image           m_aIcon;
      78             :     Image           m_aIconHC;
      79             :     FixedHyperlink* m_pPublisher;
      80             : 
      81             :     ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage> m_xPackage;
      82             : 
      83             :     Entry_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
      84             :                 const PackageState eState, const bool bReadOnly );
      85             :    ~Entry_Impl();
      86             : 
      87             :     sal_Int32     CompareTo( const CollatorWrapper *pCollator, const TEntry_Impl pEntry ) const;
      88             :     void          checkDependencies();
      89             : };
      90             : 
      91             : 
      92             : //                          class ExtensionBox_Impl
      93             : 
      94             : 
      95             : class ExtensionBox_Impl;
      96             : 
      97             : 
      98             : class ExtensionRemovedListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
      99             : {
     100             :     ExtensionBox_Impl   *m_pParent;
     101             : 
     102             : public:
     103             : 
     104           0 :     ExtensionRemovedListener( ExtensionBox_Impl *pParent ) { m_pParent = pParent; }
     105             :    virtual ~ExtensionRemovedListener();
     106             : 
     107             : 
     108             :     // XEventListener
     109             :     virtual void SAL_CALL disposing( ::com::sun::star::lang::EventObject const & evt )
     110             :         throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     111             : };
     112             : 
     113             : 
     114             : class ExtensionBox_Impl : public ::svt::IExtensionListBox
     115             : {
     116             :     bool            m_bHasScrollBar;
     117             :     bool            m_bHasActive;
     118             :     bool            m_bNeedsRecalc;
     119             :     bool            m_bInCheckMode;
     120             :     bool            m_bAdjustActive;
     121             :     bool            m_bInDelete;
     122             :     //Must be guarded together with m_vEntries to ensure a valid index at all times.
     123             :     //Use m_entriesMutex as guard.
     124             :     long            m_nActive;
     125             :     long            m_nTopIndex;
     126             :     long            m_nStdHeight;
     127             :     long            m_nActiveHeight;
     128             :     long            m_nExtraHeight;
     129             :     Size            m_aOutputSize;
     130             :     Image           m_aSharedImage;
     131             :     Image           m_aLockedImage;
     132             :     Image           m_aWarningImage;
     133             :     Image           m_aDefaultImage;
     134             :     Link            m_aClickHdl;
     135             : 
     136             :     ScrollBar      *m_pScrollBar;
     137             : 
     138             :     com::sun::star::uno::Reference< ExtensionRemovedListener > m_xRemoveListener;
     139             : 
     140             :     TheExtensionManager      *m_pManager;
     141             :     //This mutex is used for synchronizing access to m_vEntries.
     142             :     //Currently it is used to synchronize adding, removing entries and
     143             :     //functions like getItemName, getItemDescription, etc. to prevent
     144             :     //that m_vEntries is accessed at an invalid index.
     145             :     //ToDo: There are many more places where m_vEntries is read and which may
     146             :     //fail. For example the Paint method is probable called from the main thread
     147             :     //while new entries are added / removed in a separate thread.
     148             :     mutable ::osl::Mutex    m_entriesMutex;
     149             :     std::vector< TEntry_Impl > m_vEntries;
     150             :     std::vector< TEntry_Impl > m_vRemovedEntries;
     151             : 
     152             :     ::com::sun::star::lang::Locale    *m_pLocale;
     153             :     CollatorWrapper *m_pCollator;
     154             : 
     155             :     //Holds weak references to extensions to which is we have added an XEventListener
     156             :     std::vector< ::com::sun::star::uno::WeakReference<
     157             :         ::com::sun::star::deployment::XPackage> > m_vListenerAdded;
     158             :     //Removes the dead weak references from m_vListenerAdded
     159             :     void cleanVecListenerAdded();
     160             :     void addEventListenerOnce( ::com::sun::star::uno::Reference<
     161             :                                ::com::sun::star::deployment::XPackage> const & extension);
     162             : 
     163             :     void            CalcActiveHeight( const long nPos );
     164             :     long            GetTotalHeight() const;
     165             :     void            SetupScrollBar();
     166             :     void            DrawRow( const Rectangle& rRect, const TEntry_Impl pEntry );
     167             :     bool            HandleTabKey( bool bReverse );
     168             :     bool            HandleCursorKey( sal_uInt16 nKeyCode );
     169             :     bool            FindEntryPos( const TEntry_Impl pEntry, long nStart, long nEnd, long &nFound );
     170             :     void            DeleteRemoved();
     171             : 
     172             : 
     173             :     DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar * );
     174             : 
     175             :     //Index starts with 1.
     176             :     //Throws an com::sun::star::lang::IllegalArgumentException, when the index is invalid.
     177             :     void checkIndex(sal_Int32 pos) const;
     178             : 
     179             : 
     180             :     void Init();
     181             : public:
     182             :                     ExtensionBox_Impl(Window* pParent);
     183             :                     ExtensionBox_Impl(Window* pParent, TheExtensionManager *pManager);
     184             :                    virtual ~ExtensionBox_Impl();
     185             : 
     186             :     virtual void    MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
     187             :     virtual void    Paint( const Rectangle &rPaintRect ) SAL_OVERRIDE;
     188             :     virtual void    Resize() SAL_OVERRIDE;
     189             :     virtual bool    Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
     190             : 
     191             :     const Size      GetMinOutputSizePixel() const;
     192           0 :     void            SetExtraSize( long nSize ) { m_nExtraHeight = nSize; }
     193           0 :     TEntry_Impl     GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
     194           0 :     long            GetEntryCount() { return (long) m_vEntries.size(); }
     195             :     Rectangle       GetEntryRect( const long nPos ) const;
     196           0 :     bool            HasActive() { return m_bHasActive; }
     197             :     long            PointToPos( const Point& rPos );
     198             :     void            SetScrollHdl( const Link& rLink );
     199             :     void            DoScroll( long nDelta );
     200           0 :     void            SetHyperlinkHdl( const Link& rLink ){ m_aClickHdl = rLink; }
     201             :     virtual void    RecalcAll();
     202             :     void            RemoveUnlocked();
     203             : 
     204             : 
     205             :     virtual void    selectEntry( const long nPos );
     206             :     long            addEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
     207             :                               bool bLicenseMissing = false );
     208             :     void            updateEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
     209             :     void            removeEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
     210             : 
     211             :     void            prepareChecking();
     212             :     void            checkEntries();
     213             : 
     214             :     TheExtensionManager*    getExtensionManager() const { return m_pManager; }
     215           0 :     void setExtensionManager(TheExtensionManager* pManager) { m_pManager = pManager; }
     216             : 
     217             : 
     218             :     //These functions are used for automatic testing
     219             : 
     220             :     /** @return  The count of the entries in the list box. */
     221             :     virtual sal_Int32 getItemCount() const SAL_OVERRIDE;
     222             : 
     223             :     /** @return  The index of the first selected entry in the list box.
     224             :         When nothing is selected, which is the case when getItemCount returns '0',
     225             :         then this function returns ENTRY_NOTFOUND */
     226             :     virtual sal_Int32 getSelIndex() const SAL_OVERRIDE;
     227             : 
     228             :     /** @return  The item name of the entry with the given index
     229             :         The index starts with 0.
     230             :         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
     231             :     virtual OUString getItemName( sal_Int32 index ) const SAL_OVERRIDE;
     232             : 
     233             :     /** @return  The version string of the entry with the given index
     234             :         The index starts with 0.
     235             :         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
     236             :     virtual OUString getItemVersion( sal_Int32 index ) const SAL_OVERRIDE;
     237             : 
     238             :     /** @return  The description string of the entry with the given index
     239             :         The index starts with 0.
     240             :         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
     241             :     virtual OUString getItemDescription( sal_Int32 index ) const SAL_OVERRIDE;
     242             : 
     243             :     /** @return  The publisher string of the entry with the given index
     244             :         The index starts with 0.
     245             :         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
     246             :     virtual OUString getItemPublisher( sal_Int32 index ) const SAL_OVERRIDE;
     247             : 
     248             :     /** @return  The link behind the publisher text of the entry with the given index
     249             :         The index starts with 0.
     250             :         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
     251             :     virtual OUString getItemPublisherLink( sal_Int32 index ) const SAL_OVERRIDE;
     252             : 
     253             :     /** The entry at the given position will be selected
     254             :         Index starts with 0.
     255             :         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
     256             :     virtual void select( sal_Int32 pos ) SAL_OVERRIDE;
     257             : 
     258             :     /** The first found entry with the given name will be selected
     259             :         When there was no entry found with the name, the selection doesn't change.
     260             :         Please note that there might be more than one entry with the same
     261             :         name, because:
     262             :             1. the name is not unique
     263             :             2. one extension can be installed as user and shared extension.
     264             :     */
     265             :     virtual void select( const OUString & sName ) SAL_OVERRIDE;
     266             : };
     267             : 
     268             : }
     269             : 
     270             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10