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 #include "dp_gui.h"
39 
40 namespace dp_gui {
41 
42 #define SMALL_ICON_SIZE 16
43 #define TOP_OFFSET 5
44 #define ICON_HEIGHT 42
45 #define ICON_WIDTH 47
46 #define ICON_OFFSET 72
47 #define RIGHT_ICON_OFFSET 5
48 #define SPACE_BETWEEN 3
49 
50 class TheExtensionManager;
51 
52 
53 struct Entry_Impl;
54 
55 typedef std::shared_ptr< Entry_Impl > TEntry_Impl;
56 
57 struct Entry_Impl
58 {
59  bool m_bActive :1;
60  bool m_bLocked :1;
61  bool m_bHasOptions :1;
62  bool m_bUser :1;
63  bool m_bShared :1;
64  bool m_bNew :1;
65  bool m_bChecked :1;
66  bool m_bMissingDeps :1;
67  bool m_bHasButtons :1;
68  bool m_bMissingLic :1;
70  OUString m_sTitle;
71  OUString m_sVersion;
72  OUString m_sDescription;
73  OUString m_sPublisher;
74  OUString m_sPublisherURL;
75  OUString m_sErrorText;
76  OUString m_sLicenseText;
79 
80  css::uno::Reference<css::deployment::XPackage> m_xPackage;
81 
82  Entry_Impl(const css::uno::Reference<css::deployment::XPackage> &xPackage,
83  const PackageState eState, const bool bReadOnly);
84  ~Entry_Impl();
85 
86  sal_Int32 CompareTo(const CollatorWrapper *pCollator, const TEntry_Impl& rEntry) const;
87  void checkDependencies();
88 };
89 
90 class ExtensionBox_Impl;
91 
92 
93 class ExtensionRemovedListener : public ::cppu::WeakImplHelper<css::lang::XEventListener>
94 {
96 
97 public:
98 
99  explicit ExtensionRemovedListener( ExtensionBox_Impl *pParent ) { m_pParent = pParent; }
100  virtual ~ExtensionRemovedListener() override;
101 
102 
103  // XEventListener
104  virtual void SAL_CALL disposing(css::lang::EventObject const& evt) override;
105 };
106 
108 {
109  bool m_bHasScrollBar : 1;
110  bool m_bHasActive : 1;
111  bool m_bNeedsRecalc : 1;
112  bool m_bInCheckMode : 1;
113  bool m_bAdjustActive : 1;
114  bool m_bInDelete : 1;
115  //Must be guarded together with m_vEntries to ensure a valid index at all times.
116  //Use m_entriesMutex as guard.
117  long m_nActive;
125 
127 
129  //This mutex is used for synchronizing access to m_vEntries.
130  //Currently it is used to synchronize adding, removing entries and
131  //functions like getItemName, getItemDescription, etc. to prevent
132  //that m_vEntries is accessed at an invalid index.
133  //ToDo: There are many more places where m_vEntries is read and which may
134  //fail. For example the Paint method is probable called from the main thread
135  //while new entries are added / removed in a separate thread.
136  mutable ::osl::Mutex m_entriesMutex;
137  std::vector< TEntry_Impl > m_vEntries;
138  std::vector< TEntry_Impl > m_vRemovedEntries;
139 
140  std::unique_ptr<css::lang::Locale> m_pLocale;
141  std::unique_ptr<CollatorWrapper> m_pCollator;
142 
143  //Holds weak references to extensions to which is we have added an XEventListener
144  std::vector< css::uno::WeakReference<
145  css::deployment::XPackage> > m_vListenerAdded;
146 
147  std::unique_ptr<weld::ScrolledWindow> m_xScrollBar;
148 
149  //Removes the dead weak references from m_vListenerAdded
150  void cleanVecListenerAdded();
151  void addEventListenerOnce(css::uno::Reference<css::deployment::XPackage> const & extension);
152 
153  void CalcActiveHeight( const long nPos );
154  long GetTotalHeight() const;
155  void SetupScrollBar();
156  void DrawRow(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const TEntry_Impl& rEntry);
157  bool HandleCursorKey( sal_uInt16 nKeyCode );
158  bool FindEntryPos( const TEntry_Impl& rEntry, long nStart, long nEnd, long &nFound );
159  void DeleteRemoved();
160 
161  DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void );
162 
163  void Init();
164 public:
165  explicit ExtensionBox_Impl(std::unique_ptr<weld::ScrolledWindow> xScroll);
166  virtual ~ExtensionBox_Impl() override;
167 
168  virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
169  virtual bool MouseMove( const MouseEvent& rMEvt ) override;
170  virtual bool KeyInput(const KeyEvent& rKEvt) override;
171  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle &rPaintRect ) override;
172  virtual void Resize() override;
173  virtual OUString RequestHelp(tools::Rectangle& rRect) override;
174 
175  virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
176 
177  TEntry_Impl const & GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
178  long GetEntryCount() const { return static_cast<long>(m_vEntries.size()); }
179  tools::Rectangle GetEntryRect( const long nPos ) const;
180  bool HasActive() const { return m_bHasActive; }
181  long PointToPos( const Point& rPos );
182  virtual void RecalcAll();
183  void RemoveUnlocked();
184 
185 
186  virtual void selectEntry( const long nPos );
187  void addEntry(const css::uno::Reference<css::deployment::XPackage> &xPackage,
188  bool bLicenseMissing = false );
189  void updateEntry(const css::uno::Reference<css::deployment::XPackage> &xPackage );
190  void removeEntry(const css::uno::Reference<css::deployment::XPackage> &xPackage );
191 
192  void prepareChecking();
193  void checkEntries();
194 
195  void setExtensionManager(TheExtensionManager* pManager) { m_pManager = pManager; }
196 
197  //These functions are used for automatic testing
198 public:
199  enum { ENTRY_NOTFOUND = -1 };
200 
202  sal_Int32 getItemCount() const;
203 
210  sal_Int32 getSelIndex() const;
211 };
212 
213 }
214 
215 #endif // INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_EXTLISTBOX_HXX
216 
217 /* 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:25
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:23
tools::Rectangle m_aLinkRect
void removeEntry(const css::uno::Reference< css::deployment::XPackage > &xPackage)
std::shared_ptr< Entry_Impl > TEntry_Impl