Line data Source code
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 : #include "rtl/ustring.hxx"
21 : #include "vcl/scrbar.hxx"
22 : #include "vcl/fixed.hxx"
23 : #include "vcl/dialog.hxx"
24 : #include "vcl/field.hxx"
25 :
26 : #include "svtools/extensionlistbox.hxx"
27 : #include "cppuhelper/implbase1.hxx"
28 :
29 : #include "com/sun/star/lang/Locale.hpp"
30 : #include "com/sun/star/lang/XEventListener.hpp"
31 : #include "com/sun/star/deployment/XPackage.hpp"
32 :
33 : #include <boost/shared_ptr.hpp>
34 :
35 : #include "sdresid.hxx"
36 :
37 : namespace sd {
38 :
39 : #define SMALL_ICON_SIZE 16
40 : #define TOP_OFFSET 5
41 : #define ICON_HEIGHT 42
42 : #define ICON_WIDTH 47
43 : #define ICON_OFFSET 72
44 : #define RIGHT_ICON_OFFSET 5
45 : #define SPACE_BETWEEN 3
46 :
47 : // struct ClientBoxEntry
48 : struct ClientBoxEntry;
49 : struct ClientInfo;
50 :
51 : typedef ::boost::shared_ptr< ClientBoxEntry > TClientBoxEntry;
52 :
53 : struct ClientBoxEntry
54 : {
55 : bool m_bActive :1;
56 : ClientInfo* m_pClientInfo;
57 :
58 :
59 : ClientBoxEntry( ClientInfo* pClientInfo );
60 : ~ClientBoxEntry();
61 :
62 : };
63 :
64 :
65 : // class ExtensionBox_Impl
66 : class ClientBox;
67 :
68 :
69 : class ClientRemovedListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
70 : {
71 : ClientBox *m_pParent;
72 :
73 : public:
74 :
75 0 : ClientRemovedListener( ClientBox *pParent ) { m_pParent = pParent; }
76 : virtual ~ClientRemovedListener();
77 :
78 :
79 : // XEventListener
80 : virtual void SAL_CALL disposing( ::com::sun::star::lang::EventObject const & evt )
81 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
82 : };
83 :
84 : class ClientBox:
85 : public Control
86 : {
87 : bool m_bHasScrollBar;
88 : bool m_bHasActive;
89 : bool m_bNeedsRecalc;
90 : bool m_bInCheckMode;
91 : bool m_bAdjustActive;
92 : bool m_bInDelete;
93 : //Must be guarded together with m_vEntries to ensure a valid index at all times.
94 : //Use m_entriesMutex as guard.
95 : long m_nActive;
96 : long m_nTopIndex;
97 : long m_nStdHeight;
98 : long m_nActiveHeight;
99 : long m_nExtraHeight;
100 : Size m_aOutputSize;
101 : Link m_aClickHdl;
102 :
103 : NumericBox m_aPinBox;
104 :
105 : ScrollBar m_aScrollBar;
106 :
107 : com::sun::star::uno::Reference< ClientRemovedListener > m_xRemoveListener;
108 :
109 : //This mutex is used for synchronizing access to m_vEntries.
110 : //Currently it is used to synchronize adding, removing entries and
111 : //functions like getItemName, getItemDescription, etc. to prevent
112 : //that m_vEntries is accessed at an invalid index.
113 : //ToDo: There are many more places where m_vEntries is read and which may
114 : //fail. For example the Paint method is probable called from the main thread
115 : //while new entries are added / removed in a separate thread.
116 : mutable ::osl::Mutex m_entriesMutex;
117 : std::vector< TClientBoxEntry > m_vEntries;
118 : std::vector< TClientBoxEntry > m_vRemovedEntries;
119 :
120 : void CalcActiveHeight( const long nPos );
121 : long GetTotalHeight() const;
122 : void SetupScrollBar();
123 : void DrawRow( const Rectangle& rRect, const TClientBoxEntry pEntry );
124 : bool HandleTabKey( bool bReverse );
125 : bool HandleCursorKey( sal_uInt16 nKeyCode );
126 : void DeleteRemoved();
127 :
128 :
129 : DECL_DLLPRIVATE_LINK( ScrollHdl, ScrollBar* );
130 :
131 : //Index starts with 1.
132 : //Throws an com::sun::star::lang::IllegalArgumentException, when the index is invalid.
133 : void checkIndex(sal_Int32 pos) const;
134 :
135 :
136 : public:
137 : ClientBox( Window* pParent, WinBits nStyle );
138 : virtual ~ClientBox();
139 :
140 : void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
141 : void Paint( const Rectangle &rPaintRect ) SAL_OVERRIDE;
142 : void Resize() SAL_OVERRIDE;
143 : Size GetOptimalSize() const SAL_OVERRIDE;
144 : bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
145 :
146 : const Size GetMinOutputSizePixel() const;
147 : void SetExtraSize( long nSize ) { m_nExtraHeight = nSize; }
148 0 : TClientBoxEntry GetEntryData( long nPos ) { return m_vEntries[ nPos ]; }
149 : long GetActiveEntryIndex();
150 : long GetEntryCount() { return (long) m_vEntries.size(); }
151 : Rectangle GetEntryRect( const long nPos ) const;
152 : bool HasActive() { return m_bHasActive; }
153 : long PointToPos( const Point& rPos );
154 : void SetScrollHdl( const Link& rLink );
155 : void DoScroll( long nDelta );
156 : void SetHyperlinkHdl( const Link& rLink ){ m_aClickHdl = rLink; }
157 : void RecalcAll();
158 : void RemoveUnlocked();
159 :
160 :
161 : void selectEntry( const long nPos );
162 : long addEntry( ClientInfo* pClientInfo );
163 : void updateEntry( const ClientInfo* rPackageInfo );
164 : void removeEntry( const ClientInfo* rPackageInfo );
165 :
166 : void prepareChecking();
167 : void checkEntries();
168 :
169 : OUString getPin();
170 : };
171 :
172 : }
173 :
174 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|