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