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