1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <rtl/ustring.hxx>
23 #include <vcl/customweld.hxx>
24 #include <vcl/image.hxx>
25 #include <vcl/weld.hxx>
27 #include <cppuhelper/implbase.hxx>
28 #include <cppuhelper/weakref.hxx>
29 #include <unotools/collatorwrapper.hxx>
31 #include <com/sun/star/lang/Locale.hpp>
32 #include <com/sun/star/lang/XEventListener.hpp>
33 #include <com/sun/star/deployment/XPackage.hpp>
42 #define SMALL_ICON_SIZE 16
44 #define ICON_HEIGHT 42
46 #define ICON_OFFSET 72
47 #define RIGHT_ICON_OFFSET 5
48 #define SPACE_BETWEEN 3
50 class TheExtensionManager
;
55 typedef std::shared_ptr
< Entry_Impl
> TEntry_Impl
;
61 bool m_bHasOptions
:1;
66 bool m_bMissingDeps
:1;
67 bool m_bHasButtons
:1;
68 bool m_bMissingLic
:1;
69 PackageState m_eState
;
72 OUString m_sDescription
;
73 OUString m_sPublisher
;
74 OUString m_sPublisherURL
;
75 OUString m_sErrorText
;
76 OUString m_sLicenseText
;
78 tools::Rectangle m_aLinkRect
;
80 css::uno::Reference
<css::deployment::XPackage
> m_xPackage
;
82 Entry_Impl(const css::uno::Reference
<css::deployment::XPackage
> &xPackage
,
83 const PackageState eState
, const bool bReadOnly
);
86 sal_Int32
CompareTo(const CollatorWrapper
*pCollator
, const TEntry_Impl
& rEntry
) const;
87 void checkDependencies();
90 class ExtensionBox_Impl
;
93 class ExtensionRemovedListener
: public ::cppu::WeakImplHelper
<css::lang::XEventListener
>
95 ExtensionBox_Impl
* m_pParent
;
99 explicit ExtensionRemovedListener( ExtensionBox_Impl
*pParent
) { m_pParent
= pParent
; }
100 virtual ~ExtensionRemovedListener() override
;
104 virtual void SAL_CALL
disposing(css::lang::EventObject
const& evt
) override
;
107 class ExtensionBox_Impl
: public weld::CustomWidgetController
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 tools::Long m_nActive
;
118 tools::Long m_nTopIndex
;
119 tools::Long m_nStdHeight
;
120 tools::Long m_nActiveHeight
;
121 Image m_aSharedImage
;
122 Image m_aLockedImage
;
123 Image m_aWarningImage
;
124 Image m_aDefaultImage
;
126 rtl::Reference
<ExtensionRemovedListener
> m_xRemoveListener
;
128 TheExtensionManager
*m_pManager
;
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
;
140 std::unique_ptr
<css::lang::Locale
> m_pLocale
;
141 std::optional
<CollatorWrapper
> m_oCollator
;
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
;
147 std::unique_ptr
<weld::ScrolledWindow
> m_xScrollBar
;
149 //Removes the dead weak references from m_vListenerAdded
150 void cleanVecListenerAdded();
151 void addEventListenerOnce(css::uno::Reference
<css::deployment::XPackage
> const & extension
);
153 void CalcActiveHeight( const tools::Long nPos
);
154 tools::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
, tools::Long nStart
, tools::Long nEnd
, tools::Long
&nFound
);
159 void DeleteRemoved();
161 DECL_LINK( ScrollHdl
, weld::ScrolledWindow
&, void );
165 explicit ExtensionBox_Impl(std::unique_ptr
<weld::ScrolledWindow
> xScroll
);
166 virtual ~ExtensionBox_Impl() override
;
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
;
175 virtual void SetDrawingArea(weld::DrawingArea
* pDrawingArea
) override
;
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();
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
);
192 void prepareChecking();
195 void setExtensionManager(TheExtensionManager
* pManager
) { m_pManager
= pManager
; }
197 //These functions are used for automatic testing
199 enum { ENTRY_NOTFOUND
= -1 };
201 /** @return The count of the entries in the list box. */
202 sal_Int32
getItemCount() const;
204 /** @return The index of the first selected entry in the list box.
205 When nothing is selected, which is the case when getItemCount returns '0',
206 then this function returns ENTRY_NOTFOUND */
207 /** @return The index of the first selected entry in the list box.
208 When nothing is selected, which is the case when getItemCount returns '0',
209 then this function returns ENTRY_NOTFOUND */
210 sal_Int32
getSelIndex() const;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */