1*0a1e2f0eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*0a1e2f0eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*0a1e2f0eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*0a1e2f0eSAndrew Rist  * distributed with this work for additional information
6*0a1e2f0eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*0a1e2f0eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*0a1e2f0eSAndrew Rist  * "License"); you may not use this file except in compliance
9*0a1e2f0eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*0a1e2f0eSAndrew Rist  *
11*0a1e2f0eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*0a1e2f0eSAndrew Rist  *
13*0a1e2f0eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*0a1e2f0eSAndrew Rist  * software distributed under the License is distributed on an
15*0a1e2f0eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0a1e2f0eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*0a1e2f0eSAndrew Rist  * specific language governing permissions and limitations
18*0a1e2f0eSAndrew Rist  * under the License.
19*0a1e2f0eSAndrew Rist  *
20*0a1e2f0eSAndrew Rist  *************************************************************/
21*0a1e2f0eSAndrew Rist 
22*0a1e2f0eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "rtl/ustring.hxx"
25cdf0e10cSrcweir #include "vcl/scrbar.hxx"
26cdf0e10cSrcweir #include "vcl/fixed.hxx"
27cdf0e10cSrcweir #include "vcl/dialog.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "svtools/extensionlistbox.hxx"
30cdf0e10cSrcweir #include "svtools/fixedhyper.hxx"
31cdf0e10cSrcweir #include "cppuhelper/implbase1.hxx"
32cdf0e10cSrcweir #include "unotools/collatorwrapper.hxx"
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include "com/sun/star/lang/Locale.hpp"
35cdf0e10cSrcweir #include "com/sun/star/lang/XEventListener.hpp"
36cdf0e10cSrcweir #include "com/sun/star/deployment/XPackage.hpp"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir namespace dp_gui {
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #define SMALL_ICON_SIZE     16
43cdf0e10cSrcweir #define TOP_OFFSET           5
44cdf0e10cSrcweir #define ICON_HEIGHT         42
45cdf0e10cSrcweir #define ICON_WIDTH          47
46cdf0e10cSrcweir #define ICON_OFFSET         72
47cdf0e10cSrcweir #define RIGHT_ICON_OFFSET    5
48cdf0e10cSrcweir #define SPACE_BETWEEN        3
49cdf0e10cSrcweir 
50cdf0e10cSrcweir class TheExtensionManager;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir typedef ::boost::shared_ptr< svt::FixedHyperlink > TFixedHyperlink;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //------------------------------------------------------------------------------
55cdf0e10cSrcweir //                          struct Entry_Impl
56cdf0e10cSrcweir //------------------------------------------------------------------------------
57cdf0e10cSrcweir struct Entry_Impl;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir typedef ::boost::shared_ptr< Entry_Impl > TEntry_Impl;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir struct Entry_Impl
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     bool            m_bActive       :1;
64cdf0e10cSrcweir     bool            m_bLocked       :1;
65cdf0e10cSrcweir     bool            m_bHasOptions   :1;
66cdf0e10cSrcweir     bool            m_bUser         :1;
67cdf0e10cSrcweir     bool            m_bShared       :1;
68cdf0e10cSrcweir     bool            m_bNew          :1;
69cdf0e10cSrcweir     bool            m_bChecked      :1;
70cdf0e10cSrcweir     bool            m_bMissingDeps  :1;
71cdf0e10cSrcweir     bool            m_bHasButtons   :1;
72cdf0e10cSrcweir     bool            m_bMissingLic   :1;
73cdf0e10cSrcweir     PackageState    m_eState;
74cdf0e10cSrcweir     String          m_sTitle;
75cdf0e10cSrcweir     String          m_sVersion;
76cdf0e10cSrcweir     String          m_sDescription;
77cdf0e10cSrcweir     String          m_sPublisher;
78cdf0e10cSrcweir     String          m_sPublisherURL;
79cdf0e10cSrcweir     String          m_sErrorText;
80cdf0e10cSrcweir     String          m_sLicenseText;
81cdf0e10cSrcweir     Image           m_aIcon;
82cdf0e10cSrcweir     Image           m_aIconHC;
83cdf0e10cSrcweir     svt::FixedHyperlink *m_pPublisher;
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage> m_xPackage;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     Entry_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
88cdf0e10cSrcweir                 const PackageState eState, const bool bReadOnly );
89cdf0e10cSrcweir    ~Entry_Impl();
90cdf0e10cSrcweir 
91cdf0e10cSrcweir     StringCompare CompareTo( const CollatorWrapper *pCollator, const TEntry_Impl pEntry ) const;
92cdf0e10cSrcweir     void          checkDependencies();
93cdf0e10cSrcweir };
94cdf0e10cSrcweir 
95cdf0e10cSrcweir //------------------------------------------------------------------------------
96cdf0e10cSrcweir //                          class ExtensionBox_Impl
97cdf0e10cSrcweir //------------------------------------------------------------------------------
98cdf0e10cSrcweir 
99cdf0e10cSrcweir class ExtensionBox_Impl;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //------------------------------------------------------------------------------
102cdf0e10cSrcweir class ExtensionRemovedListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     ExtensionBox_Impl   *m_pParent;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir public:
107cdf0e10cSrcweir 
ExtensionRemovedListener(ExtensionBox_Impl * pParent)108cdf0e10cSrcweir     ExtensionRemovedListener( ExtensionBox_Impl *pParent ) { m_pParent = pParent; }
109cdf0e10cSrcweir    ~ExtensionRemovedListener();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir     //===================================================================================
112cdf0e10cSrcweir     // XEventListener
113cdf0e10cSrcweir     virtual void SAL_CALL disposing( ::com::sun::star::lang::EventObject const & evt )
114cdf0e10cSrcweir         throw (::com::sun::star::uno::RuntimeException);
115cdf0e10cSrcweir };
116cdf0e10cSrcweir 
117cdf0e10cSrcweir //------------------------------------------------------------------------------
118cdf0e10cSrcweir class ExtensionBox_Impl : public ::svt::IExtensionListBox
119cdf0e10cSrcweir {
120cdf0e10cSrcweir     bool            m_bHasScrollBar;
121cdf0e10cSrcweir     bool            m_bHasActive;
122cdf0e10cSrcweir     bool            m_bNeedsRecalc;
123cdf0e10cSrcweir     bool            m_bHasNew;
124cdf0e10cSrcweir     bool            m_bInCheckMode;
125cdf0e10cSrcweir     bool            m_bAdjustActive;
126cdf0e10cSrcweir     bool            m_bInDelete;
127cdf0e10cSrcweir     //Must be guarded together with m_vEntries to ensure a valid index at all times.
128cdf0e10cSrcweir     //Use m_entriesMutex as guard.
129cdf0e10cSrcweir     long            m_nActive;
130cdf0e10cSrcweir     long            m_nTopIndex;
131cdf0e10cSrcweir     long            m_nStdHeight;
132cdf0e10cSrcweir     long            m_nActiveHeight;
133cdf0e10cSrcweir     long            m_nExtraHeight;
134cdf0e10cSrcweir     Size            m_aOutputSize;
135cdf0e10cSrcweir     Image           m_aSharedImage;
136cdf0e10cSrcweir     Image           m_aSharedImageHC;
137cdf0e10cSrcweir     Image           m_aLockedImage;
138cdf0e10cSrcweir     Image           m_aLockedImageHC;
139cdf0e10cSrcweir     Image           m_aWarningImage;
140cdf0e10cSrcweir     Image           m_aWarningImageHC;
141cdf0e10cSrcweir     Image           m_aDefaultImage;
142cdf0e10cSrcweir     Image           m_aDefaultImageHC;
143cdf0e10cSrcweir     Link            m_aClickHdl;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     ScrollBar      *m_pScrollBar;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     com::sun::star::uno::Reference< ExtensionRemovedListener > m_xRemoveListener;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     TheExtensionManager      *m_pManager;
150cdf0e10cSrcweir     //This mutex is used for synchronizing access to m_vEntries.
151cdf0e10cSrcweir     //Currently it is used to synchronize adding, removing entries and
152cdf0e10cSrcweir     //functions like getItemName, getItemDescription, etc. to prevent
153cdf0e10cSrcweir     //that m_vEntries is accessed at an invalid index.
154cdf0e10cSrcweir     //ToDo: There are many more places where m_vEntries is read and which may
155cdf0e10cSrcweir     //fail. For example the Paint method is probable called from the main thread
156cdf0e10cSrcweir     //while new entries are added / removed in a separate thread.
157cdf0e10cSrcweir     mutable ::osl::Mutex    m_entriesMutex;
158cdf0e10cSrcweir     std::vector< TEntry_Impl > m_vEntries;
159cdf0e10cSrcweir     std::vector< TEntry_Impl > m_vRemovedEntries;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	::com::sun::star::lang::Locale    *m_pLocale;
162cdf0e10cSrcweir 	CollatorWrapper *m_pCollator;
163cdf0e10cSrcweir 
1648402cd44SMichael Stahl     //Holds weak references to extensions to which is we have added an XEventListener
1658402cd44SMichael Stahl     std::vector< ::com::sun::star::uno::WeakReference<
1668402cd44SMichael Stahl         ::com::sun::star::deployment::XPackage> > m_vListenerAdded;
1678402cd44SMichael Stahl     //Removes the dead weak references from m_vListenerAdded
1688402cd44SMichael Stahl     void cleanVecListenerAdded();
1698402cd44SMichael Stahl     void addEventListenerOnce( ::com::sun::star::uno::Reference<
1708402cd44SMichael Stahl                                ::com::sun::star::deployment::XPackage> const & extension);
1718402cd44SMichael Stahl 
172cdf0e10cSrcweir     void            CalcActiveHeight( const long nPos );
173cdf0e10cSrcweir     long            GetTotalHeight() const;
174cdf0e10cSrcweir     void            SetupScrollBar();
175cdf0e10cSrcweir     void            DrawRow( const Rectangle& rRect, const TEntry_Impl pEntry );
176cdf0e10cSrcweir     bool            HandleTabKey( bool bReverse );
177cdf0e10cSrcweir     bool            HandleCursorKey( sal_uInt16 nKeyCode );
178cdf0e10cSrcweir     bool            FindEntryPos( const TEntry_Impl pEntry, long nStart, long nEnd, long &nFound );
179cdf0e10cSrcweir     bool            isHCMode();
180cdf0e10cSrcweir     void            DeleteRemoved();
181cdf0e10cSrcweir 
182cdf0e10cSrcweir     //-----------------
183cdf0e10cSrcweir     DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar * );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir     //Index starts with 1.
186cdf0e10cSrcweir     //Throws an com::sun::star::lang::IllegalArgumentException, when the index is invalid.
187cdf0e10cSrcweir     void checkIndex(sal_Int32 pos) const;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir public:
191cdf0e10cSrcweir                     ExtensionBox_Impl( Dialog* pParent, TheExtensionManager *pManager );
192cdf0e10cSrcweir                    ~ExtensionBox_Impl();
193cdf0e10cSrcweir 
194cdf0e10cSrcweir     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
195cdf0e10cSrcweir     virtual void    Paint( const Rectangle &rPaintRect );
196cdf0e10cSrcweir     virtual void    Resize();
197cdf0e10cSrcweir     virtual long    Notify( NotifyEvent& rNEvt );
198cdf0e10cSrcweir 
199cdf0e10cSrcweir     const Size      GetMinOutputSizePixel() const;
SetExtraSize(long nSize)200cdf0e10cSrcweir     void            SetExtraSize( long nSize ) { m_nExtraHeight = nSize; }
GetEntryData(long nPos)201cdf0e10cSrcweir     TEntry_Impl     GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
GetEntryCount()202cdf0e10cSrcweir     long            GetEntryCount() { return (long) m_vEntries.size(); }
203cdf0e10cSrcweir     Rectangle       GetEntryRect( const long nPos ) const;
HasActive()204cdf0e10cSrcweir     bool            HasActive() { return m_bHasActive; }
205cdf0e10cSrcweir     long            PointToPos( const Point& rPos );
206cdf0e10cSrcweir     void            SetScrollHdl( const Link& rLink );
207cdf0e10cSrcweir     void            DoScroll( long nDelta );
SetHyperlinkHdl(const Link & rLink)208cdf0e10cSrcweir     void            SetHyperlinkHdl( const Link& rLink ){ m_aClickHdl = rLink; }
209cdf0e10cSrcweir     virtual void    RecalcAll();
210cdf0e10cSrcweir     void            RemoveUnlocked();
211cdf0e10cSrcweir 
212cdf0e10cSrcweir     //-----------------
213cdf0e10cSrcweir     virtual void    selectEntry( const long nPos );
214cdf0e10cSrcweir     long            addEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
215cdf0e10cSrcweir                               bool bLicenseMissing = false );
216cdf0e10cSrcweir     void            updateEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
217cdf0e10cSrcweir     void            removeEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir     void            prepareChecking();
220cdf0e10cSrcweir     void            checkEntries();
221cdf0e10cSrcweir 
getExtensionManager() const222cdf0e10cSrcweir     TheExtensionManager*    getExtensionManager() const { return m_pManager; }
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     //===================================================================================
225cdf0e10cSrcweir     //These functions are used for automatic testing
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     /** @return  The count of the entries in the list box. */
228cdf0e10cSrcweir     virtual sal_Int32 getItemCount() const;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir     /** @return  The index of the first selected entry in the list box.
231cdf0e10cSrcweir         When nothing is selected, which is the case when getItemCount returns '0',
232cdf0e10cSrcweir         then this function returns EXTENSION_LISTBOX_ENTRY_NOTFOUND */
233cdf0e10cSrcweir     virtual sal_Int32 getSelIndex() const;
234cdf0e10cSrcweir 
235cdf0e10cSrcweir     /** @return  The item name of the entry with the given index
236cdf0e10cSrcweir         The index starts with 0.
237cdf0e10cSrcweir         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
238cdf0e10cSrcweir     virtual ::rtl::OUString getItemName( sal_Int32 index ) const;
239cdf0e10cSrcweir 
240cdf0e10cSrcweir     /** @return  The version string of the entry with the given index
241cdf0e10cSrcweir         The index starts with 0.
242cdf0e10cSrcweir         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
243cdf0e10cSrcweir     virtual ::rtl::OUString getItemVersion( sal_Int32 index ) const;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     /** @return  The description string of the entry with the given index
246cdf0e10cSrcweir         The index starts with 0.
247cdf0e10cSrcweir         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
248cdf0e10cSrcweir     virtual ::rtl::OUString getItemDescription( sal_Int32 index ) const;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir     /** @return  The publisher string of the entry with the given index
251cdf0e10cSrcweir         The index starts with 0.
252cdf0e10cSrcweir         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
253cdf0e10cSrcweir     virtual ::rtl::OUString getItemPublisher( sal_Int32 index ) const;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir     /** @return  The link behind the publisher text of the entry with the given index
256cdf0e10cSrcweir         The index starts with 0.
257cdf0e10cSrcweir         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
258cdf0e10cSrcweir     virtual ::rtl::OUString getItemPublisherLink( sal_Int32 index ) const;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     /** The entry at the given position will be selected
261cdf0e10cSrcweir         Index starts with 0.
262cdf0e10cSrcweir         Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
263cdf0e10cSrcweir     virtual void select( sal_Int32 pos );
264cdf0e10cSrcweir 
265cdf0e10cSrcweir     /** The first found entry with the given name will be selected
266cdf0e10cSrcweir         When there was no entry found with the name, the selection doesn't change.
267cdf0e10cSrcweir         Please note that there might be more than one entry with the same
268cdf0e10cSrcweir         name, because:
269cdf0e10cSrcweir             1. the name is not unique
270cdf0e10cSrcweir             2. one extension can be installed as user and shared extension.
271cdf0e10cSrcweir     */
272cdf0e10cSrcweir     virtual void select( const ::rtl::OUString & sName );
273cdf0e10cSrcweir };
274cdf0e10cSrcweir 
275cdf0e10cSrcweir }
276