Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / desktop / source / deployment / gui / dp_gui_extlistbox.hxx
blob7621807f1ef6d615982c02aa5e78e6288c4acb00
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_EXTLISTBOX_HXX
21 #define INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_EXTLISTBOX_HXX
23 #include <rtl/ustring.hxx>
24 #include <vcl/customweld.hxx>
25 #include <vcl/image.hxx>
26 #include <vcl/weld.hxx>
28 #include <cppuhelper/implbase.hxx>
29 #include <cppuhelper/weakref.hxx>
30 #include <unotools/collatorwrapper.hxx>
32 #include <com/sun/star/lang/Locale.hpp>
33 #include <com/sun/star/lang/XEventListener.hpp>
34 #include <com/sun/star/deployment/XPackage.hpp>
36 #include <memory>
38 namespace dp_gui {
40 #define SMALL_ICON_SIZE 16
41 #define TOP_OFFSET 5
42 #define ICON_HEIGHT 42
43 #define ICON_WIDTH 47
44 #define ICON_OFFSET 72
45 #define RIGHT_ICON_OFFSET 5
46 #define SPACE_BETWEEN 3
48 class TheExtensionManager;
51 struct Entry_Impl;
53 typedef std::shared_ptr< Entry_Impl > TEntry_Impl;
55 struct Entry_Impl
57 bool m_bActive :1;
58 bool m_bLocked :1;
59 bool m_bHasOptions :1;
60 bool m_bUser :1;
61 bool m_bShared :1;
62 bool m_bNew :1;
63 bool m_bChecked :1;
64 bool m_bMissingDeps :1;
65 bool m_bHasButtons :1;
66 bool m_bMissingLic :1;
67 PackageState m_eState;
68 OUString m_sTitle;
69 OUString m_sVersion;
70 OUString m_sDescription;
71 OUString m_sPublisher;
72 OUString m_sPublisherURL;
73 OUString m_sErrorText;
74 OUString m_sLicenseText;
75 Image m_aIcon;
76 tools::Rectangle m_aLinkRect;
78 css::uno::Reference<css::deployment::XPackage> m_xPackage;
80 Entry_Impl(const css::uno::Reference<css::deployment::XPackage> &xPackage,
81 const PackageState eState, const bool bReadOnly);
82 ~Entry_Impl();
84 sal_Int32 CompareTo(const CollatorWrapper *pCollator, const TEntry_Impl& rEntry) const;
85 void checkDependencies();
88 class ExtensionBox_Impl;
91 class ExtensionRemovedListener : public ::cppu::WeakImplHelper<css::lang::XEventListener>
93 ExtensionBox_Impl* m_pParent;
95 public:
97 explicit ExtensionRemovedListener( ExtensionBox_Impl *pParent ) { m_pParent = pParent; }
98 virtual ~ExtensionRemovedListener() override;
101 // XEventListener
102 virtual void SAL_CALL disposing(css::lang::EventObject const& evt) override;
105 class ExtensionBox_Impl : public weld::CustomWidgetController
107 bool m_bHasScrollBar : 1;
108 bool m_bHasActive : 1;
109 bool m_bNeedsRecalc : 1;
110 bool m_bInCheckMode : 1;
111 bool m_bAdjustActive : 1;
112 bool m_bInDelete : 1;
113 //Must be guarded together with m_vEntries to ensure a valid index at all times.
114 //Use m_entriesMutex as guard.
115 long m_nActive;
116 long m_nTopIndex;
117 long m_nStdHeight;
118 long m_nActiveHeight;
119 Image m_aSharedImage;
120 Image m_aLockedImage;
121 Image m_aWarningImage;
122 Image m_aDefaultImage;
124 rtl::Reference<ExtensionRemovedListener> m_xRemoveListener;
126 TheExtensionManager *m_pManager;
127 //This mutex is used for synchronizing access to m_vEntries.
128 //Currently it is used to synchronize adding, removing entries and
129 //functions like getItemName, getItemDescription, etc. to prevent
130 //that m_vEntries is accessed at an invalid index.
131 //ToDo: There are many more places where m_vEntries is read and which may
132 //fail. For example the Paint method is probable called from the main thread
133 //while new entries are added / removed in a separate thread.
134 mutable ::osl::Mutex m_entriesMutex;
135 std::vector< TEntry_Impl > m_vEntries;
136 std::vector< TEntry_Impl > m_vRemovedEntries;
138 std::unique_ptr<css::lang::Locale> m_pLocale;
139 std::unique_ptr<CollatorWrapper> m_pCollator;
141 //Holds weak references to extensions to which is we have added an XEventListener
142 std::vector< css::uno::WeakReference<
143 css::deployment::XPackage> > m_vListenerAdded;
145 std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
147 //Removes the dead weak references from m_vListenerAdded
148 void cleanVecListenerAdded();
149 void addEventListenerOnce(css::uno::Reference<css::deployment::XPackage> const & extension);
151 void CalcActiveHeight( const long nPos );
152 long GetTotalHeight() const;
153 void SetupScrollBar();
154 void DrawRow(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const TEntry_Impl& rEntry);
155 bool HandleCursorKey( sal_uInt16 nKeyCode );
156 bool FindEntryPos( const TEntry_Impl& rEntry, long nStart, long nEnd, long &nFound );
157 void DeleteRemoved();
159 DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void );
161 void Init();
162 public:
163 explicit ExtensionBox_Impl(std::unique_ptr<weld::ScrolledWindow> xScroll);
164 virtual ~ExtensionBox_Impl() override;
166 virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
167 virtual bool MouseMove( const MouseEvent& rMEvt ) override;
168 virtual bool KeyInput(const KeyEvent& rKEvt) override;
169 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle &rPaintRect ) override;
170 virtual void Resize() override;
171 virtual OUString RequestHelp(tools::Rectangle& rRect) override;
173 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
175 TEntry_Impl const & GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
176 long GetEntryCount() const { return static_cast<long>(m_vEntries.size()); }
177 tools::Rectangle GetEntryRect( const long nPos ) const;
178 bool HasActive() const { return m_bHasActive; }
179 long PointToPos( const Point& rPos );
180 virtual void RecalcAll();
181 void RemoveUnlocked();
184 virtual void selectEntry( const long nPos );
185 void addEntry(const css::uno::Reference<css::deployment::XPackage> &xPackage,
186 bool bLicenseMissing = false );
187 void updateEntry(const css::uno::Reference<css::deployment::XPackage> &xPackage );
188 void removeEntry(const css::uno::Reference<css::deployment::XPackage> &xPackage );
190 void prepareChecking();
191 void checkEntries();
193 void setExtensionManager(TheExtensionManager* pManager) { m_pManager = pManager; }
195 //These functions are used for automatic testing
196 public:
197 enum { ENTRY_NOTFOUND = -1 };
199 /** @return The count of the entries in the list box. */
200 sal_Int32 getItemCount() const;
202 /** @return The index of the first selected entry in the list box.
203 When nothing is selected, which is the case when getItemCount returns '0',
204 then this function returns ENTRY_NOTFOUND */
205 /** @return The index of the first selected entry in the list box.
206 When nothing is selected, which is the case when getItemCount returns '0',
207 then this function returns ENTRY_NOTFOUND */
208 sal_Int32 getSelIndex() const;
213 #endif // INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_EXTLISTBOX_HXX
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */