LibreOffice Module desktop (master)  1
dp_gui_extlistbox.hxx
Go to the documentation of this file.
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/customweld.hxx>
25 #include <vcl/image.hxx>
26 #include <vcl/weld.hxx>
27 
28 #include <cppuhelper/implbase.hxx>
29 #include <cppuhelper/weakref.hxx>
31 
32 #include <com/sun/star/lang/Locale.hpp>
33 #include <com/sun/star/lang/XEventListener.hpp>
34 #include <com/sun/star/deployment/XPackage.hpp>
35 
36 #include <memory>
37 
38 namespace dp_gui {
39 
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
47 
48 class TheExtensionManager;
49 
50 
51 struct Entry_Impl;
52 
53 typedef std::shared_ptr< Entry_Impl > TEntry_Impl;
54 
55 struct Entry_Impl
56 {
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;
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;
77 
78  css::uno::Reference<css::deployment::XPackage> m_xPackage;
79 
80  Entry_Impl(const css::uno::Reference<css::deployment::XPackage> &xPackage,
81  const PackageState eState, const bool bReadOnly);
82  ~Entry_Impl();
83 
84  sal_Int32 CompareTo(const CollatorWrapper *pCollator, const TEntry_Impl& rEntry) const;
85  void checkDependencies();
86 };
87 
88 class ExtensionBox_Impl;
89 
90 
91 class ExtensionRemovedListener : public ::cppu::WeakImplHelper<css::lang::XEventListener>
92 {
94 
95 public:
96 
97  explicit ExtensionRemovedListener( ExtensionBox_Impl *pParent ) { m_pParent = pParent; }
98  virtual ~ExtensionRemovedListener() override;
99 
100 
101  // XEventListener
102  virtual void SAL_CALL disposing(css::lang::EventObject const& evt) override;
103 };
104 
106 {
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;
123 
125 
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;
137 
138  std::unique_ptr<css::lang::Locale> m_pLocale;
139  std::unique_ptr<CollatorWrapper> m_pCollator;
140 
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;
144 
145  std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
146 
147  //Removes the dead weak references from m_vListenerAdded
148  void cleanVecListenerAdded();
149  void addEventListenerOnce(css::uno::Reference<css::deployment::XPackage> const & extension);
150 
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();
158 
159  DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void );
160 
161  void Init();
162 public:
163  explicit ExtensionBox_Impl(std::unique_ptr<weld::ScrolledWindow> xScroll);
164  virtual ~ExtensionBox_Impl() override;
165 
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;
172 
173  virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
174 
175  TEntry_Impl const & GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
176  long GetEntryCount() { return static_cast<long>(m_vEntries.size()); }
177  tools::Rectangle GetEntryRect( const long nPos ) const;
178  bool HasActive() { return m_bHasActive; }
179  long PointToPos( const Point& rPos );
180  virtual void RecalcAll();
181  void RemoveUnlocked();
182 
183 
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 );
189 
190  void prepareChecking();
191  void checkEntries();
192 
193  void setExtensionManager(TheExtensionManager* pManager) { m_pManager = pManager; }
194 
195  //These functions are used for automatic testing
196 public:
197  enum { ENTRY_NOTFOUND = -1 };
198 
200  sal_Int32 getItemCount() const;
201 
208  sal_Int32 getSelIndex() const;
209 };
210 
211 }
212 
213 #endif // INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_EXTLISTBOX_HXX
214 
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void addEntry(const css::uno::Reference< css::deployment::XPackage > &xPackage, bool bLicenseMissing=false)
TEntry_Impl const & GetEntryData(long nPos)
void updateEntry(const css::uno::Reference< css::deployment::XPackage > &xPackage)
DECL_LINK(ScrollHdl, weld::ScrolledWindow &, void)
virtual void Resize() override
bool HandleCursorKey(sal_uInt16 nKeyCode)
void CalcActiveHeight(const long nPos)
sal_Int32 CompareTo(const CollatorWrapper *pCollator, const TEntry_Impl &rEntry) const
void setExtensionManager(TheExtensionManager *pManager)
bool FindEntryPos(const TEntry_Impl &rEntry, long nStart, long nEnd, long &nFound)
Entry_Impl(const css::uno::Reference< css::deployment::XPackage > &xPackage, const PackageState eState, const bool bReadOnly)
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rPaintRect) override
virtual ~ExtensionRemovedListener() override
virtual bool MouseMove(const MouseEvent &rMEvt) override
virtual void selectEntry(const long nPos)
void DrawRow(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect, const TEntry_Impl &rEntry)
long PointToPos(const Point &rPos)
std::unique_ptr< weld::ScrolledWindow > m_xScrollBar
virtual ~ExtensionBox_Impl() override
std::unique_ptr< css::lang::Locale > m_pLocale
virtual bool KeyInput(const KeyEvent &rKEvt) override
rtl::Reference< ExtensionRemovedListener > m_xRemoveListener
virtual void SAL_CALL disposing(css::lang::EventObject const &evt) override
TheExtensionManager * m_pManager
css::uno::Reference< css::deployment::XPackage > m_xPackage
std::vector< TEntry_Impl > m_vEntries
sal_Int32 getSelIndex() const
tools::Rectangle GetEntryRect(const long nPos) const
sal_Int32 getItemCount() const
ExtensionBox_Impl(std::unique_ptr< weld::ScrolledWindow > xScroll)
ExtensionRemovedListener(ExtensionBox_Impl *pParent)
std::vector< TEntry_Impl > m_vRemovedEntries
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
PackageState
Definition: dp_gui.h:52
virtual OUString RequestHelp(tools::Rectangle &rRect) override
std::unique_ptr< CollatorWrapper > m_pCollator
void addEventListenerOnce(css::uno::Reference< css::deployment::XPackage > const &extension)
mutable::osl::Mutex m_entriesMutex
std::vector< css::uno::WeakReference< css::deployment::XPackage > > m_vListenerAdded
Definition: dp_gui.h:50
tools::Rectangle m_aLinkRect
void removeEntry(const css::uno::Reference< css::deployment::XPackage > &xPackage)
std::shared_ptr< Entry_Impl > TEntry_Impl