Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "rtl/ustring.hxx"
30 : : #include "vcl/scrbar.hxx"
31 : : #include "vcl/fixed.hxx"
32 : : #include "vcl/dialog.hxx"
33 : :
34 : : #include "svtools/extensionlistbox.hxx"
35 : : #include "svtools/fixedhyper.hxx"
36 : : #include "cppuhelper/implbase1.hxx"
37 : : #include "unotools/collatorwrapper.hxx"
38 : :
39 : : #include "com/sun/star/lang/Locale.hpp"
40 : : #include "com/sun/star/lang/XEventListener.hpp"
41 : : #include "com/sun/star/deployment/XPackage.hpp"
42 : :
43 : : #include <boost/shared_ptr.hpp>
44 : :
45 : : namespace dp_gui {
46 : :
47 : : #define SMALL_ICON_SIZE 16
48 : : #define TOP_OFFSET 5
49 : : #define ICON_HEIGHT 42
50 : : #define ICON_WIDTH 47
51 : : #define ICON_OFFSET 72
52 : : #define RIGHT_ICON_OFFSET 5
53 : : #define SPACE_BETWEEN 3
54 : :
55 : : class TheExtensionManager;
56 : :
57 : : typedef ::boost::shared_ptr< svt::FixedHyperlink > TFixedHyperlink;
58 : :
59 : : //------------------------------------------------------------------------------
60 : : // struct Entry_Impl
61 : : //------------------------------------------------------------------------------
62 : : struct Entry_Impl;
63 : :
64 : : typedef ::boost::shared_ptr< Entry_Impl > TEntry_Impl;
65 : :
66 : : struct Entry_Impl
67 : : {
68 : : bool m_bActive :1;
69 : : bool m_bLocked :1;
70 : : bool m_bHasOptions :1;
71 : : bool m_bUser :1;
72 : : bool m_bShared :1;
73 : : bool m_bNew :1;
74 : : bool m_bChecked :1;
75 : : bool m_bMissingDeps :1;
76 : : bool m_bHasButtons :1;
77 : : bool m_bMissingLic :1;
78 : : PackageState m_eState;
79 : : String m_sTitle;
80 : : String m_sVersion;
81 : : String m_sDescription;
82 : : String m_sPublisher;
83 : : String m_sPublisherURL;
84 : : String m_sErrorText;
85 : : String m_sLicenseText;
86 : : Image m_aIcon;
87 : : Image m_aIconHC;
88 : : svt::FixedHyperlink *m_pPublisher;
89 : :
90 : : ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage> m_xPackage;
91 : :
92 : : Entry_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
93 : : const PackageState eState, const bool bReadOnly );
94 : : ~Entry_Impl();
95 : :
96 : : StringCompare CompareTo( const CollatorWrapper *pCollator, const TEntry_Impl pEntry ) const;
97 : : void checkDependencies();
98 : : };
99 : :
100 : : //------------------------------------------------------------------------------
101 : : // class ExtensionBox_Impl
102 : : //------------------------------------------------------------------------------
103 : :
104 : : class ExtensionBox_Impl;
105 : :
106 : : //------------------------------------------------------------------------------
107 : : class ExtensionRemovedListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
108 : : {
109 : : ExtensionBox_Impl *m_pParent;
110 : :
111 : : public:
112 : :
113 : 0 : ExtensionRemovedListener( ExtensionBox_Impl *pParent ) { m_pParent = pParent; }
114 : : ~ExtensionRemovedListener();
115 : :
116 : : //===================================================================================
117 : : // XEventListener
118 : : virtual void SAL_CALL disposing( ::com::sun::star::lang::EventObject const & evt )
119 : : throw (::com::sun::star::uno::RuntimeException);
120 : : };
121 : :
122 : : //------------------------------------------------------------------------------
123 : : class ExtensionBox_Impl : public ::svt::IExtensionListBox
124 : : {
125 : : bool m_bHasScrollBar;
126 : : bool m_bHasActive;
127 : : bool m_bNeedsRecalc;
128 : : bool m_bHasNew;
129 : : bool m_bInCheckMode;
130 : : bool m_bAdjustActive;
131 : : bool m_bInDelete;
132 : : //Must be guarded together with m_vEntries to ensure a valid index at all times.
133 : : //Use m_entriesMutex as guard.
134 : : long m_nActive;
135 : : long m_nTopIndex;
136 : : long m_nStdHeight;
137 : : long m_nActiveHeight;
138 : : long m_nExtraHeight;
139 : : Size m_aOutputSize;
140 : : Image m_aSharedImage;
141 : : Image m_aLockedImage;
142 : : Image m_aWarningImage;
143 : : Image m_aDefaultImage;
144 : : Link m_aClickHdl;
145 : :
146 : : ScrollBar *m_pScrollBar;
147 : :
148 : : com::sun::star::uno::Reference< ExtensionRemovedListener > m_xRemoveListener;
149 : :
150 : : TheExtensionManager *m_pManager;
151 : : //This mutex is used for synchronizing access to m_vEntries.
152 : : //Currently it is used to synchronize adding, removing entries and
153 : : //functions like getItemName, getItemDescription, etc. to prevent
154 : : //that m_vEntries is accessed at an invalid index.
155 : : //ToDo: There are many more places where m_vEntries is read and which may
156 : : //fail. For example the Paint method is probable called from the main thread
157 : : //while new entries are added / removed in a separate thread.
158 : : mutable ::osl::Mutex m_entriesMutex;
159 : : std::vector< TEntry_Impl > m_vEntries;
160 : : std::vector< TEntry_Impl > m_vRemovedEntries;
161 : :
162 : : ::com::sun::star::lang::Locale *m_pLocale;
163 : : CollatorWrapper *m_pCollator;
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 : : public:
183 : : ExtensionBox_Impl( Dialog* pParent, TheExtensionManager *pManager );
184 : : ~ExtensionBox_Impl();
185 : :
186 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
187 : : virtual void Paint( const Rectangle &rPaintRect );
188 : : virtual void Resize();
189 : : virtual long Notify( NotifyEvent& rNEvt );
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 : :
216 : : //===================================================================================
217 : : //These functions are used for automatic testing
218 : :
219 : : /** @return The count of the entries in the list box. */
220 : : virtual sal_Int32 getItemCount() const;
221 : :
222 : : /** @return The index of the first selected entry in the list box.
223 : : When nothing is selected, which is the case when getItemCount returns '0',
224 : : then this function returns EXTENSION_LISTBOX_ENTRY_NOTFOUND */
225 : : virtual sal_Int32 getSelIndex() const;
226 : :
227 : : /** @return The item name 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 ::rtl::OUString getItemName( sal_Int32 index ) const;
231 : :
232 : : /** @return The version 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 ::rtl::OUString getItemVersion( sal_Int32 index ) const;
236 : :
237 : : /** @return The description 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 ::rtl::OUString getItemDescription( sal_Int32 index ) const;
241 : :
242 : : /** @return The publisher string 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 ::rtl::OUString getItemPublisher( sal_Int32 index ) const;
246 : :
247 : : /** @return The link behind the publisher text of the entry with the given index
248 : : The index starts with 0.
249 : : Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
250 : : virtual ::rtl::OUString getItemPublisherLink( sal_Int32 index ) const;
251 : :
252 : : /** The entry at the given position will be selected
253 : : Index starts with 0.
254 : : Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
255 : : virtual void select( sal_Int32 pos );
256 : :
257 : : /** The first found entry with the given name will be selected
258 : : When there was no entry found with the name, the selection doesn't change.
259 : : Please note that there might be more than one entry with the same
260 : : name, because:
261 : : 1. the name is not unique
262 : : 2. one extension can be installed as user and shared extension.
263 : : */
264 : : virtual void select( const ::rtl::OUString & sName );
265 : : };
266 : :
267 : : }
268 : :
269 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|