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