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
37#include "dp_gui.h"
38
39namespace 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
49class TheExtensionManager;
50
51
52struct Entry_Impl;
53
54typedef std::shared_ptr< Entry_Impl > TEntry_Impl;
55
57{
58 bool m_bActive :1;
59 bool m_bLocked :1;
61 bool m_bUser :1;
62 bool m_bShared :1;
63 bool m_bNew :1;
64 bool m_bChecked :1;
69 OUString m_sTitle;
70 OUString m_sVersion;
72 OUString m_sPublisher;
74 OUString m_sErrorText;
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);
84
85 sal_Int32 CompareTo(const CollatorWrapper *pCollator, const TEntry_Impl& rEntry) const;
86 void checkDependencies();
87};
88
90
91
92class ExtensionRemovedListener : public ::cppu::WeakImplHelper<css::lang::XEventListener>
93{
95
96public:
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{
109 bool m_bHasActive : 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
150 void addEventListenerOnce(css::uno::Reference<css::deployment::XPackage> const & extension);
151
152 void CalcActiveHeight( const tools::Long nPos );
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();
163public:
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
197public:
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: */
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)
std::unique_ptr< CollatorWrapper > m_pCollator
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)
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