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
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#include <optional>
37
38#include "dp_gui.h"
39
40namespace 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
50class TheExtensionManager;
51
52
53struct Entry_Impl;
54
55typedef std::shared_ptr< Entry_Impl > TEntry_Impl;
56
58{
59 bool m_bActive :1;
60 bool m_bLocked :1;
62 bool m_bUser :1;
63 bool m_bShared :1;
64 bool m_bNew :1;
65 bool m_bChecked :1;
70 OUString m_sTitle;
71 OUString m_sVersion;
73 OUString m_sPublisher;
75 OUString m_sErrorText;
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);
85
86 sal_Int32 CompareTo(const CollatorWrapper *pCollator, const TEntry_Impl& rEntry) const;
87 void checkDependencies();
88};
89
91
92
93class ExtensionRemovedListener : public ::cppu::WeakImplHelper<css::lang::XEventListener>
94{
96
97public:
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{
110 bool m_bHasActive : 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.
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::optional<CollatorWrapper> m_oCollator;
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
151 void addEventListenerOnce(css::uno::Reference<css::deployment::XPackage> const & extension);
152
153 void CalcActiveHeight( const tools::Long nPos );
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, tools::Long nStart, tools::Long nEnd, tools::Long &nFound );
159 void DeleteRemoved();
160
161 DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void );
162
163 void Init();
164public:
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( tools::Long nPos ) { return m_vEntries[ nPos ]; }
178 tools::Long GetEntryCount() const { return static_cast<tools::Long>(m_vEntries.size()); }
179 tools::Rectangle GetEntryRect( const tools::Long nPos ) const;
180 bool HasActive() const { return m_bHasActive; }
181 tools::Long PointToPos( const Point& rPos );
182 virtual void RecalcAll();
183 void RemoveUnlocked();
184
185
186 virtual void selectEntry( const tools::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
198public:
199 enum { ENTRY_NOTFOUND = -1 };
200
202 sal_Int32 getItemCount() const;
203
210 sal_Int32 getSelIndex() const;
211};
212
213}
214
215/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void selectEntry(const tools::Long nPos)
std::vector< TEntry_Impl > m_vEntries
tools::Long PointToPos(const Point &rPos)
virtual ~ExtensionBox_Impl() override
bool FindEntryPos(const TEntry_Impl &rEntry, tools::Long nStart, tools::Long nEnd, tools::Long &nFound)
virtual void SetDrawingArea(weld::DrawingArea *pDrawingArea) override
void setExtensionManager(TheExtensionManager *pManager)
void updateEntry(const css::uno::Reference< css::deployment::XPackage > &xPackage)
tools::Long GetTotalHeight() const
tools::Rectangle GetEntryRect(const tools::Long nPos) const
void DrawRow(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect, const TEntry_Impl &rEntry)
std::vector< TEntry_Impl > m_vRemovedEntries
tools::Long GetEntryCount() const
void addEventListenerOnce(css::uno::Reference< css::deployment::XPackage > const &extension)
std::optional< CollatorWrapper > m_oCollator
virtual void Resize() override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rPaintRect) override
mutable::osl::Mutex m_entriesMutex
std::unique_ptr< css::lang::Locale > m_pLocale
rtl::Reference< ExtensionRemovedListener > m_xRemoveListener
std::vector< css::uno::WeakReference< css::deployment::XPackage > > m_vListenerAdded
virtual bool MouseButtonDown(const MouseEvent &rMEvt) override
DECL_LINK(ScrollHdl, weld::ScrolledWindow &, void)
void removeEntry(const css::uno::Reference< css::deployment::XPackage > &xPackage)
ExtensionBox_Impl(std::unique_ptr< weld::ScrolledWindow > xScroll)
std::unique_ptr< weld::ScrolledWindow > m_xScrollBar
virtual OUString RequestHelp(tools::Rectangle &rRect) override
TheExtensionManager * m_pManager
bool HandleCursorKey(sal_uInt16 nKeyCode)
virtual bool KeyInput(const KeyEvent &rKEvt) override
TEntry_Impl const & GetEntryData(tools::Long nPos)
void CalcActiveHeight(const tools::Long nPos)
void addEntry(const css::uno::Reference< css::deployment::XPackage > &xPackage, bool bLicenseMissing=false)
virtual bool MouseMove(const MouseEvent &rMEvt) override
virtual void SAL_CALL disposing(css::lang::EventObject const &evt) override
virtual ~ExtensionRemovedListener() override
ExtensionRemovedListener(ExtensionBox_Impl *pParent)
sal_uInt16 nPos
Definition: dp_gui.h:22
PackageState
Definition: dp_gui.h:24
std::shared_ptr< Entry_Impl > TEntry_Impl
long Long
sal_Int32 CompareTo(const CollatorWrapper *pCollator, const TEntry_Impl &rEntry) const
Entry_Impl(const css::uno::Reference< css::deployment::XPackage > &xPackage, const PackageState eState, const bool bReadOnly)
tools::Rectangle m_aLinkRect
css::uno::Reference< css::deployment::XPackage > m_xPackage