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/scrbar.hxx>
25 #include <vcl/fixed.hxx>
26 #include <vcl/fixedhyper.hxx>
27 #include <vcl/dialog.hxx>
28 
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/weakref.hxx>
33 
34 #include <com/sun/star/lang/Locale.hpp>
35 #include <com/sun/star/lang/XEventListener.hpp>
36 #include <com/sun/star/deployment/XPackage.hpp>
37 
38 #include <memory>
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 
107 
109 {
110  bool m_bHasScrollBar : 1;
111  bool m_bHasActive : 1;
112  bool m_bNeedsRecalc : 1;
113  bool m_bInCheckMode : 1;
114  bool m_bAdjustActive : 1;
115  bool m_bInDelete : 1;
116  //Must be guarded together with m_vEntries to ensure a valid index at all times.
117  //Use m_entriesMutex as guard.
118  long m_nActive;
126 
128 
130 
132  //This mutex is used for synchronizing access to m_vEntries.
133  //Currently it is used to synchronize adding, removing entries and
134  //functions like getItemName, getItemDescription, etc. to prevent
135  //that m_vEntries is accessed at an invalid index.
136  //ToDo: There are many more places where m_vEntries is read and which may
137  //fail. For example the Paint method is probable called from the main thread
138  //while new entries are added / removed in a separate thread.
139  mutable ::osl::Mutex m_entriesMutex;
140  std::vector< TEntry_Impl > m_vEntries;
141  std::vector< TEntry_Impl > m_vRemovedEntries;
142 
143  std::unique_ptr<css::lang::Locale> m_pLocale;
144  std::unique_ptr<CollatorWrapper> m_pCollator;
145 
146  //Holds weak references to extensions to which is we have added an XEventListener
147  std::vector< css::uno::WeakReference<
148  css::deployment::XPackage> > m_vListenerAdded;
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 
162  DECL_LINK( ScrollHdl, ScrollBar*, void );
163 
164  void Init();
165 public:
166  explicit ExtensionBox_Impl(vcl::Window* pParent);
167  virtual ~ExtensionBox_Impl() override;
168  virtual void dispose() override;
169 
170  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
171  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle &rPaintRect ) override;
172  virtual void Resize() override;
173  virtual bool EventNotify( NotifyEvent& rNEvt ) override;
174  virtual Size GetOptimalSize() const override;
175 
176  TEntry_Impl const & GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
177  long GetEntryCount() { return static_cast<long>(m_vEntries.size()); }
178  tools::Rectangle GetEntryRect( const long nPos ) const;
179  bool HasActive() { return m_bHasActive; }
180  long PointToPos( const Point& rPos );
181  void DoScroll( long nDelta );
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 
200  virtual sal_Int32 getItemCount() const override;
201 
205  virtual sal_Int32 getSelIndex() const override;
206 };
207 
208 }
209 
210 #endif // INCLUDED_DESKTOP_SOURCE_DEPLOYMENT_GUI_DP_GUI_EXTLISTBOX_HXX
211 
212 /* 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)
virtual void Resize() override
bool HandleCursorKey(sal_uInt16 nKeyCode)
void CalcActiveHeight(const long nPos)
virtual sal_Int32 getSelIndex() const override
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)
VclPtr< ExtensionBox_Impl > m_pParent
Entry_Impl(const css::uno::Reference< css::deployment::XPackage > &xPackage, const PackageState eState, const bool bReadOnly)
VclPtr< ScrollBar > m_pScrollBar
virtual void dispose() override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rPaintRect) override
virtual sal_Int32 getItemCount() const override
virtual ~ExtensionRemovedListener() 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)
virtual bool EventNotify(NotifyEvent &rNEvt) override
virtual ~ExtensionBox_Impl() override
std::unique_ptr< css::lang::Locale > m_pLocale
ExtensionBox_Impl(vcl::Window *pParent)
VclPtr< FixedHyperlink > m_pPublisher
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
tools::Rectangle GetEntryRect(const long nPos) const
ExtensionRemovedListener(ExtensionBox_Impl *pParent)
std::vector< TEntry_Impl > m_vRemovedEntries
virtual Size GetOptimalSize() const override
PackageState
Definition: dp_gui.h:61
std::unique_ptr< CollatorWrapper > m_pCollator
void addEventListenerOnce(css::uno::Reference< css::deployment::XPackage > const &extension)
mutable::osl::Mutex m_entriesMutex
DECL_LINK(ScrollHdl, ScrollBar *, void)
std::vector< css::uno::WeakReference< css::deployment::XPackage > > m_vListenerAdded
Definition: dp_gui.h:59
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
void removeEntry(const css::uno::Reference< css::deployment::XPackage > &xPackage)
std::shared_ptr< Entry_Impl > TEntry_Impl