Update ooo320-m1
[ooovba.git] / desktop / source / deployment / gui / dp_gui_extlistbox.hxx
blobe1a17bb06dc95bac9cee3a4851bc5ee06440eff2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dp_gui_dialog2.cxx,v $
11 * $Revision: 1.8.4.8 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "rtl/ustring.hxx"
33 #include "vcl/scrbar.hxx"
34 #include "vcl/fixed.hxx"
35 #include "vcl/dialog.hxx"
37 #include "svtools/extensionlistbox.hxx"
38 #include "svtools/fixedhyper.hxx"
39 #include "cppuhelper/implbase1.hxx"
40 #include "unotools/collatorwrapper.hxx"
42 #include "com/sun/star/lang/Locale.hpp"
43 #include "com/sun/star/lang/XEventListener.hpp"
44 #include "com/sun/star/deployment/XPackage.hpp"
45 #include "com/sun/star/deployment/XPackageManager.hpp"
47 #include <boost/shared_ptr.hpp>
49 namespace dp_gui {
51 #define SMALL_ICON_SIZE 16
52 #define TOP_OFFSET 3
53 #define ICON_HEIGHT 42
54 #define ICON_OFFSET 50
55 #define RIGHT_ICON_OFFSET 5
56 #define SPACE_BETWEEN 3
58 class TheExtensionManager;
60 typedef ::boost::shared_ptr< svt::FixedHyperlink > TFixedHyperlink;
62 //------------------------------------------------------------------------------
63 // struct Entry_Impl
64 //------------------------------------------------------------------------------
65 struct Entry_Impl;
67 typedef ::boost::shared_ptr< Entry_Impl > TEntry_Impl;
69 struct Entry_Impl
71 bool m_bActive;
72 bool m_bLocked;
73 bool m_bHasOptions;
74 bool m_bShared;
75 bool m_bNew;
76 bool m_bChecked;
77 bool m_bMissingDeps;
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 Image m_aIcon;
86 Image m_aIconHC;
87 svt::FixedHyperlink *m_pPublisher;
89 ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage> m_xPackage;
90 ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackageManager> m_xPackageManager;
92 Entry_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
93 const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackageManager > &xPackageManager,
94 PackageState eState );
95 ~Entry_Impl();
97 StringCompare CompareTo( const CollatorWrapper *pCollator, const TEntry_Impl pEntry ) const;
98 void checkDependencies();
101 //------------------------------------------------------------------------------
102 // class ExtensionBox_Impl
103 //------------------------------------------------------------------------------
105 class ExtensionBox_Impl;
107 //------------------------------------------------------------------------------
108 class ExtensionRemovedListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
110 ExtensionBox_Impl *m_pParent;
112 public:
114 ExtensionRemovedListener( ExtensionBox_Impl *pParent ) { m_pParent = pParent; }
115 ~ExtensionRemovedListener();
117 //===================================================================================
118 // XEventListener
119 virtual void SAL_CALL disposing( ::com::sun::star::lang::EventObject const & evt )
120 throw (::com::sun::star::uno::RuntimeException);
123 //------------------------------------------------------------------------------
124 class ExtensionBox_Impl : public ::svt::IExtensionListBox
126 bool m_bHasScrollBar;
127 bool m_bHasActive;
128 bool m_bNeedsRecalc;
129 bool m_bHasNew;
130 bool m_bInCheckMode;
131 bool m_bAdjustActive;
132 bool m_bInDelete;
133 //Must be guarded together with m_vEntries to ensure a valid index at all times.
134 //Use m_entriesMutex as guard.
135 long m_nActive;
136 long m_nTopIndex;
137 long m_nStdHeight;
138 long m_nActiveHeight;
139 long m_nExtraHeight;
140 Size m_aOutputSize;
141 Image m_aLockedImage;
142 Image m_aLockedImageHC;
143 Image m_aWarningImage;
144 Image m_aWarningImageHC;
145 Image m_aDefaultImage;
146 Image m_aDefaultImageHC;
147 Link m_aClickHdl;
149 ScrollBar *m_pScrollBar;
151 com::sun::star::uno::Reference< ExtensionRemovedListener > m_xRemoveListener;
153 TheExtensionManager *m_pManager;
154 //This mutex is used for synchronizing access to m_vEntries.
155 //Currently it is used to synchronize adding, removing entries and
156 //functions like getItemName, getItemDescription, etc. to prevent
157 //that m_vEntries is accessed at an invalid index.
158 //ToDo: There are many more places where m_vEntries is read and which may
159 //fail. For example the Paint method is probable called from the main thread
160 //while new entries are added / removed in a separate thread.
161 mutable ::osl::Mutex m_entriesMutex;
162 std::vector< TEntry_Impl > m_vEntries;
163 std::vector< TEntry_Impl > m_vRemovedEntries;
165 ::com::sun::star::lang::Locale *m_pLocale;
166 CollatorWrapper *m_pCollator;
168 void CalcActiveHeight( const long nPos );
169 long GetTotalHeight() const;
170 void SetupScrollBar();
171 void DrawRow( const Rectangle& rRect, const TEntry_Impl pEntry );
172 bool HandleTabKey( bool bReverse );
173 bool HandleCursorKey( USHORT nKeyCode );
174 bool FindEntryPos( const TEntry_Impl pEntry, long nStart, long nEnd, long &nFound );
175 bool isHCMode();
176 void DeleteRemoved();
178 //-----------------
179 DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar * );
181 //Index starts with 1.
182 //Throws an com::sun::star::lang::IllegalArgumentException, when the index is invalid.
183 void checkIndex(sal_Int32 pos) const;
186 public:
187 ExtensionBox_Impl( Dialog* pParent, TheExtensionManager *pManager );
188 ~ExtensionBox_Impl();
190 virtual void MouseButtonDown( const MouseEvent& rMEvt );
191 virtual void Paint( const Rectangle &rPaintRect );
192 virtual void Resize();
193 virtual long Notify( NotifyEvent& rNEvt );
195 const Size GetMinOutputSizePixel() const;
196 void SetExtraSize( long nSize ) { m_nExtraHeight = nSize; }
197 TEntry_Impl GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
198 long GetEntryCount() { return (long) m_vEntries.size(); }
199 Rectangle GetEntryRect( const long nPos ) const;
200 bool HasActive() { return m_bHasActive; }
201 long PointToPos( const Point& rPos );
202 void SetScrollHdl( const Link& rLink );
203 void DoScroll( long nDelta );
204 void SetHyperlinkHdl( const Link& rLink ){ m_aClickHdl = rLink; }
205 virtual void RecalcAll();
206 void RemoveUnlocked();
208 //-----------------
209 virtual void selectEntry( const long nPos );
210 long addEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage,
211 const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackageManager > &xPackageManager );
212 void updateEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
213 void removeEntry( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &xPackage );
215 void prepareChecking( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackageManager > &xPackageMgr );
216 void checkEntries();
218 TheExtensionManager* getExtensionManager() const { return m_pManager; }
220 //===================================================================================
221 //These functions are used for automatic testing
223 /** @return The count of the entries in the list box. */
224 virtual sal_Int32 getItemCount() const;
226 /** @return The index of the first selected entry in the list box.
227 When nothing is selected, which is the case when getItemCount returns '0',
228 then this function returns EXTENSION_LISTBOX_ENTRY_NOTFOUND */
229 virtual sal_Int32 getSelIndex() const;
231 /** @return The item name of the entry with the given index
232 The index starts with 0.
233 Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
234 virtual ::rtl::OUString getItemName( sal_Int32 index ) const;
236 /** @return The version string of the entry with the given index
237 The index starts with 0.
238 Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
239 virtual ::rtl::OUString getItemVersion( sal_Int32 index ) const;
241 /** @return The description string of the entry with the given index
242 The index starts with 0.
243 Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
244 virtual ::rtl::OUString getItemDescription( sal_Int32 index ) const;
246 /** @return The publisher string of the entry with the given index
247 The index starts with 0.
248 Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
249 virtual ::rtl::OUString getItemPublisher( sal_Int32 index ) const;
251 /** @return The link behind the publisher text of the entry with the given index
252 The index starts with 0.
253 Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
254 virtual ::rtl::OUString getItemPublisherLink( sal_Int32 index ) const;
256 /** The entry at the given position will be selected
257 Index starts with 0.
258 Throws an com::sun::star::lang::IllegalArgumentException, when the position is invalid. */
259 virtual void select( sal_Int32 pos );
261 /** The first found entry with the given name will be selected
262 When there was no entry found with the name, the selection doesn't change.
263 Please note that there might be more than one entry with the same
264 name, because:
265 1. the name is not unique
266 2. one extension can be installed as user and shared extension.
268 virtual void select( const ::rtl::OUString & sName );