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

Generated by: LCOV version 1.11